Skip to contentSkip to conversation

ALSA: usb: UAC3. Add support for Basic Audio Device (BADD)

PATCH In review Jorge Sanjuan 3 participants 10 messages Nov 29, 2017 – Dec 13, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ALSA: usb: UAC3. Add support for Basic Audio Device (BADD)

This adds functionality for the Basic Audio Device (BADD) subset that is defined in the USB Audio Class 3 (UAC3). The new class requires the device to have 3 usb configurations as follows:

1: Legacy Mode: UAC1 or UAC2.
2: BADD device with a prefined topology. (Minimum). 3: UAC3 device for more detailed description or more complex
devices that can't be covered by the BADD profile.

This patch series also includes some minor fixes to the usb card driver.

Also, this has been implemented on top of the the patch which adds UAC3 support to the usb sound card driver:

	commit ddd452d7b04b86fb5f9285a19ac54deca9264ac1
	Author: Ruslan Bilovol <[email protected]>
	Date:   Tue Nov 7 04:01:20 2017 +0200

Jorge Sanjuan (6):
ALSA: usb: ADC3: Add initial BADD spec support
ALSA: usb: ADC3. BADD specification: fixed 48KHz sample rate.
ALSA: usb: ADC3. Do not set sample rate for BADD configuration.
usb: audio: Fix variable length field to be variable.
ALSA: usb: Use Class Specific EP for UAC3 devices.
ALSA: usb: Only get control header for UAC1 class.

 include/linux/usb/audio-v3.h |   2 +-
 sound/usb/Makefile           |   3 +-
 sound/usb/badd.c             | 495 +++++++++++++++++++++++++++++++++++++++++++
 sound/usb/badd.h             |  30 +++
 sound/usb/card.c             |  22 +-
 sound/usb/clock.c            |   6 +-
 sound/usb/format.c           |   7 +-
 sound/usb/stream.c           | 175 +++++++++------
 sound/usb/usbaudio.h         |   1 +
 9 files changed, 670 insertions(+), 71 deletions(-)
 create mode 100644 sound/usb/badd.c
 create mode 100644 sound/usb/badd.h
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/6 ALSA: usb: ADC3: Add initial BADD spec support

The Basic Audio Device 3 (BADD) spec requires the host to have "inferred" descriptors when a BADD profile ID is specified. This descriptor generator creates a buffer with known descriptors for each profile that can be then read to create the alsa audio device(s). The UAC3 compliant devices should have one configuration that is BADD compliant.

The USB request from host are bypassed and these buffers are read instead.

This patch series covers (for now) the following topologies:

- HEADPHONE.
- HEADSET.

For more information refer to the spec at:

http://www.usb.org/developers/docs/devclass_docs/

---
 sound/usb/Makefile   |   3 +-
 sound/usb/badd.c     | 495 +++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/usb/badd.h     |  30 ++++
 sound/usb/card.c     |   3 +
 sound/usb/stream.c   | 158 ++++++++++------
 sound/usb/usbaudio.h |   1 +
 6 files changed, 632 insertions(+), 58 deletions(-)
 create mode 100644 sound/usb/badd.c
 create mode 100644 sound/usb/badd.h
sound/usb/Makefile +2 -1
index 42cb33b94f6a..b4b54947a276 100644
@@ -2,7 +2,8 @@
 # Makefile for ALSA
 #
 
-snd-usb-audio-objs := 	card.o \
+snd-usb-audio-objs := 	badd.o \
+			card.o \
 			clock.o \
 			endpoint.o \
 			format.o \
sound/usb/badd.c new file +495 -0

495 lines not on this page · raw message

sound/usb/badd.h new file +30 -0
new file mode 100644
index 000000000000..de3d990bfbb8
@@ -0,0 +1,30 @@
+/*
+ *   USB: Audio Class 3: support for BASIC AUDIO DEVICE v.3
+ *
+ *   Author: Jorge Sanjuan <[email protected]>
+ *   Copyright (C) 2017 Codethink Ltd.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+#ifndef __USBAUDIO_BADD_H
+#define __USBAUDIO_BADD_H
+
+int badd_gen_csint_desc(void **buffer, int profile, unsigned int m_s);
+void * badd_gen_cluster_desc(unsigned int m_s);
+void * badd_get_as_iface(int stream_dir, int badd_cfg);
+void * badd_get_ep_dec(void);
+
+#endif /* __USBAUDIO_BADD_H */
+
sound/usb/card.c +3 -0
index 24cfb4bc5ed6..fa3cabd1cadc 100644
@@ -288,6 +288,9 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
 			return -EINVAL;
 		}
 
+		if (assoc->bFunctionSubClass > UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0)
+			chip->badd_profile = assoc->bFunctionSubClass;
+
 		for (i = 0; i < assoc->bInterfaceCount; i++) {
 			int intf = assoc->bFirstInterface + i;
 
sound/usb/stream.c +101 -57

220 lines not on this page · raw message

sound/usb/usbaudio.h +1 -0
index 4d5c89a7ba2b..276f5f93ad40 100644
@@ -61,6 +61,7 @@ struct snd_usb_audio {
 	bool autoclock;			/* from the 'autoclock' module param */
 
 	struct usb_host_interface *ctrl_intf;	/* the audio control interface */
+	unsigned int badd_profile;	/* BADD profile from bFunctionSubClass */
 };
 
 #define usb_audio_err(chip, fmt, args...) \
Signature · 1 line
2.11.0
#2 lore raw

Re: [Linux-kernel] [PATCH 1/6] ALSA: usb: ADC3: Add initial BADD spec support

Quoted 21 lines · Jorge Sanjuan

The Basic Audio Device 3 (BADD) spec requires the host to have "inferred" descriptors when a BADD profile ID is specified. This descriptor generator creates a buffer with known descriptors for each profile that can be then read to create the alsa audio device(s). The UAC3 compliant devices should have one configuration that is BADD compliant.

The USB request from host are bypassed and these buffers are read instead.

This patch series covers (for now) the following topologies:

 - HEADPHONE.
 - HEADSET.

For more information refer to the spec at:

 http://www.usb.org/developers/docs/devclass_docs/

---

[...]

sound/usb/badd.c line 7

Quoted 10 lines
sound/usb/badd.c new file +7 -0
@@ -0,0 +1,495 @@
+/*
+ *   USB: Audio Class 3: support for BASIC AUDIO DEVICE v.3
+ *
+ *   Author: Jorge Sanjuan <[email protected]>
+ *   Copyright (C) 2017 Codethink Ltd.
+ *
+ *   This program is free software; you can redistribute it and/or modify

Drop the GPL boilerplate and add an SPDX licence identifier instead (see commit b24413180f56).

[...]

sound/usb/badd.c line 137

Quoted 11 lines
sound/usb/badd.c new file +11 -0
+struct uac3_feature_unit_descriptor inf_feat_unit_id2 = {
+	.bLength = 0x0F, /* 0x13 if stereo */
+	.bDescriptorType = USB_DT_CS_INTERFACE,
+	.bDescriptorSubtype = UAC3_FEATURE_UNIT,
+
+	.bUnitID = 0x02,
+	/* bSourceID -> Profile dependent */
+	.bmaControls[0] = 0x03, /* Mute */
+	.bmaControls[1] = 0x0C, /* Chn1 Vol */
+	/* If stereo */
+	//.bmaControls[2] = 0x0C, /* Chn2 Vol */

Kernel style is to use only /* */ comments, not // comments.

[...]

sound/usb/badd.c line 235

Quoted 5 lines
sound/usb/badd.c new file +5 -0
+/**
+ * badd_gen_cluster_desc - This is to bypass the GET_HIGH_CAPABILITY
+ * UAC3 requests for getting cluster descriptors and, instead, generate
+ * the cluster on the host side as per BADD specification.
+ */

A kernel-doc comment mst have a one-line summary and then a description of each parameter. This function probably doesn't need that kind of documentation, so you could drop the extra * from the comment opener.

sound/usb/badd.c line 236

Quoted 1 line
sound/usb/badd.c new file +1 -0
+void * badd_gen_cluster_desc(unsigned int m_s)

No space after the *. Use checkpatch.pl to check for trivial style issues like this.

sound/usb/badd.c line 245

Quoted 9 lines
sound/usb/badd.c new file +9 -0
+{
+	struct uac3_cluster_header_descriptor cluster;
+	struct uac3_cluster_information_segment_descriptor segment;
+	struct uac3_cluster_end_segment_descriptor end;
+	void *buffer;
+	int pos = 0;
+	int length;
+
+	end.wLength = 0x03;

I think this needs to be a little-endian, in which case you need to use cpu_to_le16(0x03).

Similarly for all the other 16/32-bit fields in descriptors.

sound/usb/badd.c line 248

Quoted 3 lines
sound/usb/badd.c new file +3 -0
+	end.bSegmentType = UAC3_END_SEGMENT;
+
+	if (m_s == 0x01) { /* Mono */

Rather than commenting that this constant means Mono, you should name it with an enum or macro. (Or if the variable is actually a number of channels, then you should rename it.)

sound/usb/badd.c line 249

Quoted 1 line
sound/usb/badd.c new file +1 -0
+		length = 0x10;

Where does this number come from? Shouldn't it be written as sizeof(cluster) + sizeof(segment) + sizeof(end)?

[...]

sound/usb/badd.c line 319

Quoted 3 lines
sound/usb/badd.c new file +3 -0
+/**
+ * badd_gen_csint_desc - generates a buffer with the inferred
+ * descriptors that are predefined in the BADD specfication.

A kernel-doc summary has to be a single line. This is not just a recommendation, it's a hard constraint of the script.

There are a lot more magic numbers in here that ought to be replaced by either named constants or an expression using sizeof().

[...]

Quoted 14 lines
sound/usb/stream.c +1 -0
@@ -37,6 +37,7 @@
  #include "format.h"
  #include "clock.h"
  #include "stream.h"
+#include "badd.h"


 /*
  * free a substream

sound/usb/stream.c +0 -0
@@ -485,7 +486,11 @@ static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
  	struct usb_interface_descriptor *altsd = get_iface_desc(alts);
  	int attributes = 0;

sound/usb/stream.c static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip, · line 490

Quoted 3 lines
sound/usb/stream.c +2 -1
-	csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
+	if (protocol == UAC_VERSION_3 &&
+			chip->badd_profile > UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0)

This looks excessively indented.

Quoted 6 lines
sound/usb/stream.c +3 -0
+		csep = badd_get_ep_dec();
+	else
+		csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);


  /* Creamware Noah has this descriptor after the 2nd endpoint */ if (!csep && altsd->bNumEndpoints >= 2)

[...]

sound/usb/stream.c int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) · line 731

Quoted 13 lines
sound/usb/stream.c +3 -0
@@ -715,11 +723,33 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
  			struct uac3_as_header_descriptor *as;
  			struct uac3_cluster_header_descriptor *cluster;
  			struct uac3_hc_descriptor_header hc_header;
+			struct usb_host_interface *badd_ctrl_intf;
+			void *badd_extra;
+			int badd_extralen;
  			u16 cluster_id, wLength;

sound/usb/stream.c +1 -3
-			as = snd_usb_find_csint_desc(alts->extra,
-							alts->extralen,
-							NULL, UAC_AS_GENERAL);
+			badd_ctrl_intf = kzalloc(sizeof(*badd_ctrl_intf), GFP_KERNEL);

Missing an error check here.

Quoted 7 lines
sound/usb/stream.c +7 -0
+			memcpy(badd_ctrl_intf, chip->ctrl_intf, sizeof(*badd_ctrl_intf));
+
+			if (chip->badd_profile > UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0) {
+
+				as = badd_get_as_iface(stream, ep_packsize);
+
+				err = badd_gen_csint_desc(&badd_extra, chip->badd_profile, as->wClusterDescrID);

sound/usb/stream.c int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) · line 748

Quoted 10 lines
sound/usb/stream.c +10 -0
+				if (err <= 0 || !badd_extra) {
+					dev_err(&dev->dev,
+						"%u:%d : Cannot set BADD profile 0x%x. err=%d. badd_extra %p\n",
+						iface_no, altno, chip->badd_profile, err, badd_extra);
+					return err;
+				}
+
+				badd_extralen = err;
+				badd_ctrl_intf->extra = badd_extra;
+				badd_ctrl_intf->extralen = badd_extralen;

I don't think the badd_extra or badd_extralen variables are really needed here - they just seem to complicate this.

Quoted 106 lines
sound/usb/stream.c +4 -0
+			} else
+				as = snd_usb_find_csint_desc(alts->extra,
+								alts->extralen,
+								NULL, UAC_AS_GENERAL);


  if (!as) { dev_err(&dev->dev,

sound/usb/stream.c +0 -0
@@ -743,53 +773,64 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
  				continue;
  			}

sound/usb/stream.c +48 -47
-			/*
-			 * Get number of channels and channel map through
-			 * High Capability Cluster Descriptor
-			 *
-			 * First step: get High Capability header and
-			 * read size of Cluster Descriptor
-			 */
-			err = snd_usb_ctl_msg(chip->dev,
-					usb_rcvctrlpipe(chip->dev, 0),
-					UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
-					USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
-					cluster_id,
-					snd_usb_ctrl_intf(chip),
-					&hc_header, sizeof(hc_header));
-			if (err < 0)
-				return err;
-			else if (err != sizeof(hc_header)) {
-				dev_err(&dev->dev,
-					"%u:%d : can't get High Capability descriptor\n",
-					iface_no, altno);
-				return -EIO;
-			}
-
-			/*
-			 * Second step: allocate needed amount of memory
-			 * and request Cluster Descriptor
-			 */
-			wLength = le16_to_cpu(hc_header.wLength);
-			cluster = kzalloc(wLength, GFP_KERNEL);
-			if (!cluster)
-				return -ENOMEM;
-			err = snd_usb_ctl_msg(chip->dev,
-					usb_rcvctrlpipe(chip->dev, 0),
-					UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
-					USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
-					cluster_id,
-					snd_usb_ctrl_intf(chip),
-					cluster, wLength);
-			if (err < 0) {
-				kfree(cluster);
-				return err;
-			} else if (err != wLength) {
-				dev_err(&dev->dev,
-					"%u:%d : can't get Cluster Descriptor\n",
-					iface_no, altno);
-				kfree(cluster);
-				return -EIO;
+			if (chip->badd_profile > UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0) {
+
+				cluster = badd_gen_cluster_desc(cluster_id);
+				if (!cluster) {
+					dev_err(&dev->dev, 
+						"%u:%d : can't get Cluster Descriptor\n",
+						iface_no, altno);
+					return -ENOMEM;
+				}
+			} else {
+				/*
+				 * Get number of channels and channel map through
+				 * High Capability Cluster Descriptor
+				 *
+				 * First step: get High Capability header and
+				 * read size of Cluster Descriptor
+				 */
+				err = snd_usb_ctl_msg(chip->dev,
+						usb_rcvctrlpipe(chip->dev, 0),
+						UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
+						USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
+						cluster_id,
+						snd_usb_ctrl_intf(chip),
+						&hc_header, sizeof(hc_header));
+				if (err < 0)
+					return err;
+				else if (err != sizeof(hc_header)) {
+					dev_err(&dev->dev,
+						"%u:%d : can't get High Capability descriptor\n",
+						iface_no, altno);
+					return -EIO;
+				}
+
+				/*
+				 * Second step: allocate needed amount of memory
+				 * and request Cluster Descriptor
+				 */
+				wLength = le16_to_cpu(hc_header.wLength);
+				cluster = kzalloc(wLength, GFP_KERNEL);
+				if (!cluster)
+					return -ENOMEM;
+				err = snd_usb_ctl_msg(chip->dev,
+						usb_rcvctrlpipe(chip->dev, 0),
+						UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
+						USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
+						cluster_id,
+						snd_usb_ctrl_intf(chip),
+						cluster, wLength);

sound/usb/stream.c int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) · line 833

Quoted 10 lines
sound/usb/stream.c +10 -0
+				if (err < 0) {
+					kfree(cluster);
+					return err;
+				} else if (err != wLength) {
+					dev_err(&dev->dev,
+						"%u:%d : can't get Cluster Descriptor\n",
+						iface_no, altno);
+					kfree(cluster);
+					return -EIO;
+				}

This is a large block of code getting indented many levels deep. I can't help thinking that it also ought to be turned into a separate function.

All the error cases in this block will now leak badd_ctrl_inf, and it would be easier to avoid that if it's turned into a separate function.

Quoted 18 lines

  }

  num_channels = cluster->bNrChannels;

sound/usb/stream.c +0 -0
@@ -802,7 +843,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
  			/* lookup the terminal associated to this interface
  			 * to extract the clock */

  input_term = snd_usb_find_input_terminal_descriptor(

sound/usb/stream.c +1 -1
-							chip->ctrl_intf,
+							badd_ctrl_intf,

  as->bTerminalLink);
  if (input_term) {

sound/usb/stream.c +0 -0
@@ -810,7 +851,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
  				break;
  			}

sound/usb/stream.c +1 -1
-			output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
+			output_term = snd_usb_find_output_terminal_descriptor(badd_ctrl_intf,
Quoted 3 lines

        as->bTerminalLink); if (output_term) {
  clock = output_term->bCSourceID;

[...]

It looks like badd_ctrl_inf *always* gets leaked.

Ben.

Signature · 7 lines
Ben Hutchings
Software Developer, Codethink Ltd.

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#3 lore raw

PATCH 2/6 ALSA: usb: ADC3. BADD specification: fixed 48KHz sample rate.

In reply to Jorge Sanjuan

Make the frame rate range fixed to just 48KHz as the BADD specification stands for ADC3 devices.

For more details check section 4.2.4 of the Basic Audio Device version 3.

---
 sound/usb/format.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
sound/usb/format.c +6 -1
index 6f8589227e6a..e8669a1e996e 100644
@@ -445,7 +445,12 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
 	case UAC_VERSION_2:
 	case UAC_VERSION_3: {
 		/* fp->channels is already set in this case */
-		ret = parse_audio_format_rates_v2v3(chip, fp);
+		if (chip->badd_profile > UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0) {
+			fp->rate_min = fp->rate_max = 48000;
+			fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
+			return 0;
+		} else
+			ret = parse_audio_format_rates_v2v3(chip, fp);
 		break;
 	}
 	}
Signature · 1 line
2.11.0
#4 lore raw

PATCH 3/6 ALSA: usb: ADC3. Do not set sample rate for BADD configuration.

In reply to Jorge Sanjuan

BADD configuration is fixed to 48KHz for all AudioStreaming interfaces.

---
 sound/usb/clock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
sound/usb/clock.c +5 -1
index 04361d79b163..c7f4ca4cdcd4 100644
@@ -605,7 +605,11 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
 
 	case UAC_VERSION_2:
 	case UAC_VERSION_3:
-		return set_sample_rate_v2v3(chip, iface, alts, fmt, rate);
+		if (chip->badd_profile > UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0)
+			return 0;
+		else
+			return set_sample_rate_v2v3(chip, iface,
+						    alts, fmt, rate);
 	}
 }
 
Signature · 1 line
2.11.0
#5 lore raw

PATCH 4/6 usb: audio: Fix variable length field to be variable.

In reply to Jorge Sanjuan

Make bmaControls be a pointer insted of a fixed size array so it can have a variable length.

---
 include/linux/usb/audio-v3.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/usb/audio-v3.h +1 -1
index cbbe51e309dd..68f651e8d11a 100644
@@ -176,7 +176,7 @@ struct uac3_feature_unit_descriptor {
 	__u8 bSourceID;
 	/* bmaControls is actually u32,
 	 * but u8 is needed for the hybrid parser */
-	__u8 bmaControls[0]; /* variable length */
+	__u8 bmaControls[]; /* variable length */
 	/* wFeatureDescrStr omitted */
 } __attribute__((packed));
 
Signature · 1 line
2.11.0
#6 lore raw

Re: [PATCH 4/6] usb: audio: Fix variable length field to be variable.

include/linux/usb/audio-v3.h struct uac3_feature_unit_descriptor { · line 181

Quoted 9 lines · Jorge Sanjuan

Make bmaControls be a pointer insted of a fixed size array so it can have a variable length.

include/linux/usb/audio-v3.h +1 -1
 	/* bmaControls is actually u32,
 	 * but u8 is needed for the hybrid parser */
-	__u8 bmaControls[0]; /* variable length */
+	__u8 bmaControls[]; /* variable length */
 	/* wFeatureDescrStr omitted */
 } __attribute__((packed));

This is not a pointer but a flexible array member. And in theory, it does not change anything:
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

Regards,
Clemens

#7 lore raw

PATCH 5/6 ALSA: usb: Use Class Specific EP for UAC3 devices.

In reply to Jorge Sanjuan

bmAtributes offset doesn't exist in the UAC3 CS_EP descriptor. Hence, checking for pitch control as if it was UAC2 doesn't make any sense. Use the defined UAC3 offsets instead.

---
 sound/usb/stream.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
sound/usb/stream.c +15 -2
index 8b3565d4ca24..fbc7e056ee88 100644
@@ -512,9 +512,11 @@ static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
 		return 0;
 	}
 
-	if (protocol == UAC_VERSION_1) {
+	switch (protocol) {
+	case UAC_VERSION_1:
 		attributes = csep->bmAttributes;
-	} else {
+		break;
+	case UAC_VERSION_2: {
 		struct uac2_iso_endpoint_descriptor *csep2 =
 			(struct uac2_iso_endpoint_descriptor *) csep;
 
@@ -523,6 +525,17 @@ static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
 		/* emulate the endpoint attributes of a v1 device */
 		if (csep2->bmControls & UAC2_CONTROL_PITCH)
 			attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+		break;
+	}
+	case UAC_VERSION_3: {
+		struct uac3_iso_endpoint_descriptor *csep3 =
+			(struct uac3_iso_endpoint_descriptor *) csep;
+
+		/* emulate the endpoint attributes of a v1 device */
+		if (csep3->bmControls & UAC3_CONTROL_PITCH)
+			attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+		break;
+	}
 	}
 
 	return attributes;
Signature · 1 line
2.11.0
#8 lore raw

Re: [Linux-kernel] [PATCH 5/6] ALSA: usb: Use Class Specific EP for UAC3 devices.

sound/usb/stream.c static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,

Quoted 14 lines · Jorge Sanjuan

bmAtributes offset doesn't exist in the UAC3 CS_EP descriptor. Hence, checking for pitch control as if it was UAC2 doesn't make any sense. Use the defined UAC3 offsets instead.

---
 sound/usb/stream.c | 17 +++++++++++++++--

 1 file changed, 15 insertions(+), 2 deletions(-)
sound/usb/stream.c +0 -0
index 8b3565d4ca24..fbc7e056ee88 100644
@@ -512,9 +512,11 @@ static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,

The check for minimum length of the EP descriptor (just above this) should also be updated to be version-dependent.

The current check has a hardcoded minimum of 7, which I think will still cover all the fields being accessed - but that might change in future.

Ben.

Quoted 31 lines
sound/usb/stream.c +0 -0
  		return 0;
  	}

sound/usb/stream.c +2 -1
-	if (protocol == UAC_VERSION_1) {
+	switch (protocol) {
+	case UAC_VERSION_1:

  attributes = csep->bmAttributes;

sound/usb/stream.c +2 -1
-	} else {
+		break;
+	case UAC_VERSION_2: {

  struct uac2_iso_endpoint_descriptor *csep2 = (struct uac2_iso_endpoint_descriptor *) csep;

sound/usb/stream.c +11 -0
@@ -523,6 +525,17 @@ static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
  		/* emulate the endpoint attributes of a v1 device */
  		if (csep2->bmControls & UAC2_CONTROL_PITCH)
  			attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+		break;
+	}
+	case UAC_VERSION_3: {
+		struct uac3_iso_endpoint_descriptor *csep3 =
+			(struct uac3_iso_endpoint_descriptor *) csep;
+
+		/* emulate the endpoint attributes of a v1 device */
+		if (csep3->bmControls & UAC3_CONTROL_PITCH)
+			attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+		break;
+	}
  	}


  return attributes;

Signature · 7 lines
Ben Hutchings
Software Developer, Codethink Ltd.

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#9 lore raw

PATCH 6/6 ALSA: usb: Only get control header for UAC1 class.

In reply to Jorge Sanjuan

The control header needs to be read from buffer only in the case of UAC1 protocol.

---
 sound/usb/card.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
sound/usb/card.c +11 -8
index fa3cabd1cadc..646a0408f809 100644
@@ -226,16 +226,9 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
 
 	/* find audiocontrol interface */
 	host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
-	control_header = snd_usb_find_csint_desc(host_iface->extra,
-						 host_iface->extralen,
-						 NULL, UAC_HEADER);
 	altsd = get_iface_desc(host_iface);
 	protocol = altsd->bInterfaceProtocol;
 
-	if (!control_header) {
-		dev_err(&dev->dev, "cannot find UAC_HEADER\n");
-		return -EINVAL;
-	}
 
 	switch (protocol) {
 	default:
@@ -245,7 +238,17 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
 		/* fall through */
 
 	case UAC_VERSION_1: {
-		struct uac1_ac_header_descriptor *h1 = control_header;
+		struct uac1_ac_header_descriptor *h1;
+
+		control_header = snd_usb_find_csint_desc(host_iface->extra,
+							 host_iface->extralen,
+							 NULL, UAC_HEADER);
+		if (!control_header) {
+			dev_err(&dev->dev, "cannot find UAC_HEADER\n");
+			return -EINVAL;
+		}
+
+		h1 = control_header;
 
 		if (!h1->bInCollection) {
 			dev_info(&dev->dev, "skipping empty audio interface (v1)\n");
Signature · 1 line
2.11.0