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