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.
61 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
62 * initialized as an output only device.
63 * The Keyboard driver will not be
64 * set-up. This may be used, if you have
65 * no or more than one Keyboard devices
66 * (USB Keyboard, AT Keyboard).
68 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
69 * character. No blinking is provided.
70 * Uses the macros CURSOR_SET and
73 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
74 * of the graphic chip. Uses the macro
75 * CURSOR_SET. ATTENTION: If booting an
76 * OS, the display driver must disable
77 * the hardware register of the graphic
78 * chip. Otherwise a blinking field is
86 #include <linux/compiler.h>
89 * Defines for the CT69000 driver
91 #ifdef CONFIG_VIDEO_CT69000
93 #define VIDEO_FB_LITTLE_ENDIAN
94 #define VIDEO_HW_RECTFILL
95 #define VIDEO_HW_BITBLT
98 #if defined(CONFIG_VIDEO_MXS)
99 #define VIDEO_FB_16BPP_WORD_SWAP
103 * Defines for the MB862xx driver
105 #ifdef CONFIG_VIDEO_MB862xx
107 #ifdef CONFIG_VIDEO_CORALP
108 #define VIDEO_FB_LITTLE_ENDIAN
110 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
111 #define VIDEO_HW_RECTFILL
112 #define VIDEO_HW_BITBLT
117 * Defines for the i.MX31 driver (mx3fb.c)
119 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
120 #define VIDEO_FB_16BPP_WORD_SWAP
124 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
126 #include <video_fb.h>
133 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
134 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
135 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
136 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
137 #define VIDEO_FB_ADRS (pGD->frameAdrs)
144 #include <linux/types.h>
145 #include <stdio_dev.h>
146 #include <video_font.h>
148 #if defined(CONFIG_CMD_DATE)
152 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
153 #include <watchdog.h>
154 #include <bmp_layout.h>
160 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
161 * blinking is provided. Uses the macros CURSOR_SET
163 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
164 * graphic chip. Uses the macro CURSOR_SET.
165 * ATTENTION: If booting an OS, the display driver
166 * must disable the hardware register of the graphic
167 * chip. Otherwise a blinking field is displayed
169 #if !defined(CONFIG_VIDEO_SW_CURSOR) && !defined(CONFIG_VIDEO_HW_CURSOR)
170 /* no Cursor defined */
176 #if defined(CONFIG_VIDEO_SW_CURSOR)
177 #if defined(CONFIG_VIDEO_HW_CURSOR)
178 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
181 void console_cursor(int state);
183 #define CURSOR_ON console_cursor(1)
184 #define CURSOR_OFF console_cursor(0)
185 #define CURSOR_SET video_set_cursor()
186 #endif /* CONFIG_VIDEO_SW_CURSOR */
188 #ifdef CONFIG_VIDEO_HW_CURSOR
190 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
195 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
196 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
197 #endif /* CONFIG_VIDEO_HW_CURSOR */
199 #ifdef CONFIG_VIDEO_LOGO
200 #ifdef CONFIG_VIDEO_BMP_LOGO
201 #include <bmp_logo.h>
202 #include <bmp_logo_data.h>
203 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
204 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
205 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
206 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
208 #else /* CONFIG_VIDEO_BMP_LOGO */
209 #define LINUX_LOGO_WIDTH 80
210 #define LINUX_LOGO_HEIGHT 80
211 #define LINUX_LOGO_COLORS 214
212 #define LINUX_LOGO_LUT_OFFSET 0x20
214 #include <linux_logo.h>
215 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
216 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
217 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
218 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
219 #endif /* CONFIG_VIDEO_BMP_LOGO */
220 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
221 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
222 #else /* CONFIG_VIDEO_LOGO */
223 #define VIDEO_LOGO_WIDTH 0
224 #define VIDEO_LOGO_HEIGHT 0
225 #endif /* CONFIG_VIDEO_LOGO */
227 #define VIDEO_COLS VIDEO_VISIBLE_COLS
228 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
229 #ifndef VIDEO_LINE_LEN
230 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
232 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
233 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
235 #ifdef CONFIG_VIDEO_LOGO
236 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
238 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
241 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
242 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
243 #define CONSOLE_ROW_FIRST (video_console_address)
244 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
245 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
246 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
248 /* By default we scroll by a single line */
249 #ifndef CONFIG_CONSOLE_SCROLL_LINES
250 #define CONFIG_CONSOLE_SCROLL_LINES 1
254 #ifdef VIDEO_FB_LITTLE_ENDIAN
255 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
258 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
259 (((x) & 0x0000ff00) << 8) | \
260 (((x) & 0x00ff0000) >> 8) | \
261 (((x) & 0xff000000) >> 24) \
263 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
264 (((x) & 0x0000ff00) >> 8) | \
265 (((x) & 0x00ff0000) << 8) | \
266 (((x) & 0xff000000) >> 8) \
269 #define SWAP16(x) (x)
270 #define SWAP32(x) (x)
271 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
272 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
274 #define SHORTSWAP32(x) (x)
278 #ifdef CONFIG_CONSOLE_EXTRA_INFO
280 * setup a board string: type, speed, etc.
282 * line_number: location to place info string beside logo
283 * info: buffer for info string
285 extern void video_get_info_str(int line_number, char *info);
288 DECLARE_GLOBAL_DATA_PTR;
291 static GraphicDevice *pGD; /* Pointer to Graphic array */
293 static void *video_fb_address; /* frame buffer address */
294 static void *video_console_address; /* console buffer start address */
296 static int video_logo_height = VIDEO_LOGO_HEIGHT;
298 static int __maybe_unused cursor_state;
299 static int __maybe_unused old_col;
300 static int __maybe_unused old_row;
302 static int console_col; /* cursor col */
303 static int console_row; /* cursor row */
305 static u32 eorx, fgx, bgx; /* color pats */
307 static int cfb_do_flush_cache;
309 #ifdef CONFIG_CFB_CONSOLE_ANSI
310 static char ansi_buf[10];
311 static int ansi_buf_size;
312 static int ansi_colors_need_revert;
313 static int ansi_cursor_hidden;
316 static const int video_font_draw_table8[] = {
317 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
318 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
319 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
320 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
323 static const int video_font_draw_table15[] = {
324 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
327 static const int video_font_draw_table16[] = {
328 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
331 static const int video_font_draw_table24[16][3] = {
332 {0x00000000, 0x00000000, 0x00000000},
333 {0x00000000, 0x00000000, 0x00ffffff},
334 {0x00000000, 0x0000ffff, 0xff000000},
335 {0x00000000, 0x0000ffff, 0xffffffff},
336 {0x000000ff, 0xffff0000, 0x00000000},
337 {0x000000ff, 0xffff0000, 0x00ffffff},
338 {0x000000ff, 0xffffffff, 0xff000000},
339 {0x000000ff, 0xffffffff, 0xffffffff},
340 {0xffffff00, 0x00000000, 0x00000000},
341 {0xffffff00, 0x00000000, 0x00ffffff},
342 {0xffffff00, 0x0000ffff, 0xff000000},
343 {0xffffff00, 0x0000ffff, 0xffffffff},
344 {0xffffffff, 0xffff0000, 0x00000000},
345 {0xffffffff, 0xffff0000, 0x00ffffff},
346 {0xffffffff, 0xffffffff, 0xff000000},
347 {0xffffffff, 0xffffffff, 0xffffffff}
350 static const int video_font_draw_table32[16][4] = {
351 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
352 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
353 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
354 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
355 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
356 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
357 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
358 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
359 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
360 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
361 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
362 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
363 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
364 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
365 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
366 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
370 * Implement a weak default function for boards that optionally
371 * need to skip the cfb initialization.
373 __weak int board_cfb_skip(void)
375 /* As default, don't skip cfb init */
379 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
381 u8 *cdat, *dest, *dest0;
384 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
385 dest0 = video_fb_address + offset;
387 switch (VIDEO_DATA_FORMAT) {
388 case GDF__8BIT_INDEX:
389 case GDF__8BIT_332RGB:
392 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
393 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
394 rows--; dest += VIDEO_LINE_LEN) {
398 (video_font_draw_table8[bits >> 4] &
401 if (VIDEO_FONT_WIDTH == 4)
405 (video_font_draw_table8[bits & 15] &
408 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
413 case GDF_15BIT_555RGB:
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_table15
423 [bits >> 6] & eorx) ^
426 SHORTSWAP32((video_font_draw_table15
427 [bits >> 4 & 3] & eorx) ^
430 if (VIDEO_FONT_WIDTH == 4)
434 SHORTSWAP32((video_font_draw_table15
435 [bits >> 2 & 3] & eorx) ^
438 SHORTSWAP32((video_font_draw_table15
442 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
447 case GDF_16BIT_565RGB:
450 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
451 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
452 rows--; dest += VIDEO_LINE_LEN) {
456 SHORTSWAP32((video_font_draw_table16
457 [bits >> 6] & eorx) ^
460 SHORTSWAP32((video_font_draw_table16
461 [bits >> 4 & 3] & eorx) ^
464 if (VIDEO_FONT_WIDTH == 4)
468 SHORTSWAP32((video_font_draw_table16
469 [bits >> 2 & 3] & eorx) ^
472 SHORTSWAP32((video_font_draw_table16
476 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
481 case GDF_32BIT_X888RGB:
484 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
485 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
486 rows--; dest += VIDEO_LINE_LEN) {
490 SWAP32((video_font_draw_table32
491 [bits >> 4][0] & eorx) ^ bgx);
493 SWAP32((video_font_draw_table32
494 [bits >> 4][1] & eorx) ^ bgx);
496 SWAP32((video_font_draw_table32
497 [bits >> 4][2] & eorx) ^ bgx);
499 SWAP32((video_font_draw_table32
500 [bits >> 4][3] & eorx) ^ bgx);
503 if (VIDEO_FONT_WIDTH == 4)
507 SWAP32((video_font_draw_table32
508 [bits & 15][0] & eorx) ^ bgx);
510 SWAP32((video_font_draw_table32
511 [bits & 15][1] & eorx) ^ bgx);
513 SWAP32((video_font_draw_table32
514 [bits & 15][2] & eorx) ^ bgx);
516 SWAP32((video_font_draw_table32
517 [bits & 15][3] & eorx) ^ bgx);
519 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
524 case GDF_24BIT_888RGB:
527 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
528 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
529 rows--; dest += VIDEO_LINE_LEN) {
533 (video_font_draw_table24[bits >> 4][0]
536 (video_font_draw_table24[bits >> 4][1]
539 (video_font_draw_table24[bits >> 4][2]
542 if (VIDEO_FONT_WIDTH == 4)
546 (video_font_draw_table24[bits & 15][0]
549 (video_font_draw_table24[bits & 15][1]
552 (video_font_draw_table24[bits & 15][2]
555 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
562 static inline void video_drawstring(int xx, int yy, unsigned char *s)
564 video_drawchars(xx, yy, s, strlen((char *) s));
567 static void video_putchar(int xx, int yy, unsigned char c)
569 video_drawchars(xx, yy + video_logo_height, &c, 1);
572 #if defined(CONFIG_VIDEO_SW_CURSOR)
573 static void video_set_cursor(void)
580 static void video_invertchar(int xx, int yy)
582 int firstx = xx * VIDEO_PIXEL_SIZE;
583 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
584 int firsty = yy * VIDEO_LINE_LEN;
585 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
587 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
588 for (x = firstx; x < lastx; x++) {
589 u8 *dest = (u8 *)(video_fb_address) + x + y;
595 void console_cursor(int state)
597 if (cursor_state != state) {
599 /* turn off the cursor */
600 video_invertchar(old_col * VIDEO_FONT_WIDTH,
601 old_row * VIDEO_FONT_HEIGHT +
604 /* turn off the cursor and record where it is */
605 video_invertchar(console_col * VIDEO_FONT_WIDTH,
606 console_row * VIDEO_FONT_HEIGHT +
608 old_col = console_col;
609 old_row = console_row;
611 cursor_state = state;
613 if (cfb_do_flush_cache)
614 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
618 #ifndef VIDEO_HW_RECTFILL
619 static void memsetl(int *p, int c, int v)
626 #ifndef VIDEO_HW_BITBLT
627 static void memcpyl(int *d, int *s, int c)
634 static void console_clear_line(int line, int begin, int end)
636 #ifdef VIDEO_HW_RECTFILL
637 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
638 VIDEO_FONT_WIDTH * begin, /* dest pos x */
640 VIDEO_FONT_HEIGHT * line, /* dest pos y */
641 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
642 VIDEO_FONT_HEIGHT, /* frame height */
646 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
647 memsetl(CONSOLE_ROW_FIRST +
648 CONSOLE_ROW_SIZE * line, /* offset of row */
649 CONSOLE_ROW_SIZE >> 2, /* length of row */
656 offset = CONSOLE_ROW_FIRST +
657 CONSOLE_ROW_SIZE * line + /* offset of row */
659 VIDEO_PIXEL_SIZE * begin; /* offset of col */
660 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
661 size >>= 2; /* length to end for memsetl() */
662 /* fill at col offset of i'th line using bgx as fill color */
663 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
664 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
669 static void console_scrollup(void)
671 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
674 /* copy up rows ignoring the first one */
676 #ifdef VIDEO_HW_BITBLT
677 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
678 0, /* source pos x */
680 VIDEO_FONT_HEIGHT * rows, /* source pos y */
682 video_logo_height, /* dest pos y */
683 VIDEO_VISIBLE_COLS, /* frame width */
686 - VIDEO_FONT_HEIGHT * rows /* frame height */
689 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
690 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
692 /* clear the last one */
693 for (i = 1; i <= rows; i++)
694 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
696 /* Decrement row number */
700 static void console_back(void)
704 if (console_col < 0) {
705 console_col = CONSOLE_COLS - 1;
712 #ifdef CONFIG_CFB_CONSOLE_ANSI
714 static void console_clear(void)
716 #ifdef VIDEO_HW_RECTFILL
717 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
719 video_logo_height, /* dest pos y */
720 VIDEO_VISIBLE_COLS, /* frame width */
721 VIDEO_VISIBLE_ROWS, /* frame height */
725 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
729 static void console_cursor_fix(void)
733 if (console_row >= CONSOLE_ROWS)
734 console_row = CONSOLE_ROWS - 1;
737 if (console_col >= CONSOLE_COLS)
738 console_col = CONSOLE_COLS - 1;
741 static void console_cursor_up(int n)
744 console_cursor_fix();
747 static void console_cursor_down(int n)
750 console_cursor_fix();
753 static void console_cursor_left(int n)
756 console_cursor_fix();
759 static void console_cursor_right(int n)
762 console_cursor_fix();
765 static void console_cursor_set_position(int row, int col)
767 if (console_row != -1)
769 if (console_col != -1)
771 console_cursor_fix();
774 static void console_previousline(int n)
776 /* FIXME: also scroll terminal ? */
778 console_cursor_fix();
781 static void console_swap_colors(void)
789 static inline int console_cursor_is_visible(void)
791 return !ansi_cursor_hidden;
794 static inline int console_cursor_is_visible(void)
800 static void console_newline(int n)
805 /* Check if we need to scroll the terminal */
806 if (console_row >= CONSOLE_ROWS) {
807 /* Scroll everything up */
812 static void console_cr(void)
817 static void parse_putc(const char c)
821 if (console_cursor_is_visible())
825 case 13: /* back to first column */
829 case '\n': /* next line */
830 if (console_col || (!console_col && nl))
836 console_col |= 0x0008;
837 console_col &= ~0x0007;
839 if (console_col >= CONSOLE_COLS)
843 case 8: /* backspace */
850 default: /* draw the char */
851 video_putchar(console_col * VIDEO_FONT_WIDTH,
852 console_row * VIDEO_FONT_HEIGHT, c);
855 /* check for newline */
856 if (console_col >= CONSOLE_COLS) {
862 if (console_cursor_is_visible())
866 static void video_putc(struct stdio_dev *dev, const char c)
868 #ifdef CONFIG_CFB_CONSOLE_ANSI
872 for (i = 0; i < ansi_buf_size; ++i)
873 parse_putc(ansi_buf[i]);
879 if (ansi_buf_size > 0) {
899 ansi_buf[ansi_buf_size++] = c;
901 if (ansi_buf_size >= sizeof(ansi_buf))
904 for (i = 0; i < ansi_buf_size; ++i) {
910 if (ansi_buf[i] == 27)
917 if (ansi_buf[i] == '[')
924 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
925 num1 = ansi_buf[i]-'0';
927 } else if (ansi_buf[i] != '?') {
935 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
937 num1 += ansi_buf[i]-'0';
945 if (ansi_buf[i] != ';') {
953 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
954 num2 = ansi_buf[i]-'0';
961 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
963 num2 += ansi_buf[i]-'0';
971 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
972 || ansi_buf[i] == 'J'
973 || ansi_buf[i] == 'K'
974 || ansi_buf[i] == 'h'
975 || ansi_buf[i] == 'l'
976 || ansi_buf[i] == 'm') {
986 for (i = 0; i < ansi_buf_size; ++i)
987 parse_putc(ansi_buf[i]);
993 if (!ansi_cursor_hidden)
998 /* move cursor num1 rows up */
999 console_cursor_up(num1);
1002 /* move cursor num1 rows down */
1003 console_cursor_down(num1);
1006 /* move cursor num1 columns forward */
1007 console_cursor_right(num1);
1010 /* move cursor num1 columns back */
1011 console_cursor_left(num1);
1014 /* move cursor num1 rows up at begin of row */
1015 console_previousline(num1);
1018 /* move cursor num1 rows down at begin of row */
1019 console_newline(num1);
1022 /* move cursor to column num1 */
1023 console_cursor_set_position(-1, num1-1);
1026 /* move cursor to row num1, column num2 */
1027 console_cursor_set_position(num1-1, num2-1);
1030 /* clear console and move cursor to 0, 0 */
1032 console_cursor_set_position(0, 0);
1037 console_clear_line(console_row,
1041 console_clear_line(console_row,
1044 console_clear_line(console_row,
1048 ansi_cursor_hidden = 0;
1051 ansi_cursor_hidden = 1;
1054 if (num1 == 0) { /* reset swapped colors */
1055 if (ansi_colors_need_revert) {
1056 console_swap_colors();
1057 ansi_colors_need_revert = 0;
1059 } else if (num1 == 7) { /* once swap colors */
1060 if (!ansi_colors_need_revert) {
1061 console_swap_colors();
1062 ansi_colors_need_revert = 1;
1067 if (!ansi_cursor_hidden)
1076 if (cfb_do_flush_cache)
1077 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1080 static void video_puts(struct stdio_dev *dev, const char *s)
1082 int flush = cfb_do_flush_cache;
1083 int count = strlen(s);
1085 /* temporarily disable cache flush */
1086 cfb_do_flush_cache = 0;
1089 video_putc(dev, *s++);
1092 cfb_do_flush_cache = flush;
1093 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1098 * Do not enforce drivers (or board code) to provide empty
1099 * video_set_lut() if they do not support 8 bpp format.
1100 * Implement weak default function instead.
1102 __weak void video_set_lut(unsigned int index, unsigned char r,
1103 unsigned char g, unsigned char b)
1107 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1109 #define FILL_8BIT_332RGB(r,g,b) { \
1110 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1114 #define FILL_15BIT_555RGB(r,g,b) { \
1115 *(unsigned short *)fb = \
1116 SWAP16((unsigned short)(((r>>3)<<10) | \
1122 #define FILL_16BIT_565RGB(r,g,b) { \
1123 *(unsigned short *)fb = \
1124 SWAP16((unsigned short)((((r)>>3)<<11)| \
1130 #define FILL_32BIT_X888RGB(r,g,b) { \
1131 *(unsigned long *)fb = \
1132 SWAP32((unsigned long)(((r<<16) | \
1138 #ifdef VIDEO_FB_LITTLE_ENDIAN
1139 #define FILL_24BIT_888RGB(r,g,b) { \
1146 #define FILL_24BIT_888RGB(r,g,b) { \
1154 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1155 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1157 ushort *dst = (ushort *) fb;
1158 ushort color = (ushort) (((r >> 3) << 10) |
1169 * RLE8 bitmap support
1172 #ifdef CONFIG_VIDEO_BMP_RLE8
1173 /* Pre-calculated color table entry */
1176 unsigned short w; /* word */
1177 unsigned int dw; /* double word */
1178 } ce; /* color entry */
1182 * Helper to draw encoded/unencoded run.
1184 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1187 ulong addr = (ulong) *fb;
1193 * Setup offset of the color index in the bitmap.
1194 * Color index of encoded run is at offset 1.
1196 off = enc ? &enc_off : &i;
1198 switch (VIDEO_DATA_FORMAT) {
1199 case GDF__8BIT_INDEX:
1200 for (i = 0; i < cnt; i++)
1201 *(unsigned char *) addr++ = bm[*off];
1203 case GDF_15BIT_555RGB:
1204 case GDF_16BIT_565RGB:
1205 /* differences handled while pre-calculating palette */
1206 for (i = 0; i < cnt; i++) {
1207 *(unsigned short *) addr = p[bm[*off]].ce.w;
1211 case GDF_32BIT_X888RGB:
1212 for (i = 0; i < cnt; i++) {
1213 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1218 *fb = (uchar *) addr; /* return modified address */
1221 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1222 int width, int height)
1226 unsigned int cnt, runlen;
1228 int x, y, bpp, i, ncolors;
1229 struct palette p[256];
1230 struct bmp_color_table_entry cte;
1231 int green_shift, red_off;
1232 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1236 y = __le32_to_cpu(img->header.height) - 1;
1237 ncolors = __le32_to_cpu(img->header.colors_used);
1238 bpp = VIDEO_PIXEL_SIZE;
1239 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1240 (y + yoff) * VIDEO_LINE_LEN +
1243 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1245 /* pre-calculate and setup palette */
1246 switch (VIDEO_DATA_FORMAT) {
1247 case GDF__8BIT_INDEX:
1248 for (i = 0; i < ncolors; i++) {
1249 cte = img->color_table[i];
1250 video_set_lut(i, cte.red, cte.green, cte.blue);
1253 case GDF_15BIT_555RGB:
1254 case GDF_16BIT_565RGB:
1255 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1262 for (i = 0; i < ncolors; i++) {
1263 cte = img->color_table[i];
1264 p[i].ce.w = SWAP16((unsigned short)
1265 (((cte.red >> 3) << red_off) |
1266 ((cte.green >> green_shift) << 5) |
1270 case GDF_32BIT_X888RGB:
1271 for (i = 0; i < ncolors; i++) {
1272 cte = img->color_table[i];
1273 p[i].ce.dw = SWAP32((cte.red << 16) |
1279 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1289 /* scan line end marker */
1293 fbp = (unsigned char *)
1294 ((unsigned int) video_fb_address +
1295 (y + yoff) * VIDEO_LINE_LEN +
1299 /* end of bitmap data marker */
1303 /* run offset marker */
1306 fbp = (unsigned char *)
1307 ((unsigned int) video_fb_address +
1308 (y + yoff) * VIDEO_LINE_LEN +
1326 if (x + runlen > width)
1328 draw_bitmap(&fbp, bm, p, cnt, 0);
1334 bm++; /* 0 padding if length is odd */
1345 if (y < height) { /* only draw into visible area */
1351 if (x + runlen > width)
1353 draw_bitmap(&fbp, bm, p, cnt, 1);
1362 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1368 * Display the BMP file located at address bmp_image.
1370 int video_display_bitmap(ulong bmp_image, int x, int y)
1372 ushort xcount, ycount;
1374 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1377 unsigned long width, height, bpp;
1379 unsigned long compression;
1380 struct bmp_color_table_entry cte;
1382 #ifdef CONFIG_VIDEO_BMP_GZIP
1383 unsigned char *dst = NULL;
1389 if (!((bmp->header.signature[0] == 'B') &&
1390 (bmp->header.signature[1] == 'M'))) {
1392 #ifdef CONFIG_VIDEO_BMP_GZIP
1394 * Could be a gzipped bmp image, try to decrompress...
1396 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1397 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1399 printf("Error: malloc in gunzip failed!\n");
1403 * NB: we need to force offset of +2
1404 * See doc/README.displaying-bmps
1406 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1407 (uchar *) bmp_image,
1409 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1414 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1415 printf("Image could be truncated "
1416 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1420 * Set addr to decompressed image
1422 bmp = (struct bmp_image *)(dst+2);
1424 if (!((bmp->header.signature[0] == 'B') &&
1425 (bmp->header.signature[1] == 'M'))) {
1426 printf("Error: no valid bmp.gz image at %lx\n",
1432 printf("Error: no valid bmp image at %lx\n", bmp_image);
1434 #endif /* CONFIG_VIDEO_BMP_GZIP */
1437 width = le32_to_cpu(bmp->header.width);
1438 height = le32_to_cpu(bmp->header.height);
1439 bpp = le16_to_cpu(bmp->header.bit_count);
1440 colors = le32_to_cpu(bmp->header.colors_used);
1441 compression = le32_to_cpu(bmp->header.compression);
1443 debug("Display-bmp: %ld x %ld with %d colors\n",
1444 width, height, colors);
1446 if (compression != BMP_BI_RGB
1447 #ifdef CONFIG_VIDEO_BMP_RLE8
1448 && compression != BMP_BI_RLE8
1451 printf("Error: compression type %ld not supported\n",
1453 #ifdef CONFIG_VIDEO_BMP_GZIP
1460 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1462 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1463 if (x == BMP_ALIGN_CENTER)
1464 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1466 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1468 if (y == BMP_ALIGN_CENTER)
1469 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1471 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1472 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1475 * Just ignore elements which are completely beyond screen
1478 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1481 if ((x + width) > VIDEO_VISIBLE_COLS)
1482 width = VIDEO_VISIBLE_COLS - x;
1483 if ((y + height) > VIDEO_VISIBLE_ROWS)
1484 height = VIDEO_VISIBLE_ROWS - y;
1486 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1487 fb = (uchar *) (video_fb_address +
1488 ((y + height - 1) * VIDEO_LINE_LEN) +
1489 x * VIDEO_PIXEL_SIZE);
1491 #ifdef CONFIG_VIDEO_BMP_RLE8
1492 if (compression == BMP_BI_RLE8) {
1493 return display_rle8_bitmap(bmp, x, y, width, height);
1497 /* We handle only 4, 8, or 24 bpp bitmaps */
1498 switch (le16_to_cpu(bmp->header.bit_count)) {
1500 padded_line -= width / 2;
1503 switch (VIDEO_DATA_FORMAT) {
1504 case GDF_32BIT_X888RGB:
1508 * Don't assume that 'width' is an
1511 for (xcount = 0; xcount < width; xcount++) {
1519 cte = bmp->color_table[idx];
1520 FILL_32BIT_X888RGB(cte.red, cte.green,
1523 bmap += padded_line;
1524 fb -= VIDEO_LINE_LEN + width *
1529 puts("4bpp bitmap unsupported with current "
1536 padded_line -= width;
1537 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1539 for (xcount = 0; xcount < colors; ++xcount) {
1540 cte = bmp->color_table[xcount];
1541 video_set_lut(xcount, cte.red, cte.green,
1546 switch (VIDEO_DATA_FORMAT) {
1547 case GDF__8BIT_INDEX:
1554 bmap += padded_line;
1555 fb -= VIDEO_LINE_LEN + width *
1559 case GDF__8BIT_332RGB:
1564 cte = bmp->color_table[*bmap++];
1565 FILL_8BIT_332RGB(cte.red, cte.green,
1568 bmap += padded_line;
1569 fb -= VIDEO_LINE_LEN + width *
1573 case GDF_15BIT_555RGB:
1575 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1581 cte = bmp->color_table[*bmap++];
1582 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1583 fill_555rgb_pswap(fb, xpos++, cte.red,
1588 FILL_15BIT_555RGB(cte.red, cte.green,
1592 bmap += padded_line;
1593 fb -= VIDEO_LINE_LEN + width *
1597 case GDF_16BIT_565RGB:
1602 cte = bmp->color_table[*bmap++];
1603 FILL_16BIT_565RGB(cte.red, cte.green,
1606 bmap += padded_line;
1607 fb -= VIDEO_LINE_LEN + width *
1611 case GDF_32BIT_X888RGB:
1616 cte = bmp->color_table[*bmap++];
1617 FILL_32BIT_X888RGB(cte.red, cte.green,
1620 bmap += padded_line;
1621 fb -= VIDEO_LINE_LEN + width *
1625 case GDF_24BIT_888RGB:
1630 cte = bmp->color_table[*bmap++];
1631 FILL_24BIT_888RGB(cte.red, cte.green,
1634 bmap += padded_line;
1635 fb -= VIDEO_LINE_LEN + width *
1642 padded_line -= 3 * width;
1644 switch (VIDEO_DATA_FORMAT) {
1645 case GDF__8BIT_332RGB:
1650 FILL_8BIT_332RGB(bmap[2], bmap[1],
1654 bmap += padded_line;
1655 fb -= VIDEO_LINE_LEN + width *
1659 case GDF_15BIT_555RGB:
1661 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1667 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1668 fill_555rgb_pswap(fb, xpos++, bmap[2],
1672 FILL_15BIT_555RGB(bmap[2], bmap[1],
1677 bmap += padded_line;
1678 fb -= VIDEO_LINE_LEN + width *
1682 case GDF_16BIT_565RGB:
1687 FILL_16BIT_565RGB(bmap[2], bmap[1],
1691 bmap += padded_line;
1692 fb -= VIDEO_LINE_LEN + width *
1696 case GDF_32BIT_X888RGB:
1701 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1705 bmap += padded_line;
1706 fb -= VIDEO_LINE_LEN + width *
1710 case GDF_24BIT_888RGB:
1715 FILL_24BIT_888RGB(bmap[2], bmap[1],
1719 bmap += padded_line;
1720 fb -= VIDEO_LINE_LEN + width *
1725 printf("Error: 24 bits/pixel bitmap incompatible "
1726 "with current video mode\n");
1731 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1732 le16_to_cpu(bmp->header.bit_count));
1736 #ifdef CONFIG_VIDEO_BMP_GZIP
1742 if (cfb_do_flush_cache)
1743 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1749 #ifdef CONFIG_VIDEO_LOGO
1750 static int video_logo_xpos;
1751 static int video_logo_ypos;
1753 static void plot_logo_or_black(void *screen, int x, int y, int black);
1755 static void logo_plot(void *screen, int x, int y)
1757 plot_logo_or_black(screen, x, y, 0);
1760 static void logo_black(void)
1762 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1766 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1769 return cmd_usage(cmdtp);
1776 clrlogo, 1, 0, do_clrlogo,
1777 "fill the boot logo area with black",
1781 static void plot_logo_or_black(void *screen, int x, int y, int black)
1785 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1786 int ycount = video_logo_height;
1787 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1788 unsigned char *source;
1789 unsigned char *dest;
1791 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1792 if (x == BMP_ALIGN_CENTER)
1793 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1795 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1797 if (y == BMP_ALIGN_CENTER)
1798 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1800 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1801 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1803 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1805 #ifdef CONFIG_VIDEO_BMP_LOGO
1806 source = bmp_logo_bitmap;
1808 /* Allocate temporary space for computing colormap */
1809 logo_red = malloc(BMP_LOGO_COLORS);
1810 logo_green = malloc(BMP_LOGO_COLORS);
1811 logo_blue = malloc(BMP_LOGO_COLORS);
1812 /* Compute color map */
1813 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1814 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1815 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1816 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1819 source = linux_logo;
1820 logo_red = linux_logo_red;
1821 logo_green = linux_logo_green;
1822 logo_blue = linux_logo_blue;
1825 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1826 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1827 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1828 logo_red[i], logo_green[i],
1834 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1837 xcount = VIDEO_LOGO_WIDTH;
1844 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1845 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1846 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1849 switch (VIDEO_DATA_FORMAT) {
1850 case GDF__8BIT_INDEX:
1853 case GDF__8BIT_332RGB:
1854 *dest = ((r >> 5) << 5) |
1858 case GDF_15BIT_555RGB:
1859 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1860 fill_555rgb_pswap(dest, xpos++, r, g, b);
1862 *(unsigned short *) dest =
1863 SWAP16((unsigned short) (
1869 case GDF_16BIT_565RGB:
1870 *(unsigned short *) dest =
1871 SWAP16((unsigned short) (
1876 case GDF_32BIT_X888RGB:
1877 *(unsigned long *) dest =
1878 SWAP32((unsigned long) (
1883 case GDF_24BIT_888RGB:
1884 #ifdef VIDEO_FB_LITTLE_ENDIAN
1896 dest += VIDEO_PIXEL_SIZE;
1900 #ifdef CONFIG_VIDEO_BMP_LOGO
1907 static void *video_logo(void)
1910 __maybe_unused int y_off = 0;
1911 __maybe_unused ulong addr;
1912 __maybe_unused char *s;
1913 __maybe_unused int len, space;
1915 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1917 #ifdef CONFIG_SPLASH_SCREEN
1918 s = getenv("splashimage");
1920 splash_screen_prepare();
1921 addr = simple_strtoul(s, NULL, 16);
1923 if (video_display_bitmap(addr,
1925 video_logo_ypos) == 0) {
1926 video_logo_height = 0;
1927 return ((void *) (video_fb_address));
1930 #endif /* CONFIG_SPLASH_SCREEN */
1932 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1934 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1936 * when using splashpos for video_logo, skip any info
1937 * output on video console if the logo is not at 0,0
1939 if (video_logo_xpos || video_logo_ypos) {
1941 * video_logo_height is used in text and cursor offset
1942 * calculations. Since the console is below the logo,
1943 * we need to adjust the logo height
1945 if (video_logo_ypos == BMP_ALIGN_CENTER)
1946 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1947 VIDEO_LOGO_HEIGHT) / 2);
1948 else if (video_logo_ypos > 0)
1949 video_logo_height += video_logo_ypos;
1951 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1954 if (board_cfb_skip())
1957 sprintf(info, " %s", version_string);
1959 #ifndef CONFIG_HIDE_LOGO_VERSION
1960 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1964 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1965 (uchar *) info, space);
1966 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1967 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1968 (uchar *) info + space, len - space);
1971 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1973 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1976 ((video_logo_height -
1977 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1979 for (i = 1; i < n; i++) {
1980 video_get_info_str(i, info);
1986 video_drawchars(VIDEO_INFO_X,
1990 (uchar *) info, space);
1992 video_drawchars(VIDEO_INFO_X +
1997 (uchar *) info + space,
2000 video_drawstring(VIDEO_INFO_X,
2011 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
2015 static int cfb_fb_is_in_dram(void)
2018 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2019 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2023 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2024 start = bd->bi_dram[i].start;
2025 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2026 if ((ulong)video_fb_address >= start &&
2027 (ulong)video_fb_address < end)
2031 if ((ulong)video_fb_address >= bd->bi_memstart &&
2032 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2038 void video_clear(void)
2040 if (!video_fb_address)
2042 #ifdef VIDEO_HW_RECTFILL
2043 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2046 VIDEO_VISIBLE_COLS, /* frame width */
2047 VIDEO_VISIBLE_ROWS, /* frame height */
2048 bgx /* fill color */
2051 memsetl(video_fb_address,
2052 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2056 static int video_init(void)
2058 unsigned char color8;
2060 pGD = video_hw_init();
2064 video_fb_address = (void *) VIDEO_FB_ADRS;
2065 #ifdef CONFIG_VIDEO_HW_CURSOR
2066 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
2069 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2071 /* Init drawing pats */
2072 switch (VIDEO_DATA_FORMAT) {
2073 case GDF__8BIT_INDEX:
2074 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2075 CONFIG_SYS_CONSOLE_FG_COL,
2076 CONFIG_SYS_CONSOLE_FG_COL);
2077 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2078 CONFIG_SYS_CONSOLE_BG_COL,
2079 CONFIG_SYS_CONSOLE_BG_COL);
2083 case GDF__8BIT_332RGB:
2084 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2085 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2086 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2087 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2089 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2090 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2091 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2092 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2095 case GDF_15BIT_555RGB:
2096 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2097 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2098 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2099 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2100 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2101 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2102 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2103 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2104 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2105 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2106 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2107 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2109 case GDF_16BIT_565RGB:
2110 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2111 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2112 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2113 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2114 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2115 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2116 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2117 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2118 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2119 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2120 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2121 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2123 case GDF_32BIT_X888RGB:
2124 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2125 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2126 CONFIG_SYS_CONSOLE_FG_COL;
2127 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2128 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2129 CONFIG_SYS_CONSOLE_BG_COL;
2131 case GDF_24BIT_888RGB:
2132 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2133 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2134 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2135 CONFIG_SYS_CONSOLE_FG_COL;
2136 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2137 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2138 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2139 CONFIG_SYS_CONSOLE_BG_COL;
2146 #ifdef CONFIG_VIDEO_LOGO
2147 /* Plot the logo and get start point of console */
2148 debug("Video: Drawing the logo ...\n");
2149 video_console_address = video_logo();
2151 video_console_address = video_fb_address;
2154 /* Initialize the console */
2158 if (cfb_do_flush_cache)
2159 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2165 * Implement a weak default function for boards that optionally
2166 * need to skip the video initialization.
2168 __weak int board_video_skip(void)
2170 /* As default, don't skip test */
2174 int drv_video_init(void)
2176 struct stdio_dev console_dev;
2178 bool __maybe_unused keyboard_ok = false;
2180 /* Check if video initialization should be skipped */
2181 if (board_video_skip())
2184 /* Init video chip - returns with framebuffer cleared */
2185 if (video_init() == -1)
2188 if (board_cfb_skip())
2191 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2192 have_keyboard = false;
2193 #elif defined(CONFIG_OF_CONTROL)
2194 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2195 "u-boot,no-keyboard");
2197 have_keyboard = true;
2199 if (have_keyboard) {
2200 debug("KBD: Keyboard init ...\n");
2201 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2202 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2206 /* Init vga device */
2207 memset(&console_dev, 0, sizeof(console_dev));
2208 strcpy(console_dev.name, "vga");
2209 console_dev.flags = DEV_FLAGS_OUTPUT;
2210 console_dev.putc = video_putc; /* 'putc' function */
2211 console_dev.puts = video_puts; /* 'puts' function */
2213 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2214 if (have_keyboard && keyboard_ok) {
2215 /* Also init console device */
2216 console_dev.flags |= DEV_FLAGS_INPUT;
2217 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2218 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2222 if (stdio_register(&console_dev) != 0)
2225 /* Return success */
2229 void video_position_cursor(unsigned col, unsigned row)
2231 console_col = min(col, CONSOLE_COLS - 1);
2232 console_row = min(row, CONSOLE_ROWS - 1);
2235 int video_get_pixel_width(void)
2237 return VIDEO_VISIBLE_COLS;
2240 int video_get_pixel_height(void)
2242 return VIDEO_VISIBLE_ROWS;
2245 int video_get_screen_rows(void)
2247 return CONSOLE_ROWS;
2250 int video_get_screen_columns(void)
2252 return CONSOLE_COLS;