Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / sound / usb / quirks.c
1 /*
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.
6 *
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.
11 *
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
15 */
16
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/usb.h>
20 #include <linux/usb/audio.h>
21
22 #include <sound/control.h>
23 #include <sound/core.h>
24 #include <sound/info.h>
25 #include <sound/pcm.h>
26
27 #include "usbaudio.h"
28 #include "card.h"
29 #include "mixer.h"
30 #include "mixer_quirks.h"
31 #include "midi.h"
32 #include "quirks.h"
33 #include "helper.h"
34 #include "endpoint.h"
35 #include "pcm.h"
36 #include "clock.h"
37 #include "stream.h"
38
39 /*
40 * handle the quirks for the contained interfaces
41 */
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)
46 {
47 int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
48 int err;
49
50 for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) {
51 iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
52 if (!iface)
53 continue;
54 if (quirk->ifnum != probed_ifnum &&
55 usb_interface_claimed(iface))
56 continue;
57 err = snd_usb_create_quirk(chip, iface, driver, quirk);
58 if (err < 0)
59 return err;
60 if (quirk->ifnum != probed_ifnum)
61 usb_driver_claim_interface(driver, iface, (void *)-1L);
62 }
63 return 0;
64 }
65
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)
70 {
71 return 0;
72 }
73
74
75 /*
76 * Allow alignment on audio sub-slot (channel samples) rather than
77 * on audio slots (audio frames)
78 */
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)
83 {
84 chip->txfr_quirk = 1;
85 return 1; /* Continue with creating streams and mixer */
86 }
87
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)
92 {
93 return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
94 }
95
96 /*
97 * create a stream for an interface with proper descriptors
98 */
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)
103 {
104 struct usb_host_interface *alts;
105 struct usb_interface_descriptor *altsd;
106 int err;
107
108 alts = &iface->altsetting[0];
109 altsd = get_iface_desc(alts);
110 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
111 if (err < 0) {
112 snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
113 altsd->bInterfaceNumber, err);
114 return err;
115 }
116 /* reset the current interface */
117 usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
118 return 0;
119 }
120
121 /*
122 * create a stream for an endpoint/altsetting without proper descriptors
123 */
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)
128 {
129 struct audioformat *fp;
130 struct usb_host_interface *alts;
131 int stream, err;
132 unsigned *rate_table = NULL;
133
134 fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
135 if (! fp) {
136 snd_printk(KERN_ERR "cannot memdup\n");
137 return -ENOMEM;
138 }
139 if (fp->nr_rates > 0) {
140 rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
141 if (!rate_table) {
142 kfree(fp);
143 return -ENOMEM;
144 }
145 memcpy(rate_table, fp->rate_table, sizeof(int) * fp->nr_rates);
146 fp->rate_table = rate_table;
147 }
148
149 stream = (fp->endpoint & USB_DIR_IN)
150 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
151 err = snd_usb_add_audio_stream(chip, stream, fp);
152 if (err < 0) {
153 kfree(fp);
154 kfree(rate_table);
155 return err;
156 }
157 if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
158 fp->altset_idx >= iface->num_altsetting) {
159 kfree(fp);
160 kfree(rate_table);
161 return -EINVAL;
162 }
163 alts = &iface->altsetting[fp->altset_idx];
164 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
165 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
166 usb_set_interface(chip->dev, fp->iface, 0);
167 snd_usb_init_pitch(chip, fp->iface, alts, fp);
168 snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
169 return 0;
170 }
171
172 /*
173 * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
174 * The only way to detect the sample rate is by looking at wMaxPacketSize.
175 */
176 static int create_uaxx_quirk(struct snd_usb_audio *chip,
177 struct usb_interface *iface,
178 struct usb_driver *driver,
179 const struct snd_usb_audio_quirk *quirk)
180 {
181 static const struct audioformat ua_format = {
182 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
183 .channels = 2,
184 .fmt_type = UAC_FORMAT_TYPE_I,
185 .altsetting = 1,
186 .altset_idx = 1,
187 .rates = SNDRV_PCM_RATE_CONTINUOUS,
188 };
189 struct usb_host_interface *alts;
190 struct usb_interface_descriptor *altsd;
191 struct audioformat *fp;
192 int stream, err;
193
194 /* both PCM and MIDI interfaces have 2 or more altsettings */
195 if (iface->num_altsetting < 2)
196 return -ENXIO;
197 alts = &iface->altsetting[1];
198 altsd = get_iface_desc(alts);
199
200 if (altsd->bNumEndpoints == 2) {
201 static const struct snd_usb_midi_endpoint_info ua700_ep = {
202 .out_cables = 0x0003,
203 .in_cables = 0x0003
204 };
205 static const struct snd_usb_audio_quirk ua700_quirk = {
206 .type = QUIRK_MIDI_FIXED_ENDPOINT,
207 .data = &ua700_ep
208 };
209 static const struct snd_usb_midi_endpoint_info uaxx_ep = {
210 .out_cables = 0x0001,
211 .in_cables = 0x0001
212 };
213 static const struct snd_usb_audio_quirk uaxx_quirk = {
214 .type = QUIRK_MIDI_FIXED_ENDPOINT,
215 .data = &uaxx_ep
216 };
217 const struct snd_usb_audio_quirk *quirk =
218 chip->usb_id == USB_ID(0x0582, 0x002b)
219 ? &ua700_quirk : &uaxx_quirk;
220 return snd_usbmidi_create(chip->card, iface,
221 &chip->midi_list, quirk);
222 }
223
224 if (altsd->bNumEndpoints != 1)
225 return -ENXIO;
226
227 fp = kmalloc(sizeof(*fp), GFP_KERNEL);
228 if (!fp)
229 return -ENOMEM;
230 memcpy(fp, &ua_format, sizeof(*fp));
231
232 fp->iface = altsd->bInterfaceNumber;
233 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
234 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
235 fp->datainterval = 0;
236 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
237
238 switch (fp->maxpacksize) {
239 case 0x120:
240 fp->rate_max = fp->rate_min = 44100;
241 break;
242 case 0x138:
243 case 0x140:
244 fp->rate_max = fp->rate_min = 48000;
245 break;
246 case 0x258:
247 case 0x260:
248 fp->rate_max = fp->rate_min = 96000;
249 break;
250 default:
251 snd_printk(KERN_ERR "unknown sample rate\n");
252 kfree(fp);
253 return -ENXIO;
254 }
255
256 stream = (fp->endpoint & USB_DIR_IN)
257 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
258 err = snd_usb_add_audio_stream(chip, stream, fp);
259 if (err < 0) {
260 kfree(fp);
261 return err;
262 }
263 usb_set_interface(chip->dev, fp->iface, 0);
264 return 0;
265 }
266
267 /*
268 * Create a standard mixer for the specified interface.
269 */
270 static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
271 struct usb_interface *iface,
272 struct usb_driver *driver,
273 const struct snd_usb_audio_quirk *quirk)
274 {
275 if (quirk->ifnum < 0)
276 return 0;
277
278 return snd_usb_create_mixer(chip, quirk->ifnum, 0);
279 }
280
281 /*
282 * audio-interface quirks
283 *
284 * returns zero if no standard audio/MIDI parsing is needed.
285 * returns a positive value if standard audio/midi interfaces are parsed
286 * after this.
287 * returns a negative value at error.
288 */
289 int snd_usb_create_quirk(struct snd_usb_audio *chip,
290 struct usb_interface *iface,
291 struct usb_driver *driver,
292 const struct snd_usb_audio_quirk *quirk)
293 {
294 typedef int (*quirk_func_t)(struct snd_usb_audio *,
295 struct usb_interface *,
296 struct usb_driver *,
297 const struct snd_usb_audio_quirk *);
298 static const quirk_func_t quirk_funcs[] = {
299 [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
300 [QUIRK_COMPOSITE] = create_composite_quirk,
301 [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
302 [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
303 [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
304 [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
305 [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
306 [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
307 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
308 [QUIRK_MIDI_CME] = create_any_midi_quirk,
309 [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
310 [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
311 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
312 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
313 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
314 [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
315 [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
316 };
317
318 if (quirk->type < QUIRK_TYPE_COUNT) {
319 return quirk_funcs[quirk->type](chip, iface, driver, quirk);
320 } else {
321 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
322 return -ENXIO;
323 }
324 }
325
326 /*
327 * boot quirks
328 */
329
330 #define EXTIGY_FIRMWARE_SIZE_OLD 794
331 #define EXTIGY_FIRMWARE_SIZE_NEW 483
332
333 static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
334 {
335 struct usb_host_config *config = dev->actconfig;
336 int err;
337
338 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
339 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
340 snd_printdd("sending Extigy boot sequence...\n");
341 /* Send message to force it to reconnect with full interface. */
342 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
343 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
344 if (err < 0) snd_printdd("error sending boot message: %d\n", err);
345 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
346 &dev->descriptor, sizeof(dev->descriptor));
347 config = dev->actconfig;
348 if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
349 err = usb_reset_configuration(dev);
350 if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
351 snd_printdd("extigy_boot: new boot length = %d\n",
352 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
353 return -ENODEV; /* quit this anyway */
354 }
355 return 0;
356 }
357
358 static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
359 {
360 u8 buf = 1;
361
362 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
363 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
364 0, 0, &buf, 1);
365 if (buf == 0) {
366 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
367 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
368 1, 2000, NULL, 0);
369 return -ENODEV;
370 }
371 return 0;
372 }
373
374 static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
375 {
376 int err;
377
378 if (dev->actconfig->desc.bConfigurationValue == 1) {
379 snd_printk(KERN_INFO "usb-audio: "
380 "Fast Track Pro switching to config #2\n");
381 /* This function has to be available by the usb core module.
382 * if it is not avialable the boot quirk has to be left out
383 * and the configuration has to be set by udev or hotplug
384 * rules
385 */
386 err = usb_driver_set_configuration(dev, 2);
387 if (err < 0) {
388 snd_printdd("error usb_driver_set_configuration: %d\n",
389 err);
390 return -ENODEV;
391 }
392 } else
393 snd_printk(KERN_INFO "usb-audio: Fast Track Pro config OK\n");
394
395 return 0;
396 }
397
398 /*
399 * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
400 * documented in the device's data sheet.
401 */
402 static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
403 {
404 u8 buf[4];
405 buf[0] = 0x20;
406 buf[1] = value & 0xff;
407 buf[2] = (value >> 8) & 0xff;
408 buf[3] = reg;
409 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
410 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
411 0, 0, &buf, 4);
412 }
413
414 static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
415 {
416 /*
417 * Enable line-out driver mode, set headphone source to front
418 * channels, enable stereo mic.
419 */
420 return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
421 }
422
423 /*
424 * C-Media CM6206 is based on CM106 with two additional
425 * registers that are not documented in the data sheet.
426 * Values here are chosen based on sniffing USB traffic
427 * under Windows.
428 */
429 static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
430 {
431 int err = 0, reg;
432 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
433
434 for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
435 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
436 if (err < 0)
437 return err;
438 }
439
440 return err;
441 }
442
443 /*
444 * This call will put the synth in "USB send" mode, i.e it will send MIDI
445 * messages through USB (this is disabled at startup). The synth will
446 * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
447 * sign on its LCD. Values here are chosen based on sniffing USB traffic
448 * under Windows.
449 */
450 static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
451 {
452 int err, actual_length;
453
454 /* "midi send" enable */
455 static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
456
457 void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
458 if (!buf)
459 return -ENOMEM;
460 err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
461 ARRAY_SIZE(seq), &actual_length, 1000);
462 kfree(buf);
463 if (err < 0)
464 return err;
465
466 return 0;
467 }
468
469 /*
470 * Some sound cards from Native Instruments are in fact compliant to the USB
471 * audio standard of version 2 and other approved USB standards, even though
472 * they come up as vendor-specific device when first connected.
473 *
474 * However, they can be told to come up with a new set of descriptors
475 * upon their next enumeration, and the interfaces announced by the new
476 * descriptors will then be handled by the kernel's class drivers. As the
477 * product ID will also change, no further checks are required.
478 */
479
480 static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
481 {
482 int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
483 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
484 cpu_to_le16(1), 0, NULL, 0, 1000);
485
486 if (ret < 0)
487 return ret;
488
489 usb_reset_device(dev);
490
491 /* return -EAGAIN, so the creation of an audio interface for this
492 * temporary device is aborted. The device will reconnect with a
493 * new product ID */
494 return -EAGAIN;
495 }
496
497 /*
498 * Setup quirks
499 */
500 #define MAUDIO_SET 0x01 /* parse device_setup */
501 #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
502 #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
503 #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
504 #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
505 #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
506 #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
507 #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
508 #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
509 #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
510 #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
511
512 static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
513 int iface, int altno)
514 {
515 /* Reset ALL ifaces to 0 altsetting.
516 * Call it for every possible altsetting of every interface.
517 */
518 usb_set_interface(chip->dev, iface, 0);
519 if (chip->setup & MAUDIO_SET) {
520 if (chip->setup & MAUDIO_SET_COMPATIBLE) {
521 if (iface != 1 && iface != 2)
522 return 1; /* skip all interfaces but 1 and 2 */
523 } else {
524 unsigned int mask;
525 if (iface == 1 || iface == 2)
526 return 1; /* skip interfaces 1 and 2 */
527 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
528 return 1; /* skip this altsetting */
529 mask = chip->setup & MAUDIO_SET_MASK;
530 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
531 return 1; /* skip this altsetting */
532 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
533 return 1; /* skip this altsetting */
534 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
535 return 1; /* skip this altsetting */
536 }
537 }
538 snd_printdd(KERN_INFO
539 "using altsetting %d for interface %d config %d\n",
540 altno, iface, chip->setup);
541 return 0; /* keep this altsetting */
542 }
543
544 static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
545 int iface,
546 int altno)
547 {
548 /* Reset ALL ifaces to 0 altsetting.
549 * Call it for every possible altsetting of every interface.
550 */
551 usb_set_interface(chip->dev, iface, 0);
552
553 if (chip->setup & MAUDIO_SET) {
554 unsigned int mask;
555 if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
556 return 1; /* skip this altsetting */
557 if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
558 return 1; /* skip this altsetting */
559 mask = chip->setup & MAUDIO_SET_MASK;
560 if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
561 return 1; /* skip this altsetting */
562 if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
563 return 1; /* skip this altsetting */
564 if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
565 return 1; /* skip this altsetting */
566 if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
567 return 1; /* skip this altsetting */
568 }
569
570 return 0; /* keep this altsetting */
571 }
572
573
574 static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
575 int iface, int altno)
576 {
577 /* Reset ALL ifaces to 0 altsetting.
578 * Call it for every possible altsetting of every interface.
579 */
580 usb_set_interface(chip->dev, iface, 0);
581
582 /* possible configuration where both inputs and only one output is
583 *used is not supported by the current setup
584 */
585 if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
586 if (chip->setup & MAUDIO_SET_96K) {
587 if (altno != 3 && altno != 6)
588 return 1;
589 } else if (chip->setup & MAUDIO_SET_DI) {
590 if (iface == 4)
591 return 1; /* no analog input */
592 if (altno != 2 && altno != 5)
593 return 1; /* enable only altsets 2 and 5 */
594 } else {
595 if (iface == 5)
596 return 1; /* disable digialt input */
597 if (altno != 2 && altno != 5)
598 return 1; /* enalbe only altsets 2 and 5 */
599 }
600 } else {
601 /* keep only 16-Bit mode */
602 if (altno != 1)
603 return 1;
604 }
605
606 snd_printdd(KERN_INFO
607 "using altsetting %d for interface %d config %d\n",
608 altno, iface, chip->setup);
609 return 0; /* keep this altsetting */
610 }
611
612 int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
613 int iface,
614 int altno)
615 {
616 /* audiophile usb: skip altsets incompatible with device_setup */
617 if (chip->usb_id == USB_ID(0x0763, 0x2003))
618 return audiophile_skip_setting_quirk(chip, iface, altno);
619 /* quattro usb: skip altsets incompatible with device_setup */
620 if (chip->usb_id == USB_ID(0x0763, 0x2001))
621 return quattro_skip_setting_quirk(chip, iface, altno);
622 /* fasttrackpro usb: skip altsets incompatible with device_setup */
623 if (chip->usb_id == USB_ID(0x0763, 0x2012))
624 return fasttrackpro_skip_setting_quirk(chip, iface, altno);
625
626 return 0;
627 }
628
629 int snd_usb_apply_boot_quirk(struct usb_device *dev,
630 struct usb_interface *intf,
631 const struct snd_usb_audio_quirk *quirk)
632 {
633 u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
634 le16_to_cpu(dev->descriptor.idProduct));
635
636 switch (id) {
637 case USB_ID(0x041e, 0x3000):
638 /* SB Extigy needs special boot-up sequence */
639 /* if more models come, this will go to the quirk list. */
640 return snd_usb_extigy_boot_quirk(dev, intf);
641
642 case USB_ID(0x041e, 0x3020):
643 /* SB Audigy 2 NX needs its own boot-up magic, too */
644 return snd_usb_audigy2nx_boot_quirk(dev);
645
646 case USB_ID(0x10f5, 0x0200):
647 /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
648 return snd_usb_cm106_boot_quirk(dev);
649
650 case USB_ID(0x0d8c, 0x0102):
651 /* C-Media CM6206 / CM106-Like Sound Device */
652 case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
653 return snd_usb_cm6206_boot_quirk(dev);
654
655 case USB_ID(0x133e, 0x0815):
656 /* Access Music VirusTI Desktop */
657 return snd_usb_accessmusic_boot_quirk(dev);
658
659 case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
660 case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
661 case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
662 return snd_usb_nativeinstruments_boot_quirk(dev);
663 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
664 return snd_usb_fasttrackpro_boot_quirk(dev);
665 }
666
667 return 0;
668 }
669
670 /*
671 * check if the device uses big-endian samples
672 */
673 int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
674 {
675 /* it depends on altsetting wether the device is big-endian or not */
676 switch (chip->usb_id) {
677 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
678 if (fp->altsetting == 2 || fp->altsetting == 3 ||
679 fp->altsetting == 5 || fp->altsetting == 6)
680 return 1;
681 break;
682 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
683 if (chip->setup == 0x00 ||
684 fp->altsetting == 1 || fp->altsetting == 2 ||
685 fp->altsetting == 3)
686 return 1;
687 break;
688 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
689 if (fp->altsetting == 2 || fp->altsetting == 3 ||
690 fp->altsetting == 5 || fp->altsetting == 6)
691 return 1;
692 break;
693 }
694 return 0;
695 }
696
697 /*
698 * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
699 * not for interface.
700 */
701
702 enum {
703 EMU_QUIRK_SR_44100HZ = 0,
704 EMU_QUIRK_SR_48000HZ,
705 EMU_QUIRK_SR_88200HZ,
706 EMU_QUIRK_SR_96000HZ,
707 EMU_QUIRK_SR_176400HZ,
708 EMU_QUIRK_SR_192000HZ
709 };
710
711 static void set_format_emu_quirk(struct snd_usb_substream *subs,
712 struct audioformat *fmt)
713 {
714 unsigned char emu_samplerate_id = 0;
715
716 /* When capture is active
717 * sample rate shouldn't be changed
718 * by playback substream
719 */
720 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
721 if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
722 return;
723 }
724
725 switch (fmt->rate_min) {
726 case 48000:
727 emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
728 break;
729 case 88200:
730 emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
731 break;
732 case 96000:
733 emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
734 break;
735 case 176400:
736 emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
737 break;
738 case 192000:
739 emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
740 break;
741 default:
742 emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
743 break;
744 }
745 snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
746 }
747
748 void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
749 struct audioformat *fmt)
750 {
751 switch (subs->stream->chip->usb_id) {
752 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
753 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
754 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
755 case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
756 set_format_emu_quirk(subs, fmt);
757 break;
758 }
759 }
760