zoran_device.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. /*
  2. * Zoran zr36057/zr36067 PCI controller driver, for the
  3. * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
  4. * Media Labs LML33/LML33R10.
  5. *
  6. * This part handles device access (PCI/I2C/codec/...)
  7. *
  8. * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
  9. *
  10. * Currently maintained by:
  11. * Ronald Bultje <rbultje@ronald.bitfreak.net>
  12. * Laurent Pinchart <laurent.pinchart@skynet.be>
  13. * Mailinglist <mjpeg-users@lists.sf.net>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. #include <linux/types.h>
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/vmalloc.h>
  33. #include <linux/byteorder/generic.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/i2c.h>
  37. #include <linux/i2c-algo-bit.h>
  38. #include <linux/videodev.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/sem.h>
  41. #include <linux/pci.h>
  42. #include <linux/video_decoder.h>
  43. #include <linux/video_encoder.h>
  44. #include <linux/delay.h>
  45. #include <linux/wait.h>
  46. #include <asm/io.h>
  47. #include "videocodec.h"
  48. #include "zoran.h"
  49. #include "zoran_device.h"
  50. #define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
  51. ZR36057_ISR_GIRQ1 | \
  52. ZR36057_ISR_JPEGRepIRQ )
  53. extern const struct zoran_format zoran_formats[];
  54. extern int *zr_debug;
  55. #define dprintk(num, format, args...) \
  56. do { \
  57. if (*zr_debug >= num) \
  58. printk(format, ##args); \
  59. } while (0)
  60. static int lml33dpath = 0; /* 1 will use digital path in capture
  61. * mode instead of analog. It can be
  62. * used for picture adjustments using
  63. * tool like xawtv while watching image
  64. * on TV monitor connected to the output.
  65. * However, due to absence of 75 Ohm
  66. * load on Bt819 input, there will be
  67. * some image imperfections */
  68. module_param(lml33dpath, bool, 0);
  69. MODULE_PARM_DESC(lml33dpath,
  70. "Use digital path capture mode (on LML33 cards)");
  71. static void
  72. zr36057_init_vfe (struct zoran *zr);
  73. /*
  74. * General Purpose I/O and Guest bus access
  75. */
  76. /*
  77. * This is a bit tricky. When a board lacks a GPIO function, the corresponding
  78. * GPIO bit number in the card_info structure is set to 0.
  79. */
  80. void
  81. GPIO (struct zoran *zr,
  82. int bit,
  83. unsigned int value)
  84. {
  85. u32 reg;
  86. u32 mask;
  87. /* Make sure the bit number is legal
  88. * A bit number of -1 (lacking) gives a mask of 0,
  89. * making it harmless */
  90. mask = (1 << (24 + bit)) & 0xff000000;
  91. reg = btread(ZR36057_GPPGCR1) & ~mask;
  92. if (value) {
  93. reg |= mask;
  94. }
  95. btwrite(reg, ZR36057_GPPGCR1);
  96. udelay(1);
  97. }
  98. /*
  99. * Wait til post office is no longer busy
  100. */
  101. int
  102. post_office_wait (struct zoran *zr)
  103. {
  104. u32 por;
  105. // while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
  106. while ((por = btread(ZR36057_POR)) & ZR36057_POR_POPen) {
  107. /* wait for something to happen */
  108. }
  109. if ((por & ZR36057_POR_POTime) && !zr->card.gws_not_connected) {
  110. /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
  111. dprintk(1, KERN_INFO "%s: pop timeout %08x\n", ZR_DEVNAME(zr),
  112. por);
  113. return -1;
  114. }
  115. return 0;
  116. }
  117. int
  118. post_office_write (struct zoran *zr,
  119. unsigned int guest,
  120. unsigned int reg,
  121. unsigned int value)
  122. {
  123. u32 por;
  124. por =
  125. ZR36057_POR_PODir | ZR36057_POR_POTime | ((guest & 7) << 20) |
  126. ((reg & 7) << 16) | (value & 0xFF);
  127. btwrite(por, ZR36057_POR);
  128. return post_office_wait(zr);
  129. }
  130. int
  131. post_office_read (struct zoran *zr,
  132. unsigned int guest,
  133. unsigned int reg)
  134. {
  135. u32 por;
  136. por = ZR36057_POR_POTime | ((guest & 7) << 20) | ((reg & 7) << 16);
  137. btwrite(por, ZR36057_POR);
  138. if (post_office_wait(zr) < 0) {
  139. return -1;
  140. }
  141. return btread(ZR36057_POR) & 0xFF;
  142. }
  143. /*
  144. * detect guests
  145. */
  146. static void
  147. dump_guests (struct zoran *zr)
  148. {
  149. if (*zr_debug > 2) {
  150. int i, guest[8];
  151. for (i = 1; i < 8; i++) { // Don't read jpeg codec here
  152. guest[i] = post_office_read(zr, i, 0);
  153. }
  154. printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
  155. for (i = 1; i < 8; i++) {
  156. printk(" 0x%02x", guest[i]);
  157. }
  158. printk("\n");
  159. }
  160. }
  161. static inline unsigned long
  162. get_time (void)
  163. {
  164. struct timeval tv;
  165. do_gettimeofday(&tv);
  166. return (1000000 * tv.tv_sec + tv.tv_usec);
  167. }
  168. void
  169. detect_guest_activity (struct zoran *zr)
  170. {
  171. int timeout, i, j, res, guest[8], guest0[8], change[8][3];
  172. unsigned long t0, t1;
  173. dump_guests(zr);
  174. printk(KERN_INFO "%s: Detecting guests activity, please wait...\n",
  175. ZR_DEVNAME(zr));
  176. for (i = 1; i < 8; i++) { // Don't read jpeg codec here
  177. guest0[i] = guest[i] = post_office_read(zr, i, 0);
  178. }
  179. timeout = 0;
  180. j = 0;
  181. t0 = get_time();
  182. while (timeout < 10000) {
  183. udelay(10);
  184. timeout++;
  185. for (i = 1; (i < 8) && (j < 8); i++) {
  186. res = post_office_read(zr, i, 0);
  187. if (res != guest[i]) {
  188. t1 = get_time();
  189. change[j][0] = (t1 - t0);
  190. t0 = t1;
  191. change[j][1] = i;
  192. change[j][2] = res;
  193. j++;
  194. guest[i] = res;
  195. }
  196. }
  197. if (j >= 8)
  198. break;
  199. }
  200. printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
  201. for (i = 1; i < 8; i++) {
  202. printk(" 0x%02x", guest0[i]);
  203. }
  204. printk("\n");
  205. if (j == 0) {
  206. printk(KERN_INFO "%s: No activity detected.\n", ZR_DEVNAME(zr));
  207. return;
  208. }
  209. for (i = 0; i < j; i++) {
  210. printk(KERN_INFO "%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr),
  211. change[i][0], change[i][1], change[i][2]);
  212. }
  213. }
  214. /*
  215. * JPEG Codec access
  216. */
  217. void
  218. jpeg_codec_sleep (struct zoran *zr,
  219. int sleep)
  220. {
  221. GPIO(zr, zr->card.gpio[GPIO_JPEG_SLEEP], !sleep);
  222. if (!sleep) {
  223. dprintk(3,
  224. KERN_DEBUG
  225. "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
  226. ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
  227. udelay(500);
  228. } else {
  229. dprintk(3,
  230. KERN_DEBUG
  231. "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
  232. ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
  233. udelay(2);
  234. }
  235. }
  236. int
  237. jpeg_codec_reset (struct zoran *zr)
  238. {
  239. /* Take the codec out of sleep */
  240. jpeg_codec_sleep(zr, 0);
  241. if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) {
  242. post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0,
  243. 0);
  244. udelay(2);
  245. } else {
  246. GPIO(zr, zr->card.gpio[GPIO_JPEG_RESET], 0);
  247. udelay(2);
  248. GPIO(zr, zr->card.gpio[GPIO_JPEG_RESET], 1);
  249. udelay(2);
  250. }
  251. return 0;
  252. }
  253. /*
  254. * Set the registers for the size we have specified. Don't bother
  255. * trying to understand this without the ZR36057 manual in front of
  256. * you [AC].
  257. *
  258. * PS: The manual is free for download in .pdf format from
  259. * www.zoran.com - nicely done those folks.
  260. */
  261. static void
  262. zr36057_adjust_vfe (struct zoran *zr,
  263. enum zoran_codec_mode mode)
  264. {
  265. u32 reg;
  266. switch (mode) {
  267. case BUZ_MODE_MOTION_DECOMPRESS:
  268. btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
  269. reg = btread(ZR36057_VFEHCR);
  270. if ((reg & (1 << 10)) && zr->card.type != LML33R10) {
  271. reg += ((1 << 10) | 1);
  272. }
  273. btwrite(reg, ZR36057_VFEHCR);
  274. break;
  275. case BUZ_MODE_MOTION_COMPRESS:
  276. case BUZ_MODE_IDLE:
  277. default:
  278. if (zr->norm == VIDEO_MODE_NTSC ||
  279. (zr->card.type == LML33R10 &&
  280. zr->norm == VIDEO_MODE_PAL))
  281. btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
  282. else
  283. btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
  284. reg = btread(ZR36057_VFEHCR);
  285. if (!(reg & (1 << 10)) && zr->card.type != LML33R10) {
  286. reg -= ((1 << 10) | 1);
  287. }
  288. btwrite(reg, ZR36057_VFEHCR);
  289. break;
  290. }
  291. }
  292. /*
  293. * set geometry
  294. */
  295. static void
  296. zr36057_set_vfe (struct zoran *zr,
  297. int video_width,
  298. int video_height,
  299. const struct zoran_format *format)
  300. {
  301. struct tvnorm *tvn;
  302. unsigned HStart, HEnd, VStart, VEnd;
  303. unsigned DispMode;
  304. unsigned VidWinWid, VidWinHt;
  305. unsigned hcrop1, hcrop2, vcrop1, vcrop2;
  306. unsigned Wa, We, Ha, He;
  307. unsigned X, Y, HorDcm, VerDcm;
  308. u32 reg;
  309. unsigned mask_line_size;
  310. tvn = zr->timing;
  311. Wa = tvn->Wa;
  312. Ha = tvn->Ha;
  313. dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
  314. ZR_DEVNAME(zr), video_width, video_height);
  315. if (zr->norm != VIDEO_MODE_PAL &&
  316. zr->norm != VIDEO_MODE_NTSC &&
  317. zr->norm != VIDEO_MODE_SECAM) {
  318. dprintk(1,
  319. KERN_ERR "%s: set_vfe() - norm = %d not valid\n",
  320. ZR_DEVNAME(zr), zr->norm);
  321. return;
  322. }
  323. if (video_width < BUZ_MIN_WIDTH ||
  324. video_height < BUZ_MIN_HEIGHT ||
  325. video_width > Wa || video_height > Ha) {
  326. dprintk(1, KERN_ERR "%s: set_vfe: w=%d h=%d not valid\n",
  327. ZR_DEVNAME(zr), video_width, video_height);
  328. return;
  329. }
  330. /**** zr36057 ****/
  331. /* horizontal */
  332. VidWinWid = video_width;
  333. X = (VidWinWid * 64 + tvn->Wa - 1) / tvn->Wa;
  334. We = (VidWinWid * 64) / X;
  335. HorDcm = 64 - X;
  336. hcrop1 = 2 * ((tvn->Wa - We) / 4);
  337. hcrop2 = tvn->Wa - We - hcrop1;
  338. HStart = tvn->HStart ? tvn->HStart : 1;
  339. /* (Ronald) Original comment:
  340. * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
  341. * this is false. It inverses chroma values on the LML33R10 (so Cr
  342. * suddenly is shown as Cb and reverse, really cool effect if you
  343. * want to see blue faces, not useful otherwise). So don't use |1.
  344. * However, the DC10 has '0' as HStart, but does need |1, so we
  345. * use a dirty check...
  346. */
  347. HEnd = HStart + tvn->Wa - 1;
  348. HStart += hcrop1;
  349. HEnd -= hcrop2;
  350. reg = ((HStart & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HStart)
  351. | ((HEnd & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HEnd);
  352. if (zr->card.vfe_pol.hsync_pol)
  353. reg |= ZR36057_VFEHCR_HSPol;
  354. btwrite(reg, ZR36057_VFEHCR);
  355. /* Vertical */
  356. DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
  357. VidWinHt = DispMode ? video_height : video_height / 2;
  358. Y = (VidWinHt * 64 * 2 + tvn->Ha - 1) / tvn->Ha;
  359. He = (VidWinHt * 64) / Y;
  360. VerDcm = 64 - Y;
  361. vcrop1 = (tvn->Ha / 2 - He) / 2;
  362. vcrop2 = tvn->Ha / 2 - He - vcrop1;
  363. VStart = tvn->VStart;
  364. VEnd = VStart + tvn->Ha / 2; // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
  365. VStart += vcrop1;
  366. VEnd -= vcrop2;
  367. reg = ((VStart & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VStart)
  368. | ((VEnd & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VEnd);
  369. if (zr->card.vfe_pol.vsync_pol)
  370. reg |= ZR36057_VFEVCR_VSPol;
  371. btwrite(reg, ZR36057_VFEVCR);
  372. /* scaler and pixel format */
  373. reg = 0;
  374. reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
  375. reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
  376. reg |= (DispMode << ZR36057_VFESPFR_DispMode);
  377. if (format->palette != VIDEO_PALETTE_YUV422)
  378. reg |= ZR36057_VFESPFR_LittleEndian;
  379. /* RJ: I don't know, why the following has to be the opposite
  380. * of the corresponding ZR36060 setting, but only this way
  381. * we get the correct colors when uncompressing to the screen */
  382. //reg |= ZR36057_VFESPFR_VCLKPol; /**/
  383. /* RJ: Don't know if that is needed for NTSC also */
  384. if (zr->norm != VIDEO_MODE_NTSC)
  385. reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang
  386. reg |= ZR36057_VFESPFR_TopField;
  387. switch (format->palette) {
  388. case VIDEO_PALETTE_YUV422:
  389. reg |= ZR36057_VFESPFR_YUV422;
  390. break;
  391. case VIDEO_PALETTE_RGB555:
  392. reg |= ZR36057_VFESPFR_RGB555 | ZR36057_VFESPFR_ErrDif;
  393. break;
  394. case VIDEO_PALETTE_RGB565:
  395. reg |= ZR36057_VFESPFR_RGB565 | ZR36057_VFESPFR_ErrDif;
  396. break;
  397. case VIDEO_PALETTE_RGB24:
  398. reg |= ZR36057_VFESPFR_RGB888 | ZR36057_VFESPFR_Pack24;
  399. break;
  400. case VIDEO_PALETTE_RGB32:
  401. reg |= ZR36057_VFESPFR_RGB888;
  402. break;
  403. default:
  404. dprintk(1,
  405. KERN_INFO "%s: set_vfe() - unknown color_fmt=%x\n",
  406. ZR_DEVNAME(zr), format->palette);
  407. return;
  408. }
  409. if (HorDcm >= 48) {
  410. reg |= 3 << ZR36057_VFESPFR_HFilter; /* 5 tap filter */
  411. } else if (HorDcm >= 32) {
  412. reg |= 2 << ZR36057_VFESPFR_HFilter; /* 4 tap filter */
  413. } else if (HorDcm >= 16) {
  414. reg |= 1 << ZR36057_VFESPFR_HFilter; /* 3 tap filter */
  415. }
  416. btwrite(reg, ZR36057_VFESPFR);
  417. /* display configuration */
  418. reg = (16 << ZR36057_VDCR_MinPix)
  419. | (VidWinHt << ZR36057_VDCR_VidWinHt)
  420. | (VidWinWid << ZR36057_VDCR_VidWinWid);
  421. if (pci_pci_problems & PCIPCI_TRITON)
  422. // || zr->revision < 1) // Revision 1 has also Triton support
  423. reg &= ~ZR36057_VDCR_Triton;
  424. else
  425. reg |= ZR36057_VDCR_Triton;
  426. btwrite(reg, ZR36057_VDCR);
  427. /* (Ronald) don't write this if overlay_mask = NULL */
  428. if (zr->overlay_mask) {
  429. /* Write overlay clipping mask data, but don't enable overlay clipping */
  430. /* RJ: since this makes only sense on the screen, we use
  431. * zr->overlay_settings.width instead of video_width */
  432. mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
  433. reg = virt_to_bus(zr->overlay_mask);
  434. btwrite(reg, ZR36057_MMTR);
  435. reg = virt_to_bus(zr->overlay_mask + mask_line_size);
  436. btwrite(reg, ZR36057_MMBR);
  437. reg =
  438. mask_line_size - (zr->overlay_settings.width +
  439. 31) / 32;
  440. if (DispMode == 0)
  441. reg += mask_line_size;
  442. reg <<= ZR36057_OCR_MaskStride;
  443. btwrite(reg, ZR36057_OCR);
  444. }
  445. zr36057_adjust_vfe(zr, zr->codec_mode);
  446. }
  447. /*
  448. * Switch overlay on or off
  449. */
  450. void
  451. zr36057_overlay (struct zoran *zr,
  452. int on)
  453. {
  454. u32 reg;
  455. if (on) {
  456. /* do the necessary settings ... */
  457. btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR); /* switch it off first */
  458. zr36057_set_vfe(zr,
  459. zr->overlay_settings.width,
  460. zr->overlay_settings.height,
  461. zr->overlay_settings.format);
  462. /* Start and length of each line MUST be 4-byte aligned.
  463. * This should be allready checked before the call to this routine.
  464. * All error messages are internal driver checking only! */
  465. /* video display top and bottom registers */
  466. reg = (long) zr->buffer.base +
  467. zr->overlay_settings.x *
  468. ((zr->overlay_settings.format->depth + 7) / 8) +
  469. zr->overlay_settings.y *
  470. zr->buffer.bytesperline;
  471. btwrite(reg, ZR36057_VDTR);
  472. if (reg & 3)
  473. dprintk(1,
  474. KERN_ERR
  475. "%s: zr36057_overlay() - video_address not aligned\n",
  476. ZR_DEVNAME(zr));
  477. if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
  478. reg += zr->buffer.bytesperline;
  479. btwrite(reg, ZR36057_VDBR);
  480. /* video stride, status, and frame grab register */
  481. reg = zr->buffer.bytesperline -
  482. zr->overlay_settings.width *
  483. ((zr->overlay_settings.format->depth + 7) / 8);
  484. if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
  485. reg += zr->buffer.bytesperline;
  486. if (reg & 3)
  487. dprintk(1,
  488. KERN_ERR
  489. "%s: zr36057_overlay() - video_stride not aligned\n",
  490. ZR_DEVNAME(zr));
  491. reg = (reg << ZR36057_VSSFGR_DispStride);
  492. reg |= ZR36057_VSSFGR_VidOvf; /* clear overflow status */
  493. btwrite(reg, ZR36057_VSSFGR);
  494. /* Set overlay clipping */
  495. if (zr->overlay_settings.clipcount > 0)
  496. btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
  497. /* ... and switch it on */
  498. btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
  499. } else {
  500. /* Switch it off */
  501. btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
  502. }
  503. }
  504. /*
  505. * The overlay mask has one bit for each pixel on a scan line,
  506. * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
  507. */
  508. void
  509. write_overlay_mask (struct file *file,
  510. struct video_clip *vp,
  511. int count)
  512. {
  513. struct zoran_fh *fh = file->private_data;
  514. struct zoran *zr = fh->zr;
  515. unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
  516. u32 *mask;
  517. int x, y, width, height;
  518. unsigned i, j, k;
  519. u32 reg;
  520. /* fill mask with one bits */
  521. memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
  522. reg = 0;
  523. for (i = 0; i < count; ++i) {
  524. /* pick up local copy of clip */
  525. x = vp[i].x;
  526. y = vp[i].y;
  527. width = vp[i].width;
  528. height = vp[i].height;
  529. /* trim clips that extend beyond the window */
  530. if (x < 0) {
  531. width += x;
  532. x = 0;
  533. }
  534. if (y < 0) {
  535. height += y;
  536. y = 0;
  537. }
  538. if (x + width > fh->overlay_settings.width) {
  539. width = fh->overlay_settings.width - x;
  540. }
  541. if (y + height > fh->overlay_settings.height) {
  542. height = fh->overlay_settings.height - y;
  543. }
  544. /* ignore degenerate clips */
  545. if (height <= 0) {
  546. continue;
  547. }
  548. if (width <= 0) {
  549. continue;
  550. }
  551. /* apply clip for each scan line */
  552. for (j = 0; j < height; ++j) {
  553. /* reset bit for each pixel */
  554. /* this can be optimized later if need be */
  555. mask = fh->overlay_mask + (y + j) * mask_line_size;
  556. for (k = 0; k < width; ++k) {
  557. mask[(x + k) / 32] &=
  558. ~((u32) 1 << (x + k) % 32);
  559. }
  560. }
  561. }
  562. }
  563. /* Enable/Disable uncompressed memory grabbing of the 36057 */
  564. void
  565. zr36057_set_memgrab (struct zoran *zr,
  566. int mode)
  567. {
  568. if (mode) {
  569. if (btread(ZR36057_VSSFGR) &
  570. (ZR36057_VSSFGR_SnapShot | ZR36057_VSSFGR_FrameGrab))
  571. dprintk(1,
  572. KERN_WARNING
  573. "%s: zr36057_set_memgrab(1) with SnapShot or FrameGrab on!?\n",
  574. ZR_DEVNAME(zr));
  575. /* switch on VSync interrupts */
  576. btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
  577. btor(zr->card.vsync_int, ZR36057_ICR); // SW
  578. /* enable SnapShot */
  579. btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
  580. /* Set zr36057 video front end and enable video */
  581. zr36057_set_vfe(zr, zr->v4l_settings.width,
  582. zr->v4l_settings.height,
  583. zr->v4l_settings.format);
  584. zr->v4l_memgrab_active = 1;
  585. } else {
  586. zr->v4l_memgrab_active = 0;
  587. /* switch off VSync interrupts */
  588. btand(~zr->card.vsync_int, ZR36057_ICR); // SW
  589. /* reenable grabbing to screen if it was running */
  590. if (zr->v4l_overlay_active) {
  591. zr36057_overlay(zr, 1);
  592. } else {
  593. btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
  594. btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
  595. }
  596. }
  597. }
  598. int
  599. wait_grab_pending (struct zoran *zr)
  600. {
  601. unsigned long flags;
  602. /* wait until all pending grabs are finished */
  603. if (!zr->v4l_memgrab_active)
  604. return 0;
  605. wait_event_interruptible(zr->v4l_capq,
  606. (zr->v4l_pend_tail == zr->v4l_pend_head));
  607. if (signal_pending(current))
  608. return -ERESTARTSYS;
  609. spin_lock_irqsave(&zr->spinlock, flags);
  610. zr36057_set_memgrab(zr, 0);
  611. spin_unlock_irqrestore(&zr->spinlock, flags);
  612. return 0;
  613. }
  614. /*****************************************************************************
  615. * *
  616. * Set up the Buz-specific MJPEG part *
  617. * *
  618. *****************************************************************************/
  619. static inline void
  620. set_frame (struct zoran *zr,
  621. int val)
  622. {
  623. GPIO(zr, zr->card.gpio[GPIO_JPEG_FRAME], val);
  624. }
  625. static void
  626. set_videobus_dir (struct zoran *zr,
  627. int val)
  628. {
  629. switch (zr->card.type) {
  630. case LML33:
  631. case LML33R10:
  632. if (lml33dpath == 0)
  633. GPIO(zr, 5, val);
  634. else
  635. GPIO(zr, 5, 1);
  636. break;
  637. default:
  638. GPIO(zr, zr->card.gpio[GPIO_VID_DIR],
  639. zr->card.gpio_pol[GPIO_VID_DIR] ? !val : val);
  640. break;
  641. }
  642. }
  643. static void
  644. init_jpeg_queue (struct zoran *zr)
  645. {
  646. int i;
  647. /* re-initialize DMA ring stuff */
  648. zr->jpg_que_head = 0;
  649. zr->jpg_dma_head = 0;
  650. zr->jpg_dma_tail = 0;
  651. zr->jpg_que_tail = 0;
  652. zr->jpg_seq_num = 0;
  653. zr->JPEG_error = 0;
  654. zr->num_errors = 0;
  655. zr->jpg_err_seq = 0;
  656. zr->jpg_err_shift = 0;
  657. zr->jpg_queued_num = 0;
  658. for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
  659. zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
  660. }
  661. for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
  662. zr->stat_com[i] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
  663. }
  664. }
  665. static void
  666. zr36057_set_jpg (struct zoran *zr,
  667. enum zoran_codec_mode mode)
  668. {
  669. struct tvnorm *tvn;
  670. u32 reg;
  671. tvn = zr->timing;
  672. /* assert P_Reset, disable code transfer, deassert Active */
  673. btwrite(0, ZR36057_JPC);
  674. /* MJPEG compression mode */
  675. switch (mode) {
  676. case BUZ_MODE_MOTION_COMPRESS:
  677. default:
  678. reg = ZR36057_JMC_MJPGCmpMode;
  679. break;
  680. case BUZ_MODE_MOTION_DECOMPRESS:
  681. reg = ZR36057_JMC_MJPGExpMode;
  682. reg |= ZR36057_JMC_SyncMstr;
  683. /* RJ: The following is experimental - improves the output to screen */
  684. //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
  685. break;
  686. case BUZ_MODE_STILL_COMPRESS:
  687. reg = ZR36057_JMC_JPGCmpMode;
  688. break;
  689. case BUZ_MODE_STILL_DECOMPRESS:
  690. reg = ZR36057_JMC_JPGExpMode;
  691. break;
  692. }
  693. reg |= ZR36057_JMC_JPG;
  694. if (zr->jpg_settings.field_per_buff == 1)
  695. reg |= ZR36057_JMC_Fld_per_buff;
  696. btwrite(reg, ZR36057_JMC);
  697. /* vertical */
  698. btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
  699. reg = (6 << ZR36057_VSP_VsyncSize) |
  700. (tvn->Ht << ZR36057_VSP_FrmTot);
  701. btwrite(reg, ZR36057_VSP);
  702. reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
  703. (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
  704. btwrite(reg, ZR36057_FVAP);
  705. /* horizontal */
  706. if (zr->card.vfe_pol.hsync_pol)
  707. btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
  708. else
  709. btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
  710. reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
  711. (tvn->Wt << ZR36057_HSP_LineTot);
  712. btwrite(reg, ZR36057_HSP);
  713. reg = ((zr->jpg_settings.img_x +
  714. tvn->HStart + 4) << ZR36057_FHAP_NAX) |
  715. (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
  716. btwrite(reg, ZR36057_FHAP);
  717. /* field process parameters */
  718. if (zr->jpg_settings.odd_even)
  719. reg = ZR36057_FPP_Odd_Even;
  720. else
  721. reg = 0;
  722. btwrite(reg, ZR36057_FPP);
  723. /* Set proper VCLK Polarity, else colors will be wrong during playback */
  724. //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
  725. /* code base address */
  726. reg = virt_to_bus(zr->stat_com);
  727. btwrite(reg, ZR36057_JCBA);
  728. /* FIFO threshold (FIFO is 160. double words) */
  729. /* NOTE: decimal values here */
  730. switch (mode) {
  731. case BUZ_MODE_STILL_COMPRESS:
  732. case BUZ_MODE_MOTION_COMPRESS:
  733. if (zr->card.type != BUZ)
  734. reg = 140;
  735. else
  736. reg = 60;
  737. break;
  738. case BUZ_MODE_STILL_DECOMPRESS:
  739. case BUZ_MODE_MOTION_DECOMPRESS:
  740. reg = 20;
  741. break;
  742. default:
  743. reg = 80;
  744. break;
  745. }
  746. btwrite(reg, ZR36057_JCFT);
  747. zr36057_adjust_vfe(zr, mode);
  748. }
  749. void
  750. print_interrupts (struct zoran *zr)
  751. {
  752. int res, noerr = 0;
  753. printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
  754. if ((res = zr->field_counter) < -1 || res > 1) {
  755. printk(" FD:%d", res);
  756. }
  757. if ((res = zr->intr_counter_GIRQ1) != 0) {
  758. printk(" GIRQ1:%d", res);
  759. noerr++;
  760. }
  761. if ((res = zr->intr_counter_GIRQ0) != 0) {
  762. printk(" GIRQ0:%d", res);
  763. noerr++;
  764. }
  765. if ((res = zr->intr_counter_CodRepIRQ) != 0) {
  766. printk(" CodRepIRQ:%d", res);
  767. noerr++;
  768. }
  769. if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
  770. printk(" JPEGRepIRQ:%d", res);
  771. noerr++;
  772. }
  773. if (zr->JPEG_max_missed) {
  774. printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
  775. zr->JPEG_min_missed);
  776. }
  777. if (zr->END_event_missed) {
  778. printk(" ENDs missed: %d", zr->END_event_missed);
  779. }
  780. //if (zr->jpg_queued_num) {
  781. printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
  782. zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
  783. //}
  784. if (!noerr) {
  785. printk(": no interrupts detected.");
  786. }
  787. printk("\n");
  788. }
  789. void
  790. clear_interrupt_counters (struct zoran *zr)
  791. {
  792. zr->intr_counter_GIRQ1 = 0;
  793. zr->intr_counter_GIRQ0 = 0;
  794. zr->intr_counter_CodRepIRQ = 0;
  795. zr->intr_counter_JPEGRepIRQ = 0;
  796. zr->field_counter = 0;
  797. zr->IRQ1_in = 0;
  798. zr->IRQ1_out = 0;
  799. zr->JPEG_in = 0;
  800. zr->JPEG_out = 0;
  801. zr->JPEG_0 = 0;
  802. zr->JPEG_1 = 0;
  803. zr->END_event_missed = 0;
  804. zr->JPEG_missed = 0;
  805. zr->JPEG_max_missed = 0;
  806. zr->JPEG_min_missed = 0x7fffffff;
  807. }
  808. static u32
  809. count_reset_interrupt (struct zoran *zr)
  810. {
  811. u32 isr;
  812. if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
  813. if (isr & ZR36057_ISR_GIRQ1) {
  814. btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
  815. zr->intr_counter_GIRQ1++;
  816. }
  817. if (isr & ZR36057_ISR_GIRQ0) {
  818. btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
  819. zr->intr_counter_GIRQ0++;
  820. }
  821. if (isr & ZR36057_ISR_CodRepIRQ) {
  822. btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
  823. zr->intr_counter_CodRepIRQ++;
  824. }
  825. if (isr & ZR36057_ISR_JPEGRepIRQ) {
  826. btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
  827. zr->intr_counter_JPEGRepIRQ++;
  828. }
  829. }
  830. return isr;
  831. }
  832. /* hack */
  833. extern void zr36016_write (struct videocodec *codec,
  834. u16 reg,
  835. u32 val);
  836. void
  837. jpeg_start (struct zoran *zr)
  838. {
  839. int reg;
  840. zr->frame_num = 0;
  841. /* deassert P_reset, disable code transfer, deassert Active */
  842. btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
  843. /* stop flushing the internal code buffer */
  844. btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
  845. /* enable code transfer */
  846. btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
  847. /* clear IRQs */
  848. btwrite(IRQ_MASK, ZR36057_ISR);
  849. /* enable the JPEG IRQs */
  850. btwrite(zr->card.jpeg_int |
  851. ZR36057_ICR_JPEGRepIRQ |
  852. ZR36057_ICR_IntPinEn,
  853. ZR36057_ICR);
  854. set_frame(zr, 0); // \FRAME
  855. /* set the JPEG codec guest ID */
  856. reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
  857. (0 << ZR36057_JCGI_JPEGuestReg);
  858. btwrite(reg, ZR36057_JCGI);
  859. if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
  860. zr->card.video_codec == CODEC_TYPE_ZR36050) {
  861. /* Enable processing on the ZR36016 */
  862. if (zr->vfe)
  863. zr36016_write(zr->vfe, 0, 1);
  864. /* load the address of the GO register in the ZR36050 latch */
  865. post_office_write(zr, 0, 0, 0);
  866. }
  867. /* assert Active */
  868. btor(ZR36057_JPC_Active, ZR36057_JPC);
  869. /* enable the Go generation */
  870. btor(ZR36057_JMC_Go_en, ZR36057_JMC);
  871. udelay(30);
  872. set_frame(zr, 1); // /FRAME
  873. dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
  874. }
  875. void
  876. zr36057_enable_jpg (struct zoran *zr,
  877. enum zoran_codec_mode mode)
  878. {
  879. static int zero = 0;
  880. static int one = 1;
  881. struct vfe_settings cap;
  882. int field_size =
  883. zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
  884. zr->codec_mode = mode;
  885. cap.x = zr->jpg_settings.img_x;
  886. cap.y = zr->jpg_settings.img_y;
  887. cap.width = zr->jpg_settings.img_width;
  888. cap.height = zr->jpg_settings.img_height;
  889. cap.decimation =
  890. zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
  891. cap.quality = zr->jpg_settings.jpg_comp.quality;
  892. switch (mode) {
  893. case BUZ_MODE_MOTION_COMPRESS: {
  894. struct jpeg_app_marker app;
  895. struct jpeg_com_marker com;
  896. /* In motion compress mode, the decoder output must be enabled, and
  897. * the video bus direction set to input.
  898. */
  899. set_videobus_dir(zr, 0);
  900. decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
  901. encoder_command(zr, ENCODER_SET_INPUT, &zero);
  902. /* Take the JPEG codec and the VFE out of sleep */
  903. jpeg_codec_sleep(zr, 0);
  904. /* set JPEG app/com marker */
  905. app.appn = zr->jpg_settings.jpg_comp.APPn;
  906. app.len = zr->jpg_settings.jpg_comp.APP_len;
  907. memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
  908. zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
  909. sizeof(struct jpeg_app_marker), &app);
  910. com.len = zr->jpg_settings.jpg_comp.COM_len;
  911. memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
  912. zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
  913. sizeof(struct jpeg_com_marker), &com);
  914. /* Setup the JPEG codec */
  915. zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
  916. sizeof(int), &field_size);
  917. zr->codec->set_video(zr->codec, zr->timing, &cap,
  918. &zr->card.vfe_pol);
  919. zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
  920. /* Setup the VFE */
  921. if (zr->vfe) {
  922. zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
  923. sizeof(int), &field_size);
  924. zr->vfe->set_video(zr->vfe, zr->timing, &cap,
  925. &zr->card.vfe_pol);
  926. zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
  927. }
  928. init_jpeg_queue(zr);
  929. zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
  930. clear_interrupt_counters(zr);
  931. dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
  932. ZR_DEVNAME(zr));
  933. break;
  934. }
  935. case BUZ_MODE_MOTION_DECOMPRESS:
  936. /* In motion decompression mode, the decoder output must be disabled, and
  937. * the video bus direction set to output.
  938. */
  939. decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
  940. set_videobus_dir(zr, 1);
  941. encoder_command(zr, ENCODER_SET_INPUT, &one);
  942. /* Take the JPEG codec and the VFE out of sleep */
  943. jpeg_codec_sleep(zr, 0);
  944. /* Setup the VFE */
  945. if (zr->vfe) {
  946. zr->vfe->set_video(zr->vfe, zr->timing, &cap,
  947. &zr->card.vfe_pol);
  948. zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
  949. }
  950. /* Setup the JPEG codec */
  951. zr->codec->set_video(zr->codec, zr->timing, &cap,
  952. &zr->card.vfe_pol);
  953. zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
  954. init_jpeg_queue(zr);
  955. zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
  956. clear_interrupt_counters(zr);
  957. dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
  958. ZR_DEVNAME(zr));
  959. break;
  960. case BUZ_MODE_IDLE:
  961. default:
  962. /* shut down processing */
  963. btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
  964. ZR36057_ICR);
  965. btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
  966. ZR36057_ISR);
  967. btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
  968. msleep(50);
  969. set_videobus_dir(zr, 0);
  970. set_frame(zr, 1); // /FRAME
  971. btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); // /CFlush
  972. btwrite(0, ZR36057_JPC); // \P_Reset,\CodTrnsEn,\Active
  973. btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
  974. btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
  975. jpeg_codec_reset(zr);
  976. jpeg_codec_sleep(zr, 1);
  977. zr36057_adjust_vfe(zr, mode);
  978. decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
  979. encoder_command(zr, ENCODER_SET_INPUT, &zero);
  980. dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
  981. break;
  982. }
  983. }
  984. /* when this is called the spinlock must be held */
  985. void
  986. zoran_feed_stat_com (struct zoran *zr)
  987. {
  988. /* move frames from pending queue to DMA */
  989. int frame, i, max_stat_com;
  990. max_stat_com =
  991. (zr->jpg_settings.TmpDcm ==
  992. 1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
  993. while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
  994. zr->jpg_dma_head < zr->jpg_que_head) {
  995. frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
  996. if (zr->jpg_settings.TmpDcm == 1) {
  997. /* fill 1 stat_com entry */
  998. i = (zr->jpg_dma_head -
  999. zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
  1000. if (!(zr->stat_com[i] & cpu_to_le32(1)))
  1001. break;
  1002. zr->stat_com[i] =
  1003. cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
  1004. } else {
  1005. /* fill 2 stat_com entries */
  1006. i = ((zr->jpg_dma_head -
  1007. zr->jpg_err_shift) & 1) * 2;
  1008. if (!(zr->stat_com[i] & cpu_to_le32(1)))
  1009. break;
  1010. zr->stat_com[i] =
  1011. cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
  1012. zr->stat_com[i + 1] =
  1013. cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
  1014. }
  1015. zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
  1016. zr->jpg_dma_head++;
  1017. }
  1018. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
  1019. zr->jpg_queued_num++;
  1020. }
  1021. /* when this is called the spinlock must be held */
  1022. static void
  1023. zoran_reap_stat_com (struct zoran *zr)
  1024. {
  1025. /* move frames from DMA queue to done queue */
  1026. int i;
  1027. u32 stat_com;
  1028. unsigned int seq;
  1029. unsigned int dif;
  1030. struct zoran_jpg_buffer *buffer;
  1031. int frame;
  1032. /* In motion decompress we don't have a hardware frame counter,
  1033. * we just count the interrupts here */
  1034. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
  1035. zr->jpg_seq_num++;
  1036. }
  1037. while (zr->jpg_dma_tail < zr->jpg_dma_head) {
  1038. if (zr->jpg_settings.TmpDcm == 1)
  1039. i = (zr->jpg_dma_tail -
  1040. zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
  1041. else
  1042. i = ((zr->jpg_dma_tail -
  1043. zr->jpg_err_shift) & 1) * 2 + 1;
  1044. stat_com = le32_to_cpu(zr->stat_com[i]);
  1045. if ((stat_com & 1) == 0) {
  1046. return;
  1047. }
  1048. frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
  1049. buffer = &zr->jpg_buffers.buffer[frame];
  1050. do_gettimeofday(&buffer->bs.timestamp);
  1051. if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1052. buffer->bs.length = (stat_com & 0x7fffff) >> 1;
  1053. /* update sequence number with the help of the counter in stat_com */
  1054. seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
  1055. dif = (seq - zr->jpg_seq_num) & 0xff;
  1056. zr->jpg_seq_num += dif;
  1057. } else {
  1058. buffer->bs.length = 0;
  1059. }
  1060. buffer->bs.seq =
  1061. zr->jpg_settings.TmpDcm ==
  1062. 2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
  1063. buffer->state = BUZ_STATE_DONE;
  1064. zr->jpg_dma_tail++;
  1065. }
  1066. }
  1067. static void
  1068. error_handler (struct zoran *zr,
  1069. u32 astat,
  1070. u32 stat)
  1071. {
  1072. /* This is JPEG error handling part */
  1073. if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) &&
  1074. (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) {
  1075. //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
  1076. return;
  1077. }
  1078. if ((stat & 1) == 0 &&
  1079. zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
  1080. zr->jpg_dma_tail - zr->jpg_que_tail >=
  1081. zr->jpg_buffers.num_buffers) {
  1082. /* No free buffers... */
  1083. zoran_reap_stat_com(zr);
  1084. zoran_feed_stat_com(zr);
  1085. wake_up_interruptible(&zr->jpg_capq);
  1086. zr->JPEG_missed = 0;
  1087. return;
  1088. }
  1089. if (zr->JPEG_error != 1) {
  1090. /*
  1091. * First entry: error just happened during normal operation
  1092. *
  1093. * In BUZ_MODE_MOTION_COMPRESS:
  1094. *
  1095. * Possible glitch in TV signal. In this case we should
  1096. * stop the codec and wait for good quality signal before
  1097. * restarting it to avoid further problems
  1098. *
  1099. * In BUZ_MODE_MOTION_DECOMPRESS:
  1100. *
  1101. * Bad JPEG frame: we have to mark it as processed (codec crashed
  1102. * and was not able to do it itself), and to remove it from queue.
  1103. */
  1104. btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
  1105. udelay(1);
  1106. stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
  1107. btwrite(0, ZR36057_JPC);
  1108. btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
  1109. jpeg_codec_reset(zr);
  1110. jpeg_codec_sleep(zr, 1);
  1111. zr->JPEG_error = 1;
  1112. zr->num_errors++;
  1113. /* Report error */
  1114. if (*zr_debug > 1 && zr->num_errors <= 8) {
  1115. long frame;
  1116. frame =
  1117. zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
  1118. printk(KERN_ERR
  1119. "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
  1120. ZR_DEVNAME(zr), stat, zr->last_isr,
  1121. zr->jpg_que_tail, zr->jpg_dma_tail,
  1122. zr->jpg_dma_head, zr->jpg_que_head,
  1123. zr->jpg_seq_num, frame);
  1124. printk("stat_com frames:");
  1125. {
  1126. int i, j;
  1127. for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
  1128. for (i = 0;
  1129. i < zr->jpg_buffers.num_buffers;
  1130. i++) {
  1131. if (le32_to_cpu(zr->stat_com[j]) ==
  1132. zr->jpg_buffers.
  1133. buffer[i].
  1134. frag_tab_bus) {
  1135. printk("% d->%d",
  1136. j, i);
  1137. }
  1138. }
  1139. }
  1140. printk("\n");
  1141. }
  1142. }
  1143. /* Find an entry in stat_com and rotate contents */
  1144. {
  1145. int i;
  1146. if (zr->jpg_settings.TmpDcm == 1)
  1147. i = (zr->jpg_dma_tail -
  1148. zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
  1149. else
  1150. i = ((zr->jpg_dma_tail -
  1151. zr->jpg_err_shift) & 1) * 2;
  1152. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
  1153. /* Mimic zr36067 operation */
  1154. zr->stat_com[i] |= cpu_to_le32(1);
  1155. if (zr->jpg_settings.TmpDcm != 1)
  1156. zr->stat_com[i + 1] |= cpu_to_le32(1);
  1157. /* Refill */
  1158. zoran_reap_stat_com(zr);
  1159. zoran_feed_stat_com(zr);
  1160. wake_up_interruptible(&zr->jpg_capq);
  1161. /* Find an entry in stat_com again after refill */
  1162. if (zr->jpg_settings.TmpDcm == 1)
  1163. i = (zr->jpg_dma_tail -
  1164. zr->jpg_err_shift) &
  1165. BUZ_MASK_STAT_COM;
  1166. else
  1167. i = ((zr->jpg_dma_tail -
  1168. zr->jpg_err_shift) & 1) * 2;
  1169. }
  1170. if (i) {
  1171. /* Rotate stat_comm entries to make current entry first */
  1172. int j;
  1173. u32 bus_addr[BUZ_NUM_STAT_COM];
  1174. /* Here we are copying the stat_com array, which
  1175. * is already in little endian format, so
  1176. * no endian conversions here
  1177. */
  1178. memcpy(bus_addr, zr->stat_com,
  1179. sizeof(bus_addr));
  1180. for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
  1181. zr->stat_com[j] =
  1182. bus_addr[(i + j) &
  1183. BUZ_MASK_STAT_COM];
  1184. }
  1185. zr->jpg_err_shift += i;
  1186. zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
  1187. }
  1188. if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
  1189. zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
  1190. }
  1191. }
  1192. /* Now the stat_comm buffer is ready for restart */
  1193. do {
  1194. int status, mode;
  1195. if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1196. decoder_command(zr, DECODER_GET_STATUS, &status);
  1197. mode = CODEC_DO_COMPRESSION;
  1198. } else {
  1199. status = 0;
  1200. mode = CODEC_DO_EXPANSION;
  1201. }
  1202. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
  1203. (status & DECODER_STATUS_GOOD)) {
  1204. /********** RESTART code *************/
  1205. jpeg_codec_reset(zr);
  1206. zr->codec->set_mode(zr->codec, mode);
  1207. zr36057_set_jpg(zr, zr->codec_mode);
  1208. jpeg_start(zr);
  1209. if (zr->num_errors <= 8)
  1210. dprintk(2, KERN_INFO "%s: Restart\n",
  1211. ZR_DEVNAME(zr));
  1212. zr->JPEG_missed = 0;
  1213. zr->JPEG_error = 2;
  1214. /********** End RESTART code ***********/
  1215. }
  1216. } while (0);
  1217. }
  1218. irqreturn_t
  1219. zoran_irq (int irq,
  1220. void *dev_id,
  1221. struct pt_regs *regs)
  1222. {
  1223. u32 stat, astat;
  1224. int count;
  1225. struct zoran *zr;
  1226. unsigned long flags;
  1227. zr = (struct zoran *) dev_id;
  1228. count = 0;
  1229. if (zr->testing) {
  1230. /* Testing interrupts */
  1231. spin_lock_irqsave(&zr->spinlock, flags);
  1232. while ((stat = count_reset_interrupt(zr))) {
  1233. if (count++ > 100) {
  1234. btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
  1235. dprintk(1,
  1236. KERN_ERR
  1237. "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
  1238. ZR_DEVNAME(zr), stat);
  1239. wake_up_interruptible(&zr->test_q);
  1240. }
  1241. }
  1242. zr->last_isr = stat;
  1243. spin_unlock_irqrestore(&zr->spinlock, flags);
  1244. return IRQ_HANDLED;
  1245. }
  1246. spin_lock_irqsave(&zr->spinlock, flags);
  1247. while (1) {
  1248. /* get/clear interrupt status bits */
  1249. stat = count_reset_interrupt(zr);
  1250. astat = stat & IRQ_MASK;
  1251. if (!astat) {
  1252. break;
  1253. }
  1254. dprintk(4,
  1255. KERN_DEBUG
  1256. "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
  1257. astat, btread(ZR36057_ICR));
  1258. if (astat & zr->card.vsync_int) { // SW
  1259. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
  1260. zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1261. /* count missed interrupts */
  1262. zr->JPEG_missed++;
  1263. }
  1264. //post_office_read(zr,1,0);
  1265. /* Interrupts may still happen when
  1266. * zr->v4l_memgrab_active is switched off.
  1267. * We simply ignore them */
  1268. if (zr->v4l_memgrab_active) {
  1269. /* A lot more checks should be here ... */
  1270. if ((btread(ZR36057_VSSFGR) &
  1271. ZR36057_VSSFGR_SnapShot) == 0)
  1272. dprintk(1,
  1273. KERN_WARNING
  1274. "%s: BuzIRQ with SnapShot off ???\n",
  1275. ZR_DEVNAME(zr));
  1276. if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
  1277. /* There is a grab on a frame going on, check if it has finished */
  1278. if ((btread(ZR36057_VSSFGR) &
  1279. ZR36057_VSSFGR_FrameGrab) ==
  1280. 0) {
  1281. /* it is finished, notify the user */
  1282. zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
  1283. zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
  1284. do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
  1285. zr->v4l_grab_frame = NO_GRAB_ACTIVE;
  1286. zr->v4l_pend_tail++;
  1287. }
  1288. }
  1289. if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
  1290. wake_up_interruptible(&zr->v4l_capq);
  1291. /* Check if there is another grab queued */
  1292. if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
  1293. zr->v4l_pend_tail != zr->v4l_pend_head) {
  1294. int frame = zr->v4l_pend[zr->v4l_pend_tail &
  1295. V4L_MASK_FRAME];
  1296. u32 reg;
  1297. zr->v4l_grab_frame = frame;
  1298. /* Set zr36057 video front end and enable video */
  1299. /* Buffer address */
  1300. reg =
  1301. zr->v4l_buffers.buffer[frame].
  1302. fbuffer_bus;
  1303. btwrite(reg, ZR36057_VDTR);
  1304. if (zr->v4l_settings.height >
  1305. BUZ_MAX_HEIGHT / 2)
  1306. reg +=
  1307. zr->v4l_settings.
  1308. bytesperline;
  1309. btwrite(reg, ZR36057_VDBR);
  1310. /* video stride, status, and frame grab register */
  1311. reg = 0;
  1312. if (zr->v4l_settings.height >
  1313. BUZ_MAX_HEIGHT / 2)
  1314. reg +=
  1315. zr->v4l_settings.
  1316. bytesperline;
  1317. reg =
  1318. (reg <<
  1319. ZR36057_VSSFGR_DispStride);
  1320. reg |= ZR36057_VSSFGR_VidOvf;
  1321. reg |= ZR36057_VSSFGR_SnapShot;
  1322. reg |= ZR36057_VSSFGR_FrameGrab;
  1323. btwrite(reg, ZR36057_VSSFGR);
  1324. btor(ZR36057_VDCR_VidEn,
  1325. ZR36057_VDCR);
  1326. }
  1327. }
  1328. /* even if we don't grab, we do want to increment
  1329. * the sequence counter to see lost frames */
  1330. zr->v4l_grab_seq++;
  1331. }
  1332. #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
  1333. if (astat & ZR36057_ISR_CodRepIRQ) {
  1334. zr->intr_counter_CodRepIRQ++;
  1335. IDEBUG(printk
  1336. (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
  1337. ZR_DEVNAME(zr)));
  1338. btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
  1339. }
  1340. #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
  1341. #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
  1342. if (astat & ZR36057_ISR_JPEGRepIRQ) {
  1343. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
  1344. zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1345. if (*zr_debug > 1 &&
  1346. (!zr->frame_num || zr->JPEG_error)) {
  1347. printk(KERN_INFO
  1348. "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
  1349. ZR_DEVNAME(zr), stat,
  1350. zr->jpg_settings.odd_even,
  1351. zr->jpg_settings.
  1352. field_per_buff,
  1353. zr->JPEG_missed);
  1354. {
  1355. char sc[] = "0000";
  1356. char sv[5];
  1357. int i;
  1358. strcpy(sv, sc);
  1359. for (i = 0; i < 4; i++) {
  1360. if (le32_to_cpu(zr->stat_com[i]) & 1)
  1361. sv[i] = '1';
  1362. }
  1363. sv[4] = 0;
  1364. printk(KERN_INFO
  1365. "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
  1366. ZR_DEVNAME(zr), sv,
  1367. zr->jpg_que_tail,
  1368. zr->jpg_dma_tail,
  1369. zr->jpg_dma_head,
  1370. zr->jpg_que_head);
  1371. }
  1372. } else {
  1373. if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics
  1374. zr->JPEG_max_missed =
  1375. zr->JPEG_missed;
  1376. if (zr->JPEG_missed <
  1377. zr->JPEG_min_missed)
  1378. zr->JPEG_min_missed =
  1379. zr->JPEG_missed;
  1380. }
  1381. if (*zr_debug > 2 && zr->frame_num < 6) {
  1382. int i;
  1383. printk("%s: seq=%ld stat_com:",
  1384. ZR_DEVNAME(zr), zr->jpg_seq_num);
  1385. for (i = 0; i < 4; i++) {
  1386. printk(" %08x",
  1387. le32_to_cpu(zr->stat_com[i]));
  1388. }
  1389. printk("\n");
  1390. }
  1391. zr->frame_num++;
  1392. zr->JPEG_missed = 0;
  1393. zr->JPEG_error = 0;
  1394. zoran_reap_stat_com(zr);
  1395. zoran_feed_stat_com(zr);
  1396. wake_up_interruptible(&zr->jpg_capq);
  1397. } /*else {
  1398. dprintk(1,
  1399. KERN_ERR
  1400. "%s: JPEG interrupt while not in motion (de)compress mode!\n",
  1401. ZR_DEVNAME(zr));
  1402. }*/
  1403. }
  1404. #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
  1405. /* DATERR, too many fields missed, error processing */
  1406. if ((astat & zr->card.jpeg_int) ||
  1407. zr->JPEG_missed > 25 ||
  1408. zr->JPEG_error == 1 ||
  1409. ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
  1410. (zr->frame_num & (zr->JPEG_missed >
  1411. zr->jpg_settings.field_per_buff)))) {
  1412. error_handler(zr, astat, stat);
  1413. }
  1414. count++;
  1415. if (count > 10) {
  1416. dprintk(2, KERN_WARNING "%s: irq loop %d\n",
  1417. ZR_DEVNAME(zr), count);
  1418. if (count > 20) {
  1419. btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
  1420. dprintk(2,
  1421. KERN_ERR
  1422. "%s: IRQ lockup, cleared int mask\n",
  1423. ZR_DEVNAME(zr));
  1424. break;
  1425. }
  1426. }
  1427. zr->last_isr = stat;
  1428. }
  1429. spin_unlock_irqrestore(&zr->spinlock, flags);
  1430. return IRQ_HANDLED;
  1431. }
  1432. void
  1433. zoran_set_pci_master (struct zoran *zr,
  1434. int set_master)
  1435. {
  1436. if (set_master) {
  1437. pci_set_master(zr->pci_dev);
  1438. } else {
  1439. u16 command;
  1440. pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
  1441. command &= ~PCI_COMMAND_MASTER;
  1442. pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
  1443. }
  1444. }
  1445. void
  1446. zoran_init_hardware (struct zoran *zr)
  1447. {
  1448. int j, zero = 0;
  1449. /* Enable bus-mastering */
  1450. zoran_set_pci_master(zr, 1);
  1451. /* Initialize the board */
  1452. if (zr->card.init) {
  1453. zr->card.init(zr);
  1454. }
  1455. j = zr->card.input[zr->input].muxsel;
  1456. decoder_command(zr, 0, NULL);
  1457. decoder_command(zr, DECODER_SET_NORM, &zr->norm);
  1458. decoder_command(zr, DECODER_SET_INPUT, &j);
  1459. encoder_command(zr, 0, NULL);
  1460. encoder_command(zr, ENCODER_SET_NORM, &zr->norm);
  1461. encoder_command(zr, ENCODER_SET_INPUT, &zero);
  1462. /* toggle JPEG codec sleep to sync PLL */
  1463. jpeg_codec_sleep(zr, 1);
  1464. jpeg_codec_sleep(zr, 0);
  1465. /* set individual interrupt enables (without GIRQ1)
  1466. * but don't global enable until zoran_open() */
  1467. //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW
  1468. // It looks like using only JPEGRepIRQEn is not always reliable,
  1469. // may be when JPEG codec crashes it won't generate IRQ? So,
  1470. /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
  1471. zr36057_init_vfe(zr);
  1472. zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
  1473. btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
  1474. }
  1475. void
  1476. zr36057_restart (struct zoran *zr)
  1477. {
  1478. btwrite(0, ZR36057_SPGPPCR);
  1479. mdelay(1);
  1480. btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
  1481. mdelay(1);
  1482. /* assert P_Reset */
  1483. btwrite(0, ZR36057_JPC);
  1484. /* set up GPIO direction - all output */
  1485. btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
  1486. /* set up GPIO pins and guest bus timing */
  1487. btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
  1488. }
  1489. /*
  1490. * initialize video front end
  1491. */
  1492. static void
  1493. zr36057_init_vfe (struct zoran *zr)
  1494. {
  1495. u32 reg;
  1496. reg = btread(ZR36057_VFESPFR);
  1497. reg |= ZR36057_VFESPFR_LittleEndian;
  1498. reg &= ~ZR36057_VFESPFR_VCLKPol;
  1499. reg |= ZR36057_VFESPFR_ExtFl;
  1500. reg |= ZR36057_VFESPFR_TopField;
  1501. btwrite(reg, ZR36057_VFESPFR);
  1502. reg = btread(ZR36057_VDCR);
  1503. if (pci_pci_problems & PCIPCI_TRITON)
  1504. // || zr->revision < 1) // Revision 1 has also Triton support
  1505. reg &= ~ZR36057_VDCR_Triton;
  1506. else
  1507. reg |= ZR36057_VDCR_Triton;
  1508. btwrite(reg, ZR36057_VDCR);
  1509. }
  1510. /*
  1511. * Interface to decoder and encoder chips using i2c bus
  1512. */
  1513. int
  1514. decoder_command (struct zoran *zr,
  1515. int cmd,
  1516. void *data)
  1517. {
  1518. if (zr->decoder == NULL)
  1519. return -EIO;
  1520. if (zr->card.type == LML33 &&
  1521. (cmd == DECODER_SET_NORM || DECODER_SET_INPUT)) {
  1522. int res;
  1523. // Bt819 needs to reset its FIFO buffer using #FRST pin and
  1524. // LML33 card uses GPIO(7) for that.
  1525. GPIO(zr, 7, 0);
  1526. res = zr->decoder->driver->command(zr->decoder, cmd, data);
  1527. // Pull #FRST high.
  1528. GPIO(zr, 7, 1);
  1529. return res;
  1530. } else
  1531. return zr->decoder->driver->command(zr->decoder, cmd,
  1532. data);
  1533. }
  1534. int
  1535. encoder_command (struct zoran *zr,
  1536. int cmd,
  1537. void *data)
  1538. {
  1539. if (zr->encoder == NULL)
  1540. return -1;
  1541. return zr->encoder->driver->command(zr->encoder, cmd, data);
  1542. }