]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
usb: gadget: uvc: Delay the status stage when setting alternate setting 1
authorBhupesh Sharma <bhupesh.sharma@st.com>
Fri, 1 Mar 2013 19:46:30 +0000 (20:46 +0100)
committerFelipe Balbi <balbi@ti.com>
Mon, 18 Mar 2013 09:18:21 +0000 (11:18 +0200)
This patch adds the support in UVC webcam gadget design for providing
USB_GADGET_DELAYED_STATUS in response to a set_interface(alt setting 1)
command issue by the Host.

The current UVC webcam gadget design generates a STREAMON event
corresponding to a set_interface(alt setting 1) command from the Host.
This STREAMON event will eventually be routed to a real V4L2 device.

To start video streaming, it may be required to perform some register
writes to a camera sensor device over slow external busses like I2C or
SPI. So, it makes sense to ensure that we delay the STATUS stage of the
set_interface (alt setting 1) command.

Otherwise, a lot of ISOC IN tokens sent by the Host will be replied to
by zero-length packets by the webcam device. On certain Hosts this may
even lead to ISOC URBs been cancelled from the Host side.

So, as soon as we finish doing all the "streaming" related stuff on the
real V4L2 device, we call a STREAMON ioctl on the UVC side and from here
we call the 'usb_composite_setup_continue' function to complete the
status stage of the set_interface(alt setting 1) command.

Further, we need to ensure that we queue no video buffers on the UVC
webcam gadget, until we de-queue a video buffer from the V4L2 device.
So, the application should call the STREAMON on UVC side only when it
has dequeued sufficient buffers from the V4L2 side and queued them to
the UVC gadget.

Signed-off-by: Bhupesh Sharma <bhupesh.sharma@st.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Bhupesh Sharma <bhupesh.sharma@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/f_uvc.c
drivers/usb/gadget/uvc.h
drivers/usb/gadget/uvc_v4l2.c

index 49939e44ed748a2751bd5478d94271797a4ac3fb..38dcedddc52c0bb43b70e6c5faa8ac3857d5c466 100644 (file)
@@ -266,6 +266,13 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
        return 0;
 }
 
+void uvc_function_setup_continue(struct uvc_device *uvc)
+{
+       struct usb_composite_dev *cdev = uvc->func.config->cdev;
+
+       usb_composite_setup_continue(cdev);
+}
+
 static int
 uvc_function_get_alt(struct usb_function *f, unsigned interface)
 {
@@ -328,7 +335,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
                v4l2_event_queue(uvc->vdev, &v4l2_event);
 
                uvc->state = UVC_STATE_CONNECTED;
-               break;
+               return 0;
 
        case 1:
                if (uvc->state != UVC_STATE_CONNECTED)
@@ -345,15 +352,11 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
                memset(&v4l2_event, 0, sizeof(v4l2_event));
                v4l2_event.type = UVC_EVENT_STREAMON;
                v4l2_event_queue(uvc->vdev, &v4l2_event);
-
-               uvc->state = UVC_STATE_STREAMING;
-               break;
+               return USB_GADGET_DELAYED_STATUS;
 
        default:
                return -EINVAL;
        }
-
-       return 0;
 }
 
 static void
index 7e90b1d12d09f646cc5fd0dce2530e7301d25fef..817e9e19cecf75c34253f0ebbb75d7e9282e383a 100644 (file)
@@ -188,6 +188,7 @@ struct uvc_file_handle
  * Functions
  */
 
+extern void uvc_function_setup_continue(struct uvc_device *uvc);
 extern void uvc_endpoint_stream(struct uvc_device *dev);
 
 extern void uvc_function_connect(struct uvc_device *uvc);
index 0080d073bd5e2e283ab49dee94f812ce31977c71..2bb5af8d2b23632f035951de136914d4dcdb04e6 100644 (file)
@@ -253,7 +253,19 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
                if (*type != video->queue.type)
                        return -EINVAL;
 
-               return uvc_video_enable(video, 1);
+               /* Enable UVC video. */
+               ret = uvc_video_enable(video, 1);
+               if (ret < 0)
+                       return ret;
+
+               /*
+                * Complete the alternate setting selection setup phase now that
+                * userspace is ready to provide video frames.
+                */
+               uvc_function_setup_continue(uvc);
+               uvc->state = UVC_STATE_STREAMING;
+
+               return 0;
        }
 
        case VIDIOC_STREAMOFF: