]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - arch/ppc/cpu/mpc8xx/video.c
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 /************************************************************************/
36 #include <timestamp.h>
38 #include <linux/types.h>
39 #include <stdio_dev.h>
43 DECLARE_GLOBAL_DATA_PTR
;
45 /************************************************************************/
46 /* ** DEBUG SETTINGS */
47 /************************************************************************/
50 #define VIDEO_DEBUG_COLORBARS /* Force colorbars output */
53 /************************************************************************/
54 /* ** VIDEO MODE SETTINGS */
55 /************************************************************************/
58 #define VIDEO_MODE_EXTENDED /* Allow screen size bigger than visible area */
59 #define VIDEO_MODE_NTSC
62 #define VIDEO_MODE_PAL
65 #define VIDEO_BLINK /* This enables cursor blinking (under construction) */
68 #define VIDEO_INFO /* Show U-Boot information */
69 #define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
70 #define VIDEO_INFO_Y 16
72 /************************************************************************/
73 /* ** VIDEO ENCODER CONSTANTS */
74 /************************************************************************/
76 #ifdef CONFIG_VIDEO_ENCODER_AD7176
78 #include <video_ad7176.h> /* Sets encoder data, mode, and visible and active area */
81 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
84 #ifdef CONFIG_VIDEO_ENCODER_AD7177
86 #include <video_ad7177.h> /* Sets encoder data, mode, and visible and active area */
89 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
92 #ifdef CONFIG_VIDEO_ENCODER_AD7179
94 #include <video_ad7179.h> /* Sets encoder data, mode, and visible and active area */
97 #define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
100 /************************************************************************/
101 /* ** VIDEO MODE CONSTANTS */
102 /************************************************************************/
104 #ifdef VIDEO_MODE_EXTENDED
105 #define VIDEO_COLS VIDEO_ACTIVE_COLS
106 #define VIDEO_ROWS VIDEO_ACTIVE_ROWS
108 #define VIDEO_COLS VIDEO_VISIBLE_COLS
109 #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
112 #define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
113 #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Total size of buffer */
114 #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) /* Number of ints */
115 #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Number of bytes per line */
116 #define VIDEO_BURST_LEN (VIDEO_COLS/8)
118 #ifdef VIDEO_MODE_YUYV
119 #define VIDEO_BG_COL 0x80D880D8 /* Background color in YUYV format */
121 #define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
124 /************************************************************************/
125 /* ** FONT AND LOGO DATA */
126 /************************************************************************/
128 #include <video_font.h> /* Get font data, width and height */
130 #ifdef CONFIG_VIDEO_LOGO
131 #include <video_logo.h> /* Get logo data, width and height */
133 #define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
134 #define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
135 #define VIDEO_LOGO_ADDR &u_boot_logo
138 /************************************************************************/
139 /* ** VIDEO CONTROLLER CONSTANTS */
140 /************************************************************************/
142 /* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
144 #define VIDEO_VCCR_VON 0 /* Video controller ON */
145 #define VIDEO_VCCR_CSRC 1 /* Clock source */
146 #define VIDEO_VCCR_PDF 13 /* Pixel display format */
147 #define VIDEO_VCCR_IEN 11 /* Interrupt enable */
149 /* VSR - VIDEO STATUS REGISTER */
151 #define VIDEO_VSR_CAS 6 /* Active set */
152 #define VIDEO_VSR_EOF 0 /* End of frame */
154 /* VCMR - VIDEO COMMAND REGISTER */
156 #define VIDEO_VCMR_BD 0 /* Blank display */
157 #define VIDEO_VCMR_ASEL 1 /* Active set selection */
159 /* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
161 #define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
162 #define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
163 #define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
165 /************************************************************************/
166 /* ** CONSOLE CONSTANTS */
167 /************************************************************************/
169 #ifdef CONFIG_VIDEO_LOGO
170 #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
171 #define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
173 #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
176 #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
177 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
178 #define CONSOLE_ROW_FIRST (video_console_address)
179 #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
180 #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
181 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
182 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
185 * Simple color definitions
187 #define CONSOLE_COLOR_BLACK 0
188 #define CONSOLE_COLOR_RED 1
189 #define CONSOLE_COLOR_GREEN 2
190 #define CONSOLE_COLOR_YELLOW 3
191 #define CONSOLE_COLOR_BLUE 4
192 #define CONSOLE_COLOR_MAGENTA 5
193 #define CONSOLE_COLOR_CYAN 6
194 #define CONSOLE_COLOR_GREY 13
195 #define CONSOLE_COLOR_GREY2 14
196 #define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
198 /************************************************************************/
199 /* ** BITOPS MACROS */
200 /************************************************************************/
202 #define HISHORT(i) ((i >> 16)&0xffff)
203 #define LOSHORT(i) (i & 0xffff)
204 #define HICHAR(s) ((i >> 8)&0xff)
205 #define LOCHAR(s) (i & 0xff)
206 #define HI(c) ((c >> 4)&0xf)
207 #define LO(c) (c & 0xf)
208 #define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
209 #define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
210 #define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
211 #define BITMASK(b) (1 << (b))
212 #define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
213 #define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
215 /************************************************************************/
217 /************************************************************************/
220 unsigned char V
, Y1
, U
, Y2
;
223 /* This structure is based on the Video Ram in the MPC823. */
224 typedef struct VRAM
{
225 unsigned hx
:2, /* Horizontal sync */
226 vx
:2, /* Vertical sync */
229 res1
:6, /* Reserved */
230 vds
:2, /* Video Data Select */
231 inter
:1, /* Interrupt */
232 res2
:2, /* Reserved */
233 lcyc
:11, /* Loop/video cycles */
234 lp
:1, /* Loop start/end */
235 lst
:1; /* Last entry */
238 /************************************************************************/
240 /************************************************************************/
243 video_panning_range_x
= 0, /* Video mode invisible pixels x range */
244 video_panning_range_y
= 0, /* Video mode invisible pixels y range */
245 video_panning_value_x
= 0, /* Video mode x panning value (absolute) */
246 video_panning_value_y
= 0, /* Video mode y panning value (absolute) */
247 video_panning_factor_x
= 0, /* Video mode x panning value (-127 +127) */
248 video_panning_factor_y
= 0, /* Video mode y panning value (-127 +127) */
249 console_col
= 0, /* Cursor col */
250 console_row
= 0, /* Cursor row */
251 video_palette
[16]; /* Our palette */
253 static const int video_font_draw_table
[] =
254 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
257 video_color_fg
= 0, /* Current fg color index (0-15) */
258 video_color_bg
= 0, /* Current bg color index (0-15) */
259 video_enable
= 0; /* Video has been initialized? */
262 *video_fb_address
, /* Frame buffer address */
263 *video_console_address
; /* Console frame buffer start address */
265 /************************************************************************/
266 /* ** MEMORY FUNCTIONS (32bit) */
267 /************************************************************************/
269 static void memsetl (int *p
, int c
, int v
)
275 static void memcpyl (int *d
, int *s
, int c
)
281 /************************************************************************/
282 /* ** VIDEO DRAWING AND COLOR FUNCTIONS */
283 /************************************************************************/
285 static int video_maprgb (int r
, int g
, int b
)
287 #ifdef VIDEO_MODE_YUYV
288 unsigned int pR
, pG
, pB
;
290 unsigned int *ret
= (unsigned int *) &YUYV
;
292 /* Transform (0-255) components to (0-100) */
298 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
300 YUYV
.Y1
= YUYV
.Y2
= 209 * (pR
+ pG
+ pB
) / 300 + 16;
301 YUYV
.U
= pR
- (pG
* 3 / 4) - (pB
/ 4) + 128;
302 YUYV
.V
= pB
- (pR
/ 4) - (pG
* 3 / 4) + 128;
305 #ifdef VIDEO_MODE_RGB
306 return ((r
>> 3) << 11) | ((g
> 2) << 6) | (b
>> 3);
310 static void video_setpalette (int color
, int r
, int g
, int b
)
314 video_palette
[color
] = video_maprgb (r
, g
, b
);
316 /* Swap values if our panning offset is odd */
317 if (video_panning_value_x
& 1)
318 video_palette
[color
] = SWAPINT (video_palette
[color
]);
321 static void video_fill (int color
)
323 memsetl (video_fb_address
, VIDEO_PIX_BLOCKS
, color
);
326 static void video_setfgcolor (int i
)
328 video_color_fg
= i
& 0xf;
331 static void video_setbgcolor (int i
)
333 video_color_bg
= i
& 0xf;
336 static int video_pickcolor (int i
)
338 return video_palette
[i
& 0xf];
341 /* Absolute console plotting functions */
344 static void video_revchar (int xx
, int yy
)
349 dest
= video_fb_address
+ yy
* VIDEO_LINE_LEN
+ xx
* 2;
351 for (rows
= VIDEO_FONT_HEIGHT
; rows
--; dest
+= VIDEO_LINE_LEN
) {
352 switch (VIDEO_FONT_WIDTH
) {
354 ((u32
*) dest
)[6] ^= 0xffffffff;
355 ((u32
*) dest
)[7] ^= 0xffffffff;
358 ((u32
*) dest
)[4] ^= 0xffffffff;
359 ((u32
*) dest
)[5] ^= 0xffffffff;
362 ((u32
*) dest
)[2] ^= 0xffffffff;
363 ((u32
*) dest
)[3] ^= 0xffffffff;
366 ((u32
*) dest
)[0] ^= 0xffffffff;
367 ((u32
*) dest
)[1] ^= 0xffffffff;
373 static void video_drawchars (int xx
, int yy
, unsigned char *s
, int count
)
375 u8
*cdat
, *dest
, *dest0
;
379 offset
= yy
* VIDEO_LINE_LEN
+ xx
* 2;
380 dest0
= video_fb_address
+ offset
;
382 fgx
= video_pickcolor (video_color_fg
);
383 bgx
= video_pickcolor (video_color_bg
);
392 switch (VIDEO_FONT_WIDTH
) {
397 cdat
= video_fontdata
+ c
* VIDEO_FONT_HEIGHT
;
398 for (rows
= VIDEO_FONT_HEIGHT
, dest
= dest0
;
400 dest
+= VIDEO_LINE_LEN
) {
404 (video_font_draw_table
[bits
>> 6] & eorx
) ^ bgx
;
406 (video_font_draw_table
[bits
>> 4 & 3] & eorx
) ^ bgx
;
407 if (VIDEO_FONT_WIDTH
== 8) {
409 (video_font_draw_table
[bits
>> 2 & 3] & eorx
) ^ bgx
;
411 (video_font_draw_table
[bits
& 3] & eorx
) ^ bgx
;
414 dest0
+= VIDEO_FONT_WIDTH
* 2;
421 cdat
= video_fontdata
+ (*s
) * (VIDEO_FONT_HEIGHT
<< 1);
422 for (rows
= VIDEO_FONT_HEIGHT
, dest
= dest0
; rows
--;
423 dest
+= VIDEO_LINE_LEN
) {
427 (video_font_draw_table
[bits
>> 6] & eorx
) ^ bgx
;
429 (video_font_draw_table
[bits
>> 4 & 3] & eorx
) ^ bgx
;
431 (video_font_draw_table
[bits
>> 2 & 3] & eorx
) ^ bgx
;
433 (video_font_draw_table
[bits
& 3] & eorx
) ^ bgx
;
436 (video_font_draw_table
[bits
>> 6] & eorx
) ^ bgx
;
438 (video_font_draw_table
[bits
>> 4 & 3] & eorx
) ^ bgx
;
439 if (VIDEO_FONT_WIDTH
== 16) {
441 (video_font_draw_table
[bits
>> 2 & 3] & eorx
) ^ bgx
;
443 (video_font_draw_table
[bits
& 3] & eorx
) ^ bgx
;
447 dest0
+= VIDEO_FONT_WIDTH
* 2;
453 static inline void video_drawstring (int xx
, int yy
, char *s
)
455 video_drawchars (xx
, yy
, (unsigned char *)s
, strlen (s
));
458 /* Relative to console plotting functions */
460 static void video_putchars (int xx
, int yy
, unsigned char *s
, int count
)
462 #ifdef CONFIG_VIDEO_LOGO
463 video_drawchars (xx
, yy
+ VIDEO_LOGO_HEIGHT
, s
, count
);
465 video_drawchars (xx
, yy
, s
, count
);
469 static void video_putchar (int xx
, int yy
, unsigned char c
)
471 #ifdef CONFIG_VIDEO_LOGO
472 video_drawchars (xx
, yy
+ VIDEO_LOGO_HEIGHT
, &c
, 1);
474 video_drawchars (xx
, yy
, &c
, 1);
478 static inline void video_putstring (int xx
, int yy
, unsigned char *s
)
480 video_putchars (xx
, yy
, (unsigned char *)s
, strlen ((char *)s
));
483 /************************************************************************/
484 /* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
485 /************************************************************************/
487 #if !defined(CONFIG_RRVISION)
488 static void video_mode_dupefield (VRAM
* source
, VRAM
* dest
, int entries
)
492 for (i
= 0; i
< entries
; i
++) {
493 dest
[i
] = source
[i
]; /* Copy the entire record */
494 dest
[i
].fx
= (!dest
[i
].fx
) * 3; /* Negate field bit */
497 dest
[0].lcyc
++; /* Add a cycle to the first entry */
498 dest
[entries
- 1].lst
= 1; /* Set end of ram entries */
502 static void inline video_mode_addentry (VRAM
* vr
,
503 int Hx
, int Vx
, int Fx
, int Bx
,
504 int VDS
, int INT
, int LCYC
, int LP
, int LST
)
517 #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)
519 static int video_mode_generate (void)
521 immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
522 VRAM
*vr
= (VRAM
*) (((void *) immap
) + 0xb00); /* Pointer to the VRAM table */
523 int DX
, X1
, X2
, DY
, Y1
, Y2
, entry
= 0, fifo
;
525 /* CHECKING PARAMETERS */
527 if (video_panning_factor_y
< -128)
528 video_panning_factor_y
= -128;
530 if (video_panning_factor_y
> 128)
531 video_panning_factor_y
= 128;
533 if (video_panning_factor_x
< -128)
534 video_panning_factor_x
= -128;
536 if (video_panning_factor_x
> 128)
537 video_panning_factor_x
= 128;
539 /* Setting panning */
541 DX
= video_panning_range_x
= (VIDEO_ACTIVE_COLS
- VIDEO_COLS
) * 2;
542 DY
= video_panning_range_y
= (VIDEO_ACTIVE_ROWS
- VIDEO_ROWS
) / 2;
544 video_panning_value_x
= (video_panning_factor_x
+ 128) * DX
/ 256;
545 video_panning_value_y
= (video_panning_factor_y
+ 128) * DY
/ 256;
547 /* We assume these are burst units (multiplied by 2, we need it pari) */
548 X1
= video_panning_value_x
& 0xfffe;
551 /* We assume these are field line units (divided by 2, we need it pari) */
552 Y1
= video_panning_value_y
& 0xfffe;
555 debug("X1=%d, X2=%d, Y1=%d, Y2=%d, DX=%d, DY=%d VIDEO_COLS=%d \n",
556 X1
, X2
, Y1
, Y2
, DX
, DY
, VIDEO_COLS
);
558 #ifdef VIDEO_MODE_NTSC
560 * Hx Vx Fx Bx VDS INT LCYC LP LST
564 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
565 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
566 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
567 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
571 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
572 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
573 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
574 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
576 * Odd field active area (TOP)
579 ADDENTRY (0, 0, 0, 0, 1, 0, Y1
, 1, 0);
580 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
581 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
582 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
585 * Odd field active area
587 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY
, 1, 0);
588 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
589 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1
, 0, 0);
590 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS
* 2, 0, 0);
593 ADDENTRY (3, 0, 0, 3, 1, 0, X2
, 0, 0);
595 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
598 * Odd field active area (BOTTOM)
601 ADDENTRY (0, 0, 0, 0, 1, 0, Y2
, 1, 0);
602 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
603 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
604 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
609 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
610 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
611 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
612 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
616 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
617 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
618 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
619 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
621 * Even field active area (TOP)
624 ADDENTRY (0, 0, 3, 0, 1, 0, Y1
, 1, 0);
625 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
626 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
627 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
630 * Even field active area (CENTER)
632 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY
, 1, 0);
633 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
634 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1
, 0, 0);
635 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS
* 2, 0, 0);
638 ADDENTRY (3, 0, 3, 3, 1, 0, X2
, 0, 0);
640 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
642 * Even field active area (BOTTOM)
645 ADDENTRY (0, 0, 3, 0, 1, 0, Y2
, 1, 0);
646 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
647 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
648 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
653 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
654 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
655 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
656 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
659 #ifdef VIDEO_MODE_PAL
661 #if defined(CONFIG_RRVISION)
663 #define HPW 160 /* horizontal pulse width (was 139) */
664 #define VPW 2 /* vertical pulse width */
665 #define HBP 104 /* horizontal back porch (was 112) */
666 #define VBP 19 /* vertical back porch (was 19) */
667 #define VID_R 240 /* number of rows */
669 debug ("[VIDEO CTRL] Starting to add controller entries...");
673 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
674 ADDENTRY (0, 0, 0, 3, 1, 0, HPW
, 0, 0);
675 ADDENTRY (3, 0, 0, 3, 1, 0, HBP
+ (VIDEO_COLS
* 2) + 72, 0, 0);
677 ADDENTRY (0, 0, 0, 3, 1, 0, VPW
, 1, 0);
678 ADDENTRY (0, 0, 0, 3, 1, 0, HPW
-1, 0, 0);
679 ADDENTRY (3, 0, 0, 3, 1, 0, HBP
+ (VIDEO_COLS
* 2) + 72, 1, 0);
681 ADDENTRY (0, 3, 0, 3, 1, 0, VBP
, 1, 0);
682 ADDENTRY (0, 3, 0, 3, 1, 0, HPW
-1, 0, 0);
683 ADDENTRY (3, 3, 0, 3, 1, 0, HBP
+ (VIDEO_COLS
* 2) + 72, 1, 0);
687 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R
, 1, 0);
688 ADDENTRY (0, 3, 0, 3, 1, 0, HPW
-1, 0, 0);
689 ADDENTRY (3, 3, 0, 3, 1, 0, HBP
, 0, 0);
690 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS
*2, 0, 0);
691 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
693 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
694 ADDENTRY (0, 3, 0, 3, 1, 0, HPW
-1, 0, 0);
695 ADDENTRY (3, 3, 0, 3, 1, 0, HBP
+(VIDEO_COLS
* 2) + 72 , 1, 0);
699 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
700 ADDENTRY (0, 0, 0, 3, 1, 0, HPW
, 0, 0);
701 ADDENTRY (3, 0, 0, 3, 1, 0, HBP
+ (VIDEO_COLS
* 2) + 72, 0, 0);
703 ADDENTRY (0, 0, 0, 3, 1, 0, VPW
+1, 1, 0);
704 ADDENTRY (0, 0, 0, 3, 1, 0, HPW
-1, 0, 0);
705 ADDENTRY (3, 0, 0, 3, 1, 0, HBP
+ (VIDEO_COLS
* 2) + 72, 1, 0);
707 ADDENTRY (0, 3, 0, 3, 1, 0, VBP
, 1, 0);
708 ADDENTRY (0, 3, 0, 3, 1, 0, HPW
-1, 0, 0);
709 ADDENTRY (3, 3, 0, 3, 1, 0, HBP
+ (VIDEO_COLS
* 2) + 72, 1, 0);
713 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R
, 1, 0);
714 ADDENTRY (0, 3, 0, 3, 1, 0, HPW
-1, 0, 0);
715 ADDENTRY (3, 3, 0, 3, 1, 0, HBP
, 0, 0);
716 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS
*2, 0, 0);
717 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
719 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
720 ADDENTRY (0, 3, 0, 3, 1, 0, HPW
-1, 0, 0);
721 ADDENTRY (3, 3, 0, 3, 1, 0, HBP
+(VIDEO_COLS
* 2) + 72 , 1, 0);
725 #else /* !CONFIG_RRVISION */
728 * Hx Vx Fx Bx VDS INT LCYC LP LST
732 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
733 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
734 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
735 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
740 ADDENTRY (0, 0, 0, 0, 1, 0, Y1
, 1, 0); /* 11? */
741 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
742 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
743 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
746 * field active area (CENTER)
748 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY
, 1, 0); /* 265? */
749 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
750 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1
, 0, 0);
751 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS
* 2, 0, 0);
754 ADDENTRY (3, 0, 0, 1, 1, 0, X2
, 0, 0);
756 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
758 * field active area (BOTTOM)
761 ADDENTRY (0, 0, 0, 0, 1, 0, Y2
, 1, 0); /* 12? */
762 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
763 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
764 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
767 * field vertical; blanking
769 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
770 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
771 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
772 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
774 * Create the other field (like this, but whit other field selected,
775 * one more cycle loop and a last identifier)
777 video_mode_dupefield (vr
, &vr
[entry
], entry
);
778 #endif /* CONFIG_RRVISION */
780 #endif /* VIDEO_MODE_PAL */
782 /* See what FIFO are we using */
783 fifo
= GETBIT (immap
->im_vid
.vid_vsr
, VIDEO_VSR_CAS
);
785 /* Set number of lines and burst (only one frame for now) */
787 immap
->im_vid
.vid_vfcr0
= VIDEO_BURST_LEN
|
788 (VIDEO_BURST_LEN
<< 8) | ((VIDEO_ROWS
/ 2) << 19);
790 immap
->im_vid
.vid_vfcr1
= VIDEO_BURST_LEN
|
791 (VIDEO_BURST_LEN
<< 8) | ((VIDEO_ROWS
/ 2) << 19);
794 SETBIT (immap
->im_vid
.vid_vcmr
, VIDEO_VCMR_ASEL
, !fifo
);
797 * Wait until changes are applied (not done)
798 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
801 /* Return number of VRAM entries */
805 static void video_encoder_init (void)
810 /* Initialize the I2C */
811 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
812 i2c_init (CONFIG_SYS_I2C_SPEED
, CONFIG_SYS_I2C_SLAVE
);
815 /* Reset ADV7176 chip */
816 debug ("[VIDEO ENCODER] Resetting encoder...\n");
817 (*(int *) BCSR4
) &= ~(1 << 21);
819 /* Wait for 5 ms inside the reset */
820 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
823 /* Take ADV7176 out of reset */
824 (*(int *) BCSR4
) |= 1 << 21;
826 /* Wait for 5 ms after the reset */
828 #endif /* CONFIG_FADS */
830 /* Send configuration */
835 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
837 printf ("Sending %zu bytes (@ %08lX) to I2C 0x%lX:\n ",
838 sizeof(video_encoder_data
),
839 (ulong
)video_encoder_data
,
840 (ulong
)VIDEO_I2C_ADDR
);
841 for (i
=0; i
<sizeof(video_encoder_data
); ++i
) {
842 printf(" %02X", video_encoder_data
[i
]);
848 if ((rc
= i2c_write (VIDEO_I2C_ADDR
, 0, 1,
850 sizeof(video_encoder_data
))) != 0) {
851 printf ("i2c_send error: rc=%d\n", rc
);
854 #endif /* VIDEO_I2C */
858 static void video_ctrl_init (void *memptr
)
860 immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
862 video_fb_address
= memptr
;
865 debug ("[VIDEO CTRL] Setting background color...\n");
866 immap
->im_vid
.vid_vbcb
= VIDEO_BG_COL
;
868 /* Show the background */
869 debug ("[VIDEO CTRL] Forcing background...\n");
870 SETBIT (immap
->im_vid
.vid_vcmr
, VIDEO_VCMR_BD
, 1);
872 /* Turn off video controller */
873 debug ("[VIDEO CTRL] Turning off video controller...\n");
874 SETBIT (immap
->im_vid
.vid_vccr
, VIDEO_VCCR_VON
, 0);
877 /* Turn on Video Port LED */
878 debug ("[VIDEO CTRL] Turning off video port led...\n");
879 SETBIT (*(int *) BCSR4
, VIDEO_BCSR4_VIDLED_BIT
, 1);
881 /* Disable internal clock */
882 debug ("[VIDEO CTRL] Disabling internal clock...\n");
883 SETBIT (*(int *) BCSR4
, VIDEO_BCSR4_EXTCLK_BIT
, 0);
886 /* Generate and make active a new video mode */
887 debug ("[VIDEO CTRL] Generating video mode...\n");
888 video_mode_generate ();
890 /* Start of frame buffer (even and odd frame, to make it working with */
891 /* any selected active set) */
892 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
893 immap
->im_vid
.vid_vfaa1
=
894 immap
->im_vid
.vid_vfaa0
= (u32
) video_fb_address
;
895 immap
->im_vid
.vid_vfba1
=
896 immap
->im_vid
.vid_vfba0
=
897 (u32
) video_fb_address
+ VIDEO_LINE_LEN
;
899 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
900 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
901 immap
->im_vid
.vid_vccr
= 0x2042;
903 /* Configure port pins */
904 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
905 immap
->im_ioport
.iop_pdpar
= 0x1fff;
906 immap
->im_ioport
.iop_pddir
= 0x0000;
909 /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
910 debug ("[VIDEO CTRL] Turning on video clock...\n");
911 SETBIT (*(int *) BCSR4
, VIDEO_BCSR4_EXTCLK_BIT
, 1);
913 /* Turn on Video Port LED */
914 debug ("[VIDEO CTRL] Turning on video port led...\n");
915 SETBIT (*(int *) BCSR4
, VIDEO_BCSR4_VIDLED_BIT
, 0);
917 #ifdef CONFIG_RRVISION
918 debug ("PC5->Output(1): enable PAL clock");
919 immap
->im_ioport
.iop_pcpar
&= ~(0x0400);
920 immap
->im_ioport
.iop_pcdir
|= 0x0400 ;
921 immap
->im_ioport
.iop_pcdat
|= 0x0400 ;
922 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
923 immap
->im_ioport
.iop_pdpar
,
924 immap
->im_ioport
.iop_pddir
,
925 immap
->im_ioport
.iop_pddat
);
926 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
927 immap
->im_ioport
.iop_pcpar
,
928 immap
->im_ioport
.iop_pcdir
,
929 immap
->im_ioport
.iop_pcdat
);
930 #endif /* CONFIG_RRVISION */
932 /* Blanking the screen. */
933 debug ("[VIDEO CTRL] Blanking the screen...\n");
934 video_fill (VIDEO_BG_COL
);
937 * Turns on Aggressive Mode. Normally, turning on the caches
938 * will cause the screen to flicker when the caches try to
939 * fill. This gives the FIFO's for the Video Controller
940 * higher priority and prevents flickering because of
941 * underrun. This may still be an issue when using FLASH,
942 * since accessing data from Flash is so slow.
944 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
945 immap
->im_siu_conf
.sc_sdcr
= 0x40;
947 /* Turn on video controller */
948 debug ("[VIDEO CTRL] Turning on video controller...\n");
949 SETBIT (immap
->im_vid
.vid_vccr
, VIDEO_VCCR_VON
, 1);
951 /* Show the display */
952 debug ("[VIDEO CTRL] Enabling the video...\n");
953 SETBIT (immap
->im_vid
.vid_vcmr
, VIDEO_VCMR_BD
, 0);
956 /************************************************************************/
957 /* ** CONSOLE FUNCTIONS */
958 /************************************************************************/
960 static void console_scrollup (void)
962 /* Copy up rows ignoring the first one */
963 memcpyl (CONSOLE_ROW_FIRST
, CONSOLE_ROW_SECOND
, CONSOLE_SCROLL_SIZE
>> 2);
965 /* Clear the last one */
966 memsetl (CONSOLE_ROW_LAST
, CONSOLE_ROW_SIZE
>> 2, VIDEO_BG_COL
);
969 static inline void console_back (void)
973 if (console_col
< 0) {
974 console_col
= CONSOLE_COLS
- 1;
980 video_putchar ( console_col
* VIDEO_FONT_WIDTH
,
981 console_row
* VIDEO_FONT_HEIGHT
, ' ');
984 static inline void console_newline (void)
989 /* Check if we need to scroll the terminal */
990 if (console_row
>= CONSOLE_ROWS
) {
991 /* Scroll everything up */
994 /* Decrement row number */
999 void video_putc (const char c
)
1001 if (!video_enable
) {
1007 case 13: /* Simply ignore this */
1010 case '\n': /* Next line, please */
1014 case 9: /* Tab (8 chars alignment) */
1015 console_col
|= 0x0008; /* Next 8 chars boundary */
1016 console_col
&= ~0x0007; /* Set this bit to zero */
1018 if (console_col
>= CONSOLE_COLS
)
1022 case 8: /* Eat last character */
1026 default: /* Add to the console */
1027 video_putchar ( console_col
* VIDEO_FONT_WIDTH
,
1028 console_row
* VIDEO_FONT_HEIGHT
, c
);
1030 /* Check if we need to go to next row */
1031 if (console_col
>= CONSOLE_COLS
)
1036 void video_puts (const char *s
)
1038 int count
= strlen (s
);
1048 /************************************************************************/
1049 /* ** CURSOR BLINKING FUNCTIONS */
1050 /************************************************************************/
1054 #define BLINK_TIMER_ID 0
1055 #define BLINK_TIMER_HZ 2
1057 static unsigned char blink_enabled
= 0;
1058 static timer_t blink_timer
;
1060 static void blink_update (void)
1062 static int blink_row
= -1, blink_col
= -1, blink_old
= 0;
1064 /* Check if we have a new position to invert */
1065 if ((console_row
!= blink_row
) || (console_col
!= blink_col
)) {
1066 /* Check if we need to reverse last character */
1068 video_revchar ( blink_col
* VIDEO_FONT_WIDTH
,
1070 #ifdef CONFIG_VIDEO_LOGO
1073 ) * VIDEO_FONT_HEIGHT
);
1076 blink_row
= console_row
;
1077 blink_col
= console_col
;
1081 /* Reverse this character */
1082 blink_old
= !blink_old
;
1083 video_revchar ( console_col
* VIDEO_FONT_WIDTH
,
1085 #ifdef CONFIG_VIDEO_LOGO
1088 ) * VIDEO_FONT_HEIGHT
);
1093 * Handler for blinking cursor
1095 static void blink_handler (void *arg
)
1100 timer_ack (&blink_timer
);
1103 int blink_set (int blink
)
1105 int ret
= blink_enabled
;
1108 timer_enable (&blink_timer
);
1110 timer_disable (&blink_timer
);
1112 blink_enabled
= blink
;
1117 static inline void blink_close (void)
1119 timer_close (&blink_timer
);
1122 static inline void blink_init (void)
1124 timer_init (&blink_timer
,
1125 BLINK_TIMER_ID
, BLINK_TIMER_HZ
,
1130 /************************************************************************/
1131 /* ** LOGO PLOTTING FUNCTIONS */
1132 /************************************************************************/
1134 #ifdef CONFIG_VIDEO_LOGO
1135 void easylogo_plot (fastimage_t
* image
, void *screen
, int width
, int x
,
1138 int skip
= width
- image
->width
, xcount
, ycount
= image
->height
;
1140 #ifdef VIDEO_MODE_YUYV
1141 ushort
*source
= (ushort
*) image
->data
;
1142 ushort
*dest
= (ushort
*) screen
+ y
* width
+ x
;
1145 xcount
= image
->width
;
1147 *dest
++ = *source
++;
1151 #ifdef VIDEO_MODE_RGB
1153 *source
= (unsigned short *) image
->data
,
1154 *dest
= (unsigned short *) screen
+ ((y
* width
) + x
) * 3;
1157 xcount
= image
->width
* 3;
1158 memcpy (dest
, source
, xcount
);
1165 static void *video_logo (void)
1167 u16
*screen
= video_fb_address
, width
= VIDEO_COLS
;
1169 # ifndef CONFIG_FADS
1173 #endif /* VIDEO_INFO */
1175 easylogo_plot (VIDEO_LOGO_ADDR
, screen
, width
, 0, 0);
1178 sprintf (info
, "%s (%s - %s) ",
1179 U_BOOT_VERSION
, U_BOOT_DATE
, U_BOOT_TIME
);
1180 video_drawstring (VIDEO_INFO_X
, VIDEO_INFO_Y
, info
);
1182 sprintf (info
, "(C) 2002 DENX Software Engineering");
1183 video_drawstring (VIDEO_INFO_X
, VIDEO_INFO_Y
+ VIDEO_FONT_HEIGHT
,
1186 sprintf (info
, " Wolfgang DENK, wd@denx.de");
1187 video_drawstring (VIDEO_INFO_X
, VIDEO_INFO_Y
+ VIDEO_FONT_HEIGHT
* 2,
1189 #ifndef CONFIG_FADS /* all normal boards */
1190 /* leave one blank line */
1192 sprintf (info
, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1193 strmhz(temp
, gd
->cpu_clk
),
1195 gd
->bd
->bi_flashsize
>> 20 );
1196 video_drawstring (VIDEO_INFO_X
, VIDEO_INFO_Y
+ VIDEO_FONT_HEIGHT
* 4,
1198 #else /* FADS :-( */
1199 sprintf (info
, "MPC823 CPU at 50 MHz on FADS823 board");
1200 video_drawstring (VIDEO_INFO_X
, VIDEO_INFO_Y
+ VIDEO_FONT_HEIGHT
,
1203 sprintf (info
, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1204 video_drawstring (VIDEO_INFO_X
, VIDEO_INFO_Y
+ VIDEO_FONT_HEIGHT
* 2,
1209 return video_fb_address
+ VIDEO_LOGO_HEIGHT
* VIDEO_LINE_LEN
;
1213 /************************************************************************/
1214 /* ** VIDEO HIGH-LEVEL FUNCTIONS */
1215 /************************************************************************/
1217 static int video_init (void *videobase
)
1219 /* Initialize the encoder */
1220 debug ("[VIDEO] Initializing video encoder...\n");
1221 video_encoder_init ();
1223 /* Initialize the video controller */
1224 debug ("[VIDEO] Initializing video controller at %08x...\n",
1226 video_ctrl_init (videobase
);
1228 /* Setting the palette */
1229 video_setpalette (CONSOLE_COLOR_BLACK
, 0, 0, 0);
1230 video_setpalette (CONSOLE_COLOR_RED
, 0xFF, 0, 0);
1231 video_setpalette (CONSOLE_COLOR_GREEN
, 0, 0xFF, 0);
1232 video_setpalette (CONSOLE_COLOR_YELLOW
, 0xFF, 0xFF, 0);
1233 video_setpalette (CONSOLE_COLOR_BLUE
, 0, 0, 0xFF);
1234 video_setpalette (CONSOLE_COLOR_MAGENTA
, 0xFF, 0, 0xFF);
1235 video_setpalette (CONSOLE_COLOR_CYAN
, 0, 0xFF, 0xFF);
1236 video_setpalette (CONSOLE_COLOR_GREY
, 0xAA, 0xAA, 0xAA);
1237 video_setpalette (CONSOLE_COLOR_GREY2
, 0xF8, 0xF8, 0xF8);
1238 video_setpalette (CONSOLE_COLOR_WHITE
, 0xFF, 0xFF, 0xFF);
1240 #ifndef CONFIG_SYS_WHITE_ON_BLACK
1241 video_setfgcolor (CONSOLE_COLOR_BLACK
);
1242 video_setbgcolor (CONSOLE_COLOR_GREY2
);
1244 video_setfgcolor (CONSOLE_COLOR_GREY2
);
1245 video_setbgcolor (CONSOLE_COLOR_BLACK
);
1246 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
1248 #ifdef CONFIG_VIDEO_LOGO
1249 /* Paint the logo and retrieve tv base address */
1250 debug ("[VIDEO] Drawing the logo...\n");
1251 video_console_address
= video_logo ();
1253 video_console_address
= video_fb_address
;
1257 /* Enable the blinking (under construction) */
1259 blink_set (0); /* To Fix! */
1262 /* Initialize the console */
1267 #ifdef VIDEO_MODE_PAL
1268 # define VIDEO_MODE_TMP1 "PAL"
1270 #ifdef VIDEO_MODE_NTSC
1271 # define VIDEO_MODE_TMP1 "NTSC"
1273 #ifdef VIDEO_MODE_YUYV
1274 # define VIDEO_MODE_TMP2 "YCbYCr"
1276 #ifdef VIDEO_MODE_RGB
1277 # define VIDEO_MODE_TMP2 "RGB"
1279 debug ( VIDEO_MODE_TMP1
1280 " %dx%dx%d (" VIDEO_MODE_TMP2
") on %s - console %dx%d\n",
1281 VIDEO_COLS
, VIDEO_ROWS
, VIDEO_MODE_BPP
,
1282 VIDEO_ENCODER_NAME
, CONSOLE_COLS
, CONSOLE_ROWS
);
1286 int drv_video_init (void)
1288 int error
, devices
= 1;
1290 struct stdio_dev videodev
;
1292 video_init ((void *)(gd
->fb_base
)); /* Video initialization */
1294 /* Device initialization */
1296 memset (&videodev
, 0, sizeof (videodev
));
1298 strcpy (videodev
.name
, "video");
1299 videodev
.ext
= DEV_EXT_VIDEO
; /* Video extensions */
1300 videodev
.flags
= DEV_FLAGS_OUTPUT
; /* Output only */
1301 videodev
.putc
= video_putc
; /* 'putc' function */
1302 videodev
.puts
= video_puts
; /* 'puts' function */
1304 error
= stdio_register (&videodev
);
1306 return (error
== 0) ? devices
: error
;
1309 /************************************************************************/
1310 /* ** ROM capable initialization part - needed to reserve FB memory */
1311 /************************************************************************/
1314 * This is called early in the system initialization to grab memory
1315 * for the video controller.
1316 * Returns new address for monitor, after reserving video buffer memory
1318 * Note that this is running from ROM, so no write access to global data.
1320 ulong
video_setmem (ulong addr
)
1322 /* Allocate pages for the frame buffer. */
1325 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1326 VIDEO_SIZE
>>10, addr
);