video.c 34 KB

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