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