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)
32 #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
33 defined(CONFIG_CPU_MONAHANS)
34 #define CONFIG_CPU_PXA
35 #include <asm/byteorder.h>
38 #if defined(CONFIG_MPC823)
42 #if defined(CONFIG_ATMEL_LCD)
43 #include <atmel_lcdc.h>
46 #if defined(CONFIG_LCD_DT_SIMPLEFB)
50 /************************************************************************/
52 /************************************************************************/
53 #include <video_font.h> /* Get font data, width and height */
55 /************************************************************************/
57 /************************************************************************/
58 #ifdef CONFIG_LCD_LOGO
59 # include <bmp_logo.h> /* Get logo data, width and height */
60 # include <bmp_logo_data.h>
61 # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
62 # error Default Color Map overlaps with Logo Color Map
66 #ifndef CONFIG_LCD_ALIGNMENT
67 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
70 /* By default we scroll by a single line */
71 #ifndef CONFIG_CONSOLE_SCROLL_LINES
72 #define CONFIG_CONSOLE_SCROLL_LINES 1
75 /************************************************************************/
76 /* ** CONSOLE DEFINITIONS & FUNCTIONS */
77 /************************************************************************/
78 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
79 # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
82 # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
85 #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
86 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
87 #define CONSOLE_ROW_FIRST lcd_console_address
88 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
89 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
91 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
92 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
94 #if LCD_BPP == LCD_MONOCHROME
95 # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
96 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
97 #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
98 # define COLOR_MASK(c) (c)
100 # error Unsupported LCD BPP.
103 DECLARE_GLOBAL_DATA_PTR
;
105 static void lcd_drawchars(ushort x
, ushort y
, uchar
*str
, int count
);
106 static inline void lcd_puts_xy(ushort x
, ushort y
, uchar
*s
);
107 static inline void lcd_putc_xy(ushort x
, ushort y
, uchar c
);
109 static int lcd_init(void *lcdbase
);
111 static void *lcd_logo(void);
113 static int lcd_getbgcolor(void);
114 static void lcd_setfgcolor(int color
);
115 static void lcd_setbgcolor(int color
);
117 static int lcd_color_fg
;
118 static int lcd_color_bg
;
121 char lcd_is_enabled
= 0;
123 static short console_col
;
124 static short console_row
;
126 static void *lcd_console_address
;
127 static void *lcd_base
; /* Start of framebuffer memory */
129 static char lcd_flush_dcache
; /* 1 to flush dcache after each lcd update */
131 /************************************************************************/
133 /* Flush LCD activity to the caches */
137 * flush_dcache_range() is declared in common.h but it seems that some
138 * architectures do not actually implement it. Is there a way to find
139 * out whether it exists? For now, ARM is safe.
141 #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
144 if (lcd_flush_dcache
)
145 flush_dcache_range((u32
)lcd_base
,
146 (u32
)(lcd_base
+ lcd_get_size(&line_length
)));
150 void lcd_set_flush_dcache(int flush
)
152 lcd_flush_dcache
= (flush
!= 0);
155 /*----------------------------------------------------------------------*/
157 static void console_scrollup(void)
159 const int rows
= CONFIG_CONSOLE_SCROLL_LINES
;
161 /* Copy up rows ignoring those that will be overwritten */
162 memcpy(CONSOLE_ROW_FIRST
,
163 lcd_console_address
+ CONSOLE_ROW_SIZE
* rows
,
164 CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
);
166 /* Clear the last rows */
167 memset(lcd_console_address
+ CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
,
168 COLOR_MASK(lcd_color_bg
),
169 CONSOLE_ROW_SIZE
* rows
);
175 /*----------------------------------------------------------------------*/
177 static inline void console_back(void)
179 if (--console_col
< 0) {
180 console_col
= CONSOLE_COLS
-1 ;
181 if (--console_row
< 0)
185 lcd_putc_xy(console_col
* VIDEO_FONT_WIDTH
,
186 console_row
* VIDEO_FONT_HEIGHT
, ' ');
189 /*----------------------------------------------------------------------*/
191 static inline void console_newline(void)
195 /* Check if we need to scroll the terminal */
196 if (++console_row
>= CONSOLE_ROWS
)
202 /*----------------------------------------------------------------------*/
204 void lcd_putc(const char c
)
206 if (!lcd_is_enabled
) {
221 case '\t': /* Tab (8 chars alignment) */
225 if (console_col
>= CONSOLE_COLS
)
234 lcd_putc_xy(console_col
* VIDEO_FONT_WIDTH
,
235 console_row
* VIDEO_FONT_HEIGHT
, c
);
236 if (++console_col
>= CONSOLE_COLS
)
241 /*----------------------------------------------------------------------*/
243 void lcd_puts(const char *s
)
245 if (!lcd_is_enabled
) {
257 /*----------------------------------------------------------------------*/
259 void lcd_printf(const char *fmt
, ...)
262 char buf
[CONFIG_SYS_PBSIZE
];
265 vsprintf(buf
, fmt
, args
);
271 /************************************************************************/
272 /* ** Low-Level Graphics Routines */
273 /************************************************************************/
275 static void lcd_drawchars(ushort x
, ushort y
, uchar
*str
, int count
)
280 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
281 y
+= BMP_LOGO_HEIGHT
;
284 #if LCD_BPP == LCD_MONOCHROME
285 ushort off
= x
* (1 << LCD_BPP
) % 8;
288 dest
= (uchar
*)(lcd_base
+ y
* lcd_line_length
+ x
* (1 << LCD_BPP
) / 8);
290 for (row
= 0; row
< VIDEO_FONT_HEIGHT
; ++row
, dest
+= lcd_line_length
) {
293 #if LCD_BPP == LCD_COLOR16
294 ushort
*d
= (ushort
*)dest
;
299 #if LCD_BPP == LCD_MONOCHROME
300 uchar rest
= *d
& -(1 << (8 - off
));
303 for (i
= 0; i
< count
; ++i
) {
307 bits
= video_fontdata
[c
* VIDEO_FONT_HEIGHT
+ row
];
309 #if LCD_BPP == LCD_MONOCHROME
310 sym
= (COLOR_MASK(lcd_color_fg
) & bits
) |
311 (COLOR_MASK(lcd_color_bg
) & ~bits
);
313 *d
++ = rest
| (sym
>> off
);
314 rest
= sym
<< (8-off
);
315 #elif LCD_BPP == LCD_COLOR8
316 for (c
= 0; c
< 8; ++c
) {
317 *d
++ = (bits
& 0x80) ?
318 lcd_color_fg
: lcd_color_bg
;
321 #elif LCD_BPP == LCD_COLOR16
322 for (c
= 0; c
< 8; ++c
) {
323 *d
++ = (bits
& 0x80) ?
324 lcd_color_fg
: lcd_color_bg
;
329 #if LCD_BPP == LCD_MONOCHROME
330 *d
= rest
| (*d
& ((1 << (8 - off
)) - 1));
335 /*----------------------------------------------------------------------*/
337 static inline void lcd_puts_xy(ushort x
, ushort y
, uchar
*s
)
339 lcd_drawchars(x
, y
, s
, strlen((char *)s
));
342 /*----------------------------------------------------------------------*/
344 static inline void lcd_putc_xy(ushort x
, ushort y
, uchar c
)
346 lcd_drawchars(x
, y
, &c
, 1);
349 /************************************************************************/
350 /** Small utility to check that you got the colours right */
351 /************************************************************************/
352 #ifdef LCD_TEST_PATTERN
357 static int test_colors
[N_BLK_HOR
* N_BLK_VERT
] = {
358 CONSOLE_COLOR_RED
, CONSOLE_COLOR_GREEN
, CONSOLE_COLOR_YELLOW
,
359 CONSOLE_COLOR_BLUE
, CONSOLE_COLOR_MAGENTA
, CONSOLE_COLOR_CYAN
,
362 static void test_pattern(void)
364 ushort v_max
= panel_info
.vl_row
;
365 ushort h_max
= panel_info
.vl_col
;
366 ushort v_step
= (v_max
+ N_BLK_VERT
- 1) / N_BLK_VERT
;
367 ushort h_step
= (h_max
+ N_BLK_HOR
- 1) / N_BLK_HOR
;
369 uchar
*pix
= (uchar
*)lcd_base
;
371 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
372 h_max
, v_max
, h_step
, v_step
);
374 /* WARNING: Code silently assumes 8bit/pixel */
375 for (v
= 0; v
< v_max
; ++v
) {
376 uchar iy
= v
/ v_step
;
377 for (h
= 0; h
< h_max
; ++h
) {
378 uchar ix
= N_BLK_HOR
* iy
+ h
/ h_step
;
379 *pix
++ = test_colors
[ix
];
383 #endif /* LCD_TEST_PATTERN */
386 /************************************************************************/
387 /* ** GENERIC Initialization Routines */
388 /************************************************************************/
390 int lcd_get_size(int *line_length
)
392 *line_length
= (panel_info
.vl_col
* NBITS(panel_info
.vl_bpix
)) / 8;
393 return *line_length
* panel_info
.vl_row
;
396 int drv_lcd_init(void)
398 struct stdio_dev lcddev
;
401 lcd_base
= (void *) gd
->fb_base
;
403 lcd_init(lcd_base
); /* LCD initialization */
405 /* Device initialization */
406 memset(&lcddev
, 0, sizeof(lcddev
));
408 strcpy(lcddev
.name
, "lcd");
409 lcddev
.ext
= 0; /* No extensions */
410 lcddev
.flags
= DEV_FLAGS_OUTPUT
; /* Output only */
411 lcddev
.putc
= lcd_putc
; /* 'putc' function */
412 lcddev
.puts
= lcd_puts
; /* 'puts' function */
414 rc
= stdio_register(&lcddev
);
416 return (rc
== 0) ? 1 : rc
;
419 /*----------------------------------------------------------------------*/
422 #if LCD_BPP == LCD_MONOCHROME
423 /* Setting the palette */
426 #elif LCD_BPP == LCD_COLOR8
427 /* Setting the palette */
428 lcd_setcolreg(CONSOLE_COLOR_BLACK
, 0, 0, 0);
429 lcd_setcolreg(CONSOLE_COLOR_RED
, 0xFF, 0, 0);
430 lcd_setcolreg(CONSOLE_COLOR_GREEN
, 0, 0xFF, 0);
431 lcd_setcolreg(CONSOLE_COLOR_YELLOW
, 0xFF, 0xFF, 0);
432 lcd_setcolreg(CONSOLE_COLOR_BLUE
, 0, 0, 0xFF);
433 lcd_setcolreg(CONSOLE_COLOR_MAGENTA
, 0xFF, 0, 0xFF);
434 lcd_setcolreg(CONSOLE_COLOR_CYAN
, 0, 0xFF, 0xFF);
435 lcd_setcolreg(CONSOLE_COLOR_GREY
, 0xAA, 0xAA, 0xAA);
436 lcd_setcolreg(CONSOLE_COLOR_WHITE
, 0xFF, 0xFF, 0xFF);
439 #ifndef CONFIG_SYS_WHITE_ON_BLACK
440 lcd_setfgcolor(CONSOLE_COLOR_BLACK
);
441 lcd_setbgcolor(CONSOLE_COLOR_WHITE
);
443 lcd_setfgcolor(CONSOLE_COLOR_WHITE
);
444 lcd_setbgcolor(CONSOLE_COLOR_BLACK
);
445 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
447 #ifdef LCD_TEST_PATTERN
450 /* set framebuffer to background color */
451 memset((char *)lcd_base
,
452 COLOR_MASK(lcd_getbgcolor()),
453 lcd_line_length
* panel_info
.vl_row
);
455 /* Paint the logo and retrieve LCD base address */
456 debug("[LCD] Drawing the logo...\n");
457 lcd_console_address
= lcd_logo();
464 static int do_lcd_clear(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
472 cls
, 1, 1, do_lcd_clear
,
477 /*----------------------------------------------------------------------*/
479 static int lcd_init(void *lcdbase
)
481 /* Initialize the lcd controller */
482 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase
);
484 lcd_ctrl_init(lcdbase
);
487 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
488 * the 'lcdbase' argument and uses custom lcd base address
489 * by setting up gd->fb_base. Check for this condition and fixup
490 * 'lcd_base' address.
492 if ((unsigned long)lcdbase
!= gd
->fb_base
)
493 lcd_base
= (void *)gd
->fb_base
;
495 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base
);
497 lcd_get_size(&lcd_line_length
);
498 lcd_line_length
= (panel_info
.vl_col
* NBITS(panel_info
.vl_bpix
)) / 8;
503 /* Initialize the console */
505 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
506 console_row
= 7 + BMP_LOGO_HEIGHT
/ VIDEO_FONT_HEIGHT
;
508 console_row
= 1; /* leave 1 blank line below logo */
515 /************************************************************************/
516 /* ** ROM capable initialization part - needed to reserve FB memory */
517 /************************************************************************/
519 * This is called early in the system initialization to grab memory
520 * for the LCD controller.
521 * Returns new address for monitor, after reserving LCD buffer memory
523 * Note that this is running from ROM, so no write access to global data.
525 ulong
lcd_setmem(ulong addr
)
530 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info
.vl_col
,
531 panel_info
.vl_row
, NBITS(panel_info
.vl_bpix
));
533 size
= lcd_get_size(&line_length
);
535 /* Round up to nearest full page, or MMU section if defined */
536 size
= ALIGN(size
, CONFIG_LCD_ALIGNMENT
);
537 addr
= ALIGN(addr
- CONFIG_LCD_ALIGNMENT
+ 1, CONFIG_LCD_ALIGNMENT
);
539 /* Allocate pages for the frame buffer. */
542 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
548 /*----------------------------------------------------------------------*/
550 static void lcd_setfgcolor(int color
)
552 lcd_color_fg
= color
;
555 /*----------------------------------------------------------------------*/
557 static void lcd_setbgcolor(int color
)
559 lcd_color_bg
= color
;
562 /*----------------------------------------------------------------------*/
564 int lcd_getfgcolor(void)
569 /*----------------------------------------------------------------------*/
571 static int lcd_getbgcolor(void)
576 /************************************************************************/
577 /* ** Chipset depending Bitmap / Logo stuff... */
578 /************************************************************************/
579 static inline ushort
*configuration_get_cmap(void)
581 #if defined CONFIG_CPU_PXA
582 struct pxafb_info
*fbi
= &panel_info
.pxa
;
583 return (ushort
*)fbi
->palette
;
584 #elif defined(CONFIG_MPC823)
585 immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
586 cpm8xx_t
*cp
= &(immr
->im_cpm
);
587 return (ushort
*)&(cp
->lcd_cmap
[255 * sizeof(ushort
)]);
588 #elif defined(CONFIG_ATMEL_LCD)
589 return (ushort
*)(panel_info
.mmio
+ ATMEL_LCDC_LUT(0));
590 #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
591 return panel_info
.cmap
;
592 #elif defined(CONFIG_LCD_LOGO)
593 return bmp_logo_palette
;
599 #ifdef CONFIG_LCD_LOGO
600 void bitmap_plot(int x
, int y
)
602 #ifdef CONFIG_ATMEL_LCD
603 uint
*cmap
= (uint
*)bmp_logo_palette
;
605 ushort
*cmap
= (ushort
*)bmp_logo_palette
;
611 #if defined(CONFIG_MPC823)
612 immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
613 cpm8xx_t
*cp
= &(immr
->im_cpm
);
615 unsigned bpix
= NBITS(panel_info
.vl_bpix
);
617 debug("Logo: width %d height %d colors %d cmap %d\n",
618 BMP_LOGO_WIDTH
, BMP_LOGO_HEIGHT
, BMP_LOGO_COLORS
,
619 ARRAY_SIZE(bmp_logo_palette
));
621 bmap
= &bmp_logo_bitmap
[0];
622 fb
= (uchar
*)(lcd_base
+ y
* lcd_line_length
+ x
* bpix
/ 8);
625 /* Leave room for default color map
626 * default case: generic system with no cmap (most likely 16bpp)
627 * cmap was set to the source palette, so no change is done.
628 * This avoids even more ifdefs in the next stanza
630 #if defined(CONFIG_MPC823)
631 cmap
= (ushort
*) &(cp
->lcd_cmap
[BMP_LOGO_OFFSET
* sizeof(ushort
)]);
632 #elif defined(CONFIG_ATMEL_LCD)
633 cmap
= (uint
*)configuration_get_cmap();
635 cmap
= configuration_get_cmap();
641 for (i
= 0; i
< ARRAY_SIZE(bmp_logo_palette
); ++i
) {
642 ushort colreg
= bmp_logo_palette
[i
];
643 #ifdef CONFIG_ATMEL_LCD
645 #ifdef CONFIG_ATMEL_LCD_BGR555
646 lut_entry
= ((colreg
& 0x000F) << 11) |
647 ((colreg
& 0x00F0) << 2) |
648 ((colreg
& 0x0F00) >> 7);
649 #else /* CONFIG_ATMEL_LCD_RGB565 */
650 lut_entry
= ((colreg
& 0x000F) << 1) |
651 ((colreg
& 0x00F0) << 3) |
652 ((colreg
& 0x0F00) << 4);
654 *(cmap
+ BMP_LOGO_OFFSET
) = lut_entry
;
656 #else /* !CONFIG_ATMEL_LCD */
657 #ifdef CONFIG_SYS_INVERT_COLORS
658 *cmap
++ = 0xffff - colreg
;
662 #endif /* CONFIG_ATMEL_LCD */
667 for (i
= 0; i
< BMP_LOGO_HEIGHT
; ++i
) {
668 memcpy(fb
, bmap
, BMP_LOGO_WIDTH
);
669 bmap
+= BMP_LOGO_WIDTH
;
670 fb
+= panel_info
.vl_col
;
673 else { /* true color mode */
676 for (i
= 0; i
< BMP_LOGO_HEIGHT
; ++i
) {
677 for (j
= 0; j
< BMP_LOGO_WIDTH
; j
++) {
678 col16
= bmp_logo_palette
[(bmap
[j
]-16)];
680 ((col16
& 0x000F) << 1) |
681 ((col16
& 0x00F0) << 3) |
682 ((col16
& 0x0F00) << 4);
684 bmap
+= BMP_LOGO_WIDTH
;
685 fb16
+= panel_info
.vl_col
;
693 static inline void bitmap_plot(int x
, int y
) {}
694 #endif /* CONFIG_LCD_LOGO */
696 /*----------------------------------------------------------------------*/
697 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
699 * Display the BMP file located at address bmp_image.
703 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
704 #define BMP_ALIGN_CENTER 0x7FFF
706 static void splash_align_axis(int *axis
, unsigned long panel_size
,
707 unsigned long picture_size
)
709 unsigned long panel_picture_delta
= panel_size
- picture_size
;
710 unsigned long axis_alignment
;
712 if (*axis
== BMP_ALIGN_CENTER
)
713 axis_alignment
= panel_picture_delta
/ 2;
715 axis_alignment
= panel_picture_delta
+ *axis
+ 1;
719 *axis
= max(0, axis_alignment
);
724 #ifdef CONFIG_LCD_BMP_RLE8
726 #define BMP_RLE8_ESCAPE 0
727 #define BMP_RLE8_EOL 0
728 #define BMP_RLE8_EOBMP 1
729 #define BMP_RLE8_DELTA 2
731 static void draw_unencoded_bitmap(ushort
**fbp
, uchar
*bmap
, ushort
*cmap
,
735 *(*fbp
)++ = cmap
[*bmap
++];
740 static void draw_encoded_bitmap(ushort
**fbp
, ushort c
, int cnt
)
743 int cnt_8copy
= cnt
>> 3;
745 cnt
-= cnt_8copy
<< 3;
746 while (cnt_8copy
> 0) {
765 * Do not call this function directly, must be called from lcd_display_bitmap.
767 static void lcd_display_rle8_bitmap(bmp_image_t
*bmp
, ushort
*cmap
, uchar
*fb
,
768 int x_off
, int y_off
)
776 width
= le32_to_cpu(bmp
->header
.width
);
777 height
= le32_to_cpu(bmp
->header
.height
);
778 bmap
= (uchar
*)bmp
+ le32_to_cpu(bmp
->header
.data_offset
);
784 if (bmap
[0] == BMP_RLE8_ESCAPE
) {
791 /* 16bpix, 2-byte per pixel, width should *2 */
792 fb
-= (width
* 2 + lcd_line_length
);
802 /* 16bpix, 2-byte per pixel, x should *2 */
803 fb
= (uchar
*) (lcd_base
+ (y
+ y_off
- 1)
804 * lcd_line_length
+ (x
+ x_off
) * 2);
813 if (x
+ runlen
> width
)
817 draw_unencoded_bitmap(
832 /* aggregate the same code */
833 while (bmap
[0] == 0xff &&
834 bmap
[2] != BMP_RLE8_ESCAPE
&&
835 bmap
[1] == bmap
[3]) {
839 if (x
+ runlen
> width
)
843 draw_encoded_bitmap((ushort
**)&fb
,
854 #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
855 #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
857 #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
860 #if defined(CONFIG_BMP_16BPP)
861 #if defined(CONFIG_ATMEL_LCD_BGR555)
862 static inline void fb_put_word(uchar
**fb
, uchar
**from
)
864 *(*fb
)++ = (((*from
)[0] & 0x1f) << 2) | ((*from
)[1] & 0x03);
865 *(*fb
)++ = ((*from
)[0] & 0xe0) | (((*from
)[1] & 0x7c) >> 2);
869 static inline void fb_put_word(uchar
**fb
, uchar
**from
)
871 *(*fb
)++ = *(*from
)++;
872 *(*fb
)++ = *(*from
)++;
875 #endif /* CONFIG_BMP_16BPP */
877 int lcd_display_bitmap(ulong bmp_image
, int x
, int y
)
879 #if !defined(CONFIG_MCC200)
882 ushort
*cmap_base
= NULL
;
885 bmp_image_t
*bmp
=(bmp_image_t
*)bmp_image
;
888 unsigned long width
, height
, byte_width
;
889 unsigned long pwidth
= panel_info
.vl_col
;
890 unsigned colors
, bpix
, bmp_bpix
;
892 if (!bmp
|| !(bmp
->header
.signature
[0] == 'B' &&
893 bmp
->header
.signature
[1] == 'M')) {
894 printf("Error: no valid bmp image at %lx\n", bmp_image
);
899 width
= le32_to_cpu(bmp
->header
.width
);
900 height
= le32_to_cpu(bmp
->header
.height
);
901 bmp_bpix
= le16_to_cpu(bmp
->header
.bit_count
);
902 colors
= 1 << bmp_bpix
;
904 bpix
= NBITS(panel_info
.vl_bpix
);
906 if (bpix
!= 1 && bpix
!= 8 && bpix
!= 16 && bpix
!= 32) {
907 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
913 /* We support displaying 8bpp BMPs on 16bpp LCDs */
914 if (bpix
!= bmp_bpix
&& !(bmp_bpix
== 8 && bpix
== 16)) {
915 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
917 le16_to_cpu(bmp
->header
.bit_count
));
922 debug("Display-bmp: %d x %d with %d colors\n",
923 (int)width
, (int)height
, (int)colors
);
925 #if !defined(CONFIG_MCC200)
926 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
928 cmap
= configuration_get_cmap();
932 for (i
= 0; i
< colors
; ++i
) {
933 bmp_color_table_entry_t cte
= bmp
->color_table
[i
];
934 #if !defined(CONFIG_ATMEL_LCD)
936 ( ((cte
.red
) << 8) & 0xf800) |
937 ( ((cte
.green
) << 3) & 0x07e0) |
938 ( ((cte
.blue
) >> 3) & 0x001f) ;
939 #ifdef CONFIG_SYS_INVERT_COLORS
940 *cmap
= 0xffff - colreg
;
944 #if defined(CONFIG_MPC823)
949 #else /* CONFIG_ATMEL_LCD */
950 lcd_setcolreg(i
, cte
.red
, cte
.green
, cte
.blue
);
957 * BMP format for Monochrome assumes that the state of a
958 * pixel is described on a per Bit basis, not per Byte.
959 * So, in case of Monochrome BMP we should align widths
960 * on a byte boundary and convert them from Bit to Byte
962 * Probably, PXA250 and MPC823 process 1bpp BMP images in
963 * their own ways, so make the converting to be MCC200
966 #if defined(CONFIG_MCC200)
968 width
= ((width
+ 7) & ~7) >> 3;
969 x
= ((x
+ 7) & ~7) >> 3;
970 pwidth
= ((pwidth
+ 7) & ~7) >> 3;
974 padded_width
= (width
& 0x3 ? (width
& ~0x3) + 4 : width
);
976 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
977 splash_align_axis(&x
, pwidth
, width
);
978 splash_align_axis(&y
, panel_info
.vl_row
, height
);
979 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
981 if ((x
+ width
) > pwidth
)
983 if ((y
+ height
) > panel_info
.vl_row
)
984 height
= panel_info
.vl_row
- y
;
986 bmap
= (uchar
*) bmp
+ le32_to_cpu(bmp
->header
.data_offset
);
987 fb
= (uchar
*) (lcd_base
+
988 (y
+ height
- 1) * lcd_line_length
+ x
* bpix
/ 8);
991 case 1: /* pass through */
993 #ifdef CONFIG_LCD_BMP_RLE8
994 if (le32_to_cpu(bmp
->header
.compression
) == BMP_BI_RLE8
) {
996 /* TODO implement render code for bpix != 16 */
997 printf("Error: only support 16 bpix");
1000 lcd_display_rle8_bitmap(bmp
, cmap_base
, fb
, x
, y
);
1008 byte_width
= width
* 2;
1010 for (i
= 0; i
< height
; ++i
) {
1012 for (j
= 0; j
< width
; j
++) {
1014 FB_PUT_BYTE(fb
, bmap
);
1016 *(uint16_t *)fb
= cmap_base
[*(bmap
++)];
1017 fb
+= sizeof(uint16_t) / sizeof(*fb
);
1020 bmap
+= (padded_width
- width
);
1021 fb
-= byte_width
+ lcd_line_length
;
1025 #if defined(CONFIG_BMP_16BPP)
1027 for (i
= 0; i
< height
; ++i
) {
1029 for (j
= 0; j
< width
; j
++)
1030 fb_put_word(&fb
, &bmap
);
1032 bmap
+= (padded_width
- width
) * 2;
1033 fb
-= width
* 2 + lcd_line_length
;
1036 #endif /* CONFIG_BMP_16BPP */
1038 #if defined(CONFIG_BMP_32BPP)
1040 for (i
= 0; i
< height
; ++i
) {
1041 for (j
= 0; j
< width
; j
++) {
1042 *(fb
++) = *(bmap
++);
1043 *(fb
++) = *(bmap
++);
1044 *(fb
++) = *(bmap
++);
1045 *(fb
++) = *(bmap
++);
1047 fb
-= lcd_line_length
+ width
* (bpix
/ 8);
1050 #endif /* CONFIG_BMP_32BPP */
1060 static void *lcd_logo(void)
1062 #ifdef CONFIG_SPLASH_SCREEN
1065 static int do_splash
= 1;
1067 if (do_splash
&& (s
= getenv("splashimage")) != NULL
) {
1071 if (splash_screen_prepare())
1072 return (void *)lcd_base
;
1074 addr
= simple_strtoul (s
, NULL
, 16);
1076 splash_get_pos(&x
, &y
);
1078 if (bmp_display(addr
, x
, y
) == 0)
1079 return (void *)lcd_base
;
1081 #endif /* CONFIG_SPLASH_SCREEN */
1085 #ifdef CONFIG_LCD_INFO
1086 console_col
= LCD_INFO_X
/ VIDEO_FONT_WIDTH
;
1087 console_row
= LCD_INFO_Y
/ VIDEO_FONT_HEIGHT
;
1088 lcd_show_board_info();
1089 #endif /* CONFIG_LCD_INFO */
1091 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
1092 return (void *)((ulong
)lcd_base
+ BMP_LOGO_HEIGHT
* lcd_line_length
);
1094 return (void *)lcd_base
;
1095 #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
1098 #ifdef CONFIG_SPLASHIMAGE_GUARD
1099 static int on_splashimage(const char *name
, const char *value
, enum env_op op
,
1105 if (op
== env_op_delete
)
1108 addr
= simple_strtoul(value
, NULL
, 16);
1109 /* See README.displaying-bmps */
1110 aligned
= (addr
% 4 == 2);
1112 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1119 U_BOOT_ENV_CALLBACK(splashimage
, on_splashimage
);
1122 void lcd_position_cursor(unsigned col
, unsigned row
)
1124 console_col
= min(col
, CONSOLE_COLS
- 1);
1125 console_row
= min(row
, CONSOLE_ROWS
- 1);
1128 int lcd_get_pixel_width(void)
1130 return panel_info
.vl_col
;
1133 int lcd_get_pixel_height(void)
1135 return panel_info
.vl_row
;
1138 int lcd_get_screen_rows(void)
1140 return CONSOLE_ROWS
;
1143 int lcd_get_screen_columns(void)
1145 return CONSOLE_COLS
;
1148 #if defined(CONFIG_LCD_DT_SIMPLEFB)
1149 static int lcd_dt_simplefb_configure_node(void *blob
, int off
)
1154 static const char format
[] =
1155 #if LCD_BPP == LCD_COLOR16
1164 stride
= panel_info
.vl_col
* 2;
1166 cells
[0] = cpu_to_fdt32(gd
->fb_base
);
1167 cells
[1] = cpu_to_fdt32(stride
* panel_info
.vl_row
);
1168 ret
= fdt_setprop(blob
, off
, "reg", cells
, sizeof(cells
[0]) * 2);
1172 cells
[0] = cpu_to_fdt32(panel_info
.vl_col
);
1173 ret
= fdt_setprop(blob
, off
, "width", cells
, sizeof(cells
[0]));
1177 cells
[0] = cpu_to_fdt32(panel_info
.vl_row
);
1178 ret
= fdt_setprop(blob
, off
, "height", cells
, sizeof(cells
[0]));
1182 cells
[0] = cpu_to_fdt32(stride
);
1183 ret
= fdt_setprop(blob
, off
, "stride", cells
, sizeof(cells
[0]));
1187 ret
= fdt_setprop(blob
, off
, "format", format
, strlen(format
) + 1);
1191 ret
= fdt_delprop(blob
, off
, "status");
1198 int lcd_dt_simplefb_add_node(void *blob
)
1200 static const char compat
[] = "simple-framebuffer";
1201 static const char disabled
[] = "disabled";
1204 off
= fdt_add_subnode(blob
, 0, "framebuffer");
1208 ret
= fdt_setprop(blob
, off
, "status", disabled
, sizeof(disabled
));
1212 ret
= fdt_setprop(blob
, off
, "compatible", compat
, sizeof(compat
));
1216 return lcd_dt_simplefb_configure_node(blob
, off
);
1219 int lcd_dt_simplefb_enable_existing_node(void *blob
)
1223 off
= fdt_node_offset_by_compatible(blob
, -1, "simple-framebuffer");
1227 return lcd_dt_simplefb_configure_node(blob
, off
);