1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <stdarg.h>
17#include <common.h>
18#include <config.h>
19#include <version.h>
20#include <i2c.h>
21#include <linux/types.h>
22#include <stdio_dev.h>
23
24#ifdef CONFIG_VIDEO
25
26DECLARE_GLOBAL_DATA_PTR;
27
28
29
30
31
32#if 0
33#define VIDEO_DEBUG_COLORBARS
34#endif
35
36
37
38
39
40#if 0
41#define VIDEO_MODE_EXTENDED
42#define VIDEO_MODE_NTSC
43#endif
44
45#define VIDEO_MODE_PAL
46
47#if 0
48#define VIDEO_BLINK
49#endif
50
51#define VIDEO_INFO
52#define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
53#define VIDEO_INFO_Y 16
54
55
56
57
58
59#ifdef VIDEO_MODE_EXTENDED
60#define VIDEO_COLS VIDEO_ACTIVE_COLS
61#define VIDEO_ROWS VIDEO_ACTIVE_ROWS
62#else
63#define VIDEO_COLS VIDEO_VISIBLE_COLS
64#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
65#endif
66
67#define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
68#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
69#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
70#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
71#define VIDEO_BURST_LEN (VIDEO_COLS/8)
72
73#ifdef VIDEO_MODE_YUYV
74#define VIDEO_BG_COL 0x80D880D8
75#else
76#define VIDEO_BG_COL 0xF8F8F8F8
77#endif
78
79
80
81
82
83#include <video_font.h>
84
85#ifdef CONFIG_VIDEO_LOGO
86#include <video_logo.h>
87
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
91#endif
92
93
94
95
96
97
98
99#define VIDEO_VCCR_VON 0
100#define VIDEO_VCCR_CSRC 1
101#define VIDEO_VCCR_PDF 13
102#define VIDEO_VCCR_IEN 11
103
104
105
106#define VIDEO_VSR_CAS 6
107#define VIDEO_VSR_EOF 0
108
109
110
111#define VIDEO_VCMR_BD 0
112#define VIDEO_VCMR_ASEL 1
113
114
115
116#define VIDEO_BCSR4_RESET_BIT 21
117#define VIDEO_BCSR4_EXTCLK_BIT 22
118#define VIDEO_BCSR4_VIDLED_BIT 23
119
120
121
122
123
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)
127#else
128#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
129#endif
130
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)
138
139
140
141
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
152
153
154
155
156
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)))
169
170
171
172
173
174typedef struct {
175 unsigned char V, Y1, U, Y2;
176} tYUYV;
177
178
179typedef struct VRAM {
180 unsigned hx:2,
181 vx:2,
182 fx:2,
183 bx:2,
184 res1:6,
185 vds:2,
186 inter:1,
187 res2:2,
188 lcyc:11,
189 lp:1,
190 lst:1;
191} VRAM;
192
193
194
195
196
197static int
198 video_panning_range_x = 0,
199 video_panning_range_y = 0,
200 video_panning_value_x = 0,
201 video_panning_value_y = 0,
202 video_panning_factor_x = 0,
203 video_panning_factor_y = 0,
204 console_col = 0,
205 console_row = 0,
206 video_palette[16];
207
208static const int video_font_draw_table[] =
209 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
210
211static char
212 video_color_fg = 0,
213 video_color_bg = 0,
214 video_enable = 0;
215
216static void
217 *video_fb_address,
218 *video_console_address;
219
220
221
222
223
224static void memsetl (int *p, int c, int v)
225{
226 while (c--)
227 *(p++) = v;
228}
229
230static void memcpyl (int *d, int *s, int c)
231{
232 while (c--)
233 *(d++) = *(s++);
234}
235
236
237
238
239
240static int video_maprgb (int r, int g, int b)
241{
242#ifdef VIDEO_MODE_YUYV
243 unsigned int pR, pG, pB;
244 tYUYV YUYV;
245 unsigned int *ret = (unsigned int *) &YUYV;
246
247
248
249 pR = r * 100 / 255;
250 pG = g * 100 / 255;
251 pB = b * 100 / 255;
252
253
254
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;
258 return *ret;
259#endif
260#ifdef VIDEO_MODE_RGB
261 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
262#endif
263}
264
265static void video_setpalette (int color, int r, int g, int b)
266{
267 color &= 0xf;
268
269 video_palette[color] = video_maprgb (r, g, b);
270
271
272 if (video_panning_value_x & 1)
273 video_palette[color] = SWAPINT (video_palette[color]);
274}
275
276static void video_fill (int color)
277{
278 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
279}
280
281static void video_setfgcolor (int i)
282{
283 video_color_fg = i & 0xf;
284}
285
286static void video_setbgcolor (int i)
287{
288 video_color_bg = i & 0xf;
289}
290
291static int video_pickcolor (int i)
292{
293 return video_palette[i & 0xf];
294}
295
296
297
298#ifdef VIDEO_BLINK
299static void video_revchar (int xx, int yy)
300{
301 int rows;
302 u8 *dest;
303
304 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
305
306 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
307 switch (VIDEO_FONT_WIDTH) {
308 case 16:
309 ((u32 *) dest)[6] ^= 0xffffffff;
310 ((u32 *) dest)[7] ^= 0xffffffff;
311
312 case 12:
313 ((u32 *) dest)[4] ^= 0xffffffff;
314 ((u32 *) dest)[5] ^= 0xffffffff;
315
316 case 8:
317 ((u32 *) dest)[2] ^= 0xffffffff;
318 ((u32 *) dest)[3] ^= 0xffffffff;
319
320 case 4:
321 ((u32 *) dest)[0] ^= 0xffffffff;
322 ((u32 *) dest)[1] ^= 0xffffffff;
323 }
324 }
325}
326#endif
327
328static void video_drawchars (int xx, int yy, unsigned char *s, int count)
329{
330 u8 *cdat, *dest, *dest0;
331 int rows, offset, c;
332 u32 eorx, fgx, bgx;
333
334 offset = yy * VIDEO_LINE_LEN + xx * 2;
335 dest0 = video_fb_address + offset;
336
337 fgx = video_pickcolor (video_color_fg);
338 bgx = video_pickcolor (video_color_bg);
339
340 if (xx & 1) {
341 fgx = SWAPINT (fgx);
342 bgx = SWAPINT (bgx);
343 }
344
345 eorx = fgx ^ bgx;
346
347 switch (VIDEO_FONT_WIDTH) {
348 case 4:
349 case 8:
350 while (count--) {
351 c = *s;
352 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
353 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
354 rows--;
355 dest += VIDEO_LINE_LEN) {
356 u8 bits = *cdat++;
357
358 ((u32 *) dest)[0] =
359 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
360 ((u32 *) dest)[1] =
361 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
362 if (VIDEO_FONT_WIDTH == 8) {
363 ((u32 *) dest)[2] =
364 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
365 ((u32 *) dest)[3] =
366 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
367 }
368 }
369 dest0 += VIDEO_FONT_WIDTH * 2;
370 s++;
371 }
372 break;
373 case 12:
374 case 16:
375 while (count--) {
376 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
377 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
378 dest += VIDEO_LINE_LEN) {
379 u8 bits = *cdat++;
380
381 ((u32 *) dest)[0] =
382 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
383 ((u32 *) dest)[1] =
384 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
385 ((u32 *) dest)[2] =
386 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
387 ((u32 *) dest)[3] =
388 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
389 bits = *cdat++;
390 ((u32 *) dest)[4] =
391 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
392 ((u32 *) dest)[5] =
393 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
394 if (VIDEO_FONT_WIDTH == 16) {
395 ((u32 *) dest)[6] =
396 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
397 ((u32 *) dest)[7] =
398 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
399 }
400 }
401 s++;
402 dest0 += VIDEO_FONT_WIDTH * 2;
403 }
404 break;
405 }
406}
407
408static inline void video_drawstring (int xx, int yy, char *s)
409{
410 video_drawchars (xx, yy, (unsigned char *)s, strlen (s));
411}
412
413
414
415static void video_putchars (int xx, int yy, unsigned char *s, int count)
416{
417#ifdef CONFIG_VIDEO_LOGO
418 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
419#else
420 video_drawchars (xx, yy, s, count);
421#endif
422}
423
424static void video_putchar (int xx, int yy, unsigned char c)
425{
426#ifdef CONFIG_VIDEO_LOGO
427 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
428#else
429 video_drawchars (xx, yy, &c, 1);
430#endif
431}
432
433static inline void video_putstring (int xx, int yy, unsigned char *s)
434{
435 video_putchars (xx, yy, (unsigned char *)s, strlen ((char *)s));
436}
437
438
439
440
441
442static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
443{
444 int i;
445
446 for (i = 0; i < entries; i++) {
447 dest[i] = source[i];
448 dest[i].fx = (!dest[i].fx) * 3;
449 }
450
451 dest[0].lcyc++;
452 dest[entries - 1].lst = 1;
453}
454
455static 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)
458{
459 vr->hx = Hx;
460 vr->vx = Vx;
461 vr->fx = Fx;
462 vr->bx = Bx;
463 vr->vds = VDS;
464 vr->inter = INT;
465 vr->lcyc = LCYC;
466 vr->lp = LP;
467 vr->lst = LST;
468}
469
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)
471
472static int video_mode_generate (void)
473{
474 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
475 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00);
476 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
477
478
479
480 if (video_panning_factor_y < -128)
481 video_panning_factor_y = -128;
482
483 if (video_panning_factor_y > 128)
484 video_panning_factor_y = 128;
485
486 if (video_panning_factor_x < -128)
487 video_panning_factor_x = -128;
488
489 if (video_panning_factor_x > 128)
490 video_panning_factor_x = 128;
491
492
493
494 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
495 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
496
497 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
498 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
499
500
501 X1 = video_panning_value_x & 0xfffe;
502 X2 = DX - X1;
503
504
505 Y1 = video_panning_value_y & 0xfffe;
506 Y2 = DY - Y1;
507
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);
510
511#ifdef VIDEO_MODE_NTSC
512
513
514
515
516
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);
521
522
523
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);
528
529
530
531 if (Y1 > 0) {
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);
536 }
537
538
539
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);
544
545 if (X2 > 0)
546 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
547
548 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
549
550
551
552
553 if (Y1 > 0) {
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);
558 }
559
560
561
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);
566
567
568
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);
573
574
575
576 if (Y1 > 0) {
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);
581 }
582
583
584
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);
589
590 if (X2 > 0)
591 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
592
593 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
594
595
596
597 if (Y1 > 0) {
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);
602 }
603
604
605
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);
610#endif
611
612#ifdef VIDEO_MODE_PAL
613
614
615
616
617
618
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);
623
624
625
626 if (Y1 > 0) {
627 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
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);
631 }
632
633
634
635 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0);
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);
639
640 if (X2 > 0)
641 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
642
643 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
644
645
646
647 if (Y2 > 0) {
648 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
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);
652 }
653
654
655
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);
660
661
662
663
664 video_mode_dupefield (vr, &vr[entry], entry);
665
666#endif
667
668
669 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
670
671
672 if (fifo) {
673 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
674 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
675 } else {
676 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
677 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
678 }
679
680 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
681
682
683
684
685
686
687
688 return entry * 2;
689}
690
691static void video_encoder_init (void)
692{
693 return;
694}
695
696static void video_ctrl_init (void *memptr)
697{
698 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
699
700 video_fb_address = memptr;
701
702
703 debug ("[VIDEO CTRL] Setting background color...\n");
704 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
705
706
707 debug ("[VIDEO CTRL] Forcing background...\n");
708 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
709
710
711 debug ("[VIDEO CTRL] Turning off video controller...\n");
712 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
713
714
715 debug ("[VIDEO CTRL] Generating video mode...\n");
716 video_mode_generate ();
717
718
719
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;
726
727
728 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
729 immap->im_vid.vid_vccr = 0x2042;
730
731
732 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
733 immap->im_ioport.iop_pdpar = 0x1fff;
734 immap->im_ioport.iop_pddir = 0x0000;
735
736
737 debug ("[VIDEO CTRL] Blanking the screen...\n");
738 video_fill (VIDEO_BG_COL);
739
740
741
742
743
744
745
746
747
748 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
749 immap->im_siu_conf.sc_sdcr = 0x40;
750
751
752 debug ("[VIDEO CTRL] Turning on video controller...\n");
753 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
754
755
756 debug ("[VIDEO CTRL] Enabling the video...\n");
757 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
758}
759
760
761
762
763
764static void console_scrollup (void)
765{
766
767 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
768
769
770 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
771}
772
773static inline void console_back (void)
774{
775 console_col--;
776
777 if (console_col < 0) {
778 console_col = CONSOLE_COLS - 1;
779 console_row--;
780 if (console_row < 0)
781 console_row = 0;
782 }
783
784 video_putchar ( console_col * VIDEO_FONT_WIDTH,
785 console_row * VIDEO_FONT_HEIGHT, ' ');
786}
787
788static inline void console_newline (void)
789{
790 console_row++;
791 console_col = 0;
792
793
794 if (console_row >= CONSOLE_ROWS) {
795
796 console_scrollup ();
797
798
799 console_row--;
800 }
801}
802
803void video_putc(struct stdio_dev *dev, const char c)
804{
805 if (!video_enable) {
806 serial_putc (c);
807 return;
808 }
809
810 switch (c) {
811 case 13:
812 break;
813
814 case '\n':
815 console_newline ();
816 break;
817
818 case 9:
819 console_col |= 0x0008;
820 console_col &= ~0x0007;
821
822 if (console_col >= CONSOLE_COLS)
823 console_newline ();
824 break;
825
826 case 8:
827 console_back ();
828 break;
829
830 default:
831 video_putchar ( console_col * VIDEO_FONT_WIDTH,
832 console_row * VIDEO_FONT_HEIGHT, c);
833 console_col++;
834
835 if (console_col >= CONSOLE_COLS)
836 console_newline ();
837 }
838}
839
840void video_puts(struct stdio_dev *dev, const char *s)
841{
842 int count = strlen (s);
843
844 if (!video_enable)
845 while (count--)
846 serial_putc (*s++);
847 else
848 while (count--)
849 video_putc(dev, *s++);
850}
851
852
853
854
855
856#ifdef VIDEO_BLINK
857
858#define BLINK_TIMER_ID 0
859#define BLINK_TIMER_HZ 2
860
861static unsigned char blink_enabled = 0;
862static timer_t blink_timer;
863
864static void blink_update (void)
865{
866 static int blink_row = -1, blink_col = -1, blink_old = 0;
867
868
869 if ((console_row != blink_row) || (console_col != blink_col)) {
870
871 if (blink_old)
872 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
873 (blink_row
874#ifdef CONFIG_VIDEO_LOGO
875 + VIDEO_LOGO_HEIGHT
876#endif
877 ) * VIDEO_FONT_HEIGHT);
878
879
880 blink_row = console_row;
881 blink_col = console_col;
882 blink_old = 0;
883 }
884
885
886 blink_old = !blink_old;
887 video_revchar ( console_col * VIDEO_FONT_WIDTH,
888 (console_row
889#ifdef CONFIG_VIDEO_LOGO
890 + VIDEO_LOGO_HEIGHT
891#endif
892 ) * VIDEO_FONT_HEIGHT);
893
894}
895
896
897
898
899static void blink_handler (void *arg)
900{
901
902 blink_update ();
903
904 timer_ack (&blink_timer);
905}
906
907int blink_set (int blink)
908{
909 int ret = blink_enabled;
910
911 if (blink)
912 timer_enable (&blink_timer);
913 else
914 timer_disable (&blink_timer);
915
916 blink_enabled = blink;
917
918 return ret;
919}
920
921static inline void blink_close (void)
922{
923 timer_close (&blink_timer);
924}
925
926static inline void blink_init (void)
927{
928 timer_init (&blink_timer,
929 BLINK_TIMER_ID, BLINK_TIMER_HZ,
930 blink_handler);
931}
932#endif
933
934
935
936
937
938#ifdef CONFIG_VIDEO_LOGO
939void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
940 int y)
941{
942 int skip = width - image->width, xcount, ycount = image->height;
943
944#ifdef VIDEO_MODE_YUYV
945 ushort *source = (ushort *) image->data;
946 ushort *dest = (ushort *) screen + y * width + x;
947
948 while (ycount--) {
949 xcount = image->width;
950 while (xcount--)
951 *dest++ = *source++;
952 dest += skip;
953 }
954#endif
955#ifdef VIDEO_MODE_RGB
956 unsigned char
957 *source = (unsigned short *) image->data,
958 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
959
960 while (ycount--) {
961 xcount = image->width * 3;
962 memcpy (dest, source, xcount);
963 source += xcount;
964 dest += ycount;
965 }
966#endif
967}
968
969static void *video_logo (void)
970{
971 u16 *screen = video_fb_address, width = VIDEO_COLS;
972#ifdef VIDEO_INFO
973 char temp[32];
974 char info[80];
975#endif
976
977 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
978
979#ifdef VIDEO_INFO
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);
983
984 sprintf (info, "(C) 2002 DENX Software Engineering");
985 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
986 info);
987
988 sprintf (info, " Wolfgang DENK, wd@denx.de");
989 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
990 info);
991
992
993
994 sprintf(info, "MPC823 CPU at %s MHz, %ld MiB RAM, %ld MiB Flash",
995 strmhz(temp, gd->cpu_clk),
996 gd->ram_size >> 20,
997 gd->bd->bi_flashsize >> 20 );
998 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
999 info);
1000#endif
1001
1002 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1003}
1004#endif
1005
1006
1007
1008
1009
1010static int video_init (void *videobase)
1011{
1012
1013 debug ("[VIDEO] Initializing video encoder...\n");
1014 video_encoder_init ();
1015
1016
1017 debug ("[VIDEO] Initializing video controller at %08x...\n",
1018 (int) videobase);
1019 video_ctrl_init (videobase);
1020
1021
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);
1032
1033#ifndef CONFIG_SYS_WHITE_ON_BLACK
1034 video_setfgcolor (CONSOLE_COLOR_BLACK);
1035 video_setbgcolor (CONSOLE_COLOR_GREY2);
1036#else
1037 video_setfgcolor (CONSOLE_COLOR_GREY2);
1038 video_setbgcolor (CONSOLE_COLOR_BLACK);
1039#endif
1040
1041#ifdef CONFIG_VIDEO_LOGO
1042
1043 debug ("[VIDEO] Drawing the logo...\n");
1044 video_console_address = video_logo ();
1045#else
1046 video_console_address = video_fb_address;
1047#endif
1048
1049#ifdef VIDEO_BLINK
1050
1051 blink_init ();
1052 blink_set (0);
1053#endif
1054
1055
1056 console_col = 0;
1057 console_row = 0;
1058 video_enable = 1;
1059
1060#ifdef VIDEO_MODE_PAL
1061# define VIDEO_MODE_TMP1 "PAL"
1062#endif
1063#ifdef VIDEO_MODE_NTSC
1064# define VIDEO_MODE_TMP1 "NTSC"
1065#endif
1066#ifdef VIDEO_MODE_YUYV
1067# define VIDEO_MODE_TMP2 "YCbYCr"
1068#endif
1069#ifdef VIDEO_MODE_RGB
1070# define VIDEO_MODE_TMP2 "RGB"
1071#endif
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);
1076 return 0;
1077}
1078
1079int drv_video_init (void)
1080{
1081 int error, devices = 1;
1082
1083 struct stdio_dev videodev;
1084
1085 video_init ((void *)(gd->fb_base));
1086
1087
1088
1089 memset (&videodev, 0, sizeof (videodev));
1090
1091 strcpy (videodev.name, "video");
1092 videodev.ext = DEV_EXT_VIDEO;
1093 videodev.flags = DEV_FLAGS_OUTPUT;
1094 videodev.putc = video_putc;
1095 videodev.puts = video_puts;
1096
1097 error = stdio_register (&videodev);
1098
1099 return (error == 0) ? devices : error;
1100}
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113ulong video_setmem (ulong addr)
1114{
1115
1116 addr -= VIDEO_SIZE;
1117
1118 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1119 VIDEO_SIZE>>10, addr);
1120
1121 return (addr);
1122}
1123
1124#endif
1125