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