]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/video/zr364xx.c
V4L/DVB (9074): gspca: sonixj webcam 0c45:60fe added.
[linux-2.6-omap-h63xx.git] / drivers / media / video / zr364xx.c
index 617ed2856b22412c324a83ad1522494a0965275a..93991cb9ca713b9ae1b5e96a544f1c4ce22a61e5 100644 (file)
@@ -116,6 +116,7 @@ struct zr364xx_camera {
        int height;
        int method;
        struct mutex lock;
+       int users;
 };
 
 
@@ -641,21 +642,22 @@ static int zr364xx_open(struct inode *inode, struct file *file)
 
        DBG("zr364xx_open");
 
-       cam->skip = 2;
+       mutex_lock(&cam->lock);
 
-       err = video_exclusive_open(inode, file);
-       if (err < 0)
-               return err;
+       if (cam->users) {
+               err = -EBUSY;
+               goto out;
+       }
 
        if (!cam->framebuf) {
                cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES);
                if (!cam->framebuf) {
                        info("vmalloc_32 failed!");
-                       return -ENOMEM;
+                       err = -ENOMEM;
+                       goto out;
                }
        }
 
-       mutex_lock(&cam->lock);
        for (i = 0; init[cam->method][i].size != -1; i++) {
                err =
                    send_control_msg(udev, 1, init[cam->method][i].value,
@@ -663,20 +665,23 @@ static int zr364xx_open(struct inode *inode, struct file *file)
                                     init[cam->method][i].size);
                if (err < 0) {
                        info("error during open sequence: %d", i);
-                       mutex_unlock(&cam->lock);
-                       return err;
+                       goto out;
                }
        }
 
+       cam->skip = 2;
+       cam->users++;
        file->private_data = vdev;
 
        /* Added some delay here, since opening/closing the camera quickly,
         * like Ekiga does during its startup, can crash the webcam
         */
        mdelay(100);
+       err = 0;
 
+out:
        mutex_unlock(&cam->lock);
-       return 0;
+       return err;
 }
 
 
@@ -697,6 +702,10 @@ static int zr364xx_release(struct inode *inode, struct file *file)
        udev = cam->udev;
 
        mutex_lock(&cam->lock);
+
+       cam->users--;
+       file->private_data = NULL;
+
        for (i = 0; i < 2; i++) {
                err =
                    send_control_msg(udev, 1, init[cam->method][i].value,
@@ -704,21 +713,19 @@ static int zr364xx_release(struct inode *inode, struct file *file)
                                     init[cam->method][i].size);
                if (err < 0) {
                        info("error during release sequence");
-                       mutex_unlock(&cam->lock);
-                       return err;
+                       goto out;
                }
        }
 
-       file->private_data = NULL;
-       video_exclusive_release(inode, file);
-
        /* Added some delay here, since opening/closing the camera quickly,
         * like Ekiga does during its startup, can crash the webcam
         */
        mdelay(100);
+       err = 0;
 
+out:
        mutex_unlock(&cam->lock);
-       return 0;
+       return err;
 }
 
 
@@ -779,9 +786,7 @@ static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = {
 };
 
 static struct video_device zr364xx_template = {
-       .owner = THIS_MODULE,
        .name = DRIVER_DESC,
-       .type = VID_TYPE_CAPTURE,
        .fops = &zr364xx_fops,
        .ioctl_ops = &zr364xx_ioctl_ops,
        .release = video_device_release,