From patchwork Tue Oct 20 15:01:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Olivier MOYSAN X-Patchwork-Id: 11847187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4952C4363A for ; Tue, 20 Oct 2020 15:03:10 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B76921481 for ; Tue, 20 Oct 2020 15:03:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GYcYwolD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="pcALPfUl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B76921481 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Ro+nwkXDvPj1NUmx0MdmnDA1EMnI9YfIHhEvW5AQwSM=; b=GYcYwolDUSqI5z0D8O0x31Qk2/ jeBBIXu+DLCtQXcbJWHvqheLkp4RIShPrwL2ml+iCnuU9A7ylOBWT4L6wP20kdwI1wrcH6Ds1sCOd gPDGCGs4ltoo9FtFRqNcYFALQsm+j1OdXOLmfpmDYs4JvrE7qJE+ZCdzDyd3+bVXHair4B15g7Z/p evIJxMK1Gt702uYVNfF4z8tEn+jHnLBxJ61gR+Friyu9IjIO1EATIPEt8DBzYDSNrJ3QLo3HHf9a6 d7y9q4mhxYXMu3NtoTI8Ti6eymAnHUGZoTqaKMgqa9a7gIrTNX0NOgpnz2+oxMJKNIxcQ5yX5F/CY h3MUkP4A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUt8m-0002SQ-HX; Tue, 20 Oct 2020 15:01:32 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUt8k-0002Ru-4j for linux-arm-kernel@lists.infradead.org; Tue, 20 Oct 2020 15:01:31 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 09KEvgm6012136; Tue, 20 Oct 2020 17:01:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=STMicroelectronics; bh=XgCfUqxaOYwvz9RDx21gH1OGoREoJaNipM7JO27tcpQ=; b=pcALPfUlGTVlYjzgy9lQZOr9M/jywqlaRBDLx7FCwCeHIRBaIgXSyKKlk+EEwGcb0jca BxSCCUZQTF7U/ZpEN38ebvJPyOa1hdY37nyUHTziP2vgc50Z/XGd08CW7nHJUThXljuX ilcRlNsaQKIfHIiA3zVD9xhKpPmKRKkm+9d3+2PK+RYIF8M+fuSBCgP2JVBUBCd0ti0f 0FaZmGfEURtGM6jFgvSa2V/PrDAlVdO52WRtVnmcJjXSksWL4TlT+i0TOO3sAPQfrRlu rpxMtUe2vvNDRem4vYgoIwpPNWh4YQ6KJUgatqCG3PpqJYrFKX8ZnBNQbRZ501/M7ONd Lg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 347qgg4432-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Oct 2020 17:01:21 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5BA2910002A; Tue, 20 Oct 2020 17:01:20 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 30F6B2E6D30; Tue, 20 Oct 2020 17:01:20 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 20 Oct 2020 17:01:19 +0200 From: Olivier Moysan To: , , , , , , Subject: [PATCH v2] ASoC: cs42l51: manage mclk shutdown delay Date: Tue, 20 Oct 2020 17:01:09 +0200 Message-ID: <20201020150109.482-1-olivier.moysan@st.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG1NODE1.st.com (10.75.127.1) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.737 definitions=2020-10-20_08:2020-10-20, 2020-10-20 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201020_110130_536049_6595F8A9 X-CRM114-Status: GOOD ( 20.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, arnaud.pouliquen@st.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A delay must be introduced before the shutdown down of the mclk, as stated in CS42L51 datasheet. Otherwise the codec may produce some noise after the end of DAPM power down sequence. The delay between DAC and CLOCK_SUPPLY widgets is too short. Add a delay in mclk shutdown request to manage the shutdown delay explicitly. From experiments, at least 10ms delay is necessary. Set delay to 20ms as recommended in Documentation/timers/timers-howto.rst when using msleep(). Signed-off-by: Olivier Moysan --- Recommended Power-Down Sequence: (see https://statics.cirrus.com/pubs/proDatasheet/CS42L51_F2.pdf) 1. Mute the DACs and ADCs. 2. Disable soft ramp and zero-cross volume transitions 3. Set the PDN bit to 1. 4. Wait at least 100 μs. The codec will be fully powered down after this 100 μs delay. Prior to the removal of the master clock(MCLK), this delay of at least 100 μs must be implemented after step 3 to avoid premature disruption of the codec’s power down sequence. Changes in v2: - Manage explicitly DAPM events through a switch case in mclk_event() --- sound/soc/codecs/cs42l51.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c index 097c4e8d9950..c61b17dc2af8 100644 --- a/sound/soc/codecs/cs42l51.c +++ b/sound/soc/codecs/cs42l51.c @@ -254,8 +254,28 @@ static const struct snd_soc_dapm_widget cs42l51_dapm_widgets[] = { &cs42l51_adcr_mux_controls), }; +static int mclk_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); + struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(comp); + + switch (event) { + case SND_SOC_DAPM_PRE_PMU: + return clk_prepare_enable(cs42l51->mclk_handle); + case SND_SOC_DAPM_POST_PMD: + /* Delay mclk shutdown to fulfill power-down sequence requirements */ + msleep(20); + clk_disable_unprepare(cs42l51->mclk_handle); + break; + } + + return 0; +} + static const struct snd_soc_dapm_widget cs42l51_dapm_mclk_widgets[] = { - SND_SOC_DAPM_CLOCK_SUPPLY("MCLK") + SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0, mclk_event, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), }; static const struct snd_soc_dapm_route cs42l51_routes[] = {