]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * (C) Copyright 2002 ELTEC Elektronik AG | |
3 | * Frank Gottschling <fgottschling@eltec.de> | |
4 | * | |
5 | * See file CREDITS for list of people who contributed to this | |
6 | * project. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License as | |
10 | * published by the Free Software Foundation; either version 2 of | |
11 | * the License, or (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
21 | * MA 02111-1307 USA | |
22 | */ | |
23 | ||
24 | /* | |
25 | * cfb_console.c | |
26 | * | |
27 | * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel. | |
28 | * | |
29 | * At the moment only the 8x16 font is tested and the font fore- and | |
30 | * background color is limited to black/white/gray colors. The Linux | |
31 | * logo can be placed in the upper left corner and additional board | |
32 | * information strings (that normaly goes to serial port) can be drawed. | |
33 | * | |
34 | * The console driver can use the standard PC keyboard interface (i8042) | |
35 | * for character input. Character output goes to a memory mapped video | |
36 | * framebuffer with little or big-endian organisation. | |
37 | * With environment setting 'console=serial' the console i/o can be | |
38 | * forced to serial port. | |
39 | ||
40 | The driver uses graphic specific defines/parameters/functions: | |
41 | ||
42 | (for SMI LynxE graphic chip) | |
43 | ||
44 | CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810 | |
45 | VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian | |
46 | VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill | |
47 | VIDEO_HW_BITBLT - graphic driver supports hardware bit blt | |
48 | ||
49 | Console Parameters are set by graphic drivers global struct: | |
50 | ||
51 | VIDEO_VISIBLE_COLS - x resolution | |
52 | VIDEO_VISIBLE_ROWS - y resolution | |
53 | VIDEO_PIXEL_SIZE - storage size in byte per pixel | |
54 | VIDEO_DATA_FORMAT - graphical data format GDF | |
55 | VIDEO_FB_ADRS - start of video memory | |
56 | ||
57 | CONFIG_I8042_KBD - AT Keyboard driver for i8042 | |
58 | VIDEO_KBD_INIT_FCT - init function for keyboard | |
59 | VIDEO_TSTC_FCT - keyboard_tstc function | |
60 | VIDEO_GETC_FCT - keyboard_getc function | |
61 | ||
62 | CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with delay | |
63 | loop in VIDEO_TSTC_FCT (i8042) | |
64 | CFG_CONSOLE_BLINK_COUNT - value for delay loop - blink rate | |
65 | CONFIG_CONSOLE_TIME - display time/date in upper right corner, | |
66 | needs CFG_CMD_DATE and CONFIG_CONSOLE_CURSOR | |
67 | CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner | |
68 | CONFIG_CONSOLE_EXTRA_INFO - display additional board information strings | |
69 | that normaly goes to serial port. This define | |
70 | requires a board specific function: | |
71 | video_drawstring (VIDEO_INFO_X, | |
72 | VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT, | |
73 | info); | |
74 | that fills a info buffer at i=row. | |
75 | s.a: board/eltec/bab7xx. | |
76 | CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be initialised | |
77 | as an output only device. The Keyboard driver | |
78 | will not be set-up. This may be used, if you | |
79 | have none or more than one Keyboard devices | |
80 | (USB Keyboard, AT Keyboard). | |
81 | ||
82 | CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last character. No | |
83 | blinking is provided. Uses the macros CURSOR_SET | |
84 | and CURSOR_OFF. | |
85 | CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability of the | |
86 | graphic chip. Uses the macro CURSOR_SET. | |
87 | ATTENTION: If booting an OS, the display driver | |
88 | must disable the hardware register of the graphic | |
89 | chip. Otherwise a blinking field is displayed | |
90 | */ | |
91 | ||
92 | #include <common.h> | |
93 | ||
94 | #ifdef CONFIG_CFB_CONSOLE | |
95 | ||
96 | /*****************************************************************************/ | |
97 | /* Console device defines with SMI graphic */ | |
98 | /* Any other graphic must change this section */ | |
99 | /*****************************************************************************/ | |
100 | ||
101 | #ifdef CONFIG_VIDEO_SMI_LYNXEM | |
102 | ||
103 | #define VIDEO_FB_LITTLE_ENDIAN | |
104 | #define VIDEO_HW_RECTFILL | |
105 | #define VIDEO_HW_BITBLT | |
106 | #endif | |
107 | ||
108 | /*****************************************************************************/ | |
109 | /* Defines for the CT69000 driver */ | |
110 | /*****************************************************************************/ | |
111 | #ifdef CONFIG_VIDEO_CT69000 | |
112 | ||
113 | #define VIDEO_FB_LITTLE_ENDIAN | |
114 | #define VIDEO_HW_RECTFILL | |
115 | #define VIDEO_HW_BITBLT | |
116 | #endif | |
117 | ||
118 | /*****************************************************************************/ | |
119 | /* Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc */ | |
120 | /*****************************************************************************/ | |
121 | #include <video_fb.h> | |
122 | ||
123 | /*****************************************************************************/ | |
124 | /* some Macros */ | |
125 | /*****************************************************************************/ | |
126 | #define VIDEO_VISIBLE_COLS (pGD->winSizeX) | |
127 | #define VIDEO_VISIBLE_ROWS (pGD->winSizeY) | |
128 | #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP) | |
129 | #define VIDEO_DATA_FORMAT (pGD->gdfIndex) | |
130 | #define VIDEO_FB_ADRS (pGD->frameAdrs) | |
131 | ||
132 | /*****************************************************************************/ | |
133 | /* Console device defines with i8042 keyboard controller */ | |
134 | /* Any other keyboard controller must change this section */ | |
135 | /*****************************************************************************/ | |
136 | ||
137 | #ifdef CONFIG_I8042_KBD | |
138 | #include <i8042.h> | |
139 | ||
140 | #define VIDEO_KBD_INIT_FCT i8042_kbd_init() | |
141 | #define VIDEO_TSTC_FCT i8042_tstc | |
142 | #define VIDEO_GETC_FCT i8042_getc | |
143 | #endif | |
144 | ||
145 | /*****************************************************************************/ | |
146 | /* Console device */ | |
147 | /*****************************************************************************/ | |
148 | ||
149 | #include <version.h> | |
150 | #include <linux/types.h> | |
151 | #include <devices.h> | |
152 | #include <video_font.h> | |
153 | #ifdef CFG_CMD_DATE | |
154 | #include <rtc.h> | |
155 | ||
156 | #endif | |
157 | ||
158 | /*****************************************************************************/ | |
159 | /* Cursor definition: */ | |
160 | /* CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/i8042.c) to */ | |
161 | /* let the cursor blink. Uses the macros CURSOR_OFF */ | |
162 | /* and CURSOR_ON. */ | |
163 | /* CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No */ | |
164 | /* blinking is provided. Uses the macros CURSOR_SET */ | |
165 | /* and CURSOR_OFF. */ | |
166 | /* CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the */ | |
167 | /* graphic chip. Uses the macro CURSOR_SET. */ | |
168 | /* ATTENTION: If booting an OS, the display driver */ | |
169 | /* must disable the hardware register of the graphic */ | |
170 | /* chip. Otherwise a blinking field is displayed */ | |
171 | /*****************************************************************************/ | |
172 | #if !defined(CONFIG_CONSOLE_CURSOR) && \ | |
173 | !defined(CONFIG_VIDEO_SW_CURSOR) && \ | |
174 | !defined(CONFIG_VIDEO_HW_CURSOR) | |
175 | /* no Cursor defined */ | |
176 | #define CURSOR_ON | |
177 | #define CURSOR_OFF | |
178 | #define CURSOR_SET | |
179 | #endif | |
180 | ||
181 | #ifdef CONFIG_CONSOLE_CURSOR | |
182 | #ifdef CURSOR_ON | |
183 | #error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined | |
184 | #endif | |
185 | void console_cursor (int state); | |
186 | #define CURSOR_ON console_cursor(1); | |
187 | #define CURSOR_OFF console_cursor(0); | |
188 | #define CURSOR_SET | |
189 | #ifndef CONFIG_I8042_KBD | |
190 | #warning Cursor drawing on/off needs timer function s.a. drivers/i8042.c | |
191 | #endif | |
192 | #else | |
193 | #ifdef CONFIG_CONSOLE_TIME | |
194 | #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME | |
195 | #endif | |
196 | #endif /* CONFIG_CONSOLE_CURSOR */ | |
197 | ||
198 | #ifdef CONFIG_VIDEO_SW_CURSOR | |
199 | #ifdef CURSOR_ON | |
200 | #error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined | |
201 | #endif | |
202 | #define CURSOR_ON | |
203 | #define CURSOR_OFF video_putchar(console_col * VIDEO_FONT_WIDTH,\ | |
204 | console_row * VIDEO_FONT_HEIGHT, ' '); | |
205 | #define CURSOR_SET video_set_cursor(); | |
206 | #endif /* CONFIG_VIDEO_SW_CURSOR */ | |
207 | ||
208 | ||
209 | #ifdef CONFIG_VIDEO_HW_CURSOR | |
210 | #ifdef CURSOR_ON | |
211 | #error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined | |
212 | #endif | |
213 | #define CURSOR_ON | |
214 | #define CURSOR_OFF | |
215 | #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \ | |
216 | (console_row * VIDEO_FONT_HEIGHT) + VIDEO_LOGO_HEIGHT); | |
217 | #endif /* CONFIG_VIDEO_HW_CURSOR */ | |
218 | ||
219 | #ifdef CONFIG_VIDEO_LOGO | |
220 | #define LINUX_LOGO_WIDTH 80 | |
221 | #define LINUX_LOGO_HEIGHT 80 | |
222 | #define LINUX_LOGO_COLORS 214 | |
223 | #define LINUX_LOGO_LUT_OFFSET 0x20 | |
224 | #define __initdata | |
225 | #include <linux_logo.h> | |
226 | #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH | |
227 | #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT | |
228 | ||
229 | #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH) | |
230 | #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2) | |
231 | #else | |
232 | #define VIDEO_LOGO_WIDTH 0 | |
233 | #define VIDEO_LOGO_HEIGHT 0 | |
234 | #endif | |
235 | ||
236 | #define VIDEO_COLS VIDEO_VISIBLE_COLS | |
237 | #define VIDEO_ROWS VIDEO_VISIBLE_ROWS | |
238 | #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) | |
239 | #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) | |
240 | #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) | |
241 | #define VIDEO_BURST_LEN (VIDEO_COLS/8) | |
242 | ||
243 | #ifdef CONFIG_VIDEO_LOGO | |
244 | #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT) | |
245 | #else | |
246 | #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT) | |
247 | #endif | |
248 | ||
249 | #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH) | |
250 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN) | |
251 | #define CONSOLE_ROW_FIRST (video_console_address) | |
252 | #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE) | |
253 | #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE) | |
254 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) | |
255 | #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) | |
256 | ||
257 | /* Macros */ | |
258 | #ifdef VIDEO_FB_LITTLE_ENDIAN | |
259 | #define SWAP16(x) ((((x) & 0x00ff) << 8) | ( (x) >> 8)) | |
260 | #define SWAP32(x) ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8)|\ | |
261 | (((x) & 0x00ff0000) >> 8) | (((x) & 0xff000000) >> 24) ) | |
262 | #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | (((x) & 0x0000ff00) >> 8)|\ | |
263 | (((x) & 0x00ff0000) << 8) | (((x) & 0xff000000) >> 8) ) | |
264 | #else | |
265 | #define SWAP16(x) (x) | |
266 | #define SWAP32(x) (x) | |
267 | #define SHORTSWAP32(x) (x) | |
268 | #endif | |
269 | ||
270 | #if defined(DEBUG) || defined(DEBUG_CFB_CONSOLE) | |
271 | #define PRINTD(x) printf(x) | |
272 | #else | |
273 | #define PRINTD(x) | |
274 | #endif | |
275 | ||
276 | ||
277 | #ifdef CONFIG_CONSOLE_EXTRA_INFO | |
278 | extern void video_get_info_str ( /* setup a board string: type, speed, etc. */ | |
279 | int line_number, /* location to place info string beside logo */ | |
280 | char *info /* buffer for info string */ | |
281 | ); | |
282 | ||
283 | #endif | |
284 | ||
285 | /* Locals */ | |
286 | static GraphicDevice *pGD; /* Pointer to Graphic array */ | |
287 | ||
288 | static void *video_fb_address; /* frame buffer address */ | |
289 | static void *video_console_address; /* console buffer start address */ | |
290 | ||
291 | static int console_col = 0; /* cursor col */ | |
292 | static int console_row = 0; /* cursor row */ | |
293 | ||
294 | static u32 eorx, fgx, bgx; /* color pats */ | |
295 | ||
296 | static const int video_font_draw_table8[] = { | |
297 | 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, | |
298 | 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, | |
299 | 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, | |
300 | 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff }; | |
301 | ||
302 | static const int video_font_draw_table15[] = { | |
303 | 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff }; | |
304 | ||
305 | static const int video_font_draw_table16[] = { | |
306 | 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff }; | |
307 | ||
308 | static const int video_font_draw_table24[16][3] = { | |
309 | { 0x00000000, 0x00000000, 0x00000000 }, | |
310 | { 0x00000000, 0x00000000, 0x00ffffff }, | |
311 | { 0x00000000, 0x0000ffff, 0xff000000 }, | |
312 | { 0x00000000, 0x0000ffff, 0xffffffff }, | |
313 | { 0x000000ff, 0xffff0000, 0x00000000 }, | |
314 | { 0x000000ff, 0xffff0000, 0x00ffffff }, | |
315 | { 0x000000ff, 0xffffffff, 0xff000000 }, | |
316 | { 0x000000ff, 0xffffffff, 0xffffffff }, | |
317 | { 0xffffff00, 0x00000000, 0x00000000 }, | |
318 | { 0xffffff00, 0x00000000, 0x00ffffff }, | |
319 | { 0xffffff00, 0x0000ffff, 0xff000000 }, | |
320 | { 0xffffff00, 0x0000ffff, 0xffffffff }, | |
321 | { 0xffffffff, 0xffff0000, 0x00000000 }, | |
322 | { 0xffffffff, 0xffff0000, 0x00ffffff }, | |
323 | { 0xffffffff, 0xffffffff, 0xff000000 }, | |
324 | { 0xffffffff, 0xffffffff, 0xffffffff } }; | |
325 | ||
326 | static const int video_font_draw_table32[16][4] = { | |
327 | { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, | |
328 | { 0x00000000, 0x00000000, 0x00000000, 0x00ffffff }, | |
329 | { 0x00000000, 0x00000000, 0x00ffffff, 0x00000000 }, | |
330 | { 0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff }, | |
331 | { 0x00000000, 0x00ffffff, 0x00000000, 0x00000000 }, | |
332 | { 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff }, | |
333 | { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000 }, | |
334 | { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff }, | |
335 | { 0x00ffffff, 0x00000000, 0x00000000, 0x00000000 }, | |
336 | { 0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff }, | |
337 | { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000 }, | |
338 | { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff }, | |
339 | { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000 }, | |
340 | { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff }, | |
341 | { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000 }, | |
342 | { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff } }; | |
343 | ||
344 | ||
345 | /******************************************************************************/ | |
346 | ||
347 | ||
348 | static void video_drawchars (int xx, int yy, unsigned char *s, int count) | |
349 | { | |
350 | u8 *cdat, *dest, *dest0; | |
351 | int rows, offset, c; | |
352 | ||
353 | offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE; | |
354 | dest0 = video_fb_address + offset; | |
355 | ||
356 | switch (VIDEO_DATA_FORMAT) | |
357 | { | |
358 | case GDF__8BIT_INDEX: | |
359 | case GDF__8BIT_332RGB: | |
360 | while (count--) | |
361 | { | |
362 | c = *s ; | |
363 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
364 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--; dest += VIDEO_LINE_LEN) | |
365 | { | |
366 | u8 bits = *cdat++; | |
367 | ((u32 *)dest)[0] = (video_font_draw_table8[bits >> 4] & eorx) ^ bgx; | |
368 | ((u32 *)dest)[1] = (video_font_draw_table8[bits & 15] & eorx) ^ bgx; | |
369 | } | |
370 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
371 | s++; | |
372 | } | |
373 | break; | |
374 | ||
375 | case GDF_15BIT_555RGB: | |
376 | while (count--) | |
377 | { | |
378 | c = *s ; | |
379 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
380 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--; dest += VIDEO_LINE_LEN) | |
381 | { | |
382 | u8 bits = *cdat++; | |
383 | ((u32 *)dest)[0] = SHORTSWAP32((video_font_draw_table15[bits >> 6] & eorx) ^ bgx); | |
384 | ((u32 *)dest)[1] = SHORTSWAP32((video_font_draw_table15[bits >> 4 & 3] & eorx) ^ bgx); | |
385 | ((u32 *)dest)[2] = SHORTSWAP32((video_font_draw_table15[bits >> 2 & 3] & eorx) ^ bgx); | |
386 | ((u32 *)dest)[3] = SHORTSWAP32((video_font_draw_table15[bits & 3] & eorx) ^ bgx); | |
387 | } | |
388 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
389 | s++ ; | |
390 | } | |
391 | break; | |
392 | ||
393 | case GDF_16BIT_565RGB: | |
394 | while (count--) | |
395 | { | |
396 | c = *s ; | |
397 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
398 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--; dest += VIDEO_LINE_LEN) | |
399 | { | |
400 | u8 bits = *cdat++; | |
401 | ((u32 *)dest)[0] = SHORTSWAP32((video_font_draw_table16[bits >> 6] & eorx) ^ bgx); | |
402 | ((u32 *)dest)[1] = SHORTSWAP32((video_font_draw_table16[bits >> 4 & 3] & eorx) ^ bgx); | |
403 | ((u32 *)dest)[2] = SHORTSWAP32((video_font_draw_table16[bits >> 2 & 3] & eorx) ^ bgx); | |
404 | ((u32 *)dest)[3] = SHORTSWAP32((video_font_draw_table16[bits & 3] & eorx) ^ bgx); | |
405 | } | |
406 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
407 | s++ ; | |
408 | } | |
409 | break; | |
410 | ||
411 | case GDF_32BIT_X888RGB: | |
412 | while (count--) | |
413 | { | |
414 | c = *s ; | |
415 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
416 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--; dest += VIDEO_LINE_LEN) | |
417 | { | |
418 | u8 bits = *cdat++; | |
419 | ((u32 *)dest)[0] = SWAP32((video_font_draw_table32[bits >> 4][0] & eorx) ^ bgx); | |
420 | ((u32 *)dest)[1] = SWAP32((video_font_draw_table32[bits >> 4][1] & eorx) ^ bgx); | |
421 | ((u32 *)dest)[2] = SWAP32((video_font_draw_table32[bits >> 4][2] & eorx) ^ bgx); | |
422 | ((u32 *)dest)[3] = SWAP32((video_font_draw_table32[bits >> 4][3] & eorx) ^ bgx); | |
423 | ((u32 *)dest)[4] = SWAP32((video_font_draw_table32[bits & 15][0] & eorx) ^ bgx); | |
424 | ((u32 *)dest)[5] = SWAP32((video_font_draw_table32[bits & 15][1] & eorx) ^ bgx); | |
425 | ((u32 *)dest)[6] = SWAP32((video_font_draw_table32[bits & 15][2] & eorx) ^ bgx); | |
426 | ((u32 *)dest)[7] = SWAP32((video_font_draw_table32[bits & 15][3] & eorx) ^ bgx); | |
427 | } | |
428 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
429 | s++ ; | |
430 | } | |
431 | break; | |
432 | ||
433 | case GDF_24BIT_888RGB: | |
434 | while (count--) | |
435 | { | |
436 | c = *s ; | |
437 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; | |
438 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--; dest += VIDEO_LINE_LEN) | |
439 | { | |
440 | u8 bits = *cdat++; | |
441 | ((u32 *)dest)[0] = (video_font_draw_table24[bits >> 4][0] & eorx) ^ bgx; | |
442 | ((u32 *)dest)[1] = (video_font_draw_table24[bits >> 4][1] & eorx) ^ bgx; | |
443 | ((u32 *)dest)[2] = (video_font_draw_table24[bits >> 4][2] & eorx) ^ bgx; | |
444 | ((u32 *)dest)[3] = (video_font_draw_table24[bits & 15][0] & eorx) ^ bgx; | |
445 | ((u32 *)dest)[4] = (video_font_draw_table24[bits & 15][1] & eorx) ^ bgx; | |
446 | ((u32 *)dest)[5] = (video_font_draw_table24[bits & 15][2] & eorx) ^ bgx; | |
447 | } | |
448 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; | |
449 | s++ ; | |
450 | } | |
451 | break; | |
452 | } | |
453 | } | |
454 | ||
455 | /*****************************************************************************/ | |
456 | ||
457 | static inline void video_drawstring(int xx, int yy, unsigned char *s) | |
458 | { | |
459 | video_drawchars (xx, yy, s, strlen(s)); | |
460 | } | |
461 | ||
462 | /*****************************************************************************/ | |
463 | ||
464 | static void video_putchar(int xx, int yy, unsigned char c) | |
465 | { | |
466 | #ifdef CONFIG_VIDEO_LOGO | |
467 | video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1); | |
468 | #else | |
469 | video_drawchars (xx, yy, &c, 1); | |
470 | #endif | |
471 | } | |
472 | ||
473 | /*****************************************************************************/ | |
474 | #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR) | |
475 | static void video_set_cursor(void) | |
476 | { | |
477 | /* swap drawing colors */ | |
478 | eorx = fgx; | |
479 | fgx = bgx; | |
480 | bgx = eorx; | |
481 | eorx = fgx ^ bgx; | |
482 | /* draw cursor */ | |
483 | video_putchar (console_col * VIDEO_FONT_WIDTH, | |
484 | console_row * VIDEO_FONT_HEIGHT, ' '); | |
485 | /* restore drawing colors */ | |
486 | eorx = fgx; | |
487 | fgx = bgx; | |
488 | bgx = eorx; | |
489 | eorx = fgx ^ bgx; | |
490 | } | |
491 | #endif | |
492 | /*****************************************************************************/ | |
493 | #ifdef CONFIG_CONSOLE_CURSOR | |
494 | void console_cursor (int state) | |
495 | { | |
496 | static int last_state = 0; | |
497 | #ifdef CONFIG_CONSOLE_TIME | |
498 | struct rtc_time tm; | |
499 | char info[16]; | |
500 | ||
501 | /* time update only if cursor is on (faster scroll) */ | |
502 | if (state) | |
503 | { | |
504 | rtc_get (&tm); | |
505 | ||
506 | sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min, tm.tm_sec); | |
507 | video_drawstring(VIDEO_VISIBLE_COLS-10*VIDEO_FONT_WIDTH, | |
508 | VIDEO_INFO_Y, info); | |
509 | ||
510 | sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon, tm.tm_year); | |
511 | video_drawstring(VIDEO_VISIBLE_COLS-10*VIDEO_FONT_WIDTH, | |
512 | VIDEO_INFO_Y+1*VIDEO_FONT_HEIGHT, info); | |
513 | } | |
514 | #endif | |
515 | ||
516 | if (state && (last_state != state)) | |
517 | { | |
518 | video_set_cursor(); | |
519 | } | |
520 | ||
521 | if (!state && (last_state != state)) | |
522 | { | |
523 | /* clear cursor */ | |
524 | video_putchar (console_col * VIDEO_FONT_WIDTH, | |
525 | console_row * VIDEO_FONT_HEIGHT, ' '); | |
526 | } | |
527 | ||
528 | last_state = state; | |
529 | } | |
530 | #endif | |
531 | ||
532 | /*****************************************************************************/ | |
533 | ||
534 | #ifndef VIDEO_HW_RECTFILL | |
535 | static void memsetl (int *p, int c, int v) | |
536 | { | |
537 | while (c--) | |
538 | *(p++) = v; | |
539 | } | |
540 | #endif | |
541 | ||
542 | /*****************************************************************************/ | |
543 | ||
544 | #ifndef VIDEO_HW_BITBLT | |
545 | static void memcpyl (int *d, int *s, int c) | |
546 | { | |
547 | while (c--) | |
548 | *(d++) = *(s++); | |
549 | } | |
550 | #endif | |
551 | ||
552 | /*****************************************************************************/ | |
553 | ||
554 | static void console_scrollup (void) | |
555 | { | |
556 | /* copy up rows ignoring the first one */ | |
557 | ||
558 | #ifdef VIDEO_HW_BITBLT | |
559 | video_hw_bitblt ( | |
560 | VIDEO_PIXEL_SIZE, /* bytes per pixel */ | |
561 | 0, /* source pos x */ | |
562 | VIDEO_LOGO_HEIGHT + VIDEO_FONT_HEIGHT, /* source pos y */ | |
563 | 0, /* dest pos x */ | |
564 | VIDEO_LOGO_HEIGHT, /* dest pos y */ | |
565 | VIDEO_VISIBLE_COLS, /* frame width */ | |
566 | VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT - VIDEO_FONT_HEIGHT /* frame height */ | |
567 | ); | |
568 | #else | |
569 | memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2); | |
570 | #endif | |
571 | ||
572 | /* clear the last one */ | |
573 | #ifdef VIDEO_HW_RECTFILL | |
574 | video_hw_rectfill ( | |
575 | VIDEO_PIXEL_SIZE, /* bytes per pixel */ | |
576 | 0, /* dest pos x */ | |
577 | VIDEO_VISIBLE_ROWS - VIDEO_FONT_HEIGHT, /* dest pos y */ | |
578 | VIDEO_VISIBLE_COLS, /* frame width */ | |
579 | VIDEO_FONT_HEIGHT, /* frame height */ | |
580 | CONSOLE_BG_COL /* fill color */ | |
581 | ); | |
582 | #else | |
583 | memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, CONSOLE_BG_COL); | |
584 | #endif | |
585 | } | |
586 | ||
587 | /*****************************************************************************/ | |
588 | ||
589 | static void console_back (void) | |
590 | { | |
591 | CURSOR_OFF | |
592 | console_col--; | |
593 | ||
594 | if (console_col < 0) | |
595 | { | |
596 | console_col = CONSOLE_COLS - 1; | |
597 | console_row--; | |
598 | if (console_row < 0) | |
599 | console_row = 0; | |
600 | } | |
601 | video_putchar (console_col * VIDEO_FONT_WIDTH, | |
602 | console_row * VIDEO_FONT_HEIGHT, ' '); | |
603 | } | |
604 | ||
605 | /*****************************************************************************/ | |
606 | ||
607 | static void console_newline (void) | |
608 | { | |
609 | CURSOR_OFF | |
610 | console_row++; | |
611 | console_col = 0; | |
612 | ||
613 | /* Check if we need to scroll the terminal */ | |
614 | if (console_row >= CONSOLE_ROWS) | |
615 | { | |
616 | /* Scroll everything up */ | |
617 | console_scrollup (); | |
618 | ||
619 | /* Decrement row number */ | |
620 | console_row--; | |
621 | } | |
622 | } | |
623 | ||
624 | /*****************************************************************************/ | |
625 | ||
626 | void video_putc (const char c) | |
627 | { | |
628 | switch (c) | |
629 | { | |
630 | case 13: /* ignore */ | |
631 | break; | |
632 | ||
633 | case '\n': /* next line */ | |
634 | console_newline(); | |
635 | break; | |
636 | ||
637 | case 9: /* tab 8 */ | |
638 | CURSOR_OFF | |
639 | console_col |= 0x0008; | |
640 | console_col &= ~0x0007; | |
641 | ||
642 | if (console_col >= CONSOLE_COLS) | |
643 | console_newline(); | |
644 | break; | |
645 | ||
646 | case 8: /* backspace */ | |
647 | console_back(); | |
648 | break; | |
649 | ||
650 | default: /* draw the char */ | |
651 | video_putchar (console_col * VIDEO_FONT_WIDTH, | |
652 | console_row * VIDEO_FONT_HEIGHT, c); | |
653 | console_col++ ; | |
654 | ||
655 | /* check for newline */ | |
656 | if (console_col >= CONSOLE_COLS) | |
657 | console_newline(); | |
658 | } | |
659 | CURSOR_SET | |
660 | } | |
661 | ||
662 | ||
663 | ||
664 | /*****************************************************************************/ | |
665 | ||
666 | void video_puts (const char *s) | |
667 | { | |
668 | int count = strlen(s); | |
669 | ||
670 | while(count--) | |
671 | video_putc(*s++); | |
672 | } | |
673 | ||
674 | /*****************************************************************************/ | |
675 | ||
676 | #ifdef CONFIG_VIDEO_LOGO | |
677 | void logo_plot (void *screen, int width, int x, int y) | |
678 | { | |
679 | int skip = (width - LINUX_LOGO_WIDTH) * VIDEO_PIXEL_SIZE, | |
680 | xcount, i, | |
681 | ycount = LINUX_LOGO_HEIGHT; | |
682 | unsigned char | |
683 | *source = linux_logo, | |
684 | *dest = (unsigned char *) screen + ((y * width * VIDEO_PIXEL_SIZE) + x), | |
685 | r, g, b; | |
686 | ||
687 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) | |
688 | { | |
689 | for (i = 0; i < LINUX_LOGO_COLORS; i++) | |
690 | { | |
691 | r = (unsigned char)linux_logo_red [i]; | |
692 | g = (unsigned char)linux_logo_green[i]; | |
693 | b = (unsigned char)linux_logo_blue [i]; | |
694 | video_set_lut (LINUX_LOGO_LUT_OFFSET + i, r, g, b); | |
695 | } | |
696 | } | |
697 | ||
698 | while (ycount--) | |
699 | { | |
700 | xcount = LINUX_LOGO_WIDTH; | |
701 | while (xcount--) | |
702 | { | |
703 | r = (unsigned char)linux_logo_red [*source - LINUX_LOGO_LUT_OFFSET]; | |
704 | g = (unsigned char)linux_logo_green[*source - LINUX_LOGO_LUT_OFFSET]; | |
705 | b = (unsigned char)linux_logo_blue [*source - LINUX_LOGO_LUT_OFFSET]; | |
706 | ||
707 | switch (VIDEO_DATA_FORMAT) | |
708 | { | |
709 | case GDF__8BIT_INDEX: | |
710 | *dest = *source; | |
711 | break; | |
712 | case GDF__8BIT_332RGB: | |
713 | *dest = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); | |
714 | break; | |
715 | case GDF_15BIT_555RGB: | |
716 | *(unsigned short *)dest = | |
717 | SWAP16((unsigned short)(((r>>3)<<10) | ((g>>3)<<5) | (b>>3))); | |
718 | break; | |
719 | case GDF_16BIT_565RGB: | |
720 | *(unsigned short *)dest = | |
721 | SWAP16((unsigned short)(((r>>3)<<11) | ((g>>2)<<5) | (b>>3))); | |
722 | break; | |
723 | case GDF_32BIT_X888RGB: | |
724 | *(unsigned long *)dest = | |
725 | SWAP32((unsigned long)((r<<16) | (g<<8) | b)); | |
726 | break; | |
727 | case GDF_24BIT_888RGB: | |
728 | #ifdef VIDEO_FB_LITTLE_ENDIAN | |
729 | dest[0] = b; | |
730 | dest[1] = g; | |
731 | dest[2] = r; | |
732 | #else | |
733 | dest[0] = r; | |
734 | dest[1] = g; | |
735 | dest[2] = b; | |
736 | #endif | |
737 | break; | |
738 | } | |
739 | source++; | |
740 | dest += VIDEO_PIXEL_SIZE; | |
741 | } | |
742 | dest += skip; | |
743 | } | |
744 | } | |
745 | ||
746 | ||
747 | /*****************************************************************************/ | |
748 | ||
749 | static void *video_logo (void) | |
750 | { | |
751 | char info[128]; | |
752 | ||
753 | logo_plot (video_fb_address, VIDEO_COLS, 0, 0); | |
754 | ||
755 | sprintf(info, " %s (%s - %s)", U_BOOT_VERSION, __DATE__, __TIME__); | |
756 | video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info); | |
757 | ||
758 | #ifdef CONFIG_CONSOLE_EXTRA_INFO | |
759 | { | |
760 | int i, n = ((VIDEO_LOGO_HEIGHT-VIDEO_FONT_HEIGHT)/VIDEO_FONT_HEIGHT); | |
761 | ||
762 | for (i = 1; i < n; i++) | |
763 | { | |
764 | video_get_info_str (i, info); | |
765 | if (*info) | |
766 | video_drawstring (VIDEO_INFO_X, | |
767 | VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT, info); | |
768 | } | |
769 | } | |
770 | #endif | |
771 | ||
772 | return (video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN); | |
773 | } | |
774 | #endif | |
775 | ||
776 | ||
777 | /*****************************************************************************/ | |
778 | ||
779 | static int video_init(void) | |
780 | { | |
781 | unsigned char color8; | |
782 | ||
783 | if ((pGD=video_hw_init()) == NULL) | |
784 | return -1; | |
785 | ||
786 | video_fb_address = (void*)VIDEO_FB_ADRS; | |
787 | #ifdef CONFIG_VIDEO_HW_CURSOR | |
788 | video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT); | |
789 | #endif | |
790 | ||
791 | /* Init drawing pats */ | |
792 | switch (VIDEO_DATA_FORMAT) | |
793 | { | |
794 | case GDF__8BIT_INDEX: | |
795 | video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL); | |
796 | video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL); | |
797 | fgx = 0x01010101; | |
798 | bgx = 0x00000000; | |
799 | break; | |
800 | case GDF__8BIT_332RGB: | |
801 | color8 = ((CONSOLE_FG_COL & 0xe0) | ((CONSOLE_FG_COL>>3) & 0x1c) | CONSOLE_FG_COL>>6); | |
802 | fgx = (color8<<24) | (color8<<16) | (color8<<8) | color8; | |
803 | color8 = ((CONSOLE_BG_COL & 0xe0) | ((CONSOLE_BG_COL>>3) & 0x1c) | CONSOLE_BG_COL>>6); | |
804 | bgx = (color8<<24) | (color8<<16) | (color8<<8) | color8; | |
805 | break; | |
806 | case GDF_15BIT_555RGB: | |
807 | fgx = (((CONSOLE_FG_COL>>3)<<26) | ((CONSOLE_FG_COL>>3)<<21) | ((CONSOLE_FG_COL>>3)<<16) | | |
808 | ((CONSOLE_FG_COL>>3)<<10) | ((CONSOLE_FG_COL>>3)<<5) | (CONSOLE_FG_COL>>3)); | |
809 | bgx = (((CONSOLE_BG_COL>>3)<<26) | ((CONSOLE_BG_COL>>3)<<21) | ((CONSOLE_BG_COL>>3)<<16) | | |
810 | ((CONSOLE_BG_COL>>3)<<10) | ((CONSOLE_BG_COL>>3)<<5) | (CONSOLE_BG_COL>>3)); | |
811 | break; | |
812 | case GDF_16BIT_565RGB: | |
813 | fgx = (((CONSOLE_FG_COL>>3)<<27) | ((CONSOLE_FG_COL>>2)<<21) | ((CONSOLE_FG_COL>>3)<<16) | | |
814 | ((CONSOLE_FG_COL>>3)<<11) | ((CONSOLE_FG_COL>>2)<<5) | (CONSOLE_FG_COL>>3)); | |
815 | bgx = (((CONSOLE_BG_COL>>3)<<27) | ((CONSOLE_BG_COL>>2)<<21) | ((CONSOLE_BG_COL>>3)<<16) | | |
816 | ((CONSOLE_BG_COL>>3)<<11) | ((CONSOLE_BG_COL>>2)<<5) | (CONSOLE_BG_COL>>3)); | |
817 | break; | |
818 | case GDF_32BIT_X888RGB: | |
819 | fgx = (CONSOLE_FG_COL<<16) | (CONSOLE_FG_COL<<8) | CONSOLE_FG_COL; | |
820 | bgx = (CONSOLE_BG_COL<<16) | (CONSOLE_BG_COL<<8) | CONSOLE_BG_COL; | |
821 | break; | |
822 | case GDF_24BIT_888RGB: | |
823 | fgx = (CONSOLE_FG_COL<<24) | (CONSOLE_FG_COL<<16) | (CONSOLE_FG_COL<<8) | CONSOLE_FG_COL; | |
824 | bgx = (CONSOLE_BG_COL<<24) | (CONSOLE_BG_COL<<16) | (CONSOLE_BG_COL<<8) | CONSOLE_BG_COL; | |
825 | break; | |
826 | } | |
827 | eorx = fgx ^ bgx; | |
828 | ||
829 | #ifdef CONFIG_VIDEO_LOGO | |
830 | /* Plot the logo and get start point of console */ | |
831 | PRINTD("Video: Drawing the logo ...\n"); | |
832 | video_console_address = video_logo(); | |
833 | #else | |
834 | video_console_address = video_fb_address; | |
835 | #endif | |
836 | ||
837 | /* Initialize the console */ | |
838 | console_col = 0; | |
839 | console_row = 0; | |
840 | ||
841 | return 0 ; | |
842 | } | |
843 | ||
844 | ||
845 | /*****************************************************************************/ | |
846 | ||
847 | int drv_video_init (void) | |
848 | { | |
849 | int skip_dev_init; | |
850 | device_t console_dev; | |
851 | char *penv; | |
852 | ||
853 | skip_dev_init = 0; | |
854 | ||
855 | /* Force console i/o to serial ? */ | |
856 | if ((penv = getenv ("console")) != NULL) | |
857 | if (strcmp (penv, "serial") == 0) | |
858 | return 0; | |
859 | ||
860 | /* Init video chip - returns with framebuffer cleared */ | |
861 | if (video_init() == -1) | |
862 | skip_dev_init = 1; | |
863 | #ifdef CONFIG_VGA_AS_SINGLE_DEVICE | |
864 | /* Devices VGA and Keyboard will be assigned seperately */ | |
865 | /* Init vga device */ | |
866 | if (!skip_dev_init) | |
867 | { | |
868 | memset (&console_dev, 0, sizeof(console_dev)); | |
869 | strcpy(console_dev.name, "vga"); | |
870 | console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */ | |
871 | console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM; | |
872 | console_dev.putc = video_putc; /* 'putc' function */ | |
873 | console_dev.puts = video_puts; /* 'puts' function */ | |
874 | console_dev.tstc = NULL; /* 'tstc' function */ | |
875 | console_dev.getc = NULL; /* 'getc' function */ | |
876 | ||
877 | if (device_register (&console_dev) == 0) | |
878 | return 1; | |
879 | } | |
880 | #else | |
881 | PRINTD("KBD: Keyboard init ...\n"); | |
882 | if (VIDEO_KBD_INIT_FCT == -1) | |
883 | skip_dev_init = 1; | |
884 | ||
885 | /* Init console device */ | |
886 | if (!skip_dev_init) | |
887 | { | |
888 | memset (&console_dev, 0, sizeof(console_dev)); | |
889 | strcpy(console_dev.name, "console"); | |
890 | console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */ | |
891 | console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; | |
892 | console_dev.putc = video_putc; /* 'putc' function */ | |
893 | console_dev.puts = video_puts; /* 'puts' function */ | |
894 | console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */ | |
895 | console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */ | |
896 | ||
897 | if (device_register (&console_dev) == 0) | |
898 | return 1; | |
899 | } | |
900 | #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */ | |
901 | /* No console dev available */ | |
902 | return 0; | |
903 | } | |
904 | ||
905 | #endif /* CONFIG_CFB_CONSOLE */ | |
906 | ||
907 | ||
908 | ||
909 | ||
910 | ||
911 | ||
912 |