Commit bf715448 authored by Laurent Pinchart's avatar Laurent Pinchart

usb: gadget: uvc: configfs: Add interface number attributes

The video control and video streaming interface numbers are needed in
the UVC gadget userspace stack to reply to UVC requests. They are
hardcoded to fixed values at the moment, preventing configurations with
multiple functions.

To fix this, make them dynamically discoverable by userspace through
read-only configfs attributes in <function>/control/bInterfaceNumber and
<function>/streaming/bInterfaceNumber respectively.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: default avatarKieran Bingham <kieran.bingham@ideasonboard.com>
parent efbf0af7
...@@ -12,6 +12,10 @@ Date: Dec 2014 ...@@ -12,6 +12,10 @@ Date: Dec 2014
KernelVersion: 4.0 KernelVersion: 4.0
Description: Control descriptors Description: Control descriptors
All attributes read only:
bInterfaceNumber - USB interface number for this
streaming interface
What: /config/usb-gadget/gadget/functions/uvc.name/control/class What: /config/usb-gadget/gadget/functions/uvc.name/control/class
Date: Dec 2014 Date: Dec 2014
KernelVersion: 4.0 KernelVersion: 4.0
...@@ -109,6 +113,10 @@ Date: Dec 2014 ...@@ -109,6 +113,10 @@ Date: Dec 2014
KernelVersion: 4.0 KernelVersion: 4.0
Description: Streaming descriptors Description: Streaming descriptors
All attributes read only:
bInterfaceNumber - USB interface number for this
streaming interface
What: /config/usb-gadget/gadget/functions/uvc.name/streaming/class What: /config/usb-gadget/gadget/functions/uvc.name/streaming/class
Date: Dec 2014 Date: Dec 2014
KernelVersion: 4.0 KernelVersion: 4.0
......
...@@ -699,12 +699,14 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) ...@@ -699,12 +699,14 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
uvc_iad.bFirstInterface = ret; uvc_iad.bFirstInterface = ret;
uvc_control_intf.bInterfaceNumber = ret; uvc_control_intf.bInterfaceNumber = ret;
uvc->control_intf = ret; uvc->control_intf = ret;
opts->control_interface = ret;
if ((ret = usb_interface_id(c, f)) < 0) if ((ret = usb_interface_id(c, f)) < 0)
goto error; goto error;
uvc_streaming_intf_alt0.bInterfaceNumber = ret; uvc_streaming_intf_alt0.bInterfaceNumber = ret;
uvc_streaming_intf_alt1.bInterfaceNumber = ret; uvc_streaming_intf_alt1.bInterfaceNumber = ret;
uvc->streaming_intf = ret; uvc->streaming_intf = ret;
opts->streaming_interface = ret;
/* Copy descriptors */ /* Copy descriptors */
f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL); f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL);
......
...@@ -25,6 +25,9 @@ struct f_uvc_opts { ...@@ -25,6 +25,9 @@ struct f_uvc_opts {
unsigned int streaming_maxpacket; unsigned int streaming_maxpacket;
unsigned int streaming_maxburst; unsigned int streaming_maxburst;
unsigned int control_interface;
unsigned int streaming_interface;
/* /*
* Control descriptors array pointers for full-/high-speed and * Control descriptors array pointers for full-/high-speed and
* super-speed. They point by default to the uvc_fs_control_cls and * super-speed. They point by default to the uvc_fs_control_cls and
......
...@@ -713,9 +713,40 @@ static const struct uvcg_config_group_type uvcg_control_class_grp_type = { ...@@ -713,9 +713,40 @@ static const struct uvcg_config_group_type uvcg_control_class_grp_type = {
* control * control
*/ */
static ssize_t uvcg_default_control_b_interface_number_show(
struct config_item *item, char *page)
{
struct config_group *group = to_config_group(item);
struct mutex *su_mutex = &group->cg_subsys->su_mutex;
struct config_item *opts_item;
struct f_uvc_opts *opts;
int result = 0;
mutex_lock(su_mutex); /* for navigating configfs hierarchy */
opts_item = item->ci_parent;
opts = to_f_uvc_opts(opts_item);
mutex_lock(&opts->lock);
result += sprintf(page, "%u\n", opts->control_interface);
mutex_unlock(&opts->lock);
mutex_unlock(su_mutex);
return result;
}
UVC_ATTR_RO(uvcg_default_control_, b_interface_number, bInterfaceNumber);
static struct configfs_attribute *uvcg_default_control_attrs[] = {
&uvcg_default_control_attr_b_interface_number,
NULL,
};
static const struct uvcg_config_group_type uvcg_control_grp_type = { static const struct uvcg_config_group_type uvcg_control_grp_type = {
.type = { .type = {
.ct_item_ops = &uvcg_config_item_ops, .ct_item_ops = &uvcg_config_item_ops,
.ct_attrs = uvcg_default_control_attrs,
.ct_owner = THIS_MODULE, .ct_owner = THIS_MODULE,
}, },
.name = "control", .name = "control",
...@@ -2259,9 +2290,40 @@ static const struct uvcg_config_group_type uvcg_streaming_class_grp_type = { ...@@ -2259,9 +2290,40 @@ static const struct uvcg_config_group_type uvcg_streaming_class_grp_type = {
* streaming * streaming
*/ */
static ssize_t uvcg_default_streaming_b_interface_number_show(
struct config_item *item, char *page)
{
struct config_group *group = to_config_group(item);
struct mutex *su_mutex = &group->cg_subsys->su_mutex;
struct config_item *opts_item;
struct f_uvc_opts *opts;
int result = 0;
mutex_lock(su_mutex); /* for navigating configfs hierarchy */
opts_item = item->ci_parent;
opts = to_f_uvc_opts(opts_item);
mutex_lock(&opts->lock);
result += sprintf(page, "%u\n", opts->streaming_interface);
mutex_unlock(&opts->lock);
mutex_unlock(su_mutex);
return result;
}
UVC_ATTR_RO(uvcg_default_streaming_, b_interface_number, bInterfaceNumber);
static struct configfs_attribute *uvcg_default_streaming_attrs[] = {
&uvcg_default_streaming_attr_b_interface_number,
NULL,
};
static const struct uvcg_config_group_type uvcg_streaming_grp_type = { static const struct uvcg_config_group_type uvcg_streaming_grp_type = {
.type = { .type = {
.ct_item_ops = &uvcg_config_item_ops, .ct_item_ops = &uvcg_config_item_ops,
.ct_attrs = uvcg_default_streaming_attrs,
.ct_owner = THIS_MODULE, .ct_owner = THIS_MODULE,
}, },
.name = "streaming", .name = "streaming",
......
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