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
76 #include <linux/compiler.h>
78 #if defined(CONFIG_VIDEO_MXS)
79 #define VIDEO_FB_16BPP_WORD_SWAP
83 * Defines for the MB862xx driver
85 #ifdef CONFIG_VIDEO_MB862xx
87 #ifdef CONFIG_VIDEO_CORALP
88 #define VIDEO_FB_LITTLE_ENDIAN
90 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
91 #define VIDEO_HW_RECTFILL
92 #define VIDEO_HW_BITBLT
97 * Defines for the i.MX31 driver (mx3fb.c)
99 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
100 #define VIDEO_FB_16BPP_WORD_SWAP
104 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
106 #include <video_fb.h>
113 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
114 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
115 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
116 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
117 #define VIDEO_FB_ADRS (pGD->frameAdrs)
124 #include <linux/types.h>
125 #include <stdio_dev.h>
126 #include <video_font.h>
128 #if defined(CONFIG_CMD_DATE)
132 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
133 #include <watchdog.h>
134 #include <bmp_layout.h>
138 #if !defined(CONFIG_VIDEO_SW_CURSOR)
139 /* no Cursor defined */
145 #if defined(CONFIG_VIDEO_SW_CURSOR)
146 void console_cursor(int state);
148 #define CURSOR_ON console_cursor(1)
149 #define CURSOR_OFF console_cursor(0)
150 #define CURSOR_SET video_set_cursor()
151 #endif /* CONFIG_VIDEO_SW_CURSOR */
153 #ifdef CONFIG_VIDEO_LOGO
154 #ifdef CONFIG_VIDEO_BMP_LOGO
155 #include <bmp_logo.h>
156 #include <bmp_logo_data.h>
157 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
158 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
159 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
160 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
162 #else /* CONFIG_VIDEO_BMP_LOGO */
163 #define LINUX_LOGO_WIDTH 80
164 #define LINUX_LOGO_HEIGHT 80
165 #define LINUX_LOGO_COLORS 214
166 #define LINUX_LOGO_LUT_OFFSET 0x20
168 #include <linux_logo.h>
169 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
170 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
171 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
172 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
173 #endif /* CONFIG_VIDEO_BMP_LOGO */
174 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
175 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
176 #else /* CONFIG_VIDEO_LOGO */
177 #define VIDEO_LOGO_WIDTH 0
178 #define VIDEO_LOGO_HEIGHT 0
179 #endif /* CONFIG_VIDEO_LOGO */
181 #define VIDEO_COLS VIDEO_VISIBLE_COLS
182 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
183 #ifndef VIDEO_LINE_LEN
184 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
186 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
187 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
189 #ifdef CONFIG_VIDEO_LOGO
190 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
192 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
195 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
196 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
197 #define CONSOLE_ROW_FIRST (video_console_address)
198 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
199 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
200 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
202 /* By default we scroll by a single line */
203 #ifndef CONFIG_CONSOLE_SCROLL_LINES
204 #define CONFIG_CONSOLE_SCROLL_LINES 1
208 #ifdef VIDEO_FB_LITTLE_ENDIAN
209 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
212 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
213 (((x) & 0x0000ff00) << 8) | \
214 (((x) & 0x00ff0000) >> 8) | \
215 (((x) & 0xff000000) >> 24) \
217 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
218 (((x) & 0x0000ff00) >> 8) | \
219 (((x) & 0x00ff0000) << 8) | \
220 (((x) & 0xff000000) >> 8) \
223 #define SWAP16(x) (x)
224 #define SWAP32(x) (x)
225 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
226 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
228 #define SHORTSWAP32(x) (x)
232 DECLARE_GLOBAL_DATA_PTR;
235 static GraphicDevice *pGD; /* Pointer to Graphic array */
237 static void *video_fb_address; /* frame buffer address */
238 static void *video_console_address; /* console buffer start address */
240 static int video_logo_height = VIDEO_LOGO_HEIGHT;
242 static int __maybe_unused cursor_state;
243 static int __maybe_unused old_col;
244 static int __maybe_unused old_row;
246 static int console_col; /* cursor col */
247 static int console_row; /* cursor row */
249 static u32 eorx, fgx, bgx; /* color pats */
251 static int cfb_do_flush_cache;
253 #ifdef CONFIG_CFB_CONSOLE_ANSI
254 static char ansi_buf[10];
255 static int ansi_buf_size;
256 static int ansi_colors_need_revert;
257 static int ansi_cursor_hidden;
260 static const int video_font_draw_table8[] = {
261 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
262 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
263 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
264 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
267 static const int video_font_draw_table15[] = {
268 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
271 static const int video_font_draw_table16[] = {
272 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
275 static const int video_font_draw_table24[16][3] = {
276 {0x00000000, 0x00000000, 0x00000000},
277 {0x00000000, 0x00000000, 0x00ffffff},
278 {0x00000000, 0x0000ffff, 0xff000000},
279 {0x00000000, 0x0000ffff, 0xffffffff},
280 {0x000000ff, 0xffff0000, 0x00000000},
281 {0x000000ff, 0xffff0000, 0x00ffffff},
282 {0x000000ff, 0xffffffff, 0xff000000},
283 {0x000000ff, 0xffffffff, 0xffffffff},
284 {0xffffff00, 0x00000000, 0x00000000},
285 {0xffffff00, 0x00000000, 0x00ffffff},
286 {0xffffff00, 0x0000ffff, 0xff000000},
287 {0xffffff00, 0x0000ffff, 0xffffffff},
288 {0xffffffff, 0xffff0000, 0x00000000},
289 {0xffffffff, 0xffff0000, 0x00ffffff},
290 {0xffffffff, 0xffffffff, 0xff000000},
291 {0xffffffff, 0xffffffff, 0xffffffff}
294 static const int video_font_draw_table32[16][4] = {
295 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
296 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
297 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
298 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
299 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
300 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
301 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
302 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
303 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
304 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
305 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
306 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
307 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
308 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
309 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
310 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
314 * Implement a weak default function for boards that optionally
315 * need to skip the cfb initialization.
317 __weak int board_cfb_skip(void)
319 /* As default, don't skip cfb init */
323 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
325 u8 *cdat, *dest, *dest0;
328 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
329 dest0 = video_fb_address + offset;
331 switch (VIDEO_DATA_FORMAT) {
332 case GDF__8BIT_INDEX:
333 case GDF__8BIT_332RGB:
336 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
337 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
338 rows--; dest += VIDEO_LINE_LEN) {
342 (video_font_draw_table8[bits >> 4] &
345 if (VIDEO_FONT_WIDTH == 4)
349 (video_font_draw_table8[bits & 15] &
352 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
357 case GDF_15BIT_555RGB:
360 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
361 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
362 rows--; dest += VIDEO_LINE_LEN) {
366 SHORTSWAP32((video_font_draw_table15
367 [bits >> 6] & eorx) ^
370 SHORTSWAP32((video_font_draw_table15
371 [bits >> 4 & 3] & eorx) ^
374 if (VIDEO_FONT_WIDTH == 4)
378 SHORTSWAP32((video_font_draw_table15
379 [bits >> 2 & 3] & eorx) ^
382 SHORTSWAP32((video_font_draw_table15
386 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
391 case GDF_16BIT_565RGB:
394 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
395 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
396 rows--; dest += VIDEO_LINE_LEN) {
400 SHORTSWAP32((video_font_draw_table16
401 [bits >> 6] & eorx) ^
404 SHORTSWAP32((video_font_draw_table16
405 [bits >> 4 & 3] & eorx) ^
408 if (VIDEO_FONT_WIDTH == 4)
412 SHORTSWAP32((video_font_draw_table16
413 [bits >> 2 & 3] & eorx) ^
416 SHORTSWAP32((video_font_draw_table16
420 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
425 case GDF_32BIT_X888RGB:
428 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
429 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
430 rows--; dest += VIDEO_LINE_LEN) {
434 SWAP32((video_font_draw_table32
435 [bits >> 4][0] & eorx) ^ bgx);
437 SWAP32((video_font_draw_table32
438 [bits >> 4][1] & eorx) ^ bgx);
440 SWAP32((video_font_draw_table32
441 [bits >> 4][2] & eorx) ^ bgx);
443 SWAP32((video_font_draw_table32
444 [bits >> 4][3] & eorx) ^ bgx);
447 if (VIDEO_FONT_WIDTH == 4)
451 SWAP32((video_font_draw_table32
452 [bits & 15][0] & eorx) ^ bgx);
454 SWAP32((video_font_draw_table32
455 [bits & 15][1] & eorx) ^ bgx);
457 SWAP32((video_font_draw_table32
458 [bits & 15][2] & eorx) ^ bgx);
460 SWAP32((video_font_draw_table32
461 [bits & 15][3] & eorx) ^ bgx);
463 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
468 case GDF_24BIT_888RGB:
471 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
472 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
473 rows--; dest += VIDEO_LINE_LEN) {
477 (video_font_draw_table24[bits >> 4][0]
480 (video_font_draw_table24[bits >> 4][1]
483 (video_font_draw_table24[bits >> 4][2]
486 if (VIDEO_FONT_WIDTH == 4)
490 (video_font_draw_table24[bits & 15][0]
493 (video_font_draw_table24[bits & 15][1]
496 (video_font_draw_table24[bits & 15][2]
499 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
506 static inline void video_drawstring(int xx, int yy, unsigned char *s)
508 video_drawchars(xx, yy, s, strlen((char *) s));
511 static void video_putchar(int xx, int yy, unsigned char c)
513 video_drawchars(xx, yy + video_logo_height, &c, 1);
516 #if defined(CONFIG_VIDEO_SW_CURSOR)
517 static void video_set_cursor(void)
524 static void video_invertchar(int xx, int yy)
526 int firstx = xx * VIDEO_PIXEL_SIZE;
527 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
528 int firsty = yy * VIDEO_LINE_LEN;
529 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
531 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
532 for (x = firstx; x < lastx; x++) {
533 u8 *dest = (u8 *)(video_fb_address) + x + y;
539 void console_cursor(int state)
541 if (cursor_state != state) {
543 /* turn off the cursor */
544 video_invertchar(old_col * VIDEO_FONT_WIDTH,
545 old_row * VIDEO_FONT_HEIGHT +
548 /* turn off the cursor and record where it is */
549 video_invertchar(console_col * VIDEO_FONT_WIDTH,
550 console_row * VIDEO_FONT_HEIGHT +
552 old_col = console_col;
553 old_row = console_row;
555 cursor_state = state;
557 if (cfb_do_flush_cache)
558 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
562 #ifndef VIDEO_HW_RECTFILL
563 static void memsetl(int *p, int c, int v)
570 #ifndef VIDEO_HW_BITBLT
571 static void memcpyl(int *d, int *s, int c)
578 static void console_clear_line(int line, int begin, int end)
580 #ifdef VIDEO_HW_RECTFILL
581 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
582 VIDEO_FONT_WIDTH * begin, /* dest pos x */
584 VIDEO_FONT_HEIGHT * line, /* dest pos y */
585 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
586 VIDEO_FONT_HEIGHT, /* frame height */
590 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
591 memsetl(CONSOLE_ROW_FIRST +
592 CONSOLE_ROW_SIZE * line, /* offset of row */
593 CONSOLE_ROW_SIZE >> 2, /* length of row */
600 offset = CONSOLE_ROW_FIRST +
601 CONSOLE_ROW_SIZE * line + /* offset of row */
603 VIDEO_PIXEL_SIZE * begin; /* offset of col */
604 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
605 size >>= 2; /* length to end for memsetl() */
606 /* fill at col offset of i'th line using bgx as fill color */
607 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
608 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
613 static void console_scrollup(void)
615 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
618 /* copy up rows ignoring the first one */
620 #ifdef VIDEO_HW_BITBLT
621 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
622 0, /* source pos x */
624 VIDEO_FONT_HEIGHT * rows, /* source pos y */
626 video_logo_height, /* dest pos y */
627 VIDEO_VISIBLE_COLS, /* frame width */
630 - VIDEO_FONT_HEIGHT * rows /* frame height */
633 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
634 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
636 /* clear the last one */
637 for (i = 1; i <= rows; i++)
638 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
640 /* Decrement row number */
644 static void console_back(void)
648 if (console_col < 0) {
649 console_col = CONSOLE_COLS - 1;
656 #ifdef CONFIG_CFB_CONSOLE_ANSI
658 static void console_clear(void)
660 #ifdef VIDEO_HW_RECTFILL
661 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
663 video_logo_height, /* dest pos y */
664 VIDEO_VISIBLE_COLS, /* frame width */
665 VIDEO_VISIBLE_ROWS, /* frame height */
669 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
673 static void console_cursor_fix(void)
677 if (console_row >= CONSOLE_ROWS)
678 console_row = CONSOLE_ROWS - 1;
681 if (console_col >= CONSOLE_COLS)
682 console_col = CONSOLE_COLS - 1;
685 static void console_cursor_up(int n)
688 console_cursor_fix();
691 static void console_cursor_down(int n)
694 console_cursor_fix();
697 static void console_cursor_left(int n)
700 console_cursor_fix();
703 static void console_cursor_right(int n)
706 console_cursor_fix();
709 static void console_cursor_set_position(int row, int col)
711 if (console_row != -1)
713 if (console_col != -1)
715 console_cursor_fix();
718 static void console_previousline(int n)
720 /* FIXME: also scroll terminal ? */
722 console_cursor_fix();
725 static void console_swap_colors(void)
733 static inline int console_cursor_is_visible(void)
735 return !ansi_cursor_hidden;
738 static inline int console_cursor_is_visible(void)
744 static void console_newline(int n)
749 /* Check if we need to scroll the terminal */
750 if (console_row >= CONSOLE_ROWS) {
751 /* Scroll everything up */
756 static void console_cr(void)
761 static void parse_putc(const char c)
765 if (console_cursor_is_visible())
769 case 13: /* back to first column */
773 case '\n': /* next line */
774 if (console_col || nl)
780 console_col |= 0x0008;
781 console_col &= ~0x0007;
783 if (console_col >= CONSOLE_COLS)
787 case 8: /* backspace */
794 default: /* draw the char */
795 video_putchar(console_col * VIDEO_FONT_WIDTH,
796 console_row * VIDEO_FONT_HEIGHT, c);
799 /* check for newline */
800 if (console_col >= CONSOLE_COLS) {
806 if (console_cursor_is_visible())
810 static void cfb_video_putc(struct stdio_dev *dev, const char c)
812 #ifdef CONFIG_CFB_CONSOLE_ANSI
816 for (i = 0; i < ansi_buf_size; ++i)
817 parse_putc(ansi_buf[i]);
823 if (ansi_buf_size > 0) {
843 ansi_buf[ansi_buf_size++] = c;
845 if (ansi_buf_size >= sizeof(ansi_buf))
848 for (i = 0; i < ansi_buf_size; ++i) {
854 if (ansi_buf[i] == 27)
861 if (ansi_buf[i] == '[')
868 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
869 num1 = ansi_buf[i]-'0';
871 } else if (ansi_buf[i] != '?') {
879 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
881 num1 += ansi_buf[i]-'0';
889 if (ansi_buf[i] != ';') {
897 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
898 num2 = ansi_buf[i]-'0';
905 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
907 num2 += ansi_buf[i]-'0';
915 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
916 || ansi_buf[i] == 'J'
917 || ansi_buf[i] == 'K'
918 || ansi_buf[i] == 'h'
919 || ansi_buf[i] == 'l'
920 || ansi_buf[i] == 'm') {
930 for (i = 0; i < ansi_buf_size; ++i)
931 parse_putc(ansi_buf[i]);
937 if (!ansi_cursor_hidden)
942 /* move cursor num1 rows up */
943 console_cursor_up(num1);
946 /* move cursor num1 rows down */
947 console_cursor_down(num1);
950 /* move cursor num1 columns forward */
951 console_cursor_right(num1);
954 /* move cursor num1 columns back */
955 console_cursor_left(num1);
958 /* move cursor num1 rows up at begin of row */
959 console_previousline(num1);
962 /* move cursor num1 rows down at begin of row */
963 console_newline(num1);
966 /* move cursor to column num1 */
967 console_cursor_set_position(-1, num1-1);
970 /* move cursor to row num1, column num2 */
971 console_cursor_set_position(num1-1, num2-1);
974 /* clear console and move cursor to 0, 0 */
976 console_cursor_set_position(0, 0);
981 console_clear_line(console_row,
985 console_clear_line(console_row,
988 console_clear_line(console_row,
992 ansi_cursor_hidden = 0;
995 ansi_cursor_hidden = 1;
998 if (num1 == 0) { /* reset swapped colors */
999 if (ansi_colors_need_revert) {
1000 console_swap_colors();
1001 ansi_colors_need_revert = 0;
1003 } else if (num1 == 7) { /* once swap colors */
1004 if (!ansi_colors_need_revert) {
1005 console_swap_colors();
1006 ansi_colors_need_revert = 1;
1011 if (!ansi_cursor_hidden)
1020 if (cfb_do_flush_cache)
1021 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1024 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1026 int flush = cfb_do_flush_cache;
1027 int count = strlen(s);
1029 /* temporarily disable cache flush */
1030 cfb_do_flush_cache = 0;
1033 cfb_video_putc(dev, *s++);
1036 cfb_do_flush_cache = flush;
1037 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1042 * Do not enforce drivers (or board code) to provide empty
1043 * video_set_lut() if they do not support 8 bpp format.
1044 * Implement weak default function instead.
1046 __weak void video_set_lut(unsigned int index, unsigned char r,
1047 unsigned char g, unsigned char b)
1051 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1053 #define FILL_8BIT_332RGB(r,g,b) { \
1054 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1058 #define FILL_15BIT_555RGB(r,g,b) { \
1059 *(unsigned short *)fb = \
1060 SWAP16((unsigned short)(((r>>3)<<10) | \
1066 #define FILL_16BIT_565RGB(r,g,b) { \
1067 *(unsigned short *)fb = \
1068 SWAP16((unsigned short)((((r)>>3)<<11)| \
1074 #define FILL_32BIT_X888RGB(r,g,b) { \
1076 SWAP32((unsigned int)(((r<<16) | \
1082 #ifdef VIDEO_FB_LITTLE_ENDIAN
1083 #define FILL_24BIT_888RGB(r,g,b) { \
1090 #define FILL_24BIT_888RGB(r,g,b) { \
1098 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1099 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1101 ushort *dst = (ushort *) fb;
1102 ushort color = (ushort) (((r >> 3) << 10) |
1113 * RLE8 bitmap support
1116 #ifdef CONFIG_VIDEO_BMP_RLE8
1117 /* Pre-calculated color table entry */
1120 unsigned short w; /* word */
1121 unsigned int dw; /* double word */
1122 } ce; /* color entry */
1126 * Helper to draw encoded/unencoded run.
1128 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1131 ulong addr = (ulong) *fb;
1137 * Setup offset of the color index in the bitmap.
1138 * Color index of encoded run is at offset 1.
1140 off = enc ? &enc_off : &i;
1142 switch (VIDEO_DATA_FORMAT) {
1143 case GDF__8BIT_INDEX:
1144 for (i = 0; i < cnt; i++)
1145 *(unsigned char *) addr++ = bm[*off];
1147 case GDF_15BIT_555RGB:
1148 case GDF_16BIT_565RGB:
1149 /* differences handled while pre-calculating palette */
1150 for (i = 0; i < cnt; i++) {
1151 *(unsigned short *) addr = p[bm[*off]].ce.w;
1155 case GDF_32BIT_X888RGB:
1156 for (i = 0; i < cnt; i++) {
1157 *(u32 *) addr = p[bm[*off]].ce.dw;
1162 *fb = (uchar *) addr; /* return modified address */
1165 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1166 int width, int height)
1170 unsigned int cnt, runlen;
1172 int x, y, bpp, i, ncolors;
1173 struct palette p[256];
1174 struct bmp_color_table_entry cte;
1175 int green_shift, red_off;
1176 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1180 y = __le32_to_cpu(img->header.height) - 1;
1181 ncolors = __le32_to_cpu(img->header.colors_used);
1182 bpp = VIDEO_PIXEL_SIZE;
1183 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1184 (y + yoff) * VIDEO_LINE_LEN +
1187 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1189 /* pre-calculate and setup palette */
1190 switch (VIDEO_DATA_FORMAT) {
1191 case GDF__8BIT_INDEX:
1192 for (i = 0; i < ncolors; i++) {
1193 cte = img->color_table[i];
1194 video_set_lut(i, cte.red, cte.green, cte.blue);
1197 case GDF_15BIT_555RGB:
1198 case GDF_16BIT_565RGB:
1199 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1206 for (i = 0; i < ncolors; i++) {
1207 cte = img->color_table[i];
1208 p[i].ce.w = SWAP16((unsigned short)
1209 (((cte.red >> 3) << red_off) |
1210 ((cte.green >> green_shift) << 5) |
1214 case GDF_32BIT_X888RGB:
1215 for (i = 0; i < ncolors; i++) {
1216 cte = img->color_table[i];
1217 p[i].ce.dw = SWAP32((cte.red << 16) |
1223 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1233 /* scan line end marker */
1237 fbp = (unsigned char *)
1238 ((unsigned int) video_fb_address +
1239 (y + yoff) * VIDEO_LINE_LEN +
1243 /* end of bitmap data marker */
1247 /* run offset marker */
1250 fbp = (unsigned char *)
1251 ((unsigned int) video_fb_address +
1252 (y + yoff) * VIDEO_LINE_LEN +
1270 if (x + runlen > width)
1272 draw_bitmap(&fbp, bm, p, cnt, 0);
1278 bm++; /* 0 padding if length is odd */
1289 if (y < height) { /* only draw into visible area */
1295 if (x + runlen > width)
1297 draw_bitmap(&fbp, bm, p, cnt, 1);
1305 if (cfb_do_flush_cache)
1306 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1310 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1316 * Display the BMP file located at address bmp_image.
1318 int video_display_bitmap(ulong bmp_image, int x, int y)
1320 ushort xcount, ycount;
1322 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1325 unsigned long width, height, bpp;
1327 unsigned long compression;
1328 struct bmp_color_table_entry cte;
1330 #ifdef CONFIG_VIDEO_BMP_GZIP
1331 unsigned char *dst = NULL;
1337 if (!((bmp->header.signature[0] == 'B') &&
1338 (bmp->header.signature[1] == 'M'))) {
1340 #ifdef CONFIG_VIDEO_BMP_GZIP
1342 * Could be a gzipped bmp image, try to decrompress...
1344 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1345 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1347 printf("Error: malloc in gunzip failed!\n");
1351 * NB: we need to force offset of +2
1352 * See doc/README.displaying-bmps
1354 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1355 (uchar *) bmp_image,
1357 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1362 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1363 printf("Image could be truncated "
1364 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1368 * Set addr to decompressed image
1370 bmp = (struct bmp_image *)(dst+2);
1372 if (!((bmp->header.signature[0] == 'B') &&
1373 (bmp->header.signature[1] == 'M'))) {
1374 printf("Error: no valid bmp.gz image at %lx\n",
1380 printf("Error: no valid bmp image at %lx\n", bmp_image);
1382 #endif /* CONFIG_VIDEO_BMP_GZIP */
1385 width = le32_to_cpu(bmp->header.width);
1386 height = le32_to_cpu(bmp->header.height);
1387 bpp = le16_to_cpu(bmp->header.bit_count);
1388 colors = le32_to_cpu(bmp->header.colors_used);
1389 compression = le32_to_cpu(bmp->header.compression);
1391 debug("Display-bmp: %ld x %ld with %d colors\n",
1392 width, height, colors);
1394 if (compression != BMP_BI_RGB
1395 #ifdef CONFIG_VIDEO_BMP_RLE8
1396 && compression != BMP_BI_RLE8
1399 printf("Error: compression type %ld not supported\n",
1401 #ifdef CONFIG_VIDEO_BMP_GZIP
1408 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1410 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1411 if (x == BMP_ALIGN_CENTER)
1412 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1414 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1416 if (y == BMP_ALIGN_CENTER)
1417 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1419 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1420 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1423 * Just ignore elements which are completely beyond screen
1426 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1429 if ((x + width) > VIDEO_VISIBLE_COLS)
1430 width = VIDEO_VISIBLE_COLS - x;
1431 if ((y + height) > VIDEO_VISIBLE_ROWS)
1432 height = VIDEO_VISIBLE_ROWS - y;
1434 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1435 fb = (uchar *) (video_fb_address +
1436 ((y + height - 1) * VIDEO_LINE_LEN) +
1437 x * VIDEO_PIXEL_SIZE);
1439 #ifdef CONFIG_VIDEO_BMP_RLE8
1440 if (compression == BMP_BI_RLE8) {
1441 return display_rle8_bitmap(bmp, x, y, width, height);
1445 /* We handle only 4, 8, or 24 bpp bitmaps */
1446 switch (le16_to_cpu(bmp->header.bit_count)) {
1448 padded_line -= width / 2;
1451 switch (VIDEO_DATA_FORMAT) {
1452 case GDF_32BIT_X888RGB:
1456 * Don't assume that 'width' is an
1459 for (xcount = 0; xcount < width; xcount++) {
1467 cte = bmp->color_table[idx];
1468 FILL_32BIT_X888RGB(cte.red, cte.green,
1471 bmap += padded_line;
1472 fb -= VIDEO_LINE_LEN + width *
1477 puts("4bpp bitmap unsupported with current "
1484 padded_line -= width;
1485 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1487 for (xcount = 0; xcount < colors; ++xcount) {
1488 cte = bmp->color_table[xcount];
1489 video_set_lut(xcount, cte.red, cte.green,
1494 switch (VIDEO_DATA_FORMAT) {
1495 case GDF__8BIT_INDEX:
1502 bmap += padded_line;
1503 fb -= VIDEO_LINE_LEN + width *
1507 case GDF__8BIT_332RGB:
1512 cte = bmp->color_table[*bmap++];
1513 FILL_8BIT_332RGB(cte.red, cte.green,
1516 bmap += padded_line;
1517 fb -= VIDEO_LINE_LEN + width *
1521 case GDF_15BIT_555RGB:
1523 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1529 cte = bmp->color_table[*bmap++];
1530 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1531 fill_555rgb_pswap(fb, xpos++, cte.red,
1536 FILL_15BIT_555RGB(cte.red, cte.green,
1540 bmap += padded_line;
1541 fb -= VIDEO_LINE_LEN + width *
1545 case GDF_16BIT_565RGB:
1550 cte = bmp->color_table[*bmap++];
1551 FILL_16BIT_565RGB(cte.red, cte.green,
1554 bmap += padded_line;
1555 fb -= VIDEO_LINE_LEN + width *
1559 case GDF_32BIT_X888RGB:
1564 cte = bmp->color_table[*bmap++];
1565 FILL_32BIT_X888RGB(cte.red, cte.green,
1568 bmap += padded_line;
1569 fb -= VIDEO_LINE_LEN + width *
1573 case GDF_24BIT_888RGB:
1578 cte = bmp->color_table[*bmap++];
1579 FILL_24BIT_888RGB(cte.red, cte.green,
1582 bmap += padded_line;
1583 fb -= VIDEO_LINE_LEN + width *
1590 padded_line -= 3 * width;
1592 switch (VIDEO_DATA_FORMAT) {
1593 case GDF__8BIT_332RGB:
1598 FILL_8BIT_332RGB(bmap[2], bmap[1],
1602 bmap += padded_line;
1603 fb -= VIDEO_LINE_LEN + width *
1607 case GDF_15BIT_555RGB:
1609 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1615 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1616 fill_555rgb_pswap(fb, xpos++, bmap[2],
1620 FILL_15BIT_555RGB(bmap[2], bmap[1],
1625 bmap += padded_line;
1626 fb -= VIDEO_LINE_LEN + width *
1630 case GDF_16BIT_565RGB:
1635 FILL_16BIT_565RGB(bmap[2], bmap[1],
1639 bmap += padded_line;
1640 fb -= VIDEO_LINE_LEN + width *
1644 case GDF_32BIT_X888RGB:
1649 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1653 bmap += padded_line;
1654 fb -= VIDEO_LINE_LEN + width *
1658 case GDF_24BIT_888RGB:
1663 FILL_24BIT_888RGB(bmap[2], bmap[1],
1667 bmap += padded_line;
1668 fb -= VIDEO_LINE_LEN + width *
1673 printf("Error: 24 bits/pixel bitmap incompatible "
1674 "with current video mode\n");
1679 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1680 le16_to_cpu(bmp->header.bit_count));
1684 #ifdef CONFIG_VIDEO_BMP_GZIP
1690 if (cfb_do_flush_cache)
1691 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1697 #ifdef CONFIG_VIDEO_LOGO
1698 static int video_logo_xpos;
1699 static int video_logo_ypos;
1701 static void plot_logo_or_black(void *screen, int x, int y, int black);
1703 static void logo_plot(void *screen, int x, int y)
1705 plot_logo_or_black(screen, x, y, 0);
1708 static void logo_black(void)
1710 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1714 static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1718 return cmd_usage(cmdtp);
1725 clrlogo, 1, 0, do_clrlogo,
1726 "fill the boot logo area with black",
1730 static void plot_logo_or_black(void *screen, int x, int y, int black)
1734 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1735 int ycount = video_logo_height;
1736 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1737 unsigned char *source;
1738 unsigned char *dest;
1740 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1741 if (x == BMP_ALIGN_CENTER)
1742 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1744 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1746 if (y == BMP_ALIGN_CENTER)
1747 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1749 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1750 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1752 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1754 #ifdef CONFIG_VIDEO_BMP_LOGO
1755 source = bmp_logo_bitmap;
1757 /* Allocate temporary space for computing colormap */
1758 logo_red = malloc(BMP_LOGO_COLORS);
1759 logo_green = malloc(BMP_LOGO_COLORS);
1760 logo_blue = malloc(BMP_LOGO_COLORS);
1761 /* Compute color map */
1762 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1763 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1764 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1765 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1768 source = linux_logo;
1769 logo_red = linux_logo_red;
1770 logo_green = linux_logo_green;
1771 logo_blue = linux_logo_blue;
1774 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1775 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1776 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1777 logo_red[i], logo_green[i],
1783 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1786 xcount = VIDEO_LOGO_WIDTH;
1793 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1794 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1795 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1798 switch (VIDEO_DATA_FORMAT) {
1799 case GDF__8BIT_INDEX:
1802 case GDF__8BIT_332RGB:
1803 *dest = ((r >> 5) << 5) |
1807 case GDF_15BIT_555RGB:
1808 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1809 fill_555rgb_pswap(dest, xpos++, r, g, b);
1811 *(unsigned short *) dest =
1812 SWAP16((unsigned short) (
1818 case GDF_16BIT_565RGB:
1819 *(unsigned short *) dest =
1820 SWAP16((unsigned short) (
1825 case GDF_32BIT_X888RGB:
1832 case GDF_24BIT_888RGB:
1833 #ifdef VIDEO_FB_LITTLE_ENDIAN
1845 dest += VIDEO_PIXEL_SIZE;
1849 #ifdef CONFIG_VIDEO_BMP_LOGO
1856 static void *video_logo(void)
1859 __maybe_unused int y_off = 0;
1860 __maybe_unused ulong addr;
1861 __maybe_unused char *s;
1862 __maybe_unused int len, ret, space;
1864 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1866 #ifdef CONFIG_SPLASH_SCREEN
1867 s = env_get("splashimage");
1869 ret = splash_screen_prepare();
1871 return video_fb_address;
1872 addr = simple_strtoul(s, NULL, 16);
1874 if (video_display_bitmap(addr,
1876 video_logo_ypos) == 0) {
1877 video_logo_height = 0;
1878 return ((void *) (video_fb_address));
1881 #endif /* CONFIG_SPLASH_SCREEN */
1883 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1885 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1887 * when using splashpos for video_logo, skip any info
1888 * output on video console if the logo is not at 0,0
1890 if (video_logo_xpos || video_logo_ypos) {
1892 * video_logo_height is used in text and cursor offset
1893 * calculations. Since the console is below the logo,
1894 * we need to adjust the logo height
1896 if (video_logo_ypos == BMP_ALIGN_CENTER)
1897 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1898 VIDEO_LOGO_HEIGHT) / 2);
1899 else if (video_logo_ypos > 0)
1900 video_logo_height += video_logo_ypos;
1902 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1905 if (board_cfb_skip())
1908 sprintf(info, " %s", version_string);
1910 #ifndef CONFIG_HIDE_LOGO_VERSION
1911 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1915 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1916 uchar *p = (uchar *) info;
1920 video_drawchars(xx, yy, p, space);
1923 p = (uchar *)p + space;
1926 xx += VIDEO_FONT_WIDTH;
1929 yy += VIDEO_FONT_HEIGHT;
1933 video_drawchars(xx, yy, p, len);
1938 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1940 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1943 ((video_logo_height -
1944 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1946 for (i = 1; i < n; i++) {
1947 video_get_info_str(i, info);
1953 video_drawchars(VIDEO_INFO_X,
1957 (uchar *) info, space);
1959 video_drawchars(VIDEO_INFO_X +
1964 (uchar *) info + space,
1967 video_drawstring(VIDEO_INFO_X,
1978 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1982 static int cfb_fb_is_in_dram(void)
1985 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
1986 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1990 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1991 start = bd->bi_dram[i].start;
1992 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1993 if ((ulong)video_fb_address >= start &&
1994 (ulong)video_fb_address < end)
1998 if ((ulong)video_fb_address >= bd->bi_memstart &&
1999 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2005 void video_clear(void)
2007 if (!video_fb_address)
2009 #ifdef VIDEO_HW_RECTFILL
2010 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2013 VIDEO_VISIBLE_COLS, /* frame width */
2014 VIDEO_VISIBLE_ROWS, /* frame height */
2015 bgx /* fill color */
2018 memsetl(video_fb_address,
2019 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2023 static int cfg_video_init(void)
2025 unsigned char color8;
2027 pGD = video_hw_init();
2031 video_fb_address = (void *) VIDEO_FB_ADRS;
2033 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2035 /* Init drawing pats */
2036 switch (VIDEO_DATA_FORMAT) {
2037 case GDF__8BIT_INDEX:
2038 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2039 CONFIG_SYS_CONSOLE_FG_COL,
2040 CONFIG_SYS_CONSOLE_FG_COL);
2041 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2042 CONFIG_SYS_CONSOLE_BG_COL,
2043 CONFIG_SYS_CONSOLE_BG_COL);
2047 case GDF__8BIT_332RGB:
2048 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2049 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2050 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2051 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2053 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2054 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2055 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2056 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2059 case GDF_15BIT_555RGB:
2060 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2061 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2062 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2063 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2064 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2065 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2066 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2067 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2068 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2069 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2070 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2071 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2073 case GDF_16BIT_565RGB:
2074 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2075 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2076 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2077 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2078 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2079 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2080 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2081 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2082 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2083 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2084 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2085 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2087 case GDF_32BIT_X888RGB:
2088 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2089 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2090 CONFIG_SYS_CONSOLE_FG_COL;
2091 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2092 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2093 CONFIG_SYS_CONSOLE_BG_COL;
2095 case GDF_24BIT_888RGB:
2096 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2097 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2098 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2099 CONFIG_SYS_CONSOLE_FG_COL;
2100 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2101 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2102 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2103 CONFIG_SYS_CONSOLE_BG_COL;
2108 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2111 #ifdef CONFIG_VIDEO_LOGO
2112 /* Plot the logo and get start point of console */
2113 debug("Video: Drawing the logo ...\n");
2114 video_console_address = video_logo();
2116 video_console_address = video_fb_address;
2119 /* Initialize the console */
2123 if (cfb_do_flush_cache)
2124 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2130 * Implement a weak default function for boards that optionally
2131 * need to skip the video initialization.
2133 __weak int board_video_skip(void)
2135 /* As default, don't skip test */
2139 int drv_video_init(void)
2141 struct stdio_dev console_dev;
2143 bool __maybe_unused keyboard_ok = false;
2145 /* Check if video initialization should be skipped */
2146 if (board_video_skip())
2149 /* Init video chip - returns with framebuffer cleared */
2150 if (cfg_video_init() == -1)
2153 if (board_cfb_skip())
2156 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2157 have_keyboard = false;
2158 #elif defined(CONFIG_OF_CONTROL)
2159 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2160 "u-boot,no-keyboard");
2162 have_keyboard = true;
2164 if (have_keyboard) {
2165 debug("KBD: Keyboard init ...\n");
2166 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2167 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2171 /* Init vga device */
2172 memset(&console_dev, 0, sizeof(console_dev));
2173 strcpy(console_dev.name, "vga");
2174 console_dev.flags = DEV_FLAGS_OUTPUT;
2175 console_dev.putc = cfb_video_putc; /* 'putc' function */
2176 console_dev.puts = cfb_video_puts; /* 'puts' function */
2178 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2179 if (have_keyboard && keyboard_ok) {
2180 /* Also init console device */
2181 console_dev.flags |= DEV_FLAGS_INPUT;
2182 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2183 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2187 if (stdio_register(&console_dev) != 0)
2190 /* Return success */
2194 void video_position_cursor(unsigned col, unsigned row)
2196 console_col = min(col, CONSOLE_COLS - 1);
2197 console_row = min(row, CONSOLE_ROWS - 1);
2200 int video_get_pixel_width(void)
2202 return VIDEO_VISIBLE_COLS;
2205 int video_get_pixel_height(void)
2207 return VIDEO_VISIBLE_ROWS;
2210 int video_get_screen_rows(void)
2212 return CONSOLE_ROWS;
2215 int video_get_screen_columns(void)
2217 return CONSOLE_COLS;