]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/mpc8xx/video.c
Patch by Guillaume Alexandre,, 04 Nov 2002:
[karo-tx-uboot.git] / cpu / mpc8xx / video.c
1 /*
2  * (C) Copyright 2000
3  * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
4  * (C) Copyright 2002
5  * Wolfgang Denk, wd@denx.de
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25
26 /* #define      DEBUG */
27
28 /************************************************************************/
29 /* ** HEADER FILES                                                      */
30 /************************************************************************/
31
32 #include <stdarg.h>
33 #include <common.h>
34 #include <config.h>
35 #include <version.h>
36 #include <i2c.h>
37 #include <linux/types.h>
38 #include <devices.h>
39
40 #ifdef CONFIG_VIDEO
41
42 /************************************************************************/
43 /* ** DEBUG SETTINGS                                                    */
44 /************************************************************************/
45
46 #if 0
47 #define VIDEO_DEBUG_COLORBARS   /* Force colorbars output */
48 #endif
49
50 /************************************************************************/
51 /* ** VIDEO MODE SETTINGS                                               */
52 /************************************************************************/
53
54 #if 0
55 #define VIDEO_MODE_EXTENDED             /* Allow screen size bigger than visible area */
56 #define VIDEO_MODE_NTSC
57 #endif
58
59 #define VIDEO_MODE_PAL
60
61 #if 0
62 #define VIDEO_BLINK                     /* This enables cursor blinking (under construction) */
63 #endif
64
65 #define VIDEO_INFO                      /* Show U-Boot information */
66 #define VIDEO_INFO_X            VIDEO_LOGO_WIDTH+8
67 #define VIDEO_INFO_Y            16
68
69 /************************************************************************/
70 /* ** VIDEO ENCODER CONSTANTS                                           */
71 /************************************************************************/
72
73 #ifdef CONFIG_VIDEO_ENCODER_AD7176
74
75 #include <video_ad7176.h>       /* Sets encoder data, mode, and visible and active area */
76
77 #define VIDEO_I2C               1
78 #define VIDEO_I2C_ADDR          CONFIG_VIDEO_ENCODER_AD7176_ADDR
79 #endif
80
81 #ifdef CONFIG_VIDEO_ENCODER_AD7177
82
83 #include <video_ad7177.h>       /* Sets encoder data, mode, and visible and active area */
84
85 #define VIDEO_I2C               1
86 #define VIDEO_I2C_ADDR          CONFIG_VIDEO_ENCODER_AD7177_ADDR
87 #endif
88
89 /************************************************************************/
90 /* ** VIDEO MODE CONSTANTS                                              */
91 /************************************************************************/
92
93 #ifdef VIDEO_MODE_EXTENDED
94 #define VIDEO_COLS      VIDEO_ACTIVE_COLS
95 #define VIDEO_ROWS      VIDEO_ACTIVE_ROWS
96 #else
97 #define VIDEO_COLS      VIDEO_VISIBLE_COLS
98 #define VIDEO_ROWS      VIDEO_VISIBLE_ROWS
99 #endif
100
101 #define VIDEO_PIXEL_SIZE        (VIDEO_MODE_BPP/8)
102 #define VIDEO_SIZE              (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)        /* Total size of buffer */
103 #define VIDEO_PIX_BLOCKS        (VIDEO_SIZE >> 2)       /* Number of ints */
104 #define VIDEO_LINE_LEN          (VIDEO_COLS*VIDEO_PIXEL_SIZE)   /* Number of bytes per line */
105 #define VIDEO_BURST_LEN         (VIDEO_COLS/8)
106
107 #ifdef VIDEO_MODE_YUYV
108 #define VIDEO_BG_COL    0x80D880D8      /* Background color in YUYV format */
109 #else
110 #define VIDEO_BG_COL    0xF8F8F8F8      /* Background color in RGB format */
111 #endif
112
113 /************************************************************************/
114 /* ** FONT AND LOGO DATA                                                */
115 /************************************************************************/
116
117 #include <video_font.h>                 /* Get font data, width and height */
118
119 #ifdef CONFIG_VIDEO_LOGO
120 #include <video_logo.h>                 /* Get logo data, width and height */
121
122 #define VIDEO_LOGO_WIDTH        DEF_U_BOOT_LOGO_WIDTH
123 #define VIDEO_LOGO_HEIGHT       DEF_U_BOOT_LOGO_HEIGHT
124 #define VIDEO_LOGO_ADDR         &u_boot_logo
125 #endif
126
127 /************************************************************************/
128 /* ** VIDEO CONTROLLER CONSTANTS                                        */
129 /************************************************************************/
130
131 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
132
133 #define VIDEO_VCCR_VON  0               /* Video controller ON */
134 #define VIDEO_VCCR_CSRC 1               /* Clock source */
135 #define VIDEO_VCCR_PDF  13              /* Pixel display format */
136 #define VIDEO_VCCR_IEN  11              /* Interrupt enable */
137
138 /* VSR - VIDEO STATUS REGISTER */
139
140 #define VIDEO_VSR_CAS   6               /* Active set */
141 #define VIDEO_VSR_EOF   0               /* End of frame */
142
143 /* VCMR - VIDEO COMMAND REGISTER */
144
145 #define VIDEO_VCMR_BD   0               /* Blank display */
146 #define VIDEO_VCMR_ASEL 1               /* Active set selection */
147
148 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
149
150 #define VIDEO_BCSR4_RESET_BIT   21      /* BCSR4 - Extern video encoder reset */
151 #define VIDEO_BCSR4_EXTCLK_BIT  22      /* BCSR4 - Extern clock enable */
152 #define VIDEO_BCSR4_VIDLED_BIT  23      /* BCSR4 - Video led disable */
153
154 /************************************************************************/
155 /* ** CONSOLE CONSTANTS                                                 */
156 /************************************************************************/
157
158 #ifdef  CONFIG_VIDEO_LOGO
159 #define CONSOLE_ROWS            ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
160 #define VIDEO_LOGO_SKIP         (VIDEO_COLS - VIDEO_LOGO_WIDTH)
161 #else
162 #define CONSOLE_ROWS            (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
163 #endif
164
165 #define CONSOLE_COLS            (VIDEO_COLS / VIDEO_FONT_WIDTH)
166 #define CONSOLE_ROW_SIZE        (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
167 #define CONSOLE_ROW_FIRST       (video_console_address)
168 #define CONSOLE_ROW_SECOND      (video_console_address + CONSOLE_ROW_SIZE)
169 #define CONSOLE_ROW_LAST        (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
170 #define CONSOLE_SIZE            (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
171 #define CONSOLE_SCROLL_SIZE     (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
172
173 /*
174  * Simple color definitions
175  */
176 #define CONSOLE_COLOR_BLACK      0
177 #define CONSOLE_COLOR_RED        1
178 #define CONSOLE_COLOR_GREEN      2
179 #define CONSOLE_COLOR_YELLOW     3
180 #define CONSOLE_COLOR_BLUE       4
181 #define CONSOLE_COLOR_MAGENTA    5
182 #define CONSOLE_COLOR_CYAN       6
183 #define CONSOLE_COLOR_GREY      13
184 #define CONSOLE_COLOR_GREY2     14
185 #define CONSOLE_COLOR_WHITE     15      /* Must remain last / highest */
186
187 /************************************************************************/
188 /* ** BITOPS MACROS                                                     */
189 /************************************************************************/
190
191 #define HISHORT(i)      ((i >> 16)&0xffff)
192 #define LOSHORT(i)      (i & 0xffff)
193 #define HICHAR(s)       ((i >> 8)&0xff)
194 #define LOCHAR(s)       (i & 0xff)
195 #define HI(c)           ((c >> 4)&0xf)
196 #define LO(c)           (c & 0xf)
197 #define SWAPINT(i)      (HISHORT(i) | (LOSHORT(i) << 16))
198 #define SWAPSHORT(s)    (HICHAR(s) | (LOCHAR(s) << 8))
199 #define SWAPCHAR(c)     (HI(c) | (LO(c) << 4))
200 #define BITMASK(b)      (1 << (b))
201 #define GETBIT(v,b)     (((v) & BITMASK(b)) > 0)
202 #define SETBIT(v,b,d)   (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
203
204 /************************************************************************/
205 /* ** STRUCTURES                                                        */
206 /************************************************************************/
207
208 typedef struct {
209         unsigned char V, Y1, U, Y2;
210 } tYUYV;
211
212 /* This structure is based on the Video Ram in the MPC823. */
213 typedef struct VRAM {
214         unsigned        hx:2,           /* Horizontal sync */
215                         vx:2,           /* Vertical sync */
216                         fx:2,           /* Frame */
217                         bx:2,           /* Blank */
218                         res1:6,         /* Reserved */
219                         vds:2,          /* Video Data Select */
220                         inter:1,        /* Interrupt */
221                         res2:2,         /* Reserved */
222                         lcyc:11,        /* Loop/video cycles */
223                         lp:1,           /* Loop start/end */
224                         lst:1;          /* Last entry */
225 } VRAM;
226
227 /************************************************************************/
228 /* ** VARIABLES                                                         */
229 /************************************************************************/
230
231 static int
232         video_panning_range_x = 0,      /* Video mode invisible pixels x range */
233         video_panning_range_y = 0,      /* Video mode invisible pixels y range */
234         video_panning_value_x = 0,      /* Video mode x panning value (absolute) */
235         video_panning_value_y = 0,      /* Video mode y panning value (absolute) */
236         video_panning_factor_x = 0,     /* Video mode x panning value (-127 +127) */
237         video_panning_factor_y = 0,     /* Video mode y panning value (-127 +127) */
238         console_col = 0,                /* Cursor col */
239         console_row = 0,                /* Cursor row */
240         video_palette[16];              /* Our palette */
241
242 static const int video_font_draw_table[] =
243         { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
244
245 static char
246         video_color_fg = 0,             /* Current fg color index (0-15) */
247         video_color_bg = 0,             /* Current bg color index (0-15) */
248         video_enable = 0;               /* Video has been initialized? */
249
250 static void
251         *video_fb_address,              /* Frame buffer address */
252         *video_console_address;         /* Console frame buffer start address */
253
254 /************************************************************************/
255 /* ** MEMORY FUNCTIONS (32bit)                                          */
256 /************************************************************************/
257
258 static void memsetl (int *p, int c, int v)
259 {
260         while (c--)
261                 *(p++) = v;
262 }
263
264 static void memcpyl (int *d, int *s, int c)
265 {
266         while (c--)
267                 *(d++) = *(s++);
268 }
269
270 /************************************************************************/
271 /* ** VIDEO DRAWING AND COLOR FUNCTIONS                                 */
272 /************************************************************************/
273
274 static int video_maprgb (int r, int g, int b)
275 {
276 #ifdef VIDEO_MODE_YUYV
277         unsigned int pR, pG, pB;
278         tYUYV YUYV;
279         unsigned int *ret = (unsigned int *) &YUYV;
280
281         /* Transform (0-255) components to (0-100) */
282
283         pR = r * 100 / 255;
284         pG = g * 100 / 255;
285         pB = b * 100 / 255;
286
287         /* Calculate YUV values (0-255) from RGB beetween 0-100 */
288
289         YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
290         YUYV.U  = pR - (pG * 3 / 4) - (pB / 4) + 128;
291         YUYV.V  = pB - (pR / 4) - (pG * 3 / 4) + 128;
292         return *ret;
293 #endif
294 #ifdef VIDEO_MODE_RGB
295         return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
296 #endif
297 }
298
299 static void video_setpalette (int color, int r, int g, int b)
300 {
301         color &= 0xf;
302
303         video_palette[color] = video_maprgb (r, g, b);
304
305         /* Swap values if our panning offset is odd */
306         if (video_panning_value_x & 1)
307                 video_palette[color] = SWAPINT (video_palette[color]);
308 }
309
310 static void video_fill (int color)
311 {
312         memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
313 }
314
315 static void video_setfgcolor (int i)
316 {
317         video_color_fg = i & 0xf;
318 }
319
320 static void video_setbgcolor (int i)
321 {
322         video_color_bg = i & 0xf;
323 }
324
325 static int video_pickcolor (int i)
326 {
327         return video_palette[i & 0xf];
328 }
329
330 /* Absolute console plotting functions */
331
332 #ifdef VIDEO_BLINK
333 static void video_revchar (int xx, int yy)
334 {
335         int rows;
336         u8 *dest;
337
338         dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
339
340         for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
341                 switch (VIDEO_FONT_WIDTH) {
342                 case 16:
343                         ((u32 *) dest)[6] ^= 0xffffffff;
344                         ((u32 *) dest)[7] ^= 0xffffffff;
345                         /* FALL THROUGH */
346                 case 12:
347                         ((u32 *) dest)[4] ^= 0xffffffff;
348                         ((u32 *) dest)[5] ^= 0xffffffff;
349                         /* FALL THROUGH */
350                 case 8:
351                         ((u32 *) dest)[2] ^= 0xffffffff;
352                         ((u32 *) dest)[3] ^= 0xffffffff;
353                         /* FALL THROUGH */
354                 case 4:
355                         ((u32 *) dest)[0] ^= 0xffffffff;
356                         ((u32 *) dest)[1] ^= 0xffffffff;
357                 }
358         }
359 }
360 #endif
361
362 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
363 {
364         u8 *cdat, *dest, *dest0;
365         int rows, offset, c;
366         u32 eorx, fgx, bgx;
367
368         offset = yy * VIDEO_LINE_LEN + xx * 2;
369         dest0 = video_fb_address + offset;
370
371         fgx = video_pickcolor (video_color_fg);
372         bgx = video_pickcolor (video_color_bg);
373
374         if (xx & 1) {
375                 fgx = SWAPINT (fgx);
376                 bgx = SWAPINT (bgx);
377         }
378
379         eorx = fgx ^ bgx;
380
381         switch (VIDEO_FONT_WIDTH) {
382         case 4:
383         case 8:
384                 while (count--) {
385                         c = *s;
386                         cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
387                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
388                              rows--;
389                              dest += VIDEO_LINE_LEN) {
390                                 u8 bits = *cdat++;
391
392                                 ((u32 *) dest)[0] =
393                                         (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
394                                 ((u32 *) dest)[1] =
395                                         (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
396                                 if (VIDEO_FONT_WIDTH == 8) {
397                                         ((u32 *) dest)[2] =
398                                                 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
399                                         ((u32 *) dest)[3] =
400                                                 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
401                                 }
402                         }
403                         dest0 += VIDEO_FONT_WIDTH * 2;
404                         s++;
405                 }
406                 break;
407         case 12:
408         case 16:
409                 while (count--) {
410                         cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
411                         for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
412                                  dest += VIDEO_LINE_LEN) {
413                                 u8 bits = *cdat++;
414
415                                 ((u32 *) dest)[0] =
416                                         (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
417                                 ((u32 *) dest)[1] =
418                                         (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
419                                 ((u32 *) dest)[2] =
420                                         (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
421                                 ((u32 *) dest)[3] =
422                                         (video_font_draw_table[bits & 3] & eorx) ^ bgx;
423                                 bits = *cdat++;
424                                 ((u32 *) dest)[4] =
425                                         (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
426                                 ((u32 *) dest)[5] =
427                                         (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
428                                 if (VIDEO_FONT_WIDTH == 16) {
429                                         ((u32 *) dest)[6] =
430                                                 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
431                                         ((u32 *) dest)[7] =
432                                                 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
433                                 }
434                         }
435                         s++;
436                         dest0 += VIDEO_FONT_WIDTH * 2;
437                 }
438                 break;
439         }
440 }
441
442 static inline void video_drawstring (int xx, int yy, unsigned char *s)
443 {
444         video_drawchars (xx, yy, s, strlen (s));
445 }
446
447 /* Relative to console plotting functions */
448
449 static void video_putchars (int xx, int yy, unsigned char *s, int count)
450 {
451 #ifdef CONFIG_VIDEO_LOGO
452         video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
453 #else
454         video_drawchars (xx, yy, s, count);
455 #endif
456 }
457
458 static void video_putchar (int xx, int yy, unsigned char c)
459 {
460 #ifdef CONFIG_VIDEO_LOGO
461         video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
462 #else
463         video_drawchars (xx, yy, &c, 1);
464 #endif
465 }
466
467 static inline void video_putstring (int xx, int yy, unsigned char *s)
468 {
469         video_putchars (xx, yy, s, strlen (s));
470 }
471
472 /************************************************************************/
473 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS                              */
474 /************************************************************************/
475
476 static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
477 {
478         int i;
479
480         for (i = 0; i < entries; i++) {
481                 dest[i] = source[i];    /* Copy the entire record */
482                 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
483         }
484
485         dest[0].lcyc++;                 /* Add a cycle to the first entry */
486         dest[entries - 1].lst = 1;      /* Set end of ram entries */
487 }
488
489 static void inline video_mode_addentry (VRAM * vr,
490         int Hx, int Vx, int Fx, int Bx,
491         int VDS, int INT, int LCYC, int LP, int LST)
492 {
493         vr->hx = Hx;
494         vr->vx = Vx;
495         vr->fx = Fx;
496         vr->bx = Bx;
497         vr->vds = VDS;
498         vr->inter = INT;
499         vr->lcyc = LCYC;
500         vr->lp = LP;
501         vr->lst = LST;
502 }
503
504 #define ADDENTRY(a,b,c,d,e,f,g,h,i)     video_mode_addentry(&vr[entry++],a,b,c,d,e,f,g,h,i)
505
506 static int video_mode_generate (void)
507 {
508         immap_t *immap = (immap_t *) CFG_IMMR;
509         VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
510         int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
511
512         /* CHECKING PARAMETERS */
513
514         if (video_panning_factor_y < -128)
515                 video_panning_factor_y = -128;
516
517         if (video_panning_factor_y > 128)
518                 video_panning_factor_y = 128;
519
520         if (video_panning_factor_x < -128)
521                 video_panning_factor_x = -128;
522
523         if (video_panning_factor_x > 128)
524                 video_panning_factor_x = 128;
525
526         /* Setting panning */
527
528         DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
529         DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
530
531         video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
532         video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
533
534         /* We assume these are burst units (multiplied by 2, we need it pari) */
535         X1 = video_panning_value_x & 0xfffe;
536         X2 = DX - X1;
537
538         /* We assume these are field line units (divided by 2, we need it pari) */
539         Y1 = video_panning_value_y & 0xfffe;
540         Y2 = DY - Y1;
541
542 #ifdef VIDEO_MODE_NTSC
543 /*
544  *           Hx Vx Fx Bx VDS INT LCYC LP LST
545  *
546  * Retrace blanking
547  */
548         ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
549         ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
550         ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
551         ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
552 /*
553  * Vertical blanking
554  */
555         ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
556         ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
557         ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
558         ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
559 /*
560  * Odd field active area (TOP)
561  */
562         if (Y1 > 0) {
563                 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
564                 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
565                 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
566                 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
567         }
568 /*
569  * Odd field active area
570  */
571         ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
572         ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
573         ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
574         ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
575
576         if (X2 > 0)
577                 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
578
579         ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
580
581 /*
582  * Odd field active area (BOTTOM)
583  */
584         if (Y1 > 0) {
585                 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
586                 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
587                 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
588                 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
589         }
590 /*
591  * Vertical blanking
592  */
593         ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
594         ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
595         ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
596         ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
597 /*
598  * Vertical blanking
599  */
600         ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
601         ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
602         ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
603         ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
604 /*
605  * Even field active area (TOP)
606  */
607         if (Y1 > 0) {
608                 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
609                 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
610                 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
611                 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
612         }
613 /*
614  * Even field active area (CENTER)
615  */
616         ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
617         ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
618         ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
619         ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
620
621         if (X2 > 0)
622                 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
623
624         ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
625 /*
626  * Even field active area (BOTTOM)
627  */
628         if (Y1 > 0) {
629                 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
630                 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
631                 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
632                 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
633         }
634 /*
635  * Vertical blanking
636  */
637         ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
638         ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
639         ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
640         ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
641 #endif
642
643 #ifdef VIDEO_MODE_PAL
644 /*
645  *      Hx Vx Fx Bx VDS INT LCYC LP LST
646  *
647  * vertical; blanking
648  */
649         ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
650         ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
651         ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
652         ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
653 /*
654  * active area (TOP)
655  */
656         if (Y1 > 0) {
657                 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);  /* 11? */
658                 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
659                 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
660                 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
661         }
662 /*
663  * field active area (CENTER)
664  */
665         ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0);    /* 265? */
666         ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
667         ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
668         ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
669
670         if (X2 > 0)
671                 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
672
673         ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
674 /*
675  * field active area (BOTTOM)
676  */
677         if (Y2 > 0) {
678                 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);  /* 12? */
679                 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
680                 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
681                 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
682         }
683 /*
684  * field vertical; blanking
685  */
686         ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
687         ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
688         ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
689         ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
690 /*
691  * Create the other field (like this, but whit other field selected,
692  * one more cycle loop and a last identifier)
693  */
694         video_mode_dupefield (vr, &vr[entry], entry);
695 #endif
696
697         /* See what FIFO are we using */
698         fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
699
700         /* Set number of lines and burst (only one frame for now) */
701         if (fifo) {
702                 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
703                         (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
704         } else {
705                 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
706                         (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
707         }
708
709         SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
710
711 /*
712  * Wait until changes are applied (not done)
713  * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
714  */
715
716         /* Return number of VRAM entries */
717         return entry * 2;
718 }
719
720 static void video_encoder_init (void)
721 {
722 #ifdef VIDEO_I2C
723         int rc;
724
725         /* Initialize the I2C */
726         debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
727         i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
728
729 #ifdef CONFIG_FADS
730         /* Reset ADV7176 chip */
731         debug ("[VIDEO ENCODER] Resetting encoder...\n");
732         (*(int *) BCSR4) &= ~(1 << 21);
733
734         /* Wait for 5 ms inside the reset */
735         debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
736         udelay (5000);
737
738         /* Take ADV7176 out of reset */
739         (*(int *) BCSR4) |= 1 << 21;
740
741         /* Wait for 5 ms after the reset */
742         udelay (5000);
743 #endif  /* CONFIG_FADS */
744
745         /* Send configuration */
746 #ifdef DEBUG
747         {
748                 int i;
749
750                 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
751
752                 printf ("Sending %d bytes (@ %08lX) to I2C 0x%X:\n   ",
753                         sizeof(video_encoder_data),
754                         (ulong)video_encoder_data,
755                         VIDEO_I2C_ADDR);
756                 for (i=0; i<sizeof(video_encoder_data); ++i) {
757                         printf(" %02X", video_encoder_data[i]);
758                 }
759                 putc ('\n');
760         }
761 #endif  /* DEBUG */
762
763         if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
764                          video_encoder_data,
765                          sizeof(video_encoder_data))) != 0) {
766                 printf ("i2c_send error: rc=%d\n", rc);
767                 return;
768         }
769 #endif  /* VIDEO_I2C */
770         return;
771 }
772
773 static void video_ctrl_init (void *memptr)
774 {
775         immap_t *immap = (immap_t *) CFG_IMMR;
776
777         video_fb_address = memptr;
778
779         /* Set background */
780         debug ("[VIDEO CTRL] Setting background color...\n");
781         immap->im_vid.vid_vbcb = VIDEO_BG_COL;
782
783         /* Show the background */
784         debug ("[VIDEO CTRL] Forcing background...\n");
785         SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
786
787         /* Turn off video controller */
788         debug ("[VIDEO CTRL] Turning off video controller...\n");
789         SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
790
791 #ifdef CONFIG_FADS
792         /* Turn on Video Port LED */
793         debug ("[VIDEO CTRL] Turning off video port led...\n");
794         SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
795
796         /* Disable internal clock */
797         debug ("[VIDEO CTRL] Disabling internal clock...\n");
798         SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
799 #endif
800
801         /* Generate and make active a new video mode */
802         debug ("[VIDEO CTRL] Generating video mode...\n");
803         video_mode_generate ();
804
805         /* Start of frame buffer (even and odd frame, to make it working with */
806         /* any selected active set) */
807         debug ("[VIDEO CTRL] Setting frame buffer address...\n");
808         immap->im_vid.vid_vfaa1 =
809                 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
810         immap->im_vid.vid_vfba1 =
811         immap->im_vid.vid_vfba0 =
812                 (u32) video_fb_address + VIDEO_LINE_LEN;
813
814         /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
815         debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
816         immap->im_vid.vid_vccr = 0x2042;
817
818         /* Configure port pins */
819         debug ("[VIDEO CTRL] Configuring input/output pins...\n");
820         immap->im_ioport.iop_pdpar = 0x1fff;
821         immap->im_ioport.iop_pddir = 0x0000;
822
823 #ifdef CONFIG_FADS
824         /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
825         debug ("[VIDEO CTRL] Turning on video clock...\n");
826         SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
827
828         /* Turn on Video Port LED */
829         debug ("[VIDEO CTRL] Turning on video port led...\n");
830         SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
831 #endif
832
833 #ifdef CONFIG_RRVISION
834         /* enable clock: set PD3 to VCLK, PC5 to HIGH */
835         {
836                 volatile immap_t *immr = (immap_t *) CFG_IMMR;
837
838                 debug ("PDPAR=%04X PDDIR=%04X PDDAT=%04X\n",
839                         immr->im_ioport.iop_pdpar,
840                         immr->im_ioport.iop_pddir,
841                         immr->im_ioport.iop_pddat);
842
843                 debug ("[RRvision] PC5 -> Output (1): ");
844                 immr->im_ioport.iop_pcpar &= ~(0x0400);
845                 immr->im_ioport.iop_pcdir |=   0x0400 ;
846                 immr->im_ioport.iop_pcdat |=   0x0400 ;
847                 debug ("PCPAR=%04X PCDIR=%04X PCDAT=%04X\n",
848                         immr->im_ioport.iop_pcpar,
849                         immr->im_ioport.iop_pcdir,
850                         immr->im_ioport.iop_pcdat);
851         }
852 #endif  /* CONFIG_RRVISION */
853
854         /* Blanking the screen. */
855         debug ("[VIDEO CTRL] Blanking the screen...\n");
856         video_fill (VIDEO_BG_COL);
857
858         /*
859          * Turns on Aggressive Mode. Normally, turning on the caches
860          * will cause the screen to flicker when the caches try to
861          * fill. This gives the FIFO's for the Video Controller
862          * higher priority and prevents flickering because of
863          * underrun. This may still be an issue when using FLASH,
864          * since accessing data from Flash is so slow.
865          */
866         debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
867         immap->im_siu_conf.sc_sdcr = 0x40;
868
869         /* Turn on video controller */
870         debug ("[VIDEO CTRL] Turning on video controller...\n");
871         SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
872
873         /* Show the display */
874         debug ("[VIDEO CTRL] Enabling the video...\n");
875         SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
876 }
877
878 /************************************************************************/
879 /* ** CONSOLE FUNCTIONS                                                 */
880 /************************************************************************/
881
882 static void console_scrollup (void)
883 {
884         /* Copy up rows ignoring the first one */
885         memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
886
887         /* Clear the last one */
888         memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
889 }
890
891 static inline void console_back (void)
892 {
893         console_col--;
894
895         if (console_col < 0) {
896                 console_col = CONSOLE_COLS - 1;
897                 console_row--;
898                 if (console_row < 0)
899                         console_row = 0;
900         }
901
902         video_putchar ( console_col * VIDEO_FONT_WIDTH,
903                         console_row * VIDEO_FONT_HEIGHT, ' ');
904 }
905
906 static inline void console_newline (void)
907 {
908         console_row++;
909         console_col = 0;
910
911         /* Check if we need to scroll the terminal */
912         if (console_row >= CONSOLE_ROWS) {
913                 /* Scroll everything up */
914                 console_scrollup ();
915
916                 /* Decrement row number */
917                 console_row--;
918         }
919 }
920
921 void video_putc (const char c)
922 {
923         if (!video_enable) {
924                 serial_putc (c);
925                 return;
926         }
927
928         switch (c) {
929         case 13:                        /* Simply ignore this */
930                 break;
931
932         case '\n':                      /* Next line, please */
933                 console_newline ();
934                 break;
935
936         case 9:                         /* Tab (8 chars alignment) */
937                 console_col |= 0x0008;  /* Next 8 chars boundary */
938                 console_col &= ~0x0007; /* Set this bit to zero */
939
940                 if (console_col >= CONSOLE_COLS)
941                         console_newline ();
942                 break;
943
944         case 8:                         /* Eat last character */
945                 console_back ();
946                 break;
947
948         default:                        /* Add to the console */
949                 video_putchar ( console_col * VIDEO_FONT_WIDTH,
950                                 console_row * VIDEO_FONT_HEIGHT, c);
951                 console_col++;
952                 /* Check if we need to go to next row */
953                 if (console_col >= CONSOLE_COLS)
954                         console_newline ();
955         }
956 }
957
958 void video_puts (const char *s)
959 {
960         int count = strlen (s);
961
962         if (!video_enable)
963                 while (count--)
964                         serial_putc (*s++);
965         else
966                 while (count--)
967                         video_putc (*s++);
968 }
969
970 /************************************************************************/
971 /* ** CURSOR BLINKING FUNCTIONS                                         */
972 /************************************************************************/
973
974 #ifdef VIDEO_BLINK
975
976 #define BLINK_TIMER_ID          0
977 #define BLINK_TIMER_HZ          2
978
979 static unsigned char blink_enabled = 0;
980 static timer_t blink_timer;
981
982 static void blink_update (void)
983 {
984         static int blink_row = -1, blink_col = -1, blink_old = 0;
985
986         /* Check if we have a new position to invert */
987         if ((console_row != blink_row) || (console_col != blink_col)) {
988                 /* Check if we need to reverse last character */
989                 if (blink_old)
990                         video_revchar ( blink_col * VIDEO_FONT_WIDTH,
991                                         (blink_row
992 #ifdef CONFIG_VIDEO_LOGO
993                                          + VIDEO_LOGO_HEIGHT
994 #endif
995                                         ) * VIDEO_FONT_HEIGHT);
996
997                 /* Update values */
998                 blink_row = console_row;
999                 blink_col = console_col;
1000                 blink_old = 0;
1001         }
1002
1003 /* Reverse this character */
1004         blink_old = !blink_old;
1005         video_revchar ( console_col * VIDEO_FONT_WIDTH,
1006                         (console_row
1007 #ifdef CONFIG_VIDEO_LOGO
1008                         + VIDEO_LOGO_HEIGHT
1009 #endif
1010                         ) * VIDEO_FONT_HEIGHT);
1011
1012 }
1013
1014 /*
1015  * Handler for blinking cursor
1016  */
1017 static void blink_handler (void *arg)
1018 {
1019 /* Blink */
1020         blink_update ();
1021 /* Ack the timer */
1022         timer_ack (&blink_timer);
1023 }
1024
1025 int blink_set (int blink)
1026 {
1027         int ret = blink_enabled;
1028
1029         if (blink)
1030                 timer_enable (&blink_timer);
1031         else
1032                 timer_disable (&blink_timer);
1033
1034         blink_enabled = blink;
1035
1036         return ret;
1037 }
1038
1039 static inline void blink_close (void)
1040 {
1041         timer_close (&blink_timer);
1042 }
1043
1044 static inline void blink_init (void)
1045 {
1046         timer_init (&blink_timer,
1047                         BLINK_TIMER_ID, BLINK_TIMER_HZ,
1048                         blink_handler);
1049 }
1050 #endif
1051
1052 /************************************************************************/
1053 /* ** LOGO PLOTTING FUNCTIONS                                           */
1054 /************************************************************************/
1055
1056 #ifdef CONFIG_VIDEO_LOGO
1057 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1058                                         int y)
1059 {
1060         int skip = width - image->width, xcount, ycount = image->height;
1061
1062 #ifdef VIDEO_MODE_YUYV
1063         ushort *source = (ushort *) image->data;
1064         ushort *dest   = (ushort *) screen + y * width + x;
1065
1066         while (ycount--) {
1067                 xcount = image->width;
1068                 while (xcount--)
1069                         *dest++ = *source++;
1070                 dest += skip;
1071         }
1072 #endif
1073 #ifdef VIDEO_MODE_RGB
1074         unsigned char
1075         *source = (unsigned short *) image->data,
1076                         *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1077
1078         while (ycount--) {
1079                 xcount = image->width * 3;
1080                 memcpy (dest, source, xcount);
1081                 source += xcount;
1082                 dest += ycount;
1083         }
1084 #endif
1085 }
1086
1087 static void *video_logo (void)
1088 {
1089         u16 *screen = video_fb_address, width = VIDEO_COLS;
1090 #ifdef VIDEO_INFO
1091 # ifndef CONFIG_FADS
1092         DECLARE_GLOBAL_DATA_PTR;
1093         char temp[32];
1094 # endif
1095         char info[80];
1096 #endif /* VIDEO_INFO */
1097
1098         easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1099
1100 #ifdef VIDEO_INFO
1101         sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1102         video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1103
1104         sprintf (info, "(C) 2002 DENX Software Engineering");
1105         video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1106                                         info);
1107
1108         sprintf (info, "    Wolfgang DENK, wd@denx.de");
1109         video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1110                                         info);
1111 #ifndef CONFIG_FADS             /* all normal boards */
1112         /* leave one blank line */
1113
1114         sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1115                 strmhz(temp, gd->cpu_clk),
1116                 gd->ram_size >> 20,
1117                 gd->bd->bi_flashsize >> 20 );
1118         video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1119                                         info);
1120 #else                           /* FADS :-( */
1121         sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1122         video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1123                                           info);
1124
1125         sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1126         video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1127                                           info);
1128 #endif
1129 #endif
1130
1131         return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1132 }
1133 #endif
1134
1135 /************************************************************************/
1136 /* ** VIDEO HIGH-LEVEL FUNCTIONS                                        */
1137 /************************************************************************/
1138
1139 static int video_init (void *videobase)
1140 {
1141         /* Initialize the encoder */
1142         debug ("[VIDEO] Initializing video encoder...\n");
1143         video_encoder_init ();
1144
1145         /* Initialize the video controller */
1146         debug ("[VIDEO] Initializing video controller at %08x...\n",
1147                    (int) videobase);
1148         video_ctrl_init (videobase);
1149
1150         /* Setting the palette */
1151         video_setpalette  (CONSOLE_COLOR_BLACK,      0,    0,    0);
1152         video_setpalette  (CONSOLE_COLOR_RED,     0xFF,    0,    0);
1153         video_setpalette  (CONSOLE_COLOR_GREEN,      0, 0xFF,    0);
1154         video_setpalette  (CONSOLE_COLOR_YELLOW,  0xFF, 0xFF,    0);
1155         video_setpalette  (CONSOLE_COLOR_BLUE,       0,    0, 0xFF);
1156         video_setpalette  (CONSOLE_COLOR_MAGENTA, 0xFF,    0, 0xFF);
1157         video_setpalette  (CONSOLE_COLOR_CYAN,       0, 0xFF, 0xFF);
1158         video_setpalette  (CONSOLE_COLOR_GREY,    0xAA, 0xAA, 0xAA);
1159         video_setpalette  (CONSOLE_COLOR_GREY2,   0xF8, 0xF8, 0xF8);
1160         video_setpalette  (CONSOLE_COLOR_WHITE,   0xFF, 0xFF, 0xFF);
1161
1162 #ifndef CFG_WHITE_ON_BLACK
1163         video_setfgcolor (CONSOLE_COLOR_BLACK);
1164         video_setbgcolor (CONSOLE_COLOR_GREY2);
1165 #else
1166         video_setfgcolor (CONSOLE_COLOR_GREY2);
1167         video_setbgcolor (CONSOLE_COLOR_BLACK);
1168 #endif  /* CFG_WHITE_ON_BLACK */
1169
1170 #ifdef CONFIG_VIDEO_LOGO
1171         /* Paint the logo and retrieve tv base address */
1172         debug ("[VIDEO] Drawing the logo...\n");
1173         video_console_address = video_logo ();
1174 #else
1175         video_console_address = video_fb_address;
1176 #endif
1177
1178 #ifdef VIDEO_BLINK
1179         /* Enable the blinking (under construction) */
1180         blink_init ();
1181         blink_set (0);                          /* To Fix! */
1182 #endif
1183
1184         /* Initialize the console */
1185         console_col = 0;
1186         console_row = 0;
1187         video_enable = 1;
1188
1189 #ifdef VIDEO_MODE_PAL
1190 # define VIDEO_MODE_TMP1        "PAL"
1191 #endif
1192 #ifdef VIDEO_MODE_NTSC
1193 # define VIDEO_MODE_TMP1        "NTSC"
1194 #endif
1195 #ifdef VIDEO_MODE_YUYV
1196 # define VIDEO_MODE_TMP2        "YCbYCr"
1197 #endif
1198 #ifdef VIDEO_MODE_RGB
1199 # define VIDEO_MODE_TMP2        "RGB"
1200 #endif
1201         debug ( VIDEO_MODE_TMP1
1202                 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1203                         VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1204                         VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1205         return 0;
1206 }
1207
1208 int drv_video_init (void)
1209 {
1210         DECLARE_GLOBAL_DATA_PTR;
1211
1212         int error, devices = 1;
1213
1214         device_t videodev;
1215
1216         video_init ((void *)(gd->fb_base));     /* Video initialization */
1217
1218 /* Device initialization */
1219
1220         memset (&videodev, 0, sizeof (videodev));
1221
1222         strcpy (videodev.name, "video");
1223         videodev.ext = DEV_EXT_VIDEO;   /* Video extensions */
1224         videodev.flags = DEV_FLAGS_OUTPUT;      /* Output only */
1225         videodev.putc = video_putc;     /* 'putc' function */
1226         videodev.puts = video_puts;     /* 'puts' function */
1227
1228         error = device_register (&videodev);
1229
1230         return (error == 0) ? devices : error;
1231 }
1232
1233 /************************************************************************/
1234 /* ** ROM capable initialization part - needed to reserve FB memory     */
1235 /************************************************************************/
1236
1237 /*
1238  * This is called early in the system initialization to grab memory
1239  * for the video controller.
1240  * Returns new address for monitor, after reserving video buffer memory
1241  *
1242  * Note that this is running from ROM, so no write access to global data.
1243  */
1244 ulong video_setmem (ulong addr)
1245 {
1246         /* Allocate pages for the frame buffer. */
1247         addr -= VIDEO_SIZE;
1248
1249         debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1250                 VIDEO_SIZE>>10, addr);
1251
1252         return (addr);
1253 }
1254
1255
1256
1257 #endif