2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/usb.h>
20 #include <linux/usb/audio.h>
21 #include <linux/usb/midi.h>
23 #include <sound/control.h>
24 #include <sound/core.h>
25 #include <sound/info.h>
26 #include <sound/pcm.h>
31 #include "mixer_quirks.h"
41 * handle the quirks for the contained interfaces
43 static int create_composite_quirk(struct snd_usb_audio *chip,
44 struct usb_interface *iface,
45 struct usb_driver *driver,
46 const struct snd_usb_audio_quirk *quirk_comp)
48 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
49 const struct snd_usb_audio_quirk *quirk;
52 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
53 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
56 if (quirk->ifnum != probed_ifnum &&
57 usb_interface_claimed(iface))
59 err = snd_usb_create_quirk(chip, iface, driver, quirk);
64 for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
65 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
68 if (quirk->ifnum != probed_ifnum &&
69 !usb_interface_claimed(iface)) {
70 err = usb_driver_claim_interface(driver, iface,
71 USB_AUDIO_IFACE_UNUSED);
80 static int ignore_interface_quirk(struct snd_usb_audio *chip,
81 struct usb_interface *iface,
82 struct usb_driver *driver,
83 const struct snd_usb_audio_quirk *quirk)
90 * Allow alignment on audio sub-slot (channel samples) rather than
91 * on audio slots (audio frames)
93 static int create_align_transfer_quirk(struct snd_usb_audio *chip,
94 struct usb_interface *iface,
95 struct usb_driver *driver,
96 const struct snd_usb_audio_quirk *quirk)
99 return 1; /* Continue with creating streams and mixer */
102 static int create_any_midi_quirk(struct snd_usb_audio *chip,
103 struct usb_interface *intf,
104 struct usb_driver *driver,
105 const struct snd_usb_audio_quirk *quirk)
107 return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
111 * create a stream for an interface with proper descriptors
113 static int create_standard_audio_quirk(struct snd_usb_audio *chip,
114 struct usb_interface *iface,
115 struct usb_driver *driver,
116 const struct snd_usb_audio_quirk *quirk)
118 struct usb_host_interface *alts;
119 struct usb_interface_descriptor *altsd;
122 if (chip->usb_id == USB_ID(0x1686, 0x00dd)) /* Zoom R16/24 */
123 chip->tx_length_quirk = 1;
125 alts = &iface->altsetting[0];
126 altsd = get_iface_desc(alts);
127 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
129 usb_audio_err(chip, "cannot setup if %d: error %d\n",
130 altsd->bInterfaceNumber, err);
133 /* reset the current interface */
134 usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
139 * create a stream for an endpoint/altsetting without proper descriptors
141 static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
142 struct usb_interface *iface,
143 struct usb_driver *driver,
144 const struct snd_usb_audio_quirk *quirk)
146 struct audioformat *fp;
147 struct usb_host_interface *alts;
148 struct usb_interface_descriptor *altsd;
150 unsigned *rate_table = NULL;
152 fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
156 INIT_LIST_HEAD(&fp->list);
157 if (fp->nr_rates > MAX_NR_RATES) {
161 if (fp->nr_rates > 0) {
162 rate_table = kmemdup(fp->rate_table,
163 sizeof(int) * fp->nr_rates, GFP_KERNEL);
168 fp->rate_table = rate_table;
171 stream = (fp->endpoint & USB_DIR_IN)
172 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
173 err = snd_usb_add_audio_stream(chip, stream, fp);
176 if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
177 fp->altset_idx >= iface->num_altsetting) {
181 alts = &iface->altsetting[fp->altset_idx];
182 altsd = get_iface_desc(alts);
183 if (altsd->bNumEndpoints < 1) {
188 fp->protocol = altsd->bInterfaceProtocol;
190 if (fp->datainterval == 0)
191 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
192 if (fp->maxpacksize == 0)
193 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
194 usb_set_interface(chip->dev, fp->iface, 0);
195 snd_usb_init_pitch(chip, fp->iface, alts, fp);
196 snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
200 list_del(&fp->list); /* unlink for avoiding double-free */
206 static int create_auto_pcm_quirk(struct snd_usb_audio *chip,
207 struct usb_interface *iface,
208 struct usb_driver *driver)
210 struct usb_host_interface *alts;
211 struct usb_interface_descriptor *altsd;
212 struct usb_endpoint_descriptor *epd;
213 struct uac1_as_header_descriptor *ashd;
214 struct uac_format_type_i_discrete_descriptor *fmtd;
217 * Most Roland/Yamaha audio streaming interfaces have more or less
218 * standard descriptors, but older devices might lack descriptors, and
219 * future ones might change, so ensure that we fail silently if the
220 * interface doesn't look exactly right.
223 /* must have a non-zero altsetting for streaming */
224 if (iface->num_altsetting < 2)
226 alts = &iface->altsetting[1];
227 altsd = get_iface_desc(alts);
229 /* must have an isochronous endpoint for streaming */
230 if (altsd->bNumEndpoints < 1)
232 epd = get_endpoint(alts, 0);
233 if (!usb_endpoint_xfer_isoc(epd))
236 /* must have format descriptors */
237 ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
239 fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
241 if (!ashd || ashd->bLength < 7 ||
242 !fmtd || fmtd->bLength < 8)
245 return create_standard_audio_quirk(chip, iface, driver, NULL);
248 static int create_yamaha_midi_quirk(struct snd_usb_audio *chip,
249 struct usb_interface *iface,
250 struct usb_driver *driver,
251 struct usb_host_interface *alts)
253 static const struct snd_usb_audio_quirk yamaha_midi_quirk = {
254 .type = QUIRK_MIDI_YAMAHA
256 struct usb_midi_in_jack_descriptor *injd;
257 struct usb_midi_out_jack_descriptor *outjd;
259 /* must have some valid jack descriptors */
260 injd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
261 NULL, USB_MS_MIDI_IN_JACK);
262 outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
263 NULL, USB_MS_MIDI_OUT_JACK);
266 if ((injd && !snd_usb_validate_midi_desc(injd)) ||
267 (outjd && !snd_usb_validate_midi_desc(outjd)))
269 if (injd && (injd->bLength < 5 ||
270 (injd->bJackType != USB_MS_EMBEDDED &&
271 injd->bJackType != USB_MS_EXTERNAL)))
273 if (outjd && (outjd->bLength < 6 ||
274 (outjd->bJackType != USB_MS_EMBEDDED &&
275 outjd->bJackType != USB_MS_EXTERNAL)))
277 return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk);
280 static int create_roland_midi_quirk(struct snd_usb_audio *chip,
281 struct usb_interface *iface,
282 struct usb_driver *driver,
283 struct usb_host_interface *alts)
285 static const struct snd_usb_audio_quirk roland_midi_quirk = {
286 .type = QUIRK_MIDI_ROLAND
288 u8 *roland_desc = NULL;
290 /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
292 roland_desc = snd_usb_find_csint_desc(alts->extra,
297 if (roland_desc[0] < 6 || roland_desc[3] != 2)
299 return create_any_midi_quirk(chip, iface, driver,
304 static int create_std_midi_quirk(struct snd_usb_audio *chip,
305 struct usb_interface *iface,
306 struct usb_driver *driver,
307 struct usb_host_interface *alts)
309 struct usb_ms_header_descriptor *mshd;
310 struct usb_ms_endpoint_descriptor *msepd;
312 /* must have the MIDIStreaming interface header descriptor*/
313 mshd = (struct usb_ms_header_descriptor *)alts->extra;
314 if (alts->extralen < 7 ||
316 mshd->bDescriptorType != USB_DT_CS_INTERFACE ||
317 mshd->bDescriptorSubtype != USB_MS_HEADER)
319 /* must have the MIDIStreaming endpoint descriptor*/
320 msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra;
321 if (alts->endpoint[0].extralen < 4 ||
322 msepd->bLength < 4 ||
323 msepd->bDescriptorType != USB_DT_CS_ENDPOINT ||
324 msepd->bDescriptorSubtype != UAC_MS_GENERAL ||
325 msepd->bNumEmbMIDIJack < 1 ||
326 msepd->bNumEmbMIDIJack > 16)
329 return create_any_midi_quirk(chip, iface, driver, NULL);
332 static int create_auto_midi_quirk(struct snd_usb_audio *chip,
333 struct usb_interface *iface,
334 struct usb_driver *driver)
336 struct usb_host_interface *alts;
337 struct usb_interface_descriptor *altsd;
338 struct usb_endpoint_descriptor *epd;
341 alts = &iface->altsetting[0];
342 altsd = get_iface_desc(alts);
344 /* must have at least one bulk/interrupt endpoint for streaming */
345 if (altsd->bNumEndpoints < 1)
347 epd = get_endpoint(alts, 0);
348 if (!usb_endpoint_xfer_bulk(epd) &&
349 !usb_endpoint_xfer_int(epd))
352 switch (USB_ID_VENDOR(chip->usb_id)) {
353 case 0x0499: /* Yamaha */
354 err = create_yamaha_midi_quirk(chip, iface, driver, alts);
358 case 0x0582: /* Roland */
359 err = create_roland_midi_quirk(chip, iface, driver, alts);
365 return create_std_midi_quirk(chip, iface, driver, alts);
368 static int create_autodetect_quirk(struct snd_usb_audio *chip,
369 struct usb_interface *iface,
370 struct usb_driver *driver)
374 err = create_auto_pcm_quirk(chip, iface, driver);
376 err = create_auto_midi_quirk(chip, iface, driver);
380 static int create_autodetect_quirks(struct snd_usb_audio *chip,
381 struct usb_interface *iface,
382 struct usb_driver *driver,
383 const struct snd_usb_audio_quirk *quirk)
385 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
386 int ifcount, ifnum, err;
388 err = create_autodetect_quirk(chip, iface, driver);
393 * ALSA PCM playback/capture devices cannot be registered in two steps,
394 * so we have to claim the other corresponding interface here.
396 ifcount = chip->dev->actconfig->desc.bNumInterfaces;
397 for (ifnum = 0; ifnum < ifcount; ifnum++) {
398 if (ifnum == probed_ifnum || quirk->ifnum >= 0)
400 iface = usb_ifnum_to_if(chip->dev, ifnum);
402 usb_interface_claimed(iface) ||
403 get_iface_desc(iface->altsetting)->bInterfaceClass !=
404 USB_CLASS_VENDOR_SPEC)
407 err = create_autodetect_quirk(chip, iface, driver);
409 err = usb_driver_claim_interface(driver, iface,
410 USB_AUDIO_IFACE_UNUSED);
420 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
421 * The only way to detect the sample rate is by looking at wMaxPacketSize.
423 static int create_uaxx_quirk(struct snd_usb_audio *chip,
424 struct usb_interface *iface,
425 struct usb_driver *driver,
426 const struct snd_usb_audio_quirk *quirk)
428 static const struct audioformat ua_format = {
429 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
431 .fmt_type = UAC_FORMAT_TYPE_I,
434 .rates = SNDRV_PCM_RATE_CONTINUOUS,
436 struct usb_host_interface *alts;
437 struct usb_interface_descriptor *altsd;
438 struct audioformat *fp;
441 /* both PCM and MIDI interfaces have 2 or more altsettings */
442 if (iface->num_altsetting < 2)
444 alts = &iface->altsetting[1];
445 altsd = get_iface_desc(alts);
447 if (altsd->bNumEndpoints == 2) {
448 static const struct snd_usb_midi_endpoint_info ua700_ep = {
449 .out_cables = 0x0003,
452 static const struct snd_usb_audio_quirk ua700_quirk = {
453 .type = QUIRK_MIDI_FIXED_ENDPOINT,
456 static const struct snd_usb_midi_endpoint_info uaxx_ep = {
457 .out_cables = 0x0001,
460 static const struct snd_usb_audio_quirk uaxx_quirk = {
461 .type = QUIRK_MIDI_FIXED_ENDPOINT,
464 const struct snd_usb_audio_quirk *quirk =
465 chip->usb_id == USB_ID(0x0582, 0x002b)
466 ? &ua700_quirk : &uaxx_quirk;
467 return __snd_usbmidi_create(chip->card, iface,
468 &chip->midi_list, quirk,
472 if (altsd->bNumEndpoints != 1)
475 fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
479 fp->iface = altsd->bInterfaceNumber;
480 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
481 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
482 fp->datainterval = 0;
483 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
484 INIT_LIST_HEAD(&fp->list);
486 switch (fp->maxpacksize) {
488 fp->rate_max = fp->rate_min = 44100;
492 fp->rate_max = fp->rate_min = 48000;
496 fp->rate_max = fp->rate_min = 96000;
499 usb_audio_err(chip, "unknown sample rate\n");
504 stream = (fp->endpoint & USB_DIR_IN)
505 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
506 err = snd_usb_add_audio_stream(chip, stream, fp);
508 list_del(&fp->list); /* unlink for avoiding double-free */
512 usb_set_interface(chip->dev, fp->iface, 0);
517 * Create a standard mixer for the specified interface.
519 static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
520 struct usb_interface *iface,
521 struct usb_driver *driver,
522 const struct snd_usb_audio_quirk *quirk)
524 if (quirk->ifnum < 0)
527 return snd_usb_create_mixer(chip, quirk->ifnum, 0);
531 static int setup_fmt_after_resume_quirk(struct snd_usb_audio *chip,
532 struct usb_interface *iface,
533 struct usb_driver *driver,
534 const struct snd_usb_audio_quirk *quirk)
536 chip->setup_fmt_after_resume_quirk = 1;
537 return 1; /* Continue with creating streams and mixer */
541 * audio-interface quirks
543 * returns zero if no standard audio/MIDI parsing is needed.
544 * returns a positive value if standard audio/midi interfaces are parsed
546 * returns a negative value at error.
548 int snd_usb_create_quirk(struct snd_usb_audio *chip,
549 struct usb_interface *iface,
550 struct usb_driver *driver,
551 const struct snd_usb_audio_quirk *quirk)
553 typedef int (*quirk_func_t)(struct snd_usb_audio *,
554 struct usb_interface *,
556 const struct snd_usb_audio_quirk *);
557 static const quirk_func_t quirk_funcs[] = {
558 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
559 [QUIRK_COMPOSITE] = create_composite_quirk,
560 [QUIRK_AUTODETECT] = create_autodetect_quirks,
561 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
562 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
563 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
564 [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
565 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
566 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
567 [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
568 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
569 [QUIRK_MIDI_CME] = create_any_midi_quirk,
570 [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
571 [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
572 [QUIRK_MIDI_CH345] = create_any_midi_quirk,
573 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
574 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
575 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
576 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
577 [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
578 [QUIRK_SETUP_FMT_AFTER_RESUME] = setup_fmt_after_resume_quirk,
581 if (quirk->type < QUIRK_TYPE_COUNT) {
582 return quirk_funcs[quirk->type](chip, iface, driver, quirk);
584 usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
593 #define EXTIGY_FIRMWARE_SIZE_OLD 794
594 #define EXTIGY_FIRMWARE_SIZE_NEW 483
596 static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
598 struct usb_host_config *config = dev->actconfig;
601 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
602 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
603 dev_dbg(&dev->dev, "sending Extigy boot sequence...\n");
604 /* Send message to force it to reconnect with full interface. */
605 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
606 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
608 dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
609 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
610 &dev->descriptor, sizeof(dev->descriptor));
611 config = dev->actconfig;
613 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
614 err = usb_reset_configuration(dev);
616 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
617 dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
618 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
619 return -ENODEV; /* quit this anyway */
624 static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
628 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
629 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
632 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
633 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
640 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
644 if (dev->actconfig->desc.bConfigurationValue == 1) {
646 "Fast Track Pro switching to config #2\n");
647 /* This function has to be available by the usb core module.
648 * if it is not avialable the boot quirk has to be left out
649 * and the configuration has to be set by udev or hotplug
652 err = usb_driver_set_configuration(dev, 2);
655 "error usb_driver_set_configuration: %d\n",
657 /* Always return an error, so that we stop creating a device
658 that will just be destroyed and recreated with a new
662 dev_info(&dev->dev, "Fast Track Pro config OK\n");
668 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
669 * documented in the device's data sheet.
671 static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
675 buf[1] = value & 0xff;
676 buf[2] = (value >> 8) & 0xff;
678 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
679 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
683 static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
686 * Enable line-out driver mode, set headphone source to front
687 * channels, enable stereo mic.
689 return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
693 * C-Media CM6206 is based on CM106 with two additional
694 * registers that are not documented in the data sheet.
695 * Values here are chosen based on sniffing USB traffic
698 static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
701 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
703 for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
704 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
712 /* quirk for Plantronics GameCom 780 with CM6302 chip */
713 static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev)
715 /* set the initial volume and don't change; other values are either
716 * too loud or silent due to firmware bug (bko#65251)
718 u8 buf[2] = { 0x74, 0xe3 };
719 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
720 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
721 UAC_FU_VOLUME << 8, 9 << 8, buf, 2);
725 * Novation Twitch DJ controller
726 * Focusrite Novation Saffire 6 USB audio card
728 static int snd_usb_novation_boot_quirk(struct usb_device *dev)
730 /* preemptively set up the device because otherwise the
731 * raw MIDI endpoints are not active */
732 usb_set_interface(dev, 0, 1);
737 * This call will put the synth in "USB send" mode, i.e it will send MIDI
738 * messages through USB (this is disabled at startup). The synth will
739 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
740 * sign on its LCD. Values here are chosen based on sniffing USB traffic
743 static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
745 int err, actual_length;
747 /* "midi send" enable */
748 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
750 void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
753 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
754 ARRAY_SIZE(seq), &actual_length, 1000);
763 * Some sound cards from Native Instruments are in fact compliant to the USB
764 * audio standard of version 2 and other approved USB standards, even though
765 * they come up as vendor-specific device when first connected.
767 * However, they can be told to come up with a new set of descriptors
768 * upon their next enumeration, and the interfaces announced by the new
769 * descriptors will then be handled by the kernel's class drivers. As the
770 * product ID will also change, no further checks are required.
773 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
775 int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
776 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
777 1, 0, NULL, 0, 1000);
782 usb_reset_device(dev);
784 /* return -EAGAIN, so the creation of an audio interface for this
785 * temporary device is aborted. The device will reconnect with a
790 static void mbox2_setup_48_24_magic(struct usb_device *dev)
795 /* Choose 48000Hz permanently */
800 /* Send the magic! */
801 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
802 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
803 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
804 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
805 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
806 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
807 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
808 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
812 /* Digidesign Mbox 2 needs to load firmware onboard
813 * and driver must wait a few seconds for initialisation.
816 #define MBOX2_FIRMWARE_SIZE 646
817 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
818 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
820 static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
822 struct usb_host_config *config = dev->actconfig;
824 u8 bootresponse[0x12];
828 fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
830 if (fwsize != MBOX2_FIRMWARE_SIZE) {
831 dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
835 dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
838 bootresponse[0] = MBOX2_BOOT_LOADING;
839 while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
840 msleep(500); /* 0.5 second delay */
841 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
842 /* Control magic - load onboard firmware */
843 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
844 if (bootresponse[0] == MBOX2_BOOT_READY)
846 dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
850 if (bootresponse[0] != MBOX2_BOOT_READY) {
851 dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
855 dev_dbg(&dev->dev, "device initialised!\n");
857 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
858 &dev->descriptor, sizeof(dev->descriptor));
859 config = dev->actconfig;
861 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
863 err = usb_reset_configuration(dev);
865 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
866 dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
867 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
869 mbox2_setup_48_24_magic(dev);
871 dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
873 return 0; /* Successful boot */
876 static int snd_usb_axefx3_boot_quirk(struct usb_device *dev)
880 dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n");
882 /* If the Axe-Fx III has not fully booted, it will timeout when trying
883 * to enable the audio streaming interface. A more generous timeout is
884 * used here to detect when the Axe-Fx III has finished booting as the
885 * set interface message will be acked once it has
887 err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
888 USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
889 1, 1, NULL, 0, 120000);
892 "failed waiting for Axe-Fx III to boot: %d\n", err);
896 dev_dbg(&dev->dev, "Axe-Fx III is now ready\n");
898 err = usb_set_interface(dev, 1, 0);
901 "error stopping Axe-Fx III interface: %d\n", err);
909 #define MAUDIO_SET 0x01 /* parse device_setup */
910 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
911 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
912 #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
913 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
914 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
915 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
916 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
917 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
918 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
919 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
921 static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
922 int iface, int altno)
924 /* Reset ALL ifaces to 0 altsetting.
925 * Call it for every possible altsetting of every interface.
927 usb_set_interface(chip->dev, iface, 0);
928 if (chip->setup & MAUDIO_SET) {
929 if (chip->setup & MAUDIO_SET_COMPATIBLE) {
930 if (iface != 1 && iface != 2)
931 return 1; /* skip all interfaces but 1 and 2 */
934 if (iface == 1 || iface == 2)
935 return 1; /* skip interfaces 1 and 2 */
936 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
937 return 1; /* skip this altsetting */
938 mask = chip->setup & MAUDIO_SET_MASK;
939 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
940 return 1; /* skip this altsetting */
941 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
942 return 1; /* skip this altsetting */
943 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
944 return 1; /* skip this altsetting */
948 "using altsetting %d for interface %d config %d\n",
949 altno, iface, chip->setup);
950 return 0; /* keep this altsetting */
953 static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
957 /* Reset ALL ifaces to 0 altsetting.
958 * Call it for every possible altsetting of every interface.
960 usb_set_interface(chip->dev, iface, 0);
962 if (chip->setup & MAUDIO_SET) {
964 if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
965 return 1; /* skip this altsetting */
966 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
967 return 1; /* skip this altsetting */
968 mask = chip->setup & MAUDIO_SET_MASK;
969 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
970 return 1; /* skip this altsetting */
971 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
972 return 1; /* skip this altsetting */
973 if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
974 return 1; /* skip this altsetting */
975 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
976 return 1; /* skip this altsetting */
979 return 0; /* keep this altsetting */
982 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
983 int iface, int altno)
985 /* Reset ALL ifaces to 0 altsetting.
986 * Call it for every possible altsetting of every interface.
988 usb_set_interface(chip->dev, iface, 0);
990 /* possible configuration where both inputs and only one output is
991 *used is not supported by the current setup
993 if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
994 if (chip->setup & MAUDIO_SET_96K) {
995 if (altno != 3 && altno != 6)
997 } else if (chip->setup & MAUDIO_SET_DI) {
999 return 1; /* no analog input */
1000 if (altno != 2 && altno != 5)
1001 return 1; /* enable only altsets 2 and 5 */
1004 return 1; /* disable digialt input */
1005 if (altno != 2 && altno != 5)
1006 return 1; /* enalbe only altsets 2 and 5 */
1009 /* keep only 16-Bit mode */
1015 "using altsetting %d for interface %d config %d\n",
1016 altno, iface, chip->setup);
1017 return 0; /* keep this altsetting */
1020 int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
1024 /* audiophile usb: skip altsets incompatible with device_setup */
1025 if (chip->usb_id == USB_ID(0x0763, 0x2003))
1026 return audiophile_skip_setting_quirk(chip, iface, altno);
1027 /* quattro usb: skip altsets incompatible with device_setup */
1028 if (chip->usb_id == USB_ID(0x0763, 0x2001))
1029 return quattro_skip_setting_quirk(chip, iface, altno);
1030 /* fasttrackpro usb: skip altsets incompatible with device_setup */
1031 if (chip->usb_id == USB_ID(0x0763, 0x2012))
1032 return fasttrackpro_skip_setting_quirk(chip, iface, altno);
1037 int snd_usb_apply_boot_quirk(struct usb_device *dev,
1038 struct usb_interface *intf,
1039 const struct snd_usb_audio_quirk *quirk,
1043 case USB_ID(0x041e, 0x3000):
1044 /* SB Extigy needs special boot-up sequence */
1045 /* if more models come, this will go to the quirk list. */
1046 return snd_usb_extigy_boot_quirk(dev, intf);
1048 case USB_ID(0x041e, 0x3020):
1049 /* SB Audigy 2 NX needs its own boot-up magic, too */
1050 return snd_usb_audigy2nx_boot_quirk(dev);
1052 case USB_ID(0x10f5, 0x0200):
1053 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
1054 return snd_usb_cm106_boot_quirk(dev);
1056 case USB_ID(0x0d8c, 0x0102):
1057 /* C-Media CM6206 / CM106-Like Sound Device */
1058 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
1059 return snd_usb_cm6206_boot_quirk(dev);
1061 case USB_ID(0x0dba, 0x3000):
1062 /* Digidesign Mbox 2 */
1063 return snd_usb_mbox2_boot_quirk(dev);
1065 case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
1066 case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
1067 return snd_usb_novation_boot_quirk(dev);
1069 case USB_ID(0x133e, 0x0815):
1070 /* Access Music VirusTI Desktop */
1071 return snd_usb_accessmusic_boot_quirk(dev);
1073 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
1074 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
1075 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
1076 return snd_usb_nativeinstruments_boot_quirk(dev);
1077 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1078 return snd_usb_fasttrackpro_boot_quirk(dev);
1079 case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
1080 return snd_usb_gamecon780_boot_quirk(dev);
1081 case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx 3 */
1082 return snd_usb_axefx3_boot_quirk(dev);
1089 * check if the device uses big-endian samples
1091 int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
1093 /* it depends on altsetting whether the device is big-endian or not */
1094 switch (chip->usb_id) {
1095 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
1096 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1097 fp->altsetting == 5 || fp->altsetting == 6)
1100 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1101 if (chip->setup == 0x00 ||
1102 fp->altsetting == 1 || fp->altsetting == 2 ||
1103 fp->altsetting == 3)
1106 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
1107 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1108 fp->altsetting == 5 || fp->altsetting == 6)
1116 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
1117 * not for interface.
1121 EMU_QUIRK_SR_44100HZ = 0,
1122 EMU_QUIRK_SR_48000HZ,
1123 EMU_QUIRK_SR_88200HZ,
1124 EMU_QUIRK_SR_96000HZ,
1125 EMU_QUIRK_SR_176400HZ,
1126 EMU_QUIRK_SR_192000HZ
1129 static void set_format_emu_quirk(struct snd_usb_substream *subs,
1130 struct audioformat *fmt)
1132 unsigned char emu_samplerate_id = 0;
1134 /* When capture is active
1135 * sample rate shouldn't be changed
1136 * by playback substream
1138 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
1139 if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
1143 switch (fmt->rate_min) {
1145 emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
1148 emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
1151 emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
1154 emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
1157 emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
1160 emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
1163 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
1164 subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
1167 void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
1168 struct audioformat *fmt)
1170 switch (subs->stream->chip->usb_id) {
1171 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
1172 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
1173 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
1174 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
1175 set_format_emu_quirk(subs, fmt);
1177 case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
1178 subs->stream_offset_adj = 2;
1183 bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1185 /* devices which do not support reading the sample rate. */
1186 switch (chip->usb_id) {
1187 case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
1188 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1189 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
1190 case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
1191 case USB_ID(0x05a7, 0x1020): /* Bose Companion 5 */
1192 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1193 case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */
1194 case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */
1195 case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */
1196 case USB_ID(0x2912, 0x30c8): /* Audioengine D1 */
1197 case USB_ID(0x413c, 0xa506): /* Dell AE515 sound bar */
1198 case USB_ID(0x046d, 0x084c): /* Logitech ConferenceCam Connect */
1202 /* devices of these vendors don't support reading rate, either */
1203 switch (USB_ID_VENDOR(chip->usb_id)) {
1204 case 0x045E: /* MS Lifecam */
1205 case 0x047F: /* Plantronics */
1206 case 0x1de7: /* Phoenix Audio */
1213 /* ITF-USB DSD based DACs need a vendor cmd to switch
1214 * between PCM and native DSD mode
1216 static bool is_itf_usb_dsd_dac(unsigned int id)
1219 case USB_ID(0x154e, 0x1002): /* Denon DCD-1500RE */
1220 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1221 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1222 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1223 case USB_ID(0x1852, 0x5065): /* Luxman DA-06 */
1224 case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-501V2/UD-503/NT-503 */
1225 case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */
1226 case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */
1232 int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
1233 struct audioformat *fmt)
1235 struct usb_device *dev = subs->dev;
1238 if (is_itf_usb_dsd_dac(subs->stream->chip->usb_id)) {
1239 /* First switch to alt set 0, otherwise the mode switch cmd
1240 * will not be accepted by the DAC
1242 err = usb_set_interface(dev, fmt->iface, 0);
1246 msleep(20); /* Delay needed after setting the interface */
1248 /* Vendor mode switch cmd is required. */
1249 if (fmt->formats & SNDRV_PCM_FMTBIT_DSD_U32_BE) {
1250 /* DSD mode (DSD_U32) requested */
1251 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
1252 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
1258 /* PCM or DOP mode (S32) requested */
1259 /* PCM mode (S16) requested */
1260 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
1261 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
1272 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
1275 * "Playback Design" products send bogus feedback data at the start
1276 * of the stream. Ignore them.
1278 if (USB_ID_VENDOR(ep->chip->usb_id) == 0x23ba &&
1279 ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
1280 ep->skip_packets = 4;
1283 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
1284 * world latency varies by approx. +/- 50 frames (at 96KHz) each time
1285 * the stream is (re)started. When skipping packets 16 at endpoint
1286 * start up, the real world latency is stable within +/- 1 frame (also
1287 * across power cycles).
1289 if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
1290 ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
1291 ep->type == SND_USB_ENDPOINT_TYPE_DATA)
1292 ep->skip_packets = 16;
1294 /* Work around devices that report unreasonable feedback data */
1295 if ((ep->chip->usb_id == USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
1296 ep->chip->usb_id == USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
1297 ep->syncmaxsize == 4)
1298 ep->tenor_fb_quirk = 1;
1301 void snd_usb_set_interface_quirk(struct usb_device *dev)
1303 struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
1308 * "Playback Design" products need a 50ms delay after setting the
1311 switch (USB_ID_VENDOR(chip->usb_id)) {
1312 case 0x23ba: /* Playback Design */
1313 case 0x0644: /* TEAC Corp. */
1319 /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
1320 void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1321 __u8 request, __u8 requesttype, __u16 value,
1322 __u16 index, void *data, __u16 size)
1324 struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
1329 * "Playback Design" products need a 20ms delay after each
1330 * class compliant request
1332 if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
1333 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1337 * "TEAC Corp." products need a 20ms delay after each
1338 * class compliant request
1340 if (USB_ID_VENDOR(chip->usb_id) == 0x0644 &&
1341 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1344 /* ITF-USB DSD based DACs functionality need a delay
1345 * after each class compliant request
1347 if (is_itf_usb_dsd_dac(chip->usb_id)
1348 && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1352 * Plantronics headsets (C320, C320-M, etc) need a delay to avoid
1353 * random microhpone failures.
1355 if (USB_ID_VENDOR(chip->usb_id) == 0x047f &&
1356 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1359 /* Zoom R16/24, many Logitech(at least H650e/H570e/BCC950),
1360 * Jabra 550a, Kingston HyperX needs a tiny delay here,
1361 * otherwise requests like get/set frequency return
1362 * as failed despite actually succeeding.
1364 if ((chip->usb_id == USB_ID(0x1686, 0x00dd) ||
1365 USB_ID_VENDOR(chip->usb_id) == 0x046d || /* Logitech */
1366 chip->usb_id == USB_ID(0x0b0e, 0x0349) ||
1367 chip->usb_id == USB_ID(0x0951, 0x16ad)) &&
1368 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1369 usleep_range(1000, 2000);
1372 * Samsung USBC Headset (AKG) need a tiny delay after each
1373 * class compliant request. (Model number: AAM625R or AAM627R)
1375 if (chip->usb_id == USB_ID(0x04e8, 0xa051) &&
1376 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1377 usleep_range(5000, 6000);
1381 * snd_usb_interface_dsd_format_quirks() is called from format.c to
1382 * augment the PCM format bit-field for DSD types. The UAC standards
1383 * don't have a designated bit field to denote DSD-capable interfaces,
1384 * hence all hardware that is known to support this format has to be
1387 u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1388 struct audioformat *fp,
1389 unsigned int sample_bytes)
1391 struct usb_interface *iface;
1393 /* Playback Designs */
1394 if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
1395 USB_ID_PRODUCT(chip->usb_id) < 0x0110) {
1396 switch (fp->altsetting) {
1399 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
1401 fp->dsd_bitrev = true;
1402 return SNDRV_PCM_FMTBIT_DSD_U8;
1404 fp->dsd_bitrev = true;
1405 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
1409 /* XMOS based USB DACs */
1410 switch (chip->usb_id) {
1411 case USB_ID(0x1511, 0x0037): /* AURALiC VEGA */
1412 case USB_ID(0x2522, 0x0012): /* LH Labs VI DAC Infinity */
1413 case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
1414 if (fp->altsetting == 2)
1415 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1418 case USB_ID(0x0d8c, 0x0316): /* Hegel HD12 DSD */
1419 case USB_ID(0x10cb, 0x0103): /* The Bit Opus #3; with fp->dsd_raw */
1420 case USB_ID(0x16d0, 0x06b2): /* NuPrime DAC-10 */
1421 case USB_ID(0x16d0, 0x09dd): /* Encore mDSD */
1422 case USB_ID(0x16d0, 0x0733): /* Furutech ADL Stratos */
1423 case USB_ID(0x16d0, 0x09db): /* NuPrime Audio DAC-9 */
1424 case USB_ID(0x1db5, 0x0003): /* Bryston BDA3 */
1425 case USB_ID(0x22e1, 0xca01): /* HDTA Serenade DSD */
1426 case USB_ID(0x249c, 0x9326): /* M2Tech Young MkIII */
1427 case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
1428 case USB_ID(0x2622, 0x0041): /* Audiolab M-DAC+ */
1429 case USB_ID(0x27f7, 0x3002): /* W4S DAC-2v2SE */
1430 case USB_ID(0x29a2, 0x0086): /* Mutec MC3+ USB */
1431 case USB_ID(0x6b42, 0x0042): /* MSB Technology */
1432 if (fp->altsetting == 3)
1433 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1436 /* Amanero Combo384 USB based DACs with native DSD support */
1437 case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
1438 case USB_ID(0x2ab6, 0x0004): /* T+A DAC8DSD-V2.0, MP1000E-V2.0, MP2000R-V2.0, MP2500R-V2.0, MP3100HV-V2.0 */
1439 case USB_ID(0x2ab6, 0x0005): /* T+A USB HD Audio 1 */
1440 case USB_ID(0x2ab6, 0x0006): /* T+A USB HD Audio 2 */
1441 if (fp->altsetting == 2) {
1442 switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) {
1444 return SNDRV_PCM_FMTBIT_DSD_U32_LE;
1447 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1453 case USB_ID(0x16d0, 0x0a23):
1454 if (fp->altsetting == 2)
1455 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1462 /* ITF-USB DSD based DACs */
1463 if (is_itf_usb_dsd_dac(chip->usb_id)) {
1464 iface = usb_ifnum_to_if(chip->dev, fp->iface);
1466 /* Altsetting 2 support native DSD if the num of altsets is
1468 * Altsetting 3 support native DSD if the num of altsets is
1471 if (fp->altsetting == iface->num_altsetting - 1)
1472 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1475 /* Mostly generic method to detect many DSD-capable implementations -
1476 * from XMOS/Thesycon
1478 switch (USB_ID_VENDOR(chip->usb_id)) {
1479 case 0x152a: /* Thesycon devices */
1480 case 0x20b1: /* XMOS based devices */
1481 case 0x22d9: /* Oppo */
1482 case 0x23ba: /* Playback Designs */
1483 case 0x25ce: /* Mytek devices */
1484 case 0x278b: /* Rotel? */
1485 case 0x292b: /* Gustard/Ess based devices */
1486 case 0x2972: /* FiiO devices */
1487 case 0x2ab6: /* T+A devices */
1488 case 0x3353: /* Khadas devices */
1489 case 0x3842: /* EVGA */
1490 case 0xc502: /* HiBy devices */
1492 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1502 void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
1503 struct audioformat *fp,
1506 switch (chip->usb_id) {
1507 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
1508 /* Optoplay sets the sample rate attribute although
1509 * it seems not supporting it in fact.
1511 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
1513 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
1514 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1515 /* doesn't set the sample rate attribute, but supports it */
1516 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
1518 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
1519 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1520 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
1521 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
1522 an older model 77d:223) */
1524 * plantronics headset and Griffin iMic have set adaptive-in
1525 * although it's really not...
1527 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
1528 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1529 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
1531 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
1537 * registration quirk:
1538 * the registration is skipped if a device matches with the given ID,
1539 * unless the interface reaches to the defined one. This is for delaying
1540 * the registration until the last known interface, so that the card and
1541 * devices appear at the same time.
1544 struct registration_quirk {
1545 unsigned int usb_id; /* composed via USB_ID() */
1546 unsigned int interface; /* the interface to trigger register */
1549 #define REG_QUIRK_ENTRY(vendor, product, iface) \
1550 { .usb_id = USB_ID(vendor, product), .interface = (iface) }
1552 static const struct registration_quirk registration_quirks[] = {
1553 REG_QUIRK_ENTRY(0x0951, 0x16d8, 2), /* Kingston HyperX AMP */
1554 REG_QUIRK_ENTRY(0x0951, 0x16ed, 2), /* Kingston HyperX Cloud Alpha S */
1555 REG_QUIRK_ENTRY(0x0951, 0x16ea, 2), /* Kingston HyperX Cloud Flight S */
1556 REG_QUIRK_ENTRY(0x0ecb, 0x1f46, 2), /* JBL Quantum 600 */
1557 REG_QUIRK_ENTRY(0x0ecb, 0x1f47, 2), /* JBL Quantum 800 */
1558 REG_QUIRK_ENTRY(0x0ecb, 0x1f4c, 2), /* JBL Quantum 400 */
1559 REG_QUIRK_ENTRY(0x0ecb, 0x2039, 2), /* JBL Quantum 400 */
1560 REG_QUIRK_ENTRY(0x0ecb, 0x203c, 2), /* JBL Quantum 600 */
1561 REG_QUIRK_ENTRY(0x0ecb, 0x203e, 2), /* JBL Quantum 800 */
1562 { 0 } /* terminator */
1565 /* return true if skipping registration */
1566 bool snd_usb_registration_quirk(struct snd_usb_audio *chip, int iface)
1568 const struct registration_quirk *q;
1570 for (q = registration_quirks; q->usb_id; q++)
1571 if (chip->usb_id == q->usb_id)
1572 return iface != q->interface;
1574 /* Register as normal */