aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/media/sn9c102_core.c
diff options
context:
space:
mode:
authorLuca Risolia <luca.risolia@studio.unibo.it>2006-02-25 01:50:47 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-20 17:49:59 -0500
commit2ffab02fea5880da284dc5511479b25a796a8dee (patch)
treeb94481244ae823598d06cd72472b9c76e9639bd1 /drivers/usb/media/sn9c102_core.c
parent7039f4224d4e40b06308d5c1a97427af1a142459 (diff)
[PATCH] USB: SN9C10x driver updates
SN9C10x driver updates. Changes: + new, - removed, * cleanup, @ bugfix @ Fix stream_interrupt() @ Fix vidioc_enum_input() and split vidioc_gs_input() @ Need usb_get|put_dev() when disconnecting, if the device is open * Use wait_event_interruptible_timeout() instead of wait_event_interruptible() when waiting for video frames * replace wake_up_interruptible(&wait_stream) with wake_up(&wait_stream) * Cleanups and updates in the documentation + Use per-device sensor structures + Add support for PAS202BCA image sensors + Add frame_timeout module parameter Signed-off-by: Luca Risolia <luca.risolia@studio.unibo.it> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/media/sn9c102_core.c')
-rw-r--r--drivers/usb/media/sn9c102_core.c170
1 files changed, 100 insertions, 70 deletions
diff --git a/drivers/usb/media/sn9c102_core.c b/drivers/usb/media/sn9c102_core.c
index 30119080871b..4c6cc6395723 100644
--- a/drivers/usb/media/sn9c102_core.c
+++ b/drivers/usb/media/sn9c102_core.c
@@ -25,11 +25,9 @@
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/string.h>
29#include <linux/device.h> 28#include <linux/device.h>
30#include <linux/fs.h> 29#include <linux/fs.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/stddef.h>
33#include <linux/compiler.h> 31#include <linux/compiler.h>
34#include <linux/ioctl.h> 32#include <linux/ioctl.h>
35#include <linux/poll.h> 33#include <linux/poll.h>
@@ -49,8 +47,8 @@
49#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia" 47#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia"
50#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 48#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
51#define SN9C102_MODULE_LICENSE "GPL" 49#define SN9C102_MODULE_LICENSE "GPL"
52#define SN9C102_MODULE_VERSION "1:1.26" 50#define SN9C102_MODULE_VERSION "1:1.27"
53#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 26) 51#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 27)
54 52
55/*****************************************************************************/ 53/*****************************************************************************/
56 54
@@ -89,6 +87,15 @@ MODULE_PARM_DESC(force_munmap,
89 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"." 87 "\nDefault value is "__MODULE_STRING(SN9C102_FORCE_MUNMAP)"."
90 "\n"); 88 "\n");
91 89
90static unsigned int frame_timeout[] = {[0 ... SN9C102_MAX_DEVICES-1] =
91 SN9C102_FRAME_TIMEOUT};
92module_param_array(frame_timeout, uint, NULL, 0644);
93MODULE_PARM_DESC(frame_timeout,
94 "\n<n[,...]> Timeout for a video frame in seconds."
95 "\nThis parameter is specific for each detected camera."
96 "\nDefault value is "__MODULE_STRING(SN9C102_FRAME_TIMEOUT)"."
97 "\n");
98
92#ifdef SN9C102_DEBUG 99#ifdef SN9C102_DEBUG
93static unsigned short debug = SN9C102_DEBUG_LEVEL; 100static unsigned short debug = SN9C102_DEBUG_LEVEL;
94module_param(debug, ushort, 0644); 101module_param(debug, ushort, 0644);
@@ -128,8 +135,8 @@ static u32
128sn9c102_request_buffers(struct sn9c102_device* cam, u32 count, 135sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
129 enum sn9c102_io_method io) 136 enum sn9c102_io_method io)
130{ 137{
131 struct v4l2_pix_format* p = &(cam->sensor->pix_format); 138 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
132 struct v4l2_rect* r = &(cam->sensor->cropcap.bounds); 139 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
133 const size_t imagesize = cam->module_param.force_munmap || 140 const size_t imagesize = cam->module_param.force_munmap ||
134 io == IO_READ ? 141 io == IO_READ ?
135 (p->width * p->height * p->priv) / 8 : 142 (p->width * p->height * p->priv) / 8 :
@@ -449,19 +456,13 @@ sn9c102_i2c_try_write(struct sn9c102_device* cam,
449 456
450int sn9c102_i2c_read(struct sn9c102_device* cam, u8 address) 457int sn9c102_i2c_read(struct sn9c102_device* cam, u8 address)
451{ 458{
452 if (!cam->sensor) 459 return sn9c102_i2c_try_read(cam, &cam->sensor, address);
453 return -1;
454
455 return sn9c102_i2c_try_read(cam, cam->sensor, address);
456} 460}
457 461
458 462
459int sn9c102_i2c_write(struct sn9c102_device* cam, u8 address, u8 value) 463int sn9c102_i2c_write(struct sn9c102_device* cam, u8 address, u8 value)
460{ 464{
461 if (!cam->sensor) 465 return sn9c102_i2c_try_write(cam, &cam->sensor, address, value);
462 return -1;
463
464 return sn9c102_i2c_try_write(cam, cam->sensor, address, value);
465} 466}
466 467
467/*****************************************************************************/ 468/*****************************************************************************/
@@ -505,7 +506,7 @@ sn9c102_find_eof_header(struct sn9c102_device* cam, void* mem, size_t len)
505 size_t eoflen = sizeof(sn9c102_eof_header_t), i; 506 size_t eoflen = sizeof(sn9c102_eof_header_t), i;
506 unsigned j, n = sizeof(sn9c102_eof_header) / eoflen; 507 unsigned j, n = sizeof(sn9c102_eof_header) / eoflen;
507 508
508 if (cam->sensor->pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X) 509 if (cam->sensor.pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X)
509 return NULL; /* EOF header does not exist in compressed data */ 510 return NULL; /* EOF header does not exist in compressed data */
510 511
511 for (i = 0; (len >= eoflen) && (i <= len - eoflen); i++) 512 for (i = 0; (len >= eoflen) && (i <= len - eoflen); i++)
@@ -535,7 +536,7 @@ static void sn9c102_urb_complete(struct urb *urb, struct pt_regs* regs)
535 if ((*f)) 536 if ((*f))
536 (*f)->state = F_QUEUED; 537 (*f)->state = F_QUEUED;
537 DBG(3, "Stream interrupted"); 538 DBG(3, "Stream interrupted");
538 wake_up_interruptible(&cam->wait_stream); 539 wake_up(&cam->wait_stream);
539 } 540 }
540 541
541 if (cam->state & DEV_DISCONNECTED) 542 if (cam->state & DEV_DISCONNECTED)
@@ -553,9 +554,9 @@ static void sn9c102_urb_complete(struct urb *urb, struct pt_regs* regs)
553 (*f) = list_entry(cam->inqueue.next, struct sn9c102_frame_t, 554 (*f) = list_entry(cam->inqueue.next, struct sn9c102_frame_t,
554 frame); 555 frame);
555 556
556 imagesize = (cam->sensor->pix_format.width * 557 imagesize = (cam->sensor.pix_format.width *
557 cam->sensor->pix_format.height * 558 cam->sensor.pix_format.height *
558 cam->sensor->pix_format.priv) / 8; 559 cam->sensor.pix_format.priv) / 8;
559 560
560 soflen = (cam->bridge) == BRIDGE_SN9C103 ? 561 soflen = (cam->bridge) == BRIDGE_SN9C103 ?
561 sizeof(sn9c103_sof_header_t) : 562 sizeof(sn9c103_sof_header_t) :
@@ -579,7 +580,7 @@ static void sn9c102_urb_complete(struct urb *urb, struct pt_regs* regs)
579 580
580redo: 581redo:
581 sof = sn9c102_find_sof_header(cam, pos, len); 582 sof = sn9c102_find_sof_header(cam, pos, len);
582 if (!sof) { 583 if (likely(!sof)) {
583 eof = sn9c102_find_eof_header(cam, pos, len); 584 eof = sn9c102_find_eof_header(cam, pos, len);
584 if ((*f)->state == F_GRABBING) { 585 if ((*f)->state == F_GRABBING) {
585end_of_frame: 586end_of_frame:
@@ -589,8 +590,9 @@ end_of_frame:
589 img = (eof > pos) ? eof - pos - 1 : 0; 590 img = (eof > pos) ? eof - pos - 1 : 0;
590 591
591 if ((*f)->buf.bytesused+img > imagesize) { 592 if ((*f)->buf.bytesused+img > imagesize) {
592 u32 b = (*f)->buf.bytesused + img - 593 u32 b;
593 imagesize; 594 b = (*f)->buf.bytesused + img -
595 imagesize;
594 img = imagesize - (*f)->buf.bytesused; 596 img = imagesize - (*f)->buf.bytesused;
595 DBG(3, "Expected EOF not found: " 597 DBG(3, "Expected EOF not found: "
596 "video frame cut"); 598 "video frame cut");
@@ -608,9 +610,10 @@ end_of_frame:
608 (*f)->buf.bytesused += img; 610 (*f)->buf.bytesused += img;
609 611
610 if ((*f)->buf.bytesused == imagesize || 612 if ((*f)->buf.bytesused == imagesize ||
611 (cam->sensor->pix_format.pixelformat == 613 (cam->sensor.pix_format.pixelformat ==
612 V4L2_PIX_FMT_SN9C10X && eof)) { 614 V4L2_PIX_FMT_SN9C10X && eof)) {
613 u32 b = (*f)->buf.bytesused; 615 u32 b;
616 b = (*f)->buf.bytesused;
614 (*f)->state = F_DONE; 617 (*f)->state = F_DONE;
615 (*f)->buf.sequence= ++cam->frame_count; 618 (*f)->buf.sequence= ++cam->frame_count;
616 spin_lock(&cam->queue_lock); 619 spin_lock(&cam->queue_lock);
@@ -667,7 +670,7 @@ start_of_frame:
667 if (eof && eof < sof) 670 if (eof && eof < sof)
668 goto end_of_frame; /* (1) */ 671 goto end_of_frame; /* (1) */
669 else { 672 else {
670 if (cam->sensor->pix_format.pixelformat == 673 if (cam->sensor.pix_format.pixelformat ==
671 V4L2_PIX_FMT_SN9C10X) { 674 V4L2_PIX_FMT_SN9C10X) {
672 eof = sof - soflen; 675 eof = sof - soflen;
673 goto end_of_frame; 676 goto end_of_frame;
@@ -808,20 +811,21 @@ static int sn9c102_stop_transfer(struct sn9c102_device* cam)
808 811
809static int sn9c102_stream_interrupt(struct sn9c102_device* cam) 812static int sn9c102_stream_interrupt(struct sn9c102_device* cam)
810{ 813{
811 int err = 0; 814 long timeout;
812 815
813 cam->stream = STREAM_INTERRUPT; 816 cam->stream = STREAM_INTERRUPT;
814 err = wait_event_timeout(cam->wait_stream, 817 timeout = wait_event_timeout(cam->wait_stream,
815 (cam->stream == STREAM_OFF) || 818 (cam->stream == STREAM_OFF) ||
816 (cam->state & DEV_DISCONNECTED), 819 (cam->state & DEV_DISCONNECTED),
817 SN9C102_URB_TIMEOUT); 820 SN9C102_URB_TIMEOUT);
818 if (cam->state & DEV_DISCONNECTED) 821 if (cam->state & DEV_DISCONNECTED)
819 return -ENODEV; 822 return -ENODEV;
820 else if (err) { 823 else if (cam->stream != STREAM_OFF) {
821 cam->state |= DEV_MISCONFIGURED; 824 cam->state |= DEV_MISCONFIGURED;
822 DBG(1, "The camera is misconfigured. To use it, close and " 825 DBG(1, "URB timeout reached. The camera is misconfigured. "
823 "open /dev/video%d again.", cam->v4ldev->minor); 826 "To use it, close and open /dev/video%d again.",
824 return err; 827 cam->v4ldev->minor);
828 return -EIO;
825 } 829 }
826 830
827 return 0; 831 return 0;
@@ -1057,7 +1061,7 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1057 return -ENODEV; 1061 return -ENODEV;
1058 } 1062 }
1059 1063
1060 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_READ)) { 1064 if (!(cam->sensor.sysfs_ops & SN9C102_I2C_READ)) {
1061 mutex_unlock(&sn9c102_sysfs_lock); 1065 mutex_unlock(&sn9c102_sysfs_lock);
1062 return -ENOSYS; 1066 return -ENOSYS;
1063 } 1067 }
@@ -1094,7 +1098,7 @@ sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1094 return -ENODEV; 1098 return -ENODEV;
1095 } 1099 }
1096 1100
1097 if (!(cam->sensor->sysfs_ops & SN9C102_I2C_WRITE)) { 1101 if (!(cam->sensor.sysfs_ops & SN9C102_I2C_WRITE)) {
1098 mutex_unlock(&sn9c102_sysfs_lock); 1102 mutex_unlock(&sn9c102_sysfs_lock);
1099 return -ENOSYS; 1103 return -ENOSYS;
1100 } 1104 }
@@ -1249,7 +1253,7 @@ static void sn9c102_create_sysfs(struct sn9c102_device* cam)
1249 video_device_create_file(v4ldev, &class_device_attr_blue); 1253 video_device_create_file(v4ldev, &class_device_attr_blue);
1250 video_device_create_file(v4ldev, &class_device_attr_red); 1254 video_device_create_file(v4ldev, &class_device_attr_red);
1251 } 1255 }
1252 if (cam->sensor && cam->sensor->sysfs_ops) { 1256 if (cam->sensor.sysfs_ops) {
1253 video_device_create_file(v4ldev, &class_device_attr_i2c_reg); 1257 video_device_create_file(v4ldev, &class_device_attr_i2c_reg);
1254 video_device_create_file(v4ldev, &class_device_attr_i2c_val); 1258 video_device_create_file(v4ldev, &class_device_attr_i2c_val);
1255 } 1259 }
@@ -1312,7 +1316,7 @@ static int sn9c102_set_scale(struct sn9c102_device* cam, u8 scale)
1312 1316
1313static int sn9c102_set_crop(struct sn9c102_device* cam, struct v4l2_rect* rect) 1317static int sn9c102_set_crop(struct sn9c102_device* cam, struct v4l2_rect* rect)
1314{ 1318{
1315 struct sn9c102_sensor* s = cam->sensor; 1319 struct sn9c102_sensor* s = &cam->sensor;
1316 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left), 1320 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left),
1317 v_start = (u8)(rect->top - s->cropcap.bounds.top), 1321 v_start = (u8)(rect->top - s->cropcap.bounds.top),
1318 h_size = (u8)(rect->width / 16), 1322 h_size = (u8)(rect->width / 16),
@@ -1335,7 +1339,7 @@ static int sn9c102_set_crop(struct sn9c102_device* cam, struct v4l2_rect* rect)
1335 1339
1336static int sn9c102_init(struct sn9c102_device* cam) 1340static int sn9c102_init(struct sn9c102_device* cam)
1337{ 1341{
1338 struct sn9c102_sensor* s = cam->sensor; 1342 struct sn9c102_sensor* s = &cam->sensor;
1339 struct v4l2_control ctrl; 1343 struct v4l2_control ctrl;
1340 struct v4l2_queryctrl *qctrl; 1344 struct v4l2_queryctrl *qctrl;
1341 struct v4l2_rect* rect; 1345 struct v4l2_rect* rect;
@@ -1428,6 +1432,8 @@ static void sn9c102_release_resources(struct sn9c102_device* cam)
1428 video_set_drvdata(cam->v4ldev, NULL); 1432 video_set_drvdata(cam->v4ldev, NULL);
1429 video_unregister_device(cam->v4ldev); 1433 video_unregister_device(cam->v4ldev);
1430 1434
1435 usb_put_dev(cam->usbdev);
1436
1431 mutex_unlock(&sn9c102_sysfs_lock); 1437 mutex_unlock(&sn9c102_sysfs_lock);
1432 1438
1433 kfree(cam->control_buffer); 1439 kfree(cam->control_buffer);
@@ -1541,6 +1547,7 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1541 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 1547 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
1542 struct sn9c102_frame_t* f, * i; 1548 struct sn9c102_frame_t* f, * i;
1543 unsigned long lock_flags; 1549 unsigned long lock_flags;
1550 long timeout;
1544 int err = 0; 1551 int err = 0;
1545 1552
1546 if (mutex_lock_interruptible(&cam->fileop_mutex)) 1553 if (mutex_lock_interruptible(&cam->fileop_mutex))
@@ -1592,20 +1599,22 @@ sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1592 mutex_unlock(&cam->fileop_mutex); 1599 mutex_unlock(&cam->fileop_mutex);
1593 return -EAGAIN; 1600 return -EAGAIN;
1594 } 1601 }
1595 err = wait_event_interruptible 1602 timeout = wait_event_interruptible_timeout
1596 ( cam->wait_frame, 1603 ( cam->wait_frame,
1597 (!list_empty(&cam->outqueue)) || 1604 (!list_empty(&cam->outqueue)) ||
1598 (cam->state & DEV_DISCONNECTED) || 1605 (cam->state & DEV_DISCONNECTED) ||
1599 (cam->state & DEV_MISCONFIGURED) ); 1606 (cam->state & DEV_MISCONFIGURED),
1600 if (err) { 1607 cam->module_param.frame_timeout *
1608 1000 * msecs_to_jiffies(1) );
1609 if (timeout < 0) {
1601 mutex_unlock(&cam->fileop_mutex); 1610 mutex_unlock(&cam->fileop_mutex);
1602 return err; 1611 return timeout;
1603 } 1612 }
1604 if (cam->state & DEV_DISCONNECTED) { 1613 if (cam->state & DEV_DISCONNECTED) {
1605 mutex_unlock(&cam->fileop_mutex); 1614 mutex_unlock(&cam->fileop_mutex);
1606 return -ENODEV; 1615 return -ENODEV;
1607 } 1616 }
1608 if (cam->state & DEV_MISCONFIGURED) { 1617 if (!timeout || (cam->state & DEV_MISCONFIGURED)) {
1609 mutex_unlock(&cam->fileop_mutex); 1618 mutex_unlock(&cam->fileop_mutex);
1610 return -EIO; 1619 return -EIO;
1611 } 1620 }
@@ -1816,6 +1825,7 @@ sn9c102_vidioc_enuminput(struct sn9c102_device* cam, void __user * arg)
1816 1825
1817 memset(&i, 0, sizeof(i)); 1826 memset(&i, 0, sizeof(i));
1818 strcpy(i.name, "Camera"); 1827 strcpy(i.name, "Camera");
1828 i.type = V4L2_INPUT_TYPE_CAMERA;
1819 1829
1820 if (copy_to_user(arg, &i, sizeof(i))) 1830 if (copy_to_user(arg, &i, sizeof(i)))
1821 return -EFAULT; 1831 return -EFAULT;
@@ -1825,7 +1835,19 @@ sn9c102_vidioc_enuminput(struct sn9c102_device* cam, void __user * arg)
1825 1835
1826 1836
1827static int 1837static int
1828sn9c102_vidioc_gs_input(struct sn9c102_device* cam, void __user * arg) 1838sn9c102_vidioc_g_input(struct sn9c102_device* cam, void __user * arg)
1839{
1840 int index = 0;
1841
1842 if (copy_to_user(arg, &index, sizeof(index)))
1843 return -EFAULT;
1844
1845 return 0;
1846}
1847
1848
1849static int
1850sn9c102_vidioc_s_input(struct sn9c102_device* cam, void __user * arg)
1829{ 1851{
1830 int index; 1852 int index;
1831 1853
@@ -1842,7 +1864,7 @@ sn9c102_vidioc_gs_input(struct sn9c102_device* cam, void __user * arg)
1842static int 1864static int
1843sn9c102_vidioc_query_ctrl(struct sn9c102_device* cam, void __user * arg) 1865sn9c102_vidioc_query_ctrl(struct sn9c102_device* cam, void __user * arg)
1844{ 1866{
1845 struct sn9c102_sensor* s = cam->sensor; 1867 struct sn9c102_sensor* s = &cam->sensor;
1846 struct v4l2_queryctrl qc; 1868 struct v4l2_queryctrl qc;
1847 u8 i; 1869 u8 i;
1848 1870
@@ -1864,7 +1886,7 @@ sn9c102_vidioc_query_ctrl(struct sn9c102_device* cam, void __user * arg)
1864static int 1886static int
1865sn9c102_vidioc_g_ctrl(struct sn9c102_device* cam, void __user * arg) 1887sn9c102_vidioc_g_ctrl(struct sn9c102_device* cam, void __user * arg)
1866{ 1888{
1867 struct sn9c102_sensor* s = cam->sensor; 1889 struct sn9c102_sensor* s = &cam->sensor;
1868 struct v4l2_control ctrl; 1890 struct v4l2_control ctrl;
1869 int err = 0; 1891 int err = 0;
1870 u8 i; 1892 u8 i;
@@ -1896,7 +1918,7 @@ exit:
1896static int 1918static int
1897sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg) 1919sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
1898{ 1920{
1899 struct sn9c102_sensor* s = cam->sensor; 1921 struct sn9c102_sensor* s = &cam->sensor;
1900 struct v4l2_control ctrl; 1922 struct v4l2_control ctrl;
1901 u8 i; 1923 u8 i;
1902 int err = 0; 1924 int err = 0;
@@ -1909,6 +1931,8 @@ sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
1909 1931
1910 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) 1932 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1911 if (ctrl.id == s->qctrl[i].id) { 1933 if (ctrl.id == s->qctrl[i].id) {
1934 if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
1935 return -EINVAL;
1912 if (ctrl.value < s->qctrl[i].minimum || 1936 if (ctrl.value < s->qctrl[i].minimum ||
1913 ctrl.value > s->qctrl[i].maximum) 1937 ctrl.value > s->qctrl[i].maximum)
1914 return -ERANGE; 1938 return -ERANGE;
@@ -1931,7 +1955,7 @@ sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
1931static int 1955static int
1932sn9c102_vidioc_cropcap(struct sn9c102_device* cam, void __user * arg) 1956sn9c102_vidioc_cropcap(struct sn9c102_device* cam, void __user * arg)
1933{ 1957{
1934 struct v4l2_cropcap* cc = &(cam->sensor->cropcap); 1958 struct v4l2_cropcap* cc = &(cam->sensor.cropcap);
1935 1959
1936 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1960 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1937 cc->pixelaspect.numerator = 1; 1961 cc->pixelaspect.numerator = 1;
@@ -1947,7 +1971,7 @@ sn9c102_vidioc_cropcap(struct sn9c102_device* cam, void __user * arg)
1947static int 1971static int
1948sn9c102_vidioc_g_crop(struct sn9c102_device* cam, void __user * arg) 1972sn9c102_vidioc_g_crop(struct sn9c102_device* cam, void __user * arg)
1949{ 1973{
1950 struct sn9c102_sensor* s = cam->sensor; 1974 struct sn9c102_sensor* s = &cam->sensor;
1951 struct v4l2_crop crop = { 1975 struct v4l2_crop crop = {
1952 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, 1976 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1953 }; 1977 };
@@ -1964,7 +1988,7 @@ sn9c102_vidioc_g_crop(struct sn9c102_device* cam, void __user * arg)
1964static int 1988static int
1965sn9c102_vidioc_s_crop(struct sn9c102_device* cam, void __user * arg) 1989sn9c102_vidioc_s_crop(struct sn9c102_device* cam, void __user * arg)
1966{ 1990{
1967 struct sn9c102_sensor* s = cam->sensor; 1991 struct sn9c102_sensor* s = &cam->sensor;
1968 struct v4l2_crop crop; 1992 struct v4l2_crop crop;
1969 struct v4l2_rect* rect; 1993 struct v4l2_rect* rect;
1970 struct v4l2_rect* bounds = &(s->cropcap.bounds); 1994 struct v4l2_rect* bounds = &(s->cropcap.bounds);
@@ -2105,7 +2129,7 @@ static int
2105sn9c102_vidioc_g_fmt(struct sn9c102_device* cam, void __user * arg) 2129sn9c102_vidioc_g_fmt(struct sn9c102_device* cam, void __user * arg)
2106{ 2130{
2107 struct v4l2_format format; 2131 struct v4l2_format format;
2108 struct v4l2_pix_format* pfmt = &(cam->sensor->pix_format); 2132 struct v4l2_pix_format* pfmt = &(cam->sensor.pix_format);
2109 2133
2110 if (copy_from_user(&format, arg, sizeof(format))) 2134 if (copy_from_user(&format, arg, sizeof(format)))
2111 return -EFAULT; 2135 return -EFAULT;
@@ -2130,7 +2154,7 @@ static int
2130sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd, 2154sn9c102_vidioc_try_s_fmt(struct sn9c102_device* cam, unsigned int cmd,
2131 void __user * arg) 2155 void __user * arg)
2132{ 2156{
2133 struct sn9c102_sensor* s = cam->sensor; 2157 struct sn9c102_sensor* s = &cam->sensor;
2134 struct v4l2_format format; 2158 struct v4l2_format format;
2135 struct v4l2_pix_format* pix; 2159 struct v4l2_pix_format* pix;
2136 struct v4l2_pix_format* pfmt = &(s->pix_format); 2160 struct v4l2_pix_format* pfmt = &(s->pix_format);
@@ -2417,7 +2441,7 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2417 struct v4l2_buffer b; 2441 struct v4l2_buffer b;
2418 struct sn9c102_frame_t *f; 2442 struct sn9c102_frame_t *f;
2419 unsigned long lock_flags; 2443 unsigned long lock_flags;
2420 int err = 0; 2444 long timeout;
2421 2445
2422 if (copy_from_user(&b, arg, sizeof(b))) 2446 if (copy_from_user(&b, arg, sizeof(b)))
2423 return -EFAULT; 2447 return -EFAULT;
@@ -2430,16 +2454,18 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2430 return -EINVAL; 2454 return -EINVAL;
2431 if (filp->f_flags & O_NONBLOCK) 2455 if (filp->f_flags & O_NONBLOCK)
2432 return -EAGAIN; 2456 return -EAGAIN;
2433 err = wait_event_interruptible 2457 timeout = wait_event_interruptible_timeout
2434 ( cam->wait_frame, 2458 ( cam->wait_frame,
2435 (!list_empty(&cam->outqueue)) || 2459 (!list_empty(&cam->outqueue)) ||
2436 (cam->state & DEV_DISCONNECTED) || 2460 (cam->state & DEV_DISCONNECTED) ||
2437 (cam->state & DEV_MISCONFIGURED) ); 2461 (cam->state & DEV_MISCONFIGURED),
2438 if (err) 2462 cam->module_param.frame_timeout *
2439 return err; 2463 1000 * msecs_to_jiffies(1) );
2464 if (timeout < 0)
2465 return timeout;
2440 if (cam->state & DEV_DISCONNECTED) 2466 if (cam->state & DEV_DISCONNECTED)
2441 return -ENODEV; 2467 return -ENODEV;
2442 if (cam->state & DEV_MISCONFIGURED) 2468 if (!timeout || (cam->state & DEV_MISCONFIGURED))
2443 return -EIO; 2469 return -EIO;
2444 } 2470 }
2445 2471
@@ -2571,8 +2597,10 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
2571 return sn9c102_vidioc_enuminput(cam, arg); 2597 return sn9c102_vidioc_enuminput(cam, arg);
2572 2598
2573 case VIDIOC_G_INPUT: 2599 case VIDIOC_G_INPUT:
2600 return sn9c102_vidioc_g_input(cam, arg);
2601
2574 case VIDIOC_S_INPUT: 2602 case VIDIOC_S_INPUT:
2575 return sn9c102_vidioc_gs_input(cam, arg); 2603 return sn9c102_vidioc_s_input(cam, arg);
2576 2604
2577 case VIDIOC_QUERYCTRL: 2605 case VIDIOC_QUERYCTRL:
2578 return sn9c102_vidioc_query_ctrl(cam, arg); 2606 return sn9c102_vidioc_query_ctrl(cam, arg);
@@ -2752,10 +2780,10 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2752 break; 2780 break;
2753 } 2781 }
2754 2782
2755 if (!err && cam->sensor) { 2783 if (!err) {
2756 DBG(2, "%s image sensor detected", cam->sensor->name); 2784 DBG(2, "%s image sensor detected", cam->sensor.name);
2757 DBG(3, "Support for %s maintained by %s", 2785 DBG(3, "Support for %s maintained by %s",
2758 cam->sensor->name, cam->sensor->maintainer); 2786 cam->sensor.name, cam->sensor.maintainer);
2759 } else { 2787 } else {
2760 DBG(1, "No supported image sensor detected"); 2788 DBG(1, "No supported image sensor detected");
2761 err = -ENODEV; 2789 err = -ENODEV;
@@ -2793,6 +2821,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2793 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor); 2821 DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor);
2794 2822
2795 cam->module_param.force_munmap = force_munmap[dev_nr]; 2823 cam->module_param.force_munmap = force_munmap[dev_nr];
2824 cam->module_param.frame_timeout = frame_timeout[dev_nr];
2796 2825
2797 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0; 2826 dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
2798 2827
@@ -2841,7 +2870,8 @@ static void sn9c102_usb_disconnect(struct usb_interface* intf)
2841 sn9c102_stop_transfer(cam); 2870 sn9c102_stop_transfer(cam);
2842 cam->state |= DEV_DISCONNECTED; 2871 cam->state |= DEV_DISCONNECTED;
2843 wake_up_interruptible(&cam->wait_frame); 2872 wake_up_interruptible(&cam->wait_frame);
2844 wake_up_interruptible(&cam->wait_stream); 2873 wake_up(&cam->wait_stream);
2874 usb_get_dev(cam->usbdev);
2845 } else { 2875 } else {
2846 cam->state |= DEV_DISCONNECTED; 2876 cam->state |= DEV_DISCONNECTED;
2847 sn9c102_release_resources(cam); 2877 sn9c102_release_resources(cam);