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)
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.
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.
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
28 * - the linked URBs would be preferred but not used so far because of
29 * the instability of unlinking.
30 * - type II is not supported properly. there is no device which supports
31 * this type *correctly*. SB extigy looks as if it supports, but it's
32 * indeed an AC3 stream packed in SPDIF frames (i.e. no real AC3 stream).
36 #include <linux/bitops.h>
37 #include <linux/init.h>
38 #include <linux/list.h>
39 #include <linux/slab.h>
40 #include <linux/string.h>
41 #include <linux/ctype.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 <linux/module.h>
49 #include <linux/switch.h>
52 #include <sound/control.h>
53 #include <sound/core.h>
54 #include <sound/info.h>
55 #include <sound/pcm.h>
56 #include <sound/pcm_params.h>
57 #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 nrpacks = 8; /* max. number of packets per urb */
86 static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
87 static bool ignore_ctl_error;
88 static bool autoclock = true;
90 module_param_array(index, int, NULL, 0444);
91 MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
92 module_param_array(id, charp, NULL, 0444);
93 MODULE_PARM_DESC(id, "ID string for the USB audio adapter.");
94 module_param_array(enable, bool, NULL, 0444);
95 MODULE_PARM_DESC(enable, "Enable USB audio adapter.");
96 module_param_array(vid, int, NULL, 0444);
97 MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
98 module_param_array(pid, int, NULL, 0444);
99 MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
100 module_param(nrpacks, int, 0644);
101 MODULE_PARM_DESC(nrpacks, "Max. number of packets per URB.");
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).");
111 * we keep the snd_usb_audio_t instances by ourselves for merging
112 * the all interfaces on the same card as one sound device.
115 static DEFINE_MUTEX(register_mutex);
116 static struct snd_usb_audio *usb_chip[SNDRV_CARDS];
117 static struct usb_driver usb_audio_driver;
118 #ifdef CONFIG_SND_RK_SOC
119 #define USB_AUDIO_CARD_NUM 3
120 struct switch_dev *usb_audio_sdev;
124 //usb audio card will begin from RBASE_USB_AUDIO_IDX.
125 #define RBASE_USB_AUDIO_IDX (3)
126 #define NO_USBAUDIO_PLAYBACK (-1)
127 #define NO_USBAUDIO_CAPTURE (-1)
129 struct usb_audio_switch {
130 int playback_switch_cur_state;
131 int capture_switch_cur_state;
132 struct switch_dev sUsbaudio_Playback;
133 struct switch_dev sUsbaudio_Capture;
136 // state: card*10 + device
137 static struct usb_audio_switch sUsbaudio_Switch = {
138 .playback_switch_cur_state = NO_USBAUDIO_PLAYBACK,
139 .capture_switch_cur_state = NO_USBAUDIO_CAPTURE,
140 .sUsbaudio_Playback = {
141 .name = "usb_audio_playback",
142 .state = NO_USBAUDIO_PLAYBACK, //this means no usb audio playback available
145 .sUsbaudio_Capture = {
146 .name = "usb_audio_capture",
147 .state = NO_USBAUDIO_CAPTURE, //this means no usb audio capture available
154 * called from snd_usb_audio_disconnect()
156 static void snd_usb_stream_disconnect(struct list_head *head)
159 struct snd_usb_stream *as;
160 struct snd_usb_substream *subs;
162 as = list_entry(head, struct snd_usb_stream, list);
163 for (idx = 0; idx < 2; idx++) {
164 subs = &as->substream[idx];
165 if (!subs->num_formats)
167 subs->interface = -1;
168 subs->data_endpoint = NULL;
169 subs->sync_endpoint = NULL;
173 static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
175 struct usb_device *dev = chip->dev;
176 struct usb_host_interface *alts;
177 struct usb_interface_descriptor *altsd;
178 struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
181 snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
182 dev->devnum, ctrlif, interface);
186 alts = &iface->altsetting[0];
187 altsd = get_iface_desc(alts);
190 * Android with both accessory and audio interfaces enabled gets the
191 * interface numbers wrong.
193 if ((chip->usb_id == USB_ID(0x18d1, 0x2d04) ||
194 chip->usb_id == USB_ID(0x18d1, 0x2d05)) &&
196 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
197 altsd->bInterfaceSubClass == USB_SUBCLASS_VENDOR_SPEC) {
199 iface = usb_ifnum_to_if(dev, interface);
202 alts = &iface->altsetting[0];
203 altsd = get_iface_desc(alts);
206 if (usb_interface_claimed(iface)) {
207 snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n",
208 dev->devnum, ctrlif, interface);
212 if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
213 altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
214 altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
215 int err = snd_usbmidi_create(chip->card, iface,
216 &chip->midi_list, NULL);
218 snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
219 dev->devnum, ctrlif, interface);
222 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
227 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
228 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
229 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
230 snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
231 dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
232 /* skip non-supported classes */
236 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
237 snd_printk(KERN_ERR "low speed audio streaming not supported\n");
241 if (! snd_usb_parse_audio_interface(chip, interface)) {
242 usb_set_interface(dev, interface, 0); /* reset the current interface */
243 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
251 * parse audio control descriptor and create pcm/midi streams
253 static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
255 struct usb_device *dev = chip->dev;
256 struct usb_host_interface *host_iface;
257 struct usb_interface_descriptor *altsd;
258 void *control_header;
261 /* find audiocontrol interface */
262 host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
263 control_header = snd_usb_find_csint_desc(host_iface->extra,
264 host_iface->extralen,
266 altsd = get_iface_desc(host_iface);
267 protocol = altsd->bInterfaceProtocol;
269 if (!control_header) {
270 snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
276 snd_printdd(KERN_WARNING "unknown interface protocol %#02x, assuming v1\n",
280 case UAC_VERSION_1: {
281 struct uac1_ac_header_descriptor *h1 = control_header;
283 if (!h1->bInCollection) {
284 snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
288 if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
289 snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n");
293 for (i = 0; i < h1->bInCollection; i++)
294 snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]);
299 case UAC_VERSION_2: {
300 struct usb_interface_assoc_descriptor *assoc =
301 usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
305 * Firmware writers cannot count to three. So to find
306 * the IAD on the NuForce UDH-100, also check the next
309 struct usb_interface *iface =
310 usb_ifnum_to_if(dev, ctrlif + 1);
313 iface->intf_assoc->bFunctionClass == USB_CLASS_AUDIO &&
314 iface->intf_assoc->bFunctionProtocol == UAC_VERSION_2)
315 assoc = iface->intf_assoc;
319 snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n");
323 for (i = 0; i < assoc->bInterfaceCount; i++) {
324 int intf = assoc->bFirstInterface + i;
327 snd_usb_create_stream(chip, ctrlif, intf);
338 * free the chip instance
340 * here we have to do not much, since pcm and controls are already freed
344 static int snd_usb_audio_free(struct snd_usb_audio *chip)
346 mutex_destroy(&chip->mutex);
351 static int snd_usb_audio_dev_free(struct snd_device *device)
353 struct snd_usb_audio *chip = device->device_data;
354 return snd_usb_audio_free(chip);
357 static void remove_trailing_spaces(char *str)
363 for (p = str + strlen(str) - 1; p >= str && isspace(*p); p--)
368 * create a chip instance and set its names.
370 static int snd_usb_audio_create(struct usb_device *dev, int idx,
371 const struct snd_usb_audio_quirk *quirk,
372 struct snd_usb_audio **rchip)
374 struct snd_card *card;
375 struct snd_usb_audio *chip;
378 static struct snd_device_ops ops = {
379 .dev_free = snd_usb_audio_dev_free,
384 switch (snd_usb_get_speed(dev)) {
388 case USB_SPEED_SUPER:
391 snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev));
394 #ifdef CONFIG_SND_RK_SOC
395 err = snd_card_create(USB_AUDIO_CARD_NUM, id[idx], THIS_MODULE, 0, &card);
397 err = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card);
400 snd_printk(KERN_ERR "cannot create card instance %d\n", idx);
404 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
410 mutex_init(&chip->mutex);
411 init_rwsem(&chip->shutdown_rwsem);
415 chip->setup = device_setup[idx];
416 chip->nrpacks = nrpacks;
417 chip->autoclock = autoclock;
420 chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
421 le16_to_cpu(dev->descriptor.idProduct));
422 INIT_LIST_HEAD(&chip->pcm_list);
423 INIT_LIST_HEAD(&chip->ep_list);
424 INIT_LIST_HEAD(&chip->midi_list);
425 INIT_LIST_HEAD(&chip->mixer_list);
427 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
428 snd_usb_audio_free(chip);
433 strcpy(card->driver, "USB-Audio");
434 sprintf(component, "USB%04x:%04x",
435 USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id));
436 snd_component_add(card, component);
438 /* retrieve the device string as shortname */
439 if (quirk && quirk->product_name && *quirk->product_name) {
440 strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
442 if (!dev->descriptor.iProduct ||
443 usb_string(dev, dev->descriptor.iProduct,
444 card->shortname, sizeof(card->shortname)) <= 0) {
445 /* no name available from anywhere, so use ID */
446 sprintf(card->shortname, "USB Device %#04x:%#04x",
447 USB_ID_VENDOR(chip->usb_id),
448 USB_ID_PRODUCT(chip->usb_id));
451 remove_trailing_spaces(card->shortname);
453 /* retrieve the vendor and device strings as longname */
454 if (quirk && quirk->vendor_name && *quirk->vendor_name) {
455 len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
457 if (dev->descriptor.iManufacturer)
458 len = usb_string(dev, dev->descriptor.iManufacturer,
459 card->longname, sizeof(card->longname));
462 /* we don't really care if there isn't any vendor string */
465 remove_trailing_spaces(card->longname);
467 strlcat(card->longname, " ", sizeof(card->longname));
470 strlcat(card->longname, card->shortname, sizeof(card->longname));
472 len = strlcat(card->longname, " at ", sizeof(card->longname));
474 if (len < sizeof(card->longname))
475 usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
477 switch (snd_usb_get_speed(dev)) {
479 strlcat(card->longname, ", low speed", sizeof(card->longname));
482 strlcat(card->longname, ", full speed", sizeof(card->longname));
485 strlcat(card->longname, ", high speed", sizeof(card->longname));
487 case USB_SPEED_SUPER:
488 strlcat(card->longname, ", super speed", sizeof(card->longname));
494 snd_usb_audio_create_proc(chip);
501 static int usb_audio_card_switch_state_update(struct snd_card *card, bool force){
502 struct snd_device *dev;
504 struct snd_pcm_str *pstr;
506 if (snd_BUG_ON(!card))
508 //we use the latest devices
509 list_for_each_entry(dev, &card->devices, list) {
510 if (dev->type == SNDRV_DEV_PCM && dev->state == SNDRV_DEV_REGISTERED) {
511 pcm = (struct snd_pcm*)dev->device_data;
513 //playback available?
514 pstr = &pcm->streams[SNDRV_PCM_STREAM_PLAYBACK];
515 snd_printdd(KERN_INFO "playback substream_count: 0x%x\n", pstr->substream_count);
516 if (pstr->substream_count > 0) {
517 sUsbaudio_Switch.playback_switch_cur_state = card->number * 10;
520 pstr = &pcm->streams[SNDRV_PCM_STREAM_CAPTURE];
521 snd_printdd(KERN_INFO "capture substream_count: 0x%x\n", pstr->substream_count);
522 if (pstr->substream_count > 0) {
523 sUsbaudio_Switch.capture_switch_cur_state = card->number * 10;
529 switch_set_state(&sUsbaudio_Switch.sUsbaudio_Playback, sUsbaudio_Switch.playback_switch_cur_state);
530 switch_set_state(&sUsbaudio_Switch.sUsbaudio_Capture, sUsbaudio_Switch.capture_switch_cur_state);
536 static void usb_audio_switch_state_update_all(void)
539 struct snd_card *card;
541 sUsbaudio_Switch.playback_switch_cur_state = NO_USBAUDIO_PLAYBACK;
542 sUsbaudio_Switch.capture_switch_cur_state = NO_USBAUDIO_CAPTURE;
544 for (index = 0; index < SNDRV_CARDS; ++index) {
545 if (NULL != usb_chip[index]) {
546 card = usb_chip[index]->card;
547 usb_audio_card_switch_state_update(card, false);
551 switch_set_state(&sUsbaudio_Switch.sUsbaudio_Playback,
552 sUsbaudio_Switch.playback_switch_cur_state);
553 switch_set_state(&sUsbaudio_Switch.sUsbaudio_Capture,
554 sUsbaudio_Switch.capture_switch_cur_state);
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 struct snd_usb_audio *
570 snd_usb_audio_probe(struct usb_device *dev,
571 struct usb_interface *intf,
572 const struct usb_device_id *usb_id)
574 const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info;
576 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 (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
588 if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0)
592 * found a config. now register to ALSA
595 /* check whether it's already registered */
597 mutex_lock(®ister_mutex);
598 for (i = 0; i < SNDRV_CARDS; i++) {
599 if (usb_chip[i] && usb_chip[i]->dev == dev) {
600 if (usb_chip[i]->shutdown) {
601 snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
611 * now look for an empty slot and create a new card instance
613 // use RBASE_USB_AUDIO_IDX instead of zero, modify by zxg.
614 for (i = 0; i < SNDRV_CARDS; i++)
615 if (enable[i] && ! usb_chip[i] &&
616 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
617 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
618 if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {
621 snd_card_set_dev(chip->card, &intf->dev);
622 chip->pm_intf = intf;
626 printk(KERN_ERR "no available usb audio device\n");
632 * For devices with more than one control interface, we assume the
633 * first contains the audio controls. We might need a more specific
634 * check here in the future.
636 if (!chip->ctrl_intf)
637 chip->ctrl_intf = alts;
639 chip->txfr_quirk = 0;
640 err = 1; /* continue */
641 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
642 /* need some special handlings */
643 if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0)
648 /* create normal USB audio interfaces */
649 if (snd_usb_create_streams(chip, ifnum) < 0 ||
650 snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) {
655 /* we are allowed to call snd_card_register() many times */
656 if (snd_card_register(chip->card) < 0) {
660 if (usb_audio_card_switch_state_update(chip->card, true) < 0) {
661 printk(KERN_ERR "usb_audio_card_switch_state_update failed!!!\n");
665 usb_chip[chip->index] = chip;
666 chip->num_interfaces++;
668 mutex_unlock(®ister_mutex);
673 if (!chip->num_interfaces)
674 snd_card_free(chip->card);
677 mutex_unlock(®ister_mutex);
683 * we need to take care of counter, since disconnection can be called also
684 * many times as well as usb_audio_probe().
686 static void snd_usb_audio_disconnect(struct usb_device *dev,
687 struct snd_usb_audio *chip)
689 struct snd_card *card;
690 struct list_head *p, *n;
692 if (chip == (void *)-1L)
696 down_write(&chip->shutdown_rwsem);
698 up_write(&chip->shutdown_rwsem);
700 mutex_lock(®ister_mutex);
701 chip->num_interfaces--;
702 if (chip->num_interfaces <= 0) {
703 snd_card_disconnect(card);
704 /* release the pcm resources */
705 list_for_each(p, &chip->pcm_list) {
706 snd_usb_stream_disconnect(p);
708 /* release the endpoint resources */
709 list_for_each_safe(p, n, &chip->ep_list) {
710 snd_usb_endpoint_free(p);
712 /* release the midi resources */
713 list_for_each(p, &chip->midi_list) {
714 snd_usbmidi_disconnect(p);
716 /* release mixer resources */
717 list_for_each(p, &chip->mixer_list) {
718 snd_usb_mixer_disconnect(p);
720 usb_chip[chip->index] = NULL;
721 mutex_unlock(®ister_mutex);
722 snd_card_free_when_closed(card);
724 mutex_unlock(®ister_mutex);
727 usb_audio_switch_state_update_all();
732 * new 2.5 USB kernel API
734 static int usb_audio_probe(struct usb_interface *intf,
735 const struct usb_device_id *id)
737 struct snd_usb_audio *chip;
738 chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
740 usb_set_intfdata(intf, chip);
741 #ifdef CONFIG_SND_RK_SOC
742 switch_set_state(usb_audio_sdev, 1);
749 static void usb_audio_disconnect(struct usb_interface *intf)
751 #ifdef CONFIG_SND_RK_SOC
752 switch_set_state(usb_audio_sdev, 0);
754 snd_usb_audio_disconnect(interface_to_usbdev(intf),
755 usb_get_intfdata(intf));
760 int snd_usb_autoresume(struct snd_usb_audio *chip)
764 down_read(&chip->shutdown_rwsem);
767 else if (!chip->shutdown)
768 err = usb_autopm_get_interface(chip->pm_intf);
769 up_read(&chip->shutdown_rwsem);
774 void snd_usb_autosuspend(struct snd_usb_audio *chip)
776 down_read(&chip->shutdown_rwsem);
777 if (!chip->shutdown && !chip->probing)
778 usb_autopm_put_interface(chip->pm_intf);
779 up_read(&chip->shutdown_rwsem);
782 static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
784 struct snd_usb_audio *chip = usb_get_intfdata(intf);
785 struct snd_usb_stream *as;
786 struct usb_mixer_interface *mixer;
788 if (chip == (void *)-1L)
791 if (!PMSG_IS_AUTO(message)) {
792 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
793 if (!chip->num_suspended_intf++) {
794 list_for_each_entry(as, &chip->pcm_list, list) {
795 snd_pcm_suspend_all(as->pcm);
796 as->substream[0].need_setup_ep =
797 as->substream[1].need_setup_ep = true;
802 * otherwise we keep the rest of the system in the dark
803 * to keep this transparent
805 if (!chip->num_suspended_intf++)
806 chip->autosuspended = 1;
809 list_for_each_entry(mixer, &chip->mixer_list, list)
810 snd_usb_mixer_inactivate(mixer);
815 static int usb_audio_resume(struct usb_interface *intf)
817 struct snd_usb_audio *chip = usb_get_intfdata(intf);
818 struct usb_mixer_interface *mixer;
821 if (chip == (void *)-1L)
823 if (--chip->num_suspended_intf)
826 * ALSA leaves material resumption to user space
827 * we just notify and restart the mixers
829 list_for_each_entry(mixer, &chip->mixer_list, list) {
830 err = snd_usb_mixer_activate(mixer);
835 if (!chip->autosuspended)
836 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
837 chip->autosuspended = 0;
843 #define usb_audio_suspend NULL
844 #define usb_audio_resume NULL
845 #endif /* CONFIG_PM */
847 static struct usb_device_id usb_audio_ids [] = {
848 #include "quirks-table.h"
849 { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
850 .bInterfaceClass = USB_CLASS_AUDIO,
851 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL },
852 { } /* Terminating entry */
854 MODULE_DEVICE_TABLE(usb, usb_audio_ids);
857 * entry point for linux usb interface
860 static struct usb_driver usb_audio_driver = {
861 .name = "snd-usb-audio",
862 .probe = usb_audio_probe,
863 .disconnect = usb_audio_disconnect,
864 .suspend = usb_audio_suspend,
865 .resume = usb_audio_resume,
866 .id_table = usb_audio_ids,
867 .supports_autosuspend = 1,
870 static int __init snd_usb_audio_init(void)
875 ret = switch_dev_register(&sUsbaudio_Switch.sUsbaudio_Playback);
878 ret = switch_dev_register(&sUsbaudio_Switch.sUsbaudio_Capture);
882 switch_set_state(&sUsbaudio_Switch.sUsbaudio_Playback, NO_USBAUDIO_PLAYBACK);
883 switch_set_state(&sUsbaudio_Switch.sUsbaudio_Capture, NO_USBAUDIO_CAPTURE);
886 if (nrpacks < 1 || nrpacks > MAX_PACKS) {
887 printk(KERN_WARNING "invalid nrpacks value.\n");
890 #ifdef CONFIG_SND_RK_SOC
891 usb_audio_sdev = kzalloc(sizeof(usb_audio_sdev), GFP_KERNEL);
892 usb_audio_sdev->name = "usb_audio";
893 switch_dev_register(usb_audio_sdev);
894 if (!usb_audio_sdev) {
895 printk(KERN_WARNING "usb-audio kmalloc fail!");
900 //re initial array index for rebasing usb audio cards create, modify by zxg.
901 for(i=0; i<SNDRV_CARDS; ++i){
905 return usb_register(&usb_audio_driver);
909 switch_dev_unregister(&sUsbaudio_Switch.sUsbaudio_Playback);
916 static void __exit snd_usb_audio_cleanup(void)
918 usb_deregister(&usb_audio_driver);
919 #ifdef CONFIG_SND_RK_SOC
920 kfree(usb_audio_sdev);
922 switch_dev_unregister(&sUsbaudio_Switch.sUsbaudio_Capture);
923 switch_dev_unregister(&sUsbaudio_Switch.sUsbaudio_Playback);
926 /*module_init(snd_usb_audio_init);*/
927 /* use late initcall_sync instead of module_init,
928 * make sure that usbaudio probe after board codec.
929 * added by zxg@rock-chips.com
931 late_initcall_sync(snd_usb_audio_init);
932 module_exit(snd_usb_audio_cleanup);