blob: e5c077e4f5227367961d3f994b16c61a70a0055d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00002/*
3 * (C) Copyright 2002 ELTEC Elektronik AG
4 * Frank Gottschling <fgottschling@eltec.de>
wdenkc6097192002-11-03 00:24:07 +00005 */
6
7/*
8 * cfb_console.c
9 *
10 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
11 *
12 * At the moment only the 8x16 font is tested and the font fore- and
13 * background color is limited to black/white/gray colors. The Linux
14 * logo can be placed in the upper left corner and additional board
Wolfgang Denk64e40d72011-07-29 09:55:27 +000015 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000016 *
Simon Glass39f615e2015-11-11 10:05:47 -070017 * The console driver can use a keyboard interface for character input
18 * but this is deprecated. Only rk51 uses it.
19 *
20 * Character output goes to a memory-mapped video
wdenkc6097192002-11-03 00:24:07 +000021 * framebuffer with little or big-endian organisation.
22 * With environment setting 'console=serial' the console i/o can be
23 * forced to serial port.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000024 *
25 * The driver uses graphic specific defines/parameters/functions:
26 *
27 * (for SMI LynxE graphic chip)
28 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000029 * 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 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000041 * VIDEO_KBD_INIT_FCT - init function for keyboard
42 * VIDEO_TSTC_FCT - keyboard_tstc function
43 * VIDEO_GETC_FCT - keyboard_getc function
44 *
Bastian Ruppert1e681f92012-09-13 22:29:01 +000045 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
46 * Use CONFIG_SPLASH_SCREEN_ALIGN with
47 * environment variable "splashpos" to place
48 * the logo on other position. In this case
49 * no CONSOLE_EXTRA_INFO is possible.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000050 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
51 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
52 * strings that normaly goes to serial
53 * port. This define requires a board
54 * specific function:
55 * video_drawstring (VIDEO_INFO_X,
56 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
57 * info);
58 * that fills a info buffer at i=row.
59 * s.a: board/eltec/bab7xx.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000060 *
61 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
62 * character. No blinking is provided.
63 * Uses the macros CURSOR_SET and
64 * CURSOR_OFF.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000065 */
wdenkc6097192002-11-03 00:24:07 +000066
67#include <common.h>
Simon Glass7b51b572019-08-01 09:46:52 -060068#include <env.h>
Simon Glass5692ccf2015-03-02 12:40:50 -070069#include <fdtdec.h>
Simon Glass0c670fc2019-08-01 09:46:36 -060070#include <gzip.h>
Andreas Bießmann09c2e902011-07-18 20:24:04 +020071#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +000072#include <malloc.h>
Simon Glass0a6eac82016-10-17 20:12:54 -060073#include <video.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +000074#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +000075
Simon Glassc370d382016-10-17 20:12:47 -060076#if defined(CONFIG_VIDEO_MXS)
Marek Vasutfb8ddc22013-04-28 09:20:03 +000077#define VIDEO_FB_16BPP_WORD_SWAP
78#endif
79
Wolfgang Denk64e40d72011-07-29 09:55:27 +000080/*
81 * Defines for the MB862xx driver
82 */
Anatolij Gustschinbed53752008-01-11 14:30:01 +010083#ifdef CONFIG_VIDEO_MB862xx
84
85#ifdef CONFIG_VIDEO_CORALP
86#define VIDEO_FB_LITTLE_ENDIAN
87#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +020088#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +010089#define VIDEO_HW_RECTFILL
90#define VIDEO_HW_BITBLT
91#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +020092#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +010093
Wolfgang Denk64e40d72011-07-29 09:55:27 +000094/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +000095 * Defines for the i.MX31 driver (mx3fb.c)
96 */
Fabio Estevam695af9a2012-05-31 07:23:56 +000097#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger62a22dc2011-10-12 23:16:29 +000098#define VIDEO_FB_16BPP_WORD_SWAP
99#endif
100
101/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000102 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
103 */
wdenkc6097192002-11-03 00:24:07 +0000104#include <video_fb.h>
105
Robert Winklerdd4425e2013-06-17 11:31:29 -0700106#include <splash.h>
107
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000108/*
109 * some Macros
110 */
wdenk4b248f32004-03-14 16:51:43 +0000111#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
112#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
113#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
114#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
115#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000116
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000117/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000118 * Console device
119 */
wdenkc6097192002-11-03 00:24:07 +0000120
121#include <version.h>
122#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200123#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000124#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000125
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500126#if defined(CONFIG_CMD_DATE)
127#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000128#endif
129
Jon Loeliger07d38a12007-07-09 17:30:01 -0500130#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000131#include <watchdog.h>
132#include <bmp_layout.h>
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200133#include <splash.h>
Jon Loeliger07d38a12007-07-09 17:30:01 -0500134#endif
wdenk4b248f32004-03-14 16:51:43 +0000135
Simon Glassa4206572016-10-17 20:12:50 -0600136#if !defined(CONFIG_VIDEO_SW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000137/* no Cursor defined */
138#define CURSOR_ON
139#define CURSOR_OFF
140#define CURSOR_SET
141#endif
142
Simon Glass7fe09332015-10-18 21:17:18 -0600143#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000144void console_cursor(int state);
145
Timur Tabi65618632010-08-27 15:45:47 -0500146#define CURSOR_ON console_cursor(1)
147#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000148#define CURSOR_SET video_set_cursor()
Simon Glass7fe09332015-10-18 21:17:18 -0600149#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000150
wdenk4b248f32004-03-14 16:51:43 +0000151#ifdef CONFIG_VIDEO_LOGO
152#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000153#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000154#include <bmp_logo_data.h>
wdenk4b248f32004-03-14 16:51:43 +0000155#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
156#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
157#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
158#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenka6c7ad22002-12-03 21:28:10 +0000159
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000160#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000161#define LINUX_LOGO_WIDTH 80
162#define LINUX_LOGO_HEIGHT 80
163#define LINUX_LOGO_COLORS 214
164#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000165#define __initdata
166#include <linux_logo.h>
wdenk4b248f32004-03-14 16:51:43 +0000167#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
168#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
169#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
170#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000171#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000172#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
173#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000174#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000175#define VIDEO_LOGO_WIDTH 0
176#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000177#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000178
wdenk4b248f32004-03-14 16:51:43 +0000179#define VIDEO_COLS VIDEO_VISIBLE_COLS
180#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedec67a8762015-08-04 12:15:39 +0200181#ifndef VIDEO_LINE_LEN
182#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
183#endif
184#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenk4b248f32004-03-14 16:51:43 +0000185#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000186
wdenk4b248f32004-03-14 16:51:43 +0000187#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100188#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000189#else
wdenk4b248f32004-03-14 16:51:43 +0000190#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000191#endif
192
wdenk4b248f32004-03-14 16:51:43 +0000193#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
194#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
195#define CONSOLE_ROW_FIRST (video_console_address)
196#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
197#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
198#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass3c0b6682015-01-01 16:17:57 -0700199
200/* By default we scroll by a single line */
201#ifndef CONFIG_CONSOLE_SCROLL_LINES
202#define CONFIG_CONSOLE_SCROLL_LINES 1
203#endif
wdenkc6097192002-11-03 00:24:07 +0000204
205/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000206#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000207#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
208 ((x) >> 8) \
209 )
210#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
211 (((x) & 0x0000ff00) << 8) | \
212 (((x) & 0x00ff0000) >> 8) | \
213 (((x) & 0xff000000) >> 24) \
214 )
215#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
216 (((x) & 0x0000ff00) >> 8) | \
217 (((x) & 0x00ff0000) << 8) | \
218 (((x) & 0xff000000) >> 8) \
219 )
wdenkc6097192002-11-03 00:24:07 +0000220#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000221#define SWAP16(x) (x)
222#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200223#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000224#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500225#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000226#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100227#endif
wdenkc6097192002-11-03 00:24:07 +0000228#endif
229
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200230DECLARE_GLOBAL_DATA_PTR;
231
wdenkc6097192002-11-03 00:24:07 +0000232/* Locals */
233static GraphicDevice *pGD; /* Pointer to Graphic array */
234
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000235static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000236static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000237
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100238static int video_logo_height = VIDEO_LOGO_HEIGHT;
239
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000240static int __maybe_unused cursor_state;
241static int __maybe_unused old_col;
242static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000243
Wolfgang Denk57912932011-07-30 12:48:09 +0000244static int console_col; /* cursor col */
245static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000246
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000247static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000248
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200249static int cfb_do_flush_cache;
250
Pali Rohár33a35bb2012-10-19 13:30:09 +0000251#ifdef CONFIG_CFB_CONSOLE_ANSI
252static char ansi_buf[10];
253static int ansi_buf_size;
254static int ansi_colors_need_revert;
255static int ansi_cursor_hidden;
256#endif
257
wdenkc6097192002-11-03 00:24:07 +0000258static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000259 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
260 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
261 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
262 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
263};
wdenkc6097192002-11-03 00:24:07 +0000264
265static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000266 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
267};
wdenkc6097192002-11-03 00:24:07 +0000268
269static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000270 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
271};
wdenkc6097192002-11-03 00:24:07 +0000272
273static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000274 {0x00000000, 0x00000000, 0x00000000},
275 {0x00000000, 0x00000000, 0x00ffffff},
276 {0x00000000, 0x0000ffff, 0xff000000},
277 {0x00000000, 0x0000ffff, 0xffffffff},
278 {0x000000ff, 0xffff0000, 0x00000000},
279 {0x000000ff, 0xffff0000, 0x00ffffff},
280 {0x000000ff, 0xffffffff, 0xff000000},
281 {0x000000ff, 0xffffffff, 0xffffffff},
282 {0xffffff00, 0x00000000, 0x00000000},
283 {0xffffff00, 0x00000000, 0x00ffffff},
284 {0xffffff00, 0x0000ffff, 0xff000000},
285 {0xffffff00, 0x0000ffff, 0xffffffff},
286 {0xffffffff, 0xffff0000, 0x00000000},
287 {0xffffffff, 0xffff0000, 0x00ffffff},
288 {0xffffffff, 0xffffffff, 0xff000000},
289 {0xffffffff, 0xffffffff, 0xffffffff}
290};
wdenkc6097192002-11-03 00:24:07 +0000291
292static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000293 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
294 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
295 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
296 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
297 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
298 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
299 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
300 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
301 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
302 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
303 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
304 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
305 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
306 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
307 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
308 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
309};
wdenkc6097192002-11-03 00:24:07 +0000310
Heiko Schocher2bc4aa52013-08-03 07:22:53 +0200311/*
312 * Implement a weak default function for boards that optionally
313 * need to skip the cfb initialization.
314 */
315__weak int board_cfb_skip(void)
316{
317 /* As default, don't skip cfb init */
318 return 0;
319}
320
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000321static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000322{
wdenk4b248f32004-03-14 16:51:43 +0000323 u8 *cdat, *dest, *dest0;
324 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000325
wdenk4b248f32004-03-14 16:51:43 +0000326 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
327 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000328
wdenk4b248f32004-03-14 16:51:43 +0000329 switch (VIDEO_DATA_FORMAT) {
330 case GDF__8BIT_INDEX:
331 case GDF__8BIT_332RGB:
332 while (count--) {
333 c = *s;
334 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
335 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000336 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000337 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000338
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000339 ((u32 *) dest)[0] =
340 (video_font_draw_table8[bits >> 4] &
341 eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200342
343 if (VIDEO_FONT_WIDTH == 4)
344 continue;
345
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000346 ((u32 *) dest)[1] =
347 (video_font_draw_table8[bits & 15] &
348 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000349 }
350 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
351 s++;
352 }
353 break;
wdenkc6097192002-11-03 00:24:07 +0000354
wdenk4b248f32004-03-14 16:51:43 +0000355 case GDF_15BIT_555RGB:
356 while (count--) {
357 c = *s;
358 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
359 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000360 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000361 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000362
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000363 ((u32 *) dest)[0] =
364 SHORTSWAP32((video_font_draw_table15
365 [bits >> 6] & eorx) ^
366 bgx);
367 ((u32 *) dest)[1] =
368 SHORTSWAP32((video_font_draw_table15
369 [bits >> 4 & 3] & eorx) ^
370 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200371
372 if (VIDEO_FONT_WIDTH == 4)
373 continue;
374
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000375 ((u32 *) dest)[2] =
376 SHORTSWAP32((video_font_draw_table15
377 [bits >> 2 & 3] & eorx) ^
378 bgx);
379 ((u32 *) dest)[3] =
380 SHORTSWAP32((video_font_draw_table15
381 [bits & 3] & eorx) ^
382 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000383 }
384 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
385 s++;
386 }
387 break;
wdenkc6097192002-11-03 00:24:07 +0000388
wdenk4b248f32004-03-14 16:51:43 +0000389 case GDF_16BIT_565RGB:
390 while (count--) {
391 c = *s;
392 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
393 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000394 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000395 u8 bits = *cdat++;
396
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000397 ((u32 *) dest)[0] =
398 SHORTSWAP32((video_font_draw_table16
399 [bits >> 6] & eorx) ^
400 bgx);
401 ((u32 *) dest)[1] =
402 SHORTSWAP32((video_font_draw_table16
403 [bits >> 4 & 3] & eorx) ^
404 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200405
406 if (VIDEO_FONT_WIDTH == 4)
407 continue;
408
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000409 ((u32 *) dest)[2] =
410 SHORTSWAP32((video_font_draw_table16
411 [bits >> 2 & 3] & eorx) ^
412 bgx);
413 ((u32 *) dest)[3] =
414 SHORTSWAP32((video_font_draw_table16
415 [bits & 3] & eorx) ^
416 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000417 }
418 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
419 s++;
420 }
421 break;
422
423 case GDF_32BIT_X888RGB:
424 while (count--) {
425 c = *s;
426 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
427 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000428 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000429 u8 bits = *cdat++;
430
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000431 ((u32 *) dest)[0] =
432 SWAP32((video_font_draw_table32
433 [bits >> 4][0] & eorx) ^ bgx);
434 ((u32 *) dest)[1] =
435 SWAP32((video_font_draw_table32
436 [bits >> 4][1] & eorx) ^ bgx);
437 ((u32 *) dest)[2] =
438 SWAP32((video_font_draw_table32
439 [bits >> 4][2] & eorx) ^ bgx);
440 ((u32 *) dest)[3] =
441 SWAP32((video_font_draw_table32
442 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200443
444
445 if (VIDEO_FONT_WIDTH == 4)
446 continue;
447
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000448 ((u32 *) dest)[4] =
449 SWAP32((video_font_draw_table32
450 [bits & 15][0] & eorx) ^ bgx);
451 ((u32 *) dest)[5] =
452 SWAP32((video_font_draw_table32
453 [bits & 15][1] & eorx) ^ bgx);
454 ((u32 *) dest)[6] =
455 SWAP32((video_font_draw_table32
456 [bits & 15][2] & eorx) ^ bgx);
457 ((u32 *) dest)[7] =
458 SWAP32((video_font_draw_table32
459 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000460 }
461 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
462 s++;
463 }
464 break;
465
466 case GDF_24BIT_888RGB:
467 while (count--) {
468 c = *s;
469 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
470 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000471 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000472 u8 bits = *cdat++;
473
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000474 ((u32 *) dest)[0] =
475 (video_font_draw_table24[bits >> 4][0]
476 & eorx) ^ bgx;
477 ((u32 *) dest)[1] =
478 (video_font_draw_table24[bits >> 4][1]
479 & eorx) ^ bgx;
480 ((u32 *) dest)[2] =
481 (video_font_draw_table24[bits >> 4][2]
482 & eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200483
484 if (VIDEO_FONT_WIDTH == 4)
485 continue;
486
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000487 ((u32 *) dest)[3] =
488 (video_font_draw_table24[bits & 15][0]
489 & eorx) ^ bgx;
490 ((u32 *) dest)[4] =
491 (video_font_draw_table24[bits & 15][1]
492 & eorx) ^ bgx;
493 ((u32 *) dest)[5] =
494 (video_font_draw_table24[bits & 15][2]
495 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000496 }
497 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
498 s++;
499 }
500 break;
wdenk8bde7f72003-06-27 21:31:46 +0000501 }
wdenkc6097192002-11-03 00:24:07 +0000502}
503
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000504static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000505{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000506 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000507}
508
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000509static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000510{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000511 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000512}
513
Simon Glass7fe09332015-10-18 21:17:18 -0600514#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000515static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000516{
Gabe Black03d31fc2011-11-30 13:50:50 +0000517 if (cursor_state)
518 console_cursor(0);
519 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000520}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000521
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000522static void video_invertchar(int xx, int yy)
523{
524 int firstx = xx * VIDEO_PIXEL_SIZE;
525 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
526 int firsty = yy * VIDEO_LINE_LEN;
527 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
528 int x, y;
529 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
530 for (x = firstx; x < lastx; x++) {
531 u8 *dest = (u8 *)(video_fb_address) + x + y;
532 *dest = ~*dest;
533 }
534 }
535}
Gabe Black03d31fc2011-11-30 13:50:50 +0000536
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000537void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000538{
Gabe Black03d31fc2011-11-30 13:50:50 +0000539 if (cursor_state != state) {
540 if (cursor_state) {
541 /* turn off the cursor */
542 video_invertchar(old_col * VIDEO_FONT_WIDTH,
543 old_row * VIDEO_FONT_HEIGHT +
544 video_logo_height);
545 } else {
546 /* turn off the cursor and record where it is */
547 video_invertchar(console_col * VIDEO_FONT_WIDTH,
548 console_row * VIDEO_FONT_HEIGHT +
549 video_logo_height);
550 old_col = console_col;
551 old_row = console_row;
552 }
553 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000554 }
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200555 if (cfb_do_flush_cache)
556 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000557}
558#endif
559
wdenkc6097192002-11-03 00:24:07 +0000560#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000561static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000562{
wdenk4b248f32004-03-14 16:51:43 +0000563 while (c--)
564 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000565}
566#endif
567
wdenkc6097192002-11-03 00:24:07 +0000568#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000569static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000570{
wdenk4b248f32004-03-14 16:51:43 +0000571 while (c--)
572 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000573}
574#endif
575
Pali Rohár90f60a82012-04-28 07:26:44 +0000576static void console_clear_line(int line, int begin, int end)
577{
578#ifdef VIDEO_HW_RECTFILL
579 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
580 VIDEO_FONT_WIDTH * begin, /* dest pos x */
581 video_logo_height +
582 VIDEO_FONT_HEIGHT * line, /* dest pos y */
583 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
584 VIDEO_FONT_HEIGHT, /* frame height */
585 bgx /* fill color */
586 );
587#else
588 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
589 memsetl(CONSOLE_ROW_FIRST +
590 CONSOLE_ROW_SIZE * line, /* offset of row */
591 CONSOLE_ROW_SIZE >> 2, /* length of row */
592 bgx /* fill color */
593 );
594 } else {
595 void *offset;
596 int i, size;
597
598 offset = CONSOLE_ROW_FIRST +
599 CONSOLE_ROW_SIZE * line + /* offset of row */
600 VIDEO_FONT_WIDTH *
601 VIDEO_PIXEL_SIZE * begin; /* offset of col */
602 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
603 size >>= 2; /* length to end for memsetl() */
604 /* fill at col offset of i'th line using bgx as fill color */
605 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
606 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
607 }
608#endif
609}
610
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000611static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000612{
Simon Glass3c0b6682015-01-01 16:17:57 -0700613 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
614 int i;
615
wdenk4b248f32004-03-14 16:51:43 +0000616 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000617
618#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000619 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
620 0, /* source pos x */
621 video_logo_height +
Simon Glass3c0b6682015-01-01 16:17:57 -0700622 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000623 0, /* dest pos x */
624 video_logo_height, /* dest pos y */
625 VIDEO_VISIBLE_COLS, /* frame width */
626 VIDEO_VISIBLE_ROWS
627 - video_logo_height
Simon Glass3c0b6682015-01-01 16:17:57 -0700628 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000629 );
wdenkc6097192002-11-03 00:24:07 +0000630#else
Simon Glass3c0b6682015-01-01 16:17:57 -0700631 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
632 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000633#endif
wdenk4b248f32004-03-14 16:51:43 +0000634 /* clear the last one */
Simon Glass3c0b6682015-01-01 16:17:57 -0700635 for (i = 1; i <= rows; i++)
636 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
637
638 /* Decrement row number */
639 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000640}
641
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000642static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000643{
Timur Tabi65618632010-08-27 15:45:47 -0500644 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000645
wdenk4b248f32004-03-14 16:51:43 +0000646 if (console_col < 0) {
647 console_col = CONSOLE_COLS - 1;
648 console_row--;
649 if (console_row < 0)
650 console_row = 0;
651 }
wdenkc6097192002-11-03 00:24:07 +0000652}
653
Pali Rohár33a35bb2012-10-19 13:30:09 +0000654#ifdef CONFIG_CFB_CONSOLE_ANSI
655
656static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000657{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000658#ifdef VIDEO_HW_RECTFILL
659 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
660 0, /* dest pos x */
661 video_logo_height, /* dest pos y */
662 VIDEO_VISIBLE_COLS, /* frame width */
663 VIDEO_VISIBLE_ROWS, /* frame height */
664 bgx /* fill color */
665 );
666#else
667 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
668#endif
669}
670
671static void console_cursor_fix(void)
672{
673 if (console_row < 0)
674 console_row = 0;
675 if (console_row >= CONSOLE_ROWS)
676 console_row = CONSOLE_ROWS - 1;
677 if (console_col < 0)
678 console_col = 0;
679 if (console_col >= CONSOLE_COLS)
680 console_col = CONSOLE_COLS - 1;
681}
682
683static void console_cursor_up(int n)
684{
685 console_row -= n;
686 console_cursor_fix();
687}
688
689static void console_cursor_down(int n)
690{
691 console_row += n;
692 console_cursor_fix();
693}
694
695static void console_cursor_left(int n)
696{
697 console_col -= n;
698 console_cursor_fix();
699}
700
701static void console_cursor_right(int n)
702{
703 console_col += n;
704 console_cursor_fix();
705}
706
707static void console_cursor_set_position(int row, int col)
708{
709 if (console_row != -1)
710 console_row = row;
711 if (console_col != -1)
712 console_col = col;
713 console_cursor_fix();
714}
715
716static void console_previousline(int n)
717{
718 /* FIXME: also scroll terminal ? */
719 console_row -= n;
720 console_cursor_fix();
721}
722
723static void console_swap_colors(void)
724{
725 eorx = fgx;
726 fgx = bgx;
727 bgx = eorx;
728 eorx = fgx ^ bgx;
729}
730
731static inline int console_cursor_is_visible(void)
732{
733 return !ansi_cursor_hidden;
734}
735#else
736static inline int console_cursor_is_visible(void)
737{
738 return 1;
739}
740#endif
741
742static void console_newline(int n)
743{
744 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000745 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000746
wdenk4b248f32004-03-14 16:51:43 +0000747 /* Check if we need to scroll the terminal */
748 if (console_row >= CONSOLE_ROWS) {
749 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000750 console_scrollup();
wdenk4b248f32004-03-14 16:51:43 +0000751 }
wdenkc6097192002-11-03 00:24:07 +0000752}
753
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000754static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100755{
Timur Tabi65618632010-08-27 15:45:47 -0500756 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100757}
758
Pali Rohár33a35bb2012-10-19 13:30:09 +0000759static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000760{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100761 static int nl = 1;
762
Pali Rohár33a35bb2012-10-19 13:30:09 +0000763 if (console_cursor_is_visible())
764 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000765
wdenk4b248f32004-03-14 16:51:43 +0000766 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100767 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000768 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000769 break;
wdenkc6097192002-11-03 00:24:07 +0000770
wdenk4b248f32004-03-14 16:51:43 +0000771 case '\n': /* next line */
Heinrich Schuchardt41ec1272018-03-18 14:24:39 +0100772 if (console_col || nl)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000773 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100774 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000775 break;
wdenkc6097192002-11-03 00:24:07 +0000776
wdenk4b248f32004-03-14 16:51:43 +0000777 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500778 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000779 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000780
wdenk4b248f32004-03-14 16:51:43 +0000781 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000782 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000783 break;
wdenkc6097192002-11-03 00:24:07 +0000784
wdenk4b248f32004-03-14 16:51:43 +0000785 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000786 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000787 break;
wdenkc6097192002-11-03 00:24:07 +0000788
Pali Rohár24fe06c2012-04-28 07:26:47 +0000789 case 7: /* bell */
790 break; /* ignored */
791
wdenk4b248f32004-03-14 16:51:43 +0000792 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000793 video_putchar(console_col * VIDEO_FONT_WIDTH,
794 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000795 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000796
wdenk4b248f32004-03-14 16:51:43 +0000797 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100798 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000799 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100800 nl = 0;
801 }
wdenk4b248f32004-03-14 16:51:43 +0000802 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000803
804 if (console_cursor_is_visible())
805 CURSOR_SET;
806}
807
Simon Glass0a6eac82016-10-17 20:12:54 -0600808static void cfb_video_putc(struct stdio_dev *dev, const char c)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000809{
810#ifdef CONFIG_CFB_CONSOLE_ANSI
811 int i;
812
813 if (c == 27) {
814 for (i = 0; i < ansi_buf_size; ++i)
815 parse_putc(ansi_buf[i]);
816 ansi_buf[0] = 27;
817 ansi_buf_size = 1;
818 return;
819 }
820
821 if (ansi_buf_size > 0) {
822 /*
823 * 0 - ESC
824 * 1 - [
825 * 2 - num1
826 * 3 - ..
827 * 4 - ;
828 * 5 - num2
829 * 6 - ..
830 * - cchar
831 */
832 int next = 0;
833
834 int flush = 0;
835 int fail = 0;
836
837 int num1 = 0;
838 int num2 = 0;
839 int cchar = 0;
840
841 ansi_buf[ansi_buf_size++] = c;
842
843 if (ansi_buf_size >= sizeof(ansi_buf))
844 fail = 1;
845
846 for (i = 0; i < ansi_buf_size; ++i) {
847 if (fail)
848 break;
849
850 switch (next) {
851 case 0:
852 if (ansi_buf[i] == 27)
853 next = 1;
854 else
855 fail = 1;
856 break;
857
858 case 1:
859 if (ansi_buf[i] == '[')
860 next = 2;
861 else
862 fail = 1;
863 break;
864
865 case 2:
866 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
867 num1 = ansi_buf[i]-'0';
868 next = 3;
869 } else if (ansi_buf[i] != '?') {
870 --i;
871 num1 = 1;
872 next = 4;
873 }
874 break;
875
876 case 3:
877 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
878 num1 *= 10;
879 num1 += ansi_buf[i]-'0';
880 } else {
881 --i;
882 next = 4;
883 }
884 break;
885
886 case 4:
887 if (ansi_buf[i] != ';') {
888 --i;
889 next = 7;
890 } else
891 next = 5;
892 break;
893
894 case 5:
895 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
896 num2 = ansi_buf[i]-'0';
897 next = 6;
898 } else
899 fail = 1;
900 break;
901
902 case 6:
903 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
904 num2 *= 10;
905 num2 += ansi_buf[i]-'0';
906 } else {
907 --i;
908 next = 7;
909 }
910 break;
911
912 case 7:
913 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
914 || ansi_buf[i] == 'J'
915 || ansi_buf[i] == 'K'
916 || ansi_buf[i] == 'h'
917 || ansi_buf[i] == 'l'
918 || ansi_buf[i] == 'm') {
919 cchar = ansi_buf[i];
920 flush = 1;
921 } else
922 fail = 1;
923 break;
924 }
925 }
926
927 if (fail) {
928 for (i = 0; i < ansi_buf_size; ++i)
929 parse_putc(ansi_buf[i]);
930 ansi_buf_size = 0;
931 return;
932 }
933
934 if (flush) {
935 if (!ansi_cursor_hidden)
936 CURSOR_OFF;
937 ansi_buf_size = 0;
938 switch (cchar) {
939 case 'A':
940 /* move cursor num1 rows up */
941 console_cursor_up(num1);
942 break;
943 case 'B':
944 /* move cursor num1 rows down */
945 console_cursor_down(num1);
946 break;
947 case 'C':
948 /* move cursor num1 columns forward */
949 console_cursor_right(num1);
950 break;
951 case 'D':
952 /* move cursor num1 columns back */
953 console_cursor_left(num1);
954 break;
955 case 'E':
956 /* move cursor num1 rows up at begin of row */
957 console_previousline(num1);
958 break;
959 case 'F':
960 /* move cursor num1 rows down at begin of row */
961 console_newline(num1);
962 break;
963 case 'G':
964 /* move cursor to column num1 */
965 console_cursor_set_position(-1, num1-1);
966 break;
967 case 'H':
968 /* move cursor to row num1, column num2 */
969 console_cursor_set_position(num1-1, num2-1);
970 break;
971 case 'J':
972 /* clear console and move cursor to 0, 0 */
973 console_clear();
974 console_cursor_set_position(0, 0);
975 break;
976 case 'K':
977 /* clear line */
978 if (num1 == 0)
979 console_clear_line(console_row,
980 console_col,
981 CONSOLE_COLS-1);
982 else if (num1 == 1)
983 console_clear_line(console_row,
984 0, console_col);
985 else
986 console_clear_line(console_row,
987 0, CONSOLE_COLS-1);
988 break;
989 case 'h':
990 ansi_cursor_hidden = 0;
991 break;
992 case 'l':
993 ansi_cursor_hidden = 1;
994 break;
995 case 'm':
996 if (num1 == 0) { /* reset swapped colors */
997 if (ansi_colors_need_revert) {
998 console_swap_colors();
999 ansi_colors_need_revert = 0;
1000 }
1001 } else if (num1 == 7) { /* once swap colors */
1002 if (!ansi_colors_need_revert) {
1003 console_swap_colors();
1004 ansi_colors_need_revert = 1;
1005 }
1006 }
1007 break;
1008 }
1009 if (!ansi_cursor_hidden)
1010 CURSOR_SET;
1011 }
1012 } else {
1013 parse_putc(c);
1014 }
1015#else
1016 parse_putc(c);
1017#endif
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001018 if (cfb_do_flush_cache)
1019 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabi65618632010-08-27 15:45:47 -05001020}
wdenkc6097192002-11-03 00:24:07 +00001021
Simon Glass0a6eac82016-10-17 20:12:54 -06001022static void cfb_video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001023{
Soeren Mochd37e96e2014-10-24 16:33:30 +02001024 int flush = cfb_do_flush_cache;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001025 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +00001026
Soeren Mochd37e96e2014-10-24 16:33:30 +02001027 /* temporarily disable cache flush */
1028 cfb_do_flush_cache = 0;
1029
wdenk4b248f32004-03-14 16:51:43 +00001030 while (count--)
Simon Glass0a6eac82016-10-17 20:12:54 -06001031 cfb_video_putc(dev, *s++);
Soeren Mochd37e96e2014-10-24 16:33:30 +02001032
1033 if (flush) {
1034 cfb_do_flush_cache = flush;
1035 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1036 }
wdenkc6097192002-11-03 00:24:07 +00001037}
1038
Anatolij Gustschin10543822010-05-01 22:21:09 +02001039/*
1040 * Do not enforce drivers (or board code) to provide empty
1041 * video_set_lut() if they do not support 8 bpp format.
1042 * Implement weak default function instead.
1043 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02001044__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001045 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +02001046{
1047}
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001048
Jon Loeliger07d38a12007-07-09 17:30:01 -05001049#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +00001050
1051#define FILL_8BIT_332RGB(r,g,b) { \
1052 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1053 fb ++; \
1054}
1055
1056#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001057 *(unsigned short *)fb = \
1058 SWAP16((unsigned short)(((r>>3)<<10) | \
1059 ((g>>3)<<5) | \
1060 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001061 fb += 2; \
1062}
1063
1064#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001065 *(unsigned short *)fb = \
1066 SWAP16((unsigned short)((((r)>>3)<<11)| \
1067 (((g)>>2)<<5) | \
1068 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001069 fb += 2; \
1070}
1071
1072#define FILL_32BIT_X888RGB(r,g,b) { \
Andre Przywara1d4ed262017-03-06 01:13:38 +00001073 *(u32 *)fb = \
1074 SWAP32((unsigned int)(((r<<16) | \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001075 (g<<8) | \
1076 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001077 fb += 4; \
1078}
1079
1080#ifdef VIDEO_FB_LITTLE_ENDIAN
1081#define FILL_24BIT_888RGB(r,g,b) { \
1082 fb[0] = b; \
1083 fb[1] = g; \
1084 fb[2] = r; \
1085 fb += 3; \
1086}
1087#else
1088#define FILL_24BIT_888RGB(r,g,b) { \
1089 fb[0] = r; \
1090 fb[1] = g; \
1091 fb[2] = b; \
1092 fb += 3; \
1093}
1094#endif
1095
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001096#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001097static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001098{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001099 ushort *dst = (ushort *) fb;
1100 ushort color = (ushort) (((r >> 3) << 10) |
1101 ((g >> 3) << 5) |
1102 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001103 if (x & 1)
1104 *(--dst) = color;
1105 else
1106 *(++dst) = color;
1107}
1108#endif
wdenk4b248f32004-03-14 16:51:43 +00001109
1110/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001111 * RLE8 bitmap support
1112 */
1113
1114#ifdef CONFIG_VIDEO_BMP_RLE8
1115/* Pre-calculated color table entry */
1116struct palette {
1117 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001118 unsigned short w; /* word */
1119 unsigned int dw; /* double word */
1120 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001121};
1122
1123/*
1124 * Helper to draw encoded/unencoded run.
1125 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001126static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1127 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001128{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001129 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001130 int *off;
1131 int enc_off = 1;
1132 int i;
1133
1134 /*
1135 * Setup offset of the color index in the bitmap.
1136 * Color index of encoded run is at offset 1.
1137 */
1138 off = enc ? &enc_off : &i;
1139
1140 switch (VIDEO_DATA_FORMAT) {
1141 case GDF__8BIT_INDEX:
1142 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001143 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001144 break;
1145 case GDF_15BIT_555RGB:
1146 case GDF_16BIT_565RGB:
1147 /* differences handled while pre-calculating palette */
1148 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001149 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001150 addr += 2;
1151 }
1152 break;
1153 case GDF_32BIT_X888RGB:
1154 for (i = 0; i < cnt; i++) {
Andre Przywara1d4ed262017-03-06 01:13:38 +00001155 *(u32 *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001156 addr += 4;
1157 }
1158 break;
1159 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001160 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001161}
1162
Simon Glass1c3dbe52015-05-13 07:02:27 -06001163static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001164 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001165{
1166 unsigned char *bm;
1167 unsigned char *fbp;
1168 unsigned int cnt, runlen;
1169 int decode = 1;
1170 int x, y, bpp, i, ncolors;
1171 struct palette p[256];
Simon Glass1c3dbe52015-05-13 07:02:27 -06001172 struct bmp_color_table_entry cte;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001173 int green_shift, red_off;
Hans de Goedec67a8762015-08-04 12:15:39 +02001174 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001175 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001176
1177 x = 0;
1178 y = __le32_to_cpu(img->header.height) - 1;
1179 ncolors = __le32_to_cpu(img->header.colors_used);
1180 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001181 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001182 (y + yoff) * VIDEO_LINE_LEN +
1183 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001184
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001185 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001186
1187 /* pre-calculate and setup palette */
1188 switch (VIDEO_DATA_FORMAT) {
1189 case GDF__8BIT_INDEX:
1190 for (i = 0; i < ncolors; i++) {
1191 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001192 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001193 }
1194 break;
1195 case GDF_15BIT_555RGB:
1196 case GDF_16BIT_565RGB:
1197 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1198 green_shift = 3;
1199 red_off = 10;
1200 } else {
1201 green_shift = 2;
1202 red_off = 11;
1203 }
1204 for (i = 0; i < ncolors; i++) {
1205 cte = img->color_table[i];
1206 p[i].ce.w = SWAP16((unsigned short)
1207 (((cte.red >> 3) << red_off) |
1208 ((cte.green >> green_shift) << 5) |
1209 cte.blue >> 3));
1210 }
1211 break;
1212 case GDF_32BIT_X888RGB:
1213 for (i = 0; i < ncolors; i++) {
1214 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001215 p[i].ce.dw = SWAP32((cte.red << 16) |
1216 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001217 cte.blue);
1218 }
1219 break;
1220 default:
1221 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001222 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001223 return -1;
1224 }
1225
1226 while (decode) {
1227 switch (bm[0]) {
1228 case 0:
1229 switch (bm[1]) {
1230 case 0:
1231 /* scan line end marker */
1232 bm += 2;
1233 x = 0;
1234 y--;
1235 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001236 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001237 (y + yoff) * VIDEO_LINE_LEN +
1238 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001239 continue;
1240 case 1:
1241 /* end of bitmap data marker */
1242 decode = 0;
1243 break;
1244 case 2:
1245 /* run offset marker */
1246 x += bm[2];
1247 y -= bm[3];
1248 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001249 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001250 (y + yoff) * VIDEO_LINE_LEN +
1251 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001252 bm += 4;
1253 break;
1254 default:
1255 /* unencoded run */
1256 cnt = bm[1];
1257 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001258 pixels += cnt;
1259 if (pixels > limit)
1260 goto error;
1261
Anatolij Gustschind5011762010-03-15 14:50:25 +01001262 bm += 2;
1263 if (y < height) {
1264 if (x >= width) {
1265 x += runlen;
1266 goto next_run;
1267 }
1268 if (x + runlen > width)
1269 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001270 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001271 x += runlen;
1272 }
1273next_run:
1274 bm += runlen;
1275 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001276 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001277 }
1278 break;
1279 default:
1280 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001281 cnt = bm[0];
1282 runlen = cnt;
1283 pixels += cnt;
1284 if (pixels > limit)
1285 goto error;
1286
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001287 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001288 if (x >= width) {
1289 x += runlen;
1290 bm += 2;
1291 continue;
1292 }
1293 if (x + runlen > width)
1294 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001295 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001296 x += runlen;
1297 }
1298 bm += 2;
1299 break;
1300 }
1301 }
Sébastien Szymanski47b11c82018-09-10 09:58:58 +02001302
1303 if (cfb_do_flush_cache)
1304 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1305
Anatolij Gustschind5011762010-03-15 14:50:25 +01001306 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001307error:
1308 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1309 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001310}
1311#endif
1312
1313/*
wdenk4b248f32004-03-14 16:51:43 +00001314 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001315 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001316int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001317{
1318 ushort xcount, ycount;
1319 uchar *fb;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001320 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenk4b248f32004-03-14 16:51:43 +00001321 uchar *bmap;
1322 ushort padded_line;
1323 unsigned long width, height, bpp;
1324 unsigned colors;
1325 unsigned long compression;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001326 struct bmp_color_table_entry cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001327
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001328#ifdef CONFIG_VIDEO_BMP_GZIP
1329 unsigned char *dst = NULL;
1330 ulong len;
1331#endif
wdenk4b248f32004-03-14 16:51:43 +00001332
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001333 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001334
1335 if (!((bmp->header.signature[0] == 'B') &&
1336 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001337
1338#ifdef CONFIG_VIDEO_BMP_GZIP
1339 /*
1340 * Could be a gzipped bmp image, try to decrompress...
1341 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001342 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1343 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001344 if (dst == NULL) {
1345 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001346 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001347 }
Eric Nelson5ca05c82014-03-08 07:55:52 -07001348 /*
1349 * NB: we need to force offset of +2
1350 * See doc/README.displaying-bmps
1351 */
1352 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001353 (uchar *) bmp_image,
1354 &len) != 0) {
1355 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1356 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001357 free(dst);
1358 return 1;
1359 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001360 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001361 printf("Image could be truncated "
1362 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001363 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001364
1365 /*
1366 * Set addr to decompressed image
1367 */
Simon Glass1c3dbe52015-05-13 07:02:27 -06001368 bmp = (struct bmp_image *)(dst+2);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001369
1370 if (!((bmp->header.signature[0] == 'B') &&
1371 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001372 printf("Error: no valid bmp.gz image at %lx\n",
1373 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001374 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001375 return 1;
1376 }
1377#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001378 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001379 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001380#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001381 }
1382
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001383 width = le32_to_cpu(bmp->header.width);
1384 height = le32_to_cpu(bmp->header.height);
1385 bpp = le16_to_cpu(bmp->header.bit_count);
1386 colors = le32_to_cpu(bmp->header.colors_used);
1387 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001388
Marek Vasut68da5b12011-10-21 14:17:04 +00001389 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001390 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001391
Anatolij Gustschind5011762010-03-15 14:50:25 +01001392 if (compression != BMP_BI_RGB
1393#ifdef CONFIG_VIDEO_BMP_RLE8
1394 && compression != BMP_BI_RLE8
1395#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001396 ) {
1397 printf("Error: compression type %ld not supported\n",
1398 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001399#ifdef CONFIG_VIDEO_BMP_GZIP
1400 if (dst)
1401 free(dst);
1402#endif
wdenk4b248f32004-03-14 16:51:43 +00001403 return 1;
1404 }
1405
1406 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1407
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001408#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1409 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001410 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001411 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001412 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001413
1414 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001415 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001416 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001417 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001418#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1419
Matthias Weisseracf3baa2013-02-15 03:35:12 +00001420 /*
1421 * Just ignore elements which are completely beyond screen
1422 * dimensions.
1423 */
1424 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1425 return 0;
1426
wdenk4b248f32004-03-14 16:51:43 +00001427 if ((x + width) > VIDEO_VISIBLE_COLS)
1428 width = VIDEO_VISIBLE_COLS - x;
1429 if ((y + height) > VIDEO_VISIBLE_ROWS)
1430 height = VIDEO_VISIBLE_ROWS - y;
1431
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001432 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001433 fb = (uchar *) (video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001434 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenk4b248f32004-03-14 16:51:43 +00001435 x * VIDEO_PIXEL_SIZE);
1436
Anatolij Gustschind5011762010-03-15 14:50:25 +01001437#ifdef CONFIG_VIDEO_BMP_RLE8
1438 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001439 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001440 }
1441#endif
1442
Timur Tabi68f66182010-08-23 16:58:00 -05001443 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001444 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001445 case 4:
1446 padded_line -= width / 2;
1447 ycount = height;
1448
1449 switch (VIDEO_DATA_FORMAT) {
1450 case GDF_32BIT_X888RGB:
1451 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001452 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001453 /*
1454 * Don't assume that 'width' is an
1455 * even number
1456 */
1457 for (xcount = 0; xcount < width; xcount++) {
1458 uchar idx;
1459
1460 if (xcount & 1) {
1461 idx = *bmap & 0xF;
1462 bmap++;
1463 } else
1464 idx = *bmap >> 4;
1465 cte = bmp->color_table[idx];
1466 FILL_32BIT_X888RGB(cte.red, cte.green,
1467 cte.blue);
1468 }
1469 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001470 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001471 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001472 }
1473 break;
1474 default:
1475 puts("4bpp bitmap unsupported with current "
1476 "video mode\n");
1477 break;
1478 }
1479 break;
1480
wdenk4b248f32004-03-14 16:51:43 +00001481 case 8:
1482 padded_line -= width;
1483 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001484 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001485 for (xcount = 0; xcount < colors; ++xcount) {
1486 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001487 video_set_lut(xcount, cte.red, cte.green,
1488 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001489 }
1490 }
1491 ycount = height;
1492 switch (VIDEO_DATA_FORMAT) {
1493 case GDF__8BIT_INDEX:
1494 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001495 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001496 xcount = width;
1497 while (xcount--) {
1498 *fb++ = *bmap++;
1499 }
1500 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001501 fb -= VIDEO_LINE_LEN + width *
1502 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001503 }
1504 break;
1505 case GDF__8BIT_332RGB:
1506 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001507 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001508 xcount = width;
1509 while (xcount--) {
1510 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001511 FILL_8BIT_332RGB(cte.red, cte.green,
1512 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001513 }
1514 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001515 fb -= VIDEO_LINE_LEN + width *
1516 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001517 }
1518 break;
1519 case GDF_15BIT_555RGB:
1520 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001521#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1522 int xpos = x;
1523#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001524 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001525 xcount = width;
1526 while (xcount--) {
1527 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001528#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001529 fill_555rgb_pswap(fb, xpos++, cte.red,
1530 cte.green,
1531 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001532 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001533#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001534 FILL_15BIT_555RGB(cte.red, cte.green,
1535 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001536#endif
wdenk4b248f32004-03-14 16:51:43 +00001537 }
1538 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001539 fb -= VIDEO_LINE_LEN + width *
1540 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001541 }
1542 break;
1543 case GDF_16BIT_565RGB:
1544 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001545 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001546 xcount = width;
1547 while (xcount--) {
1548 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001549 FILL_16BIT_565RGB(cte.red, cte.green,
1550 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001551 }
1552 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001553 fb -= VIDEO_LINE_LEN + width *
1554 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001555 }
1556 break;
1557 case GDF_32BIT_X888RGB:
1558 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001559 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001560 xcount = width;
1561 while (xcount--) {
1562 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001563 FILL_32BIT_X888RGB(cte.red, cte.green,
1564 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001565 }
1566 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001567 fb -= VIDEO_LINE_LEN + width *
1568 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001569 }
1570 break;
1571 case GDF_24BIT_888RGB:
1572 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001573 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001574 xcount = width;
1575 while (xcount--) {
1576 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001577 FILL_24BIT_888RGB(cte.red, cte.green,
1578 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001579 }
1580 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001581 fb -= VIDEO_LINE_LEN + width *
1582 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001583 }
1584 break;
1585 }
1586 break;
1587 case 24:
1588 padded_line -= 3 * width;
1589 ycount = height;
1590 switch (VIDEO_DATA_FORMAT) {
1591 case GDF__8BIT_332RGB:
1592 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001593 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001594 xcount = width;
1595 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001596 FILL_8BIT_332RGB(bmap[2], bmap[1],
1597 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001598 bmap += 3;
1599 }
1600 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001601 fb -= VIDEO_LINE_LEN + width *
1602 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001603 }
1604 break;
1605 case GDF_15BIT_555RGB:
1606 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001607#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1608 int xpos = x;
1609#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001610 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001611 xcount = width;
1612 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001613#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001614 fill_555rgb_pswap(fb, xpos++, bmap[2],
1615 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001616 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001617#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001618 FILL_15BIT_555RGB(bmap[2], bmap[1],
1619 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001620#endif
wdenk4b248f32004-03-14 16:51:43 +00001621 bmap += 3;
1622 }
1623 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001624 fb -= VIDEO_LINE_LEN + width *
1625 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001626 }
1627 break;
1628 case GDF_16BIT_565RGB:
1629 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001630 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001631 xcount = width;
1632 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001633 FILL_16BIT_565RGB(bmap[2], bmap[1],
1634 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001635 bmap += 3;
1636 }
1637 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001638 fb -= VIDEO_LINE_LEN + width *
1639 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001640 }
1641 break;
1642 case GDF_32BIT_X888RGB:
1643 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001644 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001645 xcount = width;
1646 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001647 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1648 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001649 bmap += 3;
1650 }
1651 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001652 fb -= VIDEO_LINE_LEN + width *
1653 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001654 }
1655 break;
1656 case GDF_24BIT_888RGB:
1657 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001658 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001659 xcount = width;
1660 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001661 FILL_24BIT_888RGB(bmap[2], bmap[1],
1662 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001663 bmap += 3;
1664 }
1665 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001666 fb -= VIDEO_LINE_LEN + width *
1667 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001668 }
1669 break;
1670 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001671 printf("Error: 24 bits/pixel bitmap incompatible "
1672 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001673 break;
1674 }
1675 break;
1676 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001677 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1678 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001679 break;
1680 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001681
1682#ifdef CONFIG_VIDEO_BMP_GZIP
1683 if (dst) {
1684 free(dst);
1685 }
1686#endif
1687
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001688 if (cfb_do_flush_cache)
1689 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk4b248f32004-03-14 16:51:43 +00001690 return (0);
1691}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001692#endif
wdenk4b248f32004-03-14 16:51:43 +00001693
wdenk4b248f32004-03-14 16:51:43 +00001694
wdenkc6097192002-11-03 00:24:07 +00001695#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001696static int video_logo_xpos;
1697static int video_logo_ypos;
1698
Hans de Goedec4c9e812015-08-04 12:21:40 +02001699static void plot_logo_or_black(void *screen, int x, int y, int black);
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001700
Hans de Goedec4c9e812015-08-04 12:21:40 +02001701static void logo_plot(void *screen, int x, int y)
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001702{
Hans de Goedec4c9e812015-08-04 12:21:40 +02001703 plot_logo_or_black(screen, x, y, 0);
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001704}
1705
1706static void logo_black(void)
1707{
Hans de Goedec4c9e812015-08-04 12:21:40 +02001708 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001709 1);
1710}
1711
1712static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1713{
1714 if (argc != 1)
1715 return cmd_usage(cmdtp);
1716
1717 logo_black();
1718 return 0;
1719}
1720
1721U_BOOT_CMD(
1722 clrlogo, 1, 0, do_clrlogo,
1723 "fill the boot logo area with black",
1724 " "
1725 );
1726
Hans de Goedec4c9e812015-08-04 12:21:40 +02001727static void plot_logo_or_black(void *screen, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001728{
wdenkc6097192002-11-03 00:24:07 +00001729
wdenk4b248f32004-03-14 16:51:43 +00001730 int xcount, i;
Hans de Goedec67a8762015-08-04 12:15:39 +02001731 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001732 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001733 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1734 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001735 unsigned char *dest;
1736
1737#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1738 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001739 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001740 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001741 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001742
1743 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001744 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001745 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001746 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001747#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1748
Hans de Goedec67a8762015-08-04 12:15:39 +02001749 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001750
1751#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001752 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001753
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001754 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001755 logo_red = malloc(BMP_LOGO_COLORS);
1756 logo_green = malloc(BMP_LOGO_COLORS);
1757 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001758 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001759 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1760 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1761 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1762 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1763 }
wdenka6c7ad22002-12-03 21:28:10 +00001764#else
wdenk4b248f32004-03-14 16:51:43 +00001765 source = linux_logo;
1766 logo_red = linux_logo_red;
1767 logo_green = linux_logo_green;
1768 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001769#endif
wdenk8bde7f72003-06-27 21:31:46 +00001770
wdenk4b248f32004-03-14 16:51:43 +00001771 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1772 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001773 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1774 logo_red[i], logo_green[i],
1775 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001776 }
wdenk8bde7f72003-06-27 21:31:46 +00001777 }
wdenkc6097192002-11-03 00:24:07 +00001778
wdenk4b248f32004-03-14 16:51:43 +00001779 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001780#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1781 int xpos = x;
1782#endif
wdenk4b248f32004-03-14 16:51:43 +00001783 xcount = VIDEO_LOGO_WIDTH;
1784 while (xcount--) {
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001785 if (black) {
1786 r = 0x00;
1787 g = 0x00;
1788 b = 0x00;
1789 } else {
1790 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1791 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1792 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1793 }
wdenk8bde7f72003-06-27 21:31:46 +00001794
wdenk4b248f32004-03-14 16:51:43 +00001795 switch (VIDEO_DATA_FORMAT) {
1796 case GDF__8BIT_INDEX:
1797 *dest = *source;
1798 break;
1799 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001800 *dest = ((r >> 5) << 5) |
1801 ((g >> 5) << 2) |
1802 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001803 break;
1804 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001805#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001806 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001807#else
wdenk4b248f32004-03-14 16:51:43 +00001808 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001809 SWAP16((unsigned short) (
1810 ((r >> 3) << 10) |
1811 ((g >> 3) << 5) |
1812 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001813#endif
wdenk4b248f32004-03-14 16:51:43 +00001814 break;
1815 case GDF_16BIT_565RGB:
1816 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001817 SWAP16((unsigned short) (
1818 ((r >> 3) << 11) |
1819 ((g >> 2) << 5) |
1820 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001821 break;
1822 case GDF_32BIT_X888RGB:
Andre Przywara1d4ed262017-03-06 01:13:38 +00001823 *(u32 *) dest =
1824 SWAP32((u32) (
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001825 (r << 16) |
1826 (g << 8) |
1827 b));
wdenk4b248f32004-03-14 16:51:43 +00001828 break;
1829 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001830#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001831 dest[0] = b;
1832 dest[1] = g;
1833 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001834#else
wdenk4b248f32004-03-14 16:51:43 +00001835 dest[0] = r;
1836 dest[1] = g;
1837 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001838#endif
wdenk4b248f32004-03-14 16:51:43 +00001839 break;
1840 }
1841 source++;
1842 dest += VIDEO_PIXEL_SIZE;
1843 }
1844 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001845 }
wdenka6c7ad22002-12-03 21:28:10 +00001846#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001847 free(logo_red);
1848 free(logo_green);
1849 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001850#endif
wdenkc6097192002-11-03 00:24:07 +00001851}
1852
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001853static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001854{
wdenk4b248f32004-03-14 16:51:43 +00001855 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001856 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001857 __maybe_unused ulong addr;
1858 __maybe_unused char *s;
Anatolij Gustschinb4fc6f22016-11-30 14:30:59 +01001859 __maybe_unused int len, ret, space;
wdenkc6097192002-11-03 00:24:07 +00001860
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001861 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001862
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001863#ifdef CONFIG_SPLASH_SCREEN
Simon Glass00caae62017-08-03 12:22:12 -06001864 s = env_get("splashimage");
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001865 if (s != NULL) {
Anatolij Gustschinb4fc6f22016-11-30 14:30:59 +01001866 ret = splash_screen_prepare();
1867 if (ret < 0)
1868 return video_fb_address;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001869 addr = simple_strtoul(s, NULL, 16);
1870
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001871 if (video_display_bitmap(addr,
1872 video_logo_xpos,
1873 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001874 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00001875 return ((void *) (video_fb_address));
1876 }
1877 }
1878#endif /* CONFIG_SPLASH_SCREEN */
1879
Hans de Goedec4c9e812015-08-04 12:21:40 +02001880 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001881
1882#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1883 /*
1884 * when using splashpos for video_logo, skip any info
1885 * output on video console if the logo is not at 0,0
1886 */
1887 if (video_logo_xpos || video_logo_ypos) {
1888 /*
1889 * video_logo_height is used in text and cursor offset
1890 * calculations. Since the console is below the logo,
1891 * we need to adjust the logo height
1892 */
1893 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001894 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001895 VIDEO_LOGO_HEIGHT) / 2);
1896 else if (video_logo_ypos > 0)
1897 video_logo_height += video_logo_ypos;
1898
1899 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1900 }
1901#endif
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02001902 if (board_cfb_skip())
1903 return 0;
wdenk4b248f32004-03-14 16:51:43 +00001904
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001905 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001906
Tim Harveyadde4352016-05-24 14:59:59 -07001907#ifndef CONFIG_HIDE_LOGO_VERSION
Peng Fanf9d891f2018-01-02 15:25:37 +08001908 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001909 len = strlen(info);
1910
1911 if (len > space) {
Peng Fanf9d891f2018-01-02 15:25:37 +08001912 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1913 uchar *p = (uchar *) info;
1914
1915 while (len) {
1916 if (len > space) {
1917 video_drawchars(xx, yy, p, space);
1918 len -= space;
1919
1920 p = (uchar *)p + space;
1921
1922 if (!y_off) {
1923 xx += VIDEO_FONT_WIDTH;
1924 space--;
1925 }
1926 yy += VIDEO_FONT_HEIGHT;
1927
1928 y_off++;
1929 } else {
1930 video_drawchars(xx, yy, p, len);
1931 len = 0;
1932 }
1933 }
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001934 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001935 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001936
1937#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00001938 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001939 int i, n =
1940 ((video_logo_height -
1941 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001942
wdenk4b248f32004-03-14 16:51:43 +00001943 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001944 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001945 if (!*info)
1946 continue;
1947
1948 len = strlen(info);
1949 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001950 video_drawchars(VIDEO_INFO_X,
1951 VIDEO_INFO_Y +
1952 (i + y_off) *
1953 VIDEO_FONT_HEIGHT,
1954 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001955 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001956 video_drawchars(VIDEO_INFO_X +
1957 VIDEO_FONT_WIDTH,
1958 VIDEO_INFO_Y +
1959 (i + y_off) *
1960 VIDEO_FONT_HEIGHT,
1961 (uchar *) info + space,
1962 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001963 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001964 video_drawstring(VIDEO_INFO_X,
1965 VIDEO_INFO_Y +
1966 (i + y_off) *
1967 VIDEO_FONT_HEIGHT,
1968 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001969 }
wdenk4b248f32004-03-14 16:51:43 +00001970 }
1971 }
wdenkc6097192002-11-03 00:24:07 +00001972#endif
Tim Harveyadde4352016-05-24 14:59:59 -07001973#endif
wdenkc6097192002-11-03 00:24:07 +00001974
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001975 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001976}
1977#endif
1978
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001979static int cfb_fb_is_in_dram(void)
1980{
1981 bd_t *bd = gd->bd;
Andy Shevchenkodaab59a2017-07-05 16:25:22 +03001982#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001983defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1984 ulong start, end;
1985 int i;
1986
1987 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1988 start = bd->bi_dram[i].start;
1989 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1990 if ((ulong)video_fb_address >= start &&
1991 (ulong)video_fb_address < end)
1992 return 1;
1993 }
1994#else
1995 if ((ulong)video_fb_address >= bd->bi_memstart &&
1996 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1997 return 1;
1998#endif
1999 return 0;
2000}
2001
Heiko Schocher45ae2542013-10-22 11:06:06 +02002002void video_clear(void)
2003{
2004 if (!video_fb_address)
2005 return;
2006#ifdef VIDEO_HW_RECTFILL
2007 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2008 0, /* dest pos x */
2009 0, /* dest pos y */
2010 VIDEO_VISIBLE_COLS, /* frame width */
2011 VIDEO_VISIBLE_ROWS, /* frame height */
2012 bgx /* fill color */
2013 );
2014#else
2015 memsetl(video_fb_address,
2016 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2017#endif
2018}
2019
Simon Glass0a6eac82016-10-17 20:12:54 -06002020static int cfg_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002021{
wdenk4b248f32004-03-14 16:51:43 +00002022 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002023
Wolfgang Denk57912932011-07-30 12:48:09 +00002024 pGD = video_hw_init();
2025 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00002026 return -1;
wdenkc6097192002-11-03 00:24:07 +00002027
wdenk4b248f32004-03-14 16:51:43 +00002028 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002029
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002030 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2031
wdenk4b248f32004-03-14 16:51:43 +00002032 /* Init drawing pats */
2033 switch (VIDEO_DATA_FORMAT) {
2034 case GDF__8BIT_INDEX:
Simon Glass002f9672016-10-17 20:12:44 -06002035 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2036 CONFIG_SYS_CONSOLE_FG_COL,
2037 CONFIG_SYS_CONSOLE_FG_COL);
2038 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2039 CONFIG_SYS_CONSOLE_BG_COL,
2040 CONFIG_SYS_CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00002041 fgx = 0x01010101;
2042 bgx = 0x00000000;
2043 break;
2044 case GDF__8BIT_332RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002045 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2046 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2047 CONFIG_SYS_CONSOLE_FG_COL >> 6);
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002048 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2049 color8;
Simon Glass002f9672016-10-17 20:12:44 -06002050 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2051 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2052 CONFIG_SYS_CONSOLE_BG_COL >> 6);
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002053 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2054 color8;
wdenk4b248f32004-03-14 16:51:43 +00002055 break;
2056 case GDF_15BIT_555RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002057 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2058 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2059 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2061 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2062 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2063 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2064 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2065 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2067 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2068 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002069 break;
2070 case GDF_16BIT_565RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002071 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2072 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2073 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2074 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2075 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2076 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2077 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2078 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2079 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2080 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2081 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2082 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002083 break;
2084 case GDF_32BIT_X888RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002085 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2086 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2087 CONFIG_SYS_CONSOLE_FG_COL;
2088 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2089 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2090 CONFIG_SYS_CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002091 break;
2092 case GDF_24BIT_888RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002093 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2094 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2095 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2096 CONFIG_SYS_CONSOLE_FG_COL;
2097 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2098 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2099 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2100 CONFIG_SYS_CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002101 break;
2102 }
2103 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002104
Rob Clark8ef05352017-08-03 12:47:01 -04002105 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2106 video_clear();
Heiko Schocher45ae2542013-10-22 11:06:06 +02002107
wdenkc6097192002-11-03 00:24:07 +00002108#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00002109 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002110 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002111 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002112#else
wdenk4b248f32004-03-14 16:51:43 +00002113 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002114#endif
2115
wdenk4b248f32004-03-14 16:51:43 +00002116 /* Initialize the console */
2117 console_col = 0;
2118 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002119
Eric Nelsondb0d47d2013-05-06 14:27:28 +02002120 if (cfb_do_flush_cache)
2121 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2122
wdenk4b248f32004-03-14 16:51:43 +00002123 return 0;
wdenkc6097192002-11-03 00:24:07 +00002124}
2125
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002126/*
2127 * Implement a weak default function for boards that optionally
2128 * need to skip the video initialization.
2129 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02002130__weak int board_video_skip(void)
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002131{
2132 /* As default, don't skip test */
2133 return 0;
2134}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002135
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002136int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002137{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02002138 struct stdio_dev console_dev;
Simon Glass5692ccf2015-03-02 12:40:50 -07002139 bool have_keyboard;
Bin Meng8ceb2422015-08-24 01:00:07 -07002140 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00002141
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002142 /* Check if video initialization should be skipped */
2143 if (board_video_skip())
2144 return 0;
2145
wdenk81050922004-07-11 20:04:51 +00002146 /* Init video chip - returns with framebuffer cleared */
Simon Glass0a6eac82016-10-17 20:12:54 -06002147 if (cfg_video_init() == -1)
Bin Meng8ceb2422015-08-24 01:00:07 -07002148 return 0;
wdenk81050922004-07-11 20:04:51 +00002149
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002150 if (board_cfb_skip())
2151 return 0;
2152
Simon Glass5692ccf2015-03-02 12:40:50 -07002153#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2154 have_keyboard = false;
2155#elif defined(CONFIG_OF_CONTROL)
2156 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2157 "u-boot,no-keyboard");
2158#else
2159 have_keyboard = true;
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002160#endif
Simon Glass5692ccf2015-03-02 12:40:50 -07002161 if (have_keyboard) {
2162 debug("KBD: Keyboard init ...\n");
2163#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07002164 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Simon Glass5692ccf2015-03-02 12:40:50 -07002165#endif
2166 }
wdenkc6097192002-11-03 00:24:07 +00002167
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002168 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002169 memset(&console_dev, 0, sizeof(console_dev));
2170 strcpy(console_dev.name, "vga");
Bin Meng1caf9342015-11-03 23:23:37 -08002171 console_dev.flags = DEV_FLAGS_OUTPUT;
Simon Glass0a6eac82016-10-17 20:12:54 -06002172 console_dev.putc = cfb_video_putc; /* 'putc' function */
2173 console_dev.puts = cfb_video_puts; /* 'puts' function */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002174
2175#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07002176 if (have_keyboard && keyboard_ok) {
Simon Glass5692ccf2015-03-02 12:40:50 -07002177 /* Also init console device */
2178 console_dev.flags |= DEV_FLAGS_INPUT;
2179 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2180 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2181 }
2182#endif
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002183
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002184 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002185 return 0;
2186
2187 /* Return success */
2188 return 1;
wdenkc6097192002-11-03 00:24:07 +00002189}
Stefan Reinauerc20ee072012-09-28 15:11:12 +00002190
2191void video_position_cursor(unsigned col, unsigned row)
2192{
2193 console_col = min(col, CONSOLE_COLS - 1);
2194 console_row = min(row, CONSOLE_ROWS - 1);
2195}
2196
2197int video_get_pixel_width(void)
2198{
2199 return VIDEO_VISIBLE_COLS;
2200}
2201
2202int video_get_pixel_height(void)
2203{
2204 return VIDEO_VISIBLE_ROWS;
2205}
2206
2207int video_get_screen_rows(void)
2208{
2209 return CONSOLE_ROWS;
2210}
2211
2212int video_get_screen_columns(void)
2213{
2214 return CONSOLE_COLS;
2215}