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
77 #include <asm/global_data.h>
78 #include <linux/compiler.h>
80 #if defined(CONFIG_VIDEO_MXS)
81 #define VIDEO_FB_16BPP_WORD_SWAP
85 * Defines for the i.MX31 driver (mx3fb.c)
87 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
88 #define VIDEO_FB_16BPP_WORD_SWAP
92 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
101 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
102 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
103 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
104 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
105 #define VIDEO_FB_ADRS (pGD->frameAdrs)
112 #include <linux/types.h>
113 #include <stdio_dev.h>
114 #include <video_font.h>
116 #if defined(CONFIG_CMD_DATE)
120 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
121 #include <watchdog.h>
122 #include <bmp_layout.h>
126 #if !defined(CONFIG_VIDEO_SW_CURSOR)
127 /* no Cursor defined */
133 #if defined(CONFIG_VIDEO_SW_CURSOR)
134 void console_cursor(int state);
136 #define CURSOR_ON console_cursor(1)
137 #define CURSOR_OFF console_cursor(0)
138 #define CURSOR_SET video_set_cursor()
139 #endif /* CONFIG_VIDEO_SW_CURSOR */
141 #ifdef CONFIG_VIDEO_LOGO
142 #ifdef CONFIG_VIDEO_BMP_LOGO
143 #include <bmp_logo.h>
144 #include <bmp_logo_data.h>
145 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
146 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
147 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
148 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
150 #else /* CONFIG_VIDEO_BMP_LOGO */
151 #define LINUX_LOGO_WIDTH 80
152 #define LINUX_LOGO_HEIGHT 80
153 #define LINUX_LOGO_COLORS 214
154 #define LINUX_LOGO_LUT_OFFSET 0x20
156 #include <linux_logo.h>
157 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
158 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
159 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
160 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
161 #endif /* CONFIG_VIDEO_BMP_LOGO */
162 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
163 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
164 #else /* CONFIG_VIDEO_LOGO */
165 #define VIDEO_LOGO_WIDTH 0
166 #define VIDEO_LOGO_HEIGHT 0
167 #endif /* CONFIG_VIDEO_LOGO */
169 #define VIDEO_COLS VIDEO_VISIBLE_COLS
170 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
171 #ifndef VIDEO_LINE_LEN
172 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
174 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
175 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
177 #ifdef CONFIG_VIDEO_LOGO
178 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
180 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
183 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
184 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
185 #define CONSOLE_ROW_FIRST (video_console_address)
186 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
187 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
188 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
190 /* By default we scroll by a single line */
191 #ifndef CONFIG_CONSOLE_SCROLL_LINES
192 #define CONFIG_CONSOLE_SCROLL_LINES 1
196 #ifdef VIDEO_FB_LITTLE_ENDIAN
197 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
200 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
201 (((x) & 0x0000ff00) << 8) | \
202 (((x) & 0x00ff0000) >> 8) | \
203 (((x) & 0xff000000) >> 24) \
205 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
206 (((x) & 0x0000ff00) >> 8) | \
207 (((x) & 0x00ff0000) << 8) | \
208 (((x) & 0xff000000) >> 8) \
211 #define SWAP16(x) (x)
212 #define SWAP32(x) (x)
213 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
214 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
216 #define SHORTSWAP32(x) (x)
220 DECLARE_GLOBAL_DATA_PTR;
223 static GraphicDevice *pGD; /* Pointer to Graphic array */
225 static void *video_fb_address; /* frame buffer address */
226 static void *video_console_address; /* console buffer start address */
228 static int video_logo_height = VIDEO_LOGO_HEIGHT;
230 static int __maybe_unused cursor_state;
231 static int __maybe_unused old_col;
232 static int __maybe_unused old_row;
234 static int console_col; /* cursor col */
235 static int console_row; /* cursor row */
237 static u32 eorx, fgx, bgx; /* color pats */
239 static int cfb_do_flush_cache;
241 #ifdef CONFIG_CFB_CONSOLE_ANSI
242 static char ansi_buf[10];
243 static int ansi_buf_size;
244 static int ansi_colors_need_revert;
245 static int ansi_cursor_hidden;
248 static const int video_font_draw_table8[] = {
249 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
250 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
251 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
252 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
255 static const int video_font_draw_table15[] = {
256 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
259 static const int video_font_draw_table16[] = {
260 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
263 static const int video_font_draw_table24[16][3] = {
264 {0x00000000, 0x00000000, 0x00000000},
265 {0x00000000, 0x00000000, 0x00ffffff},
266 {0x00000000, 0x0000ffff, 0xff000000},
267 {0x00000000, 0x0000ffff, 0xffffffff},
268 {0x000000ff, 0xffff0000, 0x00000000},
269 {0x000000ff, 0xffff0000, 0x00ffffff},
270 {0x000000ff, 0xffffffff, 0xff000000},
271 {0x000000ff, 0xffffffff, 0xffffffff},
272 {0xffffff00, 0x00000000, 0x00000000},
273 {0xffffff00, 0x00000000, 0x00ffffff},
274 {0xffffff00, 0x0000ffff, 0xff000000},
275 {0xffffff00, 0x0000ffff, 0xffffffff},
276 {0xffffffff, 0xffff0000, 0x00000000},
277 {0xffffffff, 0xffff0000, 0x00ffffff},
278 {0xffffffff, 0xffffffff, 0xff000000},
279 {0xffffffff, 0xffffffff, 0xffffffff}
282 static const int video_font_draw_table32[16][4] = {
283 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
284 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
285 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
286 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
287 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
288 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
289 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
290 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
291 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
292 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
293 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
294 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
295 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
296 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
297 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
298 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
302 * Implement a weak default function for boards that optionally
303 * need to skip the cfb initialization.
305 __weak int board_cfb_skip(void)
307 /* As default, don't skip cfb init */
311 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
313 u8 *cdat, *dest, *dest0;
316 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
317 dest0 = video_fb_address + offset;
319 switch (VIDEO_DATA_FORMAT) {
320 case GDF__8BIT_INDEX:
321 case GDF__8BIT_332RGB:
324 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
325 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
326 rows--; dest += VIDEO_LINE_LEN) {
330 (video_font_draw_table8[bits >> 4] &
333 if (VIDEO_FONT_WIDTH == 4)
337 (video_font_draw_table8[bits & 15] &
340 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
345 case GDF_15BIT_555RGB:
348 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
349 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
350 rows--; dest += VIDEO_LINE_LEN) {
354 SHORTSWAP32((video_font_draw_table15
355 [bits >> 6] & eorx) ^
358 SHORTSWAP32((video_font_draw_table15
359 [bits >> 4 & 3] & eorx) ^
362 if (VIDEO_FONT_WIDTH == 4)
366 SHORTSWAP32((video_font_draw_table15
367 [bits >> 2 & 3] & eorx) ^
370 SHORTSWAP32((video_font_draw_table15
374 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
379 case GDF_16BIT_565RGB:
382 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
383 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
384 rows--; dest += VIDEO_LINE_LEN) {
388 SHORTSWAP32((video_font_draw_table16
389 [bits >> 6] & eorx) ^
392 SHORTSWAP32((video_font_draw_table16
393 [bits >> 4 & 3] & eorx) ^
396 if (VIDEO_FONT_WIDTH == 4)
400 SHORTSWAP32((video_font_draw_table16
401 [bits >> 2 & 3] & eorx) ^
404 SHORTSWAP32((video_font_draw_table16
408 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
413 case GDF_32BIT_X888RGB:
416 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
417 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
418 rows--; dest += VIDEO_LINE_LEN) {
422 SWAP32((video_font_draw_table32
423 [bits >> 4][0] & eorx) ^ bgx);
425 SWAP32((video_font_draw_table32
426 [bits >> 4][1] & eorx) ^ bgx);
428 SWAP32((video_font_draw_table32
429 [bits >> 4][2] & eorx) ^ bgx);
431 SWAP32((video_font_draw_table32
432 [bits >> 4][3] & eorx) ^ bgx);
435 if (VIDEO_FONT_WIDTH == 4)
439 SWAP32((video_font_draw_table32
440 [bits & 15][0] & eorx) ^ bgx);
442 SWAP32((video_font_draw_table32
443 [bits & 15][1] & eorx) ^ bgx);
445 SWAP32((video_font_draw_table32
446 [bits & 15][2] & eorx) ^ bgx);
448 SWAP32((video_font_draw_table32
449 [bits & 15][3] & eorx) ^ bgx);
451 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
456 case GDF_24BIT_888RGB:
459 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
460 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
461 rows--; dest += VIDEO_LINE_LEN) {
465 (video_font_draw_table24[bits >> 4][0]
468 (video_font_draw_table24[bits >> 4][1]
471 (video_font_draw_table24[bits >> 4][2]
474 if (VIDEO_FONT_WIDTH == 4)
478 (video_font_draw_table24[bits & 15][0]
481 (video_font_draw_table24[bits & 15][1]
484 (video_font_draw_table24[bits & 15][2]
487 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
494 static inline void video_drawstring(int xx, int yy, unsigned char *s)
496 video_drawchars(xx, yy, s, strlen((char *) s));
499 static void video_putchar(int xx, int yy, unsigned char c)
501 video_drawchars(xx, yy + video_logo_height, &c, 1);
504 #if defined(CONFIG_VIDEO_SW_CURSOR)
505 static void video_set_cursor(void)
512 static void video_invertchar(int xx, int yy)
514 int firstx = xx * VIDEO_PIXEL_SIZE;
515 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
516 int firsty = yy * VIDEO_LINE_LEN;
517 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
519 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
520 for (x = firstx; x < lastx; x++) {
521 u8 *dest = (u8 *)(video_fb_address) + x + y;
527 void console_cursor(int state)
529 if (cursor_state != state) {
531 /* turn off the cursor */
532 video_invertchar(old_col * VIDEO_FONT_WIDTH,
533 old_row * VIDEO_FONT_HEIGHT +
536 /* turn off the cursor and record where it is */
537 video_invertchar(console_col * VIDEO_FONT_WIDTH,
538 console_row * VIDEO_FONT_HEIGHT +
540 old_col = console_col;
541 old_row = console_row;
543 cursor_state = state;
545 if (cfb_do_flush_cache)
546 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
550 #ifndef VIDEO_HW_RECTFILL
551 static void memsetl(int *p, int c, int v)
558 #ifndef VIDEO_HW_BITBLT
559 static void memcpyl(int *d, int *s, int c)
566 static void console_clear_line(int line, int begin, int end)
568 #ifdef VIDEO_HW_RECTFILL
569 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
570 VIDEO_FONT_WIDTH * begin, /* dest pos x */
572 VIDEO_FONT_HEIGHT * line, /* dest pos y */
573 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
574 VIDEO_FONT_HEIGHT, /* frame height */
578 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
579 memsetl(CONSOLE_ROW_FIRST +
580 CONSOLE_ROW_SIZE * line, /* offset of row */
581 CONSOLE_ROW_SIZE >> 2, /* length of row */
588 offset = CONSOLE_ROW_FIRST +
589 CONSOLE_ROW_SIZE * line + /* offset of row */
591 VIDEO_PIXEL_SIZE * begin; /* offset of col */
592 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
593 size >>= 2; /* length to end for memsetl() */
594 /* fill at col offset of i'th line using bgx as fill color */
595 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
596 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
601 static void console_scrollup(void)
603 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
606 /* copy up rows ignoring the first one */
608 #ifdef VIDEO_HW_BITBLT
609 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
610 0, /* source pos x */
612 VIDEO_FONT_HEIGHT * rows, /* source pos y */
614 video_logo_height, /* dest pos y */
615 VIDEO_VISIBLE_COLS, /* frame width */
618 - VIDEO_FONT_HEIGHT * rows /* frame height */
621 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
622 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
624 /* clear the last one */
625 for (i = 1; i <= rows; i++)
626 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
628 /* Decrement row number */
632 static void console_back(void)
636 if (console_col < 0) {
637 console_col = CONSOLE_COLS - 1;
644 #ifdef CONFIG_CFB_CONSOLE_ANSI
646 static void console_clear(void)
648 #ifdef VIDEO_HW_RECTFILL
649 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
651 video_logo_height, /* dest pos y */
652 VIDEO_VISIBLE_COLS, /* frame width */
653 VIDEO_VISIBLE_ROWS, /* frame height */
657 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
661 static void console_cursor_fix(void)
665 if (console_row >= CONSOLE_ROWS)
666 console_row = CONSOLE_ROWS - 1;
669 if (console_col >= CONSOLE_COLS)
670 console_col = CONSOLE_COLS - 1;
673 static void console_cursor_up(int n)
676 console_cursor_fix();
679 static void console_cursor_down(int n)
682 console_cursor_fix();
685 static void console_cursor_left(int n)
688 console_cursor_fix();
691 static void console_cursor_right(int n)
694 console_cursor_fix();
697 static void console_cursor_set_position(int row, int col)
699 if (console_row != -1)
701 if (console_col != -1)
703 console_cursor_fix();
706 static void console_previousline(int n)
708 /* FIXME: also scroll terminal ? */
710 console_cursor_fix();
713 static void console_swap_colors(void)
721 static inline int console_cursor_is_visible(void)
723 return !ansi_cursor_hidden;
726 static inline int console_cursor_is_visible(void)
732 static void console_newline(int n)
737 /* Check if we need to scroll the terminal */
738 if (console_row >= CONSOLE_ROWS) {
739 /* Scroll everything up */
744 static void console_cr(void)
749 static void parse_putc(const char c)
753 if (console_cursor_is_visible())
757 case 13: /* back to first column */
761 case '\n': /* next line */
762 if (console_col || nl)
768 console_col |= 0x0008;
769 console_col &= ~0x0007;
771 if (console_col >= CONSOLE_COLS)
775 case 8: /* backspace */
782 default: /* draw the char */
783 video_putchar(console_col * VIDEO_FONT_WIDTH,
784 console_row * VIDEO_FONT_HEIGHT, c);
787 /* check for newline */
788 if (console_col >= CONSOLE_COLS) {
794 if (console_cursor_is_visible())
798 static void cfb_video_putc(struct stdio_dev *dev, const char c)
800 #ifdef CONFIG_CFB_CONSOLE_ANSI
804 for (i = 0; i < ansi_buf_size; ++i)
805 parse_putc(ansi_buf[i]);
811 if (ansi_buf_size > 0) {
831 ansi_buf[ansi_buf_size++] = c;
833 if (ansi_buf_size >= sizeof(ansi_buf))
836 for (i = 0; i < ansi_buf_size; ++i) {
842 if (ansi_buf[i] == 27)
849 if (ansi_buf[i] == '[')
856 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
857 num1 = ansi_buf[i]-'0';
859 } else if (ansi_buf[i] != '?') {
867 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
869 num1 += ansi_buf[i]-'0';
877 if (ansi_buf[i] != ';') {
885 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
886 num2 = ansi_buf[i]-'0';
893 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
895 num2 += ansi_buf[i]-'0';
903 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
904 || ansi_buf[i] == 'J'
905 || ansi_buf[i] == 'K'
906 || ansi_buf[i] == 'h'
907 || ansi_buf[i] == 'l'
908 || ansi_buf[i] == 'm') {
918 for (i = 0; i < ansi_buf_size; ++i)
919 parse_putc(ansi_buf[i]);
925 if (!ansi_cursor_hidden)
930 /* move cursor num1 rows up */
931 console_cursor_up(num1);
934 /* move cursor num1 rows down */
935 console_cursor_down(num1);
938 /* move cursor num1 columns forward */
939 console_cursor_right(num1);
942 /* move cursor num1 columns back */
943 console_cursor_left(num1);
946 /* move cursor num1 rows up at begin of row */
947 console_previousline(num1);
950 /* move cursor num1 rows down at begin of row */
951 console_newline(num1);
954 /* move cursor to column num1 */
955 console_cursor_set_position(-1, num1-1);
958 /* move cursor to row num1, column num2 */
959 console_cursor_set_position(num1-1, num2-1);
962 /* clear console and move cursor to 0, 0 */
964 console_cursor_set_position(0, 0);
969 console_clear_line(console_row,
973 console_clear_line(console_row,
976 console_clear_line(console_row,
980 ansi_cursor_hidden = 0;
983 ansi_cursor_hidden = 1;
986 if (num1 == 0) { /* reset swapped colors */
987 if (ansi_colors_need_revert) {
988 console_swap_colors();
989 ansi_colors_need_revert = 0;
991 } else if (num1 == 7) { /* once swap colors */
992 if (!ansi_colors_need_revert) {
993 console_swap_colors();
994 ansi_colors_need_revert = 1;
999 if (!ansi_cursor_hidden)
1008 if (cfb_do_flush_cache)
1009 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1012 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1014 int flush = cfb_do_flush_cache;
1015 int count = strlen(s);
1017 /* temporarily disable cache flush */
1018 cfb_do_flush_cache = 0;
1021 cfb_video_putc(dev, *s++);
1024 cfb_do_flush_cache = flush;
1025 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1030 * Do not enforce drivers (or board code) to provide empty
1031 * video_set_lut() if they do not support 8 bpp format.
1032 * Implement weak default function instead.
1034 __weak void video_set_lut(unsigned int index, unsigned char r,
1035 unsigned char g, unsigned char b)
1039 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1041 #define FILL_8BIT_332RGB(r,g,b) { \
1042 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1046 #define FILL_15BIT_555RGB(r,g,b) { \
1047 *(unsigned short *)fb = \
1048 SWAP16((unsigned short)(((r>>3)<<10) | \
1054 #define FILL_16BIT_565RGB(r,g,b) { \
1055 *(unsigned short *)fb = \
1056 SWAP16((unsigned short)((((r)>>3)<<11)| \
1062 #define FILL_32BIT_X888RGB(r,g,b) { \
1064 SWAP32((unsigned int)(((r<<16) | \
1070 #ifdef VIDEO_FB_LITTLE_ENDIAN
1071 #define FILL_24BIT_888RGB(r,g,b) { \
1078 #define FILL_24BIT_888RGB(r,g,b) { \
1086 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1087 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1089 ushort *dst = (ushort *) fb;
1090 ushort color = (ushort) (((r >> 3) << 10) |
1101 * RLE8 bitmap support
1104 #ifdef CONFIG_VIDEO_BMP_RLE8
1105 /* Pre-calculated color table entry */
1108 unsigned short w; /* word */
1109 unsigned int dw; /* double word */
1110 } ce; /* color entry */
1114 * Helper to draw encoded/unencoded run.
1116 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1119 ulong addr = (ulong) *fb;
1125 * Setup offset of the color index in the bitmap.
1126 * Color index of encoded run is at offset 1.
1128 off = enc ? &enc_off : &i;
1130 switch (VIDEO_DATA_FORMAT) {
1131 case GDF__8BIT_INDEX:
1132 for (i = 0; i < cnt; i++)
1133 *(unsigned char *) addr++ = bm[*off];
1135 case GDF_15BIT_555RGB:
1136 case GDF_16BIT_565RGB:
1137 /* differences handled while pre-calculating palette */
1138 for (i = 0; i < cnt; i++) {
1139 *(unsigned short *) addr = p[bm[*off]].ce.w;
1143 case GDF_32BIT_X888RGB:
1144 for (i = 0; i < cnt; i++) {
1145 *(u32 *) addr = p[bm[*off]].ce.dw;
1150 *fb = (uchar *) addr; /* return modified address */
1153 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1154 int width, int height)
1158 unsigned int cnt, runlen;
1160 int x, y, bpp, i, ncolors;
1161 struct palette p[256];
1162 struct bmp_color_table_entry cte;
1163 int green_shift, red_off;
1164 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1168 y = __le32_to_cpu(img->header.height) - 1;
1169 ncolors = __le32_to_cpu(img->header.colors_used);
1170 bpp = VIDEO_PIXEL_SIZE;
1171 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1172 (y + yoff) * VIDEO_LINE_LEN +
1175 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1177 /* pre-calculate and setup palette */
1178 switch (VIDEO_DATA_FORMAT) {
1179 case GDF__8BIT_INDEX:
1180 for (i = 0; i < ncolors; i++) {
1181 cte = img->color_table[i];
1182 video_set_lut(i, cte.red, cte.green, cte.blue);
1185 case GDF_15BIT_555RGB:
1186 case GDF_16BIT_565RGB:
1187 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1194 for (i = 0; i < ncolors; i++) {
1195 cte = img->color_table[i];
1196 p[i].ce.w = SWAP16((unsigned short)
1197 (((cte.red >> 3) << red_off) |
1198 ((cte.green >> green_shift) << 5) |
1202 case GDF_32BIT_X888RGB:
1203 for (i = 0; i < ncolors; i++) {
1204 cte = img->color_table[i];
1205 p[i].ce.dw = SWAP32((cte.red << 16) |
1211 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1221 /* scan line end marker */
1225 fbp = (unsigned char *)
1226 ((unsigned int) video_fb_address +
1227 (y + yoff) * VIDEO_LINE_LEN +
1231 /* end of bitmap data marker */
1235 /* run offset marker */
1238 fbp = (unsigned char *)
1239 ((unsigned int) video_fb_address +
1240 (y + yoff) * VIDEO_LINE_LEN +
1258 if (x + runlen > width)
1260 draw_bitmap(&fbp, bm, p, cnt, 0);
1266 bm++; /* 0 padding if length is odd */
1277 if (y < height) { /* only draw into visible area */
1283 if (x + runlen > width)
1285 draw_bitmap(&fbp, bm, p, cnt, 1);
1293 if (cfb_do_flush_cache)
1294 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1298 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1304 * Display the BMP file located at address bmp_image.
1306 int video_display_bitmap(ulong bmp_image, int x, int y)
1308 ushort xcount, ycount;
1310 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1313 unsigned long width, height, bpp;
1315 unsigned long compression;
1316 struct bmp_color_table_entry cte;
1318 #ifdef CONFIG_VIDEO_BMP_GZIP
1319 unsigned char *dst = NULL;
1325 if (!((bmp->header.signature[0] == 'B') &&
1326 (bmp->header.signature[1] == 'M'))) {
1328 #ifdef CONFIG_VIDEO_BMP_GZIP
1330 * Could be a gzipped bmp image, try to decrompress...
1332 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1333 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1335 printf("Error: malloc in gunzip failed!\n");
1339 * NB: we need to force offset of +2
1340 * See doc/README.displaying-bmps
1342 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1343 (uchar *) bmp_image,
1345 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1350 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1351 printf("Image could be truncated "
1352 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1356 * Set addr to decompressed image
1358 bmp = (struct bmp_image *)(dst+2);
1360 if (!((bmp->header.signature[0] == 'B') &&
1361 (bmp->header.signature[1] == 'M'))) {
1362 printf("Error: no valid bmp.gz image at %lx\n",
1368 printf("Error: no valid bmp image at %lx\n", bmp_image);
1370 #endif /* CONFIG_VIDEO_BMP_GZIP */
1373 width = le32_to_cpu(bmp->header.width);
1374 height = le32_to_cpu(bmp->header.height);
1375 bpp = le16_to_cpu(bmp->header.bit_count);
1376 colors = le32_to_cpu(bmp->header.colors_used);
1377 compression = le32_to_cpu(bmp->header.compression);
1379 debug("Display-bmp: %ld x %ld with %d colors\n",
1380 width, height, colors);
1382 if (compression != BMP_BI_RGB
1383 #ifdef CONFIG_VIDEO_BMP_RLE8
1384 && compression != BMP_BI_RLE8
1387 printf("Error: compression type %ld not supported\n",
1389 #ifdef CONFIG_VIDEO_BMP_GZIP
1396 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1398 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1399 if (x == BMP_ALIGN_CENTER)
1400 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1402 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1404 if (y == BMP_ALIGN_CENTER)
1405 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1407 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1408 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1411 * Just ignore elements which are completely beyond screen
1414 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1417 if ((x + width) > VIDEO_VISIBLE_COLS)
1418 width = VIDEO_VISIBLE_COLS - x;
1419 if ((y + height) > VIDEO_VISIBLE_ROWS)
1420 height = VIDEO_VISIBLE_ROWS - y;
1422 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1423 fb = (uchar *) (video_fb_address +
1424 ((y + height - 1) * VIDEO_LINE_LEN) +
1425 x * VIDEO_PIXEL_SIZE);
1427 #ifdef CONFIG_VIDEO_BMP_RLE8
1428 if (compression == BMP_BI_RLE8) {
1429 return display_rle8_bitmap(bmp, x, y, width, height);
1433 /* We handle only 4, 8, or 24 bpp bitmaps */
1434 switch (le16_to_cpu(bmp->header.bit_count)) {
1436 padded_line -= width / 2;
1439 switch (VIDEO_DATA_FORMAT) {
1440 case GDF_32BIT_X888RGB:
1444 * Don't assume that 'width' is an
1447 for (xcount = 0; xcount < width; xcount++) {
1455 cte = bmp->color_table[idx];
1456 FILL_32BIT_X888RGB(cte.red, cte.green,
1459 bmap += padded_line;
1460 fb -= VIDEO_LINE_LEN + width *
1465 puts("4bpp bitmap unsupported with current "
1472 padded_line -= width;
1473 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1475 for (xcount = 0; xcount < colors; ++xcount) {
1476 cte = bmp->color_table[xcount];
1477 video_set_lut(xcount, cte.red, cte.green,
1482 switch (VIDEO_DATA_FORMAT) {
1483 case GDF__8BIT_INDEX:
1490 bmap += padded_line;
1491 fb -= VIDEO_LINE_LEN + width *
1495 case GDF__8BIT_332RGB:
1500 cte = bmp->color_table[*bmap++];
1501 FILL_8BIT_332RGB(cte.red, cte.green,
1504 bmap += padded_line;
1505 fb -= VIDEO_LINE_LEN + width *
1509 case GDF_15BIT_555RGB:
1511 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1517 cte = bmp->color_table[*bmap++];
1518 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1519 fill_555rgb_pswap(fb, xpos++, cte.red,
1524 FILL_15BIT_555RGB(cte.red, cte.green,
1528 bmap += padded_line;
1529 fb -= VIDEO_LINE_LEN + width *
1533 case GDF_16BIT_565RGB:
1538 cte = bmp->color_table[*bmap++];
1539 FILL_16BIT_565RGB(cte.red, cte.green,
1542 bmap += padded_line;
1543 fb -= VIDEO_LINE_LEN + width *
1547 case GDF_32BIT_X888RGB:
1552 cte = bmp->color_table[*bmap++];
1553 FILL_32BIT_X888RGB(cte.red, cte.green,
1556 bmap += padded_line;
1557 fb -= VIDEO_LINE_LEN + width *
1561 case GDF_24BIT_888RGB:
1566 cte = bmp->color_table[*bmap++];
1567 FILL_24BIT_888RGB(cte.red, cte.green,
1570 bmap += padded_line;
1571 fb -= VIDEO_LINE_LEN + width *
1578 padded_line -= 3 * width;
1580 switch (VIDEO_DATA_FORMAT) {
1581 case GDF__8BIT_332RGB:
1586 FILL_8BIT_332RGB(bmap[2], bmap[1],
1590 bmap += padded_line;
1591 fb -= VIDEO_LINE_LEN + width *
1595 case GDF_15BIT_555RGB:
1597 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1603 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1604 fill_555rgb_pswap(fb, xpos++, bmap[2],
1608 FILL_15BIT_555RGB(bmap[2], bmap[1],
1613 bmap += padded_line;
1614 fb -= VIDEO_LINE_LEN + width *
1618 case GDF_16BIT_565RGB:
1623 FILL_16BIT_565RGB(bmap[2], bmap[1],
1627 bmap += padded_line;
1628 fb -= VIDEO_LINE_LEN + width *
1632 case GDF_32BIT_X888RGB:
1637 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1641 bmap += padded_line;
1642 fb -= VIDEO_LINE_LEN + width *
1646 case GDF_24BIT_888RGB:
1651 FILL_24BIT_888RGB(bmap[2], bmap[1],
1655 bmap += padded_line;
1656 fb -= VIDEO_LINE_LEN + width *
1661 printf("Error: 24 bits/pixel bitmap incompatible "
1662 "with current video mode\n");
1667 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1668 le16_to_cpu(bmp->header.bit_count));
1672 #ifdef CONFIG_VIDEO_BMP_GZIP
1678 if (cfb_do_flush_cache)
1679 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1685 #ifdef CONFIG_VIDEO_LOGO
1686 static int video_logo_xpos;
1687 static int video_logo_ypos;
1689 static void plot_logo_or_black(void *screen, int x, int y, int black);
1691 static void logo_plot(void *screen, int x, int y)
1693 plot_logo_or_black(screen, x, y, 0);
1696 static void logo_black(void)
1698 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1702 static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1706 return cmd_usage(cmdtp);
1713 clrlogo, 1, 0, do_clrlogo,
1714 "fill the boot logo area with black",
1718 static void plot_logo_or_black(void *screen, int x, int y, int black)
1722 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1723 int ycount = video_logo_height;
1724 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1725 unsigned char *source;
1726 unsigned char *dest;
1728 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1729 if (x == BMP_ALIGN_CENTER)
1730 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1732 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1734 if (y == BMP_ALIGN_CENTER)
1735 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1737 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1738 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1740 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1742 #ifdef CONFIG_VIDEO_BMP_LOGO
1743 source = bmp_logo_bitmap;
1745 /* Allocate temporary space for computing colormap */
1746 logo_red = malloc(BMP_LOGO_COLORS);
1747 logo_green = malloc(BMP_LOGO_COLORS);
1748 logo_blue = malloc(BMP_LOGO_COLORS);
1749 /* Compute color map */
1750 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1751 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1752 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1753 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1756 source = linux_logo;
1757 logo_red = linux_logo_red;
1758 logo_green = linux_logo_green;
1759 logo_blue = linux_logo_blue;
1762 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1763 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1764 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1765 logo_red[i], logo_green[i],
1771 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1774 xcount = VIDEO_LOGO_WIDTH;
1781 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1782 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1783 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1786 switch (VIDEO_DATA_FORMAT) {
1787 case GDF__8BIT_INDEX:
1790 case GDF__8BIT_332RGB:
1791 *dest = ((r >> 5) << 5) |
1795 case GDF_15BIT_555RGB:
1796 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1797 fill_555rgb_pswap(dest, xpos++, r, g, b);
1799 *(unsigned short *) dest =
1800 SWAP16((unsigned short) (
1806 case GDF_16BIT_565RGB:
1807 *(unsigned short *) dest =
1808 SWAP16((unsigned short) (
1813 case GDF_32BIT_X888RGB:
1820 case GDF_24BIT_888RGB:
1821 #ifdef VIDEO_FB_LITTLE_ENDIAN
1833 dest += VIDEO_PIXEL_SIZE;
1837 #ifdef CONFIG_VIDEO_BMP_LOGO
1844 static void *video_logo(void)
1847 __maybe_unused int y_off = 0;
1848 __maybe_unused ulong addr;
1849 __maybe_unused char *s;
1850 __maybe_unused int len, ret, space;
1852 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1854 #ifdef CONFIG_SPLASH_SCREEN
1855 s = env_get("splashimage");
1857 ret = splash_screen_prepare();
1859 return video_fb_address;
1860 addr = hextoul(s, NULL);
1862 if (video_display_bitmap(addr,
1864 video_logo_ypos) == 0) {
1865 video_logo_height = 0;
1866 return ((void *) (video_fb_address));
1869 #endif /* CONFIG_SPLASH_SCREEN */
1871 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1873 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1875 * when using splashpos for video_logo, skip any info
1876 * output on video console if the logo is not at 0,0
1878 if (video_logo_xpos || video_logo_ypos) {
1880 * video_logo_height is used in text and cursor offset
1881 * calculations. Since the console is below the logo,
1882 * we need to adjust the logo height
1884 if (video_logo_ypos == BMP_ALIGN_CENTER)
1885 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1886 VIDEO_LOGO_HEIGHT) / 2);
1887 else if (video_logo_ypos > 0)
1888 video_logo_height += video_logo_ypos;
1890 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1893 if (board_cfb_skip())
1896 sprintf(info, " %s", version_string);
1898 #ifndef CONFIG_HIDE_LOGO_VERSION
1899 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1903 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1904 uchar *p = (uchar *) info;
1908 video_drawchars(xx, yy, p, space);
1911 p = (uchar *)p + space;
1914 xx += VIDEO_FONT_WIDTH;
1917 yy += VIDEO_FONT_HEIGHT;
1921 video_drawchars(xx, yy, p, len);
1926 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1928 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1931 ((video_logo_height -
1932 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1934 for (i = 1; i < n; i++) {
1935 video_get_info_str(i, info);
1941 video_drawchars(VIDEO_INFO_X,
1945 (uchar *) info, space);
1947 video_drawchars(VIDEO_INFO_X +
1952 (uchar *) info + space,
1955 video_drawstring(VIDEO_INFO_X,
1966 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1970 static int cfb_fb_is_in_dram(void)
1972 struct bd_info *bd = gd->bd;
1976 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1977 start = bd->bi_dram[i].start;
1978 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1979 if ((ulong)video_fb_address >= start &&
1980 (ulong)video_fb_address < end)
1987 void video_clear(void)
1989 if (!video_fb_address)
1991 #ifdef VIDEO_HW_RECTFILL
1992 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
1995 VIDEO_VISIBLE_COLS, /* frame width */
1996 VIDEO_VISIBLE_ROWS, /* frame height */
1997 bgx /* fill color */
2000 memsetl(video_fb_address,
2001 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2005 static int cfg_video_init(void)
2007 unsigned char color8;
2009 pGD = video_hw_init();
2013 video_fb_address = (void *) VIDEO_FB_ADRS;
2015 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2017 /* Init drawing pats */
2018 switch (VIDEO_DATA_FORMAT) {
2019 case GDF__8BIT_INDEX:
2020 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2021 CONFIG_SYS_CONSOLE_FG_COL,
2022 CONFIG_SYS_CONSOLE_FG_COL);
2023 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2024 CONFIG_SYS_CONSOLE_BG_COL,
2025 CONFIG_SYS_CONSOLE_BG_COL);
2029 case GDF__8BIT_332RGB:
2030 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2031 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2032 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2033 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2035 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2036 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2037 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2038 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2041 case GDF_15BIT_555RGB:
2042 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2043 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2044 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2045 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2046 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2047 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2048 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2049 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2050 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2051 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2052 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2053 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2055 case GDF_16BIT_565RGB:
2056 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2057 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2058 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2059 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2061 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2062 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2063 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2064 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2065 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2067 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2069 case GDF_32BIT_X888RGB:
2070 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2071 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2072 CONFIG_SYS_CONSOLE_FG_COL;
2073 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2074 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2075 CONFIG_SYS_CONSOLE_BG_COL;
2077 case GDF_24BIT_888RGB:
2078 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2079 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2080 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2081 CONFIG_SYS_CONSOLE_FG_COL;
2082 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2083 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2084 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2085 CONFIG_SYS_CONSOLE_BG_COL;
2090 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2093 #ifdef CONFIG_VIDEO_LOGO
2094 /* Plot the logo and get start point of console */
2095 debug("Video: Drawing the logo ...\n");
2096 video_console_address = video_logo();
2098 video_console_address = video_fb_address;
2101 /* Initialize the console */
2105 if (cfb_do_flush_cache)
2106 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2112 * Implement a weak default function for boards that optionally
2113 * need to skip the video initialization.
2115 __weak int board_video_skip(void)
2117 /* As default, don't skip test */
2121 int drv_video_init(void)
2123 struct stdio_dev console_dev;
2125 bool __maybe_unused keyboard_ok = false;
2127 /* Check if video initialization should be skipped */
2128 if (board_video_skip())
2131 /* Init video chip - returns with framebuffer cleared */
2132 if (cfg_video_init() == -1)
2135 if (board_cfb_skip())
2138 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2139 have_keyboard = false;
2140 #elif defined(CONFIG_OF_CONTROL)
2141 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2142 "u-boot,no-keyboard");
2144 have_keyboard = true;
2146 if (have_keyboard) {
2147 debug("KBD: Keyboard init ...\n");
2148 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2149 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2153 /* Init vga device */
2154 memset(&console_dev, 0, sizeof(console_dev));
2155 strcpy(console_dev.name, "vga");
2156 console_dev.flags = DEV_FLAGS_OUTPUT;
2157 console_dev.putc = cfb_video_putc; /* 'putc' function */
2158 console_dev.puts = cfb_video_puts; /* 'puts' function */
2160 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2161 if (have_keyboard && keyboard_ok) {
2162 /* Also init console device */
2163 console_dev.flags |= DEV_FLAGS_INPUT;
2164 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2165 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2169 if (stdio_register(&console_dev) != 0)
2172 /* Return success */
2176 void video_position_cursor(unsigned col, unsigned row)
2178 console_col = min(col, CONSOLE_COLS - 1);
2179 console_row = min(row, CONSOLE_ROWS - 1);
2182 int video_get_pixel_width(void)
2184 return VIDEO_VISIBLE_COLS;
2187 int video_get_pixel_height(void)
2189 return VIDEO_VISIBLE_ROWS;
2192 int video_get_screen_rows(void)
2194 return CONSOLE_ROWS;
2197 int video_get_screen_columns(void)
2199 return CONSOLE_COLS;