video.c 33 KB

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