Skip to contentSkip to conversation

usb: gadget: uvc: allow changing interface name via configfs

PATCH In review Dan Vacura 3 participants 5 messages Apr 1, 2022 – Apr 4, 2022

Subsystems (3)
lore
Share & tools
lore

Dan Vacura

author
#0 lore raw

PATCH v2 1/1 usb: gadget: uvc: allow changing interface name via configfs

Add a configfs entry, "function_name", to change the iInterface field for VideoControl. This name is used on host devices for user selection, useful when multiple cameras are present. The default will remain "UVC Camera".

---
Changes in v2:
- remove stable cc

 .../ABI/testing/configfs-usb-gadget-uvc       |  1 +
 Documentation/usb/gadget-testing.rst          |  1 +
 drivers/usb/gadget/function/f_uvc.c           |  4 +-
 drivers/usb/gadget/function/u_uvc.h           |  1 +
 drivers/usb/gadget/function/uvc_configfs.c    | 41 +++++++++++++++++++
 5 files changed, 47 insertions(+), 1 deletion(-)
Documentation/ABI/testing/configfs-usb-gadget-uvc +1 -0
index 889ed45be4ca..611b23e6488d 100644
@@ -7,6 +7,7 @@ Description:	UVC function directory
 		streaming_maxburst	0..15 (ss only)
 		streaming_maxpacket	1..1023 (fs), 1..3072 (hs/ss)
 		streaming_interval	1..16
+		function_name		string [32]
 		===================	=============================
 
 What:		/config/usb-gadget/gadget/functions/uvc.name/control
Documentation/usb/gadget-testing.rst +1 -0
index c6d034abce3a..1c37159fa171 100644
@@ -787,6 +787,7 @@ The uvc function provides these attributes in its function directory:
 	streaming_maxpacket maximum packet size this endpoint is capable of
 			    sending or receiving when this configuration is
 			    selected
+	function_name       name of the interface
 	=================== ================================================
 
 There are also "control" and "streaming" subdirectories, each of which contain
drivers/usb/gadget/function/f_uvc.c +3 -1
index 71bb5e477dba..50e6e7a58b41 100644
@@ -44,7 +44,7 @@ MODULE_PARM_DESC(trace, "Trace level bitmask");
 #define UVC_STRING_STREAMING_IDX		1
 
 static struct usb_string uvc_en_us_strings[] = {
-	[UVC_STRING_CONTROL_IDX].s = "UVC Camera",
+	/* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */
 	[UVC_STRING_STREAMING_IDX].s = "Video Streaming",
 	{  }
 };
@@ -676,6 +676,7 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
 	uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
 	uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address;
 
+	uvc_en_us_strings[UVC_STRING_CONTROL_IDX].s = opts->function_name;
 	us = usb_gstrings_attach(cdev, uvc_function_strings,
 				 ARRAY_SIZE(uvc_en_us_strings));
 	if (IS_ERR(us)) {
@@ -866,6 +867,7 @@ static struct usb_function_instance *uvc_alloc_inst(void)
 
 	opts->streaming_interval = 1;
 	opts->streaming_maxpacket = 1024;
+	snprintf(opts->function_name, sizeof(opts->function_name), "UVC Camera");
 
 	ret = uvcg_attach_configfs(opts);
 	if (ret < 0) {
drivers/usb/gadget/function/u_uvc.h +1 -0
index 9a01a7d4f17f..24b8681b0d6f 100644
@@ -27,6 +27,7 @@ struct f_uvc_opts {
 
 	unsigned int					control_interface;
 	unsigned int					streaming_interface;
+	char						function_name[32];
 
 	/*
 	 * Control descriptors array pointers for full-/high-speed and
drivers/usb/gadget/function/uvc_configfs.c +41 -0

51 lines not on this page · raw message

Signature · 1 line
2.32.0
#1 lore raw
Quoted 27 lines · Dan Vacura

Add a configfs entry, "function_name", to change the iInterface field for VideoControl. This name is used on host devices for user selection, useful when multiple cameras are present. The default will remain "UVC Camera".

drivers/usb/gadget/function/f_uvc.c +2 -1
index 71bb5e477dba..50e6e7a58b41 100644
@@ -44,7 +44,7 @@ MODULE_PARM_DESC(trace, "Trace level bitmask");
 #define UVC_STRING_STREAMING_IDX		1
 
 static struct usb_string uvc_en_us_strings[] = {
-	[UVC_STRING_CONTROL_IDX].s = "UVC Camera",
+	/* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */
 	[UVC_STRING_STREAMING_IDX].s = "Video Streaming",
 	{  }
 };
@@ -676,6 +676,7 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
 	uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
 	uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address;
 
+	uvc_en_us_strings[UVC_STRING_CONTROL_IDX].s = opts->function_name;
 	us = usb_gstrings_attach(cdev, uvc_function_strings,
 				 ARRAY_SIZE(uvc_en_us_strings));
 	if (IS_ERR(us)) {

drivers/usb/gadget/function/f_uvc.c static struct usb_function_instance *uvc_alloc_inst(void) · line 870

Quoted 4 lines
drivers/usb/gadget/function/f_uvc.c +1 -0
@@ -866,6 +867,7 @@ static struct usb_function_instance *uvc_alloc_inst(void)
 
 	opts->streaming_interval = 1;
 	opts->streaming_maxpacket = 1024;
+	snprintf(opts->function_name, sizeof(opts->function_name), "UVC Camera");

This only allows a single language to be specified. I know that's what the existing string uses, but for other strings which can be set by userspace multiple languages are supported.

Should we be making USB_CONFIG_STRINGS_LANG more generic so that it can be used by functions as well as the core configfs code?

#3 lore raw
In reply to Dan Vacura
Quoted 22 lines · Dan Vacura

Add a configfs entry, "function_name", to change the iInterface field for VideoControl. This name is used on host devices for user selection, useful when multiple cameras are present. The default will remain "UVC Camera".

---
Changes in v2:
- remove stable cc

  .../ABI/testing/configfs-usb-gadget-uvc       |  1 +
  Documentation/usb/gadget-testing.rst          |  1 +
  drivers/usb/gadget/function/f_uvc.c           |  4 +-
  drivers/usb/gadget/function/u_uvc.h           |  1 +
  drivers/usb/gadget/function/uvc_configfs.c    | 41 +++++++++++++++++++
  5 files changed, 47 insertions(+), 1 deletion(-)
Documentation/ABI/testing/configfs-usb-gadget-uvc +0 -0
index 889ed45be4ca..611b23e6488d 100644

Documentation/ABI/testing/configfs-usb-gadget-uvc Description: UVC function directory · line 11

Quoted 5 lines
Documentation/ABI/testing/configfs-usb-gadget-uvc +1 -0
@@ -7,6 +7,7 @@ Description:	UVC function directory
  		streaming_maxburst	0..15 (ss only)
  		streaming_maxpacket	1..1023 (fs), 1..3072 (hs/ss)
  		streaming_interval	1..16
+		function_name		string [32]
  		===================	=============================

Since you mention that default function_name is "UVC Camera", why don't you mention it in the documentation?

Signature · 1 line
An old man doll... just what I always wanted! - Clara
author
#4 lore raw
Quoted 18 lines · Bagas Sanjaya
Quoted 17 lines · Dan Vacura

Add a configfs entry, "function_name", to change the iInterface field for VideoControl. This name is used on host devices for user selection, useful when multiple cameras are present. The default will remain "UVC Camera".

---
Changes in v2:
- remove stable cc

  .../ABI/testing/configfs-usb-gadget-uvc       |  1 +
  Documentation/usb/gadget-testing.rst          |  1 +
  drivers/usb/gadget/function/f_uvc.c           |  4 +-
  drivers/usb/gadget/function/u_uvc.h           |  1 +
  drivers/usb/gadget/function/uvc_configfs.c    | 41 +++++++++++++++++++
  5 files changed, 47 insertions(+), 1 deletion(-)
Quoted 13 lines

Documentation/ABI/testing/configfs-usb-gadget-uvc Description: UVC function directory · line 11

Quoted 10 lines
Documentation/ABI/testing/configfs-usb-gadget-uvc +1 -0
index 889ed45be4ca..611b23e6488d 100644
@@ -7,6 +7,7 @@ Description:	UVC function directory
  		streaming_maxburst	0..15 (ss only)
  		streaming_maxpacket	1..1023 (fs), 1..3072 (hs/ss)
  		streaming_interval	1..16
+		function_name		string [32]
  		===================	=============================

Since you mention that default function_name is "UVC Camera", why don't you mention it in the documentation?

Good question. The rest of the file didn't contain any default values and I wasn't sure what the process is for keeping things like this in sync between source and documentation. Looking through most of the other usb function files I don't see any mention of the hardcoded default values either, so maybe it's intentional to not include.

Quoted 3 lines
Signature · 2 lines
-- 
An old man doll... just what I always wanted! - Clara
author
#2 lore raw
In reply to John Keeping
Quoted 37 lines · John Keeping
Quoted 27 lines · Dan Vacura

Add a configfs entry, "function_name", to change the iInterface field for VideoControl. This name is used on host devices for user selection, useful when multiple cameras are present. The default will remain "UVC Camera".

drivers/usb/gadget/function/f_uvc.c +2 -1
index 71bb5e477dba..50e6e7a58b41 100644
@@ -44,7 +44,7 @@ MODULE_PARM_DESC(trace, "Trace level bitmask");
 #define UVC_STRING_STREAMING_IDX		1
 
 static struct usb_string uvc_en_us_strings[] = {
-	[UVC_STRING_CONTROL_IDX].s = "UVC Camera",
+	/* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */
 	[UVC_STRING_STREAMING_IDX].s = "Video Streaming",
 	{  }
 };
@@ -676,6 +676,7 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
 	uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
 	uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address;
 
+	uvc_en_us_strings[UVC_STRING_CONTROL_IDX].s = opts->function_name;
 	us = usb_gstrings_attach(cdev, uvc_function_strings,
 				 ARRAY_SIZE(uvc_en_us_strings));
 	if (IS_ERR(us)) {

drivers/usb/gadget/function/f_uvc.c static struct usb_function_instance *uvc_alloc_inst(void) · line 870

Quoted 4 lines
drivers/usb/gadget/function/f_uvc.c +1 -0
@@ -866,6 +867,7 @@ static struct usb_function_instance *uvc_alloc_inst(void)
 
 	opts->streaming_interval = 1;
 	opts->streaming_maxpacket = 1024;
+	snprintf(opts->function_name, sizeof(opts->function_name), "UVC Camera");

This only allows a single language to be specified. I know that's what the existing string uses, but for other strings which can be set by userspace multiple languages are supported.

Quoted 2 lines

Should we be making USB_CONFIG_STRINGS_LANG more generic so that it can be used by functions as well as the core configfs code?

Agree that adding support for more than one language would be ideal. Looking through the gadget functions, most seem to be hardcoded to en-us locale and don't provide a way to change the exposed names. Recently this was just accepted, which I modeled my change after:
https://lore.kernel.org/all/[email protected]/
so at least making USB_CONFIG_STRINGS_LANG more generic would benefit the uac and uvc gadgets.