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