blob: 4b9346aa5462fc2bd6d6cbe3ff45c7a426195a45 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
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
wdenke55402c2004-03-14 16:51:43 +000015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkc6097192002-11-03 00:24:07 +000016 * 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
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000032 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000033 *
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.
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000039 *
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 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
71 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
72 * strings that normaly goes to serial
73 * port. This define requires a board
74 * specific function:
75 * video_drawstring (VIDEO_INFO_X,
76 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
77 * info);
78 * that fills a info buffer at i=row.
79 * s.a: board/eltec/bab7xx.
80 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
81 * initialized as an output only device.
82 * The Keyboard driver will not be
83 * set-up. This may be used, if you have
84 * no or more than one Keyboard devices
85 * (USB Keyboard, AT Keyboard).
86 *
87 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
88 * character. No blinking is provided.
89 * Uses the macros CURSOR_SET and
90 * CURSOR_OFF.
91 *
92 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
93 * of the graphic chip. Uses the macro
94 * CURSOR_SET. ATTENTION: If booting an
95 * OS, the display driver must disable
96 * the hardware register of the graphic
97 * chip. Otherwise a blinking field is
98 * displayed.
99 */
wdenkc6097192002-11-03 00:24:07 +0000100
101#include <common.h>
Andreas Bießmann61d01952011-07-18 20:24:04 +0200102#include <version.h>
wdenk9dd2b882002-12-03 21:28:10 +0000103#include <malloc.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +0000104#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +0000105
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000106/*
107 * Console device defines with SMI graphic
108 * Any other graphic must change this section
109 */
wdenkc6097192002-11-03 00:24:07 +0000110
wdenke55402c2004-03-14 16:51:43 +0000111#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000112
113#define VIDEO_FB_LITTLE_ENDIAN
114#define VIDEO_HW_RECTFILL
115#define VIDEO_HW_BITBLT
116#endif
117
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000118/*
119 * Defines for the CT69000 driver
120 */
wdenke55402c2004-03-14 16:51:43 +0000121#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000122
123#define VIDEO_FB_LITTLE_ENDIAN
124#define VIDEO_HW_RECTFILL
125#define VIDEO_HW_BITBLT
126#endif
127
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000128/*
129 * Defines for the SED13806 driver
130 */
wdenk9dd2b882002-12-03 21:28:10 +0000131#ifdef CONFIG_VIDEO_SED13806
132
wdenkda54bc92004-08-04 21:56:49 +0000133#ifndef CONFIG_TOTAL5200
wdenk9dd2b882002-12-03 21:28:10 +0000134#define VIDEO_FB_LITTLE_ENDIAN
wdenkda54bc92004-08-04 21:56:49 +0000135#endif
wdenk9dd2b882002-12-03 21:28:10 +0000136#define VIDEO_HW_RECTFILL
137#define VIDEO_HW_BITBLT
138#endif
139
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000140/*
141 * Defines for the SED13806 driver
142 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200143#ifdef CONFIG_VIDEO_SM501
144
145#ifdef CONFIG_HH405
146#define VIDEO_FB_LITTLE_ENDIAN
147#endif
148#endif
149
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000150/*
151 * Defines for the MB862xx driver
152 */
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100153#ifdef CONFIG_VIDEO_MB862xx
154
155#ifdef CONFIG_VIDEO_CORALP
156#define VIDEO_FB_LITTLE_ENDIAN
157#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200158#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100159#define VIDEO_HW_RECTFILL
160#define VIDEO_HW_BITBLT
161#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200162#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100163
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000164/*
Helmut Raiger0385c132011-10-12 23:16:29 +0000165 * Defines for the i.MX31 driver (mx3fb.c)
166 */
167#ifdef CONFIG_VIDEO_MX3
168#define VIDEO_FB_16BPP_WORD_SWAP
169#endif
170
171/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000172 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
173 */
wdenkc6097192002-11-03 00:24:07 +0000174#include <video_fb.h>
175
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000176/*
177 * some Macros
178 */
wdenke55402c2004-03-14 16:51:43 +0000179#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
180#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
181#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
182#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
183#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000184
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000185/*
186 * Console device defines with i8042 keyboard controller
187 * Any other keyboard controller must change this section
188 */
wdenkc6097192002-11-03 00:24:07 +0000189
wdenke55402c2004-03-14 16:51:43 +0000190#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000191#include <i8042.h>
192
wdenke55402c2004-03-14 16:51:43 +0000193#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
194#define VIDEO_TSTC_FCT i8042_tstc
195#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000196#endif
197
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000198/*
199 * Console device
200 */
wdenkc6097192002-11-03 00:24:07 +0000201
202#include <version.h>
203#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200204#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000205#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000206
Jon Loeliger30c2f242007-07-10 11:13:21 -0500207#if defined(CONFIG_CMD_DATE)
208#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000209#endif
210
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500211#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000212#include <watchdog.h>
213#include <bmp_layout.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200214
215#ifdef CONFIG_SPLASH_SCREEN_ALIGN
216#define BMP_ALIGN_CENTER 0x7FFF
217#endif
218
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500219#endif
wdenke55402c2004-03-14 16:51:43 +0000220
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000221/*
222 * Cursor definition:
223 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
224 * to let the cursor blink. Uses the macros
225 * CURSOR_OFF and CURSOR_ON.
226 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
227 * blinking is provided. Uses the macros CURSOR_SET
228 * and CURSOR_OFF.
229 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
230 * graphic chip. Uses the macro CURSOR_SET.
231 * ATTENTION: If booting an OS, the display driver
232 * must disable the hardware register of the graphic
233 * chip. Otherwise a blinking field is displayed
234 */
wdenkc6097192002-11-03 00:24:07 +0000235#if !defined(CONFIG_CONSOLE_CURSOR) && \
236 !defined(CONFIG_VIDEO_SW_CURSOR) && \
237 !defined(CONFIG_VIDEO_HW_CURSOR)
238/* no Cursor defined */
239#define CURSOR_ON
240#define CURSOR_OFF
241#define CURSOR_SET
242#endif
243
wdenke55402c2004-03-14 16:51:43 +0000244#ifdef CONFIG_CONSOLE_CURSOR
245#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000246#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
247 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000248#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000249void console_cursor(int state);
250
Timur Tabibe0c74e2010-08-27 15:45:47 -0500251#define CURSOR_ON console_cursor(1)
252#define CURSOR_OFF console_cursor(0)
wdenkc6097192002-11-03 00:24:07 +0000253#define CURSOR_SET
254#ifndef CONFIG_I8042_KBD
Marcel Ziswileraea68562007-12-30 03:30:46 +0100255#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000256#endif
257#else
wdenke55402c2004-03-14 16:51:43 +0000258#ifdef CONFIG_CONSOLE_TIME
259#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
wdenkc6097192002-11-03 00:24:07 +0000260#endif
261#endif /* CONFIG_CONSOLE_CURSOR */
262
wdenke55402c2004-03-14 16:51:43 +0000263#ifdef CONFIG_VIDEO_SW_CURSOR
264#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000265#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
266 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000267#endif
268#define CURSOR_ON
269#define CURSOR_OFF video_putchar(console_col * VIDEO_FONT_WIDTH,\
Timur Tabibe0c74e2010-08-27 15:45:47 -0500270 console_row * VIDEO_FONT_HEIGHT, ' ')
271#define CURSOR_SET video_set_cursor()
wdenkc6097192002-11-03 00:24:07 +0000272#endif /* CONFIG_VIDEO_SW_CURSOR */
273
274
275#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +0000276#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000277#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
278 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000279#endif
280#define CURSOR_ON
281#define CURSOR_OFF
282#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabibe0c74e2010-08-27 15:45:47 -0500283 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000284#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000285
wdenke55402c2004-03-14 16:51:43 +0000286#ifdef CONFIG_VIDEO_LOGO
287#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000288#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000289#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000290#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
291#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
292#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
293#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000294
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000295#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000296#define LINUX_LOGO_WIDTH 80
297#define LINUX_LOGO_HEIGHT 80
298#define LINUX_LOGO_COLORS 214
299#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000300#define __initdata
301#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000302#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
303#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
304#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
305#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000306#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000307#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
308#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000309#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000310#define VIDEO_LOGO_WIDTH 0
311#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000312#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000313
wdenke55402c2004-03-14 16:51:43 +0000314#define VIDEO_COLS VIDEO_VISIBLE_COLS
315#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
316#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
317#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
318#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
319#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000320
wdenke55402c2004-03-14 16:51:43 +0000321#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100322#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000323#else
wdenke55402c2004-03-14 16:51:43 +0000324#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000325#endif
326
wdenke55402c2004-03-14 16:51:43 +0000327#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
328#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
329#define CONSOLE_ROW_FIRST (video_console_address)
330#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
331#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
332#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
333#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000334
335/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000336#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000337#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
338 ((x) >> 8) \
339 )
340#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
341 (((x) & 0x0000ff00) << 8) | \
342 (((x) & 0x00ff0000) >> 8) | \
343 (((x) & 0xff000000) >> 24) \
344 )
345#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
346 (((x) & 0x0000ff00) >> 8) | \
347 (((x) & 0x00ff0000) << 8) | \
348 (((x) & 0xff000000) >> 8) \
349 )
wdenkc6097192002-11-03 00:24:07 +0000350#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000351#define SWAP16(x) (x)
352#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200353#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000354#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500355#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000356#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100357#endif
wdenkc6097192002-11-03 00:24:07 +0000358#endif
359
wdenkc6097192002-11-03 00:24:07 +0000360#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000361/*
362 * setup a board string: type, speed, etc.
363 *
364 * line_number: location to place info string beside logo
365 * info: buffer for info string
366 */
367extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000368#endif
369
370/* Locals */
371static GraphicDevice *pGD; /* Pointer to Graphic array */
372
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000373static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000374static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000375
Matthias Weisser76d70862010-01-12 12:06:31 +0100376static int video_logo_height = VIDEO_LOGO_HEIGHT;
377
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000378static int console_col; /* cursor col */
379static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000380
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000381static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000382
383static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000384 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
385 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
386 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
387 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
388};
wdenkc6097192002-11-03 00:24:07 +0000389
390static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000391 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
392};
wdenkc6097192002-11-03 00:24:07 +0000393
394static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000395 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
396};
wdenkc6097192002-11-03 00:24:07 +0000397
398static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000399 {0x00000000, 0x00000000, 0x00000000},
400 {0x00000000, 0x00000000, 0x00ffffff},
401 {0x00000000, 0x0000ffff, 0xff000000},
402 {0x00000000, 0x0000ffff, 0xffffffff},
403 {0x000000ff, 0xffff0000, 0x00000000},
404 {0x000000ff, 0xffff0000, 0x00ffffff},
405 {0x000000ff, 0xffffffff, 0xff000000},
406 {0x000000ff, 0xffffffff, 0xffffffff},
407 {0xffffff00, 0x00000000, 0x00000000},
408 {0xffffff00, 0x00000000, 0x00ffffff},
409 {0xffffff00, 0x0000ffff, 0xff000000},
410 {0xffffff00, 0x0000ffff, 0xffffffff},
411 {0xffffffff, 0xffff0000, 0x00000000},
412 {0xffffffff, 0xffff0000, 0x00ffffff},
413 {0xffffffff, 0xffffffff, 0xff000000},
414 {0xffffffff, 0xffffffff, 0xffffffff}
415};
wdenkc6097192002-11-03 00:24:07 +0000416
417static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000418 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
419 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
420 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
421 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
422 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
423 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
424 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
425 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
426 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
427 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
428 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
429 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
430 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
431 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
432 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
433 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
434};
wdenkc6097192002-11-03 00:24:07 +0000435
wdenkc6097192002-11-03 00:24:07 +0000436
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000437static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000438{
wdenke55402c2004-03-14 16:51:43 +0000439 u8 *cdat, *dest, *dest0;
440 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000441
wdenke55402c2004-03-14 16:51:43 +0000442 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
443 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000444
wdenke55402c2004-03-14 16:51:43 +0000445 switch (VIDEO_DATA_FORMAT) {
446 case GDF__8BIT_INDEX:
447 case GDF__8BIT_332RGB:
448 while (count--) {
449 c = *s;
450 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
451 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000452 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000453 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000454
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000455 ((u32 *) dest)[0] =
456 (video_font_draw_table8[bits >> 4] &
457 eorx) ^ bgx;
458 ((u32 *) dest)[1] =
459 (video_font_draw_table8[bits & 15] &
460 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000461 }
462 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
463 s++;
464 }
465 break;
wdenkc6097192002-11-03 00:24:07 +0000466
wdenke55402c2004-03-14 16:51:43 +0000467 case GDF_15BIT_555RGB:
468 while (count--) {
469 c = *s;
470 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
471 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000472 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000473 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000474
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000475 ((u32 *) dest)[0] =
476 SHORTSWAP32((video_font_draw_table15
477 [bits >> 6] & eorx) ^
478 bgx);
479 ((u32 *) dest)[1] =
480 SHORTSWAP32((video_font_draw_table15
481 [bits >> 4 & 3] & eorx) ^
482 bgx);
483 ((u32 *) dest)[2] =
484 SHORTSWAP32((video_font_draw_table15
485 [bits >> 2 & 3] & eorx) ^
486 bgx);
487 ((u32 *) dest)[3] =
488 SHORTSWAP32((video_font_draw_table15
489 [bits & 3] & eorx) ^
490 bgx);
wdenke55402c2004-03-14 16:51:43 +0000491 }
492 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
493 s++;
494 }
495 break;
wdenkc6097192002-11-03 00:24:07 +0000496
wdenke55402c2004-03-14 16:51:43 +0000497 case GDF_16BIT_565RGB:
498 while (count--) {
499 c = *s;
500 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
501 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000502 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000503 u8 bits = *cdat++;
504
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000505 ((u32 *) dest)[0] =
506 SHORTSWAP32((video_font_draw_table16
507 [bits >> 6] & eorx) ^
508 bgx);
509 ((u32 *) dest)[1] =
510 SHORTSWAP32((video_font_draw_table16
511 [bits >> 4 & 3] & eorx) ^
512 bgx);
513 ((u32 *) dest)[2] =
514 SHORTSWAP32((video_font_draw_table16
515 [bits >> 2 & 3] & eorx) ^
516 bgx);
517 ((u32 *) dest)[3] =
518 SHORTSWAP32((video_font_draw_table16
519 [bits & 3] & eorx) ^
520 bgx);
wdenke55402c2004-03-14 16:51:43 +0000521 }
522 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
523 s++;
524 }
525 break;
526
527 case GDF_32BIT_X888RGB:
528 while (count--) {
529 c = *s;
530 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
531 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000532 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000533 u8 bits = *cdat++;
534
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000535 ((u32 *) dest)[0] =
536 SWAP32((video_font_draw_table32
537 [bits >> 4][0] & eorx) ^ bgx);
538 ((u32 *) dest)[1] =
539 SWAP32((video_font_draw_table32
540 [bits >> 4][1] & eorx) ^ bgx);
541 ((u32 *) dest)[2] =
542 SWAP32((video_font_draw_table32
543 [bits >> 4][2] & eorx) ^ bgx);
544 ((u32 *) dest)[3] =
545 SWAP32((video_font_draw_table32
546 [bits >> 4][3] & eorx) ^ bgx);
547 ((u32 *) dest)[4] =
548 SWAP32((video_font_draw_table32
549 [bits & 15][0] & eorx) ^ bgx);
550 ((u32 *) dest)[5] =
551 SWAP32((video_font_draw_table32
552 [bits & 15][1] & eorx) ^ bgx);
553 ((u32 *) dest)[6] =
554 SWAP32((video_font_draw_table32
555 [bits & 15][2] & eorx) ^ bgx);
556 ((u32 *) dest)[7] =
557 SWAP32((video_font_draw_table32
558 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000559 }
560 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
561 s++;
562 }
563 break;
564
565 case GDF_24BIT_888RGB:
566 while (count--) {
567 c = *s;
568 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
569 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000570 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000571 u8 bits = *cdat++;
572
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000573 ((u32 *) dest)[0] =
574 (video_font_draw_table24[bits >> 4][0]
575 & eorx) ^ bgx;
576 ((u32 *) dest)[1] =
577 (video_font_draw_table24[bits >> 4][1]
578 & eorx) ^ bgx;
579 ((u32 *) dest)[2] =
580 (video_font_draw_table24[bits >> 4][2]
581 & eorx) ^ bgx;
582 ((u32 *) dest)[3] =
583 (video_font_draw_table24[bits & 15][0]
584 & eorx) ^ bgx;
585 ((u32 *) dest)[4] =
586 (video_font_draw_table24[bits & 15][1]
587 & eorx) ^ bgx;
588 ((u32 *) dest)[5] =
589 (video_font_draw_table24[bits & 15][2]
590 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000591 }
592 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
593 s++;
594 }
595 break;
wdenk57b2d802003-06-27 21:31:46 +0000596 }
wdenkc6097192002-11-03 00:24:07 +0000597}
598
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000599static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000600{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000601 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000602}
603
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000604static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000605{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000606 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000607}
608
wdenkc6097192002-11-03 00:24:07 +0000609#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000610static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000611{
wdenke55402c2004-03-14 16:51:43 +0000612 /* swap drawing colors */
613 eorx = fgx;
614 fgx = bgx;
615 bgx = eorx;
616 eorx = fgx ^ bgx;
617 /* draw cursor */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000618 video_putchar(console_col * VIDEO_FONT_WIDTH,
619 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenke55402c2004-03-14 16:51:43 +0000620 /* restore drawing colors */
621 eorx = fgx;
622 fgx = bgx;
623 bgx = eorx;
624 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +0000625}
626#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000627
wdenkc6097192002-11-03 00:24:07 +0000628#ifdef CONFIG_CONSOLE_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000629void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000630{
wdenke55402c2004-03-14 16:51:43 +0000631 static int last_state = 0;
632
wdenkc6097192002-11-03 00:24:07 +0000633#ifdef CONFIG_CONSOLE_TIME
wdenke55402c2004-03-14 16:51:43 +0000634 struct rtc_time tm;
635 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000636
wdenke55402c2004-03-14 16:51:43 +0000637 /* time update only if cursor is on (faster scroll) */
638 if (state) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000639 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000640
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000641 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
642 tm.tm_sec);
643 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
644 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000645
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000646 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
647 tm.tm_year);
648 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
649 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
650 (uchar *) info);
wdenke55402c2004-03-14 16:51:43 +0000651 }
wdenkc6097192002-11-03 00:24:07 +0000652#endif
653
wdenke55402c2004-03-14 16:51:43 +0000654 if (state && (last_state != state)) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000655 video_set_cursor();
wdenke55402c2004-03-14 16:51:43 +0000656 }
wdenkc6097192002-11-03 00:24:07 +0000657
wdenke55402c2004-03-14 16:51:43 +0000658 if (!state && (last_state != state)) {
659 /* clear cursor */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000660 video_putchar(console_col * VIDEO_FONT_WIDTH,
661 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenke55402c2004-03-14 16:51:43 +0000662 }
wdenkc6097192002-11-03 00:24:07 +0000663
wdenke55402c2004-03-14 16:51:43 +0000664 last_state = state;
wdenkc6097192002-11-03 00:24:07 +0000665}
666#endif
667
wdenkc6097192002-11-03 00:24:07 +0000668#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000669static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000670{
wdenke55402c2004-03-14 16:51:43 +0000671 while (c--)
672 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000673}
674#endif
675
wdenkc6097192002-11-03 00:24:07 +0000676#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000677static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000678{
wdenke55402c2004-03-14 16:51:43 +0000679 while (c--)
680 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000681}
682#endif
683
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000684static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000685{
wdenke55402c2004-03-14 16:51:43 +0000686 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000687
688#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000689 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
690 0, /* source pos x */
691 video_logo_height +
692 VIDEO_FONT_HEIGHT, /* source pos y */
693 0, /* dest pos x */
694 video_logo_height, /* dest pos y */
695 VIDEO_VISIBLE_COLS, /* frame width */
696 VIDEO_VISIBLE_ROWS
697 - video_logo_height
698 - VIDEO_FONT_HEIGHT /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000699 );
wdenkc6097192002-11-03 00:24:07 +0000700#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000701 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
702 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000703#endif
704
wdenke55402c2004-03-14 16:51:43 +0000705 /* clear the last one */
wdenkc6097192002-11-03 00:24:07 +0000706#ifdef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000707 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
708 0, /* dest pos x */
709 VIDEO_VISIBLE_ROWS
710 - VIDEO_FONT_HEIGHT, /* dest pos y */
711 VIDEO_VISIBLE_COLS, /* frame width */
712 VIDEO_FONT_HEIGHT, /* frame height */
713 CONSOLE_BG_COL /* fill color */
wdenke55402c2004-03-14 16:51:43 +0000714 );
wdenkc6097192002-11-03 00:24:07 +0000715#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000716 memsetl(CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, CONSOLE_BG_COL);
wdenkc6097192002-11-03 00:24:07 +0000717#endif
718}
719
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000720static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000721{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500722 CURSOR_OFF;
723 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000724
wdenke55402c2004-03-14 16:51:43 +0000725 if (console_col < 0) {
726 console_col = CONSOLE_COLS - 1;
727 console_row--;
728 if (console_row < 0)
729 console_row = 0;
730 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000731 video_putchar(console_col * VIDEO_FONT_WIDTH,
732 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenkc6097192002-11-03 00:24:07 +0000733}
734
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000735static void console_newline(void)
wdenkc6097192002-11-03 00:24:07 +0000736{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100737 /* Check if last character in the line was just drawn. If so, cursor was
738 overwriten and need not to be cleared. Cursor clearing without this
739 check causes overwriting the 1st character of the line if line lenght
740 is >= CONSOLE_COLS
741 */
742 if (console_col < CONSOLE_COLS)
Timur Tabibe0c74e2010-08-27 15:45:47 -0500743 CURSOR_OFF;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100744 console_row++;
wdenke55402c2004-03-14 16:51:43 +0000745 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000746
wdenke55402c2004-03-14 16:51:43 +0000747 /* Check if we need to scroll the terminal */
748 if (console_row >= CONSOLE_ROWS) {
749 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000750 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000751
wdenke55402c2004-03-14 16:51:43 +0000752 /* Decrement row number */
753 console_row--;
754 }
wdenkc6097192002-11-03 00:24:07 +0000755}
756
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000757static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100758{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500759 CURSOR_OFF;
760 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100761}
762
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000763void video_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000764{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100765 static int nl = 1;
766
wdenke55402c2004-03-14 16:51:43 +0000767 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100768 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000769 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000770 break;
wdenkc6097192002-11-03 00:24:07 +0000771
wdenke55402c2004-03-14 16:51:43 +0000772 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100773 if (console_col || (!console_col && nl))
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000774 console_newline();
Anatolij Gustschin938db912008-01-11 02:39:47 +0100775 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000776 break;
wdenkc6097192002-11-03 00:24:07 +0000777
wdenke55402c2004-03-14 16:51:43 +0000778 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500779 CURSOR_OFF;
780 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000781 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000782
wdenke55402c2004-03-14 16:51:43 +0000783 if (console_col >= CONSOLE_COLS)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000784 console_newline();
wdenke55402c2004-03-14 16:51:43 +0000785 break;
wdenkc6097192002-11-03 00:24:07 +0000786
wdenke55402c2004-03-14 16:51:43 +0000787 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000788 console_back();
wdenke55402c2004-03-14 16:51:43 +0000789 break;
wdenkc6097192002-11-03 00:24:07 +0000790
wdenke55402c2004-03-14 16:51:43 +0000791 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000792 video_putchar(console_col * VIDEO_FONT_WIDTH,
793 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000794 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000795
wdenke55402c2004-03-14 16:51:43 +0000796 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100797 if (console_col >= CONSOLE_COLS) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000798 console_newline();
Anatolij Gustschin938db912008-01-11 02:39:47 +0100799 nl = 0;
800 }
wdenke55402c2004-03-14 16:51:43 +0000801 }
Timur Tabibe0c74e2010-08-27 15:45:47 -0500802 CURSOR_SET;
803}
wdenkc6097192002-11-03 00:24:07 +0000804
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000805void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +0000806{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000807 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +0000808
809 while (count--)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000810 video_putc(*s++);
wdenke55402c2004-03-14 16:51:43 +0000811}
812
Anatolij Gustschina043c342010-05-01 22:21:09 +0200813/*
814 * Do not enforce drivers (or board code) to provide empty
815 * video_set_lut() if they do not support 8 bpp format.
816 * Implement weak default function instead.
817 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000818void __video_set_lut(unsigned int index, unsigned char r,
819 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +0200820{
821}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000822
823void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
824 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschina043c342010-05-01 22:21:09 +0200825
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500826#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000827
828#define FILL_8BIT_332RGB(r,g,b) { \
829 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
830 fb ++; \
831}
832
833#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000834 *(unsigned short *)fb = \
835 SWAP16((unsigned short)(((r>>3)<<10) | \
836 ((g>>3)<<5) | \
837 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +0000838 fb += 2; \
839}
840
841#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000842 *(unsigned short *)fb = \
843 SWAP16((unsigned short)((((r)>>3)<<11)| \
844 (((g)>>2)<<5) | \
845 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +0000846 fb += 2; \
847}
848
849#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000850 *(unsigned long *)fb = \
851 SWAP32((unsigned long)(((r<<16) | \
852 (g<<8) | \
853 b))); \
wdenke55402c2004-03-14 16:51:43 +0000854 fb += 4; \
855}
856
857#ifdef VIDEO_FB_LITTLE_ENDIAN
858#define FILL_24BIT_888RGB(r,g,b) { \
859 fb[0] = b; \
860 fb[1] = g; \
861 fb[2] = r; \
862 fb += 3; \
863}
864#else
865#define FILL_24BIT_888RGB(r,g,b) { \
866 fb[0] = r; \
867 fb[1] = g; \
868 fb[2] = b; \
869 fb += 3; \
870}
871#endif
872
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200873#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000874static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200875{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000876 ushort *dst = (ushort *) fb;
877 ushort color = (ushort) (((r >> 3) << 10) |
878 ((g >> 3) << 5) |
879 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200880 if (x & 1)
881 *(--dst) = color;
882 else
883 *(++dst) = color;
884}
885#endif
wdenke55402c2004-03-14 16:51:43 +0000886
887/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100888 * RLE8 bitmap support
889 */
890
891#ifdef CONFIG_VIDEO_BMP_RLE8
892/* Pre-calculated color table entry */
893struct palette {
894 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000895 unsigned short w; /* word */
896 unsigned int dw; /* double word */
897 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100898};
899
900/*
901 * Helper to draw encoded/unencoded run.
902 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000903static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
904 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100905{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000906 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100907 int *off;
908 int enc_off = 1;
909 int i;
910
911 /*
912 * Setup offset of the color index in the bitmap.
913 * Color index of encoded run is at offset 1.
914 */
915 off = enc ? &enc_off : &i;
916
917 switch (VIDEO_DATA_FORMAT) {
918 case GDF__8BIT_INDEX:
919 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000920 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100921 break;
922 case GDF_15BIT_555RGB:
923 case GDF_16BIT_565RGB:
924 /* differences handled while pre-calculating palette */
925 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000926 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100927 addr += 2;
928 }
929 break;
930 case GDF_32BIT_X888RGB:
931 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000932 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100933 addr += 4;
934 }
935 break;
936 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000937 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100938}
939
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000940static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
941 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100942{
943 unsigned char *bm;
944 unsigned char *fbp;
945 unsigned int cnt, runlen;
946 int decode = 1;
947 int x, y, bpp, i, ncolors;
948 struct palette p[256];
949 bmp_color_table_entry_t cte;
950 int green_shift, red_off;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +0100951 int limit = VIDEO_COLS * VIDEO_ROWS;
952 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100953
954 x = 0;
955 y = __le32_to_cpu(img->header.height) - 1;
956 ncolors = __le32_to_cpu(img->header.colors_used);
957 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000958 fbp = (unsigned char *) ((unsigned int) video_fb_address +
959 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100960
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000961 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100962
963 /* pre-calculate and setup palette */
964 switch (VIDEO_DATA_FORMAT) {
965 case GDF__8BIT_INDEX:
966 for (i = 0; i < ncolors; i++) {
967 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000968 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100969 }
970 break;
971 case GDF_15BIT_555RGB:
972 case GDF_16BIT_565RGB:
973 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
974 green_shift = 3;
975 red_off = 10;
976 } else {
977 green_shift = 2;
978 red_off = 11;
979 }
980 for (i = 0; i < ncolors; i++) {
981 cte = img->color_table[i];
982 p[i].ce.w = SWAP16((unsigned short)
983 (((cte.red >> 3) << red_off) |
984 ((cte.green >> green_shift) << 5) |
985 cte.blue >> 3));
986 }
987 break;
988 case GDF_32BIT_X888RGB:
989 for (i = 0; i < ncolors; i++) {
990 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000991 p[i].ce.dw = SWAP32((cte.red << 16) |
992 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100993 cte.blue);
994 }
995 break;
996 default:
997 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000998 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100999 return -1;
1000 }
1001
1002 while (decode) {
1003 switch (bm[0]) {
1004 case 0:
1005 switch (bm[1]) {
1006 case 0:
1007 /* scan line end marker */
1008 bm += 2;
1009 x = 0;
1010 y--;
1011 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001012 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001013 (((y + yoff) * VIDEO_COLS) +
1014 xoff) * bpp);
1015 continue;
1016 case 1:
1017 /* end of bitmap data marker */
1018 decode = 0;
1019 break;
1020 case 2:
1021 /* run offset marker */
1022 x += bm[2];
1023 y -= bm[3];
1024 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001025 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001026 (((y + yoff) * VIDEO_COLS) +
1027 x + xoff) * bpp);
1028 bm += 4;
1029 break;
1030 default:
1031 /* unencoded run */
1032 cnt = bm[1];
1033 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001034 pixels += cnt;
1035 if (pixels > limit)
1036 goto error;
1037
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001038 bm += 2;
1039 if (y < height) {
1040 if (x >= width) {
1041 x += runlen;
1042 goto next_run;
1043 }
1044 if (x + runlen > width)
1045 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001046 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001047 x += runlen;
1048 }
1049next_run:
1050 bm += runlen;
1051 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001052 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001053 }
1054 break;
1055 default:
1056 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001057 cnt = bm[0];
1058 runlen = cnt;
1059 pixels += cnt;
1060 if (pixels > limit)
1061 goto error;
1062
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001063 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001064 if (x >= width) {
1065 x += runlen;
1066 bm += 2;
1067 continue;
1068 }
1069 if (x + runlen > width)
1070 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001071 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001072 x += runlen;
1073 }
1074 bm += 2;
1075 break;
1076 }
1077 }
1078 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001079error:
1080 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1081 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001082}
1083#endif
1084
1085/*
wdenke55402c2004-03-14 16:51:43 +00001086 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001087 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001088int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001089{
1090 ushort xcount, ycount;
1091 uchar *fb;
1092 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1093 uchar *bmap;
1094 ushort padded_line;
1095 unsigned long width, height, bpp;
1096 unsigned colors;
1097 unsigned long compression;
1098 bmp_color_table_entry_t cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001099
Stefan Roesed9d97742005-09-22 09:04:17 +02001100#ifdef CONFIG_VIDEO_BMP_GZIP
1101 unsigned char *dst = NULL;
1102 ulong len;
1103#endif
wdenkc6097192002-11-03 00:24:07 +00001104
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001105 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001106
1107 if (!((bmp->header.signature[0] == 'B') &&
1108 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001109
1110#ifdef CONFIG_VIDEO_BMP_GZIP
1111 /*
1112 * Could be a gzipped bmp image, try to decrompress...
1113 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001114 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1115 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001116 if (dst == NULL) {
1117 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001118 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001119 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001120 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1121 (uchar *) bmp_image,
1122 &len) != 0) {
1123 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1124 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001125 free(dst);
1126 return 1;
1127 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001128 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001129 printf("Image could be truncated "
1130 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001131 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001132
1133 /*
1134 * Set addr to decompressed image
1135 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001136 bmp = (bmp_image_t *) dst;
Stefan Roesed9d97742005-09-22 09:04:17 +02001137
1138 if (!((bmp->header.signature[0] == 'B') &&
1139 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001140 printf("Error: no valid bmp.gz image at %lx\n",
1141 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001142 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001143 return 1;
1144 }
1145#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001146 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001147 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001148#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001149 }
1150
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001151 width = le32_to_cpu(bmp->header.width);
1152 height = le32_to_cpu(bmp->header.height);
1153 bpp = le16_to_cpu(bmp->header.bit_count);
1154 colors = le32_to_cpu(bmp->header.colors_used);
1155 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001156
Marek Vasut2eb9a492011-10-21 14:17:04 +00001157 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001158 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001159
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001160 if (compression != BMP_BI_RGB
1161#ifdef CONFIG_VIDEO_BMP_RLE8
1162 && compression != BMP_BI_RLE8
1163#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001164 ) {
1165 printf("Error: compression type %ld not supported\n",
1166 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001167#ifdef CONFIG_VIDEO_BMP_GZIP
1168 if (dst)
1169 free(dst);
1170#endif
wdenke55402c2004-03-14 16:51:43 +00001171 return 1;
1172 }
1173
1174 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1175
Matthias Weisser53884182009-07-09 16:07:30 +02001176#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1177 if (x == BMP_ALIGN_CENTER)
1178 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1179 else if (x < 0)
1180 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1181
1182 if (y == BMP_ALIGN_CENTER)
1183 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1184 else if (y < 0)
1185 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1186#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1187
wdenke55402c2004-03-14 16:51:43 +00001188 if ((x + width) > VIDEO_VISIBLE_COLS)
1189 width = VIDEO_VISIBLE_COLS - x;
1190 if ((y + height) > VIDEO_VISIBLE_ROWS)
1191 height = VIDEO_VISIBLE_ROWS - y;
1192
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001193 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001194 fb = (uchar *) (video_fb_address +
1195 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1196 x * VIDEO_PIXEL_SIZE);
1197
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001198#ifdef CONFIG_VIDEO_BMP_RLE8
1199 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001200 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001201 }
1202#endif
1203
Timur Tabi0fce9922010-08-23 16:58:00 -05001204 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001205 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001206 case 4:
1207 padded_line -= width / 2;
1208 ycount = height;
1209
1210 switch (VIDEO_DATA_FORMAT) {
1211 case GDF_32BIT_X888RGB:
1212 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001213 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001214 /*
1215 * Don't assume that 'width' is an
1216 * even number
1217 */
1218 for (xcount = 0; xcount < width; xcount++) {
1219 uchar idx;
1220
1221 if (xcount & 1) {
1222 idx = *bmap & 0xF;
1223 bmap++;
1224 } else
1225 idx = *bmap >> 4;
1226 cte = bmp->color_table[idx];
1227 FILL_32BIT_X888RGB(cte.red, cte.green,
1228 cte.blue);
1229 }
1230 bmap += padded_line;
1231 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001232 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001233 }
1234 break;
1235 default:
1236 puts("4bpp bitmap unsupported with current "
1237 "video mode\n");
1238 break;
1239 }
1240 break;
1241
wdenke55402c2004-03-14 16:51:43 +00001242 case 8:
1243 padded_line -= width;
1244 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001245 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001246 for (xcount = 0; xcount < colors; ++xcount) {
1247 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001248 video_set_lut(xcount, cte.red, cte.green,
1249 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001250 }
1251 }
1252 ycount = height;
1253 switch (VIDEO_DATA_FORMAT) {
1254 case GDF__8BIT_INDEX:
1255 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001256 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001257 xcount = width;
1258 while (xcount--) {
1259 *fb++ = *bmap++;
1260 }
1261 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001262 fb -= (VIDEO_VISIBLE_COLS + width) *
1263 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001264 }
1265 break;
1266 case GDF__8BIT_332RGB:
1267 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001268 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001269 xcount = width;
1270 while (xcount--) {
1271 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001272 FILL_8BIT_332RGB(cte.red, cte.green,
1273 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001274 }
1275 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001276 fb -= (VIDEO_VISIBLE_COLS + width) *
1277 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001278 }
1279 break;
1280 case GDF_15BIT_555RGB:
1281 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001282#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1283 int xpos = x;
1284#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001285 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001286 xcount = width;
1287 while (xcount--) {
1288 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001289#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001290 fill_555rgb_pswap(fb, xpos++, cte.red,
1291 cte.green,
1292 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001293 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001294#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001295 FILL_15BIT_555RGB(cte.red, cte.green,
1296 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001297#endif
wdenke55402c2004-03-14 16:51:43 +00001298 }
1299 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001300 fb -= (VIDEO_VISIBLE_COLS + width) *
1301 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001302 }
1303 break;
1304 case GDF_16BIT_565RGB:
1305 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001306 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001307 xcount = width;
1308 while (xcount--) {
1309 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001310 FILL_16BIT_565RGB(cte.red, cte.green,
1311 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001312 }
1313 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001314 fb -= (VIDEO_VISIBLE_COLS + width) *
1315 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001316 }
1317 break;
1318 case GDF_32BIT_X888RGB:
1319 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001320 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001321 xcount = width;
1322 while (xcount--) {
1323 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001324 FILL_32BIT_X888RGB(cte.red, cte.green,
1325 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001326 }
1327 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001328 fb -= (VIDEO_VISIBLE_COLS + width) *
1329 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001330 }
1331 break;
1332 case GDF_24BIT_888RGB:
1333 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001334 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001335 xcount = width;
1336 while (xcount--) {
1337 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001338 FILL_24BIT_888RGB(cte.red, cte.green,
1339 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001340 }
1341 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001342 fb -= (VIDEO_VISIBLE_COLS + width) *
1343 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001344 }
1345 break;
1346 }
1347 break;
1348 case 24:
1349 padded_line -= 3 * width;
1350 ycount = height;
1351 switch (VIDEO_DATA_FORMAT) {
1352 case GDF__8BIT_332RGB:
1353 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001354 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001355 xcount = width;
1356 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001357 FILL_8BIT_332RGB(bmap[2], bmap[1],
1358 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001359 bmap += 3;
1360 }
1361 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001362 fb -= (VIDEO_VISIBLE_COLS + width) *
1363 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001364 }
1365 break;
1366 case GDF_15BIT_555RGB:
1367 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001368#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1369 int xpos = x;
1370#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001371 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001372 xcount = width;
1373 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001374#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001375 fill_555rgb_pswap(fb, xpos++, bmap[2],
1376 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001377 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001378#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001379 FILL_15BIT_555RGB(bmap[2], bmap[1],
1380 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001381#endif
wdenke55402c2004-03-14 16:51:43 +00001382 bmap += 3;
1383 }
1384 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001385 fb -= (VIDEO_VISIBLE_COLS + width) *
1386 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001387 }
1388 break;
1389 case GDF_16BIT_565RGB:
1390 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001391 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001392 xcount = width;
1393 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001394 FILL_16BIT_565RGB(bmap[2], bmap[1],
1395 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001396 bmap += 3;
1397 }
1398 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001399 fb -= (VIDEO_VISIBLE_COLS + width) *
1400 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001401 }
1402 break;
1403 case GDF_32BIT_X888RGB:
1404 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001405 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001406 xcount = width;
1407 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001408 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1409 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001410 bmap += 3;
1411 }
1412 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001413 fb -= (VIDEO_VISIBLE_COLS + width) *
1414 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001415 }
1416 break;
1417 case GDF_24BIT_888RGB:
1418 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001419 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001420 xcount = width;
1421 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001422 FILL_24BIT_888RGB(bmap[2], bmap[1],
1423 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001424 bmap += 3;
1425 }
1426 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001427 fb -= (VIDEO_VISIBLE_COLS + width) *
1428 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001429 }
1430 break;
1431 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001432 printf("Error: 24 bits/pixel bitmap incompatible "
1433 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001434 break;
1435 }
1436 break;
1437 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001438 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1439 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001440 break;
1441 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001442
1443#ifdef CONFIG_VIDEO_BMP_GZIP
1444 if (dst) {
1445 free(dst);
1446 }
1447#endif
1448
wdenke55402c2004-03-14 16:51:43 +00001449 return (0);
wdenkc6097192002-11-03 00:24:07 +00001450}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001451#endif
wdenkc6097192002-11-03 00:24:07 +00001452
wdenkc6097192002-11-03 00:24:07 +00001453
1454#ifdef CONFIG_VIDEO_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001455void logo_plot(void *screen, int width, int x, int y)
wdenkc6097192002-11-03 00:24:07 +00001456{
wdenk9dd2b882002-12-03 21:28:10 +00001457
wdenke55402c2004-03-14 16:51:43 +00001458 int xcount, i;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001459 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001460 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001461 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1462 unsigned char *source;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001463 unsigned char *dest = (unsigned char *) screen +
1464 ((y * width * VIDEO_PIXEL_SIZE) + x * VIDEO_PIXEL_SIZE);
wdenkc6097192002-11-03 00:24:07 +00001465
wdenk9dd2b882002-12-03 21:28:10 +00001466#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001467 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001468
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001469 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001470 logo_red = malloc(BMP_LOGO_COLORS);
1471 logo_green = malloc(BMP_LOGO_COLORS);
1472 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001473 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001474 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1475 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1476 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1477 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1478 }
wdenk9dd2b882002-12-03 21:28:10 +00001479#else
wdenke55402c2004-03-14 16:51:43 +00001480 source = linux_logo;
1481 logo_red = linux_logo_red;
1482 logo_green = linux_logo_green;
1483 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001484#endif
wdenk57b2d802003-06-27 21:31:46 +00001485
wdenke55402c2004-03-14 16:51:43 +00001486 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1487 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001488 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1489 logo_red[i], logo_green[i],
1490 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001491 }
wdenk57b2d802003-06-27 21:31:46 +00001492 }
wdenkc6097192002-11-03 00:24:07 +00001493
wdenke55402c2004-03-14 16:51:43 +00001494 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001495#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1496 int xpos = x;
1497#endif
wdenke55402c2004-03-14 16:51:43 +00001498 xcount = VIDEO_LOGO_WIDTH;
1499 while (xcount--) {
1500 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1501 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1502 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
wdenk57b2d802003-06-27 21:31:46 +00001503
wdenke55402c2004-03-14 16:51:43 +00001504 switch (VIDEO_DATA_FORMAT) {
1505 case GDF__8BIT_INDEX:
1506 *dest = *source;
1507 break;
1508 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001509 *dest = ((r >> 5) << 5) |
1510 ((g >> 5) << 2) |
1511 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001512 break;
1513 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001514#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001515 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001516#else
wdenke55402c2004-03-14 16:51:43 +00001517 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001518 SWAP16((unsigned short) (
1519 ((r >> 3) << 10) |
1520 ((g >> 3) << 5) |
1521 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001522#endif
wdenke55402c2004-03-14 16:51:43 +00001523 break;
1524 case GDF_16BIT_565RGB:
1525 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001526 SWAP16((unsigned short) (
1527 ((r >> 3) << 11) |
1528 ((g >> 2) << 5) |
1529 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001530 break;
1531 case GDF_32BIT_X888RGB:
1532 *(unsigned long *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001533 SWAP32((unsigned long) (
1534 (r << 16) |
1535 (g << 8) |
1536 b));
wdenke55402c2004-03-14 16:51:43 +00001537 break;
1538 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001539#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001540 dest[0] = b;
1541 dest[1] = g;
1542 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001543#else
wdenke55402c2004-03-14 16:51:43 +00001544 dest[0] = r;
1545 dest[1] = g;
1546 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001547#endif
wdenke55402c2004-03-14 16:51:43 +00001548 break;
1549 }
1550 source++;
1551 dest += VIDEO_PIXEL_SIZE;
1552 }
1553 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001554 }
wdenk9dd2b882002-12-03 21:28:10 +00001555#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001556 free(logo_red);
1557 free(logo_green);
1558 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001559#endif
wdenkc6097192002-11-03 00:24:07 +00001560}
1561
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001562static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001563{
wdenke55402c2004-03-14 16:51:43 +00001564 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001565 int space, len;
1566 __maybe_unused int y_off = 0;
wdenke55402c2004-03-14 16:51:43 +00001567
1568#ifdef CONFIG_SPLASH_SCREEN
1569 char *s;
1570 ulong addr;
1571
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001572 s = getenv("splashimage");
1573 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001574 int x = 0, y = 0;
1575
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001576 addr = simple_strtoul(s, NULL, 16);
Matthias Weisser53884182009-07-09 16:07:30 +02001577#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001578 s = getenv("splashpos");
1579 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001580 if (s[0] == 'm')
1581 x = BMP_ALIGN_CENTER;
1582 else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001583 x = simple_strtol(s, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001584
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001585 s = strchr(s + 1, ',');
1586 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001587 if (s[1] == 'm')
1588 y = BMP_ALIGN_CENTER;
1589 else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001590 y = simple_strtol(s + 1, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001591 }
1592 }
1593#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
wdenke55402c2004-03-14 16:51:43 +00001594
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001595 if (video_display_bitmap(addr, x, y) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001596 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001597 return ((void *) (video_fb_address));
1598 }
1599 }
1600#endif /* CONFIG_SPLASH_SCREEN */
1601
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001602 logo_plot(video_fb_address, VIDEO_COLS, 0, 0);
wdenkc6097192002-11-03 00:24:07 +00001603
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001604 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001605
1606 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1607 len = strlen(info);
1608
1609 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001610 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1611 (uchar *) info, space);
1612 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1613 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1614 (uchar *) info + space, len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001615 y_off = 1;
1616 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001617 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001618
1619#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001620 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001621 int i, n =
1622 ((video_logo_height -
1623 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001624
wdenke55402c2004-03-14 16:51:43 +00001625 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001626 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001627 if (!*info)
1628 continue;
1629
1630 len = strlen(info);
1631 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001632 video_drawchars(VIDEO_INFO_X,
1633 VIDEO_INFO_Y +
1634 (i + y_off) *
1635 VIDEO_FONT_HEIGHT,
1636 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001637 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001638 video_drawchars(VIDEO_INFO_X +
1639 VIDEO_FONT_WIDTH,
1640 VIDEO_INFO_Y +
1641 (i + y_off) *
1642 VIDEO_FONT_HEIGHT,
1643 (uchar *) info + space,
1644 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001645 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001646 video_drawstring(VIDEO_INFO_X,
1647 VIDEO_INFO_Y +
1648 (i + y_off) *
1649 VIDEO_FONT_HEIGHT,
1650 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001651 }
wdenke55402c2004-03-14 16:51:43 +00001652 }
1653 }
wdenkc6097192002-11-03 00:24:07 +00001654#endif
1655
Matthias Weisser76d70862010-01-12 12:06:31 +01001656 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001657}
1658#endif
1659
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001660static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001661{
wdenke55402c2004-03-14 16:51:43 +00001662 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001663
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001664 pGD = video_hw_init();
1665 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00001666 return -1;
wdenkc6097192002-11-03 00:24:07 +00001667
wdenke55402c2004-03-14 16:51:43 +00001668 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001669#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001670 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001671#endif
1672
wdenke55402c2004-03-14 16:51:43 +00001673 /* Init drawing pats */
1674 switch (VIDEO_DATA_FORMAT) {
1675 case GDF__8BIT_INDEX:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001676 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
1677 CONSOLE_FG_COL);
1678 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1679 CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00001680 fgx = 0x01010101;
1681 bgx = 0x00000000;
1682 break;
1683 case GDF__8BIT_332RGB:
1684 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001685 ((CONSOLE_FG_COL >> 3) & 0x1c) |
1686 CONSOLE_FG_COL >> 6);
1687 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1688 color8;
wdenke55402c2004-03-14 16:51:43 +00001689 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001690 ((CONSOLE_BG_COL >> 3) & 0x1c) |
1691 CONSOLE_BG_COL >> 6);
1692 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1693 color8;
wdenke55402c2004-03-14 16:51:43 +00001694 break;
1695 case GDF_15BIT_555RGB:
1696 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001697 ((CONSOLE_FG_COL >> 3) << 21) |
1698 ((CONSOLE_FG_COL >> 3) << 16) |
1699 ((CONSOLE_FG_COL >> 3) << 10) |
1700 ((CONSOLE_FG_COL >> 3) << 5) |
1701 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001702 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001703 ((CONSOLE_BG_COL >> 3) << 21) |
1704 ((CONSOLE_BG_COL >> 3) << 16) |
1705 ((CONSOLE_BG_COL >> 3) << 10) |
1706 ((CONSOLE_BG_COL >> 3) << 5) |
1707 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001708 break;
1709 case GDF_16BIT_565RGB:
1710 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001711 ((CONSOLE_FG_COL >> 2) << 21) |
1712 ((CONSOLE_FG_COL >> 3) << 16) |
1713 ((CONSOLE_FG_COL >> 3) << 11) |
1714 ((CONSOLE_FG_COL >> 2) << 5) |
1715 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001716 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001717 ((CONSOLE_BG_COL >> 2) << 21) |
1718 ((CONSOLE_BG_COL >> 3) << 16) |
1719 ((CONSOLE_BG_COL >> 3) << 11) |
1720 ((CONSOLE_BG_COL >> 2) << 5) |
1721 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001722 break;
1723 case GDF_32BIT_X888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001724 fgx = (CONSOLE_FG_COL << 16) |
1725 (CONSOLE_FG_COL << 8) |
1726 CONSOLE_FG_COL;
1727 bgx = (CONSOLE_BG_COL << 16) |
1728 (CONSOLE_BG_COL << 8) |
1729 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00001730 break;
1731 case GDF_24BIT_888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001732 fgx = (CONSOLE_FG_COL << 24) |
1733 (CONSOLE_FG_COL << 16) |
1734 (CONSOLE_FG_COL << 8) |
1735 CONSOLE_FG_COL;
1736 bgx = (CONSOLE_BG_COL << 24) |
1737 (CONSOLE_BG_COL << 16) |
1738 (CONSOLE_BG_COL << 8) |
1739 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00001740 break;
1741 }
1742 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001743
1744#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00001745 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00001746 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001747 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00001748#else
wdenke55402c2004-03-14 16:51:43 +00001749 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001750#endif
1751
wdenke55402c2004-03-14 16:51:43 +00001752 /* Initialize the console */
1753 console_col = 0;
1754 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001755
wdenke55402c2004-03-14 16:51:43 +00001756 return 0;
wdenkc6097192002-11-03 00:24:07 +00001757}
1758
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001759/*
1760 * Implement a weak default function for boards that optionally
1761 * need to skip the video initialization.
1762 */
1763int __board_video_skip(void)
1764{
1765 /* As default, don't skip test */
1766 return 0;
1767}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001768
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001769int board_video_skip(void)
1770 __attribute__ ((weak, alias("__board_video_skip")));
1771
1772int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001773{
wdenke55402c2004-03-14 16:51:43 +00001774 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02001775 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00001776
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001777 /* Check if video initialization should be skipped */
1778 if (board_video_skip())
1779 return 0;
1780
wdenk7dd13292004-07-11 20:04:51 +00001781 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001782 skip_dev_init = (video_init() == -1);
wdenkc6097192002-11-03 00:24:07 +00001783
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001784#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk46717712011-07-29 09:55:28 +00001785 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001786 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1787#endif
wdenkc6097192002-11-03 00:24:07 +00001788
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001789 if (skip_dev_init)
1790 return 0;
wdenkc6097192002-11-03 00:24:07 +00001791
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001792 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001793 memset(&console_dev, 0, sizeof(console_dev));
1794 strcpy(console_dev.name, "vga");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001795 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1796 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1797 console_dev.putc = video_putc; /* 'putc' function */
1798 console_dev.puts = video_puts; /* 'puts' function */
1799 console_dev.tstc = NULL; /* 'tstc' function */
1800 console_dev.getc = NULL; /* 'getc' function */
1801
1802#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1803 /* Also init console device */
1804 console_dev.flags |= DEV_FLAGS_INPUT;
1805 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1806 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00001807#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001808
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001809 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001810 return 0;
1811
1812 /* Return success */
1813 return 1;
wdenkc6097192002-11-03 00:24:07 +00001814}