* Patch by Paul Ruhland, 17 May 2004:
[platform/kernel/u-boot.git] / drivers / cfb_console.c
1 /*
2  * (C) Copyright 2002 ELTEC Elektronik AG
3  * Frank Gottschling <fgottschling@eltec.de>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
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.
12  *
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.
17  *
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,
21  * MA 02111-1307 USA
22  */
23
24 /*
25  * cfb_console.c
26  *
27  * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
28  *
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 normaly goes to serial port) can be drawed.
33  *
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.
39
40  The driver uses graphic specific defines/parameters/functions:
41
42  (for SMI LynxE graphic chip)
43
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
48
49  Console Parameters are set by graphic drivers global struct:
50
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
56
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
61
62  CONFIG_CONSOLE_CURSOR       - on/off drawing cursor is done with delay
63                                loop in VIDEO_TSTC_FCT (i8042)
64  CFG_CONSOLE_BLINK_COUNT     - value for delay loop - blink rate
65  CONFIG_CONSOLE_TIME         - display time/date in upper right corner,
66                                needs CFG_CMD_DATE and CONFIG_CONSOLE_CURSOR
67  CONFIG_VIDEO_LOGO           - display Linux Logo in upper left corner
68  CONFIG_VIDEO_BMP_LOGO       - use bmp_logo instead of linux_logo
69  CONFIG_CONSOLE_EXTRA_INFO   - display additional board information strings
70                                that normaly goes to serial port. This define
71                                requires a board specific function:
72                                video_drawstring (VIDEO_INFO_X,
73                                                  VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
74                                                  info);
75                                that fills a info buffer at i=row.
76                                s.a: board/eltec/bab7xx.
77 CONFIG_VGA_AS_SINGLE_DEVICE  - If set the framebuffer device will be initialised
78                                as an output only device. The Keyboard driver
79                                will not be set-up. This may be used, if you
80                                have none or more than one Keyboard devices
81                                (USB Keyboard, AT Keyboard).
82
83 CONFIG_VIDEO_SW_CURSOR:      - Draws a cursor after the last character. No
84                                blinking is provided. Uses the macros CURSOR_SET
85                                and CURSOR_OFF.
86 CONFIG_VIDEO_HW_CURSOR:      - Uses the hardware cursor capability of the
87                                graphic chip. Uses the macro CURSOR_SET.
88                                ATTENTION: If booting an OS, the display driver
89                                must disable the hardware register of the graphic
90                                chip. Otherwise a blinking field is displayed
91 */
92
93 #include <common.h>
94
95 #ifdef CONFIG_CFB_CONSOLE
96
97 #include <malloc.h>
98
99 /*****************************************************************************/
100 /* Console device defines with SMI graphic                                   */
101 /* Any other graphic must change this section                                */
102 /*****************************************************************************/
103
104 #ifdef  CONFIG_VIDEO_SMI_LYNXEM
105
106 #define VIDEO_FB_LITTLE_ENDIAN
107 #define VIDEO_HW_RECTFILL
108 #define VIDEO_HW_BITBLT
109 #endif
110
111 /*****************************************************************************/
112 /* Defines for the CT69000 driver                                            */
113 /*****************************************************************************/
114 #ifdef  CONFIG_VIDEO_CT69000
115
116 #define VIDEO_FB_LITTLE_ENDIAN
117 #define VIDEO_HW_RECTFILL
118 #define VIDEO_HW_BITBLT
119 #endif
120
121 /*****************************************************************************/
122 /* Defines for the SED13806 driver                                           */
123 /*****************************************************************************/
124 #ifdef CONFIG_VIDEO_SED13806
125
126 #define VIDEO_FB_LITTLE_ENDIAN
127 #define VIDEO_HW_RECTFILL
128 #define VIDEO_HW_BITBLT
129 #endif
130
131 /*****************************************************************************/
132 /* Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc             */
133 /*****************************************************************************/
134 #include <video_fb.h>
135
136 /*****************************************************************************/
137 /* some Macros                                                               */
138 /*****************************************************************************/
139 #define VIDEO_VISIBLE_COLS      (pGD->winSizeX)
140 #define VIDEO_VISIBLE_ROWS      (pGD->winSizeY)
141 #define VIDEO_PIXEL_SIZE        (pGD->gdfBytesPP)
142 #define VIDEO_DATA_FORMAT       (pGD->gdfIndex)
143 #define VIDEO_FB_ADRS           (pGD->frameAdrs)
144
145 /*****************************************************************************/
146 /* Console device defines with i8042 keyboard controller                     */
147 /* Any other keyboard controller must change this section                    */
148 /*****************************************************************************/
149
150 #ifdef  CONFIG_I8042_KBD
151 #include <i8042.h>
152
153 #define VIDEO_KBD_INIT_FCT      i8042_kbd_init()
154 #define VIDEO_TSTC_FCT          i8042_tstc
155 #define VIDEO_GETC_FCT          i8042_getc
156 #endif
157
158 /*****************************************************************************/
159 /* Console device                                                            */
160 /*****************************************************************************/
161
162 #include <version.h>
163 #include <linux/types.h>
164 #include <devices.h>
165 #include <video_font.h>
166 #ifdef CFG_CMD_DATE
167 #include <rtc.h>
168
169 #endif
170
171 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
172 #include <watchdog.h>
173 #include <bmp_layout.h>
174 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
175
176 /*****************************************************************************/
177 /* Cursor definition:                                                        */
178 /* CONFIG_CONSOLE_CURSOR:  Uses a timer function (see drivers/i8042.c) to    */
179 /*                         let the cursor blink. Uses the macros CURSOR_OFF  */
180 /*                         and CURSOR_ON.                                    */
181 /* CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No       */
182 /*                         blinking is provided. Uses the macros CURSOR_SET  */
183 /*                         and CURSOR_OFF.                                   */
184 /* CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the        */
185 /*                         graphic chip. Uses the macro CURSOR_SET.          */
186 /*                         ATTENTION: If booting an OS, the display driver   */
187 /*                         must disable the hardware register of the graphic */
188 /*                         chip. Otherwise a blinking field is displayed     */
189 /*****************************************************************************/
190 #if !defined(CONFIG_CONSOLE_CURSOR) && \
191     !defined(CONFIG_VIDEO_SW_CURSOR) && \
192     !defined(CONFIG_VIDEO_HW_CURSOR)
193 /* no Cursor defined */
194 #define CURSOR_ON
195 #define CURSOR_OFF
196 #define CURSOR_SET
197 #endif
198
199 #ifdef  CONFIG_CONSOLE_CURSOR
200 #ifdef  CURSOR_ON
201 #error  only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
202 #endif
203 void    console_cursor (int state);
204 #define CURSOR_ON  console_cursor(1);
205 #define CURSOR_OFF console_cursor(0);
206 #define CURSOR_SET
207 #ifndef CONFIG_I8042_KBD
208 #warning Cursor drawing on/off needs timer function s.a. drivers/i8042.c
209 #endif
210 #else
211 #ifdef  CONFIG_CONSOLE_TIME
212 #error  CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
213 #endif
214 #endif /* CONFIG_CONSOLE_CURSOR */
215
216 #ifdef  CONFIG_VIDEO_SW_CURSOR
217 #ifdef  CURSOR_ON
218 #error  only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
219 #endif
220 #define CURSOR_ON
221 #define CURSOR_OFF video_putchar(console_col * VIDEO_FONT_WIDTH,\
222                                  console_row * VIDEO_FONT_HEIGHT, ' ');
223 #define CURSOR_SET video_set_cursor();
224 #endif /* CONFIG_VIDEO_SW_CURSOR */
225
226
227 #ifdef CONFIG_VIDEO_HW_CURSOR
228 #ifdef  CURSOR_ON
229 #error  only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
230 #endif
231 #define CURSOR_ON
232 #define CURSOR_OFF
233 #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
234                   (console_row * VIDEO_FONT_HEIGHT) + VIDEO_LOGO_HEIGHT);
235 #endif  /* CONFIG_VIDEO_HW_CURSOR */
236
237 #ifdef  CONFIG_VIDEO_LOGO
238 #ifdef  CONFIG_VIDEO_BMP_LOGO
239 #include <bmp_logo.h>
240 #define VIDEO_LOGO_WIDTH        BMP_LOGO_WIDTH
241 #define VIDEO_LOGO_HEIGHT       BMP_LOGO_HEIGHT
242 #define VIDEO_LOGO_LUT_OFFSET   BMP_LOGO_OFFSET
243 #define VIDEO_LOGO_COLORS       BMP_LOGO_COLORS
244
245 #else   /* CONFIG_VIDEO_BMP_LOGO */
246 #define LINUX_LOGO_WIDTH        80
247 #define LINUX_LOGO_HEIGHT       80
248 #define LINUX_LOGO_COLORS       214
249 #define LINUX_LOGO_LUT_OFFSET   0x20
250 #define __initdata
251 #include <linux_logo.h>
252 #define VIDEO_LOGO_WIDTH        LINUX_LOGO_WIDTH
253 #define VIDEO_LOGO_HEIGHT       LINUX_LOGO_HEIGHT
254 #define VIDEO_LOGO_LUT_OFFSET   LINUX_LOGO_LUT_OFFSET
255 #define VIDEO_LOGO_COLORS       LINUX_LOGO_COLORS
256 #endif  /* CONFIG_VIDEO_BMP_LOGO */
257 #define VIDEO_INFO_X            (VIDEO_LOGO_WIDTH)
258 #define VIDEO_INFO_Y            (VIDEO_FONT_HEIGHT/2)
259 #else   /* CONFIG_VIDEO_LOGO */
260 #define VIDEO_LOGO_WIDTH        0
261 #define VIDEO_LOGO_HEIGHT       0
262 #endif  /* CONFIG_VIDEO_LOGO */
263
264 #define VIDEO_COLS              VIDEO_VISIBLE_COLS
265 #define VIDEO_ROWS              VIDEO_VISIBLE_ROWS
266 #define VIDEO_SIZE              (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
267 #define VIDEO_PIX_BLOCKS        (VIDEO_SIZE >> 2)
268 #define VIDEO_LINE_LEN          (VIDEO_COLS*VIDEO_PIXEL_SIZE)
269 #define VIDEO_BURST_LEN         (VIDEO_COLS/8)
270
271 #ifdef  CONFIG_VIDEO_LOGO
272 #define CONSOLE_ROWS            ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
273 #else
274 #define CONSOLE_ROWS            (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
275 #endif
276
277 #define CONSOLE_COLS            (VIDEO_COLS / VIDEO_FONT_WIDTH)
278 #define CONSOLE_ROW_SIZE        (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
279 #define CONSOLE_ROW_FIRST       (video_console_address)
280 #define CONSOLE_ROW_SECOND      (video_console_address + CONSOLE_ROW_SIZE)
281 #define CONSOLE_ROW_LAST        (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
282 #define CONSOLE_SIZE            (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
283 #define CONSOLE_SCROLL_SIZE     (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
284
285 /* Macros */
286 #ifdef  VIDEO_FB_LITTLE_ENDIAN
287 #define SWAP16(x)        ((((x) & 0x00ff) << 8) | ( (x) >> 8))
288 #define SWAP32(x)        ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8)|\
289                           (((x) & 0x00ff0000) >>  8) | (((x) & 0xff000000) >> 24) )
290 #define SHORTSWAP32(x)   ((((x) & 0x000000ff) <<  8) | (((x) & 0x0000ff00) >> 8)|\
291                           (((x) & 0x00ff0000) <<  8) | (((x) & 0xff000000) >> 8) )
292 #else
293 #define SWAP16(x)        (x)
294 #define SWAP32(x)        (x)
295 #define SHORTSWAP32(x)   (x)
296 #endif
297
298 #if defined(DEBUG) || defined(DEBUG_CFB_CONSOLE)
299 #define PRINTD(x)         printf(x)
300 #else
301 #define PRINTD(x)
302 #endif
303
304
305 #ifdef CONFIG_CONSOLE_EXTRA_INFO
306 extern void video_get_info_str (    /* setup a board string: type, speed, etc. */
307     int line_number,        /* location to place info string beside logo */
308     char *info              /* buffer for info string */
309     );
310
311 #endif
312
313 /* Locals */
314 static GraphicDevice *pGD;      /* Pointer to Graphic array */
315
316 static void *video_fb_address;          /* frame buffer address */
317 static void *video_console_address;     /* console buffer start address */
318
319 static int console_col = 0; /* cursor col */
320 static int console_row = 0; /* cursor row */
321
322 static u32 eorx, fgx, bgx;  /* color pats */
323
324 static const int video_font_draw_table8[] = {
325             0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
326             0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
327             0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
328             0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff };
329
330 static const int video_font_draw_table15[] = {
331             0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff };
332
333 static const int video_font_draw_table16[] = {
334             0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
335
336 static const int video_font_draw_table24[16][3] = {
337             { 0x00000000, 0x00000000, 0x00000000 },
338             { 0x00000000, 0x00000000, 0x00ffffff },
339             { 0x00000000, 0x0000ffff, 0xff000000 },
340             { 0x00000000, 0x0000ffff, 0xffffffff },
341             { 0x000000ff, 0xffff0000, 0x00000000 },
342             { 0x000000ff, 0xffff0000, 0x00ffffff },
343             { 0x000000ff, 0xffffffff, 0xff000000 },
344             { 0x000000ff, 0xffffffff, 0xffffffff },
345             { 0xffffff00, 0x00000000, 0x00000000 },
346             { 0xffffff00, 0x00000000, 0x00ffffff },
347             { 0xffffff00, 0x0000ffff, 0xff000000 },
348             { 0xffffff00, 0x0000ffff, 0xffffffff },
349             { 0xffffffff, 0xffff0000, 0x00000000 },
350             { 0xffffffff, 0xffff0000, 0x00ffffff },
351             { 0xffffffff, 0xffffffff, 0xff000000 },
352             { 0xffffffff, 0xffffffff, 0xffffffff } };
353
354 static const int video_font_draw_table32[16][4] = {
355             { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
356             { 0x00000000, 0x00000000, 0x00000000, 0x00ffffff },
357             { 0x00000000, 0x00000000, 0x00ffffff, 0x00000000 },
358             { 0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff },
359             { 0x00000000, 0x00ffffff, 0x00000000, 0x00000000 },
360             { 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff },
361             { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000 },
362             { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff },
363             { 0x00ffffff, 0x00000000, 0x00000000, 0x00000000 },
364             { 0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff },
365             { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000 },
366             { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff },
367             { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000 },
368             { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff },
369             { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000 },
370             { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff } };
371
372
373 /******************************************************************************/
374
375 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
376 {
377         u8 *cdat, *dest, *dest0;
378         int rows, offset, c;
379
380         offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
381         dest0 = video_fb_address + offset;
382
383         switch (VIDEO_DATA_FORMAT) {
384         case GDF__8BIT_INDEX:
385         case GDF__8BIT_332RGB:
386                 while (count--) {
387                         c = *s;
388                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
389                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
390                              rows--;
391                              dest += VIDEO_LINE_LEN) {
392                                 u8 bits = *cdat++;
393
394                                 ((u32 *) dest)[0] = (video_font_draw_table8[bits >> 4] & eorx) ^ bgx;
395                                 ((u32 *) dest)[1] = (video_font_draw_table8[bits & 15] & eorx) ^ bgx;
396                         }
397                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
398                         s++;
399                 }
400                 break;
401
402         case GDF_15BIT_555RGB:
403                 while (count--) {
404                         c = *s;
405                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
406                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
407                              rows--;
408                              dest += VIDEO_LINE_LEN) {
409                                 u8 bits = *cdat++;
410
411                                 ((u32 *) dest)[0] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 6] & eorx) ^ bgx);
412                                 ((u32 *) dest)[1] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 4 & 3] & eorx) ^ bgx);
413                                 ((u32 *) dest)[2] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 2 & 3] & eorx) ^ bgx);
414                                 ((u32 *) dest)[3] = SHORTSWAP32 ((video_font_draw_table15 [bits & 3] & eorx) ^ bgx);
415                         }
416                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
417                         s++;
418                 }
419                 break;
420
421         case GDF_16BIT_565RGB:
422                 while (count--) {
423                         c = *s;
424                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
425                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
426                              rows--;
427                              dest += VIDEO_LINE_LEN) {
428                                 u8 bits = *cdat++;
429
430                                 ((u32 *) dest)[0] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 6] & eorx) ^ bgx);
431                                 ((u32 *) dest)[1] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 4 & 3] & eorx) ^ bgx);
432                                 ((u32 *) dest)[2] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 2 & 3] & eorx) ^ bgx);
433                                 ((u32 *) dest)[3] = SHORTSWAP32 ((video_font_draw_table16 [bits & 3] & eorx) ^ bgx);
434                         }
435                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
436                         s++;
437                 }
438                 break;
439
440         case GDF_32BIT_X888RGB:
441                 while (count--) {
442                         c = *s;
443                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
444                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
445                              rows--;
446                              dest += VIDEO_LINE_LEN) {
447                                 u8 bits = *cdat++;
448
449                                 ((u32 *) dest)[0] = SWAP32 ((video_font_draw_table32 [bits >> 4][0] & eorx) ^ bgx);
450                                 ((u32 *) dest)[1] = SWAP32 ((video_font_draw_table32 [bits >> 4][1] & eorx) ^ bgx);
451                                 ((u32 *) dest)[2] = SWAP32 ((video_font_draw_table32 [bits >> 4][2] & eorx) ^ bgx);
452                                 ((u32 *) dest)[3] = SWAP32 ((video_font_draw_table32 [bits >> 4][3] & eorx) ^ bgx);
453                                 ((u32 *) dest)[4] = SWAP32 ((video_font_draw_table32 [bits & 15][0] & eorx) ^ bgx);
454                                 ((u32 *) dest)[5] = SWAP32 ((video_font_draw_table32 [bits & 15][1] & eorx) ^ bgx);
455                                 ((u32 *) dest)[6] = SWAP32 ((video_font_draw_table32 [bits & 15][2] & eorx) ^ bgx);
456                                 ((u32 *) dest)[7] = SWAP32 ((video_font_draw_table32 [bits & 15][3] & eorx) ^ bgx);
457                         }
458                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
459                         s++;
460                 }
461                 break;
462
463         case GDF_24BIT_888RGB:
464                 while (count--) {
465                         c = *s;
466                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
467                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
468                              rows--;
469                              dest += VIDEO_LINE_LEN) {
470                                 u8 bits = *cdat++;
471
472                                 ((u32 *) dest)[0] = (video_font_draw_table24[bits >> 4][0] & eorx) ^ bgx;
473                                 ((u32 *) dest)[1] = (video_font_draw_table24[bits >> 4][1] & eorx) ^ bgx;
474                                 ((u32 *) dest)[2] = (video_font_draw_table24[bits >> 4][2] & eorx) ^ bgx;
475                                 ((u32 *) dest)[3] = (video_font_draw_table24[bits & 15][0] & eorx) ^ bgx;
476                                 ((u32 *) dest)[4] = (video_font_draw_table24[bits & 15][1] & eorx) ^ bgx;
477                                 ((u32 *) dest)[5] = (video_font_draw_table24[bits & 15][2] & eorx) ^ bgx;
478                         }
479                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
480                         s++;
481                 }
482                 break;
483         }
484 }
485
486 /*****************************************************************************/
487
488 static inline void video_drawstring (int xx, int yy, unsigned char *s)
489 {
490         video_drawchars (xx, yy, s, strlen (s));
491 }
492
493 /*****************************************************************************/
494
495 static void video_putchar (int xx, int yy, unsigned char c)
496 {
497         video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
498 }
499
500 /*****************************************************************************/
501 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
502 static void video_set_cursor (void)
503 {
504         /* swap drawing colors */
505         eorx = fgx;
506         fgx = bgx;
507         bgx = eorx;
508         eorx = fgx ^ bgx;
509         /* draw cursor */
510         video_putchar (console_col * VIDEO_FONT_WIDTH,
511                        console_row * VIDEO_FONT_HEIGHT,
512                        ' ');
513         /* restore drawing colors */
514         eorx = fgx;
515         fgx = bgx;
516         bgx = eorx;
517         eorx = fgx ^ bgx;
518 }
519 #endif
520 /*****************************************************************************/
521 #ifdef CONFIG_CONSOLE_CURSOR
522 void console_cursor (int state)
523 {
524         static int last_state = 0;
525
526 #ifdef CONFIG_CONSOLE_TIME
527         struct rtc_time tm;
528         char info[16];
529
530         /* time update only if cursor is on (faster scroll) */
531         if (state) {
532                 rtc_get (&tm);
533
534                 sprintf (info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
535                          tm.tm_sec);
536                 video_drawstring (VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
537                                   VIDEO_INFO_Y, info);
538
539                 sprintf (info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
540                          tm.tm_year);
541                 video_drawstring (VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
542                                   VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT, info);
543         }
544 #endif
545
546         if (state && (last_state != state)) {
547                 video_set_cursor ();
548         }
549
550         if (!state && (last_state != state)) {
551                 /* clear cursor */
552                 video_putchar (console_col * VIDEO_FONT_WIDTH,
553                                console_row * VIDEO_FONT_HEIGHT,
554                                ' ');
555         }
556
557         last_state = state;
558 }
559 #endif
560
561 /*****************************************************************************/
562
563 #ifndef VIDEO_HW_RECTFILL
564 static void memsetl (int *p, int c, int v)
565 {
566         while (c--)
567                 *(p++) = v;
568 }
569 #endif
570
571 /*****************************************************************************/
572
573 #ifndef VIDEO_HW_BITBLT
574 static void memcpyl (int *d, int *s, int c)
575 {
576         while (c--)
577                 *(d++) = *(s++);
578 }
579 #endif
580
581 /*****************************************************************************/
582
583 static void console_scrollup (void)
584 {
585         /* copy up rows ignoring the first one */
586
587 #ifdef VIDEO_HW_BITBLT
588         video_hw_bitblt (VIDEO_PIXEL_SIZE,      /* bytes per pixel */
589                          0,     /* source pos x */
590                          VIDEO_LOGO_HEIGHT + VIDEO_FONT_HEIGHT, /* source pos y */
591                          0,     /* dest pos x */
592                          VIDEO_LOGO_HEIGHT,     /* dest pos y */
593                          VIDEO_VISIBLE_COLS,    /* frame width */
594                          VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT - VIDEO_FONT_HEIGHT     /* frame height */
595                 );
596 #else
597         memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
598                  CONSOLE_SCROLL_SIZE >> 2);
599 #endif
600
601         /* clear the last one */
602 #ifdef VIDEO_HW_RECTFILL
603         video_hw_rectfill (VIDEO_PIXEL_SIZE,    /* bytes per pixel */
604                            0,   /* dest pos x */
605                            VIDEO_VISIBLE_ROWS - VIDEO_FONT_HEIGHT,      /* dest pos y */
606                            VIDEO_VISIBLE_COLS,  /* frame width */
607                            VIDEO_FONT_HEIGHT,   /* frame height */
608                            CONSOLE_BG_COL       /* fill color */
609                 );
610 #else
611         memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, CONSOLE_BG_COL);
612 #endif
613 }
614
615 /*****************************************************************************/
616
617 static void console_back (void)
618 {
619         CURSOR_OFF console_col--;
620
621         if (console_col < 0) {
622                 console_col = CONSOLE_COLS - 1;
623                 console_row--;
624                 if (console_row < 0)
625                         console_row = 0;
626         }
627         video_putchar (console_col * VIDEO_FONT_WIDTH,
628                        console_row * VIDEO_FONT_HEIGHT,
629                        ' ');
630 }
631
632 /*****************************************************************************/
633
634 static void console_newline (void)
635 {
636         CURSOR_OFF console_row++;
637         console_col = 0;
638
639         /* Check if we need to scroll the terminal */
640         if (console_row >= CONSOLE_ROWS) {
641                 /* Scroll everything up */
642                 console_scrollup ();
643
644                 /* Decrement row number */
645                 console_row--;
646         }
647 }
648
649 /*****************************************************************************/
650
651 void video_putc (const char c)
652 {
653         switch (c) {
654         case 13:                /* ignore */
655                 break;
656
657         case '\n':              /* next line */
658                 console_newline ();
659                 break;
660
661         case 9:         /* tab 8 */
662                 CURSOR_OFF console_col |= 0x0008;
663                 console_col &= ~0x0007;
664
665                 if (console_col >= CONSOLE_COLS)
666                         console_newline ();
667                 break;
668
669         case 8:         /* backspace */
670                 console_back ();
671                 break;
672
673         default:                /* draw the char */
674                 video_putchar (console_col * VIDEO_FONT_WIDTH,
675                                console_row * VIDEO_FONT_HEIGHT,
676                                c);
677                 console_col++;
678
679                 /* check for newline */
680                 if (console_col >= CONSOLE_COLS)
681                         console_newline ();
682         }
683 CURSOR_SET}
684
685
686 /*****************************************************************************/
687
688 void video_puts (const char *s)
689 {
690         int count = strlen (s);
691
692         while (count--)
693                 video_putc (*s++);
694 }
695
696 /*****************************************************************************/
697
698 #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
699
700 #define FILL_8BIT_332RGB(r,g,b) {                       \
701         *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6);       \
702         fb ++;                                          \
703 }
704
705 #define FILL_15BIT_555RGB(r,g,b) {                      \
706         *(unsigned short *)fb = SWAP16((unsigned short)(((r>>3)<<10) | ((g>>3)<<5) | (b>>3))); \
707         fb += 2;                                        \
708 }
709
710 #define FILL_16BIT_565RGB(r,g,b) {                      \
711         *(unsigned short *)fb = SWAP16((unsigned short)((((r)>>3)<<11) | (((g)>>2)<<5) | ((b)>>3))); \
712         fb += 2;                                        \
713 }
714
715 #define FILL_32BIT_X888RGB(r,g,b) {                     \
716         *(unsigned long *)fb = SWAP32((unsigned long)(((r<<16) | (g<<8) | b))); \
717         fb += 4;                                        \
718 }
719
720 #ifdef VIDEO_FB_LITTLE_ENDIAN
721 #define FILL_24BIT_888RGB(r,g,b) {                      \
722         fb[0] = b;                                      \
723         fb[1] = g;                                      \
724         fb[2] = r;                                      \
725         fb += 3;                                        \
726 }
727 #else
728 #define FILL_24BIT_888RGB(r,g,b) {                      \
729         fb[0] = r;                                      \
730         fb[1] = g;                                      \
731         fb[2] = b;                                      \
732         fb += 3;                                        \
733 }
734 #endif
735
736
737 /*
738  * Display the BMP file located at address bmp_image.
739  * Only uncompressed
740  */
741 int video_display_bitmap (ulong bmp_image, int x, int y)
742 {
743         ushort xcount, ycount;
744         uchar *fb;
745         bmp_image_t *bmp = (bmp_image_t *) bmp_image;
746         uchar *bmap;
747         ushort padded_line;
748         unsigned long width, height, bpp;
749         unsigned colors;
750         unsigned long compression;
751         bmp_color_table_entry_t cte;
752
753         WATCHDOG_RESET ();
754
755         if (!((bmp->header.signature[0] == 'B') &&
756               (bmp->header.signature[1] == 'M'))) {
757                 printf ("Error: no valid bmp image at %lx\n", bmp_image);
758                 return 1;
759         }
760
761         width = le32_to_cpu (bmp->header.width);
762         height = le32_to_cpu (bmp->header.height);
763         bpp = le16_to_cpu (bmp->header.bit_count);
764         colors = le32_to_cpu (bmp->header.colors_used);
765         compression = le32_to_cpu (bmp->header.compression);
766
767         debug ("Display-bmp: %d x %d  with %d colors\n",
768                width, height, colors);
769
770         if (compression != BMP_BI_RGB) {
771                 printf ("Error: compression type %ld not supported\n",
772                         compression);
773                 return 1;
774         }
775
776         padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
777
778         if ((x + width) > VIDEO_VISIBLE_COLS)
779                 width = VIDEO_VISIBLE_COLS - x;
780         if ((y + height) > VIDEO_VISIBLE_ROWS)
781                 height = VIDEO_VISIBLE_ROWS - y;
782
783         bmap = (uchar *) bmp + le32_to_cpu (bmp->header.data_offset);
784         fb = (uchar *) (video_fb_address +
785                         ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
786                         x * VIDEO_PIXEL_SIZE);
787
788         /* We handle only 8bpp or 24 bpp bitmap */
789         switch (le16_to_cpu (bmp->header.bit_count)) {
790         case 8:
791                 padded_line -= width;
792                 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
793                         /* Copy colormap                                             */
794                         for (xcount = 0; xcount < colors; ++xcount) {
795                                 cte = bmp->color_table[xcount];
796                                 video_set_lut (xcount, cte.red, cte.green, cte.blue);
797                         }
798                 }
799                 ycount = height;
800                 switch (VIDEO_DATA_FORMAT) {
801                 case GDF__8BIT_INDEX:
802                         while (ycount--) {
803                                 WATCHDOG_RESET ();
804                                 xcount = width;
805                                 while (xcount--) {
806                                         *fb++ = *bmap++;
807                                 }
808                                 bmap += padded_line;
809                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
810                         }
811                         break;
812                 case GDF__8BIT_332RGB:
813                         while (ycount--) {
814                                 WATCHDOG_RESET ();
815                                 xcount = width;
816                                 while (xcount--) {
817                                         cte = bmp->color_table[*bmap++];
818                                         FILL_8BIT_332RGB (cte.red, cte.green, cte.blue);
819                                 }
820                                 bmap += padded_line;
821                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
822                         }
823                         break;
824                 case GDF_15BIT_555RGB:
825                         while (ycount--) {
826                                 WATCHDOG_RESET ();
827                                 xcount = width;
828                                 while (xcount--) {
829                                         cte = bmp->color_table[*bmap++];
830                                         FILL_15BIT_555RGB (cte.red, cte.green, cte.blue);
831                                 }
832                                 bmap += padded_line;
833                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
834                         }
835                         break;
836                 case GDF_16BIT_565RGB:
837                         while (ycount--) {
838                                 WATCHDOG_RESET ();
839                                 xcount = width;
840                                 while (xcount--) {
841                                         cte = bmp->color_table[*bmap++];
842                                         FILL_16BIT_565RGB (cte.red, cte.green, cte.blue);
843                                 }
844                                 bmap += padded_line;
845                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
846                         }
847                         break;
848                 case GDF_32BIT_X888RGB:
849                         while (ycount--) {
850                                 WATCHDOG_RESET ();
851                                 xcount = width;
852                                 while (xcount--) {
853                                         cte = bmp->color_table[*bmap++];
854                                         FILL_32BIT_X888RGB (cte.red, cte.green, cte.blue);
855                                 }
856                                 bmap += padded_line;
857                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
858                         }
859                         break;
860                 case GDF_24BIT_888RGB:
861                         while (ycount--) {
862                                 WATCHDOG_RESET ();
863                                 xcount = width;
864                                 while (xcount--) {
865                                         cte = bmp->color_table[*bmap++];
866                                         FILL_24BIT_888RGB (cte.red, cte.green, cte.blue);
867                                 }
868                                 bmap += padded_line;
869                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
870                         }
871                         break;
872                 }
873                 break;
874         case 24:
875                 padded_line -= 3 * width;
876                 ycount = height;
877                 switch (VIDEO_DATA_FORMAT) {
878                 case GDF__8BIT_332RGB:
879                         while (ycount--) {
880                                 WATCHDOG_RESET ();
881                                 xcount = width;
882                                 while (xcount--) {
883                                         FILL_8BIT_332RGB (bmap[2], bmap[1], bmap[0]);
884                                         bmap += 3;
885                                 }
886                                 bmap += padded_line;
887                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
888                         }
889                         break;
890                 case GDF_15BIT_555RGB:
891                         while (ycount--) {
892                                 WATCHDOG_RESET ();
893                                 xcount = width;
894                                 while (xcount--) {
895                                         FILL_15BIT_555RGB (bmap[2], bmap[1], bmap[0]);
896                                         bmap += 3;
897                                 }
898                                 bmap += padded_line;
899                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
900                         }
901                         break;
902                 case GDF_16BIT_565RGB:
903                         while (ycount--) {
904                                 WATCHDOG_RESET ();
905                                 xcount = width;
906                                 while (xcount--) {
907                                         FILL_16BIT_565RGB (bmap[2], bmap[1], bmap[0]);
908                                         bmap += 3;
909                                 }
910                                 bmap += padded_line;
911                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
912                         }
913                         break;
914                 case GDF_32BIT_X888RGB:
915                         while (ycount--) {
916                                 WATCHDOG_RESET ();
917                                 xcount = width;
918                                 while (xcount--) {
919                                         FILL_32BIT_X888RGB (bmap[2], bmap[1], bmap[0]);
920                                         bmap += 3;
921                                 }
922                                 bmap += padded_line;
923                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
924                         }
925                         break;
926                 case GDF_24BIT_888RGB:
927                         while (ycount--) {
928                                 WATCHDOG_RESET ();
929                                 xcount = width;
930                                 while (xcount--) {
931                                         FILL_24BIT_888RGB (bmap[2], bmap[1], bmap[0]);
932                                         bmap += 3;
933                                 }
934                                 bmap += padded_line;
935                                 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
936                         }
937                         break;
938                 default:
939                         printf ("Error: 24 bits/pixel bitmap incompatible with current video mode\n");
940                         break;
941                 }
942                 break;
943         default:
944                 printf ("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
945                         le16_to_cpu (bmp->header.bit_count));
946                 break;
947         }
948         return (0);
949 }
950 #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
951
952 /*****************************************************************************/
953
954 #ifdef CONFIG_VIDEO_LOGO
955 void logo_plot (void *screen, int width, int x, int y)
956 {
957
958         int xcount, i;
959         int skip   = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
960         int ycount = VIDEO_LOGO_HEIGHT;
961         unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
962         unsigned char *source;
963         unsigned char *dest = (unsigned char *)screen + ((y * width * VIDEO_PIXEL_SIZE) + x);
964
965 #ifdef CONFIG_VIDEO_BMP_LOGO
966         source = bmp_logo_bitmap;
967
968         /* Allocate temporary space for computing colormap                       */
969         logo_red = malloc (BMP_LOGO_COLORS);
970         logo_green = malloc (BMP_LOGO_COLORS);
971         logo_blue = malloc (BMP_LOGO_COLORS);
972         /* Compute color map                                                     */
973         for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
974                 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
975                 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
976                 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
977         }
978 #else
979         source = linux_logo;
980         logo_red = linux_logo_red;
981         logo_green = linux_logo_green;
982         logo_blue = linux_logo_blue;
983 #endif
984
985         if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
986                 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
987                         video_set_lut (i + VIDEO_LOGO_LUT_OFFSET,
988                                        logo_red[i], logo_green[i], logo_blue[i]);
989                 }
990         }
991
992         while (ycount--) {
993                 xcount = VIDEO_LOGO_WIDTH;
994                 while (xcount--) {
995                         r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
996                         g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
997                         b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
998
999                         switch (VIDEO_DATA_FORMAT) {
1000                         case GDF__8BIT_INDEX:
1001                                 *dest = *source;
1002                                 break;
1003                         case GDF__8BIT_332RGB:
1004                                 *dest = ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
1005                                 break;
1006                         case GDF_15BIT_555RGB:
1007                                 *(unsigned short *) dest =
1008                                         SWAP16 ((unsigned short) (((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3)));
1009                                 break;
1010                         case GDF_16BIT_565RGB:
1011                                 *(unsigned short *) dest =
1012                                         SWAP16 ((unsigned short) (((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)));
1013                                 break;
1014                         case GDF_32BIT_X888RGB:
1015                                 *(unsigned long *) dest =
1016                                         SWAP32 ((unsigned long) ((r << 16) | (g << 8) | b));
1017                                 break;
1018                         case GDF_24BIT_888RGB:
1019 #ifdef VIDEO_FB_LITTLE_ENDIAN
1020                                 dest[0] = b;
1021                                 dest[1] = g;
1022                                 dest[2] = r;
1023 #else
1024                                 dest[0] = r;
1025                                 dest[1] = g;
1026                                 dest[2] = b;
1027 #endif
1028                                 break;
1029                         }
1030                         source++;
1031                         dest += VIDEO_PIXEL_SIZE;
1032                 }
1033                 dest += skip;
1034         }
1035 #ifdef CONFIG_VIDEO_BMP_LOGO
1036         free (logo_red);
1037         free (logo_green);
1038         free (logo_blue);
1039 #endif
1040 }
1041
1042 /*****************************************************************************/
1043
1044 static void *video_logo (void)
1045 {
1046         char info[128];
1047         extern char version_string;
1048
1049 #ifdef CONFIG_SPLASH_SCREEN
1050         char *s;
1051         ulong addr;
1052
1053         if ((s = getenv ("splashimage")) != NULL) {
1054                 addr = simple_strtoul (s, NULL, 16);
1055
1056                 if (video_display_bitmap (addr, 0, 0) == 0) {
1057                         return ((void *) (video_fb_address));
1058                 }
1059         }
1060 #endif /* CONFIG_SPLASH_SCREEN */
1061
1062
1063         logo_plot (video_fb_address, VIDEO_COLS, 0, 0);
1064
1065         sprintf (info, " %s", &version_string);
1066         video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1067
1068 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1069         {
1070                 int i, n = ((VIDEO_LOGO_HEIGHT - VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1071
1072                 for (i = 1; i < n; i++) {
1073                         video_get_info_str (i, info);
1074                         if (*info)
1075                                 video_drawstring (VIDEO_INFO_X,
1076                                                   VIDEO_INFO_Y + i * VIDEO_FONT_HEIGHT,
1077                                                   info);
1078                 }
1079         }
1080 #endif
1081
1082         return (video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN);
1083 }
1084 #endif
1085
1086
1087 /*****************************************************************************/
1088
1089 static int video_init (void)
1090 {
1091         unsigned char color8;
1092
1093         if ((pGD = video_hw_init ()) == NULL)
1094                 return -1;
1095
1096         video_fb_address = (void *) VIDEO_FB_ADRS;
1097 #ifdef CONFIG_VIDEO_HW_CURSOR
1098         video_init_hw_cursor (VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
1099 #endif
1100
1101         /* Init drawing pats */
1102         switch (VIDEO_DATA_FORMAT) {
1103         case GDF__8BIT_INDEX:
1104                 video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL);
1105                 video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL);
1106                 fgx = 0x01010101;
1107                 bgx = 0x00000000;
1108                 break;
1109         case GDF__8BIT_332RGB:
1110                 color8 = ((CONSOLE_FG_COL & 0xe0) |
1111                           ((CONSOLE_FG_COL >> 3) & 0x1c) | CONSOLE_FG_COL >> 6);
1112                 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
1113                 color8 = ((CONSOLE_BG_COL & 0xe0) |
1114                           ((CONSOLE_BG_COL >> 3) & 0x1c) | CONSOLE_BG_COL >> 6);
1115                 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
1116                 break;
1117         case GDF_15BIT_555RGB:
1118                 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
1119                        ((CONSOLE_FG_COL >> 3) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
1120                        ((CONSOLE_FG_COL >> 3) << 10) | ((CONSOLE_FG_COL >> 3) << 5) |
1121                        (CONSOLE_FG_COL >> 3));
1122                 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
1123                        ((CONSOLE_BG_COL >> 3) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
1124                        ((CONSOLE_BG_COL >> 3) << 10) | ((CONSOLE_BG_COL >> 3) << 5) |
1125                        (CONSOLE_BG_COL >> 3));
1126                 break;
1127         case GDF_16BIT_565RGB:
1128                 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
1129                        ((CONSOLE_FG_COL >> 2) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
1130                        ((CONSOLE_FG_COL >> 3) << 11) | ((CONSOLE_FG_COL >> 2) << 5) |
1131                        (CONSOLE_FG_COL >> 3));
1132                 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
1133                        ((CONSOLE_BG_COL >> 2) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
1134                        ((CONSOLE_BG_COL >> 3) << 11) | ((CONSOLE_BG_COL >> 2) << 5) |
1135                        (CONSOLE_BG_COL >> 3));
1136                 break;
1137         case GDF_32BIT_X888RGB:
1138                 fgx = (CONSOLE_FG_COL << 16) | (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
1139                 bgx = (CONSOLE_BG_COL << 16) | (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
1140                 break;
1141         case GDF_24BIT_888RGB:
1142                 fgx = (CONSOLE_FG_COL << 24) | (CONSOLE_FG_COL << 16) |
1143                         (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
1144                 bgx = (CONSOLE_BG_COL << 24) | (CONSOLE_BG_COL << 16) |
1145                         (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
1146                 break;
1147         }
1148         eorx = fgx ^ bgx;
1149
1150 #ifdef CONFIG_VIDEO_LOGO
1151         /* Plot the logo and get start point of console */
1152         PRINTD ("Video: Drawing the logo ...\n");
1153         video_console_address = video_logo ();
1154 #else
1155         video_console_address = video_fb_address;
1156 #endif
1157
1158         /* Initialize the console */
1159         console_col = 0;
1160         console_row = 0;
1161
1162         return 0;
1163 }
1164
1165
1166 /*****************************************************************************/
1167
1168 int drv_video_init (void)
1169 {
1170         int skip_dev_init;
1171         device_t console_dev;
1172         char *penv;
1173
1174         skip_dev_init = 0;
1175
1176         /* Force console i/o to serial ? */
1177         if ((penv = getenv ("console")) != NULL)
1178                 if (strcmp (penv, "serial") == 0)
1179                         return 0;
1180
1181         /* Init video chip - returns with framebuffer cleared */
1182         if (video_init () == -1)
1183                 skip_dev_init = 1;
1184 #ifdef CONFIG_VGA_AS_SINGLE_DEVICE
1185         /* Devices VGA and Keyboard will be assigned seperately */
1186         /* Init vga device */
1187         if (!skip_dev_init) {
1188                 memset (&console_dev, 0, sizeof (console_dev));
1189                 strcpy (console_dev.name, "vga");
1190                 console_dev.ext = DEV_EXT_VIDEO;        /* Video extensions */
1191                 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1192                 console_dev.putc = video_putc;  /* 'putc' function */
1193                 console_dev.puts = video_puts;  /* 'puts' function */
1194                 console_dev.tstc = NULL;        /* 'tstc' function */
1195                 console_dev.getc = NULL;        /* 'getc' function */
1196
1197                 if (device_register (&console_dev) == 0)
1198                         return 1;
1199         }
1200 #else
1201         PRINTD ("KBD: Keyboard init ...\n");
1202         if (VIDEO_KBD_INIT_FCT == -1)
1203                 skip_dev_init = 1;
1204
1205         /* Init console device */
1206         if (!skip_dev_init) {
1207                 memset (&console_dev, 0, sizeof (console_dev));
1208                 strcpy (console_dev.name, "console");
1209                 console_dev.ext = DEV_EXT_VIDEO;        /* Video extensions */
1210                 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
1211                 console_dev.putc = video_putc;  /* 'putc' function */
1212                 console_dev.puts = video_puts;  /* 'puts' function */
1213                 console_dev.tstc = VIDEO_TSTC_FCT;      /* 'tstc' function */
1214                 console_dev.getc = VIDEO_GETC_FCT;      /* 'getc' function */
1215
1216                 if (device_register (&console_dev) == 0)
1217                         return 1;
1218         }
1219 #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
1220         /* No console dev available */
1221         return 0;
1222 }
1223 #endif /* CONFIG_CFB_CONSOLE */