aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-03-12 16:31:50 +0000
committerAndreas Blaesius <skate4life@gmx.de>2016-04-30 11:03:55 +0200
commitf3836e62258dac17710b7324bdaddff38c850493 (patch)
tree66152242d1a9f75f8fae7e2134549501a98e6efb /sound
parent2737355b1c04b04d832561edf0b434b0993fe3c1 (diff)
downloadkernel_samsung_espresso10-f3836e62258dac17710b7324bdaddff38c850493.zip
kernel_samsung_espresso10-f3836e62258dac17710b7324bdaddff38c850493.tar.gz
kernel_samsung_espresso10-f3836e62258dac17710b7324bdaddff38c850493.tar.bz2
ASoC: wm8994: Prevent ABBA deadlock with CODEC and accdet mutexes
Currently we can the accdet mutex from within DAPM when updating the device state which means we take accdet then the CODEC mutex but we also do the locking the other way around when responding to the jackdet IRQ. Move all the jackdet use of the CODEC mutex out of the accdet lock to avoid this. Since all the DAPM interactions depend only on a single threaded IRQ this is still serialised. The locking improvements in 3.5 allow a better solution there. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/wm8994.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 5319f7b..c27abaf 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -3188,9 +3188,16 @@ static void wm8958_default_micdet(u16 status, void *data)
/* If we have jackdet that will detect removal */
if (wm8994->jackdet) {
+ mutex_lock(&wm8994->accdet_lock);
+
snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
WM8958_MICD_ENA, 0);
+ wm1811_jackdet_set_mode(codec,
+ WM1811_JACKDET_MODE_JACK);
+
+ mutex_unlock(&wm8994->accdet_lock);
+
if (wm8994->pdata->jd_ext_cap) {
mutex_lock(&codec->mutex);
snd_soc_dapm_disable_pin(&codec->dapm,
@@ -3198,9 +3205,6 @@ static void wm8958_default_micdet(u16 status, void *data)
snd_soc_dapm_sync(&codec->dapm);
mutex_unlock(&codec->mutex);
}
-
- wm1811_jackdet_set_mode(codec,
- WM1811_JACKDET_MODE_JACK);
}
}
@@ -3235,6 +3239,7 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
struct wm8994_priv *wm8994 = data;
struct snd_soc_codec *codec = wm8994->codec;
int reg;
+ bool present;
mutex_lock(&wm8994->accdet_lock);
@@ -3247,11 +3252,10 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
dev_dbg(codec->dev, "JACKDET %x\n", reg);
- if (reg & WM1811_JACKDET_LVL) {
- dev_dbg(codec->dev, "Jack detected\n");
+ present = reg & WM1811_JACKDET_LVL;
- snd_soc_jack_report(wm8994->micdet[0].jack,
- SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
+ if (present) {
+ dev_dbg(codec->dev, "Jack detected\n");
snd_soc_update_bits(codec, WM8958_MICBIAS2,
WM8958_MICB2_DISCH, 0);
@@ -3269,32 +3273,12 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
WM8958_MICD_ENA, WM8958_MICD_ENA);
-
- /* If required for an external cap force MICBIAS on */
- if (wm8994->pdata->jd_ext_cap) {
- mutex_lock(&codec->mutex);
- snd_soc_dapm_force_enable_pin(&codec->dapm,
- "MICBIAS2");
- snd_soc_dapm_sync(&codec->dapm);
- mutex_unlock(&codec->mutex);
- }
} else {
dev_dbg(codec->dev, "Jack not detected\n");
snd_soc_update_bits(codec, WM8958_MICBIAS2,
WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
- if (wm8994->pdata->jd_ext_cap) {
- mutex_lock(&codec->mutex);
- snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
- snd_soc_dapm_sync(&codec->dapm);
- mutex_unlock(&codec->mutex);
- }
-
- snd_soc_jack_report(wm8994->micdet[0].jack, 0,
- SND_JACK_MECHANICAL | SND_JACK_HEADSET |
- wm8994->btn_mask);
-
/* Enable debounce while removed */
snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
WM1811_JACKDET_DB, WM1811_JACKDET_DB);
@@ -3308,6 +3292,28 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
mutex_unlock(&wm8994->accdet_lock);
+ /* If required for an external cap force MICBIAS on */
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&codec->mutex);
+
+ if (present)
+ snd_soc_dapm_force_enable_pin(&codec->dapm,
+ "MICBIAS2");
+ else
+ snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
+
+ snd_soc_dapm_sync(&codec->dapm);
+ mutex_unlock(&codec->mutex);
+ }
+
+ if (present)
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
+ else
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ SND_JACK_MECHANICAL | SND_JACK_HEADSET |
+ wm8994->btn_mask);
+
return IRQ_HANDLED;
}
@@ -3411,17 +3417,13 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
struct snd_soc_codec *codec = wm8994->codec;
int reg, count;
- mutex_lock(&wm8994->accdet_lock);
-
/*
* Jack detection may have detected a removal simulataneously
* with an update of the MICDET status; if so it will have
* stopped detection and we can ignore this interrupt.
*/
- if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA)) {
- mutex_unlock(&wm8994->accdet_lock);
+ if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
return IRQ_HANDLED;
- }
/* We may occasionally read a detection without an impedence
* range being provided - if that happens loop again.
@@ -3430,7 +3432,6 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
do {
reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
if (reg < 0) {
- mutex_unlock(&wm8994->accdet_lock);
dev_err(codec->dev,
"Failed to read mic detect status: %d\n",
reg);
@@ -3461,8 +3462,6 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
dev_warn(codec->dev, "Accessory detection with no callback\n");
out:
- mutex_unlock(&wm8994->accdet_lock);
-
return IRQ_HANDLED;
}