video.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. #ifdef CONFIG_FADS
  668. /* Reset ADV7176 chip */
  669. debug ("[VIDEO ENCODER] Resetting encoder...\n");
  670. (*(int *) BCSR4) &= ~(1 << 21);
  671. /* Wait for 5 ms inside the reset */
  672. debug ("[VIDEO ENCODER] Waiting for encoder reset...\n");
  673. udelay (5000);
  674. /* Take ADV7176 out of reset */
  675. (*(int *) BCSR4) |= 1 << 21;
  676. /* Wait for 5 ms after the reset */
  677. udelay (5000);
  678. #endif /* CONFIG_FADS */
  679. /* Send configuration */
  680. #ifdef DEBUG
  681. {
  682. int i;
  683. puts ("[VIDEO ENCODER] Configuring the encoder...\n");
  684. printf ("Sending %zu bytes (@ %08lX) to I2C 0x%lX:\n ",
  685. sizeof(video_encoder_data),
  686. (ulong)video_encoder_data,
  687. (ulong)VIDEO_I2C_ADDR);
  688. for (i=0; i<sizeof(video_encoder_data); ++i) {
  689. printf(" %02X", video_encoder_data[i]);
  690. }
  691. putc ('\n');
  692. }
  693. #endif /* DEBUG */
  694. if ((rc = i2c_write (VIDEO_I2C_ADDR, 0, 1,
  695. video_encoder_data,
  696. sizeof(video_encoder_data))) != 0) {
  697. printf ("i2c_send error: rc=%d\n", rc);
  698. return;
  699. }
  700. #endif /* VIDEO_I2C */
  701. return;
  702. }
  703. static void video_ctrl_init (void *memptr)
  704. {
  705. immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  706. video_fb_address = memptr;
  707. /* Set background */
  708. debug ("[VIDEO CTRL] Setting background color...\n");
  709. immap->im_vid.vid_vbcb = VIDEO_BG_COL;
  710. /* Show the background */
  711. debug ("[VIDEO CTRL] Forcing background...\n");
  712. SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 1);
  713. /* Turn off video controller */
  714. debug ("[VIDEO CTRL] Turning off video controller...\n");
  715. SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 0);
  716. #ifdef CONFIG_FADS
  717. /* Turn on Video Port LED */
  718. debug ("[VIDEO CTRL] Turning off video port led...\n");
  719. SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 1);
  720. /* Disable internal clock */
  721. debug ("[VIDEO CTRL] Disabling internal clock...\n");
  722. SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 0);
  723. #endif
  724. /* Generate and make active a new video mode */
  725. debug ("[VIDEO CTRL] Generating video mode...\n");
  726. video_mode_generate ();
  727. /* Start of frame buffer (even and odd frame, to make it working with */
  728. /* any selected active set) */
  729. debug ("[VIDEO CTRL] Setting frame buffer address...\n");
  730. immap->im_vid.vid_vfaa1 =
  731. immap->im_vid.vid_vfaa0 = (u32) video_fb_address;
  732. immap->im_vid.vid_vfba1 =
  733. immap->im_vid.vid_vfba0 =
  734. (u32) video_fb_address + VIDEO_LINE_LEN;
  735. /* YUV, Big endian, SHIFT/CLK/CLK input (BEFORE ENABLING 27MHZ EXT CLOCK) */
  736. debug ("[VIDEO CTRL] Setting pixel mode and clocks...\n");
  737. immap->im_vid.vid_vccr = 0x2042;
  738. /* Configure port pins */
  739. debug ("[VIDEO CTRL] Configuring input/output pins...\n");
  740. immap->im_ioport.iop_pdpar = 0x1fff;
  741. immap->im_ioport.iop_pddir = 0x0000;
  742. #ifdef CONFIG_FADS
  743. /* Turn on Video Port Clock - ONLY AFTER SET VCCR TO ENABLE EXTERNAL CLOCK */
  744. debug ("[VIDEO CTRL] Turning on video clock...\n");
  745. SETBIT (*(int *) BCSR4, VIDEO_BCSR4_EXTCLK_BIT, 1);
  746. /* Turn on Video Port LED */
  747. debug ("[VIDEO CTRL] Turning on video port led...\n");
  748. SETBIT (*(int *) BCSR4, VIDEO_BCSR4_VIDLED_BIT, 0);
  749. #endif
  750. #ifdef CONFIG_RRVISION
  751. debug ("PC5->Output(1): enable PAL clock");
  752. immap->im_ioport.iop_pcpar &= ~(0x0400);
  753. immap->im_ioport.iop_pcdir |= 0x0400 ;
  754. immap->im_ioport.iop_pcdat |= 0x0400 ;
  755. debug ("PDPAR=0x%04X PDDIR=0x%04X PDDAT=0x%04X\n",
  756. immap->im_ioport.iop_pdpar,
  757. immap->im_ioport.iop_pddir,
  758. immap->im_ioport.iop_pddat);
  759. debug ("PCPAR=0x%04X PCDIR=0x%04X PCDAT=0x%04X\n",
  760. immap->im_ioport.iop_pcpar,
  761. immap->im_ioport.iop_pcdir,
  762. immap->im_ioport.iop_pcdat);
  763. #endif /* CONFIG_RRVISION */
  764. /* Blanking the screen. */
  765. debug ("[VIDEO CTRL] Blanking the screen...\n");
  766. video_fill (VIDEO_BG_COL);
  767. /*
  768. * Turns on Aggressive Mode. Normally, turning on the caches
  769. * will cause the screen to flicker when the caches try to
  770. * fill. This gives the FIFO's for the Video Controller
  771. * higher priority and prevents flickering because of
  772. * underrun. This may still be an issue when using FLASH,
  773. * since accessing data from Flash is so slow.
  774. */
  775. debug ("[VIDEO CTRL] Turning on aggressive mode...\n");
  776. immap->im_siu_conf.sc_sdcr = 0x40;
  777. /* Turn on video controller */
  778. debug ("[VIDEO CTRL] Turning on video controller...\n");
  779. SETBIT (immap->im_vid.vid_vccr, VIDEO_VCCR_VON, 1);
  780. /* Show the display */
  781. debug ("[VIDEO CTRL] Enabling the video...\n");
  782. SETBIT (immap->im_vid.vid_vcmr, VIDEO_VCMR_BD, 0);
  783. }
  784. /************************************************************************/
  785. /* ** CONSOLE FUNCTIONS */
  786. /************************************************************************/
  787. static void console_scrollup (void)
  788. {
  789. /* Copy up rows ignoring the first one */
  790. memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE >> 2);
  791. /* Clear the last one */
  792. memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, VIDEO_BG_COL);
  793. }
  794. static inline void console_back (void)
  795. {
  796. console_col--;
  797. if (console_col < 0) {
  798. console_col = CONSOLE_COLS - 1;
  799. console_row--;
  800. if (console_row < 0)
  801. console_row = 0;
  802. }
  803. video_putchar ( console_col * VIDEO_FONT_WIDTH,
  804. console_row * VIDEO_FONT_HEIGHT, ' ');
  805. }
  806. static inline void console_newline (void)
  807. {
  808. console_row++;
  809. console_col = 0;
  810. /* Check if we need to scroll the terminal */
  811. if (console_row >= CONSOLE_ROWS) {
  812. /* Scroll everything up */
  813. console_scrollup ();
  814. /* Decrement row number */
  815. console_row--;
  816. }
  817. }
  818. void video_putc (const char c)
  819. {
  820. if (!video_enable) {
  821. serial_putc (c);
  822. return;
  823. }
  824. switch (c) {
  825. case 13: /* Simply ignore this */
  826. break;
  827. case '\n': /* Next line, please */
  828. console_newline ();
  829. break;
  830. case 9: /* Tab (8 chars alignment) */
  831. console_col |= 0x0008; /* Next 8 chars boundary */
  832. console_col &= ~0x0007; /* Set this bit to zero */
  833. if (console_col >= CONSOLE_COLS)
  834. console_newline ();
  835. break;
  836. case 8: /* Eat last character */
  837. console_back ();
  838. break;
  839. default: /* Add to the console */
  840. video_putchar ( console_col * VIDEO_FONT_WIDTH,
  841. console_row * VIDEO_FONT_HEIGHT, c);
  842. console_col++;
  843. /* Check if we need to go to next row */
  844. if (console_col >= CONSOLE_COLS)
  845. console_newline ();
  846. }
  847. }
  848. void video_puts (const char *s)
  849. {
  850. int count = strlen (s);
  851. if (!video_enable)
  852. while (count--)
  853. serial_putc (*s++);
  854. else
  855. while (count--)
  856. video_putc (*s++);
  857. }
  858. /************************************************************************/
  859. /* ** CURSOR BLINKING FUNCTIONS */
  860. /************************************************************************/
  861. #ifdef VIDEO_BLINK
  862. #define BLINK_TIMER_ID 0
  863. #define BLINK_TIMER_HZ 2
  864. static unsigned char blink_enabled = 0;
  865. static timer_t blink_timer;
  866. static void blink_update (void)
  867. {
  868. static int blink_row = -1, blink_col = -1, blink_old = 0;
  869. /* Check if we have a new position to invert */
  870. if ((console_row != blink_row) || (console_col != blink_col)) {
  871. /* Check if we need to reverse last character */
  872. if (blink_old)
  873. video_revchar ( blink_col * VIDEO_FONT_WIDTH,
  874. (blink_row
  875. #ifdef CONFIG_VIDEO_LOGO
  876. + VIDEO_LOGO_HEIGHT
  877. #endif
  878. ) * VIDEO_FONT_HEIGHT);
  879. /* Update values */
  880. blink_row = console_row;
  881. blink_col = console_col;
  882. blink_old = 0;
  883. }
  884. /* Reverse this character */
  885. blink_old = !blink_old;
  886. video_revchar ( console_col * VIDEO_FONT_WIDTH,
  887. (console_row
  888. #ifdef CONFIG_VIDEO_LOGO
  889. + VIDEO_LOGO_HEIGHT
  890. #endif
  891. ) * VIDEO_FONT_HEIGHT);
  892. }
  893. /*
  894. * Handler for blinking cursor
  895. */
  896. static void blink_handler (void *arg)
  897. {
  898. /* Blink */
  899. blink_update ();
  900. /* Ack the timer */
  901. timer_ack (&blink_timer);
  902. }
  903. int blink_set (int blink)
  904. {
  905. int ret = blink_enabled;
  906. if (blink)
  907. timer_enable (&blink_timer);
  908. else
  909. timer_disable (&blink_timer);
  910. blink_enabled = blink;
  911. return ret;
  912. }
  913. static inline void blink_close (void)
  914. {
  915. timer_close (&blink_timer);
  916. }
  917. static inline void blink_init (void)
  918. {
  919. timer_init (&blink_timer,
  920. BLINK_TIMER_ID, BLINK_TIMER_HZ,
  921. blink_handler);
  922. }
  923. #endif
  924. /************************************************************************/
  925. /* ** LOGO PLOTTING FUNCTIONS */
  926. /************************************************************************/
  927. #ifdef CONFIG_VIDEO_LOGO
  928. void easylogo_plot (fastimage_t * image, void *screen, int width, int x,
  929. int y)
  930. {
  931. int skip = width - image->width, xcount, ycount = image->height;
  932. #ifdef VIDEO_MODE_YUYV
  933. ushort *source = (ushort *) image->data;
  934. ushort *dest = (ushort *) screen + y * width + x;
  935. while (ycount--) {
  936. xcount = image->width;
  937. while (xcount--)
  938. *dest++ = *source++;
  939. dest += skip;
  940. }
  941. #endif
  942. #ifdef VIDEO_MODE_RGB
  943. unsigned char
  944. *source = (unsigned short *) image->data,
  945. *dest = (unsigned short *) screen + ((y * width) + x) * 3;
  946. while (ycount--) {
  947. xcount = image->width * 3;
  948. memcpy (dest, source, xcount);
  949. source += xcount;
  950. dest += ycount;
  951. }
  952. #endif
  953. }
  954. static void *video_logo (void)
  955. {
  956. u16 *screen = video_fb_address, width = VIDEO_COLS;
  957. #ifdef VIDEO_INFO
  958. # ifndef CONFIG_FADS
  959. char temp[32];
  960. # endif
  961. char info[80];
  962. #endif /* VIDEO_INFO */
  963. easylogo_plot (VIDEO_LOGO_ADDR, screen, width, 0, 0);
  964. #ifdef VIDEO_INFO
  965. sprintf (info, "%s (%s - %s) ",
  966. U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
  967. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
  968. sprintf (info, "(C) 2002 DENX Software Engineering");
  969. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
  970. info);
  971. sprintf (info, " Wolfgang DENK, wd@denx.de");
  972. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
  973. info);
  974. #ifndef CONFIG_FADS /* all normal boards */
  975. /* leave one blank line */
  976. sprintf(info, "MPC823 CPU at %s MHz, %ld MiB RAM, %ld MiB Flash",
  977. strmhz(temp, gd->cpu_clk),
  978. gd->ram_size >> 20,
  979. gd->bd->bi_flashsize >> 20 );
  980. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 4,
  981. info);
  982. #else /* FADS :-( */
  983. sprintf (info, "MPC823 CPU at 50 MHz on FADS823 board");
  984. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
  985. info);
  986. sprintf(info, "2MiB FLASH - 8MiB DRAM - 4MiB SRAM");
  987. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
  988. info);
  989. #endif
  990. #endif
  991. return video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN;
  992. }
  993. #endif
  994. /************************************************************************/
  995. /* ** VIDEO HIGH-LEVEL FUNCTIONS */
  996. /************************************************************************/
  997. static int video_init (void *videobase)
  998. {
  999. /* Initialize the encoder */
  1000. debug ("[VIDEO] Initializing video encoder...\n");
  1001. video_encoder_init ();
  1002. /* Initialize the video controller */
  1003. debug ("[VIDEO] Initializing video controller at %08x...\n",
  1004. (int) videobase);
  1005. video_ctrl_init (videobase);
  1006. /* Setting the palette */
  1007. video_setpalette (CONSOLE_COLOR_BLACK, 0, 0, 0);
  1008. video_setpalette (CONSOLE_COLOR_RED, 0xFF, 0, 0);
  1009. video_setpalette (CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
  1010. video_setpalette (CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
  1011. video_setpalette (CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
  1012. video_setpalette (CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
  1013. video_setpalette (CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
  1014. video_setpalette (CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
  1015. video_setpalette (CONSOLE_COLOR_GREY2, 0xF8, 0xF8, 0xF8);
  1016. video_setpalette (CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
  1017. #ifndef CONFIG_SYS_WHITE_ON_BLACK
  1018. video_setfgcolor (CONSOLE_COLOR_BLACK);
  1019. video_setbgcolor (CONSOLE_COLOR_GREY2);
  1020. #else
  1021. video_setfgcolor (CONSOLE_COLOR_GREY2);
  1022. video_setbgcolor (CONSOLE_COLOR_BLACK);
  1023. #endif /* CONFIG_SYS_WHITE_ON_BLACK */
  1024. #ifdef CONFIG_VIDEO_LOGO
  1025. /* Paint the logo and retrieve tv base address */
  1026. debug ("[VIDEO] Drawing the logo...\n");
  1027. video_console_address = video_logo ();
  1028. #else
  1029. video_console_address = video_fb_address;
  1030. #endif
  1031. #ifdef VIDEO_BLINK
  1032. /* Enable the blinking (under construction) */
  1033. blink_init ();
  1034. blink_set (0); /* To Fix! */
  1035. #endif
  1036. /* Initialize the console */
  1037. console_col = 0;
  1038. console_row = 0;
  1039. video_enable = 1;
  1040. #ifdef VIDEO_MODE_PAL
  1041. # define VIDEO_MODE_TMP1 "PAL"
  1042. #endif
  1043. #ifdef VIDEO_MODE_NTSC
  1044. # define VIDEO_MODE_TMP1 "NTSC"
  1045. #endif
  1046. #ifdef VIDEO_MODE_YUYV
  1047. # define VIDEO_MODE_TMP2 "YCbYCr"
  1048. #endif
  1049. #ifdef VIDEO_MODE_RGB
  1050. # define VIDEO_MODE_TMP2 "RGB"
  1051. #endif
  1052. debug ( VIDEO_MODE_TMP1
  1053. " %dx%dx%d (" VIDEO_MODE_TMP2 ") on %s - console %dx%d\n",
  1054. VIDEO_COLS, VIDEO_ROWS, VIDEO_MODE_BPP,
  1055. VIDEO_ENCODER_NAME, CONSOLE_COLS, CONSOLE_ROWS);
  1056. return 0;
  1057. }
  1058. int drv_video_init (void)
  1059. {
  1060. int error, devices = 1;
  1061. struct stdio_dev videodev;
  1062. video_init ((void *)(gd->fb_base)); /* Video initialization */
  1063. /* Device initialization */
  1064. memset (&videodev, 0, sizeof (videodev));
  1065. strcpy (videodev.name, "video");
  1066. videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
  1067. videodev.flags = DEV_FLAGS_OUTPUT; /* Output only */
  1068. videodev.putc = video_putc; /* 'putc' function */
  1069. videodev.puts = video_puts; /* 'puts' function */
  1070. error = stdio_register (&videodev);
  1071. return (error == 0) ? devices : error;
  1072. }
  1073. /************************************************************************/
  1074. /* ** ROM capable initialization part - needed to reserve FB memory */
  1075. /************************************************************************/
  1076. /*
  1077. * This is called early in the system initialization to grab memory
  1078. * for the video controller.
  1079. * Returns new address for monitor, after reserving video buffer memory
  1080. *
  1081. * Note that this is running from ROM, so no write access to global data.
  1082. */
  1083. ulong video_setmem (ulong addr)
  1084. {
  1085. /* Allocate pages for the frame buffer. */
  1086. addr -= VIDEO_SIZE;
  1087. debug ("Reserving %dk for Video Framebuffer at: %08lx\n",
  1088. VIDEO_SIZE>>10, addr);
  1089. return (addr);
  1090. }
  1091. #endif