quirks.c 17 KB

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