]>
Commit | Line | Data |
---|---|---|
c609719b WD |
1 | /* |
2 | * (C) Copyright 2002 ELTEC Elektronik AG | |
3 | * Frank Gottschling <fgottschling@eltec.de> | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
c609719b WD |
6 | */ |
7 | ||
8 | /* | |
9 | * cfb_console.c | |
10 | * | |
11 | * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel. | |
12 | * | |
13 | * At the moment only the 8x16 font is tested and the font fore- and | |
14 | * background color is limited to black/white/gray colors. The Linux | |
15 | * logo can be placed in the upper left corner and additional board | |
64e40d72 | 16 | * information strings (that normally goes to serial port) can be drawn. |
c609719b WD |
17 | * |
18 | * The console driver can use the standard PC keyboard interface (i8042) | |
19 | * for character input. Character output goes to a memory mapped video | |
20 | * framebuffer with little or big-endian organisation. | |
21 | * With environment setting 'console=serial' the console i/o can be | |
22 | * forced to serial port. | |
64e40d72 WD |
23 | * |
24 | * The driver uses graphic specific defines/parameters/functions: | |
25 | * | |
26 | * (for SMI LynxE graphic chip) | |
27 | * | |
28 | * CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810 | |
29 | * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian | |
30 | * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill | |
31 | * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt | |
32 | * | |
33 | * Console Parameters are set by graphic drivers global struct: | |
34 | * | |
35 | * VIDEO_VISIBLE_COLS - x resolution | |
36 | * VIDEO_VISIBLE_ROWS - y resolution | |
37 | * VIDEO_PIXEL_SIZE - storage size in byte per pixel | |
38 | * VIDEO_DATA_FORMAT - graphical data format GDF | |
39 | * VIDEO_FB_ADRS - start of video memory | |
40 | * | |
41 | * CONFIG_I8042_KBD - AT Keyboard driver for i8042 | |
42 | * VIDEO_KBD_INIT_FCT - init function for keyboard | |
43 | * VIDEO_TSTC_FCT - keyboard_tstc function | |
44 | * VIDEO_GETC_FCT - keyboard_getc function | |
45 | * | |
46 | * CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with | |
47 | * delay loop in VIDEO_TSTC_FCT (i8042) | |
48 | * | |
49 | * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate | |
50 | * CONFIG_CONSOLE_TIME - display time/date in upper right | |
51 | * corner, needs CONFIG_CMD_DATE and | |
52 | * CONFIG_CONSOLE_CURSOR | |
1e681f9a BR |
53 | * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner. |
54 | * Use CONFIG_SPLASH_SCREEN_ALIGN with | |
55 | * environment variable "splashpos" to place | |
56 | * the logo on other position. In this case | |
57 | * no CONSOLE_EXTRA_INFO is possible. | |
64e40d72 WD |
58 | * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo |
59 | * CONFIG_CONSOLE_EXTRA_INFO - display additional board information | |
60 | * strings that normaly goes to serial | |
61 | * port. This define requires a board | |
62 | * specific function: | |
63 | * video_drawstring (VIDEO_INFO_X, | |
64 | * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT, | |
65 | * info); | |
66 | * that fills a info buffer at i=row. | |
67 | * s.a: board/eltec/bab7xx. | |
68 | * CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be | |
69 | * initialized as an output only device. | |
70 | * The Keyboard driver will not be | |
71 | * set-up. This may be used, if you have | |
72 | * no or more than one Keyboard devices | |
73 | * (USB Keyboard, AT Keyboard). | |
74 | * | |
75 | * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last | |
76 | * character. No blinking is provided. | |
77 | * Uses the macros CURSOR_SET and | |
78 | * CURSOR_OFF. | |
79 | * | |
80 | * CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability | |
81 | * of the graphic chip. Uses the macro | |
82 | * CURSOR_SET. ATTENTION: If booting an | |
83 | * OS, the display driver must disable | |
84 | * the hardware register of the graphic | |
85 | * chip. Otherwise a blinking field is | |
86 | * displayed. | |
87 | */ | |
c609719b WD |
88 | |
89 | #include <common.h> | |
09c2e90c | 90 | #include <version.h> |
a6c7ad2f | 91 | #include <malloc.h> |
a9a62af1 | 92 | #include <linux/compiler.h> |
a6c7ad2f | 93 | |
64e40d72 WD |
94 | /* |
95 | * Console device defines with SMI graphic | |
96 | * Any other graphic must change this section | |
97 | */ | |
c609719b | 98 | |
4b248f3f | 99 | #ifdef CONFIG_VIDEO_SMI_LYNXEM |
c609719b WD |
100 | |
101 | #define VIDEO_FB_LITTLE_ENDIAN | |
102 | #define VIDEO_HW_RECTFILL | |
103 | #define VIDEO_HW_BITBLT | |
104 | #endif | |
105 | ||
64e40d72 WD |
106 | /* |
107 | * Defines for the CT69000 driver | |
108 | */ | |
4b248f3f | 109 | #ifdef CONFIG_VIDEO_CT69000 |
c609719b WD |
110 | |
111 | #define VIDEO_FB_LITTLE_ENDIAN | |
112 | #define VIDEO_HW_RECTFILL | |
113 | #define VIDEO_HW_BITBLT | |
114 | #endif | |
115 | ||
64e40d72 WD |
116 | /* |
117 | * Defines for the SED13806 driver | |
118 | */ | |
a6c7ad2f WD |
119 | #ifdef CONFIG_VIDEO_SED13806 |
120 | ||
89394047 | 121 | #ifndef CONFIG_TOTAL5200 |
a6c7ad2f | 122 | #define VIDEO_FB_LITTLE_ENDIAN |
89394047 | 123 | #endif |
a6c7ad2f WD |
124 | #define VIDEO_HW_RECTFILL |
125 | #define VIDEO_HW_BITBLT | |
126 | #endif | |
127 | ||
64e40d72 WD |
128 | /* |
129 | * Defines for the SED13806 driver | |
130 | */ | |
98f4a3df SR |
131 | #ifdef CONFIG_VIDEO_SM501 |
132 | ||
133 | #ifdef CONFIG_HH405 | |
134 | #define VIDEO_FB_LITTLE_ENDIAN | |
135 | #endif | |
136 | #endif | |
137 | ||
fb8ddc24 MV |
138 | #ifdef CONFIG_VIDEO_MXS |
139 | #define VIDEO_FB_16BPP_WORD_SWAP | |
140 | #endif | |
141 | ||
64e40d72 WD |
142 | /* |
143 | * Defines for the MB862xx driver | |
144 | */ | |
bed53753 AG |
145 | #ifdef CONFIG_VIDEO_MB862xx |
146 | ||
147 | #ifdef CONFIG_VIDEO_CORALP | |
148 | #define VIDEO_FB_LITTLE_ENDIAN | |
149 | #endif | |
5d16ca87 | 150 | #ifdef CONFIG_VIDEO_MB862xx_ACCEL |
bed53753 AG |
151 | #define VIDEO_HW_RECTFILL |
152 | #define VIDEO_HW_BITBLT | |
153 | #endif | |
5d16ca87 | 154 | #endif |
bed53753 | 155 | |
62a22dca HR |
156 | /* |
157 | * Defines for the i.MX31 driver (mx3fb.c) | |
158 | */ | |
695af9ab | 159 | #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3) |
62a22dca HR |
160 | #define VIDEO_FB_16BPP_WORD_SWAP |
161 | #endif | |
162 | ||
64e40d72 WD |
163 | /* |
164 | * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc. | |
165 | */ | |
c609719b WD |
166 | #include <video_fb.h> |
167 | ||
dd4425e8 RW |
168 | #include <splash.h> |
169 | ||
64e40d72 WD |
170 | /* |
171 | * some Macros | |
172 | */ | |
4b248f3f WD |
173 | #define VIDEO_VISIBLE_COLS (pGD->winSizeX) |
174 | #define VIDEO_VISIBLE_ROWS (pGD->winSizeY) | |
175 | #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP) | |
176 | #define VIDEO_DATA_FORMAT (pGD->gdfIndex) | |
177 | #define VIDEO_FB_ADRS (pGD->frameAdrs) | |
c609719b | 178 | |
64e40d72 WD |
179 | /* |
180 | * Console device defines with i8042 keyboard controller | |
181 | * Any other keyboard controller must change this section | |
182 | */ | |
c609719b | 183 | |
4b248f3f | 184 | #ifdef CONFIG_I8042_KBD |
c609719b WD |
185 | #include <i8042.h> |
186 | ||
4b248f3f WD |
187 | #define VIDEO_KBD_INIT_FCT i8042_kbd_init() |
188 | #define VIDEO_TSTC_FCT i8042_tstc | |
189 | #define VIDEO_GETC_FCT i8042_getc | |
c609719b WD |
190 | #endif |
191 | ||
64e40d72 WD |
192 | /* |
193 | * Console device | |
194 | */ | |
c609719b WD |
195 | |
196 | #include <version.h> | |
197 | #include <linux/types.h> | |
52cb4d4f | 198 | #include <stdio_dev.h> |
c609719b | 199 | #include <video_font.h> |
d3983ee8 | 200 | #include <video_font_data.h> |
c609719b | 201 | |
ddb5d86f JL |
202 | #if defined(CONFIG_CMD_DATE) |
203 | #include <rtc.h> | |
c609719b WD |
204 | #endif |
205 | ||
07d38a17 | 206 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
4b248f3f WD |
207 | #include <watchdog.h> |
208 | #include <bmp_layout.h> | |
ff8fb56b | 209 | #include <splash.h> |
07d38a17 | 210 | #endif |
4b248f3f | 211 | |
64e40d72 WD |
212 | /* |
213 | * Cursor definition: | |
214 | * CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/input/i8042.c) | |
215 | * to let the cursor blink. Uses the macros | |
216 | * CURSOR_OFF and CURSOR_ON. | |
217 | * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No | |
218 | * blinking is provided. Uses the macros CURSOR_SET | |
219 | * and CURSOR_OFF. | |
220 | * CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the | |
221 | * graphic chip. Uses the macro CURSOR_SET. | |
222 | * ATTENTION: If booting an OS, the display driver | |
223 | * must disable the hardware register of the graphic | |
224 | * chip. Otherwise a blinking field is displayed | |
225 | */ | |
c609719b WD |
226 | #if !defined(CONFIG_CONSOLE_CURSOR) && \ |
227 | !defined(CONFIG_VIDEO_SW_CURSOR) && \ | |
228 | !defined(CONFIG_VIDEO_HW_CURSOR) | |
229 | /* no Cursor defined */ | |
230 | #define CURSOR_ON | |
231 | #define CURSOR_OFF | |
232 | #define CURSOR_SET | |
233 | #endif | |
234 | ||
03d31fcf GB |
235 | #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR) |
236 | #if defined(CURSOR_ON) || \ | |
237 | (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR)) | |
64e40d72 WD |
238 | #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \ |
239 | or CONFIG_VIDEO_HW_CURSOR can be defined | |
c609719b | 240 | #endif |
64e40d72 WD |
241 | void console_cursor(int state); |
242 | ||
65618636 TT |
243 | #define CURSOR_ON console_cursor(1) |
244 | #define CURSOR_OFF console_cursor(0) | |
03d31fcf GB |
245 | #define CURSOR_SET video_set_cursor() |
246 | #endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */ | |
247 | ||
248 | #ifdef CONFIG_CONSOLE_CURSOR | |
249 | #ifndef CONFIG_CONSOLE_TIME | |
250 | #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME | |
251 | #endif | |
c609719b | 252 | #ifndef CONFIG_I8042_KBD |
7817cb20 | 253 | #warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c |
c609719b | 254 | #endif |
c609719b WD |
255 | #endif /* CONFIG_CONSOLE_CURSOR */ |
256 | ||
c609719b WD |
257 | |
258 | #ifdef CONFIG_VIDEO_HW_CURSOR | |
4b248f3f | 259 | #ifdef CURSOR_ON |
64e40d72 WD |
260 | #error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \ |
261 | or CONFIG_VIDEO_HW_CURSOR can be defined | |
c609719b WD |
262 | #endif |
263 | #define CURSOR_ON | |
264 | #define CURSOR_OFF | |
265 | #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \ | |
65618636 | 266 | (console_row * VIDEO_FONT_HEIGHT) + video_logo_height) |
64e40d72 | 267 | #endif /* CONFIG_VIDEO_HW_CURSOR */ |
c609719b | 268 | |
4b248f3f WD |
269 | #ifdef CONFIG_VIDEO_LOGO |
270 | #ifdef CONFIG_VIDEO_BMP_LOGO | |
a6c7ad2f | 271 | #include <bmp_logo.h> |
c270730f | 272 | #include <bmp_logo_data.h> |
4b248f3f WD |
273 | #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH |
274 | #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT | |
275 | #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET | |
276 | #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS | |
277 | ||
64e40d72 | 278 | #else /* CONFIG_VIDEO_BMP_LOGO */ |
4b248f3f WD |
279 | #define LINUX_LOGO_WIDTH 80 |
280 | #define LINUX_LOGO_HEIGHT 80 | |
281 | #define LINUX_LOGO_COLORS 214 | |
282 | #define LINUX_LOGO_LUT_OFFSET 0x20 | |
c609719b WD |
283 | #define __initdata |
284 | #include <linux_logo.h> | |
4b248f3f WD |
285 | #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH |
286 | #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT | |
287 | #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET | |
288 | #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS | |
64e40d72 | 289 | #endif /* CONFIG_VIDEO_BMP_LOGO */ |
4b248f3f WD |
290 | #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH) |
291 | #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2) | |
64e40d72 | 292 | #else /* CONFIG_VIDEO_LOGO */ |
4b248f3f WD |
293 | #define VIDEO_LOGO_WIDTH 0 |
294 | #define VIDEO_LOGO_HEIGHT 0 | |
64e40d72 | 295 | #endif /* CONFIG_VIDEO_LOGO */ |
4b248f3f WD |
296 | |
297 | #define VIDEO_COLS VIDEO_VISIBLE_COLS | |
298 | #define VIDEO_ROWS VIDEO_VISIBLE_ROWS | |
299 | #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) | |
300 | #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) | |
301 | #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) | |
302 | #define VIDEO_BURST_LEN (VIDEO_COLS/8) | |
303 | ||
304 | #ifdef CONFIG_VIDEO_LOGO | |
be129aa7 | 305 | #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT) |
c609719b | 306 | #else |
4b248f3f | 307 | #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT) |
c609719b WD |
308 | #endif |
309 | ||
4b248f3f WD |
310 | #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH) |
311 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN) | |
312 | #define CONSOLE_ROW_FIRST (video_console_address) | |
313 | #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE) | |
314 | #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE) | |
315 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) | |
316 | #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) | |
c609719b WD |
317 | |
318 | /* Macros */ | |
4b248f3f | 319 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
64e40d72 WD |
320 | #define SWAP16(x) ((((x) & 0x00ff) << 8) | \ |
321 | ((x) >> 8) \ | |
322 | ) | |
323 | #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \ | |
324 | (((x) & 0x0000ff00) << 8) | \ | |
325 | (((x) & 0x00ff0000) >> 8) | \ | |
326 | (((x) & 0xff000000) >> 24) \ | |
327 | ) | |
328 | #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \ | |
329 | (((x) & 0x0000ff00) >> 8) | \ | |
330 | (((x) & 0x00ff0000) << 8) | \ | |
331 | (((x) & 0xff000000) >> 8) \ | |
332 | ) | |
c609719b | 333 | #else |
64e40d72 WD |
334 | #define SWAP16(x) (x) |
335 | #define SWAP32(x) (x) | |
229b6dce | 336 | #if defined(VIDEO_FB_16BPP_WORD_SWAP) |
64e40d72 | 337 | #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16)) |
cc347801 | 338 | #else |
64e40d72 | 339 | #define SHORTSWAP32(x) (x) |
bed53753 | 340 | #endif |
c609719b WD |
341 | #endif |
342 | ||
c609719b | 343 | #ifdef CONFIG_CONSOLE_EXTRA_INFO |
64e40d72 WD |
344 | /* |
345 | * setup a board string: type, speed, etc. | |
346 | * | |
347 | * line_number: location to place info string beside logo | |
348 | * info: buffer for info string | |
349 | */ | |
350 | extern void video_get_info_str(int line_number, char *info); | |
c609719b WD |
351 | #endif |
352 | ||
bfd4be80 AG |
353 | DECLARE_GLOBAL_DATA_PTR; |
354 | ||
c609719b WD |
355 | /* Locals */ |
356 | static GraphicDevice *pGD; /* Pointer to Graphic array */ | |
357 | ||
64e40d72 | 358 | static void *video_fb_address; /* frame buffer address */ |
4b248f3f | 359 | static void *video_console_address; /* console buffer start address */ |
c609719b | 360 | |
be129aa7 MW |
361 | static int video_logo_height = VIDEO_LOGO_HEIGHT; |
362 | ||
a45adde9 AG |
363 | static int __maybe_unused cursor_state; |
364 | static int __maybe_unused old_col; | |
365 | static int __maybe_unused old_row; | |
03d31fcf | 366 | |
57912939 WD |
367 | static int console_col; /* cursor col */ |
368 | static int console_row; /* cursor row */ | |
c609719b | 369 | |
64e40d72 | 370 | static u32 eorx, fgx, bgx; /* color pats */ |
c609719b | 371 | |
bfd4be80 AG |
372 | static int cfb_do_flush_cache; |
373 | ||
33a35bbb PR |
374 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
375 | static char ansi_buf[10]; | |
376 | static int ansi_buf_size; | |
377 | static int ansi_colors_need_revert; | |
378 | static int ansi_cursor_hidden; | |
379 | #endif | |
380 | ||
c609719b | 381 | static const int video_font_draw_table8[] = { |
64e40d72 WD |
382 | 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, |
383 | 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, | |
384 | 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, | |
385 | 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff | |
386 | }; | |
c609719b WD |
387 | |
388 | static const int video_font_draw_table15[] = { | |
64e40d72 WD |
389 | 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff |
390 | }; | |
c609719b WD |
391 | |
392 | static const int video_font_draw_table16[] = { | |
64e40d72 WD |
393 | 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff |
394 | }; | |
c609719b WD |
395 | |
396 | static const int video_font_draw_table24[16][3] = { | |
64e40d72 WD |
397 | {0x00000000, 0x00000000, 0x00000000}, |
398 | {0x00000000, 0x00000000, 0x00ffffff}, | |
399 | {0x00000000, 0x0000ffff, 0xff000000}, | |
400 | {0x00000000, 0x0000ffff, 0xffffffff}, | |
401 | {0x000000ff, 0xffff0000, 0x00000000}, | |
402 | {0x000000ff, 0xffff0000, 0x00ffffff}, | |
403 | {0x000000ff, 0xffffffff, 0xff000000}, | |
404 | {0x000000ff, 0xffffffff, 0xffffffff}, | |
405 | {0xffffff00, 0x00000000, 0x00000000}, | |
406 | {0xffffff00, 0x00000000, 0x00ffffff}, | |
407 | {0xffffff00, 0x0000ffff, 0xff000000}, | |
408 | {0xffffff00, 0x0000ffff, 0xffffffff}, | |
409 | {0xffffffff, 0xffff0000, 0x00000000}, | |
410 | {0xffffffff, 0xffff0000, 0x00ffffff}, | |
411 | {0xffffffff, 0xffffffff, 0xff000000}, | |
412 | {0xffffffff, 0xffffffff, 0xffffffff} | |
413 | }; | |
c609719b WD |
414 | |
415 | static const int video_font_draw_table32[16][4] = { | |
64e40d72 WD |
416 | {0x00000000, 0x00000000, 0x00000000, 0x00000000}, |
417 | {0x00000000, 0x00000000, 0x00000000, 0x00ffffff}, | |
418 | {0x00000000, 0x00000000, 0x00ffffff, 0x00000000}, | |
419 | {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff}, | |
420 | {0x00000000, 0x00ffffff, 0x00000000, 0x00000000}, | |
421 | {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff}, | |
422 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000}, | |
423 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff}, | |
424 | {0x00ffffff, 0x00000000, 0x00000000, 0x00000000}, | |
425 | {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff}, | |
426 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000}, | |
427 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff}, | |
428 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000}, | |
429 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff}, | |
430 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000}, | |
431 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff} | |
432 | }; | |
433 | ||
64e40d72 | 434 | static void video_drawchars(int xx, int yy, unsigned char *s, int count) |
c609719b | 435 | { |
4b248f3f WD |
436 | u8 *cdat, *dest, *dest0; |
437 | int rows, offset, c; | |
438 | ||
439 | offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE; | |
440 | dest0 = video_fb_address + offset; | |
441 | ||
442 | switch (VIDEO_DATA_FORMAT) { | |
443 | case GDF__8BIT_INDEX: | |
444 | case GDF__8BIT_332RGB: | |
445 | while (count--) { | |
446 | c = *s; | |
447 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
448 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 449 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
450 | u8 bits = *cdat++; |
451 | ||
64e40d72 WD |
452 | ((u32 *) dest)[0] = |
453 | (video_font_draw_table8[bits >> 4] & | |
454 | eorx) ^ bgx; | |
455 | ((u32 *) dest)[1] = | |
456 | (video_font_draw_table8[bits & 15] & | |
457 | eorx) ^ bgx; | |
4b248f3f WD |
458 | } |
459 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
460 | s++; | |
461 | } | |
462 | break; | |
c609719b | 463 | |
4b248f3f WD |
464 | case GDF_15BIT_555RGB: |
465 | while (count--) { | |
466 | c = *s; | |
467 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
468 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 469 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
470 | u8 bits = *cdat++; |
471 | ||
64e40d72 WD |
472 | ((u32 *) dest)[0] = |
473 | SHORTSWAP32((video_font_draw_table15 | |
474 | [bits >> 6] & eorx) ^ | |
475 | bgx); | |
476 | ((u32 *) dest)[1] = | |
477 | SHORTSWAP32((video_font_draw_table15 | |
478 | [bits >> 4 & 3] & eorx) ^ | |
479 | bgx); | |
480 | ((u32 *) dest)[2] = | |
481 | SHORTSWAP32((video_font_draw_table15 | |
482 | [bits >> 2 & 3] & eorx) ^ | |
483 | bgx); | |
484 | ((u32 *) dest)[3] = | |
485 | SHORTSWAP32((video_font_draw_table15 | |
486 | [bits & 3] & eorx) ^ | |
487 | bgx); | |
4b248f3f WD |
488 | } |
489 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
490 | s++; | |
491 | } | |
492 | break; | |
c609719b | 493 | |
4b248f3f WD |
494 | case GDF_16BIT_565RGB: |
495 | while (count--) { | |
496 | c = *s; | |
497 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
498 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 499 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
500 | u8 bits = *cdat++; |
501 | ||
64e40d72 WD |
502 | ((u32 *) dest)[0] = |
503 | SHORTSWAP32((video_font_draw_table16 | |
504 | [bits >> 6] & eorx) ^ | |
505 | bgx); | |
506 | ((u32 *) dest)[1] = | |
507 | SHORTSWAP32((video_font_draw_table16 | |
508 | [bits >> 4 & 3] & eorx) ^ | |
509 | bgx); | |
510 | ((u32 *) dest)[2] = | |
511 | SHORTSWAP32((video_font_draw_table16 | |
512 | [bits >> 2 & 3] & eorx) ^ | |
513 | bgx); | |
514 | ((u32 *) dest)[3] = | |
515 | SHORTSWAP32((video_font_draw_table16 | |
516 | [bits & 3] & eorx) ^ | |
517 | bgx); | |
4b248f3f WD |
518 | } |
519 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
520 | s++; | |
521 | } | |
522 | break; | |
c609719b | 523 | |
4b248f3f WD |
524 | case GDF_32BIT_X888RGB: |
525 | while (count--) { | |
526 | c = *s; | |
527 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
528 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 529 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
530 | u8 bits = *cdat++; |
531 | ||
64e40d72 WD |
532 | ((u32 *) dest)[0] = |
533 | SWAP32((video_font_draw_table32 | |
534 | [bits >> 4][0] & eorx) ^ bgx); | |
535 | ((u32 *) dest)[1] = | |
536 | SWAP32((video_font_draw_table32 | |
537 | [bits >> 4][1] & eorx) ^ bgx); | |
538 | ((u32 *) dest)[2] = | |
539 | SWAP32((video_font_draw_table32 | |
540 | [bits >> 4][2] & eorx) ^ bgx); | |
541 | ((u32 *) dest)[3] = | |
542 | SWAP32((video_font_draw_table32 | |
543 | [bits >> 4][3] & eorx) ^ bgx); | |
544 | ((u32 *) dest)[4] = | |
545 | SWAP32((video_font_draw_table32 | |
546 | [bits & 15][0] & eorx) ^ bgx); | |
547 | ((u32 *) dest)[5] = | |
548 | SWAP32((video_font_draw_table32 | |
549 | [bits & 15][1] & eorx) ^ bgx); | |
550 | ((u32 *) dest)[6] = | |
551 | SWAP32((video_font_draw_table32 | |
552 | [bits & 15][2] & eorx) ^ bgx); | |
553 | ((u32 *) dest)[7] = | |
554 | SWAP32((video_font_draw_table32 | |
555 | [bits & 15][3] & eorx) ^ bgx); | |
4b248f3f WD |
556 | } |
557 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
558 | s++; | |
559 | } | |
560 | break; | |
c609719b | 561 | |
4b248f3f WD |
562 | case GDF_24BIT_888RGB: |
563 | while (count--) { | |
564 | c = *s; | |
565 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
566 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; | |
64e40d72 | 567 | rows--; dest += VIDEO_LINE_LEN) { |
4b248f3f WD |
568 | u8 bits = *cdat++; |
569 | ||
64e40d72 WD |
570 | ((u32 *) dest)[0] = |
571 | (video_font_draw_table24[bits >> 4][0] | |
572 | & eorx) ^ bgx; | |
573 | ((u32 *) dest)[1] = | |
574 | (video_font_draw_table24[bits >> 4][1] | |
575 | & eorx) ^ bgx; | |
576 | ((u32 *) dest)[2] = | |
577 | (video_font_draw_table24[bits >> 4][2] | |
578 | & eorx) ^ bgx; | |
579 | ((u32 *) dest)[3] = | |
580 | (video_font_draw_table24[bits & 15][0] | |
581 | & eorx) ^ bgx; | |
582 | ((u32 *) dest)[4] = | |
583 | (video_font_draw_table24[bits & 15][1] | |
584 | & eorx) ^ bgx; | |
585 | ((u32 *) dest)[5] = | |
586 | (video_font_draw_table24[bits & 15][2] | |
587 | & eorx) ^ bgx; | |
4b248f3f WD |
588 | } |
589 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
590 | s++; | |
591 | } | |
592 | break; | |
8bde7f77 | 593 | } |
c609719b WD |
594 | } |
595 | ||
64e40d72 | 596 | static inline void video_drawstring(int xx, int yy, unsigned char *s) |
c609719b | 597 | { |
64e40d72 | 598 | video_drawchars(xx, yy, s, strlen((char *) s)); |
c609719b WD |
599 | } |
600 | ||
64e40d72 | 601 | static void video_putchar(int xx, int yy, unsigned char c) |
c609719b | 602 | { |
64e40d72 | 603 | video_drawchars(xx, yy + video_logo_height, &c, 1); |
c609719b WD |
604 | } |
605 | ||
c609719b | 606 | #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR) |
64e40d72 | 607 | static void video_set_cursor(void) |
c609719b | 608 | { |
03d31fcf GB |
609 | if (cursor_state) |
610 | console_cursor(0); | |
611 | console_cursor(1); | |
c609719b | 612 | } |
64e40d72 | 613 | |
a45adde9 AG |
614 | static void video_invertchar(int xx, int yy) |
615 | { | |
616 | int firstx = xx * VIDEO_PIXEL_SIZE; | |
617 | int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE; | |
618 | int firsty = yy * VIDEO_LINE_LEN; | |
619 | int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN; | |
620 | int x, y; | |
621 | for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) { | |
622 | for (x = firstx; x < lastx; x++) { | |
623 | u8 *dest = (u8 *)(video_fb_address) + x + y; | |
624 | *dest = ~*dest; | |
625 | } | |
626 | } | |
627 | } | |
03d31fcf | 628 | |
64e40d72 | 629 | void console_cursor(int state) |
c609719b | 630 | { |
c609719b | 631 | #ifdef CONFIG_CONSOLE_TIME |
4b248f3f WD |
632 | struct rtc_time tm; |
633 | char info[16]; | |
634 | ||
635 | /* time update only if cursor is on (faster scroll) */ | |
636 | if (state) { | |
64e40d72 WD |
637 | rtc_get(&tm); |
638 | ||
639 | sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min, | |
640 | tm.tm_sec); | |
641 | video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH, | |
642 | VIDEO_INFO_Y, (uchar *) info); | |
643 | ||
644 | sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon, | |
645 | tm.tm_year); | |
646 | video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH, | |
647 | VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT, | |
648 | (uchar *) info); | |
4b248f3f | 649 | } |
c609719b WD |
650 | #endif |
651 | ||
03d31fcf GB |
652 | if (cursor_state != state) { |
653 | if (cursor_state) { | |
654 | /* turn off the cursor */ | |
655 | video_invertchar(old_col * VIDEO_FONT_WIDTH, | |
656 | old_row * VIDEO_FONT_HEIGHT + | |
657 | video_logo_height); | |
658 | } else { | |
659 | /* turn off the cursor and record where it is */ | |
660 | video_invertchar(console_col * VIDEO_FONT_WIDTH, | |
661 | console_row * VIDEO_FONT_HEIGHT + | |
662 | video_logo_height); | |
663 | old_col = console_col; | |
664 | old_row = console_row; | |
665 | } | |
666 | cursor_state = state; | |
4b248f3f | 667 | } |
db0d47dd EN |
668 | if (cfb_do_flush_cache) |
669 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); | |
c609719b WD |
670 | } |
671 | #endif | |
672 | ||
c609719b | 673 | #ifndef VIDEO_HW_RECTFILL |
64e40d72 | 674 | static void memsetl(int *p, int c, int v) |
c609719b | 675 | { |
4b248f3f WD |
676 | while (c--) |
677 | *(p++) = v; | |
c609719b WD |
678 | } |
679 | #endif | |
680 | ||
c609719b | 681 | #ifndef VIDEO_HW_BITBLT |
64e40d72 | 682 | static void memcpyl(int *d, int *s, int c) |
c609719b | 683 | { |
4b248f3f WD |
684 | while (c--) |
685 | *(d++) = *(s++); | |
c609719b WD |
686 | } |
687 | #endif | |
688 | ||
90f60a81 PR |
689 | static void console_clear_line(int line, int begin, int end) |
690 | { | |
691 | #ifdef VIDEO_HW_RECTFILL | |
692 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ | |
693 | VIDEO_FONT_WIDTH * begin, /* dest pos x */ | |
694 | video_logo_height + | |
695 | VIDEO_FONT_HEIGHT * line, /* dest pos y */ | |
696 | VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */ | |
697 | VIDEO_FONT_HEIGHT, /* frame height */ | |
698 | bgx /* fill color */ | |
699 | ); | |
700 | #else | |
701 | if (begin == 0 && (end + 1) == CONSOLE_COLS) { | |
702 | memsetl(CONSOLE_ROW_FIRST + | |
703 | CONSOLE_ROW_SIZE * line, /* offset of row */ | |
704 | CONSOLE_ROW_SIZE >> 2, /* length of row */ | |
705 | bgx /* fill color */ | |
706 | ); | |
707 | } else { | |
708 | void *offset; | |
709 | int i, size; | |
710 | ||
711 | offset = CONSOLE_ROW_FIRST + | |
712 | CONSOLE_ROW_SIZE * line + /* offset of row */ | |
713 | VIDEO_FONT_WIDTH * | |
714 | VIDEO_PIXEL_SIZE * begin; /* offset of col */ | |
715 | size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1); | |
716 | size >>= 2; /* length to end for memsetl() */ | |
717 | /* fill at col offset of i'th line using bgx as fill color */ | |
718 | for (i = 0; i < VIDEO_FONT_HEIGHT; i++) | |
719 | memsetl(offset + i * VIDEO_LINE_LEN, size, bgx); | |
720 | } | |
721 | #endif | |
722 | } | |
723 | ||
64e40d72 | 724 | static void console_scrollup(void) |
c609719b | 725 | { |
4b248f3f | 726 | /* copy up rows ignoring the first one */ |
c609719b WD |
727 | |
728 | #ifdef VIDEO_HW_BITBLT | |
64e40d72 WD |
729 | video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
730 | 0, /* source pos x */ | |
731 | video_logo_height + | |
732 | VIDEO_FONT_HEIGHT, /* source pos y */ | |
733 | 0, /* dest pos x */ | |
734 | video_logo_height, /* dest pos y */ | |
735 | VIDEO_VISIBLE_COLS, /* frame width */ | |
736 | VIDEO_VISIBLE_ROWS | |
737 | - video_logo_height | |
738 | - VIDEO_FONT_HEIGHT /* frame height */ | |
4b248f3f | 739 | ); |
c609719b | 740 | #else |
64e40d72 WD |
741 | memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, |
742 | CONSOLE_SCROLL_SIZE >> 2); | |
c609719b | 743 | #endif |
4b248f3f | 744 | /* clear the last one */ |
90f60a81 | 745 | console_clear_line(CONSOLE_ROWS - 1, 0, CONSOLE_COLS - 1); |
c609719b WD |
746 | } |
747 | ||
64e40d72 | 748 | static void console_back(void) |
c609719b | 749 | { |
65618636 | 750 | console_col--; |
4b248f3f WD |
751 | |
752 | if (console_col < 0) { | |
753 | console_col = CONSOLE_COLS - 1; | |
754 | console_row--; | |
755 | if (console_row < 0) | |
756 | console_row = 0; | |
757 | } | |
c609719b WD |
758 | } |
759 | ||
33a35bbb PR |
760 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
761 | ||
762 | static void console_clear(void) | |
763 | { | |
764 | #ifdef VIDEO_HW_RECTFILL | |
765 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ | |
766 | 0, /* dest pos x */ | |
767 | video_logo_height, /* dest pos y */ | |
768 | VIDEO_VISIBLE_COLS, /* frame width */ | |
769 | VIDEO_VISIBLE_ROWS, /* frame height */ | |
770 | bgx /* fill color */ | |
771 | ); | |
772 | #else | |
773 | memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx); | |
774 | #endif | |
775 | } | |
776 | ||
777 | static void console_cursor_fix(void) | |
778 | { | |
779 | if (console_row < 0) | |
780 | console_row = 0; | |
781 | if (console_row >= CONSOLE_ROWS) | |
782 | console_row = CONSOLE_ROWS - 1; | |
783 | if (console_col < 0) | |
784 | console_col = 0; | |
785 | if (console_col >= CONSOLE_COLS) | |
786 | console_col = CONSOLE_COLS - 1; | |
787 | } | |
788 | ||
789 | static void console_cursor_up(int n) | |
790 | { | |
791 | console_row -= n; | |
792 | console_cursor_fix(); | |
793 | } | |
794 | ||
795 | static void console_cursor_down(int n) | |
796 | { | |
797 | console_row += n; | |
798 | console_cursor_fix(); | |
799 | } | |
800 | ||
801 | static void console_cursor_left(int n) | |
802 | { | |
803 | console_col -= n; | |
804 | console_cursor_fix(); | |
805 | } | |
806 | ||
807 | static void console_cursor_right(int n) | |
808 | { | |
809 | console_col += n; | |
810 | console_cursor_fix(); | |
811 | } | |
812 | ||
813 | static void console_cursor_set_position(int row, int col) | |
814 | { | |
815 | if (console_row != -1) | |
816 | console_row = row; | |
817 | if (console_col != -1) | |
818 | console_col = col; | |
819 | console_cursor_fix(); | |
820 | } | |
821 | ||
822 | static void console_previousline(int n) | |
823 | { | |
824 | /* FIXME: also scroll terminal ? */ | |
825 | console_row -= n; | |
826 | console_cursor_fix(); | |
827 | } | |
828 | ||
829 | static void console_swap_colors(void) | |
c609719b | 830 | { |
33a35bbb PR |
831 | eorx = fgx; |
832 | fgx = bgx; | |
833 | bgx = eorx; | |
834 | eorx = fgx ^ bgx; | |
835 | } | |
836 | ||
837 | static inline int console_cursor_is_visible(void) | |
838 | { | |
839 | return !ansi_cursor_hidden; | |
840 | } | |
841 | #else | |
842 | static inline int console_cursor_is_visible(void) | |
843 | { | |
844 | return 1; | |
845 | } | |
846 | #endif | |
847 | ||
848 | static void console_newline(int n) | |
849 | { | |
850 | console_row += n; | |
4b248f3f WD |
851 | console_col = 0; |
852 | ||
853 | /* Check if we need to scroll the terminal */ | |
854 | if (console_row >= CONSOLE_ROWS) { | |
855 | /* Scroll everything up */ | |
64e40d72 | 856 | console_scrollup(); |
4b248f3f WD |
857 | |
858 | /* Decrement row number */ | |
33a35bbb | 859 | console_row = CONSOLE_ROWS - 1; |
4b248f3f | 860 | } |
c609719b WD |
861 | } |
862 | ||
64e40d72 | 863 | static void console_cr(void) |
20c450ef | 864 | { |
65618636 | 865 | console_col = 0; |
20c450ef AG |
866 | } |
867 | ||
33a35bbb | 868 | static void parse_putc(const char c) |
c609719b | 869 | { |
20c450ef AG |
870 | static int nl = 1; |
871 | ||
33a35bbb PR |
872 | if (console_cursor_is_visible()) |
873 | CURSOR_OFF; | |
03d31fcf | 874 | |
4b248f3f | 875 | switch (c) { |
20c450ef | 876 | case 13: /* back to first column */ |
64e40d72 | 877 | console_cr(); |
4b248f3f | 878 | break; |
c609719b | 879 | |
4b248f3f | 880 | case '\n': /* next line */ |
20c450ef | 881 | if (console_col || (!console_col && nl)) |
33a35bbb | 882 | console_newline(1); |
20c450ef | 883 | nl = 1; |
4b248f3f WD |
884 | break; |
885 | ||
886 | case 9: /* tab 8 */ | |
65618636 | 887 | console_col |= 0x0008; |
4b248f3f | 888 | console_col &= ~0x0007; |
c609719b | 889 | |
4b248f3f | 890 | if (console_col >= CONSOLE_COLS) |
33a35bbb | 891 | console_newline(1); |
4b248f3f | 892 | break; |
c609719b | 893 | |
4b248f3f | 894 | case 8: /* backspace */ |
64e40d72 | 895 | console_back(); |
4b248f3f | 896 | break; |
c609719b | 897 | |
24fe06cc PR |
898 | case 7: /* bell */ |
899 | break; /* ignored */ | |
900 | ||
4b248f3f | 901 | default: /* draw the char */ |
64e40d72 WD |
902 | video_putchar(console_col * VIDEO_FONT_WIDTH, |
903 | console_row * VIDEO_FONT_HEIGHT, c); | |
4b248f3f | 904 | console_col++; |
c609719b | 905 | |
4b248f3f | 906 | /* check for newline */ |
20c450ef | 907 | if (console_col >= CONSOLE_COLS) { |
33a35bbb | 908 | console_newline(1); |
20c450ef AG |
909 | nl = 0; |
910 | } | |
4b248f3f | 911 | } |
33a35bbb PR |
912 | |
913 | if (console_cursor_is_visible()) | |
914 | CURSOR_SET; | |
915 | } | |
916 | ||
917 | void video_putc(const char c) | |
918 | { | |
919 | #ifdef CONFIG_CFB_CONSOLE_ANSI | |
920 | int i; | |
921 | ||
922 | if (c == 27) { | |
923 | for (i = 0; i < ansi_buf_size; ++i) | |
924 | parse_putc(ansi_buf[i]); | |
925 | ansi_buf[0] = 27; | |
926 | ansi_buf_size = 1; | |
927 | return; | |
928 | } | |
929 | ||
930 | if (ansi_buf_size > 0) { | |
931 | /* | |
932 | * 0 - ESC | |
933 | * 1 - [ | |
934 | * 2 - num1 | |
935 | * 3 - .. | |
936 | * 4 - ; | |
937 | * 5 - num2 | |
938 | * 6 - .. | |
939 | * - cchar | |
940 | */ | |
941 | int next = 0; | |
942 | ||
943 | int flush = 0; | |
944 | int fail = 0; | |
945 | ||
946 | int num1 = 0; | |
947 | int num2 = 0; | |
948 | int cchar = 0; | |
949 | ||
950 | ansi_buf[ansi_buf_size++] = c; | |
951 | ||
952 | if (ansi_buf_size >= sizeof(ansi_buf)) | |
953 | fail = 1; | |
954 | ||
955 | for (i = 0; i < ansi_buf_size; ++i) { | |
956 | if (fail) | |
957 | break; | |
958 | ||
959 | switch (next) { | |
960 | case 0: | |
961 | if (ansi_buf[i] == 27) | |
962 | next = 1; | |
963 | else | |
964 | fail = 1; | |
965 | break; | |
966 | ||
967 | case 1: | |
968 | if (ansi_buf[i] == '[') | |
969 | next = 2; | |
970 | else | |
971 | fail = 1; | |
972 | break; | |
973 | ||
974 | case 2: | |
975 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { | |
976 | num1 = ansi_buf[i]-'0'; | |
977 | next = 3; | |
978 | } else if (ansi_buf[i] != '?') { | |
979 | --i; | |
980 | num1 = 1; | |
981 | next = 4; | |
982 | } | |
983 | break; | |
984 | ||
985 | case 3: | |
986 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { | |
987 | num1 *= 10; | |
988 | num1 += ansi_buf[i]-'0'; | |
989 | } else { | |
990 | --i; | |
991 | next = 4; | |
992 | } | |
993 | break; | |
994 | ||
995 | case 4: | |
996 | if (ansi_buf[i] != ';') { | |
997 | --i; | |
998 | next = 7; | |
999 | } else | |
1000 | next = 5; | |
1001 | break; | |
1002 | ||
1003 | case 5: | |
1004 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { | |
1005 | num2 = ansi_buf[i]-'0'; | |
1006 | next = 6; | |
1007 | } else | |
1008 | fail = 1; | |
1009 | break; | |
1010 | ||
1011 | case 6: | |
1012 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { | |
1013 | num2 *= 10; | |
1014 | num2 += ansi_buf[i]-'0'; | |
1015 | } else { | |
1016 | --i; | |
1017 | next = 7; | |
1018 | } | |
1019 | break; | |
1020 | ||
1021 | case 7: | |
1022 | if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H') | |
1023 | || ansi_buf[i] == 'J' | |
1024 | || ansi_buf[i] == 'K' | |
1025 | || ansi_buf[i] == 'h' | |
1026 | || ansi_buf[i] == 'l' | |
1027 | || ansi_buf[i] == 'm') { | |
1028 | cchar = ansi_buf[i]; | |
1029 | flush = 1; | |
1030 | } else | |
1031 | fail = 1; | |
1032 | break; | |
1033 | } | |
1034 | } | |
1035 | ||
1036 | if (fail) { | |
1037 | for (i = 0; i < ansi_buf_size; ++i) | |
1038 | parse_putc(ansi_buf[i]); | |
1039 | ansi_buf_size = 0; | |
1040 | return; | |
1041 | } | |
1042 | ||
1043 | if (flush) { | |
1044 | if (!ansi_cursor_hidden) | |
1045 | CURSOR_OFF; | |
1046 | ansi_buf_size = 0; | |
1047 | switch (cchar) { | |
1048 | case 'A': | |
1049 | /* move cursor num1 rows up */ | |
1050 | console_cursor_up(num1); | |
1051 | break; | |
1052 | case 'B': | |
1053 | /* move cursor num1 rows down */ | |
1054 | console_cursor_down(num1); | |
1055 | break; | |
1056 | case 'C': | |
1057 | /* move cursor num1 columns forward */ | |
1058 | console_cursor_right(num1); | |
1059 | break; | |
1060 | case 'D': | |
1061 | /* move cursor num1 columns back */ | |
1062 | console_cursor_left(num1); | |
1063 | break; | |
1064 | case 'E': | |
1065 | /* move cursor num1 rows up at begin of row */ | |
1066 | console_previousline(num1); | |
1067 | break; | |
1068 | case 'F': | |
1069 | /* move cursor num1 rows down at begin of row */ | |
1070 | console_newline(num1); | |
1071 | break; | |
1072 | case 'G': | |
1073 | /* move cursor to column num1 */ | |
1074 | console_cursor_set_position(-1, num1-1); | |
1075 | break; | |
1076 | case 'H': | |
1077 | /* move cursor to row num1, column num2 */ | |
1078 | console_cursor_set_position(num1-1, num2-1); | |
1079 | break; | |
1080 | case 'J': | |
1081 | /* clear console and move cursor to 0, 0 */ | |
1082 | console_clear(); | |
1083 | console_cursor_set_position(0, 0); | |
1084 | break; | |
1085 | case 'K': | |
1086 | /* clear line */ | |
1087 | if (num1 == 0) | |
1088 | console_clear_line(console_row, | |
1089 | console_col, | |
1090 | CONSOLE_COLS-1); | |
1091 | else if (num1 == 1) | |
1092 | console_clear_line(console_row, | |
1093 | 0, console_col); | |
1094 | else | |
1095 | console_clear_line(console_row, | |
1096 | 0, CONSOLE_COLS-1); | |
1097 | break; | |
1098 | case 'h': | |
1099 | ansi_cursor_hidden = 0; | |
1100 | break; | |
1101 | case 'l': | |
1102 | ansi_cursor_hidden = 1; | |
1103 | break; | |
1104 | case 'm': | |
1105 | if (num1 == 0) { /* reset swapped colors */ | |
1106 | if (ansi_colors_need_revert) { | |
1107 | console_swap_colors(); | |
1108 | ansi_colors_need_revert = 0; | |
1109 | } | |
1110 | } else if (num1 == 7) { /* once swap colors */ | |
1111 | if (!ansi_colors_need_revert) { | |
1112 | console_swap_colors(); | |
1113 | ansi_colors_need_revert = 1; | |
1114 | } | |
1115 | } | |
1116 | break; | |
1117 | } | |
1118 | if (!ansi_cursor_hidden) | |
1119 | CURSOR_SET; | |
1120 | } | |
1121 | } else { | |
1122 | parse_putc(c); | |
1123 | } | |
1124 | #else | |
1125 | parse_putc(c); | |
1126 | #endif | |
db0d47dd EN |
1127 | if (cfb_do_flush_cache) |
1128 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); | |
65618636 | 1129 | } |
c609719b | 1130 | |
64e40d72 | 1131 | void video_puts(const char *s) |
c609719b | 1132 | { |
64e40d72 | 1133 | int count = strlen(s); |
4b248f3f WD |
1134 | |
1135 | while (count--) | |
64e40d72 | 1136 | video_putc(*s++); |
4b248f3f WD |
1137 | } |
1138 | ||
10543820 AG |
1139 | /* |
1140 | * Do not enforce drivers (or board code) to provide empty | |
1141 | * video_set_lut() if they do not support 8 bpp format. | |
1142 | * Implement weak default function instead. | |
1143 | */ | |
64e40d72 WD |
1144 | void __video_set_lut(unsigned int index, unsigned char r, |
1145 | unsigned char g, unsigned char b) | |
10543820 AG |
1146 | { |
1147 | } | |
64e40d72 WD |
1148 | |
1149 | void video_set_lut(unsigned int, unsigned char, unsigned char, unsigned char) | |
1150 | __attribute__ ((weak, alias("__video_set_lut"))); | |
10543820 | 1151 | |
07d38a17 | 1152 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
4b248f3f WD |
1153 | |
1154 | #define FILL_8BIT_332RGB(r,g,b) { \ | |
1155 | *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \ | |
1156 | fb ++; \ | |
1157 | } | |
1158 | ||
1159 | #define FILL_15BIT_555RGB(r,g,b) { \ | |
64e40d72 WD |
1160 | *(unsigned short *)fb = \ |
1161 | SWAP16((unsigned short)(((r>>3)<<10) | \ | |
1162 | ((g>>3)<<5) | \ | |
1163 | (b>>3))); \ | |
4b248f3f WD |
1164 | fb += 2; \ |
1165 | } | |
1166 | ||
1167 | #define FILL_16BIT_565RGB(r,g,b) { \ | |
64e40d72 WD |
1168 | *(unsigned short *)fb = \ |
1169 | SWAP16((unsigned short)((((r)>>3)<<11)| \ | |
1170 | (((g)>>2)<<5) | \ | |
1171 | ((b)>>3))); \ | |
4b248f3f WD |
1172 | fb += 2; \ |
1173 | } | |
1174 | ||
1175 | #define FILL_32BIT_X888RGB(r,g,b) { \ | |
64e40d72 WD |
1176 | *(unsigned long *)fb = \ |
1177 | SWAP32((unsigned long)(((r<<16) | \ | |
1178 | (g<<8) | \ | |
1179 | b))); \ | |
4b248f3f WD |
1180 | fb += 4; \ |
1181 | } | |
1182 | ||
1183 | #ifdef VIDEO_FB_LITTLE_ENDIAN | |
1184 | #define FILL_24BIT_888RGB(r,g,b) { \ | |
1185 | fb[0] = b; \ | |
1186 | fb[1] = g; \ | |
1187 | fb[2] = r; \ | |
1188 | fb += 3; \ | |
1189 | } | |
1190 | #else | |
1191 | #define FILL_24BIT_888RGB(r,g,b) { \ | |
1192 | fb[0] = r; \ | |
1193 | fb[1] = g; \ | |
1194 | fb[2] = b; \ | |
1195 | fb += 3; \ | |
1196 | } | |
1197 | #endif | |
1198 | ||
e84d568f | 1199 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 | 1200 | static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b) |
e84d568f | 1201 | { |
64e40d72 WD |
1202 | ushort *dst = (ushort *) fb; |
1203 | ushort color = (ushort) (((r >> 3) << 10) | | |
1204 | ((g >> 3) << 5) | | |
1205 | (b >> 3)); | |
e84d568f AG |
1206 | if (x & 1) |
1207 | *(--dst) = color; | |
1208 | else | |
1209 | *(++dst) = color; | |
1210 | } | |
1211 | #endif | |
4b248f3f | 1212 | |
d5011762 AG |
1213 | /* |
1214 | * RLE8 bitmap support | |
1215 | */ | |
1216 | ||
1217 | #ifdef CONFIG_VIDEO_BMP_RLE8 | |
1218 | /* Pre-calculated color table entry */ | |
1219 | struct palette { | |
1220 | union { | |
64e40d72 WD |
1221 | unsigned short w; /* word */ |
1222 | unsigned int dw; /* double word */ | |
1223 | } ce; /* color entry */ | |
d5011762 AG |
1224 | }; |
1225 | ||
1226 | /* | |
1227 | * Helper to draw encoded/unencoded run. | |
1228 | */ | |
64e40d72 WD |
1229 | static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p, |
1230 | int cnt, int enc) | |
d5011762 | 1231 | { |
64e40d72 | 1232 | ulong addr = (ulong) *fb; |
d5011762 AG |
1233 | int *off; |
1234 | int enc_off = 1; | |
1235 | int i; | |
1236 | ||
1237 | /* | |
1238 | * Setup offset of the color index in the bitmap. | |
1239 | * Color index of encoded run is at offset 1. | |
1240 | */ | |
1241 | off = enc ? &enc_off : &i; | |
1242 | ||
1243 | switch (VIDEO_DATA_FORMAT) { | |
1244 | case GDF__8BIT_INDEX: | |
1245 | for (i = 0; i < cnt; i++) | |
64e40d72 | 1246 | *(unsigned char *) addr++ = bm[*off]; |
d5011762 AG |
1247 | break; |
1248 | case GDF_15BIT_555RGB: | |
1249 | case GDF_16BIT_565RGB: | |
1250 | /* differences handled while pre-calculating palette */ | |
1251 | for (i = 0; i < cnt; i++) { | |
64e40d72 | 1252 | *(unsigned short *) addr = p[bm[*off]].ce.w; |
d5011762 AG |
1253 | addr += 2; |
1254 | } | |
1255 | break; | |
1256 | case GDF_32BIT_X888RGB: | |
1257 | for (i = 0; i < cnt; i++) { | |
64e40d72 | 1258 | *(unsigned long *) addr = p[bm[*off]].ce.dw; |
d5011762 AG |
1259 | addr += 4; |
1260 | } | |
1261 | break; | |
1262 | } | |
64e40d72 | 1263 | *fb = (uchar *) addr; /* return modified address */ |
d5011762 AG |
1264 | } |
1265 | ||
64e40d72 WD |
1266 | static int display_rle8_bitmap(bmp_image_t *img, int xoff, int yoff, |
1267 | int width, int height) | |
d5011762 AG |
1268 | { |
1269 | unsigned char *bm; | |
1270 | unsigned char *fbp; | |
1271 | unsigned int cnt, runlen; | |
1272 | int decode = 1; | |
1273 | int x, y, bpp, i, ncolors; | |
1274 | struct palette p[256]; | |
1275 | bmp_color_table_entry_t cte; | |
1276 | int green_shift, red_off; | |
74446b63 AG |
1277 | int limit = VIDEO_COLS * VIDEO_ROWS; |
1278 | int pixels = 0; | |
d5011762 AG |
1279 | |
1280 | x = 0; | |
1281 | y = __le32_to_cpu(img->header.height) - 1; | |
1282 | ncolors = __le32_to_cpu(img->header.colors_used); | |
1283 | bpp = VIDEO_PIXEL_SIZE; | |
64e40d72 WD |
1284 | fbp = (unsigned char *) ((unsigned int) video_fb_address + |
1285 | (((y + yoff) * VIDEO_COLS) + xoff) * bpp); | |
d5011762 | 1286 | |
64e40d72 | 1287 | bm = (uchar *) img + __le32_to_cpu(img->header.data_offset); |
d5011762 AG |
1288 | |
1289 | /* pre-calculate and setup palette */ | |
1290 | switch (VIDEO_DATA_FORMAT) { | |
1291 | case GDF__8BIT_INDEX: | |
1292 | for (i = 0; i < ncolors; i++) { | |
1293 | cte = img->color_table[i]; | |
64e40d72 | 1294 | video_set_lut(i, cte.red, cte.green, cte.blue); |
d5011762 AG |
1295 | } |
1296 | break; | |
1297 | case GDF_15BIT_555RGB: | |
1298 | case GDF_16BIT_565RGB: | |
1299 | if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) { | |
1300 | green_shift = 3; | |
1301 | red_off = 10; | |
1302 | } else { | |
1303 | green_shift = 2; | |
1304 | red_off = 11; | |
1305 | } | |
1306 | for (i = 0; i < ncolors; i++) { | |
1307 | cte = img->color_table[i]; | |
1308 | p[i].ce.w = SWAP16((unsigned short) | |
1309 | (((cte.red >> 3) << red_off) | | |
1310 | ((cte.green >> green_shift) << 5) | | |
1311 | cte.blue >> 3)); | |
1312 | } | |
1313 | break; | |
1314 | case GDF_32BIT_X888RGB: | |
1315 | for (i = 0; i < ncolors; i++) { | |
1316 | cte = img->color_table[i]; | |
64e40d72 WD |
1317 | p[i].ce.dw = SWAP32((cte.red << 16) | |
1318 | (cte.green << 8) | | |
d5011762 AG |
1319 | cte.blue); |
1320 | } | |
1321 | break; | |
1322 | default: | |
1323 | printf("RLE Bitmap unsupported in video mode 0x%x\n", | |
64e40d72 | 1324 | VIDEO_DATA_FORMAT); |
d5011762 AG |
1325 | return -1; |
1326 | } | |
1327 | ||
1328 | while (decode) { | |
1329 | switch (bm[0]) { | |
1330 | case 0: | |
1331 | switch (bm[1]) { | |
1332 | case 0: | |
1333 | /* scan line end marker */ | |
1334 | bm += 2; | |
1335 | x = 0; | |
1336 | y--; | |
1337 | fbp = (unsigned char *) | |
64e40d72 | 1338 | ((unsigned int) video_fb_address + |
d5011762 AG |
1339 | (((y + yoff) * VIDEO_COLS) + |
1340 | xoff) * bpp); | |
1341 | continue; | |
1342 | case 1: | |
1343 | /* end of bitmap data marker */ | |
1344 | decode = 0; | |
1345 | break; | |
1346 | case 2: | |
1347 | /* run offset marker */ | |
1348 | x += bm[2]; | |
1349 | y -= bm[3]; | |
1350 | fbp = (unsigned char *) | |
64e40d72 | 1351 | ((unsigned int) video_fb_address + |
d5011762 AG |
1352 | (((y + yoff) * VIDEO_COLS) + |
1353 | x + xoff) * bpp); | |
1354 | bm += 4; | |
1355 | break; | |
1356 | default: | |
1357 | /* unencoded run */ | |
1358 | cnt = bm[1]; | |
1359 | runlen = cnt; | |
74446b63 AG |
1360 | pixels += cnt; |
1361 | if (pixels > limit) | |
1362 | goto error; | |
1363 | ||
d5011762 AG |
1364 | bm += 2; |
1365 | if (y < height) { | |
1366 | if (x >= width) { | |
1367 | x += runlen; | |
1368 | goto next_run; | |
1369 | } | |
1370 | if (x + runlen > width) | |
1371 | cnt = width - x; | |
64e40d72 | 1372 | draw_bitmap(&fbp, bm, p, cnt, 0); |
d5011762 AG |
1373 | x += runlen; |
1374 | } | |
1375 | next_run: | |
1376 | bm += runlen; | |
1377 | if (runlen & 1) | |
64e40d72 | 1378 | bm++; /* 0 padding if length is odd */ |
d5011762 AG |
1379 | } |
1380 | break; | |
1381 | default: | |
1382 | /* encoded run */ | |
74446b63 AG |
1383 | cnt = bm[0]; |
1384 | runlen = cnt; | |
1385 | pixels += cnt; | |
1386 | if (pixels > limit) | |
1387 | goto error; | |
1388 | ||
64e40d72 | 1389 | if (y < height) { /* only draw into visible area */ |
d5011762 AG |
1390 | if (x >= width) { |
1391 | x += runlen; | |
1392 | bm += 2; | |
1393 | continue; | |
1394 | } | |
1395 | if (x + runlen > width) | |
1396 | cnt = width - x; | |
64e40d72 | 1397 | draw_bitmap(&fbp, bm, p, cnt, 1); |
d5011762 AG |
1398 | x += runlen; |
1399 | } | |
1400 | bm += 2; | |
1401 | break; | |
1402 | } | |
1403 | } | |
1404 | return 0; | |
74446b63 AG |
1405 | error: |
1406 | printf("Error: Too much encoded pixel data, validate your bitmap\n"); | |
1407 | return -1; | |
d5011762 AG |
1408 | } |
1409 | #endif | |
1410 | ||
4b248f3f WD |
1411 | /* |
1412 | * Display the BMP file located at address bmp_image. | |
4b248f3f | 1413 | */ |
64e40d72 | 1414 | int video_display_bitmap(ulong bmp_image, int x, int y) |
4b248f3f WD |
1415 | { |
1416 | ushort xcount, ycount; | |
1417 | uchar *fb; | |
1418 | bmp_image_t *bmp = (bmp_image_t *) bmp_image; | |
1419 | uchar *bmap; | |
1420 | ushort padded_line; | |
1421 | unsigned long width, height, bpp; | |
1422 | unsigned colors; | |
1423 | unsigned long compression; | |
1424 | bmp_color_table_entry_t cte; | |
64e40d72 | 1425 | |
98f4a3df SR |
1426 | #ifdef CONFIG_VIDEO_BMP_GZIP |
1427 | unsigned char *dst = NULL; | |
1428 | ulong len; | |
1429 | #endif | |
4b248f3f | 1430 | |
64e40d72 | 1431 | WATCHDOG_RESET(); |
4b248f3f WD |
1432 | |
1433 | if (!((bmp->header.signature[0] == 'B') && | |
1434 | (bmp->header.signature[1] == 'M'))) { | |
98f4a3df SR |
1435 | |
1436 | #ifdef CONFIG_VIDEO_BMP_GZIP | |
1437 | /* | |
1438 | * Could be a gzipped bmp image, try to decrompress... | |
1439 | */ | |
6d0f6bcf JCPV |
1440 | len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE; |
1441 | dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE); | |
c29ab9d7 SR |
1442 | if (dst == NULL) { |
1443 | printf("Error: malloc in gunzip failed!\n"); | |
64e40d72 | 1444 | return 1; |
c29ab9d7 | 1445 | } |
64e40d72 WD |
1446 | if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, |
1447 | (uchar *) bmp_image, | |
1448 | &len) != 0) { | |
1449 | printf("Error: no valid bmp or bmp.gz image at %lx\n", | |
1450 | bmp_image); | |
98f4a3df SR |
1451 | free(dst); |
1452 | return 1; | |
1453 | } | |
6d0f6bcf | 1454 | if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) { |
64e40d72 WD |
1455 | printf("Image could be truncated " |
1456 | "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n"); | |
c29ab9d7 | 1457 | } |
98f4a3df SR |
1458 | |
1459 | /* | |
1460 | * Set addr to decompressed image | |
1461 | */ | |
64e40d72 | 1462 | bmp = (bmp_image_t *) dst; |
98f4a3df SR |
1463 | |
1464 | if (!((bmp->header.signature[0] == 'B') && | |
1465 | (bmp->header.signature[1] == 'M'))) { | |
64e40d72 WD |
1466 | printf("Error: no valid bmp.gz image at %lx\n", |
1467 | bmp_image); | |
a49e0d17 | 1468 | free(dst); |
98f4a3df SR |
1469 | return 1; |
1470 | } | |
1471 | #else | |
64e40d72 | 1472 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
4b248f3f | 1473 | return 1; |
98f4a3df | 1474 | #endif /* CONFIG_VIDEO_BMP_GZIP */ |
4b248f3f WD |
1475 | } |
1476 | ||
64e40d72 WD |
1477 | width = le32_to_cpu(bmp->header.width); |
1478 | height = le32_to_cpu(bmp->header.height); | |
1479 | bpp = le16_to_cpu(bmp->header.bit_count); | |
1480 | colors = le32_to_cpu(bmp->header.colors_used); | |
1481 | compression = le32_to_cpu(bmp->header.compression); | |
c609719b | 1482 | |
68da5b19 | 1483 | debug("Display-bmp: %ld x %ld with %d colors\n", |
64e40d72 | 1484 | width, height, colors); |
4b248f3f | 1485 | |
d5011762 AG |
1486 | if (compression != BMP_BI_RGB |
1487 | #ifdef CONFIG_VIDEO_BMP_RLE8 | |
1488 | && compression != BMP_BI_RLE8 | |
1489 | #endif | |
64e40d72 WD |
1490 | ) { |
1491 | printf("Error: compression type %ld not supported\n", | |
1492 | compression); | |
a49e0d17 MF |
1493 | #ifdef CONFIG_VIDEO_BMP_GZIP |
1494 | if (dst) | |
1495 | free(dst); | |
1496 | #endif | |
4b248f3f WD |
1497 | return 1; |
1498 | } | |
1499 | ||
1500 | padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3; | |
1501 | ||
1ca298ce MW |
1502 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
1503 | if (x == BMP_ALIGN_CENTER) | |
1504 | x = max(0, (VIDEO_VISIBLE_COLS - width) / 2); | |
1505 | else if (x < 0) | |
1506 | x = max(0, VIDEO_VISIBLE_COLS - width + x + 1); | |
1507 | ||
1508 | if (y == BMP_ALIGN_CENTER) | |
1509 | y = max(0, (VIDEO_VISIBLE_ROWS - height) / 2); | |
1510 | else if (y < 0) | |
1511 | y = max(0, VIDEO_VISIBLE_ROWS - height + y + 1); | |
1512 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ | |
1513 | ||
acf3baad MW |
1514 | /* |
1515 | * Just ignore elements which are completely beyond screen | |
1516 | * dimensions. | |
1517 | */ | |
1518 | if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS)) | |
1519 | return 0; | |
1520 | ||
4b248f3f WD |
1521 | if ((x + width) > VIDEO_VISIBLE_COLS) |
1522 | width = VIDEO_VISIBLE_COLS - x; | |
1523 | if ((y + height) > VIDEO_VISIBLE_ROWS) | |
1524 | height = VIDEO_VISIBLE_ROWS - y; | |
1525 | ||
64e40d72 | 1526 | bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset); |
4b248f3f WD |
1527 | fb = (uchar *) (video_fb_address + |
1528 | ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) + | |
1529 | x * VIDEO_PIXEL_SIZE); | |
1530 | ||
d5011762 AG |
1531 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
1532 | if (compression == BMP_BI_RLE8) { | |
64e40d72 | 1533 | return display_rle8_bitmap(bmp, x, y, width, height); |
d5011762 AG |
1534 | } |
1535 | #endif | |
1536 | ||
68f6618b | 1537 | /* We handle only 4, 8, or 24 bpp bitmaps */ |
64e40d72 | 1538 | switch (le16_to_cpu(bmp->header.bit_count)) { |
68f6618b TT |
1539 | case 4: |
1540 | padded_line -= width / 2; | |
1541 | ycount = height; | |
1542 | ||
1543 | switch (VIDEO_DATA_FORMAT) { | |
1544 | case GDF_32BIT_X888RGB: | |
1545 | while (ycount--) { | |
64e40d72 | 1546 | WATCHDOG_RESET(); |
68f6618b TT |
1547 | /* |
1548 | * Don't assume that 'width' is an | |
1549 | * even number | |
1550 | */ | |
1551 | for (xcount = 0; xcount < width; xcount++) { | |
1552 | uchar idx; | |
1553 | ||
1554 | if (xcount & 1) { | |
1555 | idx = *bmap & 0xF; | |
1556 | bmap++; | |
1557 | } else | |
1558 | idx = *bmap >> 4; | |
1559 | cte = bmp->color_table[idx]; | |
1560 | FILL_32BIT_X888RGB(cte.red, cte.green, | |
1561 | cte.blue); | |
1562 | } | |
1563 | bmap += padded_line; | |
1564 | fb -= (VIDEO_VISIBLE_COLS + width) * | |
64e40d72 | 1565 | VIDEO_PIXEL_SIZE; |
68f6618b TT |
1566 | } |
1567 | break; | |
1568 | default: | |
1569 | puts("4bpp bitmap unsupported with current " | |
1570 | "video mode\n"); | |
1571 | break; | |
1572 | } | |
1573 | break; | |
1574 | ||
4b248f3f WD |
1575 | case 8: |
1576 | padded_line -= width; | |
1577 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) { | |
7c050f81 | 1578 | /* Copy colormap */ |
4b248f3f WD |
1579 | for (xcount = 0; xcount < colors; ++xcount) { |
1580 | cte = bmp->color_table[xcount]; | |
64e40d72 WD |
1581 | video_set_lut(xcount, cte.red, cte.green, |
1582 | cte.blue); | |
4b248f3f WD |
1583 | } |
1584 | } | |
1585 | ycount = height; | |
1586 | switch (VIDEO_DATA_FORMAT) { | |
1587 | case GDF__8BIT_INDEX: | |
1588 | while (ycount--) { | |
64e40d72 | 1589 | WATCHDOG_RESET(); |
4b248f3f WD |
1590 | xcount = width; |
1591 | while (xcount--) { | |
1592 | *fb++ = *bmap++; | |
1593 | } | |
1594 | bmap += padded_line; | |
64e40d72 WD |
1595 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1596 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1597 | } |
1598 | break; | |
1599 | case GDF__8BIT_332RGB: | |
1600 | while (ycount--) { | |
64e40d72 | 1601 | WATCHDOG_RESET(); |
4b248f3f WD |
1602 | xcount = width; |
1603 | while (xcount--) { | |
1604 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1605 | FILL_8BIT_332RGB(cte.red, cte.green, |
1606 | cte.blue); | |
4b248f3f WD |
1607 | } |
1608 | bmap += padded_line; | |
64e40d72 WD |
1609 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1610 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1611 | } |
1612 | break; | |
1613 | case GDF_15BIT_555RGB: | |
1614 | while (ycount--) { | |
e84d568f AG |
1615 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
1616 | int xpos = x; | |
1617 | #endif | |
64e40d72 | 1618 | WATCHDOG_RESET(); |
4b248f3f WD |
1619 | xcount = width; |
1620 | while (xcount--) { | |
1621 | cte = bmp->color_table[*bmap++]; | |
cc347801 | 1622 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 WD |
1623 | fill_555rgb_pswap(fb, xpos++, cte.red, |
1624 | cte.green, | |
1625 | cte.blue); | |
e84d568f | 1626 | fb += 2; |
cc347801 | 1627 | #else |
64e40d72 WD |
1628 | FILL_15BIT_555RGB(cte.red, cte.green, |
1629 | cte.blue); | |
e84d568f | 1630 | #endif |
4b248f3f WD |
1631 | } |
1632 | bmap += padded_line; | |
64e40d72 WD |
1633 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1634 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1635 | } |
1636 | break; | |
1637 | case GDF_16BIT_565RGB: | |
1638 | while (ycount--) { | |
64e40d72 | 1639 | WATCHDOG_RESET(); |
4b248f3f WD |
1640 | xcount = width; |
1641 | while (xcount--) { | |
1642 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1643 | FILL_16BIT_565RGB(cte.red, cte.green, |
1644 | cte.blue); | |
4b248f3f WD |
1645 | } |
1646 | bmap += padded_line; | |
64e40d72 WD |
1647 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1648 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1649 | } |
1650 | break; | |
1651 | case GDF_32BIT_X888RGB: | |
1652 | while (ycount--) { | |
64e40d72 | 1653 | WATCHDOG_RESET(); |
4b248f3f WD |
1654 | xcount = width; |
1655 | while (xcount--) { | |
1656 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1657 | FILL_32BIT_X888RGB(cte.red, cte.green, |
1658 | cte.blue); | |
4b248f3f WD |
1659 | } |
1660 | bmap += padded_line; | |
64e40d72 WD |
1661 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1662 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1663 | } |
1664 | break; | |
1665 | case GDF_24BIT_888RGB: | |
1666 | while (ycount--) { | |
64e40d72 | 1667 | WATCHDOG_RESET(); |
4b248f3f WD |
1668 | xcount = width; |
1669 | while (xcount--) { | |
1670 | cte = bmp->color_table[*bmap++]; | |
64e40d72 WD |
1671 | FILL_24BIT_888RGB(cte.red, cte.green, |
1672 | cte.blue); | |
4b248f3f WD |
1673 | } |
1674 | bmap += padded_line; | |
64e40d72 WD |
1675 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1676 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1677 | } |
1678 | break; | |
1679 | } | |
1680 | break; | |
1681 | case 24: | |
1682 | padded_line -= 3 * width; | |
1683 | ycount = height; | |
1684 | switch (VIDEO_DATA_FORMAT) { | |
1685 | case GDF__8BIT_332RGB: | |
1686 | while (ycount--) { | |
64e40d72 | 1687 | WATCHDOG_RESET(); |
4b248f3f WD |
1688 | xcount = width; |
1689 | while (xcount--) { | |
64e40d72 WD |
1690 | FILL_8BIT_332RGB(bmap[2], bmap[1], |
1691 | bmap[0]); | |
4b248f3f WD |
1692 | bmap += 3; |
1693 | } | |
1694 | bmap += padded_line; | |
64e40d72 WD |
1695 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1696 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1697 | } |
1698 | break; | |
1699 | case GDF_15BIT_555RGB: | |
1700 | while (ycount--) { | |
e84d568f AG |
1701 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
1702 | int xpos = x; | |
1703 | #endif | |
64e40d72 | 1704 | WATCHDOG_RESET(); |
4b248f3f WD |
1705 | xcount = width; |
1706 | while (xcount--) { | |
cc347801 | 1707 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 WD |
1708 | fill_555rgb_pswap(fb, xpos++, bmap[2], |
1709 | bmap[1], bmap[0]); | |
e84d568f | 1710 | fb += 2; |
cc347801 | 1711 | #else |
64e40d72 WD |
1712 | FILL_15BIT_555RGB(bmap[2], bmap[1], |
1713 | bmap[0]); | |
e84d568f | 1714 | #endif |
4b248f3f WD |
1715 | bmap += 3; |
1716 | } | |
1717 | bmap += padded_line; | |
64e40d72 WD |
1718 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1719 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1720 | } |
1721 | break; | |
1722 | case GDF_16BIT_565RGB: | |
1723 | while (ycount--) { | |
64e40d72 | 1724 | WATCHDOG_RESET(); |
4b248f3f WD |
1725 | xcount = width; |
1726 | while (xcount--) { | |
64e40d72 WD |
1727 | FILL_16BIT_565RGB(bmap[2], bmap[1], |
1728 | bmap[0]); | |
4b248f3f WD |
1729 | bmap += 3; |
1730 | } | |
1731 | bmap += padded_line; | |
64e40d72 WD |
1732 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1733 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1734 | } |
1735 | break; | |
1736 | case GDF_32BIT_X888RGB: | |
1737 | while (ycount--) { | |
64e40d72 | 1738 | WATCHDOG_RESET(); |
4b248f3f WD |
1739 | xcount = width; |
1740 | while (xcount--) { | |
64e40d72 WD |
1741 | FILL_32BIT_X888RGB(bmap[2], bmap[1], |
1742 | bmap[0]); | |
4b248f3f WD |
1743 | bmap += 3; |
1744 | } | |
1745 | bmap += padded_line; | |
64e40d72 WD |
1746 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1747 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1748 | } |
1749 | break; | |
1750 | case GDF_24BIT_888RGB: | |
1751 | while (ycount--) { | |
64e40d72 | 1752 | WATCHDOG_RESET(); |
4b248f3f WD |
1753 | xcount = width; |
1754 | while (xcount--) { | |
64e40d72 WD |
1755 | FILL_24BIT_888RGB(bmap[2], bmap[1], |
1756 | bmap[0]); | |
4b248f3f WD |
1757 | bmap += 3; |
1758 | } | |
1759 | bmap += padded_line; | |
64e40d72 WD |
1760 | fb -= (VIDEO_VISIBLE_COLS + width) * |
1761 | VIDEO_PIXEL_SIZE; | |
4b248f3f WD |
1762 | } |
1763 | break; | |
1764 | default: | |
64e40d72 WD |
1765 | printf("Error: 24 bits/pixel bitmap incompatible " |
1766 | "with current video mode\n"); | |
4b248f3f WD |
1767 | break; |
1768 | } | |
1769 | break; | |
1770 | default: | |
64e40d72 WD |
1771 | printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n", |
1772 | le16_to_cpu(bmp->header.bit_count)); | |
4b248f3f WD |
1773 | break; |
1774 | } | |
98f4a3df SR |
1775 | |
1776 | #ifdef CONFIG_VIDEO_BMP_GZIP | |
1777 | if (dst) { | |
1778 | free(dst); | |
1779 | } | |
1780 | #endif | |
1781 | ||
db0d47dd EN |
1782 | if (cfb_do_flush_cache) |
1783 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); | |
4b248f3f | 1784 | return (0); |
c609719b | 1785 | } |
07d38a17 | 1786 | #endif |
c609719b | 1787 | |
c609719b WD |
1788 | |
1789 | #ifdef CONFIG_VIDEO_LOGO | |
1e681f9a BR |
1790 | static int video_logo_xpos; |
1791 | static int video_logo_ypos; | |
1792 | ||
4b7d3a0e BR |
1793 | static void plot_logo_or_black(void *screen, int width, int x, int y, \ |
1794 | int black); | |
1795 | ||
1796 | static void logo_plot(void *screen, int width, int x, int y) | |
1797 | { | |
1798 | plot_logo_or_black(screen, width, x, y, 0); | |
1799 | } | |
1800 | ||
1801 | static void logo_black(void) | |
1802 | { | |
1803 | plot_logo_or_black(video_fb_address, \ | |
1804 | VIDEO_COLS, \ | |
1805 | video_logo_xpos, \ | |
1806 | video_logo_ypos, \ | |
1807 | 1); | |
1808 | } | |
1809 | ||
1810 | static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
1811 | { | |
1812 | if (argc != 1) | |
1813 | return cmd_usage(cmdtp); | |
1814 | ||
1815 | logo_black(); | |
1816 | return 0; | |
1817 | } | |
1818 | ||
1819 | U_BOOT_CMD( | |
1820 | clrlogo, 1, 0, do_clrlogo, | |
1821 | "fill the boot logo area with black", | |
1822 | " " | |
1823 | ); | |
1824 | ||
1825 | static void plot_logo_or_black(void *screen, int width, int x, int y, int black) | |
c609719b | 1826 | { |
a6c7ad2f | 1827 | |
4b248f3f | 1828 | int xcount, i; |
64e40d72 | 1829 | int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE; |
be129aa7 | 1830 | int ycount = video_logo_height; |
4b248f3f WD |
1831 | unsigned char r, g, b, *logo_red, *logo_blue, *logo_green; |
1832 | unsigned char *source; | |
1e681f9a BR |
1833 | unsigned char *dest; |
1834 | ||
1835 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN | |
1836 | if (x == BMP_ALIGN_CENTER) | |
1837 | x = max(0, (VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2); | |
1838 | else if (x < 0) | |
1839 | x = max(0, VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1); | |
1840 | ||
1841 | if (y == BMP_ALIGN_CENTER) | |
1842 | y = max(0, (VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2); | |
1843 | else if (y < 0) | |
1844 | y = max(0, VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1); | |
1845 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ | |
1846 | ||
1847 | dest = (unsigned char *)screen + (y * width + x) * VIDEO_PIXEL_SIZE; | |
a6c7ad2f WD |
1848 | |
1849 | #ifdef CONFIG_VIDEO_BMP_LOGO | |
4b248f3f WD |
1850 | source = bmp_logo_bitmap; |
1851 | ||
7c050f81 | 1852 | /* Allocate temporary space for computing colormap */ |
64e40d72 WD |
1853 | logo_red = malloc(BMP_LOGO_COLORS); |
1854 | logo_green = malloc(BMP_LOGO_COLORS); | |
1855 | logo_blue = malloc(BMP_LOGO_COLORS); | |
7c050f81 | 1856 | /* Compute color map */ |
4b248f3f WD |
1857 | for (i = 0; i < VIDEO_LOGO_COLORS; i++) { |
1858 | logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4; | |
1859 | logo_green[i] = (bmp_logo_palette[i] & 0x00f0); | |
1860 | logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4; | |
1861 | } | |
a6c7ad2f | 1862 | #else |
4b248f3f WD |
1863 | source = linux_logo; |
1864 | logo_red = linux_logo_red; | |
1865 | logo_green = linux_logo_green; | |
1866 | logo_blue = linux_logo_blue; | |
a6c7ad2f | 1867 | #endif |
8bde7f77 | 1868 | |
4b248f3f WD |
1869 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) { |
1870 | for (i = 0; i < VIDEO_LOGO_COLORS; i++) { | |
64e40d72 WD |
1871 | video_set_lut(i + VIDEO_LOGO_LUT_OFFSET, |
1872 | logo_red[i], logo_green[i], | |
1873 | logo_blue[i]); | |
4b248f3f | 1874 | } |
8bde7f77 | 1875 | } |
c609719b | 1876 | |
4b248f3f | 1877 | while (ycount--) { |
e84d568f AG |
1878 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
1879 | int xpos = x; | |
1880 | #endif | |
4b248f3f WD |
1881 | xcount = VIDEO_LOGO_WIDTH; |
1882 | while (xcount--) { | |
4b7d3a0e BR |
1883 | if (black) { |
1884 | r = 0x00; | |
1885 | g = 0x00; | |
1886 | b = 0x00; | |
1887 | } else { | |
1888 | r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET]; | |
1889 | g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET]; | |
1890 | b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET]; | |
1891 | } | |
4b248f3f WD |
1892 | |
1893 | switch (VIDEO_DATA_FORMAT) { | |
1894 | case GDF__8BIT_INDEX: | |
1895 | *dest = *source; | |
1896 | break; | |
1897 | case GDF__8BIT_332RGB: | |
64e40d72 WD |
1898 | *dest = ((r >> 5) << 5) | |
1899 | ((g >> 5) << 2) | | |
1900 | (b >> 6); | |
4b248f3f WD |
1901 | break; |
1902 | case GDF_15BIT_555RGB: | |
cc347801 | 1903 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
64e40d72 | 1904 | fill_555rgb_pswap(dest, xpos++, r, g, b); |
cc347801 | 1905 | #else |
4b248f3f | 1906 | *(unsigned short *) dest = |
64e40d72 WD |
1907 | SWAP16((unsigned short) ( |
1908 | ((r >> 3) << 10) | | |
1909 | ((g >> 3) << 5) | | |
1910 | (b >> 3))); | |
bed53753 | 1911 | #endif |
4b248f3f WD |
1912 | break; |
1913 | case GDF_16BIT_565RGB: | |
1914 | *(unsigned short *) dest = | |
64e40d72 WD |
1915 | SWAP16((unsigned short) ( |
1916 | ((r >> 3) << 11) | | |
1917 | ((g >> 2) << 5) | | |
1918 | (b >> 3))); | |
4b248f3f WD |
1919 | break; |
1920 | case GDF_32BIT_X888RGB: | |
1921 | *(unsigned long *) dest = | |
64e40d72 WD |
1922 | SWAP32((unsigned long) ( |
1923 | (r << 16) | | |
1924 | (g << 8) | | |
1925 | b)); | |
4b248f3f WD |
1926 | break; |
1927 | case GDF_24BIT_888RGB: | |
c609719b | 1928 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
4b248f3f WD |
1929 | dest[0] = b; |
1930 | dest[1] = g; | |
1931 | dest[2] = r; | |
c609719b | 1932 | #else |
4b248f3f WD |
1933 | dest[0] = r; |
1934 | dest[1] = g; | |
1935 | dest[2] = b; | |
c609719b | 1936 | #endif |
4b248f3f WD |
1937 | break; |
1938 | } | |
1939 | source++; | |
1940 | dest += VIDEO_PIXEL_SIZE; | |
1941 | } | |
1942 | dest += skip; | |
8bde7f77 | 1943 | } |
a6c7ad2f | 1944 | #ifdef CONFIG_VIDEO_BMP_LOGO |
64e40d72 WD |
1945 | free(logo_red); |
1946 | free(logo_green); | |
1947 | free(logo_blue); | |
a6c7ad2f | 1948 | #endif |
c609719b WD |
1949 | } |
1950 | ||
64e40d72 | 1951 | static void *video_logo(void) |
c609719b | 1952 | { |
4b248f3f | 1953 | char info[128]; |
a9a62af1 WD |
1954 | int space, len; |
1955 | __maybe_unused int y_off = 0; | |
1e681f9a BR |
1956 | __maybe_unused ulong addr; |
1957 | __maybe_unused char *s; | |
4b248f3f | 1958 | |
ff8fb56b | 1959 | splash_get_pos(&video_logo_xpos, &video_logo_ypos); |
4b248f3f | 1960 | |
1e681f9a BR |
1961 | #ifdef CONFIG_SPLASH_SCREEN |
1962 | s = getenv("splashimage"); | |
1963 | if (s != NULL) { | |
dd4425e8 | 1964 | splash_screen_prepare(); |
1e681f9a BR |
1965 | addr = simple_strtoul(s, NULL, 16); |
1966 | ||
1e681f9a BR |
1967 | if (video_display_bitmap(addr, |
1968 | video_logo_xpos, | |
1969 | video_logo_ypos) == 0) { | |
be129aa7 | 1970 | video_logo_height = 0; |
4b248f3f WD |
1971 | return ((void *) (video_fb_address)); |
1972 | } | |
1973 | } | |
1974 | #endif /* CONFIG_SPLASH_SCREEN */ | |
c609719b | 1975 | |
1e681f9a BR |
1976 | logo_plot(video_fb_address, VIDEO_COLS, |
1977 | video_logo_xpos, video_logo_ypos); | |
1978 | ||
1979 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN | |
1980 | /* | |
1981 | * when using splashpos for video_logo, skip any info | |
1982 | * output on video console if the logo is not at 0,0 | |
1983 | */ | |
1984 | if (video_logo_xpos || video_logo_ypos) { | |
1985 | /* | |
1986 | * video_logo_height is used in text and cursor offset | |
1987 | * calculations. Since the console is below the logo, | |
1988 | * we need to adjust the logo height | |
1989 | */ | |
1990 | if (video_logo_ypos == BMP_ALIGN_CENTER) | |
1991 | video_logo_height += max(0, (VIDEO_VISIBLE_ROWS - \ | |
1992 | VIDEO_LOGO_HEIGHT) / 2); | |
1993 | else if (video_logo_ypos > 0) | |
1994 | video_logo_height += video_logo_ypos; | |
1995 | ||
1996 | return video_fb_address + video_logo_height * VIDEO_LINE_LEN; | |
1997 | } | |
1998 | #endif | |
4b248f3f | 1999 | |
64e40d72 | 2000 | sprintf(info, " %s", version_string); |
3dcbe628 AG |
2001 | |
2002 | space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH; | |
2003 | len = strlen(info); | |
2004 | ||
2005 | if (len > space) { | |
64e40d72 WD |
2006 | video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y, |
2007 | (uchar *) info, space); | |
2008 | video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH, | |
2009 | VIDEO_INFO_Y + VIDEO_FONT_HEIGHT, | |
2010 | (uchar *) info + space, len - space); | |
3dcbe628 AG |
2011 | y_off = 1; |
2012 | } else | |
64e40d72 | 2013 | video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info); |
c609719b WD |
2014 | |
2015 | #ifdef CONFIG_CONSOLE_EXTRA_INFO | |
4b248f3f | 2016 | { |
64e40d72 WD |
2017 | int i, n = |
2018 | ((video_logo_height - | |
2019 | VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT); | |
4b248f3f WD |
2020 | |
2021 | for (i = 1; i < n; i++) { | |
64e40d72 | 2022 | video_get_info_str(i, info); |
3dcbe628 AG |
2023 | if (!*info) |
2024 | continue; | |
2025 | ||
2026 | len = strlen(info); | |
2027 | if (len > space) { | |
64e40d72 WD |
2028 | video_drawchars(VIDEO_INFO_X, |
2029 | VIDEO_INFO_Y + | |
2030 | (i + y_off) * | |
2031 | VIDEO_FONT_HEIGHT, | |
2032 | (uchar *) info, space); | |
3dcbe628 | 2033 | y_off++; |
64e40d72 WD |
2034 | video_drawchars(VIDEO_INFO_X + |
2035 | VIDEO_FONT_WIDTH, | |
2036 | VIDEO_INFO_Y + | |
2037 | (i + y_off) * | |
2038 | VIDEO_FONT_HEIGHT, | |
2039 | (uchar *) info + space, | |
2040 | len - space); | |
3dcbe628 | 2041 | } else { |
64e40d72 WD |
2042 | video_drawstring(VIDEO_INFO_X, |
2043 | VIDEO_INFO_Y + | |
2044 | (i + y_off) * | |
2045 | VIDEO_FONT_HEIGHT, | |
2046 | (uchar *) info); | |
3dcbe628 | 2047 | } |
4b248f3f WD |
2048 | } |
2049 | } | |
c609719b WD |
2050 | #endif |
2051 | ||
be129aa7 | 2052 | return (video_fb_address + video_logo_height * VIDEO_LINE_LEN); |
c609719b WD |
2053 | } |
2054 | #endif | |
2055 | ||
bfd4be80 AG |
2056 | static int cfb_fb_is_in_dram(void) |
2057 | { | |
2058 | bd_t *bd = gd->bd; | |
2059 | #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \ | |
2060 | defined(CONFIG_SANDBOX) || defined(CONFIG_X86) | |
2061 | ulong start, end; | |
2062 | int i; | |
2063 | ||
2064 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { | |
2065 | start = bd->bi_dram[i].start; | |
2066 | end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1; | |
2067 | if ((ulong)video_fb_address >= start && | |
2068 | (ulong)video_fb_address < end) | |
2069 | return 1; | |
2070 | } | |
2071 | #else | |
2072 | if ((ulong)video_fb_address >= bd->bi_memstart && | |
2073 | (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize) | |
2074 | return 1; | |
2075 | #endif | |
2076 | return 0; | |
2077 | } | |
2078 | ||
64e40d72 | 2079 | static int video_init(void) |
c609719b | 2080 | { |
4b248f3f | 2081 | unsigned char color8; |
c609719b | 2082 | |
57912939 WD |
2083 | pGD = video_hw_init(); |
2084 | if (pGD == NULL) | |
4b248f3f | 2085 | return -1; |
c609719b | 2086 | |
4b248f3f | 2087 | video_fb_address = (void *) VIDEO_FB_ADRS; |
c609719b | 2088 | #ifdef CONFIG_VIDEO_HW_CURSOR |
64e40d72 | 2089 | video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT); |
c609719b WD |
2090 | #endif |
2091 | ||
bfd4be80 AG |
2092 | cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status(); |
2093 | ||
4b248f3f WD |
2094 | /* Init drawing pats */ |
2095 | switch (VIDEO_DATA_FORMAT) { | |
2096 | case GDF__8BIT_INDEX: | |
64e40d72 WD |
2097 | video_set_lut(0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, |
2098 | CONSOLE_FG_COL); | |
2099 | video_set_lut(0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, | |
2100 | CONSOLE_BG_COL); | |
4b248f3f WD |
2101 | fgx = 0x01010101; |
2102 | bgx = 0x00000000; | |
2103 | break; | |
2104 | case GDF__8BIT_332RGB: | |
2105 | color8 = ((CONSOLE_FG_COL & 0xe0) | | |
64e40d72 WD |
2106 | ((CONSOLE_FG_COL >> 3) & 0x1c) | |
2107 | CONSOLE_FG_COL >> 6); | |
2108 | fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | | |
2109 | color8; | |
4b248f3f | 2110 | color8 = ((CONSOLE_BG_COL & 0xe0) | |
64e40d72 WD |
2111 | ((CONSOLE_BG_COL >> 3) & 0x1c) | |
2112 | CONSOLE_BG_COL >> 6); | |
2113 | bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | | |
2114 | color8; | |
4b248f3f WD |
2115 | break; |
2116 | case GDF_15BIT_555RGB: | |
2117 | fgx = (((CONSOLE_FG_COL >> 3) << 26) | | |
64e40d72 WD |
2118 | ((CONSOLE_FG_COL >> 3) << 21) | |
2119 | ((CONSOLE_FG_COL >> 3) << 16) | | |
2120 | ((CONSOLE_FG_COL >> 3) << 10) | | |
2121 | ((CONSOLE_FG_COL >> 3) << 5) | | |
2122 | (CONSOLE_FG_COL >> 3)); | |
4b248f3f | 2123 | bgx = (((CONSOLE_BG_COL >> 3) << 26) | |
64e40d72 WD |
2124 | ((CONSOLE_BG_COL >> 3) << 21) | |
2125 | ((CONSOLE_BG_COL >> 3) << 16) | | |
2126 | ((CONSOLE_BG_COL >> 3) << 10) | | |
2127 | ((CONSOLE_BG_COL >> 3) << 5) | | |
2128 | (CONSOLE_BG_COL >> 3)); | |
4b248f3f WD |
2129 | break; |
2130 | case GDF_16BIT_565RGB: | |
2131 | fgx = (((CONSOLE_FG_COL >> 3) << 27) | | |
64e40d72 WD |
2132 | ((CONSOLE_FG_COL >> 2) << 21) | |
2133 | ((CONSOLE_FG_COL >> 3) << 16) | | |
2134 | ((CONSOLE_FG_COL >> 3) << 11) | | |
2135 | ((CONSOLE_FG_COL >> 2) << 5) | | |
2136 | (CONSOLE_FG_COL >> 3)); | |
4b248f3f | 2137 | bgx = (((CONSOLE_BG_COL >> 3) << 27) | |
64e40d72 WD |
2138 | ((CONSOLE_BG_COL >> 2) << 21) | |
2139 | ((CONSOLE_BG_COL >> 3) << 16) | | |
2140 | ((CONSOLE_BG_COL >> 3) << 11) | | |
2141 | ((CONSOLE_BG_COL >> 2) << 5) | | |
2142 | (CONSOLE_BG_COL >> 3)); | |
4b248f3f WD |
2143 | break; |
2144 | case GDF_32BIT_X888RGB: | |
64e40d72 WD |
2145 | fgx = (CONSOLE_FG_COL << 16) | |
2146 | (CONSOLE_FG_COL << 8) | | |
2147 | CONSOLE_FG_COL; | |
2148 | bgx = (CONSOLE_BG_COL << 16) | | |
2149 | (CONSOLE_BG_COL << 8) | | |
2150 | CONSOLE_BG_COL; | |
4b248f3f WD |
2151 | break; |
2152 | case GDF_24BIT_888RGB: | |
64e40d72 WD |
2153 | fgx = (CONSOLE_FG_COL << 24) | |
2154 | (CONSOLE_FG_COL << 16) | | |
2155 | (CONSOLE_FG_COL << 8) | | |
2156 | CONSOLE_FG_COL; | |
2157 | bgx = (CONSOLE_BG_COL << 24) | | |
2158 | (CONSOLE_BG_COL << 16) | | |
2159 | (CONSOLE_BG_COL << 8) | | |
2160 | CONSOLE_BG_COL; | |
4b248f3f WD |
2161 | break; |
2162 | } | |
2163 | eorx = fgx ^ bgx; | |
c609719b WD |
2164 | |
2165 | #ifdef CONFIG_VIDEO_LOGO | |
4b248f3f | 2166 | /* Plot the logo and get start point of console */ |
72c65f6f | 2167 | debug("Video: Drawing the logo ...\n"); |
64e40d72 | 2168 | video_console_address = video_logo(); |
c609719b | 2169 | #else |
4b248f3f | 2170 | video_console_address = video_fb_address; |
c609719b WD |
2171 | #endif |
2172 | ||
4b248f3f WD |
2173 | /* Initialize the console */ |
2174 | console_col = 0; | |
2175 | console_row = 0; | |
c609719b | 2176 | |
db0d47dd EN |
2177 | if (cfb_do_flush_cache) |
2178 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); | |
2179 | ||
4b248f3f | 2180 | return 0; |
c609719b WD |
2181 | } |
2182 | ||
6cc7ba9e WD |
2183 | /* |
2184 | * Implement a weak default function for boards that optionally | |
2185 | * need to skip the video initialization. | |
2186 | */ | |
2187 | int __board_video_skip(void) | |
2188 | { | |
2189 | /* As default, don't skip test */ | |
2190 | return 0; | |
2191 | } | |
6cc7ba9e | 2192 | |
64e40d72 WD |
2193 | int board_video_skip(void) |
2194 | __attribute__ ((weak, alias("__board_video_skip"))); | |
2195 | ||
2196 | int drv_video_init(void) | |
c609719b | 2197 | { |
4b248f3f | 2198 | int skip_dev_init; |
52cb4d4f | 2199 | struct stdio_dev console_dev; |
c609719b | 2200 | |
6cc7ba9e WD |
2201 | /* Check if video initialization should be skipped */ |
2202 | if (board_video_skip()) | |
2203 | return 0; | |
2204 | ||
81050926 | 2205 | /* Init video chip - returns with framebuffer cleared */ |
64e40d72 | 2206 | skip_dev_init = (video_init() == -1); |
81050926 | 2207 | |
f62f6469 | 2208 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
72c65f6f | 2209 | debug("KBD: Keyboard init ...\n"); |
f62f6469 WD |
2210 | skip_dev_init |= (VIDEO_KBD_INIT_FCT == -1); |
2211 | #endif | |
2212 | ||
2213 | if (skip_dev_init) | |
2214 | return 0; | |
2215 | ||
2216 | /* Init vga device */ | |
64e40d72 WD |
2217 | memset(&console_dev, 0, sizeof(console_dev)); |
2218 | strcpy(console_dev.name, "vga"); | |
f62f6469 WD |
2219 | console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */ |
2220 | console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM; | |
2221 | console_dev.putc = video_putc; /* 'putc' function */ | |
2222 | console_dev.puts = video_puts; /* 'puts' function */ | |
2223 | console_dev.tstc = NULL; /* 'tstc' function */ | |
2224 | console_dev.getc = NULL; /* 'getc' function */ | |
2225 | ||
2226 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) | |
2227 | /* Also init console device */ | |
2228 | console_dev.flags |= DEV_FLAGS_INPUT; | |
2229 | console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */ | |
2230 | console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */ | |
c609719b | 2231 | #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */ |
f62f6469 | 2232 | |
64e40d72 | 2233 | if (stdio_register(&console_dev) != 0) |
f62f6469 WD |
2234 | return 0; |
2235 | ||
2236 | /* Return success */ | |
2237 | return 1; | |
c609719b | 2238 | } |
c20ee073 SR |
2239 | |
2240 | void video_position_cursor(unsigned col, unsigned row) | |
2241 | { | |
2242 | console_col = min(col, CONSOLE_COLS - 1); | |
2243 | console_row = min(row, CONSOLE_ROWS - 1); | |
2244 | } | |
2245 | ||
2246 | int video_get_pixel_width(void) | |
2247 | { | |
2248 | return VIDEO_VISIBLE_COLS; | |
2249 | } | |
2250 | ||
2251 | int video_get_pixel_height(void) | |
2252 | { | |
2253 | return VIDEO_VISIBLE_ROWS; | |
2254 | } | |
2255 | ||
2256 | int video_get_screen_rows(void) | |
2257 | { | |
2258 | return CONSOLE_ROWS; | |
2259 | } | |
2260 | ||
2261 | int video_get_screen_columns(void) | |
2262 | { | |
2263 | return CONSOLE_COLS; | |
2264 | } | |
2265 | ||
2266 | void video_clear(void) | |
2267 | { | |
ae630574 DL |
2268 | if (!video_fb_address) |
2269 | return; | |
c20ee073 SR |
2270 | #ifdef VIDEO_HW_RECTFILL |
2271 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ | |
2272 | 0, /* dest pos x */ | |
2273 | 0, /* dest pos y */ | |
2274 | VIDEO_VISIBLE_COLS, /* frame width */ | |
2275 | VIDEO_VISIBLE_ROWS, /* frame height */ | |
2276 | bgx /* fill color */ | |
2277 | ); | |
2278 | #else | |
2279 | memsetl(video_fb_address, | |
2280 | (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx); | |
2281 | #endif | |
2282 | } |