Skip to contentSkip to conversation

ASoC: Use delayed work to debounce WM8350 jack IRQs

PATCH In review Mark Brown 2 participants 4 messages Dec 22, 2010

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/2 ASoC: Use delayed work to debounce WM8350 jack IRQs

This avoids blocking the IRQ thread and allows further bounces to extend the debounce time.

---
 sound/soc/codecs/wm8350.c |   62 +++++++++++++++++++++++++++++++-------------
 1 files changed, 43 insertions(+), 19 deletions(-)
sound/soc/codecs/wm8350.c +43 -19
index 07ba7e3..3e0362e 100644
@@ -53,6 +53,7 @@ struct wm8350_output {
 
 struct wm8350_jack_data {
 	struct snd_soc_jack *jack;
+	struct delayed_work work;
 	int report;
 	int short_report;
 };
@@ -1335,45 +1336,63 @@ static int wm8350_resume(struct snd_soc_codec *codec)
 	return 0;
 }
 
-static irqreturn_t wm8350_hp_jack_handler(int irq, void *data)
+static void wm8350_hp_work(struct wm8350_data *priv,
+			   struct wm8350_jack_data *jack,
+			   u16 mask)
 {
-	struct wm8350_data *priv = data;
 	struct wm8350 *wm8350 = priv->codec.control_data;
 	u16 reg;
 	int report;
-	int mask;
+
+	reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
+	if (reg & mask)
+		report = jack->report;
+	else
+		report = 0;
+
+	snd_soc_jack_report(jack->jack, report, jack->report);
+
+}
+
+static void wm8350_hpl_work(struct work_struct *work)
+{
+	struct wm8350_data *priv =
+	    container_of(work, struct wm8350_data, hpl.work.work);
+
+	wm8350_hp_work(priv, &priv->hpl, WM8350_JACK_L_LVL);
+}
+
+static void wm8350_hpr_work(struct work_struct *work)
+{
+	struct wm8350_data *priv =
+	    container_of(work, struct wm8350_data, hpr.work.work);
+	
+	wm8350_hp_work(priv, &priv->hpr, WM8350_JACK_R_LVL);
+}
+
+static irqreturn_t wm8350_hp_jack_handler(int irq, void *data)
+{
+	struct wm8350_data *priv = data;
+	struct wm8350 *wm8350 = priv->codec.control_data;
 	struct wm8350_jack_data *jack = NULL;
 
 	switch (irq - wm8350->irq_base) {
 	case WM8350_IRQ_CODEC_JCK_DET_L:
 		jack = &priv->hpl;
-		mask = WM8350_JACK_L_LVL;
 		break;
 
 	case WM8350_IRQ_CODEC_JCK_DET_R:
 		jack = &priv->hpr;
-		mask = WM8350_JACK_R_LVL;
 		break;
 
 	default:
 		BUG();
 	}
 
-	if (!jack->jack) {
-		dev_warn(wm8350->dev, "Jack interrupt called with no jack\n");
-		return IRQ_NONE;
-	}
+	if (device_may_wakeup(wm8350->dev))
+		pm_wakeup_event(wm8350->dev, 250);
 
-	/* Debounce */
-	msleep(200);
-
-	reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
-	if (reg & mask)
-		report = jack->report;
-	else
-		report = 0;
-
-	snd_soc_jack_report(jack->jack, report, jack->report);
+	schedule_delayed_work(&jack->work, 200);
 
 	return IRQ_HANDLED;
 }
@@ -1552,6 +1571,8 @@ static  int wm8350_codec_probe(struct snd_soc_codec *codec)
 	wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
 
 	INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8350_pga_work);
+	INIT_DELAYED_WORK(&priv->hpl.work, wm8350_hpl_work);
+	INIT_DELAYED_WORK(&priv->hpr.work, wm8350_hpr_work);
 
 	/* Enable the codec */
 	wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
@@ -1641,6 +1662,9 @@ static int  wm8350_codec_remove(struct snd_soc_codec *codec)
 	priv->hpr.jack = NULL;
 	priv->mic.jack = NULL;
 
+	cancel_delayed_work_sync(&priv->hpl.work);
+	cancel_delayed_work_sync(&priv->hpr.work);
+
 	/* if there was any work waiting then we run it now and
 	 * wait for its completion */
 	flush_delayed_work_sync(&codec->dapm.delayed_work);
Signature · 1 line
1.7.2.3
author
#1 lore raw

PATCH 2/2 ASoC: Trace Wolfson jack detection IRQs

Add jack detection interrupt trace to Wolfson CODEC drivers.

---
 sound/soc/codecs/wm8350.c |    5 +++++
 sound/soc/codecs/wm8903.c |    4 ++++
 sound/soc/codecs/wm8962.c |    3 +++
 sound/soc/codecs/wm8994.c |    5 +++++
 4 files changed, 17 insertions(+), 0 deletions(-)
sound/soc/codecs/wm8350.c +5 -0
index 3e0362e..82d877d 100644
@@ -26,6 +26,7 @@
 #include <sound/soc.h>
 #include <sound/initval.h>
 #include <sound/tlv.h>
+#include <trace/events/asoc.h>
 
 #include "wm8350.h"
 
@@ -1378,10 +1379,12 @@ static irqreturn_t wm8350_hp_jack_handler(int irq, void *data)
 
 	switch (irq - wm8350->irq_base) {
 	case WM8350_IRQ_CODEC_JCK_DET_L:
+		trace_snd_soc_jack_irq("WM8350 HPL");
 		jack = &priv->hpl;
 		break;
 
 	case WM8350_IRQ_CODEC_JCK_DET_R:
+		trace_snd_soc_jack_irq("WM8350 HPR");
 		jack = &priv->hpr;
 		break;
 
@@ -1456,6 +1459,8 @@ static irqreturn_t wm8350_mic_handler(int irq, void *data)
 	u16 reg;
 	int report = 0;
 
+	trace_snd_soc_jack_irq("WM8350 mic");
+
 	reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
 	if (reg & WM8350_JACK_MICSCD_LVL)
 		report |= priv->mic.short_report;
sound/soc/codecs/wm8903.c +4 -0
index d015745..b32699b 100644
@@ -31,6 +31,7 @@
 #include <sound/soc.h>
 #include <sound/initval.h>
 #include <sound/wm8903.h>
+#include <trace/events/asoc.h>
 
 #include "wm8903.h"
 
@@ -1533,6 +1534,9 @@ static irqreturn_t wm8903_irq(int irq, void *data)
 	mic_report = wm8903->mic_last_report;
 	int_pol = snd_soc_read(codec, WM8903_INTERRUPT_POLARITY_1);
 
+	if (int_val & (WM8903_MICSHRT_EINT | WM8903_MICDET_EINT))
+		trace_snd_soc_jack_irq(dev_name(codec->dev));
+
 	if (int_val & WM8903_MICSHRT_EINT) {
 		dev_dbg(codec->dev, "Microphone short (pol=%x)\n", int_pol);
 
sound/soc/codecs/wm8962.c +3 -0
index f0c9d26..a24f83d 100644
@@ -32,6 +32,7 @@
 #include <sound/initval.h>
 #include <sound/tlv.h>
 #include <sound/wm8962.h>
+#include <trace/events/asoc.h>
 
 #include "wm8962.h"
 
@@ -3353,6 +3354,8 @@ static irqreturn_t wm8962_irq(int irq, void *data)
 	if (active & (WM8962_MICSCD_EINT | WM8962_MICD_EINT)) {
 		dev_dbg(codec->dev, "Microphone event detected\n");
 
+		trace_snd_soc_jack_irq(dev_name(codec->dev));
+
 		pm_wakeup_event(codec->dev, 300);
 
 		schedule_delayed_work(&wm8962->mic_work,
sound/soc/codecs/wm8994.c +5 -0
index e1a775b..067a532 100644
@@ -28,6 +28,7 @@
 #include <sound/soc.h>
 #include <sound/initval.h>
 #include <sound/tlv.h>
+#include <trace/events/asoc.h>
 
 #include <linux/mfd/wm8994/core.h>
 #include <linux/mfd/wm8994/registers.h>
@@ -2755,6 +2756,8 @@ static irqreturn_t wm8994_mic_irq(int irq, void *data)
 	int reg;
 	int report;
 
+	trace_snd_soc_jack_irq(dev_name(codec->dev));
+
 	reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
 	if (reg < 0) {
 		dev_err(codec->dev, "Failed to read microphone status: %d\n",
@@ -2901,6 +2904,8 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
 		goto out;
 	}
 
+	trace_snd_soc_jack_irq(dev_name(codec->dev));
+
 	if (wm8994->jack_cb)
 		wm8994->jack_cb(reg, wm8994->jack_cb_data);
 	else
Signature · 1 line
1.7.2.3
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] ASoC: Trace Wolfson jack detection IRQs

Quoted 9 lines · Mark Brown

Add jack detection interrupt trace to Wolfson CODEC drivers.

---
 sound/soc/codecs/wm8350.c |    5 +++++
 sound/soc/codecs/wm8903.c |    4 ++++
 sound/soc/codecs/wm8962.c |    3 +++
 sound/soc/codecs/wm8994.c |    5 +++++
 4 files changed, 17 insertions(+), 0 deletions(-)
Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
Acked-by on v1 1/2
#3 lore raw
In reply to Mark Brown
Quoted 8 lines · Mark Brown

This avoids blocking the IRQ thread and allows further bounces to extend the debounce time.

---
 sound/soc/codecs/wm8350.c |   62 +++++++++++++++++++++++++++++++-------------
 1 files changed, 43 insertions(+), 19 deletions(-)
Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk