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