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