quirks.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. */
  4. #include <linux/init.h>
  5. #include <linux/slab.h>
  6. #include <linux/usb.h>
  7. #include <linux/usb/audio.h>
  8. #include <linux/usb/midi.h>
  9. #include <linux/bits.h>
  10. #include <sound/control.h>
  11. #include <sound/core.h>
  12. #include <sound/info.h>
  13. #include <sound/pcm.h>
  14. #include "usbaudio.h"
  15. #include "card.h"
  16. #include "mixer.h"
  17. #include "mixer_quirks.h"
  18. #include "midi.h"
  19. #include "midi2.h"
  20. #include "quirks.h"
  21. #include "helper.h"
  22. #include "endpoint.h"
  23. #include "pcm.h"
  24. #include "clock.h"
  25. #include "stream.h"
  26. /*
  27. * handle the quirks for the contained interfaces
  28. */
  29. static int create_composite_quirk(struct snd_usb_audio *chip,
  30. struct usb_interface *iface,
  31. struct usb_driver *driver,
  32. const struct snd_usb_audio_quirk *quirk_comp)
  33. {
  34. int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
  35. const struct snd_usb_audio_quirk *quirk;
  36. int err;
  37. for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
  38. iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
  39. if (!iface)
  40. continue;
  41. if (quirk->ifnum != probed_ifnum &&
  42. usb_interface_claimed(iface))
  43. continue;
  44. err = snd_usb_create_quirk(chip, iface, driver, quirk);
  45. if (err < 0)
  46. return err;
  47. }
  48. for (quirk = quirk_comp->data; quirk->ifnum >= 0; ++quirk) {
  49. iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
  50. if (!iface)
  51. continue;
  52. if (quirk->ifnum != probed_ifnum &&
  53. !usb_interface_claimed(iface)) {
  54. err = usb_driver_claim_interface(driver, iface,
  55. USB_AUDIO_IFACE_UNUSED);
  56. if (err < 0)
  57. return err;
  58. }
  59. }
  60. return 0;
  61. }
  62. static int ignore_interface_quirk(struct snd_usb_audio *chip,
  63. struct usb_interface *iface,
  64. struct usb_driver *driver,
  65. const struct snd_usb_audio_quirk *quirk)
  66. {
  67. return 0;
  68. }
  69. static int create_any_midi_quirk(struct snd_usb_audio *chip,
  70. struct usb_interface *intf,
  71. struct usb_driver *driver,
  72. const struct snd_usb_audio_quirk *quirk)
  73. {
  74. return snd_usb_midi_v2_create(chip, intf, quirk, 0);
  75. }
  76. /*
  77. * create a stream for an interface with proper descriptors
  78. */
  79. static int create_standard_audio_quirk(struct snd_usb_audio *chip,
  80. struct usb_interface *iface,
  81. struct usb_driver *driver,
  82. const struct snd_usb_audio_quirk *quirk)
  83. {
  84. struct usb_host_interface *alts;
  85. struct usb_interface_descriptor *altsd;
  86. int err;
  87. alts = &iface->altsetting[0];
  88. altsd = get_iface_desc(alts);
  89. err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
  90. if (err < 0) {
  91. usb_audio_err(chip, "cannot setup if %d: error %d\n",
  92. altsd->bInterfaceNumber, err);
  93. return err;
  94. }
  95. /* reset the current interface */
  96. usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
  97. return 0;
  98. }
  99. /* create the audio stream and the corresponding endpoints from the fixed
  100. * audioformat object; this is used for quirks with the fixed EPs
  101. */
  102. static int add_audio_stream_from_fixed_fmt(struct snd_usb_audio *chip,
  103. struct audioformat *fp)
  104. {
  105. int stream, err;
  106. stream = (fp->endpoint & USB_DIR_IN) ?
  107. SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  108. snd_usb_audioformat_set_sync_ep(chip, fp);
  109. err = snd_usb_add_audio_stream(chip, stream, fp);
  110. if (err < 0)
  111. return err;
  112. err = snd_usb_add_endpoint(chip, fp->endpoint,
  113. SND_USB_ENDPOINT_TYPE_DATA);
  114. if (err < 0)
  115. return err;
  116. if (fp->sync_ep) {
  117. err = snd_usb_add_endpoint(chip, fp->sync_ep,
  118. fp->implicit_fb ?
  119. SND_USB_ENDPOINT_TYPE_DATA :
  120. SND_USB_ENDPOINT_TYPE_SYNC);
  121. if (err < 0)
  122. return err;
  123. }
  124. return 0;
  125. }
  126. /*
  127. * create a stream for an endpoint/altsetting without proper descriptors
  128. */
  129. static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
  130. struct usb_interface *iface,
  131. struct usb_driver *driver,
  132. const struct snd_usb_audio_quirk *quirk)
  133. {
  134. struct audioformat *fp;
  135. struct usb_host_interface *alts;
  136. struct usb_interface_descriptor *altsd;
  137. unsigned *rate_table = NULL;
  138. int err;
  139. fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
  140. if (!fp)
  141. return -ENOMEM;
  142. INIT_LIST_HEAD(&fp->list);
  143. if (fp->nr_rates > MAX_NR_RATES) {
  144. kfree(fp);
  145. return -EINVAL;
  146. }
  147. if (fp->nr_rates > 0) {
  148. rate_table = kmemdup_array(fp->rate_table, fp->nr_rates, sizeof(int),
  149. GFP_KERNEL);
  150. if (!rate_table) {
  151. kfree(fp);
  152. return -ENOMEM;
  153. }
  154. fp->rate_table = rate_table;
  155. }
  156. if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
  157. fp->altset_idx >= iface->num_altsetting) {
  158. err = -EINVAL;
  159. goto error;
  160. }
  161. alts = &iface->altsetting[fp->altset_idx];
  162. altsd = get_iface_desc(alts);
  163. if (altsd->bNumEndpoints <= fp->ep_idx) {
  164. err = -EINVAL;
  165. goto error;
  166. }
  167. fp->protocol = altsd->bInterfaceProtocol;
  168. if (fp->datainterval == 0)
  169. fp->datainterval = snd_usb_parse_datainterval(chip, alts);
  170. if (fp->maxpacksize == 0)
  171. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, fp->ep_idx)->wMaxPacketSize);
  172. if (!fp->fmt_type)
  173. fp->fmt_type = UAC_FORMAT_TYPE_I;
  174. err = add_audio_stream_from_fixed_fmt(chip, fp);
  175. if (err < 0)
  176. goto error;
  177. usb_set_interface(chip->dev, fp->iface, 0);
  178. snd_usb_init_pitch(chip, fp);
  179. snd_usb_init_sample_rate(chip, fp, fp->rate_max);
  180. return 0;
  181. error:
  182. list_del(&fp->list); /* unlink for avoiding double-free */
  183. kfree(fp);
  184. kfree(rate_table);
  185. return err;
  186. }
  187. static int create_auto_pcm_quirk(struct snd_usb_audio *chip,
  188. struct usb_interface *iface,
  189. struct usb_driver *driver)
  190. {
  191. struct usb_host_interface *alts;
  192. struct usb_interface_descriptor *altsd;
  193. struct usb_endpoint_descriptor *epd;
  194. struct uac1_as_header_descriptor *ashd;
  195. struct uac_format_type_i_discrete_descriptor *fmtd;
  196. /*
  197. * Most Roland/Yamaha audio streaming interfaces have more or less
  198. * standard descriptors, but older devices might lack descriptors, and
  199. * future ones might change, so ensure that we fail silently if the
  200. * interface doesn't look exactly right.
  201. */
  202. /* must have a non-zero altsetting for streaming */
  203. if (iface->num_altsetting < 2)
  204. return -ENODEV;
  205. alts = &iface->altsetting[1];
  206. altsd = get_iface_desc(alts);
  207. /* must have an isochronous endpoint for streaming */
  208. if (altsd->bNumEndpoints < 1)
  209. return -ENODEV;
  210. epd = get_endpoint(alts, 0);
  211. if (!usb_endpoint_xfer_isoc(epd))
  212. return -ENODEV;
  213. /* must have format descriptors */
  214. ashd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
  215. UAC_AS_GENERAL);
  216. fmtd = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL,
  217. UAC_FORMAT_TYPE);
  218. if (!ashd || ashd->bLength < 7 ||
  219. !fmtd || fmtd->bLength < 8)
  220. return -ENODEV;
  221. return create_standard_audio_quirk(chip, iface, driver, NULL);
  222. }
  223. static int create_yamaha_midi_quirk(struct snd_usb_audio *chip,
  224. struct usb_interface *iface,
  225. struct usb_driver *driver,
  226. struct usb_host_interface *alts)
  227. {
  228. static const struct snd_usb_audio_quirk yamaha_midi_quirk = {
  229. .type = QUIRK_MIDI_YAMAHA
  230. };
  231. struct usb_midi_in_jack_descriptor *injd;
  232. struct usb_midi_out_jack_descriptor *outjd;
  233. /* must have some valid jack descriptors */
  234. injd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
  235. NULL, USB_MS_MIDI_IN_JACK);
  236. outjd = snd_usb_find_csint_desc(alts->extra, alts->extralen,
  237. NULL, USB_MS_MIDI_OUT_JACK);
  238. if (!injd && !outjd)
  239. return -ENODEV;
  240. if ((injd && !snd_usb_validate_midi_desc(injd)) ||
  241. (outjd && !snd_usb_validate_midi_desc(outjd)))
  242. return -ENODEV;
  243. if (injd && (injd->bLength < 5 ||
  244. (injd->bJackType != USB_MS_EMBEDDED &&
  245. injd->bJackType != USB_MS_EXTERNAL)))
  246. return -ENODEV;
  247. if (outjd && (outjd->bLength < 6 ||
  248. (outjd->bJackType != USB_MS_EMBEDDED &&
  249. outjd->bJackType != USB_MS_EXTERNAL)))
  250. return -ENODEV;
  251. return create_any_midi_quirk(chip, iface, driver, &yamaha_midi_quirk);
  252. }
  253. static int create_roland_midi_quirk(struct snd_usb_audio *chip,
  254. struct usb_interface *iface,
  255. struct usb_driver *driver,
  256. struct usb_host_interface *alts)
  257. {
  258. static const struct snd_usb_audio_quirk roland_midi_quirk = {
  259. .type = QUIRK_MIDI_ROLAND
  260. };
  261. u8 *roland_desc = NULL;
  262. /* might have a vendor-specific descriptor <06 24 F1 02 ...> */
  263. for (;;) {
  264. roland_desc = snd_usb_find_csint_desc(alts->extra,
  265. alts->extralen,
  266. roland_desc, 0xf1);
  267. if (!roland_desc)
  268. return -ENODEV;
  269. if (roland_desc[0] < 6 || roland_desc[3] != 2)
  270. continue;
  271. return create_any_midi_quirk(chip, iface, driver,
  272. &roland_midi_quirk);
  273. }
  274. }
  275. static int create_std_midi_quirk(struct snd_usb_audio *chip,
  276. struct usb_interface *iface,
  277. struct usb_driver *driver,
  278. struct usb_host_interface *alts)
  279. {
  280. struct usb_ms_header_descriptor *mshd;
  281. struct usb_ms_endpoint_descriptor *msepd;
  282. /* must have the MIDIStreaming interface header descriptor*/
  283. mshd = (struct usb_ms_header_descriptor *)alts->extra;
  284. if (alts->extralen < 7 ||
  285. mshd->bLength < 7 ||
  286. mshd->bDescriptorType != USB_DT_CS_INTERFACE ||
  287. mshd->bDescriptorSubtype != USB_MS_HEADER)
  288. return -ENODEV;
  289. /* must have the MIDIStreaming endpoint descriptor*/
  290. msepd = (struct usb_ms_endpoint_descriptor *)alts->endpoint[0].extra;
  291. if (alts->endpoint[0].extralen < 4 ||
  292. msepd->bLength < 4 ||
  293. msepd->bDescriptorType != USB_DT_CS_ENDPOINT ||
  294. msepd->bDescriptorSubtype != UAC_MS_GENERAL ||
  295. msepd->bNumEmbMIDIJack < 1 ||
  296. msepd->bNumEmbMIDIJack > 16)
  297. return -ENODEV;
  298. return create_any_midi_quirk(chip, iface, driver, NULL);
  299. }
  300. static int create_auto_midi_quirk(struct snd_usb_audio *chip,
  301. struct usb_interface *iface,
  302. struct usb_driver *driver)
  303. {
  304. struct usb_host_interface *alts;
  305. struct usb_interface_descriptor *altsd;
  306. struct usb_endpoint_descriptor *epd;
  307. int err;
  308. alts = &iface->altsetting[0];
  309. altsd = get_iface_desc(alts);
  310. /* must have at least one bulk/interrupt endpoint for streaming */
  311. if (altsd->bNumEndpoints < 1)
  312. return -ENODEV;
  313. epd = get_endpoint(alts, 0);
  314. if (!usb_endpoint_xfer_bulk(epd) &&
  315. !usb_endpoint_xfer_int(epd))
  316. return -ENODEV;
  317. switch (USB_ID_VENDOR(chip->usb_id)) {
  318. case 0x0499: /* Yamaha */
  319. err = create_yamaha_midi_quirk(chip, iface, driver, alts);
  320. if (err != -ENODEV)
  321. return err;
  322. break;
  323. case 0x0582: /* Roland */
  324. err = create_roland_midi_quirk(chip, iface, driver, alts);
  325. if (err != -ENODEV)
  326. return err;
  327. break;
  328. }
  329. return create_std_midi_quirk(chip, iface, driver, alts);
  330. }
  331. static int create_autodetect_quirk(struct snd_usb_audio *chip,
  332. struct usb_interface *iface,
  333. struct usb_driver *driver,
  334. const struct snd_usb_audio_quirk *quirk)
  335. {
  336. int err;
  337. err = create_auto_pcm_quirk(chip, iface, driver);
  338. if (err == -ENODEV)
  339. err = create_auto_midi_quirk(chip, iface, driver);
  340. return err;
  341. }
  342. /*
  343. * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
  344. * The only way to detect the sample rate is by looking at wMaxPacketSize.
  345. */
  346. static int create_uaxx_quirk(struct snd_usb_audio *chip,
  347. struct usb_interface *iface,
  348. struct usb_driver *driver,
  349. const struct snd_usb_audio_quirk *quirk)
  350. {
  351. static const struct audioformat ua_format = {
  352. .formats = SNDRV_PCM_FMTBIT_S24_3LE,
  353. .channels = 2,
  354. .fmt_type = UAC_FORMAT_TYPE_I,
  355. .altsetting = 1,
  356. .altset_idx = 1,
  357. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  358. };
  359. struct usb_host_interface *alts;
  360. struct usb_interface_descriptor *altsd;
  361. struct audioformat *fp;
  362. int err;
  363. /* both PCM and MIDI interfaces have 2 or more altsettings */
  364. if (iface->num_altsetting < 2)
  365. return -ENXIO;
  366. alts = &iface->altsetting[1];
  367. altsd = get_iface_desc(alts);
  368. if (altsd->bNumEndpoints == 2) {
  369. static const struct snd_usb_midi_endpoint_info ua700_ep = {
  370. .out_cables = 0x0003,
  371. .in_cables = 0x0003
  372. };
  373. static const struct snd_usb_audio_quirk ua700_quirk = {
  374. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  375. .data = &ua700_ep
  376. };
  377. static const struct snd_usb_midi_endpoint_info uaxx_ep = {
  378. .out_cables = 0x0001,
  379. .in_cables = 0x0001
  380. };
  381. static const struct snd_usb_audio_quirk uaxx_quirk = {
  382. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  383. .data = &uaxx_ep
  384. };
  385. const struct snd_usb_audio_quirk *quirk =
  386. chip->usb_id == USB_ID(0x0582, 0x002b)
  387. ? &ua700_quirk : &uaxx_quirk;
  388. return __snd_usbmidi_create(chip->card, iface,
  389. &chip->midi_list, quirk,
  390. chip->usb_id,
  391. &chip->num_rawmidis);
  392. }
  393. if (altsd->bNumEndpoints != 1)
  394. return -ENXIO;
  395. fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
  396. if (!fp)
  397. return -ENOMEM;
  398. fp->iface = altsd->bInterfaceNumber;
  399. fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
  400. fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
  401. fp->datainterval = 0;
  402. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  403. INIT_LIST_HEAD(&fp->list);
  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. usb_audio_err(chip, "unknown sample rate\n");
  418. kfree(fp);
  419. return -ENXIO;
  420. }
  421. err = add_audio_stream_from_fixed_fmt(chip, fp);
  422. if (err < 0) {
  423. list_del(&fp->list); /* unlink for avoiding double-free */
  424. kfree(fp);
  425. return err;
  426. }
  427. usb_set_interface(chip->dev, fp->iface, 0);
  428. return 0;
  429. }
  430. /*
  431. * Create a standard mixer for the specified interface.
  432. */
  433. static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
  434. struct usb_interface *iface,
  435. struct usb_driver *driver,
  436. const struct snd_usb_audio_quirk *quirk)
  437. {
  438. if (quirk->ifnum < 0)
  439. return 0;
  440. return snd_usb_create_mixer(chip, quirk->ifnum);
  441. }
  442. /*
  443. * audio-interface quirks
  444. *
  445. * returns zero if no standard audio/MIDI parsing is needed.
  446. * returns a positive value if standard audio/midi interfaces are parsed
  447. * after this.
  448. * returns a negative value at error.
  449. */
  450. int snd_usb_create_quirk(struct snd_usb_audio *chip,
  451. struct usb_interface *iface,
  452. struct usb_driver *driver,
  453. const struct snd_usb_audio_quirk *quirk)
  454. {
  455. typedef int (*quirk_func_t)(struct snd_usb_audio *,
  456. struct usb_interface *,
  457. struct usb_driver *,
  458. const struct snd_usb_audio_quirk *);
  459. static const quirk_func_t quirk_funcs[] = {
  460. [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
  461. [QUIRK_COMPOSITE] = create_composite_quirk,
  462. [QUIRK_AUTODETECT] = create_autodetect_quirk,
  463. [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
  464. [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
  465. [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
  466. [QUIRK_MIDI_ROLAND] = create_any_midi_quirk,
  467. [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
  468. [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
  469. [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
  470. [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
  471. [QUIRK_MIDI_CME] = create_any_midi_quirk,
  472. [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
  473. [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
  474. [QUIRK_MIDI_CH345] = 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_STANDARD_MIXER] = create_standard_mixer_quirk,
  479. };
  480. if (quirk->type < QUIRK_TYPE_COUNT) {
  481. return quirk_funcs[quirk->type](chip, iface, driver, quirk);
  482. } else {
  483. usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
  484. return -ENXIO;
  485. }
  486. }
  487. /*
  488. * boot quirks
  489. */
  490. #define EXTIGY_FIRMWARE_SIZE_OLD 794
  491. #define EXTIGY_FIRMWARE_SIZE_NEW 483
  492. static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
  493. {
  494. struct usb_host_config *config = dev->actconfig;
  495. struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;
  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. dev_dbg(&dev->dev, "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)
  504. dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
  505. new_device_descriptor = kmalloc(sizeof(*new_device_descriptor), GFP_KERNEL);
  506. if (!new_device_descriptor)
  507. return -ENOMEM;
  508. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  509. new_device_descriptor, sizeof(*new_device_descriptor));
  510. if (err < 0)
  511. dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
  512. if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
  513. dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
  514. new_device_descriptor->bNumConfigurations);
  515. else
  516. memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
  517. err = usb_reset_configuration(dev);
  518. if (err < 0)
  519. dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
  520. dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
  521. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  522. return -ENODEV; /* quit this anyway */
  523. }
  524. return 0;
  525. }
  526. static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
  527. {
  528. u8 buf = 1;
  529. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
  530. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  531. 0, 0, &buf, 1);
  532. if (buf == 0) {
  533. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
  534. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  535. 1, 2000, NULL, 0);
  536. return -ENODEV;
  537. }
  538. return 0;
  539. }
  540. static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
  541. {
  542. int err;
  543. if (dev->actconfig->desc.bConfigurationValue == 1) {
  544. dev_info(&dev->dev,
  545. "Fast Track Pro switching to config #2\n");
  546. /* This function has to be available by the usb core module.
  547. * if it is not avialable the boot quirk has to be left out
  548. * and the configuration has to be set by udev or hotplug
  549. * rules
  550. */
  551. err = usb_driver_set_configuration(dev, 2);
  552. if (err < 0)
  553. dev_dbg(&dev->dev,
  554. "error usb_driver_set_configuration: %d\n",
  555. err);
  556. /* Always return an error, so that we stop creating a device
  557. that will just be destroyed and recreated with a new
  558. configuration */
  559. return -ENODEV;
  560. } else
  561. dev_info(&dev->dev, "Fast Track Pro config OK\n");
  562. return 0;
  563. }
  564. /*
  565. * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
  566. * documented in the device's data sheet.
  567. */
  568. static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
  569. {
  570. u8 buf[4];
  571. buf[0] = 0x20;
  572. buf[1] = value & 0xff;
  573. buf[2] = (value >> 8) & 0xff;
  574. buf[3] = reg;
  575. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
  576. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
  577. 0, 0, &buf, 4);
  578. }
  579. static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
  580. {
  581. /*
  582. * Enable line-out driver mode, set headphone source to front
  583. * channels, enable stereo mic.
  584. */
  585. return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
  586. }
  587. /*
  588. * CM6206 registers from the CM6206 datasheet rev 2.1
  589. */
  590. #define CM6206_REG0_DMA_MASTER BIT(15)
  591. #define CM6206_REG0_SPDIFO_RATE_48K (2 << 12)
  592. #define CM6206_REG0_SPDIFO_RATE_96K (7 << 12)
  593. /* Bit 4 thru 11 is the S/PDIF category code */
  594. #define CM6206_REG0_SPDIFO_CAT_CODE_GENERAL (0 << 4)
  595. #define CM6206_REG0_SPDIFO_EMPHASIS_CD BIT(3)
  596. #define CM6206_REG0_SPDIFO_COPYRIGHT_NA BIT(2)
  597. #define CM6206_REG0_SPDIFO_NON_AUDIO BIT(1)
  598. #define CM6206_REG0_SPDIFO_PRO_FORMAT BIT(0)
  599. #define CM6206_REG1_TEST_SEL_CLK BIT(14)
  600. #define CM6206_REG1_PLLBIN_EN BIT(13)
  601. #define CM6206_REG1_SOFT_MUTE_EN BIT(12)
  602. #define CM6206_REG1_GPIO4_OUT BIT(11)
  603. #define CM6206_REG1_GPIO4_OE BIT(10)
  604. #define CM6206_REG1_GPIO3_OUT BIT(9)
  605. #define CM6206_REG1_GPIO3_OE BIT(8)
  606. #define CM6206_REG1_GPIO2_OUT BIT(7)
  607. #define CM6206_REG1_GPIO2_OE BIT(6)
  608. #define CM6206_REG1_GPIO1_OUT BIT(5)
  609. #define CM6206_REG1_GPIO1_OE BIT(4)
  610. #define CM6206_REG1_SPDIFO_INVALID BIT(3)
  611. #define CM6206_REG1_SPDIF_LOOP_EN BIT(2)
  612. #define CM6206_REG1_SPDIFO_DIS BIT(1)
  613. #define CM6206_REG1_SPDIFI_MIX BIT(0)
  614. #define CM6206_REG2_DRIVER_ON BIT(15)
  615. #define CM6206_REG2_HEADP_SEL_SIDE_CHANNELS (0 << 13)
  616. #define CM6206_REG2_HEADP_SEL_SURROUND_CHANNELS (1 << 13)
  617. #define CM6206_REG2_HEADP_SEL_CENTER_SUBW (2 << 13)
  618. #define CM6206_REG2_HEADP_SEL_FRONT_CHANNELS (3 << 13)
  619. #define CM6206_REG2_MUTE_HEADPHONE_RIGHT BIT(12)
  620. #define CM6206_REG2_MUTE_HEADPHONE_LEFT BIT(11)
  621. #define CM6206_REG2_MUTE_REAR_SURROUND_RIGHT BIT(10)
  622. #define CM6206_REG2_MUTE_REAR_SURROUND_LEFT BIT(9)
  623. #define CM6206_REG2_MUTE_SIDE_SURROUND_RIGHT BIT(8)
  624. #define CM6206_REG2_MUTE_SIDE_SURROUND_LEFT BIT(7)
  625. #define CM6206_REG2_MUTE_SUBWOOFER BIT(6)
  626. #define CM6206_REG2_MUTE_CENTER BIT(5)
  627. #define CM6206_REG2_MUTE_RIGHT_FRONT BIT(3)
  628. #define CM6206_REG2_MUTE_LEFT_FRONT BIT(3)
  629. #define CM6206_REG2_EN_BTL BIT(2)
  630. #define CM6206_REG2_MCUCLKSEL_1_5_MHZ (0)
  631. #define CM6206_REG2_MCUCLKSEL_3_MHZ (1)
  632. #define CM6206_REG2_MCUCLKSEL_6_MHZ (2)
  633. #define CM6206_REG2_MCUCLKSEL_12_MHZ (3)
  634. /* Bit 11..13 sets the sensitivity to FLY tuner volume control VP/VD signal */
  635. #define CM6206_REG3_FLYSPEED_DEFAULT (2 << 11)
  636. #define CM6206_REG3_VRAP25EN BIT(10)
  637. #define CM6206_REG3_MSEL1 BIT(9)
  638. #define CM6206_REG3_SPDIFI_RATE_44_1K BIT(0 << 7)
  639. #define CM6206_REG3_SPDIFI_RATE_48K BIT(2 << 7)
  640. #define CM6206_REG3_SPDIFI_RATE_32K BIT(3 << 7)
  641. #define CM6206_REG3_PINSEL BIT(6)
  642. #define CM6206_REG3_FOE BIT(5)
  643. #define CM6206_REG3_ROE BIT(4)
  644. #define CM6206_REG3_CBOE BIT(3)
  645. #define CM6206_REG3_LOSE BIT(2)
  646. #define CM6206_REG3_HPOE BIT(1)
  647. #define CM6206_REG3_SPDIFI_CANREC BIT(0)
  648. #define CM6206_REG5_DA_RSTN BIT(13)
  649. #define CM6206_REG5_AD_RSTN BIT(12)
  650. #define CM6206_REG5_SPDIFO_AD2SPDO BIT(12)
  651. #define CM6206_REG5_SPDIFO_SEL_FRONT (0 << 9)
  652. #define CM6206_REG5_SPDIFO_SEL_SIDE_SUR (1 << 9)
  653. #define CM6206_REG5_SPDIFO_SEL_CEN_LFE (2 << 9)
  654. #define CM6206_REG5_SPDIFO_SEL_REAR_SUR (3 << 9)
  655. #define CM6206_REG5_CODECM BIT(8)
  656. #define CM6206_REG5_EN_HPF BIT(7)
  657. #define CM6206_REG5_T_SEL_DSDA4 BIT(6)
  658. #define CM6206_REG5_T_SEL_DSDA3 BIT(5)
  659. #define CM6206_REG5_T_SEL_DSDA2 BIT(4)
  660. #define CM6206_REG5_T_SEL_DSDA1 BIT(3)
  661. #define CM6206_REG5_T_SEL_DSDAD_NORMAL 0
  662. #define CM6206_REG5_T_SEL_DSDAD_FRONT 4
  663. #define CM6206_REG5_T_SEL_DSDAD_S_SURROUND 5
  664. #define CM6206_REG5_T_SEL_DSDAD_CEN_LFE 6
  665. #define CM6206_REG5_T_SEL_DSDAD_R_SURROUND 7
  666. static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
  667. {
  668. int err = 0, reg;
  669. int val[] = {
  670. /*
  671. * Values here are chosen based on sniffing USB traffic
  672. * under Windows.
  673. *
  674. * REG0: DAC is master, sample rate 48kHz, no copyright
  675. */
  676. CM6206_REG0_SPDIFO_RATE_48K |
  677. CM6206_REG0_SPDIFO_COPYRIGHT_NA,
  678. /*
  679. * REG1: PLL binary search enable, soft mute enable.
  680. */
  681. CM6206_REG1_PLLBIN_EN |
  682. CM6206_REG1_SOFT_MUTE_EN,
  683. /*
  684. * REG2: enable output drivers,
  685. * select front channels to the headphone output,
  686. * then mute the headphone channels, run the MCU
  687. * at 1.5 MHz.
  688. */
  689. CM6206_REG2_DRIVER_ON |
  690. CM6206_REG2_HEADP_SEL_FRONT_CHANNELS |
  691. CM6206_REG2_MUTE_HEADPHONE_RIGHT |
  692. CM6206_REG2_MUTE_HEADPHONE_LEFT,
  693. /*
  694. * REG3: default flyspeed, set 2.5V mic bias
  695. * enable all line out ports and enable SPDIF
  696. */
  697. CM6206_REG3_FLYSPEED_DEFAULT |
  698. CM6206_REG3_VRAP25EN |
  699. CM6206_REG3_FOE |
  700. CM6206_REG3_ROE |
  701. CM6206_REG3_CBOE |
  702. CM6206_REG3_LOSE |
  703. CM6206_REG3_HPOE |
  704. CM6206_REG3_SPDIFI_CANREC,
  705. /* REG4 is just a bunch of GPIO lines */
  706. 0x0000,
  707. /* REG5: de-assert AD/DA reset signals */
  708. CM6206_REG5_DA_RSTN |
  709. CM6206_REG5_AD_RSTN };
  710. for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
  711. err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
  712. if (err < 0)
  713. return err;
  714. }
  715. return err;
  716. }
  717. /* quirk for Plantronics GameCom 780 with CM6302 chip */
  718. static int snd_usb_gamecon780_boot_quirk(struct usb_device *dev)
  719. {
  720. /* set the initial volume and don't change; other values are either
  721. * too loud or silent due to firmware bug (bko#65251)
  722. */
  723. u8 buf[2] = { 0x74, 0xe3 };
  724. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
  725. USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
  726. UAC_FU_VOLUME << 8, 9 << 8, buf, 2);
  727. }
  728. /*
  729. * Novation Twitch DJ controller
  730. * Focusrite Novation Saffire 6 USB audio card
  731. */
  732. static int snd_usb_novation_boot_quirk(struct usb_device *dev)
  733. {
  734. /* preemptively set up the device because otherwise the
  735. * raw MIDI endpoints are not active */
  736. usb_set_interface(dev, 0, 1);
  737. return 0;
  738. }
  739. /*
  740. * This call will put the synth in "USB send" mode, i.e it will send MIDI
  741. * messages through USB (this is disabled at startup). The synth will
  742. * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
  743. * sign on its LCD. Values here are chosen based on sniffing USB traffic
  744. * under Windows.
  745. */
  746. static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
  747. {
  748. int err, actual_length;
  749. /* "midi send" enable */
  750. static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
  751. void *buf;
  752. if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x05)))
  753. return -EINVAL;
  754. buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
  755. if (!buf)
  756. return -ENOMEM;
  757. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
  758. ARRAY_SIZE(seq), &actual_length, 1000);
  759. kfree(buf);
  760. if (err < 0)
  761. return err;
  762. return 0;
  763. }
  764. /*
  765. * Some sound cards from Native Instruments are in fact compliant to the USB
  766. * audio standard of version 2 and other approved USB standards, even though
  767. * they come up as vendor-specific device when first connected.
  768. *
  769. * However, they can be told to come up with a new set of descriptors
  770. * upon their next enumeration, and the interfaces announced by the new
  771. * descriptors will then be handled by the kernel's class drivers. As the
  772. * product ID will also change, no further checks are required.
  773. */
  774. static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
  775. {
  776. int ret;
  777. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  778. 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  779. 1, 0, NULL, 0, 1000);
  780. if (ret < 0)
  781. return ret;
  782. usb_reset_device(dev);
  783. /* return -EAGAIN, so the creation of an audio interface for this
  784. * temporary device is aborted. The device will reconnect with a
  785. * new product ID */
  786. return -EAGAIN;
  787. }
  788. static void mbox2_setup_48_24_magic(struct usb_device *dev)
  789. {
  790. u8 srate[3];
  791. u8 temp[12];
  792. /* Choose 48000Hz permanently */
  793. srate[0] = 0x80;
  794. srate[1] = 0xbb;
  795. srate[2] = 0x00;
  796. /* Send the magic! */
  797. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  798. 0x01, 0x22, 0x0100, 0x0085, &temp, 0x0003);
  799. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  800. 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003);
  801. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  802. 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003);
  803. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  804. 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003);
  805. return;
  806. }
  807. /* Digidesign Mbox 2 needs to load firmware onboard
  808. * and driver must wait a few seconds for initialisation.
  809. */
  810. #define MBOX2_FIRMWARE_SIZE 646
  811. #define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */
  812. #define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */
  813. static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
  814. {
  815. struct usb_host_config *config = dev->actconfig;
  816. struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;
  817. int err;
  818. u8 bootresponse[0x12];
  819. int fwsize;
  820. int count;
  821. fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
  822. if (fwsize != MBOX2_FIRMWARE_SIZE) {
  823. dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
  824. return -ENODEV;
  825. }
  826. dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
  827. count = 0;
  828. bootresponse[0] = MBOX2_BOOT_LOADING;
  829. while ((bootresponse[0] == MBOX2_BOOT_LOADING) && (count < 10)) {
  830. msleep(500); /* 0.5 second delay */
  831. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
  832. /* Control magic - load onboard firmware */
  833. 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
  834. if (bootresponse[0] == MBOX2_BOOT_READY)
  835. break;
  836. dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
  837. count++;
  838. }
  839. if (bootresponse[0] != MBOX2_BOOT_READY) {
  840. dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
  841. return -ENODEV;
  842. }
  843. dev_dbg(&dev->dev, "device initialised!\n");
  844. new_device_descriptor = kmalloc(sizeof(*new_device_descriptor), GFP_KERNEL);
  845. if (!new_device_descriptor)
  846. return -ENOMEM;
  847. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  848. new_device_descriptor, sizeof(*new_device_descriptor));
  849. if (err < 0)
  850. dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
  851. if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
  852. dev_dbg(&dev->dev, "error too large bNumConfigurations: %d\n",
  853. new_device_descriptor->bNumConfigurations);
  854. else
  855. memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
  856. err = usb_reset_configuration(dev);
  857. if (err < 0)
  858. dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
  859. dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
  860. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  861. mbox2_setup_48_24_magic(dev);
  862. dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
  863. return 0; /* Successful boot */
  864. }
  865. static int snd_usb_axefx3_boot_quirk(struct usb_device *dev)
  866. {
  867. int err;
  868. dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n");
  869. /* If the Axe-Fx III has not fully booted, it will timeout when trying
  870. * to enable the audio streaming interface. A more generous timeout is
  871. * used here to detect when the Axe-Fx III has finished booting as the
  872. * set interface message will be acked once it has
  873. */
  874. err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  875. USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
  876. 1, 1, NULL, 0, 120000);
  877. if (err < 0) {
  878. dev_err(&dev->dev,
  879. "failed waiting for Axe-Fx III to boot: %d\n", err);
  880. return err;
  881. }
  882. dev_dbg(&dev->dev, "Axe-Fx III is now ready\n");
  883. err = usb_set_interface(dev, 1, 0);
  884. if (err < 0)
  885. dev_dbg(&dev->dev,
  886. "error stopping Axe-Fx III interface: %d\n", err);
  887. return 0;
  888. }
  889. static void mbox3_setup_defaults(struct usb_device *dev)
  890. {
  891. /* The Mbox 3 is "little endian" */
  892. /* max volume is: 0x0000. */
  893. /* min volume is: 0x0080 (shown in little endian form) */
  894. u8 com_buff[2];
  895. /* Deactivate Tuner */
  896. /* on = 0x01*/
  897. /* off = 0x00*/
  898. com_buff[0] = 0x00;
  899. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  900. 0x01, 0x21, 0x0003, 0x2001, &com_buff, 1);
  901. /* Set clock source to Internal (as opposed to S/PDIF) */
  902. /* Internal = 0x01*/
  903. /* S/PDIF = 0x02*/
  904. com_buff[0] = 0x01;
  905. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  906. 1, 0x21, 0x0100, 0x8001, &com_buff, 1);
  907. /* Mute the hardware loopbacks to start the device in a known state. */
  908. com_buff[0] = 0x00;
  909. com_buff[1] = 0x80;
  910. /* Analogue input 1 left channel: */
  911. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  912. 1, 0x21, 0x0110, 0x4001, &com_buff, 2);
  913. /* Analogue input 1 right channel: */
  914. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  915. 1, 0x21, 0x0111, 0x4001, &com_buff, 2);
  916. /* Analogue input 2 left channel: */
  917. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  918. 1, 0x21, 0x0114, 0x4001, &com_buff, 2);
  919. /* Analogue input 2 right channel: */
  920. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  921. 1, 0x21, 0x0115, 0x4001, &com_buff, 2);
  922. /* Analogue input 3 left channel: */
  923. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  924. 1, 0x21, 0x0118, 0x4001, &com_buff, 2);
  925. /* Analogue input 3 right channel: */
  926. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  927. 1, 0x21, 0x0119, 0x4001, &com_buff, 2);
  928. /* Analogue input 4 left channel: */
  929. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  930. 1, 0x21, 0x011c, 0x4001, &com_buff, 2);
  931. /* Analogue input 4 right channel: */
  932. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  933. 1, 0x21, 0x011d, 0x4001, &com_buff, 2);
  934. /* Set software sends to output */
  935. com_buff[0] = 0x00;
  936. com_buff[1] = 0x00;
  937. /* Analogue software return 1 left channel: */
  938. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  939. 1, 0x21, 0x0100, 0x4001, &com_buff, 2);
  940. com_buff[0] = 0x00;
  941. com_buff[1] = 0x80;
  942. /* Analogue software return 1 right channel: */
  943. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  944. 1, 0x21, 0x0101, 0x4001, &com_buff, 2);
  945. com_buff[0] = 0x00;
  946. com_buff[1] = 0x80;
  947. /* Analogue software return 2 left channel: */
  948. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  949. 1, 0x21, 0x0104, 0x4001, &com_buff, 2);
  950. com_buff[0] = 0x00;
  951. com_buff[1] = 0x00;
  952. /* Analogue software return 2 right channel: */
  953. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  954. 1, 0x21, 0x0105, 0x4001, &com_buff, 2);
  955. com_buff[0] = 0x00;
  956. com_buff[1] = 0x80;
  957. /* Analogue software return 3 left channel: */
  958. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  959. 1, 0x21, 0x0108, 0x4001, &com_buff, 2);
  960. /* Analogue software return 3 right channel: */
  961. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  962. 1, 0x21, 0x0109, 0x4001, &com_buff, 2);
  963. /* Analogue software return 4 left channel: */
  964. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  965. 1, 0x21, 0x010c, 0x4001, &com_buff, 2);
  966. /* Analogue software return 4 right channel: */
  967. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  968. 1, 0x21, 0x010d, 0x4001, &com_buff, 2);
  969. /* Return to muting sends */
  970. com_buff[0] = 0x00;
  971. com_buff[1] = 0x80;
  972. /* Analogue fx return left channel: */
  973. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  974. 1, 0x21, 0x0120, 0x4001, &com_buff, 2);
  975. /* Analogue fx return right channel: */
  976. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  977. 1, 0x21, 0x0121, 0x4001, &com_buff, 2);
  978. /* Analogue software input 1 fx send: */
  979. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  980. 1, 0x21, 0x0100, 0x4201, &com_buff, 2);
  981. /* Analogue software input 2 fx send: */
  982. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  983. 1, 0x21, 0x0101, 0x4201, &com_buff, 2);
  984. /* Analogue software input 3 fx send: */
  985. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  986. 1, 0x21, 0x0102, 0x4201, &com_buff, 2);
  987. /* Analogue software input 4 fx send: */
  988. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  989. 1, 0x21, 0x0103, 0x4201, &com_buff, 2);
  990. /* Analogue input 1 fx send: */
  991. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  992. 1, 0x21, 0x0104, 0x4201, &com_buff, 2);
  993. /* Analogue input 2 fx send: */
  994. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  995. 1, 0x21, 0x0105, 0x4201, &com_buff, 2);
  996. /* Analogue input 3 fx send: */
  997. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  998. 1, 0x21, 0x0106, 0x4201, &com_buff, 2);
  999. /* Analogue input 4 fx send: */
  1000. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1001. 1, 0x21, 0x0107, 0x4201, &com_buff, 2);
  1002. /* Toggle allowing host control */
  1003. /* Not needed
  1004. com_buff[0] = 0x02;
  1005. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1006. 3, 0x21, 0x0000, 0x2001, &com_buff, 1);
  1007. */
  1008. /* Do not dim fx returns */
  1009. com_buff[0] = 0x00;
  1010. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1011. 3, 0x21, 0x0002, 0x2001, &com_buff, 1);
  1012. /* Do not set fx returns to mono */
  1013. com_buff[0] = 0x00;
  1014. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1015. 3, 0x21, 0x0001, 0x2001, &com_buff, 1);
  1016. /* Mute the S/PDIF hardware loopback
  1017. * same odd volume logic here as above
  1018. */
  1019. com_buff[0] = 0x00;
  1020. com_buff[1] = 0x80;
  1021. /* S/PDIF hardware input 1 left channel */
  1022. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1023. 1, 0x21, 0x0112, 0x4001, &com_buff, 2);
  1024. /* S/PDIF hardware input 1 right channel */
  1025. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1026. 1, 0x21, 0x0113, 0x4001, &com_buff, 2);
  1027. /* S/PDIF hardware input 2 left channel */
  1028. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1029. 1, 0x21, 0x0116, 0x4001, &com_buff, 2);
  1030. /* S/PDIF hardware input 2 right channel */
  1031. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1032. 1, 0x21, 0x0117, 0x4001, &com_buff, 2);
  1033. /* S/PDIF hardware input 3 left channel */
  1034. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1035. 1, 0x21, 0x011a, 0x4001, &com_buff, 2);
  1036. /* S/PDIF hardware input 3 right channel */
  1037. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1038. 1, 0x21, 0x011b, 0x4001, &com_buff, 2);
  1039. /* S/PDIF hardware input 4 left channel */
  1040. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1041. 1, 0x21, 0x011e, 0x4001, &com_buff, 2);
  1042. /* S/PDIF hardware input 4 right channel */
  1043. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1044. 1, 0x21, 0x011f, 0x4001, &com_buff, 2);
  1045. /* S/PDIF software return 1 left channel */
  1046. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1047. 1, 0x21, 0x0102, 0x4001, &com_buff, 2);
  1048. /* S/PDIF software return 1 right channel */
  1049. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1050. 1, 0x21, 0x0103, 0x4001, &com_buff, 2);
  1051. /* S/PDIF software return 2 left channel */
  1052. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1053. 1, 0x21, 0x0106, 0x4001, &com_buff, 2);
  1054. /* S/PDIF software return 2 right channel */
  1055. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1056. 1, 0x21, 0x0107, 0x4001, &com_buff, 2);
  1057. com_buff[0] = 0x00;
  1058. com_buff[1] = 0x00;
  1059. /* S/PDIF software return 3 left channel */
  1060. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1061. 1, 0x21, 0x010a, 0x4001, &com_buff, 2);
  1062. com_buff[0] = 0x00;
  1063. com_buff[1] = 0x80;
  1064. /* S/PDIF software return 3 right channel */
  1065. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1066. 1, 0x21, 0x010b, 0x4001, &com_buff, 2);
  1067. /* S/PDIF software return 4 left channel */
  1068. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1069. 1, 0x21, 0x010e, 0x4001, &com_buff, 2);
  1070. com_buff[0] = 0x00;
  1071. com_buff[1] = 0x00;
  1072. /* S/PDIF software return 4 right channel */
  1073. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1074. 1, 0x21, 0x010f, 0x4001, &com_buff, 2);
  1075. com_buff[0] = 0x00;
  1076. com_buff[1] = 0x80;
  1077. /* S/PDIF fx returns left channel */
  1078. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1079. 1, 0x21, 0x0122, 0x4001, &com_buff, 2);
  1080. /* S/PDIF fx returns right channel */
  1081. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1082. 1, 0x21, 0x0123, 0x4001, &com_buff, 2);
  1083. /* Set the dropdown "Effect" to the first option */
  1084. /* Room1 = 0x00 */
  1085. /* Room2 = 0x01 */
  1086. /* Room3 = 0x02 */
  1087. /* Hall 1 = 0x03 */
  1088. /* Hall 2 = 0x04 */
  1089. /* Plate = 0x05 */
  1090. /* Delay = 0x06 */
  1091. /* Echo = 0x07 */
  1092. com_buff[0] = 0x00;
  1093. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1094. 1, 0x21, 0x0200, 0x4301, &com_buff, 1); /* max is 0xff */
  1095. /* min is 0x00 */
  1096. /* Set the effect duration to 0 */
  1097. /* max is 0xffff */
  1098. /* min is 0x0000 */
  1099. com_buff[0] = 0x00;
  1100. com_buff[1] = 0x00;
  1101. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1102. 1, 0x21, 0x0400, 0x4301, &com_buff, 2);
  1103. /* Set the effect volume and feedback to 0 */
  1104. /* max is 0xff */
  1105. /* min is 0x00 */
  1106. com_buff[0] = 0x00;
  1107. /* feedback: */
  1108. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1109. 1, 0x21, 0x0500, 0x4301, &com_buff, 1);
  1110. /* volume: */
  1111. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1112. 1, 0x21, 0x0300, 0x4301, &com_buff, 1);
  1113. /* Set soft button hold duration */
  1114. /* 0x03 = 250ms */
  1115. /* 0x05 = 500ms DEFAULT */
  1116. /* 0x08 = 750ms */
  1117. /* 0x0a = 1sec */
  1118. com_buff[0] = 0x05;
  1119. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1120. 3, 0x21, 0x0005, 0x2001, &com_buff, 1);
  1121. /* Use dim LEDs for button of state */
  1122. com_buff[0] = 0x00;
  1123. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1124. 3, 0x21, 0x0004, 0x2001, &com_buff, 1);
  1125. }
  1126. #define MBOX3_DESCRIPTOR_SIZE 464
  1127. static int snd_usb_mbox3_boot_quirk(struct usb_device *dev)
  1128. {
  1129. struct usb_host_config *config = dev->actconfig;
  1130. struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;
  1131. int err;
  1132. int descriptor_size;
  1133. descriptor_size = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
  1134. if (descriptor_size != MBOX3_DESCRIPTOR_SIZE) {
  1135. dev_err(&dev->dev, "MBOX3: Invalid descriptor size=%d.\n", descriptor_size);
  1136. return -ENODEV;
  1137. }
  1138. dev_dbg(&dev->dev, "MBOX3: device initialised!\n");
  1139. new_device_descriptor = kmalloc(sizeof(*new_device_descriptor), GFP_KERNEL);
  1140. if (!new_device_descriptor)
  1141. return -ENOMEM;
  1142. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  1143. new_device_descriptor, sizeof(*new_device_descriptor));
  1144. if (err < 0)
  1145. dev_dbg(&dev->dev, "MBOX3: error usb_get_descriptor: %d\n", err);
  1146. if (new_device_descriptor->bNumConfigurations > dev->descriptor.bNumConfigurations)
  1147. dev_dbg(&dev->dev, "MBOX3: error too large bNumConfigurations: %d\n",
  1148. new_device_descriptor->bNumConfigurations);
  1149. else
  1150. memcpy(&dev->descriptor, new_device_descriptor, sizeof(dev->descriptor));
  1151. err = usb_reset_configuration(dev);
  1152. if (err < 0)
  1153. dev_dbg(&dev->dev, "MBOX3: error usb_reset_configuration: %d\n", err);
  1154. dev_dbg(&dev->dev, "MBOX3: new boot length = %d\n",
  1155. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  1156. mbox3_setup_defaults(dev);
  1157. dev_info(&dev->dev, "MBOX3: Initialized.");
  1158. return 0; /* Successful boot */
  1159. }
  1160. #define MICROBOOK_BUF_SIZE 128
  1161. static int snd_usb_motu_microbookii_communicate(struct usb_device *dev, u8 *buf,
  1162. int buf_size, int *length)
  1163. {
  1164. int err, actual_length;
  1165. if (usb_pipe_type_check(dev, usb_sndintpipe(dev, 0x01)))
  1166. return -EINVAL;
  1167. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x01), buf, *length,
  1168. &actual_length, 1000);
  1169. if (err < 0)
  1170. return err;
  1171. print_hex_dump(KERN_DEBUG, "MicroBookII snd: ", DUMP_PREFIX_NONE, 16, 1,
  1172. buf, actual_length, false);
  1173. memset(buf, 0, buf_size);
  1174. if (usb_pipe_type_check(dev, usb_rcvintpipe(dev, 0x82)))
  1175. return -EINVAL;
  1176. err = usb_interrupt_msg(dev, usb_rcvintpipe(dev, 0x82), buf, buf_size,
  1177. &actual_length, 1000);
  1178. if (err < 0)
  1179. return err;
  1180. print_hex_dump(KERN_DEBUG, "MicroBookII rcv: ", DUMP_PREFIX_NONE, 16, 1,
  1181. buf, actual_length, false);
  1182. *length = actual_length;
  1183. return 0;
  1184. }
  1185. static int snd_usb_motu_microbookii_boot_quirk(struct usb_device *dev)
  1186. {
  1187. int err, actual_length, poll_attempts = 0;
  1188. static const u8 set_samplerate_seq[] = { 0x00, 0x00, 0x00, 0x00,
  1189. 0x00, 0x00, 0x0b, 0x14,
  1190. 0x00, 0x00, 0x00, 0x01 };
  1191. static const u8 poll_ready_seq[] = { 0x00, 0x04, 0x00, 0x00,
  1192. 0x00, 0x00, 0x0b, 0x18 };
  1193. u8 *buf = kzalloc(MICROBOOK_BUF_SIZE, GFP_KERNEL);
  1194. if (!buf)
  1195. return -ENOMEM;
  1196. dev_info(&dev->dev, "Waiting for MOTU Microbook II to boot up...\n");
  1197. /* First we tell the device which sample rate to use. */
  1198. memcpy(buf, set_samplerate_seq, sizeof(set_samplerate_seq));
  1199. actual_length = sizeof(set_samplerate_seq);
  1200. err = snd_usb_motu_microbookii_communicate(dev, buf, MICROBOOK_BUF_SIZE,
  1201. &actual_length);
  1202. if (err < 0) {
  1203. dev_err(&dev->dev,
  1204. "failed setting the sample rate for Motu MicroBook II: %d\n",
  1205. err);
  1206. goto free_buf;
  1207. }
  1208. /* Then we poll every 100 ms until the device informs of its readiness. */
  1209. while (true) {
  1210. if (++poll_attempts > 100) {
  1211. dev_err(&dev->dev,
  1212. "failed booting Motu MicroBook II: timeout\n");
  1213. err = -ENODEV;
  1214. goto free_buf;
  1215. }
  1216. memset(buf, 0, MICROBOOK_BUF_SIZE);
  1217. memcpy(buf, poll_ready_seq, sizeof(poll_ready_seq));
  1218. actual_length = sizeof(poll_ready_seq);
  1219. err = snd_usb_motu_microbookii_communicate(
  1220. dev, buf, MICROBOOK_BUF_SIZE, &actual_length);
  1221. if (err < 0) {
  1222. dev_err(&dev->dev,
  1223. "failed booting Motu MicroBook II: communication error %d\n",
  1224. err);
  1225. goto free_buf;
  1226. }
  1227. /* the device signals its readiness through a message of the
  1228. * form
  1229. * XX 06 00 00 00 00 0b 18 00 00 00 01
  1230. * If the device is not yet ready to accept audio data, the
  1231. * last byte of that sequence is 00.
  1232. */
  1233. if (actual_length == 12 && buf[actual_length - 1] == 1)
  1234. break;
  1235. msleep(100);
  1236. }
  1237. dev_info(&dev->dev, "MOTU MicroBook II ready\n");
  1238. free_buf:
  1239. kfree(buf);
  1240. return err;
  1241. }
  1242. static int snd_usb_motu_m_series_boot_quirk(struct usb_device *dev)
  1243. {
  1244. msleep(4000);
  1245. return 0;
  1246. }
  1247. static int snd_usb_rme_digiface_boot_quirk(struct usb_device *dev)
  1248. {
  1249. /* Disable mixer, internal clock, all outputs ADAT, 48kHz, TMS off */
  1250. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1251. 16, 0x40, 0x2410, 0x7fff, NULL, 0);
  1252. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1253. 18, 0x40, 0x0104, 0xffff, NULL, 0);
  1254. /* Disable loopback for all inputs */
  1255. for (int ch = 0; ch < 32; ch++)
  1256. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1257. 22, 0x40, 0x400, ch, NULL, 0);
  1258. /* Unity gain for all outputs */
  1259. for (int ch = 0; ch < 34; ch++)
  1260. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
  1261. 21, 0x40, 0x9000, 0x100 + ch, NULL, 0);
  1262. return 0;
  1263. }
  1264. /*
  1265. * Setup quirks
  1266. */
  1267. #define MAUDIO_SET 0x01 /* parse device_setup */
  1268. #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
  1269. #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
  1270. #define MAUDIO_SET_96K 0x04 /* 48-96kHz rate if set, 8-48kHz otherwise */
  1271. #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
  1272. #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
  1273. #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
  1274. #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48kHz+Digital Input */
  1275. #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48kHz+No Digital Input */
  1276. #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48kHz+Digital Input */
  1277. #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48kHz+No Digital Input */
  1278. static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
  1279. int iface, int altno)
  1280. {
  1281. /* Reset ALL ifaces to 0 altsetting.
  1282. * Call it for every possible altsetting of every interface.
  1283. */
  1284. usb_set_interface(chip->dev, iface, 0);
  1285. if (chip->setup & MAUDIO_SET) {
  1286. if (chip->setup & MAUDIO_SET_COMPATIBLE) {
  1287. if (iface != 1 && iface != 2)
  1288. return 1; /* skip all interfaces but 1 and 2 */
  1289. } else {
  1290. unsigned int mask;
  1291. if (iface == 1 || iface == 2)
  1292. return 1; /* skip interfaces 1 and 2 */
  1293. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  1294. return 1; /* skip this altsetting */
  1295. mask = chip->setup & MAUDIO_SET_MASK;
  1296. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  1297. return 1; /* skip this altsetting */
  1298. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  1299. return 1; /* skip this altsetting */
  1300. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
  1301. return 1; /* skip this altsetting */
  1302. }
  1303. }
  1304. usb_audio_dbg(chip,
  1305. "using altsetting %d for interface %d config %d\n",
  1306. altno, iface, chip->setup);
  1307. return 0; /* keep this altsetting */
  1308. }
  1309. static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
  1310. int iface,
  1311. int altno)
  1312. {
  1313. /* Reset ALL ifaces to 0 altsetting.
  1314. * Call it for every possible altsetting of every interface.
  1315. */
  1316. usb_set_interface(chip->dev, iface, 0);
  1317. if (chip->setup & MAUDIO_SET) {
  1318. unsigned int mask;
  1319. if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
  1320. return 1; /* skip this altsetting */
  1321. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  1322. return 1; /* skip this altsetting */
  1323. mask = chip->setup & MAUDIO_SET_MASK;
  1324. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  1325. return 1; /* skip this altsetting */
  1326. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  1327. return 1; /* skip this altsetting */
  1328. if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
  1329. return 1; /* skip this altsetting */
  1330. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
  1331. return 1; /* skip this altsetting */
  1332. }
  1333. return 0; /* keep this altsetting */
  1334. }
  1335. static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
  1336. int iface, int altno)
  1337. {
  1338. /* Reset ALL ifaces to 0 altsetting.
  1339. * Call it for every possible altsetting of every interface.
  1340. */
  1341. usb_set_interface(chip->dev, iface, 0);
  1342. /* possible configuration where both inputs and only one output is
  1343. *used is not supported by the current setup
  1344. */
  1345. if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
  1346. if (chip->setup & MAUDIO_SET_96K) {
  1347. if (altno != 3 && altno != 6)
  1348. return 1;
  1349. } else if (chip->setup & MAUDIO_SET_DI) {
  1350. if (iface == 4)
  1351. return 1; /* no analog input */
  1352. if (altno != 2 && altno != 5)
  1353. return 1; /* enable only altsets 2 and 5 */
  1354. } else {
  1355. if (iface == 5)
  1356. return 1; /* disable digialt input */
  1357. if (altno != 2 && altno != 5)
  1358. return 1; /* enalbe only altsets 2 and 5 */
  1359. }
  1360. } else {
  1361. /* keep only 16-Bit mode */
  1362. if (altno != 1)
  1363. return 1;
  1364. }
  1365. usb_audio_dbg(chip,
  1366. "using altsetting %d for interface %d config %d\n",
  1367. altno, iface, chip->setup);
  1368. return 0; /* keep this altsetting */
  1369. }
  1370. static int s1810c_skip_setting_quirk(struct snd_usb_audio *chip,
  1371. int iface, int altno)
  1372. {
  1373. /*
  1374. * Altno settings:
  1375. *
  1376. * Playback (Interface 1):
  1377. * 1: 6 Analog + 2 S/PDIF
  1378. * 2: 6 Analog + 2 S/PDIF
  1379. * 3: 6 Analog
  1380. *
  1381. * Capture (Interface 2):
  1382. * 1: 8 Analog + 2 S/PDIF + 8 ADAT
  1383. * 2: 8 Analog + 2 S/PDIF + 4 ADAT
  1384. * 3: 8 Analog
  1385. */
  1386. /*
  1387. * I'll leave 2 as the default one and
  1388. * use device_setup to switch to the
  1389. * other two.
  1390. */
  1391. if ((chip->setup == 0 || chip->setup > 2) && altno != 2)
  1392. return 1;
  1393. else if (chip->setup == 1 && altno != 1)
  1394. return 1;
  1395. else if (chip->setup == 2 && altno != 3)
  1396. return 1;
  1397. return 0;
  1398. }
  1399. int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
  1400. int iface,
  1401. int altno)
  1402. {
  1403. /* audiophile usb: skip altsets incompatible with device_setup */
  1404. if (chip->usb_id == USB_ID(0x0763, 0x2003))
  1405. return audiophile_skip_setting_quirk(chip, iface, altno);
  1406. /* quattro usb: skip altsets incompatible with device_setup */
  1407. if (chip->usb_id == USB_ID(0x0763, 0x2001))
  1408. return quattro_skip_setting_quirk(chip, iface, altno);
  1409. /* fasttrackpro usb: skip altsets incompatible with device_setup */
  1410. if (chip->usb_id == USB_ID(0x0763, 0x2012))
  1411. return fasttrackpro_skip_setting_quirk(chip, iface, altno);
  1412. /* presonus studio 1810c: skip altsets incompatible with device_setup */
  1413. if (chip->usb_id == USB_ID(0x194f, 0x010c))
  1414. return s1810c_skip_setting_quirk(chip, iface, altno);
  1415. return 0;
  1416. }
  1417. int snd_usb_apply_boot_quirk(struct usb_device *dev,
  1418. struct usb_interface *intf,
  1419. const struct snd_usb_audio_quirk *quirk,
  1420. unsigned int id)
  1421. {
  1422. switch (id) {
  1423. case USB_ID(0x041e, 0x3000):
  1424. /* SB Extigy needs special boot-up sequence */
  1425. /* if more models come, this will go to the quirk list. */
  1426. return snd_usb_extigy_boot_quirk(dev, intf);
  1427. case USB_ID(0x041e, 0x3020):
  1428. /* SB Audigy 2 NX needs its own boot-up magic, too */
  1429. return snd_usb_audigy2nx_boot_quirk(dev);
  1430. case USB_ID(0x10f5, 0x0200):
  1431. /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
  1432. return snd_usb_cm106_boot_quirk(dev);
  1433. case USB_ID(0x0d8c, 0x0102):
  1434. /* C-Media CM6206 / CM106-Like Sound Device */
  1435. case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
  1436. return snd_usb_cm6206_boot_quirk(dev);
  1437. case USB_ID(0x0dba, 0x3000):
  1438. /* Digidesign Mbox 2 */
  1439. return snd_usb_mbox2_boot_quirk(dev);
  1440. case USB_ID(0x0dba, 0x5000):
  1441. /* Digidesign Mbox 3 */
  1442. return snd_usb_mbox3_boot_quirk(dev);
  1443. case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
  1444. case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
  1445. return snd_usb_novation_boot_quirk(dev);
  1446. case USB_ID(0x133e, 0x0815):
  1447. /* Access Music VirusTI Desktop */
  1448. return snd_usb_accessmusic_boot_quirk(dev);
  1449. case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
  1450. case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
  1451. case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
  1452. return snd_usb_nativeinstruments_boot_quirk(dev);
  1453. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
  1454. return snd_usb_fasttrackpro_boot_quirk(dev);
  1455. case USB_ID(0x047f, 0xc010): /* Plantronics Gamecom 780 */
  1456. return snd_usb_gamecon780_boot_quirk(dev);
  1457. case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx 3 */
  1458. return snd_usb_axefx3_boot_quirk(dev);
  1459. case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook II */
  1460. /*
  1461. * For some reason interface 3 with vendor-spec class is
  1462. * detected on MicroBook IIc.
  1463. */
  1464. if (get_iface_desc(intf->altsetting)->bInterfaceClass ==
  1465. USB_CLASS_VENDOR_SPEC &&
  1466. get_iface_desc(intf->altsetting)->bInterfaceNumber < 3)
  1467. return snd_usb_motu_microbookii_boot_quirk(dev);
  1468. break;
  1469. case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */
  1470. case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */
  1471. return snd_usb_rme_digiface_boot_quirk(dev);
  1472. }
  1473. return 0;
  1474. }
  1475. int snd_usb_apply_boot_quirk_once(struct usb_device *dev,
  1476. struct usb_interface *intf,
  1477. const struct snd_usb_audio_quirk *quirk,
  1478. unsigned int id)
  1479. {
  1480. switch (id) {
  1481. case USB_ID(0x07fd, 0x0008): /* MOTU M Series, 1st hardware version */
  1482. return snd_usb_motu_m_series_boot_quirk(dev);
  1483. }
  1484. return 0;
  1485. }
  1486. /*
  1487. * check if the device uses big-endian samples
  1488. */
  1489. int snd_usb_is_big_endian_format(struct snd_usb_audio *chip,
  1490. const struct audioformat *fp)
  1491. {
  1492. /* it depends on altsetting whether the device is big-endian or not */
  1493. switch (chip->usb_id) {
  1494. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
  1495. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  1496. fp->altsetting == 5 || fp->altsetting == 6)
  1497. return 1;
  1498. break;
  1499. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  1500. if (chip->setup == 0x00 ||
  1501. fp->altsetting == 1 || fp->altsetting == 2 ||
  1502. fp->altsetting == 3)
  1503. return 1;
  1504. break;
  1505. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
  1506. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  1507. fp->altsetting == 5 || fp->altsetting == 6)
  1508. return 1;
  1509. break;
  1510. }
  1511. return 0;
  1512. }
  1513. /*
  1514. * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
  1515. * not for interface.
  1516. */
  1517. enum {
  1518. EMU_QUIRK_SR_44100HZ = 0,
  1519. EMU_QUIRK_SR_48000HZ,
  1520. EMU_QUIRK_SR_88200HZ,
  1521. EMU_QUIRK_SR_96000HZ,
  1522. EMU_QUIRK_SR_176400HZ,
  1523. EMU_QUIRK_SR_192000HZ
  1524. };
  1525. static void set_format_emu_quirk(struct snd_usb_substream *subs,
  1526. const struct audioformat *fmt)
  1527. {
  1528. unsigned char emu_samplerate_id = 0;
  1529. /* When capture is active
  1530. * sample rate shouldn't be changed
  1531. * by playback substream
  1532. */
  1533. if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
  1534. if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].cur_audiofmt)
  1535. return;
  1536. }
  1537. switch (fmt->rate_min) {
  1538. case 48000:
  1539. emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
  1540. break;
  1541. case 88200:
  1542. emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
  1543. break;
  1544. case 96000:
  1545. emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
  1546. break;
  1547. case 176400:
  1548. emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
  1549. break;
  1550. case 192000:
  1551. emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
  1552. break;
  1553. default:
  1554. emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
  1555. break;
  1556. }
  1557. snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
  1558. subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
  1559. }
  1560. static int pioneer_djm_set_format_quirk(struct snd_usb_substream *subs,
  1561. u16 windex)
  1562. {
  1563. unsigned int cur_rate = subs->data_endpoint->cur_rate;
  1564. u8 sr[3];
  1565. // Convert to little endian
  1566. sr[0] = cur_rate & 0xff;
  1567. sr[1] = (cur_rate >> 8) & 0xff;
  1568. sr[2] = (cur_rate >> 16) & 0xff;
  1569. usb_set_interface(subs->dev, 0, 1);
  1570. // we should derive windex from fmt-sync_ep but it's not set
  1571. snd_usb_ctl_msg(subs->stream->chip->dev,
  1572. usb_sndctrlpipe(subs->stream->chip->dev, 0),
  1573. 0x01, 0x22, 0x0100, windex, &sr, 0x0003);
  1574. return 0;
  1575. }
  1576. static void mbox3_set_format_quirk(struct snd_usb_substream *subs,
  1577. const struct audioformat *fmt)
  1578. {
  1579. __le32 buff4 = 0;
  1580. u8 buff1 = 0x01;
  1581. u32 new_rate = subs->data_endpoint->cur_rate;
  1582. u32 current_rate;
  1583. // Get current rate from card and check if changing it is needed
  1584. snd_usb_ctl_msg(subs->dev, usb_rcvctrlpipe(subs->dev, 0),
  1585. 0x01, 0x21 | USB_DIR_IN, 0x0100, 0x8101, &buff4, 4);
  1586. current_rate = le32_to_cpu(buff4);
  1587. dev_dbg(&subs->dev->dev,
  1588. "MBOX3: Current configured sample rate: %d", current_rate);
  1589. if (current_rate == new_rate) {
  1590. dev_dbg(&subs->dev->dev,
  1591. "MBOX3: No change needed (current rate:%d == new rate:%d)",
  1592. current_rate, new_rate);
  1593. return;
  1594. }
  1595. // Set new rate
  1596. dev_info(&subs->dev->dev,
  1597. "MBOX3: Changing sample rate to: %d", new_rate);
  1598. buff4 = cpu_to_le32(new_rate);
  1599. snd_usb_ctl_msg(subs->dev, usb_sndctrlpipe(subs->dev, 0),
  1600. 0x01, 0x21, 0x0100, 0x8101, &buff4, 4);
  1601. // Set clock source to Internal
  1602. snd_usb_ctl_msg(subs->dev, usb_sndctrlpipe(subs->dev, 0),
  1603. 0x01, 0x21, 0x0100, 0x8001, &buff1, 1);
  1604. // Check whether the change was successful
  1605. buff4 = 0;
  1606. snd_usb_ctl_msg(subs->dev, usb_rcvctrlpipe(subs->dev, 0),
  1607. 0x01, 0x21 | USB_DIR_IN, 0x0100, 0x8101, &buff4, 4);
  1608. if (new_rate != le32_to_cpu(buff4))
  1609. dev_warn(&subs->dev->dev, "MBOX3: Couldn't set the sample rate");
  1610. }
  1611. static const int rme_digiface_rate_table[] = {
  1612. 32000, 44100, 48000, 0,
  1613. 64000, 88200, 96000, 0,
  1614. 128000, 176400, 192000, 0,
  1615. };
  1616. static int rme_digiface_set_format_quirk(struct snd_usb_substream *subs)
  1617. {
  1618. unsigned int cur_rate = subs->data_endpoint->cur_rate;
  1619. u16 val;
  1620. int speed_mode;
  1621. int id;
  1622. for (id = 0; id < ARRAY_SIZE(rme_digiface_rate_table); id++) {
  1623. if (rme_digiface_rate_table[id] == cur_rate)
  1624. break;
  1625. }
  1626. if (id >= ARRAY_SIZE(rme_digiface_rate_table))
  1627. return -EINVAL;
  1628. /* 2, 3, 4 for 1x, 2x, 4x */
  1629. speed_mode = (id >> 2) + 2;
  1630. val = (id << 3) | (speed_mode << 12);
  1631. /* Set the sample rate */
  1632. snd_usb_ctl_msg(subs->stream->chip->dev,
  1633. usb_sndctrlpipe(subs->stream->chip->dev, 0),
  1634. 16, 0x40, val, 0x7078, NULL, 0);
  1635. return 0;
  1636. }
  1637. void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
  1638. const struct audioformat *fmt)
  1639. {
  1640. switch (subs->stream->chip->usb_id) {
  1641. case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
  1642. case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
  1643. case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
  1644. case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
  1645. set_format_emu_quirk(subs, fmt);
  1646. break;
  1647. case USB_ID(0x534d, 0x0021): /* MacroSilicon MS2100/MS2106 */
  1648. case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */
  1649. subs->stream_offset_adj = 2;
  1650. break;
  1651. case USB_ID(0x2b73, 0x0013): /* Pioneer DJM-450 */
  1652. pioneer_djm_set_format_quirk(subs, 0x0082);
  1653. break;
  1654. case USB_ID(0x08e4, 0x017f): /* Pioneer DJM-750 */
  1655. case USB_ID(0x08e4, 0x0163): /* Pioneer DJM-850 */
  1656. pioneer_djm_set_format_quirk(subs, 0x0086);
  1657. break;
  1658. case USB_ID(0x0dba, 0x5000):
  1659. mbox3_set_format_quirk(subs, fmt); /* Digidesign Mbox 3 */
  1660. break;
  1661. case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */
  1662. case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */
  1663. rme_digiface_set_format_quirk(subs);
  1664. break;
  1665. }
  1666. }
  1667. int snd_usb_select_mode_quirk(struct snd_usb_audio *chip,
  1668. const struct audioformat *fmt)
  1669. {
  1670. struct usb_device *dev = chip->dev;
  1671. int err;
  1672. if (chip->quirk_flags & QUIRK_FLAG_ITF_USB_DSD_DAC) {
  1673. /* First switch to alt set 0, otherwise the mode switch cmd
  1674. * will not be accepted by the DAC
  1675. */
  1676. err = usb_set_interface(dev, fmt->iface, 0);
  1677. if (err < 0)
  1678. return err;
  1679. msleep(20); /* Delay needed after setting the interface */
  1680. /* Vendor mode switch cmd is required. */
  1681. if (fmt->formats & SNDRV_PCM_FMTBIT_DSD_U32_BE) {
  1682. /* DSD mode (DSD_U32) requested */
  1683. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
  1684. USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
  1685. 1, 1, NULL, 0);
  1686. if (err < 0)
  1687. return err;
  1688. } else {
  1689. /* PCM or DOP mode (S32) requested */
  1690. /* PCM mode (S16) requested */
  1691. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0,
  1692. USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
  1693. 0, 1, NULL, 0);
  1694. if (err < 0)
  1695. return err;
  1696. }
  1697. msleep(20);
  1698. }
  1699. return 0;
  1700. }
  1701. void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
  1702. {
  1703. /*
  1704. * "Playback Design" products send bogus feedback data at the start
  1705. * of the stream. Ignore them.
  1706. */
  1707. if (USB_ID_VENDOR(ep->chip->usb_id) == 0x23ba &&
  1708. ep->type == SND_USB_ENDPOINT_TYPE_SYNC)
  1709. ep->skip_packets = 4;
  1710. /*
  1711. * M-Audio Fast Track C400/C600 - when packets are not skipped, real
  1712. * world latency varies by approx. +/- 50 frames (at 96kHz) each time
  1713. * the stream is (re)started. When skipping packets 16 at endpoint
  1714. * start up, the real world latency is stable within +/- 1 frame (also
  1715. * across power cycles).
  1716. */
  1717. if ((ep->chip->usb_id == USB_ID(0x0763, 0x2030) ||
  1718. ep->chip->usb_id == USB_ID(0x0763, 0x2031)) &&
  1719. ep->type == SND_USB_ENDPOINT_TYPE_DATA)
  1720. ep->skip_packets = 16;
  1721. /* Work around devices that report unreasonable feedback data */
  1722. if ((ep->chip->usb_id == USB_ID(0x0644, 0x8038) || /* TEAC UD-H01 */
  1723. ep->chip->usb_id == USB_ID(0x1852, 0x5034)) && /* T+A Dac8 */
  1724. ep->syncmaxsize == 4)
  1725. ep->tenor_fb_quirk = 1;
  1726. }
  1727. /* quirk applied after snd_usb_ctl_msg(); not applied during boot quirks */
  1728. void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
  1729. __u8 request, __u8 requesttype, __u16 value,
  1730. __u16 index, void *data, __u16 size)
  1731. {
  1732. struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
  1733. if (!chip || (requesttype & USB_TYPE_MASK) != USB_TYPE_CLASS)
  1734. return;
  1735. if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY)
  1736. msleep(20);
  1737. else if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY_1M)
  1738. usleep_range(1000, 2000);
  1739. else if (chip->quirk_flags & QUIRK_FLAG_CTL_MSG_DELAY_5M)
  1740. usleep_range(5000, 6000);
  1741. }
  1742. /*
  1743. * snd_usb_interface_dsd_format_quirks() is called from format.c to
  1744. * augment the PCM format bit-field for DSD types. The UAC standards
  1745. * don't have a designated bit field to denote DSD-capable interfaces,
  1746. * hence all hardware that is known to support this format has to be
  1747. * listed here.
  1748. */
  1749. u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
  1750. struct audioformat *fp,
  1751. unsigned int sample_bytes)
  1752. {
  1753. struct usb_interface *iface;
  1754. /* Playback Designs */
  1755. if (USB_ID_VENDOR(chip->usb_id) == 0x23ba &&
  1756. USB_ID_PRODUCT(chip->usb_id) < 0x0110) {
  1757. switch (fp->altsetting) {
  1758. case 1:
  1759. fp->dsd_dop = true;
  1760. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  1761. case 2:
  1762. fp->dsd_bitrev = true;
  1763. return SNDRV_PCM_FMTBIT_DSD_U8;
  1764. case 3:
  1765. fp->dsd_bitrev = true;
  1766. return SNDRV_PCM_FMTBIT_DSD_U16_LE;
  1767. }
  1768. }
  1769. /* XMOS based USB DACs */
  1770. switch (chip->usb_id) {
  1771. case USB_ID(0x139f, 0x5504): /* Nagra DAC */
  1772. case USB_ID(0x20b1, 0x3089): /* Mola-Mola DAC */
  1773. case USB_ID(0x2522, 0x0007): /* LH Labs Geek Out 1V5 */
  1774. case USB_ID(0x2522, 0x0009): /* LH Labs Geek Pulse X Inifinity 2V0 */
  1775. case USB_ID(0x2522, 0x0012): /* LH Labs VI DAC Infinity */
  1776. case USB_ID(0x2772, 0x0230): /* Pro-Ject Pre Box S2 Digital */
  1777. if (fp->altsetting == 2)
  1778. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1779. break;
  1780. case USB_ID(0x0d8c, 0x0316): /* Hegel HD12 DSD */
  1781. case USB_ID(0x10cb, 0x0103): /* The Bit Opus #3; with fp->dsd_raw */
  1782. case USB_ID(0x16d0, 0x06b2): /* NuPrime DAC-10 */
  1783. case USB_ID(0x16d0, 0x06b4): /* NuPrime Audio HD-AVP/AVA */
  1784. case USB_ID(0x16d0, 0x0733): /* Furutech ADL Stratos */
  1785. case USB_ID(0x16d0, 0x09d8): /* NuPrime IDA-8 */
  1786. case USB_ID(0x16d0, 0x09db): /* NuPrime Audio DAC-9 */
  1787. case USB_ID(0x16d0, 0x09dd): /* Encore mDSD */
  1788. case USB_ID(0x1db5, 0x0003): /* Bryston BDA3 */
  1789. case USB_ID(0x20a0, 0x4143): /* WaveIO USB Audio 2.0 */
  1790. case USB_ID(0x22e1, 0xca01): /* HDTA Serenade DSD */
  1791. case USB_ID(0x249c, 0x9326): /* M2Tech Young MkIII */
  1792. case USB_ID(0x2616, 0x0106): /* PS Audio NuWave DAC */
  1793. case USB_ID(0x2622, 0x0041): /* Audiolab M-DAC+ */
  1794. case USB_ID(0x278b, 0x5100): /* Rotel RC-1590 */
  1795. case USB_ID(0x27f7, 0x3002): /* W4S DAC-2v2SE */
  1796. case USB_ID(0x29a2, 0x0086): /* Mutec MC3+ USB */
  1797. case USB_ID(0x6b42, 0x0042): /* MSB Technology */
  1798. if (fp->altsetting == 3)
  1799. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1800. break;
  1801. /* Amanero Combo384 USB based DACs with native DSD support */
  1802. case USB_ID(0x16d0, 0x071a): /* Amanero - Combo384 */
  1803. if (fp->altsetting == 2) {
  1804. switch (le16_to_cpu(chip->dev->descriptor.bcdDevice)) {
  1805. case 0x199:
  1806. return SNDRV_PCM_FMTBIT_DSD_U32_LE;
  1807. case 0x19b:
  1808. case 0x203:
  1809. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1810. default:
  1811. break;
  1812. }
  1813. }
  1814. break;
  1815. case USB_ID(0x16d0, 0x0a23):
  1816. if (fp->altsetting == 2)
  1817. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1818. break;
  1819. default:
  1820. break;
  1821. }
  1822. /* ITF-USB DSD based DACs */
  1823. if (chip->quirk_flags & QUIRK_FLAG_ITF_USB_DSD_DAC) {
  1824. iface = usb_ifnum_to_if(chip->dev, fp->iface);
  1825. /* Altsetting 2 support native DSD if the num of altsets is
  1826. * three (0-2),
  1827. * Altsetting 3 support native DSD if the num of altsets is
  1828. * four (0-3).
  1829. */
  1830. if (fp->altsetting == iface->num_altsetting - 1)
  1831. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1832. }
  1833. /* Mostly generic method to detect many DSD-capable implementations */
  1834. if ((chip->quirk_flags & QUIRK_FLAG_DSD_RAW) && fp->dsd_raw)
  1835. return SNDRV_PCM_FMTBIT_DSD_U32_BE;
  1836. return 0;
  1837. }
  1838. void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
  1839. struct audioformat *fp,
  1840. int stream)
  1841. {
  1842. switch (chip->usb_id) {
  1843. case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
  1844. /* Optoplay sets the sample rate attribute although
  1845. * it seems not supporting it in fact.
  1846. */
  1847. fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
  1848. break;
  1849. case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
  1850. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  1851. /* doesn't set the sample rate attribute, but supports it */
  1852. fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
  1853. break;
  1854. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
  1855. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
  1856. case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
  1857. case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
  1858. an older model 77d:223) */
  1859. /*
  1860. * plantronics headset and Griffin iMic have set adaptive-in
  1861. * although it's really not...
  1862. */
  1863. fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
  1864. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  1865. fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
  1866. else
  1867. fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
  1868. break;
  1869. case USB_ID(0x07fd, 0x0004): /* MOTU MicroBook IIc */
  1870. /*
  1871. * MaxPacketsOnly attribute is erroneously set in endpoint
  1872. * descriptors. As a result this card produces noise with
  1873. * all sample rates other than 96 kHz.
  1874. */
  1875. fp->attributes &= ~UAC_EP_CS_ATTR_FILL_MAX;
  1876. break;
  1877. case USB_ID(0x1224, 0x2a25): /* Jieli Technology USB PHY 2.0 */
  1878. /* mic works only when ep packet size is set to wMaxPacketSize */
  1879. fp->attributes |= UAC_EP_CS_ATTR_FILL_MAX;
  1880. break;
  1881. case USB_ID(0x3511, 0x2b1e): /* Opencomm2 UC USB Bluetooth dongle */
  1882. /* mic works only when ep pitch control is not set */
  1883. if (stream == SNDRV_PCM_STREAM_CAPTURE)
  1884. fp->attributes &= ~UAC_EP_CS_ATTR_PITCH_CONTROL;
  1885. break;
  1886. }
  1887. }
  1888. /*
  1889. * driver behavior quirk flags
  1890. */
  1891. struct usb_audio_quirk_flags_table {
  1892. u32 id;
  1893. u32 flags;
  1894. };
  1895. #define DEVICE_FLG(vid, pid, _flags) \
  1896. { .id = USB_ID(vid, pid), .flags = (_flags) }
  1897. #define VENDOR_FLG(vid, _flags) DEVICE_FLG(vid, 0, _flags)
  1898. static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
  1899. /* Device matches */
  1900. DEVICE_FLG(0x03f0, 0x654a, /* HP 320 FHD Webcam */
  1901. QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
  1902. DEVICE_FLG(0x041e, 0x3000, /* Creative SB Extigy */
  1903. QUIRK_FLAG_IGNORE_CTL_ERROR),
  1904. DEVICE_FLG(0x041e, 0x4080, /* Creative Live Cam VF0610 */
  1905. QUIRK_FLAG_GET_SAMPLE_RATE),
  1906. DEVICE_FLG(0x045e, 0x083c, /* MS USB Link headset */
  1907. QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY |
  1908. QUIRK_FLAG_DISABLE_AUTOSUSPEND),
  1909. DEVICE_FLG(0x046d, 0x0807, /* Logitech Webcam C500 */
  1910. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1911. DEVICE_FLG(0x046d, 0x0808, /* Logitech Webcam C600 */
  1912. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1913. DEVICE_FLG(0x046d, 0x0809,
  1914. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1915. DEVICE_FLG(0x046d, 0x0819, /* Logitech Webcam C210 */
  1916. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1917. DEVICE_FLG(0x046d, 0x081b, /* HD Webcam c310 */
  1918. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1919. DEVICE_FLG(0x046d, 0x081d, /* HD Webcam c510 */
  1920. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1921. DEVICE_FLG(0x046d, 0x0825, /* HD Webcam c270 */
  1922. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1923. DEVICE_FLG(0x046d, 0x0826, /* HD Webcam c525 */
  1924. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1925. DEVICE_FLG(0x046d, 0x084c, /* Logitech ConferenceCam Connect */
  1926. QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY_1M),
  1927. DEVICE_FLG(0x046d, 0x08ca, /* Logitech Quickcam Fusion */
  1928. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1929. DEVICE_FLG(0x046d, 0x0991, /* Logitech QuickCam Pro */
  1930. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_IGNORE_CTL_ERROR |
  1931. QUIRK_FLAG_MIC_RES_384),
  1932. DEVICE_FLG(0x046d, 0x09a2, /* QuickCam Communicate Deluxe/S7500 */
  1933. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_MIC_RES_384),
  1934. DEVICE_FLG(0x046d, 0x09a4, /* Logitech QuickCam E 3500 */
  1935. QUIRK_FLAG_CTL_MSG_DELAY_1M | QUIRK_FLAG_IGNORE_CTL_ERROR),
  1936. DEVICE_FLG(0x0499, 0x1506, /* Yamaha THR5 */
  1937. QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  1938. DEVICE_FLG(0x0499, 0x1509, /* Steinberg UR22 */
  1939. QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  1940. DEVICE_FLG(0x0499, 0x3108, /* Yamaha YIT-W12TX */
  1941. QUIRK_FLAG_GET_SAMPLE_RATE),
  1942. DEVICE_FLG(0x04d8, 0xfeea, /* Benchmark DAC1 Pre */
  1943. QUIRK_FLAG_GET_SAMPLE_RATE),
  1944. DEVICE_FLG(0x04e8, 0xa051, /* Samsung USBC Headset (AKG) */
  1945. QUIRK_FLAG_SKIP_CLOCK_SELECTOR | QUIRK_FLAG_CTL_MSG_DELAY_5M),
  1946. DEVICE_FLG(0x0525, 0xa4ad, /* Hamedal C20 usb camero */
  1947. QUIRK_FLAG_IFACE_SKIP_CLOSE),
  1948. DEVICE_FLG(0x054c, 0x0b8c, /* Sony WALKMAN NW-A45 DAC */
  1949. QUIRK_FLAG_SET_IFACE_FIRST),
  1950. DEVICE_FLG(0x0556, 0x0014, /* Phoenix Audio TMX320VC */
  1951. QUIRK_FLAG_GET_SAMPLE_RATE),
  1952. DEVICE_FLG(0x05a3, 0x9420, /* ELP HD USB Camera */
  1953. QUIRK_FLAG_GET_SAMPLE_RATE),
  1954. DEVICE_FLG(0x05a7, 0x1020, /* Bose Companion 5 */
  1955. QUIRK_FLAG_GET_SAMPLE_RATE),
  1956. DEVICE_FLG(0x05e1, 0x0408, /* Syntek STK1160 */
  1957. QUIRK_FLAG_ALIGN_TRANSFER),
  1958. DEVICE_FLG(0x05e1, 0x0480, /* Hauppauge Woodbury */
  1959. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  1960. DEVICE_FLG(0x0644, 0x8043, /* TEAC UD-501/UD-501V2/UD-503/NT-503 */
  1961. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
  1962. QUIRK_FLAG_IFACE_DELAY),
  1963. DEVICE_FLG(0x0644, 0x8044, /* Esoteric D-05X */
  1964. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
  1965. QUIRK_FLAG_IFACE_DELAY),
  1966. DEVICE_FLG(0x0644, 0x804a, /* TEAC UD-301 */
  1967. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
  1968. QUIRK_FLAG_IFACE_DELAY),
  1969. DEVICE_FLG(0x0644, 0x805f, /* TEAC Model 12 */
  1970. QUIRK_FLAG_FORCE_IFACE_RESET),
  1971. DEVICE_FLG(0x0644, 0x806b, /* TEAC UD-701 */
  1972. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY |
  1973. QUIRK_FLAG_IFACE_DELAY),
  1974. DEVICE_FLG(0x06f8, 0xb000, /* Hercules DJ Console (Windows Edition) */
  1975. QUIRK_FLAG_IGNORE_CTL_ERROR),
  1976. DEVICE_FLG(0x06f8, 0xd002, /* Hercules DJ Console (Macintosh Edition) */
  1977. QUIRK_FLAG_IGNORE_CTL_ERROR),
  1978. DEVICE_FLG(0x0711, 0x5800, /* MCT Trigger 5 USB-to-HDMI */
  1979. QUIRK_FLAG_GET_SAMPLE_RATE),
  1980. DEVICE_FLG(0x074d, 0x3553, /* Outlaw RR2150 (Micronas UAC3553B) */
  1981. QUIRK_FLAG_GET_SAMPLE_RATE),
  1982. DEVICE_FLG(0x0763, 0x2030, /* M-Audio Fast Track C400 */
  1983. QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  1984. DEVICE_FLG(0x0763, 0x2031, /* M-Audio Fast Track C600 */
  1985. QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  1986. DEVICE_FLG(0x07fd, 0x000b, /* MOTU M Series 2nd hardware revision */
  1987. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  1988. DEVICE_FLG(0x08bb, 0x2702, /* LineX FM Transmitter */
  1989. QUIRK_FLAG_IGNORE_CTL_ERROR),
  1990. DEVICE_FLG(0x0951, 0x16ad, /* Kingston HyperX */
  1991. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  1992. DEVICE_FLG(0x0b0e, 0x0349, /* Jabra 550a */
  1993. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  1994. DEVICE_FLG(0x0c45, 0x6340, /* Sonix HD USB Camera */
  1995. QUIRK_FLAG_GET_SAMPLE_RATE),
  1996. DEVICE_FLG(0x0d8c, 0x0014, /* USB Audio Device */
  1997. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  1998. DEVICE_FLG(0x0ecb, 0x205c, /* JBL Quantum610 Wireless */
  1999. QUIRK_FLAG_FIXED_RATE),
  2000. DEVICE_FLG(0x0ecb, 0x2069, /* JBL Quantum810 Wireless */
  2001. QUIRK_FLAG_FIXED_RATE),
  2002. DEVICE_FLG(0x0fd9, 0x0008, /* Hauppauge HVR-950Q */
  2003. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2004. DEVICE_FLG(0x1224, 0x2a25, /* Jieli Technology USB PHY 2.0 */
  2005. QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
  2006. DEVICE_FLG(0x1395, 0x740a, /* Sennheiser DECT */
  2007. QUIRK_FLAG_GET_SAMPLE_RATE),
  2008. DEVICE_FLG(0x1397, 0x0507, /* Behringer UMC202HD */
  2009. QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  2010. DEVICE_FLG(0x1397, 0x0508, /* Behringer UMC204HD */
  2011. QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  2012. DEVICE_FLG(0x1397, 0x0509, /* Behringer UMC404HD */
  2013. QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  2014. DEVICE_FLG(0x13e5, 0x0001, /* Serato Phono */
  2015. QUIRK_FLAG_IGNORE_CTL_ERROR),
  2016. DEVICE_FLG(0x154e, 0x1002, /* Denon DCD-1500RE */
  2017. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
  2018. DEVICE_FLG(0x154e, 0x1003, /* Denon DA-300USB */
  2019. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
  2020. DEVICE_FLG(0x154e, 0x3005, /* Marantz HD-DAC1 */
  2021. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
  2022. DEVICE_FLG(0x154e, 0x3006, /* Marantz SA-14S1 */
  2023. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
  2024. DEVICE_FLG(0x154e, 0x300b, /* Marantz SA-KI RUBY / SA-12 */
  2025. QUIRK_FLAG_DSD_RAW),
  2026. DEVICE_FLG(0x154e, 0x500e, /* Denon DN-X1600 */
  2027. QUIRK_FLAG_IGNORE_CLOCK_SOURCE),
  2028. DEVICE_FLG(0x1686, 0x00dd, /* Zoom R16/24 */
  2029. QUIRK_FLAG_TX_LENGTH | QUIRK_FLAG_CTL_MSG_DELAY_1M),
  2030. DEVICE_FLG(0x17aa, 0x1046, /* Lenovo ThinkStation P620 Rear Line-in, Line-out and Microphone */
  2031. QUIRK_FLAG_DISABLE_AUTOSUSPEND),
  2032. DEVICE_FLG(0x17aa, 0x104d, /* Lenovo ThinkStation P620 Internal Speaker + Front Headset */
  2033. QUIRK_FLAG_DISABLE_AUTOSUSPEND),
  2034. DEVICE_FLG(0x1852, 0x5062, /* Luxman D-08u */
  2035. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
  2036. DEVICE_FLG(0x1852, 0x5065, /* Luxman DA-06 */
  2037. QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
  2038. DEVICE_FLG(0x1901, 0x0191, /* GE B850V3 CP2114 audio interface */
  2039. QUIRK_FLAG_GET_SAMPLE_RATE),
  2040. DEVICE_FLG(0x19f7, 0x0035, /* RODE NT-USB+ */
  2041. QUIRK_FLAG_GET_SAMPLE_RATE),
  2042. DEVICE_FLG(0x1bcf, 0x2281, /* HD Webcam */
  2043. QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
  2044. DEVICE_FLG(0x1bcf, 0x2283, /* NexiGo N930AF FHD Webcam */
  2045. QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_MIC_RES_16),
  2046. DEVICE_FLG(0x2040, 0x7200, /* Hauppauge HVR-950Q */
  2047. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2048. DEVICE_FLG(0x2040, 0x7201, /* Hauppauge HVR-950Q-MXL */
  2049. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2050. DEVICE_FLG(0x2040, 0x7210, /* Hauppauge HVR-950Q */
  2051. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2052. DEVICE_FLG(0x2040, 0x7211, /* Hauppauge HVR-950Q-MXL */
  2053. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2054. DEVICE_FLG(0x2040, 0x7213, /* Hauppauge HVR-950Q */
  2055. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2056. DEVICE_FLG(0x2040, 0x7217, /* Hauppauge HVR-950Q */
  2057. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2058. DEVICE_FLG(0x2040, 0x721b, /* Hauppauge HVR-950Q */
  2059. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2060. DEVICE_FLG(0x2040, 0x721e, /* Hauppauge HVR-950Q */
  2061. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2062. DEVICE_FLG(0x2040, 0x721f, /* Hauppauge HVR-950Q */
  2063. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2064. DEVICE_FLG(0x2040, 0x7240, /* Hauppauge HVR-850 */
  2065. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2066. DEVICE_FLG(0x2040, 0x7260, /* Hauppauge HVR-950Q */
  2067. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2068. DEVICE_FLG(0x2040, 0x7270, /* Hauppauge HVR-950Q */
  2069. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2070. DEVICE_FLG(0x2040, 0x7280, /* Hauppauge HVR-950Q */
  2071. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2072. DEVICE_FLG(0x2040, 0x7281, /* Hauppauge HVR-950Q-MXL */
  2073. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2074. DEVICE_FLG(0x2040, 0x8200, /* Hauppauge Woodbury */
  2075. QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
  2076. DEVICE_FLG(0x21b4, 0x0081, /* AudioQuest DragonFly */
  2077. QUIRK_FLAG_GET_SAMPLE_RATE),
  2078. DEVICE_FLG(0x21b4, 0x0230, /* Ayre QB-9 Twenty */
  2079. QUIRK_FLAG_DSD_RAW),
  2080. DEVICE_FLG(0x21b4, 0x0232, /* Ayre QX-5 Twenty */
  2081. QUIRK_FLAG_DSD_RAW),
  2082. DEVICE_FLG(0x2522, 0x0007, /* LH Labs Geek Out HD Audio 1V5 */
  2083. QUIRK_FLAG_SET_IFACE_FIRST),
  2084. DEVICE_FLG(0x262a, 0x9302, /* ddHiFi TC44C */
  2085. QUIRK_FLAG_DSD_RAW),
  2086. DEVICE_FLG(0x2708, 0x0002, /* Audient iD14 */
  2087. QUIRK_FLAG_IGNORE_CTL_ERROR),
  2088. DEVICE_FLG(0x2912, 0x30c8, /* Audioengine D1 */
  2089. QUIRK_FLAG_GET_SAMPLE_RATE),
  2090. DEVICE_FLG(0x2b53, 0x0023, /* Fiero SC-01 (firmware v1.0.0 @ 48 kHz) */
  2091. QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  2092. DEVICE_FLG(0x2b53, 0x0024, /* Fiero SC-01 (firmware v1.0.0 @ 96 kHz) */
  2093. QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  2094. DEVICE_FLG(0x2b53, 0x0031, /* Fiero SC-01 (firmware v1.1.0) */
  2095. QUIRK_FLAG_GENERIC_IMPLICIT_FB),
  2096. DEVICE_FLG(0x2d95, 0x8011, /* VIVO USB-C HEADSET */
  2097. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  2098. DEVICE_FLG(0x2d95, 0x8021, /* VIVO USB-C-XE710 HEADSET */
  2099. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  2100. DEVICE_FLG(0x2fc6, 0xf0b7, /* iBasso DC07 Pro */
  2101. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  2102. DEVICE_FLG(0x30be, 0x0101, /* Schiit Hel */
  2103. QUIRK_FLAG_IGNORE_CTL_ERROR),
  2104. DEVICE_FLG(0x413c, 0xa506, /* Dell AE515 sound bar */
  2105. QUIRK_FLAG_GET_SAMPLE_RATE),
  2106. DEVICE_FLG(0x534d, 0x0021, /* MacroSilicon MS2100/MS2106 */
  2107. QUIRK_FLAG_ALIGN_TRANSFER),
  2108. DEVICE_FLG(0x534d, 0x2109, /* MacroSilicon MS2109 */
  2109. QUIRK_FLAG_ALIGN_TRANSFER),
  2110. /* Vendor matches */
  2111. VENDOR_FLG(0x045e, /* MS Lifecam */
  2112. QUIRK_FLAG_GET_SAMPLE_RATE),
  2113. VENDOR_FLG(0x046d, /* Logitech */
  2114. QUIRK_FLAG_CTL_MSG_DELAY_1M),
  2115. VENDOR_FLG(0x047f, /* Plantronics */
  2116. QUIRK_FLAG_GET_SAMPLE_RATE | QUIRK_FLAG_CTL_MSG_DELAY),
  2117. VENDOR_FLG(0x0644, /* TEAC Corp. */
  2118. QUIRK_FLAG_CTL_MSG_DELAY | QUIRK_FLAG_IFACE_DELAY),
  2119. VENDOR_FLG(0x07fd, /* MOTU */
  2120. QUIRK_FLAG_VALIDATE_RATES),
  2121. VENDOR_FLG(0x1235, /* Focusrite Novation */
  2122. QUIRK_FLAG_VALIDATE_RATES),
  2123. VENDOR_FLG(0x1511, /* AURALiC */
  2124. QUIRK_FLAG_DSD_RAW),
  2125. VENDOR_FLG(0x152a, /* Thesycon devices */
  2126. QUIRK_FLAG_DSD_RAW),
  2127. VENDOR_FLG(0x18d1, /* iBasso devices */
  2128. QUIRK_FLAG_DSD_RAW),
  2129. VENDOR_FLG(0x1de7, /* Phoenix Audio */
  2130. QUIRK_FLAG_GET_SAMPLE_RATE),
  2131. VENDOR_FLG(0x20b1, /* XMOS based devices */
  2132. QUIRK_FLAG_DSD_RAW),
  2133. VENDOR_FLG(0x21ed, /* Accuphase Laboratory */
  2134. QUIRK_FLAG_DSD_RAW),
  2135. VENDOR_FLG(0x22d9, /* Oppo */
  2136. QUIRK_FLAG_DSD_RAW),
  2137. VENDOR_FLG(0x23ba, /* Playback Design */
  2138. QUIRK_FLAG_CTL_MSG_DELAY | QUIRK_FLAG_IFACE_DELAY |
  2139. QUIRK_FLAG_DSD_RAW),
  2140. VENDOR_FLG(0x25ce, /* Mytek devices */
  2141. QUIRK_FLAG_DSD_RAW),
  2142. VENDOR_FLG(0x278b, /* Rotel? */
  2143. QUIRK_FLAG_DSD_RAW),
  2144. VENDOR_FLG(0x292b, /* Gustard/Ess based devices */
  2145. QUIRK_FLAG_DSD_RAW),
  2146. VENDOR_FLG(0x2972, /* FiiO devices */
  2147. QUIRK_FLAG_DSD_RAW),
  2148. VENDOR_FLG(0x2ab6, /* T+A devices */
  2149. QUIRK_FLAG_DSD_RAW),
  2150. VENDOR_FLG(0x2afd, /* McIntosh Laboratory, Inc. */
  2151. QUIRK_FLAG_DSD_RAW),
  2152. VENDOR_FLG(0x2d87, /* Cayin device */
  2153. QUIRK_FLAG_DSD_RAW),
  2154. VENDOR_FLG(0x3336, /* HEM devices */
  2155. QUIRK_FLAG_DSD_RAW),
  2156. VENDOR_FLG(0x3353, /* Khadas devices */
  2157. QUIRK_FLAG_DSD_RAW),
  2158. VENDOR_FLG(0x35f4, /* MSB Technology */
  2159. QUIRK_FLAG_DSD_RAW),
  2160. VENDOR_FLG(0x3842, /* EVGA */
  2161. QUIRK_FLAG_DSD_RAW),
  2162. VENDOR_FLG(0xc502, /* HiBy devices */
  2163. QUIRK_FLAG_DSD_RAW),
  2164. {} /* terminator */
  2165. };
  2166. void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
  2167. {
  2168. const struct usb_audio_quirk_flags_table *p;
  2169. for (p = quirk_flags_table; p->id; p++) {
  2170. if (chip->usb_id == p->id ||
  2171. (!USB_ID_PRODUCT(p->id) &&
  2172. USB_ID_VENDOR(chip->usb_id) == USB_ID_VENDOR(p->id))) {
  2173. usb_audio_dbg(chip,
  2174. "Set quirk_flags 0x%x for device %04x:%04x\n",
  2175. p->flags, USB_ID_VENDOR(chip->usb_id),
  2176. USB_ID_PRODUCT(chip->usb_id));
  2177. chip->quirk_flags |= p->flags;
  2178. return;
  2179. }
  2180. }
  2181. }