blob: dd849c2dc13207bae02c8a6479bfabe8085fe8f6 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenke55402c2004-03-14 16:51:43 +000015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkc6097192002-11-03 00:24:07 +000016 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * cfb_console.c
26 *
27 * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
28 *
29 * At the moment only the 8x16 font is tested and the font fore- and
30 * background color is limited to black/white/gray colors. The Linux
31 * logo can be placed in the upper left corner and additional board
32 * information strings (that normaly goes to serial port) can be drawed.
33 *
34 * The console driver can use the standard PC keyboard interface (i8042)
35 * for character input. Character output goes to a memory mapped video
36 * framebuffer with little or big-endian organisation.
37 * With environment setting 'console=serial' the console i/o can be
38 * forced to serial port.
39
40 The driver uses graphic specific defines/parameters/functions:
41
42 (for SMI LynxE graphic chip)
43
44 CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
wdenke55402c2004-03-14 16:51:43 +000045 VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
46 VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
47 VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
wdenkc6097192002-11-03 00:24:07 +000048
49 Console Parameters are set by graphic drivers global struct:
50
wdenke55402c2004-03-14 16:51:43 +000051 VIDEO_VISIBLE_COLS - x resolution
52 VIDEO_VISIBLE_ROWS - y resolution
53 VIDEO_PIXEL_SIZE - storage size in byte per pixel
54 VIDEO_DATA_FORMAT - graphical data format GDF
55 VIDEO_FB_ADRS - start of video memory
wdenkc6097192002-11-03 00:24:07 +000056
wdenke55402c2004-03-14 16:51:43 +000057 CONFIG_I8042_KBD - AT Keyboard driver for i8042
58 VIDEO_KBD_INIT_FCT - init function for keyboard
59 VIDEO_TSTC_FCT - keyboard_tstc function
60 VIDEO_GETC_FCT - keyboard_getc function
wdenkc6097192002-11-03 00:24:07 +000061
wdenke55402c2004-03-14 16:51:43 +000062 CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with delay
wdenk57b2d802003-06-27 21:31:46 +000063 loop in VIDEO_TSTC_FCT (i8042)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020064 CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
wdenke55402c2004-03-14 16:51:43 +000065 CONFIG_CONSOLE_TIME - display time/date in upper right corner,
Jon Loeliger30c2f242007-07-10 11:13:21 -050066 needs CONFIG_CMD_DATE and CONFIG_CONSOLE_CURSOR
wdenke55402c2004-03-14 16:51:43 +000067 CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner
68 CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
wdenkc6097192002-11-03 00:24:07 +000069 CONFIG_CONSOLE_EXTRA_INFO - display additional board information strings
wdenk57b2d802003-06-27 21:31:46 +000070 that normaly goes to serial port. This define
71 requires a board specific function:
72 video_drawstring (VIDEO_INFO_X,
73 VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
74 info);
75 that fills a info buffer at i=row.
76 s.a: board/eltec/bab7xx.
wdenkc6097192002-11-03 00:24:07 +000077CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be initialised
wdenk57b2d802003-06-27 21:31:46 +000078 as an output only device. The Keyboard driver
79 will not be set-up. This may be used, if you
80 have none or more than one Keyboard devices
81 (USB Keyboard, AT Keyboard).
wdenkc6097192002-11-03 00:24:07 +000082
wdenke55402c2004-03-14 16:51:43 +000083CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last character. No
wdenk57b2d802003-06-27 21:31:46 +000084 blinking is provided. Uses the macros CURSOR_SET
85 and CURSOR_OFF.
wdenke55402c2004-03-14 16:51:43 +000086CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability of the
wdenk57b2d802003-06-27 21:31:46 +000087 graphic chip. Uses the macro CURSOR_SET.
88 ATTENTION: If booting an OS, the display driver
89 must disable the hardware register of the graphic
90 chip. Otherwise a blinking field is displayed
wdenkc6097192002-11-03 00:24:07 +000091*/
92
93#include <common.h>
94
wdenk9dd2b882002-12-03 21:28:10 +000095#include <malloc.h>
96
wdenkc6097192002-11-03 00:24:07 +000097/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +000098/* Console device defines with SMI graphic */
99/* Any other graphic must change this section */
wdenkc6097192002-11-03 00:24:07 +0000100/*****************************************************************************/
101
wdenke55402c2004-03-14 16:51:43 +0000102#ifdef CONFIG_VIDEO_SMI_LYNXEM
wdenkc6097192002-11-03 00:24:07 +0000103
104#define VIDEO_FB_LITTLE_ENDIAN
105#define VIDEO_HW_RECTFILL
106#define VIDEO_HW_BITBLT
107#endif
108
109/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000110/* Defines for the CT69000 driver */
wdenkc6097192002-11-03 00:24:07 +0000111/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000112#ifdef CONFIG_VIDEO_CT69000
wdenkc6097192002-11-03 00:24:07 +0000113
114#define VIDEO_FB_LITTLE_ENDIAN
115#define VIDEO_HW_RECTFILL
116#define VIDEO_HW_BITBLT
117#endif
118
119/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000120/* Defines for the SED13806 driver */
wdenk9dd2b882002-12-03 21:28:10 +0000121/*****************************************************************************/
122#ifdef CONFIG_VIDEO_SED13806
123
wdenkda54bc92004-08-04 21:56:49 +0000124#ifndef CONFIG_TOTAL5200
wdenk9dd2b882002-12-03 21:28:10 +0000125#define VIDEO_FB_LITTLE_ENDIAN
wdenkda54bc92004-08-04 21:56:49 +0000126#endif
wdenk9dd2b882002-12-03 21:28:10 +0000127#define VIDEO_HW_RECTFILL
128#define VIDEO_HW_BITBLT
129#endif
130
131/*****************************************************************************/
Stefan Roesed9d97742005-09-22 09:04:17 +0200132/* Defines for the SED13806 driver */
133/*****************************************************************************/
134#ifdef CONFIG_VIDEO_SM501
135
136#ifdef CONFIG_HH405
137#define VIDEO_FB_LITTLE_ENDIAN
138#endif
139#endif
140
141/*****************************************************************************/
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100142/* Defines for the MB862xx driver */
143/*****************************************************************************/
144#ifdef CONFIG_VIDEO_MB862xx
145
146#ifdef CONFIG_VIDEO_CORALP
147#define VIDEO_FB_LITTLE_ENDIAN
148#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200149#ifdef CONFIG_VIDEO_MB862xx_ACCEL
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100150#define VIDEO_HW_RECTFILL
151#define VIDEO_HW_BITBLT
152#endif
Anatolij Gustschine7e44a02009-10-23 12:03:14 +0200153#endif
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100154
155/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000156/* Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc */
wdenkc6097192002-11-03 00:24:07 +0000157/*****************************************************************************/
158#include <video_fb.h>
159
160/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000161/* some Macros */
wdenkc6097192002-11-03 00:24:07 +0000162/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000163#define VIDEO_VISIBLE_COLS (pGD->winSizeX)
164#define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
165#define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
166#define VIDEO_DATA_FORMAT (pGD->gdfIndex)
167#define VIDEO_FB_ADRS (pGD->frameAdrs)
wdenkc6097192002-11-03 00:24:07 +0000168
169/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000170/* Console device defines with i8042 keyboard controller */
171/* Any other keyboard controller must change this section */
wdenkc6097192002-11-03 00:24:07 +0000172/*****************************************************************************/
173
wdenke55402c2004-03-14 16:51:43 +0000174#ifdef CONFIG_I8042_KBD
wdenkc6097192002-11-03 00:24:07 +0000175#include <i8042.h>
176
wdenke55402c2004-03-14 16:51:43 +0000177#define VIDEO_KBD_INIT_FCT i8042_kbd_init()
178#define VIDEO_TSTC_FCT i8042_tstc
179#define VIDEO_GETC_FCT i8042_getc
wdenkc6097192002-11-03 00:24:07 +0000180#endif
181
182/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000183/* Console device */
wdenkc6097192002-11-03 00:24:07 +0000184/*****************************************************************************/
185
186#include <version.h>
187#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200188#include <stdio_dev.h>
wdenkc6097192002-11-03 00:24:07 +0000189#include <video_font.h>
wdenkc6097192002-11-03 00:24:07 +0000190
Jon Loeliger30c2f242007-07-10 11:13:21 -0500191#if defined(CONFIG_CMD_DATE)
192#include <rtc.h>
wdenkc6097192002-11-03 00:24:07 +0000193#endif
194
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500195#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000196#include <watchdog.h>
197#include <bmp_layout.h>
Matthias Weisser53884182009-07-09 16:07:30 +0200198
199#ifdef CONFIG_SPLASH_SCREEN_ALIGN
200#define BMP_ALIGN_CENTER 0x7FFF
201#endif
202
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500203#endif
wdenke55402c2004-03-14 16:51:43 +0000204
wdenkc6097192002-11-03 00:24:07 +0000205/*****************************************************************************/
wdenke55402c2004-03-14 16:51:43 +0000206/* Cursor definition: */
Marcel Ziswileraea68562007-12-30 03:30:46 +0100207/* CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c) */
208/* to let the cursor blink. Uses the macros */
209/* CURSOR_OFF and CURSOR_ON. */
wdenke55402c2004-03-14 16:51:43 +0000210/* CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No */
211/* blinking is provided. Uses the macros CURSOR_SET */
212/* and CURSOR_OFF. */
213/* CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the */
214/* graphic chip. Uses the macro CURSOR_SET. */
215/* ATTENTION: If booting an OS, the display driver */
216/* must disable the hardware register of the graphic */
217/* chip. Otherwise a blinking field is displayed */
wdenkc6097192002-11-03 00:24:07 +0000218/*****************************************************************************/
219#if !defined(CONFIG_CONSOLE_CURSOR) && \
220 !defined(CONFIG_VIDEO_SW_CURSOR) && \
221 !defined(CONFIG_VIDEO_HW_CURSOR)
222/* no Cursor defined */
223#define CURSOR_ON
224#define CURSOR_OFF
225#define CURSOR_SET
226#endif
227
wdenke55402c2004-03-14 16:51:43 +0000228#ifdef CONFIG_CONSOLE_CURSOR
229#ifdef CURSOR_ON
230#error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000231#endif
wdenke55402c2004-03-14 16:51:43 +0000232void console_cursor (int state);
Timur Tabibe0c74e2010-08-27 15:45:47 -0500233#define CURSOR_ON console_cursor(1)
234#define CURSOR_OFF console_cursor(0)
wdenkc6097192002-11-03 00:24:07 +0000235#define CURSOR_SET
236#ifndef CONFIG_I8042_KBD
Marcel Ziswileraea68562007-12-30 03:30:46 +0100237#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
wdenkc6097192002-11-03 00:24:07 +0000238#endif
239#else
wdenke55402c2004-03-14 16:51:43 +0000240#ifdef CONFIG_CONSOLE_TIME
241#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
wdenkc6097192002-11-03 00:24:07 +0000242#endif
243#endif /* CONFIG_CONSOLE_CURSOR */
244
wdenke55402c2004-03-14 16:51:43 +0000245#ifdef CONFIG_VIDEO_SW_CURSOR
246#ifdef CURSOR_ON
247#error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000248#endif
249#define CURSOR_ON
250#define CURSOR_OFF video_putchar(console_col * VIDEO_FONT_WIDTH,\
Timur Tabibe0c74e2010-08-27 15:45:47 -0500251 console_row * VIDEO_FONT_HEIGHT, ' ')
252#define CURSOR_SET video_set_cursor()
wdenkc6097192002-11-03 00:24:07 +0000253#endif /* CONFIG_VIDEO_SW_CURSOR */
254
255
256#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +0000257#ifdef CURSOR_ON
258#error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
wdenkc6097192002-11-03 00:24:07 +0000259#endif
260#define CURSOR_ON
261#define CURSOR_OFF
262#define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
Timur Tabibe0c74e2010-08-27 15:45:47 -0500263 (console_row * VIDEO_FONT_HEIGHT) + video_logo_height)
wdenke55402c2004-03-14 16:51:43 +0000264#endif /* CONFIG_VIDEO_HW_CURSOR */
wdenkc6097192002-11-03 00:24:07 +0000265
wdenke55402c2004-03-14 16:51:43 +0000266#ifdef CONFIG_VIDEO_LOGO
267#ifdef CONFIG_VIDEO_BMP_LOGO
wdenk9dd2b882002-12-03 21:28:10 +0000268#include <bmp_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000269#define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
270#define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
271#define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
272#define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
wdenk9dd2b882002-12-03 21:28:10 +0000273
wdenke55402c2004-03-14 16:51:43 +0000274#else /* CONFIG_VIDEO_BMP_LOGO */
275#define LINUX_LOGO_WIDTH 80
276#define LINUX_LOGO_HEIGHT 80
277#define LINUX_LOGO_COLORS 214
278#define LINUX_LOGO_LUT_OFFSET 0x20
wdenkc6097192002-11-03 00:24:07 +0000279#define __initdata
280#include <linux_logo.h>
wdenke55402c2004-03-14 16:51:43 +0000281#define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
282#define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
283#define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
284#define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
285#endif /* CONFIG_VIDEO_BMP_LOGO */
286#define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
287#define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
288#else /* CONFIG_VIDEO_LOGO */
289#define VIDEO_LOGO_WIDTH 0
290#define VIDEO_LOGO_HEIGHT 0
291#endif /* CONFIG_VIDEO_LOGO */
wdenkc6097192002-11-03 00:24:07 +0000292
wdenke55402c2004-03-14 16:51:43 +0000293#define VIDEO_COLS VIDEO_VISIBLE_COLS
294#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
295#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
296#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
297#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
298#define VIDEO_BURST_LEN (VIDEO_COLS/8)
wdenkc6097192002-11-03 00:24:07 +0000299
wdenke55402c2004-03-14 16:51:43 +0000300#ifdef CONFIG_VIDEO_LOGO
Matthias Weisser76d70862010-01-12 12:06:31 +0100301#define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000302#else
wdenke55402c2004-03-14 16:51:43 +0000303#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
wdenkc6097192002-11-03 00:24:07 +0000304#endif
305
wdenke55402c2004-03-14 16:51:43 +0000306#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
307#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
308#define CONSOLE_ROW_FIRST (video_console_address)
309#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
310#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
311#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
312#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenkc6097192002-11-03 00:24:07 +0000313
314/* Macros */
wdenke55402c2004-03-14 16:51:43 +0000315#ifdef VIDEO_FB_LITTLE_ENDIAN
316#define SWAP16(x) ((((x) & 0x00ff) << 8) | ( (x) >> 8))
317#define SWAP32(x) ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8)|\
wdenk57b2d802003-06-27 21:31:46 +0000318 (((x) & 0x00ff0000) >> 8) | (((x) & 0xff000000) >> 24) )
wdenke55402c2004-03-14 16:51:43 +0000319#define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | (((x) & 0x0000ff00) >> 8)|\
wdenk57b2d802003-06-27 21:31:46 +0000320 (((x) & 0x00ff0000) << 8) | (((x) & 0xff000000) >> 8) )
wdenkc6097192002-11-03 00:24:07 +0000321#else
wdenke55402c2004-03-14 16:51:43 +0000322#define SWAP16(x) (x)
323#define SWAP32(x) (x)
Wolfgang Grandeggere1b05842009-10-23 12:03:15 +0200324#if defined(VIDEO_FB_16BPP_WORD_SWAP)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100325#define SHORTSWAP32(x) ( ((x) >> 16) | ((x) << 16) )
Andrew Dyer5601c612008-08-29 12:30:39 -0500326#else
327#define SHORTSWAP32(x) (x)
Anatolij Gustschin3545f592008-01-11 14:30:01 +0100328#endif
wdenkc6097192002-11-03 00:24:07 +0000329#endif
330
331#if defined(DEBUG) || defined(DEBUG_CFB_CONSOLE)
wdenke55402c2004-03-14 16:51:43 +0000332#define PRINTD(x) printf(x)
wdenkc6097192002-11-03 00:24:07 +0000333#else
334#define PRINTD(x)
335#endif
336
337
338#ifdef CONFIG_CONSOLE_EXTRA_INFO
339extern void video_get_info_str ( /* setup a board string: type, speed, etc. */
wdenke55402c2004-03-14 16:51:43 +0000340 int line_number, /* location to place info string beside logo */
341 char *info /* buffer for info string */
wdenkc6097192002-11-03 00:24:07 +0000342 );
343
344#endif
345
346/* Locals */
347static GraphicDevice *pGD; /* Pointer to Graphic array */
348
wdenke55402c2004-03-14 16:51:43 +0000349static void *video_fb_address; /* frame buffer address */
350static void *video_console_address; /* console buffer start address */
wdenkc6097192002-11-03 00:24:07 +0000351
Matthias Weisser76d70862010-01-12 12:06:31 +0100352static int video_logo_height = VIDEO_LOGO_HEIGHT;
353
wdenkc6097192002-11-03 00:24:07 +0000354static int console_col = 0; /* cursor col */
355static int console_row = 0; /* cursor row */
356
357static u32 eorx, fgx, bgx; /* color pats */
358
359static const int video_font_draw_table8[] = {
wdenk57b2d802003-06-27 21:31:46 +0000360 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
361 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
362 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
363 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff };
wdenkc6097192002-11-03 00:24:07 +0000364
365static const int video_font_draw_table15[] = {
wdenk57b2d802003-06-27 21:31:46 +0000366 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff };
wdenkc6097192002-11-03 00:24:07 +0000367
368static const int video_font_draw_table16[] = {
wdenk57b2d802003-06-27 21:31:46 +0000369 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
wdenkc6097192002-11-03 00:24:07 +0000370
371static const int video_font_draw_table24[16][3] = {
wdenk57b2d802003-06-27 21:31:46 +0000372 { 0x00000000, 0x00000000, 0x00000000 },
373 { 0x00000000, 0x00000000, 0x00ffffff },
374 { 0x00000000, 0x0000ffff, 0xff000000 },
375 { 0x00000000, 0x0000ffff, 0xffffffff },
376 { 0x000000ff, 0xffff0000, 0x00000000 },
377 { 0x000000ff, 0xffff0000, 0x00ffffff },
378 { 0x000000ff, 0xffffffff, 0xff000000 },
379 { 0x000000ff, 0xffffffff, 0xffffffff },
380 { 0xffffff00, 0x00000000, 0x00000000 },
381 { 0xffffff00, 0x00000000, 0x00ffffff },
382 { 0xffffff00, 0x0000ffff, 0xff000000 },
383 { 0xffffff00, 0x0000ffff, 0xffffffff },
384 { 0xffffffff, 0xffff0000, 0x00000000 },
385 { 0xffffffff, 0xffff0000, 0x00ffffff },
386 { 0xffffffff, 0xffffffff, 0xff000000 },
387 { 0xffffffff, 0xffffffff, 0xffffffff } };
wdenkc6097192002-11-03 00:24:07 +0000388
389static const int video_font_draw_table32[16][4] = {
wdenk57b2d802003-06-27 21:31:46 +0000390 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
391 { 0x00000000, 0x00000000, 0x00000000, 0x00ffffff },
392 { 0x00000000, 0x00000000, 0x00ffffff, 0x00000000 },
393 { 0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff },
394 { 0x00000000, 0x00ffffff, 0x00000000, 0x00000000 },
395 { 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff },
396 { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000 },
397 { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff },
398 { 0x00ffffff, 0x00000000, 0x00000000, 0x00000000 },
399 { 0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff },
400 { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000 },
401 { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff },
402 { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000 },
403 { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff },
404 { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000 },
405 { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff } };
wdenkc6097192002-11-03 00:24:07 +0000406
407
408/******************************************************************************/
409
wdenkc6097192002-11-03 00:24:07 +0000410static void video_drawchars (int xx, int yy, unsigned char *s, int count)
411{
wdenke55402c2004-03-14 16:51:43 +0000412 u8 *cdat, *dest, *dest0;
413 int rows, offset, c;
wdenkc6097192002-11-03 00:24:07 +0000414
wdenke55402c2004-03-14 16:51:43 +0000415 offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
416 dest0 = video_fb_address + offset;
wdenkc6097192002-11-03 00:24:07 +0000417
wdenke55402c2004-03-14 16:51:43 +0000418 switch (VIDEO_DATA_FORMAT) {
419 case GDF__8BIT_INDEX:
420 case GDF__8BIT_332RGB:
421 while (count--) {
422 c = *s;
423 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
424 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
425 rows--;
426 dest += VIDEO_LINE_LEN) {
427 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000428
wdenke55402c2004-03-14 16:51:43 +0000429 ((u32 *) dest)[0] = (video_font_draw_table8[bits >> 4] & eorx) ^ bgx;
430 ((u32 *) dest)[1] = (video_font_draw_table8[bits & 15] & eorx) ^ bgx;
431 }
432 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
433 s++;
434 }
435 break;
wdenkc6097192002-11-03 00:24:07 +0000436
wdenke55402c2004-03-14 16:51:43 +0000437 case GDF_15BIT_555RGB:
438 while (count--) {
439 c = *s;
440 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
441 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
442 rows--;
443 dest += VIDEO_LINE_LEN) {
444 u8 bits = *cdat++;
wdenkc6097192002-11-03 00:24:07 +0000445
wdenke55402c2004-03-14 16:51:43 +0000446 ((u32 *) dest)[0] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 6] & eorx) ^ bgx);
447 ((u32 *) dest)[1] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 4 & 3] & eorx) ^ bgx);
448 ((u32 *) dest)[2] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 2 & 3] & eorx) ^ bgx);
449 ((u32 *) dest)[3] = SHORTSWAP32 ((video_font_draw_table15 [bits & 3] & eorx) ^ bgx);
450 }
451 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
452 s++;
453 }
454 break;
wdenkc6097192002-11-03 00:24:07 +0000455
wdenke55402c2004-03-14 16:51:43 +0000456 case GDF_16BIT_565RGB:
457 while (count--) {
458 c = *s;
459 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
460 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
461 rows--;
462 dest += VIDEO_LINE_LEN) {
463 u8 bits = *cdat++;
464
465 ((u32 *) dest)[0] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 6] & eorx) ^ bgx);
466 ((u32 *) dest)[1] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 4 & 3] & eorx) ^ bgx);
467 ((u32 *) dest)[2] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 2 & 3] & eorx) ^ bgx);
468 ((u32 *) dest)[3] = SHORTSWAP32 ((video_font_draw_table16 [bits & 3] & eorx) ^ bgx);
469 }
470 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
471 s++;
472 }
473 break;
474
475 case GDF_32BIT_X888RGB:
476 while (count--) {
477 c = *s;
478 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
479 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
480 rows--;
481 dest += VIDEO_LINE_LEN) {
482 u8 bits = *cdat++;
483
484 ((u32 *) dest)[0] = SWAP32 ((video_font_draw_table32 [bits >> 4][0] & eorx) ^ bgx);
485 ((u32 *) dest)[1] = SWAP32 ((video_font_draw_table32 [bits >> 4][1] & eorx) ^ bgx);
486 ((u32 *) dest)[2] = SWAP32 ((video_font_draw_table32 [bits >> 4][2] & eorx) ^ bgx);
487 ((u32 *) dest)[3] = SWAP32 ((video_font_draw_table32 [bits >> 4][3] & eorx) ^ bgx);
488 ((u32 *) dest)[4] = SWAP32 ((video_font_draw_table32 [bits & 15][0] & eorx) ^ bgx);
489 ((u32 *) dest)[5] = SWAP32 ((video_font_draw_table32 [bits & 15][1] & eorx) ^ bgx);
490 ((u32 *) dest)[6] = SWAP32 ((video_font_draw_table32 [bits & 15][2] & eorx) ^ bgx);
491 ((u32 *) dest)[7] = SWAP32 ((video_font_draw_table32 [bits & 15][3] & eorx) ^ bgx);
492 }
493 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
494 s++;
495 }
496 break;
497
498 case GDF_24BIT_888RGB:
499 while (count--) {
500 c = *s;
501 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
502 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
503 rows--;
504 dest += VIDEO_LINE_LEN) {
505 u8 bits = *cdat++;
506
507 ((u32 *) dest)[0] = (video_font_draw_table24[bits >> 4][0] & eorx) ^ bgx;
508 ((u32 *) dest)[1] = (video_font_draw_table24[bits >> 4][1] & eorx) ^ bgx;
509 ((u32 *) dest)[2] = (video_font_draw_table24[bits >> 4][2] & eorx) ^ bgx;
510 ((u32 *) dest)[3] = (video_font_draw_table24[bits & 15][0] & eorx) ^ bgx;
511 ((u32 *) dest)[4] = (video_font_draw_table24[bits & 15][1] & eorx) ^ bgx;
512 ((u32 *) dest)[5] = (video_font_draw_table24[bits & 15][2] & eorx) ^ bgx;
513 }
514 dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
515 s++;
516 }
517 break;
wdenk57b2d802003-06-27 21:31:46 +0000518 }
wdenkc6097192002-11-03 00:24:07 +0000519}
520
521/*****************************************************************************/
522
wdenke55402c2004-03-14 16:51:43 +0000523static inline void video_drawstring (int xx, int yy, unsigned char *s)
wdenkc6097192002-11-03 00:24:07 +0000524{
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200525 video_drawchars (xx, yy, s, strlen ((char *)s));
wdenkc6097192002-11-03 00:24:07 +0000526}
527
528/*****************************************************************************/
529
wdenke55402c2004-03-14 16:51:43 +0000530static void video_putchar (int xx, int yy, unsigned char c)
wdenkc6097192002-11-03 00:24:07 +0000531{
Matthias Weisser76d70862010-01-12 12:06:31 +0100532 video_drawchars (xx, yy + video_logo_height, &c, 1);
wdenkc6097192002-11-03 00:24:07 +0000533}
534
535/*****************************************************************************/
536#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
wdenke55402c2004-03-14 16:51:43 +0000537static void video_set_cursor (void)
wdenkc6097192002-11-03 00:24:07 +0000538{
wdenke55402c2004-03-14 16:51:43 +0000539 /* swap drawing colors */
540 eorx = fgx;
541 fgx = bgx;
542 bgx = eorx;
543 eorx = fgx ^ bgx;
544 /* draw cursor */
545 video_putchar (console_col * VIDEO_FONT_WIDTH,
546 console_row * VIDEO_FONT_HEIGHT,
547 ' ');
548 /* restore drawing colors */
549 eorx = fgx;
550 fgx = bgx;
551 bgx = eorx;
552 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +0000553}
554#endif
555/*****************************************************************************/
556#ifdef CONFIG_CONSOLE_CURSOR
557void console_cursor (int state)
558{
wdenke55402c2004-03-14 16:51:43 +0000559 static int last_state = 0;
560
wdenkc6097192002-11-03 00:24:07 +0000561#ifdef CONFIG_CONSOLE_TIME
wdenke55402c2004-03-14 16:51:43 +0000562 struct rtc_time tm;
563 char info[16];
wdenkc6097192002-11-03 00:24:07 +0000564
wdenke55402c2004-03-14 16:51:43 +0000565 /* time update only if cursor is on (faster scroll) */
566 if (state) {
567 rtc_get (&tm);
wdenkc6097192002-11-03 00:24:07 +0000568
wdenke55402c2004-03-14 16:51:43 +0000569 sprintf (info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
570 tm.tm_sec);
571 video_drawstring (VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200572 VIDEO_INFO_Y, (uchar *)info);
wdenkc6097192002-11-03 00:24:07 +0000573
wdenke55402c2004-03-14 16:51:43 +0000574 sprintf (info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
575 tm.tm_year);
576 video_drawstring (VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200577 VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT, (uchar *)info);
wdenke55402c2004-03-14 16:51:43 +0000578 }
wdenkc6097192002-11-03 00:24:07 +0000579#endif
580
wdenke55402c2004-03-14 16:51:43 +0000581 if (state && (last_state != state)) {
582 video_set_cursor ();
583 }
wdenkc6097192002-11-03 00:24:07 +0000584
wdenke55402c2004-03-14 16:51:43 +0000585 if (!state && (last_state != state)) {
586 /* clear cursor */
587 video_putchar (console_col * VIDEO_FONT_WIDTH,
588 console_row * VIDEO_FONT_HEIGHT,
589 ' ');
590 }
wdenkc6097192002-11-03 00:24:07 +0000591
wdenke55402c2004-03-14 16:51:43 +0000592 last_state = state;
wdenkc6097192002-11-03 00:24:07 +0000593}
594#endif
595
596/*****************************************************************************/
597
598#ifndef VIDEO_HW_RECTFILL
599static void memsetl (int *p, int c, int v)
600{
wdenke55402c2004-03-14 16:51:43 +0000601 while (c--)
602 *(p++) = v;
wdenkc6097192002-11-03 00:24:07 +0000603}
604#endif
605
606/*****************************************************************************/
607
608#ifndef VIDEO_HW_BITBLT
609static void memcpyl (int *d, int *s, int c)
610{
wdenke55402c2004-03-14 16:51:43 +0000611 while (c--)
612 *(d++) = *(s++);
wdenkc6097192002-11-03 00:24:07 +0000613}
614#endif
615
616/*****************************************************************************/
617
618static void console_scrollup (void)
619{
wdenke55402c2004-03-14 16:51:43 +0000620 /* copy up rows ignoring the first one */
wdenkc6097192002-11-03 00:24:07 +0000621
622#ifdef VIDEO_HW_BITBLT
wdenke55402c2004-03-14 16:51:43 +0000623 video_hw_bitblt (VIDEO_PIXEL_SIZE, /* bytes per pixel */
624 0, /* source pos x */
Matthias Weisser76d70862010-01-12 12:06:31 +0100625 video_logo_height + VIDEO_FONT_HEIGHT, /* source pos y */
wdenke55402c2004-03-14 16:51:43 +0000626 0, /* dest pos x */
Matthias Weisser76d70862010-01-12 12:06:31 +0100627 video_logo_height, /* dest pos y */
wdenke55402c2004-03-14 16:51:43 +0000628 VIDEO_VISIBLE_COLS, /* frame width */
Matthias Weisser76d70862010-01-12 12:06:31 +0100629 VIDEO_VISIBLE_ROWS - video_logo_height - VIDEO_FONT_HEIGHT /* frame height */
wdenke55402c2004-03-14 16:51:43 +0000630 );
wdenkc6097192002-11-03 00:24:07 +0000631#else
wdenke55402c2004-03-14 16:51:43 +0000632 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
633 CONSOLE_SCROLL_SIZE >> 2);
wdenkc6097192002-11-03 00:24:07 +0000634#endif
635
wdenke55402c2004-03-14 16:51:43 +0000636 /* clear the last one */
wdenkc6097192002-11-03 00:24:07 +0000637#ifdef VIDEO_HW_RECTFILL
wdenke55402c2004-03-14 16:51:43 +0000638 video_hw_rectfill (VIDEO_PIXEL_SIZE, /* bytes per pixel */
639 0, /* dest pos x */
640 VIDEO_VISIBLE_ROWS - VIDEO_FONT_HEIGHT, /* dest pos y */
641 VIDEO_VISIBLE_COLS, /* frame width */
642 VIDEO_FONT_HEIGHT, /* frame height */
643 CONSOLE_BG_COL /* fill color */
644 );
wdenkc6097192002-11-03 00:24:07 +0000645#else
wdenke55402c2004-03-14 16:51:43 +0000646 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, CONSOLE_BG_COL);
wdenkc6097192002-11-03 00:24:07 +0000647#endif
648}
649
650/*****************************************************************************/
651
652static void console_back (void)
653{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500654 CURSOR_OFF;
655 console_col--;
wdenkc6097192002-11-03 00:24:07 +0000656
wdenke55402c2004-03-14 16:51:43 +0000657 if (console_col < 0) {
658 console_col = CONSOLE_COLS - 1;
659 console_row--;
660 if (console_row < 0)
661 console_row = 0;
662 }
663 video_putchar (console_col * VIDEO_FONT_WIDTH,
664 console_row * VIDEO_FONT_HEIGHT,
665 ' ');
wdenkc6097192002-11-03 00:24:07 +0000666}
667
668/*****************************************************************************/
669
670static void console_newline (void)
671{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100672 /* Check if last character in the line was just drawn. If so, cursor was
673 overwriten and need not to be cleared. Cursor clearing without this
674 check causes overwriting the 1st character of the line if line lenght
675 is >= CONSOLE_COLS
676 */
677 if (console_col < CONSOLE_COLS)
Timur Tabibe0c74e2010-08-27 15:45:47 -0500678 CURSOR_OFF;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100679 console_row++;
wdenke55402c2004-03-14 16:51:43 +0000680 console_col = 0;
wdenkc6097192002-11-03 00:24:07 +0000681
wdenke55402c2004-03-14 16:51:43 +0000682 /* Check if we need to scroll the terminal */
683 if (console_row >= CONSOLE_ROWS) {
684 /* Scroll everything up */
685 console_scrollup ();
wdenkc6097192002-11-03 00:24:07 +0000686
wdenke55402c2004-03-14 16:51:43 +0000687 /* Decrement row number */
688 console_row--;
689 }
wdenkc6097192002-11-03 00:24:07 +0000690}
691
Anatolij Gustschin938db912008-01-11 02:39:47 +0100692static void console_cr (void)
693{
Timur Tabibe0c74e2010-08-27 15:45:47 -0500694 CURSOR_OFF;
695 console_col = 0;
Anatolij Gustschin938db912008-01-11 02:39:47 +0100696}
697
wdenkc6097192002-11-03 00:24:07 +0000698/*****************************************************************************/
699
700void video_putc (const char c)
701{
Anatolij Gustschin938db912008-01-11 02:39:47 +0100702 static int nl = 1;
703
wdenke55402c2004-03-14 16:51:43 +0000704 switch (c) {
Anatolij Gustschin938db912008-01-11 02:39:47 +0100705 case 13: /* back to first column */
706 console_cr ();
wdenke55402c2004-03-14 16:51:43 +0000707 break;
wdenkc6097192002-11-03 00:24:07 +0000708
wdenke55402c2004-03-14 16:51:43 +0000709 case '\n': /* next line */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100710 if (console_col || (!console_col && nl))
711 console_newline ();
712 nl = 1;
wdenke55402c2004-03-14 16:51:43 +0000713 break;
wdenkc6097192002-11-03 00:24:07 +0000714
wdenke55402c2004-03-14 16:51:43 +0000715 case 9: /* tab 8 */
Timur Tabibe0c74e2010-08-27 15:45:47 -0500716 CURSOR_OFF;
717 console_col |= 0x0008;
wdenke55402c2004-03-14 16:51:43 +0000718 console_col &= ~0x0007;
wdenkc6097192002-11-03 00:24:07 +0000719
wdenke55402c2004-03-14 16:51:43 +0000720 if (console_col >= CONSOLE_COLS)
721 console_newline ();
722 break;
wdenkc6097192002-11-03 00:24:07 +0000723
wdenke55402c2004-03-14 16:51:43 +0000724 case 8: /* backspace */
725 console_back ();
726 break;
wdenkc6097192002-11-03 00:24:07 +0000727
wdenke55402c2004-03-14 16:51:43 +0000728 default: /* draw the char */
729 video_putchar (console_col * VIDEO_FONT_WIDTH,
730 console_row * VIDEO_FONT_HEIGHT,
731 c);
732 console_col++;
wdenkc6097192002-11-03 00:24:07 +0000733
wdenke55402c2004-03-14 16:51:43 +0000734 /* check for newline */
Anatolij Gustschin938db912008-01-11 02:39:47 +0100735 if (console_col >= CONSOLE_COLS) {
wdenke55402c2004-03-14 16:51:43 +0000736 console_newline ();
Anatolij Gustschin938db912008-01-11 02:39:47 +0100737 nl = 0;
738 }
wdenke55402c2004-03-14 16:51:43 +0000739 }
Timur Tabibe0c74e2010-08-27 15:45:47 -0500740 CURSOR_SET;
741}
wdenkc6097192002-11-03 00:24:07 +0000742
743
wdenkc6097192002-11-03 00:24:07 +0000744/*****************************************************************************/
745
746void video_puts (const char *s)
747{
wdenke55402c2004-03-14 16:51:43 +0000748 int count = strlen (s);
749
750 while (count--)
751 video_putc (*s++);
752}
753
754/*****************************************************************************/
755
Anatolij Gustschina043c342010-05-01 22:21:09 +0200756/*
757 * Do not enforce drivers (or board code) to provide empty
758 * video_set_lut() if they do not support 8 bpp format.
759 * Implement weak default function instead.
760 */
761void __video_set_lut (unsigned int index, unsigned char r,
762 unsigned char g, unsigned char b)
763{
764}
765void video_set_lut (unsigned int, unsigned char, unsigned char, unsigned char)
766 __attribute__((weak, alias("__video_set_lut")));
767
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500768#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenke55402c2004-03-14 16:51:43 +0000769
770#define FILL_8BIT_332RGB(r,g,b) { \
771 *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
772 fb ++; \
773}
774
775#define FILL_15BIT_555RGB(r,g,b) { \
776 *(unsigned short *)fb = SWAP16((unsigned short)(((r>>3)<<10) | ((g>>3)<<5) | (b>>3))); \
777 fb += 2; \
778}
779
780#define FILL_16BIT_565RGB(r,g,b) { \
781 *(unsigned short *)fb = SWAP16((unsigned short)((((r)>>3)<<11) | (((g)>>2)<<5) | ((b)>>3))); \
782 fb += 2; \
783}
784
785#define FILL_32BIT_X888RGB(r,g,b) { \
786 *(unsigned long *)fb = SWAP32((unsigned long)(((r<<16) | (g<<8) | b))); \
787 fb += 4; \
788}
789
790#ifdef VIDEO_FB_LITTLE_ENDIAN
791#define FILL_24BIT_888RGB(r,g,b) { \
792 fb[0] = b; \
793 fb[1] = g; \
794 fb[2] = r; \
795 fb += 3; \
796}
797#else
798#define FILL_24BIT_888RGB(r,g,b) { \
799 fb[0] = r; \
800 fb[1] = g; \
801 fb[2] = b; \
802 fb += 3; \
803}
804#endif
805
Anatolij Gustschin18b80362008-08-08 18:00:40 +0200806#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
807static void inline fill_555rgb_pswap(uchar *fb, int x,
808 u8 r, u8 g, u8 b)
809{
810 ushort *dst = (ushort *)fb;
811 ushort color = (ushort)(((r >> 3) << 10) |
812 ((g >> 3) << 5) |
813 (b >> 3));
814 if (x & 1)
815 *(--dst) = color;
816 else
817 *(++dst) = color;
818}
819#endif
wdenke55402c2004-03-14 16:51:43 +0000820
821/*
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +0100822 * RLE8 bitmap support
823 */
824
825#ifdef CONFIG_VIDEO_BMP_RLE8
826/* Pre-calculated color table entry */
827struct palette {
828 union {
829 unsigned short w; /* word */
830 unsigned int dw; /* double word */
831 } ce; /* color entry */
832};
833
834/*
835 * Helper to draw encoded/unencoded run.
836 */
837static void draw_bitmap (uchar **fb, uchar *bm, struct palette *p,
838 int cnt, int enc)
839{
840 ulong addr = (ulong)*fb;
841 int *off;
842 int enc_off = 1;
843 int i;
844
845 /*
846 * Setup offset of the color index in the bitmap.
847 * Color index of encoded run is at offset 1.
848 */
849 off = enc ? &enc_off : &i;
850
851 switch (VIDEO_DATA_FORMAT) {
852 case GDF__8BIT_INDEX:
853 for (i = 0; i < cnt; i++)
854 *(unsigned char *)addr++ = bm[*off];
855 break;
856 case GDF_15BIT_555RGB:
857 case GDF_16BIT_565RGB:
858 /* differences handled while pre-calculating palette */
859 for (i = 0; i < cnt; i++) {
860 *(unsigned short *)addr = p[bm[*off]].ce.w;
861 addr += 2;
862 }
863 break;
864 case GDF_32BIT_X888RGB:
865 for (i = 0; i < cnt; i++) {
866 *(unsigned long *)addr = p[bm[*off]].ce.dw;
867 addr += 4;
868 }
869 break;
870 }
871 *fb = (uchar *)addr; /* return modified address */
872}
873
874static int display_rle8_bitmap (bmp_image_t *img, int xoff, int yoff,
875 int width, int height)
876{
877 unsigned char *bm;
878 unsigned char *fbp;
879 unsigned int cnt, runlen;
880 int decode = 1;
881 int x, y, bpp, i, ncolors;
882 struct palette p[256];
883 bmp_color_table_entry_t cte;
884 int green_shift, red_off;
885
886 x = 0;
887 y = __le32_to_cpu(img->header.height) - 1;
888 ncolors = __le32_to_cpu(img->header.colors_used);
889 bpp = VIDEO_PIXEL_SIZE;
890 fbp = (unsigned char *)((unsigned int)video_fb_address +
891 (((y + yoff) * VIDEO_COLS) + xoff) * bpp);
892
893 bm = (uchar *)img + __le32_to_cpu(img->header.data_offset);
894
895 /* pre-calculate and setup palette */
896 switch (VIDEO_DATA_FORMAT) {
897 case GDF__8BIT_INDEX:
898 for (i = 0; i < ncolors; i++) {
899 cte = img->color_table[i];
900 video_set_lut (i, cte.red, cte.green, cte.blue);
901 }
902 break;
903 case GDF_15BIT_555RGB:
904 case GDF_16BIT_565RGB:
905 if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
906 green_shift = 3;
907 red_off = 10;
908 } else {
909 green_shift = 2;
910 red_off = 11;
911 }
912 for (i = 0; i < ncolors; i++) {
913 cte = img->color_table[i];
914 p[i].ce.w = SWAP16((unsigned short)
915 (((cte.red >> 3) << red_off) |
916 ((cte.green >> green_shift) << 5) |
917 cte.blue >> 3));
918 }
919 break;
920 case GDF_32BIT_X888RGB:
921 for (i = 0; i < ncolors; i++) {
922 cte = img->color_table[i];
923 p[i].ce.dw = SWAP32((cte.red << 16) | (cte.green << 8) |
924 cte.blue);
925 }
926 break;
927 default:
928 printf("RLE Bitmap unsupported in video mode 0x%x\n",
929 VIDEO_DATA_FORMAT);
930 return -1;
931 }
932
933 while (decode) {
934 switch (bm[0]) {
935 case 0:
936 switch (bm[1]) {
937 case 0:
938 /* scan line end marker */
939 bm += 2;
940 x = 0;
941 y--;
942 fbp = (unsigned char *)
943 ((unsigned int)video_fb_address +
944 (((y + yoff) * VIDEO_COLS) +
945 xoff) * bpp);
946 continue;
947 case 1:
948 /* end of bitmap data marker */
949 decode = 0;
950 break;
951 case 2:
952 /* run offset marker */
953 x += bm[2];
954 y -= bm[3];
955 fbp = (unsigned char *)
956 ((unsigned int)video_fb_address +
957 (((y + yoff) * VIDEO_COLS) +
958 x + xoff) * bpp);
959 bm += 4;
960 break;
961 default:
962 /* unencoded run */
963 cnt = bm[1];
964 runlen = cnt;
965 bm += 2;
966 if (y < height) {
967 if (x >= width) {
968 x += runlen;
969 goto next_run;
970 }
971 if (x + runlen > width)
972 cnt = width - x;
973
974 draw_bitmap (&fbp, bm, p, cnt, 0);
975 x += runlen;
976 }
977next_run:
978 bm += runlen;
979 if (runlen & 1)
980 bm++; /* 0 padding if length is odd */
981 }
982 break;
983 default:
984 /* encoded run */
985 if (y < height) { /* only draw into visible area */
986 cnt = bm[0];
987 runlen = cnt;
988 if (x >= width) {
989 x += runlen;
990 bm += 2;
991 continue;
992 }
993 if (x + runlen > width)
994 cnt = width - x;
995
996 draw_bitmap (&fbp, bm, p, cnt, 1);
997 x += runlen;
998 }
999 bm += 2;
1000 break;
1001 }
1002 }
1003 return 0;
1004}
1005#endif
1006
1007/*
wdenke55402c2004-03-14 16:51:43 +00001008 * Display the BMP file located at address bmp_image.
wdenke55402c2004-03-14 16:51:43 +00001009 */
1010int video_display_bitmap (ulong bmp_image, int x, int y)
1011{
1012 ushort xcount, ycount;
1013 uchar *fb;
1014 bmp_image_t *bmp = (bmp_image_t *) bmp_image;
1015 uchar *bmap;
1016 ushort padded_line;
1017 unsigned long width, height, bpp;
1018 unsigned colors;
1019 unsigned long compression;
1020 bmp_color_table_entry_t cte;
Stefan Roesed9d97742005-09-22 09:04:17 +02001021#ifdef CONFIG_VIDEO_BMP_GZIP
1022 unsigned char *dst = NULL;
1023 ulong len;
1024#endif
wdenkc6097192002-11-03 00:24:07 +00001025
wdenke55402c2004-03-14 16:51:43 +00001026 WATCHDOG_RESET ();
1027
1028 if (!((bmp->header.signature[0] == 'B') &&
1029 (bmp->header.signature[1] == 'M'))) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001030
1031#ifdef CONFIG_VIDEO_BMP_GZIP
1032 /*
1033 * Could be a gzipped bmp image, try to decrompress...
1034 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001035 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
1036 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
Stefan Roese13b93692005-10-08 10:19:07 +02001037 if (dst == NULL) {
1038 printf("Error: malloc in gunzip failed!\n");
1039 return(1);
1040 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001041 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, (uchar *)bmp_image, &len) != 0) {
Stefan Roesed9d97742005-09-22 09:04:17 +02001042 printf ("Error: no valid bmp or bmp.gz image at %lx\n", bmp_image);
1043 free(dst);
1044 return 1;
1045 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001046 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
1047 printf("Image could be truncated (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
Stefan Roese13b93692005-10-08 10:19:07 +02001048 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001049
1050 /*
1051 * Set addr to decompressed image
1052 */
1053 bmp = (bmp_image_t *)dst;
1054
1055 if (!((bmp->header.signature[0] == 'B') &&
1056 (bmp->header.signature[1] == 'M'))) {
1057 printf ("Error: no valid bmp.gz image at %lx\n", bmp_image);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001058 free(dst);
Stefan Roesed9d97742005-09-22 09:04:17 +02001059 return 1;
1060 }
1061#else
wdenke55402c2004-03-14 16:51:43 +00001062 printf ("Error: no valid bmp image at %lx\n", bmp_image);
1063 return 1;
Stefan Roesed9d97742005-09-22 09:04:17 +02001064#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenke55402c2004-03-14 16:51:43 +00001065 }
1066
1067 width = le32_to_cpu (bmp->header.width);
1068 height = le32_to_cpu (bmp->header.height);
1069 bpp = le16_to_cpu (bmp->header.bit_count);
1070 colors = le32_to_cpu (bmp->header.colors_used);
1071 compression = le32_to_cpu (bmp->header.compression);
1072
1073 debug ("Display-bmp: %d x %d with %d colors\n",
1074 width, height, colors);
1075
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001076 if (compression != BMP_BI_RGB
1077#ifdef CONFIG_VIDEO_BMP_RLE8
1078 && compression != BMP_BI_RLE8
1079#endif
1080 ) {
wdenke55402c2004-03-14 16:51:43 +00001081 printf ("Error: compression type %ld not supported\n",
1082 compression);
Matthias Fuchsa7c5a592008-04-21 11:19:04 +02001083#ifdef CONFIG_VIDEO_BMP_GZIP
1084 if (dst)
1085 free(dst);
1086#endif
wdenke55402c2004-03-14 16:51:43 +00001087 return 1;
1088 }
1089
1090 padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
1091
Matthias Weisser53884182009-07-09 16:07:30 +02001092#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1093 if (x == BMP_ALIGN_CENTER)
1094 x = max(0, (VIDEO_VISIBLE_COLS - width) / 2);
1095 else if (x < 0)
1096 x = max(0, VIDEO_VISIBLE_COLS - width + x + 1);
1097
1098 if (y == BMP_ALIGN_CENTER)
1099 y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2);
1100 else if (y < 0)
1101 y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1);
1102#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1103
wdenke55402c2004-03-14 16:51:43 +00001104 if ((x + width) > VIDEO_VISIBLE_COLS)
1105 width = VIDEO_VISIBLE_COLS - x;
1106 if ((y + height) > VIDEO_VISIBLE_ROWS)
1107 height = VIDEO_VISIBLE_ROWS - y;
1108
1109 bmap = (uchar *) bmp + le32_to_cpu (bmp->header.data_offset);
1110 fb = (uchar *) (video_fb_address +
1111 ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
1112 x * VIDEO_PIXEL_SIZE);
1113
Anatolij Gustschin6b4e4fc2010-03-15 14:50:25 +01001114#ifdef CONFIG_VIDEO_BMP_RLE8
1115 if (compression == BMP_BI_RLE8) {
1116 return display_rle8_bitmap(bmp,
1117 x, y, width, height);
1118 }
1119#endif
1120
Timur Tabi0fce9922010-08-23 16:58:00 -05001121 /* We handle only 4, 8, or 24 bpp bitmaps */
wdenke55402c2004-03-14 16:51:43 +00001122 switch (le16_to_cpu (bmp->header.bit_count)) {
Timur Tabi0fce9922010-08-23 16:58:00 -05001123 case 4:
1124 padded_line -= width / 2;
1125 ycount = height;
1126
1127 switch (VIDEO_DATA_FORMAT) {
1128 case GDF_32BIT_X888RGB:
1129 while (ycount--) {
1130 WATCHDOG_RESET ();
1131 /*
1132 * Don't assume that 'width' is an
1133 * even number
1134 */
1135 for (xcount = 0; xcount < width; xcount++) {
1136 uchar idx;
1137
1138 if (xcount & 1) {
1139 idx = *bmap & 0xF;
1140 bmap++;
1141 } else
1142 idx = *bmap >> 4;
1143 cte = bmp->color_table[idx];
1144 FILL_32BIT_X888RGB(cte.red, cte.green,
1145 cte.blue);
1146 }
1147 bmap += padded_line;
1148 fb -= (VIDEO_VISIBLE_COLS + width) *
1149 VIDEO_PIXEL_SIZE;
1150 }
1151 break;
1152 default:
1153 puts("4bpp bitmap unsupported with current "
1154 "video mode\n");
1155 break;
1156 }
1157 break;
1158
wdenke55402c2004-03-14 16:51:43 +00001159 case 8:
1160 padded_line -= width;
1161 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001162 /* Copy colormap */
wdenke55402c2004-03-14 16:51:43 +00001163 for (xcount = 0; xcount < colors; ++xcount) {
1164 cte = bmp->color_table[xcount];
1165 video_set_lut (xcount, cte.red, cte.green, cte.blue);
1166 }
1167 }
1168 ycount = height;
1169 switch (VIDEO_DATA_FORMAT) {
1170 case GDF__8BIT_INDEX:
1171 while (ycount--) {
1172 WATCHDOG_RESET ();
1173 xcount = width;
1174 while (xcount--) {
1175 *fb++ = *bmap++;
1176 }
1177 bmap += padded_line;
1178 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1179 }
1180 break;
1181 case GDF__8BIT_332RGB:
1182 while (ycount--) {
1183 WATCHDOG_RESET ();
1184 xcount = width;
1185 while (xcount--) {
1186 cte = bmp->color_table[*bmap++];
1187 FILL_8BIT_332RGB (cte.red, cte.green, cte.blue);
1188 }
1189 bmap += padded_line;
1190 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1191 }
1192 break;
1193 case GDF_15BIT_555RGB:
1194 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001195#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1196 int xpos = x;
1197#endif
wdenke55402c2004-03-14 16:51:43 +00001198 WATCHDOG_RESET ();
1199 xcount = width;
1200 while (xcount--) {
1201 cte = bmp->color_table[*bmap++];
Andrew Dyer5601c612008-08-29 12:30:39 -05001202#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001203 fill_555rgb_pswap (fb, xpos++, cte.red,
1204 cte.green, cte.blue);
1205 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001206#else
1207 FILL_15BIT_555RGB (cte.red, cte.green, cte.blue);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001208#endif
wdenke55402c2004-03-14 16:51:43 +00001209 }
1210 bmap += padded_line;
1211 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1212 }
1213 break;
1214 case GDF_16BIT_565RGB:
1215 while (ycount--) {
1216 WATCHDOG_RESET ();
1217 xcount = width;
1218 while (xcount--) {
1219 cte = bmp->color_table[*bmap++];
1220 FILL_16BIT_565RGB (cte.red, cte.green, cte.blue);
1221 }
1222 bmap += padded_line;
1223 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1224 }
1225 break;
1226 case GDF_32BIT_X888RGB:
1227 while (ycount--) {
1228 WATCHDOG_RESET ();
1229 xcount = width;
1230 while (xcount--) {
1231 cte = bmp->color_table[*bmap++];
1232 FILL_32BIT_X888RGB (cte.red, cte.green, cte.blue);
1233 }
1234 bmap += padded_line;
1235 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1236 }
1237 break;
1238 case GDF_24BIT_888RGB:
1239 while (ycount--) {
1240 WATCHDOG_RESET ();
1241 xcount = width;
1242 while (xcount--) {
1243 cte = bmp->color_table[*bmap++];
1244 FILL_24BIT_888RGB (cte.red, cte.green, cte.blue);
1245 }
1246 bmap += padded_line;
1247 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1248 }
1249 break;
1250 }
1251 break;
1252 case 24:
1253 padded_line -= 3 * width;
1254 ycount = height;
1255 switch (VIDEO_DATA_FORMAT) {
1256 case GDF__8BIT_332RGB:
1257 while (ycount--) {
1258 WATCHDOG_RESET ();
1259 xcount = width;
1260 while (xcount--) {
1261 FILL_8BIT_332RGB (bmap[2], bmap[1], bmap[0]);
1262 bmap += 3;
1263 }
1264 bmap += padded_line;
1265 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1266 }
1267 break;
1268 case GDF_15BIT_555RGB:
1269 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001270#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1271 int xpos = x;
1272#endif
wdenke55402c2004-03-14 16:51:43 +00001273 WATCHDOG_RESET ();
1274 xcount = width;
1275 while (xcount--) {
Andrew Dyer5601c612008-08-29 12:30:39 -05001276#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001277 fill_555rgb_pswap (fb, xpos++, bmap[2],
1278 bmap[1], bmap[0]);
1279 fb += 2;
Andrew Dyer5601c612008-08-29 12:30:39 -05001280#else
1281 FILL_15BIT_555RGB (bmap[2], bmap[1], bmap[0]);
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001282#endif
wdenke55402c2004-03-14 16:51:43 +00001283 bmap += 3;
1284 }
1285 bmap += padded_line;
1286 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1287 }
1288 break;
1289 case GDF_16BIT_565RGB:
1290 while (ycount--) {
1291 WATCHDOG_RESET ();
1292 xcount = width;
1293 while (xcount--) {
1294 FILL_16BIT_565RGB (bmap[2], bmap[1], bmap[0]);
1295 bmap += 3;
1296 }
1297 bmap += padded_line;
1298 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1299 }
1300 break;
1301 case GDF_32BIT_X888RGB:
1302 while (ycount--) {
1303 WATCHDOG_RESET ();
1304 xcount = width;
1305 while (xcount--) {
1306 FILL_32BIT_X888RGB (bmap[2], bmap[1], bmap[0]);
1307 bmap += 3;
1308 }
1309 bmap += padded_line;
1310 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1311 }
1312 break;
1313 case GDF_24BIT_888RGB:
1314 while (ycount--) {
1315 WATCHDOG_RESET ();
1316 xcount = width;
1317 while (xcount--) {
1318 FILL_24BIT_888RGB (bmap[2], bmap[1], bmap[0]);
1319 bmap += 3;
1320 }
1321 bmap += padded_line;
1322 fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
1323 }
1324 break;
1325 default:
1326 printf ("Error: 24 bits/pixel bitmap incompatible with current video mode\n");
1327 break;
1328 }
1329 break;
1330 default:
1331 printf ("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
1332 le16_to_cpu (bmp->header.bit_count));
1333 break;
1334 }
Stefan Roesed9d97742005-09-22 09:04:17 +02001335
1336#ifdef CONFIG_VIDEO_BMP_GZIP
1337 if (dst) {
1338 free(dst);
1339 }
1340#endif
1341
wdenke55402c2004-03-14 16:51:43 +00001342 return (0);
wdenkc6097192002-11-03 00:24:07 +00001343}
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001344#endif
wdenkc6097192002-11-03 00:24:07 +00001345
1346/*****************************************************************************/
1347
1348#ifdef CONFIG_VIDEO_LOGO
1349void logo_plot (void *screen, int width, int x, int y)
1350{
wdenk9dd2b882002-12-03 21:28:10 +00001351
wdenke55402c2004-03-14 16:51:43 +00001352 int xcount, i;
1353 int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
Matthias Weisser76d70862010-01-12 12:06:31 +01001354 int ycount = video_logo_height;
wdenke55402c2004-03-14 16:51:43 +00001355 unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
1356 unsigned char *source;
Anatolij Gustschin06bf2a62008-08-08 18:00:39 +02001357 unsigned char *dest = (unsigned char *)screen +
1358 ((y * width * VIDEO_PIXEL_SIZE) +
1359 x * VIDEO_PIXEL_SIZE);
wdenkc6097192002-11-03 00:24:07 +00001360
wdenk9dd2b882002-12-03 21:28:10 +00001361#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001362 source = bmp_logo_bitmap;
wdenk57b2d802003-06-27 21:31:46 +00001363
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001364 /* Allocate temporary space for computing colormap */
wdenke55402c2004-03-14 16:51:43 +00001365 logo_red = malloc (BMP_LOGO_COLORS);
1366 logo_green = malloc (BMP_LOGO_COLORS);
1367 logo_blue = malloc (BMP_LOGO_COLORS);
Anatolij Gustschin794b25c2010-06-19 20:41:56 +02001368 /* Compute color map */
wdenke55402c2004-03-14 16:51:43 +00001369 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1370 logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
1371 logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
1372 logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
1373 }
wdenk9dd2b882002-12-03 21:28:10 +00001374#else
wdenke55402c2004-03-14 16:51:43 +00001375 source = linux_logo;
1376 logo_red = linux_logo_red;
1377 logo_green = linux_logo_green;
1378 logo_blue = linux_logo_blue;
wdenk9dd2b882002-12-03 21:28:10 +00001379#endif
wdenk57b2d802003-06-27 21:31:46 +00001380
wdenke55402c2004-03-14 16:51:43 +00001381 if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
1382 for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
1383 video_set_lut (i + VIDEO_LOGO_LUT_OFFSET,
1384 logo_red[i], logo_green[i], logo_blue[i]);
1385 }
wdenk57b2d802003-06-27 21:31:46 +00001386 }
wdenkc6097192002-11-03 00:24:07 +00001387
wdenke55402c2004-03-14 16:51:43 +00001388 while (ycount--) {
Anatolij Gustschin18b80362008-08-08 18:00:40 +02001389#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1390 int xpos = x;
1391#endif
wdenke55402c2004-03-14 16:51:43 +00001392 xcount = VIDEO_LOGO_WIDTH;
1393 while (xcount--) {
1394 r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
1395 g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
1396 b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
wdenk57b2d802003-06-27 21:31:46 +00001397
wdenke55402c2004-03-14 16:51:43 +00001398 switch (VIDEO_DATA_FORMAT) {
1399 case GDF__8BIT_INDEX:
1400 *dest = *source;
1401 break;
1402 case GDF__8BIT_332RGB:
1403 *dest = ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
1404 break;
1405 case GDF_15BIT_555RGB:
Andrew Dyer5601c612008-08-29 12:30:39 -05001406#if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
1407 fill_555rgb_pswap (dest, xpos++, r, g, b);
1408#else
wdenke55402c2004-03-14 16:51:43 +00001409 *(unsigned short *) dest =
1410 SWAP16 ((unsigned short) (((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3)));
Anatolij Gustschin3545f592008-01-11 14:30:01 +01001411#endif
wdenke55402c2004-03-14 16:51:43 +00001412 break;
1413 case GDF_16BIT_565RGB:
1414 *(unsigned short *) dest =
1415 SWAP16 ((unsigned short) (((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)));
1416 break;
1417 case GDF_32BIT_X888RGB:
1418 *(unsigned long *) dest =
1419 SWAP32 ((unsigned long) ((r << 16) | (g << 8) | b));
1420 break;
1421 case GDF_24BIT_888RGB:
wdenkc6097192002-11-03 00:24:07 +00001422#ifdef VIDEO_FB_LITTLE_ENDIAN
wdenke55402c2004-03-14 16:51:43 +00001423 dest[0] = b;
1424 dest[1] = g;
1425 dest[2] = r;
wdenkc6097192002-11-03 00:24:07 +00001426#else
wdenke55402c2004-03-14 16:51:43 +00001427 dest[0] = r;
1428 dest[1] = g;
1429 dest[2] = b;
wdenkc6097192002-11-03 00:24:07 +00001430#endif
wdenke55402c2004-03-14 16:51:43 +00001431 break;
1432 }
1433 source++;
1434 dest += VIDEO_PIXEL_SIZE;
1435 }
1436 dest += skip;
wdenk57b2d802003-06-27 21:31:46 +00001437 }
wdenk9dd2b882002-12-03 21:28:10 +00001438#ifdef CONFIG_VIDEO_BMP_LOGO
wdenke55402c2004-03-14 16:51:43 +00001439 free (logo_red);
1440 free (logo_green);
1441 free (logo_blue);
wdenk9dd2b882002-12-03 21:28:10 +00001442#endif
wdenkc6097192002-11-03 00:24:07 +00001443}
1444
wdenkc6097192002-11-03 00:24:07 +00001445/*****************************************************************************/
1446
1447static void *video_logo (void)
1448{
wdenke55402c2004-03-14 16:51:43 +00001449 char info[128];
1450 extern char version_string;
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001451 int space, len, y_off = 0;
wdenke55402c2004-03-14 16:51:43 +00001452
1453#ifdef CONFIG_SPLASH_SCREEN
1454 char *s;
1455 ulong addr;
1456
1457 if ((s = getenv ("splashimage")) != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001458 int x = 0, y = 0;
1459
wdenke55402c2004-03-14 16:51:43 +00001460 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser53884182009-07-09 16:07:30 +02001461#ifdef CONFIG_SPLASH_SCREEN_ALIGN
1462 if ((s = getenv ("splashpos")) != NULL) {
1463 if (s[0] == 'm')
1464 x = BMP_ALIGN_CENTER;
1465 else
1466 x = simple_strtol (s, NULL, 0);
1467
1468 if ((s = strchr (s + 1, ',')) != NULL) {
1469 if (s[1] == 'm')
1470 y = BMP_ALIGN_CENTER;
1471 else
1472 y = simple_strtol (s + 1, NULL, 0);
1473 }
1474 }
1475#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
wdenke55402c2004-03-14 16:51:43 +00001476
Matthias Weisser53884182009-07-09 16:07:30 +02001477 if (video_display_bitmap (addr, x, y) == 0) {
Matthias Weisser76d70862010-01-12 12:06:31 +01001478 video_logo_height = 0;
wdenke55402c2004-03-14 16:51:43 +00001479 return ((void *) (video_fb_address));
1480 }
1481 }
1482#endif /* CONFIG_SPLASH_SCREEN */
1483
wdenke55402c2004-03-14 16:51:43 +00001484 logo_plot (video_fb_address, VIDEO_COLS, 0, 0);
wdenkc6097192002-11-03 00:24:07 +00001485
wdenke55402c2004-03-14 16:51:43 +00001486 sprintf (info, " %s", &version_string);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001487
1488 space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
1489 len = strlen(info);
1490
1491 if (len > space) {
1492 video_drawchars (VIDEO_INFO_X, VIDEO_INFO_Y,
1493 (uchar *)info, space);
1494 video_drawchars (VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1495 VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1496 (uchar *)info + space, len - space);
1497 y_off = 1;
1498 } else
1499 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *)info);
wdenkc6097192002-11-03 00:24:07 +00001500
1501#ifdef CONFIG_CONSOLE_EXTRA_INFO
wdenke55402c2004-03-14 16:51:43 +00001502 {
Matthias Weisser76d70862010-01-12 12:06:31 +01001503 int i, n = ((video_logo_height - VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001504
wdenke55402c2004-03-14 16:51:43 +00001505 for (i = 1; i < n; i++) {
1506 video_get_info_str (i, info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001507 if (!*info)
1508 continue;
1509
1510 len = strlen(info);
1511 if (len > space) {
1512 video_drawchars (VIDEO_INFO_X,
1513 VIDEO_INFO_Y +
1514 (i + y_off) * VIDEO_FONT_HEIGHT,
1515 (uchar *)info, space);
1516 y_off++;
1517 video_drawchars (VIDEO_INFO_X + VIDEO_FONT_WIDTH,
1518 VIDEO_INFO_Y +
1519 (i + y_off) * VIDEO_FONT_HEIGHT,
1520 (uchar *)info + space,
1521 len - space);
1522 } else {
wdenke55402c2004-03-14 16:51:43 +00001523 video_drawstring (VIDEO_INFO_X,
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001524 VIDEO_INFO_Y +
1525 (i + y_off) * VIDEO_FONT_HEIGHT,
Wolfgang Denk7fb52662005-10-13 16:45:02 +02001526 (uchar *)info);
Anatolij Gustschine6e98b22009-04-23 12:35:22 +02001527 }
wdenke55402c2004-03-14 16:51:43 +00001528 }
1529 }
wdenkc6097192002-11-03 00:24:07 +00001530#endif
1531
Matthias Weisser76d70862010-01-12 12:06:31 +01001532 return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
wdenkc6097192002-11-03 00:24:07 +00001533}
1534#endif
1535
1536
1537/*****************************************************************************/
1538
wdenke55402c2004-03-14 16:51:43 +00001539static int video_init (void)
wdenkc6097192002-11-03 00:24:07 +00001540{
wdenke55402c2004-03-14 16:51:43 +00001541 unsigned char color8;
wdenkc6097192002-11-03 00:24:07 +00001542
wdenke55402c2004-03-14 16:51:43 +00001543 if ((pGD = video_hw_init ()) == NULL)
1544 return -1;
wdenkc6097192002-11-03 00:24:07 +00001545
wdenke55402c2004-03-14 16:51:43 +00001546 video_fb_address = (void *) VIDEO_FB_ADRS;
wdenkc6097192002-11-03 00:24:07 +00001547#ifdef CONFIG_VIDEO_HW_CURSOR
wdenke55402c2004-03-14 16:51:43 +00001548 video_init_hw_cursor (VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
wdenkc6097192002-11-03 00:24:07 +00001549#endif
1550
wdenke55402c2004-03-14 16:51:43 +00001551 /* Init drawing pats */
1552 switch (VIDEO_DATA_FORMAT) {
1553 case GDF__8BIT_INDEX:
1554 video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL);
1555 video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL);
1556 fgx = 0x01010101;
1557 bgx = 0x00000000;
1558 break;
1559 case GDF__8BIT_332RGB:
1560 color8 = ((CONSOLE_FG_COL & 0xe0) |
1561 ((CONSOLE_FG_COL >> 3) & 0x1c) | CONSOLE_FG_COL >> 6);
1562 fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
1563 color8 = ((CONSOLE_BG_COL & 0xe0) |
1564 ((CONSOLE_BG_COL >> 3) & 0x1c) | CONSOLE_BG_COL >> 6);
1565 bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
1566 break;
1567 case GDF_15BIT_555RGB:
1568 fgx = (((CONSOLE_FG_COL >> 3) << 26) |
1569 ((CONSOLE_FG_COL >> 3) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
1570 ((CONSOLE_FG_COL >> 3) << 10) | ((CONSOLE_FG_COL >> 3) << 5) |
1571 (CONSOLE_FG_COL >> 3));
1572 bgx = (((CONSOLE_BG_COL >> 3) << 26) |
1573 ((CONSOLE_BG_COL >> 3) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
1574 ((CONSOLE_BG_COL >> 3) << 10) | ((CONSOLE_BG_COL >> 3) << 5) |
1575 (CONSOLE_BG_COL >> 3));
1576 break;
1577 case GDF_16BIT_565RGB:
1578 fgx = (((CONSOLE_FG_COL >> 3) << 27) |
1579 ((CONSOLE_FG_COL >> 2) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
1580 ((CONSOLE_FG_COL >> 3) << 11) | ((CONSOLE_FG_COL >> 2) << 5) |
1581 (CONSOLE_FG_COL >> 3));
1582 bgx = (((CONSOLE_BG_COL >> 3) << 27) |
1583 ((CONSOLE_BG_COL >> 2) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
1584 ((CONSOLE_BG_COL >> 3) << 11) | ((CONSOLE_BG_COL >> 2) << 5) |
1585 (CONSOLE_BG_COL >> 3));
1586 break;
1587 case GDF_32BIT_X888RGB:
1588 fgx = (CONSOLE_FG_COL << 16) | (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
1589 bgx = (CONSOLE_BG_COL << 16) | (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
1590 break;
1591 case GDF_24BIT_888RGB:
1592 fgx = (CONSOLE_FG_COL << 24) | (CONSOLE_FG_COL << 16) |
1593 (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
1594 bgx = (CONSOLE_BG_COL << 24) | (CONSOLE_BG_COL << 16) |
1595 (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
1596 break;
1597 }
1598 eorx = fgx ^ bgx;
wdenkc6097192002-11-03 00:24:07 +00001599
1600#ifdef CONFIG_VIDEO_LOGO
wdenke55402c2004-03-14 16:51:43 +00001601 /* Plot the logo and get start point of console */
1602 PRINTD ("Video: Drawing the logo ...\n");
1603 video_console_address = video_logo ();
wdenkc6097192002-11-03 00:24:07 +00001604#else
wdenke55402c2004-03-14 16:51:43 +00001605 video_console_address = video_fb_address;
wdenkc6097192002-11-03 00:24:07 +00001606#endif
1607
wdenke55402c2004-03-14 16:51:43 +00001608 /* Initialize the console */
1609 console_col = 0;
1610 console_row = 0;
wdenkc6097192002-11-03 00:24:07 +00001611
wdenke55402c2004-03-14 16:51:43 +00001612 return 0;
wdenkc6097192002-11-03 00:24:07 +00001613}
1614
1615
1616/*****************************************************************************/
1617
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001618/*
1619 * Implement a weak default function for boards that optionally
1620 * need to skip the video initialization.
1621 */
1622int __board_video_skip(void)
1623{
1624 /* As default, don't skip test */
1625 return 0;
1626}
1627int board_video_skip(void) __attribute__((weak, alias("__board_video_skip")));
1628
wdenkc6097192002-11-03 00:24:07 +00001629int drv_video_init (void)
1630{
wdenke55402c2004-03-14 16:51:43 +00001631 int skip_dev_init;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02001632 struct stdio_dev console_dev;
wdenkc6097192002-11-03 00:24:07 +00001633
Wolfgang Denkd0e4e2a2009-05-15 10:07:43 +02001634 /* Check if video initialization should be skipped */
1635 if (board_video_skip())
1636 return 0;
1637
wdenk7dd13292004-07-11 20:04:51 +00001638 /* Init video chip - returns with framebuffer cleared */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001639 skip_dev_init = (video_init () == -1);
wdenkc6097192002-11-03 00:24:07 +00001640
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001641#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
wdenke55402c2004-03-14 16:51:43 +00001642 PRINTD ("KBD: Keyboard init ...\n");
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001643 skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1);
1644#endif
wdenkc6097192002-11-03 00:24:07 +00001645
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001646 if (skip_dev_init)
1647 return 0;
wdenkc6097192002-11-03 00:24:07 +00001648
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001649 /* Init vga device */
1650 memset (&console_dev, 0, sizeof (console_dev));
1651 strcpy (console_dev.name, "vga");
1652 console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
1653 console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
1654 console_dev.putc = video_putc; /* 'putc' function */
1655 console_dev.puts = video_puts; /* 'puts' function */
1656 console_dev.tstc = NULL; /* 'tstc' function */
1657 console_dev.getc = NULL; /* 'getc' function */
1658
1659#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
1660 /* Also init console device */
1661 console_dev.flags |= DEV_FLAGS_INPUT;
1662 console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
1663 console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
wdenkc6097192002-11-03 00:24:07 +00001664#endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001665
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02001666 if (stdio_register (&console_dev) != 0)
Wolfgang Denk50bc99c2009-05-15 10:07:42 +02001667 return 0;
1668
1669 /* Return success */
1670 return 1;
wdenkc6097192002-11-03 00:24:07 +00001671}