2 * Common LCD routines for supported CPUs
4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
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)
46 #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
47 defined(CONFIG_CPU_MONAHANS)
48 #define CONFIG_CPU_PXA
49 #include <asm/byteorder.h>
52 #if defined(CONFIG_MPC823)
56 #if defined(CONFIG_ATMEL_LCD)
57 #include <atmel_lcdc.h>
60 /************************************************************************/
62 /************************************************************************/
63 #include <video_font.h> /* Get font data, width and height */
64 #include <video_font_data.h>
66 /************************************************************************/
68 /************************************************************************/
69 #ifdef CONFIG_LCD_LOGO
70 # include <bmp_logo.h> /* Get logo data, width and height */
71 # include <bmp_logo_data.h>
72 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
73 # error Default Color Map overlaps with Logo Color Map
77 #ifndef CONFIG_LCD_ALIGNMENT
78 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
81 /* By default we scroll by a single line */
82 #ifndef CONFIG_CONSOLE_SCROLL_LINES
83 #define CONFIG_CONSOLE_SCROLL_LINES 1
86 DECLARE_GLOBAL_DATA_PTR;
88 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
89 static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
90 static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
92 static int lcd_init(void *lcdbase);
94 static void *lcd_logo(void);
96 static int lcd_getbgcolor(void);
97 static void lcd_setfgcolor(int color);
98 static void lcd_setbgcolor(int color);
100 static int lcd_color_fg;
101 static int lcd_color_bg;
104 char lcd_is_enabled = 0;
106 static short console_col;
107 static short console_row;
109 static void *lcd_console_address;
110 static void *lcd_base; /* Start of framebuffer memory */
112 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
114 /************************************************************************/
116 /* Flush LCD activity to the caches */
120 * flush_dcache_range() is declared in common.h but it seems that some
121 * architectures do not actually implement it. Is there a way to find
122 * out whether it exists? For now, ARM is safe.
124 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
127 if (lcd_flush_dcache)
128 flush_dcache_range((u32)lcd_base,
129 (u32)(lcd_base + lcd_get_size(&line_length)));
133 void lcd_set_flush_dcache(int flush)
135 lcd_flush_dcache = (flush != 0);
138 /*----------------------------------------------------------------------*/
140 static void console_scrollup(void)
142 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
144 /* Copy up rows ignoring those that will be overwritten */
145 memcpy(CONSOLE_ROW_FIRST,
146 lcd_console_address + CONSOLE_ROW_SIZE * rows,
147 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
149 /* Clear the last rows */
150 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
151 COLOR_MASK(lcd_color_bg),
152 CONSOLE_ROW_SIZE * rows);
158 /*----------------------------------------------------------------------*/
160 static inline void console_back(void)
162 if (--console_col < 0) {
163 console_col = CONSOLE_COLS-1 ;
164 if (--console_row < 0)
168 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
169 console_row * VIDEO_FONT_HEIGHT, ' ');
172 /*----------------------------------------------------------------------*/
174 static inline void console_newline(void)
178 /* Check if we need to scroll the terminal */
179 if (++console_row >= CONSOLE_ROWS)
185 /*----------------------------------------------------------------------*/
187 void lcd_putc(const char c)
189 if (!lcd_is_enabled) {
204 case '\t': /* Tab (8 chars alignment) */
208 if (console_col >= CONSOLE_COLS)
217 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
218 console_row * VIDEO_FONT_HEIGHT, c);
219 if (++console_col >= CONSOLE_COLS)
224 /*----------------------------------------------------------------------*/
226 void lcd_puts(const char *s)
228 if (!lcd_is_enabled) {
240 /*----------------------------------------------------------------------*/
242 void lcd_printf(const char *fmt, ...)
245 char buf[CONFIG_SYS_PBSIZE];
248 vsprintf(buf, fmt, args);
254 /************************************************************************/
255 /* ** Low-Level Graphics Routines */
256 /************************************************************************/
258 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
263 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
264 y += BMP_LOGO_HEIGHT;
267 #if LCD_BPP == LCD_MONOCHROME
268 ushort off = x * (1 << LCD_BPP) % 8;
271 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
273 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
276 #if LCD_BPP == LCD_COLOR16
277 ushort *d = (ushort *)dest;
282 #if LCD_BPP == LCD_MONOCHROME
283 uchar rest = *d & -(1 << (8 - off));
286 for (i = 0; i < count; ++i) {
290 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
292 #if LCD_BPP == LCD_MONOCHROME
293 sym = (COLOR_MASK(lcd_color_fg) & bits) |
294 (COLOR_MASK(lcd_color_bg) & ~bits);
296 *d++ = rest | (sym >> off);
297 rest = sym << (8-off);
298 #elif LCD_BPP == LCD_COLOR8
299 for (c = 0; c < 8; ++c) {
300 *d++ = (bits & 0x80) ?
301 lcd_color_fg : lcd_color_bg;
304 #elif LCD_BPP == LCD_COLOR16
305 for (c = 0; c < 8; ++c) {
306 *d++ = (bits & 0x80) ?
307 lcd_color_fg : lcd_color_bg;
312 #if LCD_BPP == LCD_MONOCHROME
313 *d = rest | (*d & ((1 << (8 - off)) - 1));
318 /*----------------------------------------------------------------------*/
320 static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
322 lcd_drawchars(x, y, s, strlen((char *)s));
325 /*----------------------------------------------------------------------*/
327 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
329 lcd_drawchars(x, y, &c, 1);
332 /************************************************************************/
333 /** Small utility to check that you got the colours right */
334 /************************************************************************/
335 #ifdef LCD_TEST_PATTERN
340 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
341 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
342 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
345 static void test_pattern(void)
347 ushort v_max = panel_info.vl_row;
348 ushort h_max = panel_info.vl_col;
349 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
350 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
352 uchar *pix = (uchar *)lcd_base;
354 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
355 h_max, v_max, h_step, v_step);
357 /* WARNING: Code silently assumes 8bit/pixel */
358 for (v = 0; v < v_max; ++v) {
359 uchar iy = v / v_step;
360 for (h = 0; h < h_max; ++h) {
361 uchar ix = N_BLK_HOR * iy + h / h_step;
362 *pix++ = test_colors[ix];
366 #endif /* LCD_TEST_PATTERN */
369 /************************************************************************/
370 /* ** GENERIC Initialization Routines */
371 /************************************************************************/
373 int lcd_get_size(int *line_length)
375 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
376 return *line_length * panel_info.vl_row;
379 int drv_lcd_init(void)
381 struct stdio_dev lcddev;
384 lcd_base = (void *) gd->fb_base;
386 lcd_get_size(&lcd_line_length);
388 lcd_init(lcd_base); /* LCD initialization */
390 /* Device initialization */
391 memset(&lcddev, 0, sizeof(lcddev));
393 strcpy(lcddev.name, "lcd");
394 lcddev.ext = 0; /* No extensions */
395 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
396 lcddev.putc = lcd_putc; /* 'putc' function */
397 lcddev.puts = lcd_puts; /* 'puts' function */
399 rc = stdio_register(&lcddev);
401 return (rc == 0) ? 1 : rc;
404 /*----------------------------------------------------------------------*/
407 #if LCD_BPP == LCD_MONOCHROME
408 /* Setting the palette */
411 #elif LCD_BPP == LCD_COLOR8
412 /* Setting the palette */
413 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
414 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
415 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
416 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
417 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
418 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
419 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
420 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
421 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
424 #ifndef CONFIG_SYS_WHITE_ON_BLACK
425 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
426 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
428 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
429 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
430 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
432 #ifdef LCD_TEST_PATTERN
435 /* set framebuffer to background color */
436 memset((char *)lcd_base,
437 COLOR_MASK(lcd_getbgcolor()),
438 lcd_line_length * panel_info.vl_row);
440 /* Paint the logo and retrieve LCD base address */
441 debug("[LCD] Drawing the logo...\n");
442 lcd_console_address = lcd_logo();
449 static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
457 cls, 1, 1, do_lcd_clear,
462 /*----------------------------------------------------------------------*/
464 static int lcd_init(void *lcdbase)
466 /* Initialize the lcd controller */
467 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
469 lcd_ctrl_init(lcdbase);
474 /* Initialize the console */
476 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
477 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
479 console_row = 1; /* leave 1 blank line below logo */
486 /************************************************************************/
487 /* ** ROM capable initialization part - needed to reserve FB memory */
488 /************************************************************************/
490 * This is called early in the system initialization to grab memory
491 * for the LCD controller.
492 * Returns new address for monitor, after reserving LCD buffer memory
494 * Note that this is running from ROM, so no write access to global data.
496 ulong lcd_setmem(ulong addr)
501 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
502 panel_info.vl_row, NBITS(panel_info.vl_bpix));
504 size = lcd_get_size(&line_length);
506 /* Round up to nearest full page, or MMU section if defined */
507 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
508 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
510 /* Allocate pages for the frame buffer. */
513 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
519 /*----------------------------------------------------------------------*/
521 static void lcd_setfgcolor(int color)
523 lcd_color_fg = color;
526 /*----------------------------------------------------------------------*/
528 static void lcd_setbgcolor(int color)
530 lcd_color_bg = color;
533 /*----------------------------------------------------------------------*/
535 int lcd_getfgcolor(void)
540 /*----------------------------------------------------------------------*/
542 static int lcd_getbgcolor(void)
547 /************************************************************************/
548 /* ** Chipset depending Bitmap / Logo stuff... */
549 /************************************************************************/
550 static inline ushort *configuration_get_cmap(void)
552 #if defined CONFIG_CPU_PXA
553 struct pxafb_info *fbi = &panel_info.pxa;
554 return (ushort *)fbi->palette;
555 #elif defined(CONFIG_MPC823)
556 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
557 cpm8xx_t *cp = &(immr->im_cpm);
558 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
559 #elif defined(CONFIG_ATMEL_LCD)
560 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
561 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
562 return panel_info.cmap;
563 #elif defined(CONFIG_LCD_LOGO)
564 return bmp_logo_palette;
570 #ifdef CONFIG_LCD_LOGO
571 void bitmap_plot(int x, int y)
573 #ifdef CONFIG_ATMEL_LCD
574 uint *cmap = (uint *)bmp_logo_palette;
576 ushort *cmap = (ushort *)bmp_logo_palette;
582 #if defined(CONFIG_MPC823)
583 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
584 cpm8xx_t *cp = &(immr->im_cpm);
587 debug("Logo: width %d height %d colors %d cmap %d\n",
588 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
589 ARRAY_SIZE(bmp_logo_palette));
591 bmap = &bmp_logo_bitmap[0];
592 fb = (uchar *)(lcd_base + y * lcd_line_length + x);
594 if (NBITS(panel_info.vl_bpix) < 12) {
595 /* Leave room for default color map
596 * default case: generic system with no cmap (most likely 16bpp)
597 * cmap was set to the source palette, so no change is done.
598 * This avoids even more ifdefs in the next stanza
600 #if defined(CONFIG_MPC823)
601 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
602 #elif defined(CONFIG_ATMEL_LCD)
603 cmap = (uint *)configuration_get_cmap();
605 cmap = configuration_get_cmap();
611 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
612 ushort colreg = bmp_logo_palette[i];
613 #ifdef CONFIG_ATMEL_LCD
615 #ifdef CONFIG_ATMEL_LCD_BGR555
616 lut_entry = ((colreg & 0x000F) << 11) |
617 ((colreg & 0x00F0) << 2) |
618 ((colreg & 0x0F00) >> 7);
619 #else /* CONFIG_ATMEL_LCD_RGB565 */
620 lut_entry = ((colreg & 0x000F) << 1) |
621 ((colreg & 0x00F0) << 3) |
622 ((colreg & 0x0F00) << 4);
624 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
626 #else /* !CONFIG_ATMEL_LCD */
627 #ifdef CONFIG_SYS_INVERT_COLORS
628 *cmap++ = 0xffff - colreg;
632 #endif /* CONFIG_ATMEL_LCD */
637 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
638 memcpy(fb, bmap, BMP_LOGO_WIDTH);
639 bmap += BMP_LOGO_WIDTH;
640 fb += panel_info.vl_col;
643 else { /* true color mode */
645 fb16 = (ushort *)(lcd_base + y * lcd_line_length + x);
646 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
647 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
648 col16 = bmp_logo_palette[(bmap[j]-16)];
650 ((col16 & 0x000F) << 1) |
651 ((col16 & 0x00F0) << 3) |
652 ((col16 & 0x0F00) << 4);
654 bmap += BMP_LOGO_WIDTH;
655 fb16 += panel_info.vl_col;
663 static inline void bitmap_plot(int x, int y) {}
664 #endif /* CONFIG_LCD_LOGO */
666 /*----------------------------------------------------------------------*/
667 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
669 * Display the BMP file located at address bmp_image.
673 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
674 #define BMP_ALIGN_CENTER 0x7FFF
676 static void splash_align_axis(int *axis, unsigned long panel_size,
677 unsigned long picture_size)
679 unsigned long panel_picture_delta = panel_size - picture_size;
680 unsigned long axis_alignment;
682 if (*axis == BMP_ALIGN_CENTER)
683 axis_alignment = panel_picture_delta / 2;
685 axis_alignment = panel_picture_delta + *axis + 1;
689 *axis = max(0, axis_alignment);
694 #ifdef CONFIG_LCD_BMP_RLE8
696 #define BMP_RLE8_ESCAPE 0
697 #define BMP_RLE8_EOL 0
698 #define BMP_RLE8_EOBMP 1
699 #define BMP_RLE8_DELTA 2
701 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
705 *(*fbp)++ = cmap[*bmap++];
710 static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
713 int cnt_8copy = cnt >> 3;
715 cnt -= cnt_8copy << 3;
716 while (cnt_8copy > 0) {
735 * Do not call this function directly, must be called from lcd_display_bitmap.
737 static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
738 int x_off, int y_off)
746 width = le32_to_cpu(bmp->header.width);
747 height = le32_to_cpu(bmp->header.height);
748 bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
754 if (bmap[0] == BMP_RLE8_ESCAPE) {
761 /* 16bpix, 2-byte per pixel, width should *2 */
762 fb -= (width * 2 + lcd_line_length);
772 /* 16bpix, 2-byte per pixel, x should *2 */
773 fb = (uchar *) (lcd_base + (y + y_off - 1)
774 * lcd_line_length + (x + x_off) * 2);
783 if (x + runlen > width)
787 draw_unencoded_bitmap(
802 /* aggregate the same code */
803 while (bmap[0] == 0xff &&
804 bmap[2] != BMP_RLE8_ESCAPE &&
805 bmap[1] == bmap[3]) {
809 if (x + runlen > width)
813 draw_encoded_bitmap((ushort **)&fb,
824 #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
825 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
827 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
830 #if defined(CONFIG_BMP_16BPP)
831 #if defined(CONFIG_ATMEL_LCD_BGR555)
832 static inline void fb_put_word(uchar **fb, uchar **from)
834 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
835 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
839 static inline void fb_put_word(uchar **fb, uchar **from)
841 *(*fb)++ = *(*from)++;
842 *(*fb)++ = *(*from)++;
845 #endif /* CONFIG_BMP_16BPP */
847 int lcd_display_bitmap(ulong bmp_image, int x, int y)
849 #if !defined(CONFIG_MCC200)
852 ushort *cmap_base = NULL;
855 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
858 unsigned long width, height, byte_width;
859 unsigned long pwidth = panel_info.vl_col;
860 unsigned colors, bpix, bmp_bpix;
862 if (!bmp || !(bmp->header.signature[0] == 'B' &&
863 bmp->header.signature[1] == 'M')) {
864 printf("Error: no valid bmp image at %lx\n", bmp_image);
869 width = le32_to_cpu(bmp->header.width);
870 height = le32_to_cpu(bmp->header.height);
871 bmp_bpix = le16_to_cpu(bmp->header.bit_count);
872 colors = 1 << bmp_bpix;
874 bpix = NBITS(panel_info.vl_bpix);
876 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
877 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
883 /* We support displaying 8bpp BMPs on 16bpp LCDs */
884 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
885 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
887 le16_to_cpu(bmp->header.bit_count));
892 debug("Display-bmp: %d x %d with %d colors\n",
893 (int)width, (int)height, (int)colors);
895 #if !defined(CONFIG_MCC200)
896 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
898 cmap = configuration_get_cmap();
902 for (i = 0; i < colors; ++i) {
903 bmp_color_table_entry_t cte = bmp->color_table[i];
904 #if !defined(CONFIG_ATMEL_LCD)
906 ( ((cte.red) << 8) & 0xf800) |
907 ( ((cte.green) << 3) & 0x07e0) |
908 ( ((cte.blue) >> 3) & 0x001f) ;
909 #ifdef CONFIG_SYS_INVERT_COLORS
910 *cmap = 0xffff - colreg;
914 #if defined(CONFIG_MPC823)
919 #else /* CONFIG_ATMEL_LCD */
920 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
927 * BMP format for Monochrome assumes that the state of a
928 * pixel is described on a per Bit basis, not per Byte.
929 * So, in case of Monochrome BMP we should align widths
930 * on a byte boundary and convert them from Bit to Byte
932 * Probably, PXA250 and MPC823 process 1bpp BMP images in
933 * their own ways, so make the converting to be MCC200
936 #if defined(CONFIG_MCC200)
938 width = ((width + 7) & ~7) >> 3;
939 x = ((x + 7) & ~7) >> 3;
940 pwidth= ((pwidth + 7) & ~7) >> 3;
944 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
946 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
947 splash_align_axis(&x, pwidth, width);
948 splash_align_axis(&y, panel_info.vl_row, height);
949 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
951 if ((x + width) > pwidth)
953 if ((y + height) > panel_info.vl_row)
954 height = panel_info.vl_row - y;
956 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
957 fb = (uchar *) (lcd_base +
958 (y + height - 1) * lcd_line_length + x * bpix / 8);
961 case 1: /* pass through */
963 #ifdef CONFIG_LCD_BMP_RLE8
964 if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
966 /* TODO implement render code for bpix != 16 */
967 printf("Error: only support 16 bpix");
970 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
978 byte_width = width * 2;
980 for (i = 0; i < height; ++i) {
982 for (j = 0; j < width; j++) {
984 FB_PUT_BYTE(fb, bmap);
986 *(uint16_t *)fb = cmap_base[*(bmap++)];
987 fb += sizeof(uint16_t) / sizeof(*fb);
990 bmap += (padded_width - width);
991 fb -= byte_width + lcd_line_length;
995 #if defined(CONFIG_BMP_16BPP)
997 for (i = 0; i < height; ++i) {
999 for (j = 0; j < width; j++)
1000 fb_put_word(&fb, &bmap);
1002 bmap += (padded_width - width) * 2;
1003 fb -= width * 2 + lcd_line_length;
1006 #endif /* CONFIG_BMP_16BPP */
1008 #if defined(CONFIG_BMP_32BPP)
1010 for (i = 0; i < height; ++i) {
1011 for (j = 0; j < width; j++) {
1012 *(fb++) = *(bmap++);
1013 *(fb++) = *(bmap++);
1014 *(fb++) = *(bmap++);
1015 *(fb++) = *(bmap++);
1017 fb -= lcd_line_length + width * (bpix / 8);
1020 #endif /* CONFIG_BMP_32BPP */
1030 #ifdef CONFIG_SPLASH_SCREEN_PREPARE
1031 static inline int splash_screen_prepare(void)
1033 return board_splash_screen_prepare();
1036 static inline int splash_screen_prepare(void)
1042 static void *lcd_logo(void)
1044 #ifdef CONFIG_SPLASH_SCREEN
1047 static int do_splash = 1;
1049 if (do_splash && (s = getenv("splashimage")) != NULL) {
1053 if (splash_screen_prepare())
1054 return (void *)gd->fb_base;
1056 addr = simple_strtoul (s, NULL, 16);
1057 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1058 s = getenv("splashpos");
1061 x = BMP_ALIGN_CENTER;
1063 x = simple_strtol(s, NULL, 0);
1065 s = strchr(s + 1, ',');
1068 y = BMP_ALIGN_CENTER;
1070 y = simple_strtol (s + 1, NULL, 0);
1073 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1075 if (bmp_display(addr, x, y) == 0)
1076 return (void *)lcd_base;
1078 #endif /* CONFIG_SPLASH_SCREEN */
1082 #ifdef CONFIG_LCD_INFO
1083 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1084 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1085 lcd_show_board_info();
1086 #endif /* CONFIG_LCD_INFO */
1088 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1089 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
1091 return (void *)lcd_base;
1092 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1095 #ifdef CONFIG_SPLASHIMAGE_GUARD
1096 static int on_splashimage(const char *name, const char *value, enum env_op op,
1102 if (op == env_op_delete)
1105 addr = simple_strtoul(value, NULL, 16);
1106 /* See README.displaying-bmps */
1107 aligned = (addr % 4 == 2);
1109 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1116 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1119 void lcd_position_cursor(unsigned col, unsigned row)
1121 console_col = min(col, CONSOLE_COLS - 1);
1122 console_row = min(row, CONSOLE_ROWS - 1);
1125 int lcd_get_pixel_width(void)
1127 return panel_info.vl_col;
1130 int lcd_get_pixel_height(void)
1132 return panel_info.vl_row;
1135 int lcd_get_screen_rows(void)
1137 return CONSOLE_ROWS;
1140 int lcd_get_screen_columns(void)
1142 return CONSOLE_COLS;