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