asoc: tegra: ALC5640 machine: Add headset detect support
Manoj Gangwal [Wed, 29 Feb 2012 14:21:36 +0000 (19:21 +0530)]
Add support for headset detection on kai board.

Bug 937914

Change-Id: Ic69f5ffda45f71c3f566533ef74fd2a94d82894c
Signed-off-by: Manoj Gangwal <mgangwal@nvidia.com>
Reviewed-on: http://git-master/r/86601
Reviewed-by: Chandler Zhang <chazhang@nvidia.com>
Reviewed-by: Sachin Nikam <snikam@nvidia.com>

sound/soc/tegra/tegra_rt5640.c

index 21264eb..60d1837 100644 (file)
@@ -45,6 +45,7 @@
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
 
+#include "../codecs/rt5639.h"
 #include "../codecs/rt5640.h"
 
 #include "tegra_pcm.h"
@@ -277,13 +278,39 @@ static int tegra_rt5640_jack_notifier(struct notifier_block *self,
        struct snd_soc_card *card = codec->card;
        struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
        enum headset_state state = BIT_NO_HEADSET;
+       unsigned char status_jack;
 
        if (jack == &tegra_rt5640_hp_jack) {
-               machine->jack_status &= ~SND_JACK_HEADPHONE;
-               machine->jack_status |= (action & SND_JACK_HEADPHONE);
-       } else {
-               machine->jack_status &= ~SND_JACK_MICROPHONE;
-               machine->jack_status |= (action & SND_JACK_MICROPHONE);
+               if (action) {
+                       if (!strncmp(machine->pdata->codec_name, "rt5639", 6))
+                               status_jack = rt5639_headset_detect(codec, 1);
+                       else if (!strncmp(machine->pdata->codec_name, "rt5640",
+                                                                           6))
+                               status_jack = rt5640_headset_detect(codec, 1);
+
+                       machine->jack_status &= ~SND_JACK_HEADPHONE;
+                       machine->jack_status &= ~SND_JACK_MICROPHONE;
+                       if (status_jack == RT5639_HEADPHO_DET ||
+                           status_jack == RT5640_HEADPHO_DET)
+                                       machine->jack_status |=
+                                                       SND_JACK_HEADPHONE;
+                       else if (status_jack == RT5639_HEADSET_DET ||
+                                status_jack == RT5640_HEADSET_DET) {
+                                       machine->jack_status |=
+                                                       SND_JACK_HEADPHONE;
+                                       machine->jack_status |=
+                                                       SND_JACK_MICROPHONE;
+                       }
+               } else {
+                       if (!strncmp(machine->pdata->codec_name, "rt5639", 6))
+                               rt5639_headset_detect(codec, 0);
+                       else if (!strncmp(machine->pdata->codec_name, "rt5640",
+                                                                           6))
+                               rt5640_headset_detect(codec, 0);
+
+                       machine->jack_status &= ~SND_JACK_HEADPHONE;
+                       machine->jack_status &= ~SND_JACK_MICROPHONE;
+               }
        }
 
        switch (machine->jack_status) {
@@ -315,12 +342,6 @@ static struct snd_soc_jack_pin tegra_rt5640_hp_jack_pins[] = {
        },
 };
 
-static struct snd_soc_jack_pin tegra_rt5640_mic_jack_pins[] = {
-       {
-               .pin = "Mic Jack",
-               .mask = SND_JACK_MICROPHONE,
-       },
-};
 #endif
 
 static int tegra_rt5640_event_int_spk(struct snd_soc_dapm_widget *w,