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