From patchwork Sun Feb 25 10:46:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10240747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 442AF60211 for ; Sun, 25 Feb 2018 10:49:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AEFD285F1 for ; Sun, 25 Feb 2018 10:49:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D8FD29C07; Sun, 25 Feb 2018 10:49:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52859285F1 for ; Sun, 25 Feb 2018 10:49:56 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 2CC7F2674D7; Sun, 25 Feb 2018 11:47:53 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 65258267409; Sun, 25 Feb 2018 11:47:40 +0100 (CET) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by alsa0.perex.cz (Postfix) with ESMTP id 0FEC12673F5 for ; Sun, 25 Feb 2018 11:47:38 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 751FCEAEAB; Sun, 25 Feb 2018 10:47:37 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-99.ams2.redhat.com [10.36.116.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57F7710B0F25; Sun, 25 Feb 2018 10:47:36 +0000 (UTC) From: Hans de Goede To: Mark Brown , Bard Liao , Oder Chiou , Pierre-Louis Bossart Date: Sun, 25 Feb 2018 11:46:55 +0100 Message-Id: <20180225104713.4745-15-hdegoede@redhat.com> In-Reply-To: <20180225104713.4745-1-hdegoede@redhat.com> References: <20180225104713.4745-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 25 Feb 2018 10:47:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 25 Feb 2018 10:47:37 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Cc: Hans de Goede , alsa-devel@alsa-project.org, Carlo Caione , Takashi Iwai Subject: [alsa-devel] [PATCH v2 14/32] ASoC: rt5651: Enable LDO and micbias1 supplies for jack-type detection X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP To determine if a plugged in jack is a headset (speakers + mic) or headphones (mic contact shorted to ground) we use the micbias1 OVer Current Detect (OVCD) functionality. For this to work we need to have a micbias current to actually cause an overcurrent condition when headphones are plugged in, so jack-type detection requires both the LDO and micbias1 supplies to be on. Before this commit there were 2 issues with the handling of this: 1) The LDO supply was force-enabled twice and never disabled again even though it only needs to be forced on when doing jack-type detection 2) micbias1 was not force-enabled, and thus may be off when doing jack-type detection This commit fixes both by force-enabling the LDO and micbias1 supplies before checking for an overcurrent condition and disabling them afterwards. Note that both supplies will still get turned on normally (and OVCD will protect against overcurrent) when the micbias1 is enabled normally because the user has activated a sound stream recording from the mic. Tested-by: Carlo Caione Signed-off-by: Hans de Goede --- sound/soc/codecs/rt5651.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c index bfacf8ea6069..2e23e126ff54 100644 --- a/sound/soc/codecs/rt5651.c +++ b/sound/soc/codecs/rt5651.c @@ -1556,6 +1556,28 @@ static int rt5651_set_bias_level(struct snd_soc_component *component, return 0; } +static void rt5651_enable_micbias1_for_ovcd(struct snd_soc_component *component) +{ + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + + snd_soc_dapm_mutex_lock(dapm); + snd_soc_dapm_force_enable_pin_unlocked(dapm, "LDO"); + snd_soc_dapm_force_enable_pin_unlocked(dapm, "micbias1"); + snd_soc_dapm_sync_unlocked(dapm); + snd_soc_dapm_mutex_unlock(dapm); +} + +static void rt5651_disable_micbias1_for_ovcd(struct snd_soc_component *component) +{ + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + + snd_soc_dapm_mutex_lock(dapm); + snd_soc_dapm_disable_pin_unlocked(dapm, "micbias1"); + snd_soc_dapm_disable_pin_unlocked(dapm, "LDO"); + snd_soc_dapm_sync_unlocked(dapm); + snd_soc_dapm_mutex_unlock(dapm); +} + static irqreturn_t rt5651_irq(int irq, void *data) { struct rt5651_priv *rt5651 = data; @@ -1569,7 +1591,6 @@ static irqreturn_t rt5651_irq(int irq, void *data) static int rt5651_set_jack(struct snd_soc_component *component, struct snd_soc_jack *hp_jack, void *data) { - struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); int ret; u32 val; @@ -1616,9 +1637,6 @@ static int rt5651_set_jack(struct snd_soc_component *component, snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, RT5651_PWR_JD_M, RT5651_PWR_JD_M); - snd_soc_dapm_force_enable_pin(dapm, "LDO"); - snd_soc_dapm_sync(dapm); - snd_soc_component_update_bits(component, RT5651_MICBIAS, 0x38, 0x38); rt5651->hp_jack = hp_jack; @@ -1802,13 +1820,10 @@ MODULE_DEVICE_TABLE(i2c, rt5651_i2c_id); static int rt5651_jack_detect(struct snd_soc_component *component, int jack_insert) { - struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); int jack_type; if (jack_insert) { - snd_soc_dapm_force_enable_pin(dapm, "LDO"); - snd_soc_dapm_sync(dapm); - + rt5651_enable_micbias1_for_ovcd(component); snd_soc_component_update_bits(component, RT5651_MICBIAS, RT5651_MIC1_OVCD_MASK | RT5651_MIC1_OVTH_MASK | @@ -1825,6 +1840,7 @@ static int rt5651_jack_detect(struct snd_soc_component *component, int jack_inse jack_type = SND_JACK_HEADSET; snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, RT5651_MB1_OC_CLR, 0); + rt5651_disable_micbias1_for_ovcd(component); } else { /* jack out */ jack_type = 0;