3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
5 * Wolfgang Denk, wd@denx.de
7 * See file CREDITS for list of people who contributed to this
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,
28 /************************************************************************/
30 /************************************************************************/
37 #include <timestamp.h>
40 #include <linux/types.h>
45 DECLARE_GLOBAL_DATA_PTR;
47 /************************************************************************/
48 /* ** DEBUG SETTINGS */
49 /************************************************************************/
52 #define VIDEO_DEBUG_COLORBARS /* Force colorbars output */
55 /************************************************************************/
56 /* ** VIDEO MODE SETTINGS */
57 /************************************************************************/
60 #define VIDEO_MODE_EXTENDED /* Allow screen size bigger than visible area */
61 #define VIDEO_MODE_NTSC
64 #define VIDEO_MODE_PAL
67 #define VIDEO_BLINK /* This enables cursor blinking (under construction) */
70 #define VIDEO_INFO /* Show U-Boot information */
71 #define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
72 #define VIDEO_INFO_Y 16
74 /************************************************************************/
75 /* ** VIDEO ENCODER CONSTANTS */
76 /************************************************************************/
78 #ifdef CONFIG_VIDEO_ENCODER_AD7176
80 #include <video_ad7176.h> /* Sets encoder data, mode, and visible and active area */
83 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
86 #ifdef CONFIG_VIDEO_ENCODER_AD7177
88 #include <video_ad7177.h> /* Sets encoder data, mode, and visible and active area */
91 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
94 #ifdef CONFIG_VIDEO_ENCODER_AD7179
96 #include <video_ad7179.h> /* Sets encoder data, mode, and visible and active area */
99 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
102 /************************************************************************/
103 /* ** VIDEO MODE CONSTANTS */
104 /************************************************************************/
106 #ifdef VIDEO_MODE_EXTENDED
107 #define VIDEO_COLS VIDEO_ACTIVE_COLS
108 #define VIDEO_ROWS VIDEO_ACTIVE_ROWS
110 #define VIDEO_COLS VIDEO_VISIBLE_COLS
111 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
114 #define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
115 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Total size of buffer */
116 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) /* Number of ints */
117 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Number of bytes per line */
118 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
120 #ifdef VIDEO_MODE_YUYV
121 #define VIDEO_BG_COL 0x80D880D8 /* Background color in YUYV format */
123 #define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
126 /************************************************************************/
127 /* ** FONT AND LOGO DATA */
128 /************************************************************************/
130 #include <video_font.h> /* Get font data, width and height */
132 #ifdef CONFIG_VIDEO_LOGO
133 #include <video_logo.h> /* Get logo data, width and height */
135 #define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
136 #define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
137 #define VIDEO_LOGO_ADDR &u_boot_logo
140 /************************************************************************/
141 /* ** VIDEO CONTROLLER CONSTANTS */
142 /************************************************************************/
144 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
146 #define VIDEO_VCCR_VON 0 /* Video controller ON */
147 #define VIDEO_VCCR_CSRC 1 /* Clock source */
148 #define VIDEO_VCCR_PDF 13 /* Pixel display format */
149 #define VIDEO_VCCR_IEN 11 /* Interrupt enable */
151 /* VSR - VIDEO STATUS REGISTER */
153 #define VIDEO_VSR_CAS 6 /* Active set */
154 #define VIDEO_VSR_EOF 0 /* End of frame */
156 /* VCMR - VIDEO COMMAND REGISTER */
158 #define VIDEO_VCMR_BD 0 /* Blank display */
159 #define VIDEO_VCMR_ASEL 1 /* Active set selection */
161 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
163 #define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
164 #define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
165 #define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
167 /************************************************************************/
168 /* ** CONSOLE CONSTANTS */
169 /************************************************************************/
171 #ifdef CONFIG_VIDEO_LOGO
172 #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
173 #define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
175 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
178 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
179 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
180 #define CONSOLE_ROW_FIRST (video_console_address)
181 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
182 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
183 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
184 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
187 * Simple color definitions
189 #define CONSOLE_COLOR_BLACK 0
190 #define CONSOLE_COLOR_RED 1
191 #define CONSOLE_COLOR_GREEN 2
192 #define CONSOLE_COLOR_YELLOW 3
193 #define CONSOLE_COLOR_BLUE 4
194 #define CONSOLE_COLOR_MAGENTA 5
195 #define CONSOLE_COLOR_CYAN 6
196 #define CONSOLE_COLOR_GREY 13
197 #define CONSOLE_COLOR_GREY2 14
198 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
200 /************************************************************************/
201 /* ** BITOPS MACROS */
202 /************************************************************************/
204 #define HISHORT(i) ((i >> 16)&0xffff)
205 #define LOSHORT(i) (i & 0xffff)
206 #define HICHAR(s) ((i >> 8)&0xff)
207 #define LOCHAR(s) (i & 0xff)
208 #define HI(c) ((c >> 4)&0xf)
209 #define LO(c) (c & 0xf)
210 #define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
211 #define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
212 #define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
213 #define BITMASK(b) (1 << (b))
214 #define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
215 #define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
217 /************************************************************************/
219 /************************************************************************/
222 unsigned char V, Y1, U, Y2;
225 /* This structure is based on the Video Ram in the MPC823. */
226 typedef struct VRAM {
227 unsigned hx:2, /* Horizontal sync */
228 vx:2, /* Vertical sync */
231 res1:6, /* Reserved */
232 vds:2, /* Video Data Select */
233 inter:1, /* Interrupt */
234 res2:2, /* Reserved */
235 lcyc:11, /* Loop/video cycles */
236 lp:1, /* Loop start/end */
237 lst:1; /* Last entry */
240 /************************************************************************/
242 /************************************************************************/
245 video_panning_range_x = 0, /* Video mode invisible pixels x range */
246 video_panning_range_y = 0, /* Video mode invisible pixels y range */
247 video_panning_value_x = 0, /* Video mode x panning value (absolute) */
248 video_panning_value_y = 0, /* Video mode y panning value (absolute) */
249 video_panning_factor_x = 0, /* Video mode x panning value (-127 +127) */
250 video_panning_factor_y = 0, /* Video mode y panning value (-127 +127) */
251 console_col = 0, /* Cursor col */
252 console_row = 0, /* Cursor row */
253 video_palette[16]; /* Our palette */
255 static const int video_font_draw_table[] =
256 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
259 video_color_fg = 0, /* Current fg color index (0-15) */
260 video_color_bg = 0, /* Current bg color index (0-15) */
261 video_enable = 0; /* Video has been initialized? */
264 *video_fb_address, /* Frame buffer address */
265 *video_console_address; /* Console frame buffer start address */
267 /************************************************************************/
268 /* ** MEMORY FUNCTIONS (32bit) */
269 /************************************************************************/
271 static void memsetl (int *p, int c, int v)
277 static void memcpyl (int *d, int *s, int c)
283 /************************************************************************/
284 /* ** VIDEO DRAWING AND COLOR FUNCTIONS */
285 /************************************************************************/
287 static int video_maprgb (int r, int g, int b)
289 #ifdef VIDEO_MODE_YUYV
290 unsigned int pR, pG, pB;
292 unsigned int *ret = (unsigned int *) &YUYV;
294 /* Transform (0-255) components to (0-100) */
300 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
302 YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
303 YUYV.U = pR - (pG * 3 / 4) - (pB / 4) + 128;
304 YUYV.V = pB - (pR / 4) - (pG * 3 / 4) + 128;
307 #ifdef VIDEO_MODE_RGB
308 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
312 static void video_setpalette (int color, int r, int g, int b)
316 video_palette[color] = video_maprgb (r, g, b);
318 /* Swap values if our panning offset is odd */
319 if (video_panning_value_x & 1)
320 video_palette[color] = SWAPINT (video_palette[color]);
323 static void video_fill (int color)
325 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
328 static void video_setfgcolor (int i)
330 video_color_fg = i & 0xf;
333 static void video_setbgcolor (int i)
335 video_color_bg = i & 0xf;
338 static int video_pickcolor (int i)
340 return video_palette[i & 0xf];
343 /* Absolute console plotting functions */
346 static void video_revchar (int xx, int yy)
351 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
353 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
354 switch (VIDEO_FONT_WIDTH) {
356 ((u32 *) dest)[6] ^= 0xffffffff;
357 ((u32 *) dest)[7] ^= 0xffffffff;
360 ((u32 *) dest)[4] ^= 0xffffffff;
361 ((u32 *) dest)[5] ^= 0xffffffff;
364 ((u32 *) dest)[2] ^= 0xffffffff;
365 ((u32 *) dest)[3] ^= 0xffffffff;
368 ((u32 *) dest)[0] ^= 0xffffffff;
369 ((u32 *) dest)[1] ^= 0xffffffff;
375 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
377 u8 *cdat, *dest, *dest0;
381 offset = yy * VIDEO_LINE_LEN + xx * 2;
382 dest0 = video_fb_address + offset;
384 fgx = video_pickcolor (video_color_fg);
385 bgx = video_pickcolor (video_color_bg);
394 switch (VIDEO_FONT_WIDTH) {
399 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
400 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
402 dest += VIDEO_LINE_LEN) {
406 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
408 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
409 if (VIDEO_FONT_WIDTH == 8) {
411 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
413 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
416 dest0 += VIDEO_FONT_WIDTH * 2;
423 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
424 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
425 dest += VIDEO_LINE_LEN) {
429 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
431 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
433 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
435 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
438 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
440 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
441 if (VIDEO_FONT_WIDTH == 16) {
443 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
445 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
449 dest0 += VIDEO_FONT_WIDTH * 2;
455 static inline void video_drawstring (int xx, int yy, char *s)
457 video_drawchars (xx, yy, (unsigned char *)s, strlen (s));
460 /* Relative to console plotting functions */
462 static void video_putchars (int xx, int yy, unsigned char *s, int count)
464 #ifdef CONFIG_VIDEO_LOGO
465 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
467 video_drawchars (xx, yy, s, count);
471 static void video_putchar (int xx, int yy, unsigned char c)
473 #ifdef CONFIG_VIDEO_LOGO
474 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
476 video_drawchars (xx, yy, &c, 1);
480 static inline void video_putstring (int xx, int yy, unsigned char *s)
482 video_putchars (xx, yy, (unsigned char *)s, strlen ((char *)s));
485 /************************************************************************/
486 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
487 /************************************************************************/
489 #if !defined(CONFIG_RRVISION)
490 static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
494 for (i = 0; i < entries; i++) {
495 dest[i] = source[i]; /* Copy the entire record */
496 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
499 dest[0].lcyc++; /* Add a cycle to the first entry */
500 dest[entries - 1].lst = 1; /* Set end of ram entries */
504 static void inline video_mode_addentry (VRAM * vr,
505 int Hx, int Vx, int Fx, int Bx,
506 int VDS, int INT, int LCYC, int LP, int LST)
519 #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)
521 static int video_mode_generate (void)
523 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
524 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
525 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
527 /* CHECKING PARAMETERS */
529 if (video_panning_factor_y < -128)
530 video_panning_factor_y = -128;
532 if (video_panning_factor_y > 128)
533 video_panning_factor_y = 128;
535 if (video_panning_factor_x < -128)
536 video_panning_factor_x = -128;
538 if (video_panning_factor_x > 128)
539 video_panning_factor_x = 128;
541 /* Setting panning */
543 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
544 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
546 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
547 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
549 /* We assume these are burst units (multiplied by 2, we need it pari) */
550 X1 = video_panning_value_x & 0xfffe;
553 /* We assume these are field line units (divided by 2, we need it pari) */
554 Y1 = video_panning_value_y & 0xfffe;
557 debug("X1=%d, X2=%d, Y1=%d, Y2=%d, DX=%d, DY=%d VIDEO_COLS=%d \n",
558 X1, X2, Y1, Y2, DX, DY, VIDEO_COLS);
560 #ifdef VIDEO_MODE_NTSC
562 * Hx Vx Fx Bx VDS INT LCYC LP LST
566 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
567 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
568 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
569 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
573 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
574 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
575 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
576 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
578 * Odd field active area (TOP)
581 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
582 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
583 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
584 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
587 * Odd field active area
589 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
590 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
591 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
592 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
595 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
597 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
600 * Odd field active area (BOTTOM)
603 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
604 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
605 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
606 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
611 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
612 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
613 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
614 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
618 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
619 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
620 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
621 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
623 * Even field active area (TOP)
626 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
627 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
628 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
629 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
632 * Even field active area (CENTER)
634 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
635 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
636 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
637 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
640 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
642 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
644 * Even field active area (BOTTOM)
647 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
648 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
649 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
650 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
655 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
656 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
657 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
658 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
661 #ifdef VIDEO_MODE_PAL
663 #if defined(CONFIG_RRVISION)
665 #define HPW 160 /* horizontal pulse width (was 139) */
666 #define VPW 2 /* vertical pulse width */
667 #define HBP 104 /* horizontal back porch (was 112) */
668 #define VBP 19 /* vertical back porch (was 19) */
669 #define VID_R 240 /* number of rows */
671 debug ("[VIDEO CTRL] Starting to add controller entries...");
675 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
676 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
677 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
679 ADDENTRY (0, 0, 0, 3, 1, 0, VPW, 1, 0);
680 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
681 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
683 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
684 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
685 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
689 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
690 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
691 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
692 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
693 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
695 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
696 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
697 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
701 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
702 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
703 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
705 ADDENTRY (0, 0, 0, 3, 1, 0, VPW+1, 1, 0);
706 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
707 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
709 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
710 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
711 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
715 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
716 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
717 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
718 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
719 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
721 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
722 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
723 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
727 #else /* !CONFIG_RRVISION */
730 * Hx Vx Fx Bx VDS INT LCYC LP LST
734 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
735 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
736 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
737 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
742 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0); /* 11? */
743 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
744 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
745 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
748 * field active area (CENTER)
750 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0); /* 265? */
751 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
752 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
753 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
756 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
758 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
760 * field active area (BOTTOM)
763 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0); /* 12? */
764 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
765 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
766 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
769 * field vertical; blanking
771 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
772 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
773 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
774 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
776 * Create the other field (like this, but whit other field selected,
777 * one more cycle loop and a last identifier)
779 video_mode_dupefield (vr, &vr[entry], entry);
780 #endif /* CONFIG_RRVISION */
782 #endif /* VIDEO_MODE_PAL */
784 /* See what FIFO are we using */
785 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
787 /* Set number of lines and burst (only one frame for now) */
789 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
790 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
792 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
793 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
796 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
799 * Wait until changes are applied (not done)
800 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
803 /* Return number of VRAM entries */
807 static void video_encoder_init (void)
812 /* Initialize the I2C */
813 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
814 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
817 /* Reset ADV7176 chip */
818 debug ("[VIDEO ENCODER] Resetting encoder...\n");
819 (*(int *) BCSR4) &= ~(1 << 21);
821 /* Wait for 5 ms inside the reset */
822 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
825 /* Take ADV7176 out of reset */
826 (*(int *) BCSR4) |= 1 << 21;
828 /* Wait for 5 ms after the reset */
830 #endif /* CONFIG_FADS */
832 /* Send configuration */
837 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
839 printf ("Sending %zu bytes (@ %08lX) to I2C 0x%lX:\n ",
840 sizeof(video_encoder_data),
841 (ulong)video_encoder_data,
842 (ulong)VIDEO_I2C_ADDR);
843 for (i=0; i<sizeof(video_encoder_data); ++i) {
844 printf(" %02X", video_encoder_data[i]);
850 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
852 sizeof(video_encoder_data))) != 0) {
853 printf ("i2c_send error: rc=%d\n", rc);
856 #endif /* VIDEO_I2C */
860 static void video_ctrl_init (void *memptr)
862 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
864 video_fb_address = memptr;
867 debug ("[VIDEO CTRL] Setting background color...\n");
868 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
870 /* Show the background */
871 debug ("[VIDEO CTRL] Forcing background...\n");
872 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
874 /* Turn off video controller */
875 debug ("[VIDEO CTRL] Turning off video controller...\n");
876 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
879 /* Turn on Video Port LED */
880 debug ("[VIDEO CTRL] Turning off video port led...\n");
881 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
883 /* Disable internal clock */
884 debug ("[VIDEO CTRL] Disabling internal clock...\n");
885 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
888 /* Generate and make active a new video mode */
889 debug ("[VIDEO CTRL] Generating video mode...\n");
890 video_mode_generate ();
892 /* Start of frame buffer (even and odd frame, to make it working with */
893 /* any selected active set) */
894 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
895 immap->im_vid.vid_vfaa1 =
896 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
897 immap->im_vid.vid_vfba1 =
898 immap->im_vid.vid_vfba0 =
899 (u32) video_fb_address + VIDEO_LINE_LEN;
901 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
902 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
903 immap->im_vid.vid_vccr = 0x2042;
905 /* Configure port pins */
906 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
907 immap->im_ioport.iop_pdpar = 0x1fff;
908 immap->im_ioport.iop_pddir = 0x0000;
911 /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
912 debug ("[VIDEO CTRL] Turning on video clock...\n");
913 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
915 /* Turn on Video Port LED */
916 debug ("[VIDEO CTRL] Turning on video port led...\n");
917 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
919 #ifdef CONFIG_RRVISION
920 debug ("PC5->Output(1): enable PAL clock");
921 immap->im_ioport.iop_pcpar &= ~(0x0400);
922 immap->im_ioport.iop_pcdir |= 0x0400 ;
923 immap->im_ioport.iop_pcdat |= 0x0400 ;
924 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
925 immap->im_ioport.iop_pdpar,
926 immap->im_ioport.iop_pddir,
927 immap->im_ioport.iop_pddat);
928 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
929 immap->im_ioport.iop_pcpar,
930 immap->im_ioport.iop_pcdir,
931 immap->im_ioport.iop_pcdat);
932 #endif /* CONFIG_RRVISION */
934 /* Blanking the screen. */
935 debug ("[VIDEO CTRL] Blanking the screen...\n");
936 video_fill (VIDEO_BG_COL);
939 * Turns on Aggressive Mode. Normally, turning on the caches
940 * will cause the screen to flicker when the caches try to
941 * fill. This gives the FIFO's for the Video Controller
942 * higher priority and prevents flickering because of
943 * underrun. This may still be an issue when using FLASH,
944 * since accessing data from Flash is so slow.
946 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
947 immap->im_siu_conf.sc_sdcr = 0x40;
949 /* Turn on video controller */
950 debug ("[VIDEO CTRL] Turning on video controller...\n");
951 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
953 /* Show the display */
954 debug ("[VIDEO CTRL] Enabling the video...\n");
955 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
958 /************************************************************************/
959 /* ** CONSOLE FUNCTIONS */
960 /************************************************************************/
962 static void console_scrollup (void)
964 /* Copy up rows ignoring the first one */
965 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
967 /* Clear the last one */
968 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
971 static inline void console_back (void)
975 if (console_col < 0) {
976 console_col = CONSOLE_COLS - 1;
982 video_putchar ( console_col * VIDEO_FONT_WIDTH,
983 console_row * VIDEO_FONT_HEIGHT, ' ');
986 static inline void console_newline (void)
991 /* Check if we need to scroll the terminal */
992 if (console_row >= CONSOLE_ROWS) {
993 /* Scroll everything up */
996 /* Decrement row number */
1001 void video_putc (const char c)
1003 if (!video_enable) {
1009 case 13: /* Simply ignore this */
1012 case '\n': /* Next line, please */
1016 case 9: /* Tab (8 chars alignment) */
1017 console_col |= 0x0008; /* Next 8 chars boundary */
1018 console_col &= ~0x0007; /* Set this bit to zero */
1020 if (console_col >= CONSOLE_COLS)
1024 case 8: /* Eat last character */
1028 default: /* Add to the console */
1029 video_putchar ( console_col * VIDEO_FONT_WIDTH,
1030 console_row * VIDEO_FONT_HEIGHT, c);
1032 /* Check if we need to go to next row */
1033 if (console_col >= CONSOLE_COLS)
1038 void video_puts (const char *s)
1040 int count = strlen (s);
1050 /************************************************************************/
1051 /* ** CURSOR BLINKING FUNCTIONS */
1052 /************************************************************************/
1056 #define BLINK_TIMER_ID 0
1057 #define BLINK_TIMER_HZ 2
1059 static unsigned char blink_enabled = 0;
1060 static timer_t blink_timer;
1062 static void blink_update (void)
1064 static int blink_row = -1, blink_col = -1, blink_old = 0;
1066 /* Check if we have a new position to invert */
1067 if ((console_row != blink_row) || (console_col != blink_col)) {
1068 /* Check if we need to reverse last character */
1070 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1072 #ifdef CONFIG_VIDEO_LOGO
1075 ) * VIDEO_FONT_HEIGHT);
1078 blink_row = console_row;
1079 blink_col = console_col;
1083 /* Reverse this character */
1084 blink_old = !blink_old;
1085 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1087 #ifdef CONFIG_VIDEO_LOGO
1090 ) * VIDEO_FONT_HEIGHT);
1095 * Handler for blinking cursor
1097 static void blink_handler (void *arg)
1102 timer_ack (&blink_timer);
1105 int blink_set (int blink)
1107 int ret = blink_enabled;
1110 timer_enable (&blink_timer);
1112 timer_disable (&blink_timer);
1114 blink_enabled = blink;
1119 static inline void blink_close (void)
1121 timer_close (&blink_timer);
1124 static inline void blink_init (void)
1126 timer_init (&blink_timer,
1127 BLINK_TIMER_ID, BLINK_TIMER_HZ,
1132 /************************************************************************/
1133 /* ** LOGO PLOTTING FUNCTIONS */
1134 /************************************************************************/
1136 #ifdef CONFIG_VIDEO_LOGO
1137 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1140 int skip = width - image->width, xcount, ycount = image->height;
1142 #ifdef VIDEO_MODE_YUYV
1143 ushort *source = (ushort *) image->data;
1144 ushort *dest = (ushort *) screen + y * width + x;
1147 xcount = image->width;
1149 *dest++ = *source++;
1153 #ifdef VIDEO_MODE_RGB
1155 *source = (unsigned short *) image->data,
1156 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1159 xcount = image->width * 3;
1160 memcpy (dest, source, xcount);
1167 static void *video_logo (void)
1169 u16 *screen = video_fb_address, width = VIDEO_COLS;
1171 # ifndef CONFIG_FADS
1175 #endif /* VIDEO_INFO */
1177 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1180 sprintf (info, "%s (%s - %s) ",
1181 U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
1182 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1184 sprintf (info, "(C) 2002 DENX Software Engineering");
1185 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1188 sprintf (info, " Wolfgang DENK, wd@denx.de");
1189 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1191 #ifndef CONFIG_FADS /* all normal boards */
1192 /* leave one blank line */
1194 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1195 strmhz(temp, gd->cpu_clk),
1197 gd->bd->bi_flashsize >> 20 );
1198 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1200 #else /* FADS :-( */
1201 sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1202 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1205 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1206 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1211 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1215 /************************************************************************/
1216 /* ** VIDEO HIGH-LEVEL FUNCTIONS */
1217 /************************************************************************/
1219 static int video_init (void *videobase)
1221 /* Initialize the encoder */
1222 debug ("[VIDEO] Initializing video encoder...\n");
1223 video_encoder_init ();
1225 /* Initialize the video controller */
1226 debug ("[VIDEO] Initializing video controller at %08x...\n",
1228 video_ctrl_init (videobase);
1230 /* Setting the palette */
1231 video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
1232 video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
1233 video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
1234 video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
1235 video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
1236 video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
1237 video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
1238 video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
1239 video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
1240 video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
1242 #ifndef CONFIG_SYS_WHITE_ON_BLACK
1243 video_setfgcolor (CONSOLE_COLOR_BLACK);
1244 video_setbgcolor (CONSOLE_COLOR_GREY2);
1246 video_setfgcolor (CONSOLE_COLOR_GREY2);
1247 video_setbgcolor (CONSOLE_COLOR_BLACK);
1248 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
1250 #ifdef CONFIG_VIDEO_LOGO
1251 /* Paint the logo and retrieve tv base address */
1252 debug ("[VIDEO] Drawing the logo...\n");
1253 video_console_address = video_logo ();
1255 video_console_address = video_fb_address;
1259 /* Enable the blinking (under construction) */
1261 blink_set (0); /* To Fix! */
1264 /* Initialize the console */
1269 #ifdef VIDEO_MODE_PAL
1270 # define VIDEO_MODE_TMP1 "PAL"
1272 #ifdef VIDEO_MODE_NTSC
1273 # define VIDEO_MODE_TMP1 "NTSC"
1275 #ifdef VIDEO_MODE_YUYV
1276 # define VIDEO_MODE_TMP2 "YCbYCr"
1278 #ifdef VIDEO_MODE_RGB
1279 # define VIDEO_MODE_TMP2 "RGB"
1281 debug ( VIDEO_MODE_TMP1
1282 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1283 VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1284 VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1288 int drv_video_init (void)
1290 int error, devices = 1;
1294 video_init ((void *)(gd->fb_base)); /* Video initialization */
1296 /* Device initialization */
1298 memset (&videodev, 0, sizeof (videodev));
1300 strcpy (videodev.name, "video");
1301 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
1302 videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
1303 videodev.putc = video_putc; /* 'putc' function */
1304 videodev.puts = video_puts; /* 'puts' function */
1306 error = device_register (&videodev);
1308 return (error == 0) ? devices : error;
1311 /************************************************************************/
1312 /* ** ROM capable initialization part - needed to reserve FB memory */
1313 /************************************************************************/
1316 * This is called early in the system initialization to grab memory
1317 * for the video controller.
1318 * Returns new address for monitor, after reserving video buffer memory
1320 * Note that this is running from ROM, so no write access to global data.
1322 ulong video_setmem (ulong addr)
1324 /* Allocate pages for the frame buffer. */
1327 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1328 VIDEO_SIZE>>10, addr);