Lines Matching full:fb
19 #include <linux/fb.h>
33 #define to_clcd(info) container_of(info, struct clcd_fb, fb)
36 static const char *clcd_name = "CLCD FB";
51 static inline void clcdfb_set_start(struct clcd_fb *fb) in clcdfb_set_start() argument
53 unsigned long ustart = fb->fb.fix.smem_start; in clcdfb_set_start()
56 ustart += fb->fb.var.yoffset * fb->fb.fix.line_length; in clcdfb_set_start()
57 lstart = ustart + fb->fb.var.yres * fb->fb.fix.line_length / 2; in clcdfb_set_start()
59 writel(ustart, fb->regs + CLCD_UBAS); in clcdfb_set_start()
60 writel(lstart, fb->regs + CLCD_LBAS); in clcdfb_set_start()
63 static void clcdfb_disable(struct clcd_fb *fb) in clcdfb_disable() argument
67 if (fb->board->disable) in clcdfb_disable()
68 fb->board->disable(fb); in clcdfb_disable()
70 if (fb->panel->backlight) { in clcdfb_disable()
71 fb->panel->backlight->props.power = FB_BLANK_POWERDOWN; in clcdfb_disable()
72 backlight_update_status(fb->panel->backlight); in clcdfb_disable()
75 val = readl(fb->regs + fb->off_cntl); in clcdfb_disable()
78 writel(val, fb->regs + fb->off_cntl); in clcdfb_disable()
84 writel(val, fb->regs + fb->off_cntl); in clcdfb_disable()
90 if (fb->clk_enabled) { in clcdfb_disable()
91 fb->clk_enabled = false; in clcdfb_disable()
92 clk_disable(fb->clk); in clcdfb_disable()
96 static void clcdfb_enable(struct clcd_fb *fb, u32 cntl) in clcdfb_enable() argument
101 if (!fb->clk_enabled) { in clcdfb_enable()
102 fb->clk_enabled = true; in clcdfb_enable()
103 clk_enable(fb->clk); in clcdfb_enable()
110 writel(cntl, fb->regs + fb->off_cntl); in clcdfb_enable()
118 writel(cntl, fb->regs + fb->off_cntl); in clcdfb_enable()
123 if (fb->panel->backlight) { in clcdfb_enable()
124 fb->panel->backlight->props.power = FB_BLANK_UNBLANK; in clcdfb_enable()
125 backlight_update_status(fb->panel->backlight); in clcdfb_enable()
131 if (fb->board->enable) in clcdfb_enable()
132 fb->board->enable(fb); in clcdfb_enable()
136 clcdfb_set_bitfields(struct clcd_fb *fb, struct fb_var_screeninfo *var) in clcdfb_set_bitfields() argument
141 if (fb->panel->caps && fb->board->caps) in clcdfb_set_bitfields()
142 caps = fb->panel->caps & fb->board->caps; in clcdfb_set_bitfields()
145 caps = fb->panel->cntl & CNTL_BGR ? in clcdfb_set_bitfields()
152 if (!(fb->panel->cntl & CNTL_LCDTFT)) in clcdfb_set_bitfields()
275 struct clcd_fb *fb = to_clcd(info); in clcdfb_check_var() local
278 if (fb->board->check) in clcdfb_check_var()
279 ret = fb->board->check(fb, var); in clcdfb_check_var()
283 var->yres_virtual > fb->fb.fix.smem_len) in clcdfb_check_var()
287 ret = clcdfb_set_bitfields(fb, var); in clcdfb_check_var()
294 struct clcd_fb *fb = to_clcd(info); in clcdfb_set_par() local
297 fb->fb.fix.line_length = fb->fb.var.xres_virtual * in clcdfb_set_par()
298 fb->fb.var.bits_per_pixel / 8; in clcdfb_set_par()
300 if (fb->fb.var.bits_per_pixel <= 8) in clcdfb_set_par()
301 fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR; in clcdfb_set_par()
303 fb->fb.fix.visual = FB_VISUAL_TRUECOLOR; in clcdfb_set_par()
305 fb->board->decode(fb, ®s); in clcdfb_set_par()
307 clcdfb_disable(fb); in clcdfb_set_par()
309 writel(regs.tim0, fb->regs + CLCD_TIM0); in clcdfb_set_par()
310 writel(regs.tim1, fb->regs + CLCD_TIM1); in clcdfb_set_par()
311 writel(regs.tim2, fb->regs + CLCD_TIM2); in clcdfb_set_par()
312 writel(regs.tim3, fb->regs + CLCD_TIM3); in clcdfb_set_par()
314 clcdfb_set_start(fb); in clcdfb_set_par()
316 clk_set_rate(fb->clk, (1000000000 / regs.pixclock) * 1000); in clcdfb_set_par()
318 fb->clcd_cntl = regs.cntl; in clcdfb_set_par()
320 clcdfb_enable(fb, regs.cntl); in clcdfb_set_par()
327 readl(fb->regs + CLCD_TIM0), readl(fb->regs + CLCD_TIM1), in clcdfb_set_par()
328 readl(fb->regs + CLCD_TIM2), readl(fb->regs + CLCD_TIM3), in clcdfb_set_par()
329 readl(fb->regs + CLCD_UBAS), readl(fb->regs + CLCD_LBAS), in clcdfb_set_par()
330 readl(fb->regs + fb->off_ienb), readl(fb->regs + fb->off_cntl)); in clcdfb_set_par()
351 struct clcd_fb *fb = to_clcd(info); in clcdfb_setcolreg() local
354 fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) | in clcdfb_setcolreg()
355 convert_bitfield(blue, &fb->fb.var.blue) | in clcdfb_setcolreg()
356 convert_bitfield(green, &fb->fb.var.green) | in clcdfb_setcolreg()
357 convert_bitfield(red, &fb->fb.var.red); in clcdfb_setcolreg()
359 if (fb->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR && regno < 256) { in clcdfb_setcolreg()
371 if (fb->clcd_cntl & CNTL_BEBO) in clcdfb_setcolreg()
381 val = readl(fb->regs + hw_reg) & mask; in clcdfb_setcolreg()
382 writel(val | newval, fb->regs + hw_reg); in clcdfb_setcolreg()
400 struct clcd_fb *fb = to_clcd(info); in clcdfb_blank() local
403 clcdfb_disable(fb); in clcdfb_blank()
405 clcdfb_enable(fb, fb->clcd_cntl); in clcdfb_blank()
413 struct clcd_fb *fb = to_clcd(info); in clcdfb_mmap() local
420 fb->board->mmap) in clcdfb_mmap()
421 ret = fb->board->mmap(fb, vma); in clcdfb_mmap()
438 static int clcdfb_register(struct clcd_fb *fb) in clcdfb_register() argument
446 if (amba_manf(fb->dev) == 0x41 && amba_part(fb->dev) == 0x111) { in clcdfb_register()
447 fb->off_ienb = CLCD_PL111_IENB; in clcdfb_register()
448 fb->off_cntl = CLCD_PL111_CNTL; in clcdfb_register()
450 fb->off_ienb = CLCD_PL110_IENB; in clcdfb_register()
451 fb->off_cntl = CLCD_PL110_CNTL; in clcdfb_register()
454 fb->clk = clk_get(&fb->dev->dev, NULL); in clcdfb_register()
455 if (IS_ERR(fb->clk)) { in clcdfb_register()
456 ret = PTR_ERR(fb->clk); in clcdfb_register()
460 ret = clk_prepare(fb->clk); in clcdfb_register()
464 fb->fb.device = &fb->dev->dev; in clcdfb_register()
466 fb->fb.fix.mmio_start = fb->dev->res.start; in clcdfb_register()
467 fb->fb.fix.mmio_len = resource_size(&fb->dev->res); in clcdfb_register()
469 fb->regs = ioremap(fb->fb.fix.mmio_start, fb->fb.fix.mmio_len); in clcdfb_register()
470 if (!fb->regs) { in clcdfb_register()
476 fb->fb.fbops = &clcdfb_ops; in clcdfb_register()
477 fb->fb.flags = FBINFO_FLAG_DEFAULT; in clcdfb_register()
478 fb->fb.pseudo_palette = fb->cmap; in clcdfb_register()
480 strncpy(fb->fb.fix.id, clcd_name, sizeof(fb->fb.fix.id)); in clcdfb_register()
481 fb->fb.fix.type = FB_TYPE_PACKED_PIXELS; in clcdfb_register()
482 fb->fb.fix.type_aux = 0; in clcdfb_register()
483 fb->fb.fix.xpanstep = 0; in clcdfb_register()
484 fb->fb.fix.ypanstep = 0; in clcdfb_register()
485 fb->fb.fix.ywrapstep = 0; in clcdfb_register()
486 fb->fb.fix.accel = FB_ACCEL_NONE; in clcdfb_register()
488 fb->fb.var.xres = fb->panel->mode.xres; in clcdfb_register()
489 fb->fb.var.yres = fb->panel->mode.yres; in clcdfb_register()
490 fb->fb.var.xres_virtual = fb->panel->mode.xres; in clcdfb_register()
491 fb->fb.var.yres_virtual = fb->panel->mode.yres; in clcdfb_register()
492 fb->fb.var.bits_per_pixel = fb->panel->bpp; in clcdfb_register()
493 fb->fb.var.grayscale = fb->panel->grayscale; in clcdfb_register()
494 fb->fb.var.pixclock = fb->panel->mode.pixclock; in clcdfb_register()
495 fb->fb.var.left_margin = fb->panel->mode.left_margin; in clcdfb_register()
496 fb->fb.var.right_margin = fb->panel->mode.right_margin; in clcdfb_register()
497 fb->fb.var.upper_margin = fb->panel->mode.upper_margin; in clcdfb_register()
498 fb->fb.var.lower_margin = fb->panel->mode.lower_margin; in clcdfb_register()
499 fb->fb.var.hsync_len = fb->panel->mode.hsync_len; in clcdfb_register()
500 fb->fb.var.vsync_len = fb->panel->mode.vsync_len; in clcdfb_register()
501 fb->fb.var.sync = fb->panel->mode.sync; in clcdfb_register()
502 fb->fb.var.vmode = fb->panel->mode.vmode; in clcdfb_register()
503 fb->fb.var.activate = FB_ACTIVATE_NOW; in clcdfb_register()
504 fb->fb.var.nonstd = 0; in clcdfb_register()
505 fb->fb.var.height = fb->panel->height; in clcdfb_register()
506 fb->fb.var.width = fb->panel->width; in clcdfb_register()
507 fb->fb.var.accel_flags = 0; in clcdfb_register()
509 fb->fb.monspecs.hfmin = 0; in clcdfb_register()
510 fb->fb.monspecs.hfmax = 100000; in clcdfb_register()
511 fb->fb.monspecs.vfmin = 0; in clcdfb_register()
512 fb->fb.monspecs.vfmax = 400; in clcdfb_register()
513 fb->fb.monspecs.dclkmin = 1000000; in clcdfb_register()
514 fb->fb.monspecs.dclkmax = 100000000; in clcdfb_register()
519 clcdfb_set_bitfields(fb, &fb->fb.var); in clcdfb_register()
524 ret = fb_alloc_cmap(&fb->fb.cmap, 256, 0); in clcdfb_register()
531 writel(0, fb->regs + fb->off_ienb); in clcdfb_register()
533 fb_set_var(&fb->fb, &fb->fb.var); in clcdfb_register()
535 dev_info(&fb->dev->dev, "%s hardware, %s display\n", in clcdfb_register()
536 fb->board->name, fb->panel->mode.name); in clcdfb_register()
538 ret = register_framebuffer(&fb->fb); in clcdfb_register()
544 fb_dealloc_cmap(&fb->fb.cmap); in clcdfb_register()
546 iounmap(fb->regs); in clcdfb_register()
548 clk_unprepare(fb->clk); in clcdfb_register()
550 clk_put(fb->clk); in clcdfb_register()
647 static int clcdfb_of_init_tft_panel(struct clcd_fb *fb, u32 r0, u32 g0, u32 b0) in clcdfb_of_init_tft_panel() argument
667 fb->panel->tim2 |= TIM2_BCD; in clcdfb_of_init_tft_panel()
670 fb->panel->cntl |= CNTL_LCDTFT | CNTL_LCDVCOMP(1); in clcdfb_of_init_tft_panel()
672 fb->panel->caps = 0; in clcdfb_of_init_tft_panel()
675 for (i = 0; i < ARRAY_SIZE(panels) && !fb->panel->caps; i++) { in clcdfb_of_init_tft_panel()
676 if (amba_part(fb->dev) != panels[i].part) in clcdfb_of_init_tft_panel()
681 fb->panel->caps = panels[i].caps; in clcdfb_of_init_tft_panel()
689 fb->panel->bgr_connection = true; in clcdfb_of_init_tft_panel()
691 return fb->panel->caps ? 0 : -EINVAL; in clcdfb_of_init_tft_panel()
694 static int clcdfb_of_init_display(struct clcd_fb *fb) in clcdfb_of_init_display() argument
702 fb->panel = devm_kzalloc(&fb->dev->dev, sizeof(*fb->panel), GFP_KERNEL); in clcdfb_of_init_display()
703 if (!fb->panel) in clcdfb_of_init_display()
709 endpoint = of_graph_get_next_endpoint(fb->dev->dev.of_node, NULL); in clcdfb_of_init_display()
717 err = clcdfb_of_get_backlight(&fb->dev->dev, fb->panel); in clcdfb_of_init_display()
721 err = clcdfb_of_get_mode(&fb->dev->dev, panel, fb->panel); in clcdfb_of_init_display()
725 err = of_property_read_u32(fb->dev->dev.of_node, "max-memory-bandwidth", in clcdfb_of_init_display()
736 / PICOS2KHZ(fb->panel->mode.pixclock); in clcdfb_of_init_display()
742 fb->panel->bpp = bpp; in clcdfb_of_init_display()
745 fb->panel->cntl |= CNTL_BEBO; in clcdfb_of_init_display()
747 fb->panel->width = -1; in clcdfb_of_init_display()
748 fb->panel->height = -1; in clcdfb_of_init_display()
755 return clcdfb_of_init_tft_panel(fb, tft_r0b0g0[0], in clcdfb_of_init_display()
759 static int clcdfb_of_vram_setup(struct clcd_fb *fb) in clcdfb_of_vram_setup() argument
765 err = clcdfb_of_init_display(fb); in clcdfb_of_vram_setup()
769 memory = of_parse_phandle(fb->dev->dev.of_node, "memory-region", 0); in clcdfb_of_vram_setup()
773 fb->fb.screen_base = of_iomap(memory, 0); in clcdfb_of_vram_setup()
774 if (!fb->fb.screen_base) in clcdfb_of_vram_setup()
777 fb->fb.fix.smem_start = of_translate_address(memory, in clcdfb_of_vram_setup()
779 fb->fb.fix.smem_len = size; in clcdfb_of_vram_setup()
784 static int clcdfb_of_vram_mmap(struct clcd_fb *fb, struct vm_area_struct *vma) in clcdfb_of_vram_mmap() argument
791 kernel_size = fb->fb.fix.smem_len; in clcdfb_of_vram_mmap()
797 __phys_to_pfn(fb->fb.fix.smem_start) + vma->vm_pgoff, in clcdfb_of_vram_mmap()
802 static void clcdfb_of_vram_remove(struct clcd_fb *fb) in clcdfb_of_vram_remove() argument
804 iounmap(fb->fb.screen_base); in clcdfb_of_vram_remove()
807 static int clcdfb_of_dma_setup(struct clcd_fb *fb) in clcdfb_of_dma_setup() argument
813 err = clcdfb_of_init_display(fb); in clcdfb_of_dma_setup()
817 framesize = PAGE_ALIGN(fb->panel->mode.xres * fb->panel->mode.yres * in clcdfb_of_dma_setup()
818 fb->panel->bpp / 8); in clcdfb_of_dma_setup()
819 fb->fb.screen_base = dma_alloc_coherent(&fb->dev->dev, framesize, in clcdfb_of_dma_setup()
821 if (!fb->fb.screen_base) in clcdfb_of_dma_setup()
824 fb->fb.fix.smem_start = dma; in clcdfb_of_dma_setup()
825 fb->fb.fix.smem_len = framesize; in clcdfb_of_dma_setup()
830 static int clcdfb_of_dma_mmap(struct clcd_fb *fb, struct vm_area_struct *vma) in clcdfb_of_dma_mmap() argument
832 return dma_mmap_wc(&fb->dev->dev, vma, fb->fb.screen_base, in clcdfb_of_dma_mmap()
833 fb->fb.fix.smem_start, fb->fb.fix.smem_len); in clcdfb_of_dma_mmap()
836 static void clcdfb_of_dma_remove(struct clcd_fb *fb) in clcdfb_of_dma_remove() argument
838 dma_free_coherent(&fb->dev->dev, fb->fb.fix.smem_len, in clcdfb_of_dma_remove()
839 fb->fb.screen_base, fb->fb.fix.smem_start); in clcdfb_of_dma_remove()
877 struct clcd_fb *fb; in clcdfb_probe() local
896 fb = kzalloc(sizeof(*fb), GFP_KERNEL); in clcdfb_probe()
897 if (!fb) { in clcdfb_probe()
902 fb->dev = dev; in clcdfb_probe()
903 fb->board = board; in clcdfb_probe()
905 dev_info(&fb->dev->dev, "PL%03x designer %02x rev%u at 0x%08llx\n", in clcdfb_probe()
909 ret = fb->board->setup(fb); in clcdfb_probe()
913 ret = clcdfb_register(fb); in clcdfb_probe()
915 amba_set_drvdata(dev, fb); in clcdfb_probe()
919 fb->board->remove(fb); in clcdfb_probe()
921 kfree(fb); in clcdfb_probe()
930 struct clcd_fb *fb = amba_get_drvdata(dev); in clcdfb_remove() local
932 clcdfb_disable(fb); in clcdfb_remove()
933 unregister_framebuffer(&fb->fb); in clcdfb_remove()
934 if (fb->fb.cmap.len) in clcdfb_remove()
935 fb_dealloc_cmap(&fb->fb.cmap); in clcdfb_remove()
936 iounmap(fb->regs); in clcdfb_remove()
937 clk_unprepare(fb->clk); in clcdfb_remove()
938 clk_put(fb->clk); in clcdfb_remove()
940 fb->board->remove(fb); in clcdfb_remove()
942 kfree(fb); in clcdfb_remove()