2 * Common LCD routines for supported CPUs
4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
7 * SPDX-License-Identifier: GPL-2.0+
10 /************************************************************************/
12 /************************************************************************/
21 #include <env_callback.h>
22 #include <linux/types.h>
23 #include <stdio_dev.h>
24 #if defined(CONFIG_POST)
29 #include <asm/unaligned.h>
32 #include <asm/unaligned.h>
34 #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
35 defined(CONFIG_CPU_MONAHANS)
36 #define CONFIG_CPU_PXA
37 #include <asm/byteorder.h>
40 #if defined(CONFIG_MPC823)
44 #if defined(CONFIG_ATMEL_LCD)
45 #include <atmel_lcdc.h>
48 #if defined(CONFIG_LCD_DT_SIMPLEFB)
52 /************************************************************************/
54 /************************************************************************/
55 #include <video_font.h> /* Get font data, width and height */
57 /************************************************************************/
59 /************************************************************************/
60 #ifdef CONFIG_LCD_LOGO
61 # include <bmp_logo.h> /* Get logo data, width and height */
62 # include <bmp_logo_data.h>
63 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
64 # error Default Color Map overlaps with Logo Color Map
72 #ifndef CONFIG_LCD_ALIGNMENT
73 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
76 /* By default we scroll by a single line */
77 #ifndef CONFIG_CONSOLE_SCROLL_LINES
78 #define CONFIG_CONSOLE_SCROLL_LINES 1
81 /************************************************************************/
82 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
83 /************************************************************************/
84 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
85 # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
88 # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
91 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
92 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
93 #define CONSOLE_ROW_FIRST lcd_console_address
94 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
95 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
97 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
98 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
100 #if LCD_BPP == LCD_MONOCHROME
101 # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
102 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
103 #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \
104 (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_puts_xy(ushort x, ushort y, uchar *s);
114 static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
116 static int lcd_init(void *lcdbase);
118 static void *lcd_logo(void);
120 static int lcd_getbgcolor(void);
121 static void lcd_setfgcolor(int color);
122 static void lcd_setbgcolor(int color);
124 static int lcd_color_fg;
125 static int lcd_color_bg;
128 char lcd_is_enabled = 0;
130 static short console_col;
131 static short console_row;
133 static void *lcd_console_address;
134 static void *lcd_base; /* Start of framebuffer memory */
136 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
138 /************************************************************************/
140 /* Flush LCD activity to the caches */
144 * flush_dcache_range() is declared in common.h but it seems that some
145 * architectures do not actually implement it. Is there a way to find
146 * out whether it exists? For now, ARM is safe.
148 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
151 if (lcd_flush_dcache)
152 flush_dcache_range((u32)lcd_base,
153 (u32)(lcd_base + lcd_get_size(&line_length)));
154 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
155 static ulong last_sync;
157 if (get_timer(last_sync) > 10) {
158 sandbox_sdl_sync(lcd_base);
159 last_sync = get_timer(0);
164 void lcd_set_flush_dcache(int flush)
166 lcd_flush_dcache = (flush != 0);
169 /*----------------------------------------------------------------------*/
171 static void console_scrollup(void)
173 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
175 /* Copy up rows ignoring those that will be overwritten */
176 memcpy(CONSOLE_ROW_FIRST,
177 lcd_console_address + CONSOLE_ROW_SIZE * rows,
178 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
180 /* Clear the last rows */
181 #if (LCD_BPP != LCD_COLOR32)
182 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
183 COLOR_MASK(lcd_color_bg),
184 CONSOLE_ROW_SIZE * rows);
186 u32 *ppix = lcd_console_address +
187 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
190 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
192 *ppix++ = COLOR_MASK(lcd_color_bg);
199 /*----------------------------------------------------------------------*/
201 static inline void console_back(void)
203 if (--console_col < 0) {
204 console_col = CONSOLE_COLS-1 ;
205 if (--console_row < 0)
209 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
210 console_row * VIDEO_FONT_HEIGHT, ' ');
213 /*----------------------------------------------------------------------*/
215 static inline void console_newline(void)
219 /* Check if we need to scroll the terminal */
220 if (++console_row >= CONSOLE_ROWS)
226 /*----------------------------------------------------------------------*/
228 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
233 void lcd_putc(const char c)
235 if (!lcd_is_enabled) {
250 case '\t': /* Tab (8 chars alignment) */
254 if (console_col >= CONSOLE_COLS)
263 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
264 console_row * VIDEO_FONT_HEIGHT, c);
265 if (++console_col >= CONSOLE_COLS)
270 /*----------------------------------------------------------------------*/
272 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
277 void lcd_puts(const char *s)
279 if (!lcd_is_enabled) {
291 /*----------------------------------------------------------------------*/
293 void lcd_printf(const char *fmt, ...)
296 char buf[CONFIG_SYS_PBSIZE];
299 vsprintf(buf, fmt, args);
305 /************************************************************************/
306 /* ** Low-Level Graphics Routines */
307 /************************************************************************/
309 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
314 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
315 y += BMP_LOGO_HEIGHT;
318 #if LCD_BPP == LCD_MONOCHROME
319 ushort off = x * (1 << LCD_BPP) % 8;
322 dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8);
324 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
327 #if LCD_BPP == LCD_COLOR16
328 ushort *d = (ushort *)dest;
329 #elif LCD_BPP == LCD_COLOR32
330 u32 *d = (u32 *)dest;
335 #if LCD_BPP == LCD_MONOCHROME
336 uchar rest = *d & -(1 << (8 - off));
339 for (i = 0; i < count; ++i) {
343 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
345 #if LCD_BPP == LCD_MONOCHROME
346 sym = (COLOR_MASK(lcd_color_fg) & bits) |
347 (COLOR_MASK(lcd_color_bg) & ~bits);
349 *d++ = rest | (sym >> off);
350 rest = sym << (8-off);
351 #elif LCD_BPP == LCD_COLOR8
352 for (c = 0; c < 8; ++c) {
353 *d++ = (bits & 0x80) ?
354 lcd_color_fg : lcd_color_bg;
357 #elif LCD_BPP == LCD_COLOR16
358 for (c = 0; c < 8; ++c) {
359 *d++ = (bits & 0x80) ?
360 lcd_color_fg : lcd_color_bg;
363 #elif LCD_BPP == LCD_COLOR32
364 for (c = 0; c < 8; ++c) {
365 *d++ = (bits & 0x80) ?
366 lcd_color_fg : lcd_color_bg;
371 #if LCD_BPP == LCD_MONOCHROME
372 *d = rest | (*d & ((1 << (8 - off)) - 1));
377 /*----------------------------------------------------------------------*/
379 static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
381 lcd_drawchars(x, y, s, strlen((char *)s));
384 /*----------------------------------------------------------------------*/
386 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
388 lcd_drawchars(x, y, &c, 1);
391 /************************************************************************/
392 /** Small utility to check that you got the colours right */
393 /************************************************************************/
394 #ifdef LCD_TEST_PATTERN
399 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
400 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
401 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
404 static void test_pattern(void)
406 ushort v_max = panel_info.vl_row;
407 ushort h_max = panel_info.vl_col;
408 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
409 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
411 uchar *pix = (uchar *)lcd_base;
413 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
414 h_max, v_max, h_step, v_step);
416 /* WARNING: Code silently assumes 8bit/pixel */
417 for (v = 0; v < v_max; ++v) {
418 uchar iy = v / v_step;
419 for (h = 0; h < h_max; ++h) {
420 uchar ix = N_BLK_HOR * iy + h / h_step;
421 *pix++ = test_colors[ix];
425 #endif /* LCD_TEST_PATTERN */
428 /************************************************************************/
429 /* ** GENERIC Initialization Routines */
430 /************************************************************************/
432 * With most lcd drivers the line length is set up
433 * by calculating it from panel_info parameters. Some
434 * drivers need to calculate the line length differently,
435 * so make the function weak to allow overriding it.
437 __weak int lcd_get_size(int *line_length)
439 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
440 return *line_length * panel_info.vl_row;
443 int drv_lcd_init(void)
445 struct stdio_dev lcddev;
448 lcd_base = map_sysmem(gd->fb_base, 0);
450 lcd_init(lcd_base); /* LCD initialization */
452 /* Device initialization */
453 memset(&lcddev, 0, sizeof(lcddev));
455 strcpy(lcddev.name, "lcd");
456 lcddev.ext = 0; /* No extensions */
457 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
458 lcddev.putc = lcd_stub_putc; /* 'putc' function */
459 lcddev.puts = lcd_stub_puts; /* 'puts' function */
461 rc = stdio_register(&lcddev);
463 return (rc == 0) ? 1 : rc;
466 /*----------------------------------------------------------------------*/
469 #if LCD_BPP == LCD_MONOCHROME
470 /* Setting the palette */
473 #elif LCD_BPP == LCD_COLOR8
474 /* Setting the palette */
475 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
476 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
477 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
478 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
479 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
480 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
481 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
482 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
483 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
486 #ifndef CONFIG_SYS_WHITE_ON_BLACK
487 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
488 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
490 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
491 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
492 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
494 #ifdef LCD_TEST_PATTERN
497 /* set framebuffer to background color */
498 #if (LCD_BPP != LCD_COLOR32)
499 memset((char *)lcd_base,
500 COLOR_MASK(lcd_getbgcolor()),
501 lcd_line_length * panel_info.vl_row);
503 u32 *ppix = lcd_base;
506 i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
508 *ppix++ = COLOR_MASK(lcd_color_bg);
512 /* Paint the logo and retrieve LCD base address */
513 debug("[LCD] Drawing the logo...\n");
514 lcd_console_address = lcd_logo();
521 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
529 cls, 1, 1, do_lcd_clear,
534 /*----------------------------------------------------------------------*/
536 static int lcd_init(void *lcdbase)
538 /* Initialize the lcd controller */
539 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
541 lcd_ctrl_init(lcdbase);
544 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
545 * the 'lcdbase' argument and uses custom lcd base address
546 * by setting up gd->fb_base. Check for this condition and fixup
547 * 'lcd_base' address.
549 if (map_to_sysmem(lcdbase) != gd->fb_base)
550 lcd_base = map_sysmem(gd->fb_base, 0);
552 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
554 lcd_get_size(&lcd_line_length);
559 /* Initialize the console */
561 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
562 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
564 console_row = 1; /* leave 1 blank line below logo */
571 /************************************************************************/
572 /* ** ROM capable initialization part - needed to reserve FB memory */
573 /************************************************************************/
575 * This is called early in the system initialization to grab memory
576 * for the LCD controller.
577 * Returns new address for monitor, after reserving LCD buffer memory
579 * Note that this is running from ROM, so no write access to global data.
581 ulong lcd_setmem(ulong addr)
586 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
587 panel_info.vl_row, NBITS(panel_info.vl_bpix));
589 size = lcd_get_size(&line_length);
591 /* Round up to nearest full page, or MMU section if defined */
592 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
593 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
595 /* Allocate pages for the frame buffer. */
598 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
604 /*----------------------------------------------------------------------*/
606 static void lcd_setfgcolor(int color)
608 lcd_color_fg = color;
611 /*----------------------------------------------------------------------*/
613 static void lcd_setbgcolor(int color)
615 lcd_color_bg = color;
618 /*----------------------------------------------------------------------*/
620 int lcd_getfgcolor(void)
625 /*----------------------------------------------------------------------*/
627 static int lcd_getbgcolor(void)
632 /************************************************************************/
633 /* ** Chipset depending Bitmap / Logo stuff... */
634 /************************************************************************/
635 static inline ushort *configuration_get_cmap(void)
637 #if defined CONFIG_CPU_PXA
638 struct pxafb_info *fbi = &panel_info.pxa;
639 return (ushort *)fbi->palette;
640 #elif defined(CONFIG_MPC823)
641 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
642 cpm8xx_t *cp = &(immr->im_cpm);
643 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
644 #elif defined(CONFIG_ATMEL_LCD)
645 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
646 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
647 return panel_info.cmap;
648 #elif defined(CONFIG_LCD_LOGO)
649 return bmp_logo_palette;
655 #ifdef CONFIG_LCD_LOGO
656 void bitmap_plot(int x, int y)
658 #ifdef CONFIG_ATMEL_LCD
659 uint *cmap = (uint *)bmp_logo_palette;
661 ushort *cmap = (ushort *)bmp_logo_palette;
667 #if defined(CONFIG_MPC823)
668 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
669 cpm8xx_t *cp = &(immr->im_cpm);
671 unsigned bpix = NBITS(panel_info.vl_bpix);
673 debug("Logo: width %d height %d colors %d cmap %d\n",
674 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
675 ARRAY_SIZE(bmp_logo_palette));
677 bmap = &bmp_logo_bitmap[0];
678 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
681 /* Leave room for default color map
682 * default case: generic system with no cmap (most likely 16bpp)
683 * cmap was set to the source palette, so no change is done.
684 * This avoids even more ifdefs in the next stanza
686 #if defined(CONFIG_MPC823)
687 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
688 #elif defined(CONFIG_ATMEL_LCD)
689 cmap = (uint *)configuration_get_cmap();
691 cmap = configuration_get_cmap();
697 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
698 ushort colreg = bmp_logo_palette[i];
699 #ifdef CONFIG_ATMEL_LCD
701 #ifdef CONFIG_ATMEL_LCD_BGR555
702 lut_entry = ((colreg & 0x000F) << 11) |
703 ((colreg & 0x00F0) << 2) |
704 ((colreg & 0x0F00) >> 7);
705 #else /* CONFIG_ATMEL_LCD_RGB565 */
706 lut_entry = ((colreg & 0x000F) << 1) |
707 ((colreg & 0x00F0) << 3) |
708 ((colreg & 0x0F00) << 4);
710 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
712 #else /* !CONFIG_ATMEL_LCD */
713 #ifdef CONFIG_SYS_INVERT_COLORS
714 *cmap++ = 0xffff - colreg;
718 #endif /* CONFIG_ATMEL_LCD */
723 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
724 memcpy(fb, bmap, BMP_LOGO_WIDTH);
725 bmap += BMP_LOGO_WIDTH;
726 fb += panel_info.vl_col;
729 else { /* true color mode */
732 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
733 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
734 col16 = bmp_logo_palette[(bmap[j]-16)];
736 ((col16 & 0x000F) << 1) |
737 ((col16 & 0x00F0) << 3) |
738 ((col16 & 0x0F00) << 4);
740 bmap += BMP_LOGO_WIDTH;
741 fb16 += panel_info.vl_col;
749 static inline void bitmap_plot(int x, int y) {}
750 #endif /* CONFIG_LCD_LOGO */
752 /*----------------------------------------------------------------------*/
753 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
755 * Display the BMP file located at address bmp_image.
759 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
760 #define BMP_ALIGN_CENTER 0x7FFF
762 static void splash_align_axis(int *axis, unsigned long panel_size,
763 unsigned long picture_size)
765 unsigned long panel_picture_delta = panel_size - picture_size;
766 unsigned long axis_alignment;
768 if (*axis == BMP_ALIGN_CENTER)
769 axis_alignment = panel_picture_delta / 2;
771 axis_alignment = panel_picture_delta + *axis + 1;
775 *axis = max(0, axis_alignment);
780 #ifdef CONFIG_LCD_BMP_RLE8
782 #define BMP_RLE8_ESCAPE 0
783 #define BMP_RLE8_EOL 0
784 #define BMP_RLE8_EOBMP 1
785 #define BMP_RLE8_DELTA 2
787 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
791 *(*fbp)++ = cmap[*bmap++];
796 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
799 int cnt_8copy = cnt >> 3;
801 cnt -= cnt_8copy << 3;
802 while (cnt_8copy > 0) {
821 * Do not call this function directly, must be called from lcd_display_bitmap.
823 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
824 int x_off, int y_off)
832 width = get_unaligned_le32(&bmp->header.width);
833 height = get_unaligned_le32(&bmp->header.height);
834 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
840 if (bmap[0] == BMP_RLE8_ESCAPE) {
847 /* 16bpix, 2-byte per pixel, width should *2 */
848 fb -= (width * 2 + lcd_line_length);
858 /* 16bpix, 2-byte per pixel, x should *2 */
859 fb = (uchar *) (lcd_base + (y + y_off - 1)
860 * lcd_line_length + (x + x_off) * 2);
869 if (x + runlen > width)
873 draw_unencoded_bitmap(
888 /* aggregate the same code */
889 while (bmap[0] == 0xff &&
890 bmap[2] != BMP_RLE8_ESCAPE &&
891 bmap[1] == bmap[3]) {
895 if (x + runlen > width)
899 draw_encoded_bitmap((ushort **)&fb,
910 #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
911 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
913 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
916 #if defined(CONFIG_BMP_16BPP)
917 #if defined(CONFIG_ATMEL_LCD_BGR555)
918 static inline void fb_put_word(uchar **fb, uchar **from)
920 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
921 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
925 static inline void fb_put_word(uchar **fb, uchar **from)
927 *(*fb)++ = *(*from)++;
928 *(*fb)++ = *(*from)++;
931 #endif /* CONFIG_BMP_16BPP */
933 int lcd_display_bitmap(ulong bmp_image, int x, int y)
935 #if !defined(CONFIG_MCC200)
938 ushort *cmap_base = NULL;
941 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
944 unsigned long width, height, byte_width;
945 unsigned long pwidth = panel_info.vl_col;
946 unsigned colors, bpix, bmp_bpix;
948 if (!bmp || !(bmp->header.signature[0] == 'B' &&
949 bmp->header.signature[1] == 'M')) {
950 printf("Error: no valid bmp image at %lx\n", bmp_image);
955 width = get_unaligned_le32(&bmp->header.width);
956 height = get_unaligned_le32(&bmp->header.height);
957 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
959 colors = 1 << bmp_bpix;
961 bpix = NBITS(panel_info.vl_bpix);
963 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
964 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
970 /* We support displaying 8bpp BMPs on 16bpp LCDs */
971 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
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: %d x %d with %d colors\n",
978 (int)width, (int)height, (int)colors);
980 #if !defined(CONFIG_MCC200)
981 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
983 cmap = configuration_get_cmap();
987 for (i = 0; i < colors; ++i) {
988 bmp_color_table_entry_t cte = bmp->color_table[i];
989 #if !defined(CONFIG_ATMEL_LCD)
991 ( ((cte.red) << 8) & 0xf800) |
992 ( ((cte.green) << 3) & 0x07e0) |
993 ( ((cte.blue) >> 3) & 0x001f) ;
994 #ifdef CONFIG_SYS_INVERT_COLORS
995 *cmap = 0xffff - colreg;
999 #if defined(CONFIG_MPC823)
1004 #else /* CONFIG_ATMEL_LCD */
1005 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
1011 * BMP format for Monochrome assumes that the state of a
1012 * pixel is described on a per Bit basis, not per Byte.
1013 * So, in case of Monochrome BMP we should align widths
1014 * on a byte boundary and convert them from Bit to Byte
1016 * Probably, PXA250 and MPC823 process 1bpp BMP images in
1017 * their own ways, so make the converting to be MCC200
1020 #if defined(CONFIG_MCC200)
1022 width = ((width + 7) & ~7) >> 3;
1023 x = ((x + 7) & ~7) >> 3;
1024 pwidth= ((pwidth + 7) & ~7) >> 3;
1028 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
1030 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1031 splash_align_axis(&x, pwidth, width);
1032 splash_align_axis(&y, panel_info.vl_row, height);
1033 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1035 if ((x + width) > pwidth)
1037 if ((y + height) > panel_info.vl_row)
1038 height = panel_info.vl_row - y;
1040 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
1041 fb = (uchar *)(lcd_base +
1042 (y + height - 1) * lcd_line_length + x * bpix / 8);
1045 case 1: /* pass through */
1047 #ifdef CONFIG_LCD_BMP_RLE8
1048 u32 compression = get_unaligned_le32(&bmp->header.compression);
1049 if (compression == BMP_BI_RLE8) {
1051 /* TODO implement render code for bpix != 16 */
1052 printf("Error: only support 16 bpix");
1055 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1063 byte_width = width * 2;
1065 for (i = 0; i < height; ++i) {
1067 for (j = 0; j < width; j++) {
1069 FB_PUT_BYTE(fb, bmap);
1071 *(uint16_t *)fb = cmap_base[*(bmap++)];
1072 fb += sizeof(uint16_t) / sizeof(*fb);
1075 bmap += (padded_width - width);
1076 fb -= byte_width + lcd_line_length;
1080 #if defined(CONFIG_BMP_16BPP)
1082 for (i = 0; i < height; ++i) {
1084 for (j = 0; j < width; j++)
1085 fb_put_word(&fb, &bmap);
1087 bmap += (padded_width - width) * 2;
1088 fb -= width * 2 + lcd_line_length;
1091 #endif /* CONFIG_BMP_16BPP */
1093 #if defined(CONFIG_BMP_32BPP)
1095 for (i = 0; i < height; ++i) {
1096 for (j = 0; j < width; j++) {
1097 *(fb++) = *(bmap++);
1098 *(fb++) = *(bmap++);
1099 *(fb++) = *(bmap++);
1100 *(fb++) = *(bmap++);
1102 fb -= lcd_line_length + width * (bpix / 8);
1105 #endif /* CONFIG_BMP_32BPP */
1115 static void *lcd_logo(void)
1117 #ifdef CONFIG_SPLASH_SCREEN
1120 static int do_splash = 1;
1122 if (do_splash && (s = getenv("splashimage")) != NULL) {
1126 if (splash_screen_prepare())
1127 return (void *)lcd_base;
1129 addr = simple_strtoul (s, NULL, 16);
1131 splash_get_pos(&x, &y);
1133 if (bmp_display(addr, x, y) == 0)
1134 return (void *)lcd_base;
1136 #endif /* CONFIG_SPLASH_SCREEN */
1140 #ifdef CONFIG_LCD_INFO
1141 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1142 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1143 lcd_show_board_info();
1144 #endif /* CONFIG_LCD_INFO */
1146 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1147 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
1149 return (void *)lcd_base;
1150 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1153 #ifdef CONFIG_SPLASHIMAGE_GUARD
1154 static int on_splashimage(const char *name, const char *value, enum env_op op,
1160 if (op == env_op_delete)
1163 addr = simple_strtoul(value, NULL, 16);
1164 /* See README.displaying-bmps */
1165 aligned = (addr % 4 == 2);
1167 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1174 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1177 void lcd_position_cursor(unsigned col, unsigned row)
1179 console_col = min(col, CONSOLE_COLS - 1);
1180 console_row = min(row, CONSOLE_ROWS - 1);
1183 int lcd_get_pixel_width(void)
1185 return panel_info.vl_col;
1188 int lcd_get_pixel_height(void)
1190 return panel_info.vl_row;
1193 int lcd_get_screen_rows(void)
1195 return CONSOLE_ROWS;
1198 int lcd_get_screen_columns(void)
1200 return CONSOLE_COLS;
1203 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1204 static int lcd_dt_simplefb_configure_node(void *blob, int off)
1209 static const char format[] =
1210 #if LCD_BPP == LCD_COLOR16
1219 stride = panel_info.vl_col * 2;
1221 cells[0] = cpu_to_fdt32(gd->fb_base);
1222 cells[1] = cpu_to_fdt32(stride * panel_info.vl_row);
1223 ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2);
1227 cells[0] = cpu_to_fdt32(panel_info.vl_col);
1228 ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0]));
1232 cells[0] = cpu_to_fdt32(panel_info.vl_row);
1233 ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0]));
1237 cells[0] = cpu_to_fdt32(stride);
1238 ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0]));
1242 ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1);
1246 ret = fdt_delprop(blob, off, "status");
1253 int lcd_dt_simplefb_add_node(void *blob)
1255 static const char compat[] = "simple-framebuffer";
1256 static const char disabled[] = "disabled";
1259 off = fdt_add_subnode(blob, 0, "framebuffer");
1263 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1267 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1271 return lcd_dt_simplefb_configure_node(blob, off);
1274 int lcd_dt_simplefb_enable_existing_node(void *blob)
1278 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1282 return lcd_dt_simplefb_configure_node(blob, off);