1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2002 ELTEC Elektronik AG
4 * Frank Gottschling <fgottschling@eltec.de>
10 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
12 * At the moment only the 8x16 font is tested and the font fore- and
13 * background color is limited to black/white/gray colors. The Linux
14 * logo can be placed in the upper left corner and additional board
15 * information strings (that normally goes to serial port) can be drawn.
17 * The console driver can use a keyboard interface for character input
18 * but this is deprecated. Only rk51 uses it.
20 * Character output goes to a memory-mapped video
21 * framebuffer with little or big-endian organisation.
22 * With environment setting 'console=serial' the console i/o can be
23 * forced to serial port.
25 * The driver uses graphic specific defines/parameters/functions:
27 * (for SMI LynxE graphic chip)
29 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
30 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
31 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
33 * Console Parameters are set by graphic drivers global struct:
35 * VIDEO_VISIBLE_COLS - x resolution
36 * VIDEO_VISIBLE_ROWS - y resolution
37 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
38 * VIDEO_DATA_FORMAT - graphical data format GDF
39 * VIDEO_FB_ADRS - start of video memory
41 * VIDEO_KBD_INIT_FCT - init function for keyboard
42 * VIDEO_TSTC_FCT - keyboard_tstc function
43 * VIDEO_GETC_FCT - keyboard_getc function
45 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
46 * Use CONFIG_SPLASH_SCREEN_ALIGN with
47 * environment variable "splashpos" to place
48 * the logo on other position. In this case
49 * no CONSOLE_EXTRA_INFO is possible.
50 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
51 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
52 * strings that normaly goes to serial
53 * port. This define requires a board
55 * video_drawstring (VIDEO_INFO_X,
56 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
58 * that fills a info buffer at i=row.
59 * s.a: board/eltec/bab7xx.
61 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
62 * character. No blinking is provided.
63 * Uses the macros CURSOR_SET and
74 #include <version_string.h>
77 #include <asm/global_data.h>
78 #include <dm/ofnode.h>
79 #include <linux/compiler.h>
82 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
91 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
92 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
93 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
94 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
95 #define VIDEO_FB_ADRS (pGD->frameAdrs)
101 #include <linux/types.h>
102 #include <stdio_dev.h>
103 #include <video_font.h>
105 #if defined(CONFIG_CMD_DATE)
109 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
110 #include <watchdog.h>
111 #include <bmp_layout.h>
115 #if !defined(CONFIG_VIDEO_SW_CURSOR)
116 /* no Cursor defined */
122 #if defined(CONFIG_VIDEO_SW_CURSOR)
123 void console_cursor(int state);
125 #define CURSOR_ON console_cursor(1)
126 #define CURSOR_OFF console_cursor(0)
127 #define CURSOR_SET video_set_cursor()
128 #endif /* CONFIG_VIDEO_SW_CURSOR */
130 #ifdef CONFIG_VIDEO_LOGO
131 #ifdef CONFIG_VIDEO_BMP_LOGO
132 #include <bmp_logo.h>
133 #include <bmp_logo_data.h>
134 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
135 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
136 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
137 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
139 #else /* CONFIG_VIDEO_BMP_LOGO */
140 #define LINUX_LOGO_WIDTH 80
141 #define LINUX_LOGO_HEIGHT 80
142 #define LINUX_LOGO_COLORS 214
143 #define LINUX_LOGO_LUT_OFFSET 0x20
145 #include <linux_logo.h>
146 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
147 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
148 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
149 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
150 #endif /* CONFIG_VIDEO_BMP_LOGO */
151 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
152 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
153 #else /* CONFIG_VIDEO_LOGO */
154 #define VIDEO_LOGO_WIDTH 0
155 #define VIDEO_LOGO_HEIGHT 0
156 #endif /* CONFIG_VIDEO_LOGO */
158 #define VIDEO_COLS VIDEO_VISIBLE_COLS
159 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
160 #ifndef VIDEO_LINE_LEN
161 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
163 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
164 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
166 #ifdef CONFIG_VIDEO_LOGO
167 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
169 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
172 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
173 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
174 #define CONSOLE_ROW_FIRST (video_console_address)
175 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
176 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
177 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
179 /* By default we scroll by a single line */
180 #ifndef CONFIG_CONSOLE_SCROLL_LINES
181 #define CONFIG_CONSOLE_SCROLL_LINES 1
185 #ifdef VIDEO_FB_LITTLE_ENDIAN
186 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
189 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
190 (((x) & 0x0000ff00) << 8) | \
191 (((x) & 0x00ff0000) >> 8) | \
192 (((x) & 0xff000000) >> 24) \
194 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
195 (((x) & 0x0000ff00) >> 8) | \
196 (((x) & 0x00ff0000) << 8) | \
197 (((x) & 0xff000000) >> 8) \
200 #define SWAP16(x) (x)
201 #define SWAP32(x) (x)
202 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
203 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
205 #define SHORTSWAP32(x) (x)
209 DECLARE_GLOBAL_DATA_PTR;
212 static GraphicDevice *pGD; /* Pointer to Graphic array */
214 static void *video_fb_address; /* frame buffer address */
215 static void *video_console_address; /* console buffer start address */
217 static int video_logo_height = VIDEO_LOGO_HEIGHT;
219 static int __maybe_unused cursor_state;
220 static int __maybe_unused old_col;
221 static int __maybe_unused old_row;
223 static int console_col; /* cursor col */
224 static int console_row; /* cursor row */
226 static u32 eorx, fgx, bgx; /* color pats */
228 static int cfb_do_flush_cache;
230 #ifdef CONFIG_CFB_CONSOLE_ANSI
231 static char ansi_buf[10];
232 static int ansi_buf_size;
233 static int ansi_colors_need_revert;
234 static int ansi_cursor_hidden;
237 static const int video_font_draw_table8[] = {
238 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
239 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
240 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
241 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
244 static const int video_font_draw_table15[] = {
245 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
248 static const int video_font_draw_table16[] = {
249 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
252 static const int video_font_draw_table24[16][3] = {
253 {0x00000000, 0x00000000, 0x00000000},
254 {0x00000000, 0x00000000, 0x00ffffff},
255 {0x00000000, 0x0000ffff, 0xff000000},
256 {0x00000000, 0x0000ffff, 0xffffffff},
257 {0x000000ff, 0xffff0000, 0x00000000},
258 {0x000000ff, 0xffff0000, 0x00ffffff},
259 {0x000000ff, 0xffffffff, 0xff000000},
260 {0x000000ff, 0xffffffff, 0xffffffff},
261 {0xffffff00, 0x00000000, 0x00000000},
262 {0xffffff00, 0x00000000, 0x00ffffff},
263 {0xffffff00, 0x0000ffff, 0xff000000},
264 {0xffffff00, 0x0000ffff, 0xffffffff},
265 {0xffffffff, 0xffff0000, 0x00000000},
266 {0xffffffff, 0xffff0000, 0x00ffffff},
267 {0xffffffff, 0xffffffff, 0xff000000},
268 {0xffffffff, 0xffffffff, 0xffffffff}
271 static const int video_font_draw_table32[16][4] = {
272 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
273 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
274 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
275 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
276 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
277 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
278 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
279 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
280 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
281 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
282 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
283 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
284 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
285 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
286 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
287 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
291 * Implement a weak default function for boards that optionally
292 * need to skip the cfb initialization.
294 __weak int board_cfb_skip(void)
296 /* As default, don't skip cfb init */
300 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
302 u8 *cdat, *dest, *dest0;
305 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
306 dest0 = video_fb_address + offset;
308 switch (VIDEO_DATA_FORMAT) {
309 case GDF__8BIT_INDEX:
310 case GDF__8BIT_332RGB:
313 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
314 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
315 rows--; dest += VIDEO_LINE_LEN) {
319 (video_font_draw_table8[bits >> 4] &
322 if (VIDEO_FONT_WIDTH == 4)
326 (video_font_draw_table8[bits & 15] &
329 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
334 case GDF_15BIT_555RGB:
337 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
338 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
339 rows--; dest += VIDEO_LINE_LEN) {
343 SHORTSWAP32((video_font_draw_table15
344 [bits >> 6] & eorx) ^
347 SHORTSWAP32((video_font_draw_table15
348 [bits >> 4 & 3] & eorx) ^
351 if (VIDEO_FONT_WIDTH == 4)
355 SHORTSWAP32((video_font_draw_table15
356 [bits >> 2 & 3] & eorx) ^
359 SHORTSWAP32((video_font_draw_table15
363 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
368 case GDF_16BIT_565RGB:
371 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
372 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
373 rows--; dest += VIDEO_LINE_LEN) {
377 SHORTSWAP32((video_font_draw_table16
378 [bits >> 6] & eorx) ^
381 SHORTSWAP32((video_font_draw_table16
382 [bits >> 4 & 3] & eorx) ^
385 if (VIDEO_FONT_WIDTH == 4)
389 SHORTSWAP32((video_font_draw_table16
390 [bits >> 2 & 3] & eorx) ^
393 SHORTSWAP32((video_font_draw_table16
397 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
402 case GDF_32BIT_X888RGB:
405 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
406 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
407 rows--; dest += VIDEO_LINE_LEN) {
411 SWAP32((video_font_draw_table32
412 [bits >> 4][0] & eorx) ^ bgx);
414 SWAP32((video_font_draw_table32
415 [bits >> 4][1] & eorx) ^ bgx);
417 SWAP32((video_font_draw_table32
418 [bits >> 4][2] & eorx) ^ bgx);
420 SWAP32((video_font_draw_table32
421 [bits >> 4][3] & eorx) ^ bgx);
424 if (VIDEO_FONT_WIDTH == 4)
428 SWAP32((video_font_draw_table32
429 [bits & 15][0] & eorx) ^ bgx);
431 SWAP32((video_font_draw_table32
432 [bits & 15][1] & eorx) ^ bgx);
434 SWAP32((video_font_draw_table32
435 [bits & 15][2] & eorx) ^ bgx);
437 SWAP32((video_font_draw_table32
438 [bits & 15][3] & eorx) ^ bgx);
440 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
445 case GDF_24BIT_888RGB:
448 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
449 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
450 rows--; dest += VIDEO_LINE_LEN) {
454 (video_font_draw_table24[bits >> 4][0]
457 (video_font_draw_table24[bits >> 4][1]
460 (video_font_draw_table24[bits >> 4][2]
463 if (VIDEO_FONT_WIDTH == 4)
467 (video_font_draw_table24[bits & 15][0]
470 (video_font_draw_table24[bits & 15][1]
473 (video_font_draw_table24[bits & 15][2]
476 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
483 static inline void video_drawstring(int xx, int yy, unsigned char *s)
485 video_drawchars(xx, yy, s, strlen((char *) s));
488 static void video_putchar(int xx, int yy, unsigned char c)
490 video_drawchars(xx, yy + video_logo_height, &c, 1);
493 #if defined(CONFIG_VIDEO_SW_CURSOR)
494 static void video_set_cursor(void)
501 static void video_invertchar(int xx, int yy)
503 int firstx = xx * VIDEO_PIXEL_SIZE;
504 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
505 int firsty = yy * VIDEO_LINE_LEN;
506 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
508 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
509 for (x = firstx; x < lastx; x++) {
510 u8 *dest = (u8 *)(video_fb_address) + x + y;
516 void console_cursor(int state)
518 if (cursor_state != state) {
520 /* turn off the cursor */
521 video_invertchar(old_col * VIDEO_FONT_WIDTH,
522 old_row * VIDEO_FONT_HEIGHT +
525 /* turn off the cursor and record where it is */
526 video_invertchar(console_col * VIDEO_FONT_WIDTH,
527 console_row * VIDEO_FONT_HEIGHT +
529 old_col = console_col;
530 old_row = console_row;
532 cursor_state = state;
534 if (cfb_do_flush_cache)
535 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
539 #ifndef VIDEO_HW_RECTFILL
540 static void memsetl(int *p, int c, int v)
547 #ifndef VIDEO_HW_BITBLT
548 static void memcpyl(int *d, int *s, int c)
555 static void console_clear_line(int line, int begin, int end)
557 #ifdef VIDEO_HW_RECTFILL
558 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
559 VIDEO_FONT_WIDTH * begin, /* dest pos x */
561 VIDEO_FONT_HEIGHT * line, /* dest pos y */
562 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
563 VIDEO_FONT_HEIGHT, /* frame height */
567 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
568 memsetl(CONSOLE_ROW_FIRST +
569 CONSOLE_ROW_SIZE * line, /* offset of row */
570 CONSOLE_ROW_SIZE >> 2, /* length of row */
577 offset = CONSOLE_ROW_FIRST +
578 CONSOLE_ROW_SIZE * line + /* offset of row */
580 VIDEO_PIXEL_SIZE * begin; /* offset of col */
581 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
582 size >>= 2; /* length to end for memsetl() */
583 /* fill at col offset of i'th line using bgx as fill color */
584 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
585 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
590 static void console_scrollup(void)
592 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
595 /* copy up rows ignoring the first one */
597 #ifdef VIDEO_HW_BITBLT
598 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
599 0, /* source pos x */
601 VIDEO_FONT_HEIGHT * rows, /* source pos y */
603 video_logo_height, /* dest pos y */
604 VIDEO_VISIBLE_COLS, /* frame width */
607 - VIDEO_FONT_HEIGHT * rows /* frame height */
610 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
611 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
613 /* clear the last one */
614 for (i = 1; i <= rows; i++)
615 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
617 /* Decrement row number */
621 static void console_back(void)
625 if (console_col < 0) {
626 console_col = CONSOLE_COLS - 1;
633 #ifdef CONFIG_CFB_CONSOLE_ANSI
635 static void console_clear(void)
637 #ifdef VIDEO_HW_RECTFILL
638 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
640 video_logo_height, /* dest pos y */
641 VIDEO_VISIBLE_COLS, /* frame width */
642 VIDEO_VISIBLE_ROWS, /* frame height */
646 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
650 static void console_cursor_fix(void)
654 if (console_row >= CONSOLE_ROWS)
655 console_row = CONSOLE_ROWS - 1;
658 if (console_col >= CONSOLE_COLS)
659 console_col = CONSOLE_COLS - 1;
662 static void console_cursor_up(int n)
665 console_cursor_fix();
668 static void console_cursor_down(int n)
671 console_cursor_fix();
674 static void console_cursor_left(int n)
677 console_cursor_fix();
680 static void console_cursor_right(int n)
683 console_cursor_fix();
686 static void console_cursor_set_position(int row, int col)
688 if (console_row != -1)
690 if (console_col != -1)
692 console_cursor_fix();
695 static void console_previousline(int n)
697 /* FIXME: also scroll terminal ? */
699 console_cursor_fix();
702 static void console_swap_colors(void)
710 static inline int console_cursor_is_visible(void)
712 return !ansi_cursor_hidden;
715 static inline int console_cursor_is_visible(void)
721 static void console_newline(int n)
726 /* Check if we need to scroll the terminal */
727 if (console_row >= CONSOLE_ROWS) {
728 /* Scroll everything up */
733 static void console_cr(void)
738 static void parse_putc(const char c)
742 if (console_cursor_is_visible())
746 case 13: /* back to first column */
750 case '\n': /* next line */
751 if (console_col || nl)
757 console_col |= 0x0008;
758 console_col &= ~0x0007;
760 if (console_col >= CONSOLE_COLS)
764 case 8: /* backspace */
771 default: /* draw the char */
772 video_putchar(console_col * VIDEO_FONT_WIDTH,
773 console_row * VIDEO_FONT_HEIGHT, c);
776 /* check for newline */
777 if (console_col >= CONSOLE_COLS) {
783 if (console_cursor_is_visible())
787 static void cfb_video_putc(struct stdio_dev *dev, const char c)
789 #ifdef CONFIG_CFB_CONSOLE_ANSI
793 for (i = 0; i < ansi_buf_size; ++i)
794 parse_putc(ansi_buf[i]);
800 if (ansi_buf_size > 0) {
820 ansi_buf[ansi_buf_size++] = c;
822 if (ansi_buf_size >= sizeof(ansi_buf))
825 for (i = 0; i < ansi_buf_size; ++i) {
831 if (ansi_buf[i] == 27)
838 if (ansi_buf[i] == '[')
845 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
846 num1 = ansi_buf[i]-'0';
848 } else if (ansi_buf[i] != '?') {
856 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
858 num1 += ansi_buf[i]-'0';
866 if (ansi_buf[i] != ';') {
874 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
875 num2 = ansi_buf[i]-'0';
882 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
884 num2 += ansi_buf[i]-'0';
892 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
893 || ansi_buf[i] == 'J'
894 || ansi_buf[i] == 'K'
895 || ansi_buf[i] == 'h'
896 || ansi_buf[i] == 'l'
897 || ansi_buf[i] == 'm') {
907 for (i = 0; i < ansi_buf_size; ++i)
908 parse_putc(ansi_buf[i]);
914 if (!ansi_cursor_hidden)
919 /* move cursor num1 rows up */
920 console_cursor_up(num1);
923 /* move cursor num1 rows down */
924 console_cursor_down(num1);
927 /* move cursor num1 columns forward */
928 console_cursor_right(num1);
931 /* move cursor num1 columns back */
932 console_cursor_left(num1);
935 /* move cursor num1 rows up at begin of row */
936 console_previousline(num1);
939 /* move cursor num1 rows down at begin of row */
940 console_newline(num1);
943 /* move cursor to column num1 */
944 console_cursor_set_position(-1, num1-1);
947 /* move cursor to row num1, column num2 */
948 console_cursor_set_position(num1-1, num2-1);
951 /* clear console and move cursor to 0, 0 */
953 console_cursor_set_position(0, 0);
958 console_clear_line(console_row,
962 console_clear_line(console_row,
965 console_clear_line(console_row,
969 ansi_cursor_hidden = 0;
972 ansi_cursor_hidden = 1;
975 if (num1 == 0) { /* reset swapped colors */
976 if (ansi_colors_need_revert) {
977 console_swap_colors();
978 ansi_colors_need_revert = 0;
980 } else if (num1 == 7) { /* once swap colors */
981 if (!ansi_colors_need_revert) {
982 console_swap_colors();
983 ansi_colors_need_revert = 1;
988 if (!ansi_cursor_hidden)
997 if (cfb_do_flush_cache)
998 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1001 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1003 int flush = cfb_do_flush_cache;
1004 int count = strlen(s);
1006 /* temporarily disable cache flush */
1007 cfb_do_flush_cache = 0;
1010 cfb_video_putc(dev, *s++);
1013 cfb_do_flush_cache = flush;
1014 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1019 * Do not enforce drivers (or board code) to provide empty
1020 * video_set_lut() if they do not support 8 bpp format.
1021 * Implement weak default function instead.
1023 __weak void video_set_lut(unsigned int index, unsigned char r,
1024 unsigned char g, unsigned char b)
1028 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1030 #define FILL_8BIT_332RGB(r,g,b) { \
1031 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1035 #define FILL_15BIT_555RGB(r,g,b) { \
1036 *(unsigned short *)fb = \
1037 SWAP16((unsigned short)(((r>>3)<<10) | \
1043 #define FILL_16BIT_565RGB(r,g,b) { \
1044 *(unsigned short *)fb = \
1045 SWAP16((unsigned short)((((r)>>3)<<11)| \
1051 #define FILL_32BIT_X888RGB(r,g,b) { \
1053 SWAP32((unsigned int)(((r<<16) | \
1059 #ifdef VIDEO_FB_LITTLE_ENDIAN
1060 #define FILL_24BIT_888RGB(r,g,b) { \
1067 #define FILL_24BIT_888RGB(r,g,b) { \
1075 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1076 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1078 ushort *dst = (ushort *) fb;
1079 ushort color = (ushort) (((r >> 3) << 10) |
1090 * RLE8 bitmap support
1093 #ifdef CONFIG_VIDEO_BMP_RLE8
1094 /* Pre-calculated color table entry */
1097 unsigned short w; /* word */
1098 unsigned int dw; /* double word */
1099 } ce; /* color entry */
1103 * Helper to draw encoded/unencoded run.
1105 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1108 ulong addr = (ulong) *fb;
1114 * Setup offset of the color index in the bitmap.
1115 * Color index of encoded run is at offset 1.
1117 off = enc ? &enc_off : &i;
1119 switch (VIDEO_DATA_FORMAT) {
1120 case GDF__8BIT_INDEX:
1121 for (i = 0; i < cnt; i++)
1122 *(unsigned char *) addr++ = bm[*off];
1124 case GDF_15BIT_555RGB:
1125 case GDF_16BIT_565RGB:
1126 /* differences handled while pre-calculating palette */
1127 for (i = 0; i < cnt; i++) {
1128 *(unsigned short *) addr = p[bm[*off]].ce.w;
1132 case GDF_32BIT_X888RGB:
1133 for (i = 0; i < cnt; i++) {
1134 *(u32 *) addr = p[bm[*off]].ce.dw;
1139 *fb = (uchar *) addr; /* return modified address */
1142 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1143 int width, int height)
1147 unsigned int cnt, runlen;
1149 int x, y, bpp, i, ncolors;
1150 struct palette p[256];
1151 struct bmp_color_table_entry cte;
1152 int green_shift, red_off;
1153 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1157 y = __le32_to_cpu(img->header.height) - 1;
1158 ncolors = __le32_to_cpu(img->header.colors_used);
1159 bpp = VIDEO_PIXEL_SIZE;
1160 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1161 (y + yoff) * VIDEO_LINE_LEN +
1164 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1166 /* pre-calculate and setup palette */
1167 switch (VIDEO_DATA_FORMAT) {
1168 case GDF__8BIT_INDEX:
1169 for (i = 0; i < ncolors; i++) {
1170 cte = img->color_table[i];
1171 video_set_lut(i, cte.red, cte.green, cte.blue);
1174 case GDF_15BIT_555RGB:
1175 case GDF_16BIT_565RGB:
1176 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1183 for (i = 0; i < ncolors; i++) {
1184 cte = img->color_table[i];
1185 p[i].ce.w = SWAP16((unsigned short)
1186 (((cte.red >> 3) << red_off) |
1187 ((cte.green >> green_shift) << 5) |
1191 case GDF_32BIT_X888RGB:
1192 for (i = 0; i < ncolors; i++) {
1193 cte = img->color_table[i];
1194 p[i].ce.dw = SWAP32((cte.red << 16) |
1200 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1210 /* scan line end marker */
1214 fbp = (unsigned char *)
1215 ((unsigned int) video_fb_address +
1216 (y + yoff) * VIDEO_LINE_LEN +
1220 /* end of bitmap data marker */
1224 /* run offset marker */
1227 fbp = (unsigned char *)
1228 ((unsigned int) video_fb_address +
1229 (y + yoff) * VIDEO_LINE_LEN +
1247 if (x + runlen > width)
1249 draw_bitmap(&fbp, bm, p, cnt, 0);
1255 bm++; /* 0 padding if length is odd */
1266 if (y < height) { /* only draw into visible area */
1272 if (x + runlen > width)
1274 draw_bitmap(&fbp, bm, p, cnt, 1);
1282 if (cfb_do_flush_cache)
1283 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1287 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1293 * Display the BMP file located at address bmp_image.
1295 int video_display_bitmap(ulong bmp_image, int x, int y)
1297 ushort xcount, ycount;
1299 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1302 unsigned long width, height, bpp;
1304 unsigned long compression;
1305 struct bmp_color_table_entry cte;
1307 #ifdef CONFIG_VIDEO_BMP_GZIP
1308 unsigned char *dst = NULL;
1314 if (!((bmp->header.signature[0] == 'B') &&
1315 (bmp->header.signature[1] == 'M'))) {
1317 #ifdef CONFIG_VIDEO_BMP_GZIP
1319 * Could be a gzipped bmp image, try to decrompress...
1321 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1322 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1324 printf("Error: malloc in gunzip failed!\n");
1328 * NB: we need to force offset of +2
1329 * See doc/README.displaying-bmps
1331 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1332 (uchar *) bmp_image,
1334 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1339 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1340 printf("Image could be truncated "
1341 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1345 * Set addr to decompressed image
1347 bmp = (struct bmp_image *)(dst+2);
1349 if (!((bmp->header.signature[0] == 'B') &&
1350 (bmp->header.signature[1] == 'M'))) {
1351 printf("Error: no valid bmp.gz image at %lx\n",
1357 printf("Error: no valid bmp image at %lx\n", bmp_image);
1359 #endif /* CONFIG_VIDEO_BMP_GZIP */
1362 width = le32_to_cpu(bmp->header.width);
1363 height = le32_to_cpu(bmp->header.height);
1364 bpp = le16_to_cpu(bmp->header.bit_count);
1365 colors = le32_to_cpu(bmp->header.colors_used);
1366 compression = le32_to_cpu(bmp->header.compression);
1368 debug("Display-bmp: %ld x %ld with %d colors\n",
1369 width, height, colors);
1371 if (compression != BMP_BI_RGB
1372 #ifdef CONFIG_VIDEO_BMP_RLE8
1373 && compression != BMP_BI_RLE8
1376 printf("Error: compression type %ld not supported\n",
1378 #ifdef CONFIG_VIDEO_BMP_GZIP
1385 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1387 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1388 if (x == BMP_ALIGN_CENTER)
1389 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1391 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1393 if (y == BMP_ALIGN_CENTER)
1394 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1396 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1397 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1400 * Just ignore elements which are completely beyond screen
1403 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1406 if ((x + width) > VIDEO_VISIBLE_COLS)
1407 width = VIDEO_VISIBLE_COLS - x;
1408 if ((y + height) > VIDEO_VISIBLE_ROWS)
1409 height = VIDEO_VISIBLE_ROWS - y;
1411 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1412 fb = (uchar *) (video_fb_address +
1413 ((y + height - 1) * VIDEO_LINE_LEN) +
1414 x * VIDEO_PIXEL_SIZE);
1416 #ifdef CONFIG_VIDEO_BMP_RLE8
1417 if (compression == BMP_BI_RLE8) {
1418 return display_rle8_bitmap(bmp, x, y, width, height);
1422 /* We handle only 4, 8, or 24 bpp bitmaps */
1423 switch (le16_to_cpu(bmp->header.bit_count)) {
1425 padded_line -= width / 2;
1428 switch (VIDEO_DATA_FORMAT) {
1429 case GDF_32BIT_X888RGB:
1433 * Don't assume that 'width' is an
1436 for (xcount = 0; xcount < width; xcount++) {
1444 cte = bmp->color_table[idx];
1445 FILL_32BIT_X888RGB(cte.red, cte.green,
1448 bmap += padded_line;
1449 fb -= VIDEO_LINE_LEN + width *
1454 puts("4bpp bitmap unsupported with current "
1461 padded_line -= width;
1462 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1464 for (xcount = 0; xcount < colors; ++xcount) {
1465 cte = bmp->color_table[xcount];
1466 video_set_lut(xcount, cte.red, cte.green,
1471 switch (VIDEO_DATA_FORMAT) {
1472 case GDF__8BIT_INDEX:
1479 bmap += padded_line;
1480 fb -= VIDEO_LINE_LEN + width *
1484 case GDF__8BIT_332RGB:
1489 cte = bmp->color_table[*bmap++];
1490 FILL_8BIT_332RGB(cte.red, cte.green,
1493 bmap += padded_line;
1494 fb -= VIDEO_LINE_LEN + width *
1498 case GDF_15BIT_555RGB:
1500 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1506 cte = bmp->color_table[*bmap++];
1507 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1508 fill_555rgb_pswap(fb, xpos++, cte.red,
1513 FILL_15BIT_555RGB(cte.red, cte.green,
1517 bmap += padded_line;
1518 fb -= VIDEO_LINE_LEN + width *
1522 case GDF_16BIT_565RGB:
1527 cte = bmp->color_table[*bmap++];
1528 FILL_16BIT_565RGB(cte.red, cte.green,
1531 bmap += padded_line;
1532 fb -= VIDEO_LINE_LEN + width *
1536 case GDF_32BIT_X888RGB:
1541 cte = bmp->color_table[*bmap++];
1542 FILL_32BIT_X888RGB(cte.red, cte.green,
1545 bmap += padded_line;
1546 fb -= VIDEO_LINE_LEN + width *
1550 case GDF_24BIT_888RGB:
1555 cte = bmp->color_table[*bmap++];
1556 FILL_24BIT_888RGB(cte.red, cte.green,
1559 bmap += padded_line;
1560 fb -= VIDEO_LINE_LEN + width *
1567 padded_line -= 3 * width;
1569 switch (VIDEO_DATA_FORMAT) {
1570 case GDF__8BIT_332RGB:
1575 FILL_8BIT_332RGB(bmap[2], bmap[1],
1579 bmap += padded_line;
1580 fb -= VIDEO_LINE_LEN + width *
1584 case GDF_15BIT_555RGB:
1586 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1592 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1593 fill_555rgb_pswap(fb, xpos++, bmap[2],
1597 FILL_15BIT_555RGB(bmap[2], bmap[1],
1602 bmap += padded_line;
1603 fb -= VIDEO_LINE_LEN + width *
1607 case GDF_16BIT_565RGB:
1612 FILL_16BIT_565RGB(bmap[2], bmap[1],
1616 bmap += padded_line;
1617 fb -= VIDEO_LINE_LEN + width *
1621 case GDF_32BIT_X888RGB:
1626 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1630 bmap += padded_line;
1631 fb -= VIDEO_LINE_LEN + width *
1635 case GDF_24BIT_888RGB:
1640 FILL_24BIT_888RGB(bmap[2], bmap[1],
1644 bmap += padded_line;
1645 fb -= VIDEO_LINE_LEN + width *
1650 printf("Error: 24 bits/pixel bitmap incompatible "
1651 "with current video mode\n");
1656 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1657 le16_to_cpu(bmp->header.bit_count));
1661 #ifdef CONFIG_VIDEO_BMP_GZIP
1667 if (cfb_do_flush_cache)
1668 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1674 #ifdef CONFIG_VIDEO_LOGO
1675 static int video_logo_xpos;
1676 static int video_logo_ypos;
1678 static void plot_logo_or_black(void *screen, int x, int y, int black);
1680 static void logo_plot(void *screen, int x, int y)
1682 plot_logo_or_black(screen, x, y, 0);
1685 static void logo_black(void)
1687 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1691 static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1695 return cmd_usage(cmdtp);
1702 clrlogo, 1, 0, do_clrlogo,
1703 "fill the boot logo area with black",
1707 static void plot_logo_or_black(void *screen, int x, int y, int black)
1711 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1712 int ycount = video_logo_height;
1713 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1714 unsigned char *source;
1715 unsigned char *dest;
1717 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1718 if (x == BMP_ALIGN_CENTER)
1719 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1721 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1723 if (y == BMP_ALIGN_CENTER)
1724 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1726 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1727 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1729 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1731 #ifdef CONFIG_VIDEO_BMP_LOGO
1732 source = bmp_logo_bitmap;
1734 /* Allocate temporary space for computing colormap */
1735 logo_red = malloc(BMP_LOGO_COLORS);
1736 logo_green = malloc(BMP_LOGO_COLORS);
1737 logo_blue = malloc(BMP_LOGO_COLORS);
1738 /* Compute color map */
1739 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1740 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1741 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1742 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1745 source = linux_logo;
1746 logo_red = linux_logo_red;
1747 logo_green = linux_logo_green;
1748 logo_blue = linux_logo_blue;
1751 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1752 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1753 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1754 logo_red[i], logo_green[i],
1760 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1763 xcount = VIDEO_LOGO_WIDTH;
1770 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1771 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1772 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1775 switch (VIDEO_DATA_FORMAT) {
1776 case GDF__8BIT_INDEX:
1779 case GDF__8BIT_332RGB:
1780 *dest = ((r >> 5) << 5) |
1784 case GDF_15BIT_555RGB:
1785 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1786 fill_555rgb_pswap(dest, xpos++, r, g, b);
1788 *(unsigned short *) dest =
1789 SWAP16((unsigned short) (
1795 case GDF_16BIT_565RGB:
1796 *(unsigned short *) dest =
1797 SWAP16((unsigned short) (
1802 case GDF_32BIT_X888RGB:
1809 case GDF_24BIT_888RGB:
1810 #ifdef VIDEO_FB_LITTLE_ENDIAN
1822 dest += VIDEO_PIXEL_SIZE;
1826 #ifdef CONFIG_VIDEO_BMP_LOGO
1833 static void *video_logo(void)
1836 __maybe_unused int y_off = 0;
1837 __maybe_unused ulong addr;
1838 __maybe_unused char *s;
1839 __maybe_unused int len, ret, space;
1841 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1843 #ifdef CONFIG_SPLASH_SCREEN
1844 s = env_get("splashimage");
1846 ret = splash_screen_prepare();
1848 return video_fb_address;
1849 addr = hextoul(s, NULL);
1851 if (video_display_bitmap(addr,
1853 video_logo_ypos) == 0) {
1854 video_logo_height = 0;
1855 return ((void *) (video_fb_address));
1858 #endif /* CONFIG_SPLASH_SCREEN */
1860 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1862 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1864 * when using splashpos for video_logo, skip any info
1865 * output on video console if the logo is not at 0,0
1867 if (video_logo_xpos || video_logo_ypos) {
1869 * video_logo_height is used in text and cursor offset
1870 * calculations. Since the console is below the logo,
1871 * we need to adjust the logo height
1873 if (video_logo_ypos == BMP_ALIGN_CENTER)
1874 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1875 VIDEO_LOGO_HEIGHT) / 2);
1876 else if (video_logo_ypos > 0)
1877 video_logo_height += video_logo_ypos;
1879 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1882 if (board_cfb_skip())
1885 sprintf(info, " %s", version_string);
1887 #ifndef CONFIG_HIDE_LOGO_VERSION
1888 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1892 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1893 uchar *p = (uchar *) info;
1897 video_drawchars(xx, yy, p, space);
1900 p = (uchar *)p + space;
1903 xx += VIDEO_FONT_WIDTH;
1906 yy += VIDEO_FONT_HEIGHT;
1910 video_drawchars(xx, yy, p, len);
1915 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1917 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1920 ((video_logo_height -
1921 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1923 for (i = 1; i < n; i++) {
1924 video_get_info_str(i, info);
1930 video_drawchars(VIDEO_INFO_X,
1934 (uchar *) info, space);
1936 video_drawchars(VIDEO_INFO_X +
1941 (uchar *) info + space,
1944 video_drawstring(VIDEO_INFO_X,
1955 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1959 static int cfb_fb_is_in_dram(void)
1961 struct bd_info *bd = gd->bd;
1965 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1966 start = bd->bi_dram[i].start;
1967 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1968 if ((ulong)video_fb_address >= start &&
1969 (ulong)video_fb_address < end)
1976 void video_clear(void)
1978 if (!video_fb_address)
1980 #ifdef VIDEO_HW_RECTFILL
1981 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
1984 VIDEO_VISIBLE_COLS, /* frame width */
1985 VIDEO_VISIBLE_ROWS, /* frame height */
1986 bgx /* fill color */
1989 memsetl(video_fb_address,
1990 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
1994 static int cfg_video_init(void)
1996 unsigned char color8;
1998 pGD = video_hw_init();
2002 video_fb_address = (void *) VIDEO_FB_ADRS;
2004 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2006 /* Init drawing pats */
2007 switch (VIDEO_DATA_FORMAT) {
2008 case GDF__8BIT_INDEX:
2009 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2010 CONFIG_SYS_CONSOLE_FG_COL,
2011 CONFIG_SYS_CONSOLE_FG_COL);
2012 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2013 CONFIG_SYS_CONSOLE_BG_COL,
2014 CONFIG_SYS_CONSOLE_BG_COL);
2018 case GDF__8BIT_332RGB:
2019 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2020 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2021 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2022 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2024 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2025 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2026 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2027 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2030 case GDF_15BIT_555RGB:
2031 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2032 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2033 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2034 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2035 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2036 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2037 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2038 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2039 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2040 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2041 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2042 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2044 case GDF_16BIT_565RGB:
2045 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2046 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2047 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2048 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2049 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2050 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2051 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2052 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2053 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2054 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2055 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2056 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2058 case GDF_32BIT_X888RGB:
2059 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2060 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2061 CONFIG_SYS_CONSOLE_FG_COL;
2062 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2063 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2064 CONFIG_SYS_CONSOLE_BG_COL;
2066 case GDF_24BIT_888RGB:
2067 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2068 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2069 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2070 CONFIG_SYS_CONSOLE_FG_COL;
2071 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2072 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2073 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2074 CONFIG_SYS_CONSOLE_BG_COL;
2079 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2082 #ifdef CONFIG_VIDEO_LOGO
2083 /* Plot the logo and get start point of console */
2084 debug("Video: Drawing the logo ...\n");
2085 video_console_address = video_logo();
2087 video_console_address = video_fb_address;
2090 /* Initialize the console */
2094 if (cfb_do_flush_cache)
2095 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2101 * Implement a weak default function for boards that optionally
2102 * need to skip the video initialization.
2104 __weak int board_video_skip(void)
2106 /* As default, don't skip test */
2110 int drv_video_init(void)
2112 struct stdio_dev console_dev;
2114 bool __maybe_unused keyboard_ok = false;
2116 /* Check if video initialization should be skipped */
2117 if (board_video_skip())
2120 /* Init video chip - returns with framebuffer cleared */
2121 if (cfg_video_init() == -1)
2124 if (board_cfb_skip())
2127 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2128 have_keyboard = false;
2129 #elif defined(CONFIG_OF_CONTROL)
2130 have_keyboard = !ofnode_conf_read_bool("u-boot,no-keyboard");
2132 have_keyboard = true;
2134 if (have_keyboard) {
2135 debug("KBD: Keyboard init ...\n");
2136 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2137 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2141 /* Init vga device */
2142 memset(&console_dev, 0, sizeof(console_dev));
2143 strcpy(console_dev.name, "vga");
2144 console_dev.flags = DEV_FLAGS_OUTPUT;
2145 console_dev.putc = cfb_video_putc; /* 'putc' function */
2146 console_dev.puts = cfb_video_puts; /* 'puts' function */
2148 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2149 if (have_keyboard && keyboard_ok) {
2150 /* Also init console device */
2151 console_dev.flags |= DEV_FLAGS_INPUT;
2152 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2153 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2157 if (stdio_register(&console_dev) != 0)
2160 /* Return success */
2164 void video_position_cursor(unsigned col, unsigned row)
2166 console_col = min(col, CONSOLE_COLS - 1);
2167 console_row = min(row, CONSOLE_ROWS - 1);
2170 int video_get_pixel_width(void)
2172 return VIDEO_VISIBLE_COLS;
2175 int video_get_pixel_height(void)
2177 return VIDEO_VISIBLE_ROWS;
2180 int video_get_screen_rows(void)
2182 return CONSOLE_ROWS;
2185 int video_get_screen_columns(void)
2187 return CONSOLE_COLS;