All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: Ensure we get an impedence reported for WM8958 jack detect
@ 2011-08-21 12:28 Mark Brown
  2011-08-22 10:26 ` Liam Girdwood
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Brown @ 2011-08-21 12:28 UTC (permalink / raw)
  To: Liam Girdwood; +Cc: alsa-devel, patches, Mark Brown

Occasionally we may see an accessory reported before we have a stable
impedance for the accessory. If this happens then reread the status in
order to ensure that the handler can take the appropriate action for the
status change.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 include/linux/mfd/wm8994/registers.h |   15 +++++++++++++
 sound/soc/codecs/wm8994.c            |   37 +++++++++++++++++++++++----------
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/include/linux/mfd/wm8994/registers.h b/include/linux/mfd/wm8994/registers.h
index d7be463..10c483f 100644
--- a/include/linux/mfd/wm8994/registers.h
+++ b/include/linux/mfd/wm8994/registers.h
@@ -1967,6 +1967,21 @@
 #define WM8958_MICB2_DISCH_WIDTH                     1  /* MICB2_DISCH */
 
 /*
+ * R210 (0xD2) - Mic Detect 3
+ */
+#define WM8958_MICD_LVL_MASK                    0x07FC  /* MICD_LVL - [10:2] */
+#define WM8958_MICD_LVL_SHIFT                        2  /* MICD_LVL - [10:2] */
+#define WM8958_MICD_LVL_WIDTH                        9  /* MICD_LVL - [10:2] */
+#define WM8958_MICD_VALID                       0x0002  /* MICD_VALID */
+#define WM8958_MICD_VALID_MASK                  0x0002  /* MICD_VALID */
+#define WM8958_MICD_VALID_SHIFT                      1  /* MICD_VALID */
+#define WM8958_MICD_VALID_WIDTH                      1  /* MICD_VALID */
+#define WM8958_MICD_STS                         0x0001  /* MICD_STS */
+#define WM8958_MICD_STS_MASK                    0x0001  /* MICD_STS */
+#define WM8958_MICD_STS_SHIFT                        0  /* MICD_STS */
+#define WM8958_MICD_STS_WIDTH                        1  /* MICD_STS */
+
+/*
  * R76 (0x4C) - Charge Pump (1)
  */
 #define WM8994_CP_ENA                           0x8000  /* CP_ENA */
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 5e8d66d..a26cee1 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -3043,19 +3043,34 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
 {
 	struct wm8994_priv *wm8994 = data;
 	struct snd_soc_codec *codec = wm8994->codec;
-	int reg;
+	int reg, count;
 
-	reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
-	if (reg < 0) {
-		dev_err(codec->dev, "Failed to read mic detect status: %d\n",
-			reg);
-		return IRQ_NONE;
-	}
+	/* We may occasionally read a detection without an impedence
+	 * range being provided - if that happens loop again.
+	 */
+	count = 10;
+	do {
+		reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
+		if (reg < 0) {
+			dev_err(codec->dev,
+				"Failed to read mic detect status: %d\n",
+				reg);
+			return IRQ_NONE;
+		}
 
-	if (!(reg & WM8958_MICD_VALID)) {
-		dev_dbg(codec->dev, "Mic detect data not valid\n");
-		goto out;
-	}
+		if (!(reg & WM8958_MICD_VALID)) {
+			dev_dbg(codec->dev, "Mic detect data not valid\n");
+			goto out;
+		}
+
+		if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
+			break;
+
+		msleep(1);
+	} while (count--);
+
+	if (count == 0)
+		dev_warn(codec->dev, "No impedence range reported for jack\n");
 
 #ifndef CONFIG_SND_SOC_WM8994_MODULE
 	trace_snd_soc_jack_irq(dev_name(codec->dev));
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASoC: Ensure we get an impedence reported for WM8958 jack detect
  2011-08-21 12:28 [PATCH] ASoC: Ensure we get an impedence reported for WM8958 jack detect Mark Brown
@ 2011-08-22 10:26 ` Liam Girdwood
  0 siblings, 0 replies; 2+ messages in thread
From: Liam Girdwood @ 2011-08-22 10:26 UTC (permalink / raw)
  To: Mark Brown
  Cc: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com

On 21/08/11 13:28, Mark Brown wrote:
> Occasionally we may see an accessory reported before we have a stable
> impedance for the accessory. If this happens then reread the status in
> order to ensure that the handler can take the appropriate action for the
> status change.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
>  include/linux/mfd/wm8994/registers.h |   15 +++++++++++++
>  sound/soc/codecs/wm8994.c            |   37 +++++++++++++++++++++++----------
>  2 files changed, 41 insertions(+), 11 deletions(-)
> 
> diff --git a/include/linux/mfd/wm8994/registers.h b/include/linux/mfd/wm8994/registers.h
> index d7be463..10c483f 100644
> --- a/include/linux/mfd/wm8994/registers.h
> +++ b/include/linux/mfd/wm8994/registers.h
> @@ -1967,6 +1967,21 @@
>  #define WM8958_MICB2_DISCH_WIDTH                     1  /* MICB2_DISCH */
>  
>  /*
> + * R210 (0xD2) - Mic Detect 3
> + */
> +#define WM8958_MICD_LVL_MASK                    0x07FC  /* MICD_LVL - [10:2] */
> +#define WM8958_MICD_LVL_SHIFT                        2  /* MICD_LVL - [10:2] */
> +#define WM8958_MICD_LVL_WIDTH                        9  /* MICD_LVL - [10:2] */
> +#define WM8958_MICD_VALID                       0x0002  /* MICD_VALID */
> +#define WM8958_MICD_VALID_MASK                  0x0002  /* MICD_VALID */
> +#define WM8958_MICD_VALID_SHIFT                      1  /* MICD_VALID */
> +#define WM8958_MICD_VALID_WIDTH                      1  /* MICD_VALID */
> +#define WM8958_MICD_STS                         0x0001  /* MICD_STS */
> +#define WM8958_MICD_STS_MASK                    0x0001  /* MICD_STS */
> +#define WM8958_MICD_STS_SHIFT                        0  /* MICD_STS */
> +#define WM8958_MICD_STS_WIDTH                        1  /* MICD_STS */
> +
> +/*
>   * R76 (0x4C) - Charge Pump (1)
>   */
>  #define WM8994_CP_ENA                           0x8000  /* CP_ENA */
> diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
> index 5e8d66d..a26cee1 100644
> --- a/sound/soc/codecs/wm8994.c
> +++ b/sound/soc/codecs/wm8994.c
> @@ -3043,19 +3043,34 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
>  {
>  	struct wm8994_priv *wm8994 = data;
>  	struct snd_soc_codec *codec = wm8994->codec;
> -	int reg;
> +	int reg, count;
>  
> -	reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
> -	if (reg < 0) {
> -		dev_err(codec->dev, "Failed to read mic detect status: %d\n",
> -			reg);
> -		return IRQ_NONE;
> -	}
> +	/* We may occasionally read a detection without an impedence
> +	 * range being provided - if that happens loop again.
> +	 */
> +	count = 10;
> +	do {
> +		reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
> +		if (reg < 0) {
> +			dev_err(codec->dev,
> +				"Failed to read mic detect status: %d\n",
> +				reg);
> +			return IRQ_NONE;
> +		}
>  
> -	if (!(reg & WM8958_MICD_VALID)) {
> -		dev_dbg(codec->dev, "Mic detect data not valid\n");
> -		goto out;
> -	}
> +		if (!(reg & WM8958_MICD_VALID)) {
> +			dev_dbg(codec->dev, "Mic detect data not valid\n");
> +			goto out;
> +		}
> +
> +		if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK))
> +			break;
> +
> +		msleep(1);
> +	} while (count--);
> +
> +	if (count == 0)
> +		dev_warn(codec->dev, "No impedence range reported for jack\n");
>  
>  #ifndef CONFIG_SND_SOC_WM8994_MODULE
>  	trace_snd_soc_jack_irq(dev_name(codec->dev));

Acked-by: Liam Girdwood <lrg@ti.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-22 10:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-21 12:28 [PATCH] ASoC: Ensure we get an impedence reported for WM8958 jack detect Mark Brown
2011-08-22 10:26 ` Liam Girdwood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.