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>
144 #if !defined(CONFIG_VIDEO_SW_CURSOR)
145 /* no Cursor defined */
151 #if defined(CONFIG_VIDEO_SW_CURSOR)
152 void console_cursor(int state);
154 #define CURSOR_ON console_cursor(1)
155 #define CURSOR_OFF console_cursor(0)
156 #define CURSOR_SET video_set_cursor()
157 #endif /* CONFIG_VIDEO_SW_CURSOR */
159 #ifdef CONFIG_VIDEO_LOGO
160 #ifdef CONFIG_VIDEO_BMP_LOGO
161 #include <bmp_logo.h>
162 #include <bmp_logo_data.h>
163 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
164 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
165 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
166 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
168 #else /* CONFIG_VIDEO_BMP_LOGO */
169 #define LINUX_LOGO_WIDTH 80
170 #define LINUX_LOGO_HEIGHT 80
171 #define LINUX_LOGO_COLORS 214
172 #define LINUX_LOGO_LUT_OFFSET 0x20
174 #include <linux_logo.h>
175 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
176 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
177 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
178 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
179 #endif /* CONFIG_VIDEO_BMP_LOGO */
180 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
181 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
182 #else /* CONFIG_VIDEO_LOGO */
183 #define VIDEO_LOGO_WIDTH 0
184 #define VIDEO_LOGO_HEIGHT 0
185 #endif /* CONFIG_VIDEO_LOGO */
187 #define VIDEO_COLS VIDEO_VISIBLE_COLS
188 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
189 #ifndef VIDEO_LINE_LEN
190 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
192 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
193 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
195 #ifdef CONFIG_VIDEO_LOGO
196 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
198 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
201 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
202 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
203 #define CONSOLE_ROW_FIRST (video_console_address)
204 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
205 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
206 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
208 /* By default we scroll by a single line */
209 #ifndef CONFIG_CONSOLE_SCROLL_LINES
210 #define CONFIG_CONSOLE_SCROLL_LINES 1
214 #ifdef VIDEO_FB_LITTLE_ENDIAN
215 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
218 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
219 (((x) & 0x0000ff00) << 8) | \
220 (((x) & 0x00ff0000) >> 8) | \
221 (((x) & 0xff000000) >> 24) \
223 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
224 (((x) & 0x0000ff00) >> 8) | \
225 (((x) & 0x00ff0000) << 8) | \
226 (((x) & 0xff000000) >> 8) \
229 #define SWAP16(x) (x)
230 #define SWAP32(x) (x)
231 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
232 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
234 #define SHORTSWAP32(x) (x)
238 #ifdef CONFIG_CONSOLE_EXTRA_INFO
240 * setup a board string: type, speed, etc.
242 * line_number: location to place info string beside logo
243 * info: buffer for info string
245 extern void video_get_info_str(int line_number, char *info);
248 DECLARE_GLOBAL_DATA_PTR;
251 static GraphicDevice *pGD; /* Pointer to Graphic array */
253 static void *video_fb_address; /* frame buffer address */
254 static void *video_console_address; /* console buffer start address */
256 static int video_logo_height = VIDEO_LOGO_HEIGHT;
258 static int __maybe_unused cursor_state;
259 static int __maybe_unused old_col;
260 static int __maybe_unused old_row;
262 static int console_col; /* cursor col */
263 static int console_row; /* cursor row */
265 static u32 eorx, fgx, bgx; /* color pats */
267 static int cfb_do_flush_cache;
269 #ifdef CONFIG_CFB_CONSOLE_ANSI
270 static char ansi_buf[10];
271 static int ansi_buf_size;
272 static int ansi_colors_need_revert;
273 static int ansi_cursor_hidden;
276 static const int video_font_draw_table8[] = {
277 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
278 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
279 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
280 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
283 static const int video_font_draw_table15[] = {
284 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
287 static const int video_font_draw_table16[] = {
288 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
291 static const int video_font_draw_table24[16][3] = {
292 {0x00000000, 0x00000000, 0x00000000},
293 {0x00000000, 0x00000000, 0x00ffffff},
294 {0x00000000, 0x0000ffff, 0xff000000},
295 {0x00000000, 0x0000ffff, 0xffffffff},
296 {0x000000ff, 0xffff0000, 0x00000000},
297 {0x000000ff, 0xffff0000, 0x00ffffff},
298 {0x000000ff, 0xffffffff, 0xff000000},
299 {0x000000ff, 0xffffffff, 0xffffffff},
300 {0xffffff00, 0x00000000, 0x00000000},
301 {0xffffff00, 0x00000000, 0x00ffffff},
302 {0xffffff00, 0x0000ffff, 0xff000000},
303 {0xffffff00, 0x0000ffff, 0xffffffff},
304 {0xffffffff, 0xffff0000, 0x00000000},
305 {0xffffffff, 0xffff0000, 0x00ffffff},
306 {0xffffffff, 0xffffffff, 0xff000000},
307 {0xffffffff, 0xffffffff, 0xffffffff}
310 static const int video_font_draw_table32[16][4] = {
311 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
312 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
313 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
314 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
315 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
316 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
317 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
318 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
319 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
320 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
321 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
322 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
323 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
324 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
325 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
326 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
330 * Implement a weak default function for boards that optionally
331 * need to skip the cfb initialization.
333 __weak int board_cfb_skip(void)
335 /* As default, don't skip cfb init */
339 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
341 u8 *cdat, *dest, *dest0;
344 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
345 dest0 = video_fb_address + offset;
347 switch (VIDEO_DATA_FORMAT) {
348 case GDF__8BIT_INDEX:
349 case GDF__8BIT_332RGB:
352 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
353 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
354 rows--; dest += VIDEO_LINE_LEN) {
358 (video_font_draw_table8[bits >> 4] &
361 if (VIDEO_FONT_WIDTH == 4)
365 (video_font_draw_table8[bits & 15] &
368 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
373 case GDF_15BIT_555RGB:
376 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
377 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
378 rows--; dest += VIDEO_LINE_LEN) {
382 SHORTSWAP32((video_font_draw_table15
383 [bits >> 6] & eorx) ^
386 SHORTSWAP32((video_font_draw_table15
387 [bits >> 4 & 3] & eorx) ^
390 if (VIDEO_FONT_WIDTH == 4)
394 SHORTSWAP32((video_font_draw_table15
395 [bits >> 2 & 3] & eorx) ^
398 SHORTSWAP32((video_font_draw_table15
402 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
407 case GDF_16BIT_565RGB:
410 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
411 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
412 rows--; dest += VIDEO_LINE_LEN) {
416 SHORTSWAP32((video_font_draw_table16
417 [bits >> 6] & eorx) ^
420 SHORTSWAP32((video_font_draw_table16
421 [bits >> 4 & 3] & eorx) ^
424 if (VIDEO_FONT_WIDTH == 4)
428 SHORTSWAP32((video_font_draw_table16
429 [bits >> 2 & 3] & eorx) ^
432 SHORTSWAP32((video_font_draw_table16
436 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
441 case GDF_32BIT_X888RGB:
444 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
445 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
446 rows--; dest += VIDEO_LINE_LEN) {
450 SWAP32((video_font_draw_table32
451 [bits >> 4][0] & eorx) ^ bgx);
453 SWAP32((video_font_draw_table32
454 [bits >> 4][1] & eorx) ^ bgx);
456 SWAP32((video_font_draw_table32
457 [bits >> 4][2] & eorx) ^ bgx);
459 SWAP32((video_font_draw_table32
460 [bits >> 4][3] & eorx) ^ bgx);
463 if (VIDEO_FONT_WIDTH == 4)
467 SWAP32((video_font_draw_table32
468 [bits & 15][0] & eorx) ^ bgx);
470 SWAP32((video_font_draw_table32
471 [bits & 15][1] & eorx) ^ bgx);
473 SWAP32((video_font_draw_table32
474 [bits & 15][2] & eorx) ^ bgx);
476 SWAP32((video_font_draw_table32
477 [bits & 15][3] & eorx) ^ bgx);
479 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
484 case GDF_24BIT_888RGB:
487 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
488 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
489 rows--; dest += VIDEO_LINE_LEN) {
493 (video_font_draw_table24[bits >> 4][0]
496 (video_font_draw_table24[bits >> 4][1]
499 (video_font_draw_table24[bits >> 4][2]
502 if (VIDEO_FONT_WIDTH == 4)
506 (video_font_draw_table24[bits & 15][0]
509 (video_font_draw_table24[bits & 15][1]
512 (video_font_draw_table24[bits & 15][2]
515 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
522 static inline void video_drawstring(int xx, int yy, unsigned char *s)
524 video_drawchars(xx, yy, s, strlen((char *) s));
527 static void video_putchar(int xx, int yy, unsigned char c)
529 video_drawchars(xx, yy + video_logo_height, &c, 1);
532 #if defined(CONFIG_VIDEO_SW_CURSOR)
533 static void video_set_cursor(void)
540 static void video_invertchar(int xx, int yy)
542 int firstx = xx * VIDEO_PIXEL_SIZE;
543 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
544 int firsty = yy * VIDEO_LINE_LEN;
545 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
547 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
548 for (x = firstx; x < lastx; x++) {
549 u8 *dest = (u8 *)(video_fb_address) + x + y;
555 void console_cursor(int state)
557 if (cursor_state != state) {
559 /* turn off the cursor */
560 video_invertchar(old_col * VIDEO_FONT_WIDTH,
561 old_row * VIDEO_FONT_HEIGHT +
564 /* turn off the cursor and record where it is */
565 video_invertchar(console_col * VIDEO_FONT_WIDTH,
566 console_row * VIDEO_FONT_HEIGHT +
568 old_col = console_col;
569 old_row = console_row;
571 cursor_state = state;
573 if (cfb_do_flush_cache)
574 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
578 #ifndef VIDEO_HW_RECTFILL
579 static void memsetl(int *p, int c, int v)
586 #ifndef VIDEO_HW_BITBLT
587 static void memcpyl(int *d, int *s, int c)
594 static void console_clear_line(int line, int begin, int end)
596 #ifdef VIDEO_HW_RECTFILL
597 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
598 VIDEO_FONT_WIDTH * begin, /* dest pos x */
600 VIDEO_FONT_HEIGHT * line, /* dest pos y */
601 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
602 VIDEO_FONT_HEIGHT, /* frame height */
606 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
607 memsetl(CONSOLE_ROW_FIRST +
608 CONSOLE_ROW_SIZE * line, /* offset of row */
609 CONSOLE_ROW_SIZE >> 2, /* length of row */
616 offset = CONSOLE_ROW_FIRST +
617 CONSOLE_ROW_SIZE * line + /* offset of row */
619 VIDEO_PIXEL_SIZE * begin; /* offset of col */
620 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
621 size >>= 2; /* length to end for memsetl() */
622 /* fill at col offset of i'th line using bgx as fill color */
623 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
624 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
629 static void console_scrollup(void)
631 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
634 /* copy up rows ignoring the first one */
636 #ifdef VIDEO_HW_BITBLT
637 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
638 0, /* source pos x */
640 VIDEO_FONT_HEIGHT * rows, /* source pos y */
642 video_logo_height, /* dest pos y */
643 VIDEO_VISIBLE_COLS, /* frame width */
646 - VIDEO_FONT_HEIGHT * rows /* frame height */
649 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
650 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
652 /* clear the last one */
653 for (i = 1; i <= rows; i++)
654 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
656 /* Decrement row number */
660 static void console_back(void)
664 if (console_col < 0) {
665 console_col = CONSOLE_COLS - 1;
672 #ifdef CONFIG_CFB_CONSOLE_ANSI
674 static void console_clear(void)
676 #ifdef VIDEO_HW_RECTFILL
677 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
679 video_logo_height, /* dest pos y */
680 VIDEO_VISIBLE_COLS, /* frame width */
681 VIDEO_VISIBLE_ROWS, /* frame height */
685 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
689 static void console_cursor_fix(void)
693 if (console_row >= CONSOLE_ROWS)
694 console_row = CONSOLE_ROWS - 1;
697 if (console_col >= CONSOLE_COLS)
698 console_col = CONSOLE_COLS - 1;
701 static void console_cursor_up(int n)
704 console_cursor_fix();
707 static void console_cursor_down(int n)
710 console_cursor_fix();
713 static void console_cursor_left(int n)
716 console_cursor_fix();
719 static void console_cursor_right(int n)
722 console_cursor_fix();
725 static void console_cursor_set_position(int row, int col)
727 if (console_row != -1)
729 if (console_col != -1)
731 console_cursor_fix();
734 static void console_previousline(int n)
736 /* FIXME: also scroll terminal ? */
738 console_cursor_fix();
741 static void console_swap_colors(void)
749 static inline int console_cursor_is_visible(void)
751 return !ansi_cursor_hidden;
754 static inline int console_cursor_is_visible(void)
760 static void console_newline(int n)
765 /* Check if we need to scroll the terminal */
766 if (console_row >= CONSOLE_ROWS) {
767 /* Scroll everything up */
772 static void console_cr(void)
777 static void parse_putc(const char c)
781 if (console_cursor_is_visible())
785 case 13: /* back to first column */
789 case '\n': /* next line */
790 if (console_col || (!console_col && nl))
796 console_col |= 0x0008;
797 console_col &= ~0x0007;
799 if (console_col >= CONSOLE_COLS)
803 case 8: /* backspace */
810 default: /* draw the char */
811 video_putchar(console_col * VIDEO_FONT_WIDTH,
812 console_row * VIDEO_FONT_HEIGHT, c);
815 /* check for newline */
816 if (console_col >= CONSOLE_COLS) {
822 if (console_cursor_is_visible())
826 static void video_putc(struct stdio_dev *dev, const char c)
828 #ifdef CONFIG_CFB_CONSOLE_ANSI
832 for (i = 0; i < ansi_buf_size; ++i)
833 parse_putc(ansi_buf[i]);
839 if (ansi_buf_size > 0) {
859 ansi_buf[ansi_buf_size++] = c;
861 if (ansi_buf_size >= sizeof(ansi_buf))
864 for (i = 0; i < ansi_buf_size; ++i) {
870 if (ansi_buf[i] == 27)
877 if (ansi_buf[i] == '[')
884 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
885 num1 = ansi_buf[i]-'0';
887 } else if (ansi_buf[i] != '?') {
895 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
897 num1 += ansi_buf[i]-'0';
905 if (ansi_buf[i] != ';') {
913 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
914 num2 = ansi_buf[i]-'0';
921 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
923 num2 += ansi_buf[i]-'0';
931 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
932 || ansi_buf[i] == 'J'
933 || ansi_buf[i] == 'K'
934 || ansi_buf[i] == 'h'
935 || ansi_buf[i] == 'l'
936 || ansi_buf[i] == 'm') {
946 for (i = 0; i < ansi_buf_size; ++i)
947 parse_putc(ansi_buf[i]);
953 if (!ansi_cursor_hidden)
958 /* move cursor num1 rows up */
959 console_cursor_up(num1);
962 /* move cursor num1 rows down */
963 console_cursor_down(num1);
966 /* move cursor num1 columns forward */
967 console_cursor_right(num1);
970 /* move cursor num1 columns back */
971 console_cursor_left(num1);
974 /* move cursor num1 rows up at begin of row */
975 console_previousline(num1);
978 /* move cursor num1 rows down at begin of row */
979 console_newline(num1);
982 /* move cursor to column num1 */
983 console_cursor_set_position(-1, num1-1);
986 /* move cursor to row num1, column num2 */
987 console_cursor_set_position(num1-1, num2-1);
990 /* clear console and move cursor to 0, 0 */
992 console_cursor_set_position(0, 0);
997 console_clear_line(console_row,
1001 console_clear_line(console_row,
1004 console_clear_line(console_row,
1008 ansi_cursor_hidden = 0;
1011 ansi_cursor_hidden = 1;
1014 if (num1 == 0) { /* reset swapped colors */
1015 if (ansi_colors_need_revert) {
1016 console_swap_colors();
1017 ansi_colors_need_revert = 0;
1019 } else if (num1 == 7) { /* once swap colors */
1020 if (!ansi_colors_need_revert) {
1021 console_swap_colors();
1022 ansi_colors_need_revert = 1;
1027 if (!ansi_cursor_hidden)
1036 if (cfb_do_flush_cache)
1037 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1040 static void video_puts(struct stdio_dev *dev, const char *s)
1042 int flush = cfb_do_flush_cache;
1043 int count = strlen(s);
1045 /* temporarily disable cache flush */
1046 cfb_do_flush_cache = 0;
1049 video_putc(dev, *s++);
1052 cfb_do_flush_cache = flush;
1053 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1058 * Do not enforce drivers (or board code) to provide empty
1059 * video_set_lut() if they do not support 8 bpp format.
1060 * Implement weak default function instead.
1062 __weak void video_set_lut(unsigned int index, unsigned char r,
1063 unsigned char g, unsigned char b)
1067 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1069 #define FILL_8BIT_332RGB(r,g,b) { \
1070 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1074 #define FILL_15BIT_555RGB(r,g,b) { \
1075 *(unsigned short *)fb = \
1076 SWAP16((unsigned short)(((r>>3)<<10) | \
1082 #define FILL_16BIT_565RGB(r,g,b) { \
1083 *(unsigned short *)fb = \
1084 SWAP16((unsigned short)((((r)>>3)<<11)| \
1090 #define FILL_32BIT_X888RGB(r,g,b) { \
1091 *(unsigned long *)fb = \
1092 SWAP32((unsigned long)(((r<<16) | \
1098 #ifdef VIDEO_FB_LITTLE_ENDIAN
1099 #define FILL_24BIT_888RGB(r,g,b) { \
1106 #define FILL_24BIT_888RGB(r,g,b) { \
1114 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1115 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1117 ushort *dst = (ushort *) fb;
1118 ushort color = (ushort) (((r >> 3) << 10) |
1129 * RLE8 bitmap support
1132 #ifdef CONFIG_VIDEO_BMP_RLE8
1133 /* Pre-calculated color table entry */
1136 unsigned short w; /* word */
1137 unsigned int dw; /* double word */
1138 } ce; /* color entry */
1142 * Helper to draw encoded/unencoded run.
1144 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1147 ulong addr = (ulong) *fb;
1153 * Setup offset of the color index in the bitmap.
1154 * Color index of encoded run is at offset 1.
1156 off = enc ? &enc_off : &i;
1158 switch (VIDEO_DATA_FORMAT) {
1159 case GDF__8BIT_INDEX:
1160 for (i = 0; i < cnt; i++)
1161 *(unsigned char *) addr++ = bm[*off];
1163 case GDF_15BIT_555RGB:
1164 case GDF_16BIT_565RGB:
1165 /* differences handled while pre-calculating palette */
1166 for (i = 0; i < cnt; i++) {
1167 *(unsigned short *) addr = p[bm[*off]].ce.w;
1171 case GDF_32BIT_X888RGB:
1172 for (i = 0; i < cnt; i++) {
1173 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1178 *fb = (uchar *) addr; /* return modified address */
1181 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1182 int width, int height)
1186 unsigned int cnt, runlen;
1188 int x, y, bpp, i, ncolors;
1189 struct palette p[256];
1190 struct bmp_color_table_entry cte;
1191 int green_shift, red_off;
1192 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1196 y = __le32_to_cpu(img->header.height) - 1;
1197 ncolors = __le32_to_cpu(img->header.colors_used);
1198 bpp = VIDEO_PIXEL_SIZE;
1199 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1200 (y + yoff) * VIDEO_LINE_LEN +
1203 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1205 /* pre-calculate and setup palette */
1206 switch (VIDEO_DATA_FORMAT) {
1207 case GDF__8BIT_INDEX:
1208 for (i = 0; i < ncolors; i++) {
1209 cte = img->color_table[i];
1210 video_set_lut(i, cte.red, cte.green, cte.blue);
1213 case GDF_15BIT_555RGB:
1214 case GDF_16BIT_565RGB:
1215 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1222 for (i = 0; i < ncolors; i++) {
1223 cte = img->color_table[i];
1224 p[i].ce.w = SWAP16((unsigned short)
1225 (((cte.red >> 3) << red_off) |
1226 ((cte.green >> green_shift) << 5) |
1230 case GDF_32BIT_X888RGB:
1231 for (i = 0; i < ncolors; i++) {
1232 cte = img->color_table[i];
1233 p[i].ce.dw = SWAP32((cte.red << 16) |
1239 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1249 /* scan line end marker */
1253 fbp = (unsigned char *)
1254 ((unsigned int) video_fb_address +
1255 (y + yoff) * VIDEO_LINE_LEN +
1259 /* end of bitmap data marker */
1263 /* run offset marker */
1266 fbp = (unsigned char *)
1267 ((unsigned int) video_fb_address +
1268 (y + yoff) * VIDEO_LINE_LEN +
1286 if (x + runlen > width)
1288 draw_bitmap(&fbp, bm, p, cnt, 0);
1294 bm++; /* 0 padding if length is odd */
1305 if (y < height) { /* only draw into visible area */
1311 if (x + runlen > width)
1313 draw_bitmap(&fbp, bm, p, cnt, 1);
1322 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1328 * Display the BMP file located at address bmp_image.
1330 int video_display_bitmap(ulong bmp_image, int x, int y)
1332 ushort xcount, ycount;
1334 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1337 unsigned long width, height, bpp;
1339 unsigned long compression;
1340 struct bmp_color_table_entry cte;
1342 #ifdef CONFIG_VIDEO_BMP_GZIP
1343 unsigned char *dst = NULL;
1349 if (!((bmp->header.signature[0] == 'B') &&
1350 (bmp->header.signature[1] == 'M'))) {
1352 #ifdef CONFIG_VIDEO_BMP_GZIP
1354 * Could be a gzipped bmp image, try to decrompress...
1356 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1357 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1359 printf("Error: malloc in gunzip failed!\n");
1363 * NB: we need to force offset of +2
1364 * See doc/README.displaying-bmps
1366 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1367 (uchar *) bmp_image,
1369 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1374 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1375 printf("Image could be truncated "
1376 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1380 * Set addr to decompressed image
1382 bmp = (struct bmp_image *)(dst+2);
1384 if (!((bmp->header.signature[0] == 'B') &&
1385 (bmp->header.signature[1] == 'M'))) {
1386 printf("Error: no valid bmp.gz image at %lx\n",
1392 printf("Error: no valid bmp image at %lx\n", bmp_image);
1394 #endif /* CONFIG_VIDEO_BMP_GZIP */
1397 width = le32_to_cpu(bmp->header.width);
1398 height = le32_to_cpu(bmp->header.height);
1399 bpp = le16_to_cpu(bmp->header.bit_count);
1400 colors = le32_to_cpu(bmp->header.colors_used);
1401 compression = le32_to_cpu(bmp->header.compression);
1403 debug("Display-bmp: %ld x %ld with %d colors\n",
1404 width, height, colors);
1406 if (compression != BMP_BI_RGB
1407 #ifdef CONFIG_VIDEO_BMP_RLE8
1408 && compression != BMP_BI_RLE8
1411 printf("Error: compression type %ld not supported\n",
1413 #ifdef CONFIG_VIDEO_BMP_GZIP
1420 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1422 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1423 if (x == BMP_ALIGN_CENTER)
1424 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1426 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1428 if (y == BMP_ALIGN_CENTER)
1429 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1431 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1432 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1435 * Just ignore elements which are completely beyond screen
1438 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1441 if ((x + width) > VIDEO_VISIBLE_COLS)
1442 width = VIDEO_VISIBLE_COLS - x;
1443 if ((y + height) > VIDEO_VISIBLE_ROWS)
1444 height = VIDEO_VISIBLE_ROWS - y;
1446 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1447 fb = (uchar *) (video_fb_address +
1448 ((y + height - 1) * VIDEO_LINE_LEN) +
1449 x * VIDEO_PIXEL_SIZE);
1451 #ifdef CONFIG_VIDEO_BMP_RLE8
1452 if (compression == BMP_BI_RLE8) {
1453 return display_rle8_bitmap(bmp, x, y, width, height);
1457 /* We handle only 4, 8, or 24 bpp bitmaps */
1458 switch (le16_to_cpu(bmp->header.bit_count)) {
1460 padded_line -= width / 2;
1463 switch (VIDEO_DATA_FORMAT) {
1464 case GDF_32BIT_X888RGB:
1468 * Don't assume that 'width' is an
1471 for (xcount = 0; xcount < width; xcount++) {
1479 cte = bmp->color_table[idx];
1480 FILL_32BIT_X888RGB(cte.red, cte.green,
1483 bmap += padded_line;
1484 fb -= VIDEO_LINE_LEN + width *
1489 puts("4bpp bitmap unsupported with current "
1496 padded_line -= width;
1497 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1499 for (xcount = 0; xcount < colors; ++xcount) {
1500 cte = bmp->color_table[xcount];
1501 video_set_lut(xcount, cte.red, cte.green,
1506 switch (VIDEO_DATA_FORMAT) {
1507 case GDF__8BIT_INDEX:
1514 bmap += padded_line;
1515 fb -= VIDEO_LINE_LEN + width *
1519 case GDF__8BIT_332RGB:
1524 cte = bmp->color_table[*bmap++];
1525 FILL_8BIT_332RGB(cte.red, cte.green,
1528 bmap += padded_line;
1529 fb -= VIDEO_LINE_LEN + width *
1533 case GDF_15BIT_555RGB:
1535 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1541 cte = bmp->color_table[*bmap++];
1542 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1543 fill_555rgb_pswap(fb, xpos++, cte.red,
1548 FILL_15BIT_555RGB(cte.red, cte.green,
1552 bmap += padded_line;
1553 fb -= VIDEO_LINE_LEN + width *
1557 case GDF_16BIT_565RGB:
1562 cte = bmp->color_table[*bmap++];
1563 FILL_16BIT_565RGB(cte.red, cte.green,
1566 bmap += padded_line;
1567 fb -= VIDEO_LINE_LEN + width *
1571 case GDF_32BIT_X888RGB:
1576 cte = bmp->color_table[*bmap++];
1577 FILL_32BIT_X888RGB(cte.red, cte.green,
1580 bmap += padded_line;
1581 fb -= VIDEO_LINE_LEN + width *
1585 case GDF_24BIT_888RGB:
1590 cte = bmp->color_table[*bmap++];
1591 FILL_24BIT_888RGB(cte.red, cte.green,
1594 bmap += padded_line;
1595 fb -= VIDEO_LINE_LEN + width *
1602 padded_line -= 3 * width;
1604 switch (VIDEO_DATA_FORMAT) {
1605 case GDF__8BIT_332RGB:
1610 FILL_8BIT_332RGB(bmap[2], bmap[1],
1614 bmap += padded_line;
1615 fb -= VIDEO_LINE_LEN + width *
1619 case GDF_15BIT_555RGB:
1621 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1627 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1628 fill_555rgb_pswap(fb, xpos++, bmap[2],
1632 FILL_15BIT_555RGB(bmap[2], bmap[1],
1637 bmap += padded_line;
1638 fb -= VIDEO_LINE_LEN + width *
1642 case GDF_16BIT_565RGB:
1647 FILL_16BIT_565RGB(bmap[2], bmap[1],
1651 bmap += padded_line;
1652 fb -= VIDEO_LINE_LEN + width *
1656 case GDF_32BIT_X888RGB:
1661 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1665 bmap += padded_line;
1666 fb -= VIDEO_LINE_LEN + width *
1670 case GDF_24BIT_888RGB:
1675 FILL_24BIT_888RGB(bmap[2], bmap[1],
1679 bmap += padded_line;
1680 fb -= VIDEO_LINE_LEN + width *
1685 printf("Error: 24 bits/pixel bitmap incompatible "
1686 "with current video mode\n");
1691 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1692 le16_to_cpu(bmp->header.bit_count));
1696 #ifdef CONFIG_VIDEO_BMP_GZIP
1702 if (cfb_do_flush_cache)
1703 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1709 #ifdef CONFIG_VIDEO_LOGO
1710 static int video_logo_xpos;
1711 static int video_logo_ypos;
1713 static void plot_logo_or_black(void *screen, int x, int y, int black);
1715 static void logo_plot(void *screen, int x, int y)
1717 plot_logo_or_black(screen, x, y, 0);
1720 static void logo_black(void)
1722 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1726 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1729 return cmd_usage(cmdtp);
1736 clrlogo, 1, 0, do_clrlogo,
1737 "fill the boot logo area with black",
1741 static void plot_logo_or_black(void *screen, int x, int y, int black)
1745 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1746 int ycount = video_logo_height;
1747 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1748 unsigned char *source;
1749 unsigned char *dest;
1751 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1752 if (x == BMP_ALIGN_CENTER)
1753 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1755 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1757 if (y == BMP_ALIGN_CENTER)
1758 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1760 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1761 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1763 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1765 #ifdef CONFIG_VIDEO_BMP_LOGO
1766 source = bmp_logo_bitmap;
1768 /* Allocate temporary space for computing colormap */
1769 logo_red = malloc(BMP_LOGO_COLORS);
1770 logo_green = malloc(BMP_LOGO_COLORS);
1771 logo_blue = malloc(BMP_LOGO_COLORS);
1772 /* Compute color map */
1773 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1774 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1775 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1776 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1779 source = linux_logo;
1780 logo_red = linux_logo_red;
1781 logo_green = linux_logo_green;
1782 logo_blue = linux_logo_blue;
1785 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1786 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1787 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1788 logo_red[i], logo_green[i],
1794 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1797 xcount = VIDEO_LOGO_WIDTH;
1804 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1805 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1806 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1809 switch (VIDEO_DATA_FORMAT) {
1810 case GDF__8BIT_INDEX:
1813 case GDF__8BIT_332RGB:
1814 *dest = ((r >> 5) << 5) |
1818 case GDF_15BIT_555RGB:
1819 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1820 fill_555rgb_pswap(dest, xpos++, r, g, b);
1822 *(unsigned short *) dest =
1823 SWAP16((unsigned short) (
1829 case GDF_16BIT_565RGB:
1830 *(unsigned short *) dest =
1831 SWAP16((unsigned short) (
1836 case GDF_32BIT_X888RGB:
1837 *(unsigned long *) dest =
1838 SWAP32((unsigned long) (
1843 case GDF_24BIT_888RGB:
1844 #ifdef VIDEO_FB_LITTLE_ENDIAN
1856 dest += VIDEO_PIXEL_SIZE;
1860 #ifdef CONFIG_VIDEO_BMP_LOGO
1867 static void *video_logo(void)
1870 __maybe_unused int y_off = 0;
1871 __maybe_unused ulong addr;
1872 __maybe_unused char *s;
1873 __maybe_unused int len, space;
1875 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1877 #ifdef CONFIG_SPLASH_SCREEN
1878 s = getenv("splashimage");
1880 splash_screen_prepare();
1881 addr = simple_strtoul(s, NULL, 16);
1883 if (video_display_bitmap(addr,
1885 video_logo_ypos) == 0) {
1886 video_logo_height = 0;
1887 return ((void *) (video_fb_address));
1890 #endif /* CONFIG_SPLASH_SCREEN */
1892 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1894 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1896 * when using splashpos for video_logo, skip any info
1897 * output on video console if the logo is not at 0,0
1899 if (video_logo_xpos || video_logo_ypos) {
1901 * video_logo_height is used in text and cursor offset
1902 * calculations. Since the console is below the logo,
1903 * we need to adjust the logo height
1905 if (video_logo_ypos == BMP_ALIGN_CENTER)
1906 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1907 VIDEO_LOGO_HEIGHT) / 2);
1908 else if (video_logo_ypos > 0)
1909 video_logo_height += video_logo_ypos;
1911 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1914 if (board_cfb_skip())
1917 sprintf(info, " %s", version_string);
1919 #ifndef CONFIG_HIDE_LOGO_VERSION
1920 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1924 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1925 (uchar *) info, space);
1926 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1927 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1928 (uchar *) info + space, len - space);
1931 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1933 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1936 ((video_logo_height -
1937 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1939 for (i = 1; i < n; i++) {
1940 video_get_info_str(i, info);
1946 video_drawchars(VIDEO_INFO_X,
1950 (uchar *) info, space);
1952 video_drawchars(VIDEO_INFO_X +
1957 (uchar *) info + space,
1960 video_drawstring(VIDEO_INFO_X,
1971 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1975 static int cfb_fb_is_in_dram(void)
1978 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1979 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1983 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1984 start = bd->bi_dram[i].start;
1985 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1986 if ((ulong)video_fb_address >= start &&
1987 (ulong)video_fb_address < end)
1991 if ((ulong)video_fb_address >= bd->bi_memstart &&
1992 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1998 void video_clear(void)
2000 if (!video_fb_address)
2002 #ifdef VIDEO_HW_RECTFILL
2003 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2006 VIDEO_VISIBLE_COLS, /* frame width */
2007 VIDEO_VISIBLE_ROWS, /* frame height */
2008 bgx /* fill color */
2011 memsetl(video_fb_address,
2012 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2016 static int video_init(void)
2018 unsigned char color8;
2020 pGD = video_hw_init();
2024 video_fb_address = (void *) VIDEO_FB_ADRS;
2026 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2028 /* Init drawing pats */
2029 switch (VIDEO_DATA_FORMAT) {
2030 case GDF__8BIT_INDEX:
2031 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2032 CONFIG_SYS_CONSOLE_FG_COL,
2033 CONFIG_SYS_CONSOLE_FG_COL);
2034 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2035 CONFIG_SYS_CONSOLE_BG_COL,
2036 CONFIG_SYS_CONSOLE_BG_COL);
2040 case GDF__8BIT_332RGB:
2041 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2042 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2043 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2044 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2046 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2047 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2048 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2049 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2052 case GDF_15BIT_555RGB:
2053 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2054 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2055 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2056 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2057 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2058 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2059 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2060 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2061 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2062 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2063 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2064 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2066 case GDF_16BIT_565RGB:
2067 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2068 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2069 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2070 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2071 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2072 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2073 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2074 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2075 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2076 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2077 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2078 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2080 case GDF_32BIT_X888RGB:
2081 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2082 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2083 CONFIG_SYS_CONSOLE_FG_COL;
2084 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2085 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2086 CONFIG_SYS_CONSOLE_BG_COL;
2088 case GDF_24BIT_888RGB:
2089 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2090 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2091 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2092 CONFIG_SYS_CONSOLE_FG_COL;
2093 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2094 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2095 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2096 CONFIG_SYS_CONSOLE_BG_COL;
2103 #ifdef CONFIG_VIDEO_LOGO
2104 /* Plot the logo and get start point of console */
2105 debug("Video: Drawing the logo ...\n");
2106 video_console_address = video_logo();
2108 video_console_address = video_fb_address;
2111 /* Initialize the console */
2115 if (cfb_do_flush_cache)
2116 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2122 * Implement a weak default function for boards that optionally
2123 * need to skip the video initialization.
2125 __weak int board_video_skip(void)
2127 /* As default, don't skip test */
2131 int drv_video_init(void)
2133 struct stdio_dev console_dev;
2135 bool __maybe_unused keyboard_ok = false;
2137 /* Check if video initialization should be skipped */
2138 if (board_video_skip())
2141 /* Init video chip - returns with framebuffer cleared */
2142 if (video_init() == -1)
2145 if (board_cfb_skip())
2148 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2149 have_keyboard = false;
2150 #elif defined(CONFIG_OF_CONTROL)
2151 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2152 "u-boot,no-keyboard");
2154 have_keyboard = true;
2156 if (have_keyboard) {
2157 debug("KBD: Keyboard init ...\n");
2158 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2159 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2163 /* Init vga device */
2164 memset(&console_dev, 0, sizeof(console_dev));
2165 strcpy(console_dev.name, "vga");
2166 console_dev.flags = DEV_FLAGS_OUTPUT;
2167 console_dev.putc = video_putc; /* 'putc' function */
2168 console_dev.puts = video_puts; /* 'puts' function */
2170 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2171 if (have_keyboard && keyboard_ok) {
2172 /* Also init console device */
2173 console_dev.flags |= DEV_FLAGS_INPUT;
2174 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2175 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2179 if (stdio_register(&console_dev) != 0)
2182 /* Return success */
2186 void video_position_cursor(unsigned col, unsigned row)
2188 console_col = min(col, CONSOLE_COLS - 1);
2189 console_row = min(row, CONSOLE_ROWS - 1);
2192 int video_get_pixel_width(void)
2194 return VIDEO_VISIBLE_COLS;
2197 int video_get_pixel_height(void)
2199 return VIDEO_VISIBLE_ROWS;
2202 int video_get_screen_rows(void)
2204 return CONSOLE_ROWS;
2207 int video_get_screen_columns(void)
2209 return CONSOLE_COLS;