V4L/DVB (5891): zr36067: Turn off raw capture properly
authorTrent Piepho <xyzzy@speakeasy.org>
Tue, 17 Jul 2007 21:29:45 +0000 (18:29 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Mon, 30 Jul 2007 19:26:26 +0000 (16:26 -0300)
When raw capture was turned off, the current capturing frame (v4l_grab_frame)
wasn't reset to NO_GRAB_ACTIVE.  If capture was turned back on, the driver
would think this frame was currently being captured, and wait for it to
complete before starting a new frame.  The hardware on the other hand would
not be actively capturing a frame.  The result was the driver would wait
forever for v4l_grab_frame to be captured.

Some calls to zr36057_set_memgrab(0) were missing spin-locks, which have been
added.

Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Acked-by: Ronald S. Bultje <rbultje@ronald.bitfreak.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/video/zoran_device.c
drivers/media/video/zoran_driver.c

index d9640ec4b9b0389264ed5c1f661cb48c565f5d0c..ba2f4ed294836586fe36e8560ab54e5cc6389918 100644 (file)
@@ -620,11 +620,17 @@ zr36057_set_memgrab (struct zoran *zr,
                     int           mode)
 {
        if (mode) {
-               if (btread(ZR36057_VSSFGR) &
-                   (ZR36057_VSSFGR_SnapShot | ZR36057_VSSFGR_FrameGrab))
+               /* We only check SnapShot and not FrameGrab here.  SnapShot==1
+                * means a capture is already in progress, but FrameGrab==1
+                * doesn't necessary mean that.  It's more correct to say a 1
+                * to 0 transition indicates a capture completed.  If a
+                * capture is pending when capturing is tuned off, FrameGrab
+                * will be stuck at 1 until capturing is turned back on.
+                */
+               if (btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot)
                        dprintk(1,
                                KERN_WARNING
-                               "%s: zr36057_set_memgrab(1) with SnapShot or FrameGrab on!?\n",
+                               "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
                                ZR_DEVNAME(zr));
 
                /* switch on VSync interrupts */
@@ -641,11 +647,12 @@ zr36057_set_memgrab (struct zoran *zr,
 
                zr->v4l_memgrab_active = 1;
        } else {
-               zr->v4l_memgrab_active = 0;
-
                /* switch off VSync interrupts */
                btand(~zr->card.vsync_int, ZR36057_ICR);        // SW
 
+               zr->v4l_memgrab_active = 0;
+               zr->v4l_grab_frame = NO_GRAB_ACTIVE;
+
                /* reenable grabbing to screen if it was running */
                if (zr->v4l_overlay_active) {
                        zr36057_overlay(zr, 1);
index ec9ae6c61bd5af7b9823f7f552ed677641ba1364..72a037b75d63af058f8a7869eca4bb4a8c8af824 100644 (file)
@@ -1188,10 +1188,14 @@ zoran_close_end_session (struct file *file)
 
        /* v4l capture */
        if (fh->v4l_buffers.active != ZORAN_FREE) {
+               long flags;
+
+               spin_lock_irqsave(&zr->spinlock, flags);
                zr36057_set_memgrab(zr, 0);
                zr->v4l_buffers.allocated = 0;
                zr->v4l_buffers.active = fh->v4l_buffers.active =
                    ZORAN_FREE;
+               spin_unlock_irqrestore(&zr->spinlock, flags);
        }
 
        /* v4l buffers */
@@ -3456,8 +3460,13 @@ zoran_do_ioctl (struct inode *inode,
                                goto strmoff_unlock_and_return;
 
                        /* unload capture */
-                       if (zr->v4l_memgrab_active)
+                       if (zr->v4l_memgrab_active) {
+                               long flags;
+
+                               spin_lock_irqsave(&zr->spinlock, flags);
                                zr36057_set_memgrab(zr, 0);
+                               spin_unlock_irqrestore(&zr->spinlock, flags);
+                       }
 
                        for (i = 0; i < fh->v4l_buffers.num_buffers; i++)
                                zr->v4l_buffers.buffer[i].state =
@@ -4392,11 +4401,15 @@ zoran_vm_close (struct vm_area_struct *vma)
                                mutex_lock(&zr->resource_lock);
 
                                if (fh->v4l_buffers.active != ZORAN_FREE) {
+                                       long flags;
+
+                                       spin_lock_irqsave(&zr->spinlock, flags);
                                        zr36057_set_memgrab(zr, 0);
                                        zr->v4l_buffers.allocated = 0;
                                        zr->v4l_buffers.active =
                                            fh->v4l_buffers.active =
                                            ZORAN_FREE;
+                                       spin_unlock_irqrestore(&zr->spinlock, flags);
                                }
                                //v4l_fbuffer_free(file);
                                fh->v4l_buffers.allocated = 0;