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_COLOR8) || (LCD_BPP == LCD_COLOR16) || \
101 (LCD_BPP == LCD_COLOR32)
102 # define COLOR_MASK(c) (c)
104 # error Unsupported LCD BPP.
107 DECLARE_GLOBAL_DATA_PTR;
109 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
110 static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
112 static int lcd_init(void *lcdbase);
114 static void *lcd_logo(void);
116 static void lcd_setfgcolor(int color);
117 static void lcd_setbgcolor(int color);
119 static int lcd_color_fg;
120 static int lcd_color_bg;
123 char lcd_is_enabled = 0;
125 static short console_col;
126 static short console_row;
128 static void *lcd_console_address;
129 static void *lcd_base; /* Start of framebuffer memory */
131 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
133 /************************************************************************/
135 /* Flush LCD activity to the caches */
139 * flush_dcache_range() is declared in common.h but it seems that some
140 * architectures do not actually implement it. Is there a way to find
141 * out whether it exists? For now, ARM is safe.
143 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
146 if (lcd_flush_dcache)
147 flush_dcache_range((u32)lcd_base,
148 (u32)(lcd_base + lcd_get_size(&line_length)));
149 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
150 static ulong last_sync;
152 if (get_timer(last_sync) > 10) {
153 sandbox_sdl_sync(lcd_base);
154 last_sync = get_timer(0);
159 void lcd_set_flush_dcache(int flush)
161 lcd_flush_dcache = (flush != 0);
164 /*----------------------------------------------------------------------*/
166 static void console_scrollup(void)
168 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
170 /* Copy up rows ignoring those that will be overwritten */
171 memcpy(CONSOLE_ROW_FIRST,
172 lcd_console_address + CONSOLE_ROW_SIZE * rows,
173 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
175 /* Clear the last rows */
176 #if (LCD_BPP != LCD_COLOR32)
177 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
178 COLOR_MASK(lcd_color_bg),
179 CONSOLE_ROW_SIZE * rows);
181 u32 *ppix = lcd_console_address +
182 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
185 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
187 *ppix++ = COLOR_MASK(lcd_color_bg);
194 /*----------------------------------------------------------------------*/
196 static inline void console_back(void)
198 if (--console_col < 0) {
199 console_col = CONSOLE_COLS-1 ;
200 if (--console_row < 0)
204 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
205 console_row * VIDEO_FONT_HEIGHT, ' ');
208 /*----------------------------------------------------------------------*/
210 static inline void console_newline(void)
214 /* Check if we need to scroll the terminal */
215 if (++console_row >= CONSOLE_ROWS)
221 /*----------------------------------------------------------------------*/
223 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
228 void lcd_putc(const char c)
230 if (!lcd_is_enabled) {
245 case '\t': /* Tab (8 chars alignment) */
249 if (console_col >= CONSOLE_COLS)
258 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
259 console_row * VIDEO_FONT_HEIGHT, c);
260 if (++console_col >= CONSOLE_COLS)
265 /*----------------------------------------------------------------------*/
267 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
272 void lcd_puts(const char *s)
274 if (!lcd_is_enabled) {
286 /*----------------------------------------------------------------------*/
288 void lcd_printf(const char *fmt, ...)
291 char buf[CONFIG_SYS_PBSIZE];
294 vsprintf(buf, fmt, args);
300 /************************************************************************/
301 /* ** Low-Level Graphics Routines */
302 /************************************************************************/
304 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
309 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
310 y += BMP_LOGO_HEIGHT;
313 dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8);
315 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
318 #if LCD_BPP == LCD_COLOR16
319 ushort *d = (ushort *)dest;
320 #elif LCD_BPP == LCD_COLOR32
321 u32 *d = (u32 *)dest;
326 for (i = 0; i < count; ++i) {
330 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
332 for (c = 0; c < 8; ++c) {
333 *d++ = (bits & 0x80) ?
334 lcd_color_fg : lcd_color_bg;
341 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
343 lcd_drawchars(x, y, &c, 1);
346 /************************************************************************/
347 /** Small utility to check that you got the colours right */
348 /************************************************************************/
349 #ifdef LCD_TEST_PATTERN
354 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
355 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
356 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
359 static void test_pattern(void)
361 ushort v_max = panel_info.vl_row;
362 ushort h_max = panel_info.vl_col;
363 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
364 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
366 uchar *pix = (uchar *)lcd_base;
368 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
369 h_max, v_max, h_step, v_step);
371 /* WARNING: Code silently assumes 8bit/pixel */
372 for (v = 0; v < v_max; ++v) {
373 uchar iy = v / v_step;
374 for (h = 0; h < h_max; ++h) {
375 uchar ix = N_BLK_HOR * iy + h / h_step;
376 *pix++ = test_colors[ix];
380 #endif /* LCD_TEST_PATTERN */
383 /************************************************************************/
384 /* ** GENERIC Initialization Routines */
385 /************************************************************************/
387 * With most lcd drivers the line length is set up
388 * by calculating it from panel_info parameters. Some
389 * drivers need to calculate the line length differently,
390 * so make the function weak to allow overriding it.
392 __weak int lcd_get_size(int *line_length)
394 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
395 return *line_length * panel_info.vl_row;
398 int drv_lcd_init(void)
400 struct stdio_dev lcddev;
403 lcd_base = map_sysmem(gd->fb_base, 0);
405 lcd_init(lcd_base); /* LCD initialization */
407 /* Device initialization */
408 memset(&lcddev, 0, sizeof(lcddev));
410 strcpy(lcddev.name, "lcd");
411 lcddev.ext = 0; /* No extensions */
412 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
413 lcddev.putc = lcd_stub_putc; /* 'putc' function */
414 lcddev.puts = lcd_stub_puts; /* 'puts' function */
416 rc = stdio_register(&lcddev);
418 return (rc == 0) ? 1 : rc;
421 /*----------------------------------------------------------------------*/
424 #if LCD_BPP == LCD_COLOR8
425 /* Setting the palette */
426 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
427 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
428 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
429 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
430 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
431 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
432 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
433 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
434 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
437 #ifndef CONFIG_SYS_WHITE_ON_BLACK
438 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
439 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
441 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
442 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
443 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
445 #ifdef LCD_TEST_PATTERN
448 /* set framebuffer to background color */
449 #if (LCD_BPP != LCD_COLOR32)
450 memset((char *)lcd_base,
451 COLOR_MASK(lcd_color_bg),
452 lcd_line_length * panel_info.vl_row);
454 u32 *ppix = lcd_base;
457 i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
459 *ppix++ = COLOR_MASK(lcd_color_bg);
463 /* Paint the logo and retrieve LCD base address */
464 debug("[LCD] Drawing the logo...\n");
465 lcd_console_address = lcd_logo();
472 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
480 cls, 1, 1, do_lcd_clear,
485 /*----------------------------------------------------------------------*/
487 static int lcd_init(void *lcdbase)
489 /* Initialize the lcd controller */
490 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
492 lcd_ctrl_init(lcdbase);
495 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
496 * the 'lcdbase' argument and uses custom lcd base address
497 * by setting up gd->fb_base. Check for this condition and fixup
498 * 'lcd_base' address.
500 if (map_to_sysmem(lcdbase) != gd->fb_base)
501 lcd_base = map_sysmem(gd->fb_base, 0);
503 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
505 lcd_get_size(&lcd_line_length);
510 /* Initialize the console */
512 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
513 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
515 console_row = 1; /* leave 1 blank line below logo */
522 /************************************************************************/
523 /* ** ROM capable initialization part - needed to reserve FB memory */
524 /************************************************************************/
526 * This is called early in the system initialization to grab memory
527 * for the LCD controller.
528 * Returns new address for monitor, after reserving LCD buffer memory
530 * Note that this is running from ROM, so no write access to global data.
532 ulong lcd_setmem(ulong addr)
537 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
538 panel_info.vl_row, NBITS(panel_info.vl_bpix));
540 size = lcd_get_size(&line_length);
542 /* Round up to nearest full page, or MMU section if defined */
543 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
544 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
546 /* Allocate pages for the frame buffer. */
549 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
555 /*----------------------------------------------------------------------*/
557 static void lcd_setfgcolor(int color)
559 lcd_color_fg = color;
562 /*----------------------------------------------------------------------*/
564 static void lcd_setbgcolor(int color)
566 lcd_color_bg = color;
569 /************************************************************************/
570 /* ** Chipset depending Bitmap / Logo stuff... */
571 /************************************************************************/
572 static inline ushort *configuration_get_cmap(void)
574 #if defined CONFIG_CPU_PXA
575 struct pxafb_info *fbi = &panel_info.pxa;
576 return (ushort *)fbi->palette;
577 #elif defined(CONFIG_MPC823)
578 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
579 cpm8xx_t *cp = &(immr->im_cpm);
580 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
581 #elif defined(CONFIG_ATMEL_LCD)
582 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
583 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
584 return panel_info.cmap;
585 #elif defined(CONFIG_LCD_LOGO)
586 return bmp_logo_palette;
592 #ifdef CONFIG_LCD_LOGO
593 void bitmap_plot(int x, int y)
595 #ifdef CONFIG_ATMEL_LCD
596 uint *cmap = (uint *)bmp_logo_palette;
598 ushort *cmap = (ushort *)bmp_logo_palette;
604 #if defined(CONFIG_MPC823)
605 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
606 cpm8xx_t *cp = &(immr->im_cpm);
608 unsigned bpix = NBITS(panel_info.vl_bpix);
610 debug("Logo: width %d height %d colors %d cmap %d\n",
611 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
612 ARRAY_SIZE(bmp_logo_palette));
614 bmap = &bmp_logo_bitmap[0];
615 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
618 /* Leave room for default color map
619 * default case: generic system with no cmap (most likely 16bpp)
620 * cmap was set to the source palette, so no change is done.
621 * This avoids even more ifdefs in the next stanza
623 #if defined(CONFIG_MPC823)
624 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
625 #elif defined(CONFIG_ATMEL_LCD)
626 cmap = (uint *)configuration_get_cmap();
628 cmap = configuration_get_cmap();
634 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
635 ushort colreg = bmp_logo_palette[i];
636 #ifdef CONFIG_ATMEL_LCD
638 #ifdef CONFIG_ATMEL_LCD_BGR555
639 lut_entry = ((colreg & 0x000F) << 11) |
640 ((colreg & 0x00F0) << 2) |
641 ((colreg & 0x0F00) >> 7);
642 #else /* CONFIG_ATMEL_LCD_RGB565 */
643 lut_entry = ((colreg & 0x000F) << 1) |
644 ((colreg & 0x00F0) << 3) |
645 ((colreg & 0x0F00) << 4);
647 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
649 #else /* !CONFIG_ATMEL_LCD */
651 #endif /* CONFIG_ATMEL_LCD */
656 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
657 memcpy(fb, bmap, BMP_LOGO_WIDTH);
658 bmap += BMP_LOGO_WIDTH;
659 fb += panel_info.vl_col;
662 else { /* true color mode */
665 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
666 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
667 col16 = bmp_logo_palette[(bmap[j]-16)];
669 ((col16 & 0x000F) << 1) |
670 ((col16 & 0x00F0) << 3) |
671 ((col16 & 0x0F00) << 4);
673 bmap += BMP_LOGO_WIDTH;
674 fb16 += panel_info.vl_col;
682 static inline void bitmap_plot(int x, int y) {}
683 #endif /* CONFIG_LCD_LOGO */
685 /*----------------------------------------------------------------------*/
686 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
688 * Display the BMP file located at address bmp_image.
692 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
693 #define BMP_ALIGN_CENTER 0x7FFF
695 static void splash_align_axis(int *axis, unsigned long panel_size,
696 unsigned long picture_size)
698 unsigned long panel_picture_delta = panel_size - picture_size;
699 unsigned long axis_alignment;
701 if (*axis == BMP_ALIGN_CENTER)
702 axis_alignment = panel_picture_delta / 2;
704 axis_alignment = panel_picture_delta + *axis + 1;
708 *axis = max(0, (int)axis_alignment);
713 #ifdef CONFIG_LCD_BMP_RLE8
715 #define BMP_RLE8_ESCAPE 0
716 #define BMP_RLE8_EOL 0
717 #define BMP_RLE8_EOBMP 1
718 #define BMP_RLE8_DELTA 2
720 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
724 *(*fbp)++ = cmap[*bmap++];
729 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
732 int cnt_8copy = cnt >> 3;
734 cnt -= cnt_8copy << 3;
735 while (cnt_8copy > 0) {
754 * Do not call this function directly, must be called from lcd_display_bitmap.
756 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
757 int x_off, int y_off)
765 width = get_unaligned_le32(&bmp->header.width);
766 height = get_unaligned_le32(&bmp->header.height);
767 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
773 if (bmap[0] == BMP_RLE8_ESCAPE) {
780 /* 16bpix, 2-byte per pixel, width should *2 */
781 fb -= (width * 2 + lcd_line_length);
791 /* 16bpix, 2-byte per pixel, x should *2 */
792 fb = (uchar *) (lcd_base + (y + y_off - 1)
793 * lcd_line_length + (x + x_off) * 2);
802 if (x + runlen > width)
806 draw_unencoded_bitmap(
821 /* aggregate the same code */
822 while (bmap[0] == 0xff &&
823 bmap[2] != BMP_RLE8_ESCAPE &&
824 bmap[1] == bmap[3]) {
828 if (x + runlen > width)
832 draw_encoded_bitmap((ushort **)&fb,
843 #if defined(CONFIG_MPC823)
844 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
846 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
849 #if defined(CONFIG_BMP_16BPP)
850 #if defined(CONFIG_ATMEL_LCD_BGR555)
851 static inline void fb_put_word(uchar **fb, uchar **from)
853 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
854 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
858 static inline void fb_put_word(uchar **fb, uchar **from)
860 *(*fb)++ = *(*from)++;
861 *(*fb)++ = *(*from)++;
864 #endif /* CONFIG_BMP_16BPP */
866 int lcd_display_bitmap(ulong bmp_image, int x, int y)
869 ushort *cmap_base = NULL;
872 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
875 unsigned long width, height, byte_width;
876 unsigned long pwidth = panel_info.vl_col;
877 unsigned colors, bpix, bmp_bpix;
879 if (!bmp || !(bmp->header.signature[0] == 'B' &&
880 bmp->header.signature[1] == 'M')) {
881 printf("Error: no valid bmp image at %lx\n", bmp_image);
886 width = get_unaligned_le32(&bmp->header.width);
887 height = get_unaligned_le32(&bmp->header.height);
888 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
890 colors = 1 << bmp_bpix;
892 bpix = NBITS(panel_info.vl_bpix);
894 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
895 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
902 * We support displaying 8bpp BMPs on 16bpp LCDs
903 * and displaying 24bpp BMPs on 32bpp LCDs
905 if (bpix != bmp_bpix &&
906 !(bmp_bpix == 8 && bpix == 16) &&
907 !(bmp_bpix == 24 && bpix == 32)) {
908 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
909 bpix, get_unaligned_le16(&bmp->header.bit_count));
913 debug("Display-bmp: %d x %d with %d colors\n",
914 (int)width, (int)height, (int)colors);
917 cmap = configuration_get_cmap();
921 for (i = 0; i < colors; ++i) {
922 bmp_color_table_entry_t cte = bmp->color_table[i];
923 #if !defined(CONFIG_ATMEL_LCD)
925 ( ((cte.red) << 8) & 0xf800) |
926 ( ((cte.green) << 3) & 0x07e0) |
927 ( ((cte.blue) >> 3) & 0x001f) ;
929 #if defined(CONFIG_MPC823)
934 #else /* CONFIG_ATMEL_LCD */
935 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
940 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
942 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
943 splash_align_axis(&x, pwidth, width);
944 splash_align_axis(&y, panel_info.vl_row, height);
945 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
947 if ((x + width) > pwidth)
949 if ((y + height) > panel_info.vl_row)
950 height = panel_info.vl_row - y;
952 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
953 fb = (uchar *)(lcd_base +
954 (y + height - 1) * lcd_line_length + x * bpix / 8);
957 case 1: /* pass through */
959 #ifdef CONFIG_LCD_BMP_RLE8
960 u32 compression = get_unaligned_le32(&bmp->header.compression);
961 if (compression == BMP_BI_RLE8) {
963 /* TODO implement render code for bpix != 16 */
964 printf("Error: only support 16 bpix");
967 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
975 byte_width = width * 2;
977 for (i = 0; i < height; ++i) {
979 for (j = 0; j < width; j++) {
981 FB_PUT_BYTE(fb, bmap);
983 *(uint16_t *)fb = cmap_base[*(bmap++)];
984 fb += sizeof(uint16_t) / sizeof(*fb);
987 bmap += (padded_width - width);
988 fb -= byte_width + lcd_line_length;
992 #if defined(CONFIG_BMP_16BPP)
994 for (i = 0; i < height; ++i) {
996 for (j = 0; j < width; j++)
997 fb_put_word(&fb, &bmap);
999 bmap += (padded_width - width) * 2;
1000 fb -= width * 2 + lcd_line_length;
1003 #endif /* CONFIG_BMP_16BPP */
1004 #if defined(CONFIG_BMP_24BMP)
1006 for (i = 0; i < height; ++i) {
1007 for (j = 0; j < width; j++) {
1008 *(fb++) = *(bmap++);
1009 *(fb++) = *(bmap++);
1010 *(fb++) = *(bmap++);
1013 fb -= lcd_line_length + width * (bpix / 8);
1016 #endif /* CONFIG_BMP_24BMP */
1017 #if defined(CONFIG_BMP_32BPP)
1019 for (i = 0; i < height; ++i) {
1020 for (j = 0; j < width; j++) {
1021 *(fb++) = *(bmap++);
1022 *(fb++) = *(bmap++);
1023 *(fb++) = *(bmap++);
1024 *(fb++) = *(bmap++);
1026 fb -= lcd_line_length + width * (bpix / 8);
1029 #endif /* CONFIG_BMP_32BPP */
1039 static void *lcd_logo(void)
1041 #ifdef CONFIG_SPLASH_SCREEN
1044 static int do_splash = 1;
1046 if (do_splash && (s = getenv("splashimage")) != NULL) {
1050 if (splash_screen_prepare())
1051 return (void *)lcd_base;
1053 addr = simple_strtoul (s, NULL, 16);
1055 splash_get_pos(&x, &y);
1057 if (bmp_display(addr, x, y) == 0)
1058 return (void *)lcd_base;
1060 #endif /* CONFIG_SPLASH_SCREEN */
1064 #ifdef CONFIG_LCD_INFO
1065 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1066 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1067 lcd_show_board_info();
1068 #endif /* CONFIG_LCD_INFO */
1070 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1071 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
1073 return (void *)lcd_base;
1074 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1077 #ifdef CONFIG_SPLASHIMAGE_GUARD
1078 static int on_splashimage(const char *name, const char *value, enum env_op op,
1084 if (op == env_op_delete)
1087 addr = simple_strtoul(value, NULL, 16);
1088 /* See README.displaying-bmps */
1089 aligned = (addr % 4 == 2);
1091 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1098 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1101 void lcd_position_cursor(unsigned col, unsigned row)
1103 console_col = min_t(short, col, CONSOLE_COLS - 1);
1104 console_row = min_t(short, row, CONSOLE_ROWS - 1);
1107 int lcd_get_pixel_width(void)
1109 return panel_info.vl_col;
1112 int lcd_get_pixel_height(void)
1114 return panel_info.vl_row;
1117 int lcd_get_screen_rows(void)
1119 return CONSOLE_ROWS;
1122 int lcd_get_screen_columns(void)
1124 return CONSOLE_COLS;
1127 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1128 static int lcd_dt_simplefb_configure_node(void *blob, int off)
1130 #if LCD_BPP == LCD_COLOR16
1131 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
1132 panel_info.vl_col, panel_info.vl_row,
1133 panel_info.vl_col * 2, "r5g6b5");
1139 int lcd_dt_simplefb_add_node(void *blob)
1141 static const char compat[] = "simple-framebuffer";
1142 static const char disabled[] = "disabled";
1145 off = fdt_add_subnode(blob, 0, "framebuffer");
1149 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1153 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1157 return lcd_dt_simplefb_configure_node(blob, off);
1160 int lcd_dt_simplefb_enable_existing_node(void *blob)
1164 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1168 return lcd_dt_simplefb_configure_node(blob, off);