Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1099591imi; Fri, 1 Jul 2022 03:08:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t8qHf8t/37STrNk8MA/jX+z233dwvUtNKM3vvlFAa8IAECRduJL9LPJbbjWJSPUzdZzZMH X-Received: by 2002:a65:684c:0:b0:411:b3d3:a7f7 with SMTP id q12-20020a65684c000000b00411b3d3a7f7mr5469547pgt.448.1656670080164; Fri, 01 Jul 2022 03:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656670080; cv=none; d=google.com; s=arc-20160816; b=vjJmQ+aE/spAO8HuBgXFNlqESm6u6KvOuGH6tloUg+gdowDrP0G2hM1HijsDP3bInp 945n7bjhnWCbSHtDfBMdjj+JMHgoC0o4VuQzKDZE6JX+MmOHjrRtQ+5AJR4PZpZBzie0 aNVg1m4kacBQkM+NC978BDzebvSi1sqvRV7Y+bzIaITn1lpm7EWFOxHhGwjxhsCb2ELP A3V9zJTr4mKqSpi+9c2j/Qoiei62oK7XN6nJl39TGagr4aM6TtT3swJhdVoW2q34+nV/ aC91CssDkDPMRj+ZcKk69f07HoZpvC+QSrT8QV2EIkWEdDYahh+uzGMXFvWvntCue8yc J3XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=HgIuNg/9h4rsJGal+PUxHFWg2qZK/qS6FGGnTmhlg8c=; b=CFWOgtwQPX0h+bn9G+ZF1UUsYNT9q4ybw0ydGgU98oiMFCGq6fgcYiUkmXNS6WVqk4 D2wbWMxnD4AWnb15GHEcI5hdRG2VHmqIyeLhYy5FZ/LM7xJsgQPJLAx30+T2gkJ4r0Bo woDiLZcQ3x2RIpEaDPc3Qjnsr6WUNvjA3+lZDrB2a3sYJHapSMgas5QJokxof90l74pO 5KMKccW4NCgqittJzSb9eYHHfUrH2qECxblW3/C0tMbllDxBec9nxajC6XDOvsAydYOd 7DCXzdLwevITyKUgwQEtGXUWaym+QHwH+klp/P2LMaPSY4VU5w526Er0HeLz+bFO7Yno KYKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob2-20020a17090b390200b001eccaceca54si7526044pjb.80.2022.07.01.03.07.48; Fri, 01 Jul 2022 03:08:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236174AbiGAJrp (ORCPT + 99 others); Fri, 1 Jul 2022 05:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236234AbiGAJrb (ORCPT ); Fri, 1 Jul 2022 05:47:31 -0400 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC5E74DE3; Fri, 1 Jul 2022 02:47:30 -0700 (PDT) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 611E11A13D6; Fri, 1 Jul 2022 11:47:29 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 290261A13C8; Fri, 1 Jul 2022 11:47:29 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id D030C1802204; Fri, 1 Jul 2022 17:47:27 +0800 (+08) From: Shengjiu Wang To: nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, shengjiu.wang@gmail.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, robh+dt@kernel.org, krzk+dt@kernel.org, devicetree@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] ASoC: fsl_micfil: Add support for PLL switch at runtime Date: Fri, 1 Jul 2022 17:32:38 +0800 Message-Id: <1656667961-1799-4-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1656667961-1799-1-git-send-email-shengjiu.wang@nxp.com> References: <1656667961-1799-1-git-send-email-shengjiu.wang@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org i.MX8MQ/MN/MM/MP platforms typically have 2 AUDIO PLLs being configured to handle 8kHz and 11kHz series audio rates. The patch implements the functionality to select at runtime the appropriate AUDIO PLL as function of audio file rate. Signed-off-by: Viorel Suman Signed-off-by: Shengjiu Wang --- sound/soc/fsl/Kconfig | 1 + sound/soc/fsl/fsl_micfil.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index 910b8747b6bd..533937166b4a 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig @@ -81,6 +81,7 @@ config SND_SOC_FSL_MICFIL select REGMAP_MMIO select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n select SND_SOC_GENERIC_DMAENGINE_PCM + select SND_SOC_FSL_UTILS help Say Y if you want to add Pulse Density Modulation microphone interface (MICFIL) support for NXP. diff --git a/sound/soc/fsl/fsl_micfil.c b/sound/soc/fsl/fsl_micfil.c index 18ab80b68752..431278bfbd7b 100644 --- a/sound/soc/fsl/fsl_micfil.c +++ b/sound/soc/fsl/fsl_micfil.c @@ -24,6 +24,7 @@ #include #include "fsl_micfil.h" +#include "fsl_utils.h" #define MICFIL_OSR_DEFAULT 16 @@ -42,6 +43,8 @@ struct fsl_micfil { const struct fsl_micfil_soc_data *soc; struct clk *busclk; struct clk *mclk; + struct clk *pll8k_clk; + struct clk *pll11k_clk; struct snd_dmaengine_dai_dma_data dma_params_rx; struct sdma_peripheral_config sdmacfg; unsigned int dataline; @@ -283,6 +286,27 @@ static int fsl_micfil_trigger(struct snd_pcm_substream *substream, int cmd, return 0; } +static int fsl_micfil_reparent_rootclk(struct fsl_micfil *micfil, unsigned int sample_rate) +{ + struct device *dev = &micfil->pdev->dev; + u64 ratio = sample_rate; + struct clk *clk; + int ret; + + /* Get root clock */ + clk = micfil->mclk; + + /* Disable clock first, for it was enabled by pm_runtime */ + clk_disable_unprepare(clk); + fsl_asoc_reparent_pll_clocks(dev, clk, micfil->pll8k_clk, + micfil->pll11k_clk, ratio); + ret = clk_prepare_enable(clk); + if (ret) + return ret; + + return 0; +} + static int fsl_micfil_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -306,6 +330,10 @@ static int fsl_micfil_hw_params(struct snd_pcm_substream *substream, if (ret) return ret; + ret = fsl_micfil_reparent_rootclk(micfil, rate); + if (ret) + return ret; + ret = clk_set_rate(micfil->mclk, rate * clk_div * osr * 8); if (ret) return ret; @@ -610,6 +638,9 @@ static int fsl_micfil_probe(struct platform_device *pdev) return PTR_ERR(micfil->busclk); } + fsl_asoc_get_pll_clocks(&pdev->dev, &micfil->pll8k_clk, + &micfil->pll11k_clk); + /* init regmap */ regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(regs)) -- 2.17.1