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>
43 /*----------------------------------------------------------------------*/
45 * Define panel bpp, LCCR0, LCCR3 and panel_info video struct for
50 /* LCD outputs connected to a video DAC */
51 # define LCD_BPP LCD_COLOR8
53 /* you have to set lccr0 and lccr3 (including pcd) */
54 # define REG_LCCR0 0x003008f8
55 # define REG_LCCR3 0x0300FF01
57 /* 640x480x16 @ 61 Hz */
58 vidinfo_t panel_info = {
63 vl_clkp: CONFIG_SYS_HIGH,
64 vl_oep: CONFIG_SYS_HIGH,
65 vl_hsp: CONFIG_SYS_HIGH,
66 vl_vsp: CONFIG_SYS_HIGH,
67 vl_dp: CONFIG_SYS_HIGH,
80 #endif /* CONFIG_PXA_VIDEO */
82 /*----------------------------------------------------------------------*/
83 #ifdef CONFIG_SHARP_LM8V31
85 # define LCD_BPP LCD_COLOR8
86 # define LCD_INVERT_COLORS /* Needed for colors to be correct, but why? */
88 /* you have to set lccr0 and lccr3 (including pcd) */
89 # define REG_LCCR0 0x0030087C
90 # define REG_LCCR3 0x0340FF08
92 vidinfo_t panel_info = {
97 vl_clkp: CONFIG_SYS_HIGH,
98 vl_oep: CONFIG_SYS_HIGH,
99 vl_hsp: CONFIG_SYS_HIGH,
100 vl_vsp: CONFIG_SYS_HIGH,
101 vl_dp: CONFIG_SYS_HIGH,
114 #endif /* CONFIG_SHARP_LM8V31 */
115 /*----------------------------------------------------------------------*/
116 #ifdef CONFIG_VOIPAC_LCD
118 # define LCD_BPP LCD_COLOR8
119 # define LCD_INVERT_COLORS
121 /* you have to set lccr0 and lccr3 (including pcd) */
122 # define REG_LCCR0 0x043008f8
123 # define REG_LCCR3 0x0340FF08
125 vidinfo_t panel_info = {
130 vl_clkp: CONFIG_SYS_HIGH,
131 vl_oep: CONFIG_SYS_HIGH,
132 vl_hsp: CONFIG_SYS_HIGH,
133 vl_vsp: CONFIG_SYS_HIGH,
134 vl_dp: CONFIG_SYS_HIGH,
147 #endif /* CONFIG_VOIPAC_LCD */
149 /*----------------------------------------------------------------------*/
150 #ifdef CONFIG_HITACHI_SX14
151 /* Hitachi SX14Q004-ZZA color STN LCD */
152 #define LCD_BPP LCD_COLOR8
154 /* you have to set lccr0 and lccr3 (including pcd) */
155 #define REG_LCCR0 0x00301079
156 #define REG_LCCR3 0x0340FF20
158 vidinfo_t panel_info = {
163 vl_clkp: CONFIG_SYS_HIGH,
164 vl_oep: CONFIG_SYS_HIGH,
165 vl_hsp: CONFIG_SYS_HIGH,
166 vl_vsp: CONFIG_SYS_HIGH,
167 vl_dp: CONFIG_SYS_HIGH,
180 #endif /* CONFIG_HITACHI_SX14 */
182 /*----------------------------------------------------------------------*/
184 #if LCD_BPP == LCD_COLOR8
185 void lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue);
187 #if LCD_BPP == LCD_MONOCHROME
188 void lcd_initcolregs (void);
191 #ifdef NOT_USED_SO_FAR
192 void lcd_disable (void);
193 void lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue);
194 #endif /* NOT_USED_SO_FAR */
196 void lcd_ctrl_init (void *lcdbase);
197 void lcd_enable (void);
203 void *lcd_base; /* Start of framebuffer memory */
204 void *lcd_console_address; /* Start of console buffer */
209 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid);
210 static void pxafb_setup_gpio (vidinfo_t *vid);
211 static void pxafb_enable_controller (vidinfo_t *vid);
212 static int pxafb_init (vidinfo_t *vid);
213 /************************************************************************/
215 /************************************************************************/
216 /* --------------- PXA chipset specific functions ------------------- */
217 /************************************************************************/
219 void lcd_ctrl_init (void *lcdbase)
221 pxafb_init_mem(lcdbase, &panel_info);
222 pxafb_init(&panel_info);
223 pxafb_setup_gpio(&panel_info);
224 pxafb_enable_controller(&panel_info);
227 /*----------------------------------------------------------------------*/
228 #ifdef NOT_USED_SO_FAR
230 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
233 #endif /* NOT_USED_SO_FAR */
235 /*----------------------------------------------------------------------*/
236 #if LCD_BPP == LCD_COLOR8
238 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
240 struct pxafb_info *fbi = &panel_info.pxa;
241 unsigned short *palette = (unsigned short *)fbi->palette;
244 if (regno < fbi->palette_size) {
245 val = ((red << 8) & 0xf800);
246 val |= ((green << 4) & 0x07e0);
247 val |= (blue & 0x001f);
249 #ifdef LCD_INVERT_COLORS
250 palette[regno] = ~val;
252 palette[regno] = val;
256 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %04X\n",
257 regno, &palette[regno],
261 #endif /* LCD_COLOR8 */
263 /*----------------------------------------------------------------------*/
264 #if LCD_BPP == LCD_MONOCHROME
265 void lcd_initcolregs (void)
267 struct pxafb_info *fbi = &panel_info.pxa;
268 cmap = (ushort *)fbi->palette;
271 for (regno = 0; regno < 16; regno++) {
273 cmap[(regno * 2) + 1] = regno & 0x0f;
276 #endif /* LCD_MONOCHROME */
278 /*----------------------------------------------------------------------*/
279 void lcd_enable (void)
283 /*----------------------------------------------------------------------*/
284 #ifdef NOT_USED_SO_FAR
285 static void lcd_disable (void)
288 #endif /* NOT_USED_SO_FAR */
290 /*----------------------------------------------------------------------*/
292 /************************************************************************/
293 /* ** PXA255 specific routines */
294 /************************************************************************/
297 * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
298 * descriptors and palette areas.
300 ulong calc_fbsize (void)
303 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
305 size = line_length * panel_info.vl_row;
311 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid)
313 u_long palette_mem_size;
314 struct pxafb_info *fbi = &vid->pxa;
315 int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
317 fbi->screen = (u_long)lcdbase;
319 fbi->palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
320 palette_mem_size = fbi->palette_size * sizeof(u16);
322 debug("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
323 /* locate palette and descs at end of page following fb */
324 fbi->palette = (u_long)lcdbase + fb_size + PAGE_SIZE - palette_mem_size;
328 #ifdef CONFIG_CPU_MONAHANS
329 static inline void pxafb_setup_gpio (vidinfo_t *vid) {}
331 static void pxafb_setup_gpio (vidinfo_t *vid)
336 * setup is based on type of panel supported
339 lccr0 = vid->pxa.reg_lccr0;
341 /* 4 bit interface */
342 if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))
344 debug("Setting GPIO for 4 bit data\n");
346 GPDR1 |= (0xf << 26);
347 GAFR1_U = (GAFR1_U & ~(0xff << 20)) | (0xaa << 20);
350 GPDR2 |= (0xf << 10);
351 GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);
354 /* 8 bit interface */
355 else if (((lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_DPD))) ||
356 (!(lccr0 & LCCR0_CMS) && !(lccr0 & LCCR0_PAS) && !(lccr0 & LCCR0_SDS)))
358 debug("Setting GPIO for 8 bit data\n");
360 GPDR1 |= (0x3f << 26);
363 GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);
364 GAFR2_L = (GAFR2_L & ~0xf) | (0xa);
367 GPDR2 |= (0xf << 10);
368 GAFR2_L = (GAFR2_L & ~(0xff << 20)) | (0xaa << 20);
371 /* 16 bit interface */
372 else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))
374 debug("Setting GPIO for 16 bit data\n");
376 GPDR1 |= (0x3f << 26);
379 GAFR1_U = (GAFR1_U & ~(0xfff << 20)) | (0xaaa << 20);
380 GAFR2_L = (GAFR2_L & 0xf0000000) | 0x0aaaaaaa;
384 printf("pxafb_setup_gpio: unable to determine bits per pixel\n");
389 static void pxafb_enable_controller (vidinfo_t *vid)
391 debug("Enabling LCD controller\n");
393 /* Sequence from 11.7.10 */
394 LCCR3 = vid->pxa.reg_lccr3;
395 LCCR2 = vid->pxa.reg_lccr2;
396 LCCR1 = vid->pxa.reg_lccr1;
397 LCCR0 = vid->pxa.reg_lccr0 & ~LCCR0_ENB;
398 FDADR0 = vid->pxa.fdadr0;
399 FDADR1 = vid->pxa.fdadr1;
402 #ifdef CONFIG_CPU_MONAHANS
403 CKENA |= CKENA_1_LCD;
408 debug("FDADR0 = 0x%08x\n", (unsigned int)FDADR0);
409 debug("FDADR1 = 0x%08x\n", (unsigned int)FDADR1);
410 debug("LCCR0 = 0x%08x\n", (unsigned int)LCCR0);
411 debug("LCCR1 = 0x%08x\n", (unsigned int)LCCR1);
412 debug("LCCR2 = 0x%08x\n", (unsigned int)LCCR2);
413 debug("LCCR3 = 0x%08x\n", (unsigned int)LCCR3);
416 static int pxafb_init (vidinfo_t *vid)
418 struct pxafb_info *fbi = &vid->pxa;
420 debug("Configuring PXA LCD\n");
422 fbi->reg_lccr0 = REG_LCCR0;
423 fbi->reg_lccr3 = REG_LCCR3;
425 debug("vid: vl_col=%d hslen=%d lm=%d rm=%d\n",
426 vid->vl_col, vid->vl_hpw,
427 vid->vl_blw, vid->vl_elw);
428 debug("vid: vl_row=%d vslen=%d um=%d bm=%d\n",
429 vid->vl_row, vid->vl_vpw,
430 vid->vl_bfw, vid->vl_efw);
433 LCCR1_DisWdth(vid->vl_col) +
434 LCCR1_HorSnchWdth(vid->vl_hpw) +
435 LCCR1_BegLnDel(vid->vl_blw) +
436 LCCR1_EndLnDel(vid->vl_elw);
439 LCCR2_DisHght(vid->vl_row) +
440 LCCR2_VrtSnchWdth(vid->vl_vpw) +
441 LCCR2_BegFrmDel(vid->vl_bfw) +
442 LCCR2_EndFrmDel(vid->vl_efw);
444 fbi->reg_lccr3 = REG_LCCR3 & ~(LCCR3_HSP | LCCR3_VSP);
445 fbi->reg_lccr3 |= (vid->vl_hsp ? LCCR3_HorSnchL : LCCR3_HorSnchH)
446 | (vid->vl_vsp ? LCCR3_VrtSnchL : LCCR3_VrtSnchH);
449 /* setup dma descriptors */
450 fbi->dmadesc_fblow = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 3*16);
451 fbi->dmadesc_fbhigh = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 2*16);
452 fbi->dmadesc_palette = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 1*16);
454 #define BYTES_PER_PANEL ((fbi->reg_lccr0 & LCCR0_SDS) ? \
455 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8 / 2) : \
456 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8))
458 /* populate descriptors */
459 fbi->dmadesc_fblow->fdadr = (u_long)fbi->dmadesc_fblow;
460 fbi->dmadesc_fblow->fsadr = fbi->screen + BYTES_PER_PANEL;
461 fbi->dmadesc_fblow->fidr = 0;
462 fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL;
464 fbi->fdadr1 = (u_long)fbi->dmadesc_fblow; /* only used in dual-panel mode */
466 fbi->dmadesc_fbhigh->fsadr = fbi->screen;
467 fbi->dmadesc_fbhigh->fidr = 0;
468 fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL;
470 fbi->dmadesc_palette->fsadr = fbi->palette;
471 fbi->dmadesc_palette->fidr = 0;
472 fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
474 if( NBITS(vid->vl_bpix) < 12)
476 /* assume any mode with <12 bpp is palette driven */
477 fbi->dmadesc_palette->fdadr = (u_long)fbi->dmadesc_fbhigh;
478 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_palette;
479 /* flips back and forth between pal and fbhigh */
480 fbi->fdadr0 = (u_long)fbi->dmadesc_palette;
484 /* palette shouldn't be loaded in true-color mode */
485 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_fbhigh;
486 fbi->fdadr0 = (u_long)fbi->dmadesc_fbhigh; /* no pal just fbhigh */
489 debug("fbi->dmadesc_fblow = 0x%lx\n", (u_long)fbi->dmadesc_fblow);
490 debug("fbi->dmadesc_fbhigh = 0x%lx\n", (u_long)fbi->dmadesc_fbhigh);
491 debug("fbi->dmadesc_palette = 0x%lx\n", (u_long)fbi->dmadesc_palette);
493 debug("fbi->dmadesc_fblow->fdadr = 0x%lx\n", fbi->dmadesc_fblow->fdadr);
494 debug("fbi->dmadesc_fbhigh->fdadr = 0x%lx\n", fbi->dmadesc_fbhigh->fdadr);
495 debug("fbi->dmadesc_palette->fdadr = 0x%lx\n", fbi->dmadesc_palette->fdadr);
497 debug("fbi->dmadesc_fblow->fsadr = 0x%lx\n", fbi->dmadesc_fblow->fsadr);
498 debug("fbi->dmadesc_fbhigh->fsadr = 0x%lx\n", fbi->dmadesc_fbhigh->fsadr);
499 debug("fbi->dmadesc_palette->fsadr = 0x%lx\n", fbi->dmadesc_palette->fsadr);
501 debug("fbi->dmadesc_fblow->ldcmd = 0x%lx\n", fbi->dmadesc_fblow->ldcmd);
502 debug("fbi->dmadesc_fbhigh->ldcmd = 0x%lx\n", fbi->dmadesc_fbhigh->ldcmd);
503 debug("fbi->dmadesc_palette->ldcmd = 0x%lx\n", fbi->dmadesc_palette->ldcmd);
508 /************************************************************************/
509 /************************************************************************/
511 #endif /* CONFIG_LCD */