1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2002 ELTEC Elektronik AG
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 <linux/compiler.h>
79 #if defined(CONFIG_VIDEO_MXS)
80 #define VIDEO_FB_16BPP_WORD_SWAP
84 * Defines for the MB862xx driver
86 #ifdef CONFIG_VIDEO_MB862xx
88 #ifdef CONFIG_VIDEO_CORALP
89 #define VIDEO_FB_LITTLE_ENDIAN
91 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
92 #define VIDEO_HW_RECTFILL
93 #define VIDEO_HW_BITBLT
98 * Defines for the i.MX31 driver (mx3fb.c)
100 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
101 #define VIDEO_FB_16BPP_WORD_SWAP
105 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
107 #include <video_fb.h>
114 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
115 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
116 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
117 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
118 #define VIDEO_FB_ADRS (pGD->frameAdrs)
125 #include <linux/types.h>
126 #include <stdio_dev.h>
127 #include <video_font.h>
129 #if defined(CONFIG_CMD_DATE)
133 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
134 #include <watchdog.h>
135 #include <bmp_layout.h>
139 #if !defined(CONFIG_VIDEO_SW_CURSOR)
140 /* no Cursor defined */
146 #if defined(CONFIG_VIDEO_SW_CURSOR)
147 void console_cursor(int state);
149 #define CURSOR_ON console_cursor(1)
150 #define CURSOR_OFF console_cursor(0)
151 #define CURSOR_SET video_set_cursor()
152 #endif /* CONFIG_VIDEO_SW_CURSOR */
154 #ifdef CONFIG_VIDEO_LOGO
155 #ifdef CONFIG_VIDEO_BMP_LOGO
156 #include <bmp_logo.h>
157 #include <bmp_logo_data.h>
158 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
159 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
160 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
161 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
163 #else /* CONFIG_VIDEO_BMP_LOGO */
164 #define LINUX_LOGO_WIDTH 80
165 #define LINUX_LOGO_HEIGHT 80
166 #define LINUX_LOGO_COLORS 214
167 #define LINUX_LOGO_LUT_OFFSET 0x20
169 #include <linux_logo.h>
170 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
171 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
172 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
173 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
174 #endif /* CONFIG_VIDEO_BMP_LOGO */
175 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
176 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
177 #else /* CONFIG_VIDEO_LOGO */
178 #define VIDEO_LOGO_WIDTH 0
179 #define VIDEO_LOGO_HEIGHT 0
180 #endif /* CONFIG_VIDEO_LOGO */
182 #define VIDEO_COLS VIDEO_VISIBLE_COLS
183 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
184 #ifndef VIDEO_LINE_LEN
185 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
187 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
188 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
190 #ifdef CONFIG_VIDEO_LOGO
191 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
193 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
196 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
197 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
198 #define CONSOLE_ROW_FIRST (video_console_address)
199 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
200 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
201 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
203 /* By default we scroll by a single line */
204 #ifndef CONFIG_CONSOLE_SCROLL_LINES
205 #define CONFIG_CONSOLE_SCROLL_LINES 1
209 #ifdef VIDEO_FB_LITTLE_ENDIAN
210 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
213 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
214 (((x) & 0x0000ff00) << 8) | \
215 (((x) & 0x00ff0000) >> 8) | \
216 (((x) & 0xff000000) >> 24) \
218 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
219 (((x) & 0x0000ff00) >> 8) | \
220 (((x) & 0x00ff0000) << 8) | \
221 (((x) & 0xff000000) >> 8) \
224 #define SWAP16(x) (x)
225 #define SWAP32(x) (x)
226 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
227 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
229 #define SHORTSWAP32(x) (x)
233 DECLARE_GLOBAL_DATA_PTR;
236 static GraphicDevice *pGD; /* Pointer to Graphic array */
238 static void *video_fb_address; /* frame buffer address */
239 static void *video_console_address; /* console buffer start address */
241 static int video_logo_height = VIDEO_LOGO_HEIGHT;
243 static int __maybe_unused cursor_state;
244 static int __maybe_unused old_col;
245 static int __maybe_unused old_row;
247 static int console_col; /* cursor col */
248 static int console_row; /* cursor row */
250 static u32 eorx, fgx, bgx; /* color pats */
252 static int cfb_do_flush_cache;
254 #ifdef CONFIG_CFB_CONSOLE_ANSI
255 static char ansi_buf[10];
256 static int ansi_buf_size;
257 static int ansi_colors_need_revert;
258 static int ansi_cursor_hidden;
261 static const int video_font_draw_table8[] = {
262 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
263 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
264 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
265 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
268 static const int video_font_draw_table15[] = {
269 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
272 static const int video_font_draw_table16[] = {
273 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
276 static const int video_font_draw_table24[16][3] = {
277 {0x00000000, 0x00000000, 0x00000000},
278 {0x00000000, 0x00000000, 0x00ffffff},
279 {0x00000000, 0x0000ffff, 0xff000000},
280 {0x00000000, 0x0000ffff, 0xffffffff},
281 {0x000000ff, 0xffff0000, 0x00000000},
282 {0x000000ff, 0xffff0000, 0x00ffffff},
283 {0x000000ff, 0xffffffff, 0xff000000},
284 {0x000000ff, 0xffffffff, 0xffffffff},
285 {0xffffff00, 0x00000000, 0x00000000},
286 {0xffffff00, 0x00000000, 0x00ffffff},
287 {0xffffff00, 0x0000ffff, 0xff000000},
288 {0xffffff00, 0x0000ffff, 0xffffffff},
289 {0xffffffff, 0xffff0000, 0x00000000},
290 {0xffffffff, 0xffff0000, 0x00ffffff},
291 {0xffffffff, 0xffffffff, 0xff000000},
292 {0xffffffff, 0xffffffff, 0xffffffff}
295 static const int video_font_draw_table32[16][4] = {
296 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
297 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
298 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
299 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
300 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
301 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
302 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
303 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
304 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
305 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
306 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
307 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
308 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
309 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
310 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
311 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
315 * Implement a weak default function for boards that optionally
316 * need to skip the cfb initialization.
318 __weak int board_cfb_skip(void)
320 /* As default, don't skip cfb init */
324 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
326 u8 *cdat, *dest, *dest0;
329 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
330 dest0 = video_fb_address + offset;
332 switch (VIDEO_DATA_FORMAT) {
333 case GDF__8BIT_INDEX:
334 case GDF__8BIT_332RGB:
337 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
338 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
339 rows--; dest += VIDEO_LINE_LEN) {
343 (video_font_draw_table8[bits >> 4] &
346 if (VIDEO_FONT_WIDTH == 4)
350 (video_font_draw_table8[bits & 15] &
353 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
358 case GDF_15BIT_555RGB:
361 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
362 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
363 rows--; dest += VIDEO_LINE_LEN) {
367 SHORTSWAP32((video_font_draw_table15
368 [bits >> 6] & eorx) ^
371 SHORTSWAP32((video_font_draw_table15
372 [bits >> 4 & 3] & eorx) ^
375 if (VIDEO_FONT_WIDTH == 4)
379 SHORTSWAP32((video_font_draw_table15
380 [bits >> 2 & 3] & eorx) ^
383 SHORTSWAP32((video_font_draw_table15
387 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
392 case GDF_16BIT_565RGB:
395 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
396 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
397 rows--; dest += VIDEO_LINE_LEN) {
401 SHORTSWAP32((video_font_draw_table16
402 [bits >> 6] & eorx) ^
405 SHORTSWAP32((video_font_draw_table16
406 [bits >> 4 & 3] & eorx) ^
409 if (VIDEO_FONT_WIDTH == 4)
413 SHORTSWAP32((video_font_draw_table16
414 [bits >> 2 & 3] & eorx) ^
417 SHORTSWAP32((video_font_draw_table16
421 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
426 case GDF_32BIT_X888RGB:
429 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
430 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
431 rows--; dest += VIDEO_LINE_LEN) {
435 SWAP32((video_font_draw_table32
436 [bits >> 4][0] & eorx) ^ bgx);
438 SWAP32((video_font_draw_table32
439 [bits >> 4][1] & eorx) ^ bgx);
441 SWAP32((video_font_draw_table32
442 [bits >> 4][2] & eorx) ^ bgx);
444 SWAP32((video_font_draw_table32
445 [bits >> 4][3] & eorx) ^ bgx);
448 if (VIDEO_FONT_WIDTH == 4)
452 SWAP32((video_font_draw_table32
453 [bits & 15][0] & eorx) ^ bgx);
455 SWAP32((video_font_draw_table32
456 [bits & 15][1] & eorx) ^ bgx);
458 SWAP32((video_font_draw_table32
459 [bits & 15][2] & eorx) ^ bgx);
461 SWAP32((video_font_draw_table32
462 [bits & 15][3] & eorx) ^ bgx);
464 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
469 case GDF_24BIT_888RGB:
472 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
473 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
474 rows--; dest += VIDEO_LINE_LEN) {
478 (video_font_draw_table24[bits >> 4][0]
481 (video_font_draw_table24[bits >> 4][1]
484 (video_font_draw_table24[bits >> 4][2]
487 if (VIDEO_FONT_WIDTH == 4)
491 (video_font_draw_table24[bits & 15][0]
494 (video_font_draw_table24[bits & 15][1]
497 (video_font_draw_table24[bits & 15][2]
500 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
507 static inline void video_drawstring(int xx, int yy, unsigned char *s)
509 video_drawchars(xx, yy, s, strlen((char *) s));
512 static void video_putchar(int xx, int yy, unsigned char c)
514 video_drawchars(xx, yy + video_logo_height, &c, 1);
517 #if defined(CONFIG_VIDEO_SW_CURSOR)
518 static void video_set_cursor(void)
525 static void video_invertchar(int xx, int yy)
527 int firstx = xx * VIDEO_PIXEL_SIZE;
528 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
529 int firsty = yy * VIDEO_LINE_LEN;
530 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
532 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
533 for (x = firstx; x < lastx; x++) {
534 u8 *dest = (u8 *)(video_fb_address) + x + y;
540 void console_cursor(int state)
542 if (cursor_state != state) {
544 /* turn off the cursor */
545 video_invertchar(old_col * VIDEO_FONT_WIDTH,
546 old_row * VIDEO_FONT_HEIGHT +
549 /* turn off the cursor and record where it is */
550 video_invertchar(console_col * VIDEO_FONT_WIDTH,
551 console_row * VIDEO_FONT_HEIGHT +
553 old_col = console_col;
554 old_row = console_row;
556 cursor_state = state;
558 if (cfb_do_flush_cache)
559 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
563 #ifndef VIDEO_HW_RECTFILL
564 static void memsetl(int *p, int c, int v)
571 #ifndef VIDEO_HW_BITBLT
572 static void memcpyl(int *d, int *s, int c)
579 static void console_clear_line(int line, int begin, int end)
581 #ifdef VIDEO_HW_RECTFILL
582 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
583 VIDEO_FONT_WIDTH * begin, /* dest pos x */
585 VIDEO_FONT_HEIGHT * line, /* dest pos y */
586 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
587 VIDEO_FONT_HEIGHT, /* frame height */
591 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
592 memsetl(CONSOLE_ROW_FIRST +
593 CONSOLE_ROW_SIZE * line, /* offset of row */
594 CONSOLE_ROW_SIZE >> 2, /* length of row */
601 offset = CONSOLE_ROW_FIRST +
602 CONSOLE_ROW_SIZE * line + /* offset of row */
604 VIDEO_PIXEL_SIZE * begin; /* offset of col */
605 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
606 size >>= 2; /* length to end for memsetl() */
607 /* fill at col offset of i'th line using bgx as fill color */
608 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
609 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
614 static void console_scrollup(void)
616 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
619 /* copy up rows ignoring the first one */
621 #ifdef VIDEO_HW_BITBLT
622 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
623 0, /* source pos x */
625 VIDEO_FONT_HEIGHT * rows, /* source pos y */
627 video_logo_height, /* dest pos y */
628 VIDEO_VISIBLE_COLS, /* frame width */
631 - VIDEO_FONT_HEIGHT * rows /* frame height */
634 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
635 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
637 /* clear the last one */
638 for (i = 1; i <= rows; i++)
639 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
641 /* Decrement row number */
645 static void console_back(void)
649 if (console_col < 0) {
650 console_col = CONSOLE_COLS - 1;
657 #ifdef CONFIG_CFB_CONSOLE_ANSI
659 static void console_clear(void)
661 #ifdef VIDEO_HW_RECTFILL
662 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
664 video_logo_height, /* dest pos y */
665 VIDEO_VISIBLE_COLS, /* frame width */
666 VIDEO_VISIBLE_ROWS, /* frame height */
670 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
674 static void console_cursor_fix(void)
678 if (console_row >= CONSOLE_ROWS)
679 console_row = CONSOLE_ROWS - 1;
682 if (console_col >= CONSOLE_COLS)
683 console_col = CONSOLE_COLS - 1;
686 static void console_cursor_up(int n)
689 console_cursor_fix();
692 static void console_cursor_down(int n)
695 console_cursor_fix();
698 static void console_cursor_left(int n)
701 console_cursor_fix();
704 static void console_cursor_right(int n)
707 console_cursor_fix();
710 static void console_cursor_set_position(int row, int col)
712 if (console_row != -1)
714 if (console_col != -1)
716 console_cursor_fix();
719 static void console_previousline(int n)
721 /* FIXME: also scroll terminal ? */
723 console_cursor_fix();
726 static void console_swap_colors(void)
734 static inline int console_cursor_is_visible(void)
736 return !ansi_cursor_hidden;
739 static inline int console_cursor_is_visible(void)
745 static void console_newline(int n)
750 /* Check if we need to scroll the terminal */
751 if (console_row >= CONSOLE_ROWS) {
752 /* Scroll everything up */
757 static void console_cr(void)
762 static void parse_putc(const char c)
766 if (console_cursor_is_visible())
770 case 13: /* back to first column */
774 case '\n': /* next line */
775 if (console_col || nl)
781 console_col |= 0x0008;
782 console_col &= ~0x0007;
784 if (console_col >= CONSOLE_COLS)
788 case 8: /* backspace */
795 default: /* draw the char */
796 video_putchar(console_col * VIDEO_FONT_WIDTH,
797 console_row * VIDEO_FONT_HEIGHT, c);
800 /* check for newline */
801 if (console_col >= CONSOLE_COLS) {
807 if (console_cursor_is_visible())
811 static void cfb_video_putc(struct stdio_dev *dev, const char c)
813 #ifdef CONFIG_CFB_CONSOLE_ANSI
817 for (i = 0; i < ansi_buf_size; ++i)
818 parse_putc(ansi_buf[i]);
824 if (ansi_buf_size > 0) {
844 ansi_buf[ansi_buf_size++] = c;
846 if (ansi_buf_size >= sizeof(ansi_buf))
849 for (i = 0; i < ansi_buf_size; ++i) {
855 if (ansi_buf[i] == 27)
862 if (ansi_buf[i] == '[')
869 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
870 num1 = ansi_buf[i]-'0';
872 } else if (ansi_buf[i] != '?') {
880 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
882 num1 += ansi_buf[i]-'0';
890 if (ansi_buf[i] != ';') {
898 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
899 num2 = ansi_buf[i]-'0';
906 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
908 num2 += ansi_buf[i]-'0';
916 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
917 || ansi_buf[i] == 'J'
918 || ansi_buf[i] == 'K'
919 || ansi_buf[i] == 'h'
920 || ansi_buf[i] == 'l'
921 || ansi_buf[i] == 'm') {
931 for (i = 0; i < ansi_buf_size; ++i)
932 parse_putc(ansi_buf[i]);
938 if (!ansi_cursor_hidden)
943 /* move cursor num1 rows up */
944 console_cursor_up(num1);
947 /* move cursor num1 rows down */
948 console_cursor_down(num1);
951 /* move cursor num1 columns forward */
952 console_cursor_right(num1);
955 /* move cursor num1 columns back */
956 console_cursor_left(num1);
959 /* move cursor num1 rows up at begin of row */
960 console_previousline(num1);
963 /* move cursor num1 rows down at begin of row */
964 console_newline(num1);
967 /* move cursor to column num1 */
968 console_cursor_set_position(-1, num1-1);
971 /* move cursor to row num1, column num2 */
972 console_cursor_set_position(num1-1, num2-1);
975 /* clear console and move cursor to 0, 0 */
977 console_cursor_set_position(0, 0);
982 console_clear_line(console_row,
986 console_clear_line(console_row,
989 console_clear_line(console_row,
993 ansi_cursor_hidden = 0;
996 ansi_cursor_hidden = 1;
999 if (num1 == 0) { /* reset swapped colors */
1000 if (ansi_colors_need_revert) {
1001 console_swap_colors();
1002 ansi_colors_need_revert = 0;
1004 } else if (num1 == 7) { /* once swap colors */
1005 if (!ansi_colors_need_revert) {
1006 console_swap_colors();
1007 ansi_colors_need_revert = 1;
1012 if (!ansi_cursor_hidden)
1021 if (cfb_do_flush_cache)
1022 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1025 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1027 int flush = cfb_do_flush_cache;
1028 int count = strlen(s);
1030 /* temporarily disable cache flush */
1031 cfb_do_flush_cache = 0;
1034 cfb_video_putc(dev, *s++);
1037 cfb_do_flush_cache = flush;
1038 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1043 * Do not enforce drivers (or board code) to provide empty
1044 * video_set_lut() if they do not support 8 bpp format.
1045 * Implement weak default function instead.
1047 __weak void video_set_lut(unsigned int index, unsigned char r,
1048 unsigned char g, unsigned char b)
1052 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1054 #define FILL_8BIT_332RGB(r,g,b) { \
1055 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1059 #define FILL_15BIT_555RGB(r,g,b) { \
1060 *(unsigned short *)fb = \
1061 SWAP16((unsigned short)(((r>>3)<<10) | \
1067 #define FILL_16BIT_565RGB(r,g,b) { \
1068 *(unsigned short *)fb = \
1069 SWAP16((unsigned short)((((r)>>3)<<11)| \
1075 #define FILL_32BIT_X888RGB(r,g,b) { \
1077 SWAP32((unsigned int)(((r<<16) | \
1083 #ifdef VIDEO_FB_LITTLE_ENDIAN
1084 #define FILL_24BIT_888RGB(r,g,b) { \
1091 #define FILL_24BIT_888RGB(r,g,b) { \
1099 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1100 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1102 ushort *dst = (ushort *) fb;
1103 ushort color = (ushort) (((r >> 3) << 10) |
1114 * RLE8 bitmap support
1117 #ifdef CONFIG_VIDEO_BMP_RLE8
1118 /* Pre-calculated color table entry */
1121 unsigned short w; /* word */
1122 unsigned int dw; /* double word */
1123 } ce; /* color entry */
1127 * Helper to draw encoded/unencoded run.
1129 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1132 ulong addr = (ulong) *fb;
1138 * Setup offset of the color index in the bitmap.
1139 * Color index of encoded run is at offset 1.
1141 off = enc ? &enc_off : &i;
1143 switch (VIDEO_DATA_FORMAT) {
1144 case GDF__8BIT_INDEX:
1145 for (i = 0; i < cnt; i++)
1146 *(unsigned char *) addr++ = bm[*off];
1148 case GDF_15BIT_555RGB:
1149 case GDF_16BIT_565RGB:
1150 /* differences handled while pre-calculating palette */
1151 for (i = 0; i < cnt; i++) {
1152 *(unsigned short *) addr = p[bm[*off]].ce.w;
1156 case GDF_32BIT_X888RGB:
1157 for (i = 0; i < cnt; i++) {
1158 *(u32 *) addr = p[bm[*off]].ce.dw;
1163 *fb = (uchar *) addr; /* return modified address */
1166 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1167 int width, int height)
1171 unsigned int cnt, runlen;
1173 int x, y, bpp, i, ncolors;
1174 struct palette p[256];
1175 struct bmp_color_table_entry cte;
1176 int green_shift, red_off;
1177 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1181 y = __le32_to_cpu(img->header.height) - 1;
1182 ncolors = __le32_to_cpu(img->header.colors_used);
1183 bpp = VIDEO_PIXEL_SIZE;
1184 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1185 (y + yoff) * VIDEO_LINE_LEN +
1188 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1190 /* pre-calculate and setup palette */
1191 switch (VIDEO_DATA_FORMAT) {
1192 case GDF__8BIT_INDEX:
1193 for (i = 0; i < ncolors; i++) {
1194 cte = img->color_table[i];
1195 video_set_lut(i, cte.red, cte.green, cte.blue);
1198 case GDF_15BIT_555RGB:
1199 case GDF_16BIT_565RGB:
1200 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1207 for (i = 0; i < ncolors; i++) {
1208 cte = img->color_table[i];
1209 p[i].ce.w = SWAP16((unsigned short)
1210 (((cte.red >> 3) << red_off) |
1211 ((cte.green >> green_shift) << 5) |
1215 case GDF_32BIT_X888RGB:
1216 for (i = 0; i < ncolors; i++) {
1217 cte = img->color_table[i];
1218 p[i].ce.dw = SWAP32((cte.red << 16) |
1224 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1234 /* scan line end marker */
1238 fbp = (unsigned char *)
1239 ((unsigned int) video_fb_address +
1240 (y + yoff) * VIDEO_LINE_LEN +
1244 /* end of bitmap data marker */
1248 /* run offset marker */
1251 fbp = (unsigned char *)
1252 ((unsigned int) video_fb_address +
1253 (y + yoff) * VIDEO_LINE_LEN +
1271 if (x + runlen > width)
1273 draw_bitmap(&fbp, bm, p, cnt, 0);
1279 bm++; /* 0 padding if length is odd */
1290 if (y < height) { /* only draw into visible area */
1296 if (x + runlen > width)
1298 draw_bitmap(&fbp, bm, p, cnt, 1);
1306 if (cfb_do_flush_cache)
1307 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1311 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1317 * Display the BMP file located at address bmp_image.
1319 int video_display_bitmap(ulong bmp_image, int x, int y)
1321 ushort xcount, ycount;
1323 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1326 unsigned long width, height, bpp;
1328 unsigned long compression;
1329 struct bmp_color_table_entry cte;
1331 #ifdef CONFIG_VIDEO_BMP_GZIP
1332 unsigned char *dst = NULL;
1338 if (!((bmp->header.signature[0] == 'B') &&
1339 (bmp->header.signature[1] == 'M'))) {
1341 #ifdef CONFIG_VIDEO_BMP_GZIP
1343 * Could be a gzipped bmp image, try to decrompress...
1345 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1346 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1348 printf("Error: malloc in gunzip failed!\n");
1352 * NB: we need to force offset of +2
1353 * See doc/README.displaying-bmps
1355 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1356 (uchar *) bmp_image,
1358 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1363 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1364 printf("Image could be truncated "
1365 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1369 * Set addr to decompressed image
1371 bmp = (struct bmp_image *)(dst+2);
1373 if (!((bmp->header.signature[0] == 'B') &&
1374 (bmp->header.signature[1] == 'M'))) {
1375 printf("Error: no valid bmp.gz image at %lx\n",
1381 printf("Error: no valid bmp image at %lx\n", bmp_image);
1383 #endif /* CONFIG_VIDEO_BMP_GZIP */
1386 width = le32_to_cpu(bmp->header.width);
1387 height = le32_to_cpu(bmp->header.height);
1388 bpp = le16_to_cpu(bmp->header.bit_count);
1389 colors = le32_to_cpu(bmp->header.colors_used);
1390 compression = le32_to_cpu(bmp->header.compression);
1392 debug("Display-bmp: %ld x %ld with %d colors\n",
1393 width, height, colors);
1395 if (compression != BMP_BI_RGB
1396 #ifdef CONFIG_VIDEO_BMP_RLE8
1397 && compression != BMP_BI_RLE8
1400 printf("Error: compression type %ld not supported\n",
1402 #ifdef CONFIG_VIDEO_BMP_GZIP
1409 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1411 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1412 if (x == BMP_ALIGN_CENTER)
1413 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1415 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1417 if (y == BMP_ALIGN_CENTER)
1418 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1420 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1421 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1424 * Just ignore elements which are completely beyond screen
1427 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1430 if ((x + width) > VIDEO_VISIBLE_COLS)
1431 width = VIDEO_VISIBLE_COLS - x;
1432 if ((y + height) > VIDEO_VISIBLE_ROWS)
1433 height = VIDEO_VISIBLE_ROWS - y;
1435 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1436 fb = (uchar *) (video_fb_address +
1437 ((y + height - 1) * VIDEO_LINE_LEN) +
1438 x * VIDEO_PIXEL_SIZE);
1440 #ifdef CONFIG_VIDEO_BMP_RLE8
1441 if (compression == BMP_BI_RLE8) {
1442 return display_rle8_bitmap(bmp, x, y, width, height);
1446 /* We handle only 4, 8, or 24 bpp bitmaps */
1447 switch (le16_to_cpu(bmp->header.bit_count)) {
1449 padded_line -= width / 2;
1452 switch (VIDEO_DATA_FORMAT) {
1453 case GDF_32BIT_X888RGB:
1457 * Don't assume that 'width' is an
1460 for (xcount = 0; xcount < width; xcount++) {
1468 cte = bmp->color_table[idx];
1469 FILL_32BIT_X888RGB(cte.red, cte.green,
1472 bmap += padded_line;
1473 fb -= VIDEO_LINE_LEN + width *
1478 puts("4bpp bitmap unsupported with current "
1485 padded_line -= width;
1486 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1488 for (xcount = 0; xcount < colors; ++xcount) {
1489 cte = bmp->color_table[xcount];
1490 video_set_lut(xcount, cte.red, cte.green,
1495 switch (VIDEO_DATA_FORMAT) {
1496 case GDF__8BIT_INDEX:
1503 bmap += padded_line;
1504 fb -= VIDEO_LINE_LEN + width *
1508 case GDF__8BIT_332RGB:
1513 cte = bmp->color_table[*bmap++];
1514 FILL_8BIT_332RGB(cte.red, cte.green,
1517 bmap += padded_line;
1518 fb -= VIDEO_LINE_LEN + width *
1522 case GDF_15BIT_555RGB:
1524 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1530 cte = bmp->color_table[*bmap++];
1531 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1532 fill_555rgb_pswap(fb, xpos++, cte.red,
1537 FILL_15BIT_555RGB(cte.red, cte.green,
1541 bmap += padded_line;
1542 fb -= VIDEO_LINE_LEN + width *
1546 case GDF_16BIT_565RGB:
1551 cte = bmp->color_table[*bmap++];
1552 FILL_16BIT_565RGB(cte.red, cte.green,
1555 bmap += padded_line;
1556 fb -= VIDEO_LINE_LEN + width *
1560 case GDF_32BIT_X888RGB:
1565 cte = bmp->color_table[*bmap++];
1566 FILL_32BIT_X888RGB(cte.red, cte.green,
1569 bmap += padded_line;
1570 fb -= VIDEO_LINE_LEN + width *
1574 case GDF_24BIT_888RGB:
1579 cte = bmp->color_table[*bmap++];
1580 FILL_24BIT_888RGB(cte.red, cte.green,
1583 bmap += padded_line;
1584 fb -= VIDEO_LINE_LEN + width *
1591 padded_line -= 3 * width;
1593 switch (VIDEO_DATA_FORMAT) {
1594 case GDF__8BIT_332RGB:
1599 FILL_8BIT_332RGB(bmap[2], bmap[1],
1603 bmap += padded_line;
1604 fb -= VIDEO_LINE_LEN + width *
1608 case GDF_15BIT_555RGB:
1610 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1616 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1617 fill_555rgb_pswap(fb, xpos++, bmap[2],
1621 FILL_15BIT_555RGB(bmap[2], bmap[1],
1626 bmap += padded_line;
1627 fb -= VIDEO_LINE_LEN + width *
1631 case GDF_16BIT_565RGB:
1636 FILL_16BIT_565RGB(bmap[2], bmap[1],
1640 bmap += padded_line;
1641 fb -= VIDEO_LINE_LEN + width *
1645 case GDF_32BIT_X888RGB:
1650 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1654 bmap += padded_line;
1655 fb -= VIDEO_LINE_LEN + width *
1659 case GDF_24BIT_888RGB:
1664 FILL_24BIT_888RGB(bmap[2], bmap[1],
1668 bmap += padded_line;
1669 fb -= VIDEO_LINE_LEN + width *
1674 printf("Error: 24 bits/pixel bitmap incompatible "
1675 "with current video mode\n");
1680 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1681 le16_to_cpu(bmp->header.bit_count));
1685 #ifdef CONFIG_VIDEO_BMP_GZIP
1691 if (cfb_do_flush_cache)
1692 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1698 #ifdef CONFIG_VIDEO_LOGO
1699 static int video_logo_xpos;
1700 static int video_logo_ypos;
1702 static void plot_logo_or_black(void *screen, int x, int y, int black);
1704 static void logo_plot(void *screen, int x, int y)
1706 plot_logo_or_black(screen, x, y, 0);
1709 static void logo_black(void)
1711 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1715 static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1719 return cmd_usage(cmdtp);
1726 clrlogo, 1, 0, do_clrlogo,
1727 "fill the boot logo area with black",
1731 static void plot_logo_or_black(void *screen, int x, int y, int black)
1735 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1736 int ycount = video_logo_height;
1737 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1738 unsigned char *source;
1739 unsigned char *dest;
1741 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1742 if (x == BMP_ALIGN_CENTER)
1743 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1745 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1747 if (y == BMP_ALIGN_CENTER)
1748 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1750 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1751 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1753 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1755 #ifdef CONFIG_VIDEO_BMP_LOGO
1756 source = bmp_logo_bitmap;
1758 /* Allocate temporary space for computing colormap */
1759 logo_red = malloc(BMP_LOGO_COLORS);
1760 logo_green = malloc(BMP_LOGO_COLORS);
1761 logo_blue = malloc(BMP_LOGO_COLORS);
1762 /* Compute color map */
1763 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1764 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1765 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1766 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1769 source = linux_logo;
1770 logo_red = linux_logo_red;
1771 logo_green = linux_logo_green;
1772 logo_blue = linux_logo_blue;
1775 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1776 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1777 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1778 logo_red[i], logo_green[i],
1784 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1787 xcount = VIDEO_LOGO_WIDTH;
1794 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1795 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1796 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1799 switch (VIDEO_DATA_FORMAT) {
1800 case GDF__8BIT_INDEX:
1803 case GDF__8BIT_332RGB:
1804 *dest = ((r >> 5) << 5) |
1808 case GDF_15BIT_555RGB:
1809 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1810 fill_555rgb_pswap(dest, xpos++, r, g, b);
1812 *(unsigned short *) dest =
1813 SWAP16((unsigned short) (
1819 case GDF_16BIT_565RGB:
1820 *(unsigned short *) dest =
1821 SWAP16((unsigned short) (
1826 case GDF_32BIT_X888RGB:
1833 case GDF_24BIT_888RGB:
1834 #ifdef VIDEO_FB_LITTLE_ENDIAN
1846 dest += VIDEO_PIXEL_SIZE;
1850 #ifdef CONFIG_VIDEO_BMP_LOGO
1857 static void *video_logo(void)
1860 __maybe_unused int y_off = 0;
1861 __maybe_unused ulong addr;
1862 __maybe_unused char *s;
1863 __maybe_unused int len, ret, space;
1865 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1867 #ifdef CONFIG_SPLASH_SCREEN
1868 s = env_get("splashimage");
1870 ret = splash_screen_prepare();
1872 return video_fb_address;
1873 addr = simple_strtoul(s, NULL, 16);
1875 if (video_display_bitmap(addr,
1877 video_logo_ypos) == 0) {
1878 video_logo_height = 0;
1879 return ((void *) (video_fb_address));
1882 #endif /* CONFIG_SPLASH_SCREEN */
1884 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1886 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1888 * when using splashpos for video_logo, skip any info
1889 * output on video console if the logo is not at 0,0
1891 if (video_logo_xpos || video_logo_ypos) {
1893 * video_logo_height is used in text and cursor offset
1894 * calculations. Since the console is below the logo,
1895 * we need to adjust the logo height
1897 if (video_logo_ypos == BMP_ALIGN_CENTER)
1898 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1899 VIDEO_LOGO_HEIGHT) / 2);
1900 else if (video_logo_ypos > 0)
1901 video_logo_height += video_logo_ypos;
1903 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1906 if (board_cfb_skip())
1909 sprintf(info, " %s", version_string);
1911 #ifndef CONFIG_HIDE_LOGO_VERSION
1912 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1916 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1917 uchar *p = (uchar *) info;
1921 video_drawchars(xx, yy, p, space);
1924 p = (uchar *)p + space;
1927 xx += VIDEO_FONT_WIDTH;
1930 yy += VIDEO_FONT_HEIGHT;
1934 video_drawchars(xx, yy, p, len);
1939 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1941 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1944 ((video_logo_height -
1945 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1947 for (i = 1; i < n; i++) {
1948 video_get_info_str(i, info);
1954 video_drawchars(VIDEO_INFO_X,
1958 (uchar *) info, space);
1960 video_drawchars(VIDEO_INFO_X +
1965 (uchar *) info + space,
1968 video_drawstring(VIDEO_INFO_X,
1979 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1983 static int cfb_fb_is_in_dram(void)
1985 struct bd_info *bd = gd->bd;
1986 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
1987 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1991 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1992 start = bd->bi_dram[i].start;
1993 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1994 if ((ulong)video_fb_address >= start &&
1995 (ulong)video_fb_address < end)
1999 if ((ulong)video_fb_address >= bd->bi_memstart &&
2000 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2006 void video_clear(void)
2008 if (!video_fb_address)
2010 #ifdef VIDEO_HW_RECTFILL
2011 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2014 VIDEO_VISIBLE_COLS, /* frame width */
2015 VIDEO_VISIBLE_ROWS, /* frame height */
2016 bgx /* fill color */
2019 memsetl(video_fb_address,
2020 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2024 static int cfg_video_init(void)
2026 unsigned char color8;
2028 pGD = video_hw_init();
2032 video_fb_address = (void *) VIDEO_FB_ADRS;
2034 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2036 /* Init drawing pats */
2037 switch (VIDEO_DATA_FORMAT) {
2038 case GDF__8BIT_INDEX:
2039 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2040 CONFIG_SYS_CONSOLE_FG_COL,
2041 CONFIG_SYS_CONSOLE_FG_COL);
2042 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2043 CONFIG_SYS_CONSOLE_BG_COL,
2044 CONFIG_SYS_CONSOLE_BG_COL);
2048 case GDF__8BIT_332RGB:
2049 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2050 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2051 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2052 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2054 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2055 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2056 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2057 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2060 case GDF_15BIT_555RGB:
2061 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2062 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2063 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2064 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2065 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2066 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2067 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2068 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2069 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2070 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2071 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2072 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2074 case GDF_16BIT_565RGB:
2075 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2076 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2077 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2078 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2079 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2080 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2081 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2082 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2083 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2084 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2085 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2086 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2088 case GDF_32BIT_X888RGB:
2089 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2090 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2091 CONFIG_SYS_CONSOLE_FG_COL;
2092 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2093 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2094 CONFIG_SYS_CONSOLE_BG_COL;
2096 case GDF_24BIT_888RGB:
2097 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2098 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2099 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2100 CONFIG_SYS_CONSOLE_FG_COL;
2101 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2102 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2103 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2104 CONFIG_SYS_CONSOLE_BG_COL;
2109 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2112 #ifdef CONFIG_VIDEO_LOGO
2113 /* Plot the logo and get start point of console */
2114 debug("Video: Drawing the logo ...\n");
2115 video_console_address = video_logo();
2117 video_console_address = video_fb_address;
2120 /* Initialize the console */
2124 if (cfb_do_flush_cache)
2125 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2131 * Implement a weak default function for boards that optionally
2132 * need to skip the video initialization.
2134 __weak int board_video_skip(void)
2136 /* As default, don't skip test */
2140 int drv_video_init(void)
2142 struct stdio_dev console_dev;
2144 bool __maybe_unused keyboard_ok = false;
2146 /* Check if video initialization should be skipped */
2147 if (board_video_skip())
2150 /* Init video chip - returns with framebuffer cleared */
2151 if (cfg_video_init() == -1)
2154 if (board_cfb_skip())
2157 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2158 have_keyboard = false;
2159 #elif defined(CONFIG_OF_CONTROL)
2160 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2161 "u-boot,no-keyboard");
2163 have_keyboard = true;
2165 if (have_keyboard) {
2166 debug("KBD: Keyboard init ...\n");
2167 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2168 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2172 /* Init vga device */
2173 memset(&console_dev, 0, sizeof(console_dev));
2174 strcpy(console_dev.name, "vga");
2175 console_dev.flags = DEV_FLAGS_OUTPUT;
2176 console_dev.putc = cfb_video_putc; /* 'putc' function */
2177 console_dev.puts = cfb_video_puts; /* 'puts' function */
2179 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2180 if (have_keyboard && keyboard_ok) {
2181 /* Also init console device */
2182 console_dev.flags |= DEV_FLAGS_INPUT;
2183 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2184 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2188 if (stdio_register(&console_dev) != 0)
2191 /* Return success */
2195 void video_position_cursor(unsigned col, unsigned row)
2197 console_col = min(col, CONSOLE_COLS - 1);
2198 console_row = min(row, CONSOLE_ROWS - 1);
2201 int video_get_pixel_width(void)
2203 return VIDEO_VISIBLE_COLS;
2206 int video_get_pixel_height(void)
2208 return VIDEO_VISIBLE_ROWS;
2211 int video_get_screen_rows(void)
2213 return CONSOLE_ROWS;
2216 int video_get_screen_columns(void)
2218 return CONSOLE_COLS;