PageRenderTime 50ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/source/u-boot/cpu/mpc8xx/video.c

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