]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/mpc8xx/lcd.c
Add support for BMS2003 board
[karo-tx-uboot.git] / cpu / mpc8xx / lcd.c
1 /*
2  * (C) Copyright 2001-2002
3  * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 /************************************************************************/
25 /* ** HEADER FILES                                                      */
26 /************************************************************************/
27
28 /* #define DEBUG */
29
30 #include <config.h>
31 #include <common.h>
32 #include <watchdog.h>
33 #include <version.h>
34 #include <stdarg.h>
35 #include <lcdvideo.h>
36 #include <linux/types.h>
37 #include <devices.h>
38 #if defined(CONFIG_POST)
39 #include <post.h>
40 #endif
41 #include <lcd.h>
42
43 #ifdef CONFIG_LCD
44
45 /************************************************************************/
46 /* ** CONFIG STUFF -- should be moved to board config file              */
47 /************************************************************************/
48 #define CONFIG_LCD_LOGO
49 #define LCD_INFO                /* Display Logo, (C) and system info    */
50
51 #if defined(CONFIG_V37) || defined(CONFIG_EDT32F10)
52 #undef CONFIG_LCD_LOGO
53 #undef LCD_INFO
54 #endif
55
56 /* #define LCD_TEST_PATTERN */  /* color backgnd for frame/color adjust */
57 /* #define CFG_INVERT_COLORS */ /* Not needed - adjust vl_dp instead    */
58 /************************************************************************/
59
60 /************************************************************************/
61 /* ** BITMAP DISPLAY SUPPORT  -- should probably be moved elsewhere     */
62 /************************************************************************/
63
64 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
65 #include <bmp_layout.h>
66 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
67
68 /************************************************************************/
69 /* ** FONT AND LOGO DATA                                                */
70 /************************************************************************/
71
72 #include <video_font.h>         /* Get font data, width and height      */
73
74 #ifdef CONFIG_LCD_LOGO
75 # include <bmp_logo.h>          /* Get logo data, width and height      */
76 #endif
77
78 /************************************************************************/
79 /************************************************************************/
80
81 /*
82  *  Information about displays we are using.  This is for configuring
83  *  the LCD controller and memory allocation.  Someone has to know what
84  *  is connected, as we can't autodetect anything.
85  */
86 #define CFG_HIGH        0       /* Pins are active high */
87 #define CFG_LOW         1       /* Pins are active low */
88
89 typedef struct vidinfo {
90     ushort      vl_col;         /* Number of columns (i.e. 640) */
91     ushort      vl_row;         /* Number of rows (i.e. 480) */
92     ushort      vl_width;       /* Width of display area in millimeters */
93     ushort      vl_height;      /* Height of display area in millimeters */
94
95     /* LCD configuration register.
96     */
97     u_char      vl_clkp;        /* Clock polarity */
98     u_char      vl_oep;         /* Output Enable polarity */
99     u_char      vl_hsp;         /* Horizontal Sync polarity */
100     u_char      vl_vsp;         /* Vertical Sync polarity */
101     u_char      vl_dp;          /* Data polarity */
102     u_char      vl_bpix;        /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
103     u_char      vl_lbw;         /* LCD Bus width, 0 = 4, 1 = 8 */
104     u_char      vl_splt;        /* Split display, 0 = single-scan, 1 = dual-scan */
105     u_char      vl_clor;        /* Color, 0 = mono, 1 = color */
106     u_char      vl_tft;         /* 0 = passive, 1 = TFT */
107
108     /* Horizontal control register.  Timing from data sheet.
109     */
110     ushort      vl_wbl;         /* Wait between lines */
111
112     /* Vertical control register.
113     */
114     u_char      vl_vpw;         /* Vertical sync pulse width */
115     u_char      vl_lcdac;       /* LCD AC timing */
116     u_char      vl_wbf;         /* Wait between frames */
117 } vidinfo_t;
118
119 #define LCD_MONOCHROME  0
120 #define LCD_COLOR2      1
121 #define LCD_COLOR4      2
122 #define LCD_COLOR8      3
123
124 /*----------------------------------------------------------------------*/
125 #ifdef CONFIG_KYOCERA_KCS057QV1AJ
126 /*
127  *  Kyocera KCS057QV1AJ-G23. Passive, color, single scan.
128  */
129 #define LCD_BPP LCD_COLOR4
130
131 static vidinfo_t panel_info = {
132     640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
133     LCD_BPP, 1, 0, 1, 0,  5, 0, 0, 0
134                 /* wbl, vpw, lcdac, wbf */
135 };
136 #endif /* CONFIG_KYOCERA_KCS057QV1AJ */
137 /*----------------------------------------------------------------------*/
138
139 /*----------------------------------------------------------------------*/
140 #ifdef CONFIG_HITACHI_SP19X001_Z1A
141 /*
142  *  Hitachi SP19X001-. Active, color, single scan.
143  */
144 static vidinfo_t panel_info = {
145     640, 480, 154, 116, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
146     LCD_COLOR8, 1, 0, 1, 0, 0, 0, 0, 0
147                 /* wbl, vpw, lcdac, wbf */
148 };
149 #endif /* CONFIG_HITACHI_SP19X001_Z1A */
150 /*----------------------------------------------------------------------*/
151
152 /*----------------------------------------------------------------------*/
153 #ifdef CONFIG_NEC_NL6448AC33
154 /*
155  *  NEC NL6448AC33-18. Active, color, single scan.
156  */
157 static vidinfo_t panel_info = {
158     640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
159     3, 0, 0, 1, 1, 144, 2, 0, 33
160                 /* wbl, vpw, lcdac, wbf */
161 };
162 #endif /* CONFIG_NEC_NL6448AC33 */
163 /*----------------------------------------------------------------------*/
164
165 #ifdef CONFIG_NEC_NL6448BC20
166 /*
167  *  NEC NL6448BC20-08.  6.5", 640x480. Active, color, single scan.
168  */
169 static vidinfo_t panel_info = {
170     640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
171     3, 0, 0, 1, 1, 144, 2, 0, 33
172                 /* wbl, vpw, lcdac, wbf */
173 };
174 #endif /* CONFIG_NEC_NL6448BC20 */
175 /*----------------------------------------------------------------------*/
176
177 #ifdef CONFIG_NEC_NL6448BC33_54
178 /*
179  *  NEC NL6448BC33-54. 10.4", 640x480. Active, color, single scan.
180  */
181 static vidinfo_t panel_info = {
182     640, 480, 212, 158, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
183     3, 0, 0, 1, 1, 144, 2, 0, 33
184                 /* wbl, vpw, lcdac, wbf */
185 };
186 #endif /* CONFIG_NEC_NL6448BC33_54 */
187 /*----------------------------------------------------------------------*/
188
189 #ifdef CONFIG_SHARP_LQ104V7DS01
190 /*
191  *  SHARP LQ104V7DS01. 6.5", 640x480. Active, color, single scan.
192  */
193 static vidinfo_t panel_info = {
194     640, 480, 132, 99, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
195     3, 0, 0, 1, 1, 25, 1, 0, 33
196                 /* wbl, vpw, lcdac, wbf */
197 };
198 #endif /* CONFIG_SHARP_LQ104V7DS01 */
199 /*----------------------------------------------------------------------*/
200
201 #ifdef CONFIG_SHARP_16x9
202 /*
203  * Sharp 320x240. Active, color, single scan.  It isn't 16x9, and I am
204  * not sure what it is.......
205  */
206 static vidinfo_t panel_info = {
207     320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
208     3, 0, 0, 1, 1, 15, 4, 0, 3
209 };
210 #endif /* CONFIG_SHARP_16x9 */
211 /*----------------------------------------------------------------------*/
212
213 #ifdef CONFIG_SHARP_LQ057Q3DC02
214 /*
215  * Sharp LQ057Q3DC02 display. Active, color, single scan.
216  */
217 #define LCD_DF 12
218
219 static vidinfo_t panel_info = {
220     320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
221     3, 0, 0, 1, 1, 15, 4, 0, 3
222                 /* wbl, vpw, lcdac, wbf */
223 };
224 #define LCD_INFO_BELOW_LOGO
225 #endif /* CONFIG_SHARP_LQ057Q3DC02 */
226 /*----------------------------------------------------------------------*/
227
228 #ifdef CONFIG_SHARP_LQ64D341
229 /*
230  * Sharp LQ64D341 display, 640x480. Active, color, single scan.
231  */
232 static vidinfo_t panel_info = {
233     640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
234     3, 0, 0, 1, 1, 128, 16, 0, 32
235                 /* wbl, vpw, lcdac, wbf */
236 };
237 #endif /* CONFIG_SHARP_LQ64D341 */
238
239 #ifdef CONFIG_SHARP_LQ065T9DR51U
240 /*
241  * Sharp LQ065T9DR51U display, 400x240. Active, color, single scan.
242  */
243 static vidinfo_t panel_info = {
244     400, 240, 143, 79, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH,
245     3, 0, 0, 1, 1, 248, 4, 0, 35
246                 /* wbl, vpw, lcdac, wbf */
247 };
248 #define LCD_INFO_BELOW_LOGO
249 #endif /* CONFIG_SHARP_LQ065T9DR51U */
250
251 #ifdef CONFIG_SHARP_LQ084V1DG21
252 /*
253  * Sharp LQ084V1DG21 display, 640x480. Active, color, single scan.
254  */
255 static vidinfo_t panel_info = {
256     640, 480, 171, 129, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_LOW,
257     3, 0, 0, 1, 1, 160, 3, 0, 48
258                 /* wbl, vpw, lcdac, wbf */
259 };
260 #endif /* CONFIG_SHARP_LQ084V1DG21 */
261
262 /*----------------------------------------------------------------------*/
263
264 #ifdef CONFIG_HLD1045
265 /*
266  * HLD1045 display, 640x480. Active, color, single scan.
267  */
268 static vidinfo_t panel_info = {
269     640, 480, 0, 0, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
270     3, 0, 0, 1, 1, 160, 3, 0, 48
271                 /* wbl, vpw, lcdac, wbf */
272 };
273 #endif /* CONFIG_HLD1045 */
274 /*----------------------------------------------------------------------*/
275
276 #ifdef CONFIG_PRIMEVIEW_V16C6448AC
277 /*
278  * Prime View V16C6448AC
279  */
280 static vidinfo_t panel_info = {
281     640, 480, 130, 98, CFG_HIGH, CFG_HIGH, CFG_LOW, CFG_LOW, CFG_HIGH,
282     3, 0, 0, 1, 1, 144, 2, 0, 35
283                 /* wbl, vpw, lcdac, wbf */
284 };
285 #endif /* CONFIG_PRIMEVIEW_V16C6448AC */
286
287 /*----------------------------------------------------------------------*/
288
289 #ifdef CONFIG_OPTREX_BW
290 /*
291  * Optrex   CBL50840-2 NF-FW 99 22 M5
292  * or
293  * Hitachi  LMG6912RPFC-00T
294  * or
295  * Hitachi  SP14Q002
296  *
297  * 320x240. Black & white.
298  */
299 #define OPTREX_BPP      0       /* 0 - monochrome,     1 bpp */
300                                 /* 1 -  4 grey levels, 2 bpp */
301                                 /* 2 - 16 grey levels, 4 bpp */
302 static vidinfo_t panel_info = {
303     320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
304     OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
305 };
306 #endif /* CONFIG_OPTREX_BW */
307
308 /*-----------------------------------------------------------------*/
309 #ifdef CONFIG_EDT32F10
310 /*
311  * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
312  */
313 #define LCD_BPP         LCD_MONOCHROME
314 #define LCD_DF          10
315
316 static vidinfo_t panel_info = {
317     320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
318     LCD_BPP,  0, 0, 0, 0, 33, 0, 0, 0
319 };
320 #endif
321 /*----------------------------------------------------------------------*/
322
323 #if defined(LCD_INFO_BELOW_LOGO)
324 # define LCD_INFO_X             0
325 # define LCD_INFO_Y             (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
326 #elif defined(CONFIG_LCD_LOGO)
327 # define LCD_INFO_X             (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
328 # define LCD_INFO_Y             (VIDEO_FONT_HEIGHT)
329 #else
330 # define LCD_INFO_X             (VIDEO_FONT_WIDTH)
331 # define LCD_INFO_Y             (VIDEO_FONT_HEIGHT)
332 #endif
333
334 #ifndef LCD_BPP
335 #define LCD_BPP                 LCD_COLOR8
336 #endif
337 #ifndef LCD_DF
338 #define LCD_DF                  1
339 #endif
340
341 #define NBITS(bit_code)         (1 << (bit_code))
342 #define NCOLORS(bit_code)       (1 << NBITS(bit_code))
343
344 static int lcd_line_length;
345
346 static int lcd_color_fg;
347 static int lcd_color_bg;
348
349 char lcd_is_enabled = 0;                /* Indicate that LCD is enabled */
350
351 /*
352  * Frame buffer memory information
353  */
354 static void *lcd_base;                  /* Start of framebuffer memory  */
355 static void *lcd_console_address;       /* Start of console buffer      */
356
357
358 /************************************************************************/
359 /* ** CONSOLE CONSTANTS                                                 */
360 /************************************************************************/
361
362 #if LCD_BPP == LCD_MONOCHROME
363
364 /*
365  * Simple color definitions
366  */
367 #define CONSOLE_COLOR_BLACK      0
368 #define CONSOLE_COLOR_WHITE      1      /* Must remain last / highest */
369
370 #else
371
372 /*
373  * Simple color definitions
374  */
375 #define CONSOLE_COLOR_BLACK      0
376 #define CONSOLE_COLOR_RED        1
377 #define CONSOLE_COLOR_GREEN      2
378 #define CONSOLE_COLOR_YELLOW     3
379 #define CONSOLE_COLOR_BLUE       4
380 #define CONSOLE_COLOR_MAGENTA    5
381 #define CONSOLE_COLOR_CYAN       6
382 #define CONSOLE_COLOR_GREY      14
383 #define CONSOLE_COLOR_WHITE     15      /* Must remain last / highest */
384
385 #endif
386
387 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
388 #error Default Color Map overlaps with Logo Color Map
389 #endif
390
391 /************************************************************************/
392
393 #ifndef PAGE_SIZE
394 #define PAGE_SIZE       4096
395 #endif
396
397
398 /************************************************************************/
399 /* ** CONSOLE DEFINITIONS & FUNCTIONS                                   */
400 /************************************************************************/
401
402 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
403 #define CONSOLE_ROWS            ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
404                                         / VIDEO_FONT_HEIGHT)
405 #else
406 #define CONSOLE_ROWS            (panel_info.vl_row / VIDEO_FONT_HEIGHT)
407 #endif
408 #define CONSOLE_COLS            (panel_info.vl_col / VIDEO_FONT_WIDTH)
409 #define CONSOLE_ROW_SIZE        (VIDEO_FONT_HEIGHT * lcd_line_length)
410 #define CONSOLE_ROW_FIRST       (lcd_console_address)
411 #define CONSOLE_ROW_SECOND      (lcd_console_address + CONSOLE_ROW_SIZE)
412 #define CONSOLE_ROW_LAST        (lcd_console_address + CONSOLE_SIZE \
413                                         - CONSOLE_ROW_SIZE)
414 #define CONSOLE_SIZE            (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
415 #define CONSOLE_SCROLL_SIZE     (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
416
417 #if  LCD_BPP == LCD_MONOCHROME
418 #define COLOR_MASK(c)           ((c)      | (c) << 1 | (c) << 2 | (c) << 3 | \
419                                  (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
420 #elif LCD_BPP == LCD_COLOR8
421 #define COLOR_MASK(c)           (c)
422 #else
423 #error Unsupported LCD BPP.
424 #endif
425
426 static short console_col;
427 static short console_row;
428
429 /************************************************************************/
430
431 ulong   lcd_setmem (ulong addr);
432
433 static void     lcd_drawchars  (ushort x, ushort y, uchar *str, int count);
434 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
435 static inline void lcd_putc_xy (ushort x, ushort y, uchar  c);
436
437 int     lcd_init (void *lcdbase);
438
439 static void     lcd_ctrl_init (void *lcdbase);
440 static void     lcd_enable (void);
441 static void    *lcd_logo (void);
442 #if LCD_BPP == LCD_COLOR8
443 static void     lcd_setcolreg (ushort regno,
444                                 ushort red, ushort green, ushort blue);
445 #endif
446 #if LCD_BPP == LCD_MONOCHROME
447 static void     lcd_initcolregs (void);
448 #endif
449 static int      lcd_getbgcolor (void);
450 static void     lcd_setfgcolor (int color);
451 static void     lcd_setbgcolor (int color);
452
453 #if defined(CONFIG_RBC823)
454 void    lcd_disable (void);
455 #endif
456
457 #ifdef  NOT_USED_SO_FAR
458 static void     lcd_getcolreg (ushort regno,
459                                 ushort *red, ushort *green, ushort *blue);
460 static int      lcd_getfgcolor (void);
461 #endif  /* NOT_USED_SO_FAR */
462
463 /************************************************************************/
464
465 /*----------------------------------------------------------------------*/
466
467 static void console_scrollup (void)
468 {
469 #if 1
470         /* Copy up rows ignoring the first one */
471         memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
472
473         /* Clear the last one */
474         memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
475 #else
476         /*
477          * Poor attempt to optimize speed by moving "long"s.
478          * But the code is ugly, and not a bit faster :-(
479          */
480         ulong *t = (ulong *)CONSOLE_ROW_FIRST;
481         ulong *s = (ulong *)CONSOLE_ROW_SECOND;
482         ulong    l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
483         uchar  c = lcd_color_bg & 0xFF;
484         ulong val= (c<<24) | (c<<16) | (c<<8) | c;
485
486         while (l--)
487                 *t++ = *s++;
488
489         t = (ulong *)CONSOLE_ROW_LAST;
490         l = CONSOLE_ROW_SIZE / sizeof(ulong);
491
492         while (l-- > 0)
493                 *t++ = val;
494 #endif
495 }
496
497 /*----------------------------------------------------------------------*/
498
499 static inline void console_back (void)
500 {
501         if (--console_col < 0) {
502                 console_col = CONSOLE_COLS-1 ;
503                 if (--console_row < 0) {
504                         console_row = 0;
505                 }
506         }
507
508         lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
509                      console_row * VIDEO_FONT_HEIGHT,
510                      ' ');
511 }
512
513 /*----------------------------------------------------------------------*/
514
515 static inline void console_newline (void)
516 {
517         ++console_row;
518         console_col = 0;
519
520         /* Check if we need to scroll the terminal */
521         if (console_row >= CONSOLE_ROWS) {
522                 /* Scroll everything up */
523                 console_scrollup () ;
524                 --console_row;
525         }
526 }
527
528 /*----------------------------------------------------------------------*/
529
530 void lcd_putc (const char c)
531 {
532         if (!lcd_is_enabled) {
533                 serial_putc(c);
534                 return;
535         }
536
537         switch (c) {
538         case '\r':      console_col = 0;
539                         return;
540
541         case '\n':      console_newline();
542                         return;
543
544         case '\t':      /* Tab (8 chars alignment) */
545                         console_col |=  8;
546                         console_col &= ~7;
547
548                         if (console_col >= CONSOLE_COLS) {
549                                 console_newline();
550                         }
551                         return;
552
553         case '\b':      console_back();
554                         return;
555
556         default:        lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
557                                      console_row * VIDEO_FONT_HEIGHT,
558                                      c);
559                         if (++console_col >= CONSOLE_COLS) {
560                                 console_newline();
561                         }
562                         return;
563         }
564         /* NOTREACHED */
565 }
566
567 /*----------------------------------------------------------------------*/
568
569 void lcd_puts (const char *s)
570 {
571         if (!lcd_is_enabled) {
572                 serial_puts (s);
573                 return;
574         }
575
576         while (*s) {
577                 lcd_putc (*s++);
578         }
579 }
580
581 /************************************************************************/
582 /* ** Low-Level Graphics Routines                                       */
583 /************************************************************************/
584
585 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
586 {
587         uchar *dest;
588         ushort off, row;
589
590         dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
591         off  = x * (1 << LCD_BPP) % 8;
592
593         for (row=0;  row < VIDEO_FONT_HEIGHT;  ++row, dest += lcd_line_length)  {
594                 uchar *s = str;
595                 uchar *d = dest;
596                 int i;
597
598 #if LCD_BPP == LCD_MONOCHROME
599                 uchar rest = *d & -(1 << (8-off));
600                 uchar sym;
601 #endif
602                 for (i=0; i<count; ++i) {
603                         uchar c, bits;
604
605                         c = *s++;
606                         bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
607
608 #if LCD_BPP == LCD_MONOCHROME
609                         sym  = (COLOR_MASK(lcd_color_fg) & bits) |
610                                (COLOR_MASK(lcd_color_bg) & ~bits);
611
612                         *d++ = rest | (sym >> off);
613                         rest = sym << (8-off);
614 #elif LCD_BPP == LCD_COLOR8
615                         for (c=0; c<8; ++c) {
616                                 *d++ = (bits & 0x80) ?
617                                                 lcd_color_fg : lcd_color_bg;
618                                 bits <<= 1;
619                         }
620 #endif
621                 }
622
623 #if LCD_BPP == LCD_MONOCHROME
624                 *d  = rest | (*d & ((1 << (8-off)) - 1));
625 #endif
626         }
627 }
628
629 /*----------------------------------------------------------------------*/
630
631 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
632 {
633 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
634         lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen (s));
635 #else
636         lcd_drawchars (x, y, s, strlen (s));
637 #endif
638 }
639
640 /*----------------------------------------------------------------------*/
641
642 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
643 {
644 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
645         lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
646 #else
647         lcd_drawchars (x, y, &c, 1);
648 #endif
649 }
650
651 /************************************************************************/
652 /**  Small utility to check that you got the colours right              */
653 /************************************************************************/
654 #ifdef LCD_TEST_PATTERN
655
656 #define N_BLK_VERT      2
657 #define N_BLK_HOR       3
658
659 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
660         CONSOLE_COLOR_RED,      CONSOLE_COLOR_GREEN,    CONSOLE_COLOR_YELLOW,
661         CONSOLE_COLOR_BLUE,     CONSOLE_COLOR_MAGENTA,  CONSOLE_COLOR_CYAN,
662 };
663
664 static void test_pattern (void)
665 {
666         ushort v_max  = panel_info.vl_row;
667         ushort h_max  = panel_info.vl_col;
668         ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
669         ushort h_step = (h_max + N_BLK_HOR  - 1) / N_BLK_HOR;
670         ushort v, h;
671         uchar *pix = (uchar *)lcd_base;
672
673         printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
674                 h_max, v_max, h_step, v_step);
675
676         /* WARNING: Code silently assumes 8bit/pixel */
677         for (v=0; v<v_max; ++v) {
678                 uchar iy = v / v_step;
679                 for (h=0; h<h_max; ++h) {
680                         uchar ix = N_BLK_HOR * iy + (h/h_step);
681                         *pix++ = test_colors[ix];
682                 }
683         }
684 }
685 #endif /* LCD_TEST_PATTERN */
686
687
688 /************************************************************************/
689 /* ** GENERIC Initialization Routines                                   */
690 /************************************************************************/
691
692 int drv_lcd_init (void)
693 {
694         DECLARE_GLOBAL_DATA_PTR;
695
696         device_t lcddev;
697         int rc;
698
699         lcd_base = (void *)(gd->fb_base);
700
701         lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
702
703         lcd_init (lcd_base);            /* LCD initialization */
704
705         /* Device initialization */
706         memset (&lcddev, 0, sizeof (lcddev));
707
708         strcpy (lcddev.name, "lcd");
709         lcddev.ext   = 0;                       /* No extensions */
710         lcddev.flags = DEV_FLAGS_OUTPUT;        /* Output only */
711         lcddev.putc  = lcd_putc;                /* 'putc' function */
712         lcddev.puts  = lcd_puts;                /* 'puts' function */
713
714         rc = device_register (&lcddev);
715
716         return (rc == 0) ? 1 : rc;
717 }
718
719 /*----------------------------------------------------------------------*/
720
721 int lcd_init (void *lcdbase)
722 {
723         /* Initialize the lcd controller */
724         debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
725
726         lcd_ctrl_init (lcdbase);
727
728 #if LCD_BPP == LCD_MONOCHROME
729         /* Setting the palette */
730         lcd_initcolregs();
731
732 #elif LCD_BPP == LCD_COLOR8
733         /* Setting the palette */
734         lcd_setcolreg  (CONSOLE_COLOR_BLACK,       0,    0,    0);
735         lcd_setcolreg  (CONSOLE_COLOR_RED,      0xFF,    0,    0);
736         lcd_setcolreg  (CONSOLE_COLOR_GREEN,       0, 0xFF,    0);
737         lcd_setcolreg  (CONSOLE_COLOR_YELLOW,   0xFF, 0xFF,    0);
738         lcd_setcolreg  (CONSOLE_COLOR_BLUE,        0,    0, 0xFF);
739         lcd_setcolreg  (CONSOLE_COLOR_MAGENTA,  0xFF,    0, 0xFF);
740         lcd_setcolreg  (CONSOLE_COLOR_CYAN,        0, 0xFF, 0xFF);
741         lcd_setcolreg  (CONSOLE_COLOR_GREY,     0xAA, 0xAA, 0xAA);
742         lcd_setcolreg  (CONSOLE_COLOR_WHITE,    0xFF, 0xFF, 0xFF);
743 #endif
744
745 #ifndef CFG_WHITE_ON_BLACK
746         lcd_setfgcolor (CONSOLE_COLOR_BLACK);
747         lcd_setbgcolor (CONSOLE_COLOR_WHITE);
748 #else
749         lcd_setfgcolor (CONSOLE_COLOR_WHITE);
750         lcd_setbgcolor (CONSOLE_COLOR_BLACK);
751 #endif  /* CFG_WHITE_ON_BLACK */
752
753 #ifdef  LCD_TEST_PATTERN
754         test_pattern();
755 #else
756         /* set framebuffer to background color */
757         memset ((char *)lcd_base,
758                 COLOR_MASK(lcd_getbgcolor()),
759                 lcd_line_length*panel_info.vl_row);
760 #endif
761
762         lcd_enable ();
763
764         /* Paint the logo and retrieve LCD base address */
765         debug ("[LCD] Drawing the logo...\n");
766         lcd_console_address = lcd_logo ();
767
768         /* Initialize the console */
769         console_col = 0;
770 #ifdef LCD_INFO_BELOW_LOGO
771         console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
772 #else
773         console_row = 1;        /* leave 1 blank line below logo */
774 #endif
775         lcd_is_enabled = 1;
776
777         return 0;
778 }
779
780
781 /************************************************************************/
782 /* ** ROM capable initialization part - needed to reserve FB memory     */
783 /************************************************************************/
784
785 /*
786  * This is called early in the system initialization to grab memory
787  * for the LCD controller.
788  * Returns new address for monitor, after reserving LCD buffer memory
789  *
790  * Note that this is running from ROM, so no write access to global data.
791  */
792 ulong lcd_setmem (ulong addr)
793 {
794         ulong size;
795         int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
796
797         debug ("LCD panel info: %d x %d, %d bit/pix\n",
798                 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
799
800         size = line_length * panel_info.vl_row;
801
802         /* Round up to nearest full page */
803         size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
804
805         /* Allocate pages for the frame buffer. */
806         addr -= size;
807
808         debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
809
810         return (addr);
811 }
812
813
814 /************************************************************************/
815 /* ----------------- chipset specific functions ----------------------- */
816 /************************************************************************/
817
818 static void lcd_ctrl_init (void *lcdbase)
819 {
820         volatile immap_t *immr = (immap_t *) CFG_IMMR;
821         volatile lcd823_t *lcdp = &immr->im_lcd;
822
823         uint lccrtmp;
824         uint lchcr_hpc_tmp;
825
826         /* Initialize the LCD control register according to the LCD
827          * parameters defined.  We do everything here but enable
828          * the controller.
829          */
830
831         lccrtmp  = LCDBIT (LCCR_BNUM_BIT,
832                    (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
833
834         lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp)   |
835                    LCDBIT (LCCR_OEP_BIT,  panel_info.vl_oep)    |
836                    LCDBIT (LCCR_HSP_BIT,  panel_info.vl_hsp)    |
837                    LCDBIT (LCCR_VSP_BIT,  panel_info.vl_vsp)    |
838                    LCDBIT (LCCR_DP_BIT,   panel_info.vl_dp)     |
839                    LCDBIT (LCCR_BPIX_BIT, panel_info.vl_bpix)   |
840                    LCDBIT (LCCR_LBW_BIT,  panel_info.vl_lbw)    |
841                    LCDBIT (LCCR_SPLT_BIT, panel_info.vl_splt)   |
842                    LCDBIT (LCCR_CLOR_BIT, panel_info.vl_clor)   |
843                    LCDBIT (LCCR_TFT_BIT,  panel_info.vl_tft);
844
845 #if 0
846         lccrtmp |= ((SIU_LEVEL5 / 2) << 12);
847         lccrtmp |= LCCR_EIEN;
848 #endif
849
850         lcdp->lcd_lccr = lccrtmp;
851         lcdp->lcd_lcsr = 0xFF;          /* Clear pending interrupts */
852
853         /* Initialize LCD controller bus priorities.
854          */
855 #ifdef CONFIG_RBC823
856         immr->im_siu_conf.sc_sdcr = (immr->im_siu_conf.sc_sdcr & ~0x0f) | 1;    /* RAID = 01, LAID = 00 */
857 #else
858         immr->im_siu_conf.sc_sdcr &= ~0x0f;     /* RAID = LAID = 0 */
859
860         /* set SHFT/CLOCK division factor 4
861          * This needs to be set based upon display type and processor
862          * speed.  The TFT displays run about 20 to 30 MHz.
863          * I was running 64 MHz processor speed.
864          * The value for this divider must be chosen so the result is
865          * an integer of the processor speed (i.e., divide by 3 with
866          * 64 MHz would be bad).
867          */
868         immr->im_clkrst.car_sccr &= ~0x1F;
869         immr->im_clkrst.car_sccr |= LCD_DF;     /* was 8 */
870
871 #endif /* CONFIG_RBC823 */
872
873 #if defined(CONFIG_RBC823)
874         /* Enable LCD on port D.
875          */
876         immr->im_ioport.iop_pddat &= 0x0300;
877         immr->im_ioport.iop_pdpar |= 0x1CFF;
878         immr->im_ioport.iop_pddir |= 0x1CFF;
879
880         /* Configure LCD_ON, VEE_ON, CCFL_ON on port B.
881          */
882         immr->im_cpm.cp_pbdat &= ~0x00005001;
883         immr->im_cpm.cp_pbpar &= ~0x00005001;
884         immr->im_cpm.cp_pbdir |=  0x00005001;
885 #elif !defined(CONFIG_EDT32F10)
886         /* Enable LCD on port D.
887          */
888         immr->im_ioport.iop_pdpar |= 0x1FFF;
889         immr->im_ioport.iop_pddir |= 0x1FFF;
890
891         /* Enable LCD_A/B/C on port B.
892          */
893         immr->im_cpm.cp_pbpar |= 0x00005001;
894         immr->im_cpm.cp_pbdir |= 0x00005001;
895 #else
896         /* Enable LCD on port D.
897          */
898         immr->im_ioport.iop_pdpar |= 0x1DFF;
899         immr->im_ioport.iop_pdpar &= ~0x0200;
900         immr->im_ioport.iop_pddir |= 0x1FFF;
901         immr->im_ioport.iop_pddat |= 0x0200;
902 #endif
903
904         /* Load the physical address of the linear frame buffer
905          * into the LCD controller.
906          * BIG NOTE:  This has to be modified to load A and B depending
907          * upon the split mode of the LCD.
908          */
909         lcdp->lcd_lcfaa = (ulong)lcd_base;
910         lcdp->lcd_lcfba = (ulong)lcd_base;
911
912         /* MORE HACKS...This must be updated according to 823 manual
913          * for different panels.
914          * Udi Finkelstein - done - see below:
915          * Note: You better not try unsupported combinations such as
916          * 4-bit wide passive dual scan LCD at 4/8 Bit color.
917          */
918         lchcr_hpc_tmp =
919                 (panel_info.vl_col *
920                  (panel_info.vl_tft ? 8 :
921                         (((2 - panel_info.vl_lbw) << /* 4 bit=2, 8-bit = 1 */
922                          /* use << to mult by: single scan = 1, dual scan = 2 */
923                           panel_info.vl_splt) *
924                          (panel_info.vl_bpix | 1)))) >> 3; /* 2/4 BPP = 1, 8/16 BPP = 3 */
925
926         lcdp->lcd_lchcr = LCHCR_BO |
927                           LCDBIT (LCHCR_AT_BIT, 4) |
928                           LCDBIT (LCHCR_HPC_BIT, lchcr_hpc_tmp) |
929                           panel_info.vl_wbl;
930
931         lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
932                           LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
933                           LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
934                           panel_info.vl_wbf;
935
936 }
937
938 /*----------------------------------------------------------------------*/
939
940 #ifdef  NOT_USED_SO_FAR
941 static void
942 lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
943 {
944         volatile immap_t *immr = (immap_t *) CFG_IMMR;
945         volatile cpm8xx_t *cp = &(immr->im_cpm);
946         unsigned short colreg, *cmap_ptr;
947
948         cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
949
950         colreg = *cmap_ptr;
951 #ifdef  CFG_INVERT_COLORS
952         colreg ^= 0x0FFF;
953 #endif
954
955         *red   = (colreg >> 8) & 0x0F;
956         *green = (colreg >> 4) & 0x0F;
957         *blue  =  colreg       & 0x0F;
958 }
959 #endif  /* NOT_USED_SO_FAR */
960
961 /*----------------------------------------------------------------------*/
962
963 #if LCD_BPP == LCD_COLOR8
964 static void
965 lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
966 {
967         volatile immap_t *immr = (immap_t *) CFG_IMMR;
968         volatile cpm8xx_t *cp = &(immr->im_cpm);
969         unsigned short colreg, *cmap_ptr;
970
971         cmap_ptr = (unsigned short *)&cp->lcd_cmap[regno * 2];
972
973         colreg = ((red   & 0x0F) << 8) |
974                  ((green & 0x0F) << 4) |
975                   (blue  & 0x0F) ;
976 #ifdef  CFG_INVERT_COLORS
977         colreg ^= 0x0FFF;
978 #endif
979         *cmap_ptr = colreg;
980
981         debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",
982                 regno, &(cp->lcd_cmap[regno * 2]),
983                 red, green, blue,
984                 cp->lcd_cmap[ regno * 2 ], cp->lcd_cmap[(regno * 2) + 1]);
985 }
986 #endif  /* LCD_COLOR8 */
987
988 /*----------------------------------------------------------------------*/
989
990 #if LCD_BPP == LCD_MONOCHROME
991 static
992 void lcd_initcolregs (void)
993 {
994         volatile immap_t *immr = (immap_t *) CFG_IMMR;
995         volatile cpm8xx_t *cp = &(immr->im_cpm);
996         ushort regno;
997
998         for (regno = 0; regno < 16; regno++) {
999                 cp->lcd_cmap[regno * 2] = 0;
1000                 cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
1001         }
1002 }
1003 #endif
1004
1005 /*----------------------------------------------------------------------*/
1006
1007 static void lcd_setfgcolor (int color)
1008 {
1009         lcd_color_fg = color & 0x0F;
1010 }
1011
1012 /*----------------------------------------------------------------------*/
1013
1014 static void lcd_setbgcolor (int color)
1015 {
1016         lcd_color_bg = color & 0x0F;
1017 }
1018
1019 /*----------------------------------------------------------------------*/
1020
1021 #ifdef  NOT_USED_SO_FAR
1022 static int lcd_getfgcolor (void)
1023 {
1024         return lcd_color_fg;
1025 }
1026 #endif  /* NOT_USED_SO_FAR */
1027
1028 /*----------------------------------------------------------------------*/
1029
1030 static int lcd_getbgcolor (void)
1031 {
1032         return lcd_color_bg;
1033 }
1034
1035 /*----------------------------------------------------------------------*/
1036
1037 static void lcd_enable (void)
1038 {
1039         volatile immap_t *immr = (immap_t *) CFG_IMMR;
1040         volatile lcd823_t *lcdp = &immr->im_lcd;
1041
1042         /* Enable the LCD panel */
1043 #ifndef CONFIG_RBC823
1044         immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25));          /* LAM = 1 */
1045 #endif
1046         lcdp->lcd_lccr |= LCCR_PON;
1047
1048 #ifdef CONFIG_V37
1049         /* Turn on display backlight */
1050         immr->im_cpm.cp_pbpar |= 0x00008000;
1051         immr->im_cpm.cp_pbdir |= 0x00008000;
1052 #elif defined(CONFIG_RBC823)
1053         /* Turn on display backlight */
1054         immr->im_cpm.cp_pbdat |= 0x00004000;
1055 #endif
1056
1057 #if defined(CONFIG_LWMON)
1058     {   uchar c = pic_read (0x60);
1059 #if defined(CONFIG_LCD) && defined(CONFIG_LWMON) && (CONFIG_POST & CFG_POST_SYSMON)
1060         c |= 0x04;      /* Chip Enable LCD */
1061 #else
1062         c |= 0x07;      /* Power on CCFL, Enable CCFL, Chip Enable LCD */
1063 #endif
1064         pic_write (0x60, c);
1065     }
1066 #endif /* CONFIG_LWMON */
1067
1068 #if defined(CONFIG_R360MPI)
1069     {
1070         extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1071         unsigned long bgi, ctr;
1072         char *p;
1073
1074         if ((p = getenv("lcdbgi")) != NULL) {
1075                 bgi = simple_strtoul (p, 0, 10) & 0xFFF;
1076         } else {
1077                 bgi = 0xFFF;
1078         }
1079
1080         if ((p = getenv("lcdctr")) != NULL) {
1081                 ctr = simple_strtoul (p, 0, 10) & 0xFFF;
1082         } else {
1083                 ctr=0x7FF;
1084         }
1085
1086         r360_i2c_lcd_write(0x10, 0x01);
1087         r360_i2c_lcd_write(0x20, 0x01);
1088         r360_i2c_lcd_write(0x30 | ((bgi>>8) & 0xF), bgi & 0xFF);
1089         r360_i2c_lcd_write(0x40 | ((ctr>>8) & 0xF), ctr & 0xFF);
1090     }
1091 #endif /* CONFIG_R360MPI */
1092 #ifdef CONFIG_RBC823
1093         udelay(200000); /* wait 200ms */
1094         /* Turn VEE_ON first */
1095         immr->im_cpm.cp_pbdat |= 0x00000001;
1096         udelay(200000); /* wait 200ms */
1097         /* Now turn on LCD_ON */
1098         immr->im_cpm.cp_pbdat |= 0x00001000;
1099 #endif
1100 #ifdef CONFIG_RRVISION
1101         debug ("PC4->Output(1): enable LVDS\n");
1102         debug ("PC5->Output(0): disable PAL clock\n");
1103         immr->im_ioport.iop_pddir |=  0x1000;
1104         immr->im_ioport.iop_pcpar &= ~(0x0C00);
1105         immr->im_ioport.iop_pcdir |=   0x0C00 ;
1106         immr->im_ioport.iop_pcdat |=   0x0800 ;
1107         immr->im_ioport.iop_pcdat &= ~(0x0400);
1108         debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
1109                immr->im_ioport.iop_pdpar,
1110                immr->im_ioport.iop_pddir,
1111                immr->im_ioport.iop_pddat);
1112         debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
1113                immr->im_ioport.iop_pcpar,
1114                immr->im_ioport.iop_pcdir,
1115                immr->im_ioport.iop_pcdat);
1116 #endif
1117 }
1118
1119 /*----------------------------------------------------------------------*/
1120
1121 #if defined (CONFIG_RBC823)
1122 void lcd_disable (void)
1123 {
1124         volatile immap_t *immr = (immap_t *) CFG_IMMR;
1125         volatile lcd823_t *lcdp = &immr->im_lcd;
1126
1127 #if defined(CONFIG_LWMON)
1128     {   uchar c = pic_read (0x60);
1129         c &= ~0x07;     /* Power off CCFL, Disable CCFL, Chip Disable LCD */
1130         pic_write (0x60, c);
1131     }
1132 #elif defined(CONFIG_R360MPI)
1133     {
1134         extern void r360_i2c_lcd_write (uchar data0, uchar data1);
1135
1136         r360_i2c_lcd_write(0x10, 0x00);
1137         r360_i2c_lcd_write(0x20, 0x00);
1138         r360_i2c_lcd_write(0x30, 0x00);
1139         r360_i2c_lcd_write(0x40, 0x00);
1140     }
1141 #endif /* CONFIG_LWMON */
1142         /* Disable the LCD panel */
1143         lcdp->lcd_lccr &= ~LCCR_PON;
1144 #ifdef CONFIG_RBC823
1145         /* Turn off display backlight, VEE and LCD_ON */
1146         immr->im_cpm.cp_pbdat &= ~0x00005001;
1147 #else
1148         immr->im_siu_conf.sc_sdcr &= ~(1 << (31 - 25)); /* LAM = 0 */
1149 #endif /* CONFIG_RBC823 */
1150 }
1151 #endif  /* NOT_USED_SO_FAR || CONFIG_RBC823 */
1152
1153
1154 /************************************************************************/
1155 /* ** Chipset depending Bitmap / Logo stuff...                          */
1156 /************************************************************************/
1157
1158
1159 #ifdef CONFIG_LCD_LOGO
1160 static void bitmap_plot (int x, int y)
1161 {
1162         volatile immap_t *immr = (immap_t *) CFG_IMMR;
1163         volatile cpm8xx_t *cp = &(immr->im_cpm);
1164         ushort *cmap;
1165         ushort i;
1166         uchar *bmap;
1167         uchar *fb;
1168
1169         debug ("Logo: width %d  height %d  colors %d  cmap %d\n",
1170                 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
1171                 sizeof(bmp_logo_palette)/(sizeof(ushort))
1172         );
1173
1174         /* Leave room for default color map */
1175         cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
1176
1177         WATCHDOG_RESET();
1178
1179         /* Set color map */
1180         for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
1181                 ushort colreg = bmp_logo_palette[i];
1182 #ifdef  CFG_INVERT_COLORS
1183                 colreg ^= 0xFFF;
1184 #endif
1185                 *cmap++ = colreg;
1186         }
1187
1188         bmap = &bmp_logo_bitmap[0];
1189         fb   = (char *)(lcd_base + y * lcd_line_length + x);
1190
1191         WATCHDOG_RESET();
1192
1193         for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
1194                 memcpy (fb, bmap, BMP_LOGO_WIDTH);
1195                 bmap += BMP_LOGO_WIDTH;
1196                 fb   += panel_info.vl_col;
1197         }
1198
1199         WATCHDOG_RESET();
1200 }
1201 #endif /* CONFIG_LCD_LOGO */
1202
1203 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1204 /*
1205  * Display the BMP file located at address bmp_image.
1206  * Only uncompressed
1207  */
1208 int lcd_display_bitmap(ulong bmp_image)
1209 {
1210         volatile immap_t *immr = (immap_t *) CFG_IMMR;
1211         volatile cpm8xx_t *cp = &(immr->im_cpm);
1212         ushort *cmap;
1213         ushort i, j;
1214         uchar *fb;
1215         bmp_image_t *bmp=(bmp_image_t *)bmp_image;
1216         uchar *bmap;
1217         ushort padded_line;
1218         unsigned long width, height;
1219         unsigned colors,bpix;
1220         unsigned long compression;
1221
1222         WATCHDOG_RESET();
1223
1224         if (!((bmp->header.signature[0]=='B') &&
1225               (bmp->header.signature[1]=='M'))) {
1226                 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1227                 return 1;
1228         }
1229
1230         width = le32_to_cpu (bmp->header.width);
1231         height = le32_to_cpu (bmp->header.height);
1232         colors = 1<<le16_to_cpu (bmp->header.bit_count);
1233         compression = le32_to_cpu (bmp->header.compression);
1234
1235         bpix = NBITS(panel_info.vl_bpix);
1236
1237         if ((bpix != 1) && (bpix != 8)) {
1238                 printf ("Error: %d bit/pixel mode not supported by U-Boot\n",
1239                         bpix);
1240                 return 1;
1241         }
1242
1243         if (bpix != le16_to_cpu(bmp->header.bit_count)) {
1244                 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
1245                         bpix,
1246                         le16_to_cpu(bmp->header.bit_count));
1247                 return 1;
1248         }
1249
1250         if (compression!=BMP_BI_RGB) {
1251                 printf ("Error: compression type %ld not supported\n",
1252                         compression);
1253                 return 1;
1254         }
1255
1256         debug ("Display-bmp: %d x %d  with %d colors\n",
1257                width, height, colors);
1258
1259         if (bpix==8) {
1260                 /* Fill the entire color map */
1261                 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
1262
1263                 /* Set color map */
1264                 for (i = 0; i < colors; ++i) {
1265                         bmp_color_table_entry_t cte = bmp->color_table[i];
1266                         ushort colreg =
1267                                 ((cte.red>>4)   << 8) |
1268                                 ((cte.green>>4) << 4) |
1269                                 (cte.blue>>4) ;
1270 #ifdef  CFG_INVERT_COLORS
1271                         colreg ^= 0xFFF;
1272 #endif
1273                         *cmap-- = colreg;
1274                 }
1275
1276                 WATCHDOG_RESET();
1277         }
1278
1279         padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
1280         if (width>panel_info.vl_col)
1281                 width = panel_info.vl_col;
1282         if (height>panel_info.vl_row)
1283                 height = panel_info.vl_row;
1284
1285         bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
1286         fb   = (uchar *)
1287                 (lcd_base +
1288                  (((height>=panel_info.vl_row) ? panel_info.vl_row : height)-1)
1289                  * lcd_line_length);
1290         for (i = 0; i < height; ++i) {
1291                 WATCHDOG_RESET();
1292                 for (j = 0; j < width ; j++)
1293                         *(fb++)=255-*(bmap++);
1294                 bmap += (width - padded_line);
1295                 fb   -= (width + lcd_line_length);
1296         }
1297
1298         return (0);
1299 }
1300 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
1301
1302 /*----------------------------------------------------------------------*/
1303
1304 static void *lcd_logo (void)
1305 {
1306 #ifdef LCD_INFO
1307         DECLARE_GLOBAL_DATA_PTR;
1308
1309         char info[80];
1310         char temp[32];
1311 #endif /* LCD_INFO */
1312
1313 #ifdef CONFIG_SPLASH_SCREEN
1314         char *s;
1315         ulong addr;
1316
1317         if ((s = getenv("splashimage")) != NULL) {
1318                 addr = simple_strtoul(s, NULL, 16);
1319
1320                 if (lcd_display_bitmap (addr) == 0) {
1321                         return ((void *)lcd_base);
1322                 }
1323         }
1324 #endif  /* CONFIG_SPLASH_SCREEN */
1325
1326 #ifdef CONFIG_LCD_LOGO
1327         bitmap_plot (0, 0);
1328 #endif /* CONFIG_LCD_LOGO */
1329
1330
1331 #ifdef LCD_INFO
1332         sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1333         lcd_drawchars (LCD_INFO_X, LCD_INFO_Y, info, strlen(info));
1334
1335         sprintf (info, "(C) 2003 DENX Software Engineering");
1336         lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT,
1337                                         info, strlen(info));
1338
1339         sprintf (info, "    Wolfgang DENK, wd@denx.de");
1340         lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1341                                         info, strlen(info));
1342 #ifdef LCD_INFO_BELOW_LOGO
1343         sprintf (info, "MPC823 CPU at %s MHz",
1344                 strmhz(temp, gd->cpu_clk));
1345         lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 3,
1346                                         info, strlen(info));
1347         sprintf (info, "  %ld MB RAM, %ld MB Flash",
1348                 gd->ram_size >> 20,
1349                 gd->bd->bi_flashsize >> 20 );
1350         lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1351                                         info, strlen(info));
1352 #else
1353         /* leave one blank line */
1354
1355         sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1356                 strmhz(temp, gd->cpu_clk),
1357                 gd->ram_size >> 20,
1358                 gd->bd->bi_flashsize >> 20 );
1359         lcd_drawchars (LCD_INFO_X, LCD_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1360                                         info, strlen(info));
1361 #endif /* LCD_INFO_BELOW_LOGO */
1362 #endif /* LCD_INFO */
1363
1364 #if defined(CONFIG_LCD_LOGO) && !defined(LCD_INFO_BELOW_LOGO)
1365         return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
1366 #else
1367         return ((void *)lcd_base);
1368 #endif  /* CONFIG_LCD_LOGO */
1369 }
1370
1371 /************************************************************************/
1372 /************************************************************************/
1373
1374 #endif /* CONFIG_LCD */