2 * Common LCD routines for supported CPUs
4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
7 * SPDX-License-Identifier: GPL-2.0+
10 /************************************************************************/
12 /************************************************************************/
21 #include <env_callback.h>
22 #include <linux/types.h>
23 #include <stdio_dev.h>
24 #if defined(CONFIG_POST)
29 #include <asm/unaligned.h>
32 #include <asm/unaligned.h>
33 #include <fdt_support.h>
35 #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
36 defined(CONFIG_CPU_MONAHANS)
37 #include <asm/byteorder.h>
40 #if defined(CONFIG_MPC823)
44 #if defined(CONFIG_ATMEL_LCD)
45 #include <atmel_lcdc.h>
48 #if defined(CONFIG_LCD_DT_SIMPLEFB)
52 /************************************************************************/
54 /************************************************************************/
55 #include <video_font.h> /* Get font data, width and height */
57 /************************************************************************/
59 /************************************************************************/
60 #ifdef CONFIG_LCD_LOGO
61 # include <bmp_logo.h> /* Get logo data, width and height */
62 # include <bmp_logo_data.h>
63 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
64 # error Default Color Map overlaps with Logo Color Map
72 #ifndef CONFIG_LCD_ALIGNMENT
73 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
76 /* By default we scroll by a single line */
77 #ifndef CONFIG_CONSOLE_SCROLL_LINES
78 #define CONFIG_CONSOLE_SCROLL_LINES 1
81 /************************************************************************/
82 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
83 /************************************************************************/
84 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
85 #define CONSOLE_ROW_FIRST lcd_console_address
86 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
87 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
89 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows)
90 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
92 #if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \
93 (LCD_BPP == LCD_COLOR32)
94 # define COLOR_MASK(c) (c)
96 # error Unsupported LCD BPP.
99 DECLARE_GLOBAL_DATA_PTR
;
101 static void lcd_drawchars(ushort x
, ushort y
, uchar
*str
, int count
);
102 static inline void lcd_putc_xy(ushort x
, ushort y
, uchar c
);
104 static int lcd_init(void *lcdbase
);
106 static void *lcd_logo(void);
108 static void lcd_setfgcolor(int color
);
109 static void lcd_setbgcolor(int color
);
111 static int lcd_color_fg
;
112 static int lcd_color_bg
;
115 char lcd_is_enabled
= 0;
117 static short console_curr_col
;
118 static short console_curr_row
;
119 static short console_cols
;
120 static short console_rows
;
122 static void *lcd_console_address
;
123 static void *lcd_base
; /* Start of framebuffer memory */
125 static char lcd_flush_dcache
; /* 1 to flush dcache after each lcd update */
127 /************************************************************************/
129 /* Flush LCD activity to the caches */
133 * flush_dcache_range() is declared in common.h but it seems that some
134 * architectures do not actually implement it. Is there a way to find
135 * out whether it exists? For now, ARM is safe.
137 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
140 if (lcd_flush_dcache
)
141 flush_dcache_range((u32
)lcd_base
,
142 (u32
)(lcd_base
+ lcd_get_size(&line_length
)));
143 #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
144 static ulong last_sync
;
146 if (get_timer(last_sync
) > 10) {
147 sandbox_sdl_sync(lcd_base
);
148 last_sync
= get_timer(0);
153 void lcd_set_flush_dcache(int flush
)
155 lcd_flush_dcache
= (flush
!= 0);
158 void lcd_init_console(void *address
, int rows
, int cols
)
160 console_curr_col
= 0;
161 console_curr_row
= 0;
164 lcd_console_address
= address
;
167 void lcd_set_col(short col
)
169 console_curr_col
= col
;
172 void lcd_set_row(short row
)
174 console_curr_row
= row
;
177 /*----------------------------------------------------------------------*/
179 static void console_scrollup(void)
181 const int rows
= CONFIG_CONSOLE_SCROLL_LINES
;
183 /* Copy up rows ignoring those that will be overwritten */
184 memcpy(CONSOLE_ROW_FIRST
,
185 lcd_console_address
+ CONSOLE_ROW_SIZE
* rows
,
186 CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
);
188 /* Clear the last rows */
189 #if (LCD_BPP != LCD_COLOR32)
190 memset(lcd_console_address
+ CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
,
191 COLOR_MASK(lcd_color_bg
),
192 CONSOLE_ROW_SIZE
* rows
);
194 u32
*ppix
= lcd_console_address
+
195 CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
;
198 i
< (CONSOLE_ROW_SIZE
* rows
) / NBYTES(panel_info
.vl_bpix
);
200 *ppix
++ = COLOR_MASK(lcd_color_bg
);
204 console_curr_row
-= rows
;
207 /*----------------------------------------------------------------------*/
209 static inline void console_back(void)
211 if (--console_curr_col
< 0) {
212 console_curr_col
= console_cols
- 1;
213 if (--console_curr_row
< 0)
214 console_curr_row
= 0;
217 lcd_putc_xy(console_curr_col
* VIDEO_FONT_WIDTH
,
218 console_curr_row
* VIDEO_FONT_HEIGHT
, ' ');
221 /*----------------------------------------------------------------------*/
223 static inline void console_newline(void)
225 console_curr_col
= 0;
227 /* Check if we need to scroll the terminal */
228 if (++console_curr_row
>= console_rows
)
234 /*----------------------------------------------------------------------*/
236 static void lcd_stub_putc(struct stdio_dev
*dev
, const char c
)
241 void lcd_putc(const char c
)
243 if (!lcd_is_enabled
) {
251 console_curr_col
= 0;
258 case '\t': /* Tab (8 chars alignment) */
259 console_curr_col
+= 8;
260 console_curr_col
&= ~7;
262 if (console_curr_col
>= console_cols
)
271 lcd_putc_xy(console_curr_col
* VIDEO_FONT_WIDTH
,
272 console_curr_row
* VIDEO_FONT_HEIGHT
, c
);
273 if (++console_curr_col
>= console_cols
)
278 /*----------------------------------------------------------------------*/
280 static void lcd_stub_puts(struct stdio_dev
*dev
, const char *s
)
285 void lcd_puts(const char *s
)
287 if (!lcd_is_enabled
) {
299 /*----------------------------------------------------------------------*/
301 void lcd_printf(const char *fmt
, ...)
304 char buf
[CONFIG_SYS_PBSIZE
];
307 vsprintf(buf
, fmt
, args
);
313 /************************************************************************/
314 /* ** Low-Level Graphics Routines */
315 /************************************************************************/
317 static void lcd_drawchars(ushort x
, ushort y
, uchar
*str
, int count
)
322 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
323 y
+= BMP_LOGO_HEIGHT
;
326 dest
= (uchar
*)(lcd_base
+ y
* lcd_line_length
+ x
* NBITS(LCD_BPP
)/8);
328 for (row
= 0; row
< VIDEO_FONT_HEIGHT
; ++row
, dest
+= lcd_line_length
) {
331 #if LCD_BPP == LCD_COLOR16
332 ushort
*d
= (ushort
*)dest
;
333 #elif LCD_BPP == LCD_COLOR32
334 u32
*d
= (u32
*)dest
;
339 for (i
= 0; i
< count
; ++i
) {
343 bits
= video_fontdata
[c
* VIDEO_FONT_HEIGHT
+ row
];
345 for (c
= 0; c
< 8; ++c
) {
346 *d
++ = (bits
& 0x80) ?
347 lcd_color_fg
: lcd_color_bg
;
354 static inline void lcd_putc_xy(ushort x
, ushort y
, uchar c
)
356 lcd_drawchars(x
, y
, &c
, 1);
359 /************************************************************************/
360 /** Small utility to check that you got the colours right */
361 /************************************************************************/
362 #ifdef LCD_TEST_PATTERN
367 static int test_colors
[N_BLK_HOR
* N_BLK_VERT
] = {
368 CONSOLE_COLOR_RED
, CONSOLE_COLOR_GREEN
, CONSOLE_COLOR_YELLOW
,
369 CONSOLE_COLOR_BLUE
, CONSOLE_COLOR_MAGENTA
, CONSOLE_COLOR_CYAN
,
372 static void test_pattern(void)
374 ushort v_max
= panel_info
.vl_row
;
375 ushort h_max
= panel_info
.vl_col
;
376 ushort v_step
= (v_max
+ N_BLK_VERT
- 1) / N_BLK_VERT
;
377 ushort h_step
= (h_max
+ N_BLK_HOR
- 1) / N_BLK_HOR
;
379 uchar
*pix
= (uchar
*)lcd_base
;
381 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
382 h_max
, v_max
, h_step
, v_step
);
384 /* WARNING: Code silently assumes 8bit/pixel */
385 for (v
= 0; v
< v_max
; ++v
) {
386 uchar iy
= v
/ v_step
;
387 for (h
= 0; h
< h_max
; ++h
) {
388 uchar ix
= N_BLK_HOR
* iy
+ h
/ h_step
;
389 *pix
++ = test_colors
[ix
];
393 #endif /* LCD_TEST_PATTERN */
396 /************************************************************************/
397 /* ** GENERIC Initialization Routines */
398 /************************************************************************/
400 * With most lcd drivers the line length is set up
401 * by calculating it from panel_info parameters. Some
402 * drivers need to calculate the line length differently,
403 * so make the function weak to allow overriding it.
405 __weak
int lcd_get_size(int *line_length
)
407 *line_length
= (panel_info
.vl_col
* NBITS(panel_info
.vl_bpix
)) / 8;
408 return *line_length
* panel_info
.vl_row
;
411 int drv_lcd_init(void)
413 struct stdio_dev lcddev
;
416 lcd_base
= map_sysmem(gd
->fb_base
, 0);
418 lcd_init(lcd_base
); /* LCD initialization */
420 /* Device initialization */
421 memset(&lcddev
, 0, sizeof(lcddev
));
423 strcpy(lcddev
.name
, "lcd");
424 lcddev
.ext
= 0; /* No extensions */
425 lcddev
.flags
= DEV_FLAGS_OUTPUT
; /* Output only */
426 lcddev
.putc
= lcd_stub_putc
; /* 'putc' function */
427 lcddev
.puts
= lcd_stub_puts
; /* 'puts' function */
429 rc
= stdio_register(&lcddev
);
431 return (rc
== 0) ? 1 : rc
;
434 /*----------------------------------------------------------------------*/
437 short console_rows
, console_cols
;
438 #if LCD_BPP == LCD_COLOR8
439 /* Setting the palette */
440 lcd_setcolreg(CONSOLE_COLOR_BLACK
, 0, 0, 0);
441 lcd_setcolreg(CONSOLE_COLOR_RED
, 0xFF, 0, 0);
442 lcd_setcolreg(CONSOLE_COLOR_GREEN
, 0, 0xFF, 0);
443 lcd_setcolreg(CONSOLE_COLOR_YELLOW
, 0xFF, 0xFF, 0);
444 lcd_setcolreg(CONSOLE_COLOR_BLUE
, 0, 0, 0xFF);
445 lcd_setcolreg(CONSOLE_COLOR_MAGENTA
, 0xFF, 0, 0xFF);
446 lcd_setcolreg(CONSOLE_COLOR_CYAN
, 0, 0xFF, 0xFF);
447 lcd_setcolreg(CONSOLE_COLOR_GREY
, 0xAA, 0xAA, 0xAA);
448 lcd_setcolreg(CONSOLE_COLOR_WHITE
, 0xFF, 0xFF, 0xFF);
451 #ifndef CONFIG_SYS_WHITE_ON_BLACK
452 lcd_setfgcolor(CONSOLE_COLOR_BLACK
);
453 lcd_setbgcolor(CONSOLE_COLOR_WHITE
);
455 lcd_setfgcolor(CONSOLE_COLOR_WHITE
);
456 lcd_setbgcolor(CONSOLE_COLOR_BLACK
);
457 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
459 #ifdef LCD_TEST_PATTERN
462 /* set framebuffer to background color */
463 #if (LCD_BPP != LCD_COLOR32)
464 memset((char *)lcd_base
,
465 COLOR_MASK(lcd_color_bg
),
466 lcd_line_length
* panel_info
.vl_row
);
468 u32
*ppix
= lcd_base
;
471 i
< (lcd_line_length
* panel_info
.vl_row
)/NBYTES(panel_info
.vl_bpix
);
473 *ppix
++ = COLOR_MASK(lcd_color_bg
);
477 /* Paint the logo and retrieve LCD base address */
478 debug("[LCD] Drawing the logo...\n");
479 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
480 console_rows
= (panel_info
.vl_row
- BMP_LOGO_HEIGHT
);
481 console_rows
/= VIDEO_FONT_HEIGHT
;
483 console_rows
= panel_info
.vl_row
/ VIDEO_FONT_HEIGHT
;
485 console_cols
= panel_info
.vl_col
/ VIDEO_FONT_WIDTH
;
486 lcd_init_console(lcd_logo(), console_rows
, console_cols
);
490 static int do_lcd_clear(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
498 cls
, 1, 1, do_lcd_clear
,
503 /*----------------------------------------------------------------------*/
505 static int lcd_init(void *lcdbase
)
507 /* Initialize the lcd controller */
508 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase
);
510 lcd_ctrl_init(lcdbase
);
513 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
514 * the 'lcdbase' argument and uses custom lcd base address
515 * by setting up gd->fb_base. Check for this condition and fixup
516 * 'lcd_base' address.
518 if (map_to_sysmem(lcdbase
) != gd
->fb_base
)
519 lcd_base
= map_sysmem(gd
->fb_base
, 0);
521 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base
);
523 lcd_get_size(&lcd_line_length
);
528 /* Initialize the console */
530 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
531 lcd_set_row(7 + BMP_LOGO_HEIGHT
/ VIDEO_FONT_HEIGHT
);
533 lcd_set_row(1); /* leave 1 blank line below logo */
540 /************************************************************************/
541 /* ** ROM capable initialization part - needed to reserve FB memory */
542 /************************************************************************/
544 * This is called early in the system initialization to grab memory
545 * for the LCD controller.
546 * Returns new address for monitor, after reserving LCD buffer memory
548 * Note that this is running from ROM, so no write access to global data.
550 ulong
lcd_setmem(ulong addr
)
555 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info
.vl_col
,
556 panel_info
.vl_row
, NBITS(panel_info
.vl_bpix
));
558 size
= lcd_get_size(&line_length
);
560 /* Round up to nearest full page, or MMU section if defined */
561 size
= ALIGN(size
, CONFIG_LCD_ALIGNMENT
);
562 addr
= ALIGN(addr
- CONFIG_LCD_ALIGNMENT
+ 1, CONFIG_LCD_ALIGNMENT
);
564 /* Allocate pages for the frame buffer. */
567 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
573 /*----------------------------------------------------------------------*/
575 static void lcd_setfgcolor(int color
)
577 lcd_color_fg
= color
;
580 /*----------------------------------------------------------------------*/
582 static void lcd_setbgcolor(int color
)
584 lcd_color_bg
= color
;
587 /************************************************************************/
588 /* ** Chipset depending Bitmap / Logo stuff... */
589 /************************************************************************/
590 static inline ushort
*configuration_get_cmap(void)
592 #if defined CONFIG_CPU_PXA
593 struct pxafb_info
*fbi
= &panel_info
.pxa
;
594 return (ushort
*)fbi
->palette
;
595 #elif defined(CONFIG_MPC823)
596 immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
597 cpm8xx_t
*cp
= &(immr
->im_cpm
);
598 return (ushort
*)&(cp
->lcd_cmap
[255 * sizeof(ushort
)]);
599 #elif defined(CONFIG_ATMEL_LCD)
600 return (ushort
*)(panel_info
.mmio
+ ATMEL_LCDC_LUT(0));
601 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
602 return panel_info
.cmap
;
603 #elif defined(CONFIG_LCD_LOGO)
604 return bmp_logo_palette
;
610 #ifdef CONFIG_LCD_LOGO
611 void bitmap_plot(int x
, int y
)
613 #ifdef CONFIG_ATMEL_LCD
614 uint
*cmap
= (uint
*)bmp_logo_palette
;
616 ushort
*cmap
= (ushort
*)bmp_logo_palette
;
622 #if defined(CONFIG_MPC823)
623 immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
624 cpm8xx_t
*cp
= &(immr
->im_cpm
);
626 unsigned bpix
= NBITS(panel_info
.vl_bpix
);
628 debug("Logo: width %d height %d colors %d cmap %d\n",
629 BMP_LOGO_WIDTH
, BMP_LOGO_HEIGHT
, BMP_LOGO_COLORS
,
630 ARRAY_SIZE(bmp_logo_palette
));
632 bmap
= &bmp_logo_bitmap
[0];
633 fb
= (uchar
*)(lcd_base
+ y
* lcd_line_length
+ x
* bpix
/ 8);
636 /* Leave room for default color map
637 * default case: generic system with no cmap (most likely 16bpp)
638 * cmap was set to the source palette, so no change is done.
639 * This avoids even more ifdefs in the next stanza
641 #if defined(CONFIG_MPC823)
642 cmap
= (ushort
*) &(cp
->lcd_cmap
[BMP_LOGO_OFFSET
* sizeof(ushort
)]);
643 #elif defined(CONFIG_ATMEL_LCD)
644 cmap
= (uint
*)configuration_get_cmap();
646 cmap
= configuration_get_cmap();
652 for (i
= 0; i
< ARRAY_SIZE(bmp_logo_palette
); ++i
) {
653 ushort colreg
= bmp_logo_palette
[i
];
654 #ifdef CONFIG_ATMEL_LCD
656 #ifdef CONFIG_ATMEL_LCD_BGR555
657 lut_entry
= ((colreg
& 0x000F) << 11) |
658 ((colreg
& 0x00F0) << 2) |
659 ((colreg
& 0x0F00) >> 7);
660 #else /* CONFIG_ATMEL_LCD_RGB565 */
661 lut_entry
= ((colreg
& 0x000F) << 1) |
662 ((colreg
& 0x00F0) << 3) |
663 ((colreg
& 0x0F00) << 4);
665 *(cmap
+ BMP_LOGO_OFFSET
) = lut_entry
;
667 #else /* !CONFIG_ATMEL_LCD */
669 #endif /* CONFIG_ATMEL_LCD */
674 for (i
= 0; i
< BMP_LOGO_HEIGHT
; ++i
) {
675 memcpy(fb
, bmap
, BMP_LOGO_WIDTH
);
676 bmap
+= BMP_LOGO_WIDTH
;
677 fb
+= panel_info
.vl_col
;
680 else { /* true color mode */
683 for (i
= 0; i
< BMP_LOGO_HEIGHT
; ++i
) {
684 for (j
= 0; j
< BMP_LOGO_WIDTH
; j
++) {
685 col16
= bmp_logo_palette
[(bmap
[j
]-16)];
687 ((col16
& 0x000F) << 1) |
688 ((col16
& 0x00F0) << 3) |
689 ((col16
& 0x0F00) << 4);
691 bmap
+= BMP_LOGO_WIDTH
;
692 fb16
+= panel_info
.vl_col
;
700 static inline void bitmap_plot(int x
, int y
) {}
701 #endif /* CONFIG_LCD_LOGO */
703 /*----------------------------------------------------------------------*/
704 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
706 * Display the BMP file located at address bmp_image.
710 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
711 #define BMP_ALIGN_CENTER 0x7FFF
713 static void splash_align_axis(int *axis
, unsigned long panel_size
,
714 unsigned long picture_size
)
716 unsigned long panel_picture_delta
= panel_size
- picture_size
;
717 unsigned long axis_alignment
;
719 if (*axis
== BMP_ALIGN_CENTER
)
720 axis_alignment
= panel_picture_delta
/ 2;
722 axis_alignment
= panel_picture_delta
+ *axis
+ 1;
726 *axis
= max(0, (int)axis_alignment
);
731 #ifdef CONFIG_LCD_BMP_RLE8
733 #define BMP_RLE8_ESCAPE 0
734 #define BMP_RLE8_EOL 0
735 #define BMP_RLE8_EOBMP 1
736 #define BMP_RLE8_DELTA 2
738 static void draw_unencoded_bitmap(ushort
**fbp
, uchar
*bmap
, ushort
*cmap
,
742 *(*fbp
)++ = cmap
[*bmap
++];
747 static void draw_encoded_bitmap(ushort
**fbp
, ushort c
, int cnt
)
750 int cnt_8copy
= cnt
>> 3;
752 cnt
-= cnt_8copy
<< 3;
753 while (cnt_8copy
> 0) {
772 * Do not call this function directly, must be called from lcd_display_bitmap.
774 static void lcd_display_rle8_bitmap(bmp_image_t
*bmp
, ushort
*cmap
, uchar
*fb
,
775 int x_off
, int y_off
)
783 width
= get_unaligned_le32(&bmp
->header
.width
);
784 height
= get_unaligned_le32(&bmp
->header
.height
);
785 bmap
= (uchar
*)bmp
+ get_unaligned_le32(&bmp
->header
.data_offset
);
791 if (bmap
[0] == BMP_RLE8_ESCAPE
) {
798 /* 16bpix, 2-byte per pixel, width should *2 */
799 fb
-= (width
* 2 + lcd_line_length
);
809 /* 16bpix, 2-byte per pixel, x should *2 */
810 fb
= (uchar
*) (lcd_base
+ (y
+ y_off
- 1)
811 * lcd_line_length
+ (x
+ x_off
) * 2);
820 if (x
+ runlen
> width
)
824 draw_unencoded_bitmap(
839 /* aggregate the same code */
840 while (bmap
[0] == 0xff &&
841 bmap
[2] != BMP_RLE8_ESCAPE
&&
842 bmap
[1] == bmap
[3]) {
846 if (x
+ runlen
> width
)
850 draw_encoded_bitmap((ushort
**)&fb
,
861 #if defined(CONFIG_MPC823)
862 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
864 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
867 #if defined(CONFIG_BMP_16BPP)
868 #if defined(CONFIG_ATMEL_LCD_BGR555)
869 static inline void fb_put_word(uchar
**fb
, uchar
**from
)
871 *(*fb
)++ = (((*from
)[0] & 0x1f) << 2) | ((*from
)[1] & 0x03);
872 *(*fb
)++ = ((*from
)[0] & 0xe0) | (((*from
)[1] & 0x7c) >> 2);
876 static inline void fb_put_word(uchar
**fb
, uchar
**from
)
878 *(*fb
)++ = *(*from
)++;
879 *(*fb
)++ = *(*from
)++;
882 #endif /* CONFIG_BMP_16BPP */
884 int lcd_display_bitmap(ulong bmp_image
, int x
, int y
)
887 ushort
*cmap_base
= NULL
;
890 bmp_image_t
*bmp
= (bmp_image_t
*)map_sysmem(bmp_image
, 0);
893 unsigned long width
, height
, byte_width
;
894 unsigned long pwidth
= panel_info
.vl_col
;
895 unsigned colors
, bpix
, bmp_bpix
;
897 if (!bmp
|| !(bmp
->header
.signature
[0] == 'B' &&
898 bmp
->header
.signature
[1] == 'M')) {
899 printf("Error: no valid bmp image at %lx\n", bmp_image
);
904 width
= get_unaligned_le32(&bmp
->header
.width
);
905 height
= get_unaligned_le32(&bmp
->header
.height
);
906 bmp_bpix
= get_unaligned_le16(&bmp
->header
.bit_count
);
908 colors
= 1 << bmp_bpix
;
910 bpix
= NBITS(panel_info
.vl_bpix
);
912 if (bpix
!= 1 && bpix
!= 8 && bpix
!= 16 && bpix
!= 32) {
913 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
920 * We support displaying 8bpp BMPs on 16bpp LCDs
921 * and displaying 24bpp BMPs on 32bpp LCDs
923 if (bpix
!= bmp_bpix
&&
924 !(bmp_bpix
== 8 && bpix
== 16) &&
925 !(bmp_bpix
== 24 && bpix
== 32)) {
926 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
927 bpix
, get_unaligned_le16(&bmp
->header
.bit_count
));
931 debug("Display-bmp: %d x %d with %d colors\n",
932 (int)width
, (int)height
, (int)colors
);
935 cmap
= configuration_get_cmap();
939 for (i
= 0; i
< colors
; ++i
) {
940 bmp_color_table_entry_t cte
= bmp
->color_table
[i
];
941 #if !defined(CONFIG_ATMEL_LCD)
943 ( ((cte
.red
) << 8) & 0xf800) |
944 ( ((cte
.green
) << 3) & 0x07e0) |
945 ( ((cte
.blue
) >> 3) & 0x001f) ;
947 #if defined(CONFIG_MPC823)
952 #else /* CONFIG_ATMEL_LCD */
953 lcd_setcolreg(i
, cte
.red
, cte
.green
, cte
.blue
);
958 padded_width
= (width
& 0x3 ? (width
& ~0x3) + 4 : width
);
960 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
961 splash_align_axis(&x
, pwidth
, width
);
962 splash_align_axis(&y
, panel_info
.vl_row
, height
);
963 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
965 if ((x
+ width
) > pwidth
)
967 if ((y
+ height
) > panel_info
.vl_row
)
968 height
= panel_info
.vl_row
- y
;
970 bmap
= (uchar
*)bmp
+ get_unaligned_le32(&bmp
->header
.data_offset
);
971 fb
= (uchar
*)(lcd_base
+
972 (y
+ height
- 1) * lcd_line_length
+ x
* bpix
/ 8);
975 case 1: /* pass through */
977 #ifdef CONFIG_LCD_BMP_RLE8
978 u32 compression
= get_unaligned_le32(&bmp
->header
.compression
);
979 if (compression
== BMP_BI_RLE8
) {
981 /* TODO implement render code for bpix != 16 */
982 printf("Error: only support 16 bpix");
985 lcd_display_rle8_bitmap(bmp
, cmap_base
, fb
, x
, y
);
993 byte_width
= width
* 2;
995 for (i
= 0; i
< height
; ++i
) {
997 for (j
= 0; j
< width
; j
++) {
999 FB_PUT_BYTE(fb
, bmap
);
1001 *(uint16_t *)fb
= cmap_base
[*(bmap
++)];
1002 fb
+= sizeof(uint16_t) / sizeof(*fb
);
1005 bmap
+= (padded_width
- width
);
1006 fb
-= byte_width
+ lcd_line_length
;
1010 #if defined(CONFIG_BMP_16BPP)
1012 for (i
= 0; i
< height
; ++i
) {
1014 for (j
= 0; j
< width
; j
++)
1015 fb_put_word(&fb
, &bmap
);
1017 bmap
+= (padded_width
- width
) * 2;
1018 fb
-= width
* 2 + lcd_line_length
;
1021 #endif /* CONFIG_BMP_16BPP */
1022 #if defined(CONFIG_BMP_24BMP)
1024 for (i
= 0; i
< height
; ++i
) {
1025 for (j
= 0; j
< width
; j
++) {
1026 *(fb
++) = *(bmap
++);
1027 *(fb
++) = *(bmap
++);
1028 *(fb
++) = *(bmap
++);
1031 fb
-= lcd_line_length
+ width
* (bpix
/ 8);
1034 #endif /* CONFIG_BMP_24BMP */
1035 #if defined(CONFIG_BMP_32BPP)
1037 for (i
= 0; i
< height
; ++i
) {
1038 for (j
= 0; j
< width
; j
++) {
1039 *(fb
++) = *(bmap
++);
1040 *(fb
++) = *(bmap
++);
1041 *(fb
++) = *(bmap
++);
1042 *(fb
++) = *(bmap
++);
1044 fb
-= lcd_line_length
+ width
* (bpix
/ 8);
1047 #endif /* CONFIG_BMP_32BPP */
1057 static void *lcd_logo(void)
1059 #ifdef CONFIG_SPLASH_SCREEN
1062 static int do_splash
= 1;
1064 if (do_splash
&& (s
= getenv("splashimage")) != NULL
) {
1068 if (splash_screen_prepare())
1069 return (void *)lcd_base
;
1071 addr
= simple_strtoul (s
, NULL
, 16);
1073 splash_get_pos(&x
, &y
);
1075 if (bmp_display(addr
, x
, y
) == 0)
1076 return (void *)lcd_base
;
1078 #endif /* CONFIG_SPLASH_SCREEN */
1082 #ifdef CONFIG_LCD_INFO
1083 lcd_set_col(LCD_INFO_X
/ VIDEO_FONT_WIDTH
);
1084 lcd_set_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_curr_col
= min_t(short, col
, console_cols
- 1);
1122 console_curr_row
= min_t(short, 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
;
1145 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1146 static int lcd_dt_simplefb_configure_node(void *blob
, int off
)
1148 #if LCD_BPP == LCD_COLOR16
1149 return fdt_setup_simplefb_node(blob
, off
, gd
->fb_base
,
1150 panel_info
.vl_col
, panel_info
.vl_row
,
1151 panel_info
.vl_col
* 2, "r5g6b5");
1157 int lcd_dt_simplefb_add_node(void *blob
)
1159 static const char compat
[] = "simple-framebuffer";
1160 static const char disabled
[] = "disabled";
1163 off
= fdt_add_subnode(blob
, 0, "framebuffer");
1167 ret
= fdt_setprop(blob
, off
, "status", disabled
, sizeof(disabled
));
1171 ret
= fdt_setprop(blob
, off
, "compatible", compat
, sizeof(compat
));
1175 return lcd_dt_simplefb_configure_node(blob
, off
);
1178 int lcd_dt_simplefb_enable_existing_node(void *blob
)
1182 off
= fdt_node_offset_by_compatible(blob
, -1, "simple-framebuffer");
1186 return lcd_dt_simplefb_configure_node(blob
, off
);