Loading arch/arm64/configs/vendor/kona-iot-perf_defconfig +1 −0 Original line number Diff line number Diff line Loading @@ -479,6 +479,7 @@ CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_ACC=y CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y CONFIG_USB_CONFIGFS_F_UAC1=y CONFIG_USB_CONFIGFS_F_UAC2=y CONFIG_USB_CONFIGFS_F_MIDI=y CONFIG_USB_CONFIGFS_F_HID=y Loading arch/arm64/configs/vendor/kona-iot_defconfig +1 −0 Original line number Diff line number Diff line Loading @@ -496,6 +496,7 @@ CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_ACC=y CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y CONFIG_USB_CONFIGFS_F_UAC1=y CONFIG_USB_CONFIGFS_F_UAC2=y CONFIG_USB_CONFIGFS_F_MIDI=y CONFIG_USB_CONFIGFS_F_HID=y Loading drivers/usb/gadget/function/f_uac1.c +407 −3 Original line number Diff line number Diff line Loading @@ -19,10 +19,18 @@ #include "u_audio.h" #include "u_uac1.h" static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); struct f_uac1 { struct g_audio g_audio; u8 ac_intf, as_in_intf, as_out_intf; u8 ac_alt, as_in_alt, as_out_alt; /* needed for get_alt() */ /* Control Set command */ struct list_head cs; u8 set_cmd; struct usb_audio_control *set_con; }; static inline struct f_uac1 *func_to_uac1(struct usb_function *f) Loading @@ -48,6 +56,17 @@ static inline struct f_uac1 *func_to_uac1(struct usb_function *f) /* Number of streaming interfaces */ #define F_AUDIO_NUM_INTERFACES 2 static struct usb_interface_assoc_descriptor iad_desc = { .bLength = sizeof(iad_desc), .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, .bFirstInterface = 0, .bInterfaceCount = 3, .bFunctionClass = USB_CLASS_AUDIO, .bFunctionSubClass = USB_SUBCLASS_AUDIOSTREAMING, .bFunctionProtocol = UAC_VERSION_1, }; /* B.3.1 Standard AC Interface Descriptor */ static struct usb_interface_descriptor ac_interface_desc = { .bLength = USB_DT_INTERFACE_SIZE, Loading @@ -66,7 +85,8 @@ DECLARE_UAC_AC_HEADER_DESCRIPTOR(2); #define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) /* 2 input terminals and 2 output terminals */ #define UAC_DT_TOTAL_LENGTH (UAC_DT_AC_HEADER_LENGTH \ + 2*UAC_DT_INPUT_TERMINAL_SIZE + 2*UAC_DT_OUTPUT_TERMINAL_SIZE) + 2*UAC_DT_INPUT_TERMINAL_SIZE + 2*UAC_DT_OUTPUT_TERMINAL_SIZE \ + 2*UAC_DT_FEATURE_UNIT_SIZE(0) + UAC_DT_MIXER_UNIT_SIZE) /* B.3.2 Class-Specific AC Interface Descriptor */ static struct uac1_ac_header_descriptor_2 ac_header_desc = { .bLength = UAC_DT_AC_HEADER_LENGTH, Loading @@ -88,6 +108,7 @@ static struct uac_input_terminal_descriptor usb_out_it_desc = { .wChannelConfig = cpu_to_le16(0x3), }; #define FEATURE_UNIT_ID 5 #define IO_OUT_OT_ID 2 static struct uac1_output_terminal_descriptor io_out_ot_desc = { .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE, Loading @@ -96,7 +117,7 @@ static struct uac1_output_terminal_descriptor io_out_ot_desc = { .bTerminalID = IO_OUT_OT_ID, .wTerminalType = cpu_to_le16(UAC_OUTPUT_TERMINAL_SPEAKER), .bAssocTerminal = 0, .bSourceID = USB_OUT_IT_ID, .bSourceID = FEATURE_UNIT_ID, }; #define IO_IN_IT_ID 3 Loading @@ -110,6 +131,7 @@ static struct uac_input_terminal_descriptor io_in_it_desc = { .wChannelConfig = cpu_to_le16(0x3), }; #define MIC_FEATURE_UNIT_ID 6 #define USB_IN_OT_ID 4 static struct uac1_output_terminal_descriptor usb_in_ot_desc = { .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE, Loading @@ -118,7 +140,94 @@ static struct uac1_output_terminal_descriptor usb_in_ot_desc = { .bTerminalID = USB_IN_OT_ID, .wTerminalType = cpu_to_le16(UAC_TERMINAL_STREAMING), .bAssocTerminal = 0, .bSourceID = MIC_FEATURE_UNIT_ID, }; DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(0); #define MIXER_UNIT_ID 9 static struct uac_feature_unit_descriptor_0 feature_unit_desc = { .bLength = UAC_DT_FEATURE_UNIT_SIZE(0), .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubtype = UAC_FEATURE_UNIT, .bUnitID = FEATURE_UNIT_ID, .bSourceID = MIXER_UNIT_ID, .bControlSize = 0x2, .bmaControls[0] = cpu_to_le16(UAC_FU_MUTE | UAC_FU_VOLUME), }; static struct uac1_mixer_unit_descriptor mixer_unit_desc = { .bLength = UAC_DT_MIXER_UNIT_SIZE, .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubtype = UAC_MIXER_UNIT, .bUnitID = MIXER_UNIT_ID, .bNrInPins = 2, .baSourceID[0] = USB_OUT_IT_ID, .baSourceID[1] = MIC_FEATURE_UNIT_ID, .bNrChannels = 1, .wChannelConfig = cpu_to_le16(0x1), }; static struct uac_feature_unit_descriptor_0 mic_feature_unit_desc = { .bLength = UAC_DT_FEATURE_UNIT_SIZE(0), .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubtype = UAC_FEATURE_UNIT, .bUnitID = MIC_FEATURE_UNIT_ID, .bSourceID = IO_IN_IT_ID, .bControlSize = 0x2, .bmaControls[0] = cpu_to_le16(UAC_FU_MUTE | UAC_FU_VOLUME), }; static struct usb_audio_control mute_control = { .list = LIST_HEAD_INIT(mute_control.list), .name = "Speaker Mute Control", .type = UAC_FU_MUTE, /* Todo: add real Mute control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control volume_control = { .list = LIST_HEAD_INIT(volume_control.list), .name = "Speaker Volume Control", .type = UAC_FU_VOLUME, /* Todo: add real Volume control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control_selector feature_unit = { .list = LIST_HEAD_INIT(feature_unit.list), .id = FEATURE_UNIT_ID, .name = "Speaker Mute & Volume Control", .type = UAC_FEATURE_UNIT, .desc = (struct usb_descriptor_header *)&feature_unit_desc, }; static struct usb_audio_control mic_mute_control = { .list = LIST_HEAD_INIT(mic_mute_control.list), .name = "MIC Mute Control", .type = UAC_FU_MUTE, /* Todo: add real Mute control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control mic_volume_control = { .list = LIST_HEAD_INIT(mic_volume_control.list), .name = "MIC Volume Control", .type = UAC_FU_VOLUME, /* Todo: add real Volume control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control_selector mic_feature_unit = { .list = LIST_HEAD_INIT(feature_unit.list), .id = MIC_FEATURE_UNIT_ID, .name = "MIC Mute & Volume Control", .type = UAC_FEATURE_UNIT, .desc = (struct usb_descriptor_header *)&mic_feature_unit_desc, }; /* B.4.1 Standard AS Interface Descriptor */ Loading Loading @@ -256,6 +365,7 @@ static struct uac_iso_endpoint_descriptor as_iso_in_desc = { }; static struct usb_descriptor_header *f_audio_desc[] = { (struct usb_descriptor_header *)&iad_desc, (struct usb_descriptor_header *)&ac_interface_desc, (struct usb_descriptor_header *)&ac_header_desc, Loading @@ -264,6 +374,10 @@ static struct usb_descriptor_header *f_audio_desc[] = { (struct usb_descriptor_header *)&io_in_it_desc, (struct usb_descriptor_header *)&usb_in_ot_desc, (struct usb_descriptor_header *)&feature_unit_desc, (struct usb_descriptor_header *)&mic_feature_unit_desc, (struct usb_descriptor_header *)&mixer_unit_desc, (struct usb_descriptor_header *)&as_out_interface_alt_0_desc, (struct usb_descriptor_header *)&as_out_interface_alt_1_desc, (struct usb_descriptor_header *)&as_out_header_desc, Loading @@ -285,6 +399,7 @@ static struct usb_descriptor_header *f_audio_desc[] = { }; static struct usb_descriptor_header *f_audio_ss_desc[] = { (struct usb_descriptor_header *)&iad_desc, (struct usb_descriptor_header *)&ac_interface_desc, (struct usb_descriptor_header *)&ac_header_desc, Loading @@ -293,6 +408,10 @@ static struct usb_descriptor_header *f_audio_ss_desc[] = { (struct usb_descriptor_header *)&io_in_it_desc, (struct usb_descriptor_header *)&usb_in_ot_desc, (struct usb_descriptor_header *)&feature_unit_desc, (struct usb_descriptor_header *)&mic_feature_unit_desc, (struct usb_descriptor_header *)&mixer_unit_desc, (struct usb_descriptor_header *)&as_out_interface_alt_0_desc, (struct usb_descriptor_header *)&as_out_interface_alt_1_desc, (struct usb_descriptor_header *)&as_out_header_desc, Loading Loading @@ -323,6 +442,8 @@ enum { STR_IO_IN_IT, STR_IO_IN_IT_CH_NAMES, STR_USB_IN_OT, STR_FEAT_DESC_0, STR_FEAT_DESC_1, STR_AS_OUT_IF_ALT0, STR_AS_OUT_IF_ALT1, STR_AS_IN_IF_ALT0, Loading @@ -337,6 +458,8 @@ static struct usb_string strings_uac1[] = { [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_FEAT_DESC_0].s = "Volume control & mute", [STR_FEAT_DESC_1].s = "Mic Volume control & mute", [STR_AS_OUT_IF_ALT0].s = "Playback Inactive", [STR_AS_OUT_IF_ALT1].s = "Playback Active", [STR_AS_IN_IF_ALT0].s = "Capture Inactive", Loading @@ -354,6 +477,100 @@ static struct usb_gadget_strings *uac1_strings[] = { NULL, }; static void f_audio_complete(struct usb_ep *ep, struct usb_request *req) { struct f_uac1 *uac1 = req->context; int status = req->status; u32 data = 0; switch (status) { case 0: /* normal completion? */ if (uac1->set_con) { memcpy(&data, req->buf, req->length); uac1->set_con->set(uac1->set_con, uac1->set_cmd, data); uac1->set_con = NULL; } break; default: break; } } static int audio_set_intf_req(struct usb_function *f, const struct usb_ctrlrequest *ctrl) { struct f_uac1 *uac1 = func_to_uac1(f); struct usb_composite_dev *cdev = f->config->cdev; struct usb_request *req = cdev->req; u8 id = ((le16_to_cpu(ctrl->wIndex) >> 8) & 0xFF); u16 len = le16_to_cpu(ctrl->wLength); u16 w_value = le16_to_cpu(ctrl->wValue); u8 con_sel = (w_value >> 8) & 0xFF; u8 cmd = (ctrl->bRequest & 0x0F); struct usb_audio_control_selector *cs; struct usb_audio_control *con; DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, entity %d\n", ctrl->bRequest, w_value, len, id); list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == id) { list_for_each_entry(con, &cs->control, list) { if (con->type == con_sel) { uac1->set_con = con; break; } } break; } } uac1->set_cmd = cmd; req->context = uac1; req->complete = f_audio_complete; return len; } static int audio_get_intf_req(struct usb_function *f, const struct usb_ctrlrequest *ctrl) { struct f_uac1 *uac1 = func_to_uac1(f); struct usb_composite_dev *cdev = f->config->cdev; struct usb_request *req = cdev->req; int value = -EOPNOTSUPP; u8 id = ((le16_to_cpu(ctrl->wIndex) >> 8) & 0xFF); u16 len = le16_to_cpu(ctrl->wLength); u16 w_value = le16_to_cpu(ctrl->wValue); u8 con_sel = (w_value >> 8) & 0xFF; u8 cmd = (ctrl->bRequest & 0x0F); struct usb_audio_control_selector *cs; struct usb_audio_control *con; DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, entity %d\n", ctrl->bRequest, w_value, len, id); list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == id) { list_for_each_entry(con, &cs->control, list) { if (con->type == con_sel && con->get) { value = con->get(con, cmd); break; } } break; } } req->context = uac1; req->complete = f_audio_complete; len = min_t(size_t, sizeof(value), len); memcpy(req->buf, &value, len); return len; } /* * This function is an ALSA sound card following USB Audio Class Spec 1.0. */ Loading Loading @@ -436,6 +653,14 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) * activation uses set_alt(). */ switch (ctrl->bRequestType) { case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE: value = audio_set_intf_req(f, ctrl); break; case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE: value = audio_get_intf_req(f, ctrl); break; case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT: value = audio_set_endpoint_req(f, ctrl); break; Loading Loading @@ -573,6 +798,8 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) io_in_it_desc.iTerminal = us[STR_IO_IN_IT].id; io_in_it_desc.iChannelNames = us[STR_IO_IN_IT_CH_NAMES].id; usb_in_ot_desc.iTerminal = us[STR_USB_IN_OT].id; feature_unit_desc.iFeature = us[STR_FEAT_DESC_0].id; mic_feature_unit_desc.iFeature = us[STR_FEAT_DESC_1].id; as_in_interface_alt_0_desc.iInterface = us[STR_AS_IN_IF_ALT0].id; as_in_interface_alt_1_desc.iInterface = us[STR_AS_IN_IF_ALT1].id; Loading Loading @@ -601,6 +828,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) if (status < 0) goto fail; ac_interface_desc.bInterfaceNumber = status; iad_desc.bFirstInterface = status; uac1->ac_intf = status; uac1->ac_alt = 0; Loading @@ -626,6 +854,10 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) status = -ENODEV; audio_opts->ep_maxp_size = clamp(audio_opts->ep_maxp_size, 1U, 1023U); as_out_ep_desc.wMaxPacketSize = cpu_to_le16(audio_opts->ep_maxp_size); as_in_ep_desc.wMaxPacketSize = cpu_to_le16(audio_opts->ep_maxp_size); /* allocate instance-specific endpoints */ ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc); if (!ep) Loading Loading @@ -669,6 +901,45 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) /*-------------------------------------------------------------------------*/ static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value) { con->data[cmd] = value; pr_debug("%s:%s:value=%d\n", __func__, con->name, value); return 0; } static int generic_get_cmd(struct usb_audio_control *con, u8 cmd) { return con->data[cmd]; } /* Todo: add more control selecotor dynamically */ static int control_selector_init(struct f_uac1 *uac1) { INIT_LIST_HEAD(&uac1->cs); list_add(&feature_unit.list, &uac1->cs); list_add(&mic_feature_unit.list, &uac1->cs); INIT_LIST_HEAD(&feature_unit.control); list_add(&mute_control.list, &feature_unit.control); list_add(&volume_control.list, &feature_unit.control); INIT_LIST_HEAD(&mic_feature_unit.control); list_add(&mic_mute_control.list, &mic_feature_unit.control); list_add(&mic_volume_control.list, &mic_feature_unit.control); volume_control.data[UAC__CUR] = 0xffc0; volume_control.data[UAC__MIN] = 0xe3a0; volume_control.data[UAC__MAX] = 0xfff0; volume_control.data[UAC__RES] = 0x0030; mic_volume_control.data[UAC__CUR] = 0xffc0; mic_volume_control.data[UAC__MIN] = 0xe3a0; mic_volume_control.data[UAC__MAX] = 0xfff0; mic_volume_control.data[UAC__RES] = 0x0030; return 0; } static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item) { return container_of(to_config_group(item), struct f_uac1_opts, Loading Loading @@ -736,6 +1007,130 @@ UAC1_ATTRIBUTE(p_chmask); UAC1_ATTRIBUTE(p_srate); UAC1_ATTRIBUTE(p_ssize); UAC1_ATTRIBUTE(req_number); UAC1_ATTRIBUTE(ep_maxp_size); static ssize_t f_uac1_opts_speaker_volume_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_VOLUME && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } static ssize_t f_uac1_opts_mic_volume_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == MIC_FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_VOLUME && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } static ssize_t f_uac1_opts_speaker_mute_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_MUTE && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } static ssize_t f_uac1_opts_mic_mute_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == MIC_FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_MUTE && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } CONFIGFS_ATTR_RO(f_uac1_opts_, speaker_volume); CONFIGFS_ATTR_RO(f_uac1_opts_, mic_volume); CONFIGFS_ATTR_RO(f_uac1_opts_, speaker_mute); CONFIGFS_ATTR_RO(f_uac1_opts_, mic_mute); static struct configfs_attribute *f_uac1_attrs[] = { &f_uac1_opts_attr_c_chmask, Loading @@ -745,6 +1140,11 @@ static struct configfs_attribute *f_uac1_attrs[] = { &f_uac1_opts_attr_p_srate, &f_uac1_opts_attr_p_ssize, &f_uac1_opts_attr_req_number, &f_uac1_opts_attr_speaker_volume, &f_uac1_opts_attr_mic_volume, &f_uac1_opts_attr_speaker_mute, &f_uac1_opts_attr_mic_mute, &f_uac1_opts_attr_ep_maxp_size, NULL, }; Loading Loading @@ -783,6 +1183,7 @@ static struct usb_function_instance *f_audio_alloc_inst(void) opts->p_srate = UAC1_DEF_PSRATE; opts->p_ssize = UAC1_DEF_PSSIZE; opts->req_number = UAC1_DEF_REQ_NUM; opts->ep_maxp_size = UAC1_OUT_EP_MAX_PACKET_SIZE; return &opts->func_inst; } Loading Loading @@ -822,6 +1223,7 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) opts = container_of(fi, struct f_uac1_opts, func_inst); mutex_lock(&opts->lock); ++opts->refcnt; opts->uac1 = uac1; mutex_unlock(&opts->lock); uac1->g_audio.func.name = "uac1_func"; Loading @@ -833,6 +1235,8 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) uac1->g_audio.func.disable = f_audio_disable; uac1->g_audio.func.free_func = f_audio_free; control_selector_init(uac1); return &uac1->g_audio.func; } Loading drivers/usb/gadget/function/u_uac1.h +18 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ struct f_uac1_opts { struct usb_function_instance func_inst; struct f_uac1 *uac1; int c_chmask; int c_srate; int c_ssize; Loading @@ -29,10 +30,27 @@ struct f_uac1_opts { int p_srate; int p_ssize; int req_number; unsigned int ep_maxp_size; unsigned bound:1; struct mutex lock; int refcnt; }; #define UAC_DT_MIXER_UNIT_SIZE 13 /* 4.3.2.3 Mixer Unit Descriptor */ struct uac1_mixer_unit_descriptor { __u8 bLength; __u8 bDescriptorType; __u8 bDescriptorSubtype; __u8 bUnitID; __u8 bNrInPins; __u8 baSourceID[2]; __u8 bNrChannels; __le16 wChannelConfig; __u8 iChannelNames; __u8 bmControls; __u8 iMixer; } __packed; #endif /* __U_UAC1_H */ Loading
arch/arm64/configs/vendor/kona-iot-perf_defconfig +1 −0 Original line number Diff line number Diff line Loading @@ -479,6 +479,7 @@ CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_ACC=y CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y CONFIG_USB_CONFIGFS_F_UAC1=y CONFIG_USB_CONFIGFS_F_UAC2=y CONFIG_USB_CONFIGFS_F_MIDI=y CONFIG_USB_CONFIGFS_F_HID=y Loading
arch/arm64/configs/vendor/kona-iot_defconfig +1 −0 Original line number Diff line number Diff line Loading @@ -496,6 +496,7 @@ CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_ACC=y CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y CONFIG_USB_CONFIGFS_F_UAC1=y CONFIG_USB_CONFIGFS_F_UAC2=y CONFIG_USB_CONFIGFS_F_MIDI=y CONFIG_USB_CONFIGFS_F_HID=y Loading
drivers/usb/gadget/function/f_uac1.c +407 −3 Original line number Diff line number Diff line Loading @@ -19,10 +19,18 @@ #include "u_audio.h" #include "u_uac1.h" static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); struct f_uac1 { struct g_audio g_audio; u8 ac_intf, as_in_intf, as_out_intf; u8 ac_alt, as_in_alt, as_out_alt; /* needed for get_alt() */ /* Control Set command */ struct list_head cs; u8 set_cmd; struct usb_audio_control *set_con; }; static inline struct f_uac1 *func_to_uac1(struct usb_function *f) Loading @@ -48,6 +56,17 @@ static inline struct f_uac1 *func_to_uac1(struct usb_function *f) /* Number of streaming interfaces */ #define F_AUDIO_NUM_INTERFACES 2 static struct usb_interface_assoc_descriptor iad_desc = { .bLength = sizeof(iad_desc), .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, .bFirstInterface = 0, .bInterfaceCount = 3, .bFunctionClass = USB_CLASS_AUDIO, .bFunctionSubClass = USB_SUBCLASS_AUDIOSTREAMING, .bFunctionProtocol = UAC_VERSION_1, }; /* B.3.1 Standard AC Interface Descriptor */ static struct usb_interface_descriptor ac_interface_desc = { .bLength = USB_DT_INTERFACE_SIZE, Loading @@ -66,7 +85,8 @@ DECLARE_UAC_AC_HEADER_DESCRIPTOR(2); #define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) /* 2 input terminals and 2 output terminals */ #define UAC_DT_TOTAL_LENGTH (UAC_DT_AC_HEADER_LENGTH \ + 2*UAC_DT_INPUT_TERMINAL_SIZE + 2*UAC_DT_OUTPUT_TERMINAL_SIZE) + 2*UAC_DT_INPUT_TERMINAL_SIZE + 2*UAC_DT_OUTPUT_TERMINAL_SIZE \ + 2*UAC_DT_FEATURE_UNIT_SIZE(0) + UAC_DT_MIXER_UNIT_SIZE) /* B.3.2 Class-Specific AC Interface Descriptor */ static struct uac1_ac_header_descriptor_2 ac_header_desc = { .bLength = UAC_DT_AC_HEADER_LENGTH, Loading @@ -88,6 +108,7 @@ static struct uac_input_terminal_descriptor usb_out_it_desc = { .wChannelConfig = cpu_to_le16(0x3), }; #define FEATURE_UNIT_ID 5 #define IO_OUT_OT_ID 2 static struct uac1_output_terminal_descriptor io_out_ot_desc = { .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE, Loading @@ -96,7 +117,7 @@ static struct uac1_output_terminal_descriptor io_out_ot_desc = { .bTerminalID = IO_OUT_OT_ID, .wTerminalType = cpu_to_le16(UAC_OUTPUT_TERMINAL_SPEAKER), .bAssocTerminal = 0, .bSourceID = USB_OUT_IT_ID, .bSourceID = FEATURE_UNIT_ID, }; #define IO_IN_IT_ID 3 Loading @@ -110,6 +131,7 @@ static struct uac_input_terminal_descriptor io_in_it_desc = { .wChannelConfig = cpu_to_le16(0x3), }; #define MIC_FEATURE_UNIT_ID 6 #define USB_IN_OT_ID 4 static struct uac1_output_terminal_descriptor usb_in_ot_desc = { .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE, Loading @@ -118,7 +140,94 @@ static struct uac1_output_terminal_descriptor usb_in_ot_desc = { .bTerminalID = USB_IN_OT_ID, .wTerminalType = cpu_to_le16(UAC_TERMINAL_STREAMING), .bAssocTerminal = 0, .bSourceID = MIC_FEATURE_UNIT_ID, }; DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(0); #define MIXER_UNIT_ID 9 static struct uac_feature_unit_descriptor_0 feature_unit_desc = { .bLength = UAC_DT_FEATURE_UNIT_SIZE(0), .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubtype = UAC_FEATURE_UNIT, .bUnitID = FEATURE_UNIT_ID, .bSourceID = MIXER_UNIT_ID, .bControlSize = 0x2, .bmaControls[0] = cpu_to_le16(UAC_FU_MUTE | UAC_FU_VOLUME), }; static struct uac1_mixer_unit_descriptor mixer_unit_desc = { .bLength = UAC_DT_MIXER_UNIT_SIZE, .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubtype = UAC_MIXER_UNIT, .bUnitID = MIXER_UNIT_ID, .bNrInPins = 2, .baSourceID[0] = USB_OUT_IT_ID, .baSourceID[1] = MIC_FEATURE_UNIT_ID, .bNrChannels = 1, .wChannelConfig = cpu_to_le16(0x1), }; static struct uac_feature_unit_descriptor_0 mic_feature_unit_desc = { .bLength = UAC_DT_FEATURE_UNIT_SIZE(0), .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubtype = UAC_FEATURE_UNIT, .bUnitID = MIC_FEATURE_UNIT_ID, .bSourceID = IO_IN_IT_ID, .bControlSize = 0x2, .bmaControls[0] = cpu_to_le16(UAC_FU_MUTE | UAC_FU_VOLUME), }; static struct usb_audio_control mute_control = { .list = LIST_HEAD_INIT(mute_control.list), .name = "Speaker Mute Control", .type = UAC_FU_MUTE, /* Todo: add real Mute control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control volume_control = { .list = LIST_HEAD_INIT(volume_control.list), .name = "Speaker Volume Control", .type = UAC_FU_VOLUME, /* Todo: add real Volume control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control_selector feature_unit = { .list = LIST_HEAD_INIT(feature_unit.list), .id = FEATURE_UNIT_ID, .name = "Speaker Mute & Volume Control", .type = UAC_FEATURE_UNIT, .desc = (struct usb_descriptor_header *)&feature_unit_desc, }; static struct usb_audio_control mic_mute_control = { .list = LIST_HEAD_INIT(mic_mute_control.list), .name = "MIC Mute Control", .type = UAC_FU_MUTE, /* Todo: add real Mute control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control mic_volume_control = { .list = LIST_HEAD_INIT(mic_volume_control.list), .name = "MIC Volume Control", .type = UAC_FU_VOLUME, /* Todo: add real Volume control code */ .set = generic_set_cmd, .get = generic_get_cmd, }; static struct usb_audio_control_selector mic_feature_unit = { .list = LIST_HEAD_INIT(feature_unit.list), .id = MIC_FEATURE_UNIT_ID, .name = "MIC Mute & Volume Control", .type = UAC_FEATURE_UNIT, .desc = (struct usb_descriptor_header *)&mic_feature_unit_desc, }; /* B.4.1 Standard AS Interface Descriptor */ Loading Loading @@ -256,6 +365,7 @@ static struct uac_iso_endpoint_descriptor as_iso_in_desc = { }; static struct usb_descriptor_header *f_audio_desc[] = { (struct usb_descriptor_header *)&iad_desc, (struct usb_descriptor_header *)&ac_interface_desc, (struct usb_descriptor_header *)&ac_header_desc, Loading @@ -264,6 +374,10 @@ static struct usb_descriptor_header *f_audio_desc[] = { (struct usb_descriptor_header *)&io_in_it_desc, (struct usb_descriptor_header *)&usb_in_ot_desc, (struct usb_descriptor_header *)&feature_unit_desc, (struct usb_descriptor_header *)&mic_feature_unit_desc, (struct usb_descriptor_header *)&mixer_unit_desc, (struct usb_descriptor_header *)&as_out_interface_alt_0_desc, (struct usb_descriptor_header *)&as_out_interface_alt_1_desc, (struct usb_descriptor_header *)&as_out_header_desc, Loading @@ -285,6 +399,7 @@ static struct usb_descriptor_header *f_audio_desc[] = { }; static struct usb_descriptor_header *f_audio_ss_desc[] = { (struct usb_descriptor_header *)&iad_desc, (struct usb_descriptor_header *)&ac_interface_desc, (struct usb_descriptor_header *)&ac_header_desc, Loading @@ -293,6 +408,10 @@ static struct usb_descriptor_header *f_audio_ss_desc[] = { (struct usb_descriptor_header *)&io_in_it_desc, (struct usb_descriptor_header *)&usb_in_ot_desc, (struct usb_descriptor_header *)&feature_unit_desc, (struct usb_descriptor_header *)&mic_feature_unit_desc, (struct usb_descriptor_header *)&mixer_unit_desc, (struct usb_descriptor_header *)&as_out_interface_alt_0_desc, (struct usb_descriptor_header *)&as_out_interface_alt_1_desc, (struct usb_descriptor_header *)&as_out_header_desc, Loading Loading @@ -323,6 +442,8 @@ enum { STR_IO_IN_IT, STR_IO_IN_IT_CH_NAMES, STR_USB_IN_OT, STR_FEAT_DESC_0, STR_FEAT_DESC_1, STR_AS_OUT_IF_ALT0, STR_AS_OUT_IF_ALT1, STR_AS_IN_IF_ALT0, Loading @@ -337,6 +458,8 @@ static struct usb_string strings_uac1[] = { [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_FEAT_DESC_0].s = "Volume control & mute", [STR_FEAT_DESC_1].s = "Mic Volume control & mute", [STR_AS_OUT_IF_ALT0].s = "Playback Inactive", [STR_AS_OUT_IF_ALT1].s = "Playback Active", [STR_AS_IN_IF_ALT0].s = "Capture Inactive", Loading @@ -354,6 +477,100 @@ static struct usb_gadget_strings *uac1_strings[] = { NULL, }; static void f_audio_complete(struct usb_ep *ep, struct usb_request *req) { struct f_uac1 *uac1 = req->context; int status = req->status; u32 data = 0; switch (status) { case 0: /* normal completion? */ if (uac1->set_con) { memcpy(&data, req->buf, req->length); uac1->set_con->set(uac1->set_con, uac1->set_cmd, data); uac1->set_con = NULL; } break; default: break; } } static int audio_set_intf_req(struct usb_function *f, const struct usb_ctrlrequest *ctrl) { struct f_uac1 *uac1 = func_to_uac1(f); struct usb_composite_dev *cdev = f->config->cdev; struct usb_request *req = cdev->req; u8 id = ((le16_to_cpu(ctrl->wIndex) >> 8) & 0xFF); u16 len = le16_to_cpu(ctrl->wLength); u16 w_value = le16_to_cpu(ctrl->wValue); u8 con_sel = (w_value >> 8) & 0xFF; u8 cmd = (ctrl->bRequest & 0x0F); struct usb_audio_control_selector *cs; struct usb_audio_control *con; DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, entity %d\n", ctrl->bRequest, w_value, len, id); list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == id) { list_for_each_entry(con, &cs->control, list) { if (con->type == con_sel) { uac1->set_con = con; break; } } break; } } uac1->set_cmd = cmd; req->context = uac1; req->complete = f_audio_complete; return len; } static int audio_get_intf_req(struct usb_function *f, const struct usb_ctrlrequest *ctrl) { struct f_uac1 *uac1 = func_to_uac1(f); struct usb_composite_dev *cdev = f->config->cdev; struct usb_request *req = cdev->req; int value = -EOPNOTSUPP; u8 id = ((le16_to_cpu(ctrl->wIndex) >> 8) & 0xFF); u16 len = le16_to_cpu(ctrl->wLength); u16 w_value = le16_to_cpu(ctrl->wValue); u8 con_sel = (w_value >> 8) & 0xFF; u8 cmd = (ctrl->bRequest & 0x0F); struct usb_audio_control_selector *cs; struct usb_audio_control *con; DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, entity %d\n", ctrl->bRequest, w_value, len, id); list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == id) { list_for_each_entry(con, &cs->control, list) { if (con->type == con_sel && con->get) { value = con->get(con, cmd); break; } } break; } } req->context = uac1; req->complete = f_audio_complete; len = min_t(size_t, sizeof(value), len); memcpy(req->buf, &value, len); return len; } /* * This function is an ALSA sound card following USB Audio Class Spec 1.0. */ Loading Loading @@ -436,6 +653,14 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) * activation uses set_alt(). */ switch (ctrl->bRequestType) { case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE: value = audio_set_intf_req(f, ctrl); break; case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE: value = audio_get_intf_req(f, ctrl); break; case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT: value = audio_set_endpoint_req(f, ctrl); break; Loading Loading @@ -573,6 +798,8 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) io_in_it_desc.iTerminal = us[STR_IO_IN_IT].id; io_in_it_desc.iChannelNames = us[STR_IO_IN_IT_CH_NAMES].id; usb_in_ot_desc.iTerminal = us[STR_USB_IN_OT].id; feature_unit_desc.iFeature = us[STR_FEAT_DESC_0].id; mic_feature_unit_desc.iFeature = us[STR_FEAT_DESC_1].id; as_in_interface_alt_0_desc.iInterface = us[STR_AS_IN_IF_ALT0].id; as_in_interface_alt_1_desc.iInterface = us[STR_AS_IN_IF_ALT1].id; Loading Loading @@ -601,6 +828,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) if (status < 0) goto fail; ac_interface_desc.bInterfaceNumber = status; iad_desc.bFirstInterface = status; uac1->ac_intf = status; uac1->ac_alt = 0; Loading @@ -626,6 +854,10 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) status = -ENODEV; audio_opts->ep_maxp_size = clamp(audio_opts->ep_maxp_size, 1U, 1023U); as_out_ep_desc.wMaxPacketSize = cpu_to_le16(audio_opts->ep_maxp_size); as_in_ep_desc.wMaxPacketSize = cpu_to_le16(audio_opts->ep_maxp_size); /* allocate instance-specific endpoints */ ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc); if (!ep) Loading Loading @@ -669,6 +901,45 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) /*-------------------------------------------------------------------------*/ static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value) { con->data[cmd] = value; pr_debug("%s:%s:value=%d\n", __func__, con->name, value); return 0; } static int generic_get_cmd(struct usb_audio_control *con, u8 cmd) { return con->data[cmd]; } /* Todo: add more control selecotor dynamically */ static int control_selector_init(struct f_uac1 *uac1) { INIT_LIST_HEAD(&uac1->cs); list_add(&feature_unit.list, &uac1->cs); list_add(&mic_feature_unit.list, &uac1->cs); INIT_LIST_HEAD(&feature_unit.control); list_add(&mute_control.list, &feature_unit.control); list_add(&volume_control.list, &feature_unit.control); INIT_LIST_HEAD(&mic_feature_unit.control); list_add(&mic_mute_control.list, &mic_feature_unit.control); list_add(&mic_volume_control.list, &mic_feature_unit.control); volume_control.data[UAC__CUR] = 0xffc0; volume_control.data[UAC__MIN] = 0xe3a0; volume_control.data[UAC__MAX] = 0xfff0; volume_control.data[UAC__RES] = 0x0030; mic_volume_control.data[UAC__CUR] = 0xffc0; mic_volume_control.data[UAC__MIN] = 0xe3a0; mic_volume_control.data[UAC__MAX] = 0xfff0; mic_volume_control.data[UAC__RES] = 0x0030; return 0; } static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item) { return container_of(to_config_group(item), struct f_uac1_opts, Loading Loading @@ -736,6 +1007,130 @@ UAC1_ATTRIBUTE(p_chmask); UAC1_ATTRIBUTE(p_srate); UAC1_ATTRIBUTE(p_ssize); UAC1_ATTRIBUTE(req_number); UAC1_ATTRIBUTE(ep_maxp_size); static ssize_t f_uac1_opts_speaker_volume_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_VOLUME && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } static ssize_t f_uac1_opts_mic_volume_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == MIC_FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_VOLUME && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } static ssize_t f_uac1_opts_speaker_mute_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_MUTE && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } static ssize_t f_uac1_opts_mic_mute_show(struct config_item *item, char *page) { struct f_uac1_opts *opts = to_f_uac1_opts(item); struct f_uac1 *uac1 = opts->uac1; int result; struct usb_audio_control_selector *cs; struct usb_audio_control *con; int value; if (!uac1) return 0; list_for_each_entry(cs, &uac1->cs, list) { if (cs->id == MIC_FEATURE_UNIT_ID) { list_for_each_entry(con, &cs->control, list) { if (con->type == UAC_FU_MUTE && con->get) { value = con->get(con, UAC__CUR); break; } } break; } } result = scnprintf(page, PAGE_SIZE, "%u\n", value); return result; } CONFIGFS_ATTR_RO(f_uac1_opts_, speaker_volume); CONFIGFS_ATTR_RO(f_uac1_opts_, mic_volume); CONFIGFS_ATTR_RO(f_uac1_opts_, speaker_mute); CONFIGFS_ATTR_RO(f_uac1_opts_, mic_mute); static struct configfs_attribute *f_uac1_attrs[] = { &f_uac1_opts_attr_c_chmask, Loading @@ -745,6 +1140,11 @@ static struct configfs_attribute *f_uac1_attrs[] = { &f_uac1_opts_attr_p_srate, &f_uac1_opts_attr_p_ssize, &f_uac1_opts_attr_req_number, &f_uac1_opts_attr_speaker_volume, &f_uac1_opts_attr_mic_volume, &f_uac1_opts_attr_speaker_mute, &f_uac1_opts_attr_mic_mute, &f_uac1_opts_attr_ep_maxp_size, NULL, }; Loading Loading @@ -783,6 +1183,7 @@ static struct usb_function_instance *f_audio_alloc_inst(void) opts->p_srate = UAC1_DEF_PSRATE; opts->p_ssize = UAC1_DEF_PSSIZE; opts->req_number = UAC1_DEF_REQ_NUM; opts->ep_maxp_size = UAC1_OUT_EP_MAX_PACKET_SIZE; return &opts->func_inst; } Loading Loading @@ -822,6 +1223,7 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) opts = container_of(fi, struct f_uac1_opts, func_inst); mutex_lock(&opts->lock); ++opts->refcnt; opts->uac1 = uac1; mutex_unlock(&opts->lock); uac1->g_audio.func.name = "uac1_func"; Loading @@ -833,6 +1235,8 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) uac1->g_audio.func.disable = f_audio_disable; uac1->g_audio.func.free_func = f_audio_free; control_selector_init(uac1); return &uac1->g_audio.func; } Loading
drivers/usb/gadget/function/u_uac1.h +18 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ struct f_uac1_opts { struct usb_function_instance func_inst; struct f_uac1 *uac1; int c_chmask; int c_srate; int c_ssize; Loading @@ -29,10 +30,27 @@ struct f_uac1_opts { int p_srate; int p_ssize; int req_number; unsigned int ep_maxp_size; unsigned bound:1; struct mutex lock; int refcnt; }; #define UAC_DT_MIXER_UNIT_SIZE 13 /* 4.3.2.3 Mixer Unit Descriptor */ struct uac1_mixer_unit_descriptor { __u8 bLength; __u8 bDescriptorType; __u8 bDescriptorSubtype; __u8 bUnitID; __u8 bNrInPins; __u8 baSourceID[2]; __u8 bNrChannels; __le16 wChannelConfig; __u8 iChannelNames; __u8 bmControls; __u8 iMixer; } __packed; #endif /* __U_UAC1_H */