Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Simplest possible simple frame-buffer driver, as a platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2013, Stephen Warren
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Based on q40fb.c, which was:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2001 Richard Zidlicky <rz@linux-m68k.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Also based on offb.c, which was:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (C) 1997 Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Copyright (C) 1996 Paul Mackerras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/platform_data/simplefb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/of_clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static const struct fb_fix_screeninfo simplefb_fix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.id		= "simple",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.type		= FB_TYPE_PACKED_PIXELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.visual		= FB_VISUAL_TRUECOLOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.accel		= FB_ACCEL_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static const struct fb_var_screeninfo simplefb_var = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.height		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	.width		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	.activate	= FB_ACTIVATE_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	.vmode		= FB_VMODE_NONINTERLACED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define PSEUDO_PALETTE_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			      u_int transp, struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u32 *pal = info->pseudo_palette;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u32 cr = red >> (16 - info->var.red.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u32 cg = green >> (16 - info->var.green.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u32 cb = blue >> (16 - info->var.blue.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (regno >= PSEUDO_PALETTE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	value = (cr << info->var.red.offset) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		(cg << info->var.green.offset) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		(cb << info->var.blue.offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (info->var.transp.length > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		u32 mask = (1 << info->var.transp.length) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		mask <<= info->var.transp.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		value |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	pal[regno] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) struct simplefb_par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static void simplefb_clocks_destroy(struct simplefb_par *par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static void simplefb_regulators_destroy(struct simplefb_par *par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void simplefb_destroy(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	simplefb_regulators_destroy(info->par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	simplefb_clocks_destroy(info->par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (info->screen_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		iounmap(info->screen_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static const struct fb_ops simplefb_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	.fb_destroy	= simplefb_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	.fb_setcolreg	= simplefb_setcolreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	.fb_fillrect	= cfb_fillrect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.fb_copyarea	= cfb_copyarea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.fb_imageblit	= cfb_imageblit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static struct simplefb_format simplefb_formats[] = SIMPLEFB_FORMATS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) struct simplefb_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	u32 width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	u32 height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u32 stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct simplefb_format *format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static int simplefb_parse_dt(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			   struct simplefb_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	const char *format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ret = of_property_read_u32(np, "width", &params->width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dev_err(&pdev->dev, "Can't parse width property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ret = of_property_read_u32(np, "height", &params->height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		dev_err(&pdev->dev, "Can't parse height property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	ret = of_property_read_u32(np, "stride", &params->stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		dev_err(&pdev->dev, "Can't parse stride property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	ret = of_property_read_string(np, "format", &format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		dev_err(&pdev->dev, "Can't parse format property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	params->format = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (strcmp(format, simplefb_formats[i].name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		params->format = &simplefb_formats[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (!params->format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		dev_err(&pdev->dev, "Invalid format value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int simplefb_parse_pd(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			     struct simplefb_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	params->width = pd->width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	params->height = pd->height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	params->stride = pd->stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	params->format = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (strcmp(pd->format, simplefb_formats[i].name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		params->format = &simplefb_formats[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (!params->format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dev_err(&pdev->dev, "Invalid format value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct simplefb_par {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	u32 palette[PSEUDO_PALETTE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	bool clks_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	unsigned int clk_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct clk **clks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #if defined CONFIG_OF && defined CONFIG_REGULATOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	bool regulators_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	u32 regulator_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct regulator **regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * Clock handling code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * Here we handle the clocks property of our "simple-framebuffer" dt node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * This is necessary so that we can make sure that any clocks needed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * the display engine that the bootloader set up for us (and for which it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * provided a simplefb dt node), stay up, for the life of the simplefb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * When the driver unloads, we cleanly disable, and then release the clocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * We only complain about errors here, no action is taken as the most likely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * error can only happen due to a mismatch between the bootloader which set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * up simplefb, and the clock definitions in the device tree. Chances are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * that there are no adverse effects, and if there are, a clean teardown of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * the fb probe will not help us much either. So just complain and carry on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * and hope that the user actually gets a working fb at the end of things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int simplefb_clocks_get(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			       struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct clk *clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (dev_get_platdata(&pdev->dev) || !np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	par->clk_count = of_clk_get_parent_count(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (!par->clk_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	par->clks = kcalloc(par->clk_count, sizeof(struct clk *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (!par->clks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	for (i = 0; i < par->clk_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		clock = of_clk_get(np, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if (IS_ERR(clock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			if (PTR_ERR(clock) == -EPROBE_DEFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				while (--i >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 					if (par->clks[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 						clk_put(par->clks[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 				kfree(par->clks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			dev_err(&pdev->dev, "%s: clock %d not found: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				__func__, i, PTR_ERR(clock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		par->clks[i] = clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static void simplefb_clocks_enable(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				   struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	for (i = 0; i < par->clk_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		if (par->clks[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			ret = clk_prepare_enable(par->clks[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 					"%s: failed to enable clock %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 					__func__, i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				clk_put(par->clks[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				par->clks[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	par->clks_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static void simplefb_clocks_destroy(struct simplefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (!par->clks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	for (i = 0; i < par->clk_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (par->clks[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			if (par->clks_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				clk_disable_unprepare(par->clks[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			clk_put(par->clks[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	kfree(par->clks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int simplefb_clocks_get(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	struct platform_device *pdev) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static void simplefb_clocks_enable(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct platform_device *pdev) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static void simplefb_clocks_destroy(struct simplefb_par *par) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #if defined CONFIG_OF && defined CONFIG_REGULATOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #define SUPPLY_SUFFIX "-supply"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * Regulator handling code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * Here we handle the num-supplies and vin*-supply properties of our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  * "simple-framebuffer" dt node. This is necessary so that we can make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * that any regulators needed by the display hardware that the bootloader
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * set up for us (and for which it provided a simplefb dt node), stay up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * for the life of the simplefb driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * When the driver unloads, we cleanly disable, and then release the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * regulators.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * We only complain about errors here, no action is taken as the most likely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * error can only happen due to a mismatch between the bootloader which set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * up simplefb, and the regulator definitions in the device tree. Chances are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * that there are no adverse effects, and if there are, a clean teardown of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  * the fb probe will not help us much either. So just complain and carry on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * and hope that the user actually gets a working fb at the end of things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static int simplefb_regulators_get(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 				   struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	struct regulator *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	const char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	int count = 0, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (dev_get_platdata(&pdev->dev) || !np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	/* Count the number of regulator supplies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	for_each_property_of_node(np, prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		p = strstr(prop->name, SUPPLY_SUFFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		if (p && p != prop->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	par->regulators = devm_kcalloc(&pdev->dev, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				       sizeof(struct regulator *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (!par->regulators)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	/* Get all the regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	for_each_property_of_node(np, prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		char name[32]; /* 32 is max size of property name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		p = strstr(prop->name, SUPPLY_SUFFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		if (!p || p == prop->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		strlcpy(name, prop->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			strlen(prop->name) - strlen(SUPPLY_SUFFIX) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		regulator = devm_regulator_get_optional(&pdev->dev, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		if (IS_ERR(regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			if (PTR_ERR(regulator) == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				name, PTR_ERR(regulator));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		par->regulators[i++] = regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	par->regulator_count = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static void simplefb_regulators_enable(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				       struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/* Enable all the regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	for (i = 0; i < par->regulator_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		ret = regulator_enable(par->regulators[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				"failed to enable regulator %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			devm_regulator_put(par->regulators[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			par->regulators[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	par->regulators_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void simplefb_regulators_destroy(struct simplefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (!par->regulators || !par->regulators_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	for (i = 0; i < par->regulator_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		if (par->regulators[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			regulator_disable(par->regulators[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static int simplefb_regulators_get(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct platform_device *pdev) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static void simplefb_regulators_enable(struct simplefb_par *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct platform_device *pdev) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static void simplefb_regulators_destroy(struct simplefb_par *par) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static int simplefb_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct simplefb_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct fb_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct simplefb_par *par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct resource *mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (fb_get_options("simplefb", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (dev_get_platdata(&pdev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		ret = simplefb_parse_pd(pdev, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	else if (pdev->dev.of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		ret = simplefb_parse_dt(pdev, &params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (!mem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		dev_err(&pdev->dev, "No memory resource\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	info = framebuffer_alloc(sizeof(struct simplefb_par), &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	platform_set_drvdata(pdev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	info->fix = simplefb_fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	info->fix.smem_start = mem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	info->fix.smem_len = resource_size(mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	info->fix.line_length = params.stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	info->var = simplefb_var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	info->var.xres = params.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	info->var.yres = params.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	info->var.xres_virtual = params.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	info->var.yres_virtual = params.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	info->var.bits_per_pixel = params.format->bits_per_pixel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	info->var.red = params.format->red;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	info->var.green = params.format->green;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	info->var.blue = params.format->blue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	info->var.transp = params.format->transp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	info->apertures = alloc_apertures(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (!info->apertures) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		goto error_fb_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	info->apertures->ranges[0].base = info->fix.smem_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	info->apertures->ranges[0].size = info->fix.smem_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	info->fbops = &simplefb_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	info->flags = FBINFO_DEFAULT | FBINFO_MISC_FIRMWARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	info->screen_base = ioremap_wc(info->fix.smem_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 				       info->fix.smem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (!info->screen_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		goto error_fb_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	info->pseudo_palette = par->palette;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	ret = simplefb_clocks_get(par, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		goto error_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	ret = simplefb_regulators_get(par, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		goto error_clocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	simplefb_clocks_enable(par, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	simplefb_regulators_enable(par, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			     info->fix.smem_start, info->fix.smem_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			     info->screen_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	dev_info(&pdev->dev, "format=%s, mode=%dx%dx%d, linelength=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			     params.format->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			     info->var.xres, info->var.yres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			     info->var.bits_per_pixel, info->fix.line_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	ret = register_framebuffer(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		goto error_regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) error_regulators:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	simplefb_regulators_destroy(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) error_clocks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	simplefb_clocks_destroy(par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) error_unmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	iounmap(info->screen_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) error_fb_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	framebuffer_release(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static int simplefb_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	struct fb_info *info = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	unregister_framebuffer(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	framebuffer_release(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static const struct of_device_id simplefb_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	{ .compatible = "simple-framebuffer", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) MODULE_DEVICE_TABLE(of, simplefb_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static struct platform_driver simplefb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		.name = "simple-framebuffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		.of_match_table = simplefb_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	.probe = simplefb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	.remove = simplefb_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static int __init simplefb_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	ret = platform_driver_register(&simplefb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		for_each_child_of_node(of_chosen, np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			if (of_device_is_compatible(np, "simple-framebuffer"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 				of_platform_device_create(np, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) fs_initcall(simplefb_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) MODULE_AUTHOR("Stephen Warren <swarren@wwwdotorg.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) MODULE_DESCRIPTION("Simple framebuffer driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) MODULE_LICENSE("GPL v2");