diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2015-03-09 12:34:08 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-02 22:36:20 -0400 |
commit | dbe98b30d3a0d703369fef9712482e12fc685805 (patch) | |
tree | 41f5434ffe7c5e264728235f82160efe3c19df6c /drivers | |
parent | cab9bf11f8ef433151a15b9519e3e0a56302c9a4 (diff) |
[media] gadget/uvc: embed video_device
Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/gadget/function/f_uvc.c | 44 | ||||
-rw-r--r-- | drivers/usb/gadget/function/uvc.h | 2 |
2 files changed, 19 insertions, 27 deletions
diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index 3242bc684e2d..cf0df8fbba89 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c | |||
@@ -222,7 +222,7 @@ uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req) | |||
222 | v4l2_event.type = UVC_EVENT_DATA; | 222 | v4l2_event.type = UVC_EVENT_DATA; |
223 | uvc_event->data.length = req->actual; | 223 | uvc_event->data.length = req->actual; |
224 | memcpy(&uvc_event->data.data, req->buf, req->actual); | 224 | memcpy(&uvc_event->data.data, req->buf, req->actual); |
225 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 225 | v4l2_event_queue(&uvc->vdev, &v4l2_event); |
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
@@ -256,7 +256,7 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | |||
256 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 256 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
257 | v4l2_event.type = UVC_EVENT_SETUP; | 257 | v4l2_event.type = UVC_EVENT_SETUP; |
258 | memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req)); | 258 | memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req)); |
259 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 259 | v4l2_event_queue(&uvc->vdev, &v4l2_event); |
260 | 260 | ||
261 | return 0; | 261 | return 0; |
262 | } | 262 | } |
@@ -315,7 +315,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) | |||
315 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 315 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
316 | v4l2_event.type = UVC_EVENT_CONNECT; | 316 | v4l2_event.type = UVC_EVENT_CONNECT; |
317 | uvc_event->speed = cdev->gadget->speed; | 317 | uvc_event->speed = cdev->gadget->speed; |
318 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 318 | v4l2_event_queue(&uvc->vdev, &v4l2_event); |
319 | 319 | ||
320 | uvc->state = UVC_STATE_CONNECTED; | 320 | uvc->state = UVC_STATE_CONNECTED; |
321 | } | 321 | } |
@@ -343,7 +343,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) | |||
343 | 343 | ||
344 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 344 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
345 | v4l2_event.type = UVC_EVENT_STREAMOFF; | 345 | v4l2_event.type = UVC_EVENT_STREAMOFF; |
346 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 346 | v4l2_event_queue(&uvc->vdev, &v4l2_event); |
347 | 347 | ||
348 | uvc->state = UVC_STATE_CONNECTED; | 348 | uvc->state = UVC_STATE_CONNECTED; |
349 | return 0; | 349 | return 0; |
@@ -370,7 +370,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) | |||
370 | 370 | ||
371 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 371 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
372 | v4l2_event.type = UVC_EVENT_STREAMON; | 372 | v4l2_event.type = UVC_EVENT_STREAMON; |
373 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 373 | v4l2_event_queue(&uvc->vdev, &v4l2_event); |
374 | return USB_GADGET_DELAYED_STATUS; | 374 | return USB_GADGET_DELAYED_STATUS; |
375 | 375 | ||
376 | default: | 376 | default: |
@@ -388,7 +388,7 @@ uvc_function_disable(struct usb_function *f) | |||
388 | 388 | ||
389 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 389 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
390 | v4l2_event.type = UVC_EVENT_DISCONNECT; | 390 | v4l2_event.type = UVC_EVENT_DISCONNECT; |
391 | v4l2_event_queue(uvc->vdev, &v4l2_event); | 391 | v4l2_event_queue(&uvc->vdev, &v4l2_event); |
392 | 392 | ||
393 | uvc->state = UVC_STATE_DISCONNECTED; | 393 | uvc->state = UVC_STATE_DISCONNECTED; |
394 | 394 | ||
@@ -435,25 +435,19 @@ static int | |||
435 | uvc_register_video(struct uvc_device *uvc) | 435 | uvc_register_video(struct uvc_device *uvc) |
436 | { | 436 | { |
437 | struct usb_composite_dev *cdev = uvc->func.config->cdev; | 437 | struct usb_composite_dev *cdev = uvc->func.config->cdev; |
438 | struct video_device *video; | ||
439 | 438 | ||
440 | /* TODO reference counting. */ | 439 | /* TODO reference counting. */ |
441 | video = video_device_alloc(); | 440 | uvc->vdev.v4l2_dev = &uvc->v4l2_dev; |
442 | if (video == NULL) | 441 | uvc->vdev.fops = &uvc_v4l2_fops; |
443 | return -ENOMEM; | 442 | uvc->vdev.ioctl_ops = &uvc_v4l2_ioctl_ops; |
444 | 443 | uvc->vdev.release = video_device_release_empty; | |
445 | video->v4l2_dev = &uvc->v4l2_dev; | 444 | uvc->vdev.vfl_dir = VFL_DIR_TX; |
446 | video->fops = &uvc_v4l2_fops; | 445 | uvc->vdev.lock = &uvc->video.mutex; |
447 | video->ioctl_ops = &uvc_v4l2_ioctl_ops; | 446 | strlcpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name)); |
448 | video->release = video_device_release; | 447 | |
449 | video->vfl_dir = VFL_DIR_TX; | 448 | video_set_drvdata(&uvc->vdev, uvc); |
450 | video->lock = &uvc->video.mutex; | 449 | |
451 | strlcpy(video->name, cdev->gadget->name, sizeof(video->name)); | 450 | return video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1); |
452 | |||
453 | uvc->vdev = video; | ||
454 | video_set_drvdata(video, uvc); | ||
455 | |||
456 | return video_register_device(video, VFL_TYPE_GRABBER, -1); | ||
457 | } | 451 | } |
458 | 452 | ||
459 | #define UVC_COPY_DESCRIPTOR(mem, dst, desc) \ | 453 | #define UVC_COPY_DESCRIPTOR(mem, dst, desc) \ |
@@ -766,8 +760,6 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
766 | 760 | ||
767 | error: | 761 | error: |
768 | v4l2_device_unregister(&uvc->v4l2_dev); | 762 | v4l2_device_unregister(&uvc->v4l2_dev); |
769 | if (uvc->vdev) | ||
770 | video_device_release(uvc->vdev); | ||
771 | 763 | ||
772 | if (uvc->control_ep) | 764 | if (uvc->control_ep) |
773 | uvc->control_ep->driver_data = NULL; | 765 | uvc->control_ep->driver_data = NULL; |
@@ -898,7 +890,7 @@ static void uvc_unbind(struct usb_configuration *c, struct usb_function *f) | |||
898 | 890 | ||
899 | INFO(cdev, "%s\n", __func__); | 891 | INFO(cdev, "%s\n", __func__); |
900 | 892 | ||
901 | video_unregister_device(uvc->vdev); | 893 | video_unregister_device(&uvc->vdev); |
902 | v4l2_device_unregister(&uvc->v4l2_dev); | 894 | v4l2_device_unregister(&uvc->v4l2_dev); |
903 | uvc->control_ep->driver_data = NULL; | 895 | uvc->control_ep->driver_data = NULL; |
904 | uvc->video.ep->driver_data = NULL; | 896 | uvc->video.ep->driver_data = NULL; |
diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/function/uvc.h index 3390ecd1a1f3..ebe409b9e419 100644 --- a/drivers/usb/gadget/function/uvc.h +++ b/drivers/usb/gadget/function/uvc.h | |||
@@ -144,7 +144,7 @@ enum uvc_state | |||
144 | 144 | ||
145 | struct uvc_device | 145 | struct uvc_device |
146 | { | 146 | { |
147 | struct video_device *vdev; | 147 | struct video_device vdev; |
148 | struct v4l2_device v4l2_dev; | 148 | struct v4l2_device v4l2_dev; |
149 | enum uvc_state state; | 149 | enum uvc_state state; |
150 | struct usb_function func; | 150 | struct usb_function func; |