video.c 36 KB

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