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 <linux/types.h>
42 /************************************************************************/
43 /* ** DEBUG SETTINGS */
44 /************************************************************************/
47 #define VIDEO_DEBUG_COLORBARS /* Force colorbars output */
50 /************************************************************************/
51 /* ** VIDEO MODE SETTINGS */
52 /************************************************************************/
55 #define VIDEO_MODE_EXTENDED /* Allow screen size bigger than visible area */
56 #define VIDEO_MODE_NTSC
59 #define VIDEO_MODE_PAL
62 #define VIDEO_BLINK /* This enables cursor blinking (under construction) */
65 #define VIDEO_INFO /* Show U-Boot information */
66 #define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
67 #define VIDEO_INFO_Y 16
69 /************************************************************************/
70 /* ** VIDEO ENCODER CONSTANTS */
71 /************************************************************************/
73 #ifdef CONFIG_VIDEO_ENCODER_AD7176
75 #include <video_ad7176.h> /* Sets encoder data, mode, and visible and active area */
78 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
81 #ifdef CONFIG_VIDEO_ENCODER_AD7177
83 #include <video_ad7177.h> /* Sets encoder data, mode, and visible and active area */
86 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
89 #ifdef CONFIG_VIDEO_ENCODER_AD7179
91 #include <video_ad7179.h> /* Sets encoder data, mode, and visible and active area */
94 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
97 /************************************************************************/
98 /* ** VIDEO MODE CONSTANTS */
99 /************************************************************************/
101 #ifdef VIDEO_MODE_EXTENDED
102 #define VIDEO_COLS VIDEO_ACTIVE_COLS
103 #define VIDEO_ROWS VIDEO_ACTIVE_ROWS
105 #define VIDEO_COLS VIDEO_VISIBLE_COLS
106 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
109 #define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
110 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Total size of buffer */
111 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) /* Number of ints */
112 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Number of bytes per line */
113 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
115 #ifdef VIDEO_MODE_YUYV
116 #define VIDEO_BG_COL 0x80D880D8 /* Background color in YUYV format */
118 #define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
121 /************************************************************************/
122 /* ** FONT AND LOGO DATA */
123 /************************************************************************/
125 #include <video_font.h> /* Get font data, width and height */
127 #ifdef CONFIG_VIDEO_LOGO
128 #include <video_logo.h> /* Get logo data, width and height */
130 #define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
131 #define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
132 #define VIDEO_LOGO_ADDR &u_boot_logo
135 /************************************************************************/
136 /* ** VIDEO CONTROLLER CONSTANTS */
137 /************************************************************************/
139 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
141 #define VIDEO_VCCR_VON 0 /* Video controller ON */
142 #define VIDEO_VCCR_CSRC 1 /* Clock source */
143 #define VIDEO_VCCR_PDF 13 /* Pixel display format */
144 #define VIDEO_VCCR_IEN 11 /* Interrupt enable */
146 /* VSR - VIDEO STATUS REGISTER */
148 #define VIDEO_VSR_CAS 6 /* Active set */
149 #define VIDEO_VSR_EOF 0 /* End of frame */
151 /* VCMR - VIDEO COMMAND REGISTER */
153 #define VIDEO_VCMR_BD 0 /* Blank display */
154 #define VIDEO_VCMR_ASEL 1 /* Active set selection */
156 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
158 #define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
159 #define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
160 #define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
162 /************************************************************************/
163 /* ** CONSOLE CONSTANTS */
164 /************************************************************************/
166 #ifdef CONFIG_VIDEO_LOGO
167 #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
168 #define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
170 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
173 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
174 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
175 #define CONSOLE_ROW_FIRST (video_console_address)
176 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
177 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
178 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
179 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
182 * Simple color definitions
184 #define CONSOLE_COLOR_BLACK 0
185 #define CONSOLE_COLOR_RED 1
186 #define CONSOLE_COLOR_GREEN 2
187 #define CONSOLE_COLOR_YELLOW 3
188 #define CONSOLE_COLOR_BLUE 4
189 #define CONSOLE_COLOR_MAGENTA 5
190 #define CONSOLE_COLOR_CYAN 6
191 #define CONSOLE_COLOR_GREY 13
192 #define CONSOLE_COLOR_GREY2 14
193 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
195 /************************************************************************/
196 /* ** BITOPS MACROS */
197 /************************************************************************/
199 #define HISHORT(i) ((i >> 16)&0xffff)
200 #define LOSHORT(i) (i & 0xffff)
201 #define HICHAR(s) ((i >> 8)&0xff)
202 #define LOCHAR(s) (i & 0xff)
203 #define HI(c) ((c >> 4)&0xf)
204 #define LO(c) (c & 0xf)
205 #define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
206 #define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
207 #define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
208 #define BITMASK(b) (1 << (b))
209 #define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
210 #define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
212 /************************************************************************/
214 /************************************************************************/
217 unsigned char V, Y1, U, Y2;
220 /* This structure is based on the Video Ram in the MPC823. */
221 typedef struct VRAM {
222 unsigned hx:2, /* Horizontal sync */
223 vx:2, /* Vertical sync */
226 res1:6, /* Reserved */
227 vds:2, /* Video Data Select */
228 inter:1, /* Interrupt */
229 res2:2, /* Reserved */
230 lcyc:11, /* Loop/video cycles */
231 lp:1, /* Loop start/end */
232 lst:1; /* Last entry */
235 /************************************************************************/
237 /************************************************************************/
240 video_panning_range_x = 0, /* Video mode invisible pixels x range */
241 video_panning_range_y = 0, /* Video mode invisible pixels y range */
242 video_panning_value_x = 0, /* Video mode x panning value (absolute) */
243 video_panning_value_y = 0, /* Video mode y panning value (absolute) */
244 video_panning_factor_x = 0, /* Video mode x panning value (-127 +127) */
245 video_panning_factor_y = 0, /* Video mode y panning value (-127 +127) */
246 console_col = 0, /* Cursor col */
247 console_row = 0, /* Cursor row */
248 video_palette[16]; /* Our palette */
250 static const int video_font_draw_table[] =
251 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
254 video_color_fg = 0, /* Current fg color index (0-15) */
255 video_color_bg = 0, /* Current bg color index (0-15) */
256 video_enable = 0; /* Video has been initialized? */
259 *video_fb_address, /* Frame buffer address */
260 *video_console_address; /* Console frame buffer start address */
262 /************************************************************************/
263 /* ** MEMORY FUNCTIONS (32bit) */
264 /************************************************************************/
266 static void memsetl (int *p, int c, int v)
272 static void memcpyl (int *d, int *s, int c)
278 /************************************************************************/
279 /* ** VIDEO DRAWING AND COLOR FUNCTIONS */
280 /************************************************************************/
282 static int video_maprgb (int r, int g, int b)
284 #ifdef VIDEO_MODE_YUYV
285 unsigned int pR, pG, pB;
287 unsigned int *ret = (unsigned int *) &YUYV;
289 /* Transform (0-255) components to (0-100) */
295 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
297 YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
298 YUYV.U = pR - (pG * 3 / 4) - (pB / 4) + 128;
299 YUYV.V = pB - (pR / 4) - (pG * 3 / 4) + 128;
302 #ifdef VIDEO_MODE_RGB
303 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
307 static void video_setpalette (int color, int r, int g, int b)
311 video_palette[color] = video_maprgb (r, g, b);
313 /* Swap values if our panning offset is odd */
314 if (video_panning_value_x & 1)
315 video_palette[color] = SWAPINT (video_palette[color]);
318 static void video_fill (int color)
320 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
323 static void video_setfgcolor (int i)
325 video_color_fg = i & 0xf;
328 static void video_setbgcolor (int i)
330 video_color_bg = i & 0xf;
333 static int video_pickcolor (int i)
335 return video_palette[i & 0xf];
338 /* Absolute console plotting functions */
341 static void video_revchar (int xx, int yy)
346 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
348 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
349 switch (VIDEO_FONT_WIDTH) {
351 ((u32 *) dest)[6] ^= 0xffffffff;
352 ((u32 *) dest)[7] ^= 0xffffffff;
355 ((u32 *) dest)[4] ^= 0xffffffff;
356 ((u32 *) dest)[5] ^= 0xffffffff;
359 ((u32 *) dest)[2] ^= 0xffffffff;
360 ((u32 *) dest)[3] ^= 0xffffffff;
363 ((u32 *) dest)[0] ^= 0xffffffff;
364 ((u32 *) dest)[1] ^= 0xffffffff;
370 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
372 u8 *cdat, *dest, *dest0;
376 offset = yy * VIDEO_LINE_LEN + xx * 2;
377 dest0 = video_fb_address + offset;
379 fgx = video_pickcolor (video_color_fg);
380 bgx = video_pickcolor (video_color_bg);
389 switch (VIDEO_FONT_WIDTH) {
394 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
395 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
397 dest += VIDEO_LINE_LEN) {
401 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
403 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
404 if (VIDEO_FONT_WIDTH == 8) {
406 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
408 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
411 dest0 += VIDEO_FONT_WIDTH * 2;
418 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
419 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
420 dest += VIDEO_LINE_LEN) {
424 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
426 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
428 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
430 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
433 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
435 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
436 if (VIDEO_FONT_WIDTH == 16) {
438 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
440 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
444 dest0 += VIDEO_FONT_WIDTH * 2;
450 static inline void video_drawstring (int xx, int yy, unsigned char *s)
452 video_drawchars (xx, yy, s, strlen (s));
455 /* Relative to console plotting functions */
457 static void video_putchars (int xx, int yy, unsigned char *s, int count)
459 #ifdef CONFIG_VIDEO_LOGO
460 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
462 video_drawchars (xx, yy, s, count);
466 static void video_putchar (int xx, int yy, unsigned char c)
468 #ifdef CONFIG_VIDEO_LOGO
469 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
471 video_drawchars (xx, yy, &c, 1);
475 static inline void video_putstring (int xx, int yy, unsigned char *s)
477 video_putchars (xx, yy, s, strlen (s));
480 /************************************************************************/
481 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
482 /************************************************************************/
484 #if !defined(CONFIG_RRVISION)
485 static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
489 for (i = 0; i < entries; i++) {
490 dest[i] = source[i]; /* Copy the entire record */
491 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
494 dest[0].lcyc++; /* Add a cycle to the first entry */
495 dest[entries - 1].lst = 1; /* Set end of ram entries */
499 static void inline video_mode_addentry (VRAM * vr,
500 int Hx, int Vx, int Fx, int Bx,
501 int VDS, int INT, int LCYC, int LP, int LST)
514 #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)
516 static int video_mode_generate (void)
518 immap_t *immap = (immap_t *) CFG_IMMR;
519 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
520 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
522 /* CHECKING PARAMETERS */
524 if (video_panning_factor_y < -128)
525 video_panning_factor_y = -128;
527 if (video_panning_factor_y > 128)
528 video_panning_factor_y = 128;
530 if (video_panning_factor_x < -128)
531 video_panning_factor_x = -128;
533 if (video_panning_factor_x > 128)
534 video_panning_factor_x = 128;
536 /* Setting panning */
538 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
539 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
541 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
542 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
544 /* We assume these are burst units (multiplied by 2, we need it pari) */
545 X1 = video_panning_value_x & 0xfffe;
548 /* We assume these are field line units (divided by 2, we need it pari) */
549 Y1 = video_panning_value_y & 0xfffe;
552 debug("X1=%d, X2=%d, Y1=%d, Y2=%d, DX=%d, DY=%d VIDEO_COLS=%d \n",
553 X1, X2, Y1, Y2, DX, DY, VIDEO_COLS);
555 #ifdef VIDEO_MODE_NTSC
557 * Hx Vx Fx Bx VDS INT LCYC LP LST
561 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
562 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
563 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
564 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
568 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
569 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
570 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
571 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
573 * Odd field active area (TOP)
576 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
577 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
578 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
579 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
582 * Odd field active area
584 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
585 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
586 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
587 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
590 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
592 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
595 * Odd field active area (BOTTOM)
598 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
599 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
600 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
601 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
606 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
607 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
608 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
609 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
613 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
614 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
615 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
616 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
618 * Even field active area (TOP)
621 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
622 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
623 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
624 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
627 * Even field active area (CENTER)
629 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
630 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
631 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
632 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
635 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
637 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
639 * Even field active area (BOTTOM)
642 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
643 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
644 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
645 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
650 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
651 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
652 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
653 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
656 #ifdef VIDEO_MODE_PAL
658 #if defined(CONFIG_RRVISION)
660 #define HPW 160 /* horizontal pulse width (was 139) */
661 #define VPW 2 /* vertical pulse width */
662 #define HBP 104 /* horizontal back porch (was 112) */
663 #define VBP 19 /* vertical back porch (was 19) */
664 #define VID_R 240 /* number of rows */
666 debug ("[VIDEO CTRL] Starting to add controller entries...");
670 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
671 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
672 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
674 ADDENTRY (0, 0, 0, 3, 1, 0, VPW, 1, 0);
675 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
676 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
678 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
679 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
680 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
684 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
685 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
686 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
687 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
688 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
690 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
691 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
692 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
696 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
697 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
698 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
700 ADDENTRY (0, 0, 0, 3, 1, 0, VPW+1, 1, 0);
701 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
702 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
704 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
705 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
706 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
710 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
711 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
712 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
713 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
714 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
716 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
717 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
718 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
722 #else /* !CONFIG_RRVISION */
725 * Hx Vx Fx Bx VDS INT LCYC LP LST
729 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
730 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
731 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
732 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
737 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0); /* 11? */
738 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
739 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
740 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
743 * field active area (CENTER)
745 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0); /* 265? */
746 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
747 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
748 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
751 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
753 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
755 * field active area (BOTTOM)
758 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0); /* 12? */
759 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
760 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
761 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
764 * field vertical; blanking
766 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
767 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
768 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
769 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
771 * Create the other field (like this, but whit other field selected,
772 * one more cycle loop and a last identifier)
774 video_mode_dupefield (vr, &vr[entry], entry);
775 #endif /* CONFIG_RRVISION */
777 #endif /* VIDEO_MODE_PAL */
779 /* See what FIFO are we using */
780 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
782 /* Set number of lines and burst (only one frame for now) */
784 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
785 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
787 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
788 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
791 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
794 * Wait until changes are applied (not done)
795 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
798 /* Return number of VRAM entries */
802 static void video_encoder_init (void)
807 /* Initialize the I2C */
808 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
809 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
812 /* Reset ADV7176 chip */
813 debug ("[VIDEO ENCODER] Resetting encoder...\n");
814 (*(int *) BCSR4) &= ~(1 << 21);
816 /* Wait for 5 ms inside the reset */
817 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
820 /* Take ADV7176 out of reset */
821 (*(int *) BCSR4) |= 1 << 21;
823 /* Wait for 5 ms after the reset */
825 #endif /* CONFIG_FADS */
827 /* Send configuration */
832 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
834 printf ("Sending %d bytes (@ %08lX) to I2C 0x%X:\n ",
835 sizeof(video_encoder_data),
836 (ulong)video_encoder_data,
838 for (i=0; i<sizeof(video_encoder_data); ++i) {
839 printf(" %02X", video_encoder_data[i]);
845 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
847 sizeof(video_encoder_data))) != 0) {
848 printf ("i2c_send error: rc=%d\n", rc);
851 #endif /* VIDEO_I2C */
855 static void video_ctrl_init (void *memptr)
857 immap_t *immap = (immap_t *) CFG_IMMR;
859 video_fb_address = memptr;
862 debug ("[VIDEO CTRL] Setting background color...\n");
863 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
865 /* Show the background */
866 debug ("[VIDEO CTRL] Forcing background...\n");
867 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
869 /* Turn off video controller */
870 debug ("[VIDEO CTRL] Turning off video controller...\n");
871 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
874 /* Turn on Video Port LED */
875 debug ("[VIDEO CTRL] Turning off video port led...\n");
876 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
878 /* Disable internal clock */
879 debug ("[VIDEO CTRL] Disabling internal clock...\n");
880 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
883 /* Generate and make active a new video mode */
884 debug ("[VIDEO CTRL] Generating video mode...\n");
885 video_mode_generate ();
887 /* Start of frame buffer (even and odd frame, to make it working with */
888 /* any selected active set) */
889 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
890 immap->im_vid.vid_vfaa1 =
891 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
892 immap->im_vid.vid_vfba1 =
893 immap->im_vid.vid_vfba0 =
894 (u32) video_fb_address + VIDEO_LINE_LEN;
896 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
897 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
898 immap->im_vid.vid_vccr = 0x2042;
900 /* Configure port pins */
901 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
902 immap->im_ioport.iop_pdpar = 0x1fff;
903 immap->im_ioport.iop_pddir = 0x0000;
906 /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
907 debug ("[VIDEO CTRL] Turning on video clock...\n");
908 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
910 /* Turn on Video Port LED */
911 debug ("[VIDEO CTRL] Turning on video port led...\n");
912 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
914 #ifdef CONFIG_RRVISION
915 debug ("PC5->Output(1): enable PAL clock");
916 immap->im_ioport.iop_pcpar &= ~(0x0400);
917 immap->im_ioport.iop_pcdir |= 0x0400 ;
918 immap->im_ioport.iop_pcdat |= 0x0400 ;
919 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
920 immap->im_ioport.iop_pdpar,
921 immap->im_ioport.iop_pddir,
922 immap->im_ioport.iop_pddat);
923 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
924 immap->im_ioport.iop_pcpar,
925 immap->im_ioport.iop_pcdir,
926 immap->im_ioport.iop_pcdat);
927 #endif /* CONFIG_RRVISION */
929 /* Blanking the screen. */
930 debug ("[VIDEO CTRL] Blanking the screen...\n");
931 video_fill (VIDEO_BG_COL);
934 * Turns on Aggressive Mode. Normally, turning on the caches
935 * will cause the screen to flicker when the caches try to
936 * fill. This gives the FIFO's for the Video Controller
937 * higher priority and prevents flickering because of
938 * underrun. This may still be an issue when using FLASH,
939 * since accessing data from Flash is so slow.
941 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
942 immap->im_siu_conf.sc_sdcr = 0x40;
944 /* Turn on video controller */
945 debug ("[VIDEO CTRL] Turning on video controller...\n");
946 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
948 /* Show the display */
949 debug ("[VIDEO CTRL] Enabling the video...\n");
950 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
953 /************************************************************************/
954 /* ** CONSOLE FUNCTIONS */
955 /************************************************************************/
957 static void console_scrollup (void)
959 /* Copy up rows ignoring the first one */
960 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
962 /* Clear the last one */
963 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
966 static inline void console_back (void)
970 if (console_col < 0) {
971 console_col = CONSOLE_COLS - 1;
977 video_putchar ( console_col * VIDEO_FONT_WIDTH,
978 console_row * VIDEO_FONT_HEIGHT, ' ');
981 static inline void console_newline (void)
986 /* Check if we need to scroll the terminal */
987 if (console_row >= CONSOLE_ROWS) {
988 /* Scroll everything up */
991 /* Decrement row number */
996 void video_putc (const char c)
1004 case 13: /* Simply ignore this */
1007 case '\n': /* Next line, please */
1011 case 9: /* Tab (8 chars alignment) */
1012 console_col |= 0x0008; /* Next 8 chars boundary */
1013 console_col &= ~0x0007; /* Set this bit to zero */
1015 if (console_col >= CONSOLE_COLS)
1019 case 8: /* Eat last character */
1023 default: /* Add to the console */
1024 video_putchar ( console_col * VIDEO_FONT_WIDTH,
1025 console_row * VIDEO_FONT_HEIGHT, c);
1027 /* Check if we need to go to next row */
1028 if (console_col >= CONSOLE_COLS)
1033 void video_puts (const char *s)
1035 int count = strlen (s);
1045 /************************************************************************/
1046 /* ** CURSOR BLINKING FUNCTIONS */
1047 /************************************************************************/
1051 #define BLINK_TIMER_ID 0
1052 #define BLINK_TIMER_HZ 2
1054 static unsigned char blink_enabled = 0;
1055 static timer_t blink_timer;
1057 static void blink_update (void)
1059 static int blink_row = -1, blink_col = -1, blink_old = 0;
1061 /* Check if we have a new position to invert */
1062 if ((console_row != blink_row) || (console_col != blink_col)) {
1063 /* Check if we need to reverse last character */
1065 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1067 #ifdef CONFIG_VIDEO_LOGO
1070 ) * VIDEO_FONT_HEIGHT);
1073 blink_row = console_row;
1074 blink_col = console_col;
1078 /* Reverse this character */
1079 blink_old = !blink_old;
1080 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1082 #ifdef CONFIG_VIDEO_LOGO
1085 ) * VIDEO_FONT_HEIGHT);
1090 * Handler for blinking cursor
1092 static void blink_handler (void *arg)
1097 timer_ack (&blink_timer);
1100 int blink_set (int blink)
1102 int ret = blink_enabled;
1105 timer_enable (&blink_timer);
1107 timer_disable (&blink_timer);
1109 blink_enabled = blink;
1114 static inline void blink_close (void)
1116 timer_close (&blink_timer);
1119 static inline void blink_init (void)
1121 timer_init (&blink_timer,
1122 BLINK_TIMER_ID, BLINK_TIMER_HZ,
1127 /************************************************************************/
1128 /* ** LOGO PLOTTING FUNCTIONS */
1129 /************************************************************************/
1131 #ifdef CONFIG_VIDEO_LOGO
1132 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1135 int skip = width - image->width, xcount, ycount = image->height;
1137 #ifdef VIDEO_MODE_YUYV
1138 ushort *source = (ushort *) image->data;
1139 ushort *dest = (ushort *) screen + y * width + x;
1142 xcount = image->width;
1144 *dest++ = *source++;
1148 #ifdef VIDEO_MODE_RGB
1150 *source = (unsigned short *) image->data,
1151 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1154 xcount = image->width * 3;
1155 memcpy (dest, source, xcount);
1162 static void *video_logo (void)
1164 u16 *screen = video_fb_address, width = VIDEO_COLS;
1166 # ifndef CONFIG_FADS
1167 DECLARE_GLOBAL_DATA_PTR;
1171 #endif /* VIDEO_INFO */
1173 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1176 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1177 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1179 sprintf (info, "(C) 2002 DENX Software Engineering");
1180 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1183 sprintf (info, " Wolfgang DENK, wd@denx.de");
1184 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1186 #ifndef CONFIG_FADS /* all normal boards */
1187 /* leave one blank line */
1189 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1190 strmhz(temp, gd->cpu_clk),
1192 gd->bd->bi_flashsize >> 20 );
1193 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1195 #else /* FADS :-( */
1196 sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1197 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1200 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1201 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1206 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1210 /************************************************************************/
1211 /* ** VIDEO HIGH-LEVEL FUNCTIONS */
1212 /************************************************************************/
1214 static int video_init (void *videobase)
1216 /* Initialize the encoder */
1217 debug ("[VIDEO] Initializing video encoder...\n");
1218 video_encoder_init ();
1220 /* Initialize the video controller */
1221 debug ("[VIDEO] Initializing video controller at %08x...\n",
1223 video_ctrl_init (videobase);
1225 /* Setting the palette */
1226 video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
1227 video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
1228 video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
1229 video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
1230 video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
1231 video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
1232 video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
1233 video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
1234 video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
1235 video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
1237 #ifndef CFG_WHITE_ON_BLACK
1238 video_setfgcolor (CONSOLE_COLOR_BLACK);
1239 video_setbgcolor (CONSOLE_COLOR_GREY2);
1241 video_setfgcolor (CONSOLE_COLOR_GREY2);
1242 video_setbgcolor (CONSOLE_COLOR_BLACK);
1243 #endif /* CFG_WHITE_ON_BLACK */
1245 #ifdef CONFIG_VIDEO_LOGO
1246 /* Paint the logo and retrieve tv base address */
1247 debug ("[VIDEO] Drawing the logo...\n");
1248 video_console_address = video_logo ();
1250 video_console_address = video_fb_address;
1254 /* Enable the blinking (under construction) */
1256 blink_set (0); /* To Fix! */
1259 /* Initialize the console */
1264 #ifdef VIDEO_MODE_PAL
1265 # define VIDEO_MODE_TMP1 "PAL"
1267 #ifdef VIDEO_MODE_NTSC
1268 # define VIDEO_MODE_TMP1 "NTSC"
1270 #ifdef VIDEO_MODE_YUYV
1271 # define VIDEO_MODE_TMP2 "YCbYCr"
1273 #ifdef VIDEO_MODE_RGB
1274 # define VIDEO_MODE_TMP2 "RGB"
1276 debug ( VIDEO_MODE_TMP1
1277 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1278 VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1279 VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1283 int drv_video_init (void)
1285 DECLARE_GLOBAL_DATA_PTR;
1287 int error, devices = 1;
1291 video_init ((void *)(gd->fb_base)); /* Video initialization */
1293 /* Device initialization */
1295 memset (&videodev, 0, sizeof (videodev));
1297 strcpy (videodev.name, "video");
1298 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
1299 videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
1300 videodev.putc = video_putc; /* 'putc' function */
1301 videodev.puts = video_puts; /* 'puts' function */
1303 error = device_register (&videodev);
1305 return (error == 0) ? devices : error;
1308 /************************************************************************/
1309 /* ** ROM capable initialization part - needed to reserve FB memory */
1310 /************************************************************************/
1313 * This is called early in the system initialization to grab memory
1314 * for the video controller.
1315 * Returns new address for monitor, after reserving video buffer memory
1317 * Note that this is running from ROM, so no write access to global data.
1319 ulong video_setmem (ulong addr)
1321 /* Allocate pages for the frame buffer. */
1324 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1325 VIDEO_SIZE>>10, addr);