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 /************************************************************************/
90 /* ** VIDEO MODE CONSTANTS */
91 /************************************************************************/
93 #ifdef VIDEO_MODE_EXTENDED
94 #define VIDEO_COLS VIDEO_ACTIVE_COLS
95 #define VIDEO_ROWS VIDEO_ACTIVE_ROWS
97 #define VIDEO_COLS VIDEO_VISIBLE_COLS
98 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
101 #define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
102 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Total size of buffer */
103 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) /* Number of ints */
104 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Number of bytes per line */
105 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
107 #ifdef VIDEO_MODE_YUYV
108 #define VIDEO_BG_COL 0x80D880D8 /* Background color in YUYV format */
110 #define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
113 /************************************************************************/
114 /* ** FONT AND LOGO DATA */
115 /************************************************************************/
117 #include <video_font.h> /* Get font data, width and height */
119 #ifdef CONFIG_VIDEO_LOGO
120 #include <video_logo.h> /* Get logo data, width and height */
122 #define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
123 #define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
124 #define VIDEO_LOGO_ADDR &u_boot_logo
127 /************************************************************************/
128 /* ** VIDEO CONTROLLER CONSTANTS */
129 /************************************************************************/
131 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
133 #define VIDEO_VCCR_VON 0 /* Video controller ON */
134 #define VIDEO_VCCR_CSRC 1 /* Clock source */
135 #define VIDEO_VCCR_PDF 13 /* Pixel display format */
136 #define VIDEO_VCCR_IEN 11 /* Interrupt enable */
138 /* VSR - VIDEO STATUS REGISTER */
140 #define VIDEO_VSR_CAS 6 /* Active set */
141 #define VIDEO_VSR_EOF 0 /* End of frame */
143 /* VCMR - VIDEO COMMAND REGISTER */
145 #define VIDEO_VCMR_BD 0 /* Blank display */
146 #define VIDEO_VCMR_ASEL 1 /* Active set selection */
148 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
150 #define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
151 #define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
152 #define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
154 /************************************************************************/
155 /* ** CONSOLE CONSTANTS */
156 /************************************************************************/
158 #ifdef CONFIG_VIDEO_LOGO
159 #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
160 #define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
162 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
165 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
166 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
167 #define CONSOLE_ROW_FIRST (video_console_address)
168 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
169 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
170 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
171 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
174 * Simple color definitions
176 #define CONSOLE_COLOR_BLACK 0
177 #define CONSOLE_COLOR_RED 1
178 #define CONSOLE_COLOR_GREEN 2
179 #define CONSOLE_COLOR_YELLOW 3
180 #define CONSOLE_COLOR_BLUE 4
181 #define CONSOLE_COLOR_MAGENTA 5
182 #define CONSOLE_COLOR_CYAN 6
183 #define CONSOLE_COLOR_GREY 13
184 #define CONSOLE_COLOR_GREY2 14
185 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
187 /************************************************************************/
188 /* ** BITOPS MACROS */
189 /************************************************************************/
191 #define HISHORT(i) ((i >> 16)&0xffff)
192 #define LOSHORT(i) (i & 0xffff)
193 #define HICHAR(s) ((i >> 8)&0xff)
194 #define LOCHAR(s) (i & 0xff)
195 #define HI(c) ((c >> 4)&0xf)
196 #define LO(c) (c & 0xf)
197 #define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
198 #define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
199 #define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
200 #define BITMASK(b) (1 << (b))
201 #define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
202 #define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
204 /************************************************************************/
206 /************************************************************************/
209 unsigned char V, Y1, U, Y2;
212 /* This structure is based on the Video Ram in the MPC823. */
213 typedef struct VRAM {
214 unsigned hx:2, /* Horizontal sync */
215 vx:2, /* Vertical sync */
218 res1:6, /* Reserved */
219 vds:2, /* Video Data Select */
220 inter:1, /* Interrupt */
221 res2:2, /* Reserved */
222 lcyc:11, /* Loop/video cycles */
223 lp:1, /* Loop start/end */
224 lst:1; /* Last entry */
227 /************************************************************************/
229 /************************************************************************/
232 video_panning_range_x = 0, /* Video mode invisible pixels x range */
233 video_panning_range_y = 0, /* Video mode invisible pixels y range */
234 video_panning_value_x = 0, /* Video mode x panning value (absolute) */
235 video_panning_value_y = 0, /* Video mode y panning value (absolute) */
236 video_panning_factor_x = 0, /* Video mode x panning value (-127 +127) */
237 video_panning_factor_y = 0, /* Video mode y panning value (-127 +127) */
238 console_col = 0, /* Cursor col */
239 console_row = 0, /* Cursor row */
240 video_palette[16]; /* Our palette */
242 static const int video_font_draw_table[] =
243 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
246 video_color_fg = 0, /* Current fg color index (0-15) */
247 video_color_bg = 0, /* Current bg color index (0-15) */
248 video_enable = 0; /* Video has been initialized? */
251 *video_fb_address, /* Frame buffer address */
252 *video_console_address; /* Console frame buffer start address */
254 /************************************************************************/
255 /* ** MEMORY FUNCTIONS (32bit) */
256 /************************************************************************/
258 static void memsetl (int *p, int c, int v)
264 static void memcpyl (int *d, int *s, int c)
270 /************************************************************************/
271 /* ** VIDEO DRAWING AND COLOR FUNCTIONS */
272 /************************************************************************/
274 static int video_maprgb (int r, int g, int b)
276 #ifdef VIDEO_MODE_YUYV
277 unsigned int pR, pG, pB;
279 unsigned int *ret = (unsigned int *) &YUYV;
281 /* Transform (0-255) components to (0-100) */
287 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
289 YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
290 YUYV.U = pR - (pG * 3 / 4) - (pB / 4) + 128;
291 YUYV.V = pB - (pR / 4) - (pG * 3 / 4) + 128;
294 #ifdef VIDEO_MODE_RGB
295 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
299 static void video_setpalette (int color, int r, int g, int b)
303 video_palette[color] = video_maprgb (r, g, b);
305 /* Swap values if our panning offset is odd */
306 if (video_panning_value_x & 1)
307 video_palette[color] = SWAPINT (video_palette[color]);
310 static void video_fill (int color)
312 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
315 static void video_setfgcolor (int i)
317 video_color_fg = i & 0xf;
320 static void video_setbgcolor (int i)
322 video_color_bg = i & 0xf;
325 static int video_pickcolor (int i)
327 return video_palette[i & 0xf];
330 /* Absolute console plotting functions */
333 static void video_revchar (int xx, int yy)
338 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
340 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
341 switch (VIDEO_FONT_WIDTH) {
343 ((u32 *) dest)[6] ^= 0xffffffff;
344 ((u32 *) dest)[7] ^= 0xffffffff;
347 ((u32 *) dest)[4] ^= 0xffffffff;
348 ((u32 *) dest)[5] ^= 0xffffffff;
351 ((u32 *) dest)[2] ^= 0xffffffff;
352 ((u32 *) dest)[3] ^= 0xffffffff;
355 ((u32 *) dest)[0] ^= 0xffffffff;
356 ((u32 *) dest)[1] ^= 0xffffffff;
362 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
364 u8 *cdat, *dest, *dest0;
368 offset = yy * VIDEO_LINE_LEN + xx * 2;
369 dest0 = video_fb_address + offset;
371 fgx = video_pickcolor (video_color_fg);
372 bgx = video_pickcolor (video_color_bg);
381 switch (VIDEO_FONT_WIDTH) {
386 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
387 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
389 dest += VIDEO_LINE_LEN) {
393 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
395 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
396 if (VIDEO_FONT_WIDTH == 8) {
398 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
400 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
403 dest0 += VIDEO_FONT_WIDTH * 2;
410 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
411 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
412 dest += VIDEO_LINE_LEN) {
416 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
418 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
420 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
422 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
425 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
427 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
428 if (VIDEO_FONT_WIDTH == 16) {
430 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
432 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
436 dest0 += VIDEO_FONT_WIDTH * 2;
442 static inline void video_drawstring (int xx, int yy, unsigned char *s)
444 video_drawchars (xx, yy, s, strlen (s));
447 /* Relative to console plotting functions */
449 static void video_putchars (int xx, int yy, unsigned char *s, int count)
451 #ifdef CONFIG_VIDEO_LOGO
452 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
454 video_drawchars (xx, yy, s, count);
458 static void video_putchar (int xx, int yy, unsigned char c)
460 #ifdef CONFIG_VIDEO_LOGO
461 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
463 video_drawchars (xx, yy, &c, 1);
467 static inline void video_putstring (int xx, int yy, unsigned char *s)
469 video_putchars (xx, yy, s, strlen (s));
472 /************************************************************************/
473 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
474 /************************************************************************/
476 static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
480 for (i = 0; i < entries; i++) {
481 dest[i] = source[i]; /* Copy the entire record */
482 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
485 dest[0].lcyc++; /* Add a cycle to the first entry */
486 dest[entries - 1].lst = 1; /* Set end of ram entries */
489 static void inline video_mode_addentry (VRAM * vr,
490 int Hx, int Vx, int Fx, int Bx,
491 int VDS, int INT, int LCYC, int LP, int LST)
504 #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)
506 static int video_mode_generate (void)
508 immap_t *immap = (immap_t *) CFG_IMMR;
509 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
510 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
512 /* CHECKING PARAMETERS */
514 if (video_panning_factor_y < -128)
515 video_panning_factor_y = -128;
517 if (video_panning_factor_y > 128)
518 video_panning_factor_y = 128;
520 if (video_panning_factor_x < -128)
521 video_panning_factor_x = -128;
523 if (video_panning_factor_x > 128)
524 video_panning_factor_x = 128;
526 /* Setting panning */
528 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
529 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
531 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
532 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
534 /* We assume these are burst units (multiplied by 2, we need it pari) */
535 X1 = video_panning_value_x & 0xfffe;
538 /* We assume these are field line units (divided by 2, we need it pari) */
539 Y1 = video_panning_value_y & 0xfffe;
542 #ifdef VIDEO_MODE_NTSC
544 * Hx Vx Fx Bx VDS INT LCYC LP LST
548 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
549 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
550 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
551 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
555 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
556 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
557 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
558 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
560 * Odd field active area (TOP)
563 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
564 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
565 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
566 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
569 * Odd field active area
571 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
572 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
573 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
574 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
577 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
579 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
582 * Odd field active area (BOTTOM)
585 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
586 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
587 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
588 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
593 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
594 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
595 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
596 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
600 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
601 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
602 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
603 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
605 * Even field active area (TOP)
608 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
609 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
610 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
611 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
614 * Even field active area (CENTER)
616 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
617 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
618 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
619 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
622 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
624 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
626 * Even field active area (BOTTOM)
629 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
630 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
631 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
632 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
637 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
638 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
639 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
640 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
643 #ifdef VIDEO_MODE_PAL
645 * Hx Vx Fx Bx VDS INT LCYC LP LST
649 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
650 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
651 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
652 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
657 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0); /* 11? */
658 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
659 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
660 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
663 * field active area (CENTER)
665 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0); /* 265? */
666 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
667 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
668 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
671 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
673 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
675 * field active area (BOTTOM)
678 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0); /* 12? */
679 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
680 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
681 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
684 * field vertical; blanking
686 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
687 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
688 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
689 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
691 * Create the other field (like this, but whit other field selected,
692 * one more cycle loop and a last identifier)
694 video_mode_dupefield (vr, &vr[entry], entry);
697 /* See what FIFO are we using */
698 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
700 /* Set number of lines and burst (only one frame for now) */
702 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
703 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
705 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
706 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
709 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
712 * Wait until changes are applied (not done)
713 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
716 /* Return number of VRAM entries */
720 static void video_encoder_init (void)
725 /* Initialize the I2C */
726 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
727 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
730 /* Reset ADV7176 chip */
731 debug ("[VIDEO ENCODER] Resetting encoder...\n");
732 (*(int *) BCSR4) &= ~(1 << 21);
734 /* Wait for 5 ms inside the reset */
735 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
738 /* Take ADV7176 out of reset */
739 (*(int *) BCSR4) |= 1 << 21;
741 /* Wait for 5 ms after the reset */
743 #endif /* CONFIG_FADS */
745 /* Send configuration */
750 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
752 printf ("Sending %d bytes (@ %08lX) to I2C 0x%X:\n ",
753 sizeof(video_encoder_data),
754 (ulong)video_encoder_data,
756 for (i=0; i<sizeof(video_encoder_data); ++i) {
757 printf(" %02X", video_encoder_data[i]);
763 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
765 sizeof(video_encoder_data))) != 0) {
766 printf ("i2c_send error: rc=%d\n", rc);
769 #endif /* VIDEO_I2C */
773 static void video_ctrl_init (void *memptr)
775 immap_t *immap = (immap_t *) CFG_IMMR;
777 video_fb_address = memptr;
780 debug ("[VIDEO CTRL] Setting background color...\n");
781 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
783 /* Show the background */
784 debug ("[VIDEO CTRL] Forcing background...\n");
785 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
787 /* Turn off video controller */
788 debug ("[VIDEO CTRL] Turning off video controller...\n");
789 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
792 /* Turn on Video Port LED */
793 debug ("[VIDEO CTRL] Turning off video port led...\n");
794 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
796 /* Disable internal clock */
797 debug ("[VIDEO CTRL] Disabling internal clock...\n");
798 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
801 /* Generate and make active a new video mode */
802 debug ("[VIDEO CTRL] Generating video mode...\n");
803 video_mode_generate ();
805 /* Start of frame buffer (even and odd frame, to make it working with */
806 /* any selected active set) */
807 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
808 immap->im_vid.vid_vfaa1 =
809 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
810 immap->im_vid.vid_vfba1 =
811 immap->im_vid.vid_vfba0 =
812 (u32) video_fb_address + VIDEO_LINE_LEN;
814 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
815 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
816 immap->im_vid.vid_vccr = 0x2042;
818 /* Configure port pins */
819 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
820 immap->im_ioport.iop_pdpar = 0x1fff;
821 immap->im_ioport.iop_pddir = 0x0000;
824 /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
825 debug ("[VIDEO CTRL] Turning on video clock...\n");
826 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
828 /* Turn on Video Port LED */
829 debug ("[VIDEO CTRL] Turning on video port led...\n");
830 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
833 #ifdef CONFIG_RRVISION
834 /* enable clock: set PD3 to VCLK, PC5 to HIGH */
836 volatile immap_t *immr = (immap_t *) CFG_IMMR;
838 debug ("[RRvision] PD3 -> clk output: ");
839 immr->im_ioport.iop_pdpar |= 0x1000 ;
840 #if 0 /* This is supposed to be an output XXX XXX */
841 immr->im_ioport.iop_pddir |= 0x1000 ;
843 immr->im_ioport.iop_pddir &= ~(0x1000);
846 debug ("PDPAR=%04X PDDIR=%04X PDDAT=%04X\n",
847 immr->im_ioport.iop_pdpar,
848 immr->im_ioport.iop_pddir,
849 immr->im_ioport.iop_pddat);
851 debug ("[RRvision] PC5 -> Output (1): ");
852 immr->im_ioport.iop_pcpar &= ~(0x0400);
853 immr->im_ioport.iop_pcdir |= 0x0400 ;
854 immr->im_ioport.iop_pcdat |= 0x0400 ;
855 debug ("PCPAR=%04X PCDIR=%04X PCDAT=%04X\n",
856 immr->im_ioport.iop_pcpar,
857 immr->im_ioport.iop_pcdir,
858 immr->im_ioport.iop_pcdat);
860 #endif /* CONFIG_RRVISION */
862 /* Blanking the screen. */
863 debug ("[VIDEO CTRL] Blanking the screen...\n");
864 video_fill (VIDEO_BG_COL);
867 * Turns on Aggressive Mode. Normally, turning on the caches
868 * will cause the screen to flicker when the caches try to
869 * fill. This gives the FIFO's for the Video Controller
870 * higher priority and prevents flickering because of
871 * underrun. This may still be an issue when using FLASH,
872 * since accessing data from Flash is so slow.
874 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
875 immap->im_siu_conf.sc_sdcr = 0x40;
877 /* Turn on video controller */
878 debug ("[VIDEO CTRL] Turning on video controller...\n");
879 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
881 /* Show the display */
882 debug ("[VIDEO CTRL] Enabling the video...\n");
883 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
886 /************************************************************************/
887 /* ** CONSOLE FUNCTIONS */
888 /************************************************************************/
890 static void console_scrollup (void)
892 /* Copy up rows ignoring the first one */
893 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
895 /* Clear the last one */
896 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
899 static inline void console_back (void)
903 if (console_col < 0) {
904 console_col = CONSOLE_COLS - 1;
910 video_putchar ( console_col * VIDEO_FONT_WIDTH,
911 console_row * VIDEO_FONT_HEIGHT, ' ');
914 static inline void console_newline (void)
919 /* Check if we need to scroll the terminal */
920 if (console_row >= CONSOLE_ROWS) {
921 /* Scroll everything up */
924 /* Decrement row number */
929 void video_putc (const char c)
937 case 13: /* Simply ignore this */
940 case '\n': /* Next line, please */
944 case 9: /* Tab (8 chars alignment) */
945 console_col |= 0x0008; /* Next 8 chars boundary */
946 console_col &= ~0x0007; /* Set this bit to zero */
948 if (console_col >= CONSOLE_COLS)
952 case 8: /* Eat last character */
956 default: /* Add to the console */
957 video_putchar ( console_col * VIDEO_FONT_WIDTH,
958 console_row * VIDEO_FONT_HEIGHT, c);
960 /* Check if we need to go to next row */
961 if (console_col >= CONSOLE_COLS)
966 void video_puts (const char *s)
968 int count = strlen (s);
978 /************************************************************************/
979 /* ** CURSOR BLINKING FUNCTIONS */
980 /************************************************************************/
984 #define BLINK_TIMER_ID 0
985 #define BLINK_TIMER_HZ 2
987 static unsigned char blink_enabled = 0;
988 static timer_t blink_timer;
990 static void blink_update (void)
992 static int blink_row = -1, blink_col = -1, blink_old = 0;
994 /* Check if we have a new position to invert */
995 if ((console_row != blink_row) || (console_col != blink_col)) {
996 /* Check if we need to reverse last character */
998 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1000 #ifdef CONFIG_VIDEO_LOGO
1003 ) * VIDEO_FONT_HEIGHT);
1006 blink_row = console_row;
1007 blink_col = console_col;
1011 /* Reverse this character */
1012 blink_old = !blink_old;
1013 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1015 #ifdef CONFIG_VIDEO_LOGO
1018 ) * VIDEO_FONT_HEIGHT);
1023 * Handler for blinking cursor
1025 static void blink_handler (void *arg)
1030 timer_ack (&blink_timer);
1033 int blink_set (int blink)
1035 int ret = blink_enabled;
1038 timer_enable (&blink_timer);
1040 timer_disable (&blink_timer);
1042 blink_enabled = blink;
1047 static inline void blink_close (void)
1049 timer_close (&blink_timer);
1052 static inline void blink_init (void)
1054 timer_init (&blink_timer,
1055 BLINK_TIMER_ID, BLINK_TIMER_HZ,
1060 /************************************************************************/
1061 /* ** LOGO PLOTTING FUNCTIONS */
1062 /************************************************************************/
1064 #ifdef CONFIG_VIDEO_LOGO
1065 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1068 int skip = width - image->width, xcount, ycount = image->height;
1070 #ifdef VIDEO_MODE_YUYV
1071 ushort *source = (ushort *) image->data;
1072 ushort *dest = (ushort *) screen + y * width + x;
1075 xcount = image->width;
1077 *dest++ = *source++;
1081 #ifdef VIDEO_MODE_RGB
1083 *source = (unsigned short *) image->data,
1084 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1087 xcount = image->width * 3;
1088 memcpy (dest, source, xcount);
1095 static void *video_logo (void)
1097 u16 *screen = video_fb_address, width = VIDEO_COLS;
1099 # ifndef CONFIG_FADS
1100 DECLARE_GLOBAL_DATA_PTR;
1104 #endif /* VIDEO_INFO */
1106 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1109 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1110 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1112 sprintf (info, "(C) 2002 DENX Software Engineering");
1113 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1116 sprintf (info, " Wolfgang DENK, wd@denx.de");
1117 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1119 #ifndef CONFIG_FADS /* all normal boards */
1120 /* leave one blank line */
1122 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1123 strmhz(temp, gd->cpu_clk),
1125 gd->bd->bi_flashsize >> 20 );
1126 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1128 #else /* FADS :-( */
1129 sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1130 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1133 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1134 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1139 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1143 /************************************************************************/
1144 /* ** VIDEO HIGH-LEVEL FUNCTIONS */
1145 /************************************************************************/
1147 static int video_init (void *videobase)
1149 /* Initialize the encoder */
1150 debug ("[VIDEO] Initializing video encoder...\n");
1151 video_encoder_init ();
1153 /* Initialize the video controller */
1154 debug ("[VIDEO] Initializing video controller at %08x...\n",
1156 video_ctrl_init (videobase);
1158 /* Setting the palette */
1159 video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
1160 video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
1161 video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
1162 video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
1163 video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
1164 video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
1165 video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
1166 video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
1167 video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
1168 video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
1170 #ifndef CFG_WHITE_ON_BLACK
1171 video_setfgcolor (CONSOLE_COLOR_BLACK);
1172 video_setbgcolor (CONSOLE_COLOR_GREY2);
1174 video_setfgcolor (CONSOLE_COLOR_GREY2);
1175 video_setbgcolor (CONSOLE_COLOR_BLACK);
1176 #endif /* CFG_WHITE_ON_BLACK */
1178 #ifdef CONFIG_VIDEO_LOGO
1179 /* Paint the logo and retrieve tv base address */
1180 debug ("[VIDEO] Drawing the logo...\n");
1181 video_console_address = video_logo ();
1183 video_console_address = video_fb_address;
1187 /* Enable the blinking (under construction) */
1189 blink_set (0); /* To Fix! */
1192 /* Initialize the console */
1197 #ifdef VIDEO_MODE_PAL
1198 # define VIDEO_MODE_TMP1 "PAL"
1200 #ifdef VIDEO_MODE_NTSC
1201 # define VIDEO_MODE_TMP1 "NTSC"
1203 #ifdef VIDEO_MODE_YUYV
1204 # define VIDEO_MODE_TMP2 "YCbYCr"
1206 #ifdef VIDEO_MODE_RGB
1207 # define VIDEO_MODE_TMP2 "RGB"
1209 debug ( VIDEO_MODE_TMP1
1210 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1211 VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1212 VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1216 int drv_video_init (void)
1218 DECLARE_GLOBAL_DATA_PTR;
1220 int error, devices = 1;
1224 video_init ((void *)(gd->fb_base)); /* Video initialization */
1226 /* Device initialization */
1228 memset (&videodev, 0, sizeof (videodev));
1230 strcpy (videodev.name, "video");
1231 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
1232 videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
1233 videodev.putc = video_putc; /* 'putc' function */
1234 videodev.puts = video_puts; /* 'puts' function */
1236 error = device_register (&videodev);
1238 return (error == 0) ? devices : error;
1241 /************************************************************************/
1242 /* ** ROM capable initialization part - needed to reserve FB memory */
1243 /************************************************************************/
1246 * This is called early in the system initialization to grab memory
1247 * for the video controller.
1248 * Returns new address for monitor, after reserving video buffer memory
1250 * Note that this is running from ROM, so no write access to global data.
1252 ulong video_setmem (ulong addr)
1254 /* Allocate pages for the frame buffer. */
1257 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1258 VIDEO_SIZE>>10, addr);