| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *   (Tentative) USB Audio Driver for ALSA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   Many codes borrowed from audio.c by | 
					
						
							|  |  |  |  *	    Alan Cox (alan@lxorguk.ukuu.org.uk) | 
					
						
							|  |  |  |  *	    Thomas Sailer (sailer@ife.ee.ethz.ch) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  *   it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  *   the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  *   (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  *   GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  *   along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  NOTES: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   - the linked URBs would be preferred but not used so far because of | 
					
						
							|  |  |  |  *     the instability of unlinking. | 
					
						
							|  |  |  |  *   - type II is not supported properly.  there is no device which supports | 
					
						
							|  |  |  |  *     this type *correctly*.  SB extigy looks as if it supports, but it's | 
					
						
							|  |  |  |  *     indeed an AC3 stream packed in SPDIF frames (i.e. no real AC3 stream). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/bitops.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | #include <linux/list.h>
 | 
					
						
							|  |  |  | #include <linux/slab.h>
 | 
					
						
							|  |  |  | #include <linux/string.h>
 | 
					
						
							| 
									
										
										
										
											2011-03-21 12:00:00 +01:00
										 |  |  | #include <linux/ctype.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | #include <linux/usb.h>
 | 
					
						
							|  |  |  | #include <linux/moduleparam.h>
 | 
					
						
							|  |  |  | #include <linux/mutex.h>
 | 
					
						
							|  |  |  | #include <linux/usb/audio.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-11 21:13:20 +01:00
										 |  |  | #include <linux/usb/audio-v2.h>
 | 
					
						
							| 
									
										
										
										
											2011-07-15 12:38:28 -04:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 09:09:01 +02:00
										 |  |  | #include <sound/control.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | #include <sound/core.h>
 | 
					
						
							|  |  |  | #include <sound/info.h>
 | 
					
						
							|  |  |  | #include <sound/pcm.h>
 | 
					
						
							|  |  |  | #include <sound/pcm_params.h>
 | 
					
						
							|  |  |  | #include <sound/initval.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "usbaudio.h"
 | 
					
						
							|  |  |  | #include "card.h"
 | 
					
						
							|  |  |  | #include "midi.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-11 21:13:23 +01:00
										 |  |  | #include "mixer.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | #include "proc.h"
 | 
					
						
							|  |  |  | #include "quirks.h"
 | 
					
						
							|  |  |  | #include "endpoint.h"
 | 
					
						
							|  |  |  | #include "helper.h"
 | 
					
						
							|  |  |  | #include "debug.h"
 | 
					
						
							|  |  |  | #include "pcm.h"
 | 
					
						
							|  |  |  | #include "format.h"
 | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | #include "power.h"
 | 
					
						
							| 
									
										
										
										
											2011-09-12 18:54:12 +02:00
										 |  |  | #include "stream.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); | 
					
						
							|  |  |  | MODULE_DESCRIPTION("USB Audio"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							|  |  |  | MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */ | 
					
						
							|  |  |  | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */ | 
					
						
							| 
									
										
										
										
											2011-12-15 13:49:36 +10:30
										 |  |  | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */ | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | /* Vendor/product IDs for this card */ | 
					
						
							|  |  |  | static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; | 
					
						
							|  |  |  | static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; | 
					
						
							|  |  |  | static int device_setup[SNDRV_CARDS]; /* device parameter for this card */ | 
					
						
							| 
									
										
										
										
											2011-12-15 13:49:36 +10:30
										 |  |  | static bool ignore_ctl_error; | 
					
						
							| 
									
										
										
										
											2013-04-03 23:18:56 +02:00
										 |  |  | static bool autoclock = true; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | module_param_array(index, int, NULL, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(index, "Index value for the USB audio adapter."); | 
					
						
							|  |  |  | module_param_array(id, charp, NULL, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(id, "ID string for the USB audio adapter."); | 
					
						
							|  |  |  | module_param_array(enable, bool, NULL, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(enable, "Enable USB audio adapter."); | 
					
						
							|  |  |  | module_param_array(vid, int, NULL, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device."); | 
					
						
							|  |  |  | module_param_array(pid, int, NULL, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(pid, "Product ID for the USB audio device."); | 
					
						
							|  |  |  | module_param_array(device_setup, int, NULL, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(device_setup, "Specific device setup (if needed)."); | 
					
						
							|  |  |  | module_param(ignore_ctl_error, bool, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(ignore_ctl_error, | 
					
						
							|  |  |  | 		 "Ignore errors from USB controller for mixer interfaces."); | 
					
						
							| 
									
										
										
										
											2013-04-03 23:18:56 +02:00
										 |  |  | module_param(autoclock, bool, 0444); | 
					
						
							|  |  |  | MODULE_PARM_DESC(autoclock, "Enable auto-clock selection for UAC2 devices (default: yes)."); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * we keep the snd_usb_audio_t instances by ourselves for merging | 
					
						
							|  |  |  |  * the all interfaces on the same card as one sound device. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static DEFINE_MUTEX(register_mutex); | 
					
						
							|  |  |  | static struct snd_usb_audio *usb_chip[SNDRV_CARDS]; | 
					
						
							|  |  |  | static struct usb_driver usb_audio_driver; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * disconnect streams | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  |  * called from usb_audio_disconnect() | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:24:32 +01:00
										 |  |  | static void snd_usb_stream_disconnect(struct snd_usb_stream *as) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	int idx; | 
					
						
							|  |  |  | 	struct snd_usb_substream *subs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (idx = 0; idx < 2; idx++) { | 
					
						
							|  |  |  | 		subs = &as->substream[idx]; | 
					
						
							|  |  |  | 		if (!subs->num_formats) | 
					
						
							| 
									
										
										
										
											2010-09-08 08:27:02 +02:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		subs->interface = -1; | 
					
						
							| 
									
										
										
										
											2012-04-12 13:51:12 +02:00
										 |  |  | 		subs->data_endpoint = NULL; | 
					
						
							|  |  |  | 		subs->sync_endpoint = NULL; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct usb_device *dev = chip->dev; | 
					
						
							|  |  |  | 	struct usb_host_interface *alts; | 
					
						
							|  |  |  | 	struct usb_interface_descriptor *altsd; | 
					
						
							|  |  |  | 	struct usb_interface *iface = usb_ifnum_to_if(dev, interface); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!iface) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_err(&dev->dev, "%u:%d : does not exist\n", | 
					
						
							|  |  |  | 			ctrlif, interface); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-15 11:21:09 +02:00
										 |  |  | 	alts = &iface->altsetting[0]; | 
					
						
							|  |  |  | 	altsd = get_iface_desc(alts); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Android with both accessory and audio interfaces enabled gets the | 
					
						
							|  |  |  | 	 * interface numbers wrong. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if ((chip->usb_id == USB_ID(0x18d1, 0x2d04) || | 
					
						
							|  |  |  | 	     chip->usb_id == USB_ID(0x18d1, 0x2d05)) && | 
					
						
							|  |  |  | 	    interface == 0 && | 
					
						
							|  |  |  | 	    altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC && | 
					
						
							|  |  |  | 	    altsd->bInterfaceSubClass == USB_SUBCLASS_VENDOR_SPEC) { | 
					
						
							|  |  |  | 		interface = 2; | 
					
						
							|  |  |  | 		iface = usb_ifnum_to_if(dev, interface); | 
					
						
							|  |  |  | 		if (!iface) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		alts = &iface->altsetting[0]; | 
					
						
							|  |  |  | 		altsd = get_iface_desc(alts); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	if (usb_interface_claimed(iface)) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_dbg(&dev->dev, "%d:%d: skipping, already claimed\n", | 
					
						
							|  |  |  | 			ctrlif, interface); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((altsd->bInterfaceClass == USB_CLASS_AUDIO || | 
					
						
							|  |  |  | 	     altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) && | 
					
						
							|  |  |  | 	    altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) { | 
					
						
							|  |  |  | 		int err = snd_usbmidi_create(chip->card, iface, | 
					
						
							|  |  |  | 					     &chip->midi_list, NULL); | 
					
						
							|  |  |  | 		if (err < 0) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 			dev_err(&dev->dev, | 
					
						
							|  |  |  | 				"%u:%d: cannot create sequencer device\n", | 
					
						
							|  |  |  | 				ctrlif, interface); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && | 
					
						
							|  |  |  | 	     altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || | 
					
						
							|  |  |  | 	    altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_dbg(&dev->dev, | 
					
						
							|  |  |  | 			"%u:%d: skipping non-supported interface %d\n", | 
					
						
							|  |  |  | 			ctrlif, interface, altsd->bInterfaceClass); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		/* skip non-supported classes */ | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (snd_usb_get_speed(dev) == USB_SPEED_LOW) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_err(&dev->dev, "low speed audio streaming not supported\n"); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-12 18:54:12 +02:00
										 |  |  | 	if (! snd_usb_parse_audio_interface(chip, interface)) { | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		usb_set_interface(dev, interface, 0); /* reset the current interface */ | 
					
						
							|  |  |  | 		usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * parse audio control descriptor and create pcm/midi streams | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct usb_device *dev = chip->dev; | 
					
						
							|  |  |  | 	struct usb_host_interface *host_iface; | 
					
						
							|  |  |  | 	struct usb_interface_descriptor *altsd; | 
					
						
							|  |  |  | 	void *control_header; | 
					
						
							|  |  |  | 	int i, protocol; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* find audiocontrol interface */ | 
					
						
							|  |  |  | 	host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0]; | 
					
						
							|  |  |  | 	control_header = snd_usb_find_csint_desc(host_iface->extra, | 
					
						
							|  |  |  | 						 host_iface->extralen, | 
					
						
							|  |  |  | 						 NULL, UAC_HEADER); | 
					
						
							|  |  |  | 	altsd = get_iface_desc(host_iface); | 
					
						
							|  |  |  | 	protocol = altsd->bInterfaceProtocol; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!control_header) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_err(&dev->dev, "cannot find UAC_HEADER\n"); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (protocol) { | 
					
						
							| 
									
										
										
										
											2010-09-03 10:53:11 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_warn(&dev->dev, | 
					
						
							|  |  |  | 			 "unknown interface protocol %#02x, assuming v1\n", | 
					
						
							|  |  |  | 			 protocol); | 
					
						
							| 
									
										
										
										
											2010-09-03 10:53:11 +02:00
										 |  |  | 		/* fall through */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	case UAC_VERSION_1: { | 
					
						
							| 
									
										
										
										
											2010-06-16 17:57:28 +02:00
										 |  |  | 		struct uac1_ac_header_descriptor *h1 = control_header; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!h1->bInCollection) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 			dev_info(&dev->dev, "skipping empty audio interface (v1)\n"); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (h1->bLength < sizeof(*h1) + h1->bInCollection) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 			dev_err(&dev->dev, "invalid UAC_HEADER (v1)\n"); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (i = 0; i < h1->bInCollection; i++) | 
					
						
							|  |  |  | 			snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case UAC_VERSION_2: { | 
					
						
							|  |  |  | 		struct usb_interface_assoc_descriptor *assoc = | 
					
						
							|  |  |  | 			usb_ifnum_to_if(dev, ctrlif)->intf_assoc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-11 20:15:34 +01:00
										 |  |  | 		if (!assoc) { | 
					
						
							|  |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * Firmware writers cannot count to three.  So to find | 
					
						
							|  |  |  | 			 * the IAD on the NuForce UDH-100, also check the next | 
					
						
							|  |  |  | 			 * interface. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			struct usb_interface *iface = | 
					
						
							|  |  |  | 				usb_ifnum_to_if(dev, ctrlif + 1); | 
					
						
							|  |  |  | 			if (iface && | 
					
						
							|  |  |  | 			    iface->intf_assoc && | 
					
						
							|  |  |  | 			    iface->intf_assoc->bFunctionClass == USB_CLASS_AUDIO && | 
					
						
							|  |  |  | 			    iface->intf_assoc->bFunctionProtocol == UAC_VERSION_2) | 
					
						
							|  |  |  | 				assoc = iface->intf_assoc; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		if (!assoc) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 			dev_err(&dev->dev, "Audio class v2 interfaces need an interface association\n"); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (i = 0; i < assoc->bInterfaceCount; i++) { | 
					
						
							|  |  |  | 			int intf = assoc->bFirstInterface + i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (intf != ctrlif) | 
					
						
							|  |  |  | 				snd_usb_create_stream(chip, ctrlif, intf); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * free the chip instance | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * here we have to do not much, since pcm and controls are already freed | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int snd_usb_audio_free(struct snd_usb_audio *chip) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 11:24:32 +01:00
										 |  |  | 	struct snd_usb_endpoint *ep, *n; | 
					
						
							| 
									
										
										
										
											2014-06-25 14:24:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 11:24:32 +01:00
										 |  |  | 	list_for_each_entry_safe(ep, n, &chip->ep_list, list) | 
					
						
							|  |  |  | 		snd_usb_endpoint_free(ep); | 
					
						
							| 
									
										
										
										
											2014-06-25 14:24:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 13:51:10 +02:00
										 |  |  | 	mutex_destroy(&chip->mutex); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	kfree(chip); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int snd_usb_audio_dev_free(struct snd_device *device) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct snd_usb_audio *chip = device->device_data; | 
					
						
							|  |  |  | 	return snd_usb_audio_free(chip); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * create a chip instance and set its names. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-01-29 14:22:20 +01:00
										 |  |  | static int snd_usb_audio_create(struct usb_interface *intf, | 
					
						
							|  |  |  | 				struct usb_device *dev, int idx, | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 				const struct snd_usb_audio_quirk *quirk, | 
					
						
							|  |  |  | 				struct snd_usb_audio **rchip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct snd_card *card; | 
					
						
							|  |  |  | 	struct snd_usb_audio *chip; | 
					
						
							|  |  |  | 	int err, len; | 
					
						
							|  |  |  | 	char component[14]; | 
					
						
							|  |  |  | 	static struct snd_device_ops ops = { | 
					
						
							|  |  |  | 		.dev_free =	snd_usb_audio_dev_free, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*rchip = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-13 12:42:07 -07:00
										 |  |  | 	switch (snd_usb_get_speed(dev)) { | 
					
						
							|  |  |  | 	case USB_SPEED_LOW: | 
					
						
							|  |  |  | 	case USB_SPEED_FULL: | 
					
						
							|  |  |  | 	case USB_SPEED_HIGH: | 
					
						
							| 
									
										
										
										
											2013-10-01 14:32:15 -05:00
										 |  |  | 	case USB_SPEED_WIRELESS: | 
					
						
							| 
									
										
										
										
											2010-08-13 12:42:07 -07:00
										 |  |  | 	case USB_SPEED_SUPER: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_err(&dev->dev, "unknown device speed %d\n", snd_usb_get_speed(dev)); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		return -ENXIO; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:22:20 +01:00
										 |  |  | 	err = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE, | 
					
						
							|  |  |  | 			   0, &card); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	if (err < 0) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 		dev_err(&dev->dev, "cannot create card instance %d\n", idx); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 
					
						
							|  |  |  | 	if (! chip) { | 
					
						
							|  |  |  | 		snd_card_free(card); | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 13:51:10 +02:00
										 |  |  | 	mutex_init(&chip->mutex); | 
					
						
							| 
									
										
										
										
											2012-10-15 12:16:02 +02:00
										 |  |  | 	init_rwsem(&chip->shutdown_rwsem); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	chip->index = idx; | 
					
						
							|  |  |  | 	chip->dev = dev; | 
					
						
							|  |  |  | 	chip->card = card; | 
					
						
							|  |  |  | 	chip->setup = device_setup[idx]; | 
					
						
							| 
									
										
										
										
											2013-04-03 23:18:56 +02:00
										 |  |  | 	chip->autoclock = autoclock; | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	chip->probing = 1; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), | 
					
						
							|  |  |  | 			      le16_to_cpu(dev->descriptor.idProduct)); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&chip->pcm_list); | 
					
						
							| 
									
										
										
										
											2012-04-12 13:51:12 +02:00
										 |  |  | 	INIT_LIST_HEAD(&chip->ep_list); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	INIT_LIST_HEAD(&chip->midi_list); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&chip->mixer_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { | 
					
						
							|  |  |  | 		snd_usb_audio_free(chip); | 
					
						
							|  |  |  | 		snd_card_free(card); | 
					
						
							|  |  |  | 		return err; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	strcpy(card->driver, "USB-Audio"); | 
					
						
							|  |  |  | 	sprintf(component, "USB%04x:%04x", | 
					
						
							|  |  |  | 		USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id)); | 
					
						
							|  |  |  | 	snd_component_add(card, component); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* retrieve the device string as shortname */ | 
					
						
							| 
									
										
										
										
											2011-03-21 12:00:00 +01:00
										 |  |  | 	if (quirk && quirk->product_name && *quirk->product_name) { | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (!dev->descriptor.iProduct || | 
					
						
							|  |  |  | 		    usb_string(dev, dev->descriptor.iProduct, | 
					
						
							|  |  |  | 		    card->shortname, sizeof(card->shortname)) <= 0) { | 
					
						
							|  |  |  | 			/* no name available from anywhere, so use ID */ | 
					
						
							|  |  |  | 			sprintf(card->shortname, "USB Device %#04x:%#04x", | 
					
						
							|  |  |  | 				USB_ID_VENDOR(chip->usb_id), | 
					
						
							|  |  |  | 				USB_ID_PRODUCT(chip->usb_id)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-31 11:32:19 +01:00
										 |  |  | 	strim(card->shortname); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* retrieve the vendor and device strings as longname */ | 
					
						
							| 
									
										
										
										
											2011-03-21 12:00:00 +01:00
										 |  |  | 	if (quirk && quirk->vendor_name && *quirk->vendor_name) { | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (dev->descriptor.iManufacturer) | 
					
						
							|  |  |  | 			len = usb_string(dev, dev->descriptor.iManufacturer, | 
					
						
							|  |  |  | 					 card->longname, sizeof(card->longname)); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			len = 0; | 
					
						
							|  |  |  | 		/* we don't really care if there isn't any vendor string */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-03-21 12:00:00 +01:00
										 |  |  | 	if (len > 0) { | 
					
						
							| 
									
										
										
										
											2014-10-31 11:32:19 +01:00
										 |  |  | 		strim(card->longname); | 
					
						
							| 
									
										
										
										
											2011-03-21 12:00:00 +01:00
										 |  |  | 		if (*card->longname) | 
					
						
							|  |  |  | 			strlcat(card->longname, " ", sizeof(card->longname)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	strlcat(card->longname, card->shortname, sizeof(card->longname)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = strlcat(card->longname, " at ", sizeof(card->longname)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (len < sizeof(card->longname)) | 
					
						
							|  |  |  | 		usb_make_path(dev, card->longname + len, sizeof(card->longname) - len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-13 12:42:07 -07:00
										 |  |  | 	switch (snd_usb_get_speed(dev)) { | 
					
						
							|  |  |  | 	case USB_SPEED_LOW: | 
					
						
							|  |  |  | 		strlcat(card->longname, ", low speed", sizeof(card->longname)); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case USB_SPEED_FULL: | 
					
						
							|  |  |  | 		strlcat(card->longname, ", full speed", sizeof(card->longname)); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case USB_SPEED_HIGH: | 
					
						
							|  |  |  | 		strlcat(card->longname, ", high speed", sizeof(card->longname)); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case USB_SPEED_SUPER: | 
					
						
							|  |  |  | 		strlcat(card->longname, ", super speed", sizeof(card->longname)); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	snd_usb_audio_create_proc(chip); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*rchip = chip; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * probe the active usb device | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * note that this can be called multiple times per a device, when it | 
					
						
							|  |  |  |  * includes multiple audio control interfaces. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * thus we check the usb device pointer and creates the card instance | 
					
						
							|  |  |  |  * only at the first time.  the successive calls of this function will | 
					
						
							|  |  |  |  * append the pcm interface to the corresponding card. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | static int usb_audio_probe(struct usb_interface *intf, | 
					
						
							|  |  |  | 			   const struct usb_device_id *usb_id) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	struct usb_device *dev = interface_to_usbdev(intf); | 
					
						
							|  |  |  | 	const struct snd_usb_audio_quirk *quirk = | 
					
						
							|  |  |  | 		(const struct snd_usb_audio_quirk *)usb_id->driver_info; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	struct snd_usb_audio *chip; | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	int i, err; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	struct usb_host_interface *alts; | 
					
						
							|  |  |  | 	int ifnum; | 
					
						
							|  |  |  | 	u32 id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	alts = &intf->altsetting[0]; | 
					
						
							|  |  |  | 	ifnum = get_iface_desc(alts)->bInterfaceNumber; | 
					
						
							|  |  |  | 	id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), | 
					
						
							|  |  |  | 		    le16_to_cpu(dev->descriptor.idProduct)); | 
					
						
							|  |  |  | 	if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 		return -ENXIO; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	err = snd_usb_apply_boot_quirk(dev, intf, quirk); | 
					
						
							|  |  |  | 	if (err < 0) | 
					
						
							|  |  |  | 		return err; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * found a config.  now register to ALSA | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* check whether it's already registered */ | 
					
						
							|  |  |  | 	chip = NULL; | 
					
						
							|  |  |  | 	mutex_lock(®ister_mutex); | 
					
						
							|  |  |  | 	for (i = 0; i < SNDRV_CARDS; i++) { | 
					
						
							|  |  |  | 		if (usb_chip[i] && usb_chip[i]->dev == dev) { | 
					
						
							|  |  |  | 			if (usb_chip[i]->shutdown) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 				dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n"); | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 				err = -EIO; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 				goto __error; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			chip = usb_chip[i]; | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 			chip->probing = 1; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (! chip) { | 
					
						
							|  |  |  | 		/* it's a fresh one.
 | 
					
						
							|  |  |  | 		 * now look for an empty slot and create a new card instance | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		for (i = 0; i < SNDRV_CARDS; i++) | 
					
						
							|  |  |  | 			if (enable[i] && ! usb_chip[i] && | 
					
						
							|  |  |  | 			    (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) && | 
					
						
							|  |  |  | 			    (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) { | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 				err = snd_usb_audio_create(intf, dev, i, quirk, | 
					
						
							|  |  |  | 							   &chip); | 
					
						
							|  |  |  | 				if (err < 0) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 					goto __error; | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 				chip->pm_intf = intf; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		if (!chip) { | 
					
						
							| 
									
										
										
										
											2014-02-26 13:02:17 +01:00
										 |  |  | 			dev_err(&dev->dev, "no available usb audio device\n"); | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 			err = -ENODEV; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 			goto __error; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 17:13:15 +08:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * For devices with more than one control interface, we assume the | 
					
						
							|  |  |  | 	 * first contains the audio controls. We might need a more specific | 
					
						
							|  |  |  | 	 * check here in the future. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (!chip->ctrl_intf) | 
					
						
							|  |  |  | 		chip->ctrl_intf = alts; | 
					
						
							| 
									
										
										
										
											2010-05-31 14:51:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 09:08:59 +02:00
										 |  |  | 	chip->txfr_quirk = 0; | 
					
						
							|  |  |  | 	err = 1; /* continue */ | 
					
						
							|  |  |  | 	if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { | 
					
						
							|  |  |  | 		/* need some special handlings */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 		err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk); | 
					
						
							|  |  |  | 		if (err < 0) | 
					
						
							| 
									
										
										
										
											2011-05-25 09:08:59 +02:00
										 |  |  | 			goto __error; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	if (err > 0) { | 
					
						
							|  |  |  | 		/* create normal USB audio interfaces */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 		err = snd_usb_create_streams(chip, ifnum); | 
					
						
							|  |  |  | 		if (err < 0) | 
					
						
							|  |  |  | 			goto __error; | 
					
						
							|  |  |  | 		err = snd_usb_create_mixer(chip, ifnum, ignore_ctl_error); | 
					
						
							|  |  |  | 		if (err < 0) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 			goto __error; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* we are allowed to call snd_card_register() many times */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	err = snd_card_register(chip->card); | 
					
						
							|  |  |  | 	if (err < 0) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		goto __error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usb_chip[chip->index] = chip; | 
					
						
							|  |  |  | 	chip->num_interfaces++; | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	chip->probing = 0; | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	usb_set_intfdata(intf, chip); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	mutex_unlock(®ister_mutex); | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |  __error: | 
					
						
							| 
									
										
										
										
											2011-09-26 15:43:59 +02:00
										 |  |  | 	if (chip) { | 
					
						
							|  |  |  | 		if (!chip->num_interfaces) | 
					
						
							|  |  |  | 			snd_card_free(chip->card); | 
					
						
							|  |  |  | 		chip->probing = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	mutex_unlock(®ister_mutex); | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	return err; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * we need to take care of counter, since disconnection can be called also | 
					
						
							|  |  |  |  * many times as well as usb_audio_probe(). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | static void usb_audio_disconnect(struct usb_interface *intf) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 11:00:23 +01:00
										 |  |  | 	struct snd_usb_audio *chip = usb_get_intfdata(intf); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	struct snd_card *card; | 
					
						
							| 
									
										
										
										
											2014-06-25 14:24:47 +02:00
										 |  |  | 	struct list_head *p; | 
					
						
							| 
									
										
										
										
											2014-11-05 15:08:49 +01:00
										 |  |  | 	bool was_shutdown; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-06 11:20:13 -04:00
										 |  |  | 	if (chip == (void *)-1L) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	card = chip->card; | 
					
						
							| 
									
										
										
										
											2012-10-15 12:16:02 +02:00
										 |  |  | 	down_write(&chip->shutdown_rwsem); | 
					
						
							| 
									
										
										
										
											2014-11-05 15:08:49 +01:00
										 |  |  | 	was_shutdown = chip->shutdown; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	chip->shutdown = 1; | 
					
						
							| 
									
										
										
										
											2012-11-13 11:22:48 +01:00
										 |  |  | 	up_write(&chip->shutdown_rwsem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutex_lock(®ister_mutex); | 
					
						
							| 
									
										
										
										
											2014-11-05 15:08:49 +01:00
										 |  |  | 	if (!was_shutdown) { | 
					
						
							| 
									
										
										
										
											2014-10-31 11:24:32 +01:00
										 |  |  | 		struct snd_usb_stream *as; | 
					
						
							| 
									
										
										
										
											2014-06-25 14:24:47 +02:00
										 |  |  | 		struct snd_usb_endpoint *ep; | 
					
						
							| 
									
										
										
										
											2014-10-31 11:24:32 +01:00
										 |  |  | 		struct usb_mixer_interface *mixer; | 
					
						
							| 
									
										
										
										
											2014-06-25 14:24:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		snd_card_disconnect(card); | 
					
						
							|  |  |  | 		/* release the pcm resources */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:24:32 +01:00
										 |  |  | 		list_for_each_entry(as, &chip->pcm_list, list) { | 
					
						
							|  |  |  | 			snd_usb_stream_disconnect(as); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-04-12 13:51:12 +02:00
										 |  |  | 		/* release the endpoint resources */ | 
					
						
							| 
									
										
										
										
											2014-06-25 14:24:47 +02:00
										 |  |  | 		list_for_each_entry(ep, &chip->ep_list, list) { | 
					
						
							|  |  |  | 			snd_usb_endpoint_release(ep); | 
					
						
							| 
									
										
										
										
											2012-04-12 13:51:12 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		/* release the midi resources */ | 
					
						
							|  |  |  | 		list_for_each(p, &chip->midi_list) { | 
					
						
							|  |  |  | 			snd_usbmidi_disconnect(p); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* release mixer resources */ | 
					
						
							| 
									
										
										
										
											2014-10-31 11:24:32 +01:00
										 |  |  | 		list_for_each_entry(mixer, &chip->mixer_list, list) { | 
					
						
							|  |  |  | 			snd_usb_mixer_disconnect(mixer); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-11-05 15:08:49 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	chip->num_interfaces--; | 
					
						
							|  |  |  | 	if (chip->num_interfaces <= 0) { | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 		usb_chip[chip->index] = NULL; | 
					
						
							|  |  |  | 		mutex_unlock(®ister_mutex); | 
					
						
							|  |  |  | 		snd_card_free_when_closed(card); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		mutex_unlock(®ister_mutex); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_PM
 | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | int snd_usb_autoresume(struct snd_usb_audio *chip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int err = -ENODEV; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-15 12:16:02 +02:00
										 |  |  | 	down_read(&chip->shutdown_rwsem); | 
					
						
							| 
									
										
										
										
											2014-05-02 18:17:06 +02:00
										 |  |  | 	if (chip->probing && chip->in_pm) | 
					
						
							| 
									
										
										
										
											2013-04-25 07:38:15 +02:00
										 |  |  | 		err = 0; | 
					
						
							|  |  |  | 	else if (!chip->shutdown) | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 		err = usb_autopm_get_interface(chip->pm_intf); | 
					
						
							| 
									
										
										
										
											2012-10-15 12:16:02 +02:00
										 |  |  | 	up_read(&chip->shutdown_rwsem); | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void snd_usb_autosuspend(struct snd_usb_audio *chip) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-15 12:16:02 +02:00
										 |  |  | 	down_read(&chip->shutdown_rwsem); | 
					
						
							| 
									
										
										
										
											2014-05-02 18:17:06 +02:00
										 |  |  | 	if (!chip->shutdown && !chip->probing && !chip->in_pm) | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 		usb_autopm_put_interface(chip->pm_intf); | 
					
						
							| 
									
										
										
										
											2012-10-15 12:16:02 +02:00
										 |  |  | 	up_read(&chip->shutdown_rwsem); | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct snd_usb_audio *chip = usb_get_intfdata(intf); | 
					
						
							|  |  |  | 	struct snd_usb_stream *as; | 
					
						
							| 
									
										
										
										
											2011-03-11 13:19:43 +01:00
										 |  |  | 	struct usb_mixer_interface *mixer; | 
					
						
							| 
									
										
										
										
											2014-08-05 12:44:50 -04:00
										 |  |  | 	struct list_head *p; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (chip == (void *)-1L) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-19 23:49:48 +02:00
										 |  |  | 	if (!PMSG_IS_AUTO(message)) { | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 		snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); | 
					
						
							|  |  |  | 		if (!chip->num_suspended_intf++) { | 
					
						
							| 
									
										
										
										
											2013-04-03 23:18:49 +02:00
										 |  |  | 			list_for_each_entry(as, &chip->pcm_list, list) { | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 				snd_pcm_suspend_all(as->pcm); | 
					
						
							| 
									
										
										
										
											2012-09-18 14:49:31 +02:00
										 |  |  | 				as->substream[0].need_setup_ep = | 
					
						
							|  |  |  | 					as->substream[1].need_setup_ep = true; | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-08-05 12:44:50 -04:00
										 |  |  | 			list_for_each(p, &chip->midi_list) { | 
					
						
							|  |  |  | 				snd_usbmidi_suspend(p); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-29 12:56:30 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * otherwise we keep the rest of the system in the dark | 
					
						
							|  |  |  | 		 * to keep this transparent | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (!chip->num_suspended_intf++) | 
					
						
							|  |  |  | 			chip->autosuspended = 1; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-02 18:14:42 +02:00
										 |  |  | 	if (chip->num_suspended_intf == 1) | 
					
						
							|  |  |  | 		list_for_each_entry(mixer, &chip->mixer_list, list) | 
					
						
							|  |  |  | 			snd_usb_mixer_suspend(mixer); | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 16:51:16 +01:00
										 |  |  | static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct snd_usb_audio *chip = usb_get_intfdata(intf); | 
					
						
							| 
									
										
										
										
											2011-03-11 13:19:43 +01:00
										 |  |  | 	struct usb_mixer_interface *mixer; | 
					
						
							| 
									
										
										
										
											2014-08-05 12:44:50 -04:00
										 |  |  | 	struct list_head *p; | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	int err = 0; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (chip == (void *)-1L) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	if (--chip->num_suspended_intf) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2014-05-02 18:17:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	chip->in_pm = 1; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * ALSA leaves material resumption to user space | 
					
						
							| 
									
										
										
										
											2011-03-11 13:19:43 +01:00
										 |  |  | 	 * we just notify and restart the mixers | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	list_for_each_entry(mixer, &chip->mixer_list, list) { | 
					
						
							| 
									
										
										
										
											2014-01-20 16:51:16 +01:00
										 |  |  | 		err = snd_usb_mixer_resume(mixer, reset_resume); | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 		if (err < 0) | 
					
						
							|  |  |  | 			goto err_out; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 12:44:50 -04:00
										 |  |  | 	list_for_each(p, &chip->midi_list) { | 
					
						
							|  |  |  | 		snd_usbmidi_resume(p); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	if (!chip->autosuspended) | 
					
						
							|  |  |  | 		snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); | 
					
						
							|  |  |  | 	chip->autosuspended = 0; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | err_out: | 
					
						
							| 
									
										
										
										
											2014-05-02 18:17:06 +02:00
										 |  |  | 	chip->in_pm = 0; | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	return err; | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-20 16:51:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int usb_audio_resume(struct usb_interface *intf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return __usb_audio_resume(intf, false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int usb_audio_reset_resume(struct usb_interface *intf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return __usb_audio_resume(intf, true); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-03-22 08:55:35 -07:00
										 |  |  | #else
 | 
					
						
							|  |  |  | #define usb_audio_suspend	NULL
 | 
					
						
							|  |  |  | #define usb_audio_resume	NULL
 | 
					
						
							| 
									
										
										
										
											2014-01-20 16:51:16 +01:00
										 |  |  | #define usb_audio_reset_resume	NULL
 | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | #endif		/* CONFIG_PM */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct usb_device_id usb_audio_ids [] = { | 
					
						
							|  |  |  | #include "quirks-table.h"
 | 
					
						
							|  |  |  |     { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS), | 
					
						
							|  |  |  |       .bInterfaceClass = USB_CLASS_AUDIO, | 
					
						
							|  |  |  |       .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL }, | 
					
						
							|  |  |  |     { }						/* Terminating entry */ | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-04-03 23:18:50 +02:00
										 |  |  | MODULE_DEVICE_TABLE(usb, usb_audio_ids); | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * entry point for linux usb interface | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct usb_driver usb_audio_driver = { | 
					
						
							|  |  |  | 	.name =		"snd-usb-audio", | 
					
						
							|  |  |  | 	.probe =	usb_audio_probe, | 
					
						
							|  |  |  | 	.disconnect =	usb_audio_disconnect, | 
					
						
							|  |  |  | 	.suspend =	usb_audio_suspend, | 
					
						
							|  |  |  | 	.resume =	usb_audio_resume, | 
					
						
							| 
									
										
										
										
											2014-01-20 16:51:16 +01:00
										 |  |  | 	.reset_resume =	usb_audio_reset_resume, | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | 	.id_table =	usb_audio_ids, | 
					
						
							| 
									
										
										
										
											2011-03-11 14:51:12 +01:00
										 |  |  | 	.supports_autosuspend = 1, | 
					
						
							| 
									
										
										
										
											2010-03-04 19:46:13 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-09 17:22:32 +05:30
										 |  |  | module_usb_driver(usb_audio_driver); |