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 MODE CONSTANTS */
57 /************************************************************************/
59 #ifdef VIDEO_MODE_EXTENDED
60 #define VIDEO_COLS VIDEO_ACTIVE_COLS
61 #define VIDEO_ROWS VIDEO_ACTIVE_ROWS
63 #define VIDEO_COLS VIDEO_VISIBLE_COLS
64 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
67 #define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
68 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Total size of buffer */
69 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) /* Number of ints */
70 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Number of bytes per line */
71 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
73 #ifdef VIDEO_MODE_YUYV
74 #define VIDEO_BG_COL 0x80D880D8 /* Background color in YUYV format */
76 #define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
79 /************************************************************************/
80 /* ** FONT AND LOGO DATA */
81 /************************************************************************/
83 #include <video_font.h> /* Get font data, width and height */
85 #ifdef CONFIG_VIDEO_LOGO
86 #include <video_logo.h> /* Get logo data, width and height */
88 #define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
89 #define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
90 #define VIDEO_LOGO_ADDR &u_boot_logo
93 /************************************************************************/
94 /* ** VIDEO CONTROLLER CONSTANTS */
95 /************************************************************************/
97 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
99 #define VIDEO_VCCR_VON 0 /* Video controller ON */
100 #define VIDEO_VCCR_CSRC 1 /* Clock source */
101 #define VIDEO_VCCR_PDF 13 /* Pixel display format */
102 #define VIDEO_VCCR_IEN 11 /* Interrupt enable */
104 /* VSR - VIDEO STATUS REGISTER */
106 #define VIDEO_VSR_CAS 6 /* Active set */
107 #define VIDEO_VSR_EOF 0 /* End of frame */
109 /* VCMR - VIDEO COMMAND REGISTER */
111 #define VIDEO_VCMR_BD 0 /* Blank display */
112 #define VIDEO_VCMR_ASEL 1 /* Active set selection */
114 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
116 #define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
117 #define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
118 #define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
120 /************************************************************************/
121 /* ** CONSOLE CONSTANTS */
122 /************************************************************************/
124 #ifdef CONFIG_VIDEO_LOGO
125 #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
126 #define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
128 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
131 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
132 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
133 #define CONSOLE_ROW_FIRST (video_console_address)
134 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
135 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
136 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
137 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
140 * Simple color definitions
142 #define CONSOLE_COLOR_BLACK 0
143 #define CONSOLE_COLOR_RED 1
144 #define CONSOLE_COLOR_GREEN 2
145 #define CONSOLE_COLOR_YELLOW 3
146 #define CONSOLE_COLOR_BLUE 4
147 #define CONSOLE_COLOR_MAGENTA 5
148 #define CONSOLE_COLOR_CYAN 6
149 #define CONSOLE_COLOR_GREY 13
150 #define CONSOLE_COLOR_GREY2 14
151 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
153 /************************************************************************/
154 /* ** BITOPS MACROS */
155 /************************************************************************/
157 #define HISHORT(i) ((i >> 16)&0xffff)
158 #define LOSHORT(i) (i & 0xffff)
159 #define HICHAR(s) ((i >> 8)&0xff)
160 #define LOCHAR(s) (i & 0xff)
161 #define HI(c) ((c >> 4)&0xf)
162 #define LO(c) (c & 0xf)
163 #define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
164 #define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
165 #define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
166 #define BITMASK(b) (1 << (b))
167 #define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
168 #define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
170 /************************************************************************/
172 /************************************************************************/
175 unsigned char V, Y1, U, Y2;
178 /* This structure is based on the Video Ram in the MPC823. */
179 typedef struct VRAM {
180 unsigned hx:2, /* Horizontal sync */
181 vx:2, /* Vertical sync */
184 res1:6, /* Reserved */
185 vds:2, /* Video Data Select */
186 inter:1, /* Interrupt */
187 res2:2, /* Reserved */
188 lcyc:11, /* Loop/video cycles */
189 lp:1, /* Loop start/end */
190 lst:1; /* Last entry */
193 /************************************************************************/
195 /************************************************************************/
198 video_panning_range_x = 0, /* Video mode invisible pixels x range */
199 video_panning_range_y = 0, /* Video mode invisible pixels y range */
200 video_panning_value_x = 0, /* Video mode x panning value (absolute) */
201 video_panning_value_y = 0, /* Video mode y panning value (absolute) */
202 video_panning_factor_x = 0, /* Video mode x panning value (-127 +127) */
203 video_panning_factor_y = 0, /* Video mode y panning value (-127 +127) */
204 console_col = 0, /* Cursor col */
205 console_row = 0, /* Cursor row */
206 video_palette[16]; /* Our palette */
208 static const int video_font_draw_table[] =
209 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
212 video_color_fg = 0, /* Current fg color index (0-15) */
213 video_color_bg = 0, /* Current bg color index (0-15) */
214 video_enable = 0; /* Video has been initialized? */
217 *video_fb_address, /* Frame buffer address */
218 *video_console_address; /* Console frame buffer start address */
220 /************************************************************************/
221 /* ** MEMORY FUNCTIONS (32bit) */
222 /************************************************************************/
224 static void memsetl (int *p, int c, int v)
230 static void memcpyl (int *d, int *s, int c)
236 /************************************************************************/
237 /* ** VIDEO DRAWING AND COLOR FUNCTIONS */
238 /************************************************************************/
240 static int video_maprgb (int r, int g, int b)
242 #ifdef VIDEO_MODE_YUYV
243 unsigned int pR, pG, pB;
245 unsigned int *ret = (unsigned int *) &YUYV;
247 /* Transform (0-255) components to (0-100) */
253 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
255 YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
256 YUYV.U = pR - (pG * 3 / 4) - (pB / 4) + 128;
257 YUYV.V = pB - (pR / 4) - (pG * 3 / 4) + 128;
260 #ifdef VIDEO_MODE_RGB
261 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
265 static void video_setpalette (int color, int r, int g, int b)
269 video_palette[color] = video_maprgb (r, g, b);
271 /* Swap values if our panning offset is odd */
272 if (video_panning_value_x & 1)
273 video_palette[color] = SWAPINT (video_palette[color]);
276 static void video_fill (int color)
278 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
281 static void video_setfgcolor (int i)
283 video_color_fg = i & 0xf;
286 static void video_setbgcolor (int i)
288 video_color_bg = i & 0xf;
291 static int video_pickcolor (int i)
293 return video_palette[i & 0xf];
296 /* Absolute console plotting functions */
299 static void video_revchar (int xx, int yy)
304 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
306 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
307 switch (VIDEO_FONT_WIDTH) {
309 ((u32 *) dest)[6] ^= 0xffffffff;
310 ((u32 *) dest)[7] ^= 0xffffffff;
313 ((u32 *) dest)[4] ^= 0xffffffff;
314 ((u32 *) dest)[5] ^= 0xffffffff;
317 ((u32 *) dest)[2] ^= 0xffffffff;
318 ((u32 *) dest)[3] ^= 0xffffffff;
321 ((u32 *) dest)[0] ^= 0xffffffff;
322 ((u32 *) dest)[1] ^= 0xffffffff;
328 static void video_drawchars (int xx, int yy, unsigned char *s, int count)
330 u8 *cdat, *dest, *dest0;
334 offset = yy * VIDEO_LINE_LEN + xx * 2;
335 dest0 = video_fb_address + offset;
337 fgx = video_pickcolor (video_color_fg);
338 bgx = video_pickcolor (video_color_bg);
347 switch (VIDEO_FONT_WIDTH) {
352 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
353 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
355 dest += VIDEO_LINE_LEN) {
359 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
361 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
362 if (VIDEO_FONT_WIDTH == 8) {
364 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
366 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
369 dest0 += VIDEO_FONT_WIDTH * 2;
376 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
377 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
378 dest += VIDEO_LINE_LEN) {
382 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
384 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
386 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
388 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
391 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
393 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
394 if (VIDEO_FONT_WIDTH == 16) {
396 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
398 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
402 dest0 += VIDEO_FONT_WIDTH * 2;
408 static inline void video_drawstring (int xx, int yy, char *s)
410 video_drawchars (xx, yy, (unsigned char *)s, strlen (s));
413 /* Relative to console plotting functions */
415 static void video_putchars (int xx, int yy, unsigned char *s, int count)
417 #ifdef CONFIG_VIDEO_LOGO
418 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
420 video_drawchars (xx, yy, s, count);
424 static void video_putchar (int xx, int yy, unsigned char c)
426 #ifdef CONFIG_VIDEO_LOGO
427 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
429 video_drawchars (xx, yy, &c, 1);
433 static inline void video_putstring (int xx, int yy, unsigned char *s)
435 video_putchars (xx, yy, (unsigned char *)s, strlen ((char *)s));
438 /************************************************************************/
439 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
440 /************************************************************************/
442 static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
446 for (i = 0; i < entries; i++) {
447 dest[i] = source[i]; /* Copy the entire record */
448 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
451 dest[0].lcyc++; /* Add a cycle to the first entry */
452 dest[entries - 1].lst = 1; /* Set end of ram entries */
455 static void inline video_mode_addentry (VRAM * vr,
456 int Hx, int Vx, int Fx, int Bx,
457 int VDS, int INT, int LCYC, int LP, int LST)
470 #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)
472 static int video_mode_generate (void)
474 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
475 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
476 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
478 /* CHECKING PARAMETERS */
480 if (video_panning_factor_y < -128)
481 video_panning_factor_y = -128;
483 if (video_panning_factor_y > 128)
484 video_panning_factor_y = 128;
486 if (video_panning_factor_x < -128)
487 video_panning_factor_x = -128;
489 if (video_panning_factor_x > 128)
490 video_panning_factor_x = 128;
492 /* Setting panning */
494 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
495 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
497 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
498 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
500 /* We assume these are burst units (multiplied by 2, we need it pari) */
501 X1 = video_panning_value_x & 0xfffe;
504 /* We assume these are field line units (divided by 2, we need it pari) */
505 Y1 = video_panning_value_y & 0xfffe;
508 debug("X1=%d, X2=%d, Y1=%d, Y2=%d, DX=%d, DY=%d VIDEO_COLS=%d \n",
509 X1, X2, Y1, Y2, DX, DY, VIDEO_COLS);
511 #ifdef VIDEO_MODE_NTSC
513 * Hx Vx Fx Bx VDS INT LCYC LP LST
517 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
518 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
519 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
520 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
524 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
525 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
526 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
527 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
529 * Odd field active area (TOP)
532 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
533 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
534 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
535 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
538 * Odd field active area
540 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
541 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
542 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
543 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
546 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
548 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
551 * Odd field active area (BOTTOM)
554 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
555 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
556 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
557 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
562 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
563 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
564 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
565 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
569 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
570 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
571 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
572 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
574 * Even field active area (TOP)
577 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
578 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
579 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
580 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
583 * Even field active area (CENTER)
585 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
586 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
587 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
588 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
591 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
593 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
595 * Even field active area (BOTTOM)
598 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
599 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
600 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
601 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
606 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
607 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
608 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
609 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
612 #ifdef VIDEO_MODE_PAL
615 * Hx Vx Fx Bx VDS INT LCYC LP LST
619 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
620 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
621 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
622 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
627 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0); /* 11? */
628 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
629 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
630 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
633 * field active area (CENTER)
635 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0); /* 265? */
636 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
637 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
638 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
641 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
643 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
645 * field active area (BOTTOM)
648 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0); /* 12? */
649 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
650 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
651 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
654 * field vertical; blanking
656 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
657 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
658 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
659 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
661 * Create the other field (like this, but whit other field selected,
662 * one more cycle loop and a last identifier)
664 video_mode_dupefield (vr, &vr[entry], entry);
666 #endif /* VIDEO_MODE_PAL */
668 /* See what FIFO are we using */
669 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
671 /* Set number of lines and burst (only one frame for now) */
673 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
674 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
676 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
677 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
680 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
683 * Wait until changes are applied (not done)
684 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
687 /* Return number of VRAM entries */
691 static void video_encoder_init (void)
696 static void video_ctrl_init (void *memptr)
698 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
700 video_fb_address = memptr;
703 debug ("[VIDEO CTRL] Setting background color...\n");
704 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
706 /* Show the background */
707 debug ("[VIDEO CTRL] Forcing background...\n");
708 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
710 /* Turn off video controller */
711 debug ("[VIDEO CTRL] Turning off video controller...\n");
712 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
714 /* Generate and make active a new video mode */
715 debug ("[VIDEO CTRL] Generating video mode...\n");
716 video_mode_generate ();
718 /* Start of frame buffer (even and odd frame, to make it working with */
719 /* any selected active set) */
720 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
721 immap->im_vid.vid_vfaa1 =
722 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
723 immap->im_vid.vid_vfba1 =
724 immap->im_vid.vid_vfba0 =
725 (u32) video_fb_address + VIDEO_LINE_LEN;
727 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
728 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
729 immap->im_vid.vid_vccr = 0x2042;
731 /* Configure port pins */
732 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
733 immap->im_ioport.iop_pdpar = 0x1fff;
734 immap->im_ioport.iop_pddir = 0x0000;
736 /* Blanking the screen. */
737 debug ("[VIDEO CTRL] Blanking the screen...\n");
738 video_fill (VIDEO_BG_COL);
741 * Turns on Aggressive Mode. Normally, turning on the caches
742 * will cause the screen to flicker when the caches try to
743 * fill. This gives the FIFO's for the Video Controller
744 * higher priority and prevents flickering because of
745 * underrun. This may still be an issue when using FLASH,
746 * since accessing data from Flash is so slow.
748 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
749 immap->im_siu_conf.sc_sdcr = 0x40;
751 /* Turn on video controller */
752 debug ("[VIDEO CTRL] Turning on video controller...\n");
753 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
755 /* Show the display */
756 debug ("[VIDEO CTRL] Enabling the video...\n");
757 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
760 /************************************************************************/
761 /* ** CONSOLE FUNCTIONS */
762 /************************************************************************/
764 static void console_scrollup (void)
766 /* Copy up rows ignoring the first one */
767 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
769 /* Clear the last one */
770 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
773 static inline void console_back (void)
777 if (console_col < 0) {
778 console_col = CONSOLE_COLS - 1;
784 video_putchar ( console_col * VIDEO_FONT_WIDTH,
785 console_row * VIDEO_FONT_HEIGHT, ' ');
788 static inline void console_newline (void)
793 /* Check if we need to scroll the terminal */
794 if (console_row >= CONSOLE_ROWS) {
795 /* Scroll everything up */
798 /* Decrement row number */
803 void video_putc(struct stdio_dev *dev, const char c)
811 case 13: /* Simply ignore this */
814 case '\n': /* Next line, please */
818 case 9: /* Tab (8 chars alignment) */
819 console_col |= 0x0008; /* Next 8 chars boundary */
820 console_col &= ~0x0007; /* Set this bit to zero */
822 if (console_col >= CONSOLE_COLS)
826 case 8: /* Eat last character */
830 default: /* Add to the console */
831 video_putchar ( console_col * VIDEO_FONT_WIDTH,
832 console_row * VIDEO_FONT_HEIGHT, c);
834 /* Check if we need to go to next row */
835 if (console_col >= CONSOLE_COLS)
840 void video_puts(struct stdio_dev *dev, const char *s)
842 int count = strlen (s);
849 video_putc(dev, *s++);
852 /************************************************************************/
853 /* ** CURSOR BLINKING FUNCTIONS */
854 /************************************************************************/
858 #define BLINK_TIMER_ID 0
859 #define BLINK_TIMER_HZ 2
861 static unsigned char blink_enabled = 0;
862 static timer_t blink_timer;
864 static void blink_update (void)
866 static int blink_row = -1, blink_col = -1, blink_old = 0;
868 /* Check if we have a new position to invert */
869 if ((console_row != blink_row) || (console_col != blink_col)) {
870 /* Check if we need to reverse last character */
872 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
874 #ifdef CONFIG_VIDEO_LOGO
877 ) * VIDEO_FONT_HEIGHT);
880 blink_row = console_row;
881 blink_col = console_col;
885 /* Reverse this character */
886 blink_old = !blink_old;
887 video_revchar ( console_col * VIDEO_FONT_WIDTH,
889 #ifdef CONFIG_VIDEO_LOGO
892 ) * VIDEO_FONT_HEIGHT);
897 * Handler for blinking cursor
899 static void blink_handler (void *arg)
904 timer_ack (&blink_timer);
907 int blink_set (int blink)
909 int ret = blink_enabled;
912 timer_enable (&blink_timer);
914 timer_disable (&blink_timer);
916 blink_enabled = blink;
921 static inline void blink_close (void)
923 timer_close (&blink_timer);
926 static inline void blink_init (void)
928 timer_init (&blink_timer,
929 BLINK_TIMER_ID, BLINK_TIMER_HZ,
934 /************************************************************************/
935 /* ** LOGO PLOTTING FUNCTIONS */
936 /************************************************************************/
938 #ifdef CONFIG_VIDEO_LOGO
939 void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
942 int skip = width - image->width, xcount, ycount = image->height;
944 #ifdef VIDEO_MODE_YUYV
945 ushort *source = (ushort *) image->data;
946 ushort *dest = (ushort *) screen + y * width + x;
949 xcount = image->width;
955 #ifdef VIDEO_MODE_RGB
957 *source = (unsigned short *) image->data,
958 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
961 xcount = image->width * 3;
962 memcpy (dest, source, xcount);
969 static void *video_logo (void)
971 u16 *screen = video_fb_address, width = VIDEO_COLS;
975 #endif /* VIDEO_INFO */
977 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
980 sprintf (info, "%s (%s - %s) ",
981 U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
982 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
984 strcpy(info, "(C) 2002 DENX Software Engineering");
985 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
988 strcpy(info, " Wolfgang DENK, wd@denx.de");
989 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
992 /* leave one blank line */
994 sprintf(info, "MPC823 CPU at %s MHz, %ld MiB RAM, %ld MiB Flash",
995 strmhz(temp, gd->cpu_clk),
997 gd->bd->bi_flashsize >> 20 );
998 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1002 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1006 /************************************************************************/
1007 /* ** VIDEO HIGH-LEVEL FUNCTIONS */
1008 /************************************************************************/
1010 static int video_init (void *videobase)
1012 /* Initialize the encoder */
1013 debug ("[VIDEO] Initializing video encoder...\n");
1014 video_encoder_init ();
1016 /* Initialize the video controller */
1017 debug ("[VIDEO] Initializing video controller at %08x...\n",
1019 video_ctrl_init (videobase);
1021 /* Setting the palette */
1022 video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
1023 video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
1024 video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
1025 video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
1026 video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
1027 video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
1028 video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
1029 video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
1030 video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
1031 video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
1033 #ifndef CONFIG_SYS_WHITE_ON_BLACK
1034 video_setfgcolor (CONSOLE_COLOR_BLACK);
1035 video_setbgcolor (CONSOLE_COLOR_GREY2);
1037 video_setfgcolor (CONSOLE_COLOR_GREY2);
1038 video_setbgcolor (CONSOLE_COLOR_BLACK);
1039 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
1041 #ifdef CONFIG_VIDEO_LOGO
1042 /* Paint the logo and retrieve tv base address */
1043 debug ("[VIDEO] Drawing the logo...\n");
1044 video_console_address = video_logo ();
1046 video_console_address = video_fb_address;
1050 /* Enable the blinking (under construction) */
1052 blink_set (0); /* To Fix! */
1055 /* Initialize the console */
1060 #ifdef VIDEO_MODE_PAL
1061 # define VIDEO_MODE_TMP1 "PAL"
1063 #ifdef VIDEO_MODE_NTSC
1064 # define VIDEO_MODE_TMP1 "NTSC"
1066 #ifdef VIDEO_MODE_YUYV
1067 # define VIDEO_MODE_TMP2 "YCbYCr"
1069 #ifdef VIDEO_MODE_RGB
1070 # define VIDEO_MODE_TMP2 "RGB"
1072 debug ( VIDEO_MODE_TMP1
1073 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1074 VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1075 VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1079 int drv_video_init (void)
1081 int error, devices = 1;
1083 struct stdio_dev videodev;
1085 video_init ((void *)(gd->fb_base)); /* Video initialization */
1087 /* Device initialization */
1089 memset (&videodev, 0, sizeof (videodev));
1091 strcpy (videodev.name, "video");
1092 videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
1093 videodev.putc = video_putc; /* 'putc' function */
1094 videodev.puts = video_puts; /* 'puts' function */
1096 error = stdio_register (&videodev);
1098 return (error == 0) ? devices : error;
1101 /************************************************************************/
1102 /* ** ROM capable initialization part - needed to reserve FB memory */
1103 /************************************************************************/
1106 * This is called early in the system initialization to grab memory
1107 * for the video controller.
1108 * Returns new address for monitor, after reserving video buffer memory
1110 * Note that this is running from ROM, so no write access to global data.
1112 ulong video_setmem (ulong addr)
1114 /* Allocate pages for the frame buffer. */
1117 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1118 VIDEO_SIZE>>10, addr);