fc4ea7216cb067e905ad79e87797c3abe2560a44
[kernel/u-boot.git] / drivers / video / 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 normally goes to serial port) can be drawn.
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
63  *                              delay loop in VIDEO_TSTC_FCT (i8042)
64  *
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
78  *                              specific function:
79  *                              video_drawstring (VIDEO_INFO_X,
80  *                                      VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
81  *                                      info);
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).
90  *
91  * CONFIG_VIDEO_SW_CURSOR:    - Draws a cursor after the last
92  *                              character. No blinking is provided.
93  *                              Uses the macros CURSOR_SET and
94  *                              CURSOR_OFF.
95  *
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
102  *                              displayed.
103  */
104
105 #include <common.h>
106 #include <version.h>
107 #include <malloc.h>
108 #include <linux/compiler.h>
109
110 /*
111  * Console device defines with SMI graphic
112  * Any other graphic must change this section
113  */
114
115 #ifdef  CONFIG_VIDEO_SMI_LYNXEM
116
117 #define VIDEO_FB_LITTLE_ENDIAN
118 #define VIDEO_HW_RECTFILL
119 #define VIDEO_HW_BITBLT
120 #endif
121
122 /*
123  * Defines for the CT69000 driver
124  */
125 #ifdef  CONFIG_VIDEO_CT69000
126
127 #define VIDEO_FB_LITTLE_ENDIAN
128 #define VIDEO_HW_RECTFILL
129 #define VIDEO_HW_BITBLT
130 #endif
131
132 /*
133  * Defines for the SED13806 driver
134  */
135 #ifdef CONFIG_VIDEO_SED13806
136
137 #ifndef CONFIG_TOTAL5200
138 #define VIDEO_FB_LITTLE_ENDIAN
139 #endif
140 #define VIDEO_HW_RECTFILL
141 #define VIDEO_HW_BITBLT
142 #endif
143
144 /*
145  * Defines for the SED13806 driver
146  */
147 #ifdef CONFIG_VIDEO_SM501
148
149 #ifdef CONFIG_HH405
150 #define VIDEO_FB_LITTLE_ENDIAN
151 #endif
152 #endif
153
154 /*
155  * Defines for the MB862xx driver
156  */
157 #ifdef CONFIG_VIDEO_MB862xx
158
159 #ifdef CONFIG_VIDEO_CORALP
160 #define VIDEO_FB_LITTLE_ENDIAN
161 #endif
162 #ifdef CONFIG_VIDEO_MB862xx_ACCEL
163 #define VIDEO_HW_RECTFILL
164 #define VIDEO_HW_BITBLT
165 #endif
166 #endif
167
168 /*
169  * Defines for the i.MX31 driver (mx3fb.c)
170  */
171 #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
172 #define VIDEO_FB_16BPP_WORD_SWAP
173 #endif
174
175 /*
176  * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
177  */
178 #include <video_fb.h>
179
180 /*
181  * some Macros
182  */
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)
188
189 /*
190  * Console device defines with i8042 keyboard controller
191  * Any other keyboard controller must change this section
192  */
193
194 #ifdef  CONFIG_I8042_KBD
195 #include <i8042.h>
196
197 #define VIDEO_KBD_INIT_FCT      i8042_kbd_init()
198 #define VIDEO_TSTC_FCT          i8042_tstc
199 #define VIDEO_GETC_FCT          i8042_getc
200 #endif
201
202 /*
203  * Console device
204  */
205
206 #include <version.h>
207 #include <linux/types.h>
208 #include <stdio_dev.h>
209 #include <video_font.h>
210 #include <video_font_data.h>
211
212 #if defined(CONFIG_CMD_DATE)
213 #include <rtc.h>
214 #endif
215
216 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
217 #include <watchdog.h>
218 #include <bmp_layout.h>
219
220 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
221 #define BMP_ALIGN_CENTER        0x7FFF
222 #endif
223
224 #endif
225
226 /*
227  * Cursor definition:
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
233  *                         and CURSOR_OFF.
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
239  */
240 #if !defined(CONFIG_CONSOLE_CURSOR) && \
241     !defined(CONFIG_VIDEO_SW_CURSOR) && \
242     !defined(CONFIG_VIDEO_HW_CURSOR)
243 /* no Cursor defined */
244 #define CURSOR_ON
245 #define CURSOR_OFF
246 #define CURSOR_SET
247 #endif
248
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
254 #endif
255 void console_cursor(int state);
256
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 */
261
262 #ifdef  CONFIG_CONSOLE_CURSOR
263 #ifndef CONFIG_CONSOLE_TIME
264 #error  CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
265 #endif
266 #ifndef CONFIG_I8042_KBD
267 #warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
268 #endif
269 #endif /* CONFIG_CONSOLE_CURSOR */
270
271
272 #ifdef CONFIG_VIDEO_HW_CURSOR
273 #ifdef  CURSOR_ON
274 #error  only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
275         or CONFIG_VIDEO_HW_CURSOR can be defined
276 #endif
277 #define CURSOR_ON
278 #define CURSOR_OFF
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 */
282
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
291
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
297 #define __initdata
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 */
310
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)
317
318 #ifdef  CONFIG_VIDEO_LOGO
319 #define CONSOLE_ROWS            ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
320 #else
321 #define CONSOLE_ROWS            (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
322 #endif
323
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)
331
332 /* Macros */
333 #ifdef  VIDEO_FB_LITTLE_ENDIAN
334 #define SWAP16(x)               ((((x) & 0x00ff) << 8) | \
335                                   ((x) >> 8) \
336                                 )
337 #define SWAP32(x)               ((((x) & 0x000000ff) << 24) | \
338                                  (((x) & 0x0000ff00) <<  8) | \
339                                  (((x) & 0x00ff0000) >>  8) | \
340                                  (((x) & 0xff000000) >> 24)   \
341                                 )
342 #define SHORTSWAP32(x)          ((((x) & 0x000000ff) <<  8) | \
343                                  (((x) & 0x0000ff00) >>  8) | \
344                                  (((x) & 0x00ff0000) <<  8) | \
345                                  (((x) & 0xff000000) >>  8)   \
346                                 )
347 #else
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))
352 #else
353 #define SHORTSWAP32(x)          (x)
354 #endif
355 #endif
356
357 #ifdef CONFIG_CONSOLE_EXTRA_INFO
358 /*
359  * setup a board string: type, speed, etc.
360  *
361  * line_number: location to place info string beside logo
362  * info:        buffer for info string
363  */
364 extern void video_get_info_str(int line_number, char *info);
365 #endif
366
367 DECLARE_GLOBAL_DATA_PTR;
368
369 /* Locals */
370 static GraphicDevice *pGD;      /* Pointer to Graphic array */
371
372 static void *video_fb_address;  /* frame buffer address */
373 static void *video_console_address;     /* console buffer start address */
374
375 static int video_logo_height = VIDEO_LOGO_HEIGHT;
376
377 static int __maybe_unused cursor_state;
378 static int __maybe_unused old_col;
379 static int __maybe_unused old_row;
380
381 static int console_col;         /* cursor col */
382 static int console_row;         /* cursor row */
383
384 static u32 eorx, fgx, bgx;      /* color pats */
385
386 static int cfb_do_flush_cache;
387
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
393 };
394
395 static const int video_font_draw_table15[] = {
396         0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
397 };
398
399 static const int video_font_draw_table16[] = {
400         0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
401 };
402
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}
420 };
421
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}
439 };
440
441 static void video_drawchars(int xx, int yy, unsigned char *s, int count)
442 {
443         u8 *cdat, *dest, *dest0;
444         int rows, offset, c;
445
446         offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
447         dest0 = video_fb_address + offset;
448
449         switch (VIDEO_DATA_FORMAT) {
450         case GDF__8BIT_INDEX:
451         case GDF__8BIT_332RGB:
452                 while (count--) {
453                         c = *s;
454                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
455                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
456                              rows--; dest += VIDEO_LINE_LEN) {
457                                 u8 bits = *cdat++;
458
459                                 ((u32 *) dest)[0] =
460                                         (video_font_draw_table8[bits >> 4] &
461                                          eorx) ^ bgx;
462                                 ((u32 *) dest)[1] =
463                                         (video_font_draw_table8[bits & 15] &
464                                          eorx) ^ bgx;
465                         }
466                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
467                         s++;
468                 }
469                 break;
470
471         case GDF_15BIT_555RGB:
472                 while (count--) {
473                         c = *s;
474                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
475                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
476                              rows--; dest += VIDEO_LINE_LEN) {
477                                 u8 bits = *cdat++;
478
479                                 ((u32 *) dest)[0] =
480                                         SHORTSWAP32((video_font_draw_table15
481                                                      [bits >> 6] & eorx) ^
482                                                     bgx);
483                                 ((u32 *) dest)[1] =
484                                         SHORTSWAP32((video_font_draw_table15
485                                                      [bits >> 4 & 3] & eorx) ^
486                                                     bgx);
487                                 ((u32 *) dest)[2] =
488                                         SHORTSWAP32((video_font_draw_table15
489                                                      [bits >> 2 & 3] & eorx) ^
490                                                     bgx);
491                                 ((u32 *) dest)[3] =
492                                         SHORTSWAP32((video_font_draw_table15
493                                                      [bits & 3] & eorx) ^
494                                                     bgx);
495                         }
496                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
497                         s++;
498                 }
499                 break;
500
501         case GDF_16BIT_565RGB:
502                 while (count--) {
503                         c = *s;
504                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
505                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
506                              rows--; dest += VIDEO_LINE_LEN) {
507                                 u8 bits = *cdat++;
508
509                                 ((u32 *) dest)[0] =
510                                         SHORTSWAP32((video_font_draw_table16
511                                                      [bits >> 6] & eorx) ^
512                                                     bgx);
513                                 ((u32 *) dest)[1] =
514                                         SHORTSWAP32((video_font_draw_table16
515                                                      [bits >> 4 & 3] & eorx) ^
516                                                     bgx);
517                                 ((u32 *) dest)[2] =
518                                         SHORTSWAP32((video_font_draw_table16
519                                                      [bits >> 2 & 3] & eorx) ^
520                                                     bgx);
521                                 ((u32 *) dest)[3] =
522                                         SHORTSWAP32((video_font_draw_table16
523                                                      [bits & 3] & eorx) ^
524                                                     bgx);
525                         }
526                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
527                         s++;
528                 }
529                 break;
530
531         case GDF_32BIT_X888RGB:
532                 while (count--) {
533                         c = *s;
534                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
535                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
536                              rows--; dest += VIDEO_LINE_LEN) {
537                                 u8 bits = *cdat++;
538
539                                 ((u32 *) dest)[0] =
540                                         SWAP32((video_font_draw_table32
541                                                 [bits >> 4][0] & eorx) ^ bgx);
542                                 ((u32 *) dest)[1] =
543                                         SWAP32((video_font_draw_table32
544                                                 [bits >> 4][1] & eorx) ^ bgx);
545                                 ((u32 *) dest)[2] =
546                                         SWAP32((video_font_draw_table32
547                                                 [bits >> 4][2] & eorx) ^ bgx);
548                                 ((u32 *) dest)[3] =
549                                         SWAP32((video_font_draw_table32
550                                                 [bits >> 4][3] & eorx) ^ bgx);
551                                 ((u32 *) dest)[4] =
552                                         SWAP32((video_font_draw_table32
553                                                 [bits & 15][0] & eorx) ^ bgx);
554                                 ((u32 *) dest)[5] =
555                                         SWAP32((video_font_draw_table32
556                                                 [bits & 15][1] & eorx) ^ bgx);
557                                 ((u32 *) dest)[6] =
558                                         SWAP32((video_font_draw_table32
559                                                 [bits & 15][2] & eorx) ^ bgx);
560                                 ((u32 *) dest)[7] =
561                                         SWAP32((video_font_draw_table32
562                                                 [bits & 15][3] & eorx) ^ bgx);
563                         }
564                         if (cfb_do_flush_cache)
565                                 flush_cache((ulong)dest0, 32);
566                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
567                         s++;
568                 }
569                 break;
570
571         case GDF_24BIT_888RGB:
572                 while (count--) {
573                         c = *s;
574                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
575                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
576                              rows--; dest += VIDEO_LINE_LEN) {
577                                 u8 bits = *cdat++;
578
579                                 ((u32 *) dest)[0] =
580                                         (video_font_draw_table24[bits >> 4][0]
581                                          & eorx) ^ bgx;
582                                 ((u32 *) dest)[1] =
583                                         (video_font_draw_table24[bits >> 4][1]
584                                          & eorx) ^ bgx;
585                                 ((u32 *) dest)[2] =
586                                         (video_font_draw_table24[bits >> 4][2]
587                                          & eorx) ^ bgx;
588                                 ((u32 *) dest)[3] =
589                                         (video_font_draw_table24[bits & 15][0]
590                                          & eorx) ^ bgx;
591                                 ((u32 *) dest)[4] =
592                                         (video_font_draw_table24[bits & 15][1]
593                                          & eorx) ^ bgx;
594                                 ((u32 *) dest)[5] =
595                                         (video_font_draw_table24[bits & 15][2]
596                                          & eorx) ^ bgx;
597                         }
598                         dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
599                         s++;
600                 }
601                 break;
602         }
603 }
604
605 static inline void video_drawstring(int xx, int yy, unsigned char *s)
606 {
607         video_drawchars(xx, yy, s, strlen((char *) s));
608 }
609
610 static void video_putchar(int xx, int yy, unsigned char c)
611 {
612         video_drawchars(xx, yy + video_logo_height, &c, 1);
613 }
614
615 #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
616 static void video_set_cursor(void)
617 {
618         if (cursor_state)
619                 console_cursor(0);
620         console_cursor(1);
621 }
622
623 static void video_invertchar(int xx, int yy)
624 {
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;
629         int x, y;
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;
633                         *dest = ~*dest;
634                         if (cfb_do_flush_cache)
635                                 flush_cache((ulong)dest, 4);
636                 }
637         }
638 }
639
640 void console_cursor(int state)
641 {
642 #ifdef CONFIG_CONSOLE_TIME
643         struct rtc_time tm;
644         char info[16];
645
646         /* time update only if cursor is on (faster scroll) */
647         if (state) {
648                 rtc_get(&tm);
649
650                 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
651                         tm.tm_sec);
652                 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
653                                  VIDEO_INFO_Y, (uchar *) info);
654
655                 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
656                         tm.tm_year);
657                 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
658                                  VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
659                                  (uchar *) info);
660         }
661 #endif
662
663         if (cursor_state != state) {
664                 if (cursor_state) {
665                         /* turn off the cursor */
666                         video_invertchar(old_col * VIDEO_FONT_WIDTH,
667                                          old_row * VIDEO_FONT_HEIGHT +
668                                          video_logo_height);
669                 } else {
670                         /* turn off the cursor and record where it is */
671                         video_invertchar(console_col * VIDEO_FONT_WIDTH,
672                                          console_row * VIDEO_FONT_HEIGHT +
673                                          video_logo_height);
674                         old_col = console_col;
675                         old_row = console_row;
676                 }
677                 cursor_state = state;
678         }
679 }
680 #endif
681
682 #ifndef VIDEO_HW_RECTFILL
683 static void memsetl(int *p, int c, int v)
684 {
685         while (c--)
686                 *(p++) = v;
687 }
688 #endif
689
690 #ifndef VIDEO_HW_BITBLT
691 static void memcpyl(int *d, int *s, int c)
692 {
693         while (c--)
694                 *(d++) = *(s++);
695 }
696 #endif
697
698 static void console_clear_line(int line, int begin, int end)
699 {
700 #ifdef VIDEO_HW_RECTFILL
701         video_hw_rectfill(VIDEO_PIXEL_SIZE,             /* bytes per pixel */
702                           VIDEO_FONT_WIDTH * begin,     /* dest pos x */
703                           video_logo_height +
704                           VIDEO_FONT_HEIGHT * line,     /* dest pos y */
705                           VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
706                           VIDEO_FONT_HEIGHT,            /* frame height */
707                           bgx                           /* fill color */
708                 );
709 #else
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 */
714                         bgx                             /* fill color */
715                 );
716         } else {
717                 void *offset;
718                 int i, size;
719
720                 offset = CONSOLE_ROW_FIRST +
721                          CONSOLE_ROW_SIZE * line +      /* offset of row */
722                          VIDEO_FONT_WIDTH *
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);
729         }
730 #endif
731         if (cfb_do_flush_cache)
732                 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
733 }
734
735 static void console_scrollup(void)
736 {
737         /* copy up rows ignoring the first one */
738
739 #ifdef VIDEO_HW_BITBLT
740         video_hw_bitblt(VIDEO_PIXEL_SIZE,       /* bytes per pixel */
741                         0,                      /* source pos x */
742                         video_logo_height +
743                                 VIDEO_FONT_HEIGHT, /* source pos y */
744                         0,                      /* dest pos x */
745                         video_logo_height,      /* dest pos y */
746                         VIDEO_VISIBLE_COLS,     /* frame width */
747                         VIDEO_VISIBLE_ROWS
748                         - video_logo_height
749                         - VIDEO_FONT_HEIGHT     /* frame height */
750                 );
751 #else
752         memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
753                 CONSOLE_SCROLL_SIZE >> 2);
754 #endif
755         /* clear the last one */
756         console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
757 }
758
759 static void console_back(void)
760 {
761         console_col--;
762
763         if (console_col < 0) {
764                 console_col = CONSOLE_COLS - 1;
765                 console_row--;
766                 if (console_row < 0)
767                         console_row = 0;
768         }
769 }
770
771 static void console_newline(void)
772 {
773         console_row++;
774         console_col = 0;
775
776         /* Check if we need to scroll the terminal */
777         if (console_row >= CONSOLE_ROWS) {
778                 /* Scroll everything up */
779                 console_scrollup();
780
781                 /* Decrement row number */
782                 console_row--;
783         }
784 }
785
786 static void console_cr(void)
787 {
788         console_col = 0;
789 }
790
791 void video_putc(const char c)
792 {
793         static int nl = 1;
794
795         CURSOR_OFF;
796
797         switch (c) {
798         case 13:                /* back to first column */
799                 console_cr();
800                 break;
801
802         case '\n':              /* next line */
803                 if (console_col || (!console_col && nl))
804                         console_newline();
805                 nl = 1;
806                 break;
807
808         case 9:         /* tab 8 */
809                 console_col |= 0x0008;
810                 console_col &= ~0x0007;
811
812                 if (console_col >= CONSOLE_COLS)
813                         console_newline();
814                 break;
815
816         case 8:         /* backspace */
817                 console_back();
818                 break;
819
820         case 7:         /* bell */
821                 break;  /* ignored */
822
823         default:                /* draw the char */
824                 video_putchar(console_col * VIDEO_FONT_WIDTH,
825                               console_row * VIDEO_FONT_HEIGHT, c);
826                 console_col++;
827
828                 /* check for newline */
829                 if (console_col >= CONSOLE_COLS) {
830                         console_newline();
831                         nl = 0;
832                 }
833         }
834         CURSOR_SET;
835 }
836
837 void video_puts(const char *s)
838 {
839         int count = strlen(s);
840
841         while (count--)
842                 video_putc(*s++);
843 }
844
845 /*
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.
849  */
850 void __video_set_lut(unsigned int index, unsigned char r,
851                      unsigned char g, unsigned char b)
852 {
853 }
854
855 void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
856         __attribute__ ((weak, alias("__video_set_lut")));
857
858 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
859
860 #define FILL_8BIT_332RGB(r,g,b) {                       \
861         *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6);       \
862         fb ++;                                          \
863 }
864
865 #define FILL_15BIT_555RGB(r,g,b) {                      \
866         *(unsigned short *)fb =                         \
867                 SWAP16((unsigned short)(((r>>3)<<10) |  \
868                                         ((g>>3)<<5)  |  \
869                                          (b>>3)));      \
870         fb += 2;                                        \
871 }
872
873 #define FILL_16BIT_565RGB(r,g,b) {                      \
874         *(unsigned short *)fb =                         \
875                 SWAP16((unsigned short)((((r)>>3)<<11)| \
876                                         (((g)>>2)<<5) | \
877                                          ((b)>>3)));    \
878         fb += 2;                                        \
879 }
880
881 #define FILL_32BIT_X888RGB(r,g,b) {                     \
882         *(unsigned long *)fb =                          \
883                 SWAP32((unsigned long)(((r<<16) |       \
884                                         (g<<8)  |       \
885                                          b)));          \
886         fb += 4;                                        \
887 }
888
889 #ifdef VIDEO_FB_LITTLE_ENDIAN
890 #define FILL_24BIT_888RGB(r,g,b) {                      \
891         fb[0] = b;                                      \
892         fb[1] = g;                                      \
893         fb[2] = r;                                      \
894         fb += 3;                                        \
895 }
896 #else
897 #define FILL_24BIT_888RGB(r,g,b) {                      \
898         fb[0] = r;                                      \
899         fb[1] = g;                                      \
900         fb[2] = b;                                      \
901         fb += 3;                                        \
902 }
903 #endif
904
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)
907 {
908         ushort *dst = (ushort *) fb;
909         ushort color = (ushort) (((r >> 3) << 10) |
910                                  ((g >> 3) <<  5) |
911                                   (b >> 3));
912         if (x & 1)
913                 *(--dst) = color;
914         else
915                 *(++dst) = color;
916 }
917 #endif
918
919 /*
920  * RLE8 bitmap support
921  */
922
923 #ifdef CONFIG_VIDEO_BMP_RLE8
924 /* Pre-calculated color table entry */
925 struct palette {
926         union {
927                 unsigned short w;       /* word */
928                 unsigned int dw;        /* double word */
929         } ce;                           /* color entry */
930 };
931
932 /*
933  * Helper to draw encoded/unencoded run.
934  */
935 static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
936                         int cnt, int enc)
937 {
938         ulong addr = (ulong) *fb;
939         int *off;
940         int enc_off = 1;
941         int i;
942
943         /*
944          * Setup offset of the color index in the bitmap.
945          * Color index of encoded run is at offset 1.
946          */
947         off = enc ? &enc_off : &i;
948
949         switch (VIDEO_DATA_FORMAT) {
950         case GDF__8BIT_INDEX:
951                 for (i = 0; i < cnt; i++)
952                         *(unsigned char *) addr++ = bm[*off];
953                 break;
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;
959                         addr += 2;
960                 }
961                 break;
962         case GDF_32BIT_X888RGB:
963                 for (i = 0; i < cnt; i++) {
964                         *(unsigned long *) addr = p[bm[*off]].ce.dw;
965                         addr += 4;
966                 }
967                 break;
968         }
969         *fb = (uchar *) addr;   /* return modified address */
970 }
971
972 static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
973                                int width, int height)
974 {
975         unsigned char *bm;
976         unsigned char *fbp;
977         unsigned int cnt, runlen;
978         int decode = 1;
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;
984         int pixels = 0;
985
986         x = 0;
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);
992
993         bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
994
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);
1001                 }
1002                 break;
1003         case GDF_15BIT_555RGB:
1004         case GDF_16BIT_565RGB:
1005                 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1006                         green_shift = 3;
1007                         red_off = 10;
1008                 } else {
1009                         green_shift = 2;
1010                         red_off = 11;
1011                 }
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) |
1017                                             cte.blue >> 3));
1018                 }
1019                 break;
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) |
1024                                             (cte.green << 8) |
1025                                              cte.blue);
1026                 }
1027                 break;
1028         default:
1029                 printf("RLE Bitmap unsupported in video mode 0x%x\n",
1030                        VIDEO_DATA_FORMAT);
1031                 return -1;
1032         }
1033
1034         while (decode) {
1035                 switch (bm[0]) {
1036                 case 0:
1037                         switch (bm[1]) {
1038                         case 0:
1039                                 /* scan line end marker */
1040                                 bm += 2;
1041                                 x = 0;
1042                                 y--;
1043                                 fbp = (unsigned char *)
1044                                         ((unsigned int) video_fb_address +
1045                                          (((y + yoff) * VIDEO_COLS) +
1046                                           xoff) * bpp);
1047                                 continue;
1048                         case 1:
1049                                 /* end of bitmap data marker */
1050                                 decode = 0;
1051                                 break;
1052                         case 2:
1053                                 /* run offset marker */
1054                                 x += bm[2];
1055                                 y -= bm[3];
1056                                 fbp = (unsigned char *)
1057                                         ((unsigned int) video_fb_address +
1058                                          (((y + yoff) * VIDEO_COLS) +
1059                                           x + xoff) * bpp);
1060                                 bm += 4;
1061                                 break;
1062                         default:
1063                                 /* unencoded run */
1064                                 cnt = bm[1];
1065                                 runlen = cnt;
1066                                 pixels += cnt;
1067                                 if (pixels > limit)
1068                                         goto error;
1069
1070                                 bm += 2;
1071                                 if (y < height) {
1072                                         if (x >= width) {
1073                                                 x += runlen;
1074                                                 goto next_run;
1075                                         }
1076                                         if (x + runlen > width)
1077                                                 cnt = width - x;
1078                                         draw_bitmap(&fbp, bm, p, cnt, 0);
1079                                         x += runlen;
1080                                 }
1081 next_run:
1082                                 bm += runlen;
1083                                 if (runlen & 1)
1084                                         bm++;   /* 0 padding if length is odd */
1085                         }
1086                         break;
1087                 default:
1088                         /* encoded run */
1089                         cnt = bm[0];
1090                         runlen = cnt;
1091                         pixels += cnt;
1092                         if (pixels > limit)
1093                                 goto error;
1094
1095                         if (y < height) {     /* only draw into visible area */
1096                                 if (x >= width) {
1097                                         x += runlen;
1098                                         bm += 2;
1099                                         continue;
1100                                 }
1101                                 if (x + runlen > width)
1102                                         cnt = width - x;
1103                                 draw_bitmap(&fbp, bm, p, cnt, 1);
1104                                 x += runlen;
1105                         }
1106                         bm += 2;
1107                         break;
1108                 }
1109         }
1110         return 0;
1111 error:
1112         printf("Error: Too much encoded pixel data, validate your bitmap\n");
1113         return -1;
1114 }
1115 #endif
1116
1117 /*
1118  * Display the BMP file located at address bmp_image.
1119  */
1120 int video_display_bitmap(ulong bmp_image, int x, int y)
1121 {
1122         ushort xcount, ycount;
1123         uchar *fb;
1124         bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1125         uchar *bmap;
1126         ushort padded_line;
1127         unsigned long width, height, bpp;
1128         unsigned colors;
1129         unsigned long compression;
1130         bmp_color_table_entry_t cte;
1131
1132 #ifdef CONFIG_VIDEO_BMP_GZIP
1133         unsigned char *dst = NULL;
1134         ulong len;
1135 #endif
1136
1137         WATCHDOG_RESET();
1138
1139         if (!((bmp->header.signature[0] == 'B') &&
1140               (bmp->header.signature[1] == 'M'))) {
1141
1142 #ifdef CONFIG_VIDEO_BMP_GZIP
1143                 /*
1144                  * Could be a gzipped bmp image, try to decrompress...
1145                  */
1146                 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1147                 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
1148                 if (dst == NULL) {
1149                         printf("Error: malloc in gunzip failed!\n");
1150                         return 1;
1151                 }
1152                 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1153                            (uchar *) bmp_image,
1154                            &len) != 0) {
1155                         printf("Error: no valid bmp or bmp.gz image at %lx\n",
1156                                bmp_image);
1157                         free(dst);
1158                         return 1;
1159                 }
1160                 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1161                         printf("Image could be truncated "
1162                                 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
1163                 }
1164
1165                 /*
1166                  * Set addr to decompressed image
1167                  */
1168                 bmp = (bmp_image_t *) dst;
1169
1170                 if (!((bmp->header.signature[0] == 'B') &&
1171                       (bmp->header.signature[1] == 'M'))) {
1172                         printf("Error: no valid bmp.gz image at %lx\n",
1173                                bmp_image);
1174                         free(dst);
1175                         return 1;
1176                 }
1177 #else
1178                 printf("Error: no valid bmp image at %lx\n", bmp_image);
1179                 return 1;
1180 #endif /* CONFIG_VIDEO_BMP_GZIP */
1181         }
1182
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);
1188
1189         debug("Display-bmp: %ld x %ld  with %d colors\n",
1190               width, height, colors);
1191
1192         if (compression != BMP_BI_RGB
1193 #ifdef CONFIG_VIDEO_BMP_RLE8
1194             && compression != BMP_BI_RLE8
1195 #endif
1196                 ) {
1197                 printf("Error: compression type %ld not supported\n",
1198                        compression);
1199 #ifdef CONFIG_VIDEO_BMP_GZIP
1200                 if (dst)
1201                         free(dst);
1202 #endif
1203                 return 1;
1204         }
1205
1206         padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1207
1208 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1209         if (x == BMP_ALIGN_CENTER)
1210                 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1211         else if (x < 0)
1212                 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1213
1214         if (y == BMP_ALIGN_CENTER)
1215                 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1216         else if (y < 0)
1217                 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1218 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1219
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;
1224
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);
1229
1230 #ifdef CONFIG_VIDEO_BMP_RLE8
1231         if (compression == BMP_BI_RLE8) {
1232                 return display_rle8_bitmap(bmp, x, y, width, height);
1233         }
1234 #endif
1235
1236         /* We handle only 4, 8, or 24 bpp bitmaps */
1237         switch (le16_to_cpu(bmp->header.bit_count)) {
1238         case 4:
1239                 padded_line -= width / 2;
1240                 ycount = height;
1241
1242                 switch (VIDEO_DATA_FORMAT) {
1243                 case GDF_32BIT_X888RGB:
1244                         while (ycount--) {
1245                                 WATCHDOG_RESET();
1246                                 /*
1247                                  * Don't assume that 'width' is an
1248                                  * even number
1249                                  */
1250                                 for (xcount = 0; xcount < width; xcount++) {
1251                                         uchar idx;
1252
1253                                         if (xcount & 1) {
1254                                                 idx = *bmap & 0xF;
1255                                                 bmap++;
1256                                         } else
1257                                                 idx = *bmap >> 4;
1258                                         cte = bmp->color_table[idx];
1259                                         FILL_32BIT_X888RGB(cte.red, cte.green,
1260                                                            cte.blue);
1261                                 }
1262                                 bmap += padded_line;
1263                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1264                                         VIDEO_PIXEL_SIZE;
1265                         }
1266                         break;
1267                 default:
1268                         puts("4bpp bitmap unsupported with current "
1269                              "video mode\n");
1270                         break;
1271                 }
1272                 break;
1273
1274         case 8:
1275                 padded_line -= width;
1276                 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1277                         /* Copy colormap */
1278                         for (xcount = 0; xcount < colors; ++xcount) {
1279                                 cte = bmp->color_table[xcount];
1280                                 video_set_lut(xcount, cte.red, cte.green,
1281                                               cte.blue);
1282                         }
1283                 }
1284                 ycount = height;
1285                 switch (VIDEO_DATA_FORMAT) {
1286                 case GDF__8BIT_INDEX:
1287                         while (ycount--) {
1288                                 WATCHDOG_RESET();
1289                                 xcount = width;
1290                                 while (xcount--) {
1291                                         *fb++ = *bmap++;
1292                                 }
1293                                 bmap += padded_line;
1294                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1295                                                         VIDEO_PIXEL_SIZE;
1296                         }
1297                         break;
1298                 case GDF__8BIT_332RGB:
1299                         while (ycount--) {
1300                                 WATCHDOG_RESET();
1301                                 xcount = width;
1302                                 while (xcount--) {
1303                                         cte = bmp->color_table[*bmap++];
1304                                         FILL_8BIT_332RGB(cte.red, cte.green,
1305                                                          cte.blue);
1306                                 }
1307                                 bmap += padded_line;
1308                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1309                                                         VIDEO_PIXEL_SIZE;
1310                         }
1311                         break;
1312                 case GDF_15BIT_555RGB:
1313                         while (ycount--) {
1314 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1315                                 int xpos = x;
1316 #endif
1317                                 WATCHDOG_RESET();
1318                                 xcount = width;
1319                                 while (xcount--) {
1320                                         cte = bmp->color_table[*bmap++];
1321 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1322                                         fill_555rgb_pswap(fb, xpos++, cte.red,
1323                                                           cte.green,
1324                                                           cte.blue);
1325                                         fb += 2;
1326 #else
1327                                         FILL_15BIT_555RGB(cte.red, cte.green,
1328                                                           cte.blue);
1329 #endif
1330                                 }
1331                                 bmap += padded_line;
1332                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1333                                                         VIDEO_PIXEL_SIZE;
1334                         }
1335                         break;
1336                 case GDF_16BIT_565RGB:
1337                         while (ycount--) {
1338                                 WATCHDOG_RESET();
1339                                 xcount = width;
1340                                 while (xcount--) {
1341                                         cte = bmp->color_table[*bmap++];
1342                                         FILL_16BIT_565RGB(cte.red, cte.green,
1343                                                           cte.blue);
1344                                 }
1345                                 bmap += padded_line;
1346                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1347                                                         VIDEO_PIXEL_SIZE;
1348                         }
1349                         break;
1350                 case GDF_32BIT_X888RGB:
1351                         while (ycount--) {
1352                                 WATCHDOG_RESET();
1353                                 xcount = width;
1354                                 while (xcount--) {
1355                                         cte = bmp->color_table[*bmap++];
1356                                         FILL_32BIT_X888RGB(cte.red, cte.green,
1357                                                            cte.blue);
1358                                 }
1359                                 bmap += padded_line;
1360                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1361                                                         VIDEO_PIXEL_SIZE;
1362                         }
1363                         break;
1364                 case GDF_24BIT_888RGB:
1365                         while (ycount--) {
1366                                 WATCHDOG_RESET();
1367                                 xcount = width;
1368                                 while (xcount--) {
1369                                         cte = bmp->color_table[*bmap++];
1370                                         FILL_24BIT_888RGB(cte.red, cte.green,
1371                                                           cte.blue);
1372                                 }
1373                                 bmap += padded_line;
1374                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1375                                                         VIDEO_PIXEL_SIZE;
1376                         }
1377                         break;
1378                 }
1379                 break;
1380         case 24:
1381                 padded_line -= 3 * width;
1382                 ycount = height;
1383                 switch (VIDEO_DATA_FORMAT) {
1384                 case GDF__8BIT_332RGB:
1385                         while (ycount--) {
1386                                 WATCHDOG_RESET();
1387                                 xcount = width;
1388                                 while (xcount--) {
1389                                         FILL_8BIT_332RGB(bmap[2], bmap[1],
1390                                                          bmap[0]);
1391                                         bmap += 3;
1392                                 }
1393                                 bmap += padded_line;
1394                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1395                                                         VIDEO_PIXEL_SIZE;
1396                         }
1397                         break;
1398                 case GDF_15BIT_555RGB:
1399                         while (ycount--) {
1400 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1401                                 int xpos = x;
1402 #endif
1403                                 WATCHDOG_RESET();
1404                                 xcount = width;
1405                                 while (xcount--) {
1406 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1407                                         fill_555rgb_pswap(fb, xpos++, bmap[2],
1408                                                           bmap[1], bmap[0]);
1409                                         fb += 2;
1410 #else
1411                                         FILL_15BIT_555RGB(bmap[2], bmap[1],
1412                                                           bmap[0]);
1413 #endif
1414                                         bmap += 3;
1415                                 }
1416                                 bmap += padded_line;
1417                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1418                                                         VIDEO_PIXEL_SIZE;
1419                         }
1420                         break;
1421                 case GDF_16BIT_565RGB:
1422                         while (ycount--) {
1423                                 WATCHDOG_RESET();
1424                                 xcount = width;
1425                                 while (xcount--) {
1426                                         FILL_16BIT_565RGB(bmap[2], bmap[1],
1427                                                           bmap[0]);
1428                                         bmap += 3;
1429                                 }
1430                                 bmap += padded_line;
1431                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1432                                                         VIDEO_PIXEL_SIZE;
1433                         }
1434                         break;
1435                 case GDF_32BIT_X888RGB:
1436                         while (ycount--) {
1437                                 WATCHDOG_RESET();
1438                                 xcount = width;
1439                                 while (xcount--) {
1440                                         FILL_32BIT_X888RGB(bmap[2], bmap[1],
1441                                                            bmap[0]);
1442                                         bmap += 3;
1443                                 }
1444                                 bmap += padded_line;
1445                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1446                                                         VIDEO_PIXEL_SIZE;
1447                         }
1448                         break;
1449                 case GDF_24BIT_888RGB:
1450                         while (ycount--) {
1451                                 WATCHDOG_RESET();
1452                                 xcount = width;
1453                                 while (xcount--) {
1454                                         FILL_24BIT_888RGB(bmap[2], bmap[1],
1455                                                           bmap[0]);
1456                                         bmap += 3;
1457                                 }
1458                                 bmap += padded_line;
1459                                 fb -= (VIDEO_VISIBLE_COLS + width) *
1460                                                         VIDEO_PIXEL_SIZE;
1461                         }
1462                         break;
1463                 default:
1464                         printf("Error: 24 bits/pixel bitmap incompatible "
1465                                 "with current video mode\n");
1466                         break;
1467                 }
1468                 break;
1469         default:
1470                 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1471                         le16_to_cpu(bmp->header.bit_count));
1472                 break;
1473         }
1474
1475 #ifdef CONFIG_VIDEO_BMP_GZIP
1476         if (dst) {
1477                 free(dst);
1478         }
1479 #endif
1480
1481         return (0);
1482 }
1483 #endif
1484
1485
1486 #ifdef CONFIG_VIDEO_LOGO
1487 static int video_logo_xpos;
1488 static int video_logo_ypos;
1489
1490 void logo_plot(void *screen, int width, int x, int y)
1491 {
1492
1493         int xcount, i;
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;
1499
1500 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1501         if (x == BMP_ALIGN_CENTER)
1502                 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1503         else if (x < 0)
1504                 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1505
1506         if (y == BMP_ALIGN_CENTER)
1507                 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1508         else if (y < 0)
1509                 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1510 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1511
1512         dest = (unsigned char *)screen + (y * width  + x) * VIDEO_PIXEL_SIZE;
1513
1514 #ifdef CONFIG_VIDEO_BMP_LOGO
1515         source = bmp_logo_bitmap;
1516
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;
1526         }
1527 #else
1528         source = linux_logo;
1529         logo_red = linux_logo_red;
1530         logo_green = linux_logo_green;
1531         logo_blue = linux_logo_blue;
1532 #endif
1533
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],
1538                                       logo_blue[i]);
1539                 }
1540         }
1541
1542         while (ycount--) {
1543 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1544                 int xpos = x;
1545 #endif
1546                 xcount = VIDEO_LOGO_WIDTH;
1547                 while (xcount--) {
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];
1551
1552                         switch (VIDEO_DATA_FORMAT) {
1553                         case GDF__8BIT_INDEX:
1554                                 *dest = *source;
1555                                 break;
1556                         case GDF__8BIT_332RGB:
1557                                 *dest = ((r >> 5) << 5) |
1558                                         ((g >> 5) << 2) |
1559                                          (b >> 6);
1560                                 break;
1561                         case GDF_15BIT_555RGB:
1562 #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1563                                 fill_555rgb_pswap(dest, xpos++, r, g, b);
1564 #else
1565                                 *(unsigned short *) dest =
1566                                         SWAP16((unsigned short) (
1567                                                         ((r >> 3) << 10) |
1568                                                         ((g >> 3) <<  5) |
1569                                                          (b >> 3)));
1570 #endif
1571                                 break;
1572                         case GDF_16BIT_565RGB:
1573                                 *(unsigned short *) dest =
1574                                         SWAP16((unsigned short) (
1575                                                         ((r >> 3) << 11) |
1576                                                         ((g >> 2) <<  5) |
1577                                                          (b >> 3)));
1578                                 break;
1579                         case GDF_32BIT_X888RGB:
1580                                 *(unsigned long *) dest =
1581                                         SWAP32((unsigned long) (
1582                                                         (r << 16) |
1583                                                         (g <<  8) |
1584                                                          b));
1585                                 break;
1586                         case GDF_24BIT_888RGB:
1587 #ifdef VIDEO_FB_LITTLE_ENDIAN
1588                                 dest[0] = b;
1589                                 dest[1] = g;
1590                                 dest[2] = r;
1591 #else
1592                                 dest[0] = r;
1593                                 dest[1] = g;
1594                                 dest[2] = b;
1595 #endif
1596                                 break;
1597                         }
1598                         source++;
1599                         dest += VIDEO_PIXEL_SIZE;
1600                 }
1601                 dest += skip;
1602         }
1603 #ifdef CONFIG_VIDEO_BMP_LOGO
1604         free(logo_red);
1605         free(logo_green);
1606         free(logo_blue);
1607 #endif
1608 }
1609
1610 static void *video_logo(void)
1611 {
1612         char info[128];
1613         int space, len;
1614         __maybe_unused int y_off = 0;
1615         __maybe_unused ulong addr;
1616         __maybe_unused char *s;
1617
1618 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1619         s = getenv("splashpos");
1620         if (s != NULL) {
1621                 if (s[0] == 'm')
1622                         video_logo_xpos = BMP_ALIGN_CENTER;
1623                 else
1624                         video_logo_xpos = simple_strtol(s, NULL, 0);
1625
1626                 s = strchr(s + 1, ',');
1627                 if (s != NULL) {
1628                         if (s[1] == 'm')
1629                                 video_logo_ypos = BMP_ALIGN_CENTER;
1630                         else
1631                                 video_logo_ypos = simple_strtol(s + 1, NULL, 0);
1632                 }
1633         }
1634 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1635
1636 #ifdef CONFIG_SPLASH_SCREEN
1637         s = getenv("splashimage");
1638         if (s != NULL) {
1639
1640                 addr = simple_strtoul(s, NULL, 16);
1641
1642
1643                 if (video_display_bitmap(addr,
1644                                         video_logo_xpos,
1645                                         video_logo_ypos) == 0) {
1646                         video_logo_height = 0;
1647                         return ((void *) (video_fb_address));
1648                 }
1649         }
1650 #endif /* CONFIG_SPLASH_SCREEN */
1651
1652         logo_plot(video_fb_address, VIDEO_COLS,
1653                   video_logo_xpos, video_logo_ypos);
1654
1655 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
1656         /*
1657          * when using splashpos for video_logo, skip any info
1658          * output on video console if the logo is not at 0,0
1659          */
1660         if (video_logo_xpos || video_logo_ypos) {
1661                 /*
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
1665                  */
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;
1671
1672                 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1673         }
1674 #endif
1675
1676         sprintf(info, " %s", version_string);
1677
1678         space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1679         len = strlen(info);
1680
1681         if (len > space) {
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);
1687                 y_off = 1;
1688         } else
1689                 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
1690
1691 #ifdef CONFIG_CONSOLE_EXTRA_INFO
1692         {
1693                 int i, n =
1694                         ((video_logo_height -
1695                           VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
1696
1697                 for (i = 1; i < n; i++) {
1698                         video_get_info_str(i, info);
1699                         if (!*info)
1700                                 continue;
1701
1702                         len = strlen(info);
1703                         if (len > space) {
1704                                 video_drawchars(VIDEO_INFO_X,
1705                                                 VIDEO_INFO_Y +
1706                                                 (i + y_off) *
1707                                                         VIDEO_FONT_HEIGHT,
1708                                                 (uchar *) info, space);
1709                                 y_off++;
1710                                 video_drawchars(VIDEO_INFO_X +
1711                                                 VIDEO_FONT_WIDTH,
1712                                                 VIDEO_INFO_Y +
1713                                                         (i + y_off) *
1714                                                         VIDEO_FONT_HEIGHT,
1715                                                 (uchar *) info + space,
1716                                                 len - space);
1717                         } else {
1718                                 video_drawstring(VIDEO_INFO_X,
1719                                                  VIDEO_INFO_Y +
1720                                                  (i + y_off) *
1721                                                         VIDEO_FONT_HEIGHT,
1722                                                  (uchar *) info);
1723                         }
1724                 }
1725         }
1726 #endif
1727
1728         return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
1729 }
1730 #endif
1731
1732 static int cfb_fb_is_in_dram(void)
1733 {
1734         bd_t *bd = gd->bd;
1735 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1736 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1737         ulong start, end;
1738         int i;
1739
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)
1745                         return 1;
1746         }
1747 #else
1748         if ((ulong)video_fb_address >= bd->bi_memstart &&
1749             (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1750                 return 1;
1751 #endif
1752         return 0;
1753 }
1754
1755 static int video_init(void)
1756 {
1757         unsigned char color8;
1758
1759         pGD = video_hw_init();
1760         if (pGD == NULL)
1761                 return -1;
1762
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);
1766 #endif
1767
1768         cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
1769
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,
1774                               CONSOLE_FG_COL);
1775                 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1776                               CONSOLE_BG_COL);
1777                 fgx = 0x01010101;
1778                 bgx = 0x00000000;
1779                 break;
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) |
1785                         color8;
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) |
1790                         color8;
1791                 break;
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));
1805                 break;
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));
1819                 break;
1820         case GDF_32BIT_X888RGB:
1821                 fgx =   (CONSOLE_FG_COL << 16) |
1822                         (CONSOLE_FG_COL <<  8) |
1823                          CONSOLE_FG_COL;
1824                 bgx =   (CONSOLE_BG_COL << 16) |
1825                         (CONSOLE_BG_COL <<  8) |
1826                          CONSOLE_BG_COL;
1827                 break;
1828         case GDF_24BIT_888RGB:
1829                 fgx =   (CONSOLE_FG_COL << 24) |
1830                         (CONSOLE_FG_COL << 16) |
1831                         (CONSOLE_FG_COL <<  8) |
1832                          CONSOLE_FG_COL;
1833                 bgx =   (CONSOLE_BG_COL << 24) |
1834                         (CONSOLE_BG_COL << 16) |
1835                         (CONSOLE_BG_COL <<  8) |
1836                          CONSOLE_BG_COL;
1837                 break;
1838         }
1839         eorx = fgx ^ bgx;
1840
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();
1845 #else
1846         video_console_address = video_fb_address;
1847 #endif
1848
1849         /* Initialize the console */
1850         console_col = 0;
1851         console_row = 0;
1852
1853         return 0;
1854 }
1855
1856 /*
1857  * Implement a weak default function for boards that optionally
1858  * need to skip the video initialization.
1859  */
1860 int __board_video_skip(void)
1861 {
1862         /* As default, don't skip test */
1863         return 0;
1864 }
1865
1866 int board_video_skip(void)
1867         __attribute__ ((weak, alias("__board_video_skip")));
1868
1869 int drv_video_init(void)
1870 {
1871         int skip_dev_init;
1872         struct stdio_dev console_dev;
1873
1874         /* Check if video initialization should be skipped */
1875         if (board_video_skip())
1876                 return 0;
1877
1878         /* Init video chip - returns with framebuffer cleared */
1879         skip_dev_init = (video_init() == -1);
1880
1881 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1882         debug("KBD: Keyboard init ...\n");
1883         skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1884 #endif
1885
1886         if (skip_dev_init)
1887                 return 0;
1888
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 */
1898
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 */
1905
1906         if (stdio_register(&console_dev) != 0)
1907                 return 0;
1908
1909         /* Return success */
1910         return 1;
1911 }