blob: fc4ea7216cb067e905ad79e87797c3abe2560a44 [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
Bastian Ruppert1e681f92012-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 Denk64e40d72011-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ßmann09c2e902011-07-18 20:24:04 +0200106#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +0000107#include <malloc.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +0000108#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +0000109
Wolfgang Denk64e40d72011-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
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000122/*
123 * Defines for the CT69000 driver
124 */
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000132/*
133 * Defines for the SED13806 driver
134 */
wdenka6c7ad22002-12-03 21:28:10 +0000135#ifdef CONFIG_VIDEO_SED13806
136
wdenk89394042004-08-04 21:56:49 +0000137#ifndef CONFIG_TOTAL5200
wdenka6c7ad22002-12-03 21:28:10 +0000138#define VIDEO_FB_LITTLE_ENDIAN
wdenk89394042004-08-04 21:56:49 +0000139#endif
wdenka6c7ad22002-12-03 21:28:10 +0000140#define VIDEO_HW_RECTFILL
141#define VIDEO_HW_BITBLT
142#endif
143
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000144/*
145 * Defines for the SED13806 driver
146 */
Stefan Roese98f4a3d2005-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 Denk64e40d72011-07-29 09:55:27 +0000154/*
155 * Defines for the MB862xx driver
156 */
Anatolij Gustschinbed53752008-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 Gustschin5d16ca82009-10-23 12:03:14 +0200162#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100163#define VIDEO_HW_RECTFILL
164#define VIDEO_HW_BITBLT
165#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200166#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100167
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000168/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000169 * Defines for the i.MX31 driver (mx3fb.c)
170 */
Fabio Estevam695af9a2012-05-31 07:23:56 +0000171#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000172#define VIDEO_FB_16BPP_WORD_SWAP
173#endif
174
175/*
Wolfgang Denk64e40d72011-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 Denk64e40d72011-07-29 09:55:27 +0000180/*
181 * some Macros
182 */
wdenk4b248f32004-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 Denk64e40d72011-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
wdenk4b248f32004-03-14 16:51:43 +0000194#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000195#include <i8042.h>
196
wdenk4b248f32004-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 Denk64e40d72011-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-VILLARD52cb4d42009-05-16 12:14:54 +0200208#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000209#include <video_font.h>
Che-Liang Chioud3983ee2011-10-21 17:04:21 +0800210#include <video_font_data.h>
wdenkc6097192002-11-03 00:24:07 +0000211
Jon Loeligerddb5d86f2007-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 Loeliger07d38a12007-07-09 17:30:01 -0500216#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000217#include <watchdog.h>
218#include <bmp_layout.h>
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200219
220#ifdef CONFIG_SPLASH_SCREEN_ALIGN
221#define BMP_ALIGN_CENTER 0x7FFF
222#endif
223
Jon Loeliger07d38a12007-07-09 17:30:01 -0500224#endif
wdenk4b248f32004-03-14 16:51:43 +0000225
Wolfgang Denk64e40d72011-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 Black03d31fc2011-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 Denk64e40d72011-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 Denk64e40d72011-07-29 09:55:27 +0000255void console_cursor(int state);
256
Timur Tabi65618632010-08-27 15:45:47 -0500257#define CURSOR_ON console_cursor(1)
258#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-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 Ziswiler7817cb22007-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
wdenk4b248f32004-03-14 16:51:43 +0000273#ifdef CURSOR_ON
Wolfgang Denk64e40d72011-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 Tabi65618632010-08-27 15:45:47 -0500280 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000281#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000282
wdenk4b248f32004-03-14 16:51:43 +0000283#ifdef CONFIG_VIDEO_LOGO
284#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000285#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000286#include <bmp_logo_data.h>
wdenk4b248f32004-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
wdenka6c7ad22002-12-03 21:28:10 +0000291
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000292#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-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>
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000303#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000304#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
305#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000306#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000307#define VIDEO_LOGO_WIDTH 0
308#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000309#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000310
wdenk4b248f32004-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
wdenk4b248f32004-03-14 16:51:43 +0000318#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-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
wdenk4b248f32004-03-14 16:51:43 +0000321#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000322#endif
323
wdenk4b248f32004-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 */
wdenk4b248f32004-03-14 16:51:43 +0000333#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-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 Denk64e40d72011-07-29 09:55:27 +0000348#define SWAP16(x) (x)
349#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200350#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000351#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500352#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000353#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-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 Denk64e40d72011-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 Gustschinbfd4be82012-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 Denk64e40d72011-07-29 09:55:27 +0000372static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000373static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000374
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100375static int video_logo_height = VIDEO_LOGO_HEIGHT;
376
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000377static int __maybe_unused cursor_state;
378static int __maybe_unused old_col;
379static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000380
Wolfgang Denk57912932011-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 Denk64e40d72011-07-29 09:55:27 +0000384static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000385
Anatolij Gustschinbfd4be82012-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 Denk64e40d72011-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 Denk64e40d72011-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 Denk64e40d72011-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 Denk64e40d72011-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 Denk64e40d72011-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 Denk64e40d72011-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{
wdenk4b248f32004-03-14 16:51:43 +0000443 u8 *cdat, *dest, *dest0;
444 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000445
wdenk4b248f32004-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
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000456 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000457 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000458
Wolfgang Denk64e40d72011-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;
wdenk4b248f32004-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
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000476 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000477 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000478
Wolfgang Denk64e40d72011-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);
wdenk4b248f32004-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
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000506 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000507 u8 bits = *cdat++;
508
Wolfgang Denk64e40d72011-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);
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000536 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000537 u8 bits = *cdat++;
538
Wolfgang Denk64e40d72011-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);
wdenk4b248f32004-03-14 16:51:43 +0000563 }
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200564 if (cfb_do_flush_cache)
565 flush_cache((ulong)dest0, 32);
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000576 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000577 u8 bits = *cdat++;
578
Wolfgang Denk64e40d72011-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;
wdenk4b248f32004-03-14 16:51:43 +0000597 }
598 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
599 s++;
600 }
601 break;
wdenk8bde7f72003-06-27 21:31:46 +0000602 }
wdenkc6097192002-11-03 00:24:07 +0000603}
604
Wolfgang Denk64e40d72011-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 Denk64e40d72011-07-29 09:55:27 +0000607 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000608}
609
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000610static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000611{
Wolfgang Denk64e40d72011-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 Denk64e40d72011-07-29 09:55:27 +0000616static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000617{
Gabe Black03d31fc2011-11-30 13:50:50 +0000618 if (cursor_state)
619 console_cursor(0);
620 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000621}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000622
Anatolij Gustschina45adde2011-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 Gustschinbfd4be82012-06-05 09:19:18 +0200634 if (cfb_do_flush_cache)
635 flush_cache((ulong)dest, 4);
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000636 }
637 }
638}
Gabe Black03d31fc2011-11-30 13:50:50 +0000639
Wolfgang Denk64e40d72011-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
wdenk4b248f32004-03-14 16:51:43 +0000643 struct rtc_time tm;
644 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000645
wdenk4b248f32004-03-14 16:51:43 +0000646 /* time update only if cursor is on (faster scroll) */
647 if (state) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000648 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000649
Wolfgang Denk64e40d72011-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 Denk64e40d72011-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);
wdenk4b248f32004-03-14 16:51:43 +0000660 }
wdenkc6097192002-11-03 00:24:07 +0000661#endif
662
Gabe Black03d31fc2011-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;
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000683static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000684{
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000691static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000692{
wdenk4b248f32004-03-14 16:51:43 +0000693 while (c--)
694 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000695}
696#endif
697
Pali Rohár90f60a82012-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 Gustschinbfd4be82012-06-05 09:19:18 +0200731 if (cfb_do_flush_cache)
732 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
Pali Rohár90f60a82012-04-28 07:26:44 +0000733}
734
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000735static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000736{
wdenk4b248f32004-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 Denk64e40d72011-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 */
wdenk4b248f32004-03-14 16:51:43 +0000750 );
wdenkc6097192002-11-03 00:24:07 +0000751#else
Wolfgang Denk64e40d72011-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
wdenk4b248f32004-03-14 16:51:43 +0000755 /* clear the last one */
Pali Rohár90f60a82012-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 Denk64e40d72011-07-29 09:55:27 +0000759static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000760{
Timur Tabi65618632010-08-27 15:45:47 -0500761 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000762
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000771static void console_newline(void)
wdenkc6097192002-11-03 00:24:07 +0000772{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100773 console_row++;
wdenk4b248f32004-03-14 16:51:43 +0000774 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000775
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000779 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000780
wdenk4b248f32004-03-14 16:51:43 +0000781 /* Decrement row number */
782 console_row--;
783 }
wdenkc6097192002-11-03 00:24:07 +0000784}
785
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000786static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100787{
Timur Tabi65618632010-08-27 15:45:47 -0500788 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100789}
790
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000791void video_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000792{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100793 static int nl = 1;
794
Gabe Black03d31fc2011-11-30 13:50:50 +0000795 CURSOR_OFF;
796
wdenk4b248f32004-03-14 16:51:43 +0000797 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100798 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000799 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000800 break;
wdenkc6097192002-11-03 00:24:07 +0000801
wdenk4b248f32004-03-14 16:51:43 +0000802 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100803 if (console_col || (!console_col && nl))
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000804 console_newline();
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100805 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000806 break;
wdenkc6097192002-11-03 00:24:07 +0000807
wdenk4b248f32004-03-14 16:51:43 +0000808 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500809 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000810 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000811
wdenk4b248f32004-03-14 16:51:43 +0000812 if (console_col >= CONSOLE_COLS)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000813 console_newline();
wdenk4b248f32004-03-14 16:51:43 +0000814 break;
wdenkc6097192002-11-03 00:24:07 +0000815
wdenk4b248f32004-03-14 16:51:43 +0000816 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000817 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000818 break;
wdenkc6097192002-11-03 00:24:07 +0000819
Pali Rohár24fe06c2012-04-28 07:26:47 +0000820 case 7: /* bell */
821 break; /* ignored */
822
wdenk4b248f32004-03-14 16:51:43 +0000823 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000824 video_putchar(console_col * VIDEO_FONT_WIDTH,
825 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000826 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000827
wdenk4b248f32004-03-14 16:51:43 +0000828 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100829 if (console_col >= CONSOLE_COLS) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000830 console_newline();
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100831 nl = 0;
832 }
wdenk4b248f32004-03-14 16:51:43 +0000833 }
Timur Tabi65618632010-08-27 15:45:47 -0500834 CURSOR_SET;
835}
wdenkc6097192002-11-03 00:24:07 +0000836
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000837void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +0000838{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000839 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +0000840
wdenk4b248f32004-03-14 16:51:43 +0000841 while (count--)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000842 video_putc(*s++);
wdenkc6097192002-11-03 00:24:07 +0000843}
844
Anatolij Gustschin10543822010-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 Denk64e40d72011-07-29 09:55:27 +0000850void __video_set_lut(unsigned int index, unsigned char r,
851 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +0200852{
853}
Wolfgang Denk64e40d72011-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 Gustschin10543822010-05-01 22:21:09 +0200857
Jon Loeliger07d38a12007-07-09 17:30:01 -0500858#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +0000866 *(unsigned short *)fb = \
867 SWAP16((unsigned short)(((r>>3)<<10) | \
868 ((g>>3)<<5) | \
869 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +0000870 fb += 2; \
871}
872
873#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000874 *(unsigned short *)fb = \
875 SWAP16((unsigned short)((((r)>>3)<<11)| \
876 (((g)>>2)<<5) | \
877 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +0000878 fb += 2; \
879}
880
881#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000882 *(unsigned long *)fb = \
883 SWAP32((unsigned long)(((r<<16) | \
884 (g<<8) | \
885 b))); \
wdenk4b248f32004-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 Gustschine84d5682008-08-08 18:00:40 +0200905#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000906static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +0200907{
Wolfgang Denk64e40d72011-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 Gustschine84d5682008-08-08 18:00:40 +0200912 if (x & 1)
913 *(--dst) = color;
914 else
915 *(++dst) = color;
916}
917#endif
wdenk4b248f32004-03-14 16:51:43 +0000918
919/*
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +0000927 unsigned short w; /* word */
928 unsigned int dw; /* double word */
929 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +0100930};
931
932/*
933 * Helper to draw encoded/unencoded run.
934 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000935static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
936 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +0100937{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000938 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +0000952 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +0000958 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100959 addr += 2;
960 }
961 break;
962 case GDF_32BIT_X888RGB:
963 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000964 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +0100965 addr += 4;
966 }
967 break;
968 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000969 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +0100970}
971
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000972static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
973 int width, int height)
Anatolij Gustschind5011762010-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 Gustschin74446b62011-02-21 21:33:29 +0100983 int limit = VIDEO_COLS * VIDEO_ROWS;
984 int pixels = 0;
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +0000990 fbp = (unsigned char *) ((unsigned int) video_fb_address +
991 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +0100992
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000993 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001000 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001023 p[i].ce.dw = SWAP32((cte.red << 16) |
1024 (cte.green << 8) |
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001030 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001044 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001057 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-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 Gustschin74446b62011-02-21 21:33:29 +01001066 pixels += cnt;
1067 if (pixels > limit)
1068 goto error;
1069
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001078 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001079 x += runlen;
1080 }
1081next_run:
1082 bm += runlen;
1083 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001084 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001085 }
1086 break;
1087 default:
1088 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001089 cnt = bm[0];
1090 runlen = cnt;
1091 pixels += cnt;
1092 if (pixels > limit)
1093 goto error;
1094
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001095 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001103 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001104 x += runlen;
1105 }
1106 bm += 2;
1107 break;
1108 }
1109 }
1110 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001111error:
1112 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1113 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001114}
1115#endif
1116
1117/*
wdenk4b248f32004-03-14 16:51:43 +00001118 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001119 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001120int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +00001131
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001132#ifdef CONFIG_VIDEO_BMP_GZIP
1133 unsigned char *dst = NULL;
1134 ulong len;
1135#endif
wdenk4b248f32004-03-14 16:51:43 +00001136
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001137 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001138
1139 if (!((bmp->header.signature[0] == 'B') &&
1140 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-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-VILLARD6d0f6bc2008-10-16 15:01:15 +02001146 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1147 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001148 if (dst == NULL) {
1149 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001150 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001151 }
Wolfgang Denk64e40d72011-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 Roese98f4a3d2005-09-22 09:04:17 +02001157 free(dst);
1158 return 1;
1159 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001160 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001161 printf("Image could be truncated "
1162 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001163 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001164
1165 /*
1166 * Set addr to decompressed image
1167 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001168 bmp = (bmp_image_t *) dst;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001169
1170 if (!((bmp->header.signature[0] == 'B') &&
1171 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001172 printf("Error: no valid bmp.gz image at %lx\n",
1173 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001174 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001175 return 1;
1176 }
1177#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001178 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001179 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001180#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001181 }
1182
Wolfgang Denk64e40d72011-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);
wdenk4b248f32004-03-14 16:51:43 +00001188
Marek Vasut68da5b12011-10-21 14:17:04 +00001189 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001190 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001191
Anatolij Gustschind5011762010-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 Denk64e40d72011-07-29 09:55:27 +00001196 ) {
1197 printf("Error: compression type %ld not supported\n",
1198 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001199#ifdef CONFIG_VIDEO_BMP_GZIP
1200 if (dst)
1201 free(dst);
1202#endif
wdenk4b248f32004-03-14 16:51:43 +00001203 return 1;
1204 }
1205
1206 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1207
Matthias Weisser1ca298c2009-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
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +00001225 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-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 Gustschind5011762010-03-15 14:50:25 +01001230#ifdef CONFIG_VIDEO_BMP_RLE8
1231 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001232 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001233 }
1234#endif
1235
Timur Tabi68f66182010-08-23 16:58:00 -05001236 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001237 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-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 Denk64e40d72011-07-29 09:55:27 +00001245 WATCHDOG_RESET();
Timur Tabi68f66182010-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 Denk64e40d72011-07-29 09:55:27 +00001264 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-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
wdenk4b248f32004-03-14 16:51:43 +00001274 case 8:
1275 padded_line -= width;
1276 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001277 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001278 for (xcount = 0; xcount < colors; ++xcount) {
1279 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001280 video_set_lut(xcount, cte.red, cte.green,
1281 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001282 }
1283 }
1284 ycount = height;
1285 switch (VIDEO_DATA_FORMAT) {
1286 case GDF__8BIT_INDEX:
1287 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001288 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001289 xcount = width;
1290 while (xcount--) {
1291 *fb++ = *bmap++;
1292 }
1293 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001294 fb -= (VIDEO_VISIBLE_COLS + width) *
1295 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001296 }
1297 break;
1298 case GDF__8BIT_332RGB:
1299 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001300 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001301 xcount = width;
1302 while (xcount--) {
1303 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001304 FILL_8BIT_332RGB(cte.red, cte.green,
1305 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001306 }
1307 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001308 fb -= (VIDEO_VISIBLE_COLS + width) *
1309 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001310 }
1311 break;
1312 case GDF_15BIT_555RGB:
1313 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001314#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1315 int xpos = x;
1316#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001317 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001318 xcount = width;
1319 while (xcount--) {
1320 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001321#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001322 fill_555rgb_pswap(fb, xpos++, cte.red,
1323 cte.green,
1324 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001325 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001326#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001327 FILL_15BIT_555RGB(cte.red, cte.green,
1328 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001329#endif
wdenk4b248f32004-03-14 16:51:43 +00001330 }
1331 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001332 fb -= (VIDEO_VISIBLE_COLS + width) *
1333 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001334 }
1335 break;
1336 case GDF_16BIT_565RGB:
1337 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001338 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001339 xcount = width;
1340 while (xcount--) {
1341 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001342 FILL_16BIT_565RGB(cte.red, cte.green,
1343 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001344 }
1345 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001346 fb -= (VIDEO_VISIBLE_COLS + width) *
1347 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001348 }
1349 break;
1350 case GDF_32BIT_X888RGB:
1351 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001352 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001353 xcount = width;
1354 while (xcount--) {
1355 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001356 FILL_32BIT_X888RGB(cte.red, cte.green,
1357 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001358 }
1359 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001360 fb -= (VIDEO_VISIBLE_COLS + width) *
1361 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001362 }
1363 break;
1364 case GDF_24BIT_888RGB:
1365 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001366 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001367 xcount = width;
1368 while (xcount--) {
1369 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001370 FILL_24BIT_888RGB(cte.red, cte.green,
1371 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001372 }
1373 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001374 fb -= (VIDEO_VISIBLE_COLS + width) *
1375 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-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 Denk64e40d72011-07-29 09:55:27 +00001386 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001387 xcount = width;
1388 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001389 FILL_8BIT_332RGB(bmap[2], bmap[1],
1390 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001391 bmap += 3;
1392 }
1393 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001394 fb -= (VIDEO_VISIBLE_COLS + width) *
1395 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001396 }
1397 break;
1398 case GDF_15BIT_555RGB:
1399 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001400#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1401 int xpos = x;
1402#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001403 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001404 xcount = width;
1405 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001406#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001407 fill_555rgb_pswap(fb, xpos++, bmap[2],
1408 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001409 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001410#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001411 FILL_15BIT_555RGB(bmap[2], bmap[1],
1412 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001413#endif
wdenk4b248f32004-03-14 16:51:43 +00001414 bmap += 3;
1415 }
1416 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001417 fb -= (VIDEO_VISIBLE_COLS + width) *
1418 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001419 }
1420 break;
1421 case GDF_16BIT_565RGB:
1422 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001423 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001424 xcount = width;
1425 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001426 FILL_16BIT_565RGB(bmap[2], bmap[1],
1427 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001428 bmap += 3;
1429 }
1430 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001431 fb -= (VIDEO_VISIBLE_COLS + width) *
1432 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001433 }
1434 break;
1435 case GDF_32BIT_X888RGB:
1436 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001437 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001438 xcount = width;
1439 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001440 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1441 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001442 bmap += 3;
1443 }
1444 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001445 fb -= (VIDEO_VISIBLE_COLS + width) *
1446 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001447 }
1448 break;
1449 case GDF_24BIT_888RGB:
1450 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001451 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001452 xcount = width;
1453 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001454 FILL_24BIT_888RGB(bmap[2], bmap[1],
1455 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001456 bmap += 3;
1457 }
1458 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001459 fb -= (VIDEO_VISIBLE_COLS + width) *
1460 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001461 }
1462 break;
1463 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001464 printf("Error: 24 bits/pixel bitmap incompatible "
1465 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001466 break;
1467 }
1468 break;
1469 default:
Wolfgang Denk64e40d72011-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));
wdenk4b248f32004-03-14 16:51:43 +00001472 break;
1473 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001474
1475#ifdef CONFIG_VIDEO_BMP_GZIP
1476 if (dst) {
1477 free(dst);
1478 }
1479#endif
1480
wdenk4b248f32004-03-14 16:51:43 +00001481 return (0);
1482}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001483#endif
wdenk4b248f32004-03-14 16:51:43 +00001484
wdenk4b248f32004-03-14 16:51:43 +00001485
wdenkc6097192002-11-03 00:24:07 +00001486#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001487static int video_logo_xpos;
1488static int video_logo_ypos;
1489
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001490void logo_plot(void *screen, int width, int x, int y)
wdenkc6097192002-11-03 00:24:07 +00001491{
wdenkc6097192002-11-03 00:24:07 +00001492
wdenk4b248f32004-03-14 16:51:43 +00001493 int xcount, i;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001494 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001495 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001496 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1497 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001498 unsigned char *dest;
1499
1500#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1501 if (x == BMP_ALIGN_CENTER)
1502 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1503 else if (x < 0)
1504 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1505
1506 if (y == BMP_ALIGN_CENTER)
1507 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1508 else if (y < 0)
1509 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1510#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1511
1512 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001513
1514#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001515 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001516
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001517 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001518 logo_red = malloc(BMP_LOGO_COLORS);
1519 logo_green = malloc(BMP_LOGO_COLORS);
1520 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001521 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001522 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1523 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1524 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1525 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1526 }
wdenka6c7ad22002-12-03 21:28:10 +00001527#else
wdenk4b248f32004-03-14 16:51:43 +00001528 source = linux_logo;
1529 logo_red = linux_logo_red;
1530 logo_green = linux_logo_green;
1531 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001532#endif
wdenk8bde7f72003-06-27 21:31:46 +00001533
wdenk4b248f32004-03-14 16:51:43 +00001534 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1535 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001536 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1537 logo_red[i], logo_green[i],
1538 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001539 }
wdenk8bde7f72003-06-27 21:31:46 +00001540 }
wdenkc6097192002-11-03 00:24:07 +00001541
wdenk4b248f32004-03-14 16:51:43 +00001542 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001543#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1544 int xpos = x;
1545#endif
wdenk4b248f32004-03-14 16:51:43 +00001546 xcount = VIDEO_LOGO_WIDTH;
1547 while (xcount--) {
1548 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1549 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1550 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
wdenk8bde7f72003-06-27 21:31:46 +00001551
wdenk4b248f32004-03-14 16:51:43 +00001552 switch (VIDEO_DATA_FORMAT) {
1553 case GDF__8BIT_INDEX:
1554 *dest = *source;
1555 break;
1556 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001557 *dest = ((r >> 5) << 5) |
1558 ((g >> 5) << 2) |
1559 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001560 break;
1561 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001562#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001563 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001564#else
wdenk4b248f32004-03-14 16:51:43 +00001565 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001566 SWAP16((unsigned short) (
1567 ((r >> 3) << 10) |
1568 ((g >> 3) << 5) |
1569 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001570#endif
wdenk4b248f32004-03-14 16:51:43 +00001571 break;
1572 case GDF_16BIT_565RGB:
1573 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001574 SWAP16((unsigned short) (
1575 ((r >> 3) << 11) |
1576 ((g >> 2) << 5) |
1577 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001578 break;
1579 case GDF_32BIT_X888RGB:
1580 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001581 SWAP32((unsigned long) (
1582 (r << 16) |
1583 (g << 8) |
1584 b));
wdenk4b248f32004-03-14 16:51:43 +00001585 break;
1586 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001587#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001588 dest[0] = b;
1589 dest[1] = g;
1590 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001591#else
wdenk4b248f32004-03-14 16:51:43 +00001592 dest[0] = r;
1593 dest[1] = g;
1594 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001595#endif
wdenk4b248f32004-03-14 16:51:43 +00001596 break;
1597 }
1598 source++;
1599 dest += VIDEO_PIXEL_SIZE;
1600 }
1601 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001602 }
wdenka6c7ad22002-12-03 21:28:10 +00001603#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001604 free(logo_red);
1605 free(logo_green);
1606 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001607#endif
wdenkc6097192002-11-03 00:24:07 +00001608}
1609
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001610static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001611{
wdenk4b248f32004-03-14 16:51:43 +00001612 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001613 int space, len;
1614 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001615 __maybe_unused ulong addr;
1616 __maybe_unused char *s;
wdenkc6097192002-11-03 00:24:07 +00001617
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001618#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001619 s = getenv("splashpos");
1620 if (s != NULL) {
1621 if (s[0] == 'm')
1622 video_logo_xpos = BMP_ALIGN_CENTER;
1623 else
1624 video_logo_xpos = simple_strtol(s, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001625
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001626 s = strchr(s + 1, ',');
1627 if (s != NULL) {
1628 if (s[1] == 'm')
1629 video_logo_ypos = BMP_ALIGN_CENTER;
1630 else
1631 video_logo_ypos = simple_strtol(s + 1, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001632 }
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001633 }
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001634#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1635
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001636#ifdef CONFIG_SPLASH_SCREEN
1637 s = getenv("splashimage");
1638 if (s != NULL) {
1639
1640 addr = simple_strtoul(s, NULL, 16);
1641
1642
1643 if (video_display_bitmap(addr,
1644 video_logo_xpos,
1645 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001646 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00001647 return ((void *) (video_fb_address));
1648 }
1649 }
1650#endif /* CONFIG_SPLASH_SCREEN */
1651
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001652 logo_plot(video_fb_address, VIDEO_COLS,
1653 video_logo_xpos, video_logo_ypos);
1654
1655#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1656 /*
1657 * when using splashpos for video_logo, skip any info
1658 * output on video console if the logo is not at 0,0
1659 */
1660 if (video_logo_xpos || video_logo_ypos) {
1661 /*
1662 * video_logo_height is used in text and cursor offset
1663 * calculations. Since the console is below the logo,
1664 * we need to adjust the logo height
1665 */
1666 if (video_logo_ypos == BMP_ALIGN_CENTER)
1667 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
1668 VIDEO_LOGO_HEIGHT) / 2);
1669 else if (video_logo_ypos > 0)
1670 video_logo_height += video_logo_ypos;
1671
1672 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1673 }
1674#endif
wdenk4b248f32004-03-14 16:51:43 +00001675
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001676 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001677
1678 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1679 len = strlen(info);
1680
1681 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001682 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1683 (uchar *) info, space);
1684 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1685 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1686 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001687 y_off = 1;
1688 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001689 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001690
1691#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00001692 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001693 int i, n =
1694 ((video_logo_height -
1695 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001696
wdenk4b248f32004-03-14 16:51:43 +00001697 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001698 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001699 if (!*info)
1700 continue;
1701
1702 len = strlen(info);
1703 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001704 video_drawchars(VIDEO_INFO_X,
1705 VIDEO_INFO_Y +
1706 (i + y_off) *
1707 VIDEO_FONT_HEIGHT,
1708 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001709 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001710 video_drawchars(VIDEO_INFO_X +
1711 VIDEO_FONT_WIDTH,
1712 VIDEO_INFO_Y +
1713 (i + y_off) *
1714 VIDEO_FONT_HEIGHT,
1715 (uchar *) info + space,
1716 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001717 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001718 video_drawstring(VIDEO_INFO_X,
1719 VIDEO_INFO_Y +
1720 (i + y_off) *
1721 VIDEO_FONT_HEIGHT,
1722 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001723 }
wdenk4b248f32004-03-14 16:51:43 +00001724 }
1725 }
wdenkc6097192002-11-03 00:24:07 +00001726#endif
1727
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001728 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001729}
1730#endif
1731
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001732static int cfb_fb_is_in_dram(void)
1733{
1734 bd_t *bd = gd->bd;
1735#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1736defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1737 ulong start, end;
1738 int i;
1739
1740 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1741 start = bd->bi_dram[i].start;
1742 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1743 if ((ulong)video_fb_address >= start &&
1744 (ulong)video_fb_address < end)
1745 return 1;
1746 }
1747#else
1748 if ((ulong)video_fb_address >= bd->bi_memstart &&
1749 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1750 return 1;
1751#endif
1752 return 0;
1753}
1754
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001755static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001756{
wdenk4b248f32004-03-14 16:51:43 +00001757 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001758
Wolfgang Denk57912932011-07-30 12:48:09 +00001759 pGD = video_hw_init();
1760 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00001761 return -1;
wdenkc6097192002-11-03 00:24:07 +00001762
wdenk4b248f32004-03-14 16:51:43 +00001763 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001764#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001765 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001766#endif
1767
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001768 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
1769
wdenk4b248f32004-03-14 16:51:43 +00001770 /* Init drawing pats */
1771 switch (VIDEO_DATA_FORMAT) {
1772 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001773 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
1774 CONSOLE_FG_COL);
1775 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
1776 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00001777 fgx = 0x01010101;
1778 bgx = 0x00000000;
1779 break;
1780 case GDF__8BIT_332RGB:
1781 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001782 ((CONSOLE_FG_COL >> 3) & 0x1c) |
1783 CONSOLE_FG_COL >> 6);
1784 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1785 color8;
wdenk4b248f32004-03-14 16:51:43 +00001786 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001787 ((CONSOLE_BG_COL >> 3) & 0x1c) |
1788 CONSOLE_BG_COL >> 6);
1789 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1790 color8;
wdenk4b248f32004-03-14 16:51:43 +00001791 break;
1792 case GDF_15BIT_555RGB:
1793 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001794 ((CONSOLE_FG_COL >> 3) << 21) |
1795 ((CONSOLE_FG_COL >> 3) << 16) |
1796 ((CONSOLE_FG_COL >> 3) << 10) |
1797 ((CONSOLE_FG_COL >> 3) << 5) |
1798 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001799 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001800 ((CONSOLE_BG_COL >> 3) << 21) |
1801 ((CONSOLE_BG_COL >> 3) << 16) |
1802 ((CONSOLE_BG_COL >> 3) << 10) |
1803 ((CONSOLE_BG_COL >> 3) << 5) |
1804 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001805 break;
1806 case GDF_16BIT_565RGB:
1807 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001808 ((CONSOLE_FG_COL >> 2) << 21) |
1809 ((CONSOLE_FG_COL >> 3) << 16) |
1810 ((CONSOLE_FG_COL >> 3) << 11) |
1811 ((CONSOLE_FG_COL >> 2) << 5) |
1812 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001813 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001814 ((CONSOLE_BG_COL >> 2) << 21) |
1815 ((CONSOLE_BG_COL >> 3) << 16) |
1816 ((CONSOLE_BG_COL >> 3) << 11) |
1817 ((CONSOLE_BG_COL >> 2) << 5) |
1818 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001819 break;
1820 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001821 fgx = (CONSOLE_FG_COL << 16) |
1822 (CONSOLE_FG_COL << 8) |
1823 CONSOLE_FG_COL;
1824 bgx = (CONSOLE_BG_COL << 16) |
1825 (CONSOLE_BG_COL << 8) |
1826 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001827 break;
1828 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001829 fgx = (CONSOLE_FG_COL << 24) |
1830 (CONSOLE_FG_COL << 16) |
1831 (CONSOLE_FG_COL << 8) |
1832 CONSOLE_FG_COL;
1833 bgx = (CONSOLE_BG_COL << 24) |
1834 (CONSOLE_BG_COL << 16) |
1835 (CONSOLE_BG_COL << 8) |
1836 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001837 break;
1838 }
1839 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001840
1841#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001842 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00001843 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001844 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00001845#else
wdenk4b248f32004-03-14 16:51:43 +00001846 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001847#endif
1848
wdenk4b248f32004-03-14 16:51:43 +00001849 /* Initialize the console */
1850 console_col = 0;
1851 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001852
wdenk4b248f32004-03-14 16:51:43 +00001853 return 0;
wdenkc6097192002-11-03 00:24:07 +00001854}
1855
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001856/*
1857 * Implement a weak default function for boards that optionally
1858 * need to skip the video initialization.
1859 */
1860int __board_video_skip(void)
1861{
1862 /* As default, don't skip test */
1863 return 0;
1864}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001865
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001866int board_video_skip(void)
1867 __attribute__ ((weak, alias("__board_video_skip")));
1868
1869int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001870{
wdenk4b248f32004-03-14 16:51:43 +00001871 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02001872 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00001873
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001874 /* Check if video initialization should be skipped */
1875 if (board_video_skip())
1876 return 0;
1877
wdenk81050922004-07-11 20:04:51 +00001878 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001879 skip_dev_init = (video_init() == -1);
wdenk81050922004-07-11 20:04:51 +00001880
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001881#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk72c65f62011-07-29 09:55:28 +00001882 debug("KBD: Keyboard init ...\n");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001883 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1884#endif
wdenkc6097192002-11-03 00:24:07 +00001885
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001886 if (skip_dev_init)
1887 return 0;
wdenkc6097192002-11-03 00:24:07 +00001888
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001889 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001890 memset(&console_dev, 0, sizeof(console_dev));
1891 strcpy(console_dev.name, "vga");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001892 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1893 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1894 console_dev.putc = video_putc; /* 'putc' function */
1895 console_dev.puts = video_puts; /* 'puts' function */
1896 console_dev.tstc = NULL; /* 'tstc' function */
1897 console_dev.getc = NULL; /* 'getc' function */
1898
1899#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1900 /* Also init console device */
1901 console_dev.flags |= DEV_FLAGS_INPUT;
1902 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1903 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00001904#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001905
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001906 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001907 return 0;
1908
1909 /* Return success */
1910 return 1;
wdenkc6097192002-11-03 00:24:07 +00001911}