2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/usb.h>
20 #include <linux/usb/audio.h>
22 #include <sound/control.h>
23 #include <sound/core.h>
24 #include <sound/info.h>
25 #include <sound/pcm.h>
30 #include "mixer_quirks.h"
40 * handle the quirks for the contained interfaces
42 static int create_composite_quirk(struct snd_usb_audio
*chip
,
43 struct usb_interface
*iface
,
44 struct usb_driver
*driver
,
45 const struct snd_usb_audio_quirk
*quirk
)
47 int probed_ifnum
= get_iface_desc(iface
->altsetting
)->bInterfaceNumber
;
50 for (quirk
= quirk
->data
; quirk
->ifnum
>= 0; ++quirk
) {
51 iface
= usb_ifnum_to_if(chip
->dev
, quirk
->ifnum
);
54 if (quirk
->ifnum
!= probed_ifnum
&&
55 usb_interface_claimed(iface
))
57 err
= snd_usb_create_quirk(chip
, iface
, driver
, quirk
);
60 if (quirk
->ifnum
!= probed_ifnum
)
61 usb_driver_claim_interface(driver
, iface
, (void *)-1L);
66 static int ignore_interface_quirk(struct snd_usb_audio
*chip
,
67 struct usb_interface
*iface
,
68 struct usb_driver
*driver
,
69 const struct snd_usb_audio_quirk
*quirk
)
76 * Allow alignment on audio sub-slot (channel samples) rather than
77 * on audio slots (audio frames)
79 static int create_align_transfer_quirk(struct snd_usb_audio
*chip
,
80 struct usb_interface
*iface
,
81 struct usb_driver
*driver
,
82 const struct snd_usb_audio_quirk
*quirk
)
85 return 1; /* Continue with creating streams and mixer */
88 static int create_any_midi_quirk(struct snd_usb_audio
*chip
,
89 struct usb_interface
*intf
,
90 struct usb_driver
*driver
,
91 const struct snd_usb_audio_quirk
*quirk
)
93 return snd_usbmidi_create(chip
->card
, intf
, &chip
->midi_list
, quirk
);
97 * create a stream for an interface with proper descriptors
99 static int create_standard_audio_quirk(struct snd_usb_audio
*chip
,
100 struct usb_interface
*iface
,
101 struct usb_driver
*driver
,
102 const struct snd_usb_audio_quirk
*quirk
)
104 struct usb_host_interface
*alts
;
105 struct usb_interface_descriptor
*altsd
;
108 alts
= &iface
->altsetting
[0];
109 altsd
= get_iface_desc(alts
);
110 err
= snd_usb_parse_audio_interface(chip
, altsd
->bInterfaceNumber
);
112 snd_printk(KERN_ERR
"cannot setup if %d: error %d\n",
113 altsd
->bInterfaceNumber
, err
);
116 /* reset the current interface */
117 usb_set_interface(chip
->dev
, altsd
->bInterfaceNumber
, 0);
122 * create a stream for an endpoint/altsetting without proper descriptors
124 static int create_fixed_stream_quirk(struct snd_usb_audio
*chip
,
125 struct usb_interface
*iface
,
126 struct usb_driver
*driver
,
127 const struct snd_usb_audio_quirk
*quirk
)
129 struct audioformat
*fp
;
130 struct usb_host_interface
*alts
;
132 unsigned *rate_table
= NULL
;
134 fp
= kmemdup(quirk
->data
, sizeof(*fp
), GFP_KERNEL
);
136 snd_printk(KERN_ERR
"cannot memdup\n");
139 if (fp
->nr_rates
> MAX_NR_RATES
) {
143 if (fp
->nr_rates
> 0) {
144 rate_table
= kmemdup(fp
->rate_table
,
145 sizeof(int) * fp
->nr_rates
, GFP_KERNEL
);
150 fp
->rate_table
= rate_table
;
153 stream
= (fp
->endpoint
& USB_DIR_IN
)
154 ? SNDRV_PCM_STREAM_CAPTURE
: SNDRV_PCM_STREAM_PLAYBACK
;
155 err
= snd_usb_add_audio_stream(chip
, stream
, fp
);
161 if (fp
->iface
!= get_iface_desc(&iface
->altsetting
[0])->bInterfaceNumber
||
162 fp
->altset_idx
>= iface
->num_altsetting
) {
167 alts
= &iface
->altsetting
[fp
->altset_idx
];
168 fp
->datainterval
= snd_usb_parse_datainterval(chip
, alts
);
169 fp
->maxpacksize
= le16_to_cpu(get_endpoint(alts
, 0)->wMaxPacketSize
);
170 usb_set_interface(chip
->dev
, fp
->iface
, 0);
171 snd_usb_init_pitch(chip
, fp
->iface
, alts
, fp
);
172 snd_usb_init_sample_rate(chip
, fp
->iface
, alts
, fp
, fp
->rate_max
);
177 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
178 * The only way to detect the sample rate is by looking at wMaxPacketSize.
180 static int create_uaxx_quirk(struct snd_usb_audio
*chip
,
181 struct usb_interface
*iface
,
182 struct usb_driver
*driver
,
183 const struct snd_usb_audio_quirk
*quirk
)
185 static const struct audioformat ua_format
= {
186 .formats
= SNDRV_PCM_FMTBIT_S24_3LE
,
188 .fmt_type
= UAC_FORMAT_TYPE_I
,
191 .rates
= SNDRV_PCM_RATE_CONTINUOUS
,
193 struct usb_host_interface
*alts
;
194 struct usb_interface_descriptor
*altsd
;
195 struct audioformat
*fp
;
198 /* both PCM and MIDI interfaces have 2 or more altsettings */
199 if (iface
->num_altsetting
< 2)
201 alts
= &iface
->altsetting
[1];
202 altsd
= get_iface_desc(alts
);
204 if (altsd
->bNumEndpoints
== 2) {
205 static const struct snd_usb_midi_endpoint_info ua700_ep
= {
206 .out_cables
= 0x0003,
209 static const struct snd_usb_audio_quirk ua700_quirk
= {
210 .type
= QUIRK_MIDI_FIXED_ENDPOINT
,
213 static const struct snd_usb_midi_endpoint_info uaxx_ep
= {
214 .out_cables
= 0x0001,
217 static const struct snd_usb_audio_quirk uaxx_quirk
= {
218 .type
= QUIRK_MIDI_FIXED_ENDPOINT
,
221 const struct snd_usb_audio_quirk
*quirk
=
222 chip
->usb_id
== USB_ID(0x0582, 0x002b)
223 ? &ua700_quirk
: &uaxx_quirk
;
224 return snd_usbmidi_create(chip
->card
, iface
,
225 &chip
->midi_list
, quirk
);
228 if (altsd
->bNumEndpoints
!= 1)
231 fp
= kmemdup(&ua_format
, sizeof(*fp
), GFP_KERNEL
);
235 fp
->iface
= altsd
->bInterfaceNumber
;
236 fp
->endpoint
= get_endpoint(alts
, 0)->bEndpointAddress
;
237 fp
->ep_attr
= get_endpoint(alts
, 0)->bmAttributes
;
238 fp
->datainterval
= 0;
239 fp
->maxpacksize
= le16_to_cpu(get_endpoint(alts
, 0)->wMaxPacketSize
);
241 switch (fp
->maxpacksize
) {
243 fp
->rate_max
= fp
->rate_min
= 44100;
247 fp
->rate_max
= fp
->rate_min
= 48000;
251 fp
->rate_max
= fp
->rate_min
= 96000;
254 snd_printk(KERN_ERR
"unknown sample rate\n");
259 stream
= (fp
->endpoint
& USB_DIR_IN
)
260 ? SNDRV_PCM_STREAM_CAPTURE
: SNDRV_PCM_STREAM_PLAYBACK
;
261 err
= snd_usb_add_audio_stream(chip
, stream
, fp
);
266 usb_set_interface(chip
->dev
, fp
->iface
, 0);
271 * Create a standard mixer for the specified interface.
273 static int create_standard_mixer_quirk(struct snd_usb_audio
*chip
,
274 struct usb_interface
*iface
,
275 struct usb_driver
*driver
,
276 const struct snd_usb_audio_quirk
*quirk
)
278 if (quirk
->ifnum
< 0)
281 return snd_usb_create_mixer(chip
, quirk
->ifnum
, 0);
285 * audio-interface quirks
287 * returns zero if no standard audio/MIDI parsing is needed.
288 * returns a positive value if standard audio/midi interfaces are parsed
290 * returns a negative value at error.
292 int snd_usb_create_quirk(struct snd_usb_audio
*chip
,
293 struct usb_interface
*iface
,
294 struct usb_driver
*driver
,
295 const struct snd_usb_audio_quirk
*quirk
)
297 typedef int (*quirk_func_t
)(struct snd_usb_audio
*,
298 struct usb_interface
*,
300 const struct snd_usb_audio_quirk
*);
301 static const quirk_func_t quirk_funcs
[] = {
302 [QUIRK_IGNORE_INTERFACE
] = ignore_interface_quirk
,
303 [QUIRK_COMPOSITE
] = create_composite_quirk
,
304 [QUIRK_MIDI_STANDARD_INTERFACE
] = create_any_midi_quirk
,
305 [QUIRK_MIDI_FIXED_ENDPOINT
] = create_any_midi_quirk
,
306 [QUIRK_MIDI_YAMAHA
] = create_any_midi_quirk
,
307 [QUIRK_MIDI_MIDIMAN
] = create_any_midi_quirk
,
308 [QUIRK_MIDI_NOVATION
] = create_any_midi_quirk
,
309 [QUIRK_MIDI_RAW_BYTES
] = create_any_midi_quirk
,
310 [QUIRK_MIDI_EMAGIC
] = create_any_midi_quirk
,
311 [QUIRK_MIDI_CME
] = create_any_midi_quirk
,
312 [QUIRK_MIDI_AKAI
] = create_any_midi_quirk
,
313 [QUIRK_MIDI_FTDI
] = create_any_midi_quirk
,
314 [QUIRK_AUDIO_STANDARD_INTERFACE
] = create_standard_audio_quirk
,
315 [QUIRK_AUDIO_FIXED_ENDPOINT
] = create_fixed_stream_quirk
,
316 [QUIRK_AUDIO_EDIROL_UAXX
] = create_uaxx_quirk
,
317 [QUIRK_AUDIO_ALIGN_TRANSFER
] = create_align_transfer_quirk
,
318 [QUIRK_AUDIO_STANDARD_MIXER
] = create_standard_mixer_quirk
,
321 if (quirk
->type
< QUIRK_TYPE_COUNT
) {
322 return quirk_funcs
[quirk
->type
](chip
, iface
, driver
, quirk
);
324 snd_printd(KERN_ERR
"invalid quirk type %d\n", quirk
->type
);
333 #define EXTIGY_FIRMWARE_SIZE_OLD 794
334 #define EXTIGY_FIRMWARE_SIZE_NEW 483
336 static int snd_usb_extigy_boot_quirk(struct usb_device
*dev
, struct usb_interface
*intf
)
338 struct usb_host_config
*config
= dev
->actconfig
;
341 if (le16_to_cpu(get_cfg_desc(config
)->wTotalLength
) == EXTIGY_FIRMWARE_SIZE_OLD
||
342 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
) == EXTIGY_FIRMWARE_SIZE_NEW
) {
343 snd_printdd("sending Extigy boot sequence...\n");
344 /* Send message to force it to reconnect with full interface. */
345 err
= snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
,0),
346 0x10, 0x43, 0x0001, 0x000a, NULL
, 0);
347 if (err
< 0) snd_printdd("error sending boot message: %d\n", err
);
348 err
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0,
349 &dev
->descriptor
, sizeof(dev
->descriptor
));
350 config
= dev
->actconfig
;
351 if (err
< 0) snd_printdd("error usb_get_descriptor: %d\n", err
);
352 err
= usb_reset_configuration(dev
);
353 if (err
< 0) snd_printdd("error usb_reset_configuration: %d\n", err
);
354 snd_printdd("extigy_boot: new boot length = %d\n",
355 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
));
356 return -ENODEV
; /* quit this anyway */
361 static int snd_usb_audigy2nx_boot_quirk(struct usb_device
*dev
)
365 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0), 0x2a,
366 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
369 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), 0x29,
370 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
377 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device
*dev
)
381 if (dev
->actconfig
->desc
.bConfigurationValue
== 1) {
382 snd_printk(KERN_INFO
"usb-audio: "
383 "Fast Track Pro switching to config #2\n");
384 /* This function has to be available by the usb core module.
385 * if it is not avialable the boot quirk has to be left out
386 * and the configuration has to be set by udev or hotplug
389 err
= usb_driver_set_configuration(dev
, 2);
391 snd_printdd("error usb_driver_set_configuration: %d\n",
393 /* Always return an error, so that we stop creating a device
394 that will just be destroyed and recreated with a new
398 snd_printk(KERN_INFO
"usb-audio: Fast Track Pro config OK\n");
404 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
405 * documented in the device's data sheet.
407 static int snd_usb_cm106_write_int_reg(struct usb_device
*dev
, int reg
, u16 value
)
411 buf
[1] = value
& 0xff;
412 buf
[2] = (value
>> 8) & 0xff;
414 return snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0), USB_REQ_SET_CONFIGURATION
,
415 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_ENDPOINT
,
419 static int snd_usb_cm106_boot_quirk(struct usb_device
*dev
)
422 * Enable line-out driver mode, set headphone source to front
423 * channels, enable stereo mic.
425 return snd_usb_cm106_write_int_reg(dev
, 2, 0x8004);
429 * C-Media CM6206 is based on CM106 with two additional
430 * registers that are not documented in the data sheet.
431 * Values here are chosen based on sniffing USB traffic
434 static int snd_usb_cm6206_boot_quirk(struct usb_device
*dev
)
437 int val
[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
439 for (reg
= 0; reg
< ARRAY_SIZE(val
); reg
++) {
440 err
= snd_usb_cm106_write_int_reg(dev
, reg
, val
[reg
]);
449 * This call will put the synth in "USB send" mode, i.e it will send MIDI
450 * messages through USB (this is disabled at startup). The synth will
451 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
452 * sign on its LCD. Values here are chosen based on sniffing USB traffic
455 static int snd_usb_accessmusic_boot_quirk(struct usb_device
*dev
)
457 int err
, actual_length
;
459 /* "midi send" enable */
460 static const u8 seq
[] = { 0x4e, 0x73, 0x52, 0x01 };
462 void *buf
= kmemdup(seq
, ARRAY_SIZE(seq
), GFP_KERNEL
);
465 err
= usb_interrupt_msg(dev
, usb_sndintpipe(dev
, 0x05), buf
,
466 ARRAY_SIZE(seq
), &actual_length
, 1000);
475 * Some sound cards from Native Instruments are in fact compliant to the USB
476 * audio standard of version 2 and other approved USB standards, even though
477 * they come up as vendor-specific device when first connected.
479 * However, they can be told to come up with a new set of descriptors
480 * upon their next enumeration, and the interfaces announced by the new
481 * descriptors will then be handled by the kernel's class drivers. As the
482 * product ID will also change, no further checks are required.
485 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device
*dev
)
487 int ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
488 0xaf, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
489 cpu_to_le16(1), 0, NULL
, 0, 1000);
494 usb_reset_device(dev
);
496 /* return -EAGAIN, so the creation of an audio interface for this
497 * temporary device is aborted. The device will reconnect with a
502 static void mbox2_setup_48_24_magic(struct usb_device
*dev
)
507 /* Choose 48000Hz permanently */
512 /* Send the magic! */
513 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
514 0x01, 0x22, 0x0100, 0x0085, &temp
, 0x0003);
515 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
516 0x81, 0xa2, 0x0100, 0x0085, &srate
, 0x0003);
517 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
518 0x81, 0xa2, 0x0100, 0x0086, &srate
, 0x0003);
519 snd_usb_ctl_msg(dev
, usb_sndctrlpipe(dev
, 0),
520 0x81, 0xa2, 0x0100, 0x0003, &srate
, 0x0003);
524 /* Digidesign Mbox 2 needs to load firmware onboard
525 * and driver must wait a few seconds for initialisation.
528 #define MBOX2_FIRMWARE_SIZE 646
529 #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
530 #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
532 static int snd_usb_mbox2_boot_quirk(struct usb_device
*dev
)
534 struct usb_host_config
*config
= dev
->actconfig
;
536 u8 bootresponse
[0x12];
540 fwsize
= le16_to_cpu(get_cfg_desc(config
)->wTotalLength
);
542 if (fwsize
!= MBOX2_FIRMWARE_SIZE
) {
543 snd_printk(KERN_ERR
"usb-audio: Invalid firmware size=%d.\n", fwsize
);
547 snd_printd("usb-audio: Sending Digidesign Mbox 2 boot sequence...\n");
550 bootresponse
[0] = MBOX2_BOOT_LOADING
;
551 while ((bootresponse
[0] == MBOX2_BOOT_LOADING
) && (count
< 10)) {
552 msleep(500); /* 0.5 second delay */
553 snd_usb_ctl_msg(dev
, usb_rcvctrlpipe(dev
, 0),
554 /* Control magic - load onboard firmware */
555 0x85, 0xc0, 0x0001, 0x0000, &bootresponse
, 0x0012);
556 if (bootresponse
[0] == MBOX2_BOOT_READY
)
558 snd_printd("usb-audio: device not ready, resending boot sequence...\n");
562 if (bootresponse
[0] != MBOX2_BOOT_READY
) {
563 snd_printk(KERN_ERR
"usb-audio: Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse
[0]);
567 snd_printdd("usb-audio: device initialised!\n");
569 err
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0,
570 &dev
->descriptor
, sizeof(dev
->descriptor
));
571 config
= dev
->actconfig
;
573 snd_printd("error usb_get_descriptor: %d\n", err
);
575 err
= usb_reset_configuration(dev
);
577 snd_printd("error usb_reset_configuration: %d\n", err
);
578 snd_printdd("mbox2_boot: new boot length = %d\n",
579 le16_to_cpu(get_cfg_desc(config
)->wTotalLength
));
581 mbox2_setup_48_24_magic(dev
);
583 snd_printk(KERN_INFO
"usb-audio: Digidesign Mbox 2: 24bit 48kHz");
585 return 0; /* Successful boot */
591 #define MAUDIO_SET 0x01 /* parse device_setup */
592 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
593 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
594 #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
595 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
596 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
597 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
598 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
599 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
600 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
601 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
603 static int quattro_skip_setting_quirk(struct snd_usb_audio
*chip
,
604 int iface
, int altno
)
606 /* Reset ALL ifaces to 0 altsetting.
607 * Call it for every possible altsetting of every interface.
609 usb_set_interface(chip
->dev
, iface
, 0);
610 if (chip
->setup
& MAUDIO_SET
) {
611 if (chip
->setup
& MAUDIO_SET_COMPATIBLE
) {
612 if (iface
!= 1 && iface
!= 2)
613 return 1; /* skip all interfaces but 1 and 2 */
616 if (iface
== 1 || iface
== 2)
617 return 1; /* skip interfaces 1 and 2 */
618 if ((chip
->setup
& MAUDIO_SET_96K
) && altno
!= 1)
619 return 1; /* skip this altsetting */
620 mask
= chip
->setup
& MAUDIO_SET_MASK
;
621 if (mask
== MAUDIO_SET_24B_48K_DI
&& altno
!= 2)
622 return 1; /* skip this altsetting */
623 if (mask
== MAUDIO_SET_24B_48K_NOTDI
&& altno
!= 3)
624 return 1; /* skip this altsetting */
625 if (mask
== MAUDIO_SET_16B_48K_NOTDI
&& altno
!= 4)
626 return 1; /* skip this altsetting */
629 snd_printdd(KERN_INFO
630 "using altsetting %d for interface %d config %d\n",
631 altno
, iface
, chip
->setup
);
632 return 0; /* keep this altsetting */
635 static int audiophile_skip_setting_quirk(struct snd_usb_audio
*chip
,
639 /* Reset ALL ifaces to 0 altsetting.
640 * Call it for every possible altsetting of every interface.
642 usb_set_interface(chip
->dev
, iface
, 0);
644 if (chip
->setup
& MAUDIO_SET
) {
646 if ((chip
->setup
& MAUDIO_SET_DTS
) && altno
!= 6)
647 return 1; /* skip this altsetting */
648 if ((chip
->setup
& MAUDIO_SET_96K
) && altno
!= 1)
649 return 1; /* skip this altsetting */
650 mask
= chip
->setup
& MAUDIO_SET_MASK
;
651 if (mask
== MAUDIO_SET_24B_48K_DI
&& altno
!= 2)
652 return 1; /* skip this altsetting */
653 if (mask
== MAUDIO_SET_24B_48K_NOTDI
&& altno
!= 3)
654 return 1; /* skip this altsetting */
655 if (mask
== MAUDIO_SET_16B_48K_DI
&& altno
!= 4)
656 return 1; /* skip this altsetting */
657 if (mask
== MAUDIO_SET_16B_48K_NOTDI
&& altno
!= 5)
658 return 1; /* skip this altsetting */
661 return 0; /* keep this altsetting */
664 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio
*chip
,
665 int iface
, int altno
)
667 /* Reset ALL ifaces to 0 altsetting.
668 * Call it for every possible altsetting of every interface.
670 usb_set_interface(chip
->dev
, iface
, 0);
672 /* possible configuration where both inputs and only one output is
673 *used is not supported by the current setup
675 if (chip
->setup
& (MAUDIO_SET
| MAUDIO_SET_24B
)) {
676 if (chip
->setup
& MAUDIO_SET_96K
) {
677 if (altno
!= 3 && altno
!= 6)
679 } else if (chip
->setup
& MAUDIO_SET_DI
) {
681 return 1; /* no analog input */
682 if (altno
!= 2 && altno
!= 5)
683 return 1; /* enable only altsets 2 and 5 */
686 return 1; /* disable digialt input */
687 if (altno
!= 2 && altno
!= 5)
688 return 1; /* enalbe only altsets 2 and 5 */
691 /* keep only 16-Bit mode */
696 snd_printdd(KERN_INFO
697 "using altsetting %d for interface %d config %d\n",
698 altno
, iface
, chip
->setup
);
699 return 0; /* keep this altsetting */
702 int snd_usb_apply_interface_quirk(struct snd_usb_audio
*chip
,
706 /* audiophile usb: skip altsets incompatible with device_setup */
707 if (chip
->usb_id
== USB_ID(0x0763, 0x2003))
708 return audiophile_skip_setting_quirk(chip
, iface
, altno
);
709 /* quattro usb: skip altsets incompatible with device_setup */
710 if (chip
->usb_id
== USB_ID(0x0763, 0x2001))
711 return quattro_skip_setting_quirk(chip
, iface
, altno
);
712 /* fasttrackpro usb: skip altsets incompatible with device_setup */
713 if (chip
->usb_id
== USB_ID(0x0763, 0x2012))
714 return fasttrackpro_skip_setting_quirk(chip
, iface
, altno
);
719 int snd_usb_apply_boot_quirk(struct usb_device
*dev
,
720 struct usb_interface
*intf
,
721 const struct snd_usb_audio_quirk
*quirk
)
723 u32 id
= USB_ID(le16_to_cpu(dev
->descriptor
.idVendor
),
724 le16_to_cpu(dev
->descriptor
.idProduct
));
727 case USB_ID(0x041e, 0x3000):
728 /* SB Extigy needs special boot-up sequence */
729 /* if more models come, this will go to the quirk list. */
730 return snd_usb_extigy_boot_quirk(dev
, intf
);
732 case USB_ID(0x041e, 0x3020):
733 /* SB Audigy 2 NX needs its own boot-up magic, too */
734 return snd_usb_audigy2nx_boot_quirk(dev
);
736 case USB_ID(0x10f5, 0x0200):
737 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
738 return snd_usb_cm106_boot_quirk(dev
);
740 case USB_ID(0x0d8c, 0x0102):
741 /* C-Media CM6206 / CM106-Like Sound Device */
742 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
743 return snd_usb_cm6206_boot_quirk(dev
);
745 case USB_ID(0x0dba, 0x3000):
746 /* Digidesign Mbox 2 */
747 return snd_usb_mbox2_boot_quirk(dev
);
749 case USB_ID(0x133e, 0x0815):
750 /* Access Music VirusTI Desktop */
751 return snd_usb_accessmusic_boot_quirk(dev
);
753 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
754 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
755 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
756 return snd_usb_nativeinstruments_boot_quirk(dev
);
757 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
758 return snd_usb_fasttrackpro_boot_quirk(dev
);
765 * check if the device uses big-endian samples
767 int snd_usb_is_big_endian_format(struct snd_usb_audio
*chip
, struct audioformat
*fp
)
769 /* it depends on altsetting whether the device is big-endian or not */
770 switch (chip
->usb_id
) {
771 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
772 if (fp
->altsetting
== 2 || fp
->altsetting
== 3 ||
773 fp
->altsetting
== 5 || fp
->altsetting
== 6)
776 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
777 if (chip
->setup
== 0x00 ||
778 fp
->altsetting
== 1 || fp
->altsetting
== 2 ||
782 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
783 if (fp
->altsetting
== 2 || fp
->altsetting
== 3 ||
784 fp
->altsetting
== 5 || fp
->altsetting
== 6)
792 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
797 EMU_QUIRK_SR_44100HZ
= 0,
798 EMU_QUIRK_SR_48000HZ
,
799 EMU_QUIRK_SR_88200HZ
,
800 EMU_QUIRK_SR_96000HZ
,
801 EMU_QUIRK_SR_176400HZ
,
802 EMU_QUIRK_SR_192000HZ
805 static void set_format_emu_quirk(struct snd_usb_substream
*subs
,
806 struct audioformat
*fmt
)
808 unsigned char emu_samplerate_id
= 0;
810 /* When capture is active
811 * sample rate shouldn't be changed
812 * by playback substream
814 if (subs
->direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
815 if (subs
->stream
->substream
[SNDRV_PCM_STREAM_CAPTURE
].interface
!= -1)
819 switch (fmt
->rate_min
) {
821 emu_samplerate_id
= EMU_QUIRK_SR_48000HZ
;
824 emu_samplerate_id
= EMU_QUIRK_SR_88200HZ
;
827 emu_samplerate_id
= EMU_QUIRK_SR_96000HZ
;
830 emu_samplerate_id
= EMU_QUIRK_SR_176400HZ
;
833 emu_samplerate_id
= EMU_QUIRK_SR_192000HZ
;
836 emu_samplerate_id
= EMU_QUIRK_SR_44100HZ
;
839 snd_emuusb_set_samplerate(subs
->stream
->chip
, emu_samplerate_id
);
842 void snd_usb_set_format_quirk(struct snd_usb_substream
*subs
,
843 struct audioformat
*fmt
)
845 switch (subs
->stream
->chip
->usb_id
) {
846 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
847 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
848 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
849 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
850 set_format_emu_quirk(subs
, fmt
);
855 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint
*ep
)
858 * "Playback Design" products send bogus feedback data at the start
859 * of the stream. Ignore them.
861 if ((le16_to_cpu(ep
->chip
->dev
->descriptor
.idVendor
) == 0x23ba) &&
862 ep
->type
== SND_USB_ENDPOINT_TYPE_SYNC
)
863 ep
->skip_packets
= 4;
866 * M-Audio Fast Track C400/C600 - when packets are not skipped, real
867 * world latency varies by approx. +/- 50 frames (at 96KHz) each time
868 * the stream is (re)started. When skipping packets 16 at endpoint
869 * start up, the real world latency is stable within +/- 1 frame (also
870 * across power cycles).
872 if ((ep
->chip
->usb_id
== USB_ID(0x0763, 0x2030) ||
873 ep
->chip
->usb_id
== USB_ID(0x0763, 0x2031)) &&
874 ep
->type
== SND_USB_ENDPOINT_TYPE_DATA
)
875 ep
->skip_packets
= 16;
878 void snd_usb_ctl_msg_quirk(struct usb_device
*dev
, unsigned int pipe
,
879 __u8 request
, __u8 requesttype
, __u16 value
,
880 __u16 index
, void *data
, __u16 size
)
883 * "Playback Design" products need a 20ms delay after each
884 * class compliant request
886 if ((le16_to_cpu(dev
->descriptor
.idVendor
) == 0x23ba) &&
887 (requesttype
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)