[alsa-devel] [PATCH 11/19] ASoC: upd9976: add jack detection function

Lu Guanqun guanqun.lu at intel.com
Wed May 4 15:45:50 CEST 2011


Signed-off-by: Lu Guanqun <guanqun.lu at intel.com>
---
 sound/soc/codecs/upd9976.c |   28 ++++++++++++++++++++++++++++
 sound/soc/codecs/upd9976.h |    2 ++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/sound/soc/codecs/upd9976.c b/sound/soc/codecs/upd9976.c
index 69d83ea..9231cee 100644
--- a/sound/soc/codecs/upd9976.c
+++ b/sound/soc/codecs/upd9976.c
@@ -60,6 +60,34 @@ static inline int upd9976_write(struct snd_soc_codec *codec,
 	return ret;
 }
 
+void upd9976_jack_detection(struct snd_soc_jack *jack, u8 interrupt_status)
+{
+	int status = 0;
+	unsigned int value = 0;
+	struct snd_soc_codec *codec = jack->codec;
+	int mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_HEADSET;
+
+	if (interrupt_status & 0x3)
+		value = snd_soc_read(codec, UPD9976_SAUXINT);
+
+	if (interrupt_status & 0x1 && value == 0x1)
+		status |= SND_JACK_HEADSET;
+
+	if (interrupt_status & 0x2 && value == 0x2)
+		status |= SND_JACK_HEADPHONE;
+
+	if (interrupt_status & 0x4)
+		status |= SND_JACK_HEADSET | SND_JACK_BTN_0;
+
+	if (interrupt_status & 0x8)
+		status |= SND_JACK_HEADSET | SND_JACK_BTN_1;
+
+	snd_soc_jack_report(jack, status, mask);
+	if (status & (SND_JACK_BTN_0 | SND_JACK_BTN_1))
+		snd_soc_jack_report(jack, SND_JACK_HEADSET, mask);
+}
+EXPORT_SYMBOL_GPL(upd9976_jack_detection);
+
 static int upd9976_mic2_bias_event(struct snd_soc_dapm_widget *widget,
 				   struct snd_kcontrol *kcontrol, int event)
 {
diff --git a/sound/soc/codecs/upd9976.h b/sound/soc/codecs/upd9976.h
index ab2ea15..090dd0b 100644
--- a/sound/soc/codecs/upd9976.h
+++ b/sound/soc/codecs/upd9976.h
@@ -80,4 +80,6 @@
 
 #define UPD9976_SAUXINT		0x132
 
+void upd9976_jack_detection(struct snd_soc_jack *jack, u8 interrupt_status);
+
 #endif



More information about the Alsa-devel mailing list