1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 */
4
5 #include <linux/cleanup.h>
6 #include <linux/err.h>
7 #include <linux/init.h>
8 #include <linux/slab.h>
9 #include <linux/string.h>
10 #include <linux/usb.h>
11 #include <linux/usb/audio.h>
12 #include <linux/usb/midi.h>
13 #include <linux/bits.h>
14
15 #include <sound/control.h>
16 #include <sound/core.h>
17 #include <sound/info.h>
18 #include <sound/pcm.h>
19
20 #include "usbaudio.h"
21 #include "card.h"
22 #include "mixer.h"
23 #include "mixer_quirks.h"
24 #include "midi.h"
25 #include "midi2.h"
26 #include "quirks.h"
27 #include "helper.h"
28 #include "endpoint.h"
29 #include "pcm.h"
30 #include "clock.h"
31 #include "stream.h"
32
33 /*
34 * handle the quirks for the contained interfaces
35 */
create_composite_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk_comp)36 static int create_composite_quirk(struct snd_usb_audio *chip,
37 struct usb_interface *iface,
38 struct usb_driver *driver,
39 const struct snd_usb_audio_quirk *quirk_comp)
40 {
41 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
42 const struct snd_usb_audio_quirk *quirk;
43 int err;
44
45 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
46 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
47 if (!iface)
48 continue;
49 if (quirk->ifnum != probed_ifnum &&
50 usb_interface_claimed(iface))
51 continue;
52 err = snd_usb_create_quirk(chip, iface, driver, quirk);
53 if (err < 0)
54 return err;
55 }
56
57 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
58 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
59 if (!iface)
60 continue;
61 if (quirk->ifnum != probed_ifnum &&
62 !usb_interface_claimed(iface)) {
63 err = usb_driver_claim_interface(driver, iface,
64 USB_AUDIO_IFACE_UNUSED);
65 if (err < 0)
66 return err;
67 }
68 }
69
70 return 0;
71 }
72
ignore_interface_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)73 static int ignore_interface_quirk(struct snd_usb_audio *chip,
74 struct usb_interface *iface,
75 struct usb_driver *driver,
76 const struct snd_usb_audio_quirk *quirk)
77 {
78 return 0;
79 }
80
81
create_any_midi_quirk(struct snd_usb_audio * chip,struct usb_interface * intf,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)82 static int create_any_midi_quirk(struct snd_usb_audio *chip,
83 struct usb_interface *intf,
84 struct usb_driver *driver,
85 const struct snd_usb_audio_quirk *quirk)
86 {
87 return snd_usb_midi_v2_create(chip, intf, quirk, 0);
88 }
89
90 /*
91 * create a stream for an interface with proper descriptors
92 */
create_standard_audio_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)93 static int create_standard_audio_quirk(struct snd_usb_audio *chip,
94 struct usb_interface *iface,
95 struct usb_driver *driver,
96 const struct snd_usb_audio_quirk *quirk)
97 {
98 struct usb_host_interface *alts;
99 struct usb_interface_descriptor *altsd;
100 int err;
101
102 alts = &iface->altsetting[0];
103 altsd = get_iface_desc(alts);
104 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
105 if (err < 0) {
106 usb_audio_err(chip, "cannot setup if %d: error %d\n",
107 altsd->bInterfaceNumber, err);
108 return err;
109 }
110 /* reset the current interface */
111 usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
112 return 0;
113 }
114
115 /* create the audio stream and the corresponding endpoints from the fixed
116 * audioformat object; this is used for quirks with the fixed EPs
117 */
add_audio_stream_from_fixed_fmt(struct snd_usb_audio * chip,struct audioformat * fp)118 static int add_audio_stream_from_fixed_fmt(struct snd_usb_audio *chip,
119 struct audioformat *fp)
120 {
121 int stream, err;
122
123 stream = (fp->endpoint & USB_DIR_IN) ?
124 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
125
126 snd_usb_audioformat_set_sync_ep(chip, fp);
127
128 err = snd_usb_add_audio_stream(chip, stream, fp);
129 if (err < 0)
130 return err;
131
132 err = snd_usb_add_endpoint(chip, fp->endpoint,
133 SND_USB_ENDPOINT_TYPE_DATA);
134 if (err < 0)
135 return err;
136
137 if (fp->sync_ep) {
138 err = snd_usb_add_endpoint(chip, fp->sync_ep,
139 fp->implicit_fb ?
140 SND_USB_ENDPOINT_TYPE_DATA :
141 SND_USB_ENDPOINT_TYPE_SYNC);
142 if (err < 0)
143 return err;
144 }
145
146 return 0;
147 }
148
149 /*
150 * create a stream for an endpoint/altsetting without proper descriptors
151 */
create_fixed_stream_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)152 static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
153 struct usb_interface *iface,
154 struct usb_driver *driver,
155 const struct snd_usb_audio_quirk *quirk)
156 {
157 struct audioformat *fp;
158 struct usb_host_interface *alts;
159 struct usb_interface_descriptor *altsd;
160 unsigned *rate_table = NULL;
161 int err;
162
163 fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
164 if (!fp)
165 return -ENOMEM;
166
167 INIT_LIST_HEAD(&fp->list);
168 if (fp->nr_rates > MAX_NR_RATES) {
169 kfree(fp);
170 return -EINVAL;
171 }
172 if (fp->nr_rates > 0) {
173 rate_table = kmemdup_array(fp->rate_table, fp->nr_rates, sizeof(int),
174 GFP_KERNEL);
175 if (!rate_table) {
176 kfree(fp);
177 return -ENOMEM;
178 }
179 fp->rate_table = rate_table;
180 }
181
182 if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
183 fp->altset_idx >= iface->num_altsetting) {
184 err = -EINVAL;
185 goto error;
186 }
187 alts = &iface->altsetting[fp->altset_idx];
188 altsd = get_iface_desc(alts);
189 if (altsd->bNumEndpoints <= fp->ep_idx) {
190 err = -EINVAL;
191 goto error;
192 }
193
194 fp->protocol = altsd->bInterfaceProtocol;
195
196 if (fp->datainterval == 0)
197 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
198 if (fp->maxpacksize == 0)
199 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, fp->ep_idx)->wMaxPacketSize);
200 if (!fp->fmt_type)
201 fp->fmt_type = UAC_FORMAT_TYPE_I;
202
203 err = add_audio_stream_from_fixed_fmt(chip, fp);
204 if (err < 0)
205 goto error;
206
207 usb_set_interface(chip->dev, fp->iface, 0);
208 snd_usb_init_pitch(chip, fp);
209 snd_usb_init_sample_rate(chip, fp, fp->rate_max);
210 return 0;
211
212 error:
213 list_del(&fp->list); /* unlink for avoiding double-free */
214 kfree(fp);
215 kfree(rate_table);
216 return err;
217 }
218
create_auto_pcm_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver)219 static int create_auto_pcm_quirk(struct snd_usb_audio *chip,
220 struct usb_interface *iface,
221 struct usb_driver *driver)
222 {
223 struct usb_host_interface *alts;
224 struct usb_interface_descriptor *altsd;
225 struct usb_endpoint_descriptor *epd;
226 struct uac1_as_header_descriptor *ashd;
227 struct uac_format_type_i_discrete_descriptor *fmtd;
228
229 /*
230 * Most Roland/Yamaha audio streaming interfaces have more or less
231 * standard descriptors, but older devices might lack descriptors, and
232 * future ones might change, so ensure that we fail silently if the
233 * interface doesn't look exactly right.
234 */
235
236 /* must have a non-zero altsetting for streaming */
237 if (iface->num_altsetting < 2)
238 return -ENODEV;
239 alts = &iface->altsetting[1];
240 altsd = get_iface_desc(alts);
241
242 /* must have an isochronous endpoint for streaming */
243 if (altsd->bNumEndpoints < 1)
244 return -ENODEV;
245 epd = get_endpoint(alts, 0);
246 if (!usb_endpoint_xfer_isoc(epd))
247 return -ENODEV;
248
249 /* must have format descriptors */
250 ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
251 UAC_AS_GENERAL);
252 fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
253 UAC_FORMAT_TYPE);
254 if (!ashd || ashd->bLength < 7 ||
255 !fmtd || fmtd->bLength < 8)
256 return -ENODEV;
257
258 return create_standard_audio_quirk(chip, iface, driver, NULL);
259 }
260
create_yamaha_midi_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,struct usb_host_interface * alts)261 static int create_yamaha_midi_quirk(struct snd_usb_audio *chip,
262 struct usb_interface *iface,
263 struct usb_driver *driver,
264 struct usb_host_interface *alts)
265 {
266 static const struct snd_usb_audio_quirk yamaha_midi_quirk = {
267 .type = QUIRK_MIDI_YAMAHA
268 };
269 struct usb_midi_in_jack_descriptor *injd;
270 struct usb_midi_out_jack_descriptor *outjd;
271
272 /* must have some valid jack descriptors */
273 injd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
274 NULL, USB_MS_MIDI_IN_JACK);
275 outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
276 NULL, USB_MS_MIDI_OUT_JACK);
277 if (!injd && !outjd)
278 return -ENODEV;
279 if ((injd && !snd_usb_validate_midi_desc(injd)) ||
280 (outjd && !snd_usb_validate_midi_desc(outjd)))
281 return -ENODEV;
282 if (injd && (injd->bLength < 5 ||
283 (injd->bJackType != USB_MS_EMBEDDED &&
284 injd->bJackType != USB_MS_EXTERNAL)))
285 return -ENODEV;
286 if (outjd && (outjd->bLength < 6 ||
287 (outjd->bJackType != USB_MS_EMBEDDED &&
288 outjd->bJackType != USB_MS_EXTERNAL)))
289 return -ENODEV;
290 return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk);
291 }
292
create_roland_midi_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,struct usb_host_interface * alts)293 static int create_roland_midi_quirk(struct snd_usb_audio *chip,
294 struct usb_interface *iface,
295 struct usb_driver *driver,
296 struct usb_host_interface *alts)
297 {
298 static const struct snd_usb_audio_quirk roland_midi_quirk = {
299 .type = QUIRK_MIDI_ROLAND
300 };
301 u8 *roland_desc = NULL;
302
303 /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
304 for (;;) {
305 roland_desc = snd_usb_find_csint_desc(alts->extra,
306 alts->extralen,
307 roland_desc, 0xf1);
308 if (!roland_desc)
309 return -ENODEV;
310 if (roland_desc[0] < 6 || roland_desc[3] != 2)
311 continue;
312 return create_any_midi_quirk(chip, iface, driver,
313 &roland_midi_quirk);
314 }
315 }
316
create_std_midi_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,struct usb_host_interface * alts)317 static int create_std_midi_quirk(struct snd_usb_audio *chip,
318 struct usb_interface *iface,
319 struct usb_driver *driver,
320 struct usb_host_interface *alts)
321 {
322 struct usb_ms_header_descriptor *mshd;
323 struct usb_ms_endpoint_descriptor *msepd;
324
325 /* must have the MIDIStreaming interface header descriptor*/
326 mshd = (struct usb_ms_header_descriptor *)alts->extra;
327 if (alts->extralen < 7 ||
328 mshd->bLength < 7 ||
329 mshd->bDescriptorType != USB_DT_CS_INTERFACE ||
330 mshd->bDescriptorSubtype != USB_MS_HEADER)
331 return -ENODEV;
332 /* must have the MIDIStreaming endpoint descriptor*/
333 msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra;
334 if (alts->endpoint[0].extralen < 4 ||
335 msepd->bLength < 4 ||
336 msepd->bDescriptorType != USB_DT_CS_ENDPOINT ||
337 msepd->bDescriptorSubtype != UAC_MS_GENERAL ||
338 msepd->bNumEmbMIDIJack < 1 ||
339 msepd->bNumEmbMIDIJack > 16)
340 return -ENODEV;
341
342 return create_any_midi_quirk(chip, iface, driver, NULL);
343 }
344
create_auto_midi_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver)345 static int create_auto_midi_quirk(struct snd_usb_audio *chip,
346 struct usb_interface *iface,
347 struct usb_driver *driver)
348 {
349 struct usb_host_interface *alts;
350 struct usb_interface_descriptor *altsd;
351 struct usb_endpoint_descriptor *epd;
352 int err;
353
354 alts = &iface->altsetting[0];
355 altsd = get_iface_desc(alts);
356
357 /* must have at least one bulk/interrupt endpoint for streaming */
358 if (altsd->bNumEndpoints < 1)
359 return -ENODEV;
360 epd = get_endpoint(alts, 0);
361 if (!usb_endpoint_xfer_bulk(epd) &&
362 !usb_endpoint_xfer_int(epd))
363 return -ENODEV;
364
365 switch (USB_ID_VENDOR(chip->usb_id)) {
366 case 0x0499: /* Yamaha */
367 err = create_yamaha_midi_quirk(chip, iface, driver, alts);
368 if (err != -ENODEV)
369 return err;
370 break;
371 case 0x0582: /* Roland */
372 err = create_roland_midi_quirk(chip, iface, driver, alts);
373 if (err != -ENODEV)
374 return err;
375 break;
376 }
377
378 return create_std_midi_quirk(chip, iface, driver, alts);
379 }
380
create_autodetect_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)381 static int create_autodetect_quirk(struct snd_usb_audio *chip,
382 struct usb_interface *iface,
383 struct usb_driver *driver,
384 const struct snd_usb_audio_quirk *quirk)
385 {
386 int err;
387
388 err = create_auto_pcm_quirk(chip, iface, driver);
389 if (err == -ENODEV)
390 err = create_auto_midi_quirk(chip, iface, driver);
391 return err;
392 }
393
394 /*
395 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
396 * The only way to detect the sample rate is by looking at wMaxPacketSize.
397 */
create_uaxx_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)398 static int create_uaxx_quirk(struct snd_usb_audio *chip,
399 struct usb_interface *iface,
400 struct usb_driver *driver,
401 const struct snd_usb_audio_quirk *quirk)
402 {
403 static const struct audioformat ua_format = {
404 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
405 .channels = 2,
406 .fmt_type = UAC_FORMAT_TYPE_I,
407 .altsetting = 1,
408 .altset_idx = 1,
409 .rates = SNDRV_PCM_RATE_CONTINUOUS,
410 };
411 struct usb_host_interface *alts;
412 struct usb_interface_descriptor *altsd;
413 struct audioformat *fp;
414 int err;
415
416 /* both PCM and MIDI interfaces have 2 or more altsettings */
417 if (iface->num_altsetting < 2)
418 return -ENXIO;
419 alts = &iface->altsetting[1];
420 altsd = get_iface_desc(alts);
421
422 if (altsd->bNumEndpoints == 2) {
423 static const struct snd_usb_midi_endpoint_info ua700_ep = {
424 .out_cables = 0x0003,
425 .in_cables = 0x0003
426 };
427 static const struct snd_usb_audio_quirk ua700_quirk = {
428 .type = QUIRK_MIDI_FIXED_ENDPOINT,
429 .data = &ua700_ep
430 };
431 static const struct snd_usb_midi_endpoint_info uaxx_ep = {
432 .out_cables = 0x0001,
433 .in_cables = 0x0001
434 };
435 static const struct snd_usb_audio_quirk uaxx_quirk = {
436 .type = QUIRK_MIDI_FIXED_ENDPOINT,
437 .data = &uaxx_ep
438 };
439 const struct snd_usb_audio_quirk *quirk =
440 chip->usb_id == USB_ID(0x0582, 0x002b)
441 ? &ua700_quirk : &uaxx_quirk;
442 return __snd_usbmidi_create(chip->card, iface,
443 &chip->midi_list, quirk,
444 chip->usb_id,
445 &chip->num_rawmidis);
446 }
447
448 if (altsd->bNumEndpoints != 1)
449 return -ENXIO;
450
451 fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
452 if (!fp)
453 return -ENOMEM;
454
455 fp->iface = altsd->bInterfaceNumber;
456 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
457 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
458 fp->datainterval = 0;
459 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
460 INIT_LIST_HEAD(&fp->list);
461
462 switch (fp->maxpacksize) {
463 case 0x120:
464 fp->rate_max = fp->rate_min = 44100;
465 break;
466 case 0x138:
467 case 0x140:
468 fp->rate_max = fp->rate_min = 48000;
469 break;
470 case 0x258:
471 case 0x260:
472 fp->rate_max = fp->rate_min = 96000;
473 break;
474 default:
475 usb_audio_err(chip, "unknown sample rate\n");
476 kfree(fp);
477 return -ENXIO;
478 }
479
480 err = add_audio_stream_from_fixed_fmt(chip, fp);
481 if (err < 0) {
482 list_del(&fp->list); /* unlink for avoiding double-free */
483 kfree(fp);
484 return err;
485 }
486 usb_set_interface(chip->dev, fp->iface, 0);
487 return 0;
488 }
489
490 /*
491 * Create a standard mixer for the specified interface.
492 */
create_standard_mixer_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)493 static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
494 struct usb_interface *iface,
495 struct usb_driver *driver,
496 const struct snd_usb_audio_quirk *quirk)
497 {
498 if (quirk->ifnum < 0)
499 return 0;
500
501 return snd_usb_create_mixer(chip, quirk->ifnum);
502 }
503
504 /*
505 * audio-interface quirks
506 *
507 * returns zero if no standard audio/MIDI parsing is needed.
508 * returns a positive value if standard audio/midi interfaces are parsed
509 * after this.
510 * returns a negative value at error.
511 */
snd_usb_create_quirk(struct snd_usb_audio * chip,struct usb_interface * iface,struct usb_driver * driver,const struct snd_usb_audio_quirk * quirk)512 int snd_usb_create_quirk(struct snd_usb_audio *chip,
513 struct usb_interface *iface,
514 struct usb_driver *driver,
515 const struct snd_usb_audio_quirk *quirk)
516 {
517 typedef int (*quirk_func_t)(struct snd_usb_audio *,
518 struct usb_interface *,
519 struct usb_driver *,
520 const struct snd_usb_audio_quirk *);
521 static const quirk_func_t quirk_funcs[] = {
522 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
523 [QUIRK_COMPOSITE] = create_composite_quirk,
524 [QUIRK_AUTODETECT] = create_autodetect_quirk,
525 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
526 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
527 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
528 [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
529 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
530 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
531 [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
532 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
533 [QUIRK_MIDI_CME] = create_any_midi_quirk,
534 [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
535 [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
536 [QUIRK_MIDI_CH345] = create_any_midi_quirk,
537 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
538 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
539 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
540 [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
541 };
542
543 if (quirk->type < QUIRK_TYPE_COUNT) {
544 return quirk_funcs[quirk->type](chip, iface, driver, quirk);
545 } else {
546 usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
547 return -ENXIO;
548 }
549 }
550
551 /*
552 * boot quirks
553 */
554
555 #define EXTIGY_FIRMWARE_SIZE_OLD 794
556 #define EXTIGY_FIRMWARE_SIZE_NEW 483
557
snd_usb_extigy_boot_quirk(struct usb_device * dev,struct usb_interface * intf)558 static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
559 {
560 struct usb_host_config *config = dev->actconfig;
561 int err;
562
563 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
564 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
565 dev_dbg(&dev->dev, "sending Extigy boot sequence...\n");
566 /* Send message to force it to reconnect with full interface. */
567 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
568 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
569 if (err < 0)
570 dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
571 struct usb_device_descriptor *new_device_descriptor __free(kfree) =
572 kmalloc_obj(*new_device_descriptor);
573 if (!new_device_descriptor)
574 return -ENOMEM;
575 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
576 new_device_descriptor, sizeof(*new_device_descriptor));
577 if (err < 0)
578 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
579 if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
580 dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
581 new_device_descriptor->bNumConfigurations);
582 else
583 memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
584 err = usb_reset_configuration(dev);
585 if (err < 0)
586 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
587 dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
588 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
589 return -ENODEV; /* quit this anyway */
590 }
591 return 0;
592 }
593
snd_usb_audigy2nx_boot_quirk(struct usb_device * dev)594 static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
595 {
596 u8 buf = 1;
597
598 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
599 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
600 0, 0, &buf, 1);
601 if (buf == 0) {
602 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
603 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
604 1, 2000, NULL, 0);
605 return -ENODEV;
606 }
607 return 0;
608 }
609
snd_usb_fasttrackpro_boot_quirk(struct usb_device * dev)610 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
611 {
612 int err;
613
614 if (dev->actconfig->desc.bConfigurationValue == 1) {
615 dev_info(&dev->dev,
616 "Fast Track Pro switching to config #2\n");
617 /* This function has to be available by the usb core module.
618 * if it is not avialable the boot quirk has to be left out
619 * and the configuration has to be set by udev or hotplug
620 * rules
621 */
622 err = usb_driver_set_configuration(dev, 2);
623 if (err < 0)
624 dev_dbg(&dev->dev,
625 "error usb_driver_set_configuration: %d\n",
626 err);
627 /* Always return an error, so that we stop creating a device
628 that will just be destroyed and recreated with a new
629 configuration */
630 return -ENODEV;
631 } else
632 dev_info(&dev->dev, "Fast Track Pro config OK\n");
633
634 return 0;
635 }
636
637 /*
638 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
639 * documented in the device's data sheet.
640 */
snd_usb_cm106_write_int_reg(struct usb_device * dev,int reg,u16 value)641 static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
642 {
643 u8 buf[4];
644 buf[0] = 0x20;
645 buf[1] = value & 0xff;
646 buf[2] = (value >> 8) & 0xff;
647 buf[3] = reg;
648 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
649 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
650 0, 0, &buf, 4);
651 }
652
snd_usb_cm106_boot_quirk(struct usb_device * dev)653 static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
654 {
655 /*
656 * Enable line-out driver mode, set headphone source to front
657 * channels, enable stereo mic.
658 */
659 return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
660 }
661
662 /*
663 * CM6206 registers from the CM6206 datasheet rev 2.1
664 */
665 #define CM6206_REG0_DMA_MASTER BIT(15)
666 #define CM6206_REG0_SPDIFO_RATE_48K (2 << 12)
667 #define CM6206_REG0_SPDIFO_RATE_96K (7 << 12)
668 /* Bit 4 thru 11 is the S/PDIF category code */
669 #define CM6206_REG0_SPDIFO_CAT_CODE_GENERAL (0 << 4)
670 #define CM6206_REG0_SPDIFO_EMPHASIS_CD BIT(3)
671 #define CM6206_REG0_SPDIFO_COPYRIGHT_NA BIT(2)
672 #define CM6206_REG0_SPDIFO_NON_AUDIO BIT(1)
673 #define CM6206_REG0_SPDIFO_PRO_FORMAT BIT(0)
674
675 #define CM6206_REG1_TEST_SEL_CLK BIT(14)
676 #define CM6206_REG1_PLLBIN_EN BIT(13)
677 #define CM6206_REG1_SOFT_MUTE_EN BIT(12)
678 #define CM6206_REG1_GPIO4_OUT BIT(11)
679 #define CM6206_REG1_GPIO4_OE BIT(10)
680 #define CM6206_REG1_GPIO3_OUT BIT(9)
681 #define CM6206_REG1_GPIO3_OE BIT(8)
682 #define CM6206_REG1_GPIO2_OUT BIT(7)
683 #define CM6206_REG1_GPIO2_OE BIT(6)
684 #define CM6206_REG1_GPIO1_OUT BIT(5)
685 #define CM6206_REG1_GPIO1_OE BIT(4)
686 #define CM6206_REG1_SPDIFO_INVALID BIT(3)
687 #define CM6206_REG1_SPDIF_LOOP_EN BIT(2)
688 #define CM6206_REG1_SPDIFO_DIS BIT(1)
689 #define CM6206_REG1_SPDIFI_MIX BIT(0)
690
691 #define CM6206_REG2_DRIVER_ON BIT(15)
692 #define CM6206_REG2_HEADP_SEL_SIDE_CHANNELS (0 << 13)
693 #define CM6206_REG2_HEADP_SEL_SURROUND_CHANNELS (1 << 13)
694 #define CM6206_REG2_HEADP_SEL_CENTER_SUBW (2 << 13)
695 #define CM6206_REG2_HEADP_SEL_FRONT_CHANNELS (3 << 13)
696 #define CM6206_REG2_MUTE_HEADPHONE_RIGHT BIT(12)
697 #define CM6206_REG2_MUTE_HEADPHONE_LEFT BIT(11)
698 #define CM6206_REG2_MUTE_REAR_SURROUND_RIGHT BIT(10)
699 #define CM6206_REG2_MUTE_REAR_SURROUND_LEFT BIT(9)
700 #define CM6206_REG2_MUTE_SIDE_SURROUND_RIGHT BIT(8)
701 #define CM6206_REG2_MUTE_SIDE_SURROUND_LEFT BIT(7)
702 #define CM6206_REG2_MUTE_SUBWOOFER BIT(6)
703 #define CM6206_REG2_MUTE_CENTER BIT(5)
704 #define CM6206_REG2_MUTE_RIGHT_FRONT BIT(3)
705 #define CM6206_REG2_MUTE_LEFT_FRONT BIT(3)
706 #define CM6206_REG2_EN_BTL BIT(2)
707 #define CM6206_REG2_MCUCLKSEL_1_5_MHZ (0)
708 #define CM6206_REG2_MCUCLKSEL_3_MHZ (1)
709 #define CM6206_REG2_MCUCLKSEL_6_MHZ (2)
710 #define CM6206_REG2_MCUCLKSEL_12_MHZ (3)
711
712 /* Bit 11..13 sets the sensitivity to FLY tuner volume control VP/VD signal */
713 #define CM6206_REG3_FLYSPEED_DEFAULT (2 << 11)
714 #define CM6206_REG3_VRAP25EN BIT(10)
715 #define CM6206_REG3_MSEL1 BIT(9)
716 #define CM6206_REG3_SPDIFI_RATE_44_1K BIT(0 << 7)
717 #define CM6206_REG3_SPDIFI_RATE_48K BIT(2 << 7)
718 #define CM6206_REG3_SPDIFI_RATE_32K BIT(3 << 7)
719 #define CM6206_REG3_PINSEL BIT(6)
720 #define CM6206_REG3_FOE BIT(5)
721 #define CM6206_REG3_ROE BIT(4)
722 #define CM6206_REG3_CBOE BIT(3)
723 #define CM6206_REG3_LOSE BIT(2)
724 #define CM6206_REG3_HPOE BIT(1)
725 #define CM6206_REG3_SPDIFI_CANREC BIT(0)
726
727 #define CM6206_REG5_DA_RSTN BIT(13)
728 #define CM6206_REG5_AD_RSTN BIT(12)
729 #define CM6206_REG5_SPDIFO_AD2SPDO BIT(12)
730 #define CM6206_REG5_SPDIFO_SEL_FRONT (0 << 9)
731 #define CM6206_REG5_SPDIFO_SEL_SIDE_SUR (1 << 9)
732 #define CM6206_REG5_SPDIFO_SEL_CEN_LFE (2 << 9)
733 #define CM6206_REG5_SPDIFO_SEL_REAR_SUR (3 << 9)
734 #define CM6206_REG5_CODECM BIT(8)
735 #define CM6206_REG5_EN_HPF BIT(7)
736 #define CM6206_REG5_T_SEL_DSDA4 BIT(6)
737 #define CM6206_REG5_T_SEL_DSDA3 BIT(5)
738 #define CM6206_REG5_T_SEL_DSDA2 BIT(4)
739 #define CM6206_REG5_T_SEL_DSDA1 BIT(3)
740 #define CM6206_REG5_T_SEL_DSDAD_NORMAL 0
741 #define CM6206_REG5_T_SEL_DSDAD_FRONT 4
742 #define CM6206_REG5_T_SEL_DSDAD_S_SURROUND 5
743 #define CM6206_REG5_T_SEL_DSDAD_CEN_LFE 6
744 #define CM6206_REG5_T_SEL_DSDAD_R_SURROUND 7
745
snd_usb_cm6206_boot_quirk(struct usb_device * dev)746 static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
747 {
748 int err = 0, reg;
749 int val[] = {
750 /*
751 * Values here are chosen based on sniffing USB traffic
752 * under Windows.
753 *
754 * REG0: DAC is master, sample rate 48kHz, no copyright
755 */
756 CM6206_REG0_SPDIFO_RATE_48K |
757 CM6206_REG0_SPDIFO_COPYRIGHT_NA,
758 /*
759 * REG1: PLL binary search enable, soft mute enable.
760 */
761 CM6206_REG1_PLLBIN_EN |
762 CM6206_REG1_SOFT_MUTE_EN,
763 /*
764 * REG2: enable output drivers,
765 * select front channels to the headphone output,
766 * then mute the headphone channels, run the MCU
767 * at 1.5 MHz.
768 */
769 CM6206_REG2_DRIVER_ON |
770 CM6206_REG2_HEADP_SEL_FRONT_CHANNELS |
771 CM6206_REG2_MUTE_HEADPHONE_RIGHT |
772 CM6206_REG2_MUTE_HEADPHONE_LEFT,
773 /*
774 * REG3: default flyspeed, set 2.5V mic bias
775 * enable all line out ports and enable SPDIF
776 */
777 CM6206_REG3_FLYSPEED_DEFAULT |
778 CM6206_REG3_VRAP25EN |
779 CM6206_REG3_FOE |
780 CM6206_REG3_ROE |
781 CM6206_REG3_CBOE |
782 CM6206_REG3_LOSE |
783 CM6206_REG3_HPOE |
784 CM6206_REG3_SPDIFI_CANREC,
785 /* REG4 is just a bunch of GPIO lines */
786 0x0000,
787 /* REG5: de-assert AD/DA reset signals */
788 CM6206_REG5_DA_RSTN |
789 CM6206_REG5_AD_RSTN };
790
791 for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
792 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
793 if (err < 0)
794 return err;
795 }
796
797 return err;
798 }
799
800 /* quirk for Plantronics GameCom 780 with CM6302 chip */
snd_usb_gamecon780_boot_quirk(struct usb_device * dev)801 static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev)
802 {
803 /* set the initial volume and don't change; other values are either
804 * too loud or silent due to firmware bug (bko#65251)
805 */
806 u8 buf[2] = { 0x74, 0xe3 };
807 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
808 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
809 UAC_FU_VOLUME << 8, 9 << 8, buf, 2);
810 }
811
812 /*
813 * Novation Twitch DJ controller
814 * Focusrite Novation Saffire 6 USB audio card
815 */
snd_usb_novation_boot_quirk(struct usb_device * dev)816 static int snd_usb_novation_boot_quirk(struct usb_device *dev)
817 {
818 /* preemptively set up the device because otherwise the
819 * raw MIDI endpoints are not active */
820 usb_set_interface(dev, 0, 1);
821 return 0;
822 }
823
824 /*
825 * This call will put the synth in "USB send" mode, i.e it will send MIDI
826 * messages through USB (this is disabled at startup). The synth will
827 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
828 * sign on its LCD. Values here are chosen based on sniffing USB traffic
829 * under Windows.
830 */
snd_usb_accessmusic_boot_quirk(struct usb_device * dev)831 static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
832 {
833 int err, actual_length;
834 /* "midi send" enable */
835 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
836 void *buf;
837
838 if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x05)))
839 return -EINVAL;
840 buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
841 if (!buf)
842 return -ENOMEM;
843 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
844 ARRAY_SIZE(seq), &actual_length, 1000);
845 kfree(buf);
846 if (err < 0)
847 return err;
848
849 return 0;
850 }
851
852 /*
853 * Some sound cards from Native Instruments are in fact compliant to the USB
854 * audio standard of version 2 and other approved USB standards, even though
855 * they come up as vendor-specific device when first connected.
856 *
857 * However, they can be told to come up with a new set of descriptors
858 * upon their next enumeration, and the interfaces announced by the new
859 * descriptors will then be handled by the kernel's class drivers. As the
860 * product ID will also change, no further checks are required.
861 */
862
snd_usb_nativeinstruments_boot_quirk(struct usb_device * dev)863 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
864 {
865 int ret;
866
867 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
868 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
869 1, 0, NULL, 0, 1000);
870
871 if (ret < 0)
872 return ret;
873
874 usb_reset_device(dev);
875
876 /* return -EAGAIN, so the creation of an audio interface for this
877 * temporary device is aborted. The device will reconnect with a
878 * new product ID */
879 return -EAGAIN;
880 }
881
mbox2_setup_48_24_magic(struct usb_device * dev)882 static void mbox2_setup_48_24_magic(struct usb_device *dev)
883 {
884 u8 srate[3];
885 u8 temp[12];
886
887 /* Choose 48000Hz permanently */
888 srate[0] = 0x80;
889 srate[1] = 0xbb;
890 srate[2] = 0x00;
891
892 /* Send the magic! */
893 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
894 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
895 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
896 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
897 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
898 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
899 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
900 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
901 return;
902 }
903
904 /* Digidesign Mbox 2 needs to load firmware onboard
905 * and driver must wait a few seconds for initialisation.
906 */
907
908 #define MBOX2_FIRMWARE_SIZE 646
909 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
910 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
911
snd_usb_mbox2_boot_quirk(struct usb_device * dev)912 static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
913 {
914 struct usb_host_config *config = dev->actconfig;
915 int err;
916 u8 bootresponse[0x12];
917 int fwsize;
918 int count;
919
920 fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
921
922 if (fwsize != MBOX2_FIRMWARE_SIZE) {
923 dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
924 return -ENODEV;
925 }
926
927 dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
928
929 count = 0;
930 bootresponse[0] = MBOX2_BOOT_LOADING;
931 while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
932 msleep(500); /* 0.5 second delay */
933 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
934 /* Control magic - load onboard firmware */
935 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
936 if (bootresponse[0] == MBOX2_BOOT_READY)
937 break;
938 dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
939 count++;
940 }
941
942 if (bootresponse[0] != MBOX2_BOOT_READY) {
943 dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
944 return -ENODEV;
945 }
946
947 dev_dbg(&dev->dev, "device initialised!\n");
948
949 struct usb_device_descriptor *new_device_descriptor __free(kfree) =
950 kmalloc_obj(*new_device_descriptor);
951 if (!new_device_descriptor)
952 return -ENOMEM;
953
954 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
955 new_device_descriptor, sizeof(*new_device_descriptor));
956 if (err < 0)
957 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
958 if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
959 dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
960 new_device_descriptor->bNumConfigurations);
961 else
962 memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
963
964 err = usb_reset_configuration(dev);
965 if (err < 0)
966 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
967 dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
968 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
969
970 mbox2_setup_48_24_magic(dev);
971
972 dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
973
974 return 0; /* Successful boot */
975 }
976
snd_usb_axefx3_boot_quirk(struct usb_device * dev)977 static int snd_usb_axefx3_boot_quirk(struct usb_device *dev)
978 {
979 int err;
980
981 dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n");
982
983 /* If the Axe-Fx III has not fully booted, it will timeout when trying
984 * to enable the audio streaming interface. A more generous timeout is
985 * used here to detect when the Axe-Fx III has finished booting as the
986 * set interface message will be acked once it has
987 */
988 err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
989 USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
990 1, 1, NULL, 0, 120000);
991 if (err < 0) {
992 dev_err(&dev->dev,
993 "failed waiting for Axe-Fx III to boot: %d\n", err);
994 return err;
995 }
996
997 dev_dbg(&dev->dev, "Axe-Fx III is now ready\n");
998
999 err = usb_set_interface(dev, 1, 0);
1000 if (err < 0)
1001 dev_dbg(&dev->dev,
1002 "error stopping Axe-Fx III interface: %d\n", err);
1003
1004 return 0;
1005 }
1006
mbox3_setup_defaults(struct usb_device * dev)1007 static void mbox3_setup_defaults(struct usb_device *dev)
1008 {
1009 /* The Mbox 3 is "little endian" */
1010 /* max volume is: 0x0000. */
1011 /* min volume is: 0x0080 (shown in little endian form) */
1012
1013 u8 com_buff[2];
1014
1015 /* Deactivate Tuner */
1016 /* on = 0x01*/
1017 /* off = 0x00*/
1018 com_buff[0] = 0x00;
1019 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1020 0x01, 0x21, 0x0003, 0x2001, &com_buff, 1);
1021
1022 /* Set clock source to Internal (as opposed to S/PDIF) */
1023 /* Internal = 0x01*/
1024 /* S/PDIF = 0x02*/
1025 com_buff[0] = 0x01;
1026 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1027 1, 0x21, 0x0100, 0x8001, &com_buff, 1);
1028
1029 /* Mute the hardware loopbacks to start the device in a known state. */
1030 com_buff[0] = 0x00;
1031 com_buff[1] = 0x80;
1032 /* Analogue input 1 left channel: */
1033 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1034 1, 0x21, 0x0110, 0x4001, &com_buff, 2);
1035 /* Analogue input 1 right channel: */
1036 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1037 1, 0x21, 0x0111, 0x4001, &com_buff, 2);
1038 /* Analogue input 2 left channel: */
1039 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1040 1, 0x21, 0x0114, 0x4001, &com_buff, 2);
1041 /* Analogue input 2 right channel: */
1042 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1043 1, 0x21, 0x0115, 0x4001, &com_buff, 2);
1044 /* Analogue input 3 left channel: */
1045 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1046 1, 0x21, 0x0118, 0x4001, &com_buff, 2);
1047 /* Analogue input 3 right channel: */
1048 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1049 1, 0x21, 0x0119, 0x4001, &com_buff, 2);
1050 /* Analogue input 4 left channel: */
1051 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1052 1, 0x21, 0x011c, 0x4001, &com_buff, 2);
1053 /* Analogue input 4 right channel: */
1054 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1055 1, 0x21, 0x011d, 0x4001, &com_buff, 2);
1056
1057 /* Set software sends to output */
1058 com_buff[0] = 0x00;
1059 com_buff[1] = 0x00;
1060 /* Analogue software return 1 left channel: */
1061 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1062 1, 0x21, 0x0100, 0x4001, &com_buff, 2);
1063 com_buff[0] = 0x00;
1064 com_buff[1] = 0x80;
1065 /* Analogue software return 1 right channel: */
1066 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1067 1, 0x21, 0x0101, 0x4001, &com_buff, 2);
1068 com_buff[0] = 0x00;
1069 com_buff[1] = 0x80;
1070 /* Analogue software return 2 left channel: */
1071 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1072 1, 0x21, 0x0104, 0x4001, &com_buff, 2);
1073 com_buff[0] = 0x00;
1074 com_buff[1] = 0x00;
1075 /* Analogue software return 2 right channel: */
1076 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1077 1, 0x21, 0x0105, 0x4001, &com_buff, 2);
1078
1079 com_buff[0] = 0x00;
1080 com_buff[1] = 0x80;
1081 /* Analogue software return 3 left channel: */
1082 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1083 1, 0x21, 0x0108, 0x4001, &com_buff, 2);
1084 /* Analogue software return 3 right channel: */
1085 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1086 1, 0x21, 0x0109, 0x4001, &com_buff, 2);
1087 /* Analogue software return 4 left channel: */
1088 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1089 1, 0x21, 0x010c, 0x4001, &com_buff, 2);
1090 /* Analogue software return 4 right channel: */
1091 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1092 1, 0x21, 0x010d, 0x4001, &com_buff, 2);
1093
1094 /* Return to muting sends */
1095 com_buff[0] = 0x00;
1096 com_buff[1] = 0x80;
1097 /* Analogue fx return left channel: */
1098 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1099 1, 0x21, 0x0120, 0x4001, &com_buff, 2);
1100 /* Analogue fx return right channel: */
1101 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1102 1, 0x21, 0x0121, 0x4001, &com_buff, 2);
1103
1104 /* Analogue software input 1 fx send: */
1105 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1106 1, 0x21, 0x0100, 0x4201, &com_buff, 2);
1107 /* Analogue software input 2 fx send: */
1108 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1109 1, 0x21, 0x0101, 0x4201, &com_buff, 2);
1110 /* Analogue software input 3 fx send: */
1111 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1112 1, 0x21, 0x0102, 0x4201, &com_buff, 2);
1113 /* Analogue software input 4 fx send: */
1114 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1115 1, 0x21, 0x0103, 0x4201, &com_buff, 2);
1116 /* Analogue input 1 fx send: */
1117 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1118 1, 0x21, 0x0104, 0x4201, &com_buff, 2);
1119 /* Analogue input 2 fx send: */
1120 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1121 1, 0x21, 0x0105, 0x4201, &com_buff, 2);
1122 /* Analogue input 3 fx send: */
1123 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1124 1, 0x21, 0x0106, 0x4201, &com_buff, 2);
1125 /* Analogue input 4 fx send: */
1126 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1127 1, 0x21, 0x0107, 0x4201, &com_buff, 2);
1128
1129 /* Toggle allowing host control */
1130 /* Not needed
1131 com_buff[0] = 0x02;
1132 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1133 3, 0x21, 0x0000, 0x2001, &com_buff, 1);
1134 */
1135
1136 /* Do not dim fx returns */
1137 com_buff[0] = 0x00;
1138 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1139 3, 0x21, 0x0002, 0x2001, &com_buff, 1);
1140
1141 /* Do not set fx returns to mono */
1142 com_buff[0] = 0x00;
1143 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1144 3, 0x21, 0x0001, 0x2001, &com_buff, 1);
1145
1146 /* Mute the S/PDIF hardware loopback
1147 * same odd volume logic here as above
1148 */
1149 com_buff[0] = 0x00;
1150 com_buff[1] = 0x80;
1151 /* S/PDIF hardware input 1 left channel */
1152 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1153 1, 0x21, 0x0112, 0x4001, &com_buff, 2);
1154 /* S/PDIF hardware input 1 right channel */
1155 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1156 1, 0x21, 0x0113, 0x4001, &com_buff, 2);
1157 /* S/PDIF hardware input 2 left channel */
1158 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1159 1, 0x21, 0x0116, 0x4001, &com_buff, 2);
1160 /* S/PDIF hardware input 2 right channel */
1161 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1162 1, 0x21, 0x0117, 0x4001, &com_buff, 2);
1163 /* S/PDIF hardware input 3 left channel */
1164 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1165 1, 0x21, 0x011a, 0x4001, &com_buff, 2);
1166 /* S/PDIF hardware input 3 right channel */
1167 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1168 1, 0x21, 0x011b, 0x4001, &com_buff, 2);
1169 /* S/PDIF hardware input 4 left channel */
1170 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1171 1, 0x21, 0x011e, 0x4001, &com_buff, 2);
1172 /* S/PDIF hardware input 4 right channel */
1173 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1174 1, 0x21, 0x011f, 0x4001, &com_buff, 2);
1175 /* S/PDIF software return 1 left channel */
1176 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1177 1, 0x21, 0x0102, 0x4001, &com_buff, 2);
1178 /* S/PDIF software return 1 right channel */
1179 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1180 1, 0x21, 0x0103, 0x4001, &com_buff, 2);
1181 /* S/PDIF software return 2 left channel */
1182 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1183 1, 0x21, 0x0106, 0x4001, &com_buff, 2);
1184 /* S/PDIF software return 2 right channel */
1185 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1186 1, 0x21, 0x0107, 0x4001, &com_buff, 2);
1187
1188 com_buff[0] = 0x00;
1189 com_buff[1] = 0x00;
1190 /* S/PDIF software return 3 left channel */
1191 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1192 1, 0x21, 0x010a, 0x4001, &com_buff, 2);
1193
1194 com_buff[0] = 0x00;
1195 com_buff[1] = 0x80;
1196 /* S/PDIF software return 3 right channel */
1197 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1198 1, 0x21, 0x010b, 0x4001, &com_buff, 2);
1199 /* S/PDIF software return 4 left channel */
1200 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1201 1, 0x21, 0x010e, 0x4001, &com_buff, 2);
1202
1203 com_buff[0] = 0x00;
1204 com_buff[1] = 0x00;
1205 /* S/PDIF software return 4 right channel */
1206 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1207 1, 0x21, 0x010f, 0x4001, &com_buff, 2);
1208
1209 com_buff[0] = 0x00;
1210 com_buff[1] = 0x80;
1211 /* S/PDIF fx returns left channel */
1212 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1213 1, 0x21, 0x0122, 0x4001, &com_buff, 2);
1214 /* S/PDIF fx returns right channel */
1215 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1216 1, 0x21, 0x0123, 0x4001, &com_buff, 2);
1217
1218 /* Set the dropdown "Effect" to the first option */
1219 /* Room1 = 0x00 */
1220 /* Room2 = 0x01 */
1221 /* Room3 = 0x02 */
1222 /* Hall 1 = 0x03 */
1223 /* Hall 2 = 0x04 */
1224 /* Plate = 0x05 */
1225 /* Delay = 0x06 */
1226 /* Echo = 0x07 */
1227 com_buff[0] = 0x00;
1228 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1229 1, 0x21, 0x0200, 0x4301, &com_buff, 1); /* max is 0xff */
1230 /* min is 0x00 */
1231
1232
1233 /* Set the effect duration to 0 */
1234 /* max is 0xffff */
1235 /* min is 0x0000 */
1236 com_buff[0] = 0x00;
1237 com_buff[1] = 0x00;
1238 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1239 1, 0x21, 0x0400, 0x4301, &com_buff, 2);
1240
1241 /* Set the effect volume and feedback to 0 */
1242 /* max is 0xff */
1243 /* min is 0x00 */
1244 com_buff[0] = 0x00;
1245 /* feedback: */
1246 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1247 1, 0x21, 0x0500, 0x4301, &com_buff, 1);
1248 /* volume: */
1249 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1250 1, 0x21, 0x0300, 0x4301, &com_buff, 1);
1251
1252 /* Set soft button hold duration */
1253 /* 0x03 = 250ms */
1254 /* 0x05 = 500ms DEFAULT */
1255 /* 0x08 = 750ms */
1256 /* 0x0a = 1sec */
1257 com_buff[0] = 0x05;
1258 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1259 3, 0x21, 0x0005, 0x2001, &com_buff, 1);
1260
1261 /* Use dim LEDs for button of state */
1262 com_buff[0] = 0x00;
1263 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1264 3, 0x21, 0x0004, 0x2001, &com_buff, 1);
1265 }
1266
1267 #define MBOX3_DESCRIPTOR_SIZE 464
1268
snd_usb_mbox3_boot_quirk(struct usb_device * dev)1269 static int snd_usb_mbox3_boot_quirk(struct usb_device *dev)
1270 {
1271 struct usb_host_config *config = dev->actconfig;
1272 int err;
1273 int descriptor_size;
1274
1275 descriptor_size = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
1276
1277 if (descriptor_size != MBOX3_DESCRIPTOR_SIZE) {
1278 dev_err(&dev->dev, "MBOX3: Invalid descriptor size=%d.\n", descriptor_size);
1279 return -ENODEV;
1280 }
1281
1282 dev_dbg(&dev->dev, "MBOX3: device initialised!\n");
1283
1284 struct usb_device_descriptor *new_device_descriptor __free(kfree) =
1285 kmalloc_obj(*new_device_descriptor);
1286 if (!new_device_descriptor)
1287 return -ENOMEM;
1288
1289 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
1290 new_device_descriptor, sizeof(*new_device_descriptor));
1291 if (err < 0)
1292 dev_dbg(&dev->dev, "MBOX3: error usb_get_descriptor: %d\n", err);
1293 if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
1294 dev_dbg(&dev->dev, "MBOX3: error too large bNumConfigurations: %d\n",
1295 new_device_descriptor->bNumConfigurations);
1296 else
1297 memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
1298
1299 err = usb_reset_configuration(dev);
1300 if (err < 0)
1301 dev_dbg(&dev->dev, "MBOX3: error usb_reset_configuration: %d\n", err);
1302
1303 dev_dbg(&dev->dev, "MBOX3: new boot length = %d\n",
1304 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
1305
1306 mbox3_setup_defaults(dev);
1307 dev_info(&dev->dev, "MBOX3: Initialized.");
1308
1309 return 0; /* Successful boot */
1310 }
1311
1312 #define MICROBOOK_BUF_SIZE 128
1313
snd_usb_motu_microbookii_communicate(struct usb_device * dev,u8 * buf,int buf_size,int * length)1314 static int snd_usb_motu_microbookii_communicate(struct usb_device *dev, u8 *buf,
1315 int buf_size, int *length)
1316 {
1317 int err, actual_length;
1318
1319 if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x01)))
1320 return -EINVAL;
1321 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x01), buf, *length,
1322 &actual_length, 1000);
1323 if (err < 0)
1324 return err;
1325
1326 print_hex_dump(KERN_DEBUG, "MicroBookII snd: ", DUMP_PREFIX_NONE, 16, 1,
1327 buf, actual_length, false);
1328
1329 memset(buf, 0, buf_size);
1330
1331 if (usb_pipe_type_check(dev, usb_rcvintpipe(dev, 0x82)))
1332 return -EINVAL;
1333 err = usb_interrupt_msg(dev, usb_rcvintpipe(dev, 0x82), buf, buf_size,
1334 &actual_length, 1000);
1335 if (err < 0)
1336 return err;
1337
1338 print_hex_dump(KERN_DEBUG, "MicroBookII rcv: ", DUMP_PREFIX_NONE, 16, 1,
1339 buf, actual_length, false);
1340
1341 *length = actual_length;
1342 return 0;
1343 }
1344
snd_usb_motu_microbookii_boot_quirk(struct usb_device * dev)1345 static int snd_usb_motu_microbookii_boot_quirk(struct usb_device *dev)
1346 {
1347 int err, actual_length, poll_attempts = 0;
1348 static const u8 set_samplerate_seq[] = { 0x00, 0x00, 0x00, 0x00,
1349 0x00, 0x00, 0x0b, 0x14,
1350 0x00, 0x00, 0x00, 0x01 };
1351 static const u8 poll_ready_seq[] = { 0x00, 0x04, 0x00, 0x00,
1352 0x00, 0x00, 0x0b, 0x18 };
1353 u8 *buf = kzalloc(MICROBOOK_BUF_SIZE, GFP_KERNEL);
1354
1355 if (!buf)
1356 return -ENOMEM;
1357
1358 dev_info(&dev->dev, "Waiting for MOTU Microbook II to boot up...\n");
1359
1360 /* First we tell the device which sample rate to use. */
1361 memcpy(buf, set_samplerate_seq, sizeof(set_samplerate_seq));
1362 actual_length = sizeof(set_samplerate_seq);
1363 err = snd_usb_motu_microbookii_communicate(dev, buf, MICROBOOK_BUF_SIZE,
1364 &actual_length);
1365
1366 if (err < 0) {
1367 dev_err(&dev->dev,
1368 "failed setting the sample rate for Motu MicroBook II: %d\n",
1369 err);
1370 goto free_buf;
1371 }
1372
1373 /* Then we poll every 100 ms until the device informs of its readiness. */
1374 while (true) {
1375 if (++poll_attempts > 100) {
1376 dev_err(&dev->dev,
1377 "failed booting Motu MicroBook II: timeout\n");
1378 err = -ENODEV;
1379 goto free_buf;
1380 }
1381
1382 memset(buf, 0, MICROBOOK_BUF_SIZE);
1383 memcpy(buf, poll_ready_seq, sizeof(poll_ready_seq));
1384
1385 actual_length = sizeof(poll_ready_seq);
1386 err = snd_usb_motu_microbookii_communicate(
1387 dev, buf, MICROBOOK_BUF_SIZE, &actual_length);
1388 if (err < 0) {
1389 dev_err(&dev->dev,
1390 "failed booting Motu MicroBook II: communication error %d\n",
1391 err);
1392 goto free_buf;
1393 }
1394
1395 /* the device signals its readiness through a message of the
1396 * form
1397 * XX 06 00 00 00 00 0b 18 00 00 00 01
1398 * If the device is not yet ready to accept audio data, the
1399 * last byte of that sequence is 00.
1400 */
1401 if (actual_length == 12 && buf[actual_length - 1] == 1)
1402 break;
1403
1404 msleep(100);
1405 }
1406
1407 dev_info(&dev->dev, "MOTU MicroBook II ready\n");
1408
1409 free_buf:
1410 kfree(buf);
1411 return err;
1412 }
1413
snd_usb_motu_m_series_boot_quirk(struct usb_device * dev)1414 static int snd_usb_motu_m_series_boot_quirk(struct usb_device *dev)
1415 {
1416 msleep(4000);
1417
1418 return 0;
1419 }
1420
snd_usb_rme_digiface_boot_quirk(struct usb_device * dev)1421 static int snd_usb_rme_digiface_boot_quirk(struct usb_device *dev)
1422 {
1423 /* Disable mixer, internal clock, all outputs ADAT, 48kHz, TMS off */
1424 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1425 16, 0x40, 0x2410, 0x7fff, NULL, 0);
1426 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1427 18, 0x40, 0x0104, 0xffff, NULL, 0);
1428
1429 /* Disable loopback for all inputs */
1430 for (int ch = 0; ch < 32; ch++)
1431 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1432 22, 0x40, 0x400, ch, NULL, 0);
1433
1434 /* Unity gain for all outputs */
1435 for (int ch = 0; ch < 34; ch++)
1436 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1437 21, 0x40, 0x9000, 0x100 + ch, NULL, 0);
1438
1439 return 0;
1440 }
1441
1442 /*
1443 * Setup quirks
1444 */
1445 #define MAUDIO_SET 0x01 /* parse device_setup */
1446 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
1447 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
1448 #define MAUDIO_SET_96K 0x04 /* 48-96kHz rate if set, 8-48kHz otherwise */
1449 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
1450 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
1451 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
1452 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48kHz+Digital Input */
1453 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48kHz+No Digital Input */
1454 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48kHz+Digital Input */
1455 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48kHz+No Digital Input */
1456
quattro_skip_setting_quirk(struct snd_usb_audio * chip,int iface,int altno)1457 static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
1458 int iface, int altno)
1459 {
1460 /* Reset ALL ifaces to 0 altsetting.
1461 * Call it for every possible altsetting of every interface.
1462 */
1463 usb_set_interface(chip->dev, iface, 0);
1464 if (chip->setup & MAUDIO_SET) {
1465 if (chip->setup & MAUDIO_SET_COMPATIBLE) {
1466 if (iface != 1 && iface != 2)
1467 return 1; /* skip all interfaces but 1 and 2 */
1468 } else {
1469 unsigned int mask;
1470 if (iface == 1 || iface == 2)
1471 return 1; /* skip interfaces 1 and 2 */
1472 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
1473 return 1; /* skip this altsetting */
1474 mask = chip->setup & MAUDIO_SET_MASK;
1475 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
1476 return 1; /* skip this altsetting */
1477 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
1478 return 1; /* skip this altsetting */
1479 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
1480 return 1; /* skip this altsetting */
1481 }
1482 }
1483 usb_audio_dbg(chip,
1484 "using altsetting %d for interface %d config %d\n",
1485 altno, iface, chip->setup);
1486 return 0; /* keep this altsetting */
1487 }
1488
audiophile_skip_setting_quirk(struct snd_usb_audio * chip,int iface,int altno)1489 static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
1490 int iface,
1491 int altno)
1492 {
1493 /* Reset ALL ifaces to 0 altsetting.
1494 * Call it for every possible altsetting of every interface.
1495 */
1496 usb_set_interface(chip->dev, iface, 0);
1497
1498 if (chip->setup & MAUDIO_SET) {
1499 unsigned int mask;
1500 if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
1501 return 1; /* skip this altsetting */
1502 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
1503 return 1; /* skip this altsetting */
1504 mask = chip->setup & MAUDIO_SET_MASK;
1505 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
1506 return 1; /* skip this altsetting */
1507 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
1508 return 1; /* skip this altsetting */
1509 if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
1510 return 1; /* skip this altsetting */
1511 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
1512 return 1; /* skip this altsetting */
1513 }
1514
1515 return 0; /* keep this altsetting */
1516 }
1517
fasttrackpro_skip_setting_quirk(struct snd_usb_audio * chip,int iface,int altno)1518 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
1519 int iface, int altno)
1520 {
1521 /* Reset ALL ifaces to 0 altsetting.
1522 * Call it for every possible altsetting of every interface.
1523 */
1524 usb_set_interface(chip->dev, iface, 0);
1525
1526 /* possible configuration where both inputs and only one output is
1527 *used is not supported by the current setup
1528 */
1529 if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
1530 if (chip->setup & MAUDIO_SET_96K) {
1531 if (altno != 3 && altno != 6)
1532 return 1;
1533 } else if (chip->setup & MAUDIO_SET_DI) {
1534 if (iface == 4)
1535 return 1; /* no analog input */
1536 if (altno != 2 && altno != 5)
1537 return 1; /* enable only altsets 2 and 5 */
1538 } else {
1539 if (iface == 5)
1540 return 1; /* disable digialt input */
1541 if (altno != 2 && altno != 5)
1542 return 1; /* enalbe only altsets 2 and 5 */
1543 }
1544 } else {
1545 /* keep only 16-Bit mode */
1546 if (altno != 1)
1547 return 1;
1548 }
1549
1550 usb_audio_dbg(chip,
1551 "using altsetting %d for interface %d config %d\n",
1552 altno, iface, chip->setup);
1553 return 0; /* keep this altsetting */
1554 }
1555
s1810c_skip_setting_quirk(struct snd_usb_audio * chip,int iface,int altno)1556 static int s1810c_skip_setting_quirk(struct snd_usb_audio *chip,
1557 int iface, int altno)
1558 {
1559 /*
1560 * Altno settings:
1561 *
1562 * Playback (Interface 1):
1563 * 1: 6 Analog + 2 S/PDIF
1564 * 2: 6 Analog + 2 S/PDIF
1565 * 3: 6 Analog
1566 *
1567 * Capture (Interface 2):
1568 * 1: 8 Analog + 2 S/PDIF + 8 ADAT
1569 * 2: 8 Analog + 2 S/PDIF + 4 ADAT
1570 * 3: 8 Analog
1571 */
1572
1573 /*
1574 * I'll leave 2 as the default one and
1575 * use device_setup to switch to the
1576 * other two.
1577 */
1578 if ((chip->setup == 0 || chip->setup > 2) && altno != 2)
1579 return 1;
1580 else if (chip->setup == 1 && altno != 1)
1581 return 1;
1582 else if (chip->setup == 2 && altno != 3)
1583 return 1;
1584
1585 return 0;
1586 }
1587
snd_usb_apply_interface_quirk(struct snd_usb_audio * chip,int iface,int altno)1588 int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
1589 int iface,
1590 int altno)
1591 {
1592 /* audiophile usb: skip altsets incompatible with device_setup */
1593 if (chip->usb_id == USB_ID(0x0763, 0x2003))
1594 return audiophile_skip_setting_quirk(chip, iface, altno);
1595 /* quattro usb: skip altsets incompatible with device_setup */
1596 if (chip->usb_id == USB_ID(0x0763, 0x2001))
1597 return quattro_skip_setting_quirk(chip, iface, altno);
1598 /* fasttrackpro usb: skip altsets incompatible with device_setup */
1599 if (chip->usb_id == USB_ID(0x0763, 0x2012))
1600 return fasttrackpro_skip_setting_quirk(chip, iface, altno);
1601 /* presonus studio 1810c: skip altsets incompatible with device_setup */
1602 if (chip->usb_id == USB_ID(0x194f, 0x010c))
1603 return s1810c_skip_setting_quirk(chip, iface, altno);
1604
1605 return 0;
1606 }
1607
snd_usb_apply_boot_quirk(struct usb_device * dev,struct usb_interface * intf,const struct snd_usb_audio_quirk * quirk,unsigned int id)1608 int snd_usb_apply_boot_quirk(struct usb_device *dev,
1609 struct usb_interface *intf,
1610 const struct snd_usb_audio_quirk *quirk,
1611 unsigned int id)
1612 {
1613 switch (id) {
1614 case USB_ID(0x041e, 0x3000):
1615 /* SB Extigy needs special boot-up sequence */
1616 /* if more models come, this will go to the quirk list. */
1617 return snd_usb_extigy_boot_quirk(dev, intf);
1618
1619 case USB_ID(0x041e, 0x3020):
1620 /* SB Audigy 2 NX needs its own boot-up magic, too */
1621 return snd_usb_audigy2nx_boot_quirk(dev);
1622
1623 case USB_ID(0x10f5, 0x0200):
1624 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
1625 return snd_usb_cm106_boot_quirk(dev);
1626
1627 case USB_ID(0x0d8c, 0x0102):
1628 /* C-Media CM6206 / CM106-Like Sound Device */
1629 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
1630 return snd_usb_cm6206_boot_quirk(dev);
1631
1632 case USB_ID(0x0dba, 0x3000):
1633 /* Digidesign Mbox 2 */
1634 return snd_usb_mbox2_boot_quirk(dev);
1635 case USB_ID(0x0dba, 0x5000):
1636 /* Digidesign Mbox 3 */
1637 return snd_usb_mbox3_boot_quirk(dev);
1638
1639
1640 case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
1641 case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
1642 return snd_usb_novation_boot_quirk(dev);
1643
1644 case USB_ID(0x133e, 0x0815):
1645 /* Access Music VirusTI Desktop */
1646 return snd_usb_accessmusic_boot_quirk(dev);
1647
1648 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
1649 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
1650 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
1651 return snd_usb_nativeinstruments_boot_quirk(dev);
1652 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1653 return snd_usb_fasttrackpro_boot_quirk(dev);
1654 case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
1655 return snd_usb_gamecon780_boot_quirk(dev);
1656 case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx 3 */
1657 return snd_usb_axefx3_boot_quirk(dev);
1658 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook II */
1659 /*
1660 * For some reason interface 3 with vendor-spec class is
1661 * detected on MicroBook IIc.
1662 */
1663 if (get_iface_desc(intf->altsetting)->bInterfaceClass ==
1664 USB_CLASS_VENDOR_SPEC &&
1665 get_iface_desc(intf->altsetting)->bInterfaceNumber < 3)
1666 return snd_usb_motu_microbookii_boot_quirk(dev);
1667 break;
1668 case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */
1669 case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */
1670 return snd_usb_rme_digiface_boot_quirk(dev);
1671 }
1672
1673 return 0;
1674 }
1675
snd_usb_apply_boot_quirk_once(struct usb_device * dev,struct usb_interface * intf,const struct snd_usb_audio_quirk * quirk,unsigned int id)1676 int snd_usb_apply_boot_quirk_once(struct usb_device *dev,
1677 struct usb_interface *intf,
1678 const struct snd_usb_audio_quirk *quirk,
1679 unsigned int id)
1680 {
1681 switch (id) {
1682 case USB_ID(0x07fd, 0x0008): /* MOTU M Series, 1st hardware version */
1683 return snd_usb_motu_m_series_boot_quirk(dev);
1684 }
1685
1686 return 0;
1687 }
1688
1689 /*
1690 * check if the device uses big-endian samples
1691 */
snd_usb_is_big_endian_format(struct snd_usb_audio * chip,const struct audioformat * fp)1692 int snd_usb_is_big_endian_format(struct snd_usb_audio *chip,
1693 const struct audioformat *fp)
1694 {
1695 /* it depends on altsetting whether the device is big-endian or not */
1696 switch (chip->usb_id) {
1697 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
1698 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1699 fp->altsetting == 5 || fp->altsetting == 6)
1700 return 1;
1701 break;
1702 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1703 if (chip->setup == 0x00 ||
1704 fp->altsetting == 1 || fp->altsetting == 2 ||
1705 fp->altsetting == 3)
1706 return 1;
1707 break;
1708 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
1709 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1710 fp->altsetting == 5 || fp->altsetting == 6)
1711 return 1;
1712 break;
1713 }
1714 return 0;
1715 }
1716
1717 /*
1718 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
1719 * not for interface.
1720 */
1721
1722 enum {
1723 EMU_QUIRK_SR_44100HZ = 0,
1724 EMU_QUIRK_SR_48000HZ,
1725 EMU_QUIRK_SR_88200HZ,
1726 EMU_QUIRK_SR_96000HZ,
1727 EMU_QUIRK_SR_176400HZ,
1728 EMU_QUIRK_SR_192000HZ
1729 };
1730
set_format_emu_quirk(struct snd_usb_substream * subs,const struct audioformat * fmt)1731 static void set_format_emu_quirk(struct snd_usb_substream *subs,
1732 const struct audioformat *fmt)
1733 {
1734 unsigned char emu_samplerate_id = 0;
1735
1736 /* When capture is active
1737 * sample rate shouldn't be changed
1738 * by playback substream
1739 */
1740 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
1741 if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].cur_audiofmt)
1742 return;
1743 }
1744
1745 switch (fmt->rate_min) {
1746 case 48000:
1747 emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
1748 break;
1749 case 88200:
1750 emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
1751 break;
1752 case 96000:
1753 emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
1754 break;
1755 case 176400:
1756 emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
1757 break;
1758 case 192000:
1759 emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
1760 break;
1761 default:
1762 emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
1763 break;
1764 }
1765 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
1766 subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
1767 }
1768
pioneer_djm_set_format_quirk(struct snd_usb_substream * subs,u16 windex)1769 static int pioneer_djm_set_format_quirk(struct snd_usb_substream *subs,
1770 u16 windex)
1771 {
1772 unsigned int cur_rate = subs->data_endpoint->cur_rate;
1773 u8 sr[3];
1774 // Convert to little endian
1775 sr[0] = cur_rate & 0xff;
1776 sr[1] = (cur_rate >> 8) & 0xff;
1777 sr[2] = (cur_rate >> 16) & 0xff;
1778 usb_set_interface(subs->dev, 0, 1);
1779 // we should derive windex from fmt-sync_ep but it's not set
1780 snd_usb_ctl_msg(subs->stream->chip->dev,
1781 usb_sndctrlpipe(subs->stream->chip->dev, 0),
1782 0x01, 0x22, 0x0100, windex, &sr, 0x0003);
1783 return 0;
1784 }
1785
mbox3_set_format_quirk(struct snd_usb_substream * subs,const struct audioformat * fmt)1786 static void mbox3_set_format_quirk(struct snd_usb_substream *subs,
1787 const struct audioformat *fmt)
1788 {
1789 __le32 buff4 = 0;
1790 u8 buff1 = 0x01;
1791 u32 new_rate = subs->data_endpoint->cur_rate;
1792 u32 current_rate;
1793
1794 // Get current rate from card and check if changing it is needed
1795 snd_usb_ctl_msg(subs->dev, usb_rcvctrlpipe(subs->dev, 0),
1796 0x01, 0x21 | USB_DIR_IN, 0x0100, 0x8101, &buff4, 4);
1797 current_rate = le32_to_cpu(buff4);
1798 dev_dbg(&subs->dev->dev,
1799 "MBOX3: Current configured sample rate: %d", current_rate);
1800 if (current_rate == new_rate) {
1801 dev_dbg(&subs->dev->dev,
1802 "MBOX3: No change needed (current rate:%d == new rate:%d)",
1803 current_rate, new_rate);
1804 return;
1805 }
1806
1807 // Set new rate
1808 dev_info(&subs->dev->dev,
1809 "MBOX3: Changing sample rate to: %d", new_rate);
1810 buff4 = cpu_to_le32(new_rate);
1811 snd_usb_ctl_msg(subs->dev, usb_sndctrlpipe(subs->dev, 0),
1812 0x01, 0x21, 0x0100, 0x8101, &buff4, 4);
1813
1814 // Set clock source to Internal
1815 snd_usb_ctl_msg(subs->dev, usb_sndctrlpipe(subs->dev, 0),
1816 0x01, 0x21, 0x0100, 0x8001, &buff1, 1);
1817
1818 // Check whether the change was successful
1819 buff4 = 0;
1820 snd_usb_ctl_msg(subs->dev, usb_rcvctrlpipe(subs->dev, 0),
1821 0x01, 0x21 | USB_DIR_IN, 0x0100, 0x8101, &buff4, 4);
1822 if (new_rate != le32_to_cpu(buff4))
1823 dev_warn(&subs->dev->dev, "MBOX3: Couldn't set the sample rate");
1824 }
1825
1826 static const int rme_digiface_rate_table[] = {
1827 32000, 44100, 48000, 0,
1828 64000, 88200, 96000, 0,
1829 128000, 176400, 192000, 0,
1830 };
1831
rme_digiface_set_format_quirk(struct snd_usb_substream * subs)1832 static int rme_digiface_set_format_quirk(struct snd_usb_substream *subs)
1833 {
1834 unsigned int cur_rate = subs->data_endpoint->cur_rate;
1835 u16 val;
1836 int speed_mode;
1837 int id;
1838
1839 for (id = 0; id < ARRAY_SIZE(rme_digiface_rate_table); id++) {
1840 if (rme_digiface_rate_table[id] == cur_rate)
1841 break;
1842 }
1843
1844 if (id >= ARRAY_SIZE(rme_digiface_rate_table))
1845 return -EINVAL;
1846
1847 /* 2, 3, 4 for 1x, 2x, 4x */
1848 speed_mode = (id >> 2) + 2;
1849 val = (id << 3) | (speed_mode << 12);
1850
1851 /* Set the sample rate */
1852 snd_usb_ctl_msg(subs->stream->chip->dev,
1853 usb_sndctrlpipe(subs->stream->chip->dev, 0),
1854 16, 0x40, val, 0x7078, NULL, 0);
1855 return 0;
1856 }
1857
snd_usb_set_format_quirk(struct snd_usb_substream * subs,const struct audioformat * fmt)1858 void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
1859 const struct audioformat *fmt)
1860 {
1861 switch (subs->stream->chip->usb_id) {
1862 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
1863 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
1864 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
1865 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
1866 set_format_emu_quirk(subs, fmt);
1867 break;
1868 case USB_ID(0x534d, 0x0021): /* MacroSilicon MS2100/MS2106 */
1869 case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
1870 subs->stream_offset_adj = 2;
1871 break;
1872 case USB_ID(0x2b73, 0x000a): /* Pioneer DJM-900NXS2 */
1873 case USB_ID(0x2b73, 0x0013): /* Pioneer DJM-450 */
1874 case USB_ID(0x2b73, 0x0034): /* Pioneer DJM-V10 */
1875 pioneer_djm_set_format_quirk(subs, 0x0082);
1876 break;
1877 case USB_ID(0x08e4, 0x017f): /* Pioneer DJM-750 */
1878 case USB_ID(0x08e4, 0x0163): /* Pioneer DJM-850 */
1879 pioneer_djm_set_format_quirk(subs, 0x0086);
1880 break;
1881 case USB_ID(0x0dba, 0x5000):
1882 mbox3_set_format_quirk(subs, fmt); /* Digidesign Mbox 3 */
1883 break;
1884 case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */
1885 case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */
1886 rme_digiface_set_format_quirk(subs);
1887 break;
1888 }
1889 }
1890
snd_usb_select_mode_quirk(struct snd_usb_audio * chip,const struct audioformat * fmt)1891 int snd_usb_select_mode_quirk(struct snd_usb_audio *chip,
1892 const struct audioformat *fmt)
1893 {
1894 struct usb_device *dev = chip->dev;
1895 int err;
1896
1897 if (chip->quirk_flags & QUIRK_FLAG_ITF_USB_DSD_DAC) {
1898 /* First switch to alt set 0, otherwise the mode switch cmd
1899 * will not be accepted by the DAC
1900 */
1901 err = usb_set_interface(dev, fmt->iface, 0);
1902 if (err < 0)
1903 return err;
1904
1905 msleep(20); /* Delay needed after setting the interface */
1906
1907 /* Vendor mode switch cmd is required. */
1908 if (fmt->formats & SNDRV_PCM_FMTBIT_DSD_U32_BE) {
1909 /* DSD mode (DSD_U32) requested */
1910 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
1911 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
1912 1, 1, NULL, 0);
1913 if (err < 0)
1914 return err;
1915
1916 } else {
1917 /* PCM or DOP mode (S32) requested */
1918 /* PCM mode (S16) requested */
1919 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
1920 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
1921 0, 1, NULL, 0);
1922 if (err < 0)
1923 return err;
1924
1925 }
1926 msleep(20);
1927 }
1928 return 0;
1929 }
1930
snd_usb_endpoint_start_quirk(struct snd_usb_endpoint * ep)1931 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
1932 {
1933 /*
1934 * "Playback Design" products send bogus feedback data at the start
1935 * of the stream. Ignore them.
1936 */
1937 if (USB_ID_VENDOR(ep->chip->usb_id) == 0x23ba &&
1938 ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
1939 ep->skip_packets = 4;
1940
1941 /*
1942 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
1943 * world latency varies by approx. +/- 50 frames (at 96kHz) each time
1944 * the stream is (re)started. When skipping packets 16 at endpoint
1945 * start up, the real world latency is stable within +/- 1 frame (also
1946 * across power cycles).
1947 */
1948 if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
1949 ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
1950 ep->type == SND_USB_ENDPOINT_TYPE_DATA)
1951 ep->skip_packets = 16;
1952
1953 /* Work around devices that report unreasonable feedback data */
1954 if ((ep->chip->usb_id == USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
1955 ep->chip->usb_id == USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
1956 ep->syncmaxsize == 4)
1957 ep->tenor_fb_quirk = 1;
1958 }
1959
1960 /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
snd_usb_ctl_msg_quirk(struct usb_device * dev,unsigned int pipe,__u8 request,__u8 requesttype,__u16 value,__u16 index,void * data,__u16 size)1961 void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1962 __u8 request, __u8 requesttype, __u16 value,
1963 __u16 index, void *data, __u16 size)
1964 {
1965 struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
1966
1967 if (!chip || (requesttype & USB_TYPE_MASK) != USB_TYPE_CLASS)
1968 return;
1969
1970 if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY)
1971 msleep(20);
1972 else if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY_1M)
1973 usleep_range(1000, 2000);
1974 else if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY_5M)
1975 usleep_range(5000, 6000);
1976 }
1977
1978 /*
1979 * snd_usb_interface_dsd_format_quirks() is called from format.c to
1980 * augment the PCM format bit-field for DSD types. The UAC standards
1981 * don't have a designated bit field to denote DSD-capable interfaces,
1982 * hence all hardware that is known to support this format has to be
1983 * listed here.
1984 */
snd_usb_interface_dsd_format_quirks(struct snd_usb_audio * chip,struct audioformat * fp,unsigned int sample_bytes)1985 u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1986 struct audioformat *fp,
1987 unsigned int sample_bytes)
1988 {
1989 struct usb_interface *iface;
1990
1991 /* Playback Designs */
1992 if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
1993 USB_ID_PRODUCT(chip->usb_id) < 0x0110) {
1994 switch (fp->altsetting) {
1995 case 1:
1996 fp->dsd_dop = true;
1997 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
1998 case 2:
1999 fp->dsd_bitrev = true;
2000 return SNDRV_PCM_FMTBIT_DSD_U8;
2001 case 3:
2002 fp->dsd_bitrev = true;
2003 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
2004 }
2005 }
2006
2007 /* XMOS based USB DACs */
2008 switch (chip->usb_id) {
2009 case USB_ID(0x139f, 0x5504): /* Nagra DAC */
2010 case USB_ID(0x20b1, 0x3089): /* Mola-Mola DAC */
2011 case USB_ID(0x2522, 0x0007): /* LH Labs Geek Out 1V5 */
2012 case USB_ID(0x2522, 0x0009): /* LH Labs Geek Pulse X Inifinity 2V0 */
2013 case USB_ID(0x2522, 0x0012): /* LH Labs VI DAC Infinity */
2014 case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
2015 if (fp->altsetting == 2)
2016 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
2017 break;
2018
2019 case USB_ID(0x0d8c, 0x0316): /* Hegel HD12 DSD */
2020 case USB_ID(0x10cb, 0x0103): /* The Bit Opus #3; with fp->dsd_raw */
2021 case USB_ID(0x16d0, 0x06b2): /* NuPrime DAC-10 */
2022 case USB_ID(0x16d0, 0x06b4): /* NuPrime Audio HD-AVP/AVA */
2023 case USB_ID(0x16d0, 0x0733): /* Furutech ADL Stratos */
2024 case USB_ID(0x16d0, 0x09d8): /* NuPrime IDA-8 */
2025 case USB_ID(0x16d0, 0x09db): /* NuPrime Audio DAC-9 */
2026 case USB_ID(0x16d0, 0x09dd): /* Encore mDSD */
2027 case USB_ID(0x16d0, 0x0ab1): /* PureAudio APA DAC */
2028 case USB_ID(0x16d0, 0xeca1): /* PureAudio Lotus DAC5, DAC5 SE, DAC5 Pro */
2029 case USB_ID(0x1db5, 0x0003): /* Bryston BDA3 */
2030 case USB_ID(0x20a0, 0x4143): /* WaveIO USB Audio 2.0 */
2031 case USB_ID(0x22e1, 0xca01): /* HDTA Serenade DSD */
2032 case USB_ID(0x249c, 0x9326): /* M2Tech Young MkIII */
2033 case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
2034 case USB_ID(0x2622, 0x0041): /* Audiolab M-DAC+ */
2035 case USB_ID(0x2622, 0x0061): /* LEAK Stereo 230 */
2036 case USB_ID(0x278b, 0x5100): /* Rotel RC-1590 */
2037 case USB_ID(0x27f7, 0x3002): /* W4S DAC-2v2SE */
2038 case USB_ID(0x29a2, 0x0086): /* Mutec MC3+ USB */
2039 case USB_ID(0x6b42, 0x0042): /* MSB Technology */
2040 if (fp->altsetting == 3)
2041 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
2042 break;
2043
2044 /* Amanero Combo384 USB based DACs with native DSD support */
2045 case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
2046 if (fp->altsetting == 2) {
2047 switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) {
2048 case 0x199:
2049 return SNDRV_PCM_FMTBIT_DSD_U32_LE;
2050 case 0x19b:
2051 case 0x203:
2052 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
2053 default:
2054 break;
2055 }
2056 }
2057 break;
2058 case USB_ID(0x16d0, 0x0a23):
2059 if (fp->altsetting == 2)
2060 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
2061 break;
2062
2063 default:
2064 break;
2065 }
2066
2067 /* ITF-USB DSD based DACs */
2068 if (chip->quirk_flags & QUIRK_FLAG_ITF_USB_DSD_DAC) {
2069 iface = usb_ifnum_to_if(chip->dev, fp->iface);
2070
2071 /* Altsetting 2 support native DSD if the num of altsets is
2072 * three (0-2),
2073 * Altsetting 3 support native DSD if the num of altsets is
2074 * four (0-3).
2075 */
2076 if (fp->altsetting == iface->num_altsetting - 1)
2077 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
2078 }
2079
2080 /* Mostly generic method to detect many DSD-capable implementations */
2081 if ((chip->quirk_flags & QUIRK_FLAG_DSD_RAW) && fp->dsd_raw)
2082 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
2083
2084 return 0;
2085 }
2086
snd_usb_audioformat_attributes_quirk(struct snd_usb_audio * chip,struct audioformat * fp,int stream)2087 void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
2088 struct audioformat *fp,
2089 int stream)
2090 {
2091 switch (chip->usb_id) {
2092 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
2093 /* Optoplay sets the sample rate attribute although
2094 * it seems not supporting it in fact.
2095 */
2096 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
2097 break;
2098 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
2099 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
2100 /* doesn't set the sample rate attribute, but supports it */
2101 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
2102 break;
2103 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
2104 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
2105 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
2106 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
2107 an older model 77d:223) */
2108 /*
2109 * plantronics headset and Griffin iMic have set adaptive-in
2110 * although it's really not...
2111 */
2112 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
2113 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
2114 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
2115 else
2116 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
2117 break;
2118 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook IIc */
2119 /*
2120 * MaxPacketsOnly attribute is erroneously set in endpoint
2121 * descriptors. As a result this card produces noise with
2122 * all sample rates other than 96 kHz.
2123 */
2124 fp->attributes &= ~UAC_EP_CS_ATTR_FILL_MAX;
2125 break;
2126 case USB_ID(0x1224, 0x2a25): /* Jieli Technology USB PHY 2.0 */
2127 /* mic works only when ep packet size is set to wMaxPacketSize */
2128 fp->attributes |= UAC_EP_CS_ATTR_FILL_MAX;
2129 break;
2130 case USB_ID(0x3511, 0x2b1e): /* Opencomm2 UC USB Bluetooth dongle */
2131 /* mic works only when ep pitch control is not set */
2132 if (stream == SNDRV_PCM_STREAM_CAPTURE)
2133 fp->attributes &= ~UAC_EP_CS_ATTR_PITCH_CONTROL;
2134 break;
2135 }
2136 }
2137
2138 /*
2139 * driver behavior quirk flags
2140 */
2141 struct usb_string_match {
2142 const char *manufacturer;
2143 const char *product;
2144 };
2145
2146 struct usb_audio_quirk_flags_table {
2147 u32 id;
2148 u32 flags;
2149 const struct usb_string_match *usb_string_match;
2150 };
2151
2152 #define DEVICE_FLG(vid, pid, _flags) \
2153 { .id = USB_ID(vid, pid), .flags = (_flags) }
2154 #define VENDOR_FLG(vid, _flags) DEVICE_FLG(vid, 0, _flags)
2155
2156 /*
2157 * Use as a last resort if using DEVICE_FLG() is prone to VID/PID conflicts.
2158 *
2159 * Usage:
2160 * // match vid, pid, "manufacturer", and "product"
2161 * DEVICE_STRING_FLG(vid, pid, "manufacturer", "product", flags)
2162 *
2163 * // match vid, pid, "manufacturer", and any product string
2164 * DEVICE_STRING_FLG(vid, pid, "manufacturer", NULL, flags)
2165 *
2166 * // match vid, pid, "manufacturer", and device must have no product string
2167 * DEVICE_STRING_FLG(vid, pid, "manufacturer", "", flags)
2168 *
2169 * // match vid, pid, any manufacturer string, and "product"
2170 * DEVICE_STRING_FLG(vid, pid, NULL, "product", flags)
2171 *
2172 * // match vid, pid, no manufacturer string, and "product"
2173 * DEVICE_STRING_FLG(vid, pid, "", "product", flags)
2174 *
2175 * // match vid, pid, no manufacturer string, and no product string
2176 * DEVICE_STRING_FLG(vid, pid, "", "", flags)
2177 */
2178 #define DEVICE_STRING_FLG(vid, pid, _manufacturer, _product, _flags) \
2179 { \
2180 .id = USB_ID(vid, pid), \
2181 .usb_string_match = &(const struct usb_string_match) { \
2182 .manufacturer = _manufacturer, \
2183 .product = _product, \
2184 }, \
2185 .flags = (_flags), \
2186 }
2187
2188 /*
2189 * Use as a last resort if using VENDOR_FLG() is prone to VID conflicts.
2190 *
2191 * Usage:
2192 * // match vid, and "manufacturer"
2193 * VENDOR_STRING_FLG(vid, "manufacturer", flags)
2194 *
2195 * // match vid, and device must have no manufacturer string
2196 * VENDOR_STRING_FLG(vid, "", flags)
2197 */
2198 #define VENDOR_STRING_FLG(vid, _manufacturer, _flags) \
2199 DEVICE_STRING_FLG(vid, 0, _manufacturer, NULL, _flags)
2200
2201 static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
2202 /* Device and string descriptor matches */
2203
2204 /* Device matches */
2205 DEVICE_FLG(0x001f, 0x0b21, /* AB13X USB Audio */
2206 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2207 DEVICE_FLG(0x001f, 0x0b23, /* AB17X USB Audio */
2208 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2209 DEVICE_FLG(0x0020, 0x0b21, /* GHW-123P */
2210 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2211 DEVICE_FLG(0x03f0, 0x654a, /* HP 320 FHD Webcam */
2212 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
2213 DEVICE_FLG(0x041e, 0x3000, /* Creative SB Extigy */
2214 QUIRK_FLAG_IGNORE_CTL_ERROR),
2215 DEVICE_FLG(0x041e, 0x4080, /* Creative Live Cam VF0610 */
2216 QUIRK_FLAG_GET_SAMPLE_RATE),
2217 DEVICE_FLG(0x045e, 0x083c, /* MS USB Link headset */
2218 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY |
2219 QUIRK_FLAG_DISABLE_AUTOSUSPEND),
2220 DEVICE_FLG(0x045e, 0x070f, /* MS LifeChat LX-3000 Headset */
2221 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2222 DEVICE_FLG(0x046d, 0x0807, /* Logitech Webcam C500 */
2223 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2224 DEVICE_FLG(0x046d, 0x0808, /* Logitech Webcam C600 */
2225 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2226 DEVICE_FLG(0x046d, 0x0809,
2227 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2228 DEVICE_FLG(0x046d, 0x0819, /* Logitech Webcam C210 */
2229 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2230 DEVICE_FLG(0x046d, 0x081b, /* HD Webcam c310 */
2231 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2232 DEVICE_FLG(0x046d, 0x081d, /* HD Webcam c510 */
2233 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2234 DEVICE_FLG(0x046d, 0x0825, /* HD Webcam c270 */
2235 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2236 DEVICE_FLG(0x046d, 0x0826, /* HD Webcam c525 */
2237 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2238 DEVICE_FLG(0x046d, 0x084c, /* Logitech ConferenceCam Connect */
2239 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY_1M),
2240 DEVICE_FLG(0x046d, 0x08ca, /* Logitech Quickcam Fusion */
2241 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2242 DEVICE_FLG(0x046d, 0x0991, /* Logitech QuickCam Pro */
2243 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_IGNORE_CTL_ERROR |
2244 QUIRK_FLAG_MIC_RES_384),
2245 DEVICE_FLG(0x046d, 0x09a2, /* QuickCam Communicate Deluxe/S7500 */
2246 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
2247 DEVICE_FLG(0x046d, 0x09a4, /* Logitech QuickCam E 3500 */
2248 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_IGNORE_CTL_ERROR),
2249 DEVICE_FLG(0x046d, 0x0a8f, /* Logitech H390 headset */
2250 QUIRK_FLAG_CTL_MSG_DELAY_1M |
2251 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2252 DEVICE_FLG(0x0499, 0x1506, /* Yamaha THR5 */
2253 QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2254 DEVICE_FLG(0x0499, 0x1509, /* Steinberg UR22 */
2255 QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2256 DEVICE_FLG(0x0499, 0x3108, /* Yamaha YIT-W12TX */
2257 QUIRK_FLAG_GET_SAMPLE_RATE),
2258 DEVICE_FLG(0x04d8, 0xfeea, /* Benchmark DAC1 Pre */
2259 QUIRK_FLAG_GET_SAMPLE_RATE),
2260 DEVICE_FLG(0x04e8, 0xa051, /* Samsung USBC Headset (AKG) */
2261 QUIRK_FLAG_SKIP_CLOCK_SELECTOR | QUIRK_FLAG_CTL_MSG_DELAY_5M),
2262 DEVICE_FLG(0x0525, 0xa4ad, /* Hamedal C20 usb camero */
2263 QUIRK_FLAG_IFACE_SKIP_CLOSE),
2264 DEVICE_FLG(0x054c, 0x0b8c, /* Sony WALKMAN NW-A45 DAC */
2265 QUIRK_FLAG_SET_IFACE_FIRST),
2266 DEVICE_FLG(0x0556, 0x0014, /* Phoenix Audio TMX320VC */
2267 QUIRK_FLAG_GET_SAMPLE_RATE),
2268 DEVICE_FLG(0x0572, 0x1b08, /* Conexant Systems (Rockwell), Inc. */
2269 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2270 DEVICE_FLG(0x0572, 0x1b09, /* Conexant Systems (Rockwell), Inc. */
2271 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2272 DEVICE_FLG(0x05a3, 0x9420, /* ELP HD USB Camera */
2273 QUIRK_FLAG_GET_SAMPLE_RATE),
2274 DEVICE_FLG(0x05a7, 0x1020, /* Bose Companion 5 */
2275 QUIRK_FLAG_GET_SAMPLE_RATE),
2276 DEVICE_FLG(0x05e1, 0x0408, /* Syntek STK1160 */
2277 QUIRK_FLAG_ALIGN_TRANSFER),
2278 DEVICE_FLG(0x05e1, 0x0480, /* Hauppauge Woodbury */
2279 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2280 DEVICE_FLG(0x0624, 0x3d3f, /* AB13X USB Audio */
2281 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2282 DEVICE_FLG(0x0644, 0x8043, /* TEAC UD-501/UD-501V2/UD-503/NT-503 */
2283 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
2284 QUIRK_FLAG_IFACE_DELAY),
2285 DEVICE_FLG(0x0644, 0x8044, /* Esoteric D-05X */
2286 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
2287 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET),
2288 DEVICE_FLG(0x0644, 0x804a, /* TEAC UD-301 */
2289 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
2290 QUIRK_FLAG_IFACE_DELAY),
2291 DEVICE_FLG(0x0644, 0x805f, /* TEAC Model 12 */
2292 QUIRK_FLAG_FORCE_IFACE_RESET),
2293 DEVICE_FLG(0x0644, 0x806b, /* TEAC UD-701 */
2294 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
2295 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET),
2296 DEVICE_FLG(0x0644, 0x807d, /* TEAC UD-507 */
2297 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
2298 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET),
2299 DEVICE_FLG(0x0644, 0x806c, /* Esoteric XD */
2300 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
2301 QUIRK_FLAG_IFACE_DELAY | QUIRK_FLAG_FORCE_IFACE_RESET),
2302 DEVICE_FLG(0x0661, 0x0883, /* iBasso DC04 Ultra */
2303 QUIRK_FLAG_DSD_RAW),
2304 DEVICE_FLG(0x0666, 0x0880, /* SPACETOUCH USB Audio */
2305 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2306 DEVICE_FLG(0x06f8, 0xb000, /* Hercules DJ Console (Windows Edition) */
2307 QUIRK_FLAG_IGNORE_CTL_ERROR),
2308 DEVICE_FLG(0x06f8, 0xd002, /* Hercules DJ Console (Macintosh Edition) */
2309 QUIRK_FLAG_IGNORE_CTL_ERROR),
2310 DEVICE_FLG(0x0711, 0x5800, /* MCT Trigger 5 USB-to-HDMI */
2311 QUIRK_FLAG_GET_SAMPLE_RATE),
2312 DEVICE_FLG(0x074d, 0x3553, /* Outlaw RR2150 (Micronas UAC3553B) */
2313 QUIRK_FLAG_GET_SAMPLE_RATE),
2314 DEVICE_FLG(0x0763, 0x2030, /* M-Audio Fast Track C400 */
2315 QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2316 DEVICE_FLG(0x0763, 0x2031, /* M-Audio Fast Track C600 */
2317 QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2318 DEVICE_FLG(0x07fd, 0x000b, /* MOTU M Series 2nd hardware revision */
2319 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2320 DEVICE_FLG(0x08bb, 0x2702, /* LineX FM Transmitter */
2321 QUIRK_FLAG_IGNORE_CTL_ERROR),
2322 DEVICE_FLG(0x0951, 0x16ad, /* Kingston HyperX */
2323 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2324 DEVICE_FLG(0x0b05, 0x18a6, /* ASUSTek Computer, Inc. */
2325 QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE),
2326 DEVICE_FLG(0x0b0e, 0x0349, /* Jabra 550a */
2327 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2328 DEVICE_FLG(0x0bda, 0x498a, /* Realtek Semiconductor Corp. */
2329 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE | QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE),
2330 DEVICE_FLG(0x0c45, 0x6340, /* Sonix HD USB Camera */
2331 QUIRK_FLAG_GET_SAMPLE_RATE),
2332 DEVICE_FLG(0x0c45, 0x636b, /* Microdia JP001 USB Camera */
2333 QUIRK_FLAG_GET_SAMPLE_RATE),
2334 DEVICE_FLG(0x0d8c, 0x000c, /* C-Media */
2335 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2336 DEVICE_FLG(0x0d8c, 0x0012, /* C-Media */
2337 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2338 DEVICE_FLG(0x0d8c, 0x0014, /* C-Media */
2339 QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2340 DEVICE_FLG(0x0e0b, 0xfa01, /* Feaulle Rainbow */
2341 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2342 DEVICE_FLG(0x0ecb, 0x205c, /* JBL Quantum610 Wireless */
2343 QUIRK_FLAG_FIXED_RATE),
2344 DEVICE_FLG(0x0ecb, 0x2069, /* JBL Quantum810 Wireless */
2345 QUIRK_FLAG_FIXED_RATE),
2346 DEVICE_FLG(0x0fd9, 0x0008, /* Hauppauge HVR-950Q */
2347 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2348 DEVICE_FLG(0x1038, 0x1294, /* SteelSeries Arctis Pro Wireless */
2349 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2350 DEVICE_FLG(0x1101, 0x0003, /* Audioengine D1 */
2351 QUIRK_FLAG_GET_SAMPLE_RATE),
2352 DEVICE_FLG(0x12d1, 0x3a07, /* HUAWEI USB-C HEADSET */
2353 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE | QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE |
2354 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2355 DEVICE_FLG(0x1224, 0x2a25, /* Jieli Technology USB PHY 2.0 */
2356 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
2357 DEVICE_FLG(0x1395, 0x740a, /* Sennheiser DECT */
2358 QUIRK_FLAG_GET_SAMPLE_RATE),
2359 DEVICE_FLG(0x1397, 0x0507, /* Behringer UMC202HD */
2360 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2361 DEVICE_FLG(0x1397, 0x0508, /* Behringer UMC204HD */
2362 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2363 DEVICE_FLG(0x1397, 0x0509, /* Behringer UMC404HD */
2364 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2365 DEVICE_FLG(0x13e5, 0x0001, /* Serato Phono */
2366 QUIRK_FLAG_IGNORE_CTL_ERROR),
2367 DEVICE_FLG(0x152a, 0x880a, /* NeuralDSP Quad Cortex */
2368 0), /* Doesn't have the vendor quirk which would otherwise apply */
2369 DEVICE_FLG(0x154e, 0x1002, /* Denon DCD-1500RE */
2370 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2371 DEVICE_FLG(0x154e, 0x1003, /* Denon DA-300USB */
2372 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2373 DEVICE_FLG(0x154e, 0x3005, /* Marantz HD-DAC1 */
2374 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2375 DEVICE_FLG(0x154e, 0x3006, /* Marantz SA-14S1 */
2376 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2377 DEVICE_FLG(0x154e, 0x300b, /* Marantz SA-KI RUBY / SA-12 */
2378 QUIRK_FLAG_DSD_RAW),
2379 DEVICE_FLG(0x154e, 0x500e, /* Denon DN-X1600 */
2380 QUIRK_FLAG_IGNORE_CLOCK_SOURCE),
2381 DEVICE_FLG(0x1686, 0x00dd, /* Zoom R16/24 */
2382 QUIRK_FLAG_TX_LENGTH | QUIRK_FLAG_CTL_MSG_DELAY_1M),
2383 DEVICE_FLG(0x16d0, 0x0ab1, /* PureAudio APA DAC */
2384 QUIRK_FLAG_DSD_RAW),
2385 DEVICE_FLG(0x16d0, 0xeca1, /* PureAudio Lotus DAC5, DAC5 SE and DAC5 Pro */
2386 QUIRK_FLAG_DSD_RAW),
2387 DEVICE_FLG(0x17aa, 0x1046, /* Lenovo ThinkStation P620 Rear Line-in, Line-out and Microphone */
2388 QUIRK_FLAG_DISABLE_AUTOSUSPEND),
2389 DEVICE_FLG(0x17aa, 0x104d, /* Lenovo ThinkStation P620 Internal Speaker + Front Headset */
2390 QUIRK_FLAG_DISABLE_AUTOSUSPEND),
2391 DEVICE_FLG(0x17ef, 0x3083, /* Lenovo TBT3 dock */
2392 QUIRK_FLAG_GET_SAMPLE_RATE),
2393 DEVICE_FLG(0x1852, 0x5062, /* Luxman D-08u */
2394 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2395 DEVICE_FLG(0x1852, 0x5065, /* Luxman DA-06 */
2396 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2397 DEVICE_FLG(0x1901, 0x0191, /* GE B850V3 CP2114 audio interface */
2398 QUIRK_FLAG_GET_SAMPLE_RATE),
2399 DEVICE_FLG(0x19f7, 0x0003, /* RODE NT-USB */
2400 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2401 DEVICE_FLG(0x19f7, 0x0035, /* RODE NT-USB+ */
2402 QUIRK_FLAG_GET_SAMPLE_RATE),
2403 DEVICE_FLG(0x1bcf, 0x2281, /* HD Webcam */
2404 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
2405 DEVICE_FLG(0x1bcf, 0x2283, /* NexiGo N930AF FHD Webcam */
2406 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
2407 DEVICE_FLG(0x2040, 0x7200, /* Hauppauge HVR-950Q */
2408 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2409 DEVICE_FLG(0x2040, 0x7201, /* Hauppauge HVR-950Q-MXL */
2410 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2411 DEVICE_FLG(0x2040, 0x7210, /* Hauppauge HVR-950Q */
2412 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2413 DEVICE_FLG(0x2040, 0x7211, /* Hauppauge HVR-950Q-MXL */
2414 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2415 DEVICE_FLG(0x2040, 0x7213, /* Hauppauge HVR-950Q */
2416 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2417 DEVICE_FLG(0x2040, 0x7217, /* Hauppauge HVR-950Q */
2418 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2419 DEVICE_FLG(0x2040, 0x721b, /* Hauppauge HVR-950Q */
2420 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2421 DEVICE_FLG(0x2040, 0x721e, /* Hauppauge HVR-950Q */
2422 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2423 DEVICE_FLG(0x2040, 0x721f, /* Hauppauge HVR-950Q */
2424 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2425 DEVICE_FLG(0x2040, 0x7240, /* Hauppauge HVR-850 */
2426 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2427 DEVICE_FLG(0x2040, 0x7260, /* Hauppauge HVR-950Q */
2428 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2429 DEVICE_FLG(0x2040, 0x7270, /* Hauppauge HVR-950Q */
2430 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2431 DEVICE_FLG(0x2040, 0x7280, /* Hauppauge HVR-950Q */
2432 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2433 DEVICE_FLG(0x2040, 0x7281, /* Hauppauge HVR-950Q-MXL */
2434 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2435 DEVICE_FLG(0x20b1, 0x2009, /* XMOS Ltd DIYINHK USB Audio 2.0 */
2436 QUIRK_FLAG_SKIP_IMPLICIT_FB | QUIRK_FLAG_DSD_RAW),
2437 DEVICE_FLG(0x2040, 0x8200, /* Hauppauge Woodbury */
2438 QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
2439 DEVICE_FLG(0x21b4, 0x0081, /* AudioQuest DragonFly */
2440 QUIRK_FLAG_GET_SAMPLE_RATE),
2441 DEVICE_FLG(0x21b4, 0x0230, /* Ayre QB-9 Twenty */
2442 QUIRK_FLAG_DSD_RAW),
2443 DEVICE_FLG(0x21b4, 0x0232, /* Ayre QX-5 Twenty */
2444 QUIRK_FLAG_DSD_RAW),
2445 DEVICE_FLG(0x2522, 0x0007, /* LH Labs Geek Out HD Audio 1V5 */
2446 QUIRK_FLAG_SET_IFACE_FIRST),
2447 DEVICE_FLG(0x262a, 0x9302, /* ddHiFi TC44C */
2448 QUIRK_FLAG_DSD_RAW),
2449 DEVICE_FLG(0x2708, 0x0002, /* Audient iD14 */
2450 QUIRK_FLAG_IGNORE_CTL_ERROR),
2451 DEVICE_FLG(0x2912, 0x30c8, /* Audioengine D1 */
2452 QUIRK_FLAG_GET_SAMPLE_RATE),
2453 DEVICE_FLG(0x2a70, 0x1881, /* OnePlus Technology (Shenzhen) Co., Ltd. BE02T */
2454 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE | QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE),
2455 DEVICE_FLG(0x2b53, 0x0023, /* Fiero SC-01 (firmware v1.0.0 @ 48 kHz) */
2456 QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2457 DEVICE_FLG(0x2b53, 0x0024, /* Fiero SC-01 (firmware v1.0.0 @ 96 kHz) */
2458 QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2459 DEVICE_FLG(0x2b53, 0x0031, /* Fiero SC-01 (firmware v1.1.0) */
2460 QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2461 DEVICE_FLG(0x2d95, 0x8011, /* VIVO USB-C HEADSET */
2462 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2463 DEVICE_FLG(0x2d95, 0x8021, /* VIVO USB-C-XE710 HEADSET */
2464 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2465 DEVICE_FLG(0x2d99, 0x0026, /* HECATE G2 GAMING HEADSET */
2466 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2467 DEVICE_FLG(0x2fc6, 0xf06b, /* MOONDROP Moonriver2 Ti */
2468 QUIRK_FLAG_CTL_MSG_DELAY),
2469 DEVICE_FLG(0x2fc6, 0xf0b7, /* iBasso DC07 Pro */
2470 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2471 DEVICE_FLG(0x30be, 0x0101, /* Schiit Hel */
2472 QUIRK_FLAG_IGNORE_CTL_ERROR),
2473 DEVICE_FLG(0x3255, 0x0000, /* Luxman D-10X */
2474 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2475 DEVICE_FLG(0x339b, 0x3a07, /* Synaptics HONOR USB-C HEADSET */
2476 QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE),
2477 DEVICE_FLG(0x413c, 0xa506, /* Dell AE515 sound bar */
2478 QUIRK_FLAG_GET_SAMPLE_RATE),
2479 DEVICE_FLG(0x534d, 0x0021, /* MacroSilicon MS2100/MS2106 */
2480 QUIRK_FLAG_ALIGN_TRANSFER),
2481 DEVICE_FLG(0x534d, 0x2109, /* MacroSilicon MS2109 */
2482 QUIRK_FLAG_ALIGN_TRANSFER),
2483 DEVICE_FLG(0x84ef, 0x0082, /* Hotone Audio Pulze Mini */
2484 QUIRK_FLAG_MIXER_PLAYBACK_LINEAR_VOL | QUIRK_FLAG_MIXER_CAPTURE_LINEAR_VOL),
2485
2486 /* Vendor and string descriptor matches */
2487 VENDOR_STRING_FLG(0x1235, /* Conflict with Focusrite Novation */
2488 "MV-SILICON",
2489 0), /* Stop matching */
2490
2491 /* Vendor matches */
2492 VENDOR_FLG(0x045e, /* MS Lifecam */
2493 QUIRK_FLAG_GET_SAMPLE_RATE),
2494 VENDOR_FLG(0x046d, /* Logitech */
2495 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2496 VENDOR_FLG(0x047f, /* Plantronics */
2497 QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY),
2498 VENDOR_FLG(0x0644, /* TEAC Corp. */
2499 QUIRK_FLAG_CTL_MSG_DELAY | QUIRK_FLAG_IFACE_DELAY),
2500 VENDOR_FLG(0x07fd, /* MOTU */
2501 QUIRK_FLAG_VALIDATE_RATES),
2502 DEVICE_FLG(0x1235, 0x8006, 0), /* Focusrite Scarlett 2i2 1st Gen */
2503 DEVICE_FLG(0x1235, 0x800a, 0), /* Focusrite Scarlett 2i4 1st Gen */
2504 DEVICE_FLG(0x1235, 0x800c, 0), /* Focusrite Scarlett 18i20 1st Gen */
2505 DEVICE_FLG(0x1235, 0x8016, 0), /* Focusrite Scarlett 2i2 1st Gen */
2506 DEVICE_FLG(0x1235, 0x801c, 0), /* Focusrite Scarlett Solo 1st Gen */
2507 VENDOR_FLG(0x1235, /* Focusrite Novation */
2508 QUIRK_FLAG_SKIP_CLOCK_SELECTOR |
2509 QUIRK_FLAG_SKIP_IFACE_SETUP),
2510 VENDOR_FLG(0x1511, /* AURALiC */
2511 QUIRK_FLAG_DSD_RAW),
2512 VENDOR_FLG(0x152a, /* Thesycon devices */
2513 QUIRK_FLAG_DSD_RAW),
2514 VENDOR_FLG(0x18d1, /* iBasso devices */
2515 QUIRK_FLAG_DSD_RAW),
2516 VENDOR_FLG(0x1de7, /* Phoenix Audio */
2517 QUIRK_FLAG_GET_SAMPLE_RATE),
2518 VENDOR_FLG(0x20b1, /* XMOS based devices */
2519 QUIRK_FLAG_DSD_RAW),
2520 VENDOR_FLG(0x21ed, /* Accuphase Laboratory */
2521 QUIRK_FLAG_DSD_RAW),
2522 VENDOR_FLG(0x22d9, /* Oppo */
2523 QUIRK_FLAG_DSD_RAW),
2524 VENDOR_FLG(0x23ba, /* Playback Design */
2525 QUIRK_FLAG_CTL_MSG_DELAY | QUIRK_FLAG_IFACE_DELAY |
2526 QUIRK_FLAG_DSD_RAW),
2527 VENDOR_FLG(0x25ce, /* Mytek devices */
2528 QUIRK_FLAG_DSD_RAW),
2529 VENDOR_FLG(0x2622, /* IAG Limited devices */
2530 QUIRK_FLAG_DSD_RAW),
2531 VENDOR_FLG(0x2772, /* Musical Fidelity devices */
2532 QUIRK_FLAG_DSD_RAW),
2533 VENDOR_FLG(0x278b, /* Rotel? */
2534 QUIRK_FLAG_DSD_RAW),
2535 VENDOR_FLG(0x292b, /* Gustard/Ess based devices */
2536 QUIRK_FLAG_DSD_RAW),
2537 VENDOR_FLG(0x2972, /* FiiO devices */
2538 QUIRK_FLAG_DSD_RAW),
2539 VENDOR_FLG(0x2ab6, /* T+A devices */
2540 QUIRK_FLAG_DSD_RAW),
2541 VENDOR_FLG(0x2afd, /* McIntosh Laboratory, Inc. */
2542 QUIRK_FLAG_DSD_RAW),
2543 VENDOR_FLG(0x2d87, /* Cayin device */
2544 QUIRK_FLAG_DSD_RAW),
2545 VENDOR_FLG(0x2fc6, /* Comture-inc devices */
2546 QUIRK_FLAG_DSD_RAW),
2547 VENDOR_FLG(0x3336, /* HEM devices */
2548 QUIRK_FLAG_DSD_RAW),
2549 VENDOR_FLG(0x3353, /* Khadas devices */
2550 QUIRK_FLAG_DSD_RAW),
2551 VENDOR_FLG(0x35f4, /* MSB Technology */
2552 QUIRK_FLAG_DSD_RAW),
2553 VENDOR_FLG(0x3842, /* EVGA */
2554 QUIRK_FLAG_DSD_RAW),
2555 VENDOR_FLG(0xc502, /* HiBy devices */
2556 QUIRK_FLAG_DSD_RAW),
2557
2558 {} /* terminator */
2559 };
2560
2561 #define QUIRK_STRING_ENTRY(x) \
2562 [QUIRK_TYPE_ ## x] = __stringify(x)
2563
2564 static const char *const snd_usb_audio_quirk_flag_names[] = {
2565 QUIRK_STRING_ENTRY(GET_SAMPLE_RATE),
2566 QUIRK_STRING_ENTRY(SHARE_MEDIA_DEVICE),
2567 QUIRK_STRING_ENTRY(ALIGN_TRANSFER),
2568 QUIRK_STRING_ENTRY(TX_LENGTH),
2569 QUIRK_STRING_ENTRY(PLAYBACK_FIRST),
2570 QUIRK_STRING_ENTRY(SKIP_CLOCK_SELECTOR),
2571 QUIRK_STRING_ENTRY(IGNORE_CLOCK_SOURCE),
2572 QUIRK_STRING_ENTRY(ITF_USB_DSD_DAC),
2573 QUIRK_STRING_ENTRY(CTL_MSG_DELAY),
2574 QUIRK_STRING_ENTRY(CTL_MSG_DELAY_1M),
2575 QUIRK_STRING_ENTRY(CTL_MSG_DELAY_5M),
2576 QUIRK_STRING_ENTRY(IFACE_DELAY),
2577 QUIRK_STRING_ENTRY(VALIDATE_RATES),
2578 QUIRK_STRING_ENTRY(DISABLE_AUTOSUSPEND),
2579 QUIRK_STRING_ENTRY(IGNORE_CTL_ERROR),
2580 QUIRK_STRING_ENTRY(DSD_RAW),
2581 QUIRK_STRING_ENTRY(SET_IFACE_FIRST),
2582 QUIRK_STRING_ENTRY(GENERIC_IMPLICIT_FB),
2583 QUIRK_STRING_ENTRY(SKIP_IMPLICIT_FB),
2584 QUIRK_STRING_ENTRY(IFACE_SKIP_CLOSE),
2585 QUIRK_STRING_ENTRY(FORCE_IFACE_RESET),
2586 QUIRK_STRING_ENTRY(FIXED_RATE),
2587 QUIRK_STRING_ENTRY(MIC_RES_16),
2588 QUIRK_STRING_ENTRY(MIC_RES_384),
2589 QUIRK_STRING_ENTRY(MIXER_PLAYBACK_MIN_MUTE),
2590 QUIRK_STRING_ENTRY(MIXER_CAPTURE_MIN_MUTE),
2591 QUIRK_STRING_ENTRY(SKIP_IFACE_SETUP),
2592 QUIRK_STRING_ENTRY(MIXER_PLAYBACK_LINEAR_VOL),
2593 QUIRK_STRING_ENTRY(MIXER_CAPTURE_LINEAR_VOL),
2594 NULL
2595 };
2596
snd_usb_quirk_flag_find_name(unsigned long index)2597 const char *snd_usb_quirk_flag_find_name(unsigned long index)
2598 {
2599 if (index >= ARRAY_SIZE(snd_usb_audio_quirk_flag_names))
2600 return NULL;
2601
2602 return snd_usb_audio_quirk_flag_names[index];
2603 }
2604
snd_usb_quirk_flags_from_name(const char * name)2605 u32 snd_usb_quirk_flags_from_name(const char *name)
2606 {
2607 int i;
2608
2609 if (!name || !*name)
2610 return 0;
2611
2612 for (i = 0; snd_usb_audio_quirk_flag_names[i]; i++) {
2613 if (strcasecmp(name, snd_usb_audio_quirk_flag_names[i]) == 0)
2614 return BIT_U32(i);
2615 }
2616
2617 return 0;
2618 }
2619
snd_usb_apply_flag_dbg(const char * reason,struct snd_usb_audio * chip,unsigned long flag)2620 void snd_usb_apply_flag_dbg(const char *reason,
2621 struct snd_usb_audio *chip,
2622 unsigned long flag)
2623 {
2624 unsigned long bit;
2625
2626 for_each_set_bit(bit, &flag, BYTES_TO_BITS(sizeof(flag))) {
2627 const char *name = snd_usb_audio_quirk_flag_names[bit];
2628
2629 if (name)
2630 usb_audio_dbg(chip,
2631 "From %s apply quirk flag %s for device %04x:%04x\n",
2632 reason, name, USB_ID_VENDOR(chip->usb_id),
2633 USB_ID_PRODUCT(chip->usb_id));
2634 else
2635 usb_audio_warn(chip,
2636 "From %s apply unknown quirk flag 0x%lx for device %04x:%04x\n",
2637 reason, bit, USB_ID_VENDOR(chip->usb_id),
2638 USB_ID_PRODUCT(chip->usb_id));
2639 }
2640 }
2641
snd_usb_init_quirk_flags_table(struct snd_usb_audio * chip)2642 void snd_usb_init_quirk_flags_table(struct snd_usb_audio *chip)
2643 {
2644 const struct usb_audio_quirk_flags_table *p;
2645
2646 for (p = quirk_flags_table; p->id; p++) {
2647 if (chip->usb_id == p->id ||
2648 (!USB_ID_PRODUCT(p->id) &&
2649 USB_ID_VENDOR(chip->usb_id) == USB_ID_VENDOR(p->id))) {
2650 /* Handle DEVICE_STRING_FLG/VENDOR_STRING_FLG. */
2651 if (p->usb_string_match && p->usb_string_match->manufacturer &&
2652 strcmp(p->usb_string_match->manufacturer,
2653 chip->dev->manufacturer ? chip->dev->manufacturer : ""))
2654 continue;
2655 if (p->usb_string_match && p->usb_string_match->product &&
2656 strcmp(p->usb_string_match->product,
2657 chip->dev->product ? chip->dev->product : ""))
2658 continue;
2659
2660 snd_usb_apply_flag_dbg("builtin table", chip, p->flags);
2661 chip->quirk_flags |= p->flags;
2662 return;
2663 }
2664 }
2665 }
2666
snd_usb_init_quirk_flags_parse_string(struct snd_usb_audio * chip,const char * str)2667 void snd_usb_init_quirk_flags_parse_string(struct snd_usb_audio *chip,
2668 const char *str)
2669 {
2670 u16 chip_vid = USB_ID_VENDOR(chip->usb_id);
2671 u16 chip_pid = USB_ID_PRODUCT(chip->usb_id);
2672 u32 mask_flags, unmask_flags, bit;
2673 char *p, *field, *flag;
2674 bool is_unmask;
2675 u16 vid, pid;
2676
2677 char *val __free(kfree) = kstrdup(str, GFP_KERNEL);
2678
2679 if (!val)
2680 return;
2681
2682 for (p = val; p && *p;) {
2683 /* Each entry consists of VID:PID:flags */
2684 field = strsep(&p, ":");
2685 if (!field)
2686 break;
2687
2688 if (strcmp(field, "*") == 0)
2689 vid = 0;
2690 else if (kstrtou16(field, 16, &vid))
2691 break;
2692
2693 field = strsep(&p, ":");
2694 if (!field)
2695 break;
2696
2697 if (strcmp(field, "*") == 0)
2698 pid = 0;
2699 else if (kstrtou16(field, 16, &pid))
2700 break;
2701
2702 field = strsep(&p, ";");
2703 if (!field || !*field)
2704 break;
2705
2706 if ((vid != 0 && vid != chip_vid) ||
2707 (pid != 0 && pid != chip_pid))
2708 continue;
2709
2710 /* Collect the flags */
2711 mask_flags = 0;
2712 unmask_flags = 0;
2713 while (field && *field) {
2714 flag = strsep(&field, "|");
2715
2716 if (!flag)
2717 break;
2718
2719 if (*flag == '!') {
2720 is_unmask = true;
2721 flag++;
2722 } else {
2723 is_unmask = false;
2724 }
2725
2726 if (!kstrtou32(flag, 16, &bit)) {
2727 if (is_unmask)
2728 unmask_flags |= bit;
2729 else
2730 mask_flags |= bit;
2731
2732 break;
2733 }
2734
2735 bit = snd_usb_quirk_flags_from_name(flag);
2736
2737 if (bit) {
2738 if (is_unmask)
2739 unmask_flags |= bit;
2740 else
2741 mask_flags |= bit;
2742 } else {
2743 pr_warn("snd_usb_audio: unknown flag %s while parsing param quirk_flags\n",
2744 flag);
2745 }
2746 }
2747
2748 chip->quirk_flags &= ~unmask_flags;
2749 chip->quirk_flags |= mask_flags;
2750 snd_usb_apply_flag_dbg("module param", chip,
2751 chip->quirk_flags);
2752 }
2753 }
2754