2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * SPDX-License-Identifier: GPL-2.0+
11 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
13 * At the moment only the 8x16 font is tested and the font fore- and
14 * background color is limited to black/white/gray colors. The Linux
15 * logo can be placed in the upper left corner and additional board
16 * information strings (that normally goes to serial port) can be drawn.
18 * The console driver can use a keyboard interface for character input
19 * but this is deprecated. Only rk51 uses it.
21 * Character output goes to a memory-mapped video
22 * framebuffer with little or big-endian organisation.
23 * With environment setting 'console=serial' the console i/o can be
24 * forced to serial port.
26 * The driver uses graphic specific defines/parameters/functions:
28 * (for SMI LynxE graphic chip)
30 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
31 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
32 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
34 * Console Parameters are set by graphic drivers global struct:
36 * VIDEO_VISIBLE_COLS - x resolution
37 * VIDEO_VISIBLE_ROWS - y resolution
38 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
39 * VIDEO_DATA_FORMAT - graphical data format GDF
40 * VIDEO_FB_ADRS - start of video memory
42 * VIDEO_KBD_INIT_FCT - init function for keyboard
43 * VIDEO_TSTC_FCT - keyboard_tstc function
44 * VIDEO_GETC_FCT - keyboard_getc function
46 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
47 * Use CONFIG_SPLASH_SCREEN_ALIGN with
48 * environment variable "splashpos" to place
49 * the logo on other position. In this case
50 * no CONSOLE_EXTRA_INFO is possible.
51 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
52 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
53 * strings that normaly goes to serial
54 * port. This define requires a board
56 * video_drawstring (VIDEO_INFO_X,
57 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
59 * that fills a info buffer at i=row.
60 * s.a: board/eltec/bab7xx.
62 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
63 * character. No blinking is provided.
64 * Uses the macros CURSOR_SET and
73 #include <linux/compiler.h>
75 #if defined(CONFIG_VIDEO_MXS)
76 #define VIDEO_FB_16BPP_WORD_SWAP
80 * Defines for the MB862xx driver
82 #ifdef CONFIG_VIDEO_MB862xx
84 #ifdef CONFIG_VIDEO_CORALP
85 #define VIDEO_FB_LITTLE_ENDIAN
87 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
88 #define VIDEO_HW_RECTFILL
89 #define VIDEO_HW_BITBLT
94 * Defines for the i.MX31 driver (mx3fb.c)
96 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
97 #define VIDEO_FB_16BPP_WORD_SWAP
101 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
103 #include <video_fb.h>
110 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
111 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
112 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
113 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
114 #define VIDEO_FB_ADRS (pGD->frameAdrs)
121 #include <linux/types.h>
122 #include <stdio_dev.h>
123 #include <video_font.h>
125 #if defined(CONFIG_CMD_DATE)
129 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
130 #include <watchdog.h>
131 #include <bmp_layout.h>
135 #if !defined(CONFIG_VIDEO_SW_CURSOR)
136 /* no Cursor defined */
142 #if defined(CONFIG_VIDEO_SW_CURSOR)
143 void console_cursor(int state);
145 #define CURSOR_ON console_cursor(1)
146 #define CURSOR_OFF console_cursor(0)
147 #define CURSOR_SET video_set_cursor()
148 #endif /* CONFIG_VIDEO_SW_CURSOR */
150 #ifdef CONFIG_VIDEO_LOGO
151 #ifdef CONFIG_VIDEO_BMP_LOGO
152 #include <bmp_logo.h>
153 #include <bmp_logo_data.h>
154 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
155 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
156 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
157 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
159 #else /* CONFIG_VIDEO_BMP_LOGO */
160 #define LINUX_LOGO_WIDTH 80
161 #define LINUX_LOGO_HEIGHT 80
162 #define LINUX_LOGO_COLORS 214
163 #define LINUX_LOGO_LUT_OFFSET 0x20
165 #include <linux_logo.h>
166 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
167 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
168 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
169 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
170 #endif /* CONFIG_VIDEO_BMP_LOGO */
171 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
172 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
173 #else /* CONFIG_VIDEO_LOGO */
174 #define VIDEO_LOGO_WIDTH 0
175 #define VIDEO_LOGO_HEIGHT 0
176 #endif /* CONFIG_VIDEO_LOGO */
178 #define VIDEO_COLS VIDEO_VISIBLE_COLS
179 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
180 #ifndef VIDEO_LINE_LEN
181 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
183 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
184 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
186 #ifdef CONFIG_VIDEO_LOGO
187 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
189 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
192 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
193 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
194 #define CONSOLE_ROW_FIRST (video_console_address)
195 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
196 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
197 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
199 /* By default we scroll by a single line */
200 #ifndef CONFIG_CONSOLE_SCROLL_LINES
201 #define CONFIG_CONSOLE_SCROLL_LINES 1
205 #ifdef VIDEO_FB_LITTLE_ENDIAN
206 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
209 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
210 (((x) & 0x0000ff00) << 8) | \
211 (((x) & 0x00ff0000) >> 8) | \
212 (((x) & 0xff000000) >> 24) \
214 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
215 (((x) & 0x0000ff00) >> 8) | \
216 (((x) & 0x00ff0000) << 8) | \
217 (((x) & 0xff000000) >> 8) \
220 #define SWAP16(x) (x)
221 #define SWAP32(x) (x)
222 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
223 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
225 #define SHORTSWAP32(x) (x)
229 DECLARE_GLOBAL_DATA_PTR;
232 static GraphicDevice *pGD; /* Pointer to Graphic array */
234 static void *video_fb_address; /* frame buffer address */
235 static void *video_console_address; /* console buffer start address */
237 static int video_logo_height = VIDEO_LOGO_HEIGHT;
239 static int __maybe_unused cursor_state;
240 static int __maybe_unused old_col;
241 static int __maybe_unused old_row;
243 static int console_col; /* cursor col */
244 static int console_row; /* cursor row */
246 static u32 eorx, fgx, bgx; /* color pats */
248 static int cfb_do_flush_cache;
250 #ifdef CONFIG_CFB_CONSOLE_ANSI
251 static char ansi_buf[10];
252 static int ansi_buf_size;
253 static int ansi_colors_need_revert;
254 static int ansi_cursor_hidden;
257 static const int video_font_draw_table8[] = {
258 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
259 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
260 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
261 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
264 static const int video_font_draw_table15[] = {
265 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
268 static const int video_font_draw_table16[] = {
269 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
272 static const int video_font_draw_table24[16][3] = {
273 {0x00000000, 0x00000000, 0x00000000},
274 {0x00000000, 0x00000000, 0x00ffffff},
275 {0x00000000, 0x0000ffff, 0xff000000},
276 {0x00000000, 0x0000ffff, 0xffffffff},
277 {0x000000ff, 0xffff0000, 0x00000000},
278 {0x000000ff, 0xffff0000, 0x00ffffff},
279 {0x000000ff, 0xffffffff, 0xff000000},
280 {0x000000ff, 0xffffffff, 0xffffffff},
281 {0xffffff00, 0x00000000, 0x00000000},
282 {0xffffff00, 0x00000000, 0x00ffffff},
283 {0xffffff00, 0x0000ffff, 0xff000000},
284 {0xffffff00, 0x0000ffff, 0xffffffff},
285 {0xffffffff, 0xffff0000, 0x00000000},
286 {0xffffffff, 0xffff0000, 0x00ffffff},
287 {0xffffffff, 0xffffffff, 0xff000000},
288 {0xffffffff, 0xffffffff, 0xffffffff}
291 static const int video_font_draw_table32[16][4] = {
292 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
293 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
294 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
295 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
296 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
297 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
298 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
299 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
300 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
301 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
302 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
303 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
304 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
305 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
306 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
307 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
311 * Implement a weak default function for boards that optionally
312 * need to skip the cfb initialization.
314 __weak int board_cfb_skip(void)
316 /* As default, don't skip cfb init */
320 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
322 u8 *cdat, *dest, *dest0;
325 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
326 dest0 = video_fb_address + offset;
328 switch (VIDEO_DATA_FORMAT) {
329 case GDF__8BIT_INDEX:
330 case GDF__8BIT_332RGB:
333 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
334 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
335 rows--; dest += VIDEO_LINE_LEN) {
339 (video_font_draw_table8[bits >> 4] &
342 if (VIDEO_FONT_WIDTH == 4)
346 (video_font_draw_table8[bits & 15] &
349 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
354 case GDF_15BIT_555RGB:
357 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
358 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
359 rows--; dest += VIDEO_LINE_LEN) {
363 SHORTSWAP32((video_font_draw_table15
364 [bits >> 6] & eorx) ^
367 SHORTSWAP32((video_font_draw_table15
368 [bits >> 4 & 3] & eorx) ^
371 if (VIDEO_FONT_WIDTH == 4)
375 SHORTSWAP32((video_font_draw_table15
376 [bits >> 2 & 3] & eorx) ^
379 SHORTSWAP32((video_font_draw_table15
383 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
388 case GDF_16BIT_565RGB:
391 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
392 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
393 rows--; dest += VIDEO_LINE_LEN) {
397 SHORTSWAP32((video_font_draw_table16
398 [bits >> 6] & eorx) ^
401 SHORTSWAP32((video_font_draw_table16
402 [bits >> 4 & 3] & eorx) ^
405 if (VIDEO_FONT_WIDTH == 4)
409 SHORTSWAP32((video_font_draw_table16
410 [bits >> 2 & 3] & eorx) ^
413 SHORTSWAP32((video_font_draw_table16
417 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
422 case GDF_32BIT_X888RGB:
425 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
426 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
427 rows--; dest += VIDEO_LINE_LEN) {
431 SWAP32((video_font_draw_table32
432 [bits >> 4][0] & eorx) ^ bgx);
434 SWAP32((video_font_draw_table32
435 [bits >> 4][1] & eorx) ^ bgx);
437 SWAP32((video_font_draw_table32
438 [bits >> 4][2] & eorx) ^ bgx);
440 SWAP32((video_font_draw_table32
441 [bits >> 4][3] & eorx) ^ bgx);
444 if (VIDEO_FONT_WIDTH == 4)
448 SWAP32((video_font_draw_table32
449 [bits & 15][0] & eorx) ^ bgx);
451 SWAP32((video_font_draw_table32
452 [bits & 15][1] & eorx) ^ bgx);
454 SWAP32((video_font_draw_table32
455 [bits & 15][2] & eorx) ^ bgx);
457 SWAP32((video_font_draw_table32
458 [bits & 15][3] & eorx) ^ bgx);
460 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
465 case GDF_24BIT_888RGB:
468 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
469 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
470 rows--; dest += VIDEO_LINE_LEN) {
474 (video_font_draw_table24[bits >> 4][0]
477 (video_font_draw_table24[bits >> 4][1]
480 (video_font_draw_table24[bits >> 4][2]
483 if (VIDEO_FONT_WIDTH == 4)
487 (video_font_draw_table24[bits & 15][0]
490 (video_font_draw_table24[bits & 15][1]
493 (video_font_draw_table24[bits & 15][2]
496 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
503 static inline void video_drawstring(int xx, int yy, unsigned char *s)
505 video_drawchars(xx, yy, s, strlen((char *) s));
508 static void video_putchar(int xx, int yy, unsigned char c)
510 video_drawchars(xx, yy + video_logo_height, &c, 1);
513 #if defined(CONFIG_VIDEO_SW_CURSOR)
514 static void video_set_cursor(void)
521 static void video_invertchar(int xx, int yy)
523 int firstx = xx * VIDEO_PIXEL_SIZE;
524 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
525 int firsty = yy * VIDEO_LINE_LEN;
526 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
528 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
529 for (x = firstx; x < lastx; x++) {
530 u8 *dest = (u8 *)(video_fb_address) + x + y;
536 void console_cursor(int state)
538 if (cursor_state != state) {
540 /* turn off the cursor */
541 video_invertchar(old_col * VIDEO_FONT_WIDTH,
542 old_row * VIDEO_FONT_HEIGHT +
545 /* turn off the cursor and record where it is */
546 video_invertchar(console_col * VIDEO_FONT_WIDTH,
547 console_row * VIDEO_FONT_HEIGHT +
549 old_col = console_col;
550 old_row = console_row;
552 cursor_state = state;
554 if (cfb_do_flush_cache)
555 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
559 #ifndef VIDEO_HW_RECTFILL
560 static void memsetl(int *p, int c, int v)
567 #ifndef VIDEO_HW_BITBLT
568 static void memcpyl(int *d, int *s, int c)
575 static void console_clear_line(int line, int begin, int end)
577 #ifdef VIDEO_HW_RECTFILL
578 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
579 VIDEO_FONT_WIDTH * begin, /* dest pos x */
581 VIDEO_FONT_HEIGHT * line, /* dest pos y */
582 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
583 VIDEO_FONT_HEIGHT, /* frame height */
587 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
588 memsetl(CONSOLE_ROW_FIRST +
589 CONSOLE_ROW_SIZE * line, /* offset of row */
590 CONSOLE_ROW_SIZE >> 2, /* length of row */
597 offset = CONSOLE_ROW_FIRST +
598 CONSOLE_ROW_SIZE * line + /* offset of row */
600 VIDEO_PIXEL_SIZE * begin; /* offset of col */
601 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
602 size >>= 2; /* length to end for memsetl() */
603 /* fill at col offset of i'th line using bgx as fill color */
604 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
605 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
610 static void console_scrollup(void)
612 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
615 /* copy up rows ignoring the first one */
617 #ifdef VIDEO_HW_BITBLT
618 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
619 0, /* source pos x */
621 VIDEO_FONT_HEIGHT * rows, /* source pos y */
623 video_logo_height, /* dest pos y */
624 VIDEO_VISIBLE_COLS, /* frame width */
627 - VIDEO_FONT_HEIGHT * rows /* frame height */
630 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
631 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
633 /* clear the last one */
634 for (i = 1; i <= rows; i++)
635 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
637 /* Decrement row number */
641 static void console_back(void)
645 if (console_col < 0) {
646 console_col = CONSOLE_COLS - 1;
653 #ifdef CONFIG_CFB_CONSOLE_ANSI
655 static void console_clear(void)
657 #ifdef VIDEO_HW_RECTFILL
658 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
660 video_logo_height, /* dest pos y */
661 VIDEO_VISIBLE_COLS, /* frame width */
662 VIDEO_VISIBLE_ROWS, /* frame height */
666 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
670 static void console_cursor_fix(void)
674 if (console_row >= CONSOLE_ROWS)
675 console_row = CONSOLE_ROWS - 1;
678 if (console_col >= CONSOLE_COLS)
679 console_col = CONSOLE_COLS - 1;
682 static void console_cursor_up(int n)
685 console_cursor_fix();
688 static void console_cursor_down(int n)
691 console_cursor_fix();
694 static void console_cursor_left(int n)
697 console_cursor_fix();
700 static void console_cursor_right(int n)
703 console_cursor_fix();
706 static void console_cursor_set_position(int row, int col)
708 if (console_row != -1)
710 if (console_col != -1)
712 console_cursor_fix();
715 static void console_previousline(int n)
717 /* FIXME: also scroll terminal ? */
719 console_cursor_fix();
722 static void console_swap_colors(void)
730 static inline int console_cursor_is_visible(void)
732 return !ansi_cursor_hidden;
735 static inline int console_cursor_is_visible(void)
741 static void console_newline(int n)
746 /* Check if we need to scroll the terminal */
747 if (console_row >= CONSOLE_ROWS) {
748 /* Scroll everything up */
753 static void console_cr(void)
758 static void parse_putc(const char c)
762 if (console_cursor_is_visible())
766 case 13: /* back to first column */
770 case '\n': /* next line */
771 if (console_col || (!console_col && nl))
777 console_col |= 0x0008;
778 console_col &= ~0x0007;
780 if (console_col >= CONSOLE_COLS)
784 case 8: /* backspace */
791 default: /* draw the char */
792 video_putchar(console_col * VIDEO_FONT_WIDTH,
793 console_row * VIDEO_FONT_HEIGHT, c);
796 /* check for newline */
797 if (console_col >= CONSOLE_COLS) {
803 if (console_cursor_is_visible())
807 static void cfb_video_putc(struct stdio_dev *dev, const char c)
809 #ifdef CONFIG_CFB_CONSOLE_ANSI
813 for (i = 0; i < ansi_buf_size; ++i)
814 parse_putc(ansi_buf[i]);
820 if (ansi_buf_size > 0) {
840 ansi_buf[ansi_buf_size++] = c;
842 if (ansi_buf_size >= sizeof(ansi_buf))
845 for (i = 0; i < ansi_buf_size; ++i) {
851 if (ansi_buf[i] == 27)
858 if (ansi_buf[i] == '[')
865 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
866 num1 = ansi_buf[i]-'0';
868 } else if (ansi_buf[i] != '?') {
876 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
878 num1 += ansi_buf[i]-'0';
886 if (ansi_buf[i] != ';') {
894 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
895 num2 = ansi_buf[i]-'0';
902 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
904 num2 += ansi_buf[i]-'0';
912 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
913 || ansi_buf[i] == 'J'
914 || ansi_buf[i] == 'K'
915 || ansi_buf[i] == 'h'
916 || ansi_buf[i] == 'l'
917 || ansi_buf[i] == 'm') {
927 for (i = 0; i < ansi_buf_size; ++i)
928 parse_putc(ansi_buf[i]);
934 if (!ansi_cursor_hidden)
939 /* move cursor num1 rows up */
940 console_cursor_up(num1);
943 /* move cursor num1 rows down */
944 console_cursor_down(num1);
947 /* move cursor num1 columns forward */
948 console_cursor_right(num1);
951 /* move cursor num1 columns back */
952 console_cursor_left(num1);
955 /* move cursor num1 rows up at begin of row */
956 console_previousline(num1);
959 /* move cursor num1 rows down at begin of row */
960 console_newline(num1);
963 /* move cursor to column num1 */
964 console_cursor_set_position(-1, num1-1);
967 /* move cursor to row num1, column num2 */
968 console_cursor_set_position(num1-1, num2-1);
971 /* clear console and move cursor to 0, 0 */
973 console_cursor_set_position(0, 0);
978 console_clear_line(console_row,
982 console_clear_line(console_row,
985 console_clear_line(console_row,
989 ansi_cursor_hidden = 0;
992 ansi_cursor_hidden = 1;
995 if (num1 == 0) { /* reset swapped colors */
996 if (ansi_colors_need_revert) {
997 console_swap_colors();
998 ansi_colors_need_revert = 0;
1000 } else if (num1 == 7) { /* once swap colors */
1001 if (!ansi_colors_need_revert) {
1002 console_swap_colors();
1003 ansi_colors_need_revert = 1;
1008 if (!ansi_cursor_hidden)
1017 if (cfb_do_flush_cache)
1018 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1021 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1023 int flush = cfb_do_flush_cache;
1024 int count = strlen(s);
1026 /* temporarily disable cache flush */
1027 cfb_do_flush_cache = 0;
1030 cfb_video_putc(dev, *s++);
1033 cfb_do_flush_cache = flush;
1034 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1039 * Do not enforce drivers (or board code) to provide empty
1040 * video_set_lut() if they do not support 8 bpp format.
1041 * Implement weak default function instead.
1043 __weak void video_set_lut(unsigned int index, unsigned char r,
1044 unsigned char g, unsigned char b)
1048 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1050 #define FILL_8BIT_332RGB(r,g,b) { \
1051 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1055 #define FILL_15BIT_555RGB(r,g,b) { \
1056 *(unsigned short *)fb = \
1057 SWAP16((unsigned short)(((r>>3)<<10) | \
1063 #define FILL_16BIT_565RGB(r,g,b) { \
1064 *(unsigned short *)fb = \
1065 SWAP16((unsigned short)((((r)>>3)<<11)| \
1071 #define FILL_32BIT_X888RGB(r,g,b) { \
1073 SWAP32((unsigned int)(((r<<16) | \
1079 #ifdef VIDEO_FB_LITTLE_ENDIAN
1080 #define FILL_24BIT_888RGB(r,g,b) { \
1087 #define FILL_24BIT_888RGB(r,g,b) { \
1095 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1096 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1098 ushort *dst = (ushort *) fb;
1099 ushort color = (ushort) (((r >> 3) << 10) |
1110 * RLE8 bitmap support
1113 #ifdef CONFIG_VIDEO_BMP_RLE8
1114 /* Pre-calculated color table entry */
1117 unsigned short w; /* word */
1118 unsigned int dw; /* double word */
1119 } ce; /* color entry */
1123 * Helper to draw encoded/unencoded run.
1125 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1128 ulong addr = (ulong) *fb;
1134 * Setup offset of the color index in the bitmap.
1135 * Color index of encoded run is at offset 1.
1137 off = enc ? &enc_off : &i;
1139 switch (VIDEO_DATA_FORMAT) {
1140 case GDF__8BIT_INDEX:
1141 for (i = 0; i < cnt; i++)
1142 *(unsigned char *) addr++ = bm[*off];
1144 case GDF_15BIT_555RGB:
1145 case GDF_16BIT_565RGB:
1146 /* differences handled while pre-calculating palette */
1147 for (i = 0; i < cnt; i++) {
1148 *(unsigned short *) addr = p[bm[*off]].ce.w;
1152 case GDF_32BIT_X888RGB:
1153 for (i = 0; i < cnt; i++) {
1154 *(u32 *) addr = p[bm[*off]].ce.dw;
1159 *fb = (uchar *) addr; /* return modified address */
1162 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1163 int width, int height)
1167 unsigned int cnt, runlen;
1169 int x, y, bpp, i, ncolors;
1170 struct palette p[256];
1171 struct bmp_color_table_entry cte;
1172 int green_shift, red_off;
1173 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1177 y = __le32_to_cpu(img->header.height) - 1;
1178 ncolors = __le32_to_cpu(img->header.colors_used);
1179 bpp = VIDEO_PIXEL_SIZE;
1180 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1181 (y + yoff) * VIDEO_LINE_LEN +
1184 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1186 /* pre-calculate and setup palette */
1187 switch (VIDEO_DATA_FORMAT) {
1188 case GDF__8BIT_INDEX:
1189 for (i = 0; i < ncolors; i++) {
1190 cte = img->color_table[i];
1191 video_set_lut(i, cte.red, cte.green, cte.blue);
1194 case GDF_15BIT_555RGB:
1195 case GDF_16BIT_565RGB:
1196 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1203 for (i = 0; i < ncolors; i++) {
1204 cte = img->color_table[i];
1205 p[i].ce.w = SWAP16((unsigned short)
1206 (((cte.red >> 3) << red_off) |
1207 ((cte.green >> green_shift) << 5) |
1211 case GDF_32BIT_X888RGB:
1212 for (i = 0; i < ncolors; i++) {
1213 cte = img->color_table[i];
1214 p[i].ce.dw = SWAP32((cte.red << 16) |
1220 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1230 /* scan line end marker */
1234 fbp = (unsigned char *)
1235 ((unsigned int) video_fb_address +
1236 (y + yoff) * VIDEO_LINE_LEN +
1240 /* end of bitmap data marker */
1244 /* run offset marker */
1247 fbp = (unsigned char *)
1248 ((unsigned int) video_fb_address +
1249 (y + yoff) * VIDEO_LINE_LEN +
1267 if (x + runlen > width)
1269 draw_bitmap(&fbp, bm, p, cnt, 0);
1275 bm++; /* 0 padding if length is odd */
1286 if (y < height) { /* only draw into visible area */
1292 if (x + runlen > width)
1294 draw_bitmap(&fbp, bm, p, cnt, 1);
1303 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1309 * Display the BMP file located at address bmp_image.
1311 int video_display_bitmap(ulong bmp_image, int x, int y)
1313 ushort xcount, ycount;
1315 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1318 unsigned long width, height, bpp;
1320 unsigned long compression;
1321 struct bmp_color_table_entry cte;
1323 #ifdef CONFIG_VIDEO_BMP_GZIP
1324 unsigned char *dst = NULL;
1330 if (!((bmp->header.signature[0] == 'B') &&
1331 (bmp->header.signature[1] == 'M'))) {
1333 #ifdef CONFIG_VIDEO_BMP_GZIP
1335 * Could be a gzipped bmp image, try to decrompress...
1337 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1338 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1340 printf("Error: malloc in gunzip failed!\n");
1344 * NB: we need to force offset of +2
1345 * See doc/README.displaying-bmps
1347 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1348 (uchar *) bmp_image,
1350 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1355 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1356 printf("Image could be truncated "
1357 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1361 * Set addr to decompressed image
1363 bmp = (struct bmp_image *)(dst+2);
1365 if (!((bmp->header.signature[0] == 'B') &&
1366 (bmp->header.signature[1] == 'M'))) {
1367 printf("Error: no valid bmp.gz image at %lx\n",
1373 printf("Error: no valid bmp image at %lx\n", bmp_image);
1375 #endif /* CONFIG_VIDEO_BMP_GZIP */
1378 width = le32_to_cpu(bmp->header.width);
1379 height = le32_to_cpu(bmp->header.height);
1380 bpp = le16_to_cpu(bmp->header.bit_count);
1381 colors = le32_to_cpu(bmp->header.colors_used);
1382 compression = le32_to_cpu(bmp->header.compression);
1384 debug("Display-bmp: %ld x %ld with %d colors\n",
1385 width, height, colors);
1387 if (compression != BMP_BI_RGB
1388 #ifdef CONFIG_VIDEO_BMP_RLE8
1389 && compression != BMP_BI_RLE8
1392 printf("Error: compression type %ld not supported\n",
1394 #ifdef CONFIG_VIDEO_BMP_GZIP
1401 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1403 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1404 if (x == BMP_ALIGN_CENTER)
1405 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1407 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1409 if (y == BMP_ALIGN_CENTER)
1410 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1412 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1413 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1416 * Just ignore elements which are completely beyond screen
1419 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1422 if ((x + width) > VIDEO_VISIBLE_COLS)
1423 width = VIDEO_VISIBLE_COLS - x;
1424 if ((y + height) > VIDEO_VISIBLE_ROWS)
1425 height = VIDEO_VISIBLE_ROWS - y;
1427 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1428 fb = (uchar *) (video_fb_address +
1429 ((y + height - 1) * VIDEO_LINE_LEN) +
1430 x * VIDEO_PIXEL_SIZE);
1432 #ifdef CONFIG_VIDEO_BMP_RLE8
1433 if (compression == BMP_BI_RLE8) {
1434 return display_rle8_bitmap(bmp, x, y, width, height);
1438 /* We handle only 4, 8, or 24 bpp bitmaps */
1439 switch (le16_to_cpu(bmp->header.bit_count)) {
1441 padded_line -= width / 2;
1444 switch (VIDEO_DATA_FORMAT) {
1445 case GDF_32BIT_X888RGB:
1449 * Don't assume that 'width' is an
1452 for (xcount = 0; xcount < width; xcount++) {
1460 cte = bmp->color_table[idx];
1461 FILL_32BIT_X888RGB(cte.red, cte.green,
1464 bmap += padded_line;
1465 fb -= VIDEO_LINE_LEN + width *
1470 puts("4bpp bitmap unsupported with current "
1477 padded_line -= width;
1478 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1480 for (xcount = 0; xcount < colors; ++xcount) {
1481 cte = bmp->color_table[xcount];
1482 video_set_lut(xcount, cte.red, cte.green,
1487 switch (VIDEO_DATA_FORMAT) {
1488 case GDF__8BIT_INDEX:
1495 bmap += padded_line;
1496 fb -= VIDEO_LINE_LEN + width *
1500 case GDF__8BIT_332RGB:
1505 cte = bmp->color_table[*bmap++];
1506 FILL_8BIT_332RGB(cte.red, cte.green,
1509 bmap += padded_line;
1510 fb -= VIDEO_LINE_LEN + width *
1514 case GDF_15BIT_555RGB:
1516 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1522 cte = bmp->color_table[*bmap++];
1523 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1524 fill_555rgb_pswap(fb, xpos++, cte.red,
1529 FILL_15BIT_555RGB(cte.red, cte.green,
1533 bmap += padded_line;
1534 fb -= VIDEO_LINE_LEN + width *
1538 case GDF_16BIT_565RGB:
1543 cte = bmp->color_table[*bmap++];
1544 FILL_16BIT_565RGB(cte.red, cte.green,
1547 bmap += padded_line;
1548 fb -= VIDEO_LINE_LEN + width *
1552 case GDF_32BIT_X888RGB:
1557 cte = bmp->color_table[*bmap++];
1558 FILL_32BIT_X888RGB(cte.red, cte.green,
1561 bmap += padded_line;
1562 fb -= VIDEO_LINE_LEN + width *
1566 case GDF_24BIT_888RGB:
1571 cte = bmp->color_table[*bmap++];
1572 FILL_24BIT_888RGB(cte.red, cte.green,
1575 bmap += padded_line;
1576 fb -= VIDEO_LINE_LEN + width *
1583 padded_line -= 3 * width;
1585 switch (VIDEO_DATA_FORMAT) {
1586 case GDF__8BIT_332RGB:
1591 FILL_8BIT_332RGB(bmap[2], bmap[1],
1595 bmap += padded_line;
1596 fb -= VIDEO_LINE_LEN + width *
1600 case GDF_15BIT_555RGB:
1602 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1608 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1609 fill_555rgb_pswap(fb, xpos++, bmap[2],
1613 FILL_15BIT_555RGB(bmap[2], bmap[1],
1618 bmap += padded_line;
1619 fb -= VIDEO_LINE_LEN + width *
1623 case GDF_16BIT_565RGB:
1628 FILL_16BIT_565RGB(bmap[2], bmap[1],
1632 bmap += padded_line;
1633 fb -= VIDEO_LINE_LEN + width *
1637 case GDF_32BIT_X888RGB:
1642 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1646 bmap += padded_line;
1647 fb -= VIDEO_LINE_LEN + width *
1651 case GDF_24BIT_888RGB:
1656 FILL_24BIT_888RGB(bmap[2], bmap[1],
1660 bmap += padded_line;
1661 fb -= VIDEO_LINE_LEN + width *
1666 printf("Error: 24 bits/pixel bitmap incompatible "
1667 "with current video mode\n");
1672 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1673 le16_to_cpu(bmp->header.bit_count));
1677 #ifdef CONFIG_VIDEO_BMP_GZIP
1683 if (cfb_do_flush_cache)
1684 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1690 #ifdef CONFIG_VIDEO_LOGO
1691 static int video_logo_xpos;
1692 static int video_logo_ypos;
1694 static void plot_logo_or_black(void *screen, int x, int y, int black);
1696 static void logo_plot(void *screen, int x, int y)
1698 plot_logo_or_black(screen, x, y, 0);
1701 static void logo_black(void)
1703 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1707 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1710 return cmd_usage(cmdtp);
1717 clrlogo, 1, 0, do_clrlogo,
1718 "fill the boot logo area with black",
1722 static void plot_logo_or_black(void *screen, int x, int y, int black)
1726 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1727 int ycount = video_logo_height;
1728 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1729 unsigned char *source;
1730 unsigned char *dest;
1732 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1733 if (x == BMP_ALIGN_CENTER)
1734 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1736 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1738 if (y == BMP_ALIGN_CENTER)
1739 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1741 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1742 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1744 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1746 #ifdef CONFIG_VIDEO_BMP_LOGO
1747 source = bmp_logo_bitmap;
1749 /* Allocate temporary space for computing colormap */
1750 logo_red = malloc(BMP_LOGO_COLORS);
1751 logo_green = malloc(BMP_LOGO_COLORS);
1752 logo_blue = malloc(BMP_LOGO_COLORS);
1753 /* Compute color map */
1754 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1755 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1756 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1757 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1760 source = linux_logo;
1761 logo_red = linux_logo_red;
1762 logo_green = linux_logo_green;
1763 logo_blue = linux_logo_blue;
1766 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1767 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1768 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1769 logo_red[i], logo_green[i],
1775 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1778 xcount = VIDEO_LOGO_WIDTH;
1785 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1786 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1787 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1790 switch (VIDEO_DATA_FORMAT) {
1791 case GDF__8BIT_INDEX:
1794 case GDF__8BIT_332RGB:
1795 *dest = ((r >> 5) << 5) |
1799 case GDF_15BIT_555RGB:
1800 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1801 fill_555rgb_pswap(dest, xpos++, r, g, b);
1803 *(unsigned short *) dest =
1804 SWAP16((unsigned short) (
1810 case GDF_16BIT_565RGB:
1811 *(unsigned short *) dest =
1812 SWAP16((unsigned short) (
1817 case GDF_32BIT_X888RGB:
1824 case GDF_24BIT_888RGB:
1825 #ifdef VIDEO_FB_LITTLE_ENDIAN
1837 dest += VIDEO_PIXEL_SIZE;
1841 #ifdef CONFIG_VIDEO_BMP_LOGO
1848 static void *video_logo(void)
1851 __maybe_unused int y_off = 0;
1852 __maybe_unused ulong addr;
1853 __maybe_unused char *s;
1854 __maybe_unused int len, ret, space;
1856 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1858 #ifdef CONFIG_SPLASH_SCREEN
1859 s = env_get("splashimage");
1861 ret = splash_screen_prepare();
1863 return video_fb_address;
1864 addr = simple_strtoul(s, NULL, 16);
1866 if (video_display_bitmap(addr,
1868 video_logo_ypos) == 0) {
1869 video_logo_height = 0;
1870 return ((void *) (video_fb_address));
1873 #endif /* CONFIG_SPLASH_SCREEN */
1875 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1877 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1879 * when using splashpos for video_logo, skip any info
1880 * output on video console if the logo is not at 0,0
1882 if (video_logo_xpos || video_logo_ypos) {
1884 * video_logo_height is used in text and cursor offset
1885 * calculations. Since the console is below the logo,
1886 * we need to adjust the logo height
1888 if (video_logo_ypos == BMP_ALIGN_CENTER)
1889 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1890 VIDEO_LOGO_HEIGHT) / 2);
1891 else if (video_logo_ypos > 0)
1892 video_logo_height += video_logo_ypos;
1894 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1897 if (board_cfb_skip())
1900 sprintf(info, " %s", version_string);
1902 #ifndef CONFIG_HIDE_LOGO_VERSION
1903 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1907 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1908 (uchar *) info, space);
1909 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1910 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1911 (uchar *) info + space, len - space);
1914 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1916 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1919 ((video_logo_height -
1920 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1922 for (i = 1; i < n; i++) {
1923 video_get_info_str(i, info);
1929 video_drawchars(VIDEO_INFO_X,
1933 (uchar *) info, space);
1935 video_drawchars(VIDEO_INFO_X +
1940 (uchar *) info + space,
1943 video_drawstring(VIDEO_INFO_X,
1954 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1958 static int cfb_fb_is_in_dram(void)
1961 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
1962 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1966 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1967 start = bd->bi_dram[i].start;
1968 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1969 if ((ulong)video_fb_address >= start &&
1970 (ulong)video_fb_address < end)
1974 if ((ulong)video_fb_address >= bd->bi_memstart &&
1975 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1981 void video_clear(void)
1983 if (!video_fb_address)
1985 #ifdef VIDEO_HW_RECTFILL
1986 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
1989 VIDEO_VISIBLE_COLS, /* frame width */
1990 VIDEO_VISIBLE_ROWS, /* frame height */
1991 bgx /* fill color */
1994 memsetl(video_fb_address,
1995 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
1999 static int cfg_video_init(void)
2001 unsigned char color8;
2003 pGD = video_hw_init();
2007 video_fb_address = (void *) VIDEO_FB_ADRS;
2009 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2011 /* Init drawing pats */
2012 switch (VIDEO_DATA_FORMAT) {
2013 case GDF__8BIT_INDEX:
2014 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2015 CONFIG_SYS_CONSOLE_FG_COL,
2016 CONFIG_SYS_CONSOLE_FG_COL);
2017 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2018 CONFIG_SYS_CONSOLE_BG_COL,
2019 CONFIG_SYS_CONSOLE_BG_COL);
2023 case GDF__8BIT_332RGB:
2024 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2025 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2026 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2027 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2029 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2030 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2031 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2032 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2035 case GDF_15BIT_555RGB:
2036 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2037 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2038 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2039 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2040 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2041 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2042 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2043 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2044 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2045 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2046 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2047 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2049 case GDF_16BIT_565RGB:
2050 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2051 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2052 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2053 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2054 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2055 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2056 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2057 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2058 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2059 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2060 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2061 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2063 case GDF_32BIT_X888RGB:
2064 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2065 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2066 CONFIG_SYS_CONSOLE_FG_COL;
2067 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2068 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2069 CONFIG_SYS_CONSOLE_BG_COL;
2071 case GDF_24BIT_888RGB:
2072 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2073 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2074 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2075 CONFIG_SYS_CONSOLE_FG_COL;
2076 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2077 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2078 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2079 CONFIG_SYS_CONSOLE_BG_COL;
2086 #ifdef CONFIG_VIDEO_LOGO
2087 /* Plot the logo and get start point of console */
2088 debug("Video: Drawing the logo ...\n");
2089 video_console_address = video_logo();
2091 video_console_address = video_fb_address;
2094 /* Initialize the console */
2098 if (cfb_do_flush_cache)
2099 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2105 * Implement a weak default function for boards that optionally
2106 * need to skip the video initialization.
2108 __weak int board_video_skip(void)
2110 /* As default, don't skip test */
2114 int drv_video_init(void)
2116 struct stdio_dev console_dev;
2118 bool __maybe_unused keyboard_ok = false;
2120 /* Check if video initialization should be skipped */
2121 if (board_video_skip())
2124 /* Init video chip - returns with framebuffer cleared */
2125 if (cfg_video_init() == -1)
2128 if (board_cfb_skip())
2131 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2132 have_keyboard = false;
2133 #elif defined(CONFIG_OF_CONTROL)
2134 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2135 "u-boot,no-keyboard");
2137 have_keyboard = true;
2139 if (have_keyboard) {
2140 debug("KBD: Keyboard init ...\n");
2141 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2142 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2146 /* Init vga device */
2147 memset(&console_dev, 0, sizeof(console_dev));
2148 strcpy(console_dev.name, "vga");
2149 console_dev.flags = DEV_FLAGS_OUTPUT;
2150 console_dev.putc = cfb_video_putc; /* 'putc' function */
2151 console_dev.puts = cfb_video_puts; /* 'puts' function */
2153 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2154 if (have_keyboard && keyboard_ok) {
2155 /* Also init console device */
2156 console_dev.flags |= DEV_FLAGS_INPUT;
2157 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2158 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2162 if (stdio_register(&console_dev) != 0)
2165 /* Return success */
2169 void video_position_cursor(unsigned col, unsigned row)
2171 console_col = min(col, CONSOLE_COLS - 1);
2172 console_row = min(row, CONSOLE_ROWS - 1);
2175 int video_get_pixel_width(void)
2177 return VIDEO_VISIBLE_COLS;
2180 int video_get_pixel_height(void)
2182 return VIDEO_VISIBLE_ROWS;
2185 int video_get_screen_rows(void)
2187 return CONSOLE_ROWS;
2190 int video_get_screen_columns(void)
2192 return CONSOLE_COLS;