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 # define COLOR_MASK(c) (c)
96 # error Unsupported LCD BPP.
99 DECLARE_GLOBAL_DATA_PTR;
101 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
102 static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
104 static int lcd_init(void *lcdbase);
106 static void *lcd_logo(void);
108 static void lcd_setfgcolor(int color);
109 static void lcd_setbgcolor(int color);
111 static int lcd_color_fg;
112 static int lcd_color_bg;
115 char lcd_is_enabled = 0;
117 static short console_curr_col;
118 static short console_curr_row;
119 static short console_cols;
120 static short console_rows;
122 static void *lcd_console_address;
123 static void *lcd_base; /* Start of framebuffer memory */
125 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
127 /************************************************************************/
129 /* Flush LCD activity to the caches */
133 * flush_dcache_range() is declared in common.h but it seems that some
134 * architectures do not actually implement it. Is there a way to find
135 * out whether it exists? For now, ARM is safe.
137 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
140 if (lcd_flush_dcache)
141 flush_dcache_range((u32)lcd_base,
142 (u32)(lcd_base + lcd_get_size(&line_length)));
143 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
144 static ulong last_sync;
146 if (get_timer(last_sync) > 10) {
147 sandbox_sdl_sync(lcd_base);
148 last_sync = get_timer(0);
153 void lcd_set_flush_dcache(int flush)
155 lcd_flush_dcache = (flush != 0);
158 /*----------------------------------------------------------------------*/
160 static void console_scrollup(void)
162 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
164 /* Copy up rows ignoring those that will be overwritten */
165 memcpy(CONSOLE_ROW_FIRST,
166 lcd_console_address + CONSOLE_ROW_SIZE * rows,
167 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
169 /* Clear the last rows */
170 #if (LCD_BPP != LCD_COLOR32)
171 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
172 COLOR_MASK(lcd_color_bg),
173 CONSOLE_ROW_SIZE * rows);
175 u32 *ppix = lcd_console_address +
176 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
179 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
181 *ppix++ = COLOR_MASK(lcd_color_bg);
185 console_curr_row -= rows;
188 /*----------------------------------------------------------------------*/
190 static inline void console_back(void)
192 if (--console_curr_col < 0) {
193 console_curr_col = console_cols - 1;
194 if (--console_curr_row < 0)
195 console_curr_row = 0;
198 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
199 console_curr_row * VIDEO_FONT_HEIGHT, ' ');
202 /*----------------------------------------------------------------------*/
204 static inline void console_newline(void)
206 console_curr_col = 0;
208 /* Check if we need to scroll the terminal */
209 if (++console_curr_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) {
232 console_curr_col = 0;
239 case '\t': /* Tab (8 chars alignment) */
240 console_curr_col += 8;
241 console_curr_col &= ~7;
243 if (console_curr_col >= console_cols)
252 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
253 console_curr_row * VIDEO_FONT_HEIGHT, c);
254 if (++console_curr_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 dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8);
309 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
312 #if LCD_BPP == LCD_COLOR16
313 ushort *d = (ushort *)dest;
314 #elif LCD_BPP == LCD_COLOR32
315 u32 *d = (u32 *)dest;
320 for (i = 0; i < count; ++i) {
324 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
326 for (c = 0; c < 8; ++c) {
327 *d++ = (bits & 0x80) ?
328 lcd_color_fg : lcd_color_bg;
335 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
337 lcd_drawchars(x, y, &c, 1);
340 /************************************************************************/
341 /** Small utility to check that you got the colours right */
342 /************************************************************************/
343 #ifdef LCD_TEST_PATTERN
348 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
349 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
350 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
353 static void test_pattern(void)
355 ushort v_max = panel_info.vl_row;
356 ushort h_max = panel_info.vl_col;
357 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
358 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
360 uchar *pix = (uchar *)lcd_base;
362 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
363 h_max, v_max, h_step, v_step);
365 /* WARNING: Code silently assumes 8bit/pixel */
366 for (v = 0; v < v_max; ++v) {
367 uchar iy = v / v_step;
368 for (h = 0; h < h_max; ++h) {
369 uchar ix = N_BLK_HOR * iy + h / h_step;
370 *pix++ = test_colors[ix];
374 #endif /* LCD_TEST_PATTERN */
377 /************************************************************************/
378 /* ** GENERIC Initialization Routines */
379 /************************************************************************/
381 * With most lcd drivers the line length is set up
382 * by calculating it from panel_info parameters. Some
383 * drivers need to calculate the line length differently,
384 * so make the function weak to allow overriding it.
386 __weak int lcd_get_size(int *line_length)
388 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
389 return *line_length * panel_info.vl_row;
392 int drv_lcd_init(void)
394 struct stdio_dev lcddev;
397 lcd_base = map_sysmem(gd->fb_base, 0);
399 lcd_init(lcd_base); /* LCD initialization */
401 /* Device initialization */
402 memset(&lcddev, 0, sizeof(lcddev));
404 strcpy(lcddev.name, "lcd");
405 lcddev.ext = 0; /* No extensions */
406 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
407 lcddev.putc = lcd_stub_putc; /* 'putc' function */
408 lcddev.puts = lcd_stub_puts; /* 'puts' function */
410 rc = stdio_register(&lcddev);
412 return (rc == 0) ? 1 : rc;
415 /*----------------------------------------------------------------------*/
418 #if LCD_BPP == LCD_COLOR8
419 /* Setting the palette */
420 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
421 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
422 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
423 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
424 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
425 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
426 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
427 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
428 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
431 #ifndef CONFIG_SYS_WHITE_ON_BLACK
432 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
433 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
435 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
436 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
437 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
439 #ifdef LCD_TEST_PATTERN
442 /* set framebuffer to background color */
443 #if (LCD_BPP != LCD_COLOR32)
444 memset((char *)lcd_base,
445 COLOR_MASK(lcd_color_bg),
446 lcd_line_length * panel_info.vl_row);
448 u32 *ppix = lcd_base;
451 i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
453 *ppix++ = COLOR_MASK(lcd_color_bg);
457 /* Paint the logo and retrieve LCD base address */
458 debug("[LCD] Drawing the logo...\n");
459 lcd_console_address = lcd_logo();
461 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
462 console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT);
463 console_rows /= VIDEO_FONT_HEIGHT;
465 console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT;
467 console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH;
468 console_curr_col = 0;
469 console_curr_row = 0;
473 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
481 cls, 1, 1, do_lcd_clear,
486 /*----------------------------------------------------------------------*/
488 static int lcd_init(void *lcdbase)
490 /* Initialize the lcd controller */
491 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
493 lcd_ctrl_init(lcdbase);
496 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
497 * the 'lcdbase' argument and uses custom lcd base address
498 * by setting up gd->fb_base. Check for this condition and fixup
499 * 'lcd_base' address.
501 if (map_to_sysmem(lcdbase) != gd->fb_base)
502 lcd_base = map_sysmem(gd->fb_base, 0);
504 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
506 lcd_get_size(&lcd_line_length);
511 /* Initialize the console */
512 console_curr_col = 0;
513 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
514 console_curr_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
516 console_curr_row = 1; /* leave 1 blank line below logo */
523 /************************************************************************/
524 /* ** ROM capable initialization part - needed to reserve FB memory */
525 /************************************************************************/
527 * This is called early in the system initialization to grab memory
528 * for the LCD controller.
529 * Returns new address for monitor, after reserving LCD buffer memory
531 * Note that this is running from ROM, so no write access to global data.
533 ulong lcd_setmem(ulong addr)
538 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
539 panel_info.vl_row, NBITS(panel_info.vl_bpix));
541 size = lcd_get_size(&line_length);
543 /* Round up to nearest full page, or MMU section if defined */
544 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
545 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
547 /* Allocate pages for the frame buffer. */
550 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
556 /*----------------------------------------------------------------------*/
558 static void lcd_setfgcolor(int color)
560 lcd_color_fg = color;
563 /*----------------------------------------------------------------------*/
565 static void lcd_setbgcolor(int color)
567 lcd_color_bg = color;
570 /************************************************************************/
571 /* ** Chipset depending Bitmap / Logo stuff... */
572 /************************************************************************/
573 static inline ushort *configuration_get_cmap(void)
575 #if defined CONFIG_CPU_PXA
576 struct pxafb_info *fbi = &panel_info.pxa;
577 return (ushort *)fbi->palette;
578 #elif defined(CONFIG_MPC823)
579 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
580 cpm8xx_t *cp = &(immr->im_cpm);
581 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
582 #elif defined(CONFIG_ATMEL_LCD)
583 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
584 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
585 return panel_info.cmap;
586 #elif defined(CONFIG_LCD_LOGO)
587 return bmp_logo_palette;
593 #ifdef CONFIG_LCD_LOGO
594 void bitmap_plot(int x, int y)
596 #ifdef CONFIG_ATMEL_LCD
597 uint *cmap = (uint *)bmp_logo_palette;
599 ushort *cmap = (ushort *)bmp_logo_palette;
605 #if defined(CONFIG_MPC823)
606 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
607 cpm8xx_t *cp = &(immr->im_cpm);
609 unsigned bpix = NBITS(panel_info.vl_bpix);
611 debug("Logo: width %d height %d colors %d cmap %d\n",
612 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
613 ARRAY_SIZE(bmp_logo_palette));
615 bmap = &bmp_logo_bitmap[0];
616 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
619 /* Leave room for default color map
620 * default case: generic system with no cmap (most likely 16bpp)
621 * cmap was set to the source palette, so no change is done.
622 * This avoids even more ifdefs in the next stanza
624 #if defined(CONFIG_MPC823)
625 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
626 #elif defined(CONFIG_ATMEL_LCD)
627 cmap = (uint *)configuration_get_cmap();
629 cmap = configuration_get_cmap();
635 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
636 ushort colreg = bmp_logo_palette[i];
637 #ifdef CONFIG_ATMEL_LCD
639 #ifdef CONFIG_ATMEL_LCD_BGR555
640 lut_entry = ((colreg & 0x000F) << 11) |
641 ((colreg & 0x00F0) << 2) |
642 ((colreg & 0x0F00) >> 7);
643 #else /* CONFIG_ATMEL_LCD_RGB565 */
644 lut_entry = ((colreg & 0x000F) << 1) |
645 ((colreg & 0x00F0) << 3) |
646 ((colreg & 0x0F00) << 4);
648 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
650 #else /* !CONFIG_ATMEL_LCD */
652 #endif /* CONFIG_ATMEL_LCD */
657 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
658 memcpy(fb, bmap, BMP_LOGO_WIDTH);
659 bmap += BMP_LOGO_WIDTH;
660 fb += panel_info.vl_col;
663 else { /* true color mode */
666 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
667 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
668 col16 = bmp_logo_palette[(bmap[j]-16)];
670 ((col16 & 0x000F) << 1) |
671 ((col16 & 0x00F0) << 3) |
672 ((col16 & 0x0F00) << 4);
674 bmap += BMP_LOGO_WIDTH;
675 fb16 += panel_info.vl_col;
683 static inline void bitmap_plot(int x, int y) {}
684 #endif /* CONFIG_LCD_LOGO */
686 /*----------------------------------------------------------------------*/
687 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
689 * Display the BMP file located at address bmp_image.
693 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
694 #define BMP_ALIGN_CENTER 0x7FFF
696 static void splash_align_axis(int *axis, unsigned long panel_size,
697 unsigned long picture_size)
699 unsigned long panel_picture_delta = panel_size - picture_size;
700 unsigned long axis_alignment;
702 if (*axis == BMP_ALIGN_CENTER)
703 axis_alignment = panel_picture_delta / 2;
705 axis_alignment = panel_picture_delta + *axis + 1;
709 *axis = max(0, (int)axis_alignment);
714 #ifdef CONFIG_LCD_BMP_RLE8
716 #define BMP_RLE8_ESCAPE 0
717 #define BMP_RLE8_EOL 0
718 #define BMP_RLE8_EOBMP 1
719 #define BMP_RLE8_DELTA 2
721 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
725 *(*fbp)++ = cmap[*bmap++];
730 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
733 int cnt_8copy = cnt >> 3;
735 cnt -= cnt_8copy << 3;
736 while (cnt_8copy > 0) {
755 * Do not call this function directly, must be called from lcd_display_bitmap.
757 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
758 int x_off, int y_off)
766 width = get_unaligned_le32(&bmp->header.width);
767 height = get_unaligned_le32(&bmp->header.height);
768 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
774 if (bmap[0] == BMP_RLE8_ESCAPE) {
781 /* 16bpix, 2-byte per pixel, width should *2 */
782 fb -= (width * 2 + lcd_line_length);
792 /* 16bpix, 2-byte per pixel, x should *2 */
793 fb = (uchar *) (lcd_base + (y + y_off - 1)
794 * lcd_line_length + (x + x_off) * 2);
803 if (x + runlen > width)
807 draw_unencoded_bitmap(
822 /* aggregate the same code */
823 while (bmap[0] == 0xff &&
824 bmap[2] != BMP_RLE8_ESCAPE &&
825 bmap[1] == bmap[3]) {
829 if (x + runlen > width)
833 draw_encoded_bitmap((ushort **)&fb,
844 #if defined(CONFIG_MPC823)
845 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
847 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
850 #if defined(CONFIG_BMP_16BPP)
851 #if defined(CONFIG_ATMEL_LCD_BGR555)
852 static inline void fb_put_word(uchar **fb, uchar **from)
854 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
855 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
859 static inline void fb_put_word(uchar **fb, uchar **from)
861 *(*fb)++ = *(*from)++;
862 *(*fb)++ = *(*from)++;
865 #endif /* CONFIG_BMP_16BPP */
867 int lcd_display_bitmap(ulong bmp_image, int x, int y)
870 ushort *cmap_base = NULL;
873 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
876 unsigned long width, height, byte_width;
877 unsigned long pwidth = panel_info.vl_col;
878 unsigned colors, bpix, bmp_bpix;
880 if (!bmp || !(bmp->header.signature[0] == 'B' &&
881 bmp->header.signature[1] == 'M')) {
882 printf("Error: no valid bmp image at %lx\n", bmp_image);
887 width = get_unaligned_le32(&bmp->header.width);
888 height = get_unaligned_le32(&bmp->header.height);
889 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
891 colors = 1 << bmp_bpix;
893 bpix = NBITS(panel_info.vl_bpix);
895 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
896 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
903 * We support displaying 8bpp BMPs on 16bpp LCDs
904 * and displaying 24bpp BMPs on 32bpp LCDs
906 if (bpix != bmp_bpix &&
907 !(bmp_bpix == 8 && bpix == 16) &&
908 !(bmp_bpix == 24 && bpix == 32)) {
909 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
910 bpix, get_unaligned_le16(&bmp->header.bit_count));
914 debug("Display-bmp: %d x %d with %d colors\n",
915 (int)width, (int)height, (int)colors);
918 cmap = configuration_get_cmap();
922 for (i = 0; i < colors; ++i) {
923 bmp_color_table_entry_t cte = bmp->color_table[i];
924 #if !defined(CONFIG_ATMEL_LCD)
926 ( ((cte.red) << 8) & 0xf800) |
927 ( ((cte.green) << 3) & 0x07e0) |
928 ( ((cte.blue) >> 3) & 0x001f) ;
930 #if defined(CONFIG_MPC823)
935 #else /* CONFIG_ATMEL_LCD */
936 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
941 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
943 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
944 splash_align_axis(&x, pwidth, width);
945 splash_align_axis(&y, panel_info.vl_row, height);
946 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
948 if ((x + width) > pwidth)
950 if ((y + height) > panel_info.vl_row)
951 height = panel_info.vl_row - y;
953 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
954 fb = (uchar *)(lcd_base +
955 (y + height - 1) * lcd_line_length + x * bpix / 8);
958 case 1: /* pass through */
960 #ifdef CONFIG_LCD_BMP_RLE8
961 u32 compression = get_unaligned_le32(&bmp->header.compression);
962 if (compression == BMP_BI_RLE8) {
964 /* TODO implement render code for bpix != 16 */
965 printf("Error: only support 16 bpix");
968 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
976 byte_width = width * 2;
978 for (i = 0; i < height; ++i) {
980 for (j = 0; j < width; j++) {
982 FB_PUT_BYTE(fb, bmap);
984 *(uint16_t *)fb = cmap_base[*(bmap++)];
985 fb += sizeof(uint16_t) / sizeof(*fb);
988 bmap += (padded_width - width);
989 fb -= byte_width + lcd_line_length;
993 #if defined(CONFIG_BMP_16BPP)
995 for (i = 0; i < height; ++i) {
997 for (j = 0; j < width; j++)
998 fb_put_word(&fb, &bmap);
1000 bmap += (padded_width - width) * 2;
1001 fb -= width * 2 + lcd_line_length;
1004 #endif /* CONFIG_BMP_16BPP */
1005 #if defined(CONFIG_BMP_24BMP)
1007 for (i = 0; i < height; ++i) {
1008 for (j = 0; j < width; j++) {
1009 *(fb++) = *(bmap++);
1010 *(fb++) = *(bmap++);
1011 *(fb++) = *(bmap++);
1014 fb -= lcd_line_length + width * (bpix / 8);
1017 #endif /* CONFIG_BMP_24BMP */
1018 #if defined(CONFIG_BMP_32BPP)
1020 for (i = 0; i < height; ++i) {
1021 for (j = 0; j < width; j++) {
1022 *(fb++) = *(bmap++);
1023 *(fb++) = *(bmap++);
1024 *(fb++) = *(bmap++);
1025 *(fb++) = *(bmap++);
1027 fb -= lcd_line_length + width * (bpix / 8);
1030 #endif /* CONFIG_BMP_32BPP */
1040 static void *lcd_logo(void)
1042 #ifdef CONFIG_SPLASH_SCREEN
1045 static int do_splash = 1;
1047 if (do_splash && (s = getenv("splashimage")) != NULL) {
1051 if (splash_screen_prepare())
1052 return (void *)lcd_base;
1054 addr = simple_strtoul (s, NULL, 16);
1056 splash_get_pos(&x, &y);
1058 if (bmp_display(addr, x, y) == 0)
1059 return (void *)lcd_base;
1061 #endif /* CONFIG_SPLASH_SCREEN */
1065 #ifdef CONFIG_LCD_INFO
1066 console_curr_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1067 console_curr_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1068 lcd_show_board_info();
1069 #endif /* CONFIG_LCD_INFO */
1071 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1072 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
1074 return (void *)lcd_base;
1075 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1078 #ifdef CONFIG_SPLASHIMAGE_GUARD
1079 static int on_splashimage(const char *name, const char *value, enum env_op op,
1085 if (op == env_op_delete)
1088 addr = simple_strtoul(value, NULL, 16);
1089 /* See README.displaying-bmps */
1090 aligned = (addr % 4 == 2);
1092 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1099 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1102 void lcd_position_cursor(unsigned col, unsigned row)
1104 console_curr_col = min_t(short, col, console_cols - 1);
1105 console_curr_row = min_t(short, row, console_rows - 1);
1108 int lcd_get_pixel_width(void)
1110 return panel_info.vl_col;
1113 int lcd_get_pixel_height(void)
1115 return panel_info.vl_row;
1118 int lcd_get_screen_rows(void)
1120 return console_rows;
1123 int lcd_get_screen_columns(void)
1125 return console_cols;
1128 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1129 static int lcd_dt_simplefb_configure_node(void *blob, int off)
1131 #if LCD_BPP == LCD_COLOR16
1132 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
1133 panel_info.vl_col, panel_info.vl_row,
1134 panel_info.vl_col * 2, "r5g6b5");
1140 int lcd_dt_simplefb_add_node(void *blob)
1142 static const char compat[] = "simple-framebuffer";
1143 static const char disabled[] = "disabled";
1146 off = fdt_add_subnode(blob, 0, "framebuffer");
1150 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1154 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1158 return lcd_dt_simplefb_configure_node(blob, off);
1161 int lcd_dt_simplefb_enable_existing_node(void *blob)
1165 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1169 return lcd_dt_simplefb_configure_node(blob, off);