xref: /linux-6.15/drivers/video/fbdev/simplefb.c (revision 0c5b240c)
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>
29fc219bfdSLuc Verhaegen #include <linux/clk-provider.h>
3089c95001SHans de Goede #include <linux/of_platform.h>
31f7018c21STomi Valkeinen 
32f7018c21STomi Valkeinen static struct fb_fix_screeninfo simplefb_fix = {
33f7018c21STomi Valkeinen 	.id		= "simple",
34f7018c21STomi Valkeinen 	.type		= FB_TYPE_PACKED_PIXELS,
35f7018c21STomi Valkeinen 	.visual		= FB_VISUAL_TRUECOLOR,
36f7018c21STomi Valkeinen 	.accel		= FB_ACCEL_NONE,
37f7018c21STomi Valkeinen };
38f7018c21STomi Valkeinen 
39f7018c21STomi Valkeinen static struct fb_var_screeninfo simplefb_var = {
40f7018c21STomi Valkeinen 	.height		= -1,
41f7018c21STomi Valkeinen 	.width		= -1,
42f7018c21STomi Valkeinen 	.activate	= FB_ACTIVATE_NOW,
43f7018c21STomi Valkeinen 	.vmode		= FB_VMODE_NONINTERLACED,
44f7018c21STomi Valkeinen };
45f7018c21STomi Valkeinen 
461270be4aSLuc Verhaegen #define PSEUDO_PALETTE_SIZE 16
471270be4aSLuc Verhaegen 
48f7018c21STomi Valkeinen static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
49f7018c21STomi Valkeinen 			      u_int transp, struct fb_info *info)
50f7018c21STomi Valkeinen {
51f7018c21STomi Valkeinen 	u32 *pal = info->pseudo_palette;
52f7018c21STomi Valkeinen 	u32 cr = red >> (16 - info->var.red.length);
53f7018c21STomi Valkeinen 	u32 cg = green >> (16 - info->var.green.length);
54f7018c21STomi Valkeinen 	u32 cb = blue >> (16 - info->var.blue.length);
55f7018c21STomi Valkeinen 	u32 value;
56f7018c21STomi Valkeinen 
571270be4aSLuc Verhaegen 	if (regno >= PSEUDO_PALETTE_SIZE)
58f7018c21STomi Valkeinen 		return -EINVAL;
59f7018c21STomi Valkeinen 
60f7018c21STomi Valkeinen 	value = (cr << info->var.red.offset) |
61f7018c21STomi Valkeinen 		(cg << info->var.green.offset) |
62f7018c21STomi Valkeinen 		(cb << info->var.blue.offset);
63f7018c21STomi Valkeinen 	if (info->var.transp.length > 0) {
64f7018c21STomi Valkeinen 		u32 mask = (1 << info->var.transp.length) - 1;
65f7018c21STomi Valkeinen 		mask <<= info->var.transp.offset;
66f7018c21STomi Valkeinen 		value |= mask;
67f7018c21STomi Valkeinen 	}
68f7018c21STomi Valkeinen 	pal[regno] = value;
69f7018c21STomi Valkeinen 
70f7018c21STomi Valkeinen 	return 0;
71f7018c21STomi Valkeinen }
72f7018c21STomi Valkeinen 
73f7018c21STomi Valkeinen static void simplefb_destroy(struct fb_info *info)
74f7018c21STomi Valkeinen {
75f7018c21STomi Valkeinen 	if (info->screen_base)
76f7018c21STomi Valkeinen 		iounmap(info->screen_base);
77f7018c21STomi Valkeinen }
78f7018c21STomi Valkeinen 
79f7018c21STomi Valkeinen static struct fb_ops simplefb_ops = {
80f7018c21STomi Valkeinen 	.owner		= THIS_MODULE,
81f7018c21STomi Valkeinen 	.fb_destroy	= simplefb_destroy,
82f7018c21STomi Valkeinen 	.fb_setcolreg	= simplefb_setcolreg,
83f7018c21STomi Valkeinen 	.fb_fillrect	= cfb_fillrect,
84f7018c21STomi Valkeinen 	.fb_copyarea	= cfb_copyarea,
85f7018c21STomi Valkeinen 	.fb_imageblit	= cfb_imageblit,
86f7018c21STomi Valkeinen };
87f7018c21STomi Valkeinen 
88f7018c21STomi Valkeinen static struct simplefb_format simplefb_formats[] = SIMPLEFB_FORMATS;
89f7018c21STomi Valkeinen 
90f7018c21STomi Valkeinen struct simplefb_params {
91f7018c21STomi Valkeinen 	u32 width;
92f7018c21STomi Valkeinen 	u32 height;
93f7018c21STomi Valkeinen 	u32 stride;
94f7018c21STomi Valkeinen 	struct simplefb_format *format;
95f7018c21STomi Valkeinen };
96f7018c21STomi Valkeinen 
97f7018c21STomi Valkeinen static int simplefb_parse_dt(struct platform_device *pdev,
98f7018c21STomi Valkeinen 			   struct simplefb_params *params)
99f7018c21STomi Valkeinen {
100f7018c21STomi Valkeinen 	struct device_node *np = pdev->dev.of_node;
101f7018c21STomi Valkeinen 	int ret;
102f7018c21STomi Valkeinen 	const char *format;
103f7018c21STomi Valkeinen 	int i;
104f7018c21STomi Valkeinen 
105f7018c21STomi Valkeinen 	ret = of_property_read_u32(np, "width", &params->width);
106f7018c21STomi Valkeinen 	if (ret) {
107f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse width property\n");
108f7018c21STomi Valkeinen 		return ret;
109f7018c21STomi Valkeinen 	}
110f7018c21STomi Valkeinen 
111f7018c21STomi Valkeinen 	ret = of_property_read_u32(np, "height", &params->height);
112f7018c21STomi Valkeinen 	if (ret) {
113f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse height property\n");
114f7018c21STomi Valkeinen 		return ret;
115f7018c21STomi Valkeinen 	}
116f7018c21STomi Valkeinen 
117f7018c21STomi Valkeinen 	ret = of_property_read_u32(np, "stride", &params->stride);
118f7018c21STomi Valkeinen 	if (ret) {
119f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse stride property\n");
120f7018c21STomi Valkeinen 		return ret;
121f7018c21STomi Valkeinen 	}
122f7018c21STomi Valkeinen 
123f7018c21STomi Valkeinen 	ret = of_property_read_string(np, "format", &format);
124f7018c21STomi Valkeinen 	if (ret) {
125f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Can't parse format property\n");
126f7018c21STomi Valkeinen 		return ret;
127f7018c21STomi Valkeinen 	}
128f7018c21STomi Valkeinen 	params->format = NULL;
129f7018c21STomi Valkeinen 	for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) {
130f7018c21STomi Valkeinen 		if (strcmp(format, simplefb_formats[i].name))
131f7018c21STomi Valkeinen 			continue;
132f7018c21STomi Valkeinen 		params->format = &simplefb_formats[i];
133f7018c21STomi Valkeinen 		break;
134f7018c21STomi Valkeinen 	}
135f7018c21STomi Valkeinen 	if (!params->format) {
136f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Invalid format value\n");
137f7018c21STomi Valkeinen 		return -EINVAL;
138f7018c21STomi Valkeinen 	}
139f7018c21STomi Valkeinen 
140f7018c21STomi Valkeinen 	return 0;
141f7018c21STomi Valkeinen }
142f7018c21STomi Valkeinen 
143f7018c21STomi Valkeinen static int simplefb_parse_pd(struct platform_device *pdev,
144f7018c21STomi Valkeinen 			     struct simplefb_params *params)
145f7018c21STomi Valkeinen {
146f7018c21STomi Valkeinen 	struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev);
147f7018c21STomi Valkeinen 	int i;
148f7018c21STomi Valkeinen 
149f7018c21STomi Valkeinen 	params->width = pd->width;
150f7018c21STomi Valkeinen 	params->height = pd->height;
151f7018c21STomi Valkeinen 	params->stride = pd->stride;
152f7018c21STomi Valkeinen 
153f7018c21STomi Valkeinen 	params->format = NULL;
154f7018c21STomi Valkeinen 	for (i = 0; i < ARRAY_SIZE(simplefb_formats); i++) {
155f7018c21STomi Valkeinen 		if (strcmp(pd->format, simplefb_formats[i].name))
156f7018c21STomi Valkeinen 			continue;
157f7018c21STomi Valkeinen 
158f7018c21STomi Valkeinen 		params->format = &simplefb_formats[i];
159f7018c21STomi Valkeinen 		break;
160f7018c21STomi Valkeinen 	}
161f7018c21STomi Valkeinen 
162f7018c21STomi Valkeinen 	if (!params->format) {
163f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Invalid format value\n");
164f7018c21STomi Valkeinen 		return -EINVAL;
165f7018c21STomi Valkeinen 	}
166f7018c21STomi Valkeinen 
167f7018c21STomi Valkeinen 	return 0;
168f7018c21STomi Valkeinen }
169f7018c21STomi Valkeinen 
1701270be4aSLuc Verhaegen struct simplefb_par {
1711270be4aSLuc Verhaegen 	u32 palette[PSEUDO_PALETTE_SIZE];
172fc219bfdSLuc Verhaegen #ifdef CONFIG_OF
173fc219bfdSLuc Verhaegen 	int clk_count;
174fc219bfdSLuc Verhaegen 	struct clk **clks;
175fc219bfdSLuc Verhaegen #endif
1761270be4aSLuc Verhaegen };
1771270be4aSLuc Verhaegen 
178fc219bfdSLuc Verhaegen #ifdef CONFIG_OF
179fc219bfdSLuc Verhaegen /*
180fc219bfdSLuc Verhaegen  * Clock handling code.
181fc219bfdSLuc Verhaegen  *
182fc219bfdSLuc Verhaegen  * Here we handle the clocks property of our "simple-framebuffer" dt node.
183fc219bfdSLuc Verhaegen  * This is necessary so that we can make sure that any clocks needed by
184fc219bfdSLuc Verhaegen  * the display engine that the bootloader set up for us (and for which it
185fc219bfdSLuc Verhaegen  * provided a simplefb dt node), stay up, for the life of the simplefb
186fc219bfdSLuc Verhaegen  * driver.
187fc219bfdSLuc Verhaegen  *
188fc219bfdSLuc Verhaegen  * When the driver unloads, we cleanly disable, and then release the clocks.
189fc219bfdSLuc Verhaegen  *
190fc219bfdSLuc Verhaegen  * We only complain about errors here, no action is taken as the most likely
191fc219bfdSLuc Verhaegen  * error can only happen due to a mismatch between the bootloader which set
192fc219bfdSLuc Verhaegen  * up simplefb, and the clock definitions in the device tree. Chances are
193fc219bfdSLuc Verhaegen  * that there are no adverse effects, and if there are, a clean teardown of
194fc219bfdSLuc Verhaegen  * the fb probe will not help us much either. So just complain and carry on,
195fc219bfdSLuc Verhaegen  * and hope that the user actually gets a working fb at the end of things.
196fc219bfdSLuc Verhaegen  */
197fc219bfdSLuc Verhaegen static int simplefb_clocks_init(struct simplefb_par *par,
198fc219bfdSLuc Verhaegen 				struct platform_device *pdev)
199fc219bfdSLuc Verhaegen {
200fc219bfdSLuc Verhaegen 	struct device_node *np = pdev->dev.of_node;
201fc219bfdSLuc Verhaegen 	struct clk *clock;
202fc219bfdSLuc Verhaegen 	int i, ret;
203fc219bfdSLuc Verhaegen 
204fc219bfdSLuc Verhaegen 	if (dev_get_platdata(&pdev->dev) || !np)
205fc219bfdSLuc Verhaegen 		return 0;
206fc219bfdSLuc Verhaegen 
207fc219bfdSLuc Verhaegen 	par->clk_count = of_clk_get_parent_count(np);
208fc219bfdSLuc Verhaegen 	if (par->clk_count <= 0)
209fc219bfdSLuc Verhaegen 		return 0;
210fc219bfdSLuc Verhaegen 
211fc219bfdSLuc Verhaegen 	par->clks = kcalloc(par->clk_count, sizeof(struct clk *), GFP_KERNEL);
212fc219bfdSLuc Verhaegen 	if (!par->clks)
213fc219bfdSLuc Verhaegen 		return -ENOMEM;
214fc219bfdSLuc Verhaegen 
215fc219bfdSLuc Verhaegen 	for (i = 0; i < par->clk_count; i++) {
216fc219bfdSLuc Verhaegen 		clock = of_clk_get(np, i);
217fc219bfdSLuc Verhaegen 		if (IS_ERR(clock)) {
218fc219bfdSLuc Verhaegen 			if (PTR_ERR(clock) == -EPROBE_DEFER) {
219fc219bfdSLuc Verhaegen 				while (--i >= 0) {
220fc219bfdSLuc Verhaegen 					if (par->clks[i])
221fc219bfdSLuc Verhaegen 						clk_put(par->clks[i]);
222fc219bfdSLuc Verhaegen 				}
223fc219bfdSLuc Verhaegen 				kfree(par->clks);
224fc219bfdSLuc Verhaegen 				return -EPROBE_DEFER;
225fc219bfdSLuc Verhaegen 			}
226fc219bfdSLuc Verhaegen 			dev_err(&pdev->dev, "%s: clock %d not found: %ld\n",
227fc219bfdSLuc Verhaegen 				__func__, i, PTR_ERR(clock));
228fc219bfdSLuc Verhaegen 			continue;
229fc219bfdSLuc Verhaegen 		}
230fc219bfdSLuc Verhaegen 		par->clks[i] = clock;
231fc219bfdSLuc Verhaegen 	}
232fc219bfdSLuc Verhaegen 
233fc219bfdSLuc Verhaegen 	for (i = 0; i < par->clk_count; i++) {
234fc219bfdSLuc Verhaegen 		if (par->clks[i]) {
235fc219bfdSLuc Verhaegen 			ret = clk_prepare_enable(par->clks[i]);
236fc219bfdSLuc Verhaegen 			if (ret) {
237fc219bfdSLuc Verhaegen 				dev_err(&pdev->dev,
238fc219bfdSLuc Verhaegen 					"%s: failed to enable clock %d: %d\n",
239fc219bfdSLuc Verhaegen 					__func__, i, ret);
240fc219bfdSLuc Verhaegen 				clk_put(par->clks[i]);
241fc219bfdSLuc Verhaegen 				par->clks[i] = NULL;
242fc219bfdSLuc Verhaegen 			}
243fc219bfdSLuc Verhaegen 		}
244fc219bfdSLuc Verhaegen 	}
245fc219bfdSLuc Verhaegen 
246fc219bfdSLuc Verhaegen 	return 0;
247fc219bfdSLuc Verhaegen }
248fc219bfdSLuc Verhaegen 
249fc219bfdSLuc Verhaegen static void simplefb_clocks_destroy(struct simplefb_par *par)
250fc219bfdSLuc Verhaegen {
251fc219bfdSLuc Verhaegen 	int i;
252fc219bfdSLuc Verhaegen 
253fc219bfdSLuc Verhaegen 	if (!par->clks)
254fc219bfdSLuc Verhaegen 		return;
255fc219bfdSLuc Verhaegen 
256fc219bfdSLuc Verhaegen 	for (i = 0; i < par->clk_count; i++) {
257fc219bfdSLuc Verhaegen 		if (par->clks[i]) {
258fc219bfdSLuc Verhaegen 			clk_disable_unprepare(par->clks[i]);
259fc219bfdSLuc Verhaegen 			clk_put(par->clks[i]);
260fc219bfdSLuc Verhaegen 		}
261fc219bfdSLuc Verhaegen 	}
262fc219bfdSLuc Verhaegen 
263fc219bfdSLuc Verhaegen 	kfree(par->clks);
264fc219bfdSLuc Verhaegen }
265fc219bfdSLuc Verhaegen #else
266fc219bfdSLuc Verhaegen static int simplefb_clocks_init(struct simplefb_par *par,
267fc219bfdSLuc Verhaegen 	struct platform_device *pdev) { return 0; }
268fc219bfdSLuc Verhaegen static void simplefb_clocks_destroy(struct simplefb_par *par) { }
269fc219bfdSLuc Verhaegen #endif
270fc219bfdSLuc Verhaegen 
271f7018c21STomi Valkeinen static int simplefb_probe(struct platform_device *pdev)
272f7018c21STomi Valkeinen {
273f7018c21STomi Valkeinen 	int ret;
274f7018c21STomi Valkeinen 	struct simplefb_params params;
275f7018c21STomi Valkeinen 	struct fb_info *info;
2761270be4aSLuc Verhaegen 	struct simplefb_par *par;
277f7018c21STomi Valkeinen 	struct resource *mem;
278f7018c21STomi Valkeinen 
279f7018c21STomi Valkeinen 	if (fb_get_options("simplefb", NULL))
280f7018c21STomi Valkeinen 		return -ENODEV;
281f7018c21STomi Valkeinen 
282f7018c21STomi Valkeinen 	ret = -ENODEV;
283f7018c21STomi Valkeinen 	if (dev_get_platdata(&pdev->dev))
284f7018c21STomi Valkeinen 		ret = simplefb_parse_pd(pdev, &params);
285f7018c21STomi Valkeinen 	else if (pdev->dev.of_node)
286f7018c21STomi Valkeinen 		ret = simplefb_parse_dt(pdev, &params);
287f7018c21STomi Valkeinen 
288f7018c21STomi Valkeinen 	if (ret)
289f7018c21STomi Valkeinen 		return ret;
290f7018c21STomi Valkeinen 
291f7018c21STomi Valkeinen 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
292f7018c21STomi Valkeinen 	if (!mem) {
293f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "No memory resource\n");
294f7018c21STomi Valkeinen 		return -EINVAL;
295f7018c21STomi Valkeinen 	}
296f7018c21STomi Valkeinen 
2971270be4aSLuc Verhaegen 	info = framebuffer_alloc(sizeof(struct simplefb_par), &pdev->dev);
298f7018c21STomi Valkeinen 	if (!info)
299f7018c21STomi Valkeinen 		return -ENOMEM;
300f7018c21STomi Valkeinen 	platform_set_drvdata(pdev, info);
301f7018c21STomi Valkeinen 
3021270be4aSLuc Verhaegen 	par = info->par;
3031270be4aSLuc Verhaegen 
304f7018c21STomi Valkeinen 	info->fix = simplefb_fix;
305f7018c21STomi Valkeinen 	info->fix.smem_start = mem->start;
306f7018c21STomi Valkeinen 	info->fix.smem_len = resource_size(mem);
307f7018c21STomi Valkeinen 	info->fix.line_length = params.stride;
308f7018c21STomi Valkeinen 
309f7018c21STomi Valkeinen 	info->var = simplefb_var;
310f7018c21STomi Valkeinen 	info->var.xres = params.width;
311f7018c21STomi Valkeinen 	info->var.yres = params.height;
312f7018c21STomi Valkeinen 	info->var.xres_virtual = params.width;
313f7018c21STomi Valkeinen 	info->var.yres_virtual = params.height;
314f7018c21STomi Valkeinen 	info->var.bits_per_pixel = params.format->bits_per_pixel;
315f7018c21STomi Valkeinen 	info->var.red = params.format->red;
316f7018c21STomi Valkeinen 	info->var.green = params.format->green;
317f7018c21STomi Valkeinen 	info->var.blue = params.format->blue;
318f7018c21STomi Valkeinen 	info->var.transp = params.format->transp;
319f7018c21STomi Valkeinen 
320f7018c21STomi Valkeinen 	info->apertures = alloc_apertures(1);
321f7018c21STomi Valkeinen 	if (!info->apertures) {
322bf2fda15SLuc Verhaegen 		ret = -ENOMEM;
323bf2fda15SLuc Verhaegen 		goto error_fb_release;
324f7018c21STomi Valkeinen 	}
325f7018c21STomi Valkeinen 	info->apertures->ranges[0].base = info->fix.smem_start;
326f7018c21STomi Valkeinen 	info->apertures->ranges[0].size = info->fix.smem_len;
327f7018c21STomi Valkeinen 
328f7018c21STomi Valkeinen 	info->fbops = &simplefb_ops;
329f7018c21STomi Valkeinen 	info->flags = FBINFO_DEFAULT | FBINFO_MISC_FIRMWARE;
330f7018c21STomi Valkeinen 	info->screen_base = ioremap_wc(info->fix.smem_start,
331f7018c21STomi Valkeinen 				       info->fix.smem_len);
332f7018c21STomi Valkeinen 	if (!info->screen_base) {
333bf2fda15SLuc Verhaegen 		ret = -ENOMEM;
334bf2fda15SLuc Verhaegen 		goto error_fb_release;
335f7018c21STomi Valkeinen 	}
3361270be4aSLuc Verhaegen 	info->pseudo_palette = par->palette;
337f7018c21STomi Valkeinen 
338fc219bfdSLuc Verhaegen 	ret = simplefb_clocks_init(par, pdev);
339fc219bfdSLuc Verhaegen 	if (ret < 0)
340fc219bfdSLuc Verhaegen 		goto error_unmap;
341fc219bfdSLuc Verhaegen 
342f7018c21STomi Valkeinen 	dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
343f7018c21STomi Valkeinen 			     info->fix.smem_start, info->fix.smem_len,
344f7018c21STomi Valkeinen 			     info->screen_base);
345f7018c21STomi Valkeinen 	dev_info(&pdev->dev, "format=%s, mode=%dx%dx%d, linelength=%d\n",
346f7018c21STomi Valkeinen 			     params.format->name,
347f7018c21STomi Valkeinen 			     info->var.xres, info->var.yres,
348f7018c21STomi Valkeinen 			     info->var.bits_per_pixel, info->fix.line_length);
349f7018c21STomi Valkeinen 
350f7018c21STomi Valkeinen 	ret = register_framebuffer(info);
351f7018c21STomi Valkeinen 	if (ret < 0) {
352f7018c21STomi Valkeinen 		dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret);
353fc219bfdSLuc Verhaegen 		goto error_clocks;
354f7018c21STomi Valkeinen 	}
355f7018c21STomi Valkeinen 
356f7018c21STomi Valkeinen 	dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
357f7018c21STomi Valkeinen 
358f7018c21STomi Valkeinen 	return 0;
359bf2fda15SLuc Verhaegen 
360fc219bfdSLuc Verhaegen error_clocks:
361fc219bfdSLuc Verhaegen 	simplefb_clocks_destroy(par);
362bf2fda15SLuc Verhaegen error_unmap:
363bf2fda15SLuc Verhaegen 	iounmap(info->screen_base);
364bf2fda15SLuc Verhaegen error_fb_release:
365bf2fda15SLuc Verhaegen 	framebuffer_release(info);
366bf2fda15SLuc Verhaegen 	return ret;
367f7018c21STomi Valkeinen }
368f7018c21STomi Valkeinen 
369f7018c21STomi Valkeinen static int simplefb_remove(struct platform_device *pdev)
370f7018c21STomi Valkeinen {
371f7018c21STomi Valkeinen 	struct fb_info *info = platform_get_drvdata(pdev);
372fc219bfdSLuc Verhaegen 	struct simplefb_par *par = info->par;
373f7018c21STomi Valkeinen 
374f7018c21STomi Valkeinen 	unregister_framebuffer(info);
375fc219bfdSLuc Verhaegen 	simplefb_clocks_destroy(par);
376f7018c21STomi Valkeinen 	framebuffer_release(info);
377f7018c21STomi Valkeinen 
378f7018c21STomi Valkeinen 	return 0;
379f7018c21STomi Valkeinen }
380f7018c21STomi Valkeinen 
381f7018c21STomi Valkeinen static const struct of_device_id simplefb_of_match[] = {
382f7018c21STomi Valkeinen 	{ .compatible = "simple-framebuffer", },
383f7018c21STomi Valkeinen 	{ },
384f7018c21STomi Valkeinen };
385f7018c21STomi Valkeinen MODULE_DEVICE_TABLE(of, simplefb_of_match);
386f7018c21STomi Valkeinen 
387f7018c21STomi Valkeinen static struct platform_driver simplefb_driver = {
388f7018c21STomi Valkeinen 	.driver = {
389f7018c21STomi Valkeinen 		.name = "simple-framebuffer",
390f7018c21STomi Valkeinen 		.owner = THIS_MODULE,
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 
40689c95001SHans de Goede 	if (IS_ENABLED(CONFIG_OF) && 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 
416*0c5b240cSHans 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