21 #include <linux/module.h>
22 #include <linux/device.h>
42 #define MODULE_NAME "lcdc"
44 #define MAX_PALETTE_SIZE PAGE_SIZE
52 static struct omap_lcd_controller {
68 unsigned int irq_mask;
75 void *dma_callback_data;
83 static void inline enable_irqs(
int mask)
85 lcdc.irq_mask |=
mask;
88 static void inline disable_irqs(
int mask)
90 lcdc.irq_mask &= ~mask;
114 static void enable_controller(
void)
125 static void disable_controller_async(
void)
141 static void disable_controller(
void)
143 init_completion(&lcdc.last_frame_complete);
144 disable_controller_async();
147 dev_err(lcdc.fbdev->dev,
"timeout waiting for FRAME DONE\n");
152 static unsigned long reset_count;
153 static unsigned long last_jiffies;
155 disable_controller_async();
157 if (reset_count == 1 ||
time_after(jiffies, last_jiffies +
HZ)) {
159 "resetting (status %#010x,reset count %lu)\n",
160 status, reset_count);
163 if (reset_count < 100) {
168 "too many reset attempts, giving up.\n");
176 static void setup_lcd_dma(
void)
178 static const int dma_elem_type[] = {
188 int esize, xelem, yelem;
190 src = lcdc.vram_phys + lcdc.frame_offset;
194 if (plane->
info.mirror || (src & 3) ||
200 xelem = lcdc.xres * lcdc.bpp / 8 / esize;
210 xelem = lcdc.yres * lcdc.bpp / 16;
219 "setup_dma: src %#010lx esize %d xelem %d yelem %d\n",
220 src, esize, xelem, yelem);
234 lcdc.screen_width * bpp / 8 / esize);
249 reset_controller(status);
262 complete(&lcdc.last_frame_complete);
265 disable_controller_async();
266 complete(&lcdc.palette_load_complete);
292 static int omap_lcdc_setup_plane(
int plane,
int channel_out,
293 unsigned long offset,
int screen_width,
298 struct lcd_panel *panel = lcdc.fbdev->panel;
302 rot_x = panel->
x_res;
303 rot_y = panel->
y_res;
305 rot_x = panel->
y_res;
306 rot_y = panel->
x_res;
308 if (plane != 0 || channel_out != 0 || pos_x != 0 || pos_y != 0 ||
309 width > rot_x || height > rot_y) {
312 "invalid plane params plane %d pos_x %d pos_y %d "
313 "w %d h %d\n", plane, pos_x, pos_y, width, height);
318 lcdc.frame_offset =
offset;
321 lcdc.screen_width = screen_width;
322 lcdc.color_mode = color_mode;
324 switch (color_mode) {
327 lcdc.palette_code = 0x3000;
328 lcdc.palette_size = 512;
332 lcdc.palette_code = 0x4000;
333 lcdc.palette_size = 32;
337 lcdc.palette_code = 0x4000;
338 lcdc.palette_size = 32;
359 dev_dbg(lcdc.fbdev->dev,
"invalid color mode %d\n", color_mode);
370 disable_controller();
379 static int omap_lcdc_enable_plane(
int plane,
int enable)
382 "plane %d enable %d update_mode %d ext_mode %d\n",
383 plane, enable, lcdc.update_mode, lcdc.ext_mode);
395 static void load_palette(
void)
399 palette = (
u16 *)lcdc.palette_virt;
401 *(
u16 *)palette &= 0x0fff;
402 *(
u16 *)palette |= lcdc.palette_code;
410 init_completion(&lcdc.palette_load_complete);
416 dev_err(lcdc.fbdev->dev,
"timeout waiting for FRAME DONE\n");
433 palette = (
u16 *)lcdc.palette_virt;
435 palette[regno] &= ~0x0fff;
436 palette[regno] |= ((red >> 12) << 8) | ((green >> 12) << 4 ) |
440 disable_controller();
451 static void calc_ck_div(
int is_tft,
int pck,
int *pck_div)
457 *pck_div = (lck + pck - 1) / pck;
459 *pck_div =
max(2, *pck_div);
461 *pck_div =
max(3, *pck_div);
462 if (*pck_div > 255) {
465 dev_warn(lcdc.fbdev->dev,
"pixclock %d kHz too low.\n",
470 static void inline setup_regs(
void)
473 struct lcd_panel *panel = lcdc.fbdev->panel;
481 #ifdef CONFIG_MACH_OMAP_PALMTE
484 l |= (is_tft && panel->
bpp == 8) ? 0x810000 : 0;
490 l &= ~(((1 << 6) - 1) << 20);
494 l = panel->
x_res - 1;
495 l |= (panel->
hsw - 1) << 10;
496 l |= (panel->
hfp - 1) << 16;
497 l |= (panel->
hbp - 1) << 24;
500 l = panel->
y_res - 1;
501 l |= (panel->
vsw - 1) << 10;
502 l |= panel->
vfp << 16;
503 l |= panel->
vbp << 24;
512 calc_ck_div(is_tft, panel->
pixel_clock * 1000, &pcd);
515 "Pixel clock divider value is obsolete.\n"
516 "Try to set pixel_clock to %lu and pcd to 0 "
517 "in drivers/video/omap/lcd_%s.c and submit a patch.\n",
518 lck / panel->
pcd / 1000, panel->
name);
523 l |= panel->
acb << 8;
539 if (mode != lcdc.update_mode) {
552 lcdc.update_mode =
mode;
555 disable_controller();
557 lcdc.update_mode =
mode;
569 return lcdc.update_mode;
573 static void omap_lcdc_suspend(
void)
578 static void omap_lcdc_resume(
void)
592 if (lcdc.dma_callback)
596 lcdc.dma_callback_data =
data;
604 lcdc.dma_callback =
NULL;
608 static void lcdc_dma_handler(
u16 status,
void *
data)
610 if (lcdc.dma_callback)
611 lcdc.dma_callback(lcdc.dma_callback_data);
614 static int mmap_kern(
void)
623 dev_err(lcdc.fbdev->dev,
"can't get kernel vm area\n");
629 vma.vm_start = vaddr;
630 vma.vm_end = vaddr + lcdc.vram_size;
635 lcdc.vram_size, pgprot) < 0) {
636 dev_err(lcdc.fbdev->dev,
"kernel mmap for FB memory failed\n");
640 lcdc.vram_virt = (
void *)vaddr;
645 static void unmap_kern(
void)
650 static int alloc_palette_ram(
void)
654 if (lcdc.palette_virt ==
NULL) {
655 dev_err(lcdc.fbdev->dev,
"failed to alloc palette memory\n");
663 static void free_palette_ram(
void)
666 lcdc.palette_virt, lcdc.palette_phys);
673 struct lcd_panel *panel = lcdc.fbdev->panel;
679 if (region->
size > frame_size)
680 frame_size = region->
size;
681 lcdc.vram_size = frame_size;
684 if (lcdc.vram_virt ==
NULL) {
685 dev_err(lcdc.fbdev->dev,
"unable to allocate FB DMA memory\n");
688 region->
size = frame_size;
689 region->
paddr = lcdc.vram_phys;
690 region->
vaddr = lcdc.vram_virt;
693 memset(lcdc.vram_virt, 0, lcdc.vram_size);
698 static void free_fbmem(
void)
701 lcdc.vram_virt, lcdc.vram_phys);
709 dev_err(lcdc.fbdev->dev,
"no memory regions defined\n");
714 dev_err(lcdc.fbdev->dev,
"only one plane is supported\n");
718 if (req_md->
region[0].paddr == 0) {
719 lcdc.fbmem_allocated = 1;
720 if ((r = alloc_fbmem(&req_md->
region[0])) < 0)
725 lcdc.vram_phys = req_md->
region[0].paddr;
726 lcdc.vram_size = req_md->
region[0].size;
728 if ((r = mmap_kern()) < 0)
731 dev_dbg(lcdc.fbdev->dev,
"vram at %08x size %08lx mapped to 0x%p\n",
732 lcdc.vram_phys, lcdc.vram_size, lcdc.vram_virt);
737 static void cleanup_fbmem(
void)
739 if (lcdc.fbmem_allocated)
756 lcdc.ext_mode = ext_mode;
765 if (IS_ERR(lcdc.lcd_ck)) {
766 dev_err(fbdev->
dev,
"unable to access LCD clock\n");
767 r = PTR_ERR(lcdc.lcd_ck);
773 dev_err(fbdev->
dev,
"unable to access TC clock\n");
781 if (machine_is_ams_delta())
783 if (machine_is_omap_h3())
787 dev_err(fbdev->
dev,
"failed to adjust LCD rate\n");
800 dev_err(fbdev->
dev,
"unable to get LCD DMA\n");
808 if ((r = alloc_palette_ram()) < 0)
811 if ((r = setup_fbmem(req_vram)) < 0)
814 pr_info(
"omapfb: LCDC initialized\n");
832 static void omap_lcdc_cleanup(
void)
845 .init = omap_lcdc_init,
846 .cleanup = omap_lcdc_cleanup,
847 .get_caps = omap_lcdc_get_caps,
848 .set_update_mode = omap_lcdc_set_update_mode,
849 .get_update_mode = omap_lcdc_get_update_mode,
850 .update_window =
NULL,
851 .suspend = omap_lcdc_suspend,
852 .resume = omap_lcdc_resume,
853 .setup_plane = omap_lcdc_setup_plane,
854 .enable_plane = omap_lcdc_enable_plane,
855 .setcolreg = omap_lcdc_setcolreg,