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; /* default = 0
64 * 1 will use digital path in capture
65 * mode instead of analog. It can be
66 * used for picture adjustments using
67 * tool like xawtv while watching image
68 * on TV monitor connected to the output.
69 * However, due to absence of 75 Ohm
70 * load on Bt819 input, there will be
71 * some image imperfections */
73 module_param(lml33dpath, bool, 0644);
74 MODULE_PARM_DESC(lml33dpath,
75 "Use digital path capture mode (on LML33 cards)");
78 zr36057_init_vfe (struct zoran *zr);
81 * General Purpose I/O and Guest bus access
85 * This is a bit tricky. When a board lacks a GPIO function, the corresponding
86 * GPIO bit number in the card_info structure is set to 0.
90 GPIO (struct zoran *zr,
97 /* Make sure the bit number is legal
98 * A bit number of -1 (lacking) gives a mask of 0,
99 * making it harmless */
100 mask = (1 << (24 + bit)) & 0xff000000;
101 reg = btread(ZR36057_GPPGCR1) & ~mask;
105 btwrite(reg, ZR36057_GPPGCR1);
110 * Wait til post office is no longer busy
114 post_office_wait (struct zoran *zr)
118 // while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
119 while ((por = btread(ZR36057_POR)) & ZR36057_POR_POPen) {
120 /* wait for something to happen */
122 if ((por & ZR36057_POR_POTime) && !zr->card.gws_not_connected) {
123 /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
124 dprintk(1, KERN_INFO "%s: pop timeout %08x\n", ZR_DEVNAME(zr),
133 post_office_write (struct zoran *zr,
141 ZR36057_POR_PODir | ZR36057_POR_POTime | ((guest & 7) << 20) |
142 ((reg & 7) << 16) | (value & 0xFF);
143 btwrite(por, ZR36057_POR);
145 return post_office_wait(zr);
149 post_office_read (struct zoran *zr,
155 por = ZR36057_POR_POTime | ((guest & 7) << 20) | ((reg & 7) << 16);
156 btwrite(por, ZR36057_POR);
157 if (post_office_wait(zr) < 0) {
161 return btread(ZR36057_POR) & 0xFF;
169 dump_guests (struct zoran *zr)
171 if (zr36067_debug > 2) {
174 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
175 guest[i] = post_office_read(zr, i, 0);
178 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
180 for (i = 1; i < 8; i++) {
181 printk(" 0x%02x", guest[i]);
187 static inline unsigned long
192 do_gettimeofday(&tv);
193 return (1000000 * tv.tv_sec + tv.tv_usec);
197 detect_guest_activity (struct zoran *zr)
199 int timeout, i, j, res, guest[8], guest0[8], change[8][3];
200 unsigned long t0, t1;
203 printk(KERN_INFO "%s: Detecting guests activity, please wait...\n",
205 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
206 guest0[i] = guest[i] = post_office_read(zr, i, 0);
212 while (timeout < 10000) {
215 for (i = 1; (i < 8) && (j < 8); i++) {
216 res = post_office_read(zr, i, 0);
217 if (res != guest[i]) {
219 change[j][0] = (t1 - t0);
230 printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
232 for (i = 1; i < 8; i++) {
233 printk(" 0x%02x", guest0[i]);
237 printk(KERN_INFO "%s: No activity detected.\n", ZR_DEVNAME(zr));
240 for (i = 0; i < j; i++) {
241 printk(KERN_INFO "%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr),
242 change[i][0], change[i][1], change[i][2]);
251 jpeg_codec_sleep (struct zoran *zr,
254 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_SLEEP], !sleep);
258 "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
259 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
264 "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
265 ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
271 jpeg_codec_reset (struct zoran *zr)
273 /* Take the codec out of sleep */
274 jpeg_codec_sleep(zr, 0);
276 if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) {
277 post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0,
281 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 0);
283 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 1);
291 * Set the registers for the size we have specified. Don't bother
292 * trying to understand this without the ZR36057 manual in front of
295 * PS: The manual is free for download in .pdf format from
296 * www.zoran.com - nicely done those folks.
300 zr36057_adjust_vfe (struct zoran *zr,
301 enum zoran_codec_mode mode)
306 case BUZ_MODE_MOTION_DECOMPRESS:
307 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
308 reg = btread(ZR36057_VFEHCR);
309 if ((reg & (1 << 10)) && zr->card.type != LML33R10) {
310 reg += ((1 << 10) | 1);
312 btwrite(reg, ZR36057_VFEHCR);
314 case BUZ_MODE_MOTION_COMPRESS:
317 if (zr->norm == VIDEO_MODE_NTSC ||
318 (zr->card.type == LML33R10 &&
319 zr->norm == VIDEO_MODE_PAL))
320 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
322 btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
323 reg = btread(ZR36057_VFEHCR);
324 if (!(reg & (1 << 10)) && zr->card.type != LML33R10) {
325 reg -= ((1 << 10) | 1);
327 btwrite(reg, ZR36057_VFEHCR);
337 zr36057_set_vfe (struct zoran *zr,
340 const struct zoran_format *format)
343 unsigned HStart, HEnd, VStart, VEnd;
345 unsigned VidWinWid, VidWinHt;
346 unsigned hcrop1, hcrop2, vcrop1, vcrop2;
347 unsigned Wa, We, Ha, He;
348 unsigned X, Y, HorDcm, VerDcm;
350 unsigned mask_line_size;
357 dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
358 ZR_DEVNAME(zr), video_width, video_height);
360 if (zr->norm != VIDEO_MODE_PAL &&
361 zr->norm != VIDEO_MODE_NTSC &&
362 zr->norm != VIDEO_MODE_SECAM) {
364 KERN_ERR "%s: set_vfe() - norm = %d not valid\n",
365 ZR_DEVNAME(zr), zr->norm);
368 if (video_width < BUZ_MIN_WIDTH ||
369 video_height < BUZ_MIN_HEIGHT ||
370 video_width > Wa || video_height > Ha) {
371 dprintk(1, KERN_ERR "%s: set_vfe: w=%d h=%d not valid\n",
372 ZR_DEVNAME(zr), video_width, video_height);
379 VidWinWid = video_width;
380 X = (VidWinWid * 64 + tvn->Wa - 1) / tvn->Wa;
381 We = (VidWinWid * 64) / X;
383 hcrop1 = 2 * ((tvn->Wa - We) / 4);
384 hcrop2 = tvn->Wa - We - hcrop1;
385 HStart = tvn->HStart ? tvn->HStart : 1;
386 /* (Ronald) Original comment:
387 * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
388 * this is false. It inverses chroma values on the LML33R10 (so Cr
389 * suddenly is shown as Cb and reverse, really cool effect if you
390 * want to see blue faces, not useful otherwise). So don't use |1.
391 * However, the DC10 has '0' as HStart, but does need |1, so we
392 * use a dirty check...
394 HEnd = HStart + tvn->Wa - 1;
397 reg = ((HStart & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HStart)
398 | ((HEnd & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HEnd);
399 if (zr->card.vfe_pol.hsync_pol)
400 reg |= ZR36057_VFEHCR_HSPol;
401 btwrite(reg, ZR36057_VFEHCR);
404 DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
405 VidWinHt = DispMode ? video_height : video_height / 2;
406 Y = (VidWinHt * 64 * 2 + tvn->Ha - 1) / tvn->Ha;
407 He = (VidWinHt * 64) / Y;
409 vcrop1 = (tvn->Ha / 2 - He) / 2;
410 vcrop2 = tvn->Ha / 2 - He - vcrop1;
411 VStart = tvn->VStart;
412 VEnd = VStart + tvn->Ha / 2; // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
415 reg = ((VStart & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VStart)
416 | ((VEnd & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VEnd);
417 if (zr->card.vfe_pol.vsync_pol)
418 reg |= ZR36057_VFEVCR_VSPol;
419 btwrite(reg, ZR36057_VFEVCR);
421 /* scaler and pixel format */
423 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
424 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
425 reg |= (DispMode << ZR36057_VFESPFR_DispMode);
426 /* RJ: I don't know, why the following has to be the opposite
427 * of the corresponding ZR36060 setting, but only this way
428 * we get the correct colors when uncompressing to the screen */
429 //reg |= ZR36057_VFESPFR_VCLKPol; /**/
430 /* RJ: Don't know if that is needed for NTSC also */
431 if (zr->norm != VIDEO_MODE_NTSC)
432 reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang
433 reg |= ZR36057_VFESPFR_TopField;
435 reg |= 3 << ZR36057_VFESPFR_HFilter; /* 5 tap filter */
436 } else if (HorDcm >= 32) {
437 reg |= 2 << ZR36057_VFESPFR_HFilter; /* 4 tap filter */
438 } else if (HorDcm >= 16) {
439 reg |= 1 << ZR36057_VFESPFR_HFilter; /* 3 tap filter */
441 reg |= format->vfespfr;
442 btwrite(reg, ZR36057_VFESPFR);
444 /* display configuration */
445 reg = (16 << ZR36057_VDCR_MinPix)
446 | (VidWinHt << ZR36057_VDCR_VidWinHt)
447 | (VidWinWid << ZR36057_VDCR_VidWinWid);
448 if (pci_pci_problems & PCIPCI_TRITON)
449 // || zr->revision < 1) // Revision 1 has also Triton support
450 reg &= ~ZR36057_VDCR_Triton;
452 reg |= ZR36057_VDCR_Triton;
453 btwrite(reg, ZR36057_VDCR);
455 /* (Ronald) don't write this if overlay_mask = NULL */
456 if (zr->overlay_mask) {
457 /* Write overlay clipping mask data, but don't enable overlay clipping */
458 /* RJ: since this makes only sense on the screen, we use
459 * zr->overlay_settings.width instead of video_width */
461 mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
462 reg = virt_to_bus(zr->overlay_mask);
463 btwrite(reg, ZR36057_MMTR);
464 reg = virt_to_bus(zr->overlay_mask + mask_line_size);
465 btwrite(reg, ZR36057_MMBR);
467 mask_line_size - (zr->overlay_settings.width +
470 reg += mask_line_size;
471 reg <<= ZR36057_OCR_MaskStride;
472 btwrite(reg, ZR36057_OCR);
475 zr36057_adjust_vfe(zr, zr->codec_mode);
479 * Switch overlay on or off
483 zr36057_overlay (struct zoran *zr,
489 /* do the necessary settings ... */
490 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR); /* switch it off first */
493 zr->overlay_settings.width,
494 zr->overlay_settings.height,
495 zr->overlay_settings.format);
497 /* Start and length of each line MUST be 4-byte aligned.
498 * This should be allready checked before the call to this routine.
499 * All error messages are internal driver checking only! */
501 /* video display top and bottom registers */
502 reg = (long) zr->buffer.base +
503 zr->overlay_settings.x *
504 ((zr->overlay_settings.format->depth + 7) / 8) +
505 zr->overlay_settings.y *
506 zr->buffer.bytesperline;
507 btwrite(reg, ZR36057_VDTR);
511 "%s: zr36057_overlay() - video_address not aligned\n",
513 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
514 reg += zr->buffer.bytesperline;
515 btwrite(reg, ZR36057_VDBR);
517 /* video stride, status, and frame grab register */
518 reg = zr->buffer.bytesperline -
519 zr->overlay_settings.width *
520 ((zr->overlay_settings.format->depth + 7) / 8);
521 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
522 reg += zr->buffer.bytesperline;
526 "%s: zr36057_overlay() - video_stride not aligned\n",
528 reg = (reg << ZR36057_VSSFGR_DispStride);
529 reg |= ZR36057_VSSFGR_VidOvf; /* clear overflow status */
530 btwrite(reg, ZR36057_VSSFGR);
532 /* Set overlay clipping */
533 if (zr->overlay_settings.clipcount > 0)
534 btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
536 /* ... and switch it on */
537 btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
540 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
545 * The overlay mask has one bit for each pixel on a scan line,
546 * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
550 write_overlay_mask (struct file *file,
551 struct video_clip *vp,
554 struct zoran_fh *fh = file->private_data;
555 struct zoran *zr = fh->zr;
556 unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
558 int x, y, width, height;
562 /* fill mask with one bits */
563 memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
566 for (i = 0; i < count; ++i) {
567 /* pick up local copy of clip */
571 height = vp[i].height;
573 /* trim clips that extend beyond the window */
582 if (x + width > fh->overlay_settings.width) {
583 width = fh->overlay_settings.width - x;
585 if (y + height > fh->overlay_settings.height) {
586 height = fh->overlay_settings.height - y;
589 /* ignore degenerate clips */
597 /* apply clip for each scan line */
598 for (j = 0; j < height; ++j) {
599 /* reset bit for each pixel */
600 /* this can be optimized later if need be */
601 mask = fh->overlay_mask + (y + j) * mask_line_size;
602 for (k = 0; k < width; ++k) {
603 mask[(x + k) / 32] &=
604 ~((u32) 1 << (x + k) % 32);
610 /* Enable/Disable uncompressed memory grabbing of the 36057 */
613 zr36057_set_memgrab (struct zoran *zr,
617 /* We only check SnapShot and not FrameGrab here. SnapShot==1
618 * means a capture is already in progress, but FrameGrab==1
619 * doesn't necessary mean that. It's more correct to say a 1
620 * to 0 transition indicates a capture completed. If a
621 * capture is pending when capturing is tuned off, FrameGrab
622 * will be stuck at 1 until capturing is turned back on.
624 if (btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot)
627 "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
630 /* switch on VSync interrupts */
631 btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
632 btor(zr->card.vsync_int, ZR36057_ICR); // SW
634 /* enable SnapShot */
635 btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
637 /* Set zr36057 video front end and enable video */
638 zr36057_set_vfe(zr, zr->v4l_settings.width,
639 zr->v4l_settings.height,
640 zr->v4l_settings.format);
642 zr->v4l_memgrab_active = 1;
644 /* switch off VSync interrupts */
645 btand(~zr->card.vsync_int, ZR36057_ICR); // SW
647 zr->v4l_memgrab_active = 0;
648 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
650 /* reenable grabbing to screen if it was running */
651 if (zr->v4l_overlay_active) {
652 zr36057_overlay(zr, 1);
654 btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
655 btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
661 wait_grab_pending (struct zoran *zr)
665 /* wait until all pending grabs are finished */
667 if (!zr->v4l_memgrab_active)
670 wait_event_interruptible(zr->v4l_capq,
671 (zr->v4l_pend_tail == zr->v4l_pend_head));
672 if (signal_pending(current))
675 spin_lock_irqsave(&zr->spinlock, flags);
676 zr36057_set_memgrab(zr, 0);
677 spin_unlock_irqrestore(&zr->spinlock, flags);
682 /*****************************************************************************
684 * Set up the Buz-specific MJPEG part *
686 *****************************************************************************/
689 set_frame (struct zoran *zr,
692 GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_FRAME], val);
696 set_videobus_dir (struct zoran *zr,
699 switch (zr->card.type) {
708 GPIO(zr, zr->card.gpio[ZR_GPIO_VID_DIR],
709 zr->card.gpio_pol[ZR_GPIO_VID_DIR] ? !val : val);
715 init_jpeg_queue (struct zoran *zr)
719 /* re-initialize DMA ring stuff */
720 zr->jpg_que_head = 0;
721 zr->jpg_dma_head = 0;
722 zr->jpg_dma_tail = 0;
723 zr->jpg_que_tail = 0;
728 zr->jpg_err_shift = 0;
729 zr->jpg_queued_num = 0;
730 for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
731 zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
733 for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
734 zr->stat_com[i] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
739 zr36057_set_jpg (struct zoran *zr,
740 enum zoran_codec_mode mode)
747 /* assert P_Reset, disable code transfer, deassert Active */
748 btwrite(0, ZR36057_JPC);
750 /* MJPEG compression mode */
753 case BUZ_MODE_MOTION_COMPRESS:
755 reg = ZR36057_JMC_MJPGCmpMode;
758 case BUZ_MODE_MOTION_DECOMPRESS:
759 reg = ZR36057_JMC_MJPGExpMode;
760 reg |= ZR36057_JMC_SyncMstr;
761 /* RJ: The following is experimental - improves the output to screen */
762 //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
765 case BUZ_MODE_STILL_COMPRESS:
766 reg = ZR36057_JMC_JPGCmpMode;
769 case BUZ_MODE_STILL_DECOMPRESS:
770 reg = ZR36057_JMC_JPGExpMode;
774 reg |= ZR36057_JMC_JPG;
775 if (zr->jpg_settings.field_per_buff == 1)
776 reg |= ZR36057_JMC_Fld_per_buff;
777 btwrite(reg, ZR36057_JMC);
780 btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
781 reg = (6 << ZR36057_VSP_VsyncSize) |
782 (tvn->Ht << ZR36057_VSP_FrmTot);
783 btwrite(reg, ZR36057_VSP);
784 reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
785 (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
786 btwrite(reg, ZR36057_FVAP);
789 if (zr->card.vfe_pol.hsync_pol)
790 btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
792 btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
793 reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
794 (tvn->Wt << ZR36057_HSP_LineTot);
795 btwrite(reg, ZR36057_HSP);
796 reg = ((zr->jpg_settings.img_x +
797 tvn->HStart + 4) << ZR36057_FHAP_NAX) |
798 (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
799 btwrite(reg, ZR36057_FHAP);
801 /* field process parameters */
802 if (zr->jpg_settings.odd_even)
803 reg = ZR36057_FPP_Odd_Even;
807 btwrite(reg, ZR36057_FPP);
809 /* Set proper VCLK Polarity, else colors will be wrong during playback */
810 //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
812 /* code base address */
813 reg = virt_to_bus(zr->stat_com);
814 btwrite(reg, ZR36057_JCBA);
816 /* FIFO threshold (FIFO is 160. double words) */
817 /* NOTE: decimal values here */
820 case BUZ_MODE_STILL_COMPRESS:
821 case BUZ_MODE_MOTION_COMPRESS:
822 if (zr->card.type != BUZ)
828 case BUZ_MODE_STILL_DECOMPRESS:
829 case BUZ_MODE_MOTION_DECOMPRESS:
838 btwrite(reg, ZR36057_JCFT);
839 zr36057_adjust_vfe(zr, mode);
844 print_interrupts (struct zoran *zr)
848 printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
849 if ((res = zr->field_counter) < -1 || res > 1) {
850 printk(" FD:%d", res);
852 if ((res = zr->intr_counter_GIRQ1) != 0) {
853 printk(" GIRQ1:%d", res);
856 if ((res = zr->intr_counter_GIRQ0) != 0) {
857 printk(" GIRQ0:%d", res);
860 if ((res = zr->intr_counter_CodRepIRQ) != 0) {
861 printk(" CodRepIRQ:%d", res);
864 if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
865 printk(" JPEGRepIRQ:%d", res);
868 if (zr->JPEG_max_missed) {
869 printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
870 zr->JPEG_min_missed);
872 if (zr->END_event_missed) {
873 printk(" ENDs missed: %d", zr->END_event_missed);
875 //if (zr->jpg_queued_num) {
876 printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
877 zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
880 printk(": no interrupts detected.");
886 clear_interrupt_counters (struct zoran *zr)
888 zr->intr_counter_GIRQ1 = 0;
889 zr->intr_counter_GIRQ0 = 0;
890 zr->intr_counter_CodRepIRQ = 0;
891 zr->intr_counter_JPEGRepIRQ = 0;
892 zr->field_counter = 0;
899 zr->END_event_missed = 0;
901 zr->JPEG_max_missed = 0;
902 zr->JPEG_min_missed = 0x7fffffff;
906 count_reset_interrupt (struct zoran *zr)
910 if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
911 if (isr & ZR36057_ISR_GIRQ1) {
912 btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
913 zr->intr_counter_GIRQ1++;
915 if (isr & ZR36057_ISR_GIRQ0) {
916 btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
917 zr->intr_counter_GIRQ0++;
919 if (isr & ZR36057_ISR_CodRepIRQ) {
920 btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
921 zr->intr_counter_CodRepIRQ++;
923 if (isr & ZR36057_ISR_JPEGRepIRQ) {
924 btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
925 zr->intr_counter_JPEGRepIRQ++;
932 extern void zr36016_write (struct videocodec *codec,
937 jpeg_start (struct zoran *zr)
943 /* deassert P_reset, disable code transfer, deassert Active */
944 btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
945 /* stop flushing the internal code buffer */
946 btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
947 /* enable code transfer */
948 btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
951 btwrite(IRQ_MASK, ZR36057_ISR);
952 /* enable the JPEG IRQs */
953 btwrite(zr->card.jpeg_int |
954 ZR36057_ICR_JPEGRepIRQ |
955 ZR36057_ICR_IntPinEn,
958 set_frame(zr, 0); // \FRAME
960 /* set the JPEG codec guest ID */
961 reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
962 (0 << ZR36057_JCGI_JPEGuestReg);
963 btwrite(reg, ZR36057_JCGI);
965 if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
966 zr->card.video_codec == CODEC_TYPE_ZR36050) {
967 /* Enable processing on the ZR36016 */
969 zr36016_write(zr->vfe, 0, 1);
971 /* load the address of the GO register in the ZR36050 latch */
972 post_office_write(zr, 0, 0, 0);
976 btor(ZR36057_JPC_Active, ZR36057_JPC);
978 /* enable the Go generation */
979 btor(ZR36057_JMC_Go_en, ZR36057_JMC);
982 set_frame(zr, 1); // /FRAME
984 dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
988 zr36057_enable_jpg (struct zoran *zr,
989 enum zoran_codec_mode mode)
993 struct vfe_settings cap;
995 zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
997 zr->codec_mode = mode;
999 cap.x = zr->jpg_settings.img_x;
1000 cap.y = zr->jpg_settings.img_y;
1001 cap.width = zr->jpg_settings.img_width;
1002 cap.height = zr->jpg_settings.img_height;
1004 zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
1005 cap.quality = zr->jpg_settings.jpg_comp.quality;
1009 case BUZ_MODE_MOTION_COMPRESS: {
1010 struct jpeg_app_marker app;
1011 struct jpeg_com_marker com;
1013 /* In motion compress mode, the decoder output must be enabled, and
1014 * the video bus direction set to input.
1016 set_videobus_dir(zr, 0);
1017 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
1018 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1020 /* Take the JPEG codec and the VFE out of sleep */
1021 jpeg_codec_sleep(zr, 0);
1023 /* set JPEG app/com marker */
1024 app.appn = zr->jpg_settings.jpg_comp.APPn;
1025 app.len = zr->jpg_settings.jpg_comp.APP_len;
1026 memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
1027 zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
1028 sizeof(struct jpeg_app_marker), &app);
1030 com.len = zr->jpg_settings.jpg_comp.COM_len;
1031 memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
1032 zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
1033 sizeof(struct jpeg_com_marker), &com);
1035 /* Setup the JPEG codec */
1036 zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
1037 sizeof(int), &field_size);
1038 zr->codec->set_video(zr->codec, zr->timing, &cap,
1040 zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
1044 zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
1045 sizeof(int), &field_size);
1046 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1048 zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
1051 init_jpeg_queue(zr);
1052 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1054 clear_interrupt_counters(zr);
1055 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
1060 case BUZ_MODE_MOTION_DECOMPRESS:
1061 /* In motion decompression mode, the decoder output must be disabled, and
1062 * the video bus direction set to output.
1064 decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
1065 set_videobus_dir(zr, 1);
1066 encoder_command(zr, ENCODER_SET_INPUT, &one);
1068 /* Take the JPEG codec and the VFE out of sleep */
1069 jpeg_codec_sleep(zr, 0);
1072 zr->vfe->set_video(zr->vfe, zr->timing, &cap,
1074 zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
1076 /* Setup the JPEG codec */
1077 zr->codec->set_video(zr->codec, zr->timing, &cap,
1079 zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
1081 init_jpeg_queue(zr);
1082 zr36057_set_jpg(zr, mode); // \P_Reset, ... Video param, FIFO
1084 clear_interrupt_counters(zr);
1085 dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
1091 /* shut down processing */
1092 btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
1094 btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
1096 btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
1100 set_videobus_dir(zr, 0);
1101 set_frame(zr, 1); // /FRAME
1102 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); // /CFlush
1103 btwrite(0, ZR36057_JPC); // \P_Reset,\CodTrnsEn,\Active
1104 btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
1105 btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
1106 jpeg_codec_reset(zr);
1107 jpeg_codec_sleep(zr, 1);
1108 zr36057_adjust_vfe(zr, mode);
1110 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
1111 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1113 dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
1119 /* when this is called the spinlock must be held */
1121 zoran_feed_stat_com (struct zoran *zr)
1123 /* move frames from pending queue to DMA */
1125 int frame, i, max_stat_com;
1128 (zr->jpg_settings.TmpDcm ==
1129 1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
1131 while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
1132 zr->jpg_dma_head < zr->jpg_que_head) {
1134 frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
1135 if (zr->jpg_settings.TmpDcm == 1) {
1136 /* fill 1 stat_com entry */
1137 i = (zr->jpg_dma_head -
1138 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1139 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1142 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1144 /* fill 2 stat_com entries */
1145 i = ((zr->jpg_dma_head -
1146 zr->jpg_err_shift) & 1) * 2;
1147 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1150 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1151 zr->stat_com[i + 1] =
1152 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
1154 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
1158 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
1159 zr->jpg_queued_num++;
1162 /* when this is called the spinlock must be held */
1164 zoran_reap_stat_com (struct zoran *zr)
1166 /* move frames from DMA queue to done queue */
1172 struct zoran_jpg_buffer *buffer;
1175 /* In motion decompress we don't have a hardware frame counter,
1176 * we just count the interrupts here */
1178 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1181 while (zr->jpg_dma_tail < zr->jpg_dma_head) {
1182 if (zr->jpg_settings.TmpDcm == 1)
1183 i = (zr->jpg_dma_tail -
1184 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1186 i = ((zr->jpg_dma_tail -
1187 zr->jpg_err_shift) & 1) * 2 + 1;
1189 stat_com = le32_to_cpu(zr->stat_com[i]);
1191 if ((stat_com & 1) == 0) {
1194 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1195 buffer = &zr->jpg_buffers.buffer[frame];
1196 do_gettimeofday(&buffer->bs.timestamp);
1198 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1199 buffer->bs.length = (stat_com & 0x7fffff) >> 1;
1201 /* update sequence number with the help of the counter in stat_com */
1203 seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
1204 dif = (seq - zr->jpg_seq_num) & 0xff;
1205 zr->jpg_seq_num += dif;
1207 buffer->bs.length = 0;
1210 zr->jpg_settings.TmpDcm ==
1211 2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
1212 buffer->state = BUZ_STATE_DONE;
1219 error_handler (struct zoran *zr,
1223 /* This is JPEG error handling part */
1224 if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) &&
1225 (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) {
1226 //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
1230 if ((stat & 1) == 0 &&
1231 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
1232 zr->jpg_dma_tail - zr->jpg_que_tail >=
1233 zr->jpg_buffers.num_buffers) {
1234 /* No free buffers... */
1235 zoran_reap_stat_com(zr);
1236 zoran_feed_stat_com(zr);
1237 wake_up_interruptible(&zr->jpg_capq);
1238 zr->JPEG_missed = 0;
1242 if (zr->JPEG_error != 1) {
1244 * First entry: error just happened during normal operation
1246 * In BUZ_MODE_MOTION_COMPRESS:
1248 * Possible glitch in TV signal. In this case we should
1249 * stop the codec and wait for good quality signal before
1250 * restarting it to avoid further problems
1252 * In BUZ_MODE_MOTION_DECOMPRESS:
1254 * Bad JPEG frame: we have to mark it as processed (codec crashed
1255 * and was not able to do it itself), and to remove it from queue.
1257 btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
1259 stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
1260 btwrite(0, ZR36057_JPC);
1261 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
1262 jpeg_codec_reset(zr);
1263 jpeg_codec_sleep(zr, 1);
1268 if (zr36067_debug > 1 && zr->num_errors <= 8) {
1271 zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1273 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1274 ZR_DEVNAME(zr), stat, zr->last_isr,
1275 zr->jpg_que_tail, zr->jpg_dma_tail,
1276 zr->jpg_dma_head, zr->jpg_que_head,
1277 zr->jpg_seq_num, frame);
1278 printk("stat_com frames:");
1281 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1283 i < zr->jpg_buffers.num_buffers;
1285 if (le32_to_cpu(zr->stat_com[j]) ==
1297 /* Find an entry in stat_com and rotate contents */
1301 if (zr->jpg_settings.TmpDcm == 1)
1302 i = (zr->jpg_dma_tail -
1303 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1305 i = ((zr->jpg_dma_tail -
1306 zr->jpg_err_shift) & 1) * 2;
1307 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1308 /* Mimic zr36067 operation */
1309 zr->stat_com[i] |= cpu_to_le32(1);
1310 if (zr->jpg_settings.TmpDcm != 1)
1311 zr->stat_com[i + 1] |= cpu_to_le32(1);
1313 zoran_reap_stat_com(zr);
1314 zoran_feed_stat_com(zr);
1315 wake_up_interruptible(&zr->jpg_capq);
1316 /* Find an entry in stat_com again after refill */
1317 if (zr->jpg_settings.TmpDcm == 1)
1318 i = (zr->jpg_dma_tail -
1319 zr->jpg_err_shift) &
1322 i = ((zr->jpg_dma_tail -
1323 zr->jpg_err_shift) & 1) * 2;
1326 /* Rotate stat_comm entries to make current entry first */
1328 u32 bus_addr[BUZ_NUM_STAT_COM];
1330 /* Here we are copying the stat_com array, which
1331 * is already in little endian format, so
1332 * no endian conversions here
1334 memcpy(bus_addr, zr->stat_com,
1336 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1342 zr->jpg_err_shift += i;
1343 zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
1345 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
1346 zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
1350 /* Now the stat_comm buffer is ready for restart */
1354 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1355 decoder_command(zr, DECODER_GET_STATUS, &status);
1356 mode = CODEC_DO_COMPRESSION;
1359 mode = CODEC_DO_EXPANSION;
1361 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1362 (status & DECODER_STATUS_GOOD)) {
1363 /********** RESTART code *************/
1364 jpeg_codec_reset(zr);
1365 zr->codec->set_mode(zr->codec, mode);
1366 zr36057_set_jpg(zr, zr->codec_mode);
1369 if (zr->num_errors <= 8)
1370 dprintk(2, KERN_INFO "%s: Restart\n",
1373 zr->JPEG_missed = 0;
1375 /********** End RESTART code ***********/
1387 unsigned long flags;
1393 /* Testing interrupts */
1394 spin_lock_irqsave(&zr->spinlock, flags);
1395 while ((stat = count_reset_interrupt(zr))) {
1396 if (count++ > 100) {
1397 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1400 "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
1401 ZR_DEVNAME(zr), stat);
1402 wake_up_interruptible(&zr->test_q);
1405 zr->last_isr = stat;
1406 spin_unlock_irqrestore(&zr->spinlock, flags);
1410 spin_lock_irqsave(&zr->spinlock, flags);
1412 /* get/clear interrupt status bits */
1413 stat = count_reset_interrupt(zr);
1414 astat = stat & IRQ_MASK;
1420 "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
1421 astat, btread(ZR36057_ICR));
1422 if (astat & zr->card.vsync_int) { // SW
1424 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1425 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1426 /* count missed interrupts */
1429 //post_office_read(zr,1,0);
1430 /* Interrupts may still happen when
1431 * zr->v4l_memgrab_active is switched off.
1432 * We simply ignore them */
1434 if (zr->v4l_memgrab_active) {
1436 /* A lot more checks should be here ... */
1437 if ((btread(ZR36057_VSSFGR) &
1438 ZR36057_VSSFGR_SnapShot) == 0)
1441 "%s: BuzIRQ with SnapShot off ???\n",
1444 if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
1445 /* There is a grab on a frame going on, check if it has finished */
1447 if ((btread(ZR36057_VSSFGR) &
1448 ZR36057_VSSFGR_FrameGrab) ==
1450 /* it is finished, notify the user */
1452 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
1453 zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
1454 do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
1455 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
1456 zr->v4l_pend_tail++;
1460 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
1461 wake_up_interruptible(&zr->v4l_capq);
1463 /* Check if there is another grab queued */
1465 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
1466 zr->v4l_pend_tail != zr->v4l_pend_head) {
1468 int frame = zr->v4l_pend[zr->v4l_pend_tail &
1472 zr->v4l_grab_frame = frame;
1474 /* Set zr36057 video front end and enable video */
1476 /* Buffer address */
1479 zr->v4l_buffers.buffer[frame].
1481 btwrite(reg, ZR36057_VDTR);
1482 if (zr->v4l_settings.height >
1487 btwrite(reg, ZR36057_VDBR);
1489 /* video stride, status, and frame grab register */
1491 if (zr->v4l_settings.height >
1498 ZR36057_VSSFGR_DispStride);
1499 reg |= ZR36057_VSSFGR_VidOvf;
1500 reg |= ZR36057_VSSFGR_SnapShot;
1501 reg |= ZR36057_VSSFGR_FrameGrab;
1502 btwrite(reg, ZR36057_VSSFGR);
1504 btor(ZR36057_VDCR_VidEn,
1509 /* even if we don't grab, we do want to increment
1510 * the sequence counter to see lost frames */
1513 #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1514 if (astat & ZR36057_ISR_CodRepIRQ) {
1515 zr->intr_counter_CodRepIRQ++;
1517 (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
1519 btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
1521 #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
1523 #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1524 if (astat & ZR36057_ISR_JPEGRepIRQ) {
1526 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1527 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1528 if (zr36067_debug > 1 &&
1529 (!zr->frame_num || zr->JPEG_error)) {
1531 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1532 ZR_DEVNAME(zr), stat,
1533 zr->jpg_settings.odd_even,
1542 for (i = 0; i < 4; i++) {
1543 if (le32_to_cpu(zr->stat_com[i]) & 1)
1548 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1556 if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics
1557 zr->JPEG_max_missed =
1559 if (zr->JPEG_missed <
1560 zr->JPEG_min_missed)
1561 zr->JPEG_min_missed =
1565 if (zr36067_debug > 2 && zr->frame_num < 6) {
1567 printk("%s: seq=%ld stat_com:",
1568 ZR_DEVNAME(zr), zr->jpg_seq_num);
1569 for (i = 0; i < 4; i++) {
1571 le32_to_cpu(zr->stat_com[i]));
1576 zr->JPEG_missed = 0;
1578 zoran_reap_stat_com(zr);
1579 zoran_feed_stat_com(zr);
1580 wake_up_interruptible(&zr->jpg_capq);
1584 "%s: JPEG interrupt while not in motion (de)compress mode!\n",
1588 #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
1590 /* DATERR, too many fields missed, error processing */
1591 if ((astat & zr->card.jpeg_int) ||
1592 zr->JPEG_missed > 25 ||
1593 zr->JPEG_error == 1 ||
1594 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
1595 (zr->frame_num & (zr->JPEG_missed >
1596 zr->jpg_settings.field_per_buff)))) {
1597 error_handler(zr, astat, stat);
1602 dprintk(2, KERN_WARNING "%s: irq loop %d\n",
1603 ZR_DEVNAME(zr), count);
1605 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1608 "%s: IRQ lockup, cleared int mask\n",
1613 zr->last_isr = stat;
1615 spin_unlock_irqrestore(&zr->spinlock, flags);
1621 zoran_set_pci_master (struct zoran *zr,
1625 pci_set_master(zr->pci_dev);
1629 pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
1630 command &= ~PCI_COMMAND_MASTER;
1631 pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
1636 zoran_init_hardware (struct zoran *zr)
1640 /* Enable bus-mastering */
1641 zoran_set_pci_master(zr, 1);
1643 /* Initialize the board */
1644 if (zr->card.init) {
1648 j = zr->card.input[zr->input].muxsel;
1650 decoder_command(zr, 0, NULL);
1651 decoder_command(zr, DECODER_SET_NORM, &zr->norm);
1652 decoder_command(zr, DECODER_SET_INPUT, &j);
1654 encoder_command(zr, 0, NULL);
1655 encoder_command(zr, ENCODER_SET_NORM, &zr->norm);
1656 encoder_command(zr, ENCODER_SET_INPUT, &zero);
1658 /* toggle JPEG codec sleep to sync PLL */
1659 jpeg_codec_sleep(zr, 1);
1660 jpeg_codec_sleep(zr, 0);
1662 /* set individual interrupt enables (without GIRQ1)
1663 * but don't global enable until zoran_open() */
1665 //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW
1666 // It looks like using only JPEGRepIRQEn is not always reliable,
1667 // may be when JPEG codec crashes it won't generate IRQ? So,
1668 /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
1669 zr36057_init_vfe(zr);
1671 zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
1673 btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
1677 zr36057_restart (struct zoran *zr)
1679 btwrite(0, ZR36057_SPGPPCR);
1681 btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
1684 /* assert P_Reset */
1685 btwrite(0, ZR36057_JPC);
1686 /* set up GPIO direction - all output */
1687 btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
1689 /* set up GPIO pins and guest bus timing */
1690 btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
1694 * initialize video front end
1698 zr36057_init_vfe (struct zoran *zr)
1702 reg = btread(ZR36057_VFESPFR);
1703 reg |= ZR36057_VFESPFR_LittleEndian;
1704 reg &= ~ZR36057_VFESPFR_VCLKPol;
1705 reg |= ZR36057_VFESPFR_ExtFl;
1706 reg |= ZR36057_VFESPFR_TopField;
1707 btwrite(reg, ZR36057_VFESPFR);
1708 reg = btread(ZR36057_VDCR);
1709 if (pci_pci_problems & PCIPCI_TRITON)
1710 // || zr->revision < 1) // Revision 1 has also Triton support
1711 reg &= ~ZR36057_VDCR_Triton;
1713 reg |= ZR36057_VDCR_Triton;
1714 btwrite(reg, ZR36057_VDCR);
1718 * Interface to decoder and encoder chips using i2c bus
1722 decoder_command (struct zoran *zr,
1726 if (zr->decoder == NULL)
1729 if (zr->card.type == LML33 &&
1730 (cmd == DECODER_SET_NORM || DECODER_SET_INPUT)) {
1733 // Bt819 needs to reset its FIFO buffer using #FRST pin and
1734 // LML33 card uses GPIO(7) for that.
1736 res = zr->decoder->driver->command(zr->decoder, cmd, data);
1741 return zr->decoder->driver->command(zr->decoder, cmd,
1746 encoder_command (struct zoran *zr,
1750 if (zr->encoder == NULL)
1753 return zr->encoder->driver->command(zr->encoder, cmd, data);