Skip to content

Commit c0cc3f1

Browse files
committed
ASoC: wm8994: Allow a delay between jack insertion and microphone detect
This can be used to provide some additional settling time to ensure that we don't start microphone detection while the microphone pin is connected to one of the headphone pins. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent ddffeb8 commit c0cc3f1

2 files changed

Lines changed: 60 additions & 19 deletions

File tree

‎include/linux/mfd/wm8994/pdata.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ struct wm8994_pdata {
176176
unsigned int lineout1fb:1;
177177
unsigned int lineout2fb:1;
178178

179+
/* Delay between detecting a jack and starting microphone
180+
* detect (specified in ms)
181+
*/
182+
int micdet_delay;
183+
179184
/* IRQ for microphone detection if brought out directly as a
180185
* signal.
181186
*/

‎sound/soc/codecs/wm8994.c‎

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,11 +3470,46 @@ static void wm8958_default_micdet(u16 status, void *data)
34703470
}
34713471
}
34723472

3473+
/* Deferred mic detection to allow for extra settling time */
3474+
static void wm1811_mic_work(struct work_struct *work)
3475+
{
3476+
struct wm8994_priv *wm8994 = container_of(work, struct wm8994_priv,
3477+
mic_work.work);
3478+
struct snd_soc_codec *codec = wm8994->hubs.codec;
3479+
3480+
pm_runtime_get_sync(codec->dev);
3481+
3482+
/* If required for an external cap force MICBIAS on */
3483+
if (wm8994->pdata->jd_ext_cap) {
3484+
snd_soc_dapm_force_enable_pin(&codec->dapm,
3485+
"MICBIAS2");
3486+
snd_soc_dapm_sync(&codec->dapm);
3487+
}
3488+
3489+
mutex_lock(&wm8994->accdet_lock);
3490+
3491+
dev_dbg(codec->dev, "Starting mic detection\n");
3492+
3493+
/*
3494+
* Start off measument of microphone impedence to find out
3495+
* what's actually there.
3496+
*/
3497+
wm8994->mic_detecting = true;
3498+
wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3499+
3500+
snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3501+
WM8958_MICD_ENA, WM8958_MICD_ENA);
3502+
3503+
mutex_unlock(&wm8994->accdet_lock);
3504+
3505+
pm_runtime_put(codec->dev);
3506+
}
3507+
34733508
static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
34743509
{
34753510
struct wm8994_priv *wm8994 = data;
34763511
struct snd_soc_codec *codec = wm8994->hubs.codec;
3477-
int reg;
3512+
int reg, delay;
34783513
bool present;
34793514

34803515
pm_runtime_get_sync(codec->dev);
@@ -3505,18 +3540,14 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
35053540
snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
35063541
WM1811_JACKDET_DB, 0);
35073542

3508-
/*
3509-
* Start off measument of microphone impedence to find
3510-
* out what's actually there.
3511-
*/
3512-
wm8994->mic_detecting = true;
3513-
wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
3514-
3515-
snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3516-
WM8958_MICD_ENA, WM8958_MICD_ENA);
3543+
delay = wm8994->pdata->micdet_delay;
3544+
schedule_delayed_work(&wm8994->mic_work,
3545+
msecs_to_jiffies(delay));
35173546
} else {
35183547
dev_dbg(codec->dev, "Jack not detected\n");
35193548

3549+
cancel_delayed_work_sync(&wm8994->mic_work);
3550+
35203551
snd_soc_update_bits(codec, WM8958_MICBIAS2,
35213552
WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
35223553

@@ -3533,14 +3564,9 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
35333564

35343565
mutex_unlock(&wm8994->accdet_lock);
35353566

3536-
/* If required for an external cap force MICBIAS on */
3537-
if (wm8994->pdata->jd_ext_cap) {
3538-
if (present)
3539-
snd_soc_dapm_force_enable_pin(&codec->dapm,
3540-
"MICBIAS2");
3541-
else
3542-
snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
3543-
}
3567+
/* Turn off MICBIAS if it was on for an external cap */
3568+
if (wm8994->pdata->jd_ext_cap && !present)
3569+
snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
35443570

35453571
if (present)
35463572
snd_soc_jack_report(wm8994->micdet[0].jack,
@@ -3763,10 +3789,20 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
37633789
snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
37643790

37653791
mutex_init(&wm8994->accdet_lock);
3766-
INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
37673792
INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap,
37683793
wm1811_jackdet_bootstrap);
37693794

3795+
switch (control->type) {
3796+
case WM8994:
3797+
INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
3798+
break;
3799+
case WM1811:
3800+
INIT_DELAYED_WORK(&wm8994->mic_work, wm1811_mic_work);
3801+
break;
3802+
default:
3803+
break;
3804+
}
3805+
37703806
for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
37713807
init_completion(&wm8994->fll_locked[i]);
37723808

0 commit comments

Comments
 (0)