2 * Common LCD routines for supported CPUs
4 * (C) Copyright 2001-2002
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /************************************************************************/
28 /************************************************************************/
37 #include <env_callback.h>
38 #include <linux/types.h>
39 #include <stdio_dev.h>
40 #if defined(CONFIG_POST)
48 #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
49 defined(CONFIG_CPU_MONAHANS)
50 #define CONFIG_CPU_PXA
51 #include <asm/byteorder.h>
54 #if defined(CONFIG_MPC823)
58 #if defined(CONFIG_ATMEL_LCD)
59 #include <atmel_lcdc.h>
62 #if defined(CONFIG_LCD_DT_SIMPLEFB)
66 /************************************************************************/
68 /************************************************************************/
69 #include <video_font.h> /* Get font data, width and height */
70 #include <video_font_data.h>
72 /************************************************************************/
74 /************************************************************************/
75 #ifdef CONFIG_LCD_LOGO
76 # include <bmp_logo.h> /* Get logo data, width and height */
77 # include <bmp_logo_data.h>
78 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
79 # error Default Color Map overlaps with Logo Color Map
83 #ifndef CONFIG_LCD_ALIGNMENT
84 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
87 /* By default we scroll by a single line */
88 #ifndef CONFIG_CONSOLE_SCROLL_LINES
89 #define CONFIG_CONSOLE_SCROLL_LINES 1
92 /************************************************************************/
93 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
94 /************************************************************************/
95 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
96 # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
99 # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
102 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
103 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
104 #define CONSOLE_ROW_FIRST lcd_console_address
105 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
106 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
108 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
109 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
111 #if LCD_BPP == LCD_MONOCHROME
112 # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
113 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
114 #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
115 # define COLOR_MASK(c) (c)
117 # error Unsupported LCD BPP.
120 DECLARE_GLOBAL_DATA_PTR;
122 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
123 static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
124 static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
126 static int lcd_init(void *lcdbase);
128 static void *lcd_logo(void);
130 static int lcd_getbgcolor(void);
131 static void lcd_setfgcolor(int color);
132 static void lcd_setbgcolor(int color);
134 static int lcd_color_fg;
135 static int lcd_color_bg;
138 char lcd_is_enabled = 0;
140 static short console_col;
141 static short console_row;
143 static void *lcd_console_address;
144 static void *lcd_base; /* Start of framebuffer memory */
146 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
148 /************************************************************************/
150 /* Flush LCD activity to the caches */
154 * flush_dcache_range() is declared in common.h but it seems that some
155 * architectures do not actually implement it. Is there a way to find
156 * out whether it exists? For now, ARM is safe.
158 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
161 if (lcd_flush_dcache)
162 flush_dcache_range((u32)lcd_base,
163 (u32)(lcd_base + lcd_get_size(&line_length)));
167 void lcd_set_flush_dcache(int flush)
169 lcd_flush_dcache = (flush != 0);
172 /*----------------------------------------------------------------------*/
174 static void console_scrollup(void)
176 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
178 /* Copy up rows ignoring those that will be overwritten */
179 memcpy(CONSOLE_ROW_FIRST,
180 lcd_console_address + CONSOLE_ROW_SIZE * rows,
181 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
183 /* Clear the last rows */
184 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
185 COLOR_MASK(lcd_color_bg),
186 CONSOLE_ROW_SIZE * rows);
192 /*----------------------------------------------------------------------*/
194 static inline void console_back(void)
196 if (--console_col < 0) {
197 console_col = CONSOLE_COLS-1 ;
198 if (--console_row < 0)
202 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
203 console_row * VIDEO_FONT_HEIGHT, ' ');
206 /*----------------------------------------------------------------------*/
208 static inline void console_newline(void)
212 /* Check if we need to scroll the terminal */
213 if (++console_row >= CONSOLE_ROWS)
219 /*----------------------------------------------------------------------*/
221 void lcd_putc(const char c)
223 if (!lcd_is_enabled) {
238 case '\t': /* Tab (8 chars alignment) */
242 if (console_col >= CONSOLE_COLS)
251 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
252 console_row * VIDEO_FONT_HEIGHT, c);
253 if (++console_col >= CONSOLE_COLS)
258 /*----------------------------------------------------------------------*/
260 void lcd_puts(const char *s)
262 if (!lcd_is_enabled) {
274 /*----------------------------------------------------------------------*/
276 void lcd_printf(const char *fmt, ...)
279 char buf[CONFIG_SYS_PBSIZE];
282 vsprintf(buf, fmt, args);
288 /************************************************************************/
289 /* ** Low-Level Graphics Routines */
290 /************************************************************************/
292 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
297 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
298 y += BMP_LOGO_HEIGHT;
301 #if LCD_BPP == LCD_MONOCHROME
302 ushort off = x * (1 << LCD_BPP) % 8;
305 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
307 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
310 #if LCD_BPP == LCD_COLOR16
311 ushort *d = (ushort *)dest;
316 #if LCD_BPP == LCD_MONOCHROME
317 uchar rest = *d & -(1 << (8 - off));
320 for (i = 0; i < count; ++i) {
324 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
326 #if LCD_BPP == LCD_MONOCHROME
327 sym = (COLOR_MASK(lcd_color_fg) & bits) |
328 (COLOR_MASK(lcd_color_bg) & ~bits);
330 *d++ = rest | (sym >> off);
331 rest = sym << (8-off);
332 #elif LCD_BPP == LCD_COLOR8
333 for (c = 0; c < 8; ++c) {
334 *d++ = (bits & 0x80) ?
335 lcd_color_fg : lcd_color_bg;
338 #elif LCD_BPP == LCD_COLOR16
339 for (c = 0; c < 8; ++c) {
340 *d++ = (bits & 0x80) ?
341 lcd_color_fg : lcd_color_bg;
346 #if LCD_BPP == LCD_MONOCHROME
347 *d = rest | (*d & ((1 << (8 - off)) - 1));
352 /*----------------------------------------------------------------------*/
354 static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
356 lcd_drawchars(x, y, s, strlen((char *)s));
359 /*----------------------------------------------------------------------*/
361 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
363 lcd_drawchars(x, y, &c, 1);
366 /************************************************************************/
367 /** Small utility to check that you got the colours right */
368 /************************************************************************/
369 #ifdef LCD_TEST_PATTERN
374 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
375 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
376 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
379 static void test_pattern(void)
381 ushort v_max = panel_info.vl_row;
382 ushort h_max = panel_info.vl_col;
383 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
384 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
386 uchar *pix = (uchar *)lcd_base;
388 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
389 h_max, v_max, h_step, v_step);
391 /* WARNING: Code silently assumes 8bit/pixel */
392 for (v = 0; v < v_max; ++v) {
393 uchar iy = v / v_step;
394 for (h = 0; h < h_max; ++h) {
395 uchar ix = N_BLK_HOR * iy + h / h_step;
396 *pix++ = test_colors[ix];
400 #endif /* LCD_TEST_PATTERN */
403 /************************************************************************/
404 /* ** GENERIC Initialization Routines */
405 /************************************************************************/
407 int lcd_get_size(int *line_length)
409 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
410 return *line_length * panel_info.vl_row;
413 int drv_lcd_init(void)
415 struct stdio_dev lcddev;
418 lcd_base = (void *) gd->fb_base;
420 lcd_init(lcd_base); /* LCD initialization */
422 /* Device initialization */
423 memset(&lcddev, 0, sizeof(lcddev));
425 strcpy(lcddev.name, "lcd");
426 lcddev.ext = 0; /* No extensions */
427 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
428 lcddev.putc = lcd_putc; /* 'putc' function */
429 lcddev.puts = lcd_puts; /* 'puts' function */
431 rc = stdio_register(&lcddev);
433 return (rc == 0) ? 1 : rc;
436 /*----------------------------------------------------------------------*/
439 #if LCD_BPP == LCD_MONOCHROME
440 /* Setting the palette */
443 #elif LCD_BPP == LCD_COLOR8
444 /* Setting the palette */
445 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
446 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
447 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
448 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
449 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
450 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
451 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
452 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
453 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
456 #ifndef CONFIG_SYS_WHITE_ON_BLACK
457 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
458 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
460 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
461 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
462 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
464 #ifdef LCD_TEST_PATTERN
467 /* set framebuffer to background color */
468 memset((char *)lcd_base,
469 COLOR_MASK(lcd_getbgcolor()),
470 lcd_line_length * panel_info.vl_row);
472 /* Paint the logo and retrieve LCD base address */
473 debug("[LCD] Drawing the logo...\n");
474 lcd_console_address = lcd_logo();
481 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
489 cls, 1, 1, do_lcd_clear,
494 /*----------------------------------------------------------------------*/
496 static int lcd_init(void *lcdbase)
498 /* Initialize the lcd controller */
499 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
501 lcd_ctrl_init(lcdbase);
504 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
505 * the 'lcdbase' argument and uses custom lcd base address
506 * by setting up gd->fb_base. Check for this condition and fixup
507 * 'lcd_base' address.
509 if ((unsigned long)lcdbase != gd->fb_base)
510 lcd_base = (void *)gd->fb_base;
512 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
514 lcd_get_size(&lcd_line_length);
515 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
520 /* Initialize the console */
522 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
523 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
525 console_row = 1; /* leave 1 blank line below logo */
532 /************************************************************************/
533 /* ** ROM capable initialization part - needed to reserve FB memory */
534 /************************************************************************/
536 * This is called early in the system initialization to grab memory
537 * for the LCD controller.
538 * Returns new address for monitor, after reserving LCD buffer memory
540 * Note that this is running from ROM, so no write access to global data.
542 ulong lcd_setmem(ulong addr)
547 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
548 panel_info.vl_row, NBITS(panel_info.vl_bpix));
550 size = lcd_get_size(&line_length);
552 /* Round up to nearest full page, or MMU section if defined */
553 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
554 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
556 /* Allocate pages for the frame buffer. */
559 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
565 /*----------------------------------------------------------------------*/
567 static void lcd_setfgcolor(int color)
569 lcd_color_fg = color;
572 /*----------------------------------------------------------------------*/
574 static void lcd_setbgcolor(int color)
576 lcd_color_bg = color;
579 /*----------------------------------------------------------------------*/
581 int lcd_getfgcolor(void)
586 /*----------------------------------------------------------------------*/
588 static int lcd_getbgcolor(void)
593 /************************************************************************/
594 /* ** Chipset depending Bitmap / Logo stuff... */
595 /************************************************************************/
596 static inline ushort *configuration_get_cmap(void)
598 #if defined CONFIG_CPU_PXA
599 struct pxafb_info *fbi = &panel_info.pxa;
600 return (ushort *)fbi->palette;
601 #elif defined(CONFIG_MPC823)
602 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
603 cpm8xx_t *cp = &(immr->im_cpm);
604 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
605 #elif defined(CONFIG_ATMEL_LCD)
606 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
607 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
608 return panel_info.cmap;
609 #elif defined(CONFIG_LCD_LOGO)
610 return bmp_logo_palette;
616 #ifdef CONFIG_LCD_LOGO
617 void bitmap_plot(int x, int y)
619 #ifdef CONFIG_ATMEL_LCD
620 uint *cmap = (uint *)bmp_logo_palette;
622 ushort *cmap = (ushort *)bmp_logo_palette;
628 #if defined(CONFIG_MPC823)
629 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
630 cpm8xx_t *cp = &(immr->im_cpm);
632 unsigned bpix = NBITS(panel_info.vl_bpix);
634 debug("Logo: width %d height %d colors %d cmap %d\n",
635 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
636 ARRAY_SIZE(bmp_logo_palette));
638 bmap = &bmp_logo_bitmap[0];
639 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
642 /* Leave room for default color map
643 * default case: generic system with no cmap (most likely 16bpp)
644 * cmap was set to the source palette, so no change is done.
645 * This avoids even more ifdefs in the next stanza
647 #if defined(CONFIG_MPC823)
648 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
649 #elif defined(CONFIG_ATMEL_LCD)
650 cmap = (uint *)configuration_get_cmap();
652 cmap = configuration_get_cmap();
658 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
659 ushort colreg = bmp_logo_palette[i];
660 #ifdef CONFIG_ATMEL_LCD
662 #ifdef CONFIG_ATMEL_LCD_BGR555
663 lut_entry = ((colreg & 0x000F) << 11) |
664 ((colreg & 0x00F0) << 2) |
665 ((colreg & 0x0F00) >> 7);
666 #else /* CONFIG_ATMEL_LCD_RGB565 */
667 lut_entry = ((colreg & 0x000F) << 1) |
668 ((colreg & 0x00F0) << 3) |
669 ((colreg & 0x0F00) << 4);
671 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
673 #else /* !CONFIG_ATMEL_LCD */
674 #ifdef CONFIG_SYS_INVERT_COLORS
675 *cmap++ = 0xffff - colreg;
679 #endif /* CONFIG_ATMEL_LCD */
684 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
685 memcpy(fb, bmap, BMP_LOGO_WIDTH);
686 bmap += BMP_LOGO_WIDTH;
687 fb += panel_info.vl_col;
690 else { /* true color mode */
693 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
694 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
695 col16 = bmp_logo_palette[(bmap[j]-16)];
697 ((col16 & 0x000F) << 1) |
698 ((col16 & 0x00F0) << 3) |
699 ((col16 & 0x0F00) << 4);
701 bmap += BMP_LOGO_WIDTH;
702 fb16 += panel_info.vl_col;
710 static inline void bitmap_plot(int x, int y) {}
711 #endif /* CONFIG_LCD_LOGO */
713 /*----------------------------------------------------------------------*/
714 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
716 * Display the BMP file located at address bmp_image.
720 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
721 #define BMP_ALIGN_CENTER 0x7FFF
723 static void splash_align_axis(int *axis, unsigned long panel_size,
724 unsigned long picture_size)
726 unsigned long panel_picture_delta = panel_size - picture_size;
727 unsigned long axis_alignment;
729 if (*axis == BMP_ALIGN_CENTER)
730 axis_alignment = panel_picture_delta / 2;
732 axis_alignment = panel_picture_delta + *axis + 1;
736 *axis = max(0, axis_alignment);
741 #ifdef CONFIG_LCD_BMP_RLE8
743 #define BMP_RLE8_ESCAPE 0
744 #define BMP_RLE8_EOL 0
745 #define BMP_RLE8_EOBMP 1
746 #define BMP_RLE8_DELTA 2
748 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
752 *(*fbp)++ = cmap[*bmap++];
757 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
760 int cnt_8copy = cnt >> 3;
762 cnt -= cnt_8copy << 3;
763 while (cnt_8copy > 0) {
782 * Do not call this function directly, must be called from lcd_display_bitmap.
784 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
785 int x_off, int y_off)
793 width = le32_to_cpu(bmp->header.width);
794 height = le32_to_cpu(bmp->header.height);
795 bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
801 if (bmap[0] == BMP_RLE8_ESCAPE) {
808 /* 16bpix, 2-byte per pixel, width should *2 */
809 fb -= (width * 2 + lcd_line_length);
819 /* 16bpix, 2-byte per pixel, x should *2 */
820 fb = (uchar *) (lcd_base + (y + y_off - 1)
821 * lcd_line_length + (x + x_off) * 2);
830 if (x + runlen > width)
834 draw_unencoded_bitmap(
849 /* aggregate the same code */
850 while (bmap[0] == 0xff &&
851 bmap[2] != BMP_RLE8_ESCAPE &&
852 bmap[1] == bmap[3]) {
856 if (x + runlen > width)
860 draw_encoded_bitmap((ushort **)&fb,
871 #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
872 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
874 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
877 #if defined(CONFIG_BMP_16BPP)
878 #if defined(CONFIG_ATMEL_LCD_BGR555)
879 static inline void fb_put_word(uchar **fb, uchar **from)
881 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
882 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
886 static inline void fb_put_word(uchar **fb, uchar **from)
888 *(*fb)++ = *(*from)++;
889 *(*fb)++ = *(*from)++;
892 #endif /* CONFIG_BMP_16BPP */
894 int lcd_display_bitmap(ulong bmp_image, int x, int y)
896 #if !defined(CONFIG_MCC200)
899 ushort *cmap_base = NULL;
902 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
905 unsigned long width, height, byte_width;
906 unsigned long pwidth = panel_info.vl_col;
907 unsigned colors, bpix, bmp_bpix;
909 if (!bmp || !(bmp->header.signature[0] == 'B' &&
910 bmp->header.signature[1] == 'M')) {
911 printf("Error: no valid bmp image at %lx\n", bmp_image);
916 width = le32_to_cpu(bmp->header.width);
917 height = le32_to_cpu(bmp->header.height);
918 bmp_bpix = le16_to_cpu(bmp->header.bit_count);
919 colors = 1 << bmp_bpix;
921 bpix = NBITS(panel_info.vl_bpix);
923 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
924 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
930 /* We support displaying 8bpp BMPs on 16bpp LCDs */
931 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
932 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
934 le16_to_cpu(bmp->header.bit_count));
939 debug("Display-bmp: %d x %d with %d colors\n",
940 (int)width, (int)height, (int)colors);
942 #if !defined(CONFIG_MCC200)
943 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
945 cmap = configuration_get_cmap();
949 for (i = 0; i < colors; ++i) {
950 bmp_color_table_entry_t cte = bmp->color_table[i];
951 #if !defined(CONFIG_ATMEL_LCD)
953 ( ((cte.red) << 8) & 0xf800) |
954 ( ((cte.green) << 3) & 0x07e0) |
955 ( ((cte.blue) >> 3) & 0x001f) ;
956 #ifdef CONFIG_SYS_INVERT_COLORS
957 *cmap = 0xffff - colreg;
961 #if defined(CONFIG_MPC823)
966 #else /* CONFIG_ATMEL_LCD */
967 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
974 * BMP format for Monochrome assumes that the state of a
975 * pixel is described on a per Bit basis, not per Byte.
976 * So, in case of Monochrome BMP we should align widths
977 * on a byte boundary and convert them from Bit to Byte
979 * Probably, PXA250 and MPC823 process 1bpp BMP images in
980 * their own ways, so make the converting to be MCC200
983 #if defined(CONFIG_MCC200)
985 width = ((width + 7) & ~7) >> 3;
986 x = ((x + 7) & ~7) >> 3;
987 pwidth= ((pwidth + 7) & ~7) >> 3;
991 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
993 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
994 splash_align_axis(&x, pwidth, width);
995 splash_align_axis(&y, panel_info.vl_row, height);
996 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
998 if ((x + width) > pwidth)
1000 if ((y + height) > panel_info.vl_row)
1001 height = panel_info.vl_row - y;
1003 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1004 fb = (uchar *) (lcd_base +
1005 (y + height - 1) * lcd_line_length + x * bpix / 8);
1008 case 1: /* pass through */
1010 #ifdef CONFIG_LCD_BMP_RLE8
1011 if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
1013 /* TODO implement render code for bpix != 16 */
1014 printf("Error: only support 16 bpix");
1017 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1025 byte_width = width * 2;
1027 for (i = 0; i < height; ++i) {
1029 for (j = 0; j < width; j++) {
1031 FB_PUT_BYTE(fb, bmap);
1033 *(uint16_t *)fb = cmap_base[*(bmap++)];
1034 fb += sizeof(uint16_t) / sizeof(*fb);
1037 bmap += (padded_width - width);
1038 fb -= byte_width + lcd_line_length;
1042 #if defined(CONFIG_BMP_16BPP)
1044 for (i = 0; i < height; ++i) {
1046 for (j = 0; j < width; j++)
1047 fb_put_word(&fb, &bmap);
1049 bmap += (padded_width - width) * 2;
1050 fb -= width * 2 + lcd_line_length;
1053 #endif /* CONFIG_BMP_16BPP */
1055 #if defined(CONFIG_BMP_32BPP)
1057 for (i = 0; i < height; ++i) {
1058 for (j = 0; j < width; j++) {
1059 *(fb++) = *(bmap++);
1060 *(fb++) = *(bmap++);
1061 *(fb++) = *(bmap++);
1062 *(fb++) = *(bmap++);
1064 fb -= lcd_line_length + width * (bpix / 8);
1067 #endif /* CONFIG_BMP_32BPP */
1077 static void *lcd_logo(void)
1079 #ifdef CONFIG_SPLASH_SCREEN
1082 static int do_splash = 1;
1084 if (do_splash && (s = getenv("splashimage")) != NULL) {
1088 if (splash_screen_prepare())
1089 return (void *)lcd_base;
1091 addr = simple_strtoul (s, NULL, 16);
1093 splash_get_pos(&x, &y);
1095 if (bmp_display(addr, x, y) == 0)
1096 return (void *)lcd_base;
1098 #endif /* CONFIG_SPLASH_SCREEN */
1102 #ifdef CONFIG_LCD_INFO
1103 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1104 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1105 lcd_show_board_info();
1106 #endif /* CONFIG_LCD_INFO */
1108 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1109 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
1111 return (void *)lcd_base;
1112 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1115 #ifdef CONFIG_SPLASHIMAGE_GUARD
1116 static int on_splashimage(const char *name, const char *value, enum env_op op,
1122 if (op == env_op_delete)
1125 addr = simple_strtoul(value, NULL, 16);
1126 /* See README.displaying-bmps */
1127 aligned = (addr % 4 == 2);
1129 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1136 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1139 void lcd_position_cursor(unsigned col, unsigned row)
1141 console_col = min(col, CONSOLE_COLS - 1);
1142 console_row = min(row, CONSOLE_ROWS - 1);
1145 int lcd_get_pixel_width(void)
1147 return panel_info.vl_col;
1150 int lcd_get_pixel_height(void)
1152 return panel_info.vl_row;
1155 int lcd_get_screen_rows(void)
1157 return CONSOLE_ROWS;
1160 int lcd_get_screen_columns(void)
1162 return CONSOLE_COLS;
1165 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1166 static int lcd_dt_simplefb_configure_node(void *blob, int off)
1171 static const char format[] =
1172 #if LCD_BPP == LCD_COLOR16
1181 stride = panel_info.vl_col * 2;
1183 cells[0] = cpu_to_fdt32(gd->fb_base);
1184 cells[1] = cpu_to_fdt32(stride * panel_info.vl_row);
1185 ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2);
1189 cells[0] = cpu_to_fdt32(panel_info.vl_col);
1190 ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0]));
1194 cells[0] = cpu_to_fdt32(panel_info.vl_row);
1195 ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0]));
1199 cells[0] = cpu_to_fdt32(stride);
1200 ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0]));
1204 ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1);
1208 ret = fdt_delprop(blob, off, "status");
1215 int lcd_dt_simplefb_add_node(void *blob)
1217 static const char compat[] = "simple-framebuffer";
1218 static const char disabled[] = "disabled";
1221 off = fdt_add_subnode(blob, 0, "framebuffer");
1225 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1229 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1233 return lcd_dt_simplefb_configure_node(blob, off);
1236 int lcd_dt_simplefb_enable_existing_node(void *blob)
1240 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1244 return lcd_dt_simplefb_configure_node(blob, off);