quirks.c 34 KB

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