blob: a99fc00c4a28fc0e52656a788b4de39f43e8aaf6 [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 Denkbd8ec7e2013-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 Denk0b4b56e2011-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 Glasseaba37e2015-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 Denk0b4b56e2011-07-29 09:55:27 +000025 *
26 * The driver uses graphic specific defines/parameters/functions:
27 *
28 * (for SMI LynxE graphic chip)
29 *
Wolfgang Denk0b4b56e2011-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 Denk0b4b56e2011-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 Rupperta13e81f2012-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 Denk0b4b56e2011-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 Denk0b4b56e2011-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 Denk0b4b56e2011-07-29 09:55:27 +000066 */
wdenkc6097192002-11-03 00:24:07 +000067
68#include <common.h>
Simon Glasse9fa1f02015-03-02 12:40:50 -070069#include <fdtdec.h>
Andreas Bießmann61d01952011-07-18 20:24:04 +020070#include <version.h>
wdenk9dd2b882002-12-03 21:28:10 +000071#include <malloc.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +000072#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +000073
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000074/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000075 * Defines for the CT69000 driver
76 */
wdenke55402c2004-03-14 16:51:43 +000077#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +000078
79#define VIDEO_FB_LITTLE_ENDIAN
80#define VIDEO_HW_RECTFILL
81#define VIDEO_HW_BITBLT
82#endif
83
Simon Glass9d057042016-10-17 20:12:47 -060084#if defined(CONFIG_VIDEO_MXS)
Marek Vasutffdd4662013-04-28 09:20:03 +000085#define VIDEO_FB_16BPP_WORD_SWAP
86#endif
87
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000088/*
89 * Defines for the MB862xx driver
90 */
Anatolij Gustschin3545f592008-01-11 14:30:01 +010091#ifdef CONFIG_VIDEO_MB862xx
92
93#ifdef CONFIG_VIDEO_CORALP
94#define VIDEO_FB_LITTLE_ENDIAN
95#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +020096#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +010097#define VIDEO_HW_RECTFILL
98#define VIDEO_HW_BITBLT
99#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200100#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100101
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000102/*
Helmut Raiger0385c132011-10-12 23:16:29 +0000103 * Defines for the i.MX31 driver (mx3fb.c)
104 */
Fabio Estevamc6dd2e02012-05-31 07:23:56 +0000105#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger0385c132011-10-12 23:16:29 +0000106#define VIDEO_FB_16BPP_WORD_SWAP
107#endif
108
109/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000110 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
111 */
wdenkc6097192002-11-03 00:24:07 +0000112#include <video_fb.h>
113
Robert Winkler2a90ed02013-06-17 11:31:29 -0700114#include <splash.h>
115
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000116/*
117 * some Macros
118 */
wdenke55402c2004-03-14 16:51:43 +0000119#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
120#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
121#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
122#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
123#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000124
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000125/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000126 * Console device
127 */
wdenkc6097192002-11-03 00:24:07 +0000128
129#include <version.h>
130#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200131#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000132#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000133
Jon Loeliger30c2f242007-07-10 11:13:21 -0500134#if defined(CONFIG_CMD_DATE)
135#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000136#endif
137
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500138#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000139#include <watchdog.h>
140#include <bmp_layout.h>
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +0200141#include <splash.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200142#endif
143
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000144/*
145 * Cursor definition:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000146 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
147 * blinking is provided. Uses the macros CURSOR_SET
148 * and CURSOR_OFF.
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000149 */
Simon Glassd615c892016-10-17 20:12:50 -0600150#if !defined(CONFIG_VIDEO_SW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000151/* no Cursor defined */
152#define CURSOR_ON
153#define CURSOR_OFF
154#define CURSOR_SET
155#endif
156
Simon Glassf406a1b2015-10-18 21:17:18 -0600157#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000158void console_cursor(int state);
159
Timur Tabibe0c74e2010-08-27 15:45:47 -0500160#define CURSOR_ON console_cursor(1)
161#define CURSOR_OFF console_cursor(0)
Gabe Black12874de2011-11-30 13:50:50 +0000162#define CURSOR_SET video_set_cursor()
Simon Glassf406a1b2015-10-18 21:17:18 -0600163#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000164
wdenke55402c2004-03-14 16:51:43 +0000165#ifdef CONFIG_VIDEO_LOGO
166#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000167#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000168#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000169#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
170#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
171#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
172#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000173
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000174#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000175#define LINUX_LOGO_WIDTH 80
176#define LINUX_LOGO_HEIGHT 80
177#define LINUX_LOGO_COLORS 214
178#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000179#define __initdata
180#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000181#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
182#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
183#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
184#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000185#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000186#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
187#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000188#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000189#define VIDEO_LOGO_WIDTH 0
190#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000191#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000192
wdenke55402c2004-03-14 16:51:43 +0000193#define VIDEO_COLS VIDEO_VISIBLE_COLS
194#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedea8287e72015-08-04 12:15:39 +0200195#ifndef VIDEO_LINE_LEN
196#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
197#endif
198#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenke55402c2004-03-14 16:51:43 +0000199#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000200
wdenke55402c2004-03-14 16:51:43 +0000201#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100202#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000203#else
wdenke55402c2004-03-14 16:51:43 +0000204#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000205#endif
206
wdenke55402c2004-03-14 16:51:43 +0000207#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
208#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
209#define CONSOLE_ROW_FIRST (video_console_address)
210#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
211#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
212#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass6ceb7f02015-01-01 16:17:57 -0700213
214/* By default we scroll by a single line */
215#ifndef CONFIG_CONSOLE_SCROLL_LINES
216#define CONFIG_CONSOLE_SCROLL_LINES 1
217#endif
wdenkc6097192002-11-03 00:24:07 +0000218
219/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000220#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000221#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
222 ((x) >> 8) \
223 )
224#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
225 (((x) & 0x0000ff00) << 8) | \
226 (((x) & 0x00ff0000) >> 8) | \
227 (((x) & 0xff000000) >> 24) \
228 )
229#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
230 (((x) & 0x0000ff00) >> 8) | \
231 (((x) & 0x00ff0000) << 8) | \
232 (((x) & 0xff000000) >> 8) \
233 )
wdenkc6097192002-11-03 00:24:07 +0000234#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000235#define SWAP16(x) (x)
236#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200237#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000238#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500239#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000240#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100241#endif
wdenkc6097192002-11-03 00:24:07 +0000242#endif
243
wdenkc6097192002-11-03 00:24:07 +0000244#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000245/*
246 * setup a board string: type, speed, etc.
247 *
248 * line_number: location to place info string beside logo
249 * info: buffer for info string
250 */
251extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000252#endif
253
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200254DECLARE_GLOBAL_DATA_PTR;
255
wdenkc6097192002-11-03 00:24:07 +0000256/* Locals */
257static GraphicDevice *pGD; /* Pointer to Graphic array */
258
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000259static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000260static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000261
Matthias Weisser76d70862010-01-12 12:06:31 +0100262static int video_logo_height = VIDEO_LOGO_HEIGHT;
263
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000264static int __maybe_unused cursor_state;
265static int __maybe_unused old_col;
266static int __maybe_unused old_row;
Gabe Black12874de2011-11-30 13:50:50 +0000267
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000268static int console_col; /* cursor col */
269static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000270
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000271static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000272
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200273static int cfb_do_flush_cache;
274
Pali Rohár4a57da32012-10-19 13:30:09 +0000275#ifdef CONFIG_CFB_CONSOLE_ANSI
276static char ansi_buf[10];
277static int ansi_buf_size;
278static int ansi_colors_need_revert;
279static int ansi_cursor_hidden;
280#endif
281
wdenkc6097192002-11-03 00:24:07 +0000282static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000283 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
284 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
285 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
286 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
287};
wdenkc6097192002-11-03 00:24:07 +0000288
289static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000290 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
291};
wdenkc6097192002-11-03 00:24:07 +0000292
293static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000294 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
295};
wdenkc6097192002-11-03 00:24:07 +0000296
297static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000298 {0x00000000, 0x00000000, 0x00000000},
299 {0x00000000, 0x00000000, 0x00ffffff},
300 {0x00000000, 0x0000ffff, 0xff000000},
301 {0x00000000, 0x0000ffff, 0xffffffff},
302 {0x000000ff, 0xffff0000, 0x00000000},
303 {0x000000ff, 0xffff0000, 0x00ffffff},
304 {0x000000ff, 0xffffffff, 0xff000000},
305 {0x000000ff, 0xffffffff, 0xffffffff},
306 {0xffffff00, 0x00000000, 0x00000000},
307 {0xffffff00, 0x00000000, 0x00ffffff},
308 {0xffffff00, 0x0000ffff, 0xff000000},
309 {0xffffff00, 0x0000ffff, 0xffffffff},
310 {0xffffffff, 0xffff0000, 0x00000000},
311 {0xffffffff, 0xffff0000, 0x00ffffff},
312 {0xffffffff, 0xffffffff, 0xff000000},
313 {0xffffffff, 0xffffffff, 0xffffffff}
314};
wdenkc6097192002-11-03 00:24:07 +0000315
316static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000317 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
318 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
319 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
320 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
321 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
322 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
323 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
324 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
325 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
326 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
327 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
328 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
329 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
330 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
331 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
332 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
333};
wdenkc6097192002-11-03 00:24:07 +0000334
Heiko Schocher9cff8ad2013-08-03 07:22:53 +0200335/*
336 * Implement a weak default function for boards that optionally
337 * need to skip the cfb initialization.
338 */
339__weak int board_cfb_skip(void)
340{
341 /* As default, don't skip cfb init */
342 return 0;
343}
344
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000345static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000346{
wdenke55402c2004-03-14 16:51:43 +0000347 u8 *cdat, *dest, *dest0;
348 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000349
wdenke55402c2004-03-14 16:51:43 +0000350 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
351 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000352
wdenke55402c2004-03-14 16:51:43 +0000353 switch (VIDEO_DATA_FORMAT) {
354 case GDF__8BIT_INDEX:
355 case GDF__8BIT_332RGB:
356 while (count--) {
357 c = *s;
358 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
359 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000360 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000361 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000362
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000363 ((u32 *) dest)[0] =
364 (video_font_draw_table8[bits >> 4] &
365 eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200366
367 if (VIDEO_FONT_WIDTH == 4)
368 continue;
369
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000370 ((u32 *) dest)[1] =
371 (video_font_draw_table8[bits & 15] &
372 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000373 }
374 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
375 s++;
376 }
377 break;
wdenkc6097192002-11-03 00:24:07 +0000378
wdenke55402c2004-03-14 16:51:43 +0000379 case GDF_15BIT_555RGB:
380 while (count--) {
381 c = *s;
382 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
383 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000384 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000385 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000386
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000387 ((u32 *) dest)[0] =
388 SHORTSWAP32((video_font_draw_table15
389 [bits >> 6] & eorx) ^
390 bgx);
391 ((u32 *) dest)[1] =
392 SHORTSWAP32((video_font_draw_table15
393 [bits >> 4 & 3] & eorx) ^
394 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200395
396 if (VIDEO_FONT_WIDTH == 4)
397 continue;
398
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000399 ((u32 *) dest)[2] =
400 SHORTSWAP32((video_font_draw_table15
401 [bits >> 2 & 3] & eorx) ^
402 bgx);
403 ((u32 *) dest)[3] =
404 SHORTSWAP32((video_font_draw_table15
405 [bits & 3] & eorx) ^
406 bgx);
wdenke55402c2004-03-14 16:51:43 +0000407 }
408 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
409 s++;
410 }
411 break;
wdenkc6097192002-11-03 00:24:07 +0000412
wdenke55402c2004-03-14 16:51:43 +0000413 case GDF_16BIT_565RGB:
414 while (count--) {
415 c = *s;
416 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
417 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000418 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000419 u8 bits = *cdat++;
420
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000421 ((u32 *) dest)[0] =
422 SHORTSWAP32((video_font_draw_table16
423 [bits >> 6] & eorx) ^
424 bgx);
425 ((u32 *) dest)[1] =
426 SHORTSWAP32((video_font_draw_table16
427 [bits >> 4 & 3] & eorx) ^
428 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200429
430 if (VIDEO_FONT_WIDTH == 4)
431 continue;
432
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000433 ((u32 *) dest)[2] =
434 SHORTSWAP32((video_font_draw_table16
435 [bits >> 2 & 3] & eorx) ^
436 bgx);
437 ((u32 *) dest)[3] =
438 SHORTSWAP32((video_font_draw_table16
439 [bits & 3] & eorx) ^
440 bgx);
wdenke55402c2004-03-14 16:51:43 +0000441 }
442 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
443 s++;
444 }
445 break;
446
447 case GDF_32BIT_X888RGB:
448 while (count--) {
449 c = *s;
450 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
451 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000452 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000453 u8 bits = *cdat++;
454
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000455 ((u32 *) dest)[0] =
456 SWAP32((video_font_draw_table32
457 [bits >> 4][0] & eorx) ^ bgx);
458 ((u32 *) dest)[1] =
459 SWAP32((video_font_draw_table32
460 [bits >> 4][1] & eorx) ^ bgx);
461 ((u32 *) dest)[2] =
462 SWAP32((video_font_draw_table32
463 [bits >> 4][2] & eorx) ^ bgx);
464 ((u32 *) dest)[3] =
465 SWAP32((video_font_draw_table32
466 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200467
468
469 if (VIDEO_FONT_WIDTH == 4)
470 continue;
471
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000472 ((u32 *) dest)[4] =
473 SWAP32((video_font_draw_table32
474 [bits & 15][0] & eorx) ^ bgx);
475 ((u32 *) dest)[5] =
476 SWAP32((video_font_draw_table32
477 [bits & 15][1] & eorx) ^ bgx);
478 ((u32 *) dest)[6] =
479 SWAP32((video_font_draw_table32
480 [bits & 15][2] & eorx) ^ bgx);
481 ((u32 *) dest)[7] =
482 SWAP32((video_font_draw_table32
483 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000484 }
485 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
486 s++;
487 }
488 break;
489
490 case GDF_24BIT_888RGB:
491 while (count--) {
492 c = *s;
493 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
494 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000495 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000496 u8 bits = *cdat++;
497
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000498 ((u32 *) dest)[0] =
499 (video_font_draw_table24[bits >> 4][0]
500 & eorx) ^ bgx;
501 ((u32 *) dest)[1] =
502 (video_font_draw_table24[bits >> 4][1]
503 & eorx) ^ bgx;
504 ((u32 *) dest)[2] =
505 (video_font_draw_table24[bits >> 4][2]
506 & eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200507
508 if (VIDEO_FONT_WIDTH == 4)
509 continue;
510
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000511 ((u32 *) dest)[3] =
512 (video_font_draw_table24[bits & 15][0]
513 & eorx) ^ bgx;
514 ((u32 *) dest)[4] =
515 (video_font_draw_table24[bits & 15][1]
516 & eorx) ^ bgx;
517 ((u32 *) dest)[5] =
518 (video_font_draw_table24[bits & 15][2]
519 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000520 }
521 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
522 s++;
523 }
524 break;
wdenk57b2d802003-06-27 21:31:46 +0000525 }
wdenkc6097192002-11-03 00:24:07 +0000526}
527
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000528static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000529{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000530 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000531}
532
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000533static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000534{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000535 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000536}
537
Simon Glassf406a1b2015-10-18 21:17:18 -0600538#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000539static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000540{
Gabe Black12874de2011-11-30 13:50:50 +0000541 if (cursor_state)
542 console_cursor(0);
543 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000544}
Gabe Black12874de2011-11-30 13:50:50 +0000545
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000546static void video_invertchar(int xx, int yy)
547{
548 int firstx = xx * VIDEO_PIXEL_SIZE;
549 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
550 int firsty = yy * VIDEO_LINE_LEN;
551 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
552 int x, y;
553 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
554 for (x = firstx; x < lastx; x++) {
555 u8 *dest = (u8 *)(video_fb_address) + x + y;
556 *dest = ~*dest;
557 }
558 }
559}
Gabe Black12874de2011-11-30 13:50:50 +0000560
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000561void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000562{
Gabe Black12874de2011-11-30 13:50:50 +0000563 if (cursor_state != state) {
564 if (cursor_state) {
565 /* turn off the cursor */
566 video_invertchar(old_col * VIDEO_FONT_WIDTH,
567 old_row * VIDEO_FONT_HEIGHT +
568 video_logo_height);
569 } else {
570 /* turn off the cursor and record where it is */
571 video_invertchar(console_col * VIDEO_FONT_WIDTH,
572 console_row * VIDEO_FONT_HEIGHT +
573 video_logo_height);
574 old_col = console_col;
575 old_row = console_row;
576 }
577 cursor_state = state;
wdenke55402c2004-03-14 16:51:43 +0000578 }
Eric Nelson54142422013-05-06 14:27:28 +0200579 if (cfb_do_flush_cache)
580 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000581}
582#endif
583
wdenkc6097192002-11-03 00:24:07 +0000584#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000585static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000586{
wdenke55402c2004-03-14 16:51:43 +0000587 while (c--)
588 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000589}
590#endif
591
wdenkc6097192002-11-03 00:24:07 +0000592#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000593static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000594{
wdenke55402c2004-03-14 16:51:43 +0000595 while (c--)
596 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000597}
598#endif
599
Pali Rohár16658612012-04-28 07:26:44 +0000600static void console_clear_line(int line, int begin, int end)
601{
602#ifdef VIDEO_HW_RECTFILL
603 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
604 VIDEO_FONT_WIDTH * begin, /* dest pos x */
605 video_logo_height +
606 VIDEO_FONT_HEIGHT * line, /* dest pos y */
607 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
608 VIDEO_FONT_HEIGHT, /* frame height */
609 bgx /* fill color */
610 );
611#else
612 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
613 memsetl(CONSOLE_ROW_FIRST +
614 CONSOLE_ROW_SIZE * line, /* offset of row */
615 CONSOLE_ROW_SIZE >> 2, /* length of row */
616 bgx /* fill color */
617 );
618 } else {
619 void *offset;
620 int i, size;
621
622 offset = CONSOLE_ROW_FIRST +
623 CONSOLE_ROW_SIZE * line + /* offset of row */
624 VIDEO_FONT_WIDTH *
625 VIDEO_PIXEL_SIZE * begin; /* offset of col */
626 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
627 size >>= 2; /* length to end for memsetl() */
628 /* fill at col offset of i'th line using bgx as fill color */
629 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
630 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
631 }
632#endif
633}
634
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000635static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000636{
Simon Glass6ceb7f02015-01-01 16:17:57 -0700637 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
638 int i;
639
wdenke55402c2004-03-14 16:51:43 +0000640 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000641
642#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000643 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
644 0, /* source pos x */
645 video_logo_height +
Simon Glass6ceb7f02015-01-01 16:17:57 -0700646 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000647 0, /* dest pos x */
648 video_logo_height, /* dest pos y */
649 VIDEO_VISIBLE_COLS, /* frame width */
650 VIDEO_VISIBLE_ROWS
651 - video_logo_height
Simon Glass6ceb7f02015-01-01 16:17:57 -0700652 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000653 );
wdenkc6097192002-11-03 00:24:07 +0000654#else
Simon Glass6ceb7f02015-01-01 16:17:57 -0700655 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
656 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000657#endif
wdenke55402c2004-03-14 16:51:43 +0000658 /* clear the last one */
Simon Glass6ceb7f02015-01-01 16:17:57 -0700659 for (i = 1; i <= rows; i++)
660 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
661
662 /* Decrement row number */
663 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000664}
665
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000666static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000667{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500668 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000669
wdenke55402c2004-03-14 16:51:43 +0000670 if (console_col < 0) {
671 console_col = CONSOLE_COLS - 1;
672 console_row--;
673 if (console_row < 0)
674 console_row = 0;
675 }
wdenkc6097192002-11-03 00:24:07 +0000676}
677
Pali Rohár4a57da32012-10-19 13:30:09 +0000678#ifdef CONFIG_CFB_CONSOLE_ANSI
679
680static void console_clear(void)
681{
682#ifdef VIDEO_HW_RECTFILL
683 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
684 0, /* dest pos x */
685 video_logo_height, /* dest pos y */
686 VIDEO_VISIBLE_COLS, /* frame width */
687 VIDEO_VISIBLE_ROWS, /* frame height */
688 bgx /* fill color */
689 );
690#else
691 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
692#endif
693}
694
695static void console_cursor_fix(void)
696{
697 if (console_row < 0)
698 console_row = 0;
699 if (console_row >= CONSOLE_ROWS)
700 console_row = CONSOLE_ROWS - 1;
701 if (console_col < 0)
702 console_col = 0;
703 if (console_col >= CONSOLE_COLS)
704 console_col = CONSOLE_COLS - 1;
705}
706
707static void console_cursor_up(int n)
708{
709 console_row -= n;
710 console_cursor_fix();
711}
712
713static void console_cursor_down(int n)
714{
715 console_row += n;
716 console_cursor_fix();
717}
718
719static void console_cursor_left(int n)
wdenkc6097192002-11-03 00:24:07 +0000720{
Pali Rohár4a57da32012-10-19 13:30:09 +0000721 console_col -= n;
722 console_cursor_fix();
723}
724
725static void console_cursor_right(int n)
726{
727 console_col += n;
728 console_cursor_fix();
729}
730
731static void console_cursor_set_position(int row, int col)
732{
733 if (console_row != -1)
734 console_row = row;
735 if (console_col != -1)
736 console_col = col;
737 console_cursor_fix();
738}
739
740static void console_previousline(int n)
741{
742 /* FIXME: also scroll terminal ? */
743 console_row -= n;
744 console_cursor_fix();
745}
746
747static void console_swap_colors(void)
748{
749 eorx = fgx;
750 fgx = bgx;
751 bgx = eorx;
752 eorx = fgx ^ bgx;
753}
754
755static inline int console_cursor_is_visible(void)
756{
757 return !ansi_cursor_hidden;
758}
759#else
760static inline int console_cursor_is_visible(void)
761{
762 return 1;
763}
764#endif
765
766static void console_newline(int n)
767{
768 console_row += n;
wdenke55402c2004-03-14 16:51:43 +0000769 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000770
wdenke55402c2004-03-14 16:51:43 +0000771 /* Check if we need to scroll the terminal */
772 if (console_row >= CONSOLE_ROWS) {
773 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000774 console_scrollup();
wdenke55402c2004-03-14 16:51:43 +0000775 }
wdenkc6097192002-11-03 00:24:07 +0000776}
777
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000778static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100779{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500780 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100781}
782
Pali Rohár4a57da32012-10-19 13:30:09 +0000783static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000784{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100785 static int nl = 1;
786
Pali Rohár4a57da32012-10-19 13:30:09 +0000787 if (console_cursor_is_visible())
788 CURSOR_OFF;
Gabe Black12874de2011-11-30 13:50:50 +0000789
wdenke55402c2004-03-14 16:51:43 +0000790 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100791 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000792 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000793 break;
wdenkc6097192002-11-03 00:24:07 +0000794
wdenke55402c2004-03-14 16:51:43 +0000795 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100796 if (console_col || (!console_col && nl))
Pali Rohár4a57da32012-10-19 13:30:09 +0000797 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100798 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000799 break;
wdenkc6097192002-11-03 00:24:07 +0000800
wdenke55402c2004-03-14 16:51:43 +0000801 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500802 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000803 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000804
wdenke55402c2004-03-14 16:51:43 +0000805 if (console_col >= CONSOLE_COLS)
Pali Rohár4a57da32012-10-19 13:30:09 +0000806 console_newline(1);
wdenke55402c2004-03-14 16:51:43 +0000807 break;
wdenkc6097192002-11-03 00:24:07 +0000808
wdenke55402c2004-03-14 16:51:43 +0000809 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000810 console_back();
wdenke55402c2004-03-14 16:51:43 +0000811 break;
wdenkc6097192002-11-03 00:24:07 +0000812
Pali Rohár9d735b62012-04-28 07:26:47 +0000813 case 7: /* bell */
814 break; /* ignored */
815
wdenke55402c2004-03-14 16:51:43 +0000816 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000817 video_putchar(console_col * VIDEO_FONT_WIDTH,
818 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000819 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000820
wdenke55402c2004-03-14 16:51:43 +0000821 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100822 if (console_col >= CONSOLE_COLS) {
Pali Rohár4a57da32012-10-19 13:30:09 +0000823 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100824 nl = 0;
825 }
wdenke55402c2004-03-14 16:51:43 +0000826 }
Pali Rohár4a57da32012-10-19 13:30:09 +0000827
828 if (console_cursor_is_visible())
829 CURSOR_SET;
830}
831
Jeroen Hofstee169eda62014-10-08 22:57:44 +0200832static void video_putc(struct stdio_dev *dev, const char c)
Pali Rohár4a57da32012-10-19 13:30:09 +0000833{
834#ifdef CONFIG_CFB_CONSOLE_ANSI
835 int i;
836
837 if (c == 27) {
838 for (i = 0; i < ansi_buf_size; ++i)
839 parse_putc(ansi_buf[i]);
840 ansi_buf[0] = 27;
841 ansi_buf_size = 1;
842 return;
843 }
844
845 if (ansi_buf_size > 0) {
846 /*
847 * 0 - ESC
848 * 1 - [
849 * 2 - num1
850 * 3 - ..
851 * 4 - ;
852 * 5 - num2
853 * 6 - ..
854 * - cchar
855 */
856 int next = 0;
857
858 int flush = 0;
859 int fail = 0;
860
861 int num1 = 0;
862 int num2 = 0;
863 int cchar = 0;
864
865 ansi_buf[ansi_buf_size++] = c;
866
867 if (ansi_buf_size >= sizeof(ansi_buf))
868 fail = 1;
869
870 for (i = 0; i < ansi_buf_size; ++i) {
871 if (fail)
872 break;
873
874 switch (next) {
875 case 0:
876 if (ansi_buf[i] == 27)
877 next = 1;
878 else
879 fail = 1;
880 break;
881
882 case 1:
883 if (ansi_buf[i] == '[')
884 next = 2;
885 else
886 fail = 1;
887 break;
888
889 case 2:
890 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
891 num1 = ansi_buf[i]-'0';
892 next = 3;
893 } else if (ansi_buf[i] != '?') {
894 --i;
895 num1 = 1;
896 next = 4;
897 }
898 break;
899
900 case 3:
901 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
902 num1 *= 10;
903 num1 += ansi_buf[i]-'0';
904 } else {
905 --i;
906 next = 4;
907 }
908 break;
909
910 case 4:
911 if (ansi_buf[i] != ';') {
912 --i;
913 next = 7;
914 } else
915 next = 5;
916 break;
917
918 case 5:
919 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
920 num2 = ansi_buf[i]-'0';
921 next = 6;
922 } else
923 fail = 1;
924 break;
925
926 case 6:
927 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
928 num2 *= 10;
929 num2 += ansi_buf[i]-'0';
930 } else {
931 --i;
932 next = 7;
933 }
934 break;
935
936 case 7:
937 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
938 || ansi_buf[i] == 'J'
939 || ansi_buf[i] == 'K'
940 || ansi_buf[i] == 'h'
941 || ansi_buf[i] == 'l'
942 || ansi_buf[i] == 'm') {
943 cchar = ansi_buf[i];
944 flush = 1;
945 } else
946 fail = 1;
947 break;
948 }
949 }
950
951 if (fail) {
952 for (i = 0; i < ansi_buf_size; ++i)
953 parse_putc(ansi_buf[i]);
954 ansi_buf_size = 0;
955 return;
956 }
957
958 if (flush) {
959 if (!ansi_cursor_hidden)
960 CURSOR_OFF;
961 ansi_buf_size = 0;
962 switch (cchar) {
963 case 'A':
964 /* move cursor num1 rows up */
965 console_cursor_up(num1);
966 break;
967 case 'B':
968 /* move cursor num1 rows down */
969 console_cursor_down(num1);
970 break;
971 case 'C':
972 /* move cursor num1 columns forward */
973 console_cursor_right(num1);
974 break;
975 case 'D':
976 /* move cursor num1 columns back */
977 console_cursor_left(num1);
978 break;
979 case 'E':
980 /* move cursor num1 rows up at begin of row */
981 console_previousline(num1);
982 break;
983 case 'F':
984 /* move cursor num1 rows down at begin of row */
985 console_newline(num1);
986 break;
987 case 'G':
988 /* move cursor to column num1 */
989 console_cursor_set_position(-1, num1-1);
990 break;
991 case 'H':
992 /* move cursor to row num1, column num2 */
993 console_cursor_set_position(num1-1, num2-1);
994 break;
995 case 'J':
996 /* clear console and move cursor to 0, 0 */
997 console_clear();
998 console_cursor_set_position(0, 0);
999 break;
1000 case 'K':
1001 /* clear line */
1002 if (num1 == 0)
1003 console_clear_line(console_row,
1004 console_col,
1005 CONSOLE_COLS-1);
1006 else if (num1 == 1)
1007 console_clear_line(console_row,
1008 0, console_col);
1009 else
1010 console_clear_line(console_row,
1011 0, CONSOLE_COLS-1);
1012 break;
1013 case 'h':
1014 ansi_cursor_hidden = 0;
1015 break;
1016 case 'l':
1017 ansi_cursor_hidden = 1;
1018 break;
1019 case 'm':
1020 if (num1 == 0) { /* reset swapped colors */
1021 if (ansi_colors_need_revert) {
1022 console_swap_colors();
1023 ansi_colors_need_revert = 0;
1024 }
1025 } else if (num1 == 7) { /* once swap colors */
1026 if (!ansi_colors_need_revert) {
1027 console_swap_colors();
1028 ansi_colors_need_revert = 1;
1029 }
1030 }
1031 break;
1032 }
1033 if (!ansi_cursor_hidden)
1034 CURSOR_SET;
1035 }
1036 } else {
1037 parse_putc(c);
1038 }
1039#else
1040 parse_putc(c);
1041#endif
Eric Nelson54142422013-05-06 14:27:28 +02001042 if (cfb_do_flush_cache)
1043 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabibe0c74e2010-08-27 15:45:47 -05001044}
wdenkc6097192002-11-03 00:24:07 +00001045
Jeroen Hofstee169eda62014-10-08 22:57:44 +02001046static void video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001047{
Soeren Mochbd9c1312014-10-24 16:33:30 +02001048 int flush = cfb_do_flush_cache;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001049 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +00001050
Soeren Mochbd9c1312014-10-24 16:33:30 +02001051 /* temporarily disable cache flush */
1052 cfb_do_flush_cache = 0;
1053
wdenke55402c2004-03-14 16:51:43 +00001054 while (count--)
Simon Glass0d1e1f72014-07-23 06:54:59 -06001055 video_putc(dev, *s++);
Soeren Mochbd9c1312014-10-24 16:33:30 +02001056
1057 if (flush) {
1058 cfb_do_flush_cache = flush;
1059 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1060 }
wdenke55402c2004-03-14 16:51:43 +00001061}
1062
Anatolij Gustschina043c342010-05-01 22:21:09 +02001063/*
1064 * Do not enforce drivers (or board code) to provide empty
1065 * video_set_lut() if they do not support 8 bpp format.
1066 * Implement weak default function instead.
1067 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02001068__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001069 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +02001070{
1071}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001072
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001073#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +00001074
1075#define FILL_8BIT_332RGB(r,g,b) { \
1076 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1077 fb ++; \
1078}
1079
1080#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001081 *(unsigned short *)fb = \
1082 SWAP16((unsigned short)(((r>>3)<<10) | \
1083 ((g>>3)<<5) | \
1084 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001085 fb += 2; \
1086}
1087
1088#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001089 *(unsigned short *)fb = \
1090 SWAP16((unsigned short)((((r)>>3)<<11)| \
1091 (((g)>>2)<<5) | \
1092 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001093 fb += 2; \
1094}
1095
1096#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001097 *(unsigned long *)fb = \
1098 SWAP32((unsigned long)(((r<<16) | \
1099 (g<<8) | \
1100 b))); \
wdenke55402c2004-03-14 16:51:43 +00001101 fb += 4; \
1102}
1103
1104#ifdef VIDEO_FB_LITTLE_ENDIAN
1105#define FILL_24BIT_888RGB(r,g,b) { \
1106 fb[0] = b; \
1107 fb[1] = g; \
1108 fb[2] = r; \
1109 fb += 3; \
1110}
1111#else
1112#define FILL_24BIT_888RGB(r,g,b) { \
1113 fb[0] = r; \
1114 fb[1] = g; \
1115 fb[2] = b; \
1116 fb += 3; \
1117}
1118#endif
1119
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001120#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001121static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001122{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001123 ushort *dst = (ushort *) fb;
1124 ushort color = (ushort) (((r >> 3) << 10) |
1125 ((g >> 3) << 5) |
1126 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001127 if (x & 1)
1128 *(--dst) = color;
1129 else
1130 *(++dst) = color;
1131}
1132#endif
wdenke55402c2004-03-14 16:51:43 +00001133
1134/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001135 * RLE8 bitmap support
1136 */
1137
1138#ifdef CONFIG_VIDEO_BMP_RLE8
1139/* Pre-calculated color table entry */
1140struct palette {
1141 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001142 unsigned short w; /* word */
1143 unsigned int dw; /* double word */
1144 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001145};
1146
1147/*
1148 * Helper to draw encoded/unencoded run.
1149 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001150static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1151 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001152{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001153 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001154 int *off;
1155 int enc_off = 1;
1156 int i;
1157
1158 /*
1159 * Setup offset of the color index in the bitmap.
1160 * Color index of encoded run is at offset 1.
1161 */
1162 off = enc ? &enc_off : &i;
1163
1164 switch (VIDEO_DATA_FORMAT) {
1165 case GDF__8BIT_INDEX:
1166 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001167 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001168 break;
1169 case GDF_15BIT_555RGB:
1170 case GDF_16BIT_565RGB:
1171 /* differences handled while pre-calculating palette */
1172 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001173 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001174 addr += 2;
1175 }
1176 break;
1177 case GDF_32BIT_X888RGB:
1178 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001179 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001180 addr += 4;
1181 }
1182 break;
1183 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001184 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001185}
1186
Simon Glass92e1f852015-05-13 07:02:27 -06001187static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001188 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001189{
1190 unsigned char *bm;
1191 unsigned char *fbp;
1192 unsigned int cnt, runlen;
1193 int decode = 1;
1194 int x, y, bpp, i, ncolors;
1195 struct palette p[256];
Simon Glass92e1f852015-05-13 07:02:27 -06001196 struct bmp_color_table_entry cte;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001197 int green_shift, red_off;
Hans de Goedea8287e72015-08-04 12:15:39 +02001198 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001199 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001200
1201 x = 0;
1202 y = __le32_to_cpu(img->header.height) - 1;
1203 ncolors = __le32_to_cpu(img->header.colors_used);
1204 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001205 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001206 (y + yoff) * VIDEO_LINE_LEN +
1207 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001208
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001209 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001210
1211 /* pre-calculate and setup palette */
1212 switch (VIDEO_DATA_FORMAT) {
1213 case GDF__8BIT_INDEX:
1214 for (i = 0; i < ncolors; i++) {
1215 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001216 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001217 }
1218 break;
1219 case GDF_15BIT_555RGB:
1220 case GDF_16BIT_565RGB:
1221 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1222 green_shift = 3;
1223 red_off = 10;
1224 } else {
1225 green_shift = 2;
1226 red_off = 11;
1227 }
1228 for (i = 0; i < ncolors; i++) {
1229 cte = img->color_table[i];
1230 p[i].ce.w = SWAP16((unsigned short)
1231 (((cte.red >> 3) << red_off) |
1232 ((cte.green >> green_shift) << 5) |
1233 cte.blue >> 3));
1234 }
1235 break;
1236 case GDF_32BIT_X888RGB:
1237 for (i = 0; i < ncolors; i++) {
1238 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001239 p[i].ce.dw = SWAP32((cte.red << 16) |
1240 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001241 cte.blue);
1242 }
1243 break;
1244 default:
1245 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001246 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001247 return -1;
1248 }
1249
1250 while (decode) {
1251 switch (bm[0]) {
1252 case 0:
1253 switch (bm[1]) {
1254 case 0:
1255 /* scan line end marker */
1256 bm += 2;
1257 x = 0;
1258 y--;
1259 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001260 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001261 (y + yoff) * VIDEO_LINE_LEN +
1262 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001263 continue;
1264 case 1:
1265 /* end of bitmap data marker */
1266 decode = 0;
1267 break;
1268 case 2:
1269 /* run offset marker */
1270 x += bm[2];
1271 y -= bm[3];
1272 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001273 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001274 (y + yoff) * VIDEO_LINE_LEN +
1275 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001276 bm += 4;
1277 break;
1278 default:
1279 /* unencoded run */
1280 cnt = bm[1];
1281 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001282 pixels += cnt;
1283 if (pixels > limit)
1284 goto error;
1285
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001286 bm += 2;
1287 if (y < height) {
1288 if (x >= width) {
1289 x += runlen;
1290 goto next_run;
1291 }
1292 if (x + runlen > width)
1293 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001294 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001295 x += runlen;
1296 }
1297next_run:
1298 bm += runlen;
1299 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001300 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001301 }
1302 break;
1303 default:
1304 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001305 cnt = bm[0];
1306 runlen = cnt;
1307 pixels += cnt;
1308 if (pixels > limit)
1309 goto error;
1310
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001311 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001312 if (x >= width) {
1313 x += runlen;
1314 bm += 2;
1315 continue;
1316 }
1317 if (x + runlen > width)
1318 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001319 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001320 x += runlen;
1321 }
1322 bm += 2;
1323 break;
1324 }
1325 }
1326 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001327error:
1328 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1329 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001330}
1331#endif
1332
1333/*
wdenke55402c2004-03-14 16:51:43 +00001334 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001335 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001336int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001337{
1338 ushort xcount, ycount;
1339 uchar *fb;
Simon Glass92e1f852015-05-13 07:02:27 -06001340 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenke55402c2004-03-14 16:51:43 +00001341 uchar *bmap;
1342 ushort padded_line;
1343 unsigned long width, height, bpp;
1344 unsigned colors;
1345 unsigned long compression;
Simon Glass92e1f852015-05-13 07:02:27 -06001346 struct bmp_color_table_entry cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001347
Stefan Roesed9d97742005-09-22 09:04:17 +02001348#ifdef CONFIG_VIDEO_BMP_GZIP
1349 unsigned char *dst = NULL;
1350 ulong len;
1351#endif
wdenkc6097192002-11-03 00:24:07 +00001352
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001353 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001354
1355 if (!((bmp->header.signature[0] == 'B') &&
1356 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001357
1358#ifdef CONFIG_VIDEO_BMP_GZIP
1359 /*
1360 * Could be a gzipped bmp image, try to decrompress...
1361 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001362 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1363 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001364 if (dst == NULL) {
1365 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001366 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001367 }
Eric Nelsonfba70872014-03-08 07:55:52 -07001368 /*
1369 * NB: we need to force offset of +2
1370 * See doc/README.displaying-bmps
1371 */
1372 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001373 (uchar *) bmp_image,
1374 &len) != 0) {
1375 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1376 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001377 free(dst);
1378 return 1;
1379 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001380 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001381 printf("Image could be truncated "
1382 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001383 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001384
1385 /*
1386 * Set addr to decompressed image
1387 */
Simon Glass92e1f852015-05-13 07:02:27 -06001388 bmp = (struct bmp_image *)(dst+2);
Stefan Roesed9d97742005-09-22 09:04:17 +02001389
1390 if (!((bmp->header.signature[0] == 'B') &&
1391 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001392 printf("Error: no valid bmp.gz image at %lx\n",
1393 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001394 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001395 return 1;
1396 }
1397#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001398 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001399 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001400#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001401 }
1402
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001403 width = le32_to_cpu(bmp->header.width);
1404 height = le32_to_cpu(bmp->header.height);
1405 bpp = le16_to_cpu(bmp->header.bit_count);
1406 colors = le32_to_cpu(bmp->header.colors_used);
1407 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001408
Marek Vasut2eb9a492011-10-21 14:17:04 +00001409 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001410 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001411
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001412 if (compression != BMP_BI_RGB
1413#ifdef CONFIG_VIDEO_BMP_RLE8
1414 && compression != BMP_BI_RLE8
1415#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001416 ) {
1417 printf("Error: compression type %ld not supported\n",
1418 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001419#ifdef CONFIG_VIDEO_BMP_GZIP
1420 if (dst)
1421 free(dst);
1422#endif
wdenke55402c2004-03-14 16:51:43 +00001423 return 1;
1424 }
1425
1426 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1427
Matthias Weisser53884182009-07-09 16:07:30 +02001428#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1429 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001430 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001431 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001432 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001433
1434 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001435 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001436 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001437 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001438#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1439
Matthias Weisser5e5ed762013-02-15 03:35:12 +00001440 /*
1441 * Just ignore elements which are completely beyond screen
1442 * dimensions.
1443 */
1444 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1445 return 0;
1446
wdenke55402c2004-03-14 16:51:43 +00001447 if ((x + width) > VIDEO_VISIBLE_COLS)
1448 width = VIDEO_VISIBLE_COLS - x;
1449 if ((y + height) > VIDEO_VISIBLE_ROWS)
1450 height = VIDEO_VISIBLE_ROWS - y;
1451
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001452 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001453 fb = (uchar *) (video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001454 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenke55402c2004-03-14 16:51:43 +00001455 x * VIDEO_PIXEL_SIZE);
1456
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001457#ifdef CONFIG_VIDEO_BMP_RLE8
1458 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001459 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001460 }
1461#endif
1462
Timur Tabi0fce9922010-08-23 16:58:00 -05001463 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001464 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001465 case 4:
1466 padded_line -= width / 2;
1467 ycount = height;
1468
1469 switch (VIDEO_DATA_FORMAT) {
1470 case GDF_32BIT_X888RGB:
1471 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001472 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001473 /*
1474 * Don't assume that 'width' is an
1475 * even number
1476 */
1477 for (xcount = 0; xcount < width; xcount++) {
1478 uchar idx;
1479
1480 if (xcount & 1) {
1481 idx = *bmap & 0xF;
1482 bmap++;
1483 } else
1484 idx = *bmap >> 4;
1485 cte = bmp->color_table[idx];
1486 FILL_32BIT_X888RGB(cte.red, cte.green,
1487 cte.blue);
1488 }
1489 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001490 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001491 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001492 }
1493 break;
1494 default:
1495 puts("4bpp bitmap unsupported with current "
1496 "video mode\n");
1497 break;
1498 }
1499 break;
1500
wdenke55402c2004-03-14 16:51:43 +00001501 case 8:
1502 padded_line -= width;
1503 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001504 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001505 for (xcount = 0; xcount < colors; ++xcount) {
1506 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001507 video_set_lut(xcount, cte.red, cte.green,
1508 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001509 }
1510 }
1511 ycount = height;
1512 switch (VIDEO_DATA_FORMAT) {
1513 case GDF__8BIT_INDEX:
1514 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001515 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001516 xcount = width;
1517 while (xcount--) {
1518 *fb++ = *bmap++;
1519 }
1520 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001521 fb -= VIDEO_LINE_LEN + width *
1522 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001523 }
1524 break;
1525 case GDF__8BIT_332RGB:
1526 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001527 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001528 xcount = width;
1529 while (xcount--) {
1530 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001531 FILL_8BIT_332RGB(cte.red, cte.green,
1532 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001533 }
1534 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001535 fb -= VIDEO_LINE_LEN + width *
1536 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001537 }
1538 break;
1539 case GDF_15BIT_555RGB:
1540 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001541#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1542 int xpos = x;
1543#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001544 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001545 xcount = width;
1546 while (xcount--) {
1547 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001548#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001549 fill_555rgb_pswap(fb, xpos++, cte.red,
1550 cte.green,
1551 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001552 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001553#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001554 FILL_15BIT_555RGB(cte.red, cte.green,
1555 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001556#endif
wdenke55402c2004-03-14 16:51:43 +00001557 }
1558 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001559 fb -= VIDEO_LINE_LEN + width *
1560 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001561 }
1562 break;
1563 case GDF_16BIT_565RGB:
1564 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001565 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001566 xcount = width;
1567 while (xcount--) {
1568 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001569 FILL_16BIT_565RGB(cte.red, cte.green,
1570 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001571 }
1572 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001573 fb -= VIDEO_LINE_LEN + width *
1574 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001575 }
1576 break;
1577 case GDF_32BIT_X888RGB:
1578 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001579 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001580 xcount = width;
1581 while (xcount--) {
1582 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001583 FILL_32BIT_X888RGB(cte.red, cte.green,
1584 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001585 }
1586 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001587 fb -= VIDEO_LINE_LEN + width *
1588 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001589 }
1590 break;
1591 case GDF_24BIT_888RGB:
1592 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001593 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001594 xcount = width;
1595 while (xcount--) {
1596 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001597 FILL_24BIT_888RGB(cte.red, cte.green,
1598 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001599 }
1600 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001601 fb -= VIDEO_LINE_LEN + width *
1602 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001603 }
1604 break;
1605 }
1606 break;
1607 case 24:
1608 padded_line -= 3 * width;
1609 ycount = height;
1610 switch (VIDEO_DATA_FORMAT) {
1611 case GDF__8BIT_332RGB:
1612 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001613 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001614 xcount = width;
1615 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001616 FILL_8BIT_332RGB(bmap[2], bmap[1],
1617 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001618 bmap += 3;
1619 }
1620 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001621 fb -= VIDEO_LINE_LEN + width *
1622 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001623 }
1624 break;
1625 case GDF_15BIT_555RGB:
1626 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001627#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1628 int xpos = x;
1629#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001630 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001631 xcount = width;
1632 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001633#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001634 fill_555rgb_pswap(fb, xpos++, bmap[2],
1635 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001636 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001637#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001638 FILL_15BIT_555RGB(bmap[2], bmap[1],
1639 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001640#endif
wdenke55402c2004-03-14 16:51:43 +00001641 bmap += 3;
1642 }
1643 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001644 fb -= VIDEO_LINE_LEN + width *
1645 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001646 }
1647 break;
1648 case GDF_16BIT_565RGB:
1649 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001650 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001651 xcount = width;
1652 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001653 FILL_16BIT_565RGB(bmap[2], bmap[1],
1654 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001655 bmap += 3;
1656 }
1657 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001658 fb -= VIDEO_LINE_LEN + width *
1659 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001660 }
1661 break;
1662 case GDF_32BIT_X888RGB:
1663 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001664 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001665 xcount = width;
1666 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001667 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1668 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001669 bmap += 3;
1670 }
1671 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001672 fb -= VIDEO_LINE_LEN + width *
1673 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001674 }
1675 break;
1676 case GDF_24BIT_888RGB:
1677 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001678 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001679 xcount = width;
1680 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001681 FILL_24BIT_888RGB(bmap[2], bmap[1],
1682 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001683 bmap += 3;
1684 }
1685 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001686 fb -= VIDEO_LINE_LEN + width *
1687 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001688 }
1689 break;
1690 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001691 printf("Error: 24 bits/pixel bitmap incompatible "
1692 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001693 break;
1694 }
1695 break;
1696 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001697 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1698 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001699 break;
1700 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001701
1702#ifdef CONFIG_VIDEO_BMP_GZIP
1703 if (dst) {
1704 free(dst);
1705 }
1706#endif
1707
Eric Nelson54142422013-05-06 14:27:28 +02001708 if (cfb_do_flush_cache)
1709 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenke55402c2004-03-14 16:51:43 +00001710 return (0);
wdenkc6097192002-11-03 00:24:07 +00001711}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001712#endif
wdenkc6097192002-11-03 00:24:07 +00001713
wdenkc6097192002-11-03 00:24:07 +00001714
1715#ifdef CONFIG_VIDEO_LOGO
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001716static int video_logo_xpos;
1717static int video_logo_ypos;
1718
Hans de Goedeb922f782015-08-04 12:21:40 +02001719static void plot_logo_or_black(void *screen, int x, int y, int black);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001720
Hans de Goedeb922f782015-08-04 12:21:40 +02001721static void logo_plot(void *screen, int x, int y)
Bastian Ruppertd5932182012-09-13 22:29:02 +00001722{
Hans de Goedeb922f782015-08-04 12:21:40 +02001723 plot_logo_or_black(screen, x, y, 0);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001724}
1725
1726static void logo_black(void)
1727{
Hans de Goedeb922f782015-08-04 12:21:40 +02001728 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
Bastian Ruppertd5932182012-09-13 22:29:02 +00001729 1);
1730}
1731
1732static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1733{
1734 if (argc != 1)
1735 return cmd_usage(cmdtp);
1736
1737 logo_black();
1738 return 0;
1739}
1740
1741U_BOOT_CMD(
1742 clrlogo, 1, 0, do_clrlogo,
1743 "fill the boot logo area with black",
1744 " "
1745 );
1746
Hans de Goedeb922f782015-08-04 12:21:40 +02001747static void plot_logo_or_black(void *screen, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001748{
wdenk9dd2b882002-12-03 21:28:10 +00001749
wdenke55402c2004-03-14 16:51:43 +00001750 int xcount, i;
Hans de Goedea8287e72015-08-04 12:15:39 +02001751 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001752 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001753 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1754 unsigned char *source;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001755 unsigned char *dest;
1756
1757#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1758 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001759 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001760 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001761 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001762
1763 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001764 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001765 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001766 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001767#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1768
Hans de Goedea8287e72015-08-04 12:15:39 +02001769 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001770
wdenk9dd2b882002-12-03 21:28:10 +00001771#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001772 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001773
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001774 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001775 logo_red = malloc(BMP_LOGO_COLORS);
1776 logo_green = malloc(BMP_LOGO_COLORS);
1777 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001778 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001779 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1780 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1781 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1782 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1783 }
wdenk9dd2b882002-12-03 21:28:10 +00001784#else
wdenke55402c2004-03-14 16:51:43 +00001785 source = linux_logo;
1786 logo_red = linux_logo_red;
1787 logo_green = linux_logo_green;
1788 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001789#endif
wdenk57b2d802003-06-27 21:31:46 +00001790
wdenke55402c2004-03-14 16:51:43 +00001791 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1792 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001793 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1794 logo_red[i], logo_green[i],
1795 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001796 }
wdenk57b2d802003-06-27 21:31:46 +00001797 }
wdenkc6097192002-11-03 00:24:07 +00001798
wdenke55402c2004-03-14 16:51:43 +00001799 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001800#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1801 int xpos = x;
1802#endif
wdenke55402c2004-03-14 16:51:43 +00001803 xcount = VIDEO_LOGO_WIDTH;
1804 while (xcount--) {
Bastian Ruppertd5932182012-09-13 22:29:02 +00001805 if (black) {
1806 r = 0x00;
1807 g = 0x00;
1808 b = 0x00;
1809 } else {
1810 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1811 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1812 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1813 }
wdenk57b2d802003-06-27 21:31:46 +00001814
wdenke55402c2004-03-14 16:51:43 +00001815 switch (VIDEO_DATA_FORMAT) {
1816 case GDF__8BIT_INDEX:
1817 *dest = *source;
1818 break;
1819 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001820 *dest = ((r >> 5) << 5) |
1821 ((g >> 5) << 2) |
1822 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001823 break;
1824 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001825#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001826 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001827#else
wdenke55402c2004-03-14 16:51:43 +00001828 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001829 SWAP16((unsigned short) (
1830 ((r >> 3) << 10) |
1831 ((g >> 3) << 5) |
1832 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001833#endif
wdenke55402c2004-03-14 16:51:43 +00001834 break;
1835 case GDF_16BIT_565RGB:
1836 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001837 SWAP16((unsigned short) (
1838 ((r >> 3) << 11) |
1839 ((g >> 2) << 5) |
1840 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001841 break;
1842 case GDF_32BIT_X888RGB:
1843 *(unsigned long *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001844 SWAP32((unsigned long) (
1845 (r << 16) |
1846 (g << 8) |
1847 b));
wdenke55402c2004-03-14 16:51:43 +00001848 break;
1849 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001850#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001851 dest[0] = b;
1852 dest[1] = g;
1853 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001854#else
wdenke55402c2004-03-14 16:51:43 +00001855 dest[0] = r;
1856 dest[1] = g;
1857 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001858#endif
wdenke55402c2004-03-14 16:51:43 +00001859 break;
1860 }
1861 source++;
1862 dest += VIDEO_PIXEL_SIZE;
1863 }
1864 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001865 }
wdenk9dd2b882002-12-03 21:28:10 +00001866#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001867 free(logo_red);
1868 free(logo_green);
1869 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001870#endif
wdenkc6097192002-11-03 00:24:07 +00001871}
1872
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001873static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001874{
wdenke55402c2004-03-14 16:51:43 +00001875 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001876 __maybe_unused int y_off = 0;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001877 __maybe_unused ulong addr;
1878 __maybe_unused char *s;
Tim Harvey98899462016-05-24 14:59:59 -07001879 __maybe_unused int len, space;
wdenke55402c2004-03-14 16:51:43 +00001880
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +02001881 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
wdenke55402c2004-03-14 16:51:43 +00001882
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001883#ifdef CONFIG_SPLASH_SCREEN
1884 s = getenv("splashimage");
1885 if (s != NULL) {
Robert Winkler2a90ed02013-06-17 11:31:29 -07001886 splash_screen_prepare();
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001887 addr = simple_strtoul(s, NULL, 16);
1888
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001889 if (video_display_bitmap(addr,
1890 video_logo_xpos,
1891 video_logo_ypos) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001892 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001893 return ((void *) (video_fb_address));
1894 }
1895 }
1896#endif /* CONFIG_SPLASH_SCREEN */
1897
Hans de Goedeb922f782015-08-04 12:21:40 +02001898 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001899
1900#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1901 /*
1902 * when using splashpos for video_logo, skip any info
1903 * output on video console if the logo is not at 0,0
1904 */
1905 if (video_logo_xpos || video_logo_ypos) {
1906 /*
1907 * video_logo_height is used in text and cursor offset
1908 * calculations. Since the console is below the logo,
1909 * we need to adjust the logo height
1910 */
1911 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001912 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001913 VIDEO_LOGO_HEIGHT) / 2);
1914 else if (video_logo_ypos > 0)
1915 video_logo_height += video_logo_ypos;
1916
1917 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1918 }
1919#endif
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02001920 if (board_cfb_skip())
1921 return 0;
wdenkc6097192002-11-03 00:24:07 +00001922
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001923 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001924
Tim Harvey98899462016-05-24 14:59:59 -07001925#ifndef CONFIG_HIDE_LOGO_VERSION
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001926 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1927 len = strlen(info);
1928
1929 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001930 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1931 (uchar *) info, space);
1932 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1933 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1934 (uchar *) info + space, len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001935 y_off = 1;
1936 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001937 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001938
1939#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001940 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001941 int i, n =
1942 ((video_logo_height -
1943 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001944
wdenke55402c2004-03-14 16:51:43 +00001945 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001946 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001947 if (!*info)
1948 continue;
1949
1950 len = strlen(info);
1951 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001952 video_drawchars(VIDEO_INFO_X,
1953 VIDEO_INFO_Y +
1954 (i + y_off) *
1955 VIDEO_FONT_HEIGHT,
1956 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001957 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001958 video_drawchars(VIDEO_INFO_X +
1959 VIDEO_FONT_WIDTH,
1960 VIDEO_INFO_Y +
1961 (i + y_off) *
1962 VIDEO_FONT_HEIGHT,
1963 (uchar *) info + space,
1964 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001965 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001966 video_drawstring(VIDEO_INFO_X,
1967 VIDEO_INFO_Y +
1968 (i + y_off) *
1969 VIDEO_FONT_HEIGHT,
1970 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001971 }
wdenke55402c2004-03-14 16:51:43 +00001972 }
1973 }
wdenkc6097192002-11-03 00:24:07 +00001974#endif
Tim Harvey98899462016-05-24 14:59:59 -07001975#endif
wdenkc6097192002-11-03 00:24:07 +00001976
Matthias Weisser76d70862010-01-12 12:06:31 +01001977 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001978}
1979#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02001980
1981static int cfb_fb_is_in_dram(void)
1982{
1983 bd_t *bd = gd->bd;
1984#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
1985defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
1986 ulong start, end;
1987 int i;
1988
1989 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
1990 start = bd->bi_dram[i].start;
1991 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
1992 if ((ulong)video_fb_address >= start &&
1993 (ulong)video_fb_address < end)
1994 return 1;
1995 }
1996#else
1997 if ((ulong)video_fb_address >= bd->bi_memstart &&
1998 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
1999 return 1;
2000#endif
2001 return 0;
2002}
wdenkc6097192002-11-03 00:24:07 +00002003
Heiko Schocher62759562013-10-22 11:06:06 +02002004void video_clear(void)
2005{
2006 if (!video_fb_address)
2007 return;
2008#ifdef VIDEO_HW_RECTFILL
2009 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2010 0, /* dest pos x */
2011 0, /* dest pos y */
2012 VIDEO_VISIBLE_COLS, /* frame width */
2013 VIDEO_VISIBLE_ROWS, /* frame height */
2014 bgx /* fill color */
2015 );
2016#else
2017 memsetl(video_fb_address,
2018 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2019#endif
2020}
2021
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002022static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002023{
wdenke55402c2004-03-14 16:51:43 +00002024 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002025
Wolfgang Denka87b2a952011-07-30 12:48:09 +00002026 pGD = video_hw_init();
2027 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00002028 return -1;
wdenkc6097192002-11-03 00:24:07 +00002029
wdenke55402c2004-03-14 16:51:43 +00002030 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002031
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002032 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2033
wdenke55402c2004-03-14 16:51:43 +00002034 /* Init drawing pats */
2035 switch (VIDEO_DATA_FORMAT) {
2036 case GDF__8BIT_INDEX:
Simon Glass884889d2016-10-17 20:12:44 -06002037 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2038 CONFIG_SYS_CONSOLE_FG_COL,
2039 CONFIG_SYS_CONSOLE_FG_COL);
2040 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2041 CONFIG_SYS_CONSOLE_BG_COL,
2042 CONFIG_SYS_CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00002043 fgx = 0x01010101;
2044 bgx = 0x00000000;
2045 break;
2046 case GDF__8BIT_332RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002047 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2048 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2049 CONFIG_SYS_CONSOLE_FG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002050 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2051 color8;
Simon Glass884889d2016-10-17 20:12:44 -06002052 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2053 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2054 CONFIG_SYS_CONSOLE_BG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002055 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2056 color8;
wdenke55402c2004-03-14 16:51:43 +00002057 break;
2058 case GDF_15BIT_555RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002059 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2060 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2061 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2062 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2063 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2064 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2065 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2066 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2067 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2068 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2069 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2070 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002071 break;
2072 case GDF_16BIT_565RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002073 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2074 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2075 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2076 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2077 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2078 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2079 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2080 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2081 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2082 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2083 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2084 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002085 break;
2086 case GDF_32BIT_X888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002087 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2088 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2089 CONFIG_SYS_CONSOLE_FG_COL;
2090 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2091 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2092 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002093 break;
2094 case GDF_24BIT_888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002095 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2096 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2097 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2098 CONFIG_SYS_CONSOLE_FG_COL;
2099 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2100 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2101 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2102 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002103 break;
2104 }
2105 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002106
Heiko Schocher62759562013-10-22 11:06:06 +02002107 video_clear();
2108
wdenkc6097192002-11-03 00:24:07 +00002109#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00002110 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00002111 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002112 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002113#else
wdenke55402c2004-03-14 16:51:43 +00002114 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002115#endif
2116
wdenke55402c2004-03-14 16:51:43 +00002117 /* Initialize the console */
2118 console_col = 0;
2119 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002120
Eric Nelson54142422013-05-06 14:27:28 +02002121 if (cfb_do_flush_cache)
2122 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2123
wdenke55402c2004-03-14 16:51:43 +00002124 return 0;
wdenkc6097192002-11-03 00:24:07 +00002125}
2126
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002127/*
2128 * Implement a weak default function for boards that optionally
2129 * need to skip the video initialization.
2130 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02002131__weak int board_video_skip(void)
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002132{
2133 /* As default, don't skip test */
2134 return 0;
2135}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002136
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002137int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002138{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02002139 struct stdio_dev console_dev;
Simon Glasse9fa1f02015-03-02 12:40:50 -07002140 bool have_keyboard;
Bin Menge52e17a2015-08-24 01:00:07 -07002141 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00002142
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002143 /* Check if video initialization should be skipped */
2144 if (board_video_skip())
2145 return 0;
2146
wdenk7dd13292004-07-11 20:04:51 +00002147 /* Init video chip - returns with framebuffer cleared */
Bin Menge52e17a2015-08-24 01:00:07 -07002148 if (video_init() == -1)
2149 return 0;
wdenkc6097192002-11-03 00:24:07 +00002150
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02002151 if (board_cfb_skip())
2152 return 0;
2153
Simon Glasse9fa1f02015-03-02 12:40:50 -07002154#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2155 have_keyboard = false;
2156#elif defined(CONFIG_OF_CONTROL)
2157 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2158 "u-boot,no-keyboard");
2159#else
2160 have_keyboard = true;
2161#endif
2162 if (have_keyboard) {
2163 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002164#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002165 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002166#endif
Simon Glasse9fa1f02015-03-02 12:40:50 -07002167 }
wdenkc6097192002-11-03 00:24:07 +00002168
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002169 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002170 memset(&console_dev, 0, sizeof(console_dev));
2171 strcpy(console_dev.name, "vga");
Bin Meng6abe4b62015-11-03 23:23:37 -08002172 console_dev.flags = DEV_FLAGS_OUTPUT;
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002173 console_dev.putc = video_putc; /* 'putc' function */
2174 console_dev.puts = video_puts; /* 'puts' function */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002175
2176#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002177 if (have_keyboard && keyboard_ok) {
Simon Glasse9fa1f02015-03-02 12:40:50 -07002178 /* Also init console device */
2179 console_dev.flags |= DEV_FLAGS_INPUT;
2180 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2181 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2182 }
2183#endif
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002184
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002185 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002186 return 0;
2187
2188 /* Return success */
2189 return 1;
wdenkc6097192002-11-03 00:24:07 +00002190}
Stefan Reinauer7870da32012-09-28 15:11:12 +00002191
2192void video_position_cursor(unsigned col, unsigned row)
2193{
2194 console_col = min(col, CONSOLE_COLS - 1);
2195 console_row = min(row, CONSOLE_ROWS - 1);
2196}
2197
2198int video_get_pixel_width(void)
2199{
2200 return VIDEO_VISIBLE_COLS;
2201}
2202
2203int video_get_pixel_height(void)
2204{
2205 return VIDEO_VISIBLE_ROWS;
2206}
2207
2208int video_get_screen_rows(void)
2209{
2210 return CONSOLE_ROWS;
2211}
2212
2213int video_get_screen_columns(void)
2214{
2215 return CONSOLE_COLS;
2216}