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 the standard PC keyboard interface (i8042)
19 * for character input. Character output goes to a memory mapped video
20 * framebuffer with little or big-endian organisation.
21 * With environment setting 'console=serial' the console i/o can be
22 * forced to serial port.
24 * The driver uses graphic specific defines/parameters/functions:
26 * (for SMI LynxE graphic chip)
28 * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
29 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
30 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
31 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
33 * Console Parameters are set by graphic drivers global struct:
35 * VIDEO_VISIBLE_COLS - x resolution
36 * VIDEO_VISIBLE_ROWS - y resolution
37 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
38 * VIDEO_DATA_FORMAT - graphical data format GDF
39 * VIDEO_FB_ADRS - start of video memory
41 * CONFIG_I8042_KBD - AT Keyboard driver for i8042
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 * Console device defines with SMI graphic
90 * Any other graphic must change this section
93 #ifdef CONFIG_VIDEO_SMI_LYNXEM
95 #define VIDEO_FB_LITTLE_ENDIAN
96 #define VIDEO_HW_RECTFILL
97 #define VIDEO_HW_BITBLT
101 * Defines for the CT69000 driver
103 #ifdef CONFIG_VIDEO_CT69000
105 #define VIDEO_FB_LITTLE_ENDIAN
106 #define VIDEO_HW_RECTFILL
107 #define VIDEO_HW_BITBLT
111 * Defines for the SED13806 driver
113 #ifdef CONFIG_VIDEO_SED13806
114 #define VIDEO_FB_LITTLE_ENDIAN
115 #define VIDEO_HW_RECTFILL
116 #define VIDEO_HW_BITBLT
119 #ifdef CONFIG_VIDEO_MXS
120 #define VIDEO_FB_16BPP_WORD_SWAP
124 * Defines for the MB862xx driver
126 #ifdef CONFIG_VIDEO_MB862xx
128 #ifdef CONFIG_VIDEO_CORALP
129 #define VIDEO_FB_LITTLE_ENDIAN
131 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
132 #define VIDEO_HW_RECTFILL
133 #define VIDEO_HW_BITBLT
138 * Defines for the i.MX31 driver (mx3fb.c)
140 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
141 #define VIDEO_FB_16BPP_WORD_SWAP
145 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
147 #include <video_fb.h>
154 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
155 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
156 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
157 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
158 #define VIDEO_FB_ADRS (pGD->frameAdrs)
161 * Console device defines with i8042 keyboard controller
162 * Any other keyboard controller must change this section
165 #ifdef CONFIG_I8042_KBD
168 #define VIDEO_KBD_INIT_FCT i8042_kbd_init()
169 #define VIDEO_TSTC_FCT i8042_tstc
170 #define VIDEO_GETC_FCT i8042_getc
178 #include <linux/types.h>
179 #include <stdio_dev.h>
180 #include <video_font.h>
182 #if defined(CONFIG_CMD_DATE)
186 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
187 #include <watchdog.h>
188 #include <bmp_layout.h>
194 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
195 * blinking is provided. Uses the macros CURSOR_SET
197 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
198 * graphic chip. Uses the macro CURSOR_SET.
199 * ATTENTION: If booting an OS, the display driver
200 * must disable the hardware register of the graphic
201 * chip. Otherwise a blinking field is displayed
203 #if !defined(CONFIG_VIDEO_SW_CURSOR) && !defined(CONFIG_VIDEO_HW_CURSOR)
204 /* no Cursor defined */
210 #if defined(CONFIG_VIDEO_SW_CURSOR)
211 #if defined(CONFIG_VIDEO_HW_CURSOR)
212 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
215 void console_cursor(int state);
217 #define CURSOR_ON console_cursor(1)
218 #define CURSOR_OFF console_cursor(0)
219 #define CURSOR_SET video_set_cursor()
220 #endif /* CONFIG_VIDEO_SW_CURSOR */
222 #ifdef CONFIG_VIDEO_HW_CURSOR
224 #error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
229 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
230 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
231 #endif /* CONFIG_VIDEO_HW_CURSOR */
233 #ifdef CONFIG_VIDEO_LOGO
234 #ifdef CONFIG_VIDEO_BMP_LOGO
235 #include <bmp_logo.h>
236 #include <bmp_logo_data.h>
237 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
238 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
239 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
240 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
242 #else /* CONFIG_VIDEO_BMP_LOGO */
243 #define LINUX_LOGO_WIDTH 80
244 #define LINUX_LOGO_HEIGHT 80
245 #define LINUX_LOGO_COLORS 214
246 #define LINUX_LOGO_LUT_OFFSET 0x20
248 #include <linux_logo.h>
249 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
250 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
251 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
252 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
253 #endif /* CONFIG_VIDEO_BMP_LOGO */
254 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
255 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
256 #else /* CONFIG_VIDEO_LOGO */
257 #define VIDEO_LOGO_WIDTH 0
258 #define VIDEO_LOGO_HEIGHT 0
259 #endif /* CONFIG_VIDEO_LOGO */
261 #define VIDEO_COLS VIDEO_VISIBLE_COLS
262 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
263 #ifndef VIDEO_LINE_LEN
264 #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
266 #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
267 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
269 #ifdef CONFIG_VIDEO_LOGO
270 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
272 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
275 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
276 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
277 #define CONSOLE_ROW_FIRST (video_console_address)
278 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
279 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
280 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
282 /* By default we scroll by a single line */
283 #ifndef CONFIG_CONSOLE_SCROLL_LINES
284 #define CONFIG_CONSOLE_SCROLL_LINES 1
288 #ifdef VIDEO_FB_LITTLE_ENDIAN
289 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
292 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
293 (((x) & 0x0000ff00) << 8) | \
294 (((x) & 0x00ff0000) >> 8) | \
295 (((x) & 0xff000000) >> 24) \
297 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
298 (((x) & 0x0000ff00) >> 8) | \
299 (((x) & 0x00ff0000) << 8) | \
300 (((x) & 0xff000000) >> 8) \
303 #define SWAP16(x) (x)
304 #define SWAP32(x) (x)
305 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
306 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
308 #define SHORTSWAP32(x) (x)
312 #ifdef CONFIG_CONSOLE_EXTRA_INFO
314 * setup a board string: type, speed, etc.
316 * line_number: location to place info string beside logo
317 * info: buffer for info string
319 extern void video_get_info_str(int line_number, char *info);
322 DECLARE_GLOBAL_DATA_PTR;
325 static GraphicDevice *pGD; /* Pointer to Graphic array */
327 static void *video_fb_address; /* frame buffer address */
328 static void *video_console_address; /* console buffer start address */
330 static int video_logo_height = VIDEO_LOGO_HEIGHT;
332 static int __maybe_unused cursor_state;
333 static int __maybe_unused old_col;
334 static int __maybe_unused old_row;
336 static int console_col; /* cursor col */
337 static int console_row; /* cursor row */
339 static u32 eorx, fgx, bgx; /* color pats */
341 static int cfb_do_flush_cache;
343 #ifdef CONFIG_CFB_CONSOLE_ANSI
344 static char ansi_buf[10];
345 static int ansi_buf_size;
346 static int ansi_colors_need_revert;
347 static int ansi_cursor_hidden;
350 static const int video_font_draw_table8[] = {
351 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
352 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
353 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
354 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
357 static const int video_font_draw_table15[] = {
358 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
361 static const int video_font_draw_table16[] = {
362 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
365 static const int video_font_draw_table24[16][3] = {
366 {0x00000000, 0x00000000, 0x00000000},
367 {0x00000000, 0x00000000, 0x00ffffff},
368 {0x00000000, 0x0000ffff, 0xff000000},
369 {0x00000000, 0x0000ffff, 0xffffffff},
370 {0x000000ff, 0xffff0000, 0x00000000},
371 {0x000000ff, 0xffff0000, 0x00ffffff},
372 {0x000000ff, 0xffffffff, 0xff000000},
373 {0x000000ff, 0xffffffff, 0xffffffff},
374 {0xffffff00, 0x00000000, 0x00000000},
375 {0xffffff00, 0x00000000, 0x00ffffff},
376 {0xffffff00, 0x0000ffff, 0xff000000},
377 {0xffffff00, 0x0000ffff, 0xffffffff},
378 {0xffffffff, 0xffff0000, 0x00000000},
379 {0xffffffff, 0xffff0000, 0x00ffffff},
380 {0xffffffff, 0xffffffff, 0xff000000},
381 {0xffffffff, 0xffffffff, 0xffffffff}
384 static const int video_font_draw_table32[16][4] = {
385 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
386 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
387 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
388 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
389 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
390 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
391 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
392 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
393 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
394 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
395 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
396 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
397 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
398 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
399 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
400 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
404 * Implement a weak default function for boards that optionally
405 * need to skip the cfb initialization.
407 __weak int board_cfb_skip(void)
409 /* As default, don't skip cfb init */
413 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
415 u8 *cdat, *dest, *dest0;
418 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
419 dest0 = video_fb_address + offset;
421 switch (VIDEO_DATA_FORMAT) {
422 case GDF__8BIT_INDEX:
423 case GDF__8BIT_332RGB:
426 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
427 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
428 rows--; dest += VIDEO_LINE_LEN) {
432 (video_font_draw_table8[bits >> 4] &
435 if (VIDEO_FONT_WIDTH == 4)
439 (video_font_draw_table8[bits & 15] &
442 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
447 case GDF_15BIT_555RGB:
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_table15
457 [bits >> 6] & eorx) ^
460 SHORTSWAP32((video_font_draw_table15
461 [bits >> 4 & 3] & eorx) ^
464 if (VIDEO_FONT_WIDTH == 4)
468 SHORTSWAP32((video_font_draw_table15
469 [bits >> 2 & 3] & eorx) ^
472 SHORTSWAP32((video_font_draw_table15
476 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
481 case GDF_16BIT_565RGB:
484 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
485 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
486 rows--; dest += VIDEO_LINE_LEN) {
490 SHORTSWAP32((video_font_draw_table16
491 [bits >> 6] & eorx) ^
494 SHORTSWAP32((video_font_draw_table16
495 [bits >> 4 & 3] & eorx) ^
498 if (VIDEO_FONT_WIDTH == 4)
502 SHORTSWAP32((video_font_draw_table16
503 [bits >> 2 & 3] & eorx) ^
506 SHORTSWAP32((video_font_draw_table16
510 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
515 case GDF_32BIT_X888RGB:
518 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
519 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
520 rows--; dest += VIDEO_LINE_LEN) {
524 SWAP32((video_font_draw_table32
525 [bits >> 4][0] & eorx) ^ bgx);
527 SWAP32((video_font_draw_table32
528 [bits >> 4][1] & eorx) ^ bgx);
530 SWAP32((video_font_draw_table32
531 [bits >> 4][2] & eorx) ^ bgx);
533 SWAP32((video_font_draw_table32
534 [bits >> 4][3] & eorx) ^ bgx);
537 if (VIDEO_FONT_WIDTH == 4)
541 SWAP32((video_font_draw_table32
542 [bits & 15][0] & eorx) ^ bgx);
544 SWAP32((video_font_draw_table32
545 [bits & 15][1] & eorx) ^ bgx);
547 SWAP32((video_font_draw_table32
548 [bits & 15][2] & eorx) ^ bgx);
550 SWAP32((video_font_draw_table32
551 [bits & 15][3] & eorx) ^ bgx);
553 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
558 case GDF_24BIT_888RGB:
561 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
562 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
563 rows--; dest += VIDEO_LINE_LEN) {
567 (video_font_draw_table24[bits >> 4][0]
570 (video_font_draw_table24[bits >> 4][1]
573 (video_font_draw_table24[bits >> 4][2]
576 if (VIDEO_FONT_WIDTH == 4)
580 (video_font_draw_table24[bits & 15][0]
583 (video_font_draw_table24[bits & 15][1]
586 (video_font_draw_table24[bits & 15][2]
589 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
596 static inline void video_drawstring(int xx, int yy, unsigned char *s)
598 video_drawchars(xx, yy, s, strlen((char *) s));
601 static void video_putchar(int xx, int yy, unsigned char c)
603 video_drawchars(xx, yy + video_logo_height, &c, 1);
606 #if defined(CONFIG_VIDEO_SW_CURSOR)
607 static void video_set_cursor(void)
614 static void video_invertchar(int xx, int yy)
616 int firstx = xx * VIDEO_PIXEL_SIZE;
617 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
618 int firsty = yy * VIDEO_LINE_LEN;
619 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
621 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
622 for (x = firstx; x < lastx; x++) {
623 u8 *dest = (u8 *)(video_fb_address) + x + y;
629 void console_cursor(int state)
631 if (cursor_state != state) {
633 /* turn off the cursor */
634 video_invertchar(old_col * VIDEO_FONT_WIDTH,
635 old_row * VIDEO_FONT_HEIGHT +
638 /* turn off the cursor and record where it is */
639 video_invertchar(console_col * VIDEO_FONT_WIDTH,
640 console_row * VIDEO_FONT_HEIGHT +
642 old_col = console_col;
643 old_row = console_row;
645 cursor_state = state;
647 if (cfb_do_flush_cache)
648 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
652 #ifndef VIDEO_HW_RECTFILL
653 static void memsetl(int *p, int c, int v)
660 #ifndef VIDEO_HW_BITBLT
661 static void memcpyl(int *d, int *s, int c)
668 static void console_clear_line(int line, int begin, int end)
670 #ifdef VIDEO_HW_RECTFILL
671 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
672 VIDEO_FONT_WIDTH * begin, /* dest pos x */
674 VIDEO_FONT_HEIGHT * line, /* dest pos y */
675 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
676 VIDEO_FONT_HEIGHT, /* frame height */
680 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
681 memsetl(CONSOLE_ROW_FIRST +
682 CONSOLE_ROW_SIZE * line, /* offset of row */
683 CONSOLE_ROW_SIZE >> 2, /* length of row */
690 offset = CONSOLE_ROW_FIRST +
691 CONSOLE_ROW_SIZE * line + /* offset of row */
693 VIDEO_PIXEL_SIZE * begin; /* offset of col */
694 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
695 size >>= 2; /* length to end for memsetl() */
696 /* fill at col offset of i'th line using bgx as fill color */
697 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
698 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
703 static void console_scrollup(void)
705 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
708 /* copy up rows ignoring the first one */
710 #ifdef VIDEO_HW_BITBLT
711 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
712 0, /* source pos x */
714 VIDEO_FONT_HEIGHT * rows, /* source pos y */
716 video_logo_height, /* dest pos y */
717 VIDEO_VISIBLE_COLS, /* frame width */
720 - VIDEO_FONT_HEIGHT * rows /* frame height */
723 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
724 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
726 /* clear the last one */
727 for (i = 1; i <= rows; i++)
728 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
730 /* Decrement row number */
734 static void console_back(void)
738 if (console_col < 0) {
739 console_col = CONSOLE_COLS - 1;
746 #ifdef CONFIG_CFB_CONSOLE_ANSI
748 static void console_clear(void)
750 #ifdef VIDEO_HW_RECTFILL
751 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
753 video_logo_height, /* dest pos y */
754 VIDEO_VISIBLE_COLS, /* frame width */
755 VIDEO_VISIBLE_ROWS, /* frame height */
759 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
763 static void console_cursor_fix(void)
767 if (console_row >= CONSOLE_ROWS)
768 console_row = CONSOLE_ROWS - 1;
771 if (console_col >= CONSOLE_COLS)
772 console_col = CONSOLE_COLS - 1;
775 static void console_cursor_up(int n)
778 console_cursor_fix();
781 static void console_cursor_down(int n)
784 console_cursor_fix();
787 static void console_cursor_left(int n)
790 console_cursor_fix();
793 static void console_cursor_right(int n)
796 console_cursor_fix();
799 static void console_cursor_set_position(int row, int col)
801 if (console_row != -1)
803 if (console_col != -1)
805 console_cursor_fix();
808 static void console_previousline(int n)
810 /* FIXME: also scroll terminal ? */
812 console_cursor_fix();
815 static void console_swap_colors(void)
823 static inline int console_cursor_is_visible(void)
825 return !ansi_cursor_hidden;
828 static inline int console_cursor_is_visible(void)
834 static void console_newline(int n)
839 /* Check if we need to scroll the terminal */
840 if (console_row >= CONSOLE_ROWS) {
841 /* Scroll everything up */
846 static void console_cr(void)
851 static void parse_putc(const char c)
855 if (console_cursor_is_visible())
859 case 13: /* back to first column */
863 case '\n': /* next line */
864 if (console_col || (!console_col && nl))
870 console_col |= 0x0008;
871 console_col &= ~0x0007;
873 if (console_col >= CONSOLE_COLS)
877 case 8: /* backspace */
884 default: /* draw the char */
885 video_putchar(console_col * VIDEO_FONT_WIDTH,
886 console_row * VIDEO_FONT_HEIGHT, c);
889 /* check for newline */
890 if (console_col >= CONSOLE_COLS) {
896 if (console_cursor_is_visible())
900 static void video_putc(struct stdio_dev *dev, const char c)
902 #ifdef CONFIG_CFB_CONSOLE_ANSI
906 for (i = 0; i < ansi_buf_size; ++i)
907 parse_putc(ansi_buf[i]);
913 if (ansi_buf_size > 0) {
933 ansi_buf[ansi_buf_size++] = c;
935 if (ansi_buf_size >= sizeof(ansi_buf))
938 for (i = 0; i < ansi_buf_size; ++i) {
944 if (ansi_buf[i] == 27)
951 if (ansi_buf[i] == '[')
958 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
959 num1 = ansi_buf[i]-'0';
961 } else if (ansi_buf[i] != '?') {
969 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
971 num1 += ansi_buf[i]-'0';
979 if (ansi_buf[i] != ';') {
987 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
988 num2 = ansi_buf[i]-'0';
995 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
997 num2 += ansi_buf[i]-'0';
1005 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1006 || ansi_buf[i] == 'J'
1007 || ansi_buf[i] == 'K'
1008 || ansi_buf[i] == 'h'
1009 || ansi_buf[i] == 'l'
1010 || ansi_buf[i] == 'm') {
1011 cchar = ansi_buf[i];
1020 for (i = 0; i < ansi_buf_size; ++i)
1021 parse_putc(ansi_buf[i]);
1027 if (!ansi_cursor_hidden)
1032 /* move cursor num1 rows up */
1033 console_cursor_up(num1);
1036 /* move cursor num1 rows down */
1037 console_cursor_down(num1);
1040 /* move cursor num1 columns forward */
1041 console_cursor_right(num1);
1044 /* move cursor num1 columns back */
1045 console_cursor_left(num1);
1048 /* move cursor num1 rows up at begin of row */
1049 console_previousline(num1);
1052 /* move cursor num1 rows down at begin of row */
1053 console_newline(num1);
1056 /* move cursor to column num1 */
1057 console_cursor_set_position(-1, num1-1);
1060 /* move cursor to row num1, column num2 */
1061 console_cursor_set_position(num1-1, num2-1);
1064 /* clear console and move cursor to 0, 0 */
1066 console_cursor_set_position(0, 0);
1071 console_clear_line(console_row,
1075 console_clear_line(console_row,
1078 console_clear_line(console_row,
1082 ansi_cursor_hidden = 0;
1085 ansi_cursor_hidden = 1;
1088 if (num1 == 0) { /* reset swapped colors */
1089 if (ansi_colors_need_revert) {
1090 console_swap_colors();
1091 ansi_colors_need_revert = 0;
1093 } else if (num1 == 7) { /* once swap colors */
1094 if (!ansi_colors_need_revert) {
1095 console_swap_colors();
1096 ansi_colors_need_revert = 1;
1101 if (!ansi_cursor_hidden)
1110 if (cfb_do_flush_cache)
1111 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1114 static void video_puts(struct stdio_dev *dev, const char *s)
1116 int flush = cfb_do_flush_cache;
1117 int count = strlen(s);
1119 /* temporarily disable cache flush */
1120 cfb_do_flush_cache = 0;
1123 video_putc(dev, *s++);
1126 cfb_do_flush_cache = flush;
1127 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1132 * Do not enforce drivers (or board code) to provide empty
1133 * video_set_lut() if they do not support 8 bpp format.
1134 * Implement weak default function instead.
1136 __weak void video_set_lut(unsigned int index, unsigned char r,
1137 unsigned char g, unsigned char b)
1141 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1143 #define FILL_8BIT_332RGB(r,g,b) { \
1144 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1148 #define FILL_15BIT_555RGB(r,g,b) { \
1149 *(unsigned short *)fb = \
1150 SWAP16((unsigned short)(((r>>3)<<10) | \
1156 #define FILL_16BIT_565RGB(r,g,b) { \
1157 *(unsigned short *)fb = \
1158 SWAP16((unsigned short)((((r)>>3)<<11)| \
1164 #define FILL_32BIT_X888RGB(r,g,b) { \
1165 *(unsigned long *)fb = \
1166 SWAP32((unsigned long)(((r<<16) | \
1172 #ifdef VIDEO_FB_LITTLE_ENDIAN
1173 #define FILL_24BIT_888RGB(r,g,b) { \
1180 #define FILL_24BIT_888RGB(r,g,b) { \
1188 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1189 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1191 ushort *dst = (ushort *) fb;
1192 ushort color = (ushort) (((r >> 3) << 10) |
1203 * RLE8 bitmap support
1206 #ifdef CONFIG_VIDEO_BMP_RLE8
1207 /* Pre-calculated color table entry */
1210 unsigned short w; /* word */
1211 unsigned int dw; /* double word */
1212 } ce; /* color entry */
1216 * Helper to draw encoded/unencoded run.
1218 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1221 ulong addr = (ulong) *fb;
1227 * Setup offset of the color index in the bitmap.
1228 * Color index of encoded run is at offset 1.
1230 off = enc ? &enc_off : &i;
1232 switch (VIDEO_DATA_FORMAT) {
1233 case GDF__8BIT_INDEX:
1234 for (i = 0; i < cnt; i++)
1235 *(unsigned char *) addr++ = bm[*off];
1237 case GDF_15BIT_555RGB:
1238 case GDF_16BIT_565RGB:
1239 /* differences handled while pre-calculating palette */
1240 for (i = 0; i < cnt; i++) {
1241 *(unsigned short *) addr = p[bm[*off]].ce.w;
1245 case GDF_32BIT_X888RGB:
1246 for (i = 0; i < cnt; i++) {
1247 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1252 *fb = (uchar *) addr; /* return modified address */
1255 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1256 int width, int height)
1260 unsigned int cnt, runlen;
1262 int x, y, bpp, i, ncolors;
1263 struct palette p[256];
1264 struct bmp_color_table_entry cte;
1265 int green_shift, red_off;
1266 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
1270 y = __le32_to_cpu(img->header.height) - 1;
1271 ncolors = __le32_to_cpu(img->header.colors_used);
1272 bpp = VIDEO_PIXEL_SIZE;
1273 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1274 (y + yoff) * VIDEO_LINE_LEN +
1277 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1279 /* pre-calculate and setup palette */
1280 switch (VIDEO_DATA_FORMAT) {
1281 case GDF__8BIT_INDEX:
1282 for (i = 0; i < ncolors; i++) {
1283 cte = img->color_table[i];
1284 video_set_lut(i, cte.red, cte.green, cte.blue);
1287 case GDF_15BIT_555RGB:
1288 case GDF_16BIT_565RGB:
1289 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1296 for (i = 0; i < ncolors; i++) {
1297 cte = img->color_table[i];
1298 p[i].ce.w = SWAP16((unsigned short)
1299 (((cte.red >> 3) << red_off) |
1300 ((cte.green >> green_shift) << 5) |
1304 case GDF_32BIT_X888RGB:
1305 for (i = 0; i < ncolors; i++) {
1306 cte = img->color_table[i];
1307 p[i].ce.dw = SWAP32((cte.red << 16) |
1313 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1323 /* scan line end marker */
1327 fbp = (unsigned char *)
1328 ((unsigned int) video_fb_address +
1329 (y + yoff) * VIDEO_LINE_LEN +
1333 /* end of bitmap data marker */
1337 /* run offset marker */
1340 fbp = (unsigned char *)
1341 ((unsigned int) video_fb_address +
1342 (y + yoff) * VIDEO_LINE_LEN +
1360 if (x + runlen > width)
1362 draw_bitmap(&fbp, bm, p, cnt, 0);
1368 bm++; /* 0 padding if length is odd */
1379 if (y < height) { /* only draw into visible area */
1385 if (x + runlen > width)
1387 draw_bitmap(&fbp, bm, p, cnt, 1);
1396 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1402 * Display the BMP file located at address bmp_image.
1404 int video_display_bitmap(ulong bmp_image, int x, int y)
1406 ushort xcount, ycount;
1408 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1411 unsigned long width, height, bpp;
1413 unsigned long compression;
1414 struct bmp_color_table_entry cte;
1416 #ifdef CONFIG_VIDEO_BMP_GZIP
1417 unsigned char *dst = NULL;
1423 if (!((bmp->header.signature[0] == 'B') &&
1424 (bmp->header.signature[1] == 'M'))) {
1426 #ifdef CONFIG_VIDEO_BMP_GZIP
1428 * Could be a gzipped bmp image, try to decrompress...
1430 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1431 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1433 printf("Error: malloc in gunzip failed!\n");
1437 * NB: we need to force offset of +2
1438 * See doc/README.displaying-bmps
1440 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1441 (uchar *) bmp_image,
1443 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1448 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1449 printf("Image could be truncated "
1450 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1454 * Set addr to decompressed image
1456 bmp = (struct bmp_image *)(dst+2);
1458 if (!((bmp->header.signature[0] == 'B') &&
1459 (bmp->header.signature[1] == 'M'))) {
1460 printf("Error: no valid bmp.gz image at %lx\n",
1466 printf("Error: no valid bmp image at %lx\n", bmp_image);
1468 #endif /* CONFIG_VIDEO_BMP_GZIP */
1471 width = le32_to_cpu(bmp->header.width);
1472 height = le32_to_cpu(bmp->header.height);
1473 bpp = le16_to_cpu(bmp->header.bit_count);
1474 colors = le32_to_cpu(bmp->header.colors_used);
1475 compression = le32_to_cpu(bmp->header.compression);
1477 debug("Display-bmp: %ld x %ld with %d colors\n",
1478 width, height, colors);
1480 if (compression != BMP_BI_RGB
1481 #ifdef CONFIG_VIDEO_BMP_RLE8
1482 && compression != BMP_BI_RLE8
1485 printf("Error: compression type %ld not supported\n",
1487 #ifdef CONFIG_VIDEO_BMP_GZIP
1494 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1496 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1497 if (x == BMP_ALIGN_CENTER)
1498 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1500 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1502 if (y == BMP_ALIGN_CENTER)
1503 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1505 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1506 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1509 * Just ignore elements which are completely beyond screen
1512 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1515 if ((x + width) > VIDEO_VISIBLE_COLS)
1516 width = VIDEO_VISIBLE_COLS - x;
1517 if ((y + height) > VIDEO_VISIBLE_ROWS)
1518 height = VIDEO_VISIBLE_ROWS - y;
1520 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1521 fb = (uchar *) (video_fb_address +
1522 ((y + height - 1) * VIDEO_LINE_LEN) +
1523 x * VIDEO_PIXEL_SIZE);
1525 #ifdef CONFIG_VIDEO_BMP_RLE8
1526 if (compression == BMP_BI_RLE8) {
1527 return display_rle8_bitmap(bmp, x, y, width, height);
1531 /* We handle only 4, 8, or 24 bpp bitmaps */
1532 switch (le16_to_cpu(bmp->header.bit_count)) {
1534 padded_line -= width / 2;
1537 switch (VIDEO_DATA_FORMAT) {
1538 case GDF_32BIT_X888RGB:
1542 * Don't assume that 'width' is an
1545 for (xcount = 0; xcount < width; xcount++) {
1553 cte = bmp->color_table[idx];
1554 FILL_32BIT_X888RGB(cte.red, cte.green,
1557 bmap += padded_line;
1558 fb -= VIDEO_LINE_LEN + width *
1563 puts("4bpp bitmap unsupported with current "
1570 padded_line -= width;
1571 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1573 for (xcount = 0; xcount < colors; ++xcount) {
1574 cte = bmp->color_table[xcount];
1575 video_set_lut(xcount, cte.red, cte.green,
1580 switch (VIDEO_DATA_FORMAT) {
1581 case GDF__8BIT_INDEX:
1588 bmap += padded_line;
1589 fb -= VIDEO_LINE_LEN + width *
1593 case GDF__8BIT_332RGB:
1598 cte = bmp->color_table[*bmap++];
1599 FILL_8BIT_332RGB(cte.red, cte.green,
1602 bmap += padded_line;
1603 fb -= VIDEO_LINE_LEN + width *
1607 case GDF_15BIT_555RGB:
1609 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1615 cte = bmp->color_table[*bmap++];
1616 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1617 fill_555rgb_pswap(fb, xpos++, cte.red,
1622 FILL_15BIT_555RGB(cte.red, cte.green,
1626 bmap += padded_line;
1627 fb -= VIDEO_LINE_LEN + width *
1631 case GDF_16BIT_565RGB:
1636 cte = bmp->color_table[*bmap++];
1637 FILL_16BIT_565RGB(cte.red, cte.green,
1640 bmap += padded_line;
1641 fb -= VIDEO_LINE_LEN + width *
1645 case GDF_32BIT_X888RGB:
1650 cte = bmp->color_table[*bmap++];
1651 FILL_32BIT_X888RGB(cte.red, cte.green,
1654 bmap += padded_line;
1655 fb -= VIDEO_LINE_LEN + width *
1659 case GDF_24BIT_888RGB:
1664 cte = bmp->color_table[*bmap++];
1665 FILL_24BIT_888RGB(cte.red, cte.green,
1668 bmap += padded_line;
1669 fb -= VIDEO_LINE_LEN + width *
1676 padded_line -= 3 * width;
1678 switch (VIDEO_DATA_FORMAT) {
1679 case GDF__8BIT_332RGB:
1684 FILL_8BIT_332RGB(bmap[2], bmap[1],
1688 bmap += padded_line;
1689 fb -= VIDEO_LINE_LEN + width *
1693 case GDF_15BIT_555RGB:
1695 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1701 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1702 fill_555rgb_pswap(fb, xpos++, bmap[2],
1706 FILL_15BIT_555RGB(bmap[2], bmap[1],
1711 bmap += padded_line;
1712 fb -= VIDEO_LINE_LEN + width *
1716 case GDF_16BIT_565RGB:
1721 FILL_16BIT_565RGB(bmap[2], bmap[1],
1725 bmap += padded_line;
1726 fb -= VIDEO_LINE_LEN + width *
1730 case GDF_32BIT_X888RGB:
1735 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1739 bmap += padded_line;
1740 fb -= VIDEO_LINE_LEN + width *
1744 case GDF_24BIT_888RGB:
1749 FILL_24BIT_888RGB(bmap[2], bmap[1],
1753 bmap += padded_line;
1754 fb -= VIDEO_LINE_LEN + width *
1759 printf("Error: 24 bits/pixel bitmap incompatible "
1760 "with current video mode\n");
1765 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1766 le16_to_cpu(bmp->header.bit_count));
1770 #ifdef CONFIG_VIDEO_BMP_GZIP
1776 if (cfb_do_flush_cache)
1777 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1783 #ifdef CONFIG_VIDEO_LOGO
1784 static int video_logo_xpos;
1785 static int video_logo_ypos;
1787 static void plot_logo_or_black(void *screen, int x, int y, int black);
1789 static void logo_plot(void *screen, int x, int y)
1791 plot_logo_or_black(screen, x, y, 0);
1794 static void logo_black(void)
1796 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
1800 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1803 return cmd_usage(cmdtp);
1810 clrlogo, 1, 0, do_clrlogo,
1811 "fill the boot logo area with black",
1815 static void plot_logo_or_black(void *screen, int x, int y, int black)
1819 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
1820 int ycount = video_logo_height;
1821 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1822 unsigned char *source;
1823 unsigned char *dest;
1825 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1826 if (x == BMP_ALIGN_CENTER)
1827 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1829 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1831 if (y == BMP_ALIGN_CENTER)
1832 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1834 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1835 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1837 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
1839 #ifdef CONFIG_VIDEO_BMP_LOGO
1840 source = bmp_logo_bitmap;
1842 /* Allocate temporary space for computing colormap */
1843 logo_red = malloc(BMP_LOGO_COLORS);
1844 logo_green = malloc(BMP_LOGO_COLORS);
1845 logo_blue = malloc(BMP_LOGO_COLORS);
1846 /* Compute color map */
1847 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1848 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1849 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1850 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1853 source = linux_logo;
1854 logo_red = linux_logo_red;
1855 logo_green = linux_logo_green;
1856 logo_blue = linux_logo_blue;
1859 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1860 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1861 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1862 logo_red[i], logo_green[i],
1868 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1871 xcount = VIDEO_LOGO_WIDTH;
1878 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1879 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1880 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1883 switch (VIDEO_DATA_FORMAT) {
1884 case GDF__8BIT_INDEX:
1887 case GDF__8BIT_332RGB:
1888 *dest = ((r >> 5) << 5) |
1892 case GDF_15BIT_555RGB:
1893 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1894 fill_555rgb_pswap(dest, xpos++, r, g, b);
1896 *(unsigned short *) dest =
1897 SWAP16((unsigned short) (
1903 case GDF_16BIT_565RGB:
1904 *(unsigned short *) dest =
1905 SWAP16((unsigned short) (
1910 case GDF_32BIT_X888RGB:
1911 *(unsigned long *) dest =
1912 SWAP32((unsigned long) (
1917 case GDF_24BIT_888RGB:
1918 #ifdef VIDEO_FB_LITTLE_ENDIAN
1930 dest += VIDEO_PIXEL_SIZE;
1934 #ifdef CONFIG_VIDEO_BMP_LOGO
1941 static void *video_logo(void)
1945 __maybe_unused int y_off = 0;
1946 __maybe_unused ulong addr;
1947 __maybe_unused char *s;
1949 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1951 #ifdef CONFIG_SPLASH_SCREEN
1952 s = getenv("splashimage");
1954 splash_screen_prepare();
1955 addr = simple_strtoul(s, NULL, 16);
1957 if (video_display_bitmap(addr,
1959 video_logo_ypos) == 0) {
1960 video_logo_height = 0;
1961 return ((void *) (video_fb_address));
1964 #endif /* CONFIG_SPLASH_SCREEN */
1966 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
1968 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1970 * when using splashpos for video_logo, skip any info
1971 * output on video console if the logo is not at 0,0
1973 if (video_logo_xpos || video_logo_ypos) {
1975 * video_logo_height is used in text and cursor offset
1976 * calculations. Since the console is below the logo,
1977 * we need to adjust the logo height
1979 if (video_logo_ypos == BMP_ALIGN_CENTER)
1980 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
1981 VIDEO_LOGO_HEIGHT) / 2);
1982 else if (video_logo_ypos > 0)
1983 video_logo_height += video_logo_ypos;
1985 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1988 if (board_cfb_skip())
1991 sprintf(info, " %s", version_string);
1993 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1997 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1998 (uchar *) info, space);
1999 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2000 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2001 (uchar *) info + space, len - space);
2004 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
2006 #ifdef CONFIG_CONSOLE_EXTRA_INFO
2009 ((video_logo_height -
2010 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
2012 for (i = 1; i < n; i++) {
2013 video_get_info_str(i, info);
2019 video_drawchars(VIDEO_INFO_X,
2023 (uchar *) info, space);
2025 video_drawchars(VIDEO_INFO_X +
2030 (uchar *) info + space,
2033 video_drawstring(VIDEO_INFO_X,
2043 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
2047 static int cfb_fb_is_in_dram(void)
2050 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2051 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2055 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2056 start = bd->bi_dram[i].start;
2057 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2058 if ((ulong)video_fb_address >= start &&
2059 (ulong)video_fb_address < end)
2063 if ((ulong)video_fb_address >= bd->bi_memstart &&
2064 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2070 void video_clear(void)
2072 if (!video_fb_address)
2074 #ifdef VIDEO_HW_RECTFILL
2075 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2078 VIDEO_VISIBLE_COLS, /* frame width */
2079 VIDEO_VISIBLE_ROWS, /* frame height */
2080 bgx /* fill color */
2083 memsetl(video_fb_address,
2084 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2088 static int video_init(void)
2090 unsigned char color8;
2092 pGD = video_hw_init();
2096 video_fb_address = (void *) VIDEO_FB_ADRS;
2097 #ifdef CONFIG_VIDEO_HW_CURSOR
2098 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
2101 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2103 /* Init drawing pats */
2104 switch (VIDEO_DATA_FORMAT) {
2105 case GDF__8BIT_INDEX:
2106 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2108 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2113 case GDF__8BIT_332RGB:
2114 color8 = ((CONSOLE_FG_COL & 0xe0) |
2115 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2116 CONSOLE_FG_COL >> 6);
2117 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2119 color8 = ((CONSOLE_BG_COL & 0xe0) |
2120 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2121 CONSOLE_BG_COL >> 6);
2122 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2125 case GDF_15BIT_555RGB:
2126 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
2127 ((CONSOLE_FG_COL >> 3) << 21) |
2128 ((CONSOLE_FG_COL >> 3) << 16) |
2129 ((CONSOLE_FG_COL >> 3) << 10) |
2130 ((CONSOLE_FG_COL >> 3) << 5) |
2131 (CONSOLE_FG_COL >> 3));
2132 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
2133 ((CONSOLE_BG_COL >> 3) << 21) |
2134 ((CONSOLE_BG_COL >> 3) << 16) |
2135 ((CONSOLE_BG_COL >> 3) << 10) |
2136 ((CONSOLE_BG_COL >> 3) << 5) |
2137 (CONSOLE_BG_COL >> 3));
2139 case GDF_16BIT_565RGB:
2140 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
2141 ((CONSOLE_FG_COL >> 2) << 21) |
2142 ((CONSOLE_FG_COL >> 3) << 16) |
2143 ((CONSOLE_FG_COL >> 3) << 11) |
2144 ((CONSOLE_FG_COL >> 2) << 5) |
2145 (CONSOLE_FG_COL >> 3));
2146 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
2147 ((CONSOLE_BG_COL >> 2) << 21) |
2148 ((CONSOLE_BG_COL >> 3) << 16) |
2149 ((CONSOLE_BG_COL >> 3) << 11) |
2150 ((CONSOLE_BG_COL >> 2) << 5) |
2151 (CONSOLE_BG_COL >> 3));
2153 case GDF_32BIT_X888RGB:
2154 fgx = (CONSOLE_FG_COL << 16) |
2155 (CONSOLE_FG_COL << 8) |
2157 bgx = (CONSOLE_BG_COL << 16) |
2158 (CONSOLE_BG_COL << 8) |
2161 case GDF_24BIT_888RGB:
2162 fgx = (CONSOLE_FG_COL << 24) |
2163 (CONSOLE_FG_COL << 16) |
2164 (CONSOLE_FG_COL << 8) |
2166 bgx = (CONSOLE_BG_COL << 24) |
2167 (CONSOLE_BG_COL << 16) |
2168 (CONSOLE_BG_COL << 8) |
2176 #ifdef CONFIG_VIDEO_LOGO
2177 /* Plot the logo and get start point of console */
2178 debug("Video: Drawing the logo ...\n");
2179 video_console_address = video_logo();
2181 video_console_address = video_fb_address;
2184 /* Initialize the console */
2188 if (cfb_do_flush_cache)
2189 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2195 * Implement a weak default function for boards that optionally
2196 * need to skip the video initialization.
2198 __weak int board_video_skip(void)
2200 /* As default, don't skip test */
2204 int drv_video_init(void)
2206 struct stdio_dev console_dev;
2208 bool __maybe_unused keyboard_ok = false;
2210 /* Check if video initialization should be skipped */
2211 if (board_video_skip())
2214 /* Init video chip - returns with framebuffer cleared */
2215 if (video_init() == -1)
2218 if (board_cfb_skip())
2221 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2222 have_keyboard = false;
2223 #elif defined(CONFIG_OF_CONTROL)
2224 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2225 "u-boot,no-keyboard");
2227 have_keyboard = true;
2229 if (have_keyboard) {
2230 debug("KBD: Keyboard init ...\n");
2231 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2232 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
2236 /* Init vga device */
2237 memset(&console_dev, 0, sizeof(console_dev));
2238 strcpy(console_dev.name, "vga");
2239 console_dev.flags = DEV_FLAGS_OUTPUT;
2240 console_dev.putc = video_putc; /* 'putc' function */
2241 console_dev.puts = video_puts; /* 'puts' function */
2243 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2244 if (have_keyboard && keyboard_ok) {
2245 /* Also init console device */
2246 console_dev.flags |= DEV_FLAGS_INPUT;
2247 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2248 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2252 if (stdio_register(&console_dev) != 0)
2255 /* Return success */
2259 void video_position_cursor(unsigned col, unsigned row)
2261 console_col = min(col, CONSOLE_COLS - 1);
2262 console_row = min(row, CONSOLE_ROWS - 1);
2265 int video_get_pixel_width(void)
2267 return VIDEO_VISIBLE_COLS;
2270 int video_get_pixel_height(void)
2272 return VIDEO_VISIBLE_ROWS;
2275 int video_get_screen_rows(void)
2277 return CONSOLE_ROWS;
2280 int video_get_screen_columns(void)
2282 return CONSOLE_COLS;