Lines Matching +full:ouput +full:- +full:only
1 // SPDX-License-Identifier: GPL-2.0+
3 * f_uac2.c -- USB Audio Class 2.0 Function
14 #include <linux/usb/audio-v2.h>
26 * USB-OUT -> IT_1 -> FU -> OT_3 -> ALSA_Capture
27 * ALSA_Playback -> IT_2 -> FU -> OT_4 -> USB-IN
34 #define USB_OUT_FU_ID (out_feature_unit_desc->bUnitID)
35 #define USB_IN_FU_ID (in_feature_unit_desc->bUnitID)
53 #define EPIN_EN(_opts) ((_opts)->p_chmask != 0)
54 #define EPOUT_EN(_opts) ((_opts)->c_chmask != 0)
56 && ((_opts)->p_mute_present \
57 || (_opts)->p_volume_present))
59 && ((_opts)->c_mute_present \
60 || (_opts)->c_volume_present))
61 #define EPOUT_FBACK_IN_EN(_opts) ((_opts)->c_sync == USB_ENDPOINT_SYNC_ASYNC)
73 /* transient state, only valid during handling of a single control request */
85 return container_of(agdev->func.fi, struct f_uac2_opts, func_inst); in g_audio_to_uac2_opts()
90 /* --------- USB Function Interface ------------- */
125 .language = 0x0409, /* en-us */
195 /* Input Terminal for I/O-In */
209 /* Ouput Terminal for USB_IN */
223 /* Ouput Terminal for I/O-Out */
287 /* Audio Streaming OUT Interface - Alt0 */
299 /* Audio Streaming OUT Interface - Alt1 */
421 /* Audio Streaming IN Interface - Alt0 */
433 /* Audio Streaming IN Interface - Alt1 */
678 chmask = uac2_opts->p_chmask; in get_max_bw_for_bint()
679 srate = get_max_srate(uac2_opts->p_srates); in get_max_bw_for_bint()
680 ssize = uac2_opts->p_ssize; in get_max_bw_for_bint()
682 chmask = uac2_opts->c_chmask; in get_max_bw_for_bint()
683 srate = get_max_srate(uac2_opts->c_srates); in get_max_bw_for_bint()
684 ssize = uac2_opts->c_ssize; in get_max_bw_for_bint()
687 if (is_playback || (uac2_opts->c_sync == USB_ENDPOINT_SYNC_ASYNC)) { in get_max_bw_for_bint()
688 // playback is always async, capture only when configured in get_max_bw_for_bint()
690 srate = srate * (1000 + uac2_opts->fb_max) / 1000; in get_max_bw_for_bint()
693 (DIV_ROUND_UP(srate, factor / (1 << (bint - 1)))); in get_max_bw_for_bint()
697 (DIV_ROUND_UP(srate, factor / (1 << (bint - 1))) + 1); in get_max_bw_for_bint()
714 bint = ep_desc->bInterval; in set_ep_max_packet_size_bint()
722 opts_bint = uac2_opts->p_hs_bint; in set_ep_max_packet_size_bint()
724 opts_bint = uac2_opts->c_hs_bint; in set_ep_max_packet_size_bint()
732 for (bint = 4; bint > 0; --bint) { in set_ep_max_packet_size_bint()
742 return -EINVAL; in set_ep_max_packet_size_bint()
761 ep_desc->wMaxPacketSize = cpu_to_le16(max_size_bw); in set_ep_max_packet_size_bint()
762 ep_desc->bInterval = bint; in set_ep_max_packet_size_bint()
777 fu_desc->bLength = fu_desc_size; in build_fu_desc()
778 fu_desc->bDescriptorType = USB_DT_CS_INTERFACE; in build_fu_desc()
780 fu_desc->bDescriptorSubtype = UAC_FEATURE_UNIT; in build_fu_desc()
906 out_feature_unit_desc->bUnitID = i++; in setup_descriptor()
908 in_feature_unit_desc->bUnitID = i++; in setup_descriptor()
917 usb_in_ot_desc.bSourceID = in_feature_unit_desc->bUnitID; in setup_descriptor()
918 in_feature_unit_desc->bSourceID = io_in_it_desc.bTerminalID; in setup_descriptor()
928 io_out_ot_desc.bSourceID = out_feature_unit_desc->bUnitID; in setup_descriptor()
929 out_feature_unit_desc->bSourceID = usb_out_it_desc.bTerminalID; in setup_descriptor()
947 len += in_feature_unit_desc->bLength; in setup_descriptor()
960 len += out_feature_unit_desc->bLength; in setup_descriptor()
967 io_in_it_desc.wTerminalType = cpu_to_le16(opts->c_terminal_type); in setup_descriptor()
968 io_out_ot_desc.wTerminalType = cpu_to_le16(opts->p_terminal_type); in setup_descriptor()
980 if (!opts->p_chmask && !opts->c_chmask) in afunc_validate_opts()
982 else if (opts->p_chmask & ~UAC2_CHANNEL_MASK) in afunc_validate_opts()
984 else if (opts->c_chmask & ~UAC2_CHANNEL_MASK) in afunc_validate_opts()
986 else if ((opts->p_ssize < 1) || (opts->p_ssize > 4)) in afunc_validate_opts()
988 else if ((opts->c_ssize < 1) || (opts->c_ssize > 4)) in afunc_validate_opts()
990 else if (!opts->p_srates[0]) in afunc_validate_opts()
992 else if (!opts->c_srates[0]) in afunc_validate_opts()
995 else if (opts->p_volume_max <= opts->p_volume_min) in afunc_validate_opts()
997 else if (opts->c_volume_max <= opts->c_volume_min) in afunc_validate_opts()
999 else if (opts->p_volume_res <= 0) in afunc_validate_opts()
1001 else if (opts->c_volume_res <= 0) in afunc_validate_opts()
1004 else if ((opts->p_volume_max - opts->p_volume_min) % opts->p_volume_res) in afunc_validate_opts()
1006 else if ((opts->c_volume_max - opts->c_volume_min) % opts->c_volume_res) in afunc_validate_opts()
1009 else if ((opts->p_hs_bint < 0) || (opts->p_hs_bint > 4)) in afunc_validate_opts()
1010 msg = "incorrect playback HS/SS bInterval (1-4: fixed, 0: auto)"; in afunc_validate_opts()
1011 else if ((opts->c_hs_bint < 0) || (opts->c_hs_bint > 4)) in afunc_validate_opts()
1012 msg = "incorrect capture HS/SS bInterval (1-4: fixed, 0: auto)"; in afunc_validate_opts()
1016 return -EINVAL; in afunc_validate_opts()
1027 struct usb_composite_dev *cdev = cfg->cdev; in afunc_bind()
1028 struct usb_gadget *gadget = cdev->gadget; in afunc_bind()
1029 struct device *dev = &gadget->dev; in afunc_bind()
1038 strings_fn[STR_ASSOC].s = uac2_opts->function_name; in afunc_bind()
1039 strings_fn[STR_IF_CTRL].s = uac2_opts->if_ctrl_name; in afunc_bind()
1040 strings_fn[STR_CLKSRC_IN].s = uac2_opts->clksrc_in_name; in afunc_bind()
1041 strings_fn[STR_CLKSRC_OUT].s = uac2_opts->clksrc_out_name; in afunc_bind()
1043 strings_fn[STR_USB_IT].s = uac2_opts->c_it_name; in afunc_bind()
1044 strings_fn[STR_USB_IT_CH].s = uac2_opts->c_it_ch_name; in afunc_bind()
1045 strings_fn[STR_IO_OT].s = uac2_opts->c_ot_name; in afunc_bind()
1046 strings_fn[STR_FU_OUT].s = uac2_opts->c_fu_vol_name; in afunc_bind()
1050 strings_fn[STR_IO_IT].s = uac2_opts->p_it_name; in afunc_bind()
1051 strings_fn[STR_IO_IT_CH].s = uac2_opts->p_it_ch_name; in afunc_bind()
1052 strings_fn[STR_USB_OT].s = uac2_opts->p_ot_name; in afunc_bind()
1053 strings_fn[STR_FU_IN].s = uac2_opts->p_fu_vol_name; in afunc_bind()
1062 out_feature_unit_desc = build_fu_desc(uac2_opts->c_chmask); in afunc_bind()
1064 return -ENOMEM; in afunc_bind()
1067 in_feature_unit_desc = build_fu_desc(uac2_opts->p_chmask); in afunc_bind()
1069 ret = -ENOMEM; in afunc_bind()
1091 out_feature_unit_desc->bLength - 1; in afunc_bind()
1096 in_feature_unit_desc->bLength - 1; in afunc_bind()
1102 usb_out_it_desc.bNrChannels = num_channels(uac2_opts->c_chmask); in afunc_bind()
1103 usb_out_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask); in afunc_bind()
1104 io_in_it_desc.bNrChannels = num_channels(uac2_opts->p_chmask); in afunc_bind()
1105 io_in_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask); in afunc_bind()
1106 as_out_hdr_desc.bNrChannels = num_channels(uac2_opts->c_chmask); in afunc_bind()
1107 as_out_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask); in afunc_bind()
1108 as_in_hdr_desc.bNrChannels = num_channels(uac2_opts->p_chmask); in afunc_bind()
1109 as_in_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask); in afunc_bind()
1110 as_out_fmt1_desc.bSubslotSize = uac2_opts->c_ssize; in afunc_bind()
1111 as_out_fmt1_desc.bBitResolution = uac2_opts->c_ssize * 8; in afunc_bind()
1112 as_in_fmt1_desc.bSubslotSize = uac2_opts->p_ssize; in afunc_bind()
1113 as_in_fmt1_desc.bBitResolution = uac2_opts->p_ssize * 8; in afunc_bind()
1115 __le32 *bma = (__le32 *)&out_feature_unit_desc->bmaControls[0]; in afunc_bind()
1118 if (uac2_opts->c_mute_present) in afunc_bind()
1120 if (uac2_opts->c_volume_present) in afunc_bind()
1125 __le32 *bma = (__le32 *)&in_feature_unit_desc->bmaControls[0]; in afunc_bind()
1128 if (uac2_opts->p_mute_present) in afunc_bind()
1130 if (uac2_opts->p_volume_present) in afunc_bind()
1143 uac2->ac_intf = ret; in afunc_bind()
1144 uac2->ac_alt = 0; in afunc_bind()
1155 uac2->as_out_intf = ret; in afunc_bind()
1156 uac2->as_out_alt = 0; in afunc_bind()
1184 uac2->as_in_intf = ret; in afunc_bind()
1185 uac2->as_in_alt = 0; in afunc_bind()
1189 uac2->int_ep = usb_ep_autoconfig(gadget, &fs_ep_int_desc); in afunc_bind()
1190 if (!uac2->int_ep) { in afunc_bind()
1192 ret = -ENODEV; in afunc_bind()
1199 hs_epin_desc.bInterval = uac2_opts->p_hs_bint; in afunc_bind()
1200 ss_epin_desc.bInterval = uac2_opts->p_hs_bint; in afunc_bind()
1201 hs_epout_desc.bInterval = uac2_opts->c_hs_bint; in afunc_bind()
1202 ss_epout_desc.bInterval = uac2_opts->c_hs_bint; in afunc_bind()
1248 agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc); in afunc_bind()
1249 if (!agdev->out_ep) { in afunc_bind()
1251 ret = -ENODEV; in afunc_bind()
1255 agdev->in_ep_fback = usb_ep_autoconfig(gadget, in afunc_bind()
1257 if (!agdev->in_ep_fback) { in afunc_bind()
1260 ret = -ENODEV; in afunc_bind()
1267 agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc); in afunc_bind()
1268 if (!agdev->in_ep) { in afunc_bind()
1270 ret = -ENODEV; in afunc_bind()
1275 agdev->in_ep_maxpsize = max_t(u16, in afunc_bind()
1278 agdev->out_ep_maxpsize = max_t(u16, in afunc_bind()
1282 agdev->in_ep_maxpsize = max_t(u16, agdev->in_ep_maxpsize, in afunc_bind()
1284 agdev->out_ep_maxpsize = max_t(u16, agdev->out_ep_maxpsize, in afunc_bind()
1307 agdev->gadget = gadget; in afunc_bind()
1309 agdev->params.p_chmask = uac2_opts->p_chmask; in afunc_bind()
1310 memcpy(agdev->params.p_srates, uac2_opts->p_srates, in afunc_bind()
1311 sizeof(agdev->params.p_srates)); in afunc_bind()
1312 agdev->params.p_ssize = uac2_opts->p_ssize; in afunc_bind()
1314 agdev->params.p_fu.id = USB_IN_FU_ID; in afunc_bind()
1315 agdev->params.p_fu.mute_present = uac2_opts->p_mute_present; in afunc_bind()
1316 agdev->params.p_fu.volume_present = uac2_opts->p_volume_present; in afunc_bind()
1317 agdev->params.p_fu.volume_min = uac2_opts->p_volume_min; in afunc_bind()
1318 agdev->params.p_fu.volume_max = uac2_opts->p_volume_max; in afunc_bind()
1319 agdev->params.p_fu.volume_res = uac2_opts->p_volume_res; in afunc_bind()
1321 agdev->params.c_chmask = uac2_opts->c_chmask; in afunc_bind()
1322 memcpy(agdev->params.c_srates, uac2_opts->c_srates, in afunc_bind()
1323 sizeof(agdev->params.c_srates)); in afunc_bind()
1324 agdev->params.c_ssize = uac2_opts->c_ssize; in afunc_bind()
1326 agdev->params.c_fu.id = USB_OUT_FU_ID; in afunc_bind()
1327 agdev->params.c_fu.mute_present = uac2_opts->c_mute_present; in afunc_bind()
1328 agdev->params.c_fu.volume_present = uac2_opts->c_volume_present; in afunc_bind()
1329 agdev->params.c_fu.volume_min = uac2_opts->c_volume_min; in afunc_bind()
1330 agdev->params.c_fu.volume_max = uac2_opts->c_volume_max; in afunc_bind()
1331 agdev->params.c_fu.volume_res = uac2_opts->c_volume_res; in afunc_bind()
1333 agdev->params.req_number = uac2_opts->req_number; in afunc_bind()
1334 agdev->params.fb_max = uac2_opts->fb_max; in afunc_bind()
1337 agdev->notify = afunc_notify; in afunc_bind()
1347 agdev->gadget = NULL; in afunc_bind()
1359 struct g_audio *agdev = req->context; in afunc_notify_complete()
1360 struct f_uac2 *uac2 = func_to_uac2(&agdev->func); in afunc_notify_complete()
1362 atomic_dec(&uac2->int_count); in afunc_notify_complete()
1363 kfree(req->buf); in afunc_notify_complete()
1370 struct f_uac2 *uac2 = func_to_uac2(&agdev->func); in afunc_notify()
1376 if (!uac2->int_ep->enabled) in afunc_notify()
1379 if (atomic_inc_return(&uac2->int_count) > UAC2_DEF_INT_REQ_NUM) { in afunc_notify()
1380 atomic_dec(&uac2->int_count); in afunc_notify()
1384 req = usb_ep_alloc_request(uac2->int_ep, GFP_ATOMIC); in afunc_notify()
1386 ret = -ENOMEM; in afunc_notify()
1392 ret = -ENOMEM; in afunc_notify()
1396 w_index = unit_id << 8 | uac2->ac_intf; in afunc_notify()
1399 msg->bInfo = 0; /* Non-vendor, interface interrupt */ in afunc_notify()
1400 msg->bAttribute = UAC2_CS_CUR; in afunc_notify()
1401 msg->wIndex = cpu_to_le16(w_index); in afunc_notify()
1402 msg->wValue = cpu_to_le16(w_value); in afunc_notify()
1404 req->length = sizeof(*msg); in afunc_notify()
1405 req->buf = msg; in afunc_notify()
1406 req->context = agdev; in afunc_notify()
1407 req->complete = afunc_notify_complete; in afunc_notify()
1409 ret = usb_ep_queue(uac2->int_ep, req, GFP_ATOMIC); in afunc_notify()
1419 usb_ep_free_request(uac2->int_ep, req); in afunc_notify()
1421 atomic_dec(&uac2->int_count); in afunc_notify()
1429 struct usb_composite_dev *cdev = fn->config->cdev; in afunc_set_alt()
1432 struct usb_gadget *gadget = cdev->gadget; in afunc_set_alt()
1433 struct device *dev = &gadget->dev; in afunc_set_alt()
1439 return -EINVAL; in afunc_set_alt()
1442 if (intf == uac2->ac_intf) { in afunc_set_alt()
1443 /* Control I/f has only 1 AltSetting - 0 */ in afunc_set_alt()
1446 return -EINVAL; in afunc_set_alt()
1450 if (uac2->int_ep) { in afunc_set_alt()
1451 usb_ep_disable(uac2->int_ep); in afunc_set_alt()
1452 config_ep_by_speed(gadget, &agdev->func, uac2->int_ep); in afunc_set_alt()
1453 usb_ep_enable(uac2->int_ep); in afunc_set_alt()
1459 if (intf == uac2->as_out_intf) { in afunc_set_alt()
1460 uac2->as_out_alt = alt; in afunc_set_alt()
1463 ret = u_audio_start_capture(&uac2->g_audio); in afunc_set_alt()
1465 u_audio_stop_capture(&uac2->g_audio); in afunc_set_alt()
1466 } else if (intf == uac2->as_in_intf) { in afunc_set_alt()
1467 uac2->as_in_alt = alt; in afunc_set_alt()
1470 ret = u_audio_start_playback(&uac2->g_audio); in afunc_set_alt()
1472 u_audio_stop_playback(&uac2->g_audio); in afunc_set_alt()
1475 return -EINVAL; in afunc_set_alt()
1487 if (intf == uac2->ac_intf) in afunc_get_alt()
1488 return uac2->ac_alt; in afunc_get_alt()
1489 else if (intf == uac2->as_out_intf) in afunc_get_alt()
1490 return uac2->as_out_alt; in afunc_get_alt()
1491 else if (intf == uac2->as_in_intf) in afunc_get_alt()
1492 return uac2->as_in_alt; in afunc_get_alt()
1494 dev_err(&agdev->gadget->dev, in afunc_get_alt()
1498 return -EINVAL; in afunc_get_alt()
1506 uac2->as_in_alt = 0; in afunc_disable()
1507 uac2->as_out_alt = 0; in afunc_disable()
1508 u_audio_stop_capture(&uac2->g_audio); in afunc_disable()
1509 u_audio_stop_playback(&uac2->g_audio); in afunc_disable()
1510 if (uac2->int_ep) in afunc_disable()
1511 usb_ep_disable(uac2->int_ep); in afunc_disable()
1519 u_audio_suspend(&uac2->g_audio); in afunc_suspend()
1525 struct usb_request *req = fn->config->cdev->req; in in_rq_cur()
1528 u16 w_length = le16_to_cpu(cr->wLength); in in_rq_cur()
1529 u16 w_index = le16_to_cpu(cr->wIndex); in in_rq_cur()
1530 u16 w_value = le16_to_cpu(cr->wValue); in in_rq_cur()
1533 int value = -EOPNOTSUPP; in in_rq_cur()
1551 memcpy(req->buf, &c, value); in in_rq_cur()
1553 *(u8 *)req->buf = 1; in in_rq_cur()
1556 dev_err(&agdev->gadget->dev, in in_rq_cur()
1572 *(u8 *)req->buf = mute; in in_rq_cur()
1584 memcpy(req->buf, &c, value); in in_rq_cur()
1586 dev_err(&agdev->gadget->dev, in in_rq_cur()
1591 dev_err(&agdev->gadget->dev, in in_rq_cur()
1602 struct usb_request *req = fn->config->cdev->req; in in_rq_range()
1605 u16 w_length = le16_to_cpu(cr->wLength); in in_rq_range()
1606 u16 w_index = le16_to_cpu(cr->wIndex); in in_rq_range()
1607 u16 w_value = le16_to_cpu(cr->wValue); in in_rq_range()
1610 int value = -EOPNOTSUPP; in in_rq_range()
1621 srates = opts->p_srates; in in_rq_range()
1623 srates = opts->c_srates; in in_rq_range()
1625 return -EOPNOTSUPP; in in_rq_range()
1635 dev_dbg(&agdev->gadget->dev, in in_rq_range()
1641 dev_dbg(&agdev->gadget->dev, "%s(): sending %d rates, size %d\n", in in_rq_range()
1643 memcpy(req->buf, &rs, value); in in_rq_range()
1645 dev_err(&agdev->gadget->dev, in in_rq_range()
1661 max_db = opts->p_volume_max; in in_rq_range()
1662 min_db = opts->p_volume_min; in in_rq_range()
1663 res_db = opts->p_volume_res; in in_rq_range()
1665 max_db = opts->c_volume_max; in in_rq_range()
1666 min_db = opts->c_volume_min; in in_rq_range()
1667 res_db = opts->c_volume_res; in in_rq_range()
1676 memcpy(req->buf, &r, value); in in_rq_range()
1678 dev_err(&agdev->gadget->dev, in in_rq_range()
1683 dev_err(&agdev->gadget->dev, in in_rq_range()
1694 if (cr->bRequest == UAC2_CS_CUR) in ac_rq_in()
1696 else if (cr->bRequest == UAC2_CS_RANGE) in ac_rq_in()
1699 return -EOPNOTSUPP; in ac_rq_in()
1704 struct usb_function *fn = ep->driver_data; in uac2_cs_control_sam_freq()
1709 if (req->actual != 4) in uac2_cs_control_sam_freq()
1712 val = le32_to_cpu(*((__le32 *)req->buf)); in uac2_cs_control_sam_freq()
1713 dev_dbg(&agdev->gadget->dev, "%s val: %d.\n", __func__, val); in uac2_cs_control_sam_freq()
1714 if (uac2->clock_id == USB_IN_CLK_ID) { in uac2_cs_control_sam_freq()
1716 } else if (uac2->clock_id == USB_OUT_CLK_ID) { in uac2_cs_control_sam_freq()
1724 struct g_audio *agdev = req->context; in out_rq_cur_complete()
1725 struct usb_composite_dev *cdev = agdev->func.config->cdev; in out_rq_cur_complete()
1727 struct f_uac2 *uac2 = func_to_uac2(&agdev->func); in out_rq_cur_complete()
1728 struct usb_ctrlrequest *cr = &uac2->setup_cr; in out_rq_cur_complete()
1729 u16 w_index = le16_to_cpu(cr->wIndex); in out_rq_cur_complete()
1730 u16 w_value = le16_to_cpu(cr->wValue); in out_rq_cur_complete()
1734 if (req->status != 0) { in out_rq_cur_complete()
1735 dev_dbg(&cdev->gadget->dev, "completion err %d\n", req->status); in out_rq_cur_complete()
1747 u8 mute = *(u8 *)req->buf; in out_rq_cur_complete()
1753 struct cntrl_cur_lay2 *c = req->buf; in out_rq_cur_complete()
1756 volume = le16_to_cpu(c->wCUR); in out_rq_cur_complete()
1761 dev_err(&agdev->gadget->dev, in out_rq_cur_complete()
1772 struct usb_composite_dev *cdev = fn->config->cdev; in out_rq_cur()
1773 struct usb_request *req = fn->config->cdev->req; in out_rq_cur()
1777 u16 w_length = le16_to_cpu(cr->wLength); in out_rq_cur()
1778 u16 w_index = le16_to_cpu(cr->wIndex); in out_rq_cur()
1779 u16 w_value = le16_to_cpu(cr->wValue); in out_rq_cur()
1786 dev_dbg(&agdev->gadget->dev, in out_rq_cur()
1788 cdev->gadget->ep0->driver_data = fn; in out_rq_cur()
1789 uac2->clock_id = clock_id; in out_rq_cur()
1790 req->complete = uac2_cs_control_sam_freq; in out_rq_cur()
1795 memcpy(&uac2->setup_cr, cr, sizeof(*cr)); in out_rq_cur()
1796 req->context = agdev; in out_rq_cur()
1797 req->complete = out_rq_cur_complete; in out_rq_cur()
1801 dev_err(&agdev->gadget->dev, in out_rq_cur()
1805 return -EOPNOTSUPP; in out_rq_cur()
1813 u16 w_index = le16_to_cpu(cr->wIndex); in setup_rq_inf()
1816 if (intf != uac2->ac_intf) { in setup_rq_inf()
1817 dev_err(&agdev->gadget->dev, in setup_rq_inf()
1819 return -EOPNOTSUPP; in setup_rq_inf()
1822 if (cr->bRequestType & USB_DIR_IN) in setup_rq_inf()
1824 else if (cr->bRequest == UAC2_CS_CUR) in setup_rq_inf()
1827 return -EOPNOTSUPP; in setup_rq_inf()
1833 struct usb_composite_dev *cdev = fn->config->cdev; in afunc_setup()
1835 struct usb_request *req = cdev->req; in afunc_setup()
1836 u16 w_length = le16_to_cpu(cr->wLength); in afunc_setup()
1837 int value = -EOPNOTSUPP; in afunc_setup()
1839 /* Only Class specific requests are supposed to reach here */ in afunc_setup()
1840 if ((cr->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) in afunc_setup()
1841 return -EOPNOTSUPP; in afunc_setup()
1843 if ((cr->bRequestType & USB_RECIP_MASK) == USB_RECIP_INTERFACE) in afunc_setup()
1846 dev_err(&agdev->gadget->dev, "%s:%d Error!\n", in afunc_setup()
1850 req->length = value; in afunc_setup()
1851 req->zero = value < w_length; in afunc_setup()
1852 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); in afunc_setup()
1854 dev_err(&agdev->gadget->dev, in afunc_setup()
1856 req->status = 0; in afunc_setup()
1873 usb_put_function_instance(&opts->func_inst); in f_uac2_attr_release()
1897 mutex_lock(&opts->lock); \
1898 result = sprintf(page, type##_fmt, opts->name); \
1899 mutex_unlock(&opts->lock); \
1911 mutex_lock(&opts->lock); \
1912 if (opts->refcnt) { \
1913 ret = -EBUSY; \
1921 opts->name = num; \
1925 mutex_unlock(&opts->lock); \
1939 mutex_lock(&opts->lock); \
1940 switch (opts->name) { \
1952 mutex_unlock(&opts->lock); \
1963 mutex_lock(&opts->lock); \
1964 if (opts->refcnt) { \
1965 ret = -EBUSY; \
1970 opts->name = USB_ENDPOINT_SYNC_ASYNC; \
1972 opts->name = USB_ENDPOINT_SYNC_ADAPTIVE; \
1974 ret = -EINVAL; \
1981 mutex_unlock(&opts->lock); \
1995 mutex_lock(&opts->lock); \
1998 if (opts->name##s[i] == 0) \
2001 opts->name##s[i]); \
2004 page[strlen(page) - 1] = '\n'; \
2005 mutex_unlock(&opts->lock); \
2015 int ret = -EINVAL; \
2020 mutex_lock(&opts->lock); \
2021 if (opts->refcnt) { \
2022 ret = -EBUSY; \
2027 memset(opts->name##s, 0x00, sizeof(opts->name##s)); \
2034 opts->name##s[i++] = num; \
2040 mutex_unlock(&opts->lock); \
2053 mutex_lock(&opts->lock); \
2054 result = scnprintf(page, sizeof(opts->name), "%s", opts->name); \
2055 mutex_unlock(&opts->lock); \
2066 mutex_lock(&opts->lock); \
2067 if (opts->refcnt) { \
2068 ret = -EBUSY; \
2072 if (len && page[len - 1] == '\n') \
2073 len--; \
2075 scnprintf(opts->name, min(sizeof(opts->name), len + 1), \
2079 mutex_unlock(&opts->lock); \
2193 return ERR_PTR(-ENOMEM); in afunc_alloc_inst()
2195 mutex_init(&opts->lock); in afunc_alloc_inst()
2196 opts->func_inst.free_func_inst = afunc_free_inst; in afunc_alloc_inst()
2198 config_group_init_type_name(&opts->func_inst.group, "", in afunc_alloc_inst()
2201 opts->p_chmask = UAC2_DEF_PCHMASK; in afunc_alloc_inst()
2202 opts->p_srates[0] = UAC2_DEF_PSRATE; in afunc_alloc_inst()
2203 opts->p_ssize = UAC2_DEF_PSSIZE; in afunc_alloc_inst()
2204 opts->p_hs_bint = UAC2_DEF_PHSBINT; in afunc_alloc_inst()
2205 opts->c_chmask = UAC2_DEF_CCHMASK; in afunc_alloc_inst()
2206 opts->c_srates[0] = UAC2_DEF_CSRATE; in afunc_alloc_inst()
2207 opts->c_ssize = UAC2_DEF_CSSIZE; in afunc_alloc_inst()
2208 opts->c_hs_bint = UAC2_DEF_CHSBINT; in afunc_alloc_inst()
2209 opts->c_sync = UAC2_DEF_CSYNC; in afunc_alloc_inst()
2211 opts->p_mute_present = UAC2_DEF_MUTE_PRESENT; in afunc_alloc_inst()
2212 opts->p_volume_present = UAC2_DEF_VOLUME_PRESENT; in afunc_alloc_inst()
2213 opts->p_volume_min = UAC2_DEF_MIN_DB; in afunc_alloc_inst()
2214 opts->p_volume_max = UAC2_DEF_MAX_DB; in afunc_alloc_inst()
2215 opts->p_volume_res = UAC2_DEF_RES_DB; in afunc_alloc_inst()
2217 opts->c_mute_present = UAC2_DEF_MUTE_PRESENT; in afunc_alloc_inst()
2218 opts->c_volume_present = UAC2_DEF_VOLUME_PRESENT; in afunc_alloc_inst()
2219 opts->c_volume_min = UAC2_DEF_MIN_DB; in afunc_alloc_inst()
2220 opts->c_volume_max = UAC2_DEF_MAX_DB; in afunc_alloc_inst()
2221 opts->c_volume_res = UAC2_DEF_RES_DB; in afunc_alloc_inst()
2223 opts->req_number = UAC2_DEF_REQ_NUM; in afunc_alloc_inst()
2224 opts->fb_max = FBACK_FAST_MAX; in afunc_alloc_inst()
2226 scnprintf(opts->function_name, sizeof(opts->function_name), "Source/Sink"); in afunc_alloc_inst()
2227 scnprintf(opts->if_ctrl_name, sizeof(opts->if_ctrl_name), "Topology Control"); in afunc_alloc_inst()
2228 scnprintf(opts->clksrc_in_name, sizeof(opts->clksrc_in_name), "Input Clock"); in afunc_alloc_inst()
2229 scnprintf(opts->clksrc_out_name, sizeof(opts->clksrc_out_name), "Output Clock"); in afunc_alloc_inst()
2231 scnprintf(opts->p_it_name, sizeof(opts->p_it_name), "USBD Out"); in afunc_alloc_inst()
2232 scnprintf(opts->p_it_ch_name, sizeof(opts->p_it_ch_name), "Capture Channels"); in afunc_alloc_inst()
2233 scnprintf(opts->p_ot_name, sizeof(opts->p_ot_name), "USBH In"); in afunc_alloc_inst()
2234 scnprintf(opts->p_fu_vol_name, sizeof(opts->p_fu_vol_name), "Capture Volume"); in afunc_alloc_inst()
2236 scnprintf(opts->c_it_name, sizeof(opts->c_it_name), "USBH Out"); in afunc_alloc_inst()
2237 scnprintf(opts->c_it_ch_name, sizeof(opts->c_it_ch_name), "Playback Channels"); in afunc_alloc_inst()
2238 scnprintf(opts->c_ot_name, sizeof(opts->c_ot_name), "USBD In"); in afunc_alloc_inst()
2239 scnprintf(opts->c_fu_vol_name, sizeof(opts->c_fu_vol_name), "Playback Volume"); in afunc_alloc_inst()
2241 opts->p_terminal_type = UAC2_DEF_P_TERM_TYPE; in afunc_alloc_inst()
2242 opts->c_terminal_type = UAC2_DEF_C_TERM_TYPE; in afunc_alloc_inst()
2244 return &opts->func_inst; in afunc_alloc_inst()
2253 opts = container_of(f->fi, struct f_uac2_opts, func_inst); in afunc_free()
2255 mutex_lock(&opts->lock); in afunc_free()
2256 --opts->refcnt; in afunc_free()
2257 mutex_unlock(&opts->lock); in afunc_free()
2267 agdev->gadget = NULL; in afunc_unbind()
2282 return ERR_PTR(-ENOMEM); in afunc_alloc()
2285 mutex_lock(&opts->lock); in afunc_alloc()
2286 ++opts->refcnt; in afunc_alloc()
2287 mutex_unlock(&opts->lock); in afunc_alloc()
2289 uac2->g_audio.func.name = "uac2_func"; in afunc_alloc()
2290 uac2->g_audio.func.bind = afunc_bind; in afunc_alloc()
2291 uac2->g_audio.func.unbind = afunc_unbind; in afunc_alloc()
2292 uac2->g_audio.func.set_alt = afunc_set_alt; in afunc_alloc()
2293 uac2->g_audio.func.get_alt = afunc_get_alt; in afunc_alloc()
2294 uac2->g_audio.func.disable = afunc_disable; in afunc_alloc()
2295 uac2->g_audio.func.suspend = afunc_suspend; in afunc_alloc()
2296 uac2->g_audio.func.setup = afunc_setup; in afunc_alloc()
2297 uac2->g_audio.func.free_func = afunc_free; in afunc_alloc()
2299 return &uac2->g_audio.func; in afunc_alloc()