blob: 51ea1671cf6b4a2eea31404ec4d034dfb857444e [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
wdenk4b248f32004-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 Denk64e40d72011-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 Denk64e40d72011-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ßmann09c2e902011-07-18 20:24:04 +0200102#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +0000103#include <malloc.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +0000104#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +0000105
Wolfgang Denk64e40d72011-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
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000118/*
119 * Defines for the CT69000 driver
120 */
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000128/*
129 * Defines for the SED13806 driver
130 */
wdenka6c7ad22002-12-03 21:28:10 +0000131#ifdef CONFIG_VIDEO_SED13806
132
wdenk89394042004-08-04 21:56:49 +0000133#ifndef CONFIG_TOTAL5200
wdenka6c7ad22002-12-03 21:28:10 +0000134#define VIDEO_FB_LITTLE_ENDIAN
wdenk89394042004-08-04 21:56:49 +0000135#endif
wdenka6c7ad22002-12-03 21:28:10 +0000136#define VIDEO_HW_RECTFILL
137#define VIDEO_HW_BITBLT
138#endif
139
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000140/*
141 * Defines for the SED13806 driver
142 */
Stefan Roese98f4a3d2005-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 Denk64e40d72011-07-29 09:55:27 +0000150/*
151 * Defines for the MB862xx driver
152 */
Anatolij Gustschinbed53752008-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 Gustschin5d16ca82009-10-23 12:03:14 +0200158#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100159#define VIDEO_HW_RECTFILL
160#define VIDEO_HW_BITBLT
161#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200162#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100163
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000164/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000165 * Defines for the i.MX31 driver (mx3fb.c)
166 */
Marek Vasut5fb1a6f2011-11-23 16:32:16 +0000167#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_MX5)
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000168#define VIDEO_FB_16BPP_WORD_SWAP
169#endif
170
171/*
Wolfgang Denk64e40d72011-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 Denk64e40d72011-07-29 09:55:27 +0000176/*
177 * some Macros
178 */
wdenk4b248f32004-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 Denk64e40d72011-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
wdenk4b248f32004-03-14 16:51:43 +0000190#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000191#include <i8042.h>
192
wdenk4b248f32004-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 Denk64e40d72011-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-VILLARD52cb4d42009-05-16 12:14:54 +0200204#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000205#include <video_font.h>
Che-Liang Chioud3983ee2011-10-21 17:04:21 +0800206#include <video_font_data.h>
wdenkc6097192002-11-03 00:24:07 +0000207
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500208#if defined(CONFIG_CMD_DATE)
209#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000210#endif
211
Jon Loeliger07d38a12007-07-09 17:30:01 -0500212#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000213#include <watchdog.h>
214#include <bmp_layout.h>
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200215
216#ifdef CONFIG_SPLASH_SCREEN_ALIGN
217#define BMP_ALIGN_CENTER 0x7FFF
218#endif
219
Jon Loeliger07d38a12007-07-09 17:30:01 -0500220#endif
wdenk4b248f32004-03-14 16:51:43 +0000221
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000222/*
223 * Cursor definition:
224 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
225 * to let the cursor blink. Uses the macros
226 * CURSOR_OFF and CURSOR_ON.
227 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
228 * blinking is provided. Uses the macros CURSOR_SET
229 * and CURSOR_OFF.
230 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
231 * graphic chip. Uses the macro CURSOR_SET.
232 * ATTENTION: If booting an OS, the display driver
233 * must disable the hardware register of the graphic
234 * chip. Otherwise a blinking field is displayed
235 */
wdenkc6097192002-11-03 00:24:07 +0000236#if !defined(CONFIG_CONSOLE_CURSOR) && \
237 !defined(CONFIG_VIDEO_SW_CURSOR) && \
238 !defined(CONFIG_VIDEO_HW_CURSOR)
239/* no Cursor defined */
240#define CURSOR_ON
241#define CURSOR_OFF
242#define CURSOR_SET
243#endif
244
Gabe Black03d31fc2011-11-30 13:50:50 +0000245#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
246#if defined(CURSOR_ON) || \
247 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000248#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
249 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000250#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000251void console_cursor(int state);
252
Timur Tabi65618632010-08-27 15:45:47 -0500253#define CURSOR_ON console_cursor(1)
254#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000255#define CURSOR_SET video_set_cursor()
256#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
257
258#ifdef CONFIG_CONSOLE_CURSOR
259#ifndef CONFIG_CONSOLE_TIME
260#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
261#endif
wdenkc6097192002-11-03 00:24:07 +0000262#ifndef CONFIG_I8042_KBD
Marcel Ziswiler7817cb22007-12-30 03:30:46 +0100263#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000264#endif
wdenkc6097192002-11-03 00:24:07 +0000265#endif /* CONFIG_CONSOLE_CURSOR */
266
wdenkc6097192002-11-03 00:24:07 +0000267
268#ifdef CONFIG_VIDEO_HW_CURSOR
wdenk4b248f32004-03-14 16:51:43 +0000269#ifdef CURSOR_ON
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000270#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
271 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000272#endif
273#define CURSOR_ON
274#define CURSOR_OFF
275#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabi65618632010-08-27 15:45:47 -0500276 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000277#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000278
wdenk4b248f32004-03-14 16:51:43 +0000279#ifdef CONFIG_VIDEO_LOGO
280#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000281#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000282#include <bmp_logo_data.h>
wdenk4b248f32004-03-14 16:51:43 +0000283#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
284#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
285#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
286#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenka6c7ad22002-12-03 21:28:10 +0000287
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000288#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000289#define LINUX_LOGO_WIDTH 80
290#define LINUX_LOGO_HEIGHT 80
291#define LINUX_LOGO_COLORS 214
292#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000293#define __initdata
294#include <linux_logo.h>
wdenk4b248f32004-03-14 16:51:43 +0000295#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
296#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
297#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
298#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000299#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000300#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
301#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000302#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000303#define VIDEO_LOGO_WIDTH 0
304#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000305#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000306
wdenk4b248f32004-03-14 16:51:43 +0000307#define VIDEO_COLS VIDEO_VISIBLE_COLS
308#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
309#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
310#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
311#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
312#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000313
wdenk4b248f32004-03-14 16:51:43 +0000314#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100315#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000316#else
wdenk4b248f32004-03-14 16:51:43 +0000317#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000318#endif
319
wdenk4b248f32004-03-14 16:51:43 +0000320#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
321#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
322#define CONSOLE_ROW_FIRST (video_console_address)
323#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
324#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
325#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
326#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000327
328/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000329#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000330#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
331 ((x) >> 8) \
332 )
333#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
334 (((x) & 0x0000ff00) << 8) | \
335 (((x) & 0x00ff0000) >> 8) | \
336 (((x) & 0xff000000) >> 24) \
337 )
338#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
339 (((x) & 0x0000ff00) >> 8) | \
340 (((x) & 0x00ff0000) << 8) | \
341 (((x) & 0xff000000) >> 8) \
342 )
wdenkc6097192002-11-03 00:24:07 +0000343#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000344#define SWAP16(x) (x)
345#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200346#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000347#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500348#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000349#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100350#endif
wdenkc6097192002-11-03 00:24:07 +0000351#endif
352
wdenkc6097192002-11-03 00:24:07 +0000353#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000354/*
355 * setup a board string: type, speed, etc.
356 *
357 * line_number: location to place info string beside logo
358 * info: buffer for info string
359 */
360extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000361#endif
362
363/* Locals */
364static GraphicDevice *pGD; /* Pointer to Graphic array */
365
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000366static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000367static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000368
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100369static int video_logo_height = VIDEO_LOGO_HEIGHT;
370
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000371static int __maybe_unused cursor_state;
372static int __maybe_unused old_col;
373static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000374
Wolfgang Denk57912932011-07-30 12:48:09 +0000375static int console_col; /* cursor col */
376static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000377
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000378static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000379
380static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000381 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
382 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
383 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
384 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
385};
wdenkc6097192002-11-03 00:24:07 +0000386
387static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000388 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
389};
wdenkc6097192002-11-03 00:24:07 +0000390
391static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000392 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
393};
wdenkc6097192002-11-03 00:24:07 +0000394
395static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000396 {0x00000000, 0x00000000, 0x00000000},
397 {0x00000000, 0x00000000, 0x00ffffff},
398 {0x00000000, 0x0000ffff, 0xff000000},
399 {0x00000000, 0x0000ffff, 0xffffffff},
400 {0x000000ff, 0xffff0000, 0x00000000},
401 {0x000000ff, 0xffff0000, 0x00ffffff},
402 {0x000000ff, 0xffffffff, 0xff000000},
403 {0x000000ff, 0xffffffff, 0xffffffff},
404 {0xffffff00, 0x00000000, 0x00000000},
405 {0xffffff00, 0x00000000, 0x00ffffff},
406 {0xffffff00, 0x0000ffff, 0xff000000},
407 {0xffffff00, 0x0000ffff, 0xffffffff},
408 {0xffffffff, 0xffff0000, 0x00000000},
409 {0xffffffff, 0xffff0000, 0x00ffffff},
410 {0xffffffff, 0xffffffff, 0xff000000},
411 {0xffffffff, 0xffffffff, 0xffffffff}
412};
wdenkc6097192002-11-03 00:24:07 +0000413
414static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000415 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
416 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
417 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
418 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
419 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
420 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
421 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
422 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
423 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
424 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
425 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
426 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
427 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
428 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
429 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
430 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
431};
wdenkc6097192002-11-03 00:24:07 +0000432
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000433static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000434{
wdenk4b248f32004-03-14 16:51:43 +0000435 u8 *cdat, *dest, *dest0;
436 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000437
wdenk4b248f32004-03-14 16:51:43 +0000438 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
439 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000440
wdenk4b248f32004-03-14 16:51:43 +0000441 switch (VIDEO_DATA_FORMAT) {
442 case GDF__8BIT_INDEX:
443 case GDF__8BIT_332RGB:
444 while (count--) {
445 c = *s;
446 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
447 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000448 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000449 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000450
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000451 ((u32 *) dest)[0] =
452 (video_font_draw_table8[bits >> 4] &
453 eorx) ^ bgx;
454 ((u32 *) dest)[1] =
455 (video_font_draw_table8[bits & 15] &
456 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000457 }
458 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
459 s++;
460 }
461 break;
wdenkc6097192002-11-03 00:24:07 +0000462
wdenk4b248f32004-03-14 16:51:43 +0000463 case GDF_15BIT_555RGB:
464 while (count--) {
465 c = *s;
466 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
467 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000468 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000469 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000470
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000471 ((u32 *) dest)[0] =
472 SHORTSWAP32((video_font_draw_table15
473 [bits >> 6] & eorx) ^
474 bgx);
475 ((u32 *) dest)[1] =
476 SHORTSWAP32((video_font_draw_table15
477 [bits >> 4 & 3] & eorx) ^
478 bgx);
479 ((u32 *) dest)[2] =
480 SHORTSWAP32((video_font_draw_table15
481 [bits >> 2 & 3] & eorx) ^
482 bgx);
483 ((u32 *) dest)[3] =
484 SHORTSWAP32((video_font_draw_table15
485 [bits & 3] & eorx) ^
486 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000487 }
488 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
489 s++;
490 }
491 break;
wdenkc6097192002-11-03 00:24:07 +0000492
wdenk4b248f32004-03-14 16:51:43 +0000493 case GDF_16BIT_565RGB:
494 while (count--) {
495 c = *s;
496 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
497 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000498 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000499 u8 bits = *cdat++;
500
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000501 ((u32 *) dest)[0] =
502 SHORTSWAP32((video_font_draw_table16
503 [bits >> 6] & eorx) ^
504 bgx);
505 ((u32 *) dest)[1] =
506 SHORTSWAP32((video_font_draw_table16
507 [bits >> 4 & 3] & eorx) ^
508 bgx);
509 ((u32 *) dest)[2] =
510 SHORTSWAP32((video_font_draw_table16
511 [bits >> 2 & 3] & eorx) ^
512 bgx);
513 ((u32 *) dest)[3] =
514 SHORTSWAP32((video_font_draw_table16
515 [bits & 3] & eorx) ^
516 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000517 }
518 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
519 s++;
520 }
521 break;
522
523 case GDF_32BIT_X888RGB:
524 while (count--) {
525 c = *s;
526 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
527 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000528 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000529 u8 bits = *cdat++;
530
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000531 ((u32 *) dest)[0] =
532 SWAP32((video_font_draw_table32
533 [bits >> 4][0] & eorx) ^ bgx);
534 ((u32 *) dest)[1] =
535 SWAP32((video_font_draw_table32
536 [bits >> 4][1] & eorx) ^ bgx);
537 ((u32 *) dest)[2] =
538 SWAP32((video_font_draw_table32
539 [bits >> 4][2] & eorx) ^ bgx);
540 ((u32 *) dest)[3] =
541 SWAP32((video_font_draw_table32
542 [bits >> 4][3] & eorx) ^ bgx);
543 ((u32 *) dest)[4] =
544 SWAP32((video_font_draw_table32
545 [bits & 15][0] & eorx) ^ bgx);
546 ((u32 *) dest)[5] =
547 SWAP32((video_font_draw_table32
548 [bits & 15][1] & eorx) ^ bgx);
549 ((u32 *) dest)[6] =
550 SWAP32((video_font_draw_table32
551 [bits & 15][2] & eorx) ^ bgx);
552 ((u32 *) dest)[7] =
553 SWAP32((video_font_draw_table32
554 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000555 }
556 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
557 s++;
558 }
559 break;
560
561 case GDF_24BIT_888RGB:
562 while (count--) {
563 c = *s;
564 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
565 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000566 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000567 u8 bits = *cdat++;
568
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000569 ((u32 *) dest)[0] =
570 (video_font_draw_table24[bits >> 4][0]
571 & eorx) ^ bgx;
572 ((u32 *) dest)[1] =
573 (video_font_draw_table24[bits >> 4][1]
574 & eorx) ^ bgx;
575 ((u32 *) dest)[2] =
576 (video_font_draw_table24[bits >> 4][2]
577 & eorx) ^ bgx;
578 ((u32 *) dest)[3] =
579 (video_font_draw_table24[bits & 15][0]
580 & eorx) ^ bgx;
581 ((u32 *) dest)[4] =
582 (video_font_draw_table24[bits & 15][1]
583 & eorx) ^ bgx;
584 ((u32 *) dest)[5] =
585 (video_font_draw_table24[bits & 15][2]
586 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000587 }
588 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
589 s++;
590 }
591 break;
wdenk8bde7f72003-06-27 21:31:46 +0000592 }
wdenkc6097192002-11-03 00:24:07 +0000593}
594
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000595static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000596{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000597 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000598}
599
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000600static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000601{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000602 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000603}
604
wdenkc6097192002-11-03 00:24:07 +0000605#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000606static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000607{
Gabe Black03d31fc2011-11-30 13:50:50 +0000608 if (cursor_state)
609 console_cursor(0);
610 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000611}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000612
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000613static void video_invertchar(int xx, int yy)
614{
615 int firstx = xx * VIDEO_PIXEL_SIZE;
616 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
617 int firsty = yy * VIDEO_LINE_LEN;
618 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
619 int x, y;
620 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
621 for (x = firstx; x < lastx; x++) {
622 u8 *dest = (u8 *)(video_fb_address) + x + y;
623 *dest = ~*dest;
624 }
625 }
626}
Gabe Black03d31fc2011-11-30 13:50:50 +0000627
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000628void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000629{
wdenkc6097192002-11-03 00:24:07 +0000630#ifdef CONFIG_CONSOLE_TIME
wdenk4b248f32004-03-14 16:51:43 +0000631 struct rtc_time tm;
632 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000633
wdenk4b248f32004-03-14 16:51:43 +0000634 /* time update only if cursor is on (faster scroll) */
635 if (state) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000636 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000637
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000638 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
639 tm.tm_sec);
640 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
641 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000642
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000643 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
644 tm.tm_year);
645 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
646 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
647 (uchar *) info);
wdenk4b248f32004-03-14 16:51:43 +0000648 }
wdenkc6097192002-11-03 00:24:07 +0000649#endif
650
Gabe Black03d31fc2011-11-30 13:50:50 +0000651 if (cursor_state != state) {
652 if (cursor_state) {
653 /* turn off the cursor */
654 video_invertchar(old_col * VIDEO_FONT_WIDTH,
655 old_row * VIDEO_FONT_HEIGHT +
656 video_logo_height);
657 } else {
658 /* turn off the cursor and record where it is */
659 video_invertchar(console_col * VIDEO_FONT_WIDTH,
660 console_row * VIDEO_FONT_HEIGHT +
661 video_logo_height);
662 old_col = console_col;
663 old_row = console_row;
664 }
665 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000666 }
wdenkc6097192002-11-03 00:24:07 +0000667}
668#endif
669
wdenkc6097192002-11-03 00:24:07 +0000670#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000671static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000672{
wdenk4b248f32004-03-14 16:51:43 +0000673 while (c--)
674 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000675}
676#endif
677
wdenkc6097192002-11-03 00:24:07 +0000678#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000679static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000680{
wdenk4b248f32004-03-14 16:51:43 +0000681 while (c--)
682 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000683}
684#endif
685
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000686static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000687{
wdenk4b248f32004-03-14 16:51:43 +0000688 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000689
690#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000691 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
692 0, /* source pos x */
693 video_logo_height +
694 VIDEO_FONT_HEIGHT, /* source pos y */
695 0, /* dest pos x */
696 video_logo_height, /* dest pos y */
697 VIDEO_VISIBLE_COLS, /* frame width */
698 VIDEO_VISIBLE_ROWS
699 - video_logo_height
700 - VIDEO_FONT_HEIGHT /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000701 );
wdenkc6097192002-11-03 00:24:07 +0000702#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000703 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
704 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000705#endif
706
wdenk4b248f32004-03-14 16:51:43 +0000707 /* clear the last one */
wdenkc6097192002-11-03 00:24:07 +0000708#ifdef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000709 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
710 0, /* dest pos x */
711 VIDEO_VISIBLE_ROWS
712 - VIDEO_FONT_HEIGHT, /* dest pos y */
713 VIDEO_VISIBLE_COLS, /* frame width */
714 VIDEO_FONT_HEIGHT, /* frame height */
715 CONSOLE_BG_COL /* fill color */
wdenk4b248f32004-03-14 16:51:43 +0000716 );
wdenkc6097192002-11-03 00:24:07 +0000717#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000718 memsetl(CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, CONSOLE_BG_COL);
wdenkc6097192002-11-03 00:24:07 +0000719#endif
720}
721
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000722static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000723{
Timur Tabi65618632010-08-27 15:45:47 -0500724 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000725
wdenk4b248f32004-03-14 16:51:43 +0000726 if (console_col < 0) {
727 console_col = CONSOLE_COLS - 1;
728 console_row--;
729 if (console_row < 0)
730 console_row = 0;
731 }
wdenkc6097192002-11-03 00:24:07 +0000732}
733
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000734static void console_newline(void)
wdenkc6097192002-11-03 00:24:07 +0000735{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100736 console_row++;
wdenk4b248f32004-03-14 16:51:43 +0000737 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000738
wdenk4b248f32004-03-14 16:51:43 +0000739 /* Check if we need to scroll the terminal */
740 if (console_row >= CONSOLE_ROWS) {
741 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000742 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000743
wdenk4b248f32004-03-14 16:51:43 +0000744 /* Decrement row number */
745 console_row--;
746 }
wdenkc6097192002-11-03 00:24:07 +0000747}
748
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000749static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100750{
Timur Tabi65618632010-08-27 15:45:47 -0500751 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100752}
753
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000754void video_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000755{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100756 static int nl = 1;
757
Gabe Black03d31fc2011-11-30 13:50:50 +0000758 CURSOR_OFF;
759
wdenk4b248f32004-03-14 16:51:43 +0000760 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100761 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000762 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000763 break;
wdenkc6097192002-11-03 00:24:07 +0000764
wdenk4b248f32004-03-14 16:51:43 +0000765 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100766 if (console_col || (!console_col && nl))
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000767 console_newline();
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100768 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000769 break;
wdenkc6097192002-11-03 00:24:07 +0000770
wdenk4b248f32004-03-14 16:51:43 +0000771 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500772 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000773 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000774
wdenk4b248f32004-03-14 16:51:43 +0000775 if (console_col >= CONSOLE_COLS)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000776 console_newline();
wdenk4b248f32004-03-14 16:51:43 +0000777 break;
wdenkc6097192002-11-03 00:24:07 +0000778
wdenk4b248f32004-03-14 16:51:43 +0000779 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000780 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000781 break;
wdenkc6097192002-11-03 00:24:07 +0000782
wdenk4b248f32004-03-14 16:51:43 +0000783 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000784 video_putchar(console_col * VIDEO_FONT_WIDTH,
785 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000786 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000787
wdenk4b248f32004-03-14 16:51:43 +0000788 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100789 if (console_col >= CONSOLE_COLS) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000790 console_newline();
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100791 nl = 0;
792 }
wdenk4b248f32004-03-14 16:51:43 +0000793 }
Timur Tabi65618632010-08-27 15:45:47 -0500794 CURSOR_SET;
795}
wdenkc6097192002-11-03 00:24:07 +0000796
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000797void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +0000798{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000799 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +0000800
wdenk4b248f32004-03-14 16:51:43 +0000801 while (count--)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000802 video_putc(*s++);
wdenkc6097192002-11-03 00:24:07 +0000803}
804
Anatolij Gustschin10543822010-05-01 22:21:09 +0200805/*
806 * Do not enforce drivers (or board code) to provide empty
807 * video_set_lut() if they do not support 8 bpp format.
808 * Implement weak default function instead.
809 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000810void __video_set_lut(unsigned int index, unsigned char r,
811 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +0200812{
813}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000814
815void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
816 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschin10543822010-05-01 22:21:09 +0200817
Jon Loeliger07d38a12007-07-09 17:30:01 -0500818#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000819
820#define FILL_8BIT_332RGB(r,g,b) { \
821 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
822 fb ++; \
823}
824
825#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000826 *(unsigned short *)fb = \
827 SWAP16((unsigned short)(((r>>3)<<10) | \
828 ((g>>3)<<5) | \
829 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +0000830 fb += 2; \
831}
832
833#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000834 *(unsigned short *)fb = \
835 SWAP16((unsigned short)((((r)>>3)<<11)| \
836 (((g)>>2)<<5) | \
837 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +0000838 fb += 2; \
839}
840
841#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000842 *(unsigned long *)fb = \
843 SWAP32((unsigned long)(((r<<16) | \
844 (g<<8) | \
845 b))); \
wdenk4b248f32004-03-14 16:51:43 +0000846 fb += 4; \
847}
848
849#ifdef VIDEO_FB_LITTLE_ENDIAN
850#define FILL_24BIT_888RGB(r,g,b) { \
851 fb[0] = b; \
852 fb[1] = g; \
853 fb[2] = r; \
854 fb += 3; \
855}
856#else
857#define FILL_24BIT_888RGB(r,g,b) { \
858 fb[0] = r; \
859 fb[1] = g; \
860 fb[2] = b; \
861 fb += 3; \
862}
863#endif
864
Anatolij Gustschine84d5682008-08-08 18:00:40 +0200865#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000866static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +0200867{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000868 ushort *dst = (ushort *) fb;
869 ushort color = (ushort) (((r >> 3) << 10) |
870 ((g >> 3) << 5) |
871 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +0200872 if (x & 1)
873 *(--dst) = color;
874 else
875 *(++dst) = color;
876}
877#endif
wdenk4b248f32004-03-14 16:51:43 +0000878
879/*
Anatolij Gustschind5011762010-03-15 14:50:25 +0100880 * RLE8 bitmap support
881 */
882
883#ifdef CONFIG_VIDEO_BMP_RLE8
884/* Pre-calculated color table entry */
885struct palette {
886 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000887 unsigned short w; /* word */
888 unsigned int dw; /* double word */
889 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +0100890};
891
892/*
893 * Helper to draw encoded/unencoded run.
894 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000895static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
896 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +0100897{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000898 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100899 int *off;
900 int enc_off = 1;
901 int i;
902
903 /*
904 * Setup offset of the color index in the bitmap.
905 * Color index of encoded run is at offset 1.
906 */
907 off = enc ? &enc_off : &i;
908
909 switch (VIDEO_DATA_FORMAT) {
910 case GDF__8BIT_INDEX:
911 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000912 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +0100913 break;
914 case GDF_15BIT_555RGB:
915 case GDF_16BIT_565RGB:
916 /* differences handled while pre-calculating palette */
917 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000918 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100919 addr += 2;
920 }
921 break;
922 case GDF_32BIT_X888RGB:
923 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000924 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100925 addr += 4;
926 }
927 break;
928 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000929 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +0100930}
931
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000932static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
933 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +0100934{
935 unsigned char *bm;
936 unsigned char *fbp;
937 unsigned int cnt, runlen;
938 int decode = 1;
939 int x, y, bpp, i, ncolors;
940 struct palette p[256];
941 bmp_color_table_entry_t cte;
942 int green_shift, red_off;
Anatolij Gustschin74446b62011-02-21 21:33:29 +0100943 int limit = VIDEO_COLS * VIDEO_ROWS;
944 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100945
946 x = 0;
947 y = __le32_to_cpu(img->header.height) - 1;
948 ncolors = __le32_to_cpu(img->header.colors_used);
949 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000950 fbp = (unsigned char *) ((unsigned int) video_fb_address +
951 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100952
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000953 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100954
955 /* pre-calculate and setup palette */
956 switch (VIDEO_DATA_FORMAT) {
957 case GDF__8BIT_INDEX:
958 for (i = 0; i < ncolors; i++) {
959 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000960 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100961 }
962 break;
963 case GDF_15BIT_555RGB:
964 case GDF_16BIT_565RGB:
965 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
966 green_shift = 3;
967 red_off = 10;
968 } else {
969 green_shift = 2;
970 red_off = 11;
971 }
972 for (i = 0; i < ncolors; i++) {
973 cte = img->color_table[i];
974 p[i].ce.w = SWAP16((unsigned short)
975 (((cte.red >> 3) << red_off) |
976 ((cte.green >> green_shift) << 5) |
977 cte.blue >> 3));
978 }
979 break;
980 case GDF_32BIT_X888RGB:
981 for (i = 0; i < ncolors; i++) {
982 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000983 p[i].ce.dw = SWAP32((cte.red << 16) |
984 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +0100985 cte.blue);
986 }
987 break;
988 default:
989 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000990 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100991 return -1;
992 }
993
994 while (decode) {
995 switch (bm[0]) {
996 case 0:
997 switch (bm[1]) {
998 case 0:
999 /* scan line end marker */
1000 bm += 2;
1001 x = 0;
1002 y--;
1003 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001004 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001005 (((y + yoff) * VIDEO_COLS) +
1006 xoff) * bpp);
1007 continue;
1008 case 1:
1009 /* end of bitmap data marker */
1010 decode = 0;
1011 break;
1012 case 2:
1013 /* run offset marker */
1014 x += bm[2];
1015 y -= bm[3];
1016 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001017 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001018 (((y + yoff) * VIDEO_COLS) +
1019 x + xoff) * bpp);
1020 bm += 4;
1021 break;
1022 default:
1023 /* unencoded run */
1024 cnt = bm[1];
1025 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001026 pixels += cnt;
1027 if (pixels > limit)
1028 goto error;
1029
Anatolij Gustschind5011762010-03-15 14:50:25 +01001030 bm += 2;
1031 if (y < height) {
1032 if (x >= width) {
1033 x += runlen;
1034 goto next_run;
1035 }
1036 if (x + runlen > width)
1037 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001038 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001039 x += runlen;
1040 }
1041next_run:
1042 bm += runlen;
1043 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001044 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001045 }
1046 break;
1047 default:
1048 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001049 cnt = bm[0];
1050 runlen = cnt;
1051 pixels += cnt;
1052 if (pixels > limit)
1053 goto error;
1054
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001055 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001056 if (x >= width) {
1057 x += runlen;
1058 bm += 2;
1059 continue;
1060 }
1061 if (x + runlen > width)
1062 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001063 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001064 x += runlen;
1065 }
1066 bm += 2;
1067 break;
1068 }
1069 }
1070 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001071error:
1072 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1073 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001074}
1075#endif
1076
1077/*
wdenk4b248f32004-03-14 16:51:43 +00001078 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001079 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001080int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001081{
1082 ushort xcount, ycount;
1083 uchar *fb;
1084 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1085 uchar *bmap;
1086 ushort padded_line;
1087 unsigned long width, height, bpp;
1088 unsigned colors;
1089 unsigned long compression;
1090 bmp_color_table_entry_t cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001091
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001092#ifdef CONFIG_VIDEO_BMP_GZIP
1093 unsigned char *dst = NULL;
1094 ulong len;
1095#endif
wdenk4b248f32004-03-14 16:51:43 +00001096
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001097 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001098
1099 if (!((bmp->header.signature[0] == 'B') &&
1100 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001101
1102#ifdef CONFIG_VIDEO_BMP_GZIP
1103 /*
1104 * Could be a gzipped bmp image, try to decrompress...
1105 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001106 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1107 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001108 if (dst == NULL) {
1109 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001110 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001111 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001112 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1113 (uchar *) bmp_image,
1114 &len) != 0) {
1115 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1116 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001117 free(dst);
1118 return 1;
1119 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001120 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001121 printf("Image could be truncated "
1122 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001123 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001124
1125 /*
1126 * Set addr to decompressed image
1127 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001128 bmp = (bmp_image_t *) dst;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001129
1130 if (!((bmp->header.signature[0] == 'B') &&
1131 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001132 printf("Error: no valid bmp.gz image at %lx\n",
1133 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001134 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001135 return 1;
1136 }
1137#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001138 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001139 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001140#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001141 }
1142
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001143 width = le32_to_cpu(bmp->header.width);
1144 height = le32_to_cpu(bmp->header.height);
1145 bpp = le16_to_cpu(bmp->header.bit_count);
1146 colors = le32_to_cpu(bmp->header.colors_used);
1147 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001148
Marek Vasut68da5b12011-10-21 14:17:04 +00001149 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001150 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001151
Anatolij Gustschind5011762010-03-15 14:50:25 +01001152 if (compression != BMP_BI_RGB
1153#ifdef CONFIG_VIDEO_BMP_RLE8
1154 && compression != BMP_BI_RLE8
1155#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001156 ) {
1157 printf("Error: compression type %ld not supported\n",
1158 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001159#ifdef CONFIG_VIDEO_BMP_GZIP
1160 if (dst)
1161 free(dst);
1162#endif
wdenk4b248f32004-03-14 16:51:43 +00001163 return 1;
1164 }
1165
1166 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1167
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001168#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1169 if (x == BMP_ALIGN_CENTER)
1170 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1171 else if (x < 0)
1172 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1173
1174 if (y == BMP_ALIGN_CENTER)
1175 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1176 else if (y < 0)
1177 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1178#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1179
wdenk4b248f32004-03-14 16:51:43 +00001180 if ((x + width) > VIDEO_VISIBLE_COLS)
1181 width = VIDEO_VISIBLE_COLS - x;
1182 if ((y + height) > VIDEO_VISIBLE_ROWS)
1183 height = VIDEO_VISIBLE_ROWS - y;
1184
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001185 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001186 fb = (uchar *) (video_fb_address +
1187 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1188 x * VIDEO_PIXEL_SIZE);
1189
Anatolij Gustschind5011762010-03-15 14:50:25 +01001190#ifdef CONFIG_VIDEO_BMP_RLE8
1191 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001192 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001193 }
1194#endif
1195
Timur Tabi68f66182010-08-23 16:58:00 -05001196 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001197 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001198 case 4:
1199 padded_line -= width / 2;
1200 ycount = height;
1201
1202 switch (VIDEO_DATA_FORMAT) {
1203 case GDF_32BIT_X888RGB:
1204 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001205 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001206 /*
1207 * Don't assume that 'width' is an
1208 * even number
1209 */
1210 for (xcount = 0; xcount < width; xcount++) {
1211 uchar idx;
1212
1213 if (xcount & 1) {
1214 idx = *bmap & 0xF;
1215 bmap++;
1216 } else
1217 idx = *bmap >> 4;
1218 cte = bmp->color_table[idx];
1219 FILL_32BIT_X888RGB(cte.red, cte.green,
1220 cte.blue);
1221 }
1222 bmap += padded_line;
1223 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001224 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001225 }
1226 break;
1227 default:
1228 puts("4bpp bitmap unsupported with current "
1229 "video mode\n");
1230 break;
1231 }
1232 break;
1233
wdenk4b248f32004-03-14 16:51:43 +00001234 case 8:
1235 padded_line -= width;
1236 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001237 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001238 for (xcount = 0; xcount < colors; ++xcount) {
1239 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001240 video_set_lut(xcount, cte.red, cte.green,
1241 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001242 }
1243 }
1244 ycount = height;
1245 switch (VIDEO_DATA_FORMAT) {
1246 case GDF__8BIT_INDEX:
1247 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001248 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001249 xcount = width;
1250 while (xcount--) {
1251 *fb++ = *bmap++;
1252 }
1253 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001254 fb -= (VIDEO_VISIBLE_COLS + width) *
1255 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001256 }
1257 break;
1258 case GDF__8BIT_332RGB:
1259 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001260 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001261 xcount = width;
1262 while (xcount--) {
1263 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001264 FILL_8BIT_332RGB(cte.red, cte.green,
1265 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001266 }
1267 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001268 fb -= (VIDEO_VISIBLE_COLS + width) *
1269 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001270 }
1271 break;
1272 case GDF_15BIT_555RGB:
1273 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001274#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1275 int xpos = x;
1276#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001277 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001278 xcount = width;
1279 while (xcount--) {
1280 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001281#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001282 fill_555rgb_pswap(fb, xpos++, cte.red,
1283 cte.green,
1284 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001285 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001286#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001287 FILL_15BIT_555RGB(cte.red, cte.green,
1288 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001289#endif
wdenk4b248f32004-03-14 16:51:43 +00001290 }
1291 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001292 fb -= (VIDEO_VISIBLE_COLS + width) *
1293 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001294 }
1295 break;
1296 case GDF_16BIT_565RGB:
1297 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001298 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001299 xcount = width;
1300 while (xcount--) {
1301 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001302 FILL_16BIT_565RGB(cte.red, cte.green,
1303 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001304 }
1305 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001306 fb -= (VIDEO_VISIBLE_COLS + width) *
1307 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001308 }
1309 break;
1310 case GDF_32BIT_X888RGB:
1311 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001312 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001313 xcount = width;
1314 while (xcount--) {
1315 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001316 FILL_32BIT_X888RGB(cte.red, cte.green,
1317 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001318 }
1319 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001320 fb -= (VIDEO_VISIBLE_COLS + width) *
1321 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001322 }
1323 break;
1324 case GDF_24BIT_888RGB:
1325 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001326 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001327 xcount = width;
1328 while (xcount--) {
1329 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001330 FILL_24BIT_888RGB(cte.red, cte.green,
1331 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001332 }
1333 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001334 fb -= (VIDEO_VISIBLE_COLS + width) *
1335 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001336 }
1337 break;
1338 }
1339 break;
1340 case 24:
1341 padded_line -= 3 * width;
1342 ycount = height;
1343 switch (VIDEO_DATA_FORMAT) {
1344 case GDF__8BIT_332RGB:
1345 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001346 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001347 xcount = width;
1348 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001349 FILL_8BIT_332RGB(bmap[2], bmap[1],
1350 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001351 bmap += 3;
1352 }
1353 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001354 fb -= (VIDEO_VISIBLE_COLS + width) *
1355 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001356 }
1357 break;
1358 case GDF_15BIT_555RGB:
1359 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001360#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1361 int xpos = x;
1362#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001363 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001364 xcount = width;
1365 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001366#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001367 fill_555rgb_pswap(fb, xpos++, bmap[2],
1368 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001369 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001370#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001371 FILL_15BIT_555RGB(bmap[2], bmap[1],
1372 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001373#endif
wdenk4b248f32004-03-14 16:51:43 +00001374 bmap += 3;
1375 }
1376 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001377 fb -= (VIDEO_VISIBLE_COLS + width) *
1378 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001379 }
1380 break;
1381 case GDF_16BIT_565RGB:
1382 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001383 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001384 xcount = width;
1385 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001386 FILL_16BIT_565RGB(bmap[2], bmap[1],
1387 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001388 bmap += 3;
1389 }
1390 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001391 fb -= (VIDEO_VISIBLE_COLS + width) *
1392 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001393 }
1394 break;
1395 case GDF_32BIT_X888RGB:
1396 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001397 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001398 xcount = width;
1399 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001400 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1401 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001402 bmap += 3;
1403 }
1404 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001405 fb -= (VIDEO_VISIBLE_COLS + width) *
1406 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001407 }
1408 break;
1409 case GDF_24BIT_888RGB:
1410 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001411 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001412 xcount = width;
1413 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001414 FILL_24BIT_888RGB(bmap[2], bmap[1],
1415 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001416 bmap += 3;
1417 }
1418 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001419 fb -= (VIDEO_VISIBLE_COLS + width) *
1420 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001421 }
1422 break;
1423 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001424 printf("Error: 24 bits/pixel bitmap incompatible "
1425 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001426 break;
1427 }
1428 break;
1429 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001430 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1431 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001432 break;
1433 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001434
1435#ifdef CONFIG_VIDEO_BMP_GZIP
1436 if (dst) {
1437 free(dst);
1438 }
1439#endif
1440
wdenk4b248f32004-03-14 16:51:43 +00001441 return (0);
1442}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001443#endif
wdenk4b248f32004-03-14 16:51:43 +00001444
wdenk4b248f32004-03-14 16:51:43 +00001445
wdenkc6097192002-11-03 00:24:07 +00001446#ifdef CONFIG_VIDEO_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001447void logo_plot(void *screen, int width, int x, int y)
wdenkc6097192002-11-03 00:24:07 +00001448{
wdenkc6097192002-11-03 00:24:07 +00001449
wdenk4b248f32004-03-14 16:51:43 +00001450 int xcount, i;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001451 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001452 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001453 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1454 unsigned char *source;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001455 unsigned char *dest = (unsigned char *) screen +
1456 ((y * width * VIDEO_PIXEL_SIZE) + x * VIDEO_PIXEL_SIZE);
wdenka6c7ad22002-12-03 21:28:10 +00001457
1458#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001459 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001460
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001461 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001462 logo_red = malloc(BMP_LOGO_COLORS);
1463 logo_green = malloc(BMP_LOGO_COLORS);
1464 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001465 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001466 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1467 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1468 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1469 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1470 }
wdenka6c7ad22002-12-03 21:28:10 +00001471#else
wdenk4b248f32004-03-14 16:51:43 +00001472 source = linux_logo;
1473 logo_red = linux_logo_red;
1474 logo_green = linux_logo_green;
1475 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001476#endif
wdenk8bde7f72003-06-27 21:31:46 +00001477
wdenk4b248f32004-03-14 16:51:43 +00001478 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1479 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001480 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1481 logo_red[i], logo_green[i],
1482 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001483 }
wdenk8bde7f72003-06-27 21:31:46 +00001484 }
wdenkc6097192002-11-03 00:24:07 +00001485
wdenk4b248f32004-03-14 16:51:43 +00001486 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001487#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1488 int xpos = x;
1489#endif
wdenk4b248f32004-03-14 16:51:43 +00001490 xcount = VIDEO_LOGO_WIDTH;
1491 while (xcount--) {
1492 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1493 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1494 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
wdenk8bde7f72003-06-27 21:31:46 +00001495
wdenk4b248f32004-03-14 16:51:43 +00001496 switch (VIDEO_DATA_FORMAT) {
1497 case GDF__8BIT_INDEX:
1498 *dest = *source;
1499 break;
1500 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001501 *dest = ((r >> 5) << 5) |
1502 ((g >> 5) << 2) |
1503 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001504 break;
1505 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001506#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001507 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001508#else
wdenk4b248f32004-03-14 16:51:43 +00001509 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001510 SWAP16((unsigned short) (
1511 ((r >> 3) << 10) |
1512 ((g >> 3) << 5) |
1513 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001514#endif
wdenk4b248f32004-03-14 16:51:43 +00001515 break;
1516 case GDF_16BIT_565RGB:
1517 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001518 SWAP16((unsigned short) (
1519 ((r >> 3) << 11) |
1520 ((g >> 2) << 5) |
1521 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001522 break;
1523 case GDF_32BIT_X888RGB:
1524 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001525 SWAP32((unsigned long) (
1526 (r << 16) |
1527 (g << 8) |
1528 b));
wdenk4b248f32004-03-14 16:51:43 +00001529 break;
1530 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001531#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001532 dest[0] = b;
1533 dest[1] = g;
1534 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001535#else
wdenk4b248f32004-03-14 16:51:43 +00001536 dest[0] = r;
1537 dest[1] = g;
1538 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001539#endif
wdenk4b248f32004-03-14 16:51:43 +00001540 break;
1541 }
1542 source++;
1543 dest += VIDEO_PIXEL_SIZE;
1544 }
1545 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001546 }
wdenka6c7ad22002-12-03 21:28:10 +00001547#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001548 free(logo_red);
1549 free(logo_green);
1550 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001551#endif
wdenkc6097192002-11-03 00:24:07 +00001552}
1553
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001554static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001555{
wdenk4b248f32004-03-14 16:51:43 +00001556 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001557 int space, len;
1558 __maybe_unused int y_off = 0;
wdenkc6097192002-11-03 00:24:07 +00001559
wdenk4b248f32004-03-14 16:51:43 +00001560#ifdef CONFIG_SPLASH_SCREEN
1561 char *s;
1562 ulong addr;
wdenkc6097192002-11-03 00:24:07 +00001563
Wolfgang Denk57912932011-07-30 12:48:09 +00001564 s = getenv("splashimage");
1565 if (s != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001566 int x = 0, y = 0;
wdenk4b248f32004-03-14 16:51:43 +00001567
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001568 addr = simple_strtoul(s, NULL, 16);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001569#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Wolfgang Denk57912932011-07-30 12:48:09 +00001570 s = getenv("splashpos");
1571 if (s != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001572 if (s[0] == 'm')
1573 x = BMP_ALIGN_CENTER;
1574 else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001575 x = simple_strtol(s, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001576
Wolfgang Denk57912932011-07-30 12:48:09 +00001577 s = strchr(s + 1, ',');
1578 if (s != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001579 if (s[1] == 'm')
1580 y = BMP_ALIGN_CENTER;
1581 else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001582 y = simple_strtol(s + 1, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001583 }
1584 }
1585#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1586
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001587 if (video_display_bitmap(addr, x, y) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001588 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00001589 return ((void *) (video_fb_address));
1590 }
1591 }
1592#endif /* CONFIG_SPLASH_SCREEN */
1593
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001594 logo_plot(video_fb_address, VIDEO_COLS, 0, 0);
wdenk4b248f32004-03-14 16:51:43 +00001595
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001596 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001597
1598 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1599 len = strlen(info);
1600
1601 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001602 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1603 (uchar *) info, space);
1604 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1605 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1606 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001607 y_off = 1;
1608 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001609 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001610
1611#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00001612 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001613 int i, n =
1614 ((video_logo_height -
1615 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001616
wdenk4b248f32004-03-14 16:51:43 +00001617 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001618 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001619 if (!*info)
1620 continue;
1621
1622 len = strlen(info);
1623 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001624 video_drawchars(VIDEO_INFO_X,
1625 VIDEO_INFO_Y +
1626 (i + y_off) *
1627 VIDEO_FONT_HEIGHT,
1628 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001629 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001630 video_drawchars(VIDEO_INFO_X +
1631 VIDEO_FONT_WIDTH,
1632 VIDEO_INFO_Y +
1633 (i + y_off) *
1634 VIDEO_FONT_HEIGHT,
1635 (uchar *) info + space,
1636 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001637 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001638 video_drawstring(VIDEO_INFO_X,
1639 VIDEO_INFO_Y +
1640 (i + y_off) *
1641 VIDEO_FONT_HEIGHT,
1642 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001643 }
wdenk4b248f32004-03-14 16:51:43 +00001644 }
1645 }
wdenkc6097192002-11-03 00:24:07 +00001646#endif
1647
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001648 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001649}
1650#endif
1651
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001652static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001653{
wdenk4b248f32004-03-14 16:51:43 +00001654 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001655
Wolfgang Denk57912932011-07-30 12:48:09 +00001656 pGD = video_hw_init();
1657 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00001658 return -1;
wdenkc6097192002-11-03 00:24:07 +00001659
wdenk4b248f32004-03-14 16:51:43 +00001660 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001661#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001662 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001663#endif
1664
wdenk4b248f32004-03-14 16:51:43 +00001665 /* Init drawing pats */
1666 switch (VIDEO_DATA_FORMAT) {
1667 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001668 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
1669 CONSOLE_FG_COL);
1670 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1671 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00001672 fgx = 0x01010101;
1673 bgx = 0x00000000;
1674 break;
1675 case GDF__8BIT_332RGB:
1676 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001677 ((CONSOLE_FG_COL >> 3) & 0x1c) |
1678 CONSOLE_FG_COL >> 6);
1679 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1680 color8;
wdenk4b248f32004-03-14 16:51:43 +00001681 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001682 ((CONSOLE_BG_COL >> 3) & 0x1c) |
1683 CONSOLE_BG_COL >> 6);
1684 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1685 color8;
wdenk4b248f32004-03-14 16:51:43 +00001686 break;
1687 case GDF_15BIT_555RGB:
1688 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001689 ((CONSOLE_FG_COL >> 3) << 21) |
1690 ((CONSOLE_FG_COL >> 3) << 16) |
1691 ((CONSOLE_FG_COL >> 3) << 10) |
1692 ((CONSOLE_FG_COL >> 3) << 5) |
1693 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001694 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001695 ((CONSOLE_BG_COL >> 3) << 21) |
1696 ((CONSOLE_BG_COL >> 3) << 16) |
1697 ((CONSOLE_BG_COL >> 3) << 10) |
1698 ((CONSOLE_BG_COL >> 3) << 5) |
1699 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001700 break;
1701 case GDF_16BIT_565RGB:
1702 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001703 ((CONSOLE_FG_COL >> 2) << 21) |
1704 ((CONSOLE_FG_COL >> 3) << 16) |
1705 ((CONSOLE_FG_COL >> 3) << 11) |
1706 ((CONSOLE_FG_COL >> 2) << 5) |
1707 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001708 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001709 ((CONSOLE_BG_COL >> 2) << 21) |
1710 ((CONSOLE_BG_COL >> 3) << 16) |
1711 ((CONSOLE_BG_COL >> 3) << 11) |
1712 ((CONSOLE_BG_COL >> 2) << 5) |
1713 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001714 break;
1715 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001716 fgx = (CONSOLE_FG_COL << 16) |
1717 (CONSOLE_FG_COL << 8) |
1718 CONSOLE_FG_COL;
1719 bgx = (CONSOLE_BG_COL << 16) |
1720 (CONSOLE_BG_COL << 8) |
1721 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001722 break;
1723 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001724 fgx = (CONSOLE_FG_COL << 24) |
1725 (CONSOLE_FG_COL << 16) |
1726 (CONSOLE_FG_COL << 8) |
1727 CONSOLE_FG_COL;
1728 bgx = (CONSOLE_BG_COL << 24) |
1729 (CONSOLE_BG_COL << 16) |
1730 (CONSOLE_BG_COL << 8) |
1731 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001732 break;
1733 }
1734 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001735
1736#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001737 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00001738 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001739 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00001740#else
wdenk4b248f32004-03-14 16:51:43 +00001741 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001742#endif
1743
wdenk4b248f32004-03-14 16:51:43 +00001744 /* Initialize the console */
1745 console_col = 0;
1746 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001747
wdenk4b248f32004-03-14 16:51:43 +00001748 return 0;
wdenkc6097192002-11-03 00:24:07 +00001749}
1750
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001751/*
1752 * Implement a weak default function for boards that optionally
1753 * need to skip the video initialization.
1754 */
1755int __board_video_skip(void)
1756{
1757 /* As default, don't skip test */
1758 return 0;
1759}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001760
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001761int board_video_skip(void)
1762 __attribute__ ((weak, alias("__board_video_skip")));
1763
1764int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001765{
wdenk4b248f32004-03-14 16:51:43 +00001766 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02001767 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00001768
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001769 /* Check if video initialization should be skipped */
1770 if (board_video_skip())
1771 return 0;
1772
wdenk81050922004-07-11 20:04:51 +00001773 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001774 skip_dev_init = (video_init() == -1);
wdenk81050922004-07-11 20:04:51 +00001775
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001776#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk72c65f62011-07-29 09:55:28 +00001777 debug("KBD: Keyboard init ...\n");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001778 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1779#endif
wdenkc6097192002-11-03 00:24:07 +00001780
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001781 if (skip_dev_init)
1782 return 0;
wdenkc6097192002-11-03 00:24:07 +00001783
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001784 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001785 memset(&console_dev, 0, sizeof(console_dev));
1786 strcpy(console_dev.name, "vga");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001787 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1788 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1789 console_dev.putc = video_putc; /* 'putc' function */
1790 console_dev.puts = video_puts; /* 'puts' function */
1791 console_dev.tstc = NULL; /* 'tstc' function */
1792 console_dev.getc = NULL; /* 'getc' function */
1793
1794#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1795 /* Also init console device */
1796 console_dev.flags |= DEV_FLAGS_INPUT;
1797 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1798 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00001799#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001800
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001801 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001802 return 0;
1803
1804 /* Return success */
1805 return 1;
wdenkc6097192002-11-03 00:24:07 +00001806}