blob: 0b2589706201ccfd525437e24967f5a612b07e5f [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8/*
9 * cfb_console.c
10 *
11 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
12 *
13 * At the moment only the 8x16 font is tested and the font fore- and
14 * background color is limited to black/white/gray colors. The Linux
15 * logo can be placed in the upper left corner and additional board
Wolfgang Denk64e40d72011-07-29 09:55:27 +000016 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000017 *
Simon Glass39f615e2015-11-11 10:05:47 -070018 * The console driver can use a keyboard interface for character input
19 * but this is deprecated. Only rk51 uses it.
20 *
21 * Character output goes to a memory-mapped video
wdenkc6097192002-11-03 00:24:07 +000022 * framebuffer with little or big-endian organisation.
23 * With environment setting 'console=serial' the console i/o can be
24 * forced to serial port.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000025 *
26 * The driver uses graphic specific defines/parameters/functions:
27 *
28 * (for SMI LynxE graphic chip)
29 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000030 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
31 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
32 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
33 *
34 * Console Parameters are set by graphic drivers global struct:
35 *
36 * VIDEO_VISIBLE_COLS - x resolution
37 * VIDEO_VISIBLE_ROWS - y resolution
38 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
39 * VIDEO_DATA_FORMAT - graphical data format GDF
40 * VIDEO_FB_ADRS - start of video memory
41 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000042 * VIDEO_KBD_INIT_FCT - init function for keyboard
43 * VIDEO_TSTC_FCT - keyboard_tstc function
44 * VIDEO_GETC_FCT - keyboard_getc function
45 *
Bastian Ruppert1e681f92012-09-13 22:29:01 +000046 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
47 * Use CONFIG_SPLASH_SCREEN_ALIGN with
48 * environment variable "splashpos" to place
49 * the logo on other position. In this case
50 * no CONSOLE_EXTRA_INFO is possible.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000051 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
52 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
53 * strings that normaly goes to serial
54 * port. This define requires a board
55 * specific function:
56 * video_drawstring (VIDEO_INFO_X,
57 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
58 * info);
59 * that fills a info buffer at i=row.
60 * s.a: board/eltec/bab7xx.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000061 *
62 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
63 * character. No blinking is provided.
64 * Uses the macros CURSOR_SET and
65 * CURSOR_OFF.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000066 */
wdenkc6097192002-11-03 00:24:07 +000067
68#include <common.h>
Simon Glass5692ccf2015-03-02 12:40:50 -070069#include <fdtdec.h>
Andreas Bießmann09c2e902011-07-18 20:24:04 +020070#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +000071#include <malloc.h>
Simon Glass0a6eac82016-10-17 20:12:54 -060072#include <video.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +000073#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +000074
Simon Glassc370d382016-10-17 20:12:47 -060075#if defined(CONFIG_VIDEO_MXS)
Marek Vasutfb8ddc22013-04-28 09:20:03 +000076#define VIDEO_FB_16BPP_WORD_SWAP
77#endif
78
Wolfgang Denk64e40d72011-07-29 09:55:27 +000079/*
80 * Defines for the MB862xx driver
81 */
Anatolij Gustschinbed53752008-01-11 14:30:01 +010082#ifdef CONFIG_VIDEO_MB862xx
83
84#ifdef CONFIG_VIDEO_CORALP
85#define VIDEO_FB_LITTLE_ENDIAN
86#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +020087#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +010088#define VIDEO_HW_RECTFILL
89#define VIDEO_HW_BITBLT
90#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +020091#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +010092
Wolfgang Denk64e40d72011-07-29 09:55:27 +000093/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +000094 * Defines for the i.MX31 driver (mx3fb.c)
95 */
Fabio Estevam695af9a2012-05-31 07:23:56 +000096#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger62a22dc2011-10-12 23:16:29 +000097#define VIDEO_FB_16BPP_WORD_SWAP
98#endif
99
100/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000101 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
102 */
wdenkc6097192002-11-03 00:24:07 +0000103#include <video_fb.h>
104
Robert Winklerdd4425e2013-06-17 11:31:29 -0700105#include <splash.h>
106
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000107/*
108 * some Macros
109 */
wdenk4b248f32004-03-14 16:51:43 +0000110#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
111#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
112#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
113#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
114#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000115
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000116/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000117 * Console device
118 */
wdenkc6097192002-11-03 00:24:07 +0000119
120#include <version.h>
121#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200122#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000123#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000124
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500125#if defined(CONFIG_CMD_DATE)
126#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000127#endif
128
Jon Loeliger07d38a12007-07-09 17:30:01 -0500129#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000130#include <watchdog.h>
131#include <bmp_layout.h>
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200132#include <splash.h>
Jon Loeliger07d38a12007-07-09 17:30:01 -0500133#endif
wdenk4b248f32004-03-14 16:51:43 +0000134
Simon Glassa4206572016-10-17 20:12:50 -0600135#if !defined(CONFIG_VIDEO_SW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000136/* no Cursor defined */
137#define CURSOR_ON
138#define CURSOR_OFF
139#define CURSOR_SET
140#endif
141
Simon Glass7fe09332015-10-18 21:17:18 -0600142#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000143void console_cursor(int state);
144
Timur Tabi65618632010-08-27 15:45:47 -0500145#define CURSOR_ON console_cursor(1)
146#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000147#define CURSOR_SET video_set_cursor()
Simon Glass7fe09332015-10-18 21:17:18 -0600148#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000149
wdenk4b248f32004-03-14 16:51:43 +0000150#ifdef CONFIG_VIDEO_LOGO
151#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000152#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000153#include <bmp_logo_data.h>
wdenk4b248f32004-03-14 16:51:43 +0000154#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
155#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
156#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
157#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenka6c7ad22002-12-03 21:28:10 +0000158
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000159#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000160#define LINUX_LOGO_WIDTH 80
161#define LINUX_LOGO_HEIGHT 80
162#define LINUX_LOGO_COLORS 214
163#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000164#define __initdata
165#include <linux_logo.h>
wdenk4b248f32004-03-14 16:51:43 +0000166#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
167#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
168#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
169#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000170#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000171#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
172#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000173#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000174#define VIDEO_LOGO_WIDTH 0
175#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000176#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000177
wdenk4b248f32004-03-14 16:51:43 +0000178#define VIDEO_COLS VIDEO_VISIBLE_COLS
179#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedec67a8762015-08-04 12:15:39 +0200180#ifndef VIDEO_LINE_LEN
181#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
182#endif
183#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenk4b248f32004-03-14 16:51:43 +0000184#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000185
wdenk4b248f32004-03-14 16:51:43 +0000186#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100187#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000188#else
wdenk4b248f32004-03-14 16:51:43 +0000189#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000190#endif
191
wdenk4b248f32004-03-14 16:51:43 +0000192#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
193#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
194#define CONSOLE_ROW_FIRST (video_console_address)
195#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
196#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
197#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass3c0b6682015-01-01 16:17:57 -0700198
199/* By default we scroll by a single line */
200#ifndef CONFIG_CONSOLE_SCROLL_LINES
201#define CONFIG_CONSOLE_SCROLL_LINES 1
202#endif
wdenkc6097192002-11-03 00:24:07 +0000203
204/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000205#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000206#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
207 ((x) >> 8) \
208 )
209#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
210 (((x) & 0x0000ff00) << 8) | \
211 (((x) & 0x00ff0000) >> 8) | \
212 (((x) & 0xff000000) >> 24) \
213 )
214#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
215 (((x) & 0x0000ff00) >> 8) | \
216 (((x) & 0x00ff0000) << 8) | \
217 (((x) & 0xff000000) >> 8) \
218 )
wdenkc6097192002-11-03 00:24:07 +0000219#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000220#define SWAP16(x) (x)
221#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200222#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000223#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500224#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000225#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100226#endif
wdenkc6097192002-11-03 00:24:07 +0000227#endif
228
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200229DECLARE_GLOBAL_DATA_PTR;
230
wdenkc6097192002-11-03 00:24:07 +0000231/* Locals */
232static GraphicDevice *pGD; /* Pointer to Graphic array */
233
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000234static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000235static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000236
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100237static int video_logo_height = VIDEO_LOGO_HEIGHT;
238
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000239static int __maybe_unused cursor_state;
240static int __maybe_unused old_col;
241static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000242
Wolfgang Denk57912932011-07-30 12:48:09 +0000243static int console_col; /* cursor col */
244static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000245
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000246static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000247
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200248static int cfb_do_flush_cache;
249
Pali Rohár33a35bb2012-10-19 13:30:09 +0000250#ifdef CONFIG_CFB_CONSOLE_ANSI
251static char ansi_buf[10];
252static int ansi_buf_size;
253static int ansi_colors_need_revert;
254static int ansi_cursor_hidden;
255#endif
256
wdenkc6097192002-11-03 00:24:07 +0000257static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000258 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
259 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
260 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
261 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
262};
wdenkc6097192002-11-03 00:24:07 +0000263
264static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000265 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
266};
wdenkc6097192002-11-03 00:24:07 +0000267
268static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000269 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
270};
wdenkc6097192002-11-03 00:24:07 +0000271
272static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000273 {0x00000000, 0x00000000, 0x00000000},
274 {0x00000000, 0x00000000, 0x00ffffff},
275 {0x00000000, 0x0000ffff, 0xff000000},
276 {0x00000000, 0x0000ffff, 0xffffffff},
277 {0x000000ff, 0xffff0000, 0x00000000},
278 {0x000000ff, 0xffff0000, 0x00ffffff},
279 {0x000000ff, 0xffffffff, 0xff000000},
280 {0x000000ff, 0xffffffff, 0xffffffff},
281 {0xffffff00, 0x00000000, 0x00000000},
282 {0xffffff00, 0x00000000, 0x00ffffff},
283 {0xffffff00, 0x0000ffff, 0xff000000},
284 {0xffffff00, 0x0000ffff, 0xffffffff},
285 {0xffffffff, 0xffff0000, 0x00000000},
286 {0xffffffff, 0xffff0000, 0x00ffffff},
287 {0xffffffff, 0xffffffff, 0xff000000},
288 {0xffffffff, 0xffffffff, 0xffffffff}
289};
wdenkc6097192002-11-03 00:24:07 +0000290
291static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000292 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
293 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
294 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
295 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
296 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
297 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
298 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
299 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
300 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
301 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
302 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
303 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
304 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
305 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
306 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
307 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
308};
wdenkc6097192002-11-03 00:24:07 +0000309
Heiko Schocher2bc4aa52013-08-03 07:22:53 +0200310/*
311 * Implement a weak default function for boards that optionally
312 * need to skip the cfb initialization.
313 */
314__weak int board_cfb_skip(void)
315{
316 /* As default, don't skip cfb init */
317 return 0;
318}
319
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000320static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000321{
wdenk4b248f32004-03-14 16:51:43 +0000322 u8 *cdat, *dest, *dest0;
323 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000324
wdenk4b248f32004-03-14 16:51:43 +0000325 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
326 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000327
wdenk4b248f32004-03-14 16:51:43 +0000328 switch (VIDEO_DATA_FORMAT) {
329 case GDF__8BIT_INDEX:
330 case GDF__8BIT_332RGB:
331 while (count--) {
332 c = *s;
333 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
334 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000335 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000336 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000337
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000338 ((u32 *) dest)[0] =
339 (video_font_draw_table8[bits >> 4] &
340 eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200341
342 if (VIDEO_FONT_WIDTH == 4)
343 continue;
344
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000345 ((u32 *) dest)[1] =
346 (video_font_draw_table8[bits & 15] &
347 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000348 }
349 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
350 s++;
351 }
352 break;
wdenkc6097192002-11-03 00:24:07 +0000353
wdenk4b248f32004-03-14 16:51:43 +0000354 case GDF_15BIT_555RGB:
355 while (count--) {
356 c = *s;
357 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
358 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000359 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000360 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000361
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000362 ((u32 *) dest)[0] =
363 SHORTSWAP32((video_font_draw_table15
364 [bits >> 6] & eorx) ^
365 bgx);
366 ((u32 *) dest)[1] =
367 SHORTSWAP32((video_font_draw_table15
368 [bits >> 4 & 3] & eorx) ^
369 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200370
371 if (VIDEO_FONT_WIDTH == 4)
372 continue;
373
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000374 ((u32 *) dest)[2] =
375 SHORTSWAP32((video_font_draw_table15
376 [bits >> 2 & 3] & eorx) ^
377 bgx);
378 ((u32 *) dest)[3] =
379 SHORTSWAP32((video_font_draw_table15
380 [bits & 3] & eorx) ^
381 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000382 }
383 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
384 s++;
385 }
386 break;
wdenkc6097192002-11-03 00:24:07 +0000387
wdenk4b248f32004-03-14 16:51:43 +0000388 case GDF_16BIT_565RGB:
389 while (count--) {
390 c = *s;
391 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
392 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000393 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000394 u8 bits = *cdat++;
395
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000396 ((u32 *) dest)[0] =
397 SHORTSWAP32((video_font_draw_table16
398 [bits >> 6] & eorx) ^
399 bgx);
400 ((u32 *) dest)[1] =
401 SHORTSWAP32((video_font_draw_table16
402 [bits >> 4 & 3] & eorx) ^
403 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200404
405 if (VIDEO_FONT_WIDTH == 4)
406 continue;
407
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000408 ((u32 *) dest)[2] =
409 SHORTSWAP32((video_font_draw_table16
410 [bits >> 2 & 3] & eorx) ^
411 bgx);
412 ((u32 *) dest)[3] =
413 SHORTSWAP32((video_font_draw_table16
414 [bits & 3] & eorx) ^
415 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000416 }
417 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
418 s++;
419 }
420 break;
421
422 case GDF_32BIT_X888RGB:
423 while (count--) {
424 c = *s;
425 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
426 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000427 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000428 u8 bits = *cdat++;
429
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000430 ((u32 *) dest)[0] =
431 SWAP32((video_font_draw_table32
432 [bits >> 4][0] & eorx) ^ bgx);
433 ((u32 *) dest)[1] =
434 SWAP32((video_font_draw_table32
435 [bits >> 4][1] & eorx) ^ bgx);
436 ((u32 *) dest)[2] =
437 SWAP32((video_font_draw_table32
438 [bits >> 4][2] & eorx) ^ bgx);
439 ((u32 *) dest)[3] =
440 SWAP32((video_font_draw_table32
441 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200442
443
444 if (VIDEO_FONT_WIDTH == 4)
445 continue;
446
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000447 ((u32 *) dest)[4] =
448 SWAP32((video_font_draw_table32
449 [bits & 15][0] & eorx) ^ bgx);
450 ((u32 *) dest)[5] =
451 SWAP32((video_font_draw_table32
452 [bits & 15][1] & eorx) ^ bgx);
453 ((u32 *) dest)[6] =
454 SWAP32((video_font_draw_table32
455 [bits & 15][2] & eorx) ^ bgx);
456 ((u32 *) dest)[7] =
457 SWAP32((video_font_draw_table32
458 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000459 }
460 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
461 s++;
462 }
463 break;
464
465 case GDF_24BIT_888RGB:
466 while (count--) {
467 c = *s;
468 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
469 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000470 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000471 u8 bits = *cdat++;
472
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000473 ((u32 *) dest)[0] =
474 (video_font_draw_table24[bits >> 4][0]
475 & eorx) ^ bgx;
476 ((u32 *) dest)[1] =
477 (video_font_draw_table24[bits >> 4][1]
478 & eorx) ^ bgx;
479 ((u32 *) dest)[2] =
480 (video_font_draw_table24[bits >> 4][2]
481 & eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200482
483 if (VIDEO_FONT_WIDTH == 4)
484 continue;
485
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000486 ((u32 *) dest)[3] =
487 (video_font_draw_table24[bits & 15][0]
488 & eorx) ^ bgx;
489 ((u32 *) dest)[4] =
490 (video_font_draw_table24[bits & 15][1]
491 & eorx) ^ bgx;
492 ((u32 *) dest)[5] =
493 (video_font_draw_table24[bits & 15][2]
494 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000495 }
496 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
497 s++;
498 }
499 break;
wdenk8bde7f72003-06-27 21:31:46 +0000500 }
wdenkc6097192002-11-03 00:24:07 +0000501}
502
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000503static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000504{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000505 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000506}
507
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000508static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000509{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000510 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000511}
512
Simon Glass7fe09332015-10-18 21:17:18 -0600513#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000514static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000515{
Gabe Black03d31fc2011-11-30 13:50:50 +0000516 if (cursor_state)
517 console_cursor(0);
518 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000519}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000520
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000521static void video_invertchar(int xx, int yy)
522{
523 int firstx = xx * VIDEO_PIXEL_SIZE;
524 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
525 int firsty = yy * VIDEO_LINE_LEN;
526 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
527 int x, y;
528 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
529 for (x = firstx; x < lastx; x++) {
530 u8 *dest = (u8 *)(video_fb_address) + x + y;
531 *dest = ~*dest;
532 }
533 }
534}
Gabe Black03d31fc2011-11-30 13:50:50 +0000535
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000536void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000537{
Gabe Black03d31fc2011-11-30 13:50:50 +0000538 if (cursor_state != state) {
539 if (cursor_state) {
540 /* turn off the cursor */
541 video_invertchar(old_col * VIDEO_FONT_WIDTH,
542 old_row * VIDEO_FONT_HEIGHT +
543 video_logo_height);
544 } else {
545 /* turn off the cursor and record where it is */
546 video_invertchar(console_col * VIDEO_FONT_WIDTH,
547 console_row * VIDEO_FONT_HEIGHT +
548 video_logo_height);
549 old_col = console_col;
550 old_row = console_row;
551 }
552 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000553 }
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200554 if (cfb_do_flush_cache)
555 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000556}
557#endif
558
wdenkc6097192002-11-03 00:24:07 +0000559#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000560static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000561{
wdenk4b248f32004-03-14 16:51:43 +0000562 while (c--)
563 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000564}
565#endif
566
wdenkc6097192002-11-03 00:24:07 +0000567#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000568static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000569{
wdenk4b248f32004-03-14 16:51:43 +0000570 while (c--)
571 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000572}
573#endif
574
Pali Rohár90f60a82012-04-28 07:26:44 +0000575static void console_clear_line(int line, int begin, int end)
576{
577#ifdef VIDEO_HW_RECTFILL
578 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
579 VIDEO_FONT_WIDTH * begin, /* dest pos x */
580 video_logo_height +
581 VIDEO_FONT_HEIGHT * line, /* dest pos y */
582 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
583 VIDEO_FONT_HEIGHT, /* frame height */
584 bgx /* fill color */
585 );
586#else
587 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
588 memsetl(CONSOLE_ROW_FIRST +
589 CONSOLE_ROW_SIZE * line, /* offset of row */
590 CONSOLE_ROW_SIZE >> 2, /* length of row */
591 bgx /* fill color */
592 );
593 } else {
594 void *offset;
595 int i, size;
596
597 offset = CONSOLE_ROW_FIRST +
598 CONSOLE_ROW_SIZE * line + /* offset of row */
599 VIDEO_FONT_WIDTH *
600 VIDEO_PIXEL_SIZE * begin; /* offset of col */
601 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
602 size >>= 2; /* length to end for memsetl() */
603 /* fill at col offset of i'th line using bgx as fill color */
604 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
605 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
606 }
607#endif
608}
609
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000610static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000611{
Simon Glass3c0b6682015-01-01 16:17:57 -0700612 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
613 int i;
614
wdenk4b248f32004-03-14 16:51:43 +0000615 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000616
617#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000618 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
619 0, /* source pos x */
620 video_logo_height +
Simon Glass3c0b6682015-01-01 16:17:57 -0700621 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000622 0, /* dest pos x */
623 video_logo_height, /* dest pos y */
624 VIDEO_VISIBLE_COLS, /* frame width */
625 VIDEO_VISIBLE_ROWS
626 - video_logo_height
Simon Glass3c0b6682015-01-01 16:17:57 -0700627 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000628 );
wdenkc6097192002-11-03 00:24:07 +0000629#else
Simon Glass3c0b6682015-01-01 16:17:57 -0700630 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
631 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000632#endif
wdenk4b248f32004-03-14 16:51:43 +0000633 /* clear the last one */
Simon Glass3c0b6682015-01-01 16:17:57 -0700634 for (i = 1; i <= rows; i++)
635 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
636
637 /* Decrement row number */
638 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000639}
640
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000641static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000642{
Timur Tabi65618632010-08-27 15:45:47 -0500643 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000644
wdenk4b248f32004-03-14 16:51:43 +0000645 if (console_col < 0) {
646 console_col = CONSOLE_COLS - 1;
647 console_row--;
648 if (console_row < 0)
649 console_row = 0;
650 }
wdenkc6097192002-11-03 00:24:07 +0000651}
652
Pali Rohár33a35bb2012-10-19 13:30:09 +0000653#ifdef CONFIG_CFB_CONSOLE_ANSI
654
655static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000656{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000657#ifdef VIDEO_HW_RECTFILL
658 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
659 0, /* dest pos x */
660 video_logo_height, /* dest pos y */
661 VIDEO_VISIBLE_COLS, /* frame width */
662 VIDEO_VISIBLE_ROWS, /* frame height */
663 bgx /* fill color */
664 );
665#else
666 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
667#endif
668}
669
670static void console_cursor_fix(void)
671{
672 if (console_row < 0)
673 console_row = 0;
674 if (console_row >= CONSOLE_ROWS)
675 console_row = CONSOLE_ROWS - 1;
676 if (console_col < 0)
677 console_col = 0;
678 if (console_col >= CONSOLE_COLS)
679 console_col = CONSOLE_COLS - 1;
680}
681
682static void console_cursor_up(int n)
683{
684 console_row -= n;
685 console_cursor_fix();
686}
687
688static void console_cursor_down(int n)
689{
690 console_row += n;
691 console_cursor_fix();
692}
693
694static void console_cursor_left(int n)
695{
696 console_col -= n;
697 console_cursor_fix();
698}
699
700static void console_cursor_right(int n)
701{
702 console_col += n;
703 console_cursor_fix();
704}
705
706static void console_cursor_set_position(int row, int col)
707{
708 if (console_row != -1)
709 console_row = row;
710 if (console_col != -1)
711 console_col = col;
712 console_cursor_fix();
713}
714
715static void console_previousline(int n)
716{
717 /* FIXME: also scroll terminal ? */
718 console_row -= n;
719 console_cursor_fix();
720}
721
722static void console_swap_colors(void)
723{
724 eorx = fgx;
725 fgx = bgx;
726 bgx = eorx;
727 eorx = fgx ^ bgx;
728}
729
730static inline int console_cursor_is_visible(void)
731{
732 return !ansi_cursor_hidden;
733}
734#else
735static inline int console_cursor_is_visible(void)
736{
737 return 1;
738}
739#endif
740
741static void console_newline(int n)
742{
743 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000744 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000745
wdenk4b248f32004-03-14 16:51:43 +0000746 /* Check if we need to scroll the terminal */
747 if (console_row >= CONSOLE_ROWS) {
748 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000749 console_scrollup();
wdenk4b248f32004-03-14 16:51:43 +0000750 }
wdenkc6097192002-11-03 00:24:07 +0000751}
752
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000753static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100754{
Timur Tabi65618632010-08-27 15:45:47 -0500755 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100756}
757
Pali Rohár33a35bb2012-10-19 13:30:09 +0000758static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000759{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100760 static int nl = 1;
761
Pali Rohár33a35bb2012-10-19 13:30:09 +0000762 if (console_cursor_is_visible())
763 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000764
wdenk4b248f32004-03-14 16:51:43 +0000765 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100766 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000767 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000768 break;
wdenkc6097192002-11-03 00:24:07 +0000769
wdenk4b248f32004-03-14 16:51:43 +0000770 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100771 if (console_col || (!console_col && nl))
Pali Rohár33a35bb2012-10-19 13:30:09 +0000772 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100773 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000774 break;
wdenkc6097192002-11-03 00:24:07 +0000775
wdenk4b248f32004-03-14 16:51:43 +0000776 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500777 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000778 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000779
wdenk4b248f32004-03-14 16:51:43 +0000780 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000781 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000782 break;
wdenkc6097192002-11-03 00:24:07 +0000783
wdenk4b248f32004-03-14 16:51:43 +0000784 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000785 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000786 break;
wdenkc6097192002-11-03 00:24:07 +0000787
Pali Rohár24fe06c2012-04-28 07:26:47 +0000788 case 7: /* bell */
789 break; /* ignored */
790
wdenk4b248f32004-03-14 16:51:43 +0000791 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000792 video_putchar(console_col * VIDEO_FONT_WIDTH,
793 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000794 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000795
wdenk4b248f32004-03-14 16:51:43 +0000796 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100797 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000798 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100799 nl = 0;
800 }
wdenk4b248f32004-03-14 16:51:43 +0000801 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000802
803 if (console_cursor_is_visible())
804 CURSOR_SET;
805}
806
Simon Glass0a6eac82016-10-17 20:12:54 -0600807static void cfb_video_putc(struct stdio_dev *dev, const char c)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000808{
809#ifdef CONFIG_CFB_CONSOLE_ANSI
810 int i;
811
812 if (c == 27) {
813 for (i = 0; i < ansi_buf_size; ++i)
814 parse_putc(ansi_buf[i]);
815 ansi_buf[0] = 27;
816 ansi_buf_size = 1;
817 return;
818 }
819
820 if (ansi_buf_size > 0) {
821 /*
822 * 0 - ESC
823 * 1 - [
824 * 2 - num1
825 * 3 - ..
826 * 4 - ;
827 * 5 - num2
828 * 6 - ..
829 * - cchar
830 */
831 int next = 0;
832
833 int flush = 0;
834 int fail = 0;
835
836 int num1 = 0;
837 int num2 = 0;
838 int cchar = 0;
839
840 ansi_buf[ansi_buf_size++] = c;
841
842 if (ansi_buf_size >= sizeof(ansi_buf))
843 fail = 1;
844
845 for (i = 0; i < ansi_buf_size; ++i) {
846 if (fail)
847 break;
848
849 switch (next) {
850 case 0:
851 if (ansi_buf[i] == 27)
852 next = 1;
853 else
854 fail = 1;
855 break;
856
857 case 1:
858 if (ansi_buf[i] == '[')
859 next = 2;
860 else
861 fail = 1;
862 break;
863
864 case 2:
865 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
866 num1 = ansi_buf[i]-'0';
867 next = 3;
868 } else if (ansi_buf[i] != '?') {
869 --i;
870 num1 = 1;
871 next = 4;
872 }
873 break;
874
875 case 3:
876 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
877 num1 *= 10;
878 num1 += ansi_buf[i]-'0';
879 } else {
880 --i;
881 next = 4;
882 }
883 break;
884
885 case 4:
886 if (ansi_buf[i] != ';') {
887 --i;
888 next = 7;
889 } else
890 next = 5;
891 break;
892
893 case 5:
894 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
895 num2 = ansi_buf[i]-'0';
896 next = 6;
897 } else
898 fail = 1;
899 break;
900
901 case 6:
902 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
903 num2 *= 10;
904 num2 += ansi_buf[i]-'0';
905 } else {
906 --i;
907 next = 7;
908 }
909 break;
910
911 case 7:
912 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
913 || ansi_buf[i] == 'J'
914 || ansi_buf[i] == 'K'
915 || ansi_buf[i] == 'h'
916 || ansi_buf[i] == 'l'
917 || ansi_buf[i] == 'm') {
918 cchar = ansi_buf[i];
919 flush = 1;
920 } else
921 fail = 1;
922 break;
923 }
924 }
925
926 if (fail) {
927 for (i = 0; i < ansi_buf_size; ++i)
928 parse_putc(ansi_buf[i]);
929 ansi_buf_size = 0;
930 return;
931 }
932
933 if (flush) {
934 if (!ansi_cursor_hidden)
935 CURSOR_OFF;
936 ansi_buf_size = 0;
937 switch (cchar) {
938 case 'A':
939 /* move cursor num1 rows up */
940 console_cursor_up(num1);
941 break;
942 case 'B':
943 /* move cursor num1 rows down */
944 console_cursor_down(num1);
945 break;
946 case 'C':
947 /* move cursor num1 columns forward */
948 console_cursor_right(num1);
949 break;
950 case 'D':
951 /* move cursor num1 columns back */
952 console_cursor_left(num1);
953 break;
954 case 'E':
955 /* move cursor num1 rows up at begin of row */
956 console_previousline(num1);
957 break;
958 case 'F':
959 /* move cursor num1 rows down at begin of row */
960 console_newline(num1);
961 break;
962 case 'G':
963 /* move cursor to column num1 */
964 console_cursor_set_position(-1, num1-1);
965 break;
966 case 'H':
967 /* move cursor to row num1, column num2 */
968 console_cursor_set_position(num1-1, num2-1);
969 break;
970 case 'J':
971 /* clear console and move cursor to 0, 0 */
972 console_clear();
973 console_cursor_set_position(0, 0);
974 break;
975 case 'K':
976 /* clear line */
977 if (num1 == 0)
978 console_clear_line(console_row,
979 console_col,
980 CONSOLE_COLS-1);
981 else if (num1 == 1)
982 console_clear_line(console_row,
983 0, console_col);
984 else
985 console_clear_line(console_row,
986 0, CONSOLE_COLS-1);
987 break;
988 case 'h':
989 ansi_cursor_hidden = 0;
990 break;
991 case 'l':
992 ansi_cursor_hidden = 1;
993 break;
994 case 'm':
995 if (num1 == 0) { /* reset swapped colors */
996 if (ansi_colors_need_revert) {
997 console_swap_colors();
998 ansi_colors_need_revert = 0;
999 }
1000 } else if (num1 == 7) { /* once swap colors */
1001 if (!ansi_colors_need_revert) {
1002 console_swap_colors();
1003 ansi_colors_need_revert = 1;
1004 }
1005 }
1006 break;
1007 }
1008 if (!ansi_cursor_hidden)
1009 CURSOR_SET;
1010 }
1011 } else {
1012 parse_putc(c);
1013 }
1014#else
1015 parse_putc(c);
1016#endif
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001017 if (cfb_do_flush_cache)
1018 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabi65618632010-08-27 15:45:47 -05001019}
wdenkc6097192002-11-03 00:24:07 +00001020
Simon Glass0a6eac82016-10-17 20:12:54 -06001021static void cfb_video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001022{
Soeren Mochd37e96e2014-10-24 16:33:30 +02001023 int flush = cfb_do_flush_cache;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001024 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +00001025
Soeren Mochd37e96e2014-10-24 16:33:30 +02001026 /* temporarily disable cache flush */
1027 cfb_do_flush_cache = 0;
1028
wdenk4b248f32004-03-14 16:51:43 +00001029 while (count--)
Simon Glass0a6eac82016-10-17 20:12:54 -06001030 cfb_video_putc(dev, *s++);
Soeren Mochd37e96e2014-10-24 16:33:30 +02001031
1032 if (flush) {
1033 cfb_do_flush_cache = flush;
1034 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1035 }
wdenkc6097192002-11-03 00:24:07 +00001036}
1037
Anatolij Gustschin10543822010-05-01 22:21:09 +02001038/*
1039 * Do not enforce drivers (or board code) to provide empty
1040 * video_set_lut() if they do not support 8 bpp format.
1041 * Implement weak default function instead.
1042 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02001043__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001044 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +02001045{
1046}
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001047
Jon Loeliger07d38a12007-07-09 17:30:01 -05001048#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +00001049
1050#define FILL_8BIT_332RGB(r,g,b) { \
1051 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1052 fb ++; \
1053}
1054
1055#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001056 *(unsigned short *)fb = \
1057 SWAP16((unsigned short)(((r>>3)<<10) | \
1058 ((g>>3)<<5) | \
1059 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001060 fb += 2; \
1061}
1062
1063#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001064 *(unsigned short *)fb = \
1065 SWAP16((unsigned short)((((r)>>3)<<11)| \
1066 (((g)>>2)<<5) | \
1067 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001068 fb += 2; \
1069}
1070
1071#define FILL_32BIT_X888RGB(r,g,b) { \
Andre Przywara1d4ed262017-03-06 01:13:38 +00001072 *(u32 *)fb = \
1073 SWAP32((unsigned int)(((r<<16) | \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001074 (g<<8) | \
1075 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001076 fb += 4; \
1077}
1078
1079#ifdef VIDEO_FB_LITTLE_ENDIAN
1080#define FILL_24BIT_888RGB(r,g,b) { \
1081 fb[0] = b; \
1082 fb[1] = g; \
1083 fb[2] = r; \
1084 fb += 3; \
1085}
1086#else
1087#define FILL_24BIT_888RGB(r,g,b) { \
1088 fb[0] = r; \
1089 fb[1] = g; \
1090 fb[2] = b; \
1091 fb += 3; \
1092}
1093#endif
1094
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001095#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001096static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001097{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001098 ushort *dst = (ushort *) fb;
1099 ushort color = (ushort) (((r >> 3) << 10) |
1100 ((g >> 3) << 5) |
1101 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001102 if (x & 1)
1103 *(--dst) = color;
1104 else
1105 *(++dst) = color;
1106}
1107#endif
wdenk4b248f32004-03-14 16:51:43 +00001108
1109/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001110 * RLE8 bitmap support
1111 */
1112
1113#ifdef CONFIG_VIDEO_BMP_RLE8
1114/* Pre-calculated color table entry */
1115struct palette {
1116 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001117 unsigned short w; /* word */
1118 unsigned int dw; /* double word */
1119 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001120};
1121
1122/*
1123 * Helper to draw encoded/unencoded run.
1124 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001125static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1126 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001127{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001128 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001129 int *off;
1130 int enc_off = 1;
1131 int i;
1132
1133 /*
1134 * Setup offset of the color index in the bitmap.
1135 * Color index of encoded run is at offset 1.
1136 */
1137 off = enc ? &enc_off : &i;
1138
1139 switch (VIDEO_DATA_FORMAT) {
1140 case GDF__8BIT_INDEX:
1141 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001142 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001143 break;
1144 case GDF_15BIT_555RGB:
1145 case GDF_16BIT_565RGB:
1146 /* differences handled while pre-calculating palette */
1147 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001148 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001149 addr += 2;
1150 }
1151 break;
1152 case GDF_32BIT_X888RGB:
1153 for (i = 0; i < cnt; i++) {
Andre Przywara1d4ed262017-03-06 01:13:38 +00001154 *(u32 *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001155 addr += 4;
1156 }
1157 break;
1158 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001159 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001160}
1161
Simon Glass1c3dbe52015-05-13 07:02:27 -06001162static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001163 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001164{
1165 unsigned char *bm;
1166 unsigned char *fbp;
1167 unsigned int cnt, runlen;
1168 int decode = 1;
1169 int x, y, bpp, i, ncolors;
1170 struct palette p[256];
Simon Glass1c3dbe52015-05-13 07:02:27 -06001171 struct bmp_color_table_entry cte;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001172 int green_shift, red_off;
Hans de Goedec67a8762015-08-04 12:15:39 +02001173 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001174 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001175
1176 x = 0;
1177 y = __le32_to_cpu(img->header.height) - 1;
1178 ncolors = __le32_to_cpu(img->header.colors_used);
1179 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001180 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001181 (y + yoff) * VIDEO_LINE_LEN +
1182 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001183
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001184 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001185
1186 /* pre-calculate and setup palette */
1187 switch (VIDEO_DATA_FORMAT) {
1188 case GDF__8BIT_INDEX:
1189 for (i = 0; i < ncolors; i++) {
1190 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001191 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001192 }
1193 break;
1194 case GDF_15BIT_555RGB:
1195 case GDF_16BIT_565RGB:
1196 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1197 green_shift = 3;
1198 red_off = 10;
1199 } else {
1200 green_shift = 2;
1201 red_off = 11;
1202 }
1203 for (i = 0; i < ncolors; i++) {
1204 cte = img->color_table[i];
1205 p[i].ce.w = SWAP16((unsigned short)
1206 (((cte.red >> 3) << red_off) |
1207 ((cte.green >> green_shift) << 5) |
1208 cte.blue >> 3));
1209 }
1210 break;
1211 case GDF_32BIT_X888RGB:
1212 for (i = 0; i < ncolors; i++) {
1213 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001214 p[i].ce.dw = SWAP32((cte.red << 16) |
1215 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001216 cte.blue);
1217 }
1218 break;
1219 default:
1220 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001221 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001222 return -1;
1223 }
1224
1225 while (decode) {
1226 switch (bm[0]) {
1227 case 0:
1228 switch (bm[1]) {
1229 case 0:
1230 /* scan line end marker */
1231 bm += 2;
1232 x = 0;
1233 y--;
1234 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001235 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001236 (y + yoff) * VIDEO_LINE_LEN +
1237 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001238 continue;
1239 case 1:
1240 /* end of bitmap data marker */
1241 decode = 0;
1242 break;
1243 case 2:
1244 /* run offset marker */
1245 x += bm[2];
1246 y -= bm[3];
1247 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001248 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001249 (y + yoff) * VIDEO_LINE_LEN +
1250 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001251 bm += 4;
1252 break;
1253 default:
1254 /* unencoded run */
1255 cnt = bm[1];
1256 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001257 pixels += cnt;
1258 if (pixels > limit)
1259 goto error;
1260
Anatolij Gustschind5011762010-03-15 14:50:25 +01001261 bm += 2;
1262 if (y < height) {
1263 if (x >= width) {
1264 x += runlen;
1265 goto next_run;
1266 }
1267 if (x + runlen > width)
1268 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001269 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001270 x += runlen;
1271 }
1272next_run:
1273 bm += runlen;
1274 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001275 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001276 }
1277 break;
1278 default:
1279 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001280 cnt = bm[0];
1281 runlen = cnt;
1282 pixels += cnt;
1283 if (pixels > limit)
1284 goto error;
1285
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001286 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001287 if (x >= width) {
1288 x += runlen;
1289 bm += 2;
1290 continue;
1291 }
1292 if (x + runlen > width)
1293 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001294 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001295 x += runlen;
1296 }
1297 bm += 2;
1298 break;
1299 }
1300 }
1301 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001302error:
1303 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1304 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001305}
1306#endif
1307
1308/*
wdenk4b248f32004-03-14 16:51:43 +00001309 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001310 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001311int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001312{
1313 ushort xcount, ycount;
1314 uchar *fb;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001315 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenk4b248f32004-03-14 16:51:43 +00001316 uchar *bmap;
1317 ushort padded_line;
1318 unsigned long width, height, bpp;
1319 unsigned colors;
1320 unsigned long compression;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001321 struct bmp_color_table_entry cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001322
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001323#ifdef CONFIG_VIDEO_BMP_GZIP
1324 unsigned char *dst = NULL;
1325 ulong len;
1326#endif
wdenk4b248f32004-03-14 16:51:43 +00001327
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001328 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001329
1330 if (!((bmp->header.signature[0] == 'B') &&
1331 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001332
1333#ifdef CONFIG_VIDEO_BMP_GZIP
1334 /*
1335 * Could be a gzipped bmp image, try to decrompress...
1336 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001337 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1338 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001339 if (dst == NULL) {
1340 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001341 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001342 }
Eric Nelson5ca05c82014-03-08 07:55:52 -07001343 /*
1344 * NB: we need to force offset of +2
1345 * See doc/README.displaying-bmps
1346 */
1347 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001348 (uchar *) bmp_image,
1349 &len) != 0) {
1350 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1351 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001352 free(dst);
1353 return 1;
1354 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001355 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001356 printf("Image could be truncated "
1357 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001358 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001359
1360 /*
1361 * Set addr to decompressed image
1362 */
Simon Glass1c3dbe52015-05-13 07:02:27 -06001363 bmp = (struct bmp_image *)(dst+2);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001364
1365 if (!((bmp->header.signature[0] == 'B') &&
1366 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001367 printf("Error: no valid bmp.gz image at %lx\n",
1368 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001369 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001370 return 1;
1371 }
1372#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001373 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001374 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001375#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001376 }
1377
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001378 width = le32_to_cpu(bmp->header.width);
1379 height = le32_to_cpu(bmp->header.height);
1380 bpp = le16_to_cpu(bmp->header.bit_count);
1381 colors = le32_to_cpu(bmp->header.colors_used);
1382 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001383
Marek Vasut68da5b12011-10-21 14:17:04 +00001384 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001385 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001386
Anatolij Gustschind5011762010-03-15 14:50:25 +01001387 if (compression != BMP_BI_RGB
1388#ifdef CONFIG_VIDEO_BMP_RLE8
1389 && compression != BMP_BI_RLE8
1390#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001391 ) {
1392 printf("Error: compression type %ld not supported\n",
1393 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001394#ifdef CONFIG_VIDEO_BMP_GZIP
1395 if (dst)
1396 free(dst);
1397#endif
wdenk4b248f32004-03-14 16:51:43 +00001398 return 1;
1399 }
1400
1401 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1402
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001403#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1404 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001405 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001406 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001407 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001408
1409 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001410 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001411 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001412 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001413#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1414
Matthias Weisseracf3baa2013-02-15 03:35:12 +00001415 /*
1416 * Just ignore elements which are completely beyond screen
1417 * dimensions.
1418 */
1419 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1420 return 0;
1421
wdenk4b248f32004-03-14 16:51:43 +00001422 if ((x + width) > VIDEO_VISIBLE_COLS)
1423 width = VIDEO_VISIBLE_COLS - x;
1424 if ((y + height) > VIDEO_VISIBLE_ROWS)
1425 height = VIDEO_VISIBLE_ROWS - y;
1426
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001427 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001428 fb = (uchar *) (video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001429 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenk4b248f32004-03-14 16:51:43 +00001430 x * VIDEO_PIXEL_SIZE);
1431
Anatolij Gustschind5011762010-03-15 14:50:25 +01001432#ifdef CONFIG_VIDEO_BMP_RLE8
1433 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001434 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001435 }
1436#endif
1437
Timur Tabi68f66182010-08-23 16:58:00 -05001438 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001439 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001440 case 4:
1441 padded_line -= width / 2;
1442 ycount = height;
1443
1444 switch (VIDEO_DATA_FORMAT) {
1445 case GDF_32BIT_X888RGB:
1446 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001447 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001448 /*
1449 * Don't assume that 'width' is an
1450 * even number
1451 */
1452 for (xcount = 0; xcount < width; xcount++) {
1453 uchar idx;
1454
1455 if (xcount & 1) {
1456 idx = *bmap & 0xF;
1457 bmap++;
1458 } else
1459 idx = *bmap >> 4;
1460 cte = bmp->color_table[idx];
1461 FILL_32BIT_X888RGB(cte.red, cte.green,
1462 cte.blue);
1463 }
1464 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001465 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001466 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001467 }
1468 break;
1469 default:
1470 puts("4bpp bitmap unsupported with current "
1471 "video mode\n");
1472 break;
1473 }
1474 break;
1475
wdenk4b248f32004-03-14 16:51:43 +00001476 case 8:
1477 padded_line -= width;
1478 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001479 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001480 for (xcount = 0; xcount < colors; ++xcount) {
1481 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001482 video_set_lut(xcount, cte.red, cte.green,
1483 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001484 }
1485 }
1486 ycount = height;
1487 switch (VIDEO_DATA_FORMAT) {
1488 case GDF__8BIT_INDEX:
1489 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001490 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001491 xcount = width;
1492 while (xcount--) {
1493 *fb++ = *bmap++;
1494 }
1495 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001496 fb -= VIDEO_LINE_LEN + width *
1497 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001498 }
1499 break;
1500 case GDF__8BIT_332RGB:
1501 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001502 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001503 xcount = width;
1504 while (xcount--) {
1505 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001506 FILL_8BIT_332RGB(cte.red, cte.green,
1507 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001508 }
1509 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001510 fb -= VIDEO_LINE_LEN + width *
1511 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001512 }
1513 break;
1514 case GDF_15BIT_555RGB:
1515 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001516#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1517 int xpos = x;
1518#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001519 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001520 xcount = width;
1521 while (xcount--) {
1522 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001523#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001524 fill_555rgb_pswap(fb, xpos++, cte.red,
1525 cte.green,
1526 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001527 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001528#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001529 FILL_15BIT_555RGB(cte.red, cte.green,
1530 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001531#endif
wdenk4b248f32004-03-14 16:51:43 +00001532 }
1533 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001534 fb -= VIDEO_LINE_LEN + width *
1535 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001536 }
1537 break;
1538 case GDF_16BIT_565RGB:
1539 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001540 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001541 xcount = width;
1542 while (xcount--) {
1543 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001544 FILL_16BIT_565RGB(cte.red, cte.green,
1545 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001546 }
1547 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001548 fb -= VIDEO_LINE_LEN + width *
1549 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001550 }
1551 break;
1552 case GDF_32BIT_X888RGB:
1553 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001554 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001555 xcount = width;
1556 while (xcount--) {
1557 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001558 FILL_32BIT_X888RGB(cte.red, cte.green,
1559 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001560 }
1561 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001562 fb -= VIDEO_LINE_LEN + width *
1563 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001564 }
1565 break;
1566 case GDF_24BIT_888RGB:
1567 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001568 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001569 xcount = width;
1570 while (xcount--) {
1571 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001572 FILL_24BIT_888RGB(cte.red, cte.green,
1573 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001574 }
1575 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001576 fb -= VIDEO_LINE_LEN + width *
1577 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001578 }
1579 break;
1580 }
1581 break;
1582 case 24:
1583 padded_line -= 3 * width;
1584 ycount = height;
1585 switch (VIDEO_DATA_FORMAT) {
1586 case GDF__8BIT_332RGB:
1587 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001588 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001589 xcount = width;
1590 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001591 FILL_8BIT_332RGB(bmap[2], bmap[1],
1592 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001593 bmap += 3;
1594 }
1595 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001596 fb -= VIDEO_LINE_LEN + width *
1597 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001598 }
1599 break;
1600 case GDF_15BIT_555RGB:
1601 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001602#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1603 int xpos = x;
1604#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001605 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001606 xcount = width;
1607 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001608#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001609 fill_555rgb_pswap(fb, xpos++, bmap[2],
1610 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001611 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001612#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001613 FILL_15BIT_555RGB(bmap[2], bmap[1],
1614 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001615#endif
wdenk4b248f32004-03-14 16:51:43 +00001616 bmap += 3;
1617 }
1618 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001619 fb -= VIDEO_LINE_LEN + width *
1620 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001621 }
1622 break;
1623 case GDF_16BIT_565RGB:
1624 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001625 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001626 xcount = width;
1627 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001628 FILL_16BIT_565RGB(bmap[2], bmap[1],
1629 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001630 bmap += 3;
1631 }
1632 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001633 fb -= VIDEO_LINE_LEN + width *
1634 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001635 }
1636 break;
1637 case GDF_32BIT_X888RGB:
1638 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001639 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001640 xcount = width;
1641 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001642 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1643 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001644 bmap += 3;
1645 }
1646 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001647 fb -= VIDEO_LINE_LEN + width *
1648 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001649 }
1650 break;
1651 case GDF_24BIT_888RGB:
1652 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001653 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001654 xcount = width;
1655 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001656 FILL_24BIT_888RGB(bmap[2], bmap[1],
1657 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001658 bmap += 3;
1659 }
1660 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001661 fb -= VIDEO_LINE_LEN + width *
1662 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001663 }
1664 break;
1665 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001666 printf("Error: 24 bits/pixel bitmap incompatible "
1667 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001668 break;
1669 }
1670 break;
1671 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001672 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1673 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001674 break;
1675 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001676
1677#ifdef CONFIG_VIDEO_BMP_GZIP
1678 if (dst) {
1679 free(dst);
1680 }
1681#endif
1682
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001683 if (cfb_do_flush_cache)
1684 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk4b248f32004-03-14 16:51:43 +00001685 return (0);
1686}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001687#endif
wdenk4b248f32004-03-14 16:51:43 +00001688
wdenk4b248f32004-03-14 16:51:43 +00001689
wdenkc6097192002-11-03 00:24:07 +00001690#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001691static int video_logo_xpos;
1692static int video_logo_ypos;
1693
Hans de Goedec4c9e812015-08-04 12:21:40 +02001694static void plot_logo_or_black(void *screen, int x, int y, int black);
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001695
Hans de Goedec4c9e812015-08-04 12:21:40 +02001696static void logo_plot(void *screen, int x, int y)
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001697{
Hans de Goedec4c9e812015-08-04 12:21:40 +02001698 plot_logo_or_black(screen, x, y, 0);
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001699}
1700
1701static void logo_black(void)
1702{
Hans de Goedec4c9e812015-08-04 12:21:40 +02001703 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001704 1);
1705}
1706
1707static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1708{
1709 if (argc != 1)
1710 return cmd_usage(cmdtp);
1711
1712 logo_black();
1713 return 0;
1714}
1715
1716U_BOOT_CMD(
1717 clrlogo, 1, 0, do_clrlogo,
1718 "fill the boot logo area with black",
1719 " "
1720 );
1721
Hans de Goedec4c9e812015-08-04 12:21:40 +02001722static void plot_logo_or_black(void *screen, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001723{
wdenkc6097192002-11-03 00:24:07 +00001724
wdenk4b248f32004-03-14 16:51:43 +00001725 int xcount, i;
Hans de Goedec67a8762015-08-04 12:15:39 +02001726 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001727 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001728 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1729 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001730 unsigned char *dest;
1731
1732#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1733 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001734 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001735 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001736 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001737
1738 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001739 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001740 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001741 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001742#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1743
Hans de Goedec67a8762015-08-04 12:15:39 +02001744 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001745
1746#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001747 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001748
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001749 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001750 logo_red = malloc(BMP_LOGO_COLORS);
1751 logo_green = malloc(BMP_LOGO_COLORS);
1752 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001753 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001754 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1755 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1756 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1757 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1758 }
wdenka6c7ad22002-12-03 21:28:10 +00001759#else
wdenk4b248f32004-03-14 16:51:43 +00001760 source = linux_logo;
1761 logo_red = linux_logo_red;
1762 logo_green = linux_logo_green;
1763 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001764#endif
wdenk8bde7f72003-06-27 21:31:46 +00001765
wdenk4b248f32004-03-14 16:51:43 +00001766 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1767 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001768 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1769 logo_red[i], logo_green[i],
1770 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001771 }
wdenk8bde7f72003-06-27 21:31:46 +00001772 }
wdenkc6097192002-11-03 00:24:07 +00001773
wdenk4b248f32004-03-14 16:51:43 +00001774 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001775#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1776 int xpos = x;
1777#endif
wdenk4b248f32004-03-14 16:51:43 +00001778 xcount = VIDEO_LOGO_WIDTH;
1779 while (xcount--) {
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001780 if (black) {
1781 r = 0x00;
1782 g = 0x00;
1783 b = 0x00;
1784 } else {
1785 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1786 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1787 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1788 }
wdenk8bde7f72003-06-27 21:31:46 +00001789
wdenk4b248f32004-03-14 16:51:43 +00001790 switch (VIDEO_DATA_FORMAT) {
1791 case GDF__8BIT_INDEX:
1792 *dest = *source;
1793 break;
1794 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001795 *dest = ((r >> 5) << 5) |
1796 ((g >> 5) << 2) |
1797 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001798 break;
1799 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001800#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001801 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001802#else
wdenk4b248f32004-03-14 16:51:43 +00001803 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001804 SWAP16((unsigned short) (
1805 ((r >> 3) << 10) |
1806 ((g >> 3) << 5) |
1807 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001808#endif
wdenk4b248f32004-03-14 16:51:43 +00001809 break;
1810 case GDF_16BIT_565RGB:
1811 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001812 SWAP16((unsigned short) (
1813 ((r >> 3) << 11) |
1814 ((g >> 2) << 5) |
1815 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001816 break;
1817 case GDF_32BIT_X888RGB:
Andre Przywara1d4ed262017-03-06 01:13:38 +00001818 *(u32 *) dest =
1819 SWAP32((u32) (
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001820 (r << 16) |
1821 (g << 8) |
1822 b));
wdenk4b248f32004-03-14 16:51:43 +00001823 break;
1824 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001825#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001826 dest[0] = b;
1827 dest[1] = g;
1828 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001829#else
wdenk4b248f32004-03-14 16:51:43 +00001830 dest[0] = r;
1831 dest[1] = g;
1832 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001833#endif
wdenk4b248f32004-03-14 16:51:43 +00001834 break;
1835 }
1836 source++;
1837 dest += VIDEO_PIXEL_SIZE;
1838 }
1839 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001840 }
wdenka6c7ad22002-12-03 21:28:10 +00001841#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001842 free(logo_red);
1843 free(logo_green);
1844 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001845#endif
wdenkc6097192002-11-03 00:24:07 +00001846}
1847
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001848static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001849{
wdenk4b248f32004-03-14 16:51:43 +00001850 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001851 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001852 __maybe_unused ulong addr;
1853 __maybe_unused char *s;
Anatolij Gustschinb4fc6f22016-11-30 14:30:59 +01001854 __maybe_unused int len, ret, space;
wdenkc6097192002-11-03 00:24:07 +00001855
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001856 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001857
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001858#ifdef CONFIG_SPLASH_SCREEN
Simon Glass00caae62017-08-03 12:22:12 -06001859 s = env_get("splashimage");
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001860 if (s != NULL) {
Anatolij Gustschinb4fc6f22016-11-30 14:30:59 +01001861 ret = splash_screen_prepare();
1862 if (ret < 0)
1863 return video_fb_address;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001864 addr = simple_strtoul(s, NULL, 16);
1865
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001866 if (video_display_bitmap(addr,
1867 video_logo_xpos,
1868 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001869 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00001870 return ((void *) (video_fb_address));
1871 }
1872 }
1873#endif /* CONFIG_SPLASH_SCREEN */
1874
Hans de Goedec4c9e812015-08-04 12:21:40 +02001875 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001876
1877#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1878 /*
1879 * when using splashpos for video_logo, skip any info
1880 * output on video console if the logo is not at 0,0
1881 */
1882 if (video_logo_xpos || video_logo_ypos) {
1883 /*
1884 * video_logo_height is used in text and cursor offset
1885 * calculations. Since the console is below the logo,
1886 * we need to adjust the logo height
1887 */
1888 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001889 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001890 VIDEO_LOGO_HEIGHT) / 2);
1891 else if (video_logo_ypos > 0)
1892 video_logo_height += video_logo_ypos;
1893
1894 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1895 }
1896#endif
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02001897 if (board_cfb_skip())
1898 return 0;
wdenk4b248f32004-03-14 16:51:43 +00001899
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001900 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001901
Tim Harveyadde4352016-05-24 14:59:59 -07001902#ifndef CONFIG_HIDE_LOGO_VERSION
Peng Fanf9d891f2018-01-02 15:25:37 +08001903 space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001904 len = strlen(info);
1905
1906 if (len > space) {
Peng Fanf9d891f2018-01-02 15:25:37 +08001907 int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
1908 uchar *p = (uchar *) info;
1909
1910 while (len) {
1911 if (len > space) {
1912 video_drawchars(xx, yy, p, space);
1913 len -= space;
1914
1915 p = (uchar *)p + space;
1916
1917 if (!y_off) {
1918 xx += VIDEO_FONT_WIDTH;
1919 space--;
1920 }
1921 yy += VIDEO_FONT_HEIGHT;
1922
1923 y_off++;
1924 } else {
1925 video_drawchars(xx, yy, p, len);
1926 len = 0;
1927 }
1928 }
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001929 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001930 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001931
1932#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00001933 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001934 int i, n =
1935 ((video_logo_height -
1936 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001937
wdenk4b248f32004-03-14 16:51:43 +00001938 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001939 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001940 if (!*info)
1941 continue;
1942
1943 len = strlen(info);
1944 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001945 video_drawchars(VIDEO_INFO_X,
1946 VIDEO_INFO_Y +
1947 (i + y_off) *
1948 VIDEO_FONT_HEIGHT,
1949 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001950 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001951 video_drawchars(VIDEO_INFO_X +
1952 VIDEO_FONT_WIDTH,
1953 VIDEO_INFO_Y +
1954 (i + y_off) *
1955 VIDEO_FONT_HEIGHT,
1956 (uchar *) info + space,
1957 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001958 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001959 video_drawstring(VIDEO_INFO_X,
1960 VIDEO_INFO_Y +
1961 (i + y_off) *
1962 VIDEO_FONT_HEIGHT,
1963 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001964 }
wdenk4b248f32004-03-14 16:51:43 +00001965 }
1966 }
wdenkc6097192002-11-03 00:24:07 +00001967#endif
Tim Harveyadde4352016-05-24 14:59:59 -07001968#endif
wdenkc6097192002-11-03 00:24:07 +00001969
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001970 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001971}
1972#endif
1973
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001974static int cfb_fb_is_in_dram(void)
1975{
1976 bd_t *bd = gd->bd;
Andy Shevchenkodaab59a2017-07-05 16:25:22 +03001977#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001978defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1979 ulong start, end;
1980 int i;
1981
1982 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1983 start = bd->bi_dram[i].start;
1984 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1985 if ((ulong)video_fb_address >= start &&
1986 (ulong)video_fb_address < end)
1987 return 1;
1988 }
1989#else
1990 if ((ulong)video_fb_address >= bd->bi_memstart &&
1991 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1992 return 1;
1993#endif
1994 return 0;
1995}
1996
Heiko Schocher45ae2542013-10-22 11:06:06 +02001997void video_clear(void)
1998{
1999 if (!video_fb_address)
2000 return;
2001#ifdef VIDEO_HW_RECTFILL
2002 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2003 0, /* dest pos x */
2004 0, /* dest pos y */
2005 VIDEO_VISIBLE_COLS, /* frame width */
2006 VIDEO_VISIBLE_ROWS, /* frame height */
2007 bgx /* fill color */
2008 );
2009#else
2010 memsetl(video_fb_address,
2011 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2012#endif
2013}
2014
Simon Glass0a6eac82016-10-17 20:12:54 -06002015static int cfg_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002016{
wdenk4b248f32004-03-14 16:51:43 +00002017 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002018
Wolfgang Denk57912932011-07-30 12:48:09 +00002019 pGD = video_hw_init();
2020 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00002021 return -1;
wdenkc6097192002-11-03 00:24:07 +00002022
wdenk4b248f32004-03-14 16:51:43 +00002023 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002024
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002025 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2026
wdenk4b248f32004-03-14 16:51:43 +00002027 /* Init drawing pats */
2028 switch (VIDEO_DATA_FORMAT) {
2029 case GDF__8BIT_INDEX:
Simon Glass002f9672016-10-17 20:12:44 -06002030 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2031 CONFIG_SYS_CONSOLE_FG_COL,
2032 CONFIG_SYS_CONSOLE_FG_COL);
2033 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2034 CONFIG_SYS_CONSOLE_BG_COL,
2035 CONFIG_SYS_CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00002036 fgx = 0x01010101;
2037 bgx = 0x00000000;
2038 break;
2039 case GDF__8BIT_332RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002040 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2041 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2042 CONFIG_SYS_CONSOLE_FG_COL >> 6);
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002043 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2044 color8;
Simon Glass002f9672016-10-17 20:12:44 -06002045 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2046 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2047 CONFIG_SYS_CONSOLE_BG_COL >> 6);
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002048 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2049 color8;
wdenk4b248f32004-03-14 16:51:43 +00002050 break;
2051 case GDF_15BIT_555RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002052 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2053 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2054 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2055 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2056 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2057 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2058 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2059 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2060 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2061 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2062 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2063 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002064 break;
2065 case GDF_16BIT_565RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002066 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2067 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2068 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2069 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2070 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2071 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2072 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2073 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2074 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2075 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2076 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2077 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002078 break;
2079 case GDF_32BIT_X888RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002080 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2081 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2082 CONFIG_SYS_CONSOLE_FG_COL;
2083 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2084 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2085 CONFIG_SYS_CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002086 break;
2087 case GDF_24BIT_888RGB:
Simon Glass002f9672016-10-17 20:12:44 -06002088 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2089 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2090 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2091 CONFIG_SYS_CONSOLE_FG_COL;
2092 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2093 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2094 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2095 CONFIG_SYS_CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002096 break;
2097 }
2098 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002099
Rob Clark8ef05352017-08-03 12:47:01 -04002100 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
2101 video_clear();
Heiko Schocher45ae2542013-10-22 11:06:06 +02002102
wdenkc6097192002-11-03 00:24:07 +00002103#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00002104 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002105 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002106 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002107#else
wdenk4b248f32004-03-14 16:51:43 +00002108 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002109#endif
2110
wdenk4b248f32004-03-14 16:51:43 +00002111 /* Initialize the console */
2112 console_col = 0;
2113 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002114
Eric Nelsondb0d47d2013-05-06 14:27:28 +02002115 if (cfb_do_flush_cache)
2116 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2117
wdenk4b248f32004-03-14 16:51:43 +00002118 return 0;
wdenkc6097192002-11-03 00:24:07 +00002119}
2120
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002121/*
2122 * Implement a weak default function for boards that optionally
2123 * need to skip the video initialization.
2124 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02002125__weak int board_video_skip(void)
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002126{
2127 /* As default, don't skip test */
2128 return 0;
2129}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002130
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002131int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002132{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02002133 struct stdio_dev console_dev;
Simon Glass5692ccf2015-03-02 12:40:50 -07002134 bool have_keyboard;
Bin Meng8ceb2422015-08-24 01:00:07 -07002135 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00002136
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002137 /* Check if video initialization should be skipped */
2138 if (board_video_skip())
2139 return 0;
2140
wdenk81050922004-07-11 20:04:51 +00002141 /* Init video chip - returns with framebuffer cleared */
Simon Glass0a6eac82016-10-17 20:12:54 -06002142 if (cfg_video_init() == -1)
Bin Meng8ceb2422015-08-24 01:00:07 -07002143 return 0;
wdenk81050922004-07-11 20:04:51 +00002144
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002145 if (board_cfb_skip())
2146 return 0;
2147
Simon Glass5692ccf2015-03-02 12:40:50 -07002148#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2149 have_keyboard = false;
2150#elif defined(CONFIG_OF_CONTROL)
2151 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2152 "u-boot,no-keyboard");
2153#else
2154 have_keyboard = true;
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002155#endif
Simon Glass5692ccf2015-03-02 12:40:50 -07002156 if (have_keyboard) {
2157 debug("KBD: Keyboard init ...\n");
2158#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07002159 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Simon Glass5692ccf2015-03-02 12:40:50 -07002160#endif
2161 }
wdenkc6097192002-11-03 00:24:07 +00002162
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002163 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002164 memset(&console_dev, 0, sizeof(console_dev));
2165 strcpy(console_dev.name, "vga");
Bin Meng1caf9342015-11-03 23:23:37 -08002166 console_dev.flags = DEV_FLAGS_OUTPUT;
Simon Glass0a6eac82016-10-17 20:12:54 -06002167 console_dev.putc = cfb_video_putc; /* 'putc' function */
2168 console_dev.puts = cfb_video_puts; /* 'puts' function */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002169
2170#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07002171 if (have_keyboard && keyboard_ok) {
Simon Glass5692ccf2015-03-02 12:40:50 -07002172 /* Also init console device */
2173 console_dev.flags |= DEV_FLAGS_INPUT;
2174 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2175 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2176 }
2177#endif
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002178
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002179 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002180 return 0;
2181
2182 /* Return success */
2183 return 1;
wdenkc6097192002-11-03 00:24:07 +00002184}
Stefan Reinauerc20ee072012-09-28 15:11:12 +00002185
2186void video_position_cursor(unsigned col, unsigned row)
2187{
2188 console_col = min(col, CONSOLE_COLS - 1);
2189 console_row = min(row, CONSOLE_ROWS - 1);
2190}
2191
2192int video_get_pixel_width(void)
2193{
2194 return VIDEO_VISIBLE_COLS;
2195}
2196
2197int video_get_pixel_height(void)
2198{
2199 return VIDEO_VISIBLE_ROWS;
2200}
2201
2202int video_get_screen_rows(void)
2203{
2204 return CONSOLE_ROWS;
2205}
2206
2207int video_get_screen_columns(void)
2208{
2209 return CONSOLE_COLS;
2210}