zoran_device.c 44 KB

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