blob: 3a93b64dad473a47f95a54df5b94d7d85575b66a [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>
104
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000105/*
106 * Console device defines with SMI graphic
107 * Any other graphic must change this section
108 */
wdenkc6097192002-11-03 00:24:07 +0000109
wdenke55402c2004-03-14 16:51:43 +0000110#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000111
112#define VIDEO_FB_LITTLE_ENDIAN
113#define VIDEO_HW_RECTFILL
114#define VIDEO_HW_BITBLT
115#endif
116
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000117/*
118 * Defines for the CT69000 driver
119 */
wdenke55402c2004-03-14 16:51:43 +0000120#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000121
122#define VIDEO_FB_LITTLE_ENDIAN
123#define VIDEO_HW_RECTFILL
124#define VIDEO_HW_BITBLT
125#endif
126
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000127/*
128 * Defines for the SED13806 driver
129 */
wdenk9dd2b882002-12-03 21:28:10 +0000130#ifdef CONFIG_VIDEO_SED13806
131
wdenkda54bc92004-08-04 21:56:49 +0000132#ifndef CONFIG_TOTAL5200
wdenk9dd2b882002-12-03 21:28:10 +0000133#define VIDEO_FB_LITTLE_ENDIAN
wdenkda54bc92004-08-04 21:56:49 +0000134#endif
wdenk9dd2b882002-12-03 21:28:10 +0000135#define VIDEO_HW_RECTFILL
136#define VIDEO_HW_BITBLT
137#endif
138
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000139/*
140 * Defines for the SED13806 driver
141 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200142#ifdef CONFIG_VIDEO_SM501
143
144#ifdef CONFIG_HH405
145#define VIDEO_FB_LITTLE_ENDIAN
146#endif
147#endif
148
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000149/*
150 * Defines for the MB862xx driver
151 */
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100152#ifdef CONFIG_VIDEO_MB862xx
153
154#ifdef CONFIG_VIDEO_CORALP
155#define VIDEO_FB_LITTLE_ENDIAN
156#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200157#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100158#define VIDEO_HW_RECTFILL
159#define VIDEO_HW_BITBLT
160#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200161#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100162
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000163/*
164 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
165 */
wdenkc6097192002-11-03 00:24:07 +0000166#include <video_fb.h>
167
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000168/*
169 * some Macros
170 */
wdenke55402c2004-03-14 16:51:43 +0000171#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
172#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
173#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
174#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
175#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000176
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000177/*
178 * Console device defines with i8042 keyboard controller
179 * Any other keyboard controller must change this section
180 */
wdenkc6097192002-11-03 00:24:07 +0000181
wdenke55402c2004-03-14 16:51:43 +0000182#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000183#include <i8042.h>
184
wdenke55402c2004-03-14 16:51:43 +0000185#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
186#define VIDEO_TSTC_FCT i8042_tstc
187#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000188#endif
189
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000190/*
191 * Console device
192 */
wdenkc6097192002-11-03 00:24:07 +0000193
194#include <version.h>
195#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200196#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000197#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000198
Jon Loeliger30c2f242007-07-10 11:13:21 -0500199#if defined(CONFIG_CMD_DATE)
200#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000201#endif
202
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500203#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000204#include <watchdog.h>
205#include <bmp_layout.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200206
207#ifdef CONFIG_SPLASH_SCREEN_ALIGN
208#define BMP_ALIGN_CENTER 0x7FFF
209#endif
210
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500211#endif
wdenke55402c2004-03-14 16:51:43 +0000212
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000213/*
214 * Cursor definition:
215 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
216 * to let the cursor blink. Uses the macros
217 * CURSOR_OFF and CURSOR_ON.
218 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
219 * blinking is provided. Uses the macros CURSOR_SET
220 * and CURSOR_OFF.
221 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
222 * graphic chip. Uses the macro CURSOR_SET.
223 * ATTENTION: If booting an OS, the display driver
224 * must disable the hardware register of the graphic
225 * chip. Otherwise a blinking field is displayed
226 */
wdenkc6097192002-11-03 00:24:07 +0000227#if !defined(CONFIG_CONSOLE_CURSOR) && \
228 !defined(CONFIG_VIDEO_SW_CURSOR) && \
229 !defined(CONFIG_VIDEO_HW_CURSOR)
230/* no Cursor defined */
231#define CURSOR_ON
232#define CURSOR_OFF
233#define CURSOR_SET
234#endif
235
wdenke55402c2004-03-14 16:51:43 +0000236#ifdef CONFIG_CONSOLE_CURSOR
237#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000238#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
239 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000240#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000241void console_cursor(int state);
242
Timur Tabibe0c74e2010-08-27 15:45:47 -0500243#define CURSOR_ON console_cursor(1)
244#define CURSOR_OFF console_cursor(0)
wdenkc6097192002-11-03 00:24:07 +0000245#define CURSOR_SET
246#ifndef CONFIG_I8042_KBD
Marcel Ziswileraea68562007-12-30 03:30:46 +0100247#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000248#endif
249#else
wdenke55402c2004-03-14 16:51:43 +0000250#ifdef CONFIG_CONSOLE_TIME
251#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
wdenkc6097192002-11-03 00:24:07 +0000252#endif
253#endif /* CONFIG_CONSOLE_CURSOR */
254
wdenke55402c2004-03-14 16:51:43 +0000255#ifdef CONFIG_VIDEO_SW_CURSOR
256#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000257#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
258 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000259#endif
260#define CURSOR_ON
261#define CURSOR_OFF video_putchar(console_col * VIDEO_FONT_WIDTH,\
Timur Tabibe0c74e2010-08-27 15:45:47 -0500262 console_row * VIDEO_FONT_HEIGHT, ' ')
263#define CURSOR_SET video_set_cursor()
wdenkc6097192002-11-03 00:24:07 +0000264#endif /* CONFIG_VIDEO_SW_CURSOR */
265
266
267#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +0000268#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000269#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
270 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000271#endif
272#define CURSOR_ON
273#define CURSOR_OFF
274#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabibe0c74e2010-08-27 15:45:47 -0500275 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000276#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000277
wdenke55402c2004-03-14 16:51:43 +0000278#ifdef CONFIG_VIDEO_LOGO
279#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000280#include <bmp_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000281#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
282#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
283#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
284#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000285
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000286#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000287#define LINUX_LOGO_WIDTH 80
288#define LINUX_LOGO_HEIGHT 80
289#define LINUX_LOGO_COLORS 214
290#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000291#define __initdata
292#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000293#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
294#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
295#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
296#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000297#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000298#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
299#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000300#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000301#define VIDEO_LOGO_WIDTH 0
302#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000303#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000304
wdenke55402c2004-03-14 16:51:43 +0000305#define VIDEO_COLS VIDEO_VISIBLE_COLS
306#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
307#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
308#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
309#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
310#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000311
wdenke55402c2004-03-14 16:51:43 +0000312#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100313#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000314#else
wdenke55402c2004-03-14 16:51:43 +0000315#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000316#endif
317
wdenke55402c2004-03-14 16:51:43 +0000318#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
319#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
320#define CONSOLE_ROW_FIRST (video_console_address)
321#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
322#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
323#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
324#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000325
326/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000327#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000328#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
329 ((x) >> 8) \
330 )
331#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
332 (((x) & 0x0000ff00) << 8) | \
333 (((x) & 0x00ff0000) >> 8) | \
334 (((x) & 0xff000000) >> 24) \
335 )
336#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
337 (((x) & 0x0000ff00) >> 8) | \
338 (((x) & 0x00ff0000) << 8) | \
339 (((x) & 0xff000000) >> 8) \
340 )
wdenkc6097192002-11-03 00:24:07 +0000341#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000342#define SWAP16(x) (x)
343#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200344#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000345#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500346#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000347#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100348#endif
wdenkc6097192002-11-03 00:24:07 +0000349#endif
350
wdenkc6097192002-11-03 00:24:07 +0000351#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000352/*
353 * setup a board string: type, speed, etc.
354 *
355 * line_number: location to place info string beside logo
356 * info: buffer for info string
357 */
358extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000359#endif
360
361/* Locals */
362static GraphicDevice *pGD; /* Pointer to Graphic array */
363
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000364static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000365static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000366
Matthias Weisser76d70862010-01-12 12:06:31 +0100367static int video_logo_height = VIDEO_LOGO_HEIGHT;
368
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000369static int console_col; /* cursor col */
370static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000371
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000372static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000373
374static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000375 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
376 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
377 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
378 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
379};
wdenkc6097192002-11-03 00:24:07 +0000380
381static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000382 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
383};
wdenkc6097192002-11-03 00:24:07 +0000384
385static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000386 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
387};
wdenkc6097192002-11-03 00:24:07 +0000388
389static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000390 {0x00000000, 0x00000000, 0x00000000},
391 {0x00000000, 0x00000000, 0x00ffffff},
392 {0x00000000, 0x0000ffff, 0xff000000},
393 {0x00000000, 0x0000ffff, 0xffffffff},
394 {0x000000ff, 0xffff0000, 0x00000000},
395 {0x000000ff, 0xffff0000, 0x00ffffff},
396 {0x000000ff, 0xffffffff, 0xff000000},
397 {0x000000ff, 0xffffffff, 0xffffffff},
398 {0xffffff00, 0x00000000, 0x00000000},
399 {0xffffff00, 0x00000000, 0x00ffffff},
400 {0xffffff00, 0x0000ffff, 0xff000000},
401 {0xffffff00, 0x0000ffff, 0xffffffff},
402 {0xffffffff, 0xffff0000, 0x00000000},
403 {0xffffffff, 0xffff0000, 0x00ffffff},
404 {0xffffffff, 0xffffffff, 0xff000000},
405 {0xffffffff, 0xffffffff, 0xffffffff}
406};
wdenkc6097192002-11-03 00:24:07 +0000407
408static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000409 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
410 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
411 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
412 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
413 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
414 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
415 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
416 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
417 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
418 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
419 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
420 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
421 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
422 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
423 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
424 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
425};
wdenkc6097192002-11-03 00:24:07 +0000426
wdenkc6097192002-11-03 00:24:07 +0000427
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000428static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000429{
wdenke55402c2004-03-14 16:51:43 +0000430 u8 *cdat, *dest, *dest0;
431 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000432
wdenke55402c2004-03-14 16:51:43 +0000433 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
434 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000435
wdenke55402c2004-03-14 16:51:43 +0000436 switch (VIDEO_DATA_FORMAT) {
437 case GDF__8BIT_INDEX:
438 case GDF__8BIT_332RGB:
439 while (count--) {
440 c = *s;
441 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
442 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000443 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000444 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000445
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000446 ((u32 *) dest)[0] =
447 (video_font_draw_table8[bits >> 4] &
448 eorx) ^ bgx;
449 ((u32 *) dest)[1] =
450 (video_font_draw_table8[bits & 15] &
451 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000452 }
453 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
454 s++;
455 }
456 break;
wdenkc6097192002-11-03 00:24:07 +0000457
wdenke55402c2004-03-14 16:51:43 +0000458 case GDF_15BIT_555RGB:
459 while (count--) {
460 c = *s;
461 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
462 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000463 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000464 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000465
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000466 ((u32 *) dest)[0] =
467 SHORTSWAP32((video_font_draw_table15
468 [bits >> 6] & eorx) ^
469 bgx);
470 ((u32 *) dest)[1] =
471 SHORTSWAP32((video_font_draw_table15
472 [bits >> 4 & 3] & eorx) ^
473 bgx);
474 ((u32 *) dest)[2] =
475 SHORTSWAP32((video_font_draw_table15
476 [bits >> 2 & 3] & eorx) ^
477 bgx);
478 ((u32 *) dest)[3] =
479 SHORTSWAP32((video_font_draw_table15
480 [bits & 3] & eorx) ^
481 bgx);
wdenke55402c2004-03-14 16:51:43 +0000482 }
483 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
484 s++;
485 }
486 break;
wdenkc6097192002-11-03 00:24:07 +0000487
wdenke55402c2004-03-14 16:51:43 +0000488 case GDF_16BIT_565RGB:
489 while (count--) {
490 c = *s;
491 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
492 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000493 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000494 u8 bits = *cdat++;
495
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000496 ((u32 *) dest)[0] =
497 SHORTSWAP32((video_font_draw_table16
498 [bits >> 6] & eorx) ^
499 bgx);
500 ((u32 *) dest)[1] =
501 SHORTSWAP32((video_font_draw_table16
502 [bits >> 4 & 3] & eorx) ^
503 bgx);
504 ((u32 *) dest)[2] =
505 SHORTSWAP32((video_font_draw_table16
506 [bits >> 2 & 3] & eorx) ^
507 bgx);
508 ((u32 *) dest)[3] =
509 SHORTSWAP32((video_font_draw_table16
510 [bits & 3] & eorx) ^
511 bgx);
wdenke55402c2004-03-14 16:51:43 +0000512 }
513 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
514 s++;
515 }
516 break;
517
518 case GDF_32BIT_X888RGB:
519 while (count--) {
520 c = *s;
521 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
522 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000523 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000524 u8 bits = *cdat++;
525
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000526 ((u32 *) dest)[0] =
527 SWAP32((video_font_draw_table32
528 [bits >> 4][0] & eorx) ^ bgx);
529 ((u32 *) dest)[1] =
530 SWAP32((video_font_draw_table32
531 [bits >> 4][1] & eorx) ^ bgx);
532 ((u32 *) dest)[2] =
533 SWAP32((video_font_draw_table32
534 [bits >> 4][2] & eorx) ^ bgx);
535 ((u32 *) dest)[3] =
536 SWAP32((video_font_draw_table32
537 [bits >> 4][3] & eorx) ^ bgx);
538 ((u32 *) dest)[4] =
539 SWAP32((video_font_draw_table32
540 [bits & 15][0] & eorx) ^ bgx);
541 ((u32 *) dest)[5] =
542 SWAP32((video_font_draw_table32
543 [bits & 15][1] & eorx) ^ bgx);
544 ((u32 *) dest)[6] =
545 SWAP32((video_font_draw_table32
546 [bits & 15][2] & eorx) ^ bgx);
547 ((u32 *) dest)[7] =
548 SWAP32((video_font_draw_table32
549 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000550 }
551 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
552 s++;
553 }
554 break;
555
556 case GDF_24BIT_888RGB:
557 while (count--) {
558 c = *s;
559 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
560 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000561 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000562 u8 bits = *cdat++;
563
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000564 ((u32 *) dest)[0] =
565 (video_font_draw_table24[bits >> 4][0]
566 & eorx) ^ bgx;
567 ((u32 *) dest)[1] =
568 (video_font_draw_table24[bits >> 4][1]
569 & eorx) ^ bgx;
570 ((u32 *) dest)[2] =
571 (video_font_draw_table24[bits >> 4][2]
572 & eorx) ^ bgx;
573 ((u32 *) dest)[3] =
574 (video_font_draw_table24[bits & 15][0]
575 & eorx) ^ bgx;
576 ((u32 *) dest)[4] =
577 (video_font_draw_table24[bits & 15][1]
578 & eorx) ^ bgx;
579 ((u32 *) dest)[5] =
580 (video_font_draw_table24[bits & 15][2]
581 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000582 }
583 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
584 s++;
585 }
586 break;
wdenk57b2d802003-06-27 21:31:46 +0000587 }
wdenkc6097192002-11-03 00:24:07 +0000588}
589
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000590static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000591{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000592 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000593}
594
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000595static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000596{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000597 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000598}
599
wdenkc6097192002-11-03 00:24:07 +0000600#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000601static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000602{
wdenke55402c2004-03-14 16:51:43 +0000603 /* swap drawing colors */
604 eorx = fgx;
605 fgx = bgx;
606 bgx = eorx;
607 eorx = fgx ^ bgx;
608 /* draw cursor */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000609 video_putchar(console_col * VIDEO_FONT_WIDTH,
610 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenke55402c2004-03-14 16:51:43 +0000611 /* restore drawing colors */
612 eorx = fgx;
613 fgx = bgx;
614 bgx = eorx;
615 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +0000616}
617#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000618
wdenkc6097192002-11-03 00:24:07 +0000619#ifdef CONFIG_CONSOLE_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000620void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000621{
wdenke55402c2004-03-14 16:51:43 +0000622 static int last_state = 0;
623
wdenkc6097192002-11-03 00:24:07 +0000624#ifdef CONFIG_CONSOLE_TIME
wdenke55402c2004-03-14 16:51:43 +0000625 struct rtc_time tm;
626 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000627
wdenke55402c2004-03-14 16:51:43 +0000628 /* time update only if cursor is on (faster scroll) */
629 if (state) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000630 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000631
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000632 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
633 tm.tm_sec);
634 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
635 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000636
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000637 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
638 tm.tm_year);
639 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
640 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
641 (uchar *) info);
wdenke55402c2004-03-14 16:51:43 +0000642 }
wdenkc6097192002-11-03 00:24:07 +0000643#endif
644
wdenke55402c2004-03-14 16:51:43 +0000645 if (state && (last_state != state)) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000646 video_set_cursor();
wdenke55402c2004-03-14 16:51:43 +0000647 }
wdenkc6097192002-11-03 00:24:07 +0000648
wdenke55402c2004-03-14 16:51:43 +0000649 if (!state && (last_state != state)) {
650 /* clear cursor */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000651 video_putchar(console_col * VIDEO_FONT_WIDTH,
652 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenke55402c2004-03-14 16:51:43 +0000653 }
wdenkc6097192002-11-03 00:24:07 +0000654
wdenke55402c2004-03-14 16:51:43 +0000655 last_state = state;
wdenkc6097192002-11-03 00:24:07 +0000656}
657#endif
658
wdenkc6097192002-11-03 00:24:07 +0000659#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000660static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000661{
wdenke55402c2004-03-14 16:51:43 +0000662 while (c--)
663 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000664}
665#endif
666
wdenkc6097192002-11-03 00:24:07 +0000667#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000668static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000669{
wdenke55402c2004-03-14 16:51:43 +0000670 while (c--)
671 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000672}
673#endif
674
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000675static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000676{
wdenke55402c2004-03-14 16:51:43 +0000677 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000678
679#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000680 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
681 0, /* source pos x */
682 video_logo_height +
683 VIDEO_FONT_HEIGHT, /* source pos y */
684 0, /* dest pos x */
685 video_logo_height, /* dest pos y */
686 VIDEO_VISIBLE_COLS, /* frame width */
687 VIDEO_VISIBLE_ROWS
688 - video_logo_height
689 - VIDEO_FONT_HEIGHT /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000690 );
wdenkc6097192002-11-03 00:24:07 +0000691#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000692 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
693 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000694#endif
695
wdenke55402c2004-03-14 16:51:43 +0000696 /* clear the last one */
wdenkc6097192002-11-03 00:24:07 +0000697#ifdef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000698 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
699 0, /* dest pos x */
700 VIDEO_VISIBLE_ROWS
701 - VIDEO_FONT_HEIGHT, /* dest pos y */
702 VIDEO_VISIBLE_COLS, /* frame width */
703 VIDEO_FONT_HEIGHT, /* frame height */
704 CONSOLE_BG_COL /* fill color */
wdenke55402c2004-03-14 16:51:43 +0000705 );
wdenkc6097192002-11-03 00:24:07 +0000706#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000707 memsetl(CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, CONSOLE_BG_COL);
wdenkc6097192002-11-03 00:24:07 +0000708#endif
709}
710
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000711static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000712{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500713 CURSOR_OFF;
714 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000715
wdenke55402c2004-03-14 16:51:43 +0000716 if (console_col < 0) {
717 console_col = CONSOLE_COLS - 1;
718 console_row--;
719 if (console_row < 0)
720 console_row = 0;
721 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000722 video_putchar(console_col * VIDEO_FONT_WIDTH,
723 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenkc6097192002-11-03 00:24:07 +0000724}
725
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000726static void console_newline(void)
wdenkc6097192002-11-03 00:24:07 +0000727{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100728 /* Check if last character in the line was just drawn. If so, cursor was
729 overwriten and need not to be cleared. Cursor clearing without this
730 check causes overwriting the 1st character of the line if line lenght
731 is >= CONSOLE_COLS
732 */
733 if (console_col < CONSOLE_COLS)
Timur Tabibe0c74e2010-08-27 15:45:47 -0500734 CURSOR_OFF;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100735 console_row++;
wdenke55402c2004-03-14 16:51:43 +0000736 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000737
wdenke55402c2004-03-14 16:51:43 +0000738 /* Check if we need to scroll the terminal */
739 if (console_row >= CONSOLE_ROWS) {
740 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000741 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000742
wdenke55402c2004-03-14 16:51:43 +0000743 /* Decrement row number */
744 console_row--;
745 }
wdenkc6097192002-11-03 00:24:07 +0000746}
747
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000748static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100749{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500750 CURSOR_OFF;
751 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100752}
753
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000754void video_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000755{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100756 static int nl = 1;
757
wdenke55402c2004-03-14 16:51:43 +0000758 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100759 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000760 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000761 break;
wdenkc6097192002-11-03 00:24:07 +0000762
wdenke55402c2004-03-14 16:51:43 +0000763 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100764 if (console_col || (!console_col && nl))
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000765 console_newline();
Anatolij Gustschin938db912008-01-11 02:39:47 +0100766 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000767 break;
wdenkc6097192002-11-03 00:24:07 +0000768
wdenke55402c2004-03-14 16:51:43 +0000769 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500770 CURSOR_OFF;
771 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000772 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000773
wdenke55402c2004-03-14 16:51:43 +0000774 if (console_col >= CONSOLE_COLS)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000775 console_newline();
wdenke55402c2004-03-14 16:51:43 +0000776 break;
wdenkc6097192002-11-03 00:24:07 +0000777
wdenke55402c2004-03-14 16:51:43 +0000778 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000779 console_back();
wdenke55402c2004-03-14 16:51:43 +0000780 break;
wdenkc6097192002-11-03 00:24:07 +0000781
wdenke55402c2004-03-14 16:51:43 +0000782 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000783 video_putchar(console_col * VIDEO_FONT_WIDTH,
784 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000785 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000786
wdenke55402c2004-03-14 16:51:43 +0000787 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100788 if (console_col >= CONSOLE_COLS) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000789 console_newline();
Anatolij Gustschin938db912008-01-11 02:39:47 +0100790 nl = 0;
791 }
wdenke55402c2004-03-14 16:51:43 +0000792 }
Timur Tabibe0c74e2010-08-27 15:45:47 -0500793 CURSOR_SET;
794}
wdenkc6097192002-11-03 00:24:07 +0000795
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000796void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +0000797{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000798 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +0000799
800 while (count--)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000801 video_putc(*s++);
wdenke55402c2004-03-14 16:51:43 +0000802}
803
Anatolij Gustschina043c342010-05-01 22:21:09 +0200804/*
805 * Do not enforce drivers (or board code) to provide empty
806 * video_set_lut() if they do not support 8 bpp format.
807 * Implement weak default function instead.
808 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000809void __video_set_lut(unsigned int index, unsigned char r,
810 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +0200811{
812}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000813
814void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
815 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschina043c342010-05-01 22:21:09 +0200816
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500817#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000818
819#define FILL_8BIT_332RGB(r,g,b) { \
820 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
821 fb ++; \
822}
823
824#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000825 *(unsigned short *)fb = \
826 SWAP16((unsigned short)(((r>>3)<<10) | \
827 ((g>>3)<<5) | \
828 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +0000829 fb += 2; \
830}
831
832#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000833 *(unsigned short *)fb = \
834 SWAP16((unsigned short)((((r)>>3)<<11)| \
835 (((g)>>2)<<5) | \
836 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +0000837 fb += 2; \
838}
839
840#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000841 *(unsigned long *)fb = \
842 SWAP32((unsigned long)(((r<<16) | \
843 (g<<8) | \
844 b))); \
wdenke55402c2004-03-14 16:51:43 +0000845 fb += 4; \
846}
847
848#ifdef VIDEO_FB_LITTLE_ENDIAN
849#define FILL_24BIT_888RGB(r,g,b) { \
850 fb[0] = b; \
851 fb[1] = g; \
852 fb[2] = r; \
853 fb += 3; \
854}
855#else
856#define FILL_24BIT_888RGB(r,g,b) { \
857 fb[0] = r; \
858 fb[1] = g; \
859 fb[2] = b; \
860 fb += 3; \
861}
862#endif
863
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200864#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000865static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200866{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000867 ushort *dst = (ushort *) fb;
868 ushort color = (ushort) (((r >> 3) << 10) |
869 ((g >> 3) << 5) |
870 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200871 if (x & 1)
872 *(--dst) = color;
873 else
874 *(++dst) = color;
875}
876#endif
wdenke55402c2004-03-14 16:51:43 +0000877
878/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100879 * RLE8 bitmap support
880 */
881
882#ifdef CONFIG_VIDEO_BMP_RLE8
883/* Pre-calculated color table entry */
884struct palette {
885 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000886 unsigned short w; /* word */
887 unsigned int dw; /* double word */
888 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100889};
890
891/*
892 * Helper to draw encoded/unencoded run.
893 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000894static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
895 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100896{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000897 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100898 int *off;
899 int enc_off = 1;
900 int i;
901
902 /*
903 * Setup offset of the color index in the bitmap.
904 * Color index of encoded run is at offset 1.
905 */
906 off = enc ? &enc_off : &i;
907
908 switch (VIDEO_DATA_FORMAT) {
909 case GDF__8BIT_INDEX:
910 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000911 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100912 break;
913 case GDF_15BIT_555RGB:
914 case GDF_16BIT_565RGB:
915 /* differences handled while pre-calculating palette */
916 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000917 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100918 addr += 2;
919 }
920 break;
921 case GDF_32BIT_X888RGB:
922 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000923 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100924 addr += 4;
925 }
926 break;
927 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000928 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100929}
930
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000931static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
932 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100933{
934 unsigned char *bm;
935 unsigned char *fbp;
936 unsigned int cnt, runlen;
937 int decode = 1;
938 int x, y, bpp, i, ncolors;
939 struct palette p[256];
940 bmp_color_table_entry_t cte;
941 int green_shift, red_off;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +0100942 int limit = VIDEO_COLS * VIDEO_ROWS;
943 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100944
945 x = 0;
946 y = __le32_to_cpu(img->header.height) - 1;
947 ncolors = __le32_to_cpu(img->header.colors_used);
948 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000949 fbp = (unsigned char *) ((unsigned int) video_fb_address +
950 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100951
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000952 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100953
954 /* pre-calculate and setup palette */
955 switch (VIDEO_DATA_FORMAT) {
956 case GDF__8BIT_INDEX:
957 for (i = 0; i < ncolors; i++) {
958 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000959 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100960 }
961 break;
962 case GDF_15BIT_555RGB:
963 case GDF_16BIT_565RGB:
964 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
965 green_shift = 3;
966 red_off = 10;
967 } else {
968 green_shift = 2;
969 red_off = 11;
970 }
971 for (i = 0; i < ncolors; i++) {
972 cte = img->color_table[i];
973 p[i].ce.w = SWAP16((unsigned short)
974 (((cte.red >> 3) << red_off) |
975 ((cte.green >> green_shift) << 5) |
976 cte.blue >> 3));
977 }
978 break;
979 case GDF_32BIT_X888RGB:
980 for (i = 0; i < ncolors; i++) {
981 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000982 p[i].ce.dw = SWAP32((cte.red << 16) |
983 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100984 cte.blue);
985 }
986 break;
987 default:
988 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000989 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100990 return -1;
991 }
992
993 while (decode) {
994 switch (bm[0]) {
995 case 0:
996 switch (bm[1]) {
997 case 0:
998 /* scan line end marker */
999 bm += 2;
1000 x = 0;
1001 y--;
1002 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001003 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001004 (((y + yoff) * VIDEO_COLS) +
1005 xoff) * bpp);
1006 continue;
1007 case 1:
1008 /* end of bitmap data marker */
1009 decode = 0;
1010 break;
1011 case 2:
1012 /* run offset marker */
1013 x += bm[2];
1014 y -= bm[3];
1015 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001016 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001017 (((y + yoff) * VIDEO_COLS) +
1018 x + xoff) * bpp);
1019 bm += 4;
1020 break;
1021 default:
1022 /* unencoded run */
1023 cnt = bm[1];
1024 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001025 pixels += cnt;
1026 if (pixels > limit)
1027 goto error;
1028
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001029 bm += 2;
1030 if (y < height) {
1031 if (x >= width) {
1032 x += runlen;
1033 goto next_run;
1034 }
1035 if (x + runlen > width)
1036 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001037 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001038 x += runlen;
1039 }
1040next_run:
1041 bm += runlen;
1042 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001043 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001044 }
1045 break;
1046 default:
1047 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001048 cnt = bm[0];
1049 runlen = cnt;
1050 pixels += cnt;
1051 if (pixels > limit)
1052 goto error;
1053
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001054 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001055 if (x >= width) {
1056 x += runlen;
1057 bm += 2;
1058 continue;
1059 }
1060 if (x + runlen > width)
1061 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001062 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001063 x += runlen;
1064 }
1065 bm += 2;
1066 break;
1067 }
1068 }
1069 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001070error:
1071 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1072 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001073}
1074#endif
1075
1076/*
wdenke55402c2004-03-14 16:51:43 +00001077 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001078 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001079int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001080{
1081 ushort xcount, ycount;
1082 uchar *fb;
1083 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1084 uchar *bmap;
1085 ushort padded_line;
1086 unsigned long width, height, bpp;
1087 unsigned colors;
1088 unsigned long compression;
1089 bmp_color_table_entry_t cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001090
Stefan Roesed9d97742005-09-22 09:04:17 +02001091#ifdef CONFIG_VIDEO_BMP_GZIP
1092 unsigned char *dst = NULL;
1093 ulong len;
1094#endif
wdenkc6097192002-11-03 00:24:07 +00001095
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001096 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001097
1098 if (!((bmp->header.signature[0] == 'B') &&
1099 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001100
1101#ifdef CONFIG_VIDEO_BMP_GZIP
1102 /*
1103 * Could be a gzipped bmp image, try to decrompress...
1104 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001105 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1106 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001107 if (dst == NULL) {
1108 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001109 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001110 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001111 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1112 (uchar *) bmp_image,
1113 &len) != 0) {
1114 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1115 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001116 free(dst);
1117 return 1;
1118 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001119 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001120 printf("Image could be truncated "
1121 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001122 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001123
1124 /*
1125 * Set addr to decompressed image
1126 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001127 bmp = (bmp_image_t *) dst;
Stefan Roesed9d97742005-09-22 09:04:17 +02001128
1129 if (!((bmp->header.signature[0] == 'B') &&
1130 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001131 printf("Error: no valid bmp.gz image at %lx\n",
1132 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001133 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001134 return 1;
1135 }
1136#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001137 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001138 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001139#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001140 }
1141
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001142 width = le32_to_cpu(bmp->header.width);
1143 height = le32_to_cpu(bmp->header.height);
1144 bpp = le16_to_cpu(bmp->header.bit_count);
1145 colors = le32_to_cpu(bmp->header.colors_used);
1146 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001147
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001148 debug("Display-bmp: %d x %d with %d colors\n",
1149 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001150
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001151 if (compression != BMP_BI_RGB
1152#ifdef CONFIG_VIDEO_BMP_RLE8
1153 && compression != BMP_BI_RLE8
1154#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001155 ) {
1156 printf("Error: compression type %ld not supported\n",
1157 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001158#ifdef CONFIG_VIDEO_BMP_GZIP
1159 if (dst)
1160 free(dst);
1161#endif
wdenke55402c2004-03-14 16:51:43 +00001162 return 1;
1163 }
1164
1165 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1166
Matthias Weisser53884182009-07-09 16:07:30 +02001167#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1168 if (x == BMP_ALIGN_CENTER)
1169 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1170 else if (x < 0)
1171 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1172
1173 if (y == BMP_ALIGN_CENTER)
1174 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1175 else if (y < 0)
1176 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1177#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1178
wdenke55402c2004-03-14 16:51:43 +00001179 if ((x + width) > VIDEO_VISIBLE_COLS)
1180 width = VIDEO_VISIBLE_COLS - x;
1181 if ((y + height) > VIDEO_VISIBLE_ROWS)
1182 height = VIDEO_VISIBLE_ROWS - y;
1183
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001184 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001185 fb = (uchar *) (video_fb_address +
1186 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1187 x * VIDEO_PIXEL_SIZE);
1188
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001189#ifdef CONFIG_VIDEO_BMP_RLE8
1190 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001191 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001192 }
1193#endif
1194
Timur Tabi0fce9922010-08-23 16:58:00 -05001195 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001196 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001197 case 4:
1198 padded_line -= width / 2;
1199 ycount = height;
1200
1201 switch (VIDEO_DATA_FORMAT) {
1202 case GDF_32BIT_X888RGB:
1203 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001204 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001205 /*
1206 * Don't assume that 'width' is an
1207 * even number
1208 */
1209 for (xcount = 0; xcount < width; xcount++) {
1210 uchar idx;
1211
1212 if (xcount & 1) {
1213 idx = *bmap & 0xF;
1214 bmap++;
1215 } else
1216 idx = *bmap >> 4;
1217 cte = bmp->color_table[idx];
1218 FILL_32BIT_X888RGB(cte.red, cte.green,
1219 cte.blue);
1220 }
1221 bmap += padded_line;
1222 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001223 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001224 }
1225 break;
1226 default:
1227 puts("4bpp bitmap unsupported with current "
1228 "video mode\n");
1229 break;
1230 }
1231 break;
1232
wdenke55402c2004-03-14 16:51:43 +00001233 case 8:
1234 padded_line -= width;
1235 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001236 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001237 for (xcount = 0; xcount < colors; ++xcount) {
1238 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001239 video_set_lut(xcount, cte.red, cte.green,
1240 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001241 }
1242 }
1243 ycount = height;
1244 switch (VIDEO_DATA_FORMAT) {
1245 case GDF__8BIT_INDEX:
1246 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001247 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001248 xcount = width;
1249 while (xcount--) {
1250 *fb++ = *bmap++;
1251 }
1252 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001253 fb -= (VIDEO_VISIBLE_COLS + width) *
1254 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001255 }
1256 break;
1257 case GDF__8BIT_332RGB:
1258 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001259 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001260 xcount = width;
1261 while (xcount--) {
1262 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001263 FILL_8BIT_332RGB(cte.red, cte.green,
1264 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001265 }
1266 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001267 fb -= (VIDEO_VISIBLE_COLS + width) *
1268 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001269 }
1270 break;
1271 case GDF_15BIT_555RGB:
1272 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001273#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1274 int xpos = x;
1275#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001276 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001277 xcount = width;
1278 while (xcount--) {
1279 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001280#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001281 fill_555rgb_pswap(fb, xpos++, cte.red,
1282 cte.green,
1283 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001284 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001285#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001286 FILL_15BIT_555RGB(cte.red, cte.green,
1287 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001288#endif
wdenke55402c2004-03-14 16:51:43 +00001289 }
1290 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001291 fb -= (VIDEO_VISIBLE_COLS + width) *
1292 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001293 }
1294 break;
1295 case GDF_16BIT_565RGB:
1296 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001297 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001298 xcount = width;
1299 while (xcount--) {
1300 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001301 FILL_16BIT_565RGB(cte.red, cte.green,
1302 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001303 }
1304 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001305 fb -= (VIDEO_VISIBLE_COLS + width) *
1306 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001307 }
1308 break;
1309 case GDF_32BIT_X888RGB:
1310 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001311 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001312 xcount = width;
1313 while (xcount--) {
1314 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001315 FILL_32BIT_X888RGB(cte.red, cte.green,
1316 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001317 }
1318 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001319 fb -= (VIDEO_VISIBLE_COLS + width) *
1320 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001321 }
1322 break;
1323 case GDF_24BIT_888RGB:
1324 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001325 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001326 xcount = width;
1327 while (xcount--) {
1328 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001329 FILL_24BIT_888RGB(cte.red, cte.green,
1330 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001331 }
1332 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001333 fb -= (VIDEO_VISIBLE_COLS + width) *
1334 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001335 }
1336 break;
1337 }
1338 break;
1339 case 24:
1340 padded_line -= 3 * width;
1341 ycount = height;
1342 switch (VIDEO_DATA_FORMAT) {
1343 case GDF__8BIT_332RGB:
1344 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001345 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001346 xcount = width;
1347 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001348 FILL_8BIT_332RGB(bmap[2], bmap[1],
1349 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001350 bmap += 3;
1351 }
1352 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001353 fb -= (VIDEO_VISIBLE_COLS + width) *
1354 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001355 }
1356 break;
1357 case GDF_15BIT_555RGB:
1358 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001359#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1360 int xpos = x;
1361#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001362 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001363 xcount = width;
1364 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001365#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001366 fill_555rgb_pswap(fb, xpos++, bmap[2],
1367 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001368 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001369#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001370 FILL_15BIT_555RGB(bmap[2], bmap[1],
1371 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001372#endif
wdenke55402c2004-03-14 16:51:43 +00001373 bmap += 3;
1374 }
1375 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001376 fb -= (VIDEO_VISIBLE_COLS + width) *
1377 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001378 }
1379 break;
1380 case GDF_16BIT_565RGB:
1381 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001382 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001383 xcount = width;
1384 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001385 FILL_16BIT_565RGB(bmap[2], bmap[1],
1386 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001387 bmap += 3;
1388 }
1389 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001390 fb -= (VIDEO_VISIBLE_COLS + width) *
1391 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001392 }
1393 break;
1394 case GDF_32BIT_X888RGB:
1395 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001396 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001397 xcount = width;
1398 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001399 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1400 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001401 bmap += 3;
1402 }
1403 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001404 fb -= (VIDEO_VISIBLE_COLS + width) *
1405 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001406 }
1407 break;
1408 case GDF_24BIT_888RGB:
1409 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001410 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001411 xcount = width;
1412 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001413 FILL_24BIT_888RGB(bmap[2], bmap[1],
1414 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001415 bmap += 3;
1416 }
1417 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001418 fb -= (VIDEO_VISIBLE_COLS + width) *
1419 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001420 }
1421 break;
1422 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001423 printf("Error: 24 bits/pixel bitmap incompatible "
1424 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001425 break;
1426 }
1427 break;
1428 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001429 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1430 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001431 break;
1432 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001433
1434#ifdef CONFIG_VIDEO_BMP_GZIP
1435 if (dst) {
1436 free(dst);
1437 }
1438#endif
1439
wdenke55402c2004-03-14 16:51:43 +00001440 return (0);
wdenkc6097192002-11-03 00:24:07 +00001441}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001442#endif
wdenkc6097192002-11-03 00:24:07 +00001443
wdenkc6097192002-11-03 00:24:07 +00001444
1445#ifdef CONFIG_VIDEO_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001446void logo_plot(void *screen, int width, int x, int y)
wdenkc6097192002-11-03 00:24:07 +00001447{
wdenk9dd2b882002-12-03 21:28:10 +00001448
wdenke55402c2004-03-14 16:51:43 +00001449 int xcount, i;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001450 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001451 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001452 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1453 unsigned char *source;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001454 unsigned char *dest = (unsigned char *) screen +
1455 ((y * width * VIDEO_PIXEL_SIZE) + x * VIDEO_PIXEL_SIZE);
wdenkc6097192002-11-03 00:24:07 +00001456
wdenk9dd2b882002-12-03 21:28:10 +00001457#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001458 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001459
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001460 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001461 logo_red = malloc(BMP_LOGO_COLORS);
1462 logo_green = malloc(BMP_LOGO_COLORS);
1463 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001464 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001465 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1466 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1467 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1468 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1469 }
wdenk9dd2b882002-12-03 21:28:10 +00001470#else
wdenke55402c2004-03-14 16:51:43 +00001471 source = linux_logo;
1472 logo_red = linux_logo_red;
1473 logo_green = linux_logo_green;
1474 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001475#endif
wdenk57b2d802003-06-27 21:31:46 +00001476
wdenke55402c2004-03-14 16:51:43 +00001477 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1478 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001479 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1480 logo_red[i], logo_green[i],
1481 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001482 }
wdenk57b2d802003-06-27 21:31:46 +00001483 }
wdenkc6097192002-11-03 00:24:07 +00001484
wdenke55402c2004-03-14 16:51:43 +00001485 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001486#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1487 int xpos = x;
1488#endif
wdenke55402c2004-03-14 16:51:43 +00001489 xcount = VIDEO_LOGO_WIDTH;
1490 while (xcount--) {
1491 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1492 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1493 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
wdenk57b2d802003-06-27 21:31:46 +00001494
wdenke55402c2004-03-14 16:51:43 +00001495 switch (VIDEO_DATA_FORMAT) {
1496 case GDF__8BIT_INDEX:
1497 *dest = *source;
1498 break;
1499 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001500 *dest = ((r >> 5) << 5) |
1501 ((g >> 5) << 2) |
1502 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001503 break;
1504 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001505#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001506 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001507#else
wdenke55402c2004-03-14 16:51:43 +00001508 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001509 SWAP16((unsigned short) (
1510 ((r >> 3) << 10) |
1511 ((g >> 3) << 5) |
1512 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001513#endif
wdenke55402c2004-03-14 16:51:43 +00001514 break;
1515 case GDF_16BIT_565RGB:
1516 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001517 SWAP16((unsigned short) (
1518 ((r >> 3) << 11) |
1519 ((g >> 2) << 5) |
1520 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001521 break;
1522 case GDF_32BIT_X888RGB:
1523 *(unsigned long *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001524 SWAP32((unsigned long) (
1525 (r << 16) |
1526 (g << 8) |
1527 b));
wdenke55402c2004-03-14 16:51:43 +00001528 break;
1529 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001530#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001531 dest[0] = b;
1532 dest[1] = g;
1533 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001534#else
wdenke55402c2004-03-14 16:51:43 +00001535 dest[0] = r;
1536 dest[1] = g;
1537 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001538#endif
wdenke55402c2004-03-14 16:51:43 +00001539 break;
1540 }
1541 source++;
1542 dest += VIDEO_PIXEL_SIZE;
1543 }
1544 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001545 }
wdenk9dd2b882002-12-03 21:28:10 +00001546#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001547 free(logo_red);
1548 free(logo_green);
1549 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001550#endif
wdenkc6097192002-11-03 00:24:07 +00001551}
1552
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001553static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001554{
wdenke55402c2004-03-14 16:51:43 +00001555 char info[128];
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001556 int space, len, y_off = 0;
wdenke55402c2004-03-14 16:51:43 +00001557
1558#ifdef CONFIG_SPLASH_SCREEN
1559 char *s;
1560 ulong addr;
1561
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001562 s = getenv("splashimage");
1563 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001564 int x = 0, y = 0;
1565
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001566 addr = simple_strtoul(s, NULL, 16);
Matthias Weisser53884182009-07-09 16:07:30 +02001567#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001568 s = getenv("splashpos");
1569 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001570 if (s[0] == 'm')
1571 x = BMP_ALIGN_CENTER;
1572 else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001573 x = simple_strtol(s, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001574
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001575 s = strchr(s + 1, ',');
1576 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001577 if (s[1] == 'm')
1578 y = BMP_ALIGN_CENTER;
1579 else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001580 y = simple_strtol(s + 1, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001581 }
1582 }
1583#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
wdenke55402c2004-03-14 16:51:43 +00001584
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001585 if (video_display_bitmap(addr, x, y) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001586 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001587 return ((void *) (video_fb_address));
1588 }
1589 }
1590#endif /* CONFIG_SPLASH_SCREEN */
1591
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001592 logo_plot(video_fb_address, VIDEO_COLS, 0, 0);
wdenkc6097192002-11-03 00:24:07 +00001593
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001594 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001595
1596 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1597 len = strlen(info);
1598
1599 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001600 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1601 (uchar *) info, space);
1602 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1603 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1604 (uchar *) info + space, len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001605 y_off = 1;
1606 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001607 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001608
1609#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001610 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001611 int i, n =
1612 ((video_logo_height -
1613 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001614
wdenke55402c2004-03-14 16:51:43 +00001615 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001616 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001617 if (!*info)
1618 continue;
1619
1620 len = strlen(info);
1621 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001622 video_drawchars(VIDEO_INFO_X,
1623 VIDEO_INFO_Y +
1624 (i + y_off) *
1625 VIDEO_FONT_HEIGHT,
1626 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001627 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001628 video_drawchars(VIDEO_INFO_X +
1629 VIDEO_FONT_WIDTH,
1630 VIDEO_INFO_Y +
1631 (i + y_off) *
1632 VIDEO_FONT_HEIGHT,
1633 (uchar *) info + space,
1634 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001635 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001636 video_drawstring(VIDEO_INFO_X,
1637 VIDEO_INFO_Y +
1638 (i + y_off) *
1639 VIDEO_FONT_HEIGHT,
1640 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001641 }
wdenke55402c2004-03-14 16:51:43 +00001642 }
1643 }
wdenkc6097192002-11-03 00:24:07 +00001644#endif
1645
Matthias Weisser76d70862010-01-12 12:06:31 +01001646 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001647}
1648#endif
1649
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001650static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001651{
wdenke55402c2004-03-14 16:51:43 +00001652 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001653
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001654 pGD = video_hw_init();
1655 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00001656 return -1;
wdenkc6097192002-11-03 00:24:07 +00001657
wdenke55402c2004-03-14 16:51:43 +00001658 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001659#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001660 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001661#endif
1662
wdenke55402c2004-03-14 16:51:43 +00001663 /* Init drawing pats */
1664 switch (VIDEO_DATA_FORMAT) {
1665 case GDF__8BIT_INDEX:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001666 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
1667 CONSOLE_FG_COL);
1668 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1669 CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00001670 fgx = 0x01010101;
1671 bgx = 0x00000000;
1672 break;
1673 case GDF__8BIT_332RGB:
1674 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001675 ((CONSOLE_FG_COL >> 3) & 0x1c) |
1676 CONSOLE_FG_COL >> 6);
1677 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1678 color8;
wdenke55402c2004-03-14 16:51:43 +00001679 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001680 ((CONSOLE_BG_COL >> 3) & 0x1c) |
1681 CONSOLE_BG_COL >> 6);
1682 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1683 color8;
wdenke55402c2004-03-14 16:51:43 +00001684 break;
1685 case GDF_15BIT_555RGB:
1686 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001687 ((CONSOLE_FG_COL >> 3) << 21) |
1688 ((CONSOLE_FG_COL >> 3) << 16) |
1689 ((CONSOLE_FG_COL >> 3) << 10) |
1690 ((CONSOLE_FG_COL >> 3) << 5) |
1691 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001692 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001693 ((CONSOLE_BG_COL >> 3) << 21) |
1694 ((CONSOLE_BG_COL >> 3) << 16) |
1695 ((CONSOLE_BG_COL >> 3) << 10) |
1696 ((CONSOLE_BG_COL >> 3) << 5) |
1697 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001698 break;
1699 case GDF_16BIT_565RGB:
1700 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001701 ((CONSOLE_FG_COL >> 2) << 21) |
1702 ((CONSOLE_FG_COL >> 3) << 16) |
1703 ((CONSOLE_FG_COL >> 3) << 11) |
1704 ((CONSOLE_FG_COL >> 2) << 5) |
1705 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001706 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001707 ((CONSOLE_BG_COL >> 2) << 21) |
1708 ((CONSOLE_BG_COL >> 3) << 16) |
1709 ((CONSOLE_BG_COL >> 3) << 11) |
1710 ((CONSOLE_BG_COL >> 2) << 5) |
1711 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001712 break;
1713 case GDF_32BIT_X888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001714 fgx = (CONSOLE_FG_COL << 16) |
1715 (CONSOLE_FG_COL << 8) |
1716 CONSOLE_FG_COL;
1717 bgx = (CONSOLE_BG_COL << 16) |
1718 (CONSOLE_BG_COL << 8) |
1719 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00001720 break;
1721 case GDF_24BIT_888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001722 fgx = (CONSOLE_FG_COL << 24) |
1723 (CONSOLE_FG_COL << 16) |
1724 (CONSOLE_FG_COL << 8) |
1725 CONSOLE_FG_COL;
1726 bgx = (CONSOLE_BG_COL << 24) |
1727 (CONSOLE_BG_COL << 16) |
1728 (CONSOLE_BG_COL << 8) |
1729 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00001730 break;
1731 }
1732 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001733
1734#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00001735 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00001736 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001737 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00001738#else
wdenke55402c2004-03-14 16:51:43 +00001739 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001740#endif
1741
wdenke55402c2004-03-14 16:51:43 +00001742 /* Initialize the console */
1743 console_col = 0;
1744 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001745
wdenke55402c2004-03-14 16:51:43 +00001746 return 0;
wdenkc6097192002-11-03 00:24:07 +00001747}
1748
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001749/*
1750 * Implement a weak default function for boards that optionally
1751 * need to skip the video initialization.
1752 */
1753int __board_video_skip(void)
1754{
1755 /* As default, don't skip test */
1756 return 0;
1757}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001758
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001759int board_video_skip(void)
1760 __attribute__ ((weak, alias("__board_video_skip")));
1761
1762int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001763{
wdenke55402c2004-03-14 16:51:43 +00001764 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02001765 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00001766
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001767 /* Check if video initialization should be skipped */
1768 if (board_video_skip())
1769 return 0;
1770
wdenk7dd13292004-07-11 20:04:51 +00001771 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001772 skip_dev_init = (video_init() == -1);
wdenkc6097192002-11-03 00:24:07 +00001773
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001774#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk46717712011-07-29 09:55:28 +00001775 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001776 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1777#endif
wdenkc6097192002-11-03 00:24:07 +00001778
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001779 if (skip_dev_init)
1780 return 0;
wdenkc6097192002-11-03 00:24:07 +00001781
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001782 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001783 memset(&console_dev, 0, sizeof(console_dev));
1784 strcpy(console_dev.name, "vga");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001785 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1786 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1787 console_dev.putc = video_putc; /* 'putc' function */
1788 console_dev.puts = video_puts; /* 'puts' function */
1789 console_dev.tstc = NULL; /* 'tstc' function */
1790 console_dev.getc = NULL; /* 'getc' function */
1791
1792#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1793 /* Also init console device */
1794 console_dev.flags |= DEV_FLAGS_INPUT;
1795 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1796 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00001797#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001798
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001799 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001800 return 0;
1801
1802 /* Return success */
1803 return 1;
wdenkc6097192002-11-03 00:24:07 +00001804}