3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
5 * Wolfgang Denk, wd@denx.de
7 * SPDX-License-Identifier: GPL-2.0+
12 /************************************************************************/
14 /************************************************************************/
21 #include <linux/types.h>
22 #include <stdio_dev.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 /************************************************************************/
29 /* ** DEBUG SETTINGS */
30 /************************************************************************/
33 #define VIDEO_DEBUG_COLORBARS /* Force colorbars output */
36 /************************************************************************/
37 /* ** VIDEO MODE SETTINGS */
38 /************************************************************************/
41 #define VIDEO_MODE_EXTENDED /* Allow screen size bigger than visible area */
42 #define VIDEO_MODE_NTSC
45 #define VIDEO_MODE_PAL
48 #define VIDEO_BLINK /* This enables cursor blinking (under construction) */
51 #define VIDEO_INFO /* Show U-Boot information */
52 #define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
53 #define VIDEO_INFO_Y 16
55 /************************************************************************/
56 /* ** VIDEO ENCODER CONSTANTS */
57 /************************************************************************/
59 #ifdef CONFIG_VIDEO_ENCODER_AD7176
61 #include <video_ad7176.h> /* Sets encoder data, mode, and visible and active area */
64 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
67 #ifdef CONFIG_VIDEO_ENCODER_AD7177
69 #include <video_ad7177.h> /* Sets encoder data, mode, and visible and active area */
72 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
75 #ifdef CONFIG_VIDEO_ENCODER_AD7179
77 #include <video_ad7179.h> /* Sets encoder data, mode, and visible and active area */
80 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
83 /************************************************************************/
84 /* ** VIDEO MODE CONSTANTS */
85 /************************************************************************/
87 #ifdef VIDEO_MODE_EXTENDED
88 #define VIDEO_COLS VIDEO_ACTIVE_COLS
89 #define VIDEO_ROWS VIDEO_ACTIVE_ROWS
91 #define VIDEO_COLS VIDEO_VISIBLE_COLS
92 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
95 #define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
96 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Total size of buffer */
97 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) /* Number of ints */
98 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Number of bytes per line */
99 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
101 #ifdef VIDEO_MODE_YUYV
102 #define VIDEO_BG_COL 0x80D880D8 /* Background color in YUYV format */
104 #define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
107 /************************************************************************/
108 /* ** FONT AND LOGO DATA */
109 /************************************************************************/
111 #include <video_font.h> /* Get font data, width and height */
113 #ifdef CONFIG_VIDEO_LOGO
114 #include <video_logo.h> /* Get logo data, width and height */
116 #define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
117 #define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
118 #define VIDEO_LOGO_ADDR &u_boot_logo
121 /************************************************************************/
122 /* ** VIDEO CONTROLLER CONSTANTS */
123 /************************************************************************/
125 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
127 #define VIDEO_VCCR_VON 0 /* Video controller ON */
128 #define VIDEO_VCCR_CSRC 1 /* Clock source */
129 #define VIDEO_VCCR_PDF 13 /* Pixel display format */
130 #define VIDEO_VCCR_IEN 11 /* Interrupt enable */
132 /* VSR - VIDEO STATUS REGISTER */
134 #define VIDEO_VSR_CAS 6 /* Active set */
135 #define VIDEO_VSR_EOF 0 /* End of frame */
137 /* VCMR - VIDEO COMMAND REGISTER */
139 #define VIDEO_VCMR_BD 0 /* Blank display */
140 #define VIDEO_VCMR_ASEL 1 /* Active set selection */
142 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
144 #define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
145 #define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
146 #define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
148 /************************************************************************/
149 /* ** CONSOLE CONSTANTS */
150 /************************************************************************/
152 #ifdef CONFIG_VIDEO_LOGO
153 #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
154 #define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
156 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
159 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
160 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
161 #define CONSOLE_ROW_FIRST (video_console_address)
162 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
163 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
164 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
165 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
168 * Simple color definitions
170 #define CONSOLE_COLOR_BLACK 0
171 #define CONSOLE_COLOR_RED 1
172 #define CONSOLE_COLOR_GREEN 2
173 #define CONSOLE_COLOR_YELLOW 3
174 #define CONSOLE_COLOR_BLUE 4
175 #define CONSOLE_COLOR_MAGENTA 5
176 #define CONSOLE_COLOR_CYAN 6
177 #define CONSOLE_COLOR_GREY 13
178 #define CONSOLE_COLOR_GREY2 14
179 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
181 /************************************************************************/
182 /* ** BITOPS MACROS */
183 /************************************************************************/
185 #define HISHORT(i) ((i >> 16)&0xffff)
186 #define LOSHORT(i) (i & 0xffff)
187 #define HICHAR(s) ((i >> 8)&0xff)
188 #define LOCHAR(s) (i & 0xff)
189 #define HI(c) ((c >> 4)&0xf)
190 #define LO(c) (c & 0xf)
191 #define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
192 #define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
193 #define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
194 #define BITMASK(b) (1 << (b))
195 #define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
196 #define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
198 /************************************************************************/
200 /************************************************************************/
203 unsigned char V, Y1, U, Y2;
206 /* This structure is based on the Video Ram in the MPC823. */
207 typedef struct VRAM {
208 unsigned hx:2, /* Horizontal sync */
209 vx:2, /* Vertical sync */
212 res1:6, /* Reserved */
213 vds:2, /* Video Data Select */
214 inter:1, /* Interrupt */
215 res2:2, /* Reserved */
216 lcyc:11, /* Loop/video cycles */
217 lp:1, /* Loop start/end */
218 lst:1; /* Last entry */
221 /************************************************************************/
223 /************************************************************************/
226 video_panning_range_x = 0, /* Video mode invisible pixels x range */
227 video_panning_range_y = 0, /* Video mode invisible pixels y range */
228 video_panning_value_x = 0, /* Video mode x panning value (absolute) */
229 video_panning_value_y = 0, /* Video mode y panning value (absolute) */
230 video_panning_factor_x = 0, /* Video mode x panning value (-127 +127) */
231 video_panning_factor_y = 0, /* Video mode y panning value (-127 +127) */
232 console_col = 0, /* Cursor col */
233 console_row = 0, /* Cursor row */
234 video_palette[16]; /* Our palette */
236 static const int video_font_draw_table[] =
237 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
240 video_color_fg = 0, /* Current fg color index (0-15) */
241 video_color_bg = 0, /* Current bg color index (0-15) */
242 video_enable = 0; /* Video has been initialized? */
245 *video_fb_address, /* Frame buffer address */
246 *video_console_address; /* Console frame buffer start address */
248 /************************************************************************/
249 /* ** MEMORY FUNCTIONS (32bit) */
250 /************************************************************************/
252 static void memsetl (int *p, int c, int v)
258 static void memcpyl (int *d, int *s, int c)
264 /************************************************************************/
265 /* ** VIDEO DRAWING AND COLOR FUNCTIONS */
266 /************************************************************************/
268 static int video_maprgb (int r, int g, int b)
270 #ifdef VIDEO_MODE_YUYV
271 unsigned int pR, pG, pB;
273 unsigned int *ret = (unsigned int *) &YUYV;
275 /* Transform (0-255) components to (0-100) */
281 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
283 YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
284 YUYV.U = pR - (pG * 3 / 4) - (pB / 4) + 128;
285 YUYV.V = pB - (pR / 4) - (pG * 3 / 4) + 128;
288 #ifdef VIDEO_MODE_RGB
289 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
293 static void video_setpalette (int color, int r, int g, int b)
297 video_palette[color] = video_maprgb (r, g, b);
299 /* Swap values if our panning offset is odd */
300 if (video_panning_value_x & 1)
301 video_palette[color] = SWAPINT (video_palette[color]);
304 static void video_fill (int color)
306 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
309 static void video_setfgcolor (int i)
311 video_color_fg = i & 0xf;
314 static void video_setbgcolor (int i)
316 video_color_bg = i & 0xf;
319 static int video_pickcolor (int i)
321 return video_palette[i & 0xf];
324 /* Absolute console plotting functions */
327 static void video_revchar (int xx, int yy)
332 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
334 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
335 switch (VIDEO_FONT_WIDTH) {
337 ((u32 *) dest)[6] ^= 0xffffffff;
338 ((u32 *) dest)[7] ^= 0xffffffff;
341 ((u32 *) dest)[4] ^= 0xffffffff;
342 ((u32 *) dest)[5] ^= 0xffffffff;
345 ((u32 *) dest)[2] ^= 0xffffffff;
346 ((u32 *) dest)[3] ^= 0xffffffff;
349 ((u32 *) dest)[0] ^= 0xffffffff;
350 ((u32 *) dest)[1] ^= 0xffffffff;
356 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
358 u8 *cdat, *dest, *dest0;
362 offset = yy * VIDEO_LINE_LEN + xx * 2;
363 dest0 = video_fb_address + offset;
365 fgx = video_pickcolor (video_color_fg);
366 bgx = video_pickcolor (video_color_bg);
375 switch (VIDEO_FONT_WIDTH) {
380 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
381 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
383 dest += VIDEO_LINE_LEN) {
387 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
389 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
390 if (VIDEO_FONT_WIDTH == 8) {
392 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
394 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
397 dest0 += VIDEO_FONT_WIDTH * 2;
404 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
405 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
406 dest += VIDEO_LINE_LEN) {
410 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
412 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
414 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
416 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
419 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
421 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
422 if (VIDEO_FONT_WIDTH == 16) {
424 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
426 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
430 dest0 += VIDEO_FONT_WIDTH * 2;
436 static inline void video_drawstring (int xx, int yy, char *s)
438 video_drawchars (xx, yy, (unsigned char *)s, strlen (s));
441 /* Relative to console plotting functions */
443 static void video_putchars (int xx, int yy, unsigned char *s, int count)
445 #ifdef CONFIG_VIDEO_LOGO
446 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
448 video_drawchars (xx, yy, s, count);
452 static void video_putchar (int xx, int yy, unsigned char c)
454 #ifdef CONFIG_VIDEO_LOGO
455 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
457 video_drawchars (xx, yy, &c, 1);
461 static inline void video_putstring (int xx, int yy, unsigned char *s)
463 video_putchars (xx, yy, (unsigned char *)s, strlen ((char *)s));
466 /************************************************************************/
467 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
468 /************************************************************************/
470 #if !defined(CONFIG_RRVISION)
471 static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
475 for (i = 0; i < entries; i++) {
476 dest[i] = source[i]; /* Copy the entire record */
477 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
480 dest[0].lcyc++; /* Add a cycle to the first entry */
481 dest[entries - 1].lst = 1; /* Set end of ram entries */
485 static void inline video_mode_addentry (VRAM * vr,
486 int Hx, int Vx, int Fx, int Bx,
487 int VDS, int INT, int LCYC, int LP, int LST)
500 #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)
502 static int video_mode_generate (void)
504 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
505 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
506 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
508 /* CHECKING PARAMETERS */
510 if (video_panning_factor_y < -128)
511 video_panning_factor_y = -128;
513 if (video_panning_factor_y > 128)
514 video_panning_factor_y = 128;
516 if (video_panning_factor_x < -128)
517 video_panning_factor_x = -128;
519 if (video_panning_factor_x > 128)
520 video_panning_factor_x = 128;
522 /* Setting panning */
524 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
525 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
527 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
528 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
530 /* We assume these are burst units (multiplied by 2, we need it pari) */
531 X1 = video_panning_value_x & 0xfffe;
534 /* We assume these are field line units (divided by 2, we need it pari) */
535 Y1 = video_panning_value_y & 0xfffe;
538 debug("X1=%d, X2=%d, Y1=%d, Y2=%d, DX=%d, DY=%d VIDEO_COLS=%d \n",
539 X1, X2, Y1, Y2, DX, DY, VIDEO_COLS);
541 #ifdef VIDEO_MODE_NTSC
543 * Hx Vx Fx Bx VDS INT LCYC LP LST
547 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
548 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
549 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
550 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
554 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
555 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
556 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
557 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
559 * Odd field active area (TOP)
562 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
563 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
564 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
565 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
568 * Odd field active area
570 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
571 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
572 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
573 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
576 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
578 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
581 * Odd field active area (BOTTOM)
584 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
585 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
586 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
587 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
592 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
593 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
594 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
595 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
599 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
600 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
601 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
602 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
604 * Even field active area (TOP)
607 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
608 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
609 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
610 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
613 * Even field active area (CENTER)
615 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
616 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
617 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
618 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
621 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
623 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
625 * Even field active area (BOTTOM)
628 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
629 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
630 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
631 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
636 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
637 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
638 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
639 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
642 #ifdef VIDEO_MODE_PAL
644 #if defined(CONFIG_RRVISION)
646 #define HPW 160 /* horizontal pulse width (was 139) */
647 #define VPW 2 /* vertical pulse width */
648 #define HBP 104 /* horizontal back porch (was 112) */
649 #define VBP 19 /* vertical back porch (was 19) */
650 #define VID_R 240 /* number of rows */
652 debug ("[VIDEO CTRL] Starting to add controller entries...");
656 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
657 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
658 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
660 ADDENTRY (0, 0, 0, 3, 1, 0, VPW, 1, 0);
661 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
662 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
664 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
665 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
666 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
670 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
671 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
672 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
673 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
674 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
676 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
677 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
678 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
682 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
683 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
684 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
686 ADDENTRY (0, 0, 0, 3, 1, 0, VPW+1, 1, 0);
687 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
688 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
690 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 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, VID_R , 1, 0);
697 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
698 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
699 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
700 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
702 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
703 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
704 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
708 #else /* !CONFIG_RRVISION */
711 * Hx Vx Fx Bx VDS INT LCYC LP LST
715 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
716 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
717 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
718 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
723 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0); /* 11? */
724 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
725 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
726 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
729 * field active area (CENTER)
731 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0); /* 265? */
732 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
733 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
734 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
737 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
739 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
741 * field active area (BOTTOM)
744 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0); /* 12? */
745 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
746 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
747 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
750 * field vertical; blanking
752 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
753 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
754 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
755 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
757 * Create the other field (like this, but whit other field selected,
758 * one more cycle loop and a last identifier)
760 video_mode_dupefield (vr, &vr[entry], entry);
761 #endif /* CONFIG_RRVISION */
763 #endif /* VIDEO_MODE_PAL */
765 /* See what FIFO are we using */
766 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
768 /* Set number of lines and burst (only one frame for now) */
770 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
771 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
773 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
774 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
777 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
780 * Wait until changes are applied (not done)
781 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
784 /* Return number of VRAM entries */
788 static void video_encoder_init (void)
793 /* Initialize the I2C */
794 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
795 #ifdef CONFIG_SYS_I2C
798 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
802 /* Reset ADV7176 chip */
803 debug ("[VIDEO ENCODER] Resetting encoder...\n");
804 (*(int *) BCSR4) &= ~(1 << 21);
806 /* Wait for 5 ms inside the reset */
807 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
810 /* Take ADV7176 out of reset */
811 (*(int *) BCSR4) |= 1 << 21;
813 /* Wait for 5 ms after the reset */
815 #endif /* CONFIG_FADS */
817 /* Send configuration */
822 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
824 printf ("Sending %zu bytes (@ %08lX) to I2C 0x%lX:\n ",
825 sizeof(video_encoder_data),
826 (ulong)video_encoder_data,
827 (ulong)VIDEO_I2C_ADDR);
828 for (i=0; i<sizeof(video_encoder_data); ++i) {
829 printf(" %02X", video_encoder_data[i]);
835 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
837 sizeof(video_encoder_data))) != 0) {
838 printf ("i2c_send error: rc=%d\n", rc);
841 #endif /* VIDEO_I2C */
845 static void video_ctrl_init (void *memptr)
847 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
849 video_fb_address = memptr;
852 debug ("[VIDEO CTRL] Setting background color...\n");
853 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
855 /* Show the background */
856 debug ("[VIDEO CTRL] Forcing background...\n");
857 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
859 /* Turn off video controller */
860 debug ("[VIDEO CTRL] Turning off video controller...\n");
861 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
864 /* Turn on Video Port LED */
865 debug ("[VIDEO CTRL] Turning off video port led...\n");
866 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
868 /* Disable internal clock */
869 debug ("[VIDEO CTRL] Disabling internal clock...\n");
870 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
873 /* Generate and make active a new video mode */
874 debug ("[VIDEO CTRL] Generating video mode...\n");
875 video_mode_generate ();
877 /* Start of frame buffer (even and odd frame, to make it working with */
878 /* any selected active set) */
879 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
880 immap->im_vid.vid_vfaa1 =
881 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
882 immap->im_vid.vid_vfba1 =
883 immap->im_vid.vid_vfba0 =
884 (u32) video_fb_address + VIDEO_LINE_LEN;
886 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
887 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
888 immap->im_vid.vid_vccr = 0x2042;
890 /* Configure port pins */
891 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
892 immap->im_ioport.iop_pdpar = 0x1fff;
893 immap->im_ioport.iop_pddir = 0x0000;
896 /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
897 debug ("[VIDEO CTRL] Turning on video clock...\n");
898 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
900 /* Turn on Video Port LED */
901 debug ("[VIDEO CTRL] Turning on video port led...\n");
902 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
904 #ifdef CONFIG_RRVISION
905 debug ("PC5->Output(1): enable PAL clock");
906 immap->im_ioport.iop_pcpar &= ~(0x0400);
907 immap->im_ioport.iop_pcdir |= 0x0400 ;
908 immap->im_ioport.iop_pcdat |= 0x0400 ;
909 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
910 immap->im_ioport.iop_pdpar,
911 immap->im_ioport.iop_pddir,
912 immap->im_ioport.iop_pddat);
913 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
914 immap->im_ioport.iop_pcpar,
915 immap->im_ioport.iop_pcdir,
916 immap->im_ioport.iop_pcdat);
917 #endif /* CONFIG_RRVISION */
919 /* Blanking the screen. */
920 debug ("[VIDEO CTRL] Blanking the screen...\n");
921 video_fill (VIDEO_BG_COL);
924 * Turns on Aggressive Mode. Normally, turning on the caches
925 * will cause the screen to flicker when the caches try to
926 * fill. This gives the FIFO's for the Video Controller
927 * higher priority and prevents flickering because of
928 * underrun. This may still be an issue when using FLASH,
929 * since accessing data from Flash is so slow.
931 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
932 immap->im_siu_conf.sc_sdcr = 0x40;
934 /* Turn on video controller */
935 debug ("[VIDEO CTRL] Turning on video controller...\n");
936 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
938 /* Show the display */
939 debug ("[VIDEO CTRL] Enabling the video...\n");
940 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
943 /************************************************************************/
944 /* ** CONSOLE FUNCTIONS */
945 /************************************************************************/
947 static void console_scrollup (void)
949 /* Copy up rows ignoring the first one */
950 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
952 /* Clear the last one */
953 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
956 static inline void console_back (void)
960 if (console_col < 0) {
961 console_col = CONSOLE_COLS - 1;
967 video_putchar ( console_col * VIDEO_FONT_WIDTH,
968 console_row * VIDEO_FONT_HEIGHT, ' ');
971 static inline void console_newline (void)
976 /* Check if we need to scroll the terminal */
977 if (console_row >= CONSOLE_ROWS) {
978 /* Scroll everything up */
981 /* Decrement row number */
986 void video_putc (const char c)
994 case 13: /* Simply ignore this */
997 case '\n': /* Next line, please */
1001 case 9: /* Tab (8 chars alignment) */
1002 console_col |= 0x0008; /* Next 8 chars boundary */
1003 console_col &= ~0x0007; /* Set this bit to zero */
1005 if (console_col >= CONSOLE_COLS)
1009 case 8: /* Eat last character */
1013 default: /* Add to the console */
1014 video_putchar ( console_col * VIDEO_FONT_WIDTH,
1015 console_row * VIDEO_FONT_HEIGHT, c);
1017 /* Check if we need to go to next row */
1018 if (console_col >= CONSOLE_COLS)
1023 void video_puts (const char *s)
1025 int count = strlen (s);
1035 /************************************************************************/
1036 /* ** CURSOR BLINKING FUNCTIONS */
1037 /************************************************************************/
1041 #define BLINK_TIMER_ID 0
1042 #define BLINK_TIMER_HZ 2
1044 static unsigned char blink_enabled = 0;
1045 static timer_t blink_timer;
1047 static void blink_update (void)
1049 static int blink_row = -1, blink_col = -1, blink_old = 0;
1051 /* Check if we have a new position to invert */
1052 if ((console_row != blink_row) || (console_col != blink_col)) {
1053 /* Check if we need to reverse last character */
1055 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1057 #ifdef CONFIG_VIDEO_LOGO
1060 ) * VIDEO_FONT_HEIGHT);
1063 blink_row = console_row;
1064 blink_col = console_col;
1068 /* Reverse this character */
1069 blink_old = !blink_old;
1070 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1072 #ifdef CONFIG_VIDEO_LOGO
1075 ) * VIDEO_FONT_HEIGHT);
1080 * Handler for blinking cursor
1082 static void blink_handler (void *arg)
1087 timer_ack (&blink_timer);
1090 int blink_set (int blink)
1092 int ret = blink_enabled;
1095 timer_enable (&blink_timer);
1097 timer_disable (&blink_timer);
1099 blink_enabled = blink;
1104 static inline void blink_close (void)
1106 timer_close (&blink_timer);
1109 static inline void blink_init (void)
1111 timer_init (&blink_timer,
1112 BLINK_TIMER_ID, BLINK_TIMER_HZ,
1117 /************************************************************************/
1118 /* ** LOGO PLOTTING FUNCTIONS */
1119 /************************************************************************/
1121 #ifdef CONFIG_VIDEO_LOGO
1122 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1125 int skip = width - image->width, xcount, ycount = image->height;
1127 #ifdef VIDEO_MODE_YUYV
1128 ushort *source = (ushort *) image->data;
1129 ushort *dest = (ushort *) screen + y * width + x;
1132 xcount = image->width;
1134 *dest++ = *source++;
1138 #ifdef VIDEO_MODE_RGB
1140 *source = (unsigned short *) image->data,
1141 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1144 xcount = image->width * 3;
1145 memcpy (dest, source, xcount);
1152 static void *video_logo (void)
1154 u16 *screen = video_fb_address, width = VIDEO_COLS;
1156 # ifndef CONFIG_FADS
1160 #endif /* VIDEO_INFO */
1162 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1165 sprintf (info, "%s (%s - %s) ",
1166 U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
1167 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1169 sprintf (info, "(C) 2002 DENX Software Engineering");
1170 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1173 sprintf (info, " Wolfgang DENK, wd@denx.de");
1174 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1176 #ifndef CONFIG_FADS /* all normal boards */
1177 /* leave one blank line */
1179 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1180 strmhz(temp, gd->cpu_clk),
1182 gd->bd->bi_flashsize >> 20 );
1183 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1185 #else /* FADS :-( */
1186 sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1187 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1190 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1191 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1196 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1200 /************************************************************************/
1201 /* ** VIDEO HIGH-LEVEL FUNCTIONS */
1202 /************************************************************************/
1204 static int video_init (void *videobase)
1206 /* Initialize the encoder */
1207 debug ("[VIDEO] Initializing video encoder...\n");
1208 video_encoder_init ();
1210 /* Initialize the video controller */
1211 debug ("[VIDEO] Initializing video controller at %08x...\n",
1213 video_ctrl_init (videobase);
1215 /* Setting the palette */
1216 video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
1217 video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
1218 video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
1219 video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
1220 video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
1221 video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
1222 video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
1223 video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
1224 video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
1225 video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
1227 #ifndef CONFIG_SYS_WHITE_ON_BLACK
1228 video_setfgcolor (CONSOLE_COLOR_BLACK);
1229 video_setbgcolor (CONSOLE_COLOR_GREY2);
1231 video_setfgcolor (CONSOLE_COLOR_GREY2);
1232 video_setbgcolor (CONSOLE_COLOR_BLACK);
1233 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
1235 #ifdef CONFIG_VIDEO_LOGO
1236 /* Paint the logo and retrieve tv base address */
1237 debug ("[VIDEO] Drawing the logo...\n");
1238 video_console_address = video_logo ();
1240 video_console_address = video_fb_address;
1244 /* Enable the blinking (under construction) */
1246 blink_set (0); /* To Fix! */
1249 /* Initialize the console */
1254 #ifdef VIDEO_MODE_PAL
1255 # define VIDEO_MODE_TMP1 "PAL"
1257 #ifdef VIDEO_MODE_NTSC
1258 # define VIDEO_MODE_TMP1 "NTSC"
1260 #ifdef VIDEO_MODE_YUYV
1261 # define VIDEO_MODE_TMP2 "YCbYCr"
1263 #ifdef VIDEO_MODE_RGB
1264 # define VIDEO_MODE_TMP2 "RGB"
1266 debug ( VIDEO_MODE_TMP1
1267 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1268 VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1269 VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1273 int drv_video_init (void)
1275 int error, devices = 1;
1277 struct stdio_dev videodev;
1279 video_init ((void *)(gd->fb_base)); /* Video initialization */
1281 /* Device initialization */
1283 memset (&videodev, 0, sizeof (videodev));
1285 strcpy (videodev.name, "video");
1286 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
1287 videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
1288 videodev.putc = video_putc; /* 'putc' function */
1289 videodev.puts = video_puts; /* 'puts' function */
1291 error = stdio_register (&videodev);
1293 return (error == 0) ? devices : error;
1296 /************************************************************************/
1297 /* ** ROM capable initialization part - needed to reserve FB memory */
1298 /************************************************************************/
1301 * This is called early in the system initialization to grab memory
1302 * for the video controller.
1303 * Returns new address for monitor, after reserving video buffer memory
1305 * Note that this is running from ROM, so no write access to global data.
1307 ulong video_setmem (ulong addr)
1309 /* Allocate pages for the frame buffer. */
1312 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1313 VIDEO_SIZE>>10, addr);