Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+60 -19
+5
include/linux/mfd/wm8994/pdata.h
··· 176 176 unsigned int lineout1fb:1; 177 177 unsigned int lineout2fb:1; 178 178 179 + /* Delay between detecting a jack and starting microphone 180 + * detect (specified in ms) 181 + */ 182 + int micdet_delay; 183 + 179 184 /* IRQ for microphone detection if brought out directly as a 180 185 * signal. 181 186 */
+55 -19
sound/soc/codecs/wm8994.c
··· 3470 3470 } 3471 3471 } 3472 3472 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 + 3473 3508 static irqreturn_t wm1811_jackdet_irq(int irq, void *data) 3474 3509 { 3475 3510 struct wm8994_priv *wm8994 = data; 3476 3511 struct snd_soc_codec *codec = wm8994->hubs.codec; 3477 - int reg; 3512 + int reg, delay; 3478 3513 bool present; 3479 3514 3480 3515 pm_runtime_get_sync(codec->dev); ··· 3540 3505 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL, 3541 3506 WM1811_JACKDET_DB, 0); 3542 3507 3543 - /* 3544 - * Start off measument of microphone impedence to find 3545 - * out what's actually there. 3546 - */ 3547 - wm8994->mic_detecting = true; 3548 - wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC); 3549 - 3550 - snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, 3551 - WM8958_MICD_ENA, WM8958_MICD_ENA); 3508 + delay = wm8994->pdata->micdet_delay; 3509 + schedule_delayed_work(&wm8994->mic_work, 3510 + msecs_to_jiffies(delay)); 3552 3511 } else { 3553 3512 dev_dbg(codec->dev, "Jack not detected\n"); 3513 + 3514 + cancel_delayed_work_sync(&wm8994->mic_work); 3554 3515 3555 3516 snd_soc_update_bits(codec, WM8958_MICBIAS2, 3556 3517 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH); ··· 3564 3533 3565 3534 mutex_unlock(&wm8994->accdet_lock); 3566 3535 3567 - /* If required for an external cap force MICBIAS on */ 3568 - if (wm8994->pdata->jd_ext_cap) { 3569 - if (present) 3570 - snd_soc_dapm_force_enable_pin(&codec->dapm, 3571 - "MICBIAS2"); 3572 - else 3573 - snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2"); 3574 - } 3536 + /* Turn off MICBIAS if it was on for an external cap */ 3537 + if (wm8994->pdata->jd_ext_cap && !present) 3538 + snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2"); 3575 3539 3576 3540 if (present) 3577 3541 snd_soc_jack_report(wm8994->micdet[0].jack, ··· 3789 3763 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP); 3790 3764 3791 3765 mutex_init(&wm8994->accdet_lock); 3792 - INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work); 3793 3766 INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap, 3794 3767 wm1811_jackdet_bootstrap); 3768 + 3769 + switch (control->type) { 3770 + case WM8994: 3771 + INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work); 3772 + break; 3773 + case WM1811: 3774 + INIT_DELAYED_WORK(&wm8994->mic_work, wm1811_mic_work); 3775 + break; 3776 + default: 3777 + break; 3778 + } 3795 3779 3796 3780 for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) 3797 3781 init_completion(&wm8994->fll_locked[i]);