]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/pxa/pxafb.c
PXA: pxa-regs.h cleanup
[u-boot] / arch / arm / cpu / pxa / pxafb.c
1 /*
2  * PXA LCD Controller
3  *
4  * (C) Copyright 2001-2002
5  * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
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.
14  *
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.
19  *
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,
23  * MA 02111-1307 USA
24  */
25
26 /************************************************************************/
27 /* ** HEADER FILES                                                      */
28 /************************************************************************/
29
30 #include <config.h>
31 #include <common.h>
32 #include <version.h>
33 #include <stdarg.h>
34 #include <linux/types.h>
35 #include <stdio_dev.h>
36 #include <lcd.h>
37 #include <asm/arch/pxa-regs.h>
38 #include <asm/io.h>
39
40 /* #define DEBUG */
41
42 #ifdef CONFIG_LCD
43
44 /*----------------------------------------------------------------------*/
45 /*
46  * Define panel bpp, LCCR0, LCCR3 and panel_info video struct for
47  * your display.
48  */
49
50 #ifdef CONFIG_PXA_VGA
51 /* LCD outputs connected to a video DAC  */
52 # define LCD_BPP        LCD_COLOR8
53
54 /* you have to set lccr0 and lccr3 (including pcd) */
55 # define REG_LCCR0      0x003008f8
56 # define REG_LCCR3      0x0300FF01
57
58 /* 640x480x16 @ 61 Hz */
59 vidinfo_t panel_info = {
60         .vl_col         = 640,
61         .vl_row         = 480,
62         .vl_width       = 640,
63         .vl_height      = 480,
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,
69         .vl_bpix        = LCD_BPP,
70         .vl_lbw         = 0,
71         .vl_splt        = 0,
72         .vl_clor        = 0,
73         .vl_tft         = 1,
74         .vl_hpw         = 40,
75         .vl_blw         = 56,
76         .vl_elw         = 56,
77         .vl_vpw         = 20,
78         .vl_bfw         = 8,
79         .vl_efw         = 8,
80 };
81 #endif /* CONFIG_PXA_VIDEO */
82
83 /*----------------------------------------------------------------------*/
84 #ifdef CONFIG_SHARP_LM8V31
85
86 # define LCD_BPP        LCD_COLOR8
87 # define LCD_INVERT_COLORS      /* Needed for colors to be correct, but why?    */
88
89 /* you have to set lccr0 and lccr3 (including pcd) */
90 # define REG_LCCR0      0x0030087C
91 # define REG_LCCR3      0x0340FF08
92
93 vidinfo_t panel_info = {
94         .vl_col         = 640,
95         .vl_row         = 480,
96         .vl_width       = 157,
97         .vl_height      = 118,
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,
103         .vl_bpix        = LCD_BPP,
104         .vl_lbw         = 0,
105         .vl_splt        = 1,
106         .vl_clor        = 1,
107         .vl_tft         = 0,
108         .vl_hpw         = 1,
109         .vl_blw         = 3,
110         .vl_elw         = 3,
111         .vl_vpw         = 1,
112         .vl_bfw         = 0,
113         .vl_efw         = 0,
114 };
115 #endif /* CONFIG_SHARP_LM8V31 */
116 /*----------------------------------------------------------------------*/
117 #ifdef CONFIG_VOIPAC_LCD
118
119 # define LCD_BPP        LCD_COLOR8
120 # define LCD_INVERT_COLORS
121
122 /* you have to set lccr0 and lccr3 (including pcd) */
123 # define REG_LCCR0      0x043008f8
124 # define REG_LCCR3      0x0340FF08
125
126 vidinfo_t panel_info = {
127         .vl_col         = 640,
128         .vl_row         = 480,
129         .vl_width       = 157,
130         .vl_height      = 118,
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,
136         .vl_bpix        = LCD_BPP,
137         .vl_lbw         = 0,
138         .vl_splt        = 1,
139         .vl_clor        = 1,
140         .vl_tft         = 1,
141         .vl_hpw         = 32,
142         .vl_blw         = 144,
143         .vl_elw         = 32,
144         .vl_vpw         = 2,
145         .vl_bfw         = 13,
146         .vl_efw         = 30,
147 };
148 #endif /* CONFIG_VOIPAC_LCD */
149
150 /*----------------------------------------------------------------------*/
151 #ifdef CONFIG_HITACHI_SX14
152 /* Hitachi SX14Q004-ZZA color STN LCD */
153 #define LCD_BPP         LCD_COLOR8
154
155 /* you have to set lccr0 and lccr3 (including pcd) */
156 #define REG_LCCR0       0x00301079
157 #define REG_LCCR3       0x0340FF20
158
159 vidinfo_t panel_info = {
160         .vl_col         = 320,
161         .vl_row         = 240,
162         .vl_width       = 167,
163         .vl_height      = 109,
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,
169         .vl_bpix        = LCD_BPP,
170         .vl_lbw         = 1,
171         .vl_splt        = 0,
172         .vl_clor        = 1,
173         .vl_tft         = 0,
174         .vl_hpw         = 1,
175         .vl_blw         = 1,
176         .vl_elw         = 1,
177         .vl_vpw         = 7,
178         .vl_bfw         = 0,
179         .vl_efw         = 0,
180 };
181 #endif /* CONFIG_HITACHI_SX14 */
182
183 /*----------------------------------------------------------------------*/
184 #ifdef CONFIG_LMS283GF05
185
186 # define LCD_BPP        LCD_COLOR8
187 /*# define LCD_INVERT_COLORS*/
188
189 /* you have to set lccr0 and lccr3 (including pcd) */
190 # define REG_LCCR0      0x043008f8
191 # define REG_LCCR3      0x03b00009
192
193 vidinfo_t panel_info = {
194         .vl_col         = 240,
195         .vl_row         = 320,
196         .vl_width       = 240,
197         .vl_height      = 320,
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,
203         .vl_bpix        = LCD_BPP,
204         .vl_lbw         = 0,
205         .vl_splt        = 1,
206         .vl_clor        = 1,
207         .vl_tft         = 1,
208         .vl_hpw         = 4,
209         .vl_blw         = 4,
210         .vl_elw         = 8,
211         .vl_vpw         = 4,
212         .vl_bfw         = 4,
213         .vl_efw         = 8,
214 };
215 #endif /* CONFIG_LMS283GF05 */
216
217 /*----------------------------------------------------------------------*/
218
219 #if LCD_BPP == LCD_COLOR8
220 void lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue);
221 #endif
222 #if LCD_BPP == LCD_MONOCHROME
223 void lcd_initcolregs (void);
224 #endif
225
226 #ifdef NOT_USED_SO_FAR
227 void lcd_disable (void);
228 void lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue);
229 #endif /* NOT_USED_SO_FAR */
230
231 void lcd_ctrl_init      (void *lcdbase);
232 void lcd_enable (void);
233
234 int lcd_line_length;
235 int lcd_color_fg;
236 int lcd_color_bg;
237
238 void *lcd_base;                 /* Start of framebuffer memory  */
239 void *lcd_console_address;              /* Start of console buffer      */
240
241 short console_col;
242 short console_row;
243
244 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid);
245 static void pxafb_setup_gpio (vidinfo_t *vid);
246 static void pxafb_enable_controller (vidinfo_t *vid);
247 static int pxafb_init (vidinfo_t *vid);
248 /************************************************************************/
249
250 /************************************************************************/
251 /* ---------------  PXA chipset specific functions  ------------------- */
252 /************************************************************************/
253
254 void lcd_ctrl_init (void *lcdbase)
255 {
256         pxafb_init_mem(lcdbase, &panel_info);
257         pxafb_init(&panel_info);
258         pxafb_setup_gpio(&panel_info);
259         pxafb_enable_controller(&panel_info);
260 }
261
262 /*----------------------------------------------------------------------*/
263 #ifdef NOT_USED_SO_FAR
264 void
265 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
266 {
267 }
268 #endif /* NOT_USED_SO_FAR */
269
270 /*----------------------------------------------------------------------*/
271 #if LCD_BPP == LCD_COLOR8
272 void
273 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
274 {
275         struct pxafb_info *fbi = &panel_info.pxa;
276         unsigned short *palette = (unsigned short *)fbi->palette;
277         u_int val;
278
279         if (regno < fbi->palette_size) {
280                 val = ((red << 8) & 0xf800);
281                 val |= ((green << 4) & 0x07e0);
282                 val |= (blue & 0x001f);
283
284 #ifdef LCD_INVERT_COLORS
285                 palette[regno] = ~val;
286 #else
287                 palette[regno] = val;
288 #endif
289         }
290
291         debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %04X\n",
292                 regno, &palette[regno],
293                 red, green, blue,
294                 palette[regno]);
295 }
296 #endif /* LCD_COLOR8 */
297
298 /*----------------------------------------------------------------------*/
299 #if LCD_BPP == LCD_MONOCHROME
300 void lcd_initcolregs (void)
301 {
302         struct pxafb_info *fbi = &panel_info.pxa;
303         cmap = (ushort *)fbi->palette;
304         ushort regno;
305
306         for (regno = 0; regno < 16; regno++) {
307                 cmap[regno * 2] = 0;
308                 cmap[(regno * 2) + 1] = regno & 0x0f;
309         }
310 }
311 #endif /* LCD_MONOCHROME */
312
313 /*----------------------------------------------------------------------*/
314 void lcd_enable (void)
315 {
316 }
317
318 /*----------------------------------------------------------------------*/
319 #ifdef  NOT_USED_SO_FAR
320 static void lcd_disable (void)
321 {
322 }
323 #endif /* NOT_USED_SO_FAR */
324
325 /*----------------------------------------------------------------------*/
326
327 /************************************************************************/
328 /* ** PXA255 specific routines                                          */
329 /************************************************************************/
330
331 /*
332  * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
333  * descriptors and palette areas.
334  */
335 ulong calc_fbsize (void)
336 {
337         ulong size;
338         int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
339
340         size = line_length * panel_info.vl_row;
341         size += PAGE_SIZE;
342
343         return size;
344 }
345
346 static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid)
347 {
348         u_long palette_mem_size;
349         struct pxafb_info *fbi = &vid->pxa;
350         int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
351
352         fbi->screen = (u_long)lcdbase;
353
354         fbi->palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
355         palette_mem_size = fbi->palette_size * sizeof(u16);
356
357         debug("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
358         /* locate palette and descs at end of page following fb */
359         fbi->palette = (u_long)lcdbase + fb_size + PAGE_SIZE - palette_mem_size;
360
361         return 0;
362 }
363 #ifdef  CONFIG_CPU_MONAHANS
364 static inline void pxafb_setup_gpio (vidinfo_t *vid) {}
365 #else
366 static void pxafb_setup_gpio (vidinfo_t *vid)
367 {
368         u_long lccr0;
369
370         /*
371          * setup is based on type of panel supported
372          */
373
374         lccr0 = vid->pxa.reg_lccr0;
375
376         /* 4 bit interface */
377         if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))
378         {
379                 debug("Setting GPIO for 4 bit data\n");
380                 /* bits 58-61 */
381                 writel(readl(GPDR1) | (0xf << 26), GPDR1);
382                 writel((readl(GAFR1_U) & ~(0xff << 20)) | (0xaa << 20),
383                         GAFR1_U);
384
385                 /* bits 74-77 */
386                 writel(readl(GPDR2) | (0xf << 10), GPDR2);
387                 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
388                         GAFR2_L);
389         }
390
391         /* 8 bit interface */
392         else if (((lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_DPD))) ||
393                 (!(lccr0 & LCCR0_CMS) && !(lccr0 & LCCR0_PAS) && !(lccr0 & LCCR0_SDS)))
394         {
395                 debug("Setting GPIO for 8 bit data\n");
396                 /* bits 58-65 */
397                 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
398                 writel(readl(GPDR2) | (0x3), GPDR2);
399
400                 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
401                         GAFR1_U);
402                 writel((readl(GAFR2_L) & ~0xf) | (0xa), GAFR2_L);
403
404                 /* bits 74-77 */
405                 writel(readl(GPDR2) | (0xf << 10), GPDR2);
406                 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
407                         GAFR2_L);
408         }
409
410         /* 16 bit interface */
411         else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))
412         {
413                 debug("Setting GPIO for 16 bit data\n");
414                 /* bits 58-77 */
415                 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
416                 writel(readl(GPDR2) | 0x00003fff, GPDR2);
417
418                 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
419                         GAFR1_U);
420                 writel((readl(GAFR2_L) & 0xf0000000) | 0x0aaaaaaa, GAFR2_L);
421         }
422         else
423         {
424                 printf("pxafb_setup_gpio: unable to determine bits per pixel\n");
425         }
426 }
427 #endif
428
429 static void pxafb_enable_controller (vidinfo_t *vid)
430 {
431         debug("Enabling LCD controller\n");
432
433         /* Sequence from 11.7.10 */
434         writel(vid->pxa.reg_lccr3, LCCR3);
435         writel(vid->pxa.reg_lccr2, LCCR2);
436         writel(vid->pxa.reg_lccr1, LCCR1);
437         writel(vid->pxa.reg_lccr0 & ~LCCR0_ENB, LCCR0);
438         writel(vid->pxa.fdadr0, FDADR0);
439         writel(vid->pxa.fdadr1, FDADR1);
440         writel(readl(LCCR0) | LCCR0_ENB, LCCR0);
441
442 #ifdef  CONFIG_CPU_MONAHANS
443         writel(readl(CKENA) | CKENA_1_LCD, CKENA);
444 #else
445         writel(readl(CKEN) | CKEN16_LCD, CKEN);
446 #endif
447
448         debug("FDADR0 = 0x%08x\n", readl(FDADR0));
449         debug("FDADR1 = 0x%08x\n", readl(FDADR1));
450         debug("LCCR0 = 0x%08x\n", readl(LCCR0));
451         debug("LCCR1 = 0x%08x\n", readl(LCCR1));
452         debug("LCCR2 = 0x%08x\n", readl(LCCR2));
453         debug("LCCR3 = 0x%08x\n", readl(LCCR3));
454 }
455
456 static int pxafb_init (vidinfo_t *vid)
457 {
458         struct pxafb_info *fbi = &vid->pxa;
459
460         debug("Configuring PXA LCD\n");
461
462         fbi->reg_lccr0 = REG_LCCR0;
463         fbi->reg_lccr3 = REG_LCCR3;
464
465         debug("vid: vl_col=%d hslen=%d lm=%d rm=%d\n",
466                 vid->vl_col, vid->vl_hpw,
467                 vid->vl_blw, vid->vl_elw);
468         debug("vid: vl_row=%d vslen=%d um=%d bm=%d\n",
469                 vid->vl_row, vid->vl_vpw,
470                 vid->vl_bfw, vid->vl_efw);
471
472         fbi->reg_lccr1 =
473                 LCCR1_DisWdth(vid->vl_col) +
474                 LCCR1_HorSnchWdth(vid->vl_hpw) +
475                 LCCR1_BegLnDel(vid->vl_blw) +
476                 LCCR1_EndLnDel(vid->vl_elw);
477
478         fbi->reg_lccr2 =
479                 LCCR2_DisHght(vid->vl_row) +
480                 LCCR2_VrtSnchWdth(vid->vl_vpw) +
481                 LCCR2_BegFrmDel(vid->vl_bfw) +
482                 LCCR2_EndFrmDel(vid->vl_efw);
483
484         fbi->reg_lccr3 = REG_LCCR3 & ~(LCCR3_HSP | LCCR3_VSP);
485         fbi->reg_lccr3 |= (vid->vl_hsp ? LCCR3_HorSnchL : LCCR3_HorSnchH)
486                         | (vid->vl_vsp ? LCCR3_VrtSnchL : LCCR3_VrtSnchH);
487
488
489         /* setup dma descriptors */
490         fbi->dmadesc_fblow = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 3*16);
491         fbi->dmadesc_fbhigh = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 2*16);
492         fbi->dmadesc_palette = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 1*16);
493
494         #define BYTES_PER_PANEL ((fbi->reg_lccr0 & LCCR0_SDS) ? \
495                 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8 / 2) : \
496                 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8))
497
498         /* populate descriptors */
499         fbi->dmadesc_fblow->fdadr = (u_long)fbi->dmadesc_fblow;
500         fbi->dmadesc_fblow->fsadr = fbi->screen + BYTES_PER_PANEL;
501         fbi->dmadesc_fblow->fidr  = 0;
502         fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL;
503
504         fbi->fdadr1 = (u_long)fbi->dmadesc_fblow; /* only used in dual-panel mode */
505
506         fbi->dmadesc_fbhigh->fsadr = fbi->screen;
507         fbi->dmadesc_fbhigh->fidr = 0;
508         fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL;
509
510         fbi->dmadesc_palette->fsadr = fbi->palette;
511         fbi->dmadesc_palette->fidr  = 0;
512         fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
513
514         if( NBITS(vid->vl_bpix) < 12)
515         {
516                 /* assume any mode with <12 bpp is palette driven */
517                 fbi->dmadesc_palette->fdadr = (u_long)fbi->dmadesc_fbhigh;
518                 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_palette;
519                 /* flips back and forth between pal and fbhigh */
520                 fbi->fdadr0 = (u_long)fbi->dmadesc_palette;
521         }
522         else
523         {
524                 /* palette shouldn't be loaded in true-color mode */
525                 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_fbhigh;
526                 fbi->fdadr0 = (u_long)fbi->dmadesc_fbhigh; /* no pal just fbhigh */
527         }
528
529         debug("fbi->dmadesc_fblow = 0x%lx\n", (u_long)fbi->dmadesc_fblow);
530         debug("fbi->dmadesc_fbhigh = 0x%lx\n", (u_long)fbi->dmadesc_fbhigh);
531         debug("fbi->dmadesc_palette = 0x%lx\n", (u_long)fbi->dmadesc_palette);
532
533         debug("fbi->dmadesc_fblow->fdadr = 0x%lx\n", fbi->dmadesc_fblow->fdadr);
534         debug("fbi->dmadesc_fbhigh->fdadr = 0x%lx\n", fbi->dmadesc_fbhigh->fdadr);
535         debug("fbi->dmadesc_palette->fdadr = 0x%lx\n", fbi->dmadesc_palette->fdadr);
536
537         debug("fbi->dmadesc_fblow->fsadr = 0x%lx\n", fbi->dmadesc_fblow->fsadr);
538         debug("fbi->dmadesc_fbhigh->fsadr = 0x%lx\n", fbi->dmadesc_fbhigh->fsadr);
539         debug("fbi->dmadesc_palette->fsadr = 0x%lx\n", fbi->dmadesc_palette->fsadr);
540
541         debug("fbi->dmadesc_fblow->ldcmd = 0x%lx\n", fbi->dmadesc_fblow->ldcmd);
542         debug("fbi->dmadesc_fbhigh->ldcmd = 0x%lx\n", fbi->dmadesc_fbhigh->ldcmd);
543         debug("fbi->dmadesc_palette->ldcmd = 0x%lx\n", fbi->dmadesc_palette->ldcmd);
544
545         return 0;
546 }
547
548 /************************************************************************/
549 /************************************************************************/
550
551 #endif /* CONFIG_LCD */