This makes all string descriptors configurable for the UAC1 gadget so the user can configure names of terminals/controls/alt modes. Signed-off-by: Chris Wulff <chris.wulff@xxxxxxxxx> --- drivers/usb/gadget/function/f_uac1.c | 66 +++++++++++++++++++++------- drivers/usb/gadget/function/u_uac1.h | 14 +++++- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 7de74a3dd392..100169d6dca7 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c @@ -377,24 +377,10 @@ enum { STR_AS_OUT_IF_ALT1, STR_AS_IN_IF_ALT0, STR_AS_IN_IF_ALT1, + NUM_STR_DESCRIPTORS, }; -static struct usb_string strings_uac1[] = { - /* [STR_AC_IF].s = DYNAMIC, */ - [STR_USB_OUT_IT].s = "Playback Input terminal", - [STR_USB_OUT_IT_CH_NAMES].s = "Playback Channels", - [STR_IO_OUT_OT].s = "Playback Output terminal", - [STR_IO_IN_IT].s = "Capture Input terminal", - [STR_IO_IN_IT_CH_NAMES].s = "Capture Channels", - [STR_USB_IN_OT].s = "Capture Output terminal", - [STR_FU_IN].s = "Capture Volume", - [STR_FU_OUT].s = "Playback Volume", - [STR_AS_OUT_IF_ALT0].s = "Playback Inactive", - [STR_AS_OUT_IF_ALT1].s = "Playback Active", - [STR_AS_IN_IF_ALT0].s = "Capture Inactive", - [STR_AS_IN_IF_ALT1].s = "Capture Active", - { }, -}; +static struct usb_string strings_uac1[NUM_STR_DESCRIPTORS + 1] = {}; static struct usb_gadget_strings str_uac1 = { .language = 0x0409, /* en-us */ @@ -1264,6 +1250,18 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst); strings_uac1[STR_AC_IF].s = audio_opts->function_name; + strings_uac1[STR_USB_OUT_IT].s = audio_opts->usb_out_it_string; + strings_uac1[STR_USB_OUT_IT_CH_NAMES].s = audio_opts->usb_out_it_ch_name_string; + strings_uac1[STR_IO_OUT_OT].s = audio_opts->io_out_ot_string; + strings_uac1[STR_IO_IN_IT].s = audio_opts->io_in_it_string; + strings_uac1[STR_IO_IN_IT_CH_NAMES].s = audio_opts->io_in_it_ch_name_string; + strings_uac1[STR_USB_IN_OT].s = audio_opts->usb_in_ot_string; + strings_uac1[STR_FU_IN].s = audio_opts->fu_in_string; + strings_uac1[STR_FU_OUT].s = audio_opts->fu_out_string; + strings_uac1[STR_AS_OUT_IF_ALT0].s = audio_opts->as_out_if_alt0_string; + strings_uac1[STR_AS_OUT_IF_ALT1].s = audio_opts->as_out_if_alt1_string; + strings_uac1[STR_AS_IN_IF_ALT0].s = audio_opts->as_in_if_alt0_string; + strings_uac1[STR_AS_IN_IF_ALT1].s = audio_opts->as_in_if_alt1_string; us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1)); if (IS_ERR(us)) @@ -1682,6 +1680,18 @@ UAC1_ATTRIBUTE(s16, c_volume_min); UAC1_ATTRIBUTE(s16, c_volume_max); UAC1_ATTRIBUTE(s16, c_volume_res); UAC1_ATTRIBUTE_STRING(function_name); +UAC1_ATTRIBUTE_STRING(usb_out_it_string); +UAC1_ATTRIBUTE_STRING(usb_out_it_ch_name_string); +UAC1_ATTRIBUTE_STRING(io_out_ot_string); +UAC1_ATTRIBUTE_STRING(io_in_it_string); +UAC1_ATTRIBUTE_STRING(io_in_it_ch_name_string); +UAC1_ATTRIBUTE_STRING(usb_in_ot_string); +UAC1_ATTRIBUTE_STRING(fu_in_string); +UAC1_ATTRIBUTE_STRING(fu_out_string); +UAC1_ATTRIBUTE_STRING(as_out_if_alt0_string); +UAC1_ATTRIBUTE_STRING(as_out_if_alt1_string); +UAC1_ATTRIBUTE_STRING(as_in_if_alt0_string); +UAC1_ATTRIBUTE_STRING(as_in_if_alt1_string); static struct configfs_attribute *f_uac1_attrs[] = { &f_uac1_opts_attr_c_chmask, @@ -1705,6 +1715,18 @@ static struct configfs_attribute *f_uac1_attrs[] = { &f_uac1_opts_attr_c_volume_res, &f_uac1_opts_attr_function_name, + &f_uac1_opts_attr_usb_out_it_string, + &f_uac1_opts_attr_usb_out_it_ch_name_string, + &f_uac1_opts_attr_io_out_ot_string, + &f_uac1_opts_attr_io_in_it_string, + &f_uac1_opts_attr_io_in_it_ch_name_string, + &f_uac1_opts_attr_usb_in_ot_string, + &f_uac1_opts_attr_fu_in_string, + &f_uac1_opts_attr_fu_out_string, + &f_uac1_opts_attr_as_out_if_alt0_string, + &f_uac1_opts_attr_as_out_if_alt1_string, + &f_uac1_opts_attr_as_in_if_alt0_string, + &f_uac1_opts_attr_as_in_if_alt1_string, NULL, }; @@ -1759,6 +1781,18 @@ static struct usb_function_instance *f_audio_alloc_inst(void) opts->req_number = UAC1_DEF_REQ_NUM; scnprintf(opts->function_name, sizeof(opts->function_name), "AC Interface"); + scnprintf(opts->usb_out_it_string, sizeof(opts->usb_out_it_string), "Playback Input terminal"); + scnprintf(opts->usb_out_it_ch_name_string, sizeof(opts->usb_out_it_ch_name_string), "Playback Channels"); + scnprintf(opts->io_out_ot_string, sizeof(opts->io_out_ot_string), "Playback Output terminal"); + scnprintf(opts->io_in_it_string, sizeof(opts->io_in_it_string), "Capture Input terminal"); + scnprintf(opts->io_in_it_ch_name_string, sizeof(opts->io_in_it_ch_name_string), "Capture Channels"); + scnprintf(opts->usb_in_ot_string, sizeof(opts->usb_in_ot_string), "Capture Output terminal"); + scnprintf(opts->fu_in_string, sizeof(opts->fu_in_string), "Capture Volume"); + scnprintf(opts->fu_out_string, sizeof(opts->fu_out_string), "Playback Volume"); + scnprintf(opts->as_out_if_alt0_string, sizeof(opts->as_out_if_alt0_string), "Playback Inactive"); + scnprintf(opts->as_out_if_alt1_string, sizeof(opts->as_out_if_alt1_string), "Playback Active"); + scnprintf(opts->as_in_if_alt0_string, sizeof(opts->as_in_if_alt0_string), "Capture Inactive"); + scnprintf(opts->as_in_if_alt1_string, sizeof(opts->as_in_if_alt1_string), "Capture Active"); return &opts->func_inst; } diff --git a/drivers/usb/gadget/function/u_uac1.h b/drivers/usb/gadget/function/u_uac1.h index f7a616760e31..818a335a309a 100644 --- a/drivers/usb/gadget/function/u_uac1.h +++ b/drivers/usb/gadget/function/u_uac1.h @@ -52,7 +52,19 @@ struct f_uac1_opts { int req_number; unsigned bound:1; - char function_name[32]; + char function_name[USB_MAX_STRING_LEN]; + char usb_out_it_string[USB_MAX_STRING_LEN]; + char usb_out_it_ch_name_string[USB_MAX_STRING_LEN]; + char io_out_ot_string[USB_MAX_STRING_LEN]; + char io_in_it_string[USB_MAX_STRING_LEN]; + char io_in_it_ch_name_string[USB_MAX_STRING_LEN]; + char usb_in_ot_string[USB_MAX_STRING_LEN]; + char fu_in_string[USB_MAX_STRING_LEN]; + char fu_out_string[USB_MAX_STRING_LEN]; + char as_out_if_alt0_string[USB_MAX_STRING_LEN]; + char as_out_if_alt1_string[USB_MAX_STRING_LEN]; + char as_in_if_alt0_string[USB_MAX_STRING_LEN]; + char as_in_if_alt1_string[USB_MAX_STRING_LEN]; struct mutex lock; int refcnt; -- 2.34.1