video.c 36 KB

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