quirks.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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_comp)
  43. {
  44. int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
  45. const struct snd_usb_audio_quirk *quirk;
  46. int err;
  47. for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
  48. iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
  49. if (!iface)
  50. continue;
  51. if (quirk->ifnum != probed_ifnum &&
  52. usb_interface_claimed(iface))
  53. continue;
  54. err = snd_usb_create_quirk(chip, iface, driver, quirk);
  55. if (err < 0)
  56. return err;
  57. }
  58. for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
  59. iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
  60. if (!iface)
  61. continue;
  62. if (quirk->ifnum != probed_ifnum &&
  63. !usb_interface_claimed(iface)) {
  64. err = usb_driver_claim_interface(driver, iface,
  65. USB_AUDIO_IFACE_UNUSED);
  66. if (err < 0)
  67. return err;
  68. }
  69. }
  70. return 0;
  71. }
  72. static int ignore_interface_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. return 0;
  78. }
  79. /*
  80. * Allow alignment on audio sub-slot (channel samples) rather than
  81. * on audio slots (audio frames)
  82. */
  83. static int create_align_transfer_quirk(struct snd_usb_audio *chip,
  84. struct usb_interface *iface,
  85. struct usb_driver *driver,
  86. const struct snd_usb_audio_quirk *quirk)
  87. {
  88. chip->txfr_quirk = 1;
  89. return 1; /* Continue with creating streams and mixer */
  90. }
  91. static int create_any_midi_quirk(struct snd_usb_audio *chip,
  92. struct usb_interface *intf,
  93. struct usb_driver *driver,
  94. const struct snd_usb_audio_quirk *quirk)
  95. {
  96. return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
  97. }
  98. /*
  99. * create a stream for an interface with proper descriptors
  100. */
  101. static int create_standard_audio_quirk(struct snd_usb_audio *chip,
  102. struct usb_interface *iface,
  103. struct usb_driver *driver,
  104. const struct snd_usb_audio_quirk *quirk)
  105. {
  106. struct usb_host_interface *alts;
  107. struct usb_interface_descriptor *altsd;
  108. int err;
  109. if (chip->usb_id == USB_ID(0x1686, 0x00dd)) /* Zoom R16/24 */
  110. chip->tx_length_quirk = 1;
  111. alts = &iface->altsetting[0];
  112. altsd = get_iface_desc(alts);
  113. err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
  114. if (err < 0) {
  115. usb_audio_err(chip, "cannot setup if %d: error %d\n",
  116. altsd->bInterfaceNumber, err);
  117. return err;
  118. }
  119. /* reset the current interface */
  120. usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
  121. return 0;
  122. }
  123. /*
  124. * create a stream for an endpoint/altsetting without proper descriptors
  125. */
  126. static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
  127. struct usb_interface *iface,
  128. struct usb_driver *driver,
  129. const struct snd_usb_audio_quirk *quirk)
  130. {
  131. struct audioformat *fp;
  132. struct usb_host_interface *alts;
  133. struct usb_interface_descriptor *altsd;
  134. int stream, err;
  135. unsigned *rate_table = NULL;
  136. fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
  137. if (!fp)
  138. return -ENOMEM;
  139. INIT_LIST_HEAD(&fp->list);
  140. if (fp->nr_rates > MAX_NR_RATES) {
  141. kfree(fp);
  142. return -EINVAL;
  143. }
  144. if (fp->nr_rates > 0) {
  145. rate_table = kmemdup(fp->rate_table,
  146. sizeof(int) * fp->nr_rates, GFP_KERNEL);
  147. if (!rate_table) {
  148. kfree(fp);
  149. return -ENOMEM;
  150. }
  151. fp->rate_table = rate_table;
  152. }
  153. stream = (fp->endpoint & USB_DIR_IN)
  154. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  155. err = snd_usb_add_audio_stream(chip, stream, fp);
  156. if (err < 0)
  157. goto error;
  158. if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
  159. fp->altset_idx >= iface->num_altsetting) {
  160. err = -EINVAL;
  161. goto error;
  162. }
  163. alts = &iface->altsetting[fp->altset_idx];
  164. altsd = get_iface_desc(alts);
  165. if (altsd->bNumEndpoints < 1) {
  166. err = -EINVAL;
  167. goto error;
  168. }
  169. fp->protocol = altsd->bInterfaceProtocol;
  170. if (fp->datainterval == 0)
  171. fp->datainterval = snd_usb_parse_datainterval(chip, alts);
  172. if (fp->maxpacksize == 0)
  173. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  174. usb_set_interface(chip->dev, fp->iface, 0);
  175. snd_usb_init_pitch(chip, fp->iface, alts, fp);
  176. snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
  177. return 0;
  178. error:
  179. list_del(&fp->list); /* unlink for avoiding double-free */
  180. kfree(fp);
  181. kfree(rate_table);
  182. return err;
  183. }
  184. static int create_auto_pcm_quirk(struct snd_usb_audio *chip,
  185. struct usb_interface *iface,
  186. struct usb_driver *driver)
  187. {
  188. struct usb_host_interface *alts;
  189. struct usb_interface_descriptor *altsd;
  190. struct usb_endpoint_descriptor *epd;
  191. struct uac1_as_header_descriptor *ashd;
  192. struct uac_format_type_i_discrete_descriptor *fmtd;
  193. /*
  194. * Most Roland/Yamaha audio streaming interfaces have more or less
  195. * standard descriptors, but older devices might lack descriptors, and
  196. * future ones might change, so ensure that we fail silently if the
  197. * interface doesn't look exactly right.
  198. */
  199. /* must have a non-zero altsetting for streaming */
  200. if (iface->num_altsetting < 2)
  201. return -ENODEV;
  202. alts = &iface->altsetting[1];
  203. altsd = get_iface_desc(alts);
  204. /* must have an isochronous endpoint for streaming */
  205. if (altsd->bNumEndpoints < 1)
  206. return -ENODEV;
  207. epd = get_endpoint(alts, 0);
  208. if (!usb_endpoint_xfer_isoc(epd))
  209. return -ENODEV;
  210. /* must have format descriptors */
  211. ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
  212. UAC_AS_GENERAL);
  213. fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
  214. UAC_FORMAT_TYPE);
  215. if (!ashd || ashd->bLength < 7 ||
  216. !fmtd || fmtd->bLength < 8)
  217. return -ENODEV;
  218. return create_standard_audio_quirk(chip, iface, driver, NULL);
  219. }
  220. static int create_yamaha_midi_quirk(struct snd_usb_audio *chip,
  221. struct usb_interface *iface,
  222. struct usb_driver *driver,
  223. struct usb_host_interface *alts)
  224. {
  225. static const struct snd_usb_audio_quirk yamaha_midi_quirk = {
  226. .type = QUIRK_MIDI_YAMAHA
  227. };
  228. struct usb_midi_in_jack_descriptor *injd;
  229. struct usb_midi_out_jack_descriptor *outjd;
  230. /* must have some valid jack descriptors */
  231. injd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
  232. NULL, USB_MS_MIDI_IN_JACK);
  233. outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
  234. NULL, USB_MS_MIDI_OUT_JACK);
  235. if (!injd && !outjd)
  236. return -ENODEV;
  237. if ((injd && !snd_usb_validate_midi_desc(injd)) ||
  238. (outjd && !snd_usb_validate_midi_desc(outjd)))
  239. return -ENODEV;
  240. if (injd && (injd->bLength < 5 ||
  241. (injd->bJackType != USB_MS_EMBEDDED &&
  242. injd->bJackType != USB_MS_EXTERNAL)))
  243. return -ENODEV;
  244. if (outjd && (outjd->bLength < 6 ||
  245. (outjd->bJackType != USB_MS_EMBEDDED &&
  246. outjd->bJackType != USB_MS_EXTERNAL)))
  247. return -ENODEV;
  248. return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk);
  249. }
  250. static int create_roland_midi_quirk(struct snd_usb_audio *chip,
  251. struct usb_interface *iface,
  252. struct usb_driver *driver,
  253. struct usb_host_interface *alts)
  254. {
  255. static const struct snd_usb_audio_quirk roland_midi_quirk = {
  256. .type = QUIRK_MIDI_ROLAND
  257. };
  258. u8 *roland_desc = NULL;
  259. /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
  260. for (;;) {
  261. roland_desc = snd_usb_find_csint_desc(alts->extra,
  262. alts->extralen,
  263. roland_desc, 0xf1);
  264. if (!roland_desc)
  265. return -ENODEV;
  266. if (roland_desc[0] < 6 || roland_desc[3] != 2)
  267. continue;
  268. return create_any_midi_quirk(chip, iface, driver,
  269. &roland_midi_quirk);
  270. }
  271. }
  272. static int create_std_midi_quirk(struct snd_usb_audio *chip,
  273. struct usb_interface *iface,
  274. struct usb_driver *driver,
  275. struct usb_host_interface *alts)
  276. {
  277. struct usb_ms_header_descriptor *mshd;
  278. struct usb_ms_endpoint_descriptor *msepd;
  279. /* must have the MIDIStreaming interface header descriptor*/
  280. mshd = (struct usb_ms_header_descriptor *)alts->extra;
  281. if (alts->extralen < 7 ||
  282. mshd->bLength < 7 ||
  283. mshd->bDescriptorType != USB_DT_CS_INTERFACE ||
  284. mshd->bDescriptorSubtype != USB_MS_HEADER)
  285. return -ENODEV;
  286. /* must have the MIDIStreaming endpoint descriptor*/
  287. msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra;
  288. if (alts->endpoint[0].extralen < 4 ||
  289. msepd->bLength < 4 ||
  290. msepd->bDescriptorType != USB_DT_CS_ENDPOINT ||
  291. msepd->bDescriptorSubtype != UAC_MS_GENERAL ||
  292. msepd->bNumEmbMIDIJack < 1 ||
  293. msepd->bNumEmbMIDIJack > 16)
  294. return -ENODEV;
  295. return create_any_midi_quirk(chip, iface, driver, NULL);
  296. }
  297. static int create_auto_midi_quirk(struct snd_usb_audio *chip,
  298. struct usb_interface *iface,
  299. struct usb_driver *driver)
  300. {
  301. struct usb_host_interface *alts;
  302. struct usb_interface_descriptor *altsd;
  303. struct usb_endpoint_descriptor *epd;
  304. int err;
  305. alts = &iface->altsetting[0];
  306. altsd = get_iface_desc(alts);
  307. /* must have at least one bulk/interrupt endpoint for streaming */
  308. if (altsd->bNumEndpoints < 1)
  309. return -ENODEV;
  310. epd = get_endpoint(alts, 0);
  311. if (!usb_endpoint_xfer_bulk(epd) &&
  312. !usb_endpoint_xfer_int(epd))
  313. return -ENODEV;
  314. switch (USB_ID_VENDOR(chip->usb_id)) {
  315. case 0x0499: /* Yamaha */
  316. err = create_yamaha_midi_quirk(chip, iface, driver, alts);
  317. if (err != -ENODEV)
  318. return err;
  319. break;
  320. case 0x0582: /* Roland */
  321. err = create_roland_midi_quirk(chip, iface, driver, alts);
  322. if (err != -ENODEV)
  323. return err;
  324. break;
  325. }
  326. return create_std_midi_quirk(chip, iface, driver, alts);
  327. }
  328. static int create_autodetect_quirk(struct snd_usb_audio *chip,
  329. struct usb_interface *iface,
  330. struct usb_driver *driver)
  331. {
  332. int err;
  333. err = create_auto_pcm_quirk(chip, iface, driver);
  334. if (err == -ENODEV)
  335. err = create_auto_midi_quirk(chip, iface, driver);
  336. return err;
  337. }
  338. static int create_autodetect_quirks(struct snd_usb_audio *chip,
  339. struct usb_interface *iface,
  340. struct usb_driver *driver,
  341. const struct snd_usb_audio_quirk *quirk)
  342. {
  343. int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
  344. int ifcount, ifnum, err;
  345. err = create_autodetect_quirk(chip, iface, driver);
  346. if (err < 0)
  347. return err;
  348. /*
  349. * ALSA PCM playback/capture devices cannot be registered in two steps,
  350. * so we have to claim the other corresponding interface here.
  351. */
  352. ifcount = chip->dev->actconfig->desc.bNumInterfaces;
  353. for (ifnum = 0; ifnum < ifcount; ifnum++) {
  354. if (ifnum == probed_ifnum || quirk->ifnum >= 0)
  355. continue;
  356. iface = usb_ifnum_to_if(chip->dev, ifnum);
  357. if (!iface ||
  358. usb_interface_claimed(iface) ||
  359. get_iface_desc(iface->altsetting)->bInterfaceClass !=
  360. USB_CLASS_VENDOR_SPEC)
  361. continue;
  362. err = create_autodetect_quirk(chip, iface, driver);
  363. if (err >= 0) {
  364. err = usb_driver_claim_interface(driver, iface,
  365. USB_AUDIO_IFACE_UNUSED);
  366. if (err < 0)
  367. return err;
  368. }
  369. }
  370. return 0;
  371. }
  372. /*
  373. * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
  374. * The only way to detect the sample rate is by looking at wMaxPacketSize.
  375. */
  376. static int create_uaxx_quirk(struct snd_usb_audio *chip,
  377. struct usb_interface *iface,
  378. struct usb_driver *driver,
  379. const struct snd_usb_audio_quirk *quirk)
  380. {
  381. static const struct audioformat ua_format = {
  382. .formats = SNDRV_PCM_FMTBIT_S24_3LE,
  383. .channels = 2,
  384. .fmt_type = UAC_FORMAT_TYPE_I,
  385. .altsetting = 1,
  386. .altset_idx = 1,
  387. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  388. };
  389. struct usb_host_interface *alts;
  390. struct usb_interface_descriptor *altsd;
  391. struct audioformat *fp;
  392. int stream, err;
  393. /* both PCM and MIDI interfaces have 2 or more altsettings */
  394. if (iface->num_altsetting < 2)
  395. return -ENXIO;
  396. alts = &iface->altsetting[1];
  397. altsd = get_iface_desc(alts);
  398. if (altsd->bNumEndpoints == 2) {
  399. static const struct snd_usb_midi_endpoint_info ua700_ep = {
  400. .out_cables = 0x0003,
  401. .in_cables = 0x0003
  402. };
  403. static const struct snd_usb_audio_quirk ua700_quirk = {
  404. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  405. .data = &ua700_ep
  406. };
  407. static const struct snd_usb_midi_endpoint_info uaxx_ep = {
  408. .out_cables = 0x0001,
  409. .in_cables = 0x0001
  410. };
  411. static const struct snd_usb_audio_quirk uaxx_quirk = {
  412. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  413. .data = &uaxx_ep
  414. };
  415. const struct snd_usb_audio_quirk *quirk =
  416. chip->usb_id == USB_ID(0x0582, 0x002b)
  417. ? &ua700_quirk : &uaxx_quirk;
  418. return __snd_usbmidi_create(chip->card, iface,
  419. &chip->midi_list, quirk,
  420. chip->usb_id);
  421. }
  422. if (altsd->bNumEndpoints != 1)
  423. return -ENXIO;
  424. fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
  425. if (!fp)
  426. return -ENOMEM;
  427. fp->iface = altsd->bInterfaceNumber;
  428. fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
  429. fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
  430. fp->datainterval = 0;
  431. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  432. INIT_LIST_HEAD(&fp->list);
  433. switch (fp->maxpacksize) {
  434. case 0x120:
  435. fp->rate_max = fp->rate_min = 44100;
  436. break;
  437. case 0x138:
  438. case 0x140:
  439. fp->rate_max = fp->rate_min = 48000;
  440. break;
  441. case 0x258:
  442. case 0x260:
  443. fp->rate_max = fp->rate_min = 96000;
  444. break;
  445. default:
  446. usb_audio_err(chip, "unknown sample rate\n");
  447. kfree(fp);
  448. return -ENXIO;
  449. }
  450. stream = (fp->endpoint & USB_DIR_IN)
  451. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  452. err = snd_usb_add_audio_stream(chip, stream, fp);
  453. if (err < 0) {
  454. list_del(&fp->list); /* unlink for avoiding double-free */
  455. kfree(fp);
  456. return err;
  457. }
  458. usb_set_interface(chip->dev, fp->iface, 0);
  459. return 0;
  460. }
  461. /*
  462. * Create a standard mixer for the specified interface.
  463. */
  464. static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
  465. struct usb_interface *iface,
  466. struct usb_driver *driver,
  467. const struct snd_usb_audio_quirk *quirk)
  468. {
  469. if (quirk->ifnum < 0)
  470. return 0;
  471. return snd_usb_create_mixer(chip, quirk->ifnum, 0);
  472. }
  473. static int setup_fmt_after_resume_quirk(struct snd_usb_audio *chip,
  474. struct usb_interface *iface,
  475. struct usb_driver *driver,
  476. const struct snd_usb_audio_quirk *quirk)
  477. {
  478. chip->setup_fmt_after_resume_quirk = 1;
  479. return 1; /* Continue with creating streams and mixer */
  480. }
  481. /*
  482. * audio-interface quirks
  483. *
  484. * returns zero if no standard audio/MIDI parsing is needed.
  485. * returns a positive value if standard audio/midi interfaces are parsed
  486. * after this.
  487. * returns a negative value at error.
  488. */
  489. int snd_usb_create_quirk(struct snd_usb_audio *chip,
  490. struct usb_interface *iface,
  491. struct usb_driver *driver,
  492. const struct snd_usb_audio_quirk *quirk)
  493. {
  494. typedef int (*quirk_func_t)(struct snd_usb_audio *,
  495. struct usb_interface *,
  496. struct usb_driver *,
  497. const struct snd_usb_audio_quirk *);
  498. static const quirk_func_t quirk_funcs[] = {
  499. [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
  500. [QUIRK_COMPOSITE] = create_composite_quirk,
  501. [QUIRK_AUTODETECT] = create_autodetect_quirks,
  502. [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
  503. [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
  504. [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
  505. [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
  506. [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
  507. [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
  508. [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
  509. [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
  510. [QUIRK_MIDI_CME] = create_any_midi_quirk,
  511. [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
  512. [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
  513. [QUIRK_MIDI_CH345] = create_any_midi_quirk,
  514. [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
  515. [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
  516. [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
  517. [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
  518. [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
  519. [QUIRK_SETUP_FMT_AFTER_RESUME] = setup_fmt_after_resume_quirk,
  520. };
  521. if (quirk->type < QUIRK_TYPE_COUNT) {
  522. return quirk_funcs[quirk->type](chip, iface, driver, quirk);
  523. } else {
  524. usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
  525. return -ENXIO;
  526. }
  527. }
  528. /*
  529. * boot quirks
  530. */
  531. #define EXTIGY_FIRMWARE_SIZE_OLD 794
  532. #define EXTIGY_FIRMWARE_SIZE_NEW 483
  533. static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
  534. {
  535. struct usb_host_config *config = dev->actconfig;
  536. int err;
  537. if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
  538. le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
  539. dev_dbg(&dev->dev, "sending Extigy boot sequence...\n");
  540. /* Send message to force it to reconnect with full interface. */
  541. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
  542. 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
  543. if (err < 0)
  544. dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
  545. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  546. &dev->descriptor, sizeof(dev->descriptor));
  547. config = dev->actconfig;
  548. if (err < 0)
  549. dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
  550. err = usb_reset_configuration(dev);
  551. if (err < 0)
  552. dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
  553. dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
  554. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  555. return -ENODEV; /* quit this anyway */
  556. }
  557. return 0;
  558. }
  559. static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
  560. {
  561. u8 buf = 1;
  562. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
  563. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  564. 0, 0, &buf, 1);
  565. if (buf == 0) {
  566. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
  567. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  568. 1, 2000, NULL, 0);
  569. return -ENODEV;
  570. }
  571. return 0;
  572. }
  573. static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
  574. {
  575. int err;
  576. if (dev->actconfig->desc.bConfigurationValue == 1) {
  577. dev_info(&dev->dev,
  578. "Fast Track Pro switching to config #2\n");
  579. /* This function has to be available by the usb core module.
  580. * if it is not avialable the boot quirk has to be left out
  581. * and the configuration has to be set by udev or hotplug
  582. * rules
  583. */
  584. err = usb_driver_set_configuration(dev, 2);
  585. if (err < 0)
  586. dev_dbg(&dev->dev,
  587. "error usb_driver_set_configuration: %d\n",
  588. err);
  589. /* Always return an error, so that we stop creating a device
  590. that will just be destroyed and recreated with a new
  591. configuration */
  592. return -ENODEV;
  593. } else
  594. dev_info(&dev->dev, "Fast Track Pro config OK\n");
  595. return 0;
  596. }
  597. /*
  598. * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
  599. * documented in the device's data sheet.
  600. */
  601. static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
  602. {
  603. u8 buf[4];
  604. buf[0] = 0x20;
  605. buf[1] = value & 0xff;
  606. buf[2] = (value >> 8) & 0xff;
  607. buf[3] = reg;
  608. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
  609. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
  610. 0, 0, &buf, 4);
  611. }
  612. static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
  613. {
  614. /*
  615. * Enable line-out driver mode, set headphone source to front
  616. * channels, enable stereo mic.
  617. */
  618. return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
  619. }
  620. /*
  621. * C-Media CM6206 is based on CM106 with two additional
  622. * registers that are not documented in the data sheet.
  623. * Values here are chosen based on sniffing USB traffic
  624. * under Windows.
  625. */
  626. static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
  627. {
  628. int err = 0, reg;
  629. int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
  630. for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
  631. err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
  632. if (err < 0)
  633. return err;
  634. }
  635. return err;
  636. }
  637. /* quirk for Plantronics GameCom 780 with CM6302 chip */
  638. static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev)
  639. {
  640. /* set the initial volume and don't change; other values are either
  641. * too loud or silent due to firmware bug (bko#65251)
  642. */
  643. u8 buf[2] = { 0x74, 0xe3 };
  644. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
  645. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  646. UAC_FU_VOLUME << 8, 9 << 8, buf, 2);
  647. }
  648. /*
  649. * Novation Twitch DJ controller
  650. * Focusrite Novation Saffire 6 USB audio card
  651. */
  652. static int snd_usb_novation_boot_quirk(struct usb_device *dev)
  653. {
  654. /* preemptively set up the device because otherwise the
  655. * raw MIDI endpoints are not active */
  656. usb_set_interface(dev, 0, 1);
  657. return 0;
  658. }
  659. /*
  660. * This call will put the synth in "USB send" mode, i.e it will send MIDI
  661. * messages through USB (this is disabled at startup). The synth will
  662. * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
  663. * sign on its LCD. Values here are chosen based on sniffing USB traffic
  664. * under Windows.
  665. */
  666. static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
  667. {
  668. int err, actual_length;
  669. /* "midi send" enable */
  670. static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
  671. void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
  672. if (!buf)
  673. return -ENOMEM;
  674. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
  675. ARRAY_SIZE(seq), &actual_length, 1000);
  676. kfree(buf);
  677. if (err < 0)
  678. return err;
  679. return 0;
  680. }
  681. /*
  682. * Some sound cards from Native Instruments are in fact compliant to the USB
  683. * audio standard of version 2 and other approved USB standards, even though
  684. * they come up as vendor-specific device when first connected.
  685. *
  686. * However, they can be told to come up with a new set of descriptors
  687. * upon their next enumeration, and the interfaces announced by the new
  688. * descriptors will then be handled by the kernel's class drivers. As the
  689. * product ID will also change, no further checks are required.
  690. */
  691. static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
  692. {
  693. int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  694. 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  695. 1, 0, NULL, 0, 1000);
  696. if (ret < 0)
  697. return ret;
  698. usb_reset_device(dev);
  699. /* return -EAGAIN, so the creation of an audio interface for this
  700. * temporary device is aborted. The device will reconnect with a
  701. * new product ID */
  702. return -EAGAIN;
  703. }
  704. static void mbox2_setup_48_24_magic(struct usb_device *dev)
  705. {
  706. u8 srate[3];
  707. u8 temp[12];
  708. /* Choose 48000Hz permanently */
  709. srate[0] = 0x80;
  710. srate[1] = 0xbb;
  711. srate[2] = 0x00;
  712. /* Send the magic! */
  713. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  714. 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
  715. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  716. 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
  717. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  718. 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
  719. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  720. 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
  721. return;
  722. }
  723. /* Digidesign Mbox 2 needs to load firmware onboard
  724. * and driver must wait a few seconds for initialisation.
  725. */
  726. #define MBOX2_FIRMWARE_SIZE 646
  727. #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
  728. #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
  729. static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
  730. {
  731. struct usb_host_config *config = dev->actconfig;
  732. int err;
  733. u8 bootresponse[0x12];
  734. int fwsize;
  735. int count;
  736. fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
  737. if (fwsize != MBOX2_FIRMWARE_SIZE) {
  738. dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
  739. return -ENODEV;
  740. }
  741. dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
  742. count = 0;
  743. bootresponse[0] = MBOX2_BOOT_LOADING;
  744. while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
  745. msleep(500); /* 0.5 second delay */
  746. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  747. /* Control magic - load onboard firmware */
  748. 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
  749. if (bootresponse[0] == MBOX2_BOOT_READY)
  750. break;
  751. dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
  752. count++;
  753. }
  754. if (bootresponse[0] != MBOX2_BOOT_READY) {
  755. dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
  756. return -ENODEV;
  757. }
  758. dev_dbg(&dev->dev, "device initialised!\n");
  759. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  760. &dev->descriptor, sizeof(dev->descriptor));
  761. config = dev->actconfig;
  762. if (err < 0)
  763. dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
  764. err = usb_reset_configuration(dev);
  765. if (err < 0)
  766. dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
  767. dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
  768. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  769. mbox2_setup_48_24_magic(dev);
  770. dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
  771. return 0; /* Successful boot */
  772. }
  773. static int snd_usb_axefx3_boot_quirk(struct usb_device *dev)
  774. {
  775. int err;
  776. dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n");
  777. /* If the Axe-Fx III has not fully booted, it will timeout when trying
  778. * to enable the audio streaming interface. A more generous timeout is
  779. * used here to detect when the Axe-Fx III has finished booting as the
  780. * set interface message will be acked once it has
  781. */
  782. err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  783. USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
  784. 1, 1, NULL, 0, 120000);
  785. if (err < 0) {
  786. dev_err(&dev->dev,
  787. "failed waiting for Axe-Fx III to boot: %d\n", err);
  788. return err;
  789. }
  790. dev_dbg(&dev->dev, "Axe-Fx III is now ready\n");
  791. err = usb_set_interface(dev, 1, 0);
  792. if (err < 0)
  793. dev_dbg(&dev->dev,
  794. "error stopping Axe-Fx III interface: %d\n", err);
  795. return 0;
  796. }
  797. /*
  798. * Setup quirks
  799. */
  800. #define MAUDIO_SET 0x01 /* parse device_setup */
  801. #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
  802. #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
  803. #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
  804. #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
  805. #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
  806. #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
  807. #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
  808. #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
  809. #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
  810. #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
  811. static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
  812. int iface, int altno)
  813. {
  814. /* Reset ALL ifaces to 0 altsetting.
  815. * Call it for every possible altsetting of every interface.
  816. */
  817. usb_set_interface(chip->dev, iface, 0);
  818. if (chip->setup & MAUDIO_SET) {
  819. if (chip->setup & MAUDIO_SET_COMPATIBLE) {
  820. if (iface != 1 && iface != 2)
  821. return 1; /* skip all interfaces but 1 and 2 */
  822. } else {
  823. unsigned int mask;
  824. if (iface == 1 || iface == 2)
  825. return 1; /* skip interfaces 1 and 2 */
  826. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  827. return 1; /* skip this altsetting */
  828. mask = chip->setup & MAUDIO_SET_MASK;
  829. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  830. return 1; /* skip this altsetting */
  831. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  832. return 1; /* skip this altsetting */
  833. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
  834. return 1; /* skip this altsetting */
  835. }
  836. }
  837. usb_audio_dbg(chip,
  838. "using altsetting %d for interface %d config %d\n",
  839. altno, iface, chip->setup);
  840. return 0; /* keep this altsetting */
  841. }
  842. static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
  843. int iface,
  844. int altno)
  845. {
  846. /* Reset ALL ifaces to 0 altsetting.
  847. * Call it for every possible altsetting of every interface.
  848. */
  849. usb_set_interface(chip->dev, iface, 0);
  850. if (chip->setup & MAUDIO_SET) {
  851. unsigned int mask;
  852. if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
  853. return 1; /* skip this altsetting */
  854. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  855. return 1; /* skip this altsetting */
  856. mask = chip->setup & MAUDIO_SET_MASK;
  857. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  858. return 1; /* skip this altsetting */
  859. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  860. return 1; /* skip this altsetting */
  861. if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
  862. return 1; /* skip this altsetting */
  863. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
  864. return 1; /* skip this altsetting */
  865. }
  866. return 0; /* keep this altsetting */
  867. }
  868. static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
  869. int iface, int altno)
  870. {
  871. /* Reset ALL ifaces to 0 altsetting.
  872. * Call it for every possible altsetting of every interface.
  873. */
  874. usb_set_interface(chip->dev, iface, 0);
  875. /* possible configuration where both inputs and only one output is
  876. *used is not supported by the current setup
  877. */
  878. if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
  879. if (chip->setup & MAUDIO_SET_96K) {
  880. if (altno != 3 && altno != 6)
  881. return 1;
  882. } else if (chip->setup & MAUDIO_SET_DI) {
  883. if (iface == 4)
  884. return 1; /* no analog input */
  885. if (altno != 2 && altno != 5)
  886. return 1; /* enable only altsets 2 and 5 */
  887. } else {
  888. if (iface == 5)
  889. return 1; /* disable digialt input */
  890. if (altno != 2 && altno != 5)
  891. return 1; /* enalbe only altsets 2 and 5 */
  892. }
  893. } else {
  894. /* keep only 16-Bit mode */
  895. if (altno != 1)
  896. return 1;
  897. }
  898. usb_audio_dbg(chip,
  899. "using altsetting %d for interface %d config %d\n",
  900. altno, iface, chip->setup);
  901. return 0; /* keep this altsetting */
  902. }
  903. int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
  904. int iface,
  905. int altno)
  906. {
  907. /* audiophile usb: skip altsets incompatible with device_setup */
  908. if (chip->usb_id == USB_ID(0x0763, 0x2003))
  909. return audiophile_skip_setting_quirk(chip, iface, altno);
  910. /* quattro usb: skip altsets incompatible with device_setup */
  911. if (chip->usb_id == USB_ID(0x0763, 0x2001))
  912. return quattro_skip_setting_quirk(chip, iface, altno);
  913. /* fasttrackpro usb: skip altsets incompatible with device_setup */
  914. if (chip->usb_id == USB_ID(0x0763, 0x2012))
  915. return fasttrackpro_skip_setting_quirk(chip, iface, altno);
  916. return 0;
  917. }
  918. int snd_usb_apply_boot_quirk(struct usb_device *dev,
  919. struct usb_interface *intf,
  920. const struct snd_usb_audio_quirk *quirk,
  921. unsigned int id)
  922. {
  923. switch (id) {
  924. case USB_ID(0x041e, 0x3000):
  925. /* SB Extigy needs special boot-up sequence */
  926. /* if more models come, this will go to the quirk list. */
  927. return snd_usb_extigy_boot_quirk(dev, intf);
  928. case USB_ID(0x041e, 0x3020):
  929. /* SB Audigy 2 NX needs its own boot-up magic, too */
  930. return snd_usb_audigy2nx_boot_quirk(dev);
  931. case USB_ID(0x10f5, 0x0200):
  932. /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
  933. return snd_usb_cm106_boot_quirk(dev);
  934. case USB_ID(0x0d8c, 0x0102):
  935. /* C-Media CM6206 / CM106-Like Sound Device */
  936. case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
  937. return snd_usb_cm6206_boot_quirk(dev);
  938. case USB_ID(0x0dba, 0x3000):
  939. /* Digidesign Mbox 2 */
  940. return snd_usb_mbox2_boot_quirk(dev);
  941. case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
  942. case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
  943. return snd_usb_novation_boot_quirk(dev);
  944. case USB_ID(0x133e, 0x0815):
  945. /* Access Music VirusTI Desktop */
  946. return snd_usb_accessmusic_boot_quirk(dev);
  947. case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
  948. case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
  949. case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
  950. return snd_usb_nativeinstruments_boot_quirk(dev);
  951. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
  952. return snd_usb_fasttrackpro_boot_quirk(dev);
  953. case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
  954. return snd_usb_gamecon780_boot_quirk(dev);
  955. case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx 3 */
  956. return snd_usb_axefx3_boot_quirk(dev);
  957. }
  958. return 0;
  959. }
  960. /*
  961. * check if the device uses big-endian samples
  962. */
  963. int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
  964. {
  965. /* it depends on altsetting whether the device is big-endian or not */
  966. switch (chip->usb_id) {
  967. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
  968. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  969. fp->altsetting == 5 || fp->altsetting == 6)
  970. return 1;
  971. break;
  972. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  973. if (chip->setup == 0x00 ||
  974. fp->altsetting == 1 || fp->altsetting == 2 ||
  975. fp->altsetting == 3)
  976. return 1;
  977. break;
  978. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
  979. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  980. fp->altsetting == 5 || fp->altsetting == 6)
  981. return 1;
  982. break;
  983. }
  984. return 0;
  985. }
  986. /*
  987. * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
  988. * not for interface.
  989. */
  990. enum {
  991. EMU_QUIRK_SR_44100HZ = 0,
  992. EMU_QUIRK_SR_48000HZ,
  993. EMU_QUIRK_SR_88200HZ,
  994. EMU_QUIRK_SR_96000HZ,
  995. EMU_QUIRK_SR_176400HZ,
  996. EMU_QUIRK_SR_192000HZ
  997. };
  998. static void set_format_emu_quirk(struct snd_usb_substream *subs,
  999. struct audioformat *fmt)
  1000. {
  1001. unsigned char emu_samplerate_id = 0;
  1002. /* When capture is active
  1003. * sample rate shouldn't be changed
  1004. * by playback substream
  1005. */
  1006. if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
  1007. if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
  1008. return;
  1009. }
  1010. switch (fmt->rate_min) {
  1011. case 48000:
  1012. emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
  1013. break;
  1014. case 88200:
  1015. emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
  1016. break;
  1017. case 96000:
  1018. emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
  1019. break;
  1020. case 176400:
  1021. emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
  1022. break;
  1023. case 192000:
  1024. emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
  1025. break;
  1026. default:
  1027. emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
  1028. break;
  1029. }
  1030. snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
  1031. subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
  1032. }
  1033. void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
  1034. struct audioformat *fmt)
  1035. {
  1036. switch (subs->stream->chip->usb_id) {
  1037. case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
  1038. case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
  1039. case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
  1040. case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
  1041. set_format_emu_quirk(subs, fmt);
  1042. break;
  1043. case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
  1044. subs->stream_offset_adj = 2;
  1045. break;
  1046. }
  1047. }
  1048. bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
  1049. {
  1050. /* devices which do not support reading the sample rate. */
  1051. switch (chip->usb_id) {
  1052. case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
  1053. case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
  1054. case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
  1055. case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
  1056. case USB_ID(0x05a7, 0x1020): /* Bose Companion 5 */
  1057. case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
  1058. case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */
  1059. case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */
  1060. case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */
  1061. case USB_ID(0x2912, 0x30c8): /* Audioengine D1 */
  1062. case USB_ID(0x413c, 0xa506): /* Dell AE515 sound bar */
  1063. case USB_ID(0x046d, 0x084c): /* Logitech ConferenceCam Connect */
  1064. return true;
  1065. }
  1066. /* devices of these vendors don't support reading rate, either */
  1067. switch (USB_ID_VENDOR(chip->usb_id)) {
  1068. case 0x045E: /* MS Lifecam */
  1069. case 0x047F: /* Plantronics */
  1070. case 0x1de7: /* Phoenix Audio */
  1071. return true;
  1072. }
  1073. return false;
  1074. }
  1075. /* ITF-USB DSD based DACs need a vendor cmd to switch
  1076. * between PCM and native DSD mode
  1077. */
  1078. static bool is_itf_usb_dsd_dac(unsigned int id)
  1079. {
  1080. switch (id) {
  1081. case USB_ID(0x154e, 0x1002): /* Denon DCD-1500RE */
  1082. case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
  1083. case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
  1084. case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
  1085. case USB_ID(0x1852, 0x5065): /* Luxman DA-06 */
  1086. case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-501V2/UD-503/NT-503 */
  1087. case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */
  1088. case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */
  1089. return true;
  1090. }
  1091. return false;
  1092. }
  1093. int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
  1094. struct audioformat *fmt)
  1095. {
  1096. struct usb_device *dev = subs->dev;
  1097. int err;
  1098. if (is_itf_usb_dsd_dac(subs->stream->chip->usb_id)) {
  1099. /* First switch to alt set 0, otherwise the mode switch cmd
  1100. * will not be accepted by the DAC
  1101. */
  1102. err = usb_set_interface(dev, fmt->iface, 0);
  1103. if (err < 0)
  1104. return err;
  1105. msleep(20); /* Delay needed after setting the interface */
  1106. /* Vendor mode switch cmd is required. */
  1107. if (fmt->formats & SNDRV_PCM_FMTBIT_DSD_U32_BE) {
  1108. /* DSD mode (DSD_U32) requested */
  1109. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
  1110. USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
  1111. 1, 1, NULL, 0);
  1112. if (err < 0)
  1113. return err;
  1114. } else {
  1115. /* PCM or DOP mode (S32) requested */
  1116. /* PCM mode (S16) requested */
  1117. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
  1118. USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
  1119. 0, 1, NULL, 0);
  1120. if (err < 0)
  1121. return err;
  1122. }
  1123. msleep(20);
  1124. }
  1125. return 0;
  1126. }
  1127. void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
  1128. {
  1129. /*
  1130. * "Playback Design" products send bogus feedback data at the start
  1131. * of the stream. Ignore them.
  1132. */
  1133. if (USB_ID_VENDOR(ep->chip->usb_id) == 0x23ba &&
  1134. ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
  1135. ep->skip_packets = 4;
  1136. /*
  1137. * M-Audio Fast Track C400/C600 - when packets are not skipped, real
  1138. * world latency varies by approx. +/- 50 frames (at 96KHz) each time
  1139. * the stream is (re)started. When skipping packets 16 at endpoint
  1140. * start up, the real world latency is stable within +/- 1 frame (also
  1141. * across power cycles).
  1142. */
  1143. if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
  1144. ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
  1145. ep->type == SND_USB_ENDPOINT_TYPE_DATA)
  1146. ep->skip_packets = 16;
  1147. /* Work around devices that report unreasonable feedback data */
  1148. if ((ep->chip->usb_id == USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
  1149. ep->chip->usb_id == USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
  1150. ep->syncmaxsize == 4)
  1151. ep->tenor_fb_quirk = 1;
  1152. }
  1153. void snd_usb_set_interface_quirk(struct usb_device *dev)
  1154. {
  1155. struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
  1156. if (!chip)
  1157. return;
  1158. /*
  1159. * "Playback Design" products need a 50ms delay after setting the
  1160. * USB interface.
  1161. */
  1162. switch (USB_ID_VENDOR(chip->usb_id)) {
  1163. case 0x23ba: /* Playback Design */
  1164. case 0x0644: /* TEAC Corp. */
  1165. msleep(50);
  1166. break;
  1167. }
  1168. }
  1169. /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
  1170. void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
  1171. __u8 request, __u8 requesttype, __u16 value,
  1172. __u16 index, void *data, __u16 size)
  1173. {
  1174. struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
  1175. if (!chip)
  1176. return;
  1177. /*
  1178. * "Playback Design" products need a 20ms delay after each
  1179. * class compliant request
  1180. */
  1181. if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
  1182. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1183. msleep(20);
  1184. /*
  1185. * "TEAC Corp." products need a 20ms delay after each
  1186. * class compliant request
  1187. */
  1188. if (USB_ID_VENDOR(chip->usb_id) == 0x0644 &&
  1189. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1190. msleep(20);
  1191. /* ITF-USB DSD based DACs functionality need a delay
  1192. * after each class compliant request
  1193. */
  1194. if (is_itf_usb_dsd_dac(chip->usb_id)
  1195. && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1196. msleep(20);
  1197. /*
  1198. * Plantronics headsets (C320, C320-M, etc) need a delay to avoid
  1199. * random microhpone failures.
  1200. */
  1201. if (USB_ID_VENDOR(chip->usb_id) == 0x047f &&
  1202. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1203. msleep(20);
  1204. /* Zoom R16/24, many Logitech(at least H650e/H570e/BCC950),
  1205. * Jabra 550a, Kingston HyperX needs a tiny delay here,
  1206. * otherwise requests like get/set frequency return
  1207. * as failed despite actually succeeding.
  1208. */
  1209. if ((chip->usb_id == USB_ID(0x1686, 0x00dd) ||
  1210. USB_ID_VENDOR(chip->usb_id) == 0x046d || /* Logitech */
  1211. chip->usb_id == USB_ID(0x0b0e, 0x0349) ||
  1212. chip->usb_id == USB_ID(0x0951, 0x16ad)) &&
  1213. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1214. usleep_range(1000, 2000);
  1215. /*
  1216. * Samsung USBC Headset (AKG) need a tiny delay after each
  1217. * class compliant request. (Model number: AAM625R or AAM627R)
  1218. */
  1219. if (chip->usb_id == USB_ID(0x04e8, 0xa051) &&
  1220. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1221. usleep_range(5000, 6000);
  1222. }
  1223. /*
  1224. * snd_usb_interface_dsd_format_quirks() is called from format.c to
  1225. * augment the PCM format bit-field for DSD types. The UAC standards
  1226. * don't have a designated bit field to denote DSD-capable interfaces,
  1227. * hence all hardware that is known to support this format has to be
  1228. * listed here.
  1229. */
  1230. u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
  1231. struct audioformat *fp,
  1232. unsigned int sample_bytes)
  1233. {
  1234. struct usb_interface *iface;
  1235. /* Playback Designs */
  1236. if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
  1237. USB_ID_PRODUCT(chip->usb_id) < 0x0110) {
  1238. switch (fp->altsetting) {
  1239. case 1:
  1240. fp->dsd_dop = true;
  1241. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  1242. case 2:
  1243. fp->dsd_bitrev = true;
  1244. return SNDRV_PCM_FMTBIT_DSD_U8;
  1245. case 3:
  1246. fp->dsd_bitrev = true;
  1247. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  1248. }
  1249. }
  1250. /* XMOS based USB DACs */
  1251. switch (chip->usb_id) {
  1252. case USB_ID(0x1511, 0x0037): /* AURALiC VEGA */
  1253. case USB_ID(0x2522, 0x0012): /* LH Labs VI DAC Infinity */
  1254. case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
  1255. if (fp->altsetting == 2)
  1256. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1257. break;
  1258. case USB_ID(0x0d8c, 0x0316): /* Hegel HD12 DSD */
  1259. case USB_ID(0x10cb, 0x0103): /* The Bit Opus #3; with fp->dsd_raw */
  1260. case USB_ID(0x16d0, 0x06b2): /* NuPrime DAC-10 */
  1261. case USB_ID(0x16d0, 0x09dd): /* Encore mDSD */
  1262. case USB_ID(0x16d0, 0x0733): /* Furutech ADL Stratos */
  1263. case USB_ID(0x16d0, 0x09db): /* NuPrime Audio DAC-9 */
  1264. case USB_ID(0x1db5, 0x0003): /* Bryston BDA3 */
  1265. case USB_ID(0x22e1, 0xca01): /* HDTA Serenade DSD */
  1266. case USB_ID(0x249c, 0x9326): /* M2Tech Young MkIII */
  1267. case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
  1268. case USB_ID(0x2622, 0x0041): /* Audiolab M-DAC+ */
  1269. case USB_ID(0x27f7, 0x3002): /* W4S DAC-2v2SE */
  1270. case USB_ID(0x29a2, 0x0086): /* Mutec MC3+ USB */
  1271. case USB_ID(0x6b42, 0x0042): /* MSB Technology */
  1272. if (fp->altsetting == 3)
  1273. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1274. break;
  1275. /* Amanero Combo384 USB based DACs with native DSD support */
  1276. case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
  1277. case USB_ID(0x2ab6, 0x0004): /* T+A DAC8DSD-V2.0, MP1000E-V2.0, MP2000R-V2.0, MP2500R-V2.0, MP3100HV-V2.0 */
  1278. case USB_ID(0x2ab6, 0x0005): /* T+A USB HD Audio 1 */
  1279. case USB_ID(0x2ab6, 0x0006): /* T+A USB HD Audio 2 */
  1280. if (fp->altsetting == 2) {
  1281. switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) {
  1282. case 0x199:
  1283. return SNDRV_PCM_FMTBIT_DSD_U32_LE;
  1284. case 0x19b:
  1285. case 0x203:
  1286. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1287. default:
  1288. break;
  1289. }
  1290. }
  1291. break;
  1292. case USB_ID(0x16d0, 0x0a23):
  1293. if (fp->altsetting == 2)
  1294. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1295. break;
  1296. default:
  1297. break;
  1298. }
  1299. /* ITF-USB DSD based DACs */
  1300. if (is_itf_usb_dsd_dac(chip->usb_id)) {
  1301. iface = usb_ifnum_to_if(chip->dev, fp->iface);
  1302. /* Altsetting 2 support native DSD if the num of altsets is
  1303. * three (0-2),
  1304. * Altsetting 3 support native DSD if the num of altsets is
  1305. * four (0-3).
  1306. */
  1307. if (fp->altsetting == iface->num_altsetting - 1)
  1308. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1309. }
  1310. /* Mostly generic method to detect many DSD-capable implementations -
  1311. * from XMOS/Thesycon
  1312. */
  1313. switch (USB_ID_VENDOR(chip->usb_id)) {
  1314. case 0x152a: /* Thesycon devices */
  1315. case 0x20b1: /* XMOS based devices */
  1316. case 0x22d9: /* Oppo */
  1317. case 0x23ba: /* Playback Designs */
  1318. case 0x25ce: /* Mytek devices */
  1319. case 0x278b: /* Rotel? */
  1320. case 0x292b: /* Gustard/Ess based devices */
  1321. case 0x2972: /* FiiO devices */
  1322. case 0x2ab6: /* T+A devices */
  1323. case 0x3353: /* Khadas devices */
  1324. case 0x3842: /* EVGA */
  1325. case 0xc502: /* HiBy devices */
  1326. if (fp->dsd_raw)
  1327. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1328. break;
  1329. default:
  1330. break;
  1331. }
  1332. return 0;
  1333. }
  1334. void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
  1335. struct audioformat *fp,
  1336. int stream)
  1337. {
  1338. switch (chip->usb_id) {
  1339. case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
  1340. /* Optoplay sets the sample rate attribute although
  1341. * it seems not supporting it in fact.
  1342. */
  1343. fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
  1344. break;
  1345. case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
  1346. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  1347. /* doesn't set the sample rate attribute, but supports it */
  1348. fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
  1349. break;
  1350. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
  1351. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
  1352. case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
  1353. case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
  1354. an older model 77d:223) */
  1355. /*
  1356. * plantronics headset and Griffin iMic have set adaptive-in
  1357. * although it's really not...
  1358. */
  1359. fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
  1360. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  1361. fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
  1362. else
  1363. fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
  1364. break;
  1365. }
  1366. }
  1367. /*
  1368. * registration quirk:
  1369. * the registration is skipped if a device matches with the given ID,
  1370. * unless the interface reaches to the defined one. This is for delaying
  1371. * the registration until the last known interface, so that the card and
  1372. * devices appear at the same time.
  1373. */
  1374. struct registration_quirk {
  1375. unsigned int usb_id; /* composed via USB_ID() */
  1376. unsigned int interface; /* the interface to trigger register */
  1377. };
  1378. #define REG_QUIRK_ENTRY(vendor, product, iface) \
  1379. { .usb_id = USB_ID(vendor, product), .interface = (iface) }
  1380. static const struct registration_quirk registration_quirks[] = {
  1381. REG_QUIRK_ENTRY(0x0951, 0x16d8, 2), /* Kingston HyperX AMP */
  1382. REG_QUIRK_ENTRY(0x0951, 0x16ed, 2), /* Kingston HyperX Cloud Alpha S */
  1383. REG_QUIRK_ENTRY(0x0951, 0x16ea, 2), /* Kingston HyperX Cloud Flight S */
  1384. { 0 } /* terminator */
  1385. };
  1386. /* return true if skipping registration */
  1387. bool snd_usb_registration_quirk(struct snd_usb_audio *chip, int iface)
  1388. {
  1389. const struct registration_quirk *q;
  1390. for (q = registration_quirks; q->usb_id; q++)
  1391. if (chip->usb_id == q->usb_id)
  1392. return iface != q->interface;
  1393. /* Register as normal */
  1394. return false;
  1395. }