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 static const int video_font_draw_table8[] = {
389 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
390 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
391 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
392 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
395 static const int video_font_draw_table15[] = {
396 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
399 static const int video_font_draw_table16[] = {
400 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
403 static const int video_font_draw_table24[16][3] = {
404 {0x00000000, 0x00000000, 0x00000000},
405 {0x00000000, 0x00000000, 0x00ffffff},
406 {0x00000000, 0x0000ffff, 0xff000000},
407 {0x00000000, 0x0000ffff, 0xffffffff},
408 {0x000000ff, 0xffff0000, 0x00000000},
409 {0x000000ff, 0xffff0000, 0x00ffffff},
410 {0x000000ff, 0xffffffff, 0xff000000},
411 {0x000000ff, 0xffffffff, 0xffffffff},
412 {0xffffff00, 0x00000000, 0x00000000},
413 {0xffffff00, 0x00000000, 0x00ffffff},
414 {0xffffff00, 0x0000ffff, 0xff000000},
415 {0xffffff00, 0x0000ffff, 0xffffffff},
416 {0xffffffff, 0xffff0000, 0x00000000},
417 {0xffffffff, 0xffff0000, 0x00ffffff},
418 {0xffffffff, 0xffffffff, 0xff000000},
419 {0xffffffff, 0xffffffff, 0xffffffff}
422 static const int video_font_draw_table32[16][4] = {
423 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
424 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
425 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
426 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
427 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
428 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
429 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
430 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
431 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
432 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
433 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
434 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
435 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
436 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
437 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
438 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
441 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
443 u8 *cdat, *dest, *dest0;
446 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
447 dest0 = video_fb_address + offset;
449 switch (VIDEO_DATA_FORMAT) {
450 case GDF__8BIT_INDEX:
451 case GDF__8BIT_332RGB:
454 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
455 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
456 rows--; dest += VIDEO_LINE_LEN) {
460 (video_font_draw_table8[bits >> 4] &
463 (video_font_draw_table8[bits & 15] &
466 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
471 case GDF_15BIT_555RGB:
474 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
475 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
476 rows--; dest += VIDEO_LINE_LEN) {
480 SHORTSWAP32((video_font_draw_table15
481 [bits >> 6] & eorx) ^
484 SHORTSWAP32((video_font_draw_table15
485 [bits >> 4 & 3] & eorx) ^
488 SHORTSWAP32((video_font_draw_table15
489 [bits >> 2 & 3] & eorx) ^
492 SHORTSWAP32((video_font_draw_table15
496 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
501 case GDF_16BIT_565RGB:
504 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
505 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
506 rows--; dest += VIDEO_LINE_LEN) {
510 SHORTSWAP32((video_font_draw_table16
511 [bits >> 6] & eorx) ^
514 SHORTSWAP32((video_font_draw_table16
515 [bits >> 4 & 3] & eorx) ^
518 SHORTSWAP32((video_font_draw_table16
519 [bits >> 2 & 3] & eorx) ^
522 SHORTSWAP32((video_font_draw_table16
526 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
531 case GDF_32BIT_X888RGB:
534 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
535 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
536 rows--; dest += VIDEO_LINE_LEN) {
540 SWAP32((video_font_draw_table32
541 [bits >> 4][0] & eorx) ^ bgx);
543 SWAP32((video_font_draw_table32
544 [bits >> 4][1] & eorx) ^ bgx);
546 SWAP32((video_font_draw_table32
547 [bits >> 4][2] & eorx) ^ bgx);
549 SWAP32((video_font_draw_table32
550 [bits >> 4][3] & eorx) ^ bgx);
552 SWAP32((video_font_draw_table32
553 [bits & 15][0] & eorx) ^ bgx);
555 SWAP32((video_font_draw_table32
556 [bits & 15][1] & eorx) ^ bgx);
558 SWAP32((video_font_draw_table32
559 [bits & 15][2] & eorx) ^ bgx);
561 SWAP32((video_font_draw_table32
562 [bits & 15][3] & eorx) ^ bgx);
564 if (cfb_do_flush_cache)
565 flush_cache((ulong)dest0, 32);
566 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
571 case GDF_24BIT_888RGB:
574 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
575 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
576 rows--; dest += VIDEO_LINE_LEN) {
580 (video_font_draw_table24[bits >> 4][0]
583 (video_font_draw_table24[bits >> 4][1]
586 (video_font_draw_table24[bits >> 4][2]
589 (video_font_draw_table24[bits & 15][0]
592 (video_font_draw_table24[bits & 15][1]
595 (video_font_draw_table24[bits & 15][2]
598 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
605 static inline void video_drawstring(int xx, int yy, unsigned char *s)
607 video_drawchars(xx, yy, s, strlen((char *) s));
610 static void video_putchar(int xx, int yy, unsigned char c)
612 video_drawchars(xx, yy + video_logo_height, &c, 1);
615 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
616 static void video_set_cursor(void)
623 static void video_invertchar(int xx, int yy)
625 int firstx = xx * VIDEO_PIXEL_SIZE;
626 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
627 int firsty = yy * VIDEO_LINE_LEN;
628 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
630 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
631 for (x = firstx; x < lastx; x++) {
632 u8 *dest = (u8 *)(video_fb_address) + x + y;
634 if (cfb_do_flush_cache)
635 flush_cache((ulong)dest, 4);
640 void console_cursor(int state)
642 #ifdef CONFIG_CONSOLE_TIME
646 /* time update only if cursor is on (faster scroll) */
650 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
652 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
653 VIDEO_INFO_Y, (uchar *) info);
655 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
657 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
658 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
663 if (cursor_state != state) {
665 /* turn off the cursor */
666 video_invertchar(old_col * VIDEO_FONT_WIDTH,
667 old_row * VIDEO_FONT_HEIGHT +
670 /* turn off the cursor and record where it is */
671 video_invertchar(console_col * VIDEO_FONT_WIDTH,
672 console_row * VIDEO_FONT_HEIGHT +
674 old_col = console_col;
675 old_row = console_row;
677 cursor_state = state;
682 #ifndef VIDEO_HW_RECTFILL
683 static void memsetl(int *p, int c, int v)
690 #ifndef VIDEO_HW_BITBLT
691 static void memcpyl(int *d, int *s, int c)
698 static void console_clear_line(int line, int begin, int end)
700 #ifdef VIDEO_HW_RECTFILL
701 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
702 VIDEO_FONT_WIDTH * begin, /* dest pos x */
704 VIDEO_FONT_HEIGHT * line, /* dest pos y */
705 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
706 VIDEO_FONT_HEIGHT, /* frame height */
710 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
711 memsetl(CONSOLE_ROW_FIRST +
712 CONSOLE_ROW_SIZE * line, /* offset of row */
713 CONSOLE_ROW_SIZE >> 2, /* length of row */
720 offset = CONSOLE_ROW_FIRST +
721 CONSOLE_ROW_SIZE * line + /* offset of row */
723 VIDEO_PIXEL_SIZE * begin; /* offset of col */
724 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
725 size >>= 2; /* length to end for memsetl() */
726 /* fill at col offset of i'th line using bgx as fill color */
727 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
728 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
731 if (cfb_do_flush_cache)
732 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
735 static void console_scrollup(void)
737 /* copy up rows ignoring the first one */
739 #ifdef VIDEO_HW_BITBLT
740 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
741 0, /* source pos x */
743 VIDEO_FONT_HEIGHT, /* source pos y */
745 video_logo_height, /* dest pos y */
746 VIDEO_VISIBLE_COLS, /* frame width */
749 - VIDEO_FONT_HEIGHT /* frame height */
752 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
753 CONSOLE_SCROLL_SIZE >> 2);
755 /* clear the last one */
756 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
759 static void console_back(void)
763 if (console_col < 0) {
764 console_col = CONSOLE_COLS - 1;
771 static void console_newline(void)
776 /* Check if we need to scroll the terminal */
777 if (console_row >= CONSOLE_ROWS) {
778 /* Scroll everything up */
781 /* Decrement row number */
786 static void console_cr(void)
791 void video_putc(const char c)
798 case 13: /* back to first column */
802 case '\n': /* next line */
803 if (console_col || (!console_col && nl))
809 console_col |= 0x0008;
810 console_col &= ~0x0007;
812 if (console_col >= CONSOLE_COLS)
816 case 8: /* backspace */
823 default: /* draw the char */
824 video_putchar(console_col * VIDEO_FONT_WIDTH,
825 console_row * VIDEO_FONT_HEIGHT, c);
828 /* check for newline */
829 if (console_col >= CONSOLE_COLS) {
837 void video_puts(const char *s)
839 int count = strlen(s);
846 * Do not enforce drivers (or board code) to provide empty
847 * video_set_lut() if they do not support 8 bpp format.
848 * Implement weak default function instead.
850 void __video_set_lut(unsigned int index, unsigned char r,
851 unsigned char g, unsigned char b)
855 void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
856 __attribute__ ((weak, alias("__video_set_lut")));
858 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
860 #define FILL_8BIT_332RGB(r,g,b) { \
861 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
865 #define FILL_15BIT_555RGB(r,g,b) { \
866 *(unsigned short *)fb = \
867 SWAP16((unsigned short)(((r>>3)<<10) | \
873 #define FILL_16BIT_565RGB(r,g,b) { \
874 *(unsigned short *)fb = \
875 SWAP16((unsigned short)((((r)>>3)<<11)| \
881 #define FILL_32BIT_X888RGB(r,g,b) { \
882 *(unsigned long *)fb = \
883 SWAP32((unsigned long)(((r<<16) | \
889 #ifdef VIDEO_FB_LITTLE_ENDIAN
890 #define FILL_24BIT_888RGB(r,g,b) { \
897 #define FILL_24BIT_888RGB(r,g,b) { \
905 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
906 static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
908 ushort *dst = (ushort *) fb;
909 ushort color = (ushort) (((r >> 3) << 10) |
920 * RLE8 bitmap support
923 #ifdef CONFIG_VIDEO_BMP_RLE8
924 /* Pre-calculated color table entry */
927 unsigned short w; /* word */
928 unsigned int dw; /* double word */
929 } ce; /* color entry */
933 * Helper to draw encoded/unencoded run.
935 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
938 ulong addr = (ulong) *fb;
944 * Setup offset of the color index in the bitmap.
945 * Color index of encoded run is at offset 1.
947 off = enc ? &enc_off : &i;
949 switch (VIDEO_DATA_FORMAT) {
950 case GDF__8BIT_INDEX:
951 for (i = 0; i < cnt; i++)
952 *(unsigned char *) addr++ = bm[*off];
954 case GDF_15BIT_555RGB:
955 case GDF_16BIT_565RGB:
956 /* differences handled while pre-calculating palette */
957 for (i = 0; i < cnt; i++) {
958 *(unsigned short *) addr = p[bm[*off]].ce.w;
962 case GDF_32BIT_X888RGB:
963 for (i = 0; i < cnt; i++) {
964 *(unsigned long *) addr = p[bm[*off]].ce.dw;
969 *fb = (uchar *) addr; /* return modified address */
972 static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
973 int width, int height)
977 unsigned int cnt, runlen;
979 int x, y, bpp, i, ncolors;
980 struct palette p[256];
981 bmp_color_table_entry_t cte;
982 int green_shift, red_off;
983 int limit = VIDEO_COLS * VIDEO_ROWS;
987 y = __le32_to_cpu(img->header.height) - 1;
988 ncolors = __le32_to_cpu(img->header.colors_used);
989 bpp = VIDEO_PIXEL_SIZE;
990 fbp = (unsigned char *) ((unsigned int) video_fb_address +
991 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
993 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
995 /* pre-calculate and setup palette */
996 switch (VIDEO_DATA_FORMAT) {
997 case GDF__8BIT_INDEX:
998 for (i = 0; i < ncolors; i++) {
999 cte = img->color_table[i];
1000 video_set_lut(i, cte.red, cte.green, cte.blue);
1003 case GDF_15BIT_555RGB:
1004 case GDF_16BIT_565RGB:
1005 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1012 for (i = 0; i < ncolors; i++) {
1013 cte = img->color_table[i];
1014 p[i].ce.w = SWAP16((unsigned short)
1015 (((cte.red >> 3) << red_off) |
1016 ((cte.green >> green_shift) << 5) |
1020 case GDF_32BIT_X888RGB:
1021 for (i = 0; i < ncolors; i++) {
1022 cte = img->color_table[i];
1023 p[i].ce.dw = SWAP32((cte.red << 16) |
1029 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1039 /* scan line end marker */
1043 fbp = (unsigned char *)
1044 ((unsigned int) video_fb_address +
1045 (((y + yoff) * VIDEO_COLS) +
1049 /* end of bitmap data marker */
1053 /* run offset marker */
1056 fbp = (unsigned char *)
1057 ((unsigned int) video_fb_address +
1058 (((y + yoff) * VIDEO_COLS) +
1076 if (x + runlen > width)
1078 draw_bitmap(&fbp, bm, p, cnt, 0);
1084 bm++; /* 0 padding if length is odd */
1095 if (y < height) { /* only draw into visible area */
1101 if (x + runlen > width)
1103 draw_bitmap(&fbp, bm, p, cnt, 1);
1112 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1118 * Display the BMP file located at address bmp_image.
1120 int video_display_bitmap(ulong bmp_image, int x, int y)
1122 ushort xcount, ycount;
1124 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1127 unsigned long width, height, bpp;
1129 unsigned long compression;
1130 bmp_color_table_entry_t cte;
1132 #ifdef CONFIG_VIDEO_BMP_GZIP
1133 unsigned char *dst = NULL;
1139 if (!((bmp->header.signature[0] == 'B') &&
1140 (bmp->header.signature[1] == 'M'))) {
1142 #ifdef CONFIG_VIDEO_BMP_GZIP
1144 * Could be a gzipped bmp image, try to decrompress...
1146 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1147 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1149 printf("Error: malloc in gunzip failed!\n");
1152 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1153 (uchar *) bmp_image,
1155 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1160 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1161 printf("Image could be truncated "
1162 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1166 * Set addr to decompressed image
1168 bmp = (bmp_image_t *) dst;
1170 if (!((bmp->header.signature[0] == 'B') &&
1171 (bmp->header.signature[1] == 'M'))) {
1172 printf("Error: no valid bmp.gz image at %lx\n",
1178 printf("Error: no valid bmp image at %lx\n", bmp_image);
1180 #endif /* CONFIG_VIDEO_BMP_GZIP */
1183 width = le32_to_cpu(bmp->header.width);
1184 height = le32_to_cpu(bmp->header.height);
1185 bpp = le16_to_cpu(bmp->header.bit_count);
1186 colors = le32_to_cpu(bmp->header.colors_used);
1187 compression = le32_to_cpu(bmp->header.compression);
1189 debug("Display-bmp: %ld x %ld with %d colors\n",
1190 width, height, colors);
1192 if (compression != BMP_BI_RGB
1193 #ifdef CONFIG_VIDEO_BMP_RLE8
1194 && compression != BMP_BI_RLE8
1197 printf("Error: compression type %ld not supported\n",
1199 #ifdef CONFIG_VIDEO_BMP_GZIP
1206 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1208 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1209 if (x == BMP_ALIGN_CENTER)
1210 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1212 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1214 if (y == BMP_ALIGN_CENTER)
1215 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1217 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1218 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1220 if ((x + width) > VIDEO_VISIBLE_COLS)
1221 width = VIDEO_VISIBLE_COLS - x;
1222 if ((y + height) > VIDEO_VISIBLE_ROWS)
1223 height = VIDEO_VISIBLE_ROWS - y;
1225 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
1226 fb = (uchar *) (video_fb_address +
1227 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1228 x * VIDEO_PIXEL_SIZE);
1230 #ifdef CONFIG_VIDEO_BMP_RLE8
1231 if (compression == BMP_BI_RLE8) {
1232 return display_rle8_bitmap(bmp, x, y, width, height);
1236 /* We handle only 4, 8, or 24 bpp bitmaps */
1237 switch (le16_to_cpu(bmp->header.bit_count)) {
1239 padded_line -= width / 2;
1242 switch (VIDEO_DATA_FORMAT) {
1243 case GDF_32BIT_X888RGB:
1247 * Don't assume that 'width' is an
1250 for (xcount = 0; xcount < width; xcount++) {
1258 cte = bmp->color_table[idx];
1259 FILL_32BIT_X888RGB(cte.red, cte.green,
1262 bmap += padded_line;
1263 fb -= (VIDEO_VISIBLE_COLS + width) *
1268 puts("4bpp bitmap unsupported with current "
1275 padded_line -= width;
1276 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1278 for (xcount = 0; xcount < colors; ++xcount) {
1279 cte = bmp->color_table[xcount];
1280 video_set_lut(xcount, cte.red, cte.green,
1285 switch (VIDEO_DATA_FORMAT) {
1286 case GDF__8BIT_INDEX:
1293 bmap += padded_line;
1294 fb -= (VIDEO_VISIBLE_COLS + width) *
1298 case GDF__8BIT_332RGB:
1303 cte = bmp->color_table[*bmap++];
1304 FILL_8BIT_332RGB(cte.red, cte.green,
1307 bmap += padded_line;
1308 fb -= (VIDEO_VISIBLE_COLS + width) *
1312 case GDF_15BIT_555RGB:
1314 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1320 cte = bmp->color_table[*bmap++];
1321 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1322 fill_555rgb_pswap(fb, xpos++, cte.red,
1327 FILL_15BIT_555RGB(cte.red, cte.green,
1331 bmap += padded_line;
1332 fb -= (VIDEO_VISIBLE_COLS + width) *
1336 case GDF_16BIT_565RGB:
1341 cte = bmp->color_table[*bmap++];
1342 FILL_16BIT_565RGB(cte.red, cte.green,
1345 bmap += padded_line;
1346 fb -= (VIDEO_VISIBLE_COLS + width) *
1350 case GDF_32BIT_X888RGB:
1355 cte = bmp->color_table[*bmap++];
1356 FILL_32BIT_X888RGB(cte.red, cte.green,
1359 bmap += padded_line;
1360 fb -= (VIDEO_VISIBLE_COLS + width) *
1364 case GDF_24BIT_888RGB:
1369 cte = bmp->color_table[*bmap++];
1370 FILL_24BIT_888RGB(cte.red, cte.green,
1373 bmap += padded_line;
1374 fb -= (VIDEO_VISIBLE_COLS + width) *
1381 padded_line -= 3 * width;
1383 switch (VIDEO_DATA_FORMAT) {
1384 case GDF__8BIT_332RGB:
1389 FILL_8BIT_332RGB(bmap[2], bmap[1],
1393 bmap += padded_line;
1394 fb -= (VIDEO_VISIBLE_COLS + width) *
1398 case GDF_15BIT_555RGB:
1400 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1406 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1407 fill_555rgb_pswap(fb, xpos++, bmap[2],
1411 FILL_15BIT_555RGB(bmap[2], bmap[1],
1416 bmap += padded_line;
1417 fb -= (VIDEO_VISIBLE_COLS + width) *
1421 case GDF_16BIT_565RGB:
1426 FILL_16BIT_565RGB(bmap[2], bmap[1],
1430 bmap += padded_line;
1431 fb -= (VIDEO_VISIBLE_COLS + width) *
1435 case GDF_32BIT_X888RGB:
1440 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1444 bmap += padded_line;
1445 fb -= (VIDEO_VISIBLE_COLS + width) *
1449 case GDF_24BIT_888RGB:
1454 FILL_24BIT_888RGB(bmap[2], bmap[1],
1458 bmap += padded_line;
1459 fb -= (VIDEO_VISIBLE_COLS + width) *
1464 printf("Error: 24 bits/pixel bitmap incompatible "
1465 "with current video mode\n");
1470 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1471 le16_to_cpu(bmp->header.bit_count));
1475 #ifdef CONFIG_VIDEO_BMP_GZIP
1486 #ifdef CONFIG_VIDEO_LOGO
1487 static int video_logo_xpos;
1488 static int video_logo_ypos;
1490 void logo_plot(void *screen, int width, int x, int y)
1494 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
1495 int ycount = video_logo_height;
1496 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1497 unsigned char *source;
1498 unsigned char *dest;
1500 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1501 if (x == BMP_ALIGN_CENTER)
1502 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1504 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1506 if (y == BMP_ALIGN_CENTER)
1507 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1509 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1510 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1512 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
1514 #ifdef CONFIG_VIDEO_BMP_LOGO
1515 source = bmp_logo_bitmap;
1517 /* Allocate temporary space for computing colormap */
1518 logo_red = malloc(BMP_LOGO_COLORS);
1519 logo_green = malloc(BMP_LOGO_COLORS);
1520 logo_blue = malloc(BMP_LOGO_COLORS);
1521 /* Compute color map */
1522 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1523 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1524 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1525 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1528 source = linux_logo;
1529 logo_red = linux_logo_red;
1530 logo_green = linux_logo_green;
1531 logo_blue = linux_logo_blue;
1534 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1535 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1536 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1537 logo_red[i], logo_green[i],
1543 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1546 xcount = VIDEO_LOGO_WIDTH;
1548 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1549 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1550 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1552 switch (VIDEO_DATA_FORMAT) {
1553 case GDF__8BIT_INDEX:
1556 case GDF__8BIT_332RGB:
1557 *dest = ((r >> 5) << 5) |
1561 case GDF_15BIT_555RGB:
1562 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1563 fill_555rgb_pswap(dest, xpos++, r, g, b);
1565 *(unsigned short *) dest =
1566 SWAP16((unsigned short) (
1572 case GDF_16BIT_565RGB:
1573 *(unsigned short *) dest =
1574 SWAP16((unsigned short) (
1579 case GDF_32BIT_X888RGB:
1580 *(unsigned long *) dest =
1581 SWAP32((unsigned long) (
1586 case GDF_24BIT_888RGB:
1587 #ifdef VIDEO_FB_LITTLE_ENDIAN
1599 dest += VIDEO_PIXEL_SIZE;
1603 #ifdef CONFIG_VIDEO_BMP_LOGO
1610 static void *video_logo(void)
1614 __maybe_unused int y_off = 0;
1615 __maybe_unused ulong addr;
1616 __maybe_unused char *s;
1618 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1619 s = getenv("splashpos");
1622 video_logo_xpos = BMP_ALIGN_CENTER;
1624 video_logo_xpos = simple_strtol(s, NULL, 0);
1626 s = strchr(s + 1, ',');
1629 video_logo_ypos = BMP_ALIGN_CENTER;
1631 video_logo_ypos = simple_strtol(s + 1, NULL, 0);
1634 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1636 #ifdef CONFIG_SPLASH_SCREEN
1637 s = getenv("splashimage");
1640 addr = simple_strtoul(s, NULL, 16);
1643 if (video_display_bitmap(addr,
1645 video_logo_ypos) == 0) {
1646 video_logo_height = 0;
1647 return ((void *) (video_fb_address));
1650 #endif /* CONFIG_SPLASH_SCREEN */
1652 logo_plot(video_fb_address, VIDEO_COLS,
1653 video_logo_xpos, video_logo_ypos);
1655 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1657 * when using splashpos for video_logo, skip any info
1658 * output on video console if the logo is not at 0,0
1660 if (video_logo_xpos || video_logo_ypos) {
1662 * video_logo_height is used in text and cursor offset
1663 * calculations. Since the console is below the logo,
1664 * we need to adjust the logo height
1666 if (video_logo_ypos == BMP_ALIGN_CENTER)
1667 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
1668 VIDEO_LOGO_HEIGHT) / 2);
1669 else if (video_logo_ypos > 0)
1670 video_logo_height += video_logo_ypos;
1672 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1676 sprintf(info, " %s", version_string);
1678 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1682 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1683 (uchar *) info, space);
1684 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1685 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1686 (uchar *) info + space, len - space);
1689 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1691 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1694 ((video_logo_height -
1695 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1697 for (i = 1; i < n; i++) {
1698 video_get_info_str(i, info);
1704 video_drawchars(VIDEO_INFO_X,
1708 (uchar *) info, space);
1710 video_drawchars(VIDEO_INFO_X +
1715 (uchar *) info + space,
1718 video_drawstring(VIDEO_INFO_X,
1728 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1732 static int cfb_fb_is_in_dram(void)
1735 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1736 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1740 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1741 start = bd->bi_dram[i].start;
1742 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1743 if ((ulong)video_fb_address >= start &&
1744 (ulong)video_fb_address < end)
1748 if ((ulong)video_fb_address >= bd->bi_memstart &&
1749 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1755 static int video_init(void)
1757 unsigned char color8;
1759 pGD = video_hw_init();
1763 video_fb_address = (void *) VIDEO_FB_ADRS;
1764 #ifdef CONFIG_VIDEO_HW_CURSOR
1765 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
1768 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
1770 /* Init drawing pats */
1771 switch (VIDEO_DATA_FORMAT) {
1772 case GDF__8BIT_INDEX:
1773 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
1775 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1780 case GDF__8BIT_332RGB:
1781 color8 = ((CONSOLE_FG_COL & 0xe0) |
1782 ((CONSOLE_FG_COL >> 3) & 0x1c) |
1783 CONSOLE_FG_COL >> 6);
1784 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1786 color8 = ((CONSOLE_BG_COL & 0xe0) |
1787 ((CONSOLE_BG_COL >> 3) & 0x1c) |
1788 CONSOLE_BG_COL >> 6);
1789 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1792 case GDF_15BIT_555RGB:
1793 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
1794 ((CONSOLE_FG_COL >> 3) << 21) |
1795 ((CONSOLE_FG_COL >> 3) << 16) |
1796 ((CONSOLE_FG_COL >> 3) << 10) |
1797 ((CONSOLE_FG_COL >> 3) << 5) |
1798 (CONSOLE_FG_COL >> 3));
1799 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
1800 ((CONSOLE_BG_COL >> 3) << 21) |
1801 ((CONSOLE_BG_COL >> 3) << 16) |
1802 ((CONSOLE_BG_COL >> 3) << 10) |
1803 ((CONSOLE_BG_COL >> 3) << 5) |
1804 (CONSOLE_BG_COL >> 3));
1806 case GDF_16BIT_565RGB:
1807 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
1808 ((CONSOLE_FG_COL >> 2) << 21) |
1809 ((CONSOLE_FG_COL >> 3) << 16) |
1810 ((CONSOLE_FG_COL >> 3) << 11) |
1811 ((CONSOLE_FG_COL >> 2) << 5) |
1812 (CONSOLE_FG_COL >> 3));
1813 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
1814 ((CONSOLE_BG_COL >> 2) << 21) |
1815 ((CONSOLE_BG_COL >> 3) << 16) |
1816 ((CONSOLE_BG_COL >> 3) << 11) |
1817 ((CONSOLE_BG_COL >> 2) << 5) |
1818 (CONSOLE_BG_COL >> 3));
1820 case GDF_32BIT_X888RGB:
1821 fgx = (CONSOLE_FG_COL << 16) |
1822 (CONSOLE_FG_COL << 8) |
1824 bgx = (CONSOLE_BG_COL << 16) |
1825 (CONSOLE_BG_COL << 8) |
1828 case GDF_24BIT_888RGB:
1829 fgx = (CONSOLE_FG_COL << 24) |
1830 (CONSOLE_FG_COL << 16) |
1831 (CONSOLE_FG_COL << 8) |
1833 bgx = (CONSOLE_BG_COL << 24) |
1834 (CONSOLE_BG_COL << 16) |
1835 (CONSOLE_BG_COL << 8) |
1841 #ifdef CONFIG_VIDEO_LOGO
1842 /* Plot the logo and get start point of console */
1843 debug("Video: Drawing the logo ...\n");
1844 video_console_address = video_logo();
1846 video_console_address = video_fb_address;
1849 /* Initialize the console */
1857 * Implement a weak default function for boards that optionally
1858 * need to skip the video initialization.
1860 int __board_video_skip(void)
1862 /* As default, don't skip test */
1866 int board_video_skip(void)
1867 __attribute__ ((weak, alias("__board_video_skip")));
1869 int drv_video_init(void)
1872 struct stdio_dev console_dev;
1874 /* Check if video initialization should be skipped */
1875 if (board_video_skip())
1878 /* Init video chip - returns with framebuffer cleared */
1879 skip_dev_init = (video_init() == -1);
1881 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1882 debug("KBD: Keyboard init ...\n");
1883 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1889 /* Init vga device */
1890 memset(&console_dev, 0, sizeof(console_dev));
1891 strcpy(console_dev.name, "vga");
1892 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1893 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1894 console_dev.putc = video_putc; /* 'putc' function */
1895 console_dev.puts = video_puts; /* 'puts' function */
1896 console_dev.tstc = NULL; /* 'tstc' function */
1897 console_dev.getc = NULL; /* 'getc' function */
1899 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1900 /* Also init console device */
1901 console_dev.flags |= DEV_FLAGS_INPUT;
1902 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1903 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
1904 #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
1906 if (stdio_register(&console_dev) != 0)
1909 /* Return success */