Lines Matching +full:assoc +full:- +full:select
1 // SPDX-License-Identifier: GPL-2.0-or-later
17 * - support for UAC2 effect units
18 * - support for graphical equalizers
19 * - RANGE and MEM set commands (UAC2)
20 * - RANGE and MEM interrupt dispatchers (UAC2)
21 * - audio channel clustering (UAC2)
22 * - audio sample rate converter units (UAC2)
23 * - proper handling of clock multipliers (UAC2)
24 * - dispatch clock change notifications (UAC2)
25 * - stop PCM streams which use a clock that became invalid
26 * - stop PCM streams which use a clock selector that has changed
27 * - parse available sample rates again when clock sources changed
38 #include <linux/usb/audio-v2.h>
39 #include <linux/usb/audio-v3.h>
77 /*E-mu 0202/0404/0204 eXtension Unit(XU) control*/
106 for (; p->id; p++) { in find_map()
107 if (p->id == unitid && in find_map()
108 (!control || !p->control || control == p->control)) in find_map()
118 if (!p || !p->name) in check_mapped_name()
121 buflen--; in check_mapped_name()
122 return strlcpy(buf, p->name, buflen); in check_mapped_name()
127 ((cval)->head.mixer->ignore_ctl_error ? 0 : (err))
133 if (!p || p->name || p->dB) in check_ignored_ctl()
142 if (p && p->dB) { in check_mapped_dB()
143 cval->dBmin = p->dB->min; in check_mapped_dB()
144 cval->dBmax = p->dB->max; in check_mapped_dB()
145 cval->initialized = 1; in check_mapped_dB()
155 if (!state->selector_map) in check_mapped_selector_name()
157 for (p = state->selector_map; p->id; p++) { in check_mapped_selector_name()
158 if (p->id == unitid && index < p->count) in check_mapped_selector_name()
159 return strlcpy(buf, p->names[index], buflen); in check_mapped_selector_name()
173 while ((hdr = snd_usb_find_desc(state->buffer, state->buflen, hdr, in find_audio_control_unit()
175 if (hdr->bLength >= 4 && in find_audio_control_unit()
176 hdr->bDescriptorSubtype >= UAC_INPUT_TERMINAL && in find_audio_control_unit()
177 hdr->bDescriptorSubtype <= UAC3_SAMPLE_RATE_CONVERTER && in find_audio_control_unit()
178 hdr->bUnitID == unit) in find_audio_control_unit()
191 int len = usb_string(chip->dev, index, buf, maxlen - 1); in snd_usb_copy_string_desc()
201 * convert from the byte/word on usb descriptor to the zero-based integer
205 switch (cval->val_type) { in convert_signed_value()
216 val -= 0x100; in convert_signed_value()
224 val -= 0x10000; in convert_signed_value()
231 * convert from the zero-based int to the byte/word for usb descriptor
235 switch (cval->val_type) { in convert_bytes_value()
252 if (!cval->res) in get_relative_value()
253 cval->res = 1; in get_relative_value()
254 if (val < cval->min) in get_relative_value()
256 else if (val >= cval->max) in get_relative_value()
257 return (cval->max - cval->min + cval->res - 1) / cval->res; in get_relative_value()
259 return (val - cval->min) / cval->res; in get_relative_value()
265 return cval->min; in get_abs_value()
266 if (!cval->res) in get_abs_value()
267 cval->res = 1; in get_abs_value()
268 val *= cval->res; in get_abs_value()
269 val += cval->min; in get_abs_value()
270 if (val > cval->max) in get_abs_value()
271 return cval->max; in get_abs_value()
297 return get_iface_desc(mixer->hostif)->bInterfaceNumber; in mixer_ctrl_intf()
303 struct snd_usb_audio *chip = cval->head.mixer->chip; in get_ctl_value_v1()
305 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; in get_ctl_value_v1()
311 return -EIO; in get_ctl_value_v1()
313 while (timeout-- > 0) { in get_ctl_value_v1()
314 idx = mixer_ctrl_intf(cval->head.mixer) | (cval->head.id << 8); in get_ctl_value_v1()
315 err = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request, in get_ctl_value_v1()
322 } else if (err == -ETIMEDOUT) { in get_ctl_value_v1()
328 request, validx, idx, cval->val_type); in get_ctl_value_v1()
329 err = -EINVAL; in get_ctl_value_v1()
339 struct snd_usb_audio *chip = cval->head.mixer->chip; in get_ctl_value_v2()
346 val_size = uac2_ctl_value_size(cval->val_type); in get_ctl_value_v2()
358 ret = snd_usb_lock_shutdown(chip) ? -EIO : 0; in get_ctl_value_v2()
362 idx = mixer_ctrl_intf(cval->head.mixer) | (cval->head.id << 8); in get_ctl_value_v2()
363 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest, in get_ctl_value_v2()
372 request, validx, idx, cval->val_type); in get_ctl_value_v2()
392 return -EINVAL; in get_ctl_value_v2()
404 validx += cval->idx_off; in get_ctl_value()
406 return (cval->head.mixer->protocol == UAC_VERSION_1) ? in get_ctl_value()
422 (cval->control << 8) | channel, in get_cur_mix_raw()
431 if (cval->cached & (1 << channel)) { in snd_usb_get_cur_mix_value()
432 *value = cval->cache_val[index]; in snd_usb_get_cur_mix_value()
437 if (!cval->head.mixer->ignore_ctl_error) in snd_usb_get_cur_mix_value()
438 usb_audio_dbg(cval->head.mixer->chip, in snd_usb_get_cur_mix_value()
440 cval->control, channel, err); in snd_usb_get_cur_mix_value()
443 cval->cached |= 1 << channel; in snd_usb_get_cur_mix_value()
444 cval->cache_val[index] = *value; in snd_usb_get_cur_mix_value()
455 struct snd_usb_audio *chip = cval->head.mixer->chip; in snd_usb_mixer_set_ctl_value()
459 validx += cval->idx_off; in snd_usb_mixer_set_ctl_value()
462 if (cval->head.mixer->protocol == UAC_VERSION_1) { in snd_usb_mixer_set_ctl_value()
463 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; in snd_usb_mixer_set_ctl_value()
465 val_len = uac2_ctl_value_size(cval->val_type); in snd_usb_mixer_set_ctl_value()
470 return -EINVAL; in snd_usb_mixer_set_ctl_value()
484 return -EIO; in snd_usb_mixer_set_ctl_value()
486 while (timeout-- > 0) { in snd_usb_mixer_set_ctl_value()
487 idx = mixer_ctrl_intf(cval->head.mixer) | (cval->head.id << 8); in snd_usb_mixer_set_ctl_value()
488 err = snd_usb_ctl_msg(chip->dev, in snd_usb_mixer_set_ctl_value()
489 usb_sndctrlpipe(chip->dev, 0), request, in snd_usb_mixer_set_ctl_value()
495 } else if (err == -ETIMEDOUT) { in snd_usb_mixer_set_ctl_value()
500 request, validx, idx, cval->val_type, buf[0], buf[1]); in snd_usb_mixer_set_ctl_value()
501 err = -EINVAL; in snd_usb_mixer_set_ctl_value()
519 cval->master_readonly : in snd_usb_set_cur_mix_value()
520 cval->ch_readonly & (1 << (channel - 1)); in snd_usb_set_cur_mix_value()
523 usb_audio_dbg(cval->head.mixer->chip, in snd_usb_set_cur_mix_value()
525 __func__, channel, cval->control); in snd_usb_set_cur_mix_value()
530 UAC_SET_CUR, (cval->control << 8) | channel, in snd_usb_set_cur_mix_value()
534 cval->cached |= 1 << channel; in snd_usb_set_cur_mix_value()
535 cval->cache_val[index] = value; in snd_usb_set_cur_mix_value()
545 struct usb_mixer_elem_info *cval = kcontrol->private_data; in snd_usb_mixer_vol_tlv()
549 return -ENOMEM; in snd_usb_mixer_vol_tlv()
550 if (cval->min_mute) in snd_usb_mixer_vol_tlv()
552 scale[2] = cval->dBmin; in snd_usb_mixer_vol_tlv()
553 scale[3] = cval->dBmax; in snd_usb_mixer_vol_tlv()
555 return -EFAULT; in snd_usb_mixer_vol_tlv()
588 struct usb_mixer_interface *mixer = list->mixer; in snd_usb_mixer_add_list()
591 while (snd_ctl_find_id(mixer->chip->card, &kctl->id)) in snd_usb_mixer_add_list()
592 kctl->id.index++; in snd_usb_mixer_add_list()
593 err = snd_ctl_add(mixer->chip->card, kctl); in snd_usb_mixer_add_list()
595 usb_audio_dbg(mixer->chip, "cannot add control (err = %d)\n", in snd_usb_mixer_add_list()
599 list->kctl = kctl; in snd_usb_mixer_add_list()
600 list->is_std_info = is_std_info; in snd_usb_mixer_add_list()
601 list->next_id_elem = mixer->id_elems[list->id]; in snd_usb_mixer_add_list()
602 mixer->id_elems[list->id] = list; in snd_usb_mixer_add_list()
648 { 0x0712, "Multi-Track Recorder" },
659 if (iterm->name) { in get_term_name()
660 len = snd_usb_copy_string_desc(chip, iterm->name, in get_term_name()
666 /* virtual type - not a real terminal */ in get_term_name()
667 if (iterm->type >> 16) { in get_term_name()
670 switch (iterm->type >> 16) { in get_term_name()
684 return sprintf(name, "Unit %d", iterm->id); in get_term_name()
688 switch (iterm->type & 0xff00) { in get_term_name()
703 for (names = iterm_names; names->type; names++) { in get_term_name()
704 if (names->type == iterm->type) { in get_term_name()
705 strcpy(name, names->name); in get_term_name()
706 return strlen(names->name); in get_term_name()
721 err = snd_usb_ctl_msg(state->chip->dev, in get_cluster_channels_v3()
722 usb_rcvctrlpipe(state->chip->dev, 0), in get_cluster_channels_v3()
726 snd_usb_ctrl_intf(state->chip), in get_cluster_channels_v3()
731 err = -EIO; in get_cluster_channels_v3()
738 usb_audio_err(state->chip, "cannot request logical cluster ID: %d (err: %d)\n", cluster_id, err); in get_cluster_channels_v3()
750 switch (state->mixer->protocol) { in uac_mixer_unit_get_channels()
754 if (desc->bLength < sizeof(*desc) + desc->bNrInPins + 1) in uac_mixer_unit_get_channels()
755 return 0; /* no bmControls -> skip */ in uac_mixer_unit_get_channels()
779 term->type = le16_to_cpu(d->wTerminalType); in parse_term_uac1_iterm_unit()
780 term->channels = d->bNrChannels; in parse_term_uac1_iterm_unit()
781 term->chconfig = le16_to_cpu(d->wChannelConfig); in parse_term_uac1_iterm_unit()
782 term->name = d->iTerminal; in parse_term_uac1_iterm_unit()
794 err = __check_input_term(state, d->bCSourceID, term); in parse_term_uac2_iterm_unit()
801 term->id = id; in parse_term_uac2_iterm_unit()
802 term->type = le16_to_cpu(d->wTerminalType); in parse_term_uac2_iterm_unit()
803 term->channels = d->bNrChannels; in parse_term_uac2_iterm_unit()
804 term->chconfig = le32_to_cpu(d->bmChannelConfig); in parse_term_uac2_iterm_unit()
805 term->name = d->iTerminal; in parse_term_uac2_iterm_unit()
817 err = __check_input_term(state, d->bCSourceID, term); in parse_term_uac3_iterm_unit()
824 term->id = id; in parse_term_uac3_iterm_unit()
825 term->type = le16_to_cpu(d->wTerminalType); in parse_term_uac3_iterm_unit()
827 err = get_cluster_channels_v3(state, le16_to_cpu(d->wClusterDescrID)); in parse_term_uac3_iterm_unit()
830 term->channels = err; in parse_term_uac3_iterm_unit()
833 term->chconfig = 0; in parse_term_uac3_iterm_unit()
835 term->name = le16_to_cpu(d->wTerminalDescrStr); in parse_term_uac3_iterm_unit()
844 int protocol = state->mixer->protocol; in parse_term_mixer_unit()
851 term->type = UAC3_MIXER_UNIT << 16; /* virtual type */ in parse_term_mixer_unit()
852 term->channels = err; in parse_term_mixer_unit()
854 term->chconfig = uac_mixer_unit_wChannelConfig(d, protocol); in parse_term_mixer_unit()
855 term->name = uac_mixer_unit_iMixer(d); in parse_term_mixer_unit()
868 err = __check_input_term(state, d->baSourceID[0], term); in parse_term_selector_unit()
871 term->type = UAC3_SELECTOR_UNIT << 16; /* virtual type */ in parse_term_selector_unit()
872 term->id = id; in parse_term_selector_unit()
873 if (state->mixer->protocol != UAC_VERSION_3) in parse_term_selector_unit()
874 term->name = uac_selector_unit_iSelector(d); in parse_term_selector_unit()
883 int protocol = state->mixer->protocol; in parse_term_proc_unit()
886 if (d->bNrInPins) { in parse_term_proc_unit()
888 err = __check_input_term(state, d->baSourceID[0], term); in parse_term_proc_unit()
893 term->type = vtype << 16; /* virtual type */ in parse_term_proc_unit()
894 term->id = id; in parse_term_proc_unit()
899 if (!term->channels) { in parse_term_proc_unit()
900 term->channels = uac_processing_unit_bNrChannels(d); in parse_term_proc_unit()
901 term->chconfig = uac_processing_unit_wChannelConfig(d, protocol); in parse_term_proc_unit()
903 term->name = uac_processing_unit_iProcessing(d, protocol); in parse_term_proc_unit()
914 err = __check_input_term(state, d->bSourceID, term); in parse_term_effect_unit()
917 term->type = UAC3_EFFECT_UNIT << 16; /* virtual type */ in parse_term_effect_unit()
918 term->id = id; in parse_term_effect_unit()
928 term->type = UAC3_CLOCK_SOURCE << 16; /* virtual type */ in parse_term_uac2_clock_source()
929 term->id = id; in parse_term_uac2_clock_source()
930 term->name = d->iClockSource; in parse_term_uac2_clock_source()
940 term->type = UAC3_CLOCK_SOURCE << 16; /* virtual type */ in parse_term_uac3_clock_source()
941 term->id = id; in parse_term_uac3_clock_source()
942 term->name = le16_to_cpu(d->wClockSourceStr); in parse_term_uac3_clock_source()
955 int protocol = state->mixer->protocol; in __check_input_term()
961 if (test_and_set_bit(id, state->termbitmap)) in __check_input_term()
962 return -EINVAL; in __check_input_term()
971 term->id = id; in __check_input_term()
980 id = d->bSourceID; in __check_input_term()
1017 return -ENODEV; in __check_input_term()
1020 return -ENODEV; in __check_input_term()
1028 memset(state->termbitmap, 0, sizeof(state->termbitmap)); in check_input_term()
1041 int type_uac2; /* data type for uac2 if different from uac1, else -1 */
1045 { UAC_FU_MUTE, "Mute", USB_MIXER_INV_BOOLEAN, -1 },
1046 { UAC_FU_VOLUME, "Volume", USB_MIXER_S16, -1 },
1047 { UAC_FU_BASS, "Tone Control - Bass", USB_MIXER_S8, -1 },
1048 { UAC_FU_MID, "Tone Control - Mid", USB_MIXER_S8, -1 },
1049 { UAC_FU_TREBLE, "Tone Control - Treble", USB_MIXER_S8, -1 },
1050 …{ UAC_FU_GRAPHIC_EQUALIZER, "Graphic Equalizer", USB_MIXER_S8, -1 }, /* FIXME: not implemented yet…
1051 { UAC_FU_AUTOMATIC_GAIN, "Auto Gain Control", USB_MIXER_BOOLEAN, -1 },
1053 { UAC_FU_BASS_BOOST, "Bass Boost", USB_MIXER_BOOLEAN, -1 },
1054 { UAC_FU_LOUDNESS, "Loudness", USB_MIXER_BOOLEAN, -1 },
1056 { UAC2_FU_INPUT_GAIN, "Input Gain Control", USB_MIXER_S16, -1 },
1057 { UAC2_FU_INPUT_GAIN_PAD, "Input Gain Pad Control", USB_MIXER_S16, -1 },
1058 { UAC2_FU_PHASE_INVERTER, "Phase Inverter Control", USB_MIXER_BOOLEAN, -1 },
1069 usb_mixer_elem_info_free(kctl->private_data); in snd_usb_mixer_elem_free()
1070 kctl->private_data = NULL; in snd_usb_mixer_elem_free()
1081 struct snd_usb_audio *chip = cval->head.mixer->chip; in volume_control_quirks()
1082 switch (chip->usb_id) { in volume_control_quirks()
1083 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ in volume_control_quirks()
1084 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */ in volume_control_quirks()
1085 if (strcmp(kctl->id.name, "Effect Duration") == 0) { in volume_control_quirks()
1086 cval->min = 0x0000; in volume_control_quirks()
1087 cval->max = 0xffff; in volume_control_quirks()
1088 cval->res = 0x00e6; in volume_control_quirks()
1091 if (strcmp(kctl->id.name, "Effect Volume") == 0 || in volume_control_quirks()
1092 strcmp(kctl->id.name, "Effect Feedback Volume") == 0) { in volume_control_quirks()
1093 cval->min = 0x00; in volume_control_quirks()
1094 cval->max = 0xff; in volume_control_quirks()
1097 if (strstr(kctl->id.name, "Effect Return") != NULL) { in volume_control_quirks()
1098 cval->min = 0xb706; in volume_control_quirks()
1099 cval->max = 0xff7b; in volume_control_quirks()
1100 cval->res = 0x0073; in volume_control_quirks()
1103 if ((strstr(kctl->id.name, "Playback Volume") != NULL) || in volume_control_quirks()
1104 (strstr(kctl->id.name, "Effect Send") != NULL)) { in volume_control_quirks()
1105 cval->min = 0xb5fb; /* -73 dB = 0xb6ff */ in volume_control_quirks()
1106 cval->max = 0xfcfe; in volume_control_quirks()
1107 cval->res = 0x0073; in volume_control_quirks()
1111 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ in volume_control_quirks()
1112 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ in volume_control_quirks()
1113 if (strcmp(kctl->id.name, "Effect Duration") == 0) { in volume_control_quirks()
1116 cval->min = 0x0000; in volume_control_quirks()
1117 cval->max = 0x7f00; in volume_control_quirks()
1118 cval->res = 0x0100; in volume_control_quirks()
1121 if (strcmp(kctl->id.name, "Effect Volume") == 0 || in volume_control_quirks()
1122 strcmp(kctl->id.name, "Effect Feedback Volume") == 0) { in volume_control_quirks()
1125 cval->min = 0x00; in volume_control_quirks()
1126 cval->max = 0x7f; in volume_control_quirks()
1132 if (!strcmp(kctl->id.name, "PCM Playback Volume")) { in volume_control_quirks()
1134 "set volume quirk for CM102-A+/102S+\n"); in volume_control_quirks()
1135 cval->min = -256; in volume_control_quirks()
1146 * I hope that the min value is -15360 for newer firmware --jk in volume_control_quirks()
1148 if (!strcmp(kctl->id.name, "PCM Playback Volume") && in volume_control_quirks()
1149 cval->min == -15616) { in volume_control_quirks()
1152 cval->max = -256; in volume_control_quirks()
1157 if (!strcmp(kctl->id.name, "Mic Capture Volume")) { in volume_control_quirks()
1160 cval->min = 6080; in volume_control_quirks()
1161 cval->max = 8768; in volume_control_quirks()
1162 cval->res = 192; in volume_control_quirks()
1179 * Probably there is some logitech magic behind this number --fishor in volume_control_quirks()
1181 if (!strcmp(kctl->id.name, "Mic Capture Volume")) { in volume_control_quirks()
1183 "set resolution quirk: cval->res = 384\n"); in volume_control_quirks()
1184 cval->res = 384; in volume_control_quirks()
1188 if ((strstr(kctl->id.name, "Playback Volume") != NULL) || in volume_control_quirks()
1189 strstr(kctl->id.name, "Capture Volume") != NULL) { in volume_control_quirks()
1190 cval->min >>= 8; in volume_control_quirks()
1191 cval->max = 0; in volume_control_quirks()
1192 cval->res = 1; in volume_control_quirks()
1205 cval->min = default_min; in get_min_max_with_quirks()
1206 cval->max = cval->min + 1; in get_min_max_with_quirks()
1207 cval->res = 1; in get_min_max_with_quirks()
1208 cval->dBmin = cval->dBmax = 0; in get_min_max_with_quirks()
1210 if (cval->val_type == USB_MIXER_BOOLEAN || in get_min_max_with_quirks()
1211 cval->val_type == USB_MIXER_INV_BOOLEAN) { in get_min_max_with_quirks()
1212 cval->initialized = 1; in get_min_max_with_quirks()
1215 if (cval->cmask) { in get_min_max_with_quirks()
1218 if (cval->cmask & (1 << i)) { in get_min_max_with_quirks()
1223 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || in get_min_max_with_quirks()
1224 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { in get_min_max_with_quirks()
1225 usb_audio_err(cval->head.mixer->chip, in get_min_max_with_quirks()
1227 cval->head.id, mixer_ctrl_intf(cval->head.mixer), in get_min_max_with_quirks()
1228 cval->control, cval->head.id); in get_min_max_with_quirks()
1229 return -EINVAL; in get_min_max_with_quirks()
1232 (cval->control << 8) | minchn, in get_min_max_with_quirks()
1233 &cval->res) < 0) { in get_min_max_with_quirks()
1234 cval->res = 1; in get_min_max_with_quirks()
1236 int last_valid_res = cval->res; in get_min_max_with_quirks()
1238 while (cval->res > 1) { in get_min_max_with_quirks()
1240 (cval->control << 8) | minchn, in get_min_max_with_quirks()
1241 cval->res / 2) < 0) in get_min_max_with_quirks()
1243 cval->res /= 2; in get_min_max_with_quirks()
1246 (cval->control << 8) | minchn, &cval->res) < 0) in get_min_max_with_quirks()
1247 cval->res = last_valid_res; in get_min_max_with_quirks()
1249 if (cval->res == 0) in get_min_max_with_quirks()
1250 cval->res = 1; in get_min_max_with_quirks()
1258 if (cval->min + cval->res < cval->max) { in get_min_max_with_quirks()
1259 int last_valid_res = cval->res; in get_min_max_with_quirks()
1265 if (test < cval->max) in get_min_max_with_quirks()
1266 test += cval->res; in get_min_max_with_quirks()
1268 test -= cval->res; in get_min_max_with_quirks()
1269 if (test < cval->min || test > cval->max || in get_min_max_with_quirks()
1272 cval->res = last_valid_res; in get_min_max_with_quirks()
1277 cval->res *= 2; in get_min_max_with_quirks()
1283 cval->initialized = 1; in get_min_max_with_quirks()
1292 cval->dBmin = (convert_signed_value(cval, cval->min) * 100) / 256; in get_min_max_with_quirks()
1293 cval->dBmax = (convert_signed_value(cval, cval->max) * 100) / 256; in get_min_max_with_quirks()
1294 if (cval->dBmin > cval->dBmax) { in get_min_max_with_quirks()
1296 if (cval->dBmin < 0) in get_min_max_with_quirks()
1297 cval->dBmax = 0; in get_min_max_with_quirks()
1298 else if (cval->dBmin > 0) in get_min_max_with_quirks()
1299 cval->dBmin = 0; in get_min_max_with_quirks()
1300 if (cval->dBmin > cval->dBmax) { in get_min_max_with_quirks()
1302 return -EINVAL; in get_min_max_with_quirks()
1315 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_feature_info()
1317 if (cval->val_type == USB_MIXER_BOOLEAN || in mixer_ctl_feature_info()
1318 cval->val_type == USB_MIXER_INV_BOOLEAN) in mixer_ctl_feature_info()
1319 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; in mixer_ctl_feature_info()
1321 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in mixer_ctl_feature_info()
1322 uinfo->count = cval->channels; in mixer_ctl_feature_info()
1323 if (cval->val_type == USB_MIXER_BOOLEAN || in mixer_ctl_feature_info()
1324 cval->val_type == USB_MIXER_INV_BOOLEAN) { in mixer_ctl_feature_info()
1325 uinfo->value.integer.min = 0; in mixer_ctl_feature_info()
1326 uinfo->value.integer.max = 1; in mixer_ctl_feature_info()
1328 if (!cval->initialized) { in mixer_ctl_feature_info()
1330 if (cval->initialized && cval->dBmin >= cval->dBmax) { in mixer_ctl_feature_info()
1331 kcontrol->vd[0].access &= in mixer_ctl_feature_info()
1334 snd_ctl_notify(cval->head.mixer->chip->card, in mixer_ctl_feature_info()
1336 &kcontrol->id); in mixer_ctl_feature_info()
1339 uinfo->value.integer.min = 0; in mixer_ctl_feature_info()
1340 uinfo->value.integer.max = in mixer_ctl_feature_info()
1341 (cval->max - cval->min + cval->res - 1) / cval->res; in mixer_ctl_feature_info()
1350 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_feature_get()
1353 ucontrol->value.integer.value[0] = cval->min; in mixer_ctl_feature_get()
1354 if (cval->cmask) { in mixer_ctl_feature_get()
1357 if (!(cval->cmask & (1 << c))) in mixer_ctl_feature_get()
1363 ucontrol->value.integer.value[cnt] = val; in mixer_ctl_feature_get()
1373 ucontrol->value.integer.value[0] = val; in mixer_ctl_feature_get()
1382 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_feature_put()
1386 if (cval->cmask) { in mixer_ctl_feature_put()
1389 if (!(cval->cmask & (1 << c))) in mixer_ctl_feature_put()
1394 val = ucontrol->value.integer.value[cnt]; in mixer_ctl_feature_put()
1407 val = ucontrol->value.integer.value[0]; in mixer_ctl_feature_put()
1421 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_master_bool_get()
1428 ucontrol->value.integer.value[0] = val; in mixer_ctl_master_bool_get()
1436 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_connector_get()
1437 struct snd_usb_audio *chip = cval->head.mixer->chip; in mixer_ctl_connector_get()
1440 validx = cval->control << 8 | 0; in mixer_ctl_connector_get()
1442 ret = snd_usb_lock_shutdown(chip) ? -EIO : 0; in mixer_ctl_connector_get()
1446 idx = mixer_ctrl_intf(cval->head.mixer) | (cval->head.id << 8); in mixer_ctl_connector_get()
1447 if (cval->head.mixer->protocol == UAC_VERSION_2) { in mixer_ctl_connector_get()
1450 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), UAC2_CS_CUR, in mixer_ctl_connector_get()
1457 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), UAC2_CS_CUR, in mixer_ctl_connector_get()
1466 if (strstr(kcontrol->id.name, "Speaker")) { in mixer_ctl_connector_get()
1467 ucontrol->value.integer.value[0] = 1; in mixer_ctl_connector_get()
1473 UAC_GET_CUR, validx, idx, cval->val_type); in mixer_ctl_connector_get()
1477 ucontrol->value.integer.value[0] = val; in mixer_ctl_connector_get()
1489 /* the read-only variant */
1531 return strlcat(kctl->id.name, str, sizeof(kctl->id.name)); in append_ctl_name()
1547 if (strcmp("Speaker", kctl->id.name)) in check_no_speaker_on_headset()
1551 if (strstr(card->shortname, *s)) { in check_no_speaker_on_headset()
1559 strlcpy(kctl->id.name, "Headphone", sizeof(kctl->id.name)); in check_no_speaker_on_headset()
1600 snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid); in __build_feature_ctl()
1601 cval->control = control; in __build_feature_ctl()
1602 cval->cmask = ctl_mask; in __build_feature_ctl()
1609 if (mixer->protocol == UAC_VERSION_1) in __build_feature_ctl()
1610 cval->val_type = ctl_info->type; in __build_feature_ctl()
1612 cval->val_type = ctl_info->type_uac2 >= 0 ? in __build_feature_ctl()
1613 ctl_info->type_uac2 : ctl_info->type; in __build_feature_ctl()
1616 cval->channels = 1; /* master channel */ in __build_feature_ctl()
1617 cval->master_readonly = readonly_mask; in __build_feature_ctl()
1623 cval->channels = c; in __build_feature_ctl()
1624 cval->ch_readonly = readonly_mask; in __build_feature_ctl()
1628 * If all channels in the mask are marked read-only, make the control in __build_feature_ctl()
1629 * read-only. snd_usb_set_cur_mix_value() will check the mask again and won't in __build_feature_ctl()
1630 * issue write commands to read-only channels. in __build_feature_ctl()
1632 if (cval->channels == readonly_mask) in __build_feature_ctl()
1638 usb_audio_err(mixer->chip, "cannot malloc kcontrol\n"); in __build_feature_ctl()
1642 kctl->private_free = snd_usb_mixer_elem_free; in __build_feature_ctl()
1644 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); in __build_feature_ctl()
1647 len = snd_usb_copy_string_desc(mixer->chip, nameid, in __build_feature_ctl()
1648 kctl->id.name, sizeof(kctl->id.name)); in __build_feature_ctl()
1655 * - if a name id is given in descriptor, use it. in __build_feature_ctl()
1656 * - if the connected input can be determined, then use the name in __build_feature_ctl()
1658 * - if the connected output can be determined, use it. in __build_feature_ctl()
1659 * - otherwise, anonymous name. in __build_feature_ctl()
1663 len = get_term_name(mixer->chip, iterm, in __build_feature_ctl()
1664 kctl->id.name, in __build_feature_ctl()
1665 sizeof(kctl->id.name), 1); in __build_feature_ctl()
1667 len = get_term_name(mixer->chip, oterm, in __build_feature_ctl()
1668 kctl->id.name, in __build_feature_ctl()
1669 sizeof(kctl->id.name), 1); in __build_feature_ctl()
1671 snprintf(kctl->id.name, sizeof(kctl->id.name), in __build_feature_ctl()
1676 check_no_speaker_on_headset(kctl, mixer->chip->card); in __build_feature_ctl()
1683 if (!mapped_name && oterm && !(oterm->type >> 16)) { in __build_feature_ctl()
1684 if ((oterm->type & 0xff00) == 0x0100) in __build_feature_ctl()
1694 strlcpy(kctl->id.name, audio_feature_info[control-1].name, in __build_feature_ctl()
1695 sizeof(kctl->id.name)); in __build_feature_ctl()
1703 if (cval->max <= cval->min) { in __build_feature_ctl()
1704 usb_audio_dbg(mixer->chip, in __build_feature_ctl()
1706 cval->head.id, kctl->id.name); in __build_feature_ctl()
1714 if (cval->dBmin < cval->dBmax || !cval->initialized) { in __build_feature_ctl()
1715 kctl->tlv.c = snd_usb_mixer_vol_tlv; in __build_feature_ctl()
1716 kctl->vd[0].access |= in __build_feature_ctl()
1724 range = (cval->max - cval->min) / cval->res; in __build_feature_ctl()
1731 usb_audio_warn(mixer->chip, in __build_feature_ctl()
1732 "Warning! Unlikely big volume range (=%u), cval->res is probably wrong.", in __build_feature_ctl()
1734 usb_audio_warn(mixer->chip, in __build_feature_ctl()
1736 cval->head.id, kctl->id.name, cval->channels, in __build_feature_ctl()
1737 cval->min, cval->max, cval->res); in __build_feature_ctl()
1740 usb_audio_dbg(mixer->chip, "[%d] FU [%s] ch = %d, val = %d/%d/%d\n", in __build_feature_ctl()
1741 cval->head.id, kctl->id.name, cval->channels, in __build_feature_ctl()
1742 cval->min, cval->max, cval->res); in __build_feature_ctl()
1743 snd_usb_mixer_add_control(&cval->head, kctl); in __build_feature_ctl()
1754 __build_feature_ctl(state->mixer, state->map, ctl_mask, control, in build_feature_ctl()
1755 iterm, &state->oterm, unitid, nameid, readonly_mask); in build_feature_ctl()
1770 int name_len = get_term_name(mixer->chip, term, name, name_size, 0); in get_connector_control_name()
1781 strlcat(name, " - Input Jack", name_size); in get_connector_control_name()
1783 strlcat(name, " - Output Jack", name_size); in get_connector_control_name()
1786 /* Build a mixer control for a UAC connector control (jack-detect) */
1795 map = find_map(imap, term->id, 0); in build_connector_control()
1802 snd_usb_mixer_elem_init_std(&cval->head, mixer, term->id); in build_connector_control()
1813 if (mixer->protocol == UAC_VERSION_2) in build_connector_control()
1814 cval->control = UAC2_TE_CONNECTOR; in build_connector_control()
1816 cval->control = UAC3_TE_INSERTION; in build_connector_control()
1818 cval->val_type = USB_MIXER_BOOLEAN; in build_connector_control()
1819 cval->channels = 1; /* report true if any channel is connected */ in build_connector_control()
1820 cval->min = 0; in build_connector_control()
1821 cval->max = 1; in build_connector_control()
1824 usb_audio_err(mixer->chip, "cannot malloc kcontrol\n"); in build_connector_control()
1829 if (check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name))) in build_connector_control()
1830 strlcat(kctl->id.name, " Jack", sizeof(kctl->id.name)); in build_connector_control()
1832 get_connector_control_name(mixer, term, is_input, kctl->id.name, in build_connector_control()
1833 sizeof(kctl->id.name)); in build_connector_control()
1834 kctl->private_free = snd_usb_mixer_elem_free; in build_connector_control()
1835 snd_usb_mixer_add_control(&cval->head, kctl); in build_connector_control()
1847 if (state->mixer->protocol != UAC_VERSION_2) in parse_clock_source_unit()
1848 return -EINVAL; in parse_clock_source_unit()
1854 if (!uac_v2v3_control_is_readable(hdr->bmControls, in parse_clock_source_unit()
1860 return -ENOMEM; in parse_clock_source_unit()
1862 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, hdr->bClockID); in parse_clock_source_unit()
1864 cval->min = 0; in parse_clock_source_unit()
1865 cval->max = 1; in parse_clock_source_unit()
1866 cval->channels = 1; in parse_clock_source_unit()
1867 cval->val_type = USB_MIXER_BOOLEAN; in parse_clock_source_unit()
1868 cval->control = UAC2_CS_CONTROL_CLOCK_VALID; in parse_clock_source_unit()
1870 cval->master_readonly = 1; in parse_clock_source_unit()
1876 return -ENOMEM; in parse_clock_source_unit()
1879 kctl->private_free = snd_usb_mixer_elem_free; in parse_clock_source_unit()
1880 ret = snd_usb_copy_string_desc(state->chip, hdr->iClockSource, in parse_clock_source_unit()
1883 snprintf(kctl->id.name, sizeof(kctl->id.name), in parse_clock_source_unit()
1886 snprintf(kctl->id.name, sizeof(kctl->id.name), in parse_clock_source_unit()
1887 "Clock Source %d Validity", hdr->bClockID); in parse_clock_source_unit()
1889 return snd_usb_mixer_add_control(&cval->head, kctl); in parse_clock_source_unit()
1907 if (state->mixer->protocol == UAC_VERSION_1) { in parse_audio_feature_unit()
1908 csize = hdr->bControlSize; in parse_audio_feature_unit()
1909 channels = (hdr->bLength - 7) / csize - 1; in parse_audio_feature_unit()
1910 bmaControls = hdr->bmaControls; in parse_audio_feature_unit()
1911 } else if (state->mixer->protocol == UAC_VERSION_2) { in parse_audio_feature_unit()
1914 channels = (hdr->bLength - 6) / 4 - 1; in parse_audio_feature_unit()
1915 bmaControls = ftr->bmaControls; in parse_audio_feature_unit()
1920 channels = (ftr->bLength - 7) / 4 - 1; in parse_audio_feature_unit()
1921 bmaControls = ftr->bmaControls; in parse_audio_feature_unit()
1925 err = parse_audio_unit(state, hdr->bSourceID); in parse_audio_feature_unit()
1930 err = check_input_term(state, hdr->bSourceID, &iterm); in parse_audio_feature_unit()
1936 switch (state->chip->usb_id) { in parse_audio_feature_unit()
1938 usb_audio_info(state->chip, in parse_audio_feature_unit()
1940 /* disable non-functional volume control */ in parse_audio_feature_unit()
1944 usb_audio_info(state->chip, in parse_audio_feature_unit()
1946 /* disable non-functional volume control */ in parse_audio_feature_unit()
1952 if (state->mixer->protocol == UAC_VERSION_1) { in parse_audio_feature_unit()
1966 /* audio class v1 controls are never read-only */ in parse_audio_feature_unit()
1999 * read-only if all channels are marked read-only in in parse_audio_feature_unit()
2002 * actually issue a write command for read-only in parse_audio_feature_unit()
2069 map = find_map(state->map, unitid, 0); in build_mixer_unit_ctl()
2077 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid); in build_mixer_unit_ctl()
2078 cval->control = in_ch + 1; /* based on 1 */ in build_mixer_unit_ctl()
2079 cval->val_type = USB_MIXER_S16; in build_mixer_unit_ctl()
2081 __u8 *c = uac_mixer_unit_bmControls(desc, state->mixer->protocol); in build_mixer_unit_ctl()
2084 cval->cmask |= (1 << i); in build_mixer_unit_ctl()
2085 cval->channels++; in build_mixer_unit_ctl()
2094 usb_audio_err(state->chip, "cannot malloc kcontrol\n"); in build_mixer_unit_ctl()
2098 kctl->private_free = snd_usb_mixer_elem_free; in build_mixer_unit_ctl()
2100 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); in build_mixer_unit_ctl()
2102 len = get_term_name(state->chip, iterm, kctl->id.name, in build_mixer_unit_ctl()
2103 sizeof(kctl->id.name), 0); in build_mixer_unit_ctl()
2105 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); in build_mixer_unit_ctl()
2108 usb_audio_dbg(state->chip, "[%d] MU [%s] ch = %d, val = %d/%d\n", in build_mixer_unit_ctl()
2109 cval->head.id, kctl->id.name, cval->channels, cval->min, cval->max); in build_mixer_unit_ctl()
2110 snd_usb_mixer_add_control(&cval->head, kctl); in build_mixer_unit_ctl()
2119 if (state->mixer->protocol == UAC_VERSION_2) { in parse_audio_input_terminal()
2122 term_id = d_v2->bTerminalID; in parse_audio_input_terminal()
2123 bmctls = le16_to_cpu(d_v2->bmControls); in parse_audio_input_terminal()
2124 } else if (state->mixer->protocol == UAC_VERSION_3) { in parse_audio_input_terminal()
2127 term_id = d_v3->bTerminalID; in parse_audio_input_terminal()
2128 bmctls = le32_to_cpu(d_v3->bmControls); in parse_audio_input_terminal()
2138 build_connector_control(state->mixer, state->map, &iterm, true); in parse_audio_input_terminal()
2156 usb_audio_err(state->chip, in parse_audio_mixer_unit()
2163 input_pins = desc->bNrInPins; in parse_audio_mixer_unit()
2168 err = parse_audio_unit(state, desc->baSourceID[pin]); in parse_audio_mixer_unit()
2171 /* no bmControls field (e.g. Maya44) -> ignore */ in parse_audio_mixer_unit()
2174 err = check_input_term(state, desc->baSourceID[pin], &iterm); in parse_audio_mixer_unit()
2178 if (mixer_bitmap_overflow(desc, state->mixer->protocol, in parse_audio_mixer_unit()
2186 state->mixer->protocol); in parse_audio_mixer_unit()
2209 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_procunit_get()
2212 err = get_cur_ctl_value(cval, cval->control << 8, &val); in mixer_ctl_procunit_get()
2214 ucontrol->value.integer.value[0] = cval->min; in mixer_ctl_procunit_get()
2218 ucontrol->value.integer.value[0] = val; in mixer_ctl_procunit_get()
2226 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_procunit_put()
2229 err = get_cur_ctl_value(cval, cval->control << 8, &oval); in mixer_ctl_procunit_put()
2232 val = ucontrol->value.integer.value[0]; in mixer_ctl_procunit_put()
2235 set_cur_ctl_value(cval, cval->control << 8, val); in mixer_ctl_procunit_put()
2273 { UAC_UD_MODE_SELECT, "Mode Select", USB_MIXER_U8, 1 },
2278 { UAC_DP_MODE_SELECT, "Mode Select", USB_MIXER_U8, 1 },
2321 { UAC3_UD_MODE_SELECT, "Mode Select", USB_MIXER_U8, 1 },
2332 { UAC3_PROCESS_MULTI_FUNCTION, "Multi-Function", undefined_proc_info },
2388 num_ins = desc->bNrInPins; in build_audio_procunit()
2390 err = parse_audio_unit(state, desc->baSourceID[i]); in build_audio_procunit()
2395 type = le16_to_cpu(desc->wProcessType); in build_audio_procunit()
2396 for (info = list; info && info->type; info++) in build_audio_procunit()
2397 if (info->type == type) in build_audio_procunit()
2399 if (!info || !info->type) in build_audio_procunit()
2402 for (valinfo = info->values; valinfo->control; valinfo++) { in build_audio_procunit()
2403 __u8 *controls = uac_processing_unit_bmControls(desc, state->mixer->protocol); in build_audio_procunit()
2405 if (state->mixer->protocol == UAC_VERSION_1) { in build_audio_procunit()
2406 if (!(controls[valinfo->control / 8] & in build_audio_procunit()
2407 (1 << ((valinfo->control % 8) - 1)))) in build_audio_procunit()
2410 if (!uac_v2v3_control_is_readable(controls[valinfo->control / 8], in build_audio_procunit()
2411 valinfo->control)) in build_audio_procunit()
2415 map = find_map(state->map, unitid, valinfo->control); in build_audio_procunit()
2420 return -ENOMEM; in build_audio_procunit()
2421 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid); in build_audio_procunit()
2422 cval->control = valinfo->control; in build_audio_procunit()
2423 cval->val_type = valinfo->val_type; in build_audio_procunit()
2424 cval->channels = 1; in build_audio_procunit()
2426 if (state->mixer->protocol > UAC_VERSION_1 && in build_audio_procunit()
2427 !uac_v2v3_control_is_writeable(controls[valinfo->control / 8], in build_audio_procunit()
2428 valinfo->control)) in build_audio_procunit()
2429 cval->master_readonly = 1; in build_audio_procunit()
2436 switch (state->mixer->protocol) { in build_audio_procunit()
2440 if (cval->control == UAC_UD_MODE_SELECT) in build_audio_procunit()
2444 if (cval->control == UAC3_UD_MODE_SELECT) in build_audio_procunit()
2451 state->mixer->protocol); in build_audio_procunit()
2452 cval->min = 1; in build_audio_procunit()
2453 cval->max = control_spec[0]; in build_audio_procunit()
2454 cval->res = 1; in build_audio_procunit()
2455 cval->initialized = 1; in build_audio_procunit()
2459 get_min_max(cval, valinfo->min_value); in build_audio_procunit()
2464 * E-Mu USB 0404/0202/TrackerPre/0204 in build_audio_procunit()
2467 cval->min = 0; in build_audio_procunit()
2468 cval->max = 5; in build_audio_procunit()
2469 cval->res = 1; in build_audio_procunit()
2470 cval->initialized = 1; in build_audio_procunit()
2473 get_min_max(cval, valinfo->min_value); in build_audio_procunit()
2477 err = get_cur_ctl_value(cval, cval->control << 8, &val); in build_audio_procunit()
2480 return -EINVAL; in build_audio_procunit()
2486 return -ENOMEM; in build_audio_procunit()
2488 kctl->private_free = snd_usb_mixer_elem_free; in build_audio_procunit()
2490 if (check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name))) { in build_audio_procunit()
2492 } else if (info->name) { in build_audio_procunit()
2493 strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name)); in build_audio_procunit()
2496 nameid = uac_extension_unit_iExtension(desc, state->mixer->protocol); in build_audio_procunit()
2498 nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol); in build_audio_procunit()
2501 len = snd_usb_copy_string_desc(state->chip, in build_audio_procunit()
2503 kctl->id.name, in build_audio_procunit()
2504 sizeof(kctl->id.name)); in build_audio_procunit()
2506 strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); in build_audio_procunit()
2509 append_ctl_name(kctl, valinfo->suffix); in build_audio_procunit()
2511 usb_audio_dbg(state->chip, in build_audio_procunit()
2513 cval->head.id, kctl->id.name, cval->channels, in build_audio_procunit()
2514 cval->min, cval->max); in build_audio_procunit()
2516 err = snd_usb_mixer_add_control(&cval->head, kctl); in build_audio_procunit()
2526 switch (state->mixer->protocol) { in parse_audio_processing_unit()
2559 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_selector_info()
2560 const char **itemlist = (const char **)kcontrol->private_value; in mixer_ctl_selector_info()
2563 return -EINVAL; in mixer_ctl_selector_info()
2564 return snd_ctl_enum_info(uinfo, 1, cval->max, itemlist); in mixer_ctl_selector_info()
2571 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_selector_get()
2574 err = get_cur_ctl_value(cval, cval->control << 8, &val); in mixer_ctl_selector_get()
2576 ucontrol->value.enumerated.item[0] = 0; in mixer_ctl_selector_get()
2580 ucontrol->value.enumerated.item[0] = val; in mixer_ctl_selector_get()
2588 struct usb_mixer_elem_info *cval = kcontrol->private_data; in mixer_ctl_selector_put()
2591 err = get_cur_ctl_value(cval, cval->control << 8, &oval); in mixer_ctl_selector_put()
2594 val = ucontrol->value.enumerated.item[0]; in mixer_ctl_selector_put()
2597 set_cur_ctl_value(cval, cval->control << 8, val); in mixer_ctl_selector_put()
2620 if (kctl->private_data) { in usb_mixer_selector_elem_free()
2621 struct usb_mixer_elem_info *cval = kctl->private_data; in usb_mixer_selector_elem_free()
2622 num_ins = cval->max; in usb_mixer_selector_elem_free()
2624 kctl->private_data = NULL; in usb_mixer_selector_elem_free()
2626 if (kctl->private_value) { in usb_mixer_selector_elem_free()
2627 char **itemlist = (char **)kctl->private_value; in usb_mixer_selector_elem_free()
2631 kctl->private_value = 0; in usb_mixer_selector_elem_free()
2649 for (i = 0; i < desc->bNrInPins; i++) { in parse_audio_selector_unit()
2650 err = parse_audio_unit(state, desc->baSourceID[i]); in parse_audio_selector_unit()
2655 if (desc->bNrInPins == 1) /* only one ? nonsense! */ in parse_audio_selector_unit()
2658 map = find_map(state->map, unitid, 0); in parse_audio_selector_unit()
2664 return -ENOMEM; in parse_audio_selector_unit()
2665 snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid); in parse_audio_selector_unit()
2666 cval->val_type = USB_MIXER_U8; in parse_audio_selector_unit()
2667 cval->channels = 1; in parse_audio_selector_unit()
2668 cval->min = 1; in parse_audio_selector_unit()
2669 cval->max = desc->bNrInPins; in parse_audio_selector_unit()
2670 cval->res = 1; in parse_audio_selector_unit()
2671 cval->initialized = 1; in parse_audio_selector_unit()
2673 switch (state->mixer->protocol) { in parse_audio_selector_unit()
2676 cval->control = 0; in parse_audio_selector_unit()
2680 if (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR || in parse_audio_selector_unit()
2681 desc->bDescriptorSubtype == UAC3_CLOCK_SELECTOR) in parse_audio_selector_unit()
2682 cval->control = UAC2_CX_CLOCK_SELECTOR; in parse_audio_selector_unit()
2684 cval->control = UAC2_SU_SELECTOR; in parse_audio_selector_unit()
2688 namelist = kcalloc(desc->bNrInPins, sizeof(char *), GFP_KERNEL); in parse_audio_selector_unit()
2690 err = -ENOMEM; in parse_audio_selector_unit()
2694 for (i = 0; i < desc->bNrInPins; i++) { in parse_audio_selector_unit()
2699 err = -ENOMEM; in parse_audio_selector_unit()
2704 if (! len && check_input_term(state, desc->baSourceID[i], &iterm) >= 0) in parse_audio_selector_unit()
2705 len = get_term_name(state->chip, &iterm, namelist[i], in parse_audio_selector_unit()
2713 usb_audio_err(state->chip, "cannot malloc kcontrol\n"); in parse_audio_selector_unit()
2714 err = -ENOMEM; in parse_audio_selector_unit()
2717 kctl->private_value = (unsigned long)namelist; in parse_audio_selector_unit()
2718 kctl->private_free = usb_mixer_selector_elem_free; in parse_audio_selector_unit()
2721 len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); in parse_audio_selector_unit()
2724 switch (state->mixer->protocol) { in parse_audio_selector_unit()
2731 len = snd_usb_copy_string_desc(state->chip, in parse_audio_selector_unit()
2732 nameid, kctl->id.name, in parse_audio_selector_unit()
2733 sizeof(kctl->id.name)); in parse_audio_selector_unit()
2736 /* TODO: Class-Specific strings not yet supported */ in parse_audio_selector_unit()
2742 len = get_term_name(state->chip, &state->oterm, in parse_audio_selector_unit()
2743 kctl->id.name, sizeof(kctl->id.name), 0); in parse_audio_selector_unit()
2746 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); in parse_audio_selector_unit()
2749 if (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR || in parse_audio_selector_unit()
2750 desc->bDescriptorSubtype == UAC3_CLOCK_SELECTOR) in parse_audio_selector_unit()
2752 else if ((state->oterm.type & 0xff00) == 0x0100) in parse_audio_selector_unit()
2758 usb_audio_dbg(state->chip, "[%d] SU [%s] items = %d\n", in parse_audio_selector_unit()
2759 cval->head.id, kctl->id.name, desc->bNrInPins); in parse_audio_selector_unit()
2760 return snd_usb_mixer_add_control(&cval->head, kctl); in parse_audio_selector_unit()
2763 for (i = 0; i < desc->bNrInPins; i++) in parse_audio_selector_unit()
2778 int protocol = state->mixer->protocol; in parse_audio_unit()
2780 if (test_and_set_bit(unitid, state->unitbitmap)) in parse_audio_unit()
2785 usb_audio_err(state->chip, "unit %d not found!\n", unitid); in parse_audio_unit()
2786 return -EINVAL; in parse_audio_unit()
2790 usb_audio_dbg(state->chip, "invalid unit %d\n", unitid); in parse_audio_unit()
2826 return 0; /* FIXME - effect units not implemented yet */ in parse_audio_unit()
2828 usb_audio_err(state->chip, in parse_audio_unit()
2831 return -EINVAL; in parse_audio_unit()
2840 kfree(mixer->id_elems); in snd_usb_mixer_free()
2841 if (mixer->urb) { in snd_usb_mixer_free()
2842 kfree(mixer->urb->transfer_buffer); in snd_usb_mixer_free()
2843 usb_free_urb(mixer->urb); in snd_usb_mixer_free()
2845 usb_free_urb(mixer->rc_urb); in snd_usb_mixer_free()
2846 kfree(mixer->rc_setup_packet); in snd_usb_mixer_free()
2852 struct usb_mixer_interface *mixer = device->device_data; in snd_usb_mixer_dev_free()
2875 .c_chmask = -1, /* dynamic channels */
2876 .p_chmask = -1, /* dynamic channels */
2888 .p_chmask = -1, /* dynamic channels */
2894 .c_chmask = -1, /* dynamic channels */
2905 .p_chmask = -1, /* dynamic channels */
2934 if (f->c_chmask < 0 && f->p_chmask < 0) { in uac3_badd_func_has_valid_channels()
2936 usb_audio_warn(mixer->chip, "BAAD %s: no channels?", in uac3_badd_func_has_valid_channels()
2937 f->name); in uac3_badd_func_has_valid_channels()
2943 if ((f->c_chmask < 0 && !c_chmask) || in uac3_badd_func_has_valid_channels()
2944 (f->c_chmask >= 0 && f->c_chmask != c_chmask)) { in uac3_badd_func_has_valid_channels()
2945 usb_audio_warn(mixer->chip, "BAAD %s c_chmask mismatch", in uac3_badd_func_has_valid_channels()
2946 f->name); in uac3_badd_func_has_valid_channels()
2949 if ((f->p_chmask < 0 && !p_chmask) || in uac3_badd_func_has_valid_channels()
2950 (f->p_chmask >= 0 && f->p_chmask != p_chmask)) { in uac3_badd_func_has_valid_channels()
2951 usb_audio_warn(mixer->chip, "BAAD %s p_chmask mismatch", in uac3_badd_func_has_valid_channels()
2952 f->name); in uac3_badd_func_has_valid_channels()
2968 struct usb_device *dev = mixer->chip->dev; in snd_usb_mixer_controls_badd()
2969 struct usb_interface_assoc_descriptor *assoc; in snd_usb_mixer_controls_badd() local
2970 int badd_profile = mixer->chip->badd_profile; in snd_usb_mixer_controls_badd()
2976 assoc = usb_ifnum_to_if(dev, ctrlif)->intf_assoc; in snd_usb_mixer_controls_badd()
2979 for (i = 0; i < assoc->bInterfaceCount; i++) { in snd_usb_mixer_controls_badd()
2980 int intf = assoc->bFirstInterface + i; in snd_usb_mixer_controls_badd()
2996 num = iface->num_altsetting; in snd_usb_mixer_controls_badd()
2999 return -EINVAL; in snd_usb_mixer_controls_badd()
3008 alts = &iface->altsetting[1]; in snd_usb_mixer_controls_badd()
3011 if (altsd->bNumEndpoints < 1) in snd_usb_mixer_controls_badd()
3012 return -EINVAL; in snd_usb_mixer_controls_badd()
3015 dir_in = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN); in snd_usb_mixer_controls_badd()
3016 maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); in snd_usb_mixer_controls_badd()
3020 usb_audio_err(mixer->chip, in snd_usb_mixer_controls_badd()
3023 return -EINVAL; in snd_usb_mixer_controls_badd()
3044 usb_audio_dbg(mixer->chip, in snd_usb_mixer_controls_badd()
3049 for (map = uac3_badd_usbmix_ctl_maps; map->id; map++) { in snd_usb_mixer_controls_badd()
3050 if (map->id == badd_profile) in snd_usb_mixer_controls_badd()
3054 if (!map->id) in snd_usb_mixer_controls_badd()
3055 return -EINVAL; in snd_usb_mixer_controls_badd()
3057 for (f = uac3_badd_profiles; f->name; f++) { in snd_usb_mixer_controls_badd()
3058 if (badd_profile == f->subclass) in snd_usb_mixer_controls_badd()
3061 if (!f->name) in snd_usb_mixer_controls_badd()
3062 return -EINVAL; in snd_usb_mixer_controls_badd()
3064 return -EINVAL; in snd_usb_mixer_controls_badd()
3065 st_chmask = f->st_chmask; in snd_usb_mixer_controls_badd()
3071 UAC3_BADD_FU_ID2, map->map); in snd_usb_mixer_controls_badd()
3074 UAC3_BADD_FU_ID2, map->map); in snd_usb_mixer_controls_badd()
3081 UAC3_BADD_FU_ID5, map->map); in snd_usb_mixer_controls_badd()
3084 UAC3_BADD_FU_ID5, map->map); in snd_usb_mixer_controls_badd()
3087 /* Side tone-mixing */ in snd_usb_mixer_controls_badd()
3091 UAC3_BADD_FU_ID7, map->map); in snd_usb_mixer_controls_badd()
3094 UAC3_BADD_FU_ID7, map->map); in snd_usb_mixer_controls_badd()
3098 if (f->subclass == UAC3_FUNCTION_SUBCLASS_HEADSET_ADAPTER) { in snd_usb_mixer_controls_badd()
3101 /* Input Term - Insertion control */ in snd_usb_mixer_controls_badd()
3105 build_connector_control(mixer, map->map, &iterm, true); in snd_usb_mixer_controls_badd()
3107 /* Output Term - Insertion control */ in snd_usb_mixer_controls_badd()
3111 build_connector_control(mixer, map->map, &oterm, false); in snd_usb_mixer_controls_badd()
3130 state.chip = mixer->chip; in snd_usb_mixer_controls()
3132 state.buffer = mixer->hostif->extra; in snd_usb_mixer_controls()
3133 state.buflen = mixer->hostif->extralen; in snd_usb_mixer_controls()
3136 for (map = usbmix_ctl_maps; map->id; map++) { in snd_usb_mixer_controls()
3137 if (map->id == state.chip->usb_id) { in snd_usb_mixer_controls()
3138 state.map = map->map; in snd_usb_mixer_controls()
3139 state.selector_map = map->selector_map; in snd_usb_mixer_controls()
3140 mixer->connector_map = map->connector_map; in snd_usb_mixer_controls()
3141 mixer->ignore_ctl_error |= map->ignore_ctl_error; in snd_usb_mixer_controls()
3147 while ((p = snd_usb_find_csint_desc(mixer->hostif->extra, in snd_usb_mixer_controls()
3148 mixer->hostif->extralen, in snd_usb_mixer_controls()
3150 if (!snd_usb_validate_audio_desc(p, mixer->protocol)) in snd_usb_mixer_controls()
3153 if (mixer->protocol == UAC_VERSION_1) { in snd_usb_mixer_controls()
3157 set_bit(desc->bTerminalID, state.unitbitmap); in snd_usb_mixer_controls()
3158 state.oterm.id = desc->bTerminalID; in snd_usb_mixer_controls()
3159 state.oterm.type = le16_to_cpu(desc->wTerminalType); in snd_usb_mixer_controls()
3160 state.oterm.name = desc->iTerminal; in snd_usb_mixer_controls()
3161 err = parse_audio_unit(&state, desc->bSourceID); in snd_usb_mixer_controls()
3162 if (err < 0 && err != -EINVAL) in snd_usb_mixer_controls()
3164 } else if (mixer->protocol == UAC_VERSION_2) { in snd_usb_mixer_controls()
3168 set_bit(desc->bTerminalID, state.unitbitmap); in snd_usb_mixer_controls()
3169 state.oterm.id = desc->bTerminalID; in snd_usb_mixer_controls()
3170 state.oterm.type = le16_to_cpu(desc->wTerminalType); in snd_usb_mixer_controls()
3171 state.oterm.name = desc->iTerminal; in snd_usb_mixer_controls()
3172 err = parse_audio_unit(&state, desc->bSourceID); in snd_usb_mixer_controls()
3173 if (err < 0 && err != -EINVAL) in snd_usb_mixer_controls()
3180 err = parse_audio_unit(&state, desc->bCSourceID); in snd_usb_mixer_controls()
3181 if (err < 0 && err != -EINVAL) in snd_usb_mixer_controls()
3185 uac_v2v3_control_is_readable(le16_to_cpu(desc->bmControls), in snd_usb_mixer_controls()
3194 set_bit(desc->bTerminalID, state.unitbitmap); in snd_usb_mixer_controls()
3195 state.oterm.id = desc->bTerminalID; in snd_usb_mixer_controls()
3196 state.oterm.type = le16_to_cpu(desc->wTerminalType); in snd_usb_mixer_controls()
3197 state.oterm.name = le16_to_cpu(desc->wTerminalDescrStr); in snd_usb_mixer_controls()
3198 err = parse_audio_unit(&state, desc->bSourceID); in snd_usb_mixer_controls()
3199 if (err < 0 && err != -EINVAL) in snd_usb_mixer_controls()
3206 err = parse_audio_unit(&state, desc->bCSourceID); in snd_usb_mixer_controls()
3207 if (err < 0 && err != -EINVAL) in snd_usb_mixer_controls()
3211 uac_v2v3_control_is_readable(le32_to_cpu(desc->bmControls), in snd_usb_mixer_controls()
3225 const struct usbmix_connector_map *map = mixer->connector_map; in delegate_notify()
3230 for (; map->id; map++) { in delegate_notify()
3231 if (map->id == unitid) { in delegate_notify()
3232 if (control && map->control) in delegate_notify()
3233 *control = map->control; in delegate_notify()
3234 if (channel && map->channel) in delegate_notify()
3235 *channel = map->channel; in delegate_notify()
3236 return map->delegated_id; in delegate_notify()
3251 if (!list->is_std_info) in snd_usb_mixer_notify_id()
3255 info->cached = 0; in snd_usb_mixer_notify_id()
3256 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, in snd_usb_mixer_notify_id()
3257 &list->kctl->id); in snd_usb_mixer_notify_id()
3268 "channels=%i, type=\"%s\"\n", cval->head.id, in snd_usb_mixer_dump_cval()
3269 cval->control, cval->cmask, cval->channels, in snd_usb_mixer_dump_cval()
3270 val_types[cval->val_type]); in snd_usb_mixer_dump_cval()
3272 cval->min, cval->max, cval->dBmin, cval->dBmax); in snd_usb_mixer_dump_cval()
3278 struct snd_usb_audio *chip = entry->private_data; in snd_usb_mixer_proc_read()
3283 list_for_each_entry(mixer, &chip->mixer_list, list) { in snd_usb_mixer_proc_read()
3286 chip->usb_id, mixer_ctrl_intf(mixer), in snd_usb_mixer_proc_read()
3287 mixer->ignore_ctl_error); in snd_usb_mixer_proc_read()
3288 snd_iprintf(buffer, "Card: %s\n", chip->card->longname); in snd_usb_mixer_proc_read()
3291 snd_iprintf(buffer, " Unit: %i\n", list->id); in snd_usb_mixer_proc_read()
3292 if (list->kctl) in snd_usb_mixer_proc_read()
3295 list->kctl->id.name, in snd_usb_mixer_proc_read()
3296 list->kctl->id.index); in snd_usb_mixer_proc_read()
3297 if (list->dump) in snd_usb_mixer_proc_read()
3298 list->dump(buffer, list); in snd_usb_mixer_proc_read()
3314 usb_audio_dbg(mixer->chip, in snd_usb_mixer_interrupt_v2()
3331 if (!list->kctl) in snd_usb_mixer_interrupt_v2()
3333 if (!list->is_std_info) in snd_usb_mixer_interrupt_v2()
3337 if (count > 1 && info->control != control) in snd_usb_mixer_interrupt_v2()
3344 info->cached &= ~(1 << channel); in snd_usb_mixer_interrupt_v2()
3346 info->cached = 0; in snd_usb_mixer_interrupt_v2()
3348 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, in snd_usb_mixer_interrupt_v2()
3349 &info->head.kctl->id); in snd_usb_mixer_interrupt_v2()
3361 usb_audio_dbg(mixer->chip, in snd_usb_mixer_interrupt_v2()
3371 struct usb_mixer_interface *mixer = urb->context; in snd_usb_mixer_interrupt()
3372 int len = urb->actual_length; in snd_usb_mixer_interrupt()
3373 int ustatus = urb->status; in snd_usb_mixer_interrupt()
3378 if (mixer->protocol == UAC_VERSION_1) { in snd_usb_mixer_interrupt()
3381 for (status = urb->transfer_buffer; in snd_usb_mixer_interrupt()
3383 len -= sizeof(*status), status++) { in snd_usb_mixer_interrupt()
3384 dev_dbg(&urb->dev->dev, "status interrupt: %02x %02x\n", in snd_usb_mixer_interrupt()
3385 status->bStatusType, in snd_usb_mixer_interrupt()
3386 status->bOriginator); in snd_usb_mixer_interrupt()
3389 if ((status->bStatusType & UAC1_STATUS_TYPE_ORIG_MASK) != in snd_usb_mixer_interrupt()
3393 if (status->bStatusType & UAC1_STATUS_TYPE_MEM_CHANGED) in snd_usb_mixer_interrupt()
3394 snd_usb_mixer_rc_memory_change(mixer, status->bOriginator); in snd_usb_mixer_interrupt()
3396 snd_usb_mixer_notify_id(mixer, status->bOriginator); in snd_usb_mixer_interrupt()
3401 for (msg = urb->transfer_buffer; in snd_usb_mixer_interrupt()
3403 len -= sizeof(*msg), msg++) { in snd_usb_mixer_interrupt()
3405 if ((msg->bInfo & UAC2_INTERRUPT_DATA_MSG_VENDOR) || in snd_usb_mixer_interrupt()
3406 (msg->bInfo & UAC2_INTERRUPT_DATA_MSG_EP)) in snd_usb_mixer_interrupt()
3409 snd_usb_mixer_interrupt_v2(mixer, msg->bAttribute, in snd_usb_mixer_interrupt()
3410 le16_to_cpu(msg->wValue), in snd_usb_mixer_interrupt()
3411 le16_to_cpu(msg->wIndex)); in snd_usb_mixer_interrupt()
3416 if (ustatus != -ENOENT && in snd_usb_mixer_interrupt()
3417 ustatus != -ECONNRESET && in snd_usb_mixer_interrupt()
3418 ustatus != -ESHUTDOWN) { in snd_usb_mixer_interrupt()
3419 urb->dev = mixer->chip->dev; in snd_usb_mixer_interrupt()
3433 if (get_iface_desc(mixer->hostif)->bNumEndpoints < 1) in snd_usb_mixer_status_create()
3435 ep = get_endpoint(mixer->hostif, 0); in snd_usb_mixer_status_create()
3440 buffer_length = le16_to_cpu(ep->wMaxPacketSize); in snd_usb_mixer_status_create()
3443 return -ENOMEM; in snd_usb_mixer_status_create()
3444 mixer->urb = usb_alloc_urb(0, GFP_KERNEL); in snd_usb_mixer_status_create()
3445 if (!mixer->urb) { in snd_usb_mixer_status_create()
3447 return -ENOMEM; in snd_usb_mixer_status_create()
3449 usb_fill_int_urb(mixer->urb, mixer->chip->dev, in snd_usb_mixer_status_create()
3450 usb_rcvintpipe(mixer->chip->dev, epnum), in snd_usb_mixer_status_create()
3452 snd_usb_mixer_interrupt, mixer, ep->bInterval); in snd_usb_mixer_status_create()
3453 usb_submit_urb(mixer->urb, GFP_KERNEL); in snd_usb_mixer_status_create()
3462 ucontrol->value.integer.value[0] = mixer->chip->keep_iface; in keep_iface_ctl_get()
3470 bool keep_iface = !!ucontrol->value.integer.value[0]; in keep_iface_ctl_put()
3472 if (mixer->chip->keep_iface == keep_iface) in keep_iface_ctl_put()
3474 mixer->chip->keep_iface = keep_iface; in keep_iface_ctl_put()
3491 if (snd_ctl_find_id(mixer->chip->card, &kctl->id)) { in create_keep_iface_ctl()
3496 return snd_ctl_add(mixer->chip->card, kctl); in create_keep_iface_ctl()
3508 strcpy(chip->card->mixername, "USB Mixer"); in snd_usb_create_mixer()
3512 return -ENOMEM; in snd_usb_create_mixer()
3513 mixer->chip = chip; in snd_usb_create_mixer()
3514 mixer->ignore_ctl_error = ignore_error; in snd_usb_create_mixer()
3515 mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems), in snd_usb_create_mixer()
3517 if (!mixer->id_elems) { in snd_usb_create_mixer()
3519 return -ENOMEM; in snd_usb_create_mixer()
3522 mixer->hostif = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0]; in snd_usb_create_mixer()
3523 switch (get_iface_desc(mixer->hostif)->bInterfaceProtocol) { in snd_usb_create_mixer()
3526 mixer->protocol = UAC_VERSION_1; in snd_usb_create_mixer()
3529 mixer->protocol = UAC_VERSION_2; in snd_usb_create_mixer()
3532 mixer->protocol = UAC_VERSION_3; in snd_usb_create_mixer()
3536 if (mixer->protocol == UAC_VERSION_3 && in snd_usb_create_mixer()
3537 chip->badd_profile >= UAC3_FUNCTION_SUBCLASS_GENERIC_IO) { in snd_usb_create_mixer()
3559 err = snd_device_new(chip->card, SNDRV_DEV_CODEC, mixer, &dev_ops); in snd_usb_create_mixer()
3563 if (list_empty(&chip->mixer_list)) in snd_usb_create_mixer()
3564 snd_card_ro_proc_new(chip->card, "usbmixer", chip, in snd_usb_create_mixer()
3567 list_add(&mixer->list, &chip->mixer_list); in snd_usb_create_mixer()
3577 if (mixer->disconnected) in snd_usb_mixer_disconnect()
3579 if (mixer->urb) in snd_usb_mixer_disconnect()
3580 usb_kill_urb(mixer->urb); in snd_usb_mixer_disconnect()
3581 if (mixer->rc_urb) in snd_usb_mixer_disconnect()
3582 usb_kill_urb(mixer->rc_urb); in snd_usb_mixer_disconnect()
3583 if (mixer->private_free) in snd_usb_mixer_disconnect()
3584 mixer->private_free(mixer); in snd_usb_mixer_disconnect()
3585 mixer->disconnected = true; in snd_usb_mixer_disconnect()
3592 usb_kill_urb(mixer->urb); in snd_usb_mixer_inactivate()
3593 usb_kill_urb(mixer->rc_urb); in snd_usb_mixer_inactivate()
3600 if (mixer->urb) { in snd_usb_mixer_activate()
3601 err = usb_submit_urb(mixer->urb, GFP_NOIO); in snd_usb_mixer_activate()
3612 if (mixer->private_suspend) in snd_usb_mixer_suspend()
3613 mixer->private_suspend(mixer); in snd_usb_mixer_suspend()
3622 if (cval->cmask) { in restore_mixer_value()
3625 if (!(cval->cmask & (1 << c))) in restore_mixer_value()
3627 if (cval->cached & (1 << (c + 1))) { in restore_mixer_value()
3629 cval->cache_val[idx]); in restore_mixer_value()
3637 if (cval->cached) { in restore_mixer_value()
3638 err = snd_usb_set_cur_mix_value(cval, 0, 0, *cval->cache_val); in restore_mixer_value()
3656 if (list->resume) { in snd_usb_mixer_resume()
3657 err = list->resume(list); in snd_usb_mixer_resume()
3675 list->mixer = mixer; in snd_usb_mixer_elem_init_std()
3676 list->id = unitid; in snd_usb_mixer_elem_init_std()
3677 list->dump = snd_usb_mixer_dump_cval; in snd_usb_mixer_elem_init_std()
3679 list->resume = restore_mixer_value; in snd_usb_mixer_elem_init_std()