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