diff options
author | Nikesh Oswal <noswal@nvidia.com> | 2011-10-10 20:07:12 +0530 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2011-11-30 21:52:33 -0800 |
commit | 0aed5989a444d72f6490ab844888788753261bdd (patch) | |
tree | 31c5a9cd1c44462eb00a11eab3c559edbb026258 /sound/soc/tegra/tegra_wm8753.c | |
parent | dac7c231c0ce1b43db77d944352d8ddba3e4b9ee (diff) |
asoc: tegra: wm8753: add switch notifier code
Bug: 862023
Change-Id: Ic4ca5d1ab4173147f2b2161a4b45f38d12c2fc78
Signed-off-by: Nikesh Oswal <noswal@nvidia.com>
Reviewed-on: http://git-master/r/57054
Reviewed-by: Varun Colbert <vcolbert@nvidia.com>
Tested-by: Varun Colbert <vcolbert@nvidia.com>
Rebase-Id: Rc79878ef186bfc5ccec7049ce99806f894c65aa3
Diffstat (limited to 'sound/soc/tegra/tegra_wm8753.c')
-rw-r--r-- | sound/soc/tegra/tegra_wm8753.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/sound/soc/tegra/tegra_wm8753.c b/sound/soc/tegra/tegra_wm8753.c index 6997220794b4..bc9e3104b605 100644 --- a/sound/soc/tegra/tegra_wm8753.c +++ b/sound/soc/tegra/tegra_wm8753.c @@ -35,6 +35,9 @@ #include <linux/slab.h> #include <linux/gpio.h> #include <linux/regulator/consumer.h> +#ifdef CONFIG_SWITCH +#include <linux/switch.h> +#endif #include <mach/tegra_wm8753_pdata.h> @@ -302,12 +305,46 @@ static struct snd_soc_ops tegra_spdif_ops = { static struct snd_soc_jack tegra_wm8753_hp_jack; +#ifdef CONFIG_SWITCH +static struct switch_dev wired_switch_dev = { + .name = "h2w", +}; + +/* These values are copied from WiredAccessoryObserver */ +enum headset_state { + BIT_NO_HEADSET = 0, + BIT_HEADSET = (1 << 0), + BIT_HEADSET_NO_MIC = (1 << 1), +}; + +static int headset_switch_notify(struct notifier_block *self, + unsigned long action, void *dev) +{ + switch (action) { + case SND_JACK_HEADPHONE: + switch_set_state(&wired_switch_dev, BIT_HEADSET_NO_MIC); + break; + case SND_JACK_HEADSET: + switch_set_state(&wired_switch_dev, BIT_HEADSET); + break; + default: + switch_set_state(&wired_switch_dev, BIT_NO_HEADSET); + } + + return NOTIFY_OK; +} + +static struct notifier_block headset_switch_nb = { + .notifier_call = headset_switch_notify, +}; +#else static struct snd_soc_jack_pin tegra_wm8753_hp_jack_pins[] = { { .pin = "Headphone Jack", .mask = SND_JACK_HEADPHONE, }, }; +#endif static int tegra_wm8753_event_int_spk(struct snd_soc_dapm_widget *w, struct snd_kcontrol *k, int event) @@ -469,9 +506,14 @@ static int tegra_wm8753_init(struct snd_soc_pcm_runtime *rtd) &tegra_wm8753_hp_jack); wm8753_headphone_detect(codec, &tegra_wm8753_hp_jack, SND_JACK_HEADPHONE, pdata->debounce_time_hp); +#ifdef CONFIG_SWITCH + snd_soc_jack_notifier_register(&tegra_wm8753_hp_jack, + &headset_switch_nb); +#else snd_soc_jack_add_pins(&tegra_wm8753_hp_jack, ARRAY_SIZE(tegra_wm8753_hp_jack_pins), tegra_wm8753_hp_jack_pins); +#endif snd_soc_dapm_nc_pin(dapm, "ACIN"); snd_soc_dapm_nc_pin(dapm, "ACOP"); @@ -558,8 +600,20 @@ static __devinit int tegra_wm8753_driver_probe(struct platform_device *pdev) goto err_fini_utils; } +#ifdef CONFIG_SWITCH + /* Add h2w swith class support */ + ret = switch_dev_register(&wired_switch_dev); + if (ret < 0) { + dev_err(&pdev->dev, "not able to register switch device\n", + ret); + goto err_unregister_card; + } +#endif + return 0; +err_unregister_card: + snd_soc_unregister_card(card); err_fini_utils: tegra_asoc_utils_fini(&machine->util_data); err_free_machine: @@ -575,6 +629,10 @@ static int __devexit tegra_wm8753_driver_remove(struct platform_device *pdev) snd_soc_unregister_card(card); +#ifdef CONFIG_SWITCH + switch_dev_unregister(&wired_switch_dev); +#endif + tegra_asoc_utils_fini(&machine->util_data); if (machine->gpio_requested & GPIO_EXT_MIC_EN) |