2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * SPDX-License-Identifier: GPL-2.0+
11 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
13 * At the moment only the 8x16 font is tested and the font fore- and
14 * background color is limited to black/white/gray colors. The Linux
15 * logo can be placed in the upper left corner and additional board
16 * information strings (that normally goes to serial port) can be drawn.
18 * The console driver can use a keyboard interface for character input
19 * but this is deprecated. Only rk51 uses it.
21 * Character output goes to a memory-mapped video
22 * framebuffer with little or big-endian organisation.
23 * With environment setting 'console=serial' the console i/o can be
24 * forced to serial port.
26 * The driver uses graphic specific defines/parameters/functions:
28 * (for SMI LynxE graphic chip)
30 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
31 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
32 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
34 * Console Parameters are set by graphic drivers global struct:
36 * VIDEO_VISIBLE_COLS - x resolution
37 * VIDEO_VISIBLE_ROWS - y resolution
38 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
39 * VIDEO_DATA_FORMAT - graphical data format GDF
40 * VIDEO_FB_ADRS - start of video memory
42 * VIDEO_KBD_INIT_FCT - init function for keyboard
43 * VIDEO_TSTC_FCT - keyboard_tstc function
44 * VIDEO_GETC_FCT - keyboard_getc function
46 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
47 * Use CONFIG_SPLASH_SCREEN_ALIGN with
48 * environment variable "splashpos" to place
49 * the logo on other position. In this case
50 * no CONSOLE_EXTRA_INFO is possible.
51 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
52 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
53 * strings that normaly goes to serial
54 * port. This define requires a board
56 * video_drawstring (VIDEO_INFO_X,
57 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
59 * that fills a info buffer at i=row.
60 * s.a: board/eltec/bab7xx.
62 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
63 * character. No blinking is provided.
64 * Uses the macros CURSOR_SET and
72 #include <linux/compiler.h>
75 * Defines for the CT69000 driver
77 #ifdef CONFIG_VIDEO_CT69000
79 #define VIDEO_FB_LITTLE_ENDIAN
80 #define VIDEO_HW_RECTFILL
81 #define VIDEO_HW_BITBLT
84 #if defined(CONFIG_VIDEO_MXS)
85 #define VIDEO_FB_16BPP_WORD_SWAP
89 * Defines for the MB862xx driver
91 #ifdef CONFIG_VIDEO_MB862xx
93 #ifdef CONFIG_VIDEO_CORALP
94 #define VIDEO_FB_LITTLE_ENDIAN
96 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
97 #define VIDEO_HW_RECTFILL
98 #define VIDEO_HW_BITBLT
103 * Defines for the i.MX31 driver (mx3fb.c)
105 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
106 #define VIDEO_FB_16BPP_WORD_SWAP
110 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
112 #include <video_fb.h>
119 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
120 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
121 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
122 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
123 #define VIDEO_FB_ADRS (pGD->frameAdrs)
130 #include <linux/types.h>
131 #include <stdio_dev.h>
132 #include <video_font.h>
134 #if defined(CONFIG_CMD_DATE)
138 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
139 #include <watchdog.h>
140 #include <bmp_layout.h>
146 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
147 * blinking is provided. Uses the macros CURSOR_SET
150 #if !defined(CONFIG_VIDEO_SW_CURSOR)
151 /* no Cursor defined */
157 #if defined(CONFIG_VIDEO_SW_CURSOR)
158 void console_cursor(int state);
160 #define CURSOR_ON console_cursor(1)
161 #define CURSOR_OFF console_cursor(0)
162 #define CURSOR_SET video_set_cursor()
163 #endif /* CONFIG_VIDEO_SW_CURSOR */
165 #ifdef CONFIG_VIDEO_LOGO
166 #ifdef CONFIG_VIDEO_BMP_LOGO
167 #include <bmp_logo.h>
168 #include <bmp_logo_data.h>
169 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
170 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
171 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
172 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
174 #else /* CONFIG_VIDEO_BMP_LOGO */
175 #define LINUX_LOGO_WIDTH 80
176 #define LINUX_LOGO_HEIGHT 80
177 #define LINUX_LOGO_COLORS 214
178 #define LINUX_LOGO_LUT_OFFSET 0x20
180 #include <linux_logo.h>
181 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
182 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
183 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
184 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
185 #endif /* CONFIG_VIDEO_BMP_LOGO */
186 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
187 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
188 #else /* CONFIG_VIDEO_LOGO */
189 #define VIDEO_LOGO_WIDTH 0
190 #define VIDEO_LOGO_HEIGHT 0
191 #endif /* CONFIG_VIDEO_LOGO */
193 #define VIDEO_COLS VIDEO_VISIBLE_COLS
194 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
195 #ifndef VIDEO_LINE_LEN
196 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
198 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
199 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
201 #ifdef CONFIG_VIDEO_LOGO
202 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
204 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
207 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
208 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
209 #define CONSOLE_ROW_FIRST (video_console_address)
210 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
211 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
212 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
214 /* By default we scroll by a single line */
215 #ifndef CONFIG_CONSOLE_SCROLL_LINES
216 #define CONFIG_CONSOLE_SCROLL_LINES 1
220 #ifdef VIDEO_FB_LITTLE_ENDIAN
221 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
224 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
225 (((x) & 0x0000ff00) << 8) | \
226 (((x) & 0x00ff0000) >> 8) | \
227 (((x) & 0xff000000) >> 24) \
229 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
230 (((x) & 0x0000ff00) >> 8) | \
231 (((x) & 0x00ff0000) << 8) | \
232 (((x) & 0xff000000) >> 8) \
235 #define SWAP16(x) (x)
236 #define SWAP32(x) (x)
237 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
238 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
240 #define SHORTSWAP32(x) (x)
244 #ifdef CONFIG_CONSOLE_EXTRA_INFO
246 * setup a board string: type, speed, etc.
248 * line_number: location to place info string beside logo
249 * info: buffer for info string
251 extern void video_get_info_str(int line_number, char *info);
254 DECLARE_GLOBAL_DATA_PTR;
257 static GraphicDevice *pGD; /* Pointer to Graphic array */
259 static void *video_fb_address; /* frame buffer address */
260 static void *video_console_address; /* console buffer start address */
262 static int video_logo_height = VIDEO_LOGO_HEIGHT;
264 static int __maybe_unused cursor_state;
265 static int __maybe_unused old_col;
266 static int __maybe_unused old_row;
268 static int console_col; /* cursor col */
269 static int console_row; /* cursor row */
271 static u32 eorx, fgx, bgx; /* color pats */
273 static int cfb_do_flush_cache;
275 #ifdef CONFIG_CFB_CONSOLE_ANSI
276 static char ansi_buf[10];
277 static int ansi_buf_size;
278 static int ansi_colors_need_revert;
279 static int ansi_cursor_hidden;
282 static const int video_font_draw_table8[] = {
283 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
284 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
285 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
286 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
289 static const int video_font_draw_table15[] = {
290 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
293 static const int video_font_draw_table16[] = {
294 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
297 static const int video_font_draw_table24[16][3] = {
298 {0x00000000, 0x00000000, 0x00000000},
299 {0x00000000, 0x00000000, 0x00ffffff},
300 {0x00000000, 0x0000ffff, 0xff000000},
301 {0x00000000, 0x0000ffff, 0xffffffff},
302 {0x000000ff, 0xffff0000, 0x00000000},
303 {0x000000ff, 0xffff0000, 0x00ffffff},
304 {0x000000ff, 0xffffffff, 0xff000000},
305 {0x000000ff, 0xffffffff, 0xffffffff},
306 {0xffffff00, 0x00000000, 0x00000000},
307 {0xffffff00, 0x00000000, 0x00ffffff},
308 {0xffffff00, 0x0000ffff, 0xff000000},
309 {0xffffff00, 0x0000ffff, 0xffffffff},
310 {0xffffffff, 0xffff0000, 0x00000000},
311 {0xffffffff, 0xffff0000, 0x00ffffff},
312 {0xffffffff, 0xffffffff, 0xff000000},
313 {0xffffffff, 0xffffffff, 0xffffffff}
316 static const int video_font_draw_table32[16][4] = {
317 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
318 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
319 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
320 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
321 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
322 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
323 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
324 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
325 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
326 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
327 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
328 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
329 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
330 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
331 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
332 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
336 * Implement a weak default function for boards that optionally
337 * need to skip the cfb initialization.
339 __weak int board_cfb_skip(void)
341 /* As default, don't skip cfb init */
345 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
347 u8 *cdat, *dest, *dest0;
350 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
351 dest0 = video_fb_address + offset;
353 switch (VIDEO_DATA_FORMAT) {
354 case GDF__8BIT_INDEX:
355 case GDF__8BIT_332RGB:
358 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
359 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
360 rows--; dest += VIDEO_LINE_LEN) {
364 (video_font_draw_table8[bits >> 4] &
367 if (VIDEO_FONT_WIDTH == 4)
371 (video_font_draw_table8[bits & 15] &
374 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
379 case GDF_15BIT_555RGB:
382 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
383 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
384 rows--; dest += VIDEO_LINE_LEN) {
388 SHORTSWAP32((video_font_draw_table15
389 [bits >> 6] & eorx) ^
392 SHORTSWAP32((video_font_draw_table15
393 [bits >> 4 & 3] & eorx) ^
396 if (VIDEO_FONT_WIDTH == 4)
400 SHORTSWAP32((video_font_draw_table15
401 [bits >> 2 & 3] & eorx) ^
404 SHORTSWAP32((video_font_draw_table15
408 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
413 case GDF_16BIT_565RGB:
416 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
417 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
418 rows--; dest += VIDEO_LINE_LEN) {
422 SHORTSWAP32((video_font_draw_table16
423 [bits >> 6] & eorx) ^
426 SHORTSWAP32((video_font_draw_table16
427 [bits >> 4 & 3] & eorx) ^
430 if (VIDEO_FONT_WIDTH == 4)
434 SHORTSWAP32((video_font_draw_table16
435 [bits >> 2 & 3] & eorx) ^
438 SHORTSWAP32((video_font_draw_table16
442 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
447 case GDF_32BIT_X888RGB:
450 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
451 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
452 rows--; dest += VIDEO_LINE_LEN) {
456 SWAP32((video_font_draw_table32
457 [bits >> 4][0] & eorx) ^ bgx);
459 SWAP32((video_font_draw_table32
460 [bits >> 4][1] & eorx) ^ bgx);
462 SWAP32((video_font_draw_table32
463 [bits >> 4][2] & eorx) ^ bgx);
465 SWAP32((video_font_draw_table32
466 [bits >> 4][3] & eorx) ^ bgx);
469 if (VIDEO_FONT_WIDTH == 4)
473 SWAP32((video_font_draw_table32
474 [bits & 15][0] & eorx) ^ bgx);
476 SWAP32((video_font_draw_table32
477 [bits & 15][1] & eorx) ^ bgx);
479 SWAP32((video_font_draw_table32
480 [bits & 15][2] & eorx) ^ bgx);
482 SWAP32((video_font_draw_table32
483 [bits & 15][3] & eorx) ^ bgx);
485 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
490 case GDF_24BIT_888RGB:
493 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
494 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
495 rows--; dest += VIDEO_LINE_LEN) {
499 (video_font_draw_table24[bits >> 4][0]
502 (video_font_draw_table24[bits >> 4][1]
505 (video_font_draw_table24[bits >> 4][2]
508 if (VIDEO_FONT_WIDTH == 4)
512 (video_font_draw_table24[bits & 15][0]
515 (video_font_draw_table24[bits & 15][1]
518 (video_font_draw_table24[bits & 15][2]
521 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
528 static inline void video_drawstring(int xx, int yy, unsigned char *s)
530 video_drawchars(xx, yy, s, strlen((char *) s));
533 static void video_putchar(int xx, int yy, unsigned char c)
535 video_drawchars(xx, yy + video_logo_height, &c, 1);
538 #if defined(CONFIG_VIDEO_SW_CURSOR)
539 static void video_set_cursor(void)
546 static void video_invertchar(int xx, int yy)
548 int firstx = xx * VIDEO_PIXEL_SIZE;
549 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
550 int firsty = yy * VIDEO_LINE_LEN;
551 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
553 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
554 for (x = firstx; x < lastx; x++) {
555 u8 *dest = (u8 *)(video_fb_address) + x + y;
561 void console_cursor(int state)
563 if (cursor_state != state) {
565 /* turn off the cursor */
566 video_invertchar(old_col * VIDEO_FONT_WIDTH,
567 old_row * VIDEO_FONT_HEIGHT +
570 /* turn off the cursor and record where it is */
571 video_invertchar(console_col * VIDEO_FONT_WIDTH,
572 console_row * VIDEO_FONT_HEIGHT +
574 old_col = console_col;
575 old_row = console_row;
577 cursor_state = state;
579 if (cfb_do_flush_cache)
580 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
584 #ifndef VIDEO_HW_RECTFILL
585 static void memsetl(int *p, int c, int v)
592 #ifndef VIDEO_HW_BITBLT
593 static void memcpyl(int *d, int *s, int c)
600 static void console_clear_line(int line, int begin, int end)
602 #ifdef VIDEO_HW_RECTFILL
603 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
604 VIDEO_FONT_WIDTH * begin, /* dest pos x */
606 VIDEO_FONT_HEIGHT * line, /* dest pos y */
607 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
608 VIDEO_FONT_HEIGHT, /* frame height */
612 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
613 memsetl(CONSOLE_ROW_FIRST +
614 CONSOLE_ROW_SIZE * line, /* offset of row */
615 CONSOLE_ROW_SIZE >> 2, /* length of row */
622 offset = CONSOLE_ROW_FIRST +
623 CONSOLE_ROW_SIZE * line + /* offset of row */
625 VIDEO_PIXEL_SIZE * begin; /* offset of col */
626 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
627 size >>= 2; /* length to end for memsetl() */
628 /* fill at col offset of i'th line using bgx as fill color */
629 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
630 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
635 static void console_scrollup(void)
637 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
640 /* copy up rows ignoring the first one */
642 #ifdef VIDEO_HW_BITBLT
643 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
644 0, /* source pos x */
646 VIDEO_FONT_HEIGHT * rows, /* source pos y */
648 video_logo_height, /* dest pos y */
649 VIDEO_VISIBLE_COLS, /* frame width */
652 - VIDEO_FONT_HEIGHT * rows /* frame height */
655 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
656 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
658 /* clear the last one */
659 for (i = 1; i <= rows; i++)
660 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
662 /* Decrement row number */
666 static void console_back(void)
670 if (console_col < 0) {
671 console_col = CONSOLE_COLS - 1;
678 #ifdef CONFIG_CFB_CONSOLE_ANSI
680 static void console_clear(void)
682 #ifdef VIDEO_HW_RECTFILL
683 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
685 video_logo_height, /* dest pos y */
686 VIDEO_VISIBLE_COLS, /* frame width */
687 VIDEO_VISIBLE_ROWS, /* frame height */
691 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
695 static void console_cursor_fix(void)
699 if (console_row >= CONSOLE_ROWS)
700 console_row = CONSOLE_ROWS - 1;
703 if (console_col >= CONSOLE_COLS)
704 console_col = CONSOLE_COLS - 1;
707 static void console_cursor_up(int n)
710 console_cursor_fix();
713 static void console_cursor_down(int n)
716 console_cursor_fix();
719 static void console_cursor_left(int n)
722 console_cursor_fix();
725 static void console_cursor_right(int n)
728 console_cursor_fix();
731 static void console_cursor_set_position(int row, int col)
733 if (console_row != -1)
735 if (console_col != -1)
737 console_cursor_fix();
740 static void console_previousline(int n)
742 /* FIXME: also scroll terminal ? */
744 console_cursor_fix();
747 static void console_swap_colors(void)
755 static inline int console_cursor_is_visible(void)
757 return !ansi_cursor_hidden;
760 static inline int console_cursor_is_visible(void)
766 static void console_newline(int n)
771 /* Check if we need to scroll the terminal */
772 if (console_row >= CONSOLE_ROWS) {
773 /* Scroll everything up */
778 static void console_cr(void)
783 static void parse_putc(const char c)
787 if (console_cursor_is_visible())
791 case 13: /* back to first column */
795 case '\n': /* next line */
796 if (console_col || (!console_col && nl))
802 console_col |= 0x0008;
803 console_col &= ~0x0007;
805 if (console_col >= CONSOLE_COLS)
809 case 8: /* backspace */
816 default: /* draw the char */
817 video_putchar(console_col * VIDEO_FONT_WIDTH,
818 console_row * VIDEO_FONT_HEIGHT, c);
821 /* check for newline */
822 if (console_col >= CONSOLE_COLS) {
828 if (console_cursor_is_visible())
832 static void video_putc(struct stdio_dev *dev, const char c)
834 #ifdef CONFIG_CFB_CONSOLE_ANSI
838 for (i = 0; i < ansi_buf_size; ++i)
839 parse_putc(ansi_buf[i]);
845 if (ansi_buf_size > 0) {
865 ansi_buf[ansi_buf_size++] = c;
867 if (ansi_buf_size >= sizeof(ansi_buf))
870 for (i = 0; i < ansi_buf_size; ++i) {
876 if (ansi_buf[i] == 27)
883 if (ansi_buf[i] == '[')
890 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
891 num1 = ansi_buf[i]-'0';
893 } else if (ansi_buf[i] != '?') {
901 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
903 num1 += ansi_buf[i]-'0';
911 if (ansi_buf[i] != ';') {
919 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
920 num2 = ansi_buf[i]-'0';
927 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
929 num2 += ansi_buf[i]-'0';
937 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
938 || ansi_buf[i] == 'J'
939 || ansi_buf[i] == 'K'
940 || ansi_buf[i] == 'h'
941 || ansi_buf[i] == 'l'
942 || ansi_buf[i] == 'm') {
952 for (i = 0; i < ansi_buf_size; ++i)
953 parse_putc(ansi_buf[i]);
959 if (!ansi_cursor_hidden)
964 /* move cursor num1 rows up */
965 console_cursor_up(num1);
968 /* move cursor num1 rows down */
969 console_cursor_down(num1);
972 /* move cursor num1 columns forward */
973 console_cursor_right(num1);
976 /* move cursor num1 columns back */
977 console_cursor_left(num1);
980 /* move cursor num1 rows up at begin of row */
981 console_previousline(num1);
984 /* move cursor num1 rows down at begin of row */
985 console_newline(num1);
988 /* move cursor to column num1 */
989 console_cursor_set_position(-1, num1-1);
992 /* move cursor to row num1, column num2 */
993 console_cursor_set_position(num1-1, num2-1);
996 /* clear console and move cursor to 0, 0 */
998 console_cursor_set_position(0, 0);
1003 console_clear_line(console_row,
1007 console_clear_line(console_row,
1010 console_clear_line(console_row,
1014 ansi_cursor_hidden = 0;
1017 ansi_cursor_hidden = 1;
1020 if (num1 == 0) { /* reset swapped colors */
1021 if (ansi_colors_need_revert) {
1022 console_swap_colors();
1023 ansi_colors_need_revert = 0;
1025 } else if (num1 == 7) { /* once swap colors */
1026 if (!ansi_colors_need_revert) {
1027 console_swap_colors();
1028 ansi_colors_need_revert = 1;
1033 if (!ansi_cursor_hidden)
1042 if (cfb_do_flush_cache)
1043 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1046 static void video_puts(struct stdio_dev *dev, const char *s)
1048 int flush = cfb_do_flush_cache;
1049 int count = strlen(s);
1051 /* temporarily disable cache flush */
1052 cfb_do_flush_cache = 0;
1055 video_putc(dev, *s++);
1058 cfb_do_flush_cache = flush;
1059 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1064 * Do not enforce drivers (or board code) to provide empty
1065 * video_set_lut() if they do not support 8 bpp format.
1066 * Implement weak default function instead.
1068 __weak void video_set_lut(unsigned int index, unsigned char r,
1069 unsigned char g, unsigned char b)
1073 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1075 #define FILL_8BIT_332RGB(r,g,b) { \
1076 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1080 #define FILL_15BIT_555RGB(r,g,b) { \
1081 *(unsigned short *)fb = \
1082 SWAP16((unsigned short)(((r>>3)<<10) | \
1088 #define FILL_16BIT_565RGB(r,g,b) { \
1089 *(unsigned short *)fb = \
1090 SWAP16((unsigned short)((((r)>>3)<<11)| \
1096 #define FILL_32BIT_X888RGB(r,g,b) { \
1097 *(unsigned long *)fb = \
1098 SWAP32((unsigned long)(((r<<16) | \
1104 #ifdef VIDEO_FB_LITTLE_ENDIAN
1105 #define FILL_24BIT_888RGB(r,g,b) { \
1112 #define FILL_24BIT_888RGB(r,g,b) { \
1120 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1121 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1123 ushort *dst = (ushort *) fb;
1124 ushort color = (ushort) (((r >> 3) << 10) |
1135 * RLE8 bitmap support
1138 #ifdef CONFIG_VIDEO_BMP_RLE8
1139 /* Pre-calculated color table entry */
1142 unsigned short w; /* word */
1143 unsigned int dw; /* double word */
1144 } ce; /* color entry */
1148 * Helper to draw encoded/unencoded run.
1150 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1153 ulong addr = (ulong) *fb;
1159 * Setup offset of the color index in the bitmap.
1160 * Color index of encoded run is at offset 1.
1162 off = enc ? &enc_off : &i;
1164 switch (VIDEO_DATA_FORMAT) {
1165 case GDF__8BIT_INDEX:
1166 for (i = 0; i < cnt; i++)
1167 *(unsigned char *) addr++ = bm[*off];
1169 case GDF_15BIT_555RGB:
1170 case GDF_16BIT_565RGB:
1171 /* differences handled while pre-calculating palette */
1172 for (i = 0; i < cnt; i++) {
1173 *(unsigned short *) addr = p[bm[*off]].ce.w;
1177 case GDF_32BIT_X888RGB:
1178 for (i = 0; i < cnt; i++) {
1179 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1184 *fb = (uchar *) addr; /* return modified address */
1187 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1188 int width, int height)
1192 unsigned int cnt, runlen;
1194 int x, y, bpp, i, ncolors;
1195 struct palette p[256];
1196 struct bmp_color_table_entry cte;
1197 int green_shift, red_off;
1198 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1202 y = __le32_to_cpu(img->header.height) - 1;
1203 ncolors = __le32_to_cpu(img->header.colors_used);
1204 bpp = VIDEO_PIXEL_SIZE;
1205 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1206 (y + yoff) * VIDEO_LINE_LEN +
1209 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1211 /* pre-calculate and setup palette */
1212 switch (VIDEO_DATA_FORMAT) {
1213 case GDF__8BIT_INDEX:
1214 for (i = 0; i < ncolors; i++) {
1215 cte = img->color_table[i];
1216 video_set_lut(i, cte.red, cte.green, cte.blue);
1219 case GDF_15BIT_555RGB:
1220 case GDF_16BIT_565RGB:
1221 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1228 for (i = 0; i < ncolors; i++) {
1229 cte = img->color_table[i];
1230 p[i].ce.w = SWAP16((unsigned short)
1231 (((cte.red >> 3) << red_off) |
1232 ((cte.green >> green_shift) << 5) |
1236 case GDF_32BIT_X888RGB:
1237 for (i = 0; i < ncolors; i++) {
1238 cte = img->color_table[i];
1239 p[i].ce.dw = SWAP32((cte.red << 16) |
1245 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1255 /* scan line end marker */
1259 fbp = (unsigned char *)
1260 ((unsigned int) video_fb_address +
1261 (y + yoff) * VIDEO_LINE_LEN +
1265 /* end of bitmap data marker */
1269 /* run offset marker */
1272 fbp = (unsigned char *)
1273 ((unsigned int) video_fb_address +
1274 (y + yoff) * VIDEO_LINE_LEN +
1292 if (x + runlen > width)
1294 draw_bitmap(&fbp, bm, p, cnt, 0);
1300 bm++; /* 0 padding if length is odd */
1311 if (y < height) { /* only draw into visible area */
1317 if (x + runlen > width)
1319 draw_bitmap(&fbp, bm, p, cnt, 1);
1328 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1334 * Display the BMP file located at address bmp_image.
1336 int video_display_bitmap(ulong bmp_image, int x, int y)
1338 ushort xcount, ycount;
1340 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1343 unsigned long width, height, bpp;
1345 unsigned long compression;
1346 struct bmp_color_table_entry cte;
1348 #ifdef CONFIG_VIDEO_BMP_GZIP
1349 unsigned char *dst = NULL;
1355 if (!((bmp->header.signature[0] == 'B') &&
1356 (bmp->header.signature[1] == 'M'))) {
1358 #ifdef CONFIG_VIDEO_BMP_GZIP
1360 * Could be a gzipped bmp image, try to decrompress...
1362 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1363 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1365 printf("Error: malloc in gunzip failed!\n");
1369 * NB: we need to force offset of +2
1370 * See doc/README.displaying-bmps
1372 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1373 (uchar *) bmp_image,
1375 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1380 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1381 printf("Image could be truncated "
1382 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1386 * Set addr to decompressed image
1388 bmp = (struct bmp_image *)(dst+2);
1390 if (!((bmp->header.signature[0] == 'B') &&
1391 (bmp->header.signature[1] == 'M'))) {
1392 printf("Error: no valid bmp.gz image at %lx\n",
1398 printf("Error: no valid bmp image at %lx\n", bmp_image);
1400 #endif /* CONFIG_VIDEO_BMP_GZIP */
1403 width = le32_to_cpu(bmp->header.width);
1404 height = le32_to_cpu(bmp->header.height);
1405 bpp = le16_to_cpu(bmp->header.bit_count);
1406 colors = le32_to_cpu(bmp->header.colors_used);
1407 compression = le32_to_cpu(bmp->header.compression);
1409 debug("Display-bmp: %ld x %ld with %d colors\n",
1410 width, height, colors);
1412 if (compression != BMP_BI_RGB
1413 #ifdef CONFIG_VIDEO_BMP_RLE8
1414 && compression != BMP_BI_RLE8
1417 printf("Error: compression type %ld not supported\n",
1419 #ifdef CONFIG_VIDEO_BMP_GZIP
1426 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1428 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1429 if (x == BMP_ALIGN_CENTER)
1430 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1432 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1434 if (y == BMP_ALIGN_CENTER)
1435 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1437 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1438 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1441 * Just ignore elements which are completely beyond screen
1444 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1447 if ((x + width) > VIDEO_VISIBLE_COLS)
1448 width = VIDEO_VISIBLE_COLS - x;
1449 if ((y + height) > VIDEO_VISIBLE_ROWS)
1450 height = VIDEO_VISIBLE_ROWS - y;
1452 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1453 fb = (uchar *) (video_fb_address +
1454 ((y + height - 1) * VIDEO_LINE_LEN) +
1455 x * VIDEO_PIXEL_SIZE);
1457 #ifdef CONFIG_VIDEO_BMP_RLE8
1458 if (compression == BMP_BI_RLE8) {
1459 return display_rle8_bitmap(bmp, x, y, width, height);
1463 /* We handle only 4, 8, or 24 bpp bitmaps */
1464 switch (le16_to_cpu(bmp->header.bit_count)) {
1466 padded_line -= width / 2;
1469 switch (VIDEO_DATA_FORMAT) {
1470 case GDF_32BIT_X888RGB:
1474 * Don't assume that 'width' is an
1477 for (xcount = 0; xcount < width; xcount++) {
1485 cte = bmp->color_table[idx];
1486 FILL_32BIT_X888RGB(cte.red, cte.green,
1489 bmap += padded_line;
1490 fb -= VIDEO_LINE_LEN + width *
1495 puts("4bpp bitmap unsupported with current "
1502 padded_line -= width;
1503 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1505 for (xcount = 0; xcount < colors; ++xcount) {
1506 cte = bmp->color_table[xcount];
1507 video_set_lut(xcount, cte.red, cte.green,
1512 switch (VIDEO_DATA_FORMAT) {
1513 case GDF__8BIT_INDEX:
1520 bmap += padded_line;
1521 fb -= VIDEO_LINE_LEN + width *
1525 case GDF__8BIT_332RGB:
1530 cte = bmp->color_table[*bmap++];
1531 FILL_8BIT_332RGB(cte.red, cte.green,
1534 bmap += padded_line;
1535 fb -= VIDEO_LINE_LEN + width *
1539 case GDF_15BIT_555RGB:
1541 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1547 cte = bmp->color_table[*bmap++];
1548 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1549 fill_555rgb_pswap(fb, xpos++, cte.red,
1554 FILL_15BIT_555RGB(cte.red, cte.green,
1558 bmap += padded_line;
1559 fb -= VIDEO_LINE_LEN + width *
1563 case GDF_16BIT_565RGB:
1568 cte = bmp->color_table[*bmap++];
1569 FILL_16BIT_565RGB(cte.red, cte.green,
1572 bmap += padded_line;
1573 fb -= VIDEO_LINE_LEN + width *
1577 case GDF_32BIT_X888RGB:
1582 cte = bmp->color_table[*bmap++];
1583 FILL_32BIT_X888RGB(cte.red, cte.green,
1586 bmap += padded_line;
1587 fb -= VIDEO_LINE_LEN + width *
1591 case GDF_24BIT_888RGB:
1596 cte = bmp->color_table[*bmap++];
1597 FILL_24BIT_888RGB(cte.red, cte.green,
1600 bmap += padded_line;
1601 fb -= VIDEO_LINE_LEN + width *
1608 padded_line -= 3 * width;
1610 switch (VIDEO_DATA_FORMAT) {
1611 case GDF__8BIT_332RGB:
1616 FILL_8BIT_332RGB(bmap[2], bmap[1],
1620 bmap += padded_line;
1621 fb -= VIDEO_LINE_LEN + width *
1625 case GDF_15BIT_555RGB:
1627 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1633 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1634 fill_555rgb_pswap(fb, xpos++, bmap[2],
1638 FILL_15BIT_555RGB(bmap[2], bmap[1],
1643 bmap += padded_line;
1644 fb -= VIDEO_LINE_LEN + width *
1648 case GDF_16BIT_565RGB:
1653 FILL_16BIT_565RGB(bmap[2], bmap[1],
1657 bmap += padded_line;
1658 fb -= VIDEO_LINE_LEN + width *
1662 case GDF_32BIT_X888RGB:
1667 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1671 bmap += padded_line;
1672 fb -= VIDEO_LINE_LEN + width *
1676 case GDF_24BIT_888RGB:
1681 FILL_24BIT_888RGB(bmap[2], bmap[1],
1685 bmap += padded_line;
1686 fb -= VIDEO_LINE_LEN + width *
1691 printf("Error: 24 bits/pixel bitmap incompatible "
1692 "with current video mode\n");
1697 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1698 le16_to_cpu(bmp->header.bit_count));
1702 #ifdef CONFIG_VIDEO_BMP_GZIP
1708 if (cfb_do_flush_cache)
1709 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1715 #ifdef CONFIG_VIDEO_LOGO
1716 static int video_logo_xpos;
1717 static int video_logo_ypos;
1719 static void plot_logo_or_black(void *screen, int x, int y, int black);
1721 static void logo_plot(void *screen, int x, int y)
1723 plot_logo_or_black(screen, x, y, 0);
1726 static void logo_black(void)
1728 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1732 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1735 return cmd_usage(cmdtp);
1742 clrlogo, 1, 0, do_clrlogo,
1743 "fill the boot logo area with black",
1747 static void plot_logo_or_black(void *screen, int x, int y, int black)
1751 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1752 int ycount = video_logo_height;
1753 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1754 unsigned char *source;
1755 unsigned char *dest;
1757 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1758 if (x == BMP_ALIGN_CENTER)
1759 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1761 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1763 if (y == BMP_ALIGN_CENTER)
1764 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1766 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1767 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1769 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1771 #ifdef CONFIG_VIDEO_BMP_LOGO
1772 source = bmp_logo_bitmap;
1774 /* Allocate temporary space for computing colormap */
1775 logo_red = malloc(BMP_LOGO_COLORS);
1776 logo_green = malloc(BMP_LOGO_COLORS);
1777 logo_blue = malloc(BMP_LOGO_COLORS);
1778 /* Compute color map */
1779 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1780 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1781 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1782 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1785 source = linux_logo;
1786 logo_red = linux_logo_red;
1787 logo_green = linux_logo_green;
1788 logo_blue = linux_logo_blue;
1791 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1792 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1793 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1794 logo_red[i], logo_green[i],
1800 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1803 xcount = VIDEO_LOGO_WIDTH;
1810 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1811 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1812 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1815 switch (VIDEO_DATA_FORMAT) {
1816 case GDF__8BIT_INDEX:
1819 case GDF__8BIT_332RGB:
1820 *dest = ((r >> 5) << 5) |
1824 case GDF_15BIT_555RGB:
1825 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1826 fill_555rgb_pswap(dest, xpos++, r, g, b);
1828 *(unsigned short *) dest =
1829 SWAP16((unsigned short) (
1835 case GDF_16BIT_565RGB:
1836 *(unsigned short *) dest =
1837 SWAP16((unsigned short) (
1842 case GDF_32BIT_X888RGB:
1843 *(unsigned long *) dest =
1844 SWAP32((unsigned long) (
1849 case GDF_24BIT_888RGB:
1850 #ifdef VIDEO_FB_LITTLE_ENDIAN
1862 dest += VIDEO_PIXEL_SIZE;
1866 #ifdef CONFIG_VIDEO_BMP_LOGO
1873 static void *video_logo(void)
1876 __maybe_unused int y_off = 0;
1877 __maybe_unused ulong addr;
1878 __maybe_unused char *s;
1879 __maybe_unused int len, space;
1881 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1883 #ifdef CONFIG_SPLASH_SCREEN
1884 s = getenv("splashimage");
1886 splash_screen_prepare();
1887 addr = simple_strtoul(s, NULL, 16);
1889 if (video_display_bitmap(addr,
1891 video_logo_ypos) == 0) {
1892 video_logo_height = 0;
1893 return ((void *) (video_fb_address));
1896 #endif /* CONFIG_SPLASH_SCREEN */
1898 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1900 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1902 * when using splashpos for video_logo, skip any info
1903 * output on video console if the logo is not at 0,0
1905 if (video_logo_xpos || video_logo_ypos) {
1907 * video_logo_height is used in text and cursor offset
1908 * calculations. Since the console is below the logo,
1909 * we need to adjust the logo height
1911 if (video_logo_ypos == BMP_ALIGN_CENTER)
1912 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1913 VIDEO_LOGO_HEIGHT) / 2);
1914 else if (video_logo_ypos > 0)
1915 video_logo_height += video_logo_ypos;
1917 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1920 if (board_cfb_skip())
1923 sprintf(info, " %s", version_string);
1925 #ifndef CONFIG_HIDE_LOGO_VERSION
1926 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1930 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1931 (uchar *) info, space);
1932 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1933 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1934 (uchar *) info + space, len - space);
1937 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1939 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1942 ((video_logo_height -
1943 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1945 for (i = 1; i < n; i++) {
1946 video_get_info_str(i, info);
1952 video_drawchars(VIDEO_INFO_X,
1956 (uchar *) info, space);
1958 video_drawchars(VIDEO_INFO_X +
1963 (uchar *) info + space,
1966 video_drawstring(VIDEO_INFO_X,
1977 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1981 static int cfb_fb_is_in_dram(void)
1984 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1985 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1989 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1990 start = bd->bi_dram[i].start;
1991 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1992 if ((ulong)video_fb_address >= start &&
1993 (ulong)video_fb_address < end)
1997 if ((ulong)video_fb_address >= bd->bi_memstart &&
1998 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2004 void video_clear(void)
2006 if (!video_fb_address)
2008 #ifdef VIDEO_HW_RECTFILL
2009 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2012 VIDEO_VISIBLE_COLS, /* frame width */
2013 VIDEO_VISIBLE_ROWS, /* frame height */
2014 bgx /* fill color */
2017 memsetl(video_fb_address,
2018 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2022 static int video_init(void)
2024 unsigned char color8;
2026 pGD = video_hw_init();
2030 video_fb_address = (void *) VIDEO_FB_ADRS;
2032 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2034 /* Init drawing pats */
2035 switch (VIDEO_DATA_FORMAT) {
2036 case GDF__8BIT_INDEX:
2037 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2038 CONFIG_SYS_CONSOLE_FG_COL,
2039 CONFIG_SYS_CONSOLE_FG_COL);
2040 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2041 CONFIG_SYS_CONSOLE_BG_COL,
2042 CONFIG_SYS_CONSOLE_BG_COL);
2046 case GDF__8BIT_332RGB:
2047 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2048 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2049 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2050 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2052 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2053 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2054 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2055 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2058 case GDF_15BIT_555RGB:
2059 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2061 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2062 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2063 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2064 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2065 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2067 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2068 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2069 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2070 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2072 case GDF_16BIT_565RGB:
2073 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2074 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2075 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2076 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2077 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2078 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2079 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2080 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2081 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2082 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2083 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2084 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2086 case GDF_32BIT_X888RGB:
2087 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2088 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2089 CONFIG_SYS_CONSOLE_FG_COL;
2090 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2091 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2092 CONFIG_SYS_CONSOLE_BG_COL;
2094 case GDF_24BIT_888RGB:
2095 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2096 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2097 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2098 CONFIG_SYS_CONSOLE_FG_COL;
2099 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2100 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2101 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2102 CONFIG_SYS_CONSOLE_BG_COL;
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 (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 = video_putc; /* 'putc' function */
2174 console_dev.puts = 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;