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
92 #include <linux/compiler.h>
95 * Console device defines with SMI graphic
96 * Any other graphic must change this section
99 #ifdef CONFIG_VIDEO_SMI_LYNXEM
101 #define VIDEO_FB_LITTLE_ENDIAN
102 #define VIDEO_HW_RECTFILL
103 #define VIDEO_HW_BITBLT
107 * Defines for the CT69000 driver
109 #ifdef CONFIG_VIDEO_CT69000
111 #define VIDEO_FB_LITTLE_ENDIAN
112 #define VIDEO_HW_RECTFILL
113 #define VIDEO_HW_BITBLT
117 * Defines for the SED13806 driver
119 #ifdef CONFIG_VIDEO_SED13806
121 #ifndef CONFIG_TOTAL5200
122 #define VIDEO_FB_LITTLE_ENDIAN
124 #define VIDEO_HW_RECTFILL
125 #define VIDEO_HW_BITBLT
129 * Defines for the SED13806 driver
131 #ifdef CONFIG_VIDEO_SM501
134 #define VIDEO_FB_LITTLE_ENDIAN
138 #ifdef CONFIG_VIDEO_MXS
139 #define VIDEO_FB_16BPP_WORD_SWAP
143 * Defines for the MB862xx driver
145 #ifdef CONFIG_VIDEO_MB862xx
147 #ifdef CONFIG_VIDEO_CORALP
148 #define VIDEO_FB_LITTLE_ENDIAN
150 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
151 #define VIDEO_HW_RECTFILL
152 #define VIDEO_HW_BITBLT
157 * Defines for the i.MX31 driver (mx3fb.c)
159 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
160 #define VIDEO_FB_16BPP_WORD_SWAP
164 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
166 #include <video_fb.h>
173 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
174 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
175 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
176 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
177 #define VIDEO_FB_ADRS (pGD->frameAdrs)
180 * Console device defines with i8042 keyboard controller
181 * Any other keyboard controller must change this section
184 #ifdef CONFIG_I8042_KBD
187 #define VIDEO_KBD_INIT_FCT i8042_kbd_init()
188 #define VIDEO_TSTC_FCT i8042_tstc
189 #define VIDEO_GETC_FCT i8042_getc
197 #include <linux/types.h>
198 #include <stdio_dev.h>
199 #include <video_font.h>
200 #include <video_font_data.h>
202 #if defined(CONFIG_CMD_DATE)
206 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
207 #include <watchdog.h>
208 #include <bmp_layout.h>
214 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
215 * to let the cursor blink. Uses the macros
216 * CURSOR_OFF and CURSOR_ON.
217 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
218 * blinking is provided. Uses the macros CURSOR_SET
220 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
221 * graphic chip. Uses the macro CURSOR_SET.
222 * ATTENTION: If booting an OS, the display driver
223 * must disable the hardware register of the graphic
224 * chip. Otherwise a blinking field is displayed
226 #if !defined(CONFIG_CONSOLE_CURSOR) && \
227 !defined(CONFIG_VIDEO_SW_CURSOR) && \
228 !defined(CONFIG_VIDEO_HW_CURSOR)
229 /* no Cursor defined */
235 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
236 #if defined(CURSOR_ON) || \
237 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
238 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
239 or CONFIG_VIDEO_HW_CURSOR can be defined
241 void console_cursor(int state);
243 #define CURSOR_ON console_cursor(1)
244 #define CURSOR_OFF console_cursor(0)
245 #define CURSOR_SET video_set_cursor()
246 #endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
248 #ifdef CONFIG_CONSOLE_CURSOR
249 #ifndef CONFIG_CONSOLE_TIME
250 #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
252 #ifndef CONFIG_I8042_KBD
253 #warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
255 #endif /* CONFIG_CONSOLE_CURSOR */
258 #ifdef CONFIG_VIDEO_HW_CURSOR
260 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
261 or CONFIG_VIDEO_HW_CURSOR can be defined
265 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
266 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
267 #endif /* CONFIG_VIDEO_HW_CURSOR */
269 #ifdef CONFIG_VIDEO_LOGO
270 #ifdef CONFIG_VIDEO_BMP_LOGO
271 #include <bmp_logo.h>
272 #include <bmp_logo_data.h>
273 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
274 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
275 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
276 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
278 #else /* CONFIG_VIDEO_BMP_LOGO */
279 #define LINUX_LOGO_WIDTH 80
280 #define LINUX_LOGO_HEIGHT 80
281 #define LINUX_LOGO_COLORS 214
282 #define LINUX_LOGO_LUT_OFFSET 0x20
284 #include <linux_logo.h>
285 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
286 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
287 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
288 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
289 #endif /* CONFIG_VIDEO_BMP_LOGO */
290 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
291 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
292 #else /* CONFIG_VIDEO_LOGO */
293 #define VIDEO_LOGO_WIDTH 0
294 #define VIDEO_LOGO_HEIGHT 0
295 #endif /* CONFIG_VIDEO_LOGO */
297 #define VIDEO_COLS VIDEO_VISIBLE_COLS
298 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
299 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
300 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
301 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
302 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
304 #ifdef CONFIG_VIDEO_LOGO
305 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
307 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
310 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
311 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
312 #define CONSOLE_ROW_FIRST (video_console_address)
313 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
314 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
315 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
316 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
319 #ifdef VIDEO_FB_LITTLE_ENDIAN
320 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
323 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
324 (((x) & 0x0000ff00) << 8) | \
325 (((x) & 0x00ff0000) >> 8) | \
326 (((x) & 0xff000000) >> 24) \
328 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
329 (((x) & 0x0000ff00) >> 8) | \
330 (((x) & 0x00ff0000) << 8) | \
331 (((x) & 0xff000000) >> 8) \
334 #define SWAP16(x) (x)
335 #define SWAP32(x) (x)
336 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
337 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
339 #define SHORTSWAP32(x) (x)
343 #ifdef CONFIG_CONSOLE_EXTRA_INFO
345 * setup a board string: type, speed, etc.
347 * line_number: location to place info string beside logo
348 * info: buffer for info string
350 extern void video_get_info_str(int line_number, char *info);
353 DECLARE_GLOBAL_DATA_PTR;
356 static GraphicDevice *pGD; /* Pointer to Graphic array */
358 static void *video_fb_address; /* frame buffer address */
359 static void *video_console_address; /* console buffer start address */
361 static int video_logo_height = VIDEO_LOGO_HEIGHT;
363 static int __maybe_unused cursor_state;
364 static int __maybe_unused old_col;
365 static int __maybe_unused old_row;
367 static int console_col; /* cursor col */
368 static int console_row; /* cursor row */
370 static u32 eorx, fgx, bgx; /* color pats */
372 static int cfb_do_flush_cache;
374 #ifdef CONFIG_CFB_CONSOLE_ANSI
375 static char ansi_buf[10];
376 static int ansi_buf_size;
377 static int ansi_colors_need_revert;
378 static int ansi_cursor_hidden;
381 static const int video_font_draw_table8[] = {
382 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
383 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
384 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
385 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
388 static const int video_font_draw_table15[] = {
389 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
392 static const int video_font_draw_table16[] = {
393 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
396 static const int video_font_draw_table24[16][3] = {
397 {0x00000000, 0x00000000, 0x00000000},
398 {0x00000000, 0x00000000, 0x00ffffff},
399 {0x00000000, 0x0000ffff, 0xff000000},
400 {0x00000000, 0x0000ffff, 0xffffffff},
401 {0x000000ff, 0xffff0000, 0x00000000},
402 {0x000000ff, 0xffff0000, 0x00ffffff},
403 {0x000000ff, 0xffffffff, 0xff000000},
404 {0x000000ff, 0xffffffff, 0xffffffff},
405 {0xffffff00, 0x00000000, 0x00000000},
406 {0xffffff00, 0x00000000, 0x00ffffff},
407 {0xffffff00, 0x0000ffff, 0xff000000},
408 {0xffffff00, 0x0000ffff, 0xffffffff},
409 {0xffffffff, 0xffff0000, 0x00000000},
410 {0xffffffff, 0xffff0000, 0x00ffffff},
411 {0xffffffff, 0xffffffff, 0xff000000},
412 {0xffffffff, 0xffffffff, 0xffffffff}
415 static const int video_font_draw_table32[16][4] = {
416 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
417 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
418 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
419 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
420 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
421 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
422 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
423 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
424 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
425 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
426 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
427 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
428 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
429 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
430 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
431 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
434 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
436 u8 *cdat, *dest, *dest0;
439 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
440 dest0 = video_fb_address + offset;
442 switch (VIDEO_DATA_FORMAT) {
443 case GDF__8BIT_INDEX:
444 case GDF__8BIT_332RGB:
447 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
448 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
449 rows--; dest += VIDEO_LINE_LEN) {
453 (video_font_draw_table8[bits >> 4] &
456 if (VIDEO_FONT_WIDTH == 4)
460 (video_font_draw_table8[bits & 15] &
463 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
468 case GDF_15BIT_555RGB:
471 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
472 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
473 rows--; dest += VIDEO_LINE_LEN) {
477 SHORTSWAP32((video_font_draw_table15
478 [bits >> 6] & eorx) ^
481 SHORTSWAP32((video_font_draw_table15
482 [bits >> 4 & 3] & eorx) ^
485 if (VIDEO_FONT_WIDTH == 4)
489 SHORTSWAP32((video_font_draw_table15
490 [bits >> 2 & 3] & eorx) ^
493 SHORTSWAP32((video_font_draw_table15
497 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
502 case GDF_16BIT_565RGB:
505 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
506 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
507 rows--; dest += VIDEO_LINE_LEN) {
511 SHORTSWAP32((video_font_draw_table16
512 [bits >> 6] & eorx) ^
515 SHORTSWAP32((video_font_draw_table16
516 [bits >> 4 & 3] & eorx) ^
519 if (VIDEO_FONT_WIDTH == 4)
523 SHORTSWAP32((video_font_draw_table16
524 [bits >> 2 & 3] & eorx) ^
527 SHORTSWAP32((video_font_draw_table16
531 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
536 case GDF_32BIT_X888RGB:
539 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
540 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
541 rows--; dest += VIDEO_LINE_LEN) {
545 SWAP32((video_font_draw_table32
546 [bits >> 4][0] & eorx) ^ bgx);
548 SWAP32((video_font_draw_table32
549 [bits >> 4][1] & eorx) ^ bgx);
551 SWAP32((video_font_draw_table32
552 [bits >> 4][2] & eorx) ^ bgx);
554 SWAP32((video_font_draw_table32
555 [bits >> 4][3] & eorx) ^ bgx);
558 if (VIDEO_FONT_WIDTH == 4)
562 SWAP32((video_font_draw_table32
563 [bits & 15][0] & eorx) ^ bgx);
565 SWAP32((video_font_draw_table32
566 [bits & 15][1] & eorx) ^ bgx);
568 SWAP32((video_font_draw_table32
569 [bits & 15][2] & eorx) ^ bgx);
571 SWAP32((video_font_draw_table32
572 [bits & 15][3] & eorx) ^ bgx);
574 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
579 case GDF_24BIT_888RGB:
582 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
583 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
584 rows--; dest += VIDEO_LINE_LEN) {
588 (video_font_draw_table24[bits >> 4][0]
591 (video_font_draw_table24[bits >> 4][1]
594 (video_font_draw_table24[bits >> 4][2]
597 if (VIDEO_FONT_WIDTH == 4)
601 (video_font_draw_table24[bits & 15][0]
604 (video_font_draw_table24[bits & 15][1]
607 (video_font_draw_table24[bits & 15][2]
610 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
617 static inline void video_drawstring(int xx, int yy, unsigned char *s)
619 video_drawchars(xx, yy, s, strlen((char *) s));
622 static void video_putchar(int xx, int yy, unsigned char c)
624 video_drawchars(xx, yy + video_logo_height, &c, 1);
627 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
628 static void video_set_cursor(void)
635 static void video_invertchar(int xx, int yy)
637 int firstx = xx * VIDEO_PIXEL_SIZE;
638 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
639 int firsty = yy * VIDEO_LINE_LEN;
640 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
642 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
643 for (x = firstx; x < lastx; x++) {
644 u8 *dest = (u8 *)(video_fb_address) + x + y;
650 void console_cursor(int state)
652 #ifdef CONFIG_CONSOLE_TIME
656 /* time update only if cursor is on (faster scroll) */
660 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
662 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
663 VIDEO_INFO_Y, (uchar *) info);
665 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
667 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
668 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
673 if (cursor_state != state) {
675 /* turn off the cursor */
676 video_invertchar(old_col * VIDEO_FONT_WIDTH,
677 old_row * VIDEO_FONT_HEIGHT +
680 /* turn off the cursor and record where it is */
681 video_invertchar(console_col * VIDEO_FONT_WIDTH,
682 console_row * VIDEO_FONT_HEIGHT +
684 old_col = console_col;
685 old_row = console_row;
687 cursor_state = state;
689 if (cfb_do_flush_cache)
690 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
694 #ifndef VIDEO_HW_RECTFILL
695 static void memsetl(int *p, int c, int v)
702 #ifndef VIDEO_HW_BITBLT
703 static void memcpyl(int *d, int *s, int c)
710 static void console_clear_line(int line, int begin, int end)
712 #ifdef VIDEO_HW_RECTFILL
713 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
714 VIDEO_FONT_WIDTH * begin, /* dest pos x */
716 VIDEO_FONT_HEIGHT * line, /* dest pos y */
717 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
718 VIDEO_FONT_HEIGHT, /* frame height */
722 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
723 memsetl(CONSOLE_ROW_FIRST +
724 CONSOLE_ROW_SIZE * line, /* offset of row */
725 CONSOLE_ROW_SIZE >> 2, /* length of row */
732 offset = CONSOLE_ROW_FIRST +
733 CONSOLE_ROW_SIZE * line + /* offset of row */
735 VIDEO_PIXEL_SIZE * begin; /* offset of col */
736 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
737 size >>= 2; /* length to end for memsetl() */
738 /* fill at col offset of i'th line using bgx as fill color */
739 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
740 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
745 static void console_scrollup(void)
747 /* copy up rows ignoring the first one */
749 #ifdef VIDEO_HW_BITBLT
750 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
751 0, /* source pos x */
753 VIDEO_FONT_HEIGHT, /* source pos y */
755 video_logo_height, /* dest pos y */
756 VIDEO_VISIBLE_COLS, /* frame width */
759 - VIDEO_FONT_HEIGHT /* frame height */
762 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
763 CONSOLE_SCROLL_SIZE >> 2);
765 /* clear the last one */
766 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
769 static void console_back(void)
773 if (console_col < 0) {
774 console_col = CONSOLE_COLS - 1;
781 #ifdef CONFIG_CFB_CONSOLE_ANSI
783 static void console_clear(void)
785 #ifdef VIDEO_HW_RECTFILL
786 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
788 video_logo_height, /* dest pos y */
789 VIDEO_VISIBLE_COLS, /* frame width */
790 VIDEO_VISIBLE_ROWS, /* frame height */
794 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
798 static void console_cursor_fix(void)
802 if (console_row >= CONSOLE_ROWS)
803 console_row = CONSOLE_ROWS - 1;
806 if (console_col >= CONSOLE_COLS)
807 console_col = CONSOLE_COLS - 1;
810 static void console_cursor_up(int n)
813 console_cursor_fix();
816 static void console_cursor_down(int n)
819 console_cursor_fix();
822 static void console_cursor_left(int n)
825 console_cursor_fix();
828 static void console_cursor_right(int n)
831 console_cursor_fix();
834 static void console_cursor_set_position(int row, int col)
836 if (console_row != -1)
838 if (console_col != -1)
840 console_cursor_fix();
843 static void console_previousline(int n)
845 /* FIXME: also scroll terminal ? */
847 console_cursor_fix();
850 static void console_swap_colors(void)
858 static inline int console_cursor_is_visible(void)
860 return !ansi_cursor_hidden;
863 static inline int console_cursor_is_visible(void)
869 static void console_newline(int n)
874 /* Check if we need to scroll the terminal */
875 if (console_row >= CONSOLE_ROWS) {
876 /* Scroll everything up */
879 /* Decrement row number */
880 console_row = CONSOLE_ROWS - 1;
884 static void console_cr(void)
889 static void parse_putc(const char c)
893 if (console_cursor_is_visible())
897 case 13: /* back to first column */
901 case '\n': /* next line */
902 if (console_col || (!console_col && nl))
908 console_col |= 0x0008;
909 console_col &= ~0x0007;
911 if (console_col >= CONSOLE_COLS)
915 case 8: /* backspace */
922 default: /* draw the char */
923 video_putchar(console_col * VIDEO_FONT_WIDTH,
924 console_row * VIDEO_FONT_HEIGHT, c);
927 /* check for newline */
928 if (console_col >= CONSOLE_COLS) {
934 if (console_cursor_is_visible())
938 void video_putc(const char c)
940 #ifdef CONFIG_CFB_CONSOLE_ANSI
944 for (i = 0; i < ansi_buf_size; ++i)
945 parse_putc(ansi_buf[i]);
951 if (ansi_buf_size > 0) {
971 ansi_buf[ansi_buf_size++] = c;
973 if (ansi_buf_size >= sizeof(ansi_buf))
976 for (i = 0; i < ansi_buf_size; ++i) {
982 if (ansi_buf[i] == 27)
989 if (ansi_buf[i] == '[')
996 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
997 num1 = ansi_buf[i]-'0';
999 } else if (ansi_buf[i] != '?') {
1007 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1009 num1 += ansi_buf[i]-'0';
1017 if (ansi_buf[i] != ';') {
1025 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1026 num2 = ansi_buf[i]-'0';
1033 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1035 num2 += ansi_buf[i]-'0';
1043 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1044 || ansi_buf[i] == 'J'
1045 || ansi_buf[i] == 'K'
1046 || ansi_buf[i] == 'h'
1047 || ansi_buf[i] == 'l'
1048 || ansi_buf[i] == 'm') {
1049 cchar = ansi_buf[i];
1058 for (i = 0; i < ansi_buf_size; ++i)
1059 parse_putc(ansi_buf[i]);
1065 if (!ansi_cursor_hidden)
1070 /* move cursor num1 rows up */
1071 console_cursor_up(num1);
1074 /* move cursor num1 rows down */
1075 console_cursor_down(num1);
1078 /* move cursor num1 columns forward */
1079 console_cursor_right(num1);
1082 /* move cursor num1 columns back */
1083 console_cursor_left(num1);
1086 /* move cursor num1 rows up at begin of row */
1087 console_previousline(num1);
1090 /* move cursor num1 rows down at begin of row */
1091 console_newline(num1);
1094 /* move cursor to column num1 */
1095 console_cursor_set_position(-1, num1-1);
1098 /* move cursor to row num1, column num2 */
1099 console_cursor_set_position(num1-1, num2-1);
1102 /* clear console and move cursor to 0, 0 */
1104 console_cursor_set_position(0, 0);
1109 console_clear_line(console_row,
1113 console_clear_line(console_row,
1116 console_clear_line(console_row,
1120 ansi_cursor_hidden = 0;
1123 ansi_cursor_hidden = 1;
1126 if (num1 == 0) { /* reset swapped colors */
1127 if (ansi_colors_need_revert) {
1128 console_swap_colors();
1129 ansi_colors_need_revert = 0;
1131 } else if (num1 == 7) { /* once swap colors */
1132 if (!ansi_colors_need_revert) {
1133 console_swap_colors();
1134 ansi_colors_need_revert = 1;
1139 if (!ansi_cursor_hidden)
1148 if (cfb_do_flush_cache)
1149 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1152 void video_puts(const char *s)
1154 int count = strlen(s);
1161 * Do not enforce drivers (or board code) to provide empty
1162 * video_set_lut() if they do not support 8 bpp format.
1163 * Implement weak default function instead.
1165 void __video_set_lut(unsigned int index, unsigned char r,
1166 unsigned char g, unsigned char b)
1170 void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
1171 __attribute__ ((weak, alias("__video_set_lut")));
1173 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1175 #define FILL_8BIT_332RGB(r,g,b) { \
1176 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1180 #define FILL_15BIT_555RGB(r,g,b) { \
1181 *(unsigned short *)fb = \
1182 SWAP16((unsigned short)(((r>>3)<<10) | \
1188 #define FILL_16BIT_565RGB(r,g,b) { \
1189 *(unsigned short *)fb = \
1190 SWAP16((unsigned short)((((r)>>3)<<11)| \
1196 #define FILL_32BIT_X888RGB(r,g,b) { \
1197 *(unsigned long *)fb = \
1198 SWAP32((unsigned long)(((r<<16) | \
1204 #ifdef VIDEO_FB_LITTLE_ENDIAN
1205 #define FILL_24BIT_888RGB(r,g,b) { \
1212 #define FILL_24BIT_888RGB(r,g,b) { \
1220 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1221 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1223 ushort *dst = (ushort *) fb;
1224 ushort color = (ushort) (((r >> 3) << 10) |
1235 * RLE8 bitmap support
1238 #ifdef CONFIG_VIDEO_BMP_RLE8
1239 /* Pre-calculated color table entry */
1242 unsigned short w; /* word */
1243 unsigned int dw; /* double word */
1244 } ce; /* color entry */
1248 * Helper to draw encoded/unencoded run.
1250 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1253 ulong addr = (ulong) *fb;
1259 * Setup offset of the color index in the bitmap.
1260 * Color index of encoded run is at offset 1.
1262 off = enc ? &enc_off : &i;
1264 switch (VIDEO_DATA_FORMAT) {
1265 case GDF__8BIT_INDEX:
1266 for (i = 0; i < cnt; i++)
1267 *(unsigned char *) addr++ = bm[*off];
1269 case GDF_15BIT_555RGB:
1270 case GDF_16BIT_565RGB:
1271 /* differences handled while pre-calculating palette */
1272 for (i = 0; i < cnt; i++) {
1273 *(unsigned short *) addr = p[bm[*off]].ce.w;
1277 case GDF_32BIT_X888RGB:
1278 for (i = 0; i < cnt; i++) {
1279 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1284 *fb = (uchar *) addr; /* return modified address */
1287 static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1288 int width, int height)
1292 unsigned int cnt, runlen;
1294 int x, y, bpp, i, ncolors;
1295 struct palette p[256];
1296 bmp_color_table_entry_t cte;
1297 int green_shift, red_off;
1298 int limit = VIDEO_COLS * VIDEO_ROWS;
1302 y = __le32_to_cpu(img->header.height) - 1;
1303 ncolors = __le32_to_cpu(img->header.colors_used);
1304 bpp = VIDEO_PIXEL_SIZE;
1305 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1306 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
1308 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1310 /* pre-calculate and setup palette */
1311 switch (VIDEO_DATA_FORMAT) {
1312 case GDF__8BIT_INDEX:
1313 for (i = 0; i < ncolors; i++) {
1314 cte = img->color_table[i];
1315 video_set_lut(i, cte.red, cte.green, cte.blue);
1318 case GDF_15BIT_555RGB:
1319 case GDF_16BIT_565RGB:
1320 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1327 for (i = 0; i < ncolors; i++) {
1328 cte = img->color_table[i];
1329 p[i].ce.w = SWAP16((unsigned short)
1330 (((cte.red >> 3) << red_off) |
1331 ((cte.green >> green_shift) << 5) |
1335 case GDF_32BIT_X888RGB:
1336 for (i = 0; i < ncolors; i++) {
1337 cte = img->color_table[i];
1338 p[i].ce.dw = SWAP32((cte.red << 16) |
1344 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1354 /* scan line end marker */
1358 fbp = (unsigned char *)
1359 ((unsigned int) video_fb_address +
1360 (((y + yoff) * VIDEO_COLS) +
1364 /* end of bitmap data marker */
1368 /* run offset marker */
1371 fbp = (unsigned char *)
1372 ((unsigned int) video_fb_address +
1373 (((y + yoff) * VIDEO_COLS) +
1391 if (x + runlen > width)
1393 draw_bitmap(&fbp, bm, p, cnt, 0);
1399 bm++; /* 0 padding if length is odd */
1410 if (y < height) { /* only draw into visible area */
1416 if (x + runlen > width)
1418 draw_bitmap(&fbp, bm, p, cnt, 1);
1427 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1433 * Display the BMP file located at address bmp_image.
1435 int video_display_bitmap(ulong bmp_image, int x, int y)
1437 ushort xcount, ycount;
1439 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1442 unsigned long width, height, bpp;
1444 unsigned long compression;
1445 bmp_color_table_entry_t cte;
1447 #ifdef CONFIG_VIDEO_BMP_GZIP
1448 unsigned char *dst = NULL;
1454 if (!((bmp->header.signature[0] == 'B') &&
1455 (bmp->header.signature[1] == 'M'))) {
1457 #ifdef CONFIG_VIDEO_BMP_GZIP
1459 * Could be a gzipped bmp image, try to decrompress...
1461 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1462 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1464 printf("Error: malloc in gunzip failed!\n");
1467 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1468 (uchar *) bmp_image,
1470 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1475 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1476 printf("Image could be truncated "
1477 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1481 * Set addr to decompressed image
1483 bmp = (bmp_image_t *) dst;
1485 if (!((bmp->header.signature[0] == 'B') &&
1486 (bmp->header.signature[1] == 'M'))) {
1487 printf("Error: no valid bmp.gz image at %lx\n",
1493 printf("Error: no valid bmp image at %lx\n", bmp_image);
1495 #endif /* CONFIG_VIDEO_BMP_GZIP */
1498 width = le32_to_cpu(bmp->header.width);
1499 height = le32_to_cpu(bmp->header.height);
1500 bpp = le16_to_cpu(bmp->header.bit_count);
1501 colors = le32_to_cpu(bmp->header.colors_used);
1502 compression = le32_to_cpu(bmp->header.compression);
1504 debug("Display-bmp: %ld x %ld with %d colors\n",
1505 width, height, colors);
1507 if (compression != BMP_BI_RGB
1508 #ifdef CONFIG_VIDEO_BMP_RLE8
1509 && compression != BMP_BI_RLE8
1512 printf("Error: compression type %ld not supported\n",
1514 #ifdef CONFIG_VIDEO_BMP_GZIP
1521 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1523 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1524 if (x == BMP_ALIGN_CENTER)
1525 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1527 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1529 if (y == BMP_ALIGN_CENTER)
1530 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1532 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1533 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1536 * Just ignore elements which are completely beyond screen
1539 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1542 if ((x + width) > VIDEO_VISIBLE_COLS)
1543 width = VIDEO_VISIBLE_COLS - x;
1544 if ((y + height) > VIDEO_VISIBLE_ROWS)
1545 height = VIDEO_VISIBLE_ROWS - y;
1547 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1548 fb = (uchar *) (video_fb_address +
1549 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1550 x * VIDEO_PIXEL_SIZE);
1552 #ifdef CONFIG_VIDEO_BMP_RLE8
1553 if (compression == BMP_BI_RLE8) {
1554 return display_rle8_bitmap(bmp, x, y, width, height);
1558 /* We handle only 4, 8, or 24 bpp bitmaps */
1559 switch (le16_to_cpu(bmp->header.bit_count)) {
1561 padded_line -= width / 2;
1564 switch (VIDEO_DATA_FORMAT) {
1565 case GDF_32BIT_X888RGB:
1569 * Don't assume that 'width' is an
1572 for (xcount = 0; xcount < width; xcount++) {
1580 cte = bmp->color_table[idx];
1581 FILL_32BIT_X888RGB(cte.red, cte.green,
1584 bmap += padded_line;
1585 fb -= (VIDEO_VISIBLE_COLS + width) *
1590 puts("4bpp bitmap unsupported with current "
1597 padded_line -= width;
1598 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1600 for (xcount = 0; xcount < colors; ++xcount) {
1601 cte = bmp->color_table[xcount];
1602 video_set_lut(xcount, cte.red, cte.green,
1607 switch (VIDEO_DATA_FORMAT) {
1608 case GDF__8BIT_INDEX:
1615 bmap += padded_line;
1616 fb -= (VIDEO_VISIBLE_COLS + width) *
1620 case GDF__8BIT_332RGB:
1625 cte = bmp->color_table[*bmap++];
1626 FILL_8BIT_332RGB(cte.red, cte.green,
1629 bmap += padded_line;
1630 fb -= (VIDEO_VISIBLE_COLS + width) *
1634 case GDF_15BIT_555RGB:
1636 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1642 cte = bmp->color_table[*bmap++];
1643 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1644 fill_555rgb_pswap(fb, xpos++, cte.red,
1649 FILL_15BIT_555RGB(cte.red, cte.green,
1653 bmap += padded_line;
1654 fb -= (VIDEO_VISIBLE_COLS + width) *
1658 case GDF_16BIT_565RGB:
1663 cte = bmp->color_table[*bmap++];
1664 FILL_16BIT_565RGB(cte.red, cte.green,
1667 bmap += padded_line;
1668 fb -= (VIDEO_VISIBLE_COLS + width) *
1672 case GDF_32BIT_X888RGB:
1677 cte = bmp->color_table[*bmap++];
1678 FILL_32BIT_X888RGB(cte.red, cte.green,
1681 bmap += padded_line;
1682 fb -= (VIDEO_VISIBLE_COLS + width) *
1686 case GDF_24BIT_888RGB:
1691 cte = bmp->color_table[*bmap++];
1692 FILL_24BIT_888RGB(cte.red, cte.green,
1695 bmap += padded_line;
1696 fb -= (VIDEO_VISIBLE_COLS + width) *
1703 padded_line -= 3 * width;
1705 switch (VIDEO_DATA_FORMAT) {
1706 case GDF__8BIT_332RGB:
1711 FILL_8BIT_332RGB(bmap[2], bmap[1],
1715 bmap += padded_line;
1716 fb -= (VIDEO_VISIBLE_COLS + width) *
1720 case GDF_15BIT_555RGB:
1722 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1728 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1729 fill_555rgb_pswap(fb, xpos++, bmap[2],
1733 FILL_15BIT_555RGB(bmap[2], bmap[1],
1738 bmap += padded_line;
1739 fb -= (VIDEO_VISIBLE_COLS + width) *
1743 case GDF_16BIT_565RGB:
1748 FILL_16BIT_565RGB(bmap[2], bmap[1],
1752 bmap += padded_line;
1753 fb -= (VIDEO_VISIBLE_COLS + width) *
1757 case GDF_32BIT_X888RGB:
1762 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1766 bmap += padded_line;
1767 fb -= (VIDEO_VISIBLE_COLS + width) *
1771 case GDF_24BIT_888RGB:
1776 FILL_24BIT_888RGB(bmap[2], bmap[1],
1780 bmap += padded_line;
1781 fb -= (VIDEO_VISIBLE_COLS + width) *
1786 printf("Error: 24 bits/pixel bitmap incompatible "
1787 "with current video mode\n");
1792 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1793 le16_to_cpu(bmp->header.bit_count));
1797 #ifdef CONFIG_VIDEO_BMP_GZIP
1803 if (cfb_do_flush_cache)
1804 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1810 #ifdef CONFIG_VIDEO_LOGO
1811 static int video_logo_xpos;
1812 static int video_logo_ypos;
1814 static void plot_logo_or_black(void *screen, int width, int x, int y, \
1817 static void logo_plot(void *screen, int width, int x, int y)
1819 plot_logo_or_black(screen, width, x, y, 0);
1822 static void logo_black(void)
1824 plot_logo_or_black(video_fb_address, \
1831 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1834 return cmd_usage(cmdtp);
1841 clrlogo, 1, 0, do_clrlogo,
1842 "fill the boot logo area with black",
1846 static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
1850 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
1851 int ycount = video_logo_height;
1852 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1853 unsigned char *source;
1854 unsigned char *dest;
1856 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1857 if (x == BMP_ALIGN_CENTER)
1858 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1860 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1862 if (y == BMP_ALIGN_CENTER)
1863 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1865 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1866 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1868 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
1870 #ifdef CONFIG_VIDEO_BMP_LOGO
1871 source = bmp_logo_bitmap;
1873 /* Allocate temporary space for computing colormap */
1874 logo_red = malloc(BMP_LOGO_COLORS);
1875 logo_green = malloc(BMP_LOGO_COLORS);
1876 logo_blue = malloc(BMP_LOGO_COLORS);
1877 /* Compute color map */
1878 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1879 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1880 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1881 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1884 source = linux_logo;
1885 logo_red = linux_logo_red;
1886 logo_green = linux_logo_green;
1887 logo_blue = linux_logo_blue;
1890 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1891 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1892 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1893 logo_red[i], logo_green[i],
1899 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1902 xcount = VIDEO_LOGO_WIDTH;
1909 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1910 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1911 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1914 switch (VIDEO_DATA_FORMAT) {
1915 case GDF__8BIT_INDEX:
1918 case GDF__8BIT_332RGB:
1919 *dest = ((r >> 5) << 5) |
1923 case GDF_15BIT_555RGB:
1924 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1925 fill_555rgb_pswap(dest, xpos++, r, g, b);
1927 *(unsigned short *) dest =
1928 SWAP16((unsigned short) (
1934 case GDF_16BIT_565RGB:
1935 *(unsigned short *) dest =
1936 SWAP16((unsigned short) (
1941 case GDF_32BIT_X888RGB:
1942 *(unsigned long *) dest =
1943 SWAP32((unsigned long) (
1948 case GDF_24BIT_888RGB:
1949 #ifdef VIDEO_FB_LITTLE_ENDIAN
1961 dest += VIDEO_PIXEL_SIZE;
1965 #ifdef CONFIG_VIDEO_BMP_LOGO
1972 static void *video_logo(void)
1976 __maybe_unused int y_off = 0;
1977 __maybe_unused ulong addr;
1978 __maybe_unused char *s;
1980 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1982 #ifdef CONFIG_SPLASH_SCREEN
1983 s = getenv("splashimage");
1985 splash_screen_prepare();
1986 addr = simple_strtoul(s, NULL, 16);
1988 if (video_display_bitmap(addr,
1990 video_logo_ypos) == 0) {
1991 video_logo_height = 0;
1992 return ((void *) (video_fb_address));
1995 #endif /* CONFIG_SPLASH_SCREEN */
1997 logo_plot(video_fb_address, VIDEO_COLS,
1998 video_logo_xpos, video_logo_ypos);
2000 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
2002 * when using splashpos for video_logo, skip any info
2003 * output on video console if the logo is not at 0,0
2005 if (video_logo_xpos || video_logo_ypos) {
2007 * video_logo_height is used in text and cursor offset
2008 * calculations. Since the console is below the logo,
2009 * we need to adjust the logo height
2011 if (video_logo_ypos == BMP_ALIGN_CENTER)
2012 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
2013 VIDEO_LOGO_HEIGHT) / 2);
2014 else if (video_logo_ypos > 0)
2015 video_logo_height += video_logo_ypos;
2017 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2021 sprintf(info, " %s", version_string);
2023 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2027 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2028 (uchar *) info, space);
2029 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2030 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2031 (uchar *) info + space, len - space);
2034 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
2036 #ifdef CONFIG_CONSOLE_EXTRA_INFO
2039 ((video_logo_height -
2040 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
2042 for (i = 1; i < n; i++) {
2043 video_get_info_str(i, info);
2049 video_drawchars(VIDEO_INFO_X,
2053 (uchar *) info, space);
2055 video_drawchars(VIDEO_INFO_X +
2060 (uchar *) info + space,
2063 video_drawstring(VIDEO_INFO_X,
2073 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
2077 static int cfb_fb_is_in_dram(void)
2080 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2081 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2085 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2086 start = bd->bi_dram[i].start;
2087 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2088 if ((ulong)video_fb_address >= start &&
2089 (ulong)video_fb_address < end)
2093 if ((ulong)video_fb_address >= bd->bi_memstart &&
2094 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2100 static int video_init(void)
2102 unsigned char color8;
2104 pGD = video_hw_init();
2108 video_fb_address = (void *) VIDEO_FB_ADRS;
2109 #ifdef CONFIG_VIDEO_HW_CURSOR
2110 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
2113 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2115 /* Init drawing pats */
2116 switch (VIDEO_DATA_FORMAT) {
2117 case GDF__8BIT_INDEX:
2118 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2120 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2125 case GDF__8BIT_332RGB:
2126 color8 = ((CONSOLE_FG_COL & 0xe0) |
2127 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2128 CONSOLE_FG_COL >> 6);
2129 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2131 color8 = ((CONSOLE_BG_COL & 0xe0) |
2132 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2133 CONSOLE_BG_COL >> 6);
2134 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2137 case GDF_15BIT_555RGB:
2138 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
2139 ((CONSOLE_FG_COL >> 3) << 21) |
2140 ((CONSOLE_FG_COL >> 3) << 16) |
2141 ((CONSOLE_FG_COL >> 3) << 10) |
2142 ((CONSOLE_FG_COL >> 3) << 5) |
2143 (CONSOLE_FG_COL >> 3));
2144 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
2145 ((CONSOLE_BG_COL >> 3) << 21) |
2146 ((CONSOLE_BG_COL >> 3) << 16) |
2147 ((CONSOLE_BG_COL >> 3) << 10) |
2148 ((CONSOLE_BG_COL >> 3) << 5) |
2149 (CONSOLE_BG_COL >> 3));
2151 case GDF_16BIT_565RGB:
2152 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
2153 ((CONSOLE_FG_COL >> 2) << 21) |
2154 ((CONSOLE_FG_COL >> 3) << 16) |
2155 ((CONSOLE_FG_COL >> 3) << 11) |
2156 ((CONSOLE_FG_COL >> 2) << 5) |
2157 (CONSOLE_FG_COL >> 3));
2158 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
2159 ((CONSOLE_BG_COL >> 2) << 21) |
2160 ((CONSOLE_BG_COL >> 3) << 16) |
2161 ((CONSOLE_BG_COL >> 3) << 11) |
2162 ((CONSOLE_BG_COL >> 2) << 5) |
2163 (CONSOLE_BG_COL >> 3));
2165 case GDF_32BIT_X888RGB:
2166 fgx = (CONSOLE_FG_COL << 16) |
2167 (CONSOLE_FG_COL << 8) |
2169 bgx = (CONSOLE_BG_COL << 16) |
2170 (CONSOLE_BG_COL << 8) |
2173 case GDF_24BIT_888RGB:
2174 fgx = (CONSOLE_FG_COL << 24) |
2175 (CONSOLE_FG_COL << 16) |
2176 (CONSOLE_FG_COL << 8) |
2178 bgx = (CONSOLE_BG_COL << 24) |
2179 (CONSOLE_BG_COL << 16) |
2180 (CONSOLE_BG_COL << 8) |
2186 #ifdef CONFIG_VIDEO_LOGO
2187 /* Plot the logo and get start point of console */
2188 debug("Video: Drawing the logo ...\n");
2189 video_console_address = video_logo();
2191 video_console_address = video_fb_address;
2194 /* Initialize the console */
2198 if (cfb_do_flush_cache)
2199 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2205 * Implement a weak default function for boards that optionally
2206 * need to skip the video initialization.
2208 int __board_video_skip(void)
2210 /* As default, don't skip test */
2214 int board_video_skip(void)
2215 __attribute__ ((weak, alias("__board_video_skip")));
2217 int drv_video_init(void)
2220 struct stdio_dev console_dev;
2222 /* Check if video initialization should be skipped */
2223 if (board_video_skip())
2226 /* Init video chip - returns with framebuffer cleared */
2227 skip_dev_init = (video_init() == -1);
2229 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2230 debug("KBD: Keyboard init ...\n");
2231 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2237 /* Init vga device */
2238 memset(&console_dev, 0, sizeof(console_dev));
2239 strcpy(console_dev.name, "vga");
2240 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2241 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2242 console_dev.putc = video_putc; /* 'putc' function */
2243 console_dev.puts = video_puts; /* 'puts' function */
2244 console_dev.tstc = NULL; /* 'tstc' function */
2245 console_dev.getc = NULL; /* 'getc' function */
2247 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2248 /* Also init console device */
2249 console_dev.flags |= DEV_FLAGS_INPUT;
2250 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2251 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2252 #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
2254 if (stdio_register(&console_dev) != 0)
2257 /* Return success */
2261 void video_position_cursor(unsigned col, unsigned row)
2263 console_col = min(col, CONSOLE_COLS - 1);
2264 console_row = min(row, CONSOLE_ROWS - 1);
2267 int video_get_pixel_width(void)
2269 return VIDEO_VISIBLE_COLS;
2272 int video_get_pixel_height(void)
2274 return VIDEO_VISIBLE_ROWS;
2277 int video_get_screen_rows(void)
2279 return CONSOLE_ROWS;
2282 int video_get_screen_columns(void)
2284 return CONSOLE_COLS;
2287 void video_clear(void)
2289 if (!video_fb_address)
2291 #ifdef VIDEO_HW_RECTFILL
2292 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2295 VIDEO_VISIBLE_COLS, /* frame width */
2296 VIDEO_VISIBLE_ROWS, /* frame height */
2297 bgx /* fill color */
2300 memsetl(video_fb_address,
2301 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);