blob: b52e9edd25277c4b79acc7c7754ca1881530ada1 [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 *
18 * The console driver can use the standard PC keyboard interface (i8042)
19 * for character input. Character output goes to a memory mapped video
20 * framebuffer with little or big-endian organisation.
21 * With environment setting 'console=serial' the console i/o can be
22 * forced to serial port.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000023 *
24 * The driver uses graphic specific defines/parameters/functions:
25 *
26 * (for SMI LynxE graphic chip)
27 *
28 * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
29 * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
30 * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
31 * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
32 *
33 * Console Parameters are set by graphic drivers global struct:
34 *
35 * VIDEO_VISIBLE_COLS - x resolution
36 * VIDEO_VISIBLE_ROWS - y resolution
37 * VIDEO_PIXEL_SIZE - storage size in byte per pixel
38 * VIDEO_DATA_FORMAT - graphical data format GDF
39 * VIDEO_FB_ADRS - start of video memory
40 *
41 * CONFIG_I8042_KBD - AT Keyboard driver for i8042
42 * VIDEO_KBD_INIT_FCT - init function for keyboard
43 * VIDEO_TSTC_FCT - keyboard_tstc function
44 * VIDEO_GETC_FCT - keyboard_getc function
45 *
46 * CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with
47 * delay loop in VIDEO_TSTC_FCT (i8042)
48 *
49 * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
50 * CONFIG_CONSOLE_TIME - display time/date in upper right
51 * corner, needs CONFIG_CMD_DATE and
52 * CONFIG_CONSOLE_CURSOR
Bastian Ruppert1e681f92012-09-13 22:29:01 +000053 * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
54 * Use CONFIG_SPLASH_SCREEN_ALIGN with
55 * environment variable "splashpos" to place
56 * the logo on other position. In this case
57 * no CONSOLE_EXTRA_INFO is possible.
Wolfgang Denk64e40d72011-07-29 09:55:27 +000058 * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
59 * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
60 * strings that normaly goes to serial
61 * port. This define requires a board
62 * specific function:
63 * video_drawstring (VIDEO_INFO_X,
64 * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
65 * info);
66 * that fills a info buffer at i=row.
67 * s.a: board/eltec/bab7xx.
68 * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be
69 * initialized as an output only device.
70 * The Keyboard driver will not be
71 * set-up. This may be used, if you have
72 * no or more than one Keyboard devices
73 * (USB Keyboard, AT Keyboard).
74 *
75 * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
76 * character. No blinking is provided.
77 * Uses the macros CURSOR_SET and
78 * CURSOR_OFF.
79 *
80 * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability
81 * of the graphic chip. Uses the macro
82 * CURSOR_SET. ATTENTION: If booting an
83 * OS, the display driver must disable
84 * the hardware register of the graphic
85 * chip. Otherwise a blinking field is
86 * displayed.
87 */
wdenkc6097192002-11-03 00:24:07 +000088
89#include <common.h>
Andreas Bießmann09c2e902011-07-18 20:24:04 +020090#include <version.h>
wdenka6c7ad22002-12-03 21:28:10 +000091#include <malloc.h>
Wolfgang Denka9a62af2011-11-04 15:55:20 +000092#include <linux/compiler.h>
wdenka6c7ad22002-12-03 21:28:10 +000093
Wolfgang Denk64e40d72011-07-29 09:55:27 +000094/*
95 * Console device defines with SMI graphic
96 * Any other graphic must change this section
97 */
wdenkc6097192002-11-03 00:24:07 +000098
wdenk4b248f32004-03-14 16:51:43 +000099#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000100
101#define VIDEO_FB_LITTLE_ENDIAN
102#define VIDEO_HW_RECTFILL
103#define VIDEO_HW_BITBLT
104#endif
105
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000106/*
107 * Defines for the CT69000 driver
108 */
wdenk4b248f32004-03-14 16:51:43 +0000109#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000110
111#define VIDEO_FB_LITTLE_ENDIAN
112#define VIDEO_HW_RECTFILL
113#define VIDEO_HW_BITBLT
114#endif
115
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000116/*
117 * Defines for the SED13806 driver
118 */
wdenka6c7ad22002-12-03 21:28:10 +0000119#ifdef CONFIG_VIDEO_SED13806
120
wdenk89394042004-08-04 21:56:49 +0000121#ifndef CONFIG_TOTAL5200
wdenka6c7ad22002-12-03 21:28:10 +0000122#define VIDEO_FB_LITTLE_ENDIAN
wdenk89394042004-08-04 21:56:49 +0000123#endif
wdenka6c7ad22002-12-03 21:28:10 +0000124#define VIDEO_HW_RECTFILL
125#define VIDEO_HW_BITBLT
126#endif
127
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000128/*
129 * Defines for the SED13806 driver
130 */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200131#ifdef CONFIG_VIDEO_SM501
132
133#ifdef CONFIG_HH405
134#define VIDEO_FB_LITTLE_ENDIAN
135#endif
136#endif
137
Marek Vasutfb8ddc22013-04-28 09:20:03 +0000138#ifdef CONFIG_VIDEO_MXS
139#define VIDEO_FB_16BPP_WORD_SWAP
140#endif
141
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000142/*
143 * Defines for the MB862xx driver
144 */
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100145#ifdef CONFIG_VIDEO_MB862xx
146
147#ifdef CONFIG_VIDEO_CORALP
148#define VIDEO_FB_LITTLE_ENDIAN
149#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200150#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100151#define VIDEO_HW_RECTFILL
152#define VIDEO_HW_BITBLT
153#endif
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200154#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100155
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000156/*
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000157 * Defines for the i.MX31 driver (mx3fb.c)
158 */
Fabio Estevam695af9a2012-05-31 07:23:56 +0000159#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger62a22dc2011-10-12 23:16:29 +0000160#define VIDEO_FB_16BPP_WORD_SWAP
161#endif
162
163/*
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000164 * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
165 */
wdenkc6097192002-11-03 00:24:07 +0000166#include <video_fb.h>
167
Robert Winklerdd4425e2013-06-17 11:31:29 -0700168#include <splash.h>
169
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000170/*
171 * some Macros
172 */
wdenk4b248f32004-03-14 16:51:43 +0000173#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
174#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
175#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
176#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
177#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000178
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000179/*
180 * Console device defines with i8042 keyboard controller
181 * Any other keyboard controller must change this section
182 */
wdenkc6097192002-11-03 00:24:07 +0000183
wdenk4b248f32004-03-14 16:51:43 +0000184#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000185#include <i8042.h>
186
wdenk4b248f32004-03-14 16:51:43 +0000187#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
188#define VIDEO_TSTC_FCT i8042_tstc
189#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000190#endif
191
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000192/*
193 * Console device
194 */
wdenkc6097192002-11-03 00:24:07 +0000195
196#include <version.h>
197#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200198#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000199#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000200
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500201#if defined(CONFIG_CMD_DATE)
202#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000203#endif
204
Jon Loeliger07d38a12007-07-09 17:30:01 -0500205#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +0000206#include <watchdog.h>
207#include <bmp_layout.h>
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200208#include <splash.h>
Jon Loeliger07d38a12007-07-09 17:30:01 -0500209#endif
wdenk4b248f32004-03-14 16:51:43 +0000210
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000211/*
212 * Cursor definition:
213 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
214 * to let the cursor blink. Uses the macros
215 * CURSOR_OFF and CURSOR_ON.
216 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
217 * blinking is provided. Uses the macros CURSOR_SET
218 * and CURSOR_OFF.
219 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
220 * graphic chip. Uses the macro CURSOR_SET.
221 * ATTENTION: If booting an OS, the display driver
222 * must disable the hardware register of the graphic
223 * chip. Otherwise a blinking field is displayed
224 */
wdenkc6097192002-11-03 00:24:07 +0000225#if !defined(CONFIG_CONSOLE_CURSOR) && \
226 !defined(CONFIG_VIDEO_SW_CURSOR) && \
227 !defined(CONFIG_VIDEO_HW_CURSOR)
228/* no Cursor defined */
229#define CURSOR_ON
230#define CURSOR_OFF
231#define CURSOR_SET
232#endif
233
Gabe Black03d31fc2011-11-30 13:50:50 +0000234#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
235#if defined(CURSOR_ON) || \
236 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000237#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
238 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000239#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000240void console_cursor(int state);
241
Timur Tabi65618632010-08-27 15:45:47 -0500242#define CURSOR_ON console_cursor(1)
243#define CURSOR_OFF console_cursor(0)
Gabe Black03d31fc2011-11-30 13:50:50 +0000244#define CURSOR_SET video_set_cursor()
245#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
246
247#ifdef CONFIG_CONSOLE_CURSOR
248#ifndef CONFIG_CONSOLE_TIME
249#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
250#endif
wdenkc6097192002-11-03 00:24:07 +0000251#ifndef CONFIG_I8042_KBD
Marcel Ziswiler7817cb22007-12-30 03:30:46 +0100252#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000253#endif
wdenkc6097192002-11-03 00:24:07 +0000254#endif /* CONFIG_CONSOLE_CURSOR */
255
wdenkc6097192002-11-03 00:24:07 +0000256
257#ifdef CONFIG_VIDEO_HW_CURSOR
wdenk4b248f32004-03-14 16:51:43 +0000258#ifdef CURSOR_ON
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000259#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
260 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000261#endif
262#define CURSOR_ON
263#define CURSOR_OFF
264#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabi65618632010-08-27 15:45:47 -0500265 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000266#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000267
wdenk4b248f32004-03-14 16:51:43 +0000268#ifdef CONFIG_VIDEO_LOGO
269#ifdef CONFIG_VIDEO_BMP_LOGO
wdenka6c7ad22002-12-03 21:28:10 +0000270#include <bmp_logo.h>
Che-Liang Chiouc2707302011-10-20 23:04:20 +0000271#include <bmp_logo_data.h>
wdenk4b248f32004-03-14 16:51:43 +0000272#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
273#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
274#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
275#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenka6c7ad22002-12-03 21:28:10 +0000276
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000277#else /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000278#define LINUX_LOGO_WIDTH 80
279#define LINUX_LOGO_HEIGHT 80
280#define LINUX_LOGO_COLORS 214
281#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000282#define __initdata
283#include <linux_logo.h>
wdenk4b248f32004-03-14 16:51:43 +0000284#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
285#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
286#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
287#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000288#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000289#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
290#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000291#else /* CONFIG_VIDEO_LOGO */
wdenk4b248f32004-03-14 16:51:43 +0000292#define VIDEO_LOGO_WIDTH 0
293#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000294#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000295
wdenk4b248f32004-03-14 16:51:43 +0000296#define VIDEO_COLS VIDEO_VISIBLE_COLS
297#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
298#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
299#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
300#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
301#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000302
wdenk4b248f32004-03-14 16:51:43 +0000303#ifdef CONFIG_VIDEO_LOGO
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100304#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000305#else
wdenk4b248f32004-03-14 16:51:43 +0000306#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000307#endif
308
wdenk4b248f32004-03-14 16:51:43 +0000309#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
310#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
311#define CONSOLE_ROW_FIRST (video_console_address)
312#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
313#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
314#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
315#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000316
317/* Macros */
wdenk4b248f32004-03-14 16:51:43 +0000318#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000319#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
320 ((x) >> 8) \
321 )
322#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
323 (((x) & 0x0000ff00) << 8) | \
324 (((x) & 0x00ff0000) >> 8) | \
325 (((x) & 0xff000000) >> 24) \
326 )
327#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
328 (((x) & 0x0000ff00) >> 8) | \
329 (((x) & 0x00ff0000) << 8) | \
330 (((x) & 0xff000000) >> 8) \
331 )
wdenkc6097192002-11-03 00:24:07 +0000332#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000333#define SWAP16(x) (x)
334#define SWAP32(x) (x)
Wolfgang Grandegger229b6dc2009-10-23 12:03:15 +0200335#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000336#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyercc347802008-08-29 12:30:39 -0500337#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000338#define SHORTSWAP32(x) (x)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100339#endif
wdenkc6097192002-11-03 00:24:07 +0000340#endif
341
wdenkc6097192002-11-03 00:24:07 +0000342#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000343/*
344 * setup a board string: type, speed, etc.
345 *
346 * line_number: location to place info string beside logo
347 * info: buffer for info string
348 */
349extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000350#endif
351
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200352DECLARE_GLOBAL_DATA_PTR;
353
wdenkc6097192002-11-03 00:24:07 +0000354/* Locals */
355static GraphicDevice *pGD; /* Pointer to Graphic array */
356
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000357static void *video_fb_address; /* frame buffer address */
wdenk4b248f32004-03-14 16:51:43 +0000358static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000359
Matthias Weisserbe129aa2010-01-12 12:06:31 +0100360static int video_logo_height = VIDEO_LOGO_HEIGHT;
361
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000362static int __maybe_unused cursor_state;
363static int __maybe_unused old_col;
364static int __maybe_unused old_row;
Gabe Black03d31fc2011-11-30 13:50:50 +0000365
Wolfgang Denk57912932011-07-30 12:48:09 +0000366static int console_col; /* cursor col */
367static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000368
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000369static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000370
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +0200371static int cfb_do_flush_cache;
372
Pali Rohár33a35bb2012-10-19 13:30:09 +0000373#ifdef CONFIG_CFB_CONSOLE_ANSI
374static char ansi_buf[10];
375static int ansi_buf_size;
376static int ansi_colors_need_revert;
377static int ansi_cursor_hidden;
378#endif
379
wdenkc6097192002-11-03 00:24:07 +0000380static const int video_font_draw_table8[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000381 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
382 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
383 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
384 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
385};
wdenkc6097192002-11-03 00:24:07 +0000386
387static const int video_font_draw_table15[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000388 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
389};
wdenkc6097192002-11-03 00:24:07 +0000390
391static const int video_font_draw_table16[] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000392 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
393};
wdenkc6097192002-11-03 00:24:07 +0000394
395static const int video_font_draw_table24[16][3] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000396 {0x00000000, 0x00000000, 0x00000000},
397 {0x00000000, 0x00000000, 0x00ffffff},
398 {0x00000000, 0x0000ffff, 0xff000000},
399 {0x00000000, 0x0000ffff, 0xffffffff},
400 {0x000000ff, 0xffff0000, 0x00000000},
401 {0x000000ff, 0xffff0000, 0x00ffffff},
402 {0x000000ff, 0xffffffff, 0xff000000},
403 {0x000000ff, 0xffffffff, 0xffffffff},
404 {0xffffff00, 0x00000000, 0x00000000},
405 {0xffffff00, 0x00000000, 0x00ffffff},
406 {0xffffff00, 0x0000ffff, 0xff000000},
407 {0xffffff00, 0x0000ffff, 0xffffffff},
408 {0xffffffff, 0xffff0000, 0x00000000},
409 {0xffffffff, 0xffff0000, 0x00ffffff},
410 {0xffffffff, 0xffffffff, 0xff000000},
411 {0xffffffff, 0xffffffff, 0xffffffff}
412};
wdenkc6097192002-11-03 00:24:07 +0000413
414static const int video_font_draw_table32[16][4] = {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000415 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
416 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
417 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
418 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
419 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
420 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
421 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
422 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
423 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
424 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
425 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
426 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
427 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
428 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
429 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
430 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
431};
wdenkc6097192002-11-03 00:24:07 +0000432
Heiko Schocher2bc4aa52013-08-03 07:22:53 +0200433/*
434 * Implement a weak default function for boards that optionally
435 * need to skip the cfb initialization.
436 */
437__weak int board_cfb_skip(void)
438{
439 /* As default, don't skip cfb init */
440 return 0;
441}
442
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000443static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000444{
wdenk4b248f32004-03-14 16:51:43 +0000445 u8 *cdat, *dest, *dest0;
446 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000447
wdenk4b248f32004-03-14 16:51:43 +0000448 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
449 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000450
wdenk4b248f32004-03-14 16:51:43 +0000451 switch (VIDEO_DATA_FORMAT) {
452 case GDF__8BIT_INDEX:
453 case GDF__8BIT_332RGB:
454 while (count--) {
455 c = *s;
456 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
457 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000458 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000459 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000460
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000461 ((u32 *) dest)[0] =
462 (video_font_draw_table8[bits >> 4] &
463 eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200464
465 if (VIDEO_FONT_WIDTH == 4)
466 continue;
467
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000468 ((u32 *) dest)[1] =
469 (video_font_draw_table8[bits & 15] &
470 eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000471 }
472 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
473 s++;
474 }
475 break;
wdenkc6097192002-11-03 00:24:07 +0000476
wdenk4b248f32004-03-14 16:51:43 +0000477 case GDF_15BIT_555RGB:
478 while (count--) {
479 c = *s;
480 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
481 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000482 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000483 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000484
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000485 ((u32 *) dest)[0] =
486 SHORTSWAP32((video_font_draw_table15
487 [bits >> 6] & eorx) ^
488 bgx);
489 ((u32 *) dest)[1] =
490 SHORTSWAP32((video_font_draw_table15
491 [bits >> 4 & 3] & eorx) ^
492 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200493
494 if (VIDEO_FONT_WIDTH == 4)
495 continue;
496
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000497 ((u32 *) dest)[2] =
498 SHORTSWAP32((video_font_draw_table15
499 [bits >> 2 & 3] & eorx) ^
500 bgx);
501 ((u32 *) dest)[3] =
502 SHORTSWAP32((video_font_draw_table15
503 [bits & 3] & eorx) ^
504 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000505 }
506 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
507 s++;
508 }
509 break;
wdenkc6097192002-11-03 00:24:07 +0000510
wdenk4b248f32004-03-14 16:51:43 +0000511 case GDF_16BIT_565RGB:
512 while (count--) {
513 c = *s;
514 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
515 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000516 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000517 u8 bits = *cdat++;
518
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000519 ((u32 *) dest)[0] =
520 SHORTSWAP32((video_font_draw_table16
521 [bits >> 6] & eorx) ^
522 bgx);
523 ((u32 *) dest)[1] =
524 SHORTSWAP32((video_font_draw_table16
525 [bits >> 4 & 3] & eorx) ^
526 bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200527
528 if (VIDEO_FONT_WIDTH == 4)
529 continue;
530
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000531 ((u32 *) dest)[2] =
532 SHORTSWAP32((video_font_draw_table16
533 [bits >> 2 & 3] & eorx) ^
534 bgx);
535 ((u32 *) dest)[3] =
536 SHORTSWAP32((video_font_draw_table16
537 [bits & 3] & eorx) ^
538 bgx);
wdenk4b248f32004-03-14 16:51:43 +0000539 }
540 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
541 s++;
542 }
543 break;
544
545 case GDF_32BIT_X888RGB:
546 while (count--) {
547 c = *s;
548 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
549 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000550 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000551 u8 bits = *cdat++;
552
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000553 ((u32 *) dest)[0] =
554 SWAP32((video_font_draw_table32
555 [bits >> 4][0] & eorx) ^ bgx);
556 ((u32 *) dest)[1] =
557 SWAP32((video_font_draw_table32
558 [bits >> 4][1] & eorx) ^ bgx);
559 ((u32 *) dest)[2] =
560 SWAP32((video_font_draw_table32
561 [bits >> 4][2] & eorx) ^ bgx);
562 ((u32 *) dest)[3] =
563 SWAP32((video_font_draw_table32
564 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasutfd8cf992013-07-30 23:37:59 +0200565
566
567 if (VIDEO_FONT_WIDTH == 4)
568 continue;
569
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000570 ((u32 *) dest)[4] =
571 SWAP32((video_font_draw_table32
572 [bits & 15][0] & eorx) ^ bgx);
573 ((u32 *) dest)[5] =
574 SWAP32((video_font_draw_table32
575 [bits & 15][1] & eorx) ^ bgx);
576 ((u32 *) dest)[6] =
577 SWAP32((video_font_draw_table32
578 [bits & 15][2] & eorx) ^ bgx);
579 ((u32 *) dest)[7] =
580 SWAP32((video_font_draw_table32
581 [bits & 15][3] & eorx) ^ bgx);
wdenk4b248f32004-03-14 16:51:43 +0000582 }
583 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
584 s++;
585 }
586 break;
587
588 case GDF_24BIT_888RGB:
589 while (count--) {
590 c = *s;
591 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
592 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000593 rows--; dest += VIDEO_LINE_LEN) {
wdenk4b248f32004-03-14 16:51:43 +0000594 u8 bits = *cdat++;
595
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000596 ((u32 *) dest)[0] =
597 (video_font_draw_table24[bits >> 4][0]
598 & eorx) ^ bgx;
599 ((u32 *) dest)[1] =
600 (video_font_draw_table24[bits >> 4][1]
601 & eorx) ^ bgx;
602 ((u32 *) dest)[2] =
603 (video_font_draw_table24[bits >> 4][2]
604 & eorx) ^ bgx;
Marek Vasutfd8cf992013-07-30 23:37:59 +0200605
606 if (VIDEO_FONT_WIDTH == 4)
607 continue;
608
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000609 ((u32 *) dest)[3] =
610 (video_font_draw_table24[bits & 15][0]
611 & eorx) ^ bgx;
612 ((u32 *) dest)[4] =
613 (video_font_draw_table24[bits & 15][1]
614 & eorx) ^ bgx;
615 ((u32 *) dest)[5] =
616 (video_font_draw_table24[bits & 15][2]
617 & eorx) ^ bgx;
wdenk4b248f32004-03-14 16:51:43 +0000618 }
619 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
620 s++;
621 }
622 break;
wdenk8bde7f72003-06-27 21:31:46 +0000623 }
wdenkc6097192002-11-03 00:24:07 +0000624}
625
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000626static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000627{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000628 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000629}
630
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000631static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000632{
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000633 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000634}
635
wdenkc6097192002-11-03 00:24:07 +0000636#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000637static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000638{
Gabe Black03d31fc2011-11-30 13:50:50 +0000639 if (cursor_state)
640 console_cursor(0);
641 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000642}
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000643
Anatolij Gustschina45adde2011-12-07 03:58:10 +0000644static void video_invertchar(int xx, int yy)
645{
646 int firstx = xx * VIDEO_PIXEL_SIZE;
647 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
648 int firsty = yy * VIDEO_LINE_LEN;
649 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
650 int x, y;
651 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
652 for (x = firstx; x < lastx; x++) {
653 u8 *dest = (u8 *)(video_fb_address) + x + y;
654 *dest = ~*dest;
655 }
656 }
657}
Gabe Black03d31fc2011-11-30 13:50:50 +0000658
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000659void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000660{
wdenkc6097192002-11-03 00:24:07 +0000661#ifdef CONFIG_CONSOLE_TIME
wdenk4b248f32004-03-14 16:51:43 +0000662 struct rtc_time tm;
663 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000664
wdenk4b248f32004-03-14 16:51:43 +0000665 /* time update only if cursor is on (faster scroll) */
666 if (state) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000667 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000668
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000669 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
670 tm.tm_sec);
671 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
672 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000673
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000674 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
675 tm.tm_year);
676 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
677 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
678 (uchar *) info);
wdenk4b248f32004-03-14 16:51:43 +0000679 }
wdenkc6097192002-11-03 00:24:07 +0000680#endif
681
Gabe Black03d31fc2011-11-30 13:50:50 +0000682 if (cursor_state != state) {
683 if (cursor_state) {
684 /* turn off the cursor */
685 video_invertchar(old_col * VIDEO_FONT_WIDTH,
686 old_row * VIDEO_FONT_HEIGHT +
687 video_logo_height);
688 } else {
689 /* turn off the cursor and record where it is */
690 video_invertchar(console_col * VIDEO_FONT_WIDTH,
691 console_row * VIDEO_FONT_HEIGHT +
692 video_logo_height);
693 old_col = console_col;
694 old_row = console_row;
695 }
696 cursor_state = state;
wdenk4b248f32004-03-14 16:51:43 +0000697 }
Eric Nelsondb0d47d2013-05-06 14:27:28 +0200698 if (cfb_do_flush_cache)
699 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000700}
701#endif
702
wdenkc6097192002-11-03 00:24:07 +0000703#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000704static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000705{
wdenk4b248f32004-03-14 16:51:43 +0000706 while (c--)
707 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000708}
709#endif
710
wdenkc6097192002-11-03 00:24:07 +0000711#ifndef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000712static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000713{
wdenk4b248f32004-03-14 16:51:43 +0000714 while (c--)
715 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000716}
717#endif
718
Pali Rohár90f60a82012-04-28 07:26:44 +0000719static void console_clear_line(int line, int begin, int end)
720{
721#ifdef VIDEO_HW_RECTFILL
722 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
723 VIDEO_FONT_WIDTH * begin, /* dest pos x */
724 video_logo_height +
725 VIDEO_FONT_HEIGHT * line, /* dest pos y */
726 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
727 VIDEO_FONT_HEIGHT, /* frame height */
728 bgx /* fill color */
729 );
730#else
731 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
732 memsetl(CONSOLE_ROW_FIRST +
733 CONSOLE_ROW_SIZE * line, /* offset of row */
734 CONSOLE_ROW_SIZE >> 2, /* length of row */
735 bgx /* fill color */
736 );
737 } else {
738 void *offset;
739 int i, size;
740
741 offset = CONSOLE_ROW_FIRST +
742 CONSOLE_ROW_SIZE * line + /* offset of row */
743 VIDEO_FONT_WIDTH *
744 VIDEO_PIXEL_SIZE * begin; /* offset of col */
745 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
746 size >>= 2; /* length to end for memsetl() */
747 /* fill at col offset of i'th line using bgx as fill color */
748 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
749 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
750 }
751#endif
752}
753
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000754static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000755{
wdenk4b248f32004-03-14 16:51:43 +0000756 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000757
758#ifdef VIDEO_HW_BITBLT
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000759 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
760 0, /* source pos x */
761 video_logo_height +
762 VIDEO_FONT_HEIGHT, /* source pos y */
763 0, /* dest pos x */
764 video_logo_height, /* dest pos y */
765 VIDEO_VISIBLE_COLS, /* frame width */
766 VIDEO_VISIBLE_ROWS
767 - video_logo_height
768 - VIDEO_FONT_HEIGHT /* frame height */
wdenk4b248f32004-03-14 16:51:43 +0000769 );
wdenkc6097192002-11-03 00:24:07 +0000770#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000771 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
772 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000773#endif
wdenk4b248f32004-03-14 16:51:43 +0000774 /* clear the last one */
Pali Rohár90f60a82012-04-28 07:26:44 +0000775 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
wdenkc6097192002-11-03 00:24:07 +0000776}
777
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000778static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000779{
Timur Tabi65618632010-08-27 15:45:47 -0500780 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000781
wdenk4b248f32004-03-14 16:51:43 +0000782 if (console_col < 0) {
783 console_col = CONSOLE_COLS - 1;
784 console_row--;
785 if (console_row < 0)
786 console_row = 0;
787 }
wdenkc6097192002-11-03 00:24:07 +0000788}
789
Pali Rohár33a35bb2012-10-19 13:30:09 +0000790#ifdef CONFIG_CFB_CONSOLE_ANSI
791
792static void console_clear(void)
wdenkc6097192002-11-03 00:24:07 +0000793{
Pali Rohár33a35bb2012-10-19 13:30:09 +0000794#ifdef VIDEO_HW_RECTFILL
795 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
796 0, /* dest pos x */
797 video_logo_height, /* dest pos y */
798 VIDEO_VISIBLE_COLS, /* frame width */
799 VIDEO_VISIBLE_ROWS, /* frame height */
800 bgx /* fill color */
801 );
802#else
803 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
804#endif
805}
806
807static void console_cursor_fix(void)
808{
809 if (console_row < 0)
810 console_row = 0;
811 if (console_row >= CONSOLE_ROWS)
812 console_row = CONSOLE_ROWS - 1;
813 if (console_col < 0)
814 console_col = 0;
815 if (console_col >= CONSOLE_COLS)
816 console_col = CONSOLE_COLS - 1;
817}
818
819static void console_cursor_up(int n)
820{
821 console_row -= n;
822 console_cursor_fix();
823}
824
825static void console_cursor_down(int n)
826{
827 console_row += n;
828 console_cursor_fix();
829}
830
831static void console_cursor_left(int n)
832{
833 console_col -= n;
834 console_cursor_fix();
835}
836
837static void console_cursor_right(int n)
838{
839 console_col += n;
840 console_cursor_fix();
841}
842
843static void console_cursor_set_position(int row, int col)
844{
845 if (console_row != -1)
846 console_row = row;
847 if (console_col != -1)
848 console_col = col;
849 console_cursor_fix();
850}
851
852static void console_previousline(int n)
853{
854 /* FIXME: also scroll terminal ? */
855 console_row -= n;
856 console_cursor_fix();
857}
858
859static void console_swap_colors(void)
860{
861 eorx = fgx;
862 fgx = bgx;
863 bgx = eorx;
864 eorx = fgx ^ bgx;
865}
866
867static inline int console_cursor_is_visible(void)
868{
869 return !ansi_cursor_hidden;
870}
871#else
872static inline int console_cursor_is_visible(void)
873{
874 return 1;
875}
876#endif
877
878static void console_newline(int n)
879{
880 console_row += n;
wdenk4b248f32004-03-14 16:51:43 +0000881 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000882
wdenk4b248f32004-03-14 16:51:43 +0000883 /* Check if we need to scroll the terminal */
884 if (console_row >= CONSOLE_ROWS) {
885 /* Scroll everything up */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000886 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000887
wdenk4b248f32004-03-14 16:51:43 +0000888 /* Decrement row number */
Pali Rohár33a35bb2012-10-19 13:30:09 +0000889 console_row = CONSOLE_ROWS - 1;
wdenk4b248f32004-03-14 16:51:43 +0000890 }
wdenkc6097192002-11-03 00:24:07 +0000891}
892
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000893static void console_cr(void)
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100894{
Timur Tabi65618632010-08-27 15:45:47 -0500895 console_col = 0;
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100896}
897
Pali Rohár33a35bb2012-10-19 13:30:09 +0000898static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000899{
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100900 static int nl = 1;
901
Pali Rohár33a35bb2012-10-19 13:30:09 +0000902 if (console_cursor_is_visible())
903 CURSOR_OFF;
Gabe Black03d31fc2011-11-30 13:50:50 +0000904
wdenk4b248f32004-03-14 16:51:43 +0000905 switch (c) {
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100906 case 13: /* back to first column */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000907 console_cr();
wdenk4b248f32004-03-14 16:51:43 +0000908 break;
wdenkc6097192002-11-03 00:24:07 +0000909
wdenk4b248f32004-03-14 16:51:43 +0000910 case '\n': /* next line */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100911 if (console_col || (!console_col && nl))
Pali Rohár33a35bb2012-10-19 13:30:09 +0000912 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100913 nl = 1;
wdenk4b248f32004-03-14 16:51:43 +0000914 break;
wdenkc6097192002-11-03 00:24:07 +0000915
wdenk4b248f32004-03-14 16:51:43 +0000916 case 9: /* tab 8 */
Timur Tabi65618632010-08-27 15:45:47 -0500917 console_col |= 0x0008;
wdenk4b248f32004-03-14 16:51:43 +0000918 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000919
wdenk4b248f32004-03-14 16:51:43 +0000920 if (console_col >= CONSOLE_COLS)
Pali Rohár33a35bb2012-10-19 13:30:09 +0000921 console_newline(1);
wdenk4b248f32004-03-14 16:51:43 +0000922 break;
wdenkc6097192002-11-03 00:24:07 +0000923
wdenk4b248f32004-03-14 16:51:43 +0000924 case 8: /* backspace */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000925 console_back();
wdenk4b248f32004-03-14 16:51:43 +0000926 break;
wdenkc6097192002-11-03 00:24:07 +0000927
Pali Rohár24fe06c2012-04-28 07:26:47 +0000928 case 7: /* bell */
929 break; /* ignored */
930
wdenk4b248f32004-03-14 16:51:43 +0000931 default: /* draw the char */
Wolfgang Denk64e40d72011-07-29 09:55:27 +0000932 video_putchar(console_col * VIDEO_FONT_WIDTH,
933 console_row * VIDEO_FONT_HEIGHT, c);
wdenk4b248f32004-03-14 16:51:43 +0000934 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000935
wdenk4b248f32004-03-14 16:51:43 +0000936 /* check for newline */
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100937 if (console_col >= CONSOLE_COLS) {
Pali Rohár33a35bb2012-10-19 13:30:09 +0000938 console_newline(1);
Anatolij Gustschin20c450e2008-01-11 02:39:47 +0100939 nl = 0;
940 }
wdenk4b248f32004-03-14 16:51:43 +0000941 }
Pali Rohár33a35bb2012-10-19 13:30:09 +0000942
943 if (console_cursor_is_visible())
944 CURSOR_SET;
945}
946
947void video_putc(const char c)
948{
949#ifdef CONFIG_CFB_CONSOLE_ANSI
950 int i;
951
952 if (c == 27) {
953 for (i = 0; i < ansi_buf_size; ++i)
954 parse_putc(ansi_buf[i]);
955 ansi_buf[0] = 27;
956 ansi_buf_size = 1;
957 return;
958 }
959
960 if (ansi_buf_size > 0) {
961 /*
962 * 0 - ESC
963 * 1 - [
964 * 2 - num1
965 * 3 - ..
966 * 4 - ;
967 * 5 - num2
968 * 6 - ..
969 * - cchar
970 */
971 int next = 0;
972
973 int flush = 0;
974 int fail = 0;
975
976 int num1 = 0;
977 int num2 = 0;
978 int cchar = 0;
979
980 ansi_buf[ansi_buf_size++] = c;
981
982 if (ansi_buf_size >= sizeof(ansi_buf))
983 fail = 1;
984
985 for (i = 0; i < ansi_buf_size; ++i) {
986 if (fail)
987 break;
988
989 switch (next) {
990 case 0:
991 if (ansi_buf[i] == 27)
992 next = 1;
993 else
994 fail = 1;
995 break;
996
997 case 1:
998 if (ansi_buf[i] == '[')
999 next = 2;
1000 else
1001 fail = 1;
1002 break;
1003
1004 case 2:
1005 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1006 num1 = ansi_buf[i]-'0';
1007 next = 3;
1008 } else if (ansi_buf[i] != '?') {
1009 --i;
1010 num1 = 1;
1011 next = 4;
1012 }
1013 break;
1014
1015 case 3:
1016 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1017 num1 *= 10;
1018 num1 += ansi_buf[i]-'0';
1019 } else {
1020 --i;
1021 next = 4;
1022 }
1023 break;
1024
1025 case 4:
1026 if (ansi_buf[i] != ';') {
1027 --i;
1028 next = 7;
1029 } else
1030 next = 5;
1031 break;
1032
1033 case 5:
1034 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1035 num2 = ansi_buf[i]-'0';
1036 next = 6;
1037 } else
1038 fail = 1;
1039 break;
1040
1041 case 6:
1042 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1043 num2 *= 10;
1044 num2 += ansi_buf[i]-'0';
1045 } else {
1046 --i;
1047 next = 7;
1048 }
1049 break;
1050
1051 case 7:
1052 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1053 || ansi_buf[i] == 'J'
1054 || ansi_buf[i] == 'K'
1055 || ansi_buf[i] == 'h'
1056 || ansi_buf[i] == 'l'
1057 || ansi_buf[i] == 'm') {
1058 cchar = ansi_buf[i];
1059 flush = 1;
1060 } else
1061 fail = 1;
1062 break;
1063 }
1064 }
1065
1066 if (fail) {
1067 for (i = 0; i < ansi_buf_size; ++i)
1068 parse_putc(ansi_buf[i]);
1069 ansi_buf_size = 0;
1070 return;
1071 }
1072
1073 if (flush) {
1074 if (!ansi_cursor_hidden)
1075 CURSOR_OFF;
1076 ansi_buf_size = 0;
1077 switch (cchar) {
1078 case 'A':
1079 /* move cursor num1 rows up */
1080 console_cursor_up(num1);
1081 break;
1082 case 'B':
1083 /* move cursor num1 rows down */
1084 console_cursor_down(num1);
1085 break;
1086 case 'C':
1087 /* move cursor num1 columns forward */
1088 console_cursor_right(num1);
1089 break;
1090 case 'D':
1091 /* move cursor num1 columns back */
1092 console_cursor_left(num1);
1093 break;
1094 case 'E':
1095 /* move cursor num1 rows up at begin of row */
1096 console_previousline(num1);
1097 break;
1098 case 'F':
1099 /* move cursor num1 rows down at begin of row */
1100 console_newline(num1);
1101 break;
1102 case 'G':
1103 /* move cursor to column num1 */
1104 console_cursor_set_position(-1, num1-1);
1105 break;
1106 case 'H':
1107 /* move cursor to row num1, column num2 */
1108 console_cursor_set_position(num1-1, num2-1);
1109 break;
1110 case 'J':
1111 /* clear console and move cursor to 0, 0 */
1112 console_clear();
1113 console_cursor_set_position(0, 0);
1114 break;
1115 case 'K':
1116 /* clear line */
1117 if (num1 == 0)
1118 console_clear_line(console_row,
1119 console_col,
1120 CONSOLE_COLS-1);
1121 else if (num1 == 1)
1122 console_clear_line(console_row,
1123 0, console_col);
1124 else
1125 console_clear_line(console_row,
1126 0, CONSOLE_COLS-1);
1127 break;
1128 case 'h':
1129 ansi_cursor_hidden = 0;
1130 break;
1131 case 'l':
1132 ansi_cursor_hidden = 1;
1133 break;
1134 case 'm':
1135 if (num1 == 0) { /* reset swapped colors */
1136 if (ansi_colors_need_revert) {
1137 console_swap_colors();
1138 ansi_colors_need_revert = 0;
1139 }
1140 } else if (num1 == 7) { /* once swap colors */
1141 if (!ansi_colors_need_revert) {
1142 console_swap_colors();
1143 ansi_colors_need_revert = 1;
1144 }
1145 }
1146 break;
1147 }
1148 if (!ansi_cursor_hidden)
1149 CURSOR_SET;
1150 }
1151 } else {
1152 parse_putc(c);
1153 }
1154#else
1155 parse_putc(c);
1156#endif
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001157 if (cfb_do_flush_cache)
1158 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabi65618632010-08-27 15:45:47 -05001159}
wdenkc6097192002-11-03 00:24:07 +00001160
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001161void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +00001162{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001163 int count = strlen(s);
wdenkc6097192002-11-03 00:24:07 +00001164
wdenk4b248f32004-03-14 16:51:43 +00001165 while (count--)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001166 video_putc(*s++);
wdenkc6097192002-11-03 00:24:07 +00001167}
1168
Anatolij Gustschin10543822010-05-01 22:21:09 +02001169/*
1170 * Do not enforce drivers (or board code) to provide empty
1171 * video_set_lut() if they do not support 8 bpp format.
1172 * Implement weak default function instead.
1173 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001174void __video_set_lut(unsigned int index, unsigned char r,
1175 unsigned char g, unsigned char b)
Anatolij Gustschin10543822010-05-01 22:21:09 +02001176{
1177}
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001178
1179void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
1180 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschin10543822010-05-01 22:21:09 +02001181
Jon Loeliger07d38a12007-07-09 17:30:01 -05001182#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk4b248f32004-03-14 16:51:43 +00001183
1184#define FILL_8BIT_332RGB(r,g,b) { \
1185 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1186 fb ++; \
1187}
1188
1189#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001190 *(unsigned short *)fb = \
1191 SWAP16((unsigned short)(((r>>3)<<10) | \
1192 ((g>>3)<<5) | \
1193 (b>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001194 fb += 2; \
1195}
1196
1197#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001198 *(unsigned short *)fb = \
1199 SWAP16((unsigned short)((((r)>>3)<<11)| \
1200 (((g)>>2)<<5) | \
1201 ((b)>>3))); \
wdenk4b248f32004-03-14 16:51:43 +00001202 fb += 2; \
1203}
1204
1205#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001206 *(unsigned long *)fb = \
1207 SWAP32((unsigned long)(((r<<16) | \
1208 (g<<8) | \
1209 b))); \
wdenk4b248f32004-03-14 16:51:43 +00001210 fb += 4; \
1211}
1212
1213#ifdef VIDEO_FB_LITTLE_ENDIAN
1214#define FILL_24BIT_888RGB(r,g,b) { \
1215 fb[0] = b; \
1216 fb[1] = g; \
1217 fb[2] = r; \
1218 fb += 3; \
1219}
1220#else
1221#define FILL_24BIT_888RGB(r,g,b) { \
1222 fb[0] = r; \
1223 fb[1] = g; \
1224 fb[2] = b; \
1225 fb += 3; \
1226}
1227#endif
1228
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001229#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001230static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001231{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001232 ushort *dst = (ushort *) fb;
1233 ushort color = (ushort) (((r >> 3) << 10) |
1234 ((g >> 3) << 5) |
1235 (b >> 3));
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001236 if (x & 1)
1237 *(--dst) = color;
1238 else
1239 *(++dst) = color;
1240}
1241#endif
wdenk4b248f32004-03-14 16:51:43 +00001242
1243/*
Anatolij Gustschind5011762010-03-15 14:50:25 +01001244 * RLE8 bitmap support
1245 */
1246
1247#ifdef CONFIG_VIDEO_BMP_RLE8
1248/* Pre-calculated color table entry */
1249struct palette {
1250 union {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001251 unsigned short w; /* word */
1252 unsigned int dw; /* double word */
1253 } ce; /* color entry */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001254};
1255
1256/*
1257 * Helper to draw encoded/unencoded run.
1258 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001259static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1260 int cnt, int enc)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001261{
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001262 ulong addr = (ulong) *fb;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001263 int *off;
1264 int enc_off = 1;
1265 int i;
1266
1267 /*
1268 * Setup offset of the color index in the bitmap.
1269 * Color index of encoded run is at offset 1.
1270 */
1271 off = enc ? &enc_off : &i;
1272
1273 switch (VIDEO_DATA_FORMAT) {
1274 case GDF__8BIT_INDEX:
1275 for (i = 0; i < cnt; i++)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001276 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschind5011762010-03-15 14:50:25 +01001277 break;
1278 case GDF_15BIT_555RGB:
1279 case GDF_16BIT_565RGB:
1280 /* differences handled while pre-calculating palette */
1281 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001282 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001283 addr += 2;
1284 }
1285 break;
1286 case GDF_32BIT_X888RGB:
1287 for (i = 0; i < cnt; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001288 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001289 addr += 4;
1290 }
1291 break;
1292 }
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001293 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001294}
1295
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001296static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1297 int width, int height)
Anatolij Gustschind5011762010-03-15 14:50:25 +01001298{
1299 unsigned char *bm;
1300 unsigned char *fbp;
1301 unsigned int cnt, runlen;
1302 int decode = 1;
1303 int x, y, bpp, i, ncolors;
1304 struct palette p[256];
1305 bmp_color_table_entry_t cte;
1306 int green_shift, red_off;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001307 int limit = VIDEO_COLS * VIDEO_ROWS;
1308 int pixels = 0;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001309
1310 x = 0;
1311 y = __le32_to_cpu(img->header.height) - 1;
1312 ncolors = __le32_to_cpu(img->header.colors_used);
1313 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001314 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1315 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001316
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001317 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001318
1319 /* pre-calculate and setup palette */
1320 switch (VIDEO_DATA_FORMAT) {
1321 case GDF__8BIT_INDEX:
1322 for (i = 0; i < ncolors; i++) {
1323 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001324 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001325 }
1326 break;
1327 case GDF_15BIT_555RGB:
1328 case GDF_16BIT_565RGB:
1329 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1330 green_shift = 3;
1331 red_off = 10;
1332 } else {
1333 green_shift = 2;
1334 red_off = 11;
1335 }
1336 for (i = 0; i < ncolors; i++) {
1337 cte = img->color_table[i];
1338 p[i].ce.w = SWAP16((unsigned short)
1339 (((cte.red >> 3) << red_off) |
1340 ((cte.green >> green_shift) << 5) |
1341 cte.blue >> 3));
1342 }
1343 break;
1344 case GDF_32BIT_X888RGB:
1345 for (i = 0; i < ncolors; i++) {
1346 cte = img->color_table[i];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001347 p[i].ce.dw = SWAP32((cte.red << 16) |
1348 (cte.green << 8) |
Anatolij Gustschind5011762010-03-15 14:50:25 +01001349 cte.blue);
1350 }
1351 break;
1352 default:
1353 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001354 VIDEO_DATA_FORMAT);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001355 return -1;
1356 }
1357
1358 while (decode) {
1359 switch (bm[0]) {
1360 case 0:
1361 switch (bm[1]) {
1362 case 0:
1363 /* scan line end marker */
1364 bm += 2;
1365 x = 0;
1366 y--;
1367 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001368 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001369 (((y + yoff) * VIDEO_COLS) +
1370 xoff) * bpp);
1371 continue;
1372 case 1:
1373 /* end of bitmap data marker */
1374 decode = 0;
1375 break;
1376 case 2:
1377 /* run offset marker */
1378 x += bm[2];
1379 y -= bm[3];
1380 fbp = (unsigned char *)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001381 ((unsigned int) video_fb_address +
Anatolij Gustschind5011762010-03-15 14:50:25 +01001382 (((y + yoff) * VIDEO_COLS) +
1383 x + xoff) * bpp);
1384 bm += 4;
1385 break;
1386 default:
1387 /* unencoded run */
1388 cnt = bm[1];
1389 runlen = cnt;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001390 pixels += cnt;
1391 if (pixels > limit)
1392 goto error;
1393
Anatolij Gustschind5011762010-03-15 14:50:25 +01001394 bm += 2;
1395 if (y < height) {
1396 if (x >= width) {
1397 x += runlen;
1398 goto next_run;
1399 }
1400 if (x + runlen > width)
1401 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001402 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001403 x += runlen;
1404 }
1405next_run:
1406 bm += runlen;
1407 if (runlen & 1)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001408 bm++; /* 0 padding if length is odd */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001409 }
1410 break;
1411 default:
1412 /* encoded run */
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001413 cnt = bm[0];
1414 runlen = cnt;
1415 pixels += cnt;
1416 if (pixels > limit)
1417 goto error;
1418
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001419 if (y < height) { /* only draw into visible area */
Anatolij Gustschind5011762010-03-15 14:50:25 +01001420 if (x >= width) {
1421 x += runlen;
1422 bm += 2;
1423 continue;
1424 }
1425 if (x + runlen > width)
1426 cnt = width - x;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001427 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001428 x += runlen;
1429 }
1430 bm += 2;
1431 break;
1432 }
1433 }
1434 return 0;
Anatolij Gustschin74446b62011-02-21 21:33:29 +01001435error:
1436 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1437 return -1;
Anatolij Gustschind5011762010-03-15 14:50:25 +01001438}
1439#endif
1440
1441/*
wdenk4b248f32004-03-14 16:51:43 +00001442 * Display the BMP file located at address bmp_image.
wdenk4b248f32004-03-14 16:51:43 +00001443 */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001444int video_display_bitmap(ulong bmp_image, int x, int y)
wdenk4b248f32004-03-14 16:51:43 +00001445{
1446 ushort xcount, ycount;
1447 uchar *fb;
1448 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1449 uchar *bmap;
1450 ushort padded_line;
1451 unsigned long width, height, bpp;
1452 unsigned colors;
1453 unsigned long compression;
1454 bmp_color_table_entry_t cte;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001455
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001456#ifdef CONFIG_VIDEO_BMP_GZIP
1457 unsigned char *dst = NULL;
1458 ulong len;
1459#endif
wdenk4b248f32004-03-14 16:51:43 +00001460
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001461 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001462
1463 if (!((bmp->header.signature[0] == 'B') &&
1464 (bmp->header.signature[1] == 'M'))) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001465
1466#ifdef CONFIG_VIDEO_BMP_GZIP
1467 /*
1468 * Could be a gzipped bmp image, try to decrompress...
1469 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001470 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1471 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001472 if (dst == NULL) {
1473 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001474 return 1;
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001475 }
Eric Nelson5ca05c82014-03-08 07:55:52 -07001476 /*
1477 * NB: we need to force offset of +2
1478 * See doc/README.displaying-bmps
1479 */
1480 if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001481 (uchar *) bmp_image,
1482 &len) != 0) {
1483 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1484 bmp_image);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001485 free(dst);
1486 return 1;
1487 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001488 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001489 printf("Image could be truncated "
1490 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roesec29ab9d2005-10-08 10:19:07 +02001491 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001492
1493 /*
1494 * Set addr to decompressed image
1495 */
Eric Nelson5ca05c82014-03-08 07:55:52 -07001496 bmp = (bmp_image_t *)(dst+2);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001497
1498 if (!((bmp->header.signature[0] == 'B') &&
1499 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001500 printf("Error: no valid bmp.gz image at %lx\n",
1501 bmp_image);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001502 free(dst);
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001503 return 1;
1504 }
1505#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001506 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenk4b248f32004-03-14 16:51:43 +00001507 return 1;
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001508#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenk4b248f32004-03-14 16:51:43 +00001509 }
1510
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001511 width = le32_to_cpu(bmp->header.width);
1512 height = le32_to_cpu(bmp->header.height);
1513 bpp = le16_to_cpu(bmp->header.bit_count);
1514 colors = le32_to_cpu(bmp->header.colors_used);
1515 compression = le32_to_cpu(bmp->header.compression);
wdenk4b248f32004-03-14 16:51:43 +00001516
Marek Vasut68da5b12011-10-21 14:17:04 +00001517 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001518 width, height, colors);
wdenk4b248f32004-03-14 16:51:43 +00001519
Anatolij Gustschind5011762010-03-15 14:50:25 +01001520 if (compression != BMP_BI_RGB
1521#ifdef CONFIG_VIDEO_BMP_RLE8
1522 && compression != BMP_BI_RLE8
1523#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001524 ) {
1525 printf("Error: compression type %ld not supported\n",
1526 compression);
Matthias Fuchsa49e0d12008-04-21 11:19:04 +02001527#ifdef CONFIG_VIDEO_BMP_GZIP
1528 if (dst)
1529 free(dst);
1530#endif
wdenk4b248f32004-03-14 16:51:43 +00001531 return 1;
1532 }
1533
1534 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1535
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001536#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1537 if (x == BMP_ALIGN_CENTER)
1538 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1539 else if (x < 0)
1540 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1541
1542 if (y == BMP_ALIGN_CENTER)
1543 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1544 else if (y < 0)
1545 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1546#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1547
Matthias Weisseracf3baa2013-02-15 03:35:12 +00001548 /*
1549 * Just ignore elements which are completely beyond screen
1550 * dimensions.
1551 */
1552 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1553 return 0;
1554
wdenk4b248f32004-03-14 16:51:43 +00001555 if ((x + width) > VIDEO_VISIBLE_COLS)
1556 width = VIDEO_VISIBLE_COLS - x;
1557 if ((y + height) > VIDEO_VISIBLE_ROWS)
1558 height = VIDEO_VISIBLE_ROWS - y;
1559
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001560 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk4b248f32004-03-14 16:51:43 +00001561 fb = (uchar *) (video_fb_address +
1562 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1563 x * VIDEO_PIXEL_SIZE);
1564
Anatolij Gustschind5011762010-03-15 14:50:25 +01001565#ifdef CONFIG_VIDEO_BMP_RLE8
1566 if (compression == BMP_BI_RLE8) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001567 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschind5011762010-03-15 14:50:25 +01001568 }
1569#endif
1570
Timur Tabi68f66182010-08-23 16:58:00 -05001571 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001572 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi68f66182010-08-23 16:58:00 -05001573 case 4:
1574 padded_line -= width / 2;
1575 ycount = height;
1576
1577 switch (VIDEO_DATA_FORMAT) {
1578 case GDF_32BIT_X888RGB:
1579 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001580 WATCHDOG_RESET();
Timur Tabi68f66182010-08-23 16:58:00 -05001581 /*
1582 * Don't assume that 'width' is an
1583 * even number
1584 */
1585 for (xcount = 0; xcount < width; xcount++) {
1586 uchar idx;
1587
1588 if (xcount & 1) {
1589 idx = *bmap & 0xF;
1590 bmap++;
1591 } else
1592 idx = *bmap >> 4;
1593 cte = bmp->color_table[idx];
1594 FILL_32BIT_X888RGB(cte.red, cte.green,
1595 cte.blue);
1596 }
1597 bmap += padded_line;
1598 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001599 VIDEO_PIXEL_SIZE;
Timur Tabi68f66182010-08-23 16:58:00 -05001600 }
1601 break;
1602 default:
1603 puts("4bpp bitmap unsupported with current "
1604 "video mode\n");
1605 break;
1606 }
1607 break;
1608
wdenk4b248f32004-03-14 16:51:43 +00001609 case 8:
1610 padded_line -= width;
1611 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001612 /* Copy colormap */
wdenk4b248f32004-03-14 16:51:43 +00001613 for (xcount = 0; xcount < colors; ++xcount) {
1614 cte = bmp->color_table[xcount];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001615 video_set_lut(xcount, cte.red, cte.green,
1616 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001617 }
1618 }
1619 ycount = height;
1620 switch (VIDEO_DATA_FORMAT) {
1621 case GDF__8BIT_INDEX:
1622 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001623 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001624 xcount = width;
1625 while (xcount--) {
1626 *fb++ = *bmap++;
1627 }
1628 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001629 fb -= (VIDEO_VISIBLE_COLS + width) *
1630 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001631 }
1632 break;
1633 case GDF__8BIT_332RGB:
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_8BIT_332RGB(cte.red, cte.green,
1640 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001641 }
1642 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001643 fb -= (VIDEO_VISIBLE_COLS + width) *
1644 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001645 }
1646 break;
1647 case GDF_15BIT_555RGB:
1648 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001649#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1650 int xpos = x;
1651#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001652 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001653 xcount = width;
1654 while (xcount--) {
1655 cte = bmp->color_table[*bmap++];
Andrew Dyercc347802008-08-29 12:30:39 -05001656#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001657 fill_555rgb_pswap(fb, xpos++, cte.red,
1658 cte.green,
1659 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001660 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001661#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001662 FILL_15BIT_555RGB(cte.red, cte.green,
1663 cte.blue);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001664#endif
wdenk4b248f32004-03-14 16:51:43 +00001665 }
1666 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001667 fb -= (VIDEO_VISIBLE_COLS + width) *
1668 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001669 }
1670 break;
1671 case GDF_16BIT_565RGB:
1672 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001673 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001674 xcount = width;
1675 while (xcount--) {
1676 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001677 FILL_16BIT_565RGB(cte.red, cte.green,
1678 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001679 }
1680 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001681 fb -= (VIDEO_VISIBLE_COLS + width) *
1682 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001683 }
1684 break;
1685 case GDF_32BIT_X888RGB:
1686 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001687 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001688 xcount = width;
1689 while (xcount--) {
1690 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001691 FILL_32BIT_X888RGB(cte.red, cte.green,
1692 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001693 }
1694 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001695 fb -= (VIDEO_VISIBLE_COLS + width) *
1696 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001697 }
1698 break;
1699 case GDF_24BIT_888RGB:
1700 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001701 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001702 xcount = width;
1703 while (xcount--) {
1704 cte = bmp->color_table[*bmap++];
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001705 FILL_24BIT_888RGB(cte.red, cte.green,
1706 cte.blue);
wdenk4b248f32004-03-14 16:51:43 +00001707 }
1708 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001709 fb -= (VIDEO_VISIBLE_COLS + width) *
1710 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001711 }
1712 break;
1713 }
1714 break;
1715 case 24:
1716 padded_line -= 3 * width;
1717 ycount = height;
1718 switch (VIDEO_DATA_FORMAT) {
1719 case GDF__8BIT_332RGB:
1720 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001721 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001722 xcount = width;
1723 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001724 FILL_8BIT_332RGB(bmap[2], bmap[1],
1725 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001726 bmap += 3;
1727 }
1728 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001729 fb -= (VIDEO_VISIBLE_COLS + width) *
1730 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001731 }
1732 break;
1733 case GDF_15BIT_555RGB:
1734 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001735#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1736 int xpos = x;
1737#endif
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001738 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001739 xcount = width;
1740 while (xcount--) {
Andrew Dyercc347802008-08-29 12:30:39 -05001741#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001742 fill_555rgb_pswap(fb, xpos++, bmap[2],
1743 bmap[1], bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001744 fb += 2;
Andrew Dyercc347802008-08-29 12:30:39 -05001745#else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001746 FILL_15BIT_555RGB(bmap[2], bmap[1],
1747 bmap[0]);
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001748#endif
wdenk4b248f32004-03-14 16:51:43 +00001749 bmap += 3;
1750 }
1751 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001752 fb -= (VIDEO_VISIBLE_COLS + width) *
1753 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001754 }
1755 break;
1756 case GDF_16BIT_565RGB:
1757 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001758 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001759 xcount = width;
1760 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001761 FILL_16BIT_565RGB(bmap[2], bmap[1],
1762 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001763 bmap += 3;
1764 }
1765 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001766 fb -= (VIDEO_VISIBLE_COLS + width) *
1767 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001768 }
1769 break;
1770 case GDF_32BIT_X888RGB:
1771 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001772 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001773 xcount = width;
1774 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001775 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1776 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001777 bmap += 3;
1778 }
1779 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001780 fb -= (VIDEO_VISIBLE_COLS + width) *
1781 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001782 }
1783 break;
1784 case GDF_24BIT_888RGB:
1785 while (ycount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001786 WATCHDOG_RESET();
wdenk4b248f32004-03-14 16:51:43 +00001787 xcount = width;
1788 while (xcount--) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001789 FILL_24BIT_888RGB(bmap[2], bmap[1],
1790 bmap[0]);
wdenk4b248f32004-03-14 16:51:43 +00001791 bmap += 3;
1792 }
1793 bmap += padded_line;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001794 fb -= (VIDEO_VISIBLE_COLS + width) *
1795 VIDEO_PIXEL_SIZE;
wdenk4b248f32004-03-14 16:51:43 +00001796 }
1797 break;
1798 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001799 printf("Error: 24 bits/pixel bitmap incompatible "
1800 "with current video mode\n");
wdenk4b248f32004-03-14 16:51:43 +00001801 break;
1802 }
1803 break;
1804 default:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001805 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1806 le16_to_cpu(bmp->header.bit_count));
wdenk4b248f32004-03-14 16:51:43 +00001807 break;
1808 }
Stefan Roese98f4a3d2005-09-22 09:04:17 +02001809
1810#ifdef CONFIG_VIDEO_BMP_GZIP
1811 if (dst) {
1812 free(dst);
1813 }
1814#endif
1815
Eric Nelsondb0d47d2013-05-06 14:27:28 +02001816 if (cfb_do_flush_cache)
1817 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenk4b248f32004-03-14 16:51:43 +00001818 return (0);
1819}
Jon Loeliger07d38a12007-07-09 17:30:01 -05001820#endif
wdenk4b248f32004-03-14 16:51:43 +00001821
wdenk4b248f32004-03-14 16:51:43 +00001822
wdenkc6097192002-11-03 00:24:07 +00001823#ifdef CONFIG_VIDEO_LOGO
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001824static int video_logo_xpos;
1825static int video_logo_ypos;
1826
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001827static void plot_logo_or_black(void *screen, int width, int x, int y, \
1828 int black);
1829
1830static void logo_plot(void *screen, int width, int x, int y)
1831{
1832 plot_logo_or_black(screen, width, x, y, 0);
1833}
1834
1835static void logo_black(void)
1836{
1837 plot_logo_or_black(video_fb_address, \
1838 VIDEO_COLS, \
1839 video_logo_xpos, \
1840 video_logo_ypos, \
1841 1);
1842}
1843
1844static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1845{
1846 if (argc != 1)
1847 return cmd_usage(cmdtp);
1848
1849 logo_black();
1850 return 0;
1851}
1852
1853U_BOOT_CMD(
1854 clrlogo, 1, 0, do_clrlogo,
1855 "fill the boot logo area with black",
1856 " "
1857 );
1858
1859static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001860{
wdenkc6097192002-11-03 00:24:07 +00001861
wdenk4b248f32004-03-14 16:51:43 +00001862 int xcount, i;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001863 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisserbe129aa2010-01-12 12:06:31 +01001864 int ycount = video_logo_height;
wdenk4b248f32004-03-14 16:51:43 +00001865 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1866 unsigned char *source;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001867 unsigned char *dest;
1868
1869#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1870 if (x == BMP_ALIGN_CENTER)
1871 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1872 else if (x < 0)
1873 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1874
1875 if (y == BMP_ALIGN_CENTER)
1876 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1877 else if (y < 0)
1878 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1879#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1880
1881 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenka6c7ad22002-12-03 21:28:10 +00001882
1883#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk4b248f32004-03-14 16:51:43 +00001884 source = bmp_logo_bitmap;
wdenk8bde7f72003-06-27 21:31:46 +00001885
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001886 /* Allocate temporary space for computing colormap */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001887 logo_red = malloc(BMP_LOGO_COLORS);
1888 logo_green = malloc(BMP_LOGO_COLORS);
1889 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin7c050f82010-06-19 20:41:56 +02001890 /* Compute color map */
wdenk4b248f32004-03-14 16:51:43 +00001891 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1892 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1893 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1894 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1895 }
wdenka6c7ad22002-12-03 21:28:10 +00001896#else
wdenk4b248f32004-03-14 16:51:43 +00001897 source = linux_logo;
1898 logo_red = linux_logo_red;
1899 logo_green = linux_logo_green;
1900 logo_blue = linux_logo_blue;
wdenka6c7ad22002-12-03 21:28:10 +00001901#endif
wdenk8bde7f72003-06-27 21:31:46 +00001902
wdenk4b248f32004-03-14 16:51:43 +00001903 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1904 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001905 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1906 logo_red[i], logo_green[i],
1907 logo_blue[i]);
wdenk4b248f32004-03-14 16:51:43 +00001908 }
wdenk8bde7f72003-06-27 21:31:46 +00001909 }
wdenkc6097192002-11-03 00:24:07 +00001910
wdenk4b248f32004-03-14 16:51:43 +00001911 while (ycount--) {
Anatolij Gustschine84d5682008-08-08 18:00:40 +02001912#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1913 int xpos = x;
1914#endif
wdenk4b248f32004-03-14 16:51:43 +00001915 xcount = VIDEO_LOGO_WIDTH;
1916 while (xcount--) {
Bastian Ruppert4b7d3a02012-09-13 22:29:02 +00001917 if (black) {
1918 r = 0x00;
1919 g = 0x00;
1920 b = 0x00;
1921 } else {
1922 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1923 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1924 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1925 }
wdenk8bde7f72003-06-27 21:31:46 +00001926
wdenk4b248f32004-03-14 16:51:43 +00001927 switch (VIDEO_DATA_FORMAT) {
1928 case GDF__8BIT_INDEX:
1929 *dest = *source;
1930 break;
1931 case GDF__8BIT_332RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001932 *dest = ((r >> 5) << 5) |
1933 ((g >> 5) << 2) |
1934 (b >> 6);
wdenk4b248f32004-03-14 16:51:43 +00001935 break;
1936 case GDF_15BIT_555RGB:
Andrew Dyercc347802008-08-29 12:30:39 -05001937#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001938 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyercc347802008-08-29 12:30:39 -05001939#else
wdenk4b248f32004-03-14 16:51:43 +00001940 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001941 SWAP16((unsigned short) (
1942 ((r >> 3) << 10) |
1943 ((g >> 3) << 5) |
1944 (b >> 3)));
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001945#endif
wdenk4b248f32004-03-14 16:51:43 +00001946 break;
1947 case GDF_16BIT_565RGB:
1948 *(unsigned short *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001949 SWAP16((unsigned short) (
1950 ((r >> 3) << 11) |
1951 ((g >> 2) << 5) |
1952 (b >> 3)));
wdenk4b248f32004-03-14 16:51:43 +00001953 break;
1954 case GDF_32BIT_X888RGB:
1955 *(unsigned long *) dest =
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001956 SWAP32((unsigned long) (
1957 (r << 16) |
1958 (g << 8) |
1959 b));
wdenk4b248f32004-03-14 16:51:43 +00001960 break;
1961 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001962#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenk4b248f32004-03-14 16:51:43 +00001963 dest[0] = b;
1964 dest[1] = g;
1965 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001966#else
wdenk4b248f32004-03-14 16:51:43 +00001967 dest[0] = r;
1968 dest[1] = g;
1969 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001970#endif
wdenk4b248f32004-03-14 16:51:43 +00001971 break;
1972 }
1973 source++;
1974 dest += VIDEO_PIXEL_SIZE;
1975 }
1976 dest += skip;
wdenk8bde7f72003-06-27 21:31:46 +00001977 }
wdenka6c7ad22002-12-03 21:28:10 +00001978#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001979 free(logo_red);
1980 free(logo_green);
1981 free(logo_blue);
wdenka6c7ad22002-12-03 21:28:10 +00001982#endif
wdenkc6097192002-11-03 00:24:07 +00001983}
1984
Wolfgang Denk64e40d72011-07-29 09:55:27 +00001985static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001986{
wdenk4b248f32004-03-14 16:51:43 +00001987 char info[128];
Wolfgang Denka9a62af2011-11-04 15:55:20 +00001988 int space, len;
1989 __maybe_unused int y_off = 0;
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001990 __maybe_unused ulong addr;
1991 __maybe_unused char *s;
wdenkc6097192002-11-03 00:24:07 +00001992
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001993 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001994
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001995#ifdef CONFIG_SPLASH_SCREEN
1996 s = getenv("splashimage");
1997 if (s != NULL) {
Robert Winklerdd4425e2013-06-17 11:31:29 -07001998 splash_screen_prepare();
Bastian Ruppert1e681f92012-09-13 22:29:01 +00001999 addr = simple_strtoul(s, NULL, 16);
2000
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002001 if (video_display_bitmap(addr,
2002 video_logo_xpos,
2003 video_logo_ypos) == 0) {
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002004 video_logo_height = 0;
wdenk4b248f32004-03-14 16:51:43 +00002005 return ((void *) (video_fb_address));
2006 }
2007 }
2008#endif /* CONFIG_SPLASH_SCREEN */
2009
Bastian Ruppert1e681f92012-09-13 22:29:01 +00002010 logo_plot(video_fb_address, VIDEO_COLS,
2011 video_logo_xpos, video_logo_ypos);
2012
2013#ifdef CONFIG_SPLASH_SCREEN_ALIGN
2014 /*
2015 * when using splashpos for video_logo, skip any info
2016 * output on video console if the logo is not at 0,0
2017 */
2018 if (video_logo_xpos || video_logo_ypos) {
2019 /*
2020 * video_logo_height is used in text and cursor offset
2021 * calculations. Since the console is below the logo,
2022 * we need to adjust the logo height
2023 */
2024 if (video_logo_ypos == BMP_ALIGN_CENTER)
2025 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
2026 VIDEO_LOGO_HEIGHT) / 2);
2027 else if (video_logo_ypos > 0)
2028 video_logo_height += video_logo_ypos;
2029
2030 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2031 }
2032#endif
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002033 if (board_cfb_skip())
2034 return 0;
wdenk4b248f32004-03-14 16:51:43 +00002035
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002036 sprintf(info, " %s", version_string);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002037
2038 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2039 len = strlen(info);
2040
2041 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002042 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2043 (uchar *) info, space);
2044 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2045 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2046 (uchar *) info + space, len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002047 y_off = 1;
2048 } else
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002049 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00002050
2051#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenk4b248f32004-03-14 16:51:43 +00002052 {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002053 int i, n =
2054 ((video_logo_height -
2055 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002056
wdenk4b248f32004-03-14 16:51:43 +00002057 for (i = 1; i < n; i++) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002058 video_get_info_str(i, info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002059 if (!*info)
2060 continue;
2061
2062 len = strlen(info);
2063 if (len > space) {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002064 video_drawchars(VIDEO_INFO_X,
2065 VIDEO_INFO_Y +
2066 (i + y_off) *
2067 VIDEO_FONT_HEIGHT,
2068 (uchar *) info, space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002069 y_off++;
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002070 video_drawchars(VIDEO_INFO_X +
2071 VIDEO_FONT_WIDTH,
2072 VIDEO_INFO_Y +
2073 (i + y_off) *
2074 VIDEO_FONT_HEIGHT,
2075 (uchar *) info + space,
2076 len - space);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002077 } else {
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002078 video_drawstring(VIDEO_INFO_X,
2079 VIDEO_INFO_Y +
2080 (i + y_off) *
2081 VIDEO_FONT_HEIGHT,
2082 (uchar *) info);
Anatolij Gustschin3dcbe622009-04-23 12:35:22 +02002083 }
wdenk4b248f32004-03-14 16:51:43 +00002084 }
2085 }
wdenkc6097192002-11-03 00:24:07 +00002086#endif
2087
Matthias Weisserbe129aa2010-01-12 12:06:31 +01002088 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002089}
2090#endif
2091
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002092static int cfb_fb_is_in_dram(void)
2093{
2094 bd_t *bd = gd->bd;
2095#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2096defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2097 ulong start, end;
2098 int i;
2099
2100 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2101 start = bd->bi_dram[i].start;
2102 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2103 if ((ulong)video_fb_address >= start &&
2104 (ulong)video_fb_address < end)
2105 return 1;
2106 }
2107#else
2108 if ((ulong)video_fb_address >= bd->bi_memstart &&
2109 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2110 return 1;
2111#endif
2112 return 0;
2113}
2114
Heiko Schocher45ae2542013-10-22 11:06:06 +02002115void video_clear(void)
2116{
2117 if (!video_fb_address)
2118 return;
2119#ifdef VIDEO_HW_RECTFILL
2120 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2121 0, /* dest pos x */
2122 0, /* dest pos y */
2123 VIDEO_VISIBLE_COLS, /* frame width */
2124 VIDEO_VISIBLE_ROWS, /* frame height */
2125 bgx /* fill color */
2126 );
2127#else
2128 memsetl(video_fb_address,
2129 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2130#endif
2131}
2132
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002133static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002134{
wdenk4b248f32004-03-14 16:51:43 +00002135 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002136
Wolfgang Denk57912932011-07-30 12:48:09 +00002137 pGD = video_hw_init();
2138 if (pGD == NULL)
wdenk4b248f32004-03-14 16:51:43 +00002139 return -1;
wdenkc6097192002-11-03 00:24:07 +00002140
wdenk4b248f32004-03-14 16:51:43 +00002141 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002142#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002143 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002144#endif
2145
Anatolij Gustschinbfd4be82012-06-05 09:19:18 +02002146 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2147
wdenk4b248f32004-03-14 16:51:43 +00002148 /* Init drawing pats */
2149 switch (VIDEO_DATA_FORMAT) {
2150 case GDF__8BIT_INDEX:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002151 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2152 CONSOLE_FG_COL);
2153 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2154 CONSOLE_BG_COL);
wdenk4b248f32004-03-14 16:51:43 +00002155 fgx = 0x01010101;
2156 bgx = 0x00000000;
2157 break;
2158 case GDF__8BIT_332RGB:
2159 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002160 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2161 CONSOLE_FG_COL >> 6);
2162 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2163 color8;
wdenk4b248f32004-03-14 16:51:43 +00002164 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002165 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2166 CONSOLE_BG_COL >> 6);
2167 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2168 color8;
wdenk4b248f32004-03-14 16:51:43 +00002169 break;
2170 case GDF_15BIT_555RGB:
2171 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002172 ((CONSOLE_FG_COL >> 3) << 21) |
2173 ((CONSOLE_FG_COL >> 3) << 16) |
2174 ((CONSOLE_FG_COL >> 3) << 10) |
2175 ((CONSOLE_FG_COL >> 3) << 5) |
2176 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002177 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002178 ((CONSOLE_BG_COL >> 3) << 21) |
2179 ((CONSOLE_BG_COL >> 3) << 16) |
2180 ((CONSOLE_BG_COL >> 3) << 10) |
2181 ((CONSOLE_BG_COL >> 3) << 5) |
2182 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002183 break;
2184 case GDF_16BIT_565RGB:
2185 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002186 ((CONSOLE_FG_COL >> 2) << 21) |
2187 ((CONSOLE_FG_COL >> 3) << 16) |
2188 ((CONSOLE_FG_COL >> 3) << 11) |
2189 ((CONSOLE_FG_COL >> 2) << 5) |
2190 (CONSOLE_FG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002191 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002192 ((CONSOLE_BG_COL >> 2) << 21) |
2193 ((CONSOLE_BG_COL >> 3) << 16) |
2194 ((CONSOLE_BG_COL >> 3) << 11) |
2195 ((CONSOLE_BG_COL >> 2) << 5) |
2196 (CONSOLE_BG_COL >> 3));
wdenk4b248f32004-03-14 16:51:43 +00002197 break;
2198 case GDF_32BIT_X888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002199 fgx = (CONSOLE_FG_COL << 16) |
2200 (CONSOLE_FG_COL << 8) |
2201 CONSOLE_FG_COL;
2202 bgx = (CONSOLE_BG_COL << 16) |
2203 (CONSOLE_BG_COL << 8) |
2204 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002205 break;
2206 case GDF_24BIT_888RGB:
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002207 fgx = (CONSOLE_FG_COL << 24) |
2208 (CONSOLE_FG_COL << 16) |
2209 (CONSOLE_FG_COL << 8) |
2210 CONSOLE_FG_COL;
2211 bgx = (CONSOLE_BG_COL << 24) |
2212 (CONSOLE_BG_COL << 16) |
2213 (CONSOLE_BG_COL << 8) |
2214 CONSOLE_BG_COL;
wdenk4b248f32004-03-14 16:51:43 +00002215 break;
2216 }
2217 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002218
Heiko Schocher45ae2542013-10-22 11:06:06 +02002219 video_clear();
2220
wdenkc6097192002-11-03 00:24:07 +00002221#ifdef CONFIG_VIDEO_LOGO
wdenk4b248f32004-03-14 16:51:43 +00002222 /* Plot the logo and get start point of console */
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002223 debug("Video: Drawing the logo ...\n");
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002224 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002225#else
wdenk4b248f32004-03-14 16:51:43 +00002226 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002227#endif
2228
wdenk4b248f32004-03-14 16:51:43 +00002229 /* Initialize the console */
2230 console_col = 0;
2231 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002232
Eric Nelsondb0d47d2013-05-06 14:27:28 +02002233 if (cfb_do_flush_cache)
2234 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2235
wdenk4b248f32004-03-14 16:51:43 +00002236 return 0;
wdenkc6097192002-11-03 00:24:07 +00002237}
2238
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002239/*
2240 * Implement a weak default function for boards that optionally
2241 * need to skip the video initialization.
2242 */
2243int __board_video_skip(void)
2244{
2245 /* As default, don't skip test */
2246 return 0;
2247}
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002248
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002249int board_video_skip(void)
2250 __attribute__ ((weak, alias("__board_video_skip")));
2251
2252int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002253{
wdenk4b248f32004-03-14 16:51:43 +00002254 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02002255 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00002256
Wolfgang Denk6cc7ba92009-05-15 10:07:43 +02002257 /* Check if video initialization should be skipped */
2258 if (board_video_skip())
2259 return 0;
2260
wdenk81050922004-07-11 20:04:51 +00002261 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002262 skip_dev_init = (video_init() == -1);
wdenk81050922004-07-11 20:04:51 +00002263
Heiko Schocher2bc4aa52013-08-03 07:22:53 +02002264 if (board_cfb_skip())
2265 return 0;
2266
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002267#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk72c65f62011-07-29 09:55:28 +00002268 debug("KBD: Keyboard init ...\n");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002269 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2270#endif
wdenkc6097192002-11-03 00:24:07 +00002271
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002272 if (skip_dev_init)
2273 return 0;
wdenkc6097192002-11-03 00:24:07 +00002274
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002275 /* Init vga device */
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002276 memset(&console_dev, 0, sizeof(console_dev));
2277 strcpy(console_dev.name, "vga");
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002278 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2279 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2280 console_dev.putc = video_putc; /* 'putc' function */
2281 console_dev.puts = video_puts; /* 'puts' function */
2282 console_dev.tstc = NULL; /* 'tstc' function */
2283 console_dev.getc = NULL; /* 'getc' function */
2284
2285#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2286 /* Also init console device */
2287 console_dev.flags |= DEV_FLAGS_INPUT;
2288 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2289 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00002290#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002291
Wolfgang Denk64e40d72011-07-29 09:55:27 +00002292 if (stdio_register(&console_dev) != 0)
Wolfgang Denkf62f6462009-05-15 10:07:42 +02002293 return 0;
2294
2295 /* Return success */
2296 return 1;
wdenkc6097192002-11-03 00:24:07 +00002297}
Stefan Reinauerc20ee072012-09-28 15:11:12 +00002298
2299void video_position_cursor(unsigned col, unsigned row)
2300{
2301 console_col = min(col, CONSOLE_COLS - 1);
2302 console_row = min(row, CONSOLE_ROWS - 1);
2303}
2304
2305int video_get_pixel_width(void)
2306{
2307 return VIDEO_VISIBLE_COLS;
2308}
2309
2310int video_get_pixel_height(void)
2311{
2312 return VIDEO_VISIBLE_ROWS;
2313}
2314
2315int video_get_screen_rows(void)
2316{
2317 return CONSOLE_ROWS;
2318}
2319
2320int video_get_screen_columns(void)
2321{
2322 return CONSOLE_COLS;
2323}