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
72 #include <linux/compiler.h>
74 #if defined(CONFIG_VIDEO_MXS)
75 #define VIDEO_FB_16BPP_WORD_SWAP
79 * Defines for the MB862xx driver
81 #ifdef CONFIG_VIDEO_MB862xx
83 #ifdef CONFIG_VIDEO_CORALP
84 #define VIDEO_FB_LITTLE_ENDIAN
86 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
87 #define VIDEO_HW_RECTFILL
88 #define VIDEO_HW_BITBLT
93 * Defines for the i.MX31 driver (mx3fb.c)
95 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
96 #define VIDEO_FB_16BPP_WORD_SWAP
100 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
102 #include <video_fb.h>
109 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
110 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
111 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
112 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
113 #define VIDEO_FB_ADRS (pGD->frameAdrs)
120 #include <linux/types.h>
121 #include <stdio_dev.h>
122 #include <video_font.h>
124 #if defined(CONFIG_CMD_DATE)
128 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
129 #include <watchdog.h>
130 #include <bmp_layout.h>
134 #if !defined(CONFIG_VIDEO_SW_CURSOR)
135 /* no Cursor defined */
141 #if defined(CONFIG_VIDEO_SW_CURSOR)
142 void console_cursor(int state);
144 #define CURSOR_ON console_cursor(1)
145 #define CURSOR_OFF console_cursor(0)
146 #define CURSOR_SET video_set_cursor()
147 #endif /* CONFIG_VIDEO_SW_CURSOR */
149 #ifdef CONFIG_VIDEO_LOGO
150 #ifdef CONFIG_VIDEO_BMP_LOGO
151 #include <bmp_logo.h>
152 #include <bmp_logo_data.h>
153 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
154 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
155 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
156 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
158 #else /* CONFIG_VIDEO_BMP_LOGO */
159 #define LINUX_LOGO_WIDTH 80
160 #define LINUX_LOGO_HEIGHT 80
161 #define LINUX_LOGO_COLORS 214
162 #define LINUX_LOGO_LUT_OFFSET 0x20
164 #include <linux_logo.h>
165 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
166 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
167 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
168 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
169 #endif /* CONFIG_VIDEO_BMP_LOGO */
170 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
171 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
172 #else /* CONFIG_VIDEO_LOGO */
173 #define VIDEO_LOGO_WIDTH 0
174 #define VIDEO_LOGO_HEIGHT 0
175 #endif /* CONFIG_VIDEO_LOGO */
177 #define VIDEO_COLS VIDEO_VISIBLE_COLS
178 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
179 #ifndef VIDEO_LINE_LEN
180 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
182 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
183 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
185 #ifdef CONFIG_VIDEO_LOGO
186 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
188 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
191 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
192 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
193 #define CONSOLE_ROW_FIRST (video_console_address)
194 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
195 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
196 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
198 /* By default we scroll by a single line */
199 #ifndef CONFIG_CONSOLE_SCROLL_LINES
200 #define CONFIG_CONSOLE_SCROLL_LINES 1
204 #ifdef VIDEO_FB_LITTLE_ENDIAN
205 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
208 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
209 (((x) & 0x0000ff00) << 8) | \
210 (((x) & 0x00ff0000) >> 8) | \
211 (((x) & 0xff000000) >> 24) \
213 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
214 (((x) & 0x0000ff00) >> 8) | \
215 (((x) & 0x00ff0000) << 8) | \
216 (((x) & 0xff000000) >> 8) \
219 #define SWAP16(x) (x)
220 #define SWAP32(x) (x)
221 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
222 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
224 #define SHORTSWAP32(x) (x)
228 DECLARE_GLOBAL_DATA_PTR;
231 static GraphicDevice *pGD; /* Pointer to Graphic array */
233 static void *video_fb_address; /* frame buffer address */
234 static void *video_console_address; /* console buffer start address */
236 static int video_logo_height = VIDEO_LOGO_HEIGHT;
238 static int __maybe_unused cursor_state;
239 static int __maybe_unused old_col;
240 static int __maybe_unused old_row;
242 static int console_col; /* cursor col */
243 static int console_row; /* cursor row */
245 static u32 eorx, fgx, bgx; /* color pats */
247 static int cfb_do_flush_cache;
249 #ifdef CONFIG_CFB_CONSOLE_ANSI
250 static char ansi_buf[10];
251 static int ansi_buf_size;
252 static int ansi_colors_need_revert;
253 static int ansi_cursor_hidden;
256 static const int video_font_draw_table8[] = {
257 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
258 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
259 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
260 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
263 static const int video_font_draw_table15[] = {
264 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
267 static const int video_font_draw_table16[] = {
268 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
271 static const int video_font_draw_table24[16][3] = {
272 {0x00000000, 0x00000000, 0x00000000},
273 {0x00000000, 0x00000000, 0x00ffffff},
274 {0x00000000, 0x0000ffff, 0xff000000},
275 {0x00000000, 0x0000ffff, 0xffffffff},
276 {0x000000ff, 0xffff0000, 0x00000000},
277 {0x000000ff, 0xffff0000, 0x00ffffff},
278 {0x000000ff, 0xffffffff, 0xff000000},
279 {0x000000ff, 0xffffffff, 0xffffffff},
280 {0xffffff00, 0x00000000, 0x00000000},
281 {0xffffff00, 0x00000000, 0x00ffffff},
282 {0xffffff00, 0x0000ffff, 0xff000000},
283 {0xffffff00, 0x0000ffff, 0xffffffff},
284 {0xffffffff, 0xffff0000, 0x00000000},
285 {0xffffffff, 0xffff0000, 0x00ffffff},
286 {0xffffffff, 0xffffffff, 0xff000000},
287 {0xffffffff, 0xffffffff, 0xffffffff}
290 static const int video_font_draw_table32[16][4] = {
291 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
292 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
293 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
294 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
295 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
296 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
297 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
298 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
299 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
300 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
301 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
302 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
303 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
304 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
305 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
306 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
310 * Implement a weak default function for boards that optionally
311 * need to skip the cfb initialization.
313 __weak int board_cfb_skip(void)
315 /* As default, don't skip cfb init */
319 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
321 u8 *cdat, *dest, *dest0;
324 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
325 dest0 = video_fb_address + offset;
327 switch (VIDEO_DATA_FORMAT) {
328 case GDF__8BIT_INDEX:
329 case GDF__8BIT_332RGB:
332 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
333 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
334 rows--; dest += VIDEO_LINE_LEN) {
338 (video_font_draw_table8[bits >> 4] &
341 if (VIDEO_FONT_WIDTH == 4)
345 (video_font_draw_table8[bits & 15] &
348 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
353 case GDF_15BIT_555RGB:
356 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
357 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
358 rows--; dest += VIDEO_LINE_LEN) {
362 SHORTSWAP32((video_font_draw_table15
363 [bits >> 6] & eorx) ^
366 SHORTSWAP32((video_font_draw_table15
367 [bits >> 4 & 3] & eorx) ^
370 if (VIDEO_FONT_WIDTH == 4)
374 SHORTSWAP32((video_font_draw_table15
375 [bits >> 2 & 3] & eorx) ^
378 SHORTSWAP32((video_font_draw_table15
382 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
387 case GDF_16BIT_565RGB:
390 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
391 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
392 rows--; dest += VIDEO_LINE_LEN) {
396 SHORTSWAP32((video_font_draw_table16
397 [bits >> 6] & eorx) ^
400 SHORTSWAP32((video_font_draw_table16
401 [bits >> 4 & 3] & eorx) ^
404 if (VIDEO_FONT_WIDTH == 4)
408 SHORTSWAP32((video_font_draw_table16
409 [bits >> 2 & 3] & eorx) ^
412 SHORTSWAP32((video_font_draw_table16
416 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
421 case GDF_32BIT_X888RGB:
424 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
425 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
426 rows--; dest += VIDEO_LINE_LEN) {
430 SWAP32((video_font_draw_table32
431 [bits >> 4][0] & eorx) ^ bgx);
433 SWAP32((video_font_draw_table32
434 [bits >> 4][1] & eorx) ^ bgx);
436 SWAP32((video_font_draw_table32
437 [bits >> 4][2] & eorx) ^ bgx);
439 SWAP32((video_font_draw_table32
440 [bits >> 4][3] & eorx) ^ bgx);
443 if (VIDEO_FONT_WIDTH == 4)
447 SWAP32((video_font_draw_table32
448 [bits & 15][0] & eorx) ^ bgx);
450 SWAP32((video_font_draw_table32
451 [bits & 15][1] & eorx) ^ bgx);
453 SWAP32((video_font_draw_table32
454 [bits & 15][2] & eorx) ^ bgx);
456 SWAP32((video_font_draw_table32
457 [bits & 15][3] & eorx) ^ bgx);
459 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
464 case GDF_24BIT_888RGB:
467 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
468 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
469 rows--; dest += VIDEO_LINE_LEN) {
473 (video_font_draw_table24[bits >> 4][0]
476 (video_font_draw_table24[bits >> 4][1]
479 (video_font_draw_table24[bits >> 4][2]
482 if (VIDEO_FONT_WIDTH == 4)
486 (video_font_draw_table24[bits & 15][0]
489 (video_font_draw_table24[bits & 15][1]
492 (video_font_draw_table24[bits & 15][2]
495 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
502 static inline void video_drawstring(int xx, int yy, unsigned char *s)
504 video_drawchars(xx, yy, s, strlen((char *) s));
507 static void video_putchar(int xx, int yy, unsigned char c)
509 video_drawchars(xx, yy + video_logo_height, &c, 1);
512 #if defined(CONFIG_VIDEO_SW_CURSOR)
513 static void video_set_cursor(void)
520 static void video_invertchar(int xx, int yy)
522 int firstx = xx * VIDEO_PIXEL_SIZE;
523 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
524 int firsty = yy * VIDEO_LINE_LEN;
525 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
527 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
528 for (x = firstx; x < lastx; x++) {
529 u8 *dest = (u8 *)(video_fb_address) + x + y;
535 void console_cursor(int state)
537 if (cursor_state != state) {
539 /* turn off the cursor */
540 video_invertchar(old_col * VIDEO_FONT_WIDTH,
541 old_row * VIDEO_FONT_HEIGHT +
544 /* turn off the cursor and record where it is */
545 video_invertchar(console_col * VIDEO_FONT_WIDTH,
546 console_row * VIDEO_FONT_HEIGHT +
548 old_col = console_col;
549 old_row = console_row;
551 cursor_state = state;
553 if (cfb_do_flush_cache)
554 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
558 #ifndef VIDEO_HW_RECTFILL
559 static void memsetl(int *p, int c, int v)
566 #ifndef VIDEO_HW_BITBLT
567 static void memcpyl(int *d, int *s, int c)
574 static void console_clear_line(int line, int begin, int end)
576 #ifdef VIDEO_HW_RECTFILL
577 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
578 VIDEO_FONT_WIDTH * begin, /* dest pos x */
580 VIDEO_FONT_HEIGHT * line, /* dest pos y */
581 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
582 VIDEO_FONT_HEIGHT, /* frame height */
586 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
587 memsetl(CONSOLE_ROW_FIRST +
588 CONSOLE_ROW_SIZE * line, /* offset of row */
589 CONSOLE_ROW_SIZE >> 2, /* length of row */
596 offset = CONSOLE_ROW_FIRST +
597 CONSOLE_ROW_SIZE * line + /* offset of row */
599 VIDEO_PIXEL_SIZE * begin; /* offset of col */
600 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
601 size >>= 2; /* length to end for memsetl() */
602 /* fill at col offset of i'th line using bgx as fill color */
603 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
604 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
609 static void console_scrollup(void)
611 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
614 /* copy up rows ignoring the first one */
616 #ifdef VIDEO_HW_BITBLT
617 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
618 0, /* source pos x */
620 VIDEO_FONT_HEIGHT * rows, /* source pos y */
622 video_logo_height, /* dest pos y */
623 VIDEO_VISIBLE_COLS, /* frame width */
626 - VIDEO_FONT_HEIGHT * rows /* frame height */
629 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
630 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
632 /* clear the last one */
633 for (i = 1; i <= rows; i++)
634 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
636 /* Decrement row number */
640 static void console_back(void)
644 if (console_col < 0) {
645 console_col = CONSOLE_COLS - 1;
652 #ifdef CONFIG_CFB_CONSOLE_ANSI
654 static void console_clear(void)
656 #ifdef VIDEO_HW_RECTFILL
657 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
659 video_logo_height, /* dest pos y */
660 VIDEO_VISIBLE_COLS, /* frame width */
661 VIDEO_VISIBLE_ROWS, /* frame height */
665 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
669 static void console_cursor_fix(void)
673 if (console_row >= CONSOLE_ROWS)
674 console_row = CONSOLE_ROWS - 1;
677 if (console_col >= CONSOLE_COLS)
678 console_col = CONSOLE_COLS - 1;
681 static void console_cursor_up(int n)
684 console_cursor_fix();
687 static void console_cursor_down(int n)
690 console_cursor_fix();
693 static void console_cursor_left(int n)
696 console_cursor_fix();
699 static void console_cursor_right(int n)
702 console_cursor_fix();
705 static void console_cursor_set_position(int row, int col)
707 if (console_row != -1)
709 if (console_col != -1)
711 console_cursor_fix();
714 static void console_previousline(int n)
716 /* FIXME: also scroll terminal ? */
718 console_cursor_fix();
721 static void console_swap_colors(void)
729 static inline int console_cursor_is_visible(void)
731 return !ansi_cursor_hidden;
734 static inline int console_cursor_is_visible(void)
740 static void console_newline(int n)
745 /* Check if we need to scroll the terminal */
746 if (console_row >= CONSOLE_ROWS) {
747 /* Scroll everything up */
752 static void console_cr(void)
757 static void parse_putc(const char c)
761 if (console_cursor_is_visible())
765 case 13: /* back to first column */
769 case '\n': /* next line */
770 if (console_col || nl)
776 console_col |= 0x0008;
777 console_col &= ~0x0007;
779 if (console_col >= CONSOLE_COLS)
783 case 8: /* backspace */
790 default: /* draw the char */
791 video_putchar(console_col * VIDEO_FONT_WIDTH,
792 console_row * VIDEO_FONT_HEIGHT, c);
795 /* check for newline */
796 if (console_col >= CONSOLE_COLS) {
802 if (console_cursor_is_visible())
806 static void cfb_video_putc(struct stdio_dev *dev, const char c)
808 #ifdef CONFIG_CFB_CONSOLE_ANSI
812 for (i = 0; i < ansi_buf_size; ++i)
813 parse_putc(ansi_buf[i]);
819 if (ansi_buf_size > 0) {
839 ansi_buf[ansi_buf_size++] = c;
841 if (ansi_buf_size >= sizeof(ansi_buf))
844 for (i = 0; i < ansi_buf_size; ++i) {
850 if (ansi_buf[i] == 27)
857 if (ansi_buf[i] == '[')
864 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
865 num1 = ansi_buf[i]-'0';
867 } else if (ansi_buf[i] != '?') {
875 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
877 num1 += ansi_buf[i]-'0';
885 if (ansi_buf[i] != ';') {
893 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
894 num2 = ansi_buf[i]-'0';
901 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
903 num2 += ansi_buf[i]-'0';
911 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
912 || ansi_buf[i] == 'J'
913 || ansi_buf[i] == 'K'
914 || ansi_buf[i] == 'h'
915 || ansi_buf[i] == 'l'
916 || ansi_buf[i] == 'm') {
926 for (i = 0; i < ansi_buf_size; ++i)
927 parse_putc(ansi_buf[i]);
933 if (!ansi_cursor_hidden)
938 /* move cursor num1 rows up */
939 console_cursor_up(num1);
942 /* move cursor num1 rows down */
943 console_cursor_down(num1);
946 /* move cursor num1 columns forward */
947 console_cursor_right(num1);
950 /* move cursor num1 columns back */
951 console_cursor_left(num1);
954 /* move cursor num1 rows up at begin of row */
955 console_previousline(num1);
958 /* move cursor num1 rows down at begin of row */
959 console_newline(num1);
962 /* move cursor to column num1 */
963 console_cursor_set_position(-1, num1-1);
966 /* move cursor to row num1, column num2 */
967 console_cursor_set_position(num1-1, num2-1);
970 /* clear console and move cursor to 0, 0 */
972 console_cursor_set_position(0, 0);
977 console_clear_line(console_row,
981 console_clear_line(console_row,
984 console_clear_line(console_row,
988 ansi_cursor_hidden = 0;
991 ansi_cursor_hidden = 1;
994 if (num1 == 0) { /* reset swapped colors */
995 if (ansi_colors_need_revert) {
996 console_swap_colors();
997 ansi_colors_need_revert = 0;
999 } else if (num1 == 7) { /* once swap colors */
1000 if (!ansi_colors_need_revert) {
1001 console_swap_colors();
1002 ansi_colors_need_revert = 1;
1007 if (!ansi_cursor_hidden)
1016 if (cfb_do_flush_cache)
1017 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1020 static void cfb_video_puts(struct stdio_dev *dev, const char *s)
1022 int flush = cfb_do_flush_cache;
1023 int count = strlen(s);
1025 /* temporarily disable cache flush */
1026 cfb_do_flush_cache = 0;
1029 cfb_video_putc(dev, *s++);
1032 cfb_do_flush_cache = flush;
1033 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1038 * Do not enforce drivers (or board code) to provide empty
1039 * video_set_lut() if they do not support 8 bpp format.
1040 * Implement weak default function instead.
1042 __weak void video_set_lut(unsigned int index, unsigned char r,
1043 unsigned char g, unsigned char b)
1047 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1049 #define FILL_8BIT_332RGB(r,g,b) { \
1050 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1054 #define FILL_15BIT_555RGB(r,g,b) { \
1055 *(unsigned short *)fb = \
1056 SWAP16((unsigned short)(((r>>3)<<10) | \
1062 #define FILL_16BIT_565RGB(r,g,b) { \
1063 *(unsigned short *)fb = \
1064 SWAP16((unsigned short)((((r)>>3)<<11)| \
1070 #define FILL_32BIT_X888RGB(r,g,b) { \
1072 SWAP32((unsigned int)(((r<<16) | \
1078 #ifdef VIDEO_FB_LITTLE_ENDIAN
1079 #define FILL_24BIT_888RGB(r,g,b) { \
1086 #define FILL_24BIT_888RGB(r,g,b) { \
1094 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1095 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1097 ushort *dst = (ushort *) fb;
1098 ushort color = (ushort) (((r >> 3) << 10) |
1109 * RLE8 bitmap support
1112 #ifdef CONFIG_VIDEO_BMP_RLE8
1113 /* Pre-calculated color table entry */
1116 unsigned short w; /* word */
1117 unsigned int dw; /* double word */
1118 } ce; /* color entry */
1122 * Helper to draw encoded/unencoded run.
1124 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1127 ulong addr = (ulong) *fb;
1133 * Setup offset of the color index in the bitmap.
1134 * Color index of encoded run is at offset 1.
1136 off = enc ? &enc_off : &i;
1138 switch (VIDEO_DATA_FORMAT) {
1139 case GDF__8BIT_INDEX:
1140 for (i = 0; i < cnt; i++)
1141 *(unsigned char *) addr++ = bm[*off];
1143 case GDF_15BIT_555RGB:
1144 case GDF_16BIT_565RGB:
1145 /* differences handled while pre-calculating palette */
1146 for (i = 0; i < cnt; i++) {
1147 *(unsigned short *) addr = p[bm[*off]].ce.w;
1151 case GDF_32BIT_X888RGB:
1152 for (i = 0; i < cnt; i++) {
1153 *(u32 *) addr = p[bm[*off]].ce.dw;
1158 *fb = (uchar *) addr; /* return modified address */
1161 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1162 int width, int height)
1166 unsigned int cnt, runlen;
1168 int x, y, bpp, i, ncolors;
1169 struct palette p[256];
1170 struct bmp_color_table_entry cte;
1171 int green_shift, red_off;
1172 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1176 y = __le32_to_cpu(img->header.height) - 1;
1177 ncolors = __le32_to_cpu(img->header.colors_used);
1178 bpp = VIDEO_PIXEL_SIZE;
1179 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1180 (y + yoff) * VIDEO_LINE_LEN +
1183 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1185 /* pre-calculate and setup palette */
1186 switch (VIDEO_DATA_FORMAT) {
1187 case GDF__8BIT_INDEX:
1188 for (i = 0; i < ncolors; i++) {
1189 cte = img->color_table[i];
1190 video_set_lut(i, cte.red, cte.green, cte.blue);
1193 case GDF_15BIT_555RGB:
1194 case GDF_16BIT_565RGB:
1195 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1202 for (i = 0; i < ncolors; i++) {
1203 cte = img->color_table[i];
1204 p[i].ce.w = SWAP16((unsigned short)
1205 (((cte.red >> 3) << red_off) |
1206 ((cte.green >> green_shift) << 5) |
1210 case GDF_32BIT_X888RGB:
1211 for (i = 0; i < ncolors; i++) {
1212 cte = img->color_table[i];
1213 p[i].ce.dw = SWAP32((cte.red << 16) |
1219 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1229 /* scan line end marker */
1233 fbp = (unsigned char *)
1234 ((unsigned int) video_fb_address +
1235 (y + yoff) * VIDEO_LINE_LEN +
1239 /* end of bitmap data marker */
1243 /* run offset marker */
1246 fbp = (unsigned char *)
1247 ((unsigned int) video_fb_address +
1248 (y + yoff) * VIDEO_LINE_LEN +
1266 if (x + runlen > width)
1268 draw_bitmap(&fbp, bm, p, cnt, 0);
1274 bm++; /* 0 padding if length is odd */
1285 if (y < height) { /* only draw into visible area */
1291 if (x + runlen > width)
1293 draw_bitmap(&fbp, bm, p, cnt, 1);
1301 if (cfb_do_flush_cache)
1302 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1306 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1312 * Display the BMP file located at address bmp_image.
1314 int video_display_bitmap(ulong bmp_image, int x, int y)
1316 ushort xcount, ycount;
1318 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1321 unsigned long width, height, bpp;
1323 unsigned long compression;
1324 struct bmp_color_table_entry cte;
1326 #ifdef CONFIG_VIDEO_BMP_GZIP
1327 unsigned char *dst = NULL;
1333 if (!((bmp->header.signature[0] == 'B') &&
1334 (bmp->header.signature[1] == 'M'))) {
1336 #ifdef CONFIG_VIDEO_BMP_GZIP
1338 * Could be a gzipped bmp image, try to decrompress...
1340 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1341 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1343 printf("Error: malloc in gunzip failed!\n");
1347 * NB: we need to force offset of +2
1348 * See doc/README.displaying-bmps
1350 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1351 (uchar *) bmp_image,
1353 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1358 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1359 printf("Image could be truncated "
1360 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1364 * Set addr to decompressed image
1366 bmp = (struct bmp_image *)(dst+2);
1368 if (!((bmp->header.signature[0] == 'B') &&
1369 (bmp->header.signature[1] == 'M'))) {
1370 printf("Error: no valid bmp.gz image at %lx\n",
1376 printf("Error: no valid bmp image at %lx\n", bmp_image);
1378 #endif /* CONFIG_VIDEO_BMP_GZIP */
1381 width = le32_to_cpu(bmp->header.width);
1382 height = le32_to_cpu(bmp->header.height);
1383 bpp = le16_to_cpu(bmp->header.bit_count);
1384 colors = le32_to_cpu(bmp->header.colors_used);
1385 compression = le32_to_cpu(bmp->header.compression);
1387 debug("Display-bmp: %ld x %ld with %d colors\n",
1388 width, height, colors);
1390 if (compression != BMP_BI_RGB
1391 #ifdef CONFIG_VIDEO_BMP_RLE8
1392 && compression != BMP_BI_RLE8
1395 printf("Error: compression type %ld not supported\n",
1397 #ifdef CONFIG_VIDEO_BMP_GZIP
1404 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1406 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1407 if (x == BMP_ALIGN_CENTER)
1408 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1410 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1412 if (y == BMP_ALIGN_CENTER)
1413 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1415 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1416 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1419 * Just ignore elements which are completely beyond screen
1422 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1425 if ((x + width) > VIDEO_VISIBLE_COLS)
1426 width = VIDEO_VISIBLE_COLS - x;
1427 if ((y + height) > VIDEO_VISIBLE_ROWS)
1428 height = VIDEO_VISIBLE_ROWS - y;
1430 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1431 fb = (uchar *) (video_fb_address +
1432 ((y + height - 1) * VIDEO_LINE_LEN) +
1433 x * VIDEO_PIXEL_SIZE);
1435 #ifdef CONFIG_VIDEO_BMP_RLE8
1436 if (compression == BMP_BI_RLE8) {
1437 return display_rle8_bitmap(bmp, x, y, width, height);
1441 /* We handle only 4, 8, or 24 bpp bitmaps */
1442 switch (le16_to_cpu(bmp->header.bit_count)) {
1444 padded_line -= width / 2;
1447 switch (VIDEO_DATA_FORMAT) {
1448 case GDF_32BIT_X888RGB:
1452 * Don't assume that 'width' is an
1455 for (xcount = 0; xcount < width; xcount++) {
1463 cte = bmp->color_table[idx];
1464 FILL_32BIT_X888RGB(cte.red, cte.green,
1467 bmap += padded_line;
1468 fb -= VIDEO_LINE_LEN + width *
1473 puts("4bpp bitmap unsupported with current "
1480 padded_line -= width;
1481 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1483 for (xcount = 0; xcount < colors; ++xcount) {
1484 cte = bmp->color_table[xcount];
1485 video_set_lut(xcount, cte.red, cte.green,
1490 switch (VIDEO_DATA_FORMAT) {
1491 case GDF__8BIT_INDEX:
1498 bmap += padded_line;
1499 fb -= VIDEO_LINE_LEN + width *
1503 case GDF__8BIT_332RGB:
1508 cte = bmp->color_table[*bmap++];
1509 FILL_8BIT_332RGB(cte.red, cte.green,
1512 bmap += padded_line;
1513 fb -= VIDEO_LINE_LEN + width *
1517 case GDF_15BIT_555RGB:
1519 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1525 cte = bmp->color_table[*bmap++];
1526 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1527 fill_555rgb_pswap(fb, xpos++, cte.red,
1532 FILL_15BIT_555RGB(cte.red, cte.green,
1536 bmap += padded_line;
1537 fb -= VIDEO_LINE_LEN + width *
1541 case GDF_16BIT_565RGB:
1546 cte = bmp->color_table[*bmap++];
1547 FILL_16BIT_565RGB(cte.red, cte.green,
1550 bmap += padded_line;
1551 fb -= VIDEO_LINE_LEN + width *
1555 case GDF_32BIT_X888RGB:
1560 cte = bmp->color_table[*bmap++];
1561 FILL_32BIT_X888RGB(cte.red, cte.green,
1564 bmap += padded_line;
1565 fb -= VIDEO_LINE_LEN + width *
1569 case GDF_24BIT_888RGB:
1574 cte = bmp->color_table[*bmap++];
1575 FILL_24BIT_888RGB(cte.red, cte.green,
1578 bmap += padded_line;
1579 fb -= VIDEO_LINE_LEN + width *
1586 padded_line -= 3 * width;
1588 switch (VIDEO_DATA_FORMAT) {
1589 case GDF__8BIT_332RGB:
1594 FILL_8BIT_332RGB(bmap[2], bmap[1],
1598 bmap += padded_line;
1599 fb -= VIDEO_LINE_LEN + width *
1603 case GDF_15BIT_555RGB:
1605 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1611 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1612 fill_555rgb_pswap(fb, xpos++, bmap[2],
1616 FILL_15BIT_555RGB(bmap[2], bmap[1],
1621 bmap += padded_line;
1622 fb -= VIDEO_LINE_LEN + width *
1626 case GDF_16BIT_565RGB:
1631 FILL_16BIT_565RGB(bmap[2], bmap[1],
1635 bmap += padded_line;
1636 fb -= VIDEO_LINE_LEN + width *
1640 case GDF_32BIT_X888RGB:
1645 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1649 bmap += padded_line;
1650 fb -= VIDEO_LINE_LEN + width *
1654 case GDF_24BIT_888RGB:
1659 FILL_24BIT_888RGB(bmap[2], bmap[1],
1663 bmap += padded_line;
1664 fb -= VIDEO_LINE_LEN + width *
1669 printf("Error: 24 bits/pixel bitmap incompatible "
1670 "with current video mode\n");
1675 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1676 le16_to_cpu(bmp->header.bit_count));
1680 #ifdef CONFIG_VIDEO_BMP_GZIP
1686 if (cfb_do_flush_cache)
1687 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1693 #ifdef CONFIG_VIDEO_LOGO
1694 static int video_logo_xpos;
1695 static int video_logo_ypos;
1697 static void plot_logo_or_black(void *screen, int x, int y, int black);
1699 static void logo_plot(void *screen, int x, int y)
1701 plot_logo_or_black(screen, x, y, 0);
1704 static void logo_black(void)
1706 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1710 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1713 return cmd_usage(cmdtp);
1720 clrlogo, 1, 0, do_clrlogo,
1721 "fill the boot logo area with black",
1725 static void plot_logo_or_black(void *screen, int x, int y, int black)
1729 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1730 int ycount = video_logo_height;
1731 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1732 unsigned char *source;
1733 unsigned char *dest;
1735 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1736 if (x == BMP_ALIGN_CENTER)
1737 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1739 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1741 if (y == BMP_ALIGN_CENTER)
1742 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1744 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1745 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1747 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1749 #ifdef CONFIG_VIDEO_BMP_LOGO
1750 source = bmp_logo_bitmap;
1752 /* Allocate temporary space for computing colormap */
1753 logo_red = malloc(BMP_LOGO_COLORS);
1754 logo_green = malloc(BMP_LOGO_COLORS);
1755 logo_blue = malloc(BMP_LOGO_COLORS);
1756 /* Compute color map */
1757 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1758 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1759 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1760 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1763 source = linux_logo;
1764 logo_red = linux_logo_red;
1765 logo_green = linux_logo_green;
1766 logo_blue = linux_logo_blue;
1769 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1770 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1771 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1772 logo_red[i], logo_green[i],
1778 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1781 xcount = VIDEO_LOGO_WIDTH;
1788 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1789 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1790 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1793 switch (VIDEO_DATA_FORMAT) {
1794 case GDF__8BIT_INDEX:
1797 case GDF__8BIT_332RGB:
1798 *dest = ((r >> 5) << 5) |
1802 case GDF_15BIT_555RGB:
1803 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1804 fill_555rgb_pswap(dest, xpos++, r, g, b);
1806 *(unsigned short *) dest =
1807 SWAP16((unsigned short) (
1813 case GDF_16BIT_565RGB:
1814 *(unsigned short *) dest =
1815 SWAP16((unsigned short) (
1820 case GDF_32BIT_X888RGB:
1827 case GDF_24BIT_888RGB:
1828 #ifdef VIDEO_FB_LITTLE_ENDIAN
1840 dest += VIDEO_PIXEL_SIZE;
1844 #ifdef CONFIG_VIDEO_BMP_LOGO
1851 static void *video_logo(void)
1854 __maybe_unused int y_off = 0;
1855 __maybe_unused ulong addr;
1856 __maybe_unused char *s;
1857 __maybe_unused int len, ret, space;
1859 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1861 #ifdef CONFIG_SPLASH_SCREEN
1862 s = env_get("splashimage");
1864 ret = splash_screen_prepare();
1866 return video_fb_address;
1867 addr = simple_strtoul(s, NULL, 16);
1869 if (video_display_bitmap(addr,
1871 video_logo_ypos) == 0) {
1872 video_logo_height = 0;
1873 return ((void *) (video_fb_address));
1876 #endif /* CONFIG_SPLASH_SCREEN */
1878 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1880 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1882 * when using splashpos for video_logo, skip any info
1883 * output on video console if the logo is not at 0,0
1885 if (video_logo_xpos || video_logo_ypos) {
1887 * video_logo_height is used in text and cursor offset
1888 * calculations. Since the console is below the logo,
1889 * we need to adjust the logo height
1891 if (video_logo_ypos == BMP_ALIGN_CENTER)
1892 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1893 VIDEO_LOGO_HEIGHT) / 2);
1894 else if (video_logo_ypos > 0)
1895 video_logo_height += video_logo_ypos;
1897 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1900 if (board_cfb_skip())
1903 sprintf(info, " %s", version_string);
1905 #ifndef CONFIG_HIDE_LOGO_VERSION
1906 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1910 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1911 uchar *p = (uchar *) info;
1915 video_drawchars(xx, yy, p, space);
1918 p = (uchar *)p + space;
1921 xx += VIDEO_FONT_WIDTH;
1924 yy += VIDEO_FONT_HEIGHT;
1928 video_drawchars(xx, yy, p, len);
1933 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1935 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1938 ((video_logo_height -
1939 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1941 for (i = 1; i < n; i++) {
1942 video_get_info_str(i, info);
1948 video_drawchars(VIDEO_INFO_X,
1952 (uchar *) info, space);
1954 video_drawchars(VIDEO_INFO_X +
1959 (uchar *) info + space,
1962 video_drawstring(VIDEO_INFO_X,
1973 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1977 static int cfb_fb_is_in_dram(void)
1980 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
1981 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1985 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1986 start = bd->bi_dram[i].start;
1987 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1988 if ((ulong)video_fb_address >= start &&
1989 (ulong)video_fb_address < end)
1993 if ((ulong)video_fb_address >= bd->bi_memstart &&
1994 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2000 void video_clear(void)
2002 if (!video_fb_address)
2004 #ifdef VIDEO_HW_RECTFILL
2005 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2008 VIDEO_VISIBLE_COLS, /* frame width */
2009 VIDEO_VISIBLE_ROWS, /* frame height */
2010 bgx /* fill color */
2013 memsetl(video_fb_address,
2014 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2018 static int cfg_video_init(void)
2020 unsigned char color8;
2022 pGD = video_hw_init();
2026 video_fb_address = (void *) VIDEO_FB_ADRS;
2028 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2030 /* Init drawing pats */
2031 switch (VIDEO_DATA_FORMAT) {
2032 case GDF__8BIT_INDEX:
2033 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2034 CONFIG_SYS_CONSOLE_FG_COL,
2035 CONFIG_SYS_CONSOLE_FG_COL);
2036 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2037 CONFIG_SYS_CONSOLE_BG_COL,
2038 CONFIG_SYS_CONSOLE_BG_COL);
2042 case GDF__8BIT_332RGB:
2043 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2044 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2045 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2046 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2048 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2049 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2050 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2051 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2054 case GDF_15BIT_555RGB:
2055 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2056 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2057 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2058 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2059 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2060 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2061 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2062 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2063 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2064 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2065 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2066 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2068 case GDF_16BIT_565RGB:
2069 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2070 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2071 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2072 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2073 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2074 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2075 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2076 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2077 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2078 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2079 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2080 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2082 case GDF_32BIT_X888RGB:
2083 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2084 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2085 CONFIG_SYS_CONSOLE_FG_COL;
2086 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2087 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2088 CONFIG_SYS_CONSOLE_BG_COL;
2090 case GDF_24BIT_888RGB:
2091 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2092 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2093 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2094 CONFIG_SYS_CONSOLE_FG_COL;
2095 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2096 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2097 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2098 CONFIG_SYS_CONSOLE_BG_COL;
2103 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2106 #ifdef CONFIG_VIDEO_LOGO
2107 /* Plot the logo and get start point of console */
2108 debug("Video: Drawing the logo ...\n");
2109 video_console_address = video_logo();
2111 video_console_address = video_fb_address;
2114 /* Initialize the console */
2118 if (cfb_do_flush_cache)
2119 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2125 * Implement a weak default function for boards that optionally
2126 * need to skip the video initialization.
2128 __weak int board_video_skip(void)
2130 /* As default, don't skip test */
2134 int drv_video_init(void)
2136 struct stdio_dev console_dev;
2138 bool __maybe_unused keyboard_ok = false;
2140 /* Check if video initialization should be skipped */
2141 if (board_video_skip())
2144 /* Init video chip - returns with framebuffer cleared */
2145 if (cfg_video_init() == -1)
2148 if (board_cfb_skip())
2151 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2152 have_keyboard = false;
2153 #elif defined(CONFIG_OF_CONTROL)
2154 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2155 "u-boot,no-keyboard");
2157 have_keyboard = true;
2159 if (have_keyboard) {
2160 debug("KBD: Keyboard init ...\n");
2161 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2162 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2166 /* Init vga device */
2167 memset(&console_dev, 0, sizeof(console_dev));
2168 strcpy(console_dev.name, "vga");
2169 console_dev.flags = DEV_FLAGS_OUTPUT;
2170 console_dev.putc = cfb_video_putc; /* 'putc' function */
2171 console_dev.puts = cfb_video_puts; /* 'puts' function */
2173 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2174 if (have_keyboard && keyboard_ok) {
2175 /* Also init console device */
2176 console_dev.flags |= DEV_FLAGS_INPUT;
2177 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2178 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2182 if (stdio_register(&console_dev) != 0)
2185 /* Return success */
2189 void video_position_cursor(unsigned col, unsigned row)
2191 console_col = min(col, CONSOLE_COLS - 1);
2192 console_row = min(row, CONSOLE_ROWS - 1);
2195 int video_get_pixel_width(void)
2197 return VIDEO_VISIBLE_COLS;
2200 int video_get_pixel_height(void)
2202 return VIDEO_VISIBLE_ROWS;
2205 int video_get_screen_rows(void)
2207 return CONSOLE_ROWS;
2210 int video_get_screen_columns(void)
2212 return CONSOLE_COLS;