Lines Matching +full:sync +full:- +full:on +full:- +full:green +full:- +full:active
2 * linux/drivers/video/amba-clcd.c
18 #include <linux/dma-mapping.h>
40 unsigned long ustart = fb->fb.fix.smem_start; in clcdfb_set_start()
43 ustart += fb->fb.var.yoffset * fb->fb.fix.line_length; in clcdfb_set_start()
44 lstart = ustart + fb->fb.var.yres * fb->fb.fix.line_length / 2; in clcdfb_set_start()
46 writel(ustart, fb->regs + CLCD_UBAS); in clcdfb_set_start()
47 writel(lstart, fb->regs + CLCD_LBAS); in clcdfb_set_start()
54 if (fb->board->disable) in clcdfb_disable()
55 fb->board->disable(fb); in clcdfb_disable()
57 if (fb->panel->backlight) { in clcdfb_disable()
58 fb->panel->backlight->props.power = FB_BLANK_POWERDOWN; in clcdfb_disable()
59 backlight_update_status(fb->panel->backlight); in clcdfb_disable()
62 val = readl(fb->regs + fb->off_cntl); in clcdfb_disable()
65 writel(val, fb->regs + fb->off_cntl); in clcdfb_disable()
71 writel(val, fb->regs + fb->off_cntl); in clcdfb_disable()
77 if (fb->clk_enabled) { in clcdfb_disable()
78 fb->clk_enabled = false; in clcdfb_disable()
79 clk_disable(fb->clk); in clcdfb_disable()
88 if (!fb->clk_enabled) { in clcdfb_enable()
89 fb->clk_enabled = true; in clcdfb_enable()
90 clk_enable(fb->clk); in clcdfb_enable()
97 writel(cntl, fb->regs + fb->off_cntl); in clcdfb_enable()
105 writel(cntl, fb->regs + fb->off_cntl); in clcdfb_enable()
108 * Turn on backlight in clcdfb_enable()
110 if (fb->panel->backlight) { in clcdfb_enable()
111 fb->panel->backlight->props.power = FB_BLANK_UNBLANK; in clcdfb_enable()
112 backlight_update_status(fb->panel->backlight); in clcdfb_enable()
118 if (fb->board->enable) in clcdfb_enable()
119 fb->board->enable(fb); in clcdfb_enable()
128 if (fb->panel->caps && fb->board->caps) in clcdfb_set_bitfields()
129 caps = fb->panel->caps & fb->board->caps; in clcdfb_set_bitfields()
132 caps = fb->panel->cntl & CNTL_BGR ? in clcdfb_set_bitfields()
139 if (!(fb->panel->cntl & CNTL_LCDTFT)) in clcdfb_set_bitfields()
142 memset(&var->transp, 0, sizeof(var->transp)); in clcdfb_set_bitfields()
144 var->red.msb_right = 0; in clcdfb_set_bitfields()
145 var->green.msb_right = 0; in clcdfb_set_bitfields()
146 var->blue.msb_right = 0; in clcdfb_set_bitfields()
148 switch (var->bits_per_pixel) { in clcdfb_set_bitfields()
156 ret = -EINVAL; in clcdfb_set_bitfields()
160 var->red.length = var->bits_per_pixel; in clcdfb_set_bitfields()
161 var->red.offset = 0; in clcdfb_set_bitfields()
162 var->green.length = var->bits_per_pixel; in clcdfb_set_bitfields()
163 var->green.offset = 0; in clcdfb_set_bitfields()
164 var->blue.length = var->bits_per_pixel; in clcdfb_set_bitfields()
165 var->blue.offset = 0; in clcdfb_set_bitfields()
171 ret = -EINVAL; in clcdfb_set_bitfields()
176 * Green length can be 4, 5 or 6 depending whether in clcdfb_set_bitfields()
179 if (var->green.length == 4 && caps & CLCD_CAP_444) in clcdfb_set_bitfields()
181 if (var->green.length == 5 && caps & CLCD_CAP_5551) in clcdfb_set_bitfields()
183 else if (var->green.length == 6 && caps & CLCD_CAP_565) in clcdfb_set_bitfields()
191 var->green.length = 6; in clcdfb_set_bitfields()
194 var->green.length = 5; in clcdfb_set_bitfields()
197 var->green.length = 4; in clcdfb_set_bitfields()
202 if (var->green.length >= 5) { in clcdfb_set_bitfields()
203 var->red.length = 5; in clcdfb_set_bitfields()
204 var->blue.length = 5; in clcdfb_set_bitfields()
206 var->red.length = 4; in clcdfb_set_bitfields()
207 var->blue.length = 4; in clcdfb_set_bitfields()
214 ret = -EINVAL; in clcdfb_set_bitfields()
218 var->red.length = 8; in clcdfb_set_bitfields()
219 var->green.length = 8; in clcdfb_set_bitfields()
220 var->blue.length = 8; in clcdfb_set_bitfields()
223 ret = -EINVAL; in clcdfb_set_bitfields()
232 if (ret == 0 && var->bits_per_pixel >= 16) { in clcdfb_set_bitfields()
235 bgr = caps & CLCD_CAP_BGR && var->blue.offset == 0; in clcdfb_set_bitfields()
236 rgb = caps & CLCD_CAP_RGB && var->red.offset == 0; in clcdfb_set_bitfields()
247 var->blue.offset = 0; in clcdfb_set_bitfields()
248 var->green.offset = var->blue.offset + var->blue.length; in clcdfb_set_bitfields()
249 var->red.offset = var->green.offset + var->green.length; in clcdfb_set_bitfields()
251 var->red.offset = 0; in clcdfb_set_bitfields()
252 var->green.offset = var->red.offset + var->red.length; in clcdfb_set_bitfields()
253 var->blue.offset = var->green.offset + var->green.length; in clcdfb_set_bitfields()
263 int ret = -EINVAL; in clcdfb_check_var()
265 if (fb->board->check) in clcdfb_check_var()
266 ret = fb->board->check(fb, var); in clcdfb_check_var()
269 var->xres_virtual * var->bits_per_pixel / 8 * in clcdfb_check_var()
270 var->yres_virtual > fb->fb.fix.smem_len) in clcdfb_check_var()
271 ret = -EINVAL; in clcdfb_check_var()
284 fb->fb.fix.line_length = fb->fb.var.xres_virtual * in clcdfb_set_par()
285 fb->fb.var.bits_per_pixel / 8; in clcdfb_set_par()
287 if (fb->fb.var.bits_per_pixel <= 8) in clcdfb_set_par()
288 fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR; in clcdfb_set_par()
290 fb->fb.fix.visual = FB_VISUAL_TRUECOLOR; in clcdfb_set_par()
292 fb->board->decode(fb, ®s); in clcdfb_set_par()
296 writel(regs.tim0, fb->regs + CLCD_TIM0); in clcdfb_set_par()
297 writel(regs.tim1, fb->regs + CLCD_TIM1); in clcdfb_set_par()
298 writel(regs.tim2, fb->regs + CLCD_TIM2); in clcdfb_set_par()
299 writel(regs.tim3, fb->regs + CLCD_TIM3); in clcdfb_set_par()
303 clk_set_rate(fb->clk, (1000000000 / regs.pixclock) * 1000); in clcdfb_set_par()
305 fb->clcd_cntl = regs.cntl; in clcdfb_set_par()
314 readl(fb->regs + CLCD_TIM0), readl(fb->regs + CLCD_TIM1), in clcdfb_set_par()
315 readl(fb->regs + CLCD_TIM2), readl(fb->regs + CLCD_TIM3), in clcdfb_set_par()
316 readl(fb->regs + CLCD_UBAS), readl(fb->regs + CLCD_LBAS), in clcdfb_set_par()
317 readl(fb->regs + fb->off_ienb), readl(fb->regs + fb->off_cntl)); in clcdfb_set_par()
325 unsigned int mask = (1 << bf->length) - 1; in convert_bitfield()
327 return (val >> (16 - bf->length) & mask) << bf->offset; in convert_bitfield()
335 clcdfb_setcolreg(unsigned int regno, unsigned int red, unsigned int green, in clcdfb_setcolreg() argument
341 fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) | in clcdfb_setcolreg()
342 convert_bitfield(blue, &fb->fb.var.blue) | in clcdfb_setcolreg()
343 convert_bitfield(green, &fb->fb.var.green) | in clcdfb_setcolreg()
344 convert_bitfield(red, &fb->fb.var.red); in clcdfb_setcolreg()
346 if (fb->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR && regno < 256) { in clcdfb_setcolreg()
351 newval |= (green >> 6) & 0x03e0; in clcdfb_setcolreg()
358 if (fb->clcd_cntl & CNTL_BEBO) in clcdfb_setcolreg()
368 val = readl(fb->regs + hw_reg) & mask; in clcdfb_setcolreg()
369 writel(val | newval, fb->regs + hw_reg); in clcdfb_setcolreg()
378 * black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due
380 * and powerdown modes on hardware that supports disabling hsync/vsync:
392 clcdfb_enable(fb, fb->clcd_cntl); in clcdfb_blank()
401 unsigned long len, off = vma->vm_pgoff << PAGE_SHIFT; in clcdfb_mmap()
402 int ret = -EINVAL; in clcdfb_mmap()
404 len = info->fix.smem_len; in clcdfb_mmap()
406 if (off <= len && vma->vm_end - vma->vm_start <= len - off && in clcdfb_mmap()
407 fb->board->mmap) in clcdfb_mmap()
408 ret = fb->board->mmap(fb, vma); in clcdfb_mmap()
431 * which is reversed on some platforms. in clcdfb_register()
433 if (amba_manf(fb->dev) == 0x41 && amba_part(fb->dev) == 0x111) { in clcdfb_register()
434 fb->off_ienb = CLCD_PL111_IENB; in clcdfb_register()
435 fb->off_cntl = CLCD_PL111_CNTL; in clcdfb_register()
437 fb->off_ienb = CLCD_PL110_IENB; in clcdfb_register()
438 fb->off_cntl = CLCD_PL110_CNTL; in clcdfb_register()
441 fb->clk = clk_get(&fb->dev->dev, NULL); in clcdfb_register()
442 if (IS_ERR(fb->clk)) { in clcdfb_register()
443 ret = PTR_ERR(fb->clk); in clcdfb_register()
447 ret = clk_prepare(fb->clk); in clcdfb_register()
451 fb->fb.device = &fb->dev->dev; in clcdfb_register()
453 fb->fb.fix.mmio_start = fb->dev->res.start; in clcdfb_register()
454 fb->fb.fix.mmio_len = resource_size(&fb->dev->res); in clcdfb_register()
456 fb->regs = ioremap(fb->fb.fix.mmio_start, fb->fb.fix.mmio_len); in clcdfb_register()
457 if (!fb->regs) { in clcdfb_register()
459 ret = -ENOMEM; in clcdfb_register()
463 fb->fb.fbops = &clcdfb_ops; in clcdfb_register()
464 fb->fb.flags = FBINFO_FLAG_DEFAULT; in clcdfb_register()
465 fb->fb.pseudo_palette = fb->cmap; in clcdfb_register()
467 strncpy(fb->fb.fix.id, clcd_name, sizeof(fb->fb.fix.id)); in clcdfb_register()
468 fb->fb.fix.type = FB_TYPE_PACKED_PIXELS; in clcdfb_register()
469 fb->fb.fix.type_aux = 0; in clcdfb_register()
470 fb->fb.fix.xpanstep = 0; in clcdfb_register()
471 fb->fb.fix.ypanstep = 0; in clcdfb_register()
472 fb->fb.fix.ywrapstep = 0; in clcdfb_register()
473 fb->fb.fix.accel = FB_ACCEL_NONE; in clcdfb_register()
475 fb->fb.var.xres = fb->panel->mode.xres; in clcdfb_register()
476 fb->fb.var.yres = fb->panel->mode.yres; in clcdfb_register()
477 fb->fb.var.xres_virtual = fb->panel->mode.xres; in clcdfb_register()
478 fb->fb.var.yres_virtual = fb->panel->mode.yres; in clcdfb_register()
479 fb->fb.var.bits_per_pixel = fb->panel->bpp; in clcdfb_register()
480 fb->fb.var.grayscale = fb->panel->grayscale; in clcdfb_register()
481 fb->fb.var.pixclock = fb->panel->mode.pixclock; in clcdfb_register()
482 fb->fb.var.left_margin = fb->panel->mode.left_margin; in clcdfb_register()
483 fb->fb.var.right_margin = fb->panel->mode.right_margin; in clcdfb_register()
484 fb->fb.var.upper_margin = fb->panel->mode.upper_margin; in clcdfb_register()
485 fb->fb.var.lower_margin = fb->panel->mode.lower_margin; in clcdfb_register()
486 fb->fb.var.hsync_len = fb->panel->mode.hsync_len; in clcdfb_register()
487 fb->fb.var.vsync_len = fb->panel->mode.vsync_len; in clcdfb_register()
488 fb->fb.var.sync = fb->panel->mode.sync; in clcdfb_register()
489 fb->fb.var.vmode = fb->panel->mode.vmode; in clcdfb_register()
490 fb->fb.var.activate = FB_ACTIVATE_NOW; in clcdfb_register()
491 fb->fb.var.nonstd = 0; in clcdfb_register()
492 fb->fb.var.height = fb->panel->height; in clcdfb_register()
493 fb->fb.var.width = fb->panel->width; in clcdfb_register()
494 fb->fb.var.accel_flags = 0; in clcdfb_register()
496 fb->fb.monspecs.hfmin = 0; in clcdfb_register()
497 fb->fb.monspecs.hfmax = 100000; in clcdfb_register()
498 fb->fb.monspecs.vfmin = 0; in clcdfb_register()
499 fb->fb.monspecs.vfmax = 400; in clcdfb_register()
500 fb->fb.monspecs.dclkmin = 1000000; in clcdfb_register()
501 fb->fb.monspecs.dclkmax = 100000000; in clcdfb_register()
506 clcdfb_set_bitfields(fb, &fb->fb.var); in clcdfb_register()
511 ret = fb_alloc_cmap(&fb->fb.cmap, 256, 0); in clcdfb_register()
518 writel(0, fb->regs + fb->off_ienb); in clcdfb_register()
520 fb_set_var(&fb->fb, &fb->fb.var); in clcdfb_register()
522 dev_info(&fb->dev->dev, "%s hardware, %s display\n", in clcdfb_register()
523 fb->board->name, fb->panel->mode.name); in clcdfb_register()
525 ret = register_framebuffer(&fb->fb); in clcdfb_register()
531 fb_dealloc_cmap(&fb->fb.cmap); in clcdfb_register()
533 iounmap(fb->regs); in clcdfb_register()
535 clk_unprepare(fb->clk); in clcdfb_register()
537 clk_put(fb->clk); in clcdfb_register()
550 err = of_get_display_timing(node, "panel-timing", &timing); in clcdfb_of_get_dpi_panel_mode()
552 pr_err("%pOF: problems parsing panel-timing (%d)\n", node, err); in clcdfb_of_get_dpi_panel_mode()
558 err = fb_videomode_from_videomode(&video, &clcd_panel->mode); in clcdfb_of_get_dpi_panel_mode()
564 clcd_panel->tim2 |= TIM2_IPC; in clcdfb_of_get_dpi_panel_mode()
568 * pixel clock) flag needs to be set on any display that in clcdfb_of_get_dpi_panel_mode()
570 * active on the negative or positive edge. in clcdfb_of_get_dpi_panel_mode()
572 clcd_panel->tim2 |= TIM2_IPC; in clcdfb_of_get_dpi_panel_mode()
575 clcd_panel->tim2 |= TIM2_IHS; in clcdfb_of_get_dpi_panel_mode()
578 clcd_panel->tim2 |= TIM2_IVS; in clcdfb_of_get_dpi_panel_mode()
581 clcd_panel->tim2 |= TIM2_IOE; in clcdfb_of_get_dpi_panel_mode()
588 return snprintf(buf, size, "%ux%u@%u", mode->xres, mode->yres, in clcdfb_snprintf_mode()
589 mode->refresh); in clcdfb_snprintf_mode()
602 clcd_panel->backlight = backlight; in clcdfb_of_get_backlight()
615 if (of_device_is_compatible(panel, "panel-dpi")) in clcdfb_of_get_mode()
618 err = -ENOENT; in clcdfb_of_get_mode()
621 mode = &clcd_panel->mode; in clcdfb_of_get_mode()
626 return -ENOMEM; in clcdfb_of_get_mode()
629 mode->name = name; in clcdfb_of_get_mode()
654 fb->panel->tim2 |= TIM2_BCD; in clcdfb_of_init_tft_panel()
657 fb->panel->cntl |= CNTL_LCDTFT | CNTL_LCDVCOMP(1); in clcdfb_of_init_tft_panel()
659 fb->panel->caps = 0; in clcdfb_of_init_tft_panel()
662 for (i = 0; i < ARRAY_SIZE(panels) && !fb->panel->caps; i++) { in clcdfb_of_init_tft_panel()
663 if (amba_part(fb->dev) != panels[i].part) in clcdfb_of_init_tft_panel()
668 fb->panel->caps = panels[i].caps; in clcdfb_of_init_tft_panel()
676 fb->panel->bgr_connection = true; in clcdfb_of_init_tft_panel()
678 return fb->panel->caps ? 0 : -EINVAL; in clcdfb_of_init_tft_panel()
689 fb->panel = devm_kzalloc(&fb->dev->dev, sizeof(*fb->panel), GFP_KERNEL); in clcdfb_of_init_display()
690 if (!fb->panel) in clcdfb_of_init_display()
691 return -ENOMEM; in clcdfb_of_init_display()
696 endpoint = of_graph_get_next_endpoint(fb->dev->dev.of_node, NULL); in clcdfb_of_init_display()
698 return -ENODEV; in clcdfb_of_init_display()
702 err = -ENODEV; in clcdfb_of_init_display()
706 err = clcdfb_of_get_backlight(&fb->dev->dev, fb->panel); in clcdfb_of_init_display()
710 err = clcdfb_of_get_mode(&fb->dev->dev, panel, fb->panel); in clcdfb_of_init_display()
714 err = of_property_read_u32(fb->dev->dev.of_node, "max-memory-bandwidth", in clcdfb_of_init_display()
719 * pico-seconds, so the maximum allowed bits per pixel is in clcdfb_of_init_display()
725 / PICOS2KHZ(fb->panel->mode.pixclock); in clcdfb_of_init_display()
731 fb->panel->bpp = bpp; in clcdfb_of_init_display()
734 fb->panel->cntl |= CNTL_BEBO; in clcdfb_of_init_display()
736 fb->panel->width = -1; in clcdfb_of_init_display()
737 fb->panel->height = -1; in clcdfb_of_init_display()
740 "arm,pl11x,tft-r0g0b0-pads", in clcdfb_of_init_display()
742 err = -ENOENT; in clcdfb_of_init_display()
768 memory = of_parse_phandle(fb->dev->dev.of_node, "memory-region", 0); in clcdfb_of_vram_setup()
770 return -ENODEV; in clcdfb_of_vram_setup()
772 fb->fb.screen_base = of_iomap(memory, 0); in clcdfb_of_vram_setup()
773 if (!fb->fb.screen_base) { in clcdfb_of_vram_setup()
775 return -ENOMEM; in clcdfb_of_vram_setup()
778 fb->fb.fix.smem_start = of_translate_address(memory, in clcdfb_of_vram_setup()
780 fb->fb.fix.smem_len = size; in clcdfb_of_vram_setup()
791 off = vma->vm_pgoff << PAGE_SHIFT; in clcdfb_of_vram_mmap()
792 user_size = vma->vm_end - vma->vm_start; in clcdfb_of_vram_mmap()
793 kernel_size = fb->fb.fix.smem_len; in clcdfb_of_vram_mmap()
795 if (off >= kernel_size || user_size > (kernel_size - off)) in clcdfb_of_vram_mmap()
796 return -ENXIO; in clcdfb_of_vram_mmap()
798 return remap_pfn_range(vma, vma->vm_start, in clcdfb_of_vram_mmap()
799 __phys_to_pfn(fb->fb.fix.smem_start) + vma->vm_pgoff, in clcdfb_of_vram_mmap()
801 pgprot_writecombine(vma->vm_page_prot)); in clcdfb_of_vram_mmap()
806 iounmap(fb->fb.screen_base); in clcdfb_of_vram_remove()
819 framesize = PAGE_ALIGN(fb->panel->mode.xres * fb->panel->mode.yres * in clcdfb_of_dma_setup()
820 fb->panel->bpp / 8); in clcdfb_of_dma_setup()
821 fb->fb.screen_base = dma_alloc_coherent(&fb->dev->dev, framesize, in clcdfb_of_dma_setup()
823 if (!fb->fb.screen_base) in clcdfb_of_dma_setup()
824 return -ENOMEM; in clcdfb_of_dma_setup()
826 fb->fb.fix.smem_start = dma; in clcdfb_of_dma_setup()
827 fb->fb.fix.smem_len = framesize; in clcdfb_of_dma_setup()
834 return dma_mmap_wc(&fb->dev->dev, vma, fb->fb.screen_base, in clcdfb_of_dma_mmap()
835 fb->fb.fix.smem_start, fb->fb.fix.smem_len); in clcdfb_of_dma_mmap()
840 dma_free_coherent(&fb->dev->dev, fb->fb.fix.smem_len, in clcdfb_of_dma_remove()
841 fb->fb.screen_base, fb->fb.fix.smem_start); in clcdfb_of_dma_remove()
846 struct clcd_board *board = devm_kzalloc(&dev->dev, sizeof(*board), in clcdfb_of_get_board()
848 struct device_node *node = dev->dev.of_node; in clcdfb_of_get_board()
853 board->name = of_node_full_name(node); in clcdfb_of_get_board()
854 board->caps = CLCD_CAP_ALL; in clcdfb_of_get_board()
855 board->check = clcdfb_check; in clcdfb_of_get_board()
856 board->decode = clcdfb_decode; in clcdfb_of_get_board()
857 if (of_find_property(node, "memory-region", NULL)) { in clcdfb_of_get_board()
858 board->setup = clcdfb_of_vram_setup; in clcdfb_of_get_board()
859 board->mmap = clcdfb_of_vram_mmap; in clcdfb_of_get_board()
860 board->remove = clcdfb_of_vram_remove; in clcdfb_of_get_board()
862 board->setup = clcdfb_of_dma_setup; in clcdfb_of_get_board()
863 board->mmap = clcdfb_of_dma_mmap; in clcdfb_of_get_board()
864 board->remove = clcdfb_of_dma_remove; in clcdfb_of_get_board()
878 struct clcd_board *board = dev_get_platdata(&dev->dev); in clcdfb_probe()
886 return -EINVAL; in clcdfb_probe()
888 ret = dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32)); in clcdfb_probe()
900 ret = -ENOMEM; in clcdfb_probe()
904 fb->dev = dev; in clcdfb_probe()
905 fb->board = board; in clcdfb_probe()
907 dev_info(&fb->dev->dev, "PL%03x designer %02x rev%u at 0x%08llx\n", in clcdfb_probe()
909 (unsigned long long)dev->res.start); in clcdfb_probe()
911 ret = fb->board->setup(fb); in clcdfb_probe()
921 fb->board->remove(fb); in clcdfb_probe()
935 unregister_framebuffer(&fb->fb); in clcdfb_remove()
936 if (fb->fb.cmap.len) in clcdfb_remove()
937 fb_dealloc_cmap(&fb->fb.cmap); in clcdfb_remove()
938 iounmap(fb->regs); in clcdfb_remove()
939 clk_unprepare(fb->clk); in clcdfb_remove()
940 clk_put(fb->clk); in clcdfb_remove()
942 fb->board->remove(fb); in clcdfb_remove()
961 .name = "clcd-pl11x",
971 return -ENODEV; in amba_clcdfb_init()