1 // SPDX-License-Identifier: GPL-2.0-or-later
5 #include <linux/init.h>
6 #include <linux/slab.h>
8 #include <linux/usb/audio.h>
9 #include <linux/usb/midi.h>
10 #include <linux/bits.h>
12 #include <sound/control.h>
13 #include <sound/core.h>
14 #include <sound/info.h>
15 #include <sound/pcm.h>
20 #include "mixer_quirks.h"
30 * handle the quirks for the contained interfaces
32 static int create_composite_quirk(struct snd_usb_audio
*chip
,
33 struct usb_interface
*iface
,
34 struct usb_driver
*driver
,
35 const struct snd_usb_audio_quirk
*quirk_comp
)
37 int probed_ifnum
= get_iface_desc(iface
->altsetting
)->bInterfaceNumber
;
38 const struct snd_usb_audio_quirk
*quirk
;
41 for (quirk
= quirk_comp
->data
; quirk
->ifnum
>= 0; ++quirk
) {
42 iface
= usb_ifnum_to_if(chip
->dev
, quirk
->ifnum
);
45 if (quirk
->ifnum
!= probed_ifnum
&&
46 usb_interface_claimed(iface
))
48 err
= snd_usb_create_quirk(chip
, iface
, driver
, quirk
);
53 for (quirk
= quirk_comp
->data
; quirk
->ifnum
>= 0; ++quirk
) {
54 iface
= usb_ifnum_to_if(chip
->dev
, quirk
->ifnum
);
57 if (quirk
->ifnum
!= probed_ifnum
&&
58 !usb_interface_claimed(iface
))
59 usb_driver_claim_interface(driver
, iface
, (void *)-1L);
65 static int ignore_interface_quirk(struct snd_usb_audio
*chip
,
66 struct usb_interface
*iface
,
67 struct usb_driver
*driver
,
68 const struct snd_usb_audio_quirk
*quirk
)
75 * Allow alignment on audio sub-slot (channel samples) rather than
76 * on audio slots (audio frames)
78 static int create_align_transfer_quirk(struct snd_usb_audio
*chip
,
79 struct usb_interface
*iface
,
80 struct usb_driver
*driver
,
81 const struct snd_usb_audio_quirk
*quirk
)
84 return 1; /* Continue with creating streams and mixer */
87 static int create_any_midi_quirk(struct snd_usb_audio
*chip
,
88 struct usb_interface
*intf
,
89 struct usb_driver
*driver
,
90 const struct snd_usb_audio_quirk
*quirk
)
92 return snd_usbmidi_create(chip
->card
, intf
, &chip
->midi_list
, quirk
);
96 * create a stream for an interface with proper descriptors
98 static int create_standard_audio_quirk(struct snd_usb_audio
*chip
,
99 struct usb_interface
*iface
,
100 struct usb_driver
*driver
,
101 const struct snd_usb_audio_quirk
*quirk
)
103 struct usb_host_interface
*alts
;
104 struct usb_interface_descriptor
*altsd
;
107 if (chip
->usb_id
== USB_ID(0x1686, 0x00dd)) /* Zoom R16/24 */
108 chip
->tx_length_quirk
= 1;
110 alts
= &iface
->altsetting
[0];
111 altsd
= get_iface_desc(alts
);
112 err
= snd_usb_parse_audio_interface(chip
, altsd
->bInterfaceNumber
);
114 usb_audio_err(chip
, "cannot setup if %d: error %d\n",
115 altsd
->bInterfaceNumber
, err
);
118 /* reset the current interface */
119 usb_set_interface(chip
->dev
, altsd
->bInterfaceNumber
, 0);
123 /* create the audio stream and the corresponding endpoints from the fixed
124 * audioformat object; this is used for quirks with the fixed EPs
126 static int add_audio_stream_from_fixed_fmt(struct snd_usb_audio
*chip
,
127 struct audioformat
*fp
)
131 stream
= (fp
->endpoint
& USB_DIR_IN
) ?
132 SNDRV_PCM_STREAM_CAPTURE
: SNDRV_PCM_STREAM_PLAYBACK
;
134 snd_usb_audioformat_set_sync_ep(chip
, fp
);
136 err
= snd_usb_add_audio_stream(chip
, stream
, fp
);
140 err
= snd_usb_add_endpoint(chip
, fp
->endpoint
,
141 SND_USB_ENDPOINT_TYPE_DATA
);
146 err
= snd_usb_add_endpoint(chip
, fp
->sync_ep
,
148 SND_USB_ENDPOINT_TYPE_DATA
:
149 SND_USB_ENDPOINT_TYPE_SYNC
);
158 * create a stream for an endpoint/altsetting without proper descriptors
160 static int create_fixed_stream_quirk(struct snd_usb_audio
*chip
,
161 struct usb_interface
*iface
,
162 struct usb_driver
*driver
,
163 const struct snd_usb_audio_quirk
*quirk
)
165 struct audioformat
*fp
;
166 struct usb_host_interface
*alts
;
167 struct usb_interface_descriptor
*altsd
;
168 unsigned *rate_table
= NULL
;
171 fp
= kmemdup(quirk
->data
, sizeof(*fp
), GFP_KERNEL
);
175 INIT_LIST_HEAD(&fp
->list
);
176 if (fp
->nr_rates
> MAX_NR_RATES
) {
180 if (fp
->nr_rates
> 0) {
181 rate_table
= kmemdup(fp
->rate_table
,
182 sizeof(int) * fp
->nr_rates
, GFP_KERNEL
);
187 fp
->rate_table
= rate_table
;
190 if (fp
->iface
!= get_iface_desc(&iface
->altsetting
[0])->bInterfaceNumber
||
191 fp
->altset_idx
>= iface
->num_altsetting
) {
195 alts
= &iface
->altsetting
[fp
->altset_idx
];
196 altsd
= get_iface_desc(alts
);
197 if (altsd
->bNumEndpoints
<= fp
->ep_idx
) {
202 fp
->protocol
= altsd
->bInterfaceProtocol
;
204 if (fp
->datainterval
== 0)
205 fp
->datainterval
= snd_usb_parse_datainterval(chip
, alts
);
206 if (fp
->maxpacksize
== 0)
207 fp
->maxpacksize
= le16_to_cpu(get_endpoint(alts
, fp
->ep_idx
)->wMaxPacketSize
);
209 fp
->fmt_type
= UAC_FORMAT_TYPE_I
;
211 err
= add_audio_stream_from_fixed_fmt(chip
, fp
);
215 usb_set_interface(chip
->dev
, fp
->iface
, 0);
216 snd_usb_init_pitch(chip
, fp
);
217 snd_usb_init_sample_rate(chip
, fp
, fp
->rate_max
);
221 list_del(&fp
->list
); /* unlink for avoiding double-free */
227 static int create_auto_pcm_quirk(struct snd_usb_audio
*chip
,
228 struct usb_interface
*iface
,
229 struct usb_driver
*driver
)
231 struct usb_host_interface
*alts
;
232 struct usb_interface_descriptor
*altsd
;
233 struct usb_endpoint_descriptor
*epd
;
234 struct uac1_as_header_descriptor
*ashd
;
235 struct uac_format_type_i_discrete_descriptor
*fmtd
;
238 * Most Roland/Yamaha audio streaming interfaces have more or less
239 * standard descriptors, but older devices might lack descriptors, and
240 * future ones might change, so ensure that we fail silently if the
241 * interface doesn't look exactly right.
244 /* must have a non-zero altsetting for streaming */
245 if (iface
->num_altsetting
< 2)
247 alts
= &iface
->altsetting
[1];
248 altsd
= get_iface_desc(alts
);
250 /* must have an isochronous endpoint for streaming */
251 if (altsd
->bNumEndpoints
< 1)
253 epd
= get_endpoint(alts
, 0);
254 if (!usb_endpoint_xfer_isoc(epd
))
257 /* must have format descriptors */
258 ashd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
, NULL
,
260 fmtd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
, NULL
,
262 if (!ashd
|| ashd
->bLength
< 7 ||
263 !fmtd
|| fmtd
->bLength
< 8)
266 return create_standard_audio_quirk(chip
, iface
, driver
, NULL
);
269 static int create_yamaha_midi_quirk(struct snd_usb_audio
*chip
,
270 struct usb_interface
*iface
,
271 struct usb_driver
*driver
,
272 struct usb_host_interface
*alts
)
274 static const struct snd_usb_audio_quirk yamaha_midi_quirk
= {
275 .type
= QUIRK_MIDI_YAMAHA
277 struct usb_midi_in_jack_descriptor
*injd
;
278 struct usb_midi_out_jack_descriptor
*outjd
;
280 /* must have some valid jack descriptors */
281 injd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
,
282 NULL
, USB_MS_MIDI_IN_JACK
);
283 outjd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
,
284 NULL
, USB_MS_MIDI_OUT_JACK
);
287 if ((injd
&& !snd_usb_validate_midi_desc(injd
)) ||
288 (outjd
&& !snd_usb_validate_midi_desc(outjd
)))
290 if (injd
&& (injd
->bLength
< 5 ||
291 (injd
->bJackType
!= USB_MS_EMBEDDED
&&
292 injd
->bJackType
!= USB_MS_EXTERNAL
)))
294 if (outjd
&& (outjd
->bLength
< 6 ||
295 (outjd
->bJackType
!= USB_MS_EMBEDDED
&&
296 outjd
->bJackType
!= USB_MS_EXTERNAL
)))
298 return create_any_midi_quirk(chip
, iface
, driver
, &yamaha_midi_quirk
);
301 static int create_roland_midi_quirk(struct snd_usb_audio
*chip
,
302 struct usb_interface
*iface
,
303 struct usb_driver
*driver
,
304 struct usb_host_interface
*alts
)
306 static const struct snd_usb_audio_quirk roland_midi_quirk
= {
307 .type
= QUIRK_MIDI_ROLAND
309 u8
*roland_desc
= NULL
;
311 /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
313 roland_desc
= snd_usb_find_csint_desc(alts
->extra
,
318 if (roland_desc
[0] < 6 || roland_desc
[3] != 2)
320 return create_any_midi_quirk(chip
, iface
, driver
,
325 static int create_std_midi_quirk(struct snd_usb_audio
*chip
,
326 struct usb_interface
*iface
,
327 struct usb_driver
*driver
,
328 struct usb_host_interface
*alts
)
330 struct usb_ms_header_descriptor
*mshd
;
331 struct usb_ms_endpoint_descriptor
*msepd
;
333 /* must have the MIDIStreaming interface header descriptor*/
334 mshd
= (struct usb_ms_header_descriptor
*)alts
->extra
;
335 if (alts
->extralen
< 7 ||
337 mshd
->bDescriptorType
!= USB_DT_CS_INTERFACE
||
338 mshd
->bDescriptorSubtype
!= USB_MS_HEADER
)
340 /* must have the MIDIStreaming endpoint descriptor*/
341 msepd
= (struct usb_ms_endpoint_descriptor
*)alts
->endpoint
[0].extra
;
342 if (alts
->endpoint
[0].extralen
< 4 ||
343 msepd
->bLength
< 4 ||
344 msepd
->bDescriptorType
!= USB_DT_CS_ENDPOINT
||
345 msepd
->bDescriptorSubtype
!= UAC_MS_GENERAL
||
346 msepd
->bNumEmbMIDIJack
< 1 ||
347 msepd
->bNumEmbMIDIJack
> 16)
350 return create_any_midi_quirk(chip
, iface
, driver
, NULL
);
353 static int create_auto_midi_quirk(struct snd_usb_audio
*chip
,
354 struct usb_interface
*iface
,
355 struct usb_driver
*driver
)
357 struct usb_host_interface
*alts
;
358 struct usb_interface_descriptor
*altsd
;
359 struct usb_endpoint_descriptor
*epd
;
362 alts
= &iface
->altsetting
[0];
363 altsd
= get_iface_desc(alts
);
365 /* must have at least one bulk/interrupt endpoint for streaming */
366 if (altsd
->bNumEndpoints
< 1)
368 epd
= get_endpoint(alts
, 0);
369 if (!usb_endpoint_xfer_bulk(epd
) &&
370 !usb_endpoint_xfer_int(epd
))
373 switch (USB_ID_VENDOR(chip
->usb_id
)) {
374 case 0x0499: /* Yamaha */
375 err
= create_yamaha_midi_quirk(chip
, iface
, driver
, alts
);
379 case 0x0582: /* Roland */
380 err
= create_roland_midi_quirk(chip
, iface
, driver
, alts
);
386 return create_std_midi_quirk(chip
, iface
, driver
, alts
);
389 static int create_autodetect_quirk(struct snd_usb_audio
*chip
,
390 struct usb_interface
*iface
,
391 struct usb_driver
*driver
)
395 err
= create_auto_pcm_quirk(chip
, iface
, driver
);
397 err
= create_auto_midi_quirk(chip
, iface
, driver
);
401 static int create_autodetect_quirks(struct snd_usb_audio
*chip
,
402 struct usb_interface
*iface
,
403 struct usb_driver
*driver
,
404 const struct snd_usb_audio_quirk
*quirk
)
406 int probed_ifnum
= get_iface_desc(iface
->altsetting
)->bInterfaceNumber
;
407 int ifcount
, ifnum
, err
;
409 err
= create_autodetect_quirk(chip
, iface
, driver
);
414 * ALSA PCM playback/capture devices cannot be registered in two steps,
415 * so we have to claim the other corresponding interface here.
417 ifcount
= chip
->dev
->actconfig
->desc
.bNumInterfaces
;
418 for (ifnum
= 0; ifnum
< ifcount
; ifnum
++) {
419 if (ifnum
== probed_ifnum
|| quirk
->ifnum
>= 0)
421 iface
= usb_ifnum_to_if(chip
->dev
, ifnum
);
423 usb_interface_claimed(iface
) ||
424 get_iface_desc(iface
->altsetting
)->bInterfaceClass
!=
425 USB_CLASS_VENDOR_SPEC
)
428 err
= create_autodetect_quirk(chip
, iface
, driver
);
430 usb_driver_claim_interface(driver
, iface
, (void *)-1L);
437 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
438 * The only way to detect the sample rate is by looking at wMaxPacketSize.
440 static int create_uaxx_quirk(struct snd_usb_audio
*chip
,
441 struct usb_interface
*iface
,
442 struct usb_driver
*driver
,
443 const struct snd_usb_audio_quirk
*quirk
)
445 static const struct audioformat ua_format
= {
446 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
448 .fmt_type
= UAC_FORMAT_TYPE_I
,
451 .rates
= SNDRV_PCM_RATE_CONTINUOUS
,
453 struct usb_host_interface
*alts
;
454 struct usb_interface_descriptor
*altsd
;
455 struct audioformat
*fp
;
458 /* both PCM and MIDI interfaces have 2 or more altsettings */
459 if (iface
->num_altsetting
< 2)
461 alts
= &iface
->altsetting
[1];
462 altsd
= get_iface_desc(alts
);
464 if (altsd
->bNumEndpoints
== 2) {
465 static const struct snd_usb_midi_endpoint_info ua700_ep
= {
466 .out_cables
= 0x0003,
469 static const struct snd_usb_audio_quirk ua700_quirk
= {
470 .type
= QUIRK_MIDI_FIXED_ENDPOINT
,
473 static const struct snd_usb_midi_endpoint_info uaxx_ep
= {
474 .out_cables
= 0x0001,
477 static const struct snd_usb_audio_quirk uaxx_quirk
= {
478 .type
= QUIRK_MIDI_FIXED_ENDPOINT
,
481 const struct snd_usb_audio_quirk
*quirk
=
482 chip
->usb_id
== USB_ID(0x0582, 0x002b)
483 ? &ua700_quirk
: &uaxx_quirk
;
484 return __snd_usbmidi_create(chip
->card
, iface
,
485 &chip
->midi_list
, quirk
,
489 if (altsd
->bNumEndpoints
!= 1)
492 fp
= kmemdup(&ua_format
, sizeof(*fp
), GFP_KERNEL
);
496 fp
->iface
= altsd
->bInterfaceNumber
;
497 fp
->endpoint
= get_endpoint(alts
, 0)->bEndpointAddress
;
498 fp
->ep_attr
= get_endpoint(alts
, 0)->bmAttributes
;
499 fp
->datainterval
= 0;
500 fp
->maxpacksize
= le16_to_cpu(get_endpoint(alts
, 0)->wMaxPacketSize
);
501 INIT_LIST_HEAD(&fp
->list
);
503 switch (fp
->maxpacksize
) {
505 fp
->rate_max
= fp
->rate_min
= 44100;
509 fp
->rate_max
= fp
->rate_min
= 48000;
513 fp
->rate_max
= fp
->rate_min
= 96000;
516 usb_audio_err(chip
, "unknown sample rate\n");
521 err
= add_audio_stream_from_fixed_fmt(chip
, fp
);
523 list_del(&fp
->list
); /* unlink for avoiding double-free */
527 usb_set_interface(chip
->dev
, fp
->iface
, 0);
532 * Create a standard mixer for the specified interface.
534 static int create_standard_mixer_quirk(struct snd_usb_audio
*chip
,
535 struct usb_interface
*iface
,
536 struct usb_driver
*driver
,
537 const struct snd_usb_audio_quirk
*quirk
)
539 if (quirk
->ifnum
< 0)
542 return snd_usb_create_mixer(chip
, quirk
->ifnum
, 0);
545 static int setup_disable_autosuspend(struct snd_usb_audio
*chip
,
546 struct usb_interface
*iface
,
547 struct usb_driver
*driver
,
548 const struct snd_usb_audio_quirk
*quirk
)
550 usb_disable_autosuspend(interface_to_usbdev(iface
));
551 return 1; /* Continue with creating streams and mixer */
555 * audio-interface quirks
557 * returns zero if no standard audio/MIDI parsing is needed.
558 * returns a positive value if standard audio/midi interfaces are parsed
560 * returns a negative value at error.
562 int snd_usb_create_quirk(struct snd_usb_audio
*chip
,
563 struct usb_interface
*iface
,
564 struct usb_driver
*driver
,
565 const struct snd_usb_audio_quirk
*quirk
)
567 typedef int (*quirk_func_t
)(struct snd_usb_audio
*,
568 struct usb_interface
*,
570 const struct snd_usb_audio_quirk
*);
571 static const quirk_func_t quirk_funcs
[] = {
572 [QUIRK_IGNORE_INTERFACE
] = ignore_interface_quirk
,
573 [QUIRK_COMPOSITE
] = create_composite_quirk
,
574 [QUIRK_AUTODETECT
] = create_autodetect_quirks
,
575 [QUIRK_MIDI_STANDARD_INTERFACE
] = create_any_midi_quirk
,
576 [QUIRK_MIDI_FIXED_ENDPOINT
] = create_any_midi_quirk
,
577 [QUIRK_MIDI_YAMAHA
] = create_any_midi_quirk
,
578 [QUIRK_MIDI_ROLAND
] = create_any_midi_quirk
,
579 [QUIRK_MIDI_MIDIMAN
] = create_any_midi_quirk
,
580 [QUIRK_MIDI_NOVATION
] = create_any_midi_quirk
,
581 [QUIRK_MIDI_RAW_BYTES
] = create_any_midi_quirk
,
582 [QUIRK_MIDI_EMAGIC
] = create_any_midi_quirk
,
583 [QUIRK_MIDI_CME
] = create_any_midi_quirk
,
584 [QUIRK_MIDI_AKAI
] = create_any_midi_quirk
,
585 [QUIRK_MIDI_FTDI
] = create_any_midi_quirk
,
586 [QUIRK_MIDI_CH345
] = create_any_midi_quirk
,
587 [QUIRK_AUDIO_STANDARD_INTERFACE
] = create_standard_audio_quirk
,
588 [QUIRK_AUDIO_FIXED_ENDPOINT
] = create_fixed_stream_quirk
,
589 [QUIRK_AUDIO_EDIROL_UAXX
] = create_uaxx_quirk
,
590 [QUIRK_AUDIO_ALIGN_TRANSFER
] = create_align_transfer_quirk
,
591 [QUIRK_AUDIO_STANDARD_MIXER
] = create_standard_mixer_quirk
,
592 [QUIRK_SETUP_DISABLE_AUTOSUSPEND
] = setup_disable_autosuspend
,
595 if (quirk
->type
< QUIRK_TYPE_COUNT
) {
596 return quirk_funcs
[quirk
->type
](chip
, iface
, driver
, quirk
);
598 usb_audio_err(chip
, "invalid quirk type %d\n", quirk
->type
);
607 #define EXTIGY_FIRMWARE_SIZE_OLD 794
608 #define EXTIGY_FIRMWARE_SIZE_NEW 483
610 static int snd_usb_extigy_boot_quirk(struct usb_device
*dev
, struct usb_interface
*intf
)
612 struct usb_host_config
*config
= dev
->actconfig
;
615 if (le16_to_cpu(get_cfg_desc(config
)->wTotalLength
) == EXTIGY_FIRMWARE_SIZE_OLD
||
616 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
) == EXTIGY_FIRMWARE_SIZE_NEW
) {
617 dev_dbg(&dev
->dev
, "sending Extigy boot sequence...\n");
618 /* Send message to force it to reconnect with full interface. */
619 err
= snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
,0),
620 0x10, 0x43, 0x0001, 0x000a, NULL
, 0);
622 dev_dbg(&dev
->dev
, "error sending boot message: %d\n", err
);
623 err
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0,
624 &dev
->descriptor
, sizeof(dev
->descriptor
));
625 config
= dev
->actconfig
;
627 dev_dbg(&dev
->dev
, "error usb_get_descriptor: %d\n", err
);
628 err
= usb_reset_configuration(dev
);
630 dev_dbg(&dev
->dev
, "error usb_reset_configuration: %d\n", err
);
631 dev_dbg(&dev
->dev
, "extigy_boot: new boot length = %d\n",
632 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
));
633 return -ENODEV
; /* quit this anyway */
638 static int snd_usb_audigy2nx_boot_quirk(struct usb_device
*dev
)
642 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0), 0x2a,
643 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
646 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), 0x29,
647 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
654 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device
*dev
)
658 if (dev
->actconfig
->desc
.bConfigurationValue
== 1) {
660 "Fast Track Pro switching to config #2\n");
661 /* This function has to be available by the usb core module.
662 * if it is not avialable the boot quirk has to be left out
663 * and the configuration has to be set by udev or hotplug
666 err
= usb_driver_set_configuration(dev
, 2);
669 "error usb_driver_set_configuration: %d\n",
671 /* Always return an error, so that we stop creating a device
672 that will just be destroyed and recreated with a new
676 dev_info(&dev
->dev
, "Fast Track Pro config OK\n");
682 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
683 * documented in the device's data sheet.
685 static int snd_usb_cm106_write_int_reg(struct usb_device
*dev
, int reg
, u16 value
)
689 buf
[1] = value
& 0xff;
690 buf
[2] = (value
>> 8) & 0xff;
692 return snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), USB_REQ_SET_CONFIGURATION
,
693 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
,
697 static int snd_usb_cm106_boot_quirk(struct usb_device
*dev
)
700 * Enable line-out driver mode, set headphone source to front
701 * channels, enable stereo mic.
703 return snd_usb_cm106_write_int_reg(dev
, 2, 0x8004);
707 * CM6206 registers from the CM6206 datasheet rev 2.1
709 #define CM6206_REG0_DMA_MASTER BIT(15)
710 #define CM6206_REG0_SPDIFO_RATE_48K (2 << 12)
711 #define CM6206_REG0_SPDIFO_RATE_96K (7 << 12)
712 /* Bit 4 thru 11 is the S/PDIF category code */
713 #define CM6206_REG0_SPDIFO_CAT_CODE_GENERAL (0 << 4)
714 #define CM6206_REG0_SPDIFO_EMPHASIS_CD BIT(3)
715 #define CM6206_REG0_SPDIFO_COPYRIGHT_NA BIT(2)
716 #define CM6206_REG0_SPDIFO_NON_AUDIO BIT(1)
717 #define CM6206_REG0_SPDIFO_PRO_FORMAT BIT(0)
719 #define CM6206_REG1_TEST_SEL_CLK BIT(14)
720 #define CM6206_REG1_PLLBIN_EN BIT(13)
721 #define CM6206_REG1_SOFT_MUTE_EN BIT(12)
722 #define CM6206_REG1_GPIO4_OUT BIT(11)
723 #define CM6206_REG1_GPIO4_OE BIT(10)
724 #define CM6206_REG1_GPIO3_OUT BIT(9)
725 #define CM6206_REG1_GPIO3_OE BIT(8)
726 #define CM6206_REG1_GPIO2_OUT BIT(7)
727 #define CM6206_REG1_GPIO2_OE BIT(6)
728 #define CM6206_REG1_GPIO1_OUT BIT(5)
729 #define CM6206_REG1_GPIO1_OE BIT(4)
730 #define CM6206_REG1_SPDIFO_INVALID BIT(3)
731 #define CM6206_REG1_SPDIF_LOOP_EN BIT(2)
732 #define CM6206_REG1_SPDIFO_DIS BIT(1)
733 #define CM6206_REG1_SPDIFI_MIX BIT(0)
735 #define CM6206_REG2_DRIVER_ON BIT(15)
736 #define CM6206_REG2_HEADP_SEL_SIDE_CHANNELS (0 << 13)
737 #define CM6206_REG2_HEADP_SEL_SURROUND_CHANNELS (1 << 13)
738 #define CM6206_REG2_HEADP_SEL_CENTER_SUBW (2 << 13)
739 #define CM6206_REG2_HEADP_SEL_FRONT_CHANNELS (3 << 13)
740 #define CM6206_REG2_MUTE_HEADPHONE_RIGHT BIT(12)
741 #define CM6206_REG2_MUTE_HEADPHONE_LEFT BIT(11)
742 #define CM6206_REG2_MUTE_REAR_SURROUND_RIGHT BIT(10)
743 #define CM6206_REG2_MUTE_REAR_SURROUND_LEFT BIT(9)
744 #define CM6206_REG2_MUTE_SIDE_SURROUND_RIGHT BIT(8)
745 #define CM6206_REG2_MUTE_SIDE_SURROUND_LEFT BIT(7)
746 #define CM6206_REG2_MUTE_SUBWOOFER BIT(6)
747 #define CM6206_REG2_MUTE_CENTER BIT(5)
748 #define CM6206_REG2_MUTE_RIGHT_FRONT BIT(3)
749 #define CM6206_REG2_MUTE_LEFT_FRONT BIT(3)
750 #define CM6206_REG2_EN_BTL BIT(2)
751 #define CM6206_REG2_MCUCLKSEL_1_5_MHZ (0)
752 #define CM6206_REG2_MCUCLKSEL_3_MHZ (1)
753 #define CM6206_REG2_MCUCLKSEL_6_MHZ (2)
754 #define CM6206_REG2_MCUCLKSEL_12_MHZ (3)
756 /* Bit 11..13 sets the sensitivity to FLY tuner volume control VP/VD signal */
757 #define CM6206_REG3_FLYSPEED_DEFAULT (2 << 11)
758 #define CM6206_REG3_VRAP25EN BIT(10)
759 #define CM6206_REG3_MSEL1 BIT(9)
760 #define CM6206_REG3_SPDIFI_RATE_44_1K BIT(0 << 7)
761 #define CM6206_REG3_SPDIFI_RATE_48K BIT(2 << 7)
762 #define CM6206_REG3_SPDIFI_RATE_32K BIT(3 << 7)
763 #define CM6206_REG3_PINSEL BIT(6)
764 #define CM6206_REG3_FOE BIT(5)
765 #define CM6206_REG3_ROE BIT(4)
766 #define CM6206_REG3_CBOE BIT(3)
767 #define CM6206_REG3_LOSE BIT(2)
768 #define CM6206_REG3_HPOE BIT(1)
769 #define CM6206_REG3_SPDIFI_CANREC BIT(0)
771 #define CM6206_REG5_DA_RSTN BIT(13)
772 #define CM6206_REG5_AD_RSTN BIT(12)
773 #define CM6206_REG5_SPDIFO_AD2SPDO BIT(12)
774 #define CM6206_REG5_SPDIFO_SEL_FRONT (0 << 9)
775 #define CM6206_REG5_SPDIFO_SEL_SIDE_SUR (1 << 9)
776 #define CM6206_REG5_SPDIFO_SEL_CEN_LFE (2 << 9)
777 #define CM6206_REG5_SPDIFO_SEL_REAR_SUR (3 << 9)
778 #define CM6206_REG5_CODECM BIT(8)
779 #define CM6206_REG5_EN_HPF BIT(7)
780 #define CM6206_REG5_T_SEL_DSDA4 BIT(6)
781 #define CM6206_REG5_T_SEL_DSDA3 BIT(5)
782 #define CM6206_REG5_T_SEL_DSDA2 BIT(4)
783 #define CM6206_REG5_T_SEL_DSDA1 BIT(3)
784 #define CM6206_REG5_T_SEL_DSDAD_NORMAL 0
785 #define CM6206_REG5_T_SEL_DSDAD_FRONT 4
786 #define CM6206_REG5_T_SEL_DSDAD_S_SURROUND 5
787 #define CM6206_REG5_T_SEL_DSDAD_CEN_LFE 6
788 #define CM6206_REG5_T_SEL_DSDAD_R_SURROUND 7
790 static int snd_usb_cm6206_boot_quirk(struct usb_device
*dev
)
795 * Values here are chosen based on sniffing USB traffic
798 * REG0: DAC is master, sample rate 48kHz, no copyright
800 CM6206_REG0_SPDIFO_RATE_48K
|
801 CM6206_REG0_SPDIFO_COPYRIGHT_NA
,
803 * REG1: PLL binary search enable, soft mute enable.
805 CM6206_REG1_PLLBIN_EN
|
806 CM6206_REG1_SOFT_MUTE_EN
,
808 * REG2: enable output drivers,
809 * select front channels to the headphone output,
810 * then mute the headphone channels, run the MCU
813 CM6206_REG2_DRIVER_ON
|
814 CM6206_REG2_HEADP_SEL_FRONT_CHANNELS
|
815 CM6206_REG2_MUTE_HEADPHONE_RIGHT
|
816 CM6206_REG2_MUTE_HEADPHONE_LEFT
,
818 * REG3: default flyspeed, set 2.5V mic bias
819 * enable all line out ports and enable SPDIF
821 CM6206_REG3_FLYSPEED_DEFAULT
|
822 CM6206_REG3_VRAP25EN
|
828 CM6206_REG3_SPDIFI_CANREC
,
829 /* REG4 is just a bunch of GPIO lines */
831 /* REG5: de-assert AD/DA reset signals */
832 CM6206_REG5_DA_RSTN
|
833 CM6206_REG5_AD_RSTN
};
835 for (reg
= 0; reg
< ARRAY_SIZE(val
); reg
++) {
836 err
= snd_usb_cm106_write_int_reg(dev
, reg
, val
[reg
]);
844 /* quirk for Plantronics GameCom 780 with CM6302 chip */
845 static int snd_usb_gamecon780_boot_quirk(struct usb_device
*dev
)
847 /* set the initial volume and don't change; other values are either
848 * too loud or silent due to firmware bug (bko#65251)
850 u8 buf
[2] = { 0x74, 0xe3 };
851 return snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), UAC_SET_CUR
,
852 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
853 UAC_FU_VOLUME
<< 8, 9 << 8, buf
, 2);
857 * Novation Twitch DJ controller
858 * Focusrite Novation Saffire 6 USB audio card
860 static int snd_usb_novation_boot_quirk(struct usb_device
*dev
)
862 /* preemptively set up the device because otherwise the
863 * raw MIDI endpoints are not active */
864 usb_set_interface(dev
, 0, 1);
869 * This call will put the synth in "USB send" mode, i.e it will send MIDI
870 * messages through USB (this is disabled at startup). The synth will
871 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
872 * sign on its LCD. Values here are chosen based on sniffing USB traffic
875 static int snd_usb_accessmusic_boot_quirk(struct usb_device
*dev
)
877 int err
, actual_length
;
878 /* "midi send" enable */
879 static const u8 seq
[] = { 0x4e, 0x73, 0x52, 0x01 };
882 if (usb_pipe_type_check(dev
, usb_sndintpipe(dev
, 0x05)))
884 buf
= kmemdup(seq
, ARRAY_SIZE(seq
), GFP_KERNEL
);
887 err
= usb_interrupt_msg(dev
, usb_sndintpipe(dev
, 0x05), buf
,
888 ARRAY_SIZE(seq
), &actual_length
, 1000);
897 * Some sound cards from Native Instruments are in fact compliant to the USB
898 * audio standard of version 2 and other approved USB standards, even though
899 * they come up as vendor-specific device when first connected.
901 * However, they can be told to come up with a new set of descriptors
902 * upon their next enumeration, and the interfaces announced by the new
903 * descriptors will then be handled by the kernel's class drivers. As the
904 * product ID will also change, no further checks are required.
907 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device
*dev
)
911 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
912 0xaf, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
913 1, 0, NULL
, 0, 1000);
918 usb_reset_device(dev
);
920 /* return -EAGAIN, so the creation of an audio interface for this
921 * temporary device is aborted. The device will reconnect with a
926 static void mbox2_setup_48_24_magic(struct usb_device
*dev
)
931 /* Choose 48000Hz permanently */
936 /* Send the magic! */
937 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
938 0x01, 0x22, 0x0100, 0x0085, &temp
, 0x0003);
939 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
940 0x81, 0xa2, 0x0100, 0x0085, &srate
, 0x0003);
941 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
942 0x81, 0xa2, 0x0100, 0x0086, &srate
, 0x0003);
943 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
944 0x81, 0xa2, 0x0100, 0x0003, &srate
, 0x0003);
948 /* Digidesign Mbox 2 needs to load firmware onboard
949 * and driver must wait a few seconds for initialisation.
952 #define MBOX2_FIRMWARE_SIZE 646
953 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
954 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
956 static int snd_usb_mbox2_boot_quirk(struct usb_device
*dev
)
958 struct usb_host_config
*config
= dev
->actconfig
;
960 u8 bootresponse
[0x12];
964 fwsize
= le16_to_cpu(get_cfg_desc(config
)->wTotalLength
);
966 if (fwsize
!= MBOX2_FIRMWARE_SIZE
) {
967 dev_err(&dev
->dev
, "Invalid firmware size=%d.\n", fwsize
);
971 dev_dbg(&dev
->dev
, "Sending Digidesign Mbox 2 boot sequence...\n");
974 bootresponse
[0] = MBOX2_BOOT_LOADING
;
975 while ((bootresponse
[0] == MBOX2_BOOT_LOADING
) && (count
< 10)) {
976 msleep(500); /* 0.5 second delay */
977 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
978 /* Control magic - load onboard firmware */
979 0x85, 0xc0, 0x0001, 0x0000, &bootresponse
, 0x0012);
980 if (bootresponse
[0] == MBOX2_BOOT_READY
)
982 dev_dbg(&dev
->dev
, "device not ready, resending boot sequence...\n");
986 if (bootresponse
[0] != MBOX2_BOOT_READY
) {
987 dev_err(&dev
->dev
, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse
[0]);
991 dev_dbg(&dev
->dev
, "device initialised!\n");
993 err
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0,
994 &dev
->descriptor
, sizeof(dev
->descriptor
));
995 config
= dev
->actconfig
;
997 dev_dbg(&dev
->dev
, "error usb_get_descriptor: %d\n", err
);
999 err
= usb_reset_configuration(dev
);
1001 dev_dbg(&dev
->dev
, "error usb_reset_configuration: %d\n", err
);
1002 dev_dbg(&dev
->dev
, "mbox2_boot: new boot length = %d\n",
1003 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
));
1005 mbox2_setup_48_24_magic(dev
);
1007 dev_info(&dev
->dev
, "Digidesign Mbox 2: 24bit 48kHz");
1009 return 0; /* Successful boot */
1012 static int snd_usb_axefx3_boot_quirk(struct usb_device
*dev
)
1016 dev_dbg(&dev
->dev
, "Waiting for Axe-Fx III to boot up...\n");
1018 /* If the Axe-Fx III has not fully booted, it will timeout when trying
1019 * to enable the audio streaming interface. A more generous timeout is
1020 * used here to detect when the Axe-Fx III has finished booting as the
1021 * set interface message will be acked once it has
1023 err
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
1024 USB_REQ_SET_INTERFACE
, USB_RECIP_INTERFACE
,
1025 1, 1, NULL
, 0, 120000);
1028 "failed waiting for Axe-Fx III to boot: %d\n", err
);
1032 dev_dbg(&dev
->dev
, "Axe-Fx III is now ready\n");
1034 err
= usb_set_interface(dev
, 1, 0);
1037 "error stopping Axe-Fx III interface: %d\n", err
);
1043 #define MICROBOOK_BUF_SIZE 128
1045 static int snd_usb_motu_microbookii_communicate(struct usb_device
*dev
, u8
*buf
,
1046 int buf_size
, int *length
)
1048 int err
, actual_length
;
1050 if (usb_pipe_type_check(dev
, usb_sndintpipe(dev
, 0x01)))
1052 err
= usb_interrupt_msg(dev
, usb_sndintpipe(dev
, 0x01), buf
, *length
,
1053 &actual_length
, 1000);
1057 print_hex_dump(KERN_DEBUG
, "MicroBookII snd: ", DUMP_PREFIX_NONE
, 16, 1,
1058 buf
, actual_length
, false);
1060 memset(buf
, 0, buf_size
);
1062 if (usb_pipe_type_check(dev
, usb_rcvintpipe(dev
, 0x82)))
1064 err
= usb_interrupt_msg(dev
, usb_rcvintpipe(dev
, 0x82), buf
, buf_size
,
1065 &actual_length
, 1000);
1069 print_hex_dump(KERN_DEBUG
, "MicroBookII rcv: ", DUMP_PREFIX_NONE
, 16, 1,
1070 buf
, actual_length
, false);
1072 *length
= actual_length
;
1076 static int snd_usb_motu_microbookii_boot_quirk(struct usb_device
*dev
)
1078 int err
, actual_length
, poll_attempts
= 0;
1079 static const u8 set_samplerate_seq
[] = { 0x00, 0x00, 0x00, 0x00,
1080 0x00, 0x00, 0x0b, 0x14,
1081 0x00, 0x00, 0x00, 0x01 };
1082 static const u8 poll_ready_seq
[] = { 0x00, 0x04, 0x00, 0x00,
1083 0x00, 0x00, 0x0b, 0x18 };
1084 u8
*buf
= kzalloc(MICROBOOK_BUF_SIZE
, GFP_KERNEL
);
1089 dev_info(&dev
->dev
, "Waiting for MOTU Microbook II to boot up...\n");
1091 /* First we tell the device which sample rate to use. */
1092 memcpy(buf
, set_samplerate_seq
, sizeof(set_samplerate_seq
));
1093 actual_length
= sizeof(set_samplerate_seq
);
1094 err
= snd_usb_motu_microbookii_communicate(dev
, buf
, MICROBOOK_BUF_SIZE
,
1099 "failed setting the sample rate for Motu MicroBook II: %d\n",
1104 /* Then we poll every 100 ms until the device informs of its readiness. */
1106 if (++poll_attempts
> 100) {
1108 "failed booting Motu MicroBook II: timeout\n");
1113 memset(buf
, 0, MICROBOOK_BUF_SIZE
);
1114 memcpy(buf
, poll_ready_seq
, sizeof(poll_ready_seq
));
1116 actual_length
= sizeof(poll_ready_seq
);
1117 err
= snd_usb_motu_microbookii_communicate(
1118 dev
, buf
, MICROBOOK_BUF_SIZE
, &actual_length
);
1121 "failed booting Motu MicroBook II: communication error %d\n",
1126 /* the device signals its readiness through a message of the
1128 * XX 06 00 00 00 00 0b 18 00 00 00 01
1129 * If the device is not yet ready to accept audio data, the
1130 * last byte of that sequence is 00.
1132 if (actual_length
== 12 && buf
[actual_length
- 1] == 1)
1138 dev_info(&dev
->dev
, "MOTU MicroBook II ready\n");
1145 static int snd_usb_motu_m_series_boot_quirk(struct usb_device
*dev
)
1155 #define MAUDIO_SET 0x01 /* parse device_setup */
1156 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
1157 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
1158 #define MAUDIO_SET_96K 0x04 /* 48-96kHz rate if set, 8-48kHz otherwise */
1159 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
1160 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
1161 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
1162 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48kHz+Digital Input */
1163 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48kHz+No Digital Input */
1164 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48kHz+Digital Input */
1165 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48kHz+No Digital Input */
1167 static int quattro_skip_setting_quirk(struct snd_usb_audio
*chip
,
1168 int iface
, int altno
)
1170 /* Reset ALL ifaces to 0 altsetting.
1171 * Call it for every possible altsetting of every interface.
1173 usb_set_interface(chip
->dev
, iface
, 0);
1174 if (chip
->setup
& MAUDIO_SET
) {
1175 if (chip
->setup
& MAUDIO_SET_COMPATIBLE
) {
1176 if (iface
!= 1 && iface
!= 2)
1177 return 1; /* skip all interfaces but 1 and 2 */
1180 if (iface
== 1 || iface
== 2)
1181 return 1; /* skip interfaces 1 and 2 */
1182 if ((chip
->setup
& MAUDIO_SET_96K
) && altno
!= 1)
1183 return 1; /* skip this altsetting */
1184 mask
= chip
->setup
& MAUDIO_SET_MASK
;
1185 if (mask
== MAUDIO_SET_24B_48K_DI
&& altno
!= 2)
1186 return 1; /* skip this altsetting */
1187 if (mask
== MAUDIO_SET_24B_48K_NOTDI
&& altno
!= 3)
1188 return 1; /* skip this altsetting */
1189 if (mask
== MAUDIO_SET_16B_48K_NOTDI
&& altno
!= 4)
1190 return 1; /* skip this altsetting */
1194 "using altsetting %d for interface %d config %d\n",
1195 altno
, iface
, chip
->setup
);
1196 return 0; /* keep this altsetting */
1199 static int audiophile_skip_setting_quirk(struct snd_usb_audio
*chip
,
1203 /* Reset ALL ifaces to 0 altsetting.
1204 * Call it for every possible altsetting of every interface.
1206 usb_set_interface(chip
->dev
, iface
, 0);
1208 if (chip
->setup
& MAUDIO_SET
) {
1210 if ((chip
->setup
& MAUDIO_SET_DTS
) && altno
!= 6)
1211 return 1; /* skip this altsetting */
1212 if ((chip
->setup
& MAUDIO_SET_96K
) && altno
!= 1)
1213 return 1; /* skip this altsetting */
1214 mask
= chip
->setup
& MAUDIO_SET_MASK
;
1215 if (mask
== MAUDIO_SET_24B_48K_DI
&& altno
!= 2)
1216 return 1; /* skip this altsetting */
1217 if (mask
== MAUDIO_SET_24B_48K_NOTDI
&& altno
!= 3)
1218 return 1; /* skip this altsetting */
1219 if (mask
== MAUDIO_SET_16B_48K_DI
&& altno
!= 4)
1220 return 1; /* skip this altsetting */
1221 if (mask
== MAUDIO_SET_16B_48K_NOTDI
&& altno
!= 5)
1222 return 1; /* skip this altsetting */
1225 return 0; /* keep this altsetting */
1228 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio
*chip
,
1229 int iface
, int altno
)
1231 /* Reset ALL ifaces to 0 altsetting.
1232 * Call it for every possible altsetting of every interface.
1234 usb_set_interface(chip
->dev
, iface
, 0);
1236 /* possible configuration where both inputs and only one output is
1237 *used is not supported by the current setup
1239 if (chip
->setup
& (MAUDIO_SET
| MAUDIO_SET_24B
)) {
1240 if (chip
->setup
& MAUDIO_SET_96K
) {
1241 if (altno
!= 3 && altno
!= 6)
1243 } else if (chip
->setup
& MAUDIO_SET_DI
) {
1245 return 1; /* no analog input */
1246 if (altno
!= 2 && altno
!= 5)
1247 return 1; /* enable only altsets 2 and 5 */
1250 return 1; /* disable digialt input */
1251 if (altno
!= 2 && altno
!= 5)
1252 return 1; /* enalbe only altsets 2 and 5 */
1255 /* keep only 16-Bit mode */
1261 "using altsetting %d for interface %d config %d\n",
1262 altno
, iface
, chip
->setup
);
1263 return 0; /* keep this altsetting */
1266 static int s1810c_skip_setting_quirk(struct snd_usb_audio
*chip
,
1267 int iface
, int altno
)
1272 * Playback (Interface 1):
1273 * 1: 6 Analog + 2 S/PDIF
1274 * 2: 6 Analog + 2 S/PDIF
1277 * Capture (Interface 2):
1278 * 1: 8 Analog + 2 S/PDIF + 8 ADAT
1279 * 2: 8 Analog + 2 S/PDIF + 4 ADAT
1284 * I'll leave 2 as the default one and
1285 * use device_setup to switch to the
1288 if ((chip
->setup
== 0 || chip
->setup
> 2) && altno
!= 2)
1290 else if (chip
->setup
== 1 && altno
!= 1)
1292 else if (chip
->setup
== 2 && altno
!= 3)
1298 int snd_usb_apply_interface_quirk(struct snd_usb_audio
*chip
,
1302 /* audiophile usb: skip altsets incompatible with device_setup */
1303 if (chip
->usb_id
== USB_ID(0x0763, 0x2003))
1304 return audiophile_skip_setting_quirk(chip
, iface
, altno
);
1305 /* quattro usb: skip altsets incompatible with device_setup */
1306 if (chip
->usb_id
== USB_ID(0x0763, 0x2001))
1307 return quattro_skip_setting_quirk(chip
, iface
, altno
);
1308 /* fasttrackpro usb: skip altsets incompatible with device_setup */
1309 if (chip
->usb_id
== USB_ID(0x0763, 0x2012))
1310 return fasttrackpro_skip_setting_quirk(chip
, iface
, altno
);
1311 /* presonus studio 1810c: skip altsets incompatible with device_setup */
1312 if (chip
->usb_id
== USB_ID(0x0194f, 0x010c))
1313 return s1810c_skip_setting_quirk(chip
, iface
, altno
);
1319 int snd_usb_apply_boot_quirk(struct usb_device
*dev
,
1320 struct usb_interface
*intf
,
1321 const struct snd_usb_audio_quirk
*quirk
,
1325 case USB_ID(0x041e, 0x3000):
1326 /* SB Extigy needs special boot-up sequence */
1327 /* if more models come, this will go to the quirk list. */
1328 return snd_usb_extigy_boot_quirk(dev
, intf
);
1330 case USB_ID(0x041e, 0x3020):
1331 /* SB Audigy 2 NX needs its own boot-up magic, too */
1332 return snd_usb_audigy2nx_boot_quirk(dev
);
1334 case USB_ID(0x10f5, 0x0200):
1335 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
1336 return snd_usb_cm106_boot_quirk(dev
);
1338 case USB_ID(0x0d8c, 0x0102):
1339 /* C-Media CM6206 / CM106-Like Sound Device */
1340 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
1341 return snd_usb_cm6206_boot_quirk(dev
);
1343 case USB_ID(0x0dba, 0x3000):
1344 /* Digidesign Mbox 2 */
1345 return snd_usb_mbox2_boot_quirk(dev
);
1347 case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
1348 case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
1349 return snd_usb_novation_boot_quirk(dev
);
1351 case USB_ID(0x133e, 0x0815):
1352 /* Access Music VirusTI Desktop */
1353 return snd_usb_accessmusic_boot_quirk(dev
);
1355 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
1356 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
1357 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
1358 return snd_usb_nativeinstruments_boot_quirk(dev
);
1359 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1360 return snd_usb_fasttrackpro_boot_quirk(dev
);
1361 case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
1362 return snd_usb_gamecon780_boot_quirk(dev
);
1363 case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx 3 */
1364 return snd_usb_axefx3_boot_quirk(dev
);
1365 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook II */
1367 * For some reason interface 3 with vendor-spec class is
1368 * detected on MicroBook IIc.
1370 if (get_iface_desc(intf
->altsetting
)->bInterfaceClass
==
1371 USB_CLASS_VENDOR_SPEC
&&
1372 get_iface_desc(intf
->altsetting
)->bInterfaceNumber
< 3)
1373 return snd_usb_motu_microbookii_boot_quirk(dev
);
1380 int snd_usb_apply_boot_quirk_once(struct usb_device
*dev
,
1381 struct usb_interface
*intf
,
1382 const struct snd_usb_audio_quirk
*quirk
,
1386 case USB_ID(0x07fd, 0x0008): /* MOTU M Series */
1387 return snd_usb_motu_m_series_boot_quirk(dev
);
1394 * check if the device uses big-endian samples
1396 int snd_usb_is_big_endian_format(struct snd_usb_audio
*chip
,
1397 const struct audioformat
*fp
)
1399 /* it depends on altsetting whether the device is big-endian or not */
1400 switch (chip
->usb_id
) {
1401 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
1402 if (fp
->altsetting
== 2 || fp
->altsetting
== 3 ||
1403 fp
->altsetting
== 5 || fp
->altsetting
== 6)
1406 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1407 if (chip
->setup
== 0x00 ||
1408 fp
->altsetting
== 1 || fp
->altsetting
== 2 ||
1409 fp
->altsetting
== 3)
1412 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
1413 if (fp
->altsetting
== 2 || fp
->altsetting
== 3 ||
1414 fp
->altsetting
== 5 || fp
->altsetting
== 6)
1422 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
1423 * not for interface.
1427 EMU_QUIRK_SR_44100HZ
= 0,
1428 EMU_QUIRK_SR_48000HZ
,
1429 EMU_QUIRK_SR_88200HZ
,
1430 EMU_QUIRK_SR_96000HZ
,
1431 EMU_QUIRK_SR_176400HZ
,
1432 EMU_QUIRK_SR_192000HZ
1435 static void set_format_emu_quirk(struct snd_usb_substream
*subs
,
1436 const struct audioformat
*fmt
)
1438 unsigned char emu_samplerate_id
= 0;
1440 /* When capture is active
1441 * sample rate shouldn't be changed
1442 * by playback substream
1444 if (subs
->direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
1445 if (subs
->stream
->substream
[SNDRV_PCM_STREAM_CAPTURE
].cur_audiofmt
)
1449 switch (fmt
->rate_min
) {
1451 emu_samplerate_id
= EMU_QUIRK_SR_48000HZ
;
1454 emu_samplerate_id
= EMU_QUIRK_SR_88200HZ
;
1457 emu_samplerate_id
= EMU_QUIRK_SR_96000HZ
;
1460 emu_samplerate_id
= EMU_QUIRK_SR_176400HZ
;
1463 emu_samplerate_id
= EMU_QUIRK_SR_192000HZ
;
1466 emu_samplerate_id
= EMU_QUIRK_SR_44100HZ
;
1469 snd_emuusb_set_samplerate(subs
->stream
->chip
, emu_samplerate_id
);
1470 subs
->pkt_offset_adj
= (emu_samplerate_id
>= EMU_QUIRK_SR_176400HZ
) ? 4 : 0;
1473 static int pioneer_djm_set_format_quirk(struct snd_usb_substream
*subs
,
1476 unsigned int cur_rate
= subs
->data_endpoint
->cur_rate
;
1478 // Convert to little endian
1479 sr
[0] = cur_rate
& 0xff;
1480 sr
[1] = (cur_rate
>> 8) & 0xff;
1481 sr
[2] = (cur_rate
>> 16) & 0xff;
1482 usb_set_interface(subs
->dev
, 0, 1);
1483 // we should derive windex from fmt-sync_ep but it's not set
1484 snd_usb_ctl_msg(subs
->stream
->chip
->dev
,
1485 usb_sndctrlpipe(subs
->stream
->chip
->dev
, 0),
1486 0x01, 0x22, 0x0100, windex
, &sr
, 0x0003);
1490 void snd_usb_set_format_quirk(struct snd_usb_substream
*subs
,
1491 const struct audioformat
*fmt
)
1493 switch (subs
->stream
->chip
->usb_id
) {
1494 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
1495 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
1496 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
1497 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
1498 set_format_emu_quirk(subs
, fmt
);
1500 case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
1501 subs
->stream_offset_adj
= 2;
1503 case USB_ID(0x2b73, 0x0013): /* Pioneer DJM-450 */
1504 pioneer_djm_set_format_quirk(subs
, 0x0082);
1509 bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio
*chip
)
1511 /* devices which do not support reading the sample rate. */
1512 switch (chip
->usb_id
) {
1513 case USB_ID(0x041e, 0x4080): /* Creative Live Cam VF0610 */
1514 case USB_ID(0x04d8, 0xfeea): /* Benchmark DAC1 Pre */
1515 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
1516 case USB_ID(0x05a3, 0x9420): /* ELP HD USB Camera */
1517 case USB_ID(0x05a7, 0x1020): /* Bose Companion 5 */
1518 case USB_ID(0x074d, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1519 case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */
1520 case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */
1521 case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */
1522 case USB_ID(0x2912, 0x30c8): /* Audioengine D1 */
1526 /* devices of these vendors don't support reading rate, either */
1527 switch (USB_ID_VENDOR(chip
->usb_id
)) {
1528 case 0x045e: /* MS Lifecam */
1529 case 0x047f: /* Plantronics */
1530 case 0x1de7: /* Phoenix Audio */
1537 /* ITF-USB DSD based DACs need a vendor cmd to switch
1538 * between PCM and native DSD mode
1540 static bool is_itf_usb_dsd_dac(unsigned int id
)
1543 case USB_ID(0x154e, 0x1002): /* Denon DCD-1500RE */
1544 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1545 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1546 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1547 case USB_ID(0x1852, 0x5065): /* Luxman DA-06 */
1548 case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-501V2/UD-503/NT-503 */
1549 case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */
1550 case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */
1556 int snd_usb_select_mode_quirk(struct snd_usb_audio
*chip
,
1557 const struct audioformat
*fmt
)
1559 struct usb_device
*dev
= chip
->dev
;
1562 if (is_itf_usb_dsd_dac(chip
->usb_id
)) {
1563 /* First switch to alt set 0, otherwise the mode switch cmd
1564 * will not be accepted by the DAC
1566 err
= usb_set_interface(dev
, fmt
->iface
, 0);
1570 msleep(20); /* Delay needed after setting the interface */
1572 /* Vendor mode switch cmd is required. */
1573 if (fmt
->formats
& SNDRV_PCM_FMTBIT_DSD_U32_BE
) {
1574 /* DSD mode (DSD_U32) requested */
1575 err
= snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), 0,
1576 USB_DIR_OUT
|USB_TYPE_VENDOR
|USB_RECIP_INTERFACE
,
1582 /* PCM or DOP mode (S32) requested */
1583 /* PCM mode (S16) requested */
1584 err
= snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), 0,
1585 USB_DIR_OUT
|USB_TYPE_VENDOR
|USB_RECIP_INTERFACE
,
1596 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint
*ep
)
1599 * "Playback Design" products send bogus feedback data at the start
1600 * of the stream. Ignore them.
1602 if (USB_ID_VENDOR(ep
->chip
->usb_id
) == 0x23ba &&
1603 ep
->type
== SND_USB_ENDPOINT_TYPE_SYNC
)
1604 ep
->skip_packets
= 4;
1607 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
1608 * world latency varies by approx. +/- 50 frames (at 96kHz) each time
1609 * the stream is (re)started. When skipping packets 16 at endpoint
1610 * start up, the real world latency is stable within +/- 1 frame (also
1611 * across power cycles).
1613 if ((ep
->chip
->usb_id
== USB_ID(0x0763, 0x2030) ||
1614 ep
->chip
->usb_id
== USB_ID(0x0763, 0x2031)) &&
1615 ep
->type
== SND_USB_ENDPOINT_TYPE_DATA
)
1616 ep
->skip_packets
= 16;
1618 /* Work around devices that report unreasonable feedback data */
1619 if ((ep
->chip
->usb_id
== USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
1620 ep
->chip
->usb_id
== USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
1621 ep
->syncmaxsize
== 4)
1622 ep
->tenor_fb_quirk
= 1;
1625 void snd_usb_set_interface_quirk(struct snd_usb_audio
*chip
)
1630 * "Playback Design" products need a 50ms delay after setting the
1633 switch (USB_ID_VENDOR(chip
->usb_id
)) {
1634 case 0x23ba: /* Playback Design */
1635 case 0x0644: /* TEAC Corp. */
1641 /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
1642 void snd_usb_ctl_msg_quirk(struct usb_device
*dev
, unsigned int pipe
,
1643 __u8 request
, __u8 requesttype
, __u16 value
,
1644 __u16 index
, void *data
, __u16 size
)
1646 struct snd_usb_audio
*chip
= dev_get_drvdata(&dev
->dev
);
1651 * "Playback Design" products need a 20ms delay after each
1652 * class compliant request
1654 if (USB_ID_VENDOR(chip
->usb_id
) == 0x23ba &&
1655 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1659 * "TEAC Corp." products need a 20ms delay after each
1660 * class compliant request
1662 if (USB_ID_VENDOR(chip
->usb_id
) == 0x0644 &&
1663 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1666 /* ITF-USB DSD based DACs functionality need a delay
1667 * after each class compliant request
1669 if (is_itf_usb_dsd_dac(chip
->usb_id
)
1670 && (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1674 * Plantronics C320-M needs a delay to avoid random
1675 * microhpone failures.
1677 if (chip
->usb_id
== USB_ID(0x047f, 0xc025) &&
1678 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1681 /* Zoom R16/24, many Logitech(at least H650e/H570e/BCC950),
1682 * Jabra 550a, Kingston HyperX needs a tiny delay here,
1683 * otherwise requests like get/set frequency return
1684 * as failed despite actually succeeding.
1686 if ((chip
->usb_id
== USB_ID(0x1686, 0x00dd) ||
1687 USB_ID_VENDOR(chip
->usb_id
) == 0x046d || /* Logitech */
1688 chip
->usb_id
== USB_ID(0x0b0e, 0x0349) ||
1689 chip
->usb_id
== USB_ID(0x0951, 0x16ad)) &&
1690 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1691 usleep_range(1000, 2000);
1694 * Samsung USBC Headset (AKG) need a tiny delay after each
1695 * class compliant request. (Model number: AAM625R or AAM627R)
1697 if (chip
->usb_id
== USB_ID(0x04e8, 0xa051) &&
1698 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1699 usleep_range(5000, 6000);
1703 * snd_usb_interface_dsd_format_quirks() is called from format.c to
1704 * augment the PCM format bit-field for DSD types. The UAC standards
1705 * don't have a designated bit field to denote DSD-capable interfaces,
1706 * hence all hardware that is known to support this format has to be
1709 u64
snd_usb_interface_dsd_format_quirks(struct snd_usb_audio
*chip
,
1710 struct audioformat
*fp
,
1711 unsigned int sample_bytes
)
1713 struct usb_interface
*iface
;
1715 /* Playback Designs */
1716 if (USB_ID_VENDOR(chip
->usb_id
) == 0x23ba &&
1717 USB_ID_PRODUCT(chip
->usb_id
) < 0x0110) {
1718 switch (fp
->altsetting
) {
1721 return SNDRV_PCM_FMTBIT_DSD_U16_LE
;
1723 fp
->dsd_bitrev
= true;
1724 return SNDRV_PCM_FMTBIT_DSD_U8
;
1726 fp
->dsd_bitrev
= true;
1727 return SNDRV_PCM_FMTBIT_DSD_U16_LE
;
1731 /* XMOS based USB DACs */
1732 switch (chip
->usb_id
) {
1733 case USB_ID(0x1511, 0x0037): /* AURALiC VEGA */
1734 case USB_ID(0x2522, 0x0012): /* LH Labs VI DAC Infinity */
1735 case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
1736 if (fp
->altsetting
== 2)
1737 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1740 case USB_ID(0x0d8c, 0x0316): /* Hegel HD12 DSD */
1741 case USB_ID(0x10cb, 0x0103): /* The Bit Opus #3; with fp->dsd_raw */
1742 case USB_ID(0x16d0, 0x06b2): /* NuPrime DAC-10 */
1743 case USB_ID(0x16d0, 0x09dd): /* Encore mDSD */
1744 case USB_ID(0x16d0, 0x0733): /* Furutech ADL Stratos */
1745 case USB_ID(0x16d0, 0x09db): /* NuPrime Audio DAC-9 */
1746 case USB_ID(0x1db5, 0x0003): /* Bryston BDA3 */
1747 case USB_ID(0x22e1, 0xca01): /* HDTA Serenade DSD */
1748 case USB_ID(0x249c, 0x9326): /* M2Tech Young MkIII */
1749 case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
1750 case USB_ID(0x2622, 0x0041): /* Audiolab M-DAC+ */
1751 case USB_ID(0x27f7, 0x3002): /* W4S DAC-2v2SE */
1752 case USB_ID(0x29a2, 0x0086): /* Mutec MC3+ USB */
1753 case USB_ID(0x6b42, 0x0042): /* MSB Technology */
1754 if (fp
->altsetting
== 3)
1755 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1758 /* Amanero Combo384 USB based DACs with native DSD support */
1759 case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
1760 case USB_ID(0x2ab6, 0x0004): /* T+A DAC8DSD-V2.0, MP1000E-V2.0, MP2000R-V2.0, MP2500R-V2.0, MP3100HV-V2.0 */
1761 case USB_ID(0x2ab6, 0x0005): /* T+A USB HD Audio 1 */
1762 case USB_ID(0x2ab6, 0x0006): /* T+A USB HD Audio 2 */
1763 if (fp
->altsetting
== 2) {
1764 switch (le16_to_cpu(chip
->dev
->descriptor
.bcdDevice
)) {
1766 return SNDRV_PCM_FMTBIT_DSD_U32_LE
;
1769 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1775 case USB_ID(0x16d0, 0x0a23):
1776 if (fp
->altsetting
== 2)
1777 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1784 /* ITF-USB DSD based DACs */
1785 if (is_itf_usb_dsd_dac(chip
->usb_id
)) {
1786 iface
= usb_ifnum_to_if(chip
->dev
, fp
->iface
);
1788 /* Altsetting 2 support native DSD if the num of altsets is
1790 * Altsetting 3 support native DSD if the num of altsets is
1793 if (fp
->altsetting
== iface
->num_altsetting
- 1)
1794 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1797 /* Mostly generic method to detect many DSD-capable implementations -
1798 * from XMOS/Thesycon
1800 switch (USB_ID_VENDOR(chip
->usb_id
)) {
1801 case 0x152a: /* Thesycon devices */
1802 case 0x20b1: /* XMOS based devices */
1803 case 0x22d9: /* Oppo */
1804 case 0x23ba: /* Playback Designs */
1805 case 0x25ce: /* Mytek devices */
1806 case 0x278b: /* Rotel? */
1807 case 0x292b: /* Gustard/Ess based devices */
1808 case 0x2972: /* FiiO devices */
1809 case 0x2ab6: /* T+A devices */
1810 case 0x3353: /* Khadas devices */
1811 case 0x3842: /* EVGA */
1812 case 0xc502: /* HiBy devices */
1814 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1824 void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio
*chip
,
1825 struct audioformat
*fp
,
1828 switch (chip
->usb_id
) {
1829 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
1830 /* Optoplay sets the sample rate attribute although
1831 * it seems not supporting it in fact.
1833 fp
->attributes
&= ~UAC_EP_CS_ATTR_SAMPLE_RATE
;
1835 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
1836 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1837 /* doesn't set the sample rate attribute, but supports it */
1838 fp
->attributes
|= UAC_EP_CS_ATTR_SAMPLE_RATE
;
1840 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
1841 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1842 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
1843 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
1844 an older model 77d:223) */
1846 * plantronics headset and Griffin iMic have set adaptive-in
1847 * although it's really not...
1849 fp
->ep_attr
&= ~USB_ENDPOINT_SYNCTYPE
;
1850 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1851 fp
->ep_attr
|= USB_ENDPOINT_SYNC_ADAPTIVE
;
1853 fp
->ep_attr
|= USB_ENDPOINT_SYNC_SYNC
;
1855 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook IIc */
1857 * MaxPacketsOnly attribute is erroneously set in endpoint
1858 * descriptors. As a result this card produces noise with
1859 * all sample rates other than 96 kHz.
1861 fp
->attributes
&= ~UAC_EP_CS_ATTR_FILL_MAX
;
1867 * registration quirk:
1868 * the registration is skipped if a device matches with the given ID,
1869 * unless the interface reaches to the defined one. This is for delaying
1870 * the registration until the last known interface, so that the card and
1871 * devices appear at the same time.
1874 struct registration_quirk
{
1875 unsigned int usb_id
; /* composed via USB_ID() */
1876 unsigned int interface
; /* the interface to trigger register */
1879 #define REG_QUIRK_ENTRY(vendor, product, iface) \
1880 { .usb_id = USB_ID(vendor, product), .interface = (iface) }
1882 static const struct registration_quirk registration_quirks
[] = {
1883 REG_QUIRK_ENTRY(0x0951, 0x16d8, 2), /* Kingston HyperX AMP */
1884 REG_QUIRK_ENTRY(0x0951, 0x16ed, 2), /* Kingston HyperX Cloud Alpha S */
1885 REG_QUIRK_ENTRY(0x0951, 0x16ea, 2), /* Kingston HyperX Cloud Flight S */
1886 { 0 } /* terminator */
1889 /* return true if skipping registration */
1890 bool snd_usb_registration_quirk(struct snd_usb_audio
*chip
, int iface
)
1892 const struct registration_quirk
*q
;
1894 for (q
= registration_quirks
; q
->usb_id
; q
++)
1895 if (chip
->usb_id
== q
->usb_id
)
1896 return iface
!= q
->interface
;
1898 /* Register as normal */