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/videodev.h>
40 #include <linux/spinlock.h>
41 #include <linux/sem.h>
43 #include <linux/pci.h>
44 #include <linux/video_decoder.h>
45 #include <linux/video_encoder.h>
46 #include <linux/delay.h>
47 #include <linux/wait.h>
49 #include <asm/byteorder.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 jpeg_start (struct zoran
*zr
)
938 /* deassert P_reset, disable code transfer, deassert Active */
939 btwrite(ZR36057_JPC_P_Reset
, ZR36057_JPC
);
940 /* stop flushing the internal code buffer */
941 btand(~ZR36057_MCTCR_CFlush
, ZR36057_MCTCR
);
942 /* enable code transfer */
943 btor(ZR36057_JPC_CodTrnsEn
, ZR36057_JPC
);
946 btwrite(IRQ_MASK
, ZR36057_ISR
);
947 /* enable the JPEG IRQs */
948 btwrite(zr
->card
.jpeg_int
|
949 ZR36057_ICR_JPEGRepIRQ
|
950 ZR36057_ICR_IntPinEn
,
953 set_frame(zr
, 0); // \FRAME
955 /* set the JPEG codec guest ID */
956 reg
= (zr
->card
.gpcs
[1] << ZR36057_JCGI_JPEGuestID
) |
957 (0 << ZR36057_JCGI_JPEGuestReg
);
958 btwrite(reg
, ZR36057_JCGI
);
960 if (zr
->card
.video_vfe
== CODEC_TYPE_ZR36016
&&
961 zr
->card
.video_codec
== CODEC_TYPE_ZR36050
) {
962 /* Enable processing on the ZR36016 */
964 zr36016_write(zr
->vfe
, 0, 1);
966 /* load the address of the GO register in the ZR36050 latch */
967 post_office_write(zr
, 0, 0, 0);
971 btor(ZR36057_JPC_Active
, ZR36057_JPC
);
973 /* enable the Go generation */
974 btor(ZR36057_JMC_Go_en
, ZR36057_JMC
);
977 set_frame(zr
, 1); // /FRAME
979 dprintk(3, KERN_DEBUG
"%s: jpeg_start\n", ZR_DEVNAME(zr
));
983 zr36057_enable_jpg (struct zoran
*zr
,
984 enum zoran_codec_mode mode
)
988 struct vfe_settings cap
;
990 zr
->jpg_buffers
.buffer_size
/ zr
->jpg_settings
.field_per_buff
;
992 zr
->codec_mode
= mode
;
994 cap
.x
= zr
->jpg_settings
.img_x
;
995 cap
.y
= zr
->jpg_settings
.img_y
;
996 cap
.width
= zr
->jpg_settings
.img_width
;
997 cap
.height
= zr
->jpg_settings
.img_height
;
999 zr
->jpg_settings
.HorDcm
| (zr
->jpg_settings
.VerDcm
<< 8);
1000 cap
.quality
= zr
->jpg_settings
.jpg_comp
.quality
;
1004 case BUZ_MODE_MOTION_COMPRESS
: {
1005 struct jpeg_app_marker app
;
1006 struct jpeg_com_marker com
;
1008 /* In motion compress mode, the decoder output must be enabled, and
1009 * the video bus direction set to input.
1011 set_videobus_dir(zr
, 0);
1012 decoder_command(zr
, DECODER_ENABLE_OUTPUT
, &one
);
1013 encoder_command(zr
, ENCODER_SET_INPUT
, &zero
);
1015 /* Take the JPEG codec and the VFE out of sleep */
1016 jpeg_codec_sleep(zr
, 0);
1018 /* set JPEG app/com marker */
1019 app
.appn
= zr
->jpg_settings
.jpg_comp
.APPn
;
1020 app
.len
= zr
->jpg_settings
.jpg_comp
.APP_len
;
1021 memcpy(app
.data
, zr
->jpg_settings
.jpg_comp
.APP_data
, 60);
1022 zr
->codec
->control(zr
->codec
, CODEC_S_JPEG_APP_DATA
,
1023 sizeof(struct jpeg_app_marker
), &app
);
1025 com
.len
= zr
->jpg_settings
.jpg_comp
.COM_len
;
1026 memcpy(com
.data
, zr
->jpg_settings
.jpg_comp
.COM_data
, 60);
1027 zr
->codec
->control(zr
->codec
, CODEC_S_JPEG_COM_DATA
,
1028 sizeof(struct jpeg_com_marker
), &com
);
1030 /* Setup the JPEG codec */
1031 zr
->codec
->control(zr
->codec
, CODEC_S_JPEG_TDS_BYTE
,
1032 sizeof(int), &field_size
);
1033 zr
->codec
->set_video(zr
->codec
, zr
->timing
, &cap
,
1035 zr
->codec
->set_mode(zr
->codec
, CODEC_DO_COMPRESSION
);
1039 zr
->vfe
->control(zr
->vfe
, CODEC_S_JPEG_TDS_BYTE
,
1040 sizeof(int), &field_size
);
1041 zr
->vfe
->set_video(zr
->vfe
, zr
->timing
, &cap
,
1043 zr
->vfe
->set_mode(zr
->vfe
, CODEC_DO_COMPRESSION
);
1046 init_jpeg_queue(zr
);
1047 zr36057_set_jpg(zr
, mode
); // \P_Reset, ... Video param, FIFO
1049 clear_interrupt_counters(zr
);
1050 dprintk(2, KERN_INFO
"%s: enable_jpg(MOTION_COMPRESS)\n",
1055 case BUZ_MODE_MOTION_DECOMPRESS
:
1056 /* In motion decompression mode, the decoder output must be disabled, and
1057 * the video bus direction set to output.
1059 decoder_command(zr
, DECODER_ENABLE_OUTPUT
, &zero
);
1060 set_videobus_dir(zr
, 1);
1061 encoder_command(zr
, ENCODER_SET_INPUT
, &one
);
1063 /* Take the JPEG codec and the VFE out of sleep */
1064 jpeg_codec_sleep(zr
, 0);
1067 zr
->vfe
->set_video(zr
->vfe
, zr
->timing
, &cap
,
1069 zr
->vfe
->set_mode(zr
->vfe
, CODEC_DO_EXPANSION
);
1071 /* Setup the JPEG codec */
1072 zr
->codec
->set_video(zr
->codec
, zr
->timing
, &cap
,
1074 zr
->codec
->set_mode(zr
->codec
, CODEC_DO_EXPANSION
);
1076 init_jpeg_queue(zr
);
1077 zr36057_set_jpg(zr
, mode
); // \P_Reset, ... Video param, FIFO
1079 clear_interrupt_counters(zr
);
1080 dprintk(2, KERN_INFO
"%s: enable_jpg(MOTION_DECOMPRESS)\n",
1086 /* shut down processing */
1087 btand(~(zr
->card
.jpeg_int
| ZR36057_ICR_JPEGRepIRQ
),
1089 btwrite(zr
->card
.jpeg_int
| ZR36057_ICR_JPEGRepIRQ
,
1091 btand(~ZR36057_JMC_Go_en
, ZR36057_JMC
); // \Go_en
1095 set_videobus_dir(zr
, 0);
1096 set_frame(zr
, 1); // /FRAME
1097 btor(ZR36057_MCTCR_CFlush
, ZR36057_MCTCR
); // /CFlush
1098 btwrite(0, ZR36057_JPC
); // \P_Reset,\CodTrnsEn,\Active
1099 btand(~ZR36057_JMC_VFIFO_FB
, ZR36057_JMC
);
1100 btand(~ZR36057_JMC_SyncMstr
, ZR36057_JMC
);
1101 jpeg_codec_reset(zr
);
1102 jpeg_codec_sleep(zr
, 1);
1103 zr36057_adjust_vfe(zr
, mode
);
1105 decoder_command(zr
, DECODER_ENABLE_OUTPUT
, &one
);
1106 encoder_command(zr
, ENCODER_SET_INPUT
, &zero
);
1108 dprintk(2, KERN_INFO
"%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr
));
1114 /* when this is called the spinlock must be held */
1116 zoran_feed_stat_com (struct zoran
*zr
)
1118 /* move frames from pending queue to DMA */
1120 int frame
, i
, max_stat_com
;
1123 (zr
->jpg_settings
.TmpDcm
==
1124 1) ? BUZ_NUM_STAT_COM
: (BUZ_NUM_STAT_COM
>> 1);
1126 while ((zr
->jpg_dma_head
- zr
->jpg_dma_tail
) < max_stat_com
&&
1127 zr
->jpg_dma_head
< zr
->jpg_que_head
) {
1129 frame
= zr
->jpg_pend
[zr
->jpg_dma_head
& BUZ_MASK_FRAME
];
1130 if (zr
->jpg_settings
.TmpDcm
== 1) {
1131 /* fill 1 stat_com entry */
1132 i
= (zr
->jpg_dma_head
-
1133 zr
->jpg_err_shift
) & BUZ_MASK_STAT_COM
;
1134 if (!(zr
->stat_com
[i
] & cpu_to_le32(1)))
1137 cpu_to_le32(zr
->jpg_buffers
.buffer
[frame
].frag_tab_bus
);
1139 /* fill 2 stat_com entries */
1140 i
= ((zr
->jpg_dma_head
-
1141 zr
->jpg_err_shift
) & 1) * 2;
1142 if (!(zr
->stat_com
[i
] & cpu_to_le32(1)))
1145 cpu_to_le32(zr
->jpg_buffers
.buffer
[frame
].frag_tab_bus
);
1146 zr
->stat_com
[i
+ 1] =
1147 cpu_to_le32(zr
->jpg_buffers
.buffer
[frame
].frag_tab_bus
);
1149 zr
->jpg_buffers
.buffer
[frame
].state
= BUZ_STATE_DMA
;
1153 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
)
1154 zr
->jpg_queued_num
++;
1157 /* when this is called the spinlock must be held */
1159 zoran_reap_stat_com (struct zoran
*zr
)
1161 /* move frames from DMA queue to done queue */
1167 struct zoran_jpg_buffer
*buffer
;
1170 /* In motion decompress we don't have a hardware frame counter,
1171 * we just count the interrupts here */
1173 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
) {
1176 while (zr
->jpg_dma_tail
< zr
->jpg_dma_head
) {
1177 if (zr
->jpg_settings
.TmpDcm
== 1)
1178 i
= (zr
->jpg_dma_tail
-
1179 zr
->jpg_err_shift
) & BUZ_MASK_STAT_COM
;
1181 i
= ((zr
->jpg_dma_tail
-
1182 zr
->jpg_err_shift
) & 1) * 2 + 1;
1184 stat_com
= le32_to_cpu(zr
->stat_com
[i
]);
1186 if ((stat_com
& 1) == 0) {
1189 frame
= zr
->jpg_pend
[zr
->jpg_dma_tail
& BUZ_MASK_FRAME
];
1190 buffer
= &zr
->jpg_buffers
.buffer
[frame
];
1191 do_gettimeofday(&buffer
->bs
.timestamp
);
1193 if (zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
) {
1194 buffer
->bs
.length
= (stat_com
& 0x7fffff) >> 1;
1196 /* update sequence number with the help of the counter in stat_com */
1198 seq
= ((stat_com
>> 24) + zr
->jpg_err_seq
) & 0xff;
1199 dif
= (seq
- zr
->jpg_seq_num
) & 0xff;
1200 zr
->jpg_seq_num
+= dif
;
1202 buffer
->bs
.length
= 0;
1205 zr
->jpg_settings
.TmpDcm
==
1206 2 ? (zr
->jpg_seq_num
>> 1) : zr
->jpg_seq_num
;
1207 buffer
->state
= BUZ_STATE_DONE
;
1214 error_handler (struct zoran
*zr
,
1218 /* This is JPEG error handling part */
1219 if ((zr
->codec_mode
!= BUZ_MODE_MOTION_COMPRESS
) &&
1220 (zr
->codec_mode
!= BUZ_MODE_MOTION_DECOMPRESS
)) {
1221 //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
1225 if ((stat
& 1) == 0 &&
1226 zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
&&
1227 zr
->jpg_dma_tail
- zr
->jpg_que_tail
>=
1228 zr
->jpg_buffers
.num_buffers
) {
1229 /* No free buffers... */
1230 zoran_reap_stat_com(zr
);
1231 zoran_feed_stat_com(zr
);
1232 wake_up_interruptible(&zr
->jpg_capq
);
1233 zr
->JPEG_missed
= 0;
1237 if (zr
->JPEG_error
!= 1) {
1239 * First entry: error just happened during normal operation
1241 * In BUZ_MODE_MOTION_COMPRESS:
1243 * Possible glitch in TV signal. In this case we should
1244 * stop the codec and wait for good quality signal before
1245 * restarting it to avoid further problems
1247 * In BUZ_MODE_MOTION_DECOMPRESS:
1249 * Bad JPEG frame: we have to mark it as processed (codec crashed
1250 * and was not able to do it itself), and to remove it from queue.
1252 btand(~ZR36057_JMC_Go_en
, ZR36057_JMC
);
1254 stat
= stat
| (post_office_read(zr
, 7, 0) & 3) << 8;
1255 btwrite(0, ZR36057_JPC
);
1256 btor(ZR36057_MCTCR_CFlush
, ZR36057_MCTCR
);
1257 jpeg_codec_reset(zr
);
1258 jpeg_codec_sleep(zr
, 1);
1263 if (zr36067_debug
> 1 && zr
->num_errors
<= 8) {
1266 zr
->jpg_pend
[zr
->jpg_dma_tail
& BUZ_MASK_FRAME
];
1268 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1269 ZR_DEVNAME(zr
), stat
, zr
->last_isr
,
1270 zr
->jpg_que_tail
, zr
->jpg_dma_tail
,
1271 zr
->jpg_dma_head
, zr
->jpg_que_head
,
1272 zr
->jpg_seq_num
, frame
);
1273 printk("stat_com frames:");
1276 for (j
= 0; j
< BUZ_NUM_STAT_COM
; j
++) {
1278 i
< zr
->jpg_buffers
.num_buffers
;
1280 if (le32_to_cpu(zr
->stat_com
[j
]) ==
1292 /* Find an entry in stat_com and rotate contents */
1296 if (zr
->jpg_settings
.TmpDcm
== 1)
1297 i
= (zr
->jpg_dma_tail
-
1298 zr
->jpg_err_shift
) & BUZ_MASK_STAT_COM
;
1300 i
= ((zr
->jpg_dma_tail
-
1301 zr
->jpg_err_shift
) & 1) * 2;
1302 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
) {
1303 /* Mimic zr36067 operation */
1304 zr
->stat_com
[i
] |= cpu_to_le32(1);
1305 if (zr
->jpg_settings
.TmpDcm
!= 1)
1306 zr
->stat_com
[i
+ 1] |= cpu_to_le32(1);
1308 zoran_reap_stat_com(zr
);
1309 zoran_feed_stat_com(zr
);
1310 wake_up_interruptible(&zr
->jpg_capq
);
1311 /* Find an entry in stat_com again after refill */
1312 if (zr
->jpg_settings
.TmpDcm
== 1)
1313 i
= (zr
->jpg_dma_tail
-
1314 zr
->jpg_err_shift
) &
1317 i
= ((zr
->jpg_dma_tail
-
1318 zr
->jpg_err_shift
) & 1) * 2;
1321 /* Rotate stat_comm entries to make current entry first */
1323 u32 bus_addr
[BUZ_NUM_STAT_COM
];
1325 /* Here we are copying the stat_com array, which
1326 * is already in little endian format, so
1327 * no endian conversions here
1329 memcpy(bus_addr
, zr
->stat_com
,
1331 for (j
= 0; j
< BUZ_NUM_STAT_COM
; j
++) {
1337 zr
->jpg_err_shift
+= i
;
1338 zr
->jpg_err_shift
&= BUZ_MASK_STAT_COM
;
1340 if (zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
)
1341 zr
->jpg_err_seq
= zr
->jpg_seq_num
; /* + 1; */
1345 /* Now the stat_comm buffer is ready for restart */
1349 if (zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
) {
1350 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
1351 mode
= CODEC_DO_COMPRESSION
;
1354 mode
= CODEC_DO_EXPANSION
;
1356 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
||
1357 (status
& DECODER_STATUS_GOOD
)) {
1358 /********** RESTART code *************/
1359 jpeg_codec_reset(zr
);
1360 zr
->codec
->set_mode(zr
->codec
, mode
);
1361 zr36057_set_jpg(zr
, zr
->codec_mode
);
1364 if (zr
->num_errors
<= 8)
1365 dprintk(2, KERN_INFO
"%s: Restart\n",
1368 zr
->JPEG_missed
= 0;
1370 /********** End RESTART code ***********/
1382 unsigned long flags
;
1388 /* Testing interrupts */
1389 spin_lock_irqsave(&zr
->spinlock
, flags
);
1390 while ((stat
= count_reset_interrupt(zr
))) {
1391 if (count
++ > 100) {
1392 btand(~ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1395 "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
1396 ZR_DEVNAME(zr
), stat
);
1397 wake_up_interruptible(&zr
->test_q
);
1400 zr
->last_isr
= stat
;
1401 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1405 spin_lock_irqsave(&zr
->spinlock
, flags
);
1407 /* get/clear interrupt status bits */
1408 stat
= count_reset_interrupt(zr
);
1409 astat
= stat
& IRQ_MASK
;
1415 "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
1416 astat
, btread(ZR36057_ICR
));
1417 if (astat
& zr
->card
.vsync_int
) { // SW
1419 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
||
1420 zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
) {
1421 /* count missed interrupts */
1424 //post_office_read(zr,1,0);
1425 /* Interrupts may still happen when
1426 * zr->v4l_memgrab_active is switched off.
1427 * We simply ignore them */
1429 if (zr
->v4l_memgrab_active
) {
1431 /* A lot more checks should be here ... */
1432 if ((btread(ZR36057_VSSFGR
) &
1433 ZR36057_VSSFGR_SnapShot
) == 0)
1436 "%s: BuzIRQ with SnapShot off ???\n",
1439 if (zr
->v4l_grab_frame
!= NO_GRAB_ACTIVE
) {
1440 /* There is a grab on a frame going on, check if it has finished */
1442 if ((btread(ZR36057_VSSFGR
) &
1443 ZR36057_VSSFGR_FrameGrab
) ==
1445 /* it is finished, notify the user */
1447 zr
->v4l_buffers
.buffer
[zr
->v4l_grab_frame
].state
= BUZ_STATE_DONE
;
1448 zr
->v4l_buffers
.buffer
[zr
->v4l_grab_frame
].bs
.seq
= zr
->v4l_grab_seq
;
1449 do_gettimeofday(&zr
->v4l_buffers
.buffer
[zr
->v4l_grab_frame
].bs
.timestamp
);
1450 zr
->v4l_grab_frame
= NO_GRAB_ACTIVE
;
1451 zr
->v4l_pend_tail
++;
1455 if (zr
->v4l_grab_frame
== NO_GRAB_ACTIVE
)
1456 wake_up_interruptible(&zr
->v4l_capq
);
1458 /* Check if there is another grab queued */
1460 if (zr
->v4l_grab_frame
== NO_GRAB_ACTIVE
&&
1461 zr
->v4l_pend_tail
!= zr
->v4l_pend_head
) {
1463 int frame
= zr
->v4l_pend
[zr
->v4l_pend_tail
&
1467 zr
->v4l_grab_frame
= frame
;
1469 /* Set zr36057 video front end and enable video */
1471 /* Buffer address */
1474 zr
->v4l_buffers
.buffer
[frame
].
1476 btwrite(reg
, ZR36057_VDTR
);
1477 if (zr
->v4l_settings
.height
>
1482 btwrite(reg
, ZR36057_VDBR
);
1484 /* video stride, status, and frame grab register */
1486 if (zr
->v4l_settings
.height
>
1493 ZR36057_VSSFGR_DispStride
);
1494 reg
|= ZR36057_VSSFGR_VidOvf
;
1495 reg
|= ZR36057_VSSFGR_SnapShot
;
1496 reg
|= ZR36057_VSSFGR_FrameGrab
;
1497 btwrite(reg
, ZR36057_VSSFGR
);
1499 btor(ZR36057_VDCR_VidEn
,
1504 /* even if we don't grab, we do want to increment
1505 * the sequence counter to see lost frames */
1508 #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1509 if (astat
& ZR36057_ISR_CodRepIRQ
) {
1510 zr
->intr_counter_CodRepIRQ
++;
1512 (KERN_DEBUG
"%s: ZR36057_ISR_CodRepIRQ\n",
1514 btand(~ZR36057_ICR_CodRepIRQ
, ZR36057_ICR
);
1516 #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
1518 #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1519 if (astat
& ZR36057_ISR_JPEGRepIRQ
) {
1521 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
||
1522 zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
) {
1523 if (zr36067_debug
> 1 &&
1524 (!zr
->frame_num
|| zr
->JPEG_error
)) {
1526 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1527 ZR_DEVNAME(zr
), stat
,
1528 zr
->jpg_settings
.odd_even
,
1537 for (i
= 0; i
< 4; i
++) {
1538 if (le32_to_cpu(zr
->stat_com
[i
]) & 1)
1543 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1551 if (zr
->JPEG_missed
> zr
->JPEG_max_missed
) // Get statistics
1552 zr
->JPEG_max_missed
=
1554 if (zr
->JPEG_missed
<
1555 zr
->JPEG_min_missed
)
1556 zr
->JPEG_min_missed
=
1560 if (zr36067_debug
> 2 && zr
->frame_num
< 6) {
1562 printk("%s: seq=%ld stat_com:",
1563 ZR_DEVNAME(zr
), zr
->jpg_seq_num
);
1564 for (i
= 0; i
< 4; i
++) {
1566 le32_to_cpu(zr
->stat_com
[i
]));
1571 zr
->JPEG_missed
= 0;
1573 zoran_reap_stat_com(zr
);
1574 zoran_feed_stat_com(zr
);
1575 wake_up_interruptible(&zr
->jpg_capq
);
1579 "%s: JPEG interrupt while not in motion (de)compress mode!\n",
1583 #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
1585 /* DATERR, too many fields missed, error processing */
1586 if ((astat
& zr
->card
.jpeg_int
) ||
1587 zr
->JPEG_missed
> 25 ||
1588 zr
->JPEG_error
== 1 ||
1589 ((zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
) &&
1590 (zr
->frame_num
& (zr
->JPEG_missed
>
1591 zr
->jpg_settings
.field_per_buff
)))) {
1592 error_handler(zr
, astat
, stat
);
1597 dprintk(2, KERN_WARNING
"%s: irq loop %d\n",
1598 ZR_DEVNAME(zr
), count
);
1600 btand(~ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1603 "%s: IRQ lockup, cleared int mask\n",
1608 zr
->last_isr
= stat
;
1610 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1616 zoran_set_pci_master (struct zoran
*zr
,
1620 pci_set_master(zr
->pci_dev
);
1624 pci_read_config_word(zr
->pci_dev
, PCI_COMMAND
, &command
);
1625 command
&= ~PCI_COMMAND_MASTER
;
1626 pci_write_config_word(zr
->pci_dev
, PCI_COMMAND
, command
);
1631 zoran_init_hardware (struct zoran
*zr
)
1635 /* Enable bus-mastering */
1636 zoran_set_pci_master(zr
, 1);
1638 /* Initialize the board */
1639 if (zr
->card
.init
) {
1643 j
= zr
->card
.input
[zr
->input
].muxsel
;
1645 decoder_command(zr
, 0, NULL
);
1646 decoder_command(zr
, DECODER_SET_NORM
, &zr
->norm
);
1647 decoder_command(zr
, DECODER_SET_INPUT
, &j
);
1649 encoder_command(zr
, 0, NULL
);
1650 encoder_command(zr
, ENCODER_SET_NORM
, &zr
->norm
);
1651 encoder_command(zr
, ENCODER_SET_INPUT
, &zero
);
1653 /* toggle JPEG codec sleep to sync PLL */
1654 jpeg_codec_sleep(zr
, 1);
1655 jpeg_codec_sleep(zr
, 0);
1657 /* set individual interrupt enables (without GIRQ1)
1658 * but don't global enable until zoran_open() */
1660 //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR); // SW
1661 // It looks like using only JPEGRepIRQEn is not always reliable,
1662 // may be when JPEG codec crashes it won't generate IRQ? So,
1663 /*CP*/ // btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM WHY ? LP
1664 zr36057_init_vfe(zr
);
1666 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1668 btwrite(IRQ_MASK
, ZR36057_ISR
); // Clears interrupts
1672 zr36057_restart (struct zoran
*zr
)
1674 btwrite(0, ZR36057_SPGPPCR
);
1676 btor(ZR36057_SPGPPCR_SoftReset
, ZR36057_SPGPPCR
);
1679 /* assert P_Reset */
1680 btwrite(0, ZR36057_JPC
);
1681 /* set up GPIO direction - all output */
1682 btwrite(ZR36057_SPGPPCR_SoftReset
| 0, ZR36057_SPGPPCR
);
1684 /* set up GPIO pins and guest bus timing */
1685 btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1
);
1689 * initialize video front end
1693 zr36057_init_vfe (struct zoran
*zr
)
1697 reg
= btread(ZR36057_VFESPFR
);
1698 reg
|= ZR36057_VFESPFR_LittleEndian
;
1699 reg
&= ~ZR36057_VFESPFR_VCLKPol
;
1700 reg
|= ZR36057_VFESPFR_ExtFl
;
1701 reg
|= ZR36057_VFESPFR_TopField
;
1702 btwrite(reg
, ZR36057_VFESPFR
);
1703 reg
= btread(ZR36057_VDCR
);
1704 if (pci_pci_problems
& PCIPCI_TRITON
)
1705 // || zr->revision < 1) // Revision 1 has also Triton support
1706 reg
&= ~ZR36057_VDCR_Triton
;
1708 reg
|= ZR36057_VDCR_Triton
;
1709 btwrite(reg
, ZR36057_VDCR
);
1713 * Interface to decoder and encoder chips using i2c bus
1717 decoder_command (struct zoran
*zr
,
1721 if (zr
->decoder
== NULL
)
1724 if (zr
->card
.type
== LML33
&&
1725 (cmd
== DECODER_SET_NORM
|| cmd
== DECODER_SET_INPUT
)) {
1728 // Bt819 needs to reset its FIFO buffer using #FRST pin and
1729 // LML33 card uses GPIO(7) for that.
1731 res
= zr
->decoder
->driver
->command(zr
->decoder
, cmd
, data
);
1736 return zr
->decoder
->driver
->command(zr
->decoder
, cmd
,
1741 encoder_command (struct zoran
*zr
,
1745 if (zr
->encoder
== NULL
)
1748 return zr
->encoder
->driver
->command(zr
->encoder
, cmd
, data
);