blob: c09b7e34c7173b8b4d0576ae706d890c3da2d95c [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 Denkd79de1d2013-07-08 09:37:19 +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 *
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 Denk0b4b56e2011-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 Rupperta13e81f2012-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 Denk0b4b56e2011-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ßmann61d01952011-07-18 20:24:04 +020090#include <version.h>
wdenk9dd2b882002-12-03 21:28:10 +000091#include <malloc.h>
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +000092#include <linux/compiler.h>
wdenk9dd2b882002-12-03 21:28:10 +000093
Wolfgang Denk0b4b56e2011-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
wdenke55402c2004-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 Denk0b4b56e2011-07-29 09:55:27 +0000106/*
107 * Defines for the CT69000 driver
108 */
wdenke55402c2004-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 Denk0b4b56e2011-07-29 09:55:27 +0000116/*
117 * Defines for the SED13806 driver
118 */
wdenk9dd2b882002-12-03 21:28:10 +0000119#ifdef CONFIG_VIDEO_SED13806
120
wdenkda54bc92004-08-04 21:56:49 +0000121#ifndef CONFIG_TOTAL5200
wdenk9dd2b882002-12-03 21:28:10 +0000122#define VIDEO_FB_LITTLE_ENDIAN
wdenkda54bc92004-08-04 21:56:49 +0000123#endif
wdenk9dd2b882002-12-03 21:28:10 +0000124#define VIDEO_HW_RECTFILL
125#define VIDEO_HW_BITBLT
126#endif
127
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000128/*
129 * Defines for the SED13806 driver
130 */
Stefan Roesed9d97742005-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 Vasutffdd4662013-04-28 09:20:03 +0000138#ifdef CONFIG_VIDEO_MXS
139#define VIDEO_FB_16BPP_WORD_SWAP
140#endif
141
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000142/*
143 * Defines for the MB862xx driver
144 */
Anatolij Gustschin3545f592008-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 Gustschine7e44a02009-10-23 12:03:14 +0200150#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100151#define VIDEO_HW_RECTFILL
152#define VIDEO_HW_BITBLT
153#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200154#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100155
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000156/*
Helmut Raiger0385c132011-10-12 23:16:29 +0000157 * Defines for the i.MX31 driver (mx3fb.c)
158 */
Fabio Estevamc6dd2e02012-05-31 07:23:56 +0000159#if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
Helmut Raiger0385c132011-10-12 23:16:29 +0000160#define VIDEO_FB_16BPP_WORD_SWAP
161#endif
162
163/*
Wolfgang Denk0b4b56e2011-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 Winkler2a90ed02013-06-17 11:31:29 -0700168#include <splash.h>
169
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000170/*
171 * some Macros
172 */
wdenke55402c2004-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 Denk0b4b56e2011-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
wdenke55402c2004-03-14 16:51:43 +0000184#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000185#include <i8042.h>
186
wdenke55402c2004-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 Denk0b4b56e2011-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-VILLARD2a7a0312009-05-16 12:14:54 +0200198#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000199#include <video_font.h>
Che-Liang Chiou41132c02011-10-21 17:04:21 +0800200#include <video_font_data.h>
wdenkc6097192002-11-03 00:24:07 +0000201
Jon Loeliger30c2f242007-07-10 11:13:21 -0500202#if defined(CONFIG_CMD_DATE)
203#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000204#endif
205
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500206#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000207#include <watchdog.h>
208#include <bmp_layout.h>
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +0200209#include <splash.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200210#endif
211
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000212/*
213 * Cursor definition:
214 * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c)
215 * to let the cursor blink. Uses the macros
216 * CURSOR_OFF and CURSOR_ON.
217 * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
218 * blinking is provided. Uses the macros CURSOR_SET
219 * and CURSOR_OFF.
220 * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the
221 * graphic chip. Uses the macro CURSOR_SET.
222 * ATTENTION: If booting an OS, the display driver
223 * must disable the hardware register of the graphic
224 * chip. Otherwise a blinking field is displayed
225 */
wdenkc6097192002-11-03 00:24:07 +0000226#if !defined(CONFIG_CONSOLE_CURSOR) && \
227 !defined(CONFIG_VIDEO_SW_CURSOR) && \
228 !defined(CONFIG_VIDEO_HW_CURSOR)
229/* no Cursor defined */
230#define CURSOR_ON
231#define CURSOR_OFF
232#define CURSOR_SET
233#endif
234
Gabe Black12874de2011-11-30 13:50:50 +0000235#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
236#if defined(CURSOR_ON) || \
237 (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000238#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
239 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000240#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000241void console_cursor(int state);
242
Timur Tabibe0c74e2010-08-27 15:45:47 -0500243#define CURSOR_ON console_cursor(1)
244#define CURSOR_OFF console_cursor(0)
Gabe Black12874de2011-11-30 13:50:50 +0000245#define CURSOR_SET video_set_cursor()
246#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
247
248#ifdef CONFIG_CONSOLE_CURSOR
249#ifndef CONFIG_CONSOLE_TIME
250#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
251#endif
wdenkc6097192002-11-03 00:24:07 +0000252#ifndef CONFIG_I8042_KBD
Marcel Ziswileraea68562007-12-30 03:30:46 +0100253#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000254#endif
wdenkc6097192002-11-03 00:24:07 +0000255#endif /* CONFIG_CONSOLE_CURSOR */
256
wdenkc6097192002-11-03 00:24:07 +0000257
258#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +0000259#ifdef CURSOR_ON
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000260#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
261 or CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000262#endif
263#define CURSOR_ON
264#define CURSOR_OFF
265#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabibe0c74e2010-08-27 15:45:47 -0500266 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000267#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000268
wdenke55402c2004-03-14 16:51:43 +0000269#ifdef CONFIG_VIDEO_LOGO
270#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000271#include <bmp_logo.h>
Che-Liang Chiou5639fc62011-10-20 23:04:20 +0000272#include <bmp_logo_data.h>
wdenke55402c2004-03-14 16:51:43 +0000273#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
274#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
275#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
276#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000277
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000278#else /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000279#define LINUX_LOGO_WIDTH 80
280#define LINUX_LOGO_HEIGHT 80
281#define LINUX_LOGO_COLORS 214
282#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000283#define __initdata
284#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000285#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
286#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
287#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
288#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000289#endif /* CONFIG_VIDEO_BMP_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000290#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
291#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000292#else /* CONFIG_VIDEO_LOGO */
wdenke55402c2004-03-14 16:51:43 +0000293#define VIDEO_LOGO_WIDTH 0
294#define VIDEO_LOGO_HEIGHT 0
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000295#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000296
wdenke55402c2004-03-14 16:51:43 +0000297#define VIDEO_COLS VIDEO_VISIBLE_COLS
298#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
299#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
300#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
301#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
302#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000303
wdenke55402c2004-03-14 16:51:43 +0000304#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100305#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000306#else
wdenke55402c2004-03-14 16:51:43 +0000307#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000308#endif
309
wdenke55402c2004-03-14 16:51:43 +0000310#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
311#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
312#define CONSOLE_ROW_FIRST (video_console_address)
313#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
314#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
315#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
316#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000317
318/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000319#ifdef VIDEO_FB_LITTLE_ENDIAN
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000320#define SWAP16(x) ((((x) & 0x00ff) << 8) | \
321 ((x) >> 8) \
322 )
323#define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
324 (((x) & 0x0000ff00) << 8) | \
325 (((x) & 0x00ff0000) >> 8) | \
326 (((x) & 0xff000000) >> 24) \
327 )
328#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
329 (((x) & 0x0000ff00) >> 8) | \
330 (((x) & 0x00ff0000) << 8) | \
331 (((x) & 0xff000000) >> 8) \
332 )
wdenkc6097192002-11-03 00:24:07 +0000333#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000334#define SWAP16(x) (x)
335#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200336#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000337#define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
Andrew Dyer5601c612008-08-29 12:30:39 -0500338#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000339#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100340#endif
wdenkc6097192002-11-03 00:24:07 +0000341#endif
342
wdenkc6097192002-11-03 00:24:07 +0000343#ifdef CONFIG_CONSOLE_EXTRA_INFO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000344/*
345 * setup a board string: type, speed, etc.
346 *
347 * line_number: location to place info string beside logo
348 * info: buffer for info string
349 */
350extern void video_get_info_str(int line_number, char *info);
wdenkc6097192002-11-03 00:24:07 +0000351#endif
352
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200353DECLARE_GLOBAL_DATA_PTR;
354
wdenkc6097192002-11-03 00:24:07 +0000355/* Locals */
356static GraphicDevice *pGD; /* Pointer to Graphic array */
357
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000358static void *video_fb_address; /* frame buffer address */
wdenke55402c2004-03-14 16:51:43 +0000359static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000360
Matthias Weisser76d70862010-01-12 12:06:31 +0100361static int video_logo_height = VIDEO_LOGO_HEIGHT;
362
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000363static int __maybe_unused cursor_state;
364static int __maybe_unused old_col;
365static int __maybe_unused old_row;
Gabe Black12874de2011-11-30 13:50:50 +0000366
Wolfgang Denka87b2a952011-07-30 12:48:09 +0000367static int console_col; /* cursor col */
368static int console_row; /* cursor row */
wdenkc6097192002-11-03 00:24:07 +0000369
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000370static u32 eorx, fgx, bgx; /* color pats */
wdenkc6097192002-11-03 00:24:07 +0000371
Anatolij Gustschindbad2b82012-06-05 09:19:18 +0200372static int cfb_do_flush_cache;
373
Pali Rohár4a57da32012-10-19 13:30:09 +0000374#ifdef CONFIG_CFB_CONSOLE_ANSI
375static char ansi_buf[10];
376static int ansi_buf_size;
377static int ansi_colors_need_revert;
378static int ansi_cursor_hidden;
379#endif
380
wdenkc6097192002-11-03 00:24:07 +0000381static const int video_font_draw_table8[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000382 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
383 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
384 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
385 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
386};
wdenkc6097192002-11-03 00:24:07 +0000387
388static const int video_font_draw_table15[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000389 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
390};
wdenkc6097192002-11-03 00:24:07 +0000391
392static const int video_font_draw_table16[] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000393 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
394};
wdenkc6097192002-11-03 00:24:07 +0000395
396static const int video_font_draw_table24[16][3] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000397 {0x00000000, 0x00000000, 0x00000000},
398 {0x00000000, 0x00000000, 0x00ffffff},
399 {0x00000000, 0x0000ffff, 0xff000000},
400 {0x00000000, 0x0000ffff, 0xffffffff},
401 {0x000000ff, 0xffff0000, 0x00000000},
402 {0x000000ff, 0xffff0000, 0x00ffffff},
403 {0x000000ff, 0xffffffff, 0xff000000},
404 {0x000000ff, 0xffffffff, 0xffffffff},
405 {0xffffff00, 0x00000000, 0x00000000},
406 {0xffffff00, 0x00000000, 0x00ffffff},
407 {0xffffff00, 0x0000ffff, 0xff000000},
408 {0xffffff00, 0x0000ffff, 0xffffffff},
409 {0xffffffff, 0xffff0000, 0x00000000},
410 {0xffffffff, 0xffff0000, 0x00ffffff},
411 {0xffffffff, 0xffffffff, 0xff000000},
412 {0xffffffff, 0xffffffff, 0xffffffff}
413};
wdenkc6097192002-11-03 00:24:07 +0000414
415static const int video_font_draw_table32[16][4] = {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000416 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
417 {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
418 {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
419 {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
420 {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
421 {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
422 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
423 {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
424 {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
425 {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
426 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
427 {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
428 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
429 {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
430 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
431 {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
432};
wdenkc6097192002-11-03 00:24:07 +0000433
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000434static void video_drawchars(int xx, int yy, unsigned char *s, int count)
wdenkc6097192002-11-03 00:24:07 +0000435{
wdenke55402c2004-03-14 16:51:43 +0000436 u8 *cdat, *dest, *dest0;
437 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000438
wdenke55402c2004-03-14 16:51:43 +0000439 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
440 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000441
wdenke55402c2004-03-14 16:51:43 +0000442 switch (VIDEO_DATA_FORMAT) {
443 case GDF__8BIT_INDEX:
444 case GDF__8BIT_332RGB:
445 while (count--) {
446 c = *s;
447 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
448 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000449 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000450 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000451
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000452 ((u32 *) dest)[0] =
453 (video_font_draw_table8[bits >> 4] &
454 eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200455
456 if (VIDEO_FONT_WIDTH == 4)
457 continue;
458
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000459 ((u32 *) dest)[1] =
460 (video_font_draw_table8[bits & 15] &
461 eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000462 }
463 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
464 s++;
465 }
466 break;
wdenkc6097192002-11-03 00:24:07 +0000467
wdenke55402c2004-03-14 16:51:43 +0000468 case GDF_15BIT_555RGB:
469 while (count--) {
470 c = *s;
471 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
472 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000473 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000474 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000475
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000476 ((u32 *) dest)[0] =
477 SHORTSWAP32((video_font_draw_table15
478 [bits >> 6] & eorx) ^
479 bgx);
480 ((u32 *) dest)[1] =
481 SHORTSWAP32((video_font_draw_table15
482 [bits >> 4 & 3] & eorx) ^
483 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200484
485 if (VIDEO_FONT_WIDTH == 4)
486 continue;
487
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000488 ((u32 *) dest)[2] =
489 SHORTSWAP32((video_font_draw_table15
490 [bits >> 2 & 3] & eorx) ^
491 bgx);
492 ((u32 *) dest)[3] =
493 SHORTSWAP32((video_font_draw_table15
494 [bits & 3] & eorx) ^
495 bgx);
wdenke55402c2004-03-14 16:51:43 +0000496 }
497 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
498 s++;
499 }
500 break;
wdenkc6097192002-11-03 00:24:07 +0000501
wdenke55402c2004-03-14 16:51:43 +0000502 case GDF_16BIT_565RGB:
503 while (count--) {
504 c = *s;
505 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
506 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000507 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000508 u8 bits = *cdat++;
509
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000510 ((u32 *) dest)[0] =
511 SHORTSWAP32((video_font_draw_table16
512 [bits >> 6] & eorx) ^
513 bgx);
514 ((u32 *) dest)[1] =
515 SHORTSWAP32((video_font_draw_table16
516 [bits >> 4 & 3] & eorx) ^
517 bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200518
519 if (VIDEO_FONT_WIDTH == 4)
520 continue;
521
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000522 ((u32 *) dest)[2] =
523 SHORTSWAP32((video_font_draw_table16
524 [bits >> 2 & 3] & eorx) ^
525 bgx);
526 ((u32 *) dest)[3] =
527 SHORTSWAP32((video_font_draw_table16
528 [bits & 3] & eorx) ^
529 bgx);
wdenke55402c2004-03-14 16:51:43 +0000530 }
531 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
532 s++;
533 }
534 break;
535
536 case GDF_32BIT_X888RGB:
537 while (count--) {
538 c = *s;
539 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
540 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000541 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000542 u8 bits = *cdat++;
543
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000544 ((u32 *) dest)[0] =
545 SWAP32((video_font_draw_table32
546 [bits >> 4][0] & eorx) ^ bgx);
547 ((u32 *) dest)[1] =
548 SWAP32((video_font_draw_table32
549 [bits >> 4][1] & eorx) ^ bgx);
550 ((u32 *) dest)[2] =
551 SWAP32((video_font_draw_table32
552 [bits >> 4][2] & eorx) ^ bgx);
553 ((u32 *) dest)[3] =
554 SWAP32((video_font_draw_table32
555 [bits >> 4][3] & eorx) ^ bgx);
Marek Vasut118959f2013-07-30 23:37:59 +0200556
557
558 if (VIDEO_FONT_WIDTH == 4)
559 continue;
560
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000561 ((u32 *) dest)[4] =
562 SWAP32((video_font_draw_table32
563 [bits & 15][0] & eorx) ^ bgx);
564 ((u32 *) dest)[5] =
565 SWAP32((video_font_draw_table32
566 [bits & 15][1] & eorx) ^ bgx);
567 ((u32 *) dest)[6] =
568 SWAP32((video_font_draw_table32
569 [bits & 15][2] & eorx) ^ bgx);
570 ((u32 *) dest)[7] =
571 SWAP32((video_font_draw_table32
572 [bits & 15][3] & eorx) ^ bgx);
wdenke55402c2004-03-14 16:51:43 +0000573 }
574 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
575 s++;
576 }
577 break;
578
579 case GDF_24BIT_888RGB:
580 while (count--) {
581 c = *s;
582 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
583 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000584 rows--; dest += VIDEO_LINE_LEN) {
wdenke55402c2004-03-14 16:51:43 +0000585 u8 bits = *cdat++;
586
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000587 ((u32 *) dest)[0] =
588 (video_font_draw_table24[bits >> 4][0]
589 & eorx) ^ bgx;
590 ((u32 *) dest)[1] =
591 (video_font_draw_table24[bits >> 4][1]
592 & eorx) ^ bgx;
593 ((u32 *) dest)[2] =
594 (video_font_draw_table24[bits >> 4][2]
595 & eorx) ^ bgx;
Marek Vasut118959f2013-07-30 23:37:59 +0200596
597 if (VIDEO_FONT_WIDTH == 4)
598 continue;
599
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000600 ((u32 *) dest)[3] =
601 (video_font_draw_table24[bits & 15][0]
602 & eorx) ^ bgx;
603 ((u32 *) dest)[4] =
604 (video_font_draw_table24[bits & 15][1]
605 & eorx) ^ bgx;
606 ((u32 *) dest)[5] =
607 (video_font_draw_table24[bits & 15][2]
608 & eorx) ^ bgx;
wdenke55402c2004-03-14 16:51:43 +0000609 }
610 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
611 s++;
612 }
613 break;
wdenk57b2d802003-06-27 21:31:46 +0000614 }
wdenkc6097192002-11-03 00:24:07 +0000615}
616
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000617static inline void video_drawstring(int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000618{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000619 video_drawchars(xx, yy, s, strlen((char *) s));
wdenkc6097192002-11-03 00:24:07 +0000620}
621
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000622static void video_putchar(int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000623{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000624 video_drawchars(xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000625}
626
wdenkc6097192002-11-03 00:24:07 +0000627#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000628static void video_set_cursor(void)
wdenkc6097192002-11-03 00:24:07 +0000629{
Gabe Black12874de2011-11-30 13:50:50 +0000630 if (cursor_state)
631 console_cursor(0);
632 console_cursor(1);
wdenkc6097192002-11-03 00:24:07 +0000633}
Gabe Black12874de2011-11-30 13:50:50 +0000634
Anatolij Gustschin814d0e12011-12-07 03:58:10 +0000635static void video_invertchar(int xx, int yy)
636{
637 int firstx = xx * VIDEO_PIXEL_SIZE;
638 int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
639 int firsty = yy * VIDEO_LINE_LEN;
640 int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
641 int x, y;
642 for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
643 for (x = firstx; x < lastx; x++) {
644 u8 *dest = (u8 *)(video_fb_address) + x + y;
645 *dest = ~*dest;
646 }
647 }
648}
Gabe Black12874de2011-11-30 13:50:50 +0000649
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000650void console_cursor(int state)
wdenkc6097192002-11-03 00:24:07 +0000651{
wdenkc6097192002-11-03 00:24:07 +0000652#ifdef CONFIG_CONSOLE_TIME
wdenke55402c2004-03-14 16:51:43 +0000653 struct rtc_time tm;
654 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000655
wdenke55402c2004-03-14 16:51:43 +0000656 /* time update only if cursor is on (faster scroll) */
657 if (state) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000658 rtc_get(&tm);
wdenkc6097192002-11-03 00:24:07 +0000659
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000660 sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
661 tm.tm_sec);
662 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
663 VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +0000664
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000665 sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
666 tm.tm_year);
667 video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
668 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
669 (uchar *) info);
wdenke55402c2004-03-14 16:51:43 +0000670 }
wdenkc6097192002-11-03 00:24:07 +0000671#endif
672
Gabe Black12874de2011-11-30 13:50:50 +0000673 if (cursor_state != state) {
674 if (cursor_state) {
675 /* turn off the cursor */
676 video_invertchar(old_col * VIDEO_FONT_WIDTH,
677 old_row * VIDEO_FONT_HEIGHT +
678 video_logo_height);
679 } else {
680 /* turn off the cursor and record where it is */
681 video_invertchar(console_col * VIDEO_FONT_WIDTH,
682 console_row * VIDEO_FONT_HEIGHT +
683 video_logo_height);
684 old_col = console_col;
685 old_row = console_row;
686 }
687 cursor_state = state;
wdenke55402c2004-03-14 16:51:43 +0000688 }
Eric Nelson54142422013-05-06 14:27:28 +0200689 if (cfb_do_flush_cache)
690 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000691}
692#endif
693
wdenkc6097192002-11-03 00:24:07 +0000694#ifndef VIDEO_HW_RECTFILL
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000695static void memsetl(int *p, int c, int v)
wdenkc6097192002-11-03 00:24:07 +0000696{
wdenke55402c2004-03-14 16:51:43 +0000697 while (c--)
698 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000699}
700#endif
701
wdenkc6097192002-11-03 00:24:07 +0000702#ifndef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000703static void memcpyl(int *d, int *s, int c)
wdenkc6097192002-11-03 00:24:07 +0000704{
wdenke55402c2004-03-14 16:51:43 +0000705 while (c--)
706 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000707}
708#endif
709
Pali Rohár16658612012-04-28 07:26:44 +0000710static void console_clear_line(int line, int begin, int end)
711{
712#ifdef VIDEO_HW_RECTFILL
713 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
714 VIDEO_FONT_WIDTH * begin, /* dest pos x */
715 video_logo_height +
716 VIDEO_FONT_HEIGHT * line, /* dest pos y */
717 VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
718 VIDEO_FONT_HEIGHT, /* frame height */
719 bgx /* fill color */
720 );
721#else
722 if (begin == 0 && (end + 1) == CONSOLE_COLS) {
723 memsetl(CONSOLE_ROW_FIRST +
724 CONSOLE_ROW_SIZE * line, /* offset of row */
725 CONSOLE_ROW_SIZE >> 2, /* length of row */
726 bgx /* fill color */
727 );
728 } else {
729 void *offset;
730 int i, size;
731
732 offset = CONSOLE_ROW_FIRST +
733 CONSOLE_ROW_SIZE * line + /* offset of row */
734 VIDEO_FONT_WIDTH *
735 VIDEO_PIXEL_SIZE * begin; /* offset of col */
736 size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
737 size >>= 2; /* length to end for memsetl() */
738 /* fill at col offset of i'th line using bgx as fill color */
739 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
740 memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
741 }
742#endif
743}
744
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000745static void console_scrollup(void)
wdenkc6097192002-11-03 00:24:07 +0000746{
wdenke55402c2004-03-14 16:51:43 +0000747 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000748
749#ifdef VIDEO_HW_BITBLT
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000750 video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
751 0, /* source pos x */
752 video_logo_height +
753 VIDEO_FONT_HEIGHT, /* source pos y */
754 0, /* dest pos x */
755 video_logo_height, /* dest pos y */
756 VIDEO_VISIBLE_COLS, /* frame width */
757 VIDEO_VISIBLE_ROWS
758 - video_logo_height
759 - VIDEO_FONT_HEIGHT /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000760 );
wdenkc6097192002-11-03 00:24:07 +0000761#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000762 memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
763 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000764#endif
wdenke55402c2004-03-14 16:51:43 +0000765 /* clear the last one */
Pali Rohár16658612012-04-28 07:26:44 +0000766 console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1);
wdenkc6097192002-11-03 00:24:07 +0000767}
768
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000769static void console_back(void)
wdenkc6097192002-11-03 00:24:07 +0000770{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500771 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000772
wdenke55402c2004-03-14 16:51:43 +0000773 if (console_col < 0) {
774 console_col = CONSOLE_COLS - 1;
775 console_row--;
776 if (console_row < 0)
777 console_row = 0;
778 }
wdenkc6097192002-11-03 00:24:07 +0000779}
780
Pali Rohár4a57da32012-10-19 13:30:09 +0000781#ifdef CONFIG_CFB_CONSOLE_ANSI
782
783static void console_clear(void)
784{
785#ifdef VIDEO_HW_RECTFILL
786 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
787 0, /* dest pos x */
788 video_logo_height, /* dest pos y */
789 VIDEO_VISIBLE_COLS, /* frame width */
790 VIDEO_VISIBLE_ROWS, /* frame height */
791 bgx /* fill color */
792 );
793#else
794 memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
795#endif
796}
797
798static void console_cursor_fix(void)
799{
800 if (console_row < 0)
801 console_row = 0;
802 if (console_row >= CONSOLE_ROWS)
803 console_row = CONSOLE_ROWS - 1;
804 if (console_col < 0)
805 console_col = 0;
806 if (console_col >= CONSOLE_COLS)
807 console_col = CONSOLE_COLS - 1;
808}
809
810static void console_cursor_up(int n)
811{
812 console_row -= n;
813 console_cursor_fix();
814}
815
816static void console_cursor_down(int n)
817{
818 console_row += n;
819 console_cursor_fix();
820}
821
822static void console_cursor_left(int n)
wdenkc6097192002-11-03 00:24:07 +0000823{
Pali Rohár4a57da32012-10-19 13:30:09 +0000824 console_col -= n;
825 console_cursor_fix();
826}
827
828static void console_cursor_right(int n)
829{
830 console_col += n;
831 console_cursor_fix();
832}
833
834static void console_cursor_set_position(int row, int col)
835{
836 if (console_row != -1)
837 console_row = row;
838 if (console_col != -1)
839 console_col = col;
840 console_cursor_fix();
841}
842
843static void console_previousline(int n)
844{
845 /* FIXME: also scroll terminal ? */
846 console_row -= n;
847 console_cursor_fix();
848}
849
850static void console_swap_colors(void)
851{
852 eorx = fgx;
853 fgx = bgx;
854 bgx = eorx;
855 eorx = fgx ^ bgx;
856}
857
858static inline int console_cursor_is_visible(void)
859{
860 return !ansi_cursor_hidden;
861}
862#else
863static inline int console_cursor_is_visible(void)
864{
865 return 1;
866}
867#endif
868
869static void console_newline(int n)
870{
871 console_row += n;
wdenke55402c2004-03-14 16:51:43 +0000872 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000873
wdenke55402c2004-03-14 16:51:43 +0000874 /* Check if we need to scroll the terminal */
875 if (console_row >= CONSOLE_ROWS) {
876 /* Scroll everything up */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000877 console_scrollup();
wdenkc6097192002-11-03 00:24:07 +0000878
wdenke55402c2004-03-14 16:51:43 +0000879 /* Decrement row number */
Pali Rohár4a57da32012-10-19 13:30:09 +0000880 console_row = CONSOLE_ROWS - 1;
wdenke55402c2004-03-14 16:51:43 +0000881 }
wdenkc6097192002-11-03 00:24:07 +0000882}
883
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000884static void console_cr(void)
Anatolij Gustschin938db912008-01-11 02:39:47 +0100885{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500886 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100887}
888
Pali Rohár4a57da32012-10-19 13:30:09 +0000889static void parse_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +0000890{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100891 static int nl = 1;
892
Pali Rohár4a57da32012-10-19 13:30:09 +0000893 if (console_cursor_is_visible())
894 CURSOR_OFF;
Gabe Black12874de2011-11-30 13:50:50 +0000895
wdenke55402c2004-03-14 16:51:43 +0000896 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100897 case 13: /* back to first column */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000898 console_cr();
wdenke55402c2004-03-14 16:51:43 +0000899 break;
wdenkc6097192002-11-03 00:24:07 +0000900
wdenke55402c2004-03-14 16:51:43 +0000901 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100902 if (console_col || (!console_col && nl))
Pali Rohár4a57da32012-10-19 13:30:09 +0000903 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100904 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000905 break;
wdenkc6097192002-11-03 00:24:07 +0000906
wdenke55402c2004-03-14 16:51:43 +0000907 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500908 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000909 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000910
wdenke55402c2004-03-14 16:51:43 +0000911 if (console_col >= CONSOLE_COLS)
Pali Rohár4a57da32012-10-19 13:30:09 +0000912 console_newline(1);
wdenke55402c2004-03-14 16:51:43 +0000913 break;
wdenkc6097192002-11-03 00:24:07 +0000914
wdenke55402c2004-03-14 16:51:43 +0000915 case 8: /* backspace */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000916 console_back();
wdenke55402c2004-03-14 16:51:43 +0000917 break;
wdenkc6097192002-11-03 00:24:07 +0000918
Pali Rohár9d735b62012-04-28 07:26:47 +0000919 case 7: /* bell */
920 break; /* ignored */
921
wdenke55402c2004-03-14 16:51:43 +0000922 default: /* draw the char */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +0000923 video_putchar(console_col * VIDEO_FONT_WIDTH,
924 console_row * VIDEO_FONT_HEIGHT, c);
wdenke55402c2004-03-14 16:51:43 +0000925 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000926
wdenke55402c2004-03-14 16:51:43 +0000927 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100928 if (console_col >= CONSOLE_COLS) {
Pali Rohár4a57da32012-10-19 13:30:09 +0000929 console_newline(1);
Anatolij Gustschin938db912008-01-11 02:39:47 +0100930 nl = 0;
931 }
wdenke55402c2004-03-14 16:51:43 +0000932 }
Pali Rohár4a57da32012-10-19 13:30:09 +0000933
934 if (console_cursor_is_visible())
935 CURSOR_SET;
936}
937
938void video_putc(const char c)
939{
940#ifdef CONFIG_CFB_CONSOLE_ANSI
941 int i;
942
943 if (c == 27) {
944 for (i = 0; i < ansi_buf_size; ++i)
945 parse_putc(ansi_buf[i]);
946 ansi_buf[0] = 27;
947 ansi_buf_size = 1;
948 return;
949 }
950
951 if (ansi_buf_size > 0) {
952 /*
953 * 0 - ESC
954 * 1 - [
955 * 2 - num1
956 * 3 - ..
957 * 4 - ;
958 * 5 - num2
959 * 6 - ..
960 * - cchar
961 */
962 int next = 0;
963
964 int flush = 0;
965 int fail = 0;
966
967 int num1 = 0;
968 int num2 = 0;
969 int cchar = 0;
970
971 ansi_buf[ansi_buf_size++] = c;
972
973 if (ansi_buf_size >= sizeof(ansi_buf))
974 fail = 1;
975
976 for (i = 0; i < ansi_buf_size; ++i) {
977 if (fail)
978 break;
979
980 switch (next) {
981 case 0:
982 if (ansi_buf[i] == 27)
983 next = 1;
984 else
985 fail = 1;
986 break;
987
988 case 1:
989 if (ansi_buf[i] == '[')
990 next = 2;
991 else
992 fail = 1;
993 break;
994
995 case 2:
996 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
997 num1 = ansi_buf[i]-'0';
998 next = 3;
999 } else if (ansi_buf[i] != '?') {
1000 --i;
1001 num1 = 1;
1002 next = 4;
1003 }
1004 break;
1005
1006 case 3:
1007 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1008 num1 *= 10;
1009 num1 += ansi_buf[i]-'0';
1010 } else {
1011 --i;
1012 next = 4;
1013 }
1014 break;
1015
1016 case 4:
1017 if (ansi_buf[i] != ';') {
1018 --i;
1019 next = 7;
1020 } else
1021 next = 5;
1022 break;
1023
1024 case 5:
1025 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1026 num2 = ansi_buf[i]-'0';
1027 next = 6;
1028 } else
1029 fail = 1;
1030 break;
1031
1032 case 6:
1033 if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
1034 num2 *= 10;
1035 num2 += ansi_buf[i]-'0';
1036 } else {
1037 --i;
1038 next = 7;
1039 }
1040 break;
1041
1042 case 7:
1043 if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
1044 || ansi_buf[i] == 'J'
1045 || ansi_buf[i] == 'K'
1046 || ansi_buf[i] == 'h'
1047 || ansi_buf[i] == 'l'
1048 || ansi_buf[i] == 'm') {
1049 cchar = ansi_buf[i];
1050 flush = 1;
1051 } else
1052 fail = 1;
1053 break;
1054 }
1055 }
1056
1057 if (fail) {
1058 for (i = 0; i < ansi_buf_size; ++i)
1059 parse_putc(ansi_buf[i]);
1060 ansi_buf_size = 0;
1061 return;
1062 }
1063
1064 if (flush) {
1065 if (!ansi_cursor_hidden)
1066 CURSOR_OFF;
1067 ansi_buf_size = 0;
1068 switch (cchar) {
1069 case 'A':
1070 /* move cursor num1 rows up */
1071 console_cursor_up(num1);
1072 break;
1073 case 'B':
1074 /* move cursor num1 rows down */
1075 console_cursor_down(num1);
1076 break;
1077 case 'C':
1078 /* move cursor num1 columns forward */
1079 console_cursor_right(num1);
1080 break;
1081 case 'D':
1082 /* move cursor num1 columns back */
1083 console_cursor_left(num1);
1084 break;
1085 case 'E':
1086 /* move cursor num1 rows up at begin of row */
1087 console_previousline(num1);
1088 break;
1089 case 'F':
1090 /* move cursor num1 rows down at begin of row */
1091 console_newline(num1);
1092 break;
1093 case 'G':
1094 /* move cursor to column num1 */
1095 console_cursor_set_position(-1, num1-1);
1096 break;
1097 case 'H':
1098 /* move cursor to row num1, column num2 */
1099 console_cursor_set_position(num1-1, num2-1);
1100 break;
1101 case 'J':
1102 /* clear console and move cursor to 0, 0 */
1103 console_clear();
1104 console_cursor_set_position(0, 0);
1105 break;
1106 case 'K':
1107 /* clear line */
1108 if (num1 == 0)
1109 console_clear_line(console_row,
1110 console_col,
1111 CONSOLE_COLS-1);
1112 else if (num1 == 1)
1113 console_clear_line(console_row,
1114 0, console_col);
1115 else
1116 console_clear_line(console_row,
1117 0, CONSOLE_COLS-1);
1118 break;
1119 case 'h':
1120 ansi_cursor_hidden = 0;
1121 break;
1122 case 'l':
1123 ansi_cursor_hidden = 1;
1124 break;
1125 case 'm':
1126 if (num1 == 0) { /* reset swapped colors */
1127 if (ansi_colors_need_revert) {
1128 console_swap_colors();
1129 ansi_colors_need_revert = 0;
1130 }
1131 } else if (num1 == 7) { /* once swap colors */
1132 if (!ansi_colors_need_revert) {
1133 console_swap_colors();
1134 ansi_colors_need_revert = 1;
1135 }
1136 }
1137 break;
1138 }
1139 if (!ansi_cursor_hidden)
1140 CURSOR_SET;
1141 }
1142 } else {
1143 parse_putc(c);
1144 }
1145#else
1146 parse_putc(c);
1147#endif
Eric Nelson54142422013-05-06 14:27:28 +02001148 if (cfb_do_flush_cache)
1149 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
Timur Tabibe0c74e2010-08-27 15:45:47 -05001150}
wdenkc6097192002-11-03 00:24:07 +00001151
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001152void video_puts(const char *s)
wdenkc6097192002-11-03 00:24:07 +00001153{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001154 int count = strlen(s);
wdenke55402c2004-03-14 16:51:43 +00001155
1156 while (count--)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001157 video_putc(*s++);
wdenke55402c2004-03-14 16:51:43 +00001158}
1159
Anatolij Gustschina043c342010-05-01 22:21:09 +02001160/*
1161 * Do not enforce drivers (or board code) to provide empty
1162 * video_set_lut() if they do not support 8 bpp format.
1163 * Implement weak default function instead.
1164 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001165void __video_set_lut(unsigned int index, unsigned char r,
1166 unsigned char g, unsigned char b)
Anatolij Gustschina043c342010-05-01 22:21:09 +02001167{
1168}
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001169
1170void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char)
1171 __attribute__ ((weak, alias("__video_set_lut")));
Anatolij Gustschina043c342010-05-01 22:21:09 +02001172
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001173#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +00001174
1175#define FILL_8BIT_332RGB(r,g,b) { \
1176 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
1177 fb ++; \
1178}
1179
1180#define FILL_15BIT_555RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001181 *(unsigned short *)fb = \
1182 SWAP16((unsigned short)(((r>>3)<<10) | \
1183 ((g>>3)<<5) | \
1184 (b>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001185 fb += 2; \
1186}
1187
1188#define FILL_16BIT_565RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001189 *(unsigned short *)fb = \
1190 SWAP16((unsigned short)((((r)>>3)<<11)| \
1191 (((g)>>2)<<5) | \
1192 ((b)>>3))); \
wdenke55402c2004-03-14 16:51:43 +00001193 fb += 2; \
1194}
1195
1196#define FILL_32BIT_X888RGB(r,g,b) { \
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001197 *(unsigned long *)fb = \
1198 SWAP32((unsigned long)(((r<<16) | \
1199 (g<<8) | \
1200 b))); \
wdenke55402c2004-03-14 16:51:43 +00001201 fb += 4; \
1202}
1203
1204#ifdef VIDEO_FB_LITTLE_ENDIAN
1205#define FILL_24BIT_888RGB(r,g,b) { \
1206 fb[0] = b; \
1207 fb[1] = g; \
1208 fb[2] = r; \
1209 fb += 3; \
1210}
1211#else
1212#define FILL_24BIT_888RGB(r,g,b) { \
1213 fb[0] = r; \
1214 fb[1] = g; \
1215 fb[2] = b; \
1216 fb += 3; \
1217}
1218#endif
1219
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001220#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001221static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001222{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001223 ushort *dst = (ushort *) fb;
1224 ushort color = (ushort) (((r >> 3) << 10) |
1225 ((g >> 3) << 5) |
1226 (b >> 3));
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001227 if (x & 1)
1228 *(--dst) = color;
1229 else
1230 *(++dst) = color;
1231}
1232#endif
wdenke55402c2004-03-14 16:51:43 +00001233
1234/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001235 * RLE8 bitmap support
1236 */
1237
1238#ifdef CONFIG_VIDEO_BMP_RLE8
1239/* Pre-calculated color table entry */
1240struct palette {
1241 union {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001242 unsigned short w; /* word */
1243 unsigned int dw; /* double word */
1244 } ce; /* color entry */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001245};
1246
1247/*
1248 * Helper to draw encoded/unencoded run.
1249 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001250static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
1251 int cnt, int enc)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001252{
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001253 ulong addr = (ulong) *fb;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001254 int *off;
1255 int enc_off = 1;
1256 int i;
1257
1258 /*
1259 * Setup offset of the color index in the bitmap.
1260 * Color index of encoded run is at offset 1.
1261 */
1262 off = enc ? &enc_off : &i;
1263
1264 switch (VIDEO_DATA_FORMAT) {
1265 case GDF__8BIT_INDEX:
1266 for (i = 0; i < cnt; i++)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001267 *(unsigned char *) addr++ = bm[*off];
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001268 break;
1269 case GDF_15BIT_555RGB:
1270 case GDF_16BIT_565RGB:
1271 /* differences handled while pre-calculating palette */
1272 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001273 *(unsigned short *) addr = p[bm[*off]].ce.w;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001274 addr += 2;
1275 }
1276 break;
1277 case GDF_32BIT_X888RGB:
1278 for (i = 0; i < cnt; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001279 *(unsigned long *) addr = p[bm[*off]].ce.dw;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001280 addr += 4;
1281 }
1282 break;
1283 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001284 *fb = (uchar *) addr; /* return modified address */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001285}
1286
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001287static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff,
1288 int width, int height)
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001289{
1290 unsigned char *bm;
1291 unsigned char *fbp;
1292 unsigned int cnt, runlen;
1293 int decode = 1;
1294 int x, y, bpp, i, ncolors;
1295 struct palette p[256];
1296 bmp_color_table_entry_t cte;
1297 int green_shift, red_off;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001298 int limit = VIDEO_COLS * VIDEO_ROWS;
1299 int pixels = 0;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001300
1301 x = 0;
1302 y = __le32_to_cpu(img->header.height) - 1;
1303 ncolors = __le32_to_cpu(img->header.colors_used);
1304 bpp = VIDEO_PIXEL_SIZE;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001305 fbp = (unsigned char *) ((unsigned int) video_fb_address +
1306 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001307
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001308 bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001309
1310 /* pre-calculate and setup palette */
1311 switch (VIDEO_DATA_FORMAT) {
1312 case GDF__8BIT_INDEX:
1313 for (i = 0; i < ncolors; i++) {
1314 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001315 video_set_lut(i, cte.red, cte.green, cte.blue);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001316 }
1317 break;
1318 case GDF_15BIT_555RGB:
1319 case GDF_16BIT_565RGB:
1320 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
1321 green_shift = 3;
1322 red_off = 10;
1323 } else {
1324 green_shift = 2;
1325 red_off = 11;
1326 }
1327 for (i = 0; i < ncolors; i++) {
1328 cte = img->color_table[i];
1329 p[i].ce.w = SWAP16((unsigned short)
1330 (((cte.red >> 3) << red_off) |
1331 ((cte.green >> green_shift) << 5) |
1332 cte.blue >> 3));
1333 }
1334 break;
1335 case GDF_32BIT_X888RGB:
1336 for (i = 0; i < ncolors; i++) {
1337 cte = img->color_table[i];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001338 p[i].ce.dw = SWAP32((cte.red << 16) |
1339 (cte.green << 8) |
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001340 cte.blue);
1341 }
1342 break;
1343 default:
1344 printf("RLE Bitmap unsupported in video mode 0x%x\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001345 VIDEO_DATA_FORMAT);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001346 return -1;
1347 }
1348
1349 while (decode) {
1350 switch (bm[0]) {
1351 case 0:
1352 switch (bm[1]) {
1353 case 0:
1354 /* scan line end marker */
1355 bm += 2;
1356 x = 0;
1357 y--;
1358 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001359 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001360 (((y + yoff) * VIDEO_COLS) +
1361 xoff) * bpp);
1362 continue;
1363 case 1:
1364 /* end of bitmap data marker */
1365 decode = 0;
1366 break;
1367 case 2:
1368 /* run offset marker */
1369 x += bm[2];
1370 y -= bm[3];
1371 fbp = (unsigned char *)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001372 ((unsigned int) video_fb_address +
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001373 (((y + yoff) * VIDEO_COLS) +
1374 x + xoff) * bpp);
1375 bm += 4;
1376 break;
1377 default:
1378 /* unencoded run */
1379 cnt = bm[1];
1380 runlen = cnt;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001381 pixels += cnt;
1382 if (pixels > limit)
1383 goto error;
1384
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001385 bm += 2;
1386 if (y < height) {
1387 if (x >= width) {
1388 x += runlen;
1389 goto next_run;
1390 }
1391 if (x + runlen > width)
1392 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001393 draw_bitmap(&fbp, bm, p, cnt, 0);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001394 x += runlen;
1395 }
1396next_run:
1397 bm += runlen;
1398 if (runlen & 1)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001399 bm++; /* 0 padding if length is odd */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001400 }
1401 break;
1402 default:
1403 /* encoded run */
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001404 cnt = bm[0];
1405 runlen = cnt;
1406 pixels += cnt;
1407 if (pixels > limit)
1408 goto error;
1409
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001410 if (y < height) { /* only draw into visible area */
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001411 if (x >= width) {
1412 x += runlen;
1413 bm += 2;
1414 continue;
1415 }
1416 if (x + runlen > width)
1417 cnt = width - x;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001418 draw_bitmap(&fbp, bm, p, cnt, 1);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001419 x += runlen;
1420 }
1421 bm += 2;
1422 break;
1423 }
1424 }
1425 return 0;
Anatolij Gustschince5f8df2011-02-21 21:33:29 +01001426error:
1427 printf("Error: Too much encoded pixel data, validate your bitmap\n");
1428 return -1;
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001429}
1430#endif
1431
1432/*
wdenke55402c2004-03-14 16:51:43 +00001433 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001434 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001435int video_display_bitmap(ulong bmp_image, int x, int y)
wdenke55402c2004-03-14 16:51:43 +00001436{
1437 ushort xcount, ycount;
1438 uchar *fb;
1439 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1440 uchar *bmap;
1441 ushort padded_line;
1442 unsigned long width, height, bpp;
1443 unsigned colors;
1444 unsigned long compression;
1445 bmp_color_table_entry_t cte;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001446
Stefan Roesed9d97742005-09-22 09:04:17 +02001447#ifdef CONFIG_VIDEO_BMP_GZIP
1448 unsigned char *dst = NULL;
1449 ulong len;
1450#endif
wdenkc6097192002-11-03 00:24:07 +00001451
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001452 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001453
1454 if (!((bmp->header.signature[0] == 'B') &&
1455 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001456
1457#ifdef CONFIG_VIDEO_BMP_GZIP
1458 /*
1459 * Could be a gzipped bmp image, try to decrompress...
1460 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001461 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1462 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001463 if (dst == NULL) {
1464 printf("Error: malloc in gunzip failed!\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001465 return 1;
Stefan Roese13b93692005-10-08 10:19:07 +02001466 }
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001467 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE,
1468 (uchar *) bmp_image,
1469 &len) != 0) {
1470 printf("Error: no valid bmp or bmp.gz image at %lx\n",
1471 bmp_image);
Stefan Roesed9d97742005-09-22 09:04:17 +02001472 free(dst);
1473 return 1;
1474 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001475 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001476 printf("Image could be truncated "
1477 "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001478 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001479
1480 /*
1481 * Set addr to decompressed image
1482 */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001483 bmp = (bmp_image_t *) dst;
Stefan Roesed9d97742005-09-22 09:04:17 +02001484
1485 if (!((bmp->header.signature[0] == 'B') &&
1486 (bmp->header.signature[1] == 'M'))) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001487 printf("Error: no valid bmp.gz image at %lx\n",
1488 bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001489 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001490 return 1;
1491 }
1492#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001493 printf("Error: no valid bmp image at %lx\n", bmp_image);
wdenke55402c2004-03-14 16:51:43 +00001494 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001495#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001496 }
1497
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001498 width = le32_to_cpu(bmp->header.width);
1499 height = le32_to_cpu(bmp->header.height);
1500 bpp = le16_to_cpu(bmp->header.bit_count);
1501 colors = le32_to_cpu(bmp->header.colors_used);
1502 compression = le32_to_cpu(bmp->header.compression);
wdenke55402c2004-03-14 16:51:43 +00001503
Marek Vasut2eb9a492011-10-21 14:17:04 +00001504 debug("Display-bmp: %ld x %ld with %d colors\n",
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001505 width, height, colors);
wdenke55402c2004-03-14 16:51:43 +00001506
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001507 if (compression != BMP_BI_RGB
1508#ifdef CONFIG_VIDEO_BMP_RLE8
1509 && compression != BMP_BI_RLE8
1510#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001511 ) {
1512 printf("Error: compression type %ld not supported\n",
1513 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001514#ifdef CONFIG_VIDEO_BMP_GZIP
1515 if (dst)
1516 free(dst);
1517#endif
wdenke55402c2004-03-14 16:51:43 +00001518 return 1;
1519 }
1520
1521 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1522
Matthias Weisser53884182009-07-09 16:07:30 +02001523#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1524 if (x == BMP_ALIGN_CENTER)
1525 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1526 else if (x < 0)
1527 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1528
1529 if (y == BMP_ALIGN_CENTER)
1530 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1531 else if (y < 0)
1532 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1533#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1534
Matthias Weisser5e5ed762013-02-15 03:35:12 +00001535 /*
1536 * Just ignore elements which are completely beyond screen
1537 * dimensions.
1538 */
1539 if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
1540 return 0;
1541
wdenke55402c2004-03-14 16:51:43 +00001542 if ((x + width) > VIDEO_VISIBLE_COLS)
1543 width = VIDEO_VISIBLE_COLS - x;
1544 if ((y + height) > VIDEO_VISIBLE_ROWS)
1545 height = VIDEO_VISIBLE_ROWS - y;
1546
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001547 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenke55402c2004-03-14 16:51:43 +00001548 fb = (uchar *) (video_fb_address +
1549 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1550 x * VIDEO_PIXEL_SIZE);
1551
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001552#ifdef CONFIG_VIDEO_BMP_RLE8
1553 if (compression == BMP_BI_RLE8) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001554 return display_rle8_bitmap(bmp, x, y, width, height);
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001555 }
1556#endif
1557
Timur Tabi0fce9922010-08-23 16:58:00 -05001558 /* We handle only 4, 8, or 24 bpp bitmaps */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001559 switch (le16_to_cpu(bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001560 case 4:
1561 padded_line -= width / 2;
1562 ycount = height;
1563
1564 switch (VIDEO_DATA_FORMAT) {
1565 case GDF_32BIT_X888RGB:
1566 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001567 WATCHDOG_RESET();
Timur Tabi0fce9922010-08-23 16:58:00 -05001568 /*
1569 * Don't assume that 'width' is an
1570 * even number
1571 */
1572 for (xcount = 0; xcount < width; xcount++) {
1573 uchar idx;
1574
1575 if (xcount & 1) {
1576 idx = *bmap & 0xF;
1577 bmap++;
1578 } else
1579 idx = *bmap >> 4;
1580 cte = bmp->color_table[idx];
1581 FILL_32BIT_X888RGB(cte.red, cte.green,
1582 cte.blue);
1583 }
1584 bmap += padded_line;
1585 fb -= (VIDEO_VISIBLE_COLS + width) *
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001586 VIDEO_PIXEL_SIZE;
Timur Tabi0fce9922010-08-23 16:58:00 -05001587 }
1588 break;
1589 default:
1590 puts("4bpp bitmap unsupported with current "
1591 "video mode\n");
1592 break;
1593 }
1594 break;
1595
wdenke55402c2004-03-14 16:51:43 +00001596 case 8:
1597 padded_line -= width;
1598 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001599 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001600 for (xcount = 0; xcount < colors; ++xcount) {
1601 cte = bmp->color_table[xcount];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001602 video_set_lut(xcount, cte.red, cte.green,
1603 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001604 }
1605 }
1606 ycount = height;
1607 switch (VIDEO_DATA_FORMAT) {
1608 case GDF__8BIT_INDEX:
1609 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001610 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001611 xcount = width;
1612 while (xcount--) {
1613 *fb++ = *bmap++;
1614 }
1615 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001616 fb -= (VIDEO_VISIBLE_COLS + width) *
1617 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001618 }
1619 break;
1620 case GDF__8BIT_332RGB:
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_8BIT_332RGB(cte.red, cte.green,
1627 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001628 }
1629 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001630 fb -= (VIDEO_VISIBLE_COLS + width) *
1631 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001632 }
1633 break;
1634 case GDF_15BIT_555RGB:
1635 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001636#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1637 int xpos = x;
1638#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001639 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001640 xcount = width;
1641 while (xcount--) {
1642 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001643#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001644 fill_555rgb_pswap(fb, xpos++, cte.red,
1645 cte.green,
1646 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001647 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001648#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001649 FILL_15BIT_555RGB(cte.red, cte.green,
1650 cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001651#endif
wdenke55402c2004-03-14 16:51:43 +00001652 }
1653 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001654 fb -= (VIDEO_VISIBLE_COLS + width) *
1655 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001656 }
1657 break;
1658 case GDF_16BIT_565RGB:
1659 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001660 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001661 xcount = width;
1662 while (xcount--) {
1663 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001664 FILL_16BIT_565RGB(cte.red, cte.green,
1665 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001666 }
1667 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001668 fb -= (VIDEO_VISIBLE_COLS + width) *
1669 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001670 }
1671 break;
1672 case GDF_32BIT_X888RGB:
1673 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001674 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001675 xcount = width;
1676 while (xcount--) {
1677 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001678 FILL_32BIT_X888RGB(cte.red, cte.green,
1679 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001680 }
1681 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001682 fb -= (VIDEO_VISIBLE_COLS + width) *
1683 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001684 }
1685 break;
1686 case GDF_24BIT_888RGB:
1687 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001688 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001689 xcount = width;
1690 while (xcount--) {
1691 cte = bmp->color_table[*bmap++];
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001692 FILL_24BIT_888RGB(cte.red, cte.green,
1693 cte.blue);
wdenke55402c2004-03-14 16:51:43 +00001694 }
1695 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001696 fb -= (VIDEO_VISIBLE_COLS + width) *
1697 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001698 }
1699 break;
1700 }
1701 break;
1702 case 24:
1703 padded_line -= 3 * width;
1704 ycount = height;
1705 switch (VIDEO_DATA_FORMAT) {
1706 case GDF__8BIT_332RGB:
1707 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001708 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001709 xcount = width;
1710 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001711 FILL_8BIT_332RGB(bmap[2], bmap[1],
1712 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001713 bmap += 3;
1714 }
1715 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001716 fb -= (VIDEO_VISIBLE_COLS + width) *
1717 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001718 }
1719 break;
1720 case GDF_15BIT_555RGB:
1721 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001722#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1723 int xpos = x;
1724#endif
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001725 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001726 xcount = width;
1727 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001728#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001729 fill_555rgb_pswap(fb, xpos++, bmap[2],
1730 bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001731 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001732#else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001733 FILL_15BIT_555RGB(bmap[2], bmap[1],
1734 bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001735#endif
wdenke55402c2004-03-14 16:51:43 +00001736 bmap += 3;
1737 }
1738 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001739 fb -= (VIDEO_VISIBLE_COLS + width) *
1740 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001741 }
1742 break;
1743 case GDF_16BIT_565RGB:
1744 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001745 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001746 xcount = width;
1747 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001748 FILL_16BIT_565RGB(bmap[2], bmap[1],
1749 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001750 bmap += 3;
1751 }
1752 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001753 fb -= (VIDEO_VISIBLE_COLS + width) *
1754 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001755 }
1756 break;
1757 case GDF_32BIT_X888RGB:
1758 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001759 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001760 xcount = width;
1761 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001762 FILL_32BIT_X888RGB(bmap[2], bmap[1],
1763 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001764 bmap += 3;
1765 }
1766 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001767 fb -= (VIDEO_VISIBLE_COLS + width) *
1768 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001769 }
1770 break;
1771 case GDF_24BIT_888RGB:
1772 while (ycount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001773 WATCHDOG_RESET();
wdenke55402c2004-03-14 16:51:43 +00001774 xcount = width;
1775 while (xcount--) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001776 FILL_24BIT_888RGB(bmap[2], bmap[1],
1777 bmap[0]);
wdenke55402c2004-03-14 16:51:43 +00001778 bmap += 3;
1779 }
1780 bmap += padded_line;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001781 fb -= (VIDEO_VISIBLE_COLS + width) *
1782 VIDEO_PIXEL_SIZE;
wdenke55402c2004-03-14 16:51:43 +00001783 }
1784 break;
1785 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001786 printf("Error: 24 bits/pixel bitmap incompatible "
1787 "with current video mode\n");
wdenke55402c2004-03-14 16:51:43 +00001788 break;
1789 }
1790 break;
1791 default:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001792 printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1793 le16_to_cpu(bmp->header.bit_count));
wdenke55402c2004-03-14 16:51:43 +00001794 break;
1795 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001796
1797#ifdef CONFIG_VIDEO_BMP_GZIP
1798 if (dst) {
1799 free(dst);
1800 }
1801#endif
1802
Eric Nelson54142422013-05-06 14:27:28 +02001803 if (cfb_do_flush_cache)
1804 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
wdenke55402c2004-03-14 16:51:43 +00001805 return (0);
wdenkc6097192002-11-03 00:24:07 +00001806}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001807#endif
wdenkc6097192002-11-03 00:24:07 +00001808
wdenkc6097192002-11-03 00:24:07 +00001809
1810#ifdef CONFIG_VIDEO_LOGO
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001811static int video_logo_xpos;
1812static int video_logo_ypos;
1813
Bastian Ruppertd5932182012-09-13 22:29:02 +00001814static void plot_logo_or_black(void *screen, int width, int x, int y, \
1815 int black);
1816
1817static void logo_plot(void *screen, int width, int x, int y)
1818{
1819 plot_logo_or_black(screen, width, x, y, 0);
1820}
1821
1822static void logo_black(void)
1823{
1824 plot_logo_or_black(video_fb_address, \
1825 VIDEO_COLS, \
1826 video_logo_xpos, \
1827 video_logo_ypos, \
1828 1);
1829}
1830
1831static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1832{
1833 if (argc != 1)
1834 return cmd_usage(cmdtp);
1835
1836 logo_black();
1837 return 0;
1838}
1839
1840U_BOOT_CMD(
1841 clrlogo, 1, 0, do_clrlogo,
1842 "fill the boot logo area with black",
1843 " "
1844 );
1845
1846static void plot_logo_or_black(void *screen, int width, int x, int y, int black)
wdenkc6097192002-11-03 00:24:07 +00001847{
wdenk9dd2b882002-12-03 21:28:10 +00001848
wdenke55402c2004-03-14 16:51:43 +00001849 int xcount, i;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001850 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001851 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001852 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1853 unsigned char *source;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001854 unsigned char *dest;
1855
1856#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1857 if (x == BMP_ALIGN_CENTER)
1858 x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
1859 else if (x < 0)
1860 x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1);
1861
1862 if (y == BMP_ALIGN_CENTER)
1863 y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
1864 else if (y < 0)
1865 y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1);
1866#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1867
1868 dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001869
wdenk9dd2b882002-12-03 21:28:10 +00001870#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001871 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001872
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001873 /* Allocate temporary space for computing colormap */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001874 logo_red = malloc(BMP_LOGO_COLORS);
1875 logo_green = malloc(BMP_LOGO_COLORS);
1876 logo_blue = malloc(BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001877 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001878 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1879 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1880 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1881 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1882 }
wdenk9dd2b882002-12-03 21:28:10 +00001883#else
wdenke55402c2004-03-14 16:51:43 +00001884 source = linux_logo;
1885 logo_red = linux_logo_red;
1886 logo_green = linux_logo_green;
1887 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001888#endif
wdenk57b2d802003-06-27 21:31:46 +00001889
wdenke55402c2004-03-14 16:51:43 +00001890 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1891 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001892 video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
1893 logo_red[i], logo_green[i],
1894 logo_blue[i]);
wdenke55402c2004-03-14 16:51:43 +00001895 }
wdenk57b2d802003-06-27 21:31:46 +00001896 }
wdenkc6097192002-11-03 00:24:07 +00001897
wdenke55402c2004-03-14 16:51:43 +00001898 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001899#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1900 int xpos = x;
1901#endif
wdenke55402c2004-03-14 16:51:43 +00001902 xcount = VIDEO_LOGO_WIDTH;
1903 while (xcount--) {
Bastian Ruppertd5932182012-09-13 22:29:02 +00001904 if (black) {
1905 r = 0x00;
1906 g = 0x00;
1907 b = 0x00;
1908 } else {
1909 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1910 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1911 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
1912 }
wdenk57b2d802003-06-27 21:31:46 +00001913
wdenke55402c2004-03-14 16:51:43 +00001914 switch (VIDEO_DATA_FORMAT) {
1915 case GDF__8BIT_INDEX:
1916 *dest = *source;
1917 break;
1918 case GDF__8BIT_332RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001919 *dest = ((r >> 5) << 5) |
1920 ((g >> 5) << 2) |
1921 (b >> 6);
wdenke55402c2004-03-14 16:51:43 +00001922 break;
1923 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001924#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001925 fill_555rgb_pswap(dest, xpos++, r, g, b);
Andrew Dyer5601c612008-08-29 12:30:39 -05001926#else
wdenke55402c2004-03-14 16:51:43 +00001927 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001928 SWAP16((unsigned short) (
1929 ((r >> 3) << 10) |
1930 ((g >> 3) << 5) |
1931 (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001932#endif
wdenke55402c2004-03-14 16:51:43 +00001933 break;
1934 case GDF_16BIT_565RGB:
1935 *(unsigned short *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001936 SWAP16((unsigned short) (
1937 ((r >> 3) << 11) |
1938 ((g >> 2) << 5) |
1939 (b >> 3)));
wdenke55402c2004-03-14 16:51:43 +00001940 break;
1941 case GDF_32BIT_X888RGB:
1942 *(unsigned long *) dest =
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001943 SWAP32((unsigned long) (
1944 (r << 16) |
1945 (g << 8) |
1946 b));
wdenke55402c2004-03-14 16:51:43 +00001947 break;
1948 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001949#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001950 dest[0] = b;
1951 dest[1] = g;
1952 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001953#else
wdenke55402c2004-03-14 16:51:43 +00001954 dest[0] = r;
1955 dest[1] = g;
1956 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001957#endif
wdenke55402c2004-03-14 16:51:43 +00001958 break;
1959 }
1960 source++;
1961 dest += VIDEO_PIXEL_SIZE;
1962 }
1963 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001964 }
wdenk9dd2b882002-12-03 21:28:10 +00001965#ifdef CONFIG_VIDEO_BMP_LOGO
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001966 free(logo_red);
1967 free(logo_green);
1968 free(logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001969#endif
wdenkc6097192002-11-03 00:24:07 +00001970}
1971
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00001972static void *video_logo(void)
wdenkc6097192002-11-03 00:24:07 +00001973{
wdenke55402c2004-03-14 16:51:43 +00001974 char info[128];
Wolfgang Denkffbd9ee2011-11-04 15:55:20 +00001975 int space, len;
1976 __maybe_unused int y_off = 0;
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001977 __maybe_unused ulong addr;
1978 __maybe_unused char *s;
wdenke55402c2004-03-14 16:51:43 +00001979
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +02001980 splash_get_pos(&video_logo_xpos, &video_logo_ypos);
wdenke55402c2004-03-14 16:51:43 +00001981
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001982#ifdef CONFIG_SPLASH_SCREEN
1983 s = getenv("splashimage");
1984 if (s != NULL) {
Robert Winkler2a90ed02013-06-17 11:31:29 -07001985 splash_screen_prepare();
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001986 addr = simple_strtoul(s, NULL, 16);
1987
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001988 if (video_display_bitmap(addr,
1989 video_logo_xpos,
1990 video_logo_ypos) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001991 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001992 return ((void *) (video_fb_address));
1993 }
1994 }
1995#endif /* CONFIG_SPLASH_SCREEN */
1996
Bastian Rupperta13e81f2012-09-13 22:29:01 +00001997 logo_plot(video_fb_address, VIDEO_COLS,
1998 video_logo_xpos, video_logo_ypos);
1999
2000#ifdef CONFIG_SPLASH_SCREEN_ALIGN
2001 /*
2002 * when using splashpos for video_logo, skip any info
2003 * output on video console if the logo is not at 0,0
2004 */
2005 if (video_logo_xpos || video_logo_ypos) {
2006 /*
2007 * video_logo_height is used in text and cursor offset
2008 * calculations. Since the console is below the logo,
2009 * we need to adjust the logo height
2010 */
2011 if (video_logo_ypos == BMP_ALIGN_CENTER)
2012 video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \
2013 VIDEO_LOGO_HEIGHT) / 2);
2014 else if (video_logo_ypos > 0)
2015 video_logo_height += video_logo_ypos;
2016
2017 return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
2018 }
2019#endif
wdenkc6097192002-11-03 00:24:07 +00002020
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002021 sprintf(info, " %s", version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002022
2023 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
2024 len = strlen(info);
2025
2026 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002027 video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
2028 (uchar *) info, space);
2029 video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
2030 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
2031 (uchar *) info + space, len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002032 y_off = 1;
2033 } else
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002034 video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
wdenkc6097192002-11-03 00:24:07 +00002035
2036#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00002037 {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002038 int i, n =
2039 ((video_logo_height -
2040 VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002041
wdenke55402c2004-03-14 16:51:43 +00002042 for (i = 1; i < n; i++) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002043 video_get_info_str(i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002044 if (!*info)
2045 continue;
2046
2047 len = strlen(info);
2048 if (len > space) {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002049 video_drawchars(VIDEO_INFO_X,
2050 VIDEO_INFO_Y +
2051 (i + y_off) *
2052 VIDEO_FONT_HEIGHT,
2053 (uchar *) info, space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002054 y_off++;
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002055 video_drawchars(VIDEO_INFO_X +
2056 VIDEO_FONT_WIDTH,
2057 VIDEO_INFO_Y +
2058 (i + y_off) *
2059 VIDEO_FONT_HEIGHT,
2060 (uchar *) info + space,
2061 len - space);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002062 } else {
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002063 video_drawstring(VIDEO_INFO_X,
2064 VIDEO_INFO_Y +
2065 (i + y_off) *
2066 VIDEO_FONT_HEIGHT,
2067 (uchar *) info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02002068 }
wdenke55402c2004-03-14 16:51:43 +00002069 }
2070 }
wdenkc6097192002-11-03 00:24:07 +00002071#endif
2072
Matthias Weisser76d70862010-01-12 12:06:31 +01002073 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00002074}
2075#endif
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002076
2077static int cfb_fb_is_in_dram(void)
2078{
2079 bd_t *bd = gd->bd;
2080#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
2081defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
2082 ulong start, end;
2083 int i;
2084
2085 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
2086 start = bd->bi_dram[i].start;
2087 end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
2088 if ((ulong)video_fb_address >= start &&
2089 (ulong)video_fb_address < end)
2090 return 1;
2091 }
2092#else
2093 if ((ulong)video_fb_address >= bd->bi_memstart &&
2094 (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
2095 return 1;
2096#endif
2097 return 0;
2098}
wdenkc6097192002-11-03 00:24:07 +00002099
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002100static int video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002101{
wdenke55402c2004-03-14 16:51:43 +00002102 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00002103
Wolfgang Denka87b2a952011-07-30 12:48:09 +00002104 pGD = video_hw_init();
2105 if (pGD == NULL)
wdenke55402c2004-03-14 16:51:43 +00002106 return -1;
wdenkc6097192002-11-03 00:24:07 +00002107
wdenke55402c2004-03-14 16:51:43 +00002108 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00002109#ifdef CONFIG_VIDEO_HW_CURSOR
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002110 video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00002111#endif
2112
Anatolij Gustschindbad2b82012-06-05 09:19:18 +02002113 cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
2114
wdenke55402c2004-03-14 16:51:43 +00002115 /* Init drawing pats */
2116 switch (VIDEO_DATA_FORMAT) {
2117 case GDF__8BIT_INDEX:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002118 video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL,
2119 CONSOLE_FG_COL);
2120 video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL,
2121 CONSOLE_BG_COL);
wdenke55402c2004-03-14 16:51:43 +00002122 fgx = 0x01010101;
2123 bgx = 0x00000000;
2124 break;
2125 case GDF__8BIT_332RGB:
2126 color8 = ((CONSOLE_FG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002127 ((CONSOLE_FG_COL >> 3) & 0x1c) |
2128 CONSOLE_FG_COL >> 6);
2129 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2130 color8;
wdenke55402c2004-03-14 16:51:43 +00002131 color8 = ((CONSOLE_BG_COL & 0xe0) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002132 ((CONSOLE_BG_COL >> 3) & 0x1c) |
2133 CONSOLE_BG_COL >> 6);
2134 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
2135 color8;
wdenke55402c2004-03-14 16:51:43 +00002136 break;
2137 case GDF_15BIT_555RGB:
2138 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002139 ((CONSOLE_FG_COL >> 3) << 21) |
2140 ((CONSOLE_FG_COL >> 3) << 16) |
2141 ((CONSOLE_FG_COL >> 3) << 10) |
2142 ((CONSOLE_FG_COL >> 3) << 5) |
2143 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002144 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002145 ((CONSOLE_BG_COL >> 3) << 21) |
2146 ((CONSOLE_BG_COL >> 3) << 16) |
2147 ((CONSOLE_BG_COL >> 3) << 10) |
2148 ((CONSOLE_BG_COL >> 3) << 5) |
2149 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002150 break;
2151 case GDF_16BIT_565RGB:
2152 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002153 ((CONSOLE_FG_COL >> 2) << 21) |
2154 ((CONSOLE_FG_COL >> 3) << 16) |
2155 ((CONSOLE_FG_COL >> 3) << 11) |
2156 ((CONSOLE_FG_COL >> 2) << 5) |
2157 (CONSOLE_FG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002158 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002159 ((CONSOLE_BG_COL >> 2) << 21) |
2160 ((CONSOLE_BG_COL >> 3) << 16) |
2161 ((CONSOLE_BG_COL >> 3) << 11) |
2162 ((CONSOLE_BG_COL >> 2) << 5) |
2163 (CONSOLE_BG_COL >> 3));
wdenke55402c2004-03-14 16:51:43 +00002164 break;
2165 case GDF_32BIT_X888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002166 fgx = (CONSOLE_FG_COL << 16) |
2167 (CONSOLE_FG_COL << 8) |
2168 CONSOLE_FG_COL;
2169 bgx = (CONSOLE_BG_COL << 16) |
2170 (CONSOLE_BG_COL << 8) |
2171 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002172 break;
2173 case GDF_24BIT_888RGB:
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002174 fgx = (CONSOLE_FG_COL << 24) |
2175 (CONSOLE_FG_COL << 16) |
2176 (CONSOLE_FG_COL << 8) |
2177 CONSOLE_FG_COL;
2178 bgx = (CONSOLE_BG_COL << 24) |
2179 (CONSOLE_BG_COL << 16) |
2180 (CONSOLE_BG_COL << 8) |
2181 CONSOLE_BG_COL;
wdenke55402c2004-03-14 16:51:43 +00002182 break;
2183 }
2184 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00002185
2186#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00002187 /* Plot the logo and get start point of console */
Wolfgang Denk46717712011-07-29 09:55:28 +00002188 debug("Video: Drawing the logo ...\n");
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002189 video_console_address = video_logo();
wdenkc6097192002-11-03 00:24:07 +00002190#else
wdenke55402c2004-03-14 16:51:43 +00002191 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00002192#endif
2193
wdenke55402c2004-03-14 16:51:43 +00002194 /* Initialize the console */
2195 console_col = 0;
2196 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00002197
Eric Nelson54142422013-05-06 14:27:28 +02002198 if (cfb_do_flush_cache)
2199 flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
2200
wdenke55402c2004-03-14 16:51:43 +00002201 return 0;
wdenkc6097192002-11-03 00:24:07 +00002202}
2203
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002204/*
2205 * Implement a weak default function for boards that optionally
2206 * need to skip the video initialization.
2207 */
2208int __board_video_skip(void)
2209{
2210 /* As default, don't skip test */
2211 return 0;
2212}
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002213
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002214int board_video_skip(void)
2215 __attribute__ ((weak, alias("__board_video_skip")));
2216
2217int drv_video_init(void)
wdenkc6097192002-11-03 00:24:07 +00002218{
wdenke55402c2004-03-14 16:51:43 +00002219 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02002220 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00002221
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02002222 /* Check if video initialization should be skipped */
2223 if (board_video_skip())
2224 return 0;
2225
wdenk7dd13292004-07-11 20:04:51 +00002226 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002227 skip_dev_init = (video_init() == -1);
wdenkc6097192002-11-03 00:24:07 +00002228
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002229#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
Wolfgang Denk46717712011-07-29 09:55:28 +00002230 debug("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002231 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
2232#endif
wdenkc6097192002-11-03 00:24:07 +00002233
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002234 if (skip_dev_init)
2235 return 0;
wdenkc6097192002-11-03 00:24:07 +00002236
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002237 /* Init vga device */
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002238 memset(&console_dev, 0, sizeof(console_dev));
2239 strcpy(console_dev.name, "vga");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002240 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
2241 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
2242 console_dev.putc = video_putc; /* 'putc' function */
2243 console_dev.puts = video_puts; /* 'puts' function */
2244 console_dev.tstc = NULL; /* 'tstc' function */
2245 console_dev.getc = NULL; /* 'getc' function */
2246
2247#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
2248 /* Also init console device */
2249 console_dev.flags |= DEV_FLAGS_INPUT;
2250 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
2251 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00002252#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002253
Wolfgang Denk0b4b56e2011-07-29 09:55:27 +00002254 if (stdio_register(&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02002255 return 0;
2256
2257 /* Return success */
2258 return 1;
wdenkc6097192002-11-03 00:24:07 +00002259}
Stefan Reinauer7870da32012-09-28 15:11:12 +00002260
2261void video_position_cursor(unsigned col, unsigned row)
2262{
2263 console_col = min(col, CONSOLE_COLS - 1);
2264 console_row = min(row, CONSOLE_ROWS - 1);
2265}
2266
2267int video_get_pixel_width(void)
2268{
2269 return VIDEO_VISIBLE_COLS;
2270}
2271
2272int video_get_pixel_height(void)
2273{
2274 return VIDEO_VISIBLE_ROWS;
2275}
2276
2277int video_get_screen_rows(void)
2278{
2279 return CONSOLE_ROWS;
2280}
2281
2282int video_get_screen_columns(void)
2283{
2284 return CONSOLE_COLS;
2285}
2286
2287void video_clear(void)
2288{
Duncan Laurie33778ea2012-11-03 11:41:40 +00002289 if (!video_fb_address)
2290 return;
Stefan Reinauer7870da32012-09-28 15:11:12 +00002291#ifdef VIDEO_HW_RECTFILL
2292 video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
2293 0, /* dest pos x */
2294 0, /* dest pos y */
2295 VIDEO_VISIBLE_COLS, /* frame width */
2296 VIDEO_VISIBLE_ROWS, /* frame height */
2297 bgx /* fill color */
2298 );
2299#else
2300 memsetl(video_fb_address,
2301 (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
2302#endif
2303}