msm: usbaudio: Add support for USB headset detection

 - During bootup, create a file system storing the
   information about usb device state and name, and
   broadcast the message to userspace whenever the
   device is plugged or unplugged.

 - Register the device at USB sound card initialization
   for creating file system and toggle the state in that
   filesystem when USB is plugged/unplugged. This will
   also send a message to user space informing it about
   state change.

Change-Id: Icd78273bb765a26bbc70725afebe8955de8f7315
Signed-off-by: Harmandeep Singh <hsingh@codeaurora.org>
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 57a8e2d..12dfa0a 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -47,6 +47,7 @@
 #include <linux/mutex.h>
 #include <linux/usb/audio.h>
 #include <linux/usb/audio-v2.h>
+#include <linux/switch.h>
 
 #include <sound/control.h>
 #include <sound/core.h>
@@ -85,6 +86,7 @@
 static int async_unlink = 1;
 static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
 static int ignore_ctl_error;
+struct switch_dev *usbaudiosdev;
 
 module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
@@ -418,6 +420,7 @@
 	}
 
 	snd_usb_audio_create_proc(chip);
+	switch_set_state(usbaudiosdev, 1);
 
 	*rchip = chip;
 	return 0;
@@ -580,6 +583,7 @@
 		mutex_unlock(&chip->shutdown_mutex);
 		mutex_unlock(&register_mutex);
 	}
+	switch_set_state(usbaudiosdev, 0);
 }
 
 /*
@@ -712,16 +716,27 @@
 
 static int __init snd_usb_audio_init(void)
 {
+	int err;
 	if (nrpacks < 1 || nrpacks > MAX_PACKS) {
 		printk(KERN_WARNING "invalid nrpacks value.\n");
 		return -EINVAL;
 	}
+
+	usbaudiosdev = kzalloc(sizeof(usbaudiosdev), GFP_KERNEL);
+	usbaudiosdev->name = "usb_audio";
+
+	err = switch_dev_register(usbaudiosdev);
+	if (err)
+		pr_err("Usb-audio switch registration failed\n");
+	else
+		pr_debug("usb hs_detected\n");
 	return usb_register(&usb_audio_driver);
 }
 
 static void __exit snd_usb_audio_cleanup(void)
 {
 	usb_deregister(&usb_audio_driver);
+	kfree(usbaudiosdev);
 }
 
 module_init(snd_usb_audio_init);