aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorBhupesh Sharma <bhupesh.sharma@st.com>2013-03-01 14:46:30 -0500
committerFelipe Balbi <balbi@ti.com>2013-03-18 05:18:21 -0400
commit41837c352fd8d804dbe978c29e57ec8217df1d51 (patch)
treef89cdcee13aa08577a6d829c68174a4631b5652d /drivers/usb/gadget
parent43ff05e20c6e2428fe2deb1dc0fed008743e66a3 (diff)
usb: gadget: uvc: Delay the status stage when setting alternate setting 1
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>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/f_uvc.c15
-rw-r--r--drivers/usb/gadget/uvc.h1
-rw-r--r--drivers/usb/gadget/uvc_v4l2.c14
3 files changed, 23 insertions, 7 deletions
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index 49939e44ed74..38dcedddc52c 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -266,6 +266,13 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
266 return 0; 266 return 0;
267} 267}
268 268
269void uvc_function_setup_continue(struct uvc_device *uvc)
270{
271 struct usb_composite_dev *cdev = uvc->func.config->cdev;
272
273 usb_composite_setup_continue(cdev);
274}
275
269static int 276static int
270uvc_function_get_alt(struct usb_function *f, unsigned interface) 277uvc_function_get_alt(struct usb_function *f, unsigned interface)
271{ 278{
@@ -328,7 +335,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
328 v4l2_event_queue(uvc->vdev, &v4l2_event); 335 v4l2_event_queue(uvc->vdev, &v4l2_event);
329 336
330 uvc->state = UVC_STATE_CONNECTED; 337 uvc->state = UVC_STATE_CONNECTED;
331 break; 338 return 0;
332 339
333 case 1: 340 case 1:
334 if (uvc->state != UVC_STATE_CONNECTED) 341 if (uvc->state != UVC_STATE_CONNECTED)
@@ -345,15 +352,11 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
345 memset(&v4l2_event, 0, sizeof(v4l2_event)); 352 memset(&v4l2_event, 0, sizeof(v4l2_event));
346 v4l2_event.type = UVC_EVENT_STREAMON; 353 v4l2_event.type = UVC_EVENT_STREAMON;
347 v4l2_event_queue(uvc->vdev, &v4l2_event); 354 v4l2_event_queue(uvc->vdev, &v4l2_event);
348 355 return USB_GADGET_DELAYED_STATUS;
349 uvc->state = UVC_STATE_STREAMING;
350 break;
351 356
352 default: 357 default:
353 return -EINVAL; 358 return -EINVAL;
354 } 359 }
355
356 return 0;
357} 360}
358 361
359static void 362static void
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
index 7e90b1d12d09..817e9e19cecf 100644
--- a/drivers/usb/gadget/uvc.h
+++ b/drivers/usb/gadget/uvc.h
@@ -188,6 +188,7 @@ struct uvc_file_handle
188 * Functions 188 * Functions
189 */ 189 */
190 190
191extern void uvc_function_setup_continue(struct uvc_device *uvc);
191extern void uvc_endpoint_stream(struct uvc_device *dev); 192extern void uvc_endpoint_stream(struct uvc_device *dev);
192 193
193extern void uvc_function_connect(struct uvc_device *uvc); 194extern void uvc_function_connect(struct uvc_device *uvc);
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c
index 0080d073bd5e..2bb5af8d2b23 100644
--- a/drivers/usb/gadget/uvc_v4l2.c
+++ b/drivers/usb/gadget/uvc_v4l2.c
@@ -253,7 +253,19 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
253 if (*type != video->queue.type) 253 if (*type != video->queue.type)
254 return -EINVAL; 254 return -EINVAL;
255 255
256 return uvc_video_enable(video, 1); 256 /* Enable UVC video. */
257 ret = uvc_video_enable(video, 1);
258 if (ret < 0)
259 return ret;
260
261 /*
262 * Complete the alternate setting selection setup phase now that
263 * userspace is ready to provide video frames.
264 */
265 uvc_function_setup_continue(uvc);
266 uvc->state = UVC_STATE_STREAMING;
267
268 return 0;
257 } 269 }
258 270
259 case VIDIOC_STREAMOFF: 271 case VIDIOC_STREAMOFF: