quirks.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #include <linux/init.h>
  17. #include <linux/slab.h>
  18. #include <linux/usb.h>
  19. #include <linux/usb/audio.h>
  20. #include <sound/control.h>
  21. #include <sound/core.h>
  22. #include <sound/info.h>
  23. #include <sound/pcm.h>
  24. #include "usbaudio.h"
  25. #include "card.h"
  26. #include "mixer.h"
  27. #include "mixer_quirks.h"
  28. #include "midi.h"
  29. #include "quirks.h"
  30. #include "helper.h"
  31. #include "endpoint.h"
  32. #include "pcm.h"
  33. #include "clock.h"
  34. /*
  35. * handle the quirks for the contained interfaces
  36. */
  37. static int create_composite_quirk(struct snd_usb_audio *chip,
  38. struct usb_interface *iface,
  39. struct usb_driver *driver,
  40. const struct snd_usb_audio_quirk *quirk)
  41. {
  42. int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
  43. int err;
  44. for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) {
  45. iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
  46. if (!iface)
  47. continue;
  48. if (quirk->ifnum != probed_ifnum &&
  49. usb_interface_claimed(iface))
  50. continue;
  51. err = snd_usb_create_quirk(chip, iface, driver, quirk);
  52. if (err < 0)
  53. return err;
  54. if (quirk->ifnum != probed_ifnum)
  55. usb_driver_claim_interface(driver, iface, (void *)-1L);
  56. }
  57. return 0;
  58. }
  59. static int ignore_interface_quirk(struct snd_usb_audio *chip,
  60. struct usb_interface *iface,
  61. struct usb_driver *driver,
  62. const struct snd_usb_audio_quirk *quirk)
  63. {
  64. return 0;
  65. }
  66. /*
  67. * Allow alignment on audio sub-slot (channel samples) rather than
  68. * on audio slots (audio frames)
  69. */
  70. static int create_align_transfer_quirk(struct snd_usb_audio *chip,
  71. struct usb_interface *iface,
  72. struct usb_driver *driver,
  73. const struct snd_usb_audio_quirk *quirk)
  74. {
  75. chip->txfr_quirk = 1;
  76. return 1; /* Continue with creating streams and mixer */
  77. }
  78. static int create_any_midi_quirk(struct snd_usb_audio *chip,
  79. struct usb_interface *intf,
  80. struct usb_driver *driver,
  81. const struct snd_usb_audio_quirk *quirk)
  82. {
  83. return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
  84. }
  85. /*
  86. * create a stream for an interface with proper descriptors
  87. */
  88. static int create_standard_audio_quirk(struct snd_usb_audio *chip,
  89. struct usb_interface *iface,
  90. struct usb_driver *driver,
  91. const struct snd_usb_audio_quirk *quirk)
  92. {
  93. struct usb_host_interface *alts;
  94. struct usb_interface_descriptor *altsd;
  95. int err;
  96. alts = &iface->altsetting[0];
  97. altsd = get_iface_desc(alts);
  98. err = snd_usb_parse_audio_endpoints(chip, altsd->bInterfaceNumber);
  99. if (err < 0) {
  100. snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
  101. altsd->bInterfaceNumber, err);
  102. return err;
  103. }
  104. /* reset the current interface */
  105. usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
  106. return 0;
  107. }
  108. /*
  109. * create a stream for an endpoint/altsetting without proper descriptors
  110. */
  111. static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
  112. struct usb_interface *iface,
  113. struct usb_driver *driver,
  114. const struct snd_usb_audio_quirk *quirk)
  115. {
  116. struct audioformat *fp;
  117. struct usb_host_interface *alts;
  118. int stream, err;
  119. unsigned *rate_table = NULL;
  120. fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
  121. if (! fp) {
  122. snd_printk(KERN_ERR "cannot memdup\n");
  123. return -ENOMEM;
  124. }
  125. if (fp->nr_rates > 0) {
  126. rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
  127. if (!rate_table) {
  128. kfree(fp);
  129. return -ENOMEM;
  130. }
  131. memcpy(rate_table, fp->rate_table, sizeof(int) * fp->nr_rates);
  132. fp->rate_table = rate_table;
  133. }
  134. stream = (fp->endpoint & USB_DIR_IN)
  135. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  136. err = snd_usb_add_audio_endpoint(chip, stream, fp);
  137. if (err < 0) {
  138. kfree(fp);
  139. kfree(rate_table);
  140. return err;
  141. }
  142. if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
  143. fp->altset_idx >= iface->num_altsetting) {
  144. kfree(fp);
  145. kfree(rate_table);
  146. return -EINVAL;
  147. }
  148. alts = &iface->altsetting[fp->altset_idx];
  149. fp->datainterval = snd_usb_parse_datainterval(chip, alts);
  150. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  151. usb_set_interface(chip->dev, fp->iface, 0);
  152. snd_usb_init_pitch(chip, fp->iface, alts, fp);
  153. snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
  154. return 0;
  155. }
  156. /*
  157. * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
  158. * The only way to detect the sample rate is by looking at wMaxPacketSize.
  159. */
  160. static int create_uaxx_quirk(struct snd_usb_audio *chip,
  161. struct usb_interface *iface,
  162. struct usb_driver *driver,
  163. const struct snd_usb_audio_quirk *quirk)
  164. {
  165. static const struct audioformat ua_format = {
  166. .formats = SNDRV_PCM_FMTBIT_S24_3LE,
  167. .channels = 2,
  168. .fmt_type = UAC_FORMAT_TYPE_I,
  169. .altsetting = 1,
  170. .altset_idx = 1,
  171. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  172. };
  173. struct usb_host_interface *alts;
  174. struct usb_interface_descriptor *altsd;
  175. struct audioformat *fp;
  176. int stream, err;
  177. /* both PCM and MIDI interfaces have 2 or more altsettings */
  178. if (iface->num_altsetting < 2)
  179. return -ENXIO;
  180. alts = &iface->altsetting[1];
  181. altsd = get_iface_desc(alts);
  182. if (altsd->bNumEndpoints == 2) {
  183. static const struct snd_usb_midi_endpoint_info ua700_ep = {
  184. .out_cables = 0x0003,
  185. .in_cables = 0x0003
  186. };
  187. static const struct snd_usb_audio_quirk ua700_quirk = {
  188. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  189. .data = &ua700_ep
  190. };
  191. static const struct snd_usb_midi_endpoint_info uaxx_ep = {
  192. .out_cables = 0x0001,
  193. .in_cables = 0x0001
  194. };
  195. static const struct snd_usb_audio_quirk uaxx_quirk = {
  196. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  197. .data = &uaxx_ep
  198. };
  199. const struct snd_usb_audio_quirk *quirk =
  200. chip->usb_id == USB_ID(0x0582, 0x002b)
  201. ? &ua700_quirk : &uaxx_quirk;
  202. return snd_usbmidi_create(chip->card, iface,
  203. &chip->midi_list, quirk);
  204. }
  205. if (altsd->bNumEndpoints != 1)
  206. return -ENXIO;
  207. fp = kmalloc(sizeof(*fp), GFP_KERNEL);
  208. if (!fp)
  209. return -ENOMEM;
  210. memcpy(fp, &ua_format, sizeof(*fp));
  211. fp->iface = altsd->bInterfaceNumber;
  212. fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
  213. fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
  214. fp->datainterval = 0;
  215. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  216. switch (fp->maxpacksize) {
  217. case 0x120:
  218. fp->rate_max = fp->rate_min = 44100;
  219. break;
  220. case 0x138:
  221. case 0x140:
  222. fp->rate_max = fp->rate_min = 48000;
  223. break;
  224. case 0x258:
  225. case 0x260:
  226. fp->rate_max = fp->rate_min = 96000;
  227. break;
  228. default:
  229. snd_printk(KERN_ERR "unknown sample rate\n");
  230. kfree(fp);
  231. return -ENXIO;
  232. }
  233. stream = (fp->endpoint & USB_DIR_IN)
  234. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  235. err = snd_usb_add_audio_endpoint(chip, stream, fp);
  236. if (err < 0) {
  237. kfree(fp);
  238. return err;
  239. }
  240. usb_set_interface(chip->dev, fp->iface, 0);
  241. return 0;
  242. }
  243. /*
  244. * Create a standard mixer for the specified interface.
  245. */
  246. static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
  247. struct usb_interface *iface,
  248. struct usb_driver *driver,
  249. const struct snd_usb_audio_quirk *quirk)
  250. {
  251. if (quirk->ifnum < 0)
  252. return 0;
  253. return snd_usb_create_mixer(chip, quirk->ifnum, 0);
  254. }
  255. /*
  256. * audio-interface quirks
  257. *
  258. * returns zero if no standard audio/MIDI parsing is needed.
  259. * returns a positive value if standard audio/midi interfaces are parsed
  260. * after this.
  261. * returns a negative value at error.
  262. */
  263. int snd_usb_create_quirk(struct snd_usb_audio *chip,
  264. struct usb_interface *iface,
  265. struct usb_driver *driver,
  266. const struct snd_usb_audio_quirk *quirk)
  267. {
  268. typedef int (*quirk_func_t)(struct snd_usb_audio *,
  269. struct usb_interface *,
  270. struct usb_driver *,
  271. const struct snd_usb_audio_quirk *);
  272. static const quirk_func_t quirk_funcs[] = {
  273. [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
  274. [QUIRK_COMPOSITE] = create_composite_quirk,
  275. [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
  276. [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
  277. [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
  278. [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
  279. [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
  280. [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
  281. [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
  282. [QUIRK_MIDI_CME] = create_any_midi_quirk,
  283. [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
  284. [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
  285. [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
  286. [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
  287. [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
  288. [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
  289. };
  290. if (quirk->type < QUIRK_TYPE_COUNT) {
  291. return quirk_funcs[quirk->type](chip, iface, driver, quirk);
  292. } else {
  293. snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
  294. return -ENXIO;
  295. }
  296. }
  297. /*
  298. * boot quirks
  299. */
  300. #define EXTIGY_FIRMWARE_SIZE_OLD 794
  301. #define EXTIGY_FIRMWARE_SIZE_NEW 483
  302. static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
  303. {
  304. struct usb_host_config *config = dev->actconfig;
  305. int err;
  306. if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
  307. le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
  308. snd_printdd("sending Extigy boot sequence...\n");
  309. /* Send message to force it to reconnect with full interface. */
  310. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
  311. 0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000);
  312. if (err < 0) snd_printdd("error sending boot message: %d\n", err);
  313. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  314. &dev->descriptor, sizeof(dev->descriptor));
  315. config = dev->actconfig;
  316. if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
  317. err = usb_reset_configuration(dev);
  318. if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
  319. snd_printdd("extigy_boot: new boot length = %d\n",
  320. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  321. return -ENODEV; /* quit this anyway */
  322. }
  323. return 0;
  324. }
  325. static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
  326. {
  327. u8 buf = 1;
  328. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
  329. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  330. 0, 0, &buf, 1, 1000);
  331. if (buf == 0) {
  332. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
  333. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  334. 1, 2000, NULL, 0, 1000);
  335. return -ENODEV;
  336. }
  337. return 0;
  338. }
  339. /*
  340. * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
  341. * documented in the device's data sheet.
  342. */
  343. static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
  344. {
  345. u8 buf[4];
  346. buf[0] = 0x20;
  347. buf[1] = value & 0xff;
  348. buf[2] = (value >> 8) & 0xff;
  349. buf[3] = reg;
  350. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
  351. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
  352. 0, 0, &buf, 4, 1000);
  353. }
  354. static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
  355. {
  356. /*
  357. * Enable line-out driver mode, set headphone source to front
  358. * channels, enable stereo mic.
  359. */
  360. return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
  361. }
  362. /*
  363. * C-Media CM6206 is based on CM106 with two additional
  364. * registers that are not documented in the data sheet.
  365. * Values here are chosen based on sniffing USB traffic
  366. * under Windows.
  367. */
  368. static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
  369. {
  370. int err, reg;
  371. int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
  372. for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
  373. err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
  374. if (err < 0)
  375. return err;
  376. }
  377. return err;
  378. }
  379. /*
  380. * This call will put the synth in "USB send" mode, i.e it will send MIDI
  381. * messages through USB (this is disabled at startup). The synth will
  382. * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
  383. * sign on its LCD. Values here are chosen based on sniffing USB traffic
  384. * under Windows.
  385. */
  386. static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
  387. {
  388. int err, actual_length;
  389. /* "midi send" enable */
  390. static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
  391. void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
  392. if (!buf)
  393. return -ENOMEM;
  394. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
  395. ARRAY_SIZE(seq), &actual_length, 1000);
  396. kfree(buf);
  397. if (err < 0)
  398. return err;
  399. return 0;
  400. }
  401. /*
  402. * Some sound cards from Native Instruments are in fact compliant to the USB
  403. * audio standard of version 2 and other approved USB standards, even though
  404. * they come up as vendor-specific device when first connected.
  405. *
  406. * However, they can be told to come up with a new set of descriptors
  407. * upon their next enumeration, and the interfaces announced by the new
  408. * descriptors will then be handled by the kernel's class drivers. As the
  409. * product ID will also change, no further checks are required.
  410. */
  411. static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
  412. {
  413. int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  414. 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  415. cpu_to_le16(1), 0, NULL, 0, 1000);
  416. if (ret < 0)
  417. return ret;
  418. usb_reset_device(dev);
  419. /* return -EAGAIN, so the creation of an audio interface for this
  420. * temporary device is aborted. The device will reconnect with a
  421. * new product ID */
  422. return -EAGAIN;
  423. }
  424. /*
  425. * Setup quirks
  426. */
  427. #define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */
  428. #define AUDIOPHILE_SET_DTS 0x02 /* if set, enable DTS Digital Output */
  429. #define AUDIOPHILE_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
  430. #define AUDIOPHILE_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
  431. #define AUDIOPHILE_SET_DI 0x10 /* if set, enable Digital Input */
  432. #define AUDIOPHILE_SET_MASK 0x1F /* bit mask for setup value */
  433. #define AUDIOPHILE_SET_24B_48K_DI 0x19 /* value for 24bits+48KHz+Digital Input */
  434. #define AUDIOPHILE_SET_24B_48K_NOTDI 0x09 /* value for 24bits+48KHz+No Digital Input */
  435. #define AUDIOPHILE_SET_16B_48K_DI 0x11 /* value for 16bits+48KHz+Digital Input */
  436. #define AUDIOPHILE_SET_16B_48K_NOTDI 0x01 /* value for 16bits+48KHz+No Digital Input */
  437. static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
  438. int iface,
  439. int altno)
  440. {
  441. /* Reset ALL ifaces to 0 altsetting.
  442. * Call it for every possible altsetting of every interface.
  443. */
  444. usb_set_interface(chip->dev, iface, 0);
  445. if (chip->setup & AUDIOPHILE_SET) {
  446. if ((chip->setup & AUDIOPHILE_SET_DTS)
  447. && altno != 6)
  448. return 1; /* skip this altsetting */
  449. if ((chip->setup & AUDIOPHILE_SET_96K)
  450. && altno != 1)
  451. return 1; /* skip this altsetting */
  452. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  453. AUDIOPHILE_SET_24B_48K_DI && altno != 2)
  454. return 1; /* skip this altsetting */
  455. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  456. AUDIOPHILE_SET_24B_48K_NOTDI && altno != 3)
  457. return 1; /* skip this altsetting */
  458. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  459. AUDIOPHILE_SET_16B_48K_DI && altno != 4)
  460. return 1; /* skip this altsetting */
  461. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  462. AUDIOPHILE_SET_16B_48K_NOTDI && altno != 5)
  463. return 1; /* skip this altsetting */
  464. }
  465. return 0; /* keep this altsetting */
  466. }
  467. int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
  468. int iface,
  469. int altno)
  470. {
  471. /* audiophile usb: skip altsets incompatible with device_setup */
  472. if (chip->usb_id == USB_ID(0x0763, 0x2003))
  473. return audiophile_skip_setting_quirk(chip, iface, altno);
  474. return 0;
  475. }
  476. int snd_usb_apply_boot_quirk(struct usb_device *dev,
  477. struct usb_interface *intf,
  478. const struct snd_usb_audio_quirk *quirk)
  479. {
  480. u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
  481. le16_to_cpu(dev->descriptor.idProduct));
  482. switch (id) {
  483. case USB_ID(0x041e, 0x3000):
  484. /* SB Extigy needs special boot-up sequence */
  485. /* if more models come, this will go to the quirk list. */
  486. return snd_usb_extigy_boot_quirk(dev, intf);
  487. case USB_ID(0x041e, 0x3020):
  488. /* SB Audigy 2 NX needs its own boot-up magic, too */
  489. return snd_usb_audigy2nx_boot_quirk(dev);
  490. case USB_ID(0x10f5, 0x0200):
  491. /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
  492. return snd_usb_cm106_boot_quirk(dev);
  493. case USB_ID(0x0d8c, 0x0102):
  494. /* C-Media CM6206 / CM106-Like Sound Device */
  495. case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
  496. return snd_usb_cm6206_boot_quirk(dev);
  497. case USB_ID(0x133e, 0x0815):
  498. /* Access Music VirusTI Desktop */
  499. return snd_usb_accessmusic_boot_quirk(dev);
  500. case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
  501. case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
  502. case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
  503. return snd_usb_nativeinstruments_boot_quirk(dev);
  504. }
  505. return 0;
  506. }
  507. /*
  508. * check if the device uses big-endian samples
  509. */
  510. int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
  511. {
  512. switch (chip->usb_id) {
  513. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
  514. if (fp->endpoint & USB_DIR_IN)
  515. return 1;
  516. break;
  517. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  518. if (chip->setup == 0x00 ||
  519. fp->altsetting==1 || fp->altsetting==2 || fp->altsetting==3)
  520. return 1;
  521. }
  522. return 0;
  523. }
  524. /*
  525. * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
  526. * not for interface.
  527. */
  528. enum {
  529. EMU_QUIRK_SR_44100HZ = 0,
  530. EMU_QUIRK_SR_48000HZ,
  531. EMU_QUIRK_SR_88200HZ,
  532. EMU_QUIRK_SR_96000HZ,
  533. EMU_QUIRK_SR_176400HZ,
  534. EMU_QUIRK_SR_192000HZ
  535. };
  536. static void set_format_emu_quirk(struct snd_usb_substream *subs,
  537. struct audioformat *fmt)
  538. {
  539. unsigned char emu_samplerate_id = 0;
  540. /* When capture is active
  541. * sample rate shouldn't be changed
  542. * by playback substream
  543. */
  544. if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
  545. if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
  546. return;
  547. }
  548. switch (fmt->rate_min) {
  549. case 48000:
  550. emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
  551. break;
  552. case 88200:
  553. emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
  554. break;
  555. case 96000:
  556. emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
  557. break;
  558. case 176400:
  559. emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
  560. break;
  561. case 192000:
  562. emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
  563. break;
  564. default:
  565. emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
  566. break;
  567. }
  568. snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
  569. }
  570. void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
  571. struct audioformat *fmt)
  572. {
  573. switch (subs->stream->chip->usb_id) {
  574. case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
  575. case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
  576. case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
  577. case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
  578. set_format_emu_quirk(subs, fmt);
  579. break;
  580. }
  581. }