card.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * (Tentative) USB Audio Driver for ALSA
  3. *
  4. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  5. *
  6. * Many codes borrowed from audio.c by
  7. * Alan Cox (alan@lxorguk.ukuu.org.uk)
  8. * Thomas Sailer (sailer@ife.ee.ethz.ch)
  9. *
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. *
  26. * NOTES:
  27. *
  28. * - async unlink should be used for avoiding the sleep inside lock.
  29. * 2.4.22 usb-uhci seems buggy for async unlinking and results in
  30. * oops. in such a cse, pass async_unlink=0 option.
  31. * - the linked URBs would be preferred but not used so far because of
  32. * the instability of unlinking.
  33. * - type II is not supported properly. there is no device which supports
  34. * this type *correctly*. SB extigy looks as if it supports, but it's
  35. * indeed an AC3 stream packed in SPDIF frames (i.e. no real AC3 stream).
  36. */
  37. #include <linux/bitops.h>
  38. #include <linux/init.h>
  39. #include <linux/list.h>
  40. #include <linux/slab.h>
  41. #include <linux/string.h>
  42. #include <linux/usb.h>
  43. #include <linux/moduleparam.h>
  44. #include <linux/mutex.h>
  45. #include <linux/usb/audio.h>
  46. #include <linux/usb/audio-v2.h>
  47. #include <sound/core.h>
  48. #include <sound/info.h>
  49. #include <sound/pcm.h>
  50. #include <sound/pcm_params.h>
  51. #include <sound/initval.h>
  52. #include "usbaudio.h"
  53. #include "card.h"
  54. #include "midi.h"
  55. #include "mixer.h"
  56. #include "proc.h"
  57. #include "quirks.h"
  58. #include "endpoint.h"
  59. #include "helper.h"
  60. #include "debug.h"
  61. #include "pcm.h"
  62. #include "urb.h"
  63. #include "format.h"
  64. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  65. MODULE_DESCRIPTION("USB Audio");
  66. MODULE_LICENSE("GPL");
  67. MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}");
  68. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  69. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  70. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
  71. /* Vendor/product IDs for this card */
  72. static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
  73. static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
  74. static int nrpacks = 8; /* max. number of packets per urb */
  75. static int async_unlink = 1;
  76. static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
  77. static int ignore_ctl_error;
  78. module_param_array(index, int, NULL, 0444);
  79. MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
  80. module_param_array(id, charp, NULL, 0444);
  81. MODULE_PARM_DESC(id, "ID string for the USB audio adapter.");
  82. module_param_array(enable, bool, NULL, 0444);
  83. MODULE_PARM_DESC(enable, "Enable USB audio adapter.");
  84. module_param_array(vid, int, NULL, 0444);
  85. MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
  86. module_param_array(pid, int, NULL, 0444);
  87. MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
  88. module_param(nrpacks, int, 0644);
  89. MODULE_PARM_DESC(nrpacks, "Max. number of packets per URB.");
  90. module_param(async_unlink, bool, 0444);
  91. MODULE_PARM_DESC(async_unlink, "Use async unlink mode.");
  92. module_param_array(device_setup, int, NULL, 0444);
  93. MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
  94. module_param(ignore_ctl_error, bool, 0444);
  95. MODULE_PARM_DESC(ignore_ctl_error,
  96. "Ignore errors from USB controller for mixer interfaces.");
  97. /*
  98. * we keep the snd_usb_audio_t instances by ourselves for merging
  99. * the all interfaces on the same card as one sound device.
  100. */
  101. static DEFINE_MUTEX(register_mutex);
  102. static struct snd_usb_audio *usb_chip[SNDRV_CARDS];
  103. static struct usb_driver usb_audio_driver;
  104. /*
  105. * disconnect streams
  106. * called from snd_usb_audio_disconnect()
  107. */
  108. static void snd_usb_stream_disconnect(struct list_head *head)
  109. {
  110. int idx;
  111. struct snd_usb_stream *as;
  112. struct snd_usb_substream *subs;
  113. as = list_entry(head, struct snd_usb_stream, list);
  114. for (idx = 0; idx < 2; idx++) {
  115. subs = &as->substream[idx];
  116. if (!subs->num_formats)
  117. continue;
  118. snd_usb_release_substream_urbs(subs, 1);
  119. subs->interface = -1;
  120. }
  121. }
  122. static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
  123. {
  124. struct usb_device *dev = chip->dev;
  125. struct usb_host_interface *alts;
  126. struct usb_interface_descriptor *altsd;
  127. struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
  128. if (!iface) {
  129. snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
  130. dev->devnum, ctrlif, interface);
  131. return -EINVAL;
  132. }
  133. if (usb_interface_claimed(iface)) {
  134. snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n",
  135. dev->devnum, ctrlif, interface);
  136. return -EINVAL;
  137. }
  138. alts = &iface->altsetting[0];
  139. altsd = get_iface_desc(alts);
  140. if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
  141. altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
  142. altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
  143. int err = snd_usbmidi_create(chip->card, iface,
  144. &chip->midi_list, NULL);
  145. if (err < 0) {
  146. snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
  147. dev->devnum, ctrlif, interface);
  148. return -EINVAL;
  149. }
  150. usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
  151. return 0;
  152. }
  153. if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
  154. altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
  155. altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
  156. snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
  157. dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
  158. /* skip non-supported classes */
  159. return -EINVAL;
  160. }
  161. if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
  162. snd_printk(KERN_ERR "low speed audio streaming not supported\n");
  163. return -EINVAL;
  164. }
  165. if (! snd_usb_parse_audio_endpoints(chip, interface)) {
  166. usb_set_interface(dev, interface, 0); /* reset the current interface */
  167. usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
  168. return -EINVAL;
  169. }
  170. return 0;
  171. }
  172. /*
  173. * parse audio control descriptor and create pcm/midi streams
  174. */
  175. static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
  176. {
  177. struct usb_device *dev = chip->dev;
  178. struct usb_host_interface *host_iface;
  179. struct usb_interface_descriptor *altsd;
  180. void *control_header;
  181. int i, protocol;
  182. /* find audiocontrol interface */
  183. host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
  184. control_header = snd_usb_find_csint_desc(host_iface->extra,
  185. host_iface->extralen,
  186. NULL, UAC_HEADER);
  187. altsd = get_iface_desc(host_iface);
  188. protocol = altsd->bInterfaceProtocol;
  189. if (!control_header) {
  190. snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
  191. return -EINVAL;
  192. }
  193. switch (protocol) {
  194. default:
  195. snd_printdd(KERN_WARNING "unknown interface protocol %#02x, assuming v1\n",
  196. protocol);
  197. /* fall through */
  198. case UAC_VERSION_1: {
  199. struct uac1_ac_header_descriptor *h1 = control_header;
  200. if (!h1->bInCollection) {
  201. snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
  202. return -EINVAL;
  203. }
  204. if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
  205. snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n");
  206. return -EINVAL;
  207. }
  208. for (i = 0; i < h1->bInCollection; i++)
  209. snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]);
  210. break;
  211. }
  212. case UAC_VERSION_2: {
  213. struct usb_interface_assoc_descriptor *assoc =
  214. usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
  215. if (!assoc) {
  216. snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n");
  217. return -EINVAL;
  218. }
  219. for (i = 0; i < assoc->bInterfaceCount; i++) {
  220. int intf = assoc->bFirstInterface + i;
  221. if (intf != ctrlif)
  222. snd_usb_create_stream(chip, ctrlif, intf);
  223. }
  224. break;
  225. }
  226. }
  227. return 0;
  228. }
  229. /*
  230. * free the chip instance
  231. *
  232. * here we have to do not much, since pcm and controls are already freed
  233. *
  234. */
  235. static int snd_usb_audio_free(struct snd_usb_audio *chip)
  236. {
  237. kfree(chip);
  238. return 0;
  239. }
  240. static int snd_usb_audio_dev_free(struct snd_device *device)
  241. {
  242. struct snd_usb_audio *chip = device->device_data;
  243. return snd_usb_audio_free(chip);
  244. }
  245. /*
  246. * create a chip instance and set its names.
  247. */
  248. static int snd_usb_audio_create(struct usb_device *dev, int idx,
  249. const struct snd_usb_audio_quirk *quirk,
  250. struct snd_usb_audio **rchip)
  251. {
  252. struct snd_card *card;
  253. struct snd_usb_audio *chip;
  254. int err, len;
  255. char component[14];
  256. static struct snd_device_ops ops = {
  257. .dev_free = snd_usb_audio_dev_free,
  258. };
  259. *rchip = NULL;
  260. switch (snd_usb_get_speed(dev)) {
  261. case USB_SPEED_LOW:
  262. case USB_SPEED_FULL:
  263. case USB_SPEED_HIGH:
  264. case USB_SPEED_SUPER:
  265. break;
  266. default:
  267. snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev));
  268. return -ENXIO;
  269. }
  270. err = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card);
  271. if (err < 0) {
  272. snd_printk(KERN_ERR "cannot create card instance %d\n", idx);
  273. return err;
  274. }
  275. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  276. if (! chip) {
  277. snd_card_free(card);
  278. return -ENOMEM;
  279. }
  280. chip->index = idx;
  281. chip->dev = dev;
  282. chip->card = card;
  283. chip->setup = device_setup[idx];
  284. chip->nrpacks = nrpacks;
  285. chip->async_unlink = async_unlink;
  286. chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
  287. le16_to_cpu(dev->descriptor.idProduct));
  288. INIT_LIST_HEAD(&chip->pcm_list);
  289. INIT_LIST_HEAD(&chip->midi_list);
  290. INIT_LIST_HEAD(&chip->mixer_list);
  291. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  292. snd_usb_audio_free(chip);
  293. snd_card_free(card);
  294. return err;
  295. }
  296. strcpy(card->driver, "USB-Audio");
  297. sprintf(component, "USB%04x:%04x",
  298. USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id));
  299. snd_component_add(card, component);
  300. /* retrieve the device string as shortname */
  301. if (quirk && quirk->product_name) {
  302. strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
  303. } else {
  304. if (!dev->descriptor.iProduct ||
  305. usb_string(dev, dev->descriptor.iProduct,
  306. card->shortname, sizeof(card->shortname)) <= 0) {
  307. /* no name available from anywhere, so use ID */
  308. sprintf(card->shortname, "USB Device %#04x:%#04x",
  309. USB_ID_VENDOR(chip->usb_id),
  310. USB_ID_PRODUCT(chip->usb_id));
  311. }
  312. }
  313. /* retrieve the vendor and device strings as longname */
  314. if (quirk && quirk->vendor_name) {
  315. len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
  316. } else {
  317. if (dev->descriptor.iManufacturer)
  318. len = usb_string(dev, dev->descriptor.iManufacturer,
  319. card->longname, sizeof(card->longname));
  320. else
  321. len = 0;
  322. /* we don't really care if there isn't any vendor string */
  323. }
  324. if (len > 0)
  325. strlcat(card->longname, " ", sizeof(card->longname));
  326. strlcat(card->longname, card->shortname, sizeof(card->longname));
  327. len = strlcat(card->longname, " at ", sizeof(card->longname));
  328. if (len < sizeof(card->longname))
  329. usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
  330. switch (snd_usb_get_speed(dev)) {
  331. case USB_SPEED_LOW:
  332. strlcat(card->longname, ", low speed", sizeof(card->longname));
  333. break;
  334. case USB_SPEED_FULL:
  335. strlcat(card->longname, ", full speed", sizeof(card->longname));
  336. break;
  337. case USB_SPEED_HIGH:
  338. strlcat(card->longname, ", high speed", sizeof(card->longname));
  339. break;
  340. case USB_SPEED_SUPER:
  341. strlcat(card->longname, ", super speed", sizeof(card->longname));
  342. break;
  343. default:
  344. break;
  345. }
  346. snd_usb_audio_create_proc(chip);
  347. *rchip = chip;
  348. return 0;
  349. }
  350. /*
  351. * probe the active usb device
  352. *
  353. * note that this can be called multiple times per a device, when it
  354. * includes multiple audio control interfaces.
  355. *
  356. * thus we check the usb device pointer and creates the card instance
  357. * only at the first time. the successive calls of this function will
  358. * append the pcm interface to the corresponding card.
  359. */
  360. static void *snd_usb_audio_probe(struct usb_device *dev,
  361. struct usb_interface *intf,
  362. const struct usb_device_id *usb_id)
  363. {
  364. const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info;
  365. int i, err;
  366. struct snd_usb_audio *chip;
  367. struct usb_host_interface *alts;
  368. int ifnum;
  369. u32 id;
  370. alts = &intf->altsetting[0];
  371. ifnum = get_iface_desc(alts)->bInterfaceNumber;
  372. id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
  373. le16_to_cpu(dev->descriptor.idProduct));
  374. if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
  375. goto __err_val;
  376. if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0)
  377. goto __err_val;
  378. /*
  379. * found a config. now register to ALSA
  380. */
  381. /* check whether it's already registered */
  382. chip = NULL;
  383. mutex_lock(&register_mutex);
  384. for (i = 0; i < SNDRV_CARDS; i++) {
  385. if (usb_chip[i] && usb_chip[i]->dev == dev) {
  386. if (usb_chip[i]->shutdown) {
  387. snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
  388. goto __error;
  389. }
  390. chip = usb_chip[i];
  391. break;
  392. }
  393. }
  394. if (! chip) {
  395. /* it's a fresh one.
  396. * now look for an empty slot and create a new card instance
  397. */
  398. for (i = 0; i < SNDRV_CARDS; i++)
  399. if (enable[i] && ! usb_chip[i] &&
  400. (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
  401. (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
  402. if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {
  403. goto __error;
  404. }
  405. snd_card_set_dev(chip->card, &intf->dev);
  406. break;
  407. }
  408. if (!chip) {
  409. printk(KERN_ERR "no available usb audio device\n");
  410. goto __error;
  411. }
  412. }
  413. chip->txfr_quirk = 0;
  414. err = 1; /* continue */
  415. if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
  416. /* need some special handlings */
  417. if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0)
  418. goto __error;
  419. }
  420. /*
  421. * For devices with more than one control interface, we assume the
  422. * first contains the audio controls. We might need a more specific
  423. * check here in the future.
  424. */
  425. if (!chip->ctrl_intf)
  426. chip->ctrl_intf = alts;
  427. if (err > 0) {
  428. /* create normal USB audio interfaces */
  429. if (snd_usb_create_streams(chip, ifnum) < 0 ||
  430. snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) {
  431. goto __error;
  432. }
  433. }
  434. /* we are allowed to call snd_card_register() many times */
  435. if (snd_card_register(chip->card) < 0) {
  436. goto __error;
  437. }
  438. usb_chip[chip->index] = chip;
  439. chip->num_interfaces++;
  440. mutex_unlock(&register_mutex);
  441. return chip;
  442. __error:
  443. if (chip && !chip->num_interfaces)
  444. snd_card_free(chip->card);
  445. mutex_unlock(&register_mutex);
  446. __err_val:
  447. return NULL;
  448. }
  449. /*
  450. * we need to take care of counter, since disconnection can be called also
  451. * many times as well as usb_audio_probe().
  452. */
  453. static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
  454. {
  455. struct snd_usb_audio *chip;
  456. struct snd_card *card;
  457. struct list_head *p;
  458. if (ptr == (void *)-1L)
  459. return;
  460. chip = ptr;
  461. card = chip->card;
  462. mutex_lock(&register_mutex);
  463. chip->shutdown = 1;
  464. chip->num_interfaces--;
  465. if (chip->num_interfaces <= 0) {
  466. snd_card_disconnect(card);
  467. /* release the pcm resources */
  468. list_for_each(p, &chip->pcm_list) {
  469. snd_usb_stream_disconnect(p);
  470. }
  471. /* release the midi resources */
  472. list_for_each(p, &chip->midi_list) {
  473. snd_usbmidi_disconnect(p);
  474. }
  475. /* release mixer resources */
  476. list_for_each(p, &chip->mixer_list) {
  477. snd_usb_mixer_disconnect(p);
  478. }
  479. usb_chip[chip->index] = NULL;
  480. mutex_unlock(&register_mutex);
  481. snd_card_free_when_closed(card);
  482. } else {
  483. mutex_unlock(&register_mutex);
  484. }
  485. }
  486. /*
  487. * new 2.5 USB kernel API
  488. */
  489. static int usb_audio_probe(struct usb_interface *intf,
  490. const struct usb_device_id *id)
  491. {
  492. void *chip;
  493. chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
  494. if (chip) {
  495. usb_set_intfdata(intf, chip);
  496. return 0;
  497. } else
  498. return -EIO;
  499. }
  500. static void usb_audio_disconnect(struct usb_interface *intf)
  501. {
  502. snd_usb_audio_disconnect(interface_to_usbdev(intf),
  503. usb_get_intfdata(intf));
  504. }
  505. #ifdef CONFIG_PM
  506. static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
  507. {
  508. struct snd_usb_audio *chip = usb_get_intfdata(intf);
  509. struct list_head *p;
  510. struct snd_usb_stream *as;
  511. if (chip == (void *)-1L)
  512. return 0;
  513. snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
  514. if (!chip->num_suspended_intf++) {
  515. list_for_each(p, &chip->pcm_list) {
  516. as = list_entry(p, struct snd_usb_stream, list);
  517. snd_pcm_suspend_all(as->pcm);
  518. }
  519. }
  520. return 0;
  521. }
  522. static int usb_audio_resume(struct usb_interface *intf)
  523. {
  524. struct snd_usb_audio *chip = usb_get_intfdata(intf);
  525. if (chip == (void *)-1L)
  526. return 0;
  527. if (--chip->num_suspended_intf)
  528. return 0;
  529. /*
  530. * ALSA leaves material resumption to user space
  531. * we just notify
  532. */
  533. snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
  534. return 0;
  535. }
  536. #else
  537. #define usb_audio_suspend NULL
  538. #define usb_audio_resume NULL
  539. #endif /* CONFIG_PM */
  540. static struct usb_device_id usb_audio_ids [] = {
  541. #include "quirks-table.h"
  542. { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
  543. .bInterfaceClass = USB_CLASS_AUDIO,
  544. .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL },
  545. { } /* Terminating entry */
  546. };
  547. MODULE_DEVICE_TABLE (usb, usb_audio_ids);
  548. /*
  549. * entry point for linux usb interface
  550. */
  551. static struct usb_driver usb_audio_driver = {
  552. .name = "snd-usb-audio",
  553. .probe = usb_audio_probe,
  554. .disconnect = usb_audio_disconnect,
  555. .suspend = usb_audio_suspend,
  556. .resume = usb_audio_resume,
  557. .id_table = usb_audio_ids,
  558. };
  559. static int __init snd_usb_audio_init(void)
  560. {
  561. if (nrpacks < 1 || nrpacks > MAX_PACKS) {
  562. printk(KERN_WARNING "invalid nrpacks value.\n");
  563. return -EINVAL;
  564. }
  565. return usb_register(&usb_audio_driver);
  566. }
  567. static void __exit snd_usb_audio_cleanup(void)
  568. {
  569. usb_deregister(&usb_audio_driver);
  570. }
  571. module_init(snd_usb_audio_init);
  572. module_exit(snd_usb_audio_cleanup);