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 usb_driver_claim_interface(driver, iface, (void *)-1L);
76 static int ignore_interface_quirk(struct snd_usb_audio *chip,
77 struct usb_interface *iface,
78 struct usb_driver *driver,
79 const struct snd_usb_audio_quirk *quirk)
86 * Allow alignment on audio sub-slot (channel samples) rather than
87 * on audio slots (audio frames)
89 static int create_align_transfer_quirk(struct snd_usb_audio *chip,
90 struct usb_interface *iface,
91 struct usb_driver *driver,
92 const struct snd_usb_audio_quirk *quirk)
95 return 1; /* Continue with creating streams and mixer */
98 static int create_any_midi_quirk(struct snd_usb_audio *chip,
99 struct usb_interface *intf,
100 struct usb_driver *driver,
101 const struct snd_usb_audio_quirk *quirk)
103 return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
107 * create a stream for an interface with proper descriptors
109 static int create_standard_audio_quirk(struct snd_usb_audio *chip,
110 struct usb_interface *iface,
111 struct usb_driver *driver,
112 const struct snd_usb_audio_quirk *quirk)
114 struct usb_host_interface *alts;
115 struct usb_interface_descriptor *altsd;
118 alts = &iface->altsetting[0];
119 altsd = get_iface_desc(alts);
120 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
122 usb_audio_err(chip, "cannot setup if %d: error %d\n",
123 altsd->bInterfaceNumber, err);
126 /* reset the current interface */
127 usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
132 * create a stream for an endpoint/altsetting without proper descriptors
134 static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
135 struct usb_interface *iface,
136 struct usb_driver *driver,
137 const struct snd_usb_audio_quirk *quirk)
139 struct audioformat *fp;
140 struct usb_host_interface *alts;
141 struct usb_interface_descriptor *altsd;
143 unsigned *rate_table = NULL;
145 fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
147 usb_audio_err(chip, "cannot memdup\n");
150 if (fp->nr_rates > MAX_NR_RATES) {
154 if (fp->nr_rates > 0) {
155 rate_table = kmemdup(fp->rate_table,
156 sizeof(int) * fp->nr_rates, GFP_KERNEL);
161 fp->rate_table = rate_table;
164 stream = (fp->endpoint & USB_DIR_IN)
165 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
166 err = snd_usb_add_audio_stream(chip, stream, fp);
172 if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
173 fp->altset_idx >= iface->num_altsetting) {
178 alts = &iface->altsetting[fp->altset_idx];
179 altsd = get_iface_desc(alts);
180 fp->protocol = altsd->bInterfaceProtocol;
182 if (fp->datainterval == 0)
183 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
184 if (fp->maxpacksize == 0)
185 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
186 usb_set_interface(chip->dev, fp->iface, 0);
187 snd_usb_init_pitch(chip, fp->iface, alts, fp);
188 snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
192 static int create_auto_pcm_quirk(struct snd_usb_audio *chip,
193 struct usb_interface *iface,
194 struct usb_driver *driver)
196 struct usb_host_interface *alts;
197 struct usb_interface_descriptor *altsd;
198 struct usb_endpoint_descriptor *epd;
199 struct uac1_as_header_descriptor *ashd;
200 struct uac_format_type_i_discrete_descriptor *fmtd;
203 * Most Roland/Yamaha audio streaming interfaces have more or less
204 * standard descriptors, but older devices might lack descriptors, and
205 * future ones might change, so ensure that we fail silently if the
206 * interface doesn't look exactly right.
209 /* must have a non-zero altsetting for streaming */
210 if (iface->num_altsetting < 2)
212 alts = &iface->altsetting[1];
213 altsd = get_iface_desc(alts);
215 /* must have an isochronous endpoint for streaming */
216 if (altsd->bNumEndpoints < 1)
218 epd = get_endpoint(alts, 0);
219 if (!usb_endpoint_xfer_isoc(epd))
222 /* must have format descriptors */
223 ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
225 fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
227 if (!ashd || ashd->bLength < 7 ||
228 !fmtd || fmtd->bLength < 8)
231 return create_standard_audio_quirk(chip, iface, driver, NULL);
234 static int create_yamaha_midi_quirk(struct snd_usb_audio *chip,
235 struct usb_interface *iface,
236 struct usb_driver *driver,
237 struct usb_host_interface *alts)
239 static const struct snd_usb_audio_quirk yamaha_midi_quirk = {
240 .type = QUIRK_MIDI_YAMAHA
242 struct usb_midi_in_jack_descriptor *injd;
243 struct usb_midi_out_jack_descriptor *outjd;
245 /* must have some valid jack descriptors */
246 injd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
247 NULL, USB_MS_MIDI_IN_JACK);
248 outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
249 NULL, USB_MS_MIDI_OUT_JACK);
252 if (injd && (injd->bLength < 5 ||
253 (injd->bJackType != USB_MS_EMBEDDED &&
254 injd->bJackType != USB_MS_EXTERNAL)))
256 if (outjd && (outjd->bLength < 6 ||
257 (outjd->bJackType != USB_MS_EMBEDDED &&
258 outjd->bJackType != USB_MS_EXTERNAL)))
260 return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk);
263 static int create_roland_midi_quirk(struct snd_usb_audio *chip,
264 struct usb_interface *iface,
265 struct usb_driver *driver,
266 struct usb_host_interface *alts)
268 static const struct snd_usb_audio_quirk roland_midi_quirk = {
269 .type = QUIRK_MIDI_ROLAND
271 u8 *roland_desc = NULL;
273 /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
275 roland_desc = snd_usb_find_csint_desc(alts->extra,
280 if (roland_desc[0] < 6 || roland_desc[3] != 2)
282 return create_any_midi_quirk(chip, iface, driver,
287 static int create_std_midi_quirk(struct snd_usb_audio *chip,
288 struct usb_interface *iface,
289 struct usb_driver *driver,
290 struct usb_host_interface *alts)
292 struct usb_ms_header_descriptor *mshd;
293 struct usb_ms_endpoint_descriptor *msepd;
295 /* must have the MIDIStreaming interface header descriptor*/
296 mshd = (struct usb_ms_header_descriptor *)alts->extra;
297 if (alts->extralen < 7 ||
299 mshd->bDescriptorType != USB_DT_CS_INTERFACE ||
300 mshd->bDescriptorSubtype != USB_MS_HEADER)
302 /* must have the MIDIStreaming endpoint descriptor*/
303 msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra;
304 if (alts->endpoint[0].extralen < 4 ||
305 msepd->bLength < 4 ||
306 msepd->bDescriptorType != USB_DT_CS_ENDPOINT ||
307 msepd->bDescriptorSubtype != UAC_MS_GENERAL ||
308 msepd->bNumEmbMIDIJack < 1 ||
309 msepd->bNumEmbMIDIJack > 16)
312 return create_any_midi_quirk(chip, iface, driver, NULL);
315 static int create_auto_midi_quirk(struct snd_usb_audio *chip,
316 struct usb_interface *iface,
317 struct usb_driver *driver)
319 struct usb_host_interface *alts;
320 struct usb_interface_descriptor *altsd;
321 struct usb_endpoint_descriptor *epd;
324 alts = &iface->altsetting[0];
325 altsd = get_iface_desc(alts);
327 /* must have at least one bulk/interrupt endpoint for streaming */
328 if (altsd->bNumEndpoints < 1)
330 epd = get_endpoint(alts, 0);
331 if (!usb_endpoint_xfer_bulk(epd) &&
332 !usb_endpoint_xfer_int(epd))
335 switch (USB_ID_VENDOR(chip->usb_id)) {
336 case 0x0499: /* Yamaha */
337 err = create_yamaha_midi_quirk(chip, iface, driver, alts);
341 case 0x0582: /* Roland */
342 err = create_roland_midi_quirk(chip, iface, driver, alts);
348 return create_std_midi_quirk(chip, iface, driver, alts);
351 static int create_autodetect_quirk(struct snd_usb_audio *chip,
352 struct usb_interface *iface,
353 struct usb_driver *driver)
357 err = create_auto_pcm_quirk(chip, iface, driver);
359 err = create_auto_midi_quirk(chip, iface, driver);
363 static int create_autodetect_quirks(struct snd_usb_audio *chip,
364 struct usb_interface *iface,
365 struct usb_driver *driver,
366 const struct snd_usb_audio_quirk *quirk)
368 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
369 int ifcount, ifnum, err;
371 err = create_autodetect_quirk(chip, iface, driver);
376 * ALSA PCM playback/capture devices cannot be registered in two steps,
377 * so we have to claim the other corresponding interface here.
379 ifcount = chip->dev->actconfig->desc.bNumInterfaces;
380 for (ifnum = 0; ifnum < ifcount; ifnum++) {
381 if (ifnum == probed_ifnum || quirk->ifnum >= 0)
383 iface = usb_ifnum_to_if(chip->dev, ifnum);
385 usb_interface_claimed(iface) ||
386 get_iface_desc(iface->altsetting)->bInterfaceClass !=
387 USB_CLASS_VENDOR_SPEC)
390 err = create_autodetect_quirk(chip, iface, driver);
392 usb_driver_claim_interface(driver, iface, (void *)-1L);
399 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
400 * The only way to detect the sample rate is by looking at wMaxPacketSize.
402 static int create_uaxx_quirk(struct snd_usb_audio *chip,
403 struct usb_interface *iface,
404 struct usb_driver *driver,
405 const struct snd_usb_audio_quirk *quirk)
407 static const struct audioformat ua_format = {
408 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
410 .fmt_type = UAC_FORMAT_TYPE_I,
413 .rates = SNDRV_PCM_RATE_CONTINUOUS,
415 struct usb_host_interface *alts;
416 struct usb_interface_descriptor *altsd;
417 struct audioformat *fp;
420 /* both PCM and MIDI interfaces have 2 or more altsettings */
421 if (iface->num_altsetting < 2)
423 alts = &iface->altsetting[1];
424 altsd = get_iface_desc(alts);
426 if (altsd->bNumEndpoints == 2) {
427 static const struct snd_usb_midi_endpoint_info ua700_ep = {
428 .out_cables = 0x0003,
431 static const struct snd_usb_audio_quirk ua700_quirk = {
432 .type = QUIRK_MIDI_FIXED_ENDPOINT,
435 static const struct snd_usb_midi_endpoint_info uaxx_ep = {
436 .out_cables = 0x0001,
439 static const struct snd_usb_audio_quirk uaxx_quirk = {
440 .type = QUIRK_MIDI_FIXED_ENDPOINT,
443 const struct snd_usb_audio_quirk *quirk =
444 chip->usb_id == USB_ID(0x0582, 0x002b)
445 ? &ua700_quirk : &uaxx_quirk;
446 return snd_usbmidi_create(chip->card, iface,
447 &chip->midi_list, quirk);
450 if (altsd->bNumEndpoints != 1)
453 fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
457 fp->iface = altsd->bInterfaceNumber;
458 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
459 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
460 fp->datainterval = 0;
461 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
463 switch (fp->maxpacksize) {
465 fp->rate_max = fp->rate_min = 44100;
469 fp->rate_max = fp->rate_min = 48000;
473 fp->rate_max = fp->rate_min = 96000;
476 usb_audio_err(chip, "unknown sample rate\n");
481 stream = (fp->endpoint & USB_DIR_IN)
482 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
483 err = snd_usb_add_audio_stream(chip, stream, fp);
488 usb_set_interface(chip->dev, fp->iface, 0);
493 * Create a standard mixer for the specified interface.
495 static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
496 struct usb_interface *iface,
497 struct usb_driver *driver,
498 const struct snd_usb_audio_quirk *quirk)
500 if (quirk->ifnum < 0)
503 return snd_usb_create_mixer(chip, quirk->ifnum, 0);
507 * audio-interface quirks
509 * returns zero if no standard audio/MIDI parsing is needed.
510 * returns a positive value if standard audio/midi interfaces are parsed
512 * returns a negative value at error.
514 int snd_usb_create_quirk(struct snd_usb_audio *chip,
515 struct usb_interface *iface,
516 struct usb_driver *driver,
517 const struct snd_usb_audio_quirk *quirk)
519 typedef int (*quirk_func_t)(struct snd_usb_audio *,
520 struct usb_interface *,
522 const struct snd_usb_audio_quirk *);
523 static const quirk_func_t quirk_funcs[] = {
524 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
525 [QUIRK_COMPOSITE] = create_composite_quirk,
526 [QUIRK_AUTODETECT] = create_autodetect_quirks,
527 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
528 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
529 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
530 [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
531 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
532 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
533 [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
534 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
535 [QUIRK_MIDI_CME] = create_any_midi_quirk,
536 [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
537 [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
538 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
539 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
540 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
541 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
542 [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
545 if (quirk->type < QUIRK_TYPE_COUNT) {
546 return quirk_funcs[quirk->type](chip, iface, driver, quirk);
548 usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
557 #define EXTIGY_FIRMWARE_SIZE_OLD 794
558 #define EXTIGY_FIRMWARE_SIZE_NEW 483
560 static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
562 struct usb_host_config *config = dev->actconfig;
565 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
566 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
567 dev_dbg(&dev->dev, "sending Extigy boot sequence...\n");
568 /* Send message to force it to reconnect with full interface. */
569 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
570 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
572 dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
573 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
574 &dev->descriptor, sizeof(dev->descriptor));
575 config = dev->actconfig;
577 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
578 err = usb_reset_configuration(dev);
580 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
581 dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
582 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
583 return -ENODEV; /* quit this anyway */
588 static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
592 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
593 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
596 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
597 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
604 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
608 if (dev->actconfig->desc.bConfigurationValue == 1) {
610 "Fast Track Pro switching to config #2\n");
611 /* This function has to be available by the usb core module.
612 * if it is not avialable the boot quirk has to be left out
613 * and the configuration has to be set by udev or hotplug
616 err = usb_driver_set_configuration(dev, 2);
619 "error usb_driver_set_configuration: %d\n",
621 /* Always return an error, so that we stop creating a device
622 that will just be destroyed and recreated with a new
626 dev_info(&dev->dev, "Fast Track Pro config OK\n");
632 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
633 * documented in the device's data sheet.
635 static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
639 buf[1] = value & 0xff;
640 buf[2] = (value >> 8) & 0xff;
642 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
643 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
647 static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
650 * Enable line-out driver mode, set headphone source to front
651 * channels, enable stereo mic.
653 return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
657 * C-Media CM6206 is based on CM106 with two additional
658 * registers that are not documented in the data sheet.
659 * Values here are chosen based on sniffing USB traffic
662 static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
665 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
667 for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
668 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
676 /* quirk for Plantronics GameCom 780 with CM6302 chip */
677 static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev)
679 /* set the initial volume and don't change; other values are either
680 * too loud or silent due to firmware bug (bko#65251)
682 u8 buf[2] = { 0x74, 0xe3 };
683 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
684 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
685 UAC_FU_VOLUME << 8, 9 << 8, buf, 2);
689 * Novation Twitch DJ controller
690 * Focusrite Novation Saffire 6 USB audio card
692 static int snd_usb_novation_boot_quirk(struct usb_device *dev)
694 /* preemptively set up the device because otherwise the
695 * raw MIDI endpoints are not active */
696 usb_set_interface(dev, 0, 1);
701 * This call will put the synth in "USB send" mode, i.e it will send MIDI
702 * messages through USB (this is disabled at startup). The synth will
703 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
704 * sign on its LCD. Values here are chosen based on sniffing USB traffic
707 static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
709 int err, actual_length;
711 /* "midi send" enable */
712 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
714 void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
717 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
718 ARRAY_SIZE(seq), &actual_length, 1000);
727 * Some sound cards from Native Instruments are in fact compliant to the USB
728 * audio standard of version 2 and other approved USB standards, even though
729 * they come up as vendor-specific device when first connected.
731 * However, they can be told to come up with a new set of descriptors
732 * upon their next enumeration, and the interfaces announced by the new
733 * descriptors will then be handled by the kernel's class drivers. As the
734 * product ID will also change, no further checks are required.
737 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
739 int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
740 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
741 1, 0, NULL, 0, 1000);
746 usb_reset_device(dev);
748 /* return -EAGAIN, so the creation of an audio interface for this
749 * temporary device is aborted. The device will reconnect with a
754 static void mbox2_setup_48_24_magic(struct usb_device *dev)
759 /* Choose 48000Hz permanently */
764 /* Send the magic! */
765 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
766 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
767 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
768 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
769 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
770 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
771 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
772 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
776 /* Digidesign Mbox 2 needs to load firmware onboard
777 * and driver must wait a few seconds for initialisation.
780 #define MBOX2_FIRMWARE_SIZE 646
781 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
782 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
784 static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
786 struct usb_host_config *config = dev->actconfig;
788 u8 bootresponse[0x12];
792 fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
794 if (fwsize != MBOX2_FIRMWARE_SIZE) {
795 dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
799 dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
802 bootresponse[0] = MBOX2_BOOT_LOADING;
803 while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
804 msleep(500); /* 0.5 second delay */
805 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
806 /* Control magic - load onboard firmware */
807 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
808 if (bootresponse[0] == MBOX2_BOOT_READY)
810 dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
814 if (bootresponse[0] != MBOX2_BOOT_READY) {
815 dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
819 dev_dbg(&dev->dev, "device initialised!\n");
821 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
822 &dev->descriptor, sizeof(dev->descriptor));
823 config = dev->actconfig;
825 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
827 err = usb_reset_configuration(dev);
829 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
830 dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
831 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
833 mbox2_setup_48_24_magic(dev);
835 dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
837 return 0; /* Successful boot */
843 #define MAUDIO_SET 0x01 /* parse device_setup */
844 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
845 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
846 #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
847 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
848 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
849 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
850 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
851 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
852 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
853 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
855 static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
856 int iface, int altno)
858 /* Reset ALL ifaces to 0 altsetting.
859 * Call it for every possible altsetting of every interface.
861 usb_set_interface(chip->dev, iface, 0);
862 if (chip->setup & MAUDIO_SET) {
863 if (chip->setup & MAUDIO_SET_COMPATIBLE) {
864 if (iface != 1 && iface != 2)
865 return 1; /* skip all interfaces but 1 and 2 */
868 if (iface == 1 || iface == 2)
869 return 1; /* skip interfaces 1 and 2 */
870 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
871 return 1; /* skip this altsetting */
872 mask = chip->setup & MAUDIO_SET_MASK;
873 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
874 return 1; /* skip this altsetting */
875 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
876 return 1; /* skip this altsetting */
877 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
878 return 1; /* skip this altsetting */
882 "using altsetting %d for interface %d config %d\n",
883 altno, iface, chip->setup);
884 return 0; /* keep this altsetting */
887 static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
891 /* Reset ALL ifaces to 0 altsetting.
892 * Call it for every possible altsetting of every interface.
894 usb_set_interface(chip->dev, iface, 0);
896 if (chip->setup & MAUDIO_SET) {
898 if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
899 return 1; /* skip this altsetting */
900 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
901 return 1; /* skip this altsetting */
902 mask = chip->setup & MAUDIO_SET_MASK;
903 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
904 return 1; /* skip this altsetting */
905 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
906 return 1; /* skip this altsetting */
907 if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
908 return 1; /* skip this altsetting */
909 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
910 return 1; /* skip this altsetting */
913 return 0; /* keep this altsetting */
916 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
917 int iface, int altno)
919 /* Reset ALL ifaces to 0 altsetting.
920 * Call it for every possible altsetting of every interface.
922 usb_set_interface(chip->dev, iface, 0);
924 /* possible configuration where both inputs and only one output is
925 *used is not supported by the current setup
927 if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
928 if (chip->setup & MAUDIO_SET_96K) {
929 if (altno != 3 && altno != 6)
931 } else if (chip->setup & MAUDIO_SET_DI) {
933 return 1; /* no analog input */
934 if (altno != 2 && altno != 5)
935 return 1; /* enable only altsets 2 and 5 */
938 return 1; /* disable digialt input */
939 if (altno != 2 && altno != 5)
940 return 1; /* enalbe only altsets 2 and 5 */
943 /* keep only 16-Bit mode */
949 "using altsetting %d for interface %d config %d\n",
950 altno, iface, chip->setup);
951 return 0; /* keep this altsetting */
954 int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
958 /* audiophile usb: skip altsets incompatible with device_setup */
959 if (chip->usb_id == USB_ID(0x0763, 0x2003))
960 return audiophile_skip_setting_quirk(chip, iface, altno);
961 /* quattro usb: skip altsets incompatible with device_setup */
962 if (chip->usb_id == USB_ID(0x0763, 0x2001))
963 return quattro_skip_setting_quirk(chip, iface, altno);
964 /* fasttrackpro usb: skip altsets incompatible with device_setup */
965 if (chip->usb_id == USB_ID(0x0763, 0x2012))
966 return fasttrackpro_skip_setting_quirk(chip, iface, altno);
971 int snd_usb_apply_boot_quirk(struct usb_device *dev,
972 struct usb_interface *intf,
973 const struct snd_usb_audio_quirk *quirk)
975 u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
976 le16_to_cpu(dev->descriptor.idProduct));
979 case USB_ID(0x041e, 0x3000):
980 /* SB Extigy needs special boot-up sequence */
981 /* if more models come, this will go to the quirk list. */
982 return snd_usb_extigy_boot_quirk(dev, intf);
984 case USB_ID(0x041e, 0x3020):
985 /* SB Audigy 2 NX needs its own boot-up magic, too */
986 return snd_usb_audigy2nx_boot_quirk(dev);
988 case USB_ID(0x10f5, 0x0200):
989 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
990 return snd_usb_cm106_boot_quirk(dev);
992 case USB_ID(0x0d8c, 0x0102):
993 /* C-Media CM6206 / CM106-Like Sound Device */
994 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
995 return snd_usb_cm6206_boot_quirk(dev);
997 case USB_ID(0x0dba, 0x3000):
998 /* Digidesign Mbox 2 */
999 return snd_usb_mbox2_boot_quirk(dev);
1001 case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
1002 case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
1003 return snd_usb_novation_boot_quirk(dev);
1005 case USB_ID(0x133e, 0x0815):
1006 /* Access Music VirusTI Desktop */
1007 return snd_usb_accessmusic_boot_quirk(dev);
1009 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
1010 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
1011 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
1012 return snd_usb_nativeinstruments_boot_quirk(dev);
1013 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1014 return snd_usb_fasttrackpro_boot_quirk(dev);
1015 case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
1016 return snd_usb_gamecon780_boot_quirk(dev);
1023 * check if the device uses big-endian samples
1025 int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
1027 /* it depends on altsetting whether the device is big-endian or not */
1028 switch (chip->usb_id) {
1029 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
1030 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1031 fp->altsetting == 5 || fp->altsetting == 6)
1034 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1035 if (chip->setup == 0x00 ||
1036 fp->altsetting == 1 || fp->altsetting == 2 ||
1037 fp->altsetting == 3)
1040 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
1041 if (fp->altsetting == 2 || fp->altsetting == 3 ||
1042 fp->altsetting == 5 || fp->altsetting == 6)
1050 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
1051 * not for interface.
1055 EMU_QUIRK_SR_44100HZ = 0,
1056 EMU_QUIRK_SR_48000HZ,
1057 EMU_QUIRK_SR_88200HZ,
1058 EMU_QUIRK_SR_96000HZ,
1059 EMU_QUIRK_SR_176400HZ,
1060 EMU_QUIRK_SR_192000HZ
1063 static void set_format_emu_quirk(struct snd_usb_substream *subs,
1064 struct audioformat *fmt)
1066 unsigned char emu_samplerate_id = 0;
1068 /* When capture is active
1069 * sample rate shouldn't be changed
1070 * by playback substream
1072 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
1073 if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
1077 switch (fmt->rate_min) {
1079 emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
1082 emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
1085 emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
1088 emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
1091 emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
1094 emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
1097 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
1098 subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
1101 void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
1102 struct audioformat *fmt)
1104 switch (subs->stream->chip->usb_id) {
1105 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
1106 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
1107 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
1108 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
1109 set_format_emu_quirk(subs, fmt);
1115 /* Marantz/Denon USB DACs need a vendor cmd to switch
1116 * between PCM and native DSD mode
1118 int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
1119 struct audioformat *fmt)
1121 struct usb_device *dev = subs->dev;
1124 switch (subs->stream->chip->usb_id) {
1125 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1126 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1128 /* First switch to alt set 0, otherwise the mode switch cmd
1129 * will not be accepted by the DAC
1131 err = usb_set_interface(dev, fmt->iface, 0);
1135 mdelay(20); /* Delay needed after setting the interface */
1137 switch (fmt->altsetting) {
1138 case 2: /* DSD mode requested */
1139 case 1: /* PCM mode requested */
1140 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
1141 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
1142 fmt->altsetting - 1, 1, NULL, 0);
1152 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
1155 * "Playback Design" products send bogus feedback data at the start
1156 * of the stream. Ignore them.
1158 if ((le16_to_cpu(ep->chip->dev->descriptor.idVendor) == 0x23ba) &&
1159 ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
1160 ep->skip_packets = 4;
1163 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
1164 * world latency varies by approx. +/- 50 frames (at 96KHz) each time
1165 * the stream is (re)started. When skipping packets 16 at endpoint
1166 * start up, the real world latency is stable within +/- 1 frame (also
1167 * across power cycles).
1169 if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
1170 ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
1171 ep->type == SND_USB_ENDPOINT_TYPE_DATA)
1172 ep->skip_packets = 16;
1175 void snd_usb_set_interface_quirk(struct usb_device *dev)
1178 * "Playback Design" products need a 50ms delay after setting the
1181 if (le16_to_cpu(dev->descriptor.idVendor) == 0x23ba)
1185 void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1186 __u8 request, __u8 requesttype, __u16 value,
1187 __u16 index, void *data, __u16 size)
1190 * "Playback Design" products need a 20ms delay after each
1191 * class compliant request
1193 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) &&
1194 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1197 /* Marantz/Denon devices with USB DAC functionality need a delay
1198 * after each class compliant request
1200 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x154e) &&
1201 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) {
1203 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1204 case 0x3005: /* Marantz HD-DAC1 */
1205 case 0x3006: /* Marantz SA-14S1 */
1211 /* Zoom R16/24 needs a tiny delay here, otherwise requests like
1212 * get/set frequency return as failed despite actually succeeding.
1214 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1686) &&
1215 (le16_to_cpu(dev->descriptor.idProduct) == 0x00dd) &&
1216 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1221 * snd_usb_interface_dsd_format_quirks() is called from format.c to
1222 * augment the PCM format bit-field for DSD types. The UAC standards
1223 * don't have a designated bit field to denote DSD-capable interfaces,
1224 * hence all hardware that is known to support this format has to be
1227 u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1228 struct audioformat *fp,
1229 unsigned int sample_bytes)
1231 /* Playback Designs */
1232 if (le16_to_cpu(chip->dev->descriptor.idVendor) == 0x23ba) {
1233 switch (fp->altsetting) {
1236 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
1238 fp->dsd_bitrev = true;
1239 return SNDRV_PCM_FMTBIT_DSD_U8;
1241 fp->dsd_bitrev = true;
1242 return SNDRV_PCM_FMTBIT_DSD_U16_LE;
1246 /* XMOS based USB DACs */
1247 switch (chip->usb_id) {
1248 case USB_ID(0x20b1, 0x3008): /* iFi Audio micro/nano iDSD */
1249 case USB_ID(0x20b1, 0x2008): /* Matrix Audio X-Sabre */
1250 case USB_ID(0x20b1, 0x300a): /* Matrix Audio Mini-i Pro */
1251 if (fp->altsetting == 2)
1252 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1254 /* DIYINHK DSD DXD 384kHz USB to I2S/DSD */
1255 case USB_ID(0x20b1, 0x2009):
1256 if (fp->altsetting == 3)
1257 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1263 /* Denon/Marantz devices with USB DAC functionality */
1264 switch (chip->usb_id) {
1265 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1266 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1267 if (fp->altsetting == 2)
1268 return SNDRV_PCM_FMTBIT_DSD_U32_BE;