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