2 * Common LCD routines for supported CPUs
4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
7 * SPDX-License-Identifier: GPL-2.0+
10 /************************************************************************/
12 /************************************************************************/
21 #include <env_callback.h>
22 #include <linux/types.h>
23 #include <stdio_dev.h>
24 #if defined(CONFIG_POST)
29 #include <asm/unaligned.h>
32 #include <asm/unaligned.h>
34 #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
35 defined(CONFIG_CPU_MONAHANS)
36 #define CONFIG_CPU_PXA
37 #include <asm/byteorder.h>
40 #if defined(CONFIG_MPC823)
44 #if defined(CONFIG_ATMEL_LCD)
45 #include <atmel_lcdc.h>
48 #if defined(CONFIG_LCD_DT_SIMPLEFB)
52 /************************************************************************/
54 /************************************************************************/
55 #include <video_font.h> /* Get font data, width and height */
57 /************************************************************************/
59 /************************************************************************/
60 #ifdef CONFIG_LCD_LOGO
61 # include <bmp_logo.h> /* Get logo data, width and height */
62 # include <bmp_logo_data.h>
63 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
64 # error Default Color Map overlaps with Logo Color Map
72 #ifndef CONFIG_LCD_ALIGNMENT
73 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
76 /* By default we scroll by a single line */
77 #ifndef CONFIG_CONSOLE_SCROLL_LINES
78 #define CONFIG_CONSOLE_SCROLL_LINES 1
81 /************************************************************************/
82 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
83 /************************************************************************/
84 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
85 # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
88 # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
91 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
92 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
93 #define CONSOLE_ROW_FIRST lcd_console_address
94 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
95 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
97 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
98 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
100 #if LCD_BPP == LCD_MONOCHROME
101 # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
102 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
103 #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
104 # define COLOR_MASK(c) (c)
106 # error Unsupported LCD BPP.
109 DECLARE_GLOBAL_DATA_PTR;
111 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
112 static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
113 static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
115 static int lcd_init(void *lcdbase);
117 static void *lcd_logo(void);
119 static int lcd_getbgcolor(void);
120 static void lcd_setfgcolor(int color);
121 static void lcd_setbgcolor(int color);
123 static int lcd_color_fg;
124 static int lcd_color_bg;
127 char lcd_is_enabled = 0;
129 static short console_col;
130 static short console_row;
132 static void *lcd_console_address;
133 static void *lcd_base; /* Start of framebuffer memory */
135 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
137 /************************************************************************/
139 /* Flush LCD activity to the caches */
143 * flush_dcache_range() is declared in common.h but it seems that some
144 * architectures do not actually implement it. Is there a way to find
145 * out whether it exists? For now, ARM is safe.
147 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
150 if (lcd_flush_dcache)
151 flush_dcache_range((u32)lcd_base,
152 (u32)(lcd_base + lcd_get_size(&line_length)));
153 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
154 static ulong last_sync;
156 if (get_timer(last_sync) > 10) {
157 sandbox_sdl_sync(lcd_base);
158 last_sync = get_timer(0);
163 void lcd_set_flush_dcache(int flush)
165 lcd_flush_dcache = (flush != 0);
168 /*----------------------------------------------------------------------*/
170 static void console_scrollup(void)
172 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
174 /* Copy up rows ignoring those that will be overwritten */
175 memcpy(CONSOLE_ROW_FIRST,
176 lcd_console_address + CONSOLE_ROW_SIZE * rows,
177 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
179 /* Clear the last rows */
180 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
181 COLOR_MASK(lcd_color_bg),
182 CONSOLE_ROW_SIZE * rows);
188 /*----------------------------------------------------------------------*/
190 static inline void console_back(void)
192 if (--console_col < 0) {
193 console_col = CONSOLE_COLS-1 ;
194 if (--console_row < 0)
198 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
199 console_row * VIDEO_FONT_HEIGHT, ' ');
202 /*----------------------------------------------------------------------*/
204 static inline void console_newline(void)
208 /* Check if we need to scroll the terminal */
209 if (++console_row >= CONSOLE_ROWS)
215 /*----------------------------------------------------------------------*/
217 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
222 void lcd_putc(const char c)
224 if (!lcd_is_enabled) {
239 case '\t': /* Tab (8 chars alignment) */
243 if (console_col >= CONSOLE_COLS)
252 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
253 console_row * VIDEO_FONT_HEIGHT, c);
254 if (++console_col >= CONSOLE_COLS)
259 /*----------------------------------------------------------------------*/
261 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
266 void lcd_puts(const char *s)
268 if (!lcd_is_enabled) {
280 /*----------------------------------------------------------------------*/
282 void lcd_printf(const char *fmt, ...)
285 char buf[CONFIG_SYS_PBSIZE];
288 vsprintf(buf, fmt, args);
294 /************************************************************************/
295 /* ** Low-Level Graphics Routines */
296 /************************************************************************/
298 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
303 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
304 y += BMP_LOGO_HEIGHT;
307 #if LCD_BPP == LCD_MONOCHROME
308 ushort off = x * (1 << LCD_BPP) % 8;
311 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
313 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
316 #if LCD_BPP == LCD_COLOR16
317 ushort *d = (ushort *)dest;
322 #if LCD_BPP == LCD_MONOCHROME
323 uchar rest = *d & -(1 << (8 - off));
326 for (i = 0; i < count; ++i) {
330 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
332 #if LCD_BPP == LCD_MONOCHROME
333 sym = (COLOR_MASK(lcd_color_fg) & bits) |
334 (COLOR_MASK(lcd_color_bg) & ~bits);
336 *d++ = rest | (sym >> off);
337 rest = sym << (8-off);
338 #elif LCD_BPP == LCD_COLOR8
339 for (c = 0; c < 8; ++c) {
340 *d++ = (bits & 0x80) ?
341 lcd_color_fg : lcd_color_bg;
344 #elif LCD_BPP == LCD_COLOR16
345 for (c = 0; c < 8; ++c) {
346 *d++ = (bits & 0x80) ?
347 lcd_color_fg : lcd_color_bg;
352 #if LCD_BPP == LCD_MONOCHROME
353 *d = rest | (*d & ((1 << (8 - off)) - 1));
358 /*----------------------------------------------------------------------*/
360 static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
362 lcd_drawchars(x, y, s, strlen((char *)s));
365 /*----------------------------------------------------------------------*/
367 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
369 lcd_drawchars(x, y, &c, 1);
372 /************************************************************************/
373 /** Small utility to check that you got the colours right */
374 /************************************************************************/
375 #ifdef LCD_TEST_PATTERN
380 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
381 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
382 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
385 static void test_pattern(void)
387 ushort v_max = panel_info.vl_row;
388 ushort h_max = panel_info.vl_col;
389 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
390 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
392 uchar *pix = (uchar *)lcd_base;
394 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
395 h_max, v_max, h_step, v_step);
397 /* WARNING: Code silently assumes 8bit/pixel */
398 for (v = 0; v < v_max; ++v) {
399 uchar iy = v / v_step;
400 for (h = 0; h < h_max; ++h) {
401 uchar ix = N_BLK_HOR * iy + h / h_step;
402 *pix++ = test_colors[ix];
406 #endif /* LCD_TEST_PATTERN */
409 /************************************************************************/
410 /* ** GENERIC Initialization Routines */
411 /************************************************************************/
413 * With most lcd drivers the line length is set up
414 * by calculating it from panel_info parameters. Some
415 * drivers need to calculate the line length differently,
416 * so make the function weak to allow overriding it.
418 __weak int lcd_get_size(int *line_length)
420 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
421 return *line_length * panel_info.vl_row;
424 int drv_lcd_init(void)
426 struct stdio_dev lcddev;
429 lcd_base = map_sysmem(gd->fb_base, 0);
431 lcd_init(lcd_base); /* LCD initialization */
433 /* Device initialization */
434 memset(&lcddev, 0, sizeof(lcddev));
436 strcpy(lcddev.name, "lcd");
437 lcddev.ext = 0; /* No extensions */
438 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
439 lcddev.putc = lcd_stub_putc; /* 'putc' function */
440 lcddev.puts = lcd_stub_puts; /* 'puts' function */
442 rc = stdio_register(&lcddev);
444 return (rc == 0) ? 1 : rc;
447 /*----------------------------------------------------------------------*/
450 #if LCD_BPP == LCD_MONOCHROME
451 /* Setting the palette */
454 #elif LCD_BPP == LCD_COLOR8
455 /* Setting the palette */
456 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
457 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
458 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
459 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
460 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
461 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
462 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
463 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
464 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
467 #ifndef CONFIG_SYS_WHITE_ON_BLACK
468 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
469 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
471 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
472 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
473 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
475 #ifdef LCD_TEST_PATTERN
478 /* set framebuffer to background color */
479 memset((char *)lcd_base,
480 COLOR_MASK(lcd_getbgcolor()),
481 lcd_line_length * panel_info.vl_row);
483 /* Paint the logo and retrieve LCD base address */
484 debug("[LCD] Drawing the logo...\n");
485 lcd_console_address = lcd_logo();
492 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
500 cls, 1, 1, do_lcd_clear,
505 /*----------------------------------------------------------------------*/
507 static int lcd_init(void *lcdbase)
509 /* Initialize the lcd controller */
510 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
512 lcd_ctrl_init(lcdbase);
515 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
516 * the 'lcdbase' argument and uses custom lcd base address
517 * by setting up gd->fb_base. Check for this condition and fixup
518 * 'lcd_base' address.
520 if (map_to_sysmem(lcdbase) != gd->fb_base)
521 lcd_base = map_sysmem(gd->fb_base, 0);
523 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
525 lcd_get_size(&lcd_line_length);
530 /* Initialize the console */
532 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
533 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
535 console_row = 1; /* leave 1 blank line below logo */
542 /************************************************************************/
543 /* ** ROM capable initialization part - needed to reserve FB memory */
544 /************************************************************************/
546 * This is called early in the system initialization to grab memory
547 * for the LCD controller.
548 * Returns new address for monitor, after reserving LCD buffer memory
550 * Note that this is running from ROM, so no write access to global data.
552 ulong lcd_setmem(ulong addr)
557 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
558 panel_info.vl_row, NBITS(panel_info.vl_bpix));
560 size = lcd_get_size(&line_length);
562 /* Round up to nearest full page, or MMU section if defined */
563 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
564 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
566 /* Allocate pages for the frame buffer. */
569 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
575 /*----------------------------------------------------------------------*/
577 static void lcd_setfgcolor(int color)
579 lcd_color_fg = color;
582 /*----------------------------------------------------------------------*/
584 static void lcd_setbgcolor(int color)
586 lcd_color_bg = color;
589 /*----------------------------------------------------------------------*/
591 int lcd_getfgcolor(void)
596 /*----------------------------------------------------------------------*/
598 static int lcd_getbgcolor(void)
603 /************************************************************************/
604 /* ** Chipset depending Bitmap / Logo stuff... */
605 /************************************************************************/
606 static inline ushort *configuration_get_cmap(void)
608 #if defined CONFIG_CPU_PXA
609 struct pxafb_info *fbi = &panel_info.pxa;
610 return (ushort *)fbi->palette;
611 #elif defined(CONFIG_MPC823)
612 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
613 cpm8xx_t *cp = &(immr->im_cpm);
614 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
615 #elif defined(CONFIG_ATMEL_LCD)
616 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
617 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
618 return panel_info.cmap;
619 #elif defined(CONFIG_LCD_LOGO)
620 return bmp_logo_palette;
626 #ifdef CONFIG_LCD_LOGO
627 void bitmap_plot(int x, int y)
629 #ifdef CONFIG_ATMEL_LCD
630 uint *cmap = (uint *)bmp_logo_palette;
632 ushort *cmap = (ushort *)bmp_logo_palette;
638 #if defined(CONFIG_MPC823)
639 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
640 cpm8xx_t *cp = &(immr->im_cpm);
642 unsigned bpix = NBITS(panel_info.vl_bpix);
644 debug("Logo: width %d height %d colors %d cmap %d\n",
645 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
646 ARRAY_SIZE(bmp_logo_palette));
648 bmap = &bmp_logo_bitmap[0];
649 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
652 /* Leave room for default color map
653 * default case: generic system with no cmap (most likely 16bpp)
654 * cmap was set to the source palette, so no change is done.
655 * This avoids even more ifdefs in the next stanza
657 #if defined(CONFIG_MPC823)
658 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
659 #elif defined(CONFIG_ATMEL_LCD)
660 cmap = (uint *)configuration_get_cmap();
662 cmap = configuration_get_cmap();
668 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
669 ushort colreg = bmp_logo_palette[i];
670 #ifdef CONFIG_ATMEL_LCD
672 #ifdef CONFIG_ATMEL_LCD_BGR555
673 lut_entry = ((colreg & 0x000F) << 11) |
674 ((colreg & 0x00F0) << 2) |
675 ((colreg & 0x0F00) >> 7);
676 #else /* CONFIG_ATMEL_LCD_RGB565 */
677 lut_entry = ((colreg & 0x000F) << 1) |
678 ((colreg & 0x00F0) << 3) |
679 ((colreg & 0x0F00) << 4);
681 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
683 #else /* !CONFIG_ATMEL_LCD */
684 #ifdef CONFIG_SYS_INVERT_COLORS
685 *cmap++ = 0xffff - colreg;
689 #endif /* CONFIG_ATMEL_LCD */
694 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
695 memcpy(fb, bmap, BMP_LOGO_WIDTH);
696 bmap += BMP_LOGO_WIDTH;
697 fb += panel_info.vl_col;
700 else { /* true color mode */
703 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
704 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
705 col16 = bmp_logo_palette[(bmap[j]-16)];
707 ((col16 & 0x000F) << 1) |
708 ((col16 & 0x00F0) << 3) |
709 ((col16 & 0x0F00) << 4);
711 bmap += BMP_LOGO_WIDTH;
712 fb16 += panel_info.vl_col;
720 static inline void bitmap_plot(int x, int y) {}
721 #endif /* CONFIG_LCD_LOGO */
723 /*----------------------------------------------------------------------*/
724 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
726 * Display the BMP file located at address bmp_image.
730 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
731 #define BMP_ALIGN_CENTER 0x7FFF
733 static void splash_align_axis(int *axis, unsigned long panel_size,
734 unsigned long picture_size)
736 unsigned long panel_picture_delta = panel_size - picture_size;
737 unsigned long axis_alignment;
739 if (*axis == BMP_ALIGN_CENTER)
740 axis_alignment = panel_picture_delta / 2;
742 axis_alignment = panel_picture_delta + *axis + 1;
746 *axis = max(0, axis_alignment);
751 #ifdef CONFIG_LCD_BMP_RLE8
753 #define BMP_RLE8_ESCAPE 0
754 #define BMP_RLE8_EOL 0
755 #define BMP_RLE8_EOBMP 1
756 #define BMP_RLE8_DELTA 2
758 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
762 *(*fbp)++ = cmap[*bmap++];
767 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
770 int cnt_8copy = cnt >> 3;
772 cnt -= cnt_8copy << 3;
773 while (cnt_8copy > 0) {
792 * Do not call this function directly, must be called from lcd_display_bitmap.
794 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
795 int x_off, int y_off)
803 width = get_unaligned_le32(&bmp->header.width);
804 height = get_unaligned_le32(&bmp->header.height);
805 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
811 if (bmap[0] == BMP_RLE8_ESCAPE) {
818 /* 16bpix, 2-byte per pixel, width should *2 */
819 fb -= (width * 2 + lcd_line_length);
829 /* 16bpix, 2-byte per pixel, x should *2 */
830 fb = (uchar *) (lcd_base + (y + y_off - 1)
831 * lcd_line_length + (x + x_off) * 2);
840 if (x + runlen > width)
844 draw_unencoded_bitmap(
859 /* aggregate the same code */
860 while (bmap[0] == 0xff &&
861 bmap[2] != BMP_RLE8_ESCAPE &&
862 bmap[1] == bmap[3]) {
866 if (x + runlen > width)
870 draw_encoded_bitmap((ushort **)&fb,
881 #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
882 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
884 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
887 #if defined(CONFIG_BMP_16BPP)
888 #if defined(CONFIG_ATMEL_LCD_BGR555)
889 static inline void fb_put_word(uchar **fb, uchar **from)
891 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
892 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
896 static inline void fb_put_word(uchar **fb, uchar **from)
898 *(*fb)++ = *(*from)++;
899 *(*fb)++ = *(*from)++;
902 #endif /* CONFIG_BMP_16BPP */
904 int lcd_display_bitmap(ulong bmp_image, int x, int y)
906 #if !defined(CONFIG_MCC200)
909 ushort *cmap_base = NULL;
912 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
915 unsigned long width, height, byte_width;
916 unsigned long pwidth = panel_info.vl_col;
917 unsigned colors, bpix, bmp_bpix;
919 if (!bmp || !(bmp->header.signature[0] == 'B' &&
920 bmp->header.signature[1] == 'M')) {
921 printf("Error: no valid bmp image at %lx\n", bmp_image);
926 width = get_unaligned_le32(&bmp->header.width);
927 height = get_unaligned_le32(&bmp->header.height);
928 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
930 colors = 1 << bmp_bpix;
932 bpix = NBITS(panel_info.vl_bpix);
934 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
935 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
941 /* We support displaying 8bpp BMPs on 16bpp LCDs */
942 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
943 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
944 bpix, get_unaligned_le16(&bmp->header.bit_count));
948 debug("Display-bmp: %d x %d with %d colors\n",
949 (int)width, (int)height, (int)colors);
951 #if !defined(CONFIG_MCC200)
952 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
954 cmap = configuration_get_cmap();
958 for (i = 0; i < colors; ++i) {
959 bmp_color_table_entry_t cte = bmp->color_table[i];
960 #if !defined(CONFIG_ATMEL_LCD)
962 ( ((cte.red) << 8) & 0xf800) |
963 ( ((cte.green) << 3) & 0x07e0) |
964 ( ((cte.blue) >> 3) & 0x001f) ;
965 #ifdef CONFIG_SYS_INVERT_COLORS
966 *cmap = 0xffff - colreg;
970 #if defined(CONFIG_MPC823)
975 #else /* CONFIG_ATMEL_LCD */
976 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
982 * BMP format for Monochrome assumes that the state of a
983 * pixel is described on a per Bit basis, not per Byte.
984 * So, in case of Monochrome BMP we should align widths
985 * on a byte boundary and convert them from Bit to Byte
987 * Probably, PXA250 and MPC823 process 1bpp BMP images in
988 * their own ways, so make the converting to be MCC200
991 #if defined(CONFIG_MCC200)
993 width = ((width + 7) & ~7) >> 3;
994 x = ((x + 7) & ~7) >> 3;
995 pwidth= ((pwidth + 7) & ~7) >> 3;
999 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
1001 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1002 splash_align_axis(&x, pwidth, width);
1003 splash_align_axis(&y, panel_info.vl_row, height);
1004 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1006 if ((x + width) > pwidth)
1008 if ((y + height) > panel_info.vl_row)
1009 height = panel_info.vl_row - y;
1011 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
1012 fb = (uchar *)(lcd_base +
1013 (y + height - 1) * lcd_line_length + x * bpix / 8);
1016 case 1: /* pass through */
1018 #ifdef CONFIG_LCD_BMP_RLE8
1019 u32 compression = get_unaligned_le32(&bmp->header.compression);
1020 if (compression == BMP_BI_RLE8) {
1022 /* TODO implement render code for bpix != 16 */
1023 printf("Error: only support 16 bpix");
1026 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1034 byte_width = width * 2;
1036 for (i = 0; i < height; ++i) {
1038 for (j = 0; j < width; j++) {
1040 FB_PUT_BYTE(fb, bmap);
1042 *(uint16_t *)fb = cmap_base[*(bmap++)];
1043 fb += sizeof(uint16_t) / sizeof(*fb);
1046 bmap += (padded_width - width);
1047 fb -= byte_width + lcd_line_length;
1051 #if defined(CONFIG_BMP_16BPP)
1053 for (i = 0; i < height; ++i) {
1055 for (j = 0; j < width; j++)
1056 fb_put_word(&fb, &bmap);
1058 bmap += (padded_width - width) * 2;
1059 fb -= width * 2 + lcd_line_length;
1062 #endif /* CONFIG_BMP_16BPP */
1064 #if defined(CONFIG_BMP_32BPP)
1066 for (i = 0; i < height; ++i) {
1067 for (j = 0; j < width; j++) {
1068 *(fb++) = *(bmap++);
1069 *(fb++) = *(bmap++);
1070 *(fb++) = *(bmap++);
1071 *(fb++) = *(bmap++);
1073 fb -= lcd_line_length + width * (bpix / 8);
1076 #endif /* CONFIG_BMP_32BPP */
1086 static void *lcd_logo(void)
1088 #ifdef CONFIG_SPLASH_SCREEN
1091 static int do_splash = 1;
1093 if (do_splash && (s = getenv("splashimage")) != NULL) {
1097 if (splash_screen_prepare())
1098 return (void *)lcd_base;
1100 addr = simple_strtoul (s, NULL, 16);
1102 splash_get_pos(&x, &y);
1104 if (bmp_display(addr, x, y) == 0)
1105 return (void *)lcd_base;
1107 #endif /* CONFIG_SPLASH_SCREEN */
1111 #ifdef CONFIG_LCD_INFO
1112 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1113 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1114 lcd_show_board_info();
1115 #endif /* CONFIG_LCD_INFO */
1117 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1118 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
1120 return (void *)lcd_base;
1121 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1124 #ifdef CONFIG_SPLASHIMAGE_GUARD
1125 static int on_splashimage(const char *name, const char *value, enum env_op op,
1131 if (op == env_op_delete)
1134 addr = simple_strtoul(value, NULL, 16);
1135 /* See README.displaying-bmps */
1136 aligned = (addr % 4 == 2);
1138 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1145 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1148 void lcd_position_cursor(unsigned col, unsigned row)
1150 console_col = min(col, CONSOLE_COLS - 1);
1151 console_row = min(row, CONSOLE_ROWS - 1);
1154 int lcd_get_pixel_width(void)
1156 return panel_info.vl_col;
1159 int lcd_get_pixel_height(void)
1161 return panel_info.vl_row;
1164 int lcd_get_screen_rows(void)
1166 return CONSOLE_ROWS;
1169 int lcd_get_screen_columns(void)
1171 return CONSOLE_COLS;
1174 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1175 static int lcd_dt_simplefb_configure_node(void *blob, int off)
1180 static const char format[] =
1181 #if LCD_BPP == LCD_COLOR16
1190 stride = panel_info.vl_col * 2;
1192 cells[0] = cpu_to_fdt32(gd->fb_base);
1193 cells[1] = cpu_to_fdt32(stride * panel_info.vl_row);
1194 ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2);
1198 cells[0] = cpu_to_fdt32(panel_info.vl_col);
1199 ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0]));
1203 cells[0] = cpu_to_fdt32(panel_info.vl_row);
1204 ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0]));
1208 cells[0] = cpu_to_fdt32(stride);
1209 ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0]));
1213 ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1);
1217 ret = fdt_delprop(blob, off, "status");
1224 int lcd_dt_simplefb_add_node(void *blob)
1226 static const char compat[] = "simple-framebuffer";
1227 static const char disabled[] = "disabled";
1230 off = fdt_add_subnode(blob, 0, "framebuffer");
1234 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1238 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1242 return lcd_dt_simplefb_configure_node(blob, off);
1245 int lcd_dt_simplefb_enable_existing_node(void *blob)
1249 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1253 return lcd_dt_simplefb_configure_node(blob, off);