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 DECLARE_GLOBAL_DATA_PTR;
44 /************************************************************************/
45 /* ** DEBUG SETTINGS */
46 /************************************************************************/
49 #define VIDEO_DEBUG_COLORBARS /* Force colorbars output */
52 /************************************************************************/
53 /* ** VIDEO MODE SETTINGS */
54 /************************************************************************/
57 #define VIDEO_MODE_EXTENDED /* Allow screen size bigger than visible area */
58 #define VIDEO_MODE_NTSC
61 #define VIDEO_MODE_PAL
64 #define VIDEO_BLINK /* This enables cursor blinking (under construction) */
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 */
80 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
83 #ifdef CONFIG_VIDEO_ENCODER_AD7177
85 #include <video_ad7177.h> /* Sets encoder data, mode, and visible and active area */
88 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
91 #ifdef CONFIG_VIDEO_ENCODER_AD7179
93 #include <video_ad7179.h> /* Sets encoder data, mode, and visible and active area */
96 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
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
107 #define VIDEO_COLS VIDEO_VISIBLE_COLS
108 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
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 */
120 #define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
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
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)
172 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
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 /************************************************************************/
216 /************************************************************************/
219 unsigned char V, Y1, U, Y2;
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 */
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 */
237 /************************************************************************/
239 /************************************************************************/
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 };
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? */
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)
274 static void memcpyl (int *d, int *s, int c)
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;
289 unsigned int *ret = (unsigned int *) &YUYV;
291 /* Transform (0-255) components to (0-100) */
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;
304 #ifdef VIDEO_MODE_RGB
305 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
309 static void video_setpalette (int color, int r, int g, int b)
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 */
343 static void video_revchar (int xx, int yy)
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) {
353 ((u32 *) dest)[6] ^= 0xffffffff;
354 ((u32 *) dest)[7] ^= 0xffffffff;
357 ((u32 *) dest)[4] ^= 0xffffffff;
358 ((u32 *) dest)[5] ^= 0xffffffff;
361 ((u32 *) dest)[2] ^= 0xffffffff;
362 ((u32 *) dest)[3] ^= 0xffffffff;
365 ((u32 *) dest)[0] ^= 0xffffffff;
366 ((u32 *) dest)[1] ^= 0xffffffff;
372 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
374 u8 *cdat, *dest, *dest0;
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);
391 switch (VIDEO_FONT_WIDTH) {
396 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
397 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
399 dest += VIDEO_LINE_LEN) {
403 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
405 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
406 if (VIDEO_FONT_WIDTH == 8) {
408 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
410 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
413 dest0 += VIDEO_FONT_WIDTH * 2;
420 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
421 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
422 dest += VIDEO_LINE_LEN) {
426 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
428 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
430 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
432 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
435 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
437 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
438 if (VIDEO_FONT_WIDTH == 16) {
440 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
442 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
446 dest0 += VIDEO_FONT_WIDTH * 2;
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);
464 video_drawchars (xx, yy, s, count);
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);
473 video_drawchars (xx, yy, &c, 1);
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)
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 */
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)
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;
550 /* We assume these are field line units (divided by 2, we need it pari) */
551 Y1 = video_panning_value_y & 0xfffe;
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
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);
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)
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);
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)
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);
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);
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)
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);
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)
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);
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);
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...");
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);
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);
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);
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);
724 #else /* !CONFIG_RRVISION */
727 * Hx Vx Fx Bx VDS INT LCYC LP LST
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);
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);
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)
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) */
786 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
787 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
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 */
804 static void video_encoder_init (void)
809 /* Initialize the I2C */
810 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
811 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
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");
822 /* Take ADV7176 out of reset */
823 (*(int *) BCSR4) |= 1 << 21;
825 /* Wait for 5 ms after the reset */
827 #endif /* CONFIG_FADS */
829 /* Send configuration */
834 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
836 printf ("Sending %zu bytes (@ %08lX) to I2C 0x%lX:\n ",
837 sizeof(video_encoder_data),
838 (ulong)video_encoder_data,
839 (ulong)VIDEO_I2C_ADDR);
840 for (i=0; i<sizeof(video_encoder_data); ++i) {
841 printf(" %02X", video_encoder_data[i]);
847 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
849 sizeof(video_encoder_data))) != 0) {
850 printf ("i2c_send error: rc=%d\n", rc);
853 #endif /* VIDEO_I2C */
857 static void video_ctrl_init (void *memptr)
859 immap_t *immap = (immap_t *) CFG_IMMR;
861 video_fb_address = memptr;
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);
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);
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;
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);
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)
972 if (console_col < 0) {
973 console_col = CONSOLE_COLS - 1;
979 video_putchar ( console_col * VIDEO_FONT_WIDTH,
980 console_row * VIDEO_FONT_HEIGHT, ' ');
983 static inline void console_newline (void)
988 /* Check if we need to scroll the terminal */
989 if (console_row >= CONSOLE_ROWS) {
990 /* Scroll everything up */
993 /* Decrement row number */
998 void video_putc (const char c)
1000 if (!video_enable) {
1006 case 13: /* Simply ignore this */
1009 case '\n': /* Next line, please */
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)
1021 case 8: /* Eat last character */
1025 default: /* Add to the console */
1026 video_putchar ( console_col * VIDEO_FONT_WIDTH,
1027 console_row * VIDEO_FONT_HEIGHT, c);
1029 /* Check if we need to go to next row */
1030 if (console_col >= CONSOLE_COLS)
1035 void video_puts (const char *s)
1037 int count = strlen (s);
1047 /************************************************************************/
1048 /* ** CURSOR BLINKING FUNCTIONS */
1049 /************************************************************************/
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 */
1067 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1069 #ifdef CONFIG_VIDEO_LOGO
1072 ) * VIDEO_FONT_HEIGHT);
1075 blink_row = console_row;
1076 blink_col = console_col;
1080 /* Reverse this character */
1081 blink_old = !blink_old;
1082 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1084 #ifdef CONFIG_VIDEO_LOGO
1087 ) * VIDEO_FONT_HEIGHT);
1092 * Handler for blinking cursor
1094 static void blink_handler (void *arg)
1099 timer_ack (&blink_timer);
1102 int blink_set (int blink)
1104 int ret = blink_enabled;
1107 timer_enable (&blink_timer);
1109 timer_disable (&blink_timer);
1111 blink_enabled = blink;
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,
1129 /************************************************************************/
1130 /* ** LOGO PLOTTING FUNCTIONS */
1131 /************************************************************************/
1133 #ifdef CONFIG_VIDEO_LOGO
1134 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
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;
1144 xcount = image->width;
1146 *dest++ = *source++;
1150 #ifdef VIDEO_MODE_RGB
1152 *source = (unsigned short *) image->data,
1153 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1156 xcount = image->width * 3;
1157 memcpy (dest, source, xcount);
1164 static void *video_logo (void)
1166 u16 *screen = video_fb_address, width = VIDEO_COLS;
1168 # ifndef CONFIG_FADS
1172 #endif /* VIDEO_INFO */
1174 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
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,
1184 sprintf (info, " Wolfgang DENK, wd@denx.de");
1185 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
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),
1193 gd->bd->bi_flashsize >> 20 );
1194 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
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,
1201 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1202 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1207 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
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",
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);
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 ();
1251 video_console_address = video_fb_address;
1255 /* Enable the blinking (under construction) */
1257 blink_set (0); /* To Fix! */
1260 /* Initialize the console */
1265 #ifdef VIDEO_MODE_PAL
1266 # define VIDEO_MODE_TMP1 "PAL"
1268 #ifdef VIDEO_MODE_NTSC
1269 # define VIDEO_MODE_TMP1 "NTSC"
1271 #ifdef VIDEO_MODE_YUYV
1272 # define VIDEO_MODE_TMP2 "YCbYCr"
1274 #ifdef VIDEO_MODE_RGB
1275 # define VIDEO_MODE_TMP2 "RGB"
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);
1284 int drv_video_init (void)
1286 int error, devices = 1;
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. */
1323 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1324 VIDEO_SIZE>>10, addr);