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