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>
81 #if defined(CONFIG_VIDEO_MXS)
82 #define VIDEO_FB_16BPP_WORD_SWAP
86 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
95 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
96 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
97 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
98 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
99 #define VIDEO_FB_ADRS (pGD->frameAdrs)
105 #include <linux/types.h>
106 #include <stdio_dev.h>
107 #include <video_font.h>
109 #if defined(CONFIG_CMD_DATE)
113 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
114 #include <watchdog.h>
115 #include <bmp_layout.h>
119 #if !defined(CONFIG_VIDEO_SW_CURSOR)
120 /* no Cursor defined */
126 #if defined(CONFIG_VIDEO_SW_CURSOR)
127 void console_cursor(int state);
129 #define CURSOR_ON console_cursor(1)
130 #define CURSOR_OFF console_cursor(0)
131 #define CURSOR_SET video_set_cursor()
132 #endif /* CONFIG_VIDEO_SW_CURSOR */
134 #ifdef CONFIG_VIDEO_LOGO
135 #ifdef CONFIG_VIDEO_BMP_LOGO
136 #include <bmp_logo.h>
137 #include <bmp_logo_data.h>
138 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
139 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
140 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
141 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
143 #else /* CONFIG_VIDEO_BMP_LOGO */
144 #define LINUX_LOGO_WIDTH 80
145 #define LINUX_LOGO_HEIGHT 80
146 #define LINUX_LOGO_COLORS 214
147 #define LINUX_LOGO_LUT_OFFSET 0x20
149 #include <linux_logo.h>
150 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
151 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
152 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
153 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
154 #endif /* CONFIG_VIDEO_BMP_LOGO */
155 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
156 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
157 #else /* CONFIG_VIDEO_LOGO */
158 #define VIDEO_LOGO_WIDTH 0
159 #define VIDEO_LOGO_HEIGHT 0
160 #endif /* CONFIG_VIDEO_LOGO */
162 #define VIDEO_COLS VIDEO_VISIBLE_COLS
163 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
164 #ifndef VIDEO_LINE_LEN
165 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
167 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
168 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
170 #ifdef CONFIG_VIDEO_LOGO
171 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
173 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
176 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
177 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
178 #define CONSOLE_ROW_FIRST (video_console_address)
179 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
180 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
181 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
183 /* By default we scroll by a single line */
184 #ifndef CONFIG_CONSOLE_SCROLL_LINES
185 #define CONFIG_CONSOLE_SCROLL_LINES 1
189 #ifdef VIDEO_FB_LITTLE_ENDIAN
190 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
193 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
194 (((x) & 0x0000ff00) << 8) | \
195 (((x) & 0x00ff0000) >> 8) | \
196 (((x) & 0xff000000) >> 24) \
198 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
199 (((x) & 0x0000ff00) >> 8) | \
200 (((x) & 0x00ff0000) << 8) | \
201 (((x) & 0xff000000) >> 8) \
204 #define SWAP16(x) (x)
205 #define SWAP32(x) (x)
206 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
207 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
209 #define SHORTSWAP32(x) (x)
213 DECLARE_GLOBAL_DATA_PTR;
216 static GraphicDevice *pGD; /* Pointer to Graphic array */
218 static void *video_fb_address; /* frame buffer address */
219 static void *video_console_address; /* console buffer start address */
221 static int video_logo_height = VIDEO_LOGO_HEIGHT;
223 static int __maybe_unused cursor_state;
224 static int __maybe_unused old_col;
225 static int __maybe_unused old_row;
227 static int console_col; /* cursor col */
228 static int console_row; /* cursor row */
230 static u32 eorx, fgx, bgx; /* color pats */
232 static int cfb_do_flush_cache;
234 #ifdef CONFIG_CFB_CONSOLE_ANSI
235 static char ansi_buf[10];
236 static int ansi_buf_size;
237 static int ansi_colors_need_revert;
238 static int ansi_cursor_hidden;
241 static const int video_font_draw_table8[] = {
242 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
243 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
244 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
245 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
248 static const int video_font_draw_table15[] = {
249 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
252 static const int video_font_draw_table16[] = {
253 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
256 static const int video_font_draw_table24[16][3] = {
257 {0x00000000, 0x00000000, 0x00000000},
258 {0x00000000, 0x00000000, 0x00ffffff},
259 {0x00000000, 0x0000ffff, 0xff000000},
260 {0x00000000, 0x0000ffff, 0xffffffff},
261 {0x000000ff, 0xffff0000, 0x00000000},
262 {0x000000ff, 0xffff0000, 0x00ffffff},
263 {0x000000ff, 0xffffffff, 0xff000000},
264 {0x000000ff, 0xffffffff, 0xffffffff},
265 {0xffffff00, 0x00000000, 0x00000000},
266 {0xffffff00, 0x00000000, 0x00ffffff},
267 {0xffffff00, 0x0000ffff, 0xff000000},
268 {0xffffff00, 0x0000ffff, 0xffffffff},
269 {0xffffffff, 0xffff0000, 0x00000000},
270 {0xffffffff, 0xffff0000, 0x00ffffff},
271 {0xffffffff, 0xffffffff, 0xff000000},
272 {0xffffffff, 0xffffffff, 0xffffffff}
275 static const int video_font_draw_table32[16][4] = {
276 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
277 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
278 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
279 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
280 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
281 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
282 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
283 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
284 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
285 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
286 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
287 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
288 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
289 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
290 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
291 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
295 * Implement a weak default function for boards that optionally
296 * need to skip the cfb initialization.
298 __weak int board_cfb_skip(void)
300 /* As default, don't skip cfb init */
304 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
306 u8 *cdat, *dest, *dest0;
309 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
310 dest0 = video_fb_address + offset;
312 switch (VIDEO_DATA_FORMAT) {
313 case GDF__8BIT_INDEX:
314 case GDF__8BIT_332RGB:
317 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
318 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
319 rows--; dest += VIDEO_LINE_LEN) {
323 (video_font_draw_table8[bits >> 4] &
326 if (VIDEO_FONT_WIDTH == 4)
330 (video_font_draw_table8[bits & 15] &
333 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
338 case GDF_15BIT_555RGB:
341 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
342 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
343 rows--; dest += VIDEO_LINE_LEN) {
347 SHORTSWAP32((video_font_draw_table15
348 [bits >> 6] & eorx) ^
351 SHORTSWAP32((video_font_draw_table15
352 [bits >> 4 & 3] & eorx) ^
355 if (VIDEO_FONT_WIDTH == 4)
359 SHORTSWAP32((video_font_draw_table15
360 [bits >> 2 & 3] & eorx) ^
363 SHORTSWAP32((video_font_draw_table15
367 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
372 case GDF_16BIT_565RGB:
375 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
376 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
377 rows--; dest += VIDEO_LINE_LEN) {
381 SHORTSWAP32((video_font_draw_table16
382 [bits >> 6] & eorx) ^
385 SHORTSWAP32((video_font_draw_table16
386 [bits >> 4 & 3] & eorx) ^
389 if (VIDEO_FONT_WIDTH == 4)
393 SHORTSWAP32((video_font_draw_table16
394 [bits >> 2 & 3] & eorx) ^
397 SHORTSWAP32((video_font_draw_table16
401 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
406 case GDF_32BIT_X888RGB:
409 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
410 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
411 rows--; dest += VIDEO_LINE_LEN) {
415 SWAP32((video_font_draw_table32
416 [bits >> 4][0] & eorx) ^ bgx);
418 SWAP32((video_font_draw_table32
419 [bits >> 4][1] & eorx) ^ bgx);
421 SWAP32((video_font_draw_table32
422 [bits >> 4][2] & eorx) ^ bgx);
424 SWAP32((video_font_draw_table32
425 [bits >> 4][3] & eorx) ^ bgx);
428 if (VIDEO_FONT_WIDTH == 4)
432 SWAP32((video_font_draw_table32
433 [bits & 15][0] & eorx) ^ bgx);
435 SWAP32((video_font_draw_table32
436 [bits & 15][1] & eorx) ^ bgx);
438 SWAP32((video_font_draw_table32
439 [bits & 15][2] & eorx) ^ bgx);
441 SWAP32((video_font_draw_table32
442 [bits & 15][3] & eorx) ^ bgx);
444 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
449 case GDF_24BIT_888RGB:
452 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
453 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
454 rows--; dest += VIDEO_LINE_LEN) {
458 (video_font_draw_table24[bits >> 4][0]
461 (video_font_draw_table24[bits >> 4][1]
464 (video_font_draw_table24[bits >> 4][2]
467 if (VIDEO_FONT_WIDTH == 4)
471 (video_font_draw_table24[bits & 15][0]
474 (video_font_draw_table24[bits & 15][1]
477 (video_font_draw_table24[bits & 15][2]
480 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
487 static inline void video_drawstring(int xx, int yy, unsigned char *s)
489 video_drawchars(xx, yy, s, strlen((char *) s));
492 static void video_putchar(int xx, int yy, unsigned char c)
494 video_drawchars(xx, yy + video_logo_height, &c, 1);
497 #if defined(CONFIG_VIDEO_SW_CURSOR)
498 static void video_set_cursor(void)
505 static void video_invertchar(int xx, int yy)
507 int firstx = xx * VIDEO_PIXEL_SIZE;
508 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
509 int firsty = yy * VIDEO_LINE_LEN;
510 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
512 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
513 for (x = firstx; x < lastx; x++) {
514 u8 *dest = (u8 *)(video_fb_address) + x + y;
520 void console_cursor(int state)
522 if (cursor_state != state) {
524 /* turn off the cursor */
525 video_invertchar(old_col * VIDEO_FONT_WIDTH,
526 old_row * VIDEO_FONT_HEIGHT +
529 /* turn off the cursor and record where it is */
530 video_invertchar(console_col * VIDEO_FONT_WIDTH,
531 console_row * VIDEO_FONT_HEIGHT +
533 old_col = console_col;
534 old_row = console_row;
536 cursor_state = state;
538 if (cfb_do_flush_cache)
539 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
543 #ifndef VIDEO_HW_RECTFILL
544 static void memsetl(int *p, int c, int v)
551 #ifndef VIDEO_HW_BITBLT
552 static void memcpyl(int *d, int *s, int c)
559 static void console_clear_line(int line, int begin, int end)
561 #ifdef VIDEO_HW_RECTFILL
562 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
563 VIDEO_FONT_WIDTH * begin, /* dest pos x */
565 VIDEO_FONT_HEIGHT * line, /* dest pos y */
566 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
567 VIDEO_FONT_HEIGHT, /* frame height */
571 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
572 memsetl(CONSOLE_ROW_FIRST +
573 CONSOLE_ROW_SIZE * line, /* offset of row */
574 CONSOLE_ROW_SIZE >> 2, /* length of row */
581 offset = CONSOLE_ROW_FIRST +
582 CONSOLE_ROW_SIZE * line + /* offset of row */
584 VIDEO_PIXEL_SIZE * begin; /* offset of col */
585 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
586 size >>= 2; /* length to end for memsetl() */
587 /* fill at col offset of i'th line using bgx as fill color */
588 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
589 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
594 static void console_scrollup(void)
596 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
599 /* copy up rows ignoring the first one */
601 #ifdef VIDEO_HW_BITBLT
602 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
603 0, /* source pos x */
605 VIDEO_FONT_HEIGHT * rows, /* source pos y */
607 video_logo_height, /* dest pos y */
608 VIDEO_VISIBLE_COLS, /* frame width */
611 - VIDEO_FONT_HEIGHT * rows /* frame height */
614 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
615 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
617 /* clear the last one */
618 for (i = 1; i <= rows; i++)
619 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
621 /* Decrement row number */
625 static void console_back(void)
629 if (console_col < 0) {
630 console_col = CONSOLE_COLS - 1;
637 #ifdef CONFIG_CFB_CONSOLE_ANSI
639 static void console_clear(void)
641 #ifdef VIDEO_HW_RECTFILL
642 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
644 video_logo_height, /* dest pos y */
645 VIDEO_VISIBLE_COLS, /* frame width */
646 VIDEO_VISIBLE_ROWS, /* frame height */
650 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
654 static void console_cursor_fix(void)
658 if (console_row >= CONSOLE_ROWS)
659 console_row = CONSOLE_ROWS - 1;
662 if (console_col >= CONSOLE_COLS)
663 console_col = CONSOLE_COLS - 1;
666 static void console_cursor_up(int n)
669 console_cursor_fix();
672 static void console_cursor_down(int n)
675 console_cursor_fix();
678 static void console_cursor_left(int n)
681 console_cursor_fix();
684 static void console_cursor_right(int n)
687 console_cursor_fix();
690 static void console_cursor_set_position(int row, int col)
692 if (console_row != -1)
694 if (console_col != -1)
696 console_cursor_fix();
699 static void console_previousline(int n)
701 /* FIXME: also scroll terminal ? */
703 console_cursor_fix();
706 static void console_swap_colors(void)
714 static inline int console_cursor_is_visible(void)
716 return !ansi_cursor_hidden;
719 static inline int console_cursor_is_visible(void)
725 static void console_newline(int n)
730 /* Check if we need to scroll the terminal */
731 if (console_row >= CONSOLE_ROWS) {
732 /* Scroll everything up */
737 static void console_cr(void)
742 static void parse_putc(const char c)
746 if (console_cursor_is_visible())
750 case 13: /* back to first column */
754 case '\n': /* next line */
755 if (console_col || nl)
761 console_col |= 0x0008;
762 console_col &= ~0x0007;
764 if (console_col >= CONSOLE_COLS)
768 case 8: /* backspace */
775 default: /* draw the char */
776 video_putchar(console_col * VIDEO_FONT_WIDTH,
777 console_row * VIDEO_FONT_HEIGHT, c);
780 /* check for newline */
781 if (console_col >= CONSOLE_COLS) {
787 if (console_cursor_is_visible())
791 static void cfb_video_putc(struct stdio_dev *dev, const char c)
793 #ifdef CONFIG_CFB_CONSOLE_ANSI
797 for (i = 0; i < ansi_buf_size; ++i)
798 parse_putc(ansi_buf[i]);
804 if (ansi_buf_size > 0) {
824 ansi_buf[ansi_buf_size++] = c;
826 if (ansi_buf_size >= sizeof(ansi_buf))
829 for (i = 0; i < ansi_buf_size; ++i) {
835 if (ansi_buf[i] == 27)
842 if (ansi_buf[i] == '[')
849 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
850 num1 = ansi_buf[i]-'0';
852 } else if (ansi_buf[i] != '?') {
860 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
862 num1 += ansi_buf[i]-'0';
870 if (ansi_buf[i] != ';') {
878 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
879 num2 = ansi_buf[i]-'0';
886 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
888 num2 += ansi_buf[i]-'0';
896 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
897 || ansi_buf[i] == 'J'
898 || ansi_buf[i] == 'K'
899 || ansi_buf[i] == 'h'
900 || ansi_buf[i] == 'l'
901 || ansi_buf[i] == 'm') {
911 for (i = 0; i < ansi_buf_size; ++i)
912 parse_putc(ansi_buf[i]);
918 if (!ansi_cursor_hidden)
923 /* move cursor num1 rows up */
924 console_cursor_up(num1);
927 /* move cursor num1 rows down */
928 console_cursor_down(num1);
931 /* move cursor num1 columns forward */
932 console_cursor_right(num1);
935 /* move cursor num1 columns back */
936 console_cursor_left(num1);
939 /* move cursor num1 rows up at begin of row */
940 console_previousline(num1);
943 /* move cursor num1 rows down at begin of row */
944 console_newline(num1);
947 /* move cursor to column num1 */
948 console_cursor_set_position(-1, num1-1);
951 /* move cursor to row num1, column num2 */
952 console_cursor_set_position(num1-1, num2-1);
955 /* clear console and move cursor to 0, 0 */
957 console_cursor_set_position(0, 0);
962 console_clear_line(console_row,
966 console_clear_line(console_row,
969 console_clear_line(console_row,
973 ansi_cursor_hidden = 0;
976 ansi_cursor_hidden = 1;
979 if (num1 == 0) { /* reset swapped colors */
980 if (ansi_colors_need_revert) {
981 console_swap_colors();
982 ansi_colors_need_revert = 0;
984 } else if (num1 == 7) { /* once swap colors */
985 if (!ansi_colors_need_revert) {
986 console_swap_colors();
987 ansi_colors_need_revert = 1;
992 if (!ansi_cursor_hidden)
1001 if (cfb_do_flush_cache)
1002 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1005 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1007 int flush = cfb_do_flush_cache;
1008 int count = strlen(s);
1010 /* temporarily disable cache flush */
1011 cfb_do_flush_cache = 0;
1014 cfb_video_putc(dev, *s++);
1017 cfb_do_flush_cache = flush;
1018 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1023 * Do not enforce drivers (or board code) to provide empty
1024 * video_set_lut() if they do not support 8 bpp format.
1025 * Implement weak default function instead.
1027 __weak void video_set_lut(unsigned int index, unsigned char r,
1028 unsigned char g, unsigned char b)
1032 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1034 #define FILL_8BIT_332RGB(r,g,b) { \
1035 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1039 #define FILL_15BIT_555RGB(r,g,b) { \
1040 *(unsigned short *)fb = \
1041 SWAP16((unsigned short)(((r>>3)<<10) | \
1047 #define FILL_16BIT_565RGB(r,g,b) { \
1048 *(unsigned short *)fb = \
1049 SWAP16((unsigned short)((((r)>>3)<<11)| \
1055 #define FILL_32BIT_X888RGB(r,g,b) { \
1057 SWAP32((unsigned int)(((r<<16) | \
1063 #ifdef VIDEO_FB_LITTLE_ENDIAN
1064 #define FILL_24BIT_888RGB(r,g,b) { \
1071 #define FILL_24BIT_888RGB(r,g,b) { \
1079 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1080 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1082 ushort *dst = (ushort *) fb;
1083 ushort color = (ushort) (((r >> 3) << 10) |
1094 * RLE8 bitmap support
1097 #ifdef CONFIG_VIDEO_BMP_RLE8
1098 /* Pre-calculated color table entry */
1101 unsigned short w; /* word */
1102 unsigned int dw; /* double word */
1103 } ce; /* color entry */
1107 * Helper to draw encoded/unencoded run.
1109 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1112 ulong addr = (ulong) *fb;
1118 * Setup offset of the color index in the bitmap.
1119 * Color index of encoded run is at offset 1.
1121 off = enc ? &enc_off : &i;
1123 switch (VIDEO_DATA_FORMAT) {
1124 case GDF__8BIT_INDEX:
1125 for (i = 0; i < cnt; i++)
1126 *(unsigned char *) addr++ = bm[*off];
1128 case GDF_15BIT_555RGB:
1129 case GDF_16BIT_565RGB:
1130 /* differences handled while pre-calculating palette */
1131 for (i = 0; i < cnt; i++) {
1132 *(unsigned short *) addr = p[bm[*off]].ce.w;
1136 case GDF_32BIT_X888RGB:
1137 for (i = 0; i < cnt; i++) {
1138 *(u32 *) addr = p[bm[*off]].ce.dw;
1143 *fb = (uchar *) addr; /* return modified address */
1146 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1147 int width, int height)
1151 unsigned int cnt, runlen;
1153 int x, y, bpp, i, ncolors;
1154 struct palette p[256];
1155 struct bmp_color_table_entry cte;
1156 int green_shift, red_off;
1157 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1161 y = __le32_to_cpu(img->header.height) - 1;
1162 ncolors = __le32_to_cpu(img->header.colors_used);
1163 bpp = VIDEO_PIXEL_SIZE;
1164 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1165 (y + yoff) * VIDEO_LINE_LEN +
1168 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1170 /* pre-calculate and setup palette */
1171 switch (VIDEO_DATA_FORMAT) {
1172 case GDF__8BIT_INDEX:
1173 for (i = 0; i < ncolors; i++) {
1174 cte = img->color_table[i];
1175 video_set_lut(i, cte.red, cte.green, cte.blue);
1178 case GDF_15BIT_555RGB:
1179 case GDF_16BIT_565RGB:
1180 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1187 for (i = 0; i < ncolors; i++) {
1188 cte = img->color_table[i];
1189 p[i].ce.w = SWAP16((unsigned short)
1190 (((cte.red >> 3) << red_off) |
1191 ((cte.green >> green_shift) << 5) |
1195 case GDF_32BIT_X888RGB:
1196 for (i = 0; i < ncolors; i++) {
1197 cte = img->color_table[i];
1198 p[i].ce.dw = SWAP32((cte.red << 16) |
1204 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1214 /* scan line end marker */
1218 fbp = (unsigned char *)
1219 ((unsigned int) video_fb_address +
1220 (y + yoff) * VIDEO_LINE_LEN +
1224 /* end of bitmap data marker */
1228 /* run offset marker */
1231 fbp = (unsigned char *)
1232 ((unsigned int) video_fb_address +
1233 (y + yoff) * VIDEO_LINE_LEN +
1251 if (x + runlen > width)
1253 draw_bitmap(&fbp, bm, p, cnt, 0);
1259 bm++; /* 0 padding if length is odd */
1270 if (y < height) { /* only draw into visible area */
1276 if (x + runlen > width)
1278 draw_bitmap(&fbp, bm, p, cnt, 1);
1286 if (cfb_do_flush_cache)
1287 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1291 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1297 * Display the BMP file located at address bmp_image.
1299 int video_display_bitmap(ulong bmp_image, int x, int y)
1301 ushort xcount, ycount;
1303 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1306 unsigned long width, height, bpp;
1308 unsigned long compression;
1309 struct bmp_color_table_entry cte;
1311 #ifdef CONFIG_VIDEO_BMP_GZIP
1312 unsigned char *dst = NULL;
1318 if (!((bmp->header.signature[0] == 'B') &&
1319 (bmp->header.signature[1] == 'M'))) {
1321 #ifdef CONFIG_VIDEO_BMP_GZIP
1323 * Could be a gzipped bmp image, try to decrompress...
1325 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1326 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1328 printf("Error: malloc in gunzip failed!\n");
1332 * NB: we need to force offset of +2
1333 * See doc/README.displaying-bmps
1335 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1336 (uchar *) bmp_image,
1338 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1343 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1344 printf("Image could be truncated "
1345 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1349 * Set addr to decompressed image
1351 bmp = (struct bmp_image *)(dst+2);
1353 if (!((bmp->header.signature[0] == 'B') &&
1354 (bmp->header.signature[1] == 'M'))) {
1355 printf("Error: no valid bmp.gz image at %lx\n",
1361 printf("Error: no valid bmp image at %lx\n", bmp_image);
1363 #endif /* CONFIG_VIDEO_BMP_GZIP */
1366 width = le32_to_cpu(bmp->header.width);
1367 height = le32_to_cpu(bmp->header.height);
1368 bpp = le16_to_cpu(bmp->header.bit_count);
1369 colors = le32_to_cpu(bmp->header.colors_used);
1370 compression = le32_to_cpu(bmp->header.compression);
1372 debug("Display-bmp: %ld x %ld with %d colors\n",
1373 width, height, colors);
1375 if (compression != BMP_BI_RGB
1376 #ifdef CONFIG_VIDEO_BMP_RLE8
1377 && compression != BMP_BI_RLE8
1380 printf("Error: compression type %ld not supported\n",
1382 #ifdef CONFIG_VIDEO_BMP_GZIP
1389 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1391 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1392 if (x == BMP_ALIGN_CENTER)
1393 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1395 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1397 if (y == BMP_ALIGN_CENTER)
1398 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1400 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1401 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1404 * Just ignore elements which are completely beyond screen
1407 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1410 if ((x + width) > VIDEO_VISIBLE_COLS)
1411 width = VIDEO_VISIBLE_COLS - x;
1412 if ((y + height) > VIDEO_VISIBLE_ROWS)
1413 height = VIDEO_VISIBLE_ROWS - y;
1415 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1416 fb = (uchar *) (video_fb_address +
1417 ((y + height - 1) * VIDEO_LINE_LEN) +
1418 x * VIDEO_PIXEL_SIZE);
1420 #ifdef CONFIG_VIDEO_BMP_RLE8
1421 if (compression == BMP_BI_RLE8) {
1422 return display_rle8_bitmap(bmp, x, y, width, height);
1426 /* We handle only 4, 8, or 24 bpp bitmaps */
1427 switch (le16_to_cpu(bmp->header.bit_count)) {
1429 padded_line -= width / 2;
1432 switch (VIDEO_DATA_FORMAT) {
1433 case GDF_32BIT_X888RGB:
1437 * Don't assume that 'width' is an
1440 for (xcount = 0; xcount < width; xcount++) {
1448 cte = bmp->color_table[idx];
1449 FILL_32BIT_X888RGB(cte.red, cte.green,
1452 bmap += padded_line;
1453 fb -= VIDEO_LINE_LEN + width *
1458 puts("4bpp bitmap unsupported with current "
1465 padded_line -= width;
1466 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1468 for (xcount = 0; xcount < colors; ++xcount) {
1469 cte = bmp->color_table[xcount];
1470 video_set_lut(xcount, cte.red, cte.green,
1475 switch (VIDEO_DATA_FORMAT) {
1476 case GDF__8BIT_INDEX:
1483 bmap += padded_line;
1484 fb -= VIDEO_LINE_LEN + width *
1488 case GDF__8BIT_332RGB:
1493 cte = bmp->color_table[*bmap++];
1494 FILL_8BIT_332RGB(cte.red, cte.green,
1497 bmap += padded_line;
1498 fb -= VIDEO_LINE_LEN + width *
1502 case GDF_15BIT_555RGB:
1504 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1510 cte = bmp->color_table[*bmap++];
1511 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1512 fill_555rgb_pswap(fb, xpos++, cte.red,
1517 FILL_15BIT_555RGB(cte.red, cte.green,
1521 bmap += padded_line;
1522 fb -= VIDEO_LINE_LEN + width *
1526 case GDF_16BIT_565RGB:
1531 cte = bmp->color_table[*bmap++];
1532 FILL_16BIT_565RGB(cte.red, cte.green,
1535 bmap += padded_line;
1536 fb -= VIDEO_LINE_LEN + width *
1540 case GDF_32BIT_X888RGB:
1545 cte = bmp->color_table[*bmap++];
1546 FILL_32BIT_X888RGB(cte.red, cte.green,
1549 bmap += padded_line;
1550 fb -= VIDEO_LINE_LEN + width *
1554 case GDF_24BIT_888RGB:
1559 cte = bmp->color_table[*bmap++];
1560 FILL_24BIT_888RGB(cte.red, cte.green,
1563 bmap += padded_line;
1564 fb -= VIDEO_LINE_LEN + width *
1571 padded_line -= 3 * width;
1573 switch (VIDEO_DATA_FORMAT) {
1574 case GDF__8BIT_332RGB:
1579 FILL_8BIT_332RGB(bmap[2], bmap[1],
1583 bmap += padded_line;
1584 fb -= VIDEO_LINE_LEN + width *
1588 case GDF_15BIT_555RGB:
1590 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1596 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1597 fill_555rgb_pswap(fb, xpos++, bmap[2],
1601 FILL_15BIT_555RGB(bmap[2], bmap[1],
1606 bmap += padded_line;
1607 fb -= VIDEO_LINE_LEN + width *
1611 case GDF_16BIT_565RGB:
1616 FILL_16BIT_565RGB(bmap[2], bmap[1],
1620 bmap += padded_line;
1621 fb -= VIDEO_LINE_LEN + width *
1625 case GDF_32BIT_X888RGB:
1630 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1634 bmap += padded_line;
1635 fb -= VIDEO_LINE_LEN + width *
1639 case GDF_24BIT_888RGB:
1644 FILL_24BIT_888RGB(bmap[2], bmap[1],
1648 bmap += padded_line;
1649 fb -= VIDEO_LINE_LEN + width *
1654 printf("Error: 24 bits/pixel bitmap incompatible "
1655 "with current video mode\n");
1660 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1661 le16_to_cpu(bmp->header.bit_count));
1665 #ifdef CONFIG_VIDEO_BMP_GZIP
1671 if (cfb_do_flush_cache)
1672 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1678 #ifdef CONFIG_VIDEO_LOGO
1679 static int video_logo_xpos;
1680 static int video_logo_ypos;
1682 static void plot_logo_or_black(void *screen, int x, int y, int black);
1684 static void logo_plot(void *screen, int x, int y)
1686 plot_logo_or_black(screen, x, y, 0);
1689 static void logo_black(void)
1691 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1695 static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1699 return cmd_usage(cmdtp);
1706 clrlogo, 1, 0, do_clrlogo,
1707 "fill the boot logo area with black",
1711 static void plot_logo_or_black(void *screen, int x, int y, int black)
1715 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1716 int ycount = video_logo_height;
1717 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1718 unsigned char *source;
1719 unsigned char *dest;
1721 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1722 if (x == BMP_ALIGN_CENTER)
1723 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1725 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1727 if (y == BMP_ALIGN_CENTER)
1728 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1730 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1731 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1733 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1735 #ifdef CONFIG_VIDEO_BMP_LOGO
1736 source = bmp_logo_bitmap;
1738 /* Allocate temporary space for computing colormap */
1739 logo_red = malloc(BMP_LOGO_COLORS);
1740 logo_green = malloc(BMP_LOGO_COLORS);
1741 logo_blue = malloc(BMP_LOGO_COLORS);
1742 /* Compute color map */
1743 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1744 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1745 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1746 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1749 source = linux_logo;
1750 logo_red = linux_logo_red;
1751 logo_green = linux_logo_green;
1752 logo_blue = linux_logo_blue;
1755 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1756 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1757 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1758 logo_red[i], logo_green[i],
1764 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1767 xcount = VIDEO_LOGO_WIDTH;
1774 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1775 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1776 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1779 switch (VIDEO_DATA_FORMAT) {
1780 case GDF__8BIT_INDEX:
1783 case GDF__8BIT_332RGB:
1784 *dest = ((r >> 5) << 5) |
1788 case GDF_15BIT_555RGB:
1789 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1790 fill_555rgb_pswap(dest, xpos++, r, g, b);
1792 *(unsigned short *) dest =
1793 SWAP16((unsigned short) (
1799 case GDF_16BIT_565RGB:
1800 *(unsigned short *) dest =
1801 SWAP16((unsigned short) (
1806 case GDF_32BIT_X888RGB:
1813 case GDF_24BIT_888RGB:
1814 #ifdef VIDEO_FB_LITTLE_ENDIAN
1826 dest += VIDEO_PIXEL_SIZE;
1830 #ifdef CONFIG_VIDEO_BMP_LOGO
1837 static void *video_logo(void)
1840 __maybe_unused int y_off = 0;
1841 __maybe_unused ulong addr;
1842 __maybe_unused char *s;
1843 __maybe_unused int len, ret, space;
1845 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1847 #ifdef CONFIG_SPLASH_SCREEN
1848 s = env_get("splashimage");
1850 ret = splash_screen_prepare();
1852 return video_fb_address;
1853 addr = hextoul(s, NULL);
1855 if (video_display_bitmap(addr,
1857 video_logo_ypos) == 0) {
1858 video_logo_height = 0;
1859 return ((void *) (video_fb_address));
1862 #endif /* CONFIG_SPLASH_SCREEN */
1864 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1866 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1868 * when using splashpos for video_logo, skip any info
1869 * output on video console if the logo is not at 0,0
1871 if (video_logo_xpos || video_logo_ypos) {
1873 * video_logo_height is used in text and cursor offset
1874 * calculations. Since the console is below the logo,
1875 * we need to adjust the logo height
1877 if (video_logo_ypos == BMP_ALIGN_CENTER)
1878 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1879 VIDEO_LOGO_HEIGHT) / 2);
1880 else if (video_logo_ypos > 0)
1881 video_logo_height += video_logo_ypos;
1883 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1886 if (board_cfb_skip())
1889 sprintf(info, " %s", version_string);
1891 #ifndef CONFIG_HIDE_LOGO_VERSION
1892 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1896 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1897 uchar *p = (uchar *) info;
1901 video_drawchars(xx, yy, p, space);
1904 p = (uchar *)p + space;
1907 xx += VIDEO_FONT_WIDTH;
1910 yy += VIDEO_FONT_HEIGHT;
1914 video_drawchars(xx, yy, p, len);
1919 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1921 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1924 ((video_logo_height -
1925 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1927 for (i = 1; i < n; i++) {
1928 video_get_info_str(i, info);
1934 video_drawchars(VIDEO_INFO_X,
1938 (uchar *) info, space);
1940 video_drawchars(VIDEO_INFO_X +
1945 (uchar *) info + space,
1948 video_drawstring(VIDEO_INFO_X,
1959 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1963 static int cfb_fb_is_in_dram(void)
1965 struct bd_info *bd = gd->bd;
1969 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1970 start = bd->bi_dram[i].start;
1971 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1972 if ((ulong)video_fb_address >= start &&
1973 (ulong)video_fb_address < end)
1980 void video_clear(void)
1982 if (!video_fb_address)
1984 #ifdef VIDEO_HW_RECTFILL
1985 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
1988 VIDEO_VISIBLE_COLS, /* frame width */
1989 VIDEO_VISIBLE_ROWS, /* frame height */
1990 bgx /* fill color */
1993 memsetl(video_fb_address,
1994 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
1998 static int cfg_video_init(void)
2000 unsigned char color8;
2002 pGD = video_hw_init();
2006 video_fb_address = (void *) VIDEO_FB_ADRS;
2008 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2010 /* Init drawing pats */
2011 switch (VIDEO_DATA_FORMAT) {
2012 case GDF__8BIT_INDEX:
2013 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2014 CONFIG_SYS_CONSOLE_FG_COL,
2015 CONFIG_SYS_CONSOLE_FG_COL);
2016 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2017 CONFIG_SYS_CONSOLE_BG_COL,
2018 CONFIG_SYS_CONSOLE_BG_COL);
2022 case GDF__8BIT_332RGB:
2023 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2024 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2025 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2026 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2028 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2029 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2030 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2031 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2034 case GDF_15BIT_555RGB:
2035 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2036 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2037 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2038 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2039 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2040 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2041 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2042 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2043 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2044 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2045 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2046 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2048 case GDF_16BIT_565RGB:
2049 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2050 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2051 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2052 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2053 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2054 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2055 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2056 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2057 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2058 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2059 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2060 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2062 case GDF_32BIT_X888RGB:
2063 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2064 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2065 CONFIG_SYS_CONSOLE_FG_COL;
2066 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2067 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2068 CONFIG_SYS_CONSOLE_BG_COL;
2070 case GDF_24BIT_888RGB:
2071 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2072 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2073 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2074 CONFIG_SYS_CONSOLE_FG_COL;
2075 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2076 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2077 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2078 CONFIG_SYS_CONSOLE_BG_COL;
2083 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2086 #ifdef CONFIG_VIDEO_LOGO
2087 /* Plot the logo and get start point of console */
2088 debug("Video: Drawing the logo ...\n");
2089 video_console_address = video_logo();
2091 video_console_address = video_fb_address;
2094 /* Initialize the console */
2098 if (cfb_do_flush_cache)
2099 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2105 * Implement a weak default function for boards that optionally
2106 * need to skip the video initialization.
2108 __weak int board_video_skip(void)
2110 /* As default, don't skip test */
2114 int drv_video_init(void)
2116 struct stdio_dev console_dev;
2118 bool __maybe_unused keyboard_ok = false;
2120 /* Check if video initialization should be skipped */
2121 if (board_video_skip())
2124 /* Init video chip - returns with framebuffer cleared */
2125 if (cfg_video_init() == -1)
2128 if (board_cfb_skip())
2131 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2132 have_keyboard = false;
2133 #elif defined(CONFIG_OF_CONTROL)
2134 have_keyboard = !ofnode_conf_read_bool("u-boot,no-keyboard");
2136 have_keyboard = true;
2138 if (have_keyboard) {
2139 debug("KBD: Keyboard init ...\n");
2140 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2141 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2145 /* Init vga device */
2146 memset(&console_dev, 0, sizeof(console_dev));
2147 strcpy(console_dev.name, "vga");
2148 console_dev.flags = DEV_FLAGS_OUTPUT;
2149 console_dev.putc = cfb_video_putc; /* 'putc' function */
2150 console_dev.puts = cfb_video_puts; /* 'puts' function */
2152 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2153 if (have_keyboard && keyboard_ok) {
2154 /* Also init console device */
2155 console_dev.flags |= DEV_FLAGS_INPUT;
2156 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2157 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2161 if (stdio_register(&console_dev) != 0)
2164 /* Return success */
2168 void video_position_cursor(unsigned col, unsigned row)
2170 console_col = min(col, CONSOLE_COLS - 1);
2171 console_row = min(row, CONSOLE_ROWS - 1);
2174 int video_get_pixel_width(void)
2176 return VIDEO_VISIBLE_COLS;
2179 int video_get_pixel_height(void)
2181 return VIDEO_VISIBLE_ROWS;
2184 int video_get_screen_rows(void)
2186 return CONSOLE_ROWS;
2189 int video_get_screen_columns(void)
2191 return CONSOLE_COLS;