blob: ef4984becb48283e5b9aee5e42220dda583b92b1 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8/*
9 * cfb_console.c
10 *
11 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
12 *
13 * At the moment only the 8x16 font is tested and the font fore- and
14 * background color is limited to black/white/gray colors. The Linux
15 * logo can be placed in the upper left corner and additional board
Wolfgang Denk64e40d72011-07-29 09:55:27 +000016 * information strings (that normally goes to serial port) can be drawn.
wdenkc6097192002-11-03 00:24:07 +000017 *
Simon Glass39f615e2015-11-11 10:05:47 -070018 * The console driver can use a keyboard interface for character input
19 * but this is deprecated. Only rk51 uses it.
20 *
21 * Character output goes to a memory-mapped video
wdenkc6097192002-11-03 00:24:07 +000022 * framebuffer with little or big-endian organisation.
23 * With environment setting 'console=serial' the console i/o can be
24 * forced to serial port.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000025 *
26 * The driver uses graphic specific defines/parameters/functions:
27 *
28 * (for SMI LynxE graphic chip)
29 *
30 * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
31 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
32 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
33 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
34 *
35 * Console Parameters are set by graphic drivers global struct:
36 *
37 * VIDEO_VISIBLE_COLS - x resolution
38 * VIDEO_VISIBLE_ROWS - y resolution
39 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
40 * VIDEO_DATA_FORMAT - graphical data format GDF
41 * VIDEO_FB_ADRS - start of video memory
42 *
Wolfgang Denk64e40d72011-07-29 09:55:27 +000043 * VIDEO_KBD_INIT_FCT - init function for keyboard
44 * VIDEO_TSTC_FCT - keyboard_tstc function
45 * VIDEO_GETC_FCT - keyboard_getc function
46 *
Bastian Ruppert1e681f92012-09-13 22:29:01 +000047 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
48 * Use CONFIG_SPLASH_SCREEN_ALIGN with
49 * environment variable "splashpos" to place
50 * the logo on other position. In this case
51 * no CONSOLE_EXTRA_INFO is possible.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000052 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
53 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
54 * strings that normaly goes to serial
55 * port. This define requires a board
56 * specific function:
57 * video_drawstring (VIDEO_INFO_X,
58 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
59 * info);
60 * that fills a info buffer at i=row.
61 * s.a: board/eltec/bab7xx.
62 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
63 * initialized as an output only device.
64 * The Keyboard driver will not be
65 * set-up. This may be used, if you have
66 * no or more than one Keyboard devices
67 * (USB Keyboard, AT Keyboard).
68 *
69 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
70 * character. No blinking is provided.
71 * Uses the macros CURSOR_SET and
72 * CURSOR_OFF.
73 *
74 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
75 * of the graphic chip. Uses the macro
76 * CURSOR_SET. ATTENTION: If booting an
77 * OS, the display driver must disable
78 * the hardware register of the graphic
79 * chip. Otherwise a blinking field is
80 * displayed.
81 */
wdenkc6097192002-11-03 00:24:07 +000082
83#include <common.h>
Simon Glass5692ccf2015-03-02 12:40:50 -070084#include <fdtdec.h>
Andreas Bießmann09c2e902011-07-18 20:24:04 +020085#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +000086#include <malloc.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +000087#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +000088
Wolfgang Denk64e40d72011-07-29 09:55:27 +000089/*
90 * Console device defines with SMI graphic
91 * Any other graphic must change this section
92 */
wdenkc6097192002-11-03 00:24:07 +000093
wdenk4b248f32004-03-14 16:51:43 +000094#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +000095
96#define VIDEO_FB_LITTLE_ENDIAN
97#define VIDEO_HW_RECTFILL
98#define VIDEO_HW_BITBLT
99#endif
100
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000101/*
102 * Defines for the CT69000 driver
103 */
wdenk4b248f32004-03-14 16:51:43 +0000104#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000105
106#define VIDEO_FB_LITTLE_ENDIAN
107#define VIDEO_HW_RECTFILL
108#define VIDEO_HW_BITBLT
109#endif
110
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000111/*
112 * Defines for the SED13806 driver
113 */
wdenka6c7ad22002-12-03 21:28:10 +0000114#ifdef CONFIG_VIDEO_SED13806
wdenka6c7ad22002-12-03 21:28:10 +0000115#define VIDEO_FB_LITTLE_ENDIAN
116#define VIDEO_HW_RECTFILL
117#define VIDEO_HW_BITBLT
118#endif
119
Marek Vasut703c7512014-10-11 18:42:49 +0200120#if defined(CONFIG_VIDEO_MXS) || defined(CONFIG_VIDEO_S3C)
Marek Vasutfb8ddc22013-04-28 09:20:03 +0000121#define VIDEO_FB_16BPP_WORD_SWAP
122#endif
123
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000124/*
125 * Defines for the MB862xx driver
126 */
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100127#ifdef CONFIG_VIDEO_MB862xx
128
129#ifdef CONFIG_VIDEO_CORALP
130#define VIDEO_FB_LITTLE_ENDIAN
131#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200132#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100133#define VIDEO_HW_RECTFILL
134#define VIDEO_HW_BITBLT
135#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200136#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100137
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000138/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000139 * Defines for the i.MX31 driver (mx3fb.c)
140 */
Fabio Estevam695af9a2012-05-31 07:23:56 +0000141#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000142#define VIDEO_FB_16BPP_WORD_SWAP
143#endif
144
145/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000146 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
147 */
wdenkc6097192002-11-03 00:24:07 +0000148#include <video_fb.h>
149
Robert Winklerdd4425e2013-06-17 11:31:29 -0700150#include <splash.h>
151
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000152/*
153 * some Macros
154 */
wdenk4b248f32004-03-14 16:51:43 +0000155#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
156#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
157#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
158#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
159#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000160
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000161/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000162 * Console device
163 */
wdenkc6097192002-11-03 00:24:07 +0000164
165#include <version.h>
166#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200167#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000168#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000169
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500170#if defined(CONFIG_CMD_DATE)
171#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000172#endif
173
Jon Loeliger07d38a12007-07-09 17:30:01 -0500174#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000175#include <watchdog.h>
176#include <bmp_layout.h>
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200177#include <splash.h>
Jon Loeliger07d38a12007-07-09 17:30:01 -0500178#endif
wdenk4b248f32004-03-14 16:51:43 +0000179
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000180/*
181 * Cursor definition:
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000182 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
183 * blinking is provided. Uses the macros CURSOR_SET
184 * and CURSOR_OFF.
185 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
186 * graphic chip. Uses the macro CURSOR_SET.
187 * ATTENTION: If booting an OS, the display driver
188 * must disable the hardware register of the graphic
189 * chip. Otherwise a blinking field is displayed
190 */
Simon Glass7fe09332015-10-18 21:17:18 -0600191#if !defined(CONFIG_VIDEO_SW_CURSOR) && !defined(CONFIG_VIDEO_HW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000192/* no Cursor defined */
193#define CURSOR_ON
194#define CURSOR_OFF
195#define CURSOR_SET
196#endif
197
Simon Glass7fe09332015-10-18 21:17:18 -0600198#if defined(CONFIG_VIDEO_SW_CURSOR)
199#if defined(CONFIG_VIDEO_HW_CURSOR)
200#error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
201 defined
wdenkc6097192002-11-03 00:24:07 +0000202#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000203void console_cursor(int state);
204
Timur Tabi65618632010-08-27 15:45:47 -0500205#define CURSOR_ON console_cursor(1)
206#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000207#define CURSOR_SET video_set_cursor()
Simon Glass7fe09332015-10-18 21:17:18 -0600208#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000209
210#ifdef CONFIG_VIDEO_HW_CURSOR
wdenk4b248f32004-03-14 16:51:43 +0000211#ifdef CURSOR_ON
Simon Glass7fe09332015-10-18 21:17:18 -0600212#error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
213 defined
wdenkc6097192002-11-03 00:24:07 +0000214#endif
215#define CURSOR_ON
216#define CURSOR_OFF
217#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabi65618632010-08-27 15:45:47 -0500218 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000219#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000220
wdenk4b248f32004-03-14 16:51:43 +0000221#ifdef CONFIG_VIDEO_LOGO
222#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000223#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000224#include <bmp_logo_data.h>
wdenk4b248f32004-03-14 16:51:43 +0000225#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
226#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
227#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
228#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenka6c7ad22002-12-03 21:28:10 +0000229
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000230#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000231#define LINUX_LOGO_WIDTH 80
232#define LINUX_LOGO_HEIGHT 80
233#define LINUX_LOGO_COLORS 214
234#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000235#define __initdata
236#include <linux_logo.h>
wdenk4b248f32004-03-14 16:51:43 +0000237#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
238#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
239#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
240#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000241#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000242#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
243#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000244#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000245#define VIDEO_LOGO_WIDTH 0
246#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000247#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000248
wdenk4b248f32004-03-14 16:51:43 +0000249#define VIDEO_COLS VIDEO_VISIBLE_COLS
250#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedec67a8762015-08-04 12:15:39 +0200251#ifndef VIDEO_LINE_LEN
252#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
253#endif
254#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenk4b248f32004-03-14 16:51:43 +0000255#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000256
wdenk4b248f32004-03-14 16:51:43 +0000257#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100258#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000259#else
wdenk4b248f32004-03-14 16:51:43 +0000260#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000261#endif
262
wdenk4b248f32004-03-14 16:51:43 +0000263#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
264#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
265#define CONSOLE_ROW_FIRST (video_console_address)
266#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
267#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
268#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass3c0b6682015-01-01 16:17:57 -0700269
270/* By default we scroll by a single line */
271#ifndef CONFIG_CONSOLE_SCROLL_LINES
272#define CONFIG_CONSOLE_SCROLL_LINES 1
273#endif
wdenkc6097192002-11-03 00:24:07 +0000274
275/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000276#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000277#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
278 ((x) >> 8) \
279 )
280#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
281 (((x) & 0x0000ff00) << 8) | \
282 (((x) & 0x00ff0000) >> 8) | \
283 (((x) & 0xff000000) >> 24) \
284 )
285#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
286 (((x) & 0x0000ff00) >> 8) | \
287 (((x) & 0x00ff0000) << 8) | \
288 (((x) & 0xff000000) >> 8) \
289 )
wdenkc6097192002-11-03 00:24:07 +0000290#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000291#define SWAP16(x) (x)
292#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200293#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000294#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500295#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000296#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100297#endif
wdenkc6097192002-11-03 00:24:07 +0000298#endif
299
wdenkc6097192002-11-03 00:24:07 +0000300#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000301/*
302 * setup a board string: type, speed, etc.
303 *
304 * line_number: location to place info string beside logo
305 * info: buffer for info string
306 */
307extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000308#endif
309
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200310DECLARE_GLOBAL_DATA_PTR;
311
wdenkc6097192002-11-03 00:24:07 +0000312/* Locals */
313static GraphicDevice *pGD; /* Pointer to Graphic array */
314
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000315static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000316static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000317
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100318static int video_logo_height = VIDEO_LOGO_HEIGHT;
319
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000320static int __maybe_unused cursor_state;
321static int __maybe_unused old_col;
322static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000323
Wolfgang Denk57912932011-07-30 12:48:09 +0000324static int console_col; /* cursor col */
325static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000326
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000327static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000328
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200329static int cfb_do_flush_cache;
330
Pali Rohár33a35bb2012-10-19 13:30:09 +0000331#ifdef CONFIG_CFB_CONSOLE_ANSI
332static char ansi_buf[10];
333static int ansi_buf_size;
334static int ansi_colors_need_revert;
335static int ansi_cursor_hidden;
336#endif
337
wdenkc6097192002-11-03 00:24:07 +0000338static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000339 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
340 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
341 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
342 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
343};
wdenkc6097192002-11-03 00:24:07 +0000344
345static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000346 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
347};
wdenkc6097192002-11-03 00:24:07 +0000348
349static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000350 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
351};
wdenkc6097192002-11-03 00:24:07 +0000352
353static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000354 {0x00000000, 0x00000000, 0x00000000},
355 {0x00000000, 0x00000000, 0x00ffffff},
356 {0x00000000, 0x0000ffff, 0xff000000},
357 {0x00000000, 0x0000ffff, 0xffffffff},
358 {0x000000ff, 0xffff0000, 0x00000000},
359 {0x000000ff, 0xffff0000, 0x00ffffff},
360 {0x000000ff, 0xffffffff, 0xff000000},
361 {0x000000ff, 0xffffffff, 0xffffffff},
362 {0xffffff00, 0x00000000, 0x00000000},
363 {0xffffff00, 0x00000000, 0x00ffffff},
364 {0xffffff00, 0x0000ffff, 0xff000000},
365 {0xffffff00, 0x0000ffff, 0xffffffff},
366 {0xffffffff, 0xffff0000, 0x00000000},
367 {0xffffffff, 0xffff0000, 0x00ffffff},
368 {0xffffffff, 0xffffffff, 0xff000000},
369 {0xffffffff, 0xffffffff, 0xffffffff}
370};
wdenkc6097192002-11-03 00:24:07 +0000371
372static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000373 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
374 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
375 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
376 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
377 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
378 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
379 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
380 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
381 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
382 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
383 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
384 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
385 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
386 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
387 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
388 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
389};
wdenkc6097192002-11-03 00:24:07 +0000390
Heiko Schocher2bc4aa52013-08-03 07:22:53 +0200391/*
392 * Implement a weak default function for boards that optionally
393 * need to skip the cfb initialization.
394 */
395__weak int board_cfb_skip(void)
396{
397 /* As default, don't skip cfb init */
398 return 0;
399}
400
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000401static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000402{
wdenk4b248f32004-03-14 16:51:43 +0000403 u8 *cdat, *dest, *dest0;
404 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000405
wdenk4b248f32004-03-14 16:51:43 +0000406 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
407 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000408
wdenk4b248f32004-03-14 16:51:43 +0000409 switch (VIDEO_DATA_FORMAT) {
410 case GDF__8BIT_INDEX:
411 case GDF__8BIT_332RGB:
412 while (count--) {
413 c = *s;
414 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
415 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000416 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000417 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000418
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000419 ((u32 *) dest)[0] =
420 (video_font_draw_table8[bits >> 4] &
421 eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200422
423 if (VIDEO_FONT_WIDTH == 4)
424 continue;
425
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000426 ((u32 *) dest)[1] =
427 (video_font_draw_table8[bits & 15] &
428 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000429 }
430 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
431 s++;
432 }
433 break;
wdenkc6097192002-11-03 00:24:07 +0000434
wdenk4b248f32004-03-14 16:51:43 +0000435 case GDF_15BIT_555RGB:
436 while (count--) {
437 c = *s;
438 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
439 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000440 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000441 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000442
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000443 ((u32 *) dest)[0] =
444 SHORTSWAP32((video_font_draw_table15
445 [bits >> 6] & eorx) ^
446 bgx);
447 ((u32 *) dest)[1] =
448 SHORTSWAP32((video_font_draw_table15
449 [bits >> 4 & 3] & eorx) ^
450 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200451
452 if (VIDEO_FONT_WIDTH == 4)
453 continue;
454
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000455 ((u32 *) dest)[2] =
456 SHORTSWAP32((video_font_draw_table15
457 [bits >> 2 & 3] & eorx) ^
458 bgx);
459 ((u32 *) dest)[3] =
460 SHORTSWAP32((video_font_draw_table15
461 [bits & 3] & eorx) ^
462 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000463 }
464 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
465 s++;
466 }
467 break;
wdenkc6097192002-11-03 00:24:07 +0000468
wdenk4b248f32004-03-14 16:51:43 +0000469 case GDF_16BIT_565RGB:
470 while (count--) {
471 c = *s;
472 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
473 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000474 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000475 u8 bits = *cdat++;
476
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000477 ((u32 *) dest)[0] =
478 SHORTSWAP32((video_font_draw_table16
479 [bits >> 6] & eorx) ^
480 bgx);
481 ((u32 *) dest)[1] =
482 SHORTSWAP32((video_font_draw_table16
483 [bits >> 4 & 3] & eorx) ^
484 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200485
486 if (VIDEO_FONT_WIDTH == 4)
487 continue;
488
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000489 ((u32 *) dest)[2] =
490 SHORTSWAP32((video_font_draw_table16
491 [bits >> 2 & 3] & eorx) ^
492 bgx);
493 ((u32 *) dest)[3] =
494 SHORTSWAP32((video_font_draw_table16
495 [bits & 3] & eorx) ^
496 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000497 }
498 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
499 s++;
500 }
501 break;
502
503 case GDF_32BIT_X888RGB:
504 while (count--) {
505 c = *s;
506 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
507 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000508 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000509 u8 bits = *cdat++;
510
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000511 ((u32 *) dest)[0] =
512 SWAP32((video_font_draw_table32
513 [bits >> 4][0] & eorx) ^ bgx);
514 ((u32 *) dest)[1] =
515 SWAP32((video_font_draw_table32
516 [bits >> 4][1] & eorx) ^ bgx);
517 ((u32 *) dest)[2] =
518 SWAP32((video_font_draw_table32
519 [bits >> 4][2] & eorx) ^ bgx);
520 ((u32 *) dest)[3] =
521 SWAP32((video_font_draw_table32
522 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200523
524
525 if (VIDEO_FONT_WIDTH == 4)
526 continue;
527
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000528 ((u32 *) dest)[4] =
529 SWAP32((video_font_draw_table32
530 [bits & 15][0] & eorx) ^ bgx);
531 ((u32 *) dest)[5] =
532 SWAP32((video_font_draw_table32
533 [bits & 15][1] & eorx) ^ bgx);
534 ((u32 *) dest)[6] =
535 SWAP32((video_font_draw_table32
536 [bits & 15][2] & eorx) ^ bgx);
537 ((u32 *) dest)[7] =
538 SWAP32((video_font_draw_table32
539 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000540 }
541 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
542 s++;
543 }
544 break;
545
546 case GDF_24BIT_888RGB:
547 while (count--) {
548 c = *s;
549 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
550 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000551 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000552 u8 bits = *cdat++;
553
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000554 ((u32 *) dest)[0] =
555 (video_font_draw_table24[bits >> 4][0]
556 & eorx) ^ bgx;
557 ((u32 *) dest)[1] =
558 (video_font_draw_table24[bits >> 4][1]
559 & eorx) ^ bgx;
560 ((u32 *) dest)[2] =
561 (video_font_draw_table24[bits >> 4][2]
562 & eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200563
564 if (VIDEO_FONT_WIDTH == 4)
565 continue;
566
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000567 ((u32 *) dest)[3] =
568 (video_font_draw_table24[bits & 15][0]
569 & eorx) ^ bgx;
570 ((u32 *) dest)[4] =
571 (video_font_draw_table24[bits & 15][1]
572 & eorx) ^ bgx;
573 ((u32 *) dest)[5] =
574 (video_font_draw_table24[bits & 15][2]
575 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000576 }
577 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
578 s++;
579 }
580 break;
wdenk8bde7f72003-06-27 21:31:46 +0000581 }
wdenkc6097192002-11-03 00:24:07 +0000582}
583
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000584static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000585{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000586 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000587}
588
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000589static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000590{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000591 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000592}
593
Simon Glass7fe09332015-10-18 21:17:18 -0600594#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000595static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000596{
Gabe Black03d31fc2011-11-30 13:50:50 +0000597 if (cursor_state)
598 console_cursor(0);
599 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000600}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000601
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000602static void video_invertchar(int xx, int yy)
603{
604 int firstx = xx * VIDEO_PIXEL_SIZE;
605 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
606 int firsty = yy * VIDEO_LINE_LEN;
607 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
608 int x, y;
609 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
610 for (x = firstx; x < lastx; x++) {
611 u8 *dest = (u8 *)(video_fb_address) + x + y;
612 *dest = ~*dest;
613 }
614 }
615}
Gabe Black03d31fc2011-11-30 13:50:50 +0000616
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000617void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000618{
Gabe Black03d31fc2011-11-30 13:50:50 +0000619 if (cursor_state != state) {
620 if (cursor_state) {
621 /* turn off the cursor */
622 video_invertchar(old_col * VIDEO_FONT_WIDTH,
623 old_row * VIDEO_FONT_HEIGHT +
624 video_logo_height);
625 } else {
626 /* turn off the cursor and record where it is */
627 video_invertchar(console_col * VIDEO_FONT_WIDTH,
628 console_row * VIDEO_FONT_HEIGHT +
629 video_logo_height);
630 old_col = console_col;
631 old_row = console_row;
632 }
633 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000634 }
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200635 if (cfb_do_flush_cache)
636 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000637}
638#endif
639
wdenkc6097192002-11-03 00:24:07 +0000640#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000641static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000642{
wdenk4b248f32004-03-14 16:51:43 +0000643 while (c--)
644 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000645}
646#endif
647
wdenkc6097192002-11-03 00:24:07 +0000648#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000649static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000650{
wdenk4b248f32004-03-14 16:51:43 +0000651 while (c--)
652 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000653}
654#endif
655
Pali Rohár90f60a82012-04-28 07:26:44 +0000656static void console_clear_line(int line, int begin, int end)
657{
658#ifdef VIDEO_HW_RECTFILL
659 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
660 VIDEO_FONT_WIDTH * begin, /* dest pos x */
661 video_logo_height +
662 VIDEO_FONT_HEIGHT * line, /* dest pos y */
663 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
664 VIDEO_FONT_HEIGHT, /* frame height */
665 bgx /* fill color */
666 );
667#else
668 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
669 memsetl(CONSOLE_ROW_FIRST +
670 CONSOLE_ROW_SIZE * line, /* offset of row */
671 CONSOLE_ROW_SIZE >> 2, /* length of row */
672 bgx /* fill color */
673 );
674 } else {
675 void *offset;
676 int i, size;
677
678 offset = CONSOLE_ROW_FIRST +
679 CONSOLE_ROW_SIZE * line + /* offset of row */
680 VIDEO_FONT_WIDTH *
681 VIDEO_PIXEL_SIZE * begin; /* offset of col */
682 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
683 size >>= 2; /* length to end for memsetl() */
684 /* fill at col offset of i'th line using bgx as fill color */
685 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
686 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
687 }
688#endif
689}
690
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000691static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000692{
Simon Glass3c0b6682015-01-01 16:17:57 -0700693 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
694 int i;
695
wdenk4b248f32004-03-14 16:51:43 +0000696 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000697
698#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000699 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
700 0, /* source pos x */
701 video_logo_height +
Simon Glass3c0b6682015-01-01 16:17:57 -0700702 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000703 0, /* dest pos x */
704 video_logo_height, /* dest pos y */
705 VIDEO_VISIBLE_COLS, /* frame width */
706 VIDEO_VISIBLE_ROWS
707 - video_logo_height
Simon Glass3c0b6682015-01-01 16:17:57 -0700708 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000709 );
wdenkc6097192002-11-03 00:24:07 +0000710#else
Simon Glass3c0b6682015-01-01 16:17:57 -0700711 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
712 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000713#endif
wdenk4b248f32004-03-14 16:51:43 +0000714 /* clear the last one */
Simon Glass3c0b6682015-01-01 16:17:57 -0700715 for (i = 1; i <= rows; i++)
716 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
717
718 /* Decrement row number */
719 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000720}
721
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000722static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000723{
Timur Tabi65618632010-08-27 15:45:47 -0500724 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000725
wdenk4b248f32004-03-14 16:51:43 +0000726 if (console_col < 0) {
727 console_col = CONSOLE_COLS - 1;
728 console_row--;
729 if (console_row < 0)
730 console_row = 0;
731 }
wdenkc6097192002-11-03 00:24:07 +0000732}
733
Pali Rohár33a35bb2012-10-19 13:30:09 +0000734#ifdef CONFIG_CFB_CONSOLE_ANSI
735
736static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000737{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000738#ifdef VIDEO_HW_RECTFILL
739 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
740 0, /* dest pos x */
741 video_logo_height, /* dest pos y */
742 VIDEO_VISIBLE_COLS, /* frame width */
743 VIDEO_VISIBLE_ROWS, /* frame height */
744 bgx /* fill color */
745 );
746#else
747 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
748#endif
749}
750
751static void console_cursor_fix(void)
752{
753 if (console_row < 0)
754 console_row = 0;
755 if (console_row >= CONSOLE_ROWS)
756 console_row = CONSOLE_ROWS - 1;
757 if (console_col < 0)
758 console_col = 0;
759 if (console_col >= CONSOLE_COLS)
760 console_col = CONSOLE_COLS - 1;
761}
762
763static void console_cursor_up(int n)
764{
765 console_row -= n;
766 console_cursor_fix();
767}
768
769static void console_cursor_down(int n)
770{
771 console_row += n;
772 console_cursor_fix();
773}
774
775static void console_cursor_left(int n)
776{
777 console_col -= n;
778 console_cursor_fix();
779}
780
781static void console_cursor_right(int n)
782{
783 console_col += n;
784 console_cursor_fix();
785}
786
787static void console_cursor_set_position(int row, int col)
788{
789 if (console_row != -1)
790 console_row = row;
791 if (console_col != -1)
792 console_col = col;
793 console_cursor_fix();
794}
795
796static void console_previousline(int n)
797{
798 /* FIXME: also scroll terminal ? */
799 console_row -= n;
800 console_cursor_fix();
801}
802
803static void console_swap_colors(void)
804{
805 eorx = fgx;
806 fgx = bgx;
807 bgx = eorx;
808 eorx = fgx ^ bgx;
809}
810
811static inline int console_cursor_is_visible(void)
812{
813 return !ansi_cursor_hidden;
814}
815#else
816static inline int console_cursor_is_visible(void)
817{
818 return 1;
819}
820#endif
821
822static void console_newline(int n)
823{
824 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000825 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000826
wdenk4b248f32004-03-14 16:51:43 +0000827 /* Check if we need to scroll the terminal */
828 if (console_row >= CONSOLE_ROWS) {
829 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000830 console_scrollup();
wdenk4b248f32004-03-14 16:51:43 +0000831 }
wdenkc6097192002-11-03 00:24:07 +0000832}
833
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000834static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100835{
Timur Tabi65618632010-08-27 15:45:47 -0500836 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100837}
838
Pali Rohár33a35bb2012-10-19 13:30:09 +0000839static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000840{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100841 static int nl = 1;
842
Pali Rohár33a35bb2012-10-19 13:30:09 +0000843 if (console_cursor_is_visible())
844 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000845
wdenk4b248f32004-03-14 16:51:43 +0000846 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100847 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000848 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000849 break;
wdenkc6097192002-11-03 00:24:07 +0000850
wdenk4b248f32004-03-14 16:51:43 +0000851 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100852 if (console_col || (!console_col && nl))
Pali Rohár33a35bb2012-10-19 13:30:09 +0000853 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100854 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000855 break;
wdenkc6097192002-11-03 00:24:07 +0000856
wdenk4b248f32004-03-14 16:51:43 +0000857 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500858 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000859 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000860
wdenk4b248f32004-03-14 16:51:43 +0000861 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000862 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000863 break;
wdenkc6097192002-11-03 00:24:07 +0000864
wdenk4b248f32004-03-14 16:51:43 +0000865 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000866 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000867 break;
wdenkc6097192002-11-03 00:24:07 +0000868
Pali Rohár24fe06c2012-04-28 07:26:47 +0000869 case 7: /* bell */
870 break; /* ignored */
871
wdenk4b248f32004-03-14 16:51:43 +0000872 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000873 video_putchar(console_col * VIDEO_FONT_WIDTH,
874 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000875 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000876
wdenk4b248f32004-03-14 16:51:43 +0000877 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100878 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000879 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100880 nl = 0;
881 }
wdenk4b248f32004-03-14 16:51:43 +0000882 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000883
884 if (console_cursor_is_visible())
885 CURSOR_SET;
886}
887
Jeroen Hofstee654f8d02014-10-08 22:57:44 +0200888static void video_putc(struct stdio_dev *dev, const char c)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000889{
890#ifdef CONFIG_CFB_CONSOLE_ANSI
891 int i;
892
893 if (c == 27) {
894 for (i = 0; i < ansi_buf_size; ++i)
895 parse_putc(ansi_buf[i]);
896 ansi_buf[0] = 27;
897 ansi_buf_size = 1;
898 return;
899 }
900
901 if (ansi_buf_size > 0) {
902 /*
903 * 0 - ESC
904 * 1 - [
905 * 2 - num1
906 * 3 - ..
907 * 4 - ;
908 * 5 - num2
909 * 6 - ..
910 * - cchar
911 */
912 int next = 0;
913
914 int flush = 0;
915 int fail = 0;
916
917 int num1 = 0;
918 int num2 = 0;
919 int cchar = 0;
920
921 ansi_buf[ansi_buf_size++] = c;
922
923 if (ansi_buf_size >= sizeof(ansi_buf))
924 fail = 1;
925
926 for (i = 0; i < ansi_buf_size; ++i) {
927 if (fail)
928 break;
929
930 switch (next) {
931 case 0:
932 if (ansi_buf[i] == 27)
933 next = 1;
934 else
935 fail = 1;
936 break;
937
938 case 1:
939 if (ansi_buf[i] == '[')
940 next = 2;
941 else
942 fail = 1;
943 break;
944
945 case 2:
946 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
947 num1 = ansi_buf[i]-'0';
948 next = 3;
949 } else if (ansi_buf[i] != '?') {
950 --i;
951 num1 = 1;
952 next = 4;
953 }
954 break;
955
956 case 3:
957 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
958 num1 *= 10;
959 num1 += ansi_buf[i]-'0';
960 } else {
961 --i;
962 next = 4;
963 }
964 break;
965
966 case 4:
967 if (ansi_buf[i] != ';') {
968 --i;
969 next = 7;
970 } else
971 next = 5;
972 break;
973
974 case 5:
975 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
976 num2 = ansi_buf[i]-'0';
977 next = 6;
978 } else
979 fail = 1;
980 break;
981
982 case 6:
983 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
984 num2 *= 10;
985 num2 += ansi_buf[i]-'0';
986 } else {
987 --i;
988 next = 7;
989 }
990 break;
991
992 case 7:
993 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
994 || ansi_buf[i] == 'J'
995 || ansi_buf[i] == 'K'
996 || ansi_buf[i] == 'h'
997 || ansi_buf[i] == 'l'
998 || ansi_buf[i] == 'm') {
999 cchar = ansi_buf[i];
1000 flush = 1;
1001 } else
1002 fail = 1;
1003 break;
1004 }
1005 }
1006
1007 if (fail) {
1008 for (i = 0; i < ansi_buf_size; ++i)
1009 parse_putc(ansi_buf[i]);
1010 ansi_buf_size = 0;
1011 return;
1012 }
1013
1014 if (flush) {
1015 if (!ansi_cursor_hidden)
1016 CURSOR_OFF;
1017 ansi_buf_size = 0;
1018 switch (cchar) {
1019 case 'A':
1020 /* move cursor num1 rows up */
1021 console_cursor_up(num1);
1022 break;
1023 case 'B':
1024 /* move cursor num1 rows down */
1025 console_cursor_down(num1);
1026 break;
1027 case 'C':
1028 /* move cursor num1 columns forward */
1029 console_cursor_right(num1);
1030 break;
1031 case 'D':
1032 /* move cursor num1 columns back */
1033 console_cursor_left(num1);
1034 break;
1035 case 'E':
1036 /* move cursor num1 rows up at begin of row */
1037 console_previousline(num1);
1038 break;
1039 case 'F':
1040 /* move cursor num1 rows down at begin of row */
1041 console_newline(num1);
1042 break;
1043 case 'G':
1044 /* move cursor to column num1 */
1045 console_cursor_set_position(-1, num1-1);
1046 break;
1047 case 'H':
1048 /* move cursor to row num1, column num2 */
1049 console_cursor_set_position(num1-1, num2-1);
1050 break;
1051 case 'J':
1052 /* clear console and move cursor to 0, 0 */
1053 console_clear();
1054 console_cursor_set_position(0, 0);
1055 break;
1056 case 'K':
1057 /* clear line */
1058 if (num1 == 0)
1059 console_clear_line(console_row,
1060 console_col,
1061 CONSOLE_COLS-1);
1062 else if (num1 == 1)
1063 console_clear_line(console_row,
1064 0, console_col);
1065 else
1066 console_clear_line(console_row,
1067 0, CONSOLE_COLS-1);
1068 break;
1069 case 'h':
1070 ansi_cursor_hidden = 0;
1071 break;
1072 case 'l':
1073 ansi_cursor_hidden = 1;
1074 break;
1075 case 'm':
1076 if (num1 == 0) { /* reset swapped colors */
1077 if (ansi_colors_need_revert) {
1078 console_swap_colors();
1079 ansi_colors_need_revert = 0;
1080 }
1081 } else if (num1 == 7) { /* once swap colors */
1082 if (!ansi_colors_need_revert) {
1083 console_swap_colors();
1084 ansi_colors_need_revert = 1;
1085 }
1086 }
1087 break;
1088 }
1089 if (!ansi_cursor_hidden)
1090 CURSOR_SET;
1091 }
1092 } else {
1093 parse_putc(c);
1094 }
1095#else
1096 parse_putc(c);
1097#endif
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001098 if (cfb_do_flush_cache)
1099 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabi65618632010-08-27 15:45:47 -05001100}
wdenkc6097192002-11-03 00:24:07 +00001101
Jeroen Hofstee654f8d02014-10-08 22:57:44 +02001102static void video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001103{
Soeren Mochd37e96e2014-10-24 16:33:30 +02001104 int flush = cfb_do_flush_cache;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001105 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +00001106
Soeren Mochd37e96e2014-10-24 16:33:30 +02001107 /* temporarily disable cache flush */
1108 cfb_do_flush_cache = 0;
1109
wdenk4b248f32004-03-14 16:51:43 +00001110 while (count--)
Simon Glass709ea542014-07-23 06:54:59 -06001111 video_putc(dev, *s++);
Soeren Mochd37e96e2014-10-24 16:33:30 +02001112
1113 if (flush) {
1114 cfb_do_flush_cache = flush;
1115 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1116 }
wdenkc6097192002-11-03 00:24:07 +00001117}
1118
Anatolij Gustschin10543822010-05-01 22:21:09 +02001119/*
1120 * Do not enforce drivers (or board code) to provide empty
1121 * video_set_lut() if they do not support 8 bpp format.
1122 * Implement weak default function instead.
1123 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02001124__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001125 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +02001126{
1127}
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001128
Jon Loeliger07d38a12007-07-09 17:30:01 -05001129#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +00001130
1131#define FILL_8BIT_332RGB(r,g,b) { \
1132 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1133 fb ++; \
1134}
1135
1136#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001137 *(unsigned short *)fb = \
1138 SWAP16((unsigned short)(((r>>3)<<10) | \
1139 ((g>>3)<<5) | \
1140 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001141 fb += 2; \
1142}
1143
1144#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001145 *(unsigned short *)fb = \
1146 SWAP16((unsigned short)((((r)>>3)<<11)| \
1147 (((g)>>2)<<5) | \
1148 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001149 fb += 2; \
1150}
1151
1152#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001153 *(unsigned long *)fb = \
1154 SWAP32((unsigned long)(((r<<16) | \
1155 (g<<8) | \
1156 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001157 fb += 4; \
1158}
1159
1160#ifdef VIDEO_FB_LITTLE_ENDIAN
1161#define FILL_24BIT_888RGB(r,g,b) { \
1162 fb[0] = b; \
1163 fb[1] = g; \
1164 fb[2] = r; \
1165 fb += 3; \
1166}
1167#else
1168#define FILL_24BIT_888RGB(r,g,b) { \
1169 fb[0] = r; \
1170 fb[1] = g; \
1171 fb[2] = b; \
1172 fb += 3; \
1173}
1174#endif
1175
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001176#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001177static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001178{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001179 ushort *dst = (ushort *) fb;
1180 ushort color = (ushort) (((r >> 3) << 10) |
1181 ((g >> 3) << 5) |
1182 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001183 if (x & 1)
1184 *(--dst) = color;
1185 else
1186 *(++dst) = color;
1187}
1188#endif
wdenk4b248f32004-03-14 16:51:43 +00001189
1190/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001191 * RLE8 bitmap support
1192 */
1193
1194#ifdef CONFIG_VIDEO_BMP_RLE8
1195/* Pre-calculated color table entry */
1196struct palette {
1197 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001198 unsigned short w; /* word */
1199 unsigned int dw; /* double word */
1200 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001201};
1202
1203/*
1204 * Helper to draw encoded/unencoded run.
1205 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001206static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1207 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001208{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001209 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001210 int *off;
1211 int enc_off = 1;
1212 int i;
1213
1214 /*
1215 * Setup offset of the color index in the bitmap.
1216 * Color index of encoded run is at offset 1.
1217 */
1218 off = enc ? &enc_off : &i;
1219
1220 switch (VIDEO_DATA_FORMAT) {
1221 case GDF__8BIT_INDEX:
1222 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001223 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001224 break;
1225 case GDF_15BIT_555RGB:
1226 case GDF_16BIT_565RGB:
1227 /* differences handled while pre-calculating palette */
1228 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001229 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001230 addr += 2;
1231 }
1232 break;
1233 case GDF_32BIT_X888RGB:
1234 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001235 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001236 addr += 4;
1237 }
1238 break;
1239 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001240 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001241}
1242
Simon Glass1c3dbe52015-05-13 07:02:27 -06001243static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001244 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001245{
1246 unsigned char *bm;
1247 unsigned char *fbp;
1248 unsigned int cnt, runlen;
1249 int decode = 1;
1250 int x, y, bpp, i, ncolors;
1251 struct palette p[256];
Simon Glass1c3dbe52015-05-13 07:02:27 -06001252 struct bmp_color_table_entry cte;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001253 int green_shift, red_off;
Hans de Goedec67a8762015-08-04 12:15:39 +02001254 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001255 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001256
1257 x = 0;
1258 y = __le32_to_cpu(img->header.height) - 1;
1259 ncolors = __le32_to_cpu(img->header.colors_used);
1260 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001261 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001262 (y + yoff) * VIDEO_LINE_LEN +
1263 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001264
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001265 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001266
1267 /* pre-calculate and setup palette */
1268 switch (VIDEO_DATA_FORMAT) {
1269 case GDF__8BIT_INDEX:
1270 for (i = 0; i < ncolors; i++) {
1271 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001272 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001273 }
1274 break;
1275 case GDF_15BIT_555RGB:
1276 case GDF_16BIT_565RGB:
1277 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1278 green_shift = 3;
1279 red_off = 10;
1280 } else {
1281 green_shift = 2;
1282 red_off = 11;
1283 }
1284 for (i = 0; i < ncolors; i++) {
1285 cte = img->color_table[i];
1286 p[i].ce.w = SWAP16((unsigned short)
1287 (((cte.red >> 3) << red_off) |
1288 ((cte.green >> green_shift) << 5) |
1289 cte.blue >> 3));
1290 }
1291 break;
1292 case GDF_32BIT_X888RGB:
1293 for (i = 0; i < ncolors; i++) {
1294 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001295 p[i].ce.dw = SWAP32((cte.red << 16) |
1296 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001297 cte.blue);
1298 }
1299 break;
1300 default:
1301 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001302 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001303 return -1;
1304 }
1305
1306 while (decode) {
1307 switch (bm[0]) {
1308 case 0:
1309 switch (bm[1]) {
1310 case 0:
1311 /* scan line end marker */
1312 bm += 2;
1313 x = 0;
1314 y--;
1315 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001316 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001317 (y + yoff) * VIDEO_LINE_LEN +
1318 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001319 continue;
1320 case 1:
1321 /* end of bitmap data marker */
1322 decode = 0;
1323 break;
1324 case 2:
1325 /* run offset marker */
1326 x += bm[2];
1327 y -= bm[3];
1328 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001329 ((unsigned int) video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001330 (y + yoff) * VIDEO_LINE_LEN +
1331 xoff * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001332 bm += 4;
1333 break;
1334 default:
1335 /* unencoded run */
1336 cnt = bm[1];
1337 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001338 pixels += cnt;
1339 if (pixels > limit)
1340 goto error;
1341
Anatolij Gustschind5011762010-03-15 14:50:25 +01001342 bm += 2;
1343 if (y < height) {
1344 if (x >= width) {
1345 x += runlen;
1346 goto next_run;
1347 }
1348 if (x + runlen > width)
1349 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001350 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001351 x += runlen;
1352 }
1353next_run:
1354 bm += runlen;
1355 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001356 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001357 }
1358 break;
1359 default:
1360 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001361 cnt = bm[0];
1362 runlen = cnt;
1363 pixels += cnt;
1364 if (pixels > limit)
1365 goto error;
1366
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001367 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001368 if (x >= width) {
1369 x += runlen;
1370 bm += 2;
1371 continue;
1372 }
1373 if (x + runlen > width)
1374 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001375 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001376 x += runlen;
1377 }
1378 bm += 2;
1379 break;
1380 }
1381 }
1382 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001383error:
1384 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1385 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001386}
1387#endif
1388
1389/*
wdenk4b248f32004-03-14 16:51:43 +00001390 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001391 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001392int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001393{
1394 ushort xcount, ycount;
1395 uchar *fb;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001396 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenk4b248f32004-03-14 16:51:43 +00001397 uchar *bmap;
1398 ushort padded_line;
1399 unsigned long width, height, bpp;
1400 unsigned colors;
1401 unsigned long compression;
Simon Glass1c3dbe52015-05-13 07:02:27 -06001402 struct bmp_color_table_entry cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001403
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001404#ifdef CONFIG_VIDEO_BMP_GZIP
1405 unsigned char *dst = NULL;
1406 ulong len;
1407#endif
wdenk4b248f32004-03-14 16:51:43 +00001408
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001409 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001410
1411 if (!((bmp->header.signature[0] == 'B') &&
1412 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001413
1414#ifdef CONFIG_VIDEO_BMP_GZIP
1415 /*
1416 * Could be a gzipped bmp image, try to decrompress...
1417 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001418 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1419 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001420 if (dst == NULL) {
1421 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001422 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001423 }
Eric Nelson5ca05c82014-03-08 07:55:52 -07001424 /*
1425 * NB: we need to force offset of +2
1426 * See doc/README.displaying-bmps
1427 */
1428 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001429 (uchar *) bmp_image,
1430 &len) != 0) {
1431 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1432 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001433 free(dst);
1434 return 1;
1435 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001436 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001437 printf("Image could be truncated "
1438 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001439 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001440
1441 /*
1442 * Set addr to decompressed image
1443 */
Simon Glass1c3dbe52015-05-13 07:02:27 -06001444 bmp = (struct bmp_image *)(dst+2);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001445
1446 if (!((bmp->header.signature[0] == 'B') &&
1447 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001448 printf("Error: no valid bmp.gz image at %lx\n",
1449 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001450 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001451 return 1;
1452 }
1453#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001454 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001455 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001456#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001457 }
1458
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001459 width = le32_to_cpu(bmp->header.width);
1460 height = le32_to_cpu(bmp->header.height);
1461 bpp = le16_to_cpu(bmp->header.bit_count);
1462 colors = le32_to_cpu(bmp->header.colors_used);
1463 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001464
Marek Vasut68da5b12011-10-21 14:17:04 +00001465 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001466 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001467
Anatolij Gustschind5011762010-03-15 14:50:25 +01001468 if (compression != BMP_BI_RGB
1469#ifdef CONFIG_VIDEO_BMP_RLE8
1470 && compression != BMP_BI_RLE8
1471#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001472 ) {
1473 printf("Error: compression type %ld not supported\n",
1474 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001475#ifdef CONFIG_VIDEO_BMP_GZIP
1476 if (dst)
1477 free(dst);
1478#endif
wdenk4b248f32004-03-14 16:51:43 +00001479 return 1;
1480 }
1481
1482 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1483
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001484#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1485 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001486 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001487 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001488 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001489
1490 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001491 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001492 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001493 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001494#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1495
Matthias Weisseracf3baa2013-02-15 03:35:12 +00001496 /*
1497 * Just ignore elements which are completely beyond screen
1498 * dimensions.
1499 */
1500 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1501 return 0;
1502
wdenk4b248f32004-03-14 16:51:43 +00001503 if ((x + width) > VIDEO_VISIBLE_COLS)
1504 width = VIDEO_VISIBLE_COLS - x;
1505 if ((y + height) > VIDEO_VISIBLE_ROWS)
1506 height = VIDEO_VISIBLE_ROWS - y;
1507
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001508 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001509 fb = (uchar *) (video_fb_address +
Hans de Goedec67a8762015-08-04 12:15:39 +02001510 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenk4b248f32004-03-14 16:51:43 +00001511 x * VIDEO_PIXEL_SIZE);
1512
Anatolij Gustschind5011762010-03-15 14:50:25 +01001513#ifdef CONFIG_VIDEO_BMP_RLE8
1514 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001515 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001516 }
1517#endif
1518
Timur Tabi68f66182010-08-23 16:58:00 -05001519 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001520 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001521 case 4:
1522 padded_line -= width / 2;
1523 ycount = height;
1524
1525 switch (VIDEO_DATA_FORMAT) {
1526 case GDF_32BIT_X888RGB:
1527 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001528 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001529 /*
1530 * Don't assume that 'width' is an
1531 * even number
1532 */
1533 for (xcount = 0; xcount < width; xcount++) {
1534 uchar idx;
1535
1536 if (xcount & 1) {
1537 idx = *bmap & 0xF;
1538 bmap++;
1539 } else
1540 idx = *bmap >> 4;
1541 cte = bmp->color_table[idx];
1542 FILL_32BIT_X888RGB(cte.red, cte.green,
1543 cte.blue);
1544 }
1545 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001546 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001547 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001548 }
1549 break;
1550 default:
1551 puts("4bpp bitmap unsupported with current "
1552 "video mode\n");
1553 break;
1554 }
1555 break;
1556
wdenk4b248f32004-03-14 16:51:43 +00001557 case 8:
1558 padded_line -= width;
1559 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001560 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001561 for (xcount = 0; xcount < colors; ++xcount) {
1562 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001563 video_set_lut(xcount, cte.red, cte.green,
1564 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001565 }
1566 }
1567 ycount = height;
1568 switch (VIDEO_DATA_FORMAT) {
1569 case GDF__8BIT_INDEX:
1570 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001571 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001572 xcount = width;
1573 while (xcount--) {
1574 *fb++ = *bmap++;
1575 }
1576 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001577 fb -= VIDEO_LINE_LEN + width *
1578 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001579 }
1580 break;
1581 case GDF__8BIT_332RGB:
1582 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001583 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001584 xcount = width;
1585 while (xcount--) {
1586 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001587 FILL_8BIT_332RGB(cte.red, cte.green,
1588 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001589 }
1590 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001591 fb -= VIDEO_LINE_LEN + width *
1592 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001593 }
1594 break;
1595 case GDF_15BIT_555RGB:
1596 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001597#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1598 int xpos = x;
1599#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001600 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001601 xcount = width;
1602 while (xcount--) {
1603 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001604#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001605 fill_555rgb_pswap(fb, xpos++, cte.red,
1606 cte.green,
1607 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001608 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001609#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001610 FILL_15BIT_555RGB(cte.red, cte.green,
1611 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001612#endif
wdenk4b248f32004-03-14 16:51:43 +00001613 }
1614 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001615 fb -= VIDEO_LINE_LEN + width *
1616 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001617 }
1618 break;
1619 case GDF_16BIT_565RGB:
1620 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001621 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001622 xcount = width;
1623 while (xcount--) {
1624 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001625 FILL_16BIT_565RGB(cte.red, cte.green,
1626 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001627 }
1628 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001629 fb -= VIDEO_LINE_LEN + width *
1630 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001631 }
1632 break;
1633 case GDF_32BIT_X888RGB:
1634 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001635 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001636 xcount = width;
1637 while (xcount--) {
1638 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001639 FILL_32BIT_X888RGB(cte.red, cte.green,
1640 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001641 }
1642 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001643 fb -= VIDEO_LINE_LEN + width *
1644 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001645 }
1646 break;
1647 case GDF_24BIT_888RGB:
1648 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001649 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001650 xcount = width;
1651 while (xcount--) {
1652 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001653 FILL_24BIT_888RGB(cte.red, cte.green,
1654 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001655 }
1656 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001657 fb -= VIDEO_LINE_LEN + width *
1658 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001659 }
1660 break;
1661 }
1662 break;
1663 case 24:
1664 padded_line -= 3 * width;
1665 ycount = height;
1666 switch (VIDEO_DATA_FORMAT) {
1667 case GDF__8BIT_332RGB:
1668 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001669 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001670 xcount = width;
1671 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001672 FILL_8BIT_332RGB(bmap[2], bmap[1],
1673 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001674 bmap += 3;
1675 }
1676 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001677 fb -= VIDEO_LINE_LEN + width *
1678 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001679 }
1680 break;
1681 case GDF_15BIT_555RGB:
1682 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001683#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1684 int xpos = x;
1685#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001686 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001687 xcount = width;
1688 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001689#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001690 fill_555rgb_pswap(fb, xpos++, bmap[2],
1691 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001692 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001693#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001694 FILL_15BIT_555RGB(bmap[2], bmap[1],
1695 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001696#endif
wdenk4b248f32004-03-14 16:51:43 +00001697 bmap += 3;
1698 }
1699 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001700 fb -= VIDEO_LINE_LEN + width *
1701 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001702 }
1703 break;
1704 case GDF_16BIT_565RGB:
1705 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001706 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001707 xcount = width;
1708 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001709 FILL_16BIT_565RGB(bmap[2], bmap[1],
1710 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001711 bmap += 3;
1712 }
1713 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001714 fb -= VIDEO_LINE_LEN + width *
1715 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001716 }
1717 break;
1718 case GDF_32BIT_X888RGB:
1719 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001720 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001721 xcount = width;
1722 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001723 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1724 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001725 bmap += 3;
1726 }
1727 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001728 fb -= VIDEO_LINE_LEN + width *
1729 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001730 }
1731 break;
1732 case GDF_24BIT_888RGB:
1733 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001734 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001735 xcount = width;
1736 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001737 FILL_24BIT_888RGB(bmap[2], bmap[1],
1738 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001739 bmap += 3;
1740 }
1741 bmap += padded_line;
Hans de Goedec67a8762015-08-04 12:15:39 +02001742 fb -= VIDEO_LINE_LEN + width *
1743 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001744 }
1745 break;
1746 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001747 printf("Error: 24 bits/pixel bitmap incompatible "
1748 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001749 break;
1750 }
1751 break;
1752 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001753 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1754 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001755 break;
1756 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001757
1758#ifdef CONFIG_VIDEO_BMP_GZIP
1759 if (dst) {
1760 free(dst);
1761 }
1762#endif
1763
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001764 if (cfb_do_flush_cache)
1765 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk4b248f32004-03-14 16:51:43 +00001766 return (0);
1767}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001768#endif
wdenk4b248f32004-03-14 16:51:43 +00001769
wdenk4b248f32004-03-14 16:51:43 +00001770
wdenkc6097192002-11-03 00:24:07 +00001771#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001772static int video_logo_xpos;
1773static int video_logo_ypos;
1774
Hans de Goedec4c9e812015-08-04 12:21:40 +02001775static void plot_logo_or_black(void *screen, int x, int y, int black);
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001776
Hans de Goedec4c9e812015-08-04 12:21:40 +02001777static void logo_plot(void *screen, int x, int y)
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001778{
Hans de Goedec4c9e812015-08-04 12:21:40 +02001779 plot_logo_or_black(screen, x, y, 0);
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001780}
1781
1782static void logo_black(void)
1783{
Hans de Goedec4c9e812015-08-04 12:21:40 +02001784 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001785 1);
1786}
1787
1788static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1789{
1790 if (argc != 1)
1791 return cmd_usage(cmdtp);
1792
1793 logo_black();
1794 return 0;
1795}
1796
1797U_BOOT_CMD(
1798 clrlogo, 1, 0, do_clrlogo,
1799 "fill the boot logo area with black",
1800 " "
1801 );
1802
Hans de Goedec4c9e812015-08-04 12:21:40 +02001803static void plot_logo_or_black(void *screen, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001804{
wdenkc6097192002-11-03 00:24:07 +00001805
wdenk4b248f32004-03-14 16:51:43 +00001806 int xcount, i;
Hans de Goedec67a8762015-08-04 12:15:39 +02001807 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001808 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001809 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1810 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001811 unsigned char *dest;
1812
1813#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1814 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001815 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001816 else if (x < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001817 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001818
1819 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001820 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001821 else if (y < 0)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001822 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001823#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1824
Hans de Goedec67a8762015-08-04 12:15:39 +02001825 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001826
1827#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001828 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001829
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001830 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001831 logo_red = malloc(BMP_LOGO_COLORS);
1832 logo_green = malloc(BMP_LOGO_COLORS);
1833 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001834 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001835 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1836 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1837 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1838 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1839 }
wdenka6c7ad22002-12-03 21:28:10 +00001840#else
wdenk4b248f32004-03-14 16:51:43 +00001841 source = linux_logo;
1842 logo_red = linux_logo_red;
1843 logo_green = linux_logo_green;
1844 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001845#endif
wdenk8bde7f72003-06-27 21:31:46 +00001846
wdenk4b248f32004-03-14 16:51:43 +00001847 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1848 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001849 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1850 logo_red[i], logo_green[i],
1851 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001852 }
wdenk8bde7f72003-06-27 21:31:46 +00001853 }
wdenkc6097192002-11-03 00:24:07 +00001854
wdenk4b248f32004-03-14 16:51:43 +00001855 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001856#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1857 int xpos = x;
1858#endif
wdenk4b248f32004-03-14 16:51:43 +00001859 xcount = VIDEO_LOGO_WIDTH;
1860 while (xcount--) {
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001861 if (black) {
1862 r = 0x00;
1863 g = 0x00;
1864 b = 0x00;
1865 } else {
1866 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1867 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1868 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1869 }
wdenk8bde7f72003-06-27 21:31:46 +00001870
wdenk4b248f32004-03-14 16:51:43 +00001871 switch (VIDEO_DATA_FORMAT) {
1872 case GDF__8BIT_INDEX:
1873 *dest = *source;
1874 break;
1875 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001876 *dest = ((r >> 5) << 5) |
1877 ((g >> 5) << 2) |
1878 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001879 break;
1880 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001881#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001882 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001883#else
wdenk4b248f32004-03-14 16:51:43 +00001884 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001885 SWAP16((unsigned short) (
1886 ((r >> 3) << 10) |
1887 ((g >> 3) << 5) |
1888 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001889#endif
wdenk4b248f32004-03-14 16:51:43 +00001890 break;
1891 case GDF_16BIT_565RGB:
1892 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001893 SWAP16((unsigned short) (
1894 ((r >> 3) << 11) |
1895 ((g >> 2) << 5) |
1896 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001897 break;
1898 case GDF_32BIT_X888RGB:
1899 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001900 SWAP32((unsigned long) (
1901 (r << 16) |
1902 (g << 8) |
1903 b));
wdenk4b248f32004-03-14 16:51:43 +00001904 break;
1905 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001906#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001907 dest[0] = b;
1908 dest[1] = g;
1909 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001910#else
wdenk4b248f32004-03-14 16:51:43 +00001911 dest[0] = r;
1912 dest[1] = g;
1913 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001914#endif
wdenk4b248f32004-03-14 16:51:43 +00001915 break;
1916 }
1917 source++;
1918 dest += VIDEO_PIXEL_SIZE;
1919 }
1920 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001921 }
wdenka6c7ad22002-12-03 21:28:10 +00001922#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001923 free(logo_red);
1924 free(logo_green);
1925 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001926#endif
wdenkc6097192002-11-03 00:24:07 +00001927}
1928
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001929static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001930{
wdenk4b248f32004-03-14 16:51:43 +00001931 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001932 int space, len;
1933 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001934 __maybe_unused ulong addr;
1935 __maybe_unused char *s;
wdenkc6097192002-11-03 00:24:07 +00001936
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001937 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001938
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001939#ifdef CONFIG_SPLASH_SCREEN
1940 s = getenv("splashimage");
1941 if (s != NULL) {
Robert Winklerdd4425e2013-06-17 11:31:29 -07001942 splash_screen_prepare();
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001943 addr = simple_strtoul(s, NULL, 16);
1944
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001945 if (video_display_bitmap(addr,
1946 video_logo_xpos,
1947 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001948 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00001949 return ((void *) (video_fb_address));
1950 }
1951 }
1952#endif /* CONFIG_SPLASH_SCREEN */
1953
Hans de Goedec4c9e812015-08-04 12:21:40 +02001954 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001955
1956#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1957 /*
1958 * when using splashpos for video_logo, skip any info
1959 * output on video console if the logo is not at 0,0
1960 */
1961 if (video_logo_xpos || video_logo_ypos) {
1962 /*
1963 * video_logo_height is used in text and cursor offset
1964 * calculations. Since the console is below the logo,
1965 * we need to adjust the logo height
1966 */
1967 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadab4141192014-11-07 03:03:31 +09001968 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001969 VIDEO_LOGO_HEIGHT) / 2);
1970 else if (video_logo_ypos > 0)
1971 video_logo_height += video_logo_ypos;
1972
1973 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1974 }
1975#endif
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02001976 if (board_cfb_skip())
1977 return 0;
wdenk4b248f32004-03-14 16:51:43 +00001978
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001979 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001980
1981 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1982 len = strlen(info);
1983
1984 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001985 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1986 (uchar *) info, space);
1987 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1988 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1989 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02001990 y_off = 1;
1991 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001992 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001993
1994#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00001995 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001996 int i, n =
1997 ((video_logo_height -
1998 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001999
wdenk4b248f32004-03-14 16:51:43 +00002000 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002001 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002002 if (!*info)
2003 continue;
2004
2005 len = strlen(info);
2006 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002007 video_drawchars(VIDEO_INFO_X,
2008 VIDEO_INFO_Y +
2009 (i + y_off) *
2010 VIDEO_FONT_HEIGHT,
2011 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002012 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002013 video_drawchars(VIDEO_INFO_X +
2014 VIDEO_FONT_WIDTH,
2015 VIDEO_INFO_Y +
2016 (i + y_off) *
2017 VIDEO_FONT_HEIGHT,
2018 (uchar *) info + space,
2019 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002020 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002021 video_drawstring(VIDEO_INFO_X,
2022 VIDEO_INFO_Y +
2023 (i + y_off) *
2024 VIDEO_FONT_HEIGHT,
2025 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002026 }
wdenk4b248f32004-03-14 16:51:43 +00002027 }
2028 }
wdenkc6097192002-11-03 00:24:07 +00002029#endif
2030
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002031 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002032}
2033#endif
2034
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002035static int cfb_fb_is_in_dram(void)
2036{
2037 bd_t *bd = gd->bd;
2038#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2039defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2040 ulong start, end;
2041 int i;
2042
2043 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2044 start = bd->bi_dram[i].start;
2045 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2046 if ((ulong)video_fb_address >= start &&
2047 (ulong)video_fb_address < end)
2048 return 1;
2049 }
2050#else
2051 if ((ulong)video_fb_address >= bd->bi_memstart &&
2052 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2053 return 1;
2054#endif
2055 return 0;
2056}
2057
Heiko Schocher45ae2542013-10-22 11:06:06 +02002058void video_clear(void)
2059{
2060 if (!video_fb_address)
2061 return;
2062#ifdef VIDEO_HW_RECTFILL
2063 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2064 0, /* dest pos x */
2065 0, /* dest pos y */
2066 VIDEO_VISIBLE_COLS, /* frame width */
2067 VIDEO_VISIBLE_ROWS, /* frame height */
2068 bgx /* fill color */
2069 );
2070#else
2071 memsetl(video_fb_address,
2072 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2073#endif
2074}
2075
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002076static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002077{
wdenk4b248f32004-03-14 16:51:43 +00002078 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002079
Wolfgang Denk57912932011-07-30 12:48:09 +00002080 pGD = video_hw_init();
2081 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00002082 return -1;
wdenkc6097192002-11-03 00:24:07 +00002083
wdenk4b248f32004-03-14 16:51:43 +00002084 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002085#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002086 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002087#endif
2088
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002089 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2090
wdenk4b248f32004-03-14 16:51:43 +00002091 /* Init drawing pats */
2092 switch (VIDEO_DATA_FORMAT) {
2093 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002094 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2095 CONSOLE_FG_COL);
2096 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2097 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00002098 fgx = 0x01010101;
2099 bgx = 0x00000000;
2100 break;
2101 case GDF__8BIT_332RGB:
2102 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002103 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2104 CONSOLE_FG_COL >> 6);
2105 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2106 color8;
wdenk4b248f32004-03-14 16:51:43 +00002107 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002108 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2109 CONSOLE_BG_COL >> 6);
2110 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2111 color8;
wdenk4b248f32004-03-14 16:51:43 +00002112 break;
2113 case GDF_15BIT_555RGB:
2114 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002115 ((CONSOLE_FG_COL >> 3) << 21) |
2116 ((CONSOLE_FG_COL >> 3) << 16) |
2117 ((CONSOLE_FG_COL >> 3) << 10) |
2118 ((CONSOLE_FG_COL >> 3) << 5) |
2119 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002120 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002121 ((CONSOLE_BG_COL >> 3) << 21) |
2122 ((CONSOLE_BG_COL >> 3) << 16) |
2123 ((CONSOLE_BG_COL >> 3) << 10) |
2124 ((CONSOLE_BG_COL >> 3) << 5) |
2125 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002126 break;
2127 case GDF_16BIT_565RGB:
2128 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002129 ((CONSOLE_FG_COL >> 2) << 21) |
2130 ((CONSOLE_FG_COL >> 3) << 16) |
2131 ((CONSOLE_FG_COL >> 3) << 11) |
2132 ((CONSOLE_FG_COL >> 2) << 5) |
2133 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002134 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002135 ((CONSOLE_BG_COL >> 2) << 21) |
2136 ((CONSOLE_BG_COL >> 3) << 16) |
2137 ((CONSOLE_BG_COL >> 3) << 11) |
2138 ((CONSOLE_BG_COL >> 2) << 5) |
2139 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002140 break;
2141 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002142 fgx = (CONSOLE_FG_COL << 16) |
2143 (CONSOLE_FG_COL << 8) |
2144 CONSOLE_FG_COL;
2145 bgx = (CONSOLE_BG_COL << 16) |
2146 (CONSOLE_BG_COL << 8) |
2147 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002148 break;
2149 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002150 fgx = (CONSOLE_FG_COL << 24) |
2151 (CONSOLE_FG_COL << 16) |
2152 (CONSOLE_FG_COL << 8) |
2153 CONSOLE_FG_COL;
2154 bgx = (CONSOLE_BG_COL << 24) |
2155 (CONSOLE_BG_COL << 16) |
2156 (CONSOLE_BG_COL << 8) |
2157 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002158 break;
2159 }
2160 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002161
Heiko Schocher45ae2542013-10-22 11:06:06 +02002162 video_clear();
2163
wdenkc6097192002-11-03 00:24:07 +00002164#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00002165 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002166 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002167 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002168#else
wdenk4b248f32004-03-14 16:51:43 +00002169 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002170#endif
2171
wdenk4b248f32004-03-14 16:51:43 +00002172 /* Initialize the console */
2173 console_col = 0;
2174 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002175
Eric Nelsondb0d47d2013-05-06 14:27:28 +02002176 if (cfb_do_flush_cache)
2177 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2178
wdenk4b248f32004-03-14 16:51:43 +00002179 return 0;
wdenkc6097192002-11-03 00:24:07 +00002180}
2181
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002182/*
2183 * Implement a weak default function for boards that optionally
2184 * need to skip the video initialization.
2185 */
Jeroen Hofstee69d27542014-10-08 22:57:30 +02002186__weak int board_video_skip(void)
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002187{
2188 /* As default, don't skip test */
2189 return 0;
2190}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002191
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002192int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002193{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02002194 struct stdio_dev console_dev;
Simon Glass5692ccf2015-03-02 12:40:50 -07002195 bool have_keyboard;
Bin Meng8ceb2422015-08-24 01:00:07 -07002196 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00002197
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002198 /* Check if video initialization should be skipped */
2199 if (board_video_skip())
2200 return 0;
2201
wdenk81050922004-07-11 20:04:51 +00002202 /* Init video chip - returns with framebuffer cleared */
Bin Meng8ceb2422015-08-24 01:00:07 -07002203 if (video_init() == -1)
2204 return 0;
wdenk81050922004-07-11 20:04:51 +00002205
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002206 if (board_cfb_skip())
2207 return 0;
2208
Simon Glass5692ccf2015-03-02 12:40:50 -07002209#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2210 have_keyboard = false;
2211#elif defined(CONFIG_OF_CONTROL)
2212 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2213 "u-boot,no-keyboard");
2214#else
2215 have_keyboard = true;
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002216#endif
Simon Glass5692ccf2015-03-02 12:40:50 -07002217 if (have_keyboard) {
2218 debug("KBD: Keyboard init ...\n");
2219#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07002220 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Simon Glass5692ccf2015-03-02 12:40:50 -07002221#endif
2222 }
wdenkc6097192002-11-03 00:24:07 +00002223
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002224 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002225 memset(&console_dev, 0, sizeof(console_dev));
2226 strcpy(console_dev.name, "vga");
Bin Meng1caf9342015-11-03 23:23:37 -08002227 console_dev.flags = DEV_FLAGS_OUTPUT;
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002228 console_dev.putc = video_putc; /* 'putc' function */
2229 console_dev.puts = video_puts; /* 'puts' function */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002230
2231#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Meng8ceb2422015-08-24 01:00:07 -07002232 if (have_keyboard && keyboard_ok) {
Simon Glass5692ccf2015-03-02 12:40:50 -07002233 /* Also init console device */
2234 console_dev.flags |= DEV_FLAGS_INPUT;
2235 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2236 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2237 }
2238#endif
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002239
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002240 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002241 return 0;
2242
2243 /* Return success */
2244 return 1;
wdenkc6097192002-11-03 00:24:07 +00002245}
Stefan Reinauerc20ee072012-09-28 15:11:12 +00002246
2247void video_position_cursor(unsigned col, unsigned row)
2248{
2249 console_col = min(col, CONSOLE_COLS - 1);
2250 console_row = min(row, CONSOLE_ROWS - 1);
2251}
2252
2253int video_get_pixel_width(void)
2254{
2255 return VIDEO_VISIBLE_COLS;
2256}
2257
2258int video_get_pixel_height(void)
2259{
2260 return VIDEO_VISIBLE_ROWS;
2261}
2262
2263int video_get_screen_rows(void)
2264{
2265 return CONSOLE_ROWS;
2266}
2267
2268int video_get_screen_columns(void)
2269{
2270 return CONSOLE_COLS;
2271}