quirks.c 17 KB

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