Commit 04a37e0f authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

V4L/DVB (11837): uvcvideo: Start status polling on device open

Most UVC camera include an interrupt endpoint to report control value changes,
video streaming errors and camera button events. The USB controller
continuously polls the interrupt endpoint to retrieve such events. This
prevents the device from being auto-suspended, and thus consumes power.

Reporting video streaming errors don't make sense when the V4L2 device is
closed. Control value changes are probably useless as well if nobody listens to
the events, although caching will probably have to be completely disabled then.
No polling is thus be required when /dev/videoX is not opened.

To enable auto-suspend and save power do not poll the interrupt endpoint until
the device is open. We lose the ability to detect button events if no
application is using the camera.

http://bugzilla.kernel.org/show_bug.cgi?id=11948Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent b2d9cc42
......@@ -1594,6 +1594,7 @@ static int uvc_probe(struct usb_interface *intf,
INIT_LIST_HEAD(&dev->entities);
INIT_LIST_HEAD(&dev->streaming);
kref_init(&dev->kref);
atomic_set(&dev->users, 0);
dev->udev = usb_get_dev(udev);
dev->intf = usb_get_intf(intf);
......
......@@ -194,7 +194,7 @@ int uvc_status_init(struct uvc_device *dev)
dev->status, UVC_MAX_STATUS_SIZE, uvc_status_complete,
dev, interval);
return usb_submit_urb(dev->int_urb, GFP_KERNEL);
return 0;
}
void uvc_status_cleanup(struct uvc_device *dev)
......@@ -205,15 +205,30 @@ void uvc_status_cleanup(struct uvc_device *dev)
uvc_input_cleanup(dev);
}
int uvc_status_suspend(struct uvc_device *dev)
int uvc_status_start(struct uvc_device *dev)
{
if (dev->int_urb == NULL)
return 0;
return usb_submit_urb(dev->int_urb, GFP_KERNEL);
}
void uvc_status_stop(struct uvc_device *dev)
{
usb_kill_urb(dev->int_urb);
}
int uvc_status_suspend(struct uvc_device *dev)
{
if (atomic_read(&dev->users))
usb_kill_urb(dev->int_urb);
return 0;
}
int uvc_status_resume(struct uvc_device *dev)
{
if (dev->int_urb == NULL)
if (dev->int_urb == NULL || atomic_read(&dev->users) == 0)
return 0;
return usb_submit_urb(dev->int_urb, GFP_NOIO);
......
......@@ -439,6 +439,15 @@ static int uvc_v4l2_open(struct file *file)
goto done;
}
if (atomic_inc_return(&video->dev->users) == 1) {
if ((ret = uvc_status_start(video->dev)) < 0) {
usb_autopm_put_interface(video->dev->intf);
atomic_dec(&video->dev->users);
kfree(handle);
goto done;
}
}
handle->device = video;
handle->state = UVC_HANDLE_PASSIVE;
file->private_data = handle;
......@@ -473,6 +482,9 @@ static int uvc_v4l2_release(struct file *file)
kfree(handle);
file->private_data = NULL;
if (atomic_dec_return(&video->dev->users) == 0)
uvc_status_stop(video->dev);
usb_autopm_put_interface(video->dev->intf);
kref_put(&video->dev->kref, uvc_delete);
return 0;
......
......@@ -634,6 +634,7 @@ struct uvc_device {
enum uvc_device_state state;
struct kref kref;
struct list_head list;
atomic_t users;
/* Video control interface */
__u16 uvc_version;
......@@ -770,6 +771,8 @@ extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
/* Status */
extern int uvc_status_init(struct uvc_device *dev);
extern void uvc_status_cleanup(struct uvc_device *dev);
extern int uvc_status_start(struct uvc_device *dev);
extern void uvc_status_stop(struct uvc_device *dev);
extern int uvc_status_suspend(struct uvc_device *dev);
extern int uvc_status_resume(struct uvc_device *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment