quirks.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  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. const struct snd_usb_audio_quirk *quirk)
  309. {
  310. int err;
  311. err = create_auto_pcm_quirk(chip, iface, driver);
  312. if (err == -ENODEV)
  313. err = create_auto_midi_quirk(chip, iface, driver);
  314. return err;
  315. }
  316. /*
  317. * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
  318. * The only way to detect the sample rate is by looking at wMaxPacketSize.
  319. */
  320. static int create_uaxx_quirk(struct snd_usb_audio *chip,
  321. struct usb_interface *iface,
  322. struct usb_driver *driver,
  323. const struct snd_usb_audio_quirk *quirk)
  324. {
  325. static const struct audioformat ua_format = {
  326. .formats = SNDRV_PCM_FMTBIT_S24_3LE,
  327. .channels = 2,
  328. .fmt_type = UAC_FORMAT_TYPE_I,
  329. .altsetting = 1,
  330. .altset_idx = 1,
  331. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  332. };
  333. struct usb_host_interface *alts;
  334. struct usb_interface_descriptor *altsd;
  335. struct audioformat *fp;
  336. int stream, err;
  337. /* both PCM and MIDI interfaces have 2 or more altsettings */
  338. if (iface->num_altsetting < 2)
  339. return -ENXIO;
  340. alts = &iface->altsetting[1];
  341. altsd = get_iface_desc(alts);
  342. if (altsd->bNumEndpoints == 2) {
  343. static const struct snd_usb_midi_endpoint_info ua700_ep = {
  344. .out_cables = 0x0003,
  345. .in_cables = 0x0003
  346. };
  347. static const struct snd_usb_audio_quirk ua700_quirk = {
  348. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  349. .data = &ua700_ep
  350. };
  351. static const struct snd_usb_midi_endpoint_info uaxx_ep = {
  352. .out_cables = 0x0001,
  353. .in_cables = 0x0001
  354. };
  355. static const struct snd_usb_audio_quirk uaxx_quirk = {
  356. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  357. .data = &uaxx_ep
  358. };
  359. const struct snd_usb_audio_quirk *quirk =
  360. chip->usb_id == USB_ID(0x0582, 0x002b)
  361. ? &ua700_quirk : &uaxx_quirk;
  362. return snd_usbmidi_create(chip->card, iface,
  363. &chip->midi_list, quirk);
  364. }
  365. if (altsd->bNumEndpoints != 1)
  366. return -ENXIO;
  367. fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
  368. if (!fp)
  369. return -ENOMEM;
  370. fp->iface = altsd->bInterfaceNumber;
  371. fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
  372. fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
  373. fp->datainterval = 0;
  374. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  375. switch (fp->maxpacksize) {
  376. case 0x120:
  377. fp->rate_max = fp->rate_min = 44100;
  378. break;
  379. case 0x138:
  380. case 0x140:
  381. fp->rate_max = fp->rate_min = 48000;
  382. break;
  383. case 0x258:
  384. case 0x260:
  385. fp->rate_max = fp->rate_min = 96000;
  386. break;
  387. default:
  388. snd_printk(KERN_ERR "unknown sample rate\n");
  389. kfree(fp);
  390. return -ENXIO;
  391. }
  392. stream = (fp->endpoint & USB_DIR_IN)
  393. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  394. err = snd_usb_add_audio_stream(chip, stream, fp);
  395. if (err < 0) {
  396. kfree(fp);
  397. return err;
  398. }
  399. usb_set_interface(chip->dev, fp->iface, 0);
  400. return 0;
  401. }
  402. /*
  403. * Create a standard mixer for the specified interface.
  404. */
  405. static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
  406. struct usb_interface *iface,
  407. struct usb_driver *driver,
  408. const struct snd_usb_audio_quirk *quirk)
  409. {
  410. if (quirk->ifnum < 0)
  411. return 0;
  412. return snd_usb_create_mixer(chip, quirk->ifnum, 0);
  413. }
  414. /*
  415. * audio-interface quirks
  416. *
  417. * returns zero if no standard audio/MIDI parsing is needed.
  418. * returns a positive value if standard audio/midi interfaces are parsed
  419. * after this.
  420. * returns a negative value at error.
  421. */
  422. int snd_usb_create_quirk(struct snd_usb_audio *chip,
  423. struct usb_interface *iface,
  424. struct usb_driver *driver,
  425. const struct snd_usb_audio_quirk *quirk)
  426. {
  427. typedef int (*quirk_func_t)(struct snd_usb_audio *,
  428. struct usb_interface *,
  429. struct usb_driver *,
  430. const struct snd_usb_audio_quirk *);
  431. static const quirk_func_t quirk_funcs[] = {
  432. [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
  433. [QUIRK_COMPOSITE] = create_composite_quirk,
  434. [QUIRK_AUTODETECT] = create_autodetect_quirk,
  435. [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
  436. [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
  437. [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
  438. [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
  439. [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
  440. [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
  441. [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
  442. [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
  443. [QUIRK_MIDI_CME] = create_any_midi_quirk,
  444. [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
  445. [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
  446. [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
  447. [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
  448. [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
  449. [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
  450. [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
  451. };
  452. if (quirk->type < QUIRK_TYPE_COUNT) {
  453. return quirk_funcs[quirk->type](chip, iface, driver, quirk);
  454. } else {
  455. snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
  456. return -ENXIO;
  457. }
  458. }
  459. /*
  460. * boot quirks
  461. */
  462. #define EXTIGY_FIRMWARE_SIZE_OLD 794
  463. #define EXTIGY_FIRMWARE_SIZE_NEW 483
  464. static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
  465. {
  466. struct usb_host_config *config = dev->actconfig;
  467. int err;
  468. if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
  469. le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
  470. snd_printdd("sending Extigy boot sequence...\n");
  471. /* Send message to force it to reconnect with full interface. */
  472. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
  473. 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
  474. if (err < 0) snd_printdd("error sending boot message: %d\n", err);
  475. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  476. &dev->descriptor, sizeof(dev->descriptor));
  477. config = dev->actconfig;
  478. if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
  479. err = usb_reset_configuration(dev);
  480. if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
  481. snd_printdd("extigy_boot: new boot length = %d\n",
  482. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  483. return -ENODEV; /* quit this anyway */
  484. }
  485. return 0;
  486. }
  487. static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
  488. {
  489. u8 buf = 1;
  490. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
  491. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  492. 0, 0, &buf, 1);
  493. if (buf == 0) {
  494. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
  495. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  496. 1, 2000, NULL, 0);
  497. return -ENODEV;
  498. }
  499. return 0;
  500. }
  501. static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
  502. {
  503. int err;
  504. if (dev->actconfig->desc.bConfigurationValue == 1) {
  505. snd_printk(KERN_INFO "usb-audio: "
  506. "Fast Track Pro switching to config #2\n");
  507. /* This function has to be available by the usb core module.
  508. * if it is not avialable the boot quirk has to be left out
  509. * and the configuration has to be set by udev or hotplug
  510. * rules
  511. */
  512. err = usb_driver_set_configuration(dev, 2);
  513. if (err < 0)
  514. snd_printdd("error usb_driver_set_configuration: %d\n",
  515. err);
  516. /* Always return an error, so that we stop creating a device
  517. that will just be destroyed and recreated with a new
  518. configuration */
  519. return -ENODEV;
  520. } else
  521. snd_printk(KERN_INFO "usb-audio: Fast Track Pro config OK\n");
  522. return 0;
  523. }
  524. /*
  525. * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
  526. * documented in the device's data sheet.
  527. */
  528. static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
  529. {
  530. u8 buf[4];
  531. buf[0] = 0x20;
  532. buf[1] = value & 0xff;
  533. buf[2] = (value >> 8) & 0xff;
  534. buf[3] = reg;
  535. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
  536. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
  537. 0, 0, &buf, 4);
  538. }
  539. static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
  540. {
  541. /*
  542. * Enable line-out driver mode, set headphone source to front
  543. * channels, enable stereo mic.
  544. */
  545. return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
  546. }
  547. /*
  548. * C-Media CM6206 is based on CM106 with two additional
  549. * registers that are not documented in the data sheet.
  550. * Values here are chosen based on sniffing USB traffic
  551. * under Windows.
  552. */
  553. static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
  554. {
  555. int err = 0, reg;
  556. int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
  557. for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
  558. err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
  559. if (err < 0)
  560. return err;
  561. }
  562. return err;
  563. }
  564. /*
  565. * Novation Twitch DJ controller
  566. */
  567. static int snd_usb_twitch_boot_quirk(struct usb_device *dev)
  568. {
  569. /* preemptively set up the device because otherwise the
  570. * raw MIDI endpoints are not active */
  571. usb_set_interface(dev, 0, 1);
  572. return 0;
  573. }
  574. /*
  575. * This call will put the synth in "USB send" mode, i.e it will send MIDI
  576. * messages through USB (this is disabled at startup). The synth will
  577. * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
  578. * sign on its LCD. Values here are chosen based on sniffing USB traffic
  579. * under Windows.
  580. */
  581. static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
  582. {
  583. int err, actual_length;
  584. /* "midi send" enable */
  585. static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
  586. void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
  587. if (!buf)
  588. return -ENOMEM;
  589. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
  590. ARRAY_SIZE(seq), &actual_length, 1000);
  591. kfree(buf);
  592. if (err < 0)
  593. return err;
  594. return 0;
  595. }
  596. /*
  597. * Some sound cards from Native Instruments are in fact compliant to the USB
  598. * audio standard of version 2 and other approved USB standards, even though
  599. * they come up as vendor-specific device when first connected.
  600. *
  601. * However, they can be told to come up with a new set of descriptors
  602. * upon their next enumeration, and the interfaces announced by the new
  603. * descriptors will then be handled by the kernel's class drivers. As the
  604. * product ID will also change, no further checks are required.
  605. */
  606. static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
  607. {
  608. int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  609. 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  610. 1, 0, NULL, 0, 1000);
  611. if (ret < 0)
  612. return ret;
  613. usb_reset_device(dev);
  614. /* return -EAGAIN, so the creation of an audio interface for this
  615. * temporary device is aborted. The device will reconnect with a
  616. * new product ID */
  617. return -EAGAIN;
  618. }
  619. static void mbox2_setup_48_24_magic(struct usb_device *dev)
  620. {
  621. u8 srate[3];
  622. u8 temp[12];
  623. /* Choose 48000Hz permanently */
  624. srate[0] = 0x80;
  625. srate[1] = 0xbb;
  626. srate[2] = 0x00;
  627. /* Send the magic! */
  628. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  629. 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
  630. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  631. 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
  632. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  633. 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
  634. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  635. 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
  636. return;
  637. }
  638. /* Digidesign Mbox 2 needs to load firmware onboard
  639. * and driver must wait a few seconds for initialisation.
  640. */
  641. #define MBOX2_FIRMWARE_SIZE 646
  642. #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
  643. #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
  644. static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
  645. {
  646. struct usb_host_config *config = dev->actconfig;
  647. int err;
  648. u8 bootresponse[0x12];
  649. int fwsize;
  650. int count;
  651. fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
  652. if (fwsize != MBOX2_FIRMWARE_SIZE) {
  653. snd_printk(KERN_ERR "usb-audio: Invalid firmware size=%d.\n", fwsize);
  654. return -ENODEV;
  655. }
  656. snd_printd("usb-audio: Sending Digidesign Mbox 2 boot sequence...\n");
  657. count = 0;
  658. bootresponse[0] = MBOX2_BOOT_LOADING;
  659. while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
  660. msleep(500); /* 0.5 second delay */
  661. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  662. /* Control magic - load onboard firmware */
  663. 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
  664. if (bootresponse[0] == MBOX2_BOOT_READY)
  665. break;
  666. snd_printd("usb-audio: device not ready, resending boot sequence...\n");
  667. count++;
  668. }
  669. if (bootresponse[0] != MBOX2_BOOT_READY) {
  670. snd_printk(KERN_ERR "usb-audio: Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
  671. return -ENODEV;
  672. }
  673. snd_printdd("usb-audio: device initialised!\n");
  674. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  675. &dev->descriptor, sizeof(dev->descriptor));
  676. config = dev->actconfig;
  677. if (err < 0)
  678. snd_printd("error usb_get_descriptor: %d\n", err);
  679. err = usb_reset_configuration(dev);
  680. if (err < 0)
  681. snd_printd("error usb_reset_configuration: %d\n", err);
  682. snd_printdd("mbox2_boot: new boot length = %d\n",
  683. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  684. mbox2_setup_48_24_magic(dev);
  685. snd_printk(KERN_INFO "usb-audio: Digidesign Mbox 2: 24bit 48kHz");
  686. return 0; /* Successful boot */
  687. }
  688. /*
  689. * Setup quirks
  690. */
  691. #define MAUDIO_SET 0x01 /* parse device_setup */
  692. #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
  693. #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
  694. #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
  695. #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
  696. #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
  697. #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
  698. #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
  699. #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
  700. #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
  701. #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
  702. static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
  703. int iface, int altno)
  704. {
  705. /* Reset ALL ifaces to 0 altsetting.
  706. * Call it for every possible altsetting of every interface.
  707. */
  708. usb_set_interface(chip->dev, iface, 0);
  709. if (chip->setup & MAUDIO_SET) {
  710. if (chip->setup & MAUDIO_SET_COMPATIBLE) {
  711. if (iface != 1 && iface != 2)
  712. return 1; /* skip all interfaces but 1 and 2 */
  713. } else {
  714. unsigned int mask;
  715. if (iface == 1 || iface == 2)
  716. return 1; /* skip interfaces 1 and 2 */
  717. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  718. return 1; /* skip this altsetting */
  719. mask = chip->setup & MAUDIO_SET_MASK;
  720. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  721. return 1; /* skip this altsetting */
  722. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  723. return 1; /* skip this altsetting */
  724. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
  725. return 1; /* skip this altsetting */
  726. }
  727. }
  728. snd_printdd(KERN_INFO
  729. "using altsetting %d for interface %d config %d\n",
  730. altno, iface, chip->setup);
  731. return 0; /* keep this altsetting */
  732. }
  733. static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
  734. int iface,
  735. int altno)
  736. {
  737. /* Reset ALL ifaces to 0 altsetting.
  738. * Call it for every possible altsetting of every interface.
  739. */
  740. usb_set_interface(chip->dev, iface, 0);
  741. if (chip->setup & MAUDIO_SET) {
  742. unsigned int mask;
  743. if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
  744. return 1; /* skip this altsetting */
  745. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  746. return 1; /* skip this altsetting */
  747. mask = chip->setup & MAUDIO_SET_MASK;
  748. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  749. return 1; /* skip this altsetting */
  750. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  751. return 1; /* skip this altsetting */
  752. if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
  753. return 1; /* skip this altsetting */
  754. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
  755. return 1; /* skip this altsetting */
  756. }
  757. return 0; /* keep this altsetting */
  758. }
  759. static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
  760. int iface, int altno)
  761. {
  762. /* Reset ALL ifaces to 0 altsetting.
  763. * Call it for every possible altsetting of every interface.
  764. */
  765. usb_set_interface(chip->dev, iface, 0);
  766. /* possible configuration where both inputs and only one output is
  767. *used is not supported by the current setup
  768. */
  769. if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
  770. if (chip->setup & MAUDIO_SET_96K) {
  771. if (altno != 3 && altno != 6)
  772. return 1;
  773. } else if (chip->setup & MAUDIO_SET_DI) {
  774. if (iface == 4)
  775. return 1; /* no analog input */
  776. if (altno != 2 && altno != 5)
  777. return 1; /* enable only altsets 2 and 5 */
  778. } else {
  779. if (iface == 5)
  780. return 1; /* disable digialt input */
  781. if (altno != 2 && altno != 5)
  782. return 1; /* enalbe only altsets 2 and 5 */
  783. }
  784. } else {
  785. /* keep only 16-Bit mode */
  786. if (altno != 1)
  787. return 1;
  788. }
  789. snd_printdd(KERN_INFO
  790. "using altsetting %d for interface %d config %d\n",
  791. altno, iface, chip->setup);
  792. return 0; /* keep this altsetting */
  793. }
  794. int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
  795. int iface,
  796. int altno)
  797. {
  798. /* audiophile usb: skip altsets incompatible with device_setup */
  799. if (chip->usb_id == USB_ID(0x0763, 0x2003))
  800. return audiophile_skip_setting_quirk(chip, iface, altno);
  801. /* quattro usb: skip altsets incompatible with device_setup */
  802. if (chip->usb_id == USB_ID(0x0763, 0x2001))
  803. return quattro_skip_setting_quirk(chip, iface, altno);
  804. /* fasttrackpro usb: skip altsets incompatible with device_setup */
  805. if (chip->usb_id == USB_ID(0x0763, 0x2012))
  806. return fasttrackpro_skip_setting_quirk(chip, iface, altno);
  807. return 0;
  808. }
  809. int snd_usb_apply_boot_quirk(struct usb_device *dev,
  810. struct usb_interface *intf,
  811. const struct snd_usb_audio_quirk *quirk)
  812. {
  813. u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
  814. le16_to_cpu(dev->descriptor.idProduct));
  815. switch (id) {
  816. case USB_ID(0x041e, 0x3000):
  817. /* SB Extigy needs special boot-up sequence */
  818. /* if more models come, this will go to the quirk list. */
  819. return snd_usb_extigy_boot_quirk(dev, intf);
  820. case USB_ID(0x041e, 0x3020):
  821. /* SB Audigy 2 NX needs its own boot-up magic, too */
  822. return snd_usb_audigy2nx_boot_quirk(dev);
  823. case USB_ID(0x10f5, 0x0200):
  824. /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
  825. return snd_usb_cm106_boot_quirk(dev);
  826. case USB_ID(0x0d8c, 0x0102):
  827. /* C-Media CM6206 / CM106-Like Sound Device */
  828. case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
  829. return snd_usb_cm6206_boot_quirk(dev);
  830. case USB_ID(0x0dba, 0x3000):
  831. /* Digidesign Mbox 2 */
  832. return snd_usb_mbox2_boot_quirk(dev);
  833. case USB_ID(0x1235, 0x0018):
  834. /* Focusrite Novation Twitch */
  835. return snd_usb_twitch_boot_quirk(dev);
  836. case USB_ID(0x133e, 0x0815):
  837. /* Access Music VirusTI Desktop */
  838. return snd_usb_accessmusic_boot_quirk(dev);
  839. case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
  840. case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
  841. case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
  842. return snd_usb_nativeinstruments_boot_quirk(dev);
  843. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
  844. return snd_usb_fasttrackpro_boot_quirk(dev);
  845. }
  846. return 0;
  847. }
  848. /*
  849. * check if the device uses big-endian samples
  850. */
  851. int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
  852. {
  853. /* it depends on altsetting whether the device is big-endian or not */
  854. switch (chip->usb_id) {
  855. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
  856. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  857. fp->altsetting == 5 || fp->altsetting == 6)
  858. return 1;
  859. break;
  860. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  861. if (chip->setup == 0x00 ||
  862. fp->altsetting == 1 || fp->altsetting == 2 ||
  863. fp->altsetting == 3)
  864. return 1;
  865. break;
  866. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
  867. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  868. fp->altsetting == 5 || fp->altsetting == 6)
  869. return 1;
  870. break;
  871. }
  872. return 0;
  873. }
  874. /*
  875. * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
  876. * not for interface.
  877. */
  878. enum {
  879. EMU_QUIRK_SR_44100HZ = 0,
  880. EMU_QUIRK_SR_48000HZ,
  881. EMU_QUIRK_SR_88200HZ,
  882. EMU_QUIRK_SR_96000HZ,
  883. EMU_QUIRK_SR_176400HZ,
  884. EMU_QUIRK_SR_192000HZ
  885. };
  886. static void set_format_emu_quirk(struct snd_usb_substream *subs,
  887. struct audioformat *fmt)
  888. {
  889. unsigned char emu_samplerate_id = 0;
  890. /* When capture is active
  891. * sample rate shouldn't be changed
  892. * by playback substream
  893. */
  894. if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
  895. if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
  896. return;
  897. }
  898. switch (fmt->rate_min) {
  899. case 48000:
  900. emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
  901. break;
  902. case 88200:
  903. emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
  904. break;
  905. case 96000:
  906. emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
  907. break;
  908. case 176400:
  909. emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
  910. break;
  911. case 192000:
  912. emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
  913. break;
  914. default:
  915. emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
  916. break;
  917. }
  918. snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
  919. subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
  920. }
  921. void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
  922. struct audioformat *fmt)
  923. {
  924. switch (subs->stream->chip->usb_id) {
  925. case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
  926. case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
  927. case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
  928. case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
  929. set_format_emu_quirk(subs, fmt);
  930. break;
  931. }
  932. }
  933. void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
  934. {
  935. /*
  936. * "Playback Design" products send bogus feedback data at the start
  937. * of the stream. Ignore them.
  938. */
  939. if ((le16_to_cpu(ep->chip->dev->descriptor.idVendor) == 0x23ba) &&
  940. ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
  941. ep->skip_packets = 4;
  942. /*
  943. * M-Audio Fast Track C400/C600 - when packets are not skipped, real
  944. * world latency varies by approx. +/- 50 frames (at 96KHz) each time
  945. * the stream is (re)started. When skipping packets 16 at endpoint
  946. * start up, the real world latency is stable within +/- 1 frame (also
  947. * across power cycles).
  948. */
  949. if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
  950. ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
  951. ep->type == SND_USB_ENDPOINT_TYPE_DATA)
  952. ep->skip_packets = 16;
  953. }
  954. void snd_usb_set_interface_quirk(struct usb_device *dev)
  955. {
  956. /*
  957. * "Playback Design" products need a 50ms delay after setting the
  958. * USB interface.
  959. */
  960. if (le16_to_cpu(dev->descriptor.idVendor) == 0x23ba)
  961. mdelay(50);
  962. }
  963. void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
  964. __u8 request, __u8 requesttype, __u16 value,
  965. __u16 index, void *data, __u16 size)
  966. {
  967. /*
  968. * "Playback Design" products need a 20ms delay after each
  969. * class compliant request
  970. */
  971. if ((le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) &&
  972. (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
  973. mdelay(20);
  974. }
  975. /*
  976. * snd_usb_interface_dsd_format_quirks() is called from format.c to
  977. * augment the PCM format bit-field for DSD types. The UAC standards
  978. * don't have a designated bit field to denote DSD-capable interfaces,
  979. * hence all hardware that is known to support this format has to be
  980. * listed here.
  981. */
  982. u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
  983. struct audioformat *fp,
  984. unsigned int sample_bytes)
  985. {
  986. /* Playback Designs */
  987. if (le16_to_cpu(chip->dev->descriptor.idVendor) == 0x23ba) {
  988. switch (fp->altsetting) {
  989. case 1:
  990. fp->dsd_dop = true;
  991. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  992. case 2:
  993. fp->dsd_bitrev = true;
  994. return SNDRV_PCM_FMTBIT_DSD_U8;
  995. case 3:
  996. fp->dsd_bitrev = true;
  997. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  998. }
  999. }
  1000. return 0;
  1001. }