2 * (Tentative) USB Audio Driver for ALSA
4 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
6 * Many codes borrowed from audio.c by
7 * Alan Cox (alan@lxorguk.ukuu.org.uk)
8 * Thomas Sailer (sailer@ife.ee.ethz.ch)
10 * Audio Class 3.0 support by Ruslan Bilovol <ruslan.bilovol@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * - the linked URBs would be preferred but not used so far because of
30 * the instability of unlinking.
31 * - type II is not supported properly. there is no device which supports
32 * this type *correctly*. SB extigy looks as if it supports, but it's
33 * indeed an AC3 stream packed in SPDIF frames (i.e. no real AC3 stream).
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/ctype.h>
43 #include <linux/usb.h>
44 #include <linux/moduleparam.h>
45 #include <linux/mutex.h>
46 #include <linux/usb/audio.h>
47 #include <linux/usb/audio-v2.h>
48 #include <linux/usb/audio-v3.h>
49 #include <linux/module.h>
51 #include <sound/control.h>
52 #include <sound/core.h>
53 #include <sound/info.h>
54 #include <sound/pcm.h>
55 #include <sound/pcm_params.h>
56 #include <sound/initval.h>
73 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
74 MODULE_DESCRIPTION("USB Audio");
75 MODULE_LICENSE("GPL");
76 MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}");
79 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
80 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
81 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
82 /* Vendor/product IDs for this card */
83 static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
84 static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
85 static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
86 static bool ignore_ctl_error;
87 static bool autoclock = true;
88 static char *quirk_alias[SNDRV_CARDS];
90 bool snd_usb_use_vmalloc = true;
92 module_param_array(index, int, NULL, 0444);
93 MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
94 module_param_array(id, charp, NULL, 0444);
95 MODULE_PARM_DESC(id, "ID string for the USB audio adapter.");
96 module_param_array(enable, bool, NULL, 0444);
97 MODULE_PARM_DESC(enable, "Enable USB audio adapter.");
98 module_param_array(vid, int, NULL, 0444);
99 MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
100 module_param_array(pid, int, NULL, 0444);
101 MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
102 module_param_array(device_setup, int, NULL, 0444);
103 MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
104 module_param(ignore_ctl_error, bool, 0444);
105 MODULE_PARM_DESC(ignore_ctl_error,
106 "Ignore errors from USB controller for mixer interfaces.");
107 module_param(autoclock, bool, 0444);
108 MODULE_PARM_DESC(autoclock, "Enable auto-clock selection for UAC2 devices (default: yes).");
109 module_param_array(quirk_alias, charp, NULL, 0444);
110 MODULE_PARM_DESC(quirk_alias, "Quirk aliases, e.g. 0123abcd:5678beef.");
111 module_param_named(use_vmalloc, snd_usb_use_vmalloc, bool, 0444);
112 MODULE_PARM_DESC(use_vmalloc, "Use vmalloc for PCM intermediate buffers (default: yes).");
115 * we keep the snd_usb_audio_t instances by ourselves for merging
116 * the all interfaces on the same card as one sound device.
119 static DEFINE_MUTEX(register_mutex);
120 static struct snd_usb_audio *usb_chip[SNDRV_CARDS];
121 static struct usb_driver usb_audio_driver;
125 * called from usb_audio_disconnect()
127 static void snd_usb_stream_disconnect(struct snd_usb_stream *as)
130 struct snd_usb_substream *subs;
132 for (idx = 0; idx < 2; idx++) {
133 subs = &as->substream[idx];
134 if (!subs->num_formats)
136 subs->interface = -1;
137 subs->data_endpoint = NULL;
138 subs->sync_endpoint = NULL;
142 static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
144 struct usb_device *dev = chip->dev;
145 struct usb_host_interface *alts;
146 struct usb_interface_descriptor *altsd;
147 struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
150 dev_err(&dev->dev, "%u:%d : does not exist\n",
155 alts = &iface->altsetting[0];
156 altsd = get_iface_desc(alts);
159 * Android with both accessory and audio interfaces enabled gets the
160 * interface numbers wrong.
162 if ((chip->usb_id == USB_ID(0x18d1, 0x2d04) ||
163 chip->usb_id == USB_ID(0x18d1, 0x2d05)) &&
165 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
166 altsd->bInterfaceSubClass == USB_SUBCLASS_VENDOR_SPEC) {
168 iface = usb_ifnum_to_if(dev, interface);
171 alts = &iface->altsetting[0];
172 altsd = get_iface_desc(alts);
175 if (usb_interface_claimed(iface)) {
176 dev_dbg(&dev->dev, "%d:%d: skipping, already claimed\n",
181 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
182 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
183 altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
184 int err = __snd_usbmidi_create(chip->card, iface,
185 &chip->midi_list, NULL,
189 "%u:%d: cannot create sequencer device\n",
193 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
198 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
199 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
200 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
202 "%u:%d: skipping non-supported interface %d\n",
203 ctrlif, interface, altsd->bInterfaceClass);
204 /* skip non-supported classes */
208 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
209 dev_err(&dev->dev, "low speed audio streaming not supported\n");
213 if (! snd_usb_parse_audio_interface(chip, interface)) {
214 usb_set_interface(dev, interface, 0); /* reset the current interface */
215 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
222 * parse audio control descriptor and create pcm/midi streams
224 static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
226 struct usb_device *dev = chip->dev;
227 struct usb_host_interface *host_iface;
228 struct usb_interface_descriptor *altsd;
231 /* find audiocontrol interface */
232 host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
233 altsd = get_iface_desc(host_iface);
234 protocol = altsd->bInterfaceProtocol;
239 "unknown interface protocol %#02x, assuming v1\n",
243 case UAC_VERSION_1: {
244 struct uac1_ac_header_descriptor *h1;
247 h1 = snd_usb_find_csint_desc(host_iface->extra,
248 host_iface->extralen,
250 if (!h1 || h1->bLength < sizeof(*h1)) {
251 dev_err(&dev->dev, "cannot find UAC_HEADER\n");
255 rest_bytes = (void *)(host_iface->extra +
256 host_iface->extralen) - (void *)h1;
258 /* just to be sure -- this shouldn't hit at all */
259 if (rest_bytes <= 0) {
260 dev_err(&dev->dev, "invalid control header\n");
264 if (rest_bytes < sizeof(*h1)) {
265 dev_err(&dev->dev, "too short v1 buffer descriptor\n");
269 if (!h1->bInCollection) {
270 dev_info(&dev->dev, "skipping empty audio interface (v1)\n");
274 if (rest_bytes < h1->bLength) {
275 dev_err(&dev->dev, "invalid buffer length (v1)\n");
279 if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
280 dev_err(&dev->dev, "invalid UAC_HEADER (v1)\n");
284 for (i = 0; i < h1->bInCollection; i++)
285 snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]);
291 case UAC_VERSION_3: {
292 struct usb_interface_assoc_descriptor *assoc =
293 usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
297 * Firmware writers cannot count to three. So to find
298 * the IAD on the NuForce UDH-100, also check the next
301 struct usb_interface *iface =
302 usb_ifnum_to_if(dev, ctrlif + 1);
305 iface->intf_assoc->bFunctionClass == USB_CLASS_AUDIO &&
306 iface->intf_assoc->bFunctionProtocol == UAC_VERSION_2)
307 assoc = iface->intf_assoc;
311 dev_err(&dev->dev, "Audio class v2/v3 interfaces need an interface association\n");
315 if (protocol == UAC_VERSION_3) {
316 int badd = assoc->bFunctionSubClass;
318 if (badd != UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0 &&
319 (badd < UAC3_FUNCTION_SUBCLASS_GENERIC_IO ||
320 badd > UAC3_FUNCTION_SUBCLASS_SPEAKERPHONE)) {
322 "Unsupported UAC3 BADD profile\n");
326 chip->badd_profile = badd;
329 for (i = 0; i < assoc->bInterfaceCount; i++) {
330 int intf = assoc->bFirstInterface + i;
333 snd_usb_create_stream(chip, ctrlif, intf);
344 * free the chip instance
346 * here we have to do not much, since pcm and controls are already freed
350 static void snd_usb_audio_free(struct snd_card *card)
352 struct snd_usb_audio *chip = card->private_data;
353 struct snd_usb_endpoint *ep, *n;
355 list_for_each_entry_safe(ep, n, &chip->ep_list, list)
356 snd_usb_endpoint_free(ep);
358 mutex_destroy(&chip->mutex);
359 if (!atomic_read(&chip->shutdown))
360 dev_set_drvdata(&chip->dev->dev, NULL);
363 static void usb_audio_make_shortname(struct usb_device *dev,
364 struct snd_usb_audio *chip,
365 const struct snd_usb_audio_quirk *quirk)
367 struct snd_card *card = chip->card;
369 if (quirk && quirk->product_name && *quirk->product_name) {
370 strlcpy(card->shortname, quirk->product_name,
371 sizeof(card->shortname));
375 /* retrieve the device string as shortname */
376 if (!dev->descriptor.iProduct ||
377 usb_string(dev, dev->descriptor.iProduct,
378 card->shortname, sizeof(card->shortname)) <= 0) {
379 /* no name available from anywhere, so use ID */
380 sprintf(card->shortname, "USB Device %#04x:%#04x",
381 USB_ID_VENDOR(chip->usb_id),
382 USB_ID_PRODUCT(chip->usb_id));
385 strim(card->shortname);
388 static void usb_audio_make_longname(struct usb_device *dev,
389 struct snd_usb_audio *chip,
390 const struct snd_usb_audio_quirk *quirk)
392 struct snd_card *card = chip->card;
395 /* shortcut - if any pre-defined string is given, use it */
396 if (quirk && quirk->profile_name && *quirk->profile_name) {
397 strlcpy(card->longname, quirk->profile_name,
398 sizeof(card->longname));
402 if (quirk && quirk->vendor_name && *quirk->vendor_name) {
403 len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
405 /* retrieve the vendor and device strings as longname */
406 if (dev->descriptor.iManufacturer)
407 len = usb_string(dev, dev->descriptor.iManufacturer,
408 card->longname, sizeof(card->longname));
411 /* we don't really care if there isn't any vendor string */
414 strim(card->longname);
416 strlcat(card->longname, " ", sizeof(card->longname));
419 strlcat(card->longname, card->shortname, sizeof(card->longname));
421 len = strlcat(card->longname, " at ", sizeof(card->longname));
423 if (len < sizeof(card->longname))
424 usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
426 switch (snd_usb_get_speed(dev)) {
428 strlcat(card->longname, ", low speed", sizeof(card->longname));
431 strlcat(card->longname, ", full speed", sizeof(card->longname));
434 strlcat(card->longname, ", high speed", sizeof(card->longname));
436 case USB_SPEED_SUPER:
437 strlcat(card->longname, ", super speed", sizeof(card->longname));
439 case USB_SPEED_SUPER_PLUS:
440 strlcat(card->longname, ", super speed plus", sizeof(card->longname));
448 * create a chip instance and set its names.
450 static int snd_usb_audio_create(struct usb_interface *intf,
451 struct usb_device *dev, int idx,
452 const struct snd_usb_audio_quirk *quirk,
454 struct snd_usb_audio **rchip)
456 struct snd_card *card;
457 struct snd_usb_audio *chip;
463 switch (snd_usb_get_speed(dev)) {
467 case USB_SPEED_WIRELESS:
468 case USB_SPEED_SUPER:
469 case USB_SPEED_SUPER_PLUS:
472 dev_err(&dev->dev, "unknown device speed %d\n", snd_usb_get_speed(dev));
476 err = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE,
477 sizeof(*chip), &card);
479 dev_err(&dev->dev, "cannot create card instance %d\n", idx);
483 chip = card->private_data;
484 mutex_init(&chip->mutex);
485 init_waitqueue_head(&chip->shutdown_wait);
489 chip->setup = device_setup[idx];
490 chip->autoclock = autoclock;
491 atomic_set(&chip->active, 1); /* avoid autopm during probing */
492 atomic_set(&chip->usage_count, 0);
493 atomic_set(&chip->shutdown, 0);
495 chip->usb_id = usb_id;
496 INIT_LIST_HEAD(&chip->pcm_list);
497 INIT_LIST_HEAD(&chip->ep_list);
498 INIT_LIST_HEAD(&chip->midi_list);
499 INIT_LIST_HEAD(&chip->mixer_list);
501 card->private_free = snd_usb_audio_free;
503 strcpy(card->driver, "USB-Audio");
504 sprintf(component, "USB%04x:%04x",
505 USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id));
506 snd_component_add(card, component);
508 usb_audio_make_shortname(dev, chip, quirk);
509 usb_audio_make_longname(dev, chip, quirk);
511 snd_usb_audio_create_proc(chip);
517 /* look for a matching quirk alias id */
518 static bool get_alias_id(struct usb_device *dev, unsigned int *id)
521 unsigned int src, dst;
523 for (i = 0; i < ARRAY_SIZE(quirk_alias); i++) {
524 if (!quirk_alias[i] ||
525 sscanf(quirk_alias[i], "%x:%x", &src, &dst) != 2 ||
529 "device (%04x:%04x): applying quirk alias %04x:%04x\n",
530 USB_ID_VENDOR(*id), USB_ID_PRODUCT(*id),
531 USB_ID_VENDOR(dst), USB_ID_PRODUCT(dst));
539 static const struct usb_device_id usb_audio_ids[]; /* defined below */
541 /* look for the corresponding quirk */
542 static const struct snd_usb_audio_quirk *
543 get_alias_quirk(struct usb_device *dev, unsigned int id)
545 const struct usb_device_id *p;
547 for (p = usb_audio_ids; p->match_flags; p++) {
548 /* FIXME: this checks only vendor:product pair in the list */
549 if ((p->match_flags & USB_DEVICE_ID_MATCH_DEVICE) ==
550 USB_DEVICE_ID_MATCH_DEVICE &&
551 p->idVendor == USB_ID_VENDOR(id) &&
552 p->idProduct == USB_ID_PRODUCT(id))
553 return (const struct snd_usb_audio_quirk *)p->driver_info;
560 * probe the active usb device
562 * note that this can be called multiple times per a device, when it
563 * includes multiple audio control interfaces.
565 * thus we check the usb device pointer and creates the card instance
566 * only at the first time. the successive calls of this function will
567 * append the pcm interface to the corresponding card.
569 static int usb_audio_probe(struct usb_interface *intf,
570 const struct usb_device_id *usb_id)
572 struct usb_device *dev = interface_to_usbdev(intf);
573 const struct snd_usb_audio_quirk *quirk =
574 (const struct snd_usb_audio_quirk *)usb_id->driver_info;
575 struct snd_usb_audio *chip;
577 struct usb_host_interface *alts;
581 alts = &intf->altsetting[0];
582 ifnum = get_iface_desc(alts)->bInterfaceNumber;
583 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
584 le16_to_cpu(dev->descriptor.idProduct));
585 if (get_alias_id(dev, &id))
586 quirk = get_alias_quirk(dev, id);
587 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
590 err = snd_usb_apply_boot_quirk(dev, intf, quirk, id);
595 * found a config. now register to ALSA
598 /* check whether it's already registered */
600 mutex_lock(®ister_mutex);
601 for (i = 0; i < SNDRV_CARDS; i++) {
602 if (usb_chip[i] && usb_chip[i]->dev == dev) {
603 if (atomic_read(&usb_chip[i]->shutdown)) {
604 dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n");
609 atomic_inc(&chip->active); /* avoid autopm */
615 * now look for an empty slot and create a new card instance
617 for (i = 0; i < SNDRV_CARDS; i++)
619 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
620 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
622 err = snd_usb_audio_create(intf, dev, i, quirk,
626 chip->pm_intf = intf;
628 } else if (vid[i] != -1 || pid[i] != -1) {
630 "device (%04x:%04x) is disabled\n",
638 dev_err(&dev->dev, "no available usb audio device\n");
643 dev_set_drvdata(&dev->dev, chip);
646 * For devices with more than one control interface, we assume the
647 * first contains the audio controls. We might need a more specific
648 * check here in the future.
650 if (!chip->ctrl_intf)
651 chip->ctrl_intf = alts;
653 chip->txfr_quirk = 0;
654 err = 1; /* continue */
655 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
656 /* need some special handlings */
657 err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk);
663 /* create normal USB audio interfaces */
664 err = snd_usb_create_streams(chip, ifnum);
667 err = snd_usb_create_mixer(chip, ifnum, ignore_ctl_error);
672 /* we are allowed to call snd_card_register() many times */
673 err = snd_card_register(chip->card);
677 if (quirk && quirk->shares_media_device) {
678 /* don't want to fail when snd_media_device_create() fails */
679 snd_media_device_create(chip, intf);
682 usb_chip[chip->index] = chip;
683 chip->num_interfaces++;
684 usb_set_intfdata(intf, chip);
685 atomic_dec(&chip->active);
686 mutex_unlock(®ister_mutex);
691 /* chip->active is inside the chip->card object,
692 * decrement before memory is possibly returned.
694 atomic_dec(&chip->active);
695 if (!chip->num_interfaces)
696 snd_card_free(chip->card);
698 mutex_unlock(®ister_mutex);
703 * we need to take care of counter, since disconnection can be called also
704 * many times as well as usb_audio_probe().
706 static void usb_audio_disconnect(struct usb_interface *intf)
708 struct snd_usb_audio *chip = usb_get_intfdata(intf);
709 struct snd_card *card;
712 if (chip == (void *)-1L)
717 mutex_lock(®ister_mutex);
718 if (atomic_inc_return(&chip->shutdown) == 1) {
719 struct snd_usb_stream *as;
720 struct snd_usb_endpoint *ep;
721 struct usb_mixer_interface *mixer;
723 /* wait until all pending tasks done;
724 * they are protected by snd_usb_lock_shutdown()
726 wait_event(chip->shutdown_wait,
727 !atomic_read(&chip->usage_count));
728 snd_card_disconnect(card);
729 /* release the pcm resources */
730 list_for_each_entry(as, &chip->pcm_list, list) {
731 snd_usb_stream_disconnect(as);
733 /* release the endpoint resources */
734 list_for_each_entry(ep, &chip->ep_list, list) {
735 snd_usb_endpoint_release(ep);
737 /* release the midi resources */
738 list_for_each(p, &chip->midi_list) {
739 snd_usbmidi_disconnect(p);
742 * Nice to check quirk && quirk->shares_media_device and
743 * then call the snd_media_device_delete(). Don't have
744 * access to the quirk here. snd_media_device_delete()
745 * accesses mixer_list
747 snd_media_device_delete(chip);
749 /* release mixer resources */
750 list_for_each_entry(mixer, &chip->mixer_list, list) {
751 snd_usb_mixer_disconnect(mixer);
755 chip->num_interfaces--;
756 if (chip->num_interfaces <= 0) {
757 usb_chip[chip->index] = NULL;
758 mutex_unlock(®ister_mutex);
759 snd_card_free_when_closed(card);
761 mutex_unlock(®ister_mutex);
765 /* lock the shutdown (disconnect) task and autoresume */
766 int snd_usb_lock_shutdown(struct snd_usb_audio *chip)
770 atomic_inc(&chip->usage_count);
771 if (atomic_read(&chip->shutdown)) {
775 err = snd_usb_autoresume(chip);
781 if (atomic_dec_and_test(&chip->usage_count))
782 wake_up(&chip->shutdown_wait);
786 /* autosuspend and unlock the shutdown */
787 void snd_usb_unlock_shutdown(struct snd_usb_audio *chip)
789 snd_usb_autosuspend(chip);
790 if (atomic_dec_and_test(&chip->usage_count))
791 wake_up(&chip->shutdown_wait);
796 int snd_usb_autoresume(struct snd_usb_audio *chip)
798 if (atomic_read(&chip->shutdown))
800 if (atomic_inc_return(&chip->active) == 1)
801 return usb_autopm_get_interface(chip->pm_intf);
805 void snd_usb_autosuspend(struct snd_usb_audio *chip)
807 if (atomic_read(&chip->shutdown))
809 if (atomic_dec_and_test(&chip->active))
810 usb_autopm_put_interface(chip->pm_intf);
813 static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
815 struct snd_usb_audio *chip = usb_get_intfdata(intf);
816 struct snd_usb_stream *as;
817 struct usb_mixer_interface *mixer;
820 if (chip == (void *)-1L)
823 chip->autosuspended = !!PMSG_IS_AUTO(message);
824 if (!chip->autosuspended)
825 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
826 if (!chip->num_suspended_intf++) {
827 list_for_each_entry(as, &chip->pcm_list, list) {
828 snd_usb_pcm_suspend(as);
829 as->substream[0].need_setup_ep =
830 as->substream[1].need_setup_ep = true;
832 list_for_each(p, &chip->midi_list)
833 snd_usbmidi_suspend(p);
834 list_for_each_entry(mixer, &chip->mixer_list, list)
835 snd_usb_mixer_suspend(mixer);
841 static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
843 struct snd_usb_audio *chip = usb_get_intfdata(intf);
844 struct snd_usb_stream *as;
845 struct usb_mixer_interface *mixer;
849 if (chip == (void *)-1L)
851 if (--chip->num_suspended_intf)
854 atomic_inc(&chip->active); /* avoid autopm */
856 list_for_each_entry(as, &chip->pcm_list, list) {
857 err = snd_usb_pcm_resume(as);
863 * ALSA leaves material resumption to user space
864 * we just notify and restart the mixers
866 list_for_each_entry(mixer, &chip->mixer_list, list) {
867 err = snd_usb_mixer_resume(mixer, reset_resume);
872 list_for_each(p, &chip->midi_list) {
873 snd_usbmidi_resume(p);
876 if (!chip->autosuspended)
877 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
878 chip->autosuspended = 0;
881 atomic_dec(&chip->active); /* allow autopm after this point */
885 static int usb_audio_resume(struct usb_interface *intf)
887 return __usb_audio_resume(intf, false);
890 static int usb_audio_reset_resume(struct usb_interface *intf)
892 return __usb_audio_resume(intf, true);
895 #define usb_audio_suspend NULL
896 #define usb_audio_resume NULL
897 #define usb_audio_reset_resume NULL
898 #endif /* CONFIG_PM */
900 static const struct usb_device_id usb_audio_ids [] = {
901 #include "quirks-table.h"
902 { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
903 .bInterfaceClass = USB_CLASS_AUDIO,
904 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL },
905 { } /* Terminating entry */
907 MODULE_DEVICE_TABLE(usb, usb_audio_ids);
910 * entry point for linux usb interface
913 static struct usb_driver usb_audio_driver = {
914 .name = "snd-usb-audio",
915 .probe = usb_audio_probe,
916 .disconnect = usb_audio_disconnect,
917 .suspend = usb_audio_suspend,
918 .resume = usb_audio_resume,
919 .reset_resume = usb_audio_reset_resume,
920 .id_table = usb_audio_ids,
921 .supports_autosuspend = 1,
924 module_usb_driver(usb_audio_driver);