Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: f_uac2: Expose all string descriptors through configfs.

This makes all string descriptors configurable for the UAC2 gadget
so the user can configure names of terminals and controls. Alt mode
names are not included for now and will be in future work related
to adding alternate settings.

discussion thread for api changes for alt mode settings:
https://lore.kernel.org/linux-usb/35be4668-58d3-894a-72cf-de1afaacae45@ivitera.com/T/

Signed-off-by: Chris Wulff <chris.wulff@biamp.com>
Link: https://lore.kernel.org/r/20240804001923.3279431-2-crwulff@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Chris Wulff and committed by
Greg Kroah-Hartman
8952e50e 2919d888

+99 -18
+11
Documentation/ABI/testing/configfs-usb-gadget-uac2
··· 35 35 req_number the number of pre-allocated requests 36 36 for both capture and playback 37 37 function_name name of the interface 38 + if_ctrl_name topology control name 39 + clksrc_in_name input clock name 40 + clksrc_out_name output clock name 41 + p_it_name playback input terminal name 42 + p_it_ch_name playback input first channel name 43 + p_ot_name playback output terminal name 44 + p_fu_vol_name playback mute/volume function unit name 45 + c_it_name capture input terminal name 46 + c_it_ch_name capture input first channel name 47 + c_ot_name capture output terminal name 48 + c_fu_vol_name capture mute/volume functional unit name 38 49 c_terminal_type code of the capture terminal type 39 50 p_terminal_type code of the playback terminal type 40 51 ===================== =======================================
+11
Documentation/usb/gadget-testing.rst
··· 765 765 req_number the number of pre-allocated request for both capture 766 766 and playback 767 767 function_name name of the interface 768 + if_ctrl_name topology control name 769 + clksrc_in_name input clock name 770 + clksrc_out_name output clock name 771 + p_it_name playback input terminal name 772 + p_it_ch_name playback input first channel name 773 + p_ot_name playback output terminal name 774 + p_fu_vol_name playback function unit name 775 + c_it_name capture input terminal name 776 + c_it_ch_name capture input first channel name 777 + c_ot_name capture output terminal name 778 + c_fu_vol_name capture functional unit name 768 779 c_terminal_type code of the capture terminal type 769 780 p_terminal_type code of the playback terminal type 770 781 ================ ====================================================
+63 -17
drivers/usb/gadget/function/f_uac2.c
··· 95 95 STR_CLKSRC_IN, 96 96 STR_CLKSRC_OUT, 97 97 STR_USB_IT, 98 + STR_USB_IT_CH, 98 99 STR_IO_IT, 100 + STR_IO_IT_CH, 99 101 STR_USB_OT, 100 102 STR_IO_OT, 101 103 STR_FU_IN, ··· 106 104 STR_AS_OUT_ALT1, 107 105 STR_AS_IN_ALT0, 108 106 STR_AS_IN_ALT1, 107 + NUM_STR_DESCRIPTORS, 109 108 }; 110 109 111 - static struct usb_string strings_fn[] = { 112 - /* [STR_ASSOC].s = DYNAMIC, */ 113 - [STR_IF_CTRL].s = "Topology Control", 114 - [STR_CLKSRC_IN].s = "Input Clock", 115 - [STR_CLKSRC_OUT].s = "Output Clock", 116 - [STR_USB_IT].s = "USBH Out", 117 - [STR_IO_IT].s = "USBD Out", 118 - [STR_USB_OT].s = "USBH In", 119 - [STR_IO_OT].s = "USBD In", 120 - [STR_FU_IN].s = "Capture Volume", 121 - [STR_FU_OUT].s = "Playback Volume", 122 - [STR_AS_OUT_ALT0].s = "Playback Inactive", 123 - [STR_AS_OUT_ALT1].s = "Playback Active", 124 - [STR_AS_IN_ALT0].s = "Capture Inactive", 125 - [STR_AS_IN_ALT1].s = "Capture Active", 126 - { }, 127 - }; 110 + static struct usb_string strings_fn[NUM_STR_DESCRIPTORS + 1] = {}; 128 111 129 112 static const char *const speed_names[] = { 130 113 [USB_SPEED_UNKNOWN] = "UNKNOWN", ··· 1036 1049 return ret; 1037 1050 1038 1051 strings_fn[STR_ASSOC].s = uac2_opts->function_name; 1052 + strings_fn[STR_IF_CTRL].s = uac2_opts->if_ctrl_name; 1053 + strings_fn[STR_CLKSRC_IN].s = uac2_opts->clksrc_in_name; 1054 + strings_fn[STR_CLKSRC_OUT].s = uac2_opts->clksrc_out_name; 1055 + 1056 + strings_fn[STR_USB_IT].s = uac2_opts->c_it_name; 1057 + strings_fn[STR_USB_IT_CH].s = uac2_opts->c_it_ch_name; 1058 + strings_fn[STR_IO_OT].s = uac2_opts->c_ot_name; 1059 + strings_fn[STR_FU_OUT].s = uac2_opts->c_fu_vol_name; 1060 + strings_fn[STR_AS_OUT_ALT0].s = "Playback Inactive"; 1061 + strings_fn[STR_AS_OUT_ALT1].s = "Playback Active"; 1062 + 1063 + strings_fn[STR_IO_IT].s = uac2_opts->p_it_name; 1064 + strings_fn[STR_IO_IT_CH].s = uac2_opts->p_it_ch_name; 1065 + strings_fn[STR_USB_OT].s = uac2_opts->p_ot_name; 1066 + strings_fn[STR_FU_IN].s = uac2_opts->p_fu_vol_name; 1067 + strings_fn[STR_AS_IN_ALT0].s = "Capture Inactive"; 1068 + strings_fn[STR_AS_IN_ALT1].s = "Capture Active"; 1039 1069 1040 1070 us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn)); 1041 1071 if (IS_ERR(us)) ··· 1076 1072 in_clk_src_desc.iClockSource = us[STR_CLKSRC_IN].id; 1077 1073 out_clk_src_desc.iClockSource = us[STR_CLKSRC_OUT].id; 1078 1074 usb_out_it_desc.iTerminal = us[STR_USB_IT].id; 1075 + usb_out_it_desc.iChannelNames = us[STR_USB_IT_CH].id; 1079 1076 io_in_it_desc.iTerminal = us[STR_IO_IT].id; 1077 + io_in_it_desc.iChannelNames = us[STR_IO_IT_CH].id; 1080 1078 usb_in_ot_desc.iTerminal = us[STR_USB_OT].id; 1081 1079 io_out_ot_desc.iTerminal = us[STR_IO_OT].id; 1082 1080 std_as_out_if0_desc.iInterface = us[STR_AS_OUT_ALT0].id; ··· 2106 2100 UAC2_ATTRIBUTE(s16, c_volume_res); 2107 2101 UAC2_ATTRIBUTE(u32, fb_max); 2108 2102 UAC2_ATTRIBUTE_STRING(function_name); 2103 + UAC2_ATTRIBUTE_STRING(if_ctrl_name); 2104 + UAC2_ATTRIBUTE_STRING(clksrc_in_name); 2105 + UAC2_ATTRIBUTE_STRING(clksrc_out_name); 2106 + 2107 + UAC2_ATTRIBUTE_STRING(p_it_name); 2108 + UAC2_ATTRIBUTE_STRING(p_it_ch_name); 2109 + UAC2_ATTRIBUTE_STRING(p_ot_name); 2110 + UAC2_ATTRIBUTE_STRING(p_fu_vol_name); 2111 + 2112 + UAC2_ATTRIBUTE_STRING(c_it_name); 2113 + UAC2_ATTRIBUTE_STRING(c_it_ch_name); 2114 + UAC2_ATTRIBUTE_STRING(c_ot_name); 2115 + UAC2_ATTRIBUTE_STRING(c_fu_vol_name); 2109 2116 2110 2117 UAC2_ATTRIBUTE(s16, p_terminal_type); 2111 2118 UAC2_ATTRIBUTE(s16, c_terminal_type); 2119 + 2112 2120 2113 2121 static struct configfs_attribute *f_uac2_attrs[] = { 2114 2122 &f_uac2_opts_attr_p_chmask, ··· 2150 2130 &f_uac2_opts_attr_c_volume_res, 2151 2131 2152 2132 &f_uac2_opts_attr_function_name, 2133 + &f_uac2_opts_attr_if_ctrl_name, 2134 + &f_uac2_opts_attr_clksrc_in_name, 2135 + &f_uac2_opts_attr_clksrc_out_name, 2136 + 2137 + &f_uac2_opts_attr_p_it_name, 2138 + &f_uac2_opts_attr_p_it_ch_name, 2139 + &f_uac2_opts_attr_p_ot_name, 2140 + &f_uac2_opts_attr_p_fu_vol_name, 2141 + 2142 + &f_uac2_opts_attr_c_it_name, 2143 + &f_uac2_opts_attr_c_it_ch_name, 2144 + &f_uac2_opts_attr_c_ot_name, 2145 + &f_uac2_opts_attr_c_fu_vol_name, 2153 2146 2154 2147 &f_uac2_opts_attr_p_terminal_type, 2155 2148 &f_uac2_opts_attr_c_terminal_type, ··· 2224 2191 opts->fb_max = FBACK_FAST_MAX; 2225 2192 2226 2193 scnprintf(opts->function_name, sizeof(opts->function_name), "Source/Sink"); 2194 + scnprintf(opts->if_ctrl_name, sizeof(opts->if_ctrl_name), "Topology Control"); 2195 + scnprintf(opts->clksrc_in_name, sizeof(opts->clksrc_in_name), "Input Clock"); 2196 + scnprintf(opts->clksrc_out_name, sizeof(opts->clksrc_out_name), "Output Clock"); 2197 + 2198 + scnprintf(opts->p_it_name, sizeof(opts->p_it_name), "USBD Out"); 2199 + scnprintf(opts->p_it_ch_name, sizeof(opts->p_it_ch_name), "Capture Channels"); 2200 + scnprintf(opts->p_ot_name, sizeof(opts->p_ot_name), "USBH In"); 2201 + scnprintf(opts->p_fu_vol_name, sizeof(opts->p_fu_vol_name), "Capture Volume"); 2202 + 2203 + scnprintf(opts->c_it_name, sizeof(opts->c_it_name), "USBH Out"); 2204 + scnprintf(opts->c_it_ch_name, sizeof(opts->c_it_ch_name), "Playback Channels"); 2205 + scnprintf(opts->c_ot_name, sizeof(opts->c_ot_name), "USBD In"); 2206 + scnprintf(opts->c_fu_vol_name, sizeof(opts->c_fu_vol_name), "Playback Volume"); 2227 2207 2228 2208 opts->p_terminal_type = UAC2_DEF_P_TERM_TYPE; 2229 2209 opts->c_terminal_type = UAC2_DEF_C_TERM_TYPE;
+14 -1
drivers/usb/gadget/function/u_uac2.h
··· 68 68 int fb_max; 69 69 bool bound; 70 70 71 - char function_name[32]; 71 + char function_name[USB_MAX_STRING_LEN]; 72 + char if_ctrl_name[USB_MAX_STRING_LEN]; 73 + char clksrc_in_name[USB_MAX_STRING_LEN]; 74 + char clksrc_out_name[USB_MAX_STRING_LEN]; 75 + 76 + char p_it_name[USB_MAX_STRING_LEN]; 77 + char p_it_ch_name[USB_MAX_STRING_LEN]; 78 + char p_ot_name[USB_MAX_STRING_LEN]; 79 + char p_fu_vol_name[USB_MAX_STRING_LEN]; 80 + 81 + char c_it_name[USB_MAX_STRING_LEN]; 82 + char c_it_ch_name[USB_MAX_STRING_LEN]; 83 + char c_ot_name[USB_MAX_STRING_LEN]; 84 + char c_fu_vol_name[USB_MAX_STRING_LEN]; 72 85 73 86 s16 p_terminal_type; 74 87 s16 c_terminal_type;