blob: 9c67b63bf4504e2345f733a9cec5485a7f52be69 [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
Pali Rohár33a35bb2012-10-19 13:30:09 +0000388#ifdef CONFIG_CFB_CONSOLE_ANSI
389static char ansi_buf[10];
390static int ansi_buf_size;
391static int ansi_colors_need_revert;
392static int ansi_cursor_hidden;
393#endif
394
wdenkc6097192002-11-03 00:24:07 +0000395static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000396 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
397 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
398 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
399 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
400};
wdenkc6097192002-11-03 00:24:07 +0000401
402static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000403 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
404};
wdenkc6097192002-11-03 00:24:07 +0000405
406static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000407 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
408};
wdenkc6097192002-11-03 00:24:07 +0000409
410static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000411 {0x00000000, 0x00000000, 0x00000000},
412 {0x00000000, 0x00000000, 0x00ffffff},
413 {0x00000000, 0x0000ffff, 0xff000000},
414 {0x00000000, 0x0000ffff, 0xffffffff},
415 {0x000000ff, 0xffff0000, 0x00000000},
416 {0x000000ff, 0xffff0000, 0x00ffffff},
417 {0x000000ff, 0xffffffff, 0xff000000},
418 {0x000000ff, 0xffffffff, 0xffffffff},
419 {0xffffff00, 0x00000000, 0x00000000},
420 {0xffffff00, 0x00000000, 0x00ffffff},
421 {0xffffff00, 0x0000ffff, 0xff000000},
422 {0xffffff00, 0x0000ffff, 0xffffffff},
423 {0xffffffff, 0xffff0000, 0x00000000},
424 {0xffffffff, 0xffff0000, 0x00ffffff},
425 {0xffffffff, 0xffffffff, 0xff000000},
426 {0xffffffff, 0xffffffff, 0xffffffff}
427};
wdenkc6097192002-11-03 00:24:07 +0000428
429static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000430 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
431 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
432 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
433 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
434 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
435 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
436 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
437 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
438 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
439 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
440 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
441 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
442 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
443 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
444 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
445 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
446};
wdenkc6097192002-11-03 00:24:07 +0000447
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000448static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000449{
wdenk4b248f32004-03-14 16:51:43 +0000450 u8 *cdat, *dest, *dest0;
451 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000452
wdenk4b248f32004-03-14 16:51:43 +0000453 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
454 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000455
wdenk4b248f32004-03-14 16:51:43 +0000456 switch (VIDEO_DATA_FORMAT) {
457 case GDF__8BIT_INDEX:
458 case GDF__8BIT_332RGB:
459 while (count--) {
460 c = *s;
461 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
462 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000463 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000464 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000465
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000466 ((u32 *) dest)[0] =
467 (video_font_draw_table8[bits >> 4] &
468 eorx) ^ bgx;
469 ((u32 *) dest)[1] =
470 (video_font_draw_table8[bits & 15] &
471 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000472 }
473 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
474 s++;
475 }
476 break;
wdenkc6097192002-11-03 00:24:07 +0000477
wdenk4b248f32004-03-14 16:51:43 +0000478 case GDF_15BIT_555RGB:
479 while (count--) {
480 c = *s;
481 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
482 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000483 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000484 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000485
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000486 ((u32 *) dest)[0] =
487 SHORTSWAP32((video_font_draw_table15
488 [bits >> 6] & eorx) ^
489 bgx);
490 ((u32 *) dest)[1] =
491 SHORTSWAP32((video_font_draw_table15
492 [bits >> 4 & 3] & eorx) ^
493 bgx);
494 ((u32 *) dest)[2] =
495 SHORTSWAP32((video_font_draw_table15
496 [bits >> 2 & 3] & eorx) ^
497 bgx);
498 ((u32 *) dest)[3] =
499 SHORTSWAP32((video_font_draw_table15
500 [bits & 3] & eorx) ^
501 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000502 }
503 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
504 s++;
505 }
506 break;
wdenkc6097192002-11-03 00:24:07 +0000507
wdenk4b248f32004-03-14 16:51:43 +0000508 case GDF_16BIT_565RGB:
509 while (count--) {
510 c = *s;
511 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
512 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000513 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000514 u8 bits = *cdat++;
515
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000516 ((u32 *) dest)[0] =
517 SHORTSWAP32((video_font_draw_table16
518 [bits >> 6] & eorx) ^
519 bgx);
520 ((u32 *) dest)[1] =
521 SHORTSWAP32((video_font_draw_table16
522 [bits >> 4 & 3] & eorx) ^
523 bgx);
524 ((u32 *) dest)[2] =
525 SHORTSWAP32((video_font_draw_table16
526 [bits >> 2 & 3] & eorx) ^
527 bgx);
528 ((u32 *) dest)[3] =
529 SHORTSWAP32((video_font_draw_table16
530 [bits & 3] & eorx) ^
531 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000532 }
533 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
534 s++;
535 }
536 break;
537
538 case GDF_32BIT_X888RGB:
539 while (count--) {
540 c = *s;
541 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
542 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000543 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000544 u8 bits = *cdat++;
545
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000546 ((u32 *) dest)[0] =
547 SWAP32((video_font_draw_table32
548 [bits >> 4][0] & eorx) ^ bgx);
549 ((u32 *) dest)[1] =
550 SWAP32((video_font_draw_table32
551 [bits >> 4][1] & eorx) ^ bgx);
552 ((u32 *) dest)[2] =
553 SWAP32((video_font_draw_table32
554 [bits >> 4][2] & eorx) ^ bgx);
555 ((u32 *) dest)[3] =
556 SWAP32((video_font_draw_table32
557 [bits >> 4][3] & eorx) ^ bgx);
558 ((u32 *) dest)[4] =
559 SWAP32((video_font_draw_table32
560 [bits & 15][0] & eorx) ^ bgx);
561 ((u32 *) dest)[5] =
562 SWAP32((video_font_draw_table32
563 [bits & 15][1] & eorx) ^ bgx);
564 ((u32 *) dest)[6] =
565 SWAP32((video_font_draw_table32
566 [bits & 15][2] & eorx) ^ bgx);
567 ((u32 *) dest)[7] =
568 SWAP32((video_font_draw_table32
569 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000570 }
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200571 if (cfb_do_flush_cache)
572 flush_cache((ulong)dest0, 32);
wdenk4b248f32004-03-14 16:51:43 +0000573 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
574 s++;
575 }
576 break;
577
578 case GDF_24BIT_888RGB:
579 while (count--) {
580 c = *s;
581 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
582 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000583 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000584 u8 bits = *cdat++;
585
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000586 ((u32 *) dest)[0] =
587 (video_font_draw_table24[bits >> 4][0]
588 & eorx) ^ bgx;
589 ((u32 *) dest)[1] =
590 (video_font_draw_table24[bits >> 4][1]
591 & eorx) ^ bgx;
592 ((u32 *) dest)[2] =
593 (video_font_draw_table24[bits >> 4][2]
594 & eorx) ^ bgx;
595 ((u32 *) dest)[3] =
596 (video_font_draw_table24[bits & 15][0]
597 & eorx) ^ bgx;
598 ((u32 *) dest)[4] =
599 (video_font_draw_table24[bits & 15][1]
600 & eorx) ^ bgx;
601 ((u32 *) dest)[5] =
602 (video_font_draw_table24[bits & 15][2]
603 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000604 }
605 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
606 s++;
607 }
608 break;
wdenk8bde7f72003-06-27 21:31:46 +0000609 }
wdenkc6097192002-11-03 00:24:07 +0000610}
611
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000612static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000613{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000614 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000615}
616
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000617static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000618{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000619 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000620}
621
wdenkc6097192002-11-03 00:24:07 +0000622#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000623static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000624{
Gabe Black03d31fc2011-11-30 13:50:50 +0000625 if (cursor_state)
626 console_cursor(0);
627 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000628}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000629
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000630static void video_invertchar(int xx, int yy)
631{
632 int firstx = xx * VIDEO_PIXEL_SIZE;
633 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
634 int firsty = yy * VIDEO_LINE_LEN;
635 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
636 int x, y;
637 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
638 for (x = firstx; x < lastx; x++) {
639 u8 *dest = (u8 *)(video_fb_address) + x + y;
640 *dest = ~*dest;
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200641 if (cfb_do_flush_cache)
642 flush_cache((ulong)dest, 4);
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000643 }
644 }
645}
Gabe Black03d31fc2011-11-30 13:50:50 +0000646
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000647void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000648{
wdenkc6097192002-11-03 00:24:07 +0000649#ifdef CONFIG_CONSOLE_TIME
wdenk4b248f32004-03-14 16:51:43 +0000650 struct rtc_time tm;
651 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000652
wdenk4b248f32004-03-14 16:51:43 +0000653 /* time update only if cursor is on (faster scroll) */
654 if (state) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000655 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000656
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000657 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
658 tm.tm_sec);
659 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
660 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000661
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000662 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
663 tm.tm_year);
664 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
665 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
666 (uchar *) info);
wdenk4b248f32004-03-14 16:51:43 +0000667 }
wdenkc6097192002-11-03 00:24:07 +0000668#endif
669
Gabe Black03d31fc2011-11-30 13:50:50 +0000670 if (cursor_state != state) {
671 if (cursor_state) {
672 /* turn off the cursor */
673 video_invertchar(old_col * VIDEO_FONT_WIDTH,
674 old_row * VIDEO_FONT_HEIGHT +
675 video_logo_height);
676 } else {
677 /* turn off the cursor and record where it is */
678 video_invertchar(console_col * VIDEO_FONT_WIDTH,
679 console_row * VIDEO_FONT_HEIGHT +
680 video_logo_height);
681 old_col = console_col;
682 old_row = console_row;
683 }
684 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000685 }
wdenkc6097192002-11-03 00:24:07 +0000686}
687#endif
688
wdenkc6097192002-11-03 00:24:07 +0000689#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000690static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000691{
wdenk4b248f32004-03-14 16:51:43 +0000692 while (c--)
693 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000694}
695#endif
696
wdenkc6097192002-11-03 00:24:07 +0000697#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000698static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000699{
wdenk4b248f32004-03-14 16:51:43 +0000700 while (c--)
701 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000702}
703#endif
704
Pali Rohár90f60a82012-04-28 07:26:44 +0000705static void console_clear_line(int line, int begin, int end)
706{
707#ifdef VIDEO_HW_RECTFILL
708 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
709 VIDEO_FONT_WIDTH * begin, /* dest pos x */
710 video_logo_height +
711 VIDEO_FONT_HEIGHT * line, /* dest pos y */
712 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
713 VIDEO_FONT_HEIGHT, /* frame height */
714 bgx /* fill color */
715 );
716#else
717 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
718 memsetl(CONSOLE_ROW_FIRST +
719 CONSOLE_ROW_SIZE * line, /* offset of row */
720 CONSOLE_ROW_SIZE >> 2, /* length of row */
721 bgx /* fill color */
722 );
723 } else {
724 void *offset;
725 int i, size;
726
727 offset = CONSOLE_ROW_FIRST +
728 CONSOLE_ROW_SIZE * line + /* offset of row */
729 VIDEO_FONT_WIDTH *
730 VIDEO_PIXEL_SIZE * begin; /* offset of col */
731 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
732 size >>= 2; /* length to end for memsetl() */
733 /* fill at col offset of i'th line using bgx as fill color */
734 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
735 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
736 }
737#endif
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200738 if (cfb_do_flush_cache)
739 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
Pali Rohár90f60a82012-04-28 07:26:44 +0000740}
741
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000742static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000743{
wdenk4b248f32004-03-14 16:51:43 +0000744 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000745
746#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000747 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
748 0, /* source pos x */
749 video_logo_height +
750 VIDEO_FONT_HEIGHT, /* source pos y */
751 0, /* dest pos x */
752 video_logo_height, /* dest pos y */
753 VIDEO_VISIBLE_COLS, /* frame width */
754 VIDEO_VISIBLE_ROWS
755 - video_logo_height
756 - VIDEO_FONT_HEIGHT /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000757 );
wdenkc6097192002-11-03 00:24:07 +0000758#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000759 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
760 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000761#endif
wdenk4b248f32004-03-14 16:51:43 +0000762 /* clear the last one */
Pali Rohár90f60a82012-04-28 07:26:44 +0000763 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
wdenkc6097192002-11-03 00:24:07 +0000764}
765
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000766static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000767{
Timur Tabi65618632010-08-27 15:45:47 -0500768 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000769
wdenk4b248f32004-03-14 16:51:43 +0000770 if (console_col < 0) {
771 console_col = CONSOLE_COLS - 1;
772 console_row--;
773 if (console_row < 0)
774 console_row = 0;
775 }
wdenkc6097192002-11-03 00:24:07 +0000776}
777
Pali Rohár33a35bb2012-10-19 13:30:09 +0000778#ifdef CONFIG_CFB_CONSOLE_ANSI
779
780static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000781{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000782#ifdef VIDEO_HW_RECTFILL
783 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
784 0, /* dest pos x */
785 video_logo_height, /* dest pos y */
786 VIDEO_VISIBLE_COLS, /* frame width */
787 VIDEO_VISIBLE_ROWS, /* frame height */
788 bgx /* fill color */
789 );
790#else
791 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
792#endif
793}
794
795static void console_cursor_fix(void)
796{
797 if (console_row < 0)
798 console_row = 0;
799 if (console_row >= CONSOLE_ROWS)
800 console_row = CONSOLE_ROWS - 1;
801 if (console_col < 0)
802 console_col = 0;
803 if (console_col >= CONSOLE_COLS)
804 console_col = CONSOLE_COLS - 1;
805}
806
807static void console_cursor_up(int n)
808{
809 console_row -= n;
810 console_cursor_fix();
811}
812
813static void console_cursor_down(int n)
814{
815 console_row += n;
816 console_cursor_fix();
817}
818
819static void console_cursor_left(int n)
820{
821 console_col -= n;
822 console_cursor_fix();
823}
824
825static void console_cursor_right(int n)
826{
827 console_col += n;
828 console_cursor_fix();
829}
830
831static void console_cursor_set_position(int row, int col)
832{
833 if (console_row != -1)
834 console_row = row;
835 if (console_col != -1)
836 console_col = col;
837 console_cursor_fix();
838}
839
840static void console_previousline(int n)
841{
842 /* FIXME: also scroll terminal ? */
843 console_row -= n;
844 console_cursor_fix();
845}
846
847static void console_swap_colors(void)
848{
849 eorx = fgx;
850 fgx = bgx;
851 bgx = eorx;
852 eorx = fgx ^ bgx;
853}
854
855static inline int console_cursor_is_visible(void)
856{
857 return !ansi_cursor_hidden;
858}
859#else
860static inline int console_cursor_is_visible(void)
861{
862 return 1;
863}
864#endif
865
866static void console_newline(int n)
867{
868 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000869 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000870
wdenk4b248f32004-03-14 16:51:43 +0000871 /* Check if we need to scroll the terminal */
872 if (console_row >= CONSOLE_ROWS) {
873 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000874 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000875
wdenk4b248f32004-03-14 16:51:43 +0000876 /* Decrement row number */
Pali Rohár33a35bb2012-10-19 13:30:09 +0000877 console_row = CONSOLE_ROWS - 1;
wdenk4b248f32004-03-14 16:51:43 +0000878 }
wdenkc6097192002-11-03 00:24:07 +0000879}
880
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000881static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100882{
Timur Tabi65618632010-08-27 15:45:47 -0500883 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100884}
885
Pali Rohár33a35bb2012-10-19 13:30:09 +0000886static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000887{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100888 static int nl = 1;
889
Pali Rohár33a35bb2012-10-19 13:30:09 +0000890 if (console_cursor_is_visible())
891 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000892
wdenk4b248f32004-03-14 16:51:43 +0000893 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100894 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000895 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000896 break;
wdenkc6097192002-11-03 00:24:07 +0000897
wdenk4b248f32004-03-14 16:51:43 +0000898 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100899 if (console_col || (!console_col && nl))
Pali Rohár33a35bb2012-10-19 13:30:09 +0000900 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100901 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000902 break;
wdenkc6097192002-11-03 00:24:07 +0000903
wdenk4b248f32004-03-14 16:51:43 +0000904 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500905 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000906 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000907
wdenk4b248f32004-03-14 16:51:43 +0000908 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000909 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000910 break;
wdenkc6097192002-11-03 00:24:07 +0000911
wdenk4b248f32004-03-14 16:51:43 +0000912 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000913 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000914 break;
wdenkc6097192002-11-03 00:24:07 +0000915
Pali Rohár24fe06c2012-04-28 07:26:47 +0000916 case 7: /* bell */
917 break; /* ignored */
918
wdenk4b248f32004-03-14 16:51:43 +0000919 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000920 video_putchar(console_col * VIDEO_FONT_WIDTH,
921 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000922 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000923
wdenk4b248f32004-03-14 16:51:43 +0000924 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100925 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000926 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100927 nl = 0;
928 }
wdenk4b248f32004-03-14 16:51:43 +0000929 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000930
931 if (console_cursor_is_visible())
932 CURSOR_SET;
933}
934
935void video_putc(const char c)
936{
937#ifdef CONFIG_CFB_CONSOLE_ANSI
938 int i;
939
940 if (c == 27) {
941 for (i = 0; i < ansi_buf_size; ++i)
942 parse_putc(ansi_buf[i]);
943 ansi_buf[0] = 27;
944 ansi_buf_size = 1;
945 return;
946 }
947
948 if (ansi_buf_size > 0) {
949 /*
950 * 0 - ESC
951 * 1 - [
952 * 2 - num1
953 * 3 - ..
954 * 4 - ;
955 * 5 - num2
956 * 6 - ..
957 * - cchar
958 */
959 int next = 0;
960
961 int flush = 0;
962 int fail = 0;
963
964 int num1 = 0;
965 int num2 = 0;
966 int cchar = 0;
967
968 ansi_buf[ansi_buf_size++] = c;
969
970 if (ansi_buf_size >= sizeof(ansi_buf))
971 fail = 1;
972
973 for (i = 0; i < ansi_buf_size; ++i) {
974 if (fail)
975 break;
976
977 switch (next) {
978 case 0:
979 if (ansi_buf[i] == 27)
980 next = 1;
981 else
982 fail = 1;
983 break;
984
985 case 1:
986 if (ansi_buf[i] == '[')
987 next = 2;
988 else
989 fail = 1;
990 break;
991
992 case 2:
993 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
994 num1 = ansi_buf[i]-'0';
995 next = 3;
996 } else if (ansi_buf[i] != '?') {
997 --i;
998 num1 = 1;
999 next = 4;
1000 }
1001 break;
1002
1003 case 3:
1004 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1005 num1 *= 10;
1006 num1 += ansi_buf[i]-'0';
1007 } else {
1008 --i;
1009 next = 4;
1010 }
1011 break;
1012
1013 case 4:
1014 if (ansi_buf[i] != ';') {
1015 --i;
1016 next = 7;
1017 } else
1018 next = 5;
1019 break;
1020
1021 case 5:
1022 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1023 num2 = ansi_buf[i]-'0';
1024 next = 6;
1025 } else
1026 fail = 1;
1027 break;
1028
1029 case 6:
1030 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1031 num2 *= 10;
1032 num2 += ansi_buf[i]-'0';
1033 } else {
1034 --i;
1035 next = 7;
1036 }
1037 break;
1038
1039 case 7:
1040 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1041 || ansi_buf[i] == 'J'
1042 || ansi_buf[i] == 'K'
1043 || ansi_buf[i] == 'h'
1044 || ansi_buf[i] == 'l'
1045 || ansi_buf[i] == 'm') {
1046 cchar = ansi_buf[i];
1047 flush = 1;
1048 } else
1049 fail = 1;
1050 break;
1051 }
1052 }
1053
1054 if (fail) {
1055 for (i = 0; i < ansi_buf_size; ++i)
1056 parse_putc(ansi_buf[i]);
1057 ansi_buf_size = 0;
1058 return;
1059 }
1060
1061 if (flush) {
1062 if (!ansi_cursor_hidden)
1063 CURSOR_OFF;
1064 ansi_buf_size = 0;
1065 switch (cchar) {
1066 case 'A':
1067 /* move cursor num1 rows up */
1068 console_cursor_up(num1);
1069 break;
1070 case 'B':
1071 /* move cursor num1 rows down */
1072 console_cursor_down(num1);
1073 break;
1074 case 'C':
1075 /* move cursor num1 columns forward */
1076 console_cursor_right(num1);
1077 break;
1078 case 'D':
1079 /* move cursor num1 columns back */
1080 console_cursor_left(num1);
1081 break;
1082 case 'E':
1083 /* move cursor num1 rows up at begin of row */
1084 console_previousline(num1);
1085 break;
1086 case 'F':
1087 /* move cursor num1 rows down at begin of row */
1088 console_newline(num1);
1089 break;
1090 case 'G':
1091 /* move cursor to column num1 */
1092 console_cursor_set_position(-1, num1-1);
1093 break;
1094 case 'H':
1095 /* move cursor to row num1, column num2 */
1096 console_cursor_set_position(num1-1, num2-1);
1097 break;
1098 case 'J':
1099 /* clear console and move cursor to 0, 0 */
1100 console_clear();
1101 console_cursor_set_position(0, 0);
1102 break;
1103 case 'K':
1104 /* clear line */
1105 if (num1 == 0)
1106 console_clear_line(console_row,
1107 console_col,
1108 CONSOLE_COLS-1);
1109 else if (num1 == 1)
1110 console_clear_line(console_row,
1111 0, console_col);
1112 else
1113 console_clear_line(console_row,
1114 0, CONSOLE_COLS-1);
1115 break;
1116 case 'h':
1117 ansi_cursor_hidden = 0;
1118 break;
1119 case 'l':
1120 ansi_cursor_hidden = 1;
1121 break;
1122 case 'm':
1123 if (num1 == 0) { /* reset swapped colors */
1124 if (ansi_colors_need_revert) {
1125 console_swap_colors();
1126 ansi_colors_need_revert = 0;
1127 }
1128 } else if (num1 == 7) { /* once swap colors */
1129 if (!ansi_colors_need_revert) {
1130 console_swap_colors();
1131 ansi_colors_need_revert = 1;
1132 }
1133 }
1134 break;
1135 }
1136 if (!ansi_cursor_hidden)
1137 CURSOR_SET;
1138 }
1139 } else {
1140 parse_putc(c);
1141 }
1142#else
1143 parse_putc(c);
1144#endif
Timur Tabi65618632010-08-27 15:45:47 -05001145}
wdenkc6097192002-11-03 00:24:07 +00001146
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001147void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +00001148{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001149 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +00001150
wdenk4b248f32004-03-14 16:51:43 +00001151 while (count--)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001152 video_putc(*s++);
wdenkc6097192002-11-03 00:24:07 +00001153}
1154
Anatolij Gustschin10543822010-05-01 22:21:09 +02001155/*
1156 * Do not enforce drivers (or board code) to provide empty
1157 * video_set_lut() if they do not support 8 bpp format.
1158 * Implement weak default function instead.
1159 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001160void __video_set_lut(unsigned int index, unsigned char r,
1161 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +02001162{
1163}
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001164
1165void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
1166 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschin10543822010-05-01 22:21:09 +02001167
Jon Loeliger07d38a12007-07-09 17:30:01 -05001168#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +00001169
1170#define FILL_8BIT_332RGB(r,g,b) { \
1171 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1172 fb ++; \
1173}
1174
1175#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001176 *(unsigned short *)fb = \
1177 SWAP16((unsigned short)(((r>>3)<<10) | \
1178 ((g>>3)<<5) | \
1179 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001180 fb += 2; \
1181}
1182
1183#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001184 *(unsigned short *)fb = \
1185 SWAP16((unsigned short)((((r)>>3)<<11)| \
1186 (((g)>>2)<<5) | \
1187 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001188 fb += 2; \
1189}
1190
1191#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001192 *(unsigned long *)fb = \
1193 SWAP32((unsigned long)(((r<<16) | \
1194 (g<<8) | \
1195 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001196 fb += 4; \
1197}
1198
1199#ifdef VIDEO_FB_LITTLE_ENDIAN
1200#define FILL_24BIT_888RGB(r,g,b) { \
1201 fb[0] = b; \
1202 fb[1] = g; \
1203 fb[2] = r; \
1204 fb += 3; \
1205}
1206#else
1207#define FILL_24BIT_888RGB(r,g,b) { \
1208 fb[0] = r; \
1209 fb[1] = g; \
1210 fb[2] = b; \
1211 fb += 3; \
1212}
1213#endif
1214
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001215#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001216static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001217{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001218 ushort *dst = (ushort *) fb;
1219 ushort color = (ushort) (((r >> 3) << 10) |
1220 ((g >> 3) << 5) |
1221 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001222 if (x & 1)
1223 *(--dst) = color;
1224 else
1225 *(++dst) = color;
1226}
1227#endif
wdenk4b248f32004-03-14 16:51:43 +00001228
1229/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001230 * RLE8 bitmap support
1231 */
1232
1233#ifdef CONFIG_VIDEO_BMP_RLE8
1234/* Pre-calculated color table entry */
1235struct palette {
1236 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001237 unsigned short w; /* word */
1238 unsigned int dw; /* double word */
1239 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001240};
1241
1242/*
1243 * Helper to draw encoded/unencoded run.
1244 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001245static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1246 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001247{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001248 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001249 int *off;
1250 int enc_off = 1;
1251 int i;
1252
1253 /*
1254 * Setup offset of the color index in the bitmap.
1255 * Color index of encoded run is at offset 1.
1256 */
1257 off = enc ? &enc_off : &i;
1258
1259 switch (VIDEO_DATA_FORMAT) {
1260 case GDF__8BIT_INDEX:
1261 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001262 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001263 break;
1264 case GDF_15BIT_555RGB:
1265 case GDF_16BIT_565RGB:
1266 /* differences handled while pre-calculating palette */
1267 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001268 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001269 addr += 2;
1270 }
1271 break;
1272 case GDF_32BIT_X888RGB:
1273 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001274 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001275 addr += 4;
1276 }
1277 break;
1278 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001279 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001280}
1281
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001282static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1283 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001284{
1285 unsigned char *bm;
1286 unsigned char *fbp;
1287 unsigned int cnt, runlen;
1288 int decode = 1;
1289 int x, y, bpp, i, ncolors;
1290 struct palette p[256];
1291 bmp_color_table_entry_t cte;
1292 int green_shift, red_off;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001293 int limit = VIDEO_COLS * VIDEO_ROWS;
1294 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001295
1296 x = 0;
1297 y = __le32_to_cpu(img->header.height) - 1;
1298 ncolors = __le32_to_cpu(img->header.colors_used);
1299 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001300 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1301 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001302
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001303 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001304
1305 /* pre-calculate and setup palette */
1306 switch (VIDEO_DATA_FORMAT) {
1307 case GDF__8BIT_INDEX:
1308 for (i = 0; i < ncolors; i++) {
1309 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001310 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001311 }
1312 break;
1313 case GDF_15BIT_555RGB:
1314 case GDF_16BIT_565RGB:
1315 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1316 green_shift = 3;
1317 red_off = 10;
1318 } else {
1319 green_shift = 2;
1320 red_off = 11;
1321 }
1322 for (i = 0; i < ncolors; i++) {
1323 cte = img->color_table[i];
1324 p[i].ce.w = SWAP16((unsigned short)
1325 (((cte.red >> 3) << red_off) |
1326 ((cte.green >> green_shift) << 5) |
1327 cte.blue >> 3));
1328 }
1329 break;
1330 case GDF_32BIT_X888RGB:
1331 for (i = 0; i < ncolors; i++) {
1332 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001333 p[i].ce.dw = SWAP32((cte.red << 16) |
1334 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001335 cte.blue);
1336 }
1337 break;
1338 default:
1339 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001340 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001341 return -1;
1342 }
1343
1344 while (decode) {
1345 switch (bm[0]) {
1346 case 0:
1347 switch (bm[1]) {
1348 case 0:
1349 /* scan line end marker */
1350 bm += 2;
1351 x = 0;
1352 y--;
1353 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001354 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001355 (((y + yoff) * VIDEO_COLS) +
1356 xoff) * bpp);
1357 continue;
1358 case 1:
1359 /* end of bitmap data marker */
1360 decode = 0;
1361 break;
1362 case 2:
1363 /* run offset marker */
1364 x += bm[2];
1365 y -= bm[3];
1366 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001367 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001368 (((y + yoff) * VIDEO_COLS) +
1369 x + xoff) * bpp);
1370 bm += 4;
1371 break;
1372 default:
1373 /* unencoded run */
1374 cnt = bm[1];
1375 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001376 pixels += cnt;
1377 if (pixels > limit)
1378 goto error;
1379
Anatolij Gustschind5011762010-03-15 14:50:25 +01001380 bm += 2;
1381 if (y < height) {
1382 if (x >= width) {
1383 x += runlen;
1384 goto next_run;
1385 }
1386 if (x + runlen > width)
1387 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001388 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001389 x += runlen;
1390 }
1391next_run:
1392 bm += runlen;
1393 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001394 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001395 }
1396 break;
1397 default:
1398 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001399 cnt = bm[0];
1400 runlen = cnt;
1401 pixels += cnt;
1402 if (pixels > limit)
1403 goto error;
1404
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001405 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001406 if (x >= width) {
1407 x += runlen;
1408 bm += 2;
1409 continue;
1410 }
1411 if (x + runlen > width)
1412 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001413 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001414 x += runlen;
1415 }
1416 bm += 2;
1417 break;
1418 }
1419 }
1420 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001421error:
1422 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1423 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001424}
1425#endif
1426
1427/*
wdenk4b248f32004-03-14 16:51:43 +00001428 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001429 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001430int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001431{
1432 ushort xcount, ycount;
1433 uchar *fb;
1434 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1435 uchar *bmap;
1436 ushort padded_line;
1437 unsigned long width, height, bpp;
1438 unsigned colors;
1439 unsigned long compression;
1440 bmp_color_table_entry_t cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001441
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001442#ifdef CONFIG_VIDEO_BMP_GZIP
1443 unsigned char *dst = NULL;
1444 ulong len;
1445#endif
wdenk4b248f32004-03-14 16:51:43 +00001446
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001447 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001448
1449 if (!((bmp->header.signature[0] == 'B') &&
1450 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001451
1452#ifdef CONFIG_VIDEO_BMP_GZIP
1453 /*
1454 * Could be a gzipped bmp image, try to decrompress...
1455 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001456 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1457 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001458 if (dst == NULL) {
1459 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001460 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001461 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001462 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1463 (uchar *) bmp_image,
1464 &len) != 0) {
1465 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1466 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001467 free(dst);
1468 return 1;
1469 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001470 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001471 printf("Image could be truncated "
1472 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001473 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001474
1475 /*
1476 * Set addr to decompressed image
1477 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001478 bmp = (bmp_image_t *) dst;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001479
1480 if (!((bmp->header.signature[0] == 'B') &&
1481 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001482 printf("Error: no valid bmp.gz image at %lx\n",
1483 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001484 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001485 return 1;
1486 }
1487#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001488 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001489 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001490#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001491 }
1492
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001493 width = le32_to_cpu(bmp->header.width);
1494 height = le32_to_cpu(bmp->header.height);
1495 bpp = le16_to_cpu(bmp->header.bit_count);
1496 colors = le32_to_cpu(bmp->header.colors_used);
1497 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001498
Marek Vasut68da5b12011-10-21 14:17:04 +00001499 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001500 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001501
Anatolij Gustschind5011762010-03-15 14:50:25 +01001502 if (compression != BMP_BI_RGB
1503#ifdef CONFIG_VIDEO_BMP_RLE8
1504 && compression != BMP_BI_RLE8
1505#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001506 ) {
1507 printf("Error: compression type %ld not supported\n",
1508 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001509#ifdef CONFIG_VIDEO_BMP_GZIP
1510 if (dst)
1511 free(dst);
1512#endif
wdenk4b248f32004-03-14 16:51:43 +00001513 return 1;
1514 }
1515
1516 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1517
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001518#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1519 if (x == BMP_ALIGN_CENTER)
1520 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1521 else if (x < 0)
1522 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1523
1524 if (y == BMP_ALIGN_CENTER)
1525 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1526 else if (y < 0)
1527 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1528#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1529
wdenk4b248f32004-03-14 16:51:43 +00001530 if ((x + width) > VIDEO_VISIBLE_COLS)
1531 width = VIDEO_VISIBLE_COLS - x;
1532 if ((y + height) > VIDEO_VISIBLE_ROWS)
1533 height = VIDEO_VISIBLE_ROWS - y;
1534
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001535 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001536 fb = (uchar *) (video_fb_address +
1537 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1538 x * VIDEO_PIXEL_SIZE);
1539
Anatolij Gustschind5011762010-03-15 14:50:25 +01001540#ifdef CONFIG_VIDEO_BMP_RLE8
1541 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001542 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001543 }
1544#endif
1545
Timur Tabi68f66182010-08-23 16:58:00 -05001546 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001547 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001548 case 4:
1549 padded_line -= width / 2;
1550 ycount = height;
1551
1552 switch (VIDEO_DATA_FORMAT) {
1553 case GDF_32BIT_X888RGB:
1554 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001555 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001556 /*
1557 * Don't assume that 'width' is an
1558 * even number
1559 */
1560 for (xcount = 0; xcount < width; xcount++) {
1561 uchar idx;
1562
1563 if (xcount & 1) {
1564 idx = *bmap & 0xF;
1565 bmap++;
1566 } else
1567 idx = *bmap >> 4;
1568 cte = bmp->color_table[idx];
1569 FILL_32BIT_X888RGB(cte.red, cte.green,
1570 cte.blue);
1571 }
1572 bmap += padded_line;
1573 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001574 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001575 }
1576 break;
1577 default:
1578 puts("4bpp bitmap unsupported with current "
1579 "video mode\n");
1580 break;
1581 }
1582 break;
1583
wdenk4b248f32004-03-14 16:51:43 +00001584 case 8:
1585 padded_line -= width;
1586 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001587 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001588 for (xcount = 0; xcount < colors; ++xcount) {
1589 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001590 video_set_lut(xcount, cte.red, cte.green,
1591 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001592 }
1593 }
1594 ycount = height;
1595 switch (VIDEO_DATA_FORMAT) {
1596 case GDF__8BIT_INDEX:
1597 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001598 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001599 xcount = width;
1600 while (xcount--) {
1601 *fb++ = *bmap++;
1602 }
1603 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001604 fb -= (VIDEO_VISIBLE_COLS + width) *
1605 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001606 }
1607 break;
1608 case GDF__8BIT_332RGB:
1609 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001610 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001611 xcount = width;
1612 while (xcount--) {
1613 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001614 FILL_8BIT_332RGB(cte.red, cte.green,
1615 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001616 }
1617 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001618 fb -= (VIDEO_VISIBLE_COLS + width) *
1619 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001620 }
1621 break;
1622 case GDF_15BIT_555RGB:
1623 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001624#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1625 int xpos = x;
1626#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001627 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001628 xcount = width;
1629 while (xcount--) {
1630 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001631#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001632 fill_555rgb_pswap(fb, xpos++, cte.red,
1633 cte.green,
1634 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001635 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001636#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001637 FILL_15BIT_555RGB(cte.red, cte.green,
1638 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001639#endif
wdenk4b248f32004-03-14 16:51:43 +00001640 }
1641 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001642 fb -= (VIDEO_VISIBLE_COLS + width) *
1643 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001644 }
1645 break;
1646 case GDF_16BIT_565RGB:
1647 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001648 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001649 xcount = width;
1650 while (xcount--) {
1651 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001652 FILL_16BIT_565RGB(cte.red, cte.green,
1653 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001654 }
1655 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001656 fb -= (VIDEO_VISIBLE_COLS + width) *
1657 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001658 }
1659 break;
1660 case GDF_32BIT_X888RGB:
1661 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001662 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001663 xcount = width;
1664 while (xcount--) {
1665 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001666 FILL_32BIT_X888RGB(cte.red, cte.green,
1667 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001668 }
1669 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001670 fb -= (VIDEO_VISIBLE_COLS + width) *
1671 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001672 }
1673 break;
1674 case GDF_24BIT_888RGB:
1675 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001676 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001677 xcount = width;
1678 while (xcount--) {
1679 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001680 FILL_24BIT_888RGB(cte.red, cte.green,
1681 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001682 }
1683 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001684 fb -= (VIDEO_VISIBLE_COLS + width) *
1685 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001686 }
1687 break;
1688 }
1689 break;
1690 case 24:
1691 padded_line -= 3 * width;
1692 ycount = height;
1693 switch (VIDEO_DATA_FORMAT) {
1694 case GDF__8BIT_332RGB:
1695 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001696 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001697 xcount = width;
1698 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001699 FILL_8BIT_332RGB(bmap[2], bmap[1],
1700 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001701 bmap += 3;
1702 }
1703 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001704 fb -= (VIDEO_VISIBLE_COLS + width) *
1705 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001706 }
1707 break;
1708 case GDF_15BIT_555RGB:
1709 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001710#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1711 int xpos = x;
1712#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001713 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001714 xcount = width;
1715 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001716#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001717 fill_555rgb_pswap(fb, xpos++, bmap[2],
1718 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001719 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001720#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001721 FILL_15BIT_555RGB(bmap[2], bmap[1],
1722 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001723#endif
wdenk4b248f32004-03-14 16:51:43 +00001724 bmap += 3;
1725 }
1726 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001727 fb -= (VIDEO_VISIBLE_COLS + width) *
1728 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001729 }
1730 break;
1731 case GDF_16BIT_565RGB:
1732 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001733 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001734 xcount = width;
1735 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001736 FILL_16BIT_565RGB(bmap[2], bmap[1],
1737 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001738 bmap += 3;
1739 }
1740 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001741 fb -= (VIDEO_VISIBLE_COLS + width) *
1742 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001743 }
1744 break;
1745 case GDF_32BIT_X888RGB:
1746 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001747 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001748 xcount = width;
1749 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001750 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1751 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001752 bmap += 3;
1753 }
1754 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001755 fb -= (VIDEO_VISIBLE_COLS + width) *
1756 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001757 }
1758 break;
1759 case GDF_24BIT_888RGB:
1760 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001761 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001762 xcount = width;
1763 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001764 FILL_24BIT_888RGB(bmap[2], bmap[1],
1765 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001766 bmap += 3;
1767 }
1768 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001769 fb -= (VIDEO_VISIBLE_COLS + width) *
1770 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001771 }
1772 break;
1773 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001774 printf("Error: 24 bits/pixel bitmap incompatible "
1775 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001776 break;
1777 }
1778 break;
1779 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001780 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1781 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001782 break;
1783 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001784
1785#ifdef CONFIG_VIDEO_BMP_GZIP
1786 if (dst) {
1787 free(dst);
1788 }
1789#endif
1790
wdenk4b248f32004-03-14 16:51:43 +00001791 return (0);
1792}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001793#endif
wdenk4b248f32004-03-14 16:51:43 +00001794
wdenk4b248f32004-03-14 16:51:43 +00001795
wdenkc6097192002-11-03 00:24:07 +00001796#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001797static int video_logo_xpos;
1798static int video_logo_ypos;
1799
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001800static void plot_logo_or_black(void *screen, int width, int x, int y, \
1801 int black);
1802
1803static void logo_plot(void *screen, int width, int x, int y)
1804{
1805 plot_logo_or_black(screen, width, x, y, 0);
1806}
1807
1808static void logo_black(void)
1809{
1810 plot_logo_or_black(video_fb_address, \
1811 VIDEO_COLS, \
1812 video_logo_xpos, \
1813 video_logo_ypos, \
1814 1);
1815}
1816
1817static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1818{
1819 if (argc != 1)
1820 return cmd_usage(cmdtp);
1821
1822 logo_black();
1823 return 0;
1824}
1825
1826U_BOOT_CMD(
1827 clrlogo, 1, 0, do_clrlogo,
1828 "fill the boot logo area with black",
1829 " "
1830 );
1831
1832static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001833{
wdenkc6097192002-11-03 00:24:07 +00001834
wdenk4b248f32004-03-14 16:51:43 +00001835 int xcount, i;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001836 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001837 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001838 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1839 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001840 unsigned char *dest;
1841
1842#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1843 if (x == BMP_ALIGN_CENTER)
1844 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1845 else if (x < 0)
1846 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1847
1848 if (y == BMP_ALIGN_CENTER)
1849 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1850 else if (y < 0)
1851 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1852#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1853
1854 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001855
1856#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001857 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001858
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001859 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001860 logo_red = malloc(BMP_LOGO_COLORS);
1861 logo_green = malloc(BMP_LOGO_COLORS);
1862 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001863 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001864 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1865 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1866 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1867 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1868 }
wdenka6c7ad22002-12-03 21:28:10 +00001869#else
wdenk4b248f32004-03-14 16:51:43 +00001870 source = linux_logo;
1871 logo_red = linux_logo_red;
1872 logo_green = linux_logo_green;
1873 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001874#endif
wdenk8bde7f72003-06-27 21:31:46 +00001875
wdenk4b248f32004-03-14 16:51:43 +00001876 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1877 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001878 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1879 logo_red[i], logo_green[i],
1880 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001881 }
wdenk8bde7f72003-06-27 21:31:46 +00001882 }
wdenkc6097192002-11-03 00:24:07 +00001883
wdenk4b248f32004-03-14 16:51:43 +00001884 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001885#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1886 int xpos = x;
1887#endif
wdenk4b248f32004-03-14 16:51:43 +00001888 xcount = VIDEO_LOGO_WIDTH;
1889 while (xcount--) {
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001890 if (black) {
1891 r = 0x00;
1892 g = 0x00;
1893 b = 0x00;
1894 } else {
1895 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1896 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1897 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1898 }
wdenk8bde7f72003-06-27 21:31:46 +00001899
wdenk4b248f32004-03-14 16:51:43 +00001900 switch (VIDEO_DATA_FORMAT) {
1901 case GDF__8BIT_INDEX:
1902 *dest = *source;
1903 break;
1904 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001905 *dest = ((r >> 5) << 5) |
1906 ((g >> 5) << 2) |
1907 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001908 break;
1909 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001910#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001911 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001912#else
wdenk4b248f32004-03-14 16:51:43 +00001913 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001914 SWAP16((unsigned short) (
1915 ((r >> 3) << 10) |
1916 ((g >> 3) << 5) |
1917 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001918#endif
wdenk4b248f32004-03-14 16:51:43 +00001919 break;
1920 case GDF_16BIT_565RGB:
1921 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001922 SWAP16((unsigned short) (
1923 ((r >> 3) << 11) |
1924 ((g >> 2) << 5) |
1925 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001926 break;
1927 case GDF_32BIT_X888RGB:
1928 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001929 SWAP32((unsigned long) (
1930 (r << 16) |
1931 (g << 8) |
1932 b));
wdenk4b248f32004-03-14 16:51:43 +00001933 break;
1934 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001935#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001936 dest[0] = b;
1937 dest[1] = g;
1938 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001939#else
wdenk4b248f32004-03-14 16:51:43 +00001940 dest[0] = r;
1941 dest[1] = g;
1942 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001943#endif
wdenk4b248f32004-03-14 16:51:43 +00001944 break;
1945 }
1946 source++;
1947 dest += VIDEO_PIXEL_SIZE;
1948 }
1949 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001950 }
wdenka6c7ad22002-12-03 21:28:10 +00001951#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001952 free(logo_red);
1953 free(logo_green);
1954 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001955#endif
wdenkc6097192002-11-03 00:24:07 +00001956}
1957
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001958static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001959{
wdenk4b248f32004-03-14 16:51:43 +00001960 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001961 int space, len;
1962 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001963 __maybe_unused ulong addr;
1964 __maybe_unused char *s;
wdenkc6097192002-11-03 00:24:07 +00001965
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001966#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001967 s = getenv("splashpos");
1968 if (s != NULL) {
1969 if (s[0] == 'm')
1970 video_logo_xpos = BMP_ALIGN_CENTER;
1971 else
1972 video_logo_xpos = simple_strtol(s, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001973
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001974 s = strchr(s + 1, ',');
1975 if (s != NULL) {
1976 if (s[1] == 'm')
1977 video_logo_ypos = BMP_ALIGN_CENTER;
1978 else
1979 video_logo_ypos = simple_strtol(s + 1, NULL, 0);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001980 }
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001981 }
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001982#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1983
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001984#ifdef CONFIG_SPLASH_SCREEN
1985 s = getenv("splashimage");
1986 if (s != NULL) {
1987
1988 addr = simple_strtoul(s, NULL, 16);
1989
1990
1991 if (video_display_bitmap(addr,
1992 video_logo_xpos,
1993 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001994 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00001995 return ((void *) (video_fb_address));
1996 }
1997 }
1998#endif /* CONFIG_SPLASH_SCREEN */
1999
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002000 logo_plot(video_fb_address, VIDEO_COLS,
2001 video_logo_xpos, video_logo_ypos);
2002
2003#ifdef CONFIG_SPLASH_SCREEN_ALIGN
2004 /*
2005 * when using splashpos for video_logo, skip any info
2006 * output on video console if the logo is not at 0,0
2007 */
2008 if (video_logo_xpos || video_logo_ypos) {
2009 /*
2010 * video_logo_height is used in text and cursor offset
2011 * calculations. Since the console is below the logo,
2012 * we need to adjust the logo height
2013 */
2014 if (video_logo_ypos == BMP_ALIGN_CENTER)
2015 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
2016 VIDEO_LOGO_HEIGHT) / 2);
2017 else if (video_logo_ypos > 0)
2018 video_logo_height += video_logo_ypos;
2019
2020 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2021 }
2022#endif
wdenk4b248f32004-03-14 16:51:43 +00002023
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002024 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002025
2026 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2027 len = strlen(info);
2028
2029 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002030 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2031 (uchar *) info, space);
2032 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2033 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2034 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002035 y_off = 1;
2036 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002037 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00002038
2039#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00002040 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002041 int i, n =
2042 ((video_logo_height -
2043 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002044
wdenk4b248f32004-03-14 16:51:43 +00002045 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002046 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002047 if (!*info)
2048 continue;
2049
2050 len = strlen(info);
2051 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002052 video_drawchars(VIDEO_INFO_X,
2053 VIDEO_INFO_Y +
2054 (i + y_off) *
2055 VIDEO_FONT_HEIGHT,
2056 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002057 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002058 video_drawchars(VIDEO_INFO_X +
2059 VIDEO_FONT_WIDTH,
2060 VIDEO_INFO_Y +
2061 (i + y_off) *
2062 VIDEO_FONT_HEIGHT,
2063 (uchar *) info + space,
2064 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002065 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002066 video_drawstring(VIDEO_INFO_X,
2067 VIDEO_INFO_Y +
2068 (i + y_off) *
2069 VIDEO_FONT_HEIGHT,
2070 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002071 }
wdenk4b248f32004-03-14 16:51:43 +00002072 }
2073 }
wdenkc6097192002-11-03 00:24:07 +00002074#endif
2075
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002076 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002077}
2078#endif
2079
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002080static int cfb_fb_is_in_dram(void)
2081{
2082 bd_t *bd = gd->bd;
2083#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2084defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2085 ulong start, end;
2086 int i;
2087
2088 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2089 start = bd->bi_dram[i].start;
2090 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2091 if ((ulong)video_fb_address >= start &&
2092 (ulong)video_fb_address < end)
2093 return 1;
2094 }
2095#else
2096 if ((ulong)video_fb_address >= bd->bi_memstart &&
2097 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2098 return 1;
2099#endif
2100 return 0;
2101}
2102
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002103static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002104{
wdenk4b248f32004-03-14 16:51:43 +00002105 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002106
Wolfgang Denk57912932011-07-30 12:48:09 +00002107 pGD = video_hw_init();
2108 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00002109 return -1;
wdenkc6097192002-11-03 00:24:07 +00002110
wdenk4b248f32004-03-14 16:51:43 +00002111 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002112#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002113 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002114#endif
2115
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002116 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2117
wdenk4b248f32004-03-14 16:51:43 +00002118 /* Init drawing pats */
2119 switch (VIDEO_DATA_FORMAT) {
2120 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002121 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2122 CONSOLE_FG_COL);
2123 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2124 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00002125 fgx = 0x01010101;
2126 bgx = 0x00000000;
2127 break;
2128 case GDF__8BIT_332RGB:
2129 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002130 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2131 CONSOLE_FG_COL >> 6);
2132 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2133 color8;
wdenk4b248f32004-03-14 16:51:43 +00002134 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002135 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2136 CONSOLE_BG_COL >> 6);
2137 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2138 color8;
wdenk4b248f32004-03-14 16:51:43 +00002139 break;
2140 case GDF_15BIT_555RGB:
2141 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002142 ((CONSOLE_FG_COL >> 3) << 21) |
2143 ((CONSOLE_FG_COL >> 3) << 16) |
2144 ((CONSOLE_FG_COL >> 3) << 10) |
2145 ((CONSOLE_FG_COL >> 3) << 5) |
2146 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002147 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002148 ((CONSOLE_BG_COL >> 3) << 21) |
2149 ((CONSOLE_BG_COL >> 3) << 16) |
2150 ((CONSOLE_BG_COL >> 3) << 10) |
2151 ((CONSOLE_BG_COL >> 3) << 5) |
2152 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002153 break;
2154 case GDF_16BIT_565RGB:
2155 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002156 ((CONSOLE_FG_COL >> 2) << 21) |
2157 ((CONSOLE_FG_COL >> 3) << 16) |
2158 ((CONSOLE_FG_COL >> 3) << 11) |
2159 ((CONSOLE_FG_COL >> 2) << 5) |
2160 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002161 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002162 ((CONSOLE_BG_COL >> 2) << 21) |
2163 ((CONSOLE_BG_COL >> 3) << 16) |
2164 ((CONSOLE_BG_COL >> 3) << 11) |
2165 ((CONSOLE_BG_COL >> 2) << 5) |
2166 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002167 break;
2168 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002169 fgx = (CONSOLE_FG_COL << 16) |
2170 (CONSOLE_FG_COL << 8) |
2171 CONSOLE_FG_COL;
2172 bgx = (CONSOLE_BG_COL << 16) |
2173 (CONSOLE_BG_COL << 8) |
2174 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002175 break;
2176 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002177 fgx = (CONSOLE_FG_COL << 24) |
2178 (CONSOLE_FG_COL << 16) |
2179 (CONSOLE_FG_COL << 8) |
2180 CONSOLE_FG_COL;
2181 bgx = (CONSOLE_BG_COL << 24) |
2182 (CONSOLE_BG_COL << 16) |
2183 (CONSOLE_BG_COL << 8) |
2184 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002185 break;
2186 }
2187 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002188
2189#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00002190 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002191 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002192 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002193#else
wdenk4b248f32004-03-14 16:51:43 +00002194 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002195#endif
2196
wdenk4b248f32004-03-14 16:51:43 +00002197 /* Initialize the console */
2198 console_col = 0;
2199 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002200
wdenk4b248f32004-03-14 16:51:43 +00002201 return 0;
wdenkc6097192002-11-03 00:24:07 +00002202}
2203
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002204/*
2205 * Implement a weak default function for boards that optionally
2206 * need to skip the video initialization.
2207 */
2208int __board_video_skip(void)
2209{
2210 /* As default, don't skip test */
2211 return 0;
2212}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002213
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002214int board_video_skip(void)
2215 __attribute__ ((weak, alias("__board_video_skip")));
2216
2217int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002218{
wdenk4b248f32004-03-14 16:51:43 +00002219 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02002220 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00002221
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002222 /* Check if video initialization should be skipped */
2223 if (board_video_skip())
2224 return 0;
2225
wdenk81050922004-07-11 20:04:51 +00002226 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002227 skip_dev_init = (video_init() == -1);
wdenk81050922004-07-11 20:04:51 +00002228
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002229#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002230 debug("KBD: Keyboard init ...\n");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002231 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2232#endif
wdenkc6097192002-11-03 00:24:07 +00002233
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002234 if (skip_dev_init)
2235 return 0;
wdenkc6097192002-11-03 00:24:07 +00002236
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002237 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002238 memset(&console_dev, 0, sizeof(console_dev));
2239 strcpy(console_dev.name, "vga");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002240 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2241 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2242 console_dev.putc = video_putc; /* 'putc' function */
2243 console_dev.puts = video_puts; /* 'puts' function */
2244 console_dev.tstc = NULL; /* 'tstc' function */
2245 console_dev.getc = NULL; /* 'getc' function */
2246
2247#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2248 /* Also init console device */
2249 console_dev.flags |= DEV_FLAGS_INPUT;
2250 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2251 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00002252#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002253
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002254 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002255 return 0;
2256
2257 /* Return success */
2258 return 1;
wdenkc6097192002-11-03 00:24:07 +00002259}