[PATCH RFC 06/14] usb: gadget: f_uac1: Add terminal type attributes

crwulff@gmail.com posted 14 patches 2 months ago
[PATCH RFC 06/14] usb: gadget: f_uac1: Add terminal type attributes
Posted by crwulff@gmail.com 2 months ago
From: Chris Wulff <crwulff@gmail.com>

Allow the user to set the terminal types. This matches the options
in f_uac2.

Signed-off-by: Chris Wulff <crwulff@gmail.com>
---
 Documentation/ABI/testing/configfs-usb-gadget-uac1 |  2 ++
 Documentation/usb/gadget-testing.rst               |  2 ++
 drivers/usb/gadget/function/f_uac1.c               | 11 +++++++++++
 drivers/usb/gadget/function/u_uac1.h               |  5 +++++
 4 files changed, 20 insertions(+)

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uac1 b/Documentation/ABI/testing/configfs-usb-gadget-uac1
index fed8567b10ec..9f7f626329e7 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-uac1
+++ b/Documentation/ABI/testing/configfs-usb-gadget-uac1
@@ -43,4 +43,6 @@ Description:
 		c_it_ch_name		capture channels name
 		c_ot_name		capture output terminal name
 		c_fu_vol_name		capture mute/volume functional unit name
+		c_terminal_type		code of the capture terminal type
+		p_terminal_type		code of the playback terminal type
 		=====================	=======================================
diff --git a/Documentation/usb/gadget-testing.rst b/Documentation/usb/gadget-testing.rst
index bdb82b58b260..53c2518dbf50 100644
--- a/Documentation/usb/gadget-testing.rst
+++ b/Documentation/usb/gadget-testing.rst
@@ -980,6 +980,8 @@ The uac1 function provides these attributes in its function directory:
 	c_it_ch_name     capture channels name
 	c_ot_name        capture output terminal name
 	c_fu_vol_name    capture mute/volume functional unit name
+	c_terminal_type  code of the capture terminal type
+	p_terminal_type  code of the playback terminal type
 	================ ====================================================
 
 The attributes have sane default values.
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 861e6219552e..5813fe3e7146 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -1277,6 +1277,8 @@ static void setup_descriptor(struct f_uac1_opts *opts)
 	as_out_header_desc.bTerminalLink = usb_out_it_desc.bTerminalID;
 	as_in_header_desc.bTerminalLink = usb_in_ot_desc.bTerminalID;
 
+	io_in_it_desc.wTerminalType = cpu_to_le16(opts->c_terminal_type);
+	io_out_ot_desc.wTerminalType = cpu_to_le16(opts->p_terminal_type);
 	ac_header_desc->wTotalLength = cpu_to_le16(ac_header_desc->bLength);
 
 	if (EPIN_EN(opts)) {
@@ -1898,6 +1900,9 @@ UAC1_ATTRIBUTE_STRING(c_it_ch_name);
 UAC1_ATTRIBUTE_STRING(c_ot_name);
 UAC1_ATTRIBUTE_STRING(c_fu_vol_name);
 
+UAC1_ATTRIBUTE(s16, p_terminal_type);
+UAC1_ATTRIBUTE(s16, c_terminal_type);
+
 static struct configfs_attribute *f_uac1_attrs[] = {
 	&f_uac1_opts_attr_c_chmask,
 	&f_uac1_opts_attr_c_srate,
@@ -1935,6 +1940,9 @@ static struct configfs_attribute *f_uac1_attrs[] = {
 	&f_uac1_opts_attr_c_ot_name,
 	&f_uac1_opts_attr_c_fu_vol_name,
 
+	&f_uac1_opts_attr_p_terminal_type,
+	&f_uac1_opts_attr_c_terminal_type,
+
 	NULL,
 };
 
@@ -2003,6 +2011,9 @@ static struct usb_function_instance *f_audio_alloc_inst(void)
 	scnprintf(opts->c_ot_name, sizeof(opts->c_ot_name), "Playback Output terminal");
 	scnprintf(opts->c_fu_vol_name, sizeof(opts->c_fu_vol_name), "Playback Volume");
 
+	opts->p_terminal_type = UAC1_DEF_P_TERM_TYPE;
+	opts->c_terminal_type = UAC1_DEF_C_TERM_TYPE;
+
 	return &opts->func_inst;
 }
 
diff --git a/drivers/usb/gadget/function/u_uac1.h b/drivers/usb/gadget/function/u_uac1.h
index c7e7480bf71f..df29018096d3 100644
--- a/drivers/usb/gadget/function/u_uac1.h
+++ b/drivers/usb/gadget/function/u_uac1.h
@@ -30,6 +30,8 @@
 #define UAC1_DEF_MAX_DB		0		/* 0 dB */
 #define UAC1_DEF_RES_DB		(1*256)	/* 1 dB */
 
+#define UAC1_DEF_P_TERM_TYPE UAC_INPUT_TERMINAL_MICROPHONE
+#define UAC1_DEF_C_TERM_TYPE UAC_OUTPUT_TERMINAL_SPEAKER
 
 struct f_uac1_opts {
 	struct usb_function_instance	func_inst;
@@ -71,6 +73,9 @@ struct f_uac1_opts {
 	char			c_ot_name[USB_MAX_STRING_LEN];
 	char			c_fu_vol_name[USB_MAX_STRING_LEN];
 
+	s16				p_terminal_type;
+	s16				c_terminal_type;
+
 	struct mutex			lock;
 	int				refcnt;
 };
-- 
2.43.0