From patchwork Wed Sep 13 20:43:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Riegel X-Patchwork-Id: 9952043 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 1C05160360 for ; Wed, 13 Sep 2017 20:46:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E5CD288FC for ; Wed, 13 Sep 2017 20:46:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0312428AB7; Wed, 13 Sep 2017 20:46:01 +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=unavailable 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 16330288FC for ; Wed, 13 Sep 2017 20:45:59 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id EB18D266D90; Wed, 13 Sep 2017 22:45:57 +0200 (CEST) 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 1A82D266E13; Wed, 13 Sep 2017 22:45:57 +0200 (CEST) Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by alsa0.perex.cz (Postfix) with ESMTP id 4596C266986 for ; Wed, 13 Sep 2017 22:45:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id DA2809C1A1E; Wed, 13 Sep 2017 16:45:51 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id utei78ucFJJM; Wed, 13 Sep 2017 16:45:51 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 560D49C1A9F; Wed, 13 Sep 2017 16:45:51 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id d3iXHlwTcegm; Wed, 13 Sep 2017 16:45:51 -0400 (EDT) Received: from workotop.humanware.local (unknown [192.252.129.34]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 16B259C1A2C; Wed, 13 Sep 2017 16:45:51 -0400 (EDT) From: Damien Riegel To: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Date: Wed, 13 Sep 2017 16:43:55 -0400 Message-Id: <20170913204355.26186-1-damien.riegel@savoirfairelinux.com> X-Mailer: git-send-email 2.14.1 Cc: Damien Riegel , Takashi Iwai , Liam Girdwood , Mark Brown , Srinivas Kandagatla Subject: [alsa-devel] [RFC] ASoC: codecs: msm8916-wcd-analog: use btn0 released 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 msm8916-wcd-analog uses button0 to differentiate between headphone and headset. Under some circumstances, button pressed and released interrupts are not fired as the driver expects it. For instance, with some connectors, there are spurious button-pressed interrupts when unplugging a headphone, without the corresponding button-released interrupt. But the codec always alternates between button pressed and released interrupts, it cannot fire two interrupts of the same kind in a row. That means that when the headphone is plugged back, only a button-released interrupt will be fired instead of pressed then released. This causes the driver to report headphone as headset. By changing the logic and relying on button 0 release interrupt, the driver could be made more robust for connectors that differ from the one used on the Dragonboard's audio mezzanine. Signed-off-by: Damien Riegel Acked-by: Srinivas Kandagatla --- sound/soc/codecs/msm8916-wcd-analog.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c index 549c269acc7d..f562f2d86907 100644 --- a/sound/soc/codecs/msm8916-wcd-analog.c +++ b/sound/soc/codecs/msm8916-wcd-analog.c @@ -285,7 +285,7 @@ struct pm8916_wcd_analog_priv { u16 codec_version; bool mbhc_btn_enabled; /* special event to detect accessory type */ - bool mbhc_btn0_pressed; + int mbhc_btn0_released; bool detect_accessory_type; struct clk *mclk; struct snd_soc_codec *codec; @@ -483,7 +483,7 @@ static void pm8916_wcd_setup_mbhc(struct pm8916_wcd_analog_priv *wcd) snd_soc_update_bits(codec, CDC_D_INT_EN_CLR, int_en_mask, 0); snd_soc_update_bits(codec, CDC_D_INT_EN_SET, int_en_mask, int_en_mask); - wcd->mbhc_btn0_pressed = false; + wcd->mbhc_btn0_released = false; wcd->detect_accessory_type = true; } @@ -950,7 +950,7 @@ static irqreturn_t mbhc_btn_release_irq_handler(int irq, void *arg) /* check if its BTN0 thats released */ if ((val != -1) && !(val & CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK)) - priv->mbhc_btn0_pressed = false; + priv->mbhc_btn0_released = true; } else { snd_soc_jack_report(priv->jack, 0, btn_mask); @@ -983,9 +983,7 @@ static irqreturn_t mbhc_btn_press_irq_handler(int irq, void *arg) break; case 0x0: /* handle BTN_0 specially for type detection */ - if (priv->detect_accessory_type) - priv->mbhc_btn0_pressed = true; - else + if (!priv->detect_accessory_type) snd_soc_jack_report(priv->jack, SND_JACK_BTN_0, btn_mask); break; @@ -1029,19 +1027,19 @@ static irqreturn_t pm8916_mbhc_switch_irq_handler(int irq, void *arg) * both press and release event received then its * a headset. */ - if (priv->mbhc_btn0_pressed) + if (priv->mbhc_btn0_released) snd_soc_jack_report(priv->jack, - SND_JACK_HEADPHONE, hs_jack_mask); + SND_JACK_HEADSET, hs_jack_mask); else snd_soc_jack_report(priv->jack, - SND_JACK_HEADSET, hs_jack_mask); + SND_JACK_HEADPHONE, hs_jack_mask); priv->detect_accessory_type = false; } else { /* removal */ snd_soc_jack_report(priv->jack, 0, hs_jack_mask); priv->detect_accessory_type = true; - priv->mbhc_btn0_pressed = false; + priv->mbhc_btn0_released = false; } return IRQ_HANDLED;