aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuslan Bilovol <ruslan.bilovol@gmail.com>2018-03-20 20:03:59 -0400
committerTakashi Iwai <tiwai@suse.de>2018-03-21 06:46:33 -0400
commit9a2fe9b801f585baccf8352d82839dcd54b300cf (patch)
tree333de5ebcac026ce1a18da1c693cb8e9603c9a54
parentceb18f511beeb8b750f027f170eb6d901a082e9a (diff)
ALSA: usb: initial USB Audio Device Class 3.0 support
Recently released USB Audio Class 3.0 specification introduces many significant changes comparing to previous versions, like - new Power Domains, support for LPM/L1 - new Cluster descriptor - changed layout of all class-specific descriptors - new High Capability descriptors - New class-specific String descriptors - new and removed units - additional sources for interrupts - removed Type II Audio Data Formats - ... and many other things (check spec) It also provides backward compatibility through multiple configurations, as well as requires mandatory support for BADD (Basic Audio Device Definition) on each ADC3.0 compliant device This patch adds initial support of UAC3 specification that is enough for Generic I/O Profile (BAOF, BAIF) device support from BADD document. Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--include/linux/usb/audio-v2.h4
-rw-r--r--include/linux/usb/audio-v3.h395
-rw-r--r--include/uapi/linux/usb/audio.h1
-rw-r--r--sound/usb/card.c7
-rw-r--r--sound/usb/card.h2
-rw-r--r--sound/usb/clock.c228
-rw-r--r--sound/usb/clock.h4
-rw-r--r--sound/usb/format.c91
-rw-r--r--sound/usb/format.h6
-rw-r--r--sound/usb/mixer.c337
-rw-r--r--sound/usb/stream.c365
11 files changed, 1246 insertions, 194 deletions
diff --git a/include/linux/usb/audio-v2.h b/include/linux/usb/audio-v2.h
index 3119d0ace7aa..2db83a191e78 100644
--- a/include/linux/usb/audio-v2.h
+++ b/include/linux/usb/audio-v2.h
@@ -34,12 +34,12 @@
34 * 34 *
35 */ 35 */
36 36
37static inline bool uac2_control_is_readable(u32 bmControls, u8 control) 37static inline bool uac_v2v3_control_is_readable(u32 bmControls, u8 control)
38{ 38{
39 return (bmControls >> (control * 2)) & 0x1; 39 return (bmControls >> (control * 2)) & 0x1;
40} 40}
41 41
42static inline bool uac2_control_is_writeable(u32 bmControls, u8 control) 42static inline bool uac_v2v3_control_is_writeable(u32 bmControls, u8 control)
43{ 43{
44 return (bmControls >> (control * 2)) & 0x2; 44 return (bmControls >> (control * 2)) & 0x2;
45} 45}
diff --git a/include/linux/usb/audio-v3.h b/include/linux/usb/audio-v3.h
new file mode 100644
index 000000000000..a8959aaba0ae
--- /dev/null
+++ b/include/linux/usb/audio-v3.h
@@ -0,0 +1,395 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2017 Ruslan Bilovol <ruslan.bilovol@gmail.com>
4 *
5 * This file holds USB constants and structures defined
6 * by the USB DEVICE CLASS DEFINITION FOR AUDIO DEVICES Release 3.0.
7 */
8
9#ifndef __LINUX_USB_AUDIO_V3_H
10#define __LINUX_USB_AUDIO_V3_H
11
12#include <linux/types.h>
13
14/*
15 * v1.0, v2.0 and v3.0 of this standard have many things in common. For the rest
16 * of the definitions, please refer to audio.h and audio-v2.h
17 */
18
19/* All High Capability descriptors have these 2 fields at the beginning */
20struct uac3_hc_descriptor_header {
21 __le16 wLength;
22 __u8 bDescriptorType;
23 __u8 bDescriptorSubtype;
24 __le16 wDescriptorID;
25} __attribute__ ((packed));
26
27/* 4.3.1 CLUSTER DESCRIPTOR HEADER */
28struct uac3_cluster_header_descriptor {
29 __le16 wLength;
30 __u8 bDescriptorType;
31 __u8 bDescriptorSubtype;
32 __le16 wDescriptorID;
33 __u8 bNrChannels;
34} __attribute__ ((packed));
35
36/* 4.3.2.1 SEGMENTS */
37struct uac3_cluster_segment_descriptor {
38 __le16 wLength;
39 __u8 bSegmentType;
40 /* __u8[0]; segment-specific data */
41} __attribute__ ((packed));
42
43/* 4.3.2.1.1 END SEGMENT */
44struct uac3_cluster_end_segment_descriptor {
45 __le16 wLength;
46 __u8 bSegmentType; /* Constant END_SEGMENT */
47} __attribute__ ((packed));
48
49/* 4.3.2.1.3.1 INFORMATION SEGMENT */
50struct uac3_cluster_information_segment_descriptor {
51 __le16 wLength;
52 __u8 bSegmentType;
53 __u8 bChPurpose;
54 __u8 bChRelationship;
55 __u8 bChGroupID;
56} __attribute__ ((packed));
57
58/* 4.5.2 CLASS-SPECIFIC AC INTERFACE DESCRIPTOR */
59struct uac3_ac_header_descriptor {
60 __u8 bLength; /* 10 */
61 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
62 __u8 bDescriptorSubtype; /* HEADER descriptor subtype */
63 __u8 bCategory;
64
65 /* includes Clock Source, Unit, Terminal, and Power Domain desc. */
66 __le16 wTotalLength;
67
68 __le32 bmControls;
69} __attribute__ ((packed));
70
71/* 4.5.2.1 INPUT TERMINAL DESCRIPTOR */
72struct uac3_input_terminal_descriptor {
73 __u8 bLength;
74 __u8 bDescriptorType;
75 __u8 bDescriptorSubtype;
76 __u8 bTerminalID;
77 __le16 wTerminalType;
78 __u8 bAssocTerminal;
79 __u8 bCSourceID;
80 __le32 bmControls;
81 __le16 wClusterDescrID;
82 __le16 wExTerminalDescrID;
83 __le16 wConnectorsDescrID;
84 __le16 wTerminalDescrStr;
85} __attribute__((packed));
86
87/* 4.5.2.2 OUTPUT TERMINAL DESCRIPTOR */
88struct uac3_output_terminal_descriptor {
89 __u8 bLength;
90 __u8 bDescriptorType;
91 __u8 bDescriptorSubtype;
92 __u8 bTerminalID;
93 __le16 wTerminalType;
94 __u8 bAssocTerminal;
95 __u8 bSourceID;
96 __u8 bCSourceID;
97 __le32 bmControls;
98 __le16 wExTerminalDescrID;
99 __le16 wConnectorsDescrID;
100 __le16 wTerminalDescrStr;
101} __attribute__((packed));
102
103/* 4.5.2.7 FEATURE UNIT DESCRIPTOR */
104struct uac3_feature_unit_descriptor {
105 __u8 bLength;
106 __u8 bDescriptorType;
107 __u8 bDescriptorSubtype;
108 __u8 bUnitID;
109 __u8 bSourceID;
110 /* bmaControls is actually u32,
111 * but u8 is needed for the hybrid parser */
112 __u8 bmaControls[0]; /* variable length */
113 /* wFeatureDescrStr omitted */
114} __attribute__((packed));
115
116#define UAC3_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 4)
117
118/* As above, but more useful for defining your own descriptors */
119#define DECLARE_UAC3_FEATURE_UNIT_DESCRIPTOR(ch) \
120struct uac3_feature_unit_descriptor_##ch { \
121 __u8 bLength; \
122 __u8 bDescriptorType; \
123 __u8 bDescriptorSubtype; \
124 __u8 bUnitID; \
125 __u8 bSourceID; \
126 __le32 bmaControls[ch + 1]; \
127 __le16 wFeatureDescrStr; \
128} __attribute__ ((packed))
129
130/* 4.5.2.12 CLOCK SOURCE DESCRIPTOR */
131struct uac3_clock_source_descriptor {
132 __u8 bLength;
133 __u8 bDescriptorType;
134 __u8 bDescriptorSubtype;
135 __u8 bClockID;
136 __u8 bmAttributes;
137 __le32 bmControls;
138 __u8 bReferenceTerminal;
139 __le16 wClockSourceStr;
140} __attribute__((packed));
141
142/* bmAttribute fields */
143#define UAC3_CLOCK_SOURCE_TYPE_EXT 0x0
144#define UAC3_CLOCK_SOURCE_TYPE_INT 0x1
145#define UAC3_CLOCK_SOURCE_ASYNC (0 << 2)
146#define UAC3_CLOCK_SOURCE_SYNCED_TO_SOF (1 << 1)
147
148/* 4.5.2.13 CLOCK SELECTOR DESCRIPTOR */
149struct uac3_clock_selector_descriptor {
150 __u8 bLength;
151 __u8 bDescriptorType;
152 __u8 bDescriptorSubtype;
153 __u8 bClockID;
154 __u8 bNrInPins;
155 __u8 baCSourceID[];
156 /* bmControls and wCSelectorDescrStr omitted */
157} __attribute__((packed));
158
159/* 4.5.2.14 CLOCK MULTIPLIER DESCRIPTOR */
160struct uac3_clock_multiplier_descriptor {
161 __u8 bLength;
162 __u8 bDescriptorType;
163 __u8 bDescriptorSubtype;
164 __u8 bClockID;
165 __u8 bCSourceID;
166 __le32 bmControls;
167 __le16 wCMultiplierDescrStr;
168} __attribute__((packed));
169
170/* 4.5.2.15 POWER DOMAIN DESCRIPTOR */
171struct uac3_power_domain_descriptor {
172 __u8 bLength;
173 __u8 bDescriptorType;
174 __u8 bDescriptorSubtype;
175 __u8 bPowerDomainID;
176 __le16 waRecoveryTime1;
177 __le16 waRecoveryTime2;
178 __u8 bNrEntities;
179 __u8 baEntityID[];
180 /* wPDomainDescrStr omitted */
181} __attribute__((packed));
182
183/* As above, but more useful for defining your own descriptors */
184#define DECLARE_UAC3_POWER_DOMAIN_DESCRIPTOR(n) \
185struct uac3_power_domain_descriptor_##n { \
186 __u8 bLength; \
187 __u8 bDescriptorType; \
188 __u8 bDescriptorSubtype; \
189 __u8 bPowerDomainID; \
190 __le16 waRecoveryTime1; \
191 __le16 waRecoveryTime2; \
192 __u8 bNrEntities; \
193 __u8 baEntityID[n]; \
194 __le16 wPDomainDescrStr; \
195} __attribute__ ((packed))
196
197/* 4.7.2 CLASS-SPECIFIC AS INTERFACE DESCRIPTOR */
198struct uac3_as_header_descriptor {
199 __u8 bLength;
200 __u8 bDescriptorType;
201 __u8 bDescriptorSubtype;
202 __u8 bTerminalLink;
203 __le32 bmControls;
204 __le16 wClusterDescrID;
205 __le64 bmFormats;
206 __u8 bSubslotSize;
207 __u8 bBitResolution;
208 __le16 bmAuxProtocols;
209 __u8 bControlSize;
210} __attribute__((packed));
211
212#define UAC3_FORMAT_TYPE_I_RAW_DATA (1 << 6)
213
214/* 4.8.1.2 CLASS-SPECIFIC AS ISOCHRONOUS AUDIO DATA ENDPOINT DESCRIPTOR */
215struct uac3_iso_endpoint_descriptor {
216 __u8 bLength;
217 __u8 bDescriptorType;
218 __u8 bDescriptorSubtype;
219 __le32 bmControls;
220 __u8 bLockDelayUnits;
221 __le16 wLockDelay;
222} __attribute__((packed));
223
224/* 6.1 INTERRUPT DATA MESSAGE */
225struct uac3_interrupt_data_msg {
226 __u8 bInfo;
227 __u8 bSourceType;
228 __le16 wValue;
229 __le16 wIndex;
230} __attribute__((packed));
231
232/* A.2 AUDIO AUDIO FUNCTION SUBCLASS CODES */
233#define UAC3_FUNCTION_SUBCLASS_UNDEFINED 0x00
234#define UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0 0x01
235/* BADD profiles */
236#define UAC3_FUNCTION_SUBCLASS_GENERIC_IO 0x20
237#define UAC3_FUNCTION_SUBCLASS_HEADPHONE 0x21
238#define UAC3_FUNCTION_SUBCLASS_SPEAKER 0x22
239#define UAC3_FUNCTION_SUBCLASS_MICROPHONE 0x23
240#define UAC3_FUNCTION_SUBCLASS_HEADSET 0x24
241#define UAC3_FUNCTION_SUBCLASS_HEADSET_ADAPTER 0x25
242#define UAC3_FUNCTION_SUBCLASS_SPEAKERPHONE 0x26
243
244/* A.7 AUDIO FUNCTION CATEGORY CODES */
245#define UAC3_FUNCTION_SUBCLASS_UNDEFINED 0x00
246#define UAC3_FUNCTION_DESKTOP_SPEAKER 0x01
247#define UAC3_FUNCTION_HOME_THEATER 0x02
248#define UAC3_FUNCTION_MICROPHONE 0x03
249#define UAC3_FUNCTION_HEADSET 0x04
250#define UAC3_FUNCTION_TELEPHONE 0x05
251#define UAC3_FUNCTION_CONVERTER 0x06
252#define UAC3_FUNCTION_SOUND_RECORDER 0x07
253#define UAC3_FUNCTION_IO_BOX 0x08
254#define UAC3_FUNCTION_MUSICAL_INSTRUMENT 0x09
255#define UAC3_FUNCTION_PRO_AUDIO 0x0a
256#define UAC3_FUNCTION_AUDIO_VIDEO 0x0b
257#define UAC3_FUNCTION_CONTROL_PANEL 0x0c
258#define UAC3_FUNCTION_HEADPHONE 0x0d
259#define UAC3_FUNCTION_GENERIC_SPEAKER 0x0e
260#define UAC3_FUNCTION_HEADSET_ADAPTER 0x0f
261#define UAC3_FUNCTION_SPEAKERPHONE 0x10
262#define UAC3_FUNCTION_OTHER 0xff
263
264/* A.8 AUDIO CLASS-SPECIFIC DESCRIPTOR TYPES */
265#define UAC3_CS_UNDEFINED 0x20
266#define UAC3_CS_DEVICE 0x21
267#define UAC3_CS_CONFIGURATION 0x22
268#define UAC3_CS_STRING 0x23
269#define UAC3_CS_INTERFACE 0x24
270#define UAC3_CS_ENDPOINT 0x25
271#define UAC3_CS_CLUSTER 0x26
272
273/* A.10 CLUSTER DESCRIPTOR SEGMENT TYPES */
274#define UAC3_SEGMENT_UNDEFINED 0x00
275#define UAC3_CLUSTER_DESCRIPTION 0x01
276#define UAC3_CLUSTER_VENDOR_DEFINED 0x1F
277#define UAC3_CHANNEL_INFORMATION 0x20
278#define UAC3_CHANNEL_AMBISONIC 0x21
279#define UAC3_CHANNEL_DESCRIPTION 0x22
280#define UAC3_CHANNEL_VENDOR_DEFINED 0xFE
281#define UAC3_END_SEGMENT 0xFF
282
283/* A.11 CHANNEL PURPOSE DEFINITIONS */
284#define UAC3_PURPOSE_UNDEFINED 0x00
285#define UAC3_PURPOSE_GENERIC_AUDIO 0x01
286#define UAC3_PURPOSE_VOICE 0x02
287#define UAC3_PURPOSE_SPEECH 0x03
288#define UAC3_PURPOSE_AMBIENT 0x04
289#define UAC3_PURPOSE_REFERENCE 0x05
290#define UAC3_PURPOSE_ULTRASONIC 0x06
291#define UAC3_PURPOSE_VIBROKINETIC 0x07
292#define UAC3_PURPOSE_NON_AUDIO 0xFF
293
294/* A.12 CHANNEL RELATIONSHIP DEFINITIONS */
295#define UAC3_CH_RELATIONSHIP_UNDEFINED 0x00
296#define UAC3_CH_MONO 0x01
297#define UAC3_CH_LEFT 0x02
298#define UAC3_CH_RIGHT 0x03
299#define UAC3_CH_ARRAY 0x04
300#define UAC3_CH_PATTERN_X 0x20
301#define UAC3_CH_PATTERN_Y 0x21
302#define UAC3_CH_PATTERN_A 0x22
303#define UAC3_CH_PATTERN_B 0x23
304#define UAC3_CH_PATTERN_M 0x24
305#define UAC3_CH_PATTERN_S 0x25
306#define UAC3_CH_FRONT_LEFT 0x80
307#define UAC3_CH_FRONT_RIGHT 0x81
308#define UAC3_CH_FRONT_CENTER 0x82
309#define UAC3_CH_FRONT_LEFT_OF_CENTER 0x83
310#define UAC3_CH_FRONT_RIGHT_OF_CENTER 0x84
311#define UAC3_CH_FRONT_WIDE_LEFT 0x85
312#define UAC3_CH_FRONT_WIDE_RIGHT 0x86
313#define UAC3_CH_SIDE_LEFT 0x87
314#define UAC3_CH_SIDE_RIGHT 0x88
315#define UAC3_CH_SURROUND_ARRAY_LEFT 0x89
316#define UAC3_CH_SURROUND_ARRAY_RIGHT 0x8A
317#define UAC3_CH_BACK_LEFT 0x8B
318#define UAC3_CH_BACK_RIGHT 0x8C
319#define UAC3_CH_BACK_CENTER 0x8D
320#define UAC3_CH_BACK_LEFT_OF_CENTER 0x8E
321#define UAC3_CH_BACK_RIGHT_OF_CENTER 0x8F
322#define UAC3_CH_BACK_WIDE_LEFT 0x90
323#define UAC3_CH_BACK_WIDE_RIGHT 0x91
324#define UAC3_CH_TOP_CENTER 0x92
325#define UAC3_CH_TOP_FRONT_LEFT 0x93
326#define UAC3_CH_TOP_FRONT_RIGHT 0x94
327#define UAC3_CH_TOP_FRONT_CENTER 0x95
328#define UAC3_CH_TOP_FRONT_LOC 0x96
329#define UAC3_CH_TOP_FRONT_ROC 0x97
330#define UAC3_CH_TOP_FRONT_WIDE_LEFT 0x98
331#define UAC3_CH_TOP_FRONT_WIDE_RIGHT 0x99
332#define UAC3_CH_TOP_SIDE_LEFT 0x9A
333#define UAC3_CH_TOP_SIDE_RIGHT 0x9B
334#define UAC3_CH_TOP_SURR_ARRAY_LEFT 0x9C
335#define UAC3_CH_TOP_SURR_ARRAY_RIGHT 0x9D
336#define UAC3_CH_TOP_BACK_LEFT 0x9E
337#define UAC3_CH_TOP_BACK_RIGHT 0x9F
338#define UAC3_CH_TOP_BACK_CENTER 0xA0
339#define UAC3_CH_TOP_BACK_LOC 0xA1
340#define UAC3_CH_TOP_BACK_ROC 0xA2
341#define UAC3_CH_TOP_BACK_WIDE_LEFT 0xA3
342#define UAC3_CH_TOP_BACK_WIDE_RIGHT 0xA4
343#define UAC3_CH_BOTTOM_CENTER 0xA5
344#define UAC3_CH_BOTTOM_FRONT_LEFT 0xA6
345#define UAC3_CH_BOTTOM_FRONT_RIGHT 0xA7
346#define UAC3_CH_BOTTOM_FRONT_CENTER 0xA8
347#define UAC3_CH_BOTTOM_FRONT_LOC 0xA9
348#define UAC3_CH_BOTTOM_FRONT_ROC 0xAA
349#define UAC3_CH_BOTTOM_FRONT_WIDE_LEFT 0xAB
350#define UAC3_CH_BOTTOM_FRONT_WIDE_RIGHT 0xAC
351#define UAC3_CH_BOTTOM_SIDE_LEFT 0xAD
352#define UAC3_CH_BOTTOM_SIDE_RIGHT 0xAE
353#define UAC3_CH_BOTTOM_SURR_ARRAY_LEFT 0xAF
354#define UAC3_CH_BOTTOM_SURR_ARRAY_RIGHT 0xB0
355#define UAC3_CH_BOTTOM_BACK_LEFT 0xB1
356#define UAC3_CH_BOTTOM_BACK_RIGHT 0xB2
357#define UAC3_CH_BOTTOM_BACK_CENTER 0xB3
358#define UAC3_CH_BOTTOM_BACK_LOC 0xB4
359#define UAC3_CH_BOTTOM_BACK_ROC 0xB5
360#define UAC3_CH_BOTTOM_BACK_WIDE_LEFT 0xB6
361#define UAC3_CH_BOTTOM_BACK_WIDE_RIGHT 0xB7
362#define UAC3_CH_LOW_FREQUENCY_EFFECTS 0xB8
363#define UAC3_CH_LFE_LEFT 0xB9
364#define UAC3_CH_LFE_RIGHT 0xBA
365#define UAC3_CH_HEADPHONE_LEFT 0xBB
366#define UAC3_CH_HEADPHONE_RIGHT 0xBC
367
368/* A.15 AUDIO CLASS-SPECIFIC AC INTERFACE DESCRIPTOR SUBTYPES */
369/* see audio.h for the rest, which is identical to v1 */
370#define UAC3_EXTENDED_TERMINAL 0x04
371#define UAC3_MIXER_UNIT 0x05
372#define UAC3_SELECTOR_UNIT 0x06
373#define UAC3_FEATURE_UNIT 0x07
374#define UAC3_EFFECT_UNIT 0x08
375#define UAC3_PROCESSING_UNIT 0x09
376#define UAC3_EXTENSION_UNIT 0x0a
377#define UAC3_CLOCK_SOURCE 0x0b
378#define UAC3_CLOCK_SELECTOR 0x0c
379#define UAC3_CLOCK_MULTIPLIER 0x0d
380#define UAC3_SAMPLE_RATE_CONVERTER 0x0e
381#define UAC3_CONNECTORS 0x0f
382#define UAC3_POWER_DOMAIN 0x10
383
384/* A.22 AUDIO CLASS-SPECIFIC REQUEST CODES */
385/* see audio-v2.h for the rest, which is identical to v2 */
386#define UAC3_CS_REQ_INTEN 0x04
387#define UAC3_CS_REQ_STRING 0x05
388#define UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR 0x06
389
390/* A.23.1 AUDIOCONTROL INTERFACE CONTROL SELECTORS */
391#define UAC3_AC_CONTROL_UNDEFINED 0x00
392#define UAC3_AC_ACTIVE_INTERFACE_CONTROL 0x01
393#define UAC3_AC_POWER_DOMAIN_CONTROL 0x02
394
395#endif /* __LINUX_USB_AUDIO_V3_H */
diff --git a/include/uapi/linux/usb/audio.h b/include/uapi/linux/usb/audio.h
index da3315ed1bcd..3a78e7145689 100644
--- a/include/uapi/linux/usb/audio.h
+++ b/include/uapi/linux/usb/audio.h
@@ -27,6 +27,7 @@
27/* bInterfaceProtocol values to denote the version of the standard used */ 27/* bInterfaceProtocol values to denote the version of the standard used */
28#define UAC_VERSION_1 0x00 28#define UAC_VERSION_1 0x00
29#define UAC_VERSION_2 0x20 29#define UAC_VERSION_2 0x20
30#define UAC_VERSION_3 0x30
30 31
31/* A.2 Audio Interface Subclass Codes */ 32/* A.2 Audio Interface Subclass Codes */
32#define USB_SUBCLASS_AUDIOCONTROL 0x01 33#define USB_SUBCLASS_AUDIOCONTROL 0x01
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 8018d56cfecc..4a1c6bb3dfa0 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -7,6 +7,7 @@
7 * Alan Cox (alan@lxorguk.ukuu.org.uk) 7 * Alan Cox (alan@lxorguk.ukuu.org.uk)
8 * Thomas Sailer (sailer@ife.ee.ethz.ch) 8 * Thomas Sailer (sailer@ife.ee.ethz.ch)
9 * 9 *
10 * Audio Class 3.0 support by Ruslan Bilovol <ruslan.bilovol@gmail.com>
10 * 11 *
11 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
@@ -44,6 +45,7 @@
44#include <linux/mutex.h> 45#include <linux/mutex.h>
45#include <linux/usb/audio.h> 46#include <linux/usb/audio.h>
46#include <linux/usb/audio-v2.h> 47#include <linux/usb/audio-v2.h>
48#include <linux/usb/audio-v3.h>
47#include <linux/module.h> 49#include <linux/module.h>
48 50
49#include <sound/control.h> 51#include <sound/control.h>
@@ -281,7 +283,8 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
281 break; 283 break;
282 } 284 }
283 285
284 case UAC_VERSION_2: { 286 case UAC_VERSION_2:
287 case UAC_VERSION_3: {
285 struct usb_interface_assoc_descriptor *assoc = 288 struct usb_interface_assoc_descriptor *assoc =
286 usb_ifnum_to_if(dev, ctrlif)->intf_assoc; 289 usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
287 290
@@ -301,7 +304,7 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
301 } 304 }
302 305
303 if (!assoc) { 306 if (!assoc) {
304 dev_err(&dev->dev, "Audio class v2 interfaces need an interface association\n"); 307 dev_err(&dev->dev, "Audio class v2/v3 interfaces need an interface association\n");
305 return -EINVAL; 308 return -EINVAL;
306 } 309 }
307 310
diff --git a/sound/usb/card.h b/sound/usb/card.h
index ed87cc83eb47..1406292d50ec 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -22,7 +22,7 @@ struct audioformat {
22 unsigned char endpoint; /* endpoint */ 22 unsigned char endpoint; /* endpoint */
23 unsigned char ep_attr; /* endpoint attributes */ 23 unsigned char ep_attr; /* endpoint attributes */
24 unsigned char datainterval; /* log_2 of data packet interval */ 24 unsigned char datainterval; /* log_2 of data packet interval */
25 unsigned char protocol; /* UAC_VERSION_1/2 */ 25 unsigned char protocol; /* UAC_VERSION_1/2/3 */
26 unsigned int maxpacksize; /* max. packet size */ 26 unsigned int maxpacksize; /* max. packet size */
27 unsigned int rates; /* rate bitmasks */ 27 unsigned int rates; /* rate bitmasks */
28 unsigned int rate_min, rate_max; /* min/max rates */ 28 unsigned int rate_min, rate_max; /* min/max rates */
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index eb3396ffba4c..25de7fe285d9 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -23,6 +23,7 @@
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include <linux/usb/audio.h> 24#include <linux/usb/audio.h>
25#include <linux/usb/audio-v2.h> 25#include <linux/usb/audio-v2.h>
26#include <linux/usb/audio-v3.h>
26 27
27#include <sound/core.h> 28#include <sound/core.h>
28#include <sound/info.h> 29#include <sound/info.h>
@@ -50,6 +51,22 @@ static struct uac_clock_source_descriptor *
50 return NULL; 51 return NULL;
51} 52}
52 53
54static struct uac3_clock_source_descriptor *
55 snd_usb_find_clock_source_v3(struct usb_host_interface *ctrl_iface,
56 int clock_id)
57{
58 struct uac3_clock_source_descriptor *cs = NULL;
59
60 while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra,
61 ctrl_iface->extralen,
62 cs, UAC3_CLOCK_SOURCE))) {
63 if (cs->bClockID == clock_id)
64 return cs;
65 }
66
67 return NULL;
68}
69
53static struct uac_clock_selector_descriptor * 70static struct uac_clock_selector_descriptor *
54 snd_usb_find_clock_selector(struct usb_host_interface *ctrl_iface, 71 snd_usb_find_clock_selector(struct usb_host_interface *ctrl_iface,
55 int clock_id) 72 int clock_id)
@@ -69,6 +86,22 @@ static struct uac_clock_selector_descriptor *
69 return NULL; 86 return NULL;
70} 87}
71 88
89static struct uac3_clock_selector_descriptor *
90 snd_usb_find_clock_selector_v3(struct usb_host_interface *ctrl_iface,
91 int clock_id)
92{
93 struct uac3_clock_selector_descriptor *cs = NULL;
94
95 while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra,
96 ctrl_iface->extralen,
97 cs, UAC3_CLOCK_SELECTOR))) {
98 if (cs->bClockID == clock_id)
99 return cs;
100 }
101
102 return NULL;
103}
104
72static struct uac_clock_multiplier_descriptor * 105static struct uac_clock_multiplier_descriptor *
73 snd_usb_find_clock_multiplier(struct usb_host_interface *ctrl_iface, 106 snd_usb_find_clock_multiplier(struct usb_host_interface *ctrl_iface,
74 int clock_id) 107 int clock_id)
@@ -85,6 +118,22 @@ static struct uac_clock_multiplier_descriptor *
85 return NULL; 118 return NULL;
86} 119}
87 120
121static struct uac3_clock_multiplier_descriptor *
122 snd_usb_find_clock_multiplier_v3(struct usb_host_interface *ctrl_iface,
123 int clock_id)
124{
125 struct uac3_clock_multiplier_descriptor *cs = NULL;
126
127 while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra,
128 ctrl_iface->extralen,
129 cs, UAC3_CLOCK_MULTIPLIER))) {
130 if (cs->bClockID == clock_id)
131 return cs;
132 }
133
134 return NULL;
135}
136
88static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_id) 137static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_id)
89{ 138{
90 unsigned char buf; 139 unsigned char buf;
@@ -138,19 +187,33 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
138 return ret; 187 return ret;
139} 188}
140 189
141static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id) 190static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
191 int protocol,
192 int source_id)
142{ 193{
143 int err; 194 int err;
144 unsigned char data; 195 unsigned char data;
145 struct usb_device *dev = chip->dev; 196 struct usb_device *dev = chip->dev;
146 struct uac_clock_source_descriptor *cs_desc = 197 u32 bmControls;
147 snd_usb_find_clock_source(chip->ctrl_intf, source_id); 198
148 199 if (protocol == UAC_VERSION_3) {
149 if (!cs_desc) 200 struct uac3_clock_source_descriptor *cs_desc =
150 return 0; 201 snd_usb_find_clock_source_v3(chip->ctrl_intf, source_id);
202
203 if (!cs_desc)
204 return 0;
205 bmControls = le32_to_cpu(cs_desc->bmControls);
206 } else { /* UAC_VERSION_1/2 */
207 struct uac_clock_source_descriptor *cs_desc =
208 snd_usb_find_clock_source(chip->ctrl_intf, source_id);
209
210 if (!cs_desc)
211 return 0;
212 bmControls = cs_desc->bmControls;
213 }
151 214
152 /* If a clock source can't tell us whether it's valid, we assume it is */ 215 /* If a clock source can't tell us whether it's valid, we assume it is */
153 if (!uac2_control_is_readable(cs_desc->bmControls, 216 if (!uac_v2v3_control_is_readable(bmControls,
154 UAC2_CS_CONTROL_CLOCK_VALID - 1)) 217 UAC2_CS_CONTROL_CLOCK_VALID - 1))
155 return 1; 218 return 1;
156 219
@@ -170,9 +233,8 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
170 return !!data; 233 return !!data;
171} 234}
172 235
173static int __uac_clock_find_source(struct snd_usb_audio *chip, 236static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id,
174 int entity_id, unsigned long *visited, 237 unsigned long *visited, bool validate)
175 bool validate)
176{ 238{
177 struct uac_clock_source_descriptor *source; 239 struct uac_clock_source_descriptor *source;
178 struct uac_clock_selector_descriptor *selector; 240 struct uac_clock_selector_descriptor *selector;
@@ -191,7 +253,8 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
191 source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id); 253 source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id);
192 if (source) { 254 if (source) {
193 entity_id = source->bClockID; 255 entity_id = source->bClockID;
194 if (validate && !uac_clock_source_is_valid(chip, entity_id)) { 256 if (validate && !uac_clock_source_is_valid(chip, UAC_VERSION_2,
257 entity_id)) {
195 usb_audio_err(chip, 258 usb_audio_err(chip,
196 "clock source %d is not valid, cannot use\n", 259 "clock source %d is not valid, cannot use\n",
197 entity_id); 260 entity_id);
@@ -260,6 +323,97 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
260 return -EINVAL; 323 return -EINVAL;
261} 324}
262 325
326static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id,
327 unsigned long *visited, bool validate)
328{
329 struct uac3_clock_source_descriptor *source;
330 struct uac3_clock_selector_descriptor *selector;
331 struct uac3_clock_multiplier_descriptor *multiplier;
332
333 entity_id &= 0xff;
334
335 if (test_and_set_bit(entity_id, visited)) {
336 usb_audio_warn(chip,
337 "%s(): recursive clock topology detected, id %d.\n",
338 __func__, entity_id);
339 return -EINVAL;
340 }
341
342 /* first, see if the ID we're looking for is a clock source already */
343 source = snd_usb_find_clock_source_v3(chip->ctrl_intf, entity_id);
344 if (source) {
345 entity_id = source->bClockID;
346 if (validate && !uac_clock_source_is_valid(chip, UAC_VERSION_3,
347 entity_id)) {
348 usb_audio_err(chip,
349 "clock source %d is not valid, cannot use\n",
350 entity_id);
351 return -ENXIO;
352 }
353 return entity_id;
354 }
355
356 selector = snd_usb_find_clock_selector_v3(chip->ctrl_intf, entity_id);
357 if (selector) {
358 int ret, i, cur;
359
360 /* the entity ID we are looking for is a selector.
361 * find out what it currently selects */
362 ret = uac_clock_selector_get_val(chip, selector->bClockID);
363 if (ret < 0)
364 return ret;
365
366 /* Selector values are one-based */
367
368 if (ret > selector->bNrInPins || ret < 1) {
369 usb_audio_err(chip,
370 "%s(): selector reported illegal value, id %d, ret %d\n",
371 __func__, selector->bClockID, ret);
372
373 return -EINVAL;
374 }
375
376 cur = ret;
377 ret = __uac3_clock_find_source(chip, selector->baCSourceID[ret - 1],
378 visited, validate);
379 if (!validate || ret > 0 || !chip->autoclock)
380 return ret;
381
382 /* The current clock source is invalid, try others. */
383 for (i = 1; i <= selector->bNrInPins; i++) {
384 int err;
385
386 if (i == cur)
387 continue;
388
389 ret = __uac3_clock_find_source(chip, selector->baCSourceID[i - 1],
390 visited, true);
391 if (ret < 0)
392 continue;
393
394 err = uac_clock_selector_set_val(chip, entity_id, i);
395 if (err < 0)
396 continue;
397
398 usb_audio_info(chip,
399 "found and selected valid clock source %d\n",
400 ret);
401 return ret;
402 }
403
404 return -ENXIO;
405 }
406
407 /* FIXME: multipliers only act as pass-thru element for now */
408 multiplier = snd_usb_find_clock_multiplier_v3(chip->ctrl_intf,
409 entity_id);
410 if (multiplier)
411 return __uac3_clock_find_source(chip, multiplier->bCSourceID,
412 visited, validate);
413
414 return -EINVAL;
415}
416
263/* 417/*
264 * For all kinds of sample rate settings and other device queries, 418 * For all kinds of sample rate settings and other device queries,
265 * the clock source (end-leaf) must be used. However, clock selectors, 419 * the clock source (end-leaf) must be used. However, clock selectors,
@@ -271,12 +425,22 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
271 * 425 *
272 * Returns the clock source UnitID (>=0) on success, or an error. 426 * Returns the clock source UnitID (>=0) on success, or an error.
273 */ 427 */
274int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id, 428int snd_usb_clock_find_source(struct snd_usb_audio *chip, int protocol,
275 bool validate) 429 int entity_id, bool validate)
276{ 430{
277 DECLARE_BITMAP(visited, 256); 431 DECLARE_BITMAP(visited, 256);
278 memset(visited, 0, sizeof(visited)); 432 memset(visited, 0, sizeof(visited));
279 return __uac_clock_find_source(chip, entity_id, visited, validate); 433
434 switch (protocol) {
435 case UAC_VERSION_2:
436 return __uac_clock_find_source(chip, entity_id, visited,
437 validate);
438 case UAC_VERSION_3:
439 return __uac3_clock_find_source(chip, entity_id, visited,
440 validate);
441 default:
442 return -EINVAL;
443 }
280} 444}
281 445
282static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, 446static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
@@ -335,7 +499,7 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
335 return 0; 499 return 0;
336} 500}
337 501
338static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface, 502static int get_sample_rate_v2v3(struct snd_usb_audio *chip, int iface,
339 int altsetting, int clock) 503 int altsetting, int clock)
340{ 504{
341 struct usb_device *dev = chip->dev; 505 struct usb_device *dev = chip->dev;
@@ -348,7 +512,7 @@ static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface,
348 snd_usb_ctrl_intf(chip) | (clock << 8), 512 snd_usb_ctrl_intf(chip) | (clock << 8),
349 &data, sizeof(data)); 513 &data, sizeof(data));
350 if (err < 0) { 514 if (err < 0) {
351 dev_warn(&dev->dev, "%d:%d: cannot get freq (v2): err %d\n", 515 dev_warn(&dev->dev, "%d:%d: cannot get freq (v2/v3): err %d\n",
352 iface, altsetting, err); 516 iface, altsetting, err);
353 return 0; 517 return 0;
354 } 518 }
@@ -356,7 +520,7 @@ static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface,
356 return le32_to_cpu(data); 520 return le32_to_cpu(data);
357} 521}
358 522
359static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, 523static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface,
360 struct usb_host_interface *alts, 524 struct usb_host_interface *alts,
361 struct audioformat *fmt, int rate) 525 struct audioformat *fmt, int rate)
362{ 526{
@@ -365,18 +529,30 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
365 int err, cur_rate, prev_rate; 529 int err, cur_rate, prev_rate;
366 int clock; 530 int clock;
367 bool writeable; 531 bool writeable;
368 struct uac_clock_source_descriptor *cs_desc; 532 u32 bmControls;
369 533
370 clock = snd_usb_clock_find_source(chip, fmt->clock, true); 534 clock = snd_usb_clock_find_source(chip, fmt->protocol,
535 fmt->clock, true);
371 if (clock < 0) 536 if (clock < 0)
372 return clock; 537 return clock;
373 538
374 prev_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); 539 prev_rate = get_sample_rate_v2v3(chip, iface, fmt->altsetting, clock);
375 if (prev_rate == rate) 540 if (prev_rate == rate)
376 return 0; 541 return 0;
377 542
378 cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock); 543 if (fmt->protocol == UAC_VERSION_3) {
379 writeable = uac2_control_is_writeable(cs_desc->bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1); 544 struct uac3_clock_source_descriptor *cs_desc;
545
546 cs_desc = snd_usb_find_clock_source_v3(chip->ctrl_intf, clock);
547 bmControls = le32_to_cpu(cs_desc->bmControls);
548 } else {
549 struct uac_clock_source_descriptor *cs_desc;
550
551 cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock);
552 bmControls = cs_desc->bmControls;
553 }
554
555 writeable = uac_v2v3_control_is_writeable(bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1);
380 if (writeable) { 556 if (writeable) {
381 data = cpu_to_le32(rate); 557 data = cpu_to_le32(rate);
382 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, 558 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
@@ -386,12 +562,13 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
386 &data, sizeof(data)); 562 &data, sizeof(data));
387 if (err < 0) { 563 if (err < 0) {
388 usb_audio_err(chip, 564 usb_audio_err(chip,
389 "%d:%d: cannot set freq %d (v2): err %d\n", 565 "%d:%d: cannot set freq %d (v2/v3): err %d\n",
390 iface, fmt->altsetting, rate, err); 566 iface, fmt->altsetting, rate, err);
391 return err; 567 return err;
392 } 568 }
393 569
394 cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); 570 cur_rate = get_sample_rate_v2v3(chip, iface,
571 fmt->altsetting, clock);
395 } else { 572 } else {
396 cur_rate = prev_rate; 573 cur_rate = prev_rate;
397 } 574 }
@@ -430,7 +607,8 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
430 return set_sample_rate_v1(chip, iface, alts, fmt, rate); 607 return set_sample_rate_v1(chip, iface, alts, fmt, rate);
431 608
432 case UAC_VERSION_2: 609 case UAC_VERSION_2:
433 return set_sample_rate_v2(chip, iface, alts, fmt, rate); 610 case UAC_VERSION_3:
611 return set_sample_rate_v2v3(chip, iface, alts, fmt, rate);
434 } 612 }
435} 613}
436 614
diff --git a/sound/usb/clock.h b/sound/usb/clock.h
index 87557cae1a0b..076e31b79ee0 100644
--- a/sound/usb/clock.h
+++ b/sound/usb/clock.h
@@ -6,7 +6,7 @@ int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
6 struct usb_host_interface *alts, 6 struct usb_host_interface *alts,
7 struct audioformat *fmt, int rate); 7 struct audioformat *fmt, int rate);
8 8
9int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id, 9int snd_usb_clock_find_source(struct snd_usb_audio *chip, int protocol,
10 bool validate); 10 int entity_id, bool validate);
11 11
12#endif /* __USBAUDIO_CLOCK_H */ 12#endif /* __USBAUDIO_CLOCK_H */
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 2c44386e5569..edbe67eeddfa 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -20,6 +20,7 @@
20#include <linux/usb.h> 20#include <linux/usb.h>
21#include <linux/usb/audio.h> 21#include <linux/usb/audio.h>
22#include <linux/usb/audio-v2.h> 22#include <linux/usb/audio-v2.h>
23#include <linux/usb/audio-v3.h>
23 24
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/pcm.h> 26#include <sound/pcm.h>
@@ -39,11 +40,11 @@
39 * @dev: usb device 40 * @dev: usb device
40 * @fp: audioformat record 41 * @fp: audioformat record
41 * @format: the format tag (wFormatTag) 42 * @format: the format tag (wFormatTag)
42 * @fmt: the format type descriptor 43 * @fmt: the format type descriptor (v1/v2) or AudioStreaming descriptor (v3)
43 */ 44 */
44static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, 45static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
45 struct audioformat *fp, 46 struct audioformat *fp,
46 unsigned int format, void *_fmt) 47 u64 format, void *_fmt)
47{ 48{
48 int sample_width, sample_bytes; 49 int sample_width, sample_bytes;
49 u64 pcm_formats = 0; 50 u64 pcm_formats = 0;
@@ -69,6 +70,18 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
69 format <<= 1; 70 format <<= 1;
70 break; 71 break;
71 } 72 }
73 case UAC_VERSION_3: {
74 struct uac3_as_header_descriptor *as = _fmt;
75
76 sample_width = as->bBitResolution;
77 sample_bytes = as->bSubslotSize;
78
79 if (format & UAC3_FORMAT_TYPE_I_RAW_DATA)
80 pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL;
81
82 format <<= 1;
83 break;
84 }
72 } 85 }
73 86
74 if ((pcm_formats == 0) && 87 if ((pcm_formats == 0) &&
@@ -137,7 +150,7 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
137 } 150 }
138 if (format & ~0x3f) { 151 if (format & ~0x3f) {
139 usb_audio_info(chip, 152 usb_audio_info(chip,
140 "%u:%d : unsupported format bits %#x\n", 153 "%u:%d : unsupported format bits %#llx\n",
141 fp->iface, fp->altsetting, format); 154 fp->iface, fp->altsetting, format);
142 } 155 }
143 156
@@ -281,15 +294,16 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip,
281 294
282/* 295/*
283 * parse the format descriptor and stores the possible sample rates 296 * parse the format descriptor and stores the possible sample rates
284 * on the audioformat table (audio class v2). 297 * on the audioformat table (audio class v2 and v3).
285 */ 298 */
286static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, 299static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip,
287 struct audioformat *fp) 300 struct audioformat *fp)
288{ 301{
289 struct usb_device *dev = chip->dev; 302 struct usb_device *dev = chip->dev;
290 unsigned char tmp[2], *data; 303 unsigned char tmp[2], *data;
291 int nr_triplets, data_size, ret = 0; 304 int nr_triplets, data_size, ret = 0;
292 int clock = snd_usb_clock_find_source(chip, fp->clock, false); 305 int clock = snd_usb_clock_find_source(chip, fp->protocol,
306 fp->clock, false);
293 307
294 if (clock < 0) { 308 if (clock < 0) {
295 dev_err(&dev->dev, 309 dev_err(&dev->dev,
@@ -368,13 +382,30 @@ err:
368 * parse the format type I and III descriptors 382 * parse the format type I and III descriptors
369 */ 383 */
370static int parse_audio_format_i(struct snd_usb_audio *chip, 384static int parse_audio_format_i(struct snd_usb_audio *chip,
371 struct audioformat *fp, unsigned int format, 385 struct audioformat *fp, u64 format,
372 struct uac_format_type_i_continuous_descriptor *fmt) 386 void *_fmt)
373{ 387{
374 snd_pcm_format_t pcm_format; 388 snd_pcm_format_t pcm_format;
389 unsigned int fmt_type;
375 int ret; 390 int ret;
376 391
377 if (fmt->bFormatType == UAC_FORMAT_TYPE_III) { 392 switch (fp->protocol) {
393 default:
394 case UAC_VERSION_1:
395 case UAC_VERSION_2: {
396 struct uac_format_type_i_continuous_descriptor *fmt = _fmt;
397
398 fmt_type = fmt->bFormatType;
399 break;
400 }
401 case UAC_VERSION_3: {
402 /* fp->fmt_type is already set in this case */
403 fmt_type = fp->fmt_type;
404 break;
405 }
406 }
407
408 if (fmt_type == UAC_FORMAT_TYPE_III) {
378 /* FIXME: the format type is really IECxxx 409 /* FIXME: the format type is really IECxxx
379 * but we give normal PCM format to get the existing 410 * but we give normal PCM format to get the existing
380 * apps working... 411 * apps working...
@@ -393,7 +424,7 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
393 } 424 }
394 fp->formats = pcm_format_to_bits(pcm_format); 425 fp->formats = pcm_format_to_bits(pcm_format);
395 } else { 426 } else {
396 fp->formats = parse_audio_format_i_type(chip, fp, format, fmt); 427 fp->formats = parse_audio_format_i_type(chip, fp, format, _fmt);
397 if (!fp->formats) 428 if (!fp->formats)
398 return -EINVAL; 429 return -EINVAL;
399 } 430 }
@@ -405,15 +436,20 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
405 */ 436 */
406 switch (fp->protocol) { 437 switch (fp->protocol) {
407 default: 438 default:
408 case UAC_VERSION_1: 439 case UAC_VERSION_1: {
440 struct uac_format_type_i_continuous_descriptor *fmt = _fmt;
441
409 fp->channels = fmt->bNrChannels; 442 fp->channels = fmt->bNrChannels;
410 ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7); 443 ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7);
411 break; 444 break;
445 }
412 case UAC_VERSION_2: 446 case UAC_VERSION_2:
447 case UAC_VERSION_3: {
413 /* fp->channels is already set in this case */ 448 /* fp->channels is already set in this case */
414 ret = parse_audio_format_rates_v2(chip, fp); 449 ret = parse_audio_format_rates_v2v3(chip, fp);
415 break; 450 break;
416 } 451 }
452 }
417 453
418 if (fp->channels < 1) { 454 if (fp->channels < 1) {
419 usb_audio_err(chip, 455 usb_audio_err(chip,
@@ -430,7 +466,7 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
430 */ 466 */
431static int parse_audio_format_ii(struct snd_usb_audio *chip, 467static int parse_audio_format_ii(struct snd_usb_audio *chip,
432 struct audioformat *fp, 468 struct audioformat *fp,
433 int format, void *_fmt) 469 u64 format, void *_fmt)
434{ 470{
435 int brate, framesize, ret; 471 int brate, framesize, ret;
436 472
@@ -445,7 +481,7 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
445 break; 481 break;
446 default: 482 default:
447 usb_audio_info(chip, 483 usb_audio_info(chip,
448 "%u:%d : unknown format tag %#x is detected. processed as MPEG.\n", 484 "%u:%d : unknown format tag %#llx is detected. processed as MPEG.\n",
449 fp->iface, fp->altsetting, format); 485 fp->iface, fp->altsetting, format);
450 fp->formats = SNDRV_PCM_FMTBIT_MPEG; 486 fp->formats = SNDRV_PCM_FMTBIT_MPEG;
451 break; 487 break;
@@ -470,7 +506,7 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
470 framesize = le16_to_cpu(fmt->wSamplesPerFrame); 506 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
471 usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 507 usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
472 fp->frame_size = framesize; 508 fp->frame_size = framesize;
473 ret = parse_audio_format_rates_v2(chip, fp); 509 ret = parse_audio_format_rates_v2v3(chip, fp);
474 break; 510 break;
475 } 511 }
476 } 512 }
@@ -479,7 +515,7 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
479} 515}
480 516
481int snd_usb_parse_audio_format(struct snd_usb_audio *chip, 517int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
482 struct audioformat *fp, unsigned int format, 518 struct audioformat *fp, u64 format,
483 struct uac_format_type_i_continuous_descriptor *fmt, 519 struct uac_format_type_i_continuous_descriptor *fmt,
484 int stream) 520 int stream)
485{ 521{
@@ -520,3 +556,26 @@ int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
520 return 0; 556 return 0;
521} 557}
522 558
559int snd_usb_parse_audio_format_v3(struct snd_usb_audio *chip,
560 struct audioformat *fp,
561 struct uac3_as_header_descriptor *as,
562 int stream)
563{
564 u64 format = le64_to_cpu(as->bmFormats);
565 int err;
566
567 /*
568 * Type I format bits are D0..D6
569 * This test works because type IV is not supported
570 */
571 if (format & 0x7f)
572 fp->fmt_type = UAC_FORMAT_TYPE_I;
573 else
574 fp->fmt_type = UAC_FORMAT_TYPE_III;
575
576 err = parse_audio_format_i(chip, fp, format, as);
577 if (err < 0)
578 return err;
579
580 return 0;
581}
diff --git a/sound/usb/format.h b/sound/usb/format.h
index 8c3ff9ce0824..e70171892f32 100644
--- a/sound/usb/format.h
+++ b/sound/usb/format.h
@@ -3,8 +3,12 @@
3#define __USBAUDIO_FORMAT_H 3#define __USBAUDIO_FORMAT_H
4 4
5int snd_usb_parse_audio_format(struct snd_usb_audio *chip, 5int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
6 struct audioformat *fp, unsigned int format, 6 struct audioformat *fp, u64 format,
7 struct uac_format_type_i_continuous_descriptor *fmt, 7 struct uac_format_type_i_continuous_descriptor *fmt,
8 int stream); 8 int stream);
9 9
10int snd_usb_parse_audio_format_v3(struct snd_usb_audio *chip,
11 struct audioformat *fp,
12 struct uac3_as_header_descriptor *as,
13 int stream);
10#endif /* __USBAUDIO_FORMAT_H */ 14#endif /* __USBAUDIO_FORMAT_H */
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 06b22624ab7a..1c02f7373eda 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -51,6 +51,7 @@
51#include <linux/usb.h> 51#include <linux/usb.h>
52#include <linux/usb/audio.h> 52#include <linux/usb/audio.h>
53#include <linux/usb/audio-v2.h> 53#include <linux/usb/audio-v2.h>
54#include <linux/usb/audio-v3.h>
54 55
55#include <sound/core.h> 56#include <sound/core.h>
56#include <sound/control.h> 57#include <sound/control.h>
@@ -189,7 +190,7 @@ static void *find_audio_control_unit(struct mixer_build *state,
189 USB_DT_CS_INTERFACE)) != NULL) { 190 USB_DT_CS_INTERFACE)) != NULL) {
190 if (hdr->bLength >= 4 && 191 if (hdr->bLength >= 4 &&
191 hdr->bDescriptorSubtype >= UAC_INPUT_TERMINAL && 192 hdr->bDescriptorSubtype >= UAC_INPUT_TERMINAL &&
192 hdr->bDescriptorSubtype <= UAC2_SAMPLE_RATE_CONVERTER && 193 hdr->bDescriptorSubtype <= UAC3_SAMPLE_RATE_CONVERTER &&
193 hdr->bUnitID == unit) 194 hdr->bUnitID == unit)
194 return hdr; 195 return hdr;
195 } 196 }
@@ -468,9 +469,10 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
468 469
469 validx += cval->idx_off; 470 validx += cval->idx_off;
470 471
472
471 if (cval->head.mixer->protocol == UAC_VERSION_1) { 473 if (cval->head.mixer->protocol == UAC_VERSION_1) {
472 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 474 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
473 } else { /* UAC_VERSION_2 */ 475 } else { /* UAC_VERSION_2/3 */
474 val_len = uac2_ctl_value_size(cval->val_type); 476 val_len = uac2_ctl_value_size(cval->val_type);
475 477
476 /* FIXME */ 478 /* FIXME */
@@ -723,6 +725,7 @@ static int get_term_name(struct mixer_build *state, struct usb_audio_term *iterm
723static int check_input_term(struct mixer_build *state, int id, 725static int check_input_term(struct mixer_build *state, int id,
724 struct usb_audio_term *term) 726 struct usb_audio_term *term)
725{ 727{
728 int protocol = state->mixer->protocol;
726 int err; 729 int err;
727 void *p1; 730 void *p1;
728 731
@@ -730,16 +733,104 @@ static int check_input_term(struct mixer_build *state, int id,
730 while ((p1 = find_audio_control_unit(state, id)) != NULL) { 733 while ((p1 = find_audio_control_unit(state, id)) != NULL) {
731 unsigned char *hdr = p1; 734 unsigned char *hdr = p1;
732 term->id = id; 735 term->id = id;
733 switch (hdr[2]) { 736
734 case UAC_INPUT_TERMINAL: 737 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
735 if (state->mixer->protocol == UAC_VERSION_1) { 738 switch (hdr[2]) {
736 struct uac_input_terminal_descriptor *d = p1; 739 case UAC_INPUT_TERMINAL:
737 term->type = le16_to_cpu(d->wTerminalType); 740 if (protocol == UAC_VERSION_1) {
738 term->channels = d->bNrChannels; 741 struct uac_input_terminal_descriptor *d = p1;
739 term->chconfig = le16_to_cpu(d->wChannelConfig); 742
740 term->name = d->iTerminal; 743 term->type = le16_to_cpu(d->wTerminalType);
741 } else { /* UAC_VERSION_2 */ 744 term->channels = d->bNrChannels;
742 struct uac2_input_terminal_descriptor *d = p1; 745 term->chconfig = le16_to_cpu(d->wChannelConfig);
746 term->name = d->iTerminal;
747 } else { /* UAC_VERSION_2 */
748 struct uac2_input_terminal_descriptor *d = p1;
749
750 /* call recursively to verify that the
751 * referenced clock entity is valid */
752 err = check_input_term(state, d->bCSourceID, term);
753 if (err < 0)
754 return err;
755
756 /* save input term properties after recursion,
757 * to ensure they are not overriden by the
758 * recursion calls */
759 term->id = id;
760 term->type = le16_to_cpu(d->wTerminalType);
761 term->channels = d->bNrChannels;
762 term->chconfig = le32_to_cpu(d->bmChannelConfig);
763 term->name = d->iTerminal;
764 }
765 return 0;
766 case UAC_FEATURE_UNIT: {
767 /* the header is the same for v1 and v2 */
768 struct uac_feature_unit_descriptor *d = p1;
769
770 id = d->bSourceID;
771 break; /* continue to parse */
772 }
773 case UAC_MIXER_UNIT: {
774 struct uac_mixer_unit_descriptor *d = p1;
775
776 term->type = d->bDescriptorSubtype << 16; /* virtual type */
777 term->channels = uac_mixer_unit_bNrChannels(d);
778 term->chconfig = uac_mixer_unit_wChannelConfig(d, protocol);
779 term->name = uac_mixer_unit_iMixer(d);
780 return 0;
781 }
782 case UAC_SELECTOR_UNIT:
783 case UAC2_CLOCK_SELECTOR: {
784 struct uac_selector_unit_descriptor *d = p1;
785 /* call recursively to retrieve the channel info */
786 err = check_input_term(state, d->baSourceID[0], term);
787 if (err < 0)
788 return err;
789 term->type = d->bDescriptorSubtype << 16; /* virtual type */
790 term->id = id;
791 term->name = uac_selector_unit_iSelector(d);
792 return 0;
793 }
794 case UAC1_PROCESSING_UNIT:
795 case UAC1_EXTENSION_UNIT:
796 /* UAC2_PROCESSING_UNIT_V2 */
797 /* UAC2_EFFECT_UNIT */
798 case UAC2_EXTENSION_UNIT_V2: {
799 struct uac_processing_unit_descriptor *d = p1;
800
801 if (protocol == UAC_VERSION_2 &&
802 hdr[2] == UAC2_EFFECT_UNIT) {
803 /* UAC2/UAC1 unit IDs overlap here in an
804 * uncompatible way. Ignore this unit for now.
805 */
806 return 0;
807 }
808
809 if (d->bNrInPins) {
810 id = d->baSourceID[0];
811 break; /* continue to parse */
812 }
813 term->type = d->bDescriptorSubtype << 16; /* virtual type */
814 term->channels = uac_processing_unit_bNrChannels(d);
815 term->chconfig = uac_processing_unit_wChannelConfig(d, protocol);
816 term->name = uac_processing_unit_iProcessing(d, protocol);
817 return 0;
818 }
819 case UAC2_CLOCK_SOURCE: {
820 struct uac_clock_source_descriptor *d = p1;
821
822 term->type = d->bDescriptorSubtype << 16; /* virtual type */
823 term->id = id;
824 term->name = d->iClockSource;
825 return 0;
826 }
827 default:
828 return -ENODEV;
829 }
830 } else { /* UAC_VERSION_3 */
831 switch (hdr[2]) {
832 case UAC_INPUT_TERMINAL: {
833 struct uac3_input_terminal_descriptor *d = p1;
743 834
744 /* call recursively to verify that the 835 /* call recursively to verify that the
745 * referenced clock entity is valid */ 836 * referenced clock entity is valid */
@@ -752,71 +843,31 @@ static int check_input_term(struct mixer_build *state, int id,
752 * recursion calls */ 843 * recursion calls */
753 term->id = id; 844 term->id = id;
754 term->type = le16_to_cpu(d->wTerminalType); 845 term->type = le16_to_cpu(d->wTerminalType);
755 term->channels = d->bNrChannels; 846
756 term->chconfig = le32_to_cpu(d->bmChannelConfig); 847 /* REVISIT: UAC3 IT doesn't have channels/cfg */
757 term->name = d->iTerminal; 848 term->channels = 0;
758 } 849 term->chconfig = 0;
759 return 0; 850
760 case UAC_FEATURE_UNIT: { 851 term->name = le16_to_cpu(d->wTerminalDescrStr);
761 /* the header is the same for v1 and v2 */
762 struct uac_feature_unit_descriptor *d = p1;
763 id = d->bSourceID;
764 break; /* continue to parse */
765 }
766 case UAC_MIXER_UNIT: {
767 struct uac_mixer_unit_descriptor *d = p1;
768 term->type = d->bDescriptorSubtype << 16; /* virtual type */
769 term->channels = uac_mixer_unit_bNrChannels(d);
770 term->chconfig = uac_mixer_unit_wChannelConfig(d, state->mixer->protocol);
771 term->name = uac_mixer_unit_iMixer(d);
772 return 0;
773 }
774 case UAC_SELECTOR_UNIT:
775 case UAC2_CLOCK_SELECTOR: {
776 struct uac_selector_unit_descriptor *d = p1;
777 /* call recursively to retrieve the channel info */
778 err = check_input_term(state, d->baSourceID[0], term);
779 if (err < 0)
780 return err;
781 term->type = d->bDescriptorSubtype << 16; /* virtual type */
782 term->id = id;
783 term->name = uac_selector_unit_iSelector(d);
784 return 0;
785 }
786 case UAC1_PROCESSING_UNIT:
787 case UAC1_EXTENSION_UNIT:
788 /* UAC2_PROCESSING_UNIT_V2 */
789 /* UAC2_EFFECT_UNIT */
790 case UAC2_EXTENSION_UNIT_V2: {
791 struct uac_processing_unit_descriptor *d = p1;
792
793 if (state->mixer->protocol == UAC_VERSION_2 &&
794 hdr[2] == UAC2_EFFECT_UNIT) {
795 /* UAC2/UAC1 unit IDs overlap here in an
796 * uncompatible way. Ignore this unit for now.
797 */
798 return 0; 852 return 0;
799 } 853 }
854 case UAC3_FEATURE_UNIT: {
855 struct uac3_feature_unit_descriptor *d = p1;
800 856
801 if (d->bNrInPins) { 857 id = d->bSourceID;
802 id = d->baSourceID[0];
803 break; /* continue to parse */ 858 break; /* continue to parse */
804 } 859 }
805 term->type = d->bDescriptorSubtype << 16; /* virtual type */ 860 case UAC3_CLOCK_SOURCE: {
806 term->channels = uac_processing_unit_bNrChannels(d); 861 struct uac3_clock_source_descriptor *d = p1;
807 term->chconfig = uac_processing_unit_wChannelConfig(d, state->mixer->protocol); 862
808 term->name = uac_processing_unit_iProcessing(d, state->mixer->protocol); 863 term->type = d->bDescriptorSubtype << 16; /* virtual type */
809 return 0; 864 term->id = id;
810 } 865 term->name = le16_to_cpu(d->wClockSourceStr);
811 case UAC2_CLOCK_SOURCE: { 866 return 0;
812 struct uac_clock_source_descriptor *d = p1; 867 }
813 term->type = d->bDescriptorSubtype << 16; /* virtual type */ 868 default:
814 term->id = id; 869 return -ENODEV;
815 term->name = d->iClockSource; 870 }
816 return 0;
817 }
818 default:
819 return -ENODEV;
820 } 871 }
821 } 872 }
822 return -ENODEV; 873 return -ENODEV;
@@ -1423,7 +1474,7 @@ static int parse_clock_source_unit(struct mixer_build *state, int unitid,
1423 * The only property of this unit we are interested in is the 1474 * The only property of this unit we are interested in is the
1424 * clock source validity. If that isn't readable, just bail out. 1475 * clock source validity. If that isn't readable, just bail out.
1425 */ 1476 */
1426 if (!uac2_control_is_readable(hdr->bmControls, 1477 if (!uac_v2v3_control_is_readable(hdr->bmControls,
1427 ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) 1478 ilog2(UAC2_CS_CONTROL_CLOCK_VALID)))
1428 return 0; 1479 return 0;
1429 1480
@@ -1439,7 +1490,7 @@ static int parse_clock_source_unit(struct mixer_build *state, int unitid,
1439 cval->val_type = USB_MIXER_BOOLEAN; 1490 cval->val_type = USB_MIXER_BOOLEAN;
1440 cval->control = UAC2_CS_CONTROL_CLOCK_VALID; 1491 cval->control = UAC2_CS_CONTROL_CLOCK_VALID;
1441 1492
1442 if (uac2_control_is_writeable(hdr->bmControls, 1493 if (uac_v2v3_control_is_writeable(hdr->bmControls,
1443 ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) 1494 ilog2(UAC2_CS_CONTROL_CLOCK_VALID)))
1444 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); 1495 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
1445 else { 1496 else {
@@ -1502,7 +1553,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
1502 unitid); 1553 unitid);
1503 return -EINVAL; 1554 return -EINVAL;
1504 } 1555 }
1505 } else { 1556 } else if (state->mixer->protocol == UAC_VERSION_2) {
1506 struct uac2_feature_unit_descriptor *ftr = _ftr; 1557 struct uac2_feature_unit_descriptor *ftr = _ftr;
1507 if (hdr->bLength < 6) { 1558 if (hdr->bLength < 6) {
1508 usb_audio_err(state->chip, 1559 usb_audio_err(state->chip,
@@ -1519,6 +1570,24 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
1519 unitid); 1570 unitid);
1520 return -EINVAL; 1571 return -EINVAL;
1521 } 1572 }
1573 } else { /* UAC_VERSION_3 */
1574 struct uac3_feature_unit_descriptor *ftr = _ftr;
1575
1576 if (hdr->bLength < 7) {
1577 usb_audio_err(state->chip,
1578 "unit %u: invalid UAC3_FEATURE_UNIT descriptor\n",
1579 unitid);
1580 return -EINVAL;
1581 }
1582 csize = 4;
1583 channels = (ftr->bLength - 7) / 4 - 1;
1584 bmaControls = ftr->bmaControls;
1585 if (hdr->bLength < 7 + csize) {
1586 usb_audio_err(state->chip,
1587 "unit %u: invalid UAC3_FEATURE_UNIT descriptor\n",
1588 unitid);
1589 return -EINVAL;
1590 }
1522 } 1591 }
1523 1592
1524 /* parse the source unit */ 1593 /* parse the source unit */
@@ -1577,7 +1646,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
1577 build_feature_ctl(state, _ftr, 0, i, &iterm, 1646 build_feature_ctl(state, _ftr, 0, i, &iterm,
1578 unitid, 0); 1647 unitid, 0);
1579 } 1648 }
1580 } else { /* UAC_VERSION_2 */ 1649 } else { /* UAC_VERSION_2/3 */
1581 for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) { 1650 for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) {
1582 unsigned int ch_bits = 0; 1651 unsigned int ch_bits = 0;
1583 unsigned int ch_read_only = 0; 1652 unsigned int ch_read_only = 0;
@@ -1587,9 +1656,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
1587 1656
1588 mask = snd_usb_combine_bytes(bmaControls + 1657 mask = snd_usb_combine_bytes(bmaControls +
1589 csize * (j+1), csize); 1658 csize * (j+1), csize);
1590 if (uac2_control_is_readable(mask, i)) { 1659 if (uac_v2v3_control_is_readable(mask, i)) {
1591 ch_bits |= (1 << j); 1660 ch_bits |= (1 << j);
1592 if (!uac2_control_is_writeable(mask, i)) 1661 if (!uac_v2v3_control_is_writeable(mask, i))
1593 ch_read_only |= (1 << j); 1662 ch_read_only |= (1 << j);
1594 } 1663 }
1595 } 1664 }
@@ -1610,9 +1679,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
1610 if (ch_bits & 1) 1679 if (ch_bits & 1)
1611 build_feature_ctl(state, _ftr, ch_bits, i, 1680 build_feature_ctl(state, _ftr, ch_bits, i,
1612 &iterm, unitid, ch_read_only); 1681 &iterm, unitid, ch_read_only);
1613 if (uac2_control_is_readable(master_bits, i)) 1682 if (uac_v2v3_control_is_readable(master_bits, i))
1614 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 1683 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid,
1615 !uac2_control_is_writeable(master_bits, i)); 1684 !uac_v2v3_control_is_writeable(master_bits, i));
1616 } 1685 }
1617 } 1686 }
1618 1687
@@ -2220,6 +2289,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
2220static int parse_audio_unit(struct mixer_build *state, int unitid) 2289static int parse_audio_unit(struct mixer_build *state, int unitid)
2221{ 2290{
2222 unsigned char *p1; 2291 unsigned char *p1;
2292 int protocol = state->mixer->protocol;
2223 2293
2224 if (test_and_set_bit(unitid, state->unitbitmap)) 2294 if (test_and_set_bit(unitid, state->unitbitmap))
2225 return 0; /* the unit already visited */ 2295 return 0; /* the unit already visited */
@@ -2230,36 +2300,61 @@ static int parse_audio_unit(struct mixer_build *state, int unitid)
2230 return -EINVAL; 2300 return -EINVAL;
2231 } 2301 }
2232 2302
2233 switch (p1[2]) { 2303 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
2234 case UAC_INPUT_TERMINAL: 2304 switch (p1[2]) {
2235 return 0; /* NOP */ 2305 case UAC_INPUT_TERMINAL:
2236 case UAC_MIXER_UNIT: 2306 return 0; /* NOP */
2237 return parse_audio_mixer_unit(state, unitid, p1); 2307 case UAC_MIXER_UNIT:
2238 case UAC2_CLOCK_SOURCE: 2308 return parse_audio_mixer_unit(state, unitid, p1);
2239 return parse_clock_source_unit(state, unitid, p1); 2309 case UAC2_CLOCK_SOURCE:
2240 case UAC_SELECTOR_UNIT: 2310 return parse_clock_source_unit(state, unitid, p1);
2241 case UAC2_CLOCK_SELECTOR: 2311 case UAC_SELECTOR_UNIT:
2242 return parse_audio_selector_unit(state, unitid, p1); 2312 case UAC2_CLOCK_SELECTOR:
2243 case UAC_FEATURE_UNIT: 2313 return parse_audio_selector_unit(state, unitid, p1);
2244 return parse_audio_feature_unit(state, unitid, p1); 2314 case UAC_FEATURE_UNIT:
2245 case UAC1_PROCESSING_UNIT: 2315 return parse_audio_feature_unit(state, unitid, p1);
2246 /* UAC2_EFFECT_UNIT has the same value */ 2316 case UAC1_PROCESSING_UNIT:
2247 if (state->mixer->protocol == UAC_VERSION_1) 2317 /* UAC2_EFFECT_UNIT has the same value */
2248 return parse_audio_processing_unit(state, unitid, p1); 2318 if (protocol == UAC_VERSION_1)
2249 else 2319 return parse_audio_processing_unit(state, unitid, p1);
2250 return 0; /* FIXME - effect units not implemented yet */ 2320 else
2251 case UAC1_EXTENSION_UNIT: 2321 return 0; /* FIXME - effect units not implemented yet */
2252 /* UAC2_PROCESSING_UNIT_V2 has the same value */ 2322 case UAC1_EXTENSION_UNIT:
2253 if (state->mixer->protocol == UAC_VERSION_1) 2323 /* UAC2_PROCESSING_UNIT_V2 has the same value */
2324 if (protocol == UAC_VERSION_1)
2325 return parse_audio_extension_unit(state, unitid, p1);
2326 else /* UAC_VERSION_2 */
2327 return parse_audio_processing_unit(state, unitid, p1);
2328 case UAC2_EXTENSION_UNIT_V2:
2254 return parse_audio_extension_unit(state, unitid, p1); 2329 return parse_audio_extension_unit(state, unitid, p1);
2255 else /* UAC_VERSION_2 */ 2330 default:
2331 usb_audio_err(state->chip,
2332 "unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
2333 return -EINVAL;
2334 }
2335 } else { /* UAC_VERSION_3 */
2336 switch (p1[2]) {
2337 case UAC_INPUT_TERMINAL:
2338 return 0; /* NOP */
2339 case UAC3_MIXER_UNIT:
2340 return parse_audio_mixer_unit(state, unitid, p1);
2341 case UAC3_CLOCK_SOURCE:
2342 return parse_clock_source_unit(state, unitid, p1);
2343 case UAC3_CLOCK_SELECTOR:
2344 return parse_audio_selector_unit(state, unitid, p1);
2345 case UAC3_FEATURE_UNIT:
2346 return parse_audio_feature_unit(state, unitid, p1);
2347 case UAC3_EFFECT_UNIT:
2348 return 0; /* FIXME - effect units not implemented yet */
2349 case UAC3_PROCESSING_UNIT:
2256 return parse_audio_processing_unit(state, unitid, p1); 2350 return parse_audio_processing_unit(state, unitid, p1);
2257 case UAC2_EXTENSION_UNIT_V2: 2351 case UAC3_EXTENSION_UNIT:
2258 return parse_audio_extension_unit(state, unitid, p1); 2352 return parse_audio_extension_unit(state, unitid, p1);
2259 default: 2353 default:
2260 usb_audio_err(state->chip, 2354 usb_audio_err(state->chip,
2261 "unit %u: unexpected type 0x%02x\n", unitid, p1[2]); 2355 "unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
2262 return -EINVAL; 2356 return -EINVAL;
2357 }
2263 } 2358 }
2264} 2359}
2265 2360
@@ -2330,7 +2425,7 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
2330 err = parse_audio_unit(&state, desc->bSourceID); 2425 err = parse_audio_unit(&state, desc->bSourceID);
2331 if (err < 0 && err != -EINVAL) 2426 if (err < 0 && err != -EINVAL)
2332 return err; 2427 return err;
2333 } else { /* UAC_VERSION_2 */ 2428 } else if (mixer->protocol == UAC_VERSION_2) {
2334 struct uac2_output_terminal_descriptor *desc = p; 2429 struct uac2_output_terminal_descriptor *desc = p;
2335 2430
2336 if (desc->bLength < sizeof(*desc)) 2431 if (desc->bLength < sizeof(*desc))
@@ -2351,6 +2446,27 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
2351 err = parse_audio_unit(&state, desc->bCSourceID); 2446 err = parse_audio_unit(&state, desc->bCSourceID);
2352 if (err < 0 && err != -EINVAL) 2447 if (err < 0 && err != -EINVAL)
2353 return err; 2448 return err;
2449 } else { /* UAC_VERSION_3 */
2450 struct uac3_output_terminal_descriptor *desc = p;
2451
2452 if (desc->bLength < sizeof(*desc))
2453 continue; /* invalid descriptor? */
2454 /* mark terminal ID as visited */
2455 set_bit(desc->bTerminalID, state.unitbitmap);
2456 state.oterm.id = desc->bTerminalID;
2457 state.oterm.type = le16_to_cpu(desc->wTerminalType);
2458 state.oterm.name = le16_to_cpu(desc->wTerminalDescrStr);
2459 err = parse_audio_unit(&state, desc->bSourceID);
2460 if (err < 0 && err != -EINVAL)
2461 return err;
2462
2463 /*
2464 * For UAC3, use the same approach to also add the
2465 * clock selectors
2466 */
2467 err = parse_audio_unit(&state, desc->bCSourceID);
2468 if (err < 0 && err != -EINVAL)
2469 return err;
2354 } 2470 }
2355 } 2471 }
2356 2472
@@ -2597,6 +2713,9 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2597 case UAC_VERSION_2: 2713 case UAC_VERSION_2:
2598 mixer->protocol = UAC_VERSION_2; 2714 mixer->protocol = UAC_VERSION_2;
2599 break; 2715 break;
2716 case UAC_VERSION_3:
2717 mixer->protocol = UAC_VERSION_3;
2718 break;
2600 } 2719 }
2601 2720
2602 if ((err = snd_usb_mixer_controls(mixer)) < 0 || 2721 if ((err = snd_usb_mixer_controls(mixer)) < 0 ||
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index dbbe854745ab..6a8f5843334e 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -20,6 +20,7 @@
20#include <linux/usb.h> 20#include <linux/usb.h>
21#include <linux/usb/audio.h> 21#include <linux/usb/audio.h>
22#include <linux/usb/audio-v2.h> 22#include <linux/usb/audio-v2.h>
23#include <linux/usb/audio-v3.h>
23 24
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/pcm.h> 26#include <sound/pcm.h>
@@ -311,6 +312,153 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
311 return chmap; 312 return chmap;
312} 313}
313 314
315/* UAC3 device stores channels information in Cluster Descriptors */
316static struct
317snd_pcm_chmap_elem *convert_chmap_v3(struct uac3_cluster_header_descriptor
318 *cluster)
319{
320 unsigned int channels = cluster->bNrChannels;
321 struct snd_pcm_chmap_elem *chmap;
322 void *p = cluster;
323 int len, c;
324
325 if (channels > ARRAY_SIZE(chmap->map))
326 return NULL;
327
328 chmap = kzalloc(sizeof(*chmap), GFP_KERNEL);
329 if (!chmap)
330 return NULL;
331
332 len = le16_to_cpu(cluster->wLength);
333 c = 0;
334 p += sizeof(struct uac3_cluster_header_descriptor);
335
336 while (((p - (void *)cluster) < len) && (c < channels)) {
337 struct uac3_cluster_segment_descriptor *cs_desc = p;
338 u16 cs_len;
339 u8 cs_type;
340
341 cs_len = le16_to_cpu(cs_desc->wLength);
342 cs_type = cs_desc->bSegmentType;
343
344 if (cs_type == UAC3_CHANNEL_INFORMATION) {
345 struct uac3_cluster_information_segment_descriptor *is = p;
346 unsigned char map;
347
348 /*
349 * TODO: this conversion is not complete, update it
350 * after adding UAC3 values to asound.h
351 */
352 switch (is->bChPurpose) {
353 case UAC3_CH_MONO:
354 map = SNDRV_CHMAP_MONO;
355 break;
356 case UAC3_CH_LEFT:
357 case UAC3_CH_FRONT_LEFT:
358 case UAC3_CH_HEADPHONE_LEFT:
359 map = SNDRV_CHMAP_FL;
360 break;
361 case UAC3_CH_RIGHT:
362 case UAC3_CH_FRONT_RIGHT:
363 case UAC3_CH_HEADPHONE_RIGHT:
364 map = SNDRV_CHMAP_FR;
365 break;
366 case UAC3_CH_FRONT_CENTER:
367 map = SNDRV_CHMAP_FC;
368 break;
369 case UAC3_CH_FRONT_LEFT_OF_CENTER:
370 map = SNDRV_CHMAP_FLC;
371 break;
372 case UAC3_CH_FRONT_RIGHT_OF_CENTER:
373 map = SNDRV_CHMAP_FRC;
374 break;
375 case UAC3_CH_SIDE_LEFT:
376 map = SNDRV_CHMAP_SL;
377 break;
378 case UAC3_CH_SIDE_RIGHT:
379 map = SNDRV_CHMAP_SR;
380 break;
381 case UAC3_CH_BACK_LEFT:
382 map = SNDRV_CHMAP_RL;
383 break;
384 case UAC3_CH_BACK_RIGHT:
385 map = SNDRV_CHMAP_RR;
386 break;
387 case UAC3_CH_BACK_CENTER:
388 map = SNDRV_CHMAP_RC;
389 break;
390 case UAC3_CH_BACK_LEFT_OF_CENTER:
391 map = SNDRV_CHMAP_RLC;
392 break;
393 case UAC3_CH_BACK_RIGHT_OF_CENTER:
394 map = SNDRV_CHMAP_RRC;
395 break;
396 case UAC3_CH_TOP_CENTER:
397 map = SNDRV_CHMAP_TC;
398 break;
399 case UAC3_CH_TOP_FRONT_LEFT:
400 map = SNDRV_CHMAP_TFL;
401 break;
402 case UAC3_CH_TOP_FRONT_RIGHT:
403 map = SNDRV_CHMAP_TFR;
404 break;
405 case UAC3_CH_TOP_FRONT_CENTER:
406 map = SNDRV_CHMAP_TFC;
407 break;
408 case UAC3_CH_TOP_FRONT_LOC:
409 map = SNDRV_CHMAP_TFLC;
410 break;
411 case UAC3_CH_TOP_FRONT_ROC:
412 map = SNDRV_CHMAP_TFRC;
413 break;
414 case UAC3_CH_TOP_SIDE_LEFT:
415 map = SNDRV_CHMAP_TSL;
416 break;
417 case UAC3_CH_TOP_SIDE_RIGHT:
418 map = SNDRV_CHMAP_TSR;
419 break;
420 case UAC3_CH_TOP_BACK_LEFT:
421 map = SNDRV_CHMAP_TRL;
422 break;
423 case UAC3_CH_TOP_BACK_RIGHT:
424 map = SNDRV_CHMAP_TRR;
425 break;
426 case UAC3_CH_TOP_BACK_CENTER:
427 map = SNDRV_CHMAP_TRC;
428 break;
429 case UAC3_CH_BOTTOM_CENTER:
430 map = SNDRV_CHMAP_BC;
431 break;
432 case UAC3_CH_LOW_FREQUENCY_EFFECTS:
433 map = SNDRV_CHMAP_LFE;
434 break;
435 case UAC3_CH_LFE_LEFT:
436 map = SNDRV_CHMAP_LLFE;
437 break;
438 case UAC3_CH_LFE_RIGHT:
439 map = SNDRV_CHMAP_RLFE;
440 break;
441 case UAC3_CH_RELATIONSHIP_UNDEFINED:
442 default:
443 map = SNDRV_CHMAP_UNKNOWN;
444 break;
445 }
446 chmap->map[c++] = map;
447 }
448 p += cs_len;
449 }
450
451 if (channels < c)
452 pr_err("%s: channel number mismatch\n", __func__);
453
454 chmap->channels = channels;
455
456 for (; c < channels; c++)
457 chmap->map[c] = SNDRV_CHMAP_UNKNOWN;
458
459 return chmap;
460}
461
314/* 462/*
315 * add this endpoint to the chip instance. 463 * add this endpoint to the chip instance.
316 * if a stream with the same endpoint already exists, append to it. 464 * if a stream with the same endpoint already exists, append to it.
@@ -461,10 +609,11 @@ snd_usb_find_input_terminal_descriptor(struct usb_host_interface *ctrl_iface,
461 return NULL; 609 return NULL;
462} 610}
463 611
464static struct uac2_output_terminal_descriptor * 612static void *
465 snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface, 613snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface,
466 int terminal_id) 614 int terminal_id)
467{ 615{
616 /* OK to use with both UAC2 and UAC3 */
468 struct uac2_output_terminal_descriptor *term = NULL; 617 struct uac2_output_terminal_descriptor *term = NULL;
469 618
470 while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, 619 while ((term = snd_usb_find_csint_desc(ctrl_iface->extra,
@@ -484,10 +633,12 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
484 struct usb_host_interface *alts; 633 struct usb_host_interface *alts;
485 struct usb_interface_descriptor *altsd; 634 struct usb_interface_descriptor *altsd;
486 int i, altno, err, stream; 635 int i, altno, err, stream;
487 unsigned int format = 0, num_channels = 0; 636 u64 format = 0;
637 unsigned int num_channels = 0;
488 struct audioformat *fp = NULL; 638 struct audioformat *fp = NULL;
489 int num, protocol, clock = 0; 639 int num, protocol, clock = 0;
490 struct uac_format_type_i_continuous_descriptor *fmt; 640 struct uac_format_type_i_continuous_descriptor *fmt = NULL;
641 struct snd_pcm_chmap_elem *chmap_v3 = NULL;
491 unsigned int chconfig; 642 unsigned int chconfig;
492 643
493 dev = chip->dev; 644 dev = chip->dev;
@@ -624,38 +775,158 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
624 iface_no, altno, as->bTerminalLink); 775 iface_no, altno, as->bTerminalLink);
625 continue; 776 continue;
626 } 777 }
627 }
628 778
629 /* get format type */ 779 case UAC_VERSION_3: {
630 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE); 780 struct uac3_input_terminal_descriptor *input_term;
631 if (!fmt) { 781 struct uac3_output_terminal_descriptor *output_term;
782 struct uac3_as_header_descriptor *as;
783 struct uac3_cluster_header_descriptor *cluster;
784 struct uac3_hc_descriptor_header hc_header;
785 u16 cluster_id, wLength;
786
787 as = snd_usb_find_csint_desc(alts->extra,
788 alts->extralen,
789 NULL, UAC_AS_GENERAL);
790
791 if (!as) {
792 dev_err(&dev->dev,
793 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
794 iface_no, altno);
795 continue;
796 }
797
798 if (as->bLength < sizeof(*as)) {
799 dev_err(&dev->dev,
800 "%u:%d : invalid UAC_AS_GENERAL desc\n",
801 iface_no, altno);
802 continue;
803 }
804
805 cluster_id = le16_to_cpu(as->wClusterDescrID);
806 if (!cluster_id) {
807 dev_err(&dev->dev,
808 "%u:%d : no cluster descriptor\n",
809 iface_no, altno);
810 continue;
811 }
812
813 /*
814 * Get number of channels and channel map through
815 * High Capability Cluster Descriptor
816 *
817 * First step: get High Capability header and
818 * read size of Cluster Descriptor
819 */
820 err = snd_usb_ctl_msg(chip->dev,
821 usb_rcvctrlpipe(chip->dev, 0),
822 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
823 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
824 cluster_id,
825 snd_usb_ctrl_intf(chip),
826 &hc_header, sizeof(hc_header));
827 if (err < 0)
828 return err;
829 else if (err != sizeof(hc_header)) {
830 dev_err(&dev->dev,
831 "%u:%d : can't get High Capability descriptor\n",
832 iface_no, altno);
833 return -EIO;
834 }
835
836 /*
837 * Second step: allocate needed amount of memory
838 * and request Cluster Descriptor
839 */
840 wLength = le16_to_cpu(hc_header.wLength);
841 cluster = kzalloc(wLength, GFP_KERNEL);
842 if (!cluster)
843 return -ENOMEM;
844 err = snd_usb_ctl_msg(chip->dev,
845 usb_rcvctrlpipe(chip->dev, 0),
846 UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR,
847 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
848 cluster_id,
849 snd_usb_ctrl_intf(chip),
850 cluster, wLength);
851 if (err < 0) {
852 kfree(cluster);
853 return err;
854 } else if (err != wLength) {
855 dev_err(&dev->dev,
856 "%u:%d : can't get Cluster Descriptor\n",
857 iface_no, altno);
858 kfree(cluster);
859 return -EIO;
860 }
861
862 num_channels = cluster->bNrChannels;
863 chmap_v3 = convert_chmap_v3(cluster);
864
865 kfree(cluster);
866
867 format = le64_to_cpu(as->bmFormats);
868
869 /* lookup the terminal associated to this interface
870 * to extract the clock */
871 input_term = snd_usb_find_input_terminal_descriptor(
872 chip->ctrl_intf,
873 as->bTerminalLink);
874
875 if (input_term) {
876 clock = input_term->bCSourceID;
877 break;
878 }
879
880 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
881 as->bTerminalLink);
882 if (output_term) {
883 clock = output_term->bCSourceID;
884 break;
885 }
886
632 dev_err(&dev->dev, 887 dev_err(&dev->dev,
633 "%u:%d : no UAC_FORMAT_TYPE desc\n", 888 "%u:%d : bogus bTerminalLink %d\n",
634 iface_no, altno); 889 iface_no, altno, as->bTerminalLink);
635 continue; 890 continue;
636 } 891 }
637 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) ||
638 ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) {
639 dev_err(&dev->dev,
640 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
641 iface_no, altno);
642 continue;
643 } 892 }
644 893
645 /* 894 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
646 * Blue Microphones workaround: The last altsetting is identical 895 /* get format type */
647 * with the previous one, except for a larger packet size, but 896 fmt = snd_usb_find_csint_desc(alts->extra,
648 * is actually a mislabeled two-channel setting; ignore it. 897 alts->extralen,
649 */ 898 NULL, UAC_FORMAT_TYPE);
650 if (fmt->bNrChannels == 1 && 899 if (!fmt) {
651 fmt->bSubframeSize == 2 && 900 dev_err(&dev->dev,
652 altno == 2 && num == 3 && 901 "%u:%d : no UAC_FORMAT_TYPE desc\n",
653 fp && fp->altsetting == 1 && fp->channels == 1 && 902 iface_no, altno);
654 fp->formats == SNDRV_PCM_FMTBIT_S16_LE && 903 continue;
655 protocol == UAC_VERSION_1 && 904 }
656 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 905 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8))
906 || ((protocol == UAC_VERSION_2) &&
907 (fmt->bLength < 6))) {
908 dev_err(&dev->dev,
909 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
910 iface_no, altno);
911 continue;
912 }
913
914 /*
915 * Blue Microphones workaround: The last altsetting is
916 * identical with the previous one, except for a larger
917 * packet size, but is actually a mislabeled two-channel
918 * setting; ignore it.
919 */
920 if (fmt->bNrChannels == 1 &&
921 fmt->bSubframeSize == 2 &&
922 altno == 2 && num == 3 &&
923 fp && fp->altsetting == 1 && fp->channels == 1 &&
924 fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
925 protocol == UAC_VERSION_1 &&
926 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
657 fp->maxpacksize * 2) 927 fp->maxpacksize * 2)
658 continue; 928 continue;
929 }
659 930
660 fp = kzalloc(sizeof(*fp), GFP_KERNEL); 931 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
661 if (!fp) 932 if (!fp)
@@ -681,17 +952,39 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
681 snd_usb_audioformat_attributes_quirk(chip, fp, stream); 952 snd_usb_audioformat_attributes_quirk(chip, fp, stream);
682 953
683 /* ok, let's parse further... */ 954 /* ok, let's parse further... */
684 if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream) < 0) { 955 if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) {
685 kfree(fp->rate_table); 956 if (snd_usb_parse_audio_format(chip, fp, format,
686 kfree(fp); 957 fmt, stream) < 0) {
687 fp = NULL; 958 kfree(fp->rate_table);
688 continue; 959 kfree(fp);
960 fp = NULL;
961 continue;
962 }
963 } else {
964 struct uac3_as_header_descriptor *as;
965
966 as = snd_usb_find_csint_desc(alts->extra,
967 alts->extralen,
968 NULL, UAC_AS_GENERAL);
969
970 if (snd_usb_parse_audio_format_v3(chip, fp, as,
971 stream) < 0) {
972 kfree(fp->rate_table);
973 kfree(fp);
974 fp = NULL;
975 continue;
976 }
689 } 977 }
690 978
691 /* Create chmap */ 979 /* Create chmap */
692 if (fp->channels != num_channels) 980 if (fp->channels != num_channels)
693 chconfig = 0; 981 chconfig = 0;
694 fp->chmap = convert_chmap(fp->channels, chconfig, protocol); 982
983 if (protocol == UAC_VERSION_3)
984 fp->chmap = chmap_v3;
985 else
986 fp->chmap = convert_chmap(fp->channels, chconfig,
987 protocol);
695 988
696 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint); 989 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint);
697 err = snd_usb_add_audio_stream(chip, stream, fp); 990 err = snd_usb_add_audio_stream(chip, stream, fp);