aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/gspca.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/gspca/gspca.c')
-rw-r--r--drivers/media/video/gspca/gspca.c210
1 files changed, 128 insertions, 82 deletions
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index 02a6e9ef0337..8b9f3bde5740 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -30,7 +30,6 @@
30#include <linux/string.h> 30#include <linux/string.h>
31#include <linux/pagemap.h> 31#include <linux/pagemap.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/kref.h>
34#include <asm/page.h> 33#include <asm/page.h>
35#include <linux/uaccess.h> 34#include <linux/uaccess.h>
36#include <linux/jiffies.h> 35#include <linux/jiffies.h>
@@ -45,7 +44,7 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
45MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 44MODULE_DESCRIPTION("GSPCA USB Camera Driver");
46MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
47 46
48#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 3, 0) 47#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 4, 0)
49 48
50static int video_nr = -1; 49static int video_nr = -1;
51 50
@@ -150,8 +149,11 @@ static void fill_frame(struct gspca_dev *gspca_dev,
150 149
151 /* check the packet status and length */ 150 /* check the packet status and length */
152 len = urb->iso_frame_desc[i].actual_length; 151 len = urb->iso_frame_desc[i].actual_length;
153 if (len == 0) 152 if (len == 0) {
153 if (gspca_dev->empty_packet == 0)
154 gspca_dev->empty_packet = 1;
154 continue; 155 continue;
156 }
155 st = urb->iso_frame_desc[i].status; 157 st = urb->iso_frame_desc[i].status;
156 if (st) { 158 if (st) {
157 PDEBUG(D_ERR, 159 PDEBUG(D_ERR,
@@ -170,7 +172,6 @@ static void fill_frame(struct gspca_dev *gspca_dev,
170 } 172 }
171 173
172 /* resubmit the URB */ 174 /* resubmit the URB */
173 urb->status = 0;
174 st = usb_submit_urb(urb, GFP_ATOMIC); 175 st = usb_submit_urb(urb, GFP_ATOMIC);
175 if (st < 0) 176 if (st < 0)
176 PDEBUG(D_ERR|D_PACK, "usb_submit_urb() ret %d", st); 177 PDEBUG(D_ERR|D_PACK, "usb_submit_urb() ret %d", st);
@@ -200,11 +201,18 @@ static void bulk_irq(struct urb *urb
200{ 201{
201 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; 202 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
202 struct gspca_frame *frame; 203 struct gspca_frame *frame;
204 int st;
203 205
204 PDEBUG(D_PACK, "bulk irq"); 206 PDEBUG(D_PACK, "bulk irq");
205 if (!gspca_dev->streaming) 207 if (!gspca_dev->streaming)
206 return; 208 return;
207 if (urb->status != 0 && urb->status != -ECONNRESET) { 209 switch (urb->status) {
210 case 0:
211 break;
212 case -ECONNRESET:
213 urb->status = 0;
214 break;
215 default:
208#ifdef CONFIG_PM 216#ifdef CONFIG_PM
209 if (!gspca_dev->frozen) 217 if (!gspca_dev->frozen)
210#endif 218#endif
@@ -223,6 +231,13 @@ static void bulk_irq(struct urb *urb
223 urb->transfer_buffer, 231 urb->transfer_buffer,
224 urb->actual_length); 232 urb->actual_length);
225 } 233 }
234
235 /* resubmit the URB */
236 if (gspca_dev->cam.bulk_nurbs != 0) {
237 st = usb_submit_urb(urb, GFP_ATOMIC);
238 if (st < 0)
239 PDEBUG(D_ERR|D_PACK, "usb_submit_urb() ret %d", st);
240 }
226} 241}
227 242
228/* 243/*
@@ -285,7 +300,6 @@ struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
285 frame->v4l2_buf.bytesused = frame->data_end - frame->data; 300 frame->v4l2_buf.bytesused = frame->data_end - frame->data;
286 frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED; 301 frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED;
287 frame->v4l2_buf.flags |= V4L2_BUF_FLAG_DONE; 302 frame->v4l2_buf.flags |= V4L2_BUF_FLAG_DONE;
288 atomic_inc(&gspca_dev->nevent);
289 wake_up_interruptible(&gspca_dev->wq); /* event = new frame */ 303 wake_up_interruptible(&gspca_dev->wq); /* event = new frame */
290 i = (gspca_dev->fr_i + 1) % gspca_dev->nframes; 304 i = (gspca_dev->fr_i + 1) % gspca_dev->nframes;
291 gspca_dev->fr_i = i; 305 gspca_dev->fr_i = i;
@@ -379,7 +393,6 @@ static int frame_alloc(struct gspca_dev *gspca_dev,
379 gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; 393 gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0;
380 gspca_dev->last_packet_type = DISCARD_PACKET; 394 gspca_dev->last_packet_type = DISCARD_PACKET;
381 gspca_dev->sequence = 0; 395 gspca_dev->sequence = 0;
382 atomic_set(&gspca_dev->nevent, 0);
383 return 0; 396 return 0;
384} 397}
385 398
@@ -520,11 +533,14 @@ static int create_urbs(struct gspca_dev *gspca_dev,
520 nurbs = DEF_NURBS; 533 nurbs = DEF_NURBS;
521 } else { /* bulk */ 534 } else { /* bulk */
522 npkt = 0; 535 npkt = 0;
523 bsize = gspca_dev->cam. bulk_size; 536 bsize = gspca_dev->cam.bulk_size;
524 if (bsize == 0) 537 if (bsize == 0)
525 bsize = psize; 538 bsize = psize;
526 PDEBUG(D_STREAM, "bulk bsize:%d", bsize); 539 PDEBUG(D_STREAM, "bulk bsize:%d", bsize);
527 nurbs = 1; 540 if (gspca_dev->cam.bulk_nurbs != 0)
541 nurbs = gspca_dev->cam.bulk_nurbs;
542 else
543 nurbs = 1;
528 } 544 }
529 545
530 gspca_dev->nurbs = nurbs; 546 gspca_dev->nurbs = nurbs;
@@ -597,6 +613,12 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
597 if (ret < 0) 613 if (ret < 0)
598 goto out; 614 goto out;
599 615
616 /* clear the bulk endpoint */
617 if (gspca_dev->alt == 0) /* if bulk transfer */
618 usb_clear_halt(gspca_dev->dev,
619 usb_rcvintpipe(gspca_dev->dev,
620 gspca_dev->cam.epaddr));
621
600 /* start the cam */ 622 /* start the cam */
601 ret = gspca_dev->sd_desc->start(gspca_dev); 623 ret = gspca_dev->sd_desc->start(gspca_dev);
602 if (ret < 0) { 624 if (ret < 0) {
@@ -604,10 +626,9 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
604 goto out; 626 goto out;
605 } 627 }
606 gspca_dev->streaming = 1; 628 gspca_dev->streaming = 1;
607 atomic_set(&gspca_dev->nevent, 0);
608 629
609 /* bulk transfers are started by the subdriver */ 630 /* some bulk transfers are started by the subdriver */
610 if (gspca_dev->alt == 0) 631 if (gspca_dev->alt == 0 && gspca_dev->cam.bulk_nurbs == 0)
611 break; 632 break;
612 633
613 /* submit the URBs */ 634 /* submit the URBs */
@@ -618,8 +639,11 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
618 "usb_submit_urb [%d] err %d", n, ret); 639 "usb_submit_urb [%d] err %d", n, ret);
619 gspca_dev->streaming = 0; 640 gspca_dev->streaming = 0;
620 destroy_urbs(gspca_dev); 641 destroy_urbs(gspca_dev);
621 if (ret == -ENOSPC) 642 if (ret == -ENOSPC) {
643 msleep(20); /* wait for kill
644 * complete */
622 break; /* try the previous alt */ 645 break; /* try the previous alt */
646 }
623 goto out; 647 goto out;
624 } 648 }
625 } 649 }
@@ -637,7 +661,7 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev)
637 661
638 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0); 662 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0);
639 if (ret < 0) 663 if (ret < 0)
640 PDEBUG(D_ERR|D_STREAM, "set interface 0 err %d", ret); 664 PDEBUG(D_ERR|D_STREAM, "set alt 0 err %d", ret);
641 return ret; 665 return ret;
642} 666}
643 667
@@ -645,7 +669,6 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev)
645static void gspca_stream_off(struct gspca_dev *gspca_dev) 669static void gspca_stream_off(struct gspca_dev *gspca_dev)
646{ 670{
647 gspca_dev->streaming = 0; 671 gspca_dev->streaming = 0;
648 atomic_set(&gspca_dev->nevent, 0);
649 if (gspca_dev->present 672 if (gspca_dev->present
650 && gspca_dev->sd_desc->stopN) 673 && gspca_dev->sd_desc->stopN)
651 gspca_dev->sd_desc->stopN(gspca_dev); 674 gspca_dev->sd_desc->stopN(gspca_dev);
@@ -727,7 +750,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
727 if (fmtdesc->index == index) 750 if (fmtdesc->index == index)
728 break; /* new format */ 751 break; /* new format */
729 index++; 752 index++;
730 if (index >= sizeof fmt_tb / sizeof fmt_tb[0]) 753 if (index >= ARRAY_SIZE(fmt_tb))
731 return -EINVAL; 754 return -EINVAL;
732 } 755 }
733 } 756 }
@@ -752,8 +775,6 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
752 struct gspca_dev *gspca_dev = priv; 775 struct gspca_dev *gspca_dev = priv;
753 int mode; 776 int mode;
754 777
755 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
756 return -EINVAL;
757 mode = gspca_dev->curr_mode; 778 mode = gspca_dev->curr_mode;
758 memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode], 779 memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode],
759 sizeof fmt->fmt.pix); 780 sizeof fmt->fmt.pix);
@@ -765,8 +786,6 @@ static int try_fmt_vid_cap(struct gspca_dev *gspca_dev,
765{ 786{
766 int w, h, mode, mode2; 787 int w, h, mode, mode2;
767 788
768 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
769 return -EINVAL;
770 w = fmt->fmt.pix.width; 789 w = fmt->fmt.pix.width;
771 h = fmt->fmt.pix.height; 790 h = fmt->fmt.pix.height;
772 791
@@ -846,11 +865,11 @@ out:
846 return ret; 865 return ret;
847} 866}
848 867
849static void gspca_delete(struct kref *kref) 868static void gspca_release(struct video_device *vfd)
850{ 869{
851 struct gspca_dev *gspca_dev = container_of(kref, struct gspca_dev, kref); 870 struct gspca_dev *gspca_dev = container_of(vfd, struct gspca_dev, vdev);
852 871
853 PDEBUG(D_STREAM, "device deleted"); 872 PDEBUG(D_STREAM, "device released");
854 873
855 kfree(gspca_dev->usb_buf); 874 kfree(gspca_dev->usb_buf);
856 kfree(gspca_dev); 875 kfree(gspca_dev);
@@ -862,7 +881,7 @@ static int dev_open(struct inode *inode, struct file *file)
862 int ret; 881 int ret;
863 882
864 PDEBUG(D_STREAM, "%s open", current->comm); 883 PDEBUG(D_STREAM, "%s open", current->comm);
865 gspca_dev = video_drvdata(file); 884 gspca_dev = (struct gspca_dev *) video_devdata(file);
866 if (mutex_lock_interruptible(&gspca_dev->queue_lock)) 885 if (mutex_lock_interruptible(&gspca_dev->queue_lock))
867 return -ERESTARTSYS; 886 return -ERESTARTSYS;
868 if (!gspca_dev->present) { 887 if (!gspca_dev->present) {
@@ -883,17 +902,14 @@ static int dev_open(struct inode *inode, struct file *file)
883 902
884 gspca_dev->users++; 903 gspca_dev->users++;
885 904
886 /* one more user */
887 kref_get(&gspca_dev->kref);
888
889 file->private_data = gspca_dev; 905 file->private_data = gspca_dev;
890#ifdef GSPCA_DEBUG 906#ifdef GSPCA_DEBUG
891 /* activate the v4l2 debug */ 907 /* activate the v4l2 debug */
892 if (gspca_debug & D_V4L2) 908 if (gspca_debug & D_V4L2)
893 gspca_dev->vdev->debug |= V4L2_DEBUG_IOCTL 909 gspca_dev->vdev.debug |= V4L2_DEBUG_IOCTL
894 | V4L2_DEBUG_IOCTL_ARG; 910 | V4L2_DEBUG_IOCTL_ARG;
895 else 911 else
896 gspca_dev->vdev->debug &= ~(V4L2_DEBUG_IOCTL 912 gspca_dev->vdev.debug &= ~(V4L2_DEBUG_IOCTL
897 | V4L2_DEBUG_IOCTL_ARG); 913 | V4L2_DEBUG_IOCTL_ARG);
898#endif 914#endif
899 ret = 0; 915 ret = 0;
@@ -932,8 +948,6 @@ static int dev_close(struct inode *inode, struct file *file)
932 948
933 PDEBUG(D_STREAM, "close done"); 949 PDEBUG(D_STREAM, "close done");
934 950
935 kref_put(&gspca_dev->kref, gspca_delete);
936
937 return 0; 951 return 0;
938} 952}
939 953
@@ -1053,6 +1067,35 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1053 return -EINVAL; 1067 return -EINVAL;
1054} 1068}
1055 1069
1070/*fixme: have an audio flag in gspca_dev?*/
1071static int vidioc_s_audio(struct file *file, void *priv,
1072 struct v4l2_audio *audio)
1073{
1074 if (audio->index != 0)
1075 return -EINVAL;
1076 return 0;
1077}
1078
1079static int vidioc_g_audio(struct file *file, void *priv,
1080 struct v4l2_audio *audio)
1081{
1082 memset(audio, 0, sizeof *audio);
1083 strcpy(audio->name, "Microphone");
1084 return 0;
1085}
1086
1087static int vidioc_enumaudio(struct file *file, void *priv,
1088 struct v4l2_audio *audio)
1089{
1090 if (audio->index != 0)
1091 return -EINVAL;
1092
1093 strcpy(audio->name, "Microphone");
1094 audio->capability = 0;
1095 audio->mode = 0;
1096 return 0;
1097}
1098
1056static int vidioc_querymenu(struct file *file, void *priv, 1099static int vidioc_querymenu(struct file *file, void *priv,
1057 struct v4l2_querymenu *qmenu) 1100 struct v4l2_querymenu *qmenu)
1058{ 1101{
@@ -1096,8 +1139,6 @@ static int vidioc_reqbufs(struct file *file, void *priv,
1096 struct gspca_dev *gspca_dev = priv; 1139 struct gspca_dev *gspca_dev = priv;
1097 int i, ret = 0; 1140 int i, ret = 0;
1098 1141
1099 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1100 return -EINVAL;
1101 switch (rb->memory) { 1142 switch (rb->memory) {
1102 case GSPCA_MEMORY_READ: /* (internal call) */ 1143 case GSPCA_MEMORY_READ: /* (internal call) */
1103 case V4L2_MEMORY_MMAP: 1144 case V4L2_MEMORY_MMAP:
@@ -1162,8 +1203,7 @@ static int vidioc_querybuf(struct file *file, void *priv,
1162 struct gspca_dev *gspca_dev = priv; 1203 struct gspca_dev *gspca_dev = priv;
1163 struct gspca_frame *frame; 1204 struct gspca_frame *frame;
1164 1205
1165 if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE 1206 if (v4l2_buf->index < 0
1166 || v4l2_buf->index < 0
1167 || v4l2_buf->index >= gspca_dev->nframes) 1207 || v4l2_buf->index >= gspca_dev->nframes)
1168 return -EINVAL; 1208 return -EINVAL;
1169 1209
@@ -1186,7 +1226,8 @@ static int vidioc_streamon(struct file *file, void *priv,
1186 ret = -ENODEV; 1226 ret = -ENODEV;
1187 goto out; 1227 goto out;
1188 } 1228 }
1189 if (gspca_dev->nframes == 0) { 1229 if (gspca_dev->nframes == 0
1230 || !(gspca_dev->frame[0].v4l2_buf.flags & V4L2_BUF_FLAG_QUEUED)) {
1190 ret = -EINVAL; 1231 ret = -EINVAL;
1191 goto out; 1232 goto out;
1192 } 1233 }
@@ -1236,7 +1277,6 @@ static int vidioc_streamoff(struct file *file, void *priv,
1236 gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; 1277 gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0;
1237 gspca_dev->last_packet_type = DISCARD_PACKET; 1278 gspca_dev->last_packet_type = DISCARD_PACKET;
1238 gspca_dev->sequence = 0; 1279 gspca_dev->sequence = 0;
1239 atomic_set(&gspca_dev->nevent, 0);
1240 ret = 0; 1280 ret = 0;
1241out: 1281out:
1242 mutex_unlock(&gspca_dev->queue_lock); 1282 mutex_unlock(&gspca_dev->queue_lock);
@@ -1281,6 +1321,17 @@ static int vidioc_g_parm(struct file *filp, void *priv,
1281 memset(parm, 0, sizeof *parm); 1321 memset(parm, 0, sizeof *parm);
1282 parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1322 parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1283 parm->parm.capture.readbuffers = gspca_dev->nbufread; 1323 parm->parm.capture.readbuffers = gspca_dev->nbufread;
1324
1325 if (gspca_dev->sd_desc->get_streamparm) {
1326 int ret;
1327
1328 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1329 return -ERESTARTSYS;
1330 ret = gspca_dev->sd_desc->get_streamparm(gspca_dev, parm);
1331 mutex_unlock(&gspca_dev->usb_lock);
1332 return ret;
1333 }
1334
1284 return 0; 1335 return 0;
1285} 1336}
1286 1337
@@ -1295,6 +1346,17 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1295 parm->parm.capture.readbuffers = gspca_dev->nbufread; 1346 parm->parm.capture.readbuffers = gspca_dev->nbufread;
1296 else 1347 else
1297 gspca_dev->nbufread = n; 1348 gspca_dev->nbufread = n;
1349
1350 if (gspca_dev->sd_desc->set_streamparm) {
1351 int ret;
1352
1353 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1354 return -ERESTARTSYS;
1355 ret = gspca_dev->sd_desc->set_streamparm(gspca_dev, parm);
1356 mutex_unlock(&gspca_dev->usb_lock);
1357 return ret;
1358 }
1359
1298 return 0; 1360 return 0;
1299} 1361}
1300 1362
@@ -1440,33 +1502,22 @@ static int frame_wait(struct gspca_dev *gspca_dev,
1440 i = gspca_dev->fr_o; 1502 i = gspca_dev->fr_o;
1441 j = gspca_dev->fr_queue[i]; 1503 j = gspca_dev->fr_queue[i];
1442 frame = &gspca_dev->frame[j]; 1504 frame = &gspca_dev->frame[j];
1443 if (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE) {
1444 atomic_dec(&gspca_dev->nevent);
1445 goto ok;
1446 }
1447 if (nonblock_ing) /* no frame yet */
1448 return -EAGAIN;
1449 1505
1450 /* wait till a frame is ready */ 1506 if (!(frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE)) {
1451 for (;;) { 1507 if (nonblock_ing)
1508 return -EAGAIN;
1509
1510 /* wait till a frame is ready */
1452 ret = wait_event_interruptible_timeout(gspca_dev->wq, 1511 ret = wait_event_interruptible_timeout(gspca_dev->wq,
1453 atomic_read(&gspca_dev->nevent) > 0, 1512 (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE) ||
1454 msecs_to_jiffies(3000)); 1513 !gspca_dev->streaming || !gspca_dev->present,
1455 if (ret <= 0) { 1514 msecs_to_jiffies(3000));
1456 if (ret < 0) 1515 if (ret < 0)
1457 return ret; /* interrupt */ 1516 return ret;
1458 return -EIO; /* timeout */ 1517 if (ret == 0 || !gspca_dev->streaming || !gspca_dev->present)
1459 }
1460 atomic_dec(&gspca_dev->nevent);
1461 if (!gspca_dev->streaming || !gspca_dev->present)
1462 return -EIO; 1518 return -EIO;
1463 i = gspca_dev->fr_o;
1464 j = gspca_dev->fr_queue[i];
1465 frame = &gspca_dev->frame[j];
1466 if (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE)
1467 break;
1468 } 1519 }
1469ok: 1520
1470 gspca_dev->fr_o = (i + 1) % gspca_dev->nframes; 1521 gspca_dev->fr_o = (i + 1) % gspca_dev->nframes;
1471 PDEBUG(D_FRAM, "frame wait q:%d i:%d o:%d", 1522 PDEBUG(D_FRAM, "frame wait q:%d i:%d o:%d",
1472 gspca_dev->fr_q, 1523 gspca_dev->fr_q,
@@ -1494,8 +1545,6 @@ static int vidioc_dqbuf(struct file *file, void *priv,
1494 int i, ret; 1545 int i, ret;
1495 1546
1496 PDEBUG(D_FRAM, "dqbuf"); 1547 PDEBUG(D_FRAM, "dqbuf");
1497 if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1498 return -EINVAL;
1499 if (v4l2_buf->memory != gspca_dev->memory) 1548 if (v4l2_buf->memory != gspca_dev->memory)
1500 return -EINVAL; 1549 return -EINVAL;
1501 1550
@@ -1550,8 +1599,6 @@ static int vidioc_qbuf(struct file *file, void *priv,
1550 int i, index, ret; 1599 int i, index, ret;
1551 1600
1552 PDEBUG(D_FRAM, "qbuf %d", v4l2_buf->index); 1601 PDEBUG(D_FRAM, "qbuf %d", v4l2_buf->index);
1553 if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1554 return -EINVAL;
1555 1602
1556 if (mutex_lock_interruptible(&gspca_dev->queue_lock)) 1603 if (mutex_lock_interruptible(&gspca_dev->queue_lock))
1557 return -ERESTARTSYS; 1604 return -ERESTARTSYS;
@@ -1761,7 +1808,7 @@ static struct file_operations dev_fops = {
1761 .release = dev_close, 1808 .release = dev_close,
1762 .read = dev_read, 1809 .read = dev_read,
1763 .mmap = dev_mmap, 1810 .mmap = dev_mmap,
1764 .ioctl = video_ioctl2, 1811 .unlocked_ioctl = __video_ioctl2,
1765#ifdef CONFIG_COMPAT 1812#ifdef CONFIG_COMPAT
1766 .compat_ioctl = v4l_compat_ioctl32, 1813 .compat_ioctl = v4l_compat_ioctl32,
1767#endif 1814#endif
@@ -1781,6 +1828,9 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
1781 .vidioc_queryctrl = vidioc_queryctrl, 1828 .vidioc_queryctrl = vidioc_queryctrl,
1782 .vidioc_g_ctrl = vidioc_g_ctrl, 1829 .vidioc_g_ctrl = vidioc_g_ctrl,
1783 .vidioc_s_ctrl = vidioc_s_ctrl, 1830 .vidioc_s_ctrl = vidioc_s_ctrl,
1831 .vidioc_g_audio = vidioc_g_audio,
1832 .vidioc_s_audio = vidioc_s_audio,
1833 .vidioc_enumaudio = vidioc_enumaudio,
1784 .vidioc_querymenu = vidioc_querymenu, 1834 .vidioc_querymenu = vidioc_querymenu,
1785 .vidioc_enum_input = vidioc_enum_input, 1835 .vidioc_enum_input = vidioc_enum_input,
1786 .vidioc_g_input = vidioc_g_input, 1836 .vidioc_g_input = vidioc_g_input,
@@ -1802,7 +1852,7 @@ static struct video_device gspca_template = {
1802 .name = "gspca main driver", 1852 .name = "gspca main driver",
1803 .fops = &dev_fops, 1853 .fops = &dev_fops,
1804 .ioctl_ops = &dev_ioctl_ops, 1854 .ioctl_ops = &dev_ioctl_ops,
1805 .release = video_device_release, 1855 .release = gspca_release,
1806 .minor = -1, 1856 .minor = -1,
1807}; 1857};
1808 1858
@@ -1840,7 +1890,6 @@ int gspca_dev_probe(struct usb_interface *intf,
1840 err("couldn't kzalloc gspca struct"); 1890 err("couldn't kzalloc gspca struct");
1841 return -ENOMEM; 1891 return -ENOMEM;
1842 } 1892 }
1843 kref_init(&gspca_dev->kref);
1844 gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL); 1893 gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL);
1845 if (!gspca_dev->usb_buf) { 1894 if (!gspca_dev->usb_buf) {
1846 err("out of memory"); 1895 err("out of memory");
@@ -1852,12 +1901,13 @@ int gspca_dev_probe(struct usb_interface *intf,
1852 gspca_dev->nbalt = intf->num_altsetting; 1901 gspca_dev->nbalt = intf->num_altsetting;
1853 gspca_dev->sd_desc = sd_desc; 1902 gspca_dev->sd_desc = sd_desc;
1854 gspca_dev->nbufread = 2; 1903 gspca_dev->nbufread = 2;
1904 gspca_dev->empty_packet = -1; /* don't check the empty packets */
1855 1905
1856 /* configure the subdriver and initialize the USB device */ 1906 /* configure the subdriver and initialize the USB device */
1857 ret = gspca_dev->sd_desc->config(gspca_dev, id); 1907 ret = sd_desc->config(gspca_dev, id);
1858 if (ret < 0) 1908 if (ret < 0)
1859 goto out; 1909 goto out;
1860 ret = gspca_dev->sd_desc->init(gspca_dev); 1910 ret = sd_desc->init(gspca_dev);
1861 if (ret < 0) 1911 if (ret < 0)
1862 goto out; 1912 goto out;
1863 ret = gspca_set_alt0(gspca_dev); 1913 ret = gspca_set_alt0(gspca_dev);
@@ -1871,18 +1921,15 @@ int gspca_dev_probe(struct usb_interface *intf,
1871 init_waitqueue_head(&gspca_dev->wq); 1921 init_waitqueue_head(&gspca_dev->wq);
1872 1922
1873 /* init video stuff */ 1923 /* init video stuff */
1874 gspca_dev->vdev = video_device_alloc(); 1924 memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template);
1875 memcpy(gspca_dev->vdev, &gspca_template, sizeof gspca_template); 1925 gspca_dev->vdev.parent = &dev->dev;
1876 gspca_dev->vdev->parent = &dev->dev;
1877 gspca_dev->module = module; 1926 gspca_dev->module = module;
1878 gspca_dev->present = 1; 1927 gspca_dev->present = 1;
1879 video_set_drvdata(gspca_dev->vdev, gspca_dev); 1928 ret = video_register_device(&gspca_dev->vdev,
1880 ret = video_register_device(gspca_dev->vdev,
1881 VFL_TYPE_GRABBER, 1929 VFL_TYPE_GRABBER,
1882 video_nr); 1930 video_nr);
1883 if (ret < 0) { 1931 if (ret < 0) {
1884 err("video_register_device err %d", ret); 1932 err("video_register_device err %d", ret);
1885 video_device_release(gspca_dev->vdev);
1886 goto out; 1933 goto out;
1887 } 1934 }
1888 1935
@@ -1906,15 +1953,14 @@ void gspca_disconnect(struct usb_interface *intf)
1906{ 1953{
1907 struct gspca_dev *gspca_dev = usb_get_intfdata(intf); 1954 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
1908 1955
1909 usb_set_intfdata(intf, NULL);
1910
1911/* We don't want people trying to open up the device */
1912 video_unregister_device(gspca_dev->vdev);
1913
1914 gspca_dev->present = 0; 1956 gspca_dev->present = 0;
1915 gspca_dev->streaming = 0; 1957 gspca_dev->streaming = 0;
1916 1958
1917 kref_put(&gspca_dev->kref, gspca_delete); 1959 usb_set_intfdata(intf, NULL);
1960
1961 /* release the device */
1962 /* (this will call gspca_release() immediatly or on last close) */
1963 video_unregister_device(&gspca_dev->vdev);
1918 1964
1919 PDEBUG(D_PROBE, "disconnect complete"); 1965 PDEBUG(D_PROBE, "disconnect complete");
1920} 1966}
@@ -1992,7 +2038,7 @@ int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
1992 desired lumination fast (with the risc of a slight overshoot) */ 2038 desired lumination fast (with the risc of a slight overshoot) */
1993 steps = abs(desired_avg_lum - avg_lum) / deadzone; 2039 steps = abs(desired_avg_lum - avg_lum) / deadzone;
1994 2040
1995 PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d\n", 2041 PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d",
1996 avg_lum, desired_avg_lum, steps); 2042 avg_lum, desired_avg_lum, steps);
1997 2043
1998 for (i = 0; i < steps; i++) { 2044 for (i = 0; i < steps; i++) {