1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2002 ELTEC Elektronik AG
4 * Frank Gottschling <fgottschling@eltec.de>
10 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
12 * At the moment only the 8x16 font is tested and the font fore- and
13 * background color is limited to black/white/gray colors. The Linux
14 * logo can be placed in the upper left corner and additional board
15 * information strings (that normally goes to serial port) can be drawn.
17 * The console driver can use a keyboard interface for character input
18 * but this is deprecated. Only rk51 uses it.
20 * Character output goes to a memory-mapped video
21 * framebuffer with little or big-endian organisation.
22 * With environment setting 'console=serial' the console i/o can be
23 * forced to serial port.
25 * The driver uses graphic specific defines/parameters/functions:
27 * (for SMI LynxE graphic chip)
29 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
30 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
31 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
33 * Console Parameters are set by graphic drivers global struct:
35 * VIDEO_VISIBLE_COLS - x resolution
36 * VIDEO_VISIBLE_ROWS - y resolution
37 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
38 * VIDEO_DATA_FORMAT - graphical data format GDF
39 * VIDEO_FB_ADRS - start of video memory
41 * VIDEO_KBD_INIT_FCT - init function for keyboard
42 * VIDEO_TSTC_FCT - keyboard_tstc function
43 * VIDEO_GETC_FCT - keyboard_getc function
45 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
46 * Use CONFIG_SPLASH_SCREEN_ALIGN with
47 * environment variable "splashpos" to place
48 * the logo on other position. In this case
49 * no CONSOLE_EXTRA_INFO is possible.
50 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
51 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
52 * strings that normaly goes to serial
53 * port. This define requires a board
55 * video_drawstring (VIDEO_INFO_X,
56 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
58 * that fills a info buffer at i=row.
59 * s.a: board/eltec/bab7xx.
61 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
62 * character. No blinking is provided.
63 * Uses the macros CURSOR_SET and
74 #include <linux/compiler.h>
76 #if defined(CONFIG_VIDEO_MXS)
77 #define VIDEO_FB_16BPP_WORD_SWAP
81 * Defines for the MB862xx driver
83 #ifdef CONFIG_VIDEO_MB862xx
85 #ifdef CONFIG_VIDEO_CORALP
86 #define VIDEO_FB_LITTLE_ENDIAN
88 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
89 #define VIDEO_HW_RECTFILL
90 #define VIDEO_HW_BITBLT
95 * Defines for the i.MX31 driver (mx3fb.c)
97 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
98 #define VIDEO_FB_16BPP_WORD_SWAP
102 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
104 #include <video_fb.h>
111 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
112 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
113 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
114 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
115 #define VIDEO_FB_ADRS (pGD->frameAdrs)
122 #include <linux/types.h>
123 #include <stdio_dev.h>
124 #include <video_font.h>
126 #if defined(CONFIG_CMD_DATE)
130 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
131 #include <watchdog.h>
132 #include <bmp_layout.h>
136 #if !defined(CONFIG_VIDEO_SW_CURSOR)
137 /* no Cursor defined */
143 #if defined(CONFIG_VIDEO_SW_CURSOR)
144 void console_cursor(int state);
146 #define CURSOR_ON console_cursor(1)
147 #define CURSOR_OFF console_cursor(0)
148 #define CURSOR_SET video_set_cursor()
149 #endif /* CONFIG_VIDEO_SW_CURSOR */
151 #ifdef CONFIG_VIDEO_LOGO
152 #ifdef CONFIG_VIDEO_BMP_LOGO
153 #include <bmp_logo.h>
154 #include <bmp_logo_data.h>
155 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
156 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
157 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
158 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
160 #else /* CONFIG_VIDEO_BMP_LOGO */
161 #define LINUX_LOGO_WIDTH 80
162 #define LINUX_LOGO_HEIGHT 80
163 #define LINUX_LOGO_COLORS 214
164 #define LINUX_LOGO_LUT_OFFSET 0x20
166 #include <linux_logo.h>
167 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
168 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
169 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
170 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
171 #endif /* CONFIG_VIDEO_BMP_LOGO */
172 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
173 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
174 #else /* CONFIG_VIDEO_LOGO */
175 #define VIDEO_LOGO_WIDTH 0
176 #define VIDEO_LOGO_HEIGHT 0
177 #endif /* CONFIG_VIDEO_LOGO */
179 #define VIDEO_COLS VIDEO_VISIBLE_COLS
180 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
181 #ifndef VIDEO_LINE_LEN
182 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
184 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
185 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
187 #ifdef CONFIG_VIDEO_LOGO
188 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
190 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
193 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
194 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
195 #define CONSOLE_ROW_FIRST (video_console_address)
196 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
197 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
198 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
200 /* By default we scroll by a single line */
201 #ifndef CONFIG_CONSOLE_SCROLL_LINES
202 #define CONFIG_CONSOLE_SCROLL_LINES 1
206 #ifdef VIDEO_FB_LITTLE_ENDIAN
207 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
210 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
211 (((x) & 0x0000ff00) << 8) | \
212 (((x) & 0x00ff0000) >> 8) | \
213 (((x) & 0xff000000) >> 24) \
215 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
216 (((x) & 0x0000ff00) >> 8) | \
217 (((x) & 0x00ff0000) << 8) | \
218 (((x) & 0xff000000) >> 8) \
221 #define SWAP16(x) (x)
222 #define SWAP32(x) (x)
223 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
224 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
226 #define SHORTSWAP32(x) (x)
230 DECLARE_GLOBAL_DATA_PTR;
233 static GraphicDevice *pGD; /* Pointer to Graphic array */
235 static void *video_fb_address; /* frame buffer address */
236 static void *video_console_address; /* console buffer start address */
238 static int video_logo_height = VIDEO_LOGO_HEIGHT;
240 static int __maybe_unused cursor_state;
241 static int __maybe_unused old_col;
242 static int __maybe_unused old_row;
244 static int console_col; /* cursor col */
245 static int console_row; /* cursor row */
247 static u32 eorx, fgx, bgx; /* color pats */
249 static int cfb_do_flush_cache;
251 #ifdef CONFIG_CFB_CONSOLE_ANSI
252 static char ansi_buf[10];
253 static int ansi_buf_size;
254 static int ansi_colors_need_revert;
255 static int ansi_cursor_hidden;
258 static const int video_font_draw_table8[] = {
259 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
260 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
261 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
262 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
265 static const int video_font_draw_table15[] = {
266 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
269 static const int video_font_draw_table16[] = {
270 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
273 static const int video_font_draw_table24[16][3] = {
274 {0x00000000, 0x00000000, 0x00000000},
275 {0x00000000, 0x00000000, 0x00ffffff},
276 {0x00000000, 0x0000ffff, 0xff000000},
277 {0x00000000, 0x0000ffff, 0xffffffff},
278 {0x000000ff, 0xffff0000, 0x00000000},
279 {0x000000ff, 0xffff0000, 0x00ffffff},
280 {0x000000ff, 0xffffffff, 0xff000000},
281 {0x000000ff, 0xffffffff, 0xffffffff},
282 {0xffffff00, 0x00000000, 0x00000000},
283 {0xffffff00, 0x00000000, 0x00ffffff},
284 {0xffffff00, 0x0000ffff, 0xff000000},
285 {0xffffff00, 0x0000ffff, 0xffffffff},
286 {0xffffffff, 0xffff0000, 0x00000000},
287 {0xffffffff, 0xffff0000, 0x00ffffff},
288 {0xffffffff, 0xffffffff, 0xff000000},
289 {0xffffffff, 0xffffffff, 0xffffffff}
292 static const int video_font_draw_table32[16][4] = {
293 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
294 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
295 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
296 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
297 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
298 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
299 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
300 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
301 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
302 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
303 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
304 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
305 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
306 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
307 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
308 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
312 * Implement a weak default function for boards that optionally
313 * need to skip the cfb initialization.
315 __weak int board_cfb_skip(void)
317 /* As default, don't skip cfb init */
321 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
323 u8 *cdat, *dest, *dest0;
326 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
327 dest0 = video_fb_address + offset;
329 switch (VIDEO_DATA_FORMAT) {
330 case GDF__8BIT_INDEX:
331 case GDF__8BIT_332RGB:
334 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
335 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
336 rows--; dest += VIDEO_LINE_LEN) {
340 (video_font_draw_table8[bits >> 4] &
343 if (VIDEO_FONT_WIDTH == 4)
347 (video_font_draw_table8[bits & 15] &
350 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
355 case GDF_15BIT_555RGB:
358 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
359 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
360 rows--; dest += VIDEO_LINE_LEN) {
364 SHORTSWAP32((video_font_draw_table15
365 [bits >> 6] & eorx) ^
368 SHORTSWAP32((video_font_draw_table15
369 [bits >> 4 & 3] & eorx) ^
372 if (VIDEO_FONT_WIDTH == 4)
376 SHORTSWAP32((video_font_draw_table15
377 [bits >> 2 & 3] & eorx) ^
380 SHORTSWAP32((video_font_draw_table15
384 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
389 case GDF_16BIT_565RGB:
392 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
393 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
394 rows--; dest += VIDEO_LINE_LEN) {
398 SHORTSWAP32((video_font_draw_table16
399 [bits >> 6] & eorx) ^
402 SHORTSWAP32((video_font_draw_table16
403 [bits >> 4 & 3] & eorx) ^
406 if (VIDEO_FONT_WIDTH == 4)
410 SHORTSWAP32((video_font_draw_table16
411 [bits >> 2 & 3] & eorx) ^
414 SHORTSWAP32((video_font_draw_table16
418 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
423 case GDF_32BIT_X888RGB:
426 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
427 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
428 rows--; dest += VIDEO_LINE_LEN) {
432 SWAP32((video_font_draw_table32
433 [bits >> 4][0] & eorx) ^ bgx);
435 SWAP32((video_font_draw_table32
436 [bits >> 4][1] & eorx) ^ bgx);
438 SWAP32((video_font_draw_table32
439 [bits >> 4][2] & eorx) ^ bgx);
441 SWAP32((video_font_draw_table32
442 [bits >> 4][3] & eorx) ^ bgx);
445 if (VIDEO_FONT_WIDTH == 4)
449 SWAP32((video_font_draw_table32
450 [bits & 15][0] & eorx) ^ bgx);
452 SWAP32((video_font_draw_table32
453 [bits & 15][1] & eorx) ^ bgx);
455 SWAP32((video_font_draw_table32
456 [bits & 15][2] & eorx) ^ bgx);
458 SWAP32((video_font_draw_table32
459 [bits & 15][3] & eorx) ^ bgx);
461 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
466 case GDF_24BIT_888RGB:
469 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
470 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
471 rows--; dest += VIDEO_LINE_LEN) {
475 (video_font_draw_table24[bits >> 4][0]
478 (video_font_draw_table24[bits >> 4][1]
481 (video_font_draw_table24[bits >> 4][2]
484 if (VIDEO_FONT_WIDTH == 4)
488 (video_font_draw_table24[bits & 15][0]
491 (video_font_draw_table24[bits & 15][1]
494 (video_font_draw_table24[bits & 15][2]
497 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
504 static inline void video_drawstring(int xx, int yy, unsigned char *s)
506 video_drawchars(xx, yy, s, strlen((char *) s));
509 static void video_putchar(int xx, int yy, unsigned char c)
511 video_drawchars(xx, yy + video_logo_height, &c, 1);
514 #if defined(CONFIG_VIDEO_SW_CURSOR)
515 static void video_set_cursor(void)
522 static void video_invertchar(int xx, int yy)
524 int firstx = xx * VIDEO_PIXEL_SIZE;
525 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
526 int firsty = yy * VIDEO_LINE_LEN;
527 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
529 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
530 for (x = firstx; x < lastx; x++) {
531 u8 *dest = (u8 *)(video_fb_address) + x + y;
537 void console_cursor(int state)
539 if (cursor_state != state) {
541 /* turn off the cursor */
542 video_invertchar(old_col * VIDEO_FONT_WIDTH,
543 old_row * VIDEO_FONT_HEIGHT +
546 /* turn off the cursor and record where it is */
547 video_invertchar(console_col * VIDEO_FONT_WIDTH,
548 console_row * VIDEO_FONT_HEIGHT +
550 old_col = console_col;
551 old_row = console_row;
553 cursor_state = state;
555 if (cfb_do_flush_cache)
556 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
560 #ifndef VIDEO_HW_RECTFILL
561 static void memsetl(int *p, int c, int v)
568 #ifndef VIDEO_HW_BITBLT
569 static void memcpyl(int *d, int *s, int c)
576 static void console_clear_line(int line, int begin, int end)
578 #ifdef VIDEO_HW_RECTFILL
579 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
580 VIDEO_FONT_WIDTH * begin, /* dest pos x */
582 VIDEO_FONT_HEIGHT * line, /* dest pos y */
583 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
584 VIDEO_FONT_HEIGHT, /* frame height */
588 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
589 memsetl(CONSOLE_ROW_FIRST +
590 CONSOLE_ROW_SIZE * line, /* offset of row */
591 CONSOLE_ROW_SIZE >> 2, /* length of row */
598 offset = CONSOLE_ROW_FIRST +
599 CONSOLE_ROW_SIZE * line + /* offset of row */
601 VIDEO_PIXEL_SIZE * begin; /* offset of col */
602 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
603 size >>= 2; /* length to end for memsetl() */
604 /* fill at col offset of i'th line using bgx as fill color */
605 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
606 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
611 static void console_scrollup(void)
613 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
616 /* copy up rows ignoring the first one */
618 #ifdef VIDEO_HW_BITBLT
619 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
620 0, /* source pos x */
622 VIDEO_FONT_HEIGHT * rows, /* source pos y */
624 video_logo_height, /* dest pos y */
625 VIDEO_VISIBLE_COLS, /* frame width */
628 - VIDEO_FONT_HEIGHT * rows /* frame height */
631 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
632 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
634 /* clear the last one */
635 for (i = 1; i <= rows; i++)
636 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
638 /* Decrement row number */
642 static void console_back(void)
646 if (console_col < 0) {
647 console_col = CONSOLE_COLS - 1;
654 #ifdef CONFIG_CFB_CONSOLE_ANSI
656 static void console_clear(void)
658 #ifdef VIDEO_HW_RECTFILL
659 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
661 video_logo_height, /* dest pos y */
662 VIDEO_VISIBLE_COLS, /* frame width */
663 VIDEO_VISIBLE_ROWS, /* frame height */
667 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
671 static void console_cursor_fix(void)
675 if (console_row >= CONSOLE_ROWS)
676 console_row = CONSOLE_ROWS - 1;
679 if (console_col >= CONSOLE_COLS)
680 console_col = CONSOLE_COLS - 1;
683 static void console_cursor_up(int n)
686 console_cursor_fix();
689 static void console_cursor_down(int n)
692 console_cursor_fix();
695 static void console_cursor_left(int n)
698 console_cursor_fix();
701 static void console_cursor_right(int n)
704 console_cursor_fix();
707 static void console_cursor_set_position(int row, int col)
709 if (console_row != -1)
711 if (console_col != -1)
713 console_cursor_fix();
716 static void console_previousline(int n)
718 /* FIXME: also scroll terminal ? */
720 console_cursor_fix();
723 static void console_swap_colors(void)
731 static inline int console_cursor_is_visible(void)
733 return !ansi_cursor_hidden;
736 static inline int console_cursor_is_visible(void)
742 static void console_newline(int n)
747 /* Check if we need to scroll the terminal */
748 if (console_row >= CONSOLE_ROWS) {
749 /* Scroll everything up */
754 static void console_cr(void)
759 static void parse_putc(const char c)
763 if (console_cursor_is_visible())
767 case 13: /* back to first column */
771 case '\n': /* next line */
772 if (console_col || nl)
778 console_col |= 0x0008;
779 console_col &= ~0x0007;
781 if (console_col >= CONSOLE_COLS)
785 case 8: /* backspace */
792 default: /* draw the char */
793 video_putchar(console_col * VIDEO_FONT_WIDTH,
794 console_row * VIDEO_FONT_HEIGHT, c);
797 /* check for newline */
798 if (console_col >= CONSOLE_COLS) {
804 if (console_cursor_is_visible())
808 static void cfb_video_putc(struct stdio_dev *dev, const char c)
810 #ifdef CONFIG_CFB_CONSOLE_ANSI
814 for (i = 0; i < ansi_buf_size; ++i)
815 parse_putc(ansi_buf[i]);
821 if (ansi_buf_size > 0) {
841 ansi_buf[ansi_buf_size++] = c;
843 if (ansi_buf_size >= sizeof(ansi_buf))
846 for (i = 0; i < ansi_buf_size; ++i) {
852 if (ansi_buf[i] == 27)
859 if (ansi_buf[i] == '[')
866 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
867 num1 = ansi_buf[i]-'0';
869 } else if (ansi_buf[i] != '?') {
877 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
879 num1 += ansi_buf[i]-'0';
887 if (ansi_buf[i] != ';') {
895 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
896 num2 = ansi_buf[i]-'0';
903 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
905 num2 += ansi_buf[i]-'0';
913 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
914 || ansi_buf[i] == 'J'
915 || ansi_buf[i] == 'K'
916 || ansi_buf[i] == 'h'
917 || ansi_buf[i] == 'l'
918 || ansi_buf[i] == 'm') {
928 for (i = 0; i < ansi_buf_size; ++i)
929 parse_putc(ansi_buf[i]);
935 if (!ansi_cursor_hidden)
940 /* move cursor num1 rows up */
941 console_cursor_up(num1);
944 /* move cursor num1 rows down */
945 console_cursor_down(num1);
948 /* move cursor num1 columns forward */
949 console_cursor_right(num1);
952 /* move cursor num1 columns back */
953 console_cursor_left(num1);
956 /* move cursor num1 rows up at begin of row */
957 console_previousline(num1);
960 /* move cursor num1 rows down at begin of row */
961 console_newline(num1);
964 /* move cursor to column num1 */
965 console_cursor_set_position(-1, num1-1);
968 /* move cursor to row num1, column num2 */
969 console_cursor_set_position(num1-1, num2-1);
972 /* clear console and move cursor to 0, 0 */
974 console_cursor_set_position(0, 0);
979 console_clear_line(console_row,
983 console_clear_line(console_row,
986 console_clear_line(console_row,
990 ansi_cursor_hidden = 0;
993 ansi_cursor_hidden = 1;
996 if (num1 == 0) { /* reset swapped colors */
997 if (ansi_colors_need_revert) {
998 console_swap_colors();
999 ansi_colors_need_revert = 0;
1001 } else if (num1 == 7) { /* once swap colors */
1002 if (!ansi_colors_need_revert) {
1003 console_swap_colors();
1004 ansi_colors_need_revert = 1;
1009 if (!ansi_cursor_hidden)
1018 if (cfb_do_flush_cache)
1019 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1022 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1024 int flush = cfb_do_flush_cache;
1025 int count = strlen(s);
1027 /* temporarily disable cache flush */
1028 cfb_do_flush_cache = 0;
1031 cfb_video_putc(dev, *s++);
1034 cfb_do_flush_cache = flush;
1035 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1040 * Do not enforce drivers (or board code) to provide empty
1041 * video_set_lut() if they do not support 8 bpp format.
1042 * Implement weak default function instead.
1044 __weak void video_set_lut(unsigned int index, unsigned char r,
1045 unsigned char g, unsigned char b)
1049 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1051 #define FILL_8BIT_332RGB(r,g,b) { \
1052 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1056 #define FILL_15BIT_555RGB(r,g,b) { \
1057 *(unsigned short *)fb = \
1058 SWAP16((unsigned short)(((r>>3)<<10) | \
1064 #define FILL_16BIT_565RGB(r,g,b) { \
1065 *(unsigned short *)fb = \
1066 SWAP16((unsigned short)((((r)>>3)<<11)| \
1072 #define FILL_32BIT_X888RGB(r,g,b) { \
1074 SWAP32((unsigned int)(((r<<16) | \
1080 #ifdef VIDEO_FB_LITTLE_ENDIAN
1081 #define FILL_24BIT_888RGB(r,g,b) { \
1088 #define FILL_24BIT_888RGB(r,g,b) { \
1096 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1097 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1099 ushort *dst = (ushort *) fb;
1100 ushort color = (ushort) (((r >> 3) << 10) |
1111 * RLE8 bitmap support
1114 #ifdef CONFIG_VIDEO_BMP_RLE8
1115 /* Pre-calculated color table entry */
1118 unsigned short w; /* word */
1119 unsigned int dw; /* double word */
1120 } ce; /* color entry */
1124 * Helper to draw encoded/unencoded run.
1126 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1129 ulong addr = (ulong) *fb;
1135 * Setup offset of the color index in the bitmap.
1136 * Color index of encoded run is at offset 1.
1138 off = enc ? &enc_off : &i;
1140 switch (VIDEO_DATA_FORMAT) {
1141 case GDF__8BIT_INDEX:
1142 for (i = 0; i < cnt; i++)
1143 *(unsigned char *) addr++ = bm[*off];
1145 case GDF_15BIT_555RGB:
1146 case GDF_16BIT_565RGB:
1147 /* differences handled while pre-calculating palette */
1148 for (i = 0; i < cnt; i++) {
1149 *(unsigned short *) addr = p[bm[*off]].ce.w;
1153 case GDF_32BIT_X888RGB:
1154 for (i = 0; i < cnt; i++) {
1155 *(u32 *) addr = p[bm[*off]].ce.dw;
1160 *fb = (uchar *) addr; /* return modified address */
1163 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1164 int width, int height)
1168 unsigned int cnt, runlen;
1170 int x, y, bpp, i, ncolors;
1171 struct palette p[256];
1172 struct bmp_color_table_entry cte;
1173 int green_shift, red_off;
1174 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1178 y = __le32_to_cpu(img->header.height) - 1;
1179 ncolors = __le32_to_cpu(img->header.colors_used);
1180 bpp = VIDEO_PIXEL_SIZE;
1181 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1182 (y + yoff) * VIDEO_LINE_LEN +
1185 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1187 /* pre-calculate and setup palette */
1188 switch (VIDEO_DATA_FORMAT) {
1189 case GDF__8BIT_INDEX:
1190 for (i = 0; i < ncolors; i++) {
1191 cte = img->color_table[i];
1192 video_set_lut(i, cte.red, cte.green, cte.blue);
1195 case GDF_15BIT_555RGB:
1196 case GDF_16BIT_565RGB:
1197 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1204 for (i = 0; i < ncolors; i++) {
1205 cte = img->color_table[i];
1206 p[i].ce.w = SWAP16((unsigned short)
1207 (((cte.red >> 3) << red_off) |
1208 ((cte.green >> green_shift) << 5) |
1212 case GDF_32BIT_X888RGB:
1213 for (i = 0; i < ncolors; i++) {
1214 cte = img->color_table[i];
1215 p[i].ce.dw = SWAP32((cte.red << 16) |
1221 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1231 /* scan line end marker */
1235 fbp = (unsigned char *)
1236 ((unsigned int) video_fb_address +
1237 (y + yoff) * VIDEO_LINE_LEN +
1241 /* end of bitmap data marker */
1245 /* run offset marker */
1248 fbp = (unsigned char *)
1249 ((unsigned int) video_fb_address +
1250 (y + yoff) * VIDEO_LINE_LEN +
1268 if (x + runlen > width)
1270 draw_bitmap(&fbp, bm, p, cnt, 0);
1276 bm++; /* 0 padding if length is odd */
1287 if (y < height) { /* only draw into visible area */
1293 if (x + runlen > width)
1295 draw_bitmap(&fbp, bm, p, cnt, 1);
1303 if (cfb_do_flush_cache)
1304 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1308 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1314 * Display the BMP file located at address bmp_image.
1316 int video_display_bitmap(ulong bmp_image, int x, int y)
1318 ushort xcount, ycount;
1320 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1323 unsigned long width, height, bpp;
1325 unsigned long compression;
1326 struct bmp_color_table_entry cte;
1328 #ifdef CONFIG_VIDEO_BMP_GZIP
1329 unsigned char *dst = NULL;
1335 if (!((bmp->header.signature[0] == 'B') &&
1336 (bmp->header.signature[1] == 'M'))) {
1338 #ifdef CONFIG_VIDEO_BMP_GZIP
1340 * Could be a gzipped bmp image, try to decrompress...
1342 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1343 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1345 printf("Error: malloc in gunzip failed!\n");
1349 * NB: we need to force offset of +2
1350 * See doc/README.displaying-bmps
1352 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1353 (uchar *) bmp_image,
1355 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1360 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1361 printf("Image could be truncated "
1362 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1366 * Set addr to decompressed image
1368 bmp = (struct bmp_image *)(dst+2);
1370 if (!((bmp->header.signature[0] == 'B') &&
1371 (bmp->header.signature[1] == 'M'))) {
1372 printf("Error: no valid bmp.gz image at %lx\n",
1378 printf("Error: no valid bmp image at %lx\n", bmp_image);
1380 #endif /* CONFIG_VIDEO_BMP_GZIP */
1383 width = le32_to_cpu(bmp->header.width);
1384 height = le32_to_cpu(bmp->header.height);
1385 bpp = le16_to_cpu(bmp->header.bit_count);
1386 colors = le32_to_cpu(bmp->header.colors_used);
1387 compression = le32_to_cpu(bmp->header.compression);
1389 debug("Display-bmp: %ld x %ld with %d colors\n",
1390 width, height, colors);
1392 if (compression != BMP_BI_RGB
1393 #ifdef CONFIG_VIDEO_BMP_RLE8
1394 && compression != BMP_BI_RLE8
1397 printf("Error: compression type %ld not supported\n",
1399 #ifdef CONFIG_VIDEO_BMP_GZIP
1406 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1408 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1409 if (x == BMP_ALIGN_CENTER)
1410 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1412 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1414 if (y == BMP_ALIGN_CENTER)
1415 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1417 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1418 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1421 * Just ignore elements which are completely beyond screen
1424 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1427 if ((x + width) > VIDEO_VISIBLE_COLS)
1428 width = VIDEO_VISIBLE_COLS - x;
1429 if ((y + height) > VIDEO_VISIBLE_ROWS)
1430 height = VIDEO_VISIBLE_ROWS - y;
1432 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1433 fb = (uchar *) (video_fb_address +
1434 ((y + height - 1) * VIDEO_LINE_LEN) +
1435 x * VIDEO_PIXEL_SIZE);
1437 #ifdef CONFIG_VIDEO_BMP_RLE8
1438 if (compression == BMP_BI_RLE8) {
1439 return display_rle8_bitmap(bmp, x, y, width, height);
1443 /* We handle only 4, 8, or 24 bpp bitmaps */
1444 switch (le16_to_cpu(bmp->header.bit_count)) {
1446 padded_line -= width / 2;
1449 switch (VIDEO_DATA_FORMAT) {
1450 case GDF_32BIT_X888RGB:
1454 * Don't assume that 'width' is an
1457 for (xcount = 0; xcount < width; xcount++) {
1465 cte = bmp->color_table[idx];
1466 FILL_32BIT_X888RGB(cte.red, cte.green,
1469 bmap += padded_line;
1470 fb -= VIDEO_LINE_LEN + width *
1475 puts("4bpp bitmap unsupported with current "
1482 padded_line -= width;
1483 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1485 for (xcount = 0; xcount < colors; ++xcount) {
1486 cte = bmp->color_table[xcount];
1487 video_set_lut(xcount, cte.red, cte.green,
1492 switch (VIDEO_DATA_FORMAT) {
1493 case GDF__8BIT_INDEX:
1500 bmap += padded_line;
1501 fb -= VIDEO_LINE_LEN + width *
1505 case GDF__8BIT_332RGB:
1510 cte = bmp->color_table[*bmap++];
1511 FILL_8BIT_332RGB(cte.red, cte.green,
1514 bmap += padded_line;
1515 fb -= VIDEO_LINE_LEN + width *
1519 case GDF_15BIT_555RGB:
1521 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1527 cte = bmp->color_table[*bmap++];
1528 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1529 fill_555rgb_pswap(fb, xpos++, cte.red,
1534 FILL_15BIT_555RGB(cte.red, cte.green,
1538 bmap += padded_line;
1539 fb -= VIDEO_LINE_LEN + width *
1543 case GDF_16BIT_565RGB:
1548 cte = bmp->color_table[*bmap++];
1549 FILL_16BIT_565RGB(cte.red, cte.green,
1552 bmap += padded_line;
1553 fb -= VIDEO_LINE_LEN + width *
1557 case GDF_32BIT_X888RGB:
1562 cte = bmp->color_table[*bmap++];
1563 FILL_32BIT_X888RGB(cte.red, cte.green,
1566 bmap += padded_line;
1567 fb -= VIDEO_LINE_LEN + width *
1571 case GDF_24BIT_888RGB:
1576 cte = bmp->color_table[*bmap++];
1577 FILL_24BIT_888RGB(cte.red, cte.green,
1580 bmap += padded_line;
1581 fb -= VIDEO_LINE_LEN + width *
1588 padded_line -= 3 * width;
1590 switch (VIDEO_DATA_FORMAT) {
1591 case GDF__8BIT_332RGB:
1596 FILL_8BIT_332RGB(bmap[2], bmap[1],
1600 bmap += padded_line;
1601 fb -= VIDEO_LINE_LEN + width *
1605 case GDF_15BIT_555RGB:
1607 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1613 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1614 fill_555rgb_pswap(fb, xpos++, bmap[2],
1618 FILL_15BIT_555RGB(bmap[2], bmap[1],
1623 bmap += padded_line;
1624 fb -= VIDEO_LINE_LEN + width *
1628 case GDF_16BIT_565RGB:
1633 FILL_16BIT_565RGB(bmap[2], bmap[1],
1637 bmap += padded_line;
1638 fb -= VIDEO_LINE_LEN + width *
1642 case GDF_32BIT_X888RGB:
1647 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1651 bmap += padded_line;
1652 fb -= VIDEO_LINE_LEN + width *
1656 case GDF_24BIT_888RGB:
1661 FILL_24BIT_888RGB(bmap[2], bmap[1],
1665 bmap += padded_line;
1666 fb -= VIDEO_LINE_LEN + width *
1671 printf("Error: 24 bits/pixel bitmap incompatible "
1672 "with current video mode\n");
1677 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1678 le16_to_cpu(bmp->header.bit_count));
1682 #ifdef CONFIG_VIDEO_BMP_GZIP
1688 if (cfb_do_flush_cache)
1689 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1695 #ifdef CONFIG_VIDEO_LOGO
1696 static int video_logo_xpos;
1697 static int video_logo_ypos;
1699 static void plot_logo_or_black(void *screen, int x, int y, int black);
1701 static void logo_plot(void *screen, int x, int y)
1703 plot_logo_or_black(screen, x, y, 0);
1706 static void logo_black(void)
1708 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1712 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1715 return cmd_usage(cmdtp);
1722 clrlogo, 1, 0, do_clrlogo,
1723 "fill the boot logo area with black",
1727 static void plot_logo_or_black(void *screen, int x, int y, int black)
1731 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1732 int ycount = video_logo_height;
1733 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1734 unsigned char *source;
1735 unsigned char *dest;
1737 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1738 if (x == BMP_ALIGN_CENTER)
1739 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1741 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1743 if (y == BMP_ALIGN_CENTER)
1744 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1746 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1747 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1749 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1751 #ifdef CONFIG_VIDEO_BMP_LOGO
1752 source = bmp_logo_bitmap;
1754 /* Allocate temporary space for computing colormap */
1755 logo_red = malloc(BMP_LOGO_COLORS);
1756 logo_green = malloc(BMP_LOGO_COLORS);
1757 logo_blue = malloc(BMP_LOGO_COLORS);
1758 /* Compute color map */
1759 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1760 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1761 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1762 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1765 source = linux_logo;
1766 logo_red = linux_logo_red;
1767 logo_green = linux_logo_green;
1768 logo_blue = linux_logo_blue;
1771 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1772 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1773 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1774 logo_red[i], logo_green[i],
1780 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1783 xcount = VIDEO_LOGO_WIDTH;
1790 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1791 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1792 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1795 switch (VIDEO_DATA_FORMAT) {
1796 case GDF__8BIT_INDEX:
1799 case GDF__8BIT_332RGB:
1800 *dest = ((r >> 5) << 5) |
1804 case GDF_15BIT_555RGB:
1805 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1806 fill_555rgb_pswap(dest, xpos++, r, g, b);
1808 *(unsigned short *) dest =
1809 SWAP16((unsigned short) (
1815 case GDF_16BIT_565RGB:
1816 *(unsigned short *) dest =
1817 SWAP16((unsigned short) (
1822 case GDF_32BIT_X888RGB:
1829 case GDF_24BIT_888RGB:
1830 #ifdef VIDEO_FB_LITTLE_ENDIAN
1842 dest += VIDEO_PIXEL_SIZE;
1846 #ifdef CONFIG_VIDEO_BMP_LOGO
1853 static void *video_logo(void)
1856 __maybe_unused int y_off = 0;
1857 __maybe_unused ulong addr;
1858 __maybe_unused char *s;
1859 __maybe_unused int len, ret, space;
1861 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1863 #ifdef CONFIG_SPLASH_SCREEN
1864 s = env_get("splashimage");
1866 ret = splash_screen_prepare();
1868 return video_fb_address;
1869 addr = simple_strtoul(s, NULL, 16);
1871 if (video_display_bitmap(addr,
1873 video_logo_ypos) == 0) {
1874 video_logo_height = 0;
1875 return ((void *) (video_fb_address));
1878 #endif /* CONFIG_SPLASH_SCREEN */
1880 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1882 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1884 * when using splashpos for video_logo, skip any info
1885 * output on video console if the logo is not at 0,0
1887 if (video_logo_xpos || video_logo_ypos) {
1889 * video_logo_height is used in text and cursor offset
1890 * calculations. Since the console is below the logo,
1891 * we need to adjust the logo height
1893 if (video_logo_ypos == BMP_ALIGN_CENTER)
1894 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1895 VIDEO_LOGO_HEIGHT) / 2);
1896 else if (video_logo_ypos > 0)
1897 video_logo_height += video_logo_ypos;
1899 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1902 if (board_cfb_skip())
1905 sprintf(info, " %s", version_string);
1907 #ifndef CONFIG_HIDE_LOGO_VERSION
1908 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1912 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1913 uchar *p = (uchar *) info;
1917 video_drawchars(xx, yy, p, space);
1920 p = (uchar *)p + space;
1923 xx += VIDEO_FONT_WIDTH;
1926 yy += VIDEO_FONT_HEIGHT;
1930 video_drawchars(xx, yy, p, len);
1935 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1937 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1940 ((video_logo_height -
1941 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1943 for (i = 1; i < n; i++) {
1944 video_get_info_str(i, info);
1950 video_drawchars(VIDEO_INFO_X,
1954 (uchar *) info, space);
1956 video_drawchars(VIDEO_INFO_X +
1961 (uchar *) info + space,
1964 video_drawstring(VIDEO_INFO_X,
1975 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1979 static int cfb_fb_is_in_dram(void)
1982 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
1983 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1987 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1988 start = bd->bi_dram[i].start;
1989 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1990 if ((ulong)video_fb_address >= start &&
1991 (ulong)video_fb_address < end)
1995 if ((ulong)video_fb_address >= bd->bi_memstart &&
1996 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2002 void video_clear(void)
2004 if (!video_fb_address)
2006 #ifdef VIDEO_HW_RECTFILL
2007 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2010 VIDEO_VISIBLE_COLS, /* frame width */
2011 VIDEO_VISIBLE_ROWS, /* frame height */
2012 bgx /* fill color */
2015 memsetl(video_fb_address,
2016 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2020 static int cfg_video_init(void)
2022 unsigned char color8;
2024 pGD = video_hw_init();
2028 video_fb_address = (void *) VIDEO_FB_ADRS;
2030 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2032 /* Init drawing pats */
2033 switch (VIDEO_DATA_FORMAT) {
2034 case GDF__8BIT_INDEX:
2035 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2036 CONFIG_SYS_CONSOLE_FG_COL,
2037 CONFIG_SYS_CONSOLE_FG_COL);
2038 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2039 CONFIG_SYS_CONSOLE_BG_COL,
2040 CONFIG_SYS_CONSOLE_BG_COL);
2044 case GDF__8BIT_332RGB:
2045 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2046 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2047 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2048 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2050 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2051 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2052 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2053 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2056 case GDF_15BIT_555RGB:
2057 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2058 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2059 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2061 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2062 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2063 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2064 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2065 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2067 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2068 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2070 case GDF_16BIT_565RGB:
2071 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2072 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2073 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2074 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2075 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2076 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2077 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2078 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2079 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2080 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2081 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2082 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2084 case GDF_32BIT_X888RGB:
2085 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2086 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2087 CONFIG_SYS_CONSOLE_FG_COL;
2088 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2089 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2090 CONFIG_SYS_CONSOLE_BG_COL;
2092 case GDF_24BIT_888RGB:
2093 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2094 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2095 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2096 CONFIG_SYS_CONSOLE_FG_COL;
2097 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2098 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2099 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2100 CONFIG_SYS_CONSOLE_BG_COL;
2105 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2108 #ifdef CONFIG_VIDEO_LOGO
2109 /* Plot the logo and get start point of console */
2110 debug("Video: Drawing the logo ...\n");
2111 video_console_address = video_logo();
2113 video_console_address = video_fb_address;
2116 /* Initialize the console */
2120 if (cfb_do_flush_cache)
2121 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2127 * Implement a weak default function for boards that optionally
2128 * need to skip the video initialization.
2130 __weak int board_video_skip(void)
2132 /* As default, don't skip test */
2136 int drv_video_init(void)
2138 struct stdio_dev console_dev;
2140 bool __maybe_unused keyboard_ok = false;
2142 /* Check if video initialization should be skipped */
2143 if (board_video_skip())
2146 /* Init video chip - returns with framebuffer cleared */
2147 if (cfg_video_init() == -1)
2150 if (board_cfb_skip())
2153 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2154 have_keyboard = false;
2155 #elif defined(CONFIG_OF_CONTROL)
2156 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2157 "u-boot,no-keyboard");
2159 have_keyboard = true;
2161 if (have_keyboard) {
2162 debug("KBD: Keyboard init ...\n");
2163 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2164 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2168 /* Init vga device */
2169 memset(&console_dev, 0, sizeof(console_dev));
2170 strcpy(console_dev.name, "vga");
2171 console_dev.flags = DEV_FLAGS_OUTPUT;
2172 console_dev.putc = cfb_video_putc; /* 'putc' function */
2173 console_dev.puts = cfb_video_puts; /* 'puts' function */
2175 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2176 if (have_keyboard && keyboard_ok) {
2177 /* Also init console device */
2178 console_dev.flags |= DEV_FLAGS_INPUT;
2179 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2180 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2184 if (stdio_register(&console_dev) != 0)
2187 /* Return success */
2191 void video_position_cursor(unsigned col, unsigned row)
2193 console_col = min(col, CONSOLE_COLS - 1);
2194 console_row = min(row, CONSOLE_ROWS - 1);
2197 int video_get_pixel_width(void)
2199 return VIDEO_VISIBLE_COLS;
2202 int video_get_pixel_height(void)
2204 return VIDEO_VISIBLE_ROWS;
2207 int video_get_screen_rows(void)
2209 return CONSOLE_ROWS;
2212 int video_get_screen_columns(void)
2214 return CONSOLE_COLS;