zoran_device.c 45 KB

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