zoran_device.c 44 KB

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