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_CONSOLE_CURSOR - on/off drawing cursor is done with
47 * delay loop in VIDEO_TSTC_FCT (i8042)
49 * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
50 * CONFIG_CONSOLE_TIME - display time/date in upper right
51 * corner, needs CONFIG_CMD_DATE and
52 * CONFIG_CONSOLE_CURSOR
53 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
54 * Use CONFIG_SPLASH_SCREEN_ALIGN with
55 * environment variable "splashpos" to place
56 * the logo on other position. In this case
57 * no CONSOLE_EXTRA_INFO is possible.
58 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
59 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
60 * strings that normaly goes to serial
61 * port. This define requires a board
63 * video_drawstring (VIDEO_INFO_X,
64 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
66 * that fills a info buffer at i=row.
67 * s.a: board/eltec/bab7xx.
68 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
69 * initialized as an output only device.
70 * The Keyboard driver will not be
71 * set-up. This may be used, if you have
72 * no or more than one Keyboard devices
73 * (USB Keyboard, AT Keyboard).
75 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
76 * character. No blinking is provided.
77 * Uses the macros CURSOR_SET and
80 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
81 * of the graphic chip. Uses the macro
82 * CURSOR_SET. ATTENTION: If booting an
83 * OS, the display driver must disable
84 * the hardware register of the graphic
85 * chip. Otherwise a blinking field is
93 #include <linux/compiler.h>
96 * Console device defines with SMI graphic
97 * Any other graphic must change this section
100 #ifdef CONFIG_VIDEO_SMI_LYNXEM
102 #define VIDEO_FB_LITTLE_ENDIAN
103 #define VIDEO_HW_RECTFILL
104 #define VIDEO_HW_BITBLT
108 * Defines for the CT69000 driver
110 #ifdef CONFIG_VIDEO_CT69000
112 #define VIDEO_FB_LITTLE_ENDIAN
113 #define VIDEO_HW_RECTFILL
114 #define VIDEO_HW_BITBLT
118 * Defines for the SED13806 driver
120 #ifdef CONFIG_VIDEO_SED13806
121 #define VIDEO_FB_LITTLE_ENDIAN
122 #define VIDEO_HW_RECTFILL
123 #define VIDEO_HW_BITBLT
126 #ifdef CONFIG_VIDEO_MXS
127 #define VIDEO_FB_16BPP_WORD_SWAP
131 * Defines for the MB862xx driver
133 #ifdef CONFIG_VIDEO_MB862xx
135 #ifdef CONFIG_VIDEO_CORALP
136 #define VIDEO_FB_LITTLE_ENDIAN
138 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
139 #define VIDEO_HW_RECTFILL
140 #define VIDEO_HW_BITBLT
145 * Defines for the i.MX31 driver (mx3fb.c)
147 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
148 #define VIDEO_FB_16BPP_WORD_SWAP
152 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
154 #include <video_fb.h>
161 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
162 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
163 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
164 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
165 #define VIDEO_FB_ADRS (pGD->frameAdrs)
168 * Console device defines with i8042 keyboard controller
169 * Any other keyboard controller must change this section
172 #ifdef CONFIG_I8042_KBD
175 #define VIDEO_KBD_INIT_FCT i8042_kbd_init()
176 #define VIDEO_TSTC_FCT i8042_tstc
177 #define VIDEO_GETC_FCT i8042_getc
185 #include <linux/types.h>
186 #include <stdio_dev.h>
187 #include <video_font.h>
189 #if defined(CONFIG_CMD_DATE)
193 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
194 #include <watchdog.h>
195 #include <bmp_layout.h>
201 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
202 * to let the cursor blink. Uses the macros
203 * CURSOR_OFF and CURSOR_ON.
204 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
205 * blinking is provided. Uses the macros CURSOR_SET
207 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
208 * graphic chip. Uses the macro CURSOR_SET.
209 * ATTENTION: If booting an OS, the display driver
210 * must disable the hardware register of the graphic
211 * chip. Otherwise a blinking field is displayed
213 #if !defined(CONFIG_CONSOLE_CURSOR) && \
214 !defined(CONFIG_VIDEO_SW_CURSOR) && \
215 !defined(CONFIG_VIDEO_HW_CURSOR)
216 /* no Cursor defined */
222 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
223 #if defined(CURSOR_ON) || \
224 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
225 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
226 or CONFIG_VIDEO_HW_CURSOR can be defined
228 void console_cursor(int state);
230 #define CURSOR_ON console_cursor(1)
231 #define CURSOR_OFF console_cursor(0)
232 #define CURSOR_SET video_set_cursor()
233 #endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
235 #ifdef CONFIG_CONSOLE_CURSOR
236 #ifndef CONFIG_CONSOLE_TIME
237 #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
239 #ifndef CONFIG_I8042_KBD
240 #warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
242 #endif /* CONFIG_CONSOLE_CURSOR */
245 #ifdef CONFIG_VIDEO_HW_CURSOR
247 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
248 or CONFIG_VIDEO_HW_CURSOR can be defined
252 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
253 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
254 #endif /* CONFIG_VIDEO_HW_CURSOR */
256 #ifdef CONFIG_VIDEO_LOGO
257 #ifdef CONFIG_VIDEO_BMP_LOGO
258 #include <bmp_logo.h>
259 #include <bmp_logo_data.h>
260 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
261 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
262 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
263 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
265 #else /* CONFIG_VIDEO_BMP_LOGO */
266 #define LINUX_LOGO_WIDTH 80
267 #define LINUX_LOGO_HEIGHT 80
268 #define LINUX_LOGO_COLORS 214
269 #define LINUX_LOGO_LUT_OFFSET 0x20
271 #include <linux_logo.h>
272 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
273 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
274 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
275 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
276 #endif /* CONFIG_VIDEO_BMP_LOGO */
277 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
278 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
279 #else /* CONFIG_VIDEO_LOGO */
280 #define VIDEO_LOGO_WIDTH 0
281 #define VIDEO_LOGO_HEIGHT 0
282 #endif /* CONFIG_VIDEO_LOGO */
284 #define VIDEO_COLS VIDEO_VISIBLE_COLS
285 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
286 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
287 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
288 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
289 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
291 #ifdef CONFIG_VIDEO_LOGO
292 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
294 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
297 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
298 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
299 #define CONSOLE_ROW_FIRST (video_console_address)
300 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
301 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
302 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
304 /* By default we scroll by a single line */
305 #ifndef CONFIG_CONSOLE_SCROLL_LINES
306 #define CONFIG_CONSOLE_SCROLL_LINES 1
310 #ifdef VIDEO_FB_LITTLE_ENDIAN
311 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
314 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
315 (((x) & 0x0000ff00) << 8) | \
316 (((x) & 0x00ff0000) >> 8) | \
317 (((x) & 0xff000000) >> 24) \
319 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
320 (((x) & 0x0000ff00) >> 8) | \
321 (((x) & 0x00ff0000) << 8) | \
322 (((x) & 0xff000000) >> 8) \
325 #define SWAP16(x) (x)
326 #define SWAP32(x) (x)
327 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
328 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
330 #define SHORTSWAP32(x) (x)
334 #ifdef CONFIG_CONSOLE_EXTRA_INFO
336 * setup a board string: type, speed, etc.
338 * line_number: location to place info string beside logo
339 * info: buffer for info string
341 extern void video_get_info_str(int line_number, char *info);
344 DECLARE_GLOBAL_DATA_PTR;
347 static GraphicDevice *pGD; /* Pointer to Graphic array */
349 static void *video_fb_address; /* frame buffer address */
350 static void *video_console_address; /* console buffer start address */
352 static int video_logo_height = VIDEO_LOGO_HEIGHT;
354 static int __maybe_unused cursor_state;
355 static int __maybe_unused old_col;
356 static int __maybe_unused old_row;
358 static int console_col; /* cursor col */
359 static int console_row; /* cursor row */
361 static u32 eorx, fgx, bgx; /* color pats */
363 static int cfb_do_flush_cache;
365 #ifdef CONFIG_CFB_CONSOLE_ANSI
366 static char ansi_buf[10];
367 static int ansi_buf_size;
368 static int ansi_colors_need_revert;
369 static int ansi_cursor_hidden;
372 static const int video_font_draw_table8[] = {
373 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
374 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
375 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
376 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
379 static const int video_font_draw_table15[] = {
380 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
383 static const int video_font_draw_table16[] = {
384 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
387 static const int video_font_draw_table24[16][3] = {
388 {0x00000000, 0x00000000, 0x00000000},
389 {0x00000000, 0x00000000, 0x00ffffff},
390 {0x00000000, 0x0000ffff, 0xff000000},
391 {0x00000000, 0x0000ffff, 0xffffffff},
392 {0x000000ff, 0xffff0000, 0x00000000},
393 {0x000000ff, 0xffff0000, 0x00ffffff},
394 {0x000000ff, 0xffffffff, 0xff000000},
395 {0x000000ff, 0xffffffff, 0xffffffff},
396 {0xffffff00, 0x00000000, 0x00000000},
397 {0xffffff00, 0x00000000, 0x00ffffff},
398 {0xffffff00, 0x0000ffff, 0xff000000},
399 {0xffffff00, 0x0000ffff, 0xffffffff},
400 {0xffffffff, 0xffff0000, 0x00000000},
401 {0xffffffff, 0xffff0000, 0x00ffffff},
402 {0xffffffff, 0xffffffff, 0xff000000},
403 {0xffffffff, 0xffffffff, 0xffffffff}
406 static const int video_font_draw_table32[16][4] = {
407 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
408 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
409 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
410 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
411 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
412 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
413 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
414 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
415 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
416 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
417 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
418 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
419 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
420 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
421 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
422 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
426 * Implement a weak default function for boards that optionally
427 * need to skip the cfb initialization.
429 __weak int board_cfb_skip(void)
431 /* As default, don't skip cfb init */
435 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
437 u8 *cdat, *dest, *dest0;
440 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
441 dest0 = video_fb_address + offset;
443 switch (VIDEO_DATA_FORMAT) {
444 case GDF__8BIT_INDEX:
445 case GDF__8BIT_332RGB:
448 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
449 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
450 rows--; dest += VIDEO_LINE_LEN) {
454 (video_font_draw_table8[bits >> 4] &
457 if (VIDEO_FONT_WIDTH == 4)
461 (video_font_draw_table8[bits & 15] &
464 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
469 case GDF_15BIT_555RGB:
472 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
473 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
474 rows--; dest += VIDEO_LINE_LEN) {
478 SHORTSWAP32((video_font_draw_table15
479 [bits >> 6] & eorx) ^
482 SHORTSWAP32((video_font_draw_table15
483 [bits >> 4 & 3] & eorx) ^
486 if (VIDEO_FONT_WIDTH == 4)
490 SHORTSWAP32((video_font_draw_table15
491 [bits >> 2 & 3] & eorx) ^
494 SHORTSWAP32((video_font_draw_table15
498 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
503 case GDF_16BIT_565RGB:
506 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
507 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
508 rows--; dest += VIDEO_LINE_LEN) {
512 SHORTSWAP32((video_font_draw_table16
513 [bits >> 6] & eorx) ^
516 SHORTSWAP32((video_font_draw_table16
517 [bits >> 4 & 3] & eorx) ^
520 if (VIDEO_FONT_WIDTH == 4)
524 SHORTSWAP32((video_font_draw_table16
525 [bits >> 2 & 3] & eorx) ^
528 SHORTSWAP32((video_font_draw_table16
532 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
537 case GDF_32BIT_X888RGB:
540 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
541 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
542 rows--; dest += VIDEO_LINE_LEN) {
546 SWAP32((video_font_draw_table32
547 [bits >> 4][0] & eorx) ^ bgx);
549 SWAP32((video_font_draw_table32
550 [bits >> 4][1] & eorx) ^ bgx);
552 SWAP32((video_font_draw_table32
553 [bits >> 4][2] & eorx) ^ bgx);
555 SWAP32((video_font_draw_table32
556 [bits >> 4][3] & eorx) ^ bgx);
559 if (VIDEO_FONT_WIDTH == 4)
563 SWAP32((video_font_draw_table32
564 [bits & 15][0] & eorx) ^ bgx);
566 SWAP32((video_font_draw_table32
567 [bits & 15][1] & eorx) ^ bgx);
569 SWAP32((video_font_draw_table32
570 [bits & 15][2] & eorx) ^ bgx);
572 SWAP32((video_font_draw_table32
573 [bits & 15][3] & eorx) ^ bgx);
575 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
580 case GDF_24BIT_888RGB:
583 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
584 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
585 rows--; dest += VIDEO_LINE_LEN) {
589 (video_font_draw_table24[bits >> 4][0]
592 (video_font_draw_table24[bits >> 4][1]
595 (video_font_draw_table24[bits >> 4][2]
598 if (VIDEO_FONT_WIDTH == 4)
602 (video_font_draw_table24[bits & 15][0]
605 (video_font_draw_table24[bits & 15][1]
608 (video_font_draw_table24[bits & 15][2]
611 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
618 static inline void video_drawstring(int xx, int yy, unsigned char *s)
620 video_drawchars(xx, yy, s, strlen((char *) s));
623 static void video_putchar(int xx, int yy, unsigned char c)
625 video_drawchars(xx, yy + video_logo_height, &c, 1);
628 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
629 static void video_set_cursor(void)
636 static void video_invertchar(int xx, int yy)
638 int firstx = xx * VIDEO_PIXEL_SIZE;
639 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
640 int firsty = yy * VIDEO_LINE_LEN;
641 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
643 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
644 for (x = firstx; x < lastx; x++) {
645 u8 *dest = (u8 *)(video_fb_address) + x + y;
651 void console_cursor(int state)
653 #ifdef CONFIG_CONSOLE_TIME
657 /* time update only if cursor is on (faster scroll) */
661 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
663 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
664 VIDEO_INFO_Y, (uchar *) info);
666 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
668 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
669 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
674 if (cursor_state != state) {
676 /* turn off the cursor */
677 video_invertchar(old_col * VIDEO_FONT_WIDTH,
678 old_row * VIDEO_FONT_HEIGHT +
681 /* turn off the cursor and record where it is */
682 video_invertchar(console_col * VIDEO_FONT_WIDTH,
683 console_row * VIDEO_FONT_HEIGHT +
685 old_col = console_col;
686 old_row = console_row;
688 cursor_state = state;
690 if (cfb_do_flush_cache)
691 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
695 #ifndef VIDEO_HW_RECTFILL
696 static void memsetl(int *p, int c, int v)
703 #ifndef VIDEO_HW_BITBLT
704 static void memcpyl(int *d, int *s, int c)
711 static void console_clear_line(int line, int begin, int end)
713 #ifdef VIDEO_HW_RECTFILL
714 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
715 VIDEO_FONT_WIDTH * begin, /* dest pos x */
717 VIDEO_FONT_HEIGHT * line, /* dest pos y */
718 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
719 VIDEO_FONT_HEIGHT, /* frame height */
723 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
724 memsetl(CONSOLE_ROW_FIRST +
725 CONSOLE_ROW_SIZE * line, /* offset of row */
726 CONSOLE_ROW_SIZE >> 2, /* length of row */
733 offset = CONSOLE_ROW_FIRST +
734 CONSOLE_ROW_SIZE * line + /* offset of row */
736 VIDEO_PIXEL_SIZE * begin; /* offset of col */
737 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
738 size >>= 2; /* length to end for memsetl() */
739 /* fill at col offset of i'th line using bgx as fill color */
740 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
741 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
746 static void console_scrollup(void)
748 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
751 /* copy up rows ignoring the first one */
753 #ifdef VIDEO_HW_BITBLT
754 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
755 0, /* source pos x */
757 VIDEO_FONT_HEIGHT * rows, /* source pos y */
759 video_logo_height, /* dest pos y */
760 VIDEO_VISIBLE_COLS, /* frame width */
763 - VIDEO_FONT_HEIGHT * rows /* frame height */
766 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
767 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
769 /* clear the last one */
770 for (i = 1; i <= rows; i++)
771 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
773 /* Decrement row number */
777 static void console_back(void)
781 if (console_col < 0) {
782 console_col = CONSOLE_COLS - 1;
789 #ifdef CONFIG_CFB_CONSOLE_ANSI
791 static void console_clear(void)
793 #ifdef VIDEO_HW_RECTFILL
794 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
796 video_logo_height, /* dest pos y */
797 VIDEO_VISIBLE_COLS, /* frame width */
798 VIDEO_VISIBLE_ROWS, /* frame height */
802 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
806 static void console_cursor_fix(void)
810 if (console_row >= CONSOLE_ROWS)
811 console_row = CONSOLE_ROWS - 1;
814 if (console_col >= CONSOLE_COLS)
815 console_col = CONSOLE_COLS - 1;
818 static void console_cursor_up(int n)
821 console_cursor_fix();
824 static void console_cursor_down(int n)
827 console_cursor_fix();
830 static void console_cursor_left(int n)
833 console_cursor_fix();
836 static void console_cursor_right(int n)
839 console_cursor_fix();
842 static void console_cursor_set_position(int row, int col)
844 if (console_row != -1)
846 if (console_col != -1)
848 console_cursor_fix();
851 static void console_previousline(int n)
853 /* FIXME: also scroll terminal ? */
855 console_cursor_fix();
858 static void console_swap_colors(void)
866 static inline int console_cursor_is_visible(void)
868 return !ansi_cursor_hidden;
871 static inline int console_cursor_is_visible(void)
877 static void console_newline(int n)
882 /* Check if we need to scroll the terminal */
883 if (console_row >= CONSOLE_ROWS) {
884 /* Scroll everything up */
889 static void console_cr(void)
894 static void parse_putc(const char c)
898 if (console_cursor_is_visible())
902 case 13: /* back to first column */
906 case '\n': /* next line */
907 if (console_col || (!console_col && nl))
913 console_col |= 0x0008;
914 console_col &= ~0x0007;
916 if (console_col >= CONSOLE_COLS)
920 case 8: /* backspace */
927 default: /* draw the char */
928 video_putchar(console_col * VIDEO_FONT_WIDTH,
929 console_row * VIDEO_FONT_HEIGHT, c);
932 /* check for newline */
933 if (console_col >= CONSOLE_COLS) {
939 if (console_cursor_is_visible())
943 static void video_putc(struct stdio_dev *dev, const char c)
945 #ifdef CONFIG_CFB_CONSOLE_ANSI
949 for (i = 0; i < ansi_buf_size; ++i)
950 parse_putc(ansi_buf[i]);
956 if (ansi_buf_size > 0) {
976 ansi_buf[ansi_buf_size++] = c;
978 if (ansi_buf_size >= sizeof(ansi_buf))
981 for (i = 0; i < ansi_buf_size; ++i) {
987 if (ansi_buf[i] == 27)
994 if (ansi_buf[i] == '[')
1001 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1002 num1 = ansi_buf[i]-'0';
1004 } else if (ansi_buf[i] != '?') {
1012 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1014 num1 += ansi_buf[i]-'0';
1022 if (ansi_buf[i] != ';') {
1030 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1031 num2 = ansi_buf[i]-'0';
1038 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1040 num2 += ansi_buf[i]-'0';
1048 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1049 || ansi_buf[i] == 'J'
1050 || ansi_buf[i] == 'K'
1051 || ansi_buf[i] == 'h'
1052 || ansi_buf[i] == 'l'
1053 || ansi_buf[i] == 'm') {
1054 cchar = ansi_buf[i];
1063 for (i = 0; i < ansi_buf_size; ++i)
1064 parse_putc(ansi_buf[i]);
1070 if (!ansi_cursor_hidden)
1075 /* move cursor num1 rows up */
1076 console_cursor_up(num1);
1079 /* move cursor num1 rows down */
1080 console_cursor_down(num1);
1083 /* move cursor num1 columns forward */
1084 console_cursor_right(num1);
1087 /* move cursor num1 columns back */
1088 console_cursor_left(num1);
1091 /* move cursor num1 rows up at begin of row */
1092 console_previousline(num1);
1095 /* move cursor num1 rows down at begin of row */
1096 console_newline(num1);
1099 /* move cursor to column num1 */
1100 console_cursor_set_position(-1, num1-1);
1103 /* move cursor to row num1, column num2 */
1104 console_cursor_set_position(num1-1, num2-1);
1107 /* clear console and move cursor to 0, 0 */
1109 console_cursor_set_position(0, 0);
1114 console_clear_line(console_row,
1118 console_clear_line(console_row,
1121 console_clear_line(console_row,
1125 ansi_cursor_hidden = 0;
1128 ansi_cursor_hidden = 1;
1131 if (num1 == 0) { /* reset swapped colors */
1132 if (ansi_colors_need_revert) {
1133 console_swap_colors();
1134 ansi_colors_need_revert = 0;
1136 } else if (num1 == 7) { /* once swap colors */
1137 if (!ansi_colors_need_revert) {
1138 console_swap_colors();
1139 ansi_colors_need_revert = 1;
1144 if (!ansi_cursor_hidden)
1153 if (cfb_do_flush_cache)
1154 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1157 static void video_puts(struct stdio_dev *dev, const char *s)
1159 int flush = cfb_do_flush_cache;
1160 int count = strlen(s);
1162 /* temporarily disable cache flush */
1163 cfb_do_flush_cache = 0;
1166 video_putc(dev, *s++);
1169 cfb_do_flush_cache = flush;
1170 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1175 * Do not enforce drivers (or board code) to provide empty
1176 * video_set_lut() if they do not support 8 bpp format.
1177 * Implement weak default function instead.
1179 __weak void video_set_lut(unsigned int index, unsigned char r,
1180 unsigned char g, unsigned char b)
1184 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1186 #define FILL_8BIT_332RGB(r,g,b) { \
1187 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1191 #define FILL_15BIT_555RGB(r,g,b) { \
1192 *(unsigned short *)fb = \
1193 SWAP16((unsigned short)(((r>>3)<<10) | \
1199 #define FILL_16BIT_565RGB(r,g,b) { \
1200 *(unsigned short *)fb = \
1201 SWAP16((unsigned short)((((r)>>3)<<11)| \
1207 #define FILL_32BIT_X888RGB(r,g,b) { \
1208 *(unsigned long *)fb = \
1209 SWAP32((unsigned long)(((r<<16) | \
1215 #ifdef VIDEO_FB_LITTLE_ENDIAN
1216 #define FILL_24BIT_888RGB(r,g,b) { \
1223 #define FILL_24BIT_888RGB(r,g,b) { \
1231 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1232 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1234 ushort *dst = (ushort *) fb;
1235 ushort color = (ushort) (((r >> 3) << 10) |
1246 * RLE8 bitmap support
1249 #ifdef CONFIG_VIDEO_BMP_RLE8
1250 /* Pre-calculated color table entry */
1253 unsigned short w; /* word */
1254 unsigned int dw; /* double word */
1255 } ce; /* color entry */
1259 * Helper to draw encoded/unencoded run.
1261 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1264 ulong addr = (ulong) *fb;
1270 * Setup offset of the color index in the bitmap.
1271 * Color index of encoded run is at offset 1.
1273 off = enc ? &enc_off : &i;
1275 switch (VIDEO_DATA_FORMAT) {
1276 case GDF__8BIT_INDEX:
1277 for (i = 0; i < cnt; i++)
1278 *(unsigned char *) addr++ = bm[*off];
1280 case GDF_15BIT_555RGB:
1281 case GDF_16BIT_565RGB:
1282 /* differences handled while pre-calculating palette */
1283 for (i = 0; i < cnt; i++) {
1284 *(unsigned short *) addr = p[bm[*off]].ce.w;
1288 case GDF_32BIT_X888RGB:
1289 for (i = 0; i < cnt; i++) {
1290 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1295 *fb = (uchar *) addr; /* return modified address */
1298 static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
1299 int width, int height)
1303 unsigned int cnt, runlen;
1305 int x, y, bpp, i, ncolors;
1306 struct palette p[256];
1307 struct bmp_color_table_entry cte;
1308 int green_shift, red_off;
1309 int limit = VIDEO_COLS * VIDEO_ROWS;
1313 y = __le32_to_cpu(img->header.height) - 1;
1314 ncolors = __le32_to_cpu(img->header.colors_used);
1315 bpp = VIDEO_PIXEL_SIZE;
1316 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1317 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
1319 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1321 /* pre-calculate and setup palette */
1322 switch (VIDEO_DATA_FORMAT) {
1323 case GDF__8BIT_INDEX:
1324 for (i = 0; i < ncolors; i++) {
1325 cte = img->color_table[i];
1326 video_set_lut(i, cte.red, cte.green, cte.blue);
1329 case GDF_15BIT_555RGB:
1330 case GDF_16BIT_565RGB:
1331 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1338 for (i = 0; i < ncolors; i++) {
1339 cte = img->color_table[i];
1340 p[i].ce.w = SWAP16((unsigned short)
1341 (((cte.red >> 3) << red_off) |
1342 ((cte.green >> green_shift) << 5) |
1346 case GDF_32BIT_X888RGB:
1347 for (i = 0; i < ncolors; i++) {
1348 cte = img->color_table[i];
1349 p[i].ce.dw = SWAP32((cte.red << 16) |
1355 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1365 /* scan line end marker */
1369 fbp = (unsigned char *)
1370 ((unsigned int) video_fb_address +
1371 (((y + yoff) * VIDEO_COLS) +
1375 /* end of bitmap data marker */
1379 /* run offset marker */
1382 fbp = (unsigned char *)
1383 ((unsigned int) video_fb_address +
1384 (((y + yoff) * VIDEO_COLS) +
1402 if (x + runlen > width)
1404 draw_bitmap(&fbp, bm, p, cnt, 0);
1410 bm++; /* 0 padding if length is odd */
1421 if (y < height) { /* only draw into visible area */
1427 if (x + runlen > width)
1429 draw_bitmap(&fbp, bm, p, cnt, 1);
1438 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1444 * Display the BMP file located at address bmp_image.
1446 int video_display_bitmap(ulong bmp_image, int x, int y)
1448 ushort xcount, ycount;
1450 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
1453 unsigned long width, height, bpp;
1455 unsigned long compression;
1456 struct bmp_color_table_entry cte;
1458 #ifdef CONFIG_VIDEO_BMP_GZIP
1459 unsigned char *dst = NULL;
1465 if (!((bmp->header.signature[0] == 'B') &&
1466 (bmp->header.signature[1] == 'M'))) {
1468 #ifdef CONFIG_VIDEO_BMP_GZIP
1470 * Could be a gzipped bmp image, try to decrompress...
1472 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1473 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1475 printf("Error: malloc in gunzip failed!\n");
1479 * NB: we need to force offset of +2
1480 * See doc/README.displaying-bmps
1482 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1483 (uchar *) bmp_image,
1485 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1490 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1491 printf("Image could be truncated "
1492 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1496 * Set addr to decompressed image
1498 bmp = (struct bmp_image *)(dst+2);
1500 if (!((bmp->header.signature[0] == 'B') &&
1501 (bmp->header.signature[1] == 'M'))) {
1502 printf("Error: no valid bmp.gz image at %lx\n",
1508 printf("Error: no valid bmp image at %lx\n", bmp_image);
1510 #endif /* CONFIG_VIDEO_BMP_GZIP */
1513 width = le32_to_cpu(bmp->header.width);
1514 height = le32_to_cpu(bmp->header.height);
1515 bpp = le16_to_cpu(bmp->header.bit_count);
1516 colors = le32_to_cpu(bmp->header.colors_used);
1517 compression = le32_to_cpu(bmp->header.compression);
1519 debug("Display-bmp: %ld x %ld with %d colors\n",
1520 width, height, colors);
1522 if (compression != BMP_BI_RGB
1523 #ifdef CONFIG_VIDEO_BMP_RLE8
1524 && compression != BMP_BI_RLE8
1527 printf("Error: compression type %ld not supported\n",
1529 #ifdef CONFIG_VIDEO_BMP_GZIP
1536 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1538 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1539 if (x == BMP_ALIGN_CENTER)
1540 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
1542 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
1544 if (y == BMP_ALIGN_CENTER)
1545 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
1547 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
1548 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1551 * Just ignore elements which are completely beyond screen
1554 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1557 if ((x + width) > VIDEO_VISIBLE_COLS)
1558 width = VIDEO_VISIBLE_COLS - x;
1559 if ((y + height) > VIDEO_VISIBLE_ROWS)
1560 height = VIDEO_VISIBLE_ROWS - y;
1562 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1563 fb = (uchar *) (video_fb_address +
1564 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1565 x * VIDEO_PIXEL_SIZE);
1567 #ifdef CONFIG_VIDEO_BMP_RLE8
1568 if (compression == BMP_BI_RLE8) {
1569 return display_rle8_bitmap(bmp, x, y, width, height);
1573 /* We handle only 4, 8, or 24 bpp bitmaps */
1574 switch (le16_to_cpu(bmp->header.bit_count)) {
1576 padded_line -= width / 2;
1579 switch (VIDEO_DATA_FORMAT) {
1580 case GDF_32BIT_X888RGB:
1584 * Don't assume that 'width' is an
1587 for (xcount = 0; xcount < width; xcount++) {
1595 cte = bmp->color_table[idx];
1596 FILL_32BIT_X888RGB(cte.red, cte.green,
1599 bmap += padded_line;
1600 fb -= (VIDEO_VISIBLE_COLS + width) *
1605 puts("4bpp bitmap unsupported with current "
1612 padded_line -= width;
1613 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1615 for (xcount = 0; xcount < colors; ++xcount) {
1616 cte = bmp->color_table[xcount];
1617 video_set_lut(xcount, cte.red, cte.green,
1622 switch (VIDEO_DATA_FORMAT) {
1623 case GDF__8BIT_INDEX:
1630 bmap += padded_line;
1631 fb -= (VIDEO_VISIBLE_COLS + width) *
1635 case GDF__8BIT_332RGB:
1640 cte = bmp->color_table[*bmap++];
1641 FILL_8BIT_332RGB(cte.red, cte.green,
1644 bmap += padded_line;
1645 fb -= (VIDEO_VISIBLE_COLS + width) *
1649 case GDF_15BIT_555RGB:
1651 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1657 cte = bmp->color_table[*bmap++];
1658 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1659 fill_555rgb_pswap(fb, xpos++, cte.red,
1664 FILL_15BIT_555RGB(cte.red, cte.green,
1668 bmap += padded_line;
1669 fb -= (VIDEO_VISIBLE_COLS + width) *
1673 case GDF_16BIT_565RGB:
1678 cte = bmp->color_table[*bmap++];
1679 FILL_16BIT_565RGB(cte.red, cte.green,
1682 bmap += padded_line;
1683 fb -= (VIDEO_VISIBLE_COLS + width) *
1687 case GDF_32BIT_X888RGB:
1692 cte = bmp->color_table[*bmap++];
1693 FILL_32BIT_X888RGB(cte.red, cte.green,
1696 bmap += padded_line;
1697 fb -= (VIDEO_VISIBLE_COLS + width) *
1701 case GDF_24BIT_888RGB:
1706 cte = bmp->color_table[*bmap++];
1707 FILL_24BIT_888RGB(cte.red, cte.green,
1710 bmap += padded_line;
1711 fb -= (VIDEO_VISIBLE_COLS + width) *
1718 padded_line -= 3 * width;
1720 switch (VIDEO_DATA_FORMAT) {
1721 case GDF__8BIT_332RGB:
1726 FILL_8BIT_332RGB(bmap[2], bmap[1],
1730 bmap += padded_line;
1731 fb -= (VIDEO_VISIBLE_COLS + width) *
1735 case GDF_15BIT_555RGB:
1737 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1743 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1744 fill_555rgb_pswap(fb, xpos++, bmap[2],
1748 FILL_15BIT_555RGB(bmap[2], bmap[1],
1753 bmap += padded_line;
1754 fb -= (VIDEO_VISIBLE_COLS + width) *
1758 case GDF_16BIT_565RGB:
1763 FILL_16BIT_565RGB(bmap[2], bmap[1],
1767 bmap += padded_line;
1768 fb -= (VIDEO_VISIBLE_COLS + width) *
1772 case GDF_32BIT_X888RGB:
1777 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1781 bmap += padded_line;
1782 fb -= (VIDEO_VISIBLE_COLS + width) *
1786 case GDF_24BIT_888RGB:
1791 FILL_24BIT_888RGB(bmap[2], bmap[1],
1795 bmap += padded_line;
1796 fb -= (VIDEO_VISIBLE_COLS + width) *
1801 printf("Error: 24 bits/pixel bitmap incompatible "
1802 "with current video mode\n");
1807 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1808 le16_to_cpu(bmp->header.bit_count));
1812 #ifdef CONFIG_VIDEO_BMP_GZIP
1818 if (cfb_do_flush_cache)
1819 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1825 #ifdef CONFIG_VIDEO_LOGO
1826 static int video_logo_xpos;
1827 static int video_logo_ypos;
1829 static void plot_logo_or_black(void *screen, int width, int x, int y, \
1832 static void logo_plot(void *screen, int width, int x, int y)
1834 plot_logo_or_black(screen, width, x, y, 0);
1837 static void logo_black(void)
1839 plot_logo_or_black(video_fb_address, \
1846 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1849 return cmd_usage(cmdtp);
1856 clrlogo, 1, 0, do_clrlogo,
1857 "fill the boot logo area with black",
1861 static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
1865 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
1866 int ycount = video_logo_height;
1867 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1868 unsigned char *source;
1869 unsigned char *dest;
1871 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1872 if (x == BMP_ALIGN_CENTER)
1873 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1875 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
1877 if (y == BMP_ALIGN_CENTER)
1878 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1880 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
1881 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1883 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
1885 #ifdef CONFIG_VIDEO_BMP_LOGO
1886 source = bmp_logo_bitmap;
1888 /* Allocate temporary space for computing colormap */
1889 logo_red = malloc(BMP_LOGO_COLORS);
1890 logo_green = malloc(BMP_LOGO_COLORS);
1891 logo_blue = malloc(BMP_LOGO_COLORS);
1892 /* Compute color map */
1893 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1894 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1895 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1896 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1899 source = linux_logo;
1900 logo_red = linux_logo_red;
1901 logo_green = linux_logo_green;
1902 logo_blue = linux_logo_blue;
1905 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1906 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1907 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1908 logo_red[i], logo_green[i],
1914 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1917 xcount = VIDEO_LOGO_WIDTH;
1924 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1925 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1926 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1929 switch (VIDEO_DATA_FORMAT) {
1930 case GDF__8BIT_INDEX:
1933 case GDF__8BIT_332RGB:
1934 *dest = ((r >> 5) << 5) |
1938 case GDF_15BIT_555RGB:
1939 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1940 fill_555rgb_pswap(dest, xpos++, r, g, b);
1942 *(unsigned short *) dest =
1943 SWAP16((unsigned short) (
1949 case GDF_16BIT_565RGB:
1950 *(unsigned short *) dest =
1951 SWAP16((unsigned short) (
1956 case GDF_32BIT_X888RGB:
1957 *(unsigned long *) dest =
1958 SWAP32((unsigned long) (
1963 case GDF_24BIT_888RGB:
1964 #ifdef VIDEO_FB_LITTLE_ENDIAN
1976 dest += VIDEO_PIXEL_SIZE;
1980 #ifdef CONFIG_VIDEO_BMP_LOGO
1987 static void *video_logo(void)
1991 __maybe_unused int y_off = 0;
1992 __maybe_unused ulong addr;
1993 __maybe_unused char *s;
1995 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1997 #ifdef CONFIG_SPLASH_SCREEN
1998 s = getenv("splashimage");
2000 splash_screen_prepare();
2001 addr = simple_strtoul(s, NULL, 16);
2003 if (video_display_bitmap(addr,
2005 video_logo_ypos) == 0) {
2006 video_logo_height = 0;
2007 return ((void *) (video_fb_address));
2010 #endif /* CONFIG_SPLASH_SCREEN */
2012 logo_plot(video_fb_address, VIDEO_COLS,
2013 video_logo_xpos, video_logo_ypos);
2015 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
2017 * when using splashpos for video_logo, skip any info
2018 * output on video console if the logo is not at 0,0
2020 if (video_logo_xpos || video_logo_ypos) {
2022 * video_logo_height is used in text and cursor offset
2023 * calculations. Since the console is below the logo,
2024 * we need to adjust the logo height
2026 if (video_logo_ypos == BMP_ALIGN_CENTER)
2027 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
2028 VIDEO_LOGO_HEIGHT) / 2);
2029 else if (video_logo_ypos > 0)
2030 video_logo_height += video_logo_ypos;
2032 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2035 if (board_cfb_skip())
2038 sprintf(info, " %s", version_string);
2040 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2044 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2045 (uchar *) info, space);
2046 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2047 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2048 (uchar *) info + space, len - space);
2051 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
2053 #ifdef CONFIG_CONSOLE_EXTRA_INFO
2056 ((video_logo_height -
2057 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
2059 for (i = 1; i < n; i++) {
2060 video_get_info_str(i, info);
2066 video_drawchars(VIDEO_INFO_X,
2070 (uchar *) info, space);
2072 video_drawchars(VIDEO_INFO_X +
2077 (uchar *) info + space,
2080 video_drawstring(VIDEO_INFO_X,
2090 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
2094 static int cfb_fb_is_in_dram(void)
2097 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2098 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2102 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2103 start = bd->bi_dram[i].start;
2104 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2105 if ((ulong)video_fb_address >= start &&
2106 (ulong)video_fb_address < end)
2110 if ((ulong)video_fb_address >= bd->bi_memstart &&
2111 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2117 void video_clear(void)
2119 if (!video_fb_address)
2121 #ifdef VIDEO_HW_RECTFILL
2122 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2125 VIDEO_VISIBLE_COLS, /* frame width */
2126 VIDEO_VISIBLE_ROWS, /* frame height */
2127 bgx /* fill color */
2130 memsetl(video_fb_address,
2131 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2135 static int video_init(void)
2137 unsigned char color8;
2139 pGD = video_hw_init();
2143 video_fb_address = (void *) VIDEO_FB_ADRS;
2144 #ifdef CONFIG_VIDEO_HW_CURSOR
2145 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
2148 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2150 /* Init drawing pats */
2151 switch (VIDEO_DATA_FORMAT) {
2152 case GDF__8BIT_INDEX:
2153 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2155 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2160 case GDF__8BIT_332RGB:
2161 color8 = ((CONSOLE_FG_COL & 0xe0) |
2162 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2163 CONSOLE_FG_COL >> 6);
2164 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2166 color8 = ((CONSOLE_BG_COL & 0xe0) |
2167 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2168 CONSOLE_BG_COL >> 6);
2169 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2172 case GDF_15BIT_555RGB:
2173 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
2174 ((CONSOLE_FG_COL >> 3) << 21) |
2175 ((CONSOLE_FG_COL >> 3) << 16) |
2176 ((CONSOLE_FG_COL >> 3) << 10) |
2177 ((CONSOLE_FG_COL >> 3) << 5) |
2178 (CONSOLE_FG_COL >> 3));
2179 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
2180 ((CONSOLE_BG_COL >> 3) << 21) |
2181 ((CONSOLE_BG_COL >> 3) << 16) |
2182 ((CONSOLE_BG_COL >> 3) << 10) |
2183 ((CONSOLE_BG_COL >> 3) << 5) |
2184 (CONSOLE_BG_COL >> 3));
2186 case GDF_16BIT_565RGB:
2187 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
2188 ((CONSOLE_FG_COL >> 2) << 21) |
2189 ((CONSOLE_FG_COL >> 3) << 16) |
2190 ((CONSOLE_FG_COL >> 3) << 11) |
2191 ((CONSOLE_FG_COL >> 2) << 5) |
2192 (CONSOLE_FG_COL >> 3));
2193 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
2194 ((CONSOLE_BG_COL >> 2) << 21) |
2195 ((CONSOLE_BG_COL >> 3) << 16) |
2196 ((CONSOLE_BG_COL >> 3) << 11) |
2197 ((CONSOLE_BG_COL >> 2) << 5) |
2198 (CONSOLE_BG_COL >> 3));
2200 case GDF_32BIT_X888RGB:
2201 fgx = (CONSOLE_FG_COL << 16) |
2202 (CONSOLE_FG_COL << 8) |
2204 bgx = (CONSOLE_BG_COL << 16) |
2205 (CONSOLE_BG_COL << 8) |
2208 case GDF_24BIT_888RGB:
2209 fgx = (CONSOLE_FG_COL << 24) |
2210 (CONSOLE_FG_COL << 16) |
2211 (CONSOLE_FG_COL << 8) |
2213 bgx = (CONSOLE_BG_COL << 24) |
2214 (CONSOLE_BG_COL << 16) |
2215 (CONSOLE_BG_COL << 8) |
2223 #ifdef CONFIG_VIDEO_LOGO
2224 /* Plot the logo and get start point of console */
2225 debug("Video: Drawing the logo ...\n");
2226 video_console_address = video_logo();
2228 video_console_address = video_fb_address;
2231 /* Initialize the console */
2235 if (cfb_do_flush_cache)
2236 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2242 * Implement a weak default function for boards that optionally
2243 * need to skip the video initialization.
2245 __weak int board_video_skip(void)
2247 /* As default, don't skip test */
2251 int drv_video_init(void)
2254 struct stdio_dev console_dev;
2257 /* Check if video initialization should be skipped */
2258 if (board_video_skip())
2261 /* Init video chip - returns with framebuffer cleared */
2262 skip_dev_init = (video_init() == -1);
2264 if (board_cfb_skip())
2267 #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2268 have_keyboard = false;
2269 #elif defined(CONFIG_OF_CONTROL)
2270 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2271 "u-boot,no-keyboard");
2273 have_keyboard = true;
2275 if (have_keyboard) {
2276 debug("KBD: Keyboard init ...\n");
2277 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2278 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2284 /* Init vga device */
2285 memset(&console_dev, 0, sizeof(console_dev));
2286 strcpy(console_dev.name, "vga");
2287 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2288 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2289 console_dev.putc = video_putc; /* 'putc' function */
2290 console_dev.puts = video_puts; /* 'puts' function */
2292 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2293 if (have_keyboard) {
2294 /* Also init console device */
2295 console_dev.flags |= DEV_FLAGS_INPUT;
2296 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2297 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2301 if (stdio_register(&console_dev) != 0)
2304 /* Return success */
2308 void video_position_cursor(unsigned col, unsigned row)
2310 console_col = min(col, CONSOLE_COLS - 1);
2311 console_row = min(row, CONSOLE_ROWS - 1);
2314 int video_get_pixel_width(void)
2316 return VIDEO_VISIBLE_COLS;
2319 int video_get_pixel_height(void)
2321 return VIDEO_VISIBLE_ROWS;
2324 int video_get_screen_rows(void)
2326 return CONSOLE_ROWS;
2329 int video_get_screen_columns(void)
2331 return CONSOLE_COLS;