Skip to content

Commit 6cfd839

Browse files
Jorge Sanjuantiwai
authored andcommitted
ALSA: usb-audio: UAC3. Add support for mixer unit.
This adds support for the MIXER UNIT in UAC3. All the information is obtained from the (HIGH CAPABILITY) Cluster's header. We don't read the rest of the logical cluster to obtain the channel config as that wont make any difference in the current mixer behaviour. The name of the mixer unit is not yet requested as there is not support for the UAC3 Class Specific String requests. Tested in an UAC3 device working as a HEADSET with a basic mixer unit (same as the one in the BADD spec) with no controls. Signed-off-by: Jorge Sanjuan <jorge.sanjuan@codethink.co.uk> Reviewed-by: Ruslan Bilovol <ruslan.bilovol@gmail.com> Tested-by: Ruslan Bilovol <ruslan.bilovol@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 8def12d commit 6cfd839

2 files changed

Lines changed: 97 additions & 10 deletions

File tree

‎include/uapi/linux/usb/audio.h‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,22 @@ static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor
285285
static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc,
286286
int protocol)
287287
{
288-
return (protocol == UAC_VERSION_1) ?
289-
&desc->baSourceID[desc->bNrInPins + 4] :
290-
&desc->baSourceID[desc->bNrInPins + 6];
288+
switch (protocol) {
289+
case UAC_VERSION_1:
290+
return &desc->baSourceID[desc->bNrInPins + 4];
291+
case UAC_VERSION_2:
292+
return &desc->baSourceID[desc->bNrInPins + 6];
293+
case UAC_VERSION_3:
294+
return &desc->baSourceID[desc->bNrInPins + 2];
295+
default:
296+
return NULL;
297+
}
298+
}
299+
300+
static inline __u16 uac3_mixer_unit_wClusterDescrID(struct uac_mixer_unit_descriptor *desc)
301+
{
302+
return (desc->baSourceID[desc->bNrInPins + 1] << 8) |
303+
desc->baSourceID[desc->bNrInPins];
291304
}
292305

293306
static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc)

‎sound/usb/mixer.c‎

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,66 @@ static int get_term_name(struct snd_usb_audio *chip, struct usb_audio_term *iter
716716
return 0;
717717
}
718718

719+
/*
720+
* Get logical cluster information for UAC3 devices.
721+
*/
722+
static int get_cluster_channels_v3(struct mixer_build *state, unsigned int cluster_id)
723+
{
724+
struct uac3_cluster_header_descriptor c_header;
725+
int err;
726+
727+
err = snd_usb_ctl_msg(state->chip->dev,
728+
usb_rcvctrlpipe(state->chip->dev, 0),
729+
UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
730+
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
731+
cluster_id,
732+
snd_usb_ctrl_intf(state->chip),
733+
&c_header, sizeof(c_header));
734+
if (err < 0)
735+
goto error;
736+
if (err != sizeof(c_header)) {
737+
err = -EIO;
738+
goto error;
739+
}
740+
741+
return c_header.bNrChannels;
742+
743+
error:
744+
usb_audio_err(state->chip, "cannot request logical cluster ID: %d (err: %d)\n", cluster_id, err);
745+
return err;
746+
}
747+
748+
/*
749+
* Get number of channels for a Mixer Unit.
750+
*/
751+
static int uac_mixer_unit_get_channels(struct mixer_build *state,
752+
struct uac_mixer_unit_descriptor *desc)
753+
{
754+
int mu_channels;
755+
756+
if (desc->bLength < 11)
757+
return -EINVAL;
758+
if (!desc->bNrInPins)
759+
return -EINVAL;
760+
761+
switch (state->mixer->protocol) {
762+
case UAC_VERSION_1:
763+
case UAC_VERSION_2:
764+
default:
765+
mu_channels = uac_mixer_unit_bNrChannels(desc);
766+
break;
767+
case UAC_VERSION_3:
768+
mu_channels = get_cluster_channels_v3(state,
769+
uac3_mixer_unit_wClusterDescrID(desc));
770+
break;
771+
}
772+
773+
if (!mu_channels)
774+
return -EINVAL;
775+
776+
return mu_channels;
777+
}
778+
719779
/*
720780
* parse the source unit recursively until it reaches to a terminal
721781
* or a branched unit.
@@ -863,6 +923,18 @@ static int check_input_term(struct mixer_build *state, int id,
863923
term->name = le16_to_cpu(d->wClockSourceStr);
864924
return 0;
865925
}
926+
case UAC3_MIXER_UNIT: {
927+
struct uac_mixer_unit_descriptor *d = p1;
928+
929+
err = uac_mixer_unit_get_channels(state, d);
930+
if (err < 0)
931+
return err;
932+
933+
term->channels = err;
934+
term->type = d->bDescriptorSubtype << 16; /* virtual type */
935+
936+
return 0;
937+
}
866938
default:
867939
return -ENODEV;
868940
}
@@ -1826,11 +1898,10 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
18261898
*/
18271899
static void build_mixer_unit_ctl(struct mixer_build *state,
18281900
struct uac_mixer_unit_descriptor *desc,
1829-
int in_pin, int in_ch, int unitid,
1830-
struct usb_audio_term *iterm)
1901+
int in_pin, int in_ch, int num_outs,
1902+
int unitid, struct usb_audio_term *iterm)
18311903
{
18321904
struct usb_mixer_elem_info *cval;
1833-
unsigned int num_outs = uac_mixer_unit_bNrChannels(desc);
18341905
unsigned int i, len;
18351906
struct snd_kcontrol *kctl;
18361907
const struct usbmix_name_map *map;
@@ -1907,14 +1978,17 @@ static int parse_audio_mixer_unit(struct mixer_build *state, int unitid,
19071978
int input_pins, num_ins, num_outs;
19081979
int pin, ich, err;
19091980

1910-
if (desc->bLength < 11 || !(input_pins = desc->bNrInPins) ||
1911-
!(num_outs = uac_mixer_unit_bNrChannels(desc))) {
1981+
err = uac_mixer_unit_get_channels(state, desc);
1982+
if (err < 0) {
19121983
usb_audio_err(state->chip,
19131984
"invalid MIXER UNIT descriptor %d\n",
19141985
unitid);
1915-
return -EINVAL;
1986+
return err;
19161987
}
19171988

1989+
num_outs = err;
1990+
input_pins = desc->bNrInPins;
1991+
19181992
num_ins = 0;
19191993
ich = 0;
19201994
for (pin = 0; pin < input_pins; pin++) {
@@ -1941,7 +2015,7 @@ static int parse_audio_mixer_unit(struct mixer_build *state, int unitid,
19412015
}
19422016
}
19432017
if (ich_has_controls)
1944-
build_mixer_unit_ctl(state, desc, pin, ich,
2018+
build_mixer_unit_ctl(state, desc, pin, ich, num_outs,
19452019
unitid, &iterm);
19462020
}
19472021
}

0 commit comments

Comments
 (0)