blob: 19d061f6cbec31615c3193f59a27895f203e959f [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 */
Fabio Estevam695af9a2012-05-31 07:23:56 +0000167#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
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
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200363DECLARE_GLOBAL_DATA_PTR;
364
wdenkc6097192002-11-03 00:24:07 +0000365/* Locals */
366static GraphicDevice *pGD; /* Pointer to Graphic array */
367
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000368static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000369static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000370
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100371static int video_logo_height = VIDEO_LOGO_HEIGHT;
372
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000373static int __maybe_unused cursor_state;
374static int __maybe_unused old_col;
375static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000376
Wolfgang Denk57912932011-07-30 12:48:09 +0000377static int console_col; /* cursor col */
378static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000379
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000380static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000381
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200382static int cfb_do_flush_cache;
383
wdenkc6097192002-11-03 00:24:07 +0000384static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000385 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
386 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
387 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
388 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
389};
wdenkc6097192002-11-03 00:24:07 +0000390
391static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000392 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
393};
wdenkc6097192002-11-03 00:24:07 +0000394
395static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000396 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
397};
wdenkc6097192002-11-03 00:24:07 +0000398
399static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000400 {0x00000000, 0x00000000, 0x00000000},
401 {0x00000000, 0x00000000, 0x00ffffff},
402 {0x00000000, 0x0000ffff, 0xff000000},
403 {0x00000000, 0x0000ffff, 0xffffffff},
404 {0x000000ff, 0xffff0000, 0x00000000},
405 {0x000000ff, 0xffff0000, 0x00ffffff},
406 {0x000000ff, 0xffffffff, 0xff000000},
407 {0x000000ff, 0xffffffff, 0xffffffff},
408 {0xffffff00, 0x00000000, 0x00000000},
409 {0xffffff00, 0x00000000, 0x00ffffff},
410 {0xffffff00, 0x0000ffff, 0xff000000},
411 {0xffffff00, 0x0000ffff, 0xffffffff},
412 {0xffffffff, 0xffff0000, 0x00000000},
413 {0xffffffff, 0xffff0000, 0x00ffffff},
414 {0xffffffff, 0xffffffff, 0xff000000},
415 {0xffffffff, 0xffffffff, 0xffffffff}
416};
wdenkc6097192002-11-03 00:24:07 +0000417
418static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000419 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
420 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
421 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
422 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
423 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
424 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
425 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
426 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
427 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
428 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
429 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
430 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
431 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
432 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
433 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
434 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
435};
wdenkc6097192002-11-03 00:24:07 +0000436
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000437static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000438{
wdenk4b248f32004-03-14 16:51:43 +0000439 u8 *cdat, *dest, *dest0;
440 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000441
wdenk4b248f32004-03-14 16:51:43 +0000442 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
443 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000444
wdenk4b248f32004-03-14 16:51:43 +0000445 switch (VIDEO_DATA_FORMAT) {
446 case GDF__8BIT_INDEX:
447 case GDF__8BIT_332RGB:
448 while (count--) {
449 c = *s;
450 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
451 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000452 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000453 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000454
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000455 ((u32 *) dest)[0] =
456 (video_font_draw_table8[bits >> 4] &
457 eorx) ^ bgx;
458 ((u32 *) dest)[1] =
459 (video_font_draw_table8[bits & 15] &
460 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000461 }
462 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
463 s++;
464 }
465 break;
wdenkc6097192002-11-03 00:24:07 +0000466
wdenk4b248f32004-03-14 16:51:43 +0000467 case GDF_15BIT_555RGB:
468 while (count--) {
469 c = *s;
470 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
471 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000472 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000473 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000474
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000475 ((u32 *) dest)[0] =
476 SHORTSWAP32((video_font_draw_table15
477 [bits >> 6] & eorx) ^
478 bgx);
479 ((u32 *) dest)[1] =
480 SHORTSWAP32((video_font_draw_table15
481 [bits >> 4 & 3] & eorx) ^
482 bgx);
483 ((u32 *) dest)[2] =
484 SHORTSWAP32((video_font_draw_table15
485 [bits >> 2 & 3] & eorx) ^
486 bgx);
487 ((u32 *) dest)[3] =
488 SHORTSWAP32((video_font_draw_table15
489 [bits & 3] & eorx) ^
490 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000491 }
492 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
493 s++;
494 }
495 break;
wdenkc6097192002-11-03 00:24:07 +0000496
wdenk4b248f32004-03-14 16:51:43 +0000497 case GDF_16BIT_565RGB:
498 while (count--) {
499 c = *s;
500 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
501 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000502 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000503 u8 bits = *cdat++;
504
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000505 ((u32 *) dest)[0] =
506 SHORTSWAP32((video_font_draw_table16
507 [bits >> 6] & eorx) ^
508 bgx);
509 ((u32 *) dest)[1] =
510 SHORTSWAP32((video_font_draw_table16
511 [bits >> 4 & 3] & eorx) ^
512 bgx);
513 ((u32 *) dest)[2] =
514 SHORTSWAP32((video_font_draw_table16
515 [bits >> 2 & 3] & eorx) ^
516 bgx);
517 ((u32 *) dest)[3] =
518 SHORTSWAP32((video_font_draw_table16
519 [bits & 3] & eorx) ^
520 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000521 }
522 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
523 s++;
524 }
525 break;
526
527 case GDF_32BIT_X888RGB:
528 while (count--) {
529 c = *s;
530 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
531 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000532 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000533 u8 bits = *cdat++;
534
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000535 ((u32 *) dest)[0] =
536 SWAP32((video_font_draw_table32
537 [bits >> 4][0] & eorx) ^ bgx);
538 ((u32 *) dest)[1] =
539 SWAP32((video_font_draw_table32
540 [bits >> 4][1] & eorx) ^ bgx);
541 ((u32 *) dest)[2] =
542 SWAP32((video_font_draw_table32
543 [bits >> 4][2] & eorx) ^ bgx);
544 ((u32 *) dest)[3] =
545 SWAP32((video_font_draw_table32
546 [bits >> 4][3] & eorx) ^ bgx);
547 ((u32 *) dest)[4] =
548 SWAP32((video_font_draw_table32
549 [bits & 15][0] & eorx) ^ bgx);
550 ((u32 *) dest)[5] =
551 SWAP32((video_font_draw_table32
552 [bits & 15][1] & eorx) ^ bgx);
553 ((u32 *) dest)[6] =
554 SWAP32((video_font_draw_table32
555 [bits & 15][2] & eorx) ^ bgx);
556 ((u32 *) dest)[7] =
557 SWAP32((video_font_draw_table32
558 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000559 }
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200560 if (cfb_do_flush_cache)
561 flush_cache((ulong)dest0, 32);
wdenk4b248f32004-03-14 16:51:43 +0000562 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
563 s++;
564 }
565 break;
566
567 case GDF_24BIT_888RGB:
568 while (count--) {
569 c = *s;
570 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
571 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000572 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000573 u8 bits = *cdat++;
574
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000575 ((u32 *) dest)[0] =
576 (video_font_draw_table24[bits >> 4][0]
577 & eorx) ^ bgx;
578 ((u32 *) dest)[1] =
579 (video_font_draw_table24[bits >> 4][1]
580 & eorx) ^ bgx;
581 ((u32 *) dest)[2] =
582 (video_font_draw_table24[bits >> 4][2]
583 & eorx) ^ bgx;
584 ((u32 *) dest)[3] =
585 (video_font_draw_table24[bits & 15][0]
586 & eorx) ^ bgx;
587 ((u32 *) dest)[4] =
588 (video_font_draw_table24[bits & 15][1]
589 & eorx) ^ bgx;
590 ((u32 *) dest)[5] =
591 (video_font_draw_table24[bits & 15][2]
592 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000593 }
594 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
595 s++;
596 }
597 break;
wdenk8bde7f72003-06-27 21:31:46 +0000598 }
wdenkc6097192002-11-03 00:24:07 +0000599}
600
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000601static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000602{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000603 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000604}
605
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000606static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000607{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000608 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000609}
610
wdenkc6097192002-11-03 00:24:07 +0000611#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000612static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000613{
Gabe Black03d31fc2011-11-30 13:50:50 +0000614 if (cursor_state)
615 console_cursor(0);
616 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000617}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000618
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000619static void video_invertchar(int xx, int yy)
620{
621 int firstx = xx * VIDEO_PIXEL_SIZE;
622 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
623 int firsty = yy * VIDEO_LINE_LEN;
624 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
625 int x, y;
626 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
627 for (x = firstx; x < lastx; x++) {
628 u8 *dest = (u8 *)(video_fb_address) + x + y;
629 *dest = ~*dest;
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200630 if (cfb_do_flush_cache)
631 flush_cache((ulong)dest, 4);
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000632 }
633 }
634}
Gabe Black03d31fc2011-11-30 13:50:50 +0000635
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000636void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000637{
wdenkc6097192002-11-03 00:24:07 +0000638#ifdef CONFIG_CONSOLE_TIME
wdenk4b248f32004-03-14 16:51:43 +0000639 struct rtc_time tm;
640 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000641
wdenk4b248f32004-03-14 16:51:43 +0000642 /* time update only if cursor is on (faster scroll) */
643 if (state) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000644 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000645
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000646 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
647 tm.tm_sec);
648 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
649 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000650
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000651 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
652 tm.tm_year);
653 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
654 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
655 (uchar *) info);
wdenk4b248f32004-03-14 16:51:43 +0000656 }
wdenkc6097192002-11-03 00:24:07 +0000657#endif
658
Gabe Black03d31fc2011-11-30 13:50:50 +0000659 if (cursor_state != state) {
660 if (cursor_state) {
661 /* turn off the cursor */
662 video_invertchar(old_col * VIDEO_FONT_WIDTH,
663 old_row * VIDEO_FONT_HEIGHT +
664 video_logo_height);
665 } else {
666 /* turn off the cursor and record where it is */
667 video_invertchar(console_col * VIDEO_FONT_WIDTH,
668 console_row * VIDEO_FONT_HEIGHT +
669 video_logo_height);
670 old_col = console_col;
671 old_row = console_row;
672 }
673 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000674 }
wdenkc6097192002-11-03 00:24:07 +0000675}
676#endif
677
wdenkc6097192002-11-03 00:24:07 +0000678#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000679static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000680{
wdenk4b248f32004-03-14 16:51:43 +0000681 while (c--)
682 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000683}
684#endif
685
wdenkc6097192002-11-03 00:24:07 +0000686#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000687static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000688{
wdenk4b248f32004-03-14 16:51:43 +0000689 while (c--)
690 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000691}
692#endif
693
Pali Rohár90f60a82012-04-28 07:26:44 +0000694static void console_clear_line(int line, int begin, int end)
695{
696#ifdef VIDEO_HW_RECTFILL
697 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
698 VIDEO_FONT_WIDTH * begin, /* dest pos x */
699 video_logo_height +
700 VIDEO_FONT_HEIGHT * line, /* dest pos y */
701 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
702 VIDEO_FONT_HEIGHT, /* frame height */
703 bgx /* fill color */
704 );
705#else
706 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
707 memsetl(CONSOLE_ROW_FIRST +
708 CONSOLE_ROW_SIZE * line, /* offset of row */
709 CONSOLE_ROW_SIZE >> 2, /* length of row */
710 bgx /* fill color */
711 );
712 } else {
713 void *offset;
714 int i, size;
715
716 offset = CONSOLE_ROW_FIRST +
717 CONSOLE_ROW_SIZE * line + /* offset of row */
718 VIDEO_FONT_WIDTH *
719 VIDEO_PIXEL_SIZE * begin; /* offset of col */
720 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
721 size >>= 2; /* length to end for memsetl() */
722 /* fill at col offset of i'th line using bgx as fill color */
723 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
724 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
725 }
726#endif
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200727 if (cfb_do_flush_cache)
728 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
Pali Rohár90f60a82012-04-28 07:26:44 +0000729}
730
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000731static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000732{
wdenk4b248f32004-03-14 16:51:43 +0000733 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000734
735#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000736 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
737 0, /* source pos x */
738 video_logo_height +
739 VIDEO_FONT_HEIGHT, /* source pos y */
740 0, /* dest pos x */
741 video_logo_height, /* dest pos y */
742 VIDEO_VISIBLE_COLS, /* frame width */
743 VIDEO_VISIBLE_ROWS
744 - video_logo_height
745 - VIDEO_FONT_HEIGHT /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000746 );
wdenkc6097192002-11-03 00:24:07 +0000747#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000748 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
749 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000750#endif
wdenk4b248f32004-03-14 16:51:43 +0000751 /* clear the last one */
Pali Rohár90f60a82012-04-28 07:26:44 +0000752 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
wdenkc6097192002-11-03 00:24:07 +0000753}
754
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000755static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000756{
Timur Tabi65618632010-08-27 15:45:47 -0500757 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000758
wdenk4b248f32004-03-14 16:51:43 +0000759 if (console_col < 0) {
760 console_col = CONSOLE_COLS - 1;
761 console_row--;
762 if (console_row < 0)
763 console_row = 0;
764 }
wdenkc6097192002-11-03 00:24:07 +0000765}
766
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000767static void console_newline(void)
wdenkc6097192002-11-03 00:24:07 +0000768{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100769 console_row++;
wdenk4b248f32004-03-14 16:51:43 +0000770 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000771
wdenk4b248f32004-03-14 16:51:43 +0000772 /* Check if we need to scroll the terminal */
773 if (console_row >= CONSOLE_ROWS) {
774 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000775 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000776
wdenk4b248f32004-03-14 16:51:43 +0000777 /* Decrement row number */
778 console_row--;
779 }
wdenkc6097192002-11-03 00:24:07 +0000780}
781
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000782static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100783{
Timur Tabi65618632010-08-27 15:45:47 -0500784 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100785}
786
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000787void video_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000788{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100789 static int nl = 1;
790
Gabe Black03d31fc2011-11-30 13:50:50 +0000791 CURSOR_OFF;
792
wdenk4b248f32004-03-14 16:51:43 +0000793 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100794 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000795 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000796 break;
wdenkc6097192002-11-03 00:24:07 +0000797
wdenk4b248f32004-03-14 16:51:43 +0000798 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100799 if (console_col || (!console_col && nl))
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000800 console_newline();
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100801 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000802 break;
wdenkc6097192002-11-03 00:24:07 +0000803
wdenk4b248f32004-03-14 16:51:43 +0000804 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500805 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000806 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000807
wdenk4b248f32004-03-14 16:51:43 +0000808 if (console_col >= CONSOLE_COLS)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000809 console_newline();
wdenk4b248f32004-03-14 16:51:43 +0000810 break;
wdenkc6097192002-11-03 00:24:07 +0000811
wdenk4b248f32004-03-14 16:51:43 +0000812 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000813 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000814 break;
wdenkc6097192002-11-03 00:24:07 +0000815
Pali Rohár24fe06c2012-04-28 07:26:47 +0000816 case 7: /* bell */
817 break; /* ignored */
818
wdenk4b248f32004-03-14 16:51:43 +0000819 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000820 video_putchar(console_col * VIDEO_FONT_WIDTH,
821 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000822 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000823
wdenk4b248f32004-03-14 16:51:43 +0000824 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100825 if (console_col >= CONSOLE_COLS) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000826 console_newline();
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100827 nl = 0;
828 }
wdenk4b248f32004-03-14 16:51:43 +0000829 }
Timur Tabi65618632010-08-27 15:45:47 -0500830 CURSOR_SET;
831}
wdenkc6097192002-11-03 00:24:07 +0000832
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000833void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +0000834{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000835 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +0000836
wdenk4b248f32004-03-14 16:51:43 +0000837 while (count--)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000838 video_putc(*s++);
wdenkc6097192002-11-03 00:24:07 +0000839}
840
Anatolij Gustschin10543822010-05-01 22:21:09 +0200841/*
842 * Do not enforce drivers (or board code) to provide empty
843 * video_set_lut() if they do not support 8 bpp format.
844 * Implement weak default function instead.
845 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000846void __video_set_lut(unsigned int index, unsigned char r,
847 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +0200848{
849}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000850
851void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
852 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschin10543822010-05-01 22:21:09 +0200853
Jon Loeliger07d38a12007-07-09 17:30:01 -0500854#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000855
856#define FILL_8BIT_332RGB(r,g,b) { \
857 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
858 fb ++; \
859}
860
861#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000862 *(unsigned short *)fb = \
863 SWAP16((unsigned short)(((r>>3)<<10) | \
864 ((g>>3)<<5) | \
865 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +0000866 fb += 2; \
867}
868
869#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000870 *(unsigned short *)fb = \
871 SWAP16((unsigned short)((((r)>>3)<<11)| \
872 (((g)>>2)<<5) | \
873 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +0000874 fb += 2; \
875}
876
877#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000878 *(unsigned long *)fb = \
879 SWAP32((unsigned long)(((r<<16) | \
880 (g<<8) | \
881 b))); \
wdenk4b248f32004-03-14 16:51:43 +0000882 fb += 4; \
883}
884
885#ifdef VIDEO_FB_LITTLE_ENDIAN
886#define FILL_24BIT_888RGB(r,g,b) { \
887 fb[0] = b; \
888 fb[1] = g; \
889 fb[2] = r; \
890 fb += 3; \
891}
892#else
893#define FILL_24BIT_888RGB(r,g,b) { \
894 fb[0] = r; \
895 fb[1] = g; \
896 fb[2] = b; \
897 fb += 3; \
898}
899#endif
900
Anatolij Gustschine84d5682008-08-08 18:00:40 +0200901#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000902static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +0200903{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000904 ushort *dst = (ushort *) fb;
905 ushort color = (ushort) (((r >> 3) << 10) |
906 ((g >> 3) << 5) |
907 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +0200908 if (x & 1)
909 *(--dst) = color;
910 else
911 *(++dst) = color;
912}
913#endif
wdenk4b248f32004-03-14 16:51:43 +0000914
915/*
Anatolij Gustschind5011762010-03-15 14:50:25 +0100916 * RLE8 bitmap support
917 */
918
919#ifdef CONFIG_VIDEO_BMP_RLE8
920/* Pre-calculated color table entry */
921struct palette {
922 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000923 unsigned short w; /* word */
924 unsigned int dw; /* double word */
925 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +0100926};
927
928/*
929 * Helper to draw encoded/unencoded run.
930 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000931static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
932 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +0100933{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000934 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100935 int *off;
936 int enc_off = 1;
937 int i;
938
939 /*
940 * Setup offset of the color index in the bitmap.
941 * Color index of encoded run is at offset 1.
942 */
943 off = enc ? &enc_off : &i;
944
945 switch (VIDEO_DATA_FORMAT) {
946 case GDF__8BIT_INDEX:
947 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000948 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +0100949 break;
950 case GDF_15BIT_555RGB:
951 case GDF_16BIT_565RGB:
952 /* differences handled while pre-calculating palette */
953 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000954 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100955 addr += 2;
956 }
957 break;
958 case GDF_32BIT_X888RGB:
959 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000960 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100961 addr += 4;
962 }
963 break;
964 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000965 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +0100966}
967
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000968static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
969 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +0100970{
971 unsigned char *bm;
972 unsigned char *fbp;
973 unsigned int cnt, runlen;
974 int decode = 1;
975 int x, y, bpp, i, ncolors;
976 struct palette p[256];
977 bmp_color_table_entry_t cte;
978 int green_shift, red_off;
Anatolij Gustschin74446b62011-02-21 21:33:29 +0100979 int limit = VIDEO_COLS * VIDEO_ROWS;
980 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100981
982 x = 0;
983 y = __le32_to_cpu(img->header.height) - 1;
984 ncolors = __le32_to_cpu(img->header.colors_used);
985 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000986 fbp = (unsigned char *) ((unsigned int) video_fb_address +
987 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100988
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000989 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100990
991 /* pre-calculate and setup palette */
992 switch (VIDEO_DATA_FORMAT) {
993 case GDF__8BIT_INDEX:
994 for (i = 0; i < ncolors; i++) {
995 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000996 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100997 }
998 break;
999 case GDF_15BIT_555RGB:
1000 case GDF_16BIT_565RGB:
1001 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1002 green_shift = 3;
1003 red_off = 10;
1004 } else {
1005 green_shift = 2;
1006 red_off = 11;
1007 }
1008 for (i = 0; i < ncolors; i++) {
1009 cte = img->color_table[i];
1010 p[i].ce.w = SWAP16((unsigned short)
1011 (((cte.red >> 3) << red_off) |
1012 ((cte.green >> green_shift) << 5) |
1013 cte.blue >> 3));
1014 }
1015 break;
1016 case GDF_32BIT_X888RGB:
1017 for (i = 0; i < ncolors; i++) {
1018 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001019 p[i].ce.dw = SWAP32((cte.red << 16) |
1020 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001021 cte.blue);
1022 }
1023 break;
1024 default:
1025 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001026 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001027 return -1;
1028 }
1029
1030 while (decode) {
1031 switch (bm[0]) {
1032 case 0:
1033 switch (bm[1]) {
1034 case 0:
1035 /* scan line end marker */
1036 bm += 2;
1037 x = 0;
1038 y--;
1039 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001040 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001041 (((y + yoff) * VIDEO_COLS) +
1042 xoff) * bpp);
1043 continue;
1044 case 1:
1045 /* end of bitmap data marker */
1046 decode = 0;
1047 break;
1048 case 2:
1049 /* run offset marker */
1050 x += bm[2];
1051 y -= bm[3];
1052 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001053 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001054 (((y + yoff) * VIDEO_COLS) +
1055 x + xoff) * bpp);
1056 bm += 4;
1057 break;
1058 default:
1059 /* unencoded run */
1060 cnt = bm[1];
1061 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001062 pixels += cnt;
1063 if (pixels > limit)
1064 goto error;
1065
Anatolij Gustschind5011762010-03-15 14:50:25 +01001066 bm += 2;
1067 if (y < height) {
1068 if (x >= width) {
1069 x += runlen;
1070 goto next_run;
1071 }
1072 if (x + runlen > width)
1073 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001074 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001075 x += runlen;
1076 }
1077next_run:
1078 bm += runlen;
1079 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001080 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001081 }
1082 break;
1083 default:
1084 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001085 cnt = bm[0];
1086 runlen = cnt;
1087 pixels += cnt;
1088 if (pixels > limit)
1089 goto error;
1090
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001091 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001092 if (x >= width) {
1093 x += runlen;
1094 bm += 2;
1095 continue;
1096 }
1097 if (x + runlen > width)
1098 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001099 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001100 x += runlen;
1101 }
1102 bm += 2;
1103 break;
1104 }
1105 }
1106 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001107error:
1108 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1109 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001110}
1111#endif
1112
1113/*
wdenk4b248f32004-03-14 16:51:43 +00001114 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001115 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001116int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001117{
1118 ushort xcount, ycount;
1119 uchar *fb;
1120 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1121 uchar *bmap;
1122 ushort padded_line;
1123 unsigned long width, height, bpp;
1124 unsigned colors;
1125 unsigned long compression;
1126 bmp_color_table_entry_t cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001127
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001128#ifdef CONFIG_VIDEO_BMP_GZIP
1129 unsigned char *dst = NULL;
1130 ulong len;
1131#endif
wdenk4b248f32004-03-14 16:51:43 +00001132
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001133 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001134
1135 if (!((bmp->header.signature[0] == 'B') &&
1136 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001137
1138#ifdef CONFIG_VIDEO_BMP_GZIP
1139 /*
1140 * Could be a gzipped bmp image, try to decrompress...
1141 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001142 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1143 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001144 if (dst == NULL) {
1145 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001146 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001147 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001148 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1149 (uchar *) bmp_image,
1150 &len) != 0) {
1151 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1152 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001153 free(dst);
1154 return 1;
1155 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001156 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001157 printf("Image could be truncated "
1158 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001159 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001160
1161 /*
1162 * Set addr to decompressed image
1163 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001164 bmp = (bmp_image_t *) dst;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001165
1166 if (!((bmp->header.signature[0] == 'B') &&
1167 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001168 printf("Error: no valid bmp.gz image at %lx\n",
1169 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001170 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001171 return 1;
1172 }
1173#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001174 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001175 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001176#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001177 }
1178
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001179 width = le32_to_cpu(bmp->header.width);
1180 height = le32_to_cpu(bmp->header.height);
1181 bpp = le16_to_cpu(bmp->header.bit_count);
1182 colors = le32_to_cpu(bmp->header.colors_used);
1183 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001184
Marek Vasut68da5b12011-10-21 14:17:04 +00001185 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001186 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001187
Anatolij Gustschind5011762010-03-15 14:50:25 +01001188 if (compression != BMP_BI_RGB
1189#ifdef CONFIG_VIDEO_BMP_RLE8
1190 && compression != BMP_BI_RLE8
1191#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001192 ) {
1193 printf("Error: compression type %ld not supported\n",
1194 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001195#ifdef CONFIG_VIDEO_BMP_GZIP
1196 if (dst)
1197 free(dst);
1198#endif
wdenk4b248f32004-03-14 16:51:43 +00001199 return 1;
1200 }
1201
1202 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1203
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001204#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1205 if (x == BMP_ALIGN_CENTER)
1206 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1207 else if (x < 0)
1208 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1209
1210 if (y == BMP_ALIGN_CENTER)
1211 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1212 else if (y < 0)
1213 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1214#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1215
wdenk4b248f32004-03-14 16:51:43 +00001216 if ((x + width) > VIDEO_VISIBLE_COLS)
1217 width = VIDEO_VISIBLE_COLS - x;
1218 if ((y + height) > VIDEO_VISIBLE_ROWS)
1219 height = VIDEO_VISIBLE_ROWS - y;
1220
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001221 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001222 fb = (uchar *) (video_fb_address +
1223 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1224 x * VIDEO_PIXEL_SIZE);
1225
Anatolij Gustschind5011762010-03-15 14:50:25 +01001226#ifdef CONFIG_VIDEO_BMP_RLE8
1227 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001228 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001229 }
1230#endif
1231
Timur Tabi68f66182010-08-23 16:58:00 -05001232 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001233 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001234 case 4:
1235 padded_line -= width / 2;
1236 ycount = height;
1237
1238 switch (VIDEO_DATA_FORMAT) {
1239 case GDF_32BIT_X888RGB:
1240 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001241 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001242 /*
1243 * Don't assume that 'width' is an
1244 * even number
1245 */
1246 for (xcount = 0; xcount < width; xcount++) {
1247 uchar idx;
1248
1249 if (xcount & 1) {
1250 idx = *bmap & 0xF;
1251 bmap++;
1252 } else
1253 idx = *bmap >> 4;
1254 cte = bmp->color_table[idx];
1255 FILL_32BIT_X888RGB(cte.red, cte.green,
1256 cte.blue);
1257 }
1258 bmap += padded_line;
1259 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001260 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001261 }
1262 break;
1263 default:
1264 puts("4bpp bitmap unsupported with current "
1265 "video mode\n");
1266 break;
1267 }
1268 break;
1269
wdenk4b248f32004-03-14 16:51:43 +00001270 case 8:
1271 padded_line -= width;
1272 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001273 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001274 for (xcount = 0; xcount < colors; ++xcount) {
1275 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001276 video_set_lut(xcount, cte.red, cte.green,
1277 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001278 }
1279 }
1280 ycount = height;
1281 switch (VIDEO_DATA_FORMAT) {
1282 case GDF__8BIT_INDEX:
1283 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001284 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001285 xcount = width;
1286 while (xcount--) {
1287 *fb++ = *bmap++;
1288 }
1289 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001290 fb -= (VIDEO_VISIBLE_COLS + width) *
1291 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001292 }
1293 break;
1294 case GDF__8BIT_332RGB:
1295 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001296 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001297 xcount = width;
1298 while (xcount--) {
1299 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001300 FILL_8BIT_332RGB(cte.red, cte.green,
1301 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001302 }
1303 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001304 fb -= (VIDEO_VISIBLE_COLS + width) *
1305 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001306 }
1307 break;
1308 case GDF_15BIT_555RGB:
1309 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001310#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1311 int xpos = x;
1312#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001313 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001314 xcount = width;
1315 while (xcount--) {
1316 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001317#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001318 fill_555rgb_pswap(fb, xpos++, cte.red,
1319 cte.green,
1320 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001321 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001322#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001323 FILL_15BIT_555RGB(cte.red, cte.green,
1324 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001325#endif
wdenk4b248f32004-03-14 16:51:43 +00001326 }
1327 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001328 fb -= (VIDEO_VISIBLE_COLS + width) *
1329 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001330 }
1331 break;
1332 case GDF_16BIT_565RGB:
1333 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001334 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001335 xcount = width;
1336 while (xcount--) {
1337 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001338 FILL_16BIT_565RGB(cte.red, cte.green,
1339 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001340 }
1341 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001342 fb -= (VIDEO_VISIBLE_COLS + width) *
1343 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001344 }
1345 break;
1346 case GDF_32BIT_X888RGB:
1347 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001348 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001349 xcount = width;
1350 while (xcount--) {
1351 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001352 FILL_32BIT_X888RGB(cte.red, cte.green,
1353 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001354 }
1355 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001356 fb -= (VIDEO_VISIBLE_COLS + width) *
1357 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001358 }
1359 break;
1360 case GDF_24BIT_888RGB:
1361 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001362 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001363 xcount = width;
1364 while (xcount--) {
1365 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001366 FILL_24BIT_888RGB(cte.red, cte.green,
1367 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001368 }
1369 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001370 fb -= (VIDEO_VISIBLE_COLS + width) *
1371 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001372 }
1373 break;
1374 }
1375 break;
1376 case 24:
1377 padded_line -= 3 * width;
1378 ycount = height;
1379 switch (VIDEO_DATA_FORMAT) {
1380 case GDF__8BIT_332RGB:
1381 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001382 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001383 xcount = width;
1384 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001385 FILL_8BIT_332RGB(bmap[2], bmap[1],
1386 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001387 bmap += 3;
1388 }
1389 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001390 fb -= (VIDEO_VISIBLE_COLS + width) *
1391 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001392 }
1393 break;
1394 case GDF_15BIT_555RGB:
1395 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001396#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1397 int xpos = x;
1398#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001399 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001400 xcount = width;
1401 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001402#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001403 fill_555rgb_pswap(fb, xpos++, bmap[2],
1404 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001405 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001406#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001407 FILL_15BIT_555RGB(bmap[2], bmap[1],
1408 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001409#endif
wdenk4b248f32004-03-14 16:51:43 +00001410 bmap += 3;
1411 }
1412 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001413 fb -= (VIDEO_VISIBLE_COLS + width) *
1414 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001415 }
1416 break;
1417 case GDF_16BIT_565RGB:
1418 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001419 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001420 xcount = width;
1421 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001422 FILL_16BIT_565RGB(bmap[2], bmap[1],
1423 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001424 bmap += 3;
1425 }
1426 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001427 fb -= (VIDEO_VISIBLE_COLS + width) *
1428 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001429 }
1430 break;
1431 case GDF_32BIT_X888RGB:
1432 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001433 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001434 xcount = width;
1435 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001436 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1437 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001438 bmap += 3;
1439 }
1440 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001441 fb -= (VIDEO_VISIBLE_COLS + width) *
1442 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001443 }
1444 break;
1445 case GDF_24BIT_888RGB:
1446 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001447 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001448 xcount = width;
1449 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001450 FILL_24BIT_888RGB(bmap[2], bmap[1],
1451 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001452 bmap += 3;
1453 }
1454 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001455 fb -= (VIDEO_VISIBLE_COLS + width) *
1456 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001457 }
1458 break;
1459 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001460 printf("Error: 24 bits/pixel bitmap incompatible "
1461 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001462 break;
1463 }
1464 break;
1465 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001466 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1467 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001468 break;
1469 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001470
1471#ifdef CONFIG_VIDEO_BMP_GZIP
1472 if (dst) {
1473 free(dst);
1474 }
1475#endif
1476
wdenk4b248f32004-03-14 16:51:43 +00001477 return (0);
1478}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001479#endif
wdenk4b248f32004-03-14 16:51:43 +00001480
wdenk4b248f32004-03-14 16:51:43 +00001481
wdenkc6097192002-11-03 00:24:07 +00001482#ifdef CONFIG_VIDEO_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001483void logo_plot(void *screen, int width, int x, int y)
wdenkc6097192002-11-03 00:24:07 +00001484{
wdenkc6097192002-11-03 00:24:07 +00001485
wdenk4b248f32004-03-14 16:51:43 +00001486 int xcount, i;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001487 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001488 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001489 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1490 unsigned char *source;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001491 unsigned char *dest = (unsigned char *) screen +
1492 ((y * width * VIDEO_PIXEL_SIZE) + x * VIDEO_PIXEL_SIZE);
wdenka6c7ad22002-12-03 21:28:10 +00001493
1494#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001495 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001496
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001497 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001498 logo_red = malloc(BMP_LOGO_COLORS);
1499 logo_green = malloc(BMP_LOGO_COLORS);
1500 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001501 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001502 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1503 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1504 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1505 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1506 }
wdenka6c7ad22002-12-03 21:28:10 +00001507#else
wdenk4b248f32004-03-14 16:51:43 +00001508 source = linux_logo;
1509 logo_red = linux_logo_red;
1510 logo_green = linux_logo_green;
1511 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001512#endif
wdenk8bde7f72003-06-27 21:31:46 +00001513
wdenk4b248f32004-03-14 16:51:43 +00001514 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1515 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001516 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1517 logo_red[i], logo_green[i],
1518 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001519 }
wdenk8bde7f72003-06-27 21:31:46 +00001520 }
wdenkc6097192002-11-03 00:24:07 +00001521
wdenk4b248f32004-03-14 16:51:43 +00001522 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001523#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1524 int xpos = x;
1525#endif
wdenk4b248f32004-03-14 16:51:43 +00001526 xcount = VIDEO_LOGO_WIDTH;
1527 while (xcount--) {
1528 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1529 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1530 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
wdenk8bde7f72003-06-27 21:31:46 +00001531
wdenk4b248f32004-03-14 16:51:43 +00001532 switch (VIDEO_DATA_FORMAT) {
1533 case GDF__8BIT_INDEX:
1534 *dest = *source;
1535 break;
1536 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001537 *dest = ((r >> 5) << 5) |
1538 ((g >> 5) << 2) |
1539 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001540 break;
1541 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001542#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001543 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001544#else
wdenk4b248f32004-03-14 16:51:43 +00001545 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001546 SWAP16((unsigned short) (
1547 ((r >> 3) << 10) |
1548 ((g >> 3) << 5) |
1549 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001550#endif
wdenk4b248f32004-03-14 16:51:43 +00001551 break;
1552 case GDF_16BIT_565RGB:
1553 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001554 SWAP16((unsigned short) (
1555 ((r >> 3) << 11) |
1556 ((g >> 2) << 5) |
1557 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001558 break;
1559 case GDF_32BIT_X888RGB:
1560 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001561 SWAP32((unsigned long) (
1562 (r << 16) |
1563 (g << 8) |
1564 b));
wdenk4b248f32004-03-14 16:51:43 +00001565 break;
1566 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001567#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001568 dest[0] = b;
1569 dest[1] = g;
1570 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001571#else
wdenk4b248f32004-03-14 16:51:43 +00001572 dest[0] = r;
1573 dest[1] = g;
1574 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001575#endif
wdenk4b248f32004-03-14 16:51:43 +00001576 break;
1577 }
1578 source++;
1579 dest += VIDEO_PIXEL_SIZE;
1580 }
1581 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001582 }
wdenka6c7ad22002-12-03 21:28:10 +00001583#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001584 free(logo_red);
1585 free(logo_green);
1586 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001587#endif
wdenkc6097192002-11-03 00:24:07 +00001588}
1589
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001590static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001591{
wdenk4b248f32004-03-14 16:51:43 +00001592 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001593 int space, len;
1594 __maybe_unused int y_off = 0;
wdenkc6097192002-11-03 00:24:07 +00001595
wdenk4b248f32004-03-14 16:51:43 +00001596#ifdef CONFIG_SPLASH_SCREEN
1597 char *s;
1598 ulong addr;
wdenkc6097192002-11-03 00:24:07 +00001599
Wolfgang Denk57912932011-07-30 12:48:09 +00001600 s = getenv("splashimage");
1601 if (s != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001602 int x = 0, y = 0;
wdenk4b248f32004-03-14 16:51:43 +00001603
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001604 addr = simple_strtoul(s, NULL, 16);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001605#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Wolfgang Denk57912932011-07-30 12:48:09 +00001606 s = getenv("splashpos");
1607 if (s != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001608 if (s[0] == 'm')
1609 x = BMP_ALIGN_CENTER;
1610 else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001611 x = simple_strtol(s, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001612
Wolfgang Denk57912932011-07-30 12:48:09 +00001613 s = strchr(s + 1, ',');
1614 if (s != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001615 if (s[1] == 'm')
1616 y = BMP_ALIGN_CENTER;
1617 else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001618 y = simple_strtol(s + 1, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001619 }
1620 }
1621#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1622
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001623 if (video_display_bitmap(addr, x, y) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001624 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00001625 return ((void *) (video_fb_address));
1626 }
1627 }
1628#endif /* CONFIG_SPLASH_SCREEN */
1629
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001630 logo_plot(video_fb_address, VIDEO_COLS, 0, 0);
wdenk4b248f32004-03-14 16:51:43 +00001631
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001632 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001633
1634 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1635 len = strlen(info);
1636
1637 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001638 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1639 (uchar *) info, space);
1640 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1641 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1642 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001643 y_off = 1;
1644 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001645 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001646
1647#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00001648 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001649 int i, n =
1650 ((video_logo_height -
1651 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001652
wdenk4b248f32004-03-14 16:51:43 +00001653 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001654 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001655 if (!*info)
1656 continue;
1657
1658 len = strlen(info);
1659 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001660 video_drawchars(VIDEO_INFO_X,
1661 VIDEO_INFO_Y +
1662 (i + y_off) *
1663 VIDEO_FONT_HEIGHT,
1664 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001665 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001666 video_drawchars(VIDEO_INFO_X +
1667 VIDEO_FONT_WIDTH,
1668 VIDEO_INFO_Y +
1669 (i + y_off) *
1670 VIDEO_FONT_HEIGHT,
1671 (uchar *) info + space,
1672 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001673 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001674 video_drawstring(VIDEO_INFO_X,
1675 VIDEO_INFO_Y +
1676 (i + y_off) *
1677 VIDEO_FONT_HEIGHT,
1678 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001679 }
wdenk4b248f32004-03-14 16:51:43 +00001680 }
1681 }
wdenkc6097192002-11-03 00:24:07 +00001682#endif
1683
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001684 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001685}
1686#endif
1687
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001688static int cfb_fb_is_in_dram(void)
1689{
1690 bd_t *bd = gd->bd;
1691#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1692defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1693 ulong start, end;
1694 int i;
1695
1696 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1697 start = bd->bi_dram[i].start;
1698 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1699 if ((ulong)video_fb_address >= start &&
1700 (ulong)video_fb_address < end)
1701 return 1;
1702 }
1703#else
1704 if ((ulong)video_fb_address >= bd->bi_memstart &&
1705 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1706 return 1;
1707#endif
1708 return 0;
1709}
1710
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001711static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001712{
wdenk4b248f32004-03-14 16:51:43 +00001713 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001714
Wolfgang Denk57912932011-07-30 12:48:09 +00001715 pGD = video_hw_init();
1716 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00001717 return -1;
wdenkc6097192002-11-03 00:24:07 +00001718
wdenk4b248f32004-03-14 16:51:43 +00001719 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001720#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001721 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001722#endif
1723
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001724 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
1725
wdenk4b248f32004-03-14 16:51:43 +00001726 /* Init drawing pats */
1727 switch (VIDEO_DATA_FORMAT) {
1728 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001729 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
1730 CONSOLE_FG_COL);
1731 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1732 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00001733 fgx = 0x01010101;
1734 bgx = 0x00000000;
1735 break;
1736 case GDF__8BIT_332RGB:
1737 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001738 ((CONSOLE_FG_COL >> 3) & 0x1c) |
1739 CONSOLE_FG_COL >> 6);
1740 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1741 color8;
wdenk4b248f32004-03-14 16:51:43 +00001742 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001743 ((CONSOLE_BG_COL >> 3) & 0x1c) |
1744 CONSOLE_BG_COL >> 6);
1745 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1746 color8;
wdenk4b248f32004-03-14 16:51:43 +00001747 break;
1748 case GDF_15BIT_555RGB:
1749 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001750 ((CONSOLE_FG_COL >> 3) << 21) |
1751 ((CONSOLE_FG_COL >> 3) << 16) |
1752 ((CONSOLE_FG_COL >> 3) << 10) |
1753 ((CONSOLE_FG_COL >> 3) << 5) |
1754 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001755 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001756 ((CONSOLE_BG_COL >> 3) << 21) |
1757 ((CONSOLE_BG_COL >> 3) << 16) |
1758 ((CONSOLE_BG_COL >> 3) << 10) |
1759 ((CONSOLE_BG_COL >> 3) << 5) |
1760 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001761 break;
1762 case GDF_16BIT_565RGB:
1763 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001764 ((CONSOLE_FG_COL >> 2) << 21) |
1765 ((CONSOLE_FG_COL >> 3) << 16) |
1766 ((CONSOLE_FG_COL >> 3) << 11) |
1767 ((CONSOLE_FG_COL >> 2) << 5) |
1768 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001769 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001770 ((CONSOLE_BG_COL >> 2) << 21) |
1771 ((CONSOLE_BG_COL >> 3) << 16) |
1772 ((CONSOLE_BG_COL >> 3) << 11) |
1773 ((CONSOLE_BG_COL >> 2) << 5) |
1774 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001775 break;
1776 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001777 fgx = (CONSOLE_FG_COL << 16) |
1778 (CONSOLE_FG_COL << 8) |
1779 CONSOLE_FG_COL;
1780 bgx = (CONSOLE_BG_COL << 16) |
1781 (CONSOLE_BG_COL << 8) |
1782 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001783 break;
1784 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001785 fgx = (CONSOLE_FG_COL << 24) |
1786 (CONSOLE_FG_COL << 16) |
1787 (CONSOLE_FG_COL << 8) |
1788 CONSOLE_FG_COL;
1789 bgx = (CONSOLE_BG_COL << 24) |
1790 (CONSOLE_BG_COL << 16) |
1791 (CONSOLE_BG_COL << 8) |
1792 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001793 break;
1794 }
1795 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001796
1797#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001798 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00001799 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001800 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00001801#else
wdenk4b248f32004-03-14 16:51:43 +00001802 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001803#endif
1804
wdenk4b248f32004-03-14 16:51:43 +00001805 /* Initialize the console */
1806 console_col = 0;
1807 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001808
wdenk4b248f32004-03-14 16:51:43 +00001809 return 0;
wdenkc6097192002-11-03 00:24:07 +00001810}
1811
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001812/*
1813 * Implement a weak default function for boards that optionally
1814 * need to skip the video initialization.
1815 */
1816int __board_video_skip(void)
1817{
1818 /* As default, don't skip test */
1819 return 0;
1820}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001821
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001822int board_video_skip(void)
1823 __attribute__ ((weak, alias("__board_video_skip")));
1824
1825int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001826{
wdenk4b248f32004-03-14 16:51:43 +00001827 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02001828 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00001829
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001830 /* Check if video initialization should be skipped */
1831 if (board_video_skip())
1832 return 0;
1833
wdenk81050922004-07-11 20:04:51 +00001834 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001835 skip_dev_init = (video_init() == -1);
wdenk81050922004-07-11 20:04:51 +00001836
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001837#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk72c65f62011-07-29 09:55:28 +00001838 debug("KBD: Keyboard init ...\n");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001839 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1840#endif
wdenkc6097192002-11-03 00:24:07 +00001841
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001842 if (skip_dev_init)
1843 return 0;
wdenkc6097192002-11-03 00:24:07 +00001844
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001845 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001846 memset(&console_dev, 0, sizeof(console_dev));
1847 strcpy(console_dev.name, "vga");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001848 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1849 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1850 console_dev.putc = video_putc; /* 'putc' function */
1851 console_dev.puts = video_puts; /* 'puts' function */
1852 console_dev.tstc = NULL; /* 'tstc' function */
1853 console_dev.getc = NULL; /* 'getc' function */
1854
1855#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1856 /* Also init console device */
1857 console_dev.flags |= DEV_FLAGS_INPUT;
1858 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1859 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00001860#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001861
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001862 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001863 return 0;
1864
1865 /* Return success */
1866 return 1;
wdenkc6097192002-11-03 00:24:07 +00001867}