video.c 34 KB

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