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 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
85 #define CONSOLE_ROW_FIRST lcd_console_address
86 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
87 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
89 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows)
90 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
92 #if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \
93 (LCD_BPP != LCD_COLOR32)
94 # error Unsupported LCD BPP.
97 DECLARE_GLOBAL_DATA_PTR;
99 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
100 static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
102 static int lcd_init(void *lcdbase);
104 static void *lcd_logo(void);
106 static void lcd_setfgcolor(int color);
107 static void lcd_setbgcolor(int color);
109 static int lcd_color_fg;
110 static int lcd_color_bg;
113 char lcd_is_enabled = 0;
115 static short console_curr_col;
116 static short console_curr_row;
117 static short console_cols;
118 static short console_rows;
120 static void *lcd_console_address;
121 static void *lcd_base; /* Start of framebuffer memory */
123 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
125 /************************************************************************/
127 /* Flush LCD activity to the caches */
131 * flush_dcache_range() is declared in common.h but it seems that some
132 * architectures do not actually implement it. Is there a way to find
133 * out whether it exists? For now, ARM is safe.
135 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
138 if (lcd_flush_dcache)
139 flush_dcache_range((u32)lcd_base,
140 (u32)(lcd_base + lcd_get_size(&line_length)));
141 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
142 static ulong last_sync;
144 if (get_timer(last_sync) > 10) {
145 sandbox_sdl_sync(lcd_base);
146 last_sync = get_timer(0);
151 void lcd_set_flush_dcache(int flush)
153 lcd_flush_dcache = (flush != 0);
156 void lcd_init_console(void *address, int rows, int cols)
158 console_curr_col = 0;
159 console_curr_row = 0;
162 lcd_console_address = address;
165 void lcd_set_col(short col)
167 console_curr_col = col;
170 void lcd_set_row(short row)
172 console_curr_row = row;
175 /*----------------------------------------------------------------------*/
177 static void console_scrollup(void)
179 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
181 /* Copy up rows ignoring those that will be overwritten */
182 memcpy(CONSOLE_ROW_FIRST,
183 lcd_console_address + CONSOLE_ROW_SIZE * rows,
184 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
186 /* Clear the last rows */
187 #if (LCD_BPP != LCD_COLOR32)
188 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
190 CONSOLE_ROW_SIZE * rows);
192 u32 *ppix = lcd_console_address +
193 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
196 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
198 *ppix++ = lcd_color_bg;
202 console_curr_row -= rows;
205 /*----------------------------------------------------------------------*/
207 static inline void console_back(void)
209 if (--console_curr_col < 0) {
210 console_curr_col = console_cols - 1;
211 if (--console_curr_row < 0)
212 console_curr_row = 0;
215 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
216 console_curr_row * VIDEO_FONT_HEIGHT, ' ');
219 /*----------------------------------------------------------------------*/
221 static inline void console_newline(void)
223 console_curr_col = 0;
225 /* Check if we need to scroll the terminal */
226 if (++console_curr_row >= console_rows)
232 /*----------------------------------------------------------------------*/
234 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
239 void lcd_putc(const char c)
241 if (!lcd_is_enabled) {
249 console_curr_col = 0;
256 case '\t': /* Tab (8 chars alignment) */
257 console_curr_col += 8;
258 console_curr_col &= ~7;
260 if (console_curr_col >= console_cols)
269 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
270 console_curr_row * VIDEO_FONT_HEIGHT, c);
271 if (++console_curr_col >= console_cols)
276 /*----------------------------------------------------------------------*/
278 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
283 void lcd_puts(const char *s)
285 if (!lcd_is_enabled) {
297 /*----------------------------------------------------------------------*/
299 void lcd_printf(const char *fmt, ...)
302 char buf[CONFIG_SYS_PBSIZE];
305 vsprintf(buf, fmt, args);
311 /************************************************************************/
312 /* ** Low-Level Graphics Routines */
313 /************************************************************************/
315 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
320 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
321 y += BMP_LOGO_HEIGHT;
324 dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8);
326 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
329 #if LCD_BPP == LCD_COLOR16
330 ushort *d = (ushort *)dest;
331 #elif LCD_BPP == LCD_COLOR32
332 u32 *d = (u32 *)dest;
337 for (i = 0; i < count; ++i) {
341 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
343 for (c = 0; c < 8; ++c) {
344 *d++ = (bits & 0x80) ?
345 lcd_color_fg : lcd_color_bg;
352 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
354 lcd_drawchars(x, y, &c, 1);
357 /************************************************************************/
358 /** Small utility to check that you got the colours right */
359 /************************************************************************/
360 #ifdef LCD_TEST_PATTERN
365 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
366 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
367 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
370 static void test_pattern(void)
372 ushort v_max = panel_info.vl_row;
373 ushort h_max = panel_info.vl_col;
374 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
375 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
377 uchar *pix = (uchar *)lcd_base;
379 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
380 h_max, v_max, h_step, v_step);
382 /* WARNING: Code silently assumes 8bit/pixel */
383 for (v = 0; v < v_max; ++v) {
384 uchar iy = v / v_step;
385 for (h = 0; h < h_max; ++h) {
386 uchar ix = N_BLK_HOR * iy + h / h_step;
387 *pix++ = test_colors[ix];
391 #endif /* LCD_TEST_PATTERN */
394 /************************************************************************/
395 /* ** GENERIC Initialization Routines */
396 /************************************************************************/
398 * With most lcd drivers the line length is set up
399 * by calculating it from panel_info parameters. Some
400 * drivers need to calculate the line length differently,
401 * so make the function weak to allow overriding it.
403 __weak int lcd_get_size(int *line_length)
405 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
406 return *line_length * panel_info.vl_row;
409 int drv_lcd_init(void)
411 struct stdio_dev lcddev;
414 lcd_base = map_sysmem(gd->fb_base, 0);
416 lcd_init(lcd_base); /* LCD initialization */
418 /* Device initialization */
419 memset(&lcddev, 0, sizeof(lcddev));
421 strcpy(lcddev.name, "lcd");
422 lcddev.ext = 0; /* No extensions */
423 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
424 lcddev.putc = lcd_stub_putc; /* 'putc' function */
425 lcddev.puts = lcd_stub_puts; /* 'puts' function */
427 rc = stdio_register(&lcddev);
429 return (rc == 0) ? 1 : rc;
432 /*----------------------------------------------------------------------*/
435 short console_rows, console_cols;
436 #if LCD_BPP == LCD_COLOR8
437 /* Setting the palette */
438 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
439 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
440 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
441 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
442 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
443 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
444 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
445 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
446 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
449 #ifndef CONFIG_SYS_WHITE_ON_BLACK
450 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
451 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
453 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
454 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
455 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
457 #ifdef LCD_TEST_PATTERN
460 /* set framebuffer to background color */
461 #if (LCD_BPP != LCD_COLOR32)
462 memset((char *)lcd_base,
464 lcd_line_length * panel_info.vl_row);
466 u32 *ppix = lcd_base;
469 i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
471 *ppix++ = lcd_color_bg;
475 /* Paint the logo and retrieve LCD base address */
476 debug("[LCD] Drawing the logo...\n");
477 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
478 console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT);
479 console_rows /= VIDEO_FONT_HEIGHT;
481 console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT;
483 console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH;
484 lcd_init_console(lcd_logo(), console_rows, console_cols);
488 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
496 cls, 1, 1, do_lcd_clear,
501 /*----------------------------------------------------------------------*/
503 static int lcd_init(void *lcdbase)
505 /* Initialize the lcd controller */
506 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
508 lcd_ctrl_init(lcdbase);
511 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
512 * the 'lcdbase' argument and uses custom lcd base address
513 * by setting up gd->fb_base. Check for this condition and fixup
514 * 'lcd_base' address.
516 if (map_to_sysmem(lcdbase) != gd->fb_base)
517 lcd_base = map_sysmem(gd->fb_base, 0);
519 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
521 lcd_get_size(&lcd_line_length);
526 /* Initialize the console */
528 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
529 lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
531 lcd_set_row(1); /* leave 1 blank line below logo */
538 /************************************************************************/
539 /* ** ROM capable initialization part - needed to reserve FB memory */
540 /************************************************************************/
542 * This is called early in the system initialization to grab memory
543 * for the LCD controller.
544 * Returns new address for monitor, after reserving LCD buffer memory
546 * Note that this is running from ROM, so no write access to global data.
548 ulong lcd_setmem(ulong addr)
553 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
554 panel_info.vl_row, NBITS(panel_info.vl_bpix));
556 size = lcd_get_size(&line_length);
558 /* Round up to nearest full page, or MMU section if defined */
559 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
560 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
562 /* Allocate pages for the frame buffer. */
565 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
571 /*----------------------------------------------------------------------*/
573 static void lcd_setfgcolor(int color)
575 lcd_color_fg = color;
578 /*----------------------------------------------------------------------*/
580 static void lcd_setbgcolor(int color)
582 lcd_color_bg = color;
585 /************************************************************************/
586 /* ** Chipset depending Bitmap / Logo stuff... */
587 /************************************************************************/
588 static inline ushort *configuration_get_cmap(void)
590 #if defined CONFIG_CPU_PXA
591 struct pxafb_info *fbi = &panel_info.pxa;
592 return (ushort *)fbi->palette;
593 #elif defined(CONFIG_MPC823)
594 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
595 cpm8xx_t *cp = &(immr->im_cpm);
596 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
597 #elif defined(CONFIG_ATMEL_LCD)
598 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
599 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
600 return panel_info.cmap;
601 #elif defined(CONFIG_LCD_LOGO)
602 return bmp_logo_palette;
608 #ifdef CONFIG_LCD_LOGO
609 void bitmap_plot(int x, int y)
611 #ifdef CONFIG_ATMEL_LCD
612 uint *cmap = (uint *)bmp_logo_palette;
614 ushort *cmap = (ushort *)bmp_logo_palette;
620 #if defined(CONFIG_MPC823)
621 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
622 cpm8xx_t *cp = &(immr->im_cpm);
624 unsigned bpix = NBITS(panel_info.vl_bpix);
626 debug("Logo: width %d height %d colors %d cmap %d\n",
627 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
628 ARRAY_SIZE(bmp_logo_palette));
630 bmap = &bmp_logo_bitmap[0];
631 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
634 /* Leave room for default color map
635 * default case: generic system with no cmap (most likely 16bpp)
636 * cmap was set to the source palette, so no change is done.
637 * This avoids even more ifdefs in the next stanza
639 #if defined(CONFIG_MPC823)
640 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
641 #elif defined(CONFIG_ATMEL_LCD)
642 cmap = (uint *)configuration_get_cmap();
644 cmap = configuration_get_cmap();
650 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
651 ushort colreg = bmp_logo_palette[i];
652 #ifdef CONFIG_ATMEL_LCD
654 #ifdef CONFIG_ATMEL_LCD_BGR555
655 lut_entry = ((colreg & 0x000F) << 11) |
656 ((colreg & 0x00F0) << 2) |
657 ((colreg & 0x0F00) >> 7);
658 #else /* CONFIG_ATMEL_LCD_RGB565 */
659 lut_entry = ((colreg & 0x000F) << 1) |
660 ((colreg & 0x00F0) << 3) |
661 ((colreg & 0x0F00) << 4);
663 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
665 #else /* !CONFIG_ATMEL_LCD */
667 #endif /* CONFIG_ATMEL_LCD */
672 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
673 memcpy(fb, bmap, BMP_LOGO_WIDTH);
674 bmap += BMP_LOGO_WIDTH;
675 fb += panel_info.vl_col;
678 else { /* true color mode */
681 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
682 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
683 col16 = bmp_logo_palette[(bmap[j]-16)];
685 ((col16 & 0x000F) << 1) |
686 ((col16 & 0x00F0) << 3) |
687 ((col16 & 0x0F00) << 4);
689 bmap += BMP_LOGO_WIDTH;
690 fb16 += panel_info.vl_col;
698 static inline void bitmap_plot(int x, int y) {}
699 #endif /* CONFIG_LCD_LOGO */
701 /*----------------------------------------------------------------------*/
702 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
704 * Display the BMP file located at address bmp_image.
708 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
709 #define BMP_ALIGN_CENTER 0x7FFF
711 static void splash_align_axis(int *axis, unsigned long panel_size,
712 unsigned long picture_size)
714 unsigned long panel_picture_delta = panel_size - picture_size;
715 unsigned long axis_alignment;
717 if (*axis == BMP_ALIGN_CENTER)
718 axis_alignment = panel_picture_delta / 2;
720 axis_alignment = panel_picture_delta + *axis + 1;
724 *axis = max(0, (int)axis_alignment);
729 #ifdef CONFIG_LCD_BMP_RLE8
731 #define BMP_RLE8_ESCAPE 0
732 #define BMP_RLE8_EOL 0
733 #define BMP_RLE8_EOBMP 1
734 #define BMP_RLE8_DELTA 2
736 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
740 *(*fbp)++ = cmap[*bmap++];
745 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
748 int cnt_8copy = cnt >> 3;
750 cnt -= cnt_8copy << 3;
751 while (cnt_8copy > 0) {
770 * Do not call this function directly, must be called from lcd_display_bitmap.
772 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
773 int x_off, int y_off)
781 width = get_unaligned_le32(&bmp->header.width);
782 height = get_unaligned_le32(&bmp->header.height);
783 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
789 if (bmap[0] == BMP_RLE8_ESCAPE) {
796 /* 16bpix, 2-byte per pixel, width should *2 */
797 fb -= (width * 2 + lcd_line_length);
807 /* 16bpix, 2-byte per pixel, x should *2 */
808 fb = (uchar *) (lcd_base + (y + y_off - 1)
809 * lcd_line_length + (x + x_off) * 2);
818 if (x + runlen > width)
822 draw_unencoded_bitmap(
837 /* aggregate the same code */
838 while (bmap[0] == 0xff &&
839 bmap[2] != BMP_RLE8_ESCAPE &&
840 bmap[1] == bmap[3]) {
844 if (x + runlen > width)
848 draw_encoded_bitmap((ushort **)&fb,
859 #if defined(CONFIG_MPC823)
860 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
862 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
865 #if defined(CONFIG_BMP_16BPP)
866 #if defined(CONFIG_ATMEL_LCD_BGR555)
867 static inline void fb_put_word(uchar **fb, uchar **from)
869 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
870 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
874 static inline void fb_put_word(uchar **fb, uchar **from)
876 *(*fb)++ = *(*from)++;
877 *(*fb)++ = *(*from)++;
880 #endif /* CONFIG_BMP_16BPP */
882 int lcd_display_bitmap(ulong bmp_image, int x, int y)
885 ushort *cmap_base = NULL;
888 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
891 unsigned long width, height, byte_width;
892 unsigned long pwidth = panel_info.vl_col;
893 unsigned colors, bpix, bmp_bpix;
895 if (!bmp || !(bmp->header.signature[0] == 'B' &&
896 bmp->header.signature[1] == 'M')) {
897 printf("Error: no valid bmp image at %lx\n", bmp_image);
902 width = get_unaligned_le32(&bmp->header.width);
903 height = get_unaligned_le32(&bmp->header.height);
904 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
906 colors = 1 << bmp_bpix;
908 bpix = NBITS(panel_info.vl_bpix);
910 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
911 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
918 * We support displaying 8bpp BMPs on 16bpp LCDs
919 * and displaying 24bpp BMPs on 32bpp LCDs
921 if (bpix != bmp_bpix &&
922 !(bmp_bpix == 8 && bpix == 16) &&
923 !(bmp_bpix == 24 && bpix == 32)) {
924 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
925 bpix, get_unaligned_le16(&bmp->header.bit_count));
929 debug("Display-bmp: %d x %d with %d colors\n",
930 (int)width, (int)height, (int)colors);
933 cmap = configuration_get_cmap();
937 for (i = 0; i < colors; ++i) {
938 bmp_color_table_entry_t cte = bmp->color_table[i];
939 #if !defined(CONFIG_ATMEL_LCD)
941 ( ((cte.red) << 8) & 0xf800) |
942 ( ((cte.green) << 3) & 0x07e0) |
943 ( ((cte.blue) >> 3) & 0x001f) ;
945 #if defined(CONFIG_MPC823)
950 #else /* CONFIG_ATMEL_LCD */
951 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
956 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
958 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
959 splash_align_axis(&x, pwidth, width);
960 splash_align_axis(&y, panel_info.vl_row, height);
961 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
963 if ((x + width) > pwidth)
965 if ((y + height) > panel_info.vl_row)
966 height = panel_info.vl_row - y;
968 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
969 fb = (uchar *)(lcd_base +
970 (y + height - 1) * lcd_line_length + x * bpix / 8);
973 case 1: /* pass through */
975 #ifdef CONFIG_LCD_BMP_RLE8
976 u32 compression = get_unaligned_le32(&bmp->header.compression);
977 if (compression == BMP_BI_RLE8) {
979 /* TODO implement render code for bpix != 16 */
980 printf("Error: only support 16 bpix");
983 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
991 byte_width = width * 2;
993 for (i = 0; i < height; ++i) {
995 for (j = 0; j < width; j++) {
997 FB_PUT_BYTE(fb, bmap);
999 *(uint16_t *)fb = cmap_base[*(bmap++)];
1000 fb += sizeof(uint16_t) / sizeof(*fb);
1003 bmap += (padded_width - width);
1004 fb -= byte_width + lcd_line_length;
1008 #if defined(CONFIG_BMP_16BPP)
1010 for (i = 0; i < height; ++i) {
1012 for (j = 0; j < width; j++)
1013 fb_put_word(&fb, &bmap);
1015 bmap += (padded_width - width) * 2;
1016 fb -= width * 2 + lcd_line_length;
1019 #endif /* CONFIG_BMP_16BPP */
1020 #if defined(CONFIG_BMP_24BMP)
1022 for (i = 0; i < height; ++i) {
1023 for (j = 0; j < width; j++) {
1024 *(fb++) = *(bmap++);
1025 *(fb++) = *(bmap++);
1026 *(fb++) = *(bmap++);
1029 fb -= lcd_line_length + width * (bpix / 8);
1032 #endif /* CONFIG_BMP_24BMP */
1033 #if defined(CONFIG_BMP_32BPP)
1035 for (i = 0; i < height; ++i) {
1036 for (j = 0; j < width; j++) {
1037 *(fb++) = *(bmap++);
1038 *(fb++) = *(bmap++);
1039 *(fb++) = *(bmap++);
1040 *(fb++) = *(bmap++);
1042 fb -= lcd_line_length + width * (bpix / 8);
1045 #endif /* CONFIG_BMP_32BPP */
1055 static void *lcd_logo(void)
1057 #ifdef CONFIG_SPLASH_SCREEN
1060 static int do_splash = 1;
1062 if (do_splash && (s = getenv("splashimage")) != NULL) {
1066 if (splash_screen_prepare())
1067 return (void *)lcd_base;
1069 addr = simple_strtoul (s, NULL, 16);
1071 splash_get_pos(&x, &y);
1073 if (bmp_display(addr, x, y) == 0)
1074 return (void *)lcd_base;
1076 #endif /* CONFIG_SPLASH_SCREEN */
1080 #ifdef CONFIG_LCD_INFO
1081 lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
1082 lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
1083 lcd_show_board_info();
1084 #endif /* CONFIG_LCD_INFO */
1086 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1087 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
1089 return (void *)lcd_base;
1090 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1093 #ifdef CONFIG_SPLASHIMAGE_GUARD
1094 static int on_splashimage(const char *name, const char *value, enum env_op op,
1100 if (op == env_op_delete)
1103 addr = simple_strtoul(value, NULL, 16);
1104 /* See README.displaying-bmps */
1105 aligned = (addr % 4 == 2);
1107 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1114 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1117 void lcd_position_cursor(unsigned col, unsigned row)
1119 console_curr_col = min_t(short, col, console_cols - 1);
1120 console_curr_row = min_t(short, row, console_rows - 1);
1123 int lcd_get_pixel_width(void)
1125 return panel_info.vl_col;
1128 int lcd_get_pixel_height(void)
1130 return panel_info.vl_row;
1133 int lcd_get_screen_rows(void)
1135 return console_rows;
1138 int lcd_get_screen_columns(void)
1140 return console_cols;
1143 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1144 static int lcd_dt_simplefb_configure_node(void *blob, int off)
1146 #if LCD_BPP == LCD_COLOR16
1147 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
1148 panel_info.vl_col, panel_info.vl_row,
1149 panel_info.vl_col * 2, "r5g6b5");
1155 int lcd_dt_simplefb_add_node(void *blob)
1157 static const char compat[] = "simple-framebuffer";
1158 static const char disabled[] = "disabled";
1161 off = fdt_add_subnode(blob, 0, "framebuffer");
1165 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1169 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1173 return lcd_dt_simplefb_configure_node(blob, off);
1176 int lcd_dt_simplefb_enable_existing_node(void *blob)
1180 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1184 return lcd_dt_simplefb_configure_node(blob, off);