quirks.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  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 && (injd->bLength < 5 ||
  238. (injd->bJackType != USB_MS_EMBEDDED &&
  239. injd->bJackType != USB_MS_EXTERNAL)))
  240. return -ENODEV;
  241. if (outjd && (outjd->bLength < 6 ||
  242. (outjd->bJackType != USB_MS_EMBEDDED &&
  243. outjd->bJackType != USB_MS_EXTERNAL)))
  244. return -ENODEV;
  245. return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk);
  246. }
  247. static int create_roland_midi_quirk(struct snd_usb_audio *chip,
  248. struct usb_interface *iface,
  249. struct usb_driver *driver,
  250. struct usb_host_interface *alts)
  251. {
  252. static const struct snd_usb_audio_quirk roland_midi_quirk = {
  253. .type = QUIRK_MIDI_ROLAND
  254. };
  255. u8 *roland_desc = NULL;
  256. /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
  257. for (;;) {
  258. roland_desc = snd_usb_find_csint_desc(alts->extra,
  259. alts->extralen,
  260. roland_desc, 0xf1);
  261. if (!roland_desc)
  262. return -ENODEV;
  263. if (roland_desc[0] < 6 || roland_desc[3] != 2)
  264. continue;
  265. return create_any_midi_quirk(chip, iface, driver,
  266. &roland_midi_quirk);
  267. }
  268. }
  269. static int create_std_midi_quirk(struct snd_usb_audio *chip,
  270. struct usb_interface *iface,
  271. struct usb_driver *driver,
  272. struct usb_host_interface *alts)
  273. {
  274. struct usb_ms_header_descriptor *mshd;
  275. struct usb_ms_endpoint_descriptor *msepd;
  276. /* must have the MIDIStreaming interface header descriptor*/
  277. mshd = (struct usb_ms_header_descriptor *)alts->extra;
  278. if (alts->extralen < 7 ||
  279. mshd->bLength < 7 ||
  280. mshd->bDescriptorType != USB_DT_CS_INTERFACE ||
  281. mshd->bDescriptorSubtype != USB_MS_HEADER)
  282. return -ENODEV;
  283. /* must have the MIDIStreaming endpoint descriptor*/
  284. msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra;
  285. if (alts->endpoint[0].extralen < 4 ||
  286. msepd->bLength < 4 ||
  287. msepd->bDescriptorType != USB_DT_CS_ENDPOINT ||
  288. msepd->bDescriptorSubtype != UAC_MS_GENERAL ||
  289. msepd->bNumEmbMIDIJack < 1 ||
  290. msepd->bNumEmbMIDIJack > 16)
  291. return -ENODEV;
  292. return create_any_midi_quirk(chip, iface, driver, NULL);
  293. }
  294. static int create_auto_midi_quirk(struct snd_usb_audio *chip,
  295. struct usb_interface *iface,
  296. struct usb_driver *driver)
  297. {
  298. struct usb_host_interface *alts;
  299. struct usb_interface_descriptor *altsd;
  300. struct usb_endpoint_descriptor *epd;
  301. int err;
  302. alts = &iface->altsetting[0];
  303. altsd = get_iface_desc(alts);
  304. /* must have at least one bulk/interrupt endpoint for streaming */
  305. if (altsd->bNumEndpoints < 1)
  306. return -ENODEV;
  307. epd = get_endpoint(alts, 0);
  308. if (!usb_endpoint_xfer_bulk(epd) &&
  309. !usb_endpoint_xfer_int(epd))
  310. return -ENODEV;
  311. switch (USB_ID_VENDOR(chip->usb_id)) {
  312. case 0x0499: /* Yamaha */
  313. err = create_yamaha_midi_quirk(chip, iface, driver, alts);
  314. if (err != -ENODEV)
  315. return err;
  316. break;
  317. case 0x0582: /* Roland */
  318. err = create_roland_midi_quirk(chip, iface, driver, alts);
  319. if (err != -ENODEV)
  320. return err;
  321. break;
  322. }
  323. return create_std_midi_quirk(chip, iface, driver, alts);
  324. }
  325. static int create_autodetect_quirk(struct snd_usb_audio *chip,
  326. struct usb_interface *iface,
  327. struct usb_driver *driver)
  328. {
  329. int err;
  330. err = create_auto_pcm_quirk(chip, iface, driver);
  331. if (err == -ENODEV)
  332. err = create_auto_midi_quirk(chip, iface, driver);
  333. return err;
  334. }
  335. static int create_autodetect_quirks(struct snd_usb_audio *chip,
  336. struct usb_interface *iface,
  337. struct usb_driver *driver,
  338. const struct snd_usb_audio_quirk *quirk)
  339. {
  340. int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
  341. int ifcount, ifnum, err;
  342. err = create_autodetect_quirk(chip, iface, driver);
  343. if (err < 0)
  344. return err;
  345. /*
  346. * ALSA PCM playback/capture devices cannot be registered in two steps,
  347. * so we have to claim the other corresponding interface here.
  348. */
  349. ifcount = chip->dev->actconfig->desc.bNumInterfaces;
  350. for (ifnum = 0; ifnum < ifcount; ifnum++) {
  351. if (ifnum == probed_ifnum || quirk->ifnum >= 0)
  352. continue;
  353. iface = usb_ifnum_to_if(chip->dev, ifnum);
  354. if (!iface ||
  355. usb_interface_claimed(iface) ||
  356. get_iface_desc(iface->altsetting)->bInterfaceClass !=
  357. USB_CLASS_VENDOR_SPEC)
  358. continue;
  359. err = create_autodetect_quirk(chip, iface, driver);
  360. if (err >= 0) {
  361. err = usb_driver_claim_interface(driver, iface,
  362. USB_AUDIO_IFACE_UNUSED);
  363. if (err < 0)
  364. return err;
  365. }
  366. }
  367. return 0;
  368. }
  369. /*
  370. * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
  371. * The only way to detect the sample rate is by looking at wMaxPacketSize.
  372. */
  373. static int create_uaxx_quirk(struct snd_usb_audio *chip,
  374. struct usb_interface *iface,
  375. struct usb_driver *driver,
  376. const struct snd_usb_audio_quirk *quirk)
  377. {
  378. static const struct audioformat ua_format = {
  379. .formats = SNDRV_PCM_FMTBIT_S24_3LE,
  380. .channels = 2,
  381. .fmt_type = UAC_FORMAT_TYPE_I,
  382. .altsetting = 1,
  383. .altset_idx = 1,
  384. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  385. };
  386. struct usb_host_interface *alts;
  387. struct usb_interface_descriptor *altsd;
  388. struct audioformat *fp;
  389. int stream, err;
  390. /* both PCM and MIDI interfaces have 2 or more altsettings */
  391. if (iface->num_altsetting < 2)
  392. return -ENXIO;
  393. alts = &iface->altsetting[1];
  394. altsd = get_iface_desc(alts);
  395. if (altsd->bNumEndpoints == 2) {
  396. static const struct snd_usb_midi_endpoint_info ua700_ep = {
  397. .out_cables = 0x0003,
  398. .in_cables = 0x0003
  399. };
  400. static const struct snd_usb_audio_quirk ua700_quirk = {
  401. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  402. .data = &ua700_ep
  403. };
  404. static const struct snd_usb_midi_endpoint_info uaxx_ep = {
  405. .out_cables = 0x0001,
  406. .in_cables = 0x0001
  407. };
  408. static const struct snd_usb_audio_quirk uaxx_quirk = {
  409. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  410. .data = &uaxx_ep
  411. };
  412. const struct snd_usb_audio_quirk *quirk =
  413. chip->usb_id == USB_ID(0x0582, 0x002b)
  414. ? &ua700_quirk : &uaxx_quirk;
  415. return __snd_usbmidi_create(chip->card, iface,
  416. &chip->midi_list, quirk,
  417. chip->usb_id);
  418. }
  419. if (altsd->bNumEndpoints != 1)
  420. return -ENXIO;
  421. fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
  422. if (!fp)
  423. return -ENOMEM;
  424. fp->iface = altsd->bInterfaceNumber;
  425. fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
  426. fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
  427. fp->datainterval = 0;
  428. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  429. INIT_LIST_HEAD(&fp->list);
  430. switch (fp->maxpacksize) {
  431. case 0x120:
  432. fp->rate_max = fp->rate_min = 44100;
  433. break;
  434. case 0x138:
  435. case 0x140:
  436. fp->rate_max = fp->rate_min = 48000;
  437. break;
  438. case 0x258:
  439. case 0x260:
  440. fp->rate_max = fp->rate_min = 96000;
  441. break;
  442. default:
  443. usb_audio_err(chip, "unknown sample rate\n");
  444. kfree(fp);
  445. return -ENXIO;
  446. }
  447. stream = (fp->endpoint & USB_DIR_IN)
  448. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  449. err = snd_usb_add_audio_stream(chip, stream, fp);
  450. if (err < 0) {
  451. list_del(&fp->list); /* unlink for avoiding double-free */
  452. kfree(fp);
  453. return err;
  454. }
  455. usb_set_interface(chip->dev, fp->iface, 0);
  456. return 0;
  457. }
  458. /*
  459. * Create a standard mixer for the specified interface.
  460. */
  461. static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
  462. struct usb_interface *iface,
  463. struct usb_driver *driver,
  464. const struct snd_usb_audio_quirk *quirk)
  465. {
  466. if (quirk->ifnum < 0)
  467. return 0;
  468. return snd_usb_create_mixer(chip, quirk->ifnum, 0);
  469. }
  470. /*
  471. * audio-interface quirks
  472. *
  473. * returns zero if no standard audio/MIDI parsing is needed.
  474. * returns a positive value if standard audio/midi interfaces are parsed
  475. * after this.
  476. * returns a negative value at error.
  477. */
  478. int snd_usb_create_quirk(struct snd_usb_audio *chip,
  479. struct usb_interface *iface,
  480. struct usb_driver *driver,
  481. const struct snd_usb_audio_quirk *quirk)
  482. {
  483. typedef int (*quirk_func_t)(struct snd_usb_audio *,
  484. struct usb_interface *,
  485. struct usb_driver *,
  486. const struct snd_usb_audio_quirk *);
  487. static const quirk_func_t quirk_funcs[] = {
  488. [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
  489. [QUIRK_COMPOSITE] = create_composite_quirk,
  490. [QUIRK_AUTODETECT] = create_autodetect_quirks,
  491. [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
  492. [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
  493. [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
  494. [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
  495. [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
  496. [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
  497. [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
  498. [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
  499. [QUIRK_MIDI_CME] = create_any_midi_quirk,
  500. [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
  501. [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
  502. [QUIRK_MIDI_CH345] = create_any_midi_quirk,
  503. [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
  504. [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
  505. [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
  506. [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
  507. [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
  508. };
  509. if (quirk->type < QUIRK_TYPE_COUNT) {
  510. return quirk_funcs[quirk->type](chip, iface, driver, quirk);
  511. } else {
  512. usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
  513. return -ENXIO;
  514. }
  515. }
  516. /*
  517. * boot quirks
  518. */
  519. #define EXTIGY_FIRMWARE_SIZE_OLD 794
  520. #define EXTIGY_FIRMWARE_SIZE_NEW 483
  521. static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
  522. {
  523. struct usb_host_config *config = dev->actconfig;
  524. int err;
  525. if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
  526. le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
  527. dev_dbg(&dev->dev, "sending Extigy boot sequence...\n");
  528. /* Send message to force it to reconnect with full interface. */
  529. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
  530. 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
  531. if (err < 0)
  532. dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
  533. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  534. &dev->descriptor, sizeof(dev->descriptor));
  535. config = dev->actconfig;
  536. if (err < 0)
  537. dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
  538. err = usb_reset_configuration(dev);
  539. if (err < 0)
  540. dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
  541. dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
  542. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  543. return -ENODEV; /* quit this anyway */
  544. }
  545. return 0;
  546. }
  547. static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
  548. {
  549. u8 buf = 1;
  550. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
  551. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  552. 0, 0, &buf, 1);
  553. if (buf == 0) {
  554. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
  555. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  556. 1, 2000, NULL, 0);
  557. return -ENODEV;
  558. }
  559. return 0;
  560. }
  561. static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
  562. {
  563. int err;
  564. if (dev->actconfig->desc.bConfigurationValue == 1) {
  565. dev_info(&dev->dev,
  566. "Fast Track Pro switching to config #2\n");
  567. /* This function has to be available by the usb core module.
  568. * if it is not avialable the boot quirk has to be left out
  569. * and the configuration has to be set by udev or hotplug
  570. * rules
  571. */
  572. err = usb_driver_set_configuration(dev, 2);
  573. if (err < 0)
  574. dev_dbg(&dev->dev,
  575. "error usb_driver_set_configuration: %d\n",
  576. err);
  577. /* Always return an error, so that we stop creating a device
  578. that will just be destroyed and recreated with a new
  579. configuration */
  580. return -ENODEV;
  581. } else
  582. dev_info(&dev->dev, "Fast Track Pro config OK\n");
  583. return 0;
  584. }
  585. /*
  586. * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
  587. * documented in the device's data sheet.
  588. */
  589. static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
  590. {
  591. u8 buf[4];
  592. buf[0] = 0x20;
  593. buf[1] = value & 0xff;
  594. buf[2] = (value >> 8) & 0xff;
  595. buf[3] = reg;
  596. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
  597. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
  598. 0, 0, &buf, 4);
  599. }
  600. static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
  601. {
  602. /*
  603. * Enable line-out driver mode, set headphone source to front
  604. * channels, enable stereo mic.
  605. */
  606. return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
  607. }
  608. /*
  609. * C-Media CM6206 is based on CM106 with two additional
  610. * registers that are not documented in the data sheet.
  611. * Values here are chosen based on sniffing USB traffic
  612. * under Windows.
  613. */
  614. static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
  615. {
  616. int err = 0, reg;
  617. int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
  618. for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
  619. err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
  620. if (err < 0)
  621. return err;
  622. }
  623. return err;
  624. }
  625. /* quirk for Plantronics GameCom 780 with CM6302 chip */
  626. static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev)
  627. {
  628. /* set the initial volume and don't change; other values are either
  629. * too loud or silent due to firmware bug (bko#65251)
  630. */
  631. u8 buf[2] = { 0x74, 0xe3 };
  632. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
  633. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  634. UAC_FU_VOLUME << 8, 9 << 8, buf, 2);
  635. }
  636. /*
  637. * Novation Twitch DJ controller
  638. * Focusrite Novation Saffire 6 USB audio card
  639. */
  640. static int snd_usb_novation_boot_quirk(struct usb_device *dev)
  641. {
  642. /* preemptively set up the device because otherwise the
  643. * raw MIDI endpoints are not active */
  644. usb_set_interface(dev, 0, 1);
  645. return 0;
  646. }
  647. /*
  648. * This call will put the synth in "USB send" mode, i.e it will send MIDI
  649. * messages through USB (this is disabled at startup). The synth will
  650. * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
  651. * sign on its LCD. Values here are chosen based on sniffing USB traffic
  652. * under Windows.
  653. */
  654. static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
  655. {
  656. int err, actual_length;
  657. /* "midi send" enable */
  658. static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
  659. void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
  660. if (!buf)
  661. return -ENOMEM;
  662. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
  663. ARRAY_SIZE(seq), &actual_length, 1000);
  664. kfree(buf);
  665. if (err < 0)
  666. return err;
  667. return 0;
  668. }
  669. /*
  670. * Some sound cards from Native Instruments are in fact compliant to the USB
  671. * audio standard of version 2 and other approved USB standards, even though
  672. * they come up as vendor-specific device when first connected.
  673. *
  674. * However, they can be told to come up with a new set of descriptors
  675. * upon their next enumeration, and the interfaces announced by the new
  676. * descriptors will then be handled by the kernel's class drivers. As the
  677. * product ID will also change, no further checks are required.
  678. */
  679. static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
  680. {
  681. int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  682. 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  683. 1, 0, NULL, 0, 1000);
  684. if (ret < 0)
  685. return ret;
  686. usb_reset_device(dev);
  687. /* return -EAGAIN, so the creation of an audio interface for this
  688. * temporary device is aborted. The device will reconnect with a
  689. * new product ID */
  690. return -EAGAIN;
  691. }
  692. static void mbox2_setup_48_24_magic(struct usb_device *dev)
  693. {
  694. u8 srate[3];
  695. u8 temp[12];
  696. /* Choose 48000Hz permanently */
  697. srate[0] = 0x80;
  698. srate[1] = 0xbb;
  699. srate[2] = 0x00;
  700. /* Send the magic! */
  701. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  702. 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
  703. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  704. 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
  705. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  706. 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
  707. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  708. 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
  709. return;
  710. }
  711. /* Digidesign Mbox 2 needs to load firmware onboard
  712. * and driver must wait a few seconds for initialisation.
  713. */
  714. #define MBOX2_FIRMWARE_SIZE 646
  715. #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
  716. #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
  717. static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
  718. {
  719. struct usb_host_config *config = dev->actconfig;
  720. int err;
  721. u8 bootresponse[0x12];
  722. int fwsize;
  723. int count;
  724. fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
  725. if (fwsize != MBOX2_FIRMWARE_SIZE) {
  726. dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
  727. return -ENODEV;
  728. }
  729. dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
  730. count = 0;
  731. bootresponse[0] = MBOX2_BOOT_LOADING;
  732. while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
  733. msleep(500); /* 0.5 second delay */
  734. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  735. /* Control magic - load onboard firmware */
  736. 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
  737. if (bootresponse[0] == MBOX2_BOOT_READY)
  738. break;
  739. dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
  740. count++;
  741. }
  742. if (bootresponse[0] != MBOX2_BOOT_READY) {
  743. dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
  744. return -ENODEV;
  745. }
  746. dev_dbg(&dev->dev, "device initialised!\n");
  747. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  748. &dev->descriptor, sizeof(dev->descriptor));
  749. config = dev->actconfig;
  750. if (err < 0)
  751. dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
  752. err = usb_reset_configuration(dev);
  753. if (err < 0)
  754. dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
  755. dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
  756. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  757. mbox2_setup_48_24_magic(dev);
  758. dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
  759. return 0; /* Successful boot */
  760. }
  761. /*
  762. * Setup quirks
  763. */
  764. #define MAUDIO_SET 0x01 /* parse device_setup */
  765. #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
  766. #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
  767. #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
  768. #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
  769. #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
  770. #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
  771. #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
  772. #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
  773. #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
  774. #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
  775. static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
  776. int iface, int altno)
  777. {
  778. /* Reset ALL ifaces to 0 altsetting.
  779. * Call it for every possible altsetting of every interface.
  780. */
  781. usb_set_interface(chip->dev, iface, 0);
  782. if (chip->setup & MAUDIO_SET) {
  783. if (chip->setup & MAUDIO_SET_COMPATIBLE) {
  784. if (iface != 1 && iface != 2)
  785. return 1; /* skip all interfaces but 1 and 2 */
  786. } else {
  787. unsigned int mask;
  788. if (iface == 1 || iface == 2)
  789. return 1; /* skip interfaces 1 and 2 */
  790. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  791. return 1; /* skip this altsetting */
  792. mask = chip->setup & MAUDIO_SET_MASK;
  793. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  794. return 1; /* skip this altsetting */
  795. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  796. return 1; /* skip this altsetting */
  797. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
  798. return 1; /* skip this altsetting */
  799. }
  800. }
  801. usb_audio_dbg(chip,
  802. "using altsetting %d for interface %d config %d\n",
  803. altno, iface, chip->setup);
  804. return 0; /* keep this altsetting */
  805. }
  806. static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
  807. int iface,
  808. int altno)
  809. {
  810. /* Reset ALL ifaces to 0 altsetting.
  811. * Call it for every possible altsetting of every interface.
  812. */
  813. usb_set_interface(chip->dev, iface, 0);
  814. if (chip->setup & MAUDIO_SET) {
  815. unsigned int mask;
  816. if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
  817. return 1; /* skip this altsetting */
  818. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  819. return 1; /* skip this altsetting */
  820. mask = chip->setup & MAUDIO_SET_MASK;
  821. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  822. return 1; /* skip this altsetting */
  823. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  824. return 1; /* skip this altsetting */
  825. if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
  826. return 1; /* skip this altsetting */
  827. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
  828. return 1; /* skip this altsetting */
  829. }
  830. return 0; /* keep this altsetting */
  831. }
  832. static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
  833. int iface, int altno)
  834. {
  835. /* Reset ALL ifaces to 0 altsetting.
  836. * Call it for every possible altsetting of every interface.
  837. */
  838. usb_set_interface(chip->dev, iface, 0);
  839. /* possible configuration where both inputs and only one output is
  840. *used is not supported by the current setup
  841. */
  842. if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
  843. if (chip->setup & MAUDIO_SET_96K) {
  844. if (altno != 3 && altno != 6)
  845. return 1;
  846. } else if (chip->setup & MAUDIO_SET_DI) {
  847. if (iface == 4)
  848. return 1; /* no analog input */
  849. if (altno != 2 && altno != 5)
  850. return 1; /* enable only altsets 2 and 5 */
  851. } else {
  852. if (iface == 5)
  853. return 1; /* disable digialt input */
  854. if (altno != 2 && altno != 5)
  855. return 1; /* enalbe only altsets 2 and 5 */
  856. }
  857. } else {
  858. /* keep only 16-Bit mode */
  859. if (altno != 1)
  860. return 1;
  861. }
  862. usb_audio_dbg(chip,
  863. "using altsetting %d for interface %d config %d\n",
  864. altno, iface, chip->setup);
  865. return 0; /* keep this altsetting */
  866. }
  867. int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
  868. int iface,
  869. int altno)
  870. {
  871. /* audiophile usb: skip altsets incompatible with device_setup */
  872. if (chip->usb_id == USB_ID(0x0763, 0x2003))
  873. return audiophile_skip_setting_quirk(chip, iface, altno);
  874. /* quattro usb: skip altsets incompatible with device_setup */
  875. if (chip->usb_id == USB_ID(0x0763, 0x2001))
  876. return quattro_skip_setting_quirk(chip, iface, altno);
  877. /* fasttrackpro usb: skip altsets incompatible with device_setup */
  878. if (chip->usb_id == USB_ID(0x0763, 0x2012))
  879. return fasttrackpro_skip_setting_quirk(chip, iface, altno);
  880. return 0;
  881. }
  882. int snd_usb_apply_boot_quirk(struct usb_device *dev,
  883. struct usb_interface *intf,
  884. const struct snd_usb_audio_quirk *quirk,
  885. unsigned int id)
  886. {
  887. switch (id) {
  888. case USB_ID(0x041e, 0x3000):
  889. /* SB Extigy needs special boot-up sequence */
  890. /* if more models come, this will go to the quirk list. */
  891. return snd_usb_extigy_boot_quirk(dev, intf);
  892. case USB_ID(0x041e, 0x3020):
  893. /* SB Audigy 2 NX needs its own boot-up magic, too */
  894. return snd_usb_audigy2nx_boot_quirk(dev);
  895. case USB_ID(0x10f5, 0x0200):
  896. /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
  897. return snd_usb_cm106_boot_quirk(dev);
  898. case USB_ID(0x0d8c, 0x0102):
  899. /* C-Media CM6206 / CM106-Like Sound Device */
  900. case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
  901. return snd_usb_cm6206_boot_quirk(dev);
  902. case USB_ID(0x0dba, 0x3000):
  903. /* Digidesign Mbox 2 */
  904. return snd_usb_mbox2_boot_quirk(dev);
  905. case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
  906. case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
  907. return snd_usb_novation_boot_quirk(dev);
  908. case USB_ID(0x133e, 0x0815):
  909. /* Access Music VirusTI Desktop */
  910. return snd_usb_accessmusic_boot_quirk(dev);
  911. case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
  912. case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
  913. case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
  914. return snd_usb_nativeinstruments_boot_quirk(dev);
  915. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
  916. return snd_usb_fasttrackpro_boot_quirk(dev);
  917. case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
  918. return snd_usb_gamecon780_boot_quirk(dev);
  919. }
  920. return 0;
  921. }
  922. /*
  923. * check if the device uses big-endian samples
  924. */
  925. int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
  926. {
  927. /* it depends on altsetting whether the device is big-endian or not */
  928. switch (chip->usb_id) {
  929. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
  930. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  931. fp->altsetting == 5 || fp->altsetting == 6)
  932. return 1;
  933. break;
  934. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  935. if (chip->setup == 0x00 ||
  936. fp->altsetting == 1 || fp->altsetting == 2 ||
  937. fp->altsetting == 3)
  938. return 1;
  939. break;
  940. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
  941. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  942. fp->altsetting == 5 || fp->altsetting == 6)
  943. return 1;
  944. break;
  945. }
  946. return 0;
  947. }
  948. /*
  949. * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
  950. * not for interface.
  951. */
  952. enum {
  953. EMU_QUIRK_SR_44100HZ = 0,
  954. EMU_QUIRK_SR_48000HZ,
  955. EMU_QUIRK_SR_88200HZ,
  956. EMU_QUIRK_SR_96000HZ,
  957. EMU_QUIRK_SR_176400HZ,
  958. EMU_QUIRK_SR_192000HZ
  959. };
  960. static void set_format_emu_quirk(struct snd_usb_substream *subs,
  961. struct audioformat *fmt)
  962. {
  963. unsigned char emu_samplerate_id = 0;
  964. /* When capture is active
  965. * sample rate shouldn't be changed
  966. * by playback substream
  967. */
  968. if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
  969. if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
  970. return;
  971. }
  972. switch (fmt->rate_min) {
  973. case 48000:
  974. emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
  975. break;
  976. case 88200:
  977. emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
  978. break;
  979. case 96000:
  980. emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
  981. break;
  982. case 176400:
  983. emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
  984. break;
  985. case 192000:
  986. emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
  987. break;
  988. default:
  989. emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
  990. break;
  991. }
  992. snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
  993. subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
  994. }
  995. void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
  996. struct audioformat *fmt)
  997. {
  998. switch (subs->stream->chip->usb_id) {
  999. case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
  1000. case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
  1001. case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
  1002. case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
  1003. set_format_emu_quirk(subs, fmt);
  1004. break;
  1005. case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
  1006. subs->stream_offset_adj = 2;
  1007. break;
  1008. }
  1009. }
  1010. bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
  1011. {
  1012. /* devices which do not support reading the sample rate. */
  1013. switch (chip->usb_id) {
  1014. case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
  1015. case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
  1016. case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
  1017. case USB_ID(0x045E, 0x076E): /* MS Lifecam HD-5001 */
  1018. case USB_ID(0x045E, 0x076F): /* MS Lifecam HD-6000 */
  1019. case USB_ID(0x045E, 0x0772): /* MS Lifecam Studio */
  1020. case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */
  1021. case USB_ID(0x047F, 0x02F7): /* Plantronics BT-600 */
  1022. case USB_ID(0x047F, 0x0415): /* Plantronics BT-300 */
  1023. case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */
  1024. case USB_ID(0x047F, 0xC022): /* Plantronics C310 */
  1025. case USB_ID(0x047F, 0xC02F): /* Plantronics P610 */
  1026. case USB_ID(0x047F, 0xC036): /* Plantronics C520-M */
  1027. case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
  1028. case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
  1029. case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
  1030. case USB_ID(0x05a7, 0x1020): /* Bose Companion 5 */
  1031. case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
  1032. case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */
  1033. case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */
  1034. case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */
  1035. case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */
  1036. case USB_ID(0x1de7, 0x0114): /* Phoenix Audio MT202pcs */
  1037. case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */
  1038. case USB_ID(0x2912, 0x30c8): /* Audioengine D1 */
  1039. case USB_ID(0x413c, 0xa506): /* Dell AE515 sound bar */
  1040. case USB_ID(0x046d, 0x084c): /* Logitech ConferenceCam Connect */
  1041. return true;
  1042. }
  1043. return false;
  1044. }
  1045. /* ITF-USB DSD based DACs need a vendor cmd to switch
  1046. * between PCM and native DSD mode
  1047. * (2 altsets version)
  1048. */
  1049. static bool is_itf_usb_dsd_2alts_dac(unsigned int id)
  1050. {
  1051. switch (id) {
  1052. case USB_ID(0x154e, 0x1002): /* Denon DCD-1500RE */
  1053. case USB_ID(0x154e, 0x1003): /* Denon DA-300USB */
  1054. case USB_ID(0x154e, 0x3005): /* Marantz HD-DAC1 */
  1055. case USB_ID(0x154e, 0x3006): /* Marantz SA-14S1 */
  1056. case USB_ID(0x1852, 0x5065): /* Luxman DA-06 */
  1057. return true;
  1058. }
  1059. return false;
  1060. }
  1061. /* ITF-USB DSD based DACs need a vendor cmd to switch
  1062. * between PCM and native DSD mode
  1063. * (3 altsets version)
  1064. */
  1065. static bool is_itf_usb_dsd_3alts_dac(unsigned int id)
  1066. {
  1067. switch (id) {
  1068. case USB_ID(0x0644, 0x8043): /* TEAC UD-501/UD-503/NT-503 */
  1069. case USB_ID(0x0644, 0x8044): /* Esoteric D-05X */
  1070. case USB_ID(0x0644, 0x804a): /* TEAC UD-301 */
  1071. return true;
  1072. }
  1073. return false;
  1074. }
  1075. int snd_usb_select_mode_quirk(struct snd_usb_substream *subs,
  1076. struct audioformat *fmt)
  1077. {
  1078. struct usb_device *dev = subs->dev;
  1079. int err;
  1080. if (is_itf_usb_dsd_2alts_dac(subs->stream->chip->usb_id)) {
  1081. /* First switch to alt set 0, otherwise the mode switch cmd
  1082. * will not be accepted by the DAC
  1083. */
  1084. err = usb_set_interface(dev, fmt->iface, 0);
  1085. if (err < 0)
  1086. return err;
  1087. mdelay(20); /* Delay needed after setting the interface */
  1088. switch (fmt->altsetting) {
  1089. case 2: /* DSD mode requested */
  1090. case 1: /* PCM mode requested */
  1091. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
  1092. USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
  1093. fmt->altsetting - 1, 1, NULL, 0);
  1094. if (err < 0)
  1095. return err;
  1096. break;
  1097. }
  1098. mdelay(20);
  1099. } else if (is_itf_usb_dsd_3alts_dac(subs->stream->chip->usb_id)) {
  1100. /* Vendor mode switch cmd is required. */
  1101. switch (fmt->altsetting) {
  1102. case 3: /* DSD mode (DSD_U32) requested */
  1103. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
  1104. USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
  1105. 1, 1, NULL, 0);
  1106. if (err < 0)
  1107. return err;
  1108. break;
  1109. case 2: /* PCM or DOP mode (S32) requested */
  1110. case 1: /* PCM mode (S16) requested */
  1111. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
  1112. USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
  1113. 0, 1, NULL, 0);
  1114. if (err < 0)
  1115. return err;
  1116. break;
  1117. }
  1118. }
  1119. return 0;
  1120. }
  1121. void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
  1122. {
  1123. /*
  1124. * "Playback Design" products send bogus feedback data at the start
  1125. * of the stream. Ignore them.
  1126. */
  1127. if (USB_ID_VENDOR(ep->chip->usb_id) == 0x23ba &&
  1128. ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
  1129. ep->skip_packets = 4;
  1130. /*
  1131. * M-Audio Fast Track C400/C600 - when packets are not skipped, real
  1132. * world latency varies by approx. +/- 50 frames (at 96KHz) each time
  1133. * the stream is (re)started. When skipping packets 16 at endpoint
  1134. * start up, the real world latency is stable within +/- 1 frame (also
  1135. * across power cycles).
  1136. */
  1137. if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
  1138. ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
  1139. ep->type == SND_USB_ENDPOINT_TYPE_DATA)
  1140. ep->skip_packets = 16;
  1141. /* Work around devices that report unreasonable feedback data */
  1142. if ((ep->chip->usb_id == USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
  1143. ep->chip->usb_id == USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
  1144. ep->syncmaxsize == 4)
  1145. ep->tenor_fb_quirk = 1;
  1146. }
  1147. void snd_usb_set_interface_quirk(struct usb_device *dev)
  1148. {
  1149. struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
  1150. if (!chip)
  1151. return;
  1152. /*
  1153. * "Playback Design" products need a 50ms delay after setting the
  1154. * USB interface.
  1155. */
  1156. switch (USB_ID_VENDOR(chip->usb_id)) {
  1157. case 0x23ba: /* Playback Design */
  1158. case 0x0644: /* TEAC Corp. */
  1159. mdelay(50);
  1160. break;
  1161. }
  1162. }
  1163. /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
  1164. void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
  1165. __u8 request, __u8 requesttype, __u16 value,
  1166. __u16 index, void *data, __u16 size)
  1167. {
  1168. struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
  1169. if (!chip)
  1170. return;
  1171. /*
  1172. * "Playback Design" products need a 20ms delay after each
  1173. * class compliant request
  1174. */
  1175. if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
  1176. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1177. mdelay(20);
  1178. /*
  1179. * "TEAC Corp." products need a 20ms delay after each
  1180. * class compliant request
  1181. */
  1182. if (USB_ID_VENDOR(chip->usb_id) == 0x0644 &&
  1183. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1184. mdelay(20);
  1185. /* ITF-USB DSD based DACs functionality need a delay
  1186. * after each class compliant request
  1187. */
  1188. if (is_itf_usb_dsd_2alts_dac(chip->usb_id)
  1189. && (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1190. mdelay(20);
  1191. /* Zoom R16/24, Logitech H650e/H570e, Jabra 550a, Kingston HyperX
  1192. * needs a tiny delay here, otherwise requests like get/set
  1193. * frequency return as failed despite actually succeeding.
  1194. */
  1195. if ((chip->usb_id == USB_ID(0x1686, 0x00dd) ||
  1196. chip->usb_id == USB_ID(0x046d, 0x0a46) ||
  1197. chip->usb_id == USB_ID(0x046d, 0x0a56) ||
  1198. chip->usb_id == USB_ID(0x0b0e, 0x0349) ||
  1199. chip->usb_id == USB_ID(0x0951, 0x16ad)) &&
  1200. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1201. mdelay(1);
  1202. if (chip->usb_id == USB_ID(0x04e8, 0xa051) &&
  1203. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  1204. mdelay(5);
  1205. }
  1206. /*
  1207. * snd_usb_interface_dsd_format_quirks() is called from format.c to
  1208. * augment the PCM format bit-field for DSD types. The UAC standards
  1209. * don't have a designated bit field to denote DSD-capable interfaces,
  1210. * hence all hardware that is known to support this format has to be
  1211. * listed here.
  1212. */
  1213. u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
  1214. struct audioformat *fp,
  1215. unsigned int sample_bytes)
  1216. {
  1217. /* Playback Designs */
  1218. if (USB_ID_VENDOR(chip->usb_id) == 0x23ba) {
  1219. switch (fp->altsetting) {
  1220. case 1:
  1221. fp->dsd_dop = true;
  1222. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  1223. case 2:
  1224. fp->dsd_bitrev = true;
  1225. return SNDRV_PCM_FMTBIT_DSD_U8;
  1226. case 3:
  1227. fp->dsd_bitrev = true;
  1228. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  1229. }
  1230. }
  1231. /* XMOS based USB DACs */
  1232. switch (chip->usb_id) {
  1233. case USB_ID(0x20b1, 0x3008): /* iFi Audio micro/nano iDSD */
  1234. case USB_ID(0x20b1, 0x2008): /* Matrix Audio X-Sabre */
  1235. case USB_ID(0x20b1, 0x300a): /* Matrix Audio Mini-i Pro */
  1236. case USB_ID(0x22d9, 0x0416): /* OPPO HA-1 */
  1237. case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
  1238. if (fp->altsetting == 2)
  1239. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1240. break;
  1241. case USB_ID(0x20b1, 0x000a): /* Gustard DAC-X20U */
  1242. case USB_ID(0x20b1, 0x2009): /* DIYINHK DSD DXD 384kHz USB to I2S/DSD */
  1243. case USB_ID(0x20b1, 0x2023): /* JLsounds I2SoverUSB */
  1244. case USB_ID(0x20b1, 0x3023): /* Aune X1S 32BIT/384 DSD DAC */
  1245. case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
  1246. if (fp->altsetting == 3)
  1247. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1248. break;
  1249. /* Amanero Combo384 USB based DACs with native DSD support */
  1250. case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
  1251. case USB_ID(0x2ab6, 0x0004): /* T+A DAC8DSD-V2.0, MP1000E-V2.0, MP2000R-V2.0, MP2500R-V2.0, MP3100HV-V2.0 */
  1252. case USB_ID(0x2ab6, 0x0005): /* T+A USB HD Audio 1 */
  1253. case USB_ID(0x2ab6, 0x0006): /* T+A USB HD Audio 2 */
  1254. if (fp->altsetting == 2) {
  1255. switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) {
  1256. case 0x199:
  1257. return SNDRV_PCM_FMTBIT_DSD_U32_LE;
  1258. case 0x19b:
  1259. case 0x203:
  1260. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1261. default:
  1262. break;
  1263. }
  1264. }
  1265. break;
  1266. case USB_ID(0x16d0, 0x0a23):
  1267. if (fp->altsetting == 2)
  1268. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1269. break;
  1270. default:
  1271. break;
  1272. }
  1273. /* ITF-USB DSD based DACs (2 altsets version) */
  1274. if (is_itf_usb_dsd_2alts_dac(chip->usb_id)) {
  1275. if (fp->altsetting == 2)
  1276. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1277. }
  1278. /* ITF-USB DSD based DACs (3 altsets version) */
  1279. if (is_itf_usb_dsd_3alts_dac(chip->usb_id)) {
  1280. if (fp->altsetting == 3)
  1281. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1282. }
  1283. return 0;
  1284. }