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