]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/cfb_console.c
* Switch LWMON board default config from FRAM to EEPROM;
[karo-tx-uboot.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
685 void video_puts (const char *s)
686 {
687     int count = strlen(s);
688
689     while(count--)
690         video_putc(*s++);
691 }
692
693 /*****************************************************************************/
694
695 #ifdef CONFIG_VIDEO_LOGO
696 void logo_plot (void *screen, int width, int x, int y)
697 {
698
699     int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE,
700         xcount, i,
701         ycount = VIDEO_LOGO_HEIGHT;
702     unsigned char
703         *source,
704         *dest   = (unsigned char *) screen + ((y * width * VIDEO_PIXEL_SIZE) + x),
705         r, g, b, *logo_red, *logo_blue, *logo_green;
706
707 #ifdef CONFIG_VIDEO_BMP_LOGO
708     source = bmp_logo_bitmap;
709     
710     /* Allocate temporary space for computing colormap                       */
711     logo_red = malloc (BMP_LOGO_COLORS);
712     logo_green = malloc (BMP_LOGO_COLORS);
713     logo_blue = malloc (BMP_LOGO_COLORS);
714     /* Compute color map                                                     */
715     for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
716         logo_red [i] = (bmp_logo_palette [i] & 0x0f00) >> 4;
717         logo_green [i] = (bmp_logo_palette [i] & 0x00f0);
718         logo_blue [i] = (bmp_logo_palette [i] & 0x000f) << 4;
719     }
720 #else
721     source = linux_logo;
722     logo_red = linux_logo_red;
723     logo_green = linux_logo_green;
724     logo_blue = linux_logo_blue;
725 #endif
726     
727     if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX)
728     {
729         for (i = 0; i < VIDEO_LOGO_COLORS; i++)
730         {
731             video_set_lut (i + VIDEO_LOGO_LUT_OFFSET,
732                            logo_red [i], logo_green [i], logo_blue [i]);
733         }
734     }
735
736     while (ycount--)
737     {
738         xcount = VIDEO_LOGO_WIDTH;
739         while (xcount--)
740         {
741             r = logo_red [*source - VIDEO_LOGO_LUT_OFFSET];
742             g = logo_green [*source - VIDEO_LOGO_LUT_OFFSET];
743             b = logo_blue [*source - VIDEO_LOGO_LUT_OFFSET];
744             
745             switch (VIDEO_DATA_FORMAT)
746             {
747             case GDF__8BIT_INDEX:
748                 *dest = *source;
749                 break;
750             case GDF__8BIT_332RGB:
751                 *dest = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6);
752                 break;
753             case GDF_15BIT_555RGB:
754                 *(unsigned short *)dest =
755                     SWAP16((unsigned short)(((r>>3)<<10) | ((g>>3)<<5) | (b>>3)));
756                 break;
757             case GDF_16BIT_565RGB:
758                 *(unsigned short *)dest =
759                     SWAP16((unsigned short)(((r>>3)<<11) | ((g>>2)<<5) | (b>>3)));
760                 break;
761             case GDF_32BIT_X888RGB:
762                 *(unsigned long  *)dest =
763                     SWAP32((unsigned long)((r<<16) | (g<<8) | b));
764                 break;
765             case GDF_24BIT_888RGB:
766 #ifdef VIDEO_FB_LITTLE_ENDIAN
767                 dest[0] = b;
768                 dest[1] = g;
769                 dest[2] = r;
770 #else
771                 dest[0] = r;
772                 dest[1] = g;
773                 dest[2] = b;
774 #endif
775                 break;
776             }
777             source++;
778             dest += VIDEO_PIXEL_SIZE;
779         }
780         dest += skip;
781     }
782 #ifdef CONFIG_VIDEO_BMP_LOGO
783     free (logo_red);
784     free (logo_green);
785     free (logo_blue);
786 #endif
787 }
788
789 /*****************************************************************************/
790
791 static void *video_logo (void)
792 {
793     char info[128];
794     extern char version_string;
795
796     logo_plot (video_fb_address, VIDEO_COLS, 0, 0);
797
798     sprintf(info, " %s", &version_string);
799     video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
800
801 #ifdef CONFIG_CONSOLE_EXTRA_INFO
802     {
803     int i, n = ((VIDEO_LOGO_HEIGHT-VIDEO_FONT_HEIGHT)/VIDEO_FONT_HEIGHT);
804
805     for (i = 1; i < n; i++)
806     {
807         video_get_info_str (i, info);
808         if (*info)
809         video_drawstring (VIDEO_INFO_X,
810                           VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT, info);
811     }
812     }
813 #endif
814
815     return (video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN);
816 }
817 #endif
818
819
820 /*****************************************************************************/
821
822 static int video_init(void)
823 {
824     unsigned char color8;
825
826     if ((pGD=video_hw_init()) == NULL)
827         return -1;
828
829     video_fb_address = (void*)VIDEO_FB_ADRS;
830 #ifdef CONFIG_VIDEO_HW_CURSOR
831     video_init_hw_cursor(VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
832 #endif
833
834     /* Init drawing pats */
835     switch (VIDEO_DATA_FORMAT)
836     {
837     case GDF__8BIT_INDEX:
838         video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL);
839         video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL);
840         fgx = 0x01010101;
841         bgx = 0x00000000;
842         break;
843     case GDF__8BIT_332RGB:
844         color8 = ((CONSOLE_FG_COL & 0xe0) | ((CONSOLE_FG_COL>>3) & 0x1c) | CONSOLE_FG_COL>>6);
845         fgx = (color8<<24) | (color8<<16) | (color8<<8) | color8;
846         color8 = ((CONSOLE_BG_COL & 0xe0) | ((CONSOLE_BG_COL>>3) & 0x1c) | CONSOLE_BG_COL>>6);
847         bgx = (color8<<24) | (color8<<16) | (color8<<8) | color8;
848         break;
849     case GDF_15BIT_555RGB:
850         fgx = (((CONSOLE_FG_COL>>3)<<26) | ((CONSOLE_FG_COL>>3)<<21) | ((CONSOLE_FG_COL>>3)<<16) |
851            ((CONSOLE_FG_COL>>3)<<10) | ((CONSOLE_FG_COL>>3)<<5)  |  (CONSOLE_FG_COL>>3));
852         bgx = (((CONSOLE_BG_COL>>3)<<26) | ((CONSOLE_BG_COL>>3)<<21) | ((CONSOLE_BG_COL>>3)<<16) |
853            ((CONSOLE_BG_COL>>3)<<10) | ((CONSOLE_BG_COL>>3)<<5)  |  (CONSOLE_BG_COL>>3));
854         break;
855     case GDF_16BIT_565RGB:
856         fgx = (((CONSOLE_FG_COL>>3)<<27) | ((CONSOLE_FG_COL>>2)<<21) | ((CONSOLE_FG_COL>>3)<<16) |
857            ((CONSOLE_FG_COL>>3)<<11) | ((CONSOLE_FG_COL>>2)<<5)  |  (CONSOLE_FG_COL>>3));
858         bgx = (((CONSOLE_BG_COL>>3)<<27) | ((CONSOLE_BG_COL>>2)<<21) | ((CONSOLE_BG_COL>>3)<<16) |
859            ((CONSOLE_BG_COL>>3)<<11) | ((CONSOLE_BG_COL>>2)<<5)  |  (CONSOLE_BG_COL>>3));
860         break;
861     case GDF_32BIT_X888RGB:
862         fgx = (CONSOLE_FG_COL<<16) | (CONSOLE_FG_COL<<8) | CONSOLE_FG_COL;
863         bgx = (CONSOLE_BG_COL<<16) | (CONSOLE_BG_COL<<8) | CONSOLE_BG_COL;
864         break;
865     case GDF_24BIT_888RGB:
866         fgx = (CONSOLE_FG_COL<<24) | (CONSOLE_FG_COL<<16) | (CONSOLE_FG_COL<<8) | CONSOLE_FG_COL;
867         bgx = (CONSOLE_BG_COL<<24) | (CONSOLE_BG_COL<<16) | (CONSOLE_BG_COL<<8) | CONSOLE_BG_COL;
868         break;
869     }
870     eorx = fgx ^ bgx;
871
872 #ifdef CONFIG_VIDEO_LOGO
873     /* Plot the logo and get start point of console */
874     PRINTD("Video: Drawing the logo ...\n");
875     video_console_address = video_logo();
876 #else
877     video_console_address = video_fb_address;
878 #endif
879
880     /* Initialize the console */
881     console_col  = 0;
882     console_row  = 0;
883
884     return 0 ;
885 }
886
887
888 /*****************************************************************************/
889
890 int drv_video_init (void)
891 {
892     int skip_dev_init;
893     device_t console_dev;
894     char *penv;
895
896     skip_dev_init = 0;
897
898      /* Force console i/o to serial ? */
899     if ((penv = getenv ("console")) != NULL)
900         if (strcmp (penv, "serial") == 0)
901             return 0;
902
903    /* Init video chip - returns with framebuffer cleared */
904     if (video_init() == -1)
905         skip_dev_init = 1;
906 #ifdef CONFIG_VGA_AS_SINGLE_DEVICE
907    /* Devices VGA and Keyboard will be assigned seperately */
908     /* Init vga device */
909     if (!skip_dev_init)
910     {
911         memset (&console_dev, 0, sizeof(console_dev));
912         strcpy(console_dev.name, "vga");
913         console_dev.ext   = DEV_EXT_VIDEO;    /* Video extensions */
914         console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
915         console_dev.putc  = video_putc;        /* 'putc' function */
916         console_dev.puts  = video_puts;        /* 'puts' function */
917         console_dev.tstc  = NULL;              /* 'tstc' function */
918         console_dev.getc  = NULL;              /* 'getc' function */
919
920         if (device_register (&console_dev) == 0)
921             return 1;
922     }
923 #else
924     PRINTD("KBD: Keyboard init ...\n");
925     if (VIDEO_KBD_INIT_FCT == -1)
926         skip_dev_init = 1;
927
928     /* Init console device */
929     if (!skip_dev_init)
930     {
931         memset (&console_dev, 0, sizeof(console_dev));
932         strcpy(console_dev.name, "console");
933         console_dev.ext   = DEV_EXT_VIDEO;    /* Video extensions */
934         console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
935         console_dev.putc  = video_putc;        /* 'putc' function */
936         console_dev.puts  = video_puts;        /* 'puts' function */
937         console_dev.tstc  = VIDEO_TSTC_FCT;    /* 'tstc' function */
938         console_dev.getc  = VIDEO_GETC_FCT;    /* 'getc' function */
939
940         if (device_register (&console_dev) == 0)
941             return 1;
942     }
943 #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
944     /* No console dev available */
945     return 0;
946 }
947
948 #endif /* CONFIG_CFB_CONSOLE */
949
950
951
952
953
954
955