blob: 5e1ee061e8e81af2ceef6b3f9373ae282b49eb58 [file] [log] [blame]
Tom Rini10e47792018-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 Denk0b4b56e2011-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 Glasseaba37e2015-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 Denk0b4b56e2011-07-29 09:55:27 +000024 *
25 * The driver uses graphic specific defines/parameters/functions:
26 *
27 * (for SMI LynxE graphic chip)
28 *
Wolfgang Denk0b4b56e2011-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 Denk0b4b56e2011-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 Rupperta13e81f2012-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 Denk0b4b56e2011-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 Denk0b4b56e2011-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 Denk0b4b56e2011-07-29 09:55:27 +000065 */
wdenkc6097192002-11-03 00:24:07 +000066
67#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -060068#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070069#include <cpu_func.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060070#include <env.h>
Simon Glasse9fa1f02015-03-02 12:40:50 -070071#include <fdtdec.h>
Simon Glass1a974af2019-08-01 09:46:36 -060072#include <gzip.h>
Simon Glass0f2af882020-05-10 11:40:05 -060073#include <log.h>
Andreas Bießmann61d01952011-07-18 20:24:04 +020074#include <version.h>
wdenk9dd2b882002-12-03 21:28:10 +000075#include <malloc.h>
Simon Glass88ecb9b2016-10-17 20:12:54 -060076#include <video.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060077#include <asm/global_data.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +000078#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +000079
Simon Glass9d057042016-10-17 20:12:47 -060080#if defined(CONFIG_VIDEO_MXS)
Marek Vasutffdd4662013-04-28 09:20:03 +000081#define VIDEO_FB_16BPP_WORD_SWAP
82#endif
83
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000084/*
Helmut Raiger0385c132011-10-12 23:16:29 +000085 * Defines for the i.MX31 driver (mx3fb.c)
86 */
Fabio Estevamc6dd2e02012-05-31 07:23:56 +000087#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger0385c132011-10-12 23:16:29 +000088#define VIDEO_FB_16BPP_WORD_SWAP
89#endif
90
91/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000092 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
93 */
wdenkc6097192002-11-03 00:24:07 +000094#include <video_fb.h>
95
Robert Winkler2a90ed02013-06-17 11:31:29 -070096#include <splash.h>
97
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000098/*
99 * some Macros
100 */
wdenke55402c2004-03-14 16:51:43 +0000101#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
102#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
103#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
104#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
105#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000106
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000107/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000108 * Console device
109 */
wdenkc6097192002-11-03 00:24:07 +0000110
111#include <version.h>
112#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200113#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000114#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000115
Jon Loeliger30c2f242007-07-10 11:13:21 -0500116#if defined(CONFIG_CMD_DATE)
117#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000118#endif
119
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500120#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000121#include <watchdog.h>
122#include <bmp_layout.h>
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +0200123#include <splash.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200124#endif
125
Simon Glassd615c892016-10-17 20:12:50 -0600126#if !defined(CONFIG_VIDEO_SW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000127/* no Cursor defined */
128#define CURSOR_ON
129#define CURSOR_OFF
130#define CURSOR_SET
131#endif
132
Simon Glassf406a1b2015-10-18 21:17:18 -0600133#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000134void console_cursor(int state);
135
Timur Tabibe0c74e2010-08-27 15:45:47 -0500136#define CURSOR_ON console_cursor(1)
137#define CURSOR_OFF console_cursor(0)
Gabe Black12874de2011-11-30 13:50:50 +0000138#define CURSOR_SET video_set_cursor()
Simon Glassf406a1b2015-10-18 21:17:18 -0600139#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000140
wdenke55402c2004-03-14 16:51:43 +0000141#ifdef CONFIG_VIDEO_LOGO
142#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000143#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000144#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000145#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
146#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
147#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
148#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000149
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000150#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000151#define LINUX_LOGO_WIDTH 80
152#define LINUX_LOGO_HEIGHT 80
153#define LINUX_LOGO_COLORS 214
154#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000155#define __initdata
156#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000157#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
158#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
159#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
160#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000161#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000162#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
163#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000164#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000165#define VIDEO_LOGO_WIDTH 0
166#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000167#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000168
wdenke55402c2004-03-14 16:51:43 +0000169#define VIDEO_COLS VIDEO_VISIBLE_COLS
170#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedea8287e72015-08-04 12:15:39 +0200171#ifndef VIDEO_LINE_LEN
172#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
173#endif
174#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenke55402c2004-03-14 16:51:43 +0000175#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000176
wdenke55402c2004-03-14 16:51:43 +0000177#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100178#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000179#else
wdenke55402c2004-03-14 16:51:43 +0000180#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000181#endif
182
wdenke55402c2004-03-14 16:51:43 +0000183#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
184#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
185#define CONSOLE_ROW_FIRST (video_console_address)
186#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
187#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
188#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass6ceb7f02015-01-01 16:17:57 -0700189
190/* By default we scroll by a single line */
191#ifndef CONFIG_CONSOLE_SCROLL_LINES
192#define CONFIG_CONSOLE_SCROLL_LINES 1
193#endif
wdenkc6097192002-11-03 00:24:07 +0000194
195/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000196#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000197#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
198 ((x) >> 8) \
199 )
200#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
201 (((x) & 0x0000ff00) << 8) | \
202 (((x) & 0x00ff0000) >> 8) | \
203 (((x) & 0xff000000) >> 24) \
204 )
205#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
206 (((x) & 0x0000ff00) >> 8) | \
207 (((x) & 0x00ff0000) << 8) | \
208 (((x) & 0xff000000) >> 8) \
209 )
wdenkc6097192002-11-03 00:24:07 +0000210#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000211#define SWAP16(x) (x)
212#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200213#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000214#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500215#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000216#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100217#endif
wdenkc6097192002-11-03 00:24:07 +0000218#endif
219
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200220DECLARE_GLOBAL_DATA_PTR;
221
wdenkc6097192002-11-03 00:24:07 +0000222/* Locals */
223static GraphicDevice *pGD; /* Pointer to Graphic array */
224
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000225static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000226static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000227
Matthias Weisser76d70862010-01-12 12:06:31 +0100228static int video_logo_height = VIDEO_LOGO_HEIGHT;
229
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000230static int __maybe_unused cursor_state;
231static int __maybe_unused old_col;
232static int __maybe_unused old_row;
Gabe Black12874de2011-11-30 13:50:50 +0000233
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000234static int console_col; /* cursor col */
235static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000236
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000237static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000238
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200239static int cfb_do_flush_cache;
240
Pali Rohár4a57da32012-10-19 13:30:09 +0000241#ifdef CONFIG_CFB_CONSOLE_ANSI
242static char ansi_buf[10];
243static int ansi_buf_size;
244static int ansi_colors_need_revert;
245static int ansi_cursor_hidden;
246#endif
247
wdenkc6097192002-11-03 00:24:07 +0000248static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000249 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
250 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
251 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
252 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
253};
wdenkc6097192002-11-03 00:24:07 +0000254
255static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000256 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
257};
wdenkc6097192002-11-03 00:24:07 +0000258
259static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000260 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
261};
wdenkc6097192002-11-03 00:24:07 +0000262
263static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000264 {0x00000000, 0x00000000, 0x00000000},
265 {0x00000000, 0x00000000, 0x00ffffff},
266 {0x00000000, 0x0000ffff, 0xff000000},
267 {0x00000000, 0x0000ffff, 0xffffffff},
268 {0x000000ff, 0xffff0000, 0x00000000},
269 {0x000000ff, 0xffff0000, 0x00ffffff},
270 {0x000000ff, 0xffffffff, 0xff000000},
271 {0x000000ff, 0xffffffff, 0xffffffff},
272 {0xffffff00, 0x00000000, 0x00000000},
273 {0xffffff00, 0x00000000, 0x00ffffff},
274 {0xffffff00, 0x0000ffff, 0xff000000},
275 {0xffffff00, 0x0000ffff, 0xffffffff},
276 {0xffffffff, 0xffff0000, 0x00000000},
277 {0xffffffff, 0xffff0000, 0x00ffffff},
278 {0xffffffff, 0xffffffff, 0xff000000},
279 {0xffffffff, 0xffffffff, 0xffffffff}
280};
wdenkc6097192002-11-03 00:24:07 +0000281
282static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000283 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
284 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
285 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
286 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
287 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
288 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
289 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
290 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
291 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
292 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
293 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
294 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
295 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
296 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
297 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
298 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
299};
wdenkc6097192002-11-03 00:24:07 +0000300
Heiko Schocher9cff8ad2013-08-03 07:22:53 +0200301/*
302 * Implement a weak default function for boards that optionally
303 * need to skip the cfb initialization.
304 */
305__weak int board_cfb_skip(void)
306{
307 /* As default, don't skip cfb init */
308 return 0;
309}
310
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000311static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000312{
wdenke55402c2004-03-14 16:51:43 +0000313 u8 *cdat, *dest, *dest0;
314 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000315
wdenke55402c2004-03-14 16:51:43 +0000316 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
317 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000318
wdenke55402c2004-03-14 16:51:43 +0000319 switch (VIDEO_DATA_FORMAT) {
320 case GDF__8BIT_INDEX:
321 case GDF__8BIT_332RGB:
322 while (count--) {
323 c = *s;
324 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
325 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000326 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000327 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000328
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000329 ((u32 *) dest)[0] =
330 (video_font_draw_table8[bits >> 4] &
331 eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200332
333 if (VIDEO_FONT_WIDTH == 4)
334 continue;
335
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000336 ((u32 *) dest)[1] =
337 (video_font_draw_table8[bits & 15] &
338 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000339 }
340 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
341 s++;
342 }
343 break;
wdenkc6097192002-11-03 00:24:07 +0000344
wdenke55402c2004-03-14 16:51:43 +0000345 case GDF_15BIT_555RGB:
346 while (count--) {
347 c = *s;
348 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
349 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000350 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000351 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000352
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000353 ((u32 *) dest)[0] =
354 SHORTSWAP32((video_font_draw_table15
355 [bits >> 6] & eorx) ^
356 bgx);
357 ((u32 *) dest)[1] =
358 SHORTSWAP32((video_font_draw_table15
359 [bits >> 4 & 3] & eorx) ^
360 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200361
362 if (VIDEO_FONT_WIDTH == 4)
363 continue;
364
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000365 ((u32 *) dest)[2] =
366 SHORTSWAP32((video_font_draw_table15
367 [bits >> 2 & 3] & eorx) ^
368 bgx);
369 ((u32 *) dest)[3] =
370 SHORTSWAP32((video_font_draw_table15
371 [bits & 3] & eorx) ^
372 bgx);
wdenke55402c2004-03-14 16:51:43 +0000373 }
374 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
375 s++;
376 }
377 break;
wdenkc6097192002-11-03 00:24:07 +0000378
wdenke55402c2004-03-14 16:51:43 +0000379 case GDF_16BIT_565RGB:
380 while (count--) {
381 c = *s;
382 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
383 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000384 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000385 u8 bits = *cdat++;
386
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000387 ((u32 *) dest)[0] =
388 SHORTSWAP32((video_font_draw_table16
389 [bits >> 6] & eorx) ^
390 bgx);
391 ((u32 *) dest)[1] =
392 SHORTSWAP32((video_font_draw_table16
393 [bits >> 4 & 3] & eorx) ^
394 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200395
396 if (VIDEO_FONT_WIDTH == 4)
397 continue;
398
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000399 ((u32 *) dest)[2] =
400 SHORTSWAP32((video_font_draw_table16
401 [bits >> 2 & 3] & eorx) ^
402 bgx);
403 ((u32 *) dest)[3] =
404 SHORTSWAP32((video_font_draw_table16
405 [bits & 3] & eorx) ^
406 bgx);
wdenke55402c2004-03-14 16:51:43 +0000407 }
408 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
409 s++;
410 }
411 break;
412
413 case GDF_32BIT_X888RGB:
414 while (count--) {
415 c = *s;
416 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
417 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000418 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000419 u8 bits = *cdat++;
420
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000421 ((u32 *) dest)[0] =
422 SWAP32((video_font_draw_table32
423 [bits >> 4][0] & eorx) ^ bgx);
424 ((u32 *) dest)[1] =
425 SWAP32((video_font_draw_table32
426 [bits >> 4][1] & eorx) ^ bgx);
427 ((u32 *) dest)[2] =
428 SWAP32((video_font_draw_table32
429 [bits >> 4][2] & eorx) ^ bgx);
430 ((u32 *) dest)[3] =
431 SWAP32((video_font_draw_table32
432 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200433
434
435 if (VIDEO_FONT_WIDTH == 4)
436 continue;
437
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000438 ((u32 *) dest)[4] =
439 SWAP32((video_font_draw_table32
440 [bits & 15][0] & eorx) ^ bgx);
441 ((u32 *) dest)[5] =
442 SWAP32((video_font_draw_table32
443 [bits & 15][1] & eorx) ^ bgx);
444 ((u32 *) dest)[6] =
445 SWAP32((video_font_draw_table32
446 [bits & 15][2] & eorx) ^ bgx);
447 ((u32 *) dest)[7] =
448 SWAP32((video_font_draw_table32
449 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000450 }
451 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
452 s++;
453 }
454 break;
455
456 case GDF_24BIT_888RGB:
457 while (count--) {
458 c = *s;
459 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
460 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000461 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000462 u8 bits = *cdat++;
463
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000464 ((u32 *) dest)[0] =
465 (video_font_draw_table24[bits >> 4][0]
466 & eorx) ^ bgx;
467 ((u32 *) dest)[1] =
468 (video_font_draw_table24[bits >> 4][1]
469 & eorx) ^ bgx;
470 ((u32 *) dest)[2] =
471 (video_font_draw_table24[bits >> 4][2]
472 & eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200473
474 if (VIDEO_FONT_WIDTH == 4)
475 continue;
476
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000477 ((u32 *) dest)[3] =
478 (video_font_draw_table24[bits & 15][0]
479 & eorx) ^ bgx;
480 ((u32 *) dest)[4] =
481 (video_font_draw_table24[bits & 15][1]
482 & eorx) ^ bgx;
483 ((u32 *) dest)[5] =
484 (video_font_draw_table24[bits & 15][2]
485 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000486 }
487 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
488 s++;
489 }
490 break;
wdenk57b2d802003-06-27 21:31:46 +0000491 }
wdenkc6097192002-11-03 00:24:07 +0000492}
493
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000494static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000495{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000496 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000497}
498
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000499static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000500{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000501 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000502}
503
Simon Glassf406a1b2015-10-18 21:17:18 -0600504#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000505static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000506{
Gabe Black12874de2011-11-30 13:50:50 +0000507 if (cursor_state)
508 console_cursor(0);
509 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000510}
Gabe Black12874de2011-11-30 13:50:50 +0000511
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000512static void video_invertchar(int xx, int yy)
513{
514 int firstx = xx * VIDEO_PIXEL_SIZE;
515 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
516 int firsty = yy * VIDEO_LINE_LEN;
517 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
518 int x, y;
519 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
520 for (x = firstx; x < lastx; x++) {
521 u8 *dest = (u8 *)(video_fb_address) + x + y;
522 *dest = ~*dest;
523 }
524 }
525}
Gabe Black12874de2011-11-30 13:50:50 +0000526
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000527void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000528{
Gabe Black12874de2011-11-30 13:50:50 +0000529 if (cursor_state != state) {
530 if (cursor_state) {
531 /* turn off the cursor */
532 video_invertchar(old_col * VIDEO_FONT_WIDTH,
533 old_row * VIDEO_FONT_HEIGHT +
534 video_logo_height);
535 } else {
536 /* turn off the cursor and record where it is */
537 video_invertchar(console_col * VIDEO_FONT_WIDTH,
538 console_row * VIDEO_FONT_HEIGHT +
539 video_logo_height);
540 old_col = console_col;
541 old_row = console_row;
542 }
543 cursor_state = state;
wdenke55402c2004-03-14 16:51:43 +0000544 }
Eric Nelson54142422013-05-06 14:27:28 +0200545 if (cfb_do_flush_cache)
546 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000547}
548#endif
549
wdenkc6097192002-11-03 00:24:07 +0000550#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000551static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000552{
wdenke55402c2004-03-14 16:51:43 +0000553 while (c--)
554 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000555}
556#endif
557
wdenkc6097192002-11-03 00:24:07 +0000558#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000559static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000560{
wdenke55402c2004-03-14 16:51:43 +0000561 while (c--)
562 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000563}
564#endif
565
Pali Rohár16658612012-04-28 07:26:44 +0000566static void console_clear_line(int line, int begin, int end)
567{
568#ifdef VIDEO_HW_RECTFILL
569 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
570 VIDEO_FONT_WIDTH * begin, /* dest pos x */
571 video_logo_height +
572 VIDEO_FONT_HEIGHT * line, /* dest pos y */
573 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
574 VIDEO_FONT_HEIGHT, /* frame height */
575 bgx /* fill color */
576 );
577#else
578 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
579 memsetl(CONSOLE_ROW_FIRST +
580 CONSOLE_ROW_SIZE * line, /* offset of row */
581 CONSOLE_ROW_SIZE >> 2, /* length of row */
582 bgx /* fill color */
583 );
584 } else {
585 void *offset;
586 int i, size;
587
588 offset = CONSOLE_ROW_FIRST +
589 CONSOLE_ROW_SIZE * line + /* offset of row */
590 VIDEO_FONT_WIDTH *
591 VIDEO_PIXEL_SIZE * begin; /* offset of col */
592 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
593 size >>= 2; /* length to end for memsetl() */
594 /* fill at col offset of i'th line using bgx as fill color */
595 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
596 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
597 }
598#endif
599}
600
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000601static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000602{
Simon Glass6ceb7f02015-01-01 16:17:57 -0700603 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
604 int i;
605
wdenke55402c2004-03-14 16:51:43 +0000606 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000607
608#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000609 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
610 0, /* source pos x */
611 video_logo_height +
Simon Glass6ceb7f02015-01-01 16:17:57 -0700612 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000613 0, /* dest pos x */
614 video_logo_height, /* dest pos y */
615 VIDEO_VISIBLE_COLS, /* frame width */
616 VIDEO_VISIBLE_ROWS
617 - video_logo_height
Simon Glass6ceb7f02015-01-01 16:17:57 -0700618 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000619 );
wdenkc6097192002-11-03 00:24:07 +0000620#else
Simon Glass6ceb7f02015-01-01 16:17:57 -0700621 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
622 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000623#endif
wdenke55402c2004-03-14 16:51:43 +0000624 /* clear the last one */
Simon Glass6ceb7f02015-01-01 16:17:57 -0700625 for (i = 1; i <= rows; i++)
626 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
627
628 /* Decrement row number */
629 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000630}
631
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000632static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000633{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500634 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000635
wdenke55402c2004-03-14 16:51:43 +0000636 if (console_col < 0) {
637 console_col = CONSOLE_COLS - 1;
638 console_row--;
639 if (console_row < 0)
640 console_row = 0;
641 }
wdenkc6097192002-11-03 00:24:07 +0000642}
643
Pali Rohár4a57da32012-10-19 13:30:09 +0000644#ifdef CONFIG_CFB_CONSOLE_ANSI
645
646static void console_clear(void)
647{
648#ifdef VIDEO_HW_RECTFILL
649 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
650 0, /* dest pos x */
651 video_logo_height, /* dest pos y */
652 VIDEO_VISIBLE_COLS, /* frame width */
653 VIDEO_VISIBLE_ROWS, /* frame height */
654 bgx /* fill color */
655 );
656#else
657 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
658#endif
659}
660
661static void console_cursor_fix(void)
662{
663 if (console_row < 0)
664 console_row = 0;
665 if (console_row >= CONSOLE_ROWS)
666 console_row = CONSOLE_ROWS - 1;
667 if (console_col < 0)
668 console_col = 0;
669 if (console_col >= CONSOLE_COLS)
670 console_col = CONSOLE_COLS - 1;
671}
672
673static void console_cursor_up(int n)
674{
675 console_row -= n;
676 console_cursor_fix();
677}
678
679static void console_cursor_down(int n)
680{
681 console_row += n;
682 console_cursor_fix();
683}
684
685static void console_cursor_left(int n)
wdenkc6097192002-11-03 00:24:07 +0000686{
Pali Rohár4a57da32012-10-19 13:30:09 +0000687 console_col -= n;
688 console_cursor_fix();
689}
690
691static void console_cursor_right(int n)
692{
693 console_col += n;
694 console_cursor_fix();
695}
696
697static void console_cursor_set_position(int row, int col)
698{
699 if (console_row != -1)
700 console_row = row;
701 if (console_col != -1)
702 console_col = col;
703 console_cursor_fix();
704}
705
706static void console_previousline(int n)
707{
708 /* FIXME: also scroll terminal ? */
709 console_row -= n;
710 console_cursor_fix();
711}
712
713static void console_swap_colors(void)
714{
715 eorx = fgx;
716 fgx = bgx;
717 bgx = eorx;
718 eorx = fgx ^ bgx;
719}
720
721static inline int console_cursor_is_visible(void)
722{
723 return !ansi_cursor_hidden;
724}
725#else
726static inline int console_cursor_is_visible(void)
727{
728 return 1;
729}
730#endif
731
732static void console_newline(int n)
733{
734 console_row += n;
wdenke55402c2004-03-14 16:51:43 +0000735 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000736
wdenke55402c2004-03-14 16:51:43 +0000737 /* Check if we need to scroll the terminal */
738 if (console_row >= CONSOLE_ROWS) {
739 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000740 console_scrollup();
wdenke55402c2004-03-14 16:51:43 +0000741 }
wdenkc6097192002-11-03 00:24:07 +0000742}
743
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000744static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100745{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500746 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100747}
748
Pali Rohár4a57da32012-10-19 13:30:09 +0000749static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000750{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100751 static int nl = 1;
752
Pali Rohár4a57da32012-10-19 13:30:09 +0000753 if (console_cursor_is_visible())
754 CURSOR_OFF;
Gabe Black12874de2011-11-30 13:50:50 +0000755
wdenke55402c2004-03-14 16:51:43 +0000756 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100757 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000758 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000759 break;
wdenkc6097192002-11-03 00:24:07 +0000760
wdenke55402c2004-03-14 16:51:43 +0000761 case '\n': /* next line */
Heinrich Schuchardtd6ef6692018-03-18 14:24:39 +0100762 if (console_col || nl)
Pali Rohár4a57da32012-10-19 13:30:09 +0000763 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100764 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000765 break;
wdenkc6097192002-11-03 00:24:07 +0000766
wdenke55402c2004-03-14 16:51:43 +0000767 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500768 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000769 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000770
wdenke55402c2004-03-14 16:51:43 +0000771 if (console_col >= CONSOLE_COLS)
Pali Rohár4a57da32012-10-19 13:30:09 +0000772 console_newline(1);
wdenke55402c2004-03-14 16:51:43 +0000773 break;
wdenkc6097192002-11-03 00:24:07 +0000774
wdenke55402c2004-03-14 16:51:43 +0000775 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000776 console_back();
wdenke55402c2004-03-14 16:51:43 +0000777 break;
wdenkc6097192002-11-03 00:24:07 +0000778
Pali Rohár9d735b62012-04-28 07:26:47 +0000779 case 7: /* bell */
780 break; /* ignored */
781
wdenke55402c2004-03-14 16:51:43 +0000782 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000783 video_putchar(console_col * VIDEO_FONT_WIDTH,
784 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000785 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000786
wdenke55402c2004-03-14 16:51:43 +0000787 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100788 if (console_col >= CONSOLE_COLS) {
Pali Rohár4a57da32012-10-19 13:30:09 +0000789 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100790 nl = 0;
791 }
wdenke55402c2004-03-14 16:51:43 +0000792 }
Pali Rohár4a57da32012-10-19 13:30:09 +0000793
794 if (console_cursor_is_visible())
795 CURSOR_SET;
796}
797
Simon Glass88ecb9b2016-10-17 20:12:54 -0600798static void cfb_video_putc(struct stdio_dev *dev, const char c)
Pali Rohár4a57da32012-10-19 13:30:09 +0000799{
800#ifdef CONFIG_CFB_CONSOLE_ANSI
801 int i;
802
803 if (c == 27) {
804 for (i = 0; i < ansi_buf_size; ++i)
805 parse_putc(ansi_buf[i]);
806 ansi_buf[0] = 27;
807 ansi_buf_size = 1;
808 return;
809 }
810
811 if (ansi_buf_size > 0) {
812 /*
813 * 0 - ESC
814 * 1 - [
815 * 2 - num1
816 * 3 - ..
817 * 4 - ;
818 * 5 - num2
819 * 6 - ..
820 * - cchar
821 */
822 int next = 0;
823
824 int flush = 0;
825 int fail = 0;
826
827 int num1 = 0;
828 int num2 = 0;
829 int cchar = 0;
830
831 ansi_buf[ansi_buf_size++] = c;
832
833 if (ansi_buf_size >= sizeof(ansi_buf))
834 fail = 1;
835
836 for (i = 0; i < ansi_buf_size; ++i) {
837 if (fail)
838 break;
839
840 switch (next) {
841 case 0:
842 if (ansi_buf[i] == 27)
843 next = 1;
844 else
845 fail = 1;
846 break;
847
848 case 1:
849 if (ansi_buf[i] == '[')
850 next = 2;
851 else
852 fail = 1;
853 break;
854
855 case 2:
856 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
857 num1 = ansi_buf[i]-'0';
858 next = 3;
859 } else if (ansi_buf[i] != '?') {
860 --i;
861 num1 = 1;
862 next = 4;
863 }
864 break;
865
866 case 3:
867 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
868 num1 *= 10;
869 num1 += ansi_buf[i]-'0';
870 } else {
871 --i;
872 next = 4;
873 }
874 break;
875
876 case 4:
877 if (ansi_buf[i] != ';') {
878 --i;
879 next = 7;
880 } else
881 next = 5;
882 break;
883
884 case 5:
885 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
886 num2 = ansi_buf[i]-'0';
887 next = 6;
888 } else
889 fail = 1;
890 break;
891
892 case 6:
893 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
894 num2 *= 10;
895 num2 += ansi_buf[i]-'0';
896 } else {
897 --i;
898 next = 7;
899 }
900 break;
901
902 case 7:
903 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
904 || ansi_buf[i] == 'J'
905 || ansi_buf[i] == 'K'
906 || ansi_buf[i] == 'h'
907 || ansi_buf[i] == 'l'
908 || ansi_buf[i] == 'm') {
909 cchar = ansi_buf[i];
910 flush = 1;
911 } else
912 fail = 1;
913 break;
914 }
915 }
916
917 if (fail) {
918 for (i = 0; i < ansi_buf_size; ++i)
919 parse_putc(ansi_buf[i]);
920 ansi_buf_size = 0;
921 return;
922 }
923
924 if (flush) {
925 if (!ansi_cursor_hidden)
926 CURSOR_OFF;
927 ansi_buf_size = 0;
928 switch (cchar) {
929 case 'A':
930 /* move cursor num1 rows up */
931 console_cursor_up(num1);
932 break;
933 case 'B':
934 /* move cursor num1 rows down */
935 console_cursor_down(num1);
936 break;
937 case 'C':
938 /* move cursor num1 columns forward */
939 console_cursor_right(num1);
940 break;
941 case 'D':
942 /* move cursor num1 columns back */
943 console_cursor_left(num1);
944 break;
945 case 'E':
946 /* move cursor num1 rows up at begin of row */
947 console_previousline(num1);
948 break;
949 case 'F':
950 /* move cursor num1 rows down at begin of row */
951 console_newline(num1);
952 break;
953 case 'G':
954 /* move cursor to column num1 */
955 console_cursor_set_position(-1, num1-1);
956 break;
957 case 'H':
958 /* move cursor to row num1, column num2 */
959 console_cursor_set_position(num1-1, num2-1);
960 break;
961 case 'J':
962 /* clear console and move cursor to 0, 0 */
963 console_clear();
964 console_cursor_set_position(0, 0);
965 break;
966 case 'K':
967 /* clear line */
968 if (num1 == 0)
969 console_clear_line(console_row,
970 console_col,
971 CONSOLE_COLS-1);
972 else if (num1 == 1)
973 console_clear_line(console_row,
974 0, console_col);
975 else
976 console_clear_line(console_row,
977 0, CONSOLE_COLS-1);
978 break;
979 case 'h':
980 ansi_cursor_hidden = 0;
981 break;
982 case 'l':
983 ansi_cursor_hidden = 1;
984 break;
985 case 'm':
986 if (num1 == 0) { /* reset swapped colors */
987 if (ansi_colors_need_revert) {
988 console_swap_colors();
989 ansi_colors_need_revert = 0;
990 }
991 } else if (num1 == 7) { /* once swap colors */
992 if (!ansi_colors_need_revert) {
993 console_swap_colors();
994 ansi_colors_need_revert = 1;
995 }
996 }
997 break;
998 }
999 if (!ansi_cursor_hidden)
1000 CURSOR_SET;
1001 }
1002 } else {
1003 parse_putc(c);
1004 }
1005#else
1006 parse_putc(c);
1007#endif
Eric Nelson54142422013-05-06 14:27:28 +02001008 if (cfb_do_flush_cache)
1009 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabibe0c74e2010-08-27 15:45:47 -05001010}
wdenkc6097192002-11-03 00:24:07 +00001011
Simon Glass88ecb9b2016-10-17 20:12:54 -06001012static void cfb_video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001013{
Soeren Mochbd9c1312014-10-24 16:33:30 +02001014 int flush = cfb_do_flush_cache;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001015 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +00001016
Soeren Mochbd9c1312014-10-24 16:33:30 +02001017 /* temporarily disable cache flush */
1018 cfb_do_flush_cache = 0;
1019
wdenke55402c2004-03-14 16:51:43 +00001020 while (count--)
Simon Glass88ecb9b2016-10-17 20:12:54 -06001021 cfb_video_putc(dev, *s++);
Soeren Mochbd9c1312014-10-24 16:33:30 +02001022
1023 if (flush) {
1024 cfb_do_flush_cache = flush;
1025 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1026 }
wdenke55402c2004-03-14 16:51:43 +00001027}
1028
Anatolij Gustschina043c342010-05-01 22:21:09 +02001029/*
1030 * Do not enforce drivers (or board code) to provide empty
1031 * video_set_lut() if they do not support 8 bpp format.
1032 * Implement weak default function instead.
1033 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02001034__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001035 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +02001036{
1037}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001038
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001039#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +00001040
1041#define FILL_8BIT_332RGB(r,g,b) { \
1042 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1043 fb ++; \
1044}
1045
1046#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001047 *(unsigned short *)fb = \
1048 SWAP16((unsigned short)(((r>>3)<<10) | \
1049 ((g>>3)<<5) | \
1050 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001051 fb += 2; \
1052}
1053
1054#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001055 *(unsigned short *)fb = \
1056 SWAP16((unsigned short)((((r)>>3)<<11)| \
1057 (((g)>>2)<<5) | \
1058 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001059 fb += 2; \
1060}
1061
1062#define FILL_32BIT_X888RGB(r,g,b) { \
Andre Przywaracd7b1ee2017-03-06 01:13:38 +00001063 *(u32 *)fb = \
1064 SWAP32((unsigned int)(((r<<16) | \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001065 (g<<8) | \
1066 b))); \
wdenke55402c2004-03-14 16:51:43 +00001067 fb += 4; \
1068}
1069
1070#ifdef VIDEO_FB_LITTLE_ENDIAN
1071#define FILL_24BIT_888RGB(r,g,b) { \
1072 fb[0] = b; \
1073 fb[1] = g; \
1074 fb[2] = r; \
1075 fb += 3; \
1076}
1077#else
1078#define FILL_24BIT_888RGB(r,g,b) { \
1079 fb[0] = r; \
1080 fb[1] = g; \
1081 fb[2] = b; \
1082 fb += 3; \
1083}
1084#endif
1085
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001086#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001087static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001088{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001089 ushort *dst = (ushort *) fb;
1090 ushort color = (ushort) (((r >> 3) << 10) |
1091 ((g >> 3) << 5) |
1092 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001093 if (x & 1)
1094 *(--dst) = color;
1095 else
1096 *(++dst) = color;
1097}
1098#endif
wdenke55402c2004-03-14 16:51:43 +00001099
1100/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001101 * RLE8 bitmap support
1102 */
1103
1104#ifdef CONFIG_VIDEO_BMP_RLE8
1105/* Pre-calculated color table entry */
1106struct palette {
1107 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001108 unsigned short w; /* word */
1109 unsigned int dw; /* double word */
1110 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001111};
1112
1113/*
1114 * Helper to draw encoded/unencoded run.
1115 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001116static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1117 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001118{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001119 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001120 int *off;
1121 int enc_off = 1;
1122 int i;
1123
1124 /*
1125 * Setup offset of the color index in the bitmap.
1126 * Color index of encoded run is at offset 1.
1127 */
1128 off = enc ? &enc_off : &i;
1129
1130 switch (VIDEO_DATA_FORMAT) {
1131 case GDF__8BIT_INDEX:
1132 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001133 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001134 break;
1135 case GDF_15BIT_555RGB:
1136 case GDF_16BIT_565RGB:
1137 /* differences handled while pre-calculating palette */
1138 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001139 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001140 addr += 2;
1141 }
1142 break;
1143 case GDF_32BIT_X888RGB:
1144 for (i = 0; i < cnt; i++) {
Andre Przywaracd7b1ee2017-03-06 01:13:38 +00001145 *(u32 *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001146 addr += 4;
1147 }
1148 break;
1149 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001150 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001151}
1152
Simon Glass92e1f852015-05-13 07:02:27 -06001153static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001154 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001155{
1156 unsigned char *bm;
1157 unsigned char *fbp;
1158 unsigned int cnt, runlen;
1159 int decode = 1;
1160 int x, y, bpp, i, ncolors;
1161 struct palette p[256];
Simon Glass92e1f852015-05-13 07:02:27 -06001162 struct bmp_color_table_entry cte;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001163 int green_shift, red_off;
Hans de Goedea8287e72015-08-04 12:15:39 +02001164 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001165 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001166
1167 x = 0;
1168 y = __le32_to_cpu(img->header.height) - 1;
1169 ncolors = __le32_to_cpu(img->header.colors_used);
1170 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001171 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001172 (y + yoff) * VIDEO_LINE_LEN +
1173 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001174
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001175 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001176
1177 /* pre-calculate and setup palette */
1178 switch (VIDEO_DATA_FORMAT) {
1179 case GDF__8BIT_INDEX:
1180 for (i = 0; i < ncolors; i++) {
1181 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001182 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001183 }
1184 break;
1185 case GDF_15BIT_555RGB:
1186 case GDF_16BIT_565RGB:
1187 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1188 green_shift = 3;
1189 red_off = 10;
1190 } else {
1191 green_shift = 2;
1192 red_off = 11;
1193 }
1194 for (i = 0; i < ncolors; i++) {
1195 cte = img->color_table[i];
1196 p[i].ce.w = SWAP16((unsigned short)
1197 (((cte.red >> 3) << red_off) |
1198 ((cte.green >> green_shift) << 5) |
1199 cte.blue >> 3));
1200 }
1201 break;
1202 case GDF_32BIT_X888RGB:
1203 for (i = 0; i < ncolors; i++) {
1204 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001205 p[i].ce.dw = SWAP32((cte.red << 16) |
1206 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001207 cte.blue);
1208 }
1209 break;
1210 default:
1211 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001212 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001213 return -1;
1214 }
1215
1216 while (decode) {
1217 switch (bm[0]) {
1218 case 0:
1219 switch (bm[1]) {
1220 case 0:
1221 /* scan line end marker */
1222 bm += 2;
1223 x = 0;
1224 y--;
1225 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001226 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001227 (y + yoff) * VIDEO_LINE_LEN +
1228 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001229 continue;
1230 case 1:
1231 /* end of bitmap data marker */
1232 decode = 0;
1233 break;
1234 case 2:
1235 /* run offset marker */
1236 x += bm[2];
1237 y -= bm[3];
1238 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001239 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001240 (y + yoff) * VIDEO_LINE_LEN +
1241 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001242 bm += 4;
1243 break;
1244 default:
1245 /* unencoded run */
1246 cnt = bm[1];
1247 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001248 pixels += cnt;
1249 if (pixels > limit)
1250 goto error;
1251
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001252 bm += 2;
1253 if (y < height) {
1254 if (x >= width) {
1255 x += runlen;
1256 goto next_run;
1257 }
1258 if (x + runlen > width)
1259 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001260 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001261 x += runlen;
1262 }
1263next_run:
1264 bm += runlen;
1265 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001266 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001267 }
1268 break;
1269 default:
1270 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001271 cnt = bm[0];
1272 runlen = cnt;
1273 pixels += cnt;
1274 if (pixels > limit)
1275 goto error;
1276
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001277 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001278 if (x >= width) {
1279 x += runlen;
1280 bm += 2;
1281 continue;
1282 }
1283 if (x + runlen > width)
1284 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001285 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001286 x += runlen;
1287 }
1288 bm += 2;
1289 break;
1290 }
1291 }
Sébastien Szymanskia14dbb52018-09-10 09:58:58 +02001292
1293 if (cfb_do_flush_cache)
1294 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1295
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001296 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001297error:
1298 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1299 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001300}
1301#endif
1302
1303/*
wdenke55402c2004-03-14 16:51:43 +00001304 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001305 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001306int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001307{
1308 ushort xcount, ycount;
1309 uchar *fb;
Simon Glass92e1f852015-05-13 07:02:27 -06001310 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenke55402c2004-03-14 16:51:43 +00001311 uchar *bmap;
1312 ushort padded_line;
1313 unsigned long width, height, bpp;
1314 unsigned colors;
1315 unsigned long compression;
Simon Glass92e1f852015-05-13 07:02:27 -06001316 struct bmp_color_table_entry cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001317
Stefan Roesed9d97742005-09-22 09:04:17 +02001318#ifdef CONFIG_VIDEO_BMP_GZIP
1319 unsigned char *dst = NULL;
1320 ulong len;
1321#endif
wdenkc6097192002-11-03 00:24:07 +00001322
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001323 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001324
1325 if (!((bmp->header.signature[0] == 'B') &&
1326 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001327
1328#ifdef CONFIG_VIDEO_BMP_GZIP
1329 /*
1330 * Could be a gzipped bmp image, try to decrompress...
1331 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001332 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1333 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001334 if (dst == NULL) {
1335 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001336 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001337 }
Eric Nelsonfba70872014-03-08 07:55:52 -07001338 /*
1339 * NB: we need to force offset of +2
1340 * See doc/README.displaying-bmps
1341 */
1342 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001343 (uchar *) bmp_image,
1344 &len) != 0) {
1345 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1346 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001347 free(dst);
1348 return 1;
1349 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001350 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001351 printf("Image could be truncated "
1352 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001353 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001354
1355 /*
1356 * Set addr to decompressed image
1357 */
Simon Glass92e1f852015-05-13 07:02:27 -06001358 bmp = (struct bmp_image *)(dst+2);
Stefan Roesed9d97742005-09-22 09:04:17 +02001359
1360 if (!((bmp->header.signature[0] == 'B') &&
1361 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001362 printf("Error: no valid bmp.gz image at %lx\n",
1363 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001364 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001365 return 1;
1366 }
1367#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001368 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001369 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001370#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001371 }
1372
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001373 width = le32_to_cpu(bmp->header.width);
1374 height = le32_to_cpu(bmp->header.height);
1375 bpp = le16_to_cpu(bmp->header.bit_count);
1376 colors = le32_to_cpu(bmp->header.colors_used);
1377 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001378
Marek Vasut2eb9a492011-10-21 14:17:04 +00001379 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001380 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001381
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001382 if (compression != BMP_BI_RGB
1383#ifdef CONFIG_VIDEO_BMP_RLE8
1384 && compression != BMP_BI_RLE8
1385#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001386 ) {
1387 printf("Error: compression type %ld not supported\n",
1388 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001389#ifdef CONFIG_VIDEO_BMP_GZIP
1390 if (dst)
1391 free(dst);
1392#endif
wdenke55402c2004-03-14 16:51:43 +00001393 return 1;
1394 }
1395
1396 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1397
Matthias Weisser53884182009-07-09 16:07:30 +02001398#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1399 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001400 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001401 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001402 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001403
1404 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001405 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001406 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001407 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001408#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1409
Matthias Weisser5e5ed762013-02-15 03:35:12 +00001410 /*
1411 * Just ignore elements which are completely beyond screen
1412 * dimensions.
1413 */
1414 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1415 return 0;
1416
wdenke55402c2004-03-14 16:51:43 +00001417 if ((x + width) > VIDEO_VISIBLE_COLS)
1418 width = VIDEO_VISIBLE_COLS - x;
1419 if ((y + height) > VIDEO_VISIBLE_ROWS)
1420 height = VIDEO_VISIBLE_ROWS - y;
1421
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001422 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001423 fb = (uchar *) (video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001424 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenke55402c2004-03-14 16:51:43 +00001425 x * VIDEO_PIXEL_SIZE);
1426
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001427#ifdef CONFIG_VIDEO_BMP_RLE8
1428 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001429 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001430 }
1431#endif
1432
Timur Tabi0fce9922010-08-23 16:58:00 -05001433 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001434 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001435 case 4:
1436 padded_line -= width / 2;
1437 ycount = height;
1438
1439 switch (VIDEO_DATA_FORMAT) {
1440 case GDF_32BIT_X888RGB:
1441 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001442 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001443 /*
1444 * Don't assume that 'width' is an
1445 * even number
1446 */
1447 for (xcount = 0; xcount < width; xcount++) {
1448 uchar idx;
1449
1450 if (xcount & 1) {
1451 idx = *bmap & 0xF;
1452 bmap++;
1453 } else
1454 idx = *bmap >> 4;
1455 cte = bmp->color_table[idx];
1456 FILL_32BIT_X888RGB(cte.red, cte.green,
1457 cte.blue);
1458 }
1459 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001460 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001461 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001462 }
1463 break;
1464 default:
1465 puts("4bpp bitmap unsupported with current "
1466 "video mode\n");
1467 break;
1468 }
1469 break;
1470
wdenke55402c2004-03-14 16:51:43 +00001471 case 8:
1472 padded_line -= width;
1473 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001474 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001475 for (xcount = 0; xcount < colors; ++xcount) {
1476 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001477 video_set_lut(xcount, cte.red, cte.green,
1478 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001479 }
1480 }
1481 ycount = height;
1482 switch (VIDEO_DATA_FORMAT) {
1483 case GDF__8BIT_INDEX:
1484 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001485 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001486 xcount = width;
1487 while (xcount--) {
1488 *fb++ = *bmap++;
1489 }
1490 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001491 fb -= VIDEO_LINE_LEN + width *
1492 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001493 }
1494 break;
1495 case GDF__8BIT_332RGB:
1496 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001497 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001498 xcount = width;
1499 while (xcount--) {
1500 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001501 FILL_8BIT_332RGB(cte.red, cte.green,
1502 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001503 }
1504 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001505 fb -= VIDEO_LINE_LEN + width *
1506 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001507 }
1508 break;
1509 case GDF_15BIT_555RGB:
1510 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001511#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1512 int xpos = x;
1513#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001514 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001515 xcount = width;
1516 while (xcount--) {
1517 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001518#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001519 fill_555rgb_pswap(fb, xpos++, cte.red,
1520 cte.green,
1521 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001522 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001523#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001524 FILL_15BIT_555RGB(cte.red, cte.green,
1525 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001526#endif
wdenke55402c2004-03-14 16:51:43 +00001527 }
1528 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001529 fb -= VIDEO_LINE_LEN + width *
1530 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001531 }
1532 break;
1533 case GDF_16BIT_565RGB:
1534 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001535 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001536 xcount = width;
1537 while (xcount--) {
1538 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001539 FILL_16BIT_565RGB(cte.red, cte.green,
1540 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001541 }
1542 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001543 fb -= VIDEO_LINE_LEN + width *
1544 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001545 }
1546 break;
1547 case GDF_32BIT_X888RGB:
1548 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001549 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001550 xcount = width;
1551 while (xcount--) {
1552 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001553 FILL_32BIT_X888RGB(cte.red, cte.green,
1554 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001555 }
1556 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001557 fb -= VIDEO_LINE_LEN + width *
1558 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001559 }
1560 break;
1561 case GDF_24BIT_888RGB:
1562 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001563 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001564 xcount = width;
1565 while (xcount--) {
1566 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001567 FILL_24BIT_888RGB(cte.red, cte.green,
1568 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001569 }
1570 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001571 fb -= VIDEO_LINE_LEN + width *
1572 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001573 }
1574 break;
1575 }
1576 break;
1577 case 24:
1578 padded_line -= 3 * width;
1579 ycount = height;
1580 switch (VIDEO_DATA_FORMAT) {
1581 case GDF__8BIT_332RGB:
1582 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001583 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001584 xcount = width;
1585 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001586 FILL_8BIT_332RGB(bmap[2], bmap[1],
1587 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001588 bmap += 3;
1589 }
1590 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001591 fb -= VIDEO_LINE_LEN + width *
1592 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001593 }
1594 break;
1595 case GDF_15BIT_555RGB:
1596 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001597#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1598 int xpos = x;
1599#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001600 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001601 xcount = width;
1602 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001603#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001604 fill_555rgb_pswap(fb, xpos++, bmap[2],
1605 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001606 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001607#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001608 FILL_15BIT_555RGB(bmap[2], bmap[1],
1609 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001610#endif
wdenke55402c2004-03-14 16:51:43 +00001611 bmap += 3;
1612 }
1613 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001614 fb -= VIDEO_LINE_LEN + width *
1615 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001616 }
1617 break;
1618 case GDF_16BIT_565RGB:
1619 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001620 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001621 xcount = width;
1622 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001623 FILL_16BIT_565RGB(bmap[2], bmap[1],
1624 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001625 bmap += 3;
1626 }
1627 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001628 fb -= VIDEO_LINE_LEN + width *
1629 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001630 }
1631 break;
1632 case GDF_32BIT_X888RGB:
1633 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001634 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001635 xcount = width;
1636 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001637 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1638 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001639 bmap += 3;
1640 }
1641 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001642 fb -= VIDEO_LINE_LEN + width *
1643 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001644 }
1645 break;
1646 case GDF_24BIT_888RGB:
1647 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001648 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001649 xcount = width;
1650 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001651 FILL_24BIT_888RGB(bmap[2], bmap[1],
1652 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001653 bmap += 3;
1654 }
1655 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001656 fb -= VIDEO_LINE_LEN + width *
1657 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001658 }
1659 break;
1660 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001661 printf("Error: 24 bits/pixel bitmap incompatible "
1662 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001663 break;
1664 }
1665 break;
1666 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001667 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1668 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001669 break;
1670 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001671
1672#ifdef CONFIG_VIDEO_BMP_GZIP
1673 if (dst) {
1674 free(dst);
1675 }
1676#endif
1677
Eric Nelson54142422013-05-06 14:27:28 +02001678 if (cfb_do_flush_cache)
1679 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenke55402c2004-03-14 16:51:43 +00001680 return (0);
wdenkc6097192002-11-03 00:24:07 +00001681}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001682#endif
wdenkc6097192002-11-03 00:24:07 +00001683
wdenkc6097192002-11-03 00:24:07 +00001684
1685#ifdef CONFIG_VIDEO_LOGO
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001686static int video_logo_xpos;
1687static int video_logo_ypos;
1688
Hans de Goedeb922f782015-08-04 12:21:40 +02001689static void plot_logo_or_black(void *screen, int x, int y, int black);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001690
Hans de Goedeb922f782015-08-04 12:21:40 +02001691static void logo_plot(void *screen, int x, int y)
Bastian Ruppertd5932182012-09-13 22:29:02 +00001692{
Hans de Goedeb922f782015-08-04 12:21:40 +02001693 plot_logo_or_black(screen, x, y, 0);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001694}
1695
1696static void logo_black(void)
1697{
Hans de Goedeb922f782015-08-04 12:21:40 +02001698 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
Bastian Ruppertd5932182012-09-13 22:29:02 +00001699 1);
1700}
1701
Simon Glassed38aef2020-05-10 11:40:03 -06001702static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1703 char *const argv[])
Bastian Ruppertd5932182012-09-13 22:29:02 +00001704{
1705 if (argc != 1)
1706 return cmd_usage(cmdtp);
1707
1708 logo_black();
1709 return 0;
1710}
1711
1712U_BOOT_CMD(
1713 clrlogo, 1, 0, do_clrlogo,
1714 "fill the boot logo area with black",
1715 " "
1716 );
1717
Hans de Goedeb922f782015-08-04 12:21:40 +02001718static void plot_logo_or_black(void *screen, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001719{
wdenk9dd2b882002-12-03 21:28:10 +00001720
wdenke55402c2004-03-14 16:51:43 +00001721 int xcount, i;
Hans de Goedea8287e72015-08-04 12:15:39 +02001722 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001723 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001724 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1725 unsigned char *source;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001726 unsigned char *dest;
1727
1728#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1729 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001730 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001731 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001732 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001733
1734 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001735 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001736 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001737 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001738#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1739
Hans de Goedea8287e72015-08-04 12:15:39 +02001740 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001741
wdenk9dd2b882002-12-03 21:28:10 +00001742#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001743 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001744
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001745 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001746 logo_red = malloc(BMP_LOGO_COLORS);
1747 logo_green = malloc(BMP_LOGO_COLORS);
1748 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001749 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001750 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1751 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1752 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1753 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1754 }
wdenk9dd2b882002-12-03 21:28:10 +00001755#else
wdenke55402c2004-03-14 16:51:43 +00001756 source = linux_logo;
1757 logo_red = linux_logo_red;
1758 logo_green = linux_logo_green;
1759 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001760#endif
wdenk57b2d802003-06-27 21:31:46 +00001761
wdenke55402c2004-03-14 16:51:43 +00001762 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1763 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001764 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1765 logo_red[i], logo_green[i],
1766 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001767 }
wdenk57b2d802003-06-27 21:31:46 +00001768 }
wdenkc6097192002-11-03 00:24:07 +00001769
wdenke55402c2004-03-14 16:51:43 +00001770 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001771#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1772 int xpos = x;
1773#endif
wdenke55402c2004-03-14 16:51:43 +00001774 xcount = VIDEO_LOGO_WIDTH;
1775 while (xcount--) {
Bastian Ruppertd5932182012-09-13 22:29:02 +00001776 if (black) {
1777 r = 0x00;
1778 g = 0x00;
1779 b = 0x00;
1780 } else {
1781 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1782 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1783 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1784 }
wdenk57b2d802003-06-27 21:31:46 +00001785
wdenke55402c2004-03-14 16:51:43 +00001786 switch (VIDEO_DATA_FORMAT) {
1787 case GDF__8BIT_INDEX:
1788 *dest = *source;
1789 break;
1790 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001791 *dest = ((r >> 5) << 5) |
1792 ((g >> 5) << 2) |
1793 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001794 break;
1795 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001796#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001797 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001798#else
wdenke55402c2004-03-14 16:51:43 +00001799 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001800 SWAP16((unsigned short) (
1801 ((r >> 3) << 10) |
1802 ((g >> 3) << 5) |
1803 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001804#endif
wdenke55402c2004-03-14 16:51:43 +00001805 break;
1806 case GDF_16BIT_565RGB:
1807 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001808 SWAP16((unsigned short) (
1809 ((r >> 3) << 11) |
1810 ((g >> 2) << 5) |
1811 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001812 break;
1813 case GDF_32BIT_X888RGB:
Andre Przywaracd7b1ee2017-03-06 01:13:38 +00001814 *(u32 *) dest =
1815 SWAP32((u32) (
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001816 (r << 16) |
1817 (g << 8) |
1818 b));
wdenke55402c2004-03-14 16:51:43 +00001819 break;
1820 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001821#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001822 dest[0] = b;
1823 dest[1] = g;
1824 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001825#else
wdenke55402c2004-03-14 16:51:43 +00001826 dest[0] = r;
1827 dest[1] = g;
1828 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001829#endif
wdenke55402c2004-03-14 16:51:43 +00001830 break;
1831 }
1832 source++;
1833 dest += VIDEO_PIXEL_SIZE;
1834 }
1835 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001836 }
wdenk9dd2b882002-12-03 21:28:10 +00001837#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001838 free(logo_red);
1839 free(logo_green);
1840 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001841#endif
wdenkc6097192002-11-03 00:24:07 +00001842}
1843
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001844static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001845{
wdenke55402c2004-03-14 16:51:43 +00001846 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001847 __maybe_unused int y_off = 0;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001848 __maybe_unused ulong addr;
1849 __maybe_unused char *s;
Anatolij Gustschinea5a9622016-11-30 14:30:59 +01001850 __maybe_unused int len, ret, space;
wdenke55402c2004-03-14 16:51:43 +00001851
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +02001852 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
wdenke55402c2004-03-14 16:51:43 +00001853
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001854#ifdef CONFIG_SPLASH_SCREEN
Simon Glass64b723f2017-08-03 12:22:12 -06001855 s = env_get("splashimage");
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001856 if (s != NULL) {
Anatolij Gustschinea5a9622016-11-30 14:30:59 +01001857 ret = splash_screen_prepare();
1858 if (ret < 0)
1859 return video_fb_address;
Simon Glass3ff49ec2021-07-24 09:03:29 -06001860 addr = hextoul(s, NULL);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001861
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001862 if (video_display_bitmap(addr,
1863 video_logo_xpos,
1864 video_logo_ypos) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001865 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001866 return ((void *) (video_fb_address));
1867 }
1868 }
1869#endif /* CONFIG_SPLASH_SCREEN */
1870
Hans de Goedeb922f782015-08-04 12:21:40 +02001871 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001872
1873#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1874 /*
1875 * when using splashpos for video_logo, skip any info
1876 * output on video console if the logo is not at 0,0
1877 */
1878 if (video_logo_xpos || video_logo_ypos) {
1879 /*
1880 * video_logo_height is used in text and cursor offset
1881 * calculations. Since the console is below the logo,
1882 * we need to adjust the logo height
1883 */
1884 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001885 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001886 VIDEO_LOGO_HEIGHT) / 2);
1887 else if (video_logo_ypos > 0)
1888 video_logo_height += video_logo_ypos;
1889
1890 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1891 }
1892#endif
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02001893 if (board_cfb_skip())
1894 return 0;
wdenkc6097192002-11-03 00:24:07 +00001895
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001896 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001897
Tim Harvey98899462016-05-24 14:59:59 -07001898#ifndef CONFIG_HIDE_LOGO_VERSION
Peng Fan1d0ccac2018-01-02 15:25:37 +08001899 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001900 len = strlen(info);
1901
1902 if (len > space) {
Peng Fan1d0ccac2018-01-02 15:25:37 +08001903 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1904 uchar *p = (uchar *) info;
1905
1906 while (len) {
1907 if (len > space) {
1908 video_drawchars(xx, yy, p, space);
1909 len -= space;
1910
1911 p = (uchar *)p + space;
1912
1913 if (!y_off) {
1914 xx += VIDEO_FONT_WIDTH;
1915 space--;
1916 }
1917 yy += VIDEO_FONT_HEIGHT;
1918
1919 y_off++;
1920 } else {
1921 video_drawchars(xx, yy, p, len);
1922 len = 0;
1923 }
1924 }
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001925 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001926 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001927
1928#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001929 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001930 int i, n =
1931 ((video_logo_height -
1932 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001933
wdenke55402c2004-03-14 16:51:43 +00001934 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001935 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001936 if (!*info)
1937 continue;
1938
1939 len = strlen(info);
1940 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001941 video_drawchars(VIDEO_INFO_X,
1942 VIDEO_INFO_Y +
1943 (i + y_off) *
1944 VIDEO_FONT_HEIGHT,
1945 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001946 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001947 video_drawchars(VIDEO_INFO_X +
1948 VIDEO_FONT_WIDTH,
1949 VIDEO_INFO_Y +
1950 (i + y_off) *
1951 VIDEO_FONT_HEIGHT,
1952 (uchar *) info + space,
1953 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001954 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001955 video_drawstring(VIDEO_INFO_X,
1956 VIDEO_INFO_Y +
1957 (i + y_off) *
1958 VIDEO_FONT_HEIGHT,
1959 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001960 }
wdenke55402c2004-03-14 16:51:43 +00001961 }
1962 }
wdenkc6097192002-11-03 00:24:07 +00001963#endif
Tim Harvey98899462016-05-24 14:59:59 -07001964#endif
wdenkc6097192002-11-03 00:24:07 +00001965
Matthias Weisser76d70862010-01-12 12:06:31 +01001966 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001967}
1968#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001969
1970static int cfb_fb_is_in_dram(void)
1971{
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001972 struct bd_info *bd = gd->bd;
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001973 ulong start, end;
1974 int i;
1975
1976 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1977 start = bd->bi_dram[i].start;
1978 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1979 if ((ulong)video_fb_address >= start &&
1980 (ulong)video_fb_address < end)
1981 return 1;
1982 }
Stefan Roesee5842152020-08-12 13:32:41 +02001983
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001984 return 0;
1985}
wdenkc6097192002-11-03 00:24:07 +00001986
Heiko Schocher62759562013-10-22 11:06:06 +02001987void video_clear(void)
1988{
1989 if (!video_fb_address)
1990 return;
1991#ifdef VIDEO_HW_RECTFILL
1992 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
1993 0, /* dest pos x */
1994 0, /* dest pos y */
1995 VIDEO_VISIBLE_COLS, /* frame width */
1996 VIDEO_VISIBLE_ROWS, /* frame height */
1997 bgx /* fill color */
1998 );
1999#else
2000 memsetl(video_fb_address,
2001 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2002#endif
2003}
2004
Simon Glass88ecb9b2016-10-17 20:12:54 -06002005static int cfg_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002006{
wdenke55402c2004-03-14 16:51:43 +00002007 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002008
Wolfgang Denka87b2a952011-07-30 12:48:09 +00002009 pGD = video_hw_init();
2010 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00002011 return -1;
wdenkc6097192002-11-03 00:24:07 +00002012
wdenke55402c2004-03-14 16:51:43 +00002013 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002014
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002015 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2016
wdenke55402c2004-03-14 16:51:43 +00002017 /* Init drawing pats */
2018 switch (VIDEO_DATA_FORMAT) {
2019 case GDF__8BIT_INDEX:
Simon Glass884889d2016-10-17 20:12:44 -06002020 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2021 CONFIG_SYS_CONSOLE_FG_COL,
2022 CONFIG_SYS_CONSOLE_FG_COL);
2023 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2024 CONFIG_SYS_CONSOLE_BG_COL,
2025 CONFIG_SYS_CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00002026 fgx = 0x01010101;
2027 bgx = 0x00000000;
2028 break;
2029 case GDF__8BIT_332RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002030 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2031 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2032 CONFIG_SYS_CONSOLE_FG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002033 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2034 color8;
Simon Glass884889d2016-10-17 20:12:44 -06002035 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2036 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2037 CONFIG_SYS_CONSOLE_BG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002038 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2039 color8;
wdenke55402c2004-03-14 16:51:43 +00002040 break;
2041 case GDF_15BIT_555RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002042 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2043 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2044 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2045 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2046 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2047 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2048 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2049 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2050 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2051 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2052 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2053 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002054 break;
2055 case GDF_16BIT_565RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002056 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2057 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2058 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2059 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2061 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2062 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2063 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2064 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2065 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2067 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002068 break;
2069 case GDF_32BIT_X888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002070 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2071 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2072 CONFIG_SYS_CONSOLE_FG_COL;
2073 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2074 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2075 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002076 break;
2077 case GDF_24BIT_888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002078 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2079 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2080 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2081 CONFIG_SYS_CONSOLE_FG_COL;
2082 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2083 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2084 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2085 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002086 break;
2087 }
2088 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002089
Rob Clarkf1411882017-08-03 12:47:01 -04002090 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2091 video_clear();
Heiko Schocher62759562013-10-22 11:06:06 +02002092
wdenkc6097192002-11-03 00:24:07 +00002093#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00002094 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00002095 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002096 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002097#else
wdenke55402c2004-03-14 16:51:43 +00002098 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002099#endif
2100
wdenke55402c2004-03-14 16:51:43 +00002101 /* Initialize the console */
2102 console_col = 0;
2103 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002104
Eric Nelson54142422013-05-06 14:27:28 +02002105 if (cfb_do_flush_cache)
2106 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2107
wdenke55402c2004-03-14 16:51:43 +00002108 return 0;
wdenkc6097192002-11-03 00:24:07 +00002109}
2110
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002111/*
2112 * Implement a weak default function for boards that optionally
2113 * need to skip the video initialization.
2114 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02002115__weak int board_video_skip(void)
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002116{
2117 /* As default, don't skip test */
2118 return 0;
2119}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002120
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002121int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002122{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02002123 struct stdio_dev console_dev;
Simon Glasse9fa1f02015-03-02 12:40:50 -07002124 bool have_keyboard;
Bin Menge52e17a2015-08-24 01:00:07 -07002125 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00002126
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002127 /* Check if video initialization should be skipped */
2128 if (board_video_skip())
2129 return 0;
2130
wdenk7dd13292004-07-11 20:04:51 +00002131 /* Init video chip - returns with framebuffer cleared */
Simon Glass88ecb9b2016-10-17 20:12:54 -06002132 if (cfg_video_init() == -1)
Bin Menge52e17a2015-08-24 01:00:07 -07002133 return 0;
wdenkc6097192002-11-03 00:24:07 +00002134
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02002135 if (board_cfb_skip())
2136 return 0;
2137
Simon Glasse9fa1f02015-03-02 12:40:50 -07002138#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2139 have_keyboard = false;
2140#elif defined(CONFIG_OF_CONTROL)
2141 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2142 "u-boot,no-keyboard");
2143#else
2144 have_keyboard = true;
2145#endif
2146 if (have_keyboard) {
2147 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002148#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002149 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002150#endif
Simon Glasse9fa1f02015-03-02 12:40:50 -07002151 }
wdenkc6097192002-11-03 00:24:07 +00002152
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002153 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002154 memset(&console_dev, 0, sizeof(console_dev));
2155 strcpy(console_dev.name, "vga");
Bin Meng6abe4b62015-11-03 23:23:37 -08002156 console_dev.flags = DEV_FLAGS_OUTPUT;
Simon Glass88ecb9b2016-10-17 20:12:54 -06002157 console_dev.putc = cfb_video_putc; /* 'putc' function */
2158 console_dev.puts = cfb_video_puts; /* 'puts' function */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002159
2160#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002161 if (have_keyboard && keyboard_ok) {
Simon Glasse9fa1f02015-03-02 12:40:50 -07002162 /* Also init console device */
2163 console_dev.flags |= DEV_FLAGS_INPUT;
2164 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2165 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2166 }
2167#endif
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002168
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002169 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002170 return 0;
2171
2172 /* Return success */
2173 return 1;
wdenkc6097192002-11-03 00:24:07 +00002174}
Stefan Reinauer7870da32012-09-28 15:11:12 +00002175
2176void video_position_cursor(unsigned col, unsigned row)
2177{
2178 console_col = min(col, CONSOLE_COLS - 1);
2179 console_row = min(row, CONSOLE_ROWS - 1);
2180}
2181
2182int video_get_pixel_width(void)
2183{
2184 return VIDEO_VISIBLE_COLS;
2185}
2186
2187int video_get_pixel_height(void)
2188{
2189 return VIDEO_VISIBLE_ROWS;
2190}
2191
2192int video_get_screen_rows(void)
2193{
2194 return CONSOLE_ROWS;
2195}
2196
2197int video_get_screen_columns(void)
2198{
2199 return CONSOLE_COLS;
2200}