MINI2440: Updated early nand loader
[u-boot-openmoko/mini2440.git] / cpu / mpc8xx / video.c
blob918de6794353b8f6b8de4c6c6a46df2c258f6d49
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
7 * See file CREDITS for list of people who contributed to this
8 * project.
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.
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.
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
26 /* #define DEBUG */
28 /************************************************************************/
29 /* ** HEADER FILES */
30 /************************************************************************/
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>
40 #ifdef CONFIG_VIDEO
42 DECLARE_GLOBAL_DATA_PTR;
44 /************************************************************************/
45 /* ** DEBUG SETTINGS */
46 /************************************************************************/
48 #if 0
49 #define VIDEO_DEBUG_COLORBARS /* Force colorbars output */
50 #endif
52 /************************************************************************/
53 /* ** VIDEO MODE SETTINGS */
54 /************************************************************************/
56 #if 0
57 #define VIDEO_MODE_EXTENDED /* Allow screen size bigger than visible area */
58 #define VIDEO_MODE_NTSC
59 #endif
61 #define VIDEO_MODE_PAL
63 #if 0
64 #define VIDEO_BLINK /* This enables cursor blinking (under construction) */
65 #endif
67 #define VIDEO_INFO /* Show U-Boot information */
68 #define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
69 #define VIDEO_INFO_Y 16
71 /************************************************************************/
72 /* ** VIDEO ENCODER CONSTANTS */
73 /************************************************************************/
75 #ifdef CONFIG_VIDEO_ENCODER_AD7176
77 #include <video_ad7176.h> /* Sets encoder data, mode, and visible and active area */
79 #define VIDEO_I2C 1
80 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
81 #endif
83 #ifdef CONFIG_VIDEO_ENCODER_AD7177
85 #include <video_ad7177.h> /* Sets encoder data, mode, and visible and active area */
87 #define VIDEO_I2C 1
88 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
89 #endif
91 #ifdef CONFIG_VIDEO_ENCODER_AD7179
93 #include <video_ad7179.h> /* Sets encoder data, mode, and visible and active area */
95 #define VIDEO_I2C 1
96 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
97 #endif
99 /************************************************************************/
100 /* ** VIDEO MODE CONSTANTS */
101 /************************************************************************/
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
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)
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
123 /************************************************************************/
124 /* ** FONT AND LOGO DATA */
125 /************************************************************************/
127 #include <video_font.h> /* Get font data, width and height */
129 #ifdef CONFIG_VIDEO_LOGO
130 #include <video_logo.h> /* Get logo data, width and height */
132 #define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
133 #define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
134 #define VIDEO_LOGO_ADDR &u_boot_logo
135 #endif
137 /************************************************************************/
138 /* ** VIDEO CONTROLLER CONSTANTS */
139 /************************************************************************/
141 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
143 #define VIDEO_VCCR_VON 0 /* Video controller ON */
144 #define VIDEO_VCCR_CSRC 1 /* Clock source */
145 #define VIDEO_VCCR_PDF 13 /* Pixel display format */
146 #define VIDEO_VCCR_IEN 11 /* Interrupt enable */
148 /* VSR - VIDEO STATUS REGISTER */
150 #define VIDEO_VSR_CAS 6 /* Active set */
151 #define VIDEO_VSR_EOF 0 /* End of frame */
153 /* VCMR - VIDEO COMMAND REGISTER */
155 #define VIDEO_VCMR_BD 0 /* Blank display */
156 #define VIDEO_VCMR_ASEL 1 /* Active set selection */
158 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
160 #define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
161 #define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
162 #define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
164 /************************************************************************/
165 /* ** CONSOLE CONSTANTS */
166 /************************************************************************/
168 #ifdef CONFIG_VIDEO_LOGO
169 #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
170 #define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
171 #else
172 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
173 #endif
175 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
176 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
177 #define CONSOLE_ROW_FIRST (video_console_address)
178 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
179 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
180 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
181 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
184 * Simple color definitions
186 #define CONSOLE_COLOR_BLACK 0
187 #define CONSOLE_COLOR_RED 1
188 #define CONSOLE_COLOR_GREEN 2
189 #define CONSOLE_COLOR_YELLOW 3
190 #define CONSOLE_COLOR_BLUE 4
191 #define CONSOLE_COLOR_MAGENTA 5
192 #define CONSOLE_COLOR_CYAN 6
193 #define CONSOLE_COLOR_GREY 13
194 #define CONSOLE_COLOR_GREY2 14
195 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
197 /************************************************************************/
198 /* ** BITOPS MACROS */
199 /************************************************************************/
201 #define HISHORT(i) ((i >> 16)&0xffff)
202 #define LOSHORT(i) (i & 0xffff)
203 #define HICHAR(s) ((i >> 8)&0xff)
204 #define LOCHAR(s) (i & 0xff)
205 #define HI(c) ((c >> 4)&0xf)
206 #define LO(c) (c & 0xf)
207 #define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
208 #define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
209 #define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
210 #define BITMASK(b) (1 << (b))
211 #define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
212 #define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
214 /************************************************************************/
215 /* ** STRUCTURES */
216 /************************************************************************/
218 typedef struct {
219 unsigned char V, Y1, U, Y2;
220 } tYUYV;
222 /* This structure is based on the Video Ram in the MPC823. */
223 typedef struct VRAM {
224 unsigned hx:2, /* Horizontal sync */
225 vx:2, /* Vertical sync */
226 fx:2, /* Frame */
227 bx:2, /* Blank */
228 res1:6, /* Reserved */
229 vds:2, /* Video Data Select */
230 inter:1, /* Interrupt */
231 res2:2, /* Reserved */
232 lcyc:11, /* Loop/video cycles */
233 lp:1, /* Loop start/end */
234 lst:1; /* Last entry */
235 } VRAM;
237 /************************************************************************/
238 /* ** VARIABLES */
239 /************************************************************************/
241 static int
242 video_panning_range_x = 0, /* Video mode invisible pixels x range */
243 video_panning_range_y = 0, /* Video mode invisible pixels y range */
244 video_panning_value_x = 0, /* Video mode x panning value (absolute) */
245 video_panning_value_y = 0, /* Video mode y panning value (absolute) */
246 video_panning_factor_x = 0, /* Video mode x panning value (-127 +127) */
247 video_panning_factor_y = 0, /* Video mode y panning value (-127 +127) */
248 console_col = 0, /* Cursor col */
249 console_row = 0, /* Cursor row */
250 video_palette[16]; /* Our palette */
252 static const int video_font_draw_table[] =
253 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
255 static char
256 video_color_fg = 0, /* Current fg color index (0-15) */
257 video_color_bg = 0, /* Current bg color index (0-15) */
258 video_enable = 0; /* Video has been initialized? */
260 static void
261 *video_fb_address, /* Frame buffer address */
262 *video_console_address; /* Console frame buffer start address */
264 /************************************************************************/
265 /* ** MEMORY FUNCTIONS (32bit) */
266 /************************************************************************/
268 static void memsetl (int *p, int c, int v)
270 while (c--)
271 *(p++) = v;
274 static void memcpyl (int *d, int *s, int c)
276 while (c--)
277 *(d++) = *(s++);
280 /************************************************************************/
281 /* ** VIDEO DRAWING AND COLOR FUNCTIONS */
282 /************************************************************************/
284 static int video_maprgb (int r, int g, int b)
286 #ifdef VIDEO_MODE_YUYV
287 unsigned int pR, pG, pB;
288 tYUYV YUYV;
289 unsigned int *ret = (unsigned int *) &YUYV;
291 /* Transform (0-255) components to (0-100) */
293 pR = r * 100 / 255;
294 pG = g * 100 / 255;
295 pB = b * 100 / 255;
297 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
299 YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
300 YUYV.U = pR - (pG * 3 / 4) - (pB / 4) + 128;
301 YUYV.V = pB - (pR / 4) - (pG * 3 / 4) + 128;
302 return *ret;
303 #endif
304 #ifdef VIDEO_MODE_RGB
305 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
306 #endif
309 static void video_setpalette (int color, int r, int g, int b)
311 color &= 0xf;
313 video_palette[color] = video_maprgb (r, g, b);
315 /* Swap values if our panning offset is odd */
316 if (video_panning_value_x & 1)
317 video_palette[color] = SWAPINT (video_palette[color]);
320 static void video_fill (int color)
322 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
325 static void video_setfgcolor (int i)
327 video_color_fg = i & 0xf;
330 static void video_setbgcolor (int i)
332 video_color_bg = i & 0xf;
335 static int video_pickcolor (int i)
337 return video_palette[i & 0xf];
340 /* Absolute console plotting functions */
342 #ifdef VIDEO_BLINK
343 static void video_revchar (int xx, int yy)
345 int rows;
346 u8 *dest;
348 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
350 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
351 switch (VIDEO_FONT_WIDTH) {
352 case 16:
353 ((u32 *) dest)[6] ^= 0xffffffff;
354 ((u32 *) dest)[7] ^= 0xffffffff;
355 /* FALL THROUGH */
356 case 12:
357 ((u32 *) dest)[4] ^= 0xffffffff;
358 ((u32 *) dest)[5] ^= 0xffffffff;
359 /* FALL THROUGH */
360 case 8:
361 ((u32 *) dest)[2] ^= 0xffffffff;
362 ((u32 *) dest)[3] ^= 0xffffffff;
363 /* FALL THROUGH */
364 case 4:
365 ((u32 *) dest)[0] ^= 0xffffffff;
366 ((u32 *) dest)[1] ^= 0xffffffff;
370 #endif
372 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
374 u8 *cdat, *dest, *dest0;
375 int rows, offset, c;
376 u32 eorx, fgx, bgx;
378 offset = yy * VIDEO_LINE_LEN + xx * 2;
379 dest0 = video_fb_address + offset;
381 fgx = video_pickcolor (video_color_fg);
382 bgx = video_pickcolor (video_color_bg);
384 if (xx & 1) {
385 fgx = SWAPINT (fgx);
386 bgx = SWAPINT (bgx);
389 eorx = fgx ^ bgx;
391 switch (VIDEO_FONT_WIDTH) {
392 case 4:
393 case 8:
394 while (count--) {
395 c = *s;
396 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
397 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
398 rows--;
399 dest += VIDEO_LINE_LEN) {
400 u8 bits = *cdat++;
402 ((u32 *) dest)[0] =
403 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
404 ((u32 *) dest)[1] =
405 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
406 if (VIDEO_FONT_WIDTH == 8) {
407 ((u32 *) dest)[2] =
408 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
409 ((u32 *) dest)[3] =
410 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
413 dest0 += VIDEO_FONT_WIDTH * 2;
414 s++;
416 break;
417 case 12:
418 case 16:
419 while (count--) {
420 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
421 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
422 dest += VIDEO_LINE_LEN) {
423 u8 bits = *cdat++;
425 ((u32 *) dest)[0] =
426 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
427 ((u32 *) dest)[1] =
428 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
429 ((u32 *) dest)[2] =
430 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
431 ((u32 *) dest)[3] =
432 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
433 bits = *cdat++;
434 ((u32 *) dest)[4] =
435 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
436 ((u32 *) dest)[5] =
437 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
438 if (VIDEO_FONT_WIDTH == 16) {
439 ((u32 *) dest)[6] =
440 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
441 ((u32 *) dest)[7] =
442 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
445 s++;
446 dest0 += VIDEO_FONT_WIDTH * 2;
448 break;
452 static inline void video_drawstring (int xx, int yy, char *s)
454 video_drawchars (xx, yy, (unsigned char *)s, strlen (s));
457 /* Relative to console plotting functions */
459 static void video_putchars (int xx, int yy, unsigned char *s, int count)
461 #ifdef CONFIG_VIDEO_LOGO
462 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
463 #else
464 video_drawchars (xx, yy, s, count);
465 #endif
468 static void video_putchar (int xx, int yy, unsigned char c)
470 #ifdef CONFIG_VIDEO_LOGO
471 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
472 #else
473 video_drawchars (xx, yy, &c, 1);
474 #endif
477 static inline void video_putstring (int xx, int yy, unsigned char *s)
479 video_putchars (xx, yy, (unsigned char *)s, strlen ((char *)s));
482 /************************************************************************/
483 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
484 /************************************************************************/
486 #if !defined(CONFIG_RRVISION)
487 static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
489 int i;
491 for (i = 0; i < entries; i++) {
492 dest[i] = source[i]; /* Copy the entire record */
493 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
496 dest[0].lcyc++; /* Add a cycle to the first entry */
497 dest[entries - 1].lst = 1; /* Set end of ram entries */
499 #endif
501 static void inline video_mode_addentry (VRAM * vr,
502 int Hx, int Vx, int Fx, int Bx,
503 int VDS, int INT, int LCYC, int LP, int LST)
505 vr->hx = Hx;
506 vr->vx = Vx;
507 vr->fx = Fx;
508 vr->bx = Bx;
509 vr->vds = VDS;
510 vr->inter = INT;
511 vr->lcyc = LCYC;
512 vr->lp = LP;
513 vr->lst = LST;
516 #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 static int video_mode_generate (void)
520 immap_t *immap = (immap_t *) CFG_IMMR;
521 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
522 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
524 /* CHECKING PARAMETERS */
526 if (video_panning_factor_y < -128)
527 video_panning_factor_y = -128;
529 if (video_panning_factor_y > 128)
530 video_panning_factor_y = 128;
532 if (video_panning_factor_x < -128)
533 video_panning_factor_x = -128;
535 if (video_panning_factor_x > 128)
536 video_panning_factor_x = 128;
538 /* Setting panning */
540 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
541 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
543 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
544 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
546 /* We assume these are burst units (multiplied by 2, we need it pari) */
547 X1 = video_panning_value_x & 0xfffe;
548 X2 = DX - X1;
550 /* We assume these are field line units (divided by 2, we need it pari) */
551 Y1 = video_panning_value_y & 0xfffe;
552 Y2 = DY - Y1;
554 debug("X1=%d, X2=%d, Y1=%d, Y2=%d, DX=%d, DY=%d VIDEO_COLS=%d \n",
555 X1, X2, Y1, Y2, DX, DY, VIDEO_COLS);
557 #ifdef VIDEO_MODE_NTSC
559 * Hx Vx Fx Bx VDS INT LCYC LP LST
561 * Retrace blanking
563 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
564 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
565 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
566 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
568 * Vertical blanking
570 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
571 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
572 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
573 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
575 * Odd field active area (TOP)
577 if (Y1 > 0) {
578 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
579 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
580 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
581 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
584 * Odd field active area
586 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
587 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
588 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
589 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
591 if (X2 > 0)
592 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
594 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
597 * Odd field active area (BOTTOM)
599 if (Y1 > 0) {
600 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
601 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
602 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
603 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
606 * Vertical blanking
608 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
609 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
610 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
611 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
613 * Vertical blanking
615 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
616 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
617 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
618 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
620 * Even field active area (TOP)
622 if (Y1 > 0) {
623 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
624 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
625 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
626 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
629 * Even field active area (CENTER)
631 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
632 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
633 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
634 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
636 if (X2 > 0)
637 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
639 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
641 * Even field active area (BOTTOM)
643 if (Y1 > 0) {
644 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
645 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
646 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
647 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
650 * Vertical blanking
652 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
653 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
654 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
655 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
656 #endif
658 #ifdef VIDEO_MODE_PAL
660 #if defined(CONFIG_RRVISION)
662 #define HPW 160 /* horizontal pulse width (was 139) */
663 #define VPW 2 /* vertical pulse width */
664 #define HBP 104 /* horizontal back porch (was 112) */
665 #define VBP 19 /* vertical back porch (was 19) */
666 #define VID_R 240 /* number of rows */
668 debug ("[VIDEO CTRL] Starting to add controller entries...");
670 * Even field
672 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
673 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
674 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
676 ADDENTRY (0, 0, 0, 3, 1, 0, VPW, 1, 0);
677 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
678 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
680 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
681 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
682 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
684 * Active area
686 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
687 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
688 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
689 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
690 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
692 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
693 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
694 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
696 * Odd field
698 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
699 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
700 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
702 ADDENTRY (0, 0, 0, 3, 1, 0, VPW+1, 1, 0);
703 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
704 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
706 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
707 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
708 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
710 * Active area
712 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
713 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
714 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
715 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
716 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
718 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
719 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
720 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
722 debug ("done\n");
724 #else /* !CONFIG_RRVISION */
727 * Hx Vx Fx Bx VDS INT LCYC LP LST
729 * vertical; blanking
731 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
732 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
733 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
734 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
736 * active area (TOP)
738 if (Y1 > 0) {
739 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0); /* 11? */
740 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
741 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
742 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
745 * field active area (CENTER)
747 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0); /* 265? */
748 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
749 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
750 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
752 if (X2 > 0)
753 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
755 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
757 * field active area (BOTTOM)
759 if (Y2 > 0) {
760 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0); /* 12? */
761 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
762 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
763 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
766 * field vertical; blanking
768 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
769 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
770 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
771 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
773 * Create the other field (like this, but whit other field selected,
774 * one more cycle loop and a last identifier)
776 video_mode_dupefield (vr, &vr[entry], entry);
777 #endif /* CONFIG_RRVISION */
779 #endif /* VIDEO_MODE_PAL */
781 /* See what FIFO are we using */
782 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
784 /* Set number of lines and burst (only one frame for now) */
785 if (fifo) {
786 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
787 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
788 } else {
789 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
790 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
793 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
796 * Wait until changes are applied (not done)
797 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
800 /* Return number of VRAM entries */
801 return entry * 2;
804 static void video_encoder_init (void)
806 #ifdef VIDEO_I2C
807 int rc;
809 /* Initialize the I2C */
810 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
811 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
813 #ifdef CONFIG_FADS
814 /* Reset ADV7176 chip */
815 debug ("[VIDEO ENCODER] Resetting encoder...\n");
816 (*(int *) BCSR4) &= ~(1 << 21);
818 /* Wait for 5 ms inside the reset */
819 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
820 udelay (5000);
822 /* Take ADV7176 out of reset */
823 (*(int *) BCSR4) |= 1 << 21;
825 /* Wait for 5 ms after the reset */
826 udelay (5000);
827 #endif /* CONFIG_FADS */
829 /* Send configuration */
830 #ifdef DEBUG
832 int i;
834 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
836 printf ("Sending %d bytes (@ %08lX) to I2C 0x%X:\n ",
837 sizeof(video_encoder_data),
838 (ulong)video_encoder_data,
839 VIDEO_I2C_ADDR);
840 for (i=0; i<sizeof(video_encoder_data); ++i) {
841 printf(" %02X", video_encoder_data[i]);
843 putc ('\n');
845 #endif /* DEBUG */
847 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
848 video_encoder_data,
849 sizeof(video_encoder_data))) != 0) {
850 printf ("i2c_send error: rc=%d\n", rc);
851 return;
853 #endif /* VIDEO_I2C */
854 return;
857 static void video_ctrl_init (void *memptr)
859 immap_t *immap = (immap_t *) CFG_IMMR;
861 video_fb_address = memptr;
863 /* Set background */
864 debug ("[VIDEO CTRL] Setting background color...\n");
865 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
867 /* Show the background */
868 debug ("[VIDEO CTRL] Forcing background...\n");
869 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
871 /* Turn off video controller */
872 debug ("[VIDEO CTRL] Turning off video controller...\n");
873 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
875 #ifdef CONFIG_FADS
876 /* Turn on Video Port LED */
877 debug ("[VIDEO CTRL] Turning off video port led...\n");
878 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
880 /* Disable internal clock */
881 debug ("[VIDEO CTRL] Disabling internal clock...\n");
882 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
883 #endif
885 /* Generate and make active a new video mode */
886 debug ("[VIDEO CTRL] Generating video mode...\n");
887 video_mode_generate ();
889 /* Start of frame buffer (even and odd frame, to make it working with */
890 /* any selected active set) */
891 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
892 immap->im_vid.vid_vfaa1 =
893 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
894 immap->im_vid.vid_vfba1 =
895 immap->im_vid.vid_vfba0 =
896 (u32) video_fb_address + VIDEO_LINE_LEN;
898 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
899 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
900 immap->im_vid.vid_vccr = 0x2042;
902 /* Configure port pins */
903 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
904 immap->im_ioport.iop_pdpar = 0x1fff;
905 immap->im_ioport.iop_pddir = 0x0000;
907 #ifdef CONFIG_FADS
908 /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
909 debug ("[VIDEO CTRL] Turning on video clock...\n");
910 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
912 /* Turn on Video Port LED */
913 debug ("[VIDEO CTRL] Turning on video port led...\n");
914 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
915 #endif
916 #ifdef CONFIG_RRVISION
917 debug ("PC5->Output(1): enable PAL clock");
918 immap->im_ioport.iop_pcpar &= ~(0x0400);
919 immap->im_ioport.iop_pcdir |= 0x0400 ;
920 immap->im_ioport.iop_pcdat |= 0x0400 ;
921 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
922 immap->im_ioport.iop_pdpar,
923 immap->im_ioport.iop_pddir,
924 immap->im_ioport.iop_pddat);
925 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
926 immap->im_ioport.iop_pcpar,
927 immap->im_ioport.iop_pcdir,
928 immap->im_ioport.iop_pcdat);
929 #endif /* CONFIG_RRVISION */
931 /* Blanking the screen. */
932 debug ("[VIDEO CTRL] Blanking the screen...\n");
933 video_fill (VIDEO_BG_COL);
936 * Turns on Aggressive Mode. Normally, turning on the caches
937 * will cause the screen to flicker when the caches try to
938 * fill. This gives the FIFO's for the Video Controller
939 * higher priority and prevents flickering because of
940 * underrun. This may still be an issue when using FLASH,
941 * since accessing data from Flash is so slow.
943 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
944 immap->im_siu_conf.sc_sdcr = 0x40;
946 /* Turn on video controller */
947 debug ("[VIDEO CTRL] Turning on video controller...\n");
948 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
950 /* Show the display */
951 debug ("[VIDEO CTRL] Enabling the video...\n");
952 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
955 /************************************************************************/
956 /* ** CONSOLE FUNCTIONS */
957 /************************************************************************/
959 static void console_scrollup (void)
961 /* Copy up rows ignoring the first one */
962 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
964 /* Clear the last one */
965 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
968 static inline void console_back (void)
970 console_col--;
972 if (console_col < 0) {
973 console_col = CONSOLE_COLS - 1;
974 console_row--;
975 if (console_row < 0)
976 console_row = 0;
979 video_putchar ( console_col * VIDEO_FONT_WIDTH,
980 console_row * VIDEO_FONT_HEIGHT, ' ');
983 static inline void console_newline (void)
985 console_row++;
986 console_col = 0;
988 /* Check if we need to scroll the terminal */
989 if (console_row >= CONSOLE_ROWS) {
990 /* Scroll everything up */
991 console_scrollup ();
993 /* Decrement row number */
994 console_row--;
998 void video_putc (const char c)
1000 if (!video_enable) {
1001 serial_putc (c);
1002 return;
1005 switch (c) {
1006 case 13: /* Simply ignore this */
1007 break;
1009 case '\n': /* Next line, please */
1010 console_newline ();
1011 break;
1013 case 9: /* Tab (8 chars alignment) */
1014 console_col |= 0x0008; /* Next 8 chars boundary */
1015 console_col &= ~0x0007; /* Set this bit to zero */
1017 if (console_col >= CONSOLE_COLS)
1018 console_newline ();
1019 break;
1021 case 8: /* Eat last character */
1022 console_back ();
1023 break;
1025 default: /* Add to the console */
1026 video_putchar ( console_col * VIDEO_FONT_WIDTH,
1027 console_row * VIDEO_FONT_HEIGHT, c);
1028 console_col++;
1029 /* Check if we need to go to next row */
1030 if (console_col >= CONSOLE_COLS)
1031 console_newline ();
1035 void video_puts (const char *s)
1037 int count = strlen (s);
1039 if (!video_enable)
1040 while (count--)
1041 serial_putc (*s++);
1042 else
1043 while (count--)
1044 video_putc (*s++);
1047 /************************************************************************/
1048 /* ** CURSOR BLINKING FUNCTIONS */
1049 /************************************************************************/
1051 #ifdef VIDEO_BLINK
1053 #define BLINK_TIMER_ID 0
1054 #define BLINK_TIMER_HZ 2
1056 static unsigned char blink_enabled = 0;
1057 static timer_t blink_timer;
1059 static void blink_update (void)
1061 static int blink_row = -1, blink_col = -1, blink_old = 0;
1063 /* Check if we have a new position to invert */
1064 if ((console_row != blink_row) || (console_col != blink_col)) {
1065 /* Check if we need to reverse last character */
1066 if (blink_old)
1067 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1068 (blink_row
1069 #ifdef CONFIG_VIDEO_LOGO
1070 + VIDEO_LOGO_HEIGHT
1071 #endif
1072 ) * VIDEO_FONT_HEIGHT);
1074 /* Update values */
1075 blink_row = console_row;
1076 blink_col = console_col;
1077 blink_old = 0;
1080 /* Reverse this character */
1081 blink_old = !blink_old;
1082 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1083 (console_row
1084 #ifdef CONFIG_VIDEO_LOGO
1085 + VIDEO_LOGO_HEIGHT
1086 #endif
1087 ) * VIDEO_FONT_HEIGHT);
1092 * Handler for blinking cursor
1094 static void blink_handler (void *arg)
1096 /* Blink */
1097 blink_update ();
1098 /* Ack the timer */
1099 timer_ack (&blink_timer);
1102 int blink_set (int blink)
1104 int ret = blink_enabled;
1106 if (blink)
1107 timer_enable (&blink_timer);
1108 else
1109 timer_disable (&blink_timer);
1111 blink_enabled = blink;
1113 return ret;
1116 static inline void blink_close (void)
1118 timer_close (&blink_timer);
1121 static inline void blink_init (void)
1123 timer_init (&blink_timer,
1124 BLINK_TIMER_ID, BLINK_TIMER_HZ,
1125 blink_handler);
1127 #endif
1129 /************************************************************************/
1130 /* ** LOGO PLOTTING FUNCTIONS */
1131 /************************************************************************/
1133 #ifdef CONFIG_VIDEO_LOGO
1134 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1135 int y)
1137 int skip = width - image->width, xcount, ycount = image->height;
1139 #ifdef VIDEO_MODE_YUYV
1140 ushort *source = (ushort *) image->data;
1141 ushort *dest = (ushort *) screen + y * width + x;
1143 while (ycount--) {
1144 xcount = image->width;
1145 while (xcount--)
1146 *dest++ = *source++;
1147 dest += skip;
1149 #endif
1150 #ifdef VIDEO_MODE_RGB
1151 unsigned char
1152 *source = (unsigned short *) image->data,
1153 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1155 while (ycount--) {
1156 xcount = image->width * 3;
1157 memcpy (dest, source, xcount);
1158 source += xcount;
1159 dest += ycount;
1161 #endif
1164 static void *video_logo (void)
1166 u16 *screen = video_fb_address, width = VIDEO_COLS;
1167 #ifdef VIDEO_INFO
1168 # ifndef CONFIG_FADS
1169 char temp[32];
1170 # endif
1171 char info[80];
1172 #endif /* VIDEO_INFO */
1174 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1176 #ifdef VIDEO_INFO
1177 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1178 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1180 sprintf (info, "(C) 2002 DENX Software Engineering");
1181 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1182 info);
1184 sprintf (info, " Wolfgang DENK, wd@denx.de");
1185 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1186 info);
1187 #ifndef CONFIG_FADS /* all normal boards */
1188 /* leave one blank line */
1190 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1191 strmhz(temp, gd->cpu_clk),
1192 gd->ram_size >> 20,
1193 gd->bd->bi_flashsize >> 20 );
1194 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1195 info);
1196 #else /* FADS :-( */
1197 sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1198 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1199 info);
1201 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1202 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1203 info);
1204 #endif
1205 #endif
1207 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1209 #endif
1211 /************************************************************************/
1212 /* ** VIDEO HIGH-LEVEL FUNCTIONS */
1213 /************************************************************************/
1215 static int video_init (void *videobase)
1217 /* Initialize the encoder */
1218 debug ("[VIDEO] Initializing video encoder...\n");
1219 video_encoder_init ();
1221 /* Initialize the video controller */
1222 debug ("[VIDEO] Initializing video controller at %08x...\n",
1223 (int) videobase);
1224 video_ctrl_init (videobase);
1226 /* Setting the palette */
1227 video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
1228 video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
1229 video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
1230 video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
1231 video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
1232 video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
1233 video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
1234 video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
1235 video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
1236 video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
1238 #ifndef CFG_WHITE_ON_BLACK
1239 video_setfgcolor (CONSOLE_COLOR_BLACK);
1240 video_setbgcolor (CONSOLE_COLOR_GREY2);
1241 #else
1242 video_setfgcolor (CONSOLE_COLOR_GREY2);
1243 video_setbgcolor (CONSOLE_COLOR_BLACK);
1244 #endif /* CFG_WHITE_ON_BLACK */
1246 #ifdef CONFIG_VIDEO_LOGO
1247 /* Paint the logo and retrieve tv base address */
1248 debug ("[VIDEO] Drawing the logo...\n");
1249 video_console_address = video_logo ();
1250 #else
1251 video_console_address = video_fb_address;
1252 #endif
1254 #ifdef VIDEO_BLINK
1255 /* Enable the blinking (under construction) */
1256 blink_init ();
1257 blink_set (0); /* To Fix! */
1258 #endif
1260 /* Initialize the console */
1261 console_col = 0;
1262 console_row = 0;
1263 video_enable = 1;
1265 #ifdef VIDEO_MODE_PAL
1266 # define VIDEO_MODE_TMP1 "PAL"
1267 #endif
1268 #ifdef VIDEO_MODE_NTSC
1269 # define VIDEO_MODE_TMP1 "NTSC"
1270 #endif
1271 #ifdef VIDEO_MODE_YUYV
1272 # define VIDEO_MODE_TMP2 "YCbYCr"
1273 #endif
1274 #ifdef VIDEO_MODE_RGB
1275 # define VIDEO_MODE_TMP2 "RGB"
1276 #endif
1277 debug ( VIDEO_MODE_TMP1
1278 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1279 VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1280 VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1281 return 0;
1284 int drv_video_init (void)
1286 int error, devices = 1;
1288 device_t videodev;
1290 video_init ((void *)(gd->fb_base)); /* Video initialization */
1292 /* Device initialization */
1294 memset (&videodev, 0, sizeof (videodev));
1296 strcpy (videodev.name, "video");
1297 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
1298 videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
1299 videodev.putc = video_putc; /* 'putc' function */
1300 videodev.puts = video_puts; /* 'puts' function */
1302 error = device_register (&videodev);
1304 return (error == 0) ? devices : error;
1307 /************************************************************************/
1308 /* ** ROM capable initialization part - needed to reserve FB memory */
1309 /************************************************************************/
1312 * This is called early in the system initialization to grab memory
1313 * for the video controller.
1314 * Returns new address for monitor, after reserving video buffer memory
1316 * Note that this is running from ROM, so no write access to global data.
1318 ulong video_setmem (ulong addr)
1320 /* Allocate pages for the frame buffer. */
1321 addr -= VIDEO_SIZE;
1323 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1324 VIDEO_SIZE>>10, addr);
1326 return (addr);
1329 #endif