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);
154 usb_audio_err(chip, "cannot memdup\n");
157 INIT_LIST_HEAD(&fp->list);
158 if (fp->nr_rates > MAX_NR_RATES) {
162 if (fp->nr_rates > 0) {
163 rate_table = kmemdup(fp->rate_table,
164 sizeof(int) * fp->nr_rates, GFP_KERNEL);
169 fp->rate_table = rate_table;
172 stream = (fp->endpoint & USB_DIR_IN)
173 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
174 err = snd_usb_add_audio_stream(chip, stream, fp);
177 if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
178 fp->altset_idx >= iface->num_altsetting) {
182 alts = &iface->altsetting[fp->altset_idx];
183 altsd = get_iface_desc(alts);
184 if (altsd->bNumEndpoints < 1) {
189 fp->protocol = altsd->bInterfaceProtocol;
191 if (fp->datainterval == 0)
192 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
193 if (fp->maxpacksize == 0)
194 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
195 usb_set_interface(chip->dev, fp->iface, 0);
196 snd_usb_init_pitch(chip, fp->iface, alts, fp);
197 snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
201 list_del(&fp->list); /* unlink for avoiding double-free */
207 static int create_auto_pcm_quirk(struct snd_usb_audio *chip,
208 struct usb_interface *iface,
209 struct usb_driver *driver)
211 struct usb_host_interface *alts;
212 struct usb_interface_descriptor *altsd;
213 struct usb_endpoint_descriptor *epd;
214 struct uac1_as_header_descriptor *ashd;
215 struct uac_format_type_i_discrete_descriptor *fmtd;
218 * Most Roland/Yamaha audio streaming interfaces have more or less
219 * standard descriptors, but older devices might lack descriptors, and
220 * future ones might change, so ensure that we fail silently if the
221 * interface doesn't look exactly right.
224 /* must have a non-zero altsetting for streaming */
225 if (iface->num_altsetting < 2)
227 alts = &iface->altsetting[1];
228 altsd = get_iface_desc(alts);
230 /* must have an isochronous endpoint for streaming */
231 if (altsd->bNumEndpoints < 1)
233 epd = get_endpoint(alts, 0);
234 if (!usb_endpoint_xfer_isoc(epd))
237 /* must have format descriptors */
238 ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
240 fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
242 if (!ashd || ashd->bLength < 7 ||
243 !fmtd || fmtd->bLength < 8)
246 return create_standard_audio_quirk(chip, iface, driver, NULL);
249 static int create_yamaha_midi_quirk(struct snd_usb_audio *chip,
250 struct usb_interface *iface,
251 struct usb_driver *driver,
252 struct usb_host_interface *alts)
254 static const struct snd_usb_audio_quirk yamaha_midi_quirk = {
255 .type = QUIRK_MIDI_YAMAHA
257 struct usb_midi_in_jack_descriptor *injd;
258 struct usb_midi_out_jack_descriptor *outjd;
260 /* must have some valid jack descriptors */
261 injd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
262 NULL, USB_MS_MIDI_IN_JACK);
263 outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
264 NULL, USB_MS_MIDI_OUT_JACK);
267 if (injd && (injd->bLength < 5 ||
268 (injd->bJackType != USB_MS_EMBEDDED &&
269 injd->bJackType != USB_MS_EXTERNAL)))
271 if (outjd && (outjd->bLength < 6 ||
272 (outjd->bJackType != USB_MS_EMBEDDED &&
273 outjd->bJackType != USB_MS_EXTERNAL)))
275 return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk);
278 static int create_roland_midi_quirk(struct snd_usb_audio *chip,
279 struct usb_interface *iface,
280 struct usb_driver *driver,
281 struct usb_host_interface *alts)
283 static const struct snd_usb_audio_quirk roland_midi_quirk = {
284 .type = QUIRK_MIDI_ROLAND
286 u8 *roland_desc = NULL;
288 /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
290 roland_desc = snd_usb_find_csint_desc(alts->extra,
295 if (roland_desc[0] < 6 || roland_desc[3] != 2)
297 return create_any_midi_quirk(chip, iface, driver,
302 static int create_std_midi_quirk(struct snd_usb_audio *chip,
303 struct usb_interface *iface,
304 struct usb_driver *driver,
305 struct usb_host_interface *alts)
307 struct usb_ms_header_descriptor *mshd;
308 struct usb_ms_endpoint_descriptor *msepd;
310 /* must have the MIDIStreaming interface header descriptor*/
311 mshd = (struct usb_ms_header_descriptor *)alts->extra;
312 if (alts->extralen < 7 ||
314 mshd->bDescriptorType != USB_DT_CS_INTERFACE ||
315 mshd->bDescriptorSubtype != USB_MS_HEADER)
317 /* must have the MIDIStreaming endpoint descriptor*/
318 msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra;
319 if (alts->endpoint[0].extralen < 4 ||
320 msepd->bLength < 4 ||
321 msepd->bDescriptorType != USB_DT_CS_ENDPOINT ||
322 msepd->bDescriptorSubtype != UAC_MS_GENERAL ||
323 msepd->bNumEmbMIDIJack < 1 ||
324 msepd->bNumEmbMIDIJack > 16)
327 return create_any_midi_quirk(chip, iface, driver, NULL);
330 static int create_auto_midi_quirk(struct snd_usb_audio *chip,
331 struct usb_interface *iface,
332 struct usb_driver *driver)
334 struct usb_host_interface *alts;
335 struct usb_interface_descriptor *altsd;
336 struct usb_endpoint_descriptor *epd;
339 alts = &iface->altsetting[0];
340 altsd = get_iface_desc(alts);
342 /* must have at least one bulk/interrupt endpoint for streaming */
343 if (altsd->bNumEndpoints < 1)
345 epd = get_endpoint(alts, 0);
346 if (!usb_endpoint_xfer_bulk(epd) &&
347 !usb_endpoint_xfer_int(epd))
350 switch (USB_ID_VENDOR(chip->usb_id)) {
351 case 0x0499: /* Yamaha */
352 err = create_yamaha_midi_quirk(chip, iface, driver, alts);
356 case 0x0582: /* Roland */
357 err = create_roland_midi_quirk(chip, iface, driver, alts);
363 return create_std_midi_quirk(chip, iface, driver, alts);
366 static int create_autodetect_quirk(struct snd_usb_audio *chip,
367 struct usb_interface *iface,
368 struct usb_driver *driver)
372 err = create_auto_pcm_quirk(chip, iface, driver);
374 err = create_auto_midi_quirk(chip, iface, driver);
378 static int create_autodetect_quirks(struct snd_usb_audio *chip,
379 struct usb_interface *iface,
380 struct usb_driver *driver,
381 const struct snd_usb_audio_quirk *quirk)
383 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
384 int ifcount, ifnum, err;
386 err = create_autodetect_quirk(chip, iface, driver);
391 * ALSA PCM playback/capture devices cannot be registered in two steps,
392 * so we have to claim the other corresponding interface here.
394 ifcount = chip->dev->actconfig->desc.bNumInterfaces;
395 for (ifnum = 0; ifnum < ifcount; ifnum++) {
396 if (ifnum == probed_ifnum || quirk->ifnum >= 0)
398 iface = usb_ifnum_to_if(chip->dev, ifnum);
400 usb_interface_claimed(iface) ||
401 get_iface_desc(iface->altsetting)->bInterfaceClass !=
402 USB_CLASS_VENDOR_SPEC)
405 err = create_autodetect_quirk(chip, iface, driver);
407 err = usb_driver_claim_interface(driver, iface,
408 USB_AUDIO_IFACE_UNUSED);
418 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
419 * The only way to detect the sample rate is by looking at wMaxPacketSize.
421 static int create_uaxx_quirk(struct snd_usb_audio *chip,
422 struct usb_interface *iface,
423 struct usb_driver *driver,
424 const struct snd_usb_audio_quirk *quirk)
426 static const struct audioformat ua_format = {
427 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
429 .fmt_type = UAC_FORMAT_TYPE_I,
432 .rates = SNDRV_PCM_RATE_CONTINUOUS,
434 struct usb_host_interface *alts;
435 struct usb_interface_descriptor *altsd;
436 struct audioformat *fp;
439 /* both PCM and MIDI interfaces have 2 or more altsettings */
440 if (iface->num_altsetting < 2)
442 alts = &iface->altsetting[1];
443 altsd = get_iface_desc(alts);
445 if (altsd->bNumEndpoints == 2) {
446 static const struct snd_usb_midi_endpoint_info ua700_ep = {
447 .out_cables = 0x0003,
450 static const struct snd_usb_audio_quirk ua700_quirk = {
451 .type = QUIRK_MIDI_FIXED_ENDPOINT,
454 static const struct snd_usb_midi_endpoint_info uaxx_ep = {
455 .out_cables = 0x0001,
458 static const struct snd_usb_audio_quirk uaxx_quirk = {
459 .type = QUIRK_MIDI_FIXED_ENDPOINT,
462 const struct snd_usb_audio_quirk *quirk =
463 chip->usb_id == USB_ID(0x0582, 0x002b)
464 ? &ua700_quirk : &uaxx_quirk;
465 return snd_usbmidi_create(chip->card, iface,
466 &chip->midi_list, quirk);
469 if (altsd->bNumEndpoints != 1)
472 fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
476 fp->iface = altsd->bInterfaceNumber;
477 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
478 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
479 fp->datainterval = 0;
480 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
481 INIT_LIST_HEAD(&fp->list);
483 switch (fp->maxpacksize) {
485 fp->rate_max = fp->rate_min = 44100;
489 fp->rate_max = fp->rate_min = 48000;
493 fp->rate_max = fp->rate_min = 96000;
496 usb_audio_err(chip, "unknown sample rate\n");
501 stream = (fp->endpoint & USB_DIR_IN)
502 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
503 err = snd_usb_add_audio_stream(chip, stream, fp);
505 list_del(&fp->list); /* unlink for avoiding double-free */
509 usb_set_interface(chip->dev, fp->iface, 0);
514 * Create a standard mixer for the specified interface.
516 static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
517 struct usb_interface *iface,
518 struct usb_driver *driver,
519 const struct snd_usb_audio_quirk *quirk)
521 if (quirk->ifnum < 0)
524 return snd_usb_create_mixer(chip, quirk->ifnum, 0);
528 * audio-interface quirks
530 * returns zero if no standard audio/MIDI parsing is needed.
531 * returns a positive value if standard audio/midi interfaces are parsed
533 * returns a negative value at error.
535 int snd_usb_create_quirk(struct snd_usb_audio *chip,
536 struct usb_interface *iface,
537 struct usb_driver *driver,
538 const struct snd_usb_audio_quirk *quirk)
540 typedef int (*quirk_func_t)(struct snd_usb_audio *,
541 struct usb_interface *,
543 const struct snd_usb_audio_quirk *);
544 static const quirk_func_t quirk_funcs[] = {
545 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
546 [QUIRK_COMPOSITE] = create_composite_quirk,
547 [QUIRK_AUTODETECT] = create_autodetect_quirks,
548 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
549 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
550 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
551 [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
552 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
553 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
554 [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
555 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
556 [QUIRK_MIDI_CME] = create_any_midi_quirk,
557 [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
558 [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
559 [QUIRK_MIDI_CH345] = create_any_midi_quirk,
560 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
561 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
562 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
563 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
564 [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
567 if (quirk->type < QUIRK_TYPE_COUNT) {
568 return quirk_funcs[quirk->type](chip, iface, driver, quirk);
570 usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
579 #define EXTIGY_FIRMWARE_SIZE_OLD 794
580 #define EXTIGY_FIRMWARE_SIZE_NEW 483
582 static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
584 struct usb_host_config *config = dev->actconfig;
587 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
588 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
589 dev_dbg(&dev->dev, "sending Extigy boot sequence...\n");
590 /* Send message to force it to reconnect with full interface. */
591 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
592 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
594 dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
595 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
596 &dev->descriptor, sizeof(dev->descriptor));
597 config = dev->actconfig;
599 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
600 err = usb_reset_configuration(dev);
602 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
603 dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
604 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
605 return -ENODEV; /* quit this anyway */
610 static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
614 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
615 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
618 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
619 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
626 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
630 if (dev->actconfig->desc.bConfigurationValue == 1) {
632 "Fast Track Pro switching to config #2\n");
633 /* This function has to be available by the usb core module.
634 * if it is not avialable the boot quirk has to be left out
635 * and the configuration has to be set by udev or hotplug
638 err = usb_driver_set_configuration(dev, 2);
641 "error usb_driver_set_configuration: %d\n",
643 /* Always return an error, so that we stop creating a device
644 that will just be destroyed and recreated with a new
648 dev_info(&dev->dev, "Fast Track Pro config OK\n");
654 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
655 * documented in the device's data sheet.
657 static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
661 buf[1] = value & 0xff;
662 buf[2] = (value >> 8) & 0xff;
664 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
665 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
669 static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
672 * Enable line-out driver mode, set headphone source to front
673 * channels, enable stereo mic.
675 return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
679 * C-Media CM6206 is based on CM106 with two additional
680 * registers that are not documented in the data sheet.
681 * Values here are chosen based on sniffing USB traffic
684 static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
687 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
689 for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
690 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
698 /* quirk for Plantronics GameCom 780 with CM6302 chip */
699 static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev)
701 /* set the initial volume and don't change; other values are either
702 * too loud or silent due to firmware bug (bko#65251)
704 u8 buf[2] = { 0x74, 0xe3 };
705 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
706 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
707 UAC_FU_VOLUME << 8, 9 << 8, buf, 2);
711 * Novation Twitch DJ controller
712 * Focusrite Novation Saffire 6 USB audio card
714 static int snd_usb_novation_boot_quirk(struct usb_device *dev)
716 /* preemptively set up the device because otherwise the
717 * raw MIDI endpoints are not active */
718 usb_set_interface(dev, 0, 1);
723 * This call will put the synth in "USB send" mode, i.e it will send MIDI
724 * messages through USB (this is disabled at startup). The synth will
725 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
726 * sign on its LCD. Values here are chosen based on sniffing USB traffic
729 static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
731 int err, actual_length;
733 /* "midi send" enable */
734 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
736 void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
739 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
740 ARRAY_SIZE(seq), &actual_length, 1000);
749 * Some sound cards from Native Instruments are in fact compliant to the USB
750 * audio standard of version 2 and other approved USB standards, even though
751 * they come up as vendor-specific device when first connected.
753 * However, they can be told to come up with a new set of descriptors
754 * upon their next enumeration, and the interfaces announced by the new
755 * descriptors will then be handled by the kernel's class drivers. As the
756 * product ID will also change, no further checks are required.
759 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
761 int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
762 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
763 1, 0, NULL, 0, 1000);
768 usb_reset_device(dev);
770 /* return -EAGAIN, so the creation of an audio interface for this
771 * temporary device is aborted. The device will reconnect with a
776 static void mbox2_setup_48_24_magic(struct usb_device *dev)
781 /* Choose 48000Hz permanently */
786 /* Send the magic! */
787 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
788 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
789 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
790 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
791 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
792 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
793 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
794 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
798 /* Digidesign Mbox 2 needs to load firmware onboard
799 * and driver must wait a few seconds for initialisation.
802 #define MBOX2_FIRMWARE_SIZE 646
803 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
804 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
806 static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
808 struct usb_host_config *config = dev->actconfig;
810 u8 bootresponse[0x12];
814 fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
816 if (fwsize != MBOX2_FIRMWARE_SIZE) {
817 dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
821 dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
824 bootresponse[0] = MBOX2_BOOT_LOADING;
825 while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
826 msleep(500); /* 0.5 second delay */
827 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
828 /* Control magic - load onboard firmware */
829 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
830 if (bootresponse[0] == MBOX2_BOOT_READY)
832 dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
836 if (bootresponse[0] != MBOX2_BOOT_READY) {
837 dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
841 dev_dbg(&dev->dev, "device initialised!\n");
843 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
844 &dev->descriptor, sizeof(dev->descriptor));
845 config = dev->actconfig;
847 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
849 err = usb_reset_configuration(dev);
851 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
852 dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
853 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
855 mbox2_setup_48_24_magic(dev);
857 dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
859 return 0; /* Successful boot */
865 #define MAUDIO_SET 0x01 /* parse device_setup */
866 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
867 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
868 #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
869 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
870 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
871 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
872 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
873 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
874 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
875 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
877 static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
878 int iface, int altno)
880 /* Reset ALL ifaces to 0 altsetting.
881 * Call it for every possible altsetting of every interface.
883 usb_set_interface(chip->dev, iface, 0);
884 if (chip->setup & MAUDIO_SET) {
885 if (chip->setup & MAUDIO_SET_COMPATIBLE) {
886 if (iface != 1 && iface != 2)
887 return 1; /* skip all interfaces but 1 and 2 */
890 if (iface == 1 || iface == 2)
891 return 1; /* skip interfaces 1 and 2 */
892 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
893 return 1; /* skip this altsetting */
894 mask = chip->setup & MAUDIO_SET_MASK;
895 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
896 return 1; /* skip this altsetting */
897 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
898 return 1; /* skip this altsetting */
899 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
900 return 1; /* skip this altsetting */
904 "using altsetting %d for interface %d config %d\n",
905 altno, iface, chip->setup);
906 return 0; /* keep this altsetting */
909 static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
913 /* Reset ALL ifaces to 0 altsetting.
914 * Call it for every possible altsetting of every interface.
916 usb_set_interface(chip->dev, iface, 0);
918 if (chip->setup & MAUDIO_SET) {
920 if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
921 return 1; /* skip this altsetting */
922 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
923 return 1; /* skip this altsetting */
924 mask = chip->setup & MAUDIO_SET_MASK;
925 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
926 return 1; /* skip this altsetting */
927 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
928 return 1; /* skip this altsetting */
929 if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
930 return 1; /* skip this altsetting */
931 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
932 return 1; /* skip this altsetting */
935 return 0; /* keep this altsetting */
938 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
939 int iface, int altno)
941 /* Reset ALL ifaces to 0 altsetting.
942 * Call it for every possible altsetting of every interface.
944 usb_set_interface(chip->dev, iface, 0);
946 /* possible configuration where both inputs and only one output is
947 *used is not supported by the current setup
949 if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
950 if (chip->setup & MAUDIO_SET_96K) {
951 if (altno != 3 && altno != 6)
953 } else if (chip->setup & MAUDIO_SET_DI) {
955 return 1; /* no analog input */
956 if (altno != 2 && altno != 5)
957 return 1; /* enable only altsets 2 and 5 */
960 return 1; /* disable digialt input */
961 if (altno != 2 && altno != 5)
962 return 1; /* enalbe only altsets 2 and 5 */
965 /* keep only 16-Bit mode */
971 "using altsetting %d for interface %d config %d\n",
972 altno, iface, chip->setup);
973 return 0; /* keep this altsetting */
976 int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
980 /* audiophile usb: skip altsets incompatible with device_setup */
981 if (chip->usb_id == USB_ID(0x0763, 0x2003))
982 return audiophile_skip_setting_quirk(chip, iface, altno);
983 /* quattro usb: skip altsets incompatible with device_setup */
984 if (chip->usb_id == USB_ID(0x0763, 0x2001))
985 return quattro_skip_setting_quirk(chip, iface, altno);
986 /* fasttrackpro usb: skip altsets incompatible with device_setup */
987 if (chip->usb_id == USB_ID(0x0763, 0x2012))
988 return fasttrackpro_skip_setting_quirk(chip, iface, altno);
993 int snd_usb_apply_boot_quirk(struct usb_device *dev,
994 struct usb_interface *intf,
995 const struct snd_usb_audio_quirk *quirk)
997 u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
998 le16_to_cpu(dev->descriptor.idProduct));
1001 case USB_ID(0x041e, 0x3000):
1002 /* SB Extigy needs special boot-up sequence */
1003 /* if more models come, this will go to the quirk list. */
1004 return snd_usb_extigy_boot_quirk(dev, intf);
1006 case USB_ID(0x041e, 0x3020):
1007 /* SB Audigy 2 NX needs its own boot-up magic, too */
1008 return snd_usb_audigy2nx_boot_quirk(dev);
1010 case USB_ID(0x10f5, 0x0200):
1011 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
1012 return snd_usb_cm106_boot_quirk(dev);
1014 case USB_ID(0x0d8c, 0x0102):
1015 /* C-Media CM6206 / CM106-Like Sound Device */
1016 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
1017 return snd_usb_cm6206_boot_quirk(dev);
1019 case USB_ID(0x0dba, 0x3000):
1020 /* Digidesign Mbox 2 */
1021 return snd_usb_mbox2_boot_quirk(dev);
1023 case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
1024 case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
1025 return snd_usb_novation_boot_quirk(dev);
1027 case USB_ID(0x133e, 0x0815):
1028 /* Access Music VirusTI Desktop */
1029 return snd_usb_accessmusic_boot_quirk(dev);
1031 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
1032 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
1033 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
1034 return snd_usb_nativeinstruments_boot_quirk(dev);
1035 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1036 return snd_usb_fasttrackpro_boot_quirk(dev);
1037 case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
1038 return snd_usb_gamecon780_boot_quirk(dev);
1045 * check if the device uses big-endian samples
1047 int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
1049 /* it depends on altsetting whether the device is big-endian or not */
1050 switch (chip->usb_id) {
1051 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
1052 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1053 fp->altsetting == 5 || fp->altsetting == 6)
1056 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1057 if (chip->setup == 0x00 ||
1058 fp->altsetting == 1 || fp->altsetting == 2 ||
1059 fp->altsetting == 3)
1062 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
1063 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1064 fp->altsetting == 5 || fp->altsetting == 6)
1072 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
1073 * not for interface.
1077 EMU_QUIRK_SR_44100HZ = 0,
1078 EMU_QUIRK_SR_48000HZ,
1079 EMU_QUIRK_SR_88200HZ,
1080 EMU_QUIRK_SR_96000HZ,
1081 EMU_QUIRK_SR_176400HZ,
1082 EMU_QUIRK_SR_192000HZ
1085 static void set_format_emu_quirk(struct snd_usb_substream *subs,
1086 struct audioformat *fmt)
1088 unsigned char emu_samplerate_id = 0;
1090 /* When capture is active
1091 * sample rate shouldn't be changed
1092 * by playback substream
1094 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
1095 if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
1099 switch (fmt->rate_min) {
1101 emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
1104 emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
1107 emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
1110 emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
1113 emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
1116 emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
1119 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
1120 subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
1123 void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
1124 struct audioformat *fmt)
1126 switch (subs->stream->chip->usb_id) {
1127 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
1128 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
1129 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
1130 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
1131 set_format_emu_quirk(subs, fmt);
1133 case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
1134 subs->stream_offset_adj = 2;
1139 bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1141 /* devices which do not support reading the sample rate. */
1142 switch (chip->usb_id) {
1143 case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
1144 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
1145 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
1146 case USB_ID(0x045E, 0x076E): /* MS Lifecam HD-5001 */
1147 case USB_ID(0x045E, 0x076F): /* MS Lifecam HD-6000 */
1148 case USB_ID(0x045E, 0x0772): /* MS Lifecam Studio */
1149 case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */
1150 case USB_ID(0x047F, 0x02F7): /* Plantronics BT-600 */
1151 case USB_ID(0x047F, 0x0415): /* Plantronics BT-300 */
1152 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */
1153 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1154 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
1155 case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
1156 case USB_ID(0x05a7, 0x1020): /* Bose Companion 5 */
1157 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1158 case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */
1159 case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */
1160 case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */
1161 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */
1162 case USB_ID(0x1de7, 0x0114): /* Phoenix Audio MT202pcs */
1163 case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */
1164 case USB_ID(0x2912, 0x30c8): /* Audioengine D1 */
1165 case USB_ID(0x413c, 0xa506): /* Dell AE515 sound bar */
1166 case USB_ID(0x046d, 0x084c): /* Logitech ConferenceCam Connect */
1172 /* Marantz/Denon USB DACs need a vendor cmd to switch
1173 * between PCM and native DSD mode
1175 static bool is_marantz_denon_dac(unsigned int id)
1178 case USB_ID(0x154e, 0x1002): /* Denon DCD-1500RE */
1179 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1180 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1181 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1187 int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
1188 struct audioformat *fmt)
1190 struct usb_device *dev = subs->dev;
1193 if (is_marantz_denon_dac(subs->stream->chip->usb_id)) {
1194 /* First switch to alt set 0, otherwise the mode switch cmd
1195 * will not be accepted by the DAC
1197 err = usb_set_interface(dev, fmt->iface, 0);
1201 mdelay(20); /* Delay needed after setting the interface */
1203 switch (fmt->altsetting) {
1204 case 2: /* DSD mode requested */
1205 case 1: /* PCM mode requested */
1206 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
1207 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
1208 fmt->altsetting - 1, 1, NULL, 0);
1218 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
1221 * "Playback Design" products send bogus feedback data at the start
1222 * of the stream. Ignore them.
1224 if ((le16_to_cpu(ep->chip->dev->descriptor.idVendor) == 0x23ba) &&
1225 ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
1226 ep->skip_packets = 4;
1229 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
1230 * world latency varies by approx. +/- 50 frames (at 96KHz) each time
1231 * the stream is (re)started. When skipping packets 16 at endpoint
1232 * start up, the real world latency is stable within +/- 1 frame (also
1233 * across power cycles).
1235 if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
1236 ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
1237 ep->type == SND_USB_ENDPOINT_TYPE_DATA)
1238 ep->skip_packets = 16;
1241 void snd_usb_set_interface_quirk(struct usb_device *dev)
1244 * "Playback Design" products need a 50ms delay after setting the
1247 switch (le16_to_cpu(dev->descriptor.idVendor)) {
1248 case 0x23ba: /* Playback Design */
1249 case 0x0644: /* TEAC Corp. */
1255 void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1256 __u8 request, __u8 requesttype, __u16 value,
1257 __u16 index, void *data, __u16 size)
1260 * "Playback Design" products need a 20ms delay after each
1261 * class compliant request
1263 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) &&
1264 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1268 * "TEAC Corp." products need a 20ms delay after each
1269 * class compliant request
1271 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x0644) &&
1272 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1275 /* Marantz/Denon devices with USB DAC functionality need a delay
1276 * after each class compliant request
1278 if (is_marantz_denon_dac(USB_ID(le16_to_cpu(dev->descriptor.idVendor),
1279 le16_to_cpu(dev->descriptor.idProduct)))
1280 && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1283 /* Zoom R16/24 needs a tiny delay here, otherwise requests like
1284 * get/set frequency return as failed despite actually succeeding.
1286 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1686) &&
1287 (le16_to_cpu(dev->descriptor.idProduct) == 0x00dd) &&
1288 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1293 * snd_usb_interface_dsd_format_quirks() is called from format.c to
1294 * augment the PCM format bit-field for DSD types. The UAC standards
1295 * don't have a designated bit field to denote DSD-capable interfaces,
1296 * hence all hardware that is known to support this format has to be
1299 u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1300 struct audioformat *fp,
1301 unsigned int sample_bytes)
1303 /* Playback Designs */
1304 if (le16_to_cpu(chip->dev->descriptor.idVendor) == 0x23ba) {
1305 switch (fp->altsetting) {
1308 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
1310 fp->dsd_bitrev = true;
1311 return SNDRV_PCM_FMTBIT_DSD_U8;
1313 fp->dsd_bitrev = true;
1314 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
1318 /* XMOS based USB DACs */
1319 switch (chip->usb_id) {
1320 case USB_ID(0x20b1, 0x3008): /* iFi Audio micro/nano iDSD */
1321 case USB_ID(0x20b1, 0x2008): /* Matrix Audio X-Sabre */
1322 case USB_ID(0x20b1, 0x300a): /* Matrix Audio Mini-i Pro */
1323 case USB_ID(0x22d9, 0x0416): /* OPPO HA-1 */
1324 case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
1325 if (fp->altsetting == 2)
1326 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1329 case USB_ID(0x20b1, 0x000a): /* Gustard DAC-X20U */
1330 case USB_ID(0x20b1, 0x2009): /* DIYINHK DSD DXD 384kHz USB to I2S/DSD */
1331 case USB_ID(0x20b1, 0x2023): /* JLsounds I2SoverUSB */
1332 case USB_ID(0x20b1, 0x3023): /* Aune X1S 32BIT/384 DSD DAC */
1333 case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
1334 if (fp->altsetting == 3)
1335 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1341 /* Denon/Marantz devices with USB DAC functionality */
1342 if (is_marantz_denon_dac(chip->usb_id)) {
1343 if (fp->altsetting == 2)
1344 return SNDRV_PCM_FMTBIT_DSD_U32_BE;