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