From patchwork Mon Nov 21 05:07:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Rau X-Patchwork-Id: 13052095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9605DC433FE for ; Tue, 22 Nov 2022 09:29:36 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 922131689; Tue, 22 Nov 2022 10:28:43 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 922131689 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1669109373; bh=EeC2D/oQJKRRb3NCL3O49IZjhgrGZW28wXABXKklcLY=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=d65S0KPc4rLAD1ucJp+tC8KtB4fjnVG8ettwUA6+q68HU7Uv8gCesKyjB4riRuKN/ HF4xUtA2qrrn/GdZ9xDrcM/bW97VTZvbOMRIIIRbyWrEbGaPOGPCg3xv+cSrBnEFYW /ckOy4RuQKFFN7sljWfq/avaCNyGCOvLh9WJRpT0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A1441F8056F; Tue, 22 Nov 2022 10:27:24 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 903AAF8028D; Mon, 21 Nov 2022 06:08:12 +0100 (CET) Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id BB713F80115 for ; Mon, 21 Nov 2022 06:08:05 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BB713F80115 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KRZhw+66" Received: by mail-pj1-x1035.google.com with SMTP id t17so8758415pjo.3 for ; Sun, 20 Nov 2022 21:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RMIqu6elzQ/fhPBiCrbaxSsjSlZL9VcX8QAuybxVFXU=; b=KRZhw+660KNtlWnEcDCJ9UN3q3BXiWu4jvt+zgrdkPEJv8Efcm2jvYdbSopbbPdKLm sfztUJ7uo8JOHMmpkZ47c33mRsFyyIQKBKhhk8duY6xWU93kmXD+loss4yL4ss3EfQeg mrCnqHflEotvmJ7PVh6+SV3tpv29ss3Hl3o6sAoc6XBhWfkkWGxlcyx5BFDGcpwiWuKt LeUy2wC0TW0b3780DzI8SZYNHJ++eJh86b266gtmfiFTCl5lXnSchG0qzEvS4RbQh+eh ScA4BSiRu1GST+Eux1wGBUgwNYNjeLWJpXtUgcEQlpNLRS4k/8skvMe4MNuqP5JFiqUx y2mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RMIqu6elzQ/fhPBiCrbaxSsjSlZL9VcX8QAuybxVFXU=; b=TZrQVi4Mnq41fhsEGZZfkFDg+B311jKd//fErZU1d3TZoIJDlskhXNwDarTZ68Troy pWTWMnT5SzBcDzE5+sKTxcbGWw5197PinIvP3fcksKRPwjXfP9D6wutstFMflg8ng9Wm BYE8AQfXLflB+1AhJBiniz6F2hxdK6BedcwAc48PE+LmV0P8HaDKOQCaTF6DKiOfxhg1 nDWRjwEnW3fS+vnRUN4cc2WbGm53oQwqrNXrOiaGexamUsC9lUB6hTDcj3HyLcOZhn63 7c9FXTQrS4lrh8klVLqPFjHurOPghNN4Kce47jZ0E9eyoioyd8d70Yyr76RioPi97NMo pnXg== X-Gm-Message-State: ANoB5plOb1QVV/Nsu8EbVsTvARbxr9bnkOMrJEFH5YewLOByX+RjQpHy 6FhYcMicTSNUox+/jaE4mLk= X-Google-Smtp-Source: AA0mqf6113UG4iffqWXkhPyaQ4BF0B7DCtUVw4L6oDk3vt/EuoUBuuVeWX7tcg1K5ySg8SrKi0VV1A== X-Received: by 2002:a17:90a:aa93:b0:218:94ff:ce1f with SMTP id l19-20020a17090aaa9300b0021894ffce1fmr10482453pjq.217.1669007282385; Sun, 20 Nov 2022 21:08:02 -0800 (PST) Received: from ubuntu-vm.mshome.net (111-71-212-184.emome-ip.hinet.net. [111.71.212.184]) by smtp.gmail.com with ESMTPSA id p3-20020a170902e74300b00188a7bce192sm8552884plf.264.2022.11.20.21.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Nov 2022 21:08:01 -0800 (PST) From: David Rau X-Google-Original-From: David Rau To: perex@perex.cz Subject: [PATCH] ASoC: da7219: Fix pole orientation detection on OMTP headsets when playing music Date: Mon, 21 Nov 2022 05:07:44 +0000 Message-Id: <20221121050744.2278-1-david.rau.zg@renesas.com> X-Mailer: git-send-email 2.17.1 X-Mailman-Approved-At: Tue, 22 Nov 2022 10:27:19 +0100 Cc: alsa-devel@alsa-project.org, support.opensource@diasemi.com, tiwai@suse.com, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, broonie@kernel.org, David Rau X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The OMTP pin define headsets can be mis-detected as line out instead of OMTP, causing obvious issues with audio quality. This patch is to put increased resistances within the device at a suitable point. To solve this issue better, the new mechanism setup ground switches with conditional delay control and these allow for more stabile detection process to operate as intended. This conditional delay control will not impact the hardware process but use extra system resource. This commit improves control of ground switches in the AAD logic. Signed-off-by: David Rau Signed-off-by: Guenter Roeck Signed-off-by: Guenter Roeck --- sound/soc/codecs/da7219-aad.c | 42 ++++++++++++++++++++++++++++++----- sound/soc/codecs/da7219-aad.h | 1 + 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/da7219-aad.c b/sound/soc/codecs/da7219-aad.c index bba73c44c219..08200ec259f9 100644 --- a/sound/soc/codecs/da7219-aad.c +++ b/sound/soc/codecs/da7219-aad.c @@ -352,9 +352,14 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data) struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); u8 events[DA7219_AAD_IRQ_REG_MAX]; - u8 statusa; + u8 statusa, srm_st; int i, report = 0, mask = 0; + srm_st = snd_soc_component_read(component, DA7219_PLL_SRM_STS) & DA7219_PLL_SRM_STS_MCLK; + msleep(da7219_aad->gnd_switch_delay * ((srm_st == 0x0) ? 2 : 1) - 4); + /* Enable ground switch */ + snd_soc_component_update_bits(component, 0xFB, 0x01, 0x01); + /* Read current IRQ events */ regmap_bulk_read(da7219->regmap, DA7219_ACCDET_IRQ_EVENT_A, events, DA7219_AAD_IRQ_REG_MAX); @@ -454,8 +459,8 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data) snd_soc_dapm_disable_pin(dapm, "Mic Bias"); snd_soc_dapm_sync(dapm); - /* Enable ground switch */ - snd_soc_component_update_bits(component, 0xFB, 0x01, 0x01); + /* Disable ground switch */ + snd_soc_component_update_bits(component, 0xFB, 0x01, 0x00); } } @@ -831,6 +836,32 @@ static void da7219_aad_handle_pdata(struct snd_soc_component *component) } } +static void da7219_aad_handle_gnd_switch_time(struct snd_soc_component *component) +{ + struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); + struct da7219_aad_priv *da7219_aad = da7219->aad; + u8 jack_det; + + jack_det = snd_soc_component_read(component, DA7219_ACCDET_CONFIG_2) + & DA7219_JACK_DETECT_RATE_MASK; + switch (jack_det) { + case 0x00: + da7219_aad->gnd_switch_delay = 32; + break; + case 0x10: + da7219_aad->gnd_switch_delay = 64; + break; + case 0x20: + da7219_aad->gnd_switch_delay = 128; + break; + case 0x30: + da7219_aad->gnd_switch_delay = 256; + break; + default: + da7219_aad->gnd_switch_delay = 32; + break; + } +} /* * Suspend/Resume @@ -908,9 +939,6 @@ int da7219_aad_init(struct snd_soc_component *component) snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1, DA7219_BUTTON_CONFIG_MASK, 0); - /* Enable ground switch */ - snd_soc_component_update_bits(component, 0xFB, 0x01, 0x01); - INIT_WORK(&da7219_aad->btn_det_work, da7219_aad_btn_det_work); INIT_WORK(&da7219_aad->hptest_work, da7219_aad_hptest_work); @@ -928,6 +956,8 @@ int da7219_aad_init(struct snd_soc_component *component) regmap_bulk_write(da7219->regmap, DA7219_ACCDET_IRQ_MASK_A, &mask, DA7219_AAD_IRQ_REG_MAX); + da7219_aad_handle_gnd_switch_time(component); + return 0; } EXPORT_SYMBOL_GPL(da7219_aad_init); diff --git a/sound/soc/codecs/da7219-aad.h b/sound/soc/codecs/da7219-aad.h index f48a12012ef3..21fdf53095cc 100644 --- a/sound/soc/codecs/da7219-aad.h +++ b/sound/soc/codecs/da7219-aad.h @@ -187,6 +187,7 @@ enum da7219_aad_event_regs { struct da7219_aad_priv { struct snd_soc_component *component; int irq; + int gnd_switch_delay; u8 micbias_pulse_lvl; u32 micbias_pulse_time;