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>
33 #include <fdt_support.h>
35 #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
36 defined(CONFIG_CPU_MONAHANS)
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 (LCD_BPP == LCD_COLOR32)
105 # define COLOR_MASK(c) (c)
107 # error Unsupported LCD BPP.
110 DECLARE_GLOBAL_DATA_PTR;
112 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
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 void lcd_setfgcolor(int color);
120 static void lcd_setbgcolor(int color);
122 static int lcd_color_fg;
123 static int lcd_color_bg;
126 char lcd_is_enabled = 0;
128 static short console_col;
129 static short console_row;
131 static void *lcd_console_address;
132 static void *lcd_base; /* Start of framebuffer memory */
134 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
136 /************************************************************************/
138 /* Flush LCD activity to the caches */
142 * flush_dcache_range() is declared in common.h but it seems that some
143 * architectures do not actually implement it. Is there a way to find
144 * out whether it exists? For now, ARM is safe.
146 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
149 if (lcd_flush_dcache)
150 flush_dcache_range((u32)lcd_base,
151 (u32)(lcd_base + lcd_get_size(&line_length)));
152 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
153 static ulong last_sync;
155 if (get_timer(last_sync) > 10) {
156 sandbox_sdl_sync(lcd_base);
157 last_sync = get_timer(0);
162 void lcd_set_flush_dcache(int flush)
164 lcd_flush_dcache = (flush != 0);
167 /*----------------------------------------------------------------------*/
169 static void console_scrollup(void)
171 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
173 /* Copy up rows ignoring those that will be overwritten */
174 memcpy(CONSOLE_ROW_FIRST,
175 lcd_console_address + CONSOLE_ROW_SIZE * rows,
176 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
178 /* Clear the last rows */
179 #if (LCD_BPP != LCD_COLOR32)
180 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
181 COLOR_MASK(lcd_color_bg),
182 CONSOLE_ROW_SIZE * rows);
184 u32 *ppix = lcd_console_address +
185 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
188 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
190 *ppix++ = COLOR_MASK(lcd_color_bg);
197 /*----------------------------------------------------------------------*/
199 static inline void console_back(void)
201 if (--console_col < 0) {
202 console_col = CONSOLE_COLS-1 ;
203 if (--console_row < 0)
207 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
208 console_row * VIDEO_FONT_HEIGHT, ' ');
211 /*----------------------------------------------------------------------*/
213 static inline void console_newline(void)
217 /* Check if we need to scroll the terminal */
218 if (++console_row >= CONSOLE_ROWS)
224 /*----------------------------------------------------------------------*/
226 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
231 void lcd_putc(const char c)
233 if (!lcd_is_enabled) {
248 case '\t': /* Tab (8 chars alignment) */
252 if (console_col >= CONSOLE_COLS)
261 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
262 console_row * VIDEO_FONT_HEIGHT, c);
263 if (++console_col >= CONSOLE_COLS)
268 /*----------------------------------------------------------------------*/
270 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
275 void lcd_puts(const char *s)
277 if (!lcd_is_enabled) {
289 /*----------------------------------------------------------------------*/
291 void lcd_printf(const char *fmt, ...)
294 char buf[CONFIG_SYS_PBSIZE];
297 vsprintf(buf, fmt, args);
303 /************************************************************************/
304 /* ** Low-Level Graphics Routines */
305 /************************************************************************/
307 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
312 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
313 y += BMP_LOGO_HEIGHT;
316 #if LCD_BPP == LCD_MONOCHROME
317 ushort off = x * NBITS(LCD_BPP) % 8;
320 dest = lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP) / 8;
322 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
325 #if LCD_BPP == LCD_COLOR16
326 ushort *d = (ushort *)dest;
327 #elif LCD_BPP == LCD_COLOR32
328 u32 *d = (u32 *)dest;
333 #if LCD_BPP == LCD_MONOCHROME
334 uchar rest = *d & -(1 << (8 - off));
337 for (i = 0; i < count; ++i) {
341 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
343 #if LCD_BPP == LCD_MONOCHROME
344 sym = (COLOR_MASK(lcd_color_fg) & bits) |
345 (COLOR_MASK(lcd_color_bg) & ~bits);
347 *d++ = rest | (sym >> off);
348 rest = sym << (8-off);
350 for (c = 0; c < 8; ++c) {
351 *d++ = (bits & 0x80) ?
352 lcd_color_fg : lcd_color_bg;
357 #if LCD_BPP == LCD_MONOCHROME
358 *d = rest | (*d & ((1 << (8 - off)) - 1));
363 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
365 lcd_drawchars(x, y, &c, 1);
368 /************************************************************************/
369 /** Small utility to check that you got the colours right */
370 /************************************************************************/
371 #ifdef LCD_TEST_PATTERN
376 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
377 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
378 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
381 #if LCD_BPP == LCD_COLOR8
383 #elif LCD_BPP == LCD_COLOR16
384 typedef ushort pix_t;
385 #elif LCD_BPP == LCD_COLOR32
388 #error Unsupported pixelformat
391 static void test_pattern(void)
393 ushort v_max = panel_info.vl_row;
394 ushort h_max = panel_info.vl_col;
395 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
396 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
398 pix_t *pix = lcd_base;
400 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
401 h_max, v_max, h_step, v_step);
403 /* WARNING: Code silently assumes 8bit/pixel */
404 for (v = 0; v < v_max; ++v) {
405 uchar iy = v / v_step;
406 for (h = 0; h < h_max; ++h) {
407 uchar ix = N_BLK_HOR * iy + h / h_step;
408 *pix++ = test_colors[ix];
412 #endif /* LCD_TEST_PATTERN */
415 /************************************************************************/
416 /* ** GENERIC Initialization Routines */
417 /************************************************************************/
419 * With most lcd drivers the line length is set up
420 * by calculating it from panel_info parameters. Some
421 * drivers need to calculate the line length differently,
422 * so make the function weak to allow overriding it.
424 __weak int lcd_get_size(int *line_length)
426 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
427 return *line_length * panel_info.vl_row;
430 int drv_lcd_init(void)
432 struct stdio_dev lcddev;
435 lcd_base = map_sysmem(gd->fb_base, 0);
437 lcd_init(lcd_base); /* LCD initialization */
439 /* Device initialization */
440 memset(&lcddev, 0, sizeof(lcddev));
442 strcpy(lcddev.name, "lcd");
443 lcddev.ext = 0; /* No extensions */
444 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
445 lcddev.putc = lcd_stub_putc; /* 'putc' function */
446 lcddev.puts = lcd_stub_puts; /* 'puts' function */
448 rc = stdio_register(&lcddev);
450 return (rc == 0) ? 1 : rc;
453 /*----------------------------------------------------------------------*/
456 #if LCD_BPP == LCD_MONOCHROME
457 /* Setting the palette */
460 #elif LCD_BPP == LCD_COLOR8
461 /* Setting the palette */
462 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
463 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
464 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
465 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
466 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
467 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
468 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
469 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
470 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
473 #ifndef CONFIG_SYS_WHITE_ON_BLACK
474 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
475 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
477 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
478 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
479 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
481 #ifdef LCD_TEST_PATTERN
484 /* set framebuffer to background color */
485 #if (LCD_BPP != LCD_COLOR32)
486 memset((char *)lcd_base,
487 COLOR_MASK(lcd_color_bg),
488 lcd_line_length * panel_info.vl_row);
490 u32 *ppix = lcd_base;
493 i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
495 *ppix++ = COLOR_MASK(lcd_color_bg);
499 /* Paint the logo and retrieve LCD base address */
500 debug("[LCD] Drawing the logo @ %p...\n", lcd_base);
501 lcd_console_address = lcd_logo();
508 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
516 cls, 1, 1, do_lcd_clear,
521 /*----------------------------------------------------------------------*/
523 static int lcd_init(void *lcdbase)
525 /* Initialize the lcd controller */
526 debug("[LCD] Initializing %ux%ux%u LCD framebuffer at %p\n",
527 panel_info.vl_col, panel_info.vl_row, NBITS(panel_info.vl_bpix),
530 lcd_ctrl_init(lcdbase);
533 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
534 * the 'lcdbase' argument and uses custom lcd base address
535 * by setting up gd->fb_base. Check for this condition and fixup
536 * 'lcd_base' address.
538 if (map_to_sysmem(lcdbase) != gd->fb_base)
539 lcd_base = map_sysmem(gd->fb_base, 0);
541 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
543 lcd_get_size(&lcd_line_length);
548 /* Initialize the console */
550 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
551 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
553 console_row = 1; /* leave 1 blank line below logo */
560 /************************************************************************/
561 /* ** ROM capable initialization part - needed to reserve FB memory */
562 /************************************************************************/
564 * This is called early in the system initialization to grab memory
565 * for the LCD controller.
566 * Returns new address for monitor, after reserving LCD buffer memory
568 * Note that this is running from ROM, so no write access to global data.
570 ulong lcd_setmem(ulong addr)
575 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
576 panel_info.vl_row, NBITS(panel_info.vl_bpix));
578 size = lcd_get_size(&line_length);
580 /* Round up to nearest full page, or MMU section if defined */
581 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
582 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
584 /* Allocate pages for the frame buffer. */
587 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
593 /*----------------------------------------------------------------------*/
595 static void lcd_setfgcolor(int color)
597 lcd_color_fg = color;
600 /*----------------------------------------------------------------------*/
602 static void lcd_setbgcolor(int color)
604 lcd_color_bg = color;
607 /************************************************************************/
608 /* ** Chipset depending Bitmap / Logo stuff... */
609 /************************************************************************/
610 static inline ushort *configuration_get_cmap(void)
612 #if defined CONFIG_CPU_PXA
613 struct pxafb_info *fbi = &panel_info.pxa;
614 return (ushort *)fbi->palette;
615 #elif defined(CONFIG_MPC823)
616 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
617 cpm8xx_t *cp = &(immr->im_cpm);
618 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
619 #elif defined(CONFIG_ATMEL_LCD)
620 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
621 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
622 return panel_info.cmap;
623 #elif defined(CONFIG_LCD_LOGO)
624 return bmp_logo_palette;
630 #ifdef CONFIG_LCD_LOGO
631 void bitmap_plot(int x, int y)
633 #ifdef CONFIG_ATMEL_LCD
634 uint *cmap = (uint *)bmp_logo_palette;
636 ushort *cmap = (ushort *)bmp_logo_palette;
642 #if defined(CONFIG_MPC823)
643 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
644 cpm8xx_t *cp = &(immr->im_cpm);
646 unsigned bpix = NBITS(panel_info.vl_bpix);
648 debug("Logo: width %d height %d colors %d cmap %d\n",
649 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
650 ARRAY_SIZE(bmp_logo_palette));
652 bmap = &bmp_logo_bitmap[0];
653 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
656 /* Leave room for default color map
657 * default case: generic system with no cmap (most likely 16bpp)
658 * cmap was set to the source palette, so no change is done.
659 * This avoids even more ifdefs in the next stanza
661 #if defined(CONFIG_MPC823)
662 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
663 #elif defined(CONFIG_ATMEL_LCD)
664 cmap = (uint *)configuration_get_cmap();
666 cmap = configuration_get_cmap();
672 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
673 ushort colreg = bmp_logo_palette[i];
674 #ifdef CONFIG_ATMEL_LCD
676 #ifdef CONFIG_ATMEL_LCD_BGR555
677 lut_entry = ((colreg & 0x000F) << 11) |
678 ((colreg & 0x00F0) << 2) |
679 ((colreg & 0x0F00) >> 7);
680 #else /* CONFIG_ATMEL_LCD_RGB565 */
681 lut_entry = ((colreg & 0x000F) << 1) |
682 ((colreg & 0x00F0) << 3) |
683 ((colreg & 0x0F00) << 4);
685 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
687 #else /* !CONFIG_ATMEL_LCD */
688 #ifdef CONFIG_SYS_INVERT_COLORS
689 *cmap++ = 0xffff - colreg;
693 #endif /* CONFIG_ATMEL_LCD */
698 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
699 memcpy(fb, bmap, BMP_LOGO_WIDTH);
700 bmap += BMP_LOGO_WIDTH;
701 fb += panel_info.vl_col;
703 } else if (NBITS(panel_info.vl_bpix) == 16) {
706 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
707 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
708 col16 = bmp_logo_palette[(bmap[j]-16)];
710 ((col16 & 0x000F) << 1) |
711 ((col16 & 0x00F0) << 3) |
712 ((col16 & 0x0F00) << 4);
714 bmap += BMP_LOGO_WIDTH;
715 fb16 += panel_info.vl_col;
717 } else { /* true color mode */
719 u32 *fb32 = lcd_base + y * lcd_line_length + x;
721 for (i = 0; i < BMP_LOGO_HEIGHT; i++) {
722 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
723 col16 = bmp_logo_palette[bmap[j] - 16];
725 ((col16 & 0x000F) << 4) |
726 ((col16 & 0x00F0) << 8) |
727 ((col16 & 0x0F00) << 12);
729 bmap += BMP_LOGO_WIDTH;
730 fb32 += panel_info.vl_col;
738 static inline void bitmap_plot(int x, int y) {}
739 #endif /* CONFIG_LCD_LOGO */
741 /*----------------------------------------------------------------------*/
742 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
744 * Display the BMP file located at address bmp_image.
748 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
749 #define BMP_ALIGN_CENTER 0x7FFF
751 static void splash_align_axis(int *axis, unsigned long panel_size,
752 unsigned long picture_size)
754 unsigned long panel_picture_delta = panel_size - picture_size;
755 unsigned long axis_alignment;
757 if (*axis == BMP_ALIGN_CENTER)
758 axis_alignment = panel_picture_delta / 2;
760 axis_alignment = panel_picture_delta + *axis + 1;
764 *axis = max(0, (int)axis_alignment);
769 #ifdef CONFIG_LCD_BMP_RLE8
771 #define BMP_RLE8_ESCAPE 0
772 #define BMP_RLE8_EOL 0
773 #define BMP_RLE8_EOBMP 1
774 #define BMP_RLE8_DELTA 2
776 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
780 *(*fbp)++ = cmap[*bmap++];
785 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
788 int cnt_8copy = cnt >> 3;
790 cnt -= cnt_8copy << 3;
791 while (cnt_8copy > 0) {
810 * Do not call this function directly, must be called from lcd_display_bitmap.
812 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
813 int x_off, int y_off)
821 width = get_unaligned_le32(&bmp->header.width);
822 height = get_unaligned_le32(&bmp->header.height);
823 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
829 if (bmap[0] == BMP_RLE8_ESCAPE) {
836 /* 16bpix, 2-byte per pixel, width should *2 */
837 fb -= (width * 2 + lcd_line_length);
847 /* 16bpix, 2-byte per pixel, x should *2 */
848 fb = (uchar *) (lcd_base + (y + y_off - 1)
849 * lcd_line_length + (x + x_off) * 2);
858 if (x + runlen > width)
862 draw_unencoded_bitmap(
877 /* aggregate the same code */
878 while (bmap[0] == 0xff &&
879 bmap[2] != BMP_RLE8_ESCAPE &&
880 bmap[1] == bmap[3]) {
884 if (x + runlen > width)
888 draw_encoded_bitmap((ushort **)&fb,
899 #if defined(CONFIG_MPC823)
900 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
902 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
905 #if defined(CONFIG_BMP_16BPP)
906 #if defined(CONFIG_ATMEL_LCD_BGR555)
907 static inline void fb_put_word(uchar **fb, uchar **from)
909 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
910 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
914 static inline void fb_put_word(uchar **fb, uchar **from)
916 *(*fb)++ = *(*from)++;
917 *(*fb)++ = *(*from)++;
920 #endif /* CONFIG_BMP_16BPP */
922 static inline bmp_color_table_entry_t *get_color_table(bmp_image_t *bmp)
924 bmp_header_t *bh = &bmp->header;
925 return (void *)bmp + offsetof(bmp_header_t, size) + bh->size;
928 int lcd_display_bitmap(ulong bmp_image, int x, int y)
931 ushort *cmap_base = NULL;
934 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
937 unsigned long width, height;
938 unsigned long pwidth = panel_info.vl_col;
939 unsigned long long colors;
940 unsigned bpix, bmp_bpix;
941 bmp_color_table_entry_t *cte;
943 if (!bmp || !(bmp->header.signature[0] == 'B' &&
944 bmp->header.signature[1] == 'M')) {
945 printf("Error: no valid bmp image at %lx\n", bmp_image);
950 width = get_unaligned_le32(&bmp->header.width);
951 height = get_unaligned_le32(&bmp->header.height);
952 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
954 colors = 1 << bmp_bpix;
956 bpix = NBITS(panel_info.vl_bpix);
958 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
959 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
966 * We support displaying 8bpp BMPs on 16bpp LCDs
967 * and displaying 24bpp BMPs on 32bpp LCDs
969 if (bpix != bmp_bpix &&
970 !(bmp_bpix == 8 && bpix == 16) &&
971 !(bmp_bpix == 24 && bpix == 32)) {
972 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
973 bpix, get_unaligned_le16(&bmp->header.bit_count));
977 debug("Display-bmp: %lu x %lu with %llu colors\n",
978 width, height, colors);
980 cte = get_color_table(bmp);
982 cmap = configuration_get_cmap();
986 for (i = 0; i < colors; ++i) {
987 #if !defined(CONFIG_ATMEL_LCD)
989 ( ((cte[i].red) << 8) & 0xf800) |
990 ( ((cte[i].green) << 3) & 0x07e0) |
991 ( ((cte[i].blue) >> 3) & 0x001f) ;
992 #ifdef CONFIG_SYS_INVERT_COLORS
993 *cmap = 0xffff - colreg;
997 #if defined(CONFIG_MPC823)
1002 #else /* CONFIG_ATMEL_LCD */
1003 lcd_setcolreg(i, cte[i].red, cte[i].green, cte[i].blue);
1008 padded_width = ALIGN(width, 4);
1010 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1011 splash_align_axis(&x, pwidth, width);
1012 splash_align_axis(&y, panel_info.vl_row, height);
1013 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1014 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
1016 if ((x + width) > pwidth)
1018 if ((y + height) > panel_info.vl_row) {
1019 height = panel_info.vl_row - y;
1020 bmap += (panel_info.vl_row - y) * padded_width;
1023 fb = (uchar *)(lcd_base +
1024 (y + height - 1) * lcd_line_length + x * bpix / 8);
1027 case 1: /* pass through */
1029 #ifdef CONFIG_LCD_BMP_RLE8
1030 u32 compression = get_unaligned_le32(&bmp->header.compression);
1031 if (compression == BMP_BI_RLE8) {
1033 /* TODO implement render code for bpix != 16 */
1034 printf("Error: only support 16 bpix");
1037 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1042 for (i = 0; i < height; ++i) {
1044 for (j = 0; j < width; j++) {
1049 fb[0] = cte[i].blue;
1050 fb[1] = cte[i].green;
1052 fb += sizeof(uint32_t) / sizeof(*fb);
1053 } else if (bpix == 16) {
1054 *(uint16_t *)fb = cmap_base[*(bmap++)];
1055 fb += sizeof(uint16_t) / sizeof(*fb);
1057 FB_PUT_BYTE(fb, bmap);
1061 bmap += padded_width - width;
1062 fb -= width * bpix / 8 + lcd_line_length;
1064 bmap += padded_width;
1065 fb -= lcd_line_length;
1070 #if defined(CONFIG_BMP_16BPP)
1072 for (i = 0; i < height; ++i) {
1074 for (j = 0; j < width; j++)
1075 fb_put_word(&fb, &bmap);
1077 bmap += (padded_width - width) * 2;
1078 fb -= width * 2 + lcd_line_length;
1081 #endif /* CONFIG_BMP_16BPP */
1082 #if defined(CONFIG_BMP_24BMP)
1084 for (i = 0; i < height; ++i) {
1085 for (j = 0; j < width; j++) {
1086 *(fb++) = *(bmap++);
1087 *(fb++) = *(bmap++);
1088 *(fb++) = *(bmap++);
1091 fb -= lcd_line_length + width * (bpix / 8);
1094 #endif /* CONFIG_BMP_24BPP */
1095 #if defined(CONFIG_BMP_32BPP)
1097 for (i = 0; i < height; ++i) {
1099 for (j = 0; j < width; j++) {
1100 fb[3] = *bmap++; /* T */
1101 fb[0] = *bmap++; /* B */
1102 fb[1] = *bmap++; /* G */
1103 fb[2] = *bmap++; /* R */
1106 bmap += (padded_width - width) * 4;
1107 fb -= lcd_line_length + width * (bpix / 8);
1110 #endif /* CONFIG_BMP_32BPP */
1117 static void *lcd_logo(void)
1119 #ifdef CONFIG_SPLASH_SCREEN
1122 static int do_splash = 1;
1124 if (do_splash && (s = getenv("splashimage")) != NULL) {
1130 if (splash_screen_prepare())
1131 return (void *)lcd_base;
1133 addr = simple_strtoul (s, &end, 16);
1134 if (addr == 0 || *end != '\0')
1137 splash_get_pos(&x, &y);
1139 if (bmp_display(addr, x, y) == 0)
1140 return (void *)lcd_base;
1142 #endif /* CONFIG_SPLASH_SCREEN */
1146 #ifdef CONFIG_LCD_INFO
1147 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1148 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1149 lcd_show_board_info();
1150 #endif /* CONFIG_LCD_INFO */
1152 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1153 return lcd_base + BMP_LOGO_HEIGHT * lcd_line_length;
1156 #endif /* CONFIG_LCD_LOGO && !CONFIG_LCD_INFO_BELOW_LOGO */
1159 #ifdef CONFIG_SPLASHIMAGE_GUARD
1160 static int on_splashimage(const char *name, const char *value, enum env_op op,
1166 if (op == env_op_delete)
1169 addr = simple_strtoul(value, NULL, 16);
1170 /* See README.displaying-bmps */
1171 aligned = (addr % 4 == 2);
1173 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1180 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1183 void lcd_position_cursor(unsigned col, unsigned row)
1185 console_col = min_t(short, col, CONSOLE_COLS - 1);
1186 console_row = min_t(short, row, CONSOLE_ROWS - 1);
1189 int lcd_get_pixel_width(void)
1191 return panel_info.vl_col;
1194 int lcd_get_pixel_height(void)
1196 return panel_info.vl_row;
1199 int lcd_get_screen_rows(void)
1201 return CONSOLE_ROWS;
1204 int lcd_get_screen_columns(void)
1206 return CONSOLE_COLS;
1209 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1210 static int lcd_dt_simplefb_configure_node(void *blob, int off)
1212 #if LCD_BPP == LCD_COLOR16
1213 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
1214 panel_info.vl_col, panel_info.vl_row,
1215 panel_info.vl_col * 2, "r5g6b5");
1221 int lcd_dt_simplefb_add_node(void *blob)
1223 static const char compat[] = "simple-framebuffer";
1224 static const char disabled[] = "disabled";
1227 off = fdt_add_subnode(blob, 0, "framebuffer");
1231 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1235 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1239 return lcd_dt_simplefb_configure_node(blob, off);
1242 int lcd_dt_simplefb_enable_existing_node(void *blob)
1246 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1250 return lcd_dt_simplefb_configure_node(blob, off);