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>
201 #if defined(CONFIG_CMD_DATE)
205 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
206 #include <watchdog.h>
207 #include <bmp_layout.h>
213 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
214 * to let the cursor blink. Uses the macros
215 * CURSOR_OFF and CURSOR_ON.
216 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
217 * blinking is provided. Uses the macros CURSOR_SET
219 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
220 * graphic chip. Uses the macro CURSOR_SET.
221 * ATTENTION: If booting an OS, the display driver
222 * must disable the hardware register of the graphic
223 * chip. Otherwise a blinking field is displayed
225 #if !defined(CONFIG_CONSOLE_CURSOR) && \
226 !defined(CONFIG_VIDEO_SW_CURSOR) && \
227 !defined(CONFIG_VIDEO_HW_CURSOR)
228 /* no Cursor defined */
234 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
235 #if defined(CURSOR_ON) || \
236 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
237 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
238 or CONFIG_VIDEO_HW_CURSOR can be defined
240 void console_cursor(int state);
242 #define CURSOR_ON console_cursor(1)
243 #define CURSOR_OFF console_cursor(0)
244 #define CURSOR_SET video_set_cursor()
245 #endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
247 #ifdef CONFIG_CONSOLE_CURSOR
248 #ifndef CONFIG_CONSOLE_TIME
249 #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
251 #ifndef CONFIG_I8042_KBD
252 #warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
254 #endif /* CONFIG_CONSOLE_CURSOR */
257 #ifdef CONFIG_VIDEO_HW_CURSOR
259 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
260 or CONFIG_VIDEO_HW_CURSOR can be defined
264 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
265 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
266 #endif /* CONFIG_VIDEO_HW_CURSOR */
268 #ifdef CONFIG_VIDEO_LOGO
269 #ifdef CONFIG_VIDEO_BMP_LOGO
270 #include <bmp_logo.h>
271 #include <bmp_logo_data.h>
272 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
273 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
274 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
275 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
277 #else /* CONFIG_VIDEO_BMP_LOGO */
278 #define LINUX_LOGO_WIDTH 80
279 #define LINUX_LOGO_HEIGHT 80
280 #define LINUX_LOGO_COLORS 214
281 #define LINUX_LOGO_LUT_OFFSET 0x20
283 #include <linux_logo.h>
284 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
285 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
286 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
287 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
288 #endif /* CONFIG_VIDEO_BMP_LOGO */
289 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
290 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
291 #else /* CONFIG_VIDEO_LOGO */
292 #define VIDEO_LOGO_WIDTH 0
293 #define VIDEO_LOGO_HEIGHT 0
294 #endif /* CONFIG_VIDEO_LOGO */
296 #define VIDEO_COLS VIDEO_VISIBLE_COLS
297 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
298 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
299 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
300 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
301 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
303 #ifdef CONFIG_VIDEO_LOGO
304 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
306 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
309 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
310 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
311 #define CONSOLE_ROW_FIRST (video_console_address)
312 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
313 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
314 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
315 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
318 #ifdef VIDEO_FB_LITTLE_ENDIAN
319 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
322 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
323 (((x) & 0x0000ff00) << 8) | \
324 (((x) & 0x00ff0000) >> 8) | \
325 (((x) & 0xff000000) >> 24) \
327 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
328 (((x) & 0x0000ff00) >> 8) | \
329 (((x) & 0x00ff0000) << 8) | \
330 (((x) & 0xff000000) >> 8) \
333 #define SWAP16(x) (x)
334 #define SWAP32(x) (x)
335 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
336 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
338 #define SHORTSWAP32(x) (x)
342 #ifdef CONFIG_CONSOLE_EXTRA_INFO
344 * setup a board string: type, speed, etc.
346 * line_number: location to place info string beside logo
347 * info: buffer for info string
349 extern void video_get_info_str(int line_number, char *info);
352 DECLARE_GLOBAL_DATA_PTR;
355 static GraphicDevice *pGD; /* Pointer to Graphic array */
357 static void *video_fb_address; /* frame buffer address */
358 static void *video_console_address; /* console buffer start address */
360 static int video_logo_height = VIDEO_LOGO_HEIGHT;
362 static int __maybe_unused cursor_state;
363 static int __maybe_unused old_col;
364 static int __maybe_unused old_row;
366 static int console_col; /* cursor col */
367 static int console_row; /* cursor row */
369 static u32 eorx, fgx, bgx; /* color pats */
371 static int cfb_do_flush_cache;
373 #ifdef CONFIG_CFB_CONSOLE_ANSI
374 static char ansi_buf[10];
375 static int ansi_buf_size;
376 static int ansi_colors_need_revert;
377 static int ansi_cursor_hidden;
380 static const int video_font_draw_table8[] = {
381 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
382 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
383 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
384 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
387 static const int video_font_draw_table15[] = {
388 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
391 static const int video_font_draw_table16[] = {
392 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
395 static const int video_font_draw_table24[16][3] = {
396 {0x00000000, 0x00000000, 0x00000000},
397 {0x00000000, 0x00000000, 0x00ffffff},
398 {0x00000000, 0x0000ffff, 0xff000000},
399 {0x00000000, 0x0000ffff, 0xffffffff},
400 {0x000000ff, 0xffff0000, 0x00000000},
401 {0x000000ff, 0xffff0000, 0x00ffffff},
402 {0x000000ff, 0xffffffff, 0xff000000},
403 {0x000000ff, 0xffffffff, 0xffffffff},
404 {0xffffff00, 0x00000000, 0x00000000},
405 {0xffffff00, 0x00000000, 0x00ffffff},
406 {0xffffff00, 0x0000ffff, 0xff000000},
407 {0xffffff00, 0x0000ffff, 0xffffffff},
408 {0xffffffff, 0xffff0000, 0x00000000},
409 {0xffffffff, 0xffff0000, 0x00ffffff},
410 {0xffffffff, 0xffffffff, 0xff000000},
411 {0xffffffff, 0xffffffff, 0xffffffff}
414 static const int video_font_draw_table32[16][4] = {
415 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
416 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
417 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
418 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
419 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
420 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
421 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
422 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
423 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
424 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
425 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
426 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
427 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
428 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
429 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
430 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
434 * Implement a weak default function for boards that optionally
435 * need to skip the cfb initialization.
437 __weak int board_cfb_skip(void)
439 /* As default, don't skip cfb init */
443 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
445 u8 *cdat, *dest, *dest0;
448 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
449 dest0 = video_fb_address + offset;
451 switch (VIDEO_DATA_FORMAT) {
452 case GDF__8BIT_INDEX:
453 case GDF__8BIT_332RGB:
456 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
457 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
458 rows--; dest += VIDEO_LINE_LEN) {
462 (video_font_draw_table8[bits >> 4] &
465 if (VIDEO_FONT_WIDTH == 4)
469 (video_font_draw_table8[bits & 15] &
472 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
477 case GDF_15BIT_555RGB:
480 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
481 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
482 rows--; dest += VIDEO_LINE_LEN) {
486 SHORTSWAP32((video_font_draw_table15
487 [bits >> 6] & eorx) ^
490 SHORTSWAP32((video_font_draw_table15
491 [bits >> 4 & 3] & eorx) ^
494 if (VIDEO_FONT_WIDTH == 4)
498 SHORTSWAP32((video_font_draw_table15
499 [bits >> 2 & 3] & eorx) ^
502 SHORTSWAP32((video_font_draw_table15
506 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
511 case GDF_16BIT_565RGB:
514 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
515 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
516 rows--; dest += VIDEO_LINE_LEN) {
520 SHORTSWAP32((video_font_draw_table16
521 [bits >> 6] & eorx) ^
524 SHORTSWAP32((video_font_draw_table16
525 [bits >> 4 & 3] & eorx) ^
528 if (VIDEO_FONT_WIDTH == 4)
532 SHORTSWAP32((video_font_draw_table16
533 [bits >> 2 & 3] & eorx) ^
536 SHORTSWAP32((video_font_draw_table16
540 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
545 case GDF_32BIT_X888RGB:
548 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
549 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
550 rows--; dest += VIDEO_LINE_LEN) {
554 SWAP32((video_font_draw_table32
555 [bits >> 4][0] & eorx) ^ bgx);
557 SWAP32((video_font_draw_table32
558 [bits >> 4][1] & eorx) ^ bgx);
560 SWAP32((video_font_draw_table32
561 [bits >> 4][2] & eorx) ^ bgx);
563 SWAP32((video_font_draw_table32
564 [bits >> 4][3] & eorx) ^ bgx);
567 if (VIDEO_FONT_WIDTH == 4)
571 SWAP32((video_font_draw_table32
572 [bits & 15][0] & eorx) ^ bgx);
574 SWAP32((video_font_draw_table32
575 [bits & 15][1] & eorx) ^ bgx);
577 SWAP32((video_font_draw_table32
578 [bits & 15][2] & eorx) ^ bgx);
580 SWAP32((video_font_draw_table32
581 [bits & 15][3] & eorx) ^ bgx);
583 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
588 case GDF_24BIT_888RGB:
591 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
592 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
593 rows--; dest += VIDEO_LINE_LEN) {
597 (video_font_draw_table24[bits >> 4][0]
600 (video_font_draw_table24[bits >> 4][1]
603 (video_font_draw_table24[bits >> 4][2]
606 if (VIDEO_FONT_WIDTH == 4)
610 (video_font_draw_table24[bits & 15][0]
613 (video_font_draw_table24[bits & 15][1]
616 (video_font_draw_table24[bits & 15][2]
619 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
626 static inline void video_drawstring(int xx, int yy, unsigned char *s)
628 video_drawchars(xx, yy, s, strlen((char *) s));
631 static void video_putchar(int xx, int yy, unsigned char c)
633 video_drawchars(xx, yy + video_logo_height, &c, 1);
636 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
637 static void video_set_cursor(void)
644 static void video_invertchar(int xx, int yy)
646 int firstx = xx * VIDEO_PIXEL_SIZE;
647 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
648 int firsty = yy * VIDEO_LINE_LEN;
649 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
651 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
652 for (x = firstx; x < lastx; x++) {
653 u8 *dest = (u8 *)(video_fb_address) + x + y;
659 void console_cursor(int state)
661 #ifdef CONFIG_CONSOLE_TIME
665 /* time update only if cursor is on (faster scroll) */
669 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
671 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
672 VIDEO_INFO_Y, (uchar *) info);
674 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
676 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
677 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
682 if (cursor_state != state) {
684 /* turn off the cursor */
685 video_invertchar(old_col * VIDEO_FONT_WIDTH,
686 old_row * VIDEO_FONT_HEIGHT +
689 /* turn off the cursor and record where it is */
690 video_invertchar(console_col * VIDEO_FONT_WIDTH,
691 console_row * VIDEO_FONT_HEIGHT +
693 old_col = console_col;
694 old_row = console_row;
696 cursor_state = state;
698 if (cfb_do_flush_cache)
699 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
703 #ifndef VIDEO_HW_RECTFILL
704 static void memsetl(int *p, int c, int v)
711 #ifndef VIDEO_HW_BITBLT
712 static void memcpyl(int *d, int *s, int c)
719 static void console_clear_line(int line, int begin, int end)
721 #ifdef VIDEO_HW_RECTFILL
722 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
723 VIDEO_FONT_WIDTH * begin, /* dest pos x */
725 VIDEO_FONT_HEIGHT * line, /* dest pos y */
726 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
727 VIDEO_FONT_HEIGHT, /* frame height */
731 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
732 memsetl(CONSOLE_ROW_FIRST +
733 CONSOLE_ROW_SIZE * line, /* offset of row */
734 CONSOLE_ROW_SIZE >> 2, /* length of row */
741 offset = CONSOLE_ROW_FIRST +
742 CONSOLE_ROW_SIZE * line + /* offset of row */
744 VIDEO_PIXEL_SIZE * begin; /* offset of col */
745 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
746 size >>= 2; /* length to end for memsetl() */
747 /* fill at col offset of i'th line using bgx as fill color */
748 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
749 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
754 static void console_scrollup(void)
756 /* copy up rows ignoring the first one */
758 #ifdef VIDEO_HW_BITBLT
759 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
760 0, /* source pos x */
762 VIDEO_FONT_HEIGHT, /* source pos y */
764 video_logo_height, /* dest pos y */
765 VIDEO_VISIBLE_COLS, /* frame width */
768 - VIDEO_FONT_HEIGHT /* frame height */
771 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
772 CONSOLE_SCROLL_SIZE >> 2);
774 /* clear the last one */
775 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
778 static void console_back(void)
782 if (console_col < 0) {
783 console_col = CONSOLE_COLS - 1;
790 #ifdef CONFIG_CFB_CONSOLE_ANSI
792 static void console_clear(void)
794 #ifdef VIDEO_HW_RECTFILL
795 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
797 video_logo_height, /* dest pos y */
798 VIDEO_VISIBLE_COLS, /* frame width */
799 VIDEO_VISIBLE_ROWS, /* frame height */
803 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
807 static void console_cursor_fix(void)
811 if (console_row >= CONSOLE_ROWS)
812 console_row = CONSOLE_ROWS - 1;
815 if (console_col >= CONSOLE_COLS)
816 console_col = CONSOLE_COLS - 1;
819 static void console_cursor_up(int n)
822 console_cursor_fix();
825 static void console_cursor_down(int n)
828 console_cursor_fix();
831 static void console_cursor_left(int n)
834 console_cursor_fix();
837 static void console_cursor_right(int n)
840 console_cursor_fix();
843 static void console_cursor_set_position(int row, int col)
845 if (console_row != -1)
847 if (console_col != -1)
849 console_cursor_fix();
852 static void console_previousline(int n)
854 /* FIXME: also scroll terminal ? */
856 console_cursor_fix();
859 static void console_swap_colors(void)
867 static inline int console_cursor_is_visible(void)
869 return !ansi_cursor_hidden;
872 static inline int console_cursor_is_visible(void)
878 static void console_newline(int n)
883 /* Check if we need to scroll the terminal */
884 if (console_row >= CONSOLE_ROWS) {
885 /* Scroll everything up */
888 /* Decrement row number */
889 console_row = CONSOLE_ROWS - 1;
893 static void console_cr(void)
898 static void parse_putc(const char c)
902 if (console_cursor_is_visible())
906 case 13: /* back to first column */
910 case '\n': /* next line */
911 if (console_col || (!console_col && nl))
917 console_col |= 0x0008;
918 console_col &= ~0x0007;
920 if (console_col >= CONSOLE_COLS)
924 case 8: /* backspace */
931 default: /* draw the char */
932 video_putchar(console_col * VIDEO_FONT_WIDTH,
933 console_row * VIDEO_FONT_HEIGHT, c);
936 /* check for newline */
937 if (console_col >= CONSOLE_COLS) {
943 if (console_cursor_is_visible())
947 void video_putc(const char c)
949 #ifdef CONFIG_CFB_CONSOLE_ANSI
953 for (i = 0; i < ansi_buf_size; ++i)
954 parse_putc(ansi_buf[i]);
960 if (ansi_buf_size > 0) {
980 ansi_buf[ansi_buf_size++] = c;
982 if (ansi_buf_size >= sizeof(ansi_buf))
985 for (i = 0; i < ansi_buf_size; ++i) {
991 if (ansi_buf[i] == 27)
998 if (ansi_buf[i] == '[')
1005 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1006 num1 = ansi_buf[i]-'0';
1008 } else if (ansi_buf[i] != '?') {
1016 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1018 num1 += ansi_buf[i]-'0';
1026 if (ansi_buf[i] != ';') {
1034 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1035 num2 = ansi_buf[i]-'0';
1042 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1044 num2 += ansi_buf[i]-'0';
1052 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1053 || ansi_buf[i] == 'J'
1054 || ansi_buf[i] == 'K'
1055 || ansi_buf[i] == 'h'
1056 || ansi_buf[i] == 'l'
1057 || ansi_buf[i] == 'm') {
1058 cchar = ansi_buf[i];
1067 for (i = 0; i < ansi_buf_size; ++i)
1068 parse_putc(ansi_buf[i]);
1074 if (!ansi_cursor_hidden)
1079 /* move cursor num1 rows up */
1080 console_cursor_up(num1);
1083 /* move cursor num1 rows down */
1084 console_cursor_down(num1);
1087 /* move cursor num1 columns forward */
1088 console_cursor_right(num1);
1091 /* move cursor num1 columns back */
1092 console_cursor_left(num1);
1095 /* move cursor num1 rows up at begin of row */
1096 console_previousline(num1);
1099 /* move cursor num1 rows down at begin of row */
1100 console_newline(num1);
1103 /* move cursor to column num1 */
1104 console_cursor_set_position(-1, num1-1);
1107 /* move cursor to row num1, column num2 */
1108 console_cursor_set_position(num1-1, num2-1);
1111 /* clear console and move cursor to 0, 0 */
1113 console_cursor_set_position(0, 0);
1118 console_clear_line(console_row,
1122 console_clear_line(console_row,
1125 console_clear_line(console_row,
1129 ansi_cursor_hidden = 0;
1132 ansi_cursor_hidden = 1;
1135 if (num1 == 0) { /* reset swapped colors */
1136 if (ansi_colors_need_revert) {
1137 console_swap_colors();
1138 ansi_colors_need_revert = 0;
1140 } else if (num1 == 7) { /* once swap colors */
1141 if (!ansi_colors_need_revert) {
1142 console_swap_colors();
1143 ansi_colors_need_revert = 1;
1148 if (!ansi_cursor_hidden)
1157 if (cfb_do_flush_cache)
1158 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1161 void video_puts(const char *s)
1163 int count = strlen(s);
1170 * Do not enforce drivers (or board code) to provide empty
1171 * video_set_lut() if they do not support 8 bpp format.
1172 * Implement weak default function instead.
1174 void __video_set_lut(unsigned int index, unsigned char r,
1175 unsigned char g, unsigned char b)
1179 void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
1180 __attribute__ ((weak, alias("__video_set_lut")));
1182 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1184 #define FILL_8BIT_332RGB(r,g,b) { \
1185 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1189 #define FILL_15BIT_555RGB(r,g,b) { \
1190 *(unsigned short *)fb = \
1191 SWAP16((unsigned short)(((r>>3)<<10) | \
1197 #define FILL_16BIT_565RGB(r,g,b) { \
1198 *(unsigned short *)fb = \
1199 SWAP16((unsigned short)((((r)>>3)<<11)| \
1205 #define FILL_32BIT_X888RGB(r,g,b) { \
1206 *(unsigned long *)fb = \
1207 SWAP32((unsigned long)(((r<<16) | \
1213 #ifdef VIDEO_FB_LITTLE_ENDIAN
1214 #define FILL_24BIT_888RGB(r,g,b) { \
1221 #define FILL_24BIT_888RGB(r,g,b) { \
1229 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1230 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1232 ushort *dst = (ushort *) fb;
1233 ushort color = (ushort) (((r >> 3) << 10) |
1244 * RLE8 bitmap support
1247 #ifdef CONFIG_VIDEO_BMP_RLE8
1248 /* Pre-calculated color table entry */
1251 unsigned short w; /* word */
1252 unsigned int dw; /* double word */
1253 } ce; /* color entry */
1257 * Helper to draw encoded/unencoded run.
1259 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1262 ulong addr = (ulong) *fb;
1268 * Setup offset of the color index in the bitmap.
1269 * Color index of encoded run is at offset 1.
1271 off = enc ? &enc_off : &i;
1273 switch (VIDEO_DATA_FORMAT) {
1274 case GDF__8BIT_INDEX:
1275 for (i = 0; i < cnt; i++)
1276 *(unsigned char *) addr++ = bm[*off];
1278 case GDF_15BIT_555RGB:
1279 case GDF_16BIT_565RGB:
1280 /* differences handled while pre-calculating palette */
1281 for (i = 0; i < cnt; i++) {
1282 *(unsigned short *) addr = p[bm[*off]].ce.w;
1286 case GDF_32BIT_X888RGB:
1287 for (i = 0; i < cnt; i++) {
1288 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1293 *fb = (uchar *) addr; /* return modified address */
1296 static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1297 int width, int height)
1301 unsigned int cnt, runlen;
1303 int x, y, bpp, i, ncolors;
1304 struct palette p[256];
1305 bmp_color_table_entry_t cte;
1306 int green_shift, red_off;
1307 int limit = VIDEO_COLS * VIDEO_ROWS;
1311 y = __le32_to_cpu(img->header.height) - 1;
1312 ncolors = __le32_to_cpu(img->header.colors_used);
1313 bpp = VIDEO_PIXEL_SIZE;
1314 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1315 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
1317 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1319 /* pre-calculate and setup palette */
1320 switch (VIDEO_DATA_FORMAT) {
1321 case GDF__8BIT_INDEX:
1322 for (i = 0; i < ncolors; i++) {
1323 cte = img->color_table[i];
1324 video_set_lut(i, cte.red, cte.green, cte.blue);
1327 case GDF_15BIT_555RGB:
1328 case GDF_16BIT_565RGB:
1329 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1336 for (i = 0; i < ncolors; i++) {
1337 cte = img->color_table[i];
1338 p[i].ce.w = SWAP16((unsigned short)
1339 (((cte.red >> 3) << red_off) |
1340 ((cte.green >> green_shift) << 5) |
1344 case GDF_32BIT_X888RGB:
1345 for (i = 0; i < ncolors; i++) {
1346 cte = img->color_table[i];
1347 p[i].ce.dw = SWAP32((cte.red << 16) |
1353 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1363 /* scan line end marker */
1367 fbp = (unsigned char *)
1368 ((unsigned int) video_fb_address +
1369 (((y + yoff) * VIDEO_COLS) +
1373 /* end of bitmap data marker */
1377 /* run offset marker */
1380 fbp = (unsigned char *)
1381 ((unsigned int) video_fb_address +
1382 (((y + yoff) * VIDEO_COLS) +
1400 if (x + runlen > width)
1402 draw_bitmap(&fbp, bm, p, cnt, 0);
1408 bm++; /* 0 padding if length is odd */
1419 if (y < height) { /* only draw into visible area */
1425 if (x + runlen > width)
1427 draw_bitmap(&fbp, bm, p, cnt, 1);
1436 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1442 * Display the BMP file located at address bmp_image.
1444 int video_display_bitmap(ulong bmp_image, int x, int y)
1446 ushort xcount, ycount;
1448 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1451 unsigned long width, height, bpp;
1453 unsigned long compression;
1454 bmp_color_table_entry_t cte;
1456 #ifdef CONFIG_VIDEO_BMP_GZIP
1457 unsigned char *dst = NULL;
1463 if (!((bmp->header.signature[0] == 'B') &&
1464 (bmp->header.signature[1] == 'M'))) {
1466 #ifdef CONFIG_VIDEO_BMP_GZIP
1468 * Could be a gzipped bmp image, try to decrompress...
1470 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1471 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1473 printf("Error: malloc in gunzip failed!\n");
1477 * NB: we need to force offset of +2
1478 * See doc/README.displaying-bmps
1480 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
1481 (uchar *) bmp_image,
1483 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1488 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1489 printf("Image could be truncated "
1490 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1494 * Set addr to decompressed image
1496 bmp = (bmp_image_t *)(dst+2);
1498 if (!((bmp->header.signature[0] == 'B') &&
1499 (bmp->header.signature[1] == 'M'))) {
1500 printf("Error: no valid bmp.gz image at %lx\n",
1506 printf("Error: no valid bmp image at %lx\n", bmp_image);
1508 #endif /* CONFIG_VIDEO_BMP_GZIP */
1511 width = le32_to_cpu(bmp->header.width);
1512 height = le32_to_cpu(bmp->header.height);
1513 bpp = le16_to_cpu(bmp->header.bit_count);
1514 colors = le32_to_cpu(bmp->header.colors_used);
1515 compression = le32_to_cpu(bmp->header.compression);
1517 debug("Display-bmp: %ld x %ld with %d colors\n",
1518 width, height, colors);
1520 if (compression != BMP_BI_RGB
1521 #ifdef CONFIG_VIDEO_BMP_RLE8
1522 && compression != BMP_BI_RLE8
1525 printf("Error: compression type %ld not supported\n",
1527 #ifdef CONFIG_VIDEO_BMP_GZIP
1534 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1536 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1537 if (x == BMP_ALIGN_CENTER)
1538 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1540 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1542 if (y == BMP_ALIGN_CENTER)
1543 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1545 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1546 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1549 * Just ignore elements which are completely beyond screen
1552 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1555 if ((x + width) > VIDEO_VISIBLE_COLS)
1556 width = VIDEO_VISIBLE_COLS - x;
1557 if ((y + height) > VIDEO_VISIBLE_ROWS)
1558 height = VIDEO_VISIBLE_ROWS - y;
1560 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1561 fb = (uchar *) (video_fb_address +
1562 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1563 x * VIDEO_PIXEL_SIZE);
1565 #ifdef CONFIG_VIDEO_BMP_RLE8
1566 if (compression == BMP_BI_RLE8) {
1567 return display_rle8_bitmap(bmp, x, y, width, height);
1571 /* We handle only 4, 8, or 24 bpp bitmaps */
1572 switch (le16_to_cpu(bmp->header.bit_count)) {
1574 padded_line -= width / 2;
1577 switch (VIDEO_DATA_FORMAT) {
1578 case GDF_32BIT_X888RGB:
1582 * Don't assume that 'width' is an
1585 for (xcount = 0; xcount < width; xcount++) {
1593 cte = bmp->color_table[idx];
1594 FILL_32BIT_X888RGB(cte.red, cte.green,
1597 bmap += padded_line;
1598 fb -= (VIDEO_VISIBLE_COLS + width) *
1603 puts("4bpp bitmap unsupported with current "
1610 padded_line -= width;
1611 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1613 for (xcount = 0; xcount < colors; ++xcount) {
1614 cte = bmp->color_table[xcount];
1615 video_set_lut(xcount, cte.red, cte.green,
1620 switch (VIDEO_DATA_FORMAT) {
1621 case GDF__8BIT_INDEX:
1628 bmap += padded_line;
1629 fb -= (VIDEO_VISIBLE_COLS + width) *
1633 case GDF__8BIT_332RGB:
1638 cte = bmp->color_table[*bmap++];
1639 FILL_8BIT_332RGB(cte.red, cte.green,
1642 bmap += padded_line;
1643 fb -= (VIDEO_VISIBLE_COLS + width) *
1647 case GDF_15BIT_555RGB:
1649 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1655 cte = bmp->color_table[*bmap++];
1656 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1657 fill_555rgb_pswap(fb, xpos++, cte.red,
1662 FILL_15BIT_555RGB(cte.red, cte.green,
1666 bmap += padded_line;
1667 fb -= (VIDEO_VISIBLE_COLS + width) *
1671 case GDF_16BIT_565RGB:
1676 cte = bmp->color_table[*bmap++];
1677 FILL_16BIT_565RGB(cte.red, cte.green,
1680 bmap += padded_line;
1681 fb -= (VIDEO_VISIBLE_COLS + width) *
1685 case GDF_32BIT_X888RGB:
1690 cte = bmp->color_table[*bmap++];
1691 FILL_32BIT_X888RGB(cte.red, cte.green,
1694 bmap += padded_line;
1695 fb -= (VIDEO_VISIBLE_COLS + width) *
1699 case GDF_24BIT_888RGB:
1704 cte = bmp->color_table[*bmap++];
1705 FILL_24BIT_888RGB(cte.red, cte.green,
1708 bmap += padded_line;
1709 fb -= (VIDEO_VISIBLE_COLS + width) *
1716 padded_line -= 3 * width;
1718 switch (VIDEO_DATA_FORMAT) {
1719 case GDF__8BIT_332RGB:
1724 FILL_8BIT_332RGB(bmap[2], bmap[1],
1728 bmap += padded_line;
1729 fb -= (VIDEO_VISIBLE_COLS + width) *
1733 case GDF_15BIT_555RGB:
1735 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1741 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1742 fill_555rgb_pswap(fb, xpos++, bmap[2],
1746 FILL_15BIT_555RGB(bmap[2], bmap[1],
1751 bmap += padded_line;
1752 fb -= (VIDEO_VISIBLE_COLS + width) *
1756 case GDF_16BIT_565RGB:
1761 FILL_16BIT_565RGB(bmap[2], bmap[1],
1765 bmap += padded_line;
1766 fb -= (VIDEO_VISIBLE_COLS + width) *
1770 case GDF_32BIT_X888RGB:
1775 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1779 bmap += padded_line;
1780 fb -= (VIDEO_VISIBLE_COLS + width) *
1784 case GDF_24BIT_888RGB:
1789 FILL_24BIT_888RGB(bmap[2], bmap[1],
1793 bmap += padded_line;
1794 fb -= (VIDEO_VISIBLE_COLS + width) *
1799 printf("Error: 24 bits/pixel bitmap incompatible "
1800 "with current video mode\n");
1805 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1806 le16_to_cpu(bmp->header.bit_count));
1810 #ifdef CONFIG_VIDEO_BMP_GZIP
1816 if (cfb_do_flush_cache)
1817 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1823 #ifdef CONFIG_VIDEO_LOGO
1824 static int video_logo_xpos;
1825 static int video_logo_ypos;
1827 static void plot_logo_or_black(void *screen, int width, int x, int y, \
1830 static void logo_plot(void *screen, int width, int x, int y)
1832 plot_logo_or_black(screen, width, x, y, 0);
1835 static void logo_black(void)
1837 plot_logo_or_black(video_fb_address, \
1844 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1847 return cmd_usage(cmdtp);
1854 clrlogo, 1, 0, do_clrlogo,
1855 "fill the boot logo area with black",
1859 static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
1863 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
1864 int ycount = video_logo_height;
1865 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1866 unsigned char *source;
1867 unsigned char *dest;
1869 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1870 if (x == BMP_ALIGN_CENTER)
1871 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1873 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1875 if (y == BMP_ALIGN_CENTER)
1876 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1878 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1879 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1881 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
1883 #ifdef CONFIG_VIDEO_BMP_LOGO
1884 source = bmp_logo_bitmap;
1886 /* Allocate temporary space for computing colormap */
1887 logo_red = malloc(BMP_LOGO_COLORS);
1888 logo_green = malloc(BMP_LOGO_COLORS);
1889 logo_blue = malloc(BMP_LOGO_COLORS);
1890 /* Compute color map */
1891 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1892 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1893 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1894 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1897 source = linux_logo;
1898 logo_red = linux_logo_red;
1899 logo_green = linux_logo_green;
1900 logo_blue = linux_logo_blue;
1903 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1904 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1905 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1906 logo_red[i], logo_green[i],
1912 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1915 xcount = VIDEO_LOGO_WIDTH;
1922 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1923 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1924 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1927 switch (VIDEO_DATA_FORMAT) {
1928 case GDF__8BIT_INDEX:
1931 case GDF__8BIT_332RGB:
1932 *dest = ((r >> 5) << 5) |
1936 case GDF_15BIT_555RGB:
1937 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1938 fill_555rgb_pswap(dest, xpos++, r, g, b);
1940 *(unsigned short *) dest =
1941 SWAP16((unsigned short) (
1947 case GDF_16BIT_565RGB:
1948 *(unsigned short *) dest =
1949 SWAP16((unsigned short) (
1954 case GDF_32BIT_X888RGB:
1955 *(unsigned long *) dest =
1956 SWAP32((unsigned long) (
1961 case GDF_24BIT_888RGB:
1962 #ifdef VIDEO_FB_LITTLE_ENDIAN
1974 dest += VIDEO_PIXEL_SIZE;
1978 #ifdef CONFIG_VIDEO_BMP_LOGO
1985 static void *video_logo(void)
1989 __maybe_unused int y_off = 0;
1990 __maybe_unused ulong addr;
1991 __maybe_unused char *s;
1993 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
1995 #ifdef CONFIG_SPLASH_SCREEN
1996 s = getenv("splashimage");
1998 splash_screen_prepare();
1999 addr = simple_strtoul(s, NULL, 16);
2001 if (video_display_bitmap(addr,
2003 video_logo_ypos) == 0) {
2004 video_logo_height = 0;
2005 return ((void *) (video_fb_address));
2008 #endif /* CONFIG_SPLASH_SCREEN */
2010 logo_plot(video_fb_address, VIDEO_COLS,
2011 video_logo_xpos, video_logo_ypos);
2013 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
2015 * when using splashpos for video_logo, skip any info
2016 * output on video console if the logo is not at 0,0
2018 if (video_logo_xpos || video_logo_ypos) {
2020 * video_logo_height is used in text and cursor offset
2021 * calculations. Since the console is below the logo,
2022 * we need to adjust the logo height
2024 if (video_logo_ypos == BMP_ALIGN_CENTER)
2025 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
2026 VIDEO_LOGO_HEIGHT) / 2);
2027 else if (video_logo_ypos > 0)
2028 video_logo_height += video_logo_ypos;
2030 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2033 if (board_cfb_skip())
2036 sprintf(info, " %s", version_string);
2038 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2042 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2043 (uchar *) info, space);
2044 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2045 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2046 (uchar *) info + space, len - space);
2049 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
2051 #ifdef CONFIG_CONSOLE_EXTRA_INFO
2054 ((video_logo_height -
2055 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
2057 for (i = 1; i < n; i++) {
2058 video_get_info_str(i, info);
2064 video_drawchars(VIDEO_INFO_X,
2068 (uchar *) info, space);
2070 video_drawchars(VIDEO_INFO_X +
2075 (uchar *) info + space,
2078 video_drawstring(VIDEO_INFO_X,
2088 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
2092 static int cfb_fb_is_in_dram(void)
2095 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2096 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2100 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2101 start = bd->bi_dram[i].start;
2102 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2103 if ((ulong)video_fb_address >= start &&
2104 (ulong)video_fb_address < end)
2108 if ((ulong)video_fb_address >= bd->bi_memstart &&
2109 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2115 void video_clear(void)
2117 if (!video_fb_address)
2119 #ifdef VIDEO_HW_RECTFILL
2120 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2123 VIDEO_VISIBLE_COLS, /* frame width */
2124 VIDEO_VISIBLE_ROWS, /* frame height */
2125 bgx /* fill color */
2128 memsetl(video_fb_address,
2129 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2133 static int video_init(void)
2135 unsigned char color8;
2137 pGD = video_hw_init();
2141 video_fb_address = (void *) VIDEO_FB_ADRS;
2142 #ifdef CONFIG_VIDEO_HW_CURSOR
2143 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
2146 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2148 /* Init drawing pats */
2149 switch (VIDEO_DATA_FORMAT) {
2150 case GDF__8BIT_INDEX:
2151 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2153 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2158 case GDF__8BIT_332RGB:
2159 color8 = ((CONSOLE_FG_COL & 0xe0) |
2160 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2161 CONSOLE_FG_COL >> 6);
2162 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2164 color8 = ((CONSOLE_BG_COL & 0xe0) |
2165 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2166 CONSOLE_BG_COL >> 6);
2167 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2170 case GDF_15BIT_555RGB:
2171 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
2172 ((CONSOLE_FG_COL >> 3) << 21) |
2173 ((CONSOLE_FG_COL >> 3) << 16) |
2174 ((CONSOLE_FG_COL >> 3) << 10) |
2175 ((CONSOLE_FG_COL >> 3) << 5) |
2176 (CONSOLE_FG_COL >> 3));
2177 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
2178 ((CONSOLE_BG_COL >> 3) << 21) |
2179 ((CONSOLE_BG_COL >> 3) << 16) |
2180 ((CONSOLE_BG_COL >> 3) << 10) |
2181 ((CONSOLE_BG_COL >> 3) << 5) |
2182 (CONSOLE_BG_COL >> 3));
2184 case GDF_16BIT_565RGB:
2185 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
2186 ((CONSOLE_FG_COL >> 2) << 21) |
2187 ((CONSOLE_FG_COL >> 3) << 16) |
2188 ((CONSOLE_FG_COL >> 3) << 11) |
2189 ((CONSOLE_FG_COL >> 2) << 5) |
2190 (CONSOLE_FG_COL >> 3));
2191 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
2192 ((CONSOLE_BG_COL >> 2) << 21) |
2193 ((CONSOLE_BG_COL >> 3) << 16) |
2194 ((CONSOLE_BG_COL >> 3) << 11) |
2195 ((CONSOLE_BG_COL >> 2) << 5) |
2196 (CONSOLE_BG_COL >> 3));
2198 case GDF_32BIT_X888RGB:
2199 fgx = (CONSOLE_FG_COL << 16) |
2200 (CONSOLE_FG_COL << 8) |
2202 bgx = (CONSOLE_BG_COL << 16) |
2203 (CONSOLE_BG_COL << 8) |
2206 case GDF_24BIT_888RGB:
2207 fgx = (CONSOLE_FG_COL << 24) |
2208 (CONSOLE_FG_COL << 16) |
2209 (CONSOLE_FG_COL << 8) |
2211 bgx = (CONSOLE_BG_COL << 24) |
2212 (CONSOLE_BG_COL << 16) |
2213 (CONSOLE_BG_COL << 8) |
2221 #ifdef CONFIG_VIDEO_LOGO
2222 /* Plot the logo and get start point of console */
2223 debug("Video: Drawing the logo ...\n");
2224 video_console_address = video_logo();
2226 video_console_address = video_fb_address;
2229 /* Initialize the console */
2233 if (cfb_do_flush_cache)
2234 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2240 * Implement a weak default function for boards that optionally
2241 * need to skip the video initialization.
2243 int __board_video_skip(void)
2245 /* As default, don't skip test */
2249 int board_video_skip(void)
2250 __attribute__ ((weak, alias("__board_video_skip")));
2252 int drv_video_init(void)
2255 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 debug("KBD: Keyboard init ...\n");
2269 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2275 /* Init vga device */
2276 memset(&console_dev, 0, sizeof(console_dev));
2277 strcpy(console_dev.name, "vga");
2278 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2279 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2280 console_dev.putc = video_putc; /* 'putc' function */
2281 console_dev.puts = video_puts; /* 'puts' function */
2282 console_dev.tstc = NULL; /* 'tstc' function */
2283 console_dev.getc = NULL; /* 'getc' function */
2285 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2286 /* Also init console device */
2287 console_dev.flags |= DEV_FLAGS_INPUT;
2288 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2289 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2290 #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
2292 if (stdio_register(&console_dev) != 0)
2295 /* Return success */
2299 void video_position_cursor(unsigned col, unsigned row)
2301 console_col = min(col, CONSOLE_COLS - 1);
2302 console_row = min(row, CONSOLE_ROWS - 1);
2305 int video_get_pixel_width(void)
2307 return VIDEO_VISIBLE_COLS;
2310 int video_get_pixel_height(void)
2312 return VIDEO_VISIBLE_ROWS;
2315 int video_get_screen_rows(void)
2317 return CONSOLE_ROWS;
2320 int video_get_screen_columns(void)
2322 return CONSOLE_COLS;