blob: 9f7794fe5300c8d45d6c836b0287aa34133e26b0 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenke55402c2004-03-14 16:51:43 +000015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkc6097192002-11-03 00:24:07 +000016 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * cfb_console.c
26 *
27 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
28 *
29 * At the moment only the 8x16 font is tested and the font fore- and
30 * background color is limited to black/white/gray colors. The Linux
31 * logo can be placed in the upper left corner and additional board
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000032 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000033 *
34 * The console driver can use the standard PC keyboard interface (i8042)
35 * for character input. Character output goes to a memory mapped video
36 * framebuffer with little or big-endian organisation.
37 * With environment setting 'console=serial' the console i/o can be
38 * forced to serial port.
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000039 *
40 * The driver uses graphic specific defines/parameters/functions:
41 *
42 * (for SMI LynxE graphic chip)
43 *
44 * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
45 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
46 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
47 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
48 *
49 * Console Parameters are set by graphic drivers global struct:
50 *
51 * VIDEO_VISIBLE_COLS - x resolution
52 * VIDEO_VISIBLE_ROWS - y resolution
53 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
54 * VIDEO_DATA_FORMAT - graphical data format GDF
55 * VIDEO_FB_ADRS - start of video memory
56 *
57 * CONFIG_I8042_KBD - AT Keyboard driver for i8042
58 * VIDEO_KBD_INIT_FCT - init function for keyboard
59 * VIDEO_TSTC_FCT - keyboard_tstc function
60 * VIDEO_GETC_FCT - keyboard_getc function
61 *
62 * CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with
63 * delay loop in VIDEO_TSTC_FCT (i8042)
64 *
65 * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
66 * CONFIG_CONSOLE_TIME - display time/date in upper right
67 * corner, needs CONFIG_CMD_DATE and
68 * CONFIG_CONSOLE_CURSOR
Bastian Rupperta13e81f2012-09-13 22:29:01 +000069 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
70 * Use CONFIG_SPLASH_SCREEN_ALIGN with
71 * environment variable "splashpos" to place
72 * the logo on other position. In this case
73 * no CONSOLE_EXTRA_INFO is possible.
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000074 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
75 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
76 * strings that normaly goes to serial
77 * port. This define requires a board
78 * specific function:
79 * video_drawstring (VIDEO_INFO_X,
80 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
81 * info);
82 * that fills a info buffer at i=row.
83 * s.a: board/eltec/bab7xx.
84 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
85 * initialized as an output only device.
86 * The Keyboard driver will not be
87 * set-up. This may be used, if you have
88 * no or more than one Keyboard devices
89 * (USB Keyboard, AT Keyboard).
90 *
91 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
92 * character. No blinking is provided.
93 * Uses the macros CURSOR_SET and
94 * CURSOR_OFF.
95 *
96 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
97 * of the graphic chip. Uses the macro
98 * CURSOR_SET. ATTENTION: If booting an
99 * OS, the display driver must disable
100 * the hardware register of the graphic
101 * chip. Otherwise a blinking field is
102 * displayed.
103 */
wdenkc6097192002-11-03 00:24:07 +0000104
105#include <common.h>
Andreas Bießmann61d01952011-07-18 20:24:04 +0200106#include <version.h>
wdenk9dd2b882002-12-03 21:28:10 +0000107#include <malloc.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +0000108#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +0000109
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000110/*
111 * Console device defines with SMI graphic
112 * Any other graphic must change this section
113 */
wdenkc6097192002-11-03 00:24:07 +0000114
wdenke55402c2004-03-14 16:51:43 +0000115#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000116
117#define VIDEO_FB_LITTLE_ENDIAN
118#define VIDEO_HW_RECTFILL
119#define VIDEO_HW_BITBLT
120#endif
121
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000122/*
123 * Defines for the CT69000 driver
124 */
wdenke55402c2004-03-14 16:51:43 +0000125#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000126
127#define VIDEO_FB_LITTLE_ENDIAN
128#define VIDEO_HW_RECTFILL
129#define VIDEO_HW_BITBLT
130#endif
131
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000132/*
133 * Defines for the SED13806 driver
134 */
wdenk9dd2b882002-12-03 21:28:10 +0000135#ifdef CONFIG_VIDEO_SED13806
136
wdenkda54bc92004-08-04 21:56:49 +0000137#ifndef CONFIG_TOTAL5200
wdenk9dd2b882002-12-03 21:28:10 +0000138#define VIDEO_FB_LITTLE_ENDIAN
wdenkda54bc92004-08-04 21:56:49 +0000139#endif
wdenk9dd2b882002-12-03 21:28:10 +0000140#define VIDEO_HW_RECTFILL
141#define VIDEO_HW_BITBLT
142#endif
143
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000144/*
145 * Defines for the SED13806 driver
146 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200147#ifdef CONFIG_VIDEO_SM501
148
149#ifdef CONFIG_HH405
150#define VIDEO_FB_LITTLE_ENDIAN
151#endif
152#endif
153
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000154/*
155 * Defines for the MB862xx driver
156 */
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100157#ifdef CONFIG_VIDEO_MB862xx
158
159#ifdef CONFIG_VIDEO_CORALP
160#define VIDEO_FB_LITTLE_ENDIAN
161#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200162#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100163#define VIDEO_HW_RECTFILL
164#define VIDEO_HW_BITBLT
165#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200166#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100167
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000168/*
Helmut Raiger0385c132011-10-12 23:16:29 +0000169 * Defines for the i.MX31 driver (mx3fb.c)
170 */
Fabio Estevamc6dd2e02012-05-31 07:23:56 +0000171#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger0385c132011-10-12 23:16:29 +0000172#define VIDEO_FB_16BPP_WORD_SWAP
173#endif
174
175/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000176 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
177 */
wdenkc6097192002-11-03 00:24:07 +0000178#include <video_fb.h>
179
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000180/*
181 * some Macros
182 */
wdenke55402c2004-03-14 16:51:43 +0000183#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
184#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
185#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
186#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
187#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000188
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000189/*
190 * Console device defines with i8042 keyboard controller
191 * Any other keyboard controller must change this section
192 */
wdenkc6097192002-11-03 00:24:07 +0000193
wdenke55402c2004-03-14 16:51:43 +0000194#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000195#include <i8042.h>
196
wdenke55402c2004-03-14 16:51:43 +0000197#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
198#define VIDEO_TSTC_FCT i8042_tstc
199#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000200#endif
201
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000202/*
203 * Console device
204 */
wdenkc6097192002-11-03 00:24:07 +0000205
206#include <version.h>
207#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200208#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000209#include <video_font.h>
Che-Liang Chiou41132c02011-10-21 17:04:21 +0800210#include <video_font_data.h>
wdenkc6097192002-11-03 00:24:07 +0000211
Jon Loeliger30c2f242007-07-10 11:13:21 -0500212#if defined(CONFIG_CMD_DATE)
213#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000214#endif
215
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500216#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000217#include <watchdog.h>
218#include <bmp_layout.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200219
220#ifdef CONFIG_SPLASH_SCREEN_ALIGN
221#define BMP_ALIGN_CENTER 0x7FFF
222#endif
223
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500224#endif
wdenke55402c2004-03-14 16:51:43 +0000225
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000226/*
227 * Cursor definition:
228 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
229 * to let the cursor blink. Uses the macros
230 * CURSOR_OFF and CURSOR_ON.
231 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
232 * blinking is provided. Uses the macros CURSOR_SET
233 * and CURSOR_OFF.
234 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
235 * graphic chip. Uses the macro CURSOR_SET.
236 * ATTENTION: If booting an OS, the display driver
237 * must disable the hardware register of the graphic
238 * chip. Otherwise a blinking field is displayed
239 */
wdenkc6097192002-11-03 00:24:07 +0000240#if !defined(CONFIG_CONSOLE_CURSOR) && \
241 !defined(CONFIG_VIDEO_SW_CURSOR) && \
242 !defined(CONFIG_VIDEO_HW_CURSOR)
243/* no Cursor defined */
244#define CURSOR_ON
245#define CURSOR_OFF
246#define CURSOR_SET
247#endif
248
Gabe Black12874de2011-11-30 13:50:50 +0000249#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
250#if defined(CURSOR_ON) || \
251 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000252#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
253 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000254#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000255void console_cursor(int state);
256
Timur Tabibe0c74e2010-08-27 15:45:47 -0500257#define CURSOR_ON console_cursor(1)
258#define CURSOR_OFF console_cursor(0)
Gabe Black12874de2011-11-30 13:50:50 +0000259#define CURSOR_SET video_set_cursor()
260#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
261
262#ifdef CONFIG_CONSOLE_CURSOR
263#ifndef CONFIG_CONSOLE_TIME
264#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
265#endif
wdenkc6097192002-11-03 00:24:07 +0000266#ifndef CONFIG_I8042_KBD
Marcel Ziswileraea68562007-12-30 03:30:46 +0100267#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000268#endif
wdenkc6097192002-11-03 00:24:07 +0000269#endif /* CONFIG_CONSOLE_CURSOR */
270
wdenkc6097192002-11-03 00:24:07 +0000271
272#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +0000273#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000274#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
275 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000276#endif
277#define CURSOR_ON
278#define CURSOR_OFF
279#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabibe0c74e2010-08-27 15:45:47 -0500280 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000281#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000282
wdenke55402c2004-03-14 16:51:43 +0000283#ifdef CONFIG_VIDEO_LOGO
284#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000285#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000286#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000287#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
288#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
289#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
290#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000291
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000292#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000293#define LINUX_LOGO_WIDTH 80
294#define LINUX_LOGO_HEIGHT 80
295#define LINUX_LOGO_COLORS 214
296#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000297#define __initdata
298#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000299#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
300#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
301#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
302#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000303#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000304#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
305#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000306#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000307#define VIDEO_LOGO_WIDTH 0
308#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000309#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000310
wdenke55402c2004-03-14 16:51:43 +0000311#define VIDEO_COLS VIDEO_VISIBLE_COLS
312#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
313#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
314#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
315#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
316#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000317
wdenke55402c2004-03-14 16:51:43 +0000318#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100319#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000320#else
wdenke55402c2004-03-14 16:51:43 +0000321#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000322#endif
323
wdenke55402c2004-03-14 16:51:43 +0000324#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
325#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
326#define CONSOLE_ROW_FIRST (video_console_address)
327#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
328#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
329#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
330#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000331
332/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000333#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000334#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
335 ((x) >> 8) \
336 )
337#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
338 (((x) & 0x0000ff00) << 8) | \
339 (((x) & 0x00ff0000) >> 8) | \
340 (((x) & 0xff000000) >> 24) \
341 )
342#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
343 (((x) & 0x0000ff00) >> 8) | \
344 (((x) & 0x00ff0000) << 8) | \
345 (((x) & 0xff000000) >> 8) \
346 )
wdenkc6097192002-11-03 00:24:07 +0000347#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000348#define SWAP16(x) (x)
349#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200350#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000351#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500352#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000353#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100354#endif
wdenkc6097192002-11-03 00:24:07 +0000355#endif
356
wdenkc6097192002-11-03 00:24:07 +0000357#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000358/*
359 * setup a board string: type, speed, etc.
360 *
361 * line_number: location to place info string beside logo
362 * info: buffer for info string
363 */
364extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000365#endif
366
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200367DECLARE_GLOBAL_DATA_PTR;
368
wdenkc6097192002-11-03 00:24:07 +0000369/* Locals */
370static GraphicDevice *pGD; /* Pointer to Graphic array */
371
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000372static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000373static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000374
Matthias Weisser76d70862010-01-12 12:06:31 +0100375static int video_logo_height = VIDEO_LOGO_HEIGHT;
376
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000377static int __maybe_unused cursor_state;
378static int __maybe_unused old_col;
379static int __maybe_unused old_row;
Gabe Black12874de2011-11-30 13:50:50 +0000380
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000381static int console_col; /* cursor col */
382static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000383
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000384static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000385
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200386static int cfb_do_flush_cache;
387
wdenkc6097192002-11-03 00:24:07 +0000388static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000389 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
390 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
391 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
392 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
393};
wdenkc6097192002-11-03 00:24:07 +0000394
395static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000396 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
397};
wdenkc6097192002-11-03 00:24:07 +0000398
399static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000400 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
401};
wdenkc6097192002-11-03 00:24:07 +0000402
403static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000404 {0x00000000, 0x00000000, 0x00000000},
405 {0x00000000, 0x00000000, 0x00ffffff},
406 {0x00000000, 0x0000ffff, 0xff000000},
407 {0x00000000, 0x0000ffff, 0xffffffff},
408 {0x000000ff, 0xffff0000, 0x00000000},
409 {0x000000ff, 0xffff0000, 0x00ffffff},
410 {0x000000ff, 0xffffffff, 0xff000000},
411 {0x000000ff, 0xffffffff, 0xffffffff},
412 {0xffffff00, 0x00000000, 0x00000000},
413 {0xffffff00, 0x00000000, 0x00ffffff},
414 {0xffffff00, 0x0000ffff, 0xff000000},
415 {0xffffff00, 0x0000ffff, 0xffffffff},
416 {0xffffffff, 0xffff0000, 0x00000000},
417 {0xffffffff, 0xffff0000, 0x00ffffff},
418 {0xffffffff, 0xffffffff, 0xff000000},
419 {0xffffffff, 0xffffffff, 0xffffffff}
420};
wdenkc6097192002-11-03 00:24:07 +0000421
422static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000423 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
424 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
425 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
426 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
427 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
428 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
429 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
430 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
431 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
432 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
433 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
434 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
435 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
436 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
437 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
438 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
439};
wdenkc6097192002-11-03 00:24:07 +0000440
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000441static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000442{
wdenke55402c2004-03-14 16:51:43 +0000443 u8 *cdat, *dest, *dest0;
444 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000445
wdenke55402c2004-03-14 16:51:43 +0000446 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
447 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000448
wdenke55402c2004-03-14 16:51:43 +0000449 switch (VIDEO_DATA_FORMAT) {
450 case GDF__8BIT_INDEX:
451 case GDF__8BIT_332RGB:
452 while (count--) {
453 c = *s;
454 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
455 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000456 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000457 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000458
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000459 ((u32 *) dest)[0] =
460 (video_font_draw_table8[bits >> 4] &
461 eorx) ^ bgx;
462 ((u32 *) dest)[1] =
463 (video_font_draw_table8[bits & 15] &
464 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000465 }
466 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
467 s++;
468 }
469 break;
wdenkc6097192002-11-03 00:24:07 +0000470
wdenke55402c2004-03-14 16:51:43 +0000471 case GDF_15BIT_555RGB:
472 while (count--) {
473 c = *s;
474 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
475 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000476 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000477 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000478
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000479 ((u32 *) dest)[0] =
480 SHORTSWAP32((video_font_draw_table15
481 [bits >> 6] & eorx) ^
482 bgx);
483 ((u32 *) dest)[1] =
484 SHORTSWAP32((video_font_draw_table15
485 [bits >> 4 & 3] & eorx) ^
486 bgx);
487 ((u32 *) dest)[2] =
488 SHORTSWAP32((video_font_draw_table15
489 [bits >> 2 & 3] & eorx) ^
490 bgx);
491 ((u32 *) dest)[3] =
492 SHORTSWAP32((video_font_draw_table15
493 [bits & 3] & eorx) ^
494 bgx);
wdenke55402c2004-03-14 16:51:43 +0000495 }
496 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
497 s++;
498 }
499 break;
wdenkc6097192002-11-03 00:24:07 +0000500
wdenke55402c2004-03-14 16:51:43 +0000501 case GDF_16BIT_565RGB:
502 while (count--) {
503 c = *s;
504 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
505 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000506 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000507 u8 bits = *cdat++;
508
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000509 ((u32 *) dest)[0] =
510 SHORTSWAP32((video_font_draw_table16
511 [bits >> 6] & eorx) ^
512 bgx);
513 ((u32 *) dest)[1] =
514 SHORTSWAP32((video_font_draw_table16
515 [bits >> 4 & 3] & eorx) ^
516 bgx);
517 ((u32 *) dest)[2] =
518 SHORTSWAP32((video_font_draw_table16
519 [bits >> 2 & 3] & eorx) ^
520 bgx);
521 ((u32 *) dest)[3] =
522 SHORTSWAP32((video_font_draw_table16
523 [bits & 3] & eorx) ^
524 bgx);
wdenke55402c2004-03-14 16:51:43 +0000525 }
526 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
527 s++;
528 }
529 break;
530
531 case GDF_32BIT_X888RGB:
532 while (count--) {
533 c = *s;
534 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
535 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000536 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000537 u8 bits = *cdat++;
538
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000539 ((u32 *) dest)[0] =
540 SWAP32((video_font_draw_table32
541 [bits >> 4][0] & eorx) ^ bgx);
542 ((u32 *) dest)[1] =
543 SWAP32((video_font_draw_table32
544 [bits >> 4][1] & eorx) ^ bgx);
545 ((u32 *) dest)[2] =
546 SWAP32((video_font_draw_table32
547 [bits >> 4][2] & eorx) ^ bgx);
548 ((u32 *) dest)[3] =
549 SWAP32((video_font_draw_table32
550 [bits >> 4][3] & eorx) ^ bgx);
551 ((u32 *) dest)[4] =
552 SWAP32((video_font_draw_table32
553 [bits & 15][0] & eorx) ^ bgx);
554 ((u32 *) dest)[5] =
555 SWAP32((video_font_draw_table32
556 [bits & 15][1] & eorx) ^ bgx);
557 ((u32 *) dest)[6] =
558 SWAP32((video_font_draw_table32
559 [bits & 15][2] & eorx) ^ bgx);
560 ((u32 *) dest)[7] =
561 SWAP32((video_font_draw_table32
562 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000563 }
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200564 if (cfb_do_flush_cache)
565 flush_cache((ulong)dest0, 32);
wdenke55402c2004-03-14 16:51:43 +0000566 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
567 s++;
568 }
569 break;
570
571 case GDF_24BIT_888RGB:
572 while (count--) {
573 c = *s;
574 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
575 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000576 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000577 u8 bits = *cdat++;
578
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000579 ((u32 *) dest)[0] =
580 (video_font_draw_table24[bits >> 4][0]
581 & eorx) ^ bgx;
582 ((u32 *) dest)[1] =
583 (video_font_draw_table24[bits >> 4][1]
584 & eorx) ^ bgx;
585 ((u32 *) dest)[2] =
586 (video_font_draw_table24[bits >> 4][2]
587 & eorx) ^ bgx;
588 ((u32 *) dest)[3] =
589 (video_font_draw_table24[bits & 15][0]
590 & eorx) ^ bgx;
591 ((u32 *) dest)[4] =
592 (video_font_draw_table24[bits & 15][1]
593 & eorx) ^ bgx;
594 ((u32 *) dest)[5] =
595 (video_font_draw_table24[bits & 15][2]
596 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000597 }
598 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
599 s++;
600 }
601 break;
wdenk57b2d802003-06-27 21:31:46 +0000602 }
wdenkc6097192002-11-03 00:24:07 +0000603}
604
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000605static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000606{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000607 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000608}
609
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000610static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000611{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000612 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000613}
614
wdenkc6097192002-11-03 00:24:07 +0000615#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000616static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000617{
Gabe Black12874de2011-11-30 13:50:50 +0000618 if (cursor_state)
619 console_cursor(0);
620 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000621}
Gabe Black12874de2011-11-30 13:50:50 +0000622
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000623static void video_invertchar(int xx, int yy)
624{
625 int firstx = xx * VIDEO_PIXEL_SIZE;
626 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
627 int firsty = yy * VIDEO_LINE_LEN;
628 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
629 int x, y;
630 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
631 for (x = firstx; x < lastx; x++) {
632 u8 *dest = (u8 *)(video_fb_address) + x + y;
633 *dest = ~*dest;
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200634 if (cfb_do_flush_cache)
635 flush_cache((ulong)dest, 4);
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000636 }
637 }
638}
Gabe Black12874de2011-11-30 13:50:50 +0000639
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000640void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000641{
wdenkc6097192002-11-03 00:24:07 +0000642#ifdef CONFIG_CONSOLE_TIME
wdenke55402c2004-03-14 16:51:43 +0000643 struct rtc_time tm;
644 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000645
wdenke55402c2004-03-14 16:51:43 +0000646 /* time update only if cursor is on (faster scroll) */
647 if (state) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000648 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000649
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000650 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
651 tm.tm_sec);
652 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
653 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000654
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000655 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
656 tm.tm_year);
657 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
658 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
659 (uchar *) info);
wdenke55402c2004-03-14 16:51:43 +0000660 }
wdenkc6097192002-11-03 00:24:07 +0000661#endif
662
Gabe Black12874de2011-11-30 13:50:50 +0000663 if (cursor_state != state) {
664 if (cursor_state) {
665 /* turn off the cursor */
666 video_invertchar(old_col * VIDEO_FONT_WIDTH,
667 old_row * VIDEO_FONT_HEIGHT +
668 video_logo_height);
669 } else {
670 /* turn off the cursor and record where it is */
671 video_invertchar(console_col * VIDEO_FONT_WIDTH,
672 console_row * VIDEO_FONT_HEIGHT +
673 video_logo_height);
674 old_col = console_col;
675 old_row = console_row;
676 }
677 cursor_state = state;
wdenke55402c2004-03-14 16:51:43 +0000678 }
wdenkc6097192002-11-03 00:24:07 +0000679}
680#endif
681
wdenkc6097192002-11-03 00:24:07 +0000682#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000683static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000684{
wdenke55402c2004-03-14 16:51:43 +0000685 while (c--)
686 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000687}
688#endif
689
wdenkc6097192002-11-03 00:24:07 +0000690#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000691static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000692{
wdenke55402c2004-03-14 16:51:43 +0000693 while (c--)
694 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000695}
696#endif
697
Pali Rohár16658612012-04-28 07:26:44 +0000698static void console_clear_line(int line, int begin, int end)
699{
700#ifdef VIDEO_HW_RECTFILL
701 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
702 VIDEO_FONT_WIDTH * begin, /* dest pos x */
703 video_logo_height +
704 VIDEO_FONT_HEIGHT * line, /* dest pos y */
705 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
706 VIDEO_FONT_HEIGHT, /* frame height */
707 bgx /* fill color */
708 );
709#else
710 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
711 memsetl(CONSOLE_ROW_FIRST +
712 CONSOLE_ROW_SIZE * line, /* offset of row */
713 CONSOLE_ROW_SIZE >> 2, /* length of row */
714 bgx /* fill color */
715 );
716 } else {
717 void *offset;
718 int i, size;
719
720 offset = CONSOLE_ROW_FIRST +
721 CONSOLE_ROW_SIZE * line + /* offset of row */
722 VIDEO_FONT_WIDTH *
723 VIDEO_PIXEL_SIZE * begin; /* offset of col */
724 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
725 size >>= 2; /* length to end for memsetl() */
726 /* fill at col offset of i'th line using bgx as fill color */
727 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
728 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
729 }
730#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200731 if (cfb_do_flush_cache)
732 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
Pali Rohár16658612012-04-28 07:26:44 +0000733}
734
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000735static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000736{
wdenke55402c2004-03-14 16:51:43 +0000737 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000738
739#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000740 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
741 0, /* source pos x */
742 video_logo_height +
743 VIDEO_FONT_HEIGHT, /* source pos y */
744 0, /* dest pos x */
745 video_logo_height, /* dest pos y */
746 VIDEO_VISIBLE_COLS, /* frame width */
747 VIDEO_VISIBLE_ROWS
748 - video_logo_height
749 - VIDEO_FONT_HEIGHT /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000750 );
wdenkc6097192002-11-03 00:24:07 +0000751#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000752 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
753 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000754#endif
wdenke55402c2004-03-14 16:51:43 +0000755 /* clear the last one */
Pali Rohár16658612012-04-28 07:26:44 +0000756 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
wdenkc6097192002-11-03 00:24:07 +0000757}
758
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000759static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000760{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500761 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000762
wdenke55402c2004-03-14 16:51:43 +0000763 if (console_col < 0) {
764 console_col = CONSOLE_COLS - 1;
765 console_row--;
766 if (console_row < 0)
767 console_row = 0;
768 }
wdenkc6097192002-11-03 00:24:07 +0000769}
770
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000771static void console_newline(void)
wdenkc6097192002-11-03 00:24:07 +0000772{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100773 console_row++;
wdenke55402c2004-03-14 16:51:43 +0000774 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000775
wdenke55402c2004-03-14 16:51:43 +0000776 /* Check if we need to scroll the terminal */
777 if (console_row >= CONSOLE_ROWS) {
778 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000779 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000780
wdenke55402c2004-03-14 16:51:43 +0000781 /* Decrement row number */
782 console_row--;
783 }
wdenkc6097192002-11-03 00:24:07 +0000784}
785
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000786static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100787{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500788 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100789}
790
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000791void video_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000792{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100793 static int nl = 1;
794
Gabe Black12874de2011-11-30 13:50:50 +0000795 CURSOR_OFF;
796
wdenke55402c2004-03-14 16:51:43 +0000797 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100798 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000799 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000800 break;
wdenkc6097192002-11-03 00:24:07 +0000801
wdenke55402c2004-03-14 16:51:43 +0000802 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100803 if (console_col || (!console_col && nl))
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000804 console_newline();
Anatolij Gustschin938db912008-01-11 02:39:47 +0100805 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000806 break;
wdenkc6097192002-11-03 00:24:07 +0000807
wdenke55402c2004-03-14 16:51:43 +0000808 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500809 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000810 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000811
wdenke55402c2004-03-14 16:51:43 +0000812 if (console_col >= CONSOLE_COLS)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000813 console_newline();
wdenke55402c2004-03-14 16:51:43 +0000814 break;
wdenkc6097192002-11-03 00:24:07 +0000815
wdenke55402c2004-03-14 16:51:43 +0000816 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000817 console_back();
wdenke55402c2004-03-14 16:51:43 +0000818 break;
wdenkc6097192002-11-03 00:24:07 +0000819
Pali Rohár9d735b62012-04-28 07:26:47 +0000820 case 7: /* bell */
821 break; /* ignored */
822
wdenke55402c2004-03-14 16:51:43 +0000823 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000824 video_putchar(console_col * VIDEO_FONT_WIDTH,
825 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000826 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000827
wdenke55402c2004-03-14 16:51:43 +0000828 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100829 if (console_col >= CONSOLE_COLS) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000830 console_newline();
Anatolij Gustschin938db912008-01-11 02:39:47 +0100831 nl = 0;
832 }
wdenke55402c2004-03-14 16:51:43 +0000833 }
Timur Tabibe0c74e2010-08-27 15:45:47 -0500834 CURSOR_SET;
835}
wdenkc6097192002-11-03 00:24:07 +0000836
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000837void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +0000838{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000839 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +0000840
841 while (count--)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000842 video_putc(*s++);
wdenke55402c2004-03-14 16:51:43 +0000843}
844
Anatolij Gustschina043c342010-05-01 22:21:09 +0200845/*
846 * Do not enforce drivers (or board code) to provide empty
847 * video_set_lut() if they do not support 8 bpp format.
848 * Implement weak default function instead.
849 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000850void __video_set_lut(unsigned int index, unsigned char r,
851 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +0200852{
853}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000854
855void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
856 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschina043c342010-05-01 22:21:09 +0200857
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500858#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000859
860#define FILL_8BIT_332RGB(r,g,b) { \
861 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
862 fb ++; \
863}
864
865#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000866 *(unsigned short *)fb = \
867 SWAP16((unsigned short)(((r>>3)<<10) | \
868 ((g>>3)<<5) | \
869 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +0000870 fb += 2; \
871}
872
873#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000874 *(unsigned short *)fb = \
875 SWAP16((unsigned short)((((r)>>3)<<11)| \
876 (((g)>>2)<<5) | \
877 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +0000878 fb += 2; \
879}
880
881#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000882 *(unsigned long *)fb = \
883 SWAP32((unsigned long)(((r<<16) | \
884 (g<<8) | \
885 b))); \
wdenke55402c2004-03-14 16:51:43 +0000886 fb += 4; \
887}
888
889#ifdef VIDEO_FB_LITTLE_ENDIAN
890#define FILL_24BIT_888RGB(r,g,b) { \
891 fb[0] = b; \
892 fb[1] = g; \
893 fb[2] = r; \
894 fb += 3; \
895}
896#else
897#define FILL_24BIT_888RGB(r,g,b) { \
898 fb[0] = r; \
899 fb[1] = g; \
900 fb[2] = b; \
901 fb += 3; \
902}
903#endif
904
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200905#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000906static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200907{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000908 ushort *dst = (ushort *) fb;
909 ushort color = (ushort) (((r >> 3) << 10) |
910 ((g >> 3) << 5) |
911 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200912 if (x & 1)
913 *(--dst) = color;
914 else
915 *(++dst) = color;
916}
917#endif
wdenke55402c2004-03-14 16:51:43 +0000918
919/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100920 * RLE8 bitmap support
921 */
922
923#ifdef CONFIG_VIDEO_BMP_RLE8
924/* Pre-calculated color table entry */
925struct palette {
926 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000927 unsigned short w; /* word */
928 unsigned int dw; /* double word */
929 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100930};
931
932/*
933 * Helper to draw encoded/unencoded run.
934 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000935static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
936 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100937{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000938 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100939 int *off;
940 int enc_off = 1;
941 int i;
942
943 /*
944 * Setup offset of the color index in the bitmap.
945 * Color index of encoded run is at offset 1.
946 */
947 off = enc ? &enc_off : &i;
948
949 switch (VIDEO_DATA_FORMAT) {
950 case GDF__8BIT_INDEX:
951 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000952 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100953 break;
954 case GDF_15BIT_555RGB:
955 case GDF_16BIT_565RGB:
956 /* differences handled while pre-calculating palette */
957 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000958 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100959 addr += 2;
960 }
961 break;
962 case GDF_32BIT_X888RGB:
963 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000964 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100965 addr += 4;
966 }
967 break;
968 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000969 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100970}
971
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000972static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
973 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100974{
975 unsigned char *bm;
976 unsigned char *fbp;
977 unsigned int cnt, runlen;
978 int decode = 1;
979 int x, y, bpp, i, ncolors;
980 struct palette p[256];
981 bmp_color_table_entry_t cte;
982 int green_shift, red_off;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +0100983 int limit = VIDEO_COLS * VIDEO_ROWS;
984 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100985
986 x = 0;
987 y = __le32_to_cpu(img->header.height) - 1;
988 ncolors = __le32_to_cpu(img->header.colors_used);
989 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000990 fbp = (unsigned char *) ((unsigned int) video_fb_address +
991 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100992
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000993 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100994
995 /* pre-calculate and setup palette */
996 switch (VIDEO_DATA_FORMAT) {
997 case GDF__8BIT_INDEX:
998 for (i = 0; i < ncolors; i++) {
999 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001000 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001001 }
1002 break;
1003 case GDF_15BIT_555RGB:
1004 case GDF_16BIT_565RGB:
1005 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1006 green_shift = 3;
1007 red_off = 10;
1008 } else {
1009 green_shift = 2;
1010 red_off = 11;
1011 }
1012 for (i = 0; i < ncolors; i++) {
1013 cte = img->color_table[i];
1014 p[i].ce.w = SWAP16((unsigned short)
1015 (((cte.red >> 3) << red_off) |
1016 ((cte.green >> green_shift) << 5) |
1017 cte.blue >> 3));
1018 }
1019 break;
1020 case GDF_32BIT_X888RGB:
1021 for (i = 0; i < ncolors; i++) {
1022 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001023 p[i].ce.dw = SWAP32((cte.red << 16) |
1024 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001025 cte.blue);
1026 }
1027 break;
1028 default:
1029 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001030 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001031 return -1;
1032 }
1033
1034 while (decode) {
1035 switch (bm[0]) {
1036 case 0:
1037 switch (bm[1]) {
1038 case 0:
1039 /* scan line end marker */
1040 bm += 2;
1041 x = 0;
1042 y--;
1043 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001044 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001045 (((y + yoff) * VIDEO_COLS) +
1046 xoff) * bpp);
1047 continue;
1048 case 1:
1049 /* end of bitmap data marker */
1050 decode = 0;
1051 break;
1052 case 2:
1053 /* run offset marker */
1054 x += bm[2];
1055 y -= bm[3];
1056 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001057 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001058 (((y + yoff) * VIDEO_COLS) +
1059 x + xoff) * bpp);
1060 bm += 4;
1061 break;
1062 default:
1063 /* unencoded run */
1064 cnt = bm[1];
1065 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001066 pixels += cnt;
1067 if (pixels > limit)
1068 goto error;
1069
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001070 bm += 2;
1071 if (y < height) {
1072 if (x >= width) {
1073 x += runlen;
1074 goto next_run;
1075 }
1076 if (x + runlen > width)
1077 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001078 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001079 x += runlen;
1080 }
1081next_run:
1082 bm += runlen;
1083 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001084 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001085 }
1086 break;
1087 default:
1088 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001089 cnt = bm[0];
1090 runlen = cnt;
1091 pixels += cnt;
1092 if (pixels > limit)
1093 goto error;
1094
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001095 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001096 if (x >= width) {
1097 x += runlen;
1098 bm += 2;
1099 continue;
1100 }
1101 if (x + runlen > width)
1102 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001103 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001104 x += runlen;
1105 }
1106 bm += 2;
1107 break;
1108 }
1109 }
1110 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001111error:
1112 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1113 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001114}
1115#endif
1116
1117/*
wdenke55402c2004-03-14 16:51:43 +00001118 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001119 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001120int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001121{
1122 ushort xcount, ycount;
1123 uchar *fb;
1124 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1125 uchar *bmap;
1126 ushort padded_line;
1127 unsigned long width, height, bpp;
1128 unsigned colors;
1129 unsigned long compression;
1130 bmp_color_table_entry_t cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001131
Stefan Roesed9d97742005-09-22 09:04:17 +02001132#ifdef CONFIG_VIDEO_BMP_GZIP
1133 unsigned char *dst = NULL;
1134 ulong len;
1135#endif
wdenkc6097192002-11-03 00:24:07 +00001136
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001137 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001138
1139 if (!((bmp->header.signature[0] == 'B') &&
1140 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001141
1142#ifdef CONFIG_VIDEO_BMP_GZIP
1143 /*
1144 * Could be a gzipped bmp image, try to decrompress...
1145 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001146 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1147 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001148 if (dst == NULL) {
1149 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001150 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001151 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001152 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1153 (uchar *) bmp_image,
1154 &len) != 0) {
1155 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1156 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001157 free(dst);
1158 return 1;
1159 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001160 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001161 printf("Image could be truncated "
1162 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001163 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001164
1165 /*
1166 * Set addr to decompressed image
1167 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001168 bmp = (bmp_image_t *) dst;
Stefan Roesed9d97742005-09-22 09:04:17 +02001169
1170 if (!((bmp->header.signature[0] == 'B') &&
1171 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001172 printf("Error: no valid bmp.gz image at %lx\n",
1173 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001174 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001175 return 1;
1176 }
1177#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001178 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001179 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001180#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001181 }
1182
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001183 width = le32_to_cpu(bmp->header.width);
1184 height = le32_to_cpu(bmp->header.height);
1185 bpp = le16_to_cpu(bmp->header.bit_count);
1186 colors = le32_to_cpu(bmp->header.colors_used);
1187 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001188
Marek Vasut2eb9a492011-10-21 14:17:04 +00001189 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001190 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001191
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001192 if (compression != BMP_BI_RGB
1193#ifdef CONFIG_VIDEO_BMP_RLE8
1194 && compression != BMP_BI_RLE8
1195#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001196 ) {
1197 printf("Error: compression type %ld not supported\n",
1198 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001199#ifdef CONFIG_VIDEO_BMP_GZIP
1200 if (dst)
1201 free(dst);
1202#endif
wdenke55402c2004-03-14 16:51:43 +00001203 return 1;
1204 }
1205
1206 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1207
Matthias Weisser53884182009-07-09 16:07:30 +02001208#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1209 if (x == BMP_ALIGN_CENTER)
1210 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1211 else if (x < 0)
1212 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1213
1214 if (y == BMP_ALIGN_CENTER)
1215 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1216 else if (y < 0)
1217 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1218#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1219
wdenke55402c2004-03-14 16:51:43 +00001220 if ((x + width) > VIDEO_VISIBLE_COLS)
1221 width = VIDEO_VISIBLE_COLS - x;
1222 if ((y + height) > VIDEO_VISIBLE_ROWS)
1223 height = VIDEO_VISIBLE_ROWS - y;
1224
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001225 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001226 fb = (uchar *) (video_fb_address +
1227 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1228 x * VIDEO_PIXEL_SIZE);
1229
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001230#ifdef CONFIG_VIDEO_BMP_RLE8
1231 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001232 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001233 }
1234#endif
1235
Timur Tabi0fce9922010-08-23 16:58:00 -05001236 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001237 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001238 case 4:
1239 padded_line -= width / 2;
1240 ycount = height;
1241
1242 switch (VIDEO_DATA_FORMAT) {
1243 case GDF_32BIT_X888RGB:
1244 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001245 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001246 /*
1247 * Don't assume that 'width' is an
1248 * even number
1249 */
1250 for (xcount = 0; xcount < width; xcount++) {
1251 uchar idx;
1252
1253 if (xcount & 1) {
1254 idx = *bmap & 0xF;
1255 bmap++;
1256 } else
1257 idx = *bmap >> 4;
1258 cte = bmp->color_table[idx];
1259 FILL_32BIT_X888RGB(cte.red, cte.green,
1260 cte.blue);
1261 }
1262 bmap += padded_line;
1263 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001264 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001265 }
1266 break;
1267 default:
1268 puts("4bpp bitmap unsupported with current "
1269 "video mode\n");
1270 break;
1271 }
1272 break;
1273
wdenke55402c2004-03-14 16:51:43 +00001274 case 8:
1275 padded_line -= width;
1276 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001277 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001278 for (xcount = 0; xcount < colors; ++xcount) {
1279 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001280 video_set_lut(xcount, cte.red, cte.green,
1281 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001282 }
1283 }
1284 ycount = height;
1285 switch (VIDEO_DATA_FORMAT) {
1286 case GDF__8BIT_INDEX:
1287 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001288 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001289 xcount = width;
1290 while (xcount--) {
1291 *fb++ = *bmap++;
1292 }
1293 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001294 fb -= (VIDEO_VISIBLE_COLS + width) *
1295 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001296 }
1297 break;
1298 case GDF__8BIT_332RGB:
1299 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001300 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001301 xcount = width;
1302 while (xcount--) {
1303 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001304 FILL_8BIT_332RGB(cte.red, cte.green,
1305 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001306 }
1307 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001308 fb -= (VIDEO_VISIBLE_COLS + width) *
1309 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001310 }
1311 break;
1312 case GDF_15BIT_555RGB:
1313 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001314#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1315 int xpos = x;
1316#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001317 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001318 xcount = width;
1319 while (xcount--) {
1320 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001321#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001322 fill_555rgb_pswap(fb, xpos++, cte.red,
1323 cte.green,
1324 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001325 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001326#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001327 FILL_15BIT_555RGB(cte.red, cte.green,
1328 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001329#endif
wdenke55402c2004-03-14 16:51:43 +00001330 }
1331 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001332 fb -= (VIDEO_VISIBLE_COLS + width) *
1333 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001334 }
1335 break;
1336 case GDF_16BIT_565RGB:
1337 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001338 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001339 xcount = width;
1340 while (xcount--) {
1341 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001342 FILL_16BIT_565RGB(cte.red, cte.green,
1343 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001344 }
1345 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001346 fb -= (VIDEO_VISIBLE_COLS + width) *
1347 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001348 }
1349 break;
1350 case GDF_32BIT_X888RGB:
1351 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001352 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001353 xcount = width;
1354 while (xcount--) {
1355 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001356 FILL_32BIT_X888RGB(cte.red, cte.green,
1357 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001358 }
1359 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001360 fb -= (VIDEO_VISIBLE_COLS + width) *
1361 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001362 }
1363 break;
1364 case GDF_24BIT_888RGB:
1365 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001366 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001367 xcount = width;
1368 while (xcount--) {
1369 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001370 FILL_24BIT_888RGB(cte.red, cte.green,
1371 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001372 }
1373 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001374 fb -= (VIDEO_VISIBLE_COLS + width) *
1375 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001376 }
1377 break;
1378 }
1379 break;
1380 case 24:
1381 padded_line -= 3 * width;
1382 ycount = height;
1383 switch (VIDEO_DATA_FORMAT) {
1384 case GDF__8BIT_332RGB:
1385 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001386 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001387 xcount = width;
1388 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001389 FILL_8BIT_332RGB(bmap[2], bmap[1],
1390 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001391 bmap += 3;
1392 }
1393 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001394 fb -= (VIDEO_VISIBLE_COLS + width) *
1395 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001396 }
1397 break;
1398 case GDF_15BIT_555RGB:
1399 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001400#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1401 int xpos = x;
1402#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001403 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001404 xcount = width;
1405 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001406#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001407 fill_555rgb_pswap(fb, xpos++, bmap[2],
1408 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001409 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001410#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001411 FILL_15BIT_555RGB(bmap[2], bmap[1],
1412 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001413#endif
wdenke55402c2004-03-14 16:51:43 +00001414 bmap += 3;
1415 }
1416 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001417 fb -= (VIDEO_VISIBLE_COLS + width) *
1418 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001419 }
1420 break;
1421 case GDF_16BIT_565RGB:
1422 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001423 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001424 xcount = width;
1425 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001426 FILL_16BIT_565RGB(bmap[2], bmap[1],
1427 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001428 bmap += 3;
1429 }
1430 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001431 fb -= (VIDEO_VISIBLE_COLS + width) *
1432 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001433 }
1434 break;
1435 case GDF_32BIT_X888RGB:
1436 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001437 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001438 xcount = width;
1439 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001440 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1441 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001442 bmap += 3;
1443 }
1444 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001445 fb -= (VIDEO_VISIBLE_COLS + width) *
1446 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001447 }
1448 break;
1449 case GDF_24BIT_888RGB:
1450 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001451 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001452 xcount = width;
1453 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001454 FILL_24BIT_888RGB(bmap[2], bmap[1],
1455 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001456 bmap += 3;
1457 }
1458 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001459 fb -= (VIDEO_VISIBLE_COLS + width) *
1460 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001461 }
1462 break;
1463 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001464 printf("Error: 24 bits/pixel bitmap incompatible "
1465 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001466 break;
1467 }
1468 break;
1469 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001470 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1471 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001472 break;
1473 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001474
1475#ifdef CONFIG_VIDEO_BMP_GZIP
1476 if (dst) {
1477 free(dst);
1478 }
1479#endif
1480
wdenke55402c2004-03-14 16:51:43 +00001481 return (0);
wdenkc6097192002-11-03 00:24:07 +00001482}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001483#endif
wdenkc6097192002-11-03 00:24:07 +00001484
wdenkc6097192002-11-03 00:24:07 +00001485
1486#ifdef CONFIG_VIDEO_LOGO
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001487static int video_logo_xpos;
1488static int video_logo_ypos;
1489
Bastian Ruppertd5932182012-09-13 22:29:02 +00001490static void plot_logo_or_black(void *screen, int width, int x, int y, \
1491 int black);
1492
1493static void logo_plot(void *screen, int width, int x, int y)
1494{
1495 plot_logo_or_black(screen, width, x, y, 0);
1496}
1497
1498static void logo_black(void)
1499{
1500 plot_logo_or_black(video_fb_address, \
1501 VIDEO_COLS, \
1502 video_logo_xpos, \
1503 video_logo_ypos, \
1504 1);
1505}
1506
1507static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1508{
1509 if (argc != 1)
1510 return cmd_usage(cmdtp);
1511
1512 logo_black();
1513 return 0;
1514}
1515
1516U_BOOT_CMD(
1517 clrlogo, 1, 0, do_clrlogo,
1518 "fill the boot logo area with black",
1519 " "
1520 );
1521
1522static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001523{
wdenk9dd2b882002-12-03 21:28:10 +00001524
wdenke55402c2004-03-14 16:51:43 +00001525 int xcount, i;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001526 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001527 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001528 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1529 unsigned char *source;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001530 unsigned char *dest;
1531
1532#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1533 if (x == BMP_ALIGN_CENTER)
1534 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1535 else if (x < 0)
1536 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1537
1538 if (y == BMP_ALIGN_CENTER)
1539 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1540 else if (y < 0)
1541 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1542#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1543
1544 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001545
wdenk9dd2b882002-12-03 21:28:10 +00001546#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001547 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001548
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001549 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001550 logo_red = malloc(BMP_LOGO_COLORS);
1551 logo_green = malloc(BMP_LOGO_COLORS);
1552 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001553 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001554 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1555 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1556 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1557 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1558 }
wdenk9dd2b882002-12-03 21:28:10 +00001559#else
wdenke55402c2004-03-14 16:51:43 +00001560 source = linux_logo;
1561 logo_red = linux_logo_red;
1562 logo_green = linux_logo_green;
1563 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001564#endif
wdenk57b2d802003-06-27 21:31:46 +00001565
wdenke55402c2004-03-14 16:51:43 +00001566 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1567 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001568 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1569 logo_red[i], logo_green[i],
1570 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001571 }
wdenk57b2d802003-06-27 21:31:46 +00001572 }
wdenkc6097192002-11-03 00:24:07 +00001573
wdenke55402c2004-03-14 16:51:43 +00001574 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001575#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1576 int xpos = x;
1577#endif
wdenke55402c2004-03-14 16:51:43 +00001578 xcount = VIDEO_LOGO_WIDTH;
1579 while (xcount--) {
Bastian Ruppertd5932182012-09-13 22:29:02 +00001580 if (black) {
1581 r = 0x00;
1582 g = 0x00;
1583 b = 0x00;
1584 } else {
1585 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1586 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1587 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1588 }
wdenk57b2d802003-06-27 21:31:46 +00001589
wdenke55402c2004-03-14 16:51:43 +00001590 switch (VIDEO_DATA_FORMAT) {
1591 case GDF__8BIT_INDEX:
1592 *dest = *source;
1593 break;
1594 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001595 *dest = ((r >> 5) << 5) |
1596 ((g >> 5) << 2) |
1597 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001598 break;
1599 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001600#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001601 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001602#else
wdenke55402c2004-03-14 16:51:43 +00001603 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001604 SWAP16((unsigned short) (
1605 ((r >> 3) << 10) |
1606 ((g >> 3) << 5) |
1607 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001608#endif
wdenke55402c2004-03-14 16:51:43 +00001609 break;
1610 case GDF_16BIT_565RGB:
1611 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001612 SWAP16((unsigned short) (
1613 ((r >> 3) << 11) |
1614 ((g >> 2) << 5) |
1615 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001616 break;
1617 case GDF_32BIT_X888RGB:
1618 *(unsigned long *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001619 SWAP32((unsigned long) (
1620 (r << 16) |
1621 (g << 8) |
1622 b));
wdenke55402c2004-03-14 16:51:43 +00001623 break;
1624 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001625#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001626 dest[0] = b;
1627 dest[1] = g;
1628 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001629#else
wdenke55402c2004-03-14 16:51:43 +00001630 dest[0] = r;
1631 dest[1] = g;
1632 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001633#endif
wdenke55402c2004-03-14 16:51:43 +00001634 break;
1635 }
1636 source++;
1637 dest += VIDEO_PIXEL_SIZE;
1638 }
1639 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001640 }
wdenk9dd2b882002-12-03 21:28:10 +00001641#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001642 free(logo_red);
1643 free(logo_green);
1644 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001645#endif
wdenkc6097192002-11-03 00:24:07 +00001646}
1647
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001648static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001649{
wdenke55402c2004-03-14 16:51:43 +00001650 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001651 int space, len;
1652 __maybe_unused int y_off = 0;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001653 __maybe_unused ulong addr;
1654 __maybe_unused char *s;
wdenke55402c2004-03-14 16:51:43 +00001655
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001656#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1657 s = getenv("splashpos");
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001658 if (s != NULL) {
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001659 if (s[0] == 'm')
1660 video_logo_xpos = BMP_ALIGN_CENTER;
1661 else
1662 video_logo_xpos = simple_strtol(s, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001663
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001664 s = strchr(s + 1, ',');
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001665 if (s != NULL) {
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001666 if (s[1] == 'm')
1667 video_logo_ypos = BMP_ALIGN_CENTER;
Matthias Weisser53884182009-07-09 16:07:30 +02001668 else
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001669 video_logo_ypos = simple_strtol(s + 1, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001670 }
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001671 }
Matthias Weisser53884182009-07-09 16:07:30 +02001672#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
wdenke55402c2004-03-14 16:51:43 +00001673
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001674#ifdef CONFIG_SPLASH_SCREEN
1675 s = getenv("splashimage");
1676 if (s != NULL) {
1677
1678 addr = simple_strtoul(s, NULL, 16);
1679
1680
1681 if (video_display_bitmap(addr,
1682 video_logo_xpos,
1683 video_logo_ypos) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001684 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001685 return ((void *) (video_fb_address));
1686 }
1687 }
1688#endif /* CONFIG_SPLASH_SCREEN */
1689
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001690 logo_plot(video_fb_address, VIDEO_COLS,
1691 video_logo_xpos, video_logo_ypos);
1692
1693#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1694 /*
1695 * when using splashpos for video_logo, skip any info
1696 * output on video console if the logo is not at 0,0
1697 */
1698 if (video_logo_xpos || video_logo_ypos) {
1699 /*
1700 * video_logo_height is used in text and cursor offset
1701 * calculations. Since the console is below the logo,
1702 * we need to adjust the logo height
1703 */
1704 if (video_logo_ypos == BMP_ALIGN_CENTER)
1705 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
1706 VIDEO_LOGO_HEIGHT) / 2);
1707 else if (video_logo_ypos > 0)
1708 video_logo_height += video_logo_ypos;
1709
1710 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1711 }
1712#endif
wdenkc6097192002-11-03 00:24:07 +00001713
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001714 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001715
1716 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1717 len = strlen(info);
1718
1719 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001720 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1721 (uchar *) info, space);
1722 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1723 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1724 (uchar *) info + space, len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001725 y_off = 1;
1726 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001727 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001728
1729#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001730 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001731 int i, n =
1732 ((video_logo_height -
1733 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001734
wdenke55402c2004-03-14 16:51:43 +00001735 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001736 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001737 if (!*info)
1738 continue;
1739
1740 len = strlen(info);
1741 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001742 video_drawchars(VIDEO_INFO_X,
1743 VIDEO_INFO_Y +
1744 (i + y_off) *
1745 VIDEO_FONT_HEIGHT,
1746 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001747 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001748 video_drawchars(VIDEO_INFO_X +
1749 VIDEO_FONT_WIDTH,
1750 VIDEO_INFO_Y +
1751 (i + y_off) *
1752 VIDEO_FONT_HEIGHT,
1753 (uchar *) info + space,
1754 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001755 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001756 video_drawstring(VIDEO_INFO_X,
1757 VIDEO_INFO_Y +
1758 (i + y_off) *
1759 VIDEO_FONT_HEIGHT,
1760 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001761 }
wdenke55402c2004-03-14 16:51:43 +00001762 }
1763 }
wdenkc6097192002-11-03 00:24:07 +00001764#endif
1765
Matthias Weisser76d70862010-01-12 12:06:31 +01001766 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001767}
1768#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001769
1770static int cfb_fb_is_in_dram(void)
1771{
1772 bd_t *bd = gd->bd;
1773#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1774defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1775 ulong start, end;
1776 int i;
1777
1778 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1779 start = bd->bi_dram[i].start;
1780 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1781 if ((ulong)video_fb_address >= start &&
1782 (ulong)video_fb_address < end)
1783 return 1;
1784 }
1785#else
1786 if ((ulong)video_fb_address >= bd->bi_memstart &&
1787 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1788 return 1;
1789#endif
1790 return 0;
1791}
wdenkc6097192002-11-03 00:24:07 +00001792
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001793static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001794{
wdenke55402c2004-03-14 16:51:43 +00001795 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001796
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001797 pGD = video_hw_init();
1798 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00001799 return -1;
wdenkc6097192002-11-03 00:24:07 +00001800
wdenke55402c2004-03-14 16:51:43 +00001801 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001802#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001803 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001804#endif
1805
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001806 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
1807
wdenke55402c2004-03-14 16:51:43 +00001808 /* Init drawing pats */
1809 switch (VIDEO_DATA_FORMAT) {
1810 case GDF__8BIT_INDEX:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001811 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
1812 CONSOLE_FG_COL);
1813 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1814 CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00001815 fgx = 0x01010101;
1816 bgx = 0x00000000;
1817 break;
1818 case GDF__8BIT_332RGB:
1819 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001820 ((CONSOLE_FG_COL >> 3) & 0x1c) |
1821 CONSOLE_FG_COL >> 6);
1822 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1823 color8;
wdenke55402c2004-03-14 16:51:43 +00001824 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001825 ((CONSOLE_BG_COL >> 3) & 0x1c) |
1826 CONSOLE_BG_COL >> 6);
1827 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1828 color8;
wdenke55402c2004-03-14 16:51:43 +00001829 break;
1830 case GDF_15BIT_555RGB:
1831 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001832 ((CONSOLE_FG_COL >> 3) << 21) |
1833 ((CONSOLE_FG_COL >> 3) << 16) |
1834 ((CONSOLE_FG_COL >> 3) << 10) |
1835 ((CONSOLE_FG_COL >> 3) << 5) |
1836 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001837 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001838 ((CONSOLE_BG_COL >> 3) << 21) |
1839 ((CONSOLE_BG_COL >> 3) << 16) |
1840 ((CONSOLE_BG_COL >> 3) << 10) |
1841 ((CONSOLE_BG_COL >> 3) << 5) |
1842 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001843 break;
1844 case GDF_16BIT_565RGB:
1845 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001846 ((CONSOLE_FG_COL >> 2) << 21) |
1847 ((CONSOLE_FG_COL >> 3) << 16) |
1848 ((CONSOLE_FG_COL >> 3) << 11) |
1849 ((CONSOLE_FG_COL >> 2) << 5) |
1850 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001851 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001852 ((CONSOLE_BG_COL >> 2) << 21) |
1853 ((CONSOLE_BG_COL >> 3) << 16) |
1854 ((CONSOLE_BG_COL >> 3) << 11) |
1855 ((CONSOLE_BG_COL >> 2) << 5) |
1856 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00001857 break;
1858 case GDF_32BIT_X888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001859 fgx = (CONSOLE_FG_COL << 16) |
1860 (CONSOLE_FG_COL << 8) |
1861 CONSOLE_FG_COL;
1862 bgx = (CONSOLE_BG_COL << 16) |
1863 (CONSOLE_BG_COL << 8) |
1864 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00001865 break;
1866 case GDF_24BIT_888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001867 fgx = (CONSOLE_FG_COL << 24) |
1868 (CONSOLE_FG_COL << 16) |
1869 (CONSOLE_FG_COL << 8) |
1870 CONSOLE_FG_COL;
1871 bgx = (CONSOLE_BG_COL << 24) |
1872 (CONSOLE_BG_COL << 16) |
1873 (CONSOLE_BG_COL << 8) |
1874 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00001875 break;
1876 }
1877 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001878
1879#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00001880 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00001881 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001882 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00001883#else
wdenke55402c2004-03-14 16:51:43 +00001884 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001885#endif
1886
wdenke55402c2004-03-14 16:51:43 +00001887 /* Initialize the console */
1888 console_col = 0;
1889 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001890
wdenke55402c2004-03-14 16:51:43 +00001891 return 0;
wdenkc6097192002-11-03 00:24:07 +00001892}
1893
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001894/*
1895 * Implement a weak default function for boards that optionally
1896 * need to skip the video initialization.
1897 */
1898int __board_video_skip(void)
1899{
1900 /* As default, don't skip test */
1901 return 0;
1902}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001903
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001904int board_video_skip(void)
1905 __attribute__ ((weak, alias("__board_video_skip")));
1906
1907int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001908{
wdenke55402c2004-03-14 16:51:43 +00001909 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02001910 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00001911
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001912 /* Check if video initialization should be skipped */
1913 if (board_video_skip())
1914 return 0;
1915
wdenk7dd13292004-07-11 20:04:51 +00001916 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001917 skip_dev_init = (video_init() == -1);
wdenkc6097192002-11-03 00:24:07 +00001918
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001919#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk46717712011-07-29 09:55:28 +00001920 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001921 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1922#endif
wdenkc6097192002-11-03 00:24:07 +00001923
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001924 if (skip_dev_init)
1925 return 0;
wdenkc6097192002-11-03 00:24:07 +00001926
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001927 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001928 memset(&console_dev, 0, sizeof(console_dev));
1929 strcpy(console_dev.name, "vga");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001930 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1931 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1932 console_dev.putc = video_putc; /* 'putc' function */
1933 console_dev.puts = video_puts; /* 'puts' function */
1934 console_dev.tstc = NULL; /* 'tstc' function */
1935 console_dev.getc = NULL; /* 'getc' function */
1936
1937#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1938 /* Also init console device */
1939 console_dev.flags |= DEV_FLAGS_INPUT;
1940 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1941 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00001942#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001943
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001944 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001945 return 0;
1946
1947 /* Return success */
1948 return 1;
wdenkc6097192002-11-03 00:24:07 +00001949}