2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
29 * At the moment only the 8x16 font is tested and the font fore- and
30 * background color is limited to black/white/gray colors. The Linux
31 * logo can be placed in the upper left corner and additional board
32 * information strings (that normally goes to serial port) can be drawn.
34 * The console driver can use the standard PC keyboard interface (i8042)
35 * for character input. Character output goes to a memory mapped video
36 * framebuffer with little or big-endian organisation.
37 * With environment setting 'console=serial' the console i/o can be
38 * forced to serial port.
40 * The driver uses graphic specific defines/parameters/functions:
42 * (for SMI LynxE graphic chip)
44 * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
45 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
46 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
47 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
49 * Console Parameters are set by graphic drivers global struct:
51 * VIDEO_VISIBLE_COLS - x resolution
52 * VIDEO_VISIBLE_ROWS - y resolution
53 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
54 * VIDEO_DATA_FORMAT - graphical data format GDF
55 * VIDEO_FB_ADRS - start of video memory
57 * CONFIG_I8042_KBD - AT Keyboard driver for i8042
58 * VIDEO_KBD_INIT_FCT - init function for keyboard
59 * VIDEO_TSTC_FCT - keyboard_tstc function
60 * VIDEO_GETC_FCT - keyboard_getc function
62 * CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with
63 * delay loop in VIDEO_TSTC_FCT (i8042)
65 * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
66 * CONFIG_CONSOLE_TIME - display time/date in upper right
67 * corner, needs CONFIG_CMD_DATE and
68 * CONFIG_CONSOLE_CURSOR
69 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
70 * Use CONFIG_SPLASH_SCREEN_ALIGN with
71 * environment variable "splashpos" to place
72 * the logo on other position. In this case
73 * no CONSOLE_EXTRA_INFO is possible.
74 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
75 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
76 * strings that normaly goes to serial
77 * port. This define requires a board
79 * video_drawstring (VIDEO_INFO_X,
80 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
82 * that fills a info buffer at i=row.
83 * s.a: board/eltec/bab7xx.
84 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
85 * initialized as an output only device.
86 * The Keyboard driver will not be
87 * set-up. This may be used, if you have
88 * no or more than one Keyboard devices
89 * (USB Keyboard, AT Keyboard).
91 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
92 * character. No blinking is provided.
93 * Uses the macros CURSOR_SET and
96 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
97 * of the graphic chip. Uses the macro
98 * CURSOR_SET. ATTENTION: If booting an
99 * OS, the display driver must disable
100 * the hardware register of the graphic
101 * chip. Otherwise a blinking field is
108 #include <linux/compiler.h>
111 * Console device defines with SMI graphic
112 * Any other graphic must change this section
115 #ifdef CONFIG_VIDEO_SMI_LYNXEM
117 #define VIDEO_FB_LITTLE_ENDIAN
118 #define VIDEO_HW_RECTFILL
119 #define VIDEO_HW_BITBLT
123 * Defines for the CT69000 driver
125 #ifdef CONFIG_VIDEO_CT69000
127 #define VIDEO_FB_LITTLE_ENDIAN
128 #define VIDEO_HW_RECTFILL
129 #define VIDEO_HW_BITBLT
133 * Defines for the SED13806 driver
135 #ifdef CONFIG_VIDEO_SED13806
137 #ifndef CONFIG_TOTAL5200
138 #define VIDEO_FB_LITTLE_ENDIAN
140 #define VIDEO_HW_RECTFILL
141 #define VIDEO_HW_BITBLT
145 * Defines for the SED13806 driver
147 #ifdef CONFIG_VIDEO_SM501
150 #define VIDEO_FB_LITTLE_ENDIAN
155 * Defines for the MB862xx driver
157 #ifdef CONFIG_VIDEO_MB862xx
159 #ifdef CONFIG_VIDEO_CORALP
160 #define VIDEO_FB_LITTLE_ENDIAN
162 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
163 #define VIDEO_HW_RECTFILL
164 #define VIDEO_HW_BITBLT
169 * Defines for the i.MX31 driver (mx3fb.c)
171 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
172 #define VIDEO_FB_16BPP_WORD_SWAP
176 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
178 #include <video_fb.h>
183 #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
184 #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
185 #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
186 #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
187 #define VIDEO_FB_ADRS (pGD->frameAdrs)
190 * Console device defines with i8042 keyboard controller
191 * Any other keyboard controller must change this section
194 #ifdef CONFIG_I8042_KBD
197 #define VIDEO_KBD_INIT_FCT i8042_kbd_init()
198 #define VIDEO_TSTC_FCT i8042_tstc
199 #define VIDEO_GETC_FCT i8042_getc
207 #include <linux/types.h>
208 #include <stdio_dev.h>
209 #include <video_font.h>
210 #include <video_font_data.h>
212 #if defined(CONFIG_CMD_DATE)
216 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
217 #include <watchdog.h>
218 #include <bmp_layout.h>
220 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
221 #define BMP_ALIGN_CENTER 0x7FFF
228 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
229 * to let the cursor blink. Uses the macros
230 * CURSOR_OFF and CURSOR_ON.
231 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
232 * blinking is provided. Uses the macros CURSOR_SET
234 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
235 * graphic chip. Uses the macro CURSOR_SET.
236 * ATTENTION: If booting an OS, the display driver
237 * must disable the hardware register of the graphic
238 * chip. Otherwise a blinking field is displayed
240 #if !defined(CONFIG_CONSOLE_CURSOR) && \
241 !defined(CONFIG_VIDEO_SW_CURSOR) && \
242 !defined(CONFIG_VIDEO_HW_CURSOR)
243 /* no Cursor defined */
249 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
250 #if defined(CURSOR_ON) || \
251 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
252 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
253 or CONFIG_VIDEO_HW_CURSOR can be defined
255 void console_cursor(int state);
257 #define CURSOR_ON console_cursor(1)
258 #define CURSOR_OFF console_cursor(0)
259 #define CURSOR_SET video_set_cursor()
260 #endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
262 #ifdef CONFIG_CONSOLE_CURSOR
263 #ifndef CONFIG_CONSOLE_TIME
264 #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
266 #ifndef CONFIG_I8042_KBD
267 #warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
269 #endif /* CONFIG_CONSOLE_CURSOR */
272 #ifdef CONFIG_VIDEO_HW_CURSOR
274 #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
275 or CONFIG_VIDEO_HW_CURSOR can be defined
279 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
280 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
281 #endif /* CONFIG_VIDEO_HW_CURSOR */
283 #ifdef CONFIG_VIDEO_LOGO
284 #ifdef CONFIG_VIDEO_BMP_LOGO
285 #include <bmp_logo.h>
286 #include <bmp_logo_data.h>
287 #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
288 #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
289 #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
290 #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
292 #else /* CONFIG_VIDEO_BMP_LOGO */
293 #define LINUX_LOGO_WIDTH 80
294 #define LINUX_LOGO_HEIGHT 80
295 #define LINUX_LOGO_COLORS 214
296 #define LINUX_LOGO_LUT_OFFSET 0x20
298 #include <linux_logo.h>
299 #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
300 #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
301 #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
302 #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
303 #endif /* CONFIG_VIDEO_BMP_LOGO */
304 #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
305 #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
306 #else /* CONFIG_VIDEO_LOGO */
307 #define VIDEO_LOGO_WIDTH 0
308 #define VIDEO_LOGO_HEIGHT 0
309 #endif /* CONFIG_VIDEO_LOGO */
311 #define VIDEO_COLS VIDEO_VISIBLE_COLS
312 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
313 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
314 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
315 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
316 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
318 #ifdef CONFIG_VIDEO_LOGO
319 #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
321 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
324 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
325 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
326 #define CONSOLE_ROW_FIRST (video_console_address)
327 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
328 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
329 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
330 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
333 #ifdef VIDEO_FB_LITTLE_ENDIAN
334 #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
337 #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
338 (((x) & 0x0000ff00) << 8) | \
339 (((x) & 0x00ff0000) >> 8) | \
340 (((x) & 0xff000000) >> 24) \
342 #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
343 (((x) & 0x0000ff00) >> 8) | \
344 (((x) & 0x00ff0000) << 8) | \
345 (((x) & 0xff000000) >> 8) \
348 #define SWAP16(x) (x)
349 #define SWAP32(x) (x)
350 #if defined(VIDEO_FB_16BPP_WORD_SWAP)
351 #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
353 #define SHORTSWAP32(x) (x)
357 #ifdef CONFIG_CONSOLE_EXTRA_INFO
359 * setup a board string: type, speed, etc.
361 * line_number: location to place info string beside logo
362 * info: buffer for info string
364 extern void video_get_info_str(int line_number, char *info);
367 DECLARE_GLOBAL_DATA_PTR;
370 static GraphicDevice *pGD; /* Pointer to Graphic array */
372 static void *video_fb_address; /* frame buffer address */
373 static void *video_console_address; /* console buffer start address */
375 static int video_logo_height = VIDEO_LOGO_HEIGHT;
377 static int __maybe_unused cursor_state;
378 static int __maybe_unused old_col;
379 static int __maybe_unused old_row;
381 static int console_col; /* cursor col */
382 static int console_row; /* cursor row */
384 static u32 eorx, fgx, bgx; /* color pats */
386 static int cfb_do_flush_cache;
388 #ifdef CONFIG_CFB_CONSOLE_ANSI
389 static char ansi_buf[10];
390 static int ansi_buf_size;
391 static int ansi_colors_need_revert;
392 static int ansi_cursor_hidden;
395 static const int video_font_draw_table8[] = {
396 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
397 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
398 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
399 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
402 static const int video_font_draw_table15[] = {
403 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
406 static const int video_font_draw_table16[] = {
407 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
410 static const int video_font_draw_table24[16][3] = {
411 {0x00000000, 0x00000000, 0x00000000},
412 {0x00000000, 0x00000000, 0x00ffffff},
413 {0x00000000, 0x0000ffff, 0xff000000},
414 {0x00000000, 0x0000ffff, 0xffffffff},
415 {0x000000ff, 0xffff0000, 0x00000000},
416 {0x000000ff, 0xffff0000, 0x00ffffff},
417 {0x000000ff, 0xffffffff, 0xff000000},
418 {0x000000ff, 0xffffffff, 0xffffffff},
419 {0xffffff00, 0x00000000, 0x00000000},
420 {0xffffff00, 0x00000000, 0x00ffffff},
421 {0xffffff00, 0x0000ffff, 0xff000000},
422 {0xffffff00, 0x0000ffff, 0xffffffff},
423 {0xffffffff, 0xffff0000, 0x00000000},
424 {0xffffffff, 0xffff0000, 0x00ffffff},
425 {0xffffffff, 0xffffffff, 0xff000000},
426 {0xffffffff, 0xffffffff, 0xffffffff}
429 static const int video_font_draw_table32[16][4] = {
430 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
431 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
432 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
433 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
434 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
435 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
436 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
437 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
438 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
439 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
440 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
441 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
442 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
443 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
444 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
445 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
448 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
450 u8 *cdat, *dest, *dest0;
453 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
454 dest0 = video_fb_address + offset;
456 switch (VIDEO_DATA_FORMAT) {
457 case GDF__8BIT_INDEX:
458 case GDF__8BIT_332RGB:
461 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
462 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
463 rows--; dest += VIDEO_LINE_LEN) {
467 (video_font_draw_table8[bits >> 4] &
470 (video_font_draw_table8[bits & 15] &
473 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
478 case GDF_15BIT_555RGB:
481 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
482 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
483 rows--; dest += VIDEO_LINE_LEN) {
487 SHORTSWAP32((video_font_draw_table15
488 [bits >> 6] & eorx) ^
491 SHORTSWAP32((video_font_draw_table15
492 [bits >> 4 & 3] & eorx) ^
495 SHORTSWAP32((video_font_draw_table15
496 [bits >> 2 & 3] & eorx) ^
499 SHORTSWAP32((video_font_draw_table15
503 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
508 case GDF_16BIT_565RGB:
511 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
512 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
513 rows--; dest += VIDEO_LINE_LEN) {
517 SHORTSWAP32((video_font_draw_table16
518 [bits >> 6] & eorx) ^
521 SHORTSWAP32((video_font_draw_table16
522 [bits >> 4 & 3] & eorx) ^
525 SHORTSWAP32((video_font_draw_table16
526 [bits >> 2 & 3] & eorx) ^
529 SHORTSWAP32((video_font_draw_table16
533 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
538 case GDF_32BIT_X888RGB:
541 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
542 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
543 rows--; dest += VIDEO_LINE_LEN) {
547 SWAP32((video_font_draw_table32
548 [bits >> 4][0] & eorx) ^ bgx);
550 SWAP32((video_font_draw_table32
551 [bits >> 4][1] & eorx) ^ bgx);
553 SWAP32((video_font_draw_table32
554 [bits >> 4][2] & eorx) ^ bgx);
556 SWAP32((video_font_draw_table32
557 [bits >> 4][3] & eorx) ^ bgx);
559 SWAP32((video_font_draw_table32
560 [bits & 15][0] & eorx) ^ bgx);
562 SWAP32((video_font_draw_table32
563 [bits & 15][1] & eorx) ^ bgx);
565 SWAP32((video_font_draw_table32
566 [bits & 15][2] & eorx) ^ bgx);
568 SWAP32((video_font_draw_table32
569 [bits & 15][3] & eorx) ^ bgx);
571 if (cfb_do_flush_cache)
572 flush_cache((ulong)dest0, 32);
573 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
578 case GDF_24BIT_888RGB:
581 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
582 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
583 rows--; dest += VIDEO_LINE_LEN) {
587 (video_font_draw_table24[bits >> 4][0]
590 (video_font_draw_table24[bits >> 4][1]
593 (video_font_draw_table24[bits >> 4][2]
596 (video_font_draw_table24[bits & 15][0]
599 (video_font_draw_table24[bits & 15][1]
602 (video_font_draw_table24[bits & 15][2]
605 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
612 static inline void video_drawstring(int xx, int yy, unsigned char *s)
614 video_drawchars(xx, yy, s, strlen((char *) s));
617 static void video_putchar(int xx, int yy, unsigned char c)
619 video_drawchars(xx, yy + video_logo_height, &c, 1);
622 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
623 static void video_set_cursor(void)
630 static void video_invertchar(int xx, int yy)
632 int firstx = xx * VIDEO_PIXEL_SIZE;
633 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
634 int firsty = yy * VIDEO_LINE_LEN;
635 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
637 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
638 for (x = firstx; x < lastx; x++) {
639 u8 *dest = (u8 *)(video_fb_address) + x + y;
641 if (cfb_do_flush_cache)
642 flush_cache((ulong)dest, 4);
647 void console_cursor(int state)
649 #ifdef CONFIG_CONSOLE_TIME
653 /* time update only if cursor is on (faster scroll) */
657 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
659 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
660 VIDEO_INFO_Y, (uchar *) info);
662 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
664 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
665 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
670 if (cursor_state != state) {
672 /* turn off the cursor */
673 video_invertchar(old_col * VIDEO_FONT_WIDTH,
674 old_row * VIDEO_FONT_HEIGHT +
677 /* turn off the cursor and record where it is */
678 video_invertchar(console_col * VIDEO_FONT_WIDTH,
679 console_row * VIDEO_FONT_HEIGHT +
681 old_col = console_col;
682 old_row = console_row;
684 cursor_state = state;
689 #ifndef VIDEO_HW_RECTFILL
690 static void memsetl(int *p, int c, int v)
697 #ifndef VIDEO_HW_BITBLT
698 static void memcpyl(int *d, int *s, int c)
705 static void console_clear_line(int line, int begin, int end)
707 #ifdef VIDEO_HW_RECTFILL
708 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
709 VIDEO_FONT_WIDTH * begin, /* dest pos x */
711 VIDEO_FONT_HEIGHT * line, /* dest pos y */
712 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
713 VIDEO_FONT_HEIGHT, /* frame height */
717 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
718 memsetl(CONSOLE_ROW_FIRST +
719 CONSOLE_ROW_SIZE * line, /* offset of row */
720 CONSOLE_ROW_SIZE >> 2, /* length of row */
727 offset = CONSOLE_ROW_FIRST +
728 CONSOLE_ROW_SIZE * line + /* offset of row */
730 VIDEO_PIXEL_SIZE * begin; /* offset of col */
731 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
732 size >>= 2; /* length to end for memsetl() */
733 /* fill at col offset of i'th line using bgx as fill color */
734 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
735 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
738 if (cfb_do_flush_cache)
739 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
742 static void console_scrollup(void)
744 /* copy up rows ignoring the first one */
746 #ifdef VIDEO_HW_BITBLT
747 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
748 0, /* source pos x */
750 VIDEO_FONT_HEIGHT, /* source pos y */
752 video_logo_height, /* dest pos y */
753 VIDEO_VISIBLE_COLS, /* frame width */
756 - VIDEO_FONT_HEIGHT /* frame height */
759 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
760 CONSOLE_SCROLL_SIZE >> 2);
762 /* clear the last one */
763 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
766 static void console_back(void)
770 if (console_col < 0) {
771 console_col = CONSOLE_COLS - 1;
778 #ifdef CONFIG_CFB_CONSOLE_ANSI
780 static void console_clear(void)
782 #ifdef VIDEO_HW_RECTFILL
783 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
785 video_logo_height, /* dest pos y */
786 VIDEO_VISIBLE_COLS, /* frame width */
787 VIDEO_VISIBLE_ROWS, /* frame height */
791 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
795 static void console_cursor_fix(void)
799 if (console_row >= CONSOLE_ROWS)
800 console_row = CONSOLE_ROWS - 1;
803 if (console_col >= CONSOLE_COLS)
804 console_col = CONSOLE_COLS - 1;
807 static void console_cursor_up(int n)
810 console_cursor_fix();
813 static void console_cursor_down(int n)
816 console_cursor_fix();
819 static void console_cursor_left(int n)
822 console_cursor_fix();
825 static void console_cursor_right(int n)
828 console_cursor_fix();
831 static void console_cursor_set_position(int row, int col)
833 if (console_row != -1)
835 if (console_col != -1)
837 console_cursor_fix();
840 static void console_previousline(int n)
842 /* FIXME: also scroll terminal ? */
844 console_cursor_fix();
847 static void console_swap_colors(void)
855 static inline int console_cursor_is_visible(void)
857 return !ansi_cursor_hidden;
860 static inline int console_cursor_is_visible(void)
866 static void console_newline(int n)
871 /* Check if we need to scroll the terminal */
872 if (console_row >= CONSOLE_ROWS) {
873 /* Scroll everything up */
876 /* Decrement row number */
877 console_row = CONSOLE_ROWS - 1;
881 static void console_cr(void)
886 static void parse_putc(const char c)
890 if (console_cursor_is_visible())
894 case 13: /* back to first column */
898 case '\n': /* next line */
899 if (console_col || (!console_col && nl))
905 console_col |= 0x0008;
906 console_col &= ~0x0007;
908 if (console_col >= CONSOLE_COLS)
912 case 8: /* backspace */
919 default: /* draw the char */
920 video_putchar(console_col * VIDEO_FONT_WIDTH,
921 console_row * VIDEO_FONT_HEIGHT, c);
924 /* check for newline */
925 if (console_col >= CONSOLE_COLS) {
931 if (console_cursor_is_visible())
935 void video_putc(const char c)
937 #ifdef CONFIG_CFB_CONSOLE_ANSI
941 for (i = 0; i < ansi_buf_size; ++i)
942 parse_putc(ansi_buf[i]);
948 if (ansi_buf_size > 0) {
968 ansi_buf[ansi_buf_size++] = c;
970 if (ansi_buf_size >= sizeof(ansi_buf))
973 for (i = 0; i < ansi_buf_size; ++i) {
979 if (ansi_buf[i] == 27)
986 if (ansi_buf[i] == '[')
993 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
994 num1 = ansi_buf[i]-'0';
996 } else if (ansi_buf[i] != '?') {
1004 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1006 num1 += ansi_buf[i]-'0';
1014 if (ansi_buf[i] != ';') {
1022 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1023 num2 = ansi_buf[i]-'0';
1030 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1032 num2 += ansi_buf[i]-'0';
1040 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1041 || ansi_buf[i] == 'J'
1042 || ansi_buf[i] == 'K'
1043 || ansi_buf[i] == 'h'
1044 || ansi_buf[i] == 'l'
1045 || ansi_buf[i] == 'm') {
1046 cchar = ansi_buf[i];
1055 for (i = 0; i < ansi_buf_size; ++i)
1056 parse_putc(ansi_buf[i]);
1062 if (!ansi_cursor_hidden)
1067 /* move cursor num1 rows up */
1068 console_cursor_up(num1);
1071 /* move cursor num1 rows down */
1072 console_cursor_down(num1);
1075 /* move cursor num1 columns forward */
1076 console_cursor_right(num1);
1079 /* move cursor num1 columns back */
1080 console_cursor_left(num1);
1083 /* move cursor num1 rows up at begin of row */
1084 console_previousline(num1);
1087 /* move cursor num1 rows down at begin of row */
1088 console_newline(num1);
1091 /* move cursor to column num1 */
1092 console_cursor_set_position(-1, num1-1);
1095 /* move cursor to row num1, column num2 */
1096 console_cursor_set_position(num1-1, num2-1);
1099 /* clear console and move cursor to 0, 0 */
1101 console_cursor_set_position(0, 0);
1106 console_clear_line(console_row,
1110 console_clear_line(console_row,
1113 console_clear_line(console_row,
1117 ansi_cursor_hidden = 0;
1120 ansi_cursor_hidden = 1;
1123 if (num1 == 0) { /* reset swapped colors */
1124 if (ansi_colors_need_revert) {
1125 console_swap_colors();
1126 ansi_colors_need_revert = 0;
1128 } else if (num1 == 7) { /* once swap colors */
1129 if (!ansi_colors_need_revert) {
1130 console_swap_colors();
1131 ansi_colors_need_revert = 1;
1136 if (!ansi_cursor_hidden)
1147 void video_puts(const char *s)
1149 int count = strlen(s);
1156 * Do not enforce drivers (or board code) to provide empty
1157 * video_set_lut() if they do not support 8 bpp format.
1158 * Implement weak default function instead.
1160 void __video_set_lut(unsigned int index, unsigned char r,
1161 unsigned char g, unsigned char b)
1165 void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
1166 __attribute__ ((weak, alias("__video_set_lut")));
1168 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
1170 #define FILL_8BIT_332RGB(r,g,b) { \
1171 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1175 #define FILL_15BIT_555RGB(r,g,b) { \
1176 *(unsigned short *)fb = \
1177 SWAP16((unsigned short)(((r>>3)<<10) | \
1183 #define FILL_16BIT_565RGB(r,g,b) { \
1184 *(unsigned short *)fb = \
1185 SWAP16((unsigned short)((((r)>>3)<<11)| \
1191 #define FILL_32BIT_X888RGB(r,g,b) { \
1192 *(unsigned long *)fb = \
1193 SWAP32((unsigned long)(((r<<16) | \
1199 #ifdef VIDEO_FB_LITTLE_ENDIAN
1200 #define FILL_24BIT_888RGB(r,g,b) { \
1207 #define FILL_24BIT_888RGB(r,g,b) { \
1215 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1216 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
1218 ushort *dst = (ushort *) fb;
1219 ushort color = (ushort) (((r >> 3) << 10) |
1230 * RLE8 bitmap support
1233 #ifdef CONFIG_VIDEO_BMP_RLE8
1234 /* Pre-calculated color table entry */
1237 unsigned short w; /* word */
1238 unsigned int dw; /* double word */
1239 } ce; /* color entry */
1243 * Helper to draw encoded/unencoded run.
1245 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1248 ulong addr = (ulong) *fb;
1254 * Setup offset of the color index in the bitmap.
1255 * Color index of encoded run is at offset 1.
1257 off = enc ? &enc_off : &i;
1259 switch (VIDEO_DATA_FORMAT) {
1260 case GDF__8BIT_INDEX:
1261 for (i = 0; i < cnt; i++)
1262 *(unsigned char *) addr++ = bm[*off];
1264 case GDF_15BIT_555RGB:
1265 case GDF_16BIT_565RGB:
1266 /* differences handled while pre-calculating palette */
1267 for (i = 0; i < cnt; i++) {
1268 *(unsigned short *) addr = p[bm[*off]].ce.w;
1272 case GDF_32BIT_X888RGB:
1273 for (i = 0; i < cnt; i++) {
1274 *(unsigned long *) addr = p[bm[*off]].ce.dw;
1279 *fb = (uchar *) addr; /* return modified address */
1282 static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1283 int width, int height)
1287 unsigned int cnt, runlen;
1289 int x, y, bpp, i, ncolors;
1290 struct palette p[256];
1291 bmp_color_table_entry_t cte;
1292 int green_shift, red_off;
1293 int limit = VIDEO_COLS * VIDEO_ROWS;
1297 y = __le32_to_cpu(img->header.height) - 1;
1298 ncolors = __le32_to_cpu(img->header.colors_used);
1299 bpp = VIDEO_PIXEL_SIZE;
1300 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1301 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
1303 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
1305 /* pre-calculate and setup palette */
1306 switch (VIDEO_DATA_FORMAT) {
1307 case GDF__8BIT_INDEX:
1308 for (i = 0; i < ncolors; i++) {
1309 cte = img->color_table[i];
1310 video_set_lut(i, cte.red, cte.green, cte.blue);
1313 case GDF_15BIT_555RGB:
1314 case GDF_16BIT_565RGB:
1315 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1322 for (i = 0; i < ncolors; i++) {
1323 cte = img->color_table[i];
1324 p[i].ce.w = SWAP16((unsigned short)
1325 (((cte.red >> 3) << red_off) |
1326 ((cte.green >> green_shift) << 5) |
1330 case GDF_32BIT_X888RGB:
1331 for (i = 0; i < ncolors; i++) {
1332 cte = img->color_table[i];
1333 p[i].ce.dw = SWAP32((cte.red << 16) |
1339 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1349 /* scan line end marker */
1353 fbp = (unsigned char *)
1354 ((unsigned int) video_fb_address +
1355 (((y + yoff) * VIDEO_COLS) +
1359 /* end of bitmap data marker */
1363 /* run offset marker */
1366 fbp = (unsigned char *)
1367 ((unsigned int) video_fb_address +
1368 (((y + yoff) * VIDEO_COLS) +
1386 if (x + runlen > width)
1388 draw_bitmap(&fbp, bm, p, cnt, 0);
1394 bm++; /* 0 padding if length is odd */
1405 if (y < height) { /* only draw into visible area */
1411 if (x + runlen > width)
1413 draw_bitmap(&fbp, bm, p, cnt, 1);
1422 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1428 * Display the BMP file located at address bmp_image.
1430 int video_display_bitmap(ulong bmp_image, int x, int y)
1432 ushort xcount, ycount;
1434 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1437 unsigned long width, height, bpp;
1439 unsigned long compression;
1440 bmp_color_table_entry_t cte;
1442 #ifdef CONFIG_VIDEO_BMP_GZIP
1443 unsigned char *dst = NULL;
1449 if (!((bmp->header.signature[0] == 'B') &&
1450 (bmp->header.signature[1] == 'M'))) {
1452 #ifdef CONFIG_VIDEO_BMP_GZIP
1454 * Could be a gzipped bmp image, try to decrompress...
1456 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1457 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1459 printf("Error: malloc in gunzip failed!\n");
1462 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1463 (uchar *) bmp_image,
1465 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1470 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1471 printf("Image could be truncated "
1472 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1476 * Set addr to decompressed image
1478 bmp = (bmp_image_t *) dst;
1480 if (!((bmp->header.signature[0] == 'B') &&
1481 (bmp->header.signature[1] == 'M'))) {
1482 printf("Error: no valid bmp.gz image at %lx\n",
1488 printf("Error: no valid bmp image at %lx\n", bmp_image);
1490 #endif /* CONFIG_VIDEO_BMP_GZIP */
1493 width = le32_to_cpu(bmp->header.width);
1494 height = le32_to_cpu(bmp->header.height);
1495 bpp = le16_to_cpu(bmp->header.bit_count);
1496 colors = le32_to_cpu(bmp->header.colors_used);
1497 compression = le32_to_cpu(bmp->header.compression);
1499 debug("Display-bmp: %ld x %ld with %d colors\n",
1500 width, height, colors);
1502 if (compression != BMP_BI_RGB
1503 #ifdef CONFIG_VIDEO_BMP_RLE8
1504 && compression != BMP_BI_RLE8
1507 printf("Error: compression type %ld not supported\n",
1509 #ifdef CONFIG_VIDEO_BMP_GZIP
1516 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1518 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1519 if (x == BMP_ALIGN_CENTER)
1520 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1522 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1524 if (y == BMP_ALIGN_CENTER)
1525 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1527 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1528 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1530 if ((x + width) > VIDEO_VISIBLE_COLS)
1531 width = VIDEO_VISIBLE_COLS - x;
1532 if ((y + height) > VIDEO_VISIBLE_ROWS)
1533 height = VIDEO_VISIBLE_ROWS - y;
1535 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1536 fb = (uchar *) (video_fb_address +
1537 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1538 x * VIDEO_PIXEL_SIZE);
1540 #ifdef CONFIG_VIDEO_BMP_RLE8
1541 if (compression == BMP_BI_RLE8) {
1542 return display_rle8_bitmap(bmp, x, y, width, height);
1546 /* We handle only 4, 8, or 24 bpp bitmaps */
1547 switch (le16_to_cpu(bmp->header.bit_count)) {
1549 padded_line -= width / 2;
1552 switch (VIDEO_DATA_FORMAT) {
1553 case GDF_32BIT_X888RGB:
1557 * Don't assume that 'width' is an
1560 for (xcount = 0; xcount < width; xcount++) {
1568 cte = bmp->color_table[idx];
1569 FILL_32BIT_X888RGB(cte.red, cte.green,
1572 bmap += padded_line;
1573 fb -= (VIDEO_VISIBLE_COLS + width) *
1578 puts("4bpp bitmap unsupported with current "
1585 padded_line -= width;
1586 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1588 for (xcount = 0; xcount < colors; ++xcount) {
1589 cte = bmp->color_table[xcount];
1590 video_set_lut(xcount, cte.red, cte.green,
1595 switch (VIDEO_DATA_FORMAT) {
1596 case GDF__8BIT_INDEX:
1603 bmap += padded_line;
1604 fb -= (VIDEO_VISIBLE_COLS + width) *
1608 case GDF__8BIT_332RGB:
1613 cte = bmp->color_table[*bmap++];
1614 FILL_8BIT_332RGB(cte.red, cte.green,
1617 bmap += padded_line;
1618 fb -= (VIDEO_VISIBLE_COLS + width) *
1622 case GDF_15BIT_555RGB:
1624 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1630 cte = bmp->color_table[*bmap++];
1631 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1632 fill_555rgb_pswap(fb, xpos++, cte.red,
1637 FILL_15BIT_555RGB(cte.red, cte.green,
1641 bmap += padded_line;
1642 fb -= (VIDEO_VISIBLE_COLS + width) *
1646 case GDF_16BIT_565RGB:
1651 cte = bmp->color_table[*bmap++];
1652 FILL_16BIT_565RGB(cte.red, cte.green,
1655 bmap += padded_line;
1656 fb -= (VIDEO_VISIBLE_COLS + width) *
1660 case GDF_32BIT_X888RGB:
1665 cte = bmp->color_table[*bmap++];
1666 FILL_32BIT_X888RGB(cte.red, cte.green,
1669 bmap += padded_line;
1670 fb -= (VIDEO_VISIBLE_COLS + width) *
1674 case GDF_24BIT_888RGB:
1679 cte = bmp->color_table[*bmap++];
1680 FILL_24BIT_888RGB(cte.red, cte.green,
1683 bmap += padded_line;
1684 fb -= (VIDEO_VISIBLE_COLS + width) *
1691 padded_line -= 3 * width;
1693 switch (VIDEO_DATA_FORMAT) {
1694 case GDF__8BIT_332RGB:
1699 FILL_8BIT_332RGB(bmap[2], bmap[1],
1703 bmap += padded_line;
1704 fb -= (VIDEO_VISIBLE_COLS + width) *
1708 case GDF_15BIT_555RGB:
1710 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1716 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1717 fill_555rgb_pswap(fb, xpos++, bmap[2],
1721 FILL_15BIT_555RGB(bmap[2], bmap[1],
1726 bmap += padded_line;
1727 fb -= (VIDEO_VISIBLE_COLS + width) *
1731 case GDF_16BIT_565RGB:
1736 FILL_16BIT_565RGB(bmap[2], bmap[1],
1740 bmap += padded_line;
1741 fb -= (VIDEO_VISIBLE_COLS + width) *
1745 case GDF_32BIT_X888RGB:
1750 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1754 bmap += padded_line;
1755 fb -= (VIDEO_VISIBLE_COLS + width) *
1759 case GDF_24BIT_888RGB:
1764 FILL_24BIT_888RGB(bmap[2], bmap[1],
1768 bmap += padded_line;
1769 fb -= (VIDEO_VISIBLE_COLS + width) *
1774 printf("Error: 24 bits/pixel bitmap incompatible "
1775 "with current video mode\n");
1780 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1781 le16_to_cpu(bmp->header.bit_count));
1785 #ifdef CONFIG_VIDEO_BMP_GZIP
1796 #ifdef CONFIG_VIDEO_LOGO
1797 static int video_logo_xpos;
1798 static int video_logo_ypos;
1800 static void plot_logo_or_black(void *screen, int width, int x, int y, \
1803 static void logo_plot(void *screen, int width, int x, int y)
1805 plot_logo_or_black(screen, width, x, y, 0);
1808 static void logo_black(void)
1810 plot_logo_or_black(video_fb_address, \
1817 static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1820 return cmd_usage(cmdtp);
1827 clrlogo, 1, 0, do_clrlogo,
1828 "fill the boot logo area with black",
1832 static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
1836 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
1837 int ycount = video_logo_height;
1838 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1839 unsigned char *source;
1840 unsigned char *dest;
1842 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1843 if (x == BMP_ALIGN_CENTER)
1844 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1846 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1848 if (y == BMP_ALIGN_CENTER)
1849 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1851 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1852 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1854 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
1856 #ifdef CONFIG_VIDEO_BMP_LOGO
1857 source = bmp_logo_bitmap;
1859 /* Allocate temporary space for computing colormap */
1860 logo_red = malloc(BMP_LOGO_COLORS);
1861 logo_green = malloc(BMP_LOGO_COLORS);
1862 logo_blue = malloc(BMP_LOGO_COLORS);
1863 /* Compute color map */
1864 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1865 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1866 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1867 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1870 source = linux_logo;
1871 logo_red = linux_logo_red;
1872 logo_green = linux_logo_green;
1873 logo_blue = linux_logo_blue;
1876 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1877 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1878 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1879 logo_red[i], logo_green[i],
1885 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1888 xcount = VIDEO_LOGO_WIDTH;
1895 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1896 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1897 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1900 switch (VIDEO_DATA_FORMAT) {
1901 case GDF__8BIT_INDEX:
1904 case GDF__8BIT_332RGB:
1905 *dest = ((r >> 5) << 5) |
1909 case GDF_15BIT_555RGB:
1910 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1911 fill_555rgb_pswap(dest, xpos++, r, g, b);
1913 *(unsigned short *) dest =
1914 SWAP16((unsigned short) (
1920 case GDF_16BIT_565RGB:
1921 *(unsigned short *) dest =
1922 SWAP16((unsigned short) (
1927 case GDF_32BIT_X888RGB:
1928 *(unsigned long *) dest =
1929 SWAP32((unsigned long) (
1934 case GDF_24BIT_888RGB:
1935 #ifdef VIDEO_FB_LITTLE_ENDIAN
1947 dest += VIDEO_PIXEL_SIZE;
1951 #ifdef CONFIG_VIDEO_BMP_LOGO
1958 static void *video_logo(void)
1962 __maybe_unused int y_off = 0;
1963 __maybe_unused ulong addr;
1964 __maybe_unused char *s;
1966 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1967 s = getenv("splashpos");
1970 video_logo_xpos = BMP_ALIGN_CENTER;
1972 video_logo_xpos = simple_strtol(s, NULL, 0);
1974 s = strchr(s + 1, ',');
1977 video_logo_ypos = BMP_ALIGN_CENTER;
1979 video_logo_ypos = simple_strtol(s + 1, NULL, 0);
1982 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1984 #ifdef CONFIG_SPLASH_SCREEN
1985 s = getenv("splashimage");
1988 addr = simple_strtoul(s, NULL, 16);
1991 if (video_display_bitmap(addr,
1993 video_logo_ypos) == 0) {
1994 video_logo_height = 0;
1995 return ((void *) (video_fb_address));
1998 #endif /* CONFIG_SPLASH_SCREEN */
2000 logo_plot(video_fb_address, VIDEO_COLS,
2001 video_logo_xpos, video_logo_ypos);
2003 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
2005 * when using splashpos for video_logo, skip any info
2006 * output on video console if the logo is not at 0,0
2008 if (video_logo_xpos || video_logo_ypos) {
2010 * video_logo_height is used in text and cursor offset
2011 * calculations. Since the console is below the logo,
2012 * we need to adjust the logo height
2014 if (video_logo_ypos == BMP_ALIGN_CENTER)
2015 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
2016 VIDEO_LOGO_HEIGHT) / 2);
2017 else if (video_logo_ypos > 0)
2018 video_logo_height += video_logo_ypos;
2020 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2024 sprintf(info, " %s", version_string);
2026 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2030 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2031 (uchar *) info, space);
2032 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2033 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2034 (uchar *) info + space, len - space);
2037 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
2039 #ifdef CONFIG_CONSOLE_EXTRA_INFO
2042 ((video_logo_height -
2043 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
2045 for (i = 1; i < n; i++) {
2046 video_get_info_str(i, info);
2052 video_drawchars(VIDEO_INFO_X,
2056 (uchar *) info, space);
2058 video_drawchars(VIDEO_INFO_X +
2063 (uchar *) info + space,
2066 video_drawstring(VIDEO_INFO_X,
2076 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
2080 static int cfb_fb_is_in_dram(void)
2083 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2084 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2088 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2089 start = bd->bi_dram[i].start;
2090 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2091 if ((ulong)video_fb_address >= start &&
2092 (ulong)video_fb_address < end)
2096 if ((ulong)video_fb_address >= bd->bi_memstart &&
2097 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2103 static int video_init(void)
2105 unsigned char color8;
2107 pGD = video_hw_init();
2111 video_fb_address = (void *) VIDEO_FB_ADRS;
2112 #ifdef CONFIG_VIDEO_HW_CURSOR
2113 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
2116 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2118 /* Init drawing pats */
2119 switch (VIDEO_DATA_FORMAT) {
2120 case GDF__8BIT_INDEX:
2121 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2123 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2128 case GDF__8BIT_332RGB:
2129 color8 = ((CONSOLE_FG_COL & 0xe0) |
2130 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2131 CONSOLE_FG_COL >> 6);
2132 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2134 color8 = ((CONSOLE_BG_COL & 0xe0) |
2135 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2136 CONSOLE_BG_COL >> 6);
2137 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2140 case GDF_15BIT_555RGB:
2141 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
2142 ((CONSOLE_FG_COL >> 3) << 21) |
2143 ((CONSOLE_FG_COL >> 3) << 16) |
2144 ((CONSOLE_FG_COL >> 3) << 10) |
2145 ((CONSOLE_FG_COL >> 3) << 5) |
2146 (CONSOLE_FG_COL >> 3));
2147 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
2148 ((CONSOLE_BG_COL >> 3) << 21) |
2149 ((CONSOLE_BG_COL >> 3) << 16) |
2150 ((CONSOLE_BG_COL >> 3) << 10) |
2151 ((CONSOLE_BG_COL >> 3) << 5) |
2152 (CONSOLE_BG_COL >> 3));
2154 case GDF_16BIT_565RGB:
2155 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
2156 ((CONSOLE_FG_COL >> 2) << 21) |
2157 ((CONSOLE_FG_COL >> 3) << 16) |
2158 ((CONSOLE_FG_COL >> 3) << 11) |
2159 ((CONSOLE_FG_COL >> 2) << 5) |
2160 (CONSOLE_FG_COL >> 3));
2161 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
2162 ((CONSOLE_BG_COL >> 2) << 21) |
2163 ((CONSOLE_BG_COL >> 3) << 16) |
2164 ((CONSOLE_BG_COL >> 3) << 11) |
2165 ((CONSOLE_BG_COL >> 2) << 5) |
2166 (CONSOLE_BG_COL >> 3));
2168 case GDF_32BIT_X888RGB:
2169 fgx = (CONSOLE_FG_COL << 16) |
2170 (CONSOLE_FG_COL << 8) |
2172 bgx = (CONSOLE_BG_COL << 16) |
2173 (CONSOLE_BG_COL << 8) |
2176 case GDF_24BIT_888RGB:
2177 fgx = (CONSOLE_FG_COL << 24) |
2178 (CONSOLE_FG_COL << 16) |
2179 (CONSOLE_FG_COL << 8) |
2181 bgx = (CONSOLE_BG_COL << 24) |
2182 (CONSOLE_BG_COL << 16) |
2183 (CONSOLE_BG_COL << 8) |
2189 #ifdef CONFIG_VIDEO_LOGO
2190 /* Plot the logo and get start point of console */
2191 debug("Video: Drawing the logo ...\n");
2192 video_console_address = video_logo();
2194 video_console_address = video_fb_address;
2197 /* Initialize the console */
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 */