* usb: gadget: f_uvc: Expose configuration name through video node
@ 2018-05-24 13:30 Laurent Pinchart
0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2018-05-24 13:30 UTC (permalink / raw)
To: Kieran Bingham; +Cc: Paul Elder, Felipe Balbi, linux-usb, Kieran Bingham
Hi Kieran,
Thank you for the patch.
On Wednesday, 23 May 2018 23:39:47 EEST Kieran Bingham wrote:
> From: Kieran Bingham <kieran.bingham@ideasonboard.com>
>
> When utilising multiple instantiations of a UVC gadget on a composite
> device, there is no clear method to link a particular configuration to
> its respective video node.
>
> Provide a means for identifying the correct video node by exposing the
> name of the function configuration through sysfs.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
> drivers/usb/gadget/function/f_uvc.c | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/f_uvc.c
> b/drivers/usb/gadget/function/f_uvc.c index 1affa8e3a974..f326d1707633
> 100644
> --- a/drivers/usb/gadget/function/f_uvc.c
> +++ b/drivers/usb/gadget/function/f_uvc.c
> @@ -421,10 +421,21 @@ uvc_function_disconnect(struct uvc_device *uvc)
> * USB probe and disconnect
> */
>
> +static ssize_t config_show(struct device *dev, struct device_attribute
> *attr, + char *buf)
> +{
> + struct uvc_device *uvc = dev_get_drvdata(dev);
> +
> + return sprintf(buf, "%s\n", uvc->func.fi->group.cg_item.ci_name);
> +}
> +
> +static DEVICE_ATTR_RO(config);
You need to document the attribute in Documentation/ABI/.
I wonder whether we should use a more explicit name for the attribute. Maybe
function_name ? usb_function_name ? usb_configfs_name ? Feel free to propose a
better option.
> +
> static int
> uvc_register_video(struct uvc_device *uvc)
> {
> struct usb_composite_dev *cdev = uvc->func.config->cdev;
> + int ret;
>
> /* TODO reference counting. */
> uvc->vdev.v4l2_dev = &uvc->v4l2_dev;
> @@ -437,7 +448,17 @@ uvc_register_video(struct uvc_device *uvc)
>
> video_set_drvdata(&uvc->vdev, uvc);
>
> - return video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1);
> + ret = video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1);
> + if (ret < 0)
> + return ret;
> +
> + ret = device_create_file(&uvc->vdev.dev, &dev_attr_config);
> + if (ret < 0) {
> + video_unregister_device(&uvc->vdev);
> + return ret;
> + }
> +
> + return 0;
> }
>
> #define UVC_COPY_DESCRIPTOR(mem, dst, desc) \
> @@ -875,6 +896,7 @@ static void uvc_unbind(struct usb_configuration *c,
> struct usb_function *f)
>
> INFO(cdev, "%s\n", __func__);
>
> + device_remove_file(&uvc->vdev.dev, &dev_attr_config);
> video_unregister_device(&uvc->vdev);
> v4l2_device_unregister(&uvc->v4l2_dev);
^ permalink raw reply [flat|nested] 2+ messages in thread
* usb: gadget: f_uvc: Expose configuration name through video node
@ 2018-05-23 20:39 Kieran Bingham
0 siblings, 0 replies; 2+ messages in thread
From: Kieran Bingham @ 2018-05-23 20:39 UTC (permalink / raw)
To: Laurent Pinchart, Paul Elder, Felipe Balbi; +Cc: linux-usb, Kieran Bingham
From: Kieran Bingham <kieran.bingham@ideasonboard.com>
When utilising multiple instantiations of a UVC gadget on a composite
device, there is no clear method to link a particular configuration to
its respective video node.
Provide a means for identifying the correct video node by exposing the
name of the function configuration through sysfs.
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
drivers/usb/gadget/function/f_uvc.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 1affa8e3a974..f326d1707633 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -421,10 +421,21 @@ uvc_function_disconnect(struct uvc_device *uvc)
* USB probe and disconnect
*/
+static ssize_t config_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct uvc_device *uvc = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%s\n", uvc->func.fi->group.cg_item.ci_name);
+}
+
+static DEVICE_ATTR_RO(config);
+
static int
uvc_register_video(struct uvc_device *uvc)
{
struct usb_composite_dev *cdev = uvc->func.config->cdev;
+ int ret;
/* TODO reference counting. */
uvc->vdev.v4l2_dev = &uvc->v4l2_dev;
@@ -437,7 +448,17 @@ uvc_register_video(struct uvc_device *uvc)
video_set_drvdata(&uvc->vdev, uvc);
- return video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1);
+ ret = video_register_device(&uvc->vdev, VFL_TYPE_GRABBER, -1);
+ if (ret < 0)
+ return ret;
+
+ ret = device_create_file(&uvc->vdev.dev, &dev_attr_config);
+ if (ret < 0) {
+ video_unregister_device(&uvc->vdev);
+ return ret;
+ }
+
+ return 0;
}
#define UVC_COPY_DESCRIPTOR(mem, dst, desc) \
@@ -875,6 +896,7 @@ static void uvc_unbind(struct usb_configuration *c, struct usb_function *f)
INFO(cdev, "%s\n", __func__);
+ device_remove_file(&uvc->vdev.dev, &dev_attr_config);
video_unregister_device(&uvc->vdev);
v4l2_device_unregister(&uvc->v4l2_dev);
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-24 13:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-24 13:30 usb: gadget: f_uvc: Expose configuration name through video node Laurent Pinchart
-- strict thread matches above, loose matches on Subject: below --
2018-05-23 20:39 Kieran Bingham
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.