quirks.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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_MIDI_AKAI] = create_any_midi_quirk,
  270. [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
  271. [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
  272. [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
  273. [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk
  274. };
  275. if (quirk->type < QUIRK_TYPE_COUNT) {
  276. return quirk_funcs[quirk->type](chip, iface, driver, quirk);
  277. } else {
  278. snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
  279. return -ENXIO;
  280. }
  281. }
  282. /*
  283. * boot quirks
  284. */
  285. #define EXTIGY_FIRMWARE_SIZE_OLD 794
  286. #define EXTIGY_FIRMWARE_SIZE_NEW 483
  287. static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
  288. {
  289. struct usb_host_config *config = dev->actconfig;
  290. int err;
  291. if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
  292. le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
  293. snd_printdd("sending Extigy boot sequence...\n");
  294. /* Send message to force it to reconnect with full interface. */
  295. err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
  296. 0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000);
  297. if (err < 0) snd_printdd("error sending boot message: %d\n", err);
  298. err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  299. &dev->descriptor, sizeof(dev->descriptor));
  300. config = dev->actconfig;
  301. if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
  302. err = usb_reset_configuration(dev);
  303. if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
  304. snd_printdd("extigy_boot: new boot length = %d\n",
  305. le16_to_cpu(get_cfg_desc(config)->wTotalLength));
  306. return -ENODEV; /* quit this anyway */
  307. }
  308. return 0;
  309. }
  310. static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
  311. {
  312. u8 buf = 1;
  313. snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
  314. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  315. 0, 0, &buf, 1, 1000);
  316. if (buf == 0) {
  317. snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
  318. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
  319. 1, 2000, NULL, 0, 1000);
  320. return -ENODEV;
  321. }
  322. return 0;
  323. }
  324. /*
  325. * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
  326. * documented in the device's data sheet.
  327. */
  328. static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
  329. {
  330. u8 buf[4];
  331. buf[0] = 0x20;
  332. buf[1] = value & 0xff;
  333. buf[2] = (value >> 8) & 0xff;
  334. buf[3] = reg;
  335. return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
  336. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
  337. 0, 0, &buf, 4, 1000);
  338. }
  339. static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
  340. {
  341. /*
  342. * Enable line-out driver mode, set headphone source to front
  343. * channels, enable stereo mic.
  344. */
  345. return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
  346. }
  347. /*
  348. * C-Media CM6206 is based on CM106 with two additional
  349. * registers that are not documented in the data sheet.
  350. * Values here are chosen based on sniffing USB traffic
  351. * under Windows.
  352. */
  353. static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
  354. {
  355. int err, reg;
  356. int val[] = {0x200c, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
  357. for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
  358. err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
  359. if (err < 0)
  360. return err;
  361. }
  362. return err;
  363. }
  364. /*
  365. * This call will put the synth in "USB send" mode, i.e it will send MIDI
  366. * messages through USB (this is disabled at startup). The synth will
  367. * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
  368. * sign on its LCD. Values here are chosen based on sniffing USB traffic
  369. * under Windows.
  370. */
  371. static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
  372. {
  373. int err, actual_length;
  374. /* "midi send" enable */
  375. static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
  376. void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
  377. if (!buf)
  378. return -ENOMEM;
  379. err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
  380. ARRAY_SIZE(seq), &actual_length, 1000);
  381. kfree(buf);
  382. if (err < 0)
  383. return err;
  384. return 0;
  385. }
  386. /*
  387. * Setup quirks
  388. */
  389. #define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */
  390. #define AUDIOPHILE_SET_DTS 0x02 /* if set, enable DTS Digital Output */
  391. #define AUDIOPHILE_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
  392. #define AUDIOPHILE_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */
  393. #define AUDIOPHILE_SET_DI 0x10 /* if set, enable Digital Input */
  394. #define AUDIOPHILE_SET_MASK 0x1F /* bit mask for setup value */
  395. #define AUDIOPHILE_SET_24B_48K_DI 0x19 /* value for 24bits+48KHz+Digital Input */
  396. #define AUDIOPHILE_SET_24B_48K_NOTDI 0x09 /* value for 24bits+48KHz+No Digital Input */
  397. #define AUDIOPHILE_SET_16B_48K_DI 0x11 /* value for 16bits+48KHz+Digital Input */
  398. #define AUDIOPHILE_SET_16B_48K_NOTDI 0x01 /* value for 16bits+48KHz+No Digital Input */
  399. static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
  400. int iface,
  401. int altno)
  402. {
  403. /* Reset ALL ifaces to 0 altsetting.
  404. * Call it for every possible altsetting of every interface.
  405. */
  406. usb_set_interface(chip->dev, iface, 0);
  407. if (chip->setup & AUDIOPHILE_SET) {
  408. if ((chip->setup & AUDIOPHILE_SET_DTS)
  409. && altno != 6)
  410. return 1; /* skip this altsetting */
  411. if ((chip->setup & AUDIOPHILE_SET_96K)
  412. && altno != 1)
  413. return 1; /* skip this altsetting */
  414. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  415. AUDIOPHILE_SET_24B_48K_DI && altno != 2)
  416. return 1; /* skip this altsetting */
  417. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  418. AUDIOPHILE_SET_24B_48K_NOTDI && altno != 3)
  419. return 1; /* skip this altsetting */
  420. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  421. AUDIOPHILE_SET_16B_48K_DI && altno != 4)
  422. return 1; /* skip this altsetting */
  423. if ((chip->setup & AUDIOPHILE_SET_MASK) ==
  424. AUDIOPHILE_SET_16B_48K_NOTDI && altno != 5)
  425. return 1; /* skip this altsetting */
  426. }
  427. return 0; /* keep this altsetting */
  428. }
  429. int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
  430. int iface,
  431. int altno)
  432. {
  433. /* audiophile usb: skip altsets incompatible with device_setup */
  434. if (chip->usb_id == USB_ID(0x0763, 0x2003))
  435. return audiophile_skip_setting_quirk(chip, iface, altno);
  436. return 0;
  437. }
  438. int snd_usb_apply_boot_quirk(struct usb_device *dev,
  439. struct usb_interface *intf,
  440. const struct snd_usb_audio_quirk *quirk)
  441. {
  442. u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
  443. le16_to_cpu(dev->descriptor.idProduct));
  444. /* SB Extigy needs special boot-up sequence */
  445. /* if more models come, this will go to the quirk list. */
  446. if (id == USB_ID(0x041e, 0x3000))
  447. return snd_usb_extigy_boot_quirk(dev, intf);
  448. /* SB Audigy 2 NX needs its own boot-up magic, too */
  449. if (id == USB_ID(0x041e, 0x3020))
  450. return snd_usb_audigy2nx_boot_quirk(dev);
  451. /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
  452. if (id == USB_ID(0x10f5, 0x0200))
  453. return snd_usb_cm106_boot_quirk(dev);
  454. /* C-Media CM6206 / CM106-Like Sound Device */
  455. if (id == USB_ID(0x0d8c, 0x0102))
  456. return snd_usb_cm6206_boot_quirk(dev);
  457. /* Access Music VirusTI Desktop */
  458. if (id == USB_ID(0x133e, 0x0815))
  459. return snd_usb_accessmusic_boot_quirk(dev);
  460. return 0;
  461. }
  462. /*
  463. * check if the device uses big-endian samples
  464. */
  465. int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
  466. {
  467. switch (chip->usb_id) {
  468. case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
  469. if (fp->endpoint & USB_DIR_IN)
  470. return 1;
  471. break;
  472. case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
  473. if (chip->setup == 0x00 ||
  474. fp->altsetting==1 || fp->altsetting==2 || fp->altsetting==3)
  475. return 1;
  476. }
  477. return 0;
  478. }
  479. /*
  480. * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device,
  481. * not for interface.
  482. */
  483. enum {
  484. EMU_QUIRK_SR_44100HZ = 0,
  485. EMU_QUIRK_SR_48000HZ,
  486. EMU_QUIRK_SR_88200HZ,
  487. EMU_QUIRK_SR_96000HZ,
  488. EMU_QUIRK_SR_176400HZ,
  489. EMU_QUIRK_SR_192000HZ
  490. };
  491. static void set_format_emu_quirk(struct snd_usb_substream *subs,
  492. struct audioformat *fmt)
  493. {
  494. unsigned char emu_samplerate_id = 0;
  495. /* When capture is active
  496. * sample rate shouldn't be changed
  497. * by playback substream
  498. */
  499. if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
  500. if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
  501. return;
  502. }
  503. switch (fmt->rate_min) {
  504. case 48000:
  505. emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
  506. break;
  507. case 88200:
  508. emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
  509. break;
  510. case 96000:
  511. emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
  512. break;
  513. case 176400:
  514. emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
  515. break;
  516. case 192000:
  517. emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
  518. break;
  519. default:
  520. emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
  521. break;
  522. }
  523. snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
  524. }
  525. void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
  526. struct audioformat *fmt)
  527. {
  528. switch (subs->stream->chip->usb_id) {
  529. case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
  530. case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
  531. case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
  532. set_format_emu_quirk(subs, fmt);
  533. break;
  534. }
  535. }