quirks.c 35 KB

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