quirks.c 23 KB

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