blob: a81affa3333f743ed6e56e8758a6fab98addf003 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8/*
9 * cfb_console.c
10 *
11 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
12 *
13 * At the moment only the 8x16 font is tested and the font fore- and
14 * background color is limited to black/white/gray colors. The Linux
15 * logo can be placed in the upper left corner and additional board
Wolfgang Denk64e40d72011-07-29 09:55:27 +000016 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000017 *
18 * The console driver can use the standard PC keyboard interface (i8042)
19 * for character input. Character output goes to a memory mapped video
20 * framebuffer with little or big-endian organisation.
21 * With environment setting 'console=serial' the console i/o can be
22 * forced to serial port.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000023 *
24 * The driver uses graphic specific defines/parameters/functions:
25 *
26 * (for SMI LynxE graphic chip)
27 *
28 * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
29 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
30 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
31 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
32 *
33 * Console Parameters are set by graphic drivers global struct:
34 *
35 * VIDEO_VISIBLE_COLS - x resolution
36 * VIDEO_VISIBLE_ROWS - y resolution
37 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
38 * VIDEO_DATA_FORMAT - graphical data format GDF
39 * VIDEO_FB_ADRS - start of video memory
40 *
41 * CONFIG_I8042_KBD - AT Keyboard driver for i8042
42 * VIDEO_KBD_INIT_FCT - init function for keyboard
43 * VIDEO_TSTC_FCT - keyboard_tstc function
44 * VIDEO_GETC_FCT - keyboard_getc function
45 *
46 * CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with
47 * delay loop in VIDEO_TSTC_FCT (i8042)
48 *
49 * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
50 * CONFIG_CONSOLE_TIME - display time/date in upper right
51 * corner, needs CONFIG_CMD_DATE and
52 * CONFIG_CONSOLE_CURSOR
Bastian Ruppert1e681f92012-09-13 22:29:01 +000053 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
54 * Use CONFIG_SPLASH_SCREEN_ALIGN with
55 * environment variable "splashpos" to place
56 * the logo on other position. In this case
57 * no CONSOLE_EXTRA_INFO is possible.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000058 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
59 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
60 * strings that normaly goes to serial
61 * port. This define requires a board
62 * specific function:
63 * video_drawstring (VIDEO_INFO_X,
64 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
65 * info);
66 * that fills a info buffer at i=row.
67 * s.a: board/eltec/bab7xx.
68 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
69 * initialized as an output only device.
70 * The Keyboard driver will not be
71 * set-up. This may be used, if you have
72 * no or more than one Keyboard devices
73 * (USB Keyboard, AT Keyboard).
74 *
75 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
76 * character. No blinking is provided.
77 * Uses the macros CURSOR_SET and
78 * CURSOR_OFF.
79 *
80 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
81 * of the graphic chip. Uses the macro
82 * CURSOR_SET. ATTENTION: If booting an
83 * OS, the display driver must disable
84 * the hardware register of the graphic
85 * chip. Otherwise a blinking field is
86 * displayed.
87 */
wdenkc6097192002-11-03 00:24:07 +000088
89#include <common.h>
Andreas Bießmann09c2e902011-07-18 20:24:04 +020090#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +000091#include <malloc.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +000092#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +000093
Wolfgang Denk64e40d72011-07-29 09:55:27 +000094/*
95 * Console device defines with SMI graphic
96 * Any other graphic must change this section
97 */
wdenkc6097192002-11-03 00:24:07 +000098
wdenk4b248f32004-03-14 16:51:43 +000099#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000100
101#define VIDEO_FB_LITTLE_ENDIAN
102#define VIDEO_HW_RECTFILL
103#define VIDEO_HW_BITBLT
104#endif
105
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000106/*
107 * Defines for the CT69000 driver
108 */
wdenk4b248f32004-03-14 16:51:43 +0000109#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000110
111#define VIDEO_FB_LITTLE_ENDIAN
112#define VIDEO_HW_RECTFILL
113#define VIDEO_HW_BITBLT
114#endif
115
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000116/*
117 * Defines for the SED13806 driver
118 */
wdenka6c7ad22002-12-03 21:28:10 +0000119#ifdef CONFIG_VIDEO_SED13806
wdenka6c7ad22002-12-03 21:28:10 +0000120#define VIDEO_FB_LITTLE_ENDIAN
121#define VIDEO_HW_RECTFILL
122#define VIDEO_HW_BITBLT
123#endif
124
Marek Vasutfb8ddc22013-04-28 09:20:03 +0000125#ifdef CONFIG_VIDEO_MXS
126#define VIDEO_FB_16BPP_WORD_SWAP
127#endif
128
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000129/*
130 * Defines for the MB862xx driver
131 */
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100132#ifdef CONFIG_VIDEO_MB862xx
133
134#ifdef CONFIG_VIDEO_CORALP
135#define VIDEO_FB_LITTLE_ENDIAN
136#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200137#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100138#define VIDEO_HW_RECTFILL
139#define VIDEO_HW_BITBLT
140#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200141#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100142
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000143/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000144 * Defines for the i.MX31 driver (mx3fb.c)
145 */
Fabio Estevam695af9a2012-05-31 07:23:56 +0000146#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000147#define VIDEO_FB_16BPP_WORD_SWAP
148#endif
149
150/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000151 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
152 */
wdenkc6097192002-11-03 00:24:07 +0000153#include <video_fb.h>
154
Robert Winklerdd4425e2013-06-17 11:31:29 -0700155#include <splash.h>
156
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000157/*
158 * some Macros
159 */
wdenk4b248f32004-03-14 16:51:43 +0000160#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
161#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
162#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
163#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
164#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000165
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000166/*
167 * Console device defines with i8042 keyboard controller
168 * Any other keyboard controller must change this section
169 */
wdenkc6097192002-11-03 00:24:07 +0000170
wdenk4b248f32004-03-14 16:51:43 +0000171#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000172#include <i8042.h>
173
wdenk4b248f32004-03-14 16:51:43 +0000174#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
175#define VIDEO_TSTC_FCT i8042_tstc
176#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000177#endif
178
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000179/*
180 * Console device
181 */
wdenkc6097192002-11-03 00:24:07 +0000182
183#include <version.h>
184#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200185#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000186#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000187
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500188#if defined(CONFIG_CMD_DATE)
189#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000190#endif
191
Jon Loeliger07d38a12007-07-09 17:30:01 -0500192#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000193#include <watchdog.h>
194#include <bmp_layout.h>
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200195#include <splash.h>
Jon Loeliger07d38a12007-07-09 17:30:01 -0500196#endif
wdenk4b248f32004-03-14 16:51:43 +0000197
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000198/*
199 * Cursor definition:
200 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
201 * to let the cursor blink. Uses the macros
202 * CURSOR_OFF and CURSOR_ON.
203 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
204 * blinking is provided. Uses the macros CURSOR_SET
205 * and CURSOR_OFF.
206 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
207 * graphic chip. Uses the macro CURSOR_SET.
208 * ATTENTION: If booting an OS, the display driver
209 * must disable the hardware register of the graphic
210 * chip. Otherwise a blinking field is displayed
211 */
wdenkc6097192002-11-03 00:24:07 +0000212#if !defined(CONFIG_CONSOLE_CURSOR) && \
213 !defined(CONFIG_VIDEO_SW_CURSOR) && \
214 !defined(CONFIG_VIDEO_HW_CURSOR)
215/* no Cursor defined */
216#define CURSOR_ON
217#define CURSOR_OFF
218#define CURSOR_SET
219#endif
220
Gabe Black03d31fc2011-11-30 13:50:50 +0000221#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
222#if defined(CURSOR_ON) || \
223 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000224#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
225 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000226#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000227void console_cursor(int state);
228
Timur Tabi65618632010-08-27 15:45:47 -0500229#define CURSOR_ON console_cursor(1)
230#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000231#define CURSOR_SET video_set_cursor()
232#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
233
234#ifdef CONFIG_CONSOLE_CURSOR
235#ifndef CONFIG_CONSOLE_TIME
236#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
237#endif
wdenkc6097192002-11-03 00:24:07 +0000238#ifndef CONFIG_I8042_KBD
Marcel Ziswiler7817cb22007-12-30 03:30:46 +0100239#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000240#endif
wdenkc6097192002-11-03 00:24:07 +0000241#endif /* CONFIG_CONSOLE_CURSOR */
242
wdenkc6097192002-11-03 00:24:07 +0000243
244#ifdef CONFIG_VIDEO_HW_CURSOR
wdenk4b248f32004-03-14 16:51:43 +0000245#ifdef CURSOR_ON
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000246#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
247 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000248#endif
249#define CURSOR_ON
250#define CURSOR_OFF
251#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabi65618632010-08-27 15:45:47 -0500252 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000253#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000254
wdenk4b248f32004-03-14 16:51:43 +0000255#ifdef CONFIG_VIDEO_LOGO
256#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000257#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000258#include <bmp_logo_data.h>
wdenk4b248f32004-03-14 16:51:43 +0000259#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
260#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
261#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
262#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenka6c7ad22002-12-03 21:28:10 +0000263
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000264#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000265#define LINUX_LOGO_WIDTH 80
266#define LINUX_LOGO_HEIGHT 80
267#define LINUX_LOGO_COLORS 214
268#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000269#define __initdata
270#include <linux_logo.h>
wdenk4b248f32004-03-14 16:51:43 +0000271#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
272#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
273#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
274#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000275#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000276#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
277#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000278#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000279#define VIDEO_LOGO_WIDTH 0
280#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000281#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000282
wdenk4b248f32004-03-14 16:51:43 +0000283#define VIDEO_COLS VIDEO_VISIBLE_COLS
284#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
285#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
286#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
287#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
288#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000289
wdenk4b248f32004-03-14 16:51:43 +0000290#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100291#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000292#else
wdenk4b248f32004-03-14 16:51:43 +0000293#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000294#endif
295
wdenk4b248f32004-03-14 16:51:43 +0000296#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
297#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
298#define CONSOLE_ROW_FIRST (video_console_address)
299#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
300#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
301#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass3c0b6682015-01-01 16:17:57 -0700302
303/* By default we scroll by a single line */
304#ifndef CONFIG_CONSOLE_SCROLL_LINES
305#define CONFIG_CONSOLE_SCROLL_LINES 1
306#endif
wdenkc6097192002-11-03 00:24:07 +0000307
308/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000309#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000310#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
311 ((x) >> 8) \
312 )
313#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
314 (((x) & 0x0000ff00) << 8) | \
315 (((x) & 0x00ff0000) >> 8) | \
316 (((x) & 0xff000000) >> 24) \
317 )
318#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
319 (((x) & 0x0000ff00) >> 8) | \
320 (((x) & 0x00ff0000) << 8) | \
321 (((x) & 0xff000000) >> 8) \
322 )
wdenkc6097192002-11-03 00:24:07 +0000323#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000324#define SWAP16(x) (x)
325#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200326#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000327#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500328#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000329#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100330#endif
wdenkc6097192002-11-03 00:24:07 +0000331#endif
332
wdenkc6097192002-11-03 00:24:07 +0000333#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000334/*
335 * setup a board string: type, speed, etc.
336 *
337 * line_number: location to place info string beside logo
338 * info: buffer for info string
339 */
340extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000341#endif
342
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200343DECLARE_GLOBAL_DATA_PTR;
344
wdenkc6097192002-11-03 00:24:07 +0000345/* Locals */
346static GraphicDevice *pGD; /* Pointer to Graphic array */
347
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000348static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000349static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000350
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100351static int video_logo_height = VIDEO_LOGO_HEIGHT;
352
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000353static int __maybe_unused cursor_state;
354static int __maybe_unused old_col;
355static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000356
Wolfgang Denk57912932011-07-30 12:48:09 +0000357static int console_col; /* cursor col */
358static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000359
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000360static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000361
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200362static int cfb_do_flush_cache;
363
Pali Rohár33a35bb2012-10-19 13:30:09 +0000364#ifdef CONFIG_CFB_CONSOLE_ANSI
365static char ansi_buf[10];
366static int ansi_buf_size;
367static int ansi_colors_need_revert;
368static int ansi_cursor_hidden;
369#endif
370
wdenkc6097192002-11-03 00:24:07 +0000371static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000372 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
373 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
374 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
375 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
376};
wdenkc6097192002-11-03 00:24:07 +0000377
378static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000379 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
380};
wdenkc6097192002-11-03 00:24:07 +0000381
382static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000383 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
384};
wdenkc6097192002-11-03 00:24:07 +0000385
386static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000387 {0x00000000, 0x00000000, 0x00000000},
388 {0x00000000, 0x00000000, 0x00ffffff},
389 {0x00000000, 0x0000ffff, 0xff000000},
390 {0x00000000, 0x0000ffff, 0xffffffff},
391 {0x000000ff, 0xffff0000, 0x00000000},
392 {0x000000ff, 0xffff0000, 0x00ffffff},
393 {0x000000ff, 0xffffffff, 0xff000000},
394 {0x000000ff, 0xffffffff, 0xffffffff},
395 {0xffffff00, 0x00000000, 0x00000000},
396 {0xffffff00, 0x00000000, 0x00ffffff},
397 {0xffffff00, 0x0000ffff, 0xff000000},
398 {0xffffff00, 0x0000ffff, 0xffffffff},
399 {0xffffffff, 0xffff0000, 0x00000000},
400 {0xffffffff, 0xffff0000, 0x00ffffff},
401 {0xffffffff, 0xffffffff, 0xff000000},
402 {0xffffffff, 0xffffffff, 0xffffffff}
403};
wdenkc6097192002-11-03 00:24:07 +0000404
405static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000406 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
407 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
408 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
409 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
410 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
411 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
412 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
413 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
414 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
415 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
416 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
417 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
418 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
419 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
420 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
421 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
422};
wdenkc6097192002-11-03 00:24:07 +0000423
Heiko Schocher2bc4aa52013-08-03 07:22:53 +0200424/*
425 * Implement a weak default function for boards that optionally
426 * need to skip the cfb initialization.
427 */
428__weak int board_cfb_skip(void)
429{
430 /* As default, don't skip cfb init */
431 return 0;
432}
433
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000434static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000435{
wdenk4b248f32004-03-14 16:51:43 +0000436 u8 *cdat, *dest, *dest0;
437 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000438
wdenk4b248f32004-03-14 16:51:43 +0000439 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
440 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000441
wdenk4b248f32004-03-14 16:51:43 +0000442 switch (VIDEO_DATA_FORMAT) {
443 case GDF__8BIT_INDEX:
444 case GDF__8BIT_332RGB:
445 while (count--) {
446 c = *s;
447 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
448 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000449 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000450 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000451
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000452 ((u32 *) dest)[0] =
453 (video_font_draw_table8[bits >> 4] &
454 eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200455
456 if (VIDEO_FONT_WIDTH == 4)
457 continue;
458
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000459 ((u32 *) dest)[1] =
460 (video_font_draw_table8[bits & 15] &
461 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000462 }
463 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
464 s++;
465 }
466 break;
wdenkc6097192002-11-03 00:24:07 +0000467
wdenk4b248f32004-03-14 16:51:43 +0000468 case GDF_15BIT_555RGB:
469 while (count--) {
470 c = *s;
471 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
472 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000473 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000474 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000475
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000476 ((u32 *) dest)[0] =
477 SHORTSWAP32((video_font_draw_table15
478 [bits >> 6] & eorx) ^
479 bgx);
480 ((u32 *) dest)[1] =
481 SHORTSWAP32((video_font_draw_table15
482 [bits >> 4 & 3] & eorx) ^
483 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200484
485 if (VIDEO_FONT_WIDTH == 4)
486 continue;
487
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000488 ((u32 *) dest)[2] =
489 SHORTSWAP32((video_font_draw_table15
490 [bits >> 2 & 3] & eorx) ^
491 bgx);
492 ((u32 *) dest)[3] =
493 SHORTSWAP32((video_font_draw_table15
494 [bits & 3] & eorx) ^
495 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000496 }
497 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
498 s++;
499 }
500 break;
wdenkc6097192002-11-03 00:24:07 +0000501
wdenk4b248f32004-03-14 16:51:43 +0000502 case GDF_16BIT_565RGB:
503 while (count--) {
504 c = *s;
505 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
506 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000507 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000508 u8 bits = *cdat++;
509
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000510 ((u32 *) dest)[0] =
511 SHORTSWAP32((video_font_draw_table16
512 [bits >> 6] & eorx) ^
513 bgx);
514 ((u32 *) dest)[1] =
515 SHORTSWAP32((video_font_draw_table16
516 [bits >> 4 & 3] & eorx) ^
517 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200518
519 if (VIDEO_FONT_WIDTH == 4)
520 continue;
521
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000522 ((u32 *) dest)[2] =
523 SHORTSWAP32((video_font_draw_table16
524 [bits >> 2 & 3] & eorx) ^
525 bgx);
526 ((u32 *) dest)[3] =
527 SHORTSWAP32((video_font_draw_table16
528 [bits & 3] & eorx) ^
529 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000530 }
531 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
532 s++;
533 }
534 break;
535
536 case GDF_32BIT_X888RGB:
537 while (count--) {
538 c = *s;
539 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
540 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000541 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000542 u8 bits = *cdat++;
543
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000544 ((u32 *) dest)[0] =
545 SWAP32((video_font_draw_table32
546 [bits >> 4][0] & eorx) ^ bgx);
547 ((u32 *) dest)[1] =
548 SWAP32((video_font_draw_table32
549 [bits >> 4][1] & eorx) ^ bgx);
550 ((u32 *) dest)[2] =
551 SWAP32((video_font_draw_table32
552 [bits >> 4][2] & eorx) ^ bgx);
553 ((u32 *) dest)[3] =
554 SWAP32((video_font_draw_table32
555 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200556
557
558 if (VIDEO_FONT_WIDTH == 4)
559 continue;
560
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000561 ((u32 *) dest)[4] =
562 SWAP32((video_font_draw_table32
563 [bits & 15][0] & eorx) ^ bgx);
564 ((u32 *) dest)[5] =
565 SWAP32((video_font_draw_table32
566 [bits & 15][1] & eorx) ^ bgx);
567 ((u32 *) dest)[6] =
568 SWAP32((video_font_draw_table32
569 [bits & 15][2] & eorx) ^ bgx);
570 ((u32 *) dest)[7] =
571 SWAP32((video_font_draw_table32
572 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000573 }
574 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
575 s++;
576 }
577 break;
578
579 case GDF_24BIT_888RGB:
580 while (count--) {
581 c = *s;
582 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
583 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000584 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000585 u8 bits = *cdat++;
586
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000587 ((u32 *) dest)[0] =
588 (video_font_draw_table24[bits >> 4][0]
589 & eorx) ^ bgx;
590 ((u32 *) dest)[1] =
591 (video_font_draw_table24[bits >> 4][1]
592 & eorx) ^ bgx;
593 ((u32 *) dest)[2] =
594 (video_font_draw_table24[bits >> 4][2]
595 & eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200596
597 if (VIDEO_FONT_WIDTH == 4)
598 continue;
599
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000600 ((u32 *) dest)[3] =
601 (video_font_draw_table24[bits & 15][0]
602 & eorx) ^ bgx;
603 ((u32 *) dest)[4] =
604 (video_font_draw_table24[bits & 15][1]
605 & eorx) ^ bgx;
606 ((u32 *) dest)[5] =
607 (video_font_draw_table24[bits & 15][2]
608 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000609 }
610 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
611 s++;
612 }
613 break;
wdenk8bde7f72003-06-27 21:31:46 +0000614 }
wdenkc6097192002-11-03 00:24:07 +0000615}
616
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000617static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000618{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000619 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000620}
621
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000622static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000623{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000624 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000625}
626
wdenkc6097192002-11-03 00:24:07 +0000627#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000628static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000629{
Gabe Black03d31fc2011-11-30 13:50:50 +0000630 if (cursor_state)
631 console_cursor(0);
632 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000633}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000634
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000635static void video_invertchar(int xx, int yy)
636{
637 int firstx = xx * VIDEO_PIXEL_SIZE;
638 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
639 int firsty = yy * VIDEO_LINE_LEN;
640 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
641 int x, y;
642 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
643 for (x = firstx; x < lastx; x++) {
644 u8 *dest = (u8 *)(video_fb_address) + x + y;
645 *dest = ~*dest;
646 }
647 }
648}
Gabe Black03d31fc2011-11-30 13:50:50 +0000649
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000650void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000651{
wdenkc6097192002-11-03 00:24:07 +0000652#ifdef CONFIG_CONSOLE_TIME
wdenk4b248f32004-03-14 16:51:43 +0000653 struct rtc_time tm;
654 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000655
wdenk4b248f32004-03-14 16:51:43 +0000656 /* time update only if cursor is on (faster scroll) */
657 if (state) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000658 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000659
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000660 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
661 tm.tm_sec);
662 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
663 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000664
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000665 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
666 tm.tm_year);
667 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
668 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
669 (uchar *) info);
wdenk4b248f32004-03-14 16:51:43 +0000670 }
wdenkc6097192002-11-03 00:24:07 +0000671#endif
672
Gabe Black03d31fc2011-11-30 13:50:50 +0000673 if (cursor_state != state) {
674 if (cursor_state) {
675 /* turn off the cursor */
676 video_invertchar(old_col * VIDEO_FONT_WIDTH,
677 old_row * VIDEO_FONT_HEIGHT +
678 video_logo_height);
679 } else {
680 /* turn off the cursor and record where it is */
681 video_invertchar(console_col * VIDEO_FONT_WIDTH,
682 console_row * VIDEO_FONT_HEIGHT +
683 video_logo_height);
684 old_col = console_col;
685 old_row = console_row;
686 }
687 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000688 }
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200689 if (cfb_do_flush_cache)
690 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000691}
692#endif
693
wdenkc6097192002-11-03 00:24:07 +0000694#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000695static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000696{
wdenk4b248f32004-03-14 16:51:43 +0000697 while (c--)
698 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000699}
700#endif
701
wdenkc6097192002-11-03 00:24:07 +0000702#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000703static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000704{
wdenk4b248f32004-03-14 16:51:43 +0000705 while (c--)
706 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000707}
708#endif
709
Pali Rohár90f60a82012-04-28 07:26:44 +0000710static void console_clear_line(int line, int begin, int end)
711{
712#ifdef VIDEO_HW_RECTFILL
713 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
714 VIDEO_FONT_WIDTH * begin, /* dest pos x */
715 video_logo_height +
716 VIDEO_FONT_HEIGHT * line, /* dest pos y */
717 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
718 VIDEO_FONT_HEIGHT, /* frame height */
719 bgx /* fill color */
720 );
721#else
722 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
723 memsetl(CONSOLE_ROW_FIRST +
724 CONSOLE_ROW_SIZE * line, /* offset of row */
725 CONSOLE_ROW_SIZE >> 2, /* length of row */
726 bgx /* fill color */
727 );
728 } else {
729 void *offset;
730 int i, size;
731
732 offset = CONSOLE_ROW_FIRST +
733 CONSOLE_ROW_SIZE * line + /* offset of row */
734 VIDEO_FONT_WIDTH *
735 VIDEO_PIXEL_SIZE * begin; /* offset of col */
736 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
737 size >>= 2; /* length to end for memsetl() */
738 /* fill at col offset of i'th line using bgx as fill color */
739 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
740 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
741 }
742#endif
743}
744
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000745static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000746{
Simon Glass3c0b6682015-01-01 16:17:57 -0700747 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
748 int i;
749
wdenk4b248f32004-03-14 16:51:43 +0000750 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000751
752#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000753 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
754 0, /* source pos x */
755 video_logo_height +
Simon Glass3c0b6682015-01-01 16:17:57 -0700756 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000757 0, /* dest pos x */
758 video_logo_height, /* dest pos y */
759 VIDEO_VISIBLE_COLS, /* frame width */
760 VIDEO_VISIBLE_ROWS
761 - video_logo_height
Simon Glass3c0b6682015-01-01 16:17:57 -0700762 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000763 );
wdenkc6097192002-11-03 00:24:07 +0000764#else
Simon Glass3c0b6682015-01-01 16:17:57 -0700765 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
766 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000767#endif
wdenk4b248f32004-03-14 16:51:43 +0000768 /* clear the last one */
Simon Glass3c0b6682015-01-01 16:17:57 -0700769 for (i = 1; i <= rows; i++)
770 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
771
772 /* Decrement row number */
773 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000774}
775
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000776static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000777{
Timur Tabi65618632010-08-27 15:45:47 -0500778 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000779
wdenk4b248f32004-03-14 16:51:43 +0000780 if (console_col < 0) {
781 console_col = CONSOLE_COLS - 1;
782 console_row--;
783 if (console_row < 0)
784 console_row = 0;
785 }
wdenkc6097192002-11-03 00:24:07 +0000786}
787
Pali Rohár33a35bb2012-10-19 13:30:09 +0000788#ifdef CONFIG_CFB_CONSOLE_ANSI
789
790static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000791{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000792#ifdef VIDEO_HW_RECTFILL
793 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
794 0, /* dest pos x */
795 video_logo_height, /* dest pos y */
796 VIDEO_VISIBLE_COLS, /* frame width */
797 VIDEO_VISIBLE_ROWS, /* frame height */
798 bgx /* fill color */
799 );
800#else
801 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
802#endif
803}
804
805static void console_cursor_fix(void)
806{
807 if (console_row < 0)
808 console_row = 0;
809 if (console_row >= CONSOLE_ROWS)
810 console_row = CONSOLE_ROWS - 1;
811 if (console_col < 0)
812 console_col = 0;
813 if (console_col >= CONSOLE_COLS)
814 console_col = CONSOLE_COLS - 1;
815}
816
817static void console_cursor_up(int n)
818{
819 console_row -= n;
820 console_cursor_fix();
821}
822
823static void console_cursor_down(int n)
824{
825 console_row += n;
826 console_cursor_fix();
827}
828
829static void console_cursor_left(int n)
830{
831 console_col -= n;
832 console_cursor_fix();
833}
834
835static void console_cursor_right(int n)
836{
837 console_col += n;
838 console_cursor_fix();
839}
840
841static void console_cursor_set_position(int row, int col)
842{
843 if (console_row != -1)
844 console_row = row;
845 if (console_col != -1)
846 console_col = col;
847 console_cursor_fix();
848}
849
850static void console_previousline(int n)
851{
852 /* FIXME: also scroll terminal ? */
853 console_row -= n;
854 console_cursor_fix();
855}
856
857static void console_swap_colors(void)
858{
859 eorx = fgx;
860 fgx = bgx;
861 bgx = eorx;
862 eorx = fgx ^ bgx;
863}
864
865static inline int console_cursor_is_visible(void)
866{
867 return !ansi_cursor_hidden;
868}
869#else
870static inline int console_cursor_is_visible(void)
871{
872 return 1;
873}
874#endif
875
876static void console_newline(int n)
877{
878 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000879 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000880
wdenk4b248f32004-03-14 16:51:43 +0000881 /* Check if we need to scroll the terminal */
882 if (console_row >= CONSOLE_ROWS) {
883 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000884 console_scrollup();
wdenk4b248f32004-03-14 16:51:43 +0000885 }
wdenkc6097192002-11-03 00:24:07 +0000886}
887
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000888static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100889{
Timur Tabi65618632010-08-27 15:45:47 -0500890 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100891}
892
Pali Rohár33a35bb2012-10-19 13:30:09 +0000893static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000894{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100895 static int nl = 1;
896
Pali Rohár33a35bb2012-10-19 13:30:09 +0000897 if (console_cursor_is_visible())
898 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000899
wdenk4b248f32004-03-14 16:51:43 +0000900 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100901 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000902 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000903 break;
wdenkc6097192002-11-03 00:24:07 +0000904
wdenk4b248f32004-03-14 16:51:43 +0000905 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100906 if (console_col || (!console_col && nl))
Pali Rohár33a35bb2012-10-19 13:30:09 +0000907 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100908 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000909 break;
wdenkc6097192002-11-03 00:24:07 +0000910
wdenk4b248f32004-03-14 16:51:43 +0000911 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500912 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000913 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000914
wdenk4b248f32004-03-14 16:51:43 +0000915 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000916 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000917 break;
wdenkc6097192002-11-03 00:24:07 +0000918
wdenk4b248f32004-03-14 16:51:43 +0000919 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000920 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000921 break;
wdenkc6097192002-11-03 00:24:07 +0000922
Pali Rohár24fe06c2012-04-28 07:26:47 +0000923 case 7: /* bell */
924 break; /* ignored */
925
wdenk4b248f32004-03-14 16:51:43 +0000926 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000927 video_putchar(console_col * VIDEO_FONT_WIDTH,
928 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000929 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000930
wdenk4b248f32004-03-14 16:51:43 +0000931 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100932 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000933 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100934 nl = 0;
935 }
wdenk4b248f32004-03-14 16:51:43 +0000936 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000937
938 if (console_cursor_is_visible())
939 CURSOR_SET;
940}
941
Jeroen Hofstee654f8d02014-10-08 22:57:44 +0200942static void video_putc(struct stdio_dev *dev, const char c)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000943{
944#ifdef CONFIG_CFB_CONSOLE_ANSI
945 int i;
946
947 if (c == 27) {
948 for (i = 0; i < ansi_buf_size; ++i)
949 parse_putc(ansi_buf[i]);
950 ansi_buf[0] = 27;
951 ansi_buf_size = 1;
952 return;
953 }
954
955 if (ansi_buf_size > 0) {
956 /*
957 * 0 - ESC
958 * 1 - [
959 * 2 - num1
960 * 3 - ..
961 * 4 - ;
962 * 5 - num2
963 * 6 - ..
964 * - cchar
965 */
966 int next = 0;
967
968 int flush = 0;
969 int fail = 0;
970
971 int num1 = 0;
972 int num2 = 0;
973 int cchar = 0;
974
975 ansi_buf[ansi_buf_size++] = c;
976
977 if (ansi_buf_size >= sizeof(ansi_buf))
978 fail = 1;
979
980 for (i = 0; i < ansi_buf_size; ++i) {
981 if (fail)
982 break;
983
984 switch (next) {
985 case 0:
986 if (ansi_buf[i] == 27)
987 next = 1;
988 else
989 fail = 1;
990 break;
991
992 case 1:
993 if (ansi_buf[i] == '[')
994 next = 2;
995 else
996 fail = 1;
997 break;
998
999 case 2:
1000 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1001 num1 = ansi_buf[i]-'0';
1002 next = 3;
1003 } else if (ansi_buf[i] != '?') {
1004 --i;
1005 num1 = 1;
1006 next = 4;
1007 }
1008 break;
1009
1010 case 3:
1011 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1012 num1 *= 10;
1013 num1 += ansi_buf[i]-'0';
1014 } else {
1015 --i;
1016 next = 4;
1017 }
1018 break;
1019
1020 case 4:
1021 if (ansi_buf[i] != ';') {
1022 --i;
1023 next = 7;
1024 } else
1025 next = 5;
1026 break;
1027
1028 case 5:
1029 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1030 num2 = ansi_buf[i]-'0';
1031 next = 6;
1032 } else
1033 fail = 1;
1034 break;
1035
1036 case 6:
1037 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1038 num2 *= 10;
1039 num2 += ansi_buf[i]-'0';
1040 } else {
1041 --i;
1042 next = 7;
1043 }
1044 break;
1045
1046 case 7:
1047 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1048 || ansi_buf[i] == 'J'
1049 || ansi_buf[i] == 'K'
1050 || ansi_buf[i] == 'h'
1051 || ansi_buf[i] == 'l'
1052 || ansi_buf[i] == 'm') {
1053 cchar = ansi_buf[i];
1054 flush = 1;
1055 } else
1056 fail = 1;
1057 break;
1058 }
1059 }
1060
1061 if (fail) {
1062 for (i = 0; i < ansi_buf_size; ++i)
1063 parse_putc(ansi_buf[i]);
1064 ansi_buf_size = 0;
1065 return;
1066 }
1067
1068 if (flush) {
1069 if (!ansi_cursor_hidden)
1070 CURSOR_OFF;
1071 ansi_buf_size = 0;
1072 switch (cchar) {
1073 case 'A':
1074 /* move cursor num1 rows up */
1075 console_cursor_up(num1);
1076 break;
1077 case 'B':
1078 /* move cursor num1 rows down */
1079 console_cursor_down(num1);
1080 break;
1081 case 'C':
1082 /* move cursor num1 columns forward */
1083 console_cursor_right(num1);
1084 break;
1085 case 'D':
1086 /* move cursor num1 columns back */
1087 console_cursor_left(num1);
1088 break;
1089 case 'E':
1090 /* move cursor num1 rows up at begin of row */
1091 console_previousline(num1);
1092 break;
1093 case 'F':
1094 /* move cursor num1 rows down at begin of row */
1095 console_newline(num1);
1096 break;
1097 case 'G':
1098 /* move cursor to column num1 */
1099 console_cursor_set_position(-1, num1-1);
1100 break;
1101 case 'H':
1102 /* move cursor to row num1, column num2 */
1103 console_cursor_set_position(num1-1, num2-1);
1104 break;
1105 case 'J':
1106 /* clear console and move cursor to 0, 0 */
1107 console_clear();
1108 console_cursor_set_position(0, 0);
1109 break;
1110 case 'K':
1111 /* clear line */
1112 if (num1 == 0)
1113 console_clear_line(console_row,
1114 console_col,
1115 CONSOLE_COLS-1);
1116 else if (num1 == 1)
1117 console_clear_line(console_row,
1118 0, console_col);
1119 else
1120 console_clear_line(console_row,
1121 0, CONSOLE_COLS-1);
1122 break;
1123 case 'h':
1124 ansi_cursor_hidden = 0;
1125 break;
1126 case 'l':
1127 ansi_cursor_hidden = 1;
1128 break;
1129 case 'm':
1130 if (num1 == 0) { /* reset swapped colors */
1131 if (ansi_colors_need_revert) {
1132 console_swap_colors();
1133 ansi_colors_need_revert = 0;
1134 }
1135 } else if (num1 == 7) { /* once swap colors */
1136 if (!ansi_colors_need_revert) {
1137 console_swap_colors();
1138 ansi_colors_need_revert = 1;
1139 }
1140 }
1141 break;
1142 }
1143 if (!ansi_cursor_hidden)
1144 CURSOR_SET;
1145 }
1146 } else {
1147 parse_putc(c);
1148 }
1149#else
1150 parse_putc(c);
1151#endif
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001152 if (cfb_do_flush_cache)
1153 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabi65618632010-08-27 15:45:47 -05001154}
wdenkc6097192002-11-03 00:24:07 +00001155
Jeroen Hofstee654f8d02014-10-08 22:57:44 +02001156static void video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001157{
Soeren Mochd37e96e2014-10-24 16:33:30 +02001158 int flush = cfb_do_flush_cache;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001159 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +00001160
Soeren Mochd37e96e2014-10-24 16:33:30 +02001161 /* temporarily disable cache flush */
1162 cfb_do_flush_cache = 0;
1163
wdenk4b248f32004-03-14 16:51:43 +00001164 while (count--)
Simon Glass709ea542014-07-23 06:54:59 -06001165 video_putc(dev, *s++);
Soeren Mochd37e96e2014-10-24 16:33:30 +02001166
1167 if (flush) {
1168 cfb_do_flush_cache = flush;
1169 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1170 }
wdenkc6097192002-11-03 00:24:07 +00001171}
1172
Anatolij Gustschin10543822010-05-01 22:21:09 +02001173/*
1174 * Do not enforce drivers (or board code) to provide empty
1175 * video_set_lut() if they do not support 8 bpp format.
1176 * Implement weak default function instead.
1177 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02001178__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001179 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +02001180{
1181}
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001182
Jon Loeliger07d38a12007-07-09 17:30:01 -05001183#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +00001184
1185#define FILL_8BIT_332RGB(r,g,b) { \
1186 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1187 fb ++; \
1188}
1189
1190#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001191 *(unsigned short *)fb = \
1192 SWAP16((unsigned short)(((r>>3)<<10) | \
1193 ((g>>3)<<5) | \
1194 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001195 fb += 2; \
1196}
1197
1198#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001199 *(unsigned short *)fb = \
1200 SWAP16((unsigned short)((((r)>>3)<<11)| \
1201 (((g)>>2)<<5) | \
1202 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001203 fb += 2; \
1204}
1205
1206#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001207 *(unsigned long *)fb = \
1208 SWAP32((unsigned long)(((r<<16) | \
1209 (g<<8) | \
1210 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001211 fb += 4; \
1212}
1213
1214#ifdef VIDEO_FB_LITTLE_ENDIAN
1215#define FILL_24BIT_888RGB(r,g,b) { \
1216 fb[0] = b; \
1217 fb[1] = g; \
1218 fb[2] = r; \
1219 fb += 3; \
1220}
1221#else
1222#define FILL_24BIT_888RGB(r,g,b) { \
1223 fb[0] = r; \
1224 fb[1] = g; \
1225 fb[2] = b; \
1226 fb += 3; \
1227}
1228#endif
1229
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001230#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001231static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001232{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001233 ushort *dst = (ushort *) fb;
1234 ushort color = (ushort) (((r >> 3) << 10) |
1235 ((g >> 3) << 5) |
1236 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001237 if (x & 1)
1238 *(--dst) = color;
1239 else
1240 *(++dst) = color;
1241}
1242#endif
wdenk4b248f32004-03-14 16:51:43 +00001243
1244/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001245 * RLE8 bitmap support
1246 */
1247
1248#ifdef CONFIG_VIDEO_BMP_RLE8
1249/* Pre-calculated color table entry */
1250struct palette {
1251 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001252 unsigned short w; /* word */
1253 unsigned int dw; /* double word */
1254 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001255};
1256
1257/*
1258 * Helper to draw encoded/unencoded run.
1259 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001260static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1261 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001262{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001263 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001264 int *off;
1265 int enc_off = 1;
1266 int i;
1267
1268 /*
1269 * Setup offset of the color index in the bitmap.
1270 * Color index of encoded run is at offset 1.
1271 */
1272 off = enc ? &enc_off : &i;
1273
1274 switch (VIDEO_DATA_FORMAT) {
1275 case GDF__8BIT_INDEX:
1276 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001277 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001278 break;
1279 case GDF_15BIT_555RGB:
1280 case GDF_16BIT_565RGB:
1281 /* differences handled while pre-calculating palette */
1282 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001283 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001284 addr += 2;
1285 }
1286 break;
1287 case GDF_32BIT_X888RGB:
1288 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001289 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001290 addr += 4;
1291 }
1292 break;
1293 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001294 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001295}
1296
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001297static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1298 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001299{
1300 unsigned char *bm;
1301 unsigned char *fbp;
1302 unsigned int cnt, runlen;
1303 int decode = 1;
1304 int x, y, bpp, i, ncolors;
1305 struct palette p[256];
1306 bmp_color_table_entry_t cte;
1307 int green_shift, red_off;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001308 int limit = VIDEO_COLS * VIDEO_ROWS;
1309 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001310
1311 x = 0;
1312 y = __le32_to_cpu(img->header.height) - 1;
1313 ncolors = __le32_to_cpu(img->header.colors_used);
1314 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001315 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1316 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001317
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001318 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001319
1320 /* pre-calculate and setup palette */
1321 switch (VIDEO_DATA_FORMAT) {
1322 case GDF__8BIT_INDEX:
1323 for (i = 0; i < ncolors; i++) {
1324 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001325 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001326 }
1327 break;
1328 case GDF_15BIT_555RGB:
1329 case GDF_16BIT_565RGB:
1330 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1331 green_shift = 3;
1332 red_off = 10;
1333 } else {
1334 green_shift = 2;
1335 red_off = 11;
1336 }
1337 for (i = 0; i < ncolors; i++) {
1338 cte = img->color_table[i];
1339 p[i].ce.w = SWAP16((unsigned short)
1340 (((cte.red >> 3) << red_off) |
1341 ((cte.green >> green_shift) << 5) |
1342 cte.blue >> 3));
1343 }
1344 break;
1345 case GDF_32BIT_X888RGB:
1346 for (i = 0; i < ncolors; i++) {
1347 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001348 p[i].ce.dw = SWAP32((cte.red << 16) |
1349 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001350 cte.blue);
1351 }
1352 break;
1353 default:
1354 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001355 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001356 return -1;
1357 }
1358
1359 while (decode) {
1360 switch (bm[0]) {
1361 case 0:
1362 switch (bm[1]) {
1363 case 0:
1364 /* scan line end marker */
1365 bm += 2;
1366 x = 0;
1367 y--;
1368 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001369 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001370 (((y + yoff) * VIDEO_COLS) +
1371 xoff) * bpp);
1372 continue;
1373 case 1:
1374 /* end of bitmap data marker */
1375 decode = 0;
1376 break;
1377 case 2:
1378 /* run offset marker */
1379 x += bm[2];
1380 y -= bm[3];
1381 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001382 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001383 (((y + yoff) * VIDEO_COLS) +
1384 x + xoff) * bpp);
1385 bm += 4;
1386 break;
1387 default:
1388 /* unencoded run */
1389 cnt = bm[1];
1390 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001391 pixels += cnt;
1392 if (pixels > limit)
1393 goto error;
1394
Anatolij Gustschind5011762010-03-15 14:50:25 +01001395 bm += 2;
1396 if (y < height) {
1397 if (x >= width) {
1398 x += runlen;
1399 goto next_run;
1400 }
1401 if (x + runlen > width)
1402 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001403 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001404 x += runlen;
1405 }
1406next_run:
1407 bm += runlen;
1408 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001409 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001410 }
1411 break;
1412 default:
1413 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001414 cnt = bm[0];
1415 runlen = cnt;
1416 pixels += cnt;
1417 if (pixels > limit)
1418 goto error;
1419
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001420 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001421 if (x >= width) {
1422 x += runlen;
1423 bm += 2;
1424 continue;
1425 }
1426 if (x + runlen > width)
1427 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001428 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001429 x += runlen;
1430 }
1431 bm += 2;
1432 break;
1433 }
1434 }
1435 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001436error:
1437 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1438 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001439}
1440#endif
1441
1442/*
wdenk4b248f32004-03-14 16:51:43 +00001443 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001444 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001445int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001446{
1447 ushort xcount, ycount;
1448 uchar *fb;
1449 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1450 uchar *bmap;
1451 ushort padded_line;
1452 unsigned long width, height, bpp;
1453 unsigned colors;
1454 unsigned long compression;
1455 bmp_color_table_entry_t cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001456
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001457#ifdef CONFIG_VIDEO_BMP_GZIP
1458 unsigned char *dst = NULL;
1459 ulong len;
1460#endif
wdenk4b248f32004-03-14 16:51:43 +00001461
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001462 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001463
1464 if (!((bmp->header.signature[0] == 'B') &&
1465 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001466
1467#ifdef CONFIG_VIDEO_BMP_GZIP
1468 /*
1469 * Could be a gzipped bmp image, try to decrompress...
1470 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001471 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1472 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001473 if (dst == NULL) {
1474 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001475 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001476 }
Eric Nelson5ca05c82014-03-08 07:55:52 -07001477 /*
1478 * NB: we need to force offset of +2
1479 * See doc/README.displaying-bmps
1480 */
1481 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001482 (uchar *) bmp_image,
1483 &len) != 0) {
1484 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1485 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001486 free(dst);
1487 return 1;
1488 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001489 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001490 printf("Image could be truncated "
1491 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001492 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001493
1494 /*
1495 * Set addr to decompressed image
1496 */
Eric Nelson5ca05c82014-03-08 07:55:52 -07001497 bmp = (bmp_image_t *)(dst+2);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001498
1499 if (!((bmp->header.signature[0] == 'B') &&
1500 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001501 printf("Error: no valid bmp.gz image at %lx\n",
1502 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001503 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001504 return 1;
1505 }
1506#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001507 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001508 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001509#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001510 }
1511
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001512 width = le32_to_cpu(bmp->header.width);
1513 height = le32_to_cpu(bmp->header.height);
1514 bpp = le16_to_cpu(bmp->header.bit_count);
1515 colors = le32_to_cpu(bmp->header.colors_used);
1516 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001517
Marek Vasut68da5b12011-10-21 14:17:04 +00001518 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001519 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001520
Anatolij Gustschind5011762010-03-15 14:50:25 +01001521 if (compression != BMP_BI_RGB
1522#ifdef CONFIG_VIDEO_BMP_RLE8
1523 && compression != BMP_BI_RLE8
1524#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001525 ) {
1526 printf("Error: compression type %ld not supported\n",
1527 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001528#ifdef CONFIG_VIDEO_BMP_GZIP
1529 if (dst)
1530 free(dst);
1531#endif
wdenk4b248f32004-03-14 16:51:43 +00001532 return 1;
1533 }
1534
1535 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1536
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001537#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1538 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001539 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001540 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001541 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001542
1543 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001544 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001545 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001546 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001547#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1548
Matthias Weisseracf3baa2013-02-15 03:35:12 +00001549 /*
1550 * Just ignore elements which are completely beyond screen
1551 * dimensions.
1552 */
1553 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1554 return 0;
1555
wdenk4b248f32004-03-14 16:51:43 +00001556 if ((x + width) > VIDEO_VISIBLE_COLS)
1557 width = VIDEO_VISIBLE_COLS - x;
1558 if ((y + height) > VIDEO_VISIBLE_ROWS)
1559 height = VIDEO_VISIBLE_ROWS - y;
1560
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001561 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001562 fb = (uchar *) (video_fb_address +
1563 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1564 x * VIDEO_PIXEL_SIZE);
1565
Anatolij Gustschind5011762010-03-15 14:50:25 +01001566#ifdef CONFIG_VIDEO_BMP_RLE8
1567 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001568 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001569 }
1570#endif
1571
Timur Tabi68f66182010-08-23 16:58:00 -05001572 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001573 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001574 case 4:
1575 padded_line -= width / 2;
1576 ycount = height;
1577
1578 switch (VIDEO_DATA_FORMAT) {
1579 case GDF_32BIT_X888RGB:
1580 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001581 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001582 /*
1583 * Don't assume that 'width' is an
1584 * even number
1585 */
1586 for (xcount = 0; xcount < width; xcount++) {
1587 uchar idx;
1588
1589 if (xcount & 1) {
1590 idx = *bmap & 0xF;
1591 bmap++;
1592 } else
1593 idx = *bmap >> 4;
1594 cte = bmp->color_table[idx];
1595 FILL_32BIT_X888RGB(cte.red, cte.green,
1596 cte.blue);
1597 }
1598 bmap += padded_line;
1599 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001600 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001601 }
1602 break;
1603 default:
1604 puts("4bpp bitmap unsupported with current "
1605 "video mode\n");
1606 break;
1607 }
1608 break;
1609
wdenk4b248f32004-03-14 16:51:43 +00001610 case 8:
1611 padded_line -= width;
1612 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001613 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001614 for (xcount = 0; xcount < colors; ++xcount) {
1615 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001616 video_set_lut(xcount, cte.red, cte.green,
1617 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001618 }
1619 }
1620 ycount = height;
1621 switch (VIDEO_DATA_FORMAT) {
1622 case GDF__8BIT_INDEX:
1623 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001624 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001625 xcount = width;
1626 while (xcount--) {
1627 *fb++ = *bmap++;
1628 }
1629 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001630 fb -= (VIDEO_VISIBLE_COLS + width) *
1631 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001632 }
1633 break;
1634 case GDF__8BIT_332RGB:
1635 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001636 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001637 xcount = width;
1638 while (xcount--) {
1639 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001640 FILL_8BIT_332RGB(cte.red, cte.green,
1641 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001642 }
1643 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001644 fb -= (VIDEO_VISIBLE_COLS + width) *
1645 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001646 }
1647 break;
1648 case GDF_15BIT_555RGB:
1649 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001650#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1651 int xpos = x;
1652#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001653 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001654 xcount = width;
1655 while (xcount--) {
1656 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001657#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001658 fill_555rgb_pswap(fb, xpos++, cte.red,
1659 cte.green,
1660 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001661 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001662#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001663 FILL_15BIT_555RGB(cte.red, cte.green,
1664 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001665#endif
wdenk4b248f32004-03-14 16:51:43 +00001666 }
1667 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001668 fb -= (VIDEO_VISIBLE_COLS + width) *
1669 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001670 }
1671 break;
1672 case GDF_16BIT_565RGB:
1673 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001674 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001675 xcount = width;
1676 while (xcount--) {
1677 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001678 FILL_16BIT_565RGB(cte.red, cte.green,
1679 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001680 }
1681 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001682 fb -= (VIDEO_VISIBLE_COLS + width) *
1683 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001684 }
1685 break;
1686 case GDF_32BIT_X888RGB:
1687 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001688 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001689 xcount = width;
1690 while (xcount--) {
1691 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001692 FILL_32BIT_X888RGB(cte.red, cte.green,
1693 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001694 }
1695 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001696 fb -= (VIDEO_VISIBLE_COLS + width) *
1697 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001698 }
1699 break;
1700 case GDF_24BIT_888RGB:
1701 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001702 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001703 xcount = width;
1704 while (xcount--) {
1705 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001706 FILL_24BIT_888RGB(cte.red, cte.green,
1707 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001708 }
1709 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001710 fb -= (VIDEO_VISIBLE_COLS + width) *
1711 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001712 }
1713 break;
1714 }
1715 break;
1716 case 24:
1717 padded_line -= 3 * width;
1718 ycount = height;
1719 switch (VIDEO_DATA_FORMAT) {
1720 case GDF__8BIT_332RGB:
1721 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001722 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001723 xcount = width;
1724 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001725 FILL_8BIT_332RGB(bmap[2], bmap[1],
1726 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001727 bmap += 3;
1728 }
1729 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001730 fb -= (VIDEO_VISIBLE_COLS + width) *
1731 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001732 }
1733 break;
1734 case GDF_15BIT_555RGB:
1735 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001736#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1737 int xpos = x;
1738#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001739 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001740 xcount = width;
1741 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001742#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001743 fill_555rgb_pswap(fb, xpos++, bmap[2],
1744 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001745 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001746#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001747 FILL_15BIT_555RGB(bmap[2], bmap[1],
1748 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001749#endif
wdenk4b248f32004-03-14 16:51:43 +00001750 bmap += 3;
1751 }
1752 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001753 fb -= (VIDEO_VISIBLE_COLS + width) *
1754 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001755 }
1756 break;
1757 case GDF_16BIT_565RGB:
1758 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001759 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001760 xcount = width;
1761 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001762 FILL_16BIT_565RGB(bmap[2], bmap[1],
1763 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001764 bmap += 3;
1765 }
1766 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001767 fb -= (VIDEO_VISIBLE_COLS + width) *
1768 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001769 }
1770 break;
1771 case GDF_32BIT_X888RGB:
1772 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001773 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001774 xcount = width;
1775 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001776 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1777 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001778 bmap += 3;
1779 }
1780 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001781 fb -= (VIDEO_VISIBLE_COLS + width) *
1782 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001783 }
1784 break;
1785 case GDF_24BIT_888RGB:
1786 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001787 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001788 xcount = width;
1789 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001790 FILL_24BIT_888RGB(bmap[2], bmap[1],
1791 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001792 bmap += 3;
1793 }
1794 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001795 fb -= (VIDEO_VISIBLE_COLS + width) *
1796 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001797 }
1798 break;
1799 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001800 printf("Error: 24 bits/pixel bitmap incompatible "
1801 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001802 break;
1803 }
1804 break;
1805 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001806 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1807 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001808 break;
1809 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001810
1811#ifdef CONFIG_VIDEO_BMP_GZIP
1812 if (dst) {
1813 free(dst);
1814 }
1815#endif
1816
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001817 if (cfb_do_flush_cache)
1818 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk4b248f32004-03-14 16:51:43 +00001819 return (0);
1820}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001821#endif
wdenk4b248f32004-03-14 16:51:43 +00001822
wdenk4b248f32004-03-14 16:51:43 +00001823
wdenkc6097192002-11-03 00:24:07 +00001824#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001825static int video_logo_xpos;
1826static int video_logo_ypos;
1827
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001828static void plot_logo_or_black(void *screen, int width, int x, int y, \
1829 int black);
1830
1831static void logo_plot(void *screen, int width, int x, int y)
1832{
1833 plot_logo_or_black(screen, width, x, y, 0);
1834}
1835
1836static void logo_black(void)
1837{
1838 plot_logo_or_black(video_fb_address, \
1839 VIDEO_COLS, \
1840 video_logo_xpos, \
1841 video_logo_ypos, \
1842 1);
1843}
1844
1845static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1846{
1847 if (argc != 1)
1848 return cmd_usage(cmdtp);
1849
1850 logo_black();
1851 return 0;
1852}
1853
1854U_BOOT_CMD(
1855 clrlogo, 1, 0, do_clrlogo,
1856 "fill the boot logo area with black",
1857 " "
1858 );
1859
1860static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001861{
wdenkc6097192002-11-03 00:24:07 +00001862
wdenk4b248f32004-03-14 16:51:43 +00001863 int xcount, i;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001864 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001865 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001866 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1867 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001868 unsigned char *dest;
1869
1870#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1871 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001872 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001873 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001874 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001875
1876 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001877 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001878 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001879 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001880#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1881
1882 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001883
1884#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001885 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001886
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001887 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001888 logo_red = malloc(BMP_LOGO_COLORS);
1889 logo_green = malloc(BMP_LOGO_COLORS);
1890 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001891 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001892 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1893 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1894 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1895 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1896 }
wdenka6c7ad22002-12-03 21:28:10 +00001897#else
wdenk4b248f32004-03-14 16:51:43 +00001898 source = linux_logo;
1899 logo_red = linux_logo_red;
1900 logo_green = linux_logo_green;
1901 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001902#endif
wdenk8bde7f72003-06-27 21:31:46 +00001903
wdenk4b248f32004-03-14 16:51:43 +00001904 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1905 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001906 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1907 logo_red[i], logo_green[i],
1908 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001909 }
wdenk8bde7f72003-06-27 21:31:46 +00001910 }
wdenkc6097192002-11-03 00:24:07 +00001911
wdenk4b248f32004-03-14 16:51:43 +00001912 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001913#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1914 int xpos = x;
1915#endif
wdenk4b248f32004-03-14 16:51:43 +00001916 xcount = VIDEO_LOGO_WIDTH;
1917 while (xcount--) {
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001918 if (black) {
1919 r = 0x00;
1920 g = 0x00;
1921 b = 0x00;
1922 } else {
1923 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1924 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1925 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1926 }
wdenk8bde7f72003-06-27 21:31:46 +00001927
wdenk4b248f32004-03-14 16:51:43 +00001928 switch (VIDEO_DATA_FORMAT) {
1929 case GDF__8BIT_INDEX:
1930 *dest = *source;
1931 break;
1932 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001933 *dest = ((r >> 5) << 5) |
1934 ((g >> 5) << 2) |
1935 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001936 break;
1937 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001938#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001939 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001940#else
wdenk4b248f32004-03-14 16:51:43 +00001941 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001942 SWAP16((unsigned short) (
1943 ((r >> 3) << 10) |
1944 ((g >> 3) << 5) |
1945 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001946#endif
wdenk4b248f32004-03-14 16:51:43 +00001947 break;
1948 case GDF_16BIT_565RGB:
1949 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001950 SWAP16((unsigned short) (
1951 ((r >> 3) << 11) |
1952 ((g >> 2) << 5) |
1953 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001954 break;
1955 case GDF_32BIT_X888RGB:
1956 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001957 SWAP32((unsigned long) (
1958 (r << 16) |
1959 (g << 8) |
1960 b));
wdenk4b248f32004-03-14 16:51:43 +00001961 break;
1962 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001963#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001964 dest[0] = b;
1965 dest[1] = g;
1966 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001967#else
wdenk4b248f32004-03-14 16:51:43 +00001968 dest[0] = r;
1969 dest[1] = g;
1970 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001971#endif
wdenk4b248f32004-03-14 16:51:43 +00001972 break;
1973 }
1974 source++;
1975 dest += VIDEO_PIXEL_SIZE;
1976 }
1977 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001978 }
wdenka6c7ad22002-12-03 21:28:10 +00001979#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001980 free(logo_red);
1981 free(logo_green);
1982 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001983#endif
wdenkc6097192002-11-03 00:24:07 +00001984}
1985
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001986static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001987{
wdenk4b248f32004-03-14 16:51:43 +00001988 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001989 int space, len;
1990 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001991 __maybe_unused ulong addr;
1992 __maybe_unused char *s;
wdenkc6097192002-11-03 00:24:07 +00001993
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001994 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001995
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001996#ifdef CONFIG_SPLASH_SCREEN
1997 s = getenv("splashimage");
1998 if (s != NULL) {
Robert Winklerdd4425e2013-06-17 11:31:29 -07001999 splash_screen_prepare();
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002000 addr = simple_strtoul(s, NULL, 16);
2001
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002002 if (video_display_bitmap(addr,
2003 video_logo_xpos,
2004 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002005 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00002006 return ((void *) (video_fb_address));
2007 }
2008 }
2009#endif /* CONFIG_SPLASH_SCREEN */
2010
Bastian Ruppert1e681f92012-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)
Masahiro Yamadab4141192014-11-07 03:03:31 +09002026 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002027 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
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002034 if (board_cfb_skip())
2035 return 0;
wdenk4b248f32004-03-14 16:51:43 +00002036
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002037 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002038
2039 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2040 len = strlen(info);
2041
2042 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002043 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2044 (uchar *) info, space);
2045 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2046 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2047 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002048 y_off = 1;
2049 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002050 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00002051
2052#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00002053 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002054 int i, n =
2055 ((video_logo_height -
2056 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002057
wdenk4b248f32004-03-14 16:51:43 +00002058 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002059 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002060 if (!*info)
2061 continue;
2062
2063 len = strlen(info);
2064 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002065 video_drawchars(VIDEO_INFO_X,
2066 VIDEO_INFO_Y +
2067 (i + y_off) *
2068 VIDEO_FONT_HEIGHT,
2069 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002070 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002071 video_drawchars(VIDEO_INFO_X +
2072 VIDEO_FONT_WIDTH,
2073 VIDEO_INFO_Y +
2074 (i + y_off) *
2075 VIDEO_FONT_HEIGHT,
2076 (uchar *) info + space,
2077 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002078 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002079 video_drawstring(VIDEO_INFO_X,
2080 VIDEO_INFO_Y +
2081 (i + y_off) *
2082 VIDEO_FONT_HEIGHT,
2083 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002084 }
wdenk4b248f32004-03-14 16:51:43 +00002085 }
2086 }
wdenkc6097192002-11-03 00:24:07 +00002087#endif
2088
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002089 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002090}
2091#endif
2092
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002093static int cfb_fb_is_in_dram(void)
2094{
2095 bd_t *bd = gd->bd;
2096#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2097defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2098 ulong start, end;
2099 int i;
2100
2101 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2102 start = bd->bi_dram[i].start;
2103 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2104 if ((ulong)video_fb_address >= start &&
2105 (ulong)video_fb_address < end)
2106 return 1;
2107 }
2108#else
2109 if ((ulong)video_fb_address >= bd->bi_memstart &&
2110 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2111 return 1;
2112#endif
2113 return 0;
2114}
2115
Heiko Schocher45ae2542013-10-22 11:06:06 +02002116void video_clear(void)
2117{
2118 if (!video_fb_address)
2119 return;
2120#ifdef VIDEO_HW_RECTFILL
2121 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2122 0, /* dest pos x */
2123 0, /* dest pos y */
2124 VIDEO_VISIBLE_COLS, /* frame width */
2125 VIDEO_VISIBLE_ROWS, /* frame height */
2126 bgx /* fill color */
2127 );
2128#else
2129 memsetl(video_fb_address,
2130 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2131#endif
2132}
2133
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002134static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002135{
wdenk4b248f32004-03-14 16:51:43 +00002136 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002137
Wolfgang Denk57912932011-07-30 12:48:09 +00002138 pGD = video_hw_init();
2139 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00002140 return -1;
wdenkc6097192002-11-03 00:24:07 +00002141
wdenk4b248f32004-03-14 16:51:43 +00002142 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002143#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002144 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002145#endif
2146
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002147 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2148
wdenk4b248f32004-03-14 16:51:43 +00002149 /* Init drawing pats */
2150 switch (VIDEO_DATA_FORMAT) {
2151 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002152 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2153 CONSOLE_FG_COL);
2154 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2155 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00002156 fgx = 0x01010101;
2157 bgx = 0x00000000;
2158 break;
2159 case GDF__8BIT_332RGB:
2160 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002161 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2162 CONSOLE_FG_COL >> 6);
2163 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2164 color8;
wdenk4b248f32004-03-14 16:51:43 +00002165 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002166 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2167 CONSOLE_BG_COL >> 6);
2168 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2169 color8;
wdenk4b248f32004-03-14 16:51:43 +00002170 break;
2171 case GDF_15BIT_555RGB:
2172 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002173 ((CONSOLE_FG_COL >> 3) << 21) |
2174 ((CONSOLE_FG_COL >> 3) << 16) |
2175 ((CONSOLE_FG_COL >> 3) << 10) |
2176 ((CONSOLE_FG_COL >> 3) << 5) |
2177 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002178 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002179 ((CONSOLE_BG_COL >> 3) << 21) |
2180 ((CONSOLE_BG_COL >> 3) << 16) |
2181 ((CONSOLE_BG_COL >> 3) << 10) |
2182 ((CONSOLE_BG_COL >> 3) << 5) |
2183 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002184 break;
2185 case GDF_16BIT_565RGB:
2186 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002187 ((CONSOLE_FG_COL >> 2) << 21) |
2188 ((CONSOLE_FG_COL >> 3) << 16) |
2189 ((CONSOLE_FG_COL >> 3) << 11) |
2190 ((CONSOLE_FG_COL >> 2) << 5) |
2191 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002192 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002193 ((CONSOLE_BG_COL >> 2) << 21) |
2194 ((CONSOLE_BG_COL >> 3) << 16) |
2195 ((CONSOLE_BG_COL >> 3) << 11) |
2196 ((CONSOLE_BG_COL >> 2) << 5) |
2197 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002198 break;
2199 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002200 fgx = (CONSOLE_FG_COL << 16) |
2201 (CONSOLE_FG_COL << 8) |
2202 CONSOLE_FG_COL;
2203 bgx = (CONSOLE_BG_COL << 16) |
2204 (CONSOLE_BG_COL << 8) |
2205 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002206 break;
2207 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002208 fgx = (CONSOLE_FG_COL << 24) |
2209 (CONSOLE_FG_COL << 16) |
2210 (CONSOLE_FG_COL << 8) |
2211 CONSOLE_FG_COL;
2212 bgx = (CONSOLE_BG_COL << 24) |
2213 (CONSOLE_BG_COL << 16) |
2214 (CONSOLE_BG_COL << 8) |
2215 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002216 break;
2217 }
2218 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002219
Heiko Schocher45ae2542013-10-22 11:06:06 +02002220 video_clear();
2221
wdenkc6097192002-11-03 00:24:07 +00002222#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00002223 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002224 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002225 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002226#else
wdenk4b248f32004-03-14 16:51:43 +00002227 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002228#endif
2229
wdenk4b248f32004-03-14 16:51:43 +00002230 /* Initialize the console */
2231 console_col = 0;
2232 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002233
Eric Nelsondb0d47d2013-05-06 14:27:28 +02002234 if (cfb_do_flush_cache)
2235 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2236
wdenk4b248f32004-03-14 16:51:43 +00002237 return 0;
wdenkc6097192002-11-03 00:24:07 +00002238}
2239
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002240/*
2241 * Implement a weak default function for boards that optionally
2242 * need to skip the video initialization.
2243 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02002244__weak int board_video_skip(void)
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002245{
2246 /* As default, don't skip test */
2247 return 0;
2248}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002249
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002250int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002251{
wdenk4b248f32004-03-14 16:51:43 +00002252 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02002253 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00002254
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002255 /* Check if video initialization should be skipped */
2256 if (board_video_skip())
2257 return 0;
2258
wdenk81050922004-07-11 20:04:51 +00002259 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002260 skip_dev_init = (video_init() == -1);
wdenk81050922004-07-11 20:04:51 +00002261
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002262 if (board_cfb_skip())
2263 return 0;
2264
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002265#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002266 debug("KBD: Keyboard init ...\n");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002267 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2268#endif
wdenkc6097192002-11-03 00:24:07 +00002269
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002270 if (skip_dev_init)
2271 return 0;
wdenkc6097192002-11-03 00:24:07 +00002272
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002273 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002274 memset(&console_dev, 0, sizeof(console_dev));
2275 strcpy(console_dev.name, "vga");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002276 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2277 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2278 console_dev.putc = video_putc; /* 'putc' function */
2279 console_dev.puts = video_puts; /* 'puts' function */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002280
2281#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2282 /* Also init console device */
2283 console_dev.flags |= DEV_FLAGS_INPUT;
2284 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2285 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00002286#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002287
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002288 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002289 return 0;
2290
2291 /* Return success */
2292 return 1;
wdenkc6097192002-11-03 00:24:07 +00002293}
Stefan Reinauerc20ee072012-09-28 15:11:12 +00002294
2295void video_position_cursor(unsigned col, unsigned row)
2296{
2297 console_col = min(col, CONSOLE_COLS - 1);
2298 console_row = min(row, CONSOLE_ROWS - 1);
2299}
2300
2301int video_get_pixel_width(void)
2302{
2303 return VIDEO_VISIBLE_COLS;
2304}
2305
2306int video_get_pixel_height(void)
2307{
2308 return VIDEO_VISIBLE_ROWS;
2309}
2310
2311int video_get_screen_rows(void)
2312{
2313 return CONSOLE_ROWS;
2314}
2315
2316int video_get_screen_columns(void)
2317{
2318 return CONSOLE_COLS;
2319}