quirks.c 71 KB

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