video.c 30 KB

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