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
67 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
68 * of the graphic chip. Uses the macro
69 * CURSOR_SET. ATTENTION: If booting an
70 * OS, the display driver must disable
71 * the hardware register of the graphic
72 * chip. Otherwise a blinking field is
80 #include <linux/compiler.h>
83 * Defines for the CT69000 driver
85 #ifdef CONFIG_VIDEO_CT69000
87 #define VIDEO_FB_LITTLE_ENDIAN
88 #define VIDEO_HW_RECTFILL
89 #define VIDEO_HW_BITBLT
92 #if defined(CONFIG_VIDEO_MXS)
93 #define VIDEO_FB_16BPP_WORD_SWAP
97 * Defines for the MB862xx driver
99 #ifdef CONFIG_VIDEO_MB862xx
101 #ifdef CONFIG_VIDEO_CORALP
102 #define VIDEO_FB_LITTLE_ENDIAN
104 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
105 #define VIDEO_HW_RECTFILL
106 #define VIDEO_HW_BITBLT
111 * Defines for the i.MX31 driver (mx3fb.c)
113 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
114 #define VIDEO_FB_16BPP_WORD_SWAP
118 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
120 #include <video_fb.h>
127 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
128 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
129 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
130 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
131 #define VIDEO_FB_ADRS (pGD->frameAdrs)
138 #include <linux/types.h>
139 #include <stdio_dev.h>
140 #include <video_font.h>
142 #if defined(CONFIG_CMD_DATE)
146 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
147 #include <watchdog.h>
148 #include <bmp_layout.h>
154 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
155 * blinking is provided. Uses the macros CURSOR_SET
157 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
158 * graphic chip. Uses the macro CURSOR_SET.
159 * ATTENTION: If booting an OS, the display driver
160 * must disable the hardware register of the graphic
161 * chip. Otherwise a blinking field is displayed
163 #if !defined(CONFIG_VIDEO_SW_CURSOR) && !defined(CONFIG_VIDEO_HW_CURSOR)
164 /* no Cursor defined */
170 #if defined(CONFIG_VIDEO_SW_CURSOR)
171 #if defined(CONFIG_VIDEO_HW_CURSOR)
172 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
175 void console_cursor(int state);
177 #define CURSOR_ON console_cursor(1)
178 #define CURSOR_OFF console_cursor(0)
179 #define CURSOR_SET video_set_cursor()
180 #endif /* CONFIG_VIDEO_SW_CURSOR */
182 #ifdef CONFIG_VIDEO_HW_CURSOR
184 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
189 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
190 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
191 #endif /* CONFIG_VIDEO_HW_CURSOR */
193 #ifdef CONFIG_VIDEO_LOGO
194 #ifdef CONFIG_VIDEO_BMP_LOGO
195 #include <bmp_logo.h>
196 #include <bmp_logo_data.h>
197 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
198 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
199 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
200 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
202 #else /* CONFIG_VIDEO_BMP_LOGO */
203 #define LINUX_LOGO_WIDTH 80
204 #define LINUX_LOGO_HEIGHT 80
205 #define LINUX_LOGO_COLORS 214
206 #define LINUX_LOGO_LUT_OFFSET 0x20
208 #include <linux_logo.h>
209 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
210 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
211 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
212 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
213 #endif /* CONFIG_VIDEO_BMP_LOGO */
214 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
215 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
216 #else /* CONFIG_VIDEO_LOGO */
217 #define VIDEO_LOGO_WIDTH 0
218 #define VIDEO_LOGO_HEIGHT 0
219 #endif /* CONFIG_VIDEO_LOGO */
221 #define VIDEO_COLS VIDEO_VISIBLE_COLS
222 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
223 #ifndef VIDEO_LINE_LEN
224 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
226 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
227 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
229 #ifdef CONFIG_VIDEO_LOGO
230 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
232 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
235 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
236 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
237 #define CONSOLE_ROW_FIRST (video_console_address)
238 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
239 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
240 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
242 /* By default we scroll by a single line */
243 #ifndef CONFIG_CONSOLE_SCROLL_LINES
244 #define CONFIG_CONSOLE_SCROLL_LINES 1
248 #ifdef VIDEO_FB_LITTLE_ENDIAN
249 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
252 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
253 (((x) & 0x0000ff00) << 8) | \
254 (((x) & 0x00ff0000) >> 8) | \
255 (((x) & 0xff000000) >> 24) \
257 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
258 (((x) & 0x0000ff00) >> 8) | \
259 (((x) & 0x00ff0000) << 8) | \
260 (((x) & 0xff000000) >> 8) \
263 #define SWAP16(x) (x)
264 #define SWAP32(x) (x)
265 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
266 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
268 #define SHORTSWAP32(x) (x)
272 #ifdef CONFIG_CONSOLE_EXTRA_INFO
274 * setup a board string: type, speed, etc.
276 * line_number: location to place info string beside logo
277 * info: buffer for info string
279 extern void video_get_info_str(int line_number, char *info);
282 DECLARE_GLOBAL_DATA_PTR;
285 static GraphicDevice *pGD; /* Pointer to Graphic array */
287 static void *video_fb_address; /* frame buffer address */
288 static void *video_console_address; /* console buffer start address */
290 static int video_logo_height = VIDEO_LOGO_HEIGHT;
292 static int __maybe_unused cursor_state;
293 static int __maybe_unused old_col;
294 static int __maybe_unused old_row;
296 static int console_col; /* cursor col */
297 static int console_row; /* cursor row */
299 static u32 eorx, fgx, bgx; /* color pats */
301 static int cfb_do_flush_cache;
303 #ifdef CONFIG_CFB_CONSOLE_ANSI
304 static char ansi_buf[10];
305 static int ansi_buf_size;
306 static int ansi_colors_need_revert;
307 static int ansi_cursor_hidden;
310 static const int video_font_draw_table8[] = {
311 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
312 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
313 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
314 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
317 static const int video_font_draw_table15[] = {
318 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
321 static const int video_font_draw_table16[] = {
322 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
325 static const int video_font_draw_table24[16][3] = {
326 {0x00000000, 0x00000000, 0x00000000},
327 {0x00000000, 0x00000000, 0x00ffffff},
328 {0x00000000, 0x0000ffff, 0xff000000},
329 {0x00000000, 0x0000ffff, 0xffffffff},
330 {0x000000ff, 0xffff0000, 0x00000000},
331 {0x000000ff, 0xffff0000, 0x00ffffff},
332 {0x000000ff, 0xffffffff, 0xff000000},
333 {0x000000ff, 0xffffffff, 0xffffffff},
334 {0xffffff00, 0x00000000, 0x00000000},
335 {0xffffff00, 0x00000000, 0x00ffffff},
336 {0xffffff00, 0x0000ffff, 0xff000000},
337 {0xffffff00, 0x0000ffff, 0xffffffff},
338 {0xffffffff, 0xffff0000, 0x00000000},
339 {0xffffffff, 0xffff0000, 0x00ffffff},
340 {0xffffffff, 0xffffffff, 0xff000000},
341 {0xffffffff, 0xffffffff, 0xffffffff}
344 static const int video_font_draw_table32[16][4] = {
345 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
346 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
347 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
348 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
349 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
350 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
351 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
352 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
353 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
354 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
355 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
356 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
357 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
358 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
359 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
360 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
364 * Implement a weak default function for boards that optionally
365 * need to skip the cfb initialization.
367 __weak int board_cfb_skip(void)
369 /* As default, don't skip cfb init */
373 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
375 u8 *cdat, *dest, *dest0;
378 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
379 dest0 = video_fb_address + offset;
381 switch (VIDEO_DATA_FORMAT) {
382 case GDF__8BIT_INDEX:
383 case GDF__8BIT_332RGB:
386 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
387 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
388 rows--; dest += VIDEO_LINE_LEN) {
392 (video_font_draw_table8[bits >> 4] &
395 if (VIDEO_FONT_WIDTH == 4)
399 (video_font_draw_table8[bits & 15] &
402 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
407 case GDF_15BIT_555RGB:
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_table15
417 [bits >> 6] & eorx) ^
420 SHORTSWAP32((video_font_draw_table15
421 [bits >> 4 & 3] & eorx) ^
424 if (VIDEO_FONT_WIDTH == 4)
428 SHORTSWAP32((video_font_draw_table15
429 [bits >> 2 & 3] & eorx) ^
432 SHORTSWAP32((video_font_draw_table15
436 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
441 case GDF_16BIT_565RGB:
444 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
445 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
446 rows--; dest += VIDEO_LINE_LEN) {
450 SHORTSWAP32((video_font_draw_table16
451 [bits >> 6] & eorx) ^
454 SHORTSWAP32((video_font_draw_table16
455 [bits >> 4 & 3] & eorx) ^
458 if (VIDEO_FONT_WIDTH == 4)
462 SHORTSWAP32((video_font_draw_table16
463 [bits >> 2 & 3] & eorx) ^
466 SHORTSWAP32((video_font_draw_table16
470 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
475 case GDF_32BIT_X888RGB:
478 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
479 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
480 rows--; dest += VIDEO_LINE_LEN) {
484 SWAP32((video_font_draw_table32
485 [bits >> 4][0] & eorx) ^ bgx);
487 SWAP32((video_font_draw_table32
488 [bits >> 4][1] & eorx) ^ bgx);
490 SWAP32((video_font_draw_table32
491 [bits >> 4][2] & eorx) ^ bgx);
493 SWAP32((video_font_draw_table32
494 [bits >> 4][3] & eorx) ^ bgx);
497 if (VIDEO_FONT_WIDTH == 4)
501 SWAP32((video_font_draw_table32
502 [bits & 15][0] & eorx) ^ bgx);
504 SWAP32((video_font_draw_table32
505 [bits & 15][1] & eorx) ^ bgx);
507 SWAP32((video_font_draw_table32
508 [bits & 15][2] & eorx) ^ bgx);
510 SWAP32((video_font_draw_table32
511 [bits & 15][3] & eorx) ^ bgx);
513 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
518 case GDF_24BIT_888RGB:
521 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
522 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
523 rows--; dest += VIDEO_LINE_LEN) {
527 (video_font_draw_table24[bits >> 4][0]
530 (video_font_draw_table24[bits >> 4][1]
533 (video_font_draw_table24[bits >> 4][2]
536 if (VIDEO_FONT_WIDTH == 4)
540 (video_font_draw_table24[bits & 15][0]
543 (video_font_draw_table24[bits & 15][1]
546 (video_font_draw_table24[bits & 15][2]
549 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
556 static inline void video_drawstring(int xx, int yy, unsigned char *s)
558 video_drawchars(xx, yy, s, strlen((char *) s));
561 static void video_putchar(int xx, int yy, unsigned char c)
563 video_drawchars(xx, yy + video_logo_height, &c, 1);
566 #if defined(CONFIG_VIDEO_SW_CURSOR)
567 static void video_set_cursor(void)
574 static void video_invertchar(int xx, int yy)
576 int firstx = xx * VIDEO_PIXEL_SIZE;
577 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
578 int firsty = yy * VIDEO_LINE_LEN;
579 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
581 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
582 for (x = firstx; x < lastx; x++) {
583 u8 *dest = (u8 *)(video_fb_address) + x + y;
589 void console_cursor(int state)
591 if (cursor_state != state) {
593 /* turn off the cursor */
594 video_invertchar(old_col * VIDEO_FONT_WIDTH,
595 old_row * VIDEO_FONT_HEIGHT +
598 /* turn off the cursor and record where it is */
599 video_invertchar(console_col * VIDEO_FONT_WIDTH,
600 console_row * VIDEO_FONT_HEIGHT +
602 old_col = console_col;
603 old_row = console_row;
605 cursor_state = state;
607 if (cfb_do_flush_cache)
608 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
612 #ifndef VIDEO_HW_RECTFILL
613 static void memsetl(int *p, int c, int v)
620 #ifndef VIDEO_HW_BITBLT
621 static void memcpyl(int *d, int *s, int c)
628 static void console_clear_line(int line, int begin, int end)
630 #ifdef VIDEO_HW_RECTFILL
631 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
632 VIDEO_FONT_WIDTH * begin, /* dest pos x */
634 VIDEO_FONT_HEIGHT * line, /* dest pos y */
635 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
636 VIDEO_FONT_HEIGHT, /* frame height */
640 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
641 memsetl(CONSOLE_ROW_FIRST +
642 CONSOLE_ROW_SIZE * line, /* offset of row */
643 CONSOLE_ROW_SIZE >> 2, /* length of row */
650 offset = CONSOLE_ROW_FIRST +
651 CONSOLE_ROW_SIZE * line + /* offset of row */
653 VIDEO_PIXEL_SIZE * begin; /* offset of col */
654 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
655 size >>= 2; /* length to end for memsetl() */
656 /* fill at col offset of i'th line using bgx as fill color */
657 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
658 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
663 static void console_scrollup(void)
665 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
668 /* copy up rows ignoring the first one */
670 #ifdef VIDEO_HW_BITBLT
671 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
672 0, /* source pos x */
674 VIDEO_FONT_HEIGHT * rows, /* source pos y */
676 video_logo_height, /* dest pos y */
677 VIDEO_VISIBLE_COLS, /* frame width */
680 - VIDEO_FONT_HEIGHT * rows /* frame height */
683 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
684 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
686 /* clear the last one */
687 for (i = 1; i <= rows; i++)
688 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
690 /* Decrement row number */
694 static void console_back(void)
698 if (console_col < 0) {
699 console_col = CONSOLE_COLS - 1;
706 #ifdef CONFIG_CFB_CONSOLE_ANSI
708 static void console_clear(void)
710 #ifdef VIDEO_HW_RECTFILL
711 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
713 video_logo_height, /* dest pos y */
714 VIDEO_VISIBLE_COLS, /* frame width */
715 VIDEO_VISIBLE_ROWS, /* frame height */
719 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
723 static void console_cursor_fix(void)
727 if (console_row >= CONSOLE_ROWS)
728 console_row = CONSOLE_ROWS - 1;
731 if (console_col >= CONSOLE_COLS)
732 console_col = CONSOLE_COLS - 1;
735 static void console_cursor_up(int n)
738 console_cursor_fix();
741 static void console_cursor_down(int n)
744 console_cursor_fix();
747 static void console_cursor_left(int n)
750 console_cursor_fix();
753 static void console_cursor_right(int n)
756 console_cursor_fix();
759 static void console_cursor_set_position(int row, int col)
761 if (console_row != -1)
763 if (console_col != -1)
765 console_cursor_fix();
768 static void console_previousline(int n)
770 /* FIXME: also scroll terminal ? */
772 console_cursor_fix();
775 static void console_swap_colors(void)
783 static inline int console_cursor_is_visible(void)
785 return !ansi_cursor_hidden;
788 static inline int console_cursor_is_visible(void)
794 static void console_newline(int n)
799 /* Check if we need to scroll the terminal */
800 if (console_row >= CONSOLE_ROWS) {
801 /* Scroll everything up */
806 static void console_cr(void)
811 static void parse_putc(const char c)
815 if (console_cursor_is_visible())
819 case 13: /* back to first column */
823 case '\n': /* next line */
824 if (console_col || (!console_col && nl))
830 console_col |= 0x0008;
831 console_col &= ~0x0007;
833 if (console_col >= CONSOLE_COLS)
837 case 8: /* backspace */
844 default: /* draw the char */
845 video_putchar(console_col * VIDEO_FONT_WIDTH,
846 console_row * VIDEO_FONT_HEIGHT, c);
849 /* check for newline */
850 if (console_col >= CONSOLE_COLS) {
856 if (console_cursor_is_visible())
860 static void video_putc(struct stdio_dev *dev, const char c)
862 #ifdef CONFIG_CFB_CONSOLE_ANSI
866 for (i = 0; i < ansi_buf_size; ++i)
867 parse_putc(ansi_buf[i]);
873 if (ansi_buf_size > 0) {
893 ansi_buf[ansi_buf_size++] = c;
895 if (ansi_buf_size >= sizeof(ansi_buf))
898 for (i = 0; i < ansi_buf_size; ++i) {
904 if (ansi_buf[i] == 27)
911 if (ansi_buf[i] == '[')
918 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
919 num1 = ansi_buf[i]-'0';
921 } else if (ansi_buf[i] != '?') {
929 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
931 num1 += ansi_buf[i]-'0';
939 if (ansi_buf[i] != ';') {
947 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
948 num2 = ansi_buf[i]-'0';
955 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
957 num2 += ansi_buf[i]-'0';
965 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
966 || ansi_buf[i] == 'J'
967 || ansi_buf[i] == 'K'
968 || ansi_buf[i] == 'h'
969 || ansi_buf[i] == 'l'
970 || ansi_buf[i] == 'm') {
980 for (i = 0; i < ansi_buf_size; ++i)
981 parse_putc(ansi_buf[i]);
987 if (!ansi_cursor_hidden)
992 /* move cursor num1 rows up */
993 console_cursor_up(num1);
996 /* move cursor num1 rows down */
997 console_cursor_down(num1);
1000 /* move cursor num1 columns forward */
1001 console_cursor_right(num1);
1004 /* move cursor num1 columns back */
1005 console_cursor_left(num1);
1008 /* move cursor num1 rows up at begin of row */
1009 console_previousline(num1);
1012 /* move cursor num1 rows down at begin of row */
1013 console_newline(num1);
1016 /* move cursor to column num1 */
1017 console_cursor_set_position(-1, num1-1);
1020 /* move cursor to row num1, column num2 */
1021 console_cursor_set_position(num1-1, num2-1);
1024 /* clear console and move cursor to 0, 0 */
1026 console_cursor_set_position(0, 0);
1031 console_clear_line(console_row,
1035 console_clear_line(console_row,
1038 console_clear_line(console_row,
1042 ansi_cursor_hidden = 0;
1045 ansi_cursor_hidden = 1;
1048 if (num1 == 0) { /* reset swapped colors */
1049 if (ansi_colors_need_revert) {
1050 console_swap_colors();
1051 ansi_colors_need_revert = 0;
1053 } else if (num1 == 7) { /* once swap colors */
1054 if (!ansi_colors_need_revert) {
1055 console_swap_colors();
1056 ansi_colors_need_revert = 1;
1061 if (!ansi_cursor_hidden)
1070 if (cfb_do_flush_cache)
1071 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1074 static void video_puts(struct stdio_dev *dev, const char *s)
1076 int flush = cfb_do_flush_cache;
1077 int count = strlen(s);
1079 /* temporarily disable cache flush */
1080 cfb_do_flush_cache = 0;
1083 video_putc(dev, *s++);
1086 cfb_do_flush_cache = flush;
1087 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1092 * Do not enforce drivers (or board code) to provide empty
1093 * video_set_lut() if they do not support 8 bpp format.
1094 * Implement weak default function instead.
1096 __weak void video_set_lut(unsigned int index, unsigned char r,
1097 unsigned char g, unsigned char b)
1101 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1103 #define FILL_8BIT_332RGB(r,g,b) { \
1104 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1108 #define FILL_15BIT_555RGB(r,g,b) { \
1109 *(unsigned short *)fb = \
1110 SWAP16((unsigned short)(((r>>3)<<10) | \
1116 #define FILL_16BIT_565RGB(r,g,b) { \
1117 *(unsigned short *)fb = \
1118 SWAP16((unsigned short)((((r)>>3)<<11)| \
1124 #define FILL_32BIT_X888RGB(r,g,b) { \
1125 *(unsigned long *)fb = \
1126 SWAP32((unsigned long)(((r<<16) | \
1132 #ifdef VIDEO_FB_LITTLE_ENDIAN
1133 #define FILL_24BIT_888RGB(r,g,b) { \
1140 #define FILL_24BIT_888RGB(r,g,b) { \
1148 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1149 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1151 ushort *dst = (ushort *) fb;
1152 ushort color = (ushort) (((r >> 3) << 10) |
1163 * RLE8 bitmap support
1166 #ifdef CONFIG_VIDEO_BMP_RLE8
1167 /* Pre-calculated color table entry */
1170 unsigned short w; /* word */
1171 unsigned int dw; /* double word */
1172 } ce; /* color entry */
1176 * Helper to draw encoded/unencoded run.
1178 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1181 ulong addr = (ulong) *fb;
1187 * Setup offset of the color index in the bitmap.
1188 * Color index of encoded run is at offset 1.
1190 off = enc ? &enc_off : &i;
1192 switch (VIDEO_DATA_FORMAT) {
1193 case GDF__8BIT_INDEX:
1194 for (i = 0; i < cnt; i++)
1195 *(unsigned char *) addr++ = bm[*off];
1197 case GDF_15BIT_555RGB:
1198 case GDF_16BIT_565RGB:
1199 /* differences handled while pre-calculating palette */
1200 for (i = 0; i < cnt; i++) {
1201 *(unsigned short *) addr = p[bm[*off]].ce.w;
1205 case GDF_32BIT_X888RGB:
1206 for (i = 0; i < cnt; i++) {
1207 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1212 *fb = (uchar *) addr; /* return modified address */
1215 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1216 int width, int height)
1220 unsigned int cnt, runlen;
1222 int x, y, bpp, i, ncolors;
1223 struct palette p[256];
1224 struct bmp_color_table_entry cte;
1225 int green_shift, red_off;
1226 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1230 y = __le32_to_cpu(img->header.height) - 1;
1231 ncolors = __le32_to_cpu(img->header.colors_used);
1232 bpp = VIDEO_PIXEL_SIZE;
1233 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1234 (y + yoff) * VIDEO_LINE_LEN +
1237 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1239 /* pre-calculate and setup palette */
1240 switch (VIDEO_DATA_FORMAT) {
1241 case GDF__8BIT_INDEX:
1242 for (i = 0; i < ncolors; i++) {
1243 cte = img->color_table[i];
1244 video_set_lut(i, cte.red, cte.green, cte.blue);
1247 case GDF_15BIT_555RGB:
1248 case GDF_16BIT_565RGB:
1249 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1256 for (i = 0; i < ncolors; i++) {
1257 cte = img->color_table[i];
1258 p[i].ce.w = SWAP16((unsigned short)
1259 (((cte.red >> 3) << red_off) |
1260 ((cte.green >> green_shift) << 5) |
1264 case GDF_32BIT_X888RGB:
1265 for (i = 0; i < ncolors; i++) {
1266 cte = img->color_table[i];
1267 p[i].ce.dw = SWAP32((cte.red << 16) |
1273 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1283 /* scan line end marker */
1287 fbp = (unsigned char *)
1288 ((unsigned int) video_fb_address +
1289 (y + yoff) * VIDEO_LINE_LEN +
1293 /* end of bitmap data marker */
1297 /* run offset marker */
1300 fbp = (unsigned char *)
1301 ((unsigned int) video_fb_address +
1302 (y + yoff) * VIDEO_LINE_LEN +
1320 if (x + runlen > width)
1322 draw_bitmap(&fbp, bm, p, cnt, 0);
1328 bm++; /* 0 padding if length is odd */
1339 if (y < height) { /* only draw into visible area */
1345 if (x + runlen > width)
1347 draw_bitmap(&fbp, bm, p, cnt, 1);
1356 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1362 * Display the BMP file located at address bmp_image.
1364 int video_display_bitmap(ulong bmp_image, int x, int y)
1366 ushort xcount, ycount;
1368 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1371 unsigned long width, height, bpp;
1373 unsigned long compression;
1374 struct bmp_color_table_entry cte;
1376 #ifdef CONFIG_VIDEO_BMP_GZIP
1377 unsigned char *dst = NULL;
1383 if (!((bmp->header.signature[0] == 'B') &&
1384 (bmp->header.signature[1] == 'M'))) {
1386 #ifdef CONFIG_VIDEO_BMP_GZIP
1388 * Could be a gzipped bmp image, try to decrompress...
1390 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1391 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1393 printf("Error: malloc in gunzip failed!\n");
1397 * NB: we need to force offset of +2
1398 * See doc/README.displaying-bmps
1400 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1401 (uchar *) bmp_image,
1403 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1408 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1409 printf("Image could be truncated "
1410 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1414 * Set addr to decompressed image
1416 bmp = (struct bmp_image *)(dst+2);
1418 if (!((bmp->header.signature[0] == 'B') &&
1419 (bmp->header.signature[1] == 'M'))) {
1420 printf("Error: no valid bmp.gz image at %lx\n",
1426 printf("Error: no valid bmp image at %lx\n", bmp_image);
1428 #endif /* CONFIG_VIDEO_BMP_GZIP */
1431 width = le32_to_cpu(bmp->header.width);
1432 height = le32_to_cpu(bmp->header.height);
1433 bpp = le16_to_cpu(bmp->header.bit_count);
1434 colors = le32_to_cpu(bmp->header.colors_used);
1435 compression = le32_to_cpu(bmp->header.compression);
1437 debug("Display-bmp: %ld x %ld with %d colors\n",
1438 width, height, colors);
1440 if (compression != BMP_BI_RGB
1441 #ifdef CONFIG_VIDEO_BMP_RLE8
1442 && compression != BMP_BI_RLE8
1445 printf("Error: compression type %ld not supported\n",
1447 #ifdef CONFIG_VIDEO_BMP_GZIP
1454 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1456 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1457 if (x == BMP_ALIGN_CENTER)
1458 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1460 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1462 if (y == BMP_ALIGN_CENTER)
1463 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1465 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1466 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1469 * Just ignore elements which are completely beyond screen
1472 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1475 if ((x + width) > VIDEO_VISIBLE_COLS)
1476 width = VIDEO_VISIBLE_COLS - x;
1477 if ((y + height) > VIDEO_VISIBLE_ROWS)
1478 height = VIDEO_VISIBLE_ROWS - y;
1480 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1481 fb = (uchar *) (video_fb_address +
1482 ((y + height - 1) * VIDEO_LINE_LEN) +
1483 x * VIDEO_PIXEL_SIZE);
1485 #ifdef CONFIG_VIDEO_BMP_RLE8
1486 if (compression == BMP_BI_RLE8) {
1487 return display_rle8_bitmap(bmp, x, y, width, height);
1491 /* We handle only 4, 8, or 24 bpp bitmaps */
1492 switch (le16_to_cpu(bmp->header.bit_count)) {
1494 padded_line -= width / 2;
1497 switch (VIDEO_DATA_FORMAT) {
1498 case GDF_32BIT_X888RGB:
1502 * Don't assume that 'width' is an
1505 for (xcount = 0; xcount < width; xcount++) {
1513 cte = bmp->color_table[idx];
1514 FILL_32BIT_X888RGB(cte.red, cte.green,
1517 bmap += padded_line;
1518 fb -= VIDEO_LINE_LEN + width *
1523 puts("4bpp bitmap unsupported with current "
1530 padded_line -= width;
1531 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1533 for (xcount = 0; xcount < colors; ++xcount) {
1534 cte = bmp->color_table[xcount];
1535 video_set_lut(xcount, cte.red, cte.green,
1540 switch (VIDEO_DATA_FORMAT) {
1541 case GDF__8BIT_INDEX:
1548 bmap += padded_line;
1549 fb -= VIDEO_LINE_LEN + width *
1553 case GDF__8BIT_332RGB:
1558 cte = bmp->color_table[*bmap++];
1559 FILL_8BIT_332RGB(cte.red, cte.green,
1562 bmap += padded_line;
1563 fb -= VIDEO_LINE_LEN + width *
1567 case GDF_15BIT_555RGB:
1569 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1575 cte = bmp->color_table[*bmap++];
1576 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1577 fill_555rgb_pswap(fb, xpos++, cte.red,
1582 FILL_15BIT_555RGB(cte.red, cte.green,
1586 bmap += padded_line;
1587 fb -= VIDEO_LINE_LEN + width *
1591 case GDF_16BIT_565RGB:
1596 cte = bmp->color_table[*bmap++];
1597 FILL_16BIT_565RGB(cte.red, cte.green,
1600 bmap += padded_line;
1601 fb -= VIDEO_LINE_LEN + width *
1605 case GDF_32BIT_X888RGB:
1610 cte = bmp->color_table[*bmap++];
1611 FILL_32BIT_X888RGB(cte.red, cte.green,
1614 bmap += padded_line;
1615 fb -= VIDEO_LINE_LEN + width *
1619 case GDF_24BIT_888RGB:
1624 cte = bmp->color_table[*bmap++];
1625 FILL_24BIT_888RGB(cte.red, cte.green,
1628 bmap += padded_line;
1629 fb -= VIDEO_LINE_LEN + width *
1636 padded_line -= 3 * width;
1638 switch (VIDEO_DATA_FORMAT) {
1639 case GDF__8BIT_332RGB:
1644 FILL_8BIT_332RGB(bmap[2], bmap[1],
1648 bmap += padded_line;
1649 fb -= VIDEO_LINE_LEN + width *
1653 case GDF_15BIT_555RGB:
1655 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1661 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1662 fill_555rgb_pswap(fb, xpos++, bmap[2],
1666 FILL_15BIT_555RGB(bmap[2], bmap[1],
1671 bmap += padded_line;
1672 fb -= VIDEO_LINE_LEN + width *
1676 case GDF_16BIT_565RGB:
1681 FILL_16BIT_565RGB(bmap[2], bmap[1],
1685 bmap += padded_line;
1686 fb -= VIDEO_LINE_LEN + width *
1690 case GDF_32BIT_X888RGB:
1695 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1699 bmap += padded_line;
1700 fb -= VIDEO_LINE_LEN + width *
1704 case GDF_24BIT_888RGB:
1709 FILL_24BIT_888RGB(bmap[2], bmap[1],
1713 bmap += padded_line;
1714 fb -= VIDEO_LINE_LEN + width *
1719 printf("Error: 24 bits/pixel bitmap incompatible "
1720 "with current video mode\n");
1725 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1726 le16_to_cpu(bmp->header.bit_count));
1730 #ifdef CONFIG_VIDEO_BMP_GZIP
1736 if (cfb_do_flush_cache)
1737 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1743 #ifdef CONFIG_VIDEO_LOGO
1744 static int video_logo_xpos;
1745 static int video_logo_ypos;
1747 static void plot_logo_or_black(void *screen, int x, int y, int black);
1749 static void logo_plot(void *screen, int x, int y)
1751 plot_logo_or_black(screen, x, y, 0);
1754 static void logo_black(void)
1756 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1760 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1763 return cmd_usage(cmdtp);
1770 clrlogo, 1, 0, do_clrlogo,
1771 "fill the boot logo area with black",
1775 static void plot_logo_or_black(void *screen, int x, int y, int black)
1779 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1780 int ycount = video_logo_height;
1781 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1782 unsigned char *source;
1783 unsigned char *dest;
1785 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1786 if (x == BMP_ALIGN_CENTER)
1787 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1789 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1791 if (y == BMP_ALIGN_CENTER)
1792 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1794 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1795 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1797 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1799 #ifdef CONFIG_VIDEO_BMP_LOGO
1800 source = bmp_logo_bitmap;
1802 /* Allocate temporary space for computing colormap */
1803 logo_red = malloc(BMP_LOGO_COLORS);
1804 logo_green = malloc(BMP_LOGO_COLORS);
1805 logo_blue = malloc(BMP_LOGO_COLORS);
1806 /* Compute color map */
1807 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1808 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1809 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1810 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1813 source = linux_logo;
1814 logo_red = linux_logo_red;
1815 logo_green = linux_logo_green;
1816 logo_blue = linux_logo_blue;
1819 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1820 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1821 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1822 logo_red[i], logo_green[i],
1828 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1831 xcount = VIDEO_LOGO_WIDTH;
1838 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1839 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1840 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1843 switch (VIDEO_DATA_FORMAT) {
1844 case GDF__8BIT_INDEX:
1847 case GDF__8BIT_332RGB:
1848 *dest = ((r >> 5) << 5) |
1852 case GDF_15BIT_555RGB:
1853 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1854 fill_555rgb_pswap(dest, xpos++, r, g, b);
1856 *(unsigned short *) dest =
1857 SWAP16((unsigned short) (
1863 case GDF_16BIT_565RGB:
1864 *(unsigned short *) dest =
1865 SWAP16((unsigned short) (
1870 case GDF_32BIT_X888RGB:
1871 *(unsigned long *) dest =
1872 SWAP32((unsigned long) (
1877 case GDF_24BIT_888RGB:
1878 #ifdef VIDEO_FB_LITTLE_ENDIAN
1890 dest += VIDEO_PIXEL_SIZE;
1894 #ifdef CONFIG_VIDEO_BMP_LOGO
1901 static void *video_logo(void)
1904 __maybe_unused int y_off = 0;
1905 __maybe_unused ulong addr;
1906 __maybe_unused char *s;
1907 __maybe_unused int len, space;
1909 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1911 #ifdef CONFIG_SPLASH_SCREEN
1912 s = getenv("splashimage");
1914 splash_screen_prepare();
1915 addr = simple_strtoul(s, NULL, 16);
1917 if (video_display_bitmap(addr,
1919 video_logo_ypos) == 0) {
1920 video_logo_height = 0;
1921 return ((void *) (video_fb_address));
1924 #endif /* CONFIG_SPLASH_SCREEN */
1926 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1928 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1930 * when using splashpos for video_logo, skip any info
1931 * output on video console if the logo is not at 0,0
1933 if (video_logo_xpos || video_logo_ypos) {
1935 * video_logo_height is used in text and cursor offset
1936 * calculations. Since the console is below the logo,
1937 * we need to adjust the logo height
1939 if (video_logo_ypos == BMP_ALIGN_CENTER)
1940 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1941 VIDEO_LOGO_HEIGHT) / 2);
1942 else if (video_logo_ypos > 0)
1943 video_logo_height += video_logo_ypos;
1945 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1948 if (board_cfb_skip())
1951 sprintf(info, " %s", version_string);
1953 #ifndef CONFIG_HIDE_LOGO_VERSION
1954 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1958 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1959 (uchar *) info, space);
1960 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1961 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1962 (uchar *) info + space, len - space);
1965 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1967 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1970 ((video_logo_height -
1971 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1973 for (i = 1; i < n; i++) {
1974 video_get_info_str(i, info);
1980 video_drawchars(VIDEO_INFO_X,
1984 (uchar *) info, space);
1986 video_drawchars(VIDEO_INFO_X +
1991 (uchar *) info + space,
1994 video_drawstring(VIDEO_INFO_X,
2005 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
2009 static int cfb_fb_is_in_dram(void)
2012 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2013 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2017 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2018 start = bd->bi_dram[i].start;
2019 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2020 if ((ulong)video_fb_address >= start &&
2021 (ulong)video_fb_address < end)
2025 if ((ulong)video_fb_address >= bd->bi_memstart &&
2026 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2032 void video_clear(void)
2034 if (!video_fb_address)
2036 #ifdef VIDEO_HW_RECTFILL
2037 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2040 VIDEO_VISIBLE_COLS, /* frame width */
2041 VIDEO_VISIBLE_ROWS, /* frame height */
2042 bgx /* fill color */
2045 memsetl(video_fb_address,
2046 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2050 static int video_init(void)
2052 unsigned char color8;
2054 pGD = video_hw_init();
2058 video_fb_address = (void *) VIDEO_FB_ADRS;
2059 #ifdef CONFIG_VIDEO_HW_CURSOR
2060 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
2063 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2065 /* Init drawing pats */
2066 switch (VIDEO_DATA_FORMAT) {
2067 case GDF__8BIT_INDEX:
2068 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2069 CONFIG_SYS_CONSOLE_FG_COL,
2070 CONFIG_SYS_CONSOLE_FG_COL);
2071 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2072 CONFIG_SYS_CONSOLE_BG_COL,
2073 CONFIG_SYS_CONSOLE_BG_COL);
2077 case GDF__8BIT_332RGB:
2078 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2079 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2080 CONFIG_SYS_CONSOLE_FG_COL >> 6);
2081 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2083 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2084 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2085 CONFIG_SYS_CONSOLE_BG_COL >> 6);
2086 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2089 case GDF_15BIT_555RGB:
2090 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2091 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2092 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2093 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2094 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2095 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2096 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2097 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2098 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2099 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2100 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2101 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2103 case GDF_16BIT_565RGB:
2104 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2105 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2106 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2107 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2108 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2109 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2110 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2111 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2112 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2113 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2114 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2115 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
2117 case GDF_32BIT_X888RGB:
2118 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2119 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2120 CONFIG_SYS_CONSOLE_FG_COL;
2121 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2122 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2123 CONFIG_SYS_CONSOLE_BG_COL;
2125 case GDF_24BIT_888RGB:
2126 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2127 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2128 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2129 CONFIG_SYS_CONSOLE_FG_COL;
2130 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2131 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2132 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2133 CONFIG_SYS_CONSOLE_BG_COL;
2140 #ifdef CONFIG_VIDEO_LOGO
2141 /* Plot the logo and get start point of console */
2142 debug("Video: Drawing the logo ...\n");
2143 video_console_address = video_logo();
2145 video_console_address = video_fb_address;
2148 /* Initialize the console */
2152 if (cfb_do_flush_cache)
2153 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2159 * Implement a weak default function for boards that optionally
2160 * need to skip the video initialization.
2162 __weak int board_video_skip(void)
2164 /* As default, don't skip test */
2168 int drv_video_init(void)
2170 struct stdio_dev console_dev;
2172 bool __maybe_unused keyboard_ok = false;
2174 /* Check if video initialization should be skipped */
2175 if (board_video_skip())
2178 /* Init video chip - returns with framebuffer cleared */
2179 if (video_init() == -1)
2182 if (board_cfb_skip())
2185 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2186 have_keyboard = false;
2187 #elif defined(CONFIG_OF_CONTROL)
2188 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2189 "u-boot,no-keyboard");
2191 have_keyboard = true;
2193 if (have_keyboard) {
2194 debug("KBD: Keyboard init ...\n");
2195 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2196 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2200 /* Init vga device */
2201 memset(&console_dev, 0, sizeof(console_dev));
2202 strcpy(console_dev.name, "vga");
2203 console_dev.flags = DEV_FLAGS_OUTPUT;
2204 console_dev.putc = video_putc; /* 'putc' function */
2205 console_dev.puts = video_puts; /* 'puts' function */
2207 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2208 if (have_keyboard && keyboard_ok) {
2209 /* Also init console device */
2210 console_dev.flags |= DEV_FLAGS_INPUT;
2211 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2212 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2216 if (stdio_register(&console_dev) != 0)
2219 /* Return success */
2223 void video_position_cursor(unsigned col, unsigned row)
2225 console_col = min(col, CONSOLE_COLS - 1);
2226 console_row = min(row, CONSOLE_ROWS - 1);
2229 int video_get_pixel_width(void)
2231 return VIDEO_VISIBLE_COLS;
2234 int video_get_pixel_height(void)
2236 return VIDEO_VISIBLE_ROWS;
2239 int video_get_screen_rows(void)
2241 return CONSOLE_ROWS;
2244 int video_get_screen_columns(void)
2246 return CONSOLE_COLS;