zoran_device.c 44 KB

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