video.c 36 KB

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