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 err
= usb_driver_claim_interface(driver
, iface
,
60 USB_AUDIO_IFACE_UNUSED
);
69 static int ignore_interface_quirk(struct snd_usb_audio
*chip
,
70 struct usb_interface
*iface
,
71 struct usb_driver
*driver
,
72 const struct snd_usb_audio_quirk
*quirk
)
79 * Allow alignment on audio sub-slot (channel samples) rather than
80 * on audio slots (audio frames)
82 static int create_align_transfer_quirk(struct snd_usb_audio
*chip
,
83 struct usb_interface
*iface
,
84 struct usb_driver
*driver
,
85 const struct snd_usb_audio_quirk
*quirk
)
88 return 1; /* Continue with creating streams and mixer */
91 static int create_any_midi_quirk(struct snd_usb_audio
*chip
,
92 struct usb_interface
*intf
,
93 struct usb_driver
*driver
,
94 const struct snd_usb_audio_quirk
*quirk
)
96 return snd_usbmidi_create(chip
->card
, intf
, &chip
->midi_list
, quirk
);
100 * create a stream for an interface with proper descriptors
102 static int create_standard_audio_quirk(struct snd_usb_audio
*chip
,
103 struct usb_interface
*iface
,
104 struct usb_driver
*driver
,
105 const struct snd_usb_audio_quirk
*quirk
)
107 struct usb_host_interface
*alts
;
108 struct usb_interface_descriptor
*altsd
;
111 if (chip
->usb_id
== USB_ID(0x1686, 0x00dd)) /* Zoom R16/24 */
112 chip
->tx_length_quirk
= 1;
114 alts
= &iface
->altsetting
[0];
115 altsd
= get_iface_desc(alts
);
116 err
= snd_usb_parse_audio_interface(chip
, altsd
->bInterfaceNumber
);
118 usb_audio_err(chip
, "cannot setup if %d: error %d\n",
119 altsd
->bInterfaceNumber
, err
);
122 /* reset the current interface */
123 usb_set_interface(chip
->dev
, altsd
->bInterfaceNumber
, 0);
128 * create a stream for an endpoint/altsetting without proper descriptors
130 static int create_fixed_stream_quirk(struct snd_usb_audio
*chip
,
131 struct usb_interface
*iface
,
132 struct usb_driver
*driver
,
133 const struct snd_usb_audio_quirk
*quirk
)
135 struct audioformat
*fp
;
136 struct usb_host_interface
*alts
;
137 struct usb_interface_descriptor
*altsd
;
139 unsigned *rate_table
= NULL
;
141 fp
= kmemdup(quirk
->data
, sizeof(*fp
), GFP_KERNEL
);
145 INIT_LIST_HEAD(&fp
->list
);
146 if (fp
->nr_rates
> MAX_NR_RATES
) {
150 if (fp
->nr_rates
> 0) {
151 rate_table
= kmemdup(fp
->rate_table
,
152 sizeof(int) * fp
->nr_rates
, GFP_KERNEL
);
157 fp
->rate_table
= rate_table
;
160 stream
= (fp
->endpoint
& USB_DIR_IN
)
161 ? SNDRV_PCM_STREAM_CAPTURE
: SNDRV_PCM_STREAM_PLAYBACK
;
162 err
= snd_usb_add_audio_stream(chip
, stream
, fp
);
165 if (fp
->iface
!= get_iface_desc(&iface
->altsetting
[0])->bInterfaceNumber
||
166 fp
->altset_idx
>= iface
->num_altsetting
) {
170 alts
= &iface
->altsetting
[fp
->altset_idx
];
171 altsd
= get_iface_desc(alts
);
172 if (altsd
->bNumEndpoints
< 1) {
177 fp
->protocol
= altsd
->bInterfaceProtocol
;
179 if (fp
->datainterval
== 0)
180 fp
->datainterval
= snd_usb_parse_datainterval(chip
, alts
);
181 if (fp
->maxpacksize
== 0)
182 fp
->maxpacksize
= le16_to_cpu(get_endpoint(alts
, 0)->wMaxPacketSize
);
183 usb_set_interface(chip
->dev
, fp
->iface
, 0);
184 snd_usb_init_pitch(chip
, fp
->iface
, alts
, fp
);
185 snd_usb_init_sample_rate(chip
, fp
->iface
, alts
, fp
, fp
->rate_max
);
189 list_del(&fp
->list
); /* unlink for avoiding double-free */
195 static int create_auto_pcm_quirk(struct snd_usb_audio
*chip
,
196 struct usb_interface
*iface
,
197 struct usb_driver
*driver
)
199 struct usb_host_interface
*alts
;
200 struct usb_interface_descriptor
*altsd
;
201 struct usb_endpoint_descriptor
*epd
;
202 struct uac1_as_header_descriptor
*ashd
;
203 struct uac_format_type_i_discrete_descriptor
*fmtd
;
206 * Most Roland/Yamaha audio streaming interfaces have more or less
207 * standard descriptors, but older devices might lack descriptors, and
208 * future ones might change, so ensure that we fail silently if the
209 * interface doesn't look exactly right.
212 /* must have a non-zero altsetting for streaming */
213 if (iface
->num_altsetting
< 2)
215 alts
= &iface
->altsetting
[1];
216 altsd
= get_iface_desc(alts
);
218 /* must have an isochronous endpoint for streaming */
219 if (altsd
->bNumEndpoints
< 1)
221 epd
= get_endpoint(alts
, 0);
222 if (!usb_endpoint_xfer_isoc(epd
))
225 /* must have format descriptors */
226 ashd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
, NULL
,
228 fmtd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
, NULL
,
230 if (!ashd
|| ashd
->bLength
< 7 ||
231 !fmtd
|| fmtd
->bLength
< 8)
234 return create_standard_audio_quirk(chip
, iface
, driver
, NULL
);
237 static int create_yamaha_midi_quirk(struct snd_usb_audio
*chip
,
238 struct usb_interface
*iface
,
239 struct usb_driver
*driver
,
240 struct usb_host_interface
*alts
)
242 static const struct snd_usb_audio_quirk yamaha_midi_quirk
= {
243 .type
= QUIRK_MIDI_YAMAHA
245 struct usb_midi_in_jack_descriptor
*injd
;
246 struct usb_midi_out_jack_descriptor
*outjd
;
248 /* must have some valid jack descriptors */
249 injd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
,
250 NULL
, USB_MS_MIDI_IN_JACK
);
251 outjd
= snd_usb_find_csint_desc(alts
->extra
, alts
->extralen
,
252 NULL
, USB_MS_MIDI_OUT_JACK
);
255 if ((injd
&& !snd_usb_validate_midi_desc(injd
)) ||
256 (outjd
&& !snd_usb_validate_midi_desc(outjd
)))
258 if (injd
&& (injd
->bLength
< 5 ||
259 (injd
->bJackType
!= USB_MS_EMBEDDED
&&
260 injd
->bJackType
!= USB_MS_EXTERNAL
)))
262 if (outjd
&& (outjd
->bLength
< 6 ||
263 (outjd
->bJackType
!= USB_MS_EMBEDDED
&&
264 outjd
->bJackType
!= USB_MS_EXTERNAL
)))
266 return create_any_midi_quirk(chip
, iface
, driver
, &yamaha_midi_quirk
);
269 static int create_roland_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 roland_midi_quirk
= {
275 .type
= QUIRK_MIDI_ROLAND
277 u8
*roland_desc
= NULL
;
279 /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
281 roland_desc
= snd_usb_find_csint_desc(alts
->extra
,
286 if (roland_desc
[0] < 6 || roland_desc
[3] != 2)
288 return create_any_midi_quirk(chip
, iface
, driver
,
293 static int create_std_midi_quirk(struct snd_usb_audio
*chip
,
294 struct usb_interface
*iface
,
295 struct usb_driver
*driver
,
296 struct usb_host_interface
*alts
)
298 struct usb_ms_header_descriptor
*mshd
;
299 struct usb_ms_endpoint_descriptor
*msepd
;
301 /* must have the MIDIStreaming interface header descriptor*/
302 mshd
= (struct usb_ms_header_descriptor
*)alts
->extra
;
303 if (alts
->extralen
< 7 ||
305 mshd
->bDescriptorType
!= USB_DT_CS_INTERFACE
||
306 mshd
->bDescriptorSubtype
!= USB_MS_HEADER
)
308 /* must have the MIDIStreaming endpoint descriptor*/
309 msepd
= (struct usb_ms_endpoint_descriptor
*)alts
->endpoint
[0].extra
;
310 if (alts
->endpoint
[0].extralen
< 4 ||
311 msepd
->bLength
< 4 ||
312 msepd
->bDescriptorType
!= USB_DT_CS_ENDPOINT
||
313 msepd
->bDescriptorSubtype
!= UAC_MS_GENERAL
||
314 msepd
->bNumEmbMIDIJack
< 1 ||
315 msepd
->bNumEmbMIDIJack
> 16)
318 return create_any_midi_quirk(chip
, iface
, driver
, NULL
);
321 static int create_auto_midi_quirk(struct snd_usb_audio
*chip
,
322 struct usb_interface
*iface
,
323 struct usb_driver
*driver
)
325 struct usb_host_interface
*alts
;
326 struct usb_interface_descriptor
*altsd
;
327 struct usb_endpoint_descriptor
*epd
;
330 alts
= &iface
->altsetting
[0];
331 altsd
= get_iface_desc(alts
);
333 /* must have at least one bulk/interrupt endpoint for streaming */
334 if (altsd
->bNumEndpoints
< 1)
336 epd
= get_endpoint(alts
, 0);
337 if (!usb_endpoint_xfer_bulk(epd
) &&
338 !usb_endpoint_xfer_int(epd
))
341 switch (USB_ID_VENDOR(chip
->usb_id
)) {
342 case 0x0499: /* Yamaha */
343 err
= create_yamaha_midi_quirk(chip
, iface
, driver
, alts
);
347 case 0x0582: /* Roland */
348 err
= create_roland_midi_quirk(chip
, iface
, driver
, alts
);
354 return create_std_midi_quirk(chip
, iface
, driver
, alts
);
357 static int create_autodetect_quirk(struct snd_usb_audio
*chip
,
358 struct usb_interface
*iface
,
359 struct usb_driver
*driver
)
363 err
= create_auto_pcm_quirk(chip
, iface
, driver
);
365 err
= create_auto_midi_quirk(chip
, iface
, driver
);
369 static int create_autodetect_quirks(struct snd_usb_audio
*chip
,
370 struct usb_interface
*iface
,
371 struct usb_driver
*driver
,
372 const struct snd_usb_audio_quirk
*quirk
)
374 int probed_ifnum
= get_iface_desc(iface
->altsetting
)->bInterfaceNumber
;
375 int ifcount
, ifnum
, err
;
377 err
= create_autodetect_quirk(chip
, iface
, driver
);
382 * ALSA PCM playback/capture devices cannot be registered in two steps,
383 * so we have to claim the other corresponding interface here.
385 ifcount
= chip
->dev
->actconfig
->desc
.bNumInterfaces
;
386 for (ifnum
= 0; ifnum
< ifcount
; ifnum
++) {
387 if (ifnum
== probed_ifnum
|| quirk
->ifnum
>= 0)
389 iface
= usb_ifnum_to_if(chip
->dev
, ifnum
);
391 usb_interface_claimed(iface
) ||
392 get_iface_desc(iface
->altsetting
)->bInterfaceClass
!=
393 USB_CLASS_VENDOR_SPEC
)
396 err
= create_autodetect_quirk(chip
, iface
, driver
);
398 err
= usb_driver_claim_interface(driver
, iface
,
399 USB_AUDIO_IFACE_UNUSED
);
409 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
410 * The only way to detect the sample rate is by looking at wMaxPacketSize.
412 static int create_uaxx_quirk(struct snd_usb_audio
*chip
,
413 struct usb_interface
*iface
,
414 struct usb_driver
*driver
,
415 const struct snd_usb_audio_quirk
*quirk
)
417 static const struct audioformat ua_format
= {
418 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
420 .fmt_type
= UAC_FORMAT_TYPE_I
,
423 .rates
= SNDRV_PCM_RATE_CONTINUOUS
,
425 struct usb_host_interface
*alts
;
426 struct usb_interface_descriptor
*altsd
;
427 struct audioformat
*fp
;
430 /* both PCM and MIDI interfaces have 2 or more altsettings */
431 if (iface
->num_altsetting
< 2)
433 alts
= &iface
->altsetting
[1];
434 altsd
= get_iface_desc(alts
);
436 if (altsd
->bNumEndpoints
== 2) {
437 static const struct snd_usb_midi_endpoint_info ua700_ep
= {
438 .out_cables
= 0x0003,
441 static const struct snd_usb_audio_quirk ua700_quirk
= {
442 .type
= QUIRK_MIDI_FIXED_ENDPOINT
,
445 static const struct snd_usb_midi_endpoint_info uaxx_ep
= {
446 .out_cables
= 0x0001,
449 static const struct snd_usb_audio_quirk uaxx_quirk
= {
450 .type
= QUIRK_MIDI_FIXED_ENDPOINT
,
453 const struct snd_usb_audio_quirk
*quirk
=
454 chip
->usb_id
== USB_ID(0x0582, 0x002b)
455 ? &ua700_quirk
: &uaxx_quirk
;
456 return __snd_usbmidi_create(chip
->card
, iface
,
457 &chip
->midi_list
, quirk
,
461 if (altsd
->bNumEndpoints
!= 1)
464 fp
= kmemdup(&ua_format
, sizeof(*fp
), GFP_KERNEL
);
468 fp
->iface
= altsd
->bInterfaceNumber
;
469 fp
->endpoint
= get_endpoint(alts
, 0)->bEndpointAddress
;
470 fp
->ep_attr
= get_endpoint(alts
, 0)->bmAttributes
;
471 fp
->datainterval
= 0;
472 fp
->maxpacksize
= le16_to_cpu(get_endpoint(alts
, 0)->wMaxPacketSize
);
473 INIT_LIST_HEAD(&fp
->list
);
475 switch (fp
->maxpacksize
) {
477 fp
->rate_max
= fp
->rate_min
= 44100;
481 fp
->rate_max
= fp
->rate_min
= 48000;
485 fp
->rate_max
= fp
->rate_min
= 96000;
488 usb_audio_err(chip
, "unknown sample rate\n");
493 stream
= (fp
->endpoint
& USB_DIR_IN
)
494 ? SNDRV_PCM_STREAM_CAPTURE
: SNDRV_PCM_STREAM_PLAYBACK
;
495 err
= snd_usb_add_audio_stream(chip
, stream
, fp
);
497 list_del(&fp
->list
); /* unlink for avoiding double-free */
501 usb_set_interface(chip
->dev
, fp
->iface
, 0);
506 * Create a standard mixer for the specified interface.
508 static int create_standard_mixer_quirk(struct snd_usb_audio
*chip
,
509 struct usb_interface
*iface
,
510 struct usb_driver
*driver
,
511 const struct snd_usb_audio_quirk
*quirk
)
513 if (quirk
->ifnum
< 0)
516 return snd_usb_create_mixer(chip
, quirk
->ifnum
, 0);
520 static int setup_fmt_after_resume_quirk(struct snd_usb_audio
*chip
,
521 struct usb_interface
*iface
,
522 struct usb_driver
*driver
,
523 const struct snd_usb_audio_quirk
*quirk
)
525 chip
->setup_fmt_after_resume_quirk
= 1;
526 return 1; /* Continue with creating streams and mixer */
530 * audio-interface quirks
532 * returns zero if no standard audio/MIDI parsing is needed.
533 * returns a positive value if standard audio/midi interfaces are parsed
535 * returns a negative value at error.
537 int snd_usb_create_quirk(struct snd_usb_audio
*chip
,
538 struct usb_interface
*iface
,
539 struct usb_driver
*driver
,
540 const struct snd_usb_audio_quirk
*quirk
)
542 typedef int (*quirk_func_t
)(struct snd_usb_audio
*,
543 struct usb_interface
*,
545 const struct snd_usb_audio_quirk
*);
546 static const quirk_func_t quirk_funcs
[] = {
547 [QUIRK_IGNORE_INTERFACE
] = ignore_interface_quirk
,
548 [QUIRK_COMPOSITE
] = create_composite_quirk
,
549 [QUIRK_AUTODETECT
] = create_autodetect_quirks
,
550 [QUIRK_MIDI_STANDARD_INTERFACE
] = create_any_midi_quirk
,
551 [QUIRK_MIDI_FIXED_ENDPOINT
] = create_any_midi_quirk
,
552 [QUIRK_MIDI_YAMAHA
] = create_any_midi_quirk
,
553 [QUIRK_MIDI_ROLAND
] = create_any_midi_quirk
,
554 [QUIRK_MIDI_MIDIMAN
] = create_any_midi_quirk
,
555 [QUIRK_MIDI_NOVATION
] = create_any_midi_quirk
,
556 [QUIRK_MIDI_RAW_BYTES
] = create_any_midi_quirk
,
557 [QUIRK_MIDI_EMAGIC
] = create_any_midi_quirk
,
558 [QUIRK_MIDI_CME
] = create_any_midi_quirk
,
559 [QUIRK_MIDI_AKAI
] = create_any_midi_quirk
,
560 [QUIRK_MIDI_FTDI
] = create_any_midi_quirk
,
561 [QUIRK_MIDI_CH345
] = create_any_midi_quirk
,
562 [QUIRK_AUDIO_STANDARD_INTERFACE
] = create_standard_audio_quirk
,
563 [QUIRK_AUDIO_FIXED_ENDPOINT
] = create_fixed_stream_quirk
,
564 [QUIRK_AUDIO_EDIROL_UAXX
] = create_uaxx_quirk
,
565 [QUIRK_AUDIO_ALIGN_TRANSFER
] = create_align_transfer_quirk
,
566 [QUIRK_AUDIO_STANDARD_MIXER
] = create_standard_mixer_quirk
,
567 [QUIRK_SETUP_FMT_AFTER_RESUME
] = setup_fmt_after_resume_quirk
,
570 if (quirk
->type
< QUIRK_TYPE_COUNT
) {
571 return quirk_funcs
[quirk
->type
](chip
, iface
, driver
, quirk
);
573 usb_audio_err(chip
, "invalid quirk type %d\n", quirk
->type
);
582 #define EXTIGY_FIRMWARE_SIZE_OLD 794
583 #define EXTIGY_FIRMWARE_SIZE_NEW 483
585 static int snd_usb_extigy_boot_quirk(struct usb_device
*dev
, struct usb_interface
*intf
)
587 struct usb_host_config
*config
= dev
->actconfig
;
590 if (le16_to_cpu(get_cfg_desc(config
)->wTotalLength
) == EXTIGY_FIRMWARE_SIZE_OLD
||
591 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
) == EXTIGY_FIRMWARE_SIZE_NEW
) {
592 dev_dbg(&dev
->dev
, "sending Extigy boot sequence...\n");
593 /* Send message to force it to reconnect with full interface. */
594 err
= snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
,0),
595 0x10, 0x43, 0x0001, 0x000a, NULL
, 0);
597 dev_dbg(&dev
->dev
, "error sending boot message: %d\n", err
);
598 err
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0,
599 &dev
->descriptor
, sizeof(dev
->descriptor
));
600 config
= dev
->actconfig
;
602 dev_dbg(&dev
->dev
, "error usb_get_descriptor: %d\n", err
);
603 err
= usb_reset_configuration(dev
);
605 dev_dbg(&dev
->dev
, "error usb_reset_configuration: %d\n", err
);
606 dev_dbg(&dev
->dev
, "extigy_boot: new boot length = %d\n",
607 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
));
608 return -ENODEV
; /* quit this anyway */
613 static int snd_usb_audigy2nx_boot_quirk(struct usb_device
*dev
)
617 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0), 0x2a,
618 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
621 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), 0x29,
622 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
629 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device
*dev
)
633 if (dev
->actconfig
->desc
.bConfigurationValue
== 1) {
635 "Fast Track Pro switching to config #2\n");
636 /* This function has to be available by the usb core module.
637 * if it is not avialable the boot quirk has to be left out
638 * and the configuration has to be set by udev or hotplug
641 err
= usb_driver_set_configuration(dev
, 2);
644 "error usb_driver_set_configuration: %d\n",
646 /* Always return an error, so that we stop creating a device
647 that will just be destroyed and recreated with a new
651 dev_info(&dev
->dev
, "Fast Track Pro config OK\n");
657 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
658 * documented in the device's data sheet.
660 static int snd_usb_cm106_write_int_reg(struct usb_device
*dev
, int reg
, u16 value
)
664 buf
[1] = value
& 0xff;
665 buf
[2] = (value
>> 8) & 0xff;
667 return snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), USB_REQ_SET_CONFIGURATION
,
668 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
,
672 static int snd_usb_cm106_boot_quirk(struct usb_device
*dev
)
675 * Enable line-out driver mode, set headphone source to front
676 * channels, enable stereo mic.
678 return snd_usb_cm106_write_int_reg(dev
, 2, 0x8004);
682 * CM6206 registers from the CM6206 datasheet rev 2.1
684 #define CM6206_REG0_DMA_MASTER BIT(15)
685 #define CM6206_REG0_SPDIFO_RATE_48K (2 << 12)
686 #define CM6206_REG0_SPDIFO_RATE_96K (7 << 12)
687 /* Bit 4 thru 11 is the S/PDIF category code */
688 #define CM6206_REG0_SPDIFO_CAT_CODE_GENERAL (0 << 4)
689 #define CM6206_REG0_SPDIFO_EMPHASIS_CD BIT(3)
690 #define CM6206_REG0_SPDIFO_COPYRIGHT_NA BIT(2)
691 #define CM6206_REG0_SPDIFO_NON_AUDIO BIT(1)
692 #define CM6206_REG0_SPDIFO_PRO_FORMAT BIT(0)
694 #define CM6206_REG1_TEST_SEL_CLK BIT(14)
695 #define CM6206_REG1_PLLBIN_EN BIT(13)
696 #define CM6206_REG1_SOFT_MUTE_EN BIT(12)
697 #define CM6206_REG1_GPIO4_OUT BIT(11)
698 #define CM6206_REG1_GPIO4_OE BIT(10)
699 #define CM6206_REG1_GPIO3_OUT BIT(9)
700 #define CM6206_REG1_GPIO3_OE BIT(8)
701 #define CM6206_REG1_GPIO2_OUT BIT(7)
702 #define CM6206_REG1_GPIO2_OE BIT(6)
703 #define CM6206_REG1_GPIO1_OUT BIT(5)
704 #define CM6206_REG1_GPIO1_OE BIT(4)
705 #define CM6206_REG1_SPDIFO_INVALID BIT(3)
706 #define CM6206_REG1_SPDIF_LOOP_EN BIT(2)
707 #define CM6206_REG1_SPDIFO_DIS BIT(1)
708 #define CM6206_REG1_SPDIFI_MIX BIT(0)
710 #define CM6206_REG2_DRIVER_ON BIT(15)
711 #define CM6206_REG2_HEADP_SEL_SIDE_CHANNELS (0 << 13)
712 #define CM6206_REG2_HEADP_SEL_SURROUND_CHANNELS (1 << 13)
713 #define CM6206_REG2_HEADP_SEL_CENTER_SUBW (2 << 13)
714 #define CM6206_REG2_HEADP_SEL_FRONT_CHANNELS (3 << 13)
715 #define CM6206_REG2_MUTE_HEADPHONE_RIGHT BIT(12)
716 #define CM6206_REG2_MUTE_HEADPHONE_LEFT BIT(11)
717 #define CM6206_REG2_MUTE_REAR_SURROUND_RIGHT BIT(10)
718 #define CM6206_REG2_MUTE_REAR_SURROUND_LEFT BIT(9)
719 #define CM6206_REG2_MUTE_SIDE_SURROUND_RIGHT BIT(8)
720 #define CM6206_REG2_MUTE_SIDE_SURROUND_LEFT BIT(7)
721 #define CM6206_REG2_MUTE_SUBWOOFER BIT(6)
722 #define CM6206_REG2_MUTE_CENTER BIT(5)
723 #define CM6206_REG2_MUTE_RIGHT_FRONT BIT(3)
724 #define CM6206_REG2_MUTE_LEFT_FRONT BIT(3)
725 #define CM6206_REG2_EN_BTL BIT(2)
726 #define CM6206_REG2_MCUCLKSEL_1_5_MHZ (0)
727 #define CM6206_REG2_MCUCLKSEL_3_MHZ (1)
728 #define CM6206_REG2_MCUCLKSEL_6_MHZ (2)
729 #define CM6206_REG2_MCUCLKSEL_12_MHZ (3)
731 /* Bit 11..13 sets the sensitivity to FLY tuner volume control VP/VD signal */
732 #define CM6206_REG3_FLYSPEED_DEFAULT (2 << 11)
733 #define CM6206_REG3_VRAP25EN BIT(10)
734 #define CM6206_REG3_MSEL1 BIT(9)
735 #define CM6206_REG3_SPDIFI_RATE_44_1K BIT(0 << 7)
736 #define CM6206_REG3_SPDIFI_RATE_48K BIT(2 << 7)
737 #define CM6206_REG3_SPDIFI_RATE_32K BIT(3 << 7)
738 #define CM6206_REG3_PINSEL BIT(6)
739 #define CM6206_REG3_FOE BIT(5)
740 #define CM6206_REG3_ROE BIT(4)
741 #define CM6206_REG3_CBOE BIT(3)
742 #define CM6206_REG3_LOSE BIT(2)
743 #define CM6206_REG3_HPOE BIT(1)
744 #define CM6206_REG3_SPDIFI_CANREC BIT(0)
746 #define CM6206_REG5_DA_RSTN BIT(13)
747 #define CM6206_REG5_AD_RSTN BIT(12)
748 #define CM6206_REG5_SPDIFO_AD2SPDO BIT(12)
749 #define CM6206_REG5_SPDIFO_SEL_FRONT (0 << 9)
750 #define CM6206_REG5_SPDIFO_SEL_SIDE_SUR (1 << 9)
751 #define CM6206_REG5_SPDIFO_SEL_CEN_LFE (2 << 9)
752 #define CM6206_REG5_SPDIFO_SEL_REAR_SUR (3 << 9)
753 #define CM6206_REG5_CODECM BIT(8)
754 #define CM6206_REG5_EN_HPF BIT(7)
755 #define CM6206_REG5_T_SEL_DSDA4 BIT(6)
756 #define CM6206_REG5_T_SEL_DSDA3 BIT(5)
757 #define CM6206_REG5_T_SEL_DSDA2 BIT(4)
758 #define CM6206_REG5_T_SEL_DSDA1 BIT(3)
759 #define CM6206_REG5_T_SEL_DSDAD_NORMAL 0
760 #define CM6206_REG5_T_SEL_DSDAD_FRONT 4
761 #define CM6206_REG5_T_SEL_DSDAD_S_SURROUND 5
762 #define CM6206_REG5_T_SEL_DSDAD_CEN_LFE 6
763 #define CM6206_REG5_T_SEL_DSDAD_R_SURROUND 7
765 static int snd_usb_cm6206_boot_quirk(struct usb_device
*dev
)
770 * Values here are chosen based on sniffing USB traffic
773 * REG0: DAC is master, sample rate 48kHz, no copyright
775 CM6206_REG0_SPDIFO_RATE_48K
|
776 CM6206_REG0_SPDIFO_COPYRIGHT_NA
,
778 * REG1: PLL binary search enable, soft mute enable.
780 CM6206_REG1_PLLBIN_EN
|
781 CM6206_REG1_SOFT_MUTE_EN
,
783 * REG2: enable output drivers,
784 * select front channels to the headphone output,
785 * then mute the headphone channels, run the MCU
788 CM6206_REG2_DRIVER_ON
|
789 CM6206_REG2_HEADP_SEL_FRONT_CHANNELS
|
790 CM6206_REG2_MUTE_HEADPHONE_RIGHT
|
791 CM6206_REG2_MUTE_HEADPHONE_LEFT
,
793 * REG3: default flyspeed, set 2.5V mic bias
794 * enable all line out ports and enable SPDIF
796 CM6206_REG3_FLYSPEED_DEFAULT
|
797 CM6206_REG3_VRAP25EN
|
803 CM6206_REG3_SPDIFI_CANREC
,
804 /* REG4 is just a bunch of GPIO lines */
806 /* REG5: de-assert AD/DA reset signals */
807 CM6206_REG5_DA_RSTN
|
808 CM6206_REG5_AD_RSTN
};
810 for (reg
= 0; reg
< ARRAY_SIZE(val
); reg
++) {
811 err
= snd_usb_cm106_write_int_reg(dev
, reg
, val
[reg
]);
819 /* quirk for Plantronics GameCom 780 with CM6302 chip */
820 static int snd_usb_gamecon780_boot_quirk(struct usb_device
*dev
)
822 /* set the initial volume and don't change; other values are either
823 * too loud or silent due to firmware bug (bko#65251)
825 u8 buf
[2] = { 0x74, 0xe3 };
826 return snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), UAC_SET_CUR
,
827 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
| USB_DIR_OUT
,
828 UAC_FU_VOLUME
<< 8, 9 << 8, buf
, 2);
832 * Novation Twitch DJ controller
833 * Focusrite Novation Saffire 6 USB audio card
835 static int snd_usb_novation_boot_quirk(struct usb_device
*dev
)
837 /* preemptively set up the device because otherwise the
838 * raw MIDI endpoints are not active */
839 usb_set_interface(dev
, 0, 1);
844 * This call will put the synth in "USB send" mode, i.e it will send MIDI
845 * messages through USB (this is disabled at startup). The synth will
846 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
847 * sign on its LCD. Values here are chosen based on sniffing USB traffic
850 static int snd_usb_accessmusic_boot_quirk(struct usb_device
*dev
)
852 int err
, actual_length
;
853 /* "midi send" enable */
854 static const u8 seq
[] = { 0x4e, 0x73, 0x52, 0x01 };
857 if (snd_usb_pipe_sanity_check(dev
, usb_sndintpipe(dev
, 0x05)))
859 buf
= kmemdup(seq
, ARRAY_SIZE(seq
), GFP_KERNEL
);
862 err
= usb_interrupt_msg(dev
, usb_sndintpipe(dev
, 0x05), buf
,
863 ARRAY_SIZE(seq
), &actual_length
, 1000);
872 * Some sound cards from Native Instruments are in fact compliant to the USB
873 * audio standard of version 2 and other approved USB standards, even though
874 * they come up as vendor-specific device when first connected.
876 * However, they can be told to come up with a new set of descriptors
877 * upon their next enumeration, and the interfaces announced by the new
878 * descriptors will then be handled by the kernel's class drivers. As the
879 * product ID will also change, no further checks are required.
882 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device
*dev
)
886 if (snd_usb_pipe_sanity_check(dev
, usb_sndctrlpipe(dev
, 0)))
888 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
889 0xaf, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
890 1, 0, NULL
, 0, 1000);
895 usb_reset_device(dev
);
897 /* return -EAGAIN, so the creation of an audio interface for this
898 * temporary device is aborted. The device will reconnect with a
903 static void mbox2_setup_48_24_magic(struct usb_device
*dev
)
908 /* Choose 48000Hz permanently */
913 /* Send the magic! */
914 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
915 0x01, 0x22, 0x0100, 0x0085, &temp
, 0x0003);
916 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
917 0x81, 0xa2, 0x0100, 0x0085, &srate
, 0x0003);
918 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
919 0x81, 0xa2, 0x0100, 0x0086, &srate
, 0x0003);
920 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
921 0x81, 0xa2, 0x0100, 0x0003, &srate
, 0x0003);
925 /* Digidesign Mbox 2 needs to load firmware onboard
926 * and driver must wait a few seconds for initialisation.
929 #define MBOX2_FIRMWARE_SIZE 646
930 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
931 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
933 static int snd_usb_mbox2_boot_quirk(struct usb_device
*dev
)
935 struct usb_host_config
*config
= dev
->actconfig
;
937 u8 bootresponse
[0x12];
941 fwsize
= le16_to_cpu(get_cfg_desc(config
)->wTotalLength
);
943 if (fwsize
!= MBOX2_FIRMWARE_SIZE
) {
944 dev_err(&dev
->dev
, "Invalid firmware size=%d.\n", fwsize
);
948 dev_dbg(&dev
->dev
, "Sending Digidesign Mbox 2 boot sequence...\n");
951 bootresponse
[0] = MBOX2_BOOT_LOADING
;
952 while ((bootresponse
[0] == MBOX2_BOOT_LOADING
) && (count
< 10)) {
953 msleep(500); /* 0.5 second delay */
954 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
955 /* Control magic - load onboard firmware */
956 0x85, 0xc0, 0x0001, 0x0000, &bootresponse
, 0x0012);
957 if (bootresponse
[0] == MBOX2_BOOT_READY
)
959 dev_dbg(&dev
->dev
, "device not ready, resending boot sequence...\n");
963 if (bootresponse
[0] != MBOX2_BOOT_READY
) {
964 dev_err(&dev
->dev
, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse
[0]);
968 dev_dbg(&dev
->dev
, "device initialised!\n");
970 err
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0,
971 &dev
->descriptor
, sizeof(dev
->descriptor
));
972 config
= dev
->actconfig
;
974 dev_dbg(&dev
->dev
, "error usb_get_descriptor: %d\n", err
);
976 err
= usb_reset_configuration(dev
);
978 dev_dbg(&dev
->dev
, "error usb_reset_configuration: %d\n", err
);
979 dev_dbg(&dev
->dev
, "mbox2_boot: new boot length = %d\n",
980 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
));
982 mbox2_setup_48_24_magic(dev
);
984 dev_info(&dev
->dev
, "Digidesign Mbox 2: 24bit 48kHz");
986 return 0; /* Successful boot */
989 static int snd_usb_axefx3_boot_quirk(struct usb_device
*dev
)
993 dev_dbg(&dev
->dev
, "Waiting for Axe-Fx III to boot up...\n");
995 if (snd_usb_pipe_sanity_check(dev
, usb_sndctrlpipe(dev
, 0)))
997 /* If the Axe-Fx III has not fully booted, it will timeout when trying
998 * to enable the audio streaming interface. A more generous timeout is
999 * used here to detect when the Axe-Fx III has finished booting as the
1000 * set interface message will be acked once it has
1002 err
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
1003 USB_REQ_SET_INTERFACE
, USB_RECIP_INTERFACE
,
1004 1, 1, NULL
, 0, 120000);
1007 "failed waiting for Axe-Fx III to boot: %d\n", err
);
1011 dev_dbg(&dev
->dev
, "Axe-Fx III is now ready\n");
1013 err
= usb_set_interface(dev
, 1, 0);
1016 "error stopping Axe-Fx III interface: %d\n", err
);
1022 #define MICROBOOK_BUF_SIZE 128
1024 static int snd_usb_motu_microbookii_communicate(struct usb_device
*dev
, u8
*buf
,
1025 int buf_size
, int *length
)
1027 int err
, actual_length
;
1029 if (snd_usb_pipe_sanity_check(dev
, usb_sndintpipe(dev
, 0x01)))
1031 err
= usb_interrupt_msg(dev
, usb_sndintpipe(dev
, 0x01), buf
, *length
,
1032 &actual_length
, 1000);
1036 print_hex_dump(KERN_DEBUG
, "MicroBookII snd: ", DUMP_PREFIX_NONE
, 16, 1,
1037 buf
, actual_length
, false);
1039 memset(buf
, 0, buf_size
);
1041 if (snd_usb_pipe_sanity_check(dev
, usb_rcvintpipe(dev
, 0x82)))
1043 err
= usb_interrupt_msg(dev
, usb_rcvintpipe(dev
, 0x82), buf
, buf_size
,
1044 &actual_length
, 1000);
1048 print_hex_dump(KERN_DEBUG
, "MicroBookII rcv: ", DUMP_PREFIX_NONE
, 16, 1,
1049 buf
, actual_length
, false);
1051 *length
= actual_length
;
1055 static int snd_usb_motu_microbookii_boot_quirk(struct usb_device
*dev
)
1057 int err
, actual_length
, poll_attempts
= 0;
1058 static const u8 set_samplerate_seq
[] = { 0x00, 0x00, 0x00, 0x00,
1059 0x00, 0x00, 0x0b, 0x14,
1060 0x00, 0x00, 0x00, 0x01 };
1061 static const u8 poll_ready_seq
[] = { 0x00, 0x04, 0x00, 0x00,
1062 0x00, 0x00, 0x0b, 0x18 };
1063 u8
*buf
= kzalloc(MICROBOOK_BUF_SIZE
, GFP_KERNEL
);
1068 dev_info(&dev
->dev
, "Waiting for MOTU Microbook II to boot up...\n");
1070 /* First we tell the device which sample rate to use. */
1071 memcpy(buf
, set_samplerate_seq
, sizeof(set_samplerate_seq
));
1072 actual_length
= sizeof(set_samplerate_seq
);
1073 err
= snd_usb_motu_microbookii_communicate(dev
, buf
, MICROBOOK_BUF_SIZE
,
1078 "failed setting the sample rate for Motu MicroBook II: %d\n",
1083 /* Then we poll every 100 ms until the device informs of its readiness. */
1085 if (++poll_attempts
> 100) {
1087 "failed booting Motu MicroBook II: timeout\n");
1092 memset(buf
, 0, MICROBOOK_BUF_SIZE
);
1093 memcpy(buf
, poll_ready_seq
, sizeof(poll_ready_seq
));
1095 actual_length
= sizeof(poll_ready_seq
);
1096 err
= snd_usb_motu_microbookii_communicate(
1097 dev
, buf
, MICROBOOK_BUF_SIZE
, &actual_length
);
1100 "failed booting Motu MicroBook II: communication error %d\n",
1105 /* the device signals its readiness through a message of the
1107 * XX 06 00 00 00 00 0b 18 00 00 00 01
1108 * If the device is not yet ready to accept audio data, the
1109 * last byte of that sequence is 00.
1111 if (actual_length
== 12 && buf
[actual_length
- 1] == 1)
1117 dev_info(&dev
->dev
, "MOTU MicroBook II ready\n");
1124 static int snd_usb_motu_m_series_boot_quirk(struct usb_device
*dev
)
1128 if (snd_usb_pipe_sanity_check(dev
, usb_sndctrlpipe(dev
, 0)))
1130 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
1131 1, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1132 0x0, 0, NULL
, 0, 1000);
1139 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
1140 1, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1141 0x20, 0, NULL
, 0, 1000);
1152 #define MAUDIO_SET 0x01 /* parse device_setup */
1153 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
1154 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
1155 #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
1156 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
1157 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
1158 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
1159 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
1160 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
1161 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
1162 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
1164 static int quattro_skip_setting_quirk(struct snd_usb_audio
*chip
,
1165 int iface
, int altno
)
1167 /* Reset ALL ifaces to 0 altsetting.
1168 * Call it for every possible altsetting of every interface.
1170 usb_set_interface(chip
->dev
, iface
, 0);
1171 if (chip
->setup
& MAUDIO_SET
) {
1172 if (chip
->setup
& MAUDIO_SET_COMPATIBLE
) {
1173 if (iface
!= 1 && iface
!= 2)
1174 return 1; /* skip all interfaces but 1 and 2 */
1177 if (iface
== 1 || iface
== 2)
1178 return 1; /* skip interfaces 1 and 2 */
1179 if ((chip
->setup
& MAUDIO_SET_96K
) && altno
!= 1)
1180 return 1; /* skip this altsetting */
1181 mask
= chip
->setup
& MAUDIO_SET_MASK
;
1182 if (mask
== MAUDIO_SET_24B_48K_DI
&& altno
!= 2)
1183 return 1; /* skip this altsetting */
1184 if (mask
== MAUDIO_SET_24B_48K_NOTDI
&& altno
!= 3)
1185 return 1; /* skip this altsetting */
1186 if (mask
== MAUDIO_SET_16B_48K_NOTDI
&& altno
!= 4)
1187 return 1; /* skip this altsetting */
1191 "using altsetting %d for interface %d config %d\n",
1192 altno
, iface
, chip
->setup
);
1193 return 0; /* keep this altsetting */
1196 static int audiophile_skip_setting_quirk(struct snd_usb_audio
*chip
,
1200 /* Reset ALL ifaces to 0 altsetting.
1201 * Call it for every possible altsetting of every interface.
1203 usb_set_interface(chip
->dev
, iface
, 0);
1205 if (chip
->setup
& MAUDIO_SET
) {
1207 if ((chip
->setup
& MAUDIO_SET_DTS
) && altno
!= 6)
1208 return 1; /* skip this altsetting */
1209 if ((chip
->setup
& MAUDIO_SET_96K
) && altno
!= 1)
1210 return 1; /* skip this altsetting */
1211 mask
= chip
->setup
& MAUDIO_SET_MASK
;
1212 if (mask
== MAUDIO_SET_24B_48K_DI
&& altno
!= 2)
1213 return 1; /* skip this altsetting */
1214 if (mask
== MAUDIO_SET_24B_48K_NOTDI
&& altno
!= 3)
1215 return 1; /* skip this altsetting */
1216 if (mask
== MAUDIO_SET_16B_48K_DI
&& altno
!= 4)
1217 return 1; /* skip this altsetting */
1218 if (mask
== MAUDIO_SET_16B_48K_NOTDI
&& altno
!= 5)
1219 return 1; /* skip this altsetting */
1222 return 0; /* keep this altsetting */
1225 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio
*chip
,
1226 int iface
, int altno
)
1228 /* Reset ALL ifaces to 0 altsetting.
1229 * Call it for every possible altsetting of every interface.
1231 usb_set_interface(chip
->dev
, iface
, 0);
1233 /* possible configuration where both inputs and only one output is
1234 *used is not supported by the current setup
1236 if (chip
->setup
& (MAUDIO_SET
| MAUDIO_SET_24B
)) {
1237 if (chip
->setup
& MAUDIO_SET_96K
) {
1238 if (altno
!= 3 && altno
!= 6)
1240 } else if (chip
->setup
& MAUDIO_SET_DI
) {
1242 return 1; /* no analog input */
1243 if (altno
!= 2 && altno
!= 5)
1244 return 1; /* enable only altsets 2 and 5 */
1247 return 1; /* disable digialt input */
1248 if (altno
!= 2 && altno
!= 5)
1249 return 1; /* enalbe only altsets 2 and 5 */
1252 /* keep only 16-Bit mode */
1258 "using altsetting %d for interface %d config %d\n",
1259 altno
, iface
, chip
->setup
);
1260 return 0; /* keep this altsetting */
1263 int snd_usb_apply_interface_quirk(struct snd_usb_audio
*chip
,
1267 /* audiophile usb: skip altsets incompatible with device_setup */
1268 if (chip
->usb_id
== USB_ID(0x0763, 0x2003))
1269 return audiophile_skip_setting_quirk(chip
, iface
, altno
);
1270 /* quattro usb: skip altsets incompatible with device_setup */
1271 if (chip
->usb_id
== USB_ID(0x0763, 0x2001))
1272 return quattro_skip_setting_quirk(chip
, iface
, altno
);
1273 /* fasttrackpro usb: skip altsets incompatible with device_setup */
1274 if (chip
->usb_id
== USB_ID(0x0763, 0x2012))
1275 return fasttrackpro_skip_setting_quirk(chip
, iface
, altno
);
1280 int snd_usb_apply_boot_quirk(struct usb_device
*dev
,
1281 struct usb_interface
*intf
,
1282 const struct snd_usb_audio_quirk
*quirk
,
1286 case USB_ID(0x041e, 0x3000):
1287 /* SB Extigy needs special boot-up sequence */
1288 /* if more models come, this will go to the quirk list. */
1289 return snd_usb_extigy_boot_quirk(dev
, intf
);
1291 case USB_ID(0x041e, 0x3020):
1292 /* SB Audigy 2 NX needs its own boot-up magic, too */
1293 return snd_usb_audigy2nx_boot_quirk(dev
);
1295 case USB_ID(0x10f5, 0x0200):
1296 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
1297 return snd_usb_cm106_boot_quirk(dev
);
1299 case USB_ID(0x0d8c, 0x0102):
1300 /* C-Media CM6206 / CM106-Like Sound Device */
1301 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
1302 return snd_usb_cm6206_boot_quirk(dev
);
1304 case USB_ID(0x0dba, 0x3000):
1305 /* Digidesign Mbox 2 */
1306 return snd_usb_mbox2_boot_quirk(dev
);
1308 case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
1309 case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
1310 return snd_usb_novation_boot_quirk(dev
);
1312 case USB_ID(0x133e, 0x0815):
1313 /* Access Music VirusTI Desktop */
1314 return snd_usb_accessmusic_boot_quirk(dev
);
1316 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
1317 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
1318 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
1319 return snd_usb_nativeinstruments_boot_quirk(dev
);
1320 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1321 return snd_usb_fasttrackpro_boot_quirk(dev
);
1322 case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
1323 return snd_usb_gamecon780_boot_quirk(dev
);
1324 case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx 3 */
1325 return snd_usb_axefx3_boot_quirk(dev
);
1326 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook II */
1328 * For some reason interface 3 with vendor-spec class is
1329 * detected on MicroBook IIc.
1331 if (get_iface_desc(intf
->altsetting
)->bInterfaceClass
==
1332 USB_CLASS_VENDOR_SPEC
&&
1333 get_iface_desc(intf
->altsetting
)->bInterfaceNumber
< 3)
1334 return snd_usb_motu_microbookii_boot_quirk(dev
);
1341 int snd_usb_apply_boot_quirk_once(struct usb_device
*dev
,
1342 struct usb_interface
*intf
,
1343 const struct snd_usb_audio_quirk
*quirk
,
1347 case USB_ID(0x07fd, 0x0008): /* MOTU M Series */
1348 return snd_usb_motu_m_series_boot_quirk(dev
);
1355 * check if the device uses big-endian samples
1357 int snd_usb_is_big_endian_format(struct snd_usb_audio
*chip
, struct audioformat
*fp
)
1359 /* it depends on altsetting whether the device is big-endian or not */
1360 switch (chip
->usb_id
) {
1361 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
1362 if (fp
->altsetting
== 2 || fp
->altsetting
== 3 ||
1363 fp
->altsetting
== 5 || fp
->altsetting
== 6)
1366 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1367 if (chip
->setup
== 0x00 ||
1368 fp
->altsetting
== 1 || fp
->altsetting
== 2 ||
1369 fp
->altsetting
== 3)
1372 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
1373 if (fp
->altsetting
== 2 || fp
->altsetting
== 3 ||
1374 fp
->altsetting
== 5 || fp
->altsetting
== 6)
1382 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
1383 * not for interface.
1387 EMU_QUIRK_SR_44100HZ
= 0,
1388 EMU_QUIRK_SR_48000HZ
,
1389 EMU_QUIRK_SR_88200HZ
,
1390 EMU_QUIRK_SR_96000HZ
,
1391 EMU_QUIRK_SR_176400HZ
,
1392 EMU_QUIRK_SR_192000HZ
1395 static void set_format_emu_quirk(struct snd_usb_substream
*subs
,
1396 struct audioformat
*fmt
)
1398 unsigned char emu_samplerate_id
= 0;
1400 /* When capture is active
1401 * sample rate shouldn't be changed
1402 * by playback substream
1404 if (subs
->direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
1405 if (subs
->stream
->substream
[SNDRV_PCM_STREAM_CAPTURE
].interface
!= -1)
1409 switch (fmt
->rate_min
) {
1411 emu_samplerate_id
= EMU_QUIRK_SR_48000HZ
;
1414 emu_samplerate_id
= EMU_QUIRK_SR_88200HZ
;
1417 emu_samplerate_id
= EMU_QUIRK_SR_96000HZ
;
1420 emu_samplerate_id
= EMU_QUIRK_SR_176400HZ
;
1423 emu_samplerate_id
= EMU_QUIRK_SR_192000HZ
;
1426 emu_samplerate_id
= EMU_QUIRK_SR_44100HZ
;
1429 snd_emuusb_set_samplerate(subs
->stream
->chip
, emu_samplerate_id
);
1430 subs
->pkt_offset_adj
= (emu_samplerate_id
>= EMU_QUIRK_SR_176400HZ
) ? 4 : 0;
1433 void snd_usb_set_format_quirk(struct snd_usb_substream
*subs
,
1434 struct audioformat
*fmt
)
1436 switch (subs
->stream
->chip
->usb_id
) {
1437 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
1438 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
1439 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
1440 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
1441 set_format_emu_quirk(subs
, fmt
);
1443 case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
1444 subs
->stream_offset_adj
= 2;
1449 bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio
*chip
)
1451 /* devices which do not support reading the sample rate. */
1452 switch (chip
->usb_id
) {
1453 case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
1454 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1455 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
1456 case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
1457 case USB_ID(0x05a7, 0x1020): /* Bose Companion 5 */
1458 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1459 case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */
1460 case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */
1461 case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */
1462 case USB_ID(0x2912, 0x30c8): /* Audioengine D1 */
1463 case USB_ID(0x413c, 0xa506): /* Dell AE515 sound bar */
1464 case USB_ID(0x046d, 0x084c): /* Logitech ConferenceCam Connect */
1468 /* devices of these vendors don't support reading rate, either */
1469 switch (USB_ID_VENDOR(chip
->usb_id
)) {
1470 case 0x045E: /* MS Lifecam */
1471 case 0x047F: /* Plantronics */
1472 case 0x1de7: /* Phoenix Audio */
1479 /* ITF-USB DSD based DACs need a vendor cmd to switch
1480 * between PCM and native DSD mode
1482 static bool is_itf_usb_dsd_dac(unsigned int id
)
1485 case USB_ID(0x154e, 0x1002): /* Denon DCD-1500RE */
1486 case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
1487 case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
1488 case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
1489 case USB_ID(0x1852, 0x5065): /* Luxman DA-06 */
1490 case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-501V2/UD-503/NT-503 */
1491 case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */
1492 case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */
1498 int snd_usb_select_mode_quirk(struct snd_usb_substream
*subs
,
1499 struct audioformat
*fmt
)
1501 struct usb_device
*dev
= subs
->dev
;
1504 if (is_itf_usb_dsd_dac(subs
->stream
->chip
->usb_id
)) {
1505 /* First switch to alt set 0, otherwise the mode switch cmd
1506 * will not be accepted by the DAC
1508 err
= usb_set_interface(dev
, fmt
->iface
, 0);
1512 msleep(20); /* Delay needed after setting the interface */
1514 /* Vendor mode switch cmd is required. */
1515 if (fmt
->formats
& SNDRV_PCM_FMTBIT_DSD_U32_BE
) {
1516 /* DSD mode (DSD_U32) requested */
1517 err
= snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), 0,
1518 USB_DIR_OUT
|USB_TYPE_VENDOR
|USB_RECIP_INTERFACE
,
1524 /* PCM or DOP mode (S32) requested */
1525 /* PCM mode (S16) requested */
1526 err
= snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), 0,
1527 USB_DIR_OUT
|USB_TYPE_VENDOR
|USB_RECIP_INTERFACE
,
1538 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint
*ep
)
1541 * "Playback Design" products send bogus feedback data at the start
1542 * of the stream. Ignore them.
1544 if (USB_ID_VENDOR(ep
->chip
->usb_id
) == 0x23ba &&
1545 ep
->type
== SND_USB_ENDPOINT_TYPE_SYNC
)
1546 ep
->skip_packets
= 4;
1549 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
1550 * world latency varies by approx. +/- 50 frames (at 96KHz) each time
1551 * the stream is (re)started. When skipping packets 16 at endpoint
1552 * start up, the real world latency is stable within +/- 1 frame (also
1553 * across power cycles).
1555 if ((ep
->chip
->usb_id
== USB_ID(0x0763, 0x2030) ||
1556 ep
->chip
->usb_id
== USB_ID(0x0763, 0x2031)) &&
1557 ep
->type
== SND_USB_ENDPOINT_TYPE_DATA
)
1558 ep
->skip_packets
= 16;
1560 /* Work around devices that report unreasonable feedback data */
1561 if ((ep
->chip
->usb_id
== USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
1562 ep
->chip
->usb_id
== USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
1563 ep
->syncmaxsize
== 4)
1564 ep
->tenor_fb_quirk
= 1;
1567 void snd_usb_set_interface_quirk(struct usb_device
*dev
)
1569 struct snd_usb_audio
*chip
= dev_get_drvdata(&dev
->dev
);
1574 * "Playback Design" products need a 50ms delay after setting the
1577 switch (USB_ID_VENDOR(chip
->usb_id
)) {
1578 case 0x23ba: /* Playback Design */
1579 case 0x0644: /* TEAC Corp. */
1585 /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
1586 void snd_usb_ctl_msg_quirk(struct usb_device
*dev
, unsigned int pipe
,
1587 __u8 request
, __u8 requesttype
, __u16 value
,
1588 __u16 index
, void *data
, __u16 size
)
1590 struct snd_usb_audio
*chip
= dev_get_drvdata(&dev
->dev
);
1595 * "Playback Design" products need a 20ms delay after each
1596 * class compliant request
1598 if (USB_ID_VENDOR(chip
->usb_id
) == 0x23ba &&
1599 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1603 * "TEAC Corp." products need a 20ms delay after each
1604 * class compliant request
1606 if (USB_ID_VENDOR(chip
->usb_id
) == 0x0644 &&
1607 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1610 /* ITF-USB DSD based DACs functionality need a delay
1611 * after each class compliant request
1613 if (is_itf_usb_dsd_dac(chip
->usb_id
)
1614 && (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1618 * Plantronics headsets (C320, C320-M, etc) need a delay to avoid
1619 * random microhpone failures.
1621 if (USB_ID_VENDOR(chip
->usb_id
) == 0x047f &&
1622 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1625 /* Zoom R16/24, many Logitech(at least H650e/H570e/BCC950),
1626 * Jabra 550a, Kingston HyperX needs a tiny delay here,
1627 * otherwise requests like get/set frequency return
1628 * as failed despite actually succeeding.
1630 if ((chip
->usb_id
== USB_ID(0x1686, 0x00dd) ||
1631 USB_ID_VENDOR(chip
->usb_id
) == 0x046d || /* Logitech */
1632 chip
->usb_id
== USB_ID(0x0b0e, 0x0349) ||
1633 chip
->usb_id
== USB_ID(0x0951, 0x16ad)) &&
1634 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1635 usleep_range(1000, 2000);
1638 * Samsung USBC Headset (AKG) need a tiny delay after each
1639 * class compliant request. (Model number: AAM625R or AAM627R)
1641 if (chip
->usb_id
== USB_ID(0x04e8, 0xa051) &&
1642 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
1643 usleep_range(5000, 6000);
1647 * snd_usb_interface_dsd_format_quirks() is called from format.c to
1648 * augment the PCM format bit-field for DSD types. The UAC standards
1649 * don't have a designated bit field to denote DSD-capable interfaces,
1650 * hence all hardware that is known to support this format has to be
1653 u64
snd_usb_interface_dsd_format_quirks(struct snd_usb_audio
*chip
,
1654 struct audioformat
*fp
,
1655 unsigned int sample_bytes
)
1657 struct usb_interface
*iface
;
1659 /* Playback Designs */
1660 if (USB_ID_VENDOR(chip
->usb_id
) == 0x23ba &&
1661 USB_ID_PRODUCT(chip
->usb_id
) < 0x0110) {
1662 switch (fp
->altsetting
) {
1665 return SNDRV_PCM_FMTBIT_DSD_U16_LE
;
1667 fp
->dsd_bitrev
= true;
1668 return SNDRV_PCM_FMTBIT_DSD_U8
;
1670 fp
->dsd_bitrev
= true;
1671 return SNDRV_PCM_FMTBIT_DSD_U16_LE
;
1675 /* XMOS based USB DACs */
1676 switch (chip
->usb_id
) {
1677 case USB_ID(0x1511, 0x0037): /* AURALiC VEGA */
1678 case USB_ID(0x2522, 0x0012): /* LH Labs VI DAC Infinity */
1679 case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
1680 if (fp
->altsetting
== 2)
1681 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1684 case USB_ID(0x0d8c, 0x0316): /* Hegel HD12 DSD */
1685 case USB_ID(0x10cb, 0x0103): /* The Bit Opus #3; with fp->dsd_raw */
1686 case USB_ID(0x16d0, 0x06b2): /* NuPrime DAC-10 */
1687 case USB_ID(0x16d0, 0x09dd): /* Encore mDSD */
1688 case USB_ID(0x16d0, 0x0733): /* Furutech ADL Stratos */
1689 case USB_ID(0x16d0, 0x09db): /* NuPrime Audio DAC-9 */
1690 case USB_ID(0x1db5, 0x0003): /* Bryston BDA3 */
1691 case USB_ID(0x22e1, 0xca01): /* HDTA Serenade DSD */
1692 case USB_ID(0x249c, 0x9326): /* M2Tech Young MkIII */
1693 case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
1694 case USB_ID(0x2622, 0x0041): /* Audiolab M-DAC+ */
1695 case USB_ID(0x27f7, 0x3002): /* W4S DAC-2v2SE */
1696 case USB_ID(0x29a2, 0x0086): /* Mutec MC3+ USB */
1697 case USB_ID(0x6b42, 0x0042): /* MSB Technology */
1698 if (fp
->altsetting
== 3)
1699 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1702 /* Amanero Combo384 USB based DACs with native DSD support */
1703 case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
1704 case USB_ID(0x2ab6, 0x0004): /* T+A DAC8DSD-V2.0, MP1000E-V2.0, MP2000R-V2.0, MP2500R-V2.0, MP3100HV-V2.0 */
1705 case USB_ID(0x2ab6, 0x0005): /* T+A USB HD Audio 1 */
1706 case USB_ID(0x2ab6, 0x0006): /* T+A USB HD Audio 2 */
1707 if (fp
->altsetting
== 2) {
1708 switch (le16_to_cpu(chip
->dev
->descriptor
.bcdDevice
)) {
1710 return SNDRV_PCM_FMTBIT_DSD_U32_LE
;
1713 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1719 case USB_ID(0x16d0, 0x0a23):
1720 if (fp
->altsetting
== 2)
1721 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1728 /* ITF-USB DSD based DACs */
1729 if (is_itf_usb_dsd_dac(chip
->usb_id
)) {
1730 iface
= usb_ifnum_to_if(chip
->dev
, fp
->iface
);
1732 /* Altsetting 2 support native DSD if the num of altsets is
1734 * Altsetting 3 support native DSD if the num of altsets is
1737 if (fp
->altsetting
== iface
->num_altsetting
- 1)
1738 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1741 /* Mostly generic method to detect many DSD-capable implementations -
1742 * from XMOS/Thesycon
1744 switch (USB_ID_VENDOR(chip
->usb_id
)) {
1745 case 0x152a: /* Thesycon devices */
1746 case 0x20b1: /* XMOS based devices */
1747 case 0x22d9: /* Oppo */
1748 case 0x23ba: /* Playback Designs */
1749 case 0x25ce: /* Mytek devices */
1750 case 0x278b: /* Rotel? */
1751 case 0x292b: /* Gustard/Ess based devices */
1752 case 0x2972: /* FiiO devices */
1753 case 0x2ab6: /* T+A devices */
1754 case 0x3353: /* Khadas devices */
1755 case 0x3842: /* EVGA */
1756 case 0xc502: /* HiBy devices */
1758 return SNDRV_PCM_FMTBIT_DSD_U32_BE
;
1768 void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio
*chip
,
1769 struct audioformat
*fp
,
1772 switch (chip
->usb_id
) {
1773 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
1774 /* Optoplay sets the sample rate attribute although
1775 * it seems not supporting it in fact.
1777 fp
->attributes
&= ~UAC_EP_CS_ATTR_SAMPLE_RATE
;
1779 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
1780 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
1781 /* doesn't set the sample rate attribute, but supports it */
1782 fp
->attributes
|= UAC_EP_CS_ATTR_SAMPLE_RATE
;
1784 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
1785 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
1786 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
1787 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
1788 an older model 77d:223) */
1790 * plantronics headset and Griffin iMic have set adaptive-in
1791 * although it's really not...
1793 fp
->ep_attr
&= ~USB_ENDPOINT_SYNCTYPE
;
1794 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1795 fp
->ep_attr
|= USB_ENDPOINT_SYNC_ADAPTIVE
;
1797 fp
->ep_attr
|= USB_ENDPOINT_SYNC_SYNC
;
1799 case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook IIc */
1801 * MaxPacketsOnly attribute is erroneously set in endpoint
1802 * descriptors. As a result this card produces noise with
1803 * all sample rates other than 96 KHz.
1805 fp
->attributes
&= ~UAC_EP_CS_ATTR_FILL_MAX
;
1807 case USB_ID(0x1235, 0x8202): /* Focusrite Scarlett 2i2 2nd gen */
1808 case USB_ID(0x1235, 0x8205): /* Focusrite Scarlett Solo 2nd gen */
1810 * Reports that playback should use Synch: Synchronous
1811 * while still providing a feedback endpoint.
1812 * Synchronous causes snapping on some sample rates.
1813 * Force it to use Synch: Asynchronous.
1815 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1816 fp
->ep_attr
&= ~USB_ENDPOINT_SYNCTYPE
;
1817 fp
->ep_attr
|= USB_ENDPOINT_SYNC_ASYNC
;
1824 * registration quirk:
1825 * the registration is skipped if a device matches with the given ID,
1826 * unless the interface reaches to the defined one. This is for delaying
1827 * the registration until the last known interface, so that the card and
1828 * devices appear at the same time.
1831 struct registration_quirk
{
1832 unsigned int usb_id
; /* composed via USB_ID() */
1833 unsigned int interface
; /* the interface to trigger register */
1836 #define REG_QUIRK_ENTRY(vendor, product, iface) \
1837 { .usb_id = USB_ID(vendor, product), .interface = (iface) }
1839 static const struct registration_quirk registration_quirks
[] = {
1840 REG_QUIRK_ENTRY(0x0951, 0x16d8, 2), /* Kingston HyperX AMP */
1841 REG_QUIRK_ENTRY(0x0951, 0x16ed, 2), /* Kingston HyperX Cloud Alpha S */
1842 REG_QUIRK_ENTRY(0x0951, 0x16ea, 2), /* Kingston HyperX Cloud Flight S */
1843 REG_QUIRK_ENTRY(0x0ecb, 0x1f46, 2), /* JBL Quantum 600 */
1844 REG_QUIRK_ENTRY(0x0ecb, 0x1f47, 2), /* JBL Quantum 800 */
1845 REG_QUIRK_ENTRY(0x0ecb, 0x1f4c, 2), /* JBL Quantum 400 */
1846 REG_QUIRK_ENTRY(0x0ecb, 0x2039, 2), /* JBL Quantum 400 */
1847 REG_QUIRK_ENTRY(0x0ecb, 0x203c, 2), /* JBL Quantum 600 */
1848 REG_QUIRK_ENTRY(0x0ecb, 0x203e, 2), /* JBL Quantum 800 */
1849 { 0 } /* terminator */
1852 /* return true if skipping registration */
1853 bool snd_usb_registration_quirk(struct snd_usb_audio
*chip
, int iface
)
1855 const struct registration_quirk
*q
;
1857 for (q
= registration_quirks
; q
->usb_id
; q
++)
1858 if (chip
->usb_id
== q
->usb_id
)
1859 return iface
!= q
->interface
;
1861 /* Register as normal */