blob: 52b109f1551062b22d0523919b35a2f0cf7afd41 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00002/*
3 * (C) Copyright 2002 ELTEC Elektronik AG
4 * Frank Gottschling <fgottschling@eltec.de>
wdenkc6097192002-11-03 00:24:07 +00005 */
6
7/*
8 * cfb_console.c
9 *
10 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
11 *
12 * At the moment only the 8x16 font is tested and the font fore- and
13 * background color is limited to black/white/gray colors. The Linux
14 * logo can be placed in the upper left corner and additional board
Wolfgang Denk64e40d72011-07-29 09:55:27 +000015 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000016 *
Simon Glass39f615e2015-11-11 10:05:47 -070017 * The console driver can use a keyboard interface for character input
18 * but this is deprecated. Only rk51 uses it.
19 *
20 * Character output goes to a memory-mapped video
wdenkc6097192002-11-03 00:24:07 +000021 * framebuffer with little or big-endian organisation.
22 * With environment setting 'console=serial' the console i/o can be
23 * forced to serial port.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000024 *
25 * The driver uses graphic specific defines/parameters/functions:
26 *
27 * (for SMI LynxE graphic chip)
28 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000029 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
30 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
31 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
32 *
33 * Console Parameters are set by graphic drivers global struct:
34 *
35 * VIDEO_VISIBLE_COLS - x resolution
36 * VIDEO_VISIBLE_ROWS - y resolution
37 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
38 * VIDEO_DATA_FORMAT - graphical data format GDF
39 * VIDEO_FB_ADRS - start of video memory
40 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000041 * VIDEO_KBD_INIT_FCT - init function for keyboard
42 * VIDEO_TSTC_FCT - keyboard_tstc function
43 * VIDEO_GETC_FCT - keyboard_getc function
44 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000045 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
46 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
47 * strings that normaly goes to serial
48 * port. This define requires a board
49 * specific function:
50 * video_drawstring (VIDEO_INFO_X,
51 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
52 * info);
53 * that fills a info buffer at i=row.
54 * s.a: board/eltec/bab7xx.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000055 *
56 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
57 * character. No blinking is provided.
58 * Uses the macros CURSOR_SET and
59 * CURSOR_OFF.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000060 */
wdenkc6097192002-11-03 00:24:07 +000061
62#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -060063#include <command.h>
Simon Glass9edefc22019-11-14 12:57:37 -070064#include <cpu_func.h>
Simon Glass7b51b572019-08-01 09:46:52 -060065#include <env.h>
Simon Glass5692ccf2015-03-02 12:40:50 -070066#include <fdtdec.h>
Simon Glass0c670fc2019-08-01 09:46:36 -060067#include <gzip.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060068#include <log.h>
Pali Rohárbdfb6d72021-08-02 15:18:31 +020069#include <version_string.h>
wdenka6c7ad22002-12-03 21:28:10 +000070#include <malloc.h>
Simon Glass0a6eac82016-10-17 20:12:54 -060071#include <video.h>
Simon Glass401d1c42020-10-30 21:38:53 -060072#include <asm/global_data.h>
Simon Glass7de8bd02021-08-07 07:24:01 -060073#include <dm/ofnode.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +000074#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +000075
Wolfgang Denk64e40d72011-07-29 09:55:27 +000076/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +000077 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
78 */
wdenkc6097192002-11-03 00:24:07 +000079#include <video_fb.h>
80
Robert Winklerdd4425e2013-06-17 11:31:29 -070081#include <splash.h>
82
Wolfgang Denk64e40d72011-07-29 09:55:27 +000083/*
84 * some Macros
85 */
wdenk4b248f32004-03-14 16:51:43 +000086#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
87#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
88#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
89#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
90#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +000091
Wolfgang Denk64e40d72011-07-29 09:55:27 +000092/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +000093 * Console device
94 */
wdenkc6097192002-11-03 00:24:07 +000095
wdenkc6097192002-11-03 00:24:07 +000096#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020097#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +000098#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +000099
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500100#if defined(CONFIG_CMD_DATE)
101#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000102#endif
103
Jon Loeliger07d38a12007-07-09 17:30:01 -0500104#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000105#include <watchdog.h>
106#include <bmp_layout.h>
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200107#include <splash.h>
Jon Loeliger07d38a12007-07-09 17:30:01 -0500108#endif
wdenk4b248f32004-03-14 16:51:43 +0000109
Simon Glassa4206572016-10-17 20:12:50 -0600110#if !defined(CONFIG_VIDEO_SW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000111/* no Cursor defined */
112#define CURSOR_ON
113#define CURSOR_OFF
114#define CURSOR_SET
115#endif
116
Simon Glass7fe09332015-10-18 21:17:18 -0600117#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000118void console_cursor(int state);
119
Timur Tabi65618632010-08-27 15:45:47 -0500120#define CURSOR_ON console_cursor(1)
121#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000122#define CURSOR_SET video_set_cursor()
Simon Glass7fe09332015-10-18 21:17:18 -0600123#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000124
wdenk4b248f32004-03-14 16:51:43 +0000125#define VIDEO_COLS VIDEO_VISIBLE_COLS
126#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedec67a8762015-08-04 12:15:39 +0200127#ifndef VIDEO_LINE_LEN
128#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
129#endif
130#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenk4b248f32004-03-14 16:51:43 +0000131#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000132
wdenk4b248f32004-03-14 16:51:43 +0000133#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000134
wdenk4b248f32004-03-14 16:51:43 +0000135#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
136#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
137#define CONSOLE_ROW_FIRST (video_console_address)
138#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
139#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
140#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass3c0b6682015-01-01 16:17:57 -0700141
142/* By default we scroll by a single line */
143#ifndef CONFIG_CONSOLE_SCROLL_LINES
144#define CONFIG_CONSOLE_SCROLL_LINES 1
145#endif
wdenkc6097192002-11-03 00:24:07 +0000146
147/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000148#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000149#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
150 ((x) >> 8) \
151 )
152#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
153 (((x) & 0x0000ff00) << 8) | \
154 (((x) & 0x00ff0000) >> 8) | \
155 (((x) & 0xff000000) >> 24) \
156 )
157#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
158 (((x) & 0x0000ff00) >> 8) | \
159 (((x) & 0x00ff0000) << 8) | \
160 (((x) & 0xff000000) >> 8) \
161 )
wdenkc6097192002-11-03 00:24:07 +0000162#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000163#define SWAP16(x) (x)
164#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200165#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000166#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500167#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000168#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100169#endif
wdenkc6097192002-11-03 00:24:07 +0000170#endif
171
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200172DECLARE_GLOBAL_DATA_PTR;
173
wdenkc6097192002-11-03 00:24:07 +0000174/* Locals */
175static GraphicDevice *pGD; /* Pointer to Graphic array */
176
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000177static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000178static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000179
Simon Glass2c8ee302021-11-19 13:24:02 -0700180static int video_logo_height; /* not supported anymore */
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100181
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000182static int __maybe_unused cursor_state;
183static int __maybe_unused old_col;
184static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000185
Wolfgang Denk57912932011-07-30 12:48:09 +0000186static int console_col; /* cursor col */
187static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000188
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000189static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000190
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200191static int cfb_do_flush_cache;
192
Pali Rohár33a35bb2012-10-19 13:30:09 +0000193#ifdef CONFIG_CFB_CONSOLE_ANSI
194static char ansi_buf[10];
195static int ansi_buf_size;
196static int ansi_colors_need_revert;
197static int ansi_cursor_hidden;
198#endif
199
wdenkc6097192002-11-03 00:24:07 +0000200static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000201 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
202 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
203 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
204 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
205};
wdenkc6097192002-11-03 00:24:07 +0000206
207static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000208 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
209};
wdenkc6097192002-11-03 00:24:07 +0000210
211static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000212 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
213};
wdenkc6097192002-11-03 00:24:07 +0000214
215static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000216 {0x00000000, 0x00000000, 0x00000000},
217 {0x00000000, 0x00000000, 0x00ffffff},
218 {0x00000000, 0x0000ffff, 0xff000000},
219 {0x00000000, 0x0000ffff, 0xffffffff},
220 {0x000000ff, 0xffff0000, 0x00000000},
221 {0x000000ff, 0xffff0000, 0x00ffffff},
222 {0x000000ff, 0xffffffff, 0xff000000},
223 {0x000000ff, 0xffffffff, 0xffffffff},
224 {0xffffff00, 0x00000000, 0x00000000},
225 {0xffffff00, 0x00000000, 0x00ffffff},
226 {0xffffff00, 0x0000ffff, 0xff000000},
227 {0xffffff00, 0x0000ffff, 0xffffffff},
228 {0xffffffff, 0xffff0000, 0x00000000},
229 {0xffffffff, 0xffff0000, 0x00ffffff},
230 {0xffffffff, 0xffffffff, 0xff000000},
231 {0xffffffff, 0xffffffff, 0xffffffff}
232};
wdenkc6097192002-11-03 00:24:07 +0000233
234static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000235 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
236 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
237 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
238 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
239 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
240 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
241 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
242 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
243 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
244 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
245 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
246 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
247 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
248 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
249 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
250 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
251};
wdenkc6097192002-11-03 00:24:07 +0000252
Heiko Schocher2bc4aa52013-08-03 07:22:53 +0200253/*
254 * Implement a weak default function for boards that optionally
255 * need to skip the cfb initialization.
256 */
257__weak int board_cfb_skip(void)
258{
259 /* As default, don't skip cfb init */
260 return 0;
261}
262
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000263static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000264{
wdenk4b248f32004-03-14 16:51:43 +0000265 u8 *cdat, *dest, *dest0;
266 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000267
wdenk4b248f32004-03-14 16:51:43 +0000268 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
269 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000270
wdenk4b248f32004-03-14 16:51:43 +0000271 switch (VIDEO_DATA_FORMAT) {
272 case GDF__8BIT_INDEX:
273 case GDF__8BIT_332RGB:
274 while (count--) {
275 c = *s;
276 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
277 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000278 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000279 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000280
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000281 ((u32 *) dest)[0] =
282 (video_font_draw_table8[bits >> 4] &
283 eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200284
285 if (VIDEO_FONT_WIDTH == 4)
286 continue;
287
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000288 ((u32 *) dest)[1] =
289 (video_font_draw_table8[bits & 15] &
290 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000291 }
292 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
293 s++;
294 }
295 break;
wdenkc6097192002-11-03 00:24:07 +0000296
wdenk4b248f32004-03-14 16:51:43 +0000297 case GDF_15BIT_555RGB:
298 while (count--) {
299 c = *s;
300 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
301 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000302 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000303 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000304
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000305 ((u32 *) dest)[0] =
306 SHORTSWAP32((video_font_draw_table15
307 [bits >> 6] & eorx) ^
308 bgx);
309 ((u32 *) dest)[1] =
310 SHORTSWAP32((video_font_draw_table15
311 [bits >> 4 & 3] & eorx) ^
312 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200313
314 if (VIDEO_FONT_WIDTH == 4)
315 continue;
316
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000317 ((u32 *) dest)[2] =
318 SHORTSWAP32((video_font_draw_table15
319 [bits >> 2 & 3] & eorx) ^
320 bgx);
321 ((u32 *) dest)[3] =
322 SHORTSWAP32((video_font_draw_table15
323 [bits & 3] & eorx) ^
324 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000325 }
326 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
327 s++;
328 }
329 break;
wdenkc6097192002-11-03 00:24:07 +0000330
wdenk4b248f32004-03-14 16:51:43 +0000331 case GDF_16BIT_565RGB:
332 while (count--) {
333 c = *s;
334 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
335 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000336 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000337 u8 bits = *cdat++;
338
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000339 ((u32 *) dest)[0] =
340 SHORTSWAP32((video_font_draw_table16
341 [bits >> 6] & eorx) ^
342 bgx);
343 ((u32 *) dest)[1] =
344 SHORTSWAP32((video_font_draw_table16
345 [bits >> 4 & 3] & eorx) ^
346 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200347
348 if (VIDEO_FONT_WIDTH == 4)
349 continue;
350
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000351 ((u32 *) dest)[2] =
352 SHORTSWAP32((video_font_draw_table16
353 [bits >> 2 & 3] & eorx) ^
354 bgx);
355 ((u32 *) dest)[3] =
356 SHORTSWAP32((video_font_draw_table16
357 [bits & 3] & eorx) ^
358 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000359 }
360 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
361 s++;
362 }
363 break;
364
365 case GDF_32BIT_X888RGB:
366 while (count--) {
367 c = *s;
368 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
369 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000370 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000371 u8 bits = *cdat++;
372
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000373 ((u32 *) dest)[0] =
374 SWAP32((video_font_draw_table32
375 [bits >> 4][0] & eorx) ^ bgx);
376 ((u32 *) dest)[1] =
377 SWAP32((video_font_draw_table32
378 [bits >> 4][1] & eorx) ^ bgx);
379 ((u32 *) dest)[2] =
380 SWAP32((video_font_draw_table32
381 [bits >> 4][2] & eorx) ^ bgx);
382 ((u32 *) dest)[3] =
383 SWAP32((video_font_draw_table32
384 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200385
386
387 if (VIDEO_FONT_WIDTH == 4)
388 continue;
389
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000390 ((u32 *) dest)[4] =
391 SWAP32((video_font_draw_table32
392 [bits & 15][0] & eorx) ^ bgx);
393 ((u32 *) dest)[5] =
394 SWAP32((video_font_draw_table32
395 [bits & 15][1] & eorx) ^ bgx);
396 ((u32 *) dest)[6] =
397 SWAP32((video_font_draw_table32
398 [bits & 15][2] & eorx) ^ bgx);
399 ((u32 *) dest)[7] =
400 SWAP32((video_font_draw_table32
401 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000402 }
403 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
404 s++;
405 }
406 break;
407
408 case GDF_24BIT_888RGB:
409 while (count--) {
410 c = *s;
411 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
412 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000413 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000414 u8 bits = *cdat++;
415
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000416 ((u32 *) dest)[0] =
417 (video_font_draw_table24[bits >> 4][0]
418 & eorx) ^ bgx;
419 ((u32 *) dest)[1] =
420 (video_font_draw_table24[bits >> 4][1]
421 & eorx) ^ bgx;
422 ((u32 *) dest)[2] =
423 (video_font_draw_table24[bits >> 4][2]
424 & eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200425
426 if (VIDEO_FONT_WIDTH == 4)
427 continue;
428
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000429 ((u32 *) dest)[3] =
430 (video_font_draw_table24[bits & 15][0]
431 & eorx) ^ bgx;
432 ((u32 *) dest)[4] =
433 (video_font_draw_table24[bits & 15][1]
434 & eorx) ^ bgx;
435 ((u32 *) dest)[5] =
436 (video_font_draw_table24[bits & 15][2]
437 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000438 }
439 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
440 s++;
441 }
442 break;
wdenk8bde7f72003-06-27 21:31:46 +0000443 }
wdenkc6097192002-11-03 00:24:07 +0000444}
445
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000446static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000447{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000448 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000449}
450
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000451static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000452{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000453 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000454}
455
Simon Glass7fe09332015-10-18 21:17:18 -0600456#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000457static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000458{
Gabe Black03d31fc2011-11-30 13:50:50 +0000459 if (cursor_state)
460 console_cursor(0);
461 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000462}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000463
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000464static void video_invertchar(int xx, int yy)
465{
466 int firstx = xx * VIDEO_PIXEL_SIZE;
467 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
468 int firsty = yy * VIDEO_LINE_LEN;
469 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
470 int x, y;
471 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
472 for (x = firstx; x < lastx; x++) {
473 u8 *dest = (u8 *)(video_fb_address) + x + y;
474 *dest = ~*dest;
475 }
476 }
477}
Gabe Black03d31fc2011-11-30 13:50:50 +0000478
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000479void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000480{
Gabe Black03d31fc2011-11-30 13:50:50 +0000481 if (cursor_state != state) {
482 if (cursor_state) {
483 /* turn off the cursor */
484 video_invertchar(old_col * VIDEO_FONT_WIDTH,
485 old_row * VIDEO_FONT_HEIGHT +
486 video_logo_height);
487 } else {
488 /* turn off the cursor and record where it is */
489 video_invertchar(console_col * VIDEO_FONT_WIDTH,
490 console_row * VIDEO_FONT_HEIGHT +
491 video_logo_height);
492 old_col = console_col;
493 old_row = console_row;
494 }
495 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000496 }
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200497 if (cfb_do_flush_cache)
498 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000499}
500#endif
501
wdenkc6097192002-11-03 00:24:07 +0000502#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000503static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000504{
wdenk4b248f32004-03-14 16:51:43 +0000505 while (c--)
506 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000507}
508#endif
509
wdenkc6097192002-11-03 00:24:07 +0000510#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000511static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000512{
wdenk4b248f32004-03-14 16:51:43 +0000513 while (c--)
514 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000515}
516#endif
517
Pali Rohár90f60a82012-04-28 07:26:44 +0000518static void console_clear_line(int line, int begin, int end)
519{
520#ifdef VIDEO_HW_RECTFILL
521 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
522 VIDEO_FONT_WIDTH * begin, /* dest pos x */
523 video_logo_height +
524 VIDEO_FONT_HEIGHT * line, /* dest pos y */
525 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
526 VIDEO_FONT_HEIGHT, /* frame height */
527 bgx /* fill color */
528 );
529#else
530 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
531 memsetl(CONSOLE_ROW_FIRST +
532 CONSOLE_ROW_SIZE * line, /* offset of row */
533 CONSOLE_ROW_SIZE >> 2, /* length of row */
534 bgx /* fill color */
535 );
536 } else {
537 void *offset;
538 int i, size;
539
540 offset = CONSOLE_ROW_FIRST +
541 CONSOLE_ROW_SIZE * line + /* offset of row */
542 VIDEO_FONT_WIDTH *
543 VIDEO_PIXEL_SIZE * begin; /* offset of col */
544 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
545 size >>= 2; /* length to end for memsetl() */
546 /* fill at col offset of i'th line using bgx as fill color */
547 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
548 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
549 }
550#endif
551}
552
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000553static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000554{
Simon Glass3c0b6682015-01-01 16:17:57 -0700555 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
556 int i;
557
wdenk4b248f32004-03-14 16:51:43 +0000558 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000559
560#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000561 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
562 0, /* source pos x */
563 video_logo_height +
Simon Glass3c0b6682015-01-01 16:17:57 -0700564 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000565 0, /* dest pos x */
566 video_logo_height, /* dest pos y */
567 VIDEO_VISIBLE_COLS, /* frame width */
568 VIDEO_VISIBLE_ROWS
569 - video_logo_height
Simon Glass3c0b6682015-01-01 16:17:57 -0700570 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000571 );
wdenkc6097192002-11-03 00:24:07 +0000572#else
Simon Glass3c0b6682015-01-01 16:17:57 -0700573 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
574 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000575#endif
wdenk4b248f32004-03-14 16:51:43 +0000576 /* clear the last one */
Simon Glass3c0b6682015-01-01 16:17:57 -0700577 for (i = 1; i <= rows; i++)
578 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
579
580 /* Decrement row number */
581 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000582}
583
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000584static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000585{
Timur Tabi65618632010-08-27 15:45:47 -0500586 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000587
wdenk4b248f32004-03-14 16:51:43 +0000588 if (console_col < 0) {
589 console_col = CONSOLE_COLS - 1;
590 console_row--;
591 if (console_row < 0)
592 console_row = 0;
593 }
wdenkc6097192002-11-03 00:24:07 +0000594}
595
Pali Rohár33a35bb2012-10-19 13:30:09 +0000596#ifdef CONFIG_CFB_CONSOLE_ANSI
597
598static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000599{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000600#ifdef VIDEO_HW_RECTFILL
601 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
602 0, /* dest pos x */
603 video_logo_height, /* dest pos y */
604 VIDEO_VISIBLE_COLS, /* frame width */
605 VIDEO_VISIBLE_ROWS, /* frame height */
606 bgx /* fill color */
607 );
608#else
609 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
610#endif
611}
612
613static void console_cursor_fix(void)
614{
615 if (console_row < 0)
616 console_row = 0;
617 if (console_row >= CONSOLE_ROWS)
618 console_row = CONSOLE_ROWS - 1;
619 if (console_col < 0)
620 console_col = 0;
621 if (console_col >= CONSOLE_COLS)
622 console_col = CONSOLE_COLS - 1;
623}
624
625static void console_cursor_up(int n)
626{
627 console_row -= n;
628 console_cursor_fix();
629}
630
631static void console_cursor_down(int n)
632{
633 console_row += n;
634 console_cursor_fix();
635}
636
637static void console_cursor_left(int n)
638{
639 console_col -= n;
640 console_cursor_fix();
641}
642
643static void console_cursor_right(int n)
644{
645 console_col += n;
646 console_cursor_fix();
647}
648
649static void console_cursor_set_position(int row, int col)
650{
651 if (console_row != -1)
652 console_row = row;
653 if (console_col != -1)
654 console_col = col;
655 console_cursor_fix();
656}
657
658static void console_previousline(int n)
659{
660 /* FIXME: also scroll terminal ? */
661 console_row -= n;
662 console_cursor_fix();
663}
664
665static void console_swap_colors(void)
666{
667 eorx = fgx;
668 fgx = bgx;
669 bgx = eorx;
670 eorx = fgx ^ bgx;
671}
672
673static inline int console_cursor_is_visible(void)
674{
675 return !ansi_cursor_hidden;
676}
677#else
678static inline int console_cursor_is_visible(void)
679{
680 return 1;
681}
682#endif
683
684static void console_newline(int n)
685{
686 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000687 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000688
wdenk4b248f32004-03-14 16:51:43 +0000689 /* Check if we need to scroll the terminal */
690 if (console_row >= CONSOLE_ROWS) {
691 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000692 console_scrollup();
wdenk4b248f32004-03-14 16:51:43 +0000693 }
wdenkc6097192002-11-03 00:24:07 +0000694}
695
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000696static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100697{
Timur Tabi65618632010-08-27 15:45:47 -0500698 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100699}
700
Pali Rohár33a35bb2012-10-19 13:30:09 +0000701static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000702{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100703 static int nl = 1;
704
Pali Rohár33a35bb2012-10-19 13:30:09 +0000705 if (console_cursor_is_visible())
706 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000707
wdenk4b248f32004-03-14 16:51:43 +0000708 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100709 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000710 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000711 break;
wdenkc6097192002-11-03 00:24:07 +0000712
wdenk4b248f32004-03-14 16:51:43 +0000713 case '\n': /* next line */
Heinrich Schuchardt41ec1272018-03-18 14:24:39 +0100714 if (console_col || nl)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000715 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100716 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000717 break;
wdenkc6097192002-11-03 00:24:07 +0000718
wdenk4b248f32004-03-14 16:51:43 +0000719 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500720 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000721 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000722
wdenk4b248f32004-03-14 16:51:43 +0000723 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000724 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000725 break;
wdenkc6097192002-11-03 00:24:07 +0000726
wdenk4b248f32004-03-14 16:51:43 +0000727 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000728 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000729 break;
wdenkc6097192002-11-03 00:24:07 +0000730
Pali Rohár24fe06c2012-04-28 07:26:47 +0000731 case 7: /* bell */
732 break; /* ignored */
733
wdenk4b248f32004-03-14 16:51:43 +0000734 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000735 video_putchar(console_col * VIDEO_FONT_WIDTH,
736 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000737 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000738
wdenk4b248f32004-03-14 16:51:43 +0000739 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100740 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000741 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100742 nl = 0;
743 }
wdenk4b248f32004-03-14 16:51:43 +0000744 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000745
746 if (console_cursor_is_visible())
747 CURSOR_SET;
748}
749
Simon Glass0a6eac82016-10-17 20:12:54 -0600750static void cfb_video_putc(struct stdio_dev *dev, const char c)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000751{
752#ifdef CONFIG_CFB_CONSOLE_ANSI
753 int i;
754
755 if (c == 27) {
756 for (i = 0; i < ansi_buf_size; ++i)
757 parse_putc(ansi_buf[i]);
758 ansi_buf[0] = 27;
759 ansi_buf_size = 1;
760 return;
761 }
762
763 if (ansi_buf_size > 0) {
764 /*
765 * 0 - ESC
766 * 1 - [
767 * 2 - num1
768 * 3 - ..
769 * 4 - ;
770 * 5 - num2
771 * 6 - ..
772 * - cchar
773 */
774 int next = 0;
775
776 int flush = 0;
777 int fail = 0;
778
779 int num1 = 0;
780 int num2 = 0;
781 int cchar = 0;
782
783 ansi_buf[ansi_buf_size++] = c;
784
785 if (ansi_buf_size >= sizeof(ansi_buf))
786 fail = 1;
787
788 for (i = 0; i < ansi_buf_size; ++i) {
789 if (fail)
790 break;
791
792 switch (next) {
793 case 0:
794 if (ansi_buf[i] == 27)
795 next = 1;
796 else
797 fail = 1;
798 break;
799
800 case 1:
801 if (ansi_buf[i] == '[')
802 next = 2;
803 else
804 fail = 1;
805 break;
806
807 case 2:
808 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
809 num1 = ansi_buf[i]-'0';
810 next = 3;
811 } else if (ansi_buf[i] != '?') {
812 --i;
813 num1 = 1;
814 next = 4;
815 }
816 break;
817
818 case 3:
819 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
820 num1 *= 10;
821 num1 += ansi_buf[i]-'0';
822 } else {
823 --i;
824 next = 4;
825 }
826 break;
827
828 case 4:
829 if (ansi_buf[i] != ';') {
830 --i;
831 next = 7;
832 } else
833 next = 5;
834 break;
835
836 case 5:
837 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
838 num2 = ansi_buf[i]-'0';
839 next = 6;
840 } else
841 fail = 1;
842 break;
843
844 case 6:
845 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
846 num2 *= 10;
847 num2 += ansi_buf[i]-'0';
848 } else {
849 --i;
850 next = 7;
851 }
852 break;
853
854 case 7:
855 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
856 || ansi_buf[i] == 'J'
857 || ansi_buf[i] == 'K'
858 || ansi_buf[i] == 'h'
859 || ansi_buf[i] == 'l'
860 || ansi_buf[i] == 'm') {
861 cchar = ansi_buf[i];
862 flush = 1;
863 } else
864 fail = 1;
865 break;
866 }
867 }
868
869 if (fail) {
870 for (i = 0; i < ansi_buf_size; ++i)
871 parse_putc(ansi_buf[i]);
872 ansi_buf_size = 0;
873 return;
874 }
875
876 if (flush) {
877 if (!ansi_cursor_hidden)
878 CURSOR_OFF;
879 ansi_buf_size = 0;
880 switch (cchar) {
881 case 'A':
882 /* move cursor num1 rows up */
883 console_cursor_up(num1);
884 break;
885 case 'B':
886 /* move cursor num1 rows down */
887 console_cursor_down(num1);
888 break;
889 case 'C':
890 /* move cursor num1 columns forward */
891 console_cursor_right(num1);
892 break;
893 case 'D':
894 /* move cursor num1 columns back */
895 console_cursor_left(num1);
896 break;
897 case 'E':
898 /* move cursor num1 rows up at begin of row */
899 console_previousline(num1);
900 break;
901 case 'F':
902 /* move cursor num1 rows down at begin of row */
903 console_newline(num1);
904 break;
905 case 'G':
906 /* move cursor to column num1 */
907 console_cursor_set_position(-1, num1-1);
908 break;
909 case 'H':
910 /* move cursor to row num1, column num2 */
911 console_cursor_set_position(num1-1, num2-1);
912 break;
913 case 'J':
914 /* clear console and move cursor to 0, 0 */
915 console_clear();
916 console_cursor_set_position(0, 0);
917 break;
918 case 'K':
919 /* clear line */
920 if (num1 == 0)
921 console_clear_line(console_row,
922 console_col,
923 CONSOLE_COLS-1);
924 else if (num1 == 1)
925 console_clear_line(console_row,
926 0, console_col);
927 else
928 console_clear_line(console_row,
929 0, CONSOLE_COLS-1);
930 break;
931 case 'h':
932 ansi_cursor_hidden = 0;
933 break;
934 case 'l':
935 ansi_cursor_hidden = 1;
936 break;
937 case 'm':
938 if (num1 == 0) { /* reset swapped colors */
939 if (ansi_colors_need_revert) {
940 console_swap_colors();
941 ansi_colors_need_revert = 0;
942 }
943 } else if (num1 == 7) { /* once swap colors */
944 if (!ansi_colors_need_revert) {
945 console_swap_colors();
946 ansi_colors_need_revert = 1;
947 }
948 }
949 break;
950 }
951 if (!ansi_cursor_hidden)
952 CURSOR_SET;
953 }
954 } else {
955 parse_putc(c);
956 }
957#else
958 parse_putc(c);
959#endif
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200960 if (cfb_do_flush_cache)
961 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabi65618632010-08-27 15:45:47 -0500962}
wdenkc6097192002-11-03 00:24:07 +0000963
Simon Glass0a6eac82016-10-17 20:12:54 -0600964static void cfb_video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +0000965{
Soeren Mochd37e96e2014-10-24 16:33:30 +0200966 int flush = cfb_do_flush_cache;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000967 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +0000968
Soeren Mochd37e96e2014-10-24 16:33:30 +0200969 /* temporarily disable cache flush */
970 cfb_do_flush_cache = 0;
971
wdenk4b248f32004-03-14 16:51:43 +0000972 while (count--)
Simon Glass0a6eac82016-10-17 20:12:54 -0600973 cfb_video_putc(dev, *s++);
Soeren Mochd37e96e2014-10-24 16:33:30 +0200974
975 if (flush) {
976 cfb_do_flush_cache = flush;
977 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
978 }
wdenkc6097192002-11-03 00:24:07 +0000979}
980
Anatolij Gustschin10543822010-05-01 22:21:09 +0200981/*
982 * Do not enforce drivers (or board code) to provide empty
983 * video_set_lut() if they do not support 8 bpp format.
984 * Implement weak default function instead.
985 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +0200986__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000987 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +0200988{
989}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000990
Jon Loeliger07d38a12007-07-09 17:30:01 -0500991#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000992
993#define FILL_8BIT_332RGB(r,g,b) { \
994 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
995 fb ++; \
996}
997
998#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000999 *(unsigned short *)fb = \
1000 SWAP16((unsigned short)(((r>>3)<<10) | \
1001 ((g>>3)<<5) | \
1002 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001003 fb += 2; \
1004}
1005
1006#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001007 *(unsigned short *)fb = \
1008 SWAP16((unsigned short)((((r)>>3)<<11)| \
1009 (((g)>>2)<<5) | \
1010 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001011 fb += 2; \
1012}
1013
1014#define FILL_32BIT_X888RGB(r,g,b) { \
Andre Przywara1d4ed262017-03-06 01:13:38 +00001015 *(u32 *)fb = \
1016 SWAP32((unsigned int)(((r<<16) | \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001017 (g<<8) | \
1018 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001019 fb += 4; \
1020}
1021
1022#ifdef VIDEO_FB_LITTLE_ENDIAN
1023#define FILL_24BIT_888RGB(r,g,b) { \
1024 fb[0] = b; \
1025 fb[1] = g; \
1026 fb[2] = r; \
1027 fb += 3; \
1028}
1029#else
1030#define FILL_24BIT_888RGB(r,g,b) { \
1031 fb[0] = r; \
1032 fb[1] = g; \
1033 fb[2] = b; \
1034 fb += 3; \
1035}
1036#endif
1037
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001038#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001039static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001040{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001041 ushort *dst = (ushort *) fb;
1042 ushort color = (ushort) (((r >> 3) << 10) |
1043 ((g >> 3) << 5) |
1044 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001045 if (x & 1)
1046 *(--dst) = color;
1047 else
1048 *(++dst) = color;
1049}
1050#endif
wdenk4b248f32004-03-14 16:51:43 +00001051
1052/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001053 * RLE8 bitmap support
1054 */
1055
1056#ifdef CONFIG_VIDEO_BMP_RLE8
1057/* Pre-calculated color table entry */
1058struct palette {
1059 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001060 unsigned short w; /* word */
1061 unsigned int dw; /* double word */
1062 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001063};
1064
1065/*
1066 * Helper to draw encoded/unencoded run.
1067 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001068static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1069 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001070{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001071 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001072 int *off;
1073 int enc_off = 1;
1074 int i;
1075
1076 /*
1077 * Setup offset of the color index in the bitmap.
1078 * Color index of encoded run is at offset 1.
1079 */
1080 off = enc ? &enc_off : &i;
1081
1082 switch (VIDEO_DATA_FORMAT) {
1083 case GDF__8BIT_INDEX:
1084 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001085 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001086 break;
1087 case GDF_15BIT_555RGB:
1088 case GDF_16BIT_565RGB:
1089 /* differences handled while pre-calculating palette */
1090 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001091 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001092 addr += 2;
1093 }
1094 break;
1095 case GDF_32BIT_X888RGB:
1096 for (i = 0; i < cnt; i++) {
Andre Przywara1d4ed262017-03-06 01:13:38 +00001097 *(u32 *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001098 addr += 4;
1099 }
1100 break;
1101 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001102 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001103}
1104
Simon Glass1c3dbe52015-05-13 07:02:27 -06001105static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001106 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001107{
1108 unsigned char *bm;
1109 unsigned char *fbp;
1110 unsigned int cnt, runlen;
1111 int decode = 1;
1112 int x, y, bpp, i, ncolors;
1113 struct palette p[256];
Simon Glass1c3dbe52015-05-13 07:02:27 -06001114 struct bmp_color_table_entry cte;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001115 int green_shift, red_off;
Hans de Goedec67a8762015-08-04 12:15:39 +02001116 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001117 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001118
1119 x = 0;
1120 y = __le32_to_cpu(img->header.height) - 1;
1121 ncolors = __le32_to_cpu(img->header.colors_used);
1122 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001123 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001124 (y + yoff) * VIDEO_LINE_LEN +
1125 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001126
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001127 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001128
1129 /* pre-calculate and setup palette */
1130 switch (VIDEO_DATA_FORMAT) {
1131 case GDF__8BIT_INDEX:
1132 for (i = 0; i < ncolors; i++) {
1133 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001134 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001135 }
1136 break;
1137 case GDF_15BIT_555RGB:
1138 case GDF_16BIT_565RGB:
1139 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1140 green_shift = 3;
1141 red_off = 10;
1142 } else {
1143 green_shift = 2;
1144 red_off = 11;
1145 }
1146 for (i = 0; i < ncolors; i++) {
1147 cte = img->color_table[i];
1148 p[i].ce.w = SWAP16((unsigned short)
1149 (((cte.red >> 3) << red_off) |
1150 ((cte.green >> green_shift) << 5) |
1151 cte.blue >> 3));
1152 }
1153 break;
1154 case GDF_32BIT_X888RGB:
1155 for (i = 0; i < ncolors; i++) {
1156 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001157 p[i].ce.dw = SWAP32((cte.red << 16) |
1158 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001159 cte.blue);
1160 }
1161 break;
1162 default:
1163 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001164 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001165 return -1;
1166 }
1167
1168 while (decode) {
1169 switch (bm[0]) {
1170 case 0:
1171 switch (bm[1]) {
1172 case 0:
1173 /* scan line end marker */
1174 bm += 2;
1175 x = 0;
1176 y--;
1177 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001178 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001179 (y + yoff) * VIDEO_LINE_LEN +
1180 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001181 continue;
1182 case 1:
1183 /* end of bitmap data marker */
1184 decode = 0;
1185 break;
1186 case 2:
1187 /* run offset marker */
1188 x += bm[2];
1189 y -= bm[3];
1190 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001191 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001192 (y + yoff) * VIDEO_LINE_LEN +
1193 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001194 bm += 4;
1195 break;
1196 default:
1197 /* unencoded run */
1198 cnt = bm[1];
1199 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001200 pixels += cnt;
1201 if (pixels > limit)
1202 goto error;
1203
Anatolij Gustschind5011762010-03-15 14:50:25 +01001204 bm += 2;
1205 if (y < height) {
1206 if (x >= width) {
1207 x += runlen;
1208 goto next_run;
1209 }
1210 if (x + runlen > width)
1211 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001212 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001213 x += runlen;
1214 }
1215next_run:
1216 bm += runlen;
1217 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001218 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001219 }
1220 break;
1221 default:
1222 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001223 cnt = bm[0];
1224 runlen = cnt;
1225 pixels += cnt;
1226 if (pixels > limit)
1227 goto error;
1228
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001229 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001230 if (x >= width) {
1231 x += runlen;
1232 bm += 2;
1233 continue;
1234 }
1235 if (x + runlen > width)
1236 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001237 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001238 x += runlen;
1239 }
1240 bm += 2;
1241 break;
1242 }
1243 }
Sébastien Szymanski47b11c82018-09-10 09:58:58 +02001244
1245 if (cfb_do_flush_cache)
1246 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1247
Anatolij Gustschind5011762010-03-15 14:50:25 +01001248 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001249error:
1250 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1251 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001252}
1253#endif
1254
1255/*
wdenk4b248f32004-03-14 16:51:43 +00001256 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001257 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001258int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001259{
1260 ushort xcount, ycount;
1261 uchar *fb;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001262 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenk4b248f32004-03-14 16:51:43 +00001263 uchar *bmap;
1264 ushort padded_line;
1265 unsigned long width, height, bpp;
1266 unsigned colors;
1267 unsigned long compression;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001268 struct bmp_color_table_entry cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001269
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001270#ifdef CONFIG_VIDEO_BMP_GZIP
1271 unsigned char *dst = NULL;
1272 ulong len;
1273#endif
wdenk4b248f32004-03-14 16:51:43 +00001274
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001275 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001276
1277 if (!((bmp->header.signature[0] == 'B') &&
1278 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001279
1280#ifdef CONFIG_VIDEO_BMP_GZIP
1281 /*
1282 * Could be a gzipped bmp image, try to decrompress...
1283 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001284 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1285 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001286 if (dst == NULL) {
1287 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001288 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001289 }
Eric Nelson5ca05c82014-03-08 07:55:52 -07001290 /*
1291 * NB: we need to force offset of +2
1292 * See doc/README.displaying-bmps
1293 */
1294 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001295 (uchar *) bmp_image,
1296 &len) != 0) {
1297 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1298 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001299 free(dst);
1300 return 1;
1301 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001302 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001303 printf("Image could be truncated "
1304 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001305 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001306
1307 /*
1308 * Set addr to decompressed image
1309 */
Simon Glass1c3dbe52015-05-13 07:02:27 -06001310 bmp = (struct bmp_image *)(dst+2);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001311
1312 if (!((bmp->header.signature[0] == 'B') &&
1313 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001314 printf("Error: no valid bmp.gz image at %lx\n",
1315 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001316 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001317 return 1;
1318 }
1319#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001320 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001321 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001322#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001323 }
1324
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001325 width = le32_to_cpu(bmp->header.width);
1326 height = le32_to_cpu(bmp->header.height);
1327 bpp = le16_to_cpu(bmp->header.bit_count);
1328 colors = le32_to_cpu(bmp->header.colors_used);
1329 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001330
Marek Vasut68da5b12011-10-21 14:17:04 +00001331 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001332 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001333
Anatolij Gustschind5011762010-03-15 14:50:25 +01001334 if (compression != BMP_BI_RGB
1335#ifdef CONFIG_VIDEO_BMP_RLE8
1336 && compression != BMP_BI_RLE8
1337#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001338 ) {
1339 printf("Error: compression type %ld not supported\n",
1340 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001341#ifdef CONFIG_VIDEO_BMP_GZIP
1342 if (dst)
1343 free(dst);
1344#endif
wdenk4b248f32004-03-14 16:51:43 +00001345 return 1;
1346 }
1347
1348 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1349
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001350#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1351 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001352 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001353 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001354 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001355
1356 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001357 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001358 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001359 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001360#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1361
Matthias Weisseracf3baa2013-02-15 03:35:12 +00001362 /*
1363 * Just ignore elements which are completely beyond screen
1364 * dimensions.
1365 */
1366 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1367 return 0;
1368
wdenk4b248f32004-03-14 16:51:43 +00001369 if ((x + width) > VIDEO_VISIBLE_COLS)
1370 width = VIDEO_VISIBLE_COLS - x;
1371 if ((y + height) > VIDEO_VISIBLE_ROWS)
1372 height = VIDEO_VISIBLE_ROWS - y;
1373
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001374 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001375 fb = (uchar *) (video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001376 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenk4b248f32004-03-14 16:51:43 +00001377 x * VIDEO_PIXEL_SIZE);
1378
Anatolij Gustschind5011762010-03-15 14:50:25 +01001379#ifdef CONFIG_VIDEO_BMP_RLE8
1380 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001381 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001382 }
1383#endif
1384
Timur Tabi68f66182010-08-23 16:58:00 -05001385 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001386 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001387 case 4:
1388 padded_line -= width / 2;
1389 ycount = height;
1390
1391 switch (VIDEO_DATA_FORMAT) {
1392 case GDF_32BIT_X888RGB:
1393 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001394 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001395 /*
1396 * Don't assume that 'width' is an
1397 * even number
1398 */
1399 for (xcount = 0; xcount < width; xcount++) {
1400 uchar idx;
1401
1402 if (xcount & 1) {
1403 idx = *bmap & 0xF;
1404 bmap++;
1405 } else
1406 idx = *bmap >> 4;
1407 cte = bmp->color_table[idx];
1408 FILL_32BIT_X888RGB(cte.red, cte.green,
1409 cte.blue);
1410 }
1411 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001412 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001413 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001414 }
1415 break;
1416 default:
1417 puts("4bpp bitmap unsupported with current "
1418 "video mode\n");
1419 break;
1420 }
1421 break;
1422
wdenk4b248f32004-03-14 16:51:43 +00001423 case 8:
1424 padded_line -= width;
1425 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001426 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001427 for (xcount = 0; xcount < colors; ++xcount) {
1428 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001429 video_set_lut(xcount, cte.red, cte.green,
1430 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001431 }
1432 }
1433 ycount = height;
1434 switch (VIDEO_DATA_FORMAT) {
1435 case GDF__8BIT_INDEX:
1436 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001437 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001438 xcount = width;
1439 while (xcount--) {
1440 *fb++ = *bmap++;
1441 }
1442 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001443 fb -= VIDEO_LINE_LEN + width *
1444 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001445 }
1446 break;
1447 case GDF__8BIT_332RGB:
1448 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001449 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001450 xcount = width;
1451 while (xcount--) {
1452 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001453 FILL_8BIT_332RGB(cte.red, cte.green,
1454 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001455 }
1456 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001457 fb -= VIDEO_LINE_LEN + width *
1458 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001459 }
1460 break;
1461 case GDF_15BIT_555RGB:
1462 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001463#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1464 int xpos = x;
1465#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001466 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001467 xcount = width;
1468 while (xcount--) {
1469 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001470#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001471 fill_555rgb_pswap(fb, xpos++, cte.red,
1472 cte.green,
1473 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001474 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001475#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001476 FILL_15BIT_555RGB(cte.red, cte.green,
1477 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001478#endif
wdenk4b248f32004-03-14 16:51:43 +00001479 }
1480 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001481 fb -= VIDEO_LINE_LEN + width *
1482 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001483 }
1484 break;
1485 case GDF_16BIT_565RGB:
1486 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001487 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001488 xcount = width;
1489 while (xcount--) {
1490 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001491 FILL_16BIT_565RGB(cte.red, cte.green,
1492 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001493 }
1494 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001495 fb -= VIDEO_LINE_LEN + width *
1496 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001497 }
1498 break;
1499 case GDF_32BIT_X888RGB:
1500 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001501 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001502 xcount = width;
1503 while (xcount--) {
1504 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001505 FILL_32BIT_X888RGB(cte.red, cte.green,
1506 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001507 }
1508 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001509 fb -= VIDEO_LINE_LEN + width *
1510 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001511 }
1512 break;
1513 case GDF_24BIT_888RGB:
1514 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001515 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001516 xcount = width;
1517 while (xcount--) {
1518 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001519 FILL_24BIT_888RGB(cte.red, cte.green,
1520 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001521 }
1522 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001523 fb -= VIDEO_LINE_LEN + width *
1524 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001525 }
1526 break;
1527 }
1528 break;
1529 case 24:
1530 padded_line -= 3 * width;
1531 ycount = height;
1532 switch (VIDEO_DATA_FORMAT) {
1533 case GDF__8BIT_332RGB:
1534 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001535 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001536 xcount = width;
1537 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001538 FILL_8BIT_332RGB(bmap[2], bmap[1],
1539 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001540 bmap += 3;
1541 }
1542 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001543 fb -= VIDEO_LINE_LEN + width *
1544 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001545 }
1546 break;
1547 case GDF_15BIT_555RGB:
1548 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001549#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1550 int xpos = x;
1551#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001552 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001553 xcount = width;
1554 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001555#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001556 fill_555rgb_pswap(fb, xpos++, bmap[2],
1557 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001558 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001559#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001560 FILL_15BIT_555RGB(bmap[2], bmap[1],
1561 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001562#endif
wdenk4b248f32004-03-14 16:51:43 +00001563 bmap += 3;
1564 }
1565 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001566 fb -= VIDEO_LINE_LEN + width *
1567 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001568 }
1569 break;
1570 case GDF_16BIT_565RGB:
1571 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001572 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001573 xcount = width;
1574 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001575 FILL_16BIT_565RGB(bmap[2], bmap[1],
1576 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001577 bmap += 3;
1578 }
1579 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001580 fb -= VIDEO_LINE_LEN + width *
1581 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001582 }
1583 break;
1584 case GDF_32BIT_X888RGB:
1585 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001586 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001587 xcount = width;
1588 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001589 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1590 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001591 bmap += 3;
1592 }
1593 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001594 fb -= VIDEO_LINE_LEN + width *
1595 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001596 }
1597 break;
1598 case GDF_24BIT_888RGB:
1599 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001600 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001601 xcount = width;
1602 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001603 FILL_24BIT_888RGB(bmap[2], bmap[1],
1604 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001605 bmap += 3;
1606 }
1607 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001608 fb -= VIDEO_LINE_LEN + width *
1609 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001610 }
1611 break;
1612 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001613 printf("Error: 24 bits/pixel bitmap incompatible "
1614 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001615 break;
1616 }
1617 break;
1618 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001619 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1620 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001621 break;
1622 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001623
1624#ifdef CONFIG_VIDEO_BMP_GZIP
1625 if (dst) {
1626 free(dst);
1627 }
1628#endif
1629
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001630 if (cfb_do_flush_cache)
1631 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk4b248f32004-03-14 16:51:43 +00001632 return (0);
1633}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001634#endif
wdenk4b248f32004-03-14 16:51:43 +00001635
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001636static int cfb_fb_is_in_dram(void)
1637{
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +09001638 struct bd_info *bd = gd->bd;
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001639 ulong start, end;
1640 int i;
1641
1642 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1643 start = bd->bi_dram[i].start;
1644 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1645 if ((ulong)video_fb_address >= start &&
1646 (ulong)video_fb_address < end)
1647 return 1;
1648 }
Stefan Roese063d5472020-08-12 13:32:41 +02001649
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001650 return 0;
1651}
1652
Heiko Schocher45ae2542013-10-22 11:06:06 +02001653void video_clear(void)
1654{
1655 if (!video_fb_address)
1656 return;
1657#ifdef VIDEO_HW_RECTFILL
1658 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
1659 0, /* dest pos x */
1660 0, /* dest pos y */
1661 VIDEO_VISIBLE_COLS, /* frame width */
1662 VIDEO_VISIBLE_ROWS, /* frame height */
1663 bgx /* fill color */
1664 );
1665#else
1666 memsetl(video_fb_address,
1667 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
1668#endif
1669}
1670
Simon Glass0a6eac82016-10-17 20:12:54 -06001671static int cfg_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001672{
wdenk4b248f32004-03-14 16:51:43 +00001673 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001674
Wolfgang Denk57912932011-07-30 12:48:09 +00001675 pGD = video_hw_init();
1676 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00001677 return -1;
wdenkc6097192002-11-03 00:24:07 +00001678
wdenk4b248f32004-03-14 16:51:43 +00001679 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001680
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02001681 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
1682
wdenk4b248f32004-03-14 16:51:43 +00001683 /* Init drawing pats */
1684 switch (VIDEO_DATA_FORMAT) {
1685 case GDF__8BIT_INDEX:
Simon Glass002f9672016-10-17 20:12:44 -06001686 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
1687 CONFIG_SYS_CONSOLE_FG_COL,
1688 CONFIG_SYS_CONSOLE_FG_COL);
1689 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
1690 CONFIG_SYS_CONSOLE_BG_COL,
1691 CONFIG_SYS_CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00001692 fgx = 0x01010101;
1693 bgx = 0x00000000;
1694 break;
1695 case GDF__8BIT_332RGB:
Simon Glass002f9672016-10-17 20:12:44 -06001696 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
1697 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
1698 CONFIG_SYS_CONSOLE_FG_COL >> 6);
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001699 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1700 color8;
Simon Glass002f9672016-10-17 20:12:44 -06001701 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
1702 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
1703 CONFIG_SYS_CONSOLE_BG_COL >> 6);
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001704 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
1705 color8;
wdenk4b248f32004-03-14 16:51:43 +00001706 break;
1707 case GDF_15BIT_555RGB:
Simon Glass002f9672016-10-17 20:12:44 -06001708 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
1709 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
1710 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
1711 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
1712 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
1713 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
1714 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
1715 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
1716 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
1717 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
1718 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
1719 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001720 break;
1721 case GDF_16BIT_565RGB:
Simon Glass002f9672016-10-17 20:12:44 -06001722 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
1723 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
1724 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
1725 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
1726 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
1727 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
1728 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
1729 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
1730 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
1731 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
1732 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
1733 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00001734 break;
1735 case GDF_32BIT_X888RGB:
Simon Glass002f9672016-10-17 20:12:44 -06001736 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
1737 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
1738 CONFIG_SYS_CONSOLE_FG_COL;
1739 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
1740 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
1741 CONFIG_SYS_CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001742 break;
1743 case GDF_24BIT_888RGB:
Simon Glass002f9672016-10-17 20:12:44 -06001744 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
1745 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
1746 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
1747 CONFIG_SYS_CONSOLE_FG_COL;
1748 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
1749 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
1750 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
1751 CONFIG_SYS_CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00001752 break;
1753 }
1754 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001755
Rob Clark8ef05352017-08-03 12:47:01 -04001756 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
1757 video_clear();
Heiko Schocher45ae2542013-10-22 11:06:06 +02001758
wdenkc6097192002-11-03 00:24:07 +00001759#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001760 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00001761 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001762 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00001763#else
wdenk4b248f32004-03-14 16:51:43 +00001764 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001765#endif
1766
wdenk4b248f32004-03-14 16:51:43 +00001767 /* Initialize the console */
1768 console_col = 0;
1769 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001770
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001771 if (cfb_do_flush_cache)
1772 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1773
wdenk4b248f32004-03-14 16:51:43 +00001774 return 0;
wdenkc6097192002-11-03 00:24:07 +00001775}
1776
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001777/*
1778 * Implement a weak default function for boards that optionally
1779 * need to skip the video initialization.
1780 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02001781__weak int board_video_skip(void)
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001782{
1783 /* As default, don't skip test */
1784 return 0;
1785}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001786
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001787int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00001788{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02001789 struct stdio_dev console_dev;
Simon Glass5692ccf2015-03-02 12:40:50 -07001790 bool have_keyboard;
Bin Meng8ceb2422015-08-24 01:00:07 -07001791 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00001792
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02001793 /* Check if video initialization should be skipped */
1794 if (board_video_skip())
1795 return 0;
1796
wdenk81050922004-07-11 20:04:51 +00001797 /* Init video chip - returns with framebuffer cleared */
Simon Glass0a6eac82016-10-17 20:12:54 -06001798 if (cfg_video_init() == -1)
Bin Meng8ceb2422015-08-24 01:00:07 -07001799 return 0;
wdenk81050922004-07-11 20:04:51 +00001800
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02001801 if (board_cfb_skip())
1802 return 0;
1803
Simon Glass5692ccf2015-03-02 12:40:50 -07001804#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1805 have_keyboard = false;
1806#elif defined(CONFIG_OF_CONTROL)
Simon Glass7de8bd02021-08-07 07:24:01 -06001807 have_keyboard = !ofnode_conf_read_bool("u-boot,no-keyboard");
Simon Glass5692ccf2015-03-02 12:40:50 -07001808#else
1809 have_keyboard = true;
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001810#endif
Simon Glass5692ccf2015-03-02 12:40:50 -07001811 if (have_keyboard) {
1812 debug("KBD: Keyboard init ...\n");
1813#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07001814 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Simon Glass5692ccf2015-03-02 12:40:50 -07001815#endif
1816 }
wdenkc6097192002-11-03 00:24:07 +00001817
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001818 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001819 memset(&console_dev, 0, sizeof(console_dev));
1820 strcpy(console_dev.name, "vga");
Bin Meng1caf9342015-11-03 23:23:37 -08001821 console_dev.flags = DEV_FLAGS_OUTPUT;
Simon Glass0a6eac82016-10-17 20:12:54 -06001822 console_dev.putc = cfb_video_putc; /* 'putc' function */
1823 console_dev.puts = cfb_video_puts; /* 'puts' function */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001824
1825#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07001826 if (have_keyboard && keyboard_ok) {
Simon Glass5692ccf2015-03-02 12:40:50 -07001827 /* Also init console device */
1828 console_dev.flags |= DEV_FLAGS_INPUT;
1829 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1830 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
1831 }
1832#endif
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001833
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001834 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02001835 return 0;
1836
1837 /* Return success */
1838 return 1;
wdenkc6097192002-11-03 00:24:07 +00001839}
Stefan Reinauerc20ee072012-09-28 15:11:12 +00001840
1841void video_position_cursor(unsigned col, unsigned row)
1842{
1843 console_col = min(col, CONSOLE_COLS - 1);
1844 console_row = min(row, CONSOLE_ROWS - 1);
1845}
1846
1847int video_get_pixel_width(void)
1848{
1849 return VIDEO_VISIBLE_COLS;
1850}
1851
1852int video_get_pixel_height(void)
1853{
1854 return VIDEO_VISIBLE_ROWS;
1855}
1856
1857int video_get_screen_rows(void)
1858{
1859 return CONSOLE_ROWS;
1860}
1861
1862int video_get_screen_columns(void)
1863{
1864 return CONSOLE_COLS;
1865}