2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * SPDX-License-Identifier: GPL-2.0+
11 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
13 * At the moment only the 8x16 font is tested and the font fore- and
14 * background color is limited to black/white/gray colors. The Linux
15 * logo can be placed in the upper left corner and additional board
16 * information strings (that normally goes to serial port) can be drawn.
18 * The console driver can use a keyboard interface for character input
19 * but this is deprecated. Only rk51 uses it.
21 * Character output goes to a memory-mapped video
22 * framebuffer with little or big-endian organisation.
23 * With environment setting 'console=serial' the console i/o can be
24 * forced to serial port.
26 * The driver uses graphic specific defines/parameters/functions:
28 * (for SMI LynxE graphic chip)
30 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
31 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
32 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
34 * Console Parameters are set by graphic drivers global struct:
36 * VIDEO_VISIBLE_COLS - x resolution
37 * VIDEO_VISIBLE_ROWS - y resolution
38 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
39 * VIDEO_DATA_FORMAT - graphical data format GDF
40 * VIDEO_FB_ADRS - start of video memory
42 * VIDEO_KBD_INIT_FCT - init function for keyboard
43 * VIDEO_TSTC_FCT - keyboard_tstc function
44 * VIDEO_GETC_FCT - keyboard_getc function
46 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
47 * Use CONFIG_SPLASH_SCREEN_ALIGN with
48 * environment variable "splashpos" to place
49 * the logo on other position. In this case
50 * no CONSOLE_EXTRA_INFO is possible.
51 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
52 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
53 * strings that normaly goes to serial
54 * port. This define requires a board
56 * video_drawstring (VIDEO_INFO_X,
57 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
59 * that fills a info buffer at i=row.
60 * s.a: board/eltec/bab7xx.
61 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
62 * initialized as an output only device.
63 * The Keyboard driver will not be
64 * set-up. This may be used, if you have
65 * no or more than one Keyboard devices
66 * (USB Keyboard, AT Keyboard).
68 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
69 * character. No blinking is provided.
70 * Uses the macros CURSOR_SET and
73 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
74 * of the graphic chip. Uses the macro
75 * CURSOR_SET. ATTENTION: If booting an
76 * OS, the display driver must disable
77 * the hardware register of the graphic
78 * chip. Otherwise a blinking field is
86 #include <linux/compiler.h>
89 * Defines for the CT69000 driver
91 #ifdef CONFIG_VIDEO_CT69000
93 #define VIDEO_FB_LITTLE_ENDIAN
94 #define VIDEO_HW_RECTFILL
95 #define VIDEO_HW_BITBLT
99 * Defines for the SED13806 driver
101 #ifdef CONFIG_VIDEO_SED13806
102 #define VIDEO_FB_LITTLE_ENDIAN
103 #define VIDEO_HW_RECTFILL
104 #define VIDEO_HW_BITBLT
107 #if defined(CONFIG_VIDEO_MXS)
108 #define VIDEO_FB_16BPP_WORD_SWAP
112 * Defines for the MB862xx driver
114 #ifdef CONFIG_VIDEO_MB862xx
116 #ifdef CONFIG_VIDEO_CORALP
117 #define VIDEO_FB_LITTLE_ENDIAN
119 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
120 #define VIDEO_HW_RECTFILL
121 #define VIDEO_HW_BITBLT
126 * Defines for the i.MX31 driver (mx3fb.c)
128 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
129 #define VIDEO_FB_16BPP_WORD_SWAP
133 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
135 #include <video_fb.h>
142 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
143 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
144 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
145 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
146 #define VIDEO_FB_ADRS (pGD->frameAdrs)
153 #include <linux/types.h>
154 #include <stdio_dev.h>
155 #include <video_font.h>
157 #if defined(CONFIG_CMD_DATE)
161 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
162 #include <watchdog.h>
163 #include <bmp_layout.h>
169 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
170 * blinking is provided. Uses the macros CURSOR_SET
172 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
173 * graphic chip. Uses the macro CURSOR_SET.
174 * ATTENTION: If booting an OS, the display driver
175 * must disable the hardware register of the graphic
176 * chip. Otherwise a blinking field is displayed
178 #if !defined(CONFIG_VIDEO_SW_CURSOR) && !defined(CONFIG_VIDEO_HW_CURSOR)
179 /* no Cursor defined */
185 #if defined(CONFIG_VIDEO_SW_CURSOR)
186 #if defined(CONFIG_VIDEO_HW_CURSOR)
187 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
190 void console_cursor(int state
);
192 #define CURSOR_ON console_cursor(1)
193 #define CURSOR_OFF console_cursor(0)
194 #define CURSOR_SET video_set_cursor()
195 #endif /* CONFIG_VIDEO_SW_CURSOR */
197 #ifdef CONFIG_VIDEO_HW_CURSOR
199 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
204 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
205 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
206 #endif /* CONFIG_VIDEO_HW_CURSOR */
208 #ifdef CONFIG_VIDEO_LOGO
209 #ifdef CONFIG_VIDEO_BMP_LOGO
210 #include <bmp_logo.h>
211 #include <bmp_logo_data.h>
212 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
213 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
214 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
215 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
217 #else /* CONFIG_VIDEO_BMP_LOGO */
218 #define LINUX_LOGO_WIDTH 80
219 #define LINUX_LOGO_HEIGHT 80
220 #define LINUX_LOGO_COLORS 214
221 #define LINUX_LOGO_LUT_OFFSET 0x20
223 #include <linux_logo.h>
224 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
225 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
226 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
227 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
228 #endif /* CONFIG_VIDEO_BMP_LOGO */
229 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
230 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
231 #else /* CONFIG_VIDEO_LOGO */
232 #define VIDEO_LOGO_WIDTH 0
233 #define VIDEO_LOGO_HEIGHT 0
234 #endif /* CONFIG_VIDEO_LOGO */
236 #define VIDEO_COLS VIDEO_VISIBLE_COLS
237 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
238 #ifndef VIDEO_LINE_LEN
239 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
241 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
242 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
244 #ifdef CONFIG_VIDEO_LOGO
245 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
247 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
250 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
251 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
252 #define CONSOLE_ROW_FIRST (video_console_address)
253 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
254 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
255 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
257 /* By default we scroll by a single line */
258 #ifndef CONFIG_CONSOLE_SCROLL_LINES
259 #define CONFIG_CONSOLE_SCROLL_LINES 1
263 #ifdef VIDEO_FB_LITTLE_ENDIAN
264 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
267 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
268 (((x) & 0x0000ff00) << 8) | \
269 (((x) & 0x00ff0000) >> 8) | \
270 (((x) & 0xff000000) >> 24) \
272 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
273 (((x) & 0x0000ff00) >> 8) | \
274 (((x) & 0x00ff0000) << 8) | \
275 (((x) & 0xff000000) >> 8) \
278 #define SWAP16(x) (x)
279 #define SWAP32(x) (x)
280 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
281 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
283 #define SHORTSWAP32(x) (x)
287 #ifdef CONFIG_CONSOLE_EXTRA_INFO
289 * setup a board string: type, speed, etc.
291 * line_number: location to place info string beside logo
292 * info: buffer for info string
294 extern void video_get_info_str(int line_number
, char *info
);
297 DECLARE_GLOBAL_DATA_PTR
;
300 static GraphicDevice
*pGD
; /* Pointer to Graphic array */
302 static void *video_fb_address
; /* frame buffer address */
303 static void *video_console_address
; /* console buffer start address */
305 static int video_logo_height
= VIDEO_LOGO_HEIGHT
;
307 static int __maybe_unused cursor_state
;
308 static int __maybe_unused old_col
;
309 static int __maybe_unused old_row
;
311 static int console_col
; /* cursor col */
312 static int console_row
; /* cursor row */
314 static u32 eorx
, fgx
, bgx
; /* color pats */
316 static int cfb_do_flush_cache
;
318 #ifdef CONFIG_CFB_CONSOLE_ANSI
319 static char ansi_buf
[10];
320 static int ansi_buf_size
;
321 static int ansi_colors_need_revert
;
322 static int ansi_cursor_hidden
;
325 static const int video_font_draw_table8
[] = {
326 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
327 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
328 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
329 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
332 static const int video_font_draw_table15
[] = {
333 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
336 static const int video_font_draw_table16
[] = {
337 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
340 static const int video_font_draw_table24
[16][3] = {
341 {0x00000000, 0x00000000, 0x00000000},
342 {0x00000000, 0x00000000, 0x00ffffff},
343 {0x00000000, 0x0000ffff, 0xff000000},
344 {0x00000000, 0x0000ffff, 0xffffffff},
345 {0x000000ff, 0xffff0000, 0x00000000},
346 {0x000000ff, 0xffff0000, 0x00ffffff},
347 {0x000000ff, 0xffffffff, 0xff000000},
348 {0x000000ff, 0xffffffff, 0xffffffff},
349 {0xffffff00, 0x00000000, 0x00000000},
350 {0xffffff00, 0x00000000, 0x00ffffff},
351 {0xffffff00, 0x0000ffff, 0xff000000},
352 {0xffffff00, 0x0000ffff, 0xffffffff},
353 {0xffffffff, 0xffff0000, 0x00000000},
354 {0xffffffff, 0xffff0000, 0x00ffffff},
355 {0xffffffff, 0xffffffff, 0xff000000},
356 {0xffffffff, 0xffffffff, 0xffffffff}
359 static const int video_font_draw_table32
[16][4] = {
360 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
361 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
362 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
363 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
364 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
365 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
366 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
367 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
368 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
369 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
370 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
371 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
372 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
373 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
374 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
375 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
379 * Implement a weak default function for boards that optionally
380 * need to skip the cfb initialization.
382 __weak
int board_cfb_skip(void)
384 /* As default, don't skip cfb init */
388 static void video_drawchars(int xx
, int yy
, unsigned char *s
, int count
)
390 u8
*cdat
, *dest
, *dest0
;
393 offset
= yy
* VIDEO_LINE_LEN
+ xx
* VIDEO_PIXEL_SIZE
;
394 dest0
= video_fb_address
+ offset
;
396 switch (VIDEO_DATA_FORMAT
) {
397 case GDF__8BIT_INDEX
:
398 case GDF__8BIT_332RGB
:
401 cdat
= video_fontdata
+ c
* VIDEO_FONT_HEIGHT
;
402 for (rows
= VIDEO_FONT_HEIGHT
, dest
= dest0
;
403 rows
--; dest
+= VIDEO_LINE_LEN
) {
407 (video_font_draw_table8
[bits
>> 4] &
410 if (VIDEO_FONT_WIDTH
== 4)
414 (video_font_draw_table8
[bits
& 15] &
417 dest0
+= VIDEO_FONT_WIDTH
* VIDEO_PIXEL_SIZE
;
422 case GDF_15BIT_555RGB
:
425 cdat
= video_fontdata
+ c
* VIDEO_FONT_HEIGHT
;
426 for (rows
= VIDEO_FONT_HEIGHT
, dest
= dest0
;
427 rows
--; dest
+= VIDEO_LINE_LEN
) {
431 SHORTSWAP32((video_font_draw_table15
432 [bits
>> 6] & eorx
) ^
435 SHORTSWAP32((video_font_draw_table15
436 [bits
>> 4 & 3] & eorx
) ^
439 if (VIDEO_FONT_WIDTH
== 4)
443 SHORTSWAP32((video_font_draw_table15
444 [bits
>> 2 & 3] & eorx
) ^
447 SHORTSWAP32((video_font_draw_table15
451 dest0
+= VIDEO_FONT_WIDTH
* VIDEO_PIXEL_SIZE
;
456 case GDF_16BIT_565RGB
:
459 cdat
= video_fontdata
+ c
* VIDEO_FONT_HEIGHT
;
460 for (rows
= VIDEO_FONT_HEIGHT
, dest
= dest0
;
461 rows
--; dest
+= VIDEO_LINE_LEN
) {
465 SHORTSWAP32((video_font_draw_table16
466 [bits
>> 6] & eorx
) ^
469 SHORTSWAP32((video_font_draw_table16
470 [bits
>> 4 & 3] & eorx
) ^
473 if (VIDEO_FONT_WIDTH
== 4)
477 SHORTSWAP32((video_font_draw_table16
478 [bits
>> 2 & 3] & eorx
) ^
481 SHORTSWAP32((video_font_draw_table16
485 dest0
+= VIDEO_FONT_WIDTH
* VIDEO_PIXEL_SIZE
;
490 case GDF_32BIT_X888RGB
:
493 cdat
= video_fontdata
+ c
* VIDEO_FONT_HEIGHT
;
494 for (rows
= VIDEO_FONT_HEIGHT
, dest
= dest0
;
495 rows
--; dest
+= VIDEO_LINE_LEN
) {
499 SWAP32((video_font_draw_table32
500 [bits
>> 4][0] & eorx
) ^ bgx
);
502 SWAP32((video_font_draw_table32
503 [bits
>> 4][1] & eorx
) ^ bgx
);
505 SWAP32((video_font_draw_table32
506 [bits
>> 4][2] & eorx
) ^ bgx
);
508 SWAP32((video_font_draw_table32
509 [bits
>> 4][3] & eorx
) ^ bgx
);
512 if (VIDEO_FONT_WIDTH
== 4)
516 SWAP32((video_font_draw_table32
517 [bits
& 15][0] & eorx
) ^ bgx
);
519 SWAP32((video_font_draw_table32
520 [bits
& 15][1] & eorx
) ^ bgx
);
522 SWAP32((video_font_draw_table32
523 [bits
& 15][2] & eorx
) ^ bgx
);
525 SWAP32((video_font_draw_table32
526 [bits
& 15][3] & eorx
) ^ bgx
);
528 dest0
+= VIDEO_FONT_WIDTH
* VIDEO_PIXEL_SIZE
;
533 case GDF_24BIT_888RGB
:
536 cdat
= video_fontdata
+ c
* VIDEO_FONT_HEIGHT
;
537 for (rows
= VIDEO_FONT_HEIGHT
, dest
= dest0
;
538 rows
--; dest
+= VIDEO_LINE_LEN
) {
542 (video_font_draw_table24
[bits
>> 4][0]
545 (video_font_draw_table24
[bits
>> 4][1]
548 (video_font_draw_table24
[bits
>> 4][2]
551 if (VIDEO_FONT_WIDTH
== 4)
555 (video_font_draw_table24
[bits
& 15][0]
558 (video_font_draw_table24
[bits
& 15][1]
561 (video_font_draw_table24
[bits
& 15][2]
564 dest0
+= VIDEO_FONT_WIDTH
* VIDEO_PIXEL_SIZE
;
571 static inline void video_drawstring(int xx
, int yy
, unsigned char *s
)
573 video_drawchars(xx
, yy
, s
, strlen((char *) s
));
576 static void video_putchar(int xx
, int yy
, unsigned char c
)
578 video_drawchars(xx
, yy
+ video_logo_height
, &c
, 1);
581 #if defined(CONFIG_VIDEO_SW_CURSOR)
582 static void video_set_cursor(void)
589 static void video_invertchar(int xx
, int yy
)
591 int firstx
= xx
* VIDEO_PIXEL_SIZE
;
592 int lastx
= (xx
+ VIDEO_FONT_WIDTH
) * VIDEO_PIXEL_SIZE
;
593 int firsty
= yy
* VIDEO_LINE_LEN
;
594 int lasty
= (yy
+ VIDEO_FONT_HEIGHT
) * VIDEO_LINE_LEN
;
596 for (y
= firsty
; y
< lasty
; y
+= VIDEO_LINE_LEN
) {
597 for (x
= firstx
; x
< lastx
; x
++) {
598 u8
*dest
= (u8
*)(video_fb_address
) + x
+ y
;
604 void console_cursor(int state
)
606 if (cursor_state
!= state
) {
608 /* turn off the cursor */
609 video_invertchar(old_col
* VIDEO_FONT_WIDTH
,
610 old_row
* VIDEO_FONT_HEIGHT
+
613 /* turn off the cursor and record where it is */
614 video_invertchar(console_col
* VIDEO_FONT_WIDTH
,
615 console_row
* VIDEO_FONT_HEIGHT
+
617 old_col
= console_col
;
618 old_row
= console_row
;
620 cursor_state
= state
;
622 if (cfb_do_flush_cache
)
623 flush_cache(VIDEO_FB_ADRS
, VIDEO_SIZE
);
627 #ifndef VIDEO_HW_RECTFILL
628 static void memsetl(int *p
, int c
, int v
)
635 #ifndef VIDEO_HW_BITBLT
636 static void memcpyl(int *d
, int *s
, int c
)
643 static void console_clear_line(int line
, int begin
, int end
)
645 #ifdef VIDEO_HW_RECTFILL
646 video_hw_rectfill(VIDEO_PIXEL_SIZE
, /* bytes per pixel */
647 VIDEO_FONT_WIDTH
* begin
, /* dest pos x */
649 VIDEO_FONT_HEIGHT
* line
, /* dest pos y */
650 VIDEO_FONT_WIDTH
* (end
- begin
+ 1), /* fr. width */
651 VIDEO_FONT_HEIGHT
, /* frame height */
655 if (begin
== 0 && (end
+ 1) == CONSOLE_COLS
) {
656 memsetl(CONSOLE_ROW_FIRST
+
657 CONSOLE_ROW_SIZE
* line
, /* offset of row */
658 CONSOLE_ROW_SIZE
>> 2, /* length of row */
665 offset
= CONSOLE_ROW_FIRST
+
666 CONSOLE_ROW_SIZE
* line
+ /* offset of row */
668 VIDEO_PIXEL_SIZE
* begin
; /* offset of col */
669 size
= VIDEO_FONT_WIDTH
* VIDEO_PIXEL_SIZE
* (end
- begin
+ 1);
670 size
>>= 2; /* length to end for memsetl() */
671 /* fill at col offset of i'th line using bgx as fill color */
672 for (i
= 0; i
< VIDEO_FONT_HEIGHT
; i
++)
673 memsetl(offset
+ i
* VIDEO_LINE_LEN
, size
, bgx
);
678 static void console_scrollup(void)
680 const int rows
= CONFIG_CONSOLE_SCROLL_LINES
;
683 /* copy up rows ignoring the first one */
685 #ifdef VIDEO_HW_BITBLT
686 video_hw_bitblt(VIDEO_PIXEL_SIZE
, /* bytes per pixel */
687 0, /* source pos x */
689 VIDEO_FONT_HEIGHT
* rows
, /* source pos y */
691 video_logo_height
, /* dest pos y */
692 VIDEO_VISIBLE_COLS
, /* frame width */
695 - VIDEO_FONT_HEIGHT
* rows
/* frame height */
698 memcpyl(CONSOLE_ROW_FIRST
, CONSOLE_ROW_FIRST
+ rows
* CONSOLE_ROW_SIZE
,
699 (CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
) >> 2);
701 /* clear the last one */
702 for (i
= 1; i
<= rows
; i
++)
703 console_clear_line(CONSOLE_ROWS
- i
, 0, CONSOLE_COLS
- 1);
705 /* Decrement row number */
709 static void console_back(void)
713 if (console_col
< 0) {
714 console_col
= CONSOLE_COLS
- 1;
721 #ifdef CONFIG_CFB_CONSOLE_ANSI
723 static void console_clear(void)
725 #ifdef VIDEO_HW_RECTFILL
726 video_hw_rectfill(VIDEO_PIXEL_SIZE
, /* bytes per pixel */
728 video_logo_height
, /* dest pos y */
729 VIDEO_VISIBLE_COLS
, /* frame width */
730 VIDEO_VISIBLE_ROWS
, /* frame height */
734 memsetl(CONSOLE_ROW_FIRST
, CONSOLE_SIZE
, bgx
);
738 static void console_cursor_fix(void)
742 if (console_row
>= CONSOLE_ROWS
)
743 console_row
= CONSOLE_ROWS
- 1;
746 if (console_col
>= CONSOLE_COLS
)
747 console_col
= CONSOLE_COLS
- 1;
750 static void console_cursor_up(int n
)
753 console_cursor_fix();
756 static void console_cursor_down(int n
)
759 console_cursor_fix();
762 static void console_cursor_left(int n
)
765 console_cursor_fix();
768 static void console_cursor_right(int n
)
771 console_cursor_fix();
774 static void console_cursor_set_position(int row
, int col
)
776 if (console_row
!= -1)
778 if (console_col
!= -1)
780 console_cursor_fix();
783 static void console_previousline(int n
)
785 /* FIXME: also scroll terminal ? */
787 console_cursor_fix();
790 static void console_swap_colors(void)
798 static inline int console_cursor_is_visible(void)
800 return !ansi_cursor_hidden
;
803 static inline int console_cursor_is_visible(void)
809 static void console_newline(int n
)
814 /* Check if we need to scroll the terminal */
815 if (console_row
>= CONSOLE_ROWS
) {
816 /* Scroll everything up */
821 static void console_cr(void)
826 static void parse_putc(const char c
)
830 if (console_cursor_is_visible())
834 case 13: /* back to first column */
838 case '\n': /* next line */
839 if (console_col
|| (!console_col
&& nl
))
845 console_col
|= 0x0008;
846 console_col
&= ~0x0007;
848 if (console_col
>= CONSOLE_COLS
)
852 case 8: /* backspace */
859 default: /* draw the char */
860 video_putchar(console_col
* VIDEO_FONT_WIDTH
,
861 console_row
* VIDEO_FONT_HEIGHT
, c
);
864 /* check for newline */
865 if (console_col
>= CONSOLE_COLS
) {
871 if (console_cursor_is_visible())
875 static void video_putc(struct stdio_dev
*dev
, const char c
)
877 #ifdef CONFIG_CFB_CONSOLE_ANSI
881 for (i
= 0; i
< ansi_buf_size
; ++i
)
882 parse_putc(ansi_buf
[i
]);
888 if (ansi_buf_size
> 0) {
908 ansi_buf
[ansi_buf_size
++] = c
;
910 if (ansi_buf_size
>= sizeof(ansi_buf
))
913 for (i
= 0; i
< ansi_buf_size
; ++i
) {
919 if (ansi_buf
[i
] == 27)
926 if (ansi_buf
[i
] == '[')
933 if (ansi_buf
[i
] >= '0' && ansi_buf
[i
] <= '9') {
934 num1
= ansi_buf
[i
]-'0';
936 } else if (ansi_buf
[i
] != '?') {
944 if (ansi_buf
[i
] >= '0' && ansi_buf
[i
] <= '9') {
946 num1
+= ansi_buf
[i
]-'0';
954 if (ansi_buf
[i
] != ';') {
962 if (ansi_buf
[i
] >= '0' && ansi_buf
[i
] <= '9') {
963 num2
= ansi_buf
[i
]-'0';
970 if (ansi_buf
[i
] >= '0' && ansi_buf
[i
] <= '9') {
972 num2
+= ansi_buf
[i
]-'0';
980 if ((ansi_buf
[i
] >= 'A' && ansi_buf
[i
] <= 'H')
981 || ansi_buf
[i
] == 'J'
982 || ansi_buf
[i
] == 'K'
983 || ansi_buf
[i
] == 'h'
984 || ansi_buf
[i
] == 'l'
985 || ansi_buf
[i
] == 'm') {
995 for (i
= 0; i
< ansi_buf_size
; ++i
)
996 parse_putc(ansi_buf
[i
]);
1002 if (!ansi_cursor_hidden
)
1007 /* move cursor num1 rows up */
1008 console_cursor_up(num1
);
1011 /* move cursor num1 rows down */
1012 console_cursor_down(num1
);
1015 /* move cursor num1 columns forward */
1016 console_cursor_right(num1
);
1019 /* move cursor num1 columns back */
1020 console_cursor_left(num1
);
1023 /* move cursor num1 rows up at begin of row */
1024 console_previousline(num1
);
1027 /* move cursor num1 rows down at begin of row */
1028 console_newline(num1
);
1031 /* move cursor to column num1 */
1032 console_cursor_set_position(-1, num1
-1);
1035 /* move cursor to row num1, column num2 */
1036 console_cursor_set_position(num1
-1, num2
-1);
1039 /* clear console and move cursor to 0, 0 */
1041 console_cursor_set_position(0, 0);
1046 console_clear_line(console_row
,
1050 console_clear_line(console_row
,
1053 console_clear_line(console_row
,
1057 ansi_cursor_hidden
= 0;
1060 ansi_cursor_hidden
= 1;
1063 if (num1
== 0) { /* reset swapped colors */
1064 if (ansi_colors_need_revert
) {
1065 console_swap_colors();
1066 ansi_colors_need_revert
= 0;
1068 } else if (num1
== 7) { /* once swap colors */
1069 if (!ansi_colors_need_revert
) {
1070 console_swap_colors();
1071 ansi_colors_need_revert
= 1;
1076 if (!ansi_cursor_hidden
)
1085 if (cfb_do_flush_cache
)
1086 flush_cache(VIDEO_FB_ADRS
, VIDEO_SIZE
);
1089 static void video_puts(struct stdio_dev
*dev
, const char *s
)
1091 int flush
= cfb_do_flush_cache
;
1092 int count
= strlen(s
);
1094 /* temporarily disable cache flush */
1095 cfb_do_flush_cache
= 0;
1098 video_putc(dev
, *s
++);
1101 cfb_do_flush_cache
= flush
;
1102 flush_cache(VIDEO_FB_ADRS
, VIDEO_SIZE
);
1107 * Do not enforce drivers (or board code) to provide empty
1108 * video_set_lut() if they do not support 8 bpp format.
1109 * Implement weak default function instead.
1111 __weak
void video_set_lut(unsigned int index
, unsigned char r
,
1112 unsigned char g
, unsigned char b
)
1116 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1118 #define FILL_8BIT_332RGB(r,g,b) { \
1119 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1123 #define FILL_15BIT_555RGB(r,g,b) { \
1124 *(unsigned short *)fb = \
1125 SWAP16((unsigned short)(((r>>3)<<10) | \
1131 #define FILL_16BIT_565RGB(r,g,b) { \
1132 *(unsigned short *)fb = \
1133 SWAP16((unsigned short)((((r)>>3)<<11)| \
1139 #define FILL_32BIT_X888RGB(r,g,b) { \
1140 *(unsigned long *)fb = \
1141 SWAP32((unsigned long)(((r<<16) | \
1147 #ifdef VIDEO_FB_LITTLE_ENDIAN
1148 #define FILL_24BIT_888RGB(r,g,b) { \
1155 #define FILL_24BIT_888RGB(r,g,b) { \
1163 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1164 static inline void fill_555rgb_pswap(uchar
*fb
, int x
, u8 r
, u8 g
, u8 b
)
1166 ushort
*dst
= (ushort
*) fb
;
1167 ushort color
= (ushort
) (((r
>> 3) << 10) |
1178 * RLE8 bitmap support
1181 #ifdef CONFIG_VIDEO_BMP_RLE8
1182 /* Pre-calculated color table entry */
1185 unsigned short w
; /* word */
1186 unsigned int dw
; /* double word */
1187 } ce
; /* color entry */
1191 * Helper to draw encoded/unencoded run.
1193 static void draw_bitmap(uchar
**fb
, uchar
*bm
, struct palette
*p
,
1196 ulong addr
= (ulong
) *fb
;
1202 * Setup offset of the color index in the bitmap.
1203 * Color index of encoded run is at offset 1.
1205 off
= enc
? &enc_off
: &i
;
1207 switch (VIDEO_DATA_FORMAT
) {
1208 case GDF__8BIT_INDEX
:
1209 for (i
= 0; i
< cnt
; i
++)
1210 *(unsigned char *) addr
++ = bm
[*off
];
1212 case GDF_15BIT_555RGB
:
1213 case GDF_16BIT_565RGB
:
1214 /* differences handled while pre-calculating palette */
1215 for (i
= 0; i
< cnt
; i
++) {
1216 *(unsigned short *) addr
= p
[bm
[*off
]].ce
.w
;
1220 case GDF_32BIT_X888RGB
:
1221 for (i
= 0; i
< cnt
; i
++) {
1222 *(unsigned long *) addr
= p
[bm
[*off
]].ce
.dw
;
1227 *fb
= (uchar
*) addr
; /* return modified address */
1230 static int display_rle8_bitmap(struct bmp_image
*img
, int xoff
, int yoff
,
1231 int width
, int height
)
1235 unsigned int cnt
, runlen
;
1237 int x
, y
, bpp
, i
, ncolors
;
1238 struct palette p
[256];
1239 struct bmp_color_table_entry cte
;
1240 int green_shift
, red_off
;
1241 int limit
= (VIDEO_LINE_LEN
/ VIDEO_PIXEL_SIZE
) * VIDEO_ROWS
;
1245 y
= __le32_to_cpu(img
->header
.height
) - 1;
1246 ncolors
= __le32_to_cpu(img
->header
.colors_used
);
1247 bpp
= VIDEO_PIXEL_SIZE
;
1248 fbp
= (unsigned char *) ((unsigned int) video_fb_address
+
1249 (y
+ yoff
) * VIDEO_LINE_LEN
+
1252 bm
= (uchar
*) img
+ __le32_to_cpu(img
->header
.data_offset
);
1254 /* pre-calculate and setup palette */
1255 switch (VIDEO_DATA_FORMAT
) {
1256 case GDF__8BIT_INDEX
:
1257 for (i
= 0; i
< ncolors
; i
++) {
1258 cte
= img
->color_table
[i
];
1259 video_set_lut(i
, cte
.red
, cte
.green
, cte
.blue
);
1262 case GDF_15BIT_555RGB
:
1263 case GDF_16BIT_565RGB
:
1264 if (VIDEO_DATA_FORMAT
== GDF_15BIT_555RGB
) {
1271 for (i
= 0; i
< ncolors
; i
++) {
1272 cte
= img
->color_table
[i
];
1273 p
[i
].ce
.w
= SWAP16((unsigned short)
1274 (((cte
.red
>> 3) << red_off
) |
1275 ((cte
.green
>> green_shift
) << 5) |
1279 case GDF_32BIT_X888RGB
:
1280 for (i
= 0; i
< ncolors
; i
++) {
1281 cte
= img
->color_table
[i
];
1282 p
[i
].ce
.dw
= SWAP32((cte
.red
<< 16) |
1288 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1298 /* scan line end marker */
1302 fbp
= (unsigned char *)
1303 ((unsigned int) video_fb_address
+
1304 (y
+ yoff
) * VIDEO_LINE_LEN
+
1308 /* end of bitmap data marker */
1312 /* run offset marker */
1315 fbp
= (unsigned char *)
1316 ((unsigned int) video_fb_address
+
1317 (y
+ yoff
) * VIDEO_LINE_LEN
+
1335 if (x
+ runlen
> width
)
1337 draw_bitmap(&fbp
, bm
, p
, cnt
, 0);
1343 bm
++; /* 0 padding if length is odd */
1354 if (y
< height
) { /* only draw into visible area */
1360 if (x
+ runlen
> width
)
1362 draw_bitmap(&fbp
, bm
, p
, cnt
, 1);
1371 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1377 * Display the BMP file located at address bmp_image.
1379 int video_display_bitmap(ulong bmp_image
, int x
, int y
)
1381 ushort xcount
, ycount
;
1383 struct bmp_image
*bmp
= (struct bmp_image
*)bmp_image
;
1386 unsigned long width
, height
, bpp
;
1388 unsigned long compression
;
1389 struct bmp_color_table_entry cte
;
1391 #ifdef CONFIG_VIDEO_BMP_GZIP
1392 unsigned char *dst
= NULL
;
1398 if (!((bmp
->header
.signature
[0] == 'B') &&
1399 (bmp
->header
.signature
[1] == 'M'))) {
1401 #ifdef CONFIG_VIDEO_BMP_GZIP
1403 * Could be a gzipped bmp image, try to decrompress...
1405 len
= CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
;
1406 dst
= malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
);
1408 printf("Error: malloc in gunzip failed!\n");
1412 * NB: we need to force offset of +2
1413 * See doc/README.displaying-bmps
1415 if (gunzip(dst
+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
-2,
1416 (uchar
*) bmp_image
,
1418 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1423 if (len
== CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
) {
1424 printf("Image could be truncated "
1425 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1429 * Set addr to decompressed image
1431 bmp
= (struct bmp_image
*)(dst
+2);
1433 if (!((bmp
->header
.signature
[0] == 'B') &&
1434 (bmp
->header
.signature
[1] == 'M'))) {
1435 printf("Error: no valid bmp.gz image at %lx\n",
1441 printf("Error: no valid bmp image at %lx\n", bmp_image
);
1443 #endif /* CONFIG_VIDEO_BMP_GZIP */
1446 width
= le32_to_cpu(bmp
->header
.width
);
1447 height
= le32_to_cpu(bmp
->header
.height
);
1448 bpp
= le16_to_cpu(bmp
->header
.bit_count
);
1449 colors
= le32_to_cpu(bmp
->header
.colors_used
);
1450 compression
= le32_to_cpu(bmp
->header
.compression
);
1452 debug("Display-bmp: %ld x %ld with %d colors\n",
1453 width
, height
, colors
);
1455 if (compression
!= BMP_BI_RGB
1456 #ifdef CONFIG_VIDEO_BMP_RLE8
1457 && compression
!= BMP_BI_RLE8
1460 printf("Error: compression type %ld not supported\n",
1462 #ifdef CONFIG_VIDEO_BMP_GZIP
1469 padded_line
= (((width
* bpp
+ 7) / 8) + 3) & ~0x3;
1471 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1472 if (x
== BMP_ALIGN_CENTER
)
1473 x
= max(0, (int)(VIDEO_VISIBLE_COLS
- width
) / 2);
1475 x
= max(0, (int)(VIDEO_VISIBLE_COLS
- width
+ x
+ 1));
1477 if (y
== BMP_ALIGN_CENTER
)
1478 y
= max(0, (int)(VIDEO_VISIBLE_ROWS
- height
) / 2);
1480 y
= max(0, (int)(VIDEO_VISIBLE_ROWS
- height
+ y
+ 1));
1481 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1484 * Just ignore elements which are completely beyond screen
1487 if ((x
>= VIDEO_VISIBLE_COLS
) || (y
>= VIDEO_VISIBLE_ROWS
))
1490 if ((x
+ width
) > VIDEO_VISIBLE_COLS
)
1491 width
= VIDEO_VISIBLE_COLS
- x
;
1492 if ((y
+ height
) > VIDEO_VISIBLE_ROWS
)
1493 height
= VIDEO_VISIBLE_ROWS
- y
;
1495 bmap
= (uchar
*) bmp
+ le32_to_cpu(bmp
->header
.data_offset
);
1496 fb
= (uchar
*) (video_fb_address
+
1497 ((y
+ height
- 1) * VIDEO_LINE_LEN
) +
1498 x
* VIDEO_PIXEL_SIZE
);
1500 #ifdef CONFIG_VIDEO_BMP_RLE8
1501 if (compression
== BMP_BI_RLE8
) {
1502 return display_rle8_bitmap(bmp
, x
, y
, width
, height
);
1506 /* We handle only 4, 8, or 24 bpp bitmaps */
1507 switch (le16_to_cpu(bmp
->header
.bit_count
)) {
1509 padded_line
-= width
/ 2;
1512 switch (VIDEO_DATA_FORMAT
) {
1513 case GDF_32BIT_X888RGB
:
1517 * Don't assume that 'width' is an
1520 for (xcount
= 0; xcount
< width
; xcount
++) {
1528 cte
= bmp
->color_table
[idx
];
1529 FILL_32BIT_X888RGB(cte
.red
, cte
.green
,
1532 bmap
+= padded_line
;
1533 fb
-= VIDEO_LINE_LEN
+ width
*
1538 puts("4bpp bitmap unsupported with current "
1545 padded_line
-= width
;
1546 if (VIDEO_DATA_FORMAT
== GDF__8BIT_INDEX
) {
1548 for (xcount
= 0; xcount
< colors
; ++xcount
) {
1549 cte
= bmp
->color_table
[xcount
];
1550 video_set_lut(xcount
, cte
.red
, cte
.green
,
1555 switch (VIDEO_DATA_FORMAT
) {
1556 case GDF__8BIT_INDEX
:
1563 bmap
+= padded_line
;
1564 fb
-= VIDEO_LINE_LEN
+ width
*
1568 case GDF__8BIT_332RGB
:
1573 cte
= bmp
->color_table
[*bmap
++];
1574 FILL_8BIT_332RGB(cte
.red
, cte
.green
,
1577 bmap
+= padded_line
;
1578 fb
-= VIDEO_LINE_LEN
+ width
*
1582 case GDF_15BIT_555RGB
:
1584 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1590 cte
= bmp
->color_table
[*bmap
++];
1591 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1592 fill_555rgb_pswap(fb
, xpos
++, cte
.red
,
1597 FILL_15BIT_555RGB(cte
.red
, cte
.green
,
1601 bmap
+= padded_line
;
1602 fb
-= VIDEO_LINE_LEN
+ width
*
1606 case GDF_16BIT_565RGB
:
1611 cte
= bmp
->color_table
[*bmap
++];
1612 FILL_16BIT_565RGB(cte
.red
, cte
.green
,
1615 bmap
+= padded_line
;
1616 fb
-= VIDEO_LINE_LEN
+ width
*
1620 case GDF_32BIT_X888RGB
:
1625 cte
= bmp
->color_table
[*bmap
++];
1626 FILL_32BIT_X888RGB(cte
.red
, cte
.green
,
1629 bmap
+= padded_line
;
1630 fb
-= VIDEO_LINE_LEN
+ width
*
1634 case GDF_24BIT_888RGB
:
1639 cte
= bmp
->color_table
[*bmap
++];
1640 FILL_24BIT_888RGB(cte
.red
, cte
.green
,
1643 bmap
+= padded_line
;
1644 fb
-= VIDEO_LINE_LEN
+ width
*
1651 padded_line
-= 3 * width
;
1653 switch (VIDEO_DATA_FORMAT
) {
1654 case GDF__8BIT_332RGB
:
1659 FILL_8BIT_332RGB(bmap
[2], bmap
[1],
1663 bmap
+= padded_line
;
1664 fb
-= VIDEO_LINE_LEN
+ width
*
1668 case GDF_15BIT_555RGB
:
1670 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1676 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1677 fill_555rgb_pswap(fb
, xpos
++, bmap
[2],
1681 FILL_15BIT_555RGB(bmap
[2], bmap
[1],
1686 bmap
+= padded_line
;
1687 fb
-= VIDEO_LINE_LEN
+ width
*
1691 case GDF_16BIT_565RGB
:
1696 FILL_16BIT_565RGB(bmap
[2], bmap
[1],
1700 bmap
+= padded_line
;
1701 fb
-= VIDEO_LINE_LEN
+ width
*
1705 case GDF_32BIT_X888RGB
:
1710 FILL_32BIT_X888RGB(bmap
[2], bmap
[1],
1714 bmap
+= padded_line
;
1715 fb
-= VIDEO_LINE_LEN
+ width
*
1719 case GDF_24BIT_888RGB
:
1724 FILL_24BIT_888RGB(bmap
[2], bmap
[1],
1728 bmap
+= padded_line
;
1729 fb
-= VIDEO_LINE_LEN
+ width
*
1734 printf("Error: 24 bits/pixel bitmap incompatible "
1735 "with current video mode\n");
1740 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1741 le16_to_cpu(bmp
->header
.bit_count
));
1745 #ifdef CONFIG_VIDEO_BMP_GZIP
1751 if (cfb_do_flush_cache
)
1752 flush_cache(VIDEO_FB_ADRS
, VIDEO_SIZE
);
1758 #ifdef CONFIG_VIDEO_LOGO
1759 static int video_logo_xpos
;
1760 static int video_logo_ypos
;
1762 static void plot_logo_or_black(void *screen
, int x
, int y
, int black
);
1764 static void logo_plot(void *screen
, int x
, int y
)
1766 plot_logo_or_black(screen
, x
, y
, 0);
1769 static void logo_black(void)
1771 plot_logo_or_black(video_fb_address
, video_logo_xpos
, video_logo_ypos
,
1775 static int do_clrlogo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1778 return cmd_usage(cmdtp
);
1785 clrlogo
, 1, 0, do_clrlogo
,
1786 "fill the boot logo area with black",
1790 static void plot_logo_or_black(void *screen
, int x
, int y
, int black
)
1794 int skip
= VIDEO_LINE_LEN
- VIDEO_LOGO_WIDTH
* VIDEO_PIXEL_SIZE
;
1795 int ycount
= video_logo_height
;
1796 unsigned char r
, g
, b
, *logo_red
, *logo_blue
, *logo_green
;
1797 unsigned char *source
;
1798 unsigned char *dest
;
1800 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1801 if (x
== BMP_ALIGN_CENTER
)
1802 x
= max(0, (int)(VIDEO_VISIBLE_COLS
- VIDEO_LOGO_WIDTH
) / 2);
1804 x
= max(0, (int)(VIDEO_VISIBLE_COLS
- VIDEO_LOGO_WIDTH
+ x
+ 1));
1806 if (y
== BMP_ALIGN_CENTER
)
1807 y
= max(0, (int)(VIDEO_VISIBLE_ROWS
- VIDEO_LOGO_HEIGHT
) / 2);
1809 y
= max(0, (int)(VIDEO_VISIBLE_ROWS
- VIDEO_LOGO_HEIGHT
+ y
+ 1));
1810 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1812 dest
= (unsigned char *)screen
+ y
* VIDEO_LINE_LEN
+ x
* VIDEO_PIXEL_SIZE
;
1814 #ifdef CONFIG_VIDEO_BMP_LOGO
1815 source
= bmp_logo_bitmap
;
1817 /* Allocate temporary space for computing colormap */
1818 logo_red
= malloc(BMP_LOGO_COLORS
);
1819 logo_green
= malloc(BMP_LOGO_COLORS
);
1820 logo_blue
= malloc(BMP_LOGO_COLORS
);
1821 /* Compute color map */
1822 for (i
= 0; i
< VIDEO_LOGO_COLORS
; i
++) {
1823 logo_red
[i
] = (bmp_logo_palette
[i
] & 0x0f00) >> 4;
1824 logo_green
[i
] = (bmp_logo_palette
[i
] & 0x00f0);
1825 logo_blue
[i
] = (bmp_logo_palette
[i
] & 0x000f) << 4;
1828 source
= linux_logo
;
1829 logo_red
= linux_logo_red
;
1830 logo_green
= linux_logo_green
;
1831 logo_blue
= linux_logo_blue
;
1834 if (VIDEO_DATA_FORMAT
== GDF__8BIT_INDEX
) {
1835 for (i
= 0; i
< VIDEO_LOGO_COLORS
; i
++) {
1836 video_set_lut(i
+ VIDEO_LOGO_LUT_OFFSET
,
1837 logo_red
[i
], logo_green
[i
],
1843 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1846 xcount
= VIDEO_LOGO_WIDTH
;
1853 r
= logo_red
[*source
- VIDEO_LOGO_LUT_OFFSET
];
1854 g
= logo_green
[*source
- VIDEO_LOGO_LUT_OFFSET
];
1855 b
= logo_blue
[*source
- VIDEO_LOGO_LUT_OFFSET
];
1858 switch (VIDEO_DATA_FORMAT
) {
1859 case GDF__8BIT_INDEX
:
1862 case GDF__8BIT_332RGB
:
1863 *dest
= ((r
>> 5) << 5) |
1867 case GDF_15BIT_555RGB
:
1868 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1869 fill_555rgb_pswap(dest
, xpos
++, r
, g
, b
);
1871 *(unsigned short *) dest
=
1872 SWAP16((unsigned short) (
1878 case GDF_16BIT_565RGB
:
1879 *(unsigned short *) dest
=
1880 SWAP16((unsigned short) (
1885 case GDF_32BIT_X888RGB
:
1886 *(unsigned long *) dest
=
1887 SWAP32((unsigned long) (
1892 case GDF_24BIT_888RGB
:
1893 #ifdef VIDEO_FB_LITTLE_ENDIAN
1905 dest
+= VIDEO_PIXEL_SIZE
;
1909 #ifdef CONFIG_VIDEO_BMP_LOGO
1916 static void *video_logo(void)
1919 __maybe_unused
int y_off
= 0;
1920 __maybe_unused ulong addr
;
1921 __maybe_unused
char *s
;
1922 __maybe_unused
int len
, space
;
1924 splash_get_pos(&video_logo_xpos
, &video_logo_ypos
);
1926 #ifdef CONFIG_SPLASH_SCREEN
1927 s
= getenv("splashimage");
1929 splash_screen_prepare();
1930 addr
= simple_strtoul(s
, NULL
, 16);
1932 if (video_display_bitmap(addr
,
1934 video_logo_ypos
) == 0) {
1935 video_logo_height
= 0;
1936 return ((void *) (video_fb_address
));
1939 #endif /* CONFIG_SPLASH_SCREEN */
1941 logo_plot(video_fb_address
, video_logo_xpos
, video_logo_ypos
);
1943 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1945 * when using splashpos for video_logo, skip any info
1946 * output on video console if the logo is not at 0,0
1948 if (video_logo_xpos
|| video_logo_ypos
) {
1950 * video_logo_height is used in text and cursor offset
1951 * calculations. Since the console is below the logo,
1952 * we need to adjust the logo height
1954 if (video_logo_ypos
== BMP_ALIGN_CENTER
)
1955 video_logo_height
+= max(0, (int)(VIDEO_VISIBLE_ROWS
-
1956 VIDEO_LOGO_HEIGHT
) / 2);
1957 else if (video_logo_ypos
> 0)
1958 video_logo_height
+= video_logo_ypos
;
1960 return video_fb_address
+ video_logo_height
* VIDEO_LINE_LEN
;
1963 if (board_cfb_skip())
1966 sprintf(info
, " %s", version_string
);
1968 #ifndef CONFIG_HIDE_LOGO_VERSION
1969 space
= (VIDEO_LINE_LEN
/ 2 - VIDEO_INFO_X
) / VIDEO_FONT_WIDTH
;
1973 video_drawchars(VIDEO_INFO_X
, VIDEO_INFO_Y
,
1974 (uchar
*) info
, space
);
1975 video_drawchars(VIDEO_INFO_X
+ VIDEO_FONT_WIDTH
,
1976 VIDEO_INFO_Y
+ VIDEO_FONT_HEIGHT
,
1977 (uchar
*) info
+ space
, len
- space
);
1980 video_drawstring(VIDEO_INFO_X
, VIDEO_INFO_Y
, (uchar
*) info
);
1982 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1985 ((video_logo_height
-
1986 VIDEO_FONT_HEIGHT
) / VIDEO_FONT_HEIGHT
);
1988 for (i
= 1; i
< n
; i
++) {
1989 video_get_info_str(i
, info
);
1995 video_drawchars(VIDEO_INFO_X
,
1999 (uchar
*) info
, space
);
2001 video_drawchars(VIDEO_INFO_X
+
2006 (uchar
*) info
+ space
,
2009 video_drawstring(VIDEO_INFO_X
,
2020 return (video_fb_address
+ video_logo_height
* VIDEO_LINE_LEN
);
2024 static int cfb_fb_is_in_dram(void)
2027 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2028 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2032 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; ++i
) {
2033 start
= bd
->bi_dram
[i
].start
;
2034 end
= bd
->bi_dram
[i
].start
+ bd
->bi_dram
[i
].size
- 1;
2035 if ((ulong
)video_fb_address
>= start
&&
2036 (ulong
)video_fb_address
< end
)
2040 if ((ulong
)video_fb_address
>= bd
->bi_memstart
&&
2041 (ulong
)video_fb_address
< bd
->bi_memstart
+ bd
->bi_memsize
)
2047 void video_clear(void)
2049 if (!video_fb_address
)
2051 #ifdef VIDEO_HW_RECTFILL
2052 video_hw_rectfill(VIDEO_PIXEL_SIZE
, /* bytes per pixel */
2055 VIDEO_VISIBLE_COLS
, /* frame width */
2056 VIDEO_VISIBLE_ROWS
, /* frame height */
2057 bgx
/* fill color */
2060 memsetl(video_fb_address
,
2061 (VIDEO_VISIBLE_ROWS
* VIDEO_LINE_LEN
) / sizeof(int), bgx
);
2065 static int video_init(void)
2067 unsigned char color8
;
2069 pGD
= video_hw_init();
2073 video_fb_address
= (void *) VIDEO_FB_ADRS
;
2074 #ifdef CONFIG_VIDEO_HW_CURSOR
2075 video_init_hw_cursor(VIDEO_FONT_WIDTH
, VIDEO_FONT_HEIGHT
);
2078 cfb_do_flush_cache
= cfb_fb_is_in_dram() && dcache_status();
2080 /* Init drawing pats */
2081 switch (VIDEO_DATA_FORMAT
) {
2082 case GDF__8BIT_INDEX
:
2083 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL
,
2084 CONFIG_SYS_CONSOLE_FG_COL
,
2085 CONFIG_SYS_CONSOLE_FG_COL
);
2086 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL
,
2087 CONFIG_SYS_CONSOLE_BG_COL
,
2088 CONFIG_SYS_CONSOLE_BG_COL
);
2092 case GDF__8BIT_332RGB
:
2093 color8
= ((CONFIG_SYS_CONSOLE_FG_COL
& 0xe0) |
2094 ((CONFIG_SYS_CONSOLE_FG_COL
>> 3) & 0x1c) |
2095 CONFIG_SYS_CONSOLE_FG_COL
>> 6);
2096 fgx
= (color8
<< 24) | (color8
<< 16) | (color8
<< 8) |
2098 color8
= ((CONFIG_SYS_CONSOLE_BG_COL
& 0xe0) |
2099 ((CONFIG_SYS_CONSOLE_BG_COL
>> 3) & 0x1c) |
2100 CONFIG_SYS_CONSOLE_BG_COL
>> 6);
2101 bgx
= (color8
<< 24) | (color8
<< 16) | (color8
<< 8) |
2104 case GDF_15BIT_555RGB
:
2105 fgx
= (((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 26) |
2106 ((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 21) |
2107 ((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 16) |
2108 ((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 10) |
2109 ((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 5) |
2110 (CONFIG_SYS_CONSOLE_FG_COL
>> 3));
2111 bgx
= (((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 26) |
2112 ((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 21) |
2113 ((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 16) |
2114 ((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 10) |
2115 ((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 5) |
2116 (CONFIG_SYS_CONSOLE_BG_COL
>> 3));
2118 case GDF_16BIT_565RGB
:
2119 fgx
= (((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 27) |
2120 ((CONFIG_SYS_CONSOLE_FG_COL
>> 2) << 21) |
2121 ((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 16) |
2122 ((CONFIG_SYS_CONSOLE_FG_COL
>> 3) << 11) |
2123 ((CONFIG_SYS_CONSOLE_FG_COL
>> 2) << 5) |
2124 (CONFIG_SYS_CONSOLE_FG_COL
>> 3));
2125 bgx
= (((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 27) |
2126 ((CONFIG_SYS_CONSOLE_BG_COL
>> 2) << 21) |
2127 ((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 16) |
2128 ((CONFIG_SYS_CONSOLE_BG_COL
>> 3) << 11) |
2129 ((CONFIG_SYS_CONSOLE_BG_COL
>> 2) << 5) |
2130 (CONFIG_SYS_CONSOLE_BG_COL
>> 3));
2132 case GDF_32BIT_X888RGB
:
2133 fgx
= (CONFIG_SYS_CONSOLE_FG_COL
<< 16) |
2134 (CONFIG_SYS_CONSOLE_FG_COL
<< 8) |
2135 CONFIG_SYS_CONSOLE_FG_COL
;
2136 bgx
= (CONFIG_SYS_CONSOLE_BG_COL
<< 16) |
2137 (CONFIG_SYS_CONSOLE_BG_COL
<< 8) |
2138 CONFIG_SYS_CONSOLE_BG_COL
;
2140 case GDF_24BIT_888RGB
:
2141 fgx
= (CONFIG_SYS_CONSOLE_FG_COL
<< 24) |
2142 (CONFIG_SYS_CONSOLE_FG_COL
<< 16) |
2143 (CONFIG_SYS_CONSOLE_FG_COL
<< 8) |
2144 CONFIG_SYS_CONSOLE_FG_COL
;
2145 bgx
= (CONFIG_SYS_CONSOLE_BG_COL
<< 24) |
2146 (CONFIG_SYS_CONSOLE_BG_COL
<< 16) |
2147 (CONFIG_SYS_CONSOLE_BG_COL
<< 8) |
2148 CONFIG_SYS_CONSOLE_BG_COL
;
2155 #ifdef CONFIG_VIDEO_LOGO
2156 /* Plot the logo and get start point of console */
2157 debug("Video: Drawing the logo ...\n");
2158 video_console_address
= video_logo();
2160 video_console_address
= video_fb_address
;
2163 /* Initialize the console */
2167 if (cfb_do_flush_cache
)
2168 flush_cache(VIDEO_FB_ADRS
, VIDEO_SIZE
);
2174 * Implement a weak default function for boards that optionally
2175 * need to skip the video initialization.
2177 __weak
int board_video_skip(void)
2179 /* As default, don't skip test */
2183 int drv_video_init(void)
2185 struct stdio_dev console_dev
;
2187 bool __maybe_unused keyboard_ok
= false;
2189 /* Check if video initialization should be skipped */
2190 if (board_video_skip())
2193 /* Init video chip - returns with framebuffer cleared */
2194 if (video_init() == -1)
2197 if (board_cfb_skip())
2200 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2201 have_keyboard
= false;
2202 #elif defined(CONFIG_OF_CONTROL)
2203 have_keyboard
= !fdtdec_get_config_bool(gd
->fdt_blob
,
2204 "u-boot,no-keyboard");
2206 have_keyboard
= true;
2208 if (have_keyboard
) {
2209 debug("KBD: Keyboard init ...\n");
2210 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2211 keyboard_ok
= !(VIDEO_KBD_INIT_FCT
== -1);
2215 /* Init vga device */
2216 memset(&console_dev
, 0, sizeof(console_dev
));
2217 strcpy(console_dev
.name
, "vga");
2218 console_dev
.flags
= DEV_FLAGS_OUTPUT
;
2219 console_dev
.putc
= video_putc
; /* 'putc' function */
2220 console_dev
.puts
= video_puts
; /* 'puts' function */
2222 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2223 if (have_keyboard
&& keyboard_ok
) {
2224 /* Also init console device */
2225 console_dev
.flags
|= DEV_FLAGS_INPUT
;
2226 console_dev
.tstc
= VIDEO_TSTC_FCT
; /* 'tstc' function */
2227 console_dev
.getc
= VIDEO_GETC_FCT
; /* 'getc' function */
2231 if (stdio_register(&console_dev
) != 0)
2234 /* Return success */
2238 void video_position_cursor(unsigned col
, unsigned row
)
2240 console_col
= min(col
, CONSOLE_COLS
- 1);
2241 console_row
= min(row
, CONSOLE_ROWS
- 1);
2244 int video_get_pixel_width(void)
2246 return VIDEO_VISIBLE_COLS
;
2249 int video_get_pixel_height(void)
2251 return VIDEO_VISIBLE_ROWS
;
2254 int video_get_screen_rows(void)
2256 return CONSOLE_ROWS
;
2259 int video_get_screen_columns(void)
2261 return CONSOLE_COLS
;