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>
This commit is contained in:
Harmandeep Singh 2012-03-05 16:38:33 -08:00 committed by Stephen Boyd
parent 806f50cdbb
commit a97a269128

View file

@ -48,6 +48,7 @@
#include <linux/usb/audio.h>
#include <linux/usb/audio-v2.h>
#include <linux/module.h>
#include <linux/switch.h>
#include <sound/control.h>
#include <sound/core.h>
@ -86,6 +87,7 @@ static int nrpacks = 8; /* max. number of packets per urb */
static bool async_unlink = 1;
static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
static bool 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.");
@ -419,6 +421,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
}
snd_usb_audio_create_proc(chip);
switch_set_state(usbaudiosdev, 1);
*rchip = chip;
return 0;
@ -581,6 +584,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
mutex_unlock(&chip->shutdown_mutex);
mutex_unlock(&register_mutex);
}
switch_set_state(usbaudiosdev, 0);
}
/*
@ -713,16 +717,27 @@ static struct usb_driver usb_audio_driver = {
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);