4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
7 * SPDX-License-Identifier: GPL-2.0+
10 /************************************************************************/
12 /************************************************************************/
15 #include <asm/arch/pxa-regs.h>
18 #include <linux/types.h>
20 #include <stdio_dev.h>
26 /*----------------------------------------------------------------------*/
28 * Define panel bpp, LCCR0, LCCR3 and panel_info video struct for
33 /* LCD outputs connected to a video DAC */
34 # define LCD_BPP LCD_COLOR8
36 /* you have to set lccr0 and lccr3 (including pcd) */
37 # define REG_LCCR0 0x003008f8
38 # define REG_LCCR3 0x0300FF01
40 /* 640x480x16 @ 61 Hz */
41 vidinfo_t panel_info = {
46 .vl_clkp = CONFIG_SYS_HIGH,
47 .vl_oep = CONFIG_SYS_HIGH,
48 .vl_hsp = CONFIG_SYS_HIGH,
49 .vl_vsp = CONFIG_SYS_HIGH,
50 .vl_dp = CONFIG_SYS_HIGH,
63 #endif /* CONFIG_PXA_VIDEO */
65 /*----------------------------------------------------------------------*/
66 #ifdef CONFIG_SHARP_LM8V31
68 # define LCD_BPP LCD_COLOR8
69 # define LCD_INVERT_COLORS /* Needed for colors to be correct, but why? */
71 /* you have to set lccr0 and lccr3 (including pcd) */
72 # define REG_LCCR0 0x0030087C
73 # define REG_LCCR3 0x0340FF08
75 vidinfo_t panel_info = {
80 .vl_clkp = CONFIG_SYS_HIGH,
81 .vl_oep = CONFIG_SYS_HIGH,
82 .vl_hsp = CONFIG_SYS_HIGH,
83 .vl_vsp = CONFIG_SYS_HIGH,
84 .vl_dp = CONFIG_SYS_HIGH,
97 #endif /* CONFIG_SHARP_LM8V31 */
98 /*----------------------------------------------------------------------*/
99 #ifdef CONFIG_VOIPAC_LCD
101 # define LCD_BPP LCD_COLOR8
102 # define LCD_INVERT_COLORS
104 /* you have to set lccr0 and lccr3 (including pcd) */
105 # define REG_LCCR0 0x043008f8
106 # define REG_LCCR3 0x0340FF08
108 vidinfo_t panel_info = {
113 .vl_clkp = CONFIG_SYS_HIGH,
114 .vl_oep = CONFIG_SYS_HIGH,
115 .vl_hsp = CONFIG_SYS_HIGH,
116 .vl_vsp = CONFIG_SYS_HIGH,
117 .vl_dp = CONFIG_SYS_HIGH,
130 #endif /* CONFIG_VOIPAC_LCD */
132 /*----------------------------------------------------------------------*/
133 #ifdef CONFIG_HITACHI_SX14
134 /* Hitachi SX14Q004-ZZA color STN LCD */
135 #define LCD_BPP LCD_COLOR8
137 /* you have to set lccr0 and lccr3 (including pcd) */
138 #define REG_LCCR0 0x00301079
139 #define REG_LCCR3 0x0340FF20
141 vidinfo_t panel_info = {
146 .vl_clkp = CONFIG_SYS_HIGH,
147 .vl_oep = CONFIG_SYS_HIGH,
148 .vl_hsp = CONFIG_SYS_HIGH,
149 .vl_vsp = CONFIG_SYS_HIGH,
150 .vl_dp = CONFIG_SYS_HIGH,
163 #endif /* CONFIG_HITACHI_SX14 */
165 /*----------------------------------------------------------------------*/
166 #ifdef CONFIG_LMS283GF05
168 # define LCD_BPP LCD_COLOR8
169 /*# define LCD_INVERT_COLORS*/
171 /* you have to set lccr0 and lccr3 (including pcd) */
172 # define REG_LCCR0 0x043008f8
173 # define REG_LCCR3 0x03b00009
175 vidinfo_t panel_info = {
181 .vl_clkp = CONFIG_SYS_HIGH,
182 .vl_oep = CONFIG_SYS_LOW,
183 .vl_hsp = CONFIG_SYS_LOW,
184 .vl_vsp = CONFIG_SYS_LOW,
185 .vl_dp = CONFIG_SYS_HIGH,
198 #endif /* CONFIG_LMS283GF05 */
200 /*----------------------------------------------------------------------*/
202 #ifdef CONFIG_ACX517AKN
204 # define LCD_BPP LCD_COLOR8
206 /* you have to set lccr0 and lccr3 (including pcd) */
207 # define REG_LCCR0 0x003008f9
208 # define REG_LCCR3 0x03700006
210 vidinfo_t panel_info = {
215 .vl_clkp = CONFIG_SYS_HIGH,
216 .vl_oep = CONFIG_SYS_LOW,
217 .vl_hsp = CONFIG_SYS_LOW,
218 .vl_vsp = CONFIG_SYS_LOW,
219 .vl_dp = CONFIG_SYS_HIGH,
232 #endif /* CONFIG_ACX517AKN */
234 #ifdef CONFIG_ACX544AKN
236 # define LCD_BPP LCD_COLOR16
238 /* you have to set lccr0 and lccr3 (including pcd) */
239 # define REG_LCCR0 0x003008f9
240 # define REG_LCCR3 0x04700007 /* 16bpp */
242 vidinfo_t panel_info = {
247 .vl_clkp = CONFIG_SYS_LOW,
248 .vl_oep = CONFIG_SYS_LOW,
249 .vl_hsp = CONFIG_SYS_LOW,
250 .vl_vsp = CONFIG_SYS_LOW,
251 .vl_dp = CONFIG_SYS_LOW,
264 #endif /* CONFIG_ACX544AKN */
266 /*----------------------------------------------------------------------*/
268 #ifdef CONFIG_LQ038J7DH53
270 # define LCD_BPP LCD_COLOR8
272 /* you have to set lccr0 and lccr3 (including pcd) */
273 # define REG_LCCR0 0x003008f9
274 # define REG_LCCR3 0x03700004
276 vidinfo_t panel_info = {
281 .vl_clkp = CONFIG_SYS_HIGH,
282 .vl_oep = CONFIG_SYS_LOW,
283 .vl_hsp = CONFIG_SYS_LOW,
284 .vl_vsp = CONFIG_SYS_LOW,
285 .vl_dp = CONFIG_SYS_HIGH,
298 #endif /* CONFIG_ACX517AKN */
300 /*----------------------------------------------------------------------*/
302 #ifdef CONFIG_LITTLETON_LCD
303 # define LCD_BPP LCD_COLOR8
305 /* you have to set lccr0 and lccr3 (including pcd) */
306 # define REG_LCCR0 0x003008f8
307 # define REG_LCCR3 0x0300FF04
309 vidinfo_t panel_info = {
314 .vl_clkp = CONFIG_SYS_HIGH,
315 .vl_oep = CONFIG_SYS_HIGH,
316 .vl_hsp = CONFIG_SYS_HIGH,
317 .vl_vsp = CONFIG_SYS_HIGH,
318 .vl_dp = CONFIG_SYS_HIGH,
331 #endif /* CONFIG_LITTLETON_LCD */
333 /*----------------------------------------------------------------------*/
335 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid);
336 static void pxafb_setup_gpio (vidinfo_t *vid);
337 static void pxafb_enable_controller (vidinfo_t *vid);
338 static int pxafb_init (vidinfo_t *vid);
340 /************************************************************************/
341 /* --------------- PXA chipset specific functions ------------------- */
342 /************************************************************************/
344 ushort *configuration_get_cmap(void)
346 struct pxafb_info *fbi = &panel_info.pxa;
347 return (ushort *)fbi->palette;
350 void lcd_ctrl_init (void *lcdbase)
352 pxafb_init_mem(lcdbase, &panel_info);
353 pxafb_init(&panel_info);
354 pxafb_setup_gpio(&panel_info);
355 pxafb_enable_controller(&panel_info);
358 /*----------------------------------------------------------------------*/
359 #if LCD_BPP == LCD_COLOR8
361 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
363 struct pxafb_info *fbi = &panel_info.pxa;
364 unsigned short *palette = (unsigned short *)fbi->palette;
367 if (regno < fbi->palette_size) {
368 val = ((red << 8) & 0xf800);
369 val |= ((green << 4) & 0x07e0);
370 val |= (blue & 0x001f);
372 #ifdef LCD_INVERT_COLORS
373 palette[regno] = ~val;
375 palette[regno] = val;
379 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %04X\n",
380 regno, &palette[regno],
384 #endif /* LCD_COLOR8 */
386 /*----------------------------------------------------------------------*/
387 __weak void lcd_enable(void)
391 /************************************************************************/
392 /* ** PXA255 specific routines */
393 /************************************************************************/
396 * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
397 * descriptors and palette areas.
399 ulong calc_fbsize (void)
402 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
404 size = line_length * panel_info.vl_row;
410 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid)
412 u_long palette_mem_size;
413 struct pxafb_info *fbi = &vid->pxa;
414 int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
416 fbi->screen = (u_long)lcdbase;
418 fbi->palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
419 palette_mem_size = fbi->palette_size * sizeof(u16);
421 debug("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
422 /* locate palette and descs at end of page following fb */
423 fbi->palette = (u_long)lcdbase + fb_size + PAGE_SIZE - palette_mem_size;
427 #ifdef CONFIG_CPU_MONAHANS
428 static inline void pxafb_setup_gpio (vidinfo_t *vid) {}
430 static void pxafb_setup_gpio (vidinfo_t *vid)
435 * setup is based on type of panel supported
438 lccr0 = vid->pxa.reg_lccr0;
440 /* 4 bit interface */
441 if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))
443 debug("Setting GPIO for 4 bit data\n");
445 writel(readl(GPDR1) | (0xf << 26), GPDR1);
446 writel((readl(GAFR1_U) & ~(0xff << 20)) | (0xaa << 20),
450 writel(readl(GPDR2) | (0xf << 10), GPDR2);
451 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
455 /* 8 bit interface */
456 else if (((lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_DPD))) ||
457 (!(lccr0 & LCCR0_CMS) && !(lccr0 & LCCR0_PAS) && !(lccr0 & LCCR0_SDS)))
459 debug("Setting GPIO for 8 bit data\n");
461 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
462 writel(readl(GPDR2) | (0x3), GPDR2);
464 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
466 writel((readl(GAFR2_L) & ~0xf) | (0xa), GAFR2_L);
469 writel(readl(GPDR2) | (0xf << 10), GPDR2);
470 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
474 /* 16 bit interface */
475 else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))
477 debug("Setting GPIO for 16 bit data\n");
479 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
480 writel(readl(GPDR2) | 0x00003fff, GPDR2);
482 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
484 writel((readl(GAFR2_L) & 0xf0000000) | 0x0aaaaaaa, GAFR2_L);
488 printf("pxafb_setup_gpio: unable to determine bits per pixel\n");
493 static void pxafb_enable_controller (vidinfo_t *vid)
495 debug("Enabling LCD controller\n");
497 /* Sequence from 11.7.10 */
498 writel(vid->pxa.reg_lccr3, LCCR3);
499 writel(vid->pxa.reg_lccr2, LCCR2);
500 writel(vid->pxa.reg_lccr1, LCCR1);
501 writel(vid->pxa.reg_lccr0 & ~LCCR0_ENB, LCCR0);
502 writel(vid->pxa.fdadr0, FDADR0);
503 writel(vid->pxa.fdadr1, FDADR1);
504 writel(readl(LCCR0) | LCCR0_ENB, LCCR0);
506 #ifdef CONFIG_CPU_MONAHANS
507 writel(readl(CKENA) | CKENA_1_LCD, CKENA);
509 writel(readl(CKEN) | CKEN16_LCD, CKEN);
512 debug("FDADR0 = 0x%08x\n", readl(FDADR0));
513 debug("FDADR1 = 0x%08x\n", readl(FDADR1));
514 debug("LCCR0 = 0x%08x\n", readl(LCCR0));
515 debug("LCCR1 = 0x%08x\n", readl(LCCR1));
516 debug("LCCR2 = 0x%08x\n", readl(LCCR2));
517 debug("LCCR3 = 0x%08x\n", readl(LCCR3));
520 static int pxafb_init (vidinfo_t *vid)
522 struct pxafb_info *fbi = &vid->pxa;
524 debug("Configuring PXA LCD\n");
526 fbi->reg_lccr0 = REG_LCCR0;
527 fbi->reg_lccr3 = REG_LCCR3;
529 debug("vid: vl_col=%d hslen=%d lm=%d rm=%d\n",
530 vid->vl_col, vid->vl_hpw,
531 vid->vl_blw, vid->vl_elw);
532 debug("vid: vl_row=%d vslen=%d um=%d bm=%d\n",
533 vid->vl_row, vid->vl_vpw,
534 vid->vl_bfw, vid->vl_efw);
537 LCCR1_DisWdth(vid->vl_col) +
538 LCCR1_HorSnchWdth(vid->vl_hpw) +
539 LCCR1_BegLnDel(vid->vl_blw) +
540 LCCR1_EndLnDel(vid->vl_elw);
543 LCCR2_DisHght(vid->vl_row) +
544 LCCR2_VrtSnchWdth(vid->vl_vpw) +
545 LCCR2_BegFrmDel(vid->vl_bfw) +
546 LCCR2_EndFrmDel(vid->vl_efw);
548 fbi->reg_lccr3 = REG_LCCR3 & ~(LCCR3_HSP | LCCR3_VSP);
549 fbi->reg_lccr3 |= (vid->vl_hsp ? LCCR3_HorSnchL : LCCR3_HorSnchH)
550 | (vid->vl_vsp ? LCCR3_VrtSnchL : LCCR3_VrtSnchH);
553 /* setup dma descriptors */
554 fbi->dmadesc_fblow = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 3*16);
555 fbi->dmadesc_fbhigh = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 2*16);
556 fbi->dmadesc_palette = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 1*16);
558 #define BYTES_PER_PANEL ((fbi->reg_lccr0 & LCCR0_SDS) ? \
559 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8 / 2) : \
560 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8))
562 /* populate descriptors */
563 fbi->dmadesc_fblow->fdadr = (u_long)fbi->dmadesc_fblow;
564 fbi->dmadesc_fblow->fsadr = fbi->screen + BYTES_PER_PANEL;
565 fbi->dmadesc_fblow->fidr = 0;
566 fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL;
568 fbi->fdadr1 = (u_long)fbi->dmadesc_fblow; /* only used in dual-panel mode */
570 fbi->dmadesc_fbhigh->fsadr = fbi->screen;
571 fbi->dmadesc_fbhigh->fidr = 0;
572 fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL;
574 fbi->dmadesc_palette->fsadr = fbi->palette;
575 fbi->dmadesc_palette->fidr = 0;
576 fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
578 if( NBITS(vid->vl_bpix) < 12)
580 /* assume any mode with <12 bpp is palette driven */
581 fbi->dmadesc_palette->fdadr = (u_long)fbi->dmadesc_fbhigh;
582 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_palette;
583 /* flips back and forth between pal and fbhigh */
584 fbi->fdadr0 = (u_long)fbi->dmadesc_palette;
588 /* palette shouldn't be loaded in true-color mode */
589 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_fbhigh;
590 fbi->fdadr0 = (u_long)fbi->dmadesc_fbhigh; /* no pal just fbhigh */
593 debug("fbi->dmadesc_fblow = 0x%lx\n", (u_long)fbi->dmadesc_fblow);
594 debug("fbi->dmadesc_fbhigh = 0x%lx\n", (u_long)fbi->dmadesc_fbhigh);
595 debug("fbi->dmadesc_palette = 0x%lx\n", (u_long)fbi->dmadesc_palette);
597 debug("fbi->dmadesc_fblow->fdadr = 0x%lx\n", fbi->dmadesc_fblow->fdadr);
598 debug("fbi->dmadesc_fbhigh->fdadr = 0x%lx\n", fbi->dmadesc_fbhigh->fdadr);
599 debug("fbi->dmadesc_palette->fdadr = 0x%lx\n", fbi->dmadesc_palette->fdadr);
601 debug("fbi->dmadesc_fblow->fsadr = 0x%lx\n", fbi->dmadesc_fblow->fsadr);
602 debug("fbi->dmadesc_fbhigh->fsadr = 0x%lx\n", fbi->dmadesc_fbhigh->fsadr);
603 debug("fbi->dmadesc_palette->fsadr = 0x%lx\n", fbi->dmadesc_palette->fsadr);
605 debug("fbi->dmadesc_fblow->ldcmd = 0x%lx\n", fbi->dmadesc_fblow->ldcmd);
606 debug("fbi->dmadesc_fbhigh->ldcmd = 0x%lx\n", fbi->dmadesc_fbhigh->ldcmd);
607 debug("fbi->dmadesc_palette->ldcmd = 0x%lx\n", fbi->dmadesc_palette->ldcmd);
612 /************************************************************************/
613 /************************************************************************/
615 #endif /* CONFIG_LCD */