4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /************************************************************************/
28 /************************************************************************/
34 #include <linux/types.h>
35 #include <stdio_dev.h>
37 #include <asm/arch/pxa-regs.h>
44 /*----------------------------------------------------------------------*/
46 * Define panel bpp, LCCR0, LCCR3 and panel_info video struct for
51 /* LCD outputs connected to a video DAC */
52 # define LCD_BPP LCD_COLOR8
54 /* you have to set lccr0 and lccr3 (including pcd) */
55 # define REG_LCCR0 0x003008f8
56 # define REG_LCCR3 0x0300FF01
58 /* 640x480x16 @ 61 Hz */
59 vidinfo_t panel_info = {
64 .vl_clkp = CONFIG_SYS_HIGH,
65 .vl_oep = CONFIG_SYS_HIGH,
66 .vl_hsp = CONFIG_SYS_HIGH,
67 .vl_vsp = CONFIG_SYS_HIGH,
68 .vl_dp = CONFIG_SYS_HIGH,
81 #endif /* CONFIG_PXA_VIDEO */
83 /*----------------------------------------------------------------------*/
84 #ifdef CONFIG_SHARP_LM8V31
86 # define LCD_BPP LCD_COLOR8
87 # define LCD_INVERT_COLORS /* Needed for colors to be correct, but why? */
89 /* you have to set lccr0 and lccr3 (including pcd) */
90 # define REG_LCCR0 0x0030087C
91 # define REG_LCCR3 0x0340FF08
93 vidinfo_t panel_info = {
98 .vl_clkp = CONFIG_SYS_HIGH,
99 .vl_oep = CONFIG_SYS_HIGH,
100 .vl_hsp = CONFIG_SYS_HIGH,
101 .vl_vsp = CONFIG_SYS_HIGH,
102 .vl_dp = CONFIG_SYS_HIGH,
115 #endif /* CONFIG_SHARP_LM8V31 */
116 /*----------------------------------------------------------------------*/
117 #ifdef CONFIG_VOIPAC_LCD
119 # define LCD_BPP LCD_COLOR8
120 # define LCD_INVERT_COLORS
122 /* you have to set lccr0 and lccr3 (including pcd) */
123 # define REG_LCCR0 0x043008f8
124 # define REG_LCCR3 0x0340FF08
126 vidinfo_t panel_info = {
131 .vl_clkp = CONFIG_SYS_HIGH,
132 .vl_oep = CONFIG_SYS_HIGH,
133 .vl_hsp = CONFIG_SYS_HIGH,
134 .vl_vsp = CONFIG_SYS_HIGH,
135 .vl_dp = CONFIG_SYS_HIGH,
148 #endif /* CONFIG_VOIPAC_LCD */
150 /*----------------------------------------------------------------------*/
151 #ifdef CONFIG_HITACHI_SX14
152 /* Hitachi SX14Q004-ZZA color STN LCD */
153 #define LCD_BPP LCD_COLOR8
155 /* you have to set lccr0 and lccr3 (including pcd) */
156 #define REG_LCCR0 0x00301079
157 #define REG_LCCR3 0x0340FF20
159 vidinfo_t panel_info = {
164 .vl_clkp = CONFIG_SYS_HIGH,
165 .vl_oep = CONFIG_SYS_HIGH,
166 .vl_hsp = CONFIG_SYS_HIGH,
167 .vl_vsp = CONFIG_SYS_HIGH,
168 .vl_dp = CONFIG_SYS_HIGH,
181 #endif /* CONFIG_HITACHI_SX14 */
183 /*----------------------------------------------------------------------*/
184 #ifdef CONFIG_LMS283GF05
186 # define LCD_BPP LCD_COLOR8
187 /*# define LCD_INVERT_COLORS*/
189 /* you have to set lccr0 and lccr3 (including pcd) */
190 # define REG_LCCR0 0x043008f8
191 # define REG_LCCR3 0x03b00009
193 vidinfo_t panel_info = {
198 .vl_clkp = CONFIG_SYS_HIGH,
199 .vl_oep = CONFIG_SYS_LOW,
200 .vl_hsp = CONFIG_SYS_LOW,
201 .vl_vsp = CONFIG_SYS_LOW,
202 .vl_dp = CONFIG_SYS_HIGH,
215 #endif /* CONFIG_LMS283GF05 */
217 /*----------------------------------------------------------------------*/
219 #ifdef CONFIG_ACX517AKN
221 # define LCD_BPP LCD_COLOR8
223 /* you have to set lccr0 and lccr3 (including pcd) */
224 # define REG_LCCR0 0x003008f9
225 # define REG_LCCR3 0x03700006
227 vidinfo_t panel_info = {
232 .vl_clkp = CONFIG_SYS_HIGH,
233 .vl_oep = CONFIG_SYS_LOW,
234 .vl_hsp = CONFIG_SYS_LOW,
235 .vl_vsp = CONFIG_SYS_LOW,
236 .vl_dp = CONFIG_SYS_HIGH,
249 #endif /* CONFIG_ACX517AKN */
251 /*----------------------------------------------------------------------*/
253 #ifdef CONFIG_LQ038J7DH53
255 # define LCD_BPP LCD_COLOR8
257 /* you have to set lccr0 and lccr3 (including pcd) */
258 # define REG_LCCR0 0x003008f9
259 # define REG_LCCR3 0x03700004
261 vidinfo_t panel_info = {
266 .vl_clkp = CONFIG_SYS_HIGH,
267 .vl_oep = CONFIG_SYS_LOW,
268 .vl_hsp = CONFIG_SYS_LOW,
269 .vl_vsp = CONFIG_SYS_LOW,
270 .vl_dp = CONFIG_SYS_HIGH,
283 #endif /* CONFIG_ACX517AKN */
285 /*----------------------------------------------------------------------*/
287 #ifdef CONFIG_LITTLETON_LCD
288 # define LCD_BPP LCD_COLOR8
290 /* you have to set lccr0 and lccr3 (including pcd) */
291 # define REG_LCCR0 0x003008f8
292 # define REG_LCCR3 0x0300FF04
294 vidinfo_t panel_info = {
299 .vl_clkp = CONFIG_SYS_HIGH,
300 .vl_oep = CONFIG_SYS_HIGH,
301 .vl_hsp = CONFIG_SYS_HIGH,
302 .vl_vsp = CONFIG_SYS_HIGH,
303 .vl_dp = CONFIG_SYS_HIGH,
316 #endif /* CONFIG_LITTLETON_LCD */
318 /*----------------------------------------------------------------------*/
320 #if LCD_BPP == LCD_COLOR8
321 void lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue);
323 #if LCD_BPP == LCD_MONOCHROME
324 void lcd_initcolregs (void);
327 #ifdef NOT_USED_SO_FAR
328 void lcd_disable (void);
329 void lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue);
330 #endif /* NOT_USED_SO_FAR */
332 void lcd_ctrl_init (void *lcdbase);
333 void lcd_enable (void);
335 void *lcd_base; /* Start of framebuffer memory */
337 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid);
338 static void pxafb_setup_gpio (vidinfo_t *vid);
339 static void pxafb_enable_controller (vidinfo_t *vid);
340 static int pxafb_init (vidinfo_t *vid);
341 /************************************************************************/
343 /************************************************************************/
344 /* --------------- PXA chipset specific functions ------------------- */
345 /************************************************************************/
347 void lcd_ctrl_init (void *lcdbase)
349 pxafb_init_mem(lcdbase, &panel_info);
350 pxafb_init(&panel_info);
351 pxafb_setup_gpio(&panel_info);
352 pxafb_enable_controller(&panel_info);
355 /*----------------------------------------------------------------------*/
356 #ifdef NOT_USED_SO_FAR
358 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
361 #endif /* NOT_USED_SO_FAR */
363 /*----------------------------------------------------------------------*/
364 #if LCD_BPP == LCD_COLOR8
366 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
368 struct pxafb_info *fbi = &panel_info.pxa;
369 unsigned short *palette = (unsigned short *)fbi->palette;
372 if (regno < fbi->palette_size) {
373 val = ((red << 8) & 0xf800);
374 val |= ((green << 4) & 0x07e0);
375 val |= (blue & 0x001f);
377 #ifdef LCD_INVERT_COLORS
378 palette[regno] = ~val;
380 palette[regno] = val;
384 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %04X\n",
385 regno, &palette[regno],
389 #endif /* LCD_COLOR8 */
391 /*----------------------------------------------------------------------*/
392 #if LCD_BPP == LCD_MONOCHROME
393 void lcd_initcolregs (void)
395 struct pxafb_info *fbi = &panel_info.pxa;
396 cmap = (ushort *)fbi->palette;
399 for (regno = 0; regno < 16; regno++) {
401 cmap[(regno * 2) + 1] = regno & 0x0f;
404 #endif /* LCD_MONOCHROME */
406 /*----------------------------------------------------------------------*/
407 void lcd_enable (void)
411 /*----------------------------------------------------------------------*/
412 #ifdef NOT_USED_SO_FAR
413 static void lcd_disable (void)
416 #endif /* NOT_USED_SO_FAR */
418 /*----------------------------------------------------------------------*/
420 /************************************************************************/
421 /* ** PXA255 specific routines */
422 /************************************************************************/
425 * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
426 * descriptors and palette areas.
428 ulong calc_fbsize (void)
431 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
433 size = line_length * panel_info.vl_row;
439 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid)
441 u_long palette_mem_size;
442 struct pxafb_info *fbi = &vid->pxa;
443 int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
445 fbi->screen = (u_long)lcdbase;
447 fbi->palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
448 palette_mem_size = fbi->palette_size * sizeof(u16);
450 debug("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
451 /* locate palette and descs at end of page following fb */
452 fbi->palette = (u_long)lcdbase + fb_size + PAGE_SIZE - palette_mem_size;
456 #ifdef CONFIG_CPU_MONAHANS
457 static inline void pxafb_setup_gpio (vidinfo_t *vid) {}
459 static void pxafb_setup_gpio (vidinfo_t *vid)
464 * setup is based on type of panel supported
467 lccr0 = vid->pxa.reg_lccr0;
469 /* 4 bit interface */
470 if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))
472 debug("Setting GPIO for 4 bit data\n");
474 writel(readl(GPDR1) | (0xf << 26), GPDR1);
475 writel((readl(GAFR1_U) & ~(0xff << 20)) | (0xaa << 20),
479 writel(readl(GPDR2) | (0xf << 10), GPDR2);
480 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
484 /* 8 bit interface */
485 else if (((lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_DPD))) ||
486 (!(lccr0 & LCCR0_CMS) && !(lccr0 & LCCR0_PAS) && !(lccr0 & LCCR0_SDS)))
488 debug("Setting GPIO for 8 bit data\n");
490 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
491 writel(readl(GPDR2) | (0x3), GPDR2);
493 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
495 writel((readl(GAFR2_L) & ~0xf) | (0xa), GAFR2_L);
498 writel(readl(GPDR2) | (0xf << 10), GPDR2);
499 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
503 /* 16 bit interface */
504 else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))
506 debug("Setting GPIO for 16 bit data\n");
508 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
509 writel(readl(GPDR2) | 0x00003fff, GPDR2);
511 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
513 writel((readl(GAFR2_L) & 0xf0000000) | 0x0aaaaaaa, GAFR2_L);
517 printf("pxafb_setup_gpio: unable to determine bits per pixel\n");
522 static void pxafb_enable_controller (vidinfo_t *vid)
524 debug("Enabling LCD controller\n");
526 /* Sequence from 11.7.10 */
527 writel(vid->pxa.reg_lccr3, LCCR3);
528 writel(vid->pxa.reg_lccr2, LCCR2);
529 writel(vid->pxa.reg_lccr1, LCCR1);
530 writel(vid->pxa.reg_lccr0 & ~LCCR0_ENB, LCCR0);
531 writel(vid->pxa.fdadr0, FDADR0);
532 writel(vid->pxa.fdadr1, FDADR1);
533 writel(readl(LCCR0) | LCCR0_ENB, LCCR0);
535 #ifdef CONFIG_CPU_MONAHANS
536 writel(readl(CKENA) | CKENA_1_LCD, CKENA);
538 writel(readl(CKEN) | CKEN16_LCD, CKEN);
541 debug("FDADR0 = 0x%08x\n", readl(FDADR0));
542 debug("FDADR1 = 0x%08x\n", readl(FDADR1));
543 debug("LCCR0 = 0x%08x\n", readl(LCCR0));
544 debug("LCCR1 = 0x%08x\n", readl(LCCR1));
545 debug("LCCR2 = 0x%08x\n", readl(LCCR2));
546 debug("LCCR3 = 0x%08x\n", readl(LCCR3));
549 static int pxafb_init (vidinfo_t *vid)
551 struct pxafb_info *fbi = &vid->pxa;
553 debug("Configuring PXA LCD\n");
555 fbi->reg_lccr0 = REG_LCCR0;
556 fbi->reg_lccr3 = REG_LCCR3;
558 debug("vid: vl_col=%d hslen=%d lm=%d rm=%d\n",
559 vid->vl_col, vid->vl_hpw,
560 vid->vl_blw, vid->vl_elw);
561 debug("vid: vl_row=%d vslen=%d um=%d bm=%d\n",
562 vid->vl_row, vid->vl_vpw,
563 vid->vl_bfw, vid->vl_efw);
566 LCCR1_DisWdth(vid->vl_col) +
567 LCCR1_HorSnchWdth(vid->vl_hpw) +
568 LCCR1_BegLnDel(vid->vl_blw) +
569 LCCR1_EndLnDel(vid->vl_elw);
572 LCCR2_DisHght(vid->vl_row) +
573 LCCR2_VrtSnchWdth(vid->vl_vpw) +
574 LCCR2_BegFrmDel(vid->vl_bfw) +
575 LCCR2_EndFrmDel(vid->vl_efw);
577 fbi->reg_lccr3 = REG_LCCR3 & ~(LCCR3_HSP | LCCR3_VSP);
578 fbi->reg_lccr3 |= (vid->vl_hsp ? LCCR3_HorSnchL : LCCR3_HorSnchH)
579 | (vid->vl_vsp ? LCCR3_VrtSnchL : LCCR3_VrtSnchH);
582 /* setup dma descriptors */
583 fbi->dmadesc_fblow = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 3*16);
584 fbi->dmadesc_fbhigh = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 2*16);
585 fbi->dmadesc_palette = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 1*16);
587 #define BYTES_PER_PANEL ((fbi->reg_lccr0 & LCCR0_SDS) ? \
588 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8 / 2) : \
589 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8))
591 /* populate descriptors */
592 fbi->dmadesc_fblow->fdadr = (u_long)fbi->dmadesc_fblow;
593 fbi->dmadesc_fblow->fsadr = fbi->screen + BYTES_PER_PANEL;
594 fbi->dmadesc_fblow->fidr = 0;
595 fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL;
597 fbi->fdadr1 = (u_long)fbi->dmadesc_fblow; /* only used in dual-panel mode */
599 fbi->dmadesc_fbhigh->fsadr = fbi->screen;
600 fbi->dmadesc_fbhigh->fidr = 0;
601 fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL;
603 fbi->dmadesc_palette->fsadr = fbi->palette;
604 fbi->dmadesc_palette->fidr = 0;
605 fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
607 if( NBITS(vid->vl_bpix) < 12)
609 /* assume any mode with <12 bpp is palette driven */
610 fbi->dmadesc_palette->fdadr = (u_long)fbi->dmadesc_fbhigh;
611 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_palette;
612 /* flips back and forth between pal and fbhigh */
613 fbi->fdadr0 = (u_long)fbi->dmadesc_palette;
617 /* palette shouldn't be loaded in true-color mode */
618 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_fbhigh;
619 fbi->fdadr0 = (u_long)fbi->dmadesc_fbhigh; /* no pal just fbhigh */
622 debug("fbi->dmadesc_fblow = 0x%lx\n", (u_long)fbi->dmadesc_fblow);
623 debug("fbi->dmadesc_fbhigh = 0x%lx\n", (u_long)fbi->dmadesc_fbhigh);
624 debug("fbi->dmadesc_palette = 0x%lx\n", (u_long)fbi->dmadesc_palette);
626 debug("fbi->dmadesc_fblow->fdadr = 0x%lx\n", fbi->dmadesc_fblow->fdadr);
627 debug("fbi->dmadesc_fbhigh->fdadr = 0x%lx\n", fbi->dmadesc_fbhigh->fdadr);
628 debug("fbi->dmadesc_palette->fdadr = 0x%lx\n", fbi->dmadesc_palette->fdadr);
630 debug("fbi->dmadesc_fblow->fsadr = 0x%lx\n", fbi->dmadesc_fblow->fsadr);
631 debug("fbi->dmadesc_fbhigh->fsadr = 0x%lx\n", fbi->dmadesc_fbhigh->fsadr);
632 debug("fbi->dmadesc_palette->fsadr = 0x%lx\n", fbi->dmadesc_palette->fsadr);
634 debug("fbi->dmadesc_fblow->ldcmd = 0x%lx\n", fbi->dmadesc_fblow->ldcmd);
635 debug("fbi->dmadesc_fbhigh->ldcmd = 0x%lx\n", fbi->dmadesc_fbhigh->ldcmd);
636 debug("fbi->dmadesc_palette->ldcmd = 0x%lx\n", fbi->dmadesc_palette->ldcmd);
641 /************************************************************************/
642 /************************************************************************/
644 #endif /* CONFIG_LCD */