fs: fat: remove build warnings
[profile/mobile/platform/kernel/u-boot-tm1.git] / common / lcd.c
1 /*
2  * Common LCD routines for supported CPUs
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
31 #include <config.h>
32 #include <common.h>
33 #include <command.h>
34 #include <stdarg.h>
35 #include <linux/types.h>
36 #include <stdio_dev.h>
37 #if defined(CONFIG_POST)
38 #include <post.h>
39 #endif
40 #include <lcd.h>
41 #include <watchdog.h>
42
43 #if defined CONFIG_PXA250 || defined CONFIG_PXA27X || defined CONFIG_CPU_MONAHANS
44 #include <asm/byteorder.h>
45 #endif
46
47 #if defined(CONFIG_MPC823)
48 #include <lcdvideo.h>
49 #endif
50
51 #if defined(CONFIG_ATMEL_LCD)
52 #include <atmel_lcdc.h>
53 #endif
54
55 /************************************************************************/
56 /* ** FONT DATA                                                         */
57 /************************************************************************/
58 #include <video_font.h>         /* Get font data, width and height      */
59
60 /************************************************************************/
61 /* ** LOGO DATA                                                         */
62 /************************************************************************/
63 #ifdef CONFIG_LCD_LOGO
64 #include <bmp_logo.h>
65 #include <sp_bmp_logo.h>
66 #include <thor_bmp_logo.h>
67 #include <charge_bmp_logo.h>
68 #include <prog_start_logo.h>
69 #include <prog_mid_logo.h>
70 #include <prog_end_logo.h>
71 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
72 #  error Default Color Map overlaps with Logo Color Map
73 # endif
74 #endif
75
76 #ifdef CONFIG_TIZEN
77 #include "../property/tizen_misc.h"
78 #endif
79
80 DECLARE_GLOBAL_DATA_PTR;
81
82 ulong lcd_setmem (ulong addr);
83
84 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count);
85 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s);
86 static inline void lcd_putc_xy (ushort x, ushort y, uchar  c);
87
88 static int lcd_init (void *lcdbase);
89
90 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]);
91 static void *lcd_logo (void);
92
93 static int lcd_getbgcolor (void);
94 void lcd_setfgcolor (int color);
95 static void lcd_setbgcolor (int color);
96
97 extern void lcd_display(void);
98
99 char lcd_is_enabled = 0;
100
101 #ifdef  NOT_USED_SO_FAR
102 static void lcd_getcolreg (ushort regno,
103                                 ushort *red, ushort *green, ushort *blue);
104 static int lcd_getfgcolor (void);
105 #endif  /* NOT_USED_SO_FAR */
106
107 /************************************************************************/
108
109 /*----------------------------------------------------------------------*/
110
111 static void console_scrollup (void)
112 {
113         /* Copy up rows ignoring the first one */
114         memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
115
116         /* Clear the last one */
117         memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
118 }
119
120 /*----------------------------------------------------------------------*/
121
122 static inline void console_back (void)
123 {
124         if (--console_col < 0) {
125                 console_col = CONSOLE_COLS-1 ;
126                 if (--console_row < 0) {
127                         console_row = 0;
128                 }
129         }
130
131         lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
132                      console_row * VIDEO_FONT_HEIGHT,
133                      ' ');
134 }
135
136 /*----------------------------------------------------------------------*/
137
138 static inline void console_newline (void)
139 {
140         ++console_row;
141         console_col = 0;
142
143         /* Check if we need to scroll the terminal */
144         if (console_row >= CONSOLE_ROWS) {
145                 /* Scroll everything up */
146                 console_scrollup () ;
147                 --console_row;
148         }
149 }
150
151 /*----------------------------------------------------------------------*/
152
153 void lcd_putc (const char c)
154 {
155         if (!lcd_is_enabled) {
156                 serial_putc(c);
157                 return;
158         }
159
160         switch (c) {
161         case '\r':      console_col = 0;
162                         return;
163
164         case '\n':      console_newline();
165                         return;
166
167         case '\t':      /* Tab (8 chars alignment) */
168                         console_col +=  8;
169                         console_col &= ~7;
170
171                         if (console_col >= CONSOLE_COLS) {
172                                 console_newline();
173                         }
174                         return;
175
176         case '\b':      console_back();
177                         return;
178
179         default:        lcd_putc_xy (console_col * VIDEO_FONT_WIDTH,
180                                      console_row * VIDEO_FONT_HEIGHT,
181                                      c);
182                         if (++console_col >= CONSOLE_COLS) {
183                                 console_newline();
184                         }
185                         return;
186         }
187         /* NOTREACHED */
188 }
189
190 /*----------------------------------------------------------------------*/
191
192 void lcd_puts (const char *s)
193 {
194         if (!lcd_is_enabled) {
195                 serial_puts (s);
196                 return;
197         }
198
199         while (*s) {
200                 lcd_putc (*s++);
201         }
202 }
203
204 /*----------------------------------------------------------------------*/
205
206 void lcd_printf(const char *fmt, ...)
207 {
208         va_list args;
209         char buf[CONFIG_SYS_PBSIZE];
210
211         va_start(args, fmt);
212         vsprintf(buf, fmt, args);
213         va_end(args);
214
215         lcd_puts(buf);
216 }
217
218 /************************************************************************/
219 /* ** Low-Level Graphics Routines                                       */
220 /************************************************************************/
221
222 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
223 {
224         uchar *dest;
225         ushort row;
226
227 #if LCD_BPP == LCD_MONOCHROME
228         ushort off  = x * (1 << LCD_BPP) % 8;
229 #endif
230
231         dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
232
233         for (row=0;  row < VIDEO_FONT_HEIGHT;  ++row, dest += lcd_line_length)  {
234                 uchar *s = str;
235                 int i;
236 #if LCD_BPP == LCD_COLOR16
237                 ushort *d = (ushort *)dest;
238 #else
239                 uchar *d = dest;
240 #endif
241
242 #if LCD_BPP == LCD_MONOCHROME
243                 uchar rest = *d & -(1 << (8-off));
244                 uchar sym;
245 #endif
246                 for (i=0; i<count; ++i) {
247                         uchar c, bits;
248
249                         c = *s++;
250                         bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
251
252 #if LCD_BPP == LCD_MONOCHROME
253                         sym  = (COLOR_MASK(lcd_color_fg) & bits) |
254                                (COLOR_MASK(lcd_color_bg) & ~bits);
255
256                         *d++ = rest | (sym >> off);
257                         rest = sym << (8-off);
258 #elif LCD_BPP == LCD_COLOR8
259                         for (c=0; c<8; ++c) {
260                                 *d++ = (bits & 0x80) ?
261                                                 lcd_color_fg : lcd_color_bg;
262                                 bits <<= 1;
263                         }
264 #elif LCD_BPP == LCD_COLOR16
265                         for (c=0; c<8; ++c) {
266                                 *d++ = (bits & 0x80) ?
267                                                 lcd_color_fg : lcd_color_bg;
268                                 bits <<= 1;
269                         }
270 #endif
271                 }
272 #if LCD_BPP == LCD_MONOCHROME
273                 *d  = rest | (*d & ((1 << (8-off)) - 1));
274 #endif
275         }
276 }
277
278 /*----------------------------------------------------------------------*/
279
280 static inline void lcd_puts_xy (ushort x, ushort y, uchar *s)
281 {
282 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) && !defined(CONFIG_TIZEN)
283         lcd_drawchars (x, y+BMP_LOGO_HEIGHT, s, strlen ((char *)s));
284 #else
285         lcd_drawchars (x, y, s, strlen ((char *)s));
286 #endif
287 }
288
289 /*----------------------------------------------------------------------*/
290
291 static inline void lcd_putc_xy (ushort x, ushort y, uchar c)
292 {
293 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) && !defined(CONFIG_TIZEN)
294         lcd_drawchars (x, y+BMP_LOGO_HEIGHT, &c, 1);
295 #else
296         lcd_drawchars (x, y, &c, 1);
297 #endif
298 }
299
300 /************************************************************************/
301 /**  Small utility to check that you got the colours right              */
302 /************************************************************************/
303 #ifdef LCD_TEST_PATTERN
304
305 #define N_BLK_VERT      2
306 #define N_BLK_HOR       3
307
308 static int test_colors[N_BLK_HOR*N_BLK_VERT] = {
309         CONSOLE_COLOR_RED,      CONSOLE_COLOR_GREEN,    CONSOLE_COLOR_YELLOW,
310         CONSOLE_COLOR_BLUE,     CONSOLE_COLOR_MAGENTA,  CONSOLE_COLOR_CYAN,
311 };
312
313 static void test_pattern (void)
314 {
315         ushort v_max  = panel_info.vl_row;
316         ushort h_max  = panel_info.vl_col;
317         ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
318         ushort h_step = (h_max + N_BLK_HOR  - 1) / N_BLK_HOR;
319         ushort v, h;
320         uchar *pix = (uchar *)lcd_base;
321
322         printf ("[LCD] Test Pattern: %d x %d [%d x %d]\n",
323                 h_max, v_max, h_step, v_step);
324
325         /* WARNING: Code silently assumes 8bit/pixel */
326         for (v=0; v<v_max; ++v) {
327                 uchar iy = v / v_step;
328                 for (h=0; h<h_max; ++h) {
329                         uchar ix = N_BLK_HOR * iy + (h/h_step);
330                         *pix++ = test_colors[ix];
331                 }
332         }
333 }
334 #endif /* LCD_TEST_PATTERN */
335
336
337 /************************************************************************/
338 /* ** GENERIC Initialization Routines                                   */
339 /************************************************************************/
340
341 int drv_lcd_init (void)
342 {
343         struct stdio_dev lcddev;
344         int rc = 0;
345
346         lcd_base = (void *)(gd->fb_base);
347
348         lcd_line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
349
350         lcd_init (lcd_base);            /* LCD initialization */
351
352         /* Device initialization */
353         memset (&lcddev, 0, sizeof (lcddev));
354
355         strcpy (lcddev.name, "lcd");
356         lcddev.ext   = 0;                       /* No extensions */
357         lcddev.flags = DEV_FLAGS_OUTPUT;        /* Output only */
358         lcddev.putc  = lcd_putc;                /* 'putc' function */
359         lcddev.puts  = lcd_puts;                /* 'puts' function */
360
361         rc = stdio_register (&lcddev);
362
363         return (rc == 0) ? 1 : rc;
364 }
365
366 /*----------------------------------------------------------------------*/
367 static int lcd_clear (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
368 {
369 #if LCD_BPP == LCD_MONOCHROME
370         /* Setting the palette */
371         lcd_initcolregs();
372
373 #elif LCD_BPP == LCD_COLOR8
374         /* Setting the palette */
375         lcd_setcolreg  (CONSOLE_COLOR_BLACK,       0,    0,    0);
376         lcd_setcolreg  (CONSOLE_COLOR_RED,      0xFF,    0,    0);
377         lcd_setcolreg  (CONSOLE_COLOR_GREEN,       0, 0xFF,    0);
378         lcd_setcolreg  (CONSOLE_COLOR_YELLOW,   0xFF, 0xFF,    0);
379         lcd_setcolreg  (CONSOLE_COLOR_BLUE,        0,    0, 0xFF);
380         lcd_setcolreg  (CONSOLE_COLOR_MAGENTA,  0xFF,    0, 0xFF);
381         lcd_setcolreg  (CONSOLE_COLOR_CYAN,        0, 0xFF, 0xFF);
382         lcd_setcolreg  (CONSOLE_COLOR_GREY,     0xAA, 0xAA, 0xAA);
383         lcd_setcolreg  (CONSOLE_COLOR_WHITE,    0xFF, 0xFF, 0xFF);
384 #endif
385
386 #ifndef CONFIG_SYS_WHITE_ON_BLACK
387         lcd_setfgcolor (CONSOLE_COLOR_BLACK);
388         lcd_setbgcolor (CONSOLE_COLOR_WHITE);
389 #else
390         //lcd_setfgcolor (CONSOLE_COLOR_WHITE);
391 #define CONSOLE_COLOR_RED (0x1f<<11)
392         lcd_setfgcolor (CONSOLE_COLOR_RED);
393         lcd_setbgcolor (CONSOLE_COLOR_BLACK);
394 #endif  /* CONFIG_SYS_WHITE_ON_BLACK */
395
396 #ifdef  LCD_TEST_PATTERN
397         test_pattern();
398 #else
399         /* set framebuffer to background color */
400         memset ((char *)lcd_base,
401                 COLOR_MASK(lcd_getbgcolor()),
402                 lcd_line_length*panel_info.vl_row);
403 #endif
404         /* Paint the logo and retrieve LCD base address */
405         debug ("[LCD] Drawing the logo...\n");
406         lcd_console_address = lcd_logo ();
407
408         console_col = 0;
409         console_row = 0;
410
411         return (0);
412 }
413
414 U_BOOT_CMD(
415         cls,    1,      1,      lcd_clear,
416         "clear screen",
417         ""
418 );
419
420 /*----------------------------------------------------------------------*/
421
422 static int lcd_init (void *lcdbase)
423 {
424         /* Initialize the lcd controller */
425         debug ("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
426
427         lcd_ctrl_init (lcdbase);
428         lcd_is_enabled = 1;
429         lcd_clear (NULL, 1, 1, NULL);   /* dummy args */
430         lcd_enable ();
431
432         /* Initialize the console */
433         console_col = 0;
434 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
435         console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
436 #else
437         console_row = 1;        /* leave 1 blank line below logo */
438 #endif
439
440         return 0;
441 }
442
443
444 /************************************************************************/
445 /* ** ROM capable initialization part - needed to reserve FB memory     */
446 /************************************************************************/
447 /*
448  * This is called early in the system initialization to grab memory
449  * for the LCD controller.
450  * Returns new address for monitor, after reserving LCD buffer memory
451  *
452  * Note that this is running from ROM, so no write access to global data.
453  */
454 ulong lcd_setmem (ulong addr)
455 {
456         ulong size;
457         int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
458
459         debug ("LCD panel info: %d x %d, %d bit/pix\n",
460                 panel_info.vl_col, panel_info.vl_row, NBITS (panel_info.vl_bpix) );
461
462         size = line_length * panel_info.vl_row;
463
464         /* Round up to nearest full page */
465         size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
466
467         /* Allocate pages for the frame buffer. */
468         addr -= size;
469
470         debug ("Reserving %ldk for LCD Framebuffer at: %08lx\n", size>>10, addr);
471
472         return (addr);
473 }
474
475 /*----------------------------------------------------------------------*/
476
477 void lcd_setfgcolor (int color)
478 {
479         lcd_color_fg = color;
480 }
481
482 /*----------------------------------------------------------------------*/
483
484 static void lcd_setbgcolor (int color)
485 {
486         lcd_color_bg = color;
487 }
488
489 /*----------------------------------------------------------------------*/
490
491 #ifdef  NOT_USED_SO_FAR
492 static int lcd_getfgcolor (void)
493 {
494         return lcd_color_fg;
495 }
496 #endif  /* NOT_USED_SO_FAR */
497
498 /*----------------------------------------------------------------------*/
499
500 static int lcd_getbgcolor (void)
501 {
502         return lcd_color_bg;
503 }
504
505 /*----------------------------------------------------------------------*/
506
507 /************************************************************************/
508 /* ** Chipset depending Bitmap / Logo stuff...                          */
509 /************************************************************************/
510 #ifdef CONFIG_LCD_LOGO
511 void _draw_image(int x, int y, int width, int height, unsigned short *palette, unsigned short *bitmap,
512                 unsigned int *num_bitmap, unsigned int num_elem, int clear) {
513         unsigned long i, j, k, num_pre_pixels, num_post_pixels;
514         u16 col16;
515         ushort *fb16;
516
517         fb16 = (ushort *)(lcd_base);
518
519         num_pre_pixels = x + y * panel_info.vl_col;
520         num_post_pixels = (panel_info.vl_row * panel_info.vl_col) - (width * height);
521
522
523         if (clear)
524                 memset(fb16, 0x0, num_pre_pixels * 2);
525         fb16 += num_pre_pixels;
526
527         i = 0;
528         k = 0;
529         for (i = 0; i < num_elem; i++) {
530                 col16 = palette[bitmap[i]];
531                 for (j = 0; j < num_bitmap[i]; j++) {
532                         if (((k % width) == 0) && (k != 0)) {
533                                 fb16 += panel_info.vl_col;
534                                 if (clear)
535                                         memset(fb16, 0x0, panel_info.vl_col * 2);
536                         }
537                         fb16[k % width] =
538                                 (u16)(((col16 & 0xF) << 1) |
539                                                 ((col16 & 0x0F0) << 3) |
540                                                 ((col16 & 0xF00) << 4));
541                         k++;
542                 }
543         }
544
545         if (clear)
546                 memset(fb16, 0x0, num_post_pixels * 2);
547 }
548
549 void draw_image(int mode) {
550         switch(mode) {
551                 case 0: /* splash */
552                         _draw_image(103, 530, sp_width, sp_height, sp_palette, sp_bitmap, sp_num_bitmap, sp_num_elem, 1);
553                         break;
554                 case 1: /* thor */
555                         _draw_image(171, 360, thor_width, thor_height, thor_palette, thor_bitmap, thor_num_bitmap, thor_num_elem, 1);
556                         break;
557                 case 2: /* charge */
558                         _draw_image(270, 440, charge_width, charge_height, charge_palette, charge_bitmap, charge_num_bitmap, charge_num_elem, 1);
559                         break;
560         }
561 }
562
563 #define DRAW_HEIGHT     925
564 #define DRAW_STEP       57
565 static int last_non_drawn = -1;
566
567 void draw_progress(int per) {
568         int idx = (per * DRAW_STEP) / 100;
569         int tmp;
570
571         if (idx < 2) {
572                 _draw_image(180, DRAW_HEIGHT, prog_start_width, prog_start_height, prog_start_palette, prog_start_bitmap, prog_start_num_bitmap, prog_start_num_elem, 0);
573         } else if(idx < DRAW_STEP) {
574                 if (last_non_drawn == -1) {
575                         _draw_image(180, DRAW_HEIGHT, prog_start_width, prog_start_height, prog_start_palette, prog_start_bitmap, prog_start_num_bitmap, prog_start_num_elem, 0);
576                         last_non_drawn = 0;
577                 }
578                 tmp = last_non_drawn;
579                 while (tmp < idx) {
580                         _draw_image(180 + 17 + (tmp - 1) * 6, DRAW_HEIGHT, prog_mid_width, prog_mid_height, prog_mid_palette, prog_mid_bitmap, prog_mid_num_bitmap, prog_mid_num_elem, 0);
581                         tmp++;
582                 }
583                 if (last_non_drawn < idx)
584                         last_non_drawn = idx;
585         } else {
586                 if (idx == DRAW_STEP)
587                         _draw_image(180, DRAW_HEIGHT, prog_start_width, prog_start_height, prog_start_palette, prog_start_bitmap, prog_start_num_bitmap, prog_start_num_elem, 0);
588                 tmp = last_non_drawn;
589                 while (tmp < idx) {
590                         _draw_image(180 + 17 + (tmp - 1) * 6, DRAW_HEIGHT, prog_mid_width, prog_mid_height, prog_mid_palette, prog_mid_bitmap, prog_mid_num_bitmap, prog_mid_num_elem, 0);
591                         tmp++;
592                 }
593
594                 _draw_image(180 + 17 + (DRAW_STEP - 2) * 6, DRAW_HEIGHT, prog_end_width, prog_end_height, prog_end_palette, prog_end_bitmap, prog_end_num_bitmap, prog_end_num_elem, 0);
595
596                 if (last_non_drawn < idx)
597                         last_non_drawn = idx;
598         }
599 }
600
601 void bitmap_plot (int x, int y, int mode)
602 {
603 #ifdef CONFIG_ATMEL_LCD
604         uint *cmap;
605 #else
606         ushort *cmap;
607 #endif
608         ushort i;
609         uchar *bmap;
610         uchar *fb;
611 #if defined CONFIG_PXA250 || defined CONFIG_PXA27X || defined CONFIG_CPU_MONAHANS
612         struct pxafb_info *fbi = &panel_info.pxa;
613 #elif defined(CONFIG_MPC823)
614         volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
615         volatile cpm8xx_t *cp = &(immr->im_cpm);
616 #endif
617
618         debug ("Logo: width %d  height %d  colors %d  cmap %d\n",
619                 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
620                 (int)(sizeof(bmp_logo_palette)/(sizeof(ushort))));
621
622         bmap = &bmp_logo_bitmap[0];
623         fb   = (uchar *)(lcd_base + y * lcd_line_length + x);
624
625         if (NBITS(panel_info.vl_bpix) < 12) {
626                 /* Leave room for default color map */
627 #if defined CONFIG_PXA250 || defined CONFIG_PXA27X || defined CONFIG_CPU_MONAHANS
628                 cmap = (ushort *)fbi->palette;
629 #elif defined(CONFIG_MPC823)
630                 cmap = (ushort *)&(cp->lcd_cmap[BMP_LOGO_OFFSET*sizeof(ushort)]);
631 #elif defined(CONFIG_ATMEL_LCD)
632                 cmap = (uint *) (panel_info.mmio + ATMEL_LCDC_LUT(0));
633 #else
634                 /*
635                  * default case: generic system with no cmap (most likely 16bpp)
636                  * We set cmap to the source palette, so no change is done.
637                  * This avoids even more ifdef in the next stanza
638                  */
639                 cmap = bmp_logo_palette;
640 #endif
641
642                 WATCHDOG_RESET();
643
644                 /* Set color map */
645                 for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
646                         ushort colreg = bmp_logo_palette[i];
647 #ifdef CONFIG_ATMEL_LCD
648                         uint lut_entry;
649 #ifdef CONFIG_ATMEL_LCD_BGR555
650                         lut_entry = ((colreg & 0x000F) << 11) |
651                                     ((colreg & 0x00F0) <<  2) |
652                                     ((colreg & 0x0F00) >>  7);
653 #else /* CONFIG_ATMEL_LCD_RGB565 */
654                         lut_entry = ((colreg & 0x000F) << 1) |
655                                     ((colreg & 0x00F0) << 3) |
656                                     ((colreg & 0x0F00) << 4);
657 #endif
658                         *(cmap + BMP_LOGO_OFFSET) = lut_entry;
659                         cmap++;
660 #else /* !CONFIG_ATMEL_LCD */
661 #ifdef  CONFIG_SYS_INVERT_COLORS
662                         *cmap++ = 0xffff - colreg;
663 #else
664                         *cmap++ = colreg;
665 #endif
666 #endif /* CONFIG_ATMEL_LCD */
667                 }
668
669                 WATCHDOG_RESET();
670
671                 for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
672                         memcpy (fb, bmap, BMP_LOGO_WIDTH);
673                         bmap += BMP_LOGO_WIDTH;
674                         fb   += panel_info.vl_col;
675                 }
676         }
677         else { /* true color mode */
678                 draw_image(mode);
679                 lcd_display();
680         }
681
682         WATCHDOG_RESET();
683 }
684 #endif /* CONFIG_LCD_LOGO */
685
686 /*----------------------------------------------------------------------*/
687 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
688 /*
689  * Display the BMP file located at address bmp_image.
690  * Only uncompressed.
691  */
692
693 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
694 #define BMP_ALIGN_CENTER        0x7FFF
695 #endif
696
697 int lcd_display_bitmap(ulong bmp_image, int x, int y)
698 {
699 #if !defined(CONFIG_MCC200)
700         ushort *cmap = NULL;
701 #endif
702         ushort *cmap_base = NULL;
703         ushort i, j;
704         uchar *fb;
705         bmp_image_t *bmp=(bmp_image_t *)bmp_image;
706         uchar *bmap;
707         ushort padded_line;
708         unsigned long width, height, byte_width;
709         unsigned long pwidth = panel_info.vl_col;
710         unsigned colors, bpix, bmp_bpix;
711 #if defined CONFIG_PXA250 || defined CONFIG_PXA27X || defined CONFIG_CPU_MONAHANS
712         struct pxafb_info *fbi = &panel_info.pxa;
713 #elif defined(CONFIG_MPC823)
714         volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
715         volatile cpm8xx_t *cp = &(immr->im_cpm);
716 #endif
717
718         if (!((bmp->header.signature[0]=='B') &&
719                 (bmp->header.signature[1]=='M'))) {
720                 printf ("Error: no valid bmp image at %lx\n", bmp_image);
721                 return 1;
722         }
723
724         width = le32_to_cpu (bmp->header.width);
725         height = le32_to_cpu (bmp->header.height);
726         bmp_bpix = le16_to_cpu(bmp->header.bit_count);
727         colors = 1 << bmp_bpix;
728
729         bpix = NBITS(panel_info.vl_bpix);
730
731         if ((bpix != 1) && (bpix != 8) && (bpix != 16)) {
732                 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
733                         bpix, bmp_bpix);
734                 return 1;
735         }
736
737         /* We support displaying 8bpp BMPs on 16bpp LCDs */
738         if (bpix != bmp_bpix && (bmp_bpix != 8 || bpix != 16)) {
739                 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
740                         bpix,
741                         le16_to_cpu(bmp->header.bit_count));
742                 return 1;
743         }
744
745         debug ("Display-bmp: %d x %d  with %d colors\n",
746                 (int)width, (int)height, (int)colors);
747
748 #if !defined(CONFIG_MCC200)
749         /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
750         if (bmp_bpix == 8) {
751 #if defined CONFIG_PXA250 || defined CONFIG_PXA27X || defined CONFIG_CPU_MONAHANS
752                 cmap = (ushort *)fbi->palette;
753 #elif defined(CONFIG_MPC823)
754                 cmap = (ushort *)&(cp->lcd_cmap[255*sizeof(ushort)]);
755 #elif !defined(CONFIG_ATMEL_LCD)
756                 cmap = panel_info.cmap;
757 #endif
758
759                 cmap_base = cmap;
760
761                 /* Set color map */
762                 for (i=0; i<colors; ++i) {
763                         bmp_color_table_entry_t cte = bmp->color_table[i];
764 #if !defined(CONFIG_ATMEL_LCD)
765                         ushort colreg =
766                                 ( ((cte.red)   << 8) & 0xf800) |
767                                 ( ((cte.green) << 3) & 0x07e0) |
768                                 ( ((cte.blue)  >> 3) & 0x001f) ;
769 #ifdef CONFIG_SYS_INVERT_COLORS
770                         *cmap = 0xffff - colreg;
771 #else
772                         *cmap = colreg;
773 #endif
774 #if defined(CONFIG_MPC823)
775                         cmap--;
776 #else
777                         cmap++;
778 #endif
779 #else /* CONFIG_ATMEL_LCD */
780                         lcd_setcolreg(i, cte.red, cte.green, cte.blue);
781 #endif
782                 }
783         }
784 #endif
785
786         /*
787          *  BMP format for Monochrome assumes that the state of a
788          * pixel is described on a per Bit basis, not per Byte.
789          *  So, in case of Monochrome BMP we should align widths
790          * on a byte boundary and convert them from Bit to Byte
791          * units.
792          *  Probably, PXA250 and MPC823 process 1bpp BMP images in
793          * their own ways, so make the converting to be MCC200
794          * specific.
795          */
796 #if defined(CONFIG_MCC200)
797         if (bpix==1)
798         {
799                 width = ((width + 7) & ~7) >> 3;
800                 x     = ((x + 7) & ~7) >> 3;
801                 pwidth= ((pwidth + 7) & ~7) >> 3;
802         }
803 #endif
804
805         padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
806
807 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
808         if (x == BMP_ALIGN_CENTER)
809                 x = max(0, (pwidth - width) / 2);
810         else if (x < 0)
811                 x = max(0, pwidth - width + x + 1);
812
813         if (y == BMP_ALIGN_CENTER)
814                 y = max(0, (panel_info.vl_row - height) / 2);
815         else if (y < 0)
816                 y = max(0, panel_info.vl_row - height + y + 1);
817 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
818
819         if ((x + width)>pwidth)
820                 width = pwidth - x;
821         if ((y + height)>panel_info.vl_row)
822                 height = panel_info.vl_row - y;
823
824         bmap = (uchar *)bmp + le32_to_cpu (bmp->header.data_offset);
825         fb   = (uchar *) (lcd_base +
826                 (y + height - 1) * lcd_line_length + x);
827
828         switch (bmp_bpix) {
829         case 1: /* pass through */
830         case 8:
831                 if (bpix != 16)
832                         byte_width = width;
833                 else
834                         byte_width = width * 2;
835
836                 for (i = 0; i < height; ++i) {
837                         WATCHDOG_RESET();
838                         for (j = 0; j < width; j++) {
839                                 if (bpix != 16) {
840 #if defined CONFIG_PXA250 || defined CONFIG_PXA27X || defined CONFIG_CPU_MONAHANS || defined(CONFIG_ATMEL_LCD)
841                                         *(fb++) = *(bmap++);
842 #elif defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
843                                         *(fb++) = 255 - *(bmap++);
844 #endif
845                                 } else {
846                                         *(uint16_t *)fb = cmap_base[*(bmap++)];
847                                         fb += sizeof(uint16_t) / sizeof(*fb);
848                                 }
849                         }
850                         bmap += (width - padded_line);
851                         fb   -= (byte_width + lcd_line_length);
852                 }
853                 break;
854
855 #if defined(CONFIG_BMP_16BPP)
856         case 16:
857                 for (i = 0; i < height; ++i) {
858                         WATCHDOG_RESET();
859                         for (j = 0; j < width; j++) {
860 #if defined(CONFIG_ATMEL_LCD_BGR555)
861                                 *(fb++) = ((bmap[0] & 0x1f) << 2) |
862                                         (bmap[1] & 0x03);
863                                 *(fb++) = (bmap[0] & 0xe0) |
864                                         ((bmap[1] & 0x7c) >> 2);
865                                 bmap += 2;
866 #else
867                                 *(fb++) = *(bmap++);
868                                 *(fb++) = *(bmap++);
869 #endif
870                         }
871                         bmap += (padded_line - width) * 2;
872                         fb   -= (width * 2 + lcd_line_length);
873                 }
874                 break;
875 #endif /* CONFIG_BMP_16BPP */
876
877         default:
878                 break;
879         };
880
881         return (0);
882 }
883 #endif
884
885 static void *lcd_logo (void)
886 {
887 #ifdef CONFIG_SPLASH_SCREEN
888         char *s;
889         ulong addr;
890         static int do_splash = 1;
891
892         if (do_splash && (s = getenv("splashimage")) != NULL) {
893                 int x = 0, y = 0;
894                 do_splash = 0;
895
896                 addr = simple_strtoul (s, NULL, 16);
897 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
898                 if ((s = getenv ("splashpos")) != NULL) {
899                         if (s[0] == 'm')
900                                 x = BMP_ALIGN_CENTER;
901                         else
902                                 x = simple_strtol (s, NULL, 0);
903
904                         if ((s = strchr (s + 1, ',')) != NULL) {
905                                 if (s[1] == 'm')
906                                         y = BMP_ALIGN_CENTER;
907                                 else
908                                         y = simple_strtol (s + 1, NULL, 0);
909                         }
910                 }
911 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
912
913 #ifdef CONFIG_VIDEO_BMP_GZIP
914                 bmp_image_t *bmp = (bmp_image_t *)addr;
915                 unsigned long len;
916
917                 if (!((bmp->header.signature[0]=='B') &&
918                       (bmp->header.signature[1]=='M'))) {
919                         addr = (ulong)gunzip_bmp(addr, &len);
920                 }
921 #endif
922
923                 if (lcd_display_bitmap (addr, x, y) == 0) {
924                         return ((void *)lcd_base);
925                 }
926         }
927 #endif /* CONFIG_SPLASH_SCREEN */
928
929 #ifdef CONFIG_LCD_INFO
930         console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
931         console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
932         lcd_show_board_info();
933 #endif /* CONFIG_LCD_INFO */
934
935 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) && !defined(CONFIG_TIZEN)
936         return ((void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length));
937 #else
938         return ((void *)lcd_base);
939 #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
940 }
941
942 void lcd_set_cur_pos(short row, short col)
943 {
944         console_row = row;
945         console_col = col;
946 }
947 /************************************************************************/
948 /************************************************************************/