quirks.c 17 KB

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