blob: aca44441524223925cbca227e151f4d72eb91527 [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.
61 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
62 * initialized as an output only device.
63 * The Keyboard driver will not be
64 * set-up. This may be used, if you have
65 * no or more than one Keyboard devices
66 * (USB Keyboard, AT Keyboard).
67 *
68 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
69 * character. No blinking is provided.
70 * Uses the macros CURSOR_SET and
71 * CURSOR_OFF.
72 *
73 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
74 * of the graphic chip. Uses the macro
75 * CURSOR_SET. ATTENTION: If booting an
76 * OS, the display driver must disable
77 * the hardware register of the graphic
78 * chip. Otherwise a blinking field is
79 * displayed.
80 */
wdenkc6097192002-11-03 00:24:07 +000081
82#include <common.h>
Simon Glasse9fa1f02015-03-02 12:40:50 -070083#include <fdtdec.h>
Andreas Bießmann61d01952011-07-18 20:24:04 +020084#include <version.h>
wdenk9dd2b882002-12-03 21:28:10 +000085#include <malloc.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +000086#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +000087
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000088/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000089 * Defines for the CT69000 driver
90 */
wdenke55402c2004-03-14 16:51:43 +000091#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +000092
93#define VIDEO_FB_LITTLE_ENDIAN
94#define VIDEO_HW_RECTFILL
95#define VIDEO_HW_BITBLT
96#endif
97
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +000098/*
99 * Defines for the SED13806 driver
100 */
wdenk9dd2b882002-12-03 21:28:10 +0000101#ifdef CONFIG_VIDEO_SED13806
wdenk9dd2b882002-12-03 21:28:10 +0000102#define VIDEO_FB_LITTLE_ENDIAN
103#define VIDEO_HW_RECTFILL
104#define VIDEO_HW_BITBLT
105#endif
106
Simon Glass9d057042016-10-17 20:12:47 -0600107#if defined(CONFIG_VIDEO_MXS)
Marek Vasutffdd4662013-04-28 09:20:03 +0000108#define VIDEO_FB_16BPP_WORD_SWAP
109#endif
110
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000111/*
112 * Defines for the MB862xx driver
113 */
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100114#ifdef CONFIG_VIDEO_MB862xx
115
116#ifdef CONFIG_VIDEO_CORALP
117#define VIDEO_FB_LITTLE_ENDIAN
118#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200119#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100120#define VIDEO_HW_RECTFILL
121#define VIDEO_HW_BITBLT
122#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200123#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100124
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000125/*
Helmut Raiger0385c132011-10-12 23:16:29 +0000126 * Defines for the i.MX31 driver (mx3fb.c)
127 */
Fabio Estevamc6dd2e02012-05-31 07:23:56 +0000128#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger0385c132011-10-12 23:16:29 +0000129#define VIDEO_FB_16BPP_WORD_SWAP
130#endif
131
132/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000133 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
134 */
wdenkc6097192002-11-03 00:24:07 +0000135#include <video_fb.h>
136
Robert Winkler2a90ed02013-06-17 11:31:29 -0700137#include <splash.h>
138
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000139/*
140 * some Macros
141 */
wdenke55402c2004-03-14 16:51:43 +0000142#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
143#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
144#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
145#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
146#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000147
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000148/*
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000149 * Console device
150 */
wdenkc6097192002-11-03 00:24:07 +0000151
152#include <version.h>
153#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200154#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000155#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000156
Jon Loeliger30c2f242007-07-10 11:13:21 -0500157#if defined(CONFIG_CMD_DATE)
158#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000159#endif
160
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500161#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000162#include <watchdog.h>
163#include <bmp_layout.h>
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +0200164#include <splash.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200165#endif
166
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000167/*
168 * Cursor definition:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000169 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
170 * blinking is provided. Uses the macros CURSOR_SET
171 * and CURSOR_OFF.
172 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
173 * graphic chip. Uses the macro CURSOR_SET.
174 * ATTENTION: If booting an OS, the display driver
175 * must disable the hardware register of the graphic
176 * chip. Otherwise a blinking field is displayed
177 */
Simon Glassf406a1b2015-10-18 21:17:18 -0600178#if !defined(CONFIG_VIDEO_SW_CURSOR) && !defined(CONFIG_VIDEO_HW_CURSOR)
wdenkc6097192002-11-03 00:24:07 +0000179/* no Cursor defined */
180#define CURSOR_ON
181#define CURSOR_OFF
182#define CURSOR_SET
183#endif
184
Simon Glassf406a1b2015-10-18 21:17:18 -0600185#if defined(CONFIG_VIDEO_SW_CURSOR)
186#if defined(CONFIG_VIDEO_HW_CURSOR)
187#error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
188 defined
wdenkc6097192002-11-03 00:24:07 +0000189#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000190void console_cursor(int state);
191
Timur Tabibe0c74e2010-08-27 15:45:47 -0500192#define CURSOR_ON console_cursor(1)
193#define CURSOR_OFF console_cursor(0)
Gabe Black12874de2011-11-30 13:50:50 +0000194#define CURSOR_SET video_set_cursor()
Simon Glassf406a1b2015-10-18 21:17:18 -0600195#endif /* CONFIG_VIDEO_SW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000196
197#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +0000198#ifdef CURSOR_ON
Simon Glassf406a1b2015-10-18 21:17:18 -0600199#error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
200 defined
wdenkc6097192002-11-03 00:24:07 +0000201#endif
202#define CURSOR_ON
203#define CURSOR_OFF
204#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabibe0c74e2010-08-27 15:45:47 -0500205 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000206#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000207
wdenke55402c2004-03-14 16:51:43 +0000208#ifdef CONFIG_VIDEO_LOGO
209#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000210#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000211#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000212#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
213#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
214#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
215#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000216
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000217#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000218#define LINUX_LOGO_WIDTH 80
219#define LINUX_LOGO_HEIGHT 80
220#define LINUX_LOGO_COLORS 214
221#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000222#define __initdata
223#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000224#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
225#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
226#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
227#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000228#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000229#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
230#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000231#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000232#define VIDEO_LOGO_WIDTH 0
233#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000234#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000235
wdenke55402c2004-03-14 16:51:43 +0000236#define VIDEO_COLS VIDEO_VISIBLE_COLS
237#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
Hans de Goedea8287e72015-08-04 12:15:39 +0200238#ifndef VIDEO_LINE_LEN
239#define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
240#endif
241#define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
wdenke55402c2004-03-14 16:51:43 +0000242#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000243
wdenke55402c2004-03-14 16:51:43 +0000244#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100245#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000246#else
wdenke55402c2004-03-14 16:51:43 +0000247#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000248#endif
249
wdenke55402c2004-03-14 16:51:43 +0000250#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
251#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
252#define CONSOLE_ROW_FIRST (video_console_address)
253#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
254#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
255#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
Simon Glass6ceb7f02015-01-01 16:17:57 -0700256
257/* By default we scroll by a single line */
258#ifndef CONFIG_CONSOLE_SCROLL_LINES
259#define CONFIG_CONSOLE_SCROLL_LINES 1
260#endif
wdenkc6097192002-11-03 00:24:07 +0000261
262/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000263#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000264#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
265 ((x) >> 8) \
266 )
267#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
268 (((x) & 0x0000ff00) << 8) | \
269 (((x) & 0x00ff0000) >> 8) | \
270 (((x) & 0xff000000) >> 24) \
271 )
272#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
273 (((x) & 0x0000ff00) >> 8) | \
274 (((x) & 0x00ff0000) << 8) | \
275 (((x) & 0xff000000) >> 8) \
276 )
wdenkc6097192002-11-03 00:24:07 +0000277#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000278#define SWAP16(x) (x)
279#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200280#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000281#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500282#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000283#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100284#endif
wdenkc6097192002-11-03 00:24:07 +0000285#endif
286
wdenkc6097192002-11-03 00:24:07 +0000287#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000288/*
289 * setup a board string: type, speed, etc.
290 *
291 * line_number: location to place info string beside logo
292 * info: buffer for info string
293 */
294extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000295#endif
296
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200297DECLARE_GLOBAL_DATA_PTR;
298
wdenkc6097192002-11-03 00:24:07 +0000299/* Locals */
300static GraphicDevice *pGD; /* Pointer to Graphic array */
301
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000302static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000303static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000304
Matthias Weisser76d70862010-01-12 12:06:31 +0100305static int video_logo_height = VIDEO_LOGO_HEIGHT;
306
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000307static int __maybe_unused cursor_state;
308static int __maybe_unused old_col;
309static int __maybe_unused old_row;
Gabe Black12874de2011-11-30 13:50:50 +0000310
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000311static int console_col; /* cursor col */
312static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000313
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000314static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000315
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200316static int cfb_do_flush_cache;
317
Pali Rohár4a57da32012-10-19 13:30:09 +0000318#ifdef CONFIG_CFB_CONSOLE_ANSI
319static char ansi_buf[10];
320static int ansi_buf_size;
321static int ansi_colors_need_revert;
322static int ansi_cursor_hidden;
323#endif
324
wdenkc6097192002-11-03 00:24:07 +0000325static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000326 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
327 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
328 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
329 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
330};
wdenkc6097192002-11-03 00:24:07 +0000331
332static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000333 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
334};
wdenkc6097192002-11-03 00:24:07 +0000335
336static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000337 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
338};
wdenkc6097192002-11-03 00:24:07 +0000339
340static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000341 {0x00000000, 0x00000000, 0x00000000},
342 {0x00000000, 0x00000000, 0x00ffffff},
343 {0x00000000, 0x0000ffff, 0xff000000},
344 {0x00000000, 0x0000ffff, 0xffffffff},
345 {0x000000ff, 0xffff0000, 0x00000000},
346 {0x000000ff, 0xffff0000, 0x00ffffff},
347 {0x000000ff, 0xffffffff, 0xff000000},
348 {0x000000ff, 0xffffffff, 0xffffffff},
349 {0xffffff00, 0x00000000, 0x00000000},
350 {0xffffff00, 0x00000000, 0x00ffffff},
351 {0xffffff00, 0x0000ffff, 0xff000000},
352 {0xffffff00, 0x0000ffff, 0xffffffff},
353 {0xffffffff, 0xffff0000, 0x00000000},
354 {0xffffffff, 0xffff0000, 0x00ffffff},
355 {0xffffffff, 0xffffffff, 0xff000000},
356 {0xffffffff, 0xffffffff, 0xffffffff}
357};
wdenkc6097192002-11-03 00:24:07 +0000358
359static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000360 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
361 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
362 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
363 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
364 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
365 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
366 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
367 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
368 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
369 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
370 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
371 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
372 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
373 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
374 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
375 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
376};
wdenkc6097192002-11-03 00:24:07 +0000377
Heiko Schocher9cff8ad2013-08-03 07:22:53 +0200378/*
379 * Implement a weak default function for boards that optionally
380 * need to skip the cfb initialization.
381 */
382__weak int board_cfb_skip(void)
383{
384 /* As default, don't skip cfb init */
385 return 0;
386}
387
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000388static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000389{
wdenke55402c2004-03-14 16:51:43 +0000390 u8 *cdat, *dest, *dest0;
391 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000392
wdenke55402c2004-03-14 16:51:43 +0000393 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
394 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000395
wdenke55402c2004-03-14 16:51:43 +0000396 switch (VIDEO_DATA_FORMAT) {
397 case GDF__8BIT_INDEX:
398 case GDF__8BIT_332RGB:
399 while (count--) {
400 c = *s;
401 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
402 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000403 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000404 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000405
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000406 ((u32 *) dest)[0] =
407 (video_font_draw_table8[bits >> 4] &
408 eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200409
410 if (VIDEO_FONT_WIDTH == 4)
411 continue;
412
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000413 ((u32 *) dest)[1] =
414 (video_font_draw_table8[bits & 15] &
415 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000416 }
417 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
418 s++;
419 }
420 break;
wdenkc6097192002-11-03 00:24:07 +0000421
wdenke55402c2004-03-14 16:51:43 +0000422 case GDF_15BIT_555RGB:
423 while (count--) {
424 c = *s;
425 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
426 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000427 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000428 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000429
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000430 ((u32 *) dest)[0] =
431 SHORTSWAP32((video_font_draw_table15
432 [bits >> 6] & eorx) ^
433 bgx);
434 ((u32 *) dest)[1] =
435 SHORTSWAP32((video_font_draw_table15
436 [bits >> 4 & 3] & eorx) ^
437 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200438
439 if (VIDEO_FONT_WIDTH == 4)
440 continue;
441
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000442 ((u32 *) dest)[2] =
443 SHORTSWAP32((video_font_draw_table15
444 [bits >> 2 & 3] & eorx) ^
445 bgx);
446 ((u32 *) dest)[3] =
447 SHORTSWAP32((video_font_draw_table15
448 [bits & 3] & eorx) ^
449 bgx);
wdenke55402c2004-03-14 16:51:43 +0000450 }
451 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
452 s++;
453 }
454 break;
wdenkc6097192002-11-03 00:24:07 +0000455
wdenke55402c2004-03-14 16:51:43 +0000456 case GDF_16BIT_565RGB:
457 while (count--) {
458 c = *s;
459 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
460 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000461 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000462 u8 bits = *cdat++;
463
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000464 ((u32 *) dest)[0] =
465 SHORTSWAP32((video_font_draw_table16
466 [bits >> 6] & eorx) ^
467 bgx);
468 ((u32 *) dest)[1] =
469 SHORTSWAP32((video_font_draw_table16
470 [bits >> 4 & 3] & eorx) ^
471 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200472
473 if (VIDEO_FONT_WIDTH == 4)
474 continue;
475
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000476 ((u32 *) dest)[2] =
477 SHORTSWAP32((video_font_draw_table16
478 [bits >> 2 & 3] & eorx) ^
479 bgx);
480 ((u32 *) dest)[3] =
481 SHORTSWAP32((video_font_draw_table16
482 [bits & 3] & eorx) ^
483 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_32BIT_X888RGB:
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 SWAP32((video_font_draw_table32
500 [bits >> 4][0] & eorx) ^ bgx);
501 ((u32 *) dest)[1] =
502 SWAP32((video_font_draw_table32
503 [bits >> 4][1] & eorx) ^ bgx);
504 ((u32 *) dest)[2] =
505 SWAP32((video_font_draw_table32
506 [bits >> 4][2] & eorx) ^ bgx);
507 ((u32 *) dest)[3] =
508 SWAP32((video_font_draw_table32
509 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200510
511
512 if (VIDEO_FONT_WIDTH == 4)
513 continue;
514
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000515 ((u32 *) dest)[4] =
516 SWAP32((video_font_draw_table32
517 [bits & 15][0] & eorx) ^ bgx);
518 ((u32 *) dest)[5] =
519 SWAP32((video_font_draw_table32
520 [bits & 15][1] & eorx) ^ bgx);
521 ((u32 *) dest)[6] =
522 SWAP32((video_font_draw_table32
523 [bits & 15][2] & eorx) ^ bgx);
524 ((u32 *) dest)[7] =
525 SWAP32((video_font_draw_table32
526 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000527 }
528 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
529 s++;
530 }
531 break;
532
533 case GDF_24BIT_888RGB:
534 while (count--) {
535 c = *s;
536 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
537 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000538 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000539 u8 bits = *cdat++;
540
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000541 ((u32 *) dest)[0] =
542 (video_font_draw_table24[bits >> 4][0]
543 & eorx) ^ bgx;
544 ((u32 *) dest)[1] =
545 (video_font_draw_table24[bits >> 4][1]
546 & eorx) ^ bgx;
547 ((u32 *) dest)[2] =
548 (video_font_draw_table24[bits >> 4][2]
549 & eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200550
551 if (VIDEO_FONT_WIDTH == 4)
552 continue;
553
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000554 ((u32 *) dest)[3] =
555 (video_font_draw_table24[bits & 15][0]
556 & eorx) ^ bgx;
557 ((u32 *) dest)[4] =
558 (video_font_draw_table24[bits & 15][1]
559 & eorx) ^ bgx;
560 ((u32 *) dest)[5] =
561 (video_font_draw_table24[bits & 15][2]
562 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000563 }
564 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
565 s++;
566 }
567 break;
wdenk57b2d802003-06-27 21:31:46 +0000568 }
wdenkc6097192002-11-03 00:24:07 +0000569}
570
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000571static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000572{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000573 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000574}
575
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000576static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000577{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000578 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000579}
580
Simon Glassf406a1b2015-10-18 21:17:18 -0600581#if defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000582static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000583{
Gabe Black12874de2011-11-30 13:50:50 +0000584 if (cursor_state)
585 console_cursor(0);
586 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000587}
Gabe Black12874de2011-11-30 13:50:50 +0000588
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000589static void video_invertchar(int xx, int yy)
590{
591 int firstx = xx * VIDEO_PIXEL_SIZE;
592 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
593 int firsty = yy * VIDEO_LINE_LEN;
594 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
595 int x, y;
596 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
597 for (x = firstx; x < lastx; x++) {
598 u8 *dest = (u8 *)(video_fb_address) + x + y;
599 *dest = ~*dest;
600 }
601 }
602}
Gabe Black12874de2011-11-30 13:50:50 +0000603
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000604void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000605{
Gabe Black12874de2011-11-30 13:50:50 +0000606 if (cursor_state != state) {
607 if (cursor_state) {
608 /* turn off the cursor */
609 video_invertchar(old_col * VIDEO_FONT_WIDTH,
610 old_row * VIDEO_FONT_HEIGHT +
611 video_logo_height);
612 } else {
613 /* turn off the cursor and record where it is */
614 video_invertchar(console_col * VIDEO_FONT_WIDTH,
615 console_row * VIDEO_FONT_HEIGHT +
616 video_logo_height);
617 old_col = console_col;
618 old_row = console_row;
619 }
620 cursor_state = state;
wdenke55402c2004-03-14 16:51:43 +0000621 }
Eric Nelson54142422013-05-06 14:27:28 +0200622 if (cfb_do_flush_cache)
623 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000624}
625#endif
626
wdenkc6097192002-11-03 00:24:07 +0000627#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000628static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000629{
wdenke55402c2004-03-14 16:51:43 +0000630 while (c--)
631 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000632}
633#endif
634
wdenkc6097192002-11-03 00:24:07 +0000635#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000636static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000637{
wdenke55402c2004-03-14 16:51:43 +0000638 while (c--)
639 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000640}
641#endif
642
Pali Rohár16658612012-04-28 07:26:44 +0000643static void console_clear_line(int line, int begin, int end)
644{
645#ifdef VIDEO_HW_RECTFILL
646 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
647 VIDEO_FONT_WIDTH * begin, /* dest pos x */
648 video_logo_height +
649 VIDEO_FONT_HEIGHT * line, /* dest pos y */
650 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
651 VIDEO_FONT_HEIGHT, /* frame height */
652 bgx /* fill color */
653 );
654#else
655 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
656 memsetl(CONSOLE_ROW_FIRST +
657 CONSOLE_ROW_SIZE * line, /* offset of row */
658 CONSOLE_ROW_SIZE >> 2, /* length of row */
659 bgx /* fill color */
660 );
661 } else {
662 void *offset;
663 int i, size;
664
665 offset = CONSOLE_ROW_FIRST +
666 CONSOLE_ROW_SIZE * line + /* offset of row */
667 VIDEO_FONT_WIDTH *
668 VIDEO_PIXEL_SIZE * begin; /* offset of col */
669 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
670 size >>= 2; /* length to end for memsetl() */
671 /* fill at col offset of i'th line using bgx as fill color */
672 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
673 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
674 }
675#endif
676}
677
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000678static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000679{
Simon Glass6ceb7f02015-01-01 16:17:57 -0700680 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
681 int i;
682
wdenke55402c2004-03-14 16:51:43 +0000683 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000684
685#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000686 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
687 0, /* source pos x */
688 video_logo_height +
Simon Glass6ceb7f02015-01-01 16:17:57 -0700689 VIDEO_FONT_HEIGHT * rows, /* source pos y */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000690 0, /* dest pos x */
691 video_logo_height, /* dest pos y */
692 VIDEO_VISIBLE_COLS, /* frame width */
693 VIDEO_VISIBLE_ROWS
694 - video_logo_height
Simon Glass6ceb7f02015-01-01 16:17:57 -0700695 - VIDEO_FONT_HEIGHT * rows /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000696 );
wdenkc6097192002-11-03 00:24:07 +0000697#else
Simon Glass6ceb7f02015-01-01 16:17:57 -0700698 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
699 (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
wdenkc6097192002-11-03 00:24:07 +0000700#endif
wdenke55402c2004-03-14 16:51:43 +0000701 /* clear the last one */
Simon Glass6ceb7f02015-01-01 16:17:57 -0700702 for (i = 1; i <= rows; i++)
703 console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
704
705 /* Decrement row number */
706 console_row -= rows;
wdenkc6097192002-11-03 00:24:07 +0000707}
708
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000709static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000710{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500711 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000712
wdenke55402c2004-03-14 16:51:43 +0000713 if (console_col < 0) {
714 console_col = CONSOLE_COLS - 1;
715 console_row--;
716 if (console_row < 0)
717 console_row = 0;
718 }
wdenkc6097192002-11-03 00:24:07 +0000719}
720
Pali Rohár4a57da32012-10-19 13:30:09 +0000721#ifdef CONFIG_CFB_CONSOLE_ANSI
722
723static void console_clear(void)
724{
725#ifdef VIDEO_HW_RECTFILL
726 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
727 0, /* dest pos x */
728 video_logo_height, /* dest pos y */
729 VIDEO_VISIBLE_COLS, /* frame width */
730 VIDEO_VISIBLE_ROWS, /* frame height */
731 bgx /* fill color */
732 );
733#else
734 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
735#endif
736}
737
738static void console_cursor_fix(void)
739{
740 if (console_row < 0)
741 console_row = 0;
742 if (console_row >= CONSOLE_ROWS)
743 console_row = CONSOLE_ROWS - 1;
744 if (console_col < 0)
745 console_col = 0;
746 if (console_col >= CONSOLE_COLS)
747 console_col = CONSOLE_COLS - 1;
748}
749
750static void console_cursor_up(int n)
751{
752 console_row -= n;
753 console_cursor_fix();
754}
755
756static void console_cursor_down(int n)
757{
758 console_row += n;
759 console_cursor_fix();
760}
761
762static void console_cursor_left(int n)
wdenkc6097192002-11-03 00:24:07 +0000763{
Pali Rohár4a57da32012-10-19 13:30:09 +0000764 console_col -= n;
765 console_cursor_fix();
766}
767
768static void console_cursor_right(int n)
769{
770 console_col += n;
771 console_cursor_fix();
772}
773
774static void console_cursor_set_position(int row, int col)
775{
776 if (console_row != -1)
777 console_row = row;
778 if (console_col != -1)
779 console_col = col;
780 console_cursor_fix();
781}
782
783static void console_previousline(int n)
784{
785 /* FIXME: also scroll terminal ? */
786 console_row -= n;
787 console_cursor_fix();
788}
789
790static void console_swap_colors(void)
791{
792 eorx = fgx;
793 fgx = bgx;
794 bgx = eorx;
795 eorx = fgx ^ bgx;
796}
797
798static inline int console_cursor_is_visible(void)
799{
800 return !ansi_cursor_hidden;
801}
802#else
803static inline int console_cursor_is_visible(void)
804{
805 return 1;
806}
807#endif
808
809static void console_newline(int n)
810{
811 console_row += n;
wdenke55402c2004-03-14 16:51:43 +0000812 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000813
wdenke55402c2004-03-14 16:51:43 +0000814 /* Check if we need to scroll the terminal */
815 if (console_row >= CONSOLE_ROWS) {
816 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000817 console_scrollup();
wdenke55402c2004-03-14 16:51:43 +0000818 }
wdenkc6097192002-11-03 00:24:07 +0000819}
820
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000821static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100822{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500823 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100824}
825
Pali Rohár4a57da32012-10-19 13:30:09 +0000826static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000827{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100828 static int nl = 1;
829
Pali Rohár4a57da32012-10-19 13:30:09 +0000830 if (console_cursor_is_visible())
831 CURSOR_OFF;
Gabe Black12874de2011-11-30 13:50:50 +0000832
wdenke55402c2004-03-14 16:51:43 +0000833 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100834 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000835 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000836 break;
wdenkc6097192002-11-03 00:24:07 +0000837
wdenke55402c2004-03-14 16:51:43 +0000838 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100839 if (console_col || (!console_col && nl))
Pali Rohár4a57da32012-10-19 13:30:09 +0000840 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100841 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000842 break;
wdenkc6097192002-11-03 00:24:07 +0000843
wdenke55402c2004-03-14 16:51:43 +0000844 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500845 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000846 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000847
wdenke55402c2004-03-14 16:51:43 +0000848 if (console_col >= CONSOLE_COLS)
Pali Rohár4a57da32012-10-19 13:30:09 +0000849 console_newline(1);
wdenke55402c2004-03-14 16:51:43 +0000850 break;
wdenkc6097192002-11-03 00:24:07 +0000851
wdenke55402c2004-03-14 16:51:43 +0000852 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000853 console_back();
wdenke55402c2004-03-14 16:51:43 +0000854 break;
wdenkc6097192002-11-03 00:24:07 +0000855
Pali Rohár9d735b62012-04-28 07:26:47 +0000856 case 7: /* bell */
857 break; /* ignored */
858
wdenke55402c2004-03-14 16:51:43 +0000859 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000860 video_putchar(console_col * VIDEO_FONT_WIDTH,
861 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000862 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000863
wdenke55402c2004-03-14 16:51:43 +0000864 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100865 if (console_col >= CONSOLE_COLS) {
Pali Rohár4a57da32012-10-19 13:30:09 +0000866 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100867 nl = 0;
868 }
wdenke55402c2004-03-14 16:51:43 +0000869 }
Pali Rohár4a57da32012-10-19 13:30:09 +0000870
871 if (console_cursor_is_visible())
872 CURSOR_SET;
873}
874
Jeroen Hofstee169eda62014-10-08 22:57:44 +0200875static void video_putc(struct stdio_dev *dev, const char c)
Pali Rohár4a57da32012-10-19 13:30:09 +0000876{
877#ifdef CONFIG_CFB_CONSOLE_ANSI
878 int i;
879
880 if (c == 27) {
881 for (i = 0; i < ansi_buf_size; ++i)
882 parse_putc(ansi_buf[i]);
883 ansi_buf[0] = 27;
884 ansi_buf_size = 1;
885 return;
886 }
887
888 if (ansi_buf_size > 0) {
889 /*
890 * 0 - ESC
891 * 1 - [
892 * 2 - num1
893 * 3 - ..
894 * 4 - ;
895 * 5 - num2
896 * 6 - ..
897 * - cchar
898 */
899 int next = 0;
900
901 int flush = 0;
902 int fail = 0;
903
904 int num1 = 0;
905 int num2 = 0;
906 int cchar = 0;
907
908 ansi_buf[ansi_buf_size++] = c;
909
910 if (ansi_buf_size >= sizeof(ansi_buf))
911 fail = 1;
912
913 for (i = 0; i < ansi_buf_size; ++i) {
914 if (fail)
915 break;
916
917 switch (next) {
918 case 0:
919 if (ansi_buf[i] == 27)
920 next = 1;
921 else
922 fail = 1;
923 break;
924
925 case 1:
926 if (ansi_buf[i] == '[')
927 next = 2;
928 else
929 fail = 1;
930 break;
931
932 case 2:
933 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
934 num1 = ansi_buf[i]-'0';
935 next = 3;
936 } else if (ansi_buf[i] != '?') {
937 --i;
938 num1 = 1;
939 next = 4;
940 }
941 break;
942
943 case 3:
944 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
945 num1 *= 10;
946 num1 += ansi_buf[i]-'0';
947 } else {
948 --i;
949 next = 4;
950 }
951 break;
952
953 case 4:
954 if (ansi_buf[i] != ';') {
955 --i;
956 next = 7;
957 } else
958 next = 5;
959 break;
960
961 case 5:
962 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
963 num2 = ansi_buf[i]-'0';
964 next = 6;
965 } else
966 fail = 1;
967 break;
968
969 case 6:
970 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
971 num2 *= 10;
972 num2 += ansi_buf[i]-'0';
973 } else {
974 --i;
975 next = 7;
976 }
977 break;
978
979 case 7:
980 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
981 || ansi_buf[i] == 'J'
982 || ansi_buf[i] == 'K'
983 || ansi_buf[i] == 'h'
984 || ansi_buf[i] == 'l'
985 || ansi_buf[i] == 'm') {
986 cchar = ansi_buf[i];
987 flush = 1;
988 } else
989 fail = 1;
990 break;
991 }
992 }
993
994 if (fail) {
995 for (i = 0; i < ansi_buf_size; ++i)
996 parse_putc(ansi_buf[i]);
997 ansi_buf_size = 0;
998 return;
999 }
1000
1001 if (flush) {
1002 if (!ansi_cursor_hidden)
1003 CURSOR_OFF;
1004 ansi_buf_size = 0;
1005 switch (cchar) {
1006 case 'A':
1007 /* move cursor num1 rows up */
1008 console_cursor_up(num1);
1009 break;
1010 case 'B':
1011 /* move cursor num1 rows down */
1012 console_cursor_down(num1);
1013 break;
1014 case 'C':
1015 /* move cursor num1 columns forward */
1016 console_cursor_right(num1);
1017 break;
1018 case 'D':
1019 /* move cursor num1 columns back */
1020 console_cursor_left(num1);
1021 break;
1022 case 'E':
1023 /* move cursor num1 rows up at begin of row */
1024 console_previousline(num1);
1025 break;
1026 case 'F':
1027 /* move cursor num1 rows down at begin of row */
1028 console_newline(num1);
1029 break;
1030 case 'G':
1031 /* move cursor to column num1 */
1032 console_cursor_set_position(-1, num1-1);
1033 break;
1034 case 'H':
1035 /* move cursor to row num1, column num2 */
1036 console_cursor_set_position(num1-1, num2-1);
1037 break;
1038 case 'J':
1039 /* clear console and move cursor to 0, 0 */
1040 console_clear();
1041 console_cursor_set_position(0, 0);
1042 break;
1043 case 'K':
1044 /* clear line */
1045 if (num1 == 0)
1046 console_clear_line(console_row,
1047 console_col,
1048 CONSOLE_COLS-1);
1049 else if (num1 == 1)
1050 console_clear_line(console_row,
1051 0, console_col);
1052 else
1053 console_clear_line(console_row,
1054 0, CONSOLE_COLS-1);
1055 break;
1056 case 'h':
1057 ansi_cursor_hidden = 0;
1058 break;
1059 case 'l':
1060 ansi_cursor_hidden = 1;
1061 break;
1062 case 'm':
1063 if (num1 == 0) { /* reset swapped colors */
1064 if (ansi_colors_need_revert) {
1065 console_swap_colors();
1066 ansi_colors_need_revert = 0;
1067 }
1068 } else if (num1 == 7) { /* once swap colors */
1069 if (!ansi_colors_need_revert) {
1070 console_swap_colors();
1071 ansi_colors_need_revert = 1;
1072 }
1073 }
1074 break;
1075 }
1076 if (!ansi_cursor_hidden)
1077 CURSOR_SET;
1078 }
1079 } else {
1080 parse_putc(c);
1081 }
1082#else
1083 parse_putc(c);
1084#endif
Eric Nelson54142422013-05-06 14:27:28 +02001085 if (cfb_do_flush_cache)
1086 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabibe0c74e2010-08-27 15:45:47 -05001087}
wdenkc6097192002-11-03 00:24:07 +00001088
Jeroen Hofstee169eda62014-10-08 22:57:44 +02001089static void video_puts(struct stdio_dev *dev, const char *s)
wdenkc6097192002-11-03 00:24:07 +00001090{
Soeren Mochbd9c1312014-10-24 16:33:30 +02001091 int flush = cfb_do_flush_cache;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001092 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +00001093
Soeren Mochbd9c1312014-10-24 16:33:30 +02001094 /* temporarily disable cache flush */
1095 cfb_do_flush_cache = 0;
1096
wdenke55402c2004-03-14 16:51:43 +00001097 while (count--)
Simon Glass0d1e1f72014-07-23 06:54:59 -06001098 video_putc(dev, *s++);
Soeren Mochbd9c1312014-10-24 16:33:30 +02001099
1100 if (flush) {
1101 cfb_do_flush_cache = flush;
1102 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
1103 }
wdenke55402c2004-03-14 16:51:43 +00001104}
1105
Anatolij Gustschina043c342010-05-01 22:21:09 +02001106/*
1107 * Do not enforce drivers (or board code) to provide empty
1108 * video_set_lut() if they do not support 8 bpp format.
1109 * Implement weak default function instead.
1110 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02001111__weak void video_set_lut(unsigned int index, unsigned char r,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001112 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +02001113{
1114}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001115
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001116#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +00001117
1118#define FILL_8BIT_332RGB(r,g,b) { \
1119 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1120 fb ++; \
1121}
1122
1123#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001124 *(unsigned short *)fb = \
1125 SWAP16((unsigned short)(((r>>3)<<10) | \
1126 ((g>>3)<<5) | \
1127 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001128 fb += 2; \
1129}
1130
1131#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001132 *(unsigned short *)fb = \
1133 SWAP16((unsigned short)((((r)>>3)<<11)| \
1134 (((g)>>2)<<5) | \
1135 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001136 fb += 2; \
1137}
1138
1139#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001140 *(unsigned long *)fb = \
1141 SWAP32((unsigned long)(((r<<16) | \
1142 (g<<8) | \
1143 b))); \
wdenke55402c2004-03-14 16:51:43 +00001144 fb += 4; \
1145}
1146
1147#ifdef VIDEO_FB_LITTLE_ENDIAN
1148#define FILL_24BIT_888RGB(r,g,b) { \
1149 fb[0] = b; \
1150 fb[1] = g; \
1151 fb[2] = r; \
1152 fb += 3; \
1153}
1154#else
1155#define FILL_24BIT_888RGB(r,g,b) { \
1156 fb[0] = r; \
1157 fb[1] = g; \
1158 fb[2] = b; \
1159 fb += 3; \
1160}
1161#endif
1162
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001163#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001164static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001165{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001166 ushort *dst = (ushort *) fb;
1167 ushort color = (ushort) (((r >> 3) << 10) |
1168 ((g >> 3) << 5) |
1169 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001170 if (x & 1)
1171 *(--dst) = color;
1172 else
1173 *(++dst) = color;
1174}
1175#endif
wdenke55402c2004-03-14 16:51:43 +00001176
1177/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001178 * RLE8 bitmap support
1179 */
1180
1181#ifdef CONFIG_VIDEO_BMP_RLE8
1182/* Pre-calculated color table entry */
1183struct palette {
1184 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001185 unsigned short w; /* word */
1186 unsigned int dw; /* double word */
1187 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001188};
1189
1190/*
1191 * Helper to draw encoded/unencoded run.
1192 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001193static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1194 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001195{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001196 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001197 int *off;
1198 int enc_off = 1;
1199 int i;
1200
1201 /*
1202 * Setup offset of the color index in the bitmap.
1203 * Color index of encoded run is at offset 1.
1204 */
1205 off = enc ? &enc_off : &i;
1206
1207 switch (VIDEO_DATA_FORMAT) {
1208 case GDF__8BIT_INDEX:
1209 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001210 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001211 break;
1212 case GDF_15BIT_555RGB:
1213 case GDF_16BIT_565RGB:
1214 /* differences handled while pre-calculating palette */
1215 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001216 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001217 addr += 2;
1218 }
1219 break;
1220 case GDF_32BIT_X888RGB:
1221 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001222 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001223 addr += 4;
1224 }
1225 break;
1226 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001227 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001228}
1229
Simon Glass92e1f852015-05-13 07:02:27 -06001230static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001231 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001232{
1233 unsigned char *bm;
1234 unsigned char *fbp;
1235 unsigned int cnt, runlen;
1236 int decode = 1;
1237 int x, y, bpp, i, ncolors;
1238 struct palette p[256];
Simon Glass92e1f852015-05-13 07:02:27 -06001239 struct bmp_color_table_entry cte;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001240 int green_shift, red_off;
Hans de Goedea8287e72015-08-04 12:15:39 +02001241 int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001242 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001243
1244 x = 0;
1245 y = __le32_to_cpu(img->header.height) - 1;
1246 ncolors = __le32_to_cpu(img->header.colors_used);
1247 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001248 fbp = (unsigned char *) ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001249 (y + yoff) * VIDEO_LINE_LEN +
1250 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001251
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001252 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001253
1254 /* pre-calculate and setup palette */
1255 switch (VIDEO_DATA_FORMAT) {
1256 case GDF__8BIT_INDEX:
1257 for (i = 0; i < ncolors; i++) {
1258 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001259 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001260 }
1261 break;
1262 case GDF_15BIT_555RGB:
1263 case GDF_16BIT_565RGB:
1264 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1265 green_shift = 3;
1266 red_off = 10;
1267 } else {
1268 green_shift = 2;
1269 red_off = 11;
1270 }
1271 for (i = 0; i < ncolors; i++) {
1272 cte = img->color_table[i];
1273 p[i].ce.w = SWAP16((unsigned short)
1274 (((cte.red >> 3) << red_off) |
1275 ((cte.green >> green_shift) << 5) |
1276 cte.blue >> 3));
1277 }
1278 break;
1279 case GDF_32BIT_X888RGB:
1280 for (i = 0; i < ncolors; i++) {
1281 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001282 p[i].ce.dw = SWAP32((cte.red << 16) |
1283 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001284 cte.blue);
1285 }
1286 break;
1287 default:
1288 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001289 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001290 return -1;
1291 }
1292
1293 while (decode) {
1294 switch (bm[0]) {
1295 case 0:
1296 switch (bm[1]) {
1297 case 0:
1298 /* scan line end marker */
1299 bm += 2;
1300 x = 0;
1301 y--;
1302 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001303 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001304 (y + yoff) * VIDEO_LINE_LEN +
1305 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001306 continue;
1307 case 1:
1308 /* end of bitmap data marker */
1309 decode = 0;
1310 break;
1311 case 2:
1312 /* run offset marker */
1313 x += bm[2];
1314 y -= bm[3];
1315 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001316 ((unsigned int) video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001317 (y + yoff) * VIDEO_LINE_LEN +
1318 xoff * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001319 bm += 4;
1320 break;
1321 default:
1322 /* unencoded run */
1323 cnt = bm[1];
1324 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001325 pixels += cnt;
1326 if (pixels > limit)
1327 goto error;
1328
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001329 bm += 2;
1330 if (y < height) {
1331 if (x >= width) {
1332 x += runlen;
1333 goto next_run;
1334 }
1335 if (x + runlen > width)
1336 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001337 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001338 x += runlen;
1339 }
1340next_run:
1341 bm += runlen;
1342 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001343 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001344 }
1345 break;
1346 default:
1347 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001348 cnt = bm[0];
1349 runlen = cnt;
1350 pixels += cnt;
1351 if (pixels > limit)
1352 goto error;
1353
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001354 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001355 if (x >= width) {
1356 x += runlen;
1357 bm += 2;
1358 continue;
1359 }
1360 if (x + runlen > width)
1361 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001362 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001363 x += runlen;
1364 }
1365 bm += 2;
1366 break;
1367 }
1368 }
1369 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001370error:
1371 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1372 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001373}
1374#endif
1375
1376/*
wdenke55402c2004-03-14 16:51:43 +00001377 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001378 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001379int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001380{
1381 ushort xcount, ycount;
1382 uchar *fb;
Simon Glass92e1f852015-05-13 07:02:27 -06001383 struct bmp_image *bmp = (struct bmp_image *)bmp_image;
wdenke55402c2004-03-14 16:51:43 +00001384 uchar *bmap;
1385 ushort padded_line;
1386 unsigned long width, height, bpp;
1387 unsigned colors;
1388 unsigned long compression;
Simon Glass92e1f852015-05-13 07:02:27 -06001389 struct bmp_color_table_entry cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001390
Stefan Roesed9d97742005-09-22 09:04:17 +02001391#ifdef CONFIG_VIDEO_BMP_GZIP
1392 unsigned char *dst = NULL;
1393 ulong len;
1394#endif
wdenkc6097192002-11-03 00:24:07 +00001395
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001396 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001397
1398 if (!((bmp->header.signature[0] == 'B') &&
1399 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001400
1401#ifdef CONFIG_VIDEO_BMP_GZIP
1402 /*
1403 * Could be a gzipped bmp image, try to decrompress...
1404 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001405 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1406 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001407 if (dst == NULL) {
1408 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001409 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001410 }
Eric Nelsonfba70872014-03-08 07:55:52 -07001411 /*
1412 * NB: we need to force offset of +2
1413 * See doc/README.displaying-bmps
1414 */
1415 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001416 (uchar *) bmp_image,
1417 &len) != 0) {
1418 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1419 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001420 free(dst);
1421 return 1;
1422 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001423 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001424 printf("Image could be truncated "
1425 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001426 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001427
1428 /*
1429 * Set addr to decompressed image
1430 */
Simon Glass92e1f852015-05-13 07:02:27 -06001431 bmp = (struct bmp_image *)(dst+2);
Stefan Roesed9d97742005-09-22 09:04:17 +02001432
1433 if (!((bmp->header.signature[0] == 'B') &&
1434 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001435 printf("Error: no valid bmp.gz image at %lx\n",
1436 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001437 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001438 return 1;
1439 }
1440#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001441 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001442 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001443#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001444 }
1445
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001446 width = le32_to_cpu(bmp->header.width);
1447 height = le32_to_cpu(bmp->header.height);
1448 bpp = le16_to_cpu(bmp->header.bit_count);
1449 colors = le32_to_cpu(bmp->header.colors_used);
1450 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001451
Marek Vasut2eb9a492011-10-21 14:17:04 +00001452 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001453 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001454
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001455 if (compression != BMP_BI_RGB
1456#ifdef CONFIG_VIDEO_BMP_RLE8
1457 && compression != BMP_BI_RLE8
1458#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001459 ) {
1460 printf("Error: compression type %ld not supported\n",
1461 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001462#ifdef CONFIG_VIDEO_BMP_GZIP
1463 if (dst)
1464 free(dst);
1465#endif
wdenke55402c2004-03-14 16:51:43 +00001466 return 1;
1467 }
1468
1469 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1470
Matthias Weisser53884182009-07-09 16:07:30 +02001471#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1472 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001473 x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001474 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001475 x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001476
1477 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001478 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
Matthias Weisser53884182009-07-09 16:07:30 +02001479 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001480 y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
Matthias Weisser53884182009-07-09 16:07:30 +02001481#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1482
Matthias Weisser5e5ed762013-02-15 03:35:12 +00001483 /*
1484 * Just ignore elements which are completely beyond screen
1485 * dimensions.
1486 */
1487 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1488 return 0;
1489
wdenke55402c2004-03-14 16:51:43 +00001490 if ((x + width) > VIDEO_VISIBLE_COLS)
1491 width = VIDEO_VISIBLE_COLS - x;
1492 if ((y + height) > VIDEO_VISIBLE_ROWS)
1493 height = VIDEO_VISIBLE_ROWS - y;
1494
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001495 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001496 fb = (uchar *) (video_fb_address +
Hans de Goedea8287e72015-08-04 12:15:39 +02001497 ((y + height - 1) * VIDEO_LINE_LEN) +
wdenke55402c2004-03-14 16:51:43 +00001498 x * VIDEO_PIXEL_SIZE);
1499
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001500#ifdef CONFIG_VIDEO_BMP_RLE8
1501 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001502 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001503 }
1504#endif
1505
Timur Tabi0fce9922010-08-23 16:58:00 -05001506 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001507 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001508 case 4:
1509 padded_line -= width / 2;
1510 ycount = height;
1511
1512 switch (VIDEO_DATA_FORMAT) {
1513 case GDF_32BIT_X888RGB:
1514 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001515 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001516 /*
1517 * Don't assume that 'width' is an
1518 * even number
1519 */
1520 for (xcount = 0; xcount < width; xcount++) {
1521 uchar idx;
1522
1523 if (xcount & 1) {
1524 idx = *bmap & 0xF;
1525 bmap++;
1526 } else
1527 idx = *bmap >> 4;
1528 cte = bmp->color_table[idx];
1529 FILL_32BIT_X888RGB(cte.red, cte.green,
1530 cte.blue);
1531 }
1532 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001533 fb -= VIDEO_LINE_LEN + width *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001534 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001535 }
1536 break;
1537 default:
1538 puts("4bpp bitmap unsupported with current "
1539 "video mode\n");
1540 break;
1541 }
1542 break;
1543
wdenke55402c2004-03-14 16:51:43 +00001544 case 8:
1545 padded_line -= width;
1546 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001547 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001548 for (xcount = 0; xcount < colors; ++xcount) {
1549 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001550 video_set_lut(xcount, cte.red, cte.green,
1551 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001552 }
1553 }
1554 ycount = height;
1555 switch (VIDEO_DATA_FORMAT) {
1556 case GDF__8BIT_INDEX:
1557 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001558 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001559 xcount = width;
1560 while (xcount--) {
1561 *fb++ = *bmap++;
1562 }
1563 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001564 fb -= VIDEO_LINE_LEN + width *
1565 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001566 }
1567 break;
1568 case GDF__8BIT_332RGB:
1569 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001570 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001571 xcount = width;
1572 while (xcount--) {
1573 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001574 FILL_8BIT_332RGB(cte.red, cte.green,
1575 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001576 }
1577 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001578 fb -= VIDEO_LINE_LEN + width *
1579 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001580 }
1581 break;
1582 case GDF_15BIT_555RGB:
1583 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001584#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1585 int xpos = x;
1586#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001587 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001588 xcount = width;
1589 while (xcount--) {
1590 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001591#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001592 fill_555rgb_pswap(fb, xpos++, cte.red,
1593 cte.green,
1594 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001595 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001596#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001597 FILL_15BIT_555RGB(cte.red, cte.green,
1598 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001599#endif
wdenke55402c2004-03-14 16:51:43 +00001600 }
1601 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001602 fb -= VIDEO_LINE_LEN + width *
1603 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001604 }
1605 break;
1606 case GDF_16BIT_565RGB:
1607 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001608 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001609 xcount = width;
1610 while (xcount--) {
1611 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001612 FILL_16BIT_565RGB(cte.red, cte.green,
1613 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001614 }
1615 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001616 fb -= VIDEO_LINE_LEN + width *
1617 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001618 }
1619 break;
1620 case GDF_32BIT_X888RGB:
1621 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001622 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001623 xcount = width;
1624 while (xcount--) {
1625 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001626 FILL_32BIT_X888RGB(cte.red, cte.green,
1627 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001628 }
1629 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001630 fb -= VIDEO_LINE_LEN + width *
1631 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001632 }
1633 break;
1634 case GDF_24BIT_888RGB:
1635 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001636 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001637 xcount = width;
1638 while (xcount--) {
1639 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001640 FILL_24BIT_888RGB(cte.red, cte.green,
1641 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001642 }
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 }
1649 break;
1650 case 24:
1651 padded_line -= 3 * width;
1652 ycount = height;
1653 switch (VIDEO_DATA_FORMAT) {
1654 case GDF__8BIT_332RGB:
1655 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001656 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001657 xcount = width;
1658 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001659 FILL_8BIT_332RGB(bmap[2], bmap[1],
1660 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001661 bmap += 3;
1662 }
1663 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001664 fb -= VIDEO_LINE_LEN + width *
1665 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001666 }
1667 break;
1668 case GDF_15BIT_555RGB:
1669 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001670#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1671 int xpos = x;
1672#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001673 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001674 xcount = width;
1675 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001676#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001677 fill_555rgb_pswap(fb, xpos++, bmap[2],
1678 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001679 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001680#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001681 FILL_15BIT_555RGB(bmap[2], bmap[1],
1682 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001683#endif
wdenke55402c2004-03-14 16:51:43 +00001684 bmap += 3;
1685 }
1686 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001687 fb -= VIDEO_LINE_LEN + width *
1688 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001689 }
1690 break;
1691 case GDF_16BIT_565RGB:
1692 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001693 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001694 xcount = width;
1695 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001696 FILL_16BIT_565RGB(bmap[2], bmap[1],
1697 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001698 bmap += 3;
1699 }
1700 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001701 fb -= VIDEO_LINE_LEN + width *
1702 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001703 }
1704 break;
1705 case GDF_32BIT_X888RGB:
1706 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001707 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001708 xcount = width;
1709 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001710 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1711 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001712 bmap += 3;
1713 }
1714 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001715 fb -= VIDEO_LINE_LEN + width *
1716 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001717 }
1718 break;
1719 case GDF_24BIT_888RGB:
1720 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001721 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001722 xcount = width;
1723 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001724 FILL_24BIT_888RGB(bmap[2], bmap[1],
1725 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001726 bmap += 3;
1727 }
1728 bmap += padded_line;
Hans de Goedea8287e72015-08-04 12:15:39 +02001729 fb -= VIDEO_LINE_LEN + width *
1730 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001731 }
1732 break;
1733 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001734 printf("Error: 24 bits/pixel bitmap incompatible "
1735 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001736 break;
1737 }
1738 break;
1739 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001740 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1741 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001742 break;
1743 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001744
1745#ifdef CONFIG_VIDEO_BMP_GZIP
1746 if (dst) {
1747 free(dst);
1748 }
1749#endif
1750
Eric Nelson54142422013-05-06 14:27:28 +02001751 if (cfb_do_flush_cache)
1752 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenke55402c2004-03-14 16:51:43 +00001753 return (0);
wdenkc6097192002-11-03 00:24:07 +00001754}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001755#endif
wdenkc6097192002-11-03 00:24:07 +00001756
wdenkc6097192002-11-03 00:24:07 +00001757
1758#ifdef CONFIG_VIDEO_LOGO
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001759static int video_logo_xpos;
1760static int video_logo_ypos;
1761
Hans de Goedeb922f782015-08-04 12:21:40 +02001762static void plot_logo_or_black(void *screen, int x, int y, int black);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001763
Hans de Goedeb922f782015-08-04 12:21:40 +02001764static void logo_plot(void *screen, int x, int y)
Bastian Ruppertd5932182012-09-13 22:29:02 +00001765{
Hans de Goedeb922f782015-08-04 12:21:40 +02001766 plot_logo_or_black(screen, x, y, 0);
Bastian Ruppertd5932182012-09-13 22:29:02 +00001767}
1768
1769static void logo_black(void)
1770{
Hans de Goedeb922f782015-08-04 12:21:40 +02001771 plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
Bastian Ruppertd5932182012-09-13 22:29:02 +00001772 1);
1773}
1774
1775static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1776{
1777 if (argc != 1)
1778 return cmd_usage(cmdtp);
1779
1780 logo_black();
1781 return 0;
1782}
1783
1784U_BOOT_CMD(
1785 clrlogo, 1, 0, do_clrlogo,
1786 "fill the boot logo area with black",
1787 " "
1788 );
1789
Hans de Goedeb922f782015-08-04 12:21:40 +02001790static void plot_logo_or_black(void *screen, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001791{
wdenk9dd2b882002-12-03 21:28:10 +00001792
wdenke55402c2004-03-14 16:51:43 +00001793 int xcount, i;
Hans de Goedea8287e72015-08-04 12:15:39 +02001794 int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001795 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001796 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1797 unsigned char *source;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001798 unsigned char *dest;
1799
1800#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1801 if (x == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001802 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001803 else if (x < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001804 x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001805
1806 if (y == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001807 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001808 else if (y < 0)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001809 y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001810#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1811
Hans de Goedea8287e72015-08-04 12:15:39 +02001812 dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001813
wdenk9dd2b882002-12-03 21:28:10 +00001814#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001815 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001816
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001817 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001818 logo_red = malloc(BMP_LOGO_COLORS);
1819 logo_green = malloc(BMP_LOGO_COLORS);
1820 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001821 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001822 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1823 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1824 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1825 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1826 }
wdenk9dd2b882002-12-03 21:28:10 +00001827#else
wdenke55402c2004-03-14 16:51:43 +00001828 source = linux_logo;
1829 logo_red = linux_logo_red;
1830 logo_green = linux_logo_green;
1831 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001832#endif
wdenk57b2d802003-06-27 21:31:46 +00001833
wdenke55402c2004-03-14 16:51:43 +00001834 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1835 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001836 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1837 logo_red[i], logo_green[i],
1838 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001839 }
wdenk57b2d802003-06-27 21:31:46 +00001840 }
wdenkc6097192002-11-03 00:24:07 +00001841
wdenke55402c2004-03-14 16:51:43 +00001842 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001843#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1844 int xpos = x;
1845#endif
wdenke55402c2004-03-14 16:51:43 +00001846 xcount = VIDEO_LOGO_WIDTH;
1847 while (xcount--) {
Bastian Ruppertd5932182012-09-13 22:29:02 +00001848 if (black) {
1849 r = 0x00;
1850 g = 0x00;
1851 b = 0x00;
1852 } else {
1853 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1854 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1855 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1856 }
wdenk57b2d802003-06-27 21:31:46 +00001857
wdenke55402c2004-03-14 16:51:43 +00001858 switch (VIDEO_DATA_FORMAT) {
1859 case GDF__8BIT_INDEX:
1860 *dest = *source;
1861 break;
1862 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001863 *dest = ((r >> 5) << 5) |
1864 ((g >> 5) << 2) |
1865 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001866 break;
1867 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001868#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001869 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001870#else
wdenke55402c2004-03-14 16:51:43 +00001871 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001872 SWAP16((unsigned short) (
1873 ((r >> 3) << 10) |
1874 ((g >> 3) << 5) |
1875 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001876#endif
wdenke55402c2004-03-14 16:51:43 +00001877 break;
1878 case GDF_16BIT_565RGB:
1879 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001880 SWAP16((unsigned short) (
1881 ((r >> 3) << 11) |
1882 ((g >> 2) << 5) |
1883 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001884 break;
1885 case GDF_32BIT_X888RGB:
1886 *(unsigned long *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001887 SWAP32((unsigned long) (
1888 (r << 16) |
1889 (g << 8) |
1890 b));
wdenke55402c2004-03-14 16:51:43 +00001891 break;
1892 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001893#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001894 dest[0] = b;
1895 dest[1] = g;
1896 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001897#else
wdenke55402c2004-03-14 16:51:43 +00001898 dest[0] = r;
1899 dest[1] = g;
1900 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001901#endif
wdenke55402c2004-03-14 16:51:43 +00001902 break;
1903 }
1904 source++;
1905 dest += VIDEO_PIXEL_SIZE;
1906 }
1907 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001908 }
wdenk9dd2b882002-12-03 21:28:10 +00001909#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001910 free(logo_red);
1911 free(logo_green);
1912 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001913#endif
wdenkc6097192002-11-03 00:24:07 +00001914}
1915
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001916static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001917{
wdenke55402c2004-03-14 16:51:43 +00001918 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001919 __maybe_unused int y_off = 0;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001920 __maybe_unused ulong addr;
1921 __maybe_unused char *s;
Tim Harvey98899462016-05-24 14:59:59 -07001922 __maybe_unused int len, space;
wdenke55402c2004-03-14 16:51:43 +00001923
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +02001924 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
wdenke55402c2004-03-14 16:51:43 +00001925
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001926#ifdef CONFIG_SPLASH_SCREEN
1927 s = getenv("splashimage");
1928 if (s != NULL) {
Robert Winkler2a90ed02013-06-17 11:31:29 -07001929 splash_screen_prepare();
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001930 addr = simple_strtoul(s, NULL, 16);
1931
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001932 if (video_display_bitmap(addr,
1933 video_logo_xpos,
1934 video_logo_ypos) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001935 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001936 return ((void *) (video_fb_address));
1937 }
1938 }
1939#endif /* CONFIG_SPLASH_SCREEN */
1940
Hans de Goedeb922f782015-08-04 12:21:40 +02001941 logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001942
1943#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1944 /*
1945 * when using splashpos for video_logo, skip any info
1946 * output on video console if the logo is not at 0,0
1947 */
1948 if (video_logo_xpos || video_logo_ypos) {
1949 /*
1950 * video_logo_height is used in text and cursor offset
1951 * calculations. Since the console is below the logo,
1952 * we need to adjust the logo height
1953 */
1954 if (video_logo_ypos == BMP_ALIGN_CENTER)
Masahiro Yamadadb204642014-11-07 03:03:31 +09001955 video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001956 VIDEO_LOGO_HEIGHT) / 2);
1957 else if (video_logo_ypos > 0)
1958 video_logo_height += video_logo_ypos;
1959
1960 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
1961 }
1962#endif
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02001963 if (board_cfb_skip())
1964 return 0;
wdenkc6097192002-11-03 00:24:07 +00001965
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001966 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001967
Tim Harvey98899462016-05-24 14:59:59 -07001968#ifndef CONFIG_HIDE_LOGO_VERSION
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001969 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1970 len = strlen(info);
1971
1972 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001973 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
1974 (uchar *) info, space);
1975 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1976 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1977 (uchar *) info + space, len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001978 y_off = 1;
1979 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001980 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00001981
1982#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001983 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001984 int i, n =
1985 ((video_logo_height -
1986 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001987
wdenke55402c2004-03-14 16:51:43 +00001988 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001989 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001990 if (!*info)
1991 continue;
1992
1993 len = strlen(info);
1994 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001995 video_drawchars(VIDEO_INFO_X,
1996 VIDEO_INFO_Y +
1997 (i + y_off) *
1998 VIDEO_FONT_HEIGHT,
1999 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002000 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002001 video_drawchars(VIDEO_INFO_X +
2002 VIDEO_FONT_WIDTH,
2003 VIDEO_INFO_Y +
2004 (i + y_off) *
2005 VIDEO_FONT_HEIGHT,
2006 (uchar *) info + space,
2007 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002008 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002009 video_drawstring(VIDEO_INFO_X,
2010 VIDEO_INFO_Y +
2011 (i + y_off) *
2012 VIDEO_FONT_HEIGHT,
2013 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002014 }
wdenke55402c2004-03-14 16:51:43 +00002015 }
2016 }
wdenkc6097192002-11-03 00:24:07 +00002017#endif
Tim Harvey98899462016-05-24 14:59:59 -07002018#endif
wdenkc6097192002-11-03 00:24:07 +00002019
Matthias Weisser76d70862010-01-12 12:06:31 +01002020 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002021}
2022#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002023
2024static int cfb_fb_is_in_dram(void)
2025{
2026 bd_t *bd = gd->bd;
2027#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2028defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2029 ulong start, end;
2030 int i;
2031
2032 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2033 start = bd->bi_dram[i].start;
2034 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2035 if ((ulong)video_fb_address >= start &&
2036 (ulong)video_fb_address < end)
2037 return 1;
2038 }
2039#else
2040 if ((ulong)video_fb_address >= bd->bi_memstart &&
2041 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2042 return 1;
2043#endif
2044 return 0;
2045}
wdenkc6097192002-11-03 00:24:07 +00002046
Heiko Schocher62759562013-10-22 11:06:06 +02002047void video_clear(void)
2048{
2049 if (!video_fb_address)
2050 return;
2051#ifdef VIDEO_HW_RECTFILL
2052 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2053 0, /* dest pos x */
2054 0, /* dest pos y */
2055 VIDEO_VISIBLE_COLS, /* frame width */
2056 VIDEO_VISIBLE_ROWS, /* frame height */
2057 bgx /* fill color */
2058 );
2059#else
2060 memsetl(video_fb_address,
2061 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2062#endif
2063}
2064
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002065static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002066{
wdenke55402c2004-03-14 16:51:43 +00002067 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002068
Wolfgang Denka87b2a952011-07-30 12:48:09 +00002069 pGD = video_hw_init();
2070 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00002071 return -1;
wdenkc6097192002-11-03 00:24:07 +00002072
wdenke55402c2004-03-14 16:51:43 +00002073 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002074#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002075 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002076#endif
2077
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002078 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2079
wdenke55402c2004-03-14 16:51:43 +00002080 /* Init drawing pats */
2081 switch (VIDEO_DATA_FORMAT) {
2082 case GDF__8BIT_INDEX:
Simon Glass884889d2016-10-17 20:12:44 -06002083 video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
2084 CONFIG_SYS_CONSOLE_FG_COL,
2085 CONFIG_SYS_CONSOLE_FG_COL);
2086 video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
2087 CONFIG_SYS_CONSOLE_BG_COL,
2088 CONFIG_SYS_CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00002089 fgx = 0x01010101;
2090 bgx = 0x00000000;
2091 break;
2092 case GDF__8BIT_332RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002093 color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
2094 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
2095 CONFIG_SYS_CONSOLE_FG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002096 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2097 color8;
Simon Glass884889d2016-10-17 20:12:44 -06002098 color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
2099 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
2100 CONFIG_SYS_CONSOLE_BG_COL >> 6);
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002101 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2102 color8;
wdenke55402c2004-03-14 16:51:43 +00002103 break;
2104 case GDF_15BIT_555RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002105 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
2106 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
2107 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2108 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
2109 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
2110 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2111 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
2112 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
2113 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2114 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
2115 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
2116 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002117 break;
2118 case GDF_16BIT_565RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002119 fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
2120 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
2121 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
2122 ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
2123 ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
2124 (CONFIG_SYS_CONSOLE_FG_COL >> 3));
2125 bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
2126 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
2127 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
2128 ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
2129 ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
2130 (CONFIG_SYS_CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002131 break;
2132 case GDF_32BIT_X888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002133 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2134 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2135 CONFIG_SYS_CONSOLE_FG_COL;
2136 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2137 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2138 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002139 break;
2140 case GDF_24BIT_888RGB:
Simon Glass884889d2016-10-17 20:12:44 -06002141 fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
2142 (CONFIG_SYS_CONSOLE_FG_COL << 16) |
2143 (CONFIG_SYS_CONSOLE_FG_COL << 8) |
2144 CONFIG_SYS_CONSOLE_FG_COL;
2145 bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
2146 (CONFIG_SYS_CONSOLE_BG_COL << 16) |
2147 (CONFIG_SYS_CONSOLE_BG_COL << 8) |
2148 CONFIG_SYS_CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002149 break;
2150 }
2151 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002152
Heiko Schocher62759562013-10-22 11:06:06 +02002153 video_clear();
2154
wdenkc6097192002-11-03 00:24:07 +00002155#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00002156 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00002157 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002158 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002159#else
wdenke55402c2004-03-14 16:51:43 +00002160 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002161#endif
2162
wdenke55402c2004-03-14 16:51:43 +00002163 /* Initialize the console */
2164 console_col = 0;
2165 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002166
Eric Nelson54142422013-05-06 14:27:28 +02002167 if (cfb_do_flush_cache)
2168 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2169
wdenke55402c2004-03-14 16:51:43 +00002170 return 0;
wdenkc6097192002-11-03 00:24:07 +00002171}
2172
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002173/*
2174 * Implement a weak default function for boards that optionally
2175 * need to skip the video initialization.
2176 */
Jeroen Hofsteef7ae3ed2014-10-08 22:57:30 +02002177__weak int board_video_skip(void)
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002178{
2179 /* As default, don't skip test */
2180 return 0;
2181}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002182
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002183int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002184{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02002185 struct stdio_dev console_dev;
Simon Glasse9fa1f02015-03-02 12:40:50 -07002186 bool have_keyboard;
Bin Menge52e17a2015-08-24 01:00:07 -07002187 bool __maybe_unused keyboard_ok = false;
wdenkc6097192002-11-03 00:24:07 +00002188
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002189 /* Check if video initialization should be skipped */
2190 if (board_video_skip())
2191 return 0;
2192
wdenk7dd13292004-07-11 20:04:51 +00002193 /* Init video chip - returns with framebuffer cleared */
Bin Menge52e17a2015-08-24 01:00:07 -07002194 if (video_init() == -1)
2195 return 0;
wdenkc6097192002-11-03 00:24:07 +00002196
Heiko Schocher9cff8ad2013-08-03 07:22:53 +02002197 if (board_cfb_skip())
2198 return 0;
2199
Simon Glasse9fa1f02015-03-02 12:40:50 -07002200#if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2201 have_keyboard = false;
2202#elif defined(CONFIG_OF_CONTROL)
2203 have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
2204 "u-boot,no-keyboard");
2205#else
2206 have_keyboard = true;
2207#endif
2208 if (have_keyboard) {
2209 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002210#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002211 keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002212#endif
Simon Glasse9fa1f02015-03-02 12:40:50 -07002213 }
wdenkc6097192002-11-03 00:24:07 +00002214
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002215 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002216 memset(&console_dev, 0, sizeof(console_dev));
2217 strcpy(console_dev.name, "vga");
Bin Meng6abe4b62015-11-03 23:23:37 -08002218 console_dev.flags = DEV_FLAGS_OUTPUT;
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002219 console_dev.putc = video_putc; /* 'putc' function */
2220 console_dev.puts = video_puts; /* 'puts' function */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002221
2222#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Bin Menge52e17a2015-08-24 01:00:07 -07002223 if (have_keyboard && keyboard_ok) {
Simon Glasse9fa1f02015-03-02 12:40:50 -07002224 /* Also init console device */
2225 console_dev.flags |= DEV_FLAGS_INPUT;
2226 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2227 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
2228 }
2229#endif
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002230
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002231 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002232 return 0;
2233
2234 /* Return success */
2235 return 1;
wdenkc6097192002-11-03 00:24:07 +00002236}
Stefan Reinauer7870da32012-09-28 15:11:12 +00002237
2238void video_position_cursor(unsigned col, unsigned row)
2239{
2240 console_col = min(col, CONSOLE_COLS - 1);
2241 console_row = min(row, CONSOLE_ROWS - 1);
2242}
2243
2244int video_get_pixel_width(void)
2245{
2246 return VIDEO_VISIBLE_COLS;
2247}
2248
2249int video_get_pixel_height(void)
2250{
2251 return VIDEO_VISIBLE_ROWS;
2252}
2253
2254int video_get_screen_rows(void)
2255{
2256 return CONSOLE_ROWS;
2257}
2258
2259int video_get_screen_columns(void)
2260{
2261 return CONSOLE_COLS;
2262}