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>
35 #include <linux/interrupt.h>
36 #include <linux/proc_fs.h>
37 #include <linux/i2c.h>
38 #include <linux/i2c-algo-bit.h>
39 #include <linux/videodev2.h>
40 #include <media/v4l2-common.h>
41 #include <linux/spinlock.h>
42 #include <linux/sem.h>
44 #include <linux/pci.h>
45 #include <linux/delay.h>
46 #include <linux/wait.h>
48 #include <asm/byteorder.h>
51 #include "videocodec.h"
53 #include "zoran_device.h"
54 #include "zoran_card.h"
56 #define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
58 ZR36057_ISR_JPEGRepIRQ )
60 static int lml33dpath; /* default = 0
61 * 1 will use digital path in capture
62 * mode instead of analog. It can be
63 * used for picture adjustments using
64 * tool like xawtv while watching image
65 * on TV monitor connected to the output.
66 * However, due to absence of 75 Ohm
67 * load on Bt819 input, there will be
68 * some image imperfections */
70 module_param(lml33dpath, bool, 0644);
71 MODULE_PARM_DESC(lml33dpath,
72 "Use digital path capture mode (on LML33 cards)");
75 zr36057_init_vfe (struct zoran *zr);
78 * General Purpose I/O and Guest bus access
82 * This is a bit tricky. When a board lacks a GPIO function, the corresponding
83 * GPIO bit number in the card_info structure is set to 0.
87 GPIO (struct zoran *zr,
94 /* Make sure the bit number is legal
95 * A bit number of -1 (lacking) gives a mask of 0,
96 * making it harmless */
97 mask = (1 << (24 + bit)) & 0xff000000;
98 reg = btread(ZR36057_GPPGCR1) & ~mask;
102 btwrite(reg, ZR36057_GPPGCR1);
107 * Wait til post office is no longer busy
111 post_office_wait (struct zoran *zr)
115 // while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
116 while ((por = btread(ZR36057_POR)) & ZR36057_POR_POPen) {
117 /* wait for something to happen */
119 if ((por & ZR36057_POR_POTime) && !zr->card.gws_not_connected) {
120 /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
121 dprintk(1, KERN_INFO "%s: pop timeout %08x\n", ZR_DEVNAME(zr),
130 post_office_write (struct zoran *zr,
138 ZR36057_POR_PODir | ZR36057_POR_POTime | ((guest & 7) << 20) |
139 ((reg & 7) << 16) | (value & 0xFF);
140 btwrite(por, ZR36057_POR);
142 return post_office_wait(zr);
146 post_office_read (struct zoran *zr,
152 por = ZR36057_POR_POTime | ((guest & 7) << 20) | ((reg & 7) << 16);
153 btwrite(por, ZR36057_POR);
154 if (post_office_wait(zr) < 0) {
158 return btread(ZR36057_POR) & 0xFF;
166 dump_guests (struct zoran *zr)
168 if (zr36067_debug > 2) {
171 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
172 guest[i] = post_office_read(zr, i, 0);
175 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
177 for (i = 1; i < 8; i++) {
178 printk(" 0x%02x", guest[i]);
184 static inline unsigned long
189 do_gettimeofday(&tv);
190 return (1000000 * tv.tv_sec + tv.tv_usec);
194 detect_guest_activity (struct zoran *zr)
196 int timeout, i, j, res, guest[8], guest0[8], change[8][3];
197 unsigned long t0, t1;
200 printk(KERN_INFO "%s: Detecting guests activity, please wait...\n",
202 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
203 guest0[i] = guest[i] = post_office_read(zr, i, 0);
209 while (timeout < 10000) {
212 for (i = 1; (i < 8) && (j < 8); i++) {
213 res = post_office_read(zr, i, 0);
214 if (res != guest[i]) {
216 change[j][0] = (t1 - t0);
227 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
229 for (i = 1; i < 8; i++) {
230 printk(" 0x%02x", guest0[i]);
234 printk(KERN_INFO "%s: No activity detected.\n", ZR_DEVNAME(zr));
237 for (i = 0; i < j; i++) {
238 printk(KERN_INFO "%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr),
239 change[i][0], change[i][1], change[i][2]);
248 jpeg_codec_sleep (struct zoran *zr,
251 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_SLEEP], !sleep);
255 "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
256 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
261 "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
262 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
268 jpeg_codec_reset (struct zoran *zr)
270 /* Take the codec out of sleep */
271 jpeg_codec_sleep(zr, 0);
273 if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) {
274 post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0,
278 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 0);
280 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 1);
288 * Set the registers for the size we have specified. Don't bother
289 * trying to understand this without the ZR36057 manual in front of
292 * PS: The manual is free for download in .pdf format from
293 * www.zoran.com - nicely done those folks.
297 zr36057_adjust_vfe (struct zoran *zr,
298 enum zoran_codec_mode mode)
303 case BUZ_MODE_MOTION_DECOMPRESS:
304 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
305 reg = btread(ZR36057_VFEHCR);
306 if ((reg & (1 << 10)) && zr->card.type != LML33R10) {
307 reg += ((1 << 10) | 1);
309 btwrite(reg, ZR36057_VFEHCR);
311 case BUZ_MODE_MOTION_COMPRESS:
314 if ((zr->norm & V4L2_STD_NTSC) ||
315 (zr->card.type == LML33R10 &&
316 (zr->norm & V4L2_STD_PAL)))
317 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
319 btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
320 reg = btread(ZR36057_VFEHCR);
321 if (!(reg & (1 << 10)) && zr->card.type != LML33R10) {
322 reg -= ((1 << 10) | 1);
324 btwrite(reg, ZR36057_VFEHCR);
334 zr36057_set_vfe (struct zoran *zr,
337 const struct zoran_format *format)
340 unsigned HStart, HEnd, VStart, VEnd;
342 unsigned VidWinWid, VidWinHt;
343 unsigned hcrop1, hcrop2, vcrop1, vcrop2;
344 unsigned Wa, We, Ha, He;
345 unsigned X, Y, HorDcm, VerDcm;
347 unsigned mask_line_size;
354 dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
355 ZR_DEVNAME(zr), video_width, video_height);
357 if (video_width < BUZ_MIN_WIDTH ||
358 video_height < BUZ_MIN_HEIGHT ||
359 video_width > Wa || video_height > Ha) {
360 dprintk(1, KERN_ERR "%s: set_vfe: w=%d h=%d not valid\n",
361 ZR_DEVNAME(zr), video_width, video_height);
368 VidWinWid = video_width;
369 X = DIV_ROUND_UP(VidWinWid * 64, tvn->Wa);
370 We = (VidWinWid * 64) / X;
372 hcrop1 = 2 * ((tvn->Wa - We) / 4);
373 hcrop2 = tvn->Wa - We - hcrop1;
374 HStart = tvn->HStart ? tvn->HStart : 1;
375 /* (Ronald) Original comment:
376 * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
377 * this is false. It inverses chroma values on the LML33R10 (so Cr
378 * suddenly is shown as Cb and reverse, really cool effect if you
379 * want to see blue faces, not useful otherwise). So don't use |1.
380 * However, the DC10 has '0' as HStart, but does need |1, so we
381 * use a dirty check...
383 HEnd = HStart + tvn->Wa - 1;
386 reg = ((HStart & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HStart)
387 | ((HEnd & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HEnd);
388 if (zr->card.vfe_pol.hsync_pol)
389 reg |= ZR36057_VFEHCR_HSPol;
390 btwrite(reg, ZR36057_VFEHCR);
393 DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
394 VidWinHt = DispMode ? video_height : video_height / 2;
395 Y = DIV_ROUND_UP(VidWinHt * 64 * 2, tvn->Ha);
396 He = (VidWinHt * 64) / Y;
398 vcrop1 = (tvn->Ha / 2 - He) / 2;
399 vcrop2 = tvn->Ha / 2 - He - vcrop1;
400 VStart = tvn->VStart;
401 VEnd = VStart + tvn->Ha / 2; // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
404 reg = ((VStart & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VStart)
405 | ((VEnd & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VEnd);
406 if (zr->card.vfe_pol.vsync_pol)
407 reg |= ZR36057_VFEVCR_VSPol;
408 btwrite(reg, ZR36057_VFEVCR);
410 /* scaler and pixel format */
412 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
413 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
414 reg |= (DispMode << ZR36057_VFESPFR_DispMode);
415 /* RJ: I don't know, why the following has to be the opposite
416 * of the corresponding ZR36060 setting, but only this way
417 * we get the correct colors when uncompressing to the screen */
418 //reg |= ZR36057_VFESPFR_VCLKPol; /**/
419 /* RJ: Don't know if that is needed for NTSC also */
420 if (!(zr->norm & V4L2_STD_NTSC))
421 reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang
422 reg |= ZR36057_VFESPFR_TopField;
424 reg |= 3 << ZR36057_VFESPFR_HFilter; /* 5 tap filter */
425 } else if (HorDcm >= 32) {
426 reg |= 2 << ZR36057_VFESPFR_HFilter; /* 4 tap filter */
427 } else if (HorDcm >= 16) {
428 reg |= 1 << ZR36057_VFESPFR_HFilter; /* 3 tap filter */
430 reg |= format->vfespfr;
431 btwrite(reg, ZR36057_VFESPFR);
433 /* display configuration */
434 reg = (16 << ZR36057_VDCR_MinPix)
435 | (VidWinHt << ZR36057_VDCR_VidWinHt)
436 | (VidWinWid << ZR36057_VDCR_VidWinWid);
437 if (pci_pci_problems & PCIPCI_TRITON)
438 // || zr->revision < 1) // Revision 1 has also Triton support
439 reg &= ~ZR36057_VDCR_Triton;
441 reg |= ZR36057_VDCR_Triton;
442 btwrite(reg, ZR36057_VDCR);
444 /* (Ronald) don't write this if overlay_mask = NULL */
445 if (zr->overlay_mask) {
446 /* Write overlay clipping mask data, but don't enable overlay clipping */
447 /* RJ: since this makes only sense on the screen, we use
448 * zr->overlay_settings.width instead of video_width */
450 mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
451 reg = virt_to_bus(zr->overlay_mask);
452 btwrite(reg, ZR36057_MMTR);
453 reg = virt_to_bus(zr->overlay_mask + mask_line_size);
454 btwrite(reg, ZR36057_MMBR);
456 mask_line_size - (zr->overlay_settings.width +
459 reg += mask_line_size;
460 reg <<= ZR36057_OCR_MaskStride;
461 btwrite(reg, ZR36057_OCR);
464 zr36057_adjust_vfe(zr, zr->codec_mode);
468 * Switch overlay on or off
472 zr36057_overlay (struct zoran *zr,
478 /* do the necessary settings ... */
479 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR); /* switch it off first */
482 zr->overlay_settings.width,
483 zr->overlay_settings.height,
484 zr->overlay_settings.format);
486 /* Start and length of each line MUST be 4-byte aligned.
487 * This should be allready checked before the call to this routine.
488 * All error messages are internal driver checking only! */
490 /* video display top and bottom registers */
491 reg = (long) zr->buffer.base +
492 zr->overlay_settings.x *
493 ((zr->overlay_settings.format->depth + 7) / 8) +
494 zr->overlay_settings.y *
495 zr->buffer.bytesperline;
496 btwrite(reg, ZR36057_VDTR);
500 "%s: zr36057_overlay() - video_address not aligned\n",
502 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
503 reg += zr->buffer.bytesperline;
504 btwrite(reg, ZR36057_VDBR);
506 /* video stride, status, and frame grab register */
507 reg = zr->buffer.bytesperline -
508 zr->overlay_settings.width *
509 ((zr->overlay_settings.format->depth + 7) / 8);
510 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
511 reg += zr->buffer.bytesperline;
515 "%s: zr36057_overlay() - video_stride not aligned\n",
517 reg = (reg << ZR36057_VSSFGR_DispStride);
518 reg |= ZR36057_VSSFGR_VidOvf; /* clear overflow status */
519 btwrite(reg, ZR36057_VSSFGR);
521 /* Set overlay clipping */
522 if (zr->overlay_settings.clipcount > 0)
523 btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
525 /* ... and switch it on */
526 btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
529 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
534 * The overlay mask has one bit for each pixel on a scan line,
535 * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
539 write_overlay_mask (struct file *file,
540 struct video_clip *vp,
543 struct zoran_fh *fh = file->private_data;
544 struct zoran *zr = fh->zr;
545 unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
547 int x, y, width, height;
551 /* fill mask with one bits */
552 memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
555 for (i = 0; i < count; ++i) {
556 /* pick up local copy of clip */
560 height = vp[i].height;
562 /* trim clips that extend beyond the window */
571 if (x + width > fh->overlay_settings.width) {
572 width = fh->overlay_settings.width - x;
574 if (y + height > fh->overlay_settings.height) {
575 height = fh->overlay_settings.height - y;
578 /* ignore degenerate clips */
586 /* apply clip for each scan line */
587 for (j = 0; j < height; ++j) {
588 /* reset bit for each pixel */
589 /* this can be optimized later if need be */
590 mask = fh->overlay_mask + (y + j) * mask_line_size;
591 for (k = 0; k < width; ++k) {
592 mask[(x + k) / 32] &=
593 ~((u32) 1 << (x + k) % 32);
599 /* Enable/Disable uncompressed memory grabbing of the 36057 */
602 zr36057_set_memgrab (struct zoran *zr,
606 /* We only check SnapShot and not FrameGrab here. SnapShot==1
607 * means a capture is already in progress, but FrameGrab==1
608 * doesn't necessary mean that. It's more correct to say a 1
609 * to 0 transition indicates a capture completed. If a
610 * capture is pending when capturing is tuned off, FrameGrab
611 * will be stuck at 1 until capturing is turned back on.
613 if (btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot)
616 "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
619 /* switch on VSync interrupts */
620 btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
621 btor(zr->card.vsync_int, ZR36057_ICR); // SW
623 /* enable SnapShot */
624 btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
626 /* Set zr36057 video front end and enable video */
627 zr36057_set_vfe(zr, zr->v4l_settings.width,
628 zr->v4l_settings.height,
629 zr->v4l_settings.format);
631 zr->v4l_memgrab_active = 1;
633 /* switch off VSync interrupts */
634 btand(~zr->card.vsync_int, ZR36057_ICR); // SW
636 zr->v4l_memgrab_active = 0;
637 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
639 /* reenable grabbing to screen if it was running */
640 if (zr->v4l_overlay_active) {
641 zr36057_overlay(zr, 1);
643 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
644 btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
650 wait_grab_pending (struct zoran *zr)
654 /* wait until all pending grabs are finished */
656 if (!zr->v4l_memgrab_active)
659 wait_event_interruptible(zr->v4l_capq,
660 (zr->v4l_pend_tail == zr->v4l_pend_head));
661 if (signal_pending(current))
664 spin_lock_irqsave(&zr->spinlock, flags);
665 zr36057_set_memgrab(zr, 0);
666 spin_unlock_irqrestore(&zr->spinlock, flags);
671 /*****************************************************************************
673 * Set up the Buz-specific MJPEG part *
675 *****************************************************************************/
678 set_frame (struct zoran *zr,
681 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_FRAME], val);
685 set_videobus_dir (struct zoran *zr,
688 switch (zr->card.type) {
697 GPIO(zr, zr->card.gpio[ZR_GPIO_VID_DIR],
698 zr->card.gpio_pol[ZR_GPIO_VID_DIR] ? !val : val);
704 init_jpeg_queue (struct zoran *zr)
708 /* re-initialize DMA ring stuff */
709 zr->jpg_que_head = 0;
710 zr->jpg_dma_head = 0;
711 zr->jpg_dma_tail = 0;
712 zr->jpg_que_tail = 0;
717 zr->jpg_err_shift = 0;
718 zr->jpg_queued_num = 0;
719 for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
720 zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
722 for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
723 zr->stat_com[i] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
728 zr36057_set_jpg (struct zoran *zr,
729 enum zoran_codec_mode mode)
736 /* assert P_Reset, disable code transfer, deassert Active */
737 btwrite(0, ZR36057_JPC);
739 /* MJPEG compression mode */
742 case BUZ_MODE_MOTION_COMPRESS:
744 reg = ZR36057_JMC_MJPGCmpMode;
747 case BUZ_MODE_MOTION_DECOMPRESS:
748 reg = ZR36057_JMC_MJPGExpMode;
749 reg |= ZR36057_JMC_SyncMstr;
750 /* RJ: The following is experimental - improves the output to screen */
751 //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
754 case BUZ_MODE_STILL_COMPRESS:
755 reg = ZR36057_JMC_JPGCmpMode;
758 case BUZ_MODE_STILL_DECOMPRESS:
759 reg = ZR36057_JMC_JPGExpMode;
763 reg |= ZR36057_JMC_JPG;
764 if (zr->jpg_settings.field_per_buff == 1)
765 reg |= ZR36057_JMC_Fld_per_buff;
766 btwrite(reg, ZR36057_JMC);
769 btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
770 reg = (6 << ZR36057_VSP_VsyncSize) |
771 (tvn->Ht << ZR36057_VSP_FrmTot);
772 btwrite(reg, ZR36057_VSP);
773 reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
774 (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
775 btwrite(reg, ZR36057_FVAP);
778 if (zr->card.vfe_pol.hsync_pol)
779 btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
781 btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
782 reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
783 (tvn->Wt << ZR36057_HSP_LineTot);
784 btwrite(reg, ZR36057_HSP);
785 reg = ((zr->jpg_settings.img_x +
786 tvn->HStart + 4) << ZR36057_FHAP_NAX) |
787 (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
788 btwrite(reg, ZR36057_FHAP);
790 /* field process parameters */
791 if (zr->jpg_settings.odd_even)
792 reg = ZR36057_FPP_Odd_Even;
796 btwrite(reg, ZR36057_FPP);
798 /* Set proper VCLK Polarity, else colors will be wrong during playback */
799 //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
801 /* code base address */
802 reg = virt_to_bus(zr->stat_com);
803 btwrite(reg, ZR36057_JCBA);
805 /* FIFO threshold (FIFO is 160. double words) */
806 /* NOTE: decimal values here */
809 case BUZ_MODE_STILL_COMPRESS:
810 case BUZ_MODE_MOTION_COMPRESS:
811 if (zr->card.type != BUZ)
817 case BUZ_MODE_STILL_DECOMPRESS:
818 case BUZ_MODE_MOTION_DECOMPRESS:
827 btwrite(reg, ZR36057_JCFT);
828 zr36057_adjust_vfe(zr, mode);
833 print_interrupts (struct zoran *zr)
837 printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
838 if ((res = zr->field_counter) < -1 || res > 1) {
839 printk(" FD:%d", res);
841 if ((res = zr->intr_counter_GIRQ1) != 0) {
842 printk(" GIRQ1:%d", res);
845 if ((res = zr->intr_counter_GIRQ0) != 0) {
846 printk(" GIRQ0:%d", res);
849 if ((res = zr->intr_counter_CodRepIRQ) != 0) {
850 printk(" CodRepIRQ:%d", res);
853 if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
854 printk(" JPEGRepIRQ:%d", res);
857 if (zr->JPEG_max_missed) {
858 printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
859 zr->JPEG_min_missed);
861 if (zr->END_event_missed) {
862 printk(" ENDs missed: %d", zr->END_event_missed);
864 //if (zr->jpg_queued_num) {
865 printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
866 zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
869 printk(": no interrupts detected.");
875 clear_interrupt_counters (struct zoran *zr)
877 zr->intr_counter_GIRQ1 = 0;
878 zr->intr_counter_GIRQ0 = 0;
879 zr->intr_counter_CodRepIRQ = 0;
880 zr->intr_counter_JPEGRepIRQ = 0;
881 zr->field_counter = 0;
888 zr->END_event_missed = 0;
890 zr->JPEG_max_missed = 0;
891 zr->JPEG_min_missed = 0x7fffffff;
895 count_reset_interrupt (struct zoran *zr)
899 if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
900 if (isr & ZR36057_ISR_GIRQ1) {
901 btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
902 zr->intr_counter_GIRQ1++;
904 if (isr & ZR36057_ISR_GIRQ0) {
905 btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
906 zr->intr_counter_GIRQ0++;
908 if (isr & ZR36057_ISR_CodRepIRQ) {
909 btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
910 zr->intr_counter_CodRepIRQ++;
912 if (isr & ZR36057_ISR_JPEGRepIRQ) {
913 btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
914 zr->intr_counter_JPEGRepIRQ++;
921 jpeg_start (struct zoran *zr)
927 /* deassert P_reset, disable code transfer, deassert Active */
928 btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
929 /* stop flushing the internal code buffer */
930 btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
931 /* enable code transfer */
932 btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
935 btwrite(IRQ_MASK, ZR36057_ISR);
936 /* enable the JPEG IRQs */
937 btwrite(zr->card.jpeg_int |
938 ZR36057_ICR_JPEGRepIRQ |
939 ZR36057_ICR_IntPinEn,
942 set_frame(zr, 0); // \FRAME
944 /* set the JPEG codec guest ID */
945 reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
946 (0 << ZR36057_JCGI_JPEGuestReg);
947 btwrite(reg, ZR36057_JCGI);
949 if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
950 zr->card.video_codec == CODEC_TYPE_ZR36050) {
951 /* Enable processing on the ZR36016 */
953 zr36016_write(zr->vfe, 0, 1);
955 /* load the address of the GO register in the ZR36050 latch */
956 post_office_write(zr, 0, 0, 0);
960 btor(ZR36057_JPC_Active, ZR36057_JPC);
962 /* enable the Go generation */
963 btor(ZR36057_JMC_Go_en, ZR36057_JMC);
966 set_frame(zr, 1); // /FRAME
968 dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
972 zr36057_enable_jpg (struct zoran *zr,
973 enum zoran_codec_mode mode)
975 struct vfe_settings cap;
977 zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
978 struct v4l2_routing route = { 0, 0 };
980 zr->codec_mode = mode;
982 cap.x = zr->jpg_settings.img_x;
983 cap.y = zr->jpg_settings.img_y;
984 cap.width = zr->jpg_settings.img_width;
985 cap.height = zr->jpg_settings.img_height;
987 zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
988 cap.quality = zr->jpg_settings.jpg_comp.quality;
992 case BUZ_MODE_MOTION_COMPRESS: {
993 struct jpeg_app_marker app;
994 struct jpeg_com_marker com;
996 /* In motion compress mode, the decoder output must be enabled, and
997 * the video bus direction set to input.
999 set_videobus_dir(zr, 0);
1000 decoder_call(zr, video, s_stream, 1);
1002 encoder_call(zr, video, s_routing, &route);
1004 /* Take the JPEG codec and the VFE out of sleep */
1005 jpeg_codec_sleep(zr, 0);
1007 /* set JPEG app/com marker */
1008 app.appn = zr->jpg_settings.jpg_comp.APPn;
1009 app.len = zr->jpg_settings.jpg_comp.APP_len;
1010 memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
1011 zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
1012 sizeof(struct jpeg_app_marker), &app);
1014 com.len = zr->jpg_settings.jpg_comp.COM_len;
1015 memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
1016 zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
1017 sizeof(struct jpeg_com_marker), &com);
1019 /* Setup the JPEG codec */
1020 zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
1021 sizeof(int), &field_size);
1022 zr->codec->set_video(zr->codec, zr->timing, &cap,
1024 zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
1028 zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
1029 sizeof(int), &field_size);
1030 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1032 zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
1035 init_jpeg_queue(zr);
1036 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1038 clear_interrupt_counters(zr);
1039 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
1044 case BUZ_MODE_MOTION_DECOMPRESS:
1045 /* In motion decompression mode, the decoder output must be disabled, and
1046 * the video bus direction set to output.
1048 decoder_call(zr, video, s_stream, 0);
1049 set_videobus_dir(zr, 1);
1051 encoder_call(zr, video, s_routing, &route);
1053 /* Take the JPEG codec and the VFE out of sleep */
1054 jpeg_codec_sleep(zr, 0);
1057 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1059 zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
1061 /* Setup the JPEG codec */
1062 zr->codec->set_video(zr->codec, zr->timing, &cap,
1064 zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
1066 init_jpeg_queue(zr);
1067 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1069 clear_interrupt_counters(zr);
1070 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
1076 /* shut down processing */
1077 btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
1079 btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
1081 btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
1085 set_videobus_dir(zr, 0);
1086 set_frame(zr, 1); // /FRAME
1087 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); // /CFlush
1088 btwrite(0, ZR36057_JPC); // \P_Reset,\CodTrnsEn,\Active
1089 btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
1090 btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
1091 jpeg_codec_reset(zr);
1092 jpeg_codec_sleep(zr, 1);
1093 zr36057_adjust_vfe(zr, mode);
1095 decoder_call(zr, video, s_stream, 1);
1097 encoder_call(zr, video, s_routing, &route);
1099 dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
1105 /* when this is called the spinlock must be held */
1107 zoran_feed_stat_com (struct zoran *zr)
1109 /* move frames from pending queue to DMA */
1111 int frame, i, max_stat_com;
1114 (zr->jpg_settings.TmpDcm ==
1115 1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
1117 while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
1118 zr->jpg_dma_head < zr->jpg_que_head) {
1120 frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
1121 if (zr->jpg_settings.TmpDcm == 1) {
1122 /* fill 1 stat_com entry */
1123 i = (zr->jpg_dma_head -
1124 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1125 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1128 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1130 /* fill 2 stat_com entries */
1131 i = ((zr->jpg_dma_head -
1132 zr->jpg_err_shift) & 1) * 2;
1133 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1136 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1137 zr->stat_com[i + 1] =
1138 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1140 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
1144 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
1145 zr->jpg_queued_num++;
1148 /* when this is called the spinlock must be held */
1150 zoran_reap_stat_com (struct zoran *zr)
1152 /* move frames from DMA queue to done queue */
1158 struct zoran_jpg_buffer *buffer;
1161 /* In motion decompress we don't have a hardware frame counter,
1162 * we just count the interrupts here */
1164 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1167 while (zr->jpg_dma_tail < zr->jpg_dma_head) {
1168 if (zr->jpg_settings.TmpDcm == 1)
1169 i = (zr->jpg_dma_tail -
1170 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1172 i = ((zr->jpg_dma_tail -
1173 zr->jpg_err_shift) & 1) * 2 + 1;
1175 stat_com = le32_to_cpu(zr->stat_com[i]);
1177 if ((stat_com & 1) == 0) {
1180 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1181 buffer = &zr->jpg_buffers.buffer[frame];
1182 do_gettimeofday(&buffer->bs.timestamp);
1184 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1185 buffer->bs.length = (stat_com & 0x7fffff) >> 1;
1187 /* update sequence number with the help of the counter in stat_com */
1189 seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
1190 dif = (seq - zr->jpg_seq_num) & 0xff;
1191 zr->jpg_seq_num += dif;
1193 buffer->bs.length = 0;
1196 zr->jpg_settings.TmpDcm ==
1197 2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
1198 buffer->state = BUZ_STATE_DONE;
1204 static void zoran_restart(struct zoran *zr)
1206 /* Now the stat_comm buffer is ready for restart */
1207 int status = 0, mode;
1209 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1210 decoder_call(zr, video, g_input_status, &status);
1211 mode = CODEC_DO_COMPRESSION;
1213 status = V4L2_IN_ST_NO_SIGNAL;
1214 mode = CODEC_DO_EXPANSION;
1216 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1217 !(status & V4L2_IN_ST_NO_SIGNAL)) {
1218 /********** RESTART code *************/
1219 jpeg_codec_reset(zr);
1220 zr->codec->set_mode(zr->codec, mode);
1221 zr36057_set_jpg(zr, zr->codec_mode);
1224 if (zr->num_errors <= 8)
1225 dprintk(2, KERN_INFO "%s: Restart\n",
1228 zr->JPEG_missed = 0;
1230 /********** End RESTART code ***********/
1235 error_handler (struct zoran *zr,
1241 /* This is JPEG error handling part */
1242 if (zr->codec_mode != BUZ_MODE_MOTION_COMPRESS &&
1243 zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS) {
1247 if ((stat & 1) == 0 &&
1248 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
1249 zr->jpg_dma_tail - zr->jpg_que_tail >= zr->jpg_buffers.num_buffers) {
1250 /* No free buffers... */
1251 zoran_reap_stat_com(zr);
1252 zoran_feed_stat_com(zr);
1253 wake_up_interruptible(&zr->jpg_capq);
1254 zr->JPEG_missed = 0;
1258 if (zr->JPEG_error == 1) {
1264 * First entry: error just happened during normal operation
1266 * In BUZ_MODE_MOTION_COMPRESS:
1268 * Possible glitch in TV signal. In this case we should
1269 * stop the codec and wait for good quality signal before
1270 * restarting it to avoid further problems
1272 * In BUZ_MODE_MOTION_DECOMPRESS:
1274 * Bad JPEG frame: we have to mark it as processed (codec crashed
1275 * and was not able to do it itself), and to remove it from queue.
1277 btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
1279 stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
1280 btwrite(0, ZR36057_JPC);
1281 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
1282 jpeg_codec_reset(zr);
1283 jpeg_codec_sleep(zr, 1);
1288 if (zr36067_debug > 1 && zr->num_errors <= 8) {
1291 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1293 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1294 ZR_DEVNAME(zr), stat, zr->last_isr,
1295 zr->jpg_que_tail, zr->jpg_dma_tail,
1296 zr->jpg_dma_head, zr->jpg_que_head,
1297 zr->jpg_seq_num, frame);
1298 printk(KERN_INFO "stat_com frames:");
1299 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1300 for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
1301 if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].frag_tab_bus)
1302 printk(KERN_CONT "% d->%d", j, i);
1305 printk(KERN_CONT "\n");
1307 /* Find an entry in stat_com and rotate contents */
1308 if (zr->jpg_settings.TmpDcm == 1)
1309 i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1311 i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2;
1312 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1313 /* Mimic zr36067 operation */
1314 zr->stat_com[i] |= cpu_to_le32(1);
1315 if (zr->jpg_settings.TmpDcm != 1)
1316 zr->stat_com[i + 1] |= cpu_to_le32(1);
1318 zoran_reap_stat_com(zr);
1319 zoran_feed_stat_com(zr);
1320 wake_up_interruptible(&zr->jpg_capq);
1321 /* Find an entry in stat_com again after refill */
1322 if (zr->jpg_settings.TmpDcm == 1)
1323 i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1325 i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2;
1328 /* Rotate stat_comm entries to make current entry first */
1330 __le32 bus_addr[BUZ_NUM_STAT_COM];
1332 /* Here we are copying the stat_com array, which
1333 * is already in little endian format, so
1334 * no endian conversions here
1336 memcpy(bus_addr, zr->stat_com, sizeof(bus_addr));
1338 for (j = 0; j < BUZ_NUM_STAT_COM; j++)
1339 zr->stat_com[j] = bus_addr[(i + j) & BUZ_MASK_STAT_COM];
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; */
1356 unsigned long flags;
1362 /* Testing interrupts */
1363 spin_lock_irqsave(&zr->spinlock, flags);
1364 while ((stat = count_reset_interrupt(zr))) {
1365 if (count++ > 100) {
1366 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1369 "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
1370 ZR_DEVNAME(zr), stat);
1371 wake_up_interruptible(&zr->test_q);
1374 zr->last_isr = stat;
1375 spin_unlock_irqrestore(&zr->spinlock, flags);
1379 spin_lock_irqsave(&zr->spinlock, flags);
1381 /* get/clear interrupt status bits */
1382 stat = count_reset_interrupt(zr);
1383 astat = stat & IRQ_MASK;
1389 "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
1390 astat, btread(ZR36057_ICR));
1391 if (astat & zr->card.vsync_int) { // SW
1393 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1394 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1395 /* count missed interrupts */
1398 //post_office_read(zr,1,0);
1399 /* Interrupts may still happen when
1400 * zr->v4l_memgrab_active is switched off.
1401 * We simply ignore them */
1403 if (zr->v4l_memgrab_active) {
1404 /* A lot more checks should be here ... */
1405 if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot) == 0)
1408 "%s: BuzIRQ with SnapShot off ???\n",
1411 if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
1412 /* There is a grab on a frame going on, check if it has finished */
1413 if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_FrameGrab) == 0) {
1414 /* it is finished, notify the user */
1416 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
1417 zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
1418 do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
1419 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
1420 zr->v4l_pend_tail++;
1424 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
1425 wake_up_interruptible(&zr->v4l_capq);
1427 /* Check if there is another grab queued */
1429 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
1430 zr->v4l_pend_tail != zr->v4l_pend_head) {
1431 int frame = zr->v4l_pend[zr->v4l_pend_tail & V4L_MASK_FRAME];
1434 zr->v4l_grab_frame = frame;
1436 /* Set zr36057 video front end and enable video */
1438 /* Buffer address */
1440 reg = zr->v4l_buffers.buffer[frame].fbuffer_bus;
1441 btwrite(reg, ZR36057_VDTR);
1442 if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2)
1443 reg += zr->v4l_settings.bytesperline;
1444 btwrite(reg, ZR36057_VDBR);
1446 /* video stride, status, and frame grab register */
1448 if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2)
1449 reg += zr->v4l_settings.bytesperline;
1450 reg = (reg << ZR36057_VSSFGR_DispStride);
1451 reg |= ZR36057_VSSFGR_VidOvf;
1452 reg |= ZR36057_VSSFGR_SnapShot;
1453 reg |= ZR36057_VSSFGR_FrameGrab;
1454 btwrite(reg, ZR36057_VSSFGR);
1456 btor(ZR36057_VDCR_VidEn,
1461 /* even if we don't grab, we do want to increment
1462 * the sequence counter to see lost frames */
1465 #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1466 if (astat & ZR36057_ISR_CodRepIRQ) {
1467 zr->intr_counter_CodRepIRQ++;
1468 IDEBUG(printk(KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
1470 btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
1472 #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
1474 #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1475 if ((astat & ZR36057_ISR_JPEGRepIRQ) &&
1476 (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1477 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)) {
1478 if (zr36067_debug > 1 && (!zr->frame_num || zr->JPEG_error)) {
1484 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1485 ZR_DEVNAME(zr), stat,
1486 zr->jpg_settings.odd_even,
1487 zr->jpg_settings.field_per_buff,
1491 for (i = 0; i < 4; i++) {
1492 if (le32_to_cpu(zr->stat_com[i]) & 1)
1497 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1504 /* Get statistics */
1505 if (zr->JPEG_missed > zr->JPEG_max_missed)
1506 zr->JPEG_max_missed = zr->JPEG_missed;
1507 if (zr->JPEG_missed < zr->JPEG_min_missed)
1508 zr->JPEG_min_missed = zr->JPEG_missed;
1511 if (zr36067_debug > 2 && zr->frame_num < 6) {
1514 printk(KERN_INFO "%s: seq=%ld stat_com:",
1515 ZR_DEVNAME(zr), zr->jpg_seq_num);
1516 for (i = 0; i < 4; i++) {
1517 printk(KERN_CONT " %08x",
1518 le32_to_cpu(zr->stat_com[i]));
1520 printk(KERN_CONT "\n");
1523 zr->JPEG_missed = 0;
1525 zoran_reap_stat_com(zr);
1526 zoran_feed_stat_com(zr);
1527 wake_up_interruptible(&zr->jpg_capq);
1529 #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
1531 /* DATERR, too many fields missed, error processing */
1532 if ((astat & zr->card.jpeg_int) ||
1533 zr->JPEG_missed > 25 ||
1534 zr->JPEG_error == 1 ||
1535 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
1536 (zr->frame_num & (zr->JPEG_missed > zr->jpg_settings.field_per_buff)))) {
1537 error_handler(zr, astat, stat);
1542 dprintk(2, KERN_WARNING "%s: irq loop %d\n",
1543 ZR_DEVNAME(zr), count);
1545 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1548 "%s: IRQ lockup, cleared int mask\n",
1553 zr->last_isr = stat;
1555 spin_unlock_irqrestore(&zr->spinlock, flags);
1561 zoran_set_pci_master (struct zoran *zr,
1565 pci_set_master(zr->pci_dev);
1569 pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
1570 command &= ~PCI_COMMAND_MASTER;
1571 pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
1576 zoran_init_hardware (struct zoran *zr)
1578 struct v4l2_routing route = { 0, 0 };
1580 /* Enable bus-mastering */
1581 zoran_set_pci_master(zr, 1);
1583 /* Initialize the board */
1584 if (zr->card.init) {
1588 route.input = zr->card.input[zr->input].muxsel;
1590 decoder_call(zr, core, init, 0);
1591 decoder_s_std(zr, zr->norm);
1592 decoder_s_routing(zr, &route);
1594 encoder_call(zr, core, init, 0);
1595 encoder_call(zr, video, s_std_output, zr->norm);
1597 encoder_call(zr, video, s_routing, &route);
1599 /* toggle JPEG codec sleep to sync PLL */
1600 jpeg_codec_sleep(zr, 1);
1601 jpeg_codec_sleep(zr, 0);
1603 /* set individual interrupt enables (without GIRQ1)
1604 * but don't global enable until zoran_open() */
1606 //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW
1607 // It looks like using only JPEGRepIRQEn is not always reliable,
1608 // may be when JPEG codec crashes it won't generate IRQ? So,
1609 /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
1610 zr36057_init_vfe(zr);
1612 zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
1614 btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
1618 zr36057_restart (struct zoran *zr)
1620 btwrite(0, ZR36057_SPGPPCR);
1622 btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
1625 /* assert P_Reset */
1626 btwrite(0, ZR36057_JPC);
1627 /* set up GPIO direction - all output */
1628 btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
1630 /* set up GPIO pins and guest bus timing */
1631 btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
1635 * initialize video front end
1639 zr36057_init_vfe (struct zoran *zr)
1643 reg = btread(ZR36057_VFESPFR);
1644 reg |= ZR36057_VFESPFR_LittleEndian;
1645 reg &= ~ZR36057_VFESPFR_VCLKPol;
1646 reg |= ZR36057_VFESPFR_ExtFl;
1647 reg |= ZR36057_VFESPFR_TopField;
1648 btwrite(reg, ZR36057_VFESPFR);
1649 reg = btread(ZR36057_VDCR);
1650 if (pci_pci_problems & PCIPCI_TRITON)
1651 // || zr->revision < 1) // Revision 1 has also Triton support
1652 reg &= ~ZR36057_VDCR_Triton;
1654 reg |= ZR36057_VDCR_Triton;
1655 btwrite(reg, ZR36057_VDCR);
1659 * Interface to decoder and encoder chips using i2c bus
1662 int decoder_s_std(struct zoran *zr, v4l2_std_id std)
1666 /* Bt819 needs to reset its FIFO buffer using #FRST pin and
1667 LML33 card uses GPIO(7) for that. */
1668 if (zr->card.type == LML33)
1670 res = decoder_call(zr, tuner, s_std, std);
1671 if (zr->card.type == LML33)
1672 GPIO(zr, 7, 1); /* Pull #FRST high. */
1676 int decoder_s_routing(struct zoran *zr, struct v4l2_routing *route)
1680 /* Bt819 needs to reset its FIFO buffer using #FRST pin and
1681 LML33 card uses GPIO(7) for that. */
1682 if (zr->card.type == LML33)
1684 res = decoder_call(zr, video, s_routing, route);
1685 if (zr->card.type == LML33)
1686 GPIO(zr, 7, 1); /* Pull #FRST high. */