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