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.
26 #include <linux/types.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/vmalloc.h>
30 #include <linux/ktime.h>
31 #include <linux/sched/signal.h>
33 #include <linux/interrupt.h>
34 #include <linux/proc_fs.h>
35 #include <linux/i2c.h>
36 #include <linux/i2c-algo-bit.h>
37 #include <linux/videodev2.h>
38 #include <media/v4l2-common.h>
39 #include <linux/spinlock.h>
40 #include <linux/sem.h>
42 #include <linux/pci.h>
43 #include <linux/delay.h>
44 #include <linux/wait.h>
46 #include <asm/byteorder.h>
49 #include "videocodec.h"
51 #include "zoran_device.h"
52 #include "zoran_card.h"
54 #define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
56 ZR36057_ISR_JPEGRepIRQ )
58 static bool lml33dpath
; /* default = 0
59 * 1 will use digital path in capture
60 * mode instead of analog. It can be
61 * used for picture adjustments using
62 * tool like xawtv while watching image
63 * on TV monitor connected to the output.
64 * However, due to absence of 75 Ohm
65 * load on Bt819 input, there will be
66 * some image imperfections */
68 module_param(lml33dpath
, bool, 0644);
69 MODULE_PARM_DESC(lml33dpath
,
70 "Use digital path capture mode (on LML33 cards)");
73 zr36057_init_vfe (struct zoran
*zr
);
76 * General Purpose I/O and Guest bus access
80 * This is a bit tricky. When a board lacks a GPIO function, the corresponding
81 * GPIO bit number in the card_info structure is set to 0.
85 GPIO (struct zoran
*zr
,
92 /* Make sure the bit number is legal
93 * A bit number of -1 (lacking) gives a mask of 0,
94 * making it harmless */
95 mask
= (1 << (24 + bit
)) & 0xff000000;
96 reg
= btread(ZR36057_GPPGCR1
) & ~mask
;
100 btwrite(reg
, ZR36057_GPPGCR1
);
105 * Wait til post office is no longer busy
109 post_office_wait (struct zoran
*zr
)
113 // while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
114 while ((por
= btread(ZR36057_POR
)) & ZR36057_POR_POPen
) {
115 /* wait for something to happen */
117 if ((por
& ZR36057_POR_POTime
) && !zr
->card
.gws_not_connected
) {
118 /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
119 dprintk(1, KERN_INFO
"%s: pop timeout %08x\n", ZR_DEVNAME(zr
),
128 post_office_write (struct zoran
*zr
,
136 ZR36057_POR_PODir
| ZR36057_POR_POTime
| ((guest
& 7) << 20) |
137 ((reg
& 7) << 16) | (value
& 0xFF);
138 btwrite(por
, ZR36057_POR
);
140 return post_office_wait(zr
);
144 post_office_read (struct zoran
*zr
,
150 por
= ZR36057_POR_POTime
| ((guest
& 7) << 20) | ((reg
& 7) << 16);
151 btwrite(por
, ZR36057_POR
);
152 if (post_office_wait(zr
) < 0) {
156 return btread(ZR36057_POR
) & 0xFF;
164 dump_guests (struct zoran
*zr
)
166 if (zr36067_debug
> 2) {
169 for (i
= 1; i
< 8; i
++) { // Don't read jpeg codec here
170 guest
[i
] = post_office_read(zr
, i
, 0);
173 printk(KERN_INFO
"%s: Guests: %*ph\n",
174 ZR_DEVNAME(zr
), 8, guest
);
179 detect_guest_activity (struct zoran
*zr
)
181 int timeout
, i
, j
, res
, guest
[8], guest0
[8], change
[8][3];
185 printk(KERN_INFO
"%s: Detecting guests activity, please wait...\n",
187 for (i
= 1; i
< 8; i
++) { // Don't read jpeg codec here
188 guest0
[i
] = guest
[i
] = post_office_read(zr
, i
, 0);
194 while (timeout
< 10000) {
197 for (i
= 1; (i
< 8) && (j
< 8); i
++) {
198 res
= post_office_read(zr
, i
, 0);
199 if (res
!= guest
[i
]) {
201 change
[j
][0] = ktime_to_us(ktime_sub(t1
, t0
));
213 printk(KERN_INFO
"%s: Guests: %*ph\n", ZR_DEVNAME(zr
), 8, guest0
);
216 printk(KERN_INFO
"%s: No activity detected.\n", ZR_DEVNAME(zr
));
219 for (i
= 0; i
< j
; i
++) {
220 printk(KERN_INFO
"%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr
),
221 change
[i
][0], change
[i
][1], change
[i
][2]);
230 jpeg_codec_sleep (struct zoran
*zr
,
233 GPIO(zr
, zr
->card
.gpio
[ZR_GPIO_JPEG_SLEEP
], !sleep
);
237 "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
238 ZR_DEVNAME(zr
), btread(ZR36057_GPPGCR1
));
243 "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
244 ZR_DEVNAME(zr
), btread(ZR36057_GPPGCR1
));
250 jpeg_codec_reset (struct zoran
*zr
)
252 /* Take the codec out of sleep */
253 jpeg_codec_sleep(zr
, 0);
255 if (zr
->card
.gpcs
[GPCS_JPEG_RESET
] != 0xff) {
256 post_office_write(zr
, zr
->card
.gpcs
[GPCS_JPEG_RESET
], 0,
260 GPIO(zr
, zr
->card
.gpio
[ZR_GPIO_JPEG_RESET
], 0);
262 GPIO(zr
, zr
->card
.gpio
[ZR_GPIO_JPEG_RESET
], 1);
270 * Set the registers for the size we have specified. Don't bother
271 * trying to understand this without the ZR36057 manual in front of
274 * PS: The manual is free for download in .pdf format from
275 * www.zoran.com - nicely done those folks.
279 zr36057_adjust_vfe (struct zoran
*zr
,
280 enum zoran_codec_mode mode
)
285 case BUZ_MODE_MOTION_DECOMPRESS
:
286 btand(~ZR36057_VFESPFR_ExtFl
, ZR36057_VFESPFR
);
287 reg
= btread(ZR36057_VFEHCR
);
288 if ((reg
& (1 << 10)) && zr
->card
.type
!= LML33R10
) {
289 reg
+= ((1 << 10) | 1);
291 btwrite(reg
, ZR36057_VFEHCR
);
293 case BUZ_MODE_MOTION_COMPRESS
:
296 if ((zr
->norm
& V4L2_STD_NTSC
) ||
297 (zr
->card
.type
== LML33R10
&&
298 (zr
->norm
& V4L2_STD_PAL
)))
299 btand(~ZR36057_VFESPFR_ExtFl
, ZR36057_VFESPFR
);
301 btor(ZR36057_VFESPFR_ExtFl
, ZR36057_VFESPFR
);
302 reg
= btread(ZR36057_VFEHCR
);
303 if (!(reg
& (1 << 10)) && zr
->card
.type
!= LML33R10
) {
304 reg
-= ((1 << 10) | 1);
306 btwrite(reg
, ZR36057_VFEHCR
);
316 zr36057_set_vfe (struct zoran
*zr
,
319 const struct zoran_format
*format
)
322 unsigned HStart
, HEnd
, VStart
, VEnd
;
324 unsigned VidWinWid
, VidWinHt
;
325 unsigned hcrop1
, hcrop2
, vcrop1
, vcrop2
;
326 unsigned Wa
, We
, Ha
, He
;
327 unsigned X
, Y
, HorDcm
, VerDcm
;
329 unsigned mask_line_size
;
336 dprintk(2, KERN_INFO
"%s: set_vfe() - width = %d, height = %d\n",
337 ZR_DEVNAME(zr
), video_width
, video_height
);
339 if (video_width
< BUZ_MIN_WIDTH
||
340 video_height
< BUZ_MIN_HEIGHT
||
341 video_width
> Wa
|| video_height
> Ha
) {
342 dprintk(1, KERN_ERR
"%s: set_vfe: w=%d h=%d not valid\n",
343 ZR_DEVNAME(zr
), video_width
, video_height
);
350 VidWinWid
= video_width
;
351 X
= DIV_ROUND_UP(VidWinWid
* 64, tvn
->Wa
);
352 We
= (VidWinWid
* 64) / X
;
354 hcrop1
= 2 * ((tvn
->Wa
- We
) / 4);
355 hcrop2
= tvn
->Wa
- We
- hcrop1
;
356 HStart
= tvn
->HStart
? tvn
->HStart
: 1;
357 /* (Ronald) Original comment:
358 * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
359 * this is false. It inverses chroma values on the LML33R10 (so Cr
360 * suddenly is shown as Cb and reverse, really cool effect if you
361 * want to see blue faces, not useful otherwise). So don't use |1.
362 * However, the DC10 has '0' as HStart, but does need |1, so we
363 * use a dirty check...
365 HEnd
= HStart
+ tvn
->Wa
- 1;
368 reg
= ((HStart
& ZR36057_VFEHCR_Hmask
) << ZR36057_VFEHCR_HStart
)
369 | ((HEnd
& ZR36057_VFEHCR_Hmask
) << ZR36057_VFEHCR_HEnd
);
370 if (zr
->card
.vfe_pol
.hsync_pol
)
371 reg
|= ZR36057_VFEHCR_HSPol
;
372 btwrite(reg
, ZR36057_VFEHCR
);
375 DispMode
= !(video_height
> BUZ_MAX_HEIGHT
/ 2);
376 VidWinHt
= DispMode
? video_height
: video_height
/ 2;
377 Y
= DIV_ROUND_UP(VidWinHt
* 64 * 2, tvn
->Ha
);
378 He
= (VidWinHt
* 64) / Y
;
380 vcrop1
= (tvn
->Ha
/ 2 - He
) / 2;
381 vcrop2
= tvn
->Ha
/ 2 - He
- vcrop1
;
382 VStart
= tvn
->VStart
;
383 VEnd
= VStart
+ tvn
->Ha
/ 2; // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
386 reg
= ((VStart
& ZR36057_VFEVCR_Vmask
) << ZR36057_VFEVCR_VStart
)
387 | ((VEnd
& ZR36057_VFEVCR_Vmask
) << ZR36057_VFEVCR_VEnd
);
388 if (zr
->card
.vfe_pol
.vsync_pol
)
389 reg
|= ZR36057_VFEVCR_VSPol
;
390 btwrite(reg
, ZR36057_VFEVCR
);
392 /* scaler and pixel format */
394 reg
|= (HorDcm
<< ZR36057_VFESPFR_HorDcm
);
395 reg
|= (VerDcm
<< ZR36057_VFESPFR_VerDcm
);
396 reg
|= (DispMode
<< ZR36057_VFESPFR_DispMode
);
397 /* RJ: I don't know, why the following has to be the opposite
398 * of the corresponding ZR36060 setting, but only this way
399 * we get the correct colors when uncompressing to the screen */
400 //reg |= ZR36057_VFESPFR_VCLKPol; /**/
401 /* RJ: Don't know if that is needed for NTSC also */
402 if (!(zr
->norm
& V4L2_STD_NTSC
))
403 reg
|= ZR36057_VFESPFR_ExtFl
; // NEEDED!!!!!!! Wolfgang
404 reg
|= ZR36057_VFESPFR_TopField
;
406 reg
|= 3 << ZR36057_VFESPFR_HFilter
; /* 5 tap filter */
407 } else if (HorDcm
>= 32) {
408 reg
|= 2 << ZR36057_VFESPFR_HFilter
; /* 4 tap filter */
409 } else if (HorDcm
>= 16) {
410 reg
|= 1 << ZR36057_VFESPFR_HFilter
; /* 3 tap filter */
412 reg
|= format
->vfespfr
;
413 btwrite(reg
, ZR36057_VFESPFR
);
415 /* display configuration */
416 reg
= (16 << ZR36057_VDCR_MinPix
)
417 | (VidWinHt
<< ZR36057_VDCR_VidWinHt
)
418 | (VidWinWid
<< ZR36057_VDCR_VidWinWid
);
419 if (pci_pci_problems
& PCIPCI_TRITON
)
420 // || zr->revision < 1) // Revision 1 has also Triton support
421 reg
&= ~ZR36057_VDCR_Triton
;
423 reg
|= ZR36057_VDCR_Triton
;
424 btwrite(reg
, ZR36057_VDCR
);
426 /* (Ronald) don't write this if overlay_mask = NULL */
427 if (zr
->overlay_mask
) {
428 /* Write overlay clipping mask data, but don't enable overlay clipping */
429 /* RJ: since this makes only sense on the screen, we use
430 * zr->overlay_settings.width instead of video_width */
432 mask_line_size
= (BUZ_MAX_WIDTH
+ 31) / 32;
433 reg
= virt_to_bus(zr
->overlay_mask
);
434 btwrite(reg
, ZR36057_MMTR
);
435 reg
= virt_to_bus(zr
->overlay_mask
+ mask_line_size
);
436 btwrite(reg
, ZR36057_MMBR
);
438 mask_line_size
- (zr
->overlay_settings
.width
+
441 reg
+= mask_line_size
;
442 reg
<<= ZR36057_OCR_MaskStride
;
443 btwrite(reg
, ZR36057_OCR
);
446 zr36057_adjust_vfe(zr
, zr
->codec_mode
);
450 * Switch overlay on or off
454 zr36057_overlay (struct zoran
*zr
,
460 /* do the necessary settings ... */
461 btand(~ZR36057_VDCR_VidEn
, ZR36057_VDCR
); /* switch it off first */
464 zr
->overlay_settings
.width
,
465 zr
->overlay_settings
.height
,
466 zr
->overlay_settings
.format
);
468 /* Start and length of each line MUST be 4-byte aligned.
469 * This should be already checked before the call to this routine.
470 * All error messages are internal driver checking only! */
472 /* video display top and bottom registers */
473 reg
= (long) zr
->vbuf_base
+
474 zr
->overlay_settings
.x
*
475 ((zr
->overlay_settings
.format
->depth
+ 7) / 8) +
476 zr
->overlay_settings
.y
*
477 zr
->vbuf_bytesperline
;
478 btwrite(reg
, ZR36057_VDTR
);
482 "%s: zr36057_overlay() - video_address not aligned\n",
484 if (zr
->overlay_settings
.height
> BUZ_MAX_HEIGHT
/ 2)
485 reg
+= zr
->vbuf_bytesperline
;
486 btwrite(reg
, ZR36057_VDBR
);
488 /* video stride, status, and frame grab register */
489 reg
= zr
->vbuf_bytesperline
-
490 zr
->overlay_settings
.width
*
491 ((zr
->overlay_settings
.format
->depth
+ 7) / 8);
492 if (zr
->overlay_settings
.height
> BUZ_MAX_HEIGHT
/ 2)
493 reg
+= zr
->vbuf_bytesperline
;
497 "%s: zr36057_overlay() - video_stride not aligned\n",
499 reg
= (reg
<< ZR36057_VSSFGR_DispStride
);
500 reg
|= ZR36057_VSSFGR_VidOvf
; /* clear overflow status */
501 btwrite(reg
, ZR36057_VSSFGR
);
503 /* Set overlay clipping */
504 if (zr
->overlay_settings
.clipcount
> 0)
505 btor(ZR36057_OCR_OvlEnable
, ZR36057_OCR
);
507 /* ... and switch it on */
508 btor(ZR36057_VDCR_VidEn
, ZR36057_VDCR
);
511 btand(~ZR36057_VDCR_VidEn
, ZR36057_VDCR
);
516 * The overlay mask has one bit for each pixel on a scan line,
517 * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
520 void write_overlay_mask(struct zoran_fh
*fh
, struct v4l2_clip
*vp
, int count
)
522 struct zoran
*zr
= fh
->zr
;
523 unsigned mask_line_size
= (BUZ_MAX_WIDTH
+ 31) / 32;
525 int x
, y
, width
, height
;
528 /* fill mask with one bits */
529 memset(fh
->overlay_mask
, ~0, mask_line_size
* 4 * BUZ_MAX_HEIGHT
);
531 for (i
= 0; i
< count
; ++i
) {
532 /* pick up local copy of clip */
535 width
= vp
[i
].c
.width
;
536 height
= vp
[i
].c
.height
;
538 /* trim clips that extend beyond the window */
547 if (x
+ width
> fh
->overlay_settings
.width
) {
548 width
= fh
->overlay_settings
.width
- x
;
550 if (y
+ height
> fh
->overlay_settings
.height
) {
551 height
= fh
->overlay_settings
.height
- y
;
554 /* ignore degenerate clips */
562 /* apply clip for each scan line */
563 for (j
= 0; j
< height
; ++j
) {
564 /* reset bit for each pixel */
565 /* this can be optimized later if need be */
566 mask
= fh
->overlay_mask
+ (y
+ j
) * mask_line_size
;
567 for (k
= 0; k
< width
; ++k
) {
568 mask
[(x
+ k
) / 32] &=
569 ~((u32
) 1 << (x
+ k
) % 32);
575 /* Enable/Disable uncompressed memory grabbing of the 36057 */
578 zr36057_set_memgrab (struct zoran
*zr
,
582 /* We only check SnapShot and not FrameGrab here. SnapShot==1
583 * means a capture is already in progress, but FrameGrab==1
584 * doesn't necessary mean that. It's more correct to say a 1
585 * to 0 transition indicates a capture completed. If a
586 * capture is pending when capturing is tuned off, FrameGrab
587 * will be stuck at 1 until capturing is turned back on.
589 if (btread(ZR36057_VSSFGR
) & ZR36057_VSSFGR_SnapShot
)
592 "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
595 /* switch on VSync interrupts */
596 btwrite(IRQ_MASK
, ZR36057_ISR
); // Clear Interrupts
597 btor(zr
->card
.vsync_int
, ZR36057_ICR
); // SW
599 /* enable SnapShot */
600 btor(ZR36057_VSSFGR_SnapShot
, ZR36057_VSSFGR
);
602 /* Set zr36057 video front end and enable video */
603 zr36057_set_vfe(zr
, zr
->v4l_settings
.width
,
604 zr
->v4l_settings
.height
,
605 zr
->v4l_settings
.format
);
607 zr
->v4l_memgrab_active
= 1;
609 /* switch off VSync interrupts */
610 btand(~zr
->card
.vsync_int
, ZR36057_ICR
); // SW
612 zr
->v4l_memgrab_active
= 0;
613 zr
->v4l_grab_frame
= NO_GRAB_ACTIVE
;
615 /* reenable grabbing to screen if it was running */
616 if (zr
->v4l_overlay_active
) {
617 zr36057_overlay(zr
, 1);
619 btand(~ZR36057_VDCR_VidEn
, ZR36057_VDCR
);
620 btand(~ZR36057_VSSFGR_SnapShot
, ZR36057_VSSFGR
);
626 wait_grab_pending (struct zoran
*zr
)
630 /* wait until all pending grabs are finished */
632 if (!zr
->v4l_memgrab_active
)
635 wait_event_interruptible(zr
->v4l_capq
,
636 (zr
->v4l_pend_tail
== zr
->v4l_pend_head
));
637 if (signal_pending(current
))
640 spin_lock_irqsave(&zr
->spinlock
, flags
);
641 zr36057_set_memgrab(zr
, 0);
642 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
647 /*****************************************************************************
649 * Set up the Buz-specific MJPEG part *
651 *****************************************************************************/
654 set_frame (struct zoran
*zr
,
657 GPIO(zr
, zr
->card
.gpio
[ZR_GPIO_JPEG_FRAME
], val
);
661 set_videobus_dir (struct zoran
*zr
,
664 switch (zr
->card
.type
) {
673 GPIO(zr
, zr
->card
.gpio
[ZR_GPIO_VID_DIR
],
674 zr
->card
.gpio_pol
[ZR_GPIO_VID_DIR
] ? !val
: val
);
680 init_jpeg_queue (struct zoran
*zr
)
684 /* re-initialize DMA ring stuff */
685 zr
->jpg_que_head
= 0;
686 zr
->jpg_dma_head
= 0;
687 zr
->jpg_dma_tail
= 0;
688 zr
->jpg_que_tail
= 0;
693 zr
->jpg_err_shift
= 0;
694 zr
->jpg_queued_num
= 0;
695 for (i
= 0; i
< zr
->jpg_buffers
.num_buffers
; i
++) {
696 zr
->jpg_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
698 for (i
= 0; i
< BUZ_NUM_STAT_COM
; i
++) {
699 zr
->stat_com
[i
] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
704 zr36057_set_jpg (struct zoran
*zr
,
705 enum zoran_codec_mode mode
)
712 /* assert P_Reset, disable code transfer, deassert Active */
713 btwrite(0, ZR36057_JPC
);
715 /* MJPEG compression mode */
718 case BUZ_MODE_MOTION_COMPRESS
:
720 reg
= ZR36057_JMC_MJPGCmpMode
;
723 case BUZ_MODE_MOTION_DECOMPRESS
:
724 reg
= ZR36057_JMC_MJPGExpMode
;
725 reg
|= ZR36057_JMC_SyncMstr
;
726 /* RJ: The following is experimental - improves the output to screen */
727 //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
730 case BUZ_MODE_STILL_COMPRESS
:
731 reg
= ZR36057_JMC_JPGCmpMode
;
734 case BUZ_MODE_STILL_DECOMPRESS
:
735 reg
= ZR36057_JMC_JPGExpMode
;
739 reg
|= ZR36057_JMC_JPG
;
740 if (zr
->jpg_settings
.field_per_buff
== 1)
741 reg
|= ZR36057_JMC_Fld_per_buff
;
742 btwrite(reg
, ZR36057_JMC
);
745 btor(ZR36057_VFEVCR_VSPol
, ZR36057_VFEVCR
);
746 reg
= (6 << ZR36057_VSP_VsyncSize
) |
747 (tvn
->Ht
<< ZR36057_VSP_FrmTot
);
748 btwrite(reg
, ZR36057_VSP
);
749 reg
= ((zr
->jpg_settings
.img_y
+ tvn
->VStart
) << ZR36057_FVAP_NAY
) |
750 (zr
->jpg_settings
.img_height
<< ZR36057_FVAP_PAY
);
751 btwrite(reg
, ZR36057_FVAP
);
754 if (zr
->card
.vfe_pol
.hsync_pol
)
755 btor(ZR36057_VFEHCR_HSPol
, ZR36057_VFEHCR
);
757 btand(~ZR36057_VFEHCR_HSPol
, ZR36057_VFEHCR
);
758 reg
= ((tvn
->HSyncStart
) << ZR36057_HSP_HsyncStart
) |
759 (tvn
->Wt
<< ZR36057_HSP_LineTot
);
760 btwrite(reg
, ZR36057_HSP
);
761 reg
= ((zr
->jpg_settings
.img_x
+
762 tvn
->HStart
+ 4) << ZR36057_FHAP_NAX
) |
763 (zr
->jpg_settings
.img_width
<< ZR36057_FHAP_PAX
);
764 btwrite(reg
, ZR36057_FHAP
);
766 /* field process parameters */
767 if (zr
->jpg_settings
.odd_even
)
768 reg
= ZR36057_FPP_Odd_Even
;
772 btwrite(reg
, ZR36057_FPP
);
774 /* Set proper VCLK Polarity, else colors will be wrong during playback */
775 //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
777 /* code base address */
778 reg
= virt_to_bus(zr
->stat_com
);
779 btwrite(reg
, ZR36057_JCBA
);
781 /* FIFO threshold (FIFO is 160. double words) */
782 /* NOTE: decimal values here */
785 case BUZ_MODE_STILL_COMPRESS
:
786 case BUZ_MODE_MOTION_COMPRESS
:
787 if (zr
->card
.type
!= BUZ
)
793 case BUZ_MODE_STILL_DECOMPRESS
:
794 case BUZ_MODE_MOTION_DECOMPRESS
:
803 btwrite(reg
, ZR36057_JCFT
);
804 zr36057_adjust_vfe(zr
, mode
);
809 print_interrupts (struct zoran
*zr
)
813 printk(KERN_INFO
"%s: interrupts received:", ZR_DEVNAME(zr
));
814 if ((res
= zr
->field_counter
) < -1 || res
> 1) {
815 printk(KERN_CONT
" FD:%d", res
);
817 if ((res
= zr
->intr_counter_GIRQ1
) != 0) {
818 printk(KERN_CONT
" GIRQ1:%d", res
);
821 if ((res
= zr
->intr_counter_GIRQ0
) != 0) {
822 printk(KERN_CONT
" GIRQ0:%d", res
);
825 if ((res
= zr
->intr_counter_CodRepIRQ
) != 0) {
826 printk(KERN_CONT
" CodRepIRQ:%d", res
);
829 if ((res
= zr
->intr_counter_JPEGRepIRQ
) != 0) {
830 printk(KERN_CONT
" JPEGRepIRQ:%d", res
);
833 if (zr
->JPEG_max_missed
) {
834 printk(KERN_CONT
" JPEG delays: max=%d min=%d", zr
->JPEG_max_missed
,
835 zr
->JPEG_min_missed
);
837 if (zr
->END_event_missed
) {
838 printk(KERN_CONT
" ENDs missed: %d", zr
->END_event_missed
);
840 //if (zr->jpg_queued_num) {
841 printk(KERN_CONT
" queue_state=%ld/%ld/%ld/%ld", zr
->jpg_que_tail
,
842 zr
->jpg_dma_tail
, zr
->jpg_dma_head
, zr
->jpg_que_head
);
845 printk(KERN_CONT
": no interrupts detected.");
847 printk(KERN_CONT
"\n");
851 clear_interrupt_counters (struct zoran
*zr
)
853 zr
->intr_counter_GIRQ1
= 0;
854 zr
->intr_counter_GIRQ0
= 0;
855 zr
->intr_counter_CodRepIRQ
= 0;
856 zr
->intr_counter_JPEGRepIRQ
= 0;
857 zr
->field_counter
= 0;
864 zr
->END_event_missed
= 0;
866 zr
->JPEG_max_missed
= 0;
867 zr
->JPEG_min_missed
= 0x7fffffff;
871 count_reset_interrupt (struct zoran
*zr
)
875 if ((isr
= btread(ZR36057_ISR
) & 0x78000000)) {
876 if (isr
& ZR36057_ISR_GIRQ1
) {
877 btwrite(ZR36057_ISR_GIRQ1
, ZR36057_ISR
);
878 zr
->intr_counter_GIRQ1
++;
880 if (isr
& ZR36057_ISR_GIRQ0
) {
881 btwrite(ZR36057_ISR_GIRQ0
, ZR36057_ISR
);
882 zr
->intr_counter_GIRQ0
++;
884 if (isr
& ZR36057_ISR_CodRepIRQ
) {
885 btwrite(ZR36057_ISR_CodRepIRQ
, ZR36057_ISR
);
886 zr
->intr_counter_CodRepIRQ
++;
888 if (isr
& ZR36057_ISR_JPEGRepIRQ
) {
889 btwrite(ZR36057_ISR_JPEGRepIRQ
, ZR36057_ISR
);
890 zr
->intr_counter_JPEGRepIRQ
++;
897 jpeg_start (struct zoran
*zr
)
903 /* deassert P_reset, disable code transfer, deassert Active */
904 btwrite(ZR36057_JPC_P_Reset
, ZR36057_JPC
);
905 /* stop flushing the internal code buffer */
906 btand(~ZR36057_MCTCR_CFlush
, ZR36057_MCTCR
);
907 /* enable code transfer */
908 btor(ZR36057_JPC_CodTrnsEn
, ZR36057_JPC
);
911 btwrite(IRQ_MASK
, ZR36057_ISR
);
912 /* enable the JPEG IRQs */
913 btwrite(zr
->card
.jpeg_int
|
914 ZR36057_ICR_JPEGRepIRQ
|
915 ZR36057_ICR_IntPinEn
,
918 set_frame(zr
, 0); // \FRAME
920 /* set the JPEG codec guest ID */
921 reg
= (zr
->card
.gpcs
[1] << ZR36057_JCGI_JPEGuestID
) |
922 (0 << ZR36057_JCGI_JPEGuestReg
);
923 btwrite(reg
, ZR36057_JCGI
);
925 if (zr
->card
.video_vfe
== CODEC_TYPE_ZR36016
&&
926 zr
->card
.video_codec
== CODEC_TYPE_ZR36050
) {
927 /* Enable processing on the ZR36016 */
929 zr36016_write(zr
->vfe
, 0, 1);
931 /* load the address of the GO register in the ZR36050 latch */
932 post_office_write(zr
, 0, 0, 0);
936 btor(ZR36057_JPC_Active
, ZR36057_JPC
);
938 /* enable the Go generation */
939 btor(ZR36057_JMC_Go_en
, ZR36057_JMC
);
942 set_frame(zr
, 1); // /FRAME
944 dprintk(3, KERN_DEBUG
"%s: jpeg_start\n", ZR_DEVNAME(zr
));
948 zr36057_enable_jpg (struct zoran
*zr
,
949 enum zoran_codec_mode mode
)
951 struct vfe_settings cap
;
953 zr
->jpg_buffers
.buffer_size
/ zr
->jpg_settings
.field_per_buff
;
955 zr
->codec_mode
= mode
;
957 cap
.x
= zr
->jpg_settings
.img_x
;
958 cap
.y
= zr
->jpg_settings
.img_y
;
959 cap
.width
= zr
->jpg_settings
.img_width
;
960 cap
.height
= zr
->jpg_settings
.img_height
;
962 zr
->jpg_settings
.HorDcm
| (zr
->jpg_settings
.VerDcm
<< 8);
963 cap
.quality
= zr
->jpg_settings
.jpg_comp
.quality
;
967 case BUZ_MODE_MOTION_COMPRESS
: {
968 struct jpeg_app_marker app
;
969 struct jpeg_com_marker com
;
971 /* In motion compress mode, the decoder output must be enabled, and
972 * the video bus direction set to input.
974 set_videobus_dir(zr
, 0);
975 decoder_call(zr
, video
, s_stream
, 1);
976 encoder_call(zr
, video
, s_routing
, 0, 0, 0);
978 /* Take the JPEG codec and the VFE out of sleep */
979 jpeg_codec_sleep(zr
, 0);
981 /* set JPEG app/com marker */
982 app
.appn
= zr
->jpg_settings
.jpg_comp
.APPn
;
983 app
.len
= zr
->jpg_settings
.jpg_comp
.APP_len
;
984 memcpy(app
.data
, zr
->jpg_settings
.jpg_comp
.APP_data
, 60);
985 zr
->codec
->control(zr
->codec
, CODEC_S_JPEG_APP_DATA
,
986 sizeof(struct jpeg_app_marker
), &app
);
988 com
.len
= zr
->jpg_settings
.jpg_comp
.COM_len
;
989 memcpy(com
.data
, zr
->jpg_settings
.jpg_comp
.COM_data
, 60);
990 zr
->codec
->control(zr
->codec
, CODEC_S_JPEG_COM_DATA
,
991 sizeof(struct jpeg_com_marker
), &com
);
993 /* Setup the JPEG codec */
994 zr
->codec
->control(zr
->codec
, CODEC_S_JPEG_TDS_BYTE
,
995 sizeof(int), &field_size
);
996 zr
->codec
->set_video(zr
->codec
, zr
->timing
, &cap
,
998 zr
->codec
->set_mode(zr
->codec
, CODEC_DO_COMPRESSION
);
1002 zr
->vfe
->control(zr
->vfe
, CODEC_S_JPEG_TDS_BYTE
,
1003 sizeof(int), &field_size
);
1004 zr
->vfe
->set_video(zr
->vfe
, zr
->timing
, &cap
,
1006 zr
->vfe
->set_mode(zr
->vfe
, CODEC_DO_COMPRESSION
);
1009 init_jpeg_queue(zr
);
1010 zr36057_set_jpg(zr
, mode
); // \P_Reset, ... Video param, FIFO
1012 clear_interrupt_counters(zr
);
1013 dprintk(2, KERN_INFO
"%s: enable_jpg(MOTION_COMPRESS)\n",
1018 case BUZ_MODE_MOTION_DECOMPRESS
:
1019 /* In motion decompression mode, the decoder output must be disabled, and
1020 * the video bus direction set to output.
1022 decoder_call(zr
, video
, s_stream
, 0);
1023 set_videobus_dir(zr
, 1);
1024 encoder_call(zr
, video
, s_routing
, 1, 0, 0);
1026 /* Take the JPEG codec and the VFE out of sleep */
1027 jpeg_codec_sleep(zr
, 0);
1030 zr
->vfe
->set_video(zr
->vfe
, zr
->timing
, &cap
,
1032 zr
->vfe
->set_mode(zr
->vfe
, CODEC_DO_EXPANSION
);
1034 /* Setup the JPEG codec */
1035 zr
->codec
->set_video(zr
->codec
, zr
->timing
, &cap
,
1037 zr
->codec
->set_mode(zr
->codec
, CODEC_DO_EXPANSION
);
1039 init_jpeg_queue(zr
);
1040 zr36057_set_jpg(zr
, mode
); // \P_Reset, ... Video param, FIFO
1042 clear_interrupt_counters(zr
);
1043 dprintk(2, KERN_INFO
"%s: enable_jpg(MOTION_DECOMPRESS)\n",
1049 /* shut down processing */
1050 btand(~(zr
->card
.jpeg_int
| ZR36057_ICR_JPEGRepIRQ
),
1052 btwrite(zr
->card
.jpeg_int
| ZR36057_ICR_JPEGRepIRQ
,
1054 btand(~ZR36057_JMC_Go_en
, ZR36057_JMC
); // \Go_en
1058 set_videobus_dir(zr
, 0);
1059 set_frame(zr
, 1); // /FRAME
1060 btor(ZR36057_MCTCR_CFlush
, ZR36057_MCTCR
); // /CFlush
1061 btwrite(0, ZR36057_JPC
); // \P_Reset,\CodTrnsEn,\Active
1062 btand(~ZR36057_JMC_VFIFO_FB
, ZR36057_JMC
);
1063 btand(~ZR36057_JMC_SyncMstr
, ZR36057_JMC
);
1064 jpeg_codec_reset(zr
);
1065 jpeg_codec_sleep(zr
, 1);
1066 zr36057_adjust_vfe(zr
, mode
);
1068 decoder_call(zr
, video
, s_stream
, 1);
1069 encoder_call(zr
, video
, s_routing
, 0, 0, 0);
1071 dprintk(2, KERN_INFO
"%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr
));
1077 /* when this is called the spinlock must be held */
1079 zoran_feed_stat_com (struct zoran
*zr
)
1081 /* move frames from pending queue to DMA */
1083 int frame
, i
, max_stat_com
;
1086 (zr
->jpg_settings
.TmpDcm
==
1087 1) ? BUZ_NUM_STAT_COM
: (BUZ_NUM_STAT_COM
>> 1);
1089 while ((zr
->jpg_dma_head
- zr
->jpg_dma_tail
) < max_stat_com
&&
1090 zr
->jpg_dma_head
< zr
->jpg_que_head
) {
1092 frame
= zr
->jpg_pend
[zr
->jpg_dma_head
& BUZ_MASK_FRAME
];
1093 if (zr
->jpg_settings
.TmpDcm
== 1) {
1094 /* fill 1 stat_com entry */
1095 i
= (zr
->jpg_dma_head
-
1096 zr
->jpg_err_shift
) & BUZ_MASK_STAT_COM
;
1097 if (!(zr
->stat_com
[i
] & cpu_to_le32(1)))
1100 cpu_to_le32(zr
->jpg_buffers
.buffer
[frame
].jpg
.frag_tab_bus
);
1102 /* fill 2 stat_com entries */
1103 i
= ((zr
->jpg_dma_head
-
1104 zr
->jpg_err_shift
) & 1) * 2;
1105 if (!(zr
->stat_com
[i
] & cpu_to_le32(1)))
1108 cpu_to_le32(zr
->jpg_buffers
.buffer
[frame
].jpg
.frag_tab_bus
);
1109 zr
->stat_com
[i
+ 1] =
1110 cpu_to_le32(zr
->jpg_buffers
.buffer
[frame
].jpg
.frag_tab_bus
);
1112 zr
->jpg_buffers
.buffer
[frame
].state
= BUZ_STATE_DMA
;
1116 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
)
1117 zr
->jpg_queued_num
++;
1120 /* when this is called the spinlock must be held */
1122 zoran_reap_stat_com (struct zoran
*zr
)
1124 /* move frames from DMA queue to done queue */
1130 struct zoran_buffer
*buffer
;
1133 /* In motion decompress we don't have a hardware frame counter,
1134 * we just count the interrupts here */
1136 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
) {
1139 while (zr
->jpg_dma_tail
< zr
->jpg_dma_head
) {
1140 if (zr
->jpg_settings
.TmpDcm
== 1)
1141 i
= (zr
->jpg_dma_tail
-
1142 zr
->jpg_err_shift
) & BUZ_MASK_STAT_COM
;
1144 i
= ((zr
->jpg_dma_tail
-
1145 zr
->jpg_err_shift
) & 1) * 2 + 1;
1147 stat_com
= le32_to_cpu(zr
->stat_com
[i
]);
1149 if ((stat_com
& 1) == 0) {
1152 frame
= zr
->jpg_pend
[zr
->jpg_dma_tail
& BUZ_MASK_FRAME
];
1153 buffer
= &zr
->jpg_buffers
.buffer
[frame
];
1154 v4l2_get_timestamp(&buffer
->bs
.timestamp
);
1156 if (zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
) {
1157 buffer
->bs
.length
= (stat_com
& 0x7fffff) >> 1;
1159 /* update sequence number with the help of the counter in stat_com */
1161 seq
= ((stat_com
>> 24) + zr
->jpg_err_seq
) & 0xff;
1162 dif
= (seq
- zr
->jpg_seq_num
) & 0xff;
1163 zr
->jpg_seq_num
+= dif
;
1165 buffer
->bs
.length
= 0;
1168 zr
->jpg_settings
.TmpDcm
==
1169 2 ? (zr
->jpg_seq_num
>> 1) : zr
->jpg_seq_num
;
1170 buffer
->state
= BUZ_STATE_DONE
;
1176 static void zoran_restart(struct zoran
*zr
)
1178 /* Now the stat_comm buffer is ready for restart */
1179 unsigned int status
= 0;
1182 if (zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
) {
1183 decoder_call(zr
, video
, g_input_status
, &status
);
1184 mode
= CODEC_DO_COMPRESSION
;
1186 status
= V4L2_IN_ST_NO_SIGNAL
;
1187 mode
= CODEC_DO_EXPANSION
;
1189 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
||
1190 !(status
& V4L2_IN_ST_NO_SIGNAL
)) {
1191 /********** RESTART code *************/
1192 jpeg_codec_reset(zr
);
1193 zr
->codec
->set_mode(zr
->codec
, mode
);
1194 zr36057_set_jpg(zr
, zr
->codec_mode
);
1197 if (zr
->num_errors
<= 8)
1198 dprintk(2, KERN_INFO
"%s: Restart\n",
1201 zr
->JPEG_missed
= 0;
1203 /********** End RESTART code ***********/
1208 error_handler (struct zoran
*zr
,
1214 /* This is JPEG error handling part */
1215 if (zr
->codec_mode
!= BUZ_MODE_MOTION_COMPRESS
&&
1216 zr
->codec_mode
!= BUZ_MODE_MOTION_DECOMPRESS
) {
1220 if ((stat
& 1) == 0 &&
1221 zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
&&
1222 zr
->jpg_dma_tail
- zr
->jpg_que_tail
>= zr
->jpg_buffers
.num_buffers
) {
1223 /* No free buffers... */
1224 zoran_reap_stat_com(zr
);
1225 zoran_feed_stat_com(zr
);
1226 wake_up_interruptible(&zr
->jpg_capq
);
1227 zr
->JPEG_missed
= 0;
1231 if (zr
->JPEG_error
== 1) {
1237 * First entry: error just happened during normal operation
1239 * In BUZ_MODE_MOTION_COMPRESS:
1241 * Possible glitch in TV signal. In this case we should
1242 * stop the codec and wait for good quality signal before
1243 * restarting it to avoid further problems
1245 * In BUZ_MODE_MOTION_DECOMPRESS:
1247 * Bad JPEG frame: we have to mark it as processed (codec crashed
1248 * and was not able to do it itself), and to remove it from queue.
1250 btand(~ZR36057_JMC_Go_en
, ZR36057_JMC
);
1252 stat
= stat
| (post_office_read(zr
, 7, 0) & 3) << 8;
1253 btwrite(0, ZR36057_JPC
);
1254 btor(ZR36057_MCTCR_CFlush
, ZR36057_MCTCR
);
1255 jpeg_codec_reset(zr
);
1256 jpeg_codec_sleep(zr
, 1);
1261 if (zr36067_debug
> 1 && zr
->num_errors
<= 8) {
1265 frame
= zr
->jpg_pend
[zr
->jpg_dma_tail
& BUZ_MASK_FRAME
];
1267 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1268 ZR_DEVNAME(zr
), stat
, zr
->last_isr
,
1269 zr
->jpg_que_tail
, zr
->jpg_dma_tail
,
1270 zr
->jpg_dma_head
, zr
->jpg_que_head
,
1271 zr
->jpg_seq_num
, frame
);
1272 printk(KERN_INFO
"stat_com frames:");
1273 for (j
= 0; j
< BUZ_NUM_STAT_COM
; j
++) {
1274 for (i
= 0; i
< zr
->jpg_buffers
.num_buffers
; i
++) {
1275 if (le32_to_cpu(zr
->stat_com
[j
]) == zr
->jpg_buffers
.buffer
[i
].jpg
.frag_tab_bus
)
1276 printk(KERN_CONT
"% d->%d", j
, i
);
1279 printk(KERN_CONT
"\n");
1281 /* Find an entry in stat_com and rotate contents */
1282 if (zr
->jpg_settings
.TmpDcm
== 1)
1283 i
= (zr
->jpg_dma_tail
- zr
->jpg_err_shift
) & BUZ_MASK_STAT_COM
;
1285 i
= ((zr
->jpg_dma_tail
- zr
->jpg_err_shift
) & 1) * 2;
1286 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
) {
1287 /* Mimic zr36067 operation */
1288 zr
->stat_com
[i
] |= cpu_to_le32(1);
1289 if (zr
->jpg_settings
.TmpDcm
!= 1)
1290 zr
->stat_com
[i
+ 1] |= cpu_to_le32(1);
1292 zoran_reap_stat_com(zr
);
1293 zoran_feed_stat_com(zr
);
1294 wake_up_interruptible(&zr
->jpg_capq
);
1295 /* Find an entry in stat_com again after refill */
1296 if (zr
->jpg_settings
.TmpDcm
== 1)
1297 i
= (zr
->jpg_dma_tail
- zr
->jpg_err_shift
) & BUZ_MASK_STAT_COM
;
1299 i
= ((zr
->jpg_dma_tail
- zr
->jpg_err_shift
) & 1) * 2;
1302 /* Rotate stat_comm entries to make current entry first */
1304 __le32 bus_addr
[BUZ_NUM_STAT_COM
];
1306 /* Here we are copying the stat_com array, which
1307 * is already in little endian format, so
1308 * no endian conversions here
1310 memcpy(bus_addr
, zr
->stat_com
, sizeof(bus_addr
));
1312 for (j
= 0; j
< BUZ_NUM_STAT_COM
; j
++)
1313 zr
->stat_com
[j
] = bus_addr
[(i
+ j
) & BUZ_MASK_STAT_COM
];
1315 zr
->jpg_err_shift
+= i
;
1316 zr
->jpg_err_shift
&= BUZ_MASK_STAT_COM
;
1318 if (zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
)
1319 zr
->jpg_err_seq
= zr
->jpg_seq_num
; /* + 1; */
1330 unsigned long flags
;
1336 /* Testing interrupts */
1337 spin_lock_irqsave(&zr
->spinlock
, flags
);
1338 while ((stat
= count_reset_interrupt(zr
))) {
1339 if (count
++ > 100) {
1340 btand(~ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1343 "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
1344 ZR_DEVNAME(zr
), stat
);
1345 wake_up_interruptible(&zr
->test_q
);
1348 zr
->last_isr
= stat
;
1349 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1353 spin_lock_irqsave(&zr
->spinlock
, flags
);
1355 /* get/clear interrupt status bits */
1356 stat
= count_reset_interrupt(zr
);
1357 astat
= stat
& IRQ_MASK
;
1363 "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
1364 astat
, btread(ZR36057_ICR
));
1365 if (astat
& zr
->card
.vsync_int
) { // SW
1367 if (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
||
1368 zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
) {
1369 /* count missed interrupts */
1372 //post_office_read(zr,1,0);
1373 /* Interrupts may still happen when
1374 * zr->v4l_memgrab_active is switched off.
1375 * We simply ignore them */
1377 if (zr
->v4l_memgrab_active
) {
1378 /* A lot more checks should be here ... */
1379 if ((btread(ZR36057_VSSFGR
) & ZR36057_VSSFGR_SnapShot
) == 0)
1382 "%s: BuzIRQ with SnapShot off ???\n",
1385 if (zr
->v4l_grab_frame
!= NO_GRAB_ACTIVE
) {
1386 /* There is a grab on a frame going on, check if it has finished */
1387 if ((btread(ZR36057_VSSFGR
) & ZR36057_VSSFGR_FrameGrab
) == 0) {
1388 /* it is finished, notify the user */
1390 zr
->v4l_buffers
.buffer
[zr
->v4l_grab_frame
].state
= BUZ_STATE_DONE
;
1391 zr
->v4l_buffers
.buffer
[zr
->v4l_grab_frame
].bs
.seq
= zr
->v4l_grab_seq
;
1392 v4l2_get_timestamp(&zr
->v4l_buffers
.buffer
[zr
->v4l_grab_frame
].bs
.timestamp
);
1393 zr
->v4l_grab_frame
= NO_GRAB_ACTIVE
;
1394 zr
->v4l_pend_tail
++;
1398 if (zr
->v4l_grab_frame
== NO_GRAB_ACTIVE
)
1399 wake_up_interruptible(&zr
->v4l_capq
);
1401 /* Check if there is another grab queued */
1403 if (zr
->v4l_grab_frame
== NO_GRAB_ACTIVE
&&
1404 zr
->v4l_pend_tail
!= zr
->v4l_pend_head
) {
1405 int frame
= zr
->v4l_pend
[zr
->v4l_pend_tail
& V4L_MASK_FRAME
];
1408 zr
->v4l_grab_frame
= frame
;
1410 /* Set zr36057 video front end and enable video */
1412 /* Buffer address */
1414 reg
= zr
->v4l_buffers
.buffer
[frame
].v4l
.fbuffer_bus
;
1415 btwrite(reg
, ZR36057_VDTR
);
1416 if (zr
->v4l_settings
.height
> BUZ_MAX_HEIGHT
/ 2)
1417 reg
+= zr
->v4l_settings
.bytesperline
;
1418 btwrite(reg
, ZR36057_VDBR
);
1420 /* video stride, status, and frame grab register */
1422 if (zr
->v4l_settings
.height
> BUZ_MAX_HEIGHT
/ 2)
1423 reg
+= zr
->v4l_settings
.bytesperline
;
1424 reg
= (reg
<< ZR36057_VSSFGR_DispStride
);
1425 reg
|= ZR36057_VSSFGR_VidOvf
;
1426 reg
|= ZR36057_VSSFGR_SnapShot
;
1427 reg
|= ZR36057_VSSFGR_FrameGrab
;
1428 btwrite(reg
, ZR36057_VSSFGR
);
1430 btor(ZR36057_VDCR_VidEn
,
1435 /* even if we don't grab, we do want to increment
1436 * the sequence counter to see lost frames */
1439 #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1440 if (astat
& ZR36057_ISR_CodRepIRQ
) {
1441 zr
->intr_counter_CodRepIRQ
++;
1442 IDEBUG(printk(KERN_DEBUG
"%s: ZR36057_ISR_CodRepIRQ\n",
1444 btand(~ZR36057_ICR_CodRepIRQ
, ZR36057_ICR
);
1446 #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
1448 #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1449 if ((astat
& ZR36057_ISR_JPEGRepIRQ
) &&
1450 (zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
||
1451 zr
->codec_mode
== BUZ_MODE_MOTION_COMPRESS
)) {
1452 if (zr36067_debug
> 1 && (!zr
->frame_num
|| zr
->JPEG_error
)) {
1453 char sv
[BUZ_NUM_STAT_COM
+ 1];
1457 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1458 ZR_DEVNAME(zr
), stat
,
1459 zr
->jpg_settings
.odd_even
,
1460 zr
->jpg_settings
.field_per_buff
,
1463 for (i
= 0; i
< BUZ_NUM_STAT_COM
; i
++)
1464 sv
[i
] = le32_to_cpu(zr
->stat_com
[i
]) & 1 ? '1' : '0';
1465 sv
[BUZ_NUM_STAT_COM
] = 0;
1467 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1474 /* Get statistics */
1475 if (zr
->JPEG_missed
> zr
->JPEG_max_missed
)
1476 zr
->JPEG_max_missed
= zr
->JPEG_missed
;
1477 if (zr
->JPEG_missed
< zr
->JPEG_min_missed
)
1478 zr
->JPEG_min_missed
= zr
->JPEG_missed
;
1481 if (zr36067_debug
> 2 && zr
->frame_num
< 6) {
1484 printk(KERN_INFO
"%s: seq=%ld stat_com:",
1485 ZR_DEVNAME(zr
), zr
->jpg_seq_num
);
1486 for (i
= 0; i
< 4; i
++) {
1487 printk(KERN_CONT
" %08x",
1488 le32_to_cpu(zr
->stat_com
[i
]));
1490 printk(KERN_CONT
"\n");
1493 zr
->JPEG_missed
= 0;
1495 zoran_reap_stat_com(zr
);
1496 zoran_feed_stat_com(zr
);
1497 wake_up_interruptible(&zr
->jpg_capq
);
1499 #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
1501 /* DATERR, too many fields missed, error processing */
1502 if ((astat
& zr
->card
.jpeg_int
) ||
1503 zr
->JPEG_missed
> 25 ||
1504 zr
->JPEG_error
== 1 ||
1505 ((zr
->codec_mode
== BUZ_MODE_MOTION_DECOMPRESS
) &&
1506 (zr
->frame_num
&& (zr
->JPEG_missed
> zr
->jpg_settings
.field_per_buff
)))) {
1507 error_handler(zr
, astat
, stat
);
1512 dprintk(2, KERN_WARNING
"%s: irq loop %d\n",
1513 ZR_DEVNAME(zr
), count
);
1515 btand(~ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1518 "%s: IRQ lockup, cleared int mask\n",
1523 zr
->last_isr
= stat
;
1525 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1531 zoran_set_pci_master (struct zoran
*zr
,
1535 pci_set_master(zr
->pci_dev
);
1539 pci_read_config_word(zr
->pci_dev
, PCI_COMMAND
, &command
);
1540 command
&= ~PCI_COMMAND_MASTER
;
1541 pci_write_config_word(zr
->pci_dev
, PCI_COMMAND
, command
);
1546 zoran_init_hardware (struct zoran
*zr
)
1548 /* Enable bus-mastering */
1549 zoran_set_pci_master(zr
, 1);
1551 /* Initialize the board */
1552 if (zr
->card
.init
) {
1556 decoder_call(zr
, core
, init
, 0);
1557 decoder_call(zr
, video
, s_std
, zr
->norm
);
1558 decoder_call(zr
, video
, s_routing
,
1559 zr
->card
.input
[zr
->input
].muxsel
, 0, 0);
1561 encoder_call(zr
, core
, init
, 0);
1562 encoder_call(zr
, video
, s_std_output
, zr
->norm
);
1563 encoder_call(zr
, video
, s_routing
, 0, 0, 0);
1565 /* toggle JPEG codec sleep to sync PLL */
1566 jpeg_codec_sleep(zr
, 1);
1567 jpeg_codec_sleep(zr
, 0);
1570 * set individual interrupt enables (without GIRQ1)
1571 * but don't global enable until zoran_open()
1573 zr36057_init_vfe(zr
);
1575 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1577 btwrite(IRQ_MASK
, ZR36057_ISR
); // Clears interrupts
1581 zr36057_restart (struct zoran
*zr
)
1583 btwrite(0, ZR36057_SPGPPCR
);
1585 btor(ZR36057_SPGPPCR_SoftReset
, ZR36057_SPGPPCR
);
1588 /* assert P_Reset */
1589 btwrite(0, ZR36057_JPC
);
1590 /* set up GPIO direction - all output */
1591 btwrite(ZR36057_SPGPPCR_SoftReset
| 0, ZR36057_SPGPPCR
);
1593 /* set up GPIO pins and guest bus timing */
1594 btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1
);
1598 * initialize video front end
1602 zr36057_init_vfe (struct zoran
*zr
)
1606 reg
= btread(ZR36057_VFESPFR
);
1607 reg
|= ZR36057_VFESPFR_LittleEndian
;
1608 reg
&= ~ZR36057_VFESPFR_VCLKPol
;
1609 reg
|= ZR36057_VFESPFR_ExtFl
;
1610 reg
|= ZR36057_VFESPFR_TopField
;
1611 btwrite(reg
, ZR36057_VFESPFR
);
1612 reg
= btread(ZR36057_VDCR
);
1613 if (pci_pci_problems
& PCIPCI_TRITON
)
1614 // || zr->revision < 1) // Revision 1 has also Triton support
1615 reg
&= ~ZR36057_VDCR_Triton
;
1617 reg
|= ZR36057_VDCR_Triton
;
1618 btwrite(reg
, ZR36057_VDCR
);