blob: 7df7d57e6ecccfae0e178626cc336348b3400605 [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>
Pali Rohárba87ddf2021-08-02 15:18:31 +020074#include <version_string.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>
Simon Glass0034d962021-08-07 07:24:01 -060078#include <dm/ofnode.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +000079#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +000080
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000081/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000082 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
83 */
wdenkc6097192002-11-03 00:24:07 +000084#include <video_fb.h>
85
Robert Winkler2a90ed02013-06-17 11:31:29 -070086#include <splash.h>
87
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000088/*
89 * some Macros
90 */
wdenke55402c2004-03-14 16:51:43 +000091#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
92#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
93#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
94#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
95#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +000096
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000097/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000098 * Console device
99 */
wdenkc6097192002-11-03 00:24:07 +0000100
wdenkc6097192002-11-03 00:24:07 +0000101#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200102#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000103#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000104
Jon Loeliger30c2f242007-07-10 11:13:21 -0500105#if defined(CONFIG_CMD_DATE)
106#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000107#endif
108
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500109#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000110#include <watchdog.h>
111#include <bmp_layout.h>
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +0200112#include <splash.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200113#endif
114
Simon Glassd615c892016-10-17 20:12:50 -0600115#if !defined(CONFIG_VIDEO_SW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000116/* no Cursor defined */
117#define CURSOR_ON
118#define CURSOR_OFF
119#define CURSOR_SET
120#endif
121
Simon Glassf406a1b2015-10-18 21:17:18 -0600122#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000123void console_cursor(int state);
124
Timur Tabibe0c74e2010-08-27 15:45:47 -0500125#define CURSOR_ON console_cursor(1)
126#define CURSOR_OFF console_cursor(0)
Gabe Black12874de2011-11-30 13:50:50 +0000127#define CURSOR_SET video_set_cursor()
Simon Glassf406a1b2015-10-18 21:17:18 -0600128#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000129
wdenke55402c2004-03-14 16:51:43 +0000130#ifdef CONFIG_VIDEO_LOGO
131#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000132#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000133#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000134#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
135#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
136#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
137#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000138
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000139#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000140#define LINUX_LOGO_WIDTH 80
141#define LINUX_LOGO_HEIGHT 80
142#define LINUX_LOGO_COLORS 214
143#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000144#define __initdata
145#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000146#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
147#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
148#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
149#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000150#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000151#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
152#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000153#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000154#define VIDEO_LOGO_WIDTH 0
155#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000156#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000157
wdenke55402c2004-03-14 16:51:43 +0000158#define VIDEO_COLS VIDEO_VISIBLE_COLS
159#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedea8287e72015-08-04 12:15:39 +0200160#ifndef VIDEO_LINE_LEN
161#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
162#endif
163#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenke55402c2004-03-14 16:51:43 +0000164#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000165
wdenke55402c2004-03-14 16:51:43 +0000166#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100167#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000168#else
wdenke55402c2004-03-14 16:51:43 +0000169#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000170#endif
171
wdenke55402c2004-03-14 16:51:43 +0000172#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
173#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
174#define CONSOLE_ROW_FIRST (video_console_address)
175#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
176#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
177#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass6ceb7f02015-01-01 16:17:57 -0700178
179/* By default we scroll by a single line */
180#ifndef CONFIG_CONSOLE_SCROLL_LINES
181#define CONFIG_CONSOLE_SCROLL_LINES 1
182#endif
wdenkc6097192002-11-03 00:24:07 +0000183
184/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000185#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000186#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
187 ((x) >> 8) \
188 )
189#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
190 (((x) & 0x0000ff00) << 8) | \
191 (((x) & 0x00ff0000) >> 8) | \
192 (((x) & 0xff000000) >> 24) \
193 )
194#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
195 (((x) & 0x0000ff00) >> 8) | \
196 (((x) & 0x00ff0000) << 8) | \
197 (((x) & 0xff000000) >> 8) \
198 )
wdenkc6097192002-11-03 00:24:07 +0000199#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000200#define SWAP16(x) (x)
201#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200202#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000203#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500204#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000205#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100206#endif
wdenkc6097192002-11-03 00:24:07 +0000207#endif
208
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200209DECLARE_GLOBAL_DATA_PTR;
210
wdenkc6097192002-11-03 00:24:07 +0000211/* Locals */
212static GraphicDevice *pGD; /* Pointer to Graphic array */
213
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000214static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000215static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000216
Matthias Weisser76d70862010-01-12 12:06:31 +0100217static int video_logo_height = VIDEO_LOGO_HEIGHT;
218
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000219static int __maybe_unused cursor_state;
220static int __maybe_unused old_col;
221static int __maybe_unused old_row;
Gabe Black12874de2011-11-30 13:50:50 +0000222
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000223static int console_col; /* cursor col */
224static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000225
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000226static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000227
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200228static int cfb_do_flush_cache;
229
Pali Rohár4a57da32012-10-19 13:30:09 +0000230#ifdef CONFIG_CFB_CONSOLE_ANSI
231static char ansi_buf[10];
232static int ansi_buf_size;
233static int ansi_colors_need_revert;
234static int ansi_cursor_hidden;
235#endif
236
wdenkc6097192002-11-03 00:24:07 +0000237static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000238 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
239 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
240 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
241 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
242};
wdenkc6097192002-11-03 00:24:07 +0000243
244static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000245 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
246};
wdenkc6097192002-11-03 00:24:07 +0000247
248static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000249 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
250};
wdenkc6097192002-11-03 00:24:07 +0000251
252static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000253 {0x00000000, 0x00000000, 0x00000000},
254 {0x00000000, 0x00000000, 0x00ffffff},
255 {0x00000000, 0x0000ffff, 0xff000000},
256 {0x00000000, 0x0000ffff, 0xffffffff},
257 {0x000000ff, 0xffff0000, 0x00000000},
258 {0x000000ff, 0xffff0000, 0x00ffffff},
259 {0x000000ff, 0xffffffff, 0xff000000},
260 {0x000000ff, 0xffffffff, 0xffffffff},
261 {0xffffff00, 0x00000000, 0x00000000},
262 {0xffffff00, 0x00000000, 0x00ffffff},
263 {0xffffff00, 0x0000ffff, 0xff000000},
264 {0xffffff00, 0x0000ffff, 0xffffffff},
265 {0xffffffff, 0xffff0000, 0x00000000},
266 {0xffffffff, 0xffff0000, 0x00ffffff},
267 {0xffffffff, 0xffffffff, 0xff000000},
268 {0xffffffff, 0xffffffff, 0xffffffff}
269};
wdenkc6097192002-11-03 00:24:07 +0000270
271static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000272 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
273 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
274 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
275 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
276 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
277 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
278 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
279 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
280 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
281 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
282 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
283 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
284 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
285 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
286 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
287 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
288};
wdenkc6097192002-11-03 00:24:07 +0000289
Heiko Schocher9cff8ad2013-08-03 07:22:53 +0200290/*
291 * Implement a weak default function for boards that optionally
292 * need to skip the cfb initialization.
293 */
294__weak int board_cfb_skip(void)
295{
296 /* As default, don't skip cfb init */
297 return 0;
298}
299
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000300static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000301{
wdenke55402c2004-03-14 16:51:43 +0000302 u8 *cdat, *dest, *dest0;
303 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000304
wdenke55402c2004-03-14 16:51:43 +0000305 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
306 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000307
wdenke55402c2004-03-14 16:51:43 +0000308 switch (VIDEO_DATA_FORMAT) {
309 case GDF__8BIT_INDEX:
310 case GDF__8BIT_332RGB:
311 while (count--) {
312 c = *s;
313 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
314 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000315 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000316 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000317
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000318 ((u32 *) dest)[0] =
319 (video_font_draw_table8[bits >> 4] &
320 eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200321
322 if (VIDEO_FONT_WIDTH == 4)
323 continue;
324
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000325 ((u32 *) dest)[1] =
326 (video_font_draw_table8[bits & 15] &
327 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000328 }
329 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
330 s++;
331 }
332 break;
wdenkc6097192002-11-03 00:24:07 +0000333
wdenke55402c2004-03-14 16:51:43 +0000334 case GDF_15BIT_555RGB:
335 while (count--) {
336 c = *s;
337 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
338 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000339 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000340 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000341
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000342 ((u32 *) dest)[0] =
343 SHORTSWAP32((video_font_draw_table15
344 [bits >> 6] & eorx) ^
345 bgx);
346 ((u32 *) dest)[1] =
347 SHORTSWAP32((video_font_draw_table15
348 [bits >> 4 & 3] & eorx) ^
349 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200350
351 if (VIDEO_FONT_WIDTH == 4)
352 continue;
353
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000354 ((u32 *) dest)[2] =
355 SHORTSWAP32((video_font_draw_table15
356 [bits >> 2 & 3] & eorx) ^
357 bgx);
358 ((u32 *) dest)[3] =
359 SHORTSWAP32((video_font_draw_table15
360 [bits & 3] & eorx) ^
361 bgx);
wdenke55402c2004-03-14 16:51:43 +0000362 }
363 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
364 s++;
365 }
366 break;
wdenkc6097192002-11-03 00:24:07 +0000367
wdenke55402c2004-03-14 16:51:43 +0000368 case GDF_16BIT_565RGB:
369 while (count--) {
370 c = *s;
371 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
372 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000373 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000374 u8 bits = *cdat++;
375
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000376 ((u32 *) dest)[0] =
377 SHORTSWAP32((video_font_draw_table16
378 [bits >> 6] & eorx) ^
379 bgx);
380 ((u32 *) dest)[1] =
381 SHORTSWAP32((video_font_draw_table16
382 [bits >> 4 & 3] & eorx) ^
383 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200384
385 if (VIDEO_FONT_WIDTH == 4)
386 continue;
387
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000388 ((u32 *) dest)[2] =
389 SHORTSWAP32((video_font_draw_table16
390 [bits >> 2 & 3] & eorx) ^
391 bgx);
392 ((u32 *) dest)[3] =
393 SHORTSWAP32((video_font_draw_table16
394 [bits & 3] & eorx) ^
395 bgx);
wdenke55402c2004-03-14 16:51:43 +0000396 }
397 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
398 s++;
399 }
400 break;
401
402 case GDF_32BIT_X888RGB:
403 while (count--) {
404 c = *s;
405 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
406 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000407 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000408 u8 bits = *cdat++;
409
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000410 ((u32 *) dest)[0] =
411 SWAP32((video_font_draw_table32
412 [bits >> 4][0] & eorx) ^ bgx);
413 ((u32 *) dest)[1] =
414 SWAP32((video_font_draw_table32
415 [bits >> 4][1] & eorx) ^ bgx);
416 ((u32 *) dest)[2] =
417 SWAP32((video_font_draw_table32
418 [bits >> 4][2] & eorx) ^ bgx);
419 ((u32 *) dest)[3] =
420 SWAP32((video_font_draw_table32
421 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200422
423
424 if (VIDEO_FONT_WIDTH == 4)
425 continue;
426
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000427 ((u32 *) dest)[4] =
428 SWAP32((video_font_draw_table32
429 [bits & 15][0] & eorx) ^ bgx);
430 ((u32 *) dest)[5] =
431 SWAP32((video_font_draw_table32
432 [bits & 15][1] & eorx) ^ bgx);
433 ((u32 *) dest)[6] =
434 SWAP32((video_font_draw_table32
435 [bits & 15][2] & eorx) ^ bgx);
436 ((u32 *) dest)[7] =
437 SWAP32((video_font_draw_table32
438 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000439 }
440 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
441 s++;
442 }
443 break;
444
445 case GDF_24BIT_888RGB:
446 while (count--) {
447 c = *s;
448 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
449 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000450 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000451 u8 bits = *cdat++;
452
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000453 ((u32 *) dest)[0] =
454 (video_font_draw_table24[bits >> 4][0]
455 & eorx) ^ bgx;
456 ((u32 *) dest)[1] =
457 (video_font_draw_table24[bits >> 4][1]
458 & eorx) ^ bgx;
459 ((u32 *) dest)[2] =
460 (video_font_draw_table24[bits >> 4][2]
461 & eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200462
463 if (VIDEO_FONT_WIDTH == 4)
464 continue;
465
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000466 ((u32 *) dest)[3] =
467 (video_font_draw_table24[bits & 15][0]
468 & eorx) ^ bgx;
469 ((u32 *) dest)[4] =
470 (video_font_draw_table24[bits & 15][1]
471 & eorx) ^ bgx;
472 ((u32 *) dest)[5] =
473 (video_font_draw_table24[bits & 15][2]
474 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000475 }
476 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
477 s++;
478 }
479 break;
wdenk57b2d802003-06-27 21:31:46 +0000480 }
wdenkc6097192002-11-03 00:24:07 +0000481}
482
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000483static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000484{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000485 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000486}
487
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000488static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000489{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000490 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000491}
492
Simon Glassf406a1b2015-10-18 21:17:18 -0600493#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000494static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000495{
Gabe Black12874de2011-11-30 13:50:50 +0000496 if (cursor_state)
497 console_cursor(0);
498 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000499}
Gabe Black12874de2011-11-30 13:50:50 +0000500
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000501static void video_invertchar(int xx, int yy)
502{
503 int firstx = xx * VIDEO_PIXEL_SIZE;
504 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
505 int firsty = yy * VIDEO_LINE_LEN;
506 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
507 int x, y;
508 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
509 for (x = firstx; x < lastx; x++) {
510 u8 *dest = (u8 *)(video_fb_address) + x + y;
511 *dest = ~*dest;
512 }
513 }
514}
Gabe Black12874de2011-11-30 13:50:50 +0000515
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000516void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000517{
Gabe Black12874de2011-11-30 13:50:50 +0000518 if (cursor_state != state) {
519 if (cursor_state) {
520 /* turn off the cursor */
521 video_invertchar(old_col * VIDEO_FONT_WIDTH,
522 old_row * VIDEO_FONT_HEIGHT +
523 video_logo_height);
524 } else {
525 /* turn off the cursor and record where it is */
526 video_invertchar(console_col * VIDEO_FONT_WIDTH,
527 console_row * VIDEO_FONT_HEIGHT +
528 video_logo_height);
529 old_col = console_col;
530 old_row = console_row;
531 }
532 cursor_state = state;
wdenke55402c2004-03-14 16:51:43 +0000533 }
Eric Nelson54142422013-05-06 14:27:28 +0200534 if (cfb_do_flush_cache)
535 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000536}
537#endif
538
wdenkc6097192002-11-03 00:24:07 +0000539#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000540static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000541{
wdenke55402c2004-03-14 16:51:43 +0000542 while (c--)
543 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000544}
545#endif
546
wdenkc6097192002-11-03 00:24:07 +0000547#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000548static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000549{
wdenke55402c2004-03-14 16:51:43 +0000550 while (c--)
551 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000552}
553#endif
554
Pali Rohár16658612012-04-28 07:26:44 +0000555static void console_clear_line(int line, int begin, int end)
556{
557#ifdef VIDEO_HW_RECTFILL
558 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
559 VIDEO_FONT_WIDTH * begin, /* dest pos x */
560 video_logo_height +
561 VIDEO_FONT_HEIGHT * line, /* dest pos y */
562 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
563 VIDEO_FONT_HEIGHT, /* frame height */
564 bgx /* fill color */
565 );
566#else
567 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
568 memsetl(CONSOLE_ROW_FIRST +
569 CONSOLE_ROW_SIZE * line, /* offset of row */
570 CONSOLE_ROW_SIZE >> 2, /* length of row */
571 bgx /* fill color */
572 );
573 } else {
574 void *offset;
575 int i, size;
576
577 offset = CONSOLE_ROW_FIRST +
578 CONSOLE_ROW_SIZE * line + /* offset of row */
579 VIDEO_FONT_WIDTH *
580 VIDEO_PIXEL_SIZE * begin; /* offset of col */
581 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
582 size >>= 2; /* length to end for memsetl() */
583 /* fill at col offset of i'th line using bgx as fill color */
584 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
585 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
586 }
587#endif
588}
589
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000590static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000591{
Simon Glass6ceb7f02015-01-01 16:17:57 -0700592 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
593 int i;
594
wdenke55402c2004-03-14 16:51:43 +0000595 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000596
597#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000598 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
599 0, /* source pos x */
600 video_logo_height +
Simon Glass6ceb7f02015-01-01 16:17:57 -0700601 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000602 0, /* dest pos x */
603 video_logo_height, /* dest pos y */
604 VIDEO_VISIBLE_COLS, /* frame width */
605 VIDEO_VISIBLE_ROWS
606 - video_logo_height
Simon Glass6ceb7f02015-01-01 16:17:57 -0700607 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000608 );
wdenkc6097192002-11-03 00:24:07 +0000609#else
Simon Glass6ceb7f02015-01-01 16:17:57 -0700610 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
611 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000612#endif
wdenke55402c2004-03-14 16:51:43 +0000613 /* clear the last one */
Simon Glass6ceb7f02015-01-01 16:17:57 -0700614 for (i = 1; i <= rows; i++)
615 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
616
617 /* Decrement row number */
618 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000619}
620
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000621static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000622{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500623 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000624
wdenke55402c2004-03-14 16:51:43 +0000625 if (console_col < 0) {
626 console_col = CONSOLE_COLS - 1;
627 console_row--;
628 if (console_row < 0)
629 console_row = 0;
630 }
wdenkc6097192002-11-03 00:24:07 +0000631}
632
Pali Rohár4a57da32012-10-19 13:30:09 +0000633#ifdef CONFIG_CFB_CONSOLE_ANSI
634
635static void console_clear(void)
636{
637#ifdef VIDEO_HW_RECTFILL
638 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
639 0, /* dest pos x */
640 video_logo_height, /* dest pos y */
641 VIDEO_VISIBLE_COLS, /* frame width */
642 VIDEO_VISIBLE_ROWS, /* frame height */
643 bgx /* fill color */
644 );
645#else
646 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
647#endif
648}
649
650static void console_cursor_fix(void)
651{
652 if (console_row < 0)
653 console_row = 0;
654 if (console_row >= CONSOLE_ROWS)
655 console_row = CONSOLE_ROWS - 1;
656 if (console_col < 0)
657 console_col = 0;
658 if (console_col >= CONSOLE_COLS)
659 console_col = CONSOLE_COLS - 1;
660}
661
662static void console_cursor_up(int n)
663{
664 console_row -= n;
665 console_cursor_fix();
666}
667
668static void console_cursor_down(int n)
669{
670 console_row += n;
671 console_cursor_fix();
672}
673
674static void console_cursor_left(int n)
wdenkc6097192002-11-03 00:24:07 +0000675{
Pali Rohár4a57da32012-10-19 13:30:09 +0000676 console_col -= n;
677 console_cursor_fix();
678}
679
680static void console_cursor_right(int n)
681{
682 console_col += n;
683 console_cursor_fix();
684}
685
686static void console_cursor_set_position(int row, int col)
687{
688 if (console_row != -1)
689 console_row = row;
690 if (console_col != -1)
691 console_col = col;
692 console_cursor_fix();
693}
694
695static void console_previousline(int n)
696{
697 /* FIXME: also scroll terminal ? */
698 console_row -= n;
699 console_cursor_fix();
700}
701
702static void console_swap_colors(void)
703{
704 eorx = fgx;
705 fgx = bgx;
706 bgx = eorx;
707 eorx = fgx ^ bgx;
708}
709
710static inline int console_cursor_is_visible(void)
711{
712 return !ansi_cursor_hidden;
713}
714#else
715static inline int console_cursor_is_visible(void)
716{
717 return 1;
718}
719#endif
720
721static void console_newline(int n)
722{
723 console_row += n;
wdenke55402c2004-03-14 16:51:43 +0000724 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000725
wdenke55402c2004-03-14 16:51:43 +0000726 /* Check if we need to scroll the terminal */
727 if (console_row >= CONSOLE_ROWS) {
728 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000729 console_scrollup();
wdenke55402c2004-03-14 16:51:43 +0000730 }
wdenkc6097192002-11-03 00:24:07 +0000731}
732
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000733static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100734{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500735 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100736}
737
Pali Rohár4a57da32012-10-19 13:30:09 +0000738static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000739{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100740 static int nl = 1;
741
Pali Rohár4a57da32012-10-19 13:30:09 +0000742 if (console_cursor_is_visible())
743 CURSOR_OFF;
Gabe Black12874de2011-11-30 13:50:50 +0000744
wdenke55402c2004-03-14 16:51:43 +0000745 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100746 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000747 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000748 break;
wdenkc6097192002-11-03 00:24:07 +0000749
wdenke55402c2004-03-14 16:51:43 +0000750 case '\n': /* next line */
Heinrich Schuchardtd6ef6692018-03-18 14:24:39 +0100751 if (console_col || nl)
Pali Rohár4a57da32012-10-19 13:30:09 +0000752 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100753 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000754 break;
wdenkc6097192002-11-03 00:24:07 +0000755
wdenke55402c2004-03-14 16:51:43 +0000756 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500757 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000758 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000759
wdenke55402c2004-03-14 16:51:43 +0000760 if (console_col >= CONSOLE_COLS)
Pali Rohár4a57da32012-10-19 13:30:09 +0000761 console_newline(1);
wdenke55402c2004-03-14 16:51:43 +0000762 break;
wdenkc6097192002-11-03 00:24:07 +0000763
wdenke55402c2004-03-14 16:51:43 +0000764 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000765 console_back();
wdenke55402c2004-03-14 16:51:43 +0000766 break;
wdenkc6097192002-11-03 00:24:07 +0000767
Pali Rohár9d735b62012-04-28 07:26:47 +0000768 case 7: /* bell */
769 break; /* ignored */
770
wdenke55402c2004-03-14 16:51:43 +0000771 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000772 video_putchar(console_col * VIDEO_FONT_WIDTH,
773 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000774 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000775
wdenke55402c2004-03-14 16:51:43 +0000776 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100777 if (console_col >= CONSOLE_COLS) {
Pali Rohár4a57da32012-10-19 13:30:09 +0000778 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100779 nl = 0;
780 }
wdenke55402c2004-03-14 16:51:43 +0000781 }
Pali Rohár4a57da32012-10-19 13:30:09 +0000782
783 if (console_cursor_is_visible())
784 CURSOR_SET;
785}
786
Simon Glass88ecb9b2016-10-17 20:12:54 -0600787static void cfb_video_putc(struct stdio_dev *dev, const char c)
Pali Rohár4a57da32012-10-19 13:30:09 +0000788{
789#ifdef CONFIG_CFB_CONSOLE_ANSI
790 int i;
791
792 if (c == 27) {
793 for (i = 0; i < ansi_buf_size; ++i)
794 parse_putc(ansi_buf[i]);
795 ansi_buf[0] = 27;
796 ansi_buf_size = 1;
797 return;
798 }
799
800 if (ansi_buf_size > 0) {
801 /*
802 * 0 - ESC
803 * 1 - [
804 * 2 - num1
805 * 3 - ..
806 * 4 - ;
807 * 5 - num2
808 * 6 - ..
809 * - cchar
810 */
811 int next = 0;
812
813 int flush = 0;
814 int fail = 0;
815
816 int num1 = 0;
817 int num2 = 0;
818 int cchar = 0;
819
820 ansi_buf[ansi_buf_size++] = c;
821
822 if (ansi_buf_size >= sizeof(ansi_buf))
823 fail = 1;
824
825 for (i = 0; i < ansi_buf_size; ++i) {
826 if (fail)
827 break;
828
829 switch (next) {
830 case 0:
831 if (ansi_buf[i] == 27)
832 next = 1;
833 else
834 fail = 1;
835 break;
836
837 case 1:
838 if (ansi_buf[i] == '[')
839 next = 2;
840 else
841 fail = 1;
842 break;
843
844 case 2:
845 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
846 num1 = ansi_buf[i]-'0';
847 next = 3;
848 } else if (ansi_buf[i] != '?') {
849 --i;
850 num1 = 1;
851 next = 4;
852 }
853 break;
854
855 case 3:
856 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
857 num1 *= 10;
858 num1 += ansi_buf[i]-'0';
859 } else {
860 --i;
861 next = 4;
862 }
863 break;
864
865 case 4:
866 if (ansi_buf[i] != ';') {
867 --i;
868 next = 7;
869 } else
870 next = 5;
871 break;
872
873 case 5:
874 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
875 num2 = ansi_buf[i]-'0';
876 next = 6;
877 } else
878 fail = 1;
879 break;
880
881 case 6:
882 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
883 num2 *= 10;
884 num2 += ansi_buf[i]-'0';
885 } else {
886 --i;
887 next = 7;
888 }
889 break;
890
891 case 7:
892 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
893 || ansi_buf[i] == 'J'
894 || ansi_buf[i] == 'K'
895 || ansi_buf[i] == 'h'
896 || ansi_buf[i] == 'l'
897 || ansi_buf[i] == 'm') {
898 cchar = ansi_buf[i];
899 flush = 1;
900 } else
901 fail = 1;
902 break;
903 }
904 }
905
906 if (fail) {
907 for (i = 0; i < ansi_buf_size; ++i)
908 parse_putc(ansi_buf[i]);
909 ansi_buf_size = 0;
910 return;
911 }
912
913 if (flush) {
914 if (!ansi_cursor_hidden)
915 CURSOR_OFF;
916 ansi_buf_size = 0;
917 switch (cchar) {
918 case 'A':
919 /* move cursor num1 rows up */
920 console_cursor_up(num1);
921 break;
922 case 'B':
923 /* move cursor num1 rows down */
924 console_cursor_down(num1);
925 break;
926 case 'C':
927 /* move cursor num1 columns forward */
928 console_cursor_right(num1);
929 break;
930 case 'D':
931 /* move cursor num1 columns back */
932 console_cursor_left(num1);
933 break;
934 case 'E':
935 /* move cursor num1 rows up at begin of row */
936 console_previousline(num1);
937 break;
938 case 'F':
939 /* move cursor num1 rows down at begin of row */
940 console_newline(num1);
941 break;
942 case 'G':
943 /* move cursor to column num1 */
944 console_cursor_set_position(-1, num1-1);
945 break;
946 case 'H':
947 /* move cursor to row num1, column num2 */
948 console_cursor_set_position(num1-1, num2-1);
949 break;
950 case 'J':
951 /* clear console and move cursor to 0, 0 */
952 console_clear();
953 console_cursor_set_position(0, 0);
954 break;
955 case 'K':
956 /* clear line */
957 if (num1 == 0)
958 console_clear_line(console_row,
959 console_col,
960 CONSOLE_COLS-1);
961 else if (num1 == 1)
962 console_clear_line(console_row,
963 0, console_col);
964 else
965 console_clear_line(console_row,
966 0, CONSOLE_COLS-1);
967 break;
968 case 'h':
969 ansi_cursor_hidden = 0;
970 break;
971 case 'l':
972 ansi_cursor_hidden = 1;
973 break;
974 case 'm':
975 if (num1 == 0) { /* reset swapped colors */
976 if (ansi_colors_need_revert) {
977 console_swap_colors();
978 ansi_colors_need_revert = 0;
979 }
980 } else if (num1 == 7) { /* once swap colors */
981 if (!ansi_colors_need_revert) {
982 console_swap_colors();
983 ansi_colors_need_revert = 1;
984 }
985 }
986 break;
987 }
988 if (!ansi_cursor_hidden)
989 CURSOR_SET;
990 }
991 } else {
992 parse_putc(c);
993 }
994#else
995 parse_putc(c);
996#endif
Eric Nelson54142422013-05-06 14:27:28 +0200997 if (cfb_do_flush_cache)
998 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabibe0c74e2010-08-27 15:45:47 -0500999}
wdenkc6097192002-11-03 00:24:07 +00001000
Simon Glass88ecb9b2016-10-17 20:12:54 -06001001static void cfb_video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001002{
Soeren Mochbd9c1312014-10-24 16:33:30 +02001003 int flush = cfb_do_flush_cache;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001004 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +00001005
Soeren Mochbd9c1312014-10-24 16:33:30 +02001006 /* temporarily disable cache flush */
1007 cfb_do_flush_cache = 0;
1008
wdenke55402c2004-03-14 16:51:43 +00001009 while (count--)
Simon Glass88ecb9b2016-10-17 20:12:54 -06001010 cfb_video_putc(dev, *s++);
Soeren Mochbd9c1312014-10-24 16:33:30 +02001011
1012 if (flush) {
1013 cfb_do_flush_cache = flush;
1014 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1015 }
wdenke55402c2004-03-14 16:51:43 +00001016}
1017
Anatolij Gustschina043c342010-05-01 22:21:09 +02001018/*
1019 * Do not enforce drivers (or board code) to provide empty
1020 * video_set_lut() if they do not support 8 bpp format.
1021 * Implement weak default function instead.
1022 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02001023__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001024 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +02001025{
1026}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001027
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001028#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +00001029
1030#define FILL_8BIT_332RGB(r,g,b) { \
1031 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1032 fb ++; \
1033}
1034
1035#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001036 *(unsigned short *)fb = \
1037 SWAP16((unsigned short)(((r>>3)<<10) | \
1038 ((g>>3)<<5) | \
1039 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001040 fb += 2; \
1041}
1042
1043#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001044 *(unsigned short *)fb = \
1045 SWAP16((unsigned short)((((r)>>3)<<11)| \
1046 (((g)>>2)<<5) | \
1047 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001048 fb += 2; \
1049}
1050
1051#define FILL_32BIT_X888RGB(r,g,b) { \
Andre Przywaracd7b1ee2017-03-06 01:13:38 +00001052 *(u32 *)fb = \
1053 SWAP32((unsigned int)(((r<<16) | \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001054 (g<<8) | \
1055 b))); \
wdenke55402c2004-03-14 16:51:43 +00001056 fb += 4; \
1057}
1058
1059#ifdef VIDEO_FB_LITTLE_ENDIAN
1060#define FILL_24BIT_888RGB(r,g,b) { \
1061 fb[0] = b; \
1062 fb[1] = g; \
1063 fb[2] = r; \
1064 fb += 3; \
1065}
1066#else
1067#define FILL_24BIT_888RGB(r,g,b) { \
1068 fb[0] = r; \
1069 fb[1] = g; \
1070 fb[2] = b; \
1071 fb += 3; \
1072}
1073#endif
1074
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001075#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001076static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001077{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001078 ushort *dst = (ushort *) fb;
1079 ushort color = (ushort) (((r >> 3) << 10) |
1080 ((g >> 3) << 5) |
1081 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001082 if (x & 1)
1083 *(--dst) = color;
1084 else
1085 *(++dst) = color;
1086}
1087#endif
wdenke55402c2004-03-14 16:51:43 +00001088
1089/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001090 * RLE8 bitmap support
1091 */
1092
1093#ifdef CONFIG_VIDEO_BMP_RLE8
1094/* Pre-calculated color table entry */
1095struct palette {
1096 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001097 unsigned short w; /* word */
1098 unsigned int dw; /* double word */
1099 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001100};
1101
1102/*
1103 * Helper to draw encoded/unencoded run.
1104 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001105static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1106 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001107{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001108 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001109 int *off;
1110 int enc_off = 1;
1111 int i;
1112
1113 /*
1114 * Setup offset of the color index in the bitmap.
1115 * Color index of encoded run is at offset 1.
1116 */
1117 off = enc ? &enc_off : &i;
1118
1119 switch (VIDEO_DATA_FORMAT) {
1120 case GDF__8BIT_INDEX:
1121 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001122 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001123 break;
1124 case GDF_15BIT_555RGB:
1125 case GDF_16BIT_565RGB:
1126 /* differences handled while pre-calculating palette */
1127 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001128 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001129 addr += 2;
1130 }
1131 break;
1132 case GDF_32BIT_X888RGB:
1133 for (i = 0; i < cnt; i++) {
Andre Przywaracd7b1ee2017-03-06 01:13:38 +00001134 *(u32 *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001135 addr += 4;
1136 }
1137 break;
1138 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001139 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001140}
1141
Simon Glass92e1f852015-05-13 07:02:27 -06001142static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001143 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001144{
1145 unsigned char *bm;
1146 unsigned char *fbp;
1147 unsigned int cnt, runlen;
1148 int decode = 1;
1149 int x, y, bpp, i, ncolors;
1150 struct palette p[256];
Simon Glass92e1f852015-05-13 07:02:27 -06001151 struct bmp_color_table_entry cte;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001152 int green_shift, red_off;
Hans de Goedea8287e72015-08-04 12:15:39 +02001153 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001154 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001155
1156 x = 0;
1157 y = __le32_to_cpu(img->header.height) - 1;
1158 ncolors = __le32_to_cpu(img->header.colors_used);
1159 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001160 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001161 (y + yoff) * VIDEO_LINE_LEN +
1162 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001163
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001164 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001165
1166 /* pre-calculate and setup palette */
1167 switch (VIDEO_DATA_FORMAT) {
1168 case GDF__8BIT_INDEX:
1169 for (i = 0; i < ncolors; i++) {
1170 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001171 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001172 }
1173 break;
1174 case GDF_15BIT_555RGB:
1175 case GDF_16BIT_565RGB:
1176 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1177 green_shift = 3;
1178 red_off = 10;
1179 } else {
1180 green_shift = 2;
1181 red_off = 11;
1182 }
1183 for (i = 0; i < ncolors; i++) {
1184 cte = img->color_table[i];
1185 p[i].ce.w = SWAP16((unsigned short)
1186 (((cte.red >> 3) << red_off) |
1187 ((cte.green >> green_shift) << 5) |
1188 cte.blue >> 3));
1189 }
1190 break;
1191 case GDF_32BIT_X888RGB:
1192 for (i = 0; i < ncolors; i++) {
1193 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001194 p[i].ce.dw = SWAP32((cte.red << 16) |
1195 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001196 cte.blue);
1197 }
1198 break;
1199 default:
1200 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001201 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001202 return -1;
1203 }
1204
1205 while (decode) {
1206 switch (bm[0]) {
1207 case 0:
1208 switch (bm[1]) {
1209 case 0:
1210 /* scan line end marker */
1211 bm += 2;
1212 x = 0;
1213 y--;
1214 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001215 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001216 (y + yoff) * VIDEO_LINE_LEN +
1217 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001218 continue;
1219 case 1:
1220 /* end of bitmap data marker */
1221 decode = 0;
1222 break;
1223 case 2:
1224 /* run offset marker */
1225 x += bm[2];
1226 y -= bm[3];
1227 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001228 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001229 (y + yoff) * VIDEO_LINE_LEN +
1230 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001231 bm += 4;
1232 break;
1233 default:
1234 /* unencoded run */
1235 cnt = bm[1];
1236 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001237 pixels += cnt;
1238 if (pixels > limit)
1239 goto error;
1240
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001241 bm += 2;
1242 if (y < height) {
1243 if (x >= width) {
1244 x += runlen;
1245 goto next_run;
1246 }
1247 if (x + runlen > width)
1248 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001249 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001250 x += runlen;
1251 }
1252next_run:
1253 bm += runlen;
1254 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001255 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001256 }
1257 break;
1258 default:
1259 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001260 cnt = bm[0];
1261 runlen = cnt;
1262 pixels += cnt;
1263 if (pixels > limit)
1264 goto error;
1265
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001266 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001267 if (x >= width) {
1268 x += runlen;
1269 bm += 2;
1270 continue;
1271 }
1272 if (x + runlen > width)
1273 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001274 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001275 x += runlen;
1276 }
1277 bm += 2;
1278 break;
1279 }
1280 }
Sébastien Szymanskia14dbb52018-09-10 09:58:58 +02001281
1282 if (cfb_do_flush_cache)
1283 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1284
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001285 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001286error:
1287 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1288 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001289}
1290#endif
1291
1292/*
wdenke55402c2004-03-14 16:51:43 +00001293 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001294 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001295int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001296{
1297 ushort xcount, ycount;
1298 uchar *fb;
Simon Glass92e1f852015-05-13 07:02:27 -06001299 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenke55402c2004-03-14 16:51:43 +00001300 uchar *bmap;
1301 ushort padded_line;
1302 unsigned long width, height, bpp;
1303 unsigned colors;
1304 unsigned long compression;
Simon Glass92e1f852015-05-13 07:02:27 -06001305 struct bmp_color_table_entry cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001306
Stefan Roesed9d97742005-09-22 09:04:17 +02001307#ifdef CONFIG_VIDEO_BMP_GZIP
1308 unsigned char *dst = NULL;
1309 ulong len;
1310#endif
wdenkc6097192002-11-03 00:24:07 +00001311
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001312 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001313
1314 if (!((bmp->header.signature[0] == 'B') &&
1315 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001316
1317#ifdef CONFIG_VIDEO_BMP_GZIP
1318 /*
1319 * Could be a gzipped bmp image, try to decrompress...
1320 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001321 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1322 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001323 if (dst == NULL) {
1324 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001325 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001326 }
Eric Nelsonfba70872014-03-08 07:55:52 -07001327 /*
1328 * NB: we need to force offset of +2
1329 * See doc/README.displaying-bmps
1330 */
1331 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001332 (uchar *) bmp_image,
1333 &len) != 0) {
1334 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1335 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001336 free(dst);
1337 return 1;
1338 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001339 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001340 printf("Image could be truncated "
1341 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001342 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001343
1344 /*
1345 * Set addr to decompressed image
1346 */
Simon Glass92e1f852015-05-13 07:02:27 -06001347 bmp = (struct bmp_image *)(dst+2);
Stefan Roesed9d97742005-09-22 09:04:17 +02001348
1349 if (!((bmp->header.signature[0] == 'B') &&
1350 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001351 printf("Error: no valid bmp.gz image at %lx\n",
1352 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001353 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001354 return 1;
1355 }
1356#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001357 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001358 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001359#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001360 }
1361
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001362 width = le32_to_cpu(bmp->header.width);
1363 height = le32_to_cpu(bmp->header.height);
1364 bpp = le16_to_cpu(bmp->header.bit_count);
1365 colors = le32_to_cpu(bmp->header.colors_used);
1366 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001367
Marek Vasut2eb9a492011-10-21 14:17:04 +00001368 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001369 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001370
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001371 if (compression != BMP_BI_RGB
1372#ifdef CONFIG_VIDEO_BMP_RLE8
1373 && compression != BMP_BI_RLE8
1374#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001375 ) {
1376 printf("Error: compression type %ld not supported\n",
1377 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001378#ifdef CONFIG_VIDEO_BMP_GZIP
1379 if (dst)
1380 free(dst);
1381#endif
wdenke55402c2004-03-14 16:51:43 +00001382 return 1;
1383 }
1384
1385 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1386
Matthias Weisser53884182009-07-09 16:07:30 +02001387#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1388 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001389 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001390 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001391 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001392
1393 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001394 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001395 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001396 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001397#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1398
Matthias Weisser5e5ed762013-02-15 03:35:12 +00001399 /*
1400 * Just ignore elements which are completely beyond screen
1401 * dimensions.
1402 */
1403 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1404 return 0;
1405
wdenke55402c2004-03-14 16:51:43 +00001406 if ((x + width) > VIDEO_VISIBLE_COLS)
1407 width = VIDEO_VISIBLE_COLS - x;
1408 if ((y + height) > VIDEO_VISIBLE_ROWS)
1409 height = VIDEO_VISIBLE_ROWS - y;
1410
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001411 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001412 fb = (uchar *) (video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001413 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenke55402c2004-03-14 16:51:43 +00001414 x * VIDEO_PIXEL_SIZE);
1415
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001416#ifdef CONFIG_VIDEO_BMP_RLE8
1417 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001418 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001419 }
1420#endif
1421
Timur Tabi0fce9922010-08-23 16:58:00 -05001422 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001423 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001424 case 4:
1425 padded_line -= width / 2;
1426 ycount = height;
1427
1428 switch (VIDEO_DATA_FORMAT) {
1429 case GDF_32BIT_X888RGB:
1430 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001431 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001432 /*
1433 * Don't assume that 'width' is an
1434 * even number
1435 */
1436 for (xcount = 0; xcount < width; xcount++) {
1437 uchar idx;
1438
1439 if (xcount & 1) {
1440 idx = *bmap & 0xF;
1441 bmap++;
1442 } else
1443 idx = *bmap >> 4;
1444 cte = bmp->color_table[idx];
1445 FILL_32BIT_X888RGB(cte.red, cte.green,
1446 cte.blue);
1447 }
1448 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001449 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001450 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001451 }
1452 break;
1453 default:
1454 puts("4bpp bitmap unsupported with current "
1455 "video mode\n");
1456 break;
1457 }
1458 break;
1459
wdenke55402c2004-03-14 16:51:43 +00001460 case 8:
1461 padded_line -= width;
1462 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001463 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001464 for (xcount = 0; xcount < colors; ++xcount) {
1465 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001466 video_set_lut(xcount, cte.red, cte.green,
1467 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001468 }
1469 }
1470 ycount = height;
1471 switch (VIDEO_DATA_FORMAT) {
1472 case GDF__8BIT_INDEX:
1473 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001474 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001475 xcount = width;
1476 while (xcount--) {
1477 *fb++ = *bmap++;
1478 }
1479 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001480 fb -= VIDEO_LINE_LEN + width *
1481 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001482 }
1483 break;
1484 case GDF__8BIT_332RGB:
1485 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001486 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001487 xcount = width;
1488 while (xcount--) {
1489 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001490 FILL_8BIT_332RGB(cte.red, cte.green,
1491 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001492 }
1493 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001494 fb -= VIDEO_LINE_LEN + width *
1495 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001496 }
1497 break;
1498 case GDF_15BIT_555RGB:
1499 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001500#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1501 int xpos = x;
1502#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001503 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001504 xcount = width;
1505 while (xcount--) {
1506 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001507#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001508 fill_555rgb_pswap(fb, xpos++, cte.red,
1509 cte.green,
1510 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001511 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001512#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001513 FILL_15BIT_555RGB(cte.red, cte.green,
1514 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001515#endif
wdenke55402c2004-03-14 16:51:43 +00001516 }
1517 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001518 fb -= VIDEO_LINE_LEN + width *
1519 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001520 }
1521 break;
1522 case GDF_16BIT_565RGB:
1523 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001524 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001525 xcount = width;
1526 while (xcount--) {
1527 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001528 FILL_16BIT_565RGB(cte.red, cte.green,
1529 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001530 }
1531 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001532 fb -= VIDEO_LINE_LEN + width *
1533 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001534 }
1535 break;
1536 case GDF_32BIT_X888RGB:
1537 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001538 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001539 xcount = width;
1540 while (xcount--) {
1541 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001542 FILL_32BIT_X888RGB(cte.red, cte.green,
1543 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001544 }
1545 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001546 fb -= VIDEO_LINE_LEN + width *
1547 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001548 }
1549 break;
1550 case GDF_24BIT_888RGB:
1551 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001552 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001553 xcount = width;
1554 while (xcount--) {
1555 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001556 FILL_24BIT_888RGB(cte.red, cte.green,
1557 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001558 }
1559 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001560 fb -= VIDEO_LINE_LEN + width *
1561 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001562 }
1563 break;
1564 }
1565 break;
1566 case 24:
1567 padded_line -= 3 * width;
1568 ycount = height;
1569 switch (VIDEO_DATA_FORMAT) {
1570 case GDF__8BIT_332RGB:
1571 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001572 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001573 xcount = width;
1574 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001575 FILL_8BIT_332RGB(bmap[2], bmap[1],
1576 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001577 bmap += 3;
1578 }
1579 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001580 fb -= VIDEO_LINE_LEN + width *
1581 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001582 }
1583 break;
1584 case GDF_15BIT_555RGB:
1585 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001586#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1587 int xpos = x;
1588#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001589 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001590 xcount = width;
1591 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001592#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001593 fill_555rgb_pswap(fb, xpos++, bmap[2],
1594 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001595 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001596#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001597 FILL_15BIT_555RGB(bmap[2], bmap[1],
1598 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001599#endif
wdenke55402c2004-03-14 16:51:43 +00001600 bmap += 3;
1601 }
1602 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001603 fb -= VIDEO_LINE_LEN + width *
1604 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001605 }
1606 break;
1607 case GDF_16BIT_565RGB:
1608 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001609 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001610 xcount = width;
1611 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001612 FILL_16BIT_565RGB(bmap[2], bmap[1],
1613 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001614 bmap += 3;
1615 }
1616 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001617 fb -= VIDEO_LINE_LEN + width *
1618 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001619 }
1620 break;
1621 case GDF_32BIT_X888RGB:
1622 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001623 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001624 xcount = width;
1625 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001626 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1627 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001628 bmap += 3;
1629 }
1630 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001631 fb -= VIDEO_LINE_LEN + width *
1632 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001633 }
1634 break;
1635 case GDF_24BIT_888RGB:
1636 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001637 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001638 xcount = width;
1639 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001640 FILL_24BIT_888RGB(bmap[2], bmap[1],
1641 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001642 bmap += 3;
1643 }
1644 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001645 fb -= VIDEO_LINE_LEN + width *
1646 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001647 }
1648 break;
1649 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001650 printf("Error: 24 bits/pixel bitmap incompatible "
1651 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001652 break;
1653 }
1654 break;
1655 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001656 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1657 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001658 break;
1659 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001660
1661#ifdef CONFIG_VIDEO_BMP_GZIP
1662 if (dst) {
1663 free(dst);
1664 }
1665#endif
1666
Eric Nelson54142422013-05-06 14:27:28 +02001667 if (cfb_do_flush_cache)
1668 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenke55402c2004-03-14 16:51:43 +00001669 return (0);
wdenkc6097192002-11-03 00:24:07 +00001670}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001671#endif
wdenkc6097192002-11-03 00:24:07 +00001672
wdenkc6097192002-11-03 00:24:07 +00001673
1674#ifdef CONFIG_VIDEO_LOGO
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001675static int video_logo_xpos;
1676static int video_logo_ypos;
1677
Hans de Goedeb922f782015-08-04 12:21:40 +02001678static void plot_logo_or_black(void *screen, int x, int y, int black);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001679
Hans de Goedeb922f782015-08-04 12:21:40 +02001680static void logo_plot(void *screen, int x, int y)
Bastian Ruppertd5932182012-09-13 22:29:02 +00001681{
Hans de Goedeb922f782015-08-04 12:21:40 +02001682 plot_logo_or_black(screen, x, y, 0);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001683}
1684
1685static void logo_black(void)
1686{
Hans de Goedeb922f782015-08-04 12:21:40 +02001687 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
Bastian Ruppertd5932182012-09-13 22:29:02 +00001688 1);
1689}
1690
Simon Glassed38aef2020-05-10 11:40:03 -06001691static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc,
1692 char *const argv[])
Bastian Ruppertd5932182012-09-13 22:29:02 +00001693{
1694 if (argc != 1)
1695 return cmd_usage(cmdtp);
1696
1697 logo_black();
1698 return 0;
1699}
1700
1701U_BOOT_CMD(
1702 clrlogo, 1, 0, do_clrlogo,
1703 "fill the boot logo area with black",
1704 " "
1705 );
1706
Hans de Goedeb922f782015-08-04 12:21:40 +02001707static void plot_logo_or_black(void *screen, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001708{
wdenk9dd2b882002-12-03 21:28:10 +00001709
wdenke55402c2004-03-14 16:51:43 +00001710 int xcount, i;
Hans de Goedea8287e72015-08-04 12:15:39 +02001711 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001712 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001713 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1714 unsigned char *source;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001715 unsigned char *dest;
1716
1717#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1718 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001719 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001720 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001721 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001722
1723 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001724 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001725 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001726 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001727#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1728
Hans de Goedea8287e72015-08-04 12:15:39 +02001729 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001730
wdenk9dd2b882002-12-03 21:28:10 +00001731#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001732 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001733
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001734 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001735 logo_red = malloc(BMP_LOGO_COLORS);
1736 logo_green = malloc(BMP_LOGO_COLORS);
1737 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001738 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001739 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1740 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1741 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1742 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1743 }
wdenk9dd2b882002-12-03 21:28:10 +00001744#else
wdenke55402c2004-03-14 16:51:43 +00001745 source = linux_logo;
1746 logo_red = linux_logo_red;
1747 logo_green = linux_logo_green;
1748 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001749#endif
wdenk57b2d802003-06-27 21:31:46 +00001750
wdenke55402c2004-03-14 16:51:43 +00001751 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1752 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001753 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1754 logo_red[i], logo_green[i],
1755 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001756 }
wdenk57b2d802003-06-27 21:31:46 +00001757 }
wdenkc6097192002-11-03 00:24:07 +00001758
wdenke55402c2004-03-14 16:51:43 +00001759 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001760#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1761 int xpos = x;
1762#endif
wdenke55402c2004-03-14 16:51:43 +00001763 xcount = VIDEO_LOGO_WIDTH;
1764 while (xcount--) {
Bastian Ruppertd5932182012-09-13 22:29:02 +00001765 if (black) {
1766 r = 0x00;
1767 g = 0x00;
1768 b = 0x00;
1769 } else {
1770 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1771 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1772 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1773 }
wdenk57b2d802003-06-27 21:31:46 +00001774
wdenke55402c2004-03-14 16:51:43 +00001775 switch (VIDEO_DATA_FORMAT) {
1776 case GDF__8BIT_INDEX:
1777 *dest = *source;
1778 break;
1779 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001780 *dest = ((r >> 5) << 5) |
1781 ((g >> 5) << 2) |
1782 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001783 break;
1784 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001785#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001786 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001787#else
wdenke55402c2004-03-14 16:51:43 +00001788 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001789 SWAP16((unsigned short) (
1790 ((r >> 3) << 10) |
1791 ((g >> 3) << 5) |
1792 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001793#endif
wdenke55402c2004-03-14 16:51:43 +00001794 break;
1795 case GDF_16BIT_565RGB:
1796 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001797 SWAP16((unsigned short) (
1798 ((r >> 3) << 11) |
1799 ((g >> 2) << 5) |
1800 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001801 break;
1802 case GDF_32BIT_X888RGB:
Andre Przywaracd7b1ee2017-03-06 01:13:38 +00001803 *(u32 *) dest =
1804 SWAP32((u32) (
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001805 (r << 16) |
1806 (g << 8) |
1807 b));
wdenke55402c2004-03-14 16:51:43 +00001808 break;
1809 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001810#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001811 dest[0] = b;
1812 dest[1] = g;
1813 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001814#else
wdenke55402c2004-03-14 16:51:43 +00001815 dest[0] = r;
1816 dest[1] = g;
1817 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001818#endif
wdenke55402c2004-03-14 16:51:43 +00001819 break;
1820 }
1821 source++;
1822 dest += VIDEO_PIXEL_SIZE;
1823 }
1824 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001825 }
wdenk9dd2b882002-12-03 21:28:10 +00001826#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001827 free(logo_red);
1828 free(logo_green);
1829 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001830#endif
wdenkc6097192002-11-03 00:24:07 +00001831}
1832
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001833static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001834{
wdenke55402c2004-03-14 16:51:43 +00001835 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001836 __maybe_unused int y_off = 0;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001837 __maybe_unused ulong addr;
1838 __maybe_unused char *s;
Anatolij Gustschinea5a9622016-11-30 14:30:59 +01001839 __maybe_unused int len, ret, space;
wdenke55402c2004-03-14 16:51:43 +00001840
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +02001841 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
wdenke55402c2004-03-14 16:51:43 +00001842
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001843#ifdef CONFIG_SPLASH_SCREEN
Simon Glass64b723f2017-08-03 12:22:12 -06001844 s = env_get("splashimage");
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001845 if (s != NULL) {
Anatolij Gustschinea5a9622016-11-30 14:30:59 +01001846 ret = splash_screen_prepare();
1847 if (ret < 0)
1848 return video_fb_address;
Simon Glass3ff49ec2021-07-24 09:03:29 -06001849 addr = hextoul(s, NULL);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001850
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001851 if (video_display_bitmap(addr,
1852 video_logo_xpos,
1853 video_logo_ypos) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001854 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001855 return ((void *) (video_fb_address));
1856 }
1857 }
1858#endif /* CONFIG_SPLASH_SCREEN */
1859
Hans de Goedeb922f782015-08-04 12:21:40 +02001860 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001861
1862#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1863 /*
1864 * when using splashpos for video_logo, skip any info
1865 * output on video console if the logo is not at 0,0
1866 */
1867 if (video_logo_xpos || video_logo_ypos) {
1868 /*
1869 * video_logo_height is used in text and cursor offset
1870 * calculations. Since the console is below the logo,
1871 * we need to adjust the logo height
1872 */
1873 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001874 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001875 VIDEO_LOGO_HEIGHT) / 2);
1876 else if (video_logo_ypos > 0)
1877 video_logo_height += video_logo_ypos;
1878
1879 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1880 }
1881#endif
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02001882 if (board_cfb_skip())
1883 return 0;
wdenkc6097192002-11-03 00:24:07 +00001884
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001885 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001886
Tim Harvey98899462016-05-24 14:59:59 -07001887#ifndef CONFIG_HIDE_LOGO_VERSION
Peng Fan1d0ccac2018-01-02 15:25:37 +08001888 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001889 len = strlen(info);
1890
1891 if (len > space) {
Peng Fan1d0ccac2018-01-02 15:25:37 +08001892 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1893 uchar *p = (uchar *) info;
1894
1895 while (len) {
1896 if (len > space) {
1897 video_drawchars(xx, yy, p, space);
1898 len -= space;
1899
1900 p = (uchar *)p + space;
1901
1902 if (!y_off) {
1903 xx += VIDEO_FONT_WIDTH;
1904 space--;
1905 }
1906 yy += VIDEO_FONT_HEIGHT;
1907
1908 y_off++;
1909 } else {
1910 video_drawchars(xx, yy, p, len);
1911 len = 0;
1912 }
1913 }
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001914 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001915 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001916
1917#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001918 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001919 int i, n =
1920 ((video_logo_height -
1921 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001922
wdenke55402c2004-03-14 16:51:43 +00001923 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001924 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001925 if (!*info)
1926 continue;
1927
1928 len = strlen(info);
1929 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001930 video_drawchars(VIDEO_INFO_X,
1931 VIDEO_INFO_Y +
1932 (i + y_off) *
1933 VIDEO_FONT_HEIGHT,
1934 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001935 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001936 video_drawchars(VIDEO_INFO_X +
1937 VIDEO_FONT_WIDTH,
1938 VIDEO_INFO_Y +
1939 (i + y_off) *
1940 VIDEO_FONT_HEIGHT,
1941 (uchar *) info + space,
1942 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001943 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001944 video_drawstring(VIDEO_INFO_X,
1945 VIDEO_INFO_Y +
1946 (i + y_off) *
1947 VIDEO_FONT_HEIGHT,
1948 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001949 }
wdenke55402c2004-03-14 16:51:43 +00001950 }
1951 }
wdenkc6097192002-11-03 00:24:07 +00001952#endif
Tim Harvey98899462016-05-24 14:59:59 -07001953#endif
wdenkc6097192002-11-03 00:24:07 +00001954
Matthias Weisser76d70862010-01-12 12:06:31 +01001955 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001956}
1957#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001958
1959static int cfb_fb_is_in_dram(void)
1960{
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001961 struct bd_info *bd = gd->bd;
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001962 ulong start, end;
1963 int i;
1964
1965 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1966 start = bd->bi_dram[i].start;
1967 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1968 if ((ulong)video_fb_address >= start &&
1969 (ulong)video_fb_address < end)
1970 return 1;
1971 }
Stefan Roesee5842152020-08-12 13:32:41 +02001972
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001973 return 0;
1974}
wdenkc6097192002-11-03 00:24:07 +00001975
Heiko Schocher62759562013-10-22 11:06:06 +02001976void video_clear(void)
1977{
1978 if (!video_fb_address)
1979 return;
1980#ifdef VIDEO_HW_RECTFILL
1981 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
1982 0, /* dest pos x */
1983 0, /* dest pos y */
1984 VIDEO_VISIBLE_COLS, /* frame width */
1985 VIDEO_VISIBLE_ROWS, /* frame height */
1986 bgx /* fill color */
1987 );
1988#else
1989 memsetl(video_fb_address,
1990 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
1991#endif
1992}
1993
Simon Glass88ecb9b2016-10-17 20:12:54 -06001994static int cfg_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001995{
wdenke55402c2004-03-14 16:51:43 +00001996 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001997
Wolfgang Denka87b2a952011-07-30 12:48:09 +00001998 pGD = video_hw_init();
1999 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00002000 return -1;
wdenkc6097192002-11-03 00:24:07 +00002001
wdenke55402c2004-03-14 16:51:43 +00002002 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002003
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002004 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2005
wdenke55402c2004-03-14 16:51:43 +00002006 /* Init drawing pats */
2007 switch (VIDEO_DATA_FORMAT) {
2008 case GDF__8BIT_INDEX:
Simon Glass884889d2016-10-17 20:12:44 -06002009 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2010 CONFIG_SYS_CONSOLE_FG_COL,
2011 CONFIG_SYS_CONSOLE_FG_COL);
2012 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2013 CONFIG_SYS_CONSOLE_BG_COL,
2014 CONFIG_SYS_CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00002015 fgx = 0x01010101;
2016 bgx = 0x00000000;
2017 break;
2018 case GDF__8BIT_332RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002019 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2020 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2021 CONFIG_SYS_CONSOLE_FG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002022 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2023 color8;
Simon Glass884889d2016-10-17 20:12:44 -06002024 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2025 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2026 CONFIG_SYS_CONSOLE_BG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002027 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2028 color8;
wdenke55402c2004-03-14 16:51:43 +00002029 break;
2030 case GDF_15BIT_555RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002031 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2032 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2033 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2034 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2035 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2036 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2037 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2038 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2039 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2040 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2041 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2042 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002043 break;
2044 case GDF_16BIT_565RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002045 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2046 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2047 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2048 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2049 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2050 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2051 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2052 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2053 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2054 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2055 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2056 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002057 break;
2058 case GDF_32BIT_X888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002059 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2060 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2061 CONFIG_SYS_CONSOLE_FG_COL;
2062 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2063 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2064 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002065 break;
2066 case GDF_24BIT_888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002067 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2068 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2069 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2070 CONFIG_SYS_CONSOLE_FG_COL;
2071 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2072 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2073 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2074 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002075 break;
2076 }
2077 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002078
Rob Clarkf1411882017-08-03 12:47:01 -04002079 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2080 video_clear();
Heiko Schocher62759562013-10-22 11:06:06 +02002081
wdenkc6097192002-11-03 00:24:07 +00002082#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00002083 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00002084 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002085 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002086#else
wdenke55402c2004-03-14 16:51:43 +00002087 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002088#endif
2089
wdenke55402c2004-03-14 16:51:43 +00002090 /* Initialize the console */
2091 console_col = 0;
2092 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002093
Eric Nelson54142422013-05-06 14:27:28 +02002094 if (cfb_do_flush_cache)
2095 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2096
wdenke55402c2004-03-14 16:51:43 +00002097 return 0;
wdenkc6097192002-11-03 00:24:07 +00002098}
2099
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002100/*
2101 * Implement a weak default function for boards that optionally
2102 * need to skip the video initialization.
2103 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02002104__weak int board_video_skip(void)
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002105{
2106 /* As default, don't skip test */
2107 return 0;
2108}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002109
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002110int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002111{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02002112 struct stdio_dev console_dev;
Simon Glasse9fa1f02015-03-02 12:40:50 -07002113 bool have_keyboard;
Bin Menge52e17a2015-08-24 01:00:07 -07002114 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00002115
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002116 /* Check if video initialization should be skipped */
2117 if (board_video_skip())
2118 return 0;
2119
wdenk7dd13292004-07-11 20:04:51 +00002120 /* Init video chip - returns with framebuffer cleared */
Simon Glass88ecb9b2016-10-17 20:12:54 -06002121 if (cfg_video_init() == -1)
Bin Menge52e17a2015-08-24 01:00:07 -07002122 return 0;
wdenkc6097192002-11-03 00:24:07 +00002123
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02002124 if (board_cfb_skip())
2125 return 0;
2126
Simon Glasse9fa1f02015-03-02 12:40:50 -07002127#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2128 have_keyboard = false;
2129#elif defined(CONFIG_OF_CONTROL)
Simon Glass0034d962021-08-07 07:24:01 -06002130 have_keyboard = !ofnode_conf_read_bool("u-boot,no-keyboard");
Simon Glasse9fa1f02015-03-02 12:40:50 -07002131#else
2132 have_keyboard = true;
2133#endif
2134 if (have_keyboard) {
2135 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002136#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002137 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002138#endif
Simon Glasse9fa1f02015-03-02 12:40:50 -07002139 }
wdenkc6097192002-11-03 00:24:07 +00002140
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002141 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002142 memset(&console_dev, 0, sizeof(console_dev));
2143 strcpy(console_dev.name, "vga");
Bin Meng6abe4b62015-11-03 23:23:37 -08002144 console_dev.flags = DEV_FLAGS_OUTPUT;
Simon Glass88ecb9b2016-10-17 20:12:54 -06002145 console_dev.putc = cfb_video_putc; /* 'putc' function */
2146 console_dev.puts = cfb_video_puts; /* 'puts' function */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002147
2148#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002149 if (have_keyboard && keyboard_ok) {
Simon Glasse9fa1f02015-03-02 12:40:50 -07002150 /* Also init console device */
2151 console_dev.flags |= DEV_FLAGS_INPUT;
2152 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2153 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2154 }
2155#endif
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002156
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002157 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002158 return 0;
2159
2160 /* Return success */
2161 return 1;
wdenkc6097192002-11-03 00:24:07 +00002162}
Stefan Reinauer7870da32012-09-28 15:11:12 +00002163
2164void video_position_cursor(unsigned col, unsigned row)
2165{
2166 console_col = min(col, CONSOLE_COLS - 1);
2167 console_row = min(row, CONSOLE_ROWS - 1);
2168}
2169
2170int video_get_pixel_width(void)
2171{
2172 return VIDEO_VISIBLE_COLS;
2173}
2174
2175int video_get_pixel_height(void)
2176{
2177 return VIDEO_VISIBLE_ROWS;
2178}
2179
2180int video_get_screen_rows(void)
2181{
2182 return CONSOLE_ROWS;
2183}
2184
2185int video_get_screen_columns(void)
2186{
2187 return CONSOLE_COLS;
2188}