quirks.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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. #include "stream.h"
  35. /*
  36. * handle the quirks for the contained interfaces
  37. */
  38. static int create_composite_quirk(struct snd_usb_audio *chip,
  39. struct usb_interface *iface,
  40. struct usb_driver *driver,
  41. const struct snd_usb_audio_quirk *quirk)
  42. {
  43. int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
  44. int err;
  45. for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) {
  46. iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
  47. if (!iface)
  48. continue;
  49. if (quirk->ifnum != probed_ifnum &&
  50. usb_interface_claimed(iface))
  51. continue;
  52. err = snd_usb_create_quirk(chip, iface, driver, quirk);
  53. if (err < 0)
  54. return err;
  55. if (quirk->ifnum != probed_ifnum)
  56. usb_driver_claim_interface(driver, iface, (void *)-1L);
  57. }
  58. return 0;
  59. }
  60. static int ignore_interface_quirk(struct snd_usb_audio *chip,
  61. struct usb_interface *iface,
  62. struct usb_driver *driver,
  63. const struct snd_usb_audio_quirk *quirk)
  64. {
  65. return 0;
  66. }
  67. /*
  68. * Allow alignment on audio sub-slot (channel samples) rather than
  69. * on audio slots (audio frames)
  70. */
  71. static int create_align_transfer_quirk(struct snd_usb_audio *chip,
  72. struct usb_interface *iface,
  73. struct usb_driver *driver,
  74. const struct snd_usb_audio_quirk *quirk)
  75. {
  76. chip->txfr_quirk = 1;
  77. return 1; /* Continue with creating streams and mixer */
  78. }
  79. static int create_any_midi_quirk(struct snd_usb_audio *chip,
  80. struct usb_interface *intf,
  81. struct usb_driver *driver,
  82. const struct snd_usb_audio_quirk *quirk)
  83. {
  84. return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
  85. }
  86. /*
  87. * create a stream for an interface with proper descriptors
  88. */
  89. static int create_standard_audio_quirk(struct snd_usb_audio *chip,
  90. struct usb_interface *iface,
  91. struct usb_driver *driver,
  92. const struct snd_usb_audio_quirk *quirk)
  93. {
  94. struct usb_host_interface *alts;
  95. struct usb_interface_descriptor *altsd;
  96. int err;
  97. alts = &iface->altsetting[0];
  98. altsd = get_iface_desc(alts);
  99. err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
  100. if (err < 0) {
  101. snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
  102. altsd->bInterfaceNumber, err);
  103. return err;
  104. }
  105. /* reset the current interface */
  106. usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
  107. return 0;
  108. }
  109. /*
  110. * create a stream for an endpoint/altsetting without proper descriptors
  111. */
  112. static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
  113. struct usb_interface *iface,
  114. struct usb_driver *driver,
  115. const struct snd_usb_audio_quirk *quirk)
  116. {
  117. struct audioformat *fp;
  118. struct usb_host_interface *alts;
  119. int stream, err;
  120. unsigned *rate_table = NULL;
  121. fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
  122. if (!fp) {
  123. snd_printk(KERN_ERR "cannot memdup\n");
  124. return -ENOMEM;
  125. }
  126. INIT_LIST_HEAD(&fp->list);
  127. if (fp->nr_rates > MAX_NR_RATES) {
  128. kfree(fp);
  129. return -EINVAL;
  130. }
  131. if (fp->nr_rates > 0) {
  132. rate_table = kmemdup(fp->rate_table,
  133. sizeof(int) * fp->nr_rates, GFP_KERNEL);
  134. if (!rate_table) {
  135. kfree(fp);
  136. return -ENOMEM;
  137. }
  138. fp->rate_table = rate_table;
  139. }
  140. stream = (fp->endpoint & USB_DIR_IN)
  141. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  142. err = snd_usb_add_audio_stream(chip, stream, fp);
  143. if (err < 0)
  144. goto error;
  145. if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
  146. fp->altset_idx >= iface->num_altsetting) {
  147. err = -EINVAL;
  148. goto error;
  149. }
  150. alts = &iface->altsetting[fp->altset_idx];
  151. if (get_iface_desc(alts)->bNumEndpoints < 1) {
  152. kfree(fp);
  153. kfree(rate_table);
  154. return -EINVAL;
  155. }
  156. fp->datainterval = snd_usb_parse_datainterval(chip, alts);
  157. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  158. usb_set_interface(chip->dev, fp->iface, 0);
  159. snd_usb_init_pitch(chip, fp->iface, alts, fp);
  160. snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
  161. return 0;
  162. error:
  163. list_del(&fp->list); /* unlink for avoiding double-free */
  164. kfree(fp);
  165. kfree(rate_table);
  166. return err;
  167. }
  168. /*
  169. * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.
  170. * The only way to detect the sample rate is by looking at wMaxPacketSize.
  171. */
  172. static int create_uaxx_quirk(struct snd_usb_audio *chip,
  173. struct usb_interface *iface,
  174. struct usb_driver *driver,
  175. const struct snd_usb_audio_quirk *quirk)
  176. {
  177. static const struct audioformat ua_format = {
  178. .formats = SNDRV_PCM_FMTBIT_S24_3LE,
  179. .channels = 2,
  180. .fmt_type = UAC_FORMAT_TYPE_I,
  181. .altsetting = 1,
  182. .altset_idx = 1,
  183. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  184. };
  185. struct usb_host_interface *alts;
  186. struct usb_interface_descriptor *altsd;
  187. struct audioformat *fp;
  188. int stream, err;
  189. /* both PCM and MIDI interfaces have 2 or more altsettings */
  190. if (iface->num_altsetting < 2)
  191. return -ENXIO;
  192. alts = &iface->altsetting[1];
  193. altsd = get_iface_desc(alts);
  194. if (altsd->bNumEndpoints == 2) {
  195. static const struct snd_usb_midi_endpoint_info ua700_ep = {
  196. .out_cables = 0x0003,
  197. .in_cables = 0x0003
  198. };
  199. static const struct snd_usb_audio_quirk ua700_quirk = {
  200. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  201. .data = &ua700_ep
  202. };
  203. static const struct snd_usb_midi_endpoint_info uaxx_ep = {
  204. .out_cables = 0x0001,
  205. .in_cables = 0x0001
  206. };
  207. static const struct snd_usb_audio_quirk uaxx_quirk = {
  208. .type = QUIRK_MIDI_FIXED_ENDPOINT,
  209. .data = &uaxx_ep
  210. };
  211. const struct snd_usb_audio_quirk *quirk =
  212. chip->usb_id == USB_ID(0x0582, 0x002b)
  213. ? &ua700_quirk : &uaxx_quirk;
  214. return snd_usbmidi_create(chip->card, iface,
  215. &chip->midi_list, quirk);
  216. }
  217. if (altsd->bNumEndpoints != 1)
  218. return -ENXIO;
  219. fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
  220. if (!fp)
  221. return -ENOMEM;
  222. fp->iface = altsd->bInterfaceNumber;
  223. fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
  224. fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
  225. fp->datainterval = 0;
  226. fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
  227. INIT_LIST_HEAD(&fp->list);
  228. switch (fp->maxpacksize) {
  229. case 0x120:
  230. fp->rate_max = fp->rate_min = 44100;
  231. break;
  232. case 0x138:
  233. case 0x140:
  234. fp->rate_max = fp->rate_min = 48000;
  235. break;
  236. case 0x258:
  237. case 0x260:
  238. fp->rate_max = fp->rate_min = 96000;
  239. break;
  240. default:
  241. snd_printk(KERN_ERR "unknown sample rate\n");
  242. kfree(fp);
  243. return -ENXIO;
  244. }
  245. stream = (fp->endpoint & USB_DIR_IN)
  246. ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
  247. err = snd_usb_add_audio_stream(chip, stream, fp);
  248. if (err < 0) {
  249. list_del(&fp->list); /* unlink for avoiding double-free */
  250. kfree(fp);
  251. return err;
  252. }
  253. usb_set_interface(chip->dev, fp->iface, 0);
  254. return 0;
  255. }
  256. /*
  257. * Create a standard mixer for the specified interface.
  258. */
  259. static int create_standard_mixer_quirk(struct snd_usb_audio *chip,
  260. struct usb_interface *iface,
  261. struct usb_driver *driver,
  262. const struct snd_usb_audio_quirk *quirk)
  263. {
  264. if (quirk->ifnum < 0)
  265. return 0;
  266. return snd_usb_create_mixer(chip, quirk->ifnum, 0);
  267. }
  268. /*
  269. * audio-interface quirks
  270. *
  271. * returns zero if no standard audio/MIDI parsing is needed.
  272. * returns a positive value if standard audio/midi interfaces are parsed
  273. * after this.
  274. * returns a negative value at error.
  275. */
  276. int snd_usb_create_quirk(struct snd_usb_audio *chip,
  277. struct usb_interface *iface,
  278. struct usb_driver *driver,
  279. const struct snd_usb_audio_quirk *quirk)
  280. {
  281. typedef int (*quirk_func_t)(struct snd_usb_audio *,
  282. struct usb_interface *,
  283. struct usb_driver *,
  284. const struct snd_usb_audio_quirk *);
  285. static const quirk_func_t quirk_funcs[] = {
  286. [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
  287. [QUIRK_COMPOSITE] = create_composite_quirk,
  288. [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
  289. [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
  290. [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
  291. [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
  292. [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
  293. [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk,
  294. [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
  295. [QUIRK_MIDI_CME] = create_any_midi_quirk,
  296. [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
  297. [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
  298. [QUIRK_MIDI_CH345] = create_any_midi_quirk,
  299. [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
  300. [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
  301. [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
  302. [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk,
  303. [QUIRK_AUDIO_STANDARD_MIXER] = create_standard_mixer_quirk,
  304. };
  305. if (quirk->type < QUIRK_TYPE_COUNT) {
  306. return quirk_funcs[quirk->type](chip, iface, driver, quirk);
  307. } else {
  308. snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
  309. return -ENXIO;
  310. }
  311. }
  312. /*
  313. * boot quirks
  314. */
  315. #define EXTIGY_FIRMWARE_SIZE_OLD 794
  316. #define EXTIGY_FIRMWARE_SIZE_NEW 483
  317. static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
  318. {
  319. struct usb_host_config *config = dev->actconfig;
  320. int err;
  321. if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
  322. le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
  323. snd_printdd("sending Extigy boot sequence...\n");
  324. /* Send message to force it to reconnect with full interface. */
  325. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
  326. 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
  327. if (err < 0) snd_printdd("error sending boot message: %d\n", err);
  328. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  329. &dev->descriptor, sizeof(dev->descriptor));
  330. config = dev->actconfig;
  331. if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
  332. err = usb_reset_configuration(dev);
  333. if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
  334. snd_printdd("extigy_boot: new boot length = %d\n",
  335. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  336. return -ENODEV; /* quit this anyway */
  337. }
  338. return 0;
  339. }
  340. static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
  341. {
  342. u8 buf = 1;
  343. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
  344. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  345. 0, 0, &buf, 1);
  346. if (buf == 0) {
  347. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
  348. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  349. 1, 2000, NULL, 0);
  350. return -ENODEV;
  351. }
  352. return 0;
  353. }
  354. static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
  355. {
  356. int err;
  357. if (dev->actconfig->desc.bConfigurationValue == 1) {
  358. snd_printk(KERN_INFO "usb-audio: "
  359. "Fast Track Pro switching to config #2\n");
  360. /* This function has to be available by the usb core module.
  361. * if it is not avialable the boot quirk has to be left out
  362. * and the configuration has to be set by udev or hotplug
  363. * rules
  364. */
  365. err = usb_driver_set_configuration(dev, 2);
  366. if (err < 0)
  367. snd_printdd("error usb_driver_set_configuration: %d\n",
  368. err);
  369. /* Always return an error, so that we stop creating a device
  370. that will just be destroyed and recreated with a new
  371. configuration */
  372. return -ENODEV;
  373. } else
  374. snd_printk(KERN_INFO "usb-audio: Fast Track Pro config OK\n");
  375. return 0;
  376. }
  377. /*
  378. * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
  379. * documented in the device's data sheet.
  380. */
  381. static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
  382. {
  383. u8 buf[4];
  384. buf[0] = 0x20;
  385. buf[1] = value & 0xff;
  386. buf[2] = (value >> 8) & 0xff;
  387. buf[3] = reg;
  388. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
  389. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
  390. 0, 0, &buf, 4);
  391. }
  392. static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
  393. {
  394. /*
  395. * Enable line-out driver mode, set headphone source to front
  396. * channels, enable stereo mic.
  397. */
  398. return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
  399. }
  400. /*
  401. * C-Media CM6206 is based on CM106 with two additional
  402. * registers that are not documented in the data sheet.
  403. * Values here are chosen based on sniffing USB traffic
  404. * under Windows.
  405. */
  406. static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
  407. {
  408. int err = 0, reg;
  409. int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
  410. for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
  411. err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
  412. if (err < 0)
  413. return err;
  414. }
  415. return err;
  416. }
  417. /*
  418. * This call will put the synth in "USB send" mode, i.e it will send MIDI
  419. * messages through USB (this is disabled at startup). The synth will
  420. * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
  421. * sign on its LCD. Values here are chosen based on sniffing USB traffic
  422. * under Windows.
  423. */
  424. static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
  425. {
  426. int err, actual_length;
  427. /* "midi send" enable */
  428. static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
  429. void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
  430. if (!buf)
  431. return -ENOMEM;
  432. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
  433. ARRAY_SIZE(seq), &actual_length, 1000);
  434. kfree(buf);
  435. if (err < 0)
  436. return err;
  437. return 0;
  438. }
  439. /*
  440. * Some sound cards from Native Instruments are in fact compliant to the USB
  441. * audio standard of version 2 and other approved USB standards, even though
  442. * they come up as vendor-specific device when first connected.
  443. *
  444. * However, they can be told to come up with a new set of descriptors
  445. * upon their next enumeration, and the interfaces announced by the new
  446. * descriptors will then be handled by the kernel's class drivers. As the
  447. * product ID will also change, no further checks are required.
  448. */
  449. static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev)
  450. {
  451. int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  452. 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  453. 1, 0, NULL, 0, 1000);
  454. if (ret < 0)
  455. return ret;
  456. usb_reset_device(dev);
  457. /* return -EAGAIN, so the creation of an audio interface for this
  458. * temporary device is aborted. The device will reconnect with a
  459. * new product ID */
  460. return -EAGAIN;
  461. }
  462. /*
  463. * Setup quirks
  464. */
  465. #define MAUDIO_SET 0x01 /* parse device_setup */
  466. #define MAUDIO_SET_COMPATIBLE 0x80 /* use only "win-compatible" interfaces */
  467. #define MAUDIO_SET_DTS 0x02 /* enable DTS Digital Output */
  468. #define MAUDIO_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
  469. #define MAUDIO_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
  470. #define MAUDIO_SET_DI 0x10 /* enable Digital Input */
  471. #define MAUDIO_SET_MASK 0x1f /* bit mask for setup value */
  472. #define MAUDIO_SET_24B_48K_DI 0x19 /* 24bits+48KHz+Digital Input */
  473. #define MAUDIO_SET_24B_48K_NOTDI 0x09 /* 24bits+48KHz+No Digital Input */
  474. #define MAUDIO_SET_16B_48K_DI 0x11 /* 16bits+48KHz+Digital Input */
  475. #define MAUDIO_SET_16B_48K_NOTDI 0x01 /* 16bits+48KHz+No Digital Input */
  476. static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
  477. int iface, int altno)
  478. {
  479. /* Reset ALL ifaces to 0 altsetting.
  480. * Call it for every possible altsetting of every interface.
  481. */
  482. usb_set_interface(chip->dev, iface, 0);
  483. if (chip->setup & MAUDIO_SET) {
  484. if (chip->setup & MAUDIO_SET_COMPATIBLE) {
  485. if (iface != 1 && iface != 2)
  486. return 1; /* skip all interfaces but 1 and 2 */
  487. } else {
  488. unsigned int mask;
  489. if (iface == 1 || iface == 2)
  490. return 1; /* skip interfaces 1 and 2 */
  491. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  492. return 1; /* skip this altsetting */
  493. mask = chip->setup & MAUDIO_SET_MASK;
  494. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  495. return 1; /* skip this altsetting */
  496. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  497. return 1; /* skip this altsetting */
  498. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 4)
  499. return 1; /* skip this altsetting */
  500. }
  501. }
  502. snd_printdd(KERN_INFO
  503. "using altsetting %d for interface %d config %d\n",
  504. altno, iface, chip->setup);
  505. return 0; /* keep this altsetting */
  506. }
  507. static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
  508. int iface,
  509. int altno)
  510. {
  511. /* Reset ALL ifaces to 0 altsetting.
  512. * Call it for every possible altsetting of every interface.
  513. */
  514. usb_set_interface(chip->dev, iface, 0);
  515. if (chip->setup & MAUDIO_SET) {
  516. unsigned int mask;
  517. if ((chip->setup & MAUDIO_SET_DTS) && altno != 6)
  518. return 1; /* skip this altsetting */
  519. if ((chip->setup & MAUDIO_SET_96K) && altno != 1)
  520. return 1; /* skip this altsetting */
  521. mask = chip->setup & MAUDIO_SET_MASK;
  522. if (mask == MAUDIO_SET_24B_48K_DI && altno != 2)
  523. return 1; /* skip this altsetting */
  524. if (mask == MAUDIO_SET_24B_48K_NOTDI && altno != 3)
  525. return 1; /* skip this altsetting */
  526. if (mask == MAUDIO_SET_16B_48K_DI && altno != 4)
  527. return 1; /* skip this altsetting */
  528. if (mask == MAUDIO_SET_16B_48K_NOTDI && altno != 5)
  529. return 1; /* skip this altsetting */
  530. }
  531. return 0; /* keep this altsetting */
  532. }
  533. static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
  534. int iface, int altno)
  535. {
  536. /* Reset ALL ifaces to 0 altsetting.
  537. * Call it for every possible altsetting of every interface.
  538. */
  539. usb_set_interface(chip->dev, iface, 0);
  540. /* possible configuration where both inputs and only one output is
  541. *used is not supported by the current setup
  542. */
  543. if (chip->setup & (MAUDIO_SET | MAUDIO_SET_24B)) {
  544. if (chip->setup & MAUDIO_SET_96K) {
  545. if (altno != 3 && altno != 6)
  546. return 1;
  547. } else if (chip->setup & MAUDIO_SET_DI) {
  548. if (iface == 4)
  549. return 1; /* no analog input */
  550. if (altno != 2 && altno != 5)
  551. return 1; /* enable only altsets 2 and 5 */
  552. } else {
  553. if (iface == 5)
  554. return 1; /* disable digialt input */
  555. if (altno != 2 && altno != 5)
  556. return 1; /* enalbe only altsets 2 and 5 */
  557. }
  558. } else {
  559. /* keep only 16-Bit mode */
  560. if (altno != 1)
  561. return 1;
  562. }
  563. snd_printdd(KERN_INFO
  564. "using altsetting %d for interface %d config %d\n",
  565. altno, iface, chip->setup);
  566. return 0; /* keep this altsetting */
  567. }
  568. int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
  569. int iface,
  570. int altno)
  571. {
  572. /* audiophile usb: skip altsets incompatible with device_setup */
  573. if (chip->usb_id == USB_ID(0x0763, 0x2003))
  574. return audiophile_skip_setting_quirk(chip, iface, altno);
  575. /* quattro usb: skip altsets incompatible with device_setup */
  576. if (chip->usb_id == USB_ID(0x0763, 0x2001))
  577. return quattro_skip_setting_quirk(chip, iface, altno);
  578. /* fasttrackpro usb: skip altsets incompatible with device_setup */
  579. if (chip->usb_id == USB_ID(0x0763, 0x2012))
  580. return fasttrackpro_skip_setting_quirk(chip, iface, altno);
  581. return 0;
  582. }
  583. int snd_usb_apply_boot_quirk(struct usb_device *dev,
  584. struct usb_interface *intf,
  585. const struct snd_usb_audio_quirk *quirk)
  586. {
  587. u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
  588. le16_to_cpu(dev->descriptor.idProduct));
  589. switch (id) {
  590. case USB_ID(0x041e, 0x3000):
  591. /* SB Extigy needs special boot-up sequence */
  592. /* if more models come, this will go to the quirk list. */
  593. return snd_usb_extigy_boot_quirk(dev, intf);
  594. case USB_ID(0x041e, 0x3020):
  595. /* SB Audigy 2 NX needs its own boot-up magic, too */
  596. return snd_usb_audigy2nx_boot_quirk(dev);
  597. case USB_ID(0x10f5, 0x0200):
  598. /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
  599. return snd_usb_cm106_boot_quirk(dev);
  600. case USB_ID(0x0d8c, 0x0102):
  601. /* C-Media CM6206 / CM106-Like Sound Device */
  602. case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
  603. return snd_usb_cm6206_boot_quirk(dev);
  604. case USB_ID(0x133e, 0x0815):
  605. /* Access Music VirusTI Desktop */
  606. return snd_usb_accessmusic_boot_quirk(dev);
  607. case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
  608. case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
  609. case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
  610. return snd_usb_nativeinstruments_boot_quirk(dev);
  611. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
  612. return snd_usb_fasttrackpro_boot_quirk(dev);
  613. }
  614. return 0;
  615. }
  616. /*
  617. * check if the device uses big-endian samples
  618. */
  619. int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
  620. {
  621. /* it depends on altsetting wether the device is big-endian or not */
  622. switch (chip->usb_id) {
  623. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
  624. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  625. fp->altsetting == 5 || fp->altsetting == 6)
  626. return 1;
  627. break;
  628. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  629. if (chip->setup == 0x00 ||
  630. fp->altsetting == 1 || fp->altsetting == 2 ||
  631. fp->altsetting == 3)
  632. return 1;
  633. break;
  634. case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro */
  635. if (fp->altsetting == 2 || fp->altsetting == 3 ||
  636. fp->altsetting == 5 || fp->altsetting == 6)
  637. return 1;
  638. break;
  639. }
  640. return 0;
  641. }
  642. /*
  643. * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device,
  644. * not for interface.
  645. */
  646. enum {
  647. EMU_QUIRK_SR_44100HZ = 0,
  648. EMU_QUIRK_SR_48000HZ,
  649. EMU_QUIRK_SR_88200HZ,
  650. EMU_QUIRK_SR_96000HZ,
  651. EMU_QUIRK_SR_176400HZ,
  652. EMU_QUIRK_SR_192000HZ
  653. };
  654. static void set_format_emu_quirk(struct snd_usb_substream *subs,
  655. struct audioformat *fmt)
  656. {
  657. unsigned char emu_samplerate_id = 0;
  658. /* When capture is active
  659. * sample rate shouldn't be changed
  660. * by playback substream
  661. */
  662. if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
  663. if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
  664. return;
  665. }
  666. switch (fmt->rate_min) {
  667. case 48000:
  668. emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
  669. break;
  670. case 88200:
  671. emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
  672. break;
  673. case 96000:
  674. emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
  675. break;
  676. case 176400:
  677. emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
  678. break;
  679. case 192000:
  680. emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
  681. break;
  682. default:
  683. emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
  684. break;
  685. }
  686. snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
  687. subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0;
  688. }
  689. void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
  690. struct audioformat *fmt)
  691. {
  692. switch (subs->stream->chip->usb_id) {
  693. case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
  694. case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
  695. case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
  696. case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */
  697. set_format_emu_quirk(subs, fmt);
  698. break;
  699. }
  700. }