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
75 #include <linux/compiler.h>
77 #if defined(CONFIG_VIDEO_MXS)
78 #define VIDEO_FB_16BPP_WORD_SWAP
82 * Defines for the MB862xx driver
84 #ifdef CONFIG_VIDEO_MB862xx
86 #ifdef CONFIG_VIDEO_CORALP
87 #define VIDEO_FB_LITTLE_ENDIAN
89 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
90 #define VIDEO_HW_RECTFILL
91 #define VIDEO_HW_BITBLT
96 * Defines for the i.MX31 driver (mx3fb.c)
98 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
99 #define VIDEO_FB_16BPP_WORD_SWAP
103 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
105 #include <video_fb.h>
112 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
113 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
114 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
115 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
116 #define VIDEO_FB_ADRS (pGD->frameAdrs)
123 #include <linux/types.h>
124 #include <stdio_dev.h>
125 #include <video_font.h>
127 #if defined(CONFIG_CMD_DATE)
131 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
132 #include <watchdog.h>
133 #include <bmp_layout.h>
137 #if !defined(CONFIG_VIDEO_SW_CURSOR)
138 /* no Cursor defined */
144 #if defined(CONFIG_VIDEO_SW_CURSOR)
145 void console_cursor(int state);
147 #define CURSOR_ON console_cursor(1)
148 #define CURSOR_OFF console_cursor(0)
149 #define CURSOR_SET video_set_cursor()
150 #endif /* CONFIG_VIDEO_SW_CURSOR */
152 #ifdef CONFIG_VIDEO_LOGO
153 #ifdef CONFIG_VIDEO_BMP_LOGO
154 #include <bmp_logo.h>
155 #include <bmp_logo_data.h>
156 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
157 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
158 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
159 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
161 #else /* CONFIG_VIDEO_BMP_LOGO */
162 #define LINUX_LOGO_WIDTH 80
163 #define LINUX_LOGO_HEIGHT 80
164 #define LINUX_LOGO_COLORS 214
165 #define LINUX_LOGO_LUT_OFFSET 0x20
167 #include <linux_logo.h>
168 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
169 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
170 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
171 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
172 #endif /* CONFIG_VIDEO_BMP_LOGO */
173 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
174 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
175 #else /* CONFIG_VIDEO_LOGO */
176 #define VIDEO_LOGO_WIDTH 0
177 #define VIDEO_LOGO_HEIGHT 0
178 #endif /* CONFIG_VIDEO_LOGO */
180 #define VIDEO_COLS VIDEO_VISIBLE_COLS
181 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
182 #ifndef VIDEO_LINE_LEN
183 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
185 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
186 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
188 #ifdef CONFIG_VIDEO_LOGO
189 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
191 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
194 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
195 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
196 #define CONSOLE_ROW_FIRST (video_console_address)
197 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
198 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
199 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
201 /* By default we scroll by a single line */
202 #ifndef CONFIG_CONSOLE_SCROLL_LINES
203 #define CONFIG_CONSOLE_SCROLL_LINES 1
207 #ifdef VIDEO_FB_LITTLE_ENDIAN
208 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
211 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
212 (((x) & 0x0000ff00) << 8) | \
213 (((x) & 0x00ff0000) >> 8) | \
214 (((x) & 0xff000000) >> 24) \
216 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
217 (((x) & 0x0000ff00) >> 8) | \
218 (((x) & 0x00ff0000) << 8) | \
219 (((x) & 0xff000000) >> 8) \
222 #define SWAP16(x) (x)
223 #define SWAP32(x) (x)
224 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
225 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
227 #define SHORTSWAP32(x) (x)
231 DECLARE_GLOBAL_DATA_PTR;
234 static GraphicDevice *pGD; /* Pointer to Graphic array */
236 static void *video_fb_address; /* frame buffer address */
237 static void *video_console_address; /* console buffer start address */
239 static int video_logo_height = VIDEO_LOGO_HEIGHT;
241 static int __maybe_unused cursor_state;
242 static int __maybe_unused old_col;
243 static int __maybe_unused old_row;
245 static int console_col; /* cursor col */
246 static int console_row; /* cursor row */
248 static u32 eorx, fgx, bgx; /* color pats */
250 static int cfb_do_flush_cache;
252 #ifdef CONFIG_CFB_CONSOLE_ANSI
253 static char ansi_buf[10];
254 static int ansi_buf_size;
255 static int ansi_colors_need_revert;
256 static int ansi_cursor_hidden;
259 static const int video_font_draw_table8[] = {
260 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
261 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
262 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
263 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
266 static const int video_font_draw_table15[] = {
267 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
270 static const int video_font_draw_table16[] = {
271 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
274 static const int video_font_draw_table24[16][3] = {
275 {0x00000000, 0x00000000, 0x00000000},
276 {0x00000000, 0x00000000, 0x00ffffff},
277 {0x00000000, 0x0000ffff, 0xff000000},
278 {0x00000000, 0x0000ffff, 0xffffffff},
279 {0x000000ff, 0xffff0000, 0x00000000},
280 {0x000000ff, 0xffff0000, 0x00ffffff},
281 {0x000000ff, 0xffffffff, 0xff000000},
282 {0x000000ff, 0xffffffff, 0xffffffff},
283 {0xffffff00, 0x00000000, 0x00000000},
284 {0xffffff00, 0x00000000, 0x00ffffff},
285 {0xffffff00, 0x0000ffff, 0xff000000},
286 {0xffffff00, 0x0000ffff, 0xffffffff},
287 {0xffffffff, 0xffff0000, 0x00000000},
288 {0xffffffff, 0xffff0000, 0x00ffffff},
289 {0xffffffff, 0xffffffff, 0xff000000},
290 {0xffffffff, 0xffffffff, 0xffffffff}
293 static const int video_font_draw_table32[16][4] = {
294 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
295 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
296 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
297 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
298 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
299 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
300 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
301 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
302 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
303 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
304 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
305 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
306 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
307 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
308 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
309 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
313 * Implement a weak default function for boards that optionally
314 * need to skip the cfb initialization.
316 __weak int board_cfb_skip(void)
318 /* As default, don't skip cfb init */
322 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
324 u8 *cdat, *dest, *dest0;
327 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
328 dest0 = video_fb_address + offset;
330 switch (VIDEO_DATA_FORMAT) {
331 case GDF__8BIT_INDEX:
332 case GDF__8BIT_332RGB:
335 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
336 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
337 rows--; dest += VIDEO_LINE_LEN) {
341 (video_font_draw_table8[bits >> 4] &
344 if (VIDEO_FONT_WIDTH == 4)
348 (video_font_draw_table8[bits & 15] &
351 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
356 case GDF_15BIT_555RGB:
359 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
360 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
361 rows--; dest += VIDEO_LINE_LEN) {
365 SHORTSWAP32((video_font_draw_table15
366 [bits >> 6] & eorx) ^
369 SHORTSWAP32((video_font_draw_table15
370 [bits >> 4 & 3] & eorx) ^
373 if (VIDEO_FONT_WIDTH == 4)
377 SHORTSWAP32((video_font_draw_table15
378 [bits >> 2 & 3] & eorx) ^
381 SHORTSWAP32((video_font_draw_table15
385 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
390 case GDF_16BIT_565RGB:
393 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
394 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
395 rows--; dest += VIDEO_LINE_LEN) {
399 SHORTSWAP32((video_font_draw_table16
400 [bits >> 6] & eorx) ^
403 SHORTSWAP32((video_font_draw_table16
404 [bits >> 4 & 3] & eorx) ^
407 if (VIDEO_FONT_WIDTH == 4)
411 SHORTSWAP32((video_font_draw_table16
412 [bits >> 2 & 3] & eorx) ^
415 SHORTSWAP32((video_font_draw_table16
419 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
424 case GDF_32BIT_X888RGB:
427 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
428 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
429 rows--; dest += VIDEO_LINE_LEN) {
433 SWAP32((video_font_draw_table32
434 [bits >> 4][0] & eorx) ^ bgx);
436 SWAP32((video_font_draw_table32
437 [bits >> 4][1] & eorx) ^ bgx);
439 SWAP32((video_font_draw_table32
440 [bits >> 4][2] & eorx) ^ bgx);
442 SWAP32((video_font_draw_table32
443 [bits >> 4][3] & eorx) ^ bgx);
446 if (VIDEO_FONT_WIDTH == 4)
450 SWAP32((video_font_draw_table32
451 [bits & 15][0] & eorx) ^ bgx);
453 SWAP32((video_font_draw_table32
454 [bits & 15][1] & eorx) ^ bgx);
456 SWAP32((video_font_draw_table32
457 [bits & 15][2] & eorx) ^ bgx);
459 SWAP32((video_font_draw_table32
460 [bits & 15][3] & eorx) ^ bgx);
462 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
467 case GDF_24BIT_888RGB:
470 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
471 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
472 rows--; dest += VIDEO_LINE_LEN) {
476 (video_font_draw_table24[bits >> 4][0]
479 (video_font_draw_table24[bits >> 4][1]
482 (video_font_draw_table24[bits >> 4][2]
485 if (VIDEO_FONT_WIDTH == 4)
489 (video_font_draw_table24[bits & 15][0]
492 (video_font_draw_table24[bits & 15][1]
495 (video_font_draw_table24[bits & 15][2]
498 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
505 static inline void video_drawstring(int xx, int yy, unsigned char *s)
507 video_drawchars(xx, yy, s, strlen((char *) s));
510 static void video_putchar(int xx, int yy, unsigned char c)
512 video_drawchars(xx, yy + video_logo_height, &c, 1);
515 #if defined(CONFIG_VIDEO_SW_CURSOR)
516 static void video_set_cursor(void)
523 static void video_invertchar(int xx, int yy)
525 int firstx = xx * VIDEO_PIXEL_SIZE;
526 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
527 int firsty = yy * VIDEO_LINE_LEN;
528 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
530 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
531 for (x = firstx; x < lastx; x++) {
532 u8 *dest = (u8 *)(video_fb_address) + x + y;
538 void console_cursor(int state)
540 if (cursor_state != state) {
542 /* turn off the cursor */
543 video_invertchar(old_col * VIDEO_FONT_WIDTH,
544 old_row * VIDEO_FONT_HEIGHT +
547 /* turn off the cursor and record where it is */
548 video_invertchar(console_col * VIDEO_FONT_WIDTH,
549 console_row * VIDEO_FONT_HEIGHT +
551 old_col = console_col;
552 old_row = console_row;
554 cursor_state = state;
556 if (cfb_do_flush_cache)
557 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
561 #ifndef VIDEO_HW_RECTFILL
562 static void memsetl(int *p, int c, int v)
569 #ifndef VIDEO_HW_BITBLT
570 static void memcpyl(int *d, int *s, int c)
577 static void console_clear_line(int line, int begin, int end)
579 #ifdef VIDEO_HW_RECTFILL
580 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
581 VIDEO_FONT_WIDTH * begin, /* dest pos x */
583 VIDEO_FONT_HEIGHT * line, /* dest pos y */
584 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
585 VIDEO_FONT_HEIGHT, /* frame height */
589 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
590 memsetl(CONSOLE_ROW_FIRST +
591 CONSOLE_ROW_SIZE * line, /* offset of row */
592 CONSOLE_ROW_SIZE >> 2, /* length of row */
599 offset = CONSOLE_ROW_FIRST +
600 CONSOLE_ROW_SIZE * line + /* offset of row */
602 VIDEO_PIXEL_SIZE * begin; /* offset of col */
603 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
604 size >>= 2; /* length to end for memsetl() */
605 /* fill at col offset of i'th line using bgx as fill color */
606 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
607 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
612 static void console_scrollup(void)
614 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
617 /* copy up rows ignoring the first one */
619 #ifdef VIDEO_HW_BITBLT
620 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
621 0, /* source pos x */
623 VIDEO_FONT_HEIGHT * rows, /* source pos y */
625 video_logo_height, /* dest pos y */
626 VIDEO_VISIBLE_COLS, /* frame width */
629 - VIDEO_FONT_HEIGHT * rows /* frame height */
632 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
633 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
635 /* clear the last one */
636 for (i = 1; i <= rows; i++)
637 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
639 /* Decrement row number */
643 static void console_back(void)
647 if (console_col < 0) {
648 console_col = CONSOLE_COLS - 1;
655 #ifdef CONFIG_CFB_CONSOLE_ANSI
657 static void console_clear(void)
659 #ifdef VIDEO_HW_RECTFILL
660 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
662 video_logo_height, /* dest pos y */
663 VIDEO_VISIBLE_COLS, /* frame width */
664 VIDEO_VISIBLE_ROWS, /* frame height */
668 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
672 static void console_cursor_fix(void)
676 if (console_row >= CONSOLE_ROWS)
677 console_row = CONSOLE_ROWS - 1;
680 if (console_col >= CONSOLE_COLS)
681 console_col = CONSOLE_COLS - 1;
684 static void console_cursor_up(int n)
687 console_cursor_fix();
690 static void console_cursor_down(int n)
693 console_cursor_fix();
696 static void console_cursor_left(int n)
699 console_cursor_fix();
702 static void console_cursor_right(int n)
705 console_cursor_fix();
708 static void console_cursor_set_position(int row, int col)
710 if (console_row != -1)
712 if (console_col != -1)
714 console_cursor_fix();
717 static void console_previousline(int n)
719 /* FIXME: also scroll terminal ? */
721 console_cursor_fix();
724 static void console_swap_colors(void)
732 static inline int console_cursor_is_visible(void)
734 return !ansi_cursor_hidden;
737 static inline int console_cursor_is_visible(void)
743 static void console_newline(int n)
748 /* Check if we need to scroll the terminal */
749 if (console_row >= CONSOLE_ROWS) {
750 /* Scroll everything up */
755 static void console_cr(void)
760 static void parse_putc(const char c)
764 if (console_cursor_is_visible())
768 case 13: /* back to first column */
772 case '\n': /* next line */
773 if (console_col || nl)
779 console_col |= 0x0008;
780 console_col &= ~0x0007;
782 if (console_col >= CONSOLE_COLS)
786 case 8: /* backspace */
793 default: /* draw the char */
794 video_putchar(console_col * VIDEO_FONT_WIDTH,
795 console_row * VIDEO_FONT_HEIGHT, c);
798 /* check for newline */
799 if (console_col >= CONSOLE_COLS) {
805 if (console_cursor_is_visible())
809 static void cfb_video_putc(struct stdio_dev *dev, const char c)
811 #ifdef CONFIG_CFB_CONSOLE_ANSI
815 for (i = 0; i < ansi_buf_size; ++i)
816 parse_putc(ansi_buf[i]);
822 if (ansi_buf_size > 0) {
842 ansi_buf[ansi_buf_size++] = c;
844 if (ansi_buf_size >= sizeof(ansi_buf))
847 for (i = 0; i < ansi_buf_size; ++i) {
853 if (ansi_buf[i] == 27)
860 if (ansi_buf[i] == '[')
867 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
868 num1 = ansi_buf[i]-'0';
870 } else if (ansi_buf[i] != '?') {
878 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
880 num1 += ansi_buf[i]-'0';
888 if (ansi_buf[i] != ';') {
896 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
897 num2 = ansi_buf[i]-'0';
904 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
906 num2 += ansi_buf[i]-'0';
914 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
915 || ansi_buf[i] == 'J'
916 || ansi_buf[i] == 'K'
917 || ansi_buf[i] == 'h'
918 || ansi_buf[i] == 'l'
919 || ansi_buf[i] == 'm') {
929 for (i = 0; i < ansi_buf_size; ++i)
930 parse_putc(ansi_buf[i]);
936 if (!ansi_cursor_hidden)
941 /* move cursor num1 rows up */
942 console_cursor_up(num1);
945 /* move cursor num1 rows down */
946 console_cursor_down(num1);
949 /* move cursor num1 columns forward */
950 console_cursor_right(num1);
953 /* move cursor num1 columns back */
954 console_cursor_left(num1);
957 /* move cursor num1 rows up at begin of row */
958 console_previousline(num1);
961 /* move cursor num1 rows down at begin of row */
962 console_newline(num1);
965 /* move cursor to column num1 */
966 console_cursor_set_position(-1, num1-1);
969 /* move cursor to row num1, column num2 */
970 console_cursor_set_position(num1-1, num2-1);
973 /* clear console and move cursor to 0, 0 */
975 console_cursor_set_position(0, 0);
980 console_clear_line(console_row,
984 console_clear_line(console_row,
987 console_clear_line(console_row,
991 ansi_cursor_hidden = 0;
994 ansi_cursor_hidden = 1;
997 if (num1 == 0) { /* reset swapped colors */
998 if (ansi_colors_need_revert) {
999 console_swap_colors();
1000 ansi_colors_need_revert = 0;
1002 } else if (num1 == 7) { /* once swap colors */
1003 if (!ansi_colors_need_revert) {
1004 console_swap_colors();
1005 ansi_colors_need_revert = 1;
1010 if (!ansi_cursor_hidden)
1019 if (cfb_do_flush_cache)
1020 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1023 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1025 int flush = cfb_do_flush_cache;
1026 int count = strlen(s);
1028 /* temporarily disable cache flush */
1029 cfb_do_flush_cache = 0;
1032 cfb_video_putc(dev, *s++);
1035 cfb_do_flush_cache = flush;
1036 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1041 * Do not enforce drivers (or board code) to provide empty
1042 * video_set_lut() if they do not support 8 bpp format.
1043 * Implement weak default function instead.
1045 __weak void video_set_lut(unsigned int index, unsigned char r,
1046 unsigned char g, unsigned char b)
1050 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1052 #define FILL_8BIT_332RGB(r,g,b) { \
1053 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1057 #define FILL_15BIT_555RGB(r,g,b) { \
1058 *(unsigned short *)fb = \
1059 SWAP16((unsigned short)(((r>>3)<<10) | \
1065 #define FILL_16BIT_565RGB(r,g,b) { \
1066 *(unsigned short *)fb = \
1067 SWAP16((unsigned short)((((r)>>3)<<11)| \
1073 #define FILL_32BIT_X888RGB(r,g,b) { \
1075 SWAP32((unsigned int)(((r<<16) | \
1081 #ifdef VIDEO_FB_LITTLE_ENDIAN
1082 #define FILL_24BIT_888RGB(r,g,b) { \
1089 #define FILL_24BIT_888RGB(r,g,b) { \
1097 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1098 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1100 ushort *dst = (ushort *) fb;
1101 ushort color = (ushort) (((r >> 3) << 10) |
1112 * RLE8 bitmap support
1115 #ifdef CONFIG_VIDEO_BMP_RLE8
1116 /* Pre-calculated color table entry */
1119 unsigned short w; /* word */
1120 unsigned int dw; /* double word */
1121 } ce; /* color entry */
1125 * Helper to draw encoded/unencoded run.
1127 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1130 ulong addr = (ulong) *fb;
1136 * Setup offset of the color index in the bitmap.
1137 * Color index of encoded run is at offset 1.
1139 off = enc ? &enc_off : &i;
1141 switch (VIDEO_DATA_FORMAT) {
1142 case GDF__8BIT_INDEX:
1143 for (i = 0; i < cnt; i++)
1144 *(unsigned char *) addr++ = bm[*off];
1146 case GDF_15BIT_555RGB:
1147 case GDF_16BIT_565RGB:
1148 /* differences handled while pre-calculating palette */
1149 for (i = 0; i < cnt; i++) {
1150 *(unsigned short *) addr = p[bm[*off]].ce.w;
1154 case GDF_32BIT_X888RGB:
1155 for (i = 0; i < cnt; i++) {
1156 *(u32 *) addr = p[bm[*off]].ce.dw;
1161 *fb = (uchar *) addr; /* return modified address */
1164 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1165 int width, int height)
1169 unsigned int cnt, runlen;
1171 int x, y, bpp, i, ncolors;
1172 struct palette p[256];
1173 struct bmp_color_table_entry cte;
1174 int green_shift, red_off;
1175 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1179 y = __le32_to_cpu(img->header.height) - 1;
1180 ncolors = __le32_to_cpu(img->header.colors_used);
1181 bpp = VIDEO_PIXEL_SIZE;
1182 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1183 (y + yoff) * VIDEO_LINE_LEN +
1186 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1188 /* pre-calculate and setup palette */
1189 switch (VIDEO_DATA_FORMAT) {
1190 case GDF__8BIT_INDEX:
1191 for (i = 0; i < ncolors; i++) {
1192 cte = img->color_table[i];
1193 video_set_lut(i, cte.red, cte.green, cte.blue);
1196 case GDF_15BIT_555RGB:
1197 case GDF_16BIT_565RGB:
1198 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1205 for (i = 0; i < ncolors; i++) {
1206 cte = img->color_table[i];
1207 p[i].ce.w = SWAP16((unsigned short)
1208 (((cte.red >> 3) << red_off) |
1209 ((cte.green >> green_shift) << 5) |
1213 case GDF_32BIT_X888RGB:
1214 for (i = 0; i < ncolors; i++) {
1215 cte = img->color_table[i];
1216 p[i].ce.dw = SWAP32((cte.red << 16) |
1222 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1232 /* scan line end marker */
1236 fbp = (unsigned char *)
1237 ((unsigned int) video_fb_address +
1238 (y + yoff) * VIDEO_LINE_LEN +
1242 /* end of bitmap data marker */
1246 /* run offset marker */
1249 fbp = (unsigned char *)
1250 ((unsigned int) video_fb_address +
1251 (y + yoff) * VIDEO_LINE_LEN +
1269 if (x + runlen > width)
1271 draw_bitmap(&fbp, bm, p, cnt, 0);
1277 bm++; /* 0 padding if length is odd */
1288 if (y < height) { /* only draw into visible area */
1294 if (x + runlen > width)
1296 draw_bitmap(&fbp, bm, p, cnt, 1);
1304 if (cfb_do_flush_cache)
1305 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1309 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1315 * Display the BMP file located at address bmp_image.
1317 int video_display_bitmap(ulong bmp_image, int x, int y)
1319 ushort xcount, ycount;
1321 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1324 unsigned long width, height, bpp;
1326 unsigned long compression;
1327 struct bmp_color_table_entry cte;
1329 #ifdef CONFIG_VIDEO_BMP_GZIP
1330 unsigned char *dst = NULL;
1336 if (!((bmp->header.signature[0] == 'B') &&
1337 (bmp->header.signature[1] == 'M'))) {
1339 #ifdef CONFIG_VIDEO_BMP_GZIP
1341 * Could be a gzipped bmp image, try to decrompress...
1343 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1344 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1346 printf("Error: malloc in gunzip failed!\n");
1350 * NB: we need to force offset of +2
1351 * See doc/README.displaying-bmps
1353 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1354 (uchar *) bmp_image,
1356 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1361 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1362 printf("Image could be truncated "
1363 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1367 * Set addr to decompressed image
1369 bmp = (struct bmp_image *)(dst+2);
1371 if (!((bmp->header.signature[0] == 'B') &&
1372 (bmp->header.signature[1] == 'M'))) {
1373 printf("Error: no valid bmp.gz image at %lx\n",
1379 printf("Error: no valid bmp image at %lx\n", bmp_image);
1381 #endif /* CONFIG_VIDEO_BMP_GZIP */
1384 width = le32_to_cpu(bmp->header.width);
1385 height = le32_to_cpu(bmp->header.height);
1386 bpp = le16_to_cpu(bmp->header.bit_count);
1387 colors = le32_to_cpu(bmp->header.colors_used);
1388 compression = le32_to_cpu(bmp->header.compression);
1390 debug("Display-bmp: %ld x %ld with %d colors\n",
1391 width, height, colors);
1393 if (compression != BMP_BI_RGB
1394 #ifdef CONFIG_VIDEO_BMP_RLE8
1395 && compression != BMP_BI_RLE8
1398 printf("Error: compression type %ld not supported\n",
1400 #ifdef CONFIG_VIDEO_BMP_GZIP
1407 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1409 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1410 if (x == BMP_ALIGN_CENTER)
1411 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1413 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1415 if (y == BMP_ALIGN_CENTER)
1416 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1418 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1419 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1422 * Just ignore elements which are completely beyond screen
1425 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1428 if ((x + width) > VIDEO_VISIBLE_COLS)
1429 width = VIDEO_VISIBLE_COLS - x;
1430 if ((y + height) > VIDEO_VISIBLE_ROWS)
1431 height = VIDEO_VISIBLE_ROWS - y;
1433 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1434 fb = (uchar *) (video_fb_address +
1435 ((y + height - 1) * VIDEO_LINE_LEN) +
1436 x * VIDEO_PIXEL_SIZE);
1438 #ifdef CONFIG_VIDEO_BMP_RLE8
1439 if (compression == BMP_BI_RLE8) {
1440 return display_rle8_bitmap(bmp, x, y, width, height);
1444 /* We handle only 4, 8, or 24 bpp bitmaps */
1445 switch (le16_to_cpu(bmp->header.bit_count)) {
1447 padded_line -= width / 2;
1450 switch (VIDEO_DATA_FORMAT) {
1451 case GDF_32BIT_X888RGB:
1455 * Don't assume that 'width' is an
1458 for (xcount = 0; xcount < width; xcount++) {
1466 cte = bmp->color_table[idx];
1467 FILL_32BIT_X888RGB(cte.red, cte.green,
1470 bmap += padded_line;
1471 fb -= VIDEO_LINE_LEN + width *
1476 puts("4bpp bitmap unsupported with current "
1483 padded_line -= width;
1484 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1486 for (xcount = 0; xcount < colors; ++xcount) {
1487 cte = bmp->color_table[xcount];
1488 video_set_lut(xcount, cte.red, cte.green,
1493 switch (VIDEO_DATA_FORMAT) {
1494 case GDF__8BIT_INDEX:
1501 bmap += padded_line;
1502 fb -= VIDEO_LINE_LEN + width *
1506 case GDF__8BIT_332RGB:
1511 cte = bmp->color_table[*bmap++];
1512 FILL_8BIT_332RGB(cte.red, cte.green,
1515 bmap += padded_line;
1516 fb -= VIDEO_LINE_LEN + width *
1520 case GDF_15BIT_555RGB:
1522 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1528 cte = bmp->color_table[*bmap++];
1529 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1530 fill_555rgb_pswap(fb, xpos++, cte.red,
1535 FILL_15BIT_555RGB(cte.red, cte.green,
1539 bmap += padded_line;
1540 fb -= VIDEO_LINE_LEN + width *
1544 case GDF_16BIT_565RGB:
1549 cte = bmp->color_table[*bmap++];
1550 FILL_16BIT_565RGB(cte.red, cte.green,
1553 bmap += padded_line;
1554 fb -= VIDEO_LINE_LEN + width *
1558 case GDF_32BIT_X888RGB:
1563 cte = bmp->color_table[*bmap++];
1564 FILL_32BIT_X888RGB(cte.red, cte.green,
1567 bmap += padded_line;
1568 fb -= VIDEO_LINE_LEN + width *
1572 case GDF_24BIT_888RGB:
1577 cte = bmp->color_table[*bmap++];
1578 FILL_24BIT_888RGB(cte.red, cte.green,
1581 bmap += padded_line;
1582 fb -= VIDEO_LINE_LEN + width *
1589 padded_line -= 3 * width;
1591 switch (VIDEO_DATA_FORMAT) {
1592 case GDF__8BIT_332RGB:
1597 FILL_8BIT_332RGB(bmap[2], bmap[1],
1601 bmap += padded_line;
1602 fb -= VIDEO_LINE_LEN + width *
1606 case GDF_15BIT_555RGB:
1608 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1614 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1615 fill_555rgb_pswap(fb, xpos++, bmap[2],
1619 FILL_15BIT_555RGB(bmap[2], bmap[1],
1624 bmap += padded_line;
1625 fb -= VIDEO_LINE_LEN + width *
1629 case GDF_16BIT_565RGB:
1634 FILL_16BIT_565RGB(bmap[2], bmap[1],
1638 bmap += padded_line;
1639 fb -= VIDEO_LINE_LEN + width *
1643 case GDF_32BIT_X888RGB:
1648 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1652 bmap += padded_line;
1653 fb -= VIDEO_LINE_LEN + width *
1657 case GDF_24BIT_888RGB:
1662 FILL_24BIT_888RGB(bmap[2], bmap[1],
1666 bmap += padded_line;
1667 fb -= VIDEO_LINE_LEN + width *
1672 printf("Error: 24 bits/pixel bitmap incompatible "
1673 "with current video mode\n");
1678 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1679 le16_to_cpu(bmp->header.bit_count));
1683 #ifdef CONFIG_VIDEO_BMP_GZIP
1689 if (cfb_do_flush_cache)
1690 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1696 #ifdef CONFIG_VIDEO_LOGO
1697 static int video_logo_xpos;
1698 static int video_logo_ypos;
1700 static void plot_logo_or_black(void *screen, int x, int y, int black);
1702 static void logo_plot(void *screen, int x, int y)
1704 plot_logo_or_black(screen, x, y, 0);
1707 static void logo_black(void)
1709 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1713 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1716 return cmd_usage(cmdtp);
1723 clrlogo, 1, 0, do_clrlogo,
1724 "fill the boot logo area with black",
1728 static void plot_logo_or_black(void *screen, int x, int y, int black)
1732 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1733 int ycount = video_logo_height;
1734 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1735 unsigned char *source;
1736 unsigned char *dest;
1738 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1739 if (x == BMP_ALIGN_CENTER)
1740 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1742 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1744 if (y == BMP_ALIGN_CENTER)
1745 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1747 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1748 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1750 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1752 #ifdef CONFIG_VIDEO_BMP_LOGO
1753 source = bmp_logo_bitmap;
1755 /* Allocate temporary space for computing colormap */
1756 logo_red = malloc(BMP_LOGO_COLORS);
1757 logo_green = malloc(BMP_LOGO_COLORS);
1758 logo_blue = malloc(BMP_LOGO_COLORS);
1759 /* Compute color map */
1760 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1761 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1762 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1763 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1766 source = linux_logo;
1767 logo_red = linux_logo_red;
1768 logo_green = linux_logo_green;
1769 logo_blue = linux_logo_blue;
1772 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1773 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1774 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1775 logo_red[i], logo_green[i],
1781 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1784 xcount = VIDEO_LOGO_WIDTH;
1791 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1792 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1793 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1796 switch (VIDEO_DATA_FORMAT) {
1797 case GDF__8BIT_INDEX:
1800 case GDF__8BIT_332RGB:
1801 *dest = ((r >> 5) << 5) |
1805 case GDF_15BIT_555RGB:
1806 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1807 fill_555rgb_pswap(dest, xpos++, r, g, b);
1809 *(unsigned short *) dest =
1810 SWAP16((unsigned short) (
1816 case GDF_16BIT_565RGB:
1817 *(unsigned short *) dest =
1818 SWAP16((unsigned short) (
1823 case GDF_32BIT_X888RGB:
1830 case GDF_24BIT_888RGB:
1831 #ifdef VIDEO_FB_LITTLE_ENDIAN
1843 dest += VIDEO_PIXEL_SIZE;
1847 #ifdef CONFIG_VIDEO_BMP_LOGO
1854 static void *video_logo(void)
1857 __maybe_unused int y_off = 0;
1858 __maybe_unused ulong addr;
1859 __maybe_unused char *s;
1860 __maybe_unused int len, ret, space;
1862 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1864 #ifdef CONFIG_SPLASH_SCREEN
1865 s = env_get("splashimage");
1867 ret = splash_screen_prepare();
1869 return video_fb_address;
1870 addr = simple_strtoul(s, NULL, 16);
1872 if (video_display_bitmap(addr,
1874 video_logo_ypos) == 0) {
1875 video_logo_height = 0;
1876 return ((void *) (video_fb_address));
1879 #endif /* CONFIG_SPLASH_SCREEN */
1881 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1883 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1885 * when using splashpos for video_logo, skip any info
1886 * output on video console if the logo is not at 0,0
1888 if (video_logo_xpos || video_logo_ypos) {
1890 * video_logo_height is used in text and cursor offset
1891 * calculations. Since the console is below the logo,
1892 * we need to adjust the logo height
1894 if (video_logo_ypos == BMP_ALIGN_CENTER)
1895 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1896 VIDEO_LOGO_HEIGHT) / 2);
1897 else if (video_logo_ypos > 0)
1898 video_logo_height += video_logo_ypos;
1900 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1903 if (board_cfb_skip())
1906 sprintf(info, " %s", version_string);
1908 #ifndef CONFIG_HIDE_LOGO_VERSION
1909 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1913 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1914 uchar *p = (uchar *) info;
1918 video_drawchars(xx, yy, p, space);
1921 p = (uchar *)p + space;
1924 xx += VIDEO_FONT_WIDTH;
1927 yy += VIDEO_FONT_HEIGHT;
1931 video_drawchars(xx, yy, p, len);
1936 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1938 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1941 ((video_logo_height -
1942 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1944 for (i = 1; i < n; i++) {
1945 video_get_info_str(i, info);
1951 video_drawchars(VIDEO_INFO_X,
1955 (uchar *) info, space);
1957 video_drawchars(VIDEO_INFO_X +
1962 (uchar *) info + space,
1965 video_drawstring(VIDEO_INFO_X,
1976 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1980 static int cfb_fb_is_in_dram(void)
1983 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
1984 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1988 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1989 start = bd->bi_dram[i].start;
1990 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1991 if ((ulong)video_fb_address >= start &&
1992 (ulong)video_fb_address < end)
1996 if ((ulong)video_fb_address >= bd->bi_memstart &&
1997 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2003 void video_clear(void)
2005 if (!video_fb_address)
2007 #ifdef VIDEO_HW_RECTFILL
2008 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2011 VIDEO_VISIBLE_COLS, /* frame width */
2012 VIDEO_VISIBLE_ROWS, /* frame height */
2013 bgx /* fill color */
2016 memsetl(video_fb_address,
2017 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2021 static int cfg_video_init(void)
2023 unsigned char color8;
2025 pGD = video_hw_init();
2029 video_fb_address = (void *) VIDEO_FB_ADRS;
2031 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2033 /* Init drawing pats */
2034 switch (VIDEO_DATA_FORMAT) {
2035 case GDF__8BIT_INDEX:
2036 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2037 CONFIG_SYS_CONSOLE_FG_COL,
2038 CONFIG_SYS_CONSOLE_FG_COL);
2039 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2040 CONFIG_SYS_CONSOLE_BG_COL,
2041 CONFIG_SYS_CONSOLE_BG_COL);
2045 case GDF__8BIT_332RGB:
2046 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2047 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2048 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2049 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2051 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2052 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2053 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2054 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2057 case GDF_15BIT_555RGB:
2058 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2059 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2061 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2062 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2063 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2064 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2065 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2067 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2068 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2069 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2071 case GDF_16BIT_565RGB:
2072 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2073 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2074 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2075 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2076 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2077 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2078 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2079 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2080 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2081 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2082 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2083 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2085 case GDF_32BIT_X888RGB:
2086 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2087 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2088 CONFIG_SYS_CONSOLE_FG_COL;
2089 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2090 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2091 CONFIG_SYS_CONSOLE_BG_COL;
2093 case GDF_24BIT_888RGB:
2094 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2095 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2096 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2097 CONFIG_SYS_CONSOLE_FG_COL;
2098 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2099 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2100 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2101 CONFIG_SYS_CONSOLE_BG_COL;
2106 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2109 #ifdef CONFIG_VIDEO_LOGO
2110 /* Plot the logo and get start point of console */
2111 debug("Video: Drawing the logo ...\n");
2112 video_console_address = video_logo();
2114 video_console_address = video_fb_address;
2117 /* Initialize the console */
2121 if (cfb_do_flush_cache)
2122 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2128 * Implement a weak default function for boards that optionally
2129 * need to skip the video initialization.
2131 __weak int board_video_skip(void)
2133 /* As default, don't skip test */
2137 int drv_video_init(void)
2139 struct stdio_dev console_dev;
2141 bool __maybe_unused keyboard_ok = false;
2143 /* Check if video initialization should be skipped */
2144 if (board_video_skip())
2147 /* Init video chip - returns with framebuffer cleared */
2148 if (cfg_video_init() == -1)
2151 if (board_cfb_skip())
2154 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2155 have_keyboard = false;
2156 #elif defined(CONFIG_OF_CONTROL)
2157 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2158 "u-boot,no-keyboard");
2160 have_keyboard = true;
2162 if (have_keyboard) {
2163 debug("KBD: Keyboard init ...\n");
2164 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2165 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2169 /* Init vga device */
2170 memset(&console_dev, 0, sizeof(console_dev));
2171 strcpy(console_dev.name, "vga");
2172 console_dev.flags = DEV_FLAGS_OUTPUT;
2173 console_dev.putc = cfb_video_putc; /* 'putc' function */
2174 console_dev.puts = cfb_video_puts; /* 'puts' function */
2176 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2177 if (have_keyboard && keyboard_ok) {
2178 /* Also init console device */
2179 console_dev.flags |= DEV_FLAGS_INPUT;
2180 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2181 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2185 if (stdio_register(&console_dev) != 0)
2188 /* Return success */
2192 void video_position_cursor(unsigned col, unsigned row)
2194 console_col = min(col, CONSOLE_COLS - 1);
2195 console_row = min(row, CONSOLE_ROWS - 1);
2198 int video_get_pixel_width(void)
2200 return VIDEO_VISIBLE_COLS;
2203 int video_get_pixel_height(void)
2205 return VIDEO_VISIBLE_ROWS;
2208 int video_get_screen_rows(void)
2210 return CONSOLE_ROWS;
2213 int video_get_screen_columns(void)
2215 return CONSOLE_COLS;