blob: 0793f07f242fe4ca02e1a0c43ac63fed68a847e2 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenke55402c2004-03-14 16:51:43 +000015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkc6097192002-11-03 00:24:07 +000016 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * cfb_console.c
26 *
27 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
28 *
29 * At the moment only the 8x16 font is tested and the font fore- and
30 * background color is limited to black/white/gray colors. The Linux
31 * logo can be placed in the upper left corner and additional board
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000032 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000033 *
34 * The console driver can use the standard PC keyboard interface (i8042)
35 * for character input. Character output goes to a memory mapped video
36 * framebuffer with little or big-endian organisation.
37 * With environment setting 'console=serial' the console i/o can be
38 * forced to serial port.
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000039 *
40 * The driver uses graphic specific defines/parameters/functions:
41 *
42 * (for SMI LynxE graphic chip)
43 *
44 * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
45 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
46 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
47 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
48 *
49 * Console Parameters are set by graphic drivers global struct:
50 *
51 * VIDEO_VISIBLE_COLS - x resolution
52 * VIDEO_VISIBLE_ROWS - y resolution
53 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
54 * VIDEO_DATA_FORMAT - graphical data format GDF
55 * VIDEO_FB_ADRS - start of video memory
56 *
57 * CONFIG_I8042_KBD - AT Keyboard driver for i8042
58 * VIDEO_KBD_INIT_FCT - init function for keyboard
59 * VIDEO_TSTC_FCT - keyboard_tstc function
60 * VIDEO_GETC_FCT - keyboard_getc function
61 *
62 * CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with
63 * delay loop in VIDEO_TSTC_FCT (i8042)
64 *
65 * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
66 * CONFIG_CONSOLE_TIME - display time/date in upper right
67 * corner, needs CONFIG_CMD_DATE and
68 * CONFIG_CONSOLE_CURSOR
Bastian Rupperta13e81f2012-09-13 22:29:01 +000069 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
70 * Use CONFIG_SPLASH_SCREEN_ALIGN with
71 * environment variable "splashpos" to place
72 * the logo on other position. In this case
73 * no CONSOLE_EXTRA_INFO is possible.
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000074 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
75 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
76 * strings that normaly goes to serial
77 * port. This define requires a board
78 * specific function:
79 * video_drawstring (VIDEO_INFO_X,
80 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
81 * info);
82 * that fills a info buffer at i=row.
83 * s.a: board/eltec/bab7xx.
84 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
85 * initialized as an output only device.
86 * The Keyboard driver will not be
87 * set-up. This may be used, if you have
88 * no or more than one Keyboard devices
89 * (USB Keyboard, AT Keyboard).
90 *
91 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
92 * character. No blinking is provided.
93 * Uses the macros CURSOR_SET and
94 * CURSOR_OFF.
95 *
96 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
97 * of the graphic chip. Uses the macro
98 * CURSOR_SET. ATTENTION: If booting an
99 * OS, the display driver must disable
100 * the hardware register of the graphic
101 * chip. Otherwise a blinking field is
102 * displayed.
103 */
wdenkc6097192002-11-03 00:24:07 +0000104
105#include <common.h>
Andreas Bießmann61d01952011-07-18 20:24:04 +0200106#include <version.h>
wdenk9dd2b882002-12-03 21:28:10 +0000107#include <malloc.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +0000108#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +0000109
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000110/*
111 * Console device defines with SMI graphic
112 * Any other graphic must change this section
113 */
wdenkc6097192002-11-03 00:24:07 +0000114
wdenke55402c2004-03-14 16:51:43 +0000115#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000116
117#define VIDEO_FB_LITTLE_ENDIAN
118#define VIDEO_HW_RECTFILL
119#define VIDEO_HW_BITBLT
120#endif
121
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000122/*
123 * Defines for the CT69000 driver
124 */
wdenke55402c2004-03-14 16:51:43 +0000125#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000126
127#define VIDEO_FB_LITTLE_ENDIAN
128#define VIDEO_HW_RECTFILL
129#define VIDEO_HW_BITBLT
130#endif
131
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000132/*
133 * Defines for the SED13806 driver
134 */
wdenk9dd2b882002-12-03 21:28:10 +0000135#ifdef CONFIG_VIDEO_SED13806
136
wdenkda54bc92004-08-04 21:56:49 +0000137#ifndef CONFIG_TOTAL5200
wdenk9dd2b882002-12-03 21:28:10 +0000138#define VIDEO_FB_LITTLE_ENDIAN
wdenkda54bc92004-08-04 21:56:49 +0000139#endif
wdenk9dd2b882002-12-03 21:28:10 +0000140#define VIDEO_HW_RECTFILL
141#define VIDEO_HW_BITBLT
142#endif
143
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000144/*
145 * Defines for the SED13806 driver
146 */
Stefan Roesed9d97742005-09-22 09:04:17 +0200147#ifdef CONFIG_VIDEO_SM501
148
149#ifdef CONFIG_HH405
150#define VIDEO_FB_LITTLE_ENDIAN
151#endif
152#endif
153
Marek Vasutffdd4662013-04-28 09:20:03 +0000154#ifdef CONFIG_VIDEO_MXS
155#define VIDEO_FB_16BPP_WORD_SWAP
156#endif
157
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000158/*
159 * Defines for the MB862xx driver
160 */
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100161#ifdef CONFIG_VIDEO_MB862xx
162
163#ifdef CONFIG_VIDEO_CORALP
164#define VIDEO_FB_LITTLE_ENDIAN
165#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200166#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100167#define VIDEO_HW_RECTFILL
168#define VIDEO_HW_BITBLT
169#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200170#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100171
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000172/*
Helmut Raiger0385c132011-10-12 23:16:29 +0000173 * Defines for the i.MX31 driver (mx3fb.c)
174 */
Fabio Estevamc6dd2e02012-05-31 07:23:56 +0000175#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger0385c132011-10-12 23:16:29 +0000176#define VIDEO_FB_16BPP_WORD_SWAP
177#endif
178
179/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000180 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
181 */
wdenkc6097192002-11-03 00:24:07 +0000182#include <video_fb.h>
183
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000184/*
185 * some Macros
186 */
wdenke55402c2004-03-14 16:51:43 +0000187#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
188#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
189#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
190#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
191#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000192
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000193/*
194 * Console device defines with i8042 keyboard controller
195 * Any other keyboard controller must change this section
196 */
wdenkc6097192002-11-03 00:24:07 +0000197
wdenke55402c2004-03-14 16:51:43 +0000198#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000199#include <i8042.h>
200
wdenke55402c2004-03-14 16:51:43 +0000201#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
202#define VIDEO_TSTC_FCT i8042_tstc
203#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000204#endif
205
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000206/*
207 * Console device
208 */
wdenkc6097192002-11-03 00:24:07 +0000209
210#include <version.h>
211#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200212#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000213#include <video_font.h>
Che-Liang Chiou41132c02011-10-21 17:04:21 +0800214#include <video_font_data.h>
wdenkc6097192002-11-03 00:24:07 +0000215
Jon Loeliger30c2f242007-07-10 11:13:21 -0500216#if defined(CONFIG_CMD_DATE)
217#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000218#endif
219
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500220#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000221#include <watchdog.h>
222#include <bmp_layout.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200223
224#ifdef CONFIG_SPLASH_SCREEN_ALIGN
225#define BMP_ALIGN_CENTER 0x7FFF
226#endif
227
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500228#endif
wdenke55402c2004-03-14 16:51:43 +0000229
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000230/*
231 * Cursor definition:
232 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
233 * to let the cursor blink. Uses the macros
234 * CURSOR_OFF and CURSOR_ON.
235 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
236 * blinking is provided. Uses the macros CURSOR_SET
237 * and CURSOR_OFF.
238 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
239 * graphic chip. Uses the macro CURSOR_SET.
240 * ATTENTION: If booting an OS, the display driver
241 * must disable the hardware register of the graphic
242 * chip. Otherwise a blinking field is displayed
243 */
wdenkc6097192002-11-03 00:24:07 +0000244#if !defined(CONFIG_CONSOLE_CURSOR) && \
245 !defined(CONFIG_VIDEO_SW_CURSOR) && \
246 !defined(CONFIG_VIDEO_HW_CURSOR)
247/* no Cursor defined */
248#define CURSOR_ON
249#define CURSOR_OFF
250#define CURSOR_SET
251#endif
252
Gabe Black12874de2011-11-30 13:50:50 +0000253#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
254#if defined(CURSOR_ON) || \
255 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000256#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
257 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000258#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000259void console_cursor(int state);
260
Timur Tabibe0c74e2010-08-27 15:45:47 -0500261#define CURSOR_ON console_cursor(1)
262#define CURSOR_OFF console_cursor(0)
Gabe Black12874de2011-11-30 13:50:50 +0000263#define CURSOR_SET video_set_cursor()
264#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
265
266#ifdef CONFIG_CONSOLE_CURSOR
267#ifndef CONFIG_CONSOLE_TIME
268#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
269#endif
wdenkc6097192002-11-03 00:24:07 +0000270#ifndef CONFIG_I8042_KBD
Marcel Ziswileraea68562007-12-30 03:30:46 +0100271#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000272#endif
wdenkc6097192002-11-03 00:24:07 +0000273#endif /* CONFIG_CONSOLE_CURSOR */
274
wdenkc6097192002-11-03 00:24:07 +0000275
276#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +0000277#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000278#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
279 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000280#endif
281#define CURSOR_ON
282#define CURSOR_OFF
283#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabibe0c74e2010-08-27 15:45:47 -0500284 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000285#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000286
wdenke55402c2004-03-14 16:51:43 +0000287#ifdef CONFIG_VIDEO_LOGO
288#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000289#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000290#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000291#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
292#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
293#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
294#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000295
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000296#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000297#define LINUX_LOGO_WIDTH 80
298#define LINUX_LOGO_HEIGHT 80
299#define LINUX_LOGO_COLORS 214
300#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000301#define __initdata
302#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000303#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
304#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
305#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
306#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000307#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000308#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
309#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000310#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000311#define VIDEO_LOGO_WIDTH 0
312#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000313#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000314
wdenke55402c2004-03-14 16:51:43 +0000315#define VIDEO_COLS VIDEO_VISIBLE_COLS
316#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
317#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
318#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
319#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
320#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000321
wdenke55402c2004-03-14 16:51:43 +0000322#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100323#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000324#else
wdenke55402c2004-03-14 16:51:43 +0000325#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000326#endif
327
wdenke55402c2004-03-14 16:51:43 +0000328#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
329#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
330#define CONSOLE_ROW_FIRST (video_console_address)
331#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
332#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
333#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
334#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000335
336/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000337#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000338#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
339 ((x) >> 8) \
340 )
341#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
342 (((x) & 0x0000ff00) << 8) | \
343 (((x) & 0x00ff0000) >> 8) | \
344 (((x) & 0xff000000) >> 24) \
345 )
346#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
347 (((x) & 0x0000ff00) >> 8) | \
348 (((x) & 0x00ff0000) << 8) | \
349 (((x) & 0xff000000) >> 8) \
350 )
wdenkc6097192002-11-03 00:24:07 +0000351#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000352#define SWAP16(x) (x)
353#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200354#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000355#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500356#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000357#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100358#endif
wdenkc6097192002-11-03 00:24:07 +0000359#endif
360
wdenkc6097192002-11-03 00:24:07 +0000361#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000362/*
363 * setup a board string: type, speed, etc.
364 *
365 * line_number: location to place info string beside logo
366 * info: buffer for info string
367 */
368extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000369#endif
370
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200371DECLARE_GLOBAL_DATA_PTR;
372
wdenkc6097192002-11-03 00:24:07 +0000373/* Locals */
374static GraphicDevice *pGD; /* Pointer to Graphic array */
375
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000376static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000377static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000378
Matthias Weisser76d70862010-01-12 12:06:31 +0100379static int video_logo_height = VIDEO_LOGO_HEIGHT;
380
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000381static int __maybe_unused cursor_state;
382static int __maybe_unused old_col;
383static int __maybe_unused old_row;
Gabe Black12874de2011-11-30 13:50:50 +0000384
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000385static int console_col; /* cursor col */
386static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000387
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000388static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000389
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200390static int cfb_do_flush_cache;
391
Pali Rohár4a57da32012-10-19 13:30:09 +0000392#ifdef CONFIG_CFB_CONSOLE_ANSI
393static char ansi_buf[10];
394static int ansi_buf_size;
395static int ansi_colors_need_revert;
396static int ansi_cursor_hidden;
397#endif
398
wdenkc6097192002-11-03 00:24:07 +0000399static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000400 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
401 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
402 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
403 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
404};
wdenkc6097192002-11-03 00:24:07 +0000405
406static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000407 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
408};
wdenkc6097192002-11-03 00:24:07 +0000409
410static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000411 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
412};
wdenkc6097192002-11-03 00:24:07 +0000413
414static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000415 {0x00000000, 0x00000000, 0x00000000},
416 {0x00000000, 0x00000000, 0x00ffffff},
417 {0x00000000, 0x0000ffff, 0xff000000},
418 {0x00000000, 0x0000ffff, 0xffffffff},
419 {0x000000ff, 0xffff0000, 0x00000000},
420 {0x000000ff, 0xffff0000, 0x00ffffff},
421 {0x000000ff, 0xffffffff, 0xff000000},
422 {0x000000ff, 0xffffffff, 0xffffffff},
423 {0xffffff00, 0x00000000, 0x00000000},
424 {0xffffff00, 0x00000000, 0x00ffffff},
425 {0xffffff00, 0x0000ffff, 0xff000000},
426 {0xffffff00, 0x0000ffff, 0xffffffff},
427 {0xffffffff, 0xffff0000, 0x00000000},
428 {0xffffffff, 0xffff0000, 0x00ffffff},
429 {0xffffffff, 0xffffffff, 0xff000000},
430 {0xffffffff, 0xffffffff, 0xffffffff}
431};
wdenkc6097192002-11-03 00:24:07 +0000432
433static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000434 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
435 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
436 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
437 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
438 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
439 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
440 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
441 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
442 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
443 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
444 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
445 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
446 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
447 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
448 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
449 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
450};
wdenkc6097192002-11-03 00:24:07 +0000451
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000452static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000453{
wdenke55402c2004-03-14 16:51:43 +0000454 u8 *cdat, *dest, *dest0;
455 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000456
wdenke55402c2004-03-14 16:51:43 +0000457 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
458 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000459
wdenke55402c2004-03-14 16:51:43 +0000460 switch (VIDEO_DATA_FORMAT) {
461 case GDF__8BIT_INDEX:
462 case GDF__8BIT_332RGB:
463 while (count--) {
464 c = *s;
465 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
466 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000467 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000468 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000469
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000470 ((u32 *) dest)[0] =
471 (video_font_draw_table8[bits >> 4] &
472 eorx) ^ bgx;
473 ((u32 *) dest)[1] =
474 (video_font_draw_table8[bits & 15] &
475 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000476 }
477 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
478 s++;
479 }
480 break;
wdenkc6097192002-11-03 00:24:07 +0000481
wdenke55402c2004-03-14 16:51:43 +0000482 case GDF_15BIT_555RGB:
483 while (count--) {
484 c = *s;
485 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
486 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000487 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000488 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000489
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000490 ((u32 *) dest)[0] =
491 SHORTSWAP32((video_font_draw_table15
492 [bits >> 6] & eorx) ^
493 bgx);
494 ((u32 *) dest)[1] =
495 SHORTSWAP32((video_font_draw_table15
496 [bits >> 4 & 3] & eorx) ^
497 bgx);
498 ((u32 *) dest)[2] =
499 SHORTSWAP32((video_font_draw_table15
500 [bits >> 2 & 3] & eorx) ^
501 bgx);
502 ((u32 *) dest)[3] =
503 SHORTSWAP32((video_font_draw_table15
504 [bits & 3] & eorx) ^
505 bgx);
wdenke55402c2004-03-14 16:51:43 +0000506 }
507 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
508 s++;
509 }
510 break;
wdenkc6097192002-11-03 00:24:07 +0000511
wdenke55402c2004-03-14 16:51:43 +0000512 case GDF_16BIT_565RGB:
513 while (count--) {
514 c = *s;
515 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
516 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000517 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000518 u8 bits = *cdat++;
519
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000520 ((u32 *) dest)[0] =
521 SHORTSWAP32((video_font_draw_table16
522 [bits >> 6] & eorx) ^
523 bgx);
524 ((u32 *) dest)[1] =
525 SHORTSWAP32((video_font_draw_table16
526 [bits >> 4 & 3] & eorx) ^
527 bgx);
528 ((u32 *) dest)[2] =
529 SHORTSWAP32((video_font_draw_table16
530 [bits >> 2 & 3] & eorx) ^
531 bgx);
532 ((u32 *) dest)[3] =
533 SHORTSWAP32((video_font_draw_table16
534 [bits & 3] & eorx) ^
535 bgx);
wdenke55402c2004-03-14 16:51:43 +0000536 }
537 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
538 s++;
539 }
540 break;
541
542 case GDF_32BIT_X888RGB:
543 while (count--) {
544 c = *s;
545 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
546 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000547 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000548 u8 bits = *cdat++;
549
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000550 ((u32 *) dest)[0] =
551 SWAP32((video_font_draw_table32
552 [bits >> 4][0] & eorx) ^ bgx);
553 ((u32 *) dest)[1] =
554 SWAP32((video_font_draw_table32
555 [bits >> 4][1] & eorx) ^ bgx);
556 ((u32 *) dest)[2] =
557 SWAP32((video_font_draw_table32
558 [bits >> 4][2] & eorx) ^ bgx);
559 ((u32 *) dest)[3] =
560 SWAP32((video_font_draw_table32
561 [bits >> 4][3] & eorx) ^ bgx);
562 ((u32 *) dest)[4] =
563 SWAP32((video_font_draw_table32
564 [bits & 15][0] & eorx) ^ bgx);
565 ((u32 *) dest)[5] =
566 SWAP32((video_font_draw_table32
567 [bits & 15][1] & eorx) ^ bgx);
568 ((u32 *) dest)[6] =
569 SWAP32((video_font_draw_table32
570 [bits & 15][2] & eorx) ^ bgx);
571 ((u32 *) dest)[7] =
572 SWAP32((video_font_draw_table32
573 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000574 }
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200575 if (cfb_do_flush_cache)
576 flush_cache((ulong)dest0, 32);
wdenke55402c2004-03-14 16:51:43 +0000577 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
578 s++;
579 }
580 break;
581
582 case GDF_24BIT_888RGB:
583 while (count--) {
584 c = *s;
585 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
586 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000587 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000588 u8 bits = *cdat++;
589
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000590 ((u32 *) dest)[0] =
591 (video_font_draw_table24[bits >> 4][0]
592 & eorx) ^ bgx;
593 ((u32 *) dest)[1] =
594 (video_font_draw_table24[bits >> 4][1]
595 & eorx) ^ bgx;
596 ((u32 *) dest)[2] =
597 (video_font_draw_table24[bits >> 4][2]
598 & eorx) ^ bgx;
599 ((u32 *) dest)[3] =
600 (video_font_draw_table24[bits & 15][0]
601 & eorx) ^ bgx;
602 ((u32 *) dest)[4] =
603 (video_font_draw_table24[bits & 15][1]
604 & eorx) ^ bgx;
605 ((u32 *) dest)[5] =
606 (video_font_draw_table24[bits & 15][2]
607 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000608 }
609 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
610 s++;
611 }
612 break;
wdenk57b2d802003-06-27 21:31:46 +0000613 }
wdenkc6097192002-11-03 00:24:07 +0000614}
615
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000616static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000617{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000618 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000619}
620
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000621static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000622{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000623 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000624}
625
wdenkc6097192002-11-03 00:24:07 +0000626#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000627static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000628{
Gabe Black12874de2011-11-30 13:50:50 +0000629 if (cursor_state)
630 console_cursor(0);
631 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000632}
Gabe Black12874de2011-11-30 13:50:50 +0000633
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000634static void video_invertchar(int xx, int yy)
635{
636 int firstx = xx * VIDEO_PIXEL_SIZE;
637 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
638 int firsty = yy * VIDEO_LINE_LEN;
639 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
640 int x, y;
641 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
642 for (x = firstx; x < lastx; x++) {
643 u8 *dest = (u8 *)(video_fb_address) + x + y;
644 *dest = ~*dest;
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200645 if (cfb_do_flush_cache)
646 flush_cache((ulong)dest, 4);
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000647 }
648 }
649}
Gabe Black12874de2011-11-30 13:50:50 +0000650
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000651void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000652{
wdenkc6097192002-11-03 00:24:07 +0000653#ifdef CONFIG_CONSOLE_TIME
wdenke55402c2004-03-14 16:51:43 +0000654 struct rtc_time tm;
655 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000656
wdenke55402c2004-03-14 16:51:43 +0000657 /* time update only if cursor is on (faster scroll) */
658 if (state) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000659 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000660
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000661 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
662 tm.tm_sec);
663 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
664 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000665
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000666 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
667 tm.tm_year);
668 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
669 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
670 (uchar *) info);
wdenke55402c2004-03-14 16:51:43 +0000671 }
wdenkc6097192002-11-03 00:24:07 +0000672#endif
673
Gabe Black12874de2011-11-30 13:50:50 +0000674 if (cursor_state != state) {
675 if (cursor_state) {
676 /* turn off the cursor */
677 video_invertchar(old_col * VIDEO_FONT_WIDTH,
678 old_row * VIDEO_FONT_HEIGHT +
679 video_logo_height);
680 } else {
681 /* turn off the cursor and record where it is */
682 video_invertchar(console_col * VIDEO_FONT_WIDTH,
683 console_row * VIDEO_FONT_HEIGHT +
684 video_logo_height);
685 old_col = console_col;
686 old_row = console_row;
687 }
688 cursor_state = state;
wdenke55402c2004-03-14 16:51:43 +0000689 }
wdenkc6097192002-11-03 00:24:07 +0000690}
691#endif
692
wdenkc6097192002-11-03 00:24:07 +0000693#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000694static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000695{
wdenke55402c2004-03-14 16:51:43 +0000696 while (c--)
697 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000698}
699#endif
700
wdenkc6097192002-11-03 00:24:07 +0000701#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000702static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000703{
wdenke55402c2004-03-14 16:51:43 +0000704 while (c--)
705 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000706}
707#endif
708
Pali Rohár16658612012-04-28 07:26:44 +0000709static void console_clear_line(int line, int begin, int end)
710{
711#ifdef VIDEO_HW_RECTFILL
712 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
713 VIDEO_FONT_WIDTH * begin, /* dest pos x */
714 video_logo_height +
715 VIDEO_FONT_HEIGHT * line, /* dest pos y */
716 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
717 VIDEO_FONT_HEIGHT, /* frame height */
718 bgx /* fill color */
719 );
720#else
721 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
722 memsetl(CONSOLE_ROW_FIRST +
723 CONSOLE_ROW_SIZE * line, /* offset of row */
724 CONSOLE_ROW_SIZE >> 2, /* length of row */
725 bgx /* fill color */
726 );
727 } else {
728 void *offset;
729 int i, size;
730
731 offset = CONSOLE_ROW_FIRST +
732 CONSOLE_ROW_SIZE * line + /* offset of row */
733 VIDEO_FONT_WIDTH *
734 VIDEO_PIXEL_SIZE * begin; /* offset of col */
735 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
736 size >>= 2; /* length to end for memsetl() */
737 /* fill at col offset of i'th line using bgx as fill color */
738 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
739 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
740 }
741#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200742 if (cfb_do_flush_cache)
743 flush_cache((ulong)CONSOLE_ROW_FIRST, CONSOLE_SIZE);
Pali Rohár16658612012-04-28 07:26:44 +0000744}
745
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000746static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000747{
wdenke55402c2004-03-14 16:51:43 +0000748 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000749
750#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000751 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
752 0, /* source pos x */
753 video_logo_height +
754 VIDEO_FONT_HEIGHT, /* source pos y */
755 0, /* dest pos x */
756 video_logo_height, /* dest pos y */
757 VIDEO_VISIBLE_COLS, /* frame width */
758 VIDEO_VISIBLE_ROWS
759 - video_logo_height
760 - VIDEO_FONT_HEIGHT /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000761 );
wdenkc6097192002-11-03 00:24:07 +0000762#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000763 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
764 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000765#endif
wdenke55402c2004-03-14 16:51:43 +0000766 /* clear the last one */
Pali Rohár16658612012-04-28 07:26:44 +0000767 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
wdenkc6097192002-11-03 00:24:07 +0000768}
769
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000770static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000771{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500772 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000773
wdenke55402c2004-03-14 16:51:43 +0000774 if (console_col < 0) {
775 console_col = CONSOLE_COLS - 1;
776 console_row--;
777 if (console_row < 0)
778 console_row = 0;
779 }
wdenkc6097192002-11-03 00:24:07 +0000780}
781
Pali Rohár4a57da32012-10-19 13:30:09 +0000782#ifdef CONFIG_CFB_CONSOLE_ANSI
783
784static void console_clear(void)
785{
786#ifdef VIDEO_HW_RECTFILL
787 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
788 0, /* dest pos x */
789 video_logo_height, /* dest pos y */
790 VIDEO_VISIBLE_COLS, /* frame width */
791 VIDEO_VISIBLE_ROWS, /* frame height */
792 bgx /* fill color */
793 );
794#else
795 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
796#endif
797}
798
799static void console_cursor_fix(void)
800{
801 if (console_row < 0)
802 console_row = 0;
803 if (console_row >= CONSOLE_ROWS)
804 console_row = CONSOLE_ROWS - 1;
805 if (console_col < 0)
806 console_col = 0;
807 if (console_col >= CONSOLE_COLS)
808 console_col = CONSOLE_COLS - 1;
809}
810
811static void console_cursor_up(int n)
812{
813 console_row -= n;
814 console_cursor_fix();
815}
816
817static void console_cursor_down(int n)
818{
819 console_row += n;
820 console_cursor_fix();
821}
822
823static void console_cursor_left(int n)
wdenkc6097192002-11-03 00:24:07 +0000824{
Pali Rohár4a57da32012-10-19 13:30:09 +0000825 console_col -= n;
826 console_cursor_fix();
827}
828
829static void console_cursor_right(int n)
830{
831 console_col += n;
832 console_cursor_fix();
833}
834
835static void console_cursor_set_position(int row, int col)
836{
837 if (console_row != -1)
838 console_row = row;
839 if (console_col != -1)
840 console_col = col;
841 console_cursor_fix();
842}
843
844static void console_previousline(int n)
845{
846 /* FIXME: also scroll terminal ? */
847 console_row -= n;
848 console_cursor_fix();
849}
850
851static void console_swap_colors(void)
852{
853 eorx = fgx;
854 fgx = bgx;
855 bgx = eorx;
856 eorx = fgx ^ bgx;
857}
858
859static inline int console_cursor_is_visible(void)
860{
861 return !ansi_cursor_hidden;
862}
863#else
864static inline int console_cursor_is_visible(void)
865{
866 return 1;
867}
868#endif
869
870static void console_newline(int n)
871{
872 console_row += n;
wdenke55402c2004-03-14 16:51:43 +0000873 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000874
wdenke55402c2004-03-14 16:51:43 +0000875 /* Check if we need to scroll the terminal */
876 if (console_row >= CONSOLE_ROWS) {
877 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000878 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000879
wdenke55402c2004-03-14 16:51:43 +0000880 /* Decrement row number */
Pali Rohár4a57da32012-10-19 13:30:09 +0000881 console_row = CONSOLE_ROWS - 1;
wdenke55402c2004-03-14 16:51:43 +0000882 }
wdenkc6097192002-11-03 00:24:07 +0000883}
884
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000885static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100886{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500887 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100888}
889
Pali Rohár4a57da32012-10-19 13:30:09 +0000890static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000891{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100892 static int nl = 1;
893
Pali Rohár4a57da32012-10-19 13:30:09 +0000894 if (console_cursor_is_visible())
895 CURSOR_OFF;
Gabe Black12874de2011-11-30 13:50:50 +0000896
wdenke55402c2004-03-14 16:51:43 +0000897 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100898 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000899 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000900 break;
wdenkc6097192002-11-03 00:24:07 +0000901
wdenke55402c2004-03-14 16:51:43 +0000902 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100903 if (console_col || (!console_col && nl))
Pali Rohár4a57da32012-10-19 13:30:09 +0000904 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100905 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000906 break;
wdenkc6097192002-11-03 00:24:07 +0000907
wdenke55402c2004-03-14 16:51:43 +0000908 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500909 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000910 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000911
wdenke55402c2004-03-14 16:51:43 +0000912 if (console_col >= CONSOLE_COLS)
Pali Rohár4a57da32012-10-19 13:30:09 +0000913 console_newline(1);
wdenke55402c2004-03-14 16:51:43 +0000914 break;
wdenkc6097192002-11-03 00:24:07 +0000915
wdenke55402c2004-03-14 16:51:43 +0000916 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000917 console_back();
wdenke55402c2004-03-14 16:51:43 +0000918 break;
wdenkc6097192002-11-03 00:24:07 +0000919
Pali Rohár9d735b62012-04-28 07:26:47 +0000920 case 7: /* bell */
921 break; /* ignored */
922
wdenke55402c2004-03-14 16:51:43 +0000923 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000924 video_putchar(console_col * VIDEO_FONT_WIDTH,
925 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000926 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000927
wdenke55402c2004-03-14 16:51:43 +0000928 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100929 if (console_col >= CONSOLE_COLS) {
Pali Rohár4a57da32012-10-19 13:30:09 +0000930 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100931 nl = 0;
932 }
wdenke55402c2004-03-14 16:51:43 +0000933 }
Pali Rohár4a57da32012-10-19 13:30:09 +0000934
935 if (console_cursor_is_visible())
936 CURSOR_SET;
937}
938
939void video_putc(const char c)
940{
941#ifdef CONFIG_CFB_CONSOLE_ANSI
942 int i;
943
944 if (c == 27) {
945 for (i = 0; i < ansi_buf_size; ++i)
946 parse_putc(ansi_buf[i]);
947 ansi_buf[0] = 27;
948 ansi_buf_size = 1;
949 return;
950 }
951
952 if (ansi_buf_size > 0) {
953 /*
954 * 0 - ESC
955 * 1 - [
956 * 2 - num1
957 * 3 - ..
958 * 4 - ;
959 * 5 - num2
960 * 6 - ..
961 * - cchar
962 */
963 int next = 0;
964
965 int flush = 0;
966 int fail = 0;
967
968 int num1 = 0;
969 int num2 = 0;
970 int cchar = 0;
971
972 ansi_buf[ansi_buf_size++] = c;
973
974 if (ansi_buf_size >= sizeof(ansi_buf))
975 fail = 1;
976
977 for (i = 0; i < ansi_buf_size; ++i) {
978 if (fail)
979 break;
980
981 switch (next) {
982 case 0:
983 if (ansi_buf[i] == 27)
984 next = 1;
985 else
986 fail = 1;
987 break;
988
989 case 1:
990 if (ansi_buf[i] == '[')
991 next = 2;
992 else
993 fail = 1;
994 break;
995
996 case 2:
997 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
998 num1 = ansi_buf[i]-'0';
999 next = 3;
1000 } else if (ansi_buf[i] != '?') {
1001 --i;
1002 num1 = 1;
1003 next = 4;
1004 }
1005 break;
1006
1007 case 3:
1008 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1009 num1 *= 10;
1010 num1 += ansi_buf[i]-'0';
1011 } else {
1012 --i;
1013 next = 4;
1014 }
1015 break;
1016
1017 case 4:
1018 if (ansi_buf[i] != ';') {
1019 --i;
1020 next = 7;
1021 } else
1022 next = 5;
1023 break;
1024
1025 case 5:
1026 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1027 num2 = ansi_buf[i]-'0';
1028 next = 6;
1029 } else
1030 fail = 1;
1031 break;
1032
1033 case 6:
1034 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1035 num2 *= 10;
1036 num2 += ansi_buf[i]-'0';
1037 } else {
1038 --i;
1039 next = 7;
1040 }
1041 break;
1042
1043 case 7:
1044 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1045 || ansi_buf[i] == 'J'
1046 || ansi_buf[i] == 'K'
1047 || ansi_buf[i] == 'h'
1048 || ansi_buf[i] == 'l'
1049 || ansi_buf[i] == 'm') {
1050 cchar = ansi_buf[i];
1051 flush = 1;
1052 } else
1053 fail = 1;
1054 break;
1055 }
1056 }
1057
1058 if (fail) {
1059 for (i = 0; i < ansi_buf_size; ++i)
1060 parse_putc(ansi_buf[i]);
1061 ansi_buf_size = 0;
1062 return;
1063 }
1064
1065 if (flush) {
1066 if (!ansi_cursor_hidden)
1067 CURSOR_OFF;
1068 ansi_buf_size = 0;
1069 switch (cchar) {
1070 case 'A':
1071 /* move cursor num1 rows up */
1072 console_cursor_up(num1);
1073 break;
1074 case 'B':
1075 /* move cursor num1 rows down */
1076 console_cursor_down(num1);
1077 break;
1078 case 'C':
1079 /* move cursor num1 columns forward */
1080 console_cursor_right(num1);
1081 break;
1082 case 'D':
1083 /* move cursor num1 columns back */
1084 console_cursor_left(num1);
1085 break;
1086 case 'E':
1087 /* move cursor num1 rows up at begin of row */
1088 console_previousline(num1);
1089 break;
1090 case 'F':
1091 /* move cursor num1 rows down at begin of row */
1092 console_newline(num1);
1093 break;
1094 case 'G':
1095 /* move cursor to column num1 */
1096 console_cursor_set_position(-1, num1-1);
1097 break;
1098 case 'H':
1099 /* move cursor to row num1, column num2 */
1100 console_cursor_set_position(num1-1, num2-1);
1101 break;
1102 case 'J':
1103 /* clear console and move cursor to 0, 0 */
1104 console_clear();
1105 console_cursor_set_position(0, 0);
1106 break;
1107 case 'K':
1108 /* clear line */
1109 if (num1 == 0)
1110 console_clear_line(console_row,
1111 console_col,
1112 CONSOLE_COLS-1);
1113 else if (num1 == 1)
1114 console_clear_line(console_row,
1115 0, console_col);
1116 else
1117 console_clear_line(console_row,
1118 0, CONSOLE_COLS-1);
1119 break;
1120 case 'h':
1121 ansi_cursor_hidden = 0;
1122 break;
1123 case 'l':
1124 ansi_cursor_hidden = 1;
1125 break;
1126 case 'm':
1127 if (num1 == 0) { /* reset swapped colors */
1128 if (ansi_colors_need_revert) {
1129 console_swap_colors();
1130 ansi_colors_need_revert = 0;
1131 }
1132 } else if (num1 == 7) { /* once swap colors */
1133 if (!ansi_colors_need_revert) {
1134 console_swap_colors();
1135 ansi_colors_need_revert = 1;
1136 }
1137 }
1138 break;
1139 }
1140 if (!ansi_cursor_hidden)
1141 CURSOR_SET;
1142 }
1143 } else {
1144 parse_putc(c);
1145 }
1146#else
1147 parse_putc(c);
1148#endif
Timur Tabibe0c74e2010-08-27 15:45:47 -05001149}
wdenkc6097192002-11-03 00:24:07 +00001150
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001151void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +00001152{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001153 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +00001154
1155 while (count--)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001156 video_putc(*s++);
wdenke55402c2004-03-14 16:51:43 +00001157}
1158
Anatolij Gustschina043c342010-05-01 22:21:09 +02001159/*
1160 * Do not enforce drivers (or board code) to provide empty
1161 * video_set_lut() if they do not support 8 bpp format.
1162 * Implement weak default function instead.
1163 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001164void __video_set_lut(unsigned int index, unsigned char r,
1165 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +02001166{
1167}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001168
1169void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
1170 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschina043c342010-05-01 22:21:09 +02001171
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001172#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +00001173
1174#define FILL_8BIT_332RGB(r,g,b) { \
1175 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1176 fb ++; \
1177}
1178
1179#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001180 *(unsigned short *)fb = \
1181 SWAP16((unsigned short)(((r>>3)<<10) | \
1182 ((g>>3)<<5) | \
1183 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001184 fb += 2; \
1185}
1186
1187#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001188 *(unsigned short *)fb = \
1189 SWAP16((unsigned short)((((r)>>3)<<11)| \
1190 (((g)>>2)<<5) | \
1191 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001192 fb += 2; \
1193}
1194
1195#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001196 *(unsigned long *)fb = \
1197 SWAP32((unsigned long)(((r<<16) | \
1198 (g<<8) | \
1199 b))); \
wdenke55402c2004-03-14 16:51:43 +00001200 fb += 4; \
1201}
1202
1203#ifdef VIDEO_FB_LITTLE_ENDIAN
1204#define FILL_24BIT_888RGB(r,g,b) { \
1205 fb[0] = b; \
1206 fb[1] = g; \
1207 fb[2] = r; \
1208 fb += 3; \
1209}
1210#else
1211#define FILL_24BIT_888RGB(r,g,b) { \
1212 fb[0] = r; \
1213 fb[1] = g; \
1214 fb[2] = b; \
1215 fb += 3; \
1216}
1217#endif
1218
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001219#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001220static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001221{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001222 ushort *dst = (ushort *) fb;
1223 ushort color = (ushort) (((r >> 3) << 10) |
1224 ((g >> 3) << 5) |
1225 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001226 if (x & 1)
1227 *(--dst) = color;
1228 else
1229 *(++dst) = color;
1230}
1231#endif
wdenke55402c2004-03-14 16:51:43 +00001232
1233/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001234 * RLE8 bitmap support
1235 */
1236
1237#ifdef CONFIG_VIDEO_BMP_RLE8
1238/* Pre-calculated color table entry */
1239struct palette {
1240 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001241 unsigned short w; /* word */
1242 unsigned int dw; /* double word */
1243 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001244};
1245
1246/*
1247 * Helper to draw encoded/unencoded run.
1248 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001249static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1250 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001251{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001252 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001253 int *off;
1254 int enc_off = 1;
1255 int i;
1256
1257 /*
1258 * Setup offset of the color index in the bitmap.
1259 * Color index of encoded run is at offset 1.
1260 */
1261 off = enc ? &enc_off : &i;
1262
1263 switch (VIDEO_DATA_FORMAT) {
1264 case GDF__8BIT_INDEX:
1265 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001266 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001267 break;
1268 case GDF_15BIT_555RGB:
1269 case GDF_16BIT_565RGB:
1270 /* differences handled while pre-calculating palette */
1271 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001272 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001273 addr += 2;
1274 }
1275 break;
1276 case GDF_32BIT_X888RGB:
1277 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001278 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001279 addr += 4;
1280 }
1281 break;
1282 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001283 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001284}
1285
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001286static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1287 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001288{
1289 unsigned char *bm;
1290 unsigned char *fbp;
1291 unsigned int cnt, runlen;
1292 int decode = 1;
1293 int x, y, bpp, i, ncolors;
1294 struct palette p[256];
1295 bmp_color_table_entry_t cte;
1296 int green_shift, red_off;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001297 int limit = VIDEO_COLS * VIDEO_ROWS;
1298 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001299
1300 x = 0;
1301 y = __le32_to_cpu(img->header.height) - 1;
1302 ncolors = __le32_to_cpu(img->header.colors_used);
1303 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001304 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1305 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001306
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001307 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001308
1309 /* pre-calculate and setup palette */
1310 switch (VIDEO_DATA_FORMAT) {
1311 case GDF__8BIT_INDEX:
1312 for (i = 0; i < ncolors; i++) {
1313 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001314 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001315 }
1316 break;
1317 case GDF_15BIT_555RGB:
1318 case GDF_16BIT_565RGB:
1319 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1320 green_shift = 3;
1321 red_off = 10;
1322 } else {
1323 green_shift = 2;
1324 red_off = 11;
1325 }
1326 for (i = 0; i < ncolors; i++) {
1327 cte = img->color_table[i];
1328 p[i].ce.w = SWAP16((unsigned short)
1329 (((cte.red >> 3) << red_off) |
1330 ((cte.green >> green_shift) << 5) |
1331 cte.blue >> 3));
1332 }
1333 break;
1334 case GDF_32BIT_X888RGB:
1335 for (i = 0; i < ncolors; i++) {
1336 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001337 p[i].ce.dw = SWAP32((cte.red << 16) |
1338 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001339 cte.blue);
1340 }
1341 break;
1342 default:
1343 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001344 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001345 return -1;
1346 }
1347
1348 while (decode) {
1349 switch (bm[0]) {
1350 case 0:
1351 switch (bm[1]) {
1352 case 0:
1353 /* scan line end marker */
1354 bm += 2;
1355 x = 0;
1356 y--;
1357 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001358 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001359 (((y + yoff) * VIDEO_COLS) +
1360 xoff) * bpp);
1361 continue;
1362 case 1:
1363 /* end of bitmap data marker */
1364 decode = 0;
1365 break;
1366 case 2:
1367 /* run offset marker */
1368 x += bm[2];
1369 y -= bm[3];
1370 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001371 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001372 (((y + yoff) * VIDEO_COLS) +
1373 x + xoff) * bpp);
1374 bm += 4;
1375 break;
1376 default:
1377 /* unencoded run */
1378 cnt = bm[1];
1379 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001380 pixels += cnt;
1381 if (pixels > limit)
1382 goto error;
1383
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001384 bm += 2;
1385 if (y < height) {
1386 if (x >= width) {
1387 x += runlen;
1388 goto next_run;
1389 }
1390 if (x + runlen > width)
1391 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001392 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001393 x += runlen;
1394 }
1395next_run:
1396 bm += runlen;
1397 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001398 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001399 }
1400 break;
1401 default:
1402 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001403 cnt = bm[0];
1404 runlen = cnt;
1405 pixels += cnt;
1406 if (pixels > limit)
1407 goto error;
1408
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001409 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001410 if (x >= width) {
1411 x += runlen;
1412 bm += 2;
1413 continue;
1414 }
1415 if (x + runlen > width)
1416 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001417 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001418 x += runlen;
1419 }
1420 bm += 2;
1421 break;
1422 }
1423 }
1424 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001425error:
1426 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1427 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001428}
1429#endif
1430
1431/*
wdenke55402c2004-03-14 16:51:43 +00001432 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001433 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001434int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001435{
1436 ushort xcount, ycount;
1437 uchar *fb;
1438 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1439 uchar *bmap;
1440 ushort padded_line;
1441 unsigned long width, height, bpp;
1442 unsigned colors;
1443 unsigned long compression;
1444 bmp_color_table_entry_t cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001445
Stefan Roesed9d97742005-09-22 09:04:17 +02001446#ifdef CONFIG_VIDEO_BMP_GZIP
1447 unsigned char *dst = NULL;
1448 ulong len;
1449#endif
wdenkc6097192002-11-03 00:24:07 +00001450
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001451 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001452
1453 if (!((bmp->header.signature[0] == 'B') &&
1454 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001455
1456#ifdef CONFIG_VIDEO_BMP_GZIP
1457 /*
1458 * Could be a gzipped bmp image, try to decrompress...
1459 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001460 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1461 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001462 if (dst == NULL) {
1463 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001464 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001465 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001466 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1467 (uchar *) bmp_image,
1468 &len) != 0) {
1469 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1470 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001471 free(dst);
1472 return 1;
1473 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001474 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001475 printf("Image could be truncated "
1476 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001477 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001478
1479 /*
1480 * Set addr to decompressed image
1481 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001482 bmp = (bmp_image_t *) dst;
Stefan Roesed9d97742005-09-22 09:04:17 +02001483
1484 if (!((bmp->header.signature[0] == 'B') &&
1485 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001486 printf("Error: no valid bmp.gz image at %lx\n",
1487 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001488 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001489 return 1;
1490 }
1491#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001492 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001493 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001494#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001495 }
1496
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001497 width = le32_to_cpu(bmp->header.width);
1498 height = le32_to_cpu(bmp->header.height);
1499 bpp = le16_to_cpu(bmp->header.bit_count);
1500 colors = le32_to_cpu(bmp->header.colors_used);
1501 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001502
Marek Vasut2eb9a492011-10-21 14:17:04 +00001503 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001504 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001505
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001506 if (compression != BMP_BI_RGB
1507#ifdef CONFIG_VIDEO_BMP_RLE8
1508 && compression != BMP_BI_RLE8
1509#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001510 ) {
1511 printf("Error: compression type %ld not supported\n",
1512 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001513#ifdef CONFIG_VIDEO_BMP_GZIP
1514 if (dst)
1515 free(dst);
1516#endif
wdenke55402c2004-03-14 16:51:43 +00001517 return 1;
1518 }
1519
1520 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1521
Matthias Weisser53884182009-07-09 16:07:30 +02001522#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1523 if (x == BMP_ALIGN_CENTER)
1524 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1525 else if (x < 0)
1526 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1527
1528 if (y == BMP_ALIGN_CENTER)
1529 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1530 else if (y < 0)
1531 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1532#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1533
Matthias Weisser5e5ed762013-02-15 03:35:12 +00001534 /*
1535 * Just ignore elements which are completely beyond screen
1536 * dimensions.
1537 */
1538 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1539 return 0;
1540
wdenke55402c2004-03-14 16:51:43 +00001541 if ((x + width) > VIDEO_VISIBLE_COLS)
1542 width = VIDEO_VISIBLE_COLS - x;
1543 if ((y + height) > VIDEO_VISIBLE_ROWS)
1544 height = VIDEO_VISIBLE_ROWS - y;
1545
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001546 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001547 fb = (uchar *) (video_fb_address +
1548 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1549 x * VIDEO_PIXEL_SIZE);
1550
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001551#ifdef CONFIG_VIDEO_BMP_RLE8
1552 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001553 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001554 }
1555#endif
1556
Timur Tabi0fce9922010-08-23 16:58:00 -05001557 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001558 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001559 case 4:
1560 padded_line -= width / 2;
1561 ycount = height;
1562
1563 switch (VIDEO_DATA_FORMAT) {
1564 case GDF_32BIT_X888RGB:
1565 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001566 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001567 /*
1568 * Don't assume that 'width' is an
1569 * even number
1570 */
1571 for (xcount = 0; xcount < width; xcount++) {
1572 uchar idx;
1573
1574 if (xcount & 1) {
1575 idx = *bmap & 0xF;
1576 bmap++;
1577 } else
1578 idx = *bmap >> 4;
1579 cte = bmp->color_table[idx];
1580 FILL_32BIT_X888RGB(cte.red, cte.green,
1581 cte.blue);
1582 }
1583 bmap += padded_line;
1584 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001585 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001586 }
1587 break;
1588 default:
1589 puts("4bpp bitmap unsupported with current "
1590 "video mode\n");
1591 break;
1592 }
1593 break;
1594
wdenke55402c2004-03-14 16:51:43 +00001595 case 8:
1596 padded_line -= width;
1597 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001598 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001599 for (xcount = 0; xcount < colors; ++xcount) {
1600 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001601 video_set_lut(xcount, cte.red, cte.green,
1602 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001603 }
1604 }
1605 ycount = height;
1606 switch (VIDEO_DATA_FORMAT) {
1607 case GDF__8BIT_INDEX:
1608 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001609 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001610 xcount = width;
1611 while (xcount--) {
1612 *fb++ = *bmap++;
1613 }
1614 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001615 fb -= (VIDEO_VISIBLE_COLS + width) *
1616 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001617 }
1618 break;
1619 case GDF__8BIT_332RGB:
1620 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001621 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001622 xcount = width;
1623 while (xcount--) {
1624 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001625 FILL_8BIT_332RGB(cte.red, cte.green,
1626 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001627 }
1628 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001629 fb -= (VIDEO_VISIBLE_COLS + width) *
1630 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001631 }
1632 break;
1633 case GDF_15BIT_555RGB:
1634 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001635#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1636 int xpos = x;
1637#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001638 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001639 xcount = width;
1640 while (xcount--) {
1641 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001642#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001643 fill_555rgb_pswap(fb, xpos++, cte.red,
1644 cte.green,
1645 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001646 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001647#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001648 FILL_15BIT_555RGB(cte.red, cte.green,
1649 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001650#endif
wdenke55402c2004-03-14 16:51:43 +00001651 }
1652 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001653 fb -= (VIDEO_VISIBLE_COLS + width) *
1654 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001655 }
1656 break;
1657 case GDF_16BIT_565RGB:
1658 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001659 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001660 xcount = width;
1661 while (xcount--) {
1662 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001663 FILL_16BIT_565RGB(cte.red, cte.green,
1664 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001665 }
1666 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001667 fb -= (VIDEO_VISIBLE_COLS + width) *
1668 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001669 }
1670 break;
1671 case GDF_32BIT_X888RGB:
1672 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001673 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001674 xcount = width;
1675 while (xcount--) {
1676 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001677 FILL_32BIT_X888RGB(cte.red, cte.green,
1678 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001679 }
1680 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001681 fb -= (VIDEO_VISIBLE_COLS + width) *
1682 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001683 }
1684 break;
1685 case GDF_24BIT_888RGB:
1686 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001687 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001688 xcount = width;
1689 while (xcount--) {
1690 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001691 FILL_24BIT_888RGB(cte.red, cte.green,
1692 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001693 }
1694 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001695 fb -= (VIDEO_VISIBLE_COLS + width) *
1696 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001697 }
1698 break;
1699 }
1700 break;
1701 case 24:
1702 padded_line -= 3 * width;
1703 ycount = height;
1704 switch (VIDEO_DATA_FORMAT) {
1705 case GDF__8BIT_332RGB:
1706 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001707 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001708 xcount = width;
1709 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001710 FILL_8BIT_332RGB(bmap[2], bmap[1],
1711 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001712 bmap += 3;
1713 }
1714 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001715 fb -= (VIDEO_VISIBLE_COLS + width) *
1716 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001717 }
1718 break;
1719 case GDF_15BIT_555RGB:
1720 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001721#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1722 int xpos = x;
1723#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001724 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001725 xcount = width;
1726 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001727#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001728 fill_555rgb_pswap(fb, xpos++, bmap[2],
1729 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001730 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001731#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001732 FILL_15BIT_555RGB(bmap[2], bmap[1],
1733 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001734#endif
wdenke55402c2004-03-14 16:51:43 +00001735 bmap += 3;
1736 }
1737 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001738 fb -= (VIDEO_VISIBLE_COLS + width) *
1739 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001740 }
1741 break;
1742 case GDF_16BIT_565RGB:
1743 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001744 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001745 xcount = width;
1746 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001747 FILL_16BIT_565RGB(bmap[2], bmap[1],
1748 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001749 bmap += 3;
1750 }
1751 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001752 fb -= (VIDEO_VISIBLE_COLS + width) *
1753 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001754 }
1755 break;
1756 case GDF_32BIT_X888RGB:
1757 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001758 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001759 xcount = width;
1760 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001761 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1762 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001763 bmap += 3;
1764 }
1765 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001766 fb -= (VIDEO_VISIBLE_COLS + width) *
1767 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001768 }
1769 break;
1770 case GDF_24BIT_888RGB:
1771 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001772 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001773 xcount = width;
1774 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001775 FILL_24BIT_888RGB(bmap[2], bmap[1],
1776 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001777 bmap += 3;
1778 }
1779 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001780 fb -= (VIDEO_VISIBLE_COLS + width) *
1781 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001782 }
1783 break;
1784 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001785 printf("Error: 24 bits/pixel bitmap incompatible "
1786 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001787 break;
1788 }
1789 break;
1790 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001791 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1792 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001793 break;
1794 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001795
1796#ifdef CONFIG_VIDEO_BMP_GZIP
1797 if (dst) {
1798 free(dst);
1799 }
1800#endif
1801
wdenke55402c2004-03-14 16:51:43 +00001802 return (0);
wdenkc6097192002-11-03 00:24:07 +00001803}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001804#endif
wdenkc6097192002-11-03 00:24:07 +00001805
wdenkc6097192002-11-03 00:24:07 +00001806
1807#ifdef CONFIG_VIDEO_LOGO
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001808static int video_logo_xpos;
1809static int video_logo_ypos;
1810
Bastian Ruppertd5932182012-09-13 22:29:02 +00001811static void plot_logo_or_black(void *screen, int width, int x, int y, \
1812 int black);
1813
1814static void logo_plot(void *screen, int width, int x, int y)
1815{
1816 plot_logo_or_black(screen, width, x, y, 0);
1817}
1818
1819static void logo_black(void)
1820{
1821 plot_logo_or_black(video_fb_address, \
1822 VIDEO_COLS, \
1823 video_logo_xpos, \
1824 video_logo_ypos, \
1825 1);
1826}
1827
1828static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1829{
1830 if (argc != 1)
1831 return cmd_usage(cmdtp);
1832
1833 logo_black();
1834 return 0;
1835}
1836
1837U_BOOT_CMD(
1838 clrlogo, 1, 0, do_clrlogo,
1839 "fill the boot logo area with black",
1840 " "
1841 );
1842
1843static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001844{
wdenk9dd2b882002-12-03 21:28:10 +00001845
wdenke55402c2004-03-14 16:51:43 +00001846 int xcount, i;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001847 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001848 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001849 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1850 unsigned char *source;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001851 unsigned char *dest;
1852
1853#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1854 if (x == BMP_ALIGN_CENTER)
1855 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1856 else if (x < 0)
1857 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1858
1859 if (y == BMP_ALIGN_CENTER)
1860 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1861 else if (y < 0)
1862 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1863#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1864
1865 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001866
wdenk9dd2b882002-12-03 21:28:10 +00001867#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001868 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001869
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001870 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001871 logo_red = malloc(BMP_LOGO_COLORS);
1872 logo_green = malloc(BMP_LOGO_COLORS);
1873 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001874 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001875 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1876 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1877 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1878 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1879 }
wdenk9dd2b882002-12-03 21:28:10 +00001880#else
wdenke55402c2004-03-14 16:51:43 +00001881 source = linux_logo;
1882 logo_red = linux_logo_red;
1883 logo_green = linux_logo_green;
1884 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001885#endif
wdenk57b2d802003-06-27 21:31:46 +00001886
wdenke55402c2004-03-14 16:51:43 +00001887 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1888 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001889 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1890 logo_red[i], logo_green[i],
1891 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001892 }
wdenk57b2d802003-06-27 21:31:46 +00001893 }
wdenkc6097192002-11-03 00:24:07 +00001894
wdenke55402c2004-03-14 16:51:43 +00001895 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001896#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1897 int xpos = x;
1898#endif
wdenke55402c2004-03-14 16:51:43 +00001899 xcount = VIDEO_LOGO_WIDTH;
1900 while (xcount--) {
Bastian Ruppertd5932182012-09-13 22:29:02 +00001901 if (black) {
1902 r = 0x00;
1903 g = 0x00;
1904 b = 0x00;
1905 } else {
1906 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1907 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1908 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1909 }
wdenk57b2d802003-06-27 21:31:46 +00001910
wdenke55402c2004-03-14 16:51:43 +00001911 switch (VIDEO_DATA_FORMAT) {
1912 case GDF__8BIT_INDEX:
1913 *dest = *source;
1914 break;
1915 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001916 *dest = ((r >> 5) << 5) |
1917 ((g >> 5) << 2) |
1918 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001919 break;
1920 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001921#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001922 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001923#else
wdenke55402c2004-03-14 16:51:43 +00001924 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001925 SWAP16((unsigned short) (
1926 ((r >> 3) << 10) |
1927 ((g >> 3) << 5) |
1928 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001929#endif
wdenke55402c2004-03-14 16:51:43 +00001930 break;
1931 case GDF_16BIT_565RGB:
1932 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001933 SWAP16((unsigned short) (
1934 ((r >> 3) << 11) |
1935 ((g >> 2) << 5) |
1936 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001937 break;
1938 case GDF_32BIT_X888RGB:
1939 *(unsigned long *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001940 SWAP32((unsigned long) (
1941 (r << 16) |
1942 (g << 8) |
1943 b));
wdenke55402c2004-03-14 16:51:43 +00001944 break;
1945 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001946#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001947 dest[0] = b;
1948 dest[1] = g;
1949 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001950#else
wdenke55402c2004-03-14 16:51:43 +00001951 dest[0] = r;
1952 dest[1] = g;
1953 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001954#endif
wdenke55402c2004-03-14 16:51:43 +00001955 break;
1956 }
1957 source++;
1958 dest += VIDEO_PIXEL_SIZE;
1959 }
1960 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001961 }
wdenk9dd2b882002-12-03 21:28:10 +00001962#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001963 free(logo_red);
1964 free(logo_green);
1965 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001966#endif
wdenkc6097192002-11-03 00:24:07 +00001967}
1968
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001969static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001970{
wdenke55402c2004-03-14 16:51:43 +00001971 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001972 int space, len;
1973 __maybe_unused int y_off = 0;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001974 __maybe_unused ulong addr;
1975 __maybe_unused char *s;
wdenke55402c2004-03-14 16:51:43 +00001976
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001977#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1978 s = getenv("splashpos");
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001979 if (s != NULL) {
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001980 if (s[0] == 'm')
1981 video_logo_xpos = BMP_ALIGN_CENTER;
1982 else
1983 video_logo_xpos = simple_strtol(s, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001984
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001985 s = strchr(s + 1, ',');
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001986 if (s != NULL) {
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001987 if (s[1] == 'm')
1988 video_logo_ypos = BMP_ALIGN_CENTER;
Matthias Weisser53884182009-07-09 16:07:30 +02001989 else
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001990 video_logo_ypos = simple_strtol(s + 1, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001991 }
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001992 }
Matthias Weisser53884182009-07-09 16:07:30 +02001993#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
wdenke55402c2004-03-14 16:51:43 +00001994
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001995#ifdef CONFIG_SPLASH_SCREEN
1996 s = getenv("splashimage");
1997 if (s != NULL) {
1998
1999 addr = simple_strtoul(s, NULL, 16);
2000
2001
2002 if (video_display_bitmap(addr,
2003 video_logo_xpos,
2004 video_logo_ypos) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01002005 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00002006 return ((void *) (video_fb_address));
2007 }
2008 }
2009#endif /* CONFIG_SPLASH_SCREEN */
2010
Bastian Rupperta13e81f2012-09-13 22:29:01 +00002011 logo_plot(video_fb_address, VIDEO_COLS,
2012 video_logo_xpos, video_logo_ypos);
2013
2014#ifdef CONFIG_SPLASH_SCREEN_ALIGN
2015 /*
2016 * when using splashpos for video_logo, skip any info
2017 * output on video console if the logo is not at 0,0
2018 */
2019 if (video_logo_xpos || video_logo_ypos) {
2020 /*
2021 * video_logo_height is used in text and cursor offset
2022 * calculations. Since the console is below the logo,
2023 * we need to adjust the logo height
2024 */
2025 if (video_logo_ypos == BMP_ALIGN_CENTER)
2026 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
2027 VIDEO_LOGO_HEIGHT) / 2);
2028 else if (video_logo_ypos > 0)
2029 video_logo_height += video_logo_ypos;
2030
2031 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2032 }
2033#endif
wdenkc6097192002-11-03 00:24:07 +00002034
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002035 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002036
2037 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2038 len = strlen(info);
2039
2040 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002041 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2042 (uchar *) info, space);
2043 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2044 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2045 (uchar *) info + space, len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002046 y_off = 1;
2047 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002048 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00002049
2050#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00002051 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002052 int i, n =
2053 ((video_logo_height -
2054 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002055
wdenke55402c2004-03-14 16:51:43 +00002056 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002057 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002058 if (!*info)
2059 continue;
2060
2061 len = strlen(info);
2062 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002063 video_drawchars(VIDEO_INFO_X,
2064 VIDEO_INFO_Y +
2065 (i + y_off) *
2066 VIDEO_FONT_HEIGHT,
2067 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002068 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002069 video_drawchars(VIDEO_INFO_X +
2070 VIDEO_FONT_WIDTH,
2071 VIDEO_INFO_Y +
2072 (i + y_off) *
2073 VIDEO_FONT_HEIGHT,
2074 (uchar *) info + space,
2075 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002076 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002077 video_drawstring(VIDEO_INFO_X,
2078 VIDEO_INFO_Y +
2079 (i + y_off) *
2080 VIDEO_FONT_HEIGHT,
2081 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002082 }
wdenke55402c2004-03-14 16:51:43 +00002083 }
2084 }
wdenkc6097192002-11-03 00:24:07 +00002085#endif
2086
Matthias Weisser76d70862010-01-12 12:06:31 +01002087 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002088}
2089#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002090
2091static int cfb_fb_is_in_dram(void)
2092{
2093 bd_t *bd = gd->bd;
2094#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2095defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2096 ulong start, end;
2097 int i;
2098
2099 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2100 start = bd->bi_dram[i].start;
2101 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2102 if ((ulong)video_fb_address >= start &&
2103 (ulong)video_fb_address < end)
2104 return 1;
2105 }
2106#else
2107 if ((ulong)video_fb_address >= bd->bi_memstart &&
2108 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2109 return 1;
2110#endif
2111 return 0;
2112}
wdenkc6097192002-11-03 00:24:07 +00002113
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002114static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002115{
wdenke55402c2004-03-14 16:51:43 +00002116 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002117
Wolfgang Denka87b2a952011-07-30 12:48:09 +00002118 pGD = video_hw_init();
2119 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00002120 return -1;
wdenkc6097192002-11-03 00:24:07 +00002121
wdenke55402c2004-03-14 16:51:43 +00002122 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002123#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002124 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002125#endif
2126
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002127 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2128
wdenke55402c2004-03-14 16:51:43 +00002129 /* Init drawing pats */
2130 switch (VIDEO_DATA_FORMAT) {
2131 case GDF__8BIT_INDEX:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002132 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2133 CONSOLE_FG_COL);
2134 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2135 CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00002136 fgx = 0x01010101;
2137 bgx = 0x00000000;
2138 break;
2139 case GDF__8BIT_332RGB:
2140 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002141 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2142 CONSOLE_FG_COL >> 6);
2143 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2144 color8;
wdenke55402c2004-03-14 16:51:43 +00002145 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002146 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2147 CONSOLE_BG_COL >> 6);
2148 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2149 color8;
wdenke55402c2004-03-14 16:51:43 +00002150 break;
2151 case GDF_15BIT_555RGB:
2152 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002153 ((CONSOLE_FG_COL >> 3) << 21) |
2154 ((CONSOLE_FG_COL >> 3) << 16) |
2155 ((CONSOLE_FG_COL >> 3) << 10) |
2156 ((CONSOLE_FG_COL >> 3) << 5) |
2157 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002158 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002159 ((CONSOLE_BG_COL >> 3) << 21) |
2160 ((CONSOLE_BG_COL >> 3) << 16) |
2161 ((CONSOLE_BG_COL >> 3) << 10) |
2162 ((CONSOLE_BG_COL >> 3) << 5) |
2163 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002164 break;
2165 case GDF_16BIT_565RGB:
2166 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002167 ((CONSOLE_FG_COL >> 2) << 21) |
2168 ((CONSOLE_FG_COL >> 3) << 16) |
2169 ((CONSOLE_FG_COL >> 3) << 11) |
2170 ((CONSOLE_FG_COL >> 2) << 5) |
2171 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002172 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002173 ((CONSOLE_BG_COL >> 2) << 21) |
2174 ((CONSOLE_BG_COL >> 3) << 16) |
2175 ((CONSOLE_BG_COL >> 3) << 11) |
2176 ((CONSOLE_BG_COL >> 2) << 5) |
2177 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002178 break;
2179 case GDF_32BIT_X888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002180 fgx = (CONSOLE_FG_COL << 16) |
2181 (CONSOLE_FG_COL << 8) |
2182 CONSOLE_FG_COL;
2183 bgx = (CONSOLE_BG_COL << 16) |
2184 (CONSOLE_BG_COL << 8) |
2185 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002186 break;
2187 case GDF_24BIT_888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002188 fgx = (CONSOLE_FG_COL << 24) |
2189 (CONSOLE_FG_COL << 16) |
2190 (CONSOLE_FG_COL << 8) |
2191 CONSOLE_FG_COL;
2192 bgx = (CONSOLE_BG_COL << 24) |
2193 (CONSOLE_BG_COL << 16) |
2194 (CONSOLE_BG_COL << 8) |
2195 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002196 break;
2197 }
2198 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002199
2200#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00002201 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00002202 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002203 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002204#else
wdenke55402c2004-03-14 16:51:43 +00002205 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002206#endif
2207
wdenke55402c2004-03-14 16:51:43 +00002208 /* Initialize the console */
2209 console_col = 0;
2210 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002211
wdenke55402c2004-03-14 16:51:43 +00002212 return 0;
wdenkc6097192002-11-03 00:24:07 +00002213}
2214
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002215/*
2216 * Implement a weak default function for boards that optionally
2217 * need to skip the video initialization.
2218 */
2219int __board_video_skip(void)
2220{
2221 /* As default, don't skip test */
2222 return 0;
2223}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002224
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002225int board_video_skip(void)
2226 __attribute__ ((weak, alias("__board_video_skip")));
2227
2228int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002229{
wdenke55402c2004-03-14 16:51:43 +00002230 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02002231 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00002232
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002233 /* Check if video initialization should be skipped */
2234 if (board_video_skip())
2235 return 0;
2236
wdenk7dd13292004-07-11 20:04:51 +00002237 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002238 skip_dev_init = (video_init() == -1);
wdenkc6097192002-11-03 00:24:07 +00002239
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002240#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk46717712011-07-29 09:55:28 +00002241 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002242 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2243#endif
wdenkc6097192002-11-03 00:24:07 +00002244
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002245 if (skip_dev_init)
2246 return 0;
wdenkc6097192002-11-03 00:24:07 +00002247
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002248 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002249 memset(&console_dev, 0, sizeof(console_dev));
2250 strcpy(console_dev.name, "vga");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002251 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2252 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2253 console_dev.putc = video_putc; /* 'putc' function */
2254 console_dev.puts = video_puts; /* 'puts' function */
2255 console_dev.tstc = NULL; /* 'tstc' function */
2256 console_dev.getc = NULL; /* 'getc' function */
2257
2258#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2259 /* Also init console device */
2260 console_dev.flags |= DEV_FLAGS_INPUT;
2261 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2262 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00002263#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002264
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002265 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002266 return 0;
2267
2268 /* Return success */
2269 return 1;
wdenkc6097192002-11-03 00:24:07 +00002270}
Stefan Reinauer7870da32012-09-28 15:11:12 +00002271
2272void video_position_cursor(unsigned col, unsigned row)
2273{
2274 console_col = min(col, CONSOLE_COLS - 1);
2275 console_row = min(row, CONSOLE_ROWS - 1);
2276}
2277
2278int video_get_pixel_width(void)
2279{
2280 return VIDEO_VISIBLE_COLS;
2281}
2282
2283int video_get_pixel_height(void)
2284{
2285 return VIDEO_VISIBLE_ROWS;
2286}
2287
2288int video_get_screen_rows(void)
2289{
2290 return CONSOLE_ROWS;
2291}
2292
2293int video_get_screen_columns(void)
2294{
2295 return CONSOLE_COLS;
2296}
2297
2298void video_clear(void)
2299{
Duncan Laurie33778ea2012-11-03 11:41:40 +00002300 if (!video_fb_address)
2301 return;
Stefan Reinauer7870da32012-09-28 15:11:12 +00002302#ifdef VIDEO_HW_RECTFILL
2303 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2304 0, /* dest pos x */
2305 0, /* dest pos y */
2306 VIDEO_VISIBLE_COLS, /* frame width */
2307 VIDEO_VISIBLE_ROWS, /* frame height */
2308 bgx /* fill color */
2309 );
2310#else
2311 memsetl(video_fb_address,
2312 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2313#endif
2314}