12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2ef74d46aSAlexander Shiyan /*
3ef74d46aSAlexander Shiyan * Cirrus Logic CLPS711X FB driver
4ef74d46aSAlexander Shiyan *
5ef74d46aSAlexander Shiyan * Copyright (C) 2014 Alexander Shiyan <shc_work@mail.ru>
6ef74d46aSAlexander Shiyan * Based on driver by Russell King <rmk@arm.linux.org.uk>
7ef74d46aSAlexander Shiyan */
8ef74d46aSAlexander Shiyan
9ef74d46aSAlexander Shiyan #include <linux/clk.h>
10ef74d46aSAlexander Shiyan #include <linux/fb.h>
11ef74d46aSAlexander Shiyan #include <linux/io.h>
12ef74d46aSAlexander Shiyan #include <linux/lcd.h>
13ef74d46aSAlexander Shiyan #include <linux/module.h>
14ef74d46aSAlexander Shiyan #include <linux/of.h>
15ef74d46aSAlexander Shiyan #include <linux/platform_device.h>
16ef74d46aSAlexander Shiyan #include <linux/regmap.h>
17ef74d46aSAlexander Shiyan #include <linux/mfd/syscon.h>
18ef74d46aSAlexander Shiyan #include <linux/mfd/syscon/clps711x.h>
19ef74d46aSAlexander Shiyan #include <linux/regulator/consumer.h>
20ef74d46aSAlexander Shiyan #include <video/of_display_timing.h>
21ef74d46aSAlexander Shiyan
22ef74d46aSAlexander Shiyan #define CLPS711X_FB_NAME "clps711x-fb"
23ef74d46aSAlexander Shiyan #define CLPS711X_FB_BPP_MAX (4)
24ef74d46aSAlexander Shiyan
25ef74d46aSAlexander Shiyan /* Registers relative to LCDCON */
26ef74d46aSAlexander Shiyan #define CLPS711X_LCDCON (0x0000)
27ef74d46aSAlexander Shiyan # define LCDCON_GSEN BIT(30)
28ef74d46aSAlexander Shiyan # define LCDCON_GSMD BIT(31)
29ef74d46aSAlexander Shiyan #define CLPS711X_PALLSW (0x0280)
30ef74d46aSAlexander Shiyan #define CLPS711X_PALMSW (0x02c0)
31ef74d46aSAlexander Shiyan #define CLPS711X_FBADDR (0x0d40)
32ef74d46aSAlexander Shiyan
33ef74d46aSAlexander Shiyan struct clps711x_fb_info {
34ef74d46aSAlexander Shiyan struct clk *clk;
35ef74d46aSAlexander Shiyan void __iomem *base;
36ef74d46aSAlexander Shiyan struct regmap *syscon;
37ef74d46aSAlexander Shiyan resource_size_t buffsize;
38ef74d46aSAlexander Shiyan struct fb_videomode mode;
39ef74d46aSAlexander Shiyan struct regulator *lcd_pwr;
40ef74d46aSAlexander Shiyan u32 ac_prescale;
41ef74d46aSAlexander Shiyan bool cmap_invert;
42ef74d46aSAlexander Shiyan };
43ef74d46aSAlexander Shiyan
clps711x_fb_setcolreg(u_int regno,u_int red,u_int green,u_int blue,u_int transp,struct fb_info * info)44ef74d46aSAlexander Shiyan static int clps711x_fb_setcolreg(u_int regno, u_int red, u_int green,
45ef74d46aSAlexander Shiyan u_int blue, u_int transp, struct fb_info *info)
46ef74d46aSAlexander Shiyan {
47ef74d46aSAlexander Shiyan struct clps711x_fb_info *cfb = info->par;
48ef74d46aSAlexander Shiyan u32 level, mask, shift;
49ef74d46aSAlexander Shiyan
50ef74d46aSAlexander Shiyan if (regno >= BIT(info->var.bits_per_pixel))
51ef74d46aSAlexander Shiyan return -EINVAL;
52ef74d46aSAlexander Shiyan
53ef74d46aSAlexander Shiyan shift = 4 * (regno & 7);
54ef74d46aSAlexander Shiyan mask = 0xf << shift;
55ef74d46aSAlexander Shiyan /* gray = 0.30*R + 0.58*G + 0.11*B */
56ef74d46aSAlexander Shiyan level = (((red * 77 + green * 151 + blue * 28) >> 20) << shift) & mask;
57ef74d46aSAlexander Shiyan if (cfb->cmap_invert)
58ef74d46aSAlexander Shiyan level = 0xf - level;
59ef74d46aSAlexander Shiyan
60ef74d46aSAlexander Shiyan regno = (regno < 8) ? CLPS711X_PALLSW : CLPS711X_PALMSW;
61ef74d46aSAlexander Shiyan
62ef74d46aSAlexander Shiyan writel((readl(cfb->base + regno) & ~mask) | level, cfb->base + regno);
63ef74d46aSAlexander Shiyan
64ef74d46aSAlexander Shiyan return 0;
65ef74d46aSAlexander Shiyan }
66ef74d46aSAlexander Shiyan
clps711x_fb_check_var(struct fb_var_screeninfo * var,struct fb_info * info)67ef74d46aSAlexander Shiyan static int clps711x_fb_check_var(struct fb_var_screeninfo *var,
68ef74d46aSAlexander Shiyan struct fb_info *info)
69ef74d46aSAlexander Shiyan {
70ef74d46aSAlexander Shiyan u32 val;
71ef74d46aSAlexander Shiyan
72ef74d46aSAlexander Shiyan if (var->bits_per_pixel < 1 ||
73ef74d46aSAlexander Shiyan var->bits_per_pixel > CLPS711X_FB_BPP_MAX)
74ef74d46aSAlexander Shiyan return -EINVAL;
75ef74d46aSAlexander Shiyan
76ef74d46aSAlexander Shiyan if (!var->pixclock)
77ef74d46aSAlexander Shiyan return -EINVAL;
78ef74d46aSAlexander Shiyan
79ef74d46aSAlexander Shiyan val = DIV_ROUND_UP(var->xres, 16) - 1;
80ef74d46aSAlexander Shiyan if (val < 0x01 || val > 0x3f)
81ef74d46aSAlexander Shiyan return -EINVAL;
82ef74d46aSAlexander Shiyan
83ef74d46aSAlexander Shiyan val = DIV_ROUND_UP(var->yres * var->xres * var->bits_per_pixel, 128);
84ef74d46aSAlexander Shiyan val--;
85ef74d46aSAlexander Shiyan if (val < 0x001 || val > 0x1fff)
86ef74d46aSAlexander Shiyan return -EINVAL;
87ef74d46aSAlexander Shiyan
88ef74d46aSAlexander Shiyan var->transp.msb_right = 0;
89ef74d46aSAlexander Shiyan var->transp.offset = 0;
90ef74d46aSAlexander Shiyan var->transp.length = 0;
91ef74d46aSAlexander Shiyan var->red.msb_right = 0;
92ef74d46aSAlexander Shiyan var->red.offset = 0;
93ef74d46aSAlexander Shiyan var->red.length = var->bits_per_pixel;
94ef74d46aSAlexander Shiyan var->green = var->red;
95ef74d46aSAlexander Shiyan var->blue = var->red;
96ef74d46aSAlexander Shiyan var->grayscale = var->bits_per_pixel > 1;
97ef74d46aSAlexander Shiyan
98ef74d46aSAlexander Shiyan return 0;
99ef74d46aSAlexander Shiyan }
100ef74d46aSAlexander Shiyan
clps711x_fb_set_par(struct fb_info * info)101ef74d46aSAlexander Shiyan static int clps711x_fb_set_par(struct fb_info *info)
102ef74d46aSAlexander Shiyan {
103ef74d46aSAlexander Shiyan struct clps711x_fb_info *cfb = info->par;
104ef74d46aSAlexander Shiyan resource_size_t size;
105ef74d46aSAlexander Shiyan u32 lcdcon, pps;
106ef74d46aSAlexander Shiyan
107ef74d46aSAlexander Shiyan size = (info->var.xres * info->var.yres * info->var.bits_per_pixel) / 8;
108ef74d46aSAlexander Shiyan if (size > cfb->buffsize)
109ef74d46aSAlexander Shiyan return -EINVAL;
110ef74d46aSAlexander Shiyan
111ef74d46aSAlexander Shiyan switch (info->var.bits_per_pixel) {
112ef74d46aSAlexander Shiyan case 1:
113ef74d46aSAlexander Shiyan info->fix.visual = FB_VISUAL_MONO01;
114ef74d46aSAlexander Shiyan break;
115ef74d46aSAlexander Shiyan case 2:
116ef74d46aSAlexander Shiyan case 4:
117ef74d46aSAlexander Shiyan info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
118ef74d46aSAlexander Shiyan break;
119ef74d46aSAlexander Shiyan default:
120ef74d46aSAlexander Shiyan return -EINVAL;
121ef74d46aSAlexander Shiyan }
122ef74d46aSAlexander Shiyan
123ef74d46aSAlexander Shiyan info->fix.line_length = info->var.xres * info->var.bits_per_pixel / 8;
124ef74d46aSAlexander Shiyan info->fix.smem_len = size;
125ef74d46aSAlexander Shiyan
126ef74d46aSAlexander Shiyan lcdcon = (info->var.xres * info->var.yres *
127ef74d46aSAlexander Shiyan info->var.bits_per_pixel) / 128 - 1;
128ef74d46aSAlexander Shiyan lcdcon |= ((info->var.xres / 16) - 1) << 13;
129ef74d46aSAlexander Shiyan lcdcon |= (cfb->ac_prescale & 0x1f) << 25;
130ef74d46aSAlexander Shiyan
131ef74d46aSAlexander Shiyan pps = clk_get_rate(cfb->clk) / (PICOS2KHZ(info->var.pixclock) * 1000);
132ef74d46aSAlexander Shiyan if (pps)
133ef74d46aSAlexander Shiyan pps--;
134ef74d46aSAlexander Shiyan lcdcon |= (pps & 0x3f) << 19;
135ef74d46aSAlexander Shiyan
136ef74d46aSAlexander Shiyan if (info->var.bits_per_pixel == 4)
137ef74d46aSAlexander Shiyan lcdcon |= LCDCON_GSMD;
138ef74d46aSAlexander Shiyan if (info->var.bits_per_pixel >= 2)
139ef74d46aSAlexander Shiyan lcdcon |= LCDCON_GSEN;
140ef74d46aSAlexander Shiyan
141ef74d46aSAlexander Shiyan /* LCDCON must only be changed while the LCD is disabled */
142ef74d46aSAlexander Shiyan regmap_update_bits(cfb->syscon, SYSCON_OFFSET, SYSCON1_LCDEN, 0);
143ef74d46aSAlexander Shiyan writel(lcdcon, cfb->base + CLPS711X_LCDCON);
144ef74d46aSAlexander Shiyan regmap_update_bits(cfb->syscon, SYSCON_OFFSET,
145ef74d46aSAlexander Shiyan SYSCON1_LCDEN, SYSCON1_LCDEN);
146ef74d46aSAlexander Shiyan
147ef74d46aSAlexander Shiyan return 0;
148ef74d46aSAlexander Shiyan }
149ef74d46aSAlexander Shiyan
clps711x_fb_blank(int blank,struct fb_info * info)150ef74d46aSAlexander Shiyan static int clps711x_fb_blank(int blank, struct fb_info *info)
151ef74d46aSAlexander Shiyan {
152ef74d46aSAlexander Shiyan /* Return happy */
153ef74d46aSAlexander Shiyan return 0;
154ef74d46aSAlexander Shiyan }
155ef74d46aSAlexander Shiyan
1568a48ac33SJani Nikula static const struct fb_ops clps711x_fb_ops = {
157ef74d46aSAlexander Shiyan .owner = THIS_MODULE,
158ef74d46aSAlexander Shiyan .fb_setcolreg = clps711x_fb_setcolreg,
159ef74d46aSAlexander Shiyan .fb_check_var = clps711x_fb_check_var,
160ef74d46aSAlexander Shiyan .fb_set_par = clps711x_fb_set_par,
161ef74d46aSAlexander Shiyan .fb_blank = clps711x_fb_blank,
162ef74d46aSAlexander Shiyan .fb_fillrect = sys_fillrect,
163ef74d46aSAlexander Shiyan .fb_copyarea = sys_copyarea,
164ef74d46aSAlexander Shiyan .fb_imageblit = sys_imageblit,
165ef74d46aSAlexander Shiyan };
166ef74d46aSAlexander Shiyan
clps711x_lcd_check_fb(struct lcd_device * lcddev,struct fb_info * fi)167ef74d46aSAlexander Shiyan static int clps711x_lcd_check_fb(struct lcd_device *lcddev, struct fb_info *fi)
168ef74d46aSAlexander Shiyan {
169ef74d46aSAlexander Shiyan struct clps711x_fb_info *cfb = dev_get_drvdata(&lcddev->dev);
170ef74d46aSAlexander Shiyan
171ef74d46aSAlexander Shiyan return (!fi || fi->par == cfb) ? 1 : 0;
172ef74d46aSAlexander Shiyan }
173ef74d46aSAlexander Shiyan
clps711x_lcd_get_power(struct lcd_device * lcddev)174ef74d46aSAlexander Shiyan static int clps711x_lcd_get_power(struct lcd_device *lcddev)
175ef74d46aSAlexander Shiyan {
176ef74d46aSAlexander Shiyan struct clps711x_fb_info *cfb = dev_get_drvdata(&lcddev->dev);
177ef74d46aSAlexander Shiyan
178ef74d46aSAlexander Shiyan if (!IS_ERR_OR_NULL(cfb->lcd_pwr))
179ef74d46aSAlexander Shiyan if (!regulator_is_enabled(cfb->lcd_pwr))
180ef74d46aSAlexander Shiyan return FB_BLANK_NORMAL;
181ef74d46aSAlexander Shiyan
182ef74d46aSAlexander Shiyan return FB_BLANK_UNBLANK;
183ef74d46aSAlexander Shiyan }
184ef74d46aSAlexander Shiyan
clps711x_lcd_set_power(struct lcd_device * lcddev,int blank)185ef74d46aSAlexander Shiyan static int clps711x_lcd_set_power(struct lcd_device *lcddev, int blank)
186ef74d46aSAlexander Shiyan {
187ef74d46aSAlexander Shiyan struct clps711x_fb_info *cfb = dev_get_drvdata(&lcddev->dev);
188ef74d46aSAlexander Shiyan
189ef74d46aSAlexander Shiyan if (!IS_ERR_OR_NULL(cfb->lcd_pwr)) {
190ef74d46aSAlexander Shiyan if (blank == FB_BLANK_UNBLANK) {
191ef74d46aSAlexander Shiyan if (!regulator_is_enabled(cfb->lcd_pwr))
192ef74d46aSAlexander Shiyan return regulator_enable(cfb->lcd_pwr);
193ef74d46aSAlexander Shiyan } else {
194ef74d46aSAlexander Shiyan if (regulator_is_enabled(cfb->lcd_pwr))
195ef74d46aSAlexander Shiyan return regulator_disable(cfb->lcd_pwr);
196ef74d46aSAlexander Shiyan }
197ef74d46aSAlexander Shiyan }
198ef74d46aSAlexander Shiyan
199ef74d46aSAlexander Shiyan return 0;
200ef74d46aSAlexander Shiyan }
201ef74d46aSAlexander Shiyan
202ef74d46aSAlexander Shiyan static struct lcd_ops clps711x_lcd_ops = {
203ef74d46aSAlexander Shiyan .check_fb = clps711x_lcd_check_fb,
204ef74d46aSAlexander Shiyan .get_power = clps711x_lcd_get_power,
205ef74d46aSAlexander Shiyan .set_power = clps711x_lcd_set_power,
206ef74d46aSAlexander Shiyan };
207ef74d46aSAlexander Shiyan
clps711x_fb_probe(struct platform_device * pdev)208ef74d46aSAlexander Shiyan static int clps711x_fb_probe(struct platform_device *pdev)
209ef74d46aSAlexander Shiyan {
210ef74d46aSAlexander Shiyan struct device *dev = &pdev->dev;
211ef74d46aSAlexander Shiyan struct device_node *disp, *np = dev->of_node;
212ef74d46aSAlexander Shiyan struct clps711x_fb_info *cfb;
213ef74d46aSAlexander Shiyan struct lcd_device *lcd;
214ef74d46aSAlexander Shiyan struct fb_info *info;
215ef74d46aSAlexander Shiyan struct resource *res;
216ef74d46aSAlexander Shiyan int ret = -ENOENT;
217ef74d46aSAlexander Shiyan u32 val;
218ef74d46aSAlexander Shiyan
219ef74d46aSAlexander Shiyan if (fb_get_options(CLPS711X_FB_NAME, NULL))
220ef74d46aSAlexander Shiyan return -ENODEV;
221ef74d46aSAlexander Shiyan
222ef74d46aSAlexander Shiyan info = framebuffer_alloc(sizeof(*cfb), dev);
223ef74d46aSAlexander Shiyan if (!info)
224ef74d46aSAlexander Shiyan return -ENOMEM;
225ef74d46aSAlexander Shiyan
226ef74d46aSAlexander Shiyan cfb = info->par;
227ef74d46aSAlexander Shiyan platform_set_drvdata(pdev, info);
228ef74d46aSAlexander Shiyan
229ef74d46aSAlexander Shiyan res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
230ef74d46aSAlexander Shiyan if (!res)
231ef74d46aSAlexander Shiyan goto out_fb_release;
232ef74d46aSAlexander Shiyan cfb->base = devm_ioremap(dev, res->start, resource_size(res));
233ef74d46aSAlexander Shiyan if (!cfb->base) {
234ef74d46aSAlexander Shiyan ret = -ENOMEM;
235ef74d46aSAlexander Shiyan goto out_fb_release;
236ef74d46aSAlexander Shiyan }
237ef74d46aSAlexander Shiyan
238ef74d46aSAlexander Shiyan info->fix.mmio_start = res->start;
239ef74d46aSAlexander Shiyan info->fix.mmio_len = resource_size(res);
240ef74d46aSAlexander Shiyan
2417eb1220fSYang Li info->screen_base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
242ef74d46aSAlexander Shiyan if (IS_ERR(info->screen_base)) {
243ef74d46aSAlexander Shiyan ret = PTR_ERR(info->screen_base);
244ef74d46aSAlexander Shiyan goto out_fb_release;
245ef74d46aSAlexander Shiyan }
246ef74d46aSAlexander Shiyan
247ef74d46aSAlexander Shiyan /* Physical address should be aligned to 256 MiB */
248ef74d46aSAlexander Shiyan if (res->start & 0x0fffffff) {
249ef74d46aSAlexander Shiyan ret = -EINVAL;
250ef74d46aSAlexander Shiyan goto out_fb_release;
251ef74d46aSAlexander Shiyan }
252ef74d46aSAlexander Shiyan
253ef74d46aSAlexander Shiyan cfb->buffsize = resource_size(res);
254ef74d46aSAlexander Shiyan info->fix.smem_start = res->start;
255ef74d46aSAlexander Shiyan
256ef74d46aSAlexander Shiyan cfb->clk = devm_clk_get(dev, NULL);
257ef74d46aSAlexander Shiyan if (IS_ERR(cfb->clk)) {
258ef74d46aSAlexander Shiyan ret = PTR_ERR(cfb->clk);
259ef74d46aSAlexander Shiyan goto out_fb_release;
260ef74d46aSAlexander Shiyan }
261ef74d46aSAlexander Shiyan
2626fbe0cc5SAlexander Shiyan cfb->syscon = syscon_regmap_lookup_by_phandle(np, "syscon");
263ef74d46aSAlexander Shiyan if (IS_ERR(cfb->syscon)) {
264ef74d46aSAlexander Shiyan ret = PTR_ERR(cfb->syscon);
265ef74d46aSAlexander Shiyan goto out_fb_release;
266ef74d46aSAlexander Shiyan }
267ef74d46aSAlexander Shiyan
268ef74d46aSAlexander Shiyan disp = of_parse_phandle(np, "display", 0);
269ef74d46aSAlexander Shiyan if (!disp) {
270ef74d46aSAlexander Shiyan dev_err(&pdev->dev, "No display defined\n");
271ef74d46aSAlexander Shiyan ret = -ENODATA;
272ef74d46aSAlexander Shiyan goto out_fb_release;
273ef74d46aSAlexander Shiyan }
274ef74d46aSAlexander Shiyan
275ef74d46aSAlexander Shiyan ret = of_get_fb_videomode(disp, &cfb->mode, OF_USE_NATIVE_MODE);
276fdac7513SAlexey Khoroshilov if (ret) {
277fdac7513SAlexey Khoroshilov of_node_put(disp);
278ef74d46aSAlexander Shiyan goto out_fb_release;
279fdac7513SAlexey Khoroshilov }
280ef74d46aSAlexander Shiyan
281ef74d46aSAlexander Shiyan of_property_read_u32(disp, "ac-prescale", &cfb->ac_prescale);
282ef74d46aSAlexander Shiyan cfb->cmap_invert = of_property_read_bool(disp, "cmap-invert");
283ef74d46aSAlexander Shiyan
284ef74d46aSAlexander Shiyan ret = of_property_read_u32(disp, "bits-per-pixel",
285ef74d46aSAlexander Shiyan &info->var.bits_per_pixel);
286fdac7513SAlexey Khoroshilov of_node_put(disp);
287ef74d46aSAlexander Shiyan if (ret)
288ef74d46aSAlexander Shiyan goto out_fb_release;
289ef74d46aSAlexander Shiyan
290ef74d46aSAlexander Shiyan /* Force disable LCD on any mismatch */
291ef74d46aSAlexander Shiyan if (info->fix.smem_start != (readb(cfb->base + CLPS711X_FBADDR) << 28))
292ef74d46aSAlexander Shiyan regmap_update_bits(cfb->syscon, SYSCON_OFFSET,
293ef74d46aSAlexander Shiyan SYSCON1_LCDEN, 0);
294ef74d46aSAlexander Shiyan
295ef74d46aSAlexander Shiyan ret = regmap_read(cfb->syscon, SYSCON_OFFSET, &val);
296ef74d46aSAlexander Shiyan if (ret)
297ef74d46aSAlexander Shiyan goto out_fb_release;
298ef74d46aSAlexander Shiyan
299ef74d46aSAlexander Shiyan if (!(val & SYSCON1_LCDEN)) {
300ef74d46aSAlexander Shiyan /* Setup start FB address */
301ef74d46aSAlexander Shiyan writeb(info->fix.smem_start >> 28, cfb->base + CLPS711X_FBADDR);
302ef74d46aSAlexander Shiyan /* Clean FB memory */
303b1f46dd1SAlexander Shiyan memset_io(info->screen_base, 0, cfb->buffsize);
304ef74d46aSAlexander Shiyan }
305ef74d46aSAlexander Shiyan
306ef74d46aSAlexander Shiyan cfb->lcd_pwr = devm_regulator_get(dev, "lcd");
307ef74d46aSAlexander Shiyan if (PTR_ERR(cfb->lcd_pwr) == -EPROBE_DEFER) {
308ef74d46aSAlexander Shiyan ret = -EPROBE_DEFER;
309ef74d46aSAlexander Shiyan goto out_fb_release;
310ef74d46aSAlexander Shiyan }
311ef74d46aSAlexander Shiyan
312ef74d46aSAlexander Shiyan info->fbops = &clps711x_fb_ops;
313ef74d46aSAlexander Shiyan info->var.activate = FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
314ef74d46aSAlexander Shiyan info->var.height = -1;
315ef74d46aSAlexander Shiyan info->var.width = -1;
316ef74d46aSAlexander Shiyan info->var.vmode = FB_VMODE_NONINTERLACED;
317ef74d46aSAlexander Shiyan info->fix.type = FB_TYPE_PACKED_PIXELS;
318ef74d46aSAlexander Shiyan info->fix.accel = FB_ACCEL_NONE;
3198d026858SWolfram Sang strscpy(info->fix.id, CLPS711X_FB_NAME, sizeof(info->fix.id));
320ef74d46aSAlexander Shiyan fb_videomode_to_var(&info->var, &cfb->mode);
321ef74d46aSAlexander Shiyan
322ef74d46aSAlexander Shiyan ret = fb_alloc_cmap(&info->cmap, BIT(CLPS711X_FB_BPP_MAX), 0);
323ef74d46aSAlexander Shiyan if (ret)
324ef74d46aSAlexander Shiyan goto out_fb_release;
325ef74d46aSAlexander Shiyan
326ef74d46aSAlexander Shiyan ret = fb_set_var(info, &info->var);
327ef74d46aSAlexander Shiyan if (ret)
328ef74d46aSAlexander Shiyan goto out_fb_dealloc_cmap;
329ef74d46aSAlexander Shiyan
330ef74d46aSAlexander Shiyan ret = register_framebuffer(info);
331ef74d46aSAlexander Shiyan if (ret)
332ef74d46aSAlexander Shiyan goto out_fb_dealloc_cmap;
333ef74d46aSAlexander Shiyan
334ef74d46aSAlexander Shiyan lcd = devm_lcd_device_register(dev, "clps711x-lcd", dev, cfb,
335ef74d46aSAlexander Shiyan &clps711x_lcd_ops);
336ef74d46aSAlexander Shiyan if (!IS_ERR(lcd))
337ef74d46aSAlexander Shiyan return 0;
338ef74d46aSAlexander Shiyan
339ef74d46aSAlexander Shiyan ret = PTR_ERR(lcd);
340ef74d46aSAlexander Shiyan unregister_framebuffer(info);
341ef74d46aSAlexander Shiyan
342ef74d46aSAlexander Shiyan out_fb_dealloc_cmap:
343ef74d46aSAlexander Shiyan regmap_update_bits(cfb->syscon, SYSCON_OFFSET, SYSCON1_LCDEN, 0);
344ef74d46aSAlexander Shiyan fb_dealloc_cmap(&info->cmap);
345ef74d46aSAlexander Shiyan
346ef74d46aSAlexander Shiyan out_fb_release:
347ef74d46aSAlexander Shiyan framebuffer_release(info);
348ef74d46aSAlexander Shiyan
349ef74d46aSAlexander Shiyan return ret;
350ef74d46aSAlexander Shiyan }
351ef74d46aSAlexander Shiyan
clps711x_fb_remove(struct platform_device * pdev)352*fdc757feSUwe Kleine-König static void clps711x_fb_remove(struct platform_device *pdev)
353ef74d46aSAlexander Shiyan {
354ef74d46aSAlexander Shiyan struct fb_info *info = platform_get_drvdata(pdev);
355ef74d46aSAlexander Shiyan struct clps711x_fb_info *cfb = info->par;
356ef74d46aSAlexander Shiyan
357ef74d46aSAlexander Shiyan regmap_update_bits(cfb->syscon, SYSCON_OFFSET, SYSCON1_LCDEN, 0);
358ef74d46aSAlexander Shiyan
359ef74d46aSAlexander Shiyan unregister_framebuffer(info);
360ef74d46aSAlexander Shiyan fb_dealloc_cmap(&info->cmap);
361ef74d46aSAlexander Shiyan framebuffer_release(info);
362ef74d46aSAlexander Shiyan }
363ef74d46aSAlexander Shiyan
364ef74d46aSAlexander Shiyan static const struct of_device_id clps711x_fb_dt_ids[] = {
365564c9741SAlexander Shiyan { .compatible = "cirrus,ep7209-fb", },
366ef74d46aSAlexander Shiyan { }
367ef74d46aSAlexander Shiyan };
368ef74d46aSAlexander Shiyan MODULE_DEVICE_TABLE(of, clps711x_fb_dt_ids);
369ef74d46aSAlexander Shiyan
370ef74d46aSAlexander Shiyan static struct platform_driver clps711x_fb_driver = {
371ef74d46aSAlexander Shiyan .driver = {
372ef74d46aSAlexander Shiyan .name = CLPS711X_FB_NAME,
373ef74d46aSAlexander Shiyan .of_match_table = clps711x_fb_dt_ids,
374ef74d46aSAlexander Shiyan },
375ef74d46aSAlexander Shiyan .probe = clps711x_fb_probe,
376*fdc757feSUwe Kleine-König .remove_new = clps711x_fb_remove,
377ef74d46aSAlexander Shiyan };
378ef74d46aSAlexander Shiyan module_platform_driver(clps711x_fb_driver);
379ef74d46aSAlexander Shiyan
380ef74d46aSAlexander Shiyan MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
381ef74d46aSAlexander Shiyan MODULE_DESCRIPTION("Cirrus Logic CLPS711X FB driver");
382ef74d46aSAlexander Shiyan MODULE_LICENSE("GPL");
383