Commit | Line | Data |
---|---|---|
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> | |
aafe77cc | 21 | #include <linux/usb/midi.h> |
e5779998 | 22 | |
9e38658f | 23 | #include <sound/control.h> |
e5779998 DM |
24 | #include <sound/core.h> |
25 | #include <sound/info.h> | |
26 | #include <sound/pcm.h> | |
27 | ||
28 | #include "usbaudio.h" | |
29 | #include "card.h" | |
f0b5e634 | 30 | #include "mixer.h" |
7b1eda22 | 31 | #include "mixer_quirks.h" |
e5779998 DM |
32 | #include "midi.h" |
33 | #include "quirks.h" | |
34 | #include "helper.h" | |
35 | #include "endpoint.h" | |
36 | #include "pcm.h" | |
3d8d4dcf | 37 | #include "clock.h" |
e8e8babf | 38 | #include "stream.h" |
e5779998 DM |
39 | |
40 | /* | |
41 | * handle the quirks for the contained interfaces | |
42 | */ | |
43 | static int create_composite_quirk(struct snd_usb_audio *chip, | |
44 | struct usb_interface *iface, | |
45 | struct usb_driver *driver, | |
46 | const struct snd_usb_audio_quirk *quirk) | |
47 | { | |
48 | int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber; | |
49 | int err; | |
50 | ||
51 | for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) { | |
52 | iface = usb_ifnum_to_if(chip->dev, quirk->ifnum); | |
53 | if (!iface) | |
54 | continue; | |
55 | if (quirk->ifnum != probed_ifnum && | |
56 | usb_interface_claimed(iface)) | |
57 | continue; | |
58 | err = snd_usb_create_quirk(chip, iface, driver, quirk); | |
59 | if (err < 0) | |
60 | return err; | |
d4b8fc66 TI |
61 | } |
62 | ||
63 | for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) { | |
64 | iface = usb_ifnum_to_if(chip->dev, quirk->ifnum); | |
65 | if (!iface) | |
66 | continue; | |
67 | if (quirk->ifnum != probed_ifnum && | |
68 | !usb_interface_claimed(iface)) | |
e5779998 DM |
69 | usb_driver_claim_interface(driver, iface, (void *)-1L); |
70 | } | |
d4b8fc66 | 71 | |
e5779998 DM |
72 | return 0; |
73 | } | |
74 | ||
75 | static int ignore_interface_quirk(struct snd_usb_audio *chip, | |
76 | struct usb_interface *iface, | |
77 | struct usb_driver *driver, | |
78 | const struct snd_usb_audio_quirk *quirk) | |
79 | { | |
80 | return 0; | |
81 | } | |
82 | ||
83 | ||
84 | /* | |
85 | * Allow alignment on audio sub-slot (channel samples) rather than | |
86 | * on audio slots (audio frames) | |
87 | */ | |
88 | static int create_align_transfer_quirk(struct snd_usb_audio *chip, | |
89 | struct usb_interface *iface, | |
90 | struct usb_driver *driver, | |
91 | const struct snd_usb_audio_quirk *quirk) | |
92 | { | |
93 | chip->txfr_quirk = 1; | |
94 | return 1; /* Continue with creating streams and mixer */ | |
95 | } | |
96 | ||
97 | static int create_any_midi_quirk(struct snd_usb_audio *chip, | |
98 | struct usb_interface *intf, | |
99 | struct usb_driver *driver, | |
100 | const struct snd_usb_audio_quirk *quirk) | |
101 | { | |
102 | return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk); | |
103 | } | |
104 | ||
105 | /* | |
106 | * create a stream for an interface with proper descriptors | |
107 | */ | |
108 | static int create_standard_audio_quirk(struct snd_usb_audio *chip, | |
109 | struct usb_interface *iface, | |
110 | struct usb_driver *driver, | |
111 | const struct snd_usb_audio_quirk *quirk) | |
112 | { | |
113 | struct usb_host_interface *alts; | |
114 | struct usb_interface_descriptor *altsd; | |
115 | int err; | |
116 | ||
117 | alts = &iface->altsetting[0]; | |
118 | altsd = get_iface_desc(alts); | |
e8e8babf | 119 | err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber); |
e5779998 | 120 | if (err < 0) { |
0ba41d91 | 121 | usb_audio_err(chip, "cannot setup if %d: error %d\n", |
e5779998 DM |
122 | altsd->bInterfaceNumber, err); |
123 | return err; | |
124 | } | |
125 | /* reset the current interface */ | |
126 | usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0); | |
127 | return 0; | |
128 | } | |
129 | ||
130 | /* | |
131 | * create a stream for an endpoint/altsetting without proper descriptors | |
132 | */ | |
133 | static int create_fixed_stream_quirk(struct snd_usb_audio *chip, | |
134 | struct usb_interface *iface, | |
135 | struct usb_driver *driver, | |
136 | const struct snd_usb_audio_quirk *quirk) | |
137 | { | |
138 | struct audioformat *fp; | |
139 | struct usb_host_interface *alts; | |
42d4ab83 | 140 | struct usb_interface_descriptor *altsd; |
e5779998 DM |
141 | int stream, err; |
142 | unsigned *rate_table = NULL; | |
143 | ||
144 | fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL); | |
8866f405 | 145 | if (!fp) { |
0ba41d91 | 146 | usb_audio_err(chip, "cannot memdup\n"); |
e5779998 DM |
147 | return -ENOMEM; |
148 | } | |
8866f405 XW |
149 | if (fp->nr_rates > MAX_NR_RATES) { |
150 | kfree(fp); | |
151 | return -EINVAL; | |
152 | } | |
e5779998 | 153 | if (fp->nr_rates > 0) { |
43df2a57 TM |
154 | rate_table = kmemdup(fp->rate_table, |
155 | sizeof(int) * fp->nr_rates, GFP_KERNEL); | |
e5779998 DM |
156 | if (!rate_table) { |
157 | kfree(fp); | |
158 | return -ENOMEM; | |
159 | } | |
e5779998 DM |
160 | fp->rate_table = rate_table; |
161 | } | |
162 | ||
163 | stream = (fp->endpoint & USB_DIR_IN) | |
164 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | |
e8e8babf | 165 | err = snd_usb_add_audio_stream(chip, stream, fp); |
e5779998 DM |
166 | if (err < 0) { |
167 | kfree(fp); | |
168 | kfree(rate_table); | |
169 | return err; | |
170 | } | |
171 | if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber || | |
172 | fp->altset_idx >= iface->num_altsetting) { | |
173 | kfree(fp); | |
174 | kfree(rate_table); | |
175 | return -EINVAL; | |
176 | } | |
177 | alts = &iface->altsetting[fp->altset_idx]; | |
42d4ab83 EZ |
178 | altsd = get_iface_desc(alts); |
179 | fp->protocol = altsd->bInterfaceProtocol; | |
180 | ||
59ea586f MH |
181 | if (fp->datainterval == 0) |
182 | fp->datainterval = snd_usb_parse_datainterval(chip, alts); | |
183 | if (fp->maxpacksize == 0) | |
184 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | |
e5779998 | 185 | usb_set_interface(chip->dev, fp->iface, 0); |
767d75ad DM |
186 | snd_usb_init_pitch(chip, fp->iface, alts, fp); |
187 | snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max); | |
e5779998 DM |
188 | return 0; |
189 | } | |
190 | ||
aafe77cc CL |
191 | static int create_auto_pcm_quirk(struct snd_usb_audio *chip, |
192 | struct usb_interface *iface, | |
193 | struct usb_driver *driver) | |
194 | { | |
195 | struct usb_host_interface *alts; | |
196 | struct usb_interface_descriptor *altsd; | |
197 | struct usb_endpoint_descriptor *epd; | |
198 | struct uac1_as_header_descriptor *ashd; | |
199 | struct uac_format_type_i_discrete_descriptor *fmtd; | |
200 | ||
201 | /* | |
202 | * Most Roland/Yamaha audio streaming interfaces have more or less | |
203 | * standard descriptors, but older devices might lack descriptors, and | |
204 | * future ones might change, so ensure that we fail silently if the | |
205 | * interface doesn't look exactly right. | |
206 | */ | |
207 | ||
208 | /* must have a non-zero altsetting for streaming */ | |
209 | if (iface->num_altsetting < 2) | |
210 | return -ENODEV; | |
211 | alts = &iface->altsetting[1]; | |
212 | altsd = get_iface_desc(alts); | |
213 | ||
214 | /* must have an isochronous endpoint for streaming */ | |
215 | if (altsd->bNumEndpoints < 1) | |
216 | return -ENODEV; | |
217 | epd = get_endpoint(alts, 0); | |
218 | if (!usb_endpoint_xfer_isoc(epd)) | |
219 | return -ENODEV; | |
220 | ||
221 | /* must have format descriptors */ | |
222 | ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, | |
223 | UAC_AS_GENERAL); | |
224 | fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, | |
225 | UAC_FORMAT_TYPE); | |
226 | if (!ashd || ashd->bLength < 7 || | |
227 | !fmtd || fmtd->bLength < 8) | |
228 | return -ENODEV; | |
229 | ||
230 | return create_standard_audio_quirk(chip, iface, driver, NULL); | |
231 | } | |
232 | ||
233 | static int create_yamaha_midi_quirk(struct snd_usb_audio *chip, | |
234 | struct usb_interface *iface, | |
235 | struct usb_driver *driver, | |
236 | struct usb_host_interface *alts) | |
237 | { | |
238 | static const struct snd_usb_audio_quirk yamaha_midi_quirk = { | |
239 | .type = QUIRK_MIDI_YAMAHA | |
240 | }; | |
241 | struct usb_midi_in_jack_descriptor *injd; | |
242 | struct usb_midi_out_jack_descriptor *outjd; | |
243 | ||
244 | /* must have some valid jack descriptors */ | |
245 | injd = snd_usb_find_csint_desc(alts->extra, alts->extralen, | |
246 | NULL, USB_MS_MIDI_IN_JACK); | |
247 | outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen, | |
248 | NULL, USB_MS_MIDI_OUT_JACK); | |
249 | if (!injd && !outjd) | |
250 | return -ENODEV; | |
251 | if (injd && (injd->bLength < 5 || | |
252 | (injd->bJackType != USB_MS_EMBEDDED && | |
253 | injd->bJackType != USB_MS_EXTERNAL))) | |
254 | return -ENODEV; | |
255 | if (outjd && (outjd->bLength < 6 || | |
256 | (outjd->bJackType != USB_MS_EMBEDDED && | |
257 | outjd->bJackType != USB_MS_EXTERNAL))) | |
258 | return -ENODEV; | |
259 | return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk); | |
260 | } | |
261 | ||
262 | static int create_roland_midi_quirk(struct snd_usb_audio *chip, | |
263 | struct usb_interface *iface, | |
264 | struct usb_driver *driver, | |
265 | struct usb_host_interface *alts) | |
266 | { | |
267 | static const struct snd_usb_audio_quirk roland_midi_quirk = { | |
268 | .type = QUIRK_MIDI_ROLAND | |
269 | }; | |
270 | u8 *roland_desc = NULL; | |
271 | ||
272 | /* might have a vendor-specific descriptor <06 24 F1 02 ...> */ | |
273 | for (;;) { | |
274 | roland_desc = snd_usb_find_csint_desc(alts->extra, | |
275 | alts->extralen, | |
276 | roland_desc, 0xf1); | |
277 | if (!roland_desc) | |
278 | return -ENODEV; | |
279 | if (roland_desc[0] < 6 || roland_desc[3] != 2) | |
280 | continue; | |
281 | return create_any_midi_quirk(chip, iface, driver, | |
282 | &roland_midi_quirk); | |
283 | } | |
284 | } | |
285 | ||
286 | static int create_std_midi_quirk(struct snd_usb_audio *chip, | |
287 | struct usb_interface *iface, | |
288 | struct usb_driver *driver, | |
289 | struct usb_host_interface *alts) | |
290 | { | |
291 | struct usb_ms_header_descriptor *mshd; | |
292 | struct usb_ms_endpoint_descriptor *msepd; | |
293 | ||
294 | /* must have the MIDIStreaming interface header descriptor*/ | |
295 | mshd = (struct usb_ms_header_descriptor *)alts->extra; | |
296 | if (alts->extralen < 7 || | |
297 | mshd->bLength < 7 || | |
298 | mshd->bDescriptorType != USB_DT_CS_INTERFACE || | |
299 | mshd->bDescriptorSubtype != USB_MS_HEADER) | |
300 | return -ENODEV; | |
301 | /* must have the MIDIStreaming endpoint descriptor*/ | |
302 | msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra; | |
303 | if (alts->endpoint[0].extralen < 4 || | |
304 | msepd->bLength < 4 || | |
305 | msepd->bDescriptorType != USB_DT_CS_ENDPOINT || | |
306 | msepd->bDescriptorSubtype != UAC_MS_GENERAL || | |
307 | msepd->bNumEmbMIDIJack < 1 || | |
308 | msepd->bNumEmbMIDIJack > 16) | |
309 | return -ENODEV; | |
310 | ||
311 | return create_any_midi_quirk(chip, iface, driver, NULL); | |
312 | } | |
313 | ||
314 | static int create_auto_midi_quirk(struct snd_usb_audio *chip, | |
315 | struct usb_interface *iface, | |
316 | struct usb_driver *driver) | |
317 | { | |
318 | struct usb_host_interface *alts; | |
319 | struct usb_interface_descriptor *altsd; | |
320 | struct usb_endpoint_descriptor *epd; | |
321 | int err; | |
322 | ||
323 | alts = &iface->altsetting[0]; | |
324 | altsd = get_iface_desc(alts); | |
325 | ||
326 | /* must have at least one bulk/interrupt endpoint for streaming */ | |
327 | if (altsd->bNumEndpoints < 1) | |
328 | return -ENODEV; | |
329 | epd = get_endpoint(alts, 0); | |
aa773bfe | 330 | if (!usb_endpoint_xfer_bulk(epd) && |
aafe77cc CL |
331 | !usb_endpoint_xfer_int(epd)) |
332 | return -ENODEV; | |
333 | ||
334 | switch (USB_ID_VENDOR(chip->usb_id)) { | |
335 | case 0x0499: /* Yamaha */ | |
336 | err = create_yamaha_midi_quirk(chip, iface, driver, alts); | |
aa773bfe | 337 | if (err != -ENODEV) |
aafe77cc CL |
338 | return err; |
339 | break; | |
340 | case 0x0582: /* Roland */ | |
341 | err = create_roland_midi_quirk(chip, iface, driver, alts); | |
aa773bfe | 342 | if (err != -ENODEV) |
aafe77cc CL |
343 | return err; |
344 | break; | |
345 | } | |
346 | ||
347 | return create_std_midi_quirk(chip, iface, driver, alts); | |
348 | } | |
349 | ||
350 | static int create_autodetect_quirk(struct snd_usb_audio *chip, | |
351 | struct usb_interface *iface, | |
b1ce7ba6 | 352 | struct usb_driver *driver) |
aafe77cc CL |
353 | { |
354 | int err; | |
355 | ||
356 | err = create_auto_pcm_quirk(chip, iface, driver); | |
357 | if (err == -ENODEV) | |
358 | err = create_auto_midi_quirk(chip, iface, driver); | |
359 | return err; | |
360 | } | |
361 | ||
b1ce7ba6 CL |
362 | static int create_autodetect_quirks(struct snd_usb_audio *chip, |
363 | struct usb_interface *iface, | |
364 | struct usb_driver *driver, | |
365 | const struct snd_usb_audio_quirk *quirk) | |
366 | { | |
367 | int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber; | |
368 | int ifcount, ifnum, err; | |
369 | ||
370 | err = create_autodetect_quirk(chip, iface, driver); | |
371 | if (err < 0) | |
372 | return err; | |
373 | ||
374 | /* | |
375 | * ALSA PCM playback/capture devices cannot be registered in two steps, | |
376 | * so we have to claim the other corresponding interface here. | |
377 | */ | |
378 | ifcount = chip->dev->actconfig->desc.bNumInterfaces; | |
379 | for (ifnum = 0; ifnum < ifcount; ifnum++) { | |
380 | if (ifnum == probed_ifnum || quirk->ifnum >= 0) | |
381 | continue; | |
382 | iface = usb_ifnum_to_if(chip->dev, ifnum); | |
383 | if (!iface || | |
384 | usb_interface_claimed(iface) || | |
385 | get_iface_desc(iface->altsetting)->bInterfaceClass != | |
386 | USB_CLASS_VENDOR_SPEC) | |
387 | continue; | |
388 | ||
389 | err = create_autodetect_quirk(chip, iface, driver); | |
390 | if (err >= 0) | |
391 | usb_driver_claim_interface(driver, iface, (void *)-1L); | |
392 | } | |
393 | ||
394 | return 0; | |
395 | } | |
396 | ||
e5779998 DM |
397 | /* |
398 | * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface. | |
399 | * The only way to detect the sample rate is by looking at wMaxPacketSize. | |
400 | */ | |
401 | static int create_uaxx_quirk(struct snd_usb_audio *chip, | |
402 | struct usb_interface *iface, | |
403 | struct usb_driver *driver, | |
404 | const struct snd_usb_audio_quirk *quirk) | |
405 | { | |
406 | static const struct audioformat ua_format = { | |
015eb0b0 | 407 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, |
e5779998 DM |
408 | .channels = 2, |
409 | .fmt_type = UAC_FORMAT_TYPE_I, | |
410 | .altsetting = 1, | |
411 | .altset_idx = 1, | |
412 | .rates = SNDRV_PCM_RATE_CONTINUOUS, | |
413 | }; | |
414 | struct usb_host_interface *alts; | |
415 | struct usb_interface_descriptor *altsd; | |
416 | struct audioformat *fp; | |
417 | int stream, err; | |
418 | ||
419 | /* both PCM and MIDI interfaces have 2 or more altsettings */ | |
420 | if (iface->num_altsetting < 2) | |
421 | return -ENXIO; | |
422 | alts = &iface->altsetting[1]; | |
423 | altsd = get_iface_desc(alts); | |
424 | ||
425 | if (altsd->bNumEndpoints == 2) { | |
426 | static const struct snd_usb_midi_endpoint_info ua700_ep = { | |
427 | .out_cables = 0x0003, | |
428 | .in_cables = 0x0003 | |
429 | }; | |
430 | static const struct snd_usb_audio_quirk ua700_quirk = { | |
431 | .type = QUIRK_MIDI_FIXED_ENDPOINT, | |
432 | .data = &ua700_ep | |
433 | }; | |
434 | static const struct snd_usb_midi_endpoint_info uaxx_ep = { | |
435 | .out_cables = 0x0001, | |
436 | .in_cables = 0x0001 | |
437 | }; | |
438 | static const struct snd_usb_audio_quirk uaxx_quirk = { | |
439 | .type = QUIRK_MIDI_FIXED_ENDPOINT, | |
440 | .data = &uaxx_ep | |
441 | }; | |
442 | const struct snd_usb_audio_quirk *quirk = | |
443 | chip->usb_id == USB_ID(0x0582, 0x002b) | |
444 | ? &ua700_quirk : &uaxx_quirk; | |
445 | return snd_usbmidi_create(chip->card, iface, | |
446 | &chip->midi_list, quirk); | |
447 | } | |
448 | ||
449 | if (altsd->bNumEndpoints != 1) | |
450 | return -ENXIO; | |
451 | ||
43df2a57 | 452 | fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL); |
e5779998 DM |
453 | if (!fp) |
454 | return -ENOMEM; | |
e5779998 DM |
455 | |
456 | fp->iface = altsd->bInterfaceNumber; | |
457 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; | |
458 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; | |
459 | fp->datainterval = 0; | |
460 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); | |
461 | ||
462 | switch (fp->maxpacksize) { | |
463 | case 0x120: | |
464 | fp->rate_max = fp->rate_min = 44100; | |
465 | break; | |
466 | case 0x138: | |
467 | case 0x140: | |
468 | fp->rate_max = fp->rate_min = 48000; | |
469 | break; | |
470 | case 0x258: | |
471 | case 0x260: | |
472 | fp->rate_max = fp->rate_min = 96000; | |
473 | break; | |
474 | default: | |
0ba41d91 | 475 | usb_audio_err(chip, "unknown sample rate\n"); |
e5779998 DM |
476 | kfree(fp); |
477 | return -ENXIO; | |
478 | } | |
479 | ||
480 | stream = (fp->endpoint & USB_DIR_IN) | |
481 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | |
e8e8babf | 482 | err = snd_usb_add_audio_stream(chip, stream, fp); |
e5779998 DM |
483 | if (err < 0) { |
484 | kfree(fp); | |
485 | return err; | |
486 | } | |
487 | usb_set_interface(chip->dev, fp->iface, 0); | |
488 | return 0; | |
489 | } | |
490 | ||
014950b0 DM |
491 | /* |
492 | * Create a standard mixer for the specified interface. | |
493 | */ | |
494 | static int create_standard_mixer_quirk(struct snd_usb_audio *chip, | |
495 | struct usb_interface *iface, | |
496 | struct usb_driver *driver, | |
497 | const struct snd_usb_audio_quirk *quirk) | |
498 | { | |
499 | if (quirk->ifnum < 0) | |
500 | return 0; | |
501 | ||
502 | return snd_usb_create_mixer(chip, quirk->ifnum, 0); | |
503 | } | |
504 | ||
e5779998 DM |
505 | /* |
506 | * audio-interface quirks | |
507 | * | |
508 | * returns zero if no standard audio/MIDI parsing is needed. | |
25985edc | 509 | * returns a positive value if standard audio/midi interfaces are parsed |
e5779998 DM |
510 | * after this. |
511 | * returns a negative value at error. | |
512 | */ | |
513 | int snd_usb_create_quirk(struct snd_usb_audio *chip, | |
514 | struct usb_interface *iface, | |
515 | struct usb_driver *driver, | |
516 | const struct snd_usb_audio_quirk *quirk) | |
517 | { | |
518 | typedef int (*quirk_func_t)(struct snd_usb_audio *, | |
519 | struct usb_interface *, | |
520 | struct usb_driver *, | |
521 | const struct snd_usb_audio_quirk *); | |
522 | static const quirk_func_t quirk_funcs[] = { | |
523 | [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk, | |
524 | [QUIRK_COMPOSITE] = create_composite_quirk, | |
b1ce7ba6 | 525 | [QUIRK_AUTODETECT] = create_autodetect_quirks, |
e5779998 DM |
526 | [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk, |
527 | [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk, | |
528 | [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk, | |
aafe77cc | 529 | [QUIRK_MIDI_ROLAND] = create_any_midi_quirk, |
e5779998 DM |
530 | [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk, |
531 | [QUIRK_MIDI_NOVATION] = create_any_midi_quirk, | |
c7f57216 | 532 | [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk, |
e5779998 DM |
533 | [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, |
534 | [QUIRK_MIDI_CME] = create_any_midi_quirk, | |
4434ade8 | 535 | [QUIRK_MIDI_AKAI] = create_any_midi_quirk, |
1ef0e0a0 | 536 | [QUIRK_MIDI_FTDI] = create_any_midi_quirk, |
e5779998 DM |
537 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, |
538 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, | |
539 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, | |
014950b0 DM |
540 | [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk, |
541 | [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk, | |
e5779998 DM |
542 | }; |
543 | ||
544 | if (quirk->type < QUIRK_TYPE_COUNT) { | |
545 | return quirk_funcs[quirk->type](chip, iface, driver, quirk); | |
546 | } else { | |
0ba41d91 | 547 | usb_audio_err(chip, "invalid quirk type %d\n", quirk->type); |
e5779998 DM |
548 | return -ENXIO; |
549 | } | |
550 | } | |
551 | ||
552 | /* | |
553 | * boot quirks | |
554 | */ | |
555 | ||
556 | #define EXTIGY_FIRMWARE_SIZE_OLD 794 | |
557 | #define EXTIGY_FIRMWARE_SIZE_NEW 483 | |
558 | ||
559 | static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf) | |
560 | { | |
561 | struct usb_host_config *config = dev->actconfig; | |
562 | int err; | |
563 | ||
564 | if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD || | |
565 | le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) { | |
0ba41d91 | 566 | dev_dbg(&dev->dev, "sending Extigy boot sequence...\n"); |
e5779998 DM |
567 | /* Send message to force it to reconnect with full interface. */ |
568 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0), | |
17d900c4 | 569 | 0x10, 0x43, 0x0001, 0x000a, NULL, 0); |
0ba41d91 TI |
570 | if (err < 0) |
571 | dev_dbg(&dev->dev, "error sending boot message: %d\n", err); | |
e5779998 DM |
572 | err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, |
573 | &dev->descriptor, sizeof(dev->descriptor)); | |
574 | config = dev->actconfig; | |
0ba41d91 TI |
575 | if (err < 0) |
576 | dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err); | |
e5779998 | 577 | err = usb_reset_configuration(dev); |
0ba41d91 TI |
578 | if (err < 0) |
579 | dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err); | |
580 | dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n", | |
e5779998 DM |
581 | le16_to_cpu(get_cfg_desc(config)->wTotalLength)); |
582 | return -ENODEV; /* quit this anyway */ | |
583 | } | |
584 | return 0; | |
585 | } | |
586 | ||
587 | static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev) | |
588 | { | |
589 | u8 buf = 1; | |
590 | ||
591 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, | |
592 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
17d900c4 | 593 | 0, 0, &buf, 1); |
e5779998 DM |
594 | if (buf == 0) { |
595 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29, | |
596 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
17d900c4 | 597 | 1, 2000, NULL, 0); |
e5779998 DM |
598 | return -ENODEV; |
599 | } | |
600 | return 0; | |
601 | } | |
602 | ||
0f5733b0 GP |
603 | static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev) |
604 | { | |
605 | int err; | |
606 | ||
607 | if (dev->actconfig->desc.bConfigurationValue == 1) { | |
0ba41d91 | 608 | dev_info(&dev->dev, |
0f5733b0 GP |
609 | "Fast Track Pro switching to config #2\n"); |
610 | /* This function has to be available by the usb core module. | |
611 | * if it is not avialable the boot quirk has to be left out | |
612 | * and the configuration has to be set by udev or hotplug | |
613 | * rules | |
614 | */ | |
615 | err = usb_driver_set_configuration(dev, 2); | |
b98ae272 | 616 | if (err < 0) |
0ba41d91 TI |
617 | dev_dbg(&dev->dev, |
618 | "error usb_driver_set_configuration: %d\n", | |
619 | err); | |
b98ae272 DH |
620 | /* Always return an error, so that we stop creating a device |
621 | that will just be destroyed and recreated with a new | |
622 | configuration */ | |
623 | return -ENODEV; | |
0f5733b0 | 624 | } else |
0ba41d91 | 625 | dev_info(&dev->dev, "Fast Track Pro config OK\n"); |
0f5733b0 GP |
626 | |
627 | return 0; | |
628 | } | |
629 | ||
e5779998 DM |
630 | /* |
631 | * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely | |
632 | * documented in the device's data sheet. | |
633 | */ | |
634 | static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value) | |
635 | { | |
636 | u8 buf[4]; | |
637 | buf[0] = 0x20; | |
638 | buf[1] = value & 0xff; | |
639 | buf[2] = (value >> 8) & 0xff; | |
640 | buf[3] = reg; | |
641 | return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION, | |
642 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, | |
17d900c4 | 643 | 0, 0, &buf, 4); |
e5779998 DM |
644 | } |
645 | ||
646 | static int snd_usb_cm106_boot_quirk(struct usb_device *dev) | |
647 | { | |
648 | /* | |
649 | * Enable line-out driver mode, set headphone source to front | |
650 | * channels, enable stereo mic. | |
651 | */ | |
652 | return snd_usb_cm106_write_int_reg(dev, 2, 0x8004); | |
653 | } | |
654 | ||
655 | /* | |
656 | * C-Media CM6206 is based on CM106 with two additional | |
657 | * registers that are not documented in the data sheet. | |
658 | * Values here are chosen based on sniffing USB traffic | |
659 | * under Windows. | |
660 | */ | |
661 | static int snd_usb_cm6206_boot_quirk(struct usb_device *dev) | |
662 | { | |
dac8f847 | 663 | int err = 0, reg; |
157186bc | 664 | int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000}; |
e5779998 DM |
665 | |
666 | for (reg = 0; reg < ARRAY_SIZE(val); reg++) { | |
667 | err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]); | |
668 | if (err < 0) | |
669 | return err; | |
670 | } | |
671 | ||
672 | return err; | |
673 | } | |
674 | ||
19570d74 TI |
675 | /* quirk for Plantronics GameCom 780 with CM6302 chip */ |
676 | static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev) | |
677 | { | |
678 | /* set the initial volume and don't change; other values are either | |
679 | * too loud or silent due to firmware bug (bko#65251) | |
680 | */ | |
542baf94 | 681 | u8 buf[2] = { 0x74, 0xe3 }; |
19570d74 TI |
682 | return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, |
683 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, | |
684 | UAC_FU_VOLUME << 8, 9 << 8, buf, 2); | |
685 | } | |
686 | ||
5e212332 MH |
687 | /* |
688 | * Novation Twitch DJ controller | |
11e424e8 | 689 | * Focusrite Novation Saffire 6 USB audio card |
5e212332 | 690 | */ |
11e424e8 | 691 | static int snd_usb_novation_boot_quirk(struct usb_device *dev) |
5e212332 MH |
692 | { |
693 | /* preemptively set up the device because otherwise the | |
694 | * raw MIDI endpoints are not active */ | |
695 | usb_set_interface(dev, 0, 1); | |
696 | return 0; | |
697 | } | |
698 | ||
e5779998 DM |
699 | /* |
700 | * This call will put the synth in "USB send" mode, i.e it will send MIDI | |
701 | * messages through USB (this is disabled at startup). The synth will | |
702 | * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB | |
703 | * sign on its LCD. Values here are chosen based on sniffing USB traffic | |
704 | * under Windows. | |
705 | */ | |
706 | static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev) | |
707 | { | |
708 | int err, actual_length; | |
709 | ||
710 | /* "midi send" enable */ | |
711 | static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 }; | |
712 | ||
713 | void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL); | |
714 | if (!buf) | |
715 | return -ENOMEM; | |
716 | err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf, | |
717 | ARRAY_SIZE(seq), &actual_length, 1000); | |
718 | kfree(buf); | |
719 | if (err < 0) | |
720 | return err; | |
721 | ||
722 | return 0; | |
723 | } | |
724 | ||
54a8c500 DM |
725 | /* |
726 | * Some sound cards from Native Instruments are in fact compliant to the USB | |
727 | * audio standard of version 2 and other approved USB standards, even though | |
728 | * they come up as vendor-specific device when first connected. | |
729 | * | |
730 | * However, they can be told to come up with a new set of descriptors | |
731 | * upon their next enumeration, and the interfaces announced by the new | |
732 | * descriptors will then be handled by the kernel's class drivers. As the | |
733 | * product ID will also change, no further checks are required. | |
734 | */ | |
735 | ||
736 | static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev) | |
737 | { | |
738 | int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | |
739 | 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
889d6684 | 740 | 1, 0, NULL, 0, 1000); |
54a8c500 DM |
741 | |
742 | if (ret < 0) | |
743 | return ret; | |
744 | ||
745 | usb_reset_device(dev); | |
746 | ||
747 | /* return -EAGAIN, so the creation of an audio interface for this | |
748 | * temporary device is aborted. The device will reconnect with a | |
749 | * new product ID */ | |
750 | return -EAGAIN; | |
751 | } | |
752 | ||
cb99864d DZ |
753 | static void mbox2_setup_48_24_magic(struct usb_device *dev) |
754 | { | |
755 | u8 srate[3]; | |
756 | u8 temp[12]; | |
757 | ||
758 | /* Choose 48000Hz permanently */ | |
759 | srate[0] = 0x80; | |
760 | srate[1] = 0xbb; | |
761 | srate[2] = 0x00; | |
762 | ||
763 | /* Send the magic! */ | |
764 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), | |
765 | 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003); | |
766 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), | |
767 | 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003); | |
768 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), | |
769 | 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003); | |
770 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), | |
771 | 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003); | |
772 | return; | |
773 | } | |
774 | ||
775 | /* Digidesign Mbox 2 needs to load firmware onboard | |
776 | * and driver must wait a few seconds for initialisation. | |
777 | */ | |
778 | ||
779 | #define MBOX2_FIRMWARE_SIZE 646 | |
780 | #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */ | |
781 | #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */ | |
782 | ||
b7b435e8 | 783 | static int snd_usb_mbox2_boot_quirk(struct usb_device *dev) |
cb99864d DZ |
784 | { |
785 | struct usb_host_config *config = dev->actconfig; | |
786 | int err; | |
4909a0ca | 787 | u8 bootresponse[0x12]; |
cb99864d DZ |
788 | int fwsize; |
789 | int count; | |
790 | ||
791 | fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength); | |
792 | ||
793 | if (fwsize != MBOX2_FIRMWARE_SIZE) { | |
0ba41d91 | 794 | dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize); |
cb99864d DZ |
795 | return -ENODEV; |
796 | } | |
797 | ||
0ba41d91 | 798 | dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n"); |
cb99864d DZ |
799 | |
800 | count = 0; | |
b7b435e8 DZ |
801 | bootresponse[0] = MBOX2_BOOT_LOADING; |
802 | while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) { | |
cb99864d DZ |
803 | msleep(500); /* 0.5 second delay */ |
804 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), | |
805 | /* Control magic - load onboard firmware */ | |
806 | 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012); | |
b7b435e8 | 807 | if (bootresponse[0] == MBOX2_BOOT_READY) |
cb99864d | 808 | break; |
0ba41d91 | 809 | dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n"); |
cb99864d DZ |
810 | count++; |
811 | } | |
812 | ||
b7b435e8 | 813 | if (bootresponse[0] != MBOX2_BOOT_READY) { |
0ba41d91 | 814 | dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]); |
cb99864d DZ |
815 | return -ENODEV; |
816 | } | |
817 | ||
0ba41d91 | 818 | dev_dbg(&dev->dev, "device initialised!\n"); |
cb99864d DZ |
819 | |
820 | err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, | |
821 | &dev->descriptor, sizeof(dev->descriptor)); | |
822 | config = dev->actconfig; | |
823 | if (err < 0) | |
0ba41d91 | 824 | dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err); |
cb99864d DZ |
825 | |
826 | err = usb_reset_configuration(dev); | |
827 | if (err < 0) | |
0ba41d91 TI |
828 | dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err); |
829 | dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n", | |
cb99864d DZ |
830 | le16_to_cpu(get_cfg_desc(config)->wTotalLength)); |
831 | ||
832 | mbox2_setup_48_24_magic(dev); | |
833 | ||
0ba41d91 | 834 | dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz"); |
cb99864d DZ |
835 | |
836 | return 0; /* Successful boot */ | |
837 | } | |
838 | ||
e5779998 DM |
839 | /* |
840 | * Setup quirks | |
841 | */ | |
0f5733b0 GP |
842 | #define MAUDIO_SET 0x01 /* parse device_setup */ |
843 | #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */ | |
844 | #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */ | |
845 | #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */ | |
846 | #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */ | |
847 | #define MAUDIO_SET_DI 0x10 /* enable Digital Input */ | |
848 | #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */ | |
849 | #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */ | |
850 | #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */ | |
851 | #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */ | |
852 | #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */ | |
853 | ||
854 | static int quattro_skip_setting_quirk(struct snd_usb_audio *chip, | |
855 | int iface, int altno) | |
856 | { | |
857 | /* Reset ALL ifaces to 0 altsetting. | |
858 | * Call it for every possible altsetting of every interface. | |
859 | */ | |
860 | usb_set_interface(chip->dev, iface, 0); | |
861 | if (chip->setup & MAUDIO_SET) { | |
862 | if (chip->setup & MAUDIO_SET_COMPATIBLE) { | |
863 | if (iface != 1 && iface != 2) | |
864 | return 1; /* skip all interfaces but 1 and 2 */ | |
865 | } else { | |
866 | unsigned int mask; | |
867 | if (iface == 1 || iface == 2) | |
868 | return 1; /* skip interfaces 1 and 2 */ | |
869 | if ((chip->setup & MAUDIO_SET_96K) && altno != 1) | |
870 | return 1; /* skip this altsetting */ | |
871 | mask = chip->setup & MAUDIO_SET_MASK; | |
872 | if (mask == MAUDIO_SET_24B_48K_DI && altno != 2) | |
873 | return 1; /* skip this altsetting */ | |
874 | if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3) | |
875 | return 1; /* skip this altsetting */ | |
876 | if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4) | |
877 | return 1; /* skip this altsetting */ | |
878 | } | |
879 | } | |
0ba41d91 | 880 | usb_audio_dbg(chip, |
0f5733b0 GP |
881 | "using altsetting %d for interface %d config %d\n", |
882 | altno, iface, chip->setup); | |
883 | return 0; /* keep this altsetting */ | |
884 | } | |
e5779998 DM |
885 | |
886 | static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip, | |
887 | int iface, | |
888 | int altno) | |
889 | { | |
890 | /* Reset ALL ifaces to 0 altsetting. | |
891 | * Call it for every possible altsetting of every interface. | |
892 | */ | |
893 | usb_set_interface(chip->dev, iface, 0); | |
894 | ||
0f5733b0 GP |
895 | if (chip->setup & MAUDIO_SET) { |
896 | unsigned int mask; | |
897 | if ((chip->setup & MAUDIO_SET_DTS) && altno != 6) | |
e5779998 | 898 | return 1; /* skip this altsetting */ |
0f5733b0 | 899 | if ((chip->setup & MAUDIO_SET_96K) && altno != 1) |
e5779998 | 900 | return 1; /* skip this altsetting */ |
0f5733b0 GP |
901 | mask = chip->setup & MAUDIO_SET_MASK; |
902 | if (mask == MAUDIO_SET_24B_48K_DI && altno != 2) | |
e5779998 | 903 | return 1; /* skip this altsetting */ |
0f5733b0 | 904 | if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3) |
e5779998 | 905 | return 1; /* skip this altsetting */ |
0f5733b0 | 906 | if (mask == MAUDIO_SET_16B_48K_DI && altno != 4) |
e5779998 | 907 | return 1; /* skip this altsetting */ |
0f5733b0 | 908 | if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5) |
e5779998 DM |
909 | return 1; /* skip this altsetting */ |
910 | } | |
911 | ||
912 | return 0; /* keep this altsetting */ | |
913 | } | |
914 | ||
0f5733b0 GP |
915 | static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip, |
916 | int iface, int altno) | |
917 | { | |
918 | /* Reset ALL ifaces to 0 altsetting. | |
919 | * Call it for every possible altsetting of every interface. | |
920 | */ | |
921 | usb_set_interface(chip->dev, iface, 0); | |
922 | ||
923 | /* possible configuration where both inputs and only one output is | |
924 | *used is not supported by the current setup | |
925 | */ | |
926 | if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) { | |
927 | if (chip->setup & MAUDIO_SET_96K) { | |
928 | if (altno != 3 && altno != 6) | |
929 | return 1; | |
930 | } else if (chip->setup & MAUDIO_SET_DI) { | |
931 | if (iface == 4) | |
932 | return 1; /* no analog input */ | |
933 | if (altno != 2 && altno != 5) | |
934 | return 1; /* enable only altsets 2 and 5 */ | |
935 | } else { | |
936 | if (iface == 5) | |
937 | return 1; /* disable digialt input */ | |
938 | if (altno != 2 && altno != 5) | |
939 | return 1; /* enalbe only altsets 2 and 5 */ | |
940 | } | |
941 | } else { | |
942 | /* keep only 16-Bit mode */ | |
943 | if (altno != 1) | |
944 | return 1; | |
945 | } | |
946 | ||
0ba41d91 | 947 | usb_audio_dbg(chip, |
0f5733b0 GP |
948 | "using altsetting %d for interface %d config %d\n", |
949 | altno, iface, chip->setup); | |
950 | return 0; /* keep this altsetting */ | |
951 | } | |
952 | ||
e5779998 DM |
953 | int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip, |
954 | int iface, | |
955 | int altno) | |
956 | { | |
957 | /* audiophile usb: skip altsets incompatible with device_setup */ | |
958 | if (chip->usb_id == USB_ID(0x0763, 0x2003)) | |
959 | return audiophile_skip_setting_quirk(chip, iface, altno); | |
0f5733b0 GP |
960 | /* quattro usb: skip altsets incompatible with device_setup */ |
961 | if (chip->usb_id == USB_ID(0x0763, 0x2001)) | |
962 | return quattro_skip_setting_quirk(chip, iface, altno); | |
963 | /* fasttrackpro usb: skip altsets incompatible with device_setup */ | |
964 | if (chip->usb_id == USB_ID(0x0763, 0x2012)) | |
965 | return fasttrackpro_skip_setting_quirk(chip, iface, altno); | |
e5779998 DM |
966 | |
967 | return 0; | |
968 | } | |
969 | ||
970 | int snd_usb_apply_boot_quirk(struct usb_device *dev, | |
971 | struct usb_interface *intf, | |
972 | const struct snd_usb_audio_quirk *quirk) | |
973 | { | |
974 | u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), | |
975 | le16_to_cpu(dev->descriptor.idProduct)); | |
976 | ||
3347b26c DM |
977 | switch (id) { |
978 | case USB_ID(0x041e, 0x3000): | |
979 | /* SB Extigy needs special boot-up sequence */ | |
980 | /* if more models come, this will go to the quirk list. */ | |
e5779998 DM |
981 | return snd_usb_extigy_boot_quirk(dev, intf); |
982 | ||
3347b26c DM |
983 | case USB_ID(0x041e, 0x3020): |
984 | /* SB Audigy 2 NX needs its own boot-up magic, too */ | |
e5779998 DM |
985 | return snd_usb_audigy2nx_boot_quirk(dev); |
986 | ||
3347b26c DM |
987 | case USB_ID(0x10f5, 0x0200): |
988 | /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */ | |
e5779998 DM |
989 | return snd_usb_cm106_boot_quirk(dev); |
990 | ||
3347b26c DM |
991 | case USB_ID(0x0d8c, 0x0102): |
992 | /* C-Media CM6206 / CM106-Like Sound Device */ | |
8129e79e | 993 | case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */ |
e5779998 DM |
994 | return snd_usb_cm6206_boot_quirk(dev); |
995 | ||
cb99864d DZ |
996 | case USB_ID(0x0dba, 0x3000): |
997 | /* Digidesign Mbox 2 */ | |
998 | return snd_usb_mbox2_boot_quirk(dev); | |
999 | ||
11e424e8 EG |
1000 | case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */ |
1001 | case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */ | |
1002 | return snd_usb_novation_boot_quirk(dev); | |
5e212332 | 1003 | |
3347b26c DM |
1004 | case USB_ID(0x133e, 0x0815): |
1005 | /* Access Music VirusTI Desktop */ | |
e5779998 DM |
1006 | return snd_usb_accessmusic_boot_quirk(dev); |
1007 | ||
759e890f | 1008 | case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */ |
3347b26c DM |
1009 | case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */ |
1010 | case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */ | |
54a8c500 | 1011 | return snd_usb_nativeinstruments_boot_quirk(dev); |
0f5733b0 GP |
1012 | case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */ |
1013 | return snd_usb_fasttrackpro_boot_quirk(dev); | |
19570d74 TI |
1014 | case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */ |
1015 | return snd_usb_gamecon780_boot_quirk(dev); | |
3347b26c | 1016 | } |
54a8c500 | 1017 | |
e5779998 DM |
1018 | return 0; |
1019 | } | |
1020 | ||
1021 | /* | |
1022 | * check if the device uses big-endian samples | |
1023 | */ | |
1024 | int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp) | |
1025 | { | |
48fc7f7e | 1026 | /* it depends on altsetting whether the device is big-endian or not */ |
e5779998 DM |
1027 | switch (chip->usb_id) { |
1028 | case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */ | |
0f5733b0 GP |
1029 | if (fp->altsetting == 2 || fp->altsetting == 3 || |
1030 | fp->altsetting == 5 || fp->altsetting == 6) | |
e5779998 DM |
1031 | return 1; |
1032 | break; | |
1033 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ | |
1034 | if (chip->setup == 0x00 || | |
0f5733b0 GP |
1035 | fp->altsetting == 1 || fp->altsetting == 2 || |
1036 | fp->altsetting == 3) | |
1037 | return 1; | |
1038 | break; | |
1039 | case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */ | |
1040 | if (fp->altsetting == 2 || fp->altsetting == 3 || | |
1041 | fp->altsetting == 5 || fp->altsetting == 6) | |
e5779998 | 1042 | return 1; |
0f5733b0 | 1043 | break; |
e5779998 DM |
1044 | } |
1045 | return 0; | |
1046 | } | |
1047 | ||
1048 | /* | |
1cdfa9f3 | 1049 | * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device, |
e5779998 DM |
1050 | * not for interface. |
1051 | */ | |
1052 | ||
1053 | enum { | |
1054 | EMU_QUIRK_SR_44100HZ = 0, | |
1055 | EMU_QUIRK_SR_48000HZ, | |
1056 | EMU_QUIRK_SR_88200HZ, | |
1057 | EMU_QUIRK_SR_96000HZ, | |
1058 | EMU_QUIRK_SR_176400HZ, | |
1059 | EMU_QUIRK_SR_192000HZ | |
1060 | }; | |
1061 | ||
1062 | static void set_format_emu_quirk(struct snd_usb_substream *subs, | |
1063 | struct audioformat *fmt) | |
1064 | { | |
1065 | unsigned char emu_samplerate_id = 0; | |
1066 | ||
1067 | /* When capture is active | |
1068 | * sample rate shouldn't be changed | |
1069 | * by playback substream | |
1070 | */ | |
1071 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { | |
1072 | if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1) | |
1073 | return; | |
1074 | } | |
1075 | ||
1076 | switch (fmt->rate_min) { | |
1077 | case 48000: | |
1078 | emu_samplerate_id = EMU_QUIRK_SR_48000HZ; | |
1079 | break; | |
1080 | case 88200: | |
1081 | emu_samplerate_id = EMU_QUIRK_SR_88200HZ; | |
1082 | break; | |
1083 | case 96000: | |
1084 | emu_samplerate_id = EMU_QUIRK_SR_96000HZ; | |
1085 | break; | |
1086 | case 176400: | |
1087 | emu_samplerate_id = EMU_QUIRK_SR_176400HZ; | |
1088 | break; | |
1089 | case 192000: | |
1090 | emu_samplerate_id = EMU_QUIRK_SR_192000HZ; | |
1091 | break; | |
1092 | default: | |
1093 | emu_samplerate_id = EMU_QUIRK_SR_44100HZ; | |
1094 | break; | |
1095 | } | |
1096 | snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id); | |
1539d4f8 | 1097 | subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0; |
e5779998 DM |
1098 | } |
1099 | ||
1100 | void snd_usb_set_format_quirk(struct snd_usb_substream *subs, | |
1101 | struct audioformat *fmt) | |
1102 | { | |
1103 | switch (subs->stream->chip->usb_id) { | |
1104 | case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */ | |
1105 | case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */ | |
1106 | case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */ | |
1cdfa9f3 | 1107 | case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */ |
e5779998 DM |
1108 | set_format_emu_quirk(subs, fmt); |
1109 | break; | |
1110 | } | |
1111 | } | |
1112 | ||
2b58fd5b DM |
1113 | void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep) |
1114 | { | |
1115 | /* | |
1116 | * "Playback Design" products send bogus feedback data at the start | |
1117 | * of the stream. Ignore them. | |
1118 | */ | |
1119 | if ((le16_to_cpu(ep->chip->dev->descriptor.idVendor) == 0x23ba) && | |
1120 | ep->type == SND_USB_ENDPOINT_TYPE_SYNC) | |
1121 | ep->skip_packets = 4; | |
83e3acd4 EZ |
1122 | |
1123 | /* | |
e9a25e04 MG |
1124 | * M-Audio Fast Track C400/C600 - when packets are not skipped, real |
1125 | * world latency varies by approx. +/- 50 frames (at 96KHz) each time | |
1126 | * the stream is (re)started. When skipping packets 16 at endpoint | |
1127 | * start up, the real world latency is stable within +/- 1 frame (also | |
83e3acd4 EZ |
1128 | * across power cycles). |
1129 | */ | |
e9a25e04 MG |
1130 | if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) || |
1131 | ep->chip->usb_id == USB_ID(0x0763, 0x2031)) && | |
83e3acd4 EZ |
1132 | ep->type == SND_USB_ENDPOINT_TYPE_DATA) |
1133 | ep->skip_packets = 16; | |
2b58fd5b DM |
1134 | } |
1135 | ||
21bb5aaf DM |
1136 | void snd_usb_set_interface_quirk(struct usb_device *dev) |
1137 | { | |
1138 | /* | |
1139 | * "Playback Design" products need a 50ms delay after setting the | |
1140 | * USB interface. | |
1141 | */ | |
1142 | if (le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) | |
1143 | mdelay(50); | |
1144 | } | |
1145 | ||
2b58fd5b DM |
1146 | void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, |
1147 | __u8 request, __u8 requesttype, __u16 value, | |
1148 | __u16 index, void *data, __u16 size) | |
1149 | { | |
1150 | /* | |
1151 | * "Playback Design" products need a 20ms delay after each | |
1152 | * class compliant request | |
1153 | */ | |
1154 | if ((le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) && | |
1155 | (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) | |
1156 | mdelay(20); | |
1157 | } | |
1158 | ||
126825e7 DM |
1159 | /* |
1160 | * snd_usb_interface_dsd_format_quirks() is called from format.c to | |
1161 | * augment the PCM format bit-field for DSD types. The UAC standards | |
1162 | * don't have a designated bit field to denote DSD-capable interfaces, | |
1163 | * hence all hardware that is known to support this format has to be | |
1164 | * listed here. | |
1165 | */ | |
1166 | u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, | |
1167 | struct audioformat *fp, | |
1168 | unsigned int sample_bytes) | |
1169 | { | |
1170 | /* Playback Designs */ | |
1171 | if (le16_to_cpu(chip->dev->descriptor.idVendor) == 0x23ba) { | |
1172 | switch (fp->altsetting) { | |
1173 | case 1: | |
1174 | fp->dsd_dop = true; | |
1175 | return SNDRV_PCM_FMTBIT_DSD_U16_LE; | |
1176 | case 2: | |
1177 | fp->dsd_bitrev = true; | |
1178 | return SNDRV_PCM_FMTBIT_DSD_U8; | |
1179 | case 3: | |
1180 | fp->dsd_bitrev = true; | |
1181 | return SNDRV_PCM_FMTBIT_DSD_U16_LE; | |
1182 | } | |
1183 | } | |
1184 | ||
848f3a82 JK |
1185 | /* XMOS based USB DACs */ |
1186 | switch (chip->usb_id) { | |
1187 | /* iFi Audio micro/nano iDSD */ | |
1188 | case USB_ID(0x20b1, 0x3008): | |
1189 | if (fp->altsetting == 2) | |
1190 | return SNDRV_PCM_FMTBIT_DSD_U32_LE; | |
1191 | break; | |
1192 | /* DIYINHK DSD DXD 384kHz USB to I2S/DSD */ | |
1193 | case USB_ID(0x20b1, 0x2009): | |
1194 | if (fp->altsetting == 3) | |
1195 | return SNDRV_PCM_FMTBIT_DSD_U32_LE; | |
1196 | break; | |
1197 | default: | |
1198 | break; | |
1199 | } | |
1200 | ||
126825e7 DM |
1201 | return 0; |
1202 | } |