quirks.c 34 KB

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