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