summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorRavindra Lokhande <rlokhande@nvidia.com>2012-07-27 22:36:29 +0530
committerLokesh Pathak <lpathak@nvidia.com>2012-07-30 08:44:11 -0700
commit8843c49092b6ed903e88eded1f1c9b9a7f432dfe (patch)
treed6933fb561934d61874689da14e53a137b4b65b1 /sound
parent20e63194505625691dd93fc613cd4268430f6bc3 (diff)
ALSA: usb-audio: register switch device
regsiter android switch device which is used to convey device plug-in and plug-out to userspace. Bugs 1009921, 1019877 Change-Id: I8e3c2fce420cc0ce094a6d8f2cf00abb630fcf2f Reviewed-on: http://git-master/r/119033 Tested-by: Ravindra Lokhande <rlokhande@nvidia.com> Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Scott Peterson <speterson@nvidia.com> Reviewed-by: Vijay Mali <vmali@nvidia.com>
Diffstat (limited to 'sound')
-rw-r--r--sound/usb/card.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/sound/usb/card.c b/sound/usb/card.c
index d8f2bf401458..fca3f56fbb30 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -35,7 +35,6 @@
* 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>
@@ -47,6 +46,9 @@
#include <linux/mutex.h>
#include <linux/usb/audio.h>
#include <linux/usb/audio-v2.h>
+#ifdef CONFIG_SWITCH
+#include <linux/switch.h>
+#endif
#include <sound/control.h>
#include <sound/core.h>
@@ -115,6 +117,18 @@ static DEFINE_MUTEX(register_mutex);
static struct snd_usb_audio *usb_chip[SNDRV_CARDS];
static struct usb_driver usb_audio_driver;
+#ifdef CONFIG_SWITCH
+enum switch_state {
+ STATE_CONNECTED_UNKNOWN = -1,
+ STATE_DISCONNECTED = 0,
+ STATE_CONNECTED = 1
+};
+
+static struct switch_dev usb_switch_dev = {
+ .name = "usb_audio",
+};
+#endif
+
/*
* disconnect streams
* called from snd_usb_audio_disconnect()
@@ -523,10 +537,15 @@ snd_usb_audio_probe(struct usb_device *dev,
goto __error;
}
+#ifdef CONFIG_SWITCH
+ switch_set_state(&usb_switch_dev, STATE_CONNECTED);
+#endif
+
usb_chip[chip->index] = chip;
chip->num_interfaces++;
chip->probing = 0;
mutex_unlock(&register_mutex);
+
return chip;
__error:
@@ -537,6 +556,7 @@ snd_usb_audio_probe(struct usb_device *dev,
}
mutex_unlock(&register_mutex);
__err_val:
+
return NULL;
}
@@ -558,6 +578,11 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
mutex_lock(&chip->shutdown_mutex);
chip->shutdown = 1;
chip->num_interfaces--;
+
+#ifdef CONFIG_SWITCH
+ switch_set_state(&usb_switch_dev, STATE_DISCONNECTED);
+#endif
+
if (chip->num_interfaces <= 0) {
snd_card_disconnect(card);
/* release the pcm resources */
@@ -712,15 +737,35 @@ static struct usb_driver usb_audio_driver = {
static int __init snd_usb_audio_init(void)
{
+ int err = 0;
+
if (nrpacks < 1 || nrpacks > MAX_PACKS) {
printk(KERN_WARNING "invalid nrpacks value.\n");
return -EINVAL;
}
- return usb_register(&usb_audio_driver);
+
+#ifdef CONFIG_SWITCH
+ /* Add usb_audio swith class support */
+ err = switch_dev_register(&usb_switch_dev);
+ if (err < 0){
+ printk(KERN_ERR "failed to register switch device");
+ return -EINVAL;
+ }
+#endif
+
+ err = usb_register(&usb_audio_driver);
+ if (err) {
+ switch_dev_unregister(&usb_switch_dev);
+ }
+
+ return err;
}
static void __exit snd_usb_audio_cleanup(void)
{
+#ifdef CONFIG_SWITCH
+ switch_dev_unregister(&usb_switch_dev);
+#endif
usb_deregister(&usb_audio_driver);
}