blob: f2b8814c83112b2131b0ca55b5c364dc22df9d97 [file] [log] [blame]
wdenk5b1d7132002-11-03 00:07:02 +00001/*
2 * (C) Copyright 2000
3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
4 * (C) Copyright 2002
5 * Wolfgang Denk, wd@denx.de
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
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.
14 *
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.
19 *
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,
23 * MA 02111-1307 USA
24 */
25
wdenk8564acf2003-07-14 22:13:32 +000026/* #define DEBUG */
wdenk5b1d7132002-11-03 00:07:02 +000027
28/************************************************************************/
29/* ** HEADER FILES */
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 <devices.h>
39
40#ifdef CONFIG_VIDEO
41
42/************************************************************************/
43/* ** DEBUG SETTINGS */
44/************************************************************************/
45
46#if 0
47#define VIDEO_DEBUG_COLORBARS /* Force colorbars output */
48#endif
49
50/************************************************************************/
51/* ** VIDEO MODE SETTINGS */
52/************************************************************************/
53
54#if 0
55#define VIDEO_MODE_EXTENDED /* Allow screen size bigger than visible area */
56#define VIDEO_MODE_NTSC
57#endif
58
59#define VIDEO_MODE_PAL
60
61#if 0
62#define VIDEO_BLINK /* This enables cursor blinking (under construction) */
63#endif
64
65#define VIDEO_INFO /* Show U-Boot information */
66#define VIDEO_INFO_X VIDEO_LOGO_WIDTH+8
67#define VIDEO_INFO_Y 16
68
69/************************************************************************/
70/* ** VIDEO ENCODER CONSTANTS */
71/************************************************************************/
72
73#ifdef CONFIG_VIDEO_ENCODER_AD7176
74
75#include <video_ad7176.h> /* Sets encoder data, mode, and visible and active area */
76
77#define VIDEO_I2C 1
78#define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7176_ADDR
79#endif
80
81#ifdef CONFIG_VIDEO_ENCODER_AD7177
82
83#include <video_ad7177.h> /* Sets encoder data, mode, and visible and active area */
84
85#define VIDEO_I2C 1
86#define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7177_ADDR
87#endif
88
wdenk8564acf2003-07-14 22:13:32 +000089#ifdef CONFIG_VIDEO_ENCODER_AD7179
90
91#include <video_ad7179.h> /* Sets encoder data, mode, and visible and active area */
92
93#define VIDEO_I2C 1
94#define VIDEO_I2C_ADDR CONFIG_VIDEO_ENCODER_AD7179_ADDR
95#endif
96
wdenk5b1d7132002-11-03 00:07:02 +000097/************************************************************************/
98/* ** VIDEO MODE CONSTANTS */
99/************************************************************************/
100
101#ifdef VIDEO_MODE_EXTENDED
102#define VIDEO_COLS VIDEO_ACTIVE_COLS
103#define VIDEO_ROWS VIDEO_ACTIVE_ROWS
104#else
105#define VIDEO_COLS VIDEO_VISIBLE_COLS
106#define VIDEO_ROWS VIDEO_VISIBLE_ROWS
107#endif
108
109#define VIDEO_PIXEL_SIZE (VIDEO_MODE_BPP/8)
110#define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Total size of buffer */
111#define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2) /* Number of ints */
112#define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE) /* Number of bytes per line */
113#define VIDEO_BURST_LEN (VIDEO_COLS/8)
114
115#ifdef VIDEO_MODE_YUYV
116#define VIDEO_BG_COL 0x80D880D8 /* Background color in YUYV format */
117#else
118#define VIDEO_BG_COL 0xF8F8F8F8 /* Background color in RGB format */
119#endif
120
121/************************************************************************/
122/* ** FONT AND LOGO DATA */
123/************************************************************************/
124
125#include <video_font.h> /* Get font data, width and height */
126
127#ifdef CONFIG_VIDEO_LOGO
128#include <video_logo.h> /* Get logo data, width and height */
129
130#define VIDEO_LOGO_WIDTH DEF_U_BOOT_LOGO_WIDTH
131#define VIDEO_LOGO_HEIGHT DEF_U_BOOT_LOGO_HEIGHT
132#define VIDEO_LOGO_ADDR &u_boot_logo
133#endif
134
135/************************************************************************/
136/* ** VIDEO CONTROLLER CONSTANTS */
137/************************************************************************/
138
139/* VCCR - VIDEO CONTROLLER CONFIGURATION REGISTER */
140
141#define VIDEO_VCCR_VON 0 /* Video controller ON */
142#define VIDEO_VCCR_CSRC 1 /* Clock source */
143#define VIDEO_VCCR_PDF 13 /* Pixel display format */
144#define VIDEO_VCCR_IEN 11 /* Interrupt enable */
145
146/* VSR - VIDEO STATUS REGISTER */
147
148#define VIDEO_VSR_CAS 6 /* Active set */
149#define VIDEO_VSR_EOF 0 /* End of frame */
150
151/* VCMR - VIDEO COMMAND REGISTER */
152
153#define VIDEO_VCMR_BD 0 /* Blank display */
154#define VIDEO_VCMR_ASEL 1 /* Active set selection */
155
156/* VBCB - VIDEO BACKGROUND COLOR BUFFER REGISTER */
157
158#define VIDEO_BCSR4_RESET_BIT 21 /* BCSR4 - Extern video encoder reset */
159#define VIDEO_BCSR4_EXTCLK_BIT 22 /* BCSR4 - Extern clock enable */
160#define VIDEO_BCSR4_VIDLED_BIT 23 /* BCSR4 - Video led disable */
161
162/************************************************************************/
163/* ** CONSOLE CONSTANTS */
164/************************************************************************/
165
wdenk8564acf2003-07-14 22:13:32 +0000166#ifdef CONFIG_VIDEO_LOGO
wdenk5b1d7132002-11-03 00:07:02 +0000167#define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
168#define VIDEO_LOGO_SKIP (VIDEO_COLS - VIDEO_LOGO_WIDTH)
169#else
170#define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
171#endif
172
173#define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
wdenk8564acf2003-07-14 22:13:32 +0000174#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
wdenk5b1d7132002-11-03 00:07:02 +0000175#define CONSOLE_ROW_FIRST (video_console_address)
wdenk8564acf2003-07-14 22:13:32 +0000176#define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
wdenk5b1d7132002-11-03 00:07:02 +0000177#define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
wdenk8564acf2003-07-14 22:13:32 +0000178#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
wdenk5b1d7132002-11-03 00:07:02 +0000179#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
180
181/*
182 * Simple color definitions
183 */
184#define CONSOLE_COLOR_BLACK 0
185#define CONSOLE_COLOR_RED 1
186#define CONSOLE_COLOR_GREEN 2
187#define CONSOLE_COLOR_YELLOW 3
188#define CONSOLE_COLOR_BLUE 4
189#define CONSOLE_COLOR_MAGENTA 5
190#define CONSOLE_COLOR_CYAN 6
191#define CONSOLE_COLOR_GREY 13
192#define CONSOLE_COLOR_GREY2 14
193#define CONSOLE_COLOR_WHITE 15 /* Must remain last / highest */
194
195/************************************************************************/
196/* ** BITOPS MACROS */
197/************************************************************************/
198
199#define HISHORT(i) ((i >> 16)&0xffff)
200#define LOSHORT(i) (i & 0xffff)
201#define HICHAR(s) ((i >> 8)&0xff)
202#define LOCHAR(s) (i & 0xff)
203#define HI(c) ((c >> 4)&0xf)
204#define LO(c) (c & 0xf)
205#define SWAPINT(i) (HISHORT(i) | (LOSHORT(i) << 16))
206#define SWAPSHORT(s) (HICHAR(s) | (LOCHAR(s) << 8))
207#define SWAPCHAR(c) (HI(c) | (LO(c) << 4))
208#define BITMASK(b) (1 << (b))
209#define GETBIT(v,b) (((v) & BITMASK(b)) > 0)
210#define SETBIT(v,b,d) (v = (((d)>0) ? (v) | BITMASK(b): (v) & ~BITMASK(b)))
211
212/************************************************************************/
213/* ** STRUCTURES */
214/************************************************************************/
215
216typedef struct {
217 unsigned char V, Y1, U, Y2;
218} tYUYV;
219
220/* This structure is based on the Video Ram in the MPC823. */
221typedef struct VRAM {
222 unsigned hx:2, /* Horizontal sync */
223 vx:2, /* Vertical sync */
224 fx:2, /* Frame */
225 bx:2, /* Blank */
226 res1:6, /* Reserved */
227 vds:2, /* Video Data Select */
228 inter:1, /* Interrupt */
229 res2:2, /* Reserved */
230 lcyc:11, /* Loop/video cycles */
231 lp:1, /* Loop start/end */
232 lst:1; /* Last entry */
233} VRAM;
234
235/************************************************************************/
236/* ** VARIABLES */
237/************************************************************************/
238
239static int
240 video_panning_range_x = 0, /* Video mode invisible pixels x range */
241 video_panning_range_y = 0, /* Video mode invisible pixels y range */
242 video_panning_value_x = 0, /* Video mode x panning value (absolute) */
243 video_panning_value_y = 0, /* Video mode y panning value (absolute) */
244 video_panning_factor_x = 0, /* Video mode x panning value (-127 +127) */
245 video_panning_factor_y = 0, /* Video mode y panning value (-127 +127) */
246 console_col = 0, /* Cursor col */
247 console_row = 0, /* Cursor row */
248 video_palette[16]; /* Our palette */
249
250static const int video_font_draw_table[] =
251 { 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
252
253static char
254 video_color_fg = 0, /* Current fg color index (0-15) */
255 video_color_bg = 0, /* Current bg color index (0-15) */
256 video_enable = 0; /* Video has been initialized? */
257
258static void
259 *video_fb_address, /* Frame buffer address */
260 *video_console_address; /* Console frame buffer start address */
261
262/************************************************************************/
263/* ** MEMORY FUNCTIONS (32bit) */
264/************************************************************************/
265
266static void memsetl (int *p, int c, int v)
267{
268 while (c--)
269 *(p++) = v;
270}
271
272static void memcpyl (int *d, int *s, int c)
273{
274 while (c--)
275 *(d++) = *(s++);
276}
277
278/************************************************************************/
279/* ** VIDEO DRAWING AND COLOR FUNCTIONS */
280/************************************************************************/
281
282static int video_maprgb (int r, int g, int b)
283{
284#ifdef VIDEO_MODE_YUYV
285 unsigned int pR, pG, pB;
286 tYUYV YUYV;
287 unsigned int *ret = (unsigned int *) &YUYV;
288
289 /* Transform (0-255) components to (0-100) */
290
291 pR = r * 100 / 255;
292 pG = g * 100 / 255;
293 pB = b * 100 / 255;
294
295 /* Calculate YUV values (0-255) from RGB beetween 0-100 */
296
297 YUYV.Y1 = YUYV.Y2 = 209 * (pR + pG + pB) / 300 + 16;
wdenk8564acf2003-07-14 22:13:32 +0000298 YUYV.U = pR - (pG * 3 / 4) - (pB / 4) + 128;
299 YUYV.V = pB - (pR / 4) - (pG * 3 / 4) + 128;
wdenk5b1d7132002-11-03 00:07:02 +0000300 return *ret;
301#endif
302#ifdef VIDEO_MODE_RGB
303 return ((r >> 3) << 11) | ((g > 2) << 6) | (b >> 3);
304#endif
305}
306
307static void video_setpalette (int color, int r, int g, int b)
308{
309 color &= 0xf;
310
311 video_palette[color] = video_maprgb (r, g, b);
312
313 /* Swap values if our panning offset is odd */
314 if (video_panning_value_x & 1)
315 video_palette[color] = SWAPINT (video_palette[color]);
316}
317
318static void video_fill (int color)
319{
320 memsetl (video_fb_address, VIDEO_PIX_BLOCKS, color);
321}
322
323static void video_setfgcolor (int i)
324{
325 video_color_fg = i & 0xf;
326}
327
328static void video_setbgcolor (int i)
329{
330 video_color_bg = i & 0xf;
331}
332
333static int video_pickcolor (int i)
334{
335 return video_palette[i & 0xf];
336}
337
338/* Absolute console plotting functions */
339
340#ifdef VIDEO_BLINK
341static void video_revchar (int xx, int yy)
342{
343 int rows;
344 u8 *dest;
345
346 dest = video_fb_address + yy * VIDEO_LINE_LEN + xx * 2;
347
348 for (rows = VIDEO_FONT_HEIGHT; rows--; dest += VIDEO_LINE_LEN) {
349 switch (VIDEO_FONT_WIDTH) {
350 case 16:
351 ((u32 *) dest)[6] ^= 0xffffffff;
352 ((u32 *) dest)[7] ^= 0xffffffff;
353 /* FALL THROUGH */
354 case 12:
355 ((u32 *) dest)[4] ^= 0xffffffff;
356 ((u32 *) dest)[5] ^= 0xffffffff;
357 /* FALL THROUGH */
358 case 8:
359 ((u32 *) dest)[2] ^= 0xffffffff;
360 ((u32 *) dest)[3] ^= 0xffffffff;
361 /* FALL THROUGH */
362 case 4:
363 ((u32 *) dest)[0] ^= 0xffffffff;
364 ((u32 *) dest)[1] ^= 0xffffffff;
365 }
366 }
367}
368#endif
369
370static void video_drawchars (int xx, int yy, unsigned char *s, int count)
371{
372 u8 *cdat, *dest, *dest0;
373 int rows, offset, c;
374 u32 eorx, fgx, bgx;
375
376 offset = yy * VIDEO_LINE_LEN + xx * 2;
377 dest0 = video_fb_address + offset;
378
379 fgx = video_pickcolor (video_color_fg);
380 bgx = video_pickcolor (video_color_bg);
381
382 if (xx & 1) {
383 fgx = SWAPINT (fgx);
384 bgx = SWAPINT (bgx);
385 }
386
387 eorx = fgx ^ bgx;
388
389 switch (VIDEO_FONT_WIDTH) {
390 case 4:
391 case 8:
392 while (count--) {
393 c = *s;
394 cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
395 for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
396 rows--;
397 dest += VIDEO_LINE_LEN) {
398 u8 bits = *cdat++;
399
400 ((u32 *) dest)[0] =
401 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
402 ((u32 *) dest)[1] =
403 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
404 if (VIDEO_FONT_WIDTH == 8) {
405 ((u32 *) dest)[2] =
406 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
407 ((u32 *) dest)[3] =
408 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
409 }
410 }
411 dest0 += VIDEO_FONT_WIDTH * 2;
412 s++;
413 }
414 break;
415 case 12:
416 case 16:
417 while (count--) {
418 cdat = video_fontdata + (*s) * (VIDEO_FONT_HEIGHT << 1);
419 for (rows = VIDEO_FONT_HEIGHT, dest = dest0; rows--;
420 dest += VIDEO_LINE_LEN) {
421 u8 bits = *cdat++;
422
423 ((u32 *) dest)[0] =
424 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
425 ((u32 *) dest)[1] =
426 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
427 ((u32 *) dest)[2] =
428 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
429 ((u32 *) dest)[3] =
430 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
431 bits = *cdat++;
432 ((u32 *) dest)[4] =
433 (video_font_draw_table[bits >> 6] & eorx) ^ bgx;
434 ((u32 *) dest)[5] =
435 (video_font_draw_table[bits >> 4 & 3] & eorx) ^ bgx;
436 if (VIDEO_FONT_WIDTH == 16) {
437 ((u32 *) dest)[6] =
438 (video_font_draw_table[bits >> 2 & 3] & eorx) ^ bgx;
439 ((u32 *) dest)[7] =
440 (video_font_draw_table[bits & 3] & eorx) ^ bgx;
441 }
442 }
443 s++;
444 dest0 += VIDEO_FONT_WIDTH * 2;
445 }
446 break;
447 }
448}
449
450static inline void video_drawstring (int xx, int yy, unsigned char *s)
451{
452 video_drawchars (xx, yy, s, strlen (s));
453}
454
455/* Relative to console plotting functions */
456
457static void video_putchars (int xx, int yy, unsigned char *s, int count)
458{
459#ifdef CONFIG_VIDEO_LOGO
460 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, s, count);
461#else
462 video_drawchars (xx, yy, s, count);
463#endif
464}
465
466static void video_putchar (int xx, int yy, unsigned char c)
467{
468#ifdef CONFIG_VIDEO_LOGO
469 video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
470#else
471 video_drawchars (xx, yy, &c, 1);
472#endif
473}
474
475static inline void video_putstring (int xx, int yy, unsigned char *s)
476{
477 video_putchars (xx, yy, s, strlen (s));
478}
479
480/************************************************************************/
481/* ** VIDEO CONTROLLER LOW-LEVEL FUNCTIONS */
482/************************************************************************/
483
wdenk8564acf2003-07-14 22:13:32 +0000484#if !defined(CONFIG_RRVISION)
wdenk5b1d7132002-11-03 00:07:02 +0000485static void video_mode_dupefield (VRAM * source, VRAM * dest, int entries)
486{
487 int i;
488
489 for (i = 0; i < entries; i++) {
490 dest[i] = source[i]; /* Copy the entire record */
491 dest[i].fx = (!dest[i].fx) * 3; /* Negate field bit */
492 }
493
494 dest[0].lcyc++; /* Add a cycle to the first entry */
495 dest[entries - 1].lst = 1; /* Set end of ram entries */
496}
wdenk8564acf2003-07-14 22:13:32 +0000497#endif
wdenk5b1d7132002-11-03 00:07:02 +0000498
499static void inline video_mode_addentry (VRAM * vr,
500 int Hx, int Vx, int Fx, int Bx,
501 int VDS, int INT, int LCYC, int LP, int LST)
502{
503 vr->hx = Hx;
504 vr->vx = Vx;
505 vr->fx = Fx;
506 vr->bx = Bx;
507 vr->vds = VDS;
508 vr->inter = INT;
509 vr->lcyc = LCYC;
510 vr->lp = LP;
511 vr->lst = LST;
512}
513
wdenk8564acf2003-07-14 22:13:32 +0000514#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)
wdenk5b1d7132002-11-03 00:07:02 +0000515
516static int video_mode_generate (void)
517{
518 immap_t *immap = (immap_t *) CFG_IMMR;
519 VRAM *vr = (VRAM *) (((void *) immap) + 0xb00); /* Pointer to the VRAM table */
520 int DX, X1, X2, DY, Y1, Y2, entry = 0, fifo;
521
522 /* CHECKING PARAMETERS */
523
524 if (video_panning_factor_y < -128)
525 video_panning_factor_y = -128;
526
527 if (video_panning_factor_y > 128)
528 video_panning_factor_y = 128;
529
530 if (video_panning_factor_x < -128)
531 video_panning_factor_x = -128;
532
533 if (video_panning_factor_x > 128)
534 video_panning_factor_x = 128;
535
536 /* Setting panning */
537
538 DX = video_panning_range_x = (VIDEO_ACTIVE_COLS - VIDEO_COLS) * 2;
539 DY = video_panning_range_y = (VIDEO_ACTIVE_ROWS - VIDEO_ROWS) / 2;
540
541 video_panning_value_x = (video_panning_factor_x + 128) * DX / 256;
542 video_panning_value_y = (video_panning_factor_y + 128) * DY / 256;
543
544 /* We assume these are burst units (multiplied by 2, we need it pari) */
545 X1 = video_panning_value_x & 0xfffe;
546 X2 = DX - X1;
547
548 /* We assume these are field line units (divided by 2, we need it pari) */
549 Y1 = video_panning_value_y & 0xfffe;
550 Y2 = DY - Y1;
551
wdenk8564acf2003-07-14 22:13:32 +0000552 debug("X1=%d, X2=%d, Y1=%d, Y2=%d, DX=%d, DY=%d VIDEO_COLS=%d \n",
553 X1, X2, Y1, Y2, DX, DY, VIDEO_COLS);
554
wdenk5b1d7132002-11-03 00:07:02 +0000555#ifdef VIDEO_MODE_NTSC
556/*
wdenk8564acf2003-07-14 22:13:32 +0000557 * Hx Vx Fx Bx VDS INT LCYC LP LST
wdenk5b1d7132002-11-03 00:07:02 +0000558 *
559 * Retrace blanking
560 */
561 ADDENTRY (0, 0, 3, 0, 1, 0, 3, 1, 0);
562 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
563 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
564 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
565/*
566 * Vertical blanking
567 */
568 ADDENTRY (0, 0, 0, 0, 1, 0, 18, 1, 0);
569 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
570 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
571 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
572/*
573 * Odd field active area (TOP)
574 */
575 if (Y1 > 0) {
576 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0);
577 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
578 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
579 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
580 }
581/*
582 * Odd field active area
583 */
584 ADDENTRY (0, 0, 0, 0, 1, 0, 240 - DY, 1, 0);
585 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
586 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
587 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
588
589 if (X2 > 0)
590 ADDENTRY (3, 0, 0, 3, 1, 0, X2, 0, 0);
591
592 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
593
594/*
595 * Odd field active area (BOTTOM)
596 */
597 if (Y1 > 0) {
598 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0);
599 ADDENTRY (3, 0, 0, 0, 1, 0, 235, 0, 0);
600 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
601 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
602 }
603/*
604 * Vertical blanking
605 */
606 ADDENTRY (0, 0, 0, 0, 1, 0, 4, 1, 0);
607 ADDENTRY (3, 0, 0, 0, 1, 0, 243, 0, 0);
608 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
609 ADDENTRY (3, 0, 0, 0, 1, 0, 32, 1, 0);
610/*
611 * Vertical blanking
612 */
613 ADDENTRY (0, 0, 3, 0, 1, 0, 19, 1, 0);
614 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
615 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
616 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
617/*
618 * Even field active area (TOP)
619 */
620 if (Y1 > 0) {
621 ADDENTRY (0, 0, 3, 0, 1, 0, Y1, 1, 0);
622 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
623 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
624 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
625 }
626/*
627 * Even field active area (CENTER)
628 */
629 ADDENTRY (0, 0, 3, 0, 1, 0, 240 - DY, 1, 0);
630 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
631 ADDENTRY (3, 0, 3, 3, 1, 0, 8 + X1, 0, 0);
632 ADDENTRY (3, 0, 3, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
633
634 if (X2 > 0)
635 ADDENTRY (3, 0, 3, 3, 1, 0, X2, 0, 0);
636
637 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
638/*
639 * Even field active area (BOTTOM)
640 */
641 if (Y1 > 0) {
642 ADDENTRY (0, 0, 3, 0, 1, 0, Y2, 1, 0);
643 ADDENTRY (3, 0, 3, 0, 1, 0, 235, 0, 0);
644 ADDENTRY (3, 0, 3, 3, 1, 0, 1448, 0, 0);
645 ADDENTRY (3, 0, 3, 0, 1, 0, 32, 1, 0);
646 }
647/*
648 * Vertical blanking
649 */
650 ADDENTRY (0, 0, 3, 0, 1, 0, 1, 1, 0);
651 ADDENTRY (3, 0, 3, 0, 1, 0, 243, 0, 0);
652 ADDENTRY (3, 0, 3, 0, 1, 0, 1440, 0, 0);
653 ADDENTRY (3, 0, 3, 0, 1, 1, 32, 1, 1);
654#endif
655
656#ifdef VIDEO_MODE_PAL
wdenk8564acf2003-07-14 22:13:32 +0000657
658#if defined(CONFIG_RRVISION)
659
660#define HPW 160 /* horizontal pulse width (was 139) */
661#define VPW 2 /* vertical pulse width */
662#define HBP 104 /* horizontal back porch (was 112) */
663#define VBP 19 /* vertical back porch (was 19) */
664#define VID_R 240 /* number of rows */
665
666 debug ("[VIDEO CTRL] Starting to add controller entries...");
667/*
668 * Even field
669 */
670 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
671 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
672 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
673
674 ADDENTRY (0, 0, 0, 3, 1, 0, VPW, 1, 0);
675 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
676 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
677
678 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
679 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
680 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
681/*
682 * Active area
683 */
684 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
685 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
686 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
wdenk945af8d2003-07-16 21:53:01 +0000687 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
wdenk8564acf2003-07-14 22:13:32 +0000688 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
689
690 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
691 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
692 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
wdenk945af8d2003-07-16 21:53:01 +0000693/*
694 * Odd field
695 */
wdenk8564acf2003-07-14 22:13:32 +0000696 ADDENTRY (0, 3, 0, 3, 1, 0, 2, 0, 0);
697 ADDENTRY (0, 0, 0, 3, 1, 0, HPW, 0, 0);
698 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 0, 0);
699
700 ADDENTRY (0, 0, 0, 3, 1, 0, VPW+1, 1, 0);
701 ADDENTRY (0, 0, 0, 3, 1, 0, HPW-1, 0, 0);
702 ADDENTRY (3, 0, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
703
704 ADDENTRY (0, 3, 0, 3, 1, 0, VBP, 1, 0);
705 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
706 ADDENTRY (3, 3, 0, 3, 1, 0, HBP + (VIDEO_COLS * 2) + 72, 1, 0);
707/*
708 * Active area
709 */
710 ADDENTRY (0, 3, 0, 3, 1, 0, VID_R , 1, 0);
711 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
712 ADDENTRY (3, 3, 0, 3, 1, 0, HBP, 0, 0);
wdenk945af8d2003-07-16 21:53:01 +0000713 ADDENTRY (3, 3, 0, 3, 0, 0, VIDEO_COLS*2, 0, 0);
wdenk8564acf2003-07-14 22:13:32 +0000714 ADDENTRY (3, 3, 0, 3, 1, 0, 72, 1, 1);
715
716 ADDENTRY (0, 3, 0, 3, 1, 0, 51, 1, 0);
717 ADDENTRY (0, 3, 0, 3, 1, 0, HPW-1, 0, 0);
718 ADDENTRY (3, 3, 0, 3, 1, 0, HBP +(VIDEO_COLS * 2) + 72 , 1, 0);
719
720 debug ("done\n");
721
722#else /* !CONFIG_RRVISION */
723
wdenk5b1d7132002-11-03 00:07:02 +0000724/*
725 * Hx Vx Fx Bx VDS INT LCYC LP LST
726 *
727 * vertical; blanking
728 */
729 ADDENTRY (0, 0, 0, 0, 1, 0, 22, 1, 0);
730 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
731 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
732 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
733/*
734 * active area (TOP)
735 */
736 if (Y1 > 0) {
737 ADDENTRY (0, 0, 0, 0, 1, 0, Y1, 1, 0); /* 11? */
738 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
739 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
740 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
741 }
742/*
743 * field active area (CENTER)
744 */
745 ADDENTRY (0, 0, 0, 0, 1, 0, 288 - DY, 1, 0); /* 265? */
746 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
747 ADDENTRY (3, 0, 0, 3, 1, 0, 8 + X1, 0, 0);
748 ADDENTRY (3, 0, 0, 3, 0, 0, VIDEO_COLS * 2, 0, 0);
749
750 if (X2 > 0)
751 ADDENTRY (3, 0, 0, 1, 1, 0, X2, 0, 0);
752
753 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
754/*
755 * field active area (BOTTOM)
756 */
757 if (Y2 > 0) {
758 ADDENTRY (0, 0, 0, 0, 1, 0, Y2, 1, 0); /* 12? */
759 ADDENTRY (3, 0, 0, 0, 1, 0, 255, 0, 0);
760 ADDENTRY (3, 0, 0, 3, 1, 0, 1448, 0, 0);
761 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
762 }
763/*
764 * field vertical; blanking
765 */
766 ADDENTRY (0, 0, 0, 0, 1, 0, 2, 1, 0);
767 ADDENTRY (3, 0, 0, 0, 1, 0, 263, 0, 0);
768 ADDENTRY (3, 0, 0, 0, 1, 0, 1440, 0, 0);
769 ADDENTRY (3, 0, 0, 0, 1, 0, 24, 1, 0);
770/*
771 * Create the other field (like this, but whit other field selected,
772 * one more cycle loop and a last identifier)
773 */
774 video_mode_dupefield (vr, &vr[entry], entry);
wdenk8564acf2003-07-14 22:13:32 +0000775#endif /* CONFIG_RRVISION */
776
777#endif /* VIDEO_MODE_PAL */
wdenk5b1d7132002-11-03 00:07:02 +0000778
779 /* See what FIFO are we using */
780 fifo = GETBIT (immap->im_vid.vid_vsr, VIDEO_VSR_CAS);
781
782 /* Set number of lines and burst (only one frame for now) */
783 if (fifo) {
784 immap->im_vid.vid_vfcr0 = VIDEO_BURST_LEN |
785 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
786 } else {
787 immap->im_vid.vid_vfcr1 = VIDEO_BURST_LEN |
788 (VIDEO_BURST_LEN << 8) | ((VIDEO_ROWS / 2) << 19);
789 }
790
791 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_ASEL, !fifo);
792
793/*
794 * Wait until changes are applied (not done)
795 * while (GETBIT(immap->im_vid.vid_vsr, VIDEO_VSR_CAS) == fifo) ;
796 */
797
798 /* Return number of VRAM entries */
799 return entry * 2;
800}
801
802static void video_encoder_init (void)
803{
804#ifdef VIDEO_I2C
805 int rc;
806
807 /* Initialize the I2C */
808 debug ("[VIDEO ENCODER] Initializing I2C bus...\n");
809 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
810
811#ifdef CONFIG_FADS
812 /* Reset ADV7176 chip */
813 debug ("[VIDEO ENCODER] Resetting encoder...\n");
814 (*(int *) BCSR4) &= ~(1 << 21);
815
816 /* Wait for 5 ms inside the reset */
817 debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
818 udelay (5000);
819
820 /* Take ADV7176 out of reset */
821 (*(int *) BCSR4) |= 1 << 21;
822
823 /* Wait for 5 ms after the reset */
824 udelay (5000);
825#endif /* CONFIG_FADS */
826
827 /* Send configuration */
828#ifdef DEBUG
829 {
830 int i;
831
832 puts ("[VIDEO ENCODER] Configuring the encoder...\n");
833
834 printf ("Sending %d bytes (@ %08lX) to I2C 0x%X:\n ",
835 sizeof(video_encoder_data),
836 (ulong)video_encoder_data,
837 VIDEO_I2C_ADDR);
838 for (i=0; i<sizeof(video_encoder_data); ++i) {
839 printf(" %02X", video_encoder_data[i]);
840 }
841 putc ('\n');
842 }
843#endif /* DEBUG */
844
845 if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
846 video_encoder_data,
847 sizeof(video_encoder_data))) != 0) {
848 printf ("i2c_send error: rc=%d\n", rc);
849 return;
850 }
851#endif /* VIDEO_I2C */
852 return;
853}
854
855static void video_ctrl_init (void *memptr)
856{
857 immap_t *immap = (immap_t *) CFG_IMMR;
858
859 video_fb_address = memptr;
860
861 /* Set background */
862 debug ("[VIDEO CTRL] Setting background color...\n");
863 immap->im_vid.vid_vbcb = VIDEO_BG_COL;
864
865 /* Show the background */
866 debug ("[VIDEO CTRL] Forcing background...\n");
867 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
868
869 /* Turn off video controller */
870 debug ("[VIDEO CTRL] Turning off video controller...\n");
871 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
872
873#ifdef CONFIG_FADS
874 /* Turn on Video Port LED */
875 debug ("[VIDEO CTRL] Turning off video port led...\n");
876 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
877
878 /* Disable internal clock */
879 debug ("[VIDEO CTRL] Disabling internal clock...\n");
880 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
881#endif
882
883 /* Generate and make active a new video mode */
884 debug ("[VIDEO CTRL] Generating video mode...\n");
885 video_mode_generate ();
886
887 /* Start of frame buffer (even and odd frame, to make it working with */
888 /* any selected active set) */
889 debug ("[VIDEO CTRL] Setting frame buffer address...\n");
890 immap->im_vid.vid_vfaa1 =
891 immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
892 immap->im_vid.vid_vfba1 =
893 immap->im_vid.vid_vfba0 =
894 (u32) video_fb_address + VIDEO_LINE_LEN;
895
896 /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
897 debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
898 immap->im_vid.vid_vccr = 0x2042;
899
900 /* Configure port pins */
901 debug ("[VIDEO CTRL] Configuring input/output pins...\n");
902 immap->im_ioport.iop_pdpar = 0x1fff;
903 immap->im_ioport.iop_pddir = 0x0000;
904
905#ifdef CONFIG_FADS
906 /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
907 debug ("[VIDEO CTRL] Turning on video clock...\n");
908 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
909
910 /* Turn on Video Port LED */
911 debug ("[VIDEO CTRL] Turning on video port led...\n");
912 SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
913#endif
wdenk5b1d7132002-11-03 00:07:02 +0000914#ifdef CONFIG_RRVISION
wdenk8564acf2003-07-14 22:13:32 +0000915 debug ("PC5->Output(1): enable PAL clock");
916 immap->im_ioport.iop_pcpar &= ~(0x0400);
917 immap->im_ioport.iop_pcdir |= 0x0400 ;
918 immap->im_ioport.iop_pcdat |= 0x0400 ;
919 debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
920 immap->im_ioport.iop_pdpar,
921 immap->im_ioport.iop_pddir,
922 immap->im_ioport.iop_pddat);
923 debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
924 immap->im_ioport.iop_pcpar,
925 immap->im_ioport.iop_pcdir,
926 immap->im_ioport.iop_pcdat);
wdenk5b1d7132002-11-03 00:07:02 +0000927#endif /* CONFIG_RRVISION */
928
929 /* Blanking the screen. */
930 debug ("[VIDEO CTRL] Blanking the screen...\n");
931 video_fill (VIDEO_BG_COL);
932
wdenk8bde7f72003-06-27 21:31:46 +0000933 /*
934 * Turns on Aggressive Mode. Normally, turning on the caches
935 * will cause the screen to flicker when the caches try to
936 * fill. This gives the FIFO's for the Video Controller
937 * higher priority and prevents flickering because of
938 * underrun. This may still be an issue when using FLASH,
939 * since accessing data from Flash is so slow.
wdenk5b1d7132002-11-03 00:07:02 +0000940 */
941 debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
942 immap->im_siu_conf.sc_sdcr = 0x40;
943
944 /* Turn on video controller */
945 debug ("[VIDEO CTRL] Turning on video controller...\n");
946 SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
947
948 /* Show the display */
949 debug ("[VIDEO CTRL] Enabling the video...\n");
950 SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
951}
952
953/************************************************************************/
954/* ** CONSOLE FUNCTIONS */
955/************************************************************************/
956
957static void console_scrollup (void)
958{
959 /* Copy up rows ignoring the first one */
960 memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
961
962 /* Clear the last one */
963 memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
964}
965
966static inline void console_back (void)
967{
968 console_col--;
969
970 if (console_col < 0) {
971 console_col = CONSOLE_COLS - 1;
972 console_row--;
973 if (console_row < 0)
974 console_row = 0;
975 }
976
977 video_putchar ( console_col * VIDEO_FONT_WIDTH,
978 console_row * VIDEO_FONT_HEIGHT, ' ');
979}
980
981static inline void console_newline (void)
982{
983 console_row++;
984 console_col = 0;
985
986 /* Check if we need to scroll the terminal */
987 if (console_row >= CONSOLE_ROWS) {
988 /* Scroll everything up */
989 console_scrollup ();
990
991 /* Decrement row number */
992 console_row--;
993 }
994}
995
996void video_putc (const char c)
997{
998 if (!video_enable) {
999 serial_putc (c);
1000 return;
1001 }
1002
1003 switch (c) {
1004 case 13: /* Simply ignore this */
1005 break;
1006
1007 case '\n': /* Next line, please */
1008 console_newline ();
1009 break;
1010
1011 case 9: /* Tab (8 chars alignment) */
1012 console_col |= 0x0008; /* Next 8 chars boundary */
1013 console_col &= ~0x0007; /* Set this bit to zero */
1014
1015 if (console_col >= CONSOLE_COLS)
1016 console_newline ();
1017 break;
1018
1019 case 8: /* Eat last character */
1020 console_back ();
1021 break;
1022
1023 default: /* Add to the console */
1024 video_putchar ( console_col * VIDEO_FONT_WIDTH,
1025 console_row * VIDEO_FONT_HEIGHT, c);
1026 console_col++;
1027 /* Check if we need to go to next row */
1028 if (console_col >= CONSOLE_COLS)
1029 console_newline ();
1030 }
1031}
1032
1033void video_puts (const char *s)
1034{
1035 int count = strlen (s);
1036
1037 if (!video_enable)
1038 while (count--)
1039 serial_putc (*s++);
1040 else
1041 while (count--)
1042 video_putc (*s++);
1043}
1044
1045/************************************************************************/
1046/* ** CURSOR BLINKING FUNCTIONS */
1047/************************************************************************/
1048
1049#ifdef VIDEO_BLINK
1050
1051#define BLINK_TIMER_ID 0
1052#define BLINK_TIMER_HZ 2
1053
1054static unsigned char blink_enabled = 0;
1055static timer_t blink_timer;
1056
1057static void blink_update (void)
1058{
1059 static int blink_row = -1, blink_col = -1, blink_old = 0;
1060
1061 /* Check if we have a new position to invert */
1062 if ((console_row != blink_row) || (console_col != blink_col)) {
1063 /* Check if we need to reverse last character */
1064 if (blink_old)
1065 video_revchar ( blink_col * VIDEO_FONT_WIDTH,
1066 (blink_row
1067#ifdef CONFIG_VIDEO_LOGO
1068 + VIDEO_LOGO_HEIGHT
1069#endif
1070 ) * VIDEO_FONT_HEIGHT);
1071
1072 /* Update values */
1073 blink_row = console_row;
1074 blink_col = console_col;
1075 blink_old = 0;
1076 }
1077
1078/* Reverse this character */
1079 blink_old = !blink_old;
1080 video_revchar ( console_col * VIDEO_FONT_WIDTH,
1081 (console_row
1082#ifdef CONFIG_VIDEO_LOGO
1083 + VIDEO_LOGO_HEIGHT
1084#endif
1085 ) * VIDEO_FONT_HEIGHT);
1086
1087}
1088
1089/*
1090 * Handler for blinking cursor
1091 */
1092static void blink_handler (void *arg)
1093{
1094/* Blink */
1095 blink_update ();
1096/* Ack the timer */
1097 timer_ack (&blink_timer);
1098}
1099
1100int blink_set (int blink)
1101{
1102 int ret = blink_enabled;
1103
1104 if (blink)
1105 timer_enable (&blink_timer);
1106 else
1107 timer_disable (&blink_timer);
1108
1109 blink_enabled = blink;
1110
1111 return ret;
1112}
1113
1114static inline void blink_close (void)
1115{
1116 timer_close (&blink_timer);
1117}
1118
1119static inline void blink_init (void)
1120{
1121 timer_init (&blink_timer,
1122 BLINK_TIMER_ID, BLINK_TIMER_HZ,
1123 blink_handler);
1124}
1125#endif
1126
1127/************************************************************************/
1128/* ** LOGO PLOTTING FUNCTIONS */
1129/************************************************************************/
1130
1131#ifdef CONFIG_VIDEO_LOGO
1132void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
1133 int y)
1134{
1135 int skip = width - image->width, xcount, ycount = image->height;
1136
1137#ifdef VIDEO_MODE_YUYV
1138 ushort *source = (ushort *) image->data;
1139 ushort *dest = (ushort *) screen + y * width + x;
1140
1141 while (ycount--) {
1142 xcount = image->width;
1143 while (xcount--)
1144 *dest++ = *source++;
1145 dest += skip;
1146 }
1147#endif
1148#ifdef VIDEO_MODE_RGB
1149 unsigned char
1150 *source = (unsigned short *) image->data,
1151 *dest = (unsigned short *) screen + ((y * width) + x) * 3;
1152
1153 while (ycount--) {
1154 xcount = image->width * 3;
1155 memcpy (dest, source, xcount);
1156 source += xcount;
1157 dest += ycount;
1158 }
1159#endif
1160}
1161
1162static void *video_logo (void)
1163{
1164 u16 *screen = video_fb_address, width = VIDEO_COLS;
1165#ifdef VIDEO_INFO
1166# ifndef CONFIG_FADS
1167 DECLARE_GLOBAL_DATA_PTR;
1168 char temp[32];
1169# endif
1170 char info[80];
1171#endif /* VIDEO_INFO */
1172
1173 easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
1174
1175#ifdef VIDEO_INFO
1176 sprintf (info, "%s (%s - %s) ", U_BOOT_VERSION, __DATE__, __TIME__);
1177 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
1178
1179 sprintf (info, "(C) 2002 DENX Software Engineering");
1180 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1181 info);
1182
1183 sprintf (info, " Wolfgang DENK, wd@denx.de");
1184 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1185 info);
1186#ifndef CONFIG_FADS /* all normal boards */
1187 /* leave one blank line */
1188
1189 sprintf (info, "MPC823 CPU at %s MHz, %ld MB RAM, %ld MB Flash",
1190 strmhz(temp, gd->cpu_clk),
1191 gd->ram_size >> 20,
1192 gd->bd->bi_flashsize >> 20 );
1193 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
1194 info);
1195#else /* FADS :-( */
1196 sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
1197 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
1198 info);
1199
1200 sprintf (info, "2MB FLASH - 8MB DRAM - 4MB SRAM");
1201 video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
1202 info);
1203#endif
1204#endif
1205
1206 return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
1207}
1208#endif
1209
1210/************************************************************************/
1211/* ** VIDEO HIGH-LEVEL FUNCTIONS */
1212/************************************************************************/
1213
1214static int video_init (void *videobase)
1215{
1216 /* Initialize the encoder */
1217 debug ("[VIDEO] Initializing video encoder...\n");
1218 video_encoder_init ();
1219
1220 /* Initialize the video controller */
1221 debug ("[VIDEO] Initializing video controller at %08x...\n",
1222 (int) videobase);
1223 video_ctrl_init (videobase);
1224
1225 /* Setting the palette */
1226 video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
1227 video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
1228 video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
1229 video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
1230 video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
1231 video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
1232 video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
1233 video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
1234 video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
1235 video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
1236
1237#ifndef CFG_WHITE_ON_BLACK
1238 video_setfgcolor (CONSOLE_COLOR_BLACK);
1239 video_setbgcolor (CONSOLE_COLOR_GREY2);
1240#else
1241 video_setfgcolor (CONSOLE_COLOR_GREY2);
1242 video_setbgcolor (CONSOLE_COLOR_BLACK);
1243#endif /* CFG_WHITE_ON_BLACK */
1244
1245#ifdef CONFIG_VIDEO_LOGO
1246 /* Paint the logo and retrieve tv base address */
1247 debug ("[VIDEO] Drawing the logo...\n");
1248 video_console_address = video_logo ();
1249#else
1250 video_console_address = video_fb_address;
1251#endif
1252
1253#ifdef VIDEO_BLINK
1254 /* Enable the blinking (under construction) */
1255 blink_init ();
1256 blink_set (0); /* To Fix! */
1257#endif
1258
1259 /* Initialize the console */
1260 console_col = 0;
1261 console_row = 0;
1262 video_enable = 1;
1263
1264#ifdef VIDEO_MODE_PAL
1265# define VIDEO_MODE_TMP1 "PAL"
1266#endif
1267#ifdef VIDEO_MODE_NTSC
1268# define VIDEO_MODE_TMP1 "NTSC"
1269#endif
1270#ifdef VIDEO_MODE_YUYV
1271# define VIDEO_MODE_TMP2 "YCbYCr"
1272#endif
1273#ifdef VIDEO_MODE_RGB
1274# define VIDEO_MODE_TMP2 "RGB"
1275#endif
1276 debug ( VIDEO_MODE_TMP1
1277 " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
1278 VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
1279 VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
1280 return 0;
1281}
1282
1283int drv_video_init (void)
1284{
1285 DECLARE_GLOBAL_DATA_PTR;
1286
1287 int error, devices = 1;
1288
1289 device_t videodev;
1290
1291 video_init ((void *)(gd->fb_base)); /* Video initialization */
1292
1293/* Device initialization */
1294
1295 memset (&videodev, 0, sizeof (videodev));
1296
1297 strcpy (videodev.name, "video");
1298 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
1299 videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
1300 videodev.putc = video_putc; /* 'putc' function */
1301 videodev.puts = video_puts; /* 'puts' function */
1302
1303 error = device_register (&videodev);
1304
1305 return (error == 0) ? devices : error;
1306}
1307
1308/************************************************************************/
1309/* ** ROM capable initialization part - needed to reserve FB memory */
1310/************************************************************************/
1311
1312/*
1313 * This is called early in the system initialization to grab memory
1314 * for the video controller.
1315 * Returns new address for monitor, after reserving video buffer memory
1316 *
1317 * Note that this is running from ROM, so no write access to global data.
1318 */
1319ulong video_setmem (ulong addr)
1320{
1321 /* Allocate pages for the frame buffer. */
1322 addr -= VIDEO_SIZE;
1323
1324 debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
1325 VIDEO_SIZE>>10, addr);
1326
1327 return (addr);
1328}
1329
wdenk5b1d7132002-11-03 00:07:02 +00001330#endif