zoran_device.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760
  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. /* RJ: I don't know, why the following has to be the opposite
  378. * of the corresponding ZR36060 setting, but only this way
  379. * we get the correct colors when uncompressing to the screen */
  380. //reg |= ZR36057_VFESPFR_VCLKPol; /**/
  381. /* RJ: Don't know if that is needed for NTSC also */
  382. if (zr->norm != VIDEO_MODE_NTSC)
  383. reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang
  384. reg |= ZR36057_VFESPFR_TopField;
  385. if (HorDcm >= 48) {
  386. reg |= 3 << ZR36057_VFESPFR_HFilter; /* 5 tap filter */
  387. } else if (HorDcm >= 32) {
  388. reg |= 2 << ZR36057_VFESPFR_HFilter; /* 4 tap filter */
  389. } else if (HorDcm >= 16) {
  390. reg |= 1 << ZR36057_VFESPFR_HFilter; /* 3 tap filter */
  391. }
  392. reg |= format->vfespfr;
  393. btwrite(reg, ZR36057_VFESPFR);
  394. /* display configuration */
  395. reg = (16 << ZR36057_VDCR_MinPix)
  396. | (VidWinHt << ZR36057_VDCR_VidWinHt)
  397. | (VidWinWid << ZR36057_VDCR_VidWinWid);
  398. if (pci_pci_problems & PCIPCI_TRITON)
  399. // || zr->revision < 1) // Revision 1 has also Triton support
  400. reg &= ~ZR36057_VDCR_Triton;
  401. else
  402. reg |= ZR36057_VDCR_Triton;
  403. btwrite(reg, ZR36057_VDCR);
  404. /* (Ronald) don't write this if overlay_mask = NULL */
  405. if (zr->overlay_mask) {
  406. /* Write overlay clipping mask data, but don't enable overlay clipping */
  407. /* RJ: since this makes only sense on the screen, we use
  408. * zr->overlay_settings.width instead of video_width */
  409. mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
  410. reg = virt_to_bus(zr->overlay_mask);
  411. btwrite(reg, ZR36057_MMTR);
  412. reg = virt_to_bus(zr->overlay_mask + mask_line_size);
  413. btwrite(reg, ZR36057_MMBR);
  414. reg =
  415. mask_line_size - (zr->overlay_settings.width +
  416. 31) / 32;
  417. if (DispMode == 0)
  418. reg += mask_line_size;
  419. reg <<= ZR36057_OCR_MaskStride;
  420. btwrite(reg, ZR36057_OCR);
  421. }
  422. zr36057_adjust_vfe(zr, zr->codec_mode);
  423. }
  424. /*
  425. * Switch overlay on or off
  426. */
  427. void
  428. zr36057_overlay (struct zoran *zr,
  429. int on)
  430. {
  431. u32 reg;
  432. if (on) {
  433. /* do the necessary settings ... */
  434. btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR); /* switch it off first */
  435. zr36057_set_vfe(zr,
  436. zr->overlay_settings.width,
  437. zr->overlay_settings.height,
  438. zr->overlay_settings.format);
  439. /* Start and length of each line MUST be 4-byte aligned.
  440. * This should be allready checked before the call to this routine.
  441. * All error messages are internal driver checking only! */
  442. /* video display top and bottom registers */
  443. reg = (long) zr->buffer.base +
  444. zr->overlay_settings.x *
  445. ((zr->overlay_settings.format->depth + 7) / 8) +
  446. zr->overlay_settings.y *
  447. zr->buffer.bytesperline;
  448. btwrite(reg, ZR36057_VDTR);
  449. if (reg & 3)
  450. dprintk(1,
  451. KERN_ERR
  452. "%s: zr36057_overlay() - video_address not aligned\n",
  453. ZR_DEVNAME(zr));
  454. if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
  455. reg += zr->buffer.bytesperline;
  456. btwrite(reg, ZR36057_VDBR);
  457. /* video stride, status, and frame grab register */
  458. reg = zr->buffer.bytesperline -
  459. zr->overlay_settings.width *
  460. ((zr->overlay_settings.format->depth + 7) / 8);
  461. if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
  462. reg += zr->buffer.bytesperline;
  463. if (reg & 3)
  464. dprintk(1,
  465. KERN_ERR
  466. "%s: zr36057_overlay() - video_stride not aligned\n",
  467. ZR_DEVNAME(zr));
  468. reg = (reg << ZR36057_VSSFGR_DispStride);
  469. reg |= ZR36057_VSSFGR_VidOvf; /* clear overflow status */
  470. btwrite(reg, ZR36057_VSSFGR);
  471. /* Set overlay clipping */
  472. if (zr->overlay_settings.clipcount > 0)
  473. btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
  474. /* ... and switch it on */
  475. btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
  476. } else {
  477. /* Switch it off */
  478. btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
  479. }
  480. }
  481. /*
  482. * The overlay mask has one bit for each pixel on a scan line,
  483. * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
  484. */
  485. void
  486. write_overlay_mask (struct file *file,
  487. struct video_clip *vp,
  488. int count)
  489. {
  490. struct zoran_fh *fh = file->private_data;
  491. struct zoran *zr = fh->zr;
  492. unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
  493. u32 *mask;
  494. int x, y, width, height;
  495. unsigned i, j, k;
  496. u32 reg;
  497. /* fill mask with one bits */
  498. memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
  499. reg = 0;
  500. for (i = 0; i < count; ++i) {
  501. /* pick up local copy of clip */
  502. x = vp[i].x;
  503. y = vp[i].y;
  504. width = vp[i].width;
  505. height = vp[i].height;
  506. /* trim clips that extend beyond the window */
  507. if (x < 0) {
  508. width += x;
  509. x = 0;
  510. }
  511. if (y < 0) {
  512. height += y;
  513. y = 0;
  514. }
  515. if (x + width > fh->overlay_settings.width) {
  516. width = fh->overlay_settings.width - x;
  517. }
  518. if (y + height > fh->overlay_settings.height) {
  519. height = fh->overlay_settings.height - y;
  520. }
  521. /* ignore degenerate clips */
  522. if (height <= 0) {
  523. continue;
  524. }
  525. if (width <= 0) {
  526. continue;
  527. }
  528. /* apply clip for each scan line */
  529. for (j = 0; j < height; ++j) {
  530. /* reset bit for each pixel */
  531. /* this can be optimized later if need be */
  532. mask = fh->overlay_mask + (y + j) * mask_line_size;
  533. for (k = 0; k < width; ++k) {
  534. mask[(x + k) / 32] &=
  535. ~((u32) 1 << (x + k) % 32);
  536. }
  537. }
  538. }
  539. }
  540. /* Enable/Disable uncompressed memory grabbing of the 36057 */
  541. void
  542. zr36057_set_memgrab (struct zoran *zr,
  543. int mode)
  544. {
  545. if (mode) {
  546. /* We only check SnapShot and not FrameGrab here. SnapShot==1
  547. * means a capture is already in progress, but FrameGrab==1
  548. * doesn't necessary mean that. It's more correct to say a 1
  549. * to 0 transition indicates a capture completed. If a
  550. * capture is pending when capturing is tuned off, FrameGrab
  551. * will be stuck at 1 until capturing is turned back on.
  552. */
  553. if (btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot)
  554. dprintk(1,
  555. KERN_WARNING
  556. "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
  557. ZR_DEVNAME(zr));
  558. /* switch on VSync interrupts */
  559. btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
  560. btor(zr->card.vsync_int, ZR36057_ICR); // SW
  561. /* enable SnapShot */
  562. btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
  563. /* Set zr36057 video front end and enable video */
  564. zr36057_set_vfe(zr, zr->v4l_settings.width,
  565. zr->v4l_settings.height,
  566. zr->v4l_settings.format);
  567. zr->v4l_memgrab_active = 1;
  568. } else {
  569. /* switch off VSync interrupts */
  570. btand(~zr->card.vsync_int, ZR36057_ICR); // SW
  571. zr->v4l_memgrab_active = 0;
  572. zr->v4l_grab_frame = NO_GRAB_ACTIVE;
  573. /* reenable grabbing to screen if it was running */
  574. if (zr->v4l_overlay_active) {
  575. zr36057_overlay(zr, 1);
  576. } else {
  577. btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
  578. btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
  579. }
  580. }
  581. }
  582. int
  583. wait_grab_pending (struct zoran *zr)
  584. {
  585. unsigned long flags;
  586. /* wait until all pending grabs are finished */
  587. if (!zr->v4l_memgrab_active)
  588. return 0;
  589. wait_event_interruptible(zr->v4l_capq,
  590. (zr->v4l_pend_tail == zr->v4l_pend_head));
  591. if (signal_pending(current))
  592. return -ERESTARTSYS;
  593. spin_lock_irqsave(&zr->spinlock, flags);
  594. zr36057_set_memgrab(zr, 0);
  595. spin_unlock_irqrestore(&zr->spinlock, flags);
  596. return 0;
  597. }
  598. /*****************************************************************************
  599. * *
  600. * Set up the Buz-specific MJPEG part *
  601. * *
  602. *****************************************************************************/
  603. static inline void
  604. set_frame (struct zoran *zr,
  605. int val)
  606. {
  607. GPIO(zr, zr->card.gpio[GPIO_JPEG_FRAME], val);
  608. }
  609. static void
  610. set_videobus_dir (struct zoran *zr,
  611. int val)
  612. {
  613. switch (zr->card.type) {
  614. case LML33:
  615. case LML33R10:
  616. if (lml33dpath == 0)
  617. GPIO(zr, 5, val);
  618. else
  619. GPIO(zr, 5, 1);
  620. break;
  621. default:
  622. GPIO(zr, zr->card.gpio[GPIO_VID_DIR],
  623. zr->card.gpio_pol[GPIO_VID_DIR] ? !val : val);
  624. break;
  625. }
  626. }
  627. static void
  628. init_jpeg_queue (struct zoran *zr)
  629. {
  630. int i;
  631. /* re-initialize DMA ring stuff */
  632. zr->jpg_que_head = 0;
  633. zr->jpg_dma_head = 0;
  634. zr->jpg_dma_tail = 0;
  635. zr->jpg_que_tail = 0;
  636. zr->jpg_seq_num = 0;
  637. zr->JPEG_error = 0;
  638. zr->num_errors = 0;
  639. zr->jpg_err_seq = 0;
  640. zr->jpg_err_shift = 0;
  641. zr->jpg_queued_num = 0;
  642. for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
  643. zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
  644. }
  645. for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
  646. zr->stat_com[i] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
  647. }
  648. }
  649. static void
  650. zr36057_set_jpg (struct zoran *zr,
  651. enum zoran_codec_mode mode)
  652. {
  653. struct tvnorm *tvn;
  654. u32 reg;
  655. tvn = zr->timing;
  656. /* assert P_Reset, disable code transfer, deassert Active */
  657. btwrite(0, ZR36057_JPC);
  658. /* MJPEG compression mode */
  659. switch (mode) {
  660. case BUZ_MODE_MOTION_COMPRESS:
  661. default:
  662. reg = ZR36057_JMC_MJPGCmpMode;
  663. break;
  664. case BUZ_MODE_MOTION_DECOMPRESS:
  665. reg = ZR36057_JMC_MJPGExpMode;
  666. reg |= ZR36057_JMC_SyncMstr;
  667. /* RJ: The following is experimental - improves the output to screen */
  668. //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
  669. break;
  670. case BUZ_MODE_STILL_COMPRESS:
  671. reg = ZR36057_JMC_JPGCmpMode;
  672. break;
  673. case BUZ_MODE_STILL_DECOMPRESS:
  674. reg = ZR36057_JMC_JPGExpMode;
  675. break;
  676. }
  677. reg |= ZR36057_JMC_JPG;
  678. if (zr->jpg_settings.field_per_buff == 1)
  679. reg |= ZR36057_JMC_Fld_per_buff;
  680. btwrite(reg, ZR36057_JMC);
  681. /* vertical */
  682. btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
  683. reg = (6 << ZR36057_VSP_VsyncSize) |
  684. (tvn->Ht << ZR36057_VSP_FrmTot);
  685. btwrite(reg, ZR36057_VSP);
  686. reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
  687. (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
  688. btwrite(reg, ZR36057_FVAP);
  689. /* horizontal */
  690. if (zr->card.vfe_pol.hsync_pol)
  691. btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
  692. else
  693. btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
  694. reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
  695. (tvn->Wt << ZR36057_HSP_LineTot);
  696. btwrite(reg, ZR36057_HSP);
  697. reg = ((zr->jpg_settings.img_x +
  698. tvn->HStart + 4) << ZR36057_FHAP_NAX) |
  699. (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
  700. btwrite(reg, ZR36057_FHAP);
  701. /* field process parameters */
  702. if (zr->jpg_settings.odd_even)
  703. reg = ZR36057_FPP_Odd_Even;
  704. else
  705. reg = 0;
  706. btwrite(reg, ZR36057_FPP);
  707. /* Set proper VCLK Polarity, else colors will be wrong during playback */
  708. //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
  709. /* code base address */
  710. reg = virt_to_bus(zr->stat_com);
  711. btwrite(reg, ZR36057_JCBA);
  712. /* FIFO threshold (FIFO is 160. double words) */
  713. /* NOTE: decimal values here */
  714. switch (mode) {
  715. case BUZ_MODE_STILL_COMPRESS:
  716. case BUZ_MODE_MOTION_COMPRESS:
  717. if (zr->card.type != BUZ)
  718. reg = 140;
  719. else
  720. reg = 60;
  721. break;
  722. case BUZ_MODE_STILL_DECOMPRESS:
  723. case BUZ_MODE_MOTION_DECOMPRESS:
  724. reg = 20;
  725. break;
  726. default:
  727. reg = 80;
  728. break;
  729. }
  730. btwrite(reg, ZR36057_JCFT);
  731. zr36057_adjust_vfe(zr, mode);
  732. }
  733. void
  734. print_interrupts (struct zoran *zr)
  735. {
  736. int res, noerr = 0;
  737. printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
  738. if ((res = zr->field_counter) < -1 || res > 1) {
  739. printk(" FD:%d", res);
  740. }
  741. if ((res = zr->intr_counter_GIRQ1) != 0) {
  742. printk(" GIRQ1:%d", res);
  743. noerr++;
  744. }
  745. if ((res = zr->intr_counter_GIRQ0) != 0) {
  746. printk(" GIRQ0:%d", res);
  747. noerr++;
  748. }
  749. if ((res = zr->intr_counter_CodRepIRQ) != 0) {
  750. printk(" CodRepIRQ:%d", res);
  751. noerr++;
  752. }
  753. if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
  754. printk(" JPEGRepIRQ:%d", res);
  755. noerr++;
  756. }
  757. if (zr->JPEG_max_missed) {
  758. printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
  759. zr->JPEG_min_missed);
  760. }
  761. if (zr->END_event_missed) {
  762. printk(" ENDs missed: %d", zr->END_event_missed);
  763. }
  764. //if (zr->jpg_queued_num) {
  765. printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
  766. zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
  767. //}
  768. if (!noerr) {
  769. printk(": no interrupts detected.");
  770. }
  771. printk("\n");
  772. }
  773. void
  774. clear_interrupt_counters (struct zoran *zr)
  775. {
  776. zr->intr_counter_GIRQ1 = 0;
  777. zr->intr_counter_GIRQ0 = 0;
  778. zr->intr_counter_CodRepIRQ = 0;
  779. zr->intr_counter_JPEGRepIRQ = 0;
  780. zr->field_counter = 0;
  781. zr->IRQ1_in = 0;
  782. zr->IRQ1_out = 0;
  783. zr->JPEG_in = 0;
  784. zr->JPEG_out = 0;
  785. zr->JPEG_0 = 0;
  786. zr->JPEG_1 = 0;
  787. zr->END_event_missed = 0;
  788. zr->JPEG_missed = 0;
  789. zr->JPEG_max_missed = 0;
  790. zr->JPEG_min_missed = 0x7fffffff;
  791. }
  792. static u32
  793. count_reset_interrupt (struct zoran *zr)
  794. {
  795. u32 isr;
  796. if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
  797. if (isr & ZR36057_ISR_GIRQ1) {
  798. btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
  799. zr->intr_counter_GIRQ1++;
  800. }
  801. if (isr & ZR36057_ISR_GIRQ0) {
  802. btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
  803. zr->intr_counter_GIRQ0++;
  804. }
  805. if (isr & ZR36057_ISR_CodRepIRQ) {
  806. btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
  807. zr->intr_counter_CodRepIRQ++;
  808. }
  809. if (isr & ZR36057_ISR_JPEGRepIRQ) {
  810. btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
  811. zr->intr_counter_JPEGRepIRQ++;
  812. }
  813. }
  814. return isr;
  815. }
  816. /* hack */
  817. extern void zr36016_write (struct videocodec *codec,
  818. u16 reg,
  819. u32 val);
  820. void
  821. jpeg_start (struct zoran *zr)
  822. {
  823. int reg;
  824. zr->frame_num = 0;
  825. /* deassert P_reset, disable code transfer, deassert Active */
  826. btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
  827. /* stop flushing the internal code buffer */
  828. btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
  829. /* enable code transfer */
  830. btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
  831. /* clear IRQs */
  832. btwrite(IRQ_MASK, ZR36057_ISR);
  833. /* enable the JPEG IRQs */
  834. btwrite(zr->card.jpeg_int |
  835. ZR36057_ICR_JPEGRepIRQ |
  836. ZR36057_ICR_IntPinEn,
  837. ZR36057_ICR);
  838. set_frame(zr, 0); // \FRAME
  839. /* set the JPEG codec guest ID */
  840. reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
  841. (0 << ZR36057_JCGI_JPEGuestReg);
  842. btwrite(reg, ZR36057_JCGI);
  843. if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
  844. zr->card.video_codec == CODEC_TYPE_ZR36050) {
  845. /* Enable processing on the ZR36016 */
  846. if (zr->vfe)
  847. zr36016_write(zr->vfe, 0, 1);
  848. /* load the address of the GO register in the ZR36050 latch */
  849. post_office_write(zr, 0, 0, 0);
  850. }
  851. /* assert Active */
  852. btor(ZR36057_JPC_Active, ZR36057_JPC);
  853. /* enable the Go generation */
  854. btor(ZR36057_JMC_Go_en, ZR36057_JMC);
  855. udelay(30);
  856. set_frame(zr, 1); // /FRAME
  857. dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
  858. }
  859. void
  860. zr36057_enable_jpg (struct zoran *zr,
  861. enum zoran_codec_mode mode)
  862. {
  863. static int zero = 0;
  864. static int one = 1;
  865. struct vfe_settings cap;
  866. int field_size =
  867. zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
  868. zr->codec_mode = mode;
  869. cap.x = zr->jpg_settings.img_x;
  870. cap.y = zr->jpg_settings.img_y;
  871. cap.width = zr->jpg_settings.img_width;
  872. cap.height = zr->jpg_settings.img_height;
  873. cap.decimation =
  874. zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
  875. cap.quality = zr->jpg_settings.jpg_comp.quality;
  876. switch (mode) {
  877. case BUZ_MODE_MOTION_COMPRESS: {
  878. struct jpeg_app_marker app;
  879. struct jpeg_com_marker com;
  880. /* In motion compress mode, the decoder output must be enabled, and
  881. * the video bus direction set to input.
  882. */
  883. set_videobus_dir(zr, 0);
  884. decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
  885. encoder_command(zr, ENCODER_SET_INPUT, &zero);
  886. /* Take the JPEG codec and the VFE out of sleep */
  887. jpeg_codec_sleep(zr, 0);
  888. /* set JPEG app/com marker */
  889. app.appn = zr->jpg_settings.jpg_comp.APPn;
  890. app.len = zr->jpg_settings.jpg_comp.APP_len;
  891. memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
  892. zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
  893. sizeof(struct jpeg_app_marker), &app);
  894. com.len = zr->jpg_settings.jpg_comp.COM_len;
  895. memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
  896. zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
  897. sizeof(struct jpeg_com_marker), &com);
  898. /* Setup the JPEG codec */
  899. zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
  900. sizeof(int), &field_size);
  901. zr->codec->set_video(zr->codec, zr->timing, &cap,
  902. &zr->card.vfe_pol);
  903. zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
  904. /* Setup the VFE */
  905. if (zr->vfe) {
  906. zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
  907. sizeof(int), &field_size);
  908. zr->vfe->set_video(zr->vfe, zr->timing, &cap,
  909. &zr->card.vfe_pol);
  910. zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
  911. }
  912. init_jpeg_queue(zr);
  913. zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
  914. clear_interrupt_counters(zr);
  915. dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
  916. ZR_DEVNAME(zr));
  917. break;
  918. }
  919. case BUZ_MODE_MOTION_DECOMPRESS:
  920. /* In motion decompression mode, the decoder output must be disabled, and
  921. * the video bus direction set to output.
  922. */
  923. decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
  924. set_videobus_dir(zr, 1);
  925. encoder_command(zr, ENCODER_SET_INPUT, &one);
  926. /* Take the JPEG codec and the VFE out of sleep */
  927. jpeg_codec_sleep(zr, 0);
  928. /* Setup the VFE */
  929. if (zr->vfe) {
  930. zr->vfe->set_video(zr->vfe, zr->timing, &cap,
  931. &zr->card.vfe_pol);
  932. zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
  933. }
  934. /* Setup the JPEG codec */
  935. zr->codec->set_video(zr->codec, zr->timing, &cap,
  936. &zr->card.vfe_pol);
  937. zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
  938. init_jpeg_queue(zr);
  939. zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
  940. clear_interrupt_counters(zr);
  941. dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
  942. ZR_DEVNAME(zr));
  943. break;
  944. case BUZ_MODE_IDLE:
  945. default:
  946. /* shut down processing */
  947. btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
  948. ZR36057_ICR);
  949. btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
  950. ZR36057_ISR);
  951. btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
  952. msleep(50);
  953. set_videobus_dir(zr, 0);
  954. set_frame(zr, 1); // /FRAME
  955. btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); // /CFlush
  956. btwrite(0, ZR36057_JPC); // \P_Reset,\CodTrnsEn,\Active
  957. btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
  958. btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
  959. jpeg_codec_reset(zr);
  960. jpeg_codec_sleep(zr, 1);
  961. zr36057_adjust_vfe(zr, mode);
  962. decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
  963. encoder_command(zr, ENCODER_SET_INPUT, &zero);
  964. dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
  965. break;
  966. }
  967. }
  968. /* when this is called the spinlock must be held */
  969. void
  970. zoran_feed_stat_com (struct zoran *zr)
  971. {
  972. /* move frames from pending queue to DMA */
  973. int frame, i, max_stat_com;
  974. max_stat_com =
  975. (zr->jpg_settings.TmpDcm ==
  976. 1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
  977. while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
  978. zr->jpg_dma_head < zr->jpg_que_head) {
  979. frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
  980. if (zr->jpg_settings.TmpDcm == 1) {
  981. /* fill 1 stat_com entry */
  982. i = (zr->jpg_dma_head -
  983. zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
  984. if (!(zr->stat_com[i] & cpu_to_le32(1)))
  985. break;
  986. zr->stat_com[i] =
  987. cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
  988. } else {
  989. /* fill 2 stat_com entries */
  990. i = ((zr->jpg_dma_head -
  991. zr->jpg_err_shift) & 1) * 2;
  992. if (!(zr->stat_com[i] & cpu_to_le32(1)))
  993. break;
  994. zr->stat_com[i] =
  995. cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
  996. zr->stat_com[i + 1] =
  997. cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
  998. }
  999. zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
  1000. zr->jpg_dma_head++;
  1001. }
  1002. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
  1003. zr->jpg_queued_num++;
  1004. }
  1005. /* when this is called the spinlock must be held */
  1006. static void
  1007. zoran_reap_stat_com (struct zoran *zr)
  1008. {
  1009. /* move frames from DMA queue to done queue */
  1010. int i;
  1011. u32 stat_com;
  1012. unsigned int seq;
  1013. unsigned int dif;
  1014. struct zoran_jpg_buffer *buffer;
  1015. int frame;
  1016. /* In motion decompress we don't have a hardware frame counter,
  1017. * we just count the interrupts here */
  1018. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
  1019. zr->jpg_seq_num++;
  1020. }
  1021. while (zr->jpg_dma_tail < zr->jpg_dma_head) {
  1022. if (zr->jpg_settings.TmpDcm == 1)
  1023. i = (zr->jpg_dma_tail -
  1024. zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
  1025. else
  1026. i = ((zr->jpg_dma_tail -
  1027. zr->jpg_err_shift) & 1) * 2 + 1;
  1028. stat_com = le32_to_cpu(zr->stat_com[i]);
  1029. if ((stat_com & 1) == 0) {
  1030. return;
  1031. }
  1032. frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
  1033. buffer = &zr->jpg_buffers.buffer[frame];
  1034. do_gettimeofday(&buffer->bs.timestamp);
  1035. if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1036. buffer->bs.length = (stat_com & 0x7fffff) >> 1;
  1037. /* update sequence number with the help of the counter in stat_com */
  1038. seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
  1039. dif = (seq - zr->jpg_seq_num) & 0xff;
  1040. zr->jpg_seq_num += dif;
  1041. } else {
  1042. buffer->bs.length = 0;
  1043. }
  1044. buffer->bs.seq =
  1045. zr->jpg_settings.TmpDcm ==
  1046. 2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
  1047. buffer->state = BUZ_STATE_DONE;
  1048. zr->jpg_dma_tail++;
  1049. }
  1050. }
  1051. static void
  1052. error_handler (struct zoran *zr,
  1053. u32 astat,
  1054. u32 stat)
  1055. {
  1056. /* This is JPEG error handling part */
  1057. if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) &&
  1058. (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) {
  1059. //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
  1060. return;
  1061. }
  1062. if ((stat & 1) == 0 &&
  1063. zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
  1064. zr->jpg_dma_tail - zr->jpg_que_tail >=
  1065. zr->jpg_buffers.num_buffers) {
  1066. /* No free buffers... */
  1067. zoran_reap_stat_com(zr);
  1068. zoran_feed_stat_com(zr);
  1069. wake_up_interruptible(&zr->jpg_capq);
  1070. zr->JPEG_missed = 0;
  1071. return;
  1072. }
  1073. if (zr->JPEG_error != 1) {
  1074. /*
  1075. * First entry: error just happened during normal operation
  1076. *
  1077. * In BUZ_MODE_MOTION_COMPRESS:
  1078. *
  1079. * Possible glitch in TV signal. In this case we should
  1080. * stop the codec and wait for good quality signal before
  1081. * restarting it to avoid further problems
  1082. *
  1083. * In BUZ_MODE_MOTION_DECOMPRESS:
  1084. *
  1085. * Bad JPEG frame: we have to mark it as processed (codec crashed
  1086. * and was not able to do it itself), and to remove it from queue.
  1087. */
  1088. btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
  1089. udelay(1);
  1090. stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
  1091. btwrite(0, ZR36057_JPC);
  1092. btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
  1093. jpeg_codec_reset(zr);
  1094. jpeg_codec_sleep(zr, 1);
  1095. zr->JPEG_error = 1;
  1096. zr->num_errors++;
  1097. /* Report error */
  1098. if (*zr_debug > 1 && zr->num_errors <= 8) {
  1099. long frame;
  1100. frame =
  1101. zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
  1102. printk(KERN_ERR
  1103. "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
  1104. ZR_DEVNAME(zr), stat, zr->last_isr,
  1105. zr->jpg_que_tail, zr->jpg_dma_tail,
  1106. zr->jpg_dma_head, zr->jpg_que_head,
  1107. zr->jpg_seq_num, frame);
  1108. printk("stat_com frames:");
  1109. {
  1110. int i, j;
  1111. for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
  1112. for (i = 0;
  1113. i < zr->jpg_buffers.num_buffers;
  1114. i++) {
  1115. if (le32_to_cpu(zr->stat_com[j]) ==
  1116. zr->jpg_buffers.
  1117. buffer[i].
  1118. frag_tab_bus) {
  1119. printk("% d->%d",
  1120. j, i);
  1121. }
  1122. }
  1123. }
  1124. printk("\n");
  1125. }
  1126. }
  1127. /* Find an entry in stat_com and rotate contents */
  1128. {
  1129. int i;
  1130. if (zr->jpg_settings.TmpDcm == 1)
  1131. i = (zr->jpg_dma_tail -
  1132. zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
  1133. else
  1134. i = ((zr->jpg_dma_tail -
  1135. zr->jpg_err_shift) & 1) * 2;
  1136. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
  1137. /* Mimic zr36067 operation */
  1138. zr->stat_com[i] |= cpu_to_le32(1);
  1139. if (zr->jpg_settings.TmpDcm != 1)
  1140. zr->stat_com[i + 1] |= cpu_to_le32(1);
  1141. /* Refill */
  1142. zoran_reap_stat_com(zr);
  1143. zoran_feed_stat_com(zr);
  1144. wake_up_interruptible(&zr->jpg_capq);
  1145. /* Find an entry in stat_com again after refill */
  1146. if (zr->jpg_settings.TmpDcm == 1)
  1147. i = (zr->jpg_dma_tail -
  1148. zr->jpg_err_shift) &
  1149. BUZ_MASK_STAT_COM;
  1150. else
  1151. i = ((zr->jpg_dma_tail -
  1152. zr->jpg_err_shift) & 1) * 2;
  1153. }
  1154. if (i) {
  1155. /* Rotate stat_comm entries to make current entry first */
  1156. int j;
  1157. u32 bus_addr[BUZ_NUM_STAT_COM];
  1158. /* Here we are copying the stat_com array, which
  1159. * is already in little endian format, so
  1160. * no endian conversions here
  1161. */
  1162. memcpy(bus_addr, zr->stat_com,
  1163. sizeof(bus_addr));
  1164. for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
  1165. zr->stat_com[j] =
  1166. bus_addr[(i + j) &
  1167. BUZ_MASK_STAT_COM];
  1168. }
  1169. zr->jpg_err_shift += i;
  1170. zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
  1171. }
  1172. if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
  1173. zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
  1174. }
  1175. }
  1176. /* Now the stat_comm buffer is ready for restart */
  1177. do {
  1178. int status, mode;
  1179. if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1180. decoder_command(zr, DECODER_GET_STATUS, &status);
  1181. mode = CODEC_DO_COMPRESSION;
  1182. } else {
  1183. status = 0;
  1184. mode = CODEC_DO_EXPANSION;
  1185. }
  1186. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
  1187. (status & DECODER_STATUS_GOOD)) {
  1188. /********** RESTART code *************/
  1189. jpeg_codec_reset(zr);
  1190. zr->codec->set_mode(zr->codec, mode);
  1191. zr36057_set_jpg(zr, zr->codec_mode);
  1192. jpeg_start(zr);
  1193. if (zr->num_errors <= 8)
  1194. dprintk(2, KERN_INFO "%s: Restart\n",
  1195. ZR_DEVNAME(zr));
  1196. zr->JPEG_missed = 0;
  1197. zr->JPEG_error = 2;
  1198. /********** End RESTART code ***********/
  1199. }
  1200. } while (0);
  1201. }
  1202. irqreturn_t
  1203. zoran_irq (int irq,
  1204. void *dev_id)
  1205. {
  1206. u32 stat, astat;
  1207. int count;
  1208. struct zoran *zr;
  1209. unsigned long flags;
  1210. zr = dev_id;
  1211. count = 0;
  1212. if (zr->testing) {
  1213. /* Testing interrupts */
  1214. spin_lock_irqsave(&zr->spinlock, flags);
  1215. while ((stat = count_reset_interrupt(zr))) {
  1216. if (count++ > 100) {
  1217. btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
  1218. dprintk(1,
  1219. KERN_ERR
  1220. "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
  1221. ZR_DEVNAME(zr), stat);
  1222. wake_up_interruptible(&zr->test_q);
  1223. }
  1224. }
  1225. zr->last_isr = stat;
  1226. spin_unlock_irqrestore(&zr->spinlock, flags);
  1227. return IRQ_HANDLED;
  1228. }
  1229. spin_lock_irqsave(&zr->spinlock, flags);
  1230. while (1) {
  1231. /* get/clear interrupt status bits */
  1232. stat = count_reset_interrupt(zr);
  1233. astat = stat & IRQ_MASK;
  1234. if (!astat) {
  1235. break;
  1236. }
  1237. dprintk(4,
  1238. KERN_DEBUG
  1239. "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
  1240. astat, btread(ZR36057_ICR));
  1241. if (astat & zr->card.vsync_int) { // SW
  1242. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
  1243. zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1244. /* count missed interrupts */
  1245. zr->JPEG_missed++;
  1246. }
  1247. //post_office_read(zr,1,0);
  1248. /* Interrupts may still happen when
  1249. * zr->v4l_memgrab_active is switched off.
  1250. * We simply ignore them */
  1251. if (zr->v4l_memgrab_active) {
  1252. /* A lot more checks should be here ... */
  1253. if ((btread(ZR36057_VSSFGR) &
  1254. ZR36057_VSSFGR_SnapShot) == 0)
  1255. dprintk(1,
  1256. KERN_WARNING
  1257. "%s: BuzIRQ with SnapShot off ???\n",
  1258. ZR_DEVNAME(zr));
  1259. if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
  1260. /* There is a grab on a frame going on, check if it has finished */
  1261. if ((btread(ZR36057_VSSFGR) &
  1262. ZR36057_VSSFGR_FrameGrab) ==
  1263. 0) {
  1264. /* it is finished, notify the user */
  1265. zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
  1266. zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
  1267. do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
  1268. zr->v4l_grab_frame = NO_GRAB_ACTIVE;
  1269. zr->v4l_pend_tail++;
  1270. }
  1271. }
  1272. if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
  1273. wake_up_interruptible(&zr->v4l_capq);
  1274. /* Check if there is another grab queued */
  1275. if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
  1276. zr->v4l_pend_tail != zr->v4l_pend_head) {
  1277. int frame = zr->v4l_pend[zr->v4l_pend_tail &
  1278. V4L_MASK_FRAME];
  1279. u32 reg;
  1280. zr->v4l_grab_frame = frame;
  1281. /* Set zr36057 video front end and enable video */
  1282. /* Buffer address */
  1283. reg =
  1284. zr->v4l_buffers.buffer[frame].
  1285. fbuffer_bus;
  1286. btwrite(reg, ZR36057_VDTR);
  1287. if (zr->v4l_settings.height >
  1288. BUZ_MAX_HEIGHT / 2)
  1289. reg +=
  1290. zr->v4l_settings.
  1291. bytesperline;
  1292. btwrite(reg, ZR36057_VDBR);
  1293. /* video stride, status, and frame grab register */
  1294. reg = 0;
  1295. if (zr->v4l_settings.height >
  1296. BUZ_MAX_HEIGHT / 2)
  1297. reg +=
  1298. zr->v4l_settings.
  1299. bytesperline;
  1300. reg =
  1301. (reg <<
  1302. ZR36057_VSSFGR_DispStride);
  1303. reg |= ZR36057_VSSFGR_VidOvf;
  1304. reg |= ZR36057_VSSFGR_SnapShot;
  1305. reg |= ZR36057_VSSFGR_FrameGrab;
  1306. btwrite(reg, ZR36057_VSSFGR);
  1307. btor(ZR36057_VDCR_VidEn,
  1308. ZR36057_VDCR);
  1309. }
  1310. }
  1311. /* even if we don't grab, we do want to increment
  1312. * the sequence counter to see lost frames */
  1313. zr->v4l_grab_seq++;
  1314. }
  1315. #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
  1316. if (astat & ZR36057_ISR_CodRepIRQ) {
  1317. zr->intr_counter_CodRepIRQ++;
  1318. IDEBUG(printk
  1319. (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
  1320. ZR_DEVNAME(zr)));
  1321. btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
  1322. }
  1323. #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
  1324. #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
  1325. if (astat & ZR36057_ISR_JPEGRepIRQ) {
  1326. if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
  1327. zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
  1328. if (*zr_debug > 1 &&
  1329. (!zr->frame_num || zr->JPEG_error)) {
  1330. printk(KERN_INFO
  1331. "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
  1332. ZR_DEVNAME(zr), stat,
  1333. zr->jpg_settings.odd_even,
  1334. zr->jpg_settings.
  1335. field_per_buff,
  1336. zr->JPEG_missed);
  1337. {
  1338. char sc[] = "0000";
  1339. char sv[5];
  1340. int i;
  1341. strcpy(sv, sc);
  1342. for (i = 0; i < 4; i++) {
  1343. if (le32_to_cpu(zr->stat_com[i]) & 1)
  1344. sv[i] = '1';
  1345. }
  1346. sv[4] = 0;
  1347. printk(KERN_INFO
  1348. "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
  1349. ZR_DEVNAME(zr), sv,
  1350. zr->jpg_que_tail,
  1351. zr->jpg_dma_tail,
  1352. zr->jpg_dma_head,
  1353. zr->jpg_que_head);
  1354. }
  1355. } else {
  1356. if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics
  1357. zr->JPEG_max_missed =
  1358. zr->JPEG_missed;
  1359. if (zr->JPEG_missed <
  1360. zr->JPEG_min_missed)
  1361. zr->JPEG_min_missed =
  1362. zr->JPEG_missed;
  1363. }
  1364. if (*zr_debug > 2 && zr->frame_num < 6) {
  1365. int i;
  1366. printk("%s: seq=%ld stat_com:",
  1367. ZR_DEVNAME(zr), zr->jpg_seq_num);
  1368. for (i = 0; i < 4; i++) {
  1369. printk(" %08x",
  1370. le32_to_cpu(zr->stat_com[i]));
  1371. }
  1372. printk("\n");
  1373. }
  1374. zr->frame_num++;
  1375. zr->JPEG_missed = 0;
  1376. zr->JPEG_error = 0;
  1377. zoran_reap_stat_com(zr);
  1378. zoran_feed_stat_com(zr);
  1379. wake_up_interruptible(&zr->jpg_capq);
  1380. } /*else {
  1381. dprintk(1,
  1382. KERN_ERR
  1383. "%s: JPEG interrupt while not in motion (de)compress mode!\n",
  1384. ZR_DEVNAME(zr));
  1385. }*/
  1386. }
  1387. #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
  1388. /* DATERR, too many fields missed, error processing */
  1389. if ((astat & zr->card.jpeg_int) ||
  1390. zr->JPEG_missed > 25 ||
  1391. zr->JPEG_error == 1 ||
  1392. ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
  1393. (zr->frame_num & (zr->JPEG_missed >
  1394. zr->jpg_settings.field_per_buff)))) {
  1395. error_handler(zr, astat, stat);
  1396. }
  1397. count++;
  1398. if (count > 10) {
  1399. dprintk(2, KERN_WARNING "%s: irq loop %d\n",
  1400. ZR_DEVNAME(zr), count);
  1401. if (count > 20) {
  1402. btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
  1403. dprintk(2,
  1404. KERN_ERR
  1405. "%s: IRQ lockup, cleared int mask\n",
  1406. ZR_DEVNAME(zr));
  1407. break;
  1408. }
  1409. }
  1410. zr->last_isr = stat;
  1411. }
  1412. spin_unlock_irqrestore(&zr->spinlock, flags);
  1413. return IRQ_HANDLED;
  1414. }
  1415. void
  1416. zoran_set_pci_master (struct zoran *zr,
  1417. int set_master)
  1418. {
  1419. if (set_master) {
  1420. pci_set_master(zr->pci_dev);
  1421. } else {
  1422. u16 command;
  1423. pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
  1424. command &= ~PCI_COMMAND_MASTER;
  1425. pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
  1426. }
  1427. }
  1428. void
  1429. zoran_init_hardware (struct zoran *zr)
  1430. {
  1431. int j, zero = 0;
  1432. /* Enable bus-mastering */
  1433. zoran_set_pci_master(zr, 1);
  1434. /* Initialize the board */
  1435. if (zr->card.init) {
  1436. zr->card.init(zr);
  1437. }
  1438. j = zr->card.input[zr->input].muxsel;
  1439. decoder_command(zr, 0, NULL);
  1440. decoder_command(zr, DECODER_SET_NORM, &zr->norm);
  1441. decoder_command(zr, DECODER_SET_INPUT, &j);
  1442. encoder_command(zr, 0, NULL);
  1443. encoder_command(zr, ENCODER_SET_NORM, &zr->norm);
  1444. encoder_command(zr, ENCODER_SET_INPUT, &zero);
  1445. /* toggle JPEG codec sleep to sync PLL */
  1446. jpeg_codec_sleep(zr, 1);
  1447. jpeg_codec_sleep(zr, 0);
  1448. /* set individual interrupt enables (without GIRQ1)
  1449. * but don't global enable until zoran_open() */
  1450. //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW
  1451. // It looks like using only JPEGRepIRQEn is not always reliable,
  1452. // may be when JPEG codec crashes it won't generate IRQ? So,
  1453. /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
  1454. zr36057_init_vfe(zr);
  1455. zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
  1456. btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
  1457. }
  1458. void
  1459. zr36057_restart (struct zoran *zr)
  1460. {
  1461. btwrite(0, ZR36057_SPGPPCR);
  1462. mdelay(1);
  1463. btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
  1464. mdelay(1);
  1465. /* assert P_Reset */
  1466. btwrite(0, ZR36057_JPC);
  1467. /* set up GPIO direction - all output */
  1468. btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
  1469. /* set up GPIO pins and guest bus timing */
  1470. btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
  1471. }
  1472. /*
  1473. * initialize video front end
  1474. */
  1475. static void
  1476. zr36057_init_vfe (struct zoran *zr)
  1477. {
  1478. u32 reg;
  1479. reg = btread(ZR36057_VFESPFR);
  1480. reg |= ZR36057_VFESPFR_LittleEndian;
  1481. reg &= ~ZR36057_VFESPFR_VCLKPol;
  1482. reg |= ZR36057_VFESPFR_ExtFl;
  1483. reg |= ZR36057_VFESPFR_TopField;
  1484. btwrite(reg, ZR36057_VFESPFR);
  1485. reg = btread(ZR36057_VDCR);
  1486. if (pci_pci_problems & PCIPCI_TRITON)
  1487. // || zr->revision < 1) // Revision 1 has also Triton support
  1488. reg &= ~ZR36057_VDCR_Triton;
  1489. else
  1490. reg |= ZR36057_VDCR_Triton;
  1491. btwrite(reg, ZR36057_VDCR);
  1492. }
  1493. /*
  1494. * Interface to decoder and encoder chips using i2c bus
  1495. */
  1496. int
  1497. decoder_command (struct zoran *zr,
  1498. int cmd,
  1499. void *data)
  1500. {
  1501. if (zr->decoder == NULL)
  1502. return -EIO;
  1503. if (zr->card.type == LML33 &&
  1504. (cmd == DECODER_SET_NORM || DECODER_SET_INPUT)) {
  1505. int res;
  1506. // Bt819 needs to reset its FIFO buffer using #FRST pin and
  1507. // LML33 card uses GPIO(7) for that.
  1508. GPIO(zr, 7, 0);
  1509. res = zr->decoder->driver->command(zr->decoder, cmd, data);
  1510. // Pull #FRST high.
  1511. GPIO(zr, 7, 1);
  1512. return res;
  1513. } else
  1514. return zr->decoder->driver->command(zr->decoder, cmd,
  1515. data);
  1516. }
  1517. int
  1518. encoder_command (struct zoran *zr,
  1519. int cmd,
  1520. void *data)
  1521. {
  1522. if (zr->encoder == NULL)
  1523. return -1;
  1524. return zr->encoder->driver->command(zr->encoder, cmd, data);
  1525. }