1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <stdarg.h>
33#include <common.h>
34#include <config.h>
35#include <version.h>
36#include <i2c.h>
37#include <linux/types.h>
38#include <stdio_dev.h>
39
40#ifdef CONFIG_VIDEO
41
42DECLARE_GLOBAL_DATA_PTR;
43
44
45
46
47
48#if 0
49#define VIDEO_DEBUG_COLORBARS
50#endif
51
52
53
54
55
56#if 0
57#define VIDEO_MODE_EXTENDED
58#define VIDEO_MODE_NTSC
59#endif
60
61#define VIDEO_MODE_PAL
62
63#if 0
64#define VIDEO_BLINK
65#endif
66
67#define VIDEO_INFO
68#define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
69#define VIDEO_INFO_Y 16
70
71
72
73
74
75#ifdef CONFIG_VIDEO_ENCODER_AD7176
76
77#include <video_ad7176.h>
78
79#define VIDEO_I2C 1
80#define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
81#endif
82
83#ifdef CONFIG_VIDEO_ENCODER_AD7177
84
85#include <video_ad7177.h>
86
87#define VIDEO_I2C 1
88#define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
89#endif
90
91#ifdef CONFIG_VIDEO_ENCODER_AD7179
92
93#include <video_ad7179.h>
94
95#define VIDEO_I2C 1
96#define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
97#endif
98
99
100
101
102
103#ifdef VIDEO_MODE_EXTENDED
104#define VIDEO_COLS VIDEO_ACTIVE_COLS
105#define VIDEO_ROWS VIDEO_ACTIVE_ROWS
106#else
107#define VIDEO_COLS VIDEO_VISIBLE_COLS
108#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
109#endif
110
111#define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
112#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
113#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
114#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
115#define VIDEO_BURST_LEN (VIDEO_COLS/8)
116
117#ifdef VIDEO_MODE_YUYV
118#define VIDEO_BG_COL 0x80D880D8
119#else
120#define VIDEO_BG_COL 0xF8F8F8F8
121#endif
122
123
124
125
126
127#include <video_font.h>
128#include <video_font_data.h>
129
130#ifdef CONFIG_VIDEO_LOGO
131#include <video_logo.h>
132
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
136#endif
137
138
139
140
141
142
143
144#define VIDEO_VCCR_VON 0
145#define VIDEO_VCCR_CSRC 1
146#define VIDEO_VCCR_PDF 13
147#define VIDEO_VCCR_IEN 11
148
149
150
151#define VIDEO_VSR_CAS 6
152#define VIDEO_VSR_EOF 0
153
154
155
156#define VIDEO_VCMR_BD 0
157#define VIDEO_VCMR_ASEL 1
158
159
160
161#define VIDEO_BCSR4_RESET_BIT 21
162#define VIDEO_BCSR4_EXTCLK_BIT 22
163#define VIDEO_BCSR4_VIDLED_BIT 23
164
165
166
167
168
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)
172#else
173#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
174#endif
175
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)
183
184
185
186
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
197
198
199
200
201
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)))
214
215
216
217
218
219typedef struct {
220 unsigned char V, Y1, U, Y2;
221} tYUYV;
222
223
224typedef struct VRAM {
225 unsigned hx:2,
226 vx:2,
227 fx:2,
228 bx:2,
229 res1:6,
230 vds:2,
231 inter:1,
232 res2:2,
233 lcyc:11,
234 lp:1,
235 lst:1;
236} VRAM;
237
238
239
240
241
242static int
243 video_panning_range_x = 0,
244 video_panning_range_y = 0,
245 video_panning_value_x = 0,
246 video_panning_value_y = 0,
247 video_panning_factor_x = 0,
248 video_panning_factor_y = 0,
249 console_col = 0,
250 console_row = 0,
251 video_palette[16];
252
253static const int video_font_draw_table[] =
254 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
255
256static char
257 video_color_fg = 0,
258 video_color_bg = 0,
259 video_enable = 0;
260
261static void
262 *video_fb_address,
263 *video_console_address;
264
265
266
267
268
269static void memsetl (int *p, int c, int v)
270{
271 while (c--)
272 *(p++) = v;
273}
274
275static void memcpyl (int *d, int *s, int c)
276{
277 while (c--)
278 *(d++) = *(s++);
279}
280
281
282
283
284
285static int video_maprgb (int r, int g, int b)
286{
287#ifdef VIDEO_MODE_YUYV
288 unsigned int pR, pG, pB;
289 tYUYV YUYV;
290 unsigned int *ret = (unsigned int *) &YUYV;
291
292
293
294 pR = r * 100 / 255;
295 pG = g * 100 / 255;
296 pB = b * 100 / 255;
297
298
299
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;
303 return *ret;
304#endif
305#ifdef VIDEO_MODE_RGB
306 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
307#endif
308}
309
310static void video_setpalette (int color, int r, int g, int b)
311{
312 color &= 0xf;
313
314 video_palette[color] = video_maprgb (r, g, b);
315
316
317 if (video_panning_value_x & 1)
318 video_palette[color] = SWAPINT (video_palette[color]);
319}
320
321static void video_fill (int color)
322{
323 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
324}
325
326static void video_setfgcolor (int i)
327{
328 video_color_fg = i & 0xf;
329}
330
331static void video_setbgcolor (int i)
332{
333 video_color_bg = i & 0xf;
334}
335
336static int video_pickcolor (int i)
337{
338 return video_palette[i & 0xf];
339}
340
341
342
343#ifdef VIDEO_BLINK
344static void video_revchar (int xx, int yy)
345{
346 int rows;
347 u8 *dest;
348
349 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
350
351 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
352 switch (VIDEO_FONT_WIDTH) {
353 case 16:
354 ((u32 *) dest)[6] ^= 0xffffffff;
355 ((u32 *) dest)[7] ^= 0xffffffff;
356
357 case 12:
358 ((u32 *) dest)[4] ^= 0xffffffff;
359 ((u32 *) dest)[5] ^= 0xffffffff;
360
361 case 8:
362 ((u32 *) dest)[2] ^= 0xffffffff;
363 ((u32 *) dest)[3] ^= 0xffffffff;
364
365 case 4:
366 ((u32 *) dest)[0] ^= 0xffffffff;
367 ((u32 *) dest)[1] ^= 0xffffffff;
368 }
369 }
370}
371#endif
372
373static void video_drawchars (int xx, int yy, unsigned char *s, int count)
374{
375 u8 *cdat, *dest, *dest0;
376 int rows, offset, c;
377 u32 eorx, fgx, bgx;
378
379 offset = yy * VIDEO_LINE_LEN + xx * 2;
380 dest0 = video_fb_address + offset;
381
382 fgx = video_pickcolor (video_color_fg);
383 bgx = video_pickcolor (video_color_bg);
384
385 if (xx & 1) {
386 fgx = SWAPINT (fgx);
387 bgx = SWAPINT (bgx);
388 }
389
390 eorx = fgx ^ bgx;
391
392 switch (VIDEO_FONT_WIDTH) {
393 case 4:
394 case 8:
395 while (count--) {
396 c = *s;
397 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
398 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
399 rows--;
400 dest += VIDEO_LINE_LEN) {
401 u8 bits = *cdat++;
402
403 ((u32 *) dest)[0] =
404 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
405 ((u32 *) dest)[1] =
406 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
407 if (VIDEO_FONT_WIDTH == 8) {
408 ((u32 *) dest)[2] =
409 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
410 ((u32 *) dest)[3] =
411 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
412 }
413 }
414 dest0 += VIDEO_FONT_WIDTH * 2;
415 s++;
416 }
417 break;
418 case 12:
419 case 16:
420 while (count--) {
421 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
422 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
423 dest += VIDEO_LINE_LEN) {
424 u8 bits = *cdat++;
425
426 ((u32 *) dest)[0] =
427 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
428 ((u32 *) dest)[1] =
429 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
430 ((u32 *) dest)[2] =
431 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
432 ((u32 *) dest)[3] =
433 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
434 bits = *cdat++;
435 ((u32 *) dest)[4] =
436 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
437 ((u32 *) dest)[5] =
438 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
439 if (VIDEO_FONT_WIDTH == 16) {
440 ((u32 *) dest)[6] =
441 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
442 ((u32 *) dest)[7] =
443 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
444 }
445 }
446 s++;
447 dest0 += VIDEO_FONT_WIDTH * 2;
448 }
449 break;
450 }
451}
452
453static inline void video_drawstring (int xx, int yy, char *s)
454{
455 video_drawchars (xx, yy, (unsigned char *)s, strlen (s));
456}
457
458
459
460static void video_putchars (int xx, int yy, unsigned char *s, int count)
461{
462#ifdef CONFIG_VIDEO_LOGO
463 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
464#else
465 video_drawchars (xx, yy, s, count);
466#endif
467}
468
469static void video_putchar (int xx, int yy, unsigned char c)
470{
471#ifdef CONFIG_VIDEO_LOGO
472 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
473#else
474 video_drawchars (xx, yy, &c, 1);
475#endif
476}
477
478static inline void video_putstring (int xx, int yy, unsigned char *s)
479{
480 video_putchars (xx, yy, (unsigned char *)s, strlen ((char *)s));
481}
482
483
484
485
486
487#if !defined(CONFIG_RRVISION)
488static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
489{
490 int i;
491
492 for (i = 0; i < entries; i++) {
493 dest[i] = source[i];
494 dest[i].fx = (!dest[i].fx) * 3;
495 }
496
497 dest[0].lcyc++;
498 dest[entries - 1].lst = 1;
499}
500#endif
501
502static 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)
505{
506 vr->hx = Hx;
507 vr->vx = Vx;
508 vr->fx = Fx;
509 vr->bx = Bx;
510 vr->vds = VDS;
511 vr->inter = INT;
512 vr->lcyc = LCYC;
513 vr->lp = LP;
514 vr->lst = LST;
515}
516
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)
518
519static int video_mode_generate (void)
520{
521 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
522 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00);
523 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
524
525
526
527 if (video_panning_factor_y < -128)
528 video_panning_factor_y = -128;
529
530 if (video_panning_factor_y > 128)
531 video_panning_factor_y = 128;
532
533 if (video_panning_factor_x < -128)
534 video_panning_factor_x = -128;
535
536 if (video_panning_factor_x > 128)
537 video_panning_factor_x = 128;
538
539
540
541 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
542 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
543
544 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
545 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
546
547
548 X1 = video_panning_value_x & 0xfffe;
549 X2 = DX - X1;
550
551
552 Y1 = video_panning_value_y & 0xfffe;
553 Y2 = DY - Y1;
554
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);
557
558#ifdef VIDEO_MODE_NTSC
559
560
561
562
563
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);
568
569
570
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);
575
576
577
578 if (Y1 > 0) {
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);
583 }
584
585
586
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);
591
592 if (X2 > 0)
593 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
594
595 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
596
597
598
599
600 if (Y1 > 0) {
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);
605 }
606
607
608
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);
613
614
615
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);
620
621
622
623 if (Y1 > 0) {
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);
628 }
629
630
631
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);
636
637 if (X2 > 0)
638 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
639
640 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
641
642
643
644 if (Y1 > 0) {
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);
649 }
650
651
652
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);
657#endif
658
659#ifdef VIDEO_MODE_PAL
660
661#if defined(CONFIG_RRVISION)
662
663#define HPW 160
664#define VPW 2
665#define HBP 104
666#define VBP 19
667#define VID_R 240
668
669 debug ("[VIDEO CTRL] Starting to add controller entries...");
670
671
672
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);
676
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);
680
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);
684
685
686
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);
692
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);
696
697
698
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);
702
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);
706
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);
710
711
712
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);
718
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);
722
723 debug ("done\n");
724
725#else
726
727
728
729
730
731
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);
736
737
738
739 if (Y1 > 0) {
740 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
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);
744 }
745
746
747
748 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0);
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);
752
753 if (X2 > 0)
754 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
755
756 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
757
758
759
760 if (Y2 > 0) {
761 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
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);
765 }
766
767
768
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);
773
774
775
776
777 video_mode_dupefield (vr, &vr[entry], entry);
778#endif
779
780#endif
781
782
783 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
784
785
786 if (fifo) {
787 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
788 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
789 } else {
790 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
791 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
792 }
793
794 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
795
796
797
798
799
800
801
802 return entry * 2;
803}
804
805static void video_encoder_init (void)
806{
807#ifdef VIDEO_I2C
808 int rc;
809
810
811 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
812 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
813
814#ifdef CONFIG_FADS
815
816 debug ("[VIDEO ENCODER] Resetting encoder...\n");
817 (*(int *) BCSR4) &= ~(1 << 21);
818
819
820 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
821 udelay (5000);
822
823
824 (*(int *) BCSR4) |= 1 << 21;
825
826
827 udelay (5000);
828#endif
829
830
831#ifdef DEBUG
832 {
833 int i;
834
835 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
836
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]);
843 }
844 putc ('\n');
845 }
846#endif
847
848 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
849 video_encoder_data,
850 sizeof(video_encoder_data))) != 0) {
851 printf ("i2c_send error: rc=%d\n", rc);
852 return;
853 }
854#endif
855 return;
856}
857
858static void video_ctrl_init (void *memptr)
859{
860 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
861
862 video_fb_address = memptr;
863
864
865 debug ("[VIDEO CTRL] Setting background color...\n");
866 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
867
868
869 debug ("[VIDEO CTRL] Forcing background...\n");
870 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
871
872
873 debug ("[VIDEO CTRL] Turning off video controller...\n");
874 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
875
876#ifdef CONFIG_FADS
877
878 debug ("[VIDEO CTRL] Turning off video port led...\n");
879 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
880
881
882 debug ("[VIDEO CTRL] Disabling internal clock...\n");
883 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
884#endif
885
886
887 debug ("[VIDEO CTRL] Generating video mode...\n");
888 video_mode_generate ();
889
890
891
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;
898
899
900 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
901 immap->im_vid.vid_vccr = 0x2042;
902
903
904 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
905 immap->im_ioport.iop_pdpar = 0x1fff;
906 immap->im_ioport.iop_pddir = 0x0000;
907
908#ifdef CONFIG_FADS
909
910 debug ("[VIDEO CTRL] Turning on video clock...\n");
911 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
912
913
914 debug ("[VIDEO CTRL] Turning on video port led...\n");
915 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
916#endif
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
931
932
933 debug ("[VIDEO CTRL] Blanking the screen...\n");
934 video_fill (VIDEO_BG_COL);
935
936
937
938
939
940
941
942
943
944 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
945 immap->im_siu_conf.sc_sdcr = 0x40;
946
947
948 debug ("[VIDEO CTRL] Turning on video controller...\n");
949 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
950
951
952 debug ("[VIDEO CTRL] Enabling the video...\n");
953 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
954}
955
956
957
958
959
960static void console_scrollup (void)
961{
962
963 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
964
965
966 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
967}
968
969static inline void console_back (void)
970{
971 console_col--;
972
973 if (console_col < 0) {
974 console_col = CONSOLE_COLS - 1;
975 console_row--;
976 if (console_row < 0)
977 console_row = 0;
978 }
979
980 video_putchar ( console_col * VIDEO_FONT_WIDTH,
981 console_row * VIDEO_FONT_HEIGHT, ' ');
982}
983
984static inline void console_newline (void)
985{
986 console_row++;
987 console_col = 0;
988
989
990 if (console_row >= CONSOLE_ROWS) {
991
992 console_scrollup ();
993
994
995 console_row--;
996 }
997}
998
999void video_putc (const char c)
1000{
1001 if (!video_enable) {
1002 serial_putc (c);
1003 return;
1004 }
1005
1006 switch (c) {
1007 case 13:
1008 break;
1009
1010 case '\n':
1011 console_newline ();
1012 break;
1013
1014 case 9:
1015 console_col |= 0x0008;
1016 console_col &= ~0x0007;
1017
1018 if (console_col >= CONSOLE_COLS)
1019 console_newline ();
1020 break;
1021
1022 case 8:
1023 console_back ();
1024 break;
1025
1026 default:
1027 video_putchar ( console_col * VIDEO_FONT_WIDTH,
1028 console_row * VIDEO_FONT_HEIGHT, c);
1029 console_col++;
1030
1031 if (console_col >= CONSOLE_COLS)
1032 console_newline ();
1033 }
1034}
1035
1036void video_puts (const char *s)
1037{
1038 int count = strlen (s);
1039
1040 if (!video_enable)
1041 while (count--)
1042 serial_putc (*s++);
1043 else
1044 while (count--)
1045 video_putc (*s++);
1046}
1047
1048
1049
1050
1051
1052#ifdef VIDEO_BLINK
1053
1054#define BLINK_TIMER_ID 0
1055#define BLINK_TIMER_HZ 2
1056
1057static unsigned char blink_enabled = 0;
1058static timer_t blink_timer;
1059
1060static void blink_update (void)
1061{
1062 static int blink_row = -1, blink_col = -1, blink_old = 0;
1063
1064
1065 if ((console_row != blink_row) || (console_col != blink_col)) {
1066
1067 if (blink_old)
1068 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1069 (blink_row
1070#ifdef CONFIG_VIDEO_LOGO
1071 + VIDEO_LOGO_HEIGHT
1072#endif
1073 ) * VIDEO_FONT_HEIGHT);
1074
1075
1076 blink_row = console_row;
1077 blink_col = console_col;
1078 blink_old = 0;
1079 }
1080
1081
1082 blink_old = !blink_old;
1083 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1084 (console_row
1085#ifdef CONFIG_VIDEO_LOGO
1086 + VIDEO_LOGO_HEIGHT
1087#endif
1088 ) * VIDEO_FONT_HEIGHT);
1089
1090}
1091
1092
1093
1094
1095static void blink_handler (void *arg)
1096{
1097
1098 blink_update ();
1099
1100 timer_ack (&blink_timer);
1101}
1102
1103int blink_set (int blink)
1104{
1105 int ret = blink_enabled;
1106
1107 if (blink)
1108 timer_enable (&blink_timer);
1109 else
1110 timer_disable (&blink_timer);
1111
1112 blink_enabled = blink;
1113
1114 return ret;
1115}
1116
1117static inline void blink_close (void)
1118{
1119 timer_close (&blink_timer);
1120}
1121
1122static inline void blink_init (void)
1123{
1124 timer_init (&blink_timer,
1125 BLINK_TIMER_ID, BLINK_TIMER_HZ,
1126 blink_handler);
1127}
1128#endif
1129
1130
1131
1132
1133
1134#ifdef CONFIG_VIDEO_LOGO
1135void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1136 int y)
1137{
1138 int skip = width - image->width, xcount, ycount = image->height;
1139
1140#ifdef VIDEO_MODE_YUYV
1141 ushort *source = (ushort *) image->data;
1142 ushort *dest = (ushort *) screen + y * width + x;
1143
1144 while (ycount--) {
1145 xcount = image->width;
1146 while (xcount--)
1147 *dest++ = *source++;
1148 dest += skip;
1149 }
1150#endif
1151#ifdef VIDEO_MODE_RGB
1152 unsigned char
1153 *source = (unsigned short *) image->data,
1154 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1155
1156 while (ycount--) {
1157 xcount = image->width * 3;
1158 memcpy (dest, source, xcount);
1159 source += xcount;
1160 dest += ycount;
1161 }
1162#endif
1163}
1164
1165static void *video_logo (void)
1166{
1167 u16 *screen = video_fb_address, width = VIDEO_COLS;
1168#ifdef VIDEO_INFO
1169# ifndef CONFIG_FADS
1170 char temp[32];
1171# endif
1172 char info[80];
1173#endif
1174
1175 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1176
1177#ifdef VIDEO_INFO
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);
1181
1182 sprintf (info, "(C) 2002 DENX Software Engineering");
1183 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1184 info);
1185
1186 sprintf (info, " Wolfgang DENK, wd@denx.de");
1187 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1188 info);
1189#ifndef CONFIG_FADS
1190
1191
1192 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1193 strmhz(temp, gd->cpu_clk),
1194 gd->ram_size >> 20,
1195 gd->bd->bi_flashsize >> 20 );
1196 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1197 info);
1198#else
1199 sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1200 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1201 info);
1202
1203 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1204 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1205 info);
1206#endif
1207#endif
1208
1209 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1210}
1211#endif
1212
1213
1214
1215
1216
1217static int video_init (void *videobase)
1218{
1219
1220 debug ("[VIDEO] Initializing video encoder...\n");
1221 video_encoder_init ();
1222
1223
1224 debug ("[VIDEO] Initializing video controller at %08x...\n",
1225 (int) videobase);
1226 video_ctrl_init (videobase);
1227
1228
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);
1239
1240#ifndef CONFIG_SYS_WHITE_ON_BLACK
1241 video_setfgcolor (CONSOLE_COLOR_BLACK);
1242 video_setbgcolor (CONSOLE_COLOR_GREY2);
1243#else
1244 video_setfgcolor (CONSOLE_COLOR_GREY2);
1245 video_setbgcolor (CONSOLE_COLOR_BLACK);
1246#endif
1247
1248#ifdef CONFIG_VIDEO_LOGO
1249
1250 debug ("[VIDEO] Drawing the logo...\n");
1251 video_console_address = video_logo ();
1252#else
1253 video_console_address = video_fb_address;
1254#endif
1255
1256#ifdef VIDEO_BLINK
1257
1258 blink_init ();
1259 blink_set (0);
1260#endif
1261
1262
1263 console_col = 0;
1264 console_row = 0;
1265 video_enable = 1;
1266
1267#ifdef VIDEO_MODE_PAL
1268# define VIDEO_MODE_TMP1 "PAL"
1269#endif
1270#ifdef VIDEO_MODE_NTSC
1271# define VIDEO_MODE_TMP1 "NTSC"
1272#endif
1273#ifdef VIDEO_MODE_YUYV
1274# define VIDEO_MODE_TMP2 "YCbYCr"
1275#endif
1276#ifdef VIDEO_MODE_RGB
1277# define VIDEO_MODE_TMP2 "RGB"
1278#endif
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);
1283 return 0;
1284}
1285
1286int drv_video_init (void)
1287{
1288 int error, devices = 1;
1289
1290 struct stdio_dev videodev;
1291
1292 video_init ((void *)(gd->fb_base));
1293
1294
1295
1296 memset (&videodev, 0, sizeof (videodev));
1297
1298 strcpy (videodev.name, "video");
1299 videodev.ext = DEV_EXT_VIDEO;
1300 videodev.flags = DEV_FLAGS_OUTPUT;
1301 videodev.putc = video_putc;
1302 videodev.puts = video_puts;
1303
1304 error = stdio_register (&videodev);
1305
1306 return (error == 0) ? devices : error;
1307}
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320ulong video_setmem (ulong addr)
1321{
1322
1323 addr -= VIDEO_SIZE;
1324
1325 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1326 VIDEO_SIZE>>10, addr);
1327
1328 return (addr);
1329}
1330
1331#endif
1332