ASoC: sn95031: Add jack support in the codec
authorVinod Koul <vinod.koul@intel.com>
Wed, 9 Feb 2011 16:14:32 +0000 (21:44 +0530)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Wed, 9 Feb 2011 22:32:26 +0000 (22:32 +0000)
This patch adds support for jack detection and reporting in the codec
It however is not fully functional as it doesn't measure adc to figure
out what got inserted which will be added later

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Harsha Priya <priya.harsha@intel.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
sound/soc/codecs/sn95031.c
sound/soc/codecs/sn95031.h

index 40e285d..b49d790 100644 (file)
@@ -34,6 +34,7 @@
 #include <sound/soc-dapm.h>
 #include <sound/initval.h>
 #include <sound/tlv.h>
+#include <sound/jack.h>
 #include "sn95031.h"
 
 #define SN95031_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100)
@@ -649,6 +650,61 @@ struct snd_soc_dai_driver sn95031_dais[] = {
 },
 };
 
+static inline void sn95031_disable_jack_btn(struct snd_soc_codec *codec)
+{
+       snd_soc_write(codec, SN95031_BTNCTRL2, 0x00);
+}
+
+static inline void sn95031_enable_jack_btn(struct snd_soc_codec *codec)
+{
+       snd_soc_write(codec, SN95031_BTNCTRL1, 0x77);
+       snd_soc_write(codec, SN95031_BTNCTRL2, 0x01);
+}
+
+static int sn95031_get_headset_state(struct snd_soc_jack *mfld_jack)
+{
+       /* Defaulting to HEADSET for now.
+        * will change after adding soc-jack detection apis */
+       int jack_type = SND_JACK_HEADSET;
+
+       pr_debug("jack type detected = %d\n", jack_type);
+       if (jack_type == SND_JACK_HEADSET)
+               sn95031_enable_jack_btn(mfld_jack->codec);
+       return jack_type;
+}
+
+void sn95031_jack_detection(struct mfld_jack_data *jack_data)
+{
+       unsigned int status;
+       unsigned int mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_HEADSET;
+
+       pr_debug("interrupt id read in sram = 0x%x\n", jack_data->intr_id);
+       if (jack_data->intr_id & 0x1) {
+               pr_debug("short_push detected\n");
+               status = SND_JACK_HEADSET | SND_JACK_BTN_0;
+       } else if (jack_data->intr_id & 0x2) {
+               pr_debug("long_push detected\n");
+               status = SND_JACK_HEADSET | SND_JACK_BTN_1;
+       } else if (jack_data->intr_id & 0x4) {
+               pr_debug("headset or headphones inserted\n");
+               status = sn95031_get_headset_state(jack_data->mfld_jack);
+       } else if (jack_data->intr_id & 0x8) {
+               pr_debug("headset or headphones removed\n");
+               status = 0;
+               sn95031_disable_jack_btn(jack_data->mfld_jack->codec);
+       } else {
+               pr_err("unidentified interrupt\n");
+               return;
+       }
+
+       snd_soc_jack_report(jack_data->mfld_jack, status, mask);
+       /*button pressed and released so we send explicit button release */
+       if ((status & SND_JACK_BTN_0) | (status & SND_JACK_BTN_1))
+               snd_soc_jack_report(jack_data->mfld_jack,
+                               SND_JACK_HEADSET, mask);
+}
+EXPORT_SYMBOL_GPL(sn95031_jack_detection);
+
 /* codec registration */
 static int sn95031_codec_probe(struct snd_soc_codec *codec)
 {
index e2b17d9..2dbae61 100644 (file)
 #define SN95031_SSR5                   0x384
 #define SN95031_SSR6                   0x385
 
+#define SN95031_AUDIO_GPIO_CTRL 0x070
+struct mfld_jack_data {
+       int intr_id;
+       int micbias_vol;
+       struct snd_soc_jack *mfld_jack;
+};
+
+extern void sn95031_jack_detection(struct mfld_jack_data *jack_data);
+
 #endif