]>
Commit | Line | Data |
---|---|---|
c609719b WD |
1 | /* |
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 | |
4b248f3f | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c609719b WD |
16 | * 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 | |
64e40d72 | 32 | * information strings (that normally goes to serial port) can be drawn. |
c609719b WD |
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. | |
64e40d72 WD |
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 | |
45 | * 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 | |
48 | * | |
49 | * Console Parameters are set by graphic drivers global struct: | |
50 | * | |
51 | * 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 | |
56 | * | |
57 | * 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 | |
61 | * | |
62 | * CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with | |
63 | * delay loop in VIDEO_TSTC_FCT (i8042) | |
64 | * | |
65 | * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate | |
66 | * CONFIG_CONSOLE_TIME - display time/date in upper right | |
67 | * corner, needs CONFIG_CMD_DATE and | |
68 | * CONFIG_CONSOLE_CURSOR | |
69 | * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner | |
70 | * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo | |
71 | * CONFIG_CONSOLE_EXTRA_INFO - display additional board information | |
72 | * strings that normaly goes to serial | |
73 | * port. This define requires a board | |
74 | * specific function: | |
75 | * video_drawstring (VIDEO_INFO_X, | |
76 | * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT, | |
77 | * info); | |
78 | * that fills a info buffer at i=row. | |
79 | * s.a: board/eltec/bab7xx. | |
80 | * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be | |
81 | * initialized as an output only device. | |
82 | * The Keyboard driver will not be | |
83 | * set-up. This may be used, if you have | |
84 | * no or more than one Keyboard devices | |
85 | * (USB Keyboard, AT Keyboard). | |
86 | * | |
87 | * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last | |
88 | * character. No blinking is provided. | |
89 | * Uses the macros CURSOR_SET and | |
90 | * CURSOR_OFF. | |
91 | * | |
92 | * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability | |
93 | * of the graphic chip. Uses the macro | |
94 | * CURSOR_SET. ATTENTION: If booting an | |
95 | * OS, the display driver must disable | |
96 | * the hardware register of the graphic | |
97 | * chip. Otherwise a blinking field is | |
98 | * displayed. | |
99 | */ | |
c609719b WD |
100 | |
101 | #include <common.h> | |
09c2e90c | 102 | #include <version.h> |
a6c7ad2f | 103 | #include <malloc.h> |
a9a62af1 | 104 | #include <linux/compiler.h> |
a6c7ad2f | 105 | |
64e40d72 WD |
106 | /* |
107 | * Console device defines with SMI graphic | |
108 | * Any other graphic must change this section | |
109 | */ | |
c609719b | 110 | |
4b248f3f | 111 | #ifdef CONFIG_VIDEO_SMI_LYNXEM |
c609719b WD |
112 | |
113 | #define VIDEO_FB_LITTLE_ENDIAN | |
114 | #define VIDEO_HW_RECTFILL | |
115 | #define VIDEO_HW_BITBLT | |
116 | #endif | |
117 | ||
64e40d72 WD |
118 | /* |
119 | * Defines for the CT69000 driver | |
120 | */ | |
4b248f3f | 121 | #ifdef CONFIG_VIDEO_CT69000 |
c609719b WD |
122 | |
123 | #define VIDEO_FB_LITTLE_ENDIAN | |
124 | #define VIDEO_HW_RECTFILL | |
125 | #define VIDEO_HW_BITBLT | |
126 | #endif | |
127 | ||
64e40d72 WD |
128 | /* |
129 | * Defines for the SED13806 driver | |
130 | */ | |
a6c7ad2f WD |
131 | #ifdef CONFIG_VIDEO_SED13806 |
132 | ||
89394047 | 133 | #ifndef CONFIG_TOTAL5200 |
a6c7ad2f | 134 | #define VIDEO_FB_LITTLE_ENDIAN |
89394047 | 135 | #endif |
a6c7ad2f WD |
136 | #define VIDEO_HW_RECTFILL |
137 | #define VIDEO_HW_BITBLT | |
138 | #endif | |
139 | ||
64e40d72 WD |
140 | /* |
141 | * Defines for the SED13806 driver | |
142 | */ | |
98f4a3df SR |
143 | #ifdef CONFIG_VIDEO_SM501 |
144 | ||
145 | #ifdef CONFIG_HH405 | |
146 | #define VIDEO_FB_LITTLE_ENDIAN | |
147 | #endif | |
148 | #endif | |
149 | ||
64e40d72 WD |
150 | /* |
151 | * Defines for the MB862xx driver | |
152 | */ | |
bed53753 AG |
153 | #ifdef CONFIG_VIDEO_MB862xx |
154 | ||
155 | #ifdef CONFIG_VIDEO_CORALP | |
156 | #define VIDEO_FB_LITTLE_ENDIAN | |
157 | #endif | |
5d16ca87 | 158 | #ifdef CONFIG_VIDEO_MB862xx_ACCEL |
bed53753 AG |
159 | #define VIDEO_HW_RECTFILL |
160 | #define VIDEO_HW_BITBLT | |
161 | #endif | |
5d16ca87 | 162 | #endif |
bed53753 | 163 | |
62a22dca HR |
164 | /* |
165 | * Defines for the i.MX31 driver (mx3fb.c) | |
166 | */ | |
5fb1a6f9 | 167 | #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_MX5) |
62a22dca HR |
168 | #define VIDEO_FB_16BPP_WORD_SWAP |
169 | #endif | |
170 | ||
64e40d72 WD |
171 | /* |
172 | * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc. | |
173 | */ | |
c609719b WD |
174 | #include <video_fb.h> |
175 | ||
64e40d72 WD |
176 | /* |
177 | * some Macros | |
178 | */ | |
4b248f3f WD |
179 | #define VIDEO_VISIBLE_COLS (pGD->winSizeX) |
180 | #define VIDEO_VISIBLE_ROWS (pGD->winSizeY) | |
181 | #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP) | |
182 | #define VIDEO_DATA_FORMAT (pGD->gdfIndex) | |
183 | #define VIDEO_FB_ADRS (pGD->frameAdrs) | |
c609719b | 184 | |
64e40d72 WD |
185 | /* |
186 | * Console device defines with i8042 keyboard controller | |
187 | * Any other keyboard controller must change this section | |
188 | */ | |
c609719b | 189 | |
4b248f3f | 190 | #ifdef CONFIG_I8042_KBD |
c609719b WD |
191 | #include <i8042.h> |
192 | ||
4b248f3f WD |
193 | #define VIDEO_KBD_INIT_FCT i8042_kbd_init() |
194 | #define VIDEO_TSTC_FCT i8042_tstc | |
195 | #define VIDEO_GETC_FCT i8042_getc | |
c609719b WD |
196 | #endif |
197 | ||
64e40d72 WD |
198 | /* |
199 | * Console device | |
200 | */ | |
c609719b WD |
201 | |
202 | #include <version.h> | |
203 | #include <linux/types.h> | |
52cb4d4f | 204 | #include <stdio_dev.h> |
c609719b | 205 | #include <video_font.h> |
d3983ee8 | 206 | #include <video_font_data.h> |
c609719b | 207 | |
ddb5d86f JL |
208 | #if defined(CONFIG_CMD_DATE) |
209 | #include <rtc.h> | |
c609719b WD |
210 | #endif |
211 | ||
07d38a17 | 212 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
4b248f3f WD |
213 | #include <watchdog.h> |
214 | #include <bmp_layout.h> | |
1ca298ce MW |
215 | |
216 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN | |
217 | #define BMP_ALIGN_CENTER 0x7FFF | |
218 | #endif | |
219 | ||
07d38a17 | 220 | #endif |
4b248f3f | 221 | |
64e40d72 WD |
222 | /* |
223 | * Cursor definition: | |
224 | * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c) | |
225 | * to let the cursor blink. Uses the macros | |
226 | * CURSOR_OFF and CURSOR_ON. | |
227 | * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No | |
228 | * blinking is provided. Uses the macros CURSOR_SET | |
229 | * and CURSOR_OFF. | |
230 | * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the | |
231 | * graphic chip. Uses the macro CURSOR_SET. | |
232 | * ATTENTION: If booting an OS, the display driver | |
233 | * must disable the hardware register of the graphic | |
234 | * chip. Otherwise a blinking field is displayed | |
235 | */ | |
c609719b WD |
236 | #if !defined(CONFIG_CONSOLE_CURSOR) && \ |
237 | !defined(CONFIG_VIDEO_SW_CURSOR) && \ | |
238 | !defined(CONFIG_VIDEO_HW_CURSOR) | |
239 | /* no Cursor defined */ | |
240 | #define CURSOR_ON | |
241 | #define CURSOR_OFF | |
242 | #define CURSOR_SET | |
243 | #endif | |
244 | ||
03d31fcf GB |
245 | #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR) |
246 | #if defined(CURSOR_ON) || \ | |
247 | (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR)) | |
64e40d72 WD |
248 | #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \ |
249 | or CONFIG_VIDEO_HW_CURSOR can be defined | |
c609719b | 250 | #endif |
64e40d72 WD |
251 | void console_cursor(int state); |
252 | ||
65618636 TT |
253 | #define CURSOR_ON console_cursor(1) |
254 | #define CURSOR_OFF console_cursor(0) | |
03d31fcf GB |
255 | #define CURSOR_SET video_set_cursor() |
256 | #endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */ | |
257 | ||
258 | #ifdef CONFIG_CONSOLE_CURSOR | |
259 | #ifndef CONFIG_CONSOLE_TIME | |
260 | #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME | |
261 | #endif | |
c609719b | 262 | #ifndef CONFIG_I8042_KBD |
7817cb20 | 263 | #warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c |
c609719b | 264 | #endif |
c609719b WD |
265 | #endif /* CONFIG_CONSOLE_CURSOR */ |
266 | ||
c609719b WD |
267 | |
268 | #ifdef CONFIG_VIDEO_HW_CURSOR | |
4b248f3f | 269 | #ifdef CURSOR_ON |
64e40d72 WD |
270 | #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \ |
271 | or CONFIG_VIDEO_HW_CURSOR can be defined | |
c609719b WD |
272 | #endif |
273 | #define CURSOR_ON | |
274 | #define CURSOR_OFF | |
275 | #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \ | |
65618636 | 276 | (console_row * VIDEO_FONT_HEIGHT) + video_logo_height) |
64e40d72 | 277 | #endif /* CONFIG_VIDEO_HW_CURSOR */ |
c609719b | 278 | |
4b248f3f WD |
279 | #ifdef CONFIG_VIDEO_LOGO |
280 | #ifdef CONFIG_VIDEO_BMP_LOGO | |
a6c7ad2f | 281 | #include <bmp_logo.h> |
c270730f | 282 | #include <bmp_logo_data.h> |
4b248f3f WD |
283 | #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH |
284 | #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT | |
285 | #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET | |
286 | #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS | |
287 | ||
64e40d72 | 288 | #else /* CONFIG_VIDEO_BMP_LOGO */ |
4b248f3f WD |
289 | #define LINUX_LOGO_WIDTH 80 |
290 | #define LINUX_LOGO_HEIGHT 80 | |
291 | #define LINUX_LOGO_COLORS 214 | |
292 | #define LINUX_LOGO_LUT_OFFSET 0x20 | |
c609719b WD |
293 | #define __initdata |
294 | #include <linux_logo.h> | |
4b248f3f WD |
295 | #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH |
296 | #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT | |
297 | #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET | |
298 | #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS | |
64e40d72 | 299 | #endif /* CONFIG_VIDEO_BMP_LOGO */ |
4b248f3f WD |
300 | #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH) |
301 | #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2) | |
64e40d72 | 302 | #else /* CONFIG_VIDEO_LOGO */ |
4b248f3f WD |
303 | #define VIDEO_LOGO_WIDTH 0 |
304 | #define VIDEO_LOGO_HEIGHT 0 | |
64e40d72 | 305 | #endif /* CONFIG_VIDEO_LOGO */ |
4b248f3f WD |
306 | |
307 | #define VIDEO_COLS VIDEO_VISIBLE_COLS | |
308 | #define VIDEO_ROWS VIDEO_VISIBLE_ROWS | |
309 | #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) | |
310 | #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) | |
311 | #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) | |
312 | #define VIDEO_BURST_LEN (VIDEO_COLS/8) | |
313 | ||
314 | #ifdef CONFIG_VIDEO_LOGO | |
be129aa7 | 315 | #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT) |
c609719b | 316 | #else |
4b248f3f | 317 | #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT) |
c609719b WD |
318 | #endif |
319 | ||
4b248f3f WD |
320 | #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH) |
321 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN) | |
322 | #define CONSOLE_ROW_FIRST (video_console_address) | |
323 | #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE) | |
324 | #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE) | |
325 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) | |
326 | #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) | |
c609719b WD |
327 | |
328 | /* Macros */ | |
4b248f3f | 329 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
64e40d72 WD |
330 | #define SWAP16(x) ((((x) & 0x00ff) << 8) | \ |
331 | ((x) >> 8) \ | |
332 | ) | |
333 | #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \ | |
334 | (((x) & 0x0000ff00) << 8) | \ | |
335 | (((x) & 0x00ff0000) >> 8) | \ | |
336 | (((x) & 0xff000000) >> 24) \ | |
337 | ) | |
338 | #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \ | |
339 | (((x) & 0x0000ff00) >> 8) | \ | |
340 | (((x) & 0x00ff0000) << 8) | \ | |
341 | (((x) & 0xff000000) >> 8) \ | |
342 | ) | |
c609719b | 343 | #else |
64e40d72 WD |
344 | #define SWAP16(x) (x) |
345 | #define SWAP32(x) (x) | |
229b6dce | 346 | #if defined(VIDEO_FB_16BPP_WORD_SWAP) |
64e40d72 | 347 | #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16)) |
cc347801 | 348 | #else |
64e40d72 | 349 | #define SHORTSWAP32(x) (x) |
bed53753 | 350 | #endif |
c609719b WD |
351 | #endif |
352 | ||
c609719b | 353 | #ifdef CONFIG_CONSOLE_EXTRA_INFO |
64e40d72 WD |
354 | /* |
355 | * setup a board string: type, speed, etc. | |
356 | * | |
357 | * line_number: location to place info string beside logo | |
358 | * info: buffer for info string | |
359 | */ | |
360 | extern void video_get_info_str(int line_number, char *info); | |
c609719b WD |
361 | #endif |
362 | ||
363 | /* Locals */ | |
364 | static GraphicDevice *pGD; /* Pointer to Graphic array */ | |
365 | ||
64e40d72 | 366 | static void *video_fb_address; /* frame buffer address */ |
4b248f3f | 367 | static void *video_console_address; /* console buffer start address */ |
c609719b | 368 | |
be129aa7 MW |
369 | static int video_logo_height = VIDEO_LOGO_HEIGHT; |
370 | ||
a45adde9 AG |
371 | static int __maybe_unused cursor_state; |
372 | static int __maybe_unused old_col; | |
373 | static int __maybe_unused old_row; | |
03d31fcf | 374 | |
57912939 WD |
375 | static int console_col; /* cursor col */ |
376 | static int console_row; /* cursor row */ | |
c609719b | 377 | |
64e40d72 | 378 | static u32 eorx, fgx, bgx; /* color pats */ |
c609719b WD |
379 | |
380 | static const int video_font_draw_table8[] = { | |
64e40d72 WD |
381 | 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, |
382 | 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, | |
383 | 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, | |
384 | 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff | |
385 | }; | |
c609719b WD |
386 | |
387 | static const int video_font_draw_table15[] = { | |
64e40d72 WD |
388 | 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff |
389 | }; | |
c609719b WD |
390 | |
391 | static const int video_font_draw_table16[] = { | |
64e40d72 WD |
392 | 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff |
393 | }; | |
c609719b WD |
394 | |
395 | static const int video_font_draw_table24[16][3] = { | |
64e40d72 WD |
396 | {0x00000000, 0x00000000, 0x00000000}, |
397 | {0x00000000, 0x00000000, 0x00ffffff}, | |
398 | {0x00000000, 0x0000ffff, 0xff000000}, | |
399 | {0x00000000, 0x0000ffff, 0xffffffff}, | |
400 | {0x000000ff, 0xffff0000, 0x00000000}, | |
401 | {0x000000ff, 0xffff0000, 0x00ffffff}, | |
402 | {0x000000ff, 0xffffffff, 0xff000000}, | |
403 | {0x000000ff, 0xffffffff, 0xffffffff}, | |
404 | {0xffffff00, 0x00000000, 0x00000000}, | |
405 | {0xffffff00, 0x00000000, 0x00ffffff}, | |
406 | {0xffffff00, 0x0000ffff, 0xff000000}, | |
407 | {0xffffff00, 0x0000ffff, 0xffffffff}, | |
408 | {0xffffffff, 0xffff0000, 0x00000000}, | |
409 | {0xffffffff, 0xffff0000, 0x00ffffff}, | |
410 | {0xffffffff, 0xffffffff, 0xff000000}, | |
411 | {0xffffffff, 0xffffffff, 0xffffffff} | |
412 | }; | |
c609719b WD |
413 | |
414 | static const int video_font_draw_table32[16][4] = { | |
64e40d72 WD |
415 | {0x00000000, 0x00000000, 0x00000000, 0x00000000}, |
416 | {0x00000000, 0x00000000, 0x00000000, 0x00ffffff}, | |
417 | {0x00000000, 0x00000000, 0x00ffffff, 0x00000000}, | |
418 | {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff}, | |
419 | {0x00000000, 0x00ffffff, 0x00000000, 0x00000000}, | |
420 | {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff}, | |
421 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000}, | |
422 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff}, | |
423 | {0x00ffffff, 0x00000000, 0x00000000, 0x00000000}, | |
424 | {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff}, | |
425 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000}, | |
426 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff}, | |
427 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000}, | |
428 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff}, | |
429 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000}, | |
430 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff} | |
431 | }; | |
432 | ||
64e40d72 | 433 | static void video_drawchars(int xx, int yy, unsigned char *s, int count) |
c609719b | 434 | { |
4b248f3f WD |
435 | u8 *cdat, *dest, *dest0; |
436 | int rows, offset, c; | |
437 | ||
438 | offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE; | |
439 | dest0 = video_fb_address + offset; | |
440 | ||
441 | switch (VIDEO_DATA_FORMAT) { | |
442 | case GDF__8BIT_INDEX: | |
443 | case GDF__8BIT_332RGB: | |
444 | while (count--) { | |
445 | c = *s; | |
446 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
447 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 448 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
449 | u8 bits = *cdat++; |
450 | ||
64e40d72 WD |
451 | ((u32 *) dest)[0] = |
452 | (video_font_draw_table8[bits >> 4] & | |
453 | eorx) ^ bgx; | |
454 | ((u32 *) dest)[1] = | |
455 | (video_font_draw_table8[bits & 15] & | |
456 | eorx) ^ bgx; | |
4b248f3f WD |
457 | } |
458 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
459 | s++; | |
460 | } | |
461 | break; | |
c609719b | 462 | |
4b248f3f WD |
463 | case GDF_15BIT_555RGB: |
464 | while (count--) { | |
465 | c = *s; | |
466 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
467 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 468 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
469 | u8 bits = *cdat++; |
470 | ||
64e40d72 WD |
471 | ((u32 *) dest)[0] = |
472 | SHORTSWAP32((video_font_draw_table15 | |
473 | [bits >> 6] & eorx) ^ | |
474 | bgx); | |
475 | ((u32 *) dest)[1] = | |
476 | SHORTSWAP32((video_font_draw_table15 | |
477 | [bits >> 4 & 3] & eorx) ^ | |
478 | bgx); | |
479 | ((u32 *) dest)[2] = | |
480 | SHORTSWAP32((video_font_draw_table15 | |
481 | [bits >> 2 & 3] & eorx) ^ | |
482 | bgx); | |
483 | ((u32 *) dest)[3] = | |
484 | SHORTSWAP32((video_font_draw_table15 | |
485 | [bits & 3] & eorx) ^ | |
486 | bgx); | |
4b248f3f WD |
487 | } |
488 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
489 | s++; | |
490 | } | |
491 | break; | |
c609719b | 492 | |
4b248f3f WD |
493 | case GDF_16BIT_565RGB: |
494 | while (count--) { | |
495 | c = *s; | |
496 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
497 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 498 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
499 | u8 bits = *cdat++; |
500 | ||
64e40d72 WD |
501 | ((u32 *) dest)[0] = |
502 | SHORTSWAP32((video_font_draw_table16 | |
503 | [bits >> 6] & eorx) ^ | |
504 | bgx); | |
505 | ((u32 *) dest)[1] = | |
506 | SHORTSWAP32((video_font_draw_table16 | |
507 | [bits >> 4 & 3] & eorx) ^ | |
508 | bgx); | |
509 | ((u32 *) dest)[2] = | |
510 | SHORTSWAP32((video_font_draw_table16 | |
511 | [bits >> 2 & 3] & eorx) ^ | |
512 | bgx); | |
513 | ((u32 *) dest)[3] = | |
514 | SHORTSWAP32((video_font_draw_table16 | |
515 | [bits & 3] & eorx) ^ | |
516 | bgx); | |
4b248f3f WD |
517 | } |
518 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
519 | s++; | |
520 | } | |
521 | break; | |
c609719b | 522 | |
4b248f3f WD |
523 | case GDF_32BIT_X888RGB: |
524 | while (count--) { | |
525 | c = *s; | |
526 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
527 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 528 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
529 | u8 bits = *cdat++; |
530 | ||
64e40d72 WD |
531 | ((u32 *) dest)[0] = |
532 | SWAP32((video_font_draw_table32 | |
533 | [bits >> 4][0] & eorx) ^ bgx); | |
534 | ((u32 *) dest)[1] = | |
535 | SWAP32((video_font_draw_table32 | |
536 | [bits >> 4][1] & eorx) ^ bgx); | |
537 | ((u32 *) dest)[2] = | |
538 | SWAP32((video_font_draw_table32 | |
539 | [bits >> 4][2] & eorx) ^ bgx); | |
540 | ((u32 *) dest)[3] = | |
541 | SWAP32((video_font_draw_table32 | |
542 | [bits >> 4][3] & eorx) ^ bgx); | |
543 | ((u32 *) dest)[4] = | |
544 | SWAP32((video_font_draw_table32 | |
545 | [bits & 15][0] & eorx) ^ bgx); | |
546 | ((u32 *) dest)[5] = | |
547 | SWAP32((video_font_draw_table32 | |
548 | [bits & 15][1] & eorx) ^ bgx); | |
549 | ((u32 *) dest)[6] = | |
550 | SWAP32((video_font_draw_table32 | |
551 | [bits & 15][2] & eorx) ^ bgx); | |
552 | ((u32 *) dest)[7] = | |
553 | SWAP32((video_font_draw_table32 | |
554 | [bits & 15][3] & eorx) ^ bgx); | |
4b248f3f WD |
555 | } |
556 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
557 | s++; | |
558 | } | |
559 | break; | |
c609719b | 560 | |
4b248f3f WD |
561 | case GDF_24BIT_888RGB: |
562 | while (count--) { | |
563 | c = *s; | |
564 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
565 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 566 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
567 | u8 bits = *cdat++; |
568 | ||
64e40d72 WD |
569 | ((u32 *) dest)[0] = |
570 | (video_font_draw_table24[bits >> 4][0] | |
571 | & eorx) ^ bgx; | |
572 | ((u32 *) dest)[1] = | |
573 | (video_font_draw_table24[bits >> 4][1] | |
574 | & eorx) ^ bgx; | |
575 | ((u32 *) dest)[2] = | |
576 | (video_font_draw_table24[bits >> 4][2] | |
577 | & eorx) ^ bgx; | |
578 | ((u32 *) dest)[3] = | |
579 | (video_font_draw_table24[bits & 15][0] | |
580 | & eorx) ^ bgx; | |
581 | ((u32 *) dest)[4] = | |
582 | (video_font_draw_table24[bits & 15][1] | |
583 | & eorx) ^ bgx; | |
584 | ((u32 *) dest)[5] = | |
585 | (video_font_draw_table24[bits & 15][2] | |
586 | & eorx) ^ bgx; | |
4b248f3f WD |
587 | } |
588 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
589 | s++; | |
590 | } | |
591 | break; | |
8bde7f77 | 592 | } |
c609719b WD |
593 | } |
594 | ||
64e40d72 | 595 | static inline void video_drawstring(int xx, int yy, unsigned char *s) |
c609719b | 596 | { |
64e40d72 | 597 | video_drawchars(xx, yy, s, strlen((char *) s)); |
c609719b WD |
598 | } |
599 | ||
64e40d72 | 600 | static void video_putchar(int xx, int yy, unsigned char c) |
c609719b | 601 | { |
64e40d72 | 602 | video_drawchars(xx, yy + video_logo_height, &c, 1); |
c609719b WD |
603 | } |
604 | ||
c609719b | 605 | #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR) |
64e40d72 | 606 | static void video_set_cursor(void) |
c609719b | 607 | { |
03d31fcf GB |
608 | if (cursor_state) |
609 | console_cursor(0); | |
610 | console_cursor(1); | |
c609719b | 611 | } |
64e40d72 | 612 | |
a45adde9 AG |
613 | static void video_invertchar(int xx, int yy) |
614 | { | |
615 | int firstx = xx * VIDEO_PIXEL_SIZE; | |
616 | int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE; | |
617 | int firsty = yy * VIDEO_LINE_LEN; | |
618 | int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN; | |
619 | int x, y; | |
620 | for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) { | |
621 | for (x = firstx; x < lastx; x++) { | |
622 | u8 *dest = (u8 *)(video_fb_address) + x + y; | |
623 | *dest = ~*dest; | |
624 | } | |
625 | } | |
626 | } | |
03d31fcf | 627 | |
64e40d72 | 628 | void console_cursor(int state) |
c609719b | 629 | { |
c609719b | 630 | #ifdef CONFIG_CONSOLE_TIME |
4b248f3f WD |
631 | struct rtc_time tm; |
632 | char info[16]; | |
633 | ||
634 | /* time update only if cursor is on (faster scroll) */ | |
635 | if (state) { | |
64e40d72 WD |
636 | rtc_get(&tm); |
637 | ||
638 | sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min, | |
639 | tm.tm_sec); | |
640 | video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH, | |
641 | VIDEO_INFO_Y, (uchar *) info); | |
642 | ||
643 | sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon, | |
644 | tm.tm_year); | |
645 | video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH, | |
646 | VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT, | |
647 | (uchar *) info); | |
4b248f3f | 648 | } |
c609719b WD |
649 | #endif |
650 | ||
03d31fcf GB |
651 | if (cursor_state != state) { |
652 | if (cursor_state) { | |
653 | /* turn off the cursor */ | |
654 | video_invertchar(old_col * VIDEO_FONT_WIDTH, | |
655 | old_row * VIDEO_FONT_HEIGHT + | |
656 | video_logo_height); | |
657 | } else { | |
658 | /* turn off the cursor and record where it is */ | |
659 | video_invertchar(console_col * VIDEO_FONT_WIDTH, | |
660 | console_row * VIDEO_FONT_HEIGHT + | |
661 | video_logo_height); | |
662 | old_col = console_col; | |
663 | old_row = console_row; | |
664 | } | |
665 | cursor_state = state; | |
4b248f3f | 666 | } |
c609719b WD |
667 | } |
668 | #endif | |
669 | ||
c609719b | 670 | #ifndef VIDEO_HW_RECTFILL |
64e40d72 | 671 | static void memsetl(int *p, int c, int v) |
c609719b | 672 | { |
4b248f3f WD |
673 | while (c--) |
674 | *(p++) = v; | |
c609719b WD |
675 | } |
676 | #endif | |
677 | ||
c609719b | 678 | #ifndef VIDEO_HW_BITBLT |
64e40d72 | 679 | static void memcpyl(int *d, int *s, int c) |
c609719b | 680 | { |
4b248f3f WD |
681 | while (c--) |
682 | *(d++) = *(s++); | |
c609719b WD |
683 | } |
684 | #endif | |
685 | ||
90f60a81 PR |
686 | static void console_clear_line(int line, int begin, int end) |
687 | { | |
688 | #ifdef VIDEO_HW_RECTFILL | |
689 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ | |
690 | VIDEO_FONT_WIDTH * begin, /* dest pos x */ | |
691 | video_logo_height + | |
692 | VIDEO_FONT_HEIGHT * line, /* dest pos y */ | |
693 | VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */ | |
694 | VIDEO_FONT_HEIGHT, /* frame height */ | |
695 | bgx /* fill color */ | |
696 | ); | |
697 | #else | |
698 | if (begin == 0 && (end + 1) == CONSOLE_COLS) { | |
699 | memsetl(CONSOLE_ROW_FIRST + | |
700 | CONSOLE_ROW_SIZE * line, /* offset of row */ | |
701 | CONSOLE_ROW_SIZE >> 2, /* length of row */ | |
702 | bgx /* fill color */ | |
703 | ); | |
704 | } else { | |
705 | void *offset; | |
706 | int i, size; | |
707 | ||
708 | offset = CONSOLE_ROW_FIRST + | |
709 | CONSOLE_ROW_SIZE * line + /* offset of row */ | |
710 | VIDEO_FONT_WIDTH * | |
711 | VIDEO_PIXEL_SIZE * begin; /* offset of col */ | |
712 | size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1); | |
713 | size >>= 2; /* length to end for memsetl() */ | |
714 | /* fill at col offset of i'th line using bgx as fill color */ | |
715 | for (i = 0; i < VIDEO_FONT_HEIGHT; i++) | |
716 | memsetl(offset + i * VIDEO_LINE_LEN, size, bgx); | |
717 | } | |
718 | #endif | |
719 | } | |
720 | ||
64e40d72 | 721 | static void console_scrollup(void) |
c609719b | 722 | { |
4b248f3f | 723 | /* copy up rows ignoring the first one */ |
c609719b WD |
724 | |
725 | #ifdef VIDEO_HW_BITBLT | |
64e40d72 WD |
726 | video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
727 | 0, /* source pos x */ | |
728 | video_logo_height + | |
729 | VIDEO_FONT_HEIGHT, /* source pos y */ | |
730 | 0, /* dest pos x */ | |
731 | video_logo_height, /* dest pos y */ | |
732 | VIDEO_VISIBLE_COLS, /* frame width */ | |
733 | VIDEO_VISIBLE_ROWS | |
734 | - video_logo_height | |
735 | - VIDEO_FONT_HEIGHT /* frame height */ | |
4b248f3f | 736 | ); |
c609719b | 737 | #else |
64e40d72 WD |
738 | memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, |
739 | CONSOLE_SCROLL_SIZE >> 2); | |
c609719b | 740 | #endif |
4b248f3f | 741 | /* clear the last one */ |
90f60a81 | 742 | console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1); |
c609719b WD |
743 | } |
744 | ||
64e40d72 | 745 | static void console_back(void) |
c609719b | 746 | { |
65618636 | 747 | console_col--; |
4b248f3f WD |
748 | |
749 | if (console_col < 0) { | |
750 | console_col = CONSOLE_COLS - 1; | |
751 | console_row--; | |
752 | if (console_row < 0) | |
753 | console_row = 0; | |
754 | } | |
c609719b WD |
755 | } |
756 | ||
64e40d72 | 757 | static void console_newline(void) |
c609719b | 758 | { |
20c450ef | 759 | console_row++; |
4b248f3f WD |
760 | console_col = 0; |
761 | ||
762 | /* Check if we need to scroll the terminal */ | |
763 | if (console_row >= CONSOLE_ROWS) { | |
764 | /* Scroll everything up */ | |
64e40d72 | 765 | console_scrollup(); |
4b248f3f WD |
766 | |
767 | /* Decrement row number */ | |
768 | console_row--; | |
769 | } | |
c609719b WD |
770 | } |
771 | ||
64e40d72 | 772 | static void console_cr(void) |
20c450ef | 773 | { |
65618636 | 774 | console_col = 0; |
20c450ef AG |
775 | } |
776 | ||
64e40d72 | 777 | void video_putc(const char c) |
c609719b | 778 | { |
20c450ef AG |
779 | static int nl = 1; |
780 | ||
03d31fcf GB |
781 | CURSOR_OFF; |
782 | ||
4b248f3f | 783 | switch (c) { |
20c450ef | 784 | case 13: /* back to first column */ |
64e40d72 | 785 | console_cr(); |
4b248f3f | 786 | break; |
c609719b | 787 | |
4b248f3f | 788 | case '\n': /* next line */ |
20c450ef | 789 | if (console_col || (!console_col && nl)) |
64e40d72 | 790 | console_newline(); |
20c450ef | 791 | nl = 1; |
4b248f3f WD |
792 | break; |
793 | ||
794 | case 9: /* tab 8 */ | |
65618636 | 795 | console_col |= 0x0008; |
4b248f3f | 796 | console_col &= ~0x0007; |
c609719b | 797 | |
4b248f3f | 798 | if (console_col >= CONSOLE_COLS) |
64e40d72 | 799 | console_newline(); |
4b248f3f | 800 | break; |
c609719b | 801 | |
4b248f3f | 802 | case 8: /* backspace */ |
64e40d72 | 803 | console_back(); |
4b248f3f | 804 | break; |
c609719b | 805 | |
4b248f3f | 806 | default: /* draw the char */ |
64e40d72 WD |
807 | video_putchar(console_col * VIDEO_FONT_WIDTH, |
808 | console_row * VIDEO_FONT_HEIGHT, c); | |
4b248f3f | 809 | console_col++; |
c609719b | 810 | |
4b248f3f | 811 | /* check for newline */ |
20c450ef | 812 | if (console_col >= CONSOLE_COLS) { |
64e40d72 | 813 | console_newline(); |
20c450ef AG |
814 | nl = 0; |
815 | } | |
4b248f3f | 816 | } |
65618636 TT |
817 | CURSOR_SET; |
818 | } | |
c609719b | 819 | |
64e40d72 | 820 | void video_puts(const char *s) |
c609719b | 821 | { |
64e40d72 | 822 | int count = strlen(s); |
4b248f3f WD |
823 | |
824 | while (count--) | |
64e40d72 | 825 | video_putc(*s++); |
4b248f3f WD |
826 | } |
827 | ||
10543820 AG |
828 | /* |
829 | * Do not enforce drivers (or board code) to provide empty | |
830 | * video_set_lut() if they do not support 8 bpp format. | |
831 | * Implement weak default function instead. | |
832 | */ | |
64e40d72 WD |
833 | void __video_set_lut(unsigned int index, unsigned char r, |
834 | unsigned char g, unsigned char b) | |
10543820 AG |
835 | { |
836 | } | |
64e40d72 WD |
837 | |
838 | void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char) | |
839 | __attribute__ ((weak, alias("__video_set_lut"))); | |
10543820 | 840 | |
07d38a17 | 841 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
4b248f3f WD |
842 | |
843 | #define FILL_8BIT_332RGB(r,g,b) { \ | |
844 | *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \ | |
845 | fb ++; \ | |
846 | } | |
847 | ||
848 | #define FILL_15BIT_555RGB(r,g,b) { \ | |
64e40d72 WD |
849 | *(unsigned short *)fb = \ |
850 | SWAP16((unsigned short)(((r>>3)<<10) | \ | |
851 | ((g>>3)<<5) | \ | |
852 | (b>>3))); \ | |
4b248f3f WD |
853 | fb += 2; \ |
854 | } | |
855 | ||
856 | #define FILL_16BIT_565RGB(r,g,b) { \ | |
64e40d72 WD |
857 | *(unsigned short *)fb = \ |
858 | SWAP16((unsigned short)((((r)>>3)<<11)| \ | |
859 | (((g)>>2)<<5) | \ | |
860 | ((b)>>3))); \ | |
4b248f3f WD |
861 | fb += 2; \ |
862 | } | |
863 | ||
864 | #define FILL_32BIT_X888RGB(r,g,b) { \ | |
64e40d72 WD |
865 | *(unsigned long *)fb = \ |
866 | SWAP32((unsigned long)(((r<<16) | \ | |
867 | (g<<8) | \ | |
868 | b))); \ | |
4b248f3f WD |
869 | fb += 4; \ |
870 | } | |
871 | ||
872 | #ifdef VIDEO_FB_LITTLE_ENDIAN | |
873 | #define FILL_24BIT_888RGB(r,g,b) { \ | |
874 | fb[0] = b; \ | |
875 | fb[1] = g; \ | |
876 | fb[2] = r; \ | |
877 | fb += 3; \ | |
878 | } | |
879 | #else | |
880 | #define FILL_24BIT_888RGB(r,g,b) { \ | |
881 | fb[0] = r; \ | |
882 | fb[1] = g; \ | |
883 | fb[2] = b; \ | |
884 | fb += 3; \ | |
885 | } | |
886 | #endif | |
887 | ||
e84d568f | 888 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 | 889 | static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b) |
e84d568f | 890 | { |
64e40d72 WD |
891 | ushort *dst = (ushort *) fb; |
892 | ushort color = (ushort) (((r >> 3) << 10) | | |
893 | ((g >> 3) << 5) | | |
894 | (b >> 3)); | |
e84d568f AG |
895 | if (x & 1) |
896 | *(--dst) = color; | |
897 | else | |
898 | *(++dst) = color; | |
899 | } | |
900 | #endif | |
4b248f3f | 901 | |
d5011762 AG |
902 | /* |
903 | * RLE8 bitmap support | |
904 | */ | |
905 | ||
906 | #ifdef CONFIG_VIDEO_BMP_RLE8 | |
907 | /* Pre-calculated color table entry */ | |
908 | struct palette { | |
909 | union { | |
64e40d72 WD |
910 | unsigned short w; /* word */ |
911 | unsigned int dw; /* double word */ | |
912 | } ce; /* color entry */ | |
d5011762 AG |
913 | }; |
914 | ||
915 | /* | |
916 | * Helper to draw encoded/unencoded run. | |
917 | */ | |
64e40d72 WD |
918 | static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p, |
919 | int cnt, int enc) | |
d5011762 | 920 | { |
64e40d72 | 921 | ulong addr = (ulong) *fb; |
d5011762 AG |
922 | int *off; |
923 | int enc_off = 1; | |
924 | int i; | |
925 | ||
926 | /* | |
927 | * Setup offset of the color index in the bitmap. | |
928 | * Color index of encoded run is at offset 1. | |
929 | */ | |
930 | off = enc ? &enc_off : &i; | |
931 | ||
932 | switch (VIDEO_DATA_FORMAT) { | |
933 | case GDF__8BIT_INDEX: | |
934 | for (i = 0; i < cnt; i++) | |
64e40d72 | 935 | *(unsigned char *) addr++ = bm[*off]; |
d5011762 AG |
936 | break; |
937 | case GDF_15BIT_555RGB: | |
938 | case GDF_16BIT_565RGB: | |
939 | /* differences handled while pre-calculating palette */ | |
940 | for (i = 0; i < cnt; i++) { | |
64e40d72 | 941 | *(unsigned short *) addr = p[bm[*off]].ce.w; |
d5011762 AG |
942 | addr += 2; |
943 | } | |
944 | break; | |
945 | case GDF_32BIT_X888RGB: | |
946 | for (i = 0; i < cnt; i++) { | |
64e40d72 | 947 | *(unsigned long *) addr = p[bm[*off]].ce.dw; |
d5011762 AG |
948 | addr += 4; |
949 | } | |
950 | break; | |
951 | } | |
64e40d72 | 952 | *fb = (uchar *) addr; /* return modified address */ |
d5011762 AG |
953 | } |
954 | ||
64e40d72 WD |
955 | static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff, |
956 | int width, int height) | |
d5011762 AG |
957 | { |
958 | unsigned char *bm; | |
959 | unsigned char *fbp; | |
960 | unsigned int cnt, runlen; | |
961 | int decode = 1; | |
962 | int x, y, bpp, i, ncolors; | |
963 | struct palette p[256]; | |
964 | bmp_color_table_entry_t cte; | |
965 | int green_shift, red_off; | |
74446b63 AG |
966 | int limit = VIDEO_COLS * VIDEO_ROWS; |
967 | int pixels = 0; | |
d5011762 AG |
968 | |
969 | x = 0; | |
970 | y = __le32_to_cpu(img->header.height) - 1; | |
971 | ncolors = __le32_to_cpu(img->header.colors_used); | |
972 | bpp = VIDEO_PIXEL_SIZE; | |
64e40d72 WD |
973 | fbp = (unsigned char *) ((unsigned int) video_fb_address + |
974 | (((y + yoff) * VIDEO_COLS) + xoff) * bpp); | |
d5011762 | 975 | |
64e40d72 | 976 | bm = (uchar *) img + __le32_to_cpu(img->header.data_offset); |
d5011762 AG |
977 | |
978 | /* pre-calculate and setup palette */ | |
979 | switch (VIDEO_DATA_FORMAT) { | |
980 | case GDF__8BIT_INDEX: | |
981 | for (i = 0; i < ncolors; i++) { | |
982 | cte = img->color_table[i]; | |
64e40d72 | 983 | video_set_lut(i, cte.red, cte.green, cte.blue); |
d5011762 AG |
984 | } |
985 | break; | |
986 | case GDF_15BIT_555RGB: | |
987 | case GDF_16BIT_565RGB: | |
988 | if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) { | |
989 | green_shift = 3; | |
990 | red_off = 10; | |
991 | } else { | |
992 | green_shift = 2; | |
993 | red_off = 11; | |
994 | } | |
995 | for (i = 0; i < ncolors; i++) { | |
996 | cte = img->color_table[i]; | |
997 | p[i].ce.w = SWAP16((unsigned short) | |
998 | (((cte.red >> 3) << red_off) | | |
999 | ((cte.green >> green_shift) << 5) | | |
1000 | cte.blue >> 3)); | |
1001 | } | |
1002 | break; | |
1003 | case GDF_32BIT_X888RGB: | |
1004 | for (i = 0; i < ncolors; i++) { | |
1005 | cte = img->color_table[i]; | |
64e40d72 WD |
1006 | p[i].ce.dw = SWAP32((cte.red << 16) | |
1007 | (cte.green << 8) | | |
d5011762 AG |
1008 | cte.blue); |
1009 | } | |
1010 | break; | |
1011 | default: | |
1012 | printf("RLE Bitmap unsupported in video mode 0x%x\n", | |
64e40d72 | 1013 | VIDEO_DATA_FORMAT); |
d5011762 AG |
1014 | return -1; |
1015 | } | |
1016 | ||
1017 | while (decode) { | |
1018 | switch (bm[0]) { | |
1019 | case 0: | |
1020 | switch (bm[1]) { | |
1021 | case 0: | |
1022 | /* scan line end marker */ | |
1023 | bm += 2; | |
1024 | x = 0; | |
1025 | y--; | |
1026 | fbp = (unsigned char *) | |
64e40d72 | 1027 | ((unsigned int) video_fb_address + |
d5011762 AG |
1028 | (((y + yoff) * VIDEO_COLS) + |
1029 | xoff) * bpp); | |
1030 | continue; | |
1031 | case 1: | |
1032 | /* end of bitmap data marker */ | |
1033 | decode = 0; | |
1034 | break; | |
1035 | case 2: | |
1036 | /* run offset marker */ | |
1037 | x += bm[2]; | |
1038 | y -= bm[3]; | |
1039 | fbp = (unsigned char *) | |
64e40d72 | 1040 | ((unsigned int) video_fb_address + |
d5011762 AG |
1041 | (((y + yoff) * VIDEO_COLS) + |
1042 | x + xoff) * bpp); | |
1043 | bm += 4; | |
1044 | break; | |
1045 | default: | |
1046 | /* unencoded run */ | |
1047 | cnt = bm[1]; | |
1048 | runlen = cnt; | |
74446b63 AG |
1049 | pixels += cnt; |
1050 | if (pixels > limit) | |
1051 | goto error; | |
1052 | ||
d5011762 AG |
1053 | bm += 2; |
1054 | if (y < height) { | |
1055 | if (x >= width) { | |
1056 | x += runlen; | |
1057 | goto next_run; | |
1058 | } | |
1059 | if (x + runlen > width) | |
1060 | cnt = width - x; | |
64e40d72 | 1061 | draw_bitmap(&fbp, bm, p, cnt, 0); |
d5011762 AG |
1062 | x += runlen; |
1063 | } | |
1064 | next_run: | |
1065 | bm += runlen; | |
1066 | if (runlen & 1) | |
64e40d72 | 1067 | bm++; /* 0 padding if length is odd */ |
d5011762 AG |
1068 | } |
1069 | break; | |
1070 | default: | |
1071 | /* encoded run */ | |
74446b63 AG |
1072 | cnt = bm[0]; |
1073 | runlen = cnt; | |
1074 | pixels += cnt; | |
1075 | if (pixels > limit) | |
1076 | goto error; | |
1077 | ||
64e40d72 | 1078 | if (y < height) { /* only draw into visible area */ |
d5011762 AG |
1079 | if (x >= width) { |
1080 | x += runlen; | |
1081 | bm += 2; | |
1082 | continue; | |
1083 | } | |
1084 | if (x + runlen > width) | |
1085 | cnt = width - x; | |
64e40d72 | 1086 | draw_bitmap(&fbp, bm, p, cnt, 1); |
d5011762 AG |
1087 | x += runlen; |
1088 | } | |
1089 | bm += 2; | |
1090 | break; | |
1091 | } | |
1092 | } | |
1093 | return 0; | |
74446b63 AG |
1094 | error: |
1095 | printf("Error: Too much encoded pixel data, validate your bitmap\n"); | |
1096 | return -1; | |
d5011762 AG |
1097 | } |
1098 | #endif | |
1099 | ||
4b248f3f WD |
1100 | /* |
1101 | * Display the BMP file located at address bmp_image. | |
4b248f3f | 1102 | */ |
64e40d72 | 1103 | int video_display_bitmap(ulong bmp_image, int x, int y) |
4b248f3f WD |
1104 | { |
1105 | ushort xcount, ycount; | |
1106 | uchar *fb; | |
1107 | bmp_image_t *bmp = (bmp_image_t *) bmp_image; | |
1108 | uchar *bmap; | |
1109 | ushort padded_line; | |
1110 | unsigned long width, height, bpp; | |
1111 | unsigned colors; | |
1112 | unsigned long compression; | |
1113 | bmp_color_table_entry_t cte; | |
64e40d72 | 1114 | |
98f4a3df SR |
1115 | #ifdef CONFIG_VIDEO_BMP_GZIP |
1116 | unsigned char *dst = NULL; | |
1117 | ulong len; | |
1118 | #endif | |
4b248f3f | 1119 | |
64e40d72 | 1120 | WATCHDOG_RESET(); |
4b248f3f WD |
1121 | |
1122 | if (!((bmp->header.signature[0] == 'B') && | |
1123 | (bmp->header.signature[1] == 'M'))) { | |
98f4a3df SR |
1124 | |
1125 | #ifdef CONFIG_VIDEO_BMP_GZIP | |
1126 | /* | |
1127 | * Could be a gzipped bmp image, try to decrompress... | |
1128 | */ | |
6d0f6bcf JCPV |
1129 | len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE; |
1130 | dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE); | |
c29ab9d7 SR |
1131 | if (dst == NULL) { |
1132 | printf("Error: malloc in gunzip failed!\n"); | |
64e40d72 | 1133 | return 1; |
c29ab9d7 | 1134 | } |
64e40d72 WD |
1135 | if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, |
1136 | (uchar *) bmp_image, | |
1137 | &len) != 0) { | |
1138 | printf("Error: no valid bmp or bmp.gz image at %lx\n", | |
1139 | bmp_image); | |
98f4a3df SR |
1140 | free(dst); |
1141 | return 1; | |
1142 | } | |
6d0f6bcf | 1143 | if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) { |
64e40d72 WD |
1144 | printf("Image could be truncated " |
1145 | "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n"); | |
c29ab9d7 | 1146 | } |
98f4a3df SR |
1147 | |
1148 | /* | |
1149 | * Set addr to decompressed image | |
1150 | */ | |
64e40d72 | 1151 | bmp = (bmp_image_t *) dst; |
98f4a3df SR |
1152 | |
1153 | if (!((bmp->header.signature[0] == 'B') && | |
1154 | (bmp->header.signature[1] == 'M'))) { | |
64e40d72 WD |
1155 | printf("Error: no valid bmp.gz image at %lx\n", |
1156 | bmp_image); | |
a49e0d17 | 1157 | free(dst); |
98f4a3df SR |
1158 | return 1; |
1159 | } | |
1160 | #else | |
64e40d72 | 1161 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
4b248f3f | 1162 | return 1; |
98f4a3df | 1163 | #endif /* CONFIG_VIDEO_BMP_GZIP */ |
4b248f3f WD |
1164 | } |
1165 | ||
64e40d72 WD |
1166 | width = le32_to_cpu(bmp->header.width); |
1167 | height = le32_to_cpu(bmp->header.height); | |
1168 | bpp = le16_to_cpu(bmp->header.bit_count); | |
1169 | colors = le32_to_cpu(bmp->header.colors_used); | |
1170 | compression = le32_to_cpu(bmp->header.compression); | |
c609719b | 1171 | |
68da5b19 | 1172 | debug("Display-bmp: %ld x %ld with %d colors\n", |
64e40d72 | 1173 | width, height, colors); |
4b248f3f | 1174 | |
d5011762 AG |
1175 | if (compression != BMP_BI_RGB |
1176 | #ifdef CONFIG_VIDEO_BMP_RLE8 | |
1177 | && compression != BMP_BI_RLE8 | |
1178 | #endif | |
64e40d72 WD |
1179 | ) { |
1180 | printf("Error: compression type %ld not supported\n", | |
1181 | compression); | |
a49e0d17 MF |
1182 | #ifdef CONFIG_VIDEO_BMP_GZIP |
1183 | if (dst) | |
1184 | free(dst); | |
1185 | #endif | |
4b248f3f WD |
1186 | return 1; |
1187 | } | |
1188 | ||
1189 | padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3; | |
1190 | ||
1ca298ce MW |
1191 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
1192 | if (x == BMP_ALIGN_CENTER) | |
1193 | x = max(0, (VIDEO_VISIBLE_COLS - width) / 2); | |
1194 | else if (x < 0) | |
1195 | x = max(0, VIDEO_VISIBLE_COLS - width + x + 1); | |
1196 | ||
1197 | if (y == BMP_ALIGN_CENTER) | |
1198 | y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2); | |
1199 | else if (y < 0) | |
1200 | y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1); | |
1201 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ | |
1202 | ||
4b248f3f WD |
1203 | if ((x + width) > VIDEO_VISIBLE_COLS) |
1204 | width = VIDEO_VISIBLE_COLS - x; | |
1205 | if ((y + height) > VIDEO_VISIBLE_ROWS) | |
1206 | height = VIDEO_VISIBLE_ROWS - y; | |
1207 | ||
64e40d72 | 1208 | bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset); |
4b248f3f WD |
1209 | fb = (uchar *) (video_fb_address + |
1210 | ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) + | |
1211 | x * VIDEO_PIXEL_SIZE); | |
1212 | ||
d5011762 AG |
1213 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
1214 | if (compression == BMP_BI_RLE8) { | |
64e40d72 | 1215 | return display_rle8_bitmap(bmp, x, y, width, height); |
d5011762 AG |
1216 | } |
1217 | #endif | |
1218 | ||
68f6618b | 1219 | /* We handle only 4, 8, or 24 bpp bitmaps */ |
64e40d72 | 1220 | switch (le16_to_cpu(bmp->header.bit_count)) { |
68f6618b TT |
1221 | case 4: |
1222 | padded_line -= width / 2; | |
1223 | ycount = height; | |
1224 | ||
1225 | switch (VIDEO_DATA_FORMAT) { | |
1226 | case GDF_32BIT_X888RGB: | |
1227 | while (ycount--) { | |
64e40d72 | 1228 | WATCHDOG_RESET(); |
68f6618b TT |
1229 | /* |
1230 | * Don't assume that 'width' is an | |
1231 | * even number | |
1232 | */ | |
1233 | for (xcount = 0; xcount < width; xcount++) { | |
1234 | uchar idx; | |
1235 | ||
1236 | if (xcount & 1) { | |
1237 | idx = *bmap & 0xF; | |
1238 | bmap++; | |
1239 | } else | |
1240 | idx = *bmap >> 4; | |
1241 | cte = bmp->color_table[idx]; | |
1242 | FILL_32BIT_X888RGB(cte.red, cte.green, | |
1243 | cte.blue); | |
1244 | } | |
1245 | bmap += padded_line; | |
1246 | fb -= (VIDEO_VISIBLE_COLS + width) * | |
64e40d72 | 1247 | VIDEO_PIXEL_SIZE; |
68f6618b TT |
1248 | } |
1249 | break; | |
1250 | default: | |
1251 | puts("4bpp bitmap unsupported with current " | |
1252 | "video mode\n"); | |
1253 | break; | |
1254 | } | |
1255 | break; | |
1256 | ||
4b248f3f WD |
1257 | case 8: |
1258 | padded_line -= width; | |
1259 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) { | |
7c050f81 | 1260 | /* Copy colormap */ |
4b248f3f WD |
1261 | for (xcount = 0; xcount < colors; ++xcount) { |
1262 | cte = bmp->color_table[xcount]; | |
64e40d72 WD |
1263 | video_set_lut(xcount, cte.red, cte.green, |
1264 | cte.blue); | |
4b248f3f WD |
1265 | } |
1266 | } | |
1267 | ycount = height; | |
1268 | switch (VIDEO_DATA_FORMAT) { | |
1269 | case GDF__8BIT_INDEX: | |
1270 | while (ycount--) { | |
64e40d72 | 1271 | WATCHDOG_RESET(); |
4b248f3f WD |
1272 | xcount = width; |
1273 | while (xcount--) { | |
1274 | *fb++ = *bmap++; | |
1275 | } | |
1276 | bmap += padded_line; | |
64e40d72 WD |
1277 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1278 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1279 | } |
1280 | break; | |
1281 | case GDF__8BIT_332RGB: | |
1282 | while (ycount--) { | |
64e40d72 | 1283 | WATCHDOG_RESET(); |
4b248f3f WD |
1284 | xcount = width; |
1285 | while (xcount--) { | |
1286 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1287 | FILL_8BIT_332RGB(cte.red, cte.green, |
1288 | cte.blue); | |
4b248f3f WD |
1289 | } |
1290 | bmap += padded_line; | |
64e40d72 WD |
1291 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1292 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1293 | } |
1294 | break; | |
1295 | case GDF_15BIT_555RGB: | |
1296 | while (ycount--) { | |
e84d568f AG |
1297 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
1298 | int xpos = x; | |
1299 | #endif | |
64e40d72 | 1300 | WATCHDOG_RESET(); |
4b248f3f WD |
1301 | xcount = width; |
1302 | while (xcount--) { | |
1303 | cte = bmp->color_table[*bmap++]; | |
cc347801 | 1304 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 WD |
1305 | fill_555rgb_pswap(fb, xpos++, cte.red, |
1306 | cte.green, | |
1307 | cte.blue); | |
e84d568f | 1308 | fb += 2; |
cc347801 | 1309 | #else |
64e40d72 WD |
1310 | FILL_15BIT_555RGB(cte.red, cte.green, |
1311 | cte.blue); | |
e84d568f | 1312 | #endif |
4b248f3f WD |
1313 | } |
1314 | bmap += padded_line; | |
64e40d72 WD |
1315 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1316 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1317 | } |
1318 | break; | |
1319 | case GDF_16BIT_565RGB: | |
1320 | while (ycount--) { | |
64e40d72 | 1321 | WATCHDOG_RESET(); |
4b248f3f WD |
1322 | xcount = width; |
1323 | while (xcount--) { | |
1324 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1325 | FILL_16BIT_565RGB(cte.red, cte.green, |
1326 | cte.blue); | |
4b248f3f WD |
1327 | } |
1328 | bmap += padded_line; | |
64e40d72 WD |
1329 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1330 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1331 | } |
1332 | break; | |
1333 | case GDF_32BIT_X888RGB: | |
1334 | while (ycount--) { | |
64e40d72 | 1335 | WATCHDOG_RESET(); |
4b248f3f WD |
1336 | xcount = width; |
1337 | while (xcount--) { | |
1338 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1339 | FILL_32BIT_X888RGB(cte.red, cte.green, |
1340 | cte.blue); | |
4b248f3f WD |
1341 | } |
1342 | bmap += padded_line; | |
64e40d72 WD |
1343 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1344 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1345 | } |
1346 | break; | |
1347 | case GDF_24BIT_888RGB: | |
1348 | while (ycount--) { | |
64e40d72 | 1349 | WATCHDOG_RESET(); |
4b248f3f WD |
1350 | xcount = width; |
1351 | while (xcount--) { | |
1352 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1353 | FILL_24BIT_888RGB(cte.red, cte.green, |
1354 | cte.blue); | |
4b248f3f WD |
1355 | } |
1356 | bmap += padded_line; | |
64e40d72 WD |
1357 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1358 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1359 | } |
1360 | break; | |
1361 | } | |
1362 | break; | |
1363 | case 24: | |
1364 | padded_line -= 3 * width; | |
1365 | ycount = height; | |
1366 | switch (VIDEO_DATA_FORMAT) { | |
1367 | case GDF__8BIT_332RGB: | |
1368 | while (ycount--) { | |
64e40d72 | 1369 | WATCHDOG_RESET(); |
4b248f3f WD |
1370 | xcount = width; |
1371 | while (xcount--) { | |
64e40d72 WD |
1372 | FILL_8BIT_332RGB(bmap[2], bmap[1], |
1373 | bmap[0]); | |
4b248f3f WD |
1374 | bmap += 3; |
1375 | } | |
1376 | bmap += padded_line; | |
64e40d72 WD |
1377 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1378 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1379 | } |
1380 | break; | |
1381 | case GDF_15BIT_555RGB: | |
1382 | while (ycount--) { | |
e84d568f AG |
1383 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
1384 | int xpos = x; | |
1385 | #endif | |
64e40d72 | 1386 | WATCHDOG_RESET(); |
4b248f3f WD |
1387 | xcount = width; |
1388 | while (xcount--) { | |
cc347801 | 1389 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 WD |
1390 | fill_555rgb_pswap(fb, xpos++, bmap[2], |
1391 | bmap[1], bmap[0]); | |
e84d568f | 1392 | fb += 2; |
cc347801 | 1393 | #else |
64e40d72 WD |
1394 | FILL_15BIT_555RGB(bmap[2], bmap[1], |
1395 | bmap[0]); | |
e84d568f | 1396 | #endif |
4b248f3f WD |
1397 | bmap += 3; |
1398 | } | |
1399 | bmap += padded_line; | |
64e40d72 WD |
1400 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1401 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1402 | } |
1403 | break; | |
1404 | case GDF_16BIT_565RGB: | |
1405 | while (ycount--) { | |
64e40d72 | 1406 | WATCHDOG_RESET(); |
4b248f3f WD |
1407 | xcount = width; |
1408 | while (xcount--) { | |
64e40d72 WD |
1409 | FILL_16BIT_565RGB(bmap[2], bmap[1], |
1410 | bmap[0]); | |
4b248f3f WD |
1411 | bmap += 3; |
1412 | } | |
1413 | bmap += padded_line; | |
64e40d72 WD |
1414 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1415 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1416 | } |
1417 | break; | |
1418 | case GDF_32BIT_X888RGB: | |
1419 | while (ycount--) { | |
64e40d72 | 1420 | WATCHDOG_RESET(); |
4b248f3f WD |
1421 | xcount = width; |
1422 | while (xcount--) { | |
64e40d72 WD |
1423 | FILL_32BIT_X888RGB(bmap[2], bmap[1], |
1424 | bmap[0]); | |
4b248f3f WD |
1425 | bmap += 3; |
1426 | } | |
1427 | bmap += padded_line; | |
64e40d72 WD |
1428 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1429 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1430 | } |
1431 | break; | |
1432 | case GDF_24BIT_888RGB: | |
1433 | while (ycount--) { | |
64e40d72 | 1434 | WATCHDOG_RESET(); |
4b248f3f WD |
1435 | xcount = width; |
1436 | while (xcount--) { | |
64e40d72 WD |
1437 | FILL_24BIT_888RGB(bmap[2], bmap[1], |
1438 | bmap[0]); | |
4b248f3f WD |
1439 | bmap += 3; |
1440 | } | |
1441 | bmap += padded_line; | |
64e40d72 WD |
1442 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1443 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1444 | } |
1445 | break; | |
1446 | default: | |
64e40d72 WD |
1447 | printf("Error: 24 bits/pixel bitmap incompatible " |
1448 | "with current video mode\n"); | |
4b248f3f WD |
1449 | break; |
1450 | } | |
1451 | break; | |
1452 | default: | |
64e40d72 WD |
1453 | printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n", |
1454 | le16_to_cpu(bmp->header.bit_count)); | |
4b248f3f WD |
1455 | break; |
1456 | } | |
98f4a3df SR |
1457 | |
1458 | #ifdef CONFIG_VIDEO_BMP_GZIP | |
1459 | if (dst) { | |
1460 | free(dst); | |
1461 | } | |
1462 | #endif | |
1463 | ||
4b248f3f | 1464 | return (0); |
c609719b | 1465 | } |
07d38a17 | 1466 | #endif |
c609719b | 1467 | |
c609719b WD |
1468 | |
1469 | #ifdef CONFIG_VIDEO_LOGO | |
64e40d72 | 1470 | void logo_plot(void *screen, int width, int x, int y) |
c609719b | 1471 | { |
a6c7ad2f | 1472 | |
4b248f3f | 1473 | int xcount, i; |
64e40d72 | 1474 | int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE; |
be129aa7 | 1475 | int ycount = video_logo_height; |
4b248f3f WD |
1476 | unsigned char r, g, b, *logo_red, *logo_blue, *logo_green; |
1477 | unsigned char *source; | |
64e40d72 WD |
1478 | unsigned char *dest = (unsigned char *) screen + |
1479 | ((y * width * VIDEO_PIXEL_SIZE) + x * VIDEO_PIXEL_SIZE); | |
a6c7ad2f WD |
1480 | |
1481 | #ifdef CONFIG_VIDEO_BMP_LOGO | |
4b248f3f WD |
1482 | source = bmp_logo_bitmap; |
1483 | ||
7c050f81 | 1484 | /* Allocate temporary space for computing colormap */ |
64e40d72 WD |
1485 | logo_red = malloc(BMP_LOGO_COLORS); |
1486 | logo_green = malloc(BMP_LOGO_COLORS); | |
1487 | logo_blue = malloc(BMP_LOGO_COLORS); | |
7c050f81 | 1488 | /* Compute color map */ |
4b248f3f WD |
1489 | for (i = 0; i < VIDEO_LOGO_COLORS; i++) { |
1490 | logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4; | |
1491 | logo_green[i] = (bmp_logo_palette[i] & 0x00f0); | |
1492 | logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4; | |
1493 | } | |
a6c7ad2f | 1494 | #else |
4b248f3f WD |
1495 | source = linux_logo; |
1496 | logo_red = linux_logo_red; | |
1497 | logo_green = linux_logo_green; | |
1498 | logo_blue = linux_logo_blue; | |
a6c7ad2f | 1499 | #endif |
8bde7f77 | 1500 | |
4b248f3f WD |
1501 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) { |
1502 | for (i = 0; i < VIDEO_LOGO_COLORS; i++) { | |
64e40d72 WD |
1503 | video_set_lut(i + VIDEO_LOGO_LUT_OFFSET, |
1504 | logo_red[i], logo_green[i], | |
1505 | logo_blue[i]); | |
4b248f3f | 1506 | } |
8bde7f77 | 1507 | } |
c609719b | 1508 | |
4b248f3f | 1509 | while (ycount--) { |
e84d568f AG |
1510 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
1511 | int xpos = x; | |
1512 | #endif | |
4b248f3f WD |
1513 | xcount = VIDEO_LOGO_WIDTH; |
1514 | while (xcount--) { | |
1515 | r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET]; | |
1516 | g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET]; | |
1517 | b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET]; | |
1518 | ||
1519 | switch (VIDEO_DATA_FORMAT) { | |
1520 | case GDF__8BIT_INDEX: | |
1521 | *dest = *source; | |
1522 | break; | |
1523 | case GDF__8BIT_332RGB: | |
64e40d72 WD |
1524 | *dest = ((r >> 5) << 5) | |
1525 | ((g >> 5) << 2) | | |
1526 | (b >> 6); | |
4b248f3f WD |
1527 | break; |
1528 | case GDF_15BIT_555RGB: | |
cc347801 | 1529 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 | 1530 | fill_555rgb_pswap(dest, xpos++, r, g, b); |
cc347801 | 1531 | #else |
4b248f3f | 1532 | *(unsigned short *) dest = |
64e40d72 WD |
1533 | SWAP16((unsigned short) ( |
1534 | ((r >> 3) << 10) | | |
1535 | ((g >> 3) << 5) | | |
1536 | (b >> 3))); | |
bed53753 | 1537 | #endif |
4b248f3f WD |
1538 | break; |
1539 | case GDF_16BIT_565RGB: | |
1540 | *(unsigned short *) dest = | |
64e40d72 WD |
1541 | SWAP16((unsigned short) ( |
1542 | ((r >> 3) << 11) | | |
1543 | ((g >> 2) << 5) | | |
1544 | (b >> 3))); | |
4b248f3f WD |
1545 | break; |
1546 | case GDF_32BIT_X888RGB: | |
1547 | *(unsigned long *) dest = | |
64e40d72 WD |
1548 | SWAP32((unsigned long) ( |
1549 | (r << 16) | | |
1550 | (g << 8) | | |
1551 | b)); | |
4b248f3f WD |
1552 | break; |
1553 | case GDF_24BIT_888RGB: | |
c609719b | 1554 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
4b248f3f WD |
1555 | dest[0] = b; |
1556 | dest[1] = g; | |
1557 | dest[2] = r; | |
c609719b | 1558 | #else |
4b248f3f WD |
1559 | dest[0] = r; |
1560 | dest[1] = g; | |
1561 | dest[2] = b; | |
c609719b | 1562 | #endif |
4b248f3f WD |
1563 | break; |
1564 | } | |
1565 | source++; | |
1566 | dest += VIDEO_PIXEL_SIZE; | |
1567 | } | |
1568 | dest += skip; | |
8bde7f77 | 1569 | } |
a6c7ad2f | 1570 | #ifdef CONFIG_VIDEO_BMP_LOGO |
64e40d72 WD |
1571 | free(logo_red); |
1572 | free(logo_green); | |
1573 | free(logo_blue); | |
a6c7ad2f | 1574 | #endif |
c609719b WD |
1575 | } |
1576 | ||
64e40d72 | 1577 | static void *video_logo(void) |
c609719b | 1578 | { |
4b248f3f | 1579 | char info[128]; |
a9a62af1 WD |
1580 | int space, len; |
1581 | __maybe_unused int y_off = 0; | |
4b248f3f WD |
1582 | |
1583 | #ifdef CONFIG_SPLASH_SCREEN | |
1584 | char *s; | |
1585 | ulong addr; | |
1586 | ||
57912939 WD |
1587 | s = getenv("splashimage"); |
1588 | if (s != NULL) { | |
1ca298ce MW |
1589 | int x = 0, y = 0; |
1590 | ||
64e40d72 | 1591 | addr = simple_strtoul(s, NULL, 16); |
1ca298ce | 1592 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
57912939 WD |
1593 | s = getenv("splashpos"); |
1594 | if (s != NULL) { | |
1ca298ce MW |
1595 | if (s[0] == 'm') |
1596 | x = BMP_ALIGN_CENTER; | |
1597 | else | |
64e40d72 | 1598 | x = simple_strtol(s, NULL, 0); |
1ca298ce | 1599 | |
57912939 WD |
1600 | s = strchr(s + 1, ','); |
1601 | if (s != NULL) { | |
1ca298ce MW |
1602 | if (s[1] == 'm') |
1603 | y = BMP_ALIGN_CENTER; | |
1604 | else | |
64e40d72 | 1605 | y = simple_strtol(s + 1, NULL, 0); |
1ca298ce MW |
1606 | } |
1607 | } | |
1608 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ | |
4b248f3f | 1609 | |
64e40d72 | 1610 | if (video_display_bitmap(addr, x, y) == 0) { |
be129aa7 | 1611 | video_logo_height = 0; |
4b248f3f WD |
1612 | return ((void *) (video_fb_address)); |
1613 | } | |
1614 | } | |
1615 | #endif /* CONFIG_SPLASH_SCREEN */ | |
c609719b | 1616 | |
64e40d72 | 1617 | logo_plot(video_fb_address, VIDEO_COLS, 0, 0); |
4b248f3f | 1618 | |
64e40d72 | 1619 | sprintf(info, " %s", version_string); |
3dcbe628 AG |
1620 | |
1621 | space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH; | |
1622 | len = strlen(info); | |
1623 | ||
1624 | if (len > space) { | |
64e40d72 WD |
1625 | video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y, |
1626 | (uchar *) info, space); | |
1627 | video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH, | |
1628 | VIDEO_INFO_Y + VIDEO_FONT_HEIGHT, | |
1629 | (uchar *) info + space, len - space); | |
3dcbe628 AG |
1630 | y_off = 1; |
1631 | } else | |
64e40d72 | 1632 | video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info); |
c609719b WD |
1633 | |
1634 | #ifdef CONFIG_CONSOLE_EXTRA_INFO | |
4b248f3f | 1635 | { |
64e40d72 WD |
1636 | int i, n = |
1637 | ((video_logo_height - | |
1638 | VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT); | |
4b248f3f WD |
1639 | |
1640 | for (i = 1; i < n; i++) { | |
64e40d72 | 1641 | video_get_info_str(i, info); |
3dcbe628 AG |
1642 | if (!*info) |
1643 | continue; | |
1644 | ||
1645 | len = strlen(info); | |
1646 | if (len > space) { | |
64e40d72 WD |
1647 | video_drawchars(VIDEO_INFO_X, |
1648 | VIDEO_INFO_Y + | |
1649 | (i + y_off) * | |
1650 | VIDEO_FONT_HEIGHT, | |
1651 | (uchar *) info, space); | |
3dcbe628 | 1652 | y_off++; |
64e40d72 WD |
1653 | video_drawchars(VIDEO_INFO_X + |
1654 | VIDEO_FONT_WIDTH, | |
1655 | VIDEO_INFO_Y + | |
1656 | (i + y_off) * | |
1657 | VIDEO_FONT_HEIGHT, | |
1658 | (uchar *) info + space, | |
1659 | len - space); | |
3dcbe628 | 1660 | } else { |
64e40d72 WD |
1661 | video_drawstring(VIDEO_INFO_X, |
1662 | VIDEO_INFO_Y + | |
1663 | (i + y_off) * | |
1664 | VIDEO_FONT_HEIGHT, | |
1665 | (uchar *) info); | |
3dcbe628 | 1666 | } |
4b248f3f WD |
1667 | } |
1668 | } | |
c609719b WD |
1669 | #endif |
1670 | ||
be129aa7 | 1671 | return (video_fb_address + video_logo_height * VIDEO_LINE_LEN); |
c609719b WD |
1672 | } |
1673 | #endif | |
1674 | ||
64e40d72 | 1675 | static int video_init(void) |
c609719b | 1676 | { |
4b248f3f | 1677 | unsigned char color8; |
c609719b | 1678 | |
57912939 WD |
1679 | pGD = video_hw_init(); |
1680 | if (pGD == NULL) | |
4b248f3f | 1681 | return -1; |
c609719b | 1682 | |
4b248f3f | 1683 | video_fb_address = (void *) VIDEO_FB_ADRS; |
c609719b | 1684 | #ifdef CONFIG_VIDEO_HW_CURSOR |
64e40d72 | 1685 | video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT); |
c609719b WD |
1686 | #endif |
1687 | ||
4b248f3f WD |
1688 | /* Init drawing pats */ |
1689 | switch (VIDEO_DATA_FORMAT) { | |
1690 | case GDF__8BIT_INDEX: | |
64e40d72 WD |
1691 | video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, |
1692 | CONSOLE_FG_COL); | |
1693 | video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, | |
1694 | CONSOLE_BG_COL); | |
4b248f3f WD |
1695 | fgx = 0x01010101; |
1696 | bgx = 0x00000000; | |
1697 | break; | |
1698 | case GDF__8BIT_332RGB: | |
1699 | color8 = ((CONSOLE_FG_COL & 0xe0) | | |
64e40d72 WD |
1700 | ((CONSOLE_FG_COL >> 3) & 0x1c) | |
1701 | CONSOLE_FG_COL >> 6); | |
1702 | fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | | |
1703 | color8; | |
4b248f3f | 1704 | color8 = ((CONSOLE_BG_COL & 0xe0) | |
64e40d72 WD |
1705 | ((CONSOLE_BG_COL >> 3) & 0x1c) | |
1706 | CONSOLE_BG_COL >> 6); | |
1707 | bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | | |
1708 | color8; | |
4b248f3f WD |
1709 | break; |
1710 | case GDF_15BIT_555RGB: | |
1711 | fgx = (((CONSOLE_FG_COL >> 3) << 26) | | |
64e40d72 WD |
1712 | ((CONSOLE_FG_COL >> 3) << 21) | |
1713 | ((CONSOLE_FG_COL >> 3) << 16) | | |
1714 | ((CONSOLE_FG_COL >> 3) << 10) | | |
1715 | ((CONSOLE_FG_COL >> 3) << 5) | | |
1716 | (CONSOLE_FG_COL >> 3)); | |
4b248f3f | 1717 | bgx = (((CONSOLE_BG_COL >> 3) << 26) | |
64e40d72 WD |
1718 | ((CONSOLE_BG_COL >> 3) << 21) | |
1719 | ((CONSOLE_BG_COL >> 3) << 16) | | |
1720 | ((CONSOLE_BG_COL >> 3) << 10) | | |
1721 | ((CONSOLE_BG_COL >> 3) << 5) | | |
1722 | (CONSOLE_BG_COL >> 3)); | |
4b248f3f WD |
1723 | break; |
1724 | case GDF_16BIT_565RGB: | |
1725 | fgx = (((CONSOLE_FG_COL >> 3) << 27) | | |
64e40d72 WD |
1726 | ((CONSOLE_FG_COL >> 2) << 21) | |
1727 | ((CONSOLE_FG_COL >> 3) << 16) | | |
1728 | ((CONSOLE_FG_COL >> 3) << 11) | | |
1729 | ((CONSOLE_FG_COL >> 2) << 5) | | |
1730 | (CONSOLE_FG_COL >> 3)); | |
4b248f3f | 1731 | bgx = (((CONSOLE_BG_COL >> 3) << 27) | |
64e40d72 WD |
1732 | ((CONSOLE_BG_COL >> 2) << 21) | |
1733 | ((CONSOLE_BG_COL >> 3) << 16) | | |
1734 | ((CONSOLE_BG_COL >> 3) << 11) | | |
1735 | ((CONSOLE_BG_COL >> 2) << 5) | | |
1736 | (CONSOLE_BG_COL >> 3)); | |
4b248f3f WD |
1737 | break; |
1738 | case GDF_32BIT_X888RGB: | |
64e40d72 WD |
1739 | fgx = (CONSOLE_FG_COL << 16) | |
1740 | (CONSOLE_FG_COL << 8) | | |
1741 | CONSOLE_FG_COL; | |
1742 | bgx = (CONSOLE_BG_COL << 16) | | |
1743 | (CONSOLE_BG_COL << 8) | | |
1744 | CONSOLE_BG_COL; | |
4b248f3f WD |
1745 | break; |
1746 | case GDF_24BIT_888RGB: | |
64e40d72 WD |
1747 | fgx = (CONSOLE_FG_COL << 24) | |
1748 | (CONSOLE_FG_COL << 16) | | |
1749 | (CONSOLE_FG_COL << 8) | | |
1750 | CONSOLE_FG_COL; | |
1751 | bgx = (CONSOLE_BG_COL << 24) | | |
1752 | (CONSOLE_BG_COL << 16) | | |
1753 | (CONSOLE_BG_COL << 8) | | |
1754 | CONSOLE_BG_COL; | |
4b248f3f WD |
1755 | break; |
1756 | } | |
1757 | eorx = fgx ^ bgx; | |
c609719b WD |
1758 | |
1759 | #ifdef CONFIG_VIDEO_LOGO | |
4b248f3f | 1760 | /* Plot the logo and get start point of console */ |
72c65f6f | 1761 | debug("Video: Drawing the logo ...\n"); |
64e40d72 | 1762 | video_console_address = video_logo(); |
c609719b | 1763 | #else |
4b248f3f | 1764 | video_console_address = video_fb_address; |
c609719b WD |
1765 | #endif |
1766 | ||
4b248f3f WD |
1767 | /* Initialize the console */ |
1768 | console_col = 0; | |
1769 | console_row = 0; | |
c609719b | 1770 | |
4b248f3f | 1771 | return 0; |
c609719b WD |
1772 | } |
1773 | ||
6cc7ba9e WD |
1774 | /* |
1775 | * Implement a weak default function for boards that optionally | |
1776 | * need to skip the video initialization. | |
1777 | */ | |
1778 | int __board_video_skip(void) | |
1779 | { | |
1780 | /* As default, don't skip test */ | |
1781 | return 0; | |
1782 | } | |
6cc7ba9e | 1783 | |
64e40d72 WD |
1784 | int board_video_skip(void) |
1785 | __attribute__ ((weak, alias("__board_video_skip"))); | |
1786 | ||
1787 | int drv_video_init(void) | |
c609719b | 1788 | { |
4b248f3f | 1789 | int skip_dev_init; |
52cb4d4f | 1790 | struct stdio_dev console_dev; |
c609719b | 1791 | |
6cc7ba9e WD |
1792 | /* Check if video initialization should be skipped */ |
1793 | if (board_video_skip()) | |
1794 | return 0; | |
1795 | ||
81050926 | 1796 | /* Init video chip - returns with framebuffer cleared */ |
64e40d72 | 1797 | skip_dev_init = (video_init() == -1); |
81050926 | 1798 | |
f62f6469 | 1799 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
72c65f6f | 1800 | debug("KBD: Keyboard init ...\n"); |
f62f6469 WD |
1801 | skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1); |
1802 | #endif | |
1803 | ||
1804 | if (skip_dev_init) | |
1805 | return 0; | |
1806 | ||
1807 | /* Init vga device */ | |
64e40d72 WD |
1808 | memset(&console_dev, 0, sizeof(console_dev)); |
1809 | strcpy(console_dev.name, "vga"); | |
f62f6469 WD |
1810 | console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */ |
1811 | console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM; | |
1812 | console_dev.putc = video_putc; /* 'putc' function */ | |
1813 | console_dev.puts = video_puts; /* 'puts' function */ | |
1814 | console_dev.tstc = NULL; /* 'tstc' function */ | |
1815 | console_dev.getc = NULL; /* 'getc' function */ | |
1816 | ||
1817 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) | |
1818 | /* Also init console device */ | |
1819 | console_dev.flags |= DEV_FLAGS_INPUT; | |
1820 | console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */ | |
1821 | console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */ | |
c609719b | 1822 | #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */ |
f62f6469 | 1823 | |
64e40d72 | 1824 | if (stdio_register(&console_dev) != 0) |
f62f6469 WD |
1825 | return 0; |
1826 | ||
1827 | /* Return success */ | |
1828 | return 1; | |
c609719b | 1829 | } |