Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ruslan Bilovol and committed by
Takashi Iwai
9a2fe9b8 ceb18f51

+1244 -192
+2 -2
include/linux/usb/audio-v2.h
··· 34 34 * 35 35 */ 36 36 37 - static inline bool uac2_control_is_readable(u32 bmControls, u8 control) 37 + static inline bool uac_v2v3_control_is_readable(u32 bmControls, u8 control) 38 38 { 39 39 return (bmControls >> (control * 2)) & 0x1; 40 40 } 41 41 42 - static inline bool uac2_control_is_writeable(u32 bmControls, u8 control) 42 + static inline bool uac_v2v3_control_is_writeable(u32 bmControls, u8 control) 43 43 { 44 44 return (bmControls >> (control * 2)) & 0x2; 45 45 }
+395
include/linux/usb/audio-v3.h
··· 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 */ 20 + struct 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 */ 28 + struct 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 */ 37 + struct 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 */ 44 + struct 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 */ 50 + struct 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 */ 59 + struct 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 */ 72 + struct 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 */ 88 + struct 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 */ 104 + struct 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) \ 120 + struct 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 */ 131 + struct 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 */ 149 + struct 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 */ 160 + struct 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 */ 171 + struct 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) \ 185 + struct 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 */ 198 + struct 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 */ 215 + struct 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 */ 225 + struct 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 */
+1
include/uapi/linux/usb/audio.h
··· 27 27 /* bInterfaceProtocol values to denote the version of the standard used */ 28 28 #define UAC_VERSION_1 0x00 29 29 #define UAC_VERSION_2 0x20 30 + #define UAC_VERSION_3 0x30 30 31 31 32 /* A.2 Audio Interface Subclass Codes */ 32 33 #define USB_SUBCLASS_AUDIOCONTROL 0x01
+5 -2
sound/usb/card.c
··· 7 7 * Alan Cox (alan@lxorguk.ukuu.org.uk) 8 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 12 * This program is free software; you can redistribute it and/or modify 12 13 * it under the terms of the GNU General Public License as published by ··· 45 44 #include <linux/mutex.h> 46 45 #include <linux/usb/audio.h> 47 46 #include <linux/usb/audio-v2.h> 47 + #include <linux/usb/audio-v3.h> 48 48 #include <linux/module.h> 49 49 50 50 #include <sound/control.h> ··· 283 281 break; 284 282 } 285 283 286 - case UAC_VERSION_2: { 284 + case UAC_VERSION_2: 285 + case UAC_VERSION_3: { 287 286 struct usb_interface_assoc_descriptor *assoc = 288 287 usb_ifnum_to_if(dev, ctrlif)->intf_assoc; 289 288 ··· 304 301 } 305 302 306 303 if (!assoc) { 307 - dev_err(&dev->dev, "Audio class v2 interfaces need an interface association\n"); 304 + dev_err(&dev->dev, "Audio class v2/v3 interfaces need an interface association\n"); 308 305 return -EINVAL; 309 306 } 310 307
+1 -1
sound/usb/card.h
··· 22 22 unsigned char endpoint; /* endpoint */ 23 23 unsigned char ep_attr; /* endpoint attributes */ 24 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 26 unsigned int maxpacksize; /* max. packet size */ 27 27 unsigned int rates; /* rate bitmasks */ 28 28 unsigned int rate_min, rate_max; /* min/max rates */
+202 -24
sound/usb/clock.c
··· 23 23 #include <linux/usb.h> 24 24 #include <linux/usb/audio.h> 25 25 #include <linux/usb/audio-v2.h> 26 + #include <linux/usb/audio-v3.h> 26 27 27 28 #include <sound/core.h> 28 29 #include <sound/info.h> ··· 51 50 return NULL; 52 51 } 53 52 53 + static struct uac3_clock_source_descriptor * 54 + snd_usb_find_clock_source_v3(struct usb_host_interface *ctrl_iface, 55 + int clock_id) 56 + { 57 + struct uac3_clock_source_descriptor *cs = NULL; 58 + 59 + while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, 60 + ctrl_iface->extralen, 61 + cs, UAC3_CLOCK_SOURCE))) { 62 + if (cs->bClockID == clock_id) 63 + return cs; 64 + } 65 + 66 + return NULL; 67 + } 68 + 54 69 static struct uac_clock_selector_descriptor * 55 70 snd_usb_find_clock_selector(struct usb_host_interface *ctrl_iface, 56 71 int clock_id) ··· 86 69 return NULL; 87 70 } 88 71 72 + static struct uac3_clock_selector_descriptor * 73 + snd_usb_find_clock_selector_v3(struct usb_host_interface *ctrl_iface, 74 + int clock_id) 75 + { 76 + struct uac3_clock_selector_descriptor *cs = NULL; 77 + 78 + while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, 79 + ctrl_iface->extralen, 80 + cs, UAC3_CLOCK_SELECTOR))) { 81 + if (cs->bClockID == clock_id) 82 + return cs; 83 + } 84 + 85 + return NULL; 86 + } 87 + 89 88 static struct uac_clock_multiplier_descriptor * 90 89 snd_usb_find_clock_multiplier(struct usb_host_interface *ctrl_iface, 91 90 int clock_id) ··· 112 79 ctrl_iface->extralen, 113 80 cs, UAC2_CLOCK_MULTIPLIER))) { 114 81 if (cs->bLength >= sizeof(*cs) && cs->bClockID == clock_id) 82 + return cs; 83 + } 84 + 85 + return NULL; 86 + } 87 + 88 + static struct uac3_clock_multiplier_descriptor * 89 + snd_usb_find_clock_multiplier_v3(struct usb_host_interface *ctrl_iface, 90 + int clock_id) 91 + { 92 + struct uac3_clock_multiplier_descriptor *cs = NULL; 93 + 94 + while ((cs = snd_usb_find_csint_desc(ctrl_iface->extra, 95 + ctrl_iface->extralen, 96 + cs, UAC3_CLOCK_MULTIPLIER))) { 97 + if (cs->bClockID == clock_id) 115 98 return cs; 116 99 } 117 100 ··· 187 138 return ret; 188 139 } 189 140 190 - static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id) 141 + static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, 142 + int protocol, 143 + int source_id) 191 144 { 192 145 int err; 193 146 unsigned char data; 194 147 struct usb_device *dev = chip->dev; 195 - struct uac_clock_source_descriptor *cs_desc = 196 - snd_usb_find_clock_source(chip->ctrl_intf, source_id); 148 + u32 bmControls; 197 149 198 - if (!cs_desc) 199 - return 0; 150 + if (protocol == UAC_VERSION_3) { 151 + struct uac3_clock_source_descriptor *cs_desc = 152 + snd_usb_find_clock_source_v3(chip->ctrl_intf, source_id); 153 + 154 + if (!cs_desc) 155 + return 0; 156 + bmControls = le32_to_cpu(cs_desc->bmControls); 157 + } else { /* UAC_VERSION_1/2 */ 158 + struct uac_clock_source_descriptor *cs_desc = 159 + snd_usb_find_clock_source(chip->ctrl_intf, source_id); 160 + 161 + if (!cs_desc) 162 + return 0; 163 + bmControls = cs_desc->bmControls; 164 + } 200 165 201 166 /* If a clock source can't tell us whether it's valid, we assume it is */ 202 - if (!uac2_control_is_readable(cs_desc->bmControls, 167 + if (!uac_v2v3_control_is_readable(bmControls, 203 168 UAC2_CS_CONTROL_CLOCK_VALID - 1)) 204 169 return 1; 205 170 ··· 233 170 return !!data; 234 171 } 235 172 236 - static int __uac_clock_find_source(struct snd_usb_audio *chip, 237 - int entity_id, unsigned long *visited, 238 - bool validate) 173 + static int __uac_clock_find_source(struct snd_usb_audio *chip, int entity_id, 174 + unsigned long *visited, bool validate) 239 175 { 240 176 struct uac_clock_source_descriptor *source; 241 177 struct uac_clock_selector_descriptor *selector; ··· 253 191 source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id); 254 192 if (source) { 255 193 entity_id = source->bClockID; 256 - if (validate && !uac_clock_source_is_valid(chip, entity_id)) { 194 + if (validate && !uac_clock_source_is_valid(chip, UAC_VERSION_2, 195 + entity_id)) { 257 196 usb_audio_err(chip, 258 197 "clock source %d is not valid, cannot use\n", 259 198 entity_id); ··· 323 260 return -EINVAL; 324 261 } 325 262 263 + static int __uac3_clock_find_source(struct snd_usb_audio *chip, int entity_id, 264 + unsigned long *visited, bool validate) 265 + { 266 + struct uac3_clock_source_descriptor *source; 267 + struct uac3_clock_selector_descriptor *selector; 268 + struct uac3_clock_multiplier_descriptor *multiplier; 269 + 270 + entity_id &= 0xff; 271 + 272 + if (test_and_set_bit(entity_id, visited)) { 273 + usb_audio_warn(chip, 274 + "%s(): recursive clock topology detected, id %d.\n", 275 + __func__, entity_id); 276 + return -EINVAL; 277 + } 278 + 279 + /* first, see if the ID we're looking for is a clock source already */ 280 + source = snd_usb_find_clock_source_v3(chip->ctrl_intf, entity_id); 281 + if (source) { 282 + entity_id = source->bClockID; 283 + if (validate && !uac_clock_source_is_valid(chip, UAC_VERSION_3, 284 + entity_id)) { 285 + usb_audio_err(chip, 286 + "clock source %d is not valid, cannot use\n", 287 + entity_id); 288 + return -ENXIO; 289 + } 290 + return entity_id; 291 + } 292 + 293 + selector = snd_usb_find_clock_selector_v3(chip->ctrl_intf, entity_id); 294 + if (selector) { 295 + int ret, i, cur; 296 + 297 + /* the entity ID we are looking for is a selector. 298 + * find out what it currently selects */ 299 + ret = uac_clock_selector_get_val(chip, selector->bClockID); 300 + if (ret < 0) 301 + return ret; 302 + 303 + /* Selector values are one-based */ 304 + 305 + if (ret > selector->bNrInPins || ret < 1) { 306 + usb_audio_err(chip, 307 + "%s(): selector reported illegal value, id %d, ret %d\n", 308 + __func__, selector->bClockID, ret); 309 + 310 + return -EINVAL; 311 + } 312 + 313 + cur = ret; 314 + ret = __uac3_clock_find_source(chip, selector->baCSourceID[ret - 1], 315 + visited, validate); 316 + if (!validate || ret > 0 || !chip->autoclock) 317 + return ret; 318 + 319 + /* The current clock source is invalid, try others. */ 320 + for (i = 1; i <= selector->bNrInPins; i++) { 321 + int err; 322 + 323 + if (i == cur) 324 + continue; 325 + 326 + ret = __uac3_clock_find_source(chip, selector->baCSourceID[i - 1], 327 + visited, true); 328 + if (ret < 0) 329 + continue; 330 + 331 + err = uac_clock_selector_set_val(chip, entity_id, i); 332 + if (err < 0) 333 + continue; 334 + 335 + usb_audio_info(chip, 336 + "found and selected valid clock source %d\n", 337 + ret); 338 + return ret; 339 + } 340 + 341 + return -ENXIO; 342 + } 343 + 344 + /* FIXME: multipliers only act as pass-thru element for now */ 345 + multiplier = snd_usb_find_clock_multiplier_v3(chip->ctrl_intf, 346 + entity_id); 347 + if (multiplier) 348 + return __uac3_clock_find_source(chip, multiplier->bCSourceID, 349 + visited, validate); 350 + 351 + return -EINVAL; 352 + } 353 + 326 354 /* 327 355 * For all kinds of sample rate settings and other device queries, 328 356 * the clock source (end-leaf) must be used. However, clock selectors, ··· 425 271 * 426 272 * Returns the clock source UnitID (>=0) on success, or an error. 427 273 */ 428 - int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id, 429 - bool validate) 274 + int snd_usb_clock_find_source(struct snd_usb_audio *chip, int protocol, 275 + int entity_id, bool validate) 430 276 { 431 277 DECLARE_BITMAP(visited, 256); 432 278 memset(visited, 0, sizeof(visited)); 433 - return __uac_clock_find_source(chip, entity_id, visited, validate); 279 + 280 + switch (protocol) { 281 + case UAC_VERSION_2: 282 + return __uac_clock_find_source(chip, entity_id, visited, 283 + validate); 284 + case UAC_VERSION_3: 285 + return __uac3_clock_find_source(chip, entity_id, visited, 286 + validate); 287 + default: 288 + return -EINVAL; 289 + } 434 290 } 435 291 436 292 static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, ··· 499 335 return 0; 500 336 } 501 337 502 - static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface, 338 + static int get_sample_rate_v2v3(struct snd_usb_audio *chip, int iface, 503 339 int altsetting, int clock) 504 340 { 505 341 struct usb_device *dev = chip->dev; ··· 512 348 snd_usb_ctrl_intf(chip) | (clock << 8), 513 349 &data, sizeof(data)); 514 350 if (err < 0) { 515 - dev_warn(&dev->dev, "%d:%d: cannot get freq (v2): err %d\n", 351 + dev_warn(&dev->dev, "%d:%d: cannot get freq (v2/v3): err %d\n", 516 352 iface, altsetting, err); 517 353 return 0; 518 354 } ··· 520 356 return le32_to_cpu(data); 521 357 } 522 358 523 - static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, 359 + static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface, 524 360 struct usb_host_interface *alts, 525 361 struct audioformat *fmt, int rate) 526 362 { ··· 529 365 int err, cur_rate, prev_rate; 530 366 int clock; 531 367 bool writeable; 532 - struct uac_clock_source_descriptor *cs_desc; 368 + u32 bmControls; 533 369 534 - clock = snd_usb_clock_find_source(chip, fmt->clock, true); 370 + clock = snd_usb_clock_find_source(chip, fmt->protocol, 371 + fmt->clock, true); 535 372 if (clock < 0) 536 373 return clock; 537 374 538 - prev_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); 375 + prev_rate = get_sample_rate_v2v3(chip, iface, fmt->altsetting, clock); 539 376 if (prev_rate == rate) 540 377 return 0; 541 378 542 - cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock); 543 - writeable = uac2_control_is_writeable(cs_desc->bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1); 379 + if (fmt->protocol == UAC_VERSION_3) { 380 + struct uac3_clock_source_descriptor *cs_desc; 381 + 382 + cs_desc = snd_usb_find_clock_source_v3(chip->ctrl_intf, clock); 383 + bmControls = le32_to_cpu(cs_desc->bmControls); 384 + } else { 385 + struct uac_clock_source_descriptor *cs_desc; 386 + 387 + cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock); 388 + bmControls = cs_desc->bmControls; 389 + } 390 + 391 + writeable = uac_v2v3_control_is_writeable(bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1); 544 392 if (writeable) { 545 393 data = cpu_to_le32(rate); 546 394 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, ··· 562 386 &data, sizeof(data)); 563 387 if (err < 0) { 564 388 usb_audio_err(chip, 565 - "%d:%d: cannot set freq %d (v2): err %d\n", 389 + "%d:%d: cannot set freq %d (v2/v3): err %d\n", 566 390 iface, fmt->altsetting, rate, err); 567 391 return err; 568 392 } 569 393 570 - cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); 394 + cur_rate = get_sample_rate_v2v3(chip, iface, 395 + fmt->altsetting, clock); 571 396 } else { 572 397 cur_rate = prev_rate; 573 398 } ··· 607 430 return set_sample_rate_v1(chip, iface, alts, fmt, rate); 608 431 609 432 case UAC_VERSION_2: 610 - return set_sample_rate_v2(chip, iface, alts, fmt, rate); 433 + case UAC_VERSION_3: 434 + return set_sample_rate_v2v3(chip, iface, alts, fmt, rate); 611 435 } 612 436 } 613 437
+2 -2
sound/usb/clock.h
··· 6 6 struct usb_host_interface *alts, 7 7 struct audioformat *fmt, int rate); 8 8 9 - int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id, 10 - bool validate); 9 + int snd_usb_clock_find_source(struct snd_usb_audio *chip, int protocol, 10 + int entity_id, bool validate); 11 11 12 12 #endif /* __USBAUDIO_CLOCK_H */
+75 -16
sound/usb/format.c
··· 20 20 #include <linux/usb.h> 21 21 #include <linux/usb/audio.h> 22 22 #include <linux/usb/audio-v2.h> 23 + #include <linux/usb/audio-v3.h> 23 24 24 25 #include <sound/core.h> 25 26 #include <sound/pcm.h> ··· 40 39 * @dev: usb device 41 40 * @fp: audioformat record 42 41 * @format: the format tag (wFormatTag) 43 - * @fmt: the format type descriptor 42 + * @fmt: the format type descriptor (v1/v2) or AudioStreaming descriptor (v3) 44 43 */ 45 44 static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, 46 45 struct audioformat *fp, 47 - unsigned int format, void *_fmt) 46 + u64 format, void *_fmt) 48 47 { 49 48 int sample_width, sample_bytes; 50 49 u64 pcm_formats = 0; ··· 65 64 sample_bytes = fmt->bSubslotSize; 66 65 67 66 if (format & UAC2_FORMAT_TYPE_I_RAW_DATA) 67 + pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL; 68 + 69 + format <<= 1; 70 + break; 71 + } 72 + case UAC_VERSION_3: { 73 + struct uac3_as_header_descriptor *as = _fmt; 74 + 75 + sample_width = as->bBitResolution; 76 + sample_bytes = as->bSubslotSize; 77 + 78 + if (format & UAC3_FORMAT_TYPE_I_RAW_DATA) 68 79 pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL; 69 80 70 81 format <<= 1; ··· 150 137 } 151 138 if (format & ~0x3f) { 152 139 usb_audio_info(chip, 153 - "%u:%d : unsupported format bits %#x\n", 140 + "%u:%d : unsupported format bits %#llx\n", 154 141 fp->iface, fp->altsetting, format); 155 142 } 156 143 ··· 294 281 295 282 /* 296 283 * parse the format descriptor and stores the possible sample rates 297 - * on the audioformat table (audio class v2). 284 + * on the audioformat table (audio class v2 and v3). 298 285 */ 299 - static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, 286 + static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip, 300 287 struct audioformat *fp) 301 288 { 302 289 struct usb_device *dev = chip->dev; 303 290 unsigned char tmp[2], *data; 304 291 int nr_triplets, data_size, ret = 0; 305 - int clock = snd_usb_clock_find_source(chip, fp->clock, false); 292 + int clock = snd_usb_clock_find_source(chip, fp->protocol, 293 + fp->clock, false); 306 294 307 295 if (clock < 0) { 308 296 dev_err(&dev->dev, ··· 382 368 * parse the format type I and III descriptors 383 369 */ 384 370 static int parse_audio_format_i(struct snd_usb_audio *chip, 385 - struct audioformat *fp, unsigned int format, 386 - struct uac_format_type_i_continuous_descriptor *fmt) 371 + struct audioformat *fp, u64 format, 372 + void *_fmt) 387 373 { 388 374 snd_pcm_format_t pcm_format; 375 + unsigned int fmt_type; 389 376 int ret; 390 377 391 - if (fmt->bFormatType == UAC_FORMAT_TYPE_III) { 378 + switch (fp->protocol) { 379 + default: 380 + case UAC_VERSION_1: 381 + case UAC_VERSION_2: { 382 + struct uac_format_type_i_continuous_descriptor *fmt = _fmt; 383 + 384 + fmt_type = fmt->bFormatType; 385 + break; 386 + } 387 + case UAC_VERSION_3: { 388 + /* fp->fmt_type is already set in this case */ 389 + fmt_type = fp->fmt_type; 390 + break; 391 + } 392 + } 393 + 394 + if (fmt_type == UAC_FORMAT_TYPE_III) { 392 395 /* FIXME: the format type is really IECxxx 393 396 * but we give normal PCM format to get the existing 394 397 * apps working... ··· 424 393 } 425 394 fp->formats = pcm_format_to_bits(pcm_format); 426 395 } else { 427 - fp->formats = parse_audio_format_i_type(chip, fp, format, fmt); 396 + fp->formats = parse_audio_format_i_type(chip, fp, format, _fmt); 428 397 if (!fp->formats) 429 398 return -EINVAL; 430 399 } ··· 436 405 */ 437 406 switch (fp->protocol) { 438 407 default: 439 - case UAC_VERSION_1: 408 + case UAC_VERSION_1: { 409 + struct uac_format_type_i_continuous_descriptor *fmt = _fmt; 410 + 440 411 fp->channels = fmt->bNrChannels; 441 412 ret = parse_audio_format_rates_v1(chip, fp, (unsigned char *) fmt, 7); 442 413 break; 414 + } 443 415 case UAC_VERSION_2: 416 + case UAC_VERSION_3: { 444 417 /* fp->channels is already set in this case */ 445 - ret = parse_audio_format_rates_v2(chip, fp); 418 + ret = parse_audio_format_rates_v2v3(chip, fp); 446 419 break; 420 + } 447 421 } 448 422 449 423 if (fp->channels < 1) { ··· 466 430 */ 467 431 static int parse_audio_format_ii(struct snd_usb_audio *chip, 468 432 struct audioformat *fp, 469 - int format, void *_fmt) 433 + u64 format, void *_fmt) 470 434 { 471 435 int brate, framesize, ret; 472 436 ··· 481 445 break; 482 446 default: 483 447 usb_audio_info(chip, 484 - "%u:%d : unknown format tag %#x is detected. processed as MPEG.\n", 448 + "%u:%d : unknown format tag %#llx is detected. processed as MPEG.\n", 485 449 fp->iface, fp->altsetting, format); 486 450 fp->formats = SNDRV_PCM_FMTBIT_MPEG; 487 451 break; ··· 506 470 framesize = le16_to_cpu(fmt->wSamplesPerFrame); 507 471 usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 508 472 fp->frame_size = framesize; 509 - ret = parse_audio_format_rates_v2(chip, fp); 473 + ret = parse_audio_format_rates_v2v3(chip, fp); 510 474 break; 511 475 } 512 476 } ··· 515 479 } 516 480 517 481 int snd_usb_parse_audio_format(struct snd_usb_audio *chip, 518 - struct audioformat *fp, unsigned int format, 482 + struct audioformat *fp, u64 format, 519 483 struct uac_format_type_i_continuous_descriptor *fmt, 520 484 int stream) 521 485 { ··· 556 520 return 0; 557 521 } 558 522 523 + int snd_usb_parse_audio_format_v3(struct snd_usb_audio *chip, 524 + struct audioformat *fp, 525 + struct uac3_as_header_descriptor *as, 526 + int stream) 527 + { 528 + u64 format = le64_to_cpu(as->bmFormats); 529 + int err; 530 + 531 + /* 532 + * Type I format bits are D0..D6 533 + * This test works because type IV is not supported 534 + */ 535 + if (format & 0x7f) 536 + fp->fmt_type = UAC_FORMAT_TYPE_I; 537 + else 538 + fp->fmt_type = UAC_FORMAT_TYPE_III; 539 + 540 + err = parse_audio_format_i(chip, fp, format, as); 541 + if (err < 0) 542 + return err; 543 + 544 + return 0; 545 + }
+5 -1
sound/usb/format.h
··· 3 3 #define __USBAUDIO_FORMAT_H 4 4 5 5 int snd_usb_parse_audio_format(struct snd_usb_audio *chip, 6 - struct audioformat *fp, unsigned int format, 6 + struct audioformat *fp, u64 format, 7 7 struct uac_format_type_i_continuous_descriptor *fmt, 8 8 int stream); 9 9 10 + int 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 14 #endif /* __USBAUDIO_FORMAT_H */
+227 -108
sound/usb/mixer.c
··· 51 51 #include <linux/usb.h> 52 52 #include <linux/usb/audio.h> 53 53 #include <linux/usb/audio-v2.h> 54 + #include <linux/usb/audio-v3.h> 54 55 55 56 #include <sound/core.h> 56 57 #include <sound/control.h> ··· 190 189 USB_DT_CS_INTERFACE)) != NULL) { 191 190 if (hdr->bLength >= 4 && 192 191 hdr->bDescriptorSubtype >= UAC_INPUT_TERMINAL && 193 - hdr->bDescriptorSubtype <= UAC2_SAMPLE_RATE_CONVERTER && 192 + hdr->bDescriptorSubtype <= UAC3_SAMPLE_RATE_CONVERTER && 194 193 hdr->bUnitID == unit) 195 194 return hdr; 196 195 } ··· 469 468 470 469 validx += cval->idx_off; 471 470 471 + 472 472 if (cval->head.mixer->protocol == UAC_VERSION_1) { 473 473 val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 474 - } else { /* UAC_VERSION_2 */ 474 + } else { /* UAC_VERSION_2/3 */ 475 475 val_len = uac2_ctl_value_size(cval->val_type); 476 476 477 477 /* FIXME */ ··· 725 723 static int check_input_term(struct mixer_build *state, int id, 726 724 struct usb_audio_term *term) 727 725 { 726 + int protocol = state->mixer->protocol; 728 727 int err; 729 728 void *p1; 730 729 ··· 733 730 while ((p1 = find_audio_control_unit(state, id)) != NULL) { 734 731 unsigned char *hdr = p1; 735 732 term->id = id; 736 - switch (hdr[2]) { 737 - case UAC_INPUT_TERMINAL: 738 - if (state->mixer->protocol == UAC_VERSION_1) { 739 - struct uac_input_terminal_descriptor *d = p1; 740 - term->type = le16_to_cpu(d->wTerminalType); 741 - term->channels = d->bNrChannels; 742 - term->chconfig = le16_to_cpu(d->wChannelConfig); 743 - term->name = d->iTerminal; 744 - } else { /* UAC_VERSION_2 */ 745 - struct uac2_input_terminal_descriptor *d = p1; 733 + 734 + if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) { 735 + switch (hdr[2]) { 736 + case UAC_INPUT_TERMINAL: 737 + if (protocol == UAC_VERSION_1) { 738 + struct uac_input_terminal_descriptor *d = p1; 739 + 740 + term->type = le16_to_cpu(d->wTerminalType); 741 + term->channels = d->bNrChannels; 742 + term->chconfig = le16_to_cpu(d->wChannelConfig); 743 + term->name = d->iTerminal; 744 + } else { /* UAC_VERSION_2 */ 745 + struct uac2_input_terminal_descriptor *d = p1; 746 + 747 + /* call recursively to verify that the 748 + * referenced clock entity is valid */ 749 + err = check_input_term(state, d->bCSourceID, term); 750 + if (err < 0) 751 + return err; 752 + 753 + /* save input term properties after recursion, 754 + * to ensure they are not overriden by the 755 + * recursion calls */ 756 + term->id = id; 757 + term->type = le16_to_cpu(d->wTerminalType); 758 + term->channels = d->bNrChannels; 759 + term->chconfig = le32_to_cpu(d->bmChannelConfig); 760 + term->name = d->iTerminal; 761 + } 762 + return 0; 763 + case UAC_FEATURE_UNIT: { 764 + /* the header is the same for v1 and v2 */ 765 + struct uac_feature_unit_descriptor *d = p1; 766 + 767 + id = d->bSourceID; 768 + break; /* continue to parse */ 769 + } 770 + case UAC_MIXER_UNIT: { 771 + struct uac_mixer_unit_descriptor *d = p1; 772 + 773 + term->type = d->bDescriptorSubtype << 16; /* virtual type */ 774 + term->channels = uac_mixer_unit_bNrChannels(d); 775 + term->chconfig = uac_mixer_unit_wChannelConfig(d, protocol); 776 + term->name = uac_mixer_unit_iMixer(d); 777 + return 0; 778 + } 779 + case UAC_SELECTOR_UNIT: 780 + case UAC2_CLOCK_SELECTOR: { 781 + struct uac_selector_unit_descriptor *d = p1; 782 + /* call recursively to retrieve the channel info */ 783 + err = check_input_term(state, d->baSourceID[0], term); 784 + if (err < 0) 785 + return err; 786 + term->type = d->bDescriptorSubtype << 16; /* virtual type */ 787 + term->id = id; 788 + term->name = uac_selector_unit_iSelector(d); 789 + return 0; 790 + } 791 + case UAC1_PROCESSING_UNIT: 792 + case UAC1_EXTENSION_UNIT: 793 + /* UAC2_PROCESSING_UNIT_V2 */ 794 + /* UAC2_EFFECT_UNIT */ 795 + case UAC2_EXTENSION_UNIT_V2: { 796 + struct uac_processing_unit_descriptor *d = p1; 797 + 798 + if (protocol == UAC_VERSION_2 && 799 + hdr[2] == UAC2_EFFECT_UNIT) { 800 + /* UAC2/UAC1 unit IDs overlap here in an 801 + * uncompatible way. Ignore this unit for now. 802 + */ 803 + return 0; 804 + } 805 + 806 + if (d->bNrInPins) { 807 + id = d->baSourceID[0]; 808 + break; /* continue to parse */ 809 + } 810 + term->type = d->bDescriptorSubtype << 16; /* virtual type */ 811 + term->channels = uac_processing_unit_bNrChannels(d); 812 + term->chconfig = uac_processing_unit_wChannelConfig(d, protocol); 813 + term->name = uac_processing_unit_iProcessing(d, protocol); 814 + return 0; 815 + } 816 + case UAC2_CLOCK_SOURCE: { 817 + struct uac_clock_source_descriptor *d = p1; 818 + 819 + term->type = d->bDescriptorSubtype << 16; /* virtual type */ 820 + term->id = id; 821 + term->name = d->iClockSource; 822 + return 0; 823 + } 824 + default: 825 + return -ENODEV; 826 + } 827 + } else { /* UAC_VERSION_3 */ 828 + switch (hdr[2]) { 829 + case UAC_INPUT_TERMINAL: { 830 + struct uac3_input_terminal_descriptor *d = p1; 746 831 747 832 /* call recursively to verify that the 748 833 * referenced clock entity is valid */ ··· 843 752 * recursion calls */ 844 753 term->id = id; 845 754 term->type = le16_to_cpu(d->wTerminalType); 846 - term->channels = d->bNrChannels; 847 - term->chconfig = le32_to_cpu(d->bmChannelConfig); 848 - term->name = d->iTerminal; 849 - } 850 - return 0; 851 - case UAC_FEATURE_UNIT: { 852 - /* the header is the same for v1 and v2 */ 853 - struct uac_feature_unit_descriptor *d = p1; 854 - id = d->bSourceID; 855 - break; /* continue to parse */ 856 - } 857 - case UAC_MIXER_UNIT: { 858 - struct uac_mixer_unit_descriptor *d = p1; 859 - term->type = d->bDescriptorSubtype << 16; /* virtual type */ 860 - term->channels = uac_mixer_unit_bNrChannels(d); 861 - term->chconfig = uac_mixer_unit_wChannelConfig(d, state->mixer->protocol); 862 - term->name = uac_mixer_unit_iMixer(d); 863 - return 0; 864 - } 865 - case UAC_SELECTOR_UNIT: 866 - case UAC2_CLOCK_SELECTOR: { 867 - struct uac_selector_unit_descriptor *d = p1; 868 - /* call recursively to retrieve the channel info */ 869 - err = check_input_term(state, d->baSourceID[0], term); 870 - if (err < 0) 871 - return err; 872 - term->type = d->bDescriptorSubtype << 16; /* virtual type */ 873 - term->id = id; 874 - term->name = uac_selector_unit_iSelector(d); 875 - return 0; 876 - } 877 - case UAC1_PROCESSING_UNIT: 878 - case UAC1_EXTENSION_UNIT: 879 - /* UAC2_PROCESSING_UNIT_V2 */ 880 - /* UAC2_EFFECT_UNIT */ 881 - case UAC2_EXTENSION_UNIT_V2: { 882 - struct uac_processing_unit_descriptor *d = p1; 883 755 884 - if (state->mixer->protocol == UAC_VERSION_2 && 885 - hdr[2] == UAC2_EFFECT_UNIT) { 886 - /* UAC2/UAC1 unit IDs overlap here in an 887 - * uncompatible way. Ignore this unit for now. 888 - */ 756 + /* REVISIT: UAC3 IT doesn't have channels/cfg */ 757 + term->channels = 0; 758 + term->chconfig = 0; 759 + 760 + term->name = le16_to_cpu(d->wTerminalDescrStr); 889 761 return 0; 890 762 } 763 + case UAC3_FEATURE_UNIT: { 764 + struct uac3_feature_unit_descriptor *d = p1; 891 765 892 - if (d->bNrInPins) { 893 - id = d->baSourceID[0]; 766 + id = d->bSourceID; 894 767 break; /* continue to parse */ 895 768 } 896 - term->type = d->bDescriptorSubtype << 16; /* virtual type */ 897 - term->channels = uac_processing_unit_bNrChannels(d); 898 - term->chconfig = uac_processing_unit_wChannelConfig(d, state->mixer->protocol); 899 - term->name = uac_processing_unit_iProcessing(d, state->mixer->protocol); 900 - return 0; 901 - } 902 - case UAC2_CLOCK_SOURCE: { 903 - struct uac_clock_source_descriptor *d = p1; 904 - term->type = d->bDescriptorSubtype << 16; /* virtual type */ 905 - term->id = id; 906 - term->name = d->iClockSource; 907 - return 0; 908 - } 909 - default: 910 - return -ENODEV; 769 + case UAC3_CLOCK_SOURCE: { 770 + struct uac3_clock_source_descriptor *d = p1; 771 + 772 + term->type = d->bDescriptorSubtype << 16; /* virtual type */ 773 + term->id = id; 774 + term->name = le16_to_cpu(d->wClockSourceStr); 775 + return 0; 776 + } 777 + default: 778 + return -ENODEV; 779 + } 911 780 } 912 781 } 913 782 return -ENODEV; ··· 1474 1423 * The only property of this unit we are interested in is the 1475 1424 * clock source validity. If that isn't readable, just bail out. 1476 1425 */ 1477 - if (!uac2_control_is_readable(hdr->bmControls, 1426 + if (!uac_v2v3_control_is_readable(hdr->bmControls, 1478 1427 ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) 1479 1428 return 0; 1480 1429 ··· 1490 1439 cval->val_type = USB_MIXER_BOOLEAN; 1491 1440 cval->control = UAC2_CS_CONTROL_CLOCK_VALID; 1492 1441 1493 - if (uac2_control_is_writeable(hdr->bmControls, 1442 + if (uac_v2v3_control_is_writeable(hdr->bmControls, 1494 1443 ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) 1495 1444 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); 1496 1445 else { ··· 1553 1502 unitid); 1554 1503 return -EINVAL; 1555 1504 } 1556 - } else { 1505 + } else if (state->mixer->protocol == UAC_VERSION_2) { 1557 1506 struct uac2_feature_unit_descriptor *ftr = _ftr; 1558 1507 if (hdr->bLength < 6) { 1559 1508 usb_audio_err(state->chip, ··· 1567 1516 if (hdr->bLength < 6 + csize) { 1568 1517 usb_audio_err(state->chip, 1569 1518 "unit %u: invalid UAC_FEATURE_UNIT descriptor\n", 1519 + unitid); 1520 + return -EINVAL; 1521 + } 1522 + } else { /* UAC_VERSION_3 */ 1523 + struct uac3_feature_unit_descriptor *ftr = _ftr; 1524 + 1525 + if (hdr->bLength < 7) { 1526 + usb_audio_err(state->chip, 1527 + "unit %u: invalid UAC3_FEATURE_UNIT descriptor\n", 1528 + unitid); 1529 + return -EINVAL; 1530 + } 1531 + csize = 4; 1532 + channels = (ftr->bLength - 7) / 4 - 1; 1533 + bmaControls = ftr->bmaControls; 1534 + if (hdr->bLength < 7 + csize) { 1535 + usb_audio_err(state->chip, 1536 + "unit %u: invalid UAC3_FEATURE_UNIT descriptor\n", 1570 1537 unitid); 1571 1538 return -EINVAL; 1572 1539 } ··· 1646 1577 build_feature_ctl(state, _ftr, 0, i, &iterm, 1647 1578 unitid, 0); 1648 1579 } 1649 - } else { /* UAC_VERSION_2 */ 1580 + } else { /* UAC_VERSION_2/3 */ 1650 1581 for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) { 1651 1582 unsigned int ch_bits = 0; 1652 1583 unsigned int ch_read_only = 0; ··· 1656 1587 1657 1588 mask = snd_usb_combine_bytes(bmaControls + 1658 1589 csize * (j+1), csize); 1659 - if (uac2_control_is_readable(mask, i)) { 1590 + if (uac_v2v3_control_is_readable(mask, i)) { 1660 1591 ch_bits |= (1 << j); 1661 - if (!uac2_control_is_writeable(mask, i)) 1592 + if (!uac_v2v3_control_is_writeable(mask, i)) 1662 1593 ch_read_only |= (1 << j); 1663 1594 } 1664 1595 } ··· 1679 1610 if (ch_bits & 1) 1680 1611 build_feature_ctl(state, _ftr, ch_bits, i, 1681 1612 &iterm, unitid, ch_read_only); 1682 - if (uac2_control_is_readable(master_bits, i)) 1613 + if (uac_v2v3_control_is_readable(master_bits, i)) 1683 1614 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 1684 - !uac2_control_is_writeable(master_bits, i)); 1615 + !uac_v2v3_control_is_writeable(master_bits, i)); 1685 1616 } 1686 1617 } 1687 1618 ··· 2289 2220 static int parse_audio_unit(struct mixer_build *state, int unitid) 2290 2221 { 2291 2222 unsigned char *p1; 2223 + int protocol = state->mixer->protocol; 2292 2224 2293 2225 if (test_and_set_bit(unitid, state->unitbitmap)) 2294 2226 return 0; /* the unit already visited */ ··· 2300 2230 return -EINVAL; 2301 2231 } 2302 2232 2303 - switch (p1[2]) { 2304 - case UAC_INPUT_TERMINAL: 2305 - return 0; /* NOP */ 2306 - case UAC_MIXER_UNIT: 2307 - return parse_audio_mixer_unit(state, unitid, p1); 2308 - case UAC2_CLOCK_SOURCE: 2309 - return parse_clock_source_unit(state, unitid, p1); 2310 - case UAC_SELECTOR_UNIT: 2311 - case UAC2_CLOCK_SELECTOR: 2312 - return parse_audio_selector_unit(state, unitid, p1); 2313 - case UAC_FEATURE_UNIT: 2314 - return parse_audio_feature_unit(state, unitid, p1); 2315 - case UAC1_PROCESSING_UNIT: 2316 - /* UAC2_EFFECT_UNIT has the same value */ 2317 - if (state->mixer->protocol == UAC_VERSION_1) 2318 - return parse_audio_processing_unit(state, unitid, p1); 2319 - else 2320 - return 0; /* FIXME - effect units not implemented yet */ 2321 - case UAC1_EXTENSION_UNIT: 2322 - /* UAC2_PROCESSING_UNIT_V2 has the same value */ 2323 - if (state->mixer->protocol == UAC_VERSION_1) 2233 + if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) { 2234 + switch (p1[2]) { 2235 + case UAC_INPUT_TERMINAL: 2236 + return 0; /* NOP */ 2237 + case UAC_MIXER_UNIT: 2238 + return parse_audio_mixer_unit(state, unitid, p1); 2239 + case UAC2_CLOCK_SOURCE: 2240 + return parse_clock_source_unit(state, unitid, p1); 2241 + case UAC_SELECTOR_UNIT: 2242 + case UAC2_CLOCK_SELECTOR: 2243 + return parse_audio_selector_unit(state, unitid, p1); 2244 + case UAC_FEATURE_UNIT: 2245 + return parse_audio_feature_unit(state, unitid, p1); 2246 + case UAC1_PROCESSING_UNIT: 2247 + /* UAC2_EFFECT_UNIT has the same value */ 2248 + if (protocol == UAC_VERSION_1) 2249 + return parse_audio_processing_unit(state, unitid, p1); 2250 + else 2251 + return 0; /* FIXME - effect units not implemented yet */ 2252 + case UAC1_EXTENSION_UNIT: 2253 + /* UAC2_PROCESSING_UNIT_V2 has the same value */ 2254 + if (protocol == UAC_VERSION_1) 2255 + return parse_audio_extension_unit(state, unitid, p1); 2256 + else /* UAC_VERSION_2 */ 2257 + return parse_audio_processing_unit(state, unitid, p1); 2258 + case UAC2_EXTENSION_UNIT_V2: 2324 2259 return parse_audio_extension_unit(state, unitid, p1); 2325 - else /* UAC_VERSION_2 */ 2260 + default: 2261 + usb_audio_err(state->chip, 2262 + "unit %u: unexpected type 0x%02x\n", unitid, p1[2]); 2263 + return -EINVAL; 2264 + } 2265 + } else { /* UAC_VERSION_3 */ 2266 + switch (p1[2]) { 2267 + case UAC_INPUT_TERMINAL: 2268 + return 0; /* NOP */ 2269 + case UAC3_MIXER_UNIT: 2270 + return parse_audio_mixer_unit(state, unitid, p1); 2271 + case UAC3_CLOCK_SOURCE: 2272 + return parse_clock_source_unit(state, unitid, p1); 2273 + case UAC3_CLOCK_SELECTOR: 2274 + return parse_audio_selector_unit(state, unitid, p1); 2275 + case UAC3_FEATURE_UNIT: 2276 + return parse_audio_feature_unit(state, unitid, p1); 2277 + case UAC3_EFFECT_UNIT: 2278 + return 0; /* FIXME - effect units not implemented yet */ 2279 + case UAC3_PROCESSING_UNIT: 2326 2280 return parse_audio_processing_unit(state, unitid, p1); 2327 - case UAC2_EXTENSION_UNIT_V2: 2328 - return parse_audio_extension_unit(state, unitid, p1); 2329 - default: 2330 - usb_audio_err(state->chip, 2331 - "unit %u: unexpected type 0x%02x\n", unitid, p1[2]); 2332 - return -EINVAL; 2281 + case UAC3_EXTENSION_UNIT: 2282 + return parse_audio_extension_unit(state, unitid, p1); 2283 + default: 2284 + usb_audio_err(state->chip, 2285 + "unit %u: unexpected type 0x%02x\n", unitid, p1[2]); 2286 + return -EINVAL; 2287 + } 2333 2288 } 2334 2289 } 2335 2290 ··· 2425 2330 err = parse_audio_unit(&state, desc->bSourceID); 2426 2331 if (err < 0 && err != -EINVAL) 2427 2332 return err; 2428 - } else { /* UAC_VERSION_2 */ 2333 + } else if (mixer->protocol == UAC_VERSION_2) { 2429 2334 struct uac2_output_terminal_descriptor *desc = p; 2430 2335 2431 2336 if (desc->bLength < sizeof(*desc)) ··· 2441 2346 2442 2347 /* 2443 2348 * For UAC2, use the same approach to also add the 2349 + * clock selectors 2350 + */ 2351 + err = parse_audio_unit(&state, desc->bCSourceID); 2352 + if (err < 0 && err != -EINVAL) 2353 + return err; 2354 + } else { /* UAC_VERSION_3 */ 2355 + struct uac3_output_terminal_descriptor *desc = p; 2356 + 2357 + if (desc->bLength < sizeof(*desc)) 2358 + continue; /* invalid descriptor? */ 2359 + /* mark terminal ID as visited */ 2360 + set_bit(desc->bTerminalID, state.unitbitmap); 2361 + state.oterm.id = desc->bTerminalID; 2362 + state.oterm.type = le16_to_cpu(desc->wTerminalType); 2363 + state.oterm.name = le16_to_cpu(desc->wTerminalDescrStr); 2364 + err = parse_audio_unit(&state, desc->bSourceID); 2365 + if (err < 0 && err != -EINVAL) 2366 + return err; 2367 + 2368 + /* 2369 + * For UAC3, use the same approach to also add the 2444 2370 * clock selectors 2445 2371 */ 2446 2372 err = parse_audio_unit(&state, desc->bCSourceID); ··· 2712 2596 break; 2713 2597 case UAC_VERSION_2: 2714 2598 mixer->protocol = UAC_VERSION_2; 2599 + break; 2600 + case UAC_VERSION_3: 2601 + mixer->protocol = UAC_VERSION_3; 2715 2602 break; 2716 2603 } 2717 2604
+329 -36
sound/usb/stream.c
··· 20 20 #include <linux/usb.h> 21 21 #include <linux/usb/audio.h> 22 22 #include <linux/usb/audio-v2.h> 23 + #include <linux/usb/audio-v3.h> 23 24 24 25 #include <sound/core.h> 25 26 #include <sound/pcm.h> ··· 312 311 return chmap; 313 312 } 314 313 314 + /* UAC3 device stores channels information in Cluster Descriptors */ 315 + static struct 316 + snd_pcm_chmap_elem *convert_chmap_v3(struct uac3_cluster_header_descriptor 317 + *cluster) 318 + { 319 + unsigned int channels = cluster->bNrChannels; 320 + struct snd_pcm_chmap_elem *chmap; 321 + void *p = cluster; 322 + int len, c; 323 + 324 + if (channels > ARRAY_SIZE(chmap->map)) 325 + return NULL; 326 + 327 + chmap = kzalloc(sizeof(*chmap), GFP_KERNEL); 328 + if (!chmap) 329 + return NULL; 330 + 331 + len = le16_to_cpu(cluster->wLength); 332 + c = 0; 333 + p += sizeof(struct uac3_cluster_header_descriptor); 334 + 335 + while (((p - (void *)cluster) < len) && (c < channels)) { 336 + struct uac3_cluster_segment_descriptor *cs_desc = p; 337 + u16 cs_len; 338 + u8 cs_type; 339 + 340 + cs_len = le16_to_cpu(cs_desc->wLength); 341 + cs_type = cs_desc->bSegmentType; 342 + 343 + if (cs_type == UAC3_CHANNEL_INFORMATION) { 344 + struct uac3_cluster_information_segment_descriptor *is = p; 345 + unsigned char map; 346 + 347 + /* 348 + * TODO: this conversion is not complete, update it 349 + * after adding UAC3 values to asound.h 350 + */ 351 + switch (is->bChPurpose) { 352 + case UAC3_CH_MONO: 353 + map = SNDRV_CHMAP_MONO; 354 + break; 355 + case UAC3_CH_LEFT: 356 + case UAC3_CH_FRONT_LEFT: 357 + case UAC3_CH_HEADPHONE_LEFT: 358 + map = SNDRV_CHMAP_FL; 359 + break; 360 + case UAC3_CH_RIGHT: 361 + case UAC3_CH_FRONT_RIGHT: 362 + case UAC3_CH_HEADPHONE_RIGHT: 363 + map = SNDRV_CHMAP_FR; 364 + break; 365 + case UAC3_CH_FRONT_CENTER: 366 + map = SNDRV_CHMAP_FC; 367 + break; 368 + case UAC3_CH_FRONT_LEFT_OF_CENTER: 369 + map = SNDRV_CHMAP_FLC; 370 + break; 371 + case UAC3_CH_FRONT_RIGHT_OF_CENTER: 372 + map = SNDRV_CHMAP_FRC; 373 + break; 374 + case UAC3_CH_SIDE_LEFT: 375 + map = SNDRV_CHMAP_SL; 376 + break; 377 + case UAC3_CH_SIDE_RIGHT: 378 + map = SNDRV_CHMAP_SR; 379 + break; 380 + case UAC3_CH_BACK_LEFT: 381 + map = SNDRV_CHMAP_RL; 382 + break; 383 + case UAC3_CH_BACK_RIGHT: 384 + map = SNDRV_CHMAP_RR; 385 + break; 386 + case UAC3_CH_BACK_CENTER: 387 + map = SNDRV_CHMAP_RC; 388 + break; 389 + case UAC3_CH_BACK_LEFT_OF_CENTER: 390 + map = SNDRV_CHMAP_RLC; 391 + break; 392 + case UAC3_CH_BACK_RIGHT_OF_CENTER: 393 + map = SNDRV_CHMAP_RRC; 394 + break; 395 + case UAC3_CH_TOP_CENTER: 396 + map = SNDRV_CHMAP_TC; 397 + break; 398 + case UAC3_CH_TOP_FRONT_LEFT: 399 + map = SNDRV_CHMAP_TFL; 400 + break; 401 + case UAC3_CH_TOP_FRONT_RIGHT: 402 + map = SNDRV_CHMAP_TFR; 403 + break; 404 + case UAC3_CH_TOP_FRONT_CENTER: 405 + map = SNDRV_CHMAP_TFC; 406 + break; 407 + case UAC3_CH_TOP_FRONT_LOC: 408 + map = SNDRV_CHMAP_TFLC; 409 + break; 410 + case UAC3_CH_TOP_FRONT_ROC: 411 + map = SNDRV_CHMAP_TFRC; 412 + break; 413 + case UAC3_CH_TOP_SIDE_LEFT: 414 + map = SNDRV_CHMAP_TSL; 415 + break; 416 + case UAC3_CH_TOP_SIDE_RIGHT: 417 + map = SNDRV_CHMAP_TSR; 418 + break; 419 + case UAC3_CH_TOP_BACK_LEFT: 420 + map = SNDRV_CHMAP_TRL; 421 + break; 422 + case UAC3_CH_TOP_BACK_RIGHT: 423 + map = SNDRV_CHMAP_TRR; 424 + break; 425 + case UAC3_CH_TOP_BACK_CENTER: 426 + map = SNDRV_CHMAP_TRC; 427 + break; 428 + case UAC3_CH_BOTTOM_CENTER: 429 + map = SNDRV_CHMAP_BC; 430 + break; 431 + case UAC3_CH_LOW_FREQUENCY_EFFECTS: 432 + map = SNDRV_CHMAP_LFE; 433 + break; 434 + case UAC3_CH_LFE_LEFT: 435 + map = SNDRV_CHMAP_LLFE; 436 + break; 437 + case UAC3_CH_LFE_RIGHT: 438 + map = SNDRV_CHMAP_RLFE; 439 + break; 440 + case UAC3_CH_RELATIONSHIP_UNDEFINED: 441 + default: 442 + map = SNDRV_CHMAP_UNKNOWN; 443 + break; 444 + } 445 + chmap->map[c++] = map; 446 + } 447 + p += cs_len; 448 + } 449 + 450 + if (channels < c) 451 + pr_err("%s: channel number mismatch\n", __func__); 452 + 453 + chmap->channels = channels; 454 + 455 + for (; c < channels; c++) 456 + chmap->map[c] = SNDRV_CHMAP_UNKNOWN; 457 + 458 + return chmap; 459 + } 460 + 315 461 /* 316 462 * add this endpoint to the chip instance. 317 463 * if a stream with the same endpoint already exists, append to it. ··· 609 461 return NULL; 610 462 } 611 463 612 - static struct uac2_output_terminal_descriptor * 613 - snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface, 614 - int terminal_id) 464 + static void * 465 + snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface, 466 + int terminal_id) 615 467 { 468 + /* OK to use with both UAC2 and UAC3 */ 616 469 struct uac2_output_terminal_descriptor *term = NULL; 617 470 618 471 while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, ··· 633 484 struct usb_host_interface *alts; 634 485 struct usb_interface_descriptor *altsd; 635 486 int i, altno, err, stream; 636 - unsigned int format = 0, num_channels = 0; 487 + u64 format = 0; 488 + unsigned int num_channels = 0; 637 489 struct audioformat *fp = NULL; 638 490 int num, protocol, clock = 0; 639 - struct uac_format_type_i_continuous_descriptor *fmt; 491 + struct uac_format_type_i_continuous_descriptor *fmt = NULL; 492 + struct snd_pcm_chmap_elem *chmap_v3 = NULL; 640 493 unsigned int chconfig; 641 494 642 495 dev = chip->dev; ··· 775 624 iface_no, altno, as->bTerminalLink); 776 625 continue; 777 626 } 778 - } 779 627 780 - /* get format type */ 781 - fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE); 782 - if (!fmt) { 628 + case UAC_VERSION_3: { 629 + struct uac3_input_terminal_descriptor *input_term; 630 + struct uac3_output_terminal_descriptor *output_term; 631 + struct uac3_as_header_descriptor *as; 632 + struct uac3_cluster_header_descriptor *cluster; 633 + struct uac3_hc_descriptor_header hc_header; 634 + u16 cluster_id, wLength; 635 + 636 + as = snd_usb_find_csint_desc(alts->extra, 637 + alts->extralen, 638 + NULL, UAC_AS_GENERAL); 639 + 640 + if (!as) { 641 + dev_err(&dev->dev, 642 + "%u:%d : UAC_AS_GENERAL descriptor not found\n", 643 + iface_no, altno); 644 + continue; 645 + } 646 + 647 + if (as->bLength < sizeof(*as)) { 648 + dev_err(&dev->dev, 649 + "%u:%d : invalid UAC_AS_GENERAL desc\n", 650 + iface_no, altno); 651 + continue; 652 + } 653 + 654 + cluster_id = le16_to_cpu(as->wClusterDescrID); 655 + if (!cluster_id) { 656 + dev_err(&dev->dev, 657 + "%u:%d : no cluster descriptor\n", 658 + iface_no, altno); 659 + continue; 660 + } 661 + 662 + /* 663 + * Get number of channels and channel map through 664 + * High Capability Cluster Descriptor 665 + * 666 + * First step: get High Capability header and 667 + * read size of Cluster Descriptor 668 + */ 669 + err = snd_usb_ctl_msg(chip->dev, 670 + usb_rcvctrlpipe(chip->dev, 0), 671 + UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR, 672 + USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 673 + cluster_id, 674 + snd_usb_ctrl_intf(chip), 675 + &hc_header, sizeof(hc_header)); 676 + if (err < 0) 677 + return err; 678 + else if (err != sizeof(hc_header)) { 679 + dev_err(&dev->dev, 680 + "%u:%d : can't get High Capability descriptor\n", 681 + iface_no, altno); 682 + return -EIO; 683 + } 684 + 685 + /* 686 + * Second step: allocate needed amount of memory 687 + * and request Cluster Descriptor 688 + */ 689 + wLength = le16_to_cpu(hc_header.wLength); 690 + cluster = kzalloc(wLength, GFP_KERNEL); 691 + if (!cluster) 692 + return -ENOMEM; 693 + err = snd_usb_ctl_msg(chip->dev, 694 + usb_rcvctrlpipe(chip->dev, 0), 695 + UAC3_CS_REQ_HIGH_CAPABILITY_DESCRIPTOR, 696 + USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 697 + cluster_id, 698 + snd_usb_ctrl_intf(chip), 699 + cluster, wLength); 700 + if (err < 0) { 701 + kfree(cluster); 702 + return err; 703 + } else if (err != wLength) { 704 + dev_err(&dev->dev, 705 + "%u:%d : can't get Cluster Descriptor\n", 706 + iface_no, altno); 707 + kfree(cluster); 708 + return -EIO; 709 + } 710 + 711 + num_channels = cluster->bNrChannels; 712 + chmap_v3 = convert_chmap_v3(cluster); 713 + 714 + kfree(cluster); 715 + 716 + format = le64_to_cpu(as->bmFormats); 717 + 718 + /* lookup the terminal associated to this interface 719 + * to extract the clock */ 720 + input_term = snd_usb_find_input_terminal_descriptor( 721 + chip->ctrl_intf, 722 + as->bTerminalLink); 723 + 724 + if (input_term) { 725 + clock = input_term->bCSourceID; 726 + break; 727 + } 728 + 729 + output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf, 730 + as->bTerminalLink); 731 + if (output_term) { 732 + clock = output_term->bCSourceID; 733 + break; 734 + } 735 + 783 736 dev_err(&dev->dev, 784 - "%u:%d : no UAC_FORMAT_TYPE desc\n", 785 - iface_no, altno); 737 + "%u:%d : bogus bTerminalLink %d\n", 738 + iface_no, altno, as->bTerminalLink); 786 739 continue; 787 740 } 788 - if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) || 789 - ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) { 790 - dev_err(&dev->dev, 791 - "%u:%d : invalid UAC_FORMAT_TYPE desc\n", 792 - iface_no, altno); 793 - continue; 794 741 } 795 742 796 - /* 797 - * Blue Microphones workaround: The last altsetting is identical 798 - * with the previous one, except for a larger packet size, but 799 - * is actually a mislabeled two-channel setting; ignore it. 800 - */ 801 - if (fmt->bNrChannels == 1 && 802 - fmt->bSubframeSize == 2 && 803 - altno == 2 && num == 3 && 804 - fp && fp->altsetting == 1 && fp->channels == 1 && 805 - fp->formats == SNDRV_PCM_FMTBIT_S16_LE && 806 - protocol == UAC_VERSION_1 && 807 - le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 743 + if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) { 744 + /* get format type */ 745 + fmt = snd_usb_find_csint_desc(alts->extra, 746 + alts->extralen, 747 + NULL, UAC_FORMAT_TYPE); 748 + if (!fmt) { 749 + dev_err(&dev->dev, 750 + "%u:%d : no UAC_FORMAT_TYPE desc\n", 751 + iface_no, altno); 752 + continue; 753 + } 754 + if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) 755 + || ((protocol == UAC_VERSION_2) && 756 + (fmt->bLength < 6))) { 757 + dev_err(&dev->dev, 758 + "%u:%d : invalid UAC_FORMAT_TYPE desc\n", 759 + iface_no, altno); 760 + continue; 761 + } 762 + 763 + /* 764 + * Blue Microphones workaround: The last altsetting is 765 + * identical with the previous one, except for a larger 766 + * packet size, but is actually a mislabeled two-channel 767 + * setting; ignore it. 768 + */ 769 + if (fmt->bNrChannels == 1 && 770 + fmt->bSubframeSize == 2 && 771 + altno == 2 && num == 3 && 772 + fp && fp->altsetting == 1 && fp->channels == 1 && 773 + fp->formats == SNDRV_PCM_FMTBIT_S16_LE && 774 + protocol == UAC_VERSION_1 && 775 + le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 808 776 fp->maxpacksize * 2) 809 - continue; 777 + continue; 778 + } 810 779 811 780 fp = kzalloc(sizeof(*fp), GFP_KERNEL); 812 781 if (!fp) ··· 952 681 snd_usb_audioformat_attributes_quirk(chip, fp, stream); 953 682 954 683 /* ok, let's parse further... */ 955 - if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream) < 0) { 956 - kfree(fp->rate_table); 957 - kfree(fp); 958 - fp = NULL; 959 - continue; 684 + if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) { 685 + if (snd_usb_parse_audio_format(chip, fp, format, 686 + fmt, stream) < 0) { 687 + kfree(fp->rate_table); 688 + kfree(fp); 689 + fp = NULL; 690 + continue; 691 + } 692 + } else { 693 + struct uac3_as_header_descriptor *as; 694 + 695 + as = snd_usb_find_csint_desc(alts->extra, 696 + alts->extralen, 697 + NULL, UAC_AS_GENERAL); 698 + 699 + if (snd_usb_parse_audio_format_v3(chip, fp, as, 700 + stream) < 0) { 701 + kfree(fp->rate_table); 702 + kfree(fp); 703 + fp = NULL; 704 + continue; 705 + } 960 706 } 961 707 962 708 /* Create chmap */ 963 709 if (fp->channels != num_channels) 964 710 chconfig = 0; 965 - fp->chmap = convert_chmap(fp->channels, chconfig, protocol); 711 + 712 + if (protocol == UAC_VERSION_3) 713 + fp->chmap = chmap_v3; 714 + else 715 + fp->chmap = convert_chmap(fp->channels, chconfig, 716 + protocol); 966 717 967 718 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint); 968 719 err = snd_usb_add_audio_stream(chip, stream, fp);