]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/lcd.c
lcd: dt: extract simplefb support
[karo-tx-uboot.git] / common / lcd.c
1 /*
2  * Common LCD routines
3  *
4  * (C) Copyright 2001-2002
5  * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 /* #define DEBUG */
11 #include <config.h>
12 #include <common.h>
13 #include <command.h>
14 #include <env_callback.h>
15 #include <linux/types.h>
16 #include <stdio_dev.h>
17 #include <lcd.h>
18 #include <watchdog.h>
19 #include <asm/unaligned.h>
20 #include <splash.h>
21 #include <asm/io.h>
22 #include <asm/unaligned.h>
23 #include <video_font.h>
24
25 #ifdef CONFIG_LCD_LOGO
26 #include <bmp_logo.h>
27 #include <bmp_logo_data.h>
28 #if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
29 #error Default Color Map overlaps with Logo Color Map
30 #endif
31 #endif
32
33 #ifdef CONFIG_SANDBOX
34 #include <asm/sdl.h>
35 #endif
36
37 #ifndef CONFIG_LCD_ALIGNMENT
38 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
39 #endif
40
41 #if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \
42         (LCD_BPP != LCD_COLOR32)
43 #error Unsupported LCD BPP.
44 #endif
45
46 DECLARE_GLOBAL_DATA_PTR;
47
48 static int lcd_init(void *lcdbase);
49 static void *lcd_logo(void);
50 static void lcd_setfgcolor(int color);
51 static void lcd_setbgcolor(int color);
52
53 static int lcd_color_fg;
54 static int lcd_color_bg;
55 int lcd_line_length;
56 char lcd_is_enabled = 0;
57 static void *lcd_base;                  /* Start of framebuffer memory  */
58 static char lcd_flush_dcache;   /* 1 to flush dcache after each lcd update */
59
60 /* Flush LCD activity to the caches */
61 void lcd_sync(void)
62 {
63         /*
64          * flush_dcache_range() is declared in common.h but it seems that some
65          * architectures do not actually implement it. Is there a way to find
66          * out whether it exists? For now, ARM is safe.
67          */
68 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
69         int line_length;
70
71         if (lcd_flush_dcache)
72                 flush_dcache_range((u32)lcd_base,
73                         (u32)(lcd_base + lcd_get_size(&line_length)));
74 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
75         static ulong last_sync;
76
77         if (get_timer(last_sync) > 10) {
78                 sandbox_sdl_sync(lcd_base);
79                 last_sync = get_timer(0);
80         }
81 #endif
82 }
83
84 void lcd_set_flush_dcache(int flush)
85 {
86         lcd_flush_dcache = (flush != 0);
87 }
88
89 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
90 {
91         lcd_putc(c);
92 }
93
94 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
95 {
96         lcd_puts(s);
97 }
98
99 /* Small utility to check that you got the colours right */
100 #ifdef LCD_TEST_PATTERN
101
102 #define N_BLK_VERT      2
103 #define N_BLK_HOR       3
104
105 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
106         CONSOLE_COLOR_RED,      CONSOLE_COLOR_GREEN,    CONSOLE_COLOR_YELLOW,
107         CONSOLE_COLOR_BLUE,     CONSOLE_COLOR_MAGENTA,  CONSOLE_COLOR_CYAN,
108 };
109
110 #if LCD_BPP == LCD_COLOR8
111 typedef uchar pix_t;
112 #elif LCD_BPP == LCD_COLOR16
113 typedef ushort pix_t;
114 #elif LCD_BPP == LCD_COLOR32
115 typedef ulong pix_t;
116 #else
117 #error Unsupported pixelformat
118 #endif
119
120 static void test_pattern(void)
121 {
122         ushort v_max  = panel_info.vl_row;
123         ushort h_max  = panel_info.vl_col;
124         ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
125         ushort h_step = (h_max + N_BLK_HOR  - 1) / N_BLK_HOR;
126         ushort v, h;
127         pix_t *pix = lcd_base;
128
129         printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
130                 h_max, v_max, h_step, v_step);
131
132         /* WARNING: Code silently assumes 8bit/pixel */
133         for (v = 0; v < v_max; ++v) {
134                 uchar iy = v / v_step;
135                 for (h = 0; h < h_max; ++h) {
136                         uchar ix = N_BLK_HOR * iy + h / h_step;
137                         *pix++ = test_colors[ix];
138                 }
139         }
140 }
141 #endif /* LCD_TEST_PATTERN */
142
143 /*
144  * With most lcd drivers the line length is set up
145  * by calculating it from panel_info parameters. Some
146  * drivers need to calculate the line length differently,
147  * so make the function weak to allow overriding it.
148  */
149 __weak int lcd_get_size(int *line_length)
150 {
151         *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
152         return *line_length * panel_info.vl_row;
153 }
154
155 int drv_lcd_init(void)
156 {
157         struct stdio_dev lcddev;
158         int rc;
159
160         lcd_base = map_sysmem(gd->fb_base, 0);
161
162         lcd_init(lcd_base);
163
164         /* Device initialization */
165         memset(&lcddev, 0, sizeof(lcddev));
166
167         strcpy(lcddev.name, "lcd");
168         lcddev.ext   = 0;                       /* No extensions */
169         lcddev.flags = DEV_FLAGS_OUTPUT;        /* Output only */
170         lcddev.putc  = lcd_stub_putc;           /* 'putc' function */
171         lcddev.puts  = lcd_stub_puts;           /* 'puts' function */
172
173         rc = stdio_register(&lcddev);
174
175         return (rc == 0) ? 1 : rc;
176 }
177
178 void lcd_clear(void)
179 {
180         short console_rows, console_cols;
181         int bg_color;
182 #if LCD_BPP == LCD_COLOR8
183         /* Setting the palette */
184         lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
185         lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
186         lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
187         lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
188         lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
189         lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
190         lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
191         lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
192         lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
193 #endif
194
195 #ifndef CONFIG_SYS_WHITE_ON_BLACK
196         lcd_setfgcolor(CONSOLE_COLOR_BLACK);
197         lcd_setbgcolor(CONSOLE_COLOR_WHITE);
198         bg_color = CONSOLE_COLOR_WHITE;
199 #else
200         lcd_setfgcolor(CONSOLE_COLOR_WHITE);
201         lcd_setbgcolor(CONSOLE_COLOR_BLACK);
202         bg_color = CONSOLE_COLOR_BLACK;
203 #endif  /* CONFIG_SYS_WHITE_ON_BLACK */
204
205 #ifdef  LCD_TEST_PATTERN
206         test_pattern();
207 #else
208         /* set framebuffer to background color */
209 #if (LCD_BPP != LCD_COLOR32)
210         memset((char *)lcd_base, bg_color, lcd_line_length * panel_info.vl_row);
211 #else
212         u32 *ppix = lcd_base;
213         u32 i;
214         for (i = 0;
215            i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
216            i++) {
217                 *ppix++ = bg_color;
218         }
219 #endif
220 #endif
221         /* Paint the logo and retrieve LCD base address */
222         debug("[LCD] Drawing the logo @ %p...\n", lcd_base);
223 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
224         console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT);
225         console_rows /= VIDEO_FONT_HEIGHT;
226 #else
227         console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT;
228 #endif
229         console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH;
230         lcd_init_console(lcd_base, console_rows, console_cols);
231         lcd_init_console(lcd_logo(), console_rows, console_cols);
232         lcd_sync();
233 }
234
235 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
236                         char *const argv[])
237 {
238         lcd_clear();
239         return 0;
240 }
241 U_BOOT_CMD(cls, 1, 1, do_lcd_clear, "clear screen", "");
242
243 static int lcd_init(void *lcdbase)
244 {
245         debug("[LCD] Initializing %ux%ux%u LCD framebuffer at %p\n",
246                 panel_info.vl_col, panel_info.vl_row, NBITS(panel_info.vl_bpix),
247                 lcdbase);
248
249         lcd_ctrl_init(lcdbase);
250
251         /*
252          * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
253          * the 'lcdbase' argument and uses custom lcd base address
254          * by setting up gd->fb_base. Check for this condition and fixup
255          * 'lcd_base' address.
256          */
257         if (map_to_sysmem(lcdbase) != gd->fb_base)
258                 lcd_base = map_sysmem(gd->fb_base, 0);
259
260         debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
261
262         lcd_get_size(&lcd_line_length);
263         lcd_is_enabled = 1;
264         lcd_clear();
265         lcd_enable();
266
267         /* Initialize the console */
268         lcd_set_col(0);
269 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
270         lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
271 #else
272         lcd_set_row(1); /* leave 1 blank line below logo */
273 #endif
274
275         return 0;
276 }
277
278 /*
279  * This is called early in the system initialization to grab memory
280  * for the LCD controller.
281  * Returns new address for monitor, after reserving LCD buffer memory
282  *
283  * Note that this is running from ROM, so no write access to global data.
284  */
285 ulong lcd_setmem(ulong addr)
286 {
287         ulong size;
288         int line_length;
289
290         debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
291                 panel_info.vl_row, NBITS(panel_info.vl_bpix));
292
293         size = lcd_get_size(&line_length);
294
295         /* Round up to nearest full page, or MMU section if defined */
296         size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
297         addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
298
299         /* Allocate pages for the frame buffer. */
300         addr -= size;
301
302         debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
303               size >> 10, addr);
304
305         return addr;
306 }
307
308 static void lcd_setfgcolor(int color)
309 {
310         lcd_color_fg = color;
311 }
312
313 int lcd_getfgcolor(void)
314 {
315         return lcd_color_fg;
316 }
317
318 static void lcd_setbgcolor(int color)
319 {
320         lcd_color_bg = color;
321 }
322
323 int lcd_getbgcolor(void)
324 {
325         return lcd_color_bg;
326 }
327
328 #ifdef CONFIG_LCD_LOGO
329 __weak void lcd_logo_set_cmap(void)
330 {
331         int i;
332         ushort *cmap = configuration_get_cmap();
333
334         for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i)
335                 *cmap++ = bmp_logo_palette[i];
336 }
337
338 void lcd_logo_plot(int x, int y)
339 {
340         ushort i, j;
341         uchar *bmap = &bmp_logo_bitmap[0];
342         unsigned bpix = NBITS(panel_info.vl_bpix);
343         uchar *fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
344         ushort *fb16;
345
346         debug("Logo: width %d  height %d  colors %d\n",
347               BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS);
348
349         if (bpix < 12) {
350                 WATCHDOG_RESET();
351                 lcd_logo_set_cmap();
352                 WATCHDOG_RESET();
353
354                 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
355                         memcpy(fb, bmap, BMP_LOGO_WIDTH);
356                         bmap += BMP_LOGO_WIDTH;
357                         fb += panel_info.vl_col;
358                 }
359         } else if (NBITS(panel_info.vl_bpix) == 16) {
360                 u16 col16;
361                 fb16 = (ushort *)fb;
362                 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
363                         for (j = 0; j < BMP_LOGO_WIDTH; j++) {
364                                 col16 = bmp_logo_palette[(bmap[j]-16)];
365                                 fb16[j] =
366                                         ((col16 & 0x000F) << 1) |
367                                         ((col16 & 0x00F0) << 3) |
368                                         ((col16 & 0x0F00) << 4);
369                                 }
370                         bmap += BMP_LOGO_WIDTH;
371                         fb16 += panel_info.vl_col;
372                 }
373         } else { /* true color mode */
374                 u16 col16;
375                 u32 *fb32 = lcd_base + y * lcd_line_length + x;
376
377                 for (i = 0; i < BMP_LOGO_HEIGHT; i++) {
378                         for (j = 0; j < BMP_LOGO_WIDTH; j++) {
379                                 col16 = bmp_logo_palette[bmap[j] - 16];
380                                 fb32[j] =
381                                         ((col16 & 0x000F) << 4) |
382                                         ((col16 & 0x00F0) << 8) |
383                                         ((col16 & 0x0F00) << 12);
384                                 }
385                         bmap += BMP_LOGO_WIDTH;
386                         fb32 += panel_info.vl_col;
387                 }
388         }
389
390         WATCHDOG_RESET();
391         lcd_sync();
392 }
393 #else
394 static inline void lcd_logo_plot(int x, int y) {}
395 #endif /* CONFIG_LCD_LOGO */
396
397 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
398 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
399 #define BMP_ALIGN_CENTER        0x7FFF
400
401 static void splash_align_axis(int *axis, unsigned long panel_size,
402                                         unsigned long picture_size)
403 {
404         unsigned long panel_picture_delta = panel_size - picture_size;
405         unsigned long axis_alignment;
406
407         if (*axis == BMP_ALIGN_CENTER)
408                 axis_alignment = panel_picture_delta / 2;
409         else if (*axis < 0)
410                 axis_alignment = panel_picture_delta + *axis + 1;
411         else
412                 return;
413
414         *axis = max(0, (int)axis_alignment);
415 }
416 #endif
417
418 #ifdef CONFIG_LCD_BMP_RLE8
419 #define BMP_RLE8_ESCAPE         0
420 #define BMP_RLE8_EOL            0
421 #define BMP_RLE8_EOBMP          1
422 #define BMP_RLE8_DELTA          2
423
424 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
425                                   int cnt)
426 {
427         while (cnt > 0) {
428                 *(*fbp)++ = cmap[*bmap++];
429                 cnt--;
430         }
431 }
432
433 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
434 {
435         ushort *fb = *fbp;
436         int cnt_8copy = cnt >> 3;
437
438         cnt -= cnt_8copy << 3;
439         while (cnt_8copy > 0) {
440                 *fb++ = c;
441                 *fb++ = c;
442                 *fb++ = c;
443                 *fb++ = c;
444                 *fb++ = c;
445                 *fb++ = c;
446                 *fb++ = c;
447                 *fb++ = c;
448                 cnt_8copy--;
449         }
450         while (cnt > 0) {
451                 *fb++ = c;
452                 cnt--;
453         }
454         *fbp = fb;
455 }
456
457 /*
458  * Do not call this function directly, must be called from lcd_display_bitmap.
459  */
460 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
461                                     int x_off, int y_off)
462 {
463         uchar *bmap;
464         ulong width, height;
465         ulong cnt, runlen;
466         int x, y;
467         int decode = 1;
468
469         width = get_unaligned_le32(&bmp->header.width);
470         height = get_unaligned_le32(&bmp->header.height);
471         bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
472
473         x = 0;
474         y = height - 1;
475
476         while (decode) {
477                 if (bmap[0] == BMP_RLE8_ESCAPE) {
478                         switch (bmap[1]) {
479                         case BMP_RLE8_EOL:
480                                 /* end of line */
481                                 bmap += 2;
482                                 x = 0;
483                                 y--;
484                                 /* 16bpix, 2-byte per pixel, width should *2 */
485                                 fb -= (width * 2 + lcd_line_length);
486                                 break;
487                         case BMP_RLE8_EOBMP:
488                                 /* end of bitmap */
489                                 decode = 0;
490                                 break;
491                         case BMP_RLE8_DELTA:
492                                 /* delta run */
493                                 x += bmap[2];
494                                 y -= bmap[3];
495                                 /* 16bpix, 2-byte per pixel, x should *2 */
496                                 fb = (uchar *) (lcd_base + (y + y_off - 1)
497                                         * lcd_line_length + (x + x_off) * 2);
498                                 bmap += 4;
499                                 break;
500                         default:
501                                 /* unencoded run */
502                                 runlen = bmap[1];
503                                 bmap += 2;
504                                 if (y < height) {
505                                         if (x < width) {
506                                                 if (x + runlen > width)
507                                                         cnt = width - x;
508                                                 else
509                                                         cnt = runlen;
510                                                 draw_unencoded_bitmap(
511                                                         (ushort **)&fb,
512                                                         bmap, cmap, cnt);
513                                         }
514                                         x += runlen;
515                                 }
516                                 bmap += runlen;
517                                 if (runlen & 1)
518                                         bmap++;
519                         }
520                 } else {
521                         /* encoded run */
522                         if (y < height) {
523                                 runlen = bmap[0];
524                                 if (x < width) {
525                                         /* aggregate the same code */
526                                         while (bmap[0] == 0xff &&
527                                                bmap[2] != BMP_RLE8_ESCAPE &&
528                                                bmap[1] == bmap[3]) {
529                                                 runlen += bmap[2];
530                                                 bmap += 2;
531                                         }
532                                         if (x + runlen > width)
533                                                 cnt = width - x;
534                                         else
535                                                 cnt = runlen;
536                                         draw_encoded_bitmap((ushort **)&fb,
537                                                 cmap[bmap[1]], cnt);
538                                 }
539                                 x += runlen;
540                         }
541                         bmap += 2;
542                 }
543         }
544 }
545 #endif
546
547 __weak void fb_put_byte(uchar **fb, uchar **from)
548 {
549         *(*fb)++ = *(*from)++;
550 }
551
552 #if defined(CONFIG_BMP_16BPP)
553 __weak void fb_put_word(uchar **fb, uchar **from)
554 {
555         *(*fb)++ = *(*from)++;
556         *(*fb)++ = *(*from)++;
557 }
558 #endif /* CONFIG_BMP_16BPP */
559
560 __weak void lcd_set_cmap(bmp_image_t *bmp, unsigned colors)
561 {
562         int i;
563         bmp_color_table_entry_t cte;
564         ushort *cmap = configuration_get_cmap();
565
566         for (i = 0; i < colors; ++i) {
567                 cte = bmp->color_table[i];
568                 *cmap = (((cte.red)   << 8) & 0xf800) |
569                         (((cte.green) << 3) & 0x07e0) |
570                         (((cte.blue)  >> 3) & 0x001f);
571 #if defined(CONFIG_MPC823)
572                 cmap--;
573 #else
574                 cmap++;
575 #endif
576         }
577 }
578
579 int lcd_display_bitmap(ulong bmp_image, int x, int y)
580 {
581         ushort *cmap_base = NULL;
582         ushort i, j;
583         uchar *fb;
584         bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
585         uchar *bmap;
586         ushort padded_width;
587         unsigned long width, height;
588         unsigned long pwidth = panel_info.vl_col;
589         unsigned long long colors;
590         unsigned bpix, bmp_bpix;
591         bmp_color_table_entry_t *cte;
592
593         if (!bmp || !(bmp->header.signature[0] == 'B' &&
594                 bmp->header.signature[1] == 'M')) {
595                 printf("Error: no valid bmp image at %lx\n", bmp_image);
596
597                 return 1;
598         }
599
600         width = get_unaligned_le32(&bmp->header.width);
601         height = get_unaligned_le32(&bmp->header.height);
602         bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
603
604         colors = 1 << bmp_bpix;
605
606         bpix = NBITS(panel_info.vl_bpix);
607
608         if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
609                 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
610                         bpix, bmp_bpix);
611
612                 return 1;
613         }
614
615         /*
616          * We support displaying 8bpp BMPs on 16bpp LCDs
617          * and displaying 24bpp BMPs on 32bpp LCDs
618          * */
619         if (bpix != bmp_bpix &&
620             !(bmp_bpix == 8 && bpix == 16) &&
621             !(bmp_bpix == 24 && bpix == 32)) {
622                 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
623                         bpix, get_unaligned_le16(&bmp->header.bit_count));
624                 return 1;
625         }
626
627         debug("Display-bmp: %lu x %lu  with %llu colors\n",
628                 width, height, colors);
629
630         if (bmp_bpix == 8)
631                 lcd_set_cmap(bmp, colors);
632
633         padded_width = ALIGN(width, 4);
634
635 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
636         splash_align_axis(&x, pwidth, width);
637         splash_align_axis(&y, panel_info.vl_row, height);
638 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
639         bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
640
641         if ((x + width) > pwidth)
642                 width = pwidth - x;
643         if ((y + height) > panel_info.vl_row) {
644                 height = panel_info.vl_row - y;
645                 bmap += (panel_info.vl_row - y) * padded_width;
646         }
647
648         fb   = (uchar *)(lcd_base +
649                 (y + height - 1) * lcd_line_length + x * bpix / 8);
650
651         switch (bmp_bpix) {
652         case 1:
653         case 8: {
654                 cmap_base = configuration_get_cmap();
655 #ifdef CONFIG_LCD_BMP_RLE8
656                 u32 compression = get_unaligned_le32(&bmp->header.compression);
657                 if (compression == BMP_BI_RLE8) {
658                         if (bpix != 16) {
659                                 /* TODO implement render code for bpix != 16 */
660                                 printf("Error: only support 16 bpix");
661                                 return 1;
662                         }
663                         lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
664                         break;
665                 }
666 #endif
667
668                 for (i = 0; i < height; ++i) {
669                         WATCHDOG_RESET();
670                         for (j = 0; j < width; j++) {
671                                 if (bpix == 32) {
672                                         int i = *bmap++;
673
674                                         fb[3] = 0; /* T */
675                                         fb[0] = cte[i].blue;
676                                         fb[1] = cte[i].green;
677                                         fb[2] = cte[i].red;
678                                         fb += sizeof(uint32_t) / sizeof(*fb);
679                                 } else if (bpix == 16) {
680                                         *(uint16_t *)fb = cmap_base[*(bmap++)];
681                                         fb += sizeof(uint16_t) / sizeof(*fb);
682                                 } else {
683                                         FB_PUT_BYTE(fb, bmap);
684                                 }
685                         }
686                         if (bpix > 8) {
687                                 bmap += padded_width - width;
688                                 fb   -= width * bpix / 8 + lcd_line_length;
689                         } else {
690                                 bmap += padded_width;
691                                 fb -= lcd_line_length;
692                         }
693                 }
694                 break;
695         }
696 #if defined(CONFIG_BMP_16BPP)
697         case 16:
698                 for (i = 0; i < height; ++i) {
699                         WATCHDOG_RESET();
700                         for (j = 0; j < width; j++)
701                                 fb_put_word(&fb, &bmap);
702
703                         bmap += (padded_width - width) * 2;
704                         fb -= width * 2 + lcd_line_length;
705                 }
706                 break;
707 #endif /* CONFIG_BMP_16BPP */
708 #if defined(CONFIG_BMP_24BMP)
709         case 24:
710                 for (i = 0; i < height; ++i) {
711                         for (j = 0; j < width; j++) {
712                                 *(fb++) = *(bmap++);
713                                 *(fb++) = *(bmap++);
714                                 *(fb++) = *(bmap++);
715                                 *(fb++) = 0;
716                         }
717                         fb -= lcd_line_length + width * (bpix / 8);
718                 }
719                 break;
720 #endif /* CONFIG_BMP_24BPP */
721 #if defined(CONFIG_BMP_32BPP)
722         case 32:
723                 for (i = 0; i < height; ++i) {
724                         WATCHDOG_RESET();
725                         for (j = 0; j < width; j++) {
726                                 fb[3] = *bmap++; /* T */
727                                 fb[0] = *bmap++; /* B */
728                                 fb[1] = *bmap++; /* G */
729                                 fb[2] = *bmap++; /* R */
730                                 fb += 4;
731                         }
732                         bmap += (padded_width - width) * 4;
733                         fb -= lcd_line_length + width * (bpix / 8);
734                 }
735                 break;
736 #endif /* CONFIG_BMP_32BPP */
737         };
738
739         return 0;
740 }
741 #endif
742
743 static void *lcd_logo(void)
744 {
745 #ifdef CONFIG_SPLASH_SCREEN
746         char *s;
747         ulong addr;
748         static int do_splash = 1;
749
750         if (do_splash && (s = getenv("splashimage")) != NULL) {
751                 int x = 0, y = 0;
752                 char *end;
753
754                 do_splash = 0;
755
756                 if (splash_screen_prepare())
757                         return (void *)lcd_base;
758
759                 addr = simple_strtoul (s, &end, 16);
760                 if (addr == 0 || *end != '\0')
761                         return lcd_base;
762
763                 splash_get_pos(&x, &y);
764
765                 if (bmp_display(addr, x, y) == 0)
766                         return (void *)lcd_base;
767         }
768 #endif /* CONFIG_SPLASH_SCREEN */
769
770         lcd_logo_plot(0, 0);
771
772 #ifdef CONFIG_LCD_INFO
773         lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
774         lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
775         lcd_show_board_info();
776 #endif /* CONFIG_LCD_INFO */
777
778 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
779         return lcd_base + BMP_LOGO_HEIGHT * lcd_line_length;
780 #else
781         return lcd_base;
782 #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
783 }
784
785 #ifdef CONFIG_SPLASHIMAGE_GUARD
786 static int on_splashimage(const char *name, const char *value, enum env_op op,
787         int flags)
788 {
789         ulong addr;
790         int aligned;
791
792         if (op == env_op_delete)
793                 return 0;
794
795         addr = simple_strtoul(value, NULL, 16);
796         /* See README.displaying-bmps */
797         aligned = (addr % 4 == 2);
798         if (!aligned) {
799                 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
800                 return -1;
801         }
802
803         return 0;
804 }
805
806 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
807 #endif
808
809 int lcd_get_pixel_width(void)
810 {
811         return panel_info.vl_col;
812 }
813
814 int lcd_get_pixel_height(void)
815 {
816         return panel_info.vl_row;
817 }