blob: 7f2ddc10c62b88e519c29fb14627c1e237db3c85 [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>
Simon Glass5692ccf2015-03-02 12:40:50 -070090#include <fdtdec.h>
Andreas Bießmann09c2e902011-07-18 20:24:04 +020091#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +000092#include <malloc.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +000093#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +000094
Wolfgang Denk64e40d72011-07-29 09:55:27 +000095/*
96 * Console device defines with SMI graphic
97 * Any other graphic must change this section
98 */
wdenkc6097192002-11-03 00:24:07 +000099
wdenk4b248f32004-03-14 16:51:43 +0000100#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000101
102#define VIDEO_FB_LITTLE_ENDIAN
103#define VIDEO_HW_RECTFILL
104#define VIDEO_HW_BITBLT
105#endif
106
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000107/*
108 * Defines for the CT69000 driver
109 */
wdenk4b248f32004-03-14 16:51:43 +0000110#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000111
112#define VIDEO_FB_LITTLE_ENDIAN
113#define VIDEO_HW_RECTFILL
114#define VIDEO_HW_BITBLT
115#endif
116
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000117/*
118 * Defines for the SED13806 driver
119 */
wdenka6c7ad22002-12-03 21:28:10 +0000120#ifdef CONFIG_VIDEO_SED13806
wdenka6c7ad22002-12-03 21:28:10 +0000121#define VIDEO_FB_LITTLE_ENDIAN
122#define VIDEO_HW_RECTFILL
123#define VIDEO_HW_BITBLT
124#endif
125
Marek Vasutfb8ddc22013-04-28 09:20:03 +0000126#ifdef CONFIG_VIDEO_MXS
127#define VIDEO_FB_16BPP_WORD_SWAP
128#endif
129
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000130/*
131 * Defines for the MB862xx driver
132 */
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100133#ifdef CONFIG_VIDEO_MB862xx
134
135#ifdef CONFIG_VIDEO_CORALP
136#define VIDEO_FB_LITTLE_ENDIAN
137#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200138#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100139#define VIDEO_HW_RECTFILL
140#define VIDEO_HW_BITBLT
141#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200142#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100143
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000144/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000145 * Defines for the i.MX31 driver (mx3fb.c)
146 */
Fabio Estevam695af9a2012-05-31 07:23:56 +0000147#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000148#define VIDEO_FB_16BPP_WORD_SWAP
149#endif
150
151/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000152 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
153 */
wdenkc6097192002-11-03 00:24:07 +0000154#include <video_fb.h>
155
Robert Winklerdd4425e2013-06-17 11:31:29 -0700156#include <splash.h>
157
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000158/*
159 * some Macros
160 */
wdenk4b248f32004-03-14 16:51:43 +0000161#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
162#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
163#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
164#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
165#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000166
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000167/*
168 * Console device defines with i8042 keyboard controller
169 * Any other keyboard controller must change this section
170 */
wdenkc6097192002-11-03 00:24:07 +0000171
wdenk4b248f32004-03-14 16:51:43 +0000172#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000173#include <i8042.h>
174
wdenk4b248f32004-03-14 16:51:43 +0000175#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
176#define VIDEO_TSTC_FCT i8042_tstc
177#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000178#endif
179
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000180/*
181 * Console device
182 */
wdenkc6097192002-11-03 00:24:07 +0000183
184#include <version.h>
185#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200186#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000187#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000188
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500189#if defined(CONFIG_CMD_DATE)
190#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000191#endif
192
Jon Loeliger07d38a12007-07-09 17:30:01 -0500193#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000194#include <watchdog.h>
195#include <bmp_layout.h>
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200196#include <splash.h>
Jon Loeliger07d38a12007-07-09 17:30:01 -0500197#endif
wdenk4b248f32004-03-14 16:51:43 +0000198
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000199/*
200 * Cursor definition:
201 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
202 * to let the cursor blink. Uses the macros
203 * CURSOR_OFF and CURSOR_ON.
204 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
205 * blinking is provided. Uses the macros CURSOR_SET
206 * and CURSOR_OFF.
207 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
208 * graphic chip. Uses the macro CURSOR_SET.
209 * ATTENTION: If booting an OS, the display driver
210 * must disable the hardware register of the graphic
211 * chip. Otherwise a blinking field is displayed
212 */
wdenkc6097192002-11-03 00:24:07 +0000213#if !defined(CONFIG_CONSOLE_CURSOR) && \
214 !defined(CONFIG_VIDEO_SW_CURSOR) && \
215 !defined(CONFIG_VIDEO_HW_CURSOR)
216/* no Cursor defined */
217#define CURSOR_ON
218#define CURSOR_OFF
219#define CURSOR_SET
220#endif
221
Gabe Black03d31fc2011-11-30 13:50:50 +0000222#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
223#if defined(CURSOR_ON) || \
224 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000225#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
226 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000227#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000228void console_cursor(int state);
229
Timur Tabi65618632010-08-27 15:45:47 -0500230#define CURSOR_ON console_cursor(1)
231#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000232#define CURSOR_SET video_set_cursor()
233#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
234
235#ifdef CONFIG_CONSOLE_CURSOR
236#ifndef CONFIG_CONSOLE_TIME
237#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
238#endif
wdenkc6097192002-11-03 00:24:07 +0000239#ifndef CONFIG_I8042_KBD
Marcel Ziswiler7817cb22007-12-30 03:30:46 +0100240#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000241#endif
wdenkc6097192002-11-03 00:24:07 +0000242#endif /* CONFIG_CONSOLE_CURSOR */
243
wdenkc6097192002-11-03 00:24:07 +0000244
245#ifdef CONFIG_VIDEO_HW_CURSOR
wdenk4b248f32004-03-14 16:51:43 +0000246#ifdef CURSOR_ON
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000247#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
248 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000249#endif
250#define CURSOR_ON
251#define CURSOR_OFF
252#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabi65618632010-08-27 15:45:47 -0500253 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000254#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000255
wdenk4b248f32004-03-14 16:51:43 +0000256#ifdef CONFIG_VIDEO_LOGO
257#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000258#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000259#include <bmp_logo_data.h>
wdenk4b248f32004-03-14 16:51:43 +0000260#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
261#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
262#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
263#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenka6c7ad22002-12-03 21:28:10 +0000264
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000265#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000266#define LINUX_LOGO_WIDTH 80
267#define LINUX_LOGO_HEIGHT 80
268#define LINUX_LOGO_COLORS 214
269#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000270#define __initdata
271#include <linux_logo.h>
wdenk4b248f32004-03-14 16:51:43 +0000272#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
273#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
274#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
275#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000276#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000277#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
278#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000279#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000280#define VIDEO_LOGO_WIDTH 0
281#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000282#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000283
wdenk4b248f32004-03-14 16:51:43 +0000284#define VIDEO_COLS VIDEO_VISIBLE_COLS
285#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
286#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
287#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
288#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
289#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000290
wdenk4b248f32004-03-14 16:51:43 +0000291#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100292#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000293#else
wdenk4b248f32004-03-14 16:51:43 +0000294#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000295#endif
296
wdenk4b248f32004-03-14 16:51:43 +0000297#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
298#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
299#define CONSOLE_ROW_FIRST (video_console_address)
300#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
301#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
302#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass3c0b6682015-01-01 16:17:57 -0700303
304/* By default we scroll by a single line */
305#ifndef CONFIG_CONSOLE_SCROLL_LINES
306#define CONFIG_CONSOLE_SCROLL_LINES 1
307#endif
wdenkc6097192002-11-03 00:24:07 +0000308
309/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000310#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000311#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
312 ((x) >> 8) \
313 )
314#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
315 (((x) & 0x0000ff00) << 8) | \
316 (((x) & 0x00ff0000) >> 8) | \
317 (((x) & 0xff000000) >> 24) \
318 )
319#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
320 (((x) & 0x0000ff00) >> 8) | \
321 (((x) & 0x00ff0000) << 8) | \
322 (((x) & 0xff000000) >> 8) \
323 )
wdenkc6097192002-11-03 00:24:07 +0000324#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000325#define SWAP16(x) (x)
326#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200327#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000328#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500329#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000330#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100331#endif
wdenkc6097192002-11-03 00:24:07 +0000332#endif
333
wdenkc6097192002-11-03 00:24:07 +0000334#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000335/*
336 * setup a board string: type, speed, etc.
337 *
338 * line_number: location to place info string beside logo
339 * info: buffer for info string
340 */
341extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000342#endif
343
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200344DECLARE_GLOBAL_DATA_PTR;
345
wdenkc6097192002-11-03 00:24:07 +0000346/* Locals */
347static GraphicDevice *pGD; /* Pointer to Graphic array */
348
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000349static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000350static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000351
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100352static int video_logo_height = VIDEO_LOGO_HEIGHT;
353
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000354static int __maybe_unused cursor_state;
355static int __maybe_unused old_col;
356static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000357
Wolfgang Denk57912932011-07-30 12:48:09 +0000358static int console_col; /* cursor col */
359static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000360
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000361static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000362
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200363static int cfb_do_flush_cache;
364
Pali Rohár33a35bb2012-10-19 13:30:09 +0000365#ifdef CONFIG_CFB_CONSOLE_ANSI
366static char ansi_buf[10];
367static int ansi_buf_size;
368static int ansi_colors_need_revert;
369static int ansi_cursor_hidden;
370#endif
371
wdenkc6097192002-11-03 00:24:07 +0000372static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000373 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
374 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
375 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
376 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
377};
wdenkc6097192002-11-03 00:24:07 +0000378
379static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000380 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
381};
wdenkc6097192002-11-03 00:24:07 +0000382
383static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000384 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
385};
wdenkc6097192002-11-03 00:24:07 +0000386
387static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000388 {0x00000000, 0x00000000, 0x00000000},
389 {0x00000000, 0x00000000, 0x00ffffff},
390 {0x00000000, 0x0000ffff, 0xff000000},
391 {0x00000000, 0x0000ffff, 0xffffffff},
392 {0x000000ff, 0xffff0000, 0x00000000},
393 {0x000000ff, 0xffff0000, 0x00ffffff},
394 {0x000000ff, 0xffffffff, 0xff000000},
395 {0x000000ff, 0xffffffff, 0xffffffff},
396 {0xffffff00, 0x00000000, 0x00000000},
397 {0xffffff00, 0x00000000, 0x00ffffff},
398 {0xffffff00, 0x0000ffff, 0xff000000},
399 {0xffffff00, 0x0000ffff, 0xffffffff},
400 {0xffffffff, 0xffff0000, 0x00000000},
401 {0xffffffff, 0xffff0000, 0x00ffffff},
402 {0xffffffff, 0xffffffff, 0xff000000},
403 {0xffffffff, 0xffffffff, 0xffffffff}
404};
wdenkc6097192002-11-03 00:24:07 +0000405
406static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000407 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
408 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
409 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
410 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
411 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
412 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
413 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
414 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
415 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
416 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
417 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
418 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
419 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
420 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
421 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
422 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
423};
wdenkc6097192002-11-03 00:24:07 +0000424
Heiko Schocher2bc4aa52013-08-03 07:22:53 +0200425/*
426 * Implement a weak default function for boards that optionally
427 * need to skip the cfb initialization.
428 */
429__weak int board_cfb_skip(void)
430{
431 /* As default, don't skip cfb init */
432 return 0;
433}
434
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000435static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000436{
wdenk4b248f32004-03-14 16:51:43 +0000437 u8 *cdat, *dest, *dest0;
438 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000439
wdenk4b248f32004-03-14 16:51:43 +0000440 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
441 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000442
wdenk4b248f32004-03-14 16:51:43 +0000443 switch (VIDEO_DATA_FORMAT) {
444 case GDF__8BIT_INDEX:
445 case GDF__8BIT_332RGB:
446 while (count--) {
447 c = *s;
448 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
449 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000450 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000451 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000452
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000453 ((u32 *) dest)[0] =
454 (video_font_draw_table8[bits >> 4] &
455 eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200456
457 if (VIDEO_FONT_WIDTH == 4)
458 continue;
459
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000460 ((u32 *) dest)[1] =
461 (video_font_draw_table8[bits & 15] &
462 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000463 }
464 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
465 s++;
466 }
467 break;
wdenkc6097192002-11-03 00:24:07 +0000468
wdenk4b248f32004-03-14 16:51:43 +0000469 case GDF_15BIT_555RGB:
470 while (count--) {
471 c = *s;
472 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
473 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000474 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000475 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000476
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000477 ((u32 *) dest)[0] =
478 SHORTSWAP32((video_font_draw_table15
479 [bits >> 6] & eorx) ^
480 bgx);
481 ((u32 *) dest)[1] =
482 SHORTSWAP32((video_font_draw_table15
483 [bits >> 4 & 3] & eorx) ^
484 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200485
486 if (VIDEO_FONT_WIDTH == 4)
487 continue;
488
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000489 ((u32 *) dest)[2] =
490 SHORTSWAP32((video_font_draw_table15
491 [bits >> 2 & 3] & eorx) ^
492 bgx);
493 ((u32 *) dest)[3] =
494 SHORTSWAP32((video_font_draw_table15
495 [bits & 3] & eorx) ^
496 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000497 }
498 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
499 s++;
500 }
501 break;
wdenkc6097192002-11-03 00:24:07 +0000502
wdenk4b248f32004-03-14 16:51:43 +0000503 case GDF_16BIT_565RGB:
504 while (count--) {
505 c = *s;
506 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
507 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000508 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000509 u8 bits = *cdat++;
510
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000511 ((u32 *) dest)[0] =
512 SHORTSWAP32((video_font_draw_table16
513 [bits >> 6] & eorx) ^
514 bgx);
515 ((u32 *) dest)[1] =
516 SHORTSWAP32((video_font_draw_table16
517 [bits >> 4 & 3] & eorx) ^
518 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200519
520 if (VIDEO_FONT_WIDTH == 4)
521 continue;
522
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000523 ((u32 *) dest)[2] =
524 SHORTSWAP32((video_font_draw_table16
525 [bits >> 2 & 3] & eorx) ^
526 bgx);
527 ((u32 *) dest)[3] =
528 SHORTSWAP32((video_font_draw_table16
529 [bits & 3] & eorx) ^
530 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000531 }
532 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
533 s++;
534 }
535 break;
536
537 case GDF_32BIT_X888RGB:
538 while (count--) {
539 c = *s;
540 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
541 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000542 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000543 u8 bits = *cdat++;
544
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000545 ((u32 *) dest)[0] =
546 SWAP32((video_font_draw_table32
547 [bits >> 4][0] & eorx) ^ bgx);
548 ((u32 *) dest)[1] =
549 SWAP32((video_font_draw_table32
550 [bits >> 4][1] & eorx) ^ bgx);
551 ((u32 *) dest)[2] =
552 SWAP32((video_font_draw_table32
553 [bits >> 4][2] & eorx) ^ bgx);
554 ((u32 *) dest)[3] =
555 SWAP32((video_font_draw_table32
556 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200557
558
559 if (VIDEO_FONT_WIDTH == 4)
560 continue;
561
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000562 ((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);
wdenk4b248f32004-03-14 16:51:43 +0000574 }
575 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
576 s++;
577 }
578 break;
579
580 case GDF_24BIT_888RGB:
581 while (count--) {
582 c = *s;
583 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
584 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000585 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000586 u8 bits = *cdat++;
587
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000588 ((u32 *) dest)[0] =
589 (video_font_draw_table24[bits >> 4][0]
590 & eorx) ^ bgx;
591 ((u32 *) dest)[1] =
592 (video_font_draw_table24[bits >> 4][1]
593 & eorx) ^ bgx;
594 ((u32 *) dest)[2] =
595 (video_font_draw_table24[bits >> 4][2]
596 & eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200597
598 if (VIDEO_FONT_WIDTH == 4)
599 continue;
600
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000601 ((u32 *) dest)[3] =
602 (video_font_draw_table24[bits & 15][0]
603 & eorx) ^ bgx;
604 ((u32 *) dest)[4] =
605 (video_font_draw_table24[bits & 15][1]
606 & eorx) ^ bgx;
607 ((u32 *) dest)[5] =
608 (video_font_draw_table24[bits & 15][2]
609 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000610 }
611 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
612 s++;
613 }
614 break;
wdenk8bde7f72003-06-27 21:31:46 +0000615 }
wdenkc6097192002-11-03 00:24:07 +0000616}
617
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000618static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000619{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000620 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000621}
622
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000623static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000624{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000625 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000626}
627
wdenkc6097192002-11-03 00:24:07 +0000628#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000629static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000630{
Gabe Black03d31fc2011-11-30 13:50:50 +0000631 if (cursor_state)
632 console_cursor(0);
633 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000634}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000635
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000636static void video_invertchar(int xx, int yy)
637{
638 int firstx = xx * VIDEO_PIXEL_SIZE;
639 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
640 int firsty = yy * VIDEO_LINE_LEN;
641 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
642 int x, y;
643 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
644 for (x = firstx; x < lastx; x++) {
645 u8 *dest = (u8 *)(video_fb_address) + x + y;
646 *dest = ~*dest;
647 }
648 }
649}
Gabe Black03d31fc2011-11-30 13:50:50 +0000650
Wolfgang Denk64e40d72011-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
wdenk4b248f32004-03-14 16:51:43 +0000654 struct rtc_time tm;
655 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000656
wdenk4b248f32004-03-14 16:51:43 +0000657 /* time update only if cursor is on (faster scroll) */
658 if (state) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000659 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000660
Wolfgang Denk64e40d72011-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 Denk64e40d72011-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);
wdenk4b248f32004-03-14 16:51:43 +0000671 }
wdenkc6097192002-11-03 00:24:07 +0000672#endif
673
Gabe Black03d31fc2011-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;
wdenk4b248f32004-03-14 16:51:43 +0000689 }
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200690 if (cfb_do_flush_cache)
691 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000692}
693#endif
694
wdenkc6097192002-11-03 00:24:07 +0000695#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000696static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000697{
wdenk4b248f32004-03-14 16:51:43 +0000698 while (c--)
699 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000700}
701#endif
702
wdenkc6097192002-11-03 00:24:07 +0000703#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000704static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000705{
wdenk4b248f32004-03-14 16:51:43 +0000706 while (c--)
707 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000708}
709#endif
710
Pali Rohár90f60a82012-04-28 07:26:44 +0000711static void console_clear_line(int line, int begin, int end)
712{
713#ifdef VIDEO_HW_RECTFILL
714 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
715 VIDEO_FONT_WIDTH * begin, /* dest pos x */
716 video_logo_height +
717 VIDEO_FONT_HEIGHT * line, /* dest pos y */
718 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
719 VIDEO_FONT_HEIGHT, /* frame height */
720 bgx /* fill color */
721 );
722#else
723 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
724 memsetl(CONSOLE_ROW_FIRST +
725 CONSOLE_ROW_SIZE * line, /* offset of row */
726 CONSOLE_ROW_SIZE >> 2, /* length of row */
727 bgx /* fill color */
728 );
729 } else {
730 void *offset;
731 int i, size;
732
733 offset = CONSOLE_ROW_FIRST +
734 CONSOLE_ROW_SIZE * line + /* offset of row */
735 VIDEO_FONT_WIDTH *
736 VIDEO_PIXEL_SIZE * begin; /* offset of col */
737 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
738 size >>= 2; /* length to end for memsetl() */
739 /* fill at col offset of i'th line using bgx as fill color */
740 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
741 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
742 }
743#endif
744}
745
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000746static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000747{
Simon Glass3c0b6682015-01-01 16:17:57 -0700748 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
749 int i;
750
wdenk4b248f32004-03-14 16:51:43 +0000751 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000752
753#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000754 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
755 0, /* source pos x */
756 video_logo_height +
Simon Glass3c0b6682015-01-01 16:17:57 -0700757 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000758 0, /* dest pos x */
759 video_logo_height, /* dest pos y */
760 VIDEO_VISIBLE_COLS, /* frame width */
761 VIDEO_VISIBLE_ROWS
762 - video_logo_height
Simon Glass3c0b6682015-01-01 16:17:57 -0700763 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000764 );
wdenkc6097192002-11-03 00:24:07 +0000765#else
Simon Glass3c0b6682015-01-01 16:17:57 -0700766 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
767 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000768#endif
wdenk4b248f32004-03-14 16:51:43 +0000769 /* clear the last one */
Simon Glass3c0b6682015-01-01 16:17:57 -0700770 for (i = 1; i <= rows; i++)
771 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
772
773 /* Decrement row number */
774 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000775}
776
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000777static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000778{
Timur Tabi65618632010-08-27 15:45:47 -0500779 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000780
wdenk4b248f32004-03-14 16:51:43 +0000781 if (console_col < 0) {
782 console_col = CONSOLE_COLS - 1;
783 console_row--;
784 if (console_row < 0)
785 console_row = 0;
786 }
wdenkc6097192002-11-03 00:24:07 +0000787}
788
Pali Rohár33a35bb2012-10-19 13:30:09 +0000789#ifdef CONFIG_CFB_CONSOLE_ANSI
790
791static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000792{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000793#ifdef VIDEO_HW_RECTFILL
794 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
795 0, /* dest pos x */
796 video_logo_height, /* dest pos y */
797 VIDEO_VISIBLE_COLS, /* frame width */
798 VIDEO_VISIBLE_ROWS, /* frame height */
799 bgx /* fill color */
800 );
801#else
802 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
803#endif
804}
805
806static void console_cursor_fix(void)
807{
808 if (console_row < 0)
809 console_row = 0;
810 if (console_row >= CONSOLE_ROWS)
811 console_row = CONSOLE_ROWS - 1;
812 if (console_col < 0)
813 console_col = 0;
814 if (console_col >= CONSOLE_COLS)
815 console_col = CONSOLE_COLS - 1;
816}
817
818static void console_cursor_up(int n)
819{
820 console_row -= n;
821 console_cursor_fix();
822}
823
824static void console_cursor_down(int n)
825{
826 console_row += n;
827 console_cursor_fix();
828}
829
830static void console_cursor_left(int n)
831{
832 console_col -= n;
833 console_cursor_fix();
834}
835
836static void console_cursor_right(int n)
837{
838 console_col += n;
839 console_cursor_fix();
840}
841
842static void console_cursor_set_position(int row, int col)
843{
844 if (console_row != -1)
845 console_row = row;
846 if (console_col != -1)
847 console_col = col;
848 console_cursor_fix();
849}
850
851static void console_previousline(int n)
852{
853 /* FIXME: also scroll terminal ? */
854 console_row -= n;
855 console_cursor_fix();
856}
857
858static void console_swap_colors(void)
859{
860 eorx = fgx;
861 fgx = bgx;
862 bgx = eorx;
863 eorx = fgx ^ bgx;
864}
865
866static inline int console_cursor_is_visible(void)
867{
868 return !ansi_cursor_hidden;
869}
870#else
871static inline int console_cursor_is_visible(void)
872{
873 return 1;
874}
875#endif
876
877static void console_newline(int n)
878{
879 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000880 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000881
wdenk4b248f32004-03-14 16:51:43 +0000882 /* Check if we need to scroll the terminal */
883 if (console_row >= CONSOLE_ROWS) {
884 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000885 console_scrollup();
wdenk4b248f32004-03-14 16:51:43 +0000886 }
wdenkc6097192002-11-03 00:24:07 +0000887}
888
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000889static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100890{
Timur Tabi65618632010-08-27 15:45:47 -0500891 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100892}
893
Pali Rohár33a35bb2012-10-19 13:30:09 +0000894static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000895{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100896 static int nl = 1;
897
Pali Rohár33a35bb2012-10-19 13:30:09 +0000898 if (console_cursor_is_visible())
899 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000900
wdenk4b248f32004-03-14 16:51:43 +0000901 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100902 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000903 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000904 break;
wdenkc6097192002-11-03 00:24:07 +0000905
wdenk4b248f32004-03-14 16:51:43 +0000906 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100907 if (console_col || (!console_col && nl))
Pali Rohár33a35bb2012-10-19 13:30:09 +0000908 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100909 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000910 break;
wdenkc6097192002-11-03 00:24:07 +0000911
wdenk4b248f32004-03-14 16:51:43 +0000912 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500913 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000914 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000915
wdenk4b248f32004-03-14 16:51:43 +0000916 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000917 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000918 break;
wdenkc6097192002-11-03 00:24:07 +0000919
wdenk4b248f32004-03-14 16:51:43 +0000920 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000921 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000922 break;
wdenkc6097192002-11-03 00:24:07 +0000923
Pali Rohár24fe06c2012-04-28 07:26:47 +0000924 case 7: /* bell */
925 break; /* ignored */
926
wdenk4b248f32004-03-14 16:51:43 +0000927 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000928 video_putchar(console_col * VIDEO_FONT_WIDTH,
929 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000930 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000931
wdenk4b248f32004-03-14 16:51:43 +0000932 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100933 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000934 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100935 nl = 0;
936 }
wdenk4b248f32004-03-14 16:51:43 +0000937 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000938
939 if (console_cursor_is_visible())
940 CURSOR_SET;
941}
942
Jeroen Hofstee654f8d02014-10-08 22:57:44 +0200943static void video_putc(struct stdio_dev *dev, const char c)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000944{
945#ifdef CONFIG_CFB_CONSOLE_ANSI
946 int i;
947
948 if (c == 27) {
949 for (i = 0; i < ansi_buf_size; ++i)
950 parse_putc(ansi_buf[i]);
951 ansi_buf[0] = 27;
952 ansi_buf_size = 1;
953 return;
954 }
955
956 if (ansi_buf_size > 0) {
957 /*
958 * 0 - ESC
959 * 1 - [
960 * 2 - num1
961 * 3 - ..
962 * 4 - ;
963 * 5 - num2
964 * 6 - ..
965 * - cchar
966 */
967 int next = 0;
968
969 int flush = 0;
970 int fail = 0;
971
972 int num1 = 0;
973 int num2 = 0;
974 int cchar = 0;
975
976 ansi_buf[ansi_buf_size++] = c;
977
978 if (ansi_buf_size >= sizeof(ansi_buf))
979 fail = 1;
980
981 for (i = 0; i < ansi_buf_size; ++i) {
982 if (fail)
983 break;
984
985 switch (next) {
986 case 0:
987 if (ansi_buf[i] == 27)
988 next = 1;
989 else
990 fail = 1;
991 break;
992
993 case 1:
994 if (ansi_buf[i] == '[')
995 next = 2;
996 else
997 fail = 1;
998 break;
999
1000 case 2:
1001 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1002 num1 = ansi_buf[i]-'0';
1003 next = 3;
1004 } else if (ansi_buf[i] != '?') {
1005 --i;
1006 num1 = 1;
1007 next = 4;
1008 }
1009 break;
1010
1011 case 3:
1012 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1013 num1 *= 10;
1014 num1 += ansi_buf[i]-'0';
1015 } else {
1016 --i;
1017 next = 4;
1018 }
1019 break;
1020
1021 case 4:
1022 if (ansi_buf[i] != ';') {
1023 --i;
1024 next = 7;
1025 } else
1026 next = 5;
1027 break;
1028
1029 case 5:
1030 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1031 num2 = ansi_buf[i]-'0';
1032 next = 6;
1033 } else
1034 fail = 1;
1035 break;
1036
1037 case 6:
1038 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1039 num2 *= 10;
1040 num2 += ansi_buf[i]-'0';
1041 } else {
1042 --i;
1043 next = 7;
1044 }
1045 break;
1046
1047 case 7:
1048 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1049 || ansi_buf[i] == 'J'
1050 || ansi_buf[i] == 'K'
1051 || ansi_buf[i] == 'h'
1052 || ansi_buf[i] == 'l'
1053 || ansi_buf[i] == 'm') {
1054 cchar = ansi_buf[i];
1055 flush = 1;
1056 } else
1057 fail = 1;
1058 break;
1059 }
1060 }
1061
1062 if (fail) {
1063 for (i = 0; i < ansi_buf_size; ++i)
1064 parse_putc(ansi_buf[i]);
1065 ansi_buf_size = 0;
1066 return;
1067 }
1068
1069 if (flush) {
1070 if (!ansi_cursor_hidden)
1071 CURSOR_OFF;
1072 ansi_buf_size = 0;
1073 switch (cchar) {
1074 case 'A':
1075 /* move cursor num1 rows up */
1076 console_cursor_up(num1);
1077 break;
1078 case 'B':
1079 /* move cursor num1 rows down */
1080 console_cursor_down(num1);
1081 break;
1082 case 'C':
1083 /* move cursor num1 columns forward */
1084 console_cursor_right(num1);
1085 break;
1086 case 'D':
1087 /* move cursor num1 columns back */
1088 console_cursor_left(num1);
1089 break;
1090 case 'E':
1091 /* move cursor num1 rows up at begin of row */
1092 console_previousline(num1);
1093 break;
1094 case 'F':
1095 /* move cursor num1 rows down at begin of row */
1096 console_newline(num1);
1097 break;
1098 case 'G':
1099 /* move cursor to column num1 */
1100 console_cursor_set_position(-1, num1-1);
1101 break;
1102 case 'H':
1103 /* move cursor to row num1, column num2 */
1104 console_cursor_set_position(num1-1, num2-1);
1105 break;
1106 case 'J':
1107 /* clear console and move cursor to 0, 0 */
1108 console_clear();
1109 console_cursor_set_position(0, 0);
1110 break;
1111 case 'K':
1112 /* clear line */
1113 if (num1 == 0)
1114 console_clear_line(console_row,
1115 console_col,
1116 CONSOLE_COLS-1);
1117 else if (num1 == 1)
1118 console_clear_line(console_row,
1119 0, console_col);
1120 else
1121 console_clear_line(console_row,
1122 0, CONSOLE_COLS-1);
1123 break;
1124 case 'h':
1125 ansi_cursor_hidden = 0;
1126 break;
1127 case 'l':
1128 ansi_cursor_hidden = 1;
1129 break;
1130 case 'm':
1131 if (num1 == 0) { /* reset swapped colors */
1132 if (ansi_colors_need_revert) {
1133 console_swap_colors();
1134 ansi_colors_need_revert = 0;
1135 }
1136 } else if (num1 == 7) { /* once swap colors */
1137 if (!ansi_colors_need_revert) {
1138 console_swap_colors();
1139 ansi_colors_need_revert = 1;
1140 }
1141 }
1142 break;
1143 }
1144 if (!ansi_cursor_hidden)
1145 CURSOR_SET;
1146 }
1147 } else {
1148 parse_putc(c);
1149 }
1150#else
1151 parse_putc(c);
1152#endif
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001153 if (cfb_do_flush_cache)
1154 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabi65618632010-08-27 15:45:47 -05001155}
wdenkc6097192002-11-03 00:24:07 +00001156
Jeroen Hofstee654f8d02014-10-08 22:57:44 +02001157static void video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001158{
Soeren Mochd37e96e2014-10-24 16:33:30 +02001159 int flush = cfb_do_flush_cache;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001160 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +00001161
Soeren Mochd37e96e2014-10-24 16:33:30 +02001162 /* temporarily disable cache flush */
1163 cfb_do_flush_cache = 0;
1164
wdenk4b248f32004-03-14 16:51:43 +00001165 while (count--)
Simon Glass709ea542014-07-23 06:54:59 -06001166 video_putc(dev, *s++);
Soeren Mochd37e96e2014-10-24 16:33:30 +02001167
1168 if (flush) {
1169 cfb_do_flush_cache = flush;
1170 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1171 }
wdenkc6097192002-11-03 00:24:07 +00001172}
1173
Anatolij Gustschin10543822010-05-01 22:21:09 +02001174/*
1175 * Do not enforce drivers (or board code) to provide empty
1176 * video_set_lut() if they do not support 8 bpp format.
1177 * Implement weak default function instead.
1178 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02001179__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001180 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +02001181{
1182}
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001183
Jon Loeliger07d38a12007-07-09 17:30:01 -05001184#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +00001185
1186#define FILL_8BIT_332RGB(r,g,b) { \
1187 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1188 fb ++; \
1189}
1190
1191#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001192 *(unsigned short *)fb = \
1193 SWAP16((unsigned short)(((r>>3)<<10) | \
1194 ((g>>3)<<5) | \
1195 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001196 fb += 2; \
1197}
1198
1199#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001200 *(unsigned short *)fb = \
1201 SWAP16((unsigned short)((((r)>>3)<<11)| \
1202 (((g)>>2)<<5) | \
1203 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001204 fb += 2; \
1205}
1206
1207#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001208 *(unsigned long *)fb = \
1209 SWAP32((unsigned long)(((r<<16) | \
1210 (g<<8) | \
1211 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001212 fb += 4; \
1213}
1214
1215#ifdef VIDEO_FB_LITTLE_ENDIAN
1216#define FILL_24BIT_888RGB(r,g,b) { \
1217 fb[0] = b; \
1218 fb[1] = g; \
1219 fb[2] = r; \
1220 fb += 3; \
1221}
1222#else
1223#define FILL_24BIT_888RGB(r,g,b) { \
1224 fb[0] = r; \
1225 fb[1] = g; \
1226 fb[2] = b; \
1227 fb += 3; \
1228}
1229#endif
1230
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001231#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001232static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001233{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001234 ushort *dst = (ushort *) fb;
1235 ushort color = (ushort) (((r >> 3) << 10) |
1236 ((g >> 3) << 5) |
1237 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001238 if (x & 1)
1239 *(--dst) = color;
1240 else
1241 *(++dst) = color;
1242}
1243#endif
wdenk4b248f32004-03-14 16:51:43 +00001244
1245/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001246 * RLE8 bitmap support
1247 */
1248
1249#ifdef CONFIG_VIDEO_BMP_RLE8
1250/* Pre-calculated color table entry */
1251struct palette {
1252 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001253 unsigned short w; /* word */
1254 unsigned int dw; /* double word */
1255 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001256};
1257
1258/*
1259 * Helper to draw encoded/unencoded run.
1260 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001261static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1262 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001263{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001264 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001265 int *off;
1266 int enc_off = 1;
1267 int i;
1268
1269 /*
1270 * Setup offset of the color index in the bitmap.
1271 * Color index of encoded run is at offset 1.
1272 */
1273 off = enc ? &enc_off : &i;
1274
1275 switch (VIDEO_DATA_FORMAT) {
1276 case GDF__8BIT_INDEX:
1277 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001278 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001279 break;
1280 case GDF_15BIT_555RGB:
1281 case GDF_16BIT_565RGB:
1282 /* differences handled while pre-calculating palette */
1283 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001284 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001285 addr += 2;
1286 }
1287 break;
1288 case GDF_32BIT_X888RGB:
1289 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001290 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001291 addr += 4;
1292 }
1293 break;
1294 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001295 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001296}
1297
Simon Glass1c3dbe52015-05-13 07:02:27 -06001298static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001299 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001300{
1301 unsigned char *bm;
1302 unsigned char *fbp;
1303 unsigned int cnt, runlen;
1304 int decode = 1;
1305 int x, y, bpp, i, ncolors;
1306 struct palette p[256];
Simon Glass1c3dbe52015-05-13 07:02:27 -06001307 struct bmp_color_table_entry cte;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001308 int green_shift, red_off;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001309 int limit = VIDEO_COLS * VIDEO_ROWS;
1310 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001311
1312 x = 0;
1313 y = __le32_to_cpu(img->header.height) - 1;
1314 ncolors = __le32_to_cpu(img->header.colors_used);
1315 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001316 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1317 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001318
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001319 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001320
1321 /* pre-calculate and setup palette */
1322 switch (VIDEO_DATA_FORMAT) {
1323 case GDF__8BIT_INDEX:
1324 for (i = 0; i < ncolors; i++) {
1325 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001326 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001327 }
1328 break;
1329 case GDF_15BIT_555RGB:
1330 case GDF_16BIT_565RGB:
1331 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1332 green_shift = 3;
1333 red_off = 10;
1334 } else {
1335 green_shift = 2;
1336 red_off = 11;
1337 }
1338 for (i = 0; i < ncolors; i++) {
1339 cte = img->color_table[i];
1340 p[i].ce.w = SWAP16((unsigned short)
1341 (((cte.red >> 3) << red_off) |
1342 ((cte.green >> green_shift) << 5) |
1343 cte.blue >> 3));
1344 }
1345 break;
1346 case GDF_32BIT_X888RGB:
1347 for (i = 0; i < ncolors; i++) {
1348 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001349 p[i].ce.dw = SWAP32((cte.red << 16) |
1350 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001351 cte.blue);
1352 }
1353 break;
1354 default:
1355 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001356 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001357 return -1;
1358 }
1359
1360 while (decode) {
1361 switch (bm[0]) {
1362 case 0:
1363 switch (bm[1]) {
1364 case 0:
1365 /* scan line end marker */
1366 bm += 2;
1367 x = 0;
1368 y--;
1369 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001370 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001371 (((y + yoff) * VIDEO_COLS) +
1372 xoff) * bpp);
1373 continue;
1374 case 1:
1375 /* end of bitmap data marker */
1376 decode = 0;
1377 break;
1378 case 2:
1379 /* run offset marker */
1380 x += bm[2];
1381 y -= bm[3];
1382 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001383 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001384 (((y + yoff) * VIDEO_COLS) +
1385 x + xoff) * bpp);
1386 bm += 4;
1387 break;
1388 default:
1389 /* unencoded run */
1390 cnt = bm[1];
1391 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001392 pixels += cnt;
1393 if (pixels > limit)
1394 goto error;
1395
Anatolij Gustschind5011762010-03-15 14:50:25 +01001396 bm += 2;
1397 if (y < height) {
1398 if (x >= width) {
1399 x += runlen;
1400 goto next_run;
1401 }
1402 if (x + runlen > width)
1403 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001404 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001405 x += runlen;
1406 }
1407next_run:
1408 bm += runlen;
1409 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001410 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001411 }
1412 break;
1413 default:
1414 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001415 cnt = bm[0];
1416 runlen = cnt;
1417 pixels += cnt;
1418 if (pixels > limit)
1419 goto error;
1420
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001421 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001422 if (x >= width) {
1423 x += runlen;
1424 bm += 2;
1425 continue;
1426 }
1427 if (x + runlen > width)
1428 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001429 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001430 x += runlen;
1431 }
1432 bm += 2;
1433 break;
1434 }
1435 }
1436 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001437error:
1438 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1439 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001440}
1441#endif
1442
1443/*
wdenk4b248f32004-03-14 16:51:43 +00001444 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001445 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001446int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001447{
1448 ushort xcount, ycount;
1449 uchar *fb;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001450 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenk4b248f32004-03-14 16:51:43 +00001451 uchar *bmap;
1452 ushort padded_line;
1453 unsigned long width, height, bpp;
1454 unsigned colors;
1455 unsigned long compression;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001456 struct bmp_color_table_entry cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001457
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001458#ifdef CONFIG_VIDEO_BMP_GZIP
1459 unsigned char *dst = NULL;
1460 ulong len;
1461#endif
wdenk4b248f32004-03-14 16:51:43 +00001462
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001463 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001464
1465 if (!((bmp->header.signature[0] == 'B') &&
1466 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001467
1468#ifdef CONFIG_VIDEO_BMP_GZIP
1469 /*
1470 * Could be a gzipped bmp image, try to decrompress...
1471 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001472 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1473 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001474 if (dst == NULL) {
1475 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001476 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001477 }
Eric Nelson5ca05c82014-03-08 07:55:52 -07001478 /*
1479 * NB: we need to force offset of +2
1480 * See doc/README.displaying-bmps
1481 */
1482 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001483 (uchar *) bmp_image,
1484 &len) != 0) {
1485 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1486 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001487 free(dst);
1488 return 1;
1489 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001490 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001491 printf("Image could be truncated "
1492 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001493 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001494
1495 /*
1496 * Set addr to decompressed image
1497 */
Simon Glass1c3dbe52015-05-13 07:02:27 -06001498 bmp = (struct bmp_image *)(dst+2);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001499
1500 if (!((bmp->header.signature[0] == 'B') &&
1501 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001502 printf("Error: no valid bmp.gz image at %lx\n",
1503 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001504 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001505 return 1;
1506 }
1507#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001508 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001509 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001510#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001511 }
1512
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001513 width = le32_to_cpu(bmp->header.width);
1514 height = le32_to_cpu(bmp->header.height);
1515 bpp = le16_to_cpu(bmp->header.bit_count);
1516 colors = le32_to_cpu(bmp->header.colors_used);
1517 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001518
Marek Vasut68da5b12011-10-21 14:17:04 +00001519 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001520 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001521
Anatolij Gustschind5011762010-03-15 14:50:25 +01001522 if (compression != BMP_BI_RGB
1523#ifdef CONFIG_VIDEO_BMP_RLE8
1524 && compression != BMP_BI_RLE8
1525#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001526 ) {
1527 printf("Error: compression type %ld not supported\n",
1528 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001529#ifdef CONFIG_VIDEO_BMP_GZIP
1530 if (dst)
1531 free(dst);
1532#endif
wdenk4b248f32004-03-14 16:51:43 +00001533 return 1;
1534 }
1535
1536 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1537
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001538#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1539 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001540 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001541 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001542 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001543
1544 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001545 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001546 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001547 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001548#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1549
Matthias Weisseracf3baa2013-02-15 03:35:12 +00001550 /*
1551 * Just ignore elements which are completely beyond screen
1552 * dimensions.
1553 */
1554 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1555 return 0;
1556
wdenk4b248f32004-03-14 16:51:43 +00001557 if ((x + width) > VIDEO_VISIBLE_COLS)
1558 width = VIDEO_VISIBLE_COLS - x;
1559 if ((y + height) > VIDEO_VISIBLE_ROWS)
1560 height = VIDEO_VISIBLE_ROWS - y;
1561
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001562 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001563 fb = (uchar *) (video_fb_address +
1564 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1565 x * VIDEO_PIXEL_SIZE);
1566
Anatolij Gustschind5011762010-03-15 14:50:25 +01001567#ifdef CONFIG_VIDEO_BMP_RLE8
1568 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001569 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001570 }
1571#endif
1572
Timur Tabi68f66182010-08-23 16:58:00 -05001573 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001574 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001575 case 4:
1576 padded_line -= width / 2;
1577 ycount = height;
1578
1579 switch (VIDEO_DATA_FORMAT) {
1580 case GDF_32BIT_X888RGB:
1581 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001582 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001583 /*
1584 * Don't assume that 'width' is an
1585 * even number
1586 */
1587 for (xcount = 0; xcount < width; xcount++) {
1588 uchar idx;
1589
1590 if (xcount & 1) {
1591 idx = *bmap & 0xF;
1592 bmap++;
1593 } else
1594 idx = *bmap >> 4;
1595 cte = bmp->color_table[idx];
1596 FILL_32BIT_X888RGB(cte.red, cte.green,
1597 cte.blue);
1598 }
1599 bmap += padded_line;
1600 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001601 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001602 }
1603 break;
1604 default:
1605 puts("4bpp bitmap unsupported with current "
1606 "video mode\n");
1607 break;
1608 }
1609 break;
1610
wdenk4b248f32004-03-14 16:51:43 +00001611 case 8:
1612 padded_line -= width;
1613 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001614 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001615 for (xcount = 0; xcount < colors; ++xcount) {
1616 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001617 video_set_lut(xcount, cte.red, cte.green,
1618 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001619 }
1620 }
1621 ycount = height;
1622 switch (VIDEO_DATA_FORMAT) {
1623 case GDF__8BIT_INDEX:
1624 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001625 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001626 xcount = width;
1627 while (xcount--) {
1628 *fb++ = *bmap++;
1629 }
1630 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001631 fb -= (VIDEO_VISIBLE_COLS + width) *
1632 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001633 }
1634 break;
1635 case GDF__8BIT_332RGB:
1636 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001637 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001638 xcount = width;
1639 while (xcount--) {
1640 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001641 FILL_8BIT_332RGB(cte.red, cte.green,
1642 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001643 }
1644 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001645 fb -= (VIDEO_VISIBLE_COLS + width) *
1646 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001647 }
1648 break;
1649 case GDF_15BIT_555RGB:
1650 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001651#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1652 int xpos = x;
1653#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001654 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001655 xcount = width;
1656 while (xcount--) {
1657 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001658#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001659 fill_555rgb_pswap(fb, xpos++, cte.red,
1660 cte.green,
1661 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001662 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001663#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001664 FILL_15BIT_555RGB(cte.red, cte.green,
1665 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001666#endif
wdenk4b248f32004-03-14 16:51:43 +00001667 }
1668 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001669 fb -= (VIDEO_VISIBLE_COLS + width) *
1670 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001671 }
1672 break;
1673 case GDF_16BIT_565RGB:
1674 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001675 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001676 xcount = width;
1677 while (xcount--) {
1678 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001679 FILL_16BIT_565RGB(cte.red, cte.green,
1680 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001681 }
1682 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001683 fb -= (VIDEO_VISIBLE_COLS + width) *
1684 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001685 }
1686 break;
1687 case GDF_32BIT_X888RGB:
1688 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001689 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001690 xcount = width;
1691 while (xcount--) {
1692 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001693 FILL_32BIT_X888RGB(cte.red, cte.green,
1694 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001695 }
1696 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001697 fb -= (VIDEO_VISIBLE_COLS + width) *
1698 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001699 }
1700 break;
1701 case GDF_24BIT_888RGB:
1702 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001703 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001704 xcount = width;
1705 while (xcount--) {
1706 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001707 FILL_24BIT_888RGB(cte.red, cte.green,
1708 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001709 }
1710 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001711 fb -= (VIDEO_VISIBLE_COLS + width) *
1712 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001713 }
1714 break;
1715 }
1716 break;
1717 case 24:
1718 padded_line -= 3 * width;
1719 ycount = height;
1720 switch (VIDEO_DATA_FORMAT) {
1721 case GDF__8BIT_332RGB:
1722 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001723 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001724 xcount = width;
1725 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001726 FILL_8BIT_332RGB(bmap[2], bmap[1],
1727 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001728 bmap += 3;
1729 }
1730 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001731 fb -= (VIDEO_VISIBLE_COLS + width) *
1732 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001733 }
1734 break;
1735 case GDF_15BIT_555RGB:
1736 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001737#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1738 int xpos = x;
1739#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001740 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001741 xcount = width;
1742 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001743#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001744 fill_555rgb_pswap(fb, xpos++, bmap[2],
1745 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001746 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001747#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001748 FILL_15BIT_555RGB(bmap[2], bmap[1],
1749 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001750#endif
wdenk4b248f32004-03-14 16:51:43 +00001751 bmap += 3;
1752 }
1753 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001754 fb -= (VIDEO_VISIBLE_COLS + width) *
1755 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001756 }
1757 break;
1758 case GDF_16BIT_565RGB:
1759 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001760 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001761 xcount = width;
1762 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001763 FILL_16BIT_565RGB(bmap[2], bmap[1],
1764 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001765 bmap += 3;
1766 }
1767 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001768 fb -= (VIDEO_VISIBLE_COLS + width) *
1769 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001770 }
1771 break;
1772 case GDF_32BIT_X888RGB:
1773 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001774 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001775 xcount = width;
1776 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001777 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1778 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001779 bmap += 3;
1780 }
1781 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001782 fb -= (VIDEO_VISIBLE_COLS + width) *
1783 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001784 }
1785 break;
1786 case GDF_24BIT_888RGB:
1787 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001788 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001789 xcount = width;
1790 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001791 FILL_24BIT_888RGB(bmap[2], bmap[1],
1792 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001793 bmap += 3;
1794 }
1795 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001796 fb -= (VIDEO_VISIBLE_COLS + width) *
1797 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001798 }
1799 break;
1800 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001801 printf("Error: 24 bits/pixel bitmap incompatible "
1802 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001803 break;
1804 }
1805 break;
1806 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001807 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1808 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001809 break;
1810 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001811
1812#ifdef CONFIG_VIDEO_BMP_GZIP
1813 if (dst) {
1814 free(dst);
1815 }
1816#endif
1817
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001818 if (cfb_do_flush_cache)
1819 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk4b248f32004-03-14 16:51:43 +00001820 return (0);
1821}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001822#endif
wdenk4b248f32004-03-14 16:51:43 +00001823
wdenk4b248f32004-03-14 16:51:43 +00001824
wdenkc6097192002-11-03 00:24:07 +00001825#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001826static int video_logo_xpos;
1827static int video_logo_ypos;
1828
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001829static void plot_logo_or_black(void *screen, int width, int x, int y, \
1830 int black);
1831
1832static void logo_plot(void *screen, int width, int x, int y)
1833{
1834 plot_logo_or_black(screen, width, x, y, 0);
1835}
1836
1837static void logo_black(void)
1838{
1839 plot_logo_or_black(video_fb_address, \
1840 VIDEO_COLS, \
1841 video_logo_xpos, \
1842 video_logo_ypos, \
1843 1);
1844}
1845
1846static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1847{
1848 if (argc != 1)
1849 return cmd_usage(cmdtp);
1850
1851 logo_black();
1852 return 0;
1853}
1854
1855U_BOOT_CMD(
1856 clrlogo, 1, 0, do_clrlogo,
1857 "fill the boot logo area with black",
1858 " "
1859 );
1860
1861static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001862{
wdenkc6097192002-11-03 00:24:07 +00001863
wdenk4b248f32004-03-14 16:51:43 +00001864 int xcount, i;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001865 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001866 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001867 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1868 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001869 unsigned char *dest;
1870
1871#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1872 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001873 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001874 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001875 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001876
1877 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001878 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001879 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001880 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001881#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1882
1883 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001884
1885#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001886 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001887
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001888 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001889 logo_red = malloc(BMP_LOGO_COLORS);
1890 logo_green = malloc(BMP_LOGO_COLORS);
1891 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001892 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001893 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1894 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1895 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1896 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1897 }
wdenka6c7ad22002-12-03 21:28:10 +00001898#else
wdenk4b248f32004-03-14 16:51:43 +00001899 source = linux_logo;
1900 logo_red = linux_logo_red;
1901 logo_green = linux_logo_green;
1902 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001903#endif
wdenk8bde7f72003-06-27 21:31:46 +00001904
wdenk4b248f32004-03-14 16:51:43 +00001905 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1906 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001907 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1908 logo_red[i], logo_green[i],
1909 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001910 }
wdenk8bde7f72003-06-27 21:31:46 +00001911 }
wdenkc6097192002-11-03 00:24:07 +00001912
wdenk4b248f32004-03-14 16:51:43 +00001913 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001914#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1915 int xpos = x;
1916#endif
wdenk4b248f32004-03-14 16:51:43 +00001917 xcount = VIDEO_LOGO_WIDTH;
1918 while (xcount--) {
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001919 if (black) {
1920 r = 0x00;
1921 g = 0x00;
1922 b = 0x00;
1923 } else {
1924 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1925 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1926 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1927 }
wdenk8bde7f72003-06-27 21:31:46 +00001928
wdenk4b248f32004-03-14 16:51:43 +00001929 switch (VIDEO_DATA_FORMAT) {
1930 case GDF__8BIT_INDEX:
1931 *dest = *source;
1932 break;
1933 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001934 *dest = ((r >> 5) << 5) |
1935 ((g >> 5) << 2) |
1936 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001937 break;
1938 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001939#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001940 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001941#else
wdenk4b248f32004-03-14 16:51:43 +00001942 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001943 SWAP16((unsigned short) (
1944 ((r >> 3) << 10) |
1945 ((g >> 3) << 5) |
1946 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001947#endif
wdenk4b248f32004-03-14 16:51:43 +00001948 break;
1949 case GDF_16BIT_565RGB:
1950 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001951 SWAP16((unsigned short) (
1952 ((r >> 3) << 11) |
1953 ((g >> 2) << 5) |
1954 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001955 break;
1956 case GDF_32BIT_X888RGB:
1957 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001958 SWAP32((unsigned long) (
1959 (r << 16) |
1960 (g << 8) |
1961 b));
wdenk4b248f32004-03-14 16:51:43 +00001962 break;
1963 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001964#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001965 dest[0] = b;
1966 dest[1] = g;
1967 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001968#else
wdenk4b248f32004-03-14 16:51:43 +00001969 dest[0] = r;
1970 dest[1] = g;
1971 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001972#endif
wdenk4b248f32004-03-14 16:51:43 +00001973 break;
1974 }
1975 source++;
1976 dest += VIDEO_PIXEL_SIZE;
1977 }
1978 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001979 }
wdenka6c7ad22002-12-03 21:28:10 +00001980#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001981 free(logo_red);
1982 free(logo_green);
1983 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001984#endif
wdenkc6097192002-11-03 00:24:07 +00001985}
1986
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001987static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001988{
wdenk4b248f32004-03-14 16:51:43 +00001989 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001990 int space, len;
1991 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001992 __maybe_unused ulong addr;
1993 __maybe_unused char *s;
wdenkc6097192002-11-03 00:24:07 +00001994
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001995 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001996
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001997#ifdef CONFIG_SPLASH_SCREEN
1998 s = getenv("splashimage");
1999 if (s != NULL) {
Robert Winklerdd4425e2013-06-17 11:31:29 -07002000 splash_screen_prepare();
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002001 addr = simple_strtoul(s, NULL, 16);
2002
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002003 if (video_display_bitmap(addr,
2004 video_logo_xpos,
2005 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002006 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00002007 return ((void *) (video_fb_address));
2008 }
2009 }
2010#endif /* CONFIG_SPLASH_SCREEN */
2011
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002012 logo_plot(video_fb_address, VIDEO_COLS,
2013 video_logo_xpos, video_logo_ypos);
2014
2015#ifdef CONFIG_SPLASH_SCREEN_ALIGN
2016 /*
2017 * when using splashpos for video_logo, skip any info
2018 * output on video console if the logo is not at 0,0
2019 */
2020 if (video_logo_xpos || video_logo_ypos) {
2021 /*
2022 * video_logo_height is used in text and cursor offset
2023 * calculations. Since the console is below the logo,
2024 * we need to adjust the logo height
2025 */
2026 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09002027 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002028 VIDEO_LOGO_HEIGHT) / 2);
2029 else if (video_logo_ypos > 0)
2030 video_logo_height += video_logo_ypos;
2031
2032 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2033 }
2034#endif
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002035 if (board_cfb_skip())
2036 return 0;
wdenk4b248f32004-03-14 16:51:43 +00002037
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002038 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002039
2040 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2041 len = strlen(info);
2042
2043 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002044 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2045 (uchar *) info, space);
2046 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2047 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2048 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002049 y_off = 1;
2050 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002051 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00002052
2053#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00002054 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002055 int i, n =
2056 ((video_logo_height -
2057 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002058
wdenk4b248f32004-03-14 16:51:43 +00002059 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002060 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002061 if (!*info)
2062 continue;
2063
2064 len = strlen(info);
2065 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002066 video_drawchars(VIDEO_INFO_X,
2067 VIDEO_INFO_Y +
2068 (i + y_off) *
2069 VIDEO_FONT_HEIGHT,
2070 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002071 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002072 video_drawchars(VIDEO_INFO_X +
2073 VIDEO_FONT_WIDTH,
2074 VIDEO_INFO_Y +
2075 (i + y_off) *
2076 VIDEO_FONT_HEIGHT,
2077 (uchar *) info + space,
2078 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002079 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002080 video_drawstring(VIDEO_INFO_X,
2081 VIDEO_INFO_Y +
2082 (i + y_off) *
2083 VIDEO_FONT_HEIGHT,
2084 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002085 }
wdenk4b248f32004-03-14 16:51:43 +00002086 }
2087 }
wdenkc6097192002-11-03 00:24:07 +00002088#endif
2089
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002090 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002091}
2092#endif
2093
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002094static int cfb_fb_is_in_dram(void)
2095{
2096 bd_t *bd = gd->bd;
2097#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2098defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2099 ulong start, end;
2100 int i;
2101
2102 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2103 start = bd->bi_dram[i].start;
2104 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2105 if ((ulong)video_fb_address >= start &&
2106 (ulong)video_fb_address < end)
2107 return 1;
2108 }
2109#else
2110 if ((ulong)video_fb_address >= bd->bi_memstart &&
2111 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2112 return 1;
2113#endif
2114 return 0;
2115}
2116
Heiko Schocher45ae2542013-10-22 11:06:06 +02002117void video_clear(void)
2118{
2119 if (!video_fb_address)
2120 return;
2121#ifdef VIDEO_HW_RECTFILL
2122 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2123 0, /* dest pos x */
2124 0, /* dest pos y */
2125 VIDEO_VISIBLE_COLS, /* frame width */
2126 VIDEO_VISIBLE_ROWS, /* frame height */
2127 bgx /* fill color */
2128 );
2129#else
2130 memsetl(video_fb_address,
2131 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2132#endif
2133}
2134
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002135static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002136{
wdenk4b248f32004-03-14 16:51:43 +00002137 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002138
Wolfgang Denk57912932011-07-30 12:48:09 +00002139 pGD = video_hw_init();
2140 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00002141 return -1;
wdenkc6097192002-11-03 00:24:07 +00002142
wdenk4b248f32004-03-14 16:51:43 +00002143 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002144#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002145 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002146#endif
2147
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002148 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2149
wdenk4b248f32004-03-14 16:51:43 +00002150 /* Init drawing pats */
2151 switch (VIDEO_DATA_FORMAT) {
2152 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002153 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2154 CONSOLE_FG_COL);
2155 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2156 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00002157 fgx = 0x01010101;
2158 bgx = 0x00000000;
2159 break;
2160 case GDF__8BIT_332RGB:
2161 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002162 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2163 CONSOLE_FG_COL >> 6);
2164 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2165 color8;
wdenk4b248f32004-03-14 16:51:43 +00002166 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002167 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2168 CONSOLE_BG_COL >> 6);
2169 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2170 color8;
wdenk4b248f32004-03-14 16:51:43 +00002171 break;
2172 case GDF_15BIT_555RGB:
2173 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002174 ((CONSOLE_FG_COL >> 3) << 21) |
2175 ((CONSOLE_FG_COL >> 3) << 16) |
2176 ((CONSOLE_FG_COL >> 3) << 10) |
2177 ((CONSOLE_FG_COL >> 3) << 5) |
2178 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002179 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002180 ((CONSOLE_BG_COL >> 3) << 21) |
2181 ((CONSOLE_BG_COL >> 3) << 16) |
2182 ((CONSOLE_BG_COL >> 3) << 10) |
2183 ((CONSOLE_BG_COL >> 3) << 5) |
2184 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002185 break;
2186 case GDF_16BIT_565RGB:
2187 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002188 ((CONSOLE_FG_COL >> 2) << 21) |
2189 ((CONSOLE_FG_COL >> 3) << 16) |
2190 ((CONSOLE_FG_COL >> 3) << 11) |
2191 ((CONSOLE_FG_COL >> 2) << 5) |
2192 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002193 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002194 ((CONSOLE_BG_COL >> 2) << 21) |
2195 ((CONSOLE_BG_COL >> 3) << 16) |
2196 ((CONSOLE_BG_COL >> 3) << 11) |
2197 ((CONSOLE_BG_COL >> 2) << 5) |
2198 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002199 break;
2200 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002201 fgx = (CONSOLE_FG_COL << 16) |
2202 (CONSOLE_FG_COL << 8) |
2203 CONSOLE_FG_COL;
2204 bgx = (CONSOLE_BG_COL << 16) |
2205 (CONSOLE_BG_COL << 8) |
2206 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002207 break;
2208 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002209 fgx = (CONSOLE_FG_COL << 24) |
2210 (CONSOLE_FG_COL << 16) |
2211 (CONSOLE_FG_COL << 8) |
2212 CONSOLE_FG_COL;
2213 bgx = (CONSOLE_BG_COL << 24) |
2214 (CONSOLE_BG_COL << 16) |
2215 (CONSOLE_BG_COL << 8) |
2216 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002217 break;
2218 }
2219 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002220
Heiko Schocher45ae2542013-10-22 11:06:06 +02002221 video_clear();
2222
wdenkc6097192002-11-03 00:24:07 +00002223#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00002224 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002225 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002226 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002227#else
wdenk4b248f32004-03-14 16:51:43 +00002228 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002229#endif
2230
wdenk4b248f32004-03-14 16:51:43 +00002231 /* Initialize the console */
2232 console_col = 0;
2233 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002234
Eric Nelsondb0d47d2013-05-06 14:27:28 +02002235 if (cfb_do_flush_cache)
2236 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2237
wdenk4b248f32004-03-14 16:51:43 +00002238 return 0;
wdenkc6097192002-11-03 00:24:07 +00002239}
2240
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002241/*
2242 * Implement a weak default function for boards that optionally
2243 * need to skip the video initialization.
2244 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02002245__weak int board_video_skip(void)
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002246{
2247 /* As default, don't skip test */
2248 return 0;
2249}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002250
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002251int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002252{
wdenk4b248f32004-03-14 16:51:43 +00002253 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02002254 struct stdio_dev console_dev;
Simon Glass5692ccf2015-03-02 12:40:50 -07002255 bool have_keyboard;
wdenkc6097192002-11-03 00:24:07 +00002256
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002257 /* Check if video initialization should be skipped */
2258 if (board_video_skip())
2259 return 0;
2260
wdenk81050922004-07-11 20:04:51 +00002261 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002262 skip_dev_init = (video_init() == -1);
wdenk81050922004-07-11 20:04:51 +00002263
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002264 if (board_cfb_skip())
2265 return 0;
2266
Simon Glass5692ccf2015-03-02 12:40:50 -07002267#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2268 have_keyboard = false;
2269#elif defined(CONFIG_OF_CONTROL)
2270 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2271 "u-boot,no-keyboard");
2272#else
2273 have_keyboard = true;
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002274#endif
Simon Glass5692ccf2015-03-02 12:40:50 -07002275 if (have_keyboard) {
2276 debug("KBD: Keyboard init ...\n");
2277#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2278 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2279#endif
2280 }
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002281 if (skip_dev_init)
2282 return 0;
wdenkc6097192002-11-03 00:24:07 +00002283
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002284 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002285 memset(&console_dev, 0, sizeof(console_dev));
2286 strcpy(console_dev.name, "vga");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002287 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2288 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2289 console_dev.putc = video_putc; /* 'putc' function */
2290 console_dev.puts = video_puts; /* 'puts' function */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002291
2292#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Simon Glass5692ccf2015-03-02 12:40:50 -07002293 if (have_keyboard) {
2294 /* Also init console device */
2295 console_dev.flags |= DEV_FLAGS_INPUT;
2296 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2297 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2298 }
2299#endif
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002300
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002301 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002302 return 0;
2303
2304 /* Return success */
2305 return 1;
wdenkc6097192002-11-03 00:24:07 +00002306}
Stefan Reinauerc20ee072012-09-28 15:11:12 +00002307
2308void video_position_cursor(unsigned col, unsigned row)
2309{
2310 console_col = min(col, CONSOLE_COLS - 1);
2311 console_row = min(row, CONSOLE_ROWS - 1);
2312}
2313
2314int video_get_pixel_width(void)
2315{
2316 return VIDEO_VISIBLE_COLS;
2317}
2318
2319int video_get_pixel_height(void)
2320{
2321 return VIDEO_VISIBLE_ROWS;
2322}
2323
2324int video_get_screen_rows(void)
2325{
2326 return CONSOLE_ROWS;
2327}
2328
2329int video_get_screen_columns(void)
2330{
2331 return CONSOLE_COLS;
2332}