2 * Zoran zr36057/zr36067 PCI controller driver, for the
3 * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
4 * Media Labs LML33/LML33R10.
6 * This part handles device access (PCI/I2C/codec/...)
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
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>
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.
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.
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.
30 #include <linux/types.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/vmalloc.h>
34 #include <linux/byteorder/generic.h>
36 #include <linux/interrupt.h>
37 #include <linux/proc_fs.h>
38 #include <linux/i2c.h>
39 #include <linux/i2c-algo-bit.h>
40 #include <linux/videodev.h>
41 #include <linux/spinlock.h>
42 #include <linux/sem.h>
44 #include <linux/pci.h>
45 #include <linux/video_decoder.h>
46 #include <linux/video_encoder.h>
47 #include <linux/delay.h>
48 #include <linux/wait.h>
52 #include "videocodec.h"
54 #include "zoran_device.h"
55 #include "zoran_card.h"
57 #define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
59 ZR36057_ISR_JPEGRepIRQ )
61 extern const struct zoran_format zoran_formats[];
63 static int lml33dpath = 0; /* 1 will use digital path in capture
64 * mode instead of analog. It can be
65 * used for picture adjustments using
66 * tool like xawtv while watching image
67 * on TV monitor connected to the output.
68 * However, due to absence of 75 Ohm
69 * load on Bt819 input, there will be
70 * some image imperfections */
72 module_param(lml33dpath, bool, 0644);
73 MODULE_PARM_DESC(lml33dpath,
74 "Use digital path capture mode (on LML33 cards)");
77 zr36057_init_vfe (struct zoran *zr);
80 * General Purpose I/O and Guest bus access
84 * This is a bit tricky. When a board lacks a GPIO function, the corresponding
85 * GPIO bit number in the card_info structure is set to 0.
89 GPIO (struct zoran *zr,
96 /* Make sure the bit number is legal
97 * A bit number of -1 (lacking) gives a mask of 0,
98 * making it harmless */
99 mask = (1 << (24 + bit)) & 0xff000000;
100 reg = btread(ZR36057_GPPGCR1) & ~mask;
104 btwrite(reg, ZR36057_GPPGCR1);
109 * Wait til post office is no longer busy
113 post_office_wait (struct zoran *zr)
117 // while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
118 while ((por = btread(ZR36057_POR)) & ZR36057_POR_POPen) {
119 /* wait for something to happen */
121 if ((por & ZR36057_POR_POTime) && !zr->card.gws_not_connected) {
122 /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
123 dprintk(1, KERN_INFO "%s: pop timeout %08x\n", ZR_DEVNAME(zr),
132 post_office_write (struct zoran *zr,
140 ZR36057_POR_PODir | ZR36057_POR_POTime | ((guest & 7) << 20) |
141 ((reg & 7) << 16) | (value & 0xFF);
142 btwrite(por, ZR36057_POR);
144 return post_office_wait(zr);
148 post_office_read (struct zoran *zr,
154 por = ZR36057_POR_POTime | ((guest & 7) << 20) | ((reg & 7) << 16);
155 btwrite(por, ZR36057_POR);
156 if (post_office_wait(zr) < 0) {
160 return btread(ZR36057_POR) & 0xFF;
168 dump_guests (struct zoran *zr)
170 if (zr36067_debug > 2) {
173 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
174 guest[i] = post_office_read(zr, i, 0);
177 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
179 for (i = 1; i < 8; i++) {
180 printk(" 0x%02x", guest[i]);
186 static inline unsigned long
191 do_gettimeofday(&tv);
192 return (1000000 * tv.tv_sec + tv.tv_usec);
196 detect_guest_activity (struct zoran *zr)
198 int timeout, i, j, res, guest[8], guest0[8], change[8][3];
199 unsigned long t0, t1;
202 printk(KERN_INFO "%s: Detecting guests activity, please wait...\n",
204 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
205 guest0[i] = guest[i] = post_office_read(zr, i, 0);
211 while (timeout < 10000) {
214 for (i = 1; (i < 8) && (j < 8); i++) {
215 res = post_office_read(zr, i, 0);
216 if (res != guest[i]) {
218 change[j][0] = (t1 - t0);
229 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
231 for (i = 1; i < 8; i++) {
232 printk(" 0x%02x", guest0[i]);
236 printk(KERN_INFO "%s: No activity detected.\n", ZR_DEVNAME(zr));
239 for (i = 0; i < j; i++) {
240 printk(KERN_INFO "%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr),
241 change[i][0], change[i][1], change[i][2]);
250 jpeg_codec_sleep (struct zoran *zr,
253 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_SLEEP], !sleep);
257 "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
258 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
263 "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
264 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
270 jpeg_codec_reset (struct zoran *zr)
272 /* Take the codec out of sleep */
273 jpeg_codec_sleep(zr, 0);
275 if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) {
276 post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0,
280 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 0);
282 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 1);
290 * Set the registers for the size we have specified. Don't bother
291 * trying to understand this without the ZR36057 manual in front of
294 * PS: The manual is free for download in .pdf format from
295 * www.zoran.com - nicely done those folks.
299 zr36057_adjust_vfe (struct zoran *zr,
300 enum zoran_codec_mode mode)
305 case BUZ_MODE_MOTION_DECOMPRESS:
306 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
307 reg = btread(ZR36057_VFEHCR);
308 if ((reg & (1 << 10)) && zr->card.type != LML33R10) {
309 reg += ((1 << 10) | 1);
311 btwrite(reg, ZR36057_VFEHCR);
313 case BUZ_MODE_MOTION_COMPRESS:
316 if (zr->norm == VIDEO_MODE_NTSC ||
317 (zr->card.type == LML33R10 &&
318 zr->norm == VIDEO_MODE_PAL))
319 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
321 btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
322 reg = btread(ZR36057_VFEHCR);
323 if (!(reg & (1 << 10)) && zr->card.type != LML33R10) {
324 reg -= ((1 << 10) | 1);
326 btwrite(reg, ZR36057_VFEHCR);
336 zr36057_set_vfe (struct zoran *zr,
339 const struct zoran_format *format)
342 unsigned HStart, HEnd, VStart, VEnd;
344 unsigned VidWinWid, VidWinHt;
345 unsigned hcrop1, hcrop2, vcrop1, vcrop2;
346 unsigned Wa, We, Ha, He;
347 unsigned X, Y, HorDcm, VerDcm;
349 unsigned mask_line_size;
356 dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
357 ZR_DEVNAME(zr), video_width, video_height);
359 if (zr->norm != VIDEO_MODE_PAL &&
360 zr->norm != VIDEO_MODE_NTSC &&
361 zr->norm != VIDEO_MODE_SECAM) {
363 KERN_ERR "%s: set_vfe() - norm = %d not valid\n",
364 ZR_DEVNAME(zr), zr->norm);
367 if (video_width < BUZ_MIN_WIDTH ||
368 video_height < BUZ_MIN_HEIGHT ||
369 video_width > Wa || video_height > Ha) {
370 dprintk(1, KERN_ERR "%s: set_vfe: w=%d h=%d not valid\n",
371 ZR_DEVNAME(zr), video_width, video_height);
378 VidWinWid = video_width;
379 X = (VidWinWid * 64 + tvn->Wa - 1) / tvn->Wa;
380 We = (VidWinWid * 64) / X;
382 hcrop1 = 2 * ((tvn->Wa - We) / 4);
383 hcrop2 = tvn->Wa - We - hcrop1;
384 HStart = tvn->HStart ? tvn->HStart : 1;
385 /* (Ronald) Original comment:
386 * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
387 * this is false. It inverses chroma values on the LML33R10 (so Cr
388 * suddenly is shown as Cb and reverse, really cool effect if you
389 * want to see blue faces, not useful otherwise). So don't use |1.
390 * However, the DC10 has '0' as HStart, but does need |1, so we
391 * use a dirty check...
393 HEnd = HStart + tvn->Wa - 1;
396 reg = ((HStart & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HStart)
397 | ((HEnd & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HEnd);
398 if (zr->card.vfe_pol.hsync_pol)
399 reg |= ZR36057_VFEHCR_HSPol;
400 btwrite(reg, ZR36057_VFEHCR);
403 DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
404 VidWinHt = DispMode ? video_height : video_height / 2;
405 Y = (VidWinHt * 64 * 2 + tvn->Ha - 1) / tvn->Ha;
406 He = (VidWinHt * 64) / Y;
408 vcrop1 = (tvn->Ha / 2 - He) / 2;
409 vcrop2 = tvn->Ha / 2 - He - vcrop1;
410 VStart = tvn->VStart;
411 VEnd = VStart + tvn->Ha / 2; // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
414 reg = ((VStart & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VStart)
415 | ((VEnd & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VEnd);
416 if (zr->card.vfe_pol.vsync_pol)
417 reg |= ZR36057_VFEVCR_VSPol;
418 btwrite(reg, ZR36057_VFEVCR);
420 /* scaler and pixel format */
422 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
423 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
424 reg |= (DispMode << ZR36057_VFESPFR_DispMode);
425 /* RJ: I don't know, why the following has to be the opposite
426 * of the corresponding ZR36060 setting, but only this way
427 * we get the correct colors when uncompressing to the screen */
428 //reg |= ZR36057_VFESPFR_VCLKPol; /**/
429 /* RJ: Don't know if that is needed for NTSC also */
430 if (zr->norm != VIDEO_MODE_NTSC)
431 reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang
432 reg |= ZR36057_VFESPFR_TopField;
434 reg |= 3 << ZR36057_VFESPFR_HFilter; /* 5 tap filter */
435 } else if (HorDcm >= 32) {
436 reg |= 2 << ZR36057_VFESPFR_HFilter; /* 4 tap filter */
437 } else if (HorDcm >= 16) {
438 reg |= 1 << ZR36057_VFESPFR_HFilter; /* 3 tap filter */
440 reg |= format->vfespfr;
441 btwrite(reg, ZR36057_VFESPFR);
443 /* display configuration */
444 reg = (16 << ZR36057_VDCR_MinPix)
445 | (VidWinHt << ZR36057_VDCR_VidWinHt)
446 | (VidWinWid << ZR36057_VDCR_VidWinWid);
447 if (pci_pci_problems & PCIPCI_TRITON)
448 // || zr->revision < 1) // Revision 1 has also Triton support
449 reg &= ~ZR36057_VDCR_Triton;
451 reg |= ZR36057_VDCR_Triton;
452 btwrite(reg, ZR36057_VDCR);
454 /* (Ronald) don't write this if overlay_mask = NULL */
455 if (zr->overlay_mask) {
456 /* Write overlay clipping mask data, but don't enable overlay clipping */
457 /* RJ: since this makes only sense on the screen, we use
458 * zr->overlay_settings.width instead of video_width */
460 mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
461 reg = virt_to_bus(zr->overlay_mask);
462 btwrite(reg, ZR36057_MMTR);
463 reg = virt_to_bus(zr->overlay_mask + mask_line_size);
464 btwrite(reg, ZR36057_MMBR);
466 mask_line_size - (zr->overlay_settings.width +
469 reg += mask_line_size;
470 reg <<= ZR36057_OCR_MaskStride;
471 btwrite(reg, ZR36057_OCR);
474 zr36057_adjust_vfe(zr, zr->codec_mode);
478 * Switch overlay on or off
482 zr36057_overlay (struct zoran *zr,
488 /* do the necessary settings ... */
489 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR); /* switch it off first */
492 zr->overlay_settings.width,
493 zr->overlay_settings.height,
494 zr->overlay_settings.format);
496 /* Start and length of each line MUST be 4-byte aligned.
497 * This should be allready checked before the call to this routine.
498 * All error messages are internal driver checking only! */
500 /* video display top and bottom registers */
501 reg = (long) zr->buffer.base +
502 zr->overlay_settings.x *
503 ((zr->overlay_settings.format->depth + 7) / 8) +
504 zr->overlay_settings.y *
505 zr->buffer.bytesperline;
506 btwrite(reg, ZR36057_VDTR);
510 "%s: zr36057_overlay() - video_address not aligned\n",
512 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
513 reg += zr->buffer.bytesperline;
514 btwrite(reg, ZR36057_VDBR);
516 /* video stride, status, and frame grab register */
517 reg = zr->buffer.bytesperline -
518 zr->overlay_settings.width *
519 ((zr->overlay_settings.format->depth + 7) / 8);
520 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
521 reg += zr->buffer.bytesperline;
525 "%s: zr36057_overlay() - video_stride not aligned\n",
527 reg = (reg << ZR36057_VSSFGR_DispStride);
528 reg |= ZR36057_VSSFGR_VidOvf; /* clear overflow status */
529 btwrite(reg, ZR36057_VSSFGR);
531 /* Set overlay clipping */
532 if (zr->overlay_settings.clipcount > 0)
533 btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
535 /* ... and switch it on */
536 btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
539 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
544 * The overlay mask has one bit for each pixel on a scan line,
545 * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
549 write_overlay_mask (struct file *file,
550 struct video_clip *vp,
553 struct zoran_fh *fh = file->private_data;
554 struct zoran *zr = fh->zr;
555 unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
557 int x, y, width, height;
561 /* fill mask with one bits */
562 memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
565 for (i = 0; i < count; ++i) {
566 /* pick up local copy of clip */
570 height = vp[i].height;
572 /* trim clips that extend beyond the window */
581 if (x + width > fh->overlay_settings.width) {
582 width = fh->overlay_settings.width - x;
584 if (y + height > fh->overlay_settings.height) {
585 height = fh->overlay_settings.height - y;
588 /* ignore degenerate clips */
596 /* apply clip for each scan line */
597 for (j = 0; j < height; ++j) {
598 /* reset bit for each pixel */
599 /* this can be optimized later if need be */
600 mask = fh->overlay_mask + (y + j) * mask_line_size;
601 for (k = 0; k < width; ++k) {
602 mask[(x + k) / 32] &=
603 ~((u32) 1 << (x + k) % 32);
609 /* Enable/Disable uncompressed memory grabbing of the 36057 */
612 zr36057_set_memgrab (struct zoran *zr,
616 /* We only check SnapShot and not FrameGrab here. SnapShot==1
617 * means a capture is already in progress, but FrameGrab==1
618 * doesn't necessary mean that. It's more correct to say a 1
619 * to 0 transition indicates a capture completed. If a
620 * capture is pending when capturing is tuned off, FrameGrab
621 * will be stuck at 1 until capturing is turned back on.
623 if (btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot)
626 "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
629 /* switch on VSync interrupts */
630 btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
631 btor(zr->card.vsync_int, ZR36057_ICR); // SW
633 /* enable SnapShot */
634 btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
636 /* Set zr36057 video front end and enable video */
637 zr36057_set_vfe(zr, zr->v4l_settings.width,
638 zr->v4l_settings.height,
639 zr->v4l_settings.format);
641 zr->v4l_memgrab_active = 1;
643 /* switch off VSync interrupts */
644 btand(~zr->card.vsync_int, ZR36057_ICR); // SW
646 zr->v4l_memgrab_active = 0;
647 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
649 /* reenable grabbing to screen if it was running */
650 if (zr->v4l_overlay_active) {
651 zr36057_overlay(zr, 1);
653 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
654 btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
660 wait_grab_pending (struct zoran *zr)
664 /* wait until all pending grabs are finished */
666 if (!zr->v4l_memgrab_active)
669 wait_event_interruptible(zr->v4l_capq,
670 (zr->v4l_pend_tail == zr->v4l_pend_head));
671 if (signal_pending(current))
674 spin_lock_irqsave(&zr->spinlock, flags);
675 zr36057_set_memgrab(zr, 0);
676 spin_unlock_irqrestore(&zr->spinlock, flags);
681 /*****************************************************************************
683 * Set up the Buz-specific MJPEG part *
685 *****************************************************************************/
688 set_frame (struct zoran *zr,
691 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_FRAME], val);
695 set_videobus_dir (struct zoran *zr,
698 switch (zr->card.type) {
707 GPIO(zr, zr->card.gpio[ZR_GPIO_VID_DIR],
708 zr->card.gpio_pol[ZR_GPIO_VID_DIR] ? !val : val);
714 init_jpeg_queue (struct zoran *zr)
718 /* re-initialize DMA ring stuff */
719 zr->jpg_que_head = 0;
720 zr->jpg_dma_head = 0;
721 zr->jpg_dma_tail = 0;
722 zr->jpg_que_tail = 0;
727 zr->jpg_err_shift = 0;
728 zr->jpg_queued_num = 0;
729 for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
730 zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
732 for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
733 zr->stat_com[i] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
738 zr36057_set_jpg (struct zoran *zr,
739 enum zoran_codec_mode mode)
746 /* assert P_Reset, disable code transfer, deassert Active */
747 btwrite(0, ZR36057_JPC);
749 /* MJPEG compression mode */
752 case BUZ_MODE_MOTION_COMPRESS:
754 reg = ZR36057_JMC_MJPGCmpMode;
757 case BUZ_MODE_MOTION_DECOMPRESS:
758 reg = ZR36057_JMC_MJPGExpMode;
759 reg |= ZR36057_JMC_SyncMstr;
760 /* RJ: The following is experimental - improves the output to screen */
761 //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
764 case BUZ_MODE_STILL_COMPRESS:
765 reg = ZR36057_JMC_JPGCmpMode;
768 case BUZ_MODE_STILL_DECOMPRESS:
769 reg = ZR36057_JMC_JPGExpMode;
773 reg |= ZR36057_JMC_JPG;
774 if (zr->jpg_settings.field_per_buff == 1)
775 reg |= ZR36057_JMC_Fld_per_buff;
776 btwrite(reg, ZR36057_JMC);
779 btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
780 reg = (6 << ZR36057_VSP_VsyncSize) |
781 (tvn->Ht << ZR36057_VSP_FrmTot);
782 btwrite(reg, ZR36057_VSP);
783 reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
784 (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
785 btwrite(reg, ZR36057_FVAP);
788 if (zr->card.vfe_pol.hsync_pol)
789 btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
791 btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
792 reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
793 (tvn->Wt << ZR36057_HSP_LineTot);
794 btwrite(reg, ZR36057_HSP);
795 reg = ((zr->jpg_settings.img_x +
796 tvn->HStart + 4) << ZR36057_FHAP_NAX) |
797 (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
798 btwrite(reg, ZR36057_FHAP);
800 /* field process parameters */
801 if (zr->jpg_settings.odd_even)
802 reg = ZR36057_FPP_Odd_Even;
806 btwrite(reg, ZR36057_FPP);
808 /* Set proper VCLK Polarity, else colors will be wrong during playback */
809 //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
811 /* code base address */
812 reg = virt_to_bus(zr->stat_com);
813 btwrite(reg, ZR36057_JCBA);
815 /* FIFO threshold (FIFO is 160. double words) */
816 /* NOTE: decimal values here */
819 case BUZ_MODE_STILL_COMPRESS:
820 case BUZ_MODE_MOTION_COMPRESS:
821 if (zr->card.type != BUZ)
827 case BUZ_MODE_STILL_DECOMPRESS:
828 case BUZ_MODE_MOTION_DECOMPRESS:
837 btwrite(reg, ZR36057_JCFT);
838 zr36057_adjust_vfe(zr, mode);
843 print_interrupts (struct zoran *zr)
847 printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
848 if ((res = zr->field_counter) < -1 || res > 1) {
849 printk(" FD:%d", res);
851 if ((res = zr->intr_counter_GIRQ1) != 0) {
852 printk(" GIRQ1:%d", res);
855 if ((res = zr->intr_counter_GIRQ0) != 0) {
856 printk(" GIRQ0:%d", res);
859 if ((res = zr->intr_counter_CodRepIRQ) != 0) {
860 printk(" CodRepIRQ:%d", res);
863 if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
864 printk(" JPEGRepIRQ:%d", res);
867 if (zr->JPEG_max_missed) {
868 printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
869 zr->JPEG_min_missed);
871 if (zr->END_event_missed) {
872 printk(" ENDs missed: %d", zr->END_event_missed);
874 //if (zr->jpg_queued_num) {
875 printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
876 zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
879 printk(": no interrupts detected.");
885 clear_interrupt_counters (struct zoran *zr)
887 zr->intr_counter_GIRQ1 = 0;
888 zr->intr_counter_GIRQ0 = 0;
889 zr->intr_counter_CodRepIRQ = 0;
890 zr->intr_counter_JPEGRepIRQ = 0;
891 zr->field_counter = 0;
898 zr->END_event_missed = 0;
900 zr->JPEG_max_missed = 0;
901 zr->JPEG_min_missed = 0x7fffffff;
905 count_reset_interrupt (struct zoran *zr)
909 if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
910 if (isr & ZR36057_ISR_GIRQ1) {
911 btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
912 zr->intr_counter_GIRQ1++;
914 if (isr & ZR36057_ISR_GIRQ0) {
915 btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
916 zr->intr_counter_GIRQ0++;
918 if (isr & ZR36057_ISR_CodRepIRQ) {
919 btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
920 zr->intr_counter_CodRepIRQ++;
922 if (isr & ZR36057_ISR_JPEGRepIRQ) {
923 btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
924 zr->intr_counter_JPEGRepIRQ++;
931 extern void zr36016_write (struct videocodec *codec,
936 jpeg_start (struct zoran *zr)
942 /* deassert P_reset, disable code transfer, deassert Active */
943 btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
944 /* stop flushing the internal code buffer */
945 btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
946 /* enable code transfer */
947 btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
950 btwrite(IRQ_MASK, ZR36057_ISR);
951 /* enable the JPEG IRQs */
952 btwrite(zr->card.jpeg_int |
953 ZR36057_ICR_JPEGRepIRQ |
954 ZR36057_ICR_IntPinEn,
957 set_frame(zr, 0); // \FRAME
959 /* set the JPEG codec guest ID */
960 reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
961 (0 << ZR36057_JCGI_JPEGuestReg);
962 btwrite(reg, ZR36057_JCGI);
964 if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
965 zr->card.video_codec == CODEC_TYPE_ZR36050) {
966 /* Enable processing on the ZR36016 */
968 zr36016_write(zr->vfe, 0, 1);
970 /* load the address of the GO register in the ZR36050 latch */
971 post_office_write(zr, 0, 0, 0);
975 btor(ZR36057_JPC_Active, ZR36057_JPC);
977 /* enable the Go generation */
978 btor(ZR36057_JMC_Go_en, ZR36057_JMC);
981 set_frame(zr, 1); // /FRAME
983 dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
987 zr36057_enable_jpg (struct zoran *zr,
988 enum zoran_codec_mode mode)
992 struct vfe_settings cap;
994 zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
996 zr->codec_mode = mode;
998 cap.x = zr->jpg_settings.img_x;
999 cap.y = zr->jpg_settings.img_y;
1000 cap.width = zr->jpg_settings.img_width;
1001 cap.height = zr->jpg_settings.img_height;
1003 zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
1004 cap.quality = zr->jpg_settings.jpg_comp.quality;
1008 case BUZ_MODE_MOTION_COMPRESS: {
1009 struct jpeg_app_marker app;
1010 struct jpeg_com_marker com;
1012 /* In motion compress mode, the decoder output must be enabled, and
1013 * the video bus direction set to input.
1015 set_videobus_dir(zr, 0);
1016 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
1017 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1019 /* Take the JPEG codec and the VFE out of sleep */
1020 jpeg_codec_sleep(zr, 0);
1022 /* set JPEG app/com marker */
1023 app.appn = zr->jpg_settings.jpg_comp.APPn;
1024 app.len = zr->jpg_settings.jpg_comp.APP_len;
1025 memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
1026 zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
1027 sizeof(struct jpeg_app_marker), &app);
1029 com.len = zr->jpg_settings.jpg_comp.COM_len;
1030 memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
1031 zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
1032 sizeof(struct jpeg_com_marker), &com);
1034 /* Setup the JPEG codec */
1035 zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
1036 sizeof(int), &field_size);
1037 zr->codec->set_video(zr->codec, zr->timing, &cap,
1039 zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
1043 zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
1044 sizeof(int), &field_size);
1045 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1047 zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
1050 init_jpeg_queue(zr);
1051 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1053 clear_interrupt_counters(zr);
1054 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
1059 case BUZ_MODE_MOTION_DECOMPRESS:
1060 /* In motion decompression mode, the decoder output must be disabled, and
1061 * the video bus direction set to output.
1063 decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
1064 set_videobus_dir(zr, 1);
1065 encoder_command(zr, ENCODER_SET_INPUT, &one);
1067 /* Take the JPEG codec and the VFE out of sleep */
1068 jpeg_codec_sleep(zr, 0);
1071 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1073 zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
1075 /* Setup the JPEG codec */
1076 zr->codec->set_video(zr->codec, zr->timing, &cap,
1078 zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
1080 init_jpeg_queue(zr);
1081 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1083 clear_interrupt_counters(zr);
1084 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
1090 /* shut down processing */
1091 btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
1093 btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
1095 btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
1099 set_videobus_dir(zr, 0);
1100 set_frame(zr, 1); // /FRAME
1101 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); // /CFlush
1102 btwrite(0, ZR36057_JPC); // \P_Reset,\CodTrnsEn,\Active
1103 btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
1104 btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
1105 jpeg_codec_reset(zr);
1106 jpeg_codec_sleep(zr, 1);
1107 zr36057_adjust_vfe(zr, mode);
1109 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
1110 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1112 dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
1118 /* when this is called the spinlock must be held */
1120 zoran_feed_stat_com (struct zoran *zr)
1122 /* move frames from pending queue to DMA */
1124 int frame, i, max_stat_com;
1127 (zr->jpg_settings.TmpDcm ==
1128 1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
1130 while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
1131 zr->jpg_dma_head < zr->jpg_que_head) {
1133 frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
1134 if (zr->jpg_settings.TmpDcm == 1) {
1135 /* fill 1 stat_com entry */
1136 i = (zr->jpg_dma_head -
1137 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1138 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1141 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1143 /* fill 2 stat_com entries */
1144 i = ((zr->jpg_dma_head -
1145 zr->jpg_err_shift) & 1) * 2;
1146 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1149 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1150 zr->stat_com[i + 1] =
1151 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1153 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
1157 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
1158 zr->jpg_queued_num++;
1161 /* when this is called the spinlock must be held */
1163 zoran_reap_stat_com (struct zoran *zr)
1165 /* move frames from DMA queue to done queue */
1171 struct zoran_jpg_buffer *buffer;
1174 /* In motion decompress we don't have a hardware frame counter,
1175 * we just count the interrupts here */
1177 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1180 while (zr->jpg_dma_tail < zr->jpg_dma_head) {
1181 if (zr->jpg_settings.TmpDcm == 1)
1182 i = (zr->jpg_dma_tail -
1183 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1185 i = ((zr->jpg_dma_tail -
1186 zr->jpg_err_shift) & 1) * 2 + 1;
1188 stat_com = le32_to_cpu(zr->stat_com[i]);
1190 if ((stat_com & 1) == 0) {
1193 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1194 buffer = &zr->jpg_buffers.buffer[frame];
1195 do_gettimeofday(&buffer->bs.timestamp);
1197 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1198 buffer->bs.length = (stat_com & 0x7fffff) >> 1;
1200 /* update sequence number with the help of the counter in stat_com */
1202 seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
1203 dif = (seq - zr->jpg_seq_num) & 0xff;
1204 zr->jpg_seq_num += dif;
1206 buffer->bs.length = 0;
1209 zr->jpg_settings.TmpDcm ==
1210 2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
1211 buffer->state = BUZ_STATE_DONE;
1218 error_handler (struct zoran *zr,
1222 /* This is JPEG error handling part */
1223 if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) &&
1224 (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) {
1225 //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
1229 if ((stat & 1) == 0 &&
1230 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
1231 zr->jpg_dma_tail - zr->jpg_que_tail >=
1232 zr->jpg_buffers.num_buffers) {
1233 /* No free buffers... */
1234 zoran_reap_stat_com(zr);
1235 zoran_feed_stat_com(zr);
1236 wake_up_interruptible(&zr->jpg_capq);
1237 zr->JPEG_missed = 0;
1241 if (zr->JPEG_error != 1) {
1243 * First entry: error just happened during normal operation
1245 * In BUZ_MODE_MOTION_COMPRESS:
1247 * Possible glitch in TV signal. In this case we should
1248 * stop the codec and wait for good quality signal before
1249 * restarting it to avoid further problems
1251 * In BUZ_MODE_MOTION_DECOMPRESS:
1253 * Bad JPEG frame: we have to mark it as processed (codec crashed
1254 * and was not able to do it itself), and to remove it from queue.
1256 btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
1258 stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
1259 btwrite(0, ZR36057_JPC);
1260 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
1261 jpeg_codec_reset(zr);
1262 jpeg_codec_sleep(zr, 1);
1267 if (zr36067_debug > 1 && zr->num_errors <= 8) {
1270 zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1272 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1273 ZR_DEVNAME(zr), stat, zr->last_isr,
1274 zr->jpg_que_tail, zr->jpg_dma_tail,
1275 zr->jpg_dma_head, zr->jpg_que_head,
1276 zr->jpg_seq_num, frame);
1277 printk("stat_com frames:");
1280 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1282 i < zr->jpg_buffers.num_buffers;
1284 if (le32_to_cpu(zr->stat_com[j]) ==
1296 /* Find an entry in stat_com and rotate contents */
1300 if (zr->jpg_settings.TmpDcm == 1)
1301 i = (zr->jpg_dma_tail -
1302 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1304 i = ((zr->jpg_dma_tail -
1305 zr->jpg_err_shift) & 1) * 2;
1306 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1307 /* Mimic zr36067 operation */
1308 zr->stat_com[i] |= cpu_to_le32(1);
1309 if (zr->jpg_settings.TmpDcm != 1)
1310 zr->stat_com[i + 1] |= cpu_to_le32(1);
1312 zoran_reap_stat_com(zr);
1313 zoran_feed_stat_com(zr);
1314 wake_up_interruptible(&zr->jpg_capq);
1315 /* Find an entry in stat_com again after refill */
1316 if (zr->jpg_settings.TmpDcm == 1)
1317 i = (zr->jpg_dma_tail -
1318 zr->jpg_err_shift) &
1321 i = ((zr->jpg_dma_tail -
1322 zr->jpg_err_shift) & 1) * 2;
1325 /* Rotate stat_comm entries to make current entry first */
1327 u32 bus_addr[BUZ_NUM_STAT_COM];
1329 /* Here we are copying the stat_com array, which
1330 * is already in little endian format, so
1331 * no endian conversions here
1333 memcpy(bus_addr, zr->stat_com,
1335 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1341 zr->jpg_err_shift += i;
1342 zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
1344 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
1345 zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
1349 /* Now the stat_comm buffer is ready for restart */
1353 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1354 decoder_command(zr, DECODER_GET_STATUS, &status);
1355 mode = CODEC_DO_COMPRESSION;
1358 mode = CODEC_DO_EXPANSION;
1360 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1361 (status & DECODER_STATUS_GOOD)) {
1362 /********** RESTART code *************/
1363 jpeg_codec_reset(zr);
1364 zr->codec->set_mode(zr->codec, mode);
1365 zr36057_set_jpg(zr, zr->codec_mode);
1368 if (zr->num_errors <= 8)
1369 dprintk(2, KERN_INFO "%s: Restart\n",
1372 zr->JPEG_missed = 0;
1374 /********** End RESTART code ***********/
1386 unsigned long flags;
1392 /* Testing interrupts */
1393 spin_lock_irqsave(&zr->spinlock, flags);
1394 while ((stat = count_reset_interrupt(zr))) {
1395 if (count++ > 100) {
1396 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1399 "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
1400 ZR_DEVNAME(zr), stat);
1401 wake_up_interruptible(&zr->test_q);
1404 zr->last_isr = stat;
1405 spin_unlock_irqrestore(&zr->spinlock, flags);
1409 spin_lock_irqsave(&zr->spinlock, flags);
1411 /* get/clear interrupt status bits */
1412 stat = count_reset_interrupt(zr);
1413 astat = stat & IRQ_MASK;
1419 "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
1420 astat, btread(ZR36057_ICR));
1421 if (astat & zr->card.vsync_int) { // SW
1423 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1424 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1425 /* count missed interrupts */
1428 //post_office_read(zr,1,0);
1429 /* Interrupts may still happen when
1430 * zr->v4l_memgrab_active is switched off.
1431 * We simply ignore them */
1433 if (zr->v4l_memgrab_active) {
1435 /* A lot more checks should be here ... */
1436 if ((btread(ZR36057_VSSFGR) &
1437 ZR36057_VSSFGR_SnapShot) == 0)
1440 "%s: BuzIRQ with SnapShot off ???\n",
1443 if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
1444 /* There is a grab on a frame going on, check if it has finished */
1446 if ((btread(ZR36057_VSSFGR) &
1447 ZR36057_VSSFGR_FrameGrab) ==
1449 /* it is finished, notify the user */
1451 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
1452 zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
1453 do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
1454 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
1455 zr->v4l_pend_tail++;
1459 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
1460 wake_up_interruptible(&zr->v4l_capq);
1462 /* Check if there is another grab queued */
1464 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
1465 zr->v4l_pend_tail != zr->v4l_pend_head) {
1467 int frame = zr->v4l_pend[zr->v4l_pend_tail &
1471 zr->v4l_grab_frame = frame;
1473 /* Set zr36057 video front end and enable video */
1475 /* Buffer address */
1478 zr->v4l_buffers.buffer[frame].
1480 btwrite(reg, ZR36057_VDTR);
1481 if (zr->v4l_settings.height >
1486 btwrite(reg, ZR36057_VDBR);
1488 /* video stride, status, and frame grab register */
1490 if (zr->v4l_settings.height >
1497 ZR36057_VSSFGR_DispStride);
1498 reg |= ZR36057_VSSFGR_VidOvf;
1499 reg |= ZR36057_VSSFGR_SnapShot;
1500 reg |= ZR36057_VSSFGR_FrameGrab;
1501 btwrite(reg, ZR36057_VSSFGR);
1503 btor(ZR36057_VDCR_VidEn,
1508 /* even if we don't grab, we do want to increment
1509 * the sequence counter to see lost frames */
1512 #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1513 if (astat & ZR36057_ISR_CodRepIRQ) {
1514 zr->intr_counter_CodRepIRQ++;
1516 (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
1518 btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
1520 #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
1522 #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1523 if (astat & ZR36057_ISR_JPEGRepIRQ) {
1525 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1526 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1527 if (zr36067_debug > 1 &&
1528 (!zr->frame_num || zr->JPEG_error)) {
1530 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1531 ZR_DEVNAME(zr), stat,
1532 zr->jpg_settings.odd_even,
1541 for (i = 0; i < 4; i++) {
1542 if (le32_to_cpu(zr->stat_com[i]) & 1)
1547 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1555 if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics
1556 zr->JPEG_max_missed =
1558 if (zr->JPEG_missed <
1559 zr->JPEG_min_missed)
1560 zr->JPEG_min_missed =
1564 if (zr36067_debug > 2 && zr->frame_num < 6) {
1566 printk("%s: seq=%ld stat_com:",
1567 ZR_DEVNAME(zr), zr->jpg_seq_num);
1568 for (i = 0; i < 4; i++) {
1570 le32_to_cpu(zr->stat_com[i]));
1575 zr->JPEG_missed = 0;
1577 zoran_reap_stat_com(zr);
1578 zoran_feed_stat_com(zr);
1579 wake_up_interruptible(&zr->jpg_capq);
1583 "%s: JPEG interrupt while not in motion (de)compress mode!\n",
1587 #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
1589 /* DATERR, too many fields missed, error processing */
1590 if ((astat & zr->card.jpeg_int) ||
1591 zr->JPEG_missed > 25 ||
1592 zr->JPEG_error == 1 ||
1593 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
1594 (zr->frame_num & (zr->JPEG_missed >
1595 zr->jpg_settings.field_per_buff)))) {
1596 error_handler(zr, astat, stat);
1601 dprintk(2, KERN_WARNING "%s: irq loop %d\n",
1602 ZR_DEVNAME(zr), count);
1604 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1607 "%s: IRQ lockup, cleared int mask\n",
1612 zr->last_isr = stat;
1614 spin_unlock_irqrestore(&zr->spinlock, flags);
1620 zoran_set_pci_master (struct zoran *zr,
1624 pci_set_master(zr->pci_dev);
1628 pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
1629 command &= ~PCI_COMMAND_MASTER;
1630 pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
1635 zoran_init_hardware (struct zoran *zr)
1639 /* Enable bus-mastering */
1640 zoran_set_pci_master(zr, 1);
1642 /* Initialize the board */
1643 if (zr->card.init) {
1647 j = zr->card.input[zr->input].muxsel;
1649 decoder_command(zr, 0, NULL);
1650 decoder_command(zr, DECODER_SET_NORM, &zr->norm);
1651 decoder_command(zr, DECODER_SET_INPUT, &j);
1653 encoder_command(zr, 0, NULL);
1654 encoder_command(zr, ENCODER_SET_NORM, &zr->norm);
1655 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1657 /* toggle JPEG codec sleep to sync PLL */
1658 jpeg_codec_sleep(zr, 1);
1659 jpeg_codec_sleep(zr, 0);
1661 /* set individual interrupt enables (without GIRQ1)
1662 * but don't global enable until zoran_open() */
1664 //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW
1665 // It looks like using only JPEGRepIRQEn is not always reliable,
1666 // may be when JPEG codec crashes it won't generate IRQ? So,
1667 /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
1668 zr36057_init_vfe(zr);
1670 zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
1672 btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
1676 zr36057_restart (struct zoran *zr)
1678 btwrite(0, ZR36057_SPGPPCR);
1680 btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
1683 /* assert P_Reset */
1684 btwrite(0, ZR36057_JPC);
1685 /* set up GPIO direction - all output */
1686 btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
1688 /* set up GPIO pins and guest bus timing */
1689 btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
1693 * initialize video front end
1697 zr36057_init_vfe (struct zoran *zr)
1701 reg = btread(ZR36057_VFESPFR);
1702 reg |= ZR36057_VFESPFR_LittleEndian;
1703 reg &= ~ZR36057_VFESPFR_VCLKPol;
1704 reg |= ZR36057_VFESPFR_ExtFl;
1705 reg |= ZR36057_VFESPFR_TopField;
1706 btwrite(reg, ZR36057_VFESPFR);
1707 reg = btread(ZR36057_VDCR);
1708 if (pci_pci_problems & PCIPCI_TRITON)
1709 // || zr->revision < 1) // Revision 1 has also Triton support
1710 reg &= ~ZR36057_VDCR_Triton;
1712 reg |= ZR36057_VDCR_Triton;
1713 btwrite(reg, ZR36057_VDCR);
1717 * Interface to decoder and encoder chips using i2c bus
1721 decoder_command (struct zoran *zr,
1725 if (zr->decoder == NULL)
1728 if (zr->card.type == LML33 &&
1729 (cmd == DECODER_SET_NORM || DECODER_SET_INPUT)) {
1732 // Bt819 needs to reset its FIFO buffer using #FRST pin and
1733 // LML33 card uses GPIO(7) for that.
1735 res = zr->decoder->driver->command(zr->decoder, cmd, data);
1740 return zr->decoder->driver->command(zr->decoder, cmd,
1745 encoder_command (struct zoran *zr,
1749 if (zr->encoder == NULL)
1752 return zr->encoder->driver->command(zr->encoder, cmd, data);