Lines Matching +full:syscon +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0-or-later
9 #include <linux/clk.h>
17 #include <linux/mfd/syscon.h>
18 #include <linux/mfd/syscon/clps711x.h>
22 #define CLPS711X_FB_NAME "clps711x-fb"
34 struct clk *clk; member
36 struct regmap *syscon; member
47 struct clps711x_fb_info *cfb = info->par; in clps711x_fb_setcolreg()
50 if (regno >= BIT(info->var.bits_per_pixel)) in clps711x_fb_setcolreg()
51 return -EINVAL; in clps711x_fb_setcolreg()
57 if (cfb->cmap_invert) in clps711x_fb_setcolreg()
58 level = 0xf - level; in clps711x_fb_setcolreg()
62 writel((readl(cfb->base + regno) & ~mask) | level, cfb->base + regno); in clps711x_fb_setcolreg()
72 if (var->bits_per_pixel < 1 || in clps711x_fb_check_var()
73 var->bits_per_pixel > CLPS711X_FB_BPP_MAX) in clps711x_fb_check_var()
74 return -EINVAL; in clps711x_fb_check_var()
76 if (!var->pixclock) in clps711x_fb_check_var()
77 return -EINVAL; in clps711x_fb_check_var()
79 val = DIV_ROUND_UP(var->xres, 16) - 1; in clps711x_fb_check_var()
81 return -EINVAL; in clps711x_fb_check_var()
83 val = DIV_ROUND_UP(var->yres * var->xres * var->bits_per_pixel, 128); in clps711x_fb_check_var()
84 val--; in clps711x_fb_check_var()
86 return -EINVAL; in clps711x_fb_check_var()
88 var->transp.msb_right = 0; in clps711x_fb_check_var()
89 var->transp.offset = 0; in clps711x_fb_check_var()
90 var->transp.length = 0; in clps711x_fb_check_var()
91 var->red.msb_right = 0; in clps711x_fb_check_var()
92 var->red.offset = 0; in clps711x_fb_check_var()
93 var->red.length = var->bits_per_pixel; in clps711x_fb_check_var()
94 var->green = var->red; in clps711x_fb_check_var()
95 var->blue = var->red; in clps711x_fb_check_var()
96 var->grayscale = var->bits_per_pixel > 1; in clps711x_fb_check_var()
103 struct clps711x_fb_info *cfb = info->par; in clps711x_fb_set_par()
107 size = (info->var.xres * info->var.yres * info->var.bits_per_pixel) / 8; in clps711x_fb_set_par()
108 if (size > cfb->buffsize) in clps711x_fb_set_par()
109 return -EINVAL; in clps711x_fb_set_par()
111 switch (info->var.bits_per_pixel) { in clps711x_fb_set_par()
113 info->fix.visual = FB_VISUAL_MONO01; in clps711x_fb_set_par()
117 info->fix.visual = FB_VISUAL_PSEUDOCOLOR; in clps711x_fb_set_par()
120 return -EINVAL; in clps711x_fb_set_par()
123 info->fix.line_length = info->var.xres * info->var.bits_per_pixel / 8; in clps711x_fb_set_par()
124 info->fix.smem_len = size; in clps711x_fb_set_par()
126 lcdcon = (info->var.xres * info->var.yres * in clps711x_fb_set_par()
127 info->var.bits_per_pixel) / 128 - 1; in clps711x_fb_set_par()
128 lcdcon |= ((info->var.xres / 16) - 1) << 13; in clps711x_fb_set_par()
129 lcdcon |= (cfb->ac_prescale & 0x1f) << 25; in clps711x_fb_set_par()
131 pps = clk_get_rate(cfb->clk) / (PICOS2KHZ(info->var.pixclock) * 1000); in clps711x_fb_set_par()
133 pps--; in clps711x_fb_set_par()
136 if (info->var.bits_per_pixel == 4) in clps711x_fb_set_par()
138 if (info->var.bits_per_pixel >= 2) in clps711x_fb_set_par()
142 regmap_update_bits(cfb->syscon, SYSCON_OFFSET, SYSCON1_LCDEN, 0); in clps711x_fb_set_par()
143 writel(lcdcon, cfb->base + CLPS711X_LCDCON); in clps711x_fb_set_par()
144 regmap_update_bits(cfb->syscon, SYSCON_OFFSET, in clps711x_fb_set_par()
167 struct clps711x_fb_info *cfb = dev_get_drvdata(&lcddev->dev); in clps711x_lcd_check_fb()
169 return (!fi || fi->par == cfb) ? 1 : 0; in clps711x_lcd_check_fb()
174 struct clps711x_fb_info *cfb = dev_get_drvdata(&lcddev->dev); in clps711x_lcd_get_power()
176 if (!IS_ERR_OR_NULL(cfb->lcd_pwr)) in clps711x_lcd_get_power()
177 if (!regulator_is_enabled(cfb->lcd_pwr)) in clps711x_lcd_get_power()
185 struct clps711x_fb_info *cfb = dev_get_drvdata(&lcddev->dev); in clps711x_lcd_set_power()
187 if (!IS_ERR_OR_NULL(cfb->lcd_pwr)) { in clps711x_lcd_set_power()
189 if (!regulator_is_enabled(cfb->lcd_pwr)) in clps711x_lcd_set_power()
190 return regulator_enable(cfb->lcd_pwr); in clps711x_lcd_set_power()
192 if (regulator_is_enabled(cfb->lcd_pwr)) in clps711x_lcd_set_power()
193 return regulator_disable(cfb->lcd_pwr); in clps711x_lcd_set_power()
208 struct device *dev = &pdev->dev; in clps711x_fb_probe()
209 struct device_node *disp, *np = dev->of_node; in clps711x_fb_probe()
214 int ret = -ENOENT; in clps711x_fb_probe()
218 return -ENODEV; in clps711x_fb_probe()
222 return -ENOMEM; in clps711x_fb_probe()
224 cfb = info->par; in clps711x_fb_probe()
230 cfb->base = devm_ioremap(dev, res->start, resource_size(res)); in clps711x_fb_probe()
231 if (!cfb->base) { in clps711x_fb_probe()
232 ret = -ENOMEM; in clps711x_fb_probe()
236 info->fix.mmio_start = res->start; in clps711x_fb_probe()
237 info->fix.mmio_len = resource_size(res); in clps711x_fb_probe()
239 info->screen_base = devm_platform_get_and_ioremap_resource(pdev, 1, &res); in clps711x_fb_probe()
240 if (IS_ERR(info->screen_base)) { in clps711x_fb_probe()
241 ret = PTR_ERR(info->screen_base); in clps711x_fb_probe()
246 if (res->start & 0x0fffffff) { in clps711x_fb_probe()
247 ret = -EINVAL; in clps711x_fb_probe()
251 cfb->buffsize = resource_size(res); in clps711x_fb_probe()
252 info->fix.smem_start = res->start; in clps711x_fb_probe()
254 cfb->clk = devm_clk_get(dev, NULL); in clps711x_fb_probe()
255 if (IS_ERR(cfb->clk)) { in clps711x_fb_probe()
256 ret = PTR_ERR(cfb->clk); in clps711x_fb_probe()
260 cfb->syscon = syscon_regmap_lookup_by_phandle(np, "syscon"); in clps711x_fb_probe()
261 if (IS_ERR(cfb->syscon)) { in clps711x_fb_probe()
262 ret = PTR_ERR(cfb->syscon); in clps711x_fb_probe()
268 dev_err(&pdev->dev, "No display defined\n"); in clps711x_fb_probe()
269 ret = -ENODATA; in clps711x_fb_probe()
273 ret = of_get_fb_videomode(disp, &cfb->mode, OF_USE_NATIVE_MODE); in clps711x_fb_probe()
279 of_property_read_u32(disp, "ac-prescale", &cfb->ac_prescale); in clps711x_fb_probe()
280 cfb->cmap_invert = of_property_read_bool(disp, "cmap-invert"); in clps711x_fb_probe()
282 ret = of_property_read_u32(disp, "bits-per-pixel", in clps711x_fb_probe()
283 &info->var.bits_per_pixel); in clps711x_fb_probe()
289 if (info->fix.smem_start != (readb(cfb->base + CLPS711X_FBADDR) << 28)) in clps711x_fb_probe()
290 regmap_update_bits(cfb->syscon, SYSCON_OFFSET, in clps711x_fb_probe()
293 ret = regmap_read(cfb->syscon, SYSCON_OFFSET, &val); in clps711x_fb_probe()
299 writeb(info->fix.smem_start >> 28, cfb->base + CLPS711X_FBADDR); in clps711x_fb_probe()
301 memset_io(info->screen_base, 0, cfb->buffsize); in clps711x_fb_probe()
304 cfb->lcd_pwr = devm_regulator_get(dev, "lcd"); in clps711x_fb_probe()
305 if (PTR_ERR(cfb->lcd_pwr) == -EPROBE_DEFER) { in clps711x_fb_probe()
306 ret = -EPROBE_DEFER; in clps711x_fb_probe()
310 info->fbops = &clps711x_fb_ops; in clps711x_fb_probe()
311 info->var.activate = FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW; in clps711x_fb_probe()
312 info->var.height = -1; in clps711x_fb_probe()
313 info->var.width = -1; in clps711x_fb_probe()
314 info->var.vmode = FB_VMODE_NONINTERLACED; in clps711x_fb_probe()
315 info->fix.type = FB_TYPE_PACKED_PIXELS; in clps711x_fb_probe()
316 info->fix.accel = FB_ACCEL_NONE; in clps711x_fb_probe()
317 strscpy(info->fix.id, CLPS711X_FB_NAME, sizeof(info->fix.id)); in clps711x_fb_probe()
318 fb_videomode_to_var(&info->var, &cfb->mode); in clps711x_fb_probe()
320 ret = fb_alloc_cmap(&info->cmap, BIT(CLPS711X_FB_BPP_MAX), 0); in clps711x_fb_probe()
324 ret = fb_set_var(info, &info->var); in clps711x_fb_probe()
332 lcd = devm_lcd_device_register(dev, "clps711x-lcd", dev, cfb, in clps711x_fb_probe()
341 regmap_update_bits(cfb->syscon, SYSCON_OFFSET, SYSCON1_LCDEN, 0); in clps711x_fb_probe()
342 fb_dealloc_cmap(&info->cmap); in clps711x_fb_probe()
353 struct clps711x_fb_info *cfb = info->par; in clps711x_fb_remove()
355 regmap_update_bits(cfb->syscon, SYSCON_OFFSET, SYSCON1_LCDEN, 0); in clps711x_fb_remove()
358 fb_dealloc_cmap(&info->cmap); in clps711x_fb_remove()
363 { .compatible = "cirrus,ep7209-fb", },