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 MB862xx driver
87 #ifdef CONFIG_VIDEO_MB862xx
89 #ifdef CONFIG_VIDEO_CORALP
90 #define VIDEO_FB_LITTLE_ENDIAN
92 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
93 #define VIDEO_HW_RECTFILL
94 #define VIDEO_HW_BITBLT
99 * Defines for the i.MX31 driver (mx3fb.c)
101 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
102 #define VIDEO_FB_16BPP_WORD_SWAP
106 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
108 #include <video_fb.h>
115 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
116 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
117 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
118 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
119 #define VIDEO_FB_ADRS (pGD->frameAdrs)
126 #include <linux/types.h>
127 #include <stdio_dev.h>
128 #include <video_font.h>
130 #if defined(CONFIG_CMD_DATE)
134 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
135 #include <watchdog.h>
136 #include <bmp_layout.h>
140 #if !defined(CONFIG_VIDEO_SW_CURSOR)
141 /* no Cursor defined */
147 #if defined(CONFIG_VIDEO_SW_CURSOR)
148 void console_cursor(int state);
150 #define CURSOR_ON console_cursor(1)
151 #define CURSOR_OFF console_cursor(0)
152 #define CURSOR_SET video_set_cursor()
153 #endif /* CONFIG_VIDEO_SW_CURSOR */
155 #ifdef CONFIG_VIDEO_LOGO
156 #ifdef CONFIG_VIDEO_BMP_LOGO
157 #include <bmp_logo.h>
158 #include <bmp_logo_data.h>
159 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
160 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
161 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
162 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
164 #else /* CONFIG_VIDEO_BMP_LOGO */
165 #define LINUX_LOGO_WIDTH 80
166 #define LINUX_LOGO_HEIGHT 80
167 #define LINUX_LOGO_COLORS 214
168 #define LINUX_LOGO_LUT_OFFSET 0x20
170 #include <linux_logo.h>
171 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
172 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
173 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
174 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
175 #endif /* CONFIG_VIDEO_BMP_LOGO */
176 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
177 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
178 #else /* CONFIG_VIDEO_LOGO */
179 #define VIDEO_LOGO_WIDTH 0
180 #define VIDEO_LOGO_HEIGHT 0
181 #endif /* CONFIG_VIDEO_LOGO */
183 #define VIDEO_COLS VIDEO_VISIBLE_COLS
184 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
185 #ifndef VIDEO_LINE_LEN
186 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
188 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
189 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
191 #ifdef CONFIG_VIDEO_LOGO
192 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
194 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
197 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
198 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
199 #define CONSOLE_ROW_FIRST (video_console_address)
200 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
201 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
202 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
204 /* By default we scroll by a single line */
205 #ifndef CONFIG_CONSOLE_SCROLL_LINES
206 #define CONFIG_CONSOLE_SCROLL_LINES 1
210 #ifdef VIDEO_FB_LITTLE_ENDIAN
211 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
214 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
215 (((x) & 0x0000ff00) << 8) | \
216 (((x) & 0x00ff0000) >> 8) | \
217 (((x) & 0xff000000) >> 24) \
219 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
220 (((x) & 0x0000ff00) >> 8) | \
221 (((x) & 0x00ff0000) << 8) | \
222 (((x) & 0xff000000) >> 8) \
225 #define SWAP16(x) (x)
226 #define SWAP32(x) (x)
227 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
228 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
230 #define SHORTSWAP32(x) (x)
234 DECLARE_GLOBAL_DATA_PTR;
237 static GraphicDevice *pGD; /* Pointer to Graphic array */
239 static void *video_fb_address; /* frame buffer address */
240 static void *video_console_address; /* console buffer start address */
242 static int video_logo_height = VIDEO_LOGO_HEIGHT;
244 static int __maybe_unused cursor_state;
245 static int __maybe_unused old_col;
246 static int __maybe_unused old_row;
248 static int console_col; /* cursor col */
249 static int console_row; /* cursor row */
251 static u32 eorx, fgx, bgx; /* color pats */
253 static int cfb_do_flush_cache;
255 #ifdef CONFIG_CFB_CONSOLE_ANSI
256 static char ansi_buf[10];
257 static int ansi_buf_size;
258 static int ansi_colors_need_revert;
259 static int ansi_cursor_hidden;
262 static const int video_font_draw_table8[] = {
263 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
264 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
265 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
266 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
269 static const int video_font_draw_table15[] = {
270 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
273 static const int video_font_draw_table16[] = {
274 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
277 static const int video_font_draw_table24[16][3] = {
278 {0x00000000, 0x00000000, 0x00000000},
279 {0x00000000, 0x00000000, 0x00ffffff},
280 {0x00000000, 0x0000ffff, 0xff000000},
281 {0x00000000, 0x0000ffff, 0xffffffff},
282 {0x000000ff, 0xffff0000, 0x00000000},
283 {0x000000ff, 0xffff0000, 0x00ffffff},
284 {0x000000ff, 0xffffffff, 0xff000000},
285 {0x000000ff, 0xffffffff, 0xffffffff},
286 {0xffffff00, 0x00000000, 0x00000000},
287 {0xffffff00, 0x00000000, 0x00ffffff},
288 {0xffffff00, 0x0000ffff, 0xff000000},
289 {0xffffff00, 0x0000ffff, 0xffffffff},
290 {0xffffffff, 0xffff0000, 0x00000000},
291 {0xffffffff, 0xffff0000, 0x00ffffff},
292 {0xffffffff, 0xffffffff, 0xff000000},
293 {0xffffffff, 0xffffffff, 0xffffffff}
296 static const int video_font_draw_table32[16][4] = {
297 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
298 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
299 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
300 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
301 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
302 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
303 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
304 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
305 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
306 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
307 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
308 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
309 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
310 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
311 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
312 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
316 * Implement a weak default function for boards that optionally
317 * need to skip the cfb initialization.
319 __weak int board_cfb_skip(void)
321 /* As default, don't skip cfb init */
325 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
327 u8 *cdat, *dest, *dest0;
330 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
331 dest0 = video_fb_address + offset;
333 switch (VIDEO_DATA_FORMAT) {
334 case GDF__8BIT_INDEX:
335 case GDF__8BIT_332RGB:
338 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
339 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
340 rows--; dest += VIDEO_LINE_LEN) {
344 (video_font_draw_table8[bits >> 4] &
347 if (VIDEO_FONT_WIDTH == 4)
351 (video_font_draw_table8[bits & 15] &
354 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
359 case GDF_15BIT_555RGB:
362 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
363 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
364 rows--; dest += VIDEO_LINE_LEN) {
368 SHORTSWAP32((video_font_draw_table15
369 [bits >> 6] & eorx) ^
372 SHORTSWAP32((video_font_draw_table15
373 [bits >> 4 & 3] & eorx) ^
376 if (VIDEO_FONT_WIDTH == 4)
380 SHORTSWAP32((video_font_draw_table15
381 [bits >> 2 & 3] & eorx) ^
384 SHORTSWAP32((video_font_draw_table15
388 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
393 case GDF_16BIT_565RGB:
396 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
397 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
398 rows--; dest += VIDEO_LINE_LEN) {
402 SHORTSWAP32((video_font_draw_table16
403 [bits >> 6] & eorx) ^
406 SHORTSWAP32((video_font_draw_table16
407 [bits >> 4 & 3] & eorx) ^
410 if (VIDEO_FONT_WIDTH == 4)
414 SHORTSWAP32((video_font_draw_table16
415 [bits >> 2 & 3] & eorx) ^
418 SHORTSWAP32((video_font_draw_table16
422 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
427 case GDF_32BIT_X888RGB:
430 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
431 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
432 rows--; dest += VIDEO_LINE_LEN) {
436 SWAP32((video_font_draw_table32
437 [bits >> 4][0] & eorx) ^ bgx);
439 SWAP32((video_font_draw_table32
440 [bits >> 4][1] & eorx) ^ bgx);
442 SWAP32((video_font_draw_table32
443 [bits >> 4][2] & eorx) ^ bgx);
445 SWAP32((video_font_draw_table32
446 [bits >> 4][3] & eorx) ^ bgx);
449 if (VIDEO_FONT_WIDTH == 4)
453 SWAP32((video_font_draw_table32
454 [bits & 15][0] & eorx) ^ bgx);
456 SWAP32((video_font_draw_table32
457 [bits & 15][1] & eorx) ^ bgx);
459 SWAP32((video_font_draw_table32
460 [bits & 15][2] & eorx) ^ bgx);
462 SWAP32((video_font_draw_table32
463 [bits & 15][3] & eorx) ^ bgx);
465 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
470 case GDF_24BIT_888RGB:
473 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
474 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
475 rows--; dest += VIDEO_LINE_LEN) {
479 (video_font_draw_table24[bits >> 4][0]
482 (video_font_draw_table24[bits >> 4][1]
485 (video_font_draw_table24[bits >> 4][2]
488 if (VIDEO_FONT_WIDTH == 4)
492 (video_font_draw_table24[bits & 15][0]
495 (video_font_draw_table24[bits & 15][1]
498 (video_font_draw_table24[bits & 15][2]
501 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
508 static inline void video_drawstring(int xx, int yy, unsigned char *s)
510 video_drawchars(xx, yy, s, strlen((char *) s));
513 static void video_putchar(int xx, int yy, unsigned char c)
515 video_drawchars(xx, yy + video_logo_height, &c, 1);
518 #if defined(CONFIG_VIDEO_SW_CURSOR)
519 static void video_set_cursor(void)
526 static void video_invertchar(int xx, int yy)
528 int firstx = xx * VIDEO_PIXEL_SIZE;
529 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
530 int firsty = yy * VIDEO_LINE_LEN;
531 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
533 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
534 for (x = firstx; x < lastx; x++) {
535 u8 *dest = (u8 *)(video_fb_address) + x + y;
541 void console_cursor(int state)
543 if (cursor_state != state) {
545 /* turn off the cursor */
546 video_invertchar(old_col * VIDEO_FONT_WIDTH,
547 old_row * VIDEO_FONT_HEIGHT +
550 /* turn off the cursor and record where it is */
551 video_invertchar(console_col * VIDEO_FONT_WIDTH,
552 console_row * VIDEO_FONT_HEIGHT +
554 old_col = console_col;
555 old_row = console_row;
557 cursor_state = state;
559 if (cfb_do_flush_cache)
560 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
564 #ifndef VIDEO_HW_RECTFILL
565 static void memsetl(int *p, int c, int v)
572 #ifndef VIDEO_HW_BITBLT
573 static void memcpyl(int *d, int *s, int c)
580 static void console_clear_line(int line, int begin, int end)
582 #ifdef VIDEO_HW_RECTFILL
583 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
584 VIDEO_FONT_WIDTH * begin, /* dest pos x */
586 VIDEO_FONT_HEIGHT * line, /* dest pos y */
587 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
588 VIDEO_FONT_HEIGHT, /* frame height */
592 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
593 memsetl(CONSOLE_ROW_FIRST +
594 CONSOLE_ROW_SIZE * line, /* offset of row */
595 CONSOLE_ROW_SIZE >> 2, /* length of row */
602 offset = CONSOLE_ROW_FIRST +
603 CONSOLE_ROW_SIZE * line + /* offset of row */
605 VIDEO_PIXEL_SIZE * begin; /* offset of col */
606 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
607 size >>= 2; /* length to end for memsetl() */
608 /* fill at col offset of i'th line using bgx as fill color */
609 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
610 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
615 static void console_scrollup(void)
617 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
620 /* copy up rows ignoring the first one */
622 #ifdef VIDEO_HW_BITBLT
623 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
624 0, /* source pos x */
626 VIDEO_FONT_HEIGHT * rows, /* source pos y */
628 video_logo_height, /* dest pos y */
629 VIDEO_VISIBLE_COLS, /* frame width */
632 - VIDEO_FONT_HEIGHT * rows /* frame height */
635 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
636 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
638 /* clear the last one */
639 for (i = 1; i <= rows; i++)
640 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
642 /* Decrement row number */
646 static void console_back(void)
650 if (console_col < 0) {
651 console_col = CONSOLE_COLS - 1;
658 #ifdef CONFIG_CFB_CONSOLE_ANSI
660 static void console_clear(void)
662 #ifdef VIDEO_HW_RECTFILL
663 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
665 video_logo_height, /* dest pos y */
666 VIDEO_VISIBLE_COLS, /* frame width */
667 VIDEO_VISIBLE_ROWS, /* frame height */
671 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
675 static void console_cursor_fix(void)
679 if (console_row >= CONSOLE_ROWS)
680 console_row = CONSOLE_ROWS - 1;
683 if (console_col >= CONSOLE_COLS)
684 console_col = CONSOLE_COLS - 1;
687 static void console_cursor_up(int n)
690 console_cursor_fix();
693 static void console_cursor_down(int n)
696 console_cursor_fix();
699 static void console_cursor_left(int n)
702 console_cursor_fix();
705 static void console_cursor_right(int n)
708 console_cursor_fix();
711 static void console_cursor_set_position(int row, int col)
713 if (console_row != -1)
715 if (console_col != -1)
717 console_cursor_fix();
720 static void console_previousline(int n)
722 /* FIXME: also scroll terminal ? */
724 console_cursor_fix();
727 static void console_swap_colors(void)
735 static inline int console_cursor_is_visible(void)
737 return !ansi_cursor_hidden;
740 static inline int console_cursor_is_visible(void)
746 static void console_newline(int n)
751 /* Check if we need to scroll the terminal */
752 if (console_row >= CONSOLE_ROWS) {
753 /* Scroll everything up */
758 static void console_cr(void)
763 static void parse_putc(const char c)
767 if (console_cursor_is_visible())
771 case 13: /* back to first column */
775 case '\n': /* next line */
776 if (console_col || nl)
782 console_col |= 0x0008;
783 console_col &= ~0x0007;
785 if (console_col >= CONSOLE_COLS)
789 case 8: /* backspace */
796 default: /* draw the char */
797 video_putchar(console_col * VIDEO_FONT_WIDTH,
798 console_row * VIDEO_FONT_HEIGHT, c);
801 /* check for newline */
802 if (console_col >= CONSOLE_COLS) {
808 if (console_cursor_is_visible())
812 static void cfb_video_putc(struct stdio_dev *dev, const char c)
814 #ifdef CONFIG_CFB_CONSOLE_ANSI
818 for (i = 0; i < ansi_buf_size; ++i)
819 parse_putc(ansi_buf[i]);
825 if (ansi_buf_size > 0) {
845 ansi_buf[ansi_buf_size++] = c;
847 if (ansi_buf_size >= sizeof(ansi_buf))
850 for (i = 0; i < ansi_buf_size; ++i) {
856 if (ansi_buf[i] == 27)
863 if (ansi_buf[i] == '[')
870 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
871 num1 = ansi_buf[i]-'0';
873 } else if (ansi_buf[i] != '?') {
881 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
883 num1 += ansi_buf[i]-'0';
891 if (ansi_buf[i] != ';') {
899 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
900 num2 = ansi_buf[i]-'0';
907 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
909 num2 += ansi_buf[i]-'0';
917 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
918 || ansi_buf[i] == 'J'
919 || ansi_buf[i] == 'K'
920 || ansi_buf[i] == 'h'
921 || ansi_buf[i] == 'l'
922 || ansi_buf[i] == 'm') {
932 for (i = 0; i < ansi_buf_size; ++i)
933 parse_putc(ansi_buf[i]);
939 if (!ansi_cursor_hidden)
944 /* move cursor num1 rows up */
945 console_cursor_up(num1);
948 /* move cursor num1 rows down */
949 console_cursor_down(num1);
952 /* move cursor num1 columns forward */
953 console_cursor_right(num1);
956 /* move cursor num1 columns back */
957 console_cursor_left(num1);
960 /* move cursor num1 rows up at begin of row */
961 console_previousline(num1);
964 /* move cursor num1 rows down at begin of row */
965 console_newline(num1);
968 /* move cursor to column num1 */
969 console_cursor_set_position(-1, num1-1);
972 /* move cursor to row num1, column num2 */
973 console_cursor_set_position(num1-1, num2-1);
976 /* clear console and move cursor to 0, 0 */
978 console_cursor_set_position(0, 0);
983 console_clear_line(console_row,
987 console_clear_line(console_row,
990 console_clear_line(console_row,
994 ansi_cursor_hidden = 0;
997 ansi_cursor_hidden = 1;
1000 if (num1 == 0) { /* reset swapped colors */
1001 if (ansi_colors_need_revert) {
1002 console_swap_colors();
1003 ansi_colors_need_revert = 0;
1005 } else if (num1 == 7) { /* once swap colors */
1006 if (!ansi_colors_need_revert) {
1007 console_swap_colors();
1008 ansi_colors_need_revert = 1;
1013 if (!ansi_cursor_hidden)
1022 if (cfb_do_flush_cache)
1023 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1026 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1028 int flush = cfb_do_flush_cache;
1029 int count = strlen(s);
1031 /* temporarily disable cache flush */
1032 cfb_do_flush_cache = 0;
1035 cfb_video_putc(dev, *s++);
1038 cfb_do_flush_cache = flush;
1039 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1044 * Do not enforce drivers (or board code) to provide empty
1045 * video_set_lut() if they do not support 8 bpp format.
1046 * Implement weak default function instead.
1048 __weak void video_set_lut(unsigned int index, unsigned char r,
1049 unsigned char g, unsigned char b)
1053 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1055 #define FILL_8BIT_332RGB(r,g,b) { \
1056 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1060 #define FILL_15BIT_555RGB(r,g,b) { \
1061 *(unsigned short *)fb = \
1062 SWAP16((unsigned short)(((r>>3)<<10) | \
1068 #define FILL_16BIT_565RGB(r,g,b) { \
1069 *(unsigned short *)fb = \
1070 SWAP16((unsigned short)((((r)>>3)<<11)| \
1076 #define FILL_32BIT_X888RGB(r,g,b) { \
1078 SWAP32((unsigned int)(((r<<16) | \
1084 #ifdef VIDEO_FB_LITTLE_ENDIAN
1085 #define FILL_24BIT_888RGB(r,g,b) { \
1092 #define FILL_24BIT_888RGB(r,g,b) { \
1100 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1101 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1103 ushort *dst = (ushort *) fb;
1104 ushort color = (ushort) (((r >> 3) << 10) |
1115 * RLE8 bitmap support
1118 #ifdef CONFIG_VIDEO_BMP_RLE8
1119 /* Pre-calculated color table entry */
1122 unsigned short w; /* word */
1123 unsigned int dw; /* double word */
1124 } ce; /* color entry */
1128 * Helper to draw encoded/unencoded run.
1130 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1133 ulong addr = (ulong) *fb;
1139 * Setup offset of the color index in the bitmap.
1140 * Color index of encoded run is at offset 1.
1142 off = enc ? &enc_off : &i;
1144 switch (VIDEO_DATA_FORMAT) {
1145 case GDF__8BIT_INDEX:
1146 for (i = 0; i < cnt; i++)
1147 *(unsigned char *) addr++ = bm[*off];
1149 case GDF_15BIT_555RGB:
1150 case GDF_16BIT_565RGB:
1151 /* differences handled while pre-calculating palette */
1152 for (i = 0; i < cnt; i++) {
1153 *(unsigned short *) addr = p[bm[*off]].ce.w;
1157 case GDF_32BIT_X888RGB:
1158 for (i = 0; i < cnt; i++) {
1159 *(u32 *) addr = p[bm[*off]].ce.dw;
1164 *fb = (uchar *) addr; /* return modified address */
1167 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1168 int width, int height)
1172 unsigned int cnt, runlen;
1174 int x, y, bpp, i, ncolors;
1175 struct palette p[256];
1176 struct bmp_color_table_entry cte;
1177 int green_shift, red_off;
1178 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1182 y = __le32_to_cpu(img->header.height) - 1;
1183 ncolors = __le32_to_cpu(img->header.colors_used);
1184 bpp = VIDEO_PIXEL_SIZE;
1185 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1186 (y + yoff) * VIDEO_LINE_LEN +
1189 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1191 /* pre-calculate and setup palette */
1192 switch (VIDEO_DATA_FORMAT) {
1193 case GDF__8BIT_INDEX:
1194 for (i = 0; i < ncolors; i++) {
1195 cte = img->color_table[i];
1196 video_set_lut(i, cte.red, cte.green, cte.blue);
1199 case GDF_15BIT_555RGB:
1200 case GDF_16BIT_565RGB:
1201 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1208 for (i = 0; i < ncolors; i++) {
1209 cte = img->color_table[i];
1210 p[i].ce.w = SWAP16((unsigned short)
1211 (((cte.red >> 3) << red_off) |
1212 ((cte.green >> green_shift) << 5) |
1216 case GDF_32BIT_X888RGB:
1217 for (i = 0; i < ncolors; i++) {
1218 cte = img->color_table[i];
1219 p[i].ce.dw = SWAP32((cte.red << 16) |
1225 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1235 /* scan line end marker */
1239 fbp = (unsigned char *)
1240 ((unsigned int) video_fb_address +
1241 (y + yoff) * VIDEO_LINE_LEN +
1245 /* end of bitmap data marker */
1249 /* run offset marker */
1252 fbp = (unsigned char *)
1253 ((unsigned int) video_fb_address +
1254 (y + yoff) * VIDEO_LINE_LEN +
1272 if (x + runlen > width)
1274 draw_bitmap(&fbp, bm, p, cnt, 0);
1280 bm++; /* 0 padding if length is odd */
1291 if (y < height) { /* only draw into visible area */
1297 if (x + runlen > width)
1299 draw_bitmap(&fbp, bm, p, cnt, 1);
1307 if (cfb_do_flush_cache)
1308 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1312 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1318 * Display the BMP file located at address bmp_image.
1320 int video_display_bitmap(ulong bmp_image, int x, int y)
1322 ushort xcount, ycount;
1324 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1327 unsigned long width, height, bpp;
1329 unsigned long compression;
1330 struct bmp_color_table_entry cte;
1332 #ifdef CONFIG_VIDEO_BMP_GZIP
1333 unsigned char *dst = NULL;
1339 if (!((bmp->header.signature[0] == 'B') &&
1340 (bmp->header.signature[1] == 'M'))) {
1342 #ifdef CONFIG_VIDEO_BMP_GZIP
1344 * Could be a gzipped bmp image, try to decrompress...
1346 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1347 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1349 printf("Error: malloc in gunzip failed!\n");
1353 * NB: we need to force offset of +2
1354 * See doc/README.displaying-bmps
1356 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1357 (uchar *) bmp_image,
1359 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1364 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1365 printf("Image could be truncated "
1366 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1370 * Set addr to decompressed image
1372 bmp = (struct bmp_image *)(dst+2);
1374 if (!((bmp->header.signature[0] == 'B') &&
1375 (bmp->header.signature[1] == 'M'))) {
1376 printf("Error: no valid bmp.gz image at %lx\n",
1382 printf("Error: no valid bmp image at %lx\n", bmp_image);
1384 #endif /* CONFIG_VIDEO_BMP_GZIP */
1387 width = le32_to_cpu(bmp->header.width);
1388 height = le32_to_cpu(bmp->header.height);
1389 bpp = le16_to_cpu(bmp->header.bit_count);
1390 colors = le32_to_cpu(bmp->header.colors_used);
1391 compression = le32_to_cpu(bmp->header.compression);
1393 debug("Display-bmp: %ld x %ld with %d colors\n",
1394 width, height, colors);
1396 if (compression != BMP_BI_RGB
1397 #ifdef CONFIG_VIDEO_BMP_RLE8
1398 && compression != BMP_BI_RLE8
1401 printf("Error: compression type %ld not supported\n",
1403 #ifdef CONFIG_VIDEO_BMP_GZIP
1410 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1412 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1413 if (x == BMP_ALIGN_CENTER)
1414 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1416 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1418 if (y == BMP_ALIGN_CENTER)
1419 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1421 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1422 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1425 * Just ignore elements which are completely beyond screen
1428 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1431 if ((x + width) > VIDEO_VISIBLE_COLS)
1432 width = VIDEO_VISIBLE_COLS - x;
1433 if ((y + height) > VIDEO_VISIBLE_ROWS)
1434 height = VIDEO_VISIBLE_ROWS - y;
1436 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1437 fb = (uchar *) (video_fb_address +
1438 ((y + height - 1) * VIDEO_LINE_LEN) +
1439 x * VIDEO_PIXEL_SIZE);
1441 #ifdef CONFIG_VIDEO_BMP_RLE8
1442 if (compression == BMP_BI_RLE8) {
1443 return display_rle8_bitmap(bmp, x, y, width, height);
1447 /* We handle only 4, 8, or 24 bpp bitmaps */
1448 switch (le16_to_cpu(bmp->header.bit_count)) {
1450 padded_line -= width / 2;
1453 switch (VIDEO_DATA_FORMAT) {
1454 case GDF_32BIT_X888RGB:
1458 * Don't assume that 'width' is an
1461 for (xcount = 0; xcount < width; xcount++) {
1469 cte = bmp->color_table[idx];
1470 FILL_32BIT_X888RGB(cte.red, cte.green,
1473 bmap += padded_line;
1474 fb -= VIDEO_LINE_LEN + width *
1479 puts("4bpp bitmap unsupported with current "
1486 padded_line -= width;
1487 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1489 for (xcount = 0; xcount < colors; ++xcount) {
1490 cte = bmp->color_table[xcount];
1491 video_set_lut(xcount, cte.red, cte.green,
1496 switch (VIDEO_DATA_FORMAT) {
1497 case GDF__8BIT_INDEX:
1504 bmap += padded_line;
1505 fb -= VIDEO_LINE_LEN + width *
1509 case GDF__8BIT_332RGB:
1514 cte = bmp->color_table[*bmap++];
1515 FILL_8BIT_332RGB(cte.red, cte.green,
1518 bmap += padded_line;
1519 fb -= VIDEO_LINE_LEN + width *
1523 case GDF_15BIT_555RGB:
1525 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1531 cte = bmp->color_table[*bmap++];
1532 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1533 fill_555rgb_pswap(fb, xpos++, cte.red,
1538 FILL_15BIT_555RGB(cte.red, cte.green,
1542 bmap += padded_line;
1543 fb -= VIDEO_LINE_LEN + width *
1547 case GDF_16BIT_565RGB:
1552 cte = bmp->color_table[*bmap++];
1553 FILL_16BIT_565RGB(cte.red, cte.green,
1556 bmap += padded_line;
1557 fb -= VIDEO_LINE_LEN + width *
1561 case GDF_32BIT_X888RGB:
1566 cte = bmp->color_table[*bmap++];
1567 FILL_32BIT_X888RGB(cte.red, cte.green,
1570 bmap += padded_line;
1571 fb -= VIDEO_LINE_LEN + width *
1575 case GDF_24BIT_888RGB:
1580 cte = bmp->color_table[*bmap++];
1581 FILL_24BIT_888RGB(cte.red, cte.green,
1584 bmap += padded_line;
1585 fb -= VIDEO_LINE_LEN + width *
1592 padded_line -= 3 * width;
1594 switch (VIDEO_DATA_FORMAT) {
1595 case GDF__8BIT_332RGB:
1600 FILL_8BIT_332RGB(bmap[2], bmap[1],
1604 bmap += padded_line;
1605 fb -= VIDEO_LINE_LEN + width *
1609 case GDF_15BIT_555RGB:
1611 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1617 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1618 fill_555rgb_pswap(fb, xpos++, bmap[2],
1622 FILL_15BIT_555RGB(bmap[2], bmap[1],
1627 bmap += padded_line;
1628 fb -= VIDEO_LINE_LEN + width *
1632 case GDF_16BIT_565RGB:
1637 FILL_16BIT_565RGB(bmap[2], bmap[1],
1641 bmap += padded_line;
1642 fb -= VIDEO_LINE_LEN + width *
1646 case GDF_32BIT_X888RGB:
1651 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1655 bmap += padded_line;
1656 fb -= VIDEO_LINE_LEN + width *
1660 case GDF_24BIT_888RGB:
1665 FILL_24BIT_888RGB(bmap[2], bmap[1],
1669 bmap += padded_line;
1670 fb -= VIDEO_LINE_LEN + width *
1675 printf("Error: 24 bits/pixel bitmap incompatible "
1676 "with current video mode\n");
1681 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1682 le16_to_cpu(bmp->header.bit_count));
1686 #ifdef CONFIG_VIDEO_BMP_GZIP
1692 if (cfb_do_flush_cache)
1693 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1699 #ifdef CONFIG_VIDEO_LOGO
1700 static int video_logo_xpos;
1701 static int video_logo_ypos;
1703 static void plot_logo_or_black(void *screen, int x, int y, int black);
1705 static void logo_plot(void *screen, int x, int y)
1707 plot_logo_or_black(screen, x, y, 0);
1710 static void logo_black(void)
1712 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1716 static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1720 return cmd_usage(cmdtp);
1727 clrlogo, 1, 0, do_clrlogo,
1728 "fill the boot logo area with black",
1732 static void plot_logo_or_black(void *screen, int x, int y, int black)
1736 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1737 int ycount = video_logo_height;
1738 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1739 unsigned char *source;
1740 unsigned char *dest;
1742 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1743 if (x == BMP_ALIGN_CENTER)
1744 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1746 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1748 if (y == BMP_ALIGN_CENTER)
1749 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1751 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1752 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1754 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1756 #ifdef CONFIG_VIDEO_BMP_LOGO
1757 source = bmp_logo_bitmap;
1759 /* Allocate temporary space for computing colormap */
1760 logo_red = malloc(BMP_LOGO_COLORS);
1761 logo_green = malloc(BMP_LOGO_COLORS);
1762 logo_blue = malloc(BMP_LOGO_COLORS);
1763 /* Compute color map */
1764 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1765 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1766 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1767 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1770 source = linux_logo;
1771 logo_red = linux_logo_red;
1772 logo_green = linux_logo_green;
1773 logo_blue = linux_logo_blue;
1776 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1777 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1778 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1779 logo_red[i], logo_green[i],
1785 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1788 xcount = VIDEO_LOGO_WIDTH;
1795 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1796 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1797 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1800 switch (VIDEO_DATA_FORMAT) {
1801 case GDF__8BIT_INDEX:
1804 case GDF__8BIT_332RGB:
1805 *dest = ((r >> 5) << 5) |
1809 case GDF_15BIT_555RGB:
1810 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1811 fill_555rgb_pswap(dest, xpos++, r, g, b);
1813 *(unsigned short *) dest =
1814 SWAP16((unsigned short) (
1820 case GDF_16BIT_565RGB:
1821 *(unsigned short *) dest =
1822 SWAP16((unsigned short) (
1827 case GDF_32BIT_X888RGB:
1834 case GDF_24BIT_888RGB:
1835 #ifdef VIDEO_FB_LITTLE_ENDIAN
1847 dest += VIDEO_PIXEL_SIZE;
1851 #ifdef CONFIG_VIDEO_BMP_LOGO
1858 static void *video_logo(void)
1861 __maybe_unused int y_off = 0;
1862 __maybe_unused ulong addr;
1863 __maybe_unused char *s;
1864 __maybe_unused int len, ret, space;
1866 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1868 #ifdef CONFIG_SPLASH_SCREEN
1869 s = env_get("splashimage");
1871 ret = splash_screen_prepare();
1873 return video_fb_address;
1874 addr = simple_strtoul(s, NULL, 16);
1876 if (video_display_bitmap(addr,
1878 video_logo_ypos) == 0) {
1879 video_logo_height = 0;
1880 return ((void *) (video_fb_address));
1883 #endif /* CONFIG_SPLASH_SCREEN */
1885 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1887 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1889 * when using splashpos for video_logo, skip any info
1890 * output on video console if the logo is not at 0,0
1892 if (video_logo_xpos || video_logo_ypos) {
1894 * video_logo_height is used in text and cursor offset
1895 * calculations. Since the console is below the logo,
1896 * we need to adjust the logo height
1898 if (video_logo_ypos == BMP_ALIGN_CENTER)
1899 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1900 VIDEO_LOGO_HEIGHT) / 2);
1901 else if (video_logo_ypos > 0)
1902 video_logo_height += video_logo_ypos;
1904 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1907 if (board_cfb_skip())
1910 sprintf(info, " %s", version_string);
1912 #ifndef CONFIG_HIDE_LOGO_VERSION
1913 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1917 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1918 uchar *p = (uchar *) info;
1922 video_drawchars(xx, yy, p, space);
1925 p = (uchar *)p + space;
1928 xx += VIDEO_FONT_WIDTH;
1931 yy += VIDEO_FONT_HEIGHT;
1935 video_drawchars(xx, yy, p, len);
1940 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1942 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1945 ((video_logo_height -
1946 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1948 for (i = 1; i < n; i++) {
1949 video_get_info_str(i, info);
1955 video_drawchars(VIDEO_INFO_X,
1959 (uchar *) info, space);
1961 video_drawchars(VIDEO_INFO_X +
1966 (uchar *) info + space,
1969 video_drawstring(VIDEO_INFO_X,
1980 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1984 static int cfb_fb_is_in_dram(void)
1986 struct bd_info *bd = gd->bd;
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)
2001 void video_clear(void)
2003 if (!video_fb_address)
2005 #ifdef VIDEO_HW_RECTFILL
2006 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2009 VIDEO_VISIBLE_COLS, /* frame width */
2010 VIDEO_VISIBLE_ROWS, /* frame height */
2011 bgx /* fill color */
2014 memsetl(video_fb_address,
2015 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2019 static int cfg_video_init(void)
2021 unsigned char color8;
2023 pGD = video_hw_init();
2027 video_fb_address = (void *) VIDEO_FB_ADRS;
2029 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2031 /* Init drawing pats */
2032 switch (VIDEO_DATA_FORMAT) {
2033 case GDF__8BIT_INDEX:
2034 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2035 CONFIG_SYS_CONSOLE_FG_COL,
2036 CONFIG_SYS_CONSOLE_FG_COL);
2037 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2038 CONFIG_SYS_CONSOLE_BG_COL,
2039 CONFIG_SYS_CONSOLE_BG_COL);
2043 case GDF__8BIT_332RGB:
2044 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2045 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2046 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2047 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2049 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2050 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2051 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2052 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2055 case GDF_15BIT_555RGB:
2056 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2057 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2058 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2059 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2061 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2062 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2063 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2064 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2065 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2067 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2069 case GDF_16BIT_565RGB:
2070 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2071 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2072 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2073 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2074 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2075 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2076 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2077 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2078 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2079 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2080 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2081 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2083 case GDF_32BIT_X888RGB:
2084 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2085 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2086 CONFIG_SYS_CONSOLE_FG_COL;
2087 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2088 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2089 CONFIG_SYS_CONSOLE_BG_COL;
2091 case GDF_24BIT_888RGB:
2092 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2093 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2094 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2095 CONFIG_SYS_CONSOLE_FG_COL;
2096 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2097 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2098 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2099 CONFIG_SYS_CONSOLE_BG_COL;
2104 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2107 #ifdef CONFIG_VIDEO_LOGO
2108 /* Plot the logo and get start point of console */
2109 debug("Video: Drawing the logo ...\n");
2110 video_console_address = video_logo();
2112 video_console_address = video_fb_address;
2115 /* Initialize the console */
2119 if (cfb_do_flush_cache)
2120 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2126 * Implement a weak default function for boards that optionally
2127 * need to skip the video initialization.
2129 __weak int board_video_skip(void)
2131 /* As default, don't skip test */
2135 int drv_video_init(void)
2137 struct stdio_dev console_dev;
2139 bool __maybe_unused keyboard_ok = false;
2141 /* Check if video initialization should be skipped */
2142 if (board_video_skip())
2145 /* Init video chip - returns with framebuffer cleared */
2146 if (cfg_video_init() == -1)
2149 if (board_cfb_skip())
2152 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2153 have_keyboard = false;
2154 #elif defined(CONFIG_OF_CONTROL)
2155 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2156 "u-boot,no-keyboard");
2158 have_keyboard = true;
2160 if (have_keyboard) {
2161 debug("KBD: Keyboard init ...\n");
2162 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2163 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2167 /* Init vga device */
2168 memset(&console_dev, 0, sizeof(console_dev));
2169 strcpy(console_dev.name, "vga");
2170 console_dev.flags = DEV_FLAGS_OUTPUT;
2171 console_dev.putc = cfb_video_putc; /* 'putc' function */
2172 console_dev.puts = cfb_video_puts; /* 'puts' function */
2174 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2175 if (have_keyboard && keyboard_ok) {
2176 /* Also init console device */
2177 console_dev.flags |= DEV_FLAGS_INPUT;
2178 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2179 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2183 if (stdio_register(&console_dev) != 0)
2186 /* Return success */
2190 void video_position_cursor(unsigned col, unsigned row)
2192 console_col = min(col, CONSOLE_COLS - 1);
2193 console_row = min(row, CONSOLE_ROWS - 1);
2196 int video_get_pixel_width(void)
2198 return VIDEO_VISIBLE_COLS;
2201 int video_get_pixel_height(void)
2203 return VIDEO_VISIBLE_ROWS;
2206 int video_get_screen_rows(void)
2208 return CONSOLE_ROWS;
2211 int video_get_screen_columns(void)
2213 return CONSOLE_COLS;