diff options
author | Takashi Iwai <tiwai@suse.de> | 2018-04-02 13:50:41 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2018-04-02 13:50:59 -0400 |
commit | bc334cb61b9ee6e85b9bb01519989a3ae8fe03f6 (patch) | |
tree | 34424a812537fe11beeee727b30b19c67193fe36 /sound/usb | |
parent | 5607dddbfca774fb38bffadcb077fe03aa4ac5c6 (diff) | |
parent | b44d419b98fae759b4f746186b1d1c8d01d962f2 (diff) |
Merge branch 'for-next' into for-linus
Preparation for 4.17 merge.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb')
-rw-r--r-- | sound/usb/card.c | 7 | ||||
-rw-r--r-- | sound/usb/card.h | 2 | ||||
-rw-r--r-- | sound/usb/clock.c | 231 | ||||
-rw-r--r-- | sound/usb/clock.h | 4 | ||||
-rw-r--r-- | sound/usb/format.c | 93 | ||||
-rw-r--r-- | sound/usb/format.h | 6 | ||||
-rw-r--r-- | sound/usb/mixer.c | 511 | ||||
-rw-r--r-- | sound/usb/quirks.c | 102 | ||||
-rw-r--r-- | sound/usb/quirks.h | 4 | ||||
-rw-r--r-- | sound/usb/stream.c | 395 |
10 files changed, 1062 insertions, 293 deletions
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..ab39ccb974c6 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 | ||
54 | static 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 | |||
53 | static struct uac_clock_selector_descriptor * | 70 | static 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 | ||
89 | static 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 | |||
72 | static struct uac_clock_multiplier_descriptor * | 105 | static 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 | ||
121 | static 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 | |||
88 | static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_id) | 137 | static 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,20 +187,34 @@ 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 | ||
141 | static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id) | 190 | static 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)) |
155 | return 1; | 218 | return 1; |
156 | 219 | ||
157 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, | 220 | err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR, |
@@ -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 | ||
173 | static int __uac_clock_find_source(struct snd_usb_audio *chip, | 236 | static 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 | ||
326 | static 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 | */ |
274 | int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id, | 428 | int 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 | ||
282 | static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface, | 446 | static 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 | ||
338 | static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface, | 502 | static 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 | ||
359 | static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, | 523 | static 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,31 @@ 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, | ||
556 | UAC2_CS_CONTROL_SAM_FREQ); | ||
380 | if (writeable) { | 557 | if (writeable) { |
381 | data = cpu_to_le32(rate); | 558 | data = cpu_to_le32(rate); |
382 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, | 559 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, |
@@ -386,12 +563,13 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface, | |||
386 | &data, sizeof(data)); | 563 | &data, sizeof(data)); |
387 | if (err < 0) { | 564 | if (err < 0) { |
388 | usb_audio_err(chip, | 565 | usb_audio_err(chip, |
389 | "%d:%d: cannot set freq %d (v2): err %d\n", | 566 | "%d:%d: cannot set freq %d (v2/v3): err %d\n", |
390 | iface, fmt->altsetting, rate, err); | 567 | iface, fmt->altsetting, rate, err); |
391 | return err; | 568 | return err; |
392 | } | 569 | } |
393 | 570 | ||
394 | cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock); | 571 | cur_rate = get_sample_rate_v2v3(chip, iface, |
572 | fmt->altsetting, clock); | ||
395 | } else { | 573 | } else { |
396 | cur_rate = prev_rate; | 574 | cur_rate = prev_rate; |
397 | } | 575 | } |
@@ -430,7 +608,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); | 608 | return set_sample_rate_v1(chip, iface, alts, fmt, rate); |
431 | 609 | ||
432 | case UAC_VERSION_2: | 610 | case UAC_VERSION_2: |
433 | return set_sample_rate_v2(chip, iface, alts, fmt, rate); | 611 | case UAC_VERSION_3: |
612 | return set_sample_rate_v2v3(chip, iface, alts, fmt, rate); | ||
434 | } | 613 | } |
435 | } | 614 | } |
436 | 615 | ||
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 | ||
9 | int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id, | 9 | int 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..49e7ec6d2399 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 | */ |
44 | static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, | 45 | static 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; |
@@ -54,7 +55,7 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, | |||
54 | struct uac_format_type_i_discrete_descriptor *fmt = _fmt; | 55 | struct uac_format_type_i_discrete_descriptor *fmt = _fmt; |
55 | sample_width = fmt->bBitResolution; | 56 | sample_width = fmt->bBitResolution; |
56 | sample_bytes = fmt->bSubframeSize; | 57 | sample_bytes = fmt->bSubframeSize; |
57 | format = 1 << format; | 58 | format = 1ULL << format; |
58 | break; | 59 | break; |
59 | } | 60 | } |
60 | 61 | ||
@@ -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 | */ |
286 | static int parse_audio_format_rates_v2(struct snd_usb_audio *chip, | 299 | static 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 | */ |
370 | static int parse_audio_format_i(struct snd_usb_audio *chip, | 384 | static 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 | */ |
431 | static int parse_audio_format_ii(struct snd_usb_audio *chip, | 467 | static 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 | ||
481 | int snd_usb_parse_audio_format(struct snd_usb_audio *chip, | 517 | int 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 | ||
559 | int 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 | ||
5 | int snd_usb_parse_audio_format(struct snd_usb_audio *chip, | 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 | 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 | ||
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 | #endif /* __USBAUDIO_FORMAT_H */ | 14 | #endif /* __USBAUDIO_FORMAT_H */ |
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index 06b22624ab7a..301ad61ed426 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 | |||
723 | static int check_input_term(struct mixer_build *state, int id, | 725 | static 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; |
@@ -828,26 +879,27 @@ static int check_input_term(struct mixer_build *state, int id, | |||
828 | 879 | ||
829 | /* feature unit control information */ | 880 | /* feature unit control information */ |
830 | struct usb_feature_control_info { | 881 | struct usb_feature_control_info { |
882 | int control; | ||
831 | const char *name; | 883 | const char *name; |
832 | int type; /* data type for uac1 */ | 884 | int type; /* data type for uac1 */ |
833 | int type_uac2; /* data type for uac2 if different from uac1, else -1 */ | 885 | int type_uac2; /* data type for uac2 if different from uac1, else -1 */ |
834 | }; | 886 | }; |
835 | 887 | ||
836 | static struct usb_feature_control_info audio_feature_info[] = { | 888 | static struct usb_feature_control_info audio_feature_info[] = { |
837 | { "Mute", USB_MIXER_INV_BOOLEAN, -1 }, | 889 | { UAC_FU_MUTE, "Mute", USB_MIXER_INV_BOOLEAN, -1 }, |
838 | { "Volume", USB_MIXER_S16, -1 }, | 890 | { UAC_FU_VOLUME, "Volume", USB_MIXER_S16, -1 }, |
839 | { "Tone Control - Bass", USB_MIXER_S8, -1 }, | 891 | { UAC_FU_BASS, "Tone Control - Bass", USB_MIXER_S8, -1 }, |
840 | { "Tone Control - Mid", USB_MIXER_S8, -1 }, | 892 | { UAC_FU_MID, "Tone Control - Mid", USB_MIXER_S8, -1 }, |
841 | { "Tone Control - Treble", USB_MIXER_S8, -1 }, | 893 | { UAC_FU_TREBLE, "Tone Control - Treble", USB_MIXER_S8, -1 }, |
842 | { "Graphic Equalizer", USB_MIXER_S8, -1 }, /* FIXME: not implemeted yet */ | 894 | { UAC_FU_GRAPHIC_EQUALIZER, "Graphic Equalizer", USB_MIXER_S8, -1 }, /* FIXME: not implemented yet */ |
843 | { "Auto Gain Control", USB_MIXER_BOOLEAN, -1 }, | 895 | { UAC_FU_AUTOMATIC_GAIN, "Auto Gain Control", USB_MIXER_BOOLEAN, -1 }, |
844 | { "Delay Control", USB_MIXER_U16, USB_MIXER_U32 }, | 896 | { UAC_FU_DELAY, "Delay Control", USB_MIXER_U16, USB_MIXER_U32 }, |
845 | { "Bass Boost", USB_MIXER_BOOLEAN, -1 }, | 897 | { UAC_FU_BASS_BOOST, "Bass Boost", USB_MIXER_BOOLEAN, -1 }, |
846 | { "Loudness", USB_MIXER_BOOLEAN, -1 }, | 898 | { UAC_FU_LOUDNESS, "Loudness", USB_MIXER_BOOLEAN, -1 }, |
847 | /* UAC2 specific */ | 899 | /* UAC2 specific */ |
848 | { "Input Gain Control", USB_MIXER_S16, -1 }, | 900 | { UAC2_FU_INPUT_GAIN, "Input Gain Control", USB_MIXER_S16, -1 }, |
849 | { "Input Gain Pad Control", USB_MIXER_S16, -1 }, | 901 | { UAC2_FU_INPUT_GAIN_PAD, "Input Gain Pad Control", USB_MIXER_S16, -1 }, |
850 | { "Phase Inverter Control", USB_MIXER_BOOLEAN, -1 }, | 902 | { UAC2_FU_PHASE_INVERTER, "Phase Inverter Control", USB_MIXER_BOOLEAN, -1 }, |
851 | }; | 903 | }; |
852 | 904 | ||
853 | /* private_free callback */ | 905 | /* private_free callback */ |
@@ -1183,6 +1235,21 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, | |||
1183 | return changed; | 1235 | return changed; |
1184 | } | 1236 | } |
1185 | 1237 | ||
1238 | /* get the boolean value from the master channel of a UAC control */ | ||
1239 | static int mixer_ctl_master_bool_get(struct snd_kcontrol *kcontrol, | ||
1240 | struct snd_ctl_elem_value *ucontrol) | ||
1241 | { | ||
1242 | struct usb_mixer_elem_info *cval = kcontrol->private_data; | ||
1243 | int val, err; | ||
1244 | |||
1245 | err = snd_usb_get_cur_mix_value(cval, 0, 0, &val); | ||
1246 | if (err < 0) | ||
1247 | return filter_error(cval, err); | ||
1248 | val = (val != 0); | ||
1249 | ucontrol->value.integer.value[0] = val; | ||
1250 | return 0; | ||
1251 | } | ||
1252 | |||
1186 | static struct snd_kcontrol_new usb_feature_unit_ctl = { | 1253 | static struct snd_kcontrol_new usb_feature_unit_ctl = { |
1187 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 1254 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
1188 | .name = "", /* will be filled later manually */ | 1255 | .name = "", /* will be filled later manually */ |
@@ -1201,6 +1268,19 @@ static const struct snd_kcontrol_new usb_feature_unit_ctl_ro = { | |||
1201 | }; | 1268 | }; |
1202 | 1269 | ||
1203 | /* | 1270 | /* |
1271 | * A control which shows the boolean value from reading a UAC control on | ||
1272 | * the master channel. | ||
1273 | */ | ||
1274 | static struct snd_kcontrol_new usb_bool_master_control_ctl_ro = { | ||
1275 | .iface = SNDRV_CTL_ELEM_IFACE_CARD, | ||
1276 | .name = "", /* will be filled later manually */ | ||
1277 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | ||
1278 | .info = snd_ctl_boolean_mono_info, | ||
1279 | .get = mixer_ctl_master_bool_get, | ||
1280 | .put = NULL, | ||
1281 | }; | ||
1282 | |||
1283 | /* | ||
1204 | * This symbol is exported in order to allow the mixer quirks to | 1284 | * This symbol is exported in order to allow the mixer quirks to |
1205 | * hook up to the standard feature unit control mechanism | 1285 | * hook up to the standard feature unit control mechanism |
1206 | */ | 1286 | */ |
@@ -1242,6 +1322,17 @@ static void check_no_speaker_on_headset(struct snd_kcontrol *kctl, | |||
1242 | strlcpy(kctl->id.name, "Headphone", sizeof(kctl->id.name)); | 1322 | strlcpy(kctl->id.name, "Headphone", sizeof(kctl->id.name)); |
1243 | } | 1323 | } |
1244 | 1324 | ||
1325 | static struct usb_feature_control_info *get_feature_control_info(int control) | ||
1326 | { | ||
1327 | int i; | ||
1328 | |||
1329 | for (i = 0; i < ARRAY_SIZE(audio_feature_info); ++i) { | ||
1330 | if (audio_feature_info[i].control == control) | ||
1331 | return &audio_feature_info[i]; | ||
1332 | } | ||
1333 | return NULL; | ||
1334 | } | ||
1335 | |||
1245 | static void build_feature_ctl(struct mixer_build *state, void *raw_desc, | 1336 | static void build_feature_ctl(struct mixer_build *state, void *raw_desc, |
1246 | unsigned int ctl_mask, int control, | 1337 | unsigned int ctl_mask, int control, |
1247 | struct usb_audio_term *iterm, int unitid, | 1338 | struct usb_audio_term *iterm, int unitid, |
@@ -1257,8 +1348,6 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, | |||
1257 | const struct usbmix_name_map *map; | 1348 | const struct usbmix_name_map *map; |
1258 | unsigned int range; | 1349 | unsigned int range; |
1259 | 1350 | ||
1260 | control++; /* change from zero-based to 1-based value */ | ||
1261 | |||
1262 | if (control == UAC_FU_GRAPHIC_EQUALIZER) { | 1351 | if (control == UAC_FU_GRAPHIC_EQUALIZER) { |
1263 | /* FIXME: not supported yet */ | 1352 | /* FIXME: not supported yet */ |
1264 | return; | 1353 | return; |
@@ -1274,7 +1363,12 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, | |||
1274 | snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid); | 1363 | snd_usb_mixer_elem_init_std(&cval->head, state->mixer, unitid); |
1275 | cval->control = control; | 1364 | cval->control = control; |
1276 | cval->cmask = ctl_mask; | 1365 | cval->cmask = ctl_mask; |
1277 | ctl_info = &audio_feature_info[control-1]; | 1366 | |
1367 | ctl_info = get_feature_control_info(control); | ||
1368 | if (!ctl_info) { | ||
1369 | kfree(cval); | ||
1370 | return; | ||
1371 | } | ||
1278 | if (state->mixer->protocol == UAC_VERSION_1) | 1372 | if (state->mixer->protocol == UAC_VERSION_1) |
1279 | cval->val_type = ctl_info->type; | 1373 | cval->val_type = ctl_info->type; |
1280 | else /* UAC_VERSION_2 */ | 1374 | else /* UAC_VERSION_2 */ |
@@ -1400,6 +1494,60 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc, | |||
1400 | snd_usb_mixer_add_control(&cval->head, kctl); | 1494 | snd_usb_mixer_add_control(&cval->head, kctl); |
1401 | } | 1495 | } |
1402 | 1496 | ||
1497 | static void get_connector_control_name(struct mixer_build *state, | ||
1498 | struct usb_audio_term *term, | ||
1499 | bool is_input, char *name, int name_size) | ||
1500 | { | ||
1501 | int name_len = get_term_name(state, term, name, name_size, 0); | ||
1502 | |||
1503 | if (name_len == 0) | ||
1504 | strlcpy(name, "Unknown", name_size); | ||
1505 | |||
1506 | /* | ||
1507 | * sound/core/ctljack.c has a convention of naming jack controls | ||
1508 | * by ending in " Jack". Make it slightly more useful by | ||
1509 | * indicating Input or Output after the terminal name. | ||
1510 | */ | ||
1511 | if (is_input) | ||
1512 | strlcat(name, " - Input Jack", name_size); | ||
1513 | else | ||
1514 | strlcat(name, " - Output Jack", name_size); | ||
1515 | } | ||
1516 | |||
1517 | /* Build a mixer control for a UAC connector control (jack-detect) */ | ||
1518 | static void build_connector_control(struct mixer_build *state, | ||
1519 | struct usb_audio_term *term, bool is_input) | ||
1520 | { | ||
1521 | struct snd_kcontrol *kctl; | ||
1522 | struct usb_mixer_elem_info *cval; | ||
1523 | |||
1524 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); | ||
1525 | if (!cval) | ||
1526 | return; | ||
1527 | snd_usb_mixer_elem_init_std(&cval->head, state->mixer, term->id); | ||
1528 | /* | ||
1529 | * The first byte from reading the UAC2_TE_CONNECTOR control returns the | ||
1530 | * number of channels connected. This boolean ctl will simply report | ||
1531 | * if any channels are connected or not. | ||
1532 | * (Audio20_final.pdf Table 5-10: Connector Control CUR Parameter Block) | ||
1533 | */ | ||
1534 | cval->control = UAC2_TE_CONNECTOR; | ||
1535 | cval->val_type = USB_MIXER_BOOLEAN; | ||
1536 | cval->channels = 1; /* report true if any channel is connected */ | ||
1537 | cval->min = 0; | ||
1538 | cval->max = 1; | ||
1539 | kctl = snd_ctl_new1(&usb_bool_master_control_ctl_ro, cval); | ||
1540 | if (!kctl) { | ||
1541 | usb_audio_err(state->chip, "cannot malloc kcontrol\n"); | ||
1542 | kfree(cval); | ||
1543 | return; | ||
1544 | } | ||
1545 | get_connector_control_name(state, term, is_input, kctl->id.name, | ||
1546 | sizeof(kctl->id.name)); | ||
1547 | kctl->private_free = snd_usb_mixer_elem_free; | ||
1548 | snd_usb_mixer_add_control(&cval->head, kctl); | ||
1549 | } | ||
1550 | |||
1403 | static int parse_clock_source_unit(struct mixer_build *state, int unitid, | 1551 | static int parse_clock_source_unit(struct mixer_build *state, int unitid, |
1404 | void *_ftr) | 1552 | void *_ftr) |
1405 | { | 1553 | { |
@@ -1423,8 +1571,8 @@ 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 | 1571 | * The only property of this unit we are interested in is the |
1424 | * clock source validity. If that isn't readable, just bail out. | 1572 | * clock source validity. If that isn't readable, just bail out. |
1425 | */ | 1573 | */ |
1426 | if (!uac2_control_is_readable(hdr->bmControls, | 1574 | if (!uac_v2v3_control_is_readable(hdr->bmControls, |
1427 | ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) | 1575 | UAC2_CS_CONTROL_CLOCK_VALID)) |
1428 | return 0; | 1576 | return 0; |
1429 | 1577 | ||
1430 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); | 1578 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); |
@@ -1439,13 +1587,9 @@ static int parse_clock_source_unit(struct mixer_build *state, int unitid, | |||
1439 | cval->val_type = USB_MIXER_BOOLEAN; | 1587 | cval->val_type = USB_MIXER_BOOLEAN; |
1440 | cval->control = UAC2_CS_CONTROL_CLOCK_VALID; | 1588 | cval->control = UAC2_CS_CONTROL_CLOCK_VALID; |
1441 | 1589 | ||
1442 | if (uac2_control_is_writeable(hdr->bmControls, | 1590 | cval->master_readonly = 1; |
1443 | ilog2(UAC2_CS_CONTROL_CLOCK_VALID))) | 1591 | /* From UAC2 5.2.5.1.2 "Only the get request is supported." */ |
1444 | kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); | 1592 | kctl = snd_ctl_new1(&usb_bool_master_control_ctl_ro, cval); |
1445 | else { | ||
1446 | cval->master_readonly = 1; | ||
1447 | kctl = snd_ctl_new1(&usb_feature_unit_ctl_ro, cval); | ||
1448 | } | ||
1449 | 1593 | ||
1450 | if (!kctl) { | 1594 | if (!kctl) { |
1451 | kfree(cval); | 1595 | kfree(cval); |
@@ -1502,7 +1646,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, | |||
1502 | unitid); | 1646 | unitid); |
1503 | return -EINVAL; | 1647 | return -EINVAL; |
1504 | } | 1648 | } |
1505 | } else { | 1649 | } else if (state->mixer->protocol == UAC_VERSION_2) { |
1506 | struct uac2_feature_unit_descriptor *ftr = _ftr; | 1650 | struct uac2_feature_unit_descriptor *ftr = _ftr; |
1507 | if (hdr->bLength < 6) { | 1651 | if (hdr->bLength < 6) { |
1508 | usb_audio_err(state->chip, | 1652 | usb_audio_err(state->chip, |
@@ -1519,6 +1663,24 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, | |||
1519 | unitid); | 1663 | unitid); |
1520 | return -EINVAL; | 1664 | return -EINVAL; |
1521 | } | 1665 | } |
1666 | } else { /* UAC_VERSION_3 */ | ||
1667 | struct uac3_feature_unit_descriptor *ftr = _ftr; | ||
1668 | |||
1669 | if (hdr->bLength < 7) { | ||
1670 | usb_audio_err(state->chip, | ||
1671 | "unit %u: invalid UAC3_FEATURE_UNIT descriptor\n", | ||
1672 | unitid); | ||
1673 | return -EINVAL; | ||
1674 | } | ||
1675 | csize = 4; | ||
1676 | channels = (ftr->bLength - 7) / 4 - 1; | ||
1677 | bmaControls = ftr->bmaControls; | ||
1678 | if (hdr->bLength < 7 + csize) { | ||
1679 | usb_audio_err(state->chip, | ||
1680 | "unit %u: invalid UAC3_FEATURE_UNIT descriptor\n", | ||
1681 | unitid); | ||
1682 | return -EINVAL; | ||
1683 | } | ||
1522 | } | 1684 | } |
1523 | 1685 | ||
1524 | /* parse the source unit */ | 1686 | /* parse the source unit */ |
@@ -1556,6 +1718,8 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, | |||
1556 | /* check all control types */ | 1718 | /* check all control types */ |
1557 | for (i = 0; i < 10; i++) { | 1719 | for (i = 0; i < 10; i++) { |
1558 | unsigned int ch_bits = 0; | 1720 | unsigned int ch_bits = 0; |
1721 | int control = audio_feature_info[i].control; | ||
1722 | |||
1559 | for (j = 0; j < channels; j++) { | 1723 | for (j = 0; j < channels; j++) { |
1560 | unsigned int mask; | 1724 | unsigned int mask; |
1561 | 1725 | ||
@@ -1571,25 +1735,26 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, | |||
1571 | * (for ease of programming). | 1735 | * (for ease of programming). |
1572 | */ | 1736 | */ |
1573 | if (ch_bits & 1) | 1737 | if (ch_bits & 1) |
1574 | build_feature_ctl(state, _ftr, ch_bits, i, | 1738 | build_feature_ctl(state, _ftr, ch_bits, control, |
1575 | &iterm, unitid, 0); | 1739 | &iterm, unitid, 0); |
1576 | if (master_bits & (1 << i)) | 1740 | if (master_bits & (1 << i)) |
1577 | build_feature_ctl(state, _ftr, 0, i, &iterm, | 1741 | build_feature_ctl(state, _ftr, 0, control, |
1578 | unitid, 0); | 1742 | &iterm, unitid, 0); |
1579 | } | 1743 | } |
1580 | } else { /* UAC_VERSION_2 */ | 1744 | } else { /* UAC_VERSION_2/3 */ |
1581 | for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) { | 1745 | for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) { |
1582 | unsigned int ch_bits = 0; | 1746 | unsigned int ch_bits = 0; |
1583 | unsigned int ch_read_only = 0; | 1747 | unsigned int ch_read_only = 0; |
1748 | int control = audio_feature_info[i].control; | ||
1584 | 1749 | ||
1585 | for (j = 0; j < channels; j++) { | 1750 | for (j = 0; j < channels; j++) { |
1586 | unsigned int mask; | 1751 | unsigned int mask; |
1587 | 1752 | ||
1588 | mask = snd_usb_combine_bytes(bmaControls + | 1753 | mask = snd_usb_combine_bytes(bmaControls + |
1589 | csize * (j+1), csize); | 1754 | csize * (j+1), csize); |
1590 | if (uac2_control_is_readable(mask, i)) { | 1755 | if (uac_v2v3_control_is_readable(mask, control)) { |
1591 | ch_bits |= (1 << j); | 1756 | ch_bits |= (1 << j); |
1592 | if (!uac2_control_is_writeable(mask, i)) | 1757 | if (!uac_v2v3_control_is_writeable(mask, control)) |
1593 | ch_read_only |= (1 << j); | 1758 | ch_read_only |= (1 << j); |
1594 | } | 1759 | } |
1595 | } | 1760 | } |
@@ -1608,11 +1773,12 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, | |||
1608 | * (for ease of programming). | 1773 | * (for ease of programming). |
1609 | */ | 1774 | */ |
1610 | if (ch_bits & 1) | 1775 | if (ch_bits & 1) |
1611 | build_feature_ctl(state, _ftr, ch_bits, i, | 1776 | build_feature_ctl(state, _ftr, ch_bits, control, |
1612 | &iterm, unitid, ch_read_only); | 1777 | &iterm, unitid, ch_read_only); |
1613 | if (uac2_control_is_readable(master_bits, i)) | 1778 | if (uac_v2v3_control_is_readable(master_bits, control)) |
1614 | build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, | 1779 | build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, |
1615 | !uac2_control_is_writeable(master_bits, i)); | 1780 | !uac_v2v3_control_is_writeable(master_bits, |
1781 | control)); | ||
1616 | } | 1782 | } |
1617 | } | 1783 | } |
1618 | 1784 | ||
@@ -1684,6 +1850,23 @@ static void build_mixer_unit_ctl(struct mixer_build *state, | |||
1684 | snd_usb_mixer_add_control(&cval->head, kctl); | 1850 | snd_usb_mixer_add_control(&cval->head, kctl); |
1685 | } | 1851 | } |
1686 | 1852 | ||
1853 | static int parse_audio_input_terminal(struct mixer_build *state, int unitid, | ||
1854 | void *raw_desc) | ||
1855 | { | ||
1856 | struct usb_audio_term iterm; | ||
1857 | struct uac2_input_terminal_descriptor *d = raw_desc; | ||
1858 | |||
1859 | check_input_term(state, d->bTerminalID, &iterm); | ||
1860 | if (state->mixer->protocol == UAC_VERSION_2) { | ||
1861 | /* Check for jack detection. */ | ||
1862 | if (uac_v2v3_control_is_readable(d->bmControls, | ||
1863 | UAC2_TE_CONNECTOR)) { | ||
1864 | build_connector_control(state, &iterm, true); | ||
1865 | } | ||
1866 | } | ||
1867 | return 0; | ||
1868 | } | ||
1869 | |||
1687 | /* | 1870 | /* |
1688 | * parse a mixer unit | 1871 | * parse a mixer unit |
1689 | */ | 1872 | */ |
@@ -2220,6 +2403,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, | |||
2220 | static int parse_audio_unit(struct mixer_build *state, int unitid) | 2403 | static int parse_audio_unit(struct mixer_build *state, int unitid) |
2221 | { | 2404 | { |
2222 | unsigned char *p1; | 2405 | unsigned char *p1; |
2406 | int protocol = state->mixer->protocol; | ||
2223 | 2407 | ||
2224 | if (test_and_set_bit(unitid, state->unitbitmap)) | 2408 | if (test_and_set_bit(unitid, state->unitbitmap)) |
2225 | return 0; /* the unit already visited */ | 2409 | return 0; /* the unit already visited */ |
@@ -2230,36 +2414,61 @@ static int parse_audio_unit(struct mixer_build *state, int unitid) | |||
2230 | return -EINVAL; | 2414 | return -EINVAL; |
2231 | } | 2415 | } |
2232 | 2416 | ||
2233 | switch (p1[2]) { | 2417 | if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) { |
2234 | case UAC_INPUT_TERMINAL: | 2418 | switch (p1[2]) { |
2235 | return 0; /* NOP */ | 2419 | case UAC_INPUT_TERMINAL: |
2236 | case UAC_MIXER_UNIT: | 2420 | return parse_audio_input_terminal(state, unitid, p1); |
2237 | return parse_audio_mixer_unit(state, unitid, p1); | 2421 | case UAC_MIXER_UNIT: |
2238 | case UAC2_CLOCK_SOURCE: | 2422 | return parse_audio_mixer_unit(state, unitid, p1); |
2239 | return parse_clock_source_unit(state, unitid, p1); | 2423 | case UAC2_CLOCK_SOURCE: |
2240 | case UAC_SELECTOR_UNIT: | 2424 | return parse_clock_source_unit(state, unitid, p1); |
2241 | case UAC2_CLOCK_SELECTOR: | 2425 | case UAC_SELECTOR_UNIT: |
2242 | return parse_audio_selector_unit(state, unitid, p1); | 2426 | case UAC2_CLOCK_SELECTOR: |
2243 | case UAC_FEATURE_UNIT: | 2427 | return parse_audio_selector_unit(state, unitid, p1); |
2244 | return parse_audio_feature_unit(state, unitid, p1); | 2428 | case UAC_FEATURE_UNIT: |
2245 | case UAC1_PROCESSING_UNIT: | 2429 | return parse_audio_feature_unit(state, unitid, p1); |
2246 | /* UAC2_EFFECT_UNIT has the same value */ | 2430 | case UAC1_PROCESSING_UNIT: |
2247 | if (state->mixer->protocol == UAC_VERSION_1) | 2431 | /* UAC2_EFFECT_UNIT has the same value */ |
2248 | return parse_audio_processing_unit(state, unitid, p1); | 2432 | if (protocol == UAC_VERSION_1) |
2249 | else | 2433 | return parse_audio_processing_unit(state, unitid, p1); |
2250 | return 0; /* FIXME - effect units not implemented yet */ | 2434 | else |
2251 | case UAC1_EXTENSION_UNIT: | 2435 | return 0; /* FIXME - effect units not implemented yet */ |
2252 | /* UAC2_PROCESSING_UNIT_V2 has the same value */ | 2436 | case UAC1_EXTENSION_UNIT: |
2253 | if (state->mixer->protocol == UAC_VERSION_1) | 2437 | /* UAC2_PROCESSING_UNIT_V2 has the same value */ |
2438 | if (protocol == UAC_VERSION_1) | ||
2439 | return parse_audio_extension_unit(state, unitid, p1); | ||
2440 | else /* UAC_VERSION_2 */ | ||
2441 | return parse_audio_processing_unit(state, unitid, p1); | ||
2442 | case UAC2_EXTENSION_UNIT_V2: | ||
2254 | return parse_audio_extension_unit(state, unitid, p1); | 2443 | return parse_audio_extension_unit(state, unitid, p1); |
2255 | else /* UAC_VERSION_2 */ | 2444 | default: |
2445 | usb_audio_err(state->chip, | ||
2446 | "unit %u: unexpected type 0x%02x\n", unitid, p1[2]); | ||
2447 | return -EINVAL; | ||
2448 | } | ||
2449 | } else { /* UAC_VERSION_3 */ | ||
2450 | switch (p1[2]) { | ||
2451 | case UAC_INPUT_TERMINAL: | ||
2452 | return 0; /* NOP */ | ||
2453 | case UAC3_MIXER_UNIT: | ||
2454 | return parse_audio_mixer_unit(state, unitid, p1); | ||
2455 | case UAC3_CLOCK_SOURCE: | ||
2456 | return parse_clock_source_unit(state, unitid, p1); | ||
2457 | case UAC3_CLOCK_SELECTOR: | ||
2458 | return parse_audio_selector_unit(state, unitid, p1); | ||
2459 | case UAC3_FEATURE_UNIT: | ||
2460 | return parse_audio_feature_unit(state, unitid, p1); | ||
2461 | case UAC3_EFFECT_UNIT: | ||
2462 | return 0; /* FIXME - effect units not implemented yet */ | ||
2463 | case UAC3_PROCESSING_UNIT: | ||
2256 | return parse_audio_processing_unit(state, unitid, p1); | 2464 | return parse_audio_processing_unit(state, unitid, p1); |
2257 | case UAC2_EXTENSION_UNIT_V2: | 2465 | case UAC3_EXTENSION_UNIT: |
2258 | return parse_audio_extension_unit(state, unitid, p1); | 2466 | return parse_audio_extension_unit(state, unitid, p1); |
2259 | default: | 2467 | default: |
2260 | usb_audio_err(state->chip, | 2468 | usb_audio_err(state->chip, |
2261 | "unit %u: unexpected type 0x%02x\n", unitid, p1[2]); | 2469 | "unit %u: unexpected type 0x%02x\n", unitid, p1[2]); |
2262 | return -EINVAL; | 2470 | return -EINVAL; |
2471 | } | ||
2263 | } | 2472 | } |
2264 | } | 2473 | } |
2265 | 2474 | ||
@@ -2330,7 +2539,7 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer) | |||
2330 | err = parse_audio_unit(&state, desc->bSourceID); | 2539 | err = parse_audio_unit(&state, desc->bSourceID); |
2331 | if (err < 0 && err != -EINVAL) | 2540 | if (err < 0 && err != -EINVAL) |
2332 | return err; | 2541 | return err; |
2333 | } else { /* UAC_VERSION_2 */ | 2542 | } else if (mixer->protocol == UAC_VERSION_2) { |
2334 | struct uac2_output_terminal_descriptor *desc = p; | 2543 | struct uac2_output_terminal_descriptor *desc = p; |
2335 | 2544 | ||
2336 | if (desc->bLength < sizeof(*desc)) | 2545 | if (desc->bLength < sizeof(*desc)) |
@@ -2351,6 +2560,33 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer) | |||
2351 | err = parse_audio_unit(&state, desc->bCSourceID); | 2560 | err = parse_audio_unit(&state, desc->bCSourceID); |
2352 | if (err < 0 && err != -EINVAL) | 2561 | if (err < 0 && err != -EINVAL) |
2353 | return err; | 2562 | return err; |
2563 | |||
2564 | if (uac_v2v3_control_is_readable(desc->bmControls, | ||
2565 | UAC2_TE_CONNECTOR)) { | ||
2566 | build_connector_control(&state, &state.oterm, | ||
2567 | false); | ||
2568 | } | ||
2569 | } else { /* UAC_VERSION_3 */ | ||
2570 | struct uac3_output_terminal_descriptor *desc = p; | ||
2571 | |||
2572 | if (desc->bLength < sizeof(*desc)) | ||
2573 | continue; /* invalid descriptor? */ | ||
2574 | /* mark terminal ID as visited */ | ||
2575 | set_bit(desc->bTerminalID, state.unitbitmap); | ||
2576 | state.oterm.id = desc->bTerminalID; | ||
2577 | state.oterm.type = le16_to_cpu(desc->wTerminalType); | ||
2578 | state.oterm.name = le16_to_cpu(desc->wTerminalDescrStr); | ||
2579 | err = parse_audio_unit(&state, desc->bSourceID); | ||
2580 | if (err < 0 && err != -EINVAL) | ||
2581 | return err; | ||
2582 | |||
2583 | /* | ||
2584 | * For UAC3, use the same approach to also add the | ||
2585 | * clock selectors | ||
2586 | */ | ||
2587 | err = parse_audio_unit(&state, desc->bCSourceID); | ||
2588 | if (err < 0 && err != -EINVAL) | ||
2589 | return err; | ||
2354 | } | 2590 | } |
2355 | } | 2591 | } |
2356 | 2592 | ||
@@ -2597,6 +2833,9 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, | |||
2597 | case UAC_VERSION_2: | 2833 | case UAC_VERSION_2: |
2598 | mixer->protocol = UAC_VERSION_2; | 2834 | mixer->protocol = UAC_VERSION_2; |
2599 | break; | 2835 | break; |
2836 | case UAC_VERSION_3: | ||
2837 | mixer->protocol = UAC_VERSION_3; | ||
2838 | break; | ||
2600 | } | 2839 | } |
2601 | 2840 | ||
2602 | if ((err = snd_usb_mixer_controls(mixer)) < 0 || | 2841 | if ((err = snd_usb_mixer_controls(mixer)) < 0 || |
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index 794224e1d6df..acbeb52f6fd6 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c | |||
@@ -1149,27 +1149,17 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) | |||
1149 | return false; | 1149 | return false; |
1150 | } | 1150 | } |
1151 | 1151 | ||
1152 | /* Marantz/Denon USB DACs need a vendor cmd to switch | 1152 | /* ITF-USB DSD based DACs need a vendor cmd to switch |
1153 | * between PCM and native DSD mode | 1153 | * between PCM and native DSD mode |
1154 | */ | 1154 | */ |
1155 | static bool is_marantz_denon_dac(unsigned int id) | 1155 | static bool is_itf_usb_dsd_dac(unsigned int id) |
1156 | { | 1156 | { |
1157 | switch (id) { | 1157 | switch (id) { |
1158 | case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */ | 1158 | case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */ |
1159 | case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */ | 1159 | case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */ |
1160 | case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */ | 1160 | case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */ |
1161 | return true; | 1161 | case USB_ID(0x1852, 0x5065): /* Luxman DA-06 */ |
1162 | } | 1162 | case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-501V2/UD-503/NT-503 */ |
1163 | return false; | ||
1164 | } | ||
1165 | |||
1166 | /* TEAC UD-501/UD-503/NT-503 USB DACs need a vendor cmd to switch | ||
1167 | * between PCM/DOP and native DSD mode | ||
1168 | */ | ||
1169 | static bool is_teac_dsd_dac(unsigned int id) | ||
1170 | { | ||
1171 | switch (id) { | ||
1172 | case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-503/NT-503 */ | ||
1173 | case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */ | 1163 | case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */ |
1174 | case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */ | 1164 | case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */ |
1175 | return true; | 1165 | return true; |
@@ -1183,7 +1173,7 @@ int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, | |||
1183 | struct usb_device *dev = subs->dev; | 1173 | struct usb_device *dev = subs->dev; |
1184 | int err; | 1174 | int err; |
1185 | 1175 | ||
1186 | if (is_marantz_denon_dac(subs->stream->chip->usb_id)) { | 1176 | if (is_itf_usb_dsd_dac(subs->stream->chip->usb_id)) { |
1187 | /* First switch to alt set 0, otherwise the mode switch cmd | 1177 | /* First switch to alt set 0, otherwise the mode switch cmd |
1188 | * will not be accepted by the DAC | 1178 | * will not be accepted by the DAC |
1189 | */ | 1179 | */ |
@@ -1193,37 +1183,26 @@ int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, | |||
1193 | 1183 | ||
1194 | mdelay(20); /* Delay needed after setting the interface */ | 1184 | mdelay(20); /* Delay needed after setting the interface */ |
1195 | 1185 | ||
1196 | switch (fmt->altsetting) { | ||
1197 | case 2: /* DSD mode requested */ | ||
1198 | case 1: /* PCM mode requested */ | ||
1199 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, | ||
1200 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, | ||
1201 | fmt->altsetting - 1, 1, NULL, 0); | ||
1202 | if (err < 0) | ||
1203 | return err; | ||
1204 | break; | ||
1205 | } | ||
1206 | mdelay(20); | ||
1207 | } else if (is_teac_dsd_dac(subs->stream->chip->usb_id)) { | ||
1208 | /* Vendor mode switch cmd is required. */ | 1186 | /* Vendor mode switch cmd is required. */ |
1209 | switch (fmt->altsetting) { | 1187 | if (fmt->formats & SNDRV_PCM_FMTBIT_DSD_U32_BE) { |
1210 | case 3: /* DSD mode (DSD_U32) requested */ | 1188 | /* DSD mode (DSD_U32) requested */ |
1211 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, | 1189 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, |
1212 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, | 1190 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, |
1213 | 1, 1, NULL, 0); | 1191 | 1, 1, NULL, 0); |
1214 | if (err < 0) | 1192 | if (err < 0) |
1215 | return err; | 1193 | return err; |
1216 | break; | ||
1217 | 1194 | ||
1218 | case 2: /* PCM or DOP mode (S32) requested */ | 1195 | } else { |
1219 | case 1: /* PCM mode (S16) requested */ | 1196 | /* PCM or DOP mode (S32) requested */ |
1197 | /* PCM mode (S16) requested */ | ||
1220 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, | 1198 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0, |
1221 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, | 1199 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, |
1222 | 0, 1, NULL, 0); | 1200 | 0, 1, NULL, 0); |
1223 | if (err < 0) | 1201 | if (err < 0) |
1224 | return err; | 1202 | return err; |
1225 | break; | 1203 | |
1226 | } | 1204 | } |
1205 | mdelay(20); | ||
1227 | } | 1206 | } |
1228 | return 0; | 1207 | return 0; |
1229 | } | 1208 | } |
@@ -1300,10 +1279,10 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, | |||
1300 | (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) | 1279 | (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) |
1301 | mdelay(20); | 1280 | mdelay(20); |
1302 | 1281 | ||
1303 | /* Marantz/Denon devices with USB DAC functionality need a delay | 1282 | /* ITF-USB DSD based DACs functionality need a delay |
1304 | * after each class compliant request | 1283 | * after each class compliant request |
1305 | */ | 1284 | */ |
1306 | if (is_marantz_denon_dac(chip->usb_id) | 1285 | if (is_itf_usb_dsd_dac(chip->usb_id) |
1307 | && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) | 1286 | && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) |
1308 | mdelay(20); | 1287 | mdelay(20); |
1309 | 1288 | ||
@@ -1329,6 +1308,8 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, | |||
1329 | struct audioformat *fp, | 1308 | struct audioformat *fp, |
1330 | unsigned int sample_bytes) | 1309 | unsigned int sample_bytes) |
1331 | { | 1310 | { |
1311 | struct usb_interface *iface; | ||
1312 | |||
1332 | /* Playback Designs */ | 1313 | /* Playback Designs */ |
1333 | if (USB_ID_VENDOR(chip->usb_id) == 0x23ba) { | 1314 | if (USB_ID_VENDOR(chip->usb_id) == 0x23ba) { |
1334 | switch (fp->altsetting) { | 1315 | switch (fp->altsetting) { |
@@ -1390,17 +1371,52 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, | |||
1390 | break; | 1371 | break; |
1391 | } | 1372 | } |
1392 | 1373 | ||
1393 | /* Denon/Marantz devices with USB DAC functionality */ | 1374 | /* ITF-USB DSD based DACs */ |
1394 | if (is_marantz_denon_dac(chip->usb_id)) { | 1375 | if (is_itf_usb_dsd_dac(chip->usb_id)) { |
1395 | if (fp->altsetting == 2) | 1376 | iface = usb_ifnum_to_if(chip->dev, fp->iface); |
1396 | return SNDRV_PCM_FMTBIT_DSD_U32_BE; | ||
1397 | } | ||
1398 | 1377 | ||
1399 | /* TEAC devices with USB DAC functionality */ | 1378 | /* Altsetting 2 support native DSD if the num of altsets is |
1400 | if (is_teac_dsd_dac(chip->usb_id)) { | 1379 | * three (0-2), |
1401 | if (fp->altsetting == 3) | 1380 | * Altsetting 3 support native DSD if the num of altsets is |
1381 | * four (0-3). | ||
1382 | */ | ||
1383 | if (fp->altsetting == iface->num_altsetting - 1) | ||
1402 | return SNDRV_PCM_FMTBIT_DSD_U32_BE; | 1384 | return SNDRV_PCM_FMTBIT_DSD_U32_BE; |
1403 | } | 1385 | } |
1404 | 1386 | ||
1405 | return 0; | 1387 | return 0; |
1406 | } | 1388 | } |
1389 | |||
1390 | void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip, | ||
1391 | struct audioformat *fp, | ||
1392 | int stream) | ||
1393 | { | ||
1394 | switch (chip->usb_id) { | ||
1395 | case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */ | ||
1396 | /* Optoplay sets the sample rate attribute although | ||
1397 | * it seems not supporting it in fact. | ||
1398 | */ | ||
1399 | fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
1400 | break; | ||
1401 | case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ | ||
1402 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ | ||
1403 | /* doesn't set the sample rate attribute, but supports it */ | ||
1404 | fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
1405 | break; | ||
1406 | case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */ | ||
1407 | case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */ | ||
1408 | case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ | ||
1409 | case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is | ||
1410 | an older model 77d:223) */ | ||
1411 | /* | ||
1412 | * plantronics headset and Griffin iMic have set adaptive-in | ||
1413 | * although it's really not... | ||
1414 | */ | ||
1415 | fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE; | ||
1416 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
1417 | fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE; | ||
1418 | else | ||
1419 | fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC; | ||
1420 | break; | ||
1421 | } | ||
1422 | } | ||
diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h index b90c8b7caab5..a80e0ddd0736 100644 --- a/sound/usb/quirks.h +++ b/sound/usb/quirks.h | |||
@@ -42,4 +42,8 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, | |||
42 | struct audioformat *fp, | 42 | struct audioformat *fp, |
43 | unsigned int sample_bytes); | 43 | unsigned int sample_bytes); |
44 | 44 | ||
45 | void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip, | ||
46 | struct audioformat *fp, | ||
47 | int stream); | ||
48 | |||
45 | #endif /* __USBAUDIO_QUIRKS_H */ | 49 | #endif /* __USBAUDIO_QUIRKS_H */ |
diff --git a/sound/usb/stream.c b/sound/usb/stream.c index d1776e5517ff..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 */ | ||
316 | static struct | ||
317 | snd_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 | ||
464 | static struct uac2_output_terminal_descriptor * | 612 | static void * |
465 | snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface, | 613 | snd_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) |
@@ -678,48 +949,42 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) | |||
678 | INIT_LIST_HEAD(&fp->list); | 949 | INIT_LIST_HEAD(&fp->list); |
679 | 950 | ||
680 | /* some quirks for attributes here */ | 951 | /* some quirks for attributes here */ |
681 | 952 | snd_usb_audioformat_attributes_quirk(chip, fp, stream); | |
682 | switch (chip->usb_id) { | ||
683 | case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */ | ||
684 | /* Optoplay sets the sample rate attribute although | ||
685 | * it seems not supporting it in fact. | ||
686 | */ | ||
687 | fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
688 | break; | ||
689 | case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */ | ||
690 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ | ||
691 | /* doesn't set the sample rate attribute, but supports it */ | ||
692 | fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE; | ||
693 | break; | ||
694 | case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */ | ||
695 | case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */ | ||
696 | case USB_ID(0x047f, 0x0ca1): /* plantronics headset */ | ||
697 | case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is | ||
698 | an older model 77d:223) */ | ||
699 | /* | ||
700 | * plantronics headset and Griffin iMic have set adaptive-in | ||
701 | * although it's really not... | ||
702 | */ | ||
703 | fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE; | ||
704 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
705 | fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE; | ||
706 | else | ||
707 | fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC; | ||
708 | break; | ||
709 | } | ||
710 | 953 | ||
711 | /* ok, let's parse further... */ | 954 | /* ok, let's parse further... */ |
712 | if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream) < 0) { | 955 | if (protocol == UAC_VERSION_1 || protocol == UAC_VERSION_2) { |
713 | kfree(fp->rate_table); | 956 | if (snd_usb_parse_audio_format(chip, fp, format, |
714 | kfree(fp); | 957 | fmt, stream) < 0) { |
715 | fp = NULL; | 958 | kfree(fp->rate_table); |
716 | 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 | } | ||
717 | } | 977 | } |
718 | 978 | ||
719 | /* Create chmap */ | 979 | /* Create chmap */ |
720 | if (fp->channels != num_channels) | 980 | if (fp->channels != num_channels) |
721 | chconfig = 0; | 981 | chconfig = 0; |
722 | 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); | ||
723 | 988 | ||
724 | 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); |
725 | err = snd_usb_add_audio_stream(chip, stream, fp); | 990 | err = snd_usb_add_audio_stream(chip, stream, fp); |