xref: /linux-6.15/drivers/video/fbdev/simplefb.c (revision d49c6993)
1f7018c21STomi Valkeinen /*
2f7018c21STomi Valkeinen  * Simplest possible simple frame-buffer driver, as a platform device
3f7018c21STomi Valkeinen  *
4f7018c21STomi Valkeinen  * Copyright (c) 2013, Stephen Warren
5f7018c21STomi Valkeinen  *
6f7018c21STomi Valkeinen  * Based on q40fb.c, which was:
7f7018c21STomi Valkeinen  * Copyright (C) 2001 Richard Zidlicky <[email protected]>
8f7018c21STomi Valkeinen  *
9f7018c21STomi Valkeinen  * Also based on offb.c, which was:
10f7018c21STomi Valkeinen  * Copyright (C) 1997 Geert Uytterhoeven
11f7018c21STomi Valkeinen  * Copyright (C) 1996 Paul Mackerras
12f7018c21STomi Valkeinen  *
13f7018c21STomi Valkeinen  * This program is free software; you can redistribute it and/or modify it
14f7018c21STomi Valkeinen  * under the terms and conditions of the GNU General Public License,
15f7018c21STomi Valkeinen  * version 2, as published by the Free Software Foundation.
16f7018c21STomi Valkeinen  *
17f7018c21STomi Valkeinen  * This program is distributed in the hope it will be useful, but WITHOUT
18f7018c21STomi Valkeinen  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19f7018c21STomi Valkeinen  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
20f7018c21STomi Valkeinen  * more details.
21f7018c21STomi Valkeinen  */
22f7018c21STomi Valkeinen 
23f7018c21STomi Valkeinen #include <linux/errno.h>
24f7018c21STomi Valkeinen #include <linux/fb.h>
25f7018c21STomi Valkeinen #include <linux/io.h>
26f7018c21STomi Valkeinen #include <linux/module.h>
27f7018c21STomi Valkeinen #include <linux/platform_data/simplefb.h>
28f7018c21STomi Valkeinen #include <linux/platform_device.h>
29*d49c6993SStephen Boyd #include <linux/clk.h>
30fc219bfdSLuc Verhaegen #include <linux/clk-provider.h>
3189c95001SHans de Goede #include <linux/of_platform.h>
32f7018c21STomi Valkeinen 
33f7018c21STomi Valkeinen static struct fb_fix_screeninfo simplefb_fix = {
34f7018c21STomi Valkeinen 	.id		= "simple",
35f7018c21STomi Valkeinen 	.type		= FB_TYPE_PACKED_PIXELS,
36f7018c21STomi Valkeinen 	.visual		= FB_VISUAL_TRUECOLOR,
37f7018c21STomi Valkeinen 	.accel		= FB_ACCEL_NONE,
38f7018c21STomi Valkeinen };
39f7018c21STomi Valkeinen 
40f7018c21STomi Valkeinen static struct fb_var_screeninfo simplefb_var = {
41f7018c21STomi Valkeinen 	.height		= -1,
42f7018c21STomi Valkeinen 	.width		= -1,
43f7018c21STomi Valkeinen 	.activate	= FB_ACTIVATE_NOW,
44f7018c21STomi Valkeinen 	.vmode		= FB_VMODE_NONINTERLACED,
45f7018c21STomi Valkeinen };
46f7018c21STomi Valkeinen 
471270be4aSLuc Verhaegen #define PSEUDO_PALETTE_SIZE 16
481270be4aSLuc Verhaegen 
49f7018c21STomi Valkeinen static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
50f7018c21STomi Valkeinen 			      u_int transp, struct fb_info *info)
51f7018c21STomi Valkeinen {
52f7018c21STomi Valkeinen 	u32 *pal = info->pseudo_palette;
53f7018c21STomi Valkeinen 	u32 cr = red >> (16 - info->var.red.length);
54f7018c21STomi Valkeinen 	u32 cg = green >> (16 - info->var.green.length);
55f7018c21STomi Valkeinen 	u32 cb = blue >> (16 - info->var.blue.length);
56f7018c21STomi Valkeinen 	u32 value;
57f7018c21STomi Valkeinen 
581270be4aSLuc Verhaegen 	if (regno >= PSEUDO_PALETTE_SIZE)
59f7018c21STomi Valkeinen 		return -EINVAL;
60f7018c21STomi Valkeinen 
61f7018c21STomi Valkeinen 	value = (cr << info->var.red.offset) |
62f7018c21STomi Valkeinen 		(cg << info->var.green.offset) |
63f7018c21STomi Valkeinen 		(cb << info->var.blue.offset);
64f7018c21STomi Valkeinen 	if (info->var.transp.length > 0) {
65f7018c21STomi Valkeinen 		u32 mask = (1 << info->var.transp.length) - 1;
66f7018c21STomi Valkeinen 		mask <<= info->var.transp.offset;
67f7018c21STomi Valkeinen 		value |= mask;
68f7018c21STomi Valkeinen 	}
69f7018c21STomi Valkeinen 	pal[regno] = value;
70f7018c21STomi Valkeinen 
71f7018c21STomi Valkeinen 	return 0;
72f7018c21STomi Valkeinen }
73f7018c21STomi Valkeinen 
74f7018c21STomi Valkeinen static void simplefb_destroy(struct fb_info *info)
75f7018c21STomi Valkeinen {
76f7018c21STomi Valkeinen 	if (info->screen_base)
77f7018c21STomi Valkeinen 		iounmap(info->screen_base);
78f7018c21STomi Valkeinen }
79f7018c21STomi Valkeinen 
80f7018c21STomi Valkeinen static struct fb_ops simplefb_ops = {
81f7018c21STomi Valkeinen 	.owner		= THIS_MODULE,
82f7018c21STomi Valkeinen 	.fb_destroy	= simplefb_destroy,
83f7018c21STomi Valkeinen 	.fb_setcolreg	= simplefb_setcolreg,
84f7018c21STomi Valkeinen 	.fb_fillrect	= cfb_fillrect,
85f7018c21STomi Valkeinen 	.fb_copyarea	= cfb_copyarea,
86f7018c21STomi Valkeinen 	.fb_imageblit	= cfb_imageblit,
87f7018c21STomi Valkeinen };
88f7018c21STomi Valkeinen 
89f7018c21STomi Valkeinen static struct simplefb_format simplefb_formats[] = SIMPLEFB_FORMATS;
90f7018c21STomi Valkeinen 
91f7018c21STomi Valkeinen struct simplefb_params {
92f7018c21STomi Valkeinen 	u32 width;
93f7018c21STomi Valkeinen 	u32 height;
94f7018c21STomi Valkeinen 	u32 stride;
95f7018c21STomi Valkeinen 	struct simplefb_format *format;
96f7018c21STomi Valkeinen };
97f7018c21STomi Valkeinen 
98f7018c21STomi Valkeinen static int simplefb_parse_dt(struct platform_device *pdev,
99f7018c21STomi Valkeinen 			   struct simplefb_params *params)
100f7018c21STomi Valkeinen {
101f7018c21STomi Valkeinen 	struct device_node *np = pdev->dev.of_node;
102f7018c21STomi Valkeinen 	int ret;
103f7018c21STomi Valkeinen 	const char *format;
104f7018c21STomi Valkeinen 	int i;
105f7018c21STomi Valkeinen 
106f7018c21STomi Valkeinen 	ret = of_property_read_u32(np, "width", &params->width);
107f7018c21STomi Valkeinen 	if (ret) {
108f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse width property\n");
109f7018c21STomi Valkeinen 		return ret;
110f7018c21STomi Valkeinen 	}
111f7018c21STomi Valkeinen 
112f7018c21STomi Valkeinen 	ret = of_property_read_u32(np, "height", &params->height);
113f7018c21STomi Valkeinen 	if (ret) {
114f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse height property\n");
115f7018c21STomi Valkeinen 		return ret;
116f7018c21STomi Valkeinen 	}
117f7018c21STomi Valkeinen 
118f7018c21STomi Valkeinen 	ret = of_property_read_u32(np, "stride", &params->stride);
119f7018c21STomi Valkeinen 	if (ret) {
120f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse stride property\n");
121f7018c21STomi Valkeinen 		return ret;
122f7018c21STomi Valkeinen 	}
123f7018c21STomi Valkeinen 
124f7018c21STomi Valkeinen 	ret = of_property_read_string(np, "format", &format);
125f7018c21STomi Valkeinen 	if (ret) {
126f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse format property\n");
127f7018c21STomi Valkeinen 		return ret;
128f7018c21STomi Valkeinen 	}
129f7018c21STomi Valkeinen 	params->format = NULL;
130f7018c21STomi Valkeinen 	for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) {
131f7018c21STomi Valkeinen 		if (strcmp(format, simplefb_formats[i].name))
132f7018c21STomi Valkeinen 			continue;
133f7018c21STomi Valkeinen 		params->format = &simplefb_formats[i];
134f7018c21STomi Valkeinen 		break;
135f7018c21STomi Valkeinen 	}
136f7018c21STomi Valkeinen 	if (!params->format) {
137f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Invalid format value\n");
138f7018c21STomi Valkeinen 		return -EINVAL;
139f7018c21STomi Valkeinen 	}
140f7018c21STomi Valkeinen 
141f7018c21STomi Valkeinen 	return 0;
142f7018c21STomi Valkeinen }
143f7018c21STomi Valkeinen 
144f7018c21STomi Valkeinen static int simplefb_parse_pd(struct platform_device *pdev,
145f7018c21STomi Valkeinen 			     struct simplefb_params *params)
146f7018c21STomi Valkeinen {
147f7018c21STomi Valkeinen 	struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev);
148f7018c21STomi Valkeinen 	int i;
149f7018c21STomi Valkeinen 
150f7018c21STomi Valkeinen 	params->width = pd->width;
151f7018c21STomi Valkeinen 	params->height = pd->height;
152f7018c21STomi Valkeinen 	params->stride = pd->stride;
153f7018c21STomi Valkeinen 
154f7018c21STomi Valkeinen 	params->format = NULL;
155f7018c21STomi Valkeinen 	for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) {
156f7018c21STomi Valkeinen 		if (strcmp(pd->format, simplefb_formats[i].name))
157f7018c21STomi Valkeinen 			continue;
158f7018c21STomi Valkeinen 
159f7018c21STomi Valkeinen 		params->format = &simplefb_formats[i];
160f7018c21STomi Valkeinen 		break;
161f7018c21STomi Valkeinen 	}
162f7018c21STomi Valkeinen 
163f7018c21STomi Valkeinen 	if (!params->format) {
164f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Invalid format value\n");
165f7018c21STomi Valkeinen 		return -EINVAL;
166f7018c21STomi Valkeinen 	}
167f7018c21STomi Valkeinen 
168f7018c21STomi Valkeinen 	return 0;
169f7018c21STomi Valkeinen }
170f7018c21STomi Valkeinen 
1711270be4aSLuc Verhaegen struct simplefb_par {
1721270be4aSLuc Verhaegen 	u32 palette[PSEUDO_PALETTE_SIZE];
1738284731eSHans de Goede #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
174fc219bfdSLuc Verhaegen 	int clk_count;
175fc219bfdSLuc Verhaegen 	struct clk **clks;
176fc219bfdSLuc Verhaegen #endif
1771270be4aSLuc Verhaegen };
1781270be4aSLuc Verhaegen 
1798284731eSHans de Goede #if defined CONFIG_OF && defined CONFIG_COMMON_CLK
180fc219bfdSLuc Verhaegen /*
181fc219bfdSLuc Verhaegen  * Clock handling code.
182fc219bfdSLuc Verhaegen  *
183fc219bfdSLuc Verhaegen  * Here we handle the clocks property of our "simple-framebuffer" dt node.
184fc219bfdSLuc Verhaegen  * This is necessary so that we can make sure that any clocks needed by
185fc219bfdSLuc Verhaegen  * the display engine that the bootloader set up for us (and for which it
186fc219bfdSLuc Verhaegen  * provided a simplefb dt node), stay up, for the life of the simplefb
187fc219bfdSLuc Verhaegen  * driver.
188fc219bfdSLuc Verhaegen  *
189fc219bfdSLuc Verhaegen  * When the driver unloads, we cleanly disable, and then release the clocks.
190fc219bfdSLuc Verhaegen  *
191fc219bfdSLuc Verhaegen  * We only complain about errors here, no action is taken as the most likely
192fc219bfdSLuc Verhaegen  * error can only happen due to a mismatch between the bootloader which set
193fc219bfdSLuc Verhaegen  * up simplefb, and the clock definitions in the device tree. Chances are
194fc219bfdSLuc Verhaegen  * that there are no adverse effects, and if there are, a clean teardown of
195fc219bfdSLuc Verhaegen  * the fb probe will not help us much either. So just complain and carry on,
196fc219bfdSLuc Verhaegen  * and hope that the user actually gets a working fb at the end of things.
197fc219bfdSLuc Verhaegen  */
198fc219bfdSLuc Verhaegen static int simplefb_clocks_init(struct simplefb_par *par,
199fc219bfdSLuc Verhaegen 				struct platform_device *pdev)
200fc219bfdSLuc Verhaegen {
201fc219bfdSLuc Verhaegen 	struct device_node *np = pdev->dev.of_node;
202fc219bfdSLuc Verhaegen 	struct clk *clock;
203fc219bfdSLuc Verhaegen 	int i, ret;
204fc219bfdSLuc Verhaegen 
205fc219bfdSLuc Verhaegen 	if (dev_get_platdata(&pdev->dev) || !np)
206fc219bfdSLuc Verhaegen 		return 0;
207fc219bfdSLuc Verhaegen 
208fc219bfdSLuc Verhaegen 	par->clk_count = of_clk_get_parent_count(np);
209fc219bfdSLuc Verhaegen 	if (par->clk_count <= 0)
210fc219bfdSLuc Verhaegen 		return 0;
211fc219bfdSLuc Verhaegen 
212fc219bfdSLuc Verhaegen 	par->clks = kcalloc(par->clk_count, sizeof(struct clk *), GFP_KERNEL);
213fc219bfdSLuc Verhaegen 	if (!par->clks)
214fc219bfdSLuc Verhaegen 		return -ENOMEM;
215fc219bfdSLuc Verhaegen 
216fc219bfdSLuc Verhaegen 	for (i = 0; i < par->clk_count; i++) {
217fc219bfdSLuc Verhaegen 		clock = of_clk_get(np, i);
218fc219bfdSLuc Verhaegen 		if (IS_ERR(clock)) {
219fc219bfdSLuc Verhaegen 			if (PTR_ERR(clock) == -EPROBE_DEFER) {
220fc219bfdSLuc Verhaegen 				while (--i >= 0) {
221fc219bfdSLuc Verhaegen 					if (par->clks[i])
222fc219bfdSLuc Verhaegen 						clk_put(par->clks[i]);
223fc219bfdSLuc Verhaegen 				}
224fc219bfdSLuc Verhaegen 				kfree(par->clks);
225fc219bfdSLuc Verhaegen 				return -EPROBE_DEFER;
226fc219bfdSLuc Verhaegen 			}
227fc219bfdSLuc Verhaegen 			dev_err(&pdev->dev, "%s: clock %d not found: %ld\n",
228fc219bfdSLuc Verhaegen 				__func__, i, PTR_ERR(clock));
229fc219bfdSLuc Verhaegen 			continue;
230fc219bfdSLuc Verhaegen 		}
231fc219bfdSLuc Verhaegen 		par->clks[i] = clock;
232fc219bfdSLuc Verhaegen 	}
233fc219bfdSLuc Verhaegen 
234fc219bfdSLuc Verhaegen 	for (i = 0; i < par->clk_count; i++) {
235fc219bfdSLuc Verhaegen 		if (par->clks[i]) {
236fc219bfdSLuc Verhaegen 			ret = clk_prepare_enable(par->clks[i]);
237fc219bfdSLuc Verhaegen 			if (ret) {
238fc219bfdSLuc Verhaegen 				dev_err(&pdev->dev,
239fc219bfdSLuc Verhaegen 					"%s: failed to enable clock %d: %d\n",
240fc219bfdSLuc Verhaegen 					__func__, i, ret);
241fc219bfdSLuc Verhaegen 				clk_put(par->clks[i]);
242fc219bfdSLuc Verhaegen 				par->clks[i] = NULL;
243fc219bfdSLuc Verhaegen 			}
244fc219bfdSLuc Verhaegen 		}
245fc219bfdSLuc Verhaegen 	}
246fc219bfdSLuc Verhaegen 
247fc219bfdSLuc Verhaegen 	return 0;
248fc219bfdSLuc Verhaegen }
249fc219bfdSLuc Verhaegen 
250fc219bfdSLuc Verhaegen static void simplefb_clocks_destroy(struct simplefb_par *par)
251fc219bfdSLuc Verhaegen {
252fc219bfdSLuc Verhaegen 	int i;
253fc219bfdSLuc Verhaegen 
254fc219bfdSLuc Verhaegen 	if (!par->clks)
255fc219bfdSLuc Verhaegen 		return;
256fc219bfdSLuc Verhaegen 
257fc219bfdSLuc Verhaegen 	for (i = 0; i < par->clk_count; i++) {
258fc219bfdSLuc Verhaegen 		if (par->clks[i]) {
259fc219bfdSLuc Verhaegen 			clk_disable_unprepare(par->clks[i]);
260fc219bfdSLuc Verhaegen 			clk_put(par->clks[i]);
261fc219bfdSLuc Verhaegen 		}
262fc219bfdSLuc Verhaegen 	}
263fc219bfdSLuc Verhaegen 
264fc219bfdSLuc Verhaegen 	kfree(par->clks);
265fc219bfdSLuc Verhaegen }
266fc219bfdSLuc Verhaegen #else
267fc219bfdSLuc Verhaegen static int simplefb_clocks_init(struct simplefb_par *par,
268fc219bfdSLuc Verhaegen 	struct platform_device *pdev) { return 0; }
269fc219bfdSLuc Verhaegen static void simplefb_clocks_destroy(struct simplefb_par *par) { }
270fc219bfdSLuc Verhaegen #endif
271fc219bfdSLuc Verhaegen 
272f7018c21STomi Valkeinen static int simplefb_probe(struct platform_device *pdev)
273f7018c21STomi Valkeinen {
274f7018c21STomi Valkeinen 	int ret;
275f7018c21STomi Valkeinen 	struct simplefb_params params;
276f7018c21STomi Valkeinen 	struct fb_info *info;
2771270be4aSLuc Verhaegen 	struct simplefb_par *par;
278f7018c21STomi Valkeinen 	struct resource *mem;
279f7018c21STomi Valkeinen 
280f7018c21STomi Valkeinen 	if (fb_get_options("simplefb", NULL))
281f7018c21STomi Valkeinen 		return -ENODEV;
282f7018c21STomi Valkeinen 
283f7018c21STomi Valkeinen 	ret = -ENODEV;
284f7018c21STomi Valkeinen 	if (dev_get_platdata(&pdev->dev))
285f7018c21STomi Valkeinen 		ret = simplefb_parse_pd(pdev, &params);
286f7018c21STomi Valkeinen 	else if (pdev->dev.of_node)
287f7018c21STomi Valkeinen 		ret = simplefb_parse_dt(pdev, &params);
288f7018c21STomi Valkeinen 
289f7018c21STomi Valkeinen 	if (ret)
290f7018c21STomi Valkeinen 		return ret;
291f7018c21STomi Valkeinen 
292f7018c21STomi Valkeinen 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
293f7018c21STomi Valkeinen 	if (!mem) {
294f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "No memory resource\n");
295f7018c21STomi Valkeinen 		return -EINVAL;
296f7018c21STomi Valkeinen 	}
297f7018c21STomi Valkeinen 
2981270be4aSLuc Verhaegen 	info = framebuffer_alloc(sizeof(struct simplefb_par), &pdev->dev);
299f7018c21STomi Valkeinen 	if (!info)
300f7018c21STomi Valkeinen 		return -ENOMEM;
301f7018c21STomi Valkeinen 	platform_set_drvdata(pdev, info);
302f7018c21STomi Valkeinen 
3031270be4aSLuc Verhaegen 	par = info->par;
3041270be4aSLuc Verhaegen 
305f7018c21STomi Valkeinen 	info->fix = simplefb_fix;
306f7018c21STomi Valkeinen 	info->fix.smem_start = mem->start;
307f7018c21STomi Valkeinen 	info->fix.smem_len = resource_size(mem);
308f7018c21STomi Valkeinen 	info->fix.line_length = params.stride;
309f7018c21STomi Valkeinen 
310f7018c21STomi Valkeinen 	info->var = simplefb_var;
311f7018c21STomi Valkeinen 	info->var.xres = params.width;
312f7018c21STomi Valkeinen 	info->var.yres = params.height;
313f7018c21STomi Valkeinen 	info->var.xres_virtual = params.width;
314f7018c21STomi Valkeinen 	info->var.yres_virtual = params.height;
315f7018c21STomi Valkeinen 	info->var.bits_per_pixel = params.format->bits_per_pixel;
316f7018c21STomi Valkeinen 	info->var.red = params.format->red;
317f7018c21STomi Valkeinen 	info->var.green = params.format->green;
318f7018c21STomi Valkeinen 	info->var.blue = params.format->blue;
319f7018c21STomi Valkeinen 	info->var.transp = params.format->transp;
320f7018c21STomi Valkeinen 
321f7018c21STomi Valkeinen 	info->apertures = alloc_apertures(1);
322f7018c21STomi Valkeinen 	if (!info->apertures) {
323bf2fda15SLuc Verhaegen 		ret = -ENOMEM;
324bf2fda15SLuc Verhaegen 		goto error_fb_release;
325f7018c21STomi Valkeinen 	}
326f7018c21STomi Valkeinen 	info->apertures->ranges[0].base = info->fix.smem_start;
327f7018c21STomi Valkeinen 	info->apertures->ranges[0].size = info->fix.smem_len;
328f7018c21STomi Valkeinen 
329f7018c21STomi Valkeinen 	info->fbops = &simplefb_ops;
330f7018c21STomi Valkeinen 	info->flags = FBINFO_DEFAULT | FBINFO_MISC_FIRMWARE;
331f7018c21STomi Valkeinen 	info->screen_base = ioremap_wc(info->fix.smem_start,
332f7018c21STomi Valkeinen 				       info->fix.smem_len);
333f7018c21STomi Valkeinen 	if (!info->screen_base) {
334bf2fda15SLuc Verhaegen 		ret = -ENOMEM;
335bf2fda15SLuc Verhaegen 		goto error_fb_release;
336f7018c21STomi Valkeinen 	}
3371270be4aSLuc Verhaegen 	info->pseudo_palette = par->palette;
338f7018c21STomi Valkeinen 
339fc219bfdSLuc Verhaegen 	ret = simplefb_clocks_init(par, pdev);
340fc219bfdSLuc Verhaegen 	if (ret < 0)
341fc219bfdSLuc Verhaegen 		goto error_unmap;
342fc219bfdSLuc Verhaegen 
343f7018c21STomi Valkeinen 	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
344f7018c21STomi Valkeinen 			     info->fix.smem_start, info->fix.smem_len,
345f7018c21STomi Valkeinen 			     info->screen_base);
346f7018c21STomi Valkeinen 	dev_info(&pdev->dev, "format=%s, mode=%dx%dx%d, linelength=%d\n",
347f7018c21STomi Valkeinen 			     params.format->name,
348f7018c21STomi Valkeinen 			     info->var.xres, info->var.yres,
349f7018c21STomi Valkeinen 			     info->var.bits_per_pixel, info->fix.line_length);
350f7018c21STomi Valkeinen 
351f7018c21STomi Valkeinen 	ret = register_framebuffer(info);
352f7018c21STomi Valkeinen 	if (ret < 0) {
353f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
354fc219bfdSLuc Verhaegen 		goto error_clocks;
355f7018c21STomi Valkeinen 	}
356f7018c21STomi Valkeinen 
357f7018c21STomi Valkeinen 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
358f7018c21STomi Valkeinen 
359f7018c21STomi Valkeinen 	return 0;
360bf2fda15SLuc Verhaegen 
361fc219bfdSLuc Verhaegen error_clocks:
362fc219bfdSLuc Verhaegen 	simplefb_clocks_destroy(par);
363bf2fda15SLuc Verhaegen error_unmap:
364bf2fda15SLuc Verhaegen 	iounmap(info->screen_base);
365bf2fda15SLuc Verhaegen error_fb_release:
366bf2fda15SLuc Verhaegen 	framebuffer_release(info);
367bf2fda15SLuc Verhaegen 	return ret;
368f7018c21STomi Valkeinen }
369f7018c21STomi Valkeinen 
370f7018c21STomi Valkeinen static int simplefb_remove(struct platform_device *pdev)
371f7018c21STomi Valkeinen {
372f7018c21STomi Valkeinen 	struct fb_info *info = platform_get_drvdata(pdev);
373fc219bfdSLuc Verhaegen 	struct simplefb_par *par = info->par;
374f7018c21STomi Valkeinen 
375f7018c21STomi Valkeinen 	unregister_framebuffer(info);
376fc219bfdSLuc Verhaegen 	simplefb_clocks_destroy(par);
377f7018c21STomi Valkeinen 	framebuffer_release(info);
378f7018c21STomi Valkeinen 
379f7018c21STomi Valkeinen 	return 0;
380f7018c21STomi Valkeinen }
381f7018c21STomi Valkeinen 
382f7018c21STomi Valkeinen static const struct of_device_id simplefb_of_match[] = {
383f7018c21STomi Valkeinen 	{ .compatible = "simple-framebuffer", },
384f7018c21STomi Valkeinen 	{ },
385f7018c21STomi Valkeinen };
386f7018c21STomi Valkeinen MODULE_DEVICE_TABLE(of, simplefb_of_match);
387f7018c21STomi Valkeinen 
388f7018c21STomi Valkeinen static struct platform_driver simplefb_driver = {
389f7018c21STomi Valkeinen 	.driver = {
390f7018c21STomi Valkeinen 		.name = "simple-framebuffer",
391f7018c21STomi Valkeinen 		.of_match_table = simplefb_of_match,
392f7018c21STomi Valkeinen 	},
393f7018c21STomi Valkeinen 	.probe = simplefb_probe,
394f7018c21STomi Valkeinen 	.remove = simplefb_remove,
395f7018c21STomi Valkeinen };
39689c95001SHans de Goede 
39789c95001SHans de Goede static int __init simplefb_init(void)
39889c95001SHans de Goede {
39989c95001SHans de Goede 	int ret;
40089c95001SHans de Goede 	struct device_node *np;
40189c95001SHans de Goede 
40289c95001SHans de Goede 	ret = platform_driver_register(&simplefb_driver);
40389c95001SHans de Goede 	if (ret)
40489c95001SHans de Goede 		return ret;
40589c95001SHans de Goede 
406d9e02019SHans de Goede 	if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
40789c95001SHans de Goede 		for_each_child_of_node(of_chosen, np) {
40889c95001SHans de Goede 			if (of_device_is_compatible(np, "simple-framebuffer"))
40989c95001SHans de Goede 				of_platform_device_create(np, NULL, NULL);
41089c95001SHans de Goede 		}
41189c95001SHans de Goede 	}
41289c95001SHans de Goede 
41389c95001SHans de Goede 	return 0;
41489c95001SHans de Goede }
41589c95001SHans de Goede 
4160c5b240cSHans de Goede fs_initcall(simplefb_init);
417f7018c21STomi Valkeinen 
418f7018c21STomi Valkeinen MODULE_AUTHOR("Stephen Warren <[email protected]>");
419f7018c21STomi Valkeinen MODULE_DESCRIPTION("Simple framebuffer driver");
420f7018c21STomi Valkeinen MODULE_LICENSE("GPL v2");
421