Commit dbe98b30 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[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: default avatarHans Verkuil <hans.verkuil@cisco.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent cab9bf11
...@@ -222,7 +222,7 @@ uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req) ...@@ -222,7 +222,7 @@ uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req)
v4l2_event.type = UVC_EVENT_DATA; v4l2_event.type = UVC_EVENT_DATA;
uvc_event->data.length = req->actual; uvc_event->data.length = req->actual;
memcpy(&uvc_event->data.data, req->buf, req->actual); memcpy(&uvc_event->data.data, req->buf, req->actual);
v4l2_event_queue(uvc->vdev, &v4l2_event); v4l2_event_queue(&uvc->vdev, &v4l2_event);
} }
} }
...@@ -256,7 +256,7 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) ...@@ -256,7 +256,7 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
memset(&v4l2_event, 0, sizeof(v4l2_event)); memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_SETUP; v4l2_event.type = UVC_EVENT_SETUP;
memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req)); memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req));
v4l2_event_queue(uvc->vdev, &v4l2_event); v4l2_event_queue(&uvc->vdev, &v4l2_event);
return 0; return 0;
} }
...@@ -315,7 +315,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) ...@@ -315,7 +315,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
memset(&v4l2_event, 0, sizeof(v4l2_event)); memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_CONNECT; v4l2_event.type = UVC_EVENT_CONNECT;
uvc_event->speed = cdev->gadget->speed; uvc_event->speed = cdev->gadget->speed;
v4l2_event_queue(uvc->vdev, &v4l2_event); v4l2_event_queue(&uvc->vdev, &v4l2_event);
uvc->state = UVC_STATE_CONNECTED; uvc->state = UVC_STATE_CONNECTED;
} }
...@@ -343,7 +343,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) ...@@ -343,7 +343,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
memset(&v4l2_event, 0, sizeof(v4l2_event)); memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_STREAMOFF; v4l2_event.type = UVC_EVENT_STREAMOFF;
v4l2_event_queue(uvc->vdev, &v4l2_event); v4l2_event_queue(&uvc->vdev, &v4l2_event);
uvc->state = UVC_STATE_CONNECTED; uvc->state = UVC_STATE_CONNECTED;
return 0; return 0;
...@@ -370,7 +370,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) ...@@ -370,7 +370,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
memset(&v4l2_event, 0, sizeof(v4l2_event)); memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_STREAMON; v4l2_event.type = UVC_EVENT_STREAMON;
v4l2_event_queue(uvc->vdev, &v4l2_event); v4l2_event_queue(&uvc->vdev, &v4l2_event);
return USB_GADGET_DELAYED_STATUS; return USB_GADGET_DELAYED_STATUS;
default: default:
...@@ -388,7 +388,7 @@ uvc_function_disable(struct usb_function *f) ...@@ -388,7 +388,7 @@ uvc_function_disable(struct usb_function *f)
memset(&v4l2_event, 0, sizeof(v4l2_event)); memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_DISCONNECT; v4l2_event.type = UVC_EVENT_DISCONNECT;
v4l2_event_queue(uvc->vdev, &v4l2_event); v4l2_event_queue(&uvc->vdev, &v4l2_event);
uvc->state = UVC_STATE_DISCONNECTED; uvc->state = UVC_STATE_DISCONNECTED;
...@@ -435,25 +435,19 @@ static int ...@@ -435,25 +435,19 @@ static int
uvc_register_video(struct uvc_device *uvc) uvc_register_video(struct uvc_device *uvc)
{ {
struct usb_composite_dev *cdev = uvc->func.config->cdev; struct usb_composite_dev *cdev = uvc->func.config->cdev;
struct video_device *video;
/* TODO reference counting. */ /* TODO reference counting. */
video = video_device_alloc(); uvc->vdev.v4l2_dev = &uvc->v4l2_dev;
if (video == NULL) uvc->vdev.fops = &uvc_v4l2_fops;
return -ENOMEM; uvc->vdev.ioctl_ops = &uvc_v4l2_ioctl_ops;
uvc->vdev.release = video_device_release_empty;
video->v4l2_dev = &uvc->v4l2_dev; uvc->vdev.vfl_dir = VFL_DIR_TX;
video->fops = &uvc_v4l2_fops; uvc->vdev.lock = &uvc->video.mutex;
video->ioctl_ops = &uvc_v4l2_ioctl_ops; strlcpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
video->release = video_device_release;
video->vfl_dir = VFL_DIR_TX; video_set_drvdata(&uvc->vdev, uvc);
video->lock = &uvc->video.mutex;
strlcpy(video->name, cdev->gadget->name, sizeof(video->name)); return video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1);
uvc->vdev = video;
video_set_drvdata(video, uvc);
return video_register_device(video, VFL_TYPE_GRABBER, -1);
} }
#define UVC_COPY_DESCRIPTOR(mem, dst, desc) \ #define UVC_COPY_DESCRIPTOR(mem, dst, desc) \
...@@ -766,8 +760,6 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) ...@@ -766,8 +760,6 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
error: error:
v4l2_device_unregister(&uvc->v4l2_dev); v4l2_device_unregister(&uvc->v4l2_dev);
if (uvc->vdev)
video_device_release(uvc->vdev);
if (uvc->control_ep) if (uvc->control_ep)
uvc->control_ep->driver_data = NULL; uvc->control_ep->driver_data = NULL;
...@@ -898,7 +890,7 @@ static void uvc_unbind(struct usb_configuration *c, struct usb_function *f) ...@@ -898,7 +890,7 @@ static void uvc_unbind(struct usb_configuration *c, struct usb_function *f)
INFO(cdev, "%s\n", __func__); INFO(cdev, "%s\n", __func__);
video_unregister_device(uvc->vdev); video_unregister_device(&uvc->vdev);
v4l2_device_unregister(&uvc->v4l2_dev); v4l2_device_unregister(&uvc->v4l2_dev);
uvc->control_ep->driver_data = NULL; uvc->control_ep->driver_data = NULL;
uvc->video.ep->driver_data = NULL; uvc->video.ep->driver_data = NULL;
......
...@@ -144,7 +144,7 @@ enum uvc_state ...@@ -144,7 +144,7 @@ enum uvc_state
struct uvc_device struct uvc_device
{ {
struct video_device *vdev; struct video_device vdev;
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
enum uvc_state state; enum uvc_state state;
struct usb_function func; struct usb_function func;
......
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