Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp170807iog; Fri, 17 Jun 2022 01:01:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vXKQkz6jnBtrnlzG7/6KfZVSc0M9RwBw8KSzO8MUkTBqt5fC0h+uQPhIfggR90i6HVVSOR X-Received: by 2002:a17:907:3f0a:b0:711:f0e2:ad67 with SMTP id hq10-20020a1709073f0a00b00711f0e2ad67mr7944583ejc.277.1655452906134; Fri, 17 Jun 2022 01:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655452906; cv=none; d=google.com; s=arc-20160816; b=azxeXqA6kAaBlEptT90tCCDqH8jW/J4kjrcntkj/fkHDLsBugwFWAyk06V0qEFVPtO WDik2FK4qMwJ7wyole53eojGmGIqslJlhw54wZ2TWioHG/KcEgQD6hh8bKP6x8VeJasd K+6y25AYqxGa6qHdb17tTvJKfYa76IwfZeOwdEt+u9H6CihYsZ/CkGNXV9ay2z1bUhLp n+WdqAVGG4DKvnnR01mysxRlc27MKzkrQyw5vC87Aw+TM/sCIonRwWB50eU7ySAvZQ5p +j+KkVCcXwytHC5YGRb3KkVI5+KwJkjXprGMJpFPDZkaSfSnxA2xevXv3VQHnUJ+Rbsu XU9g== 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=+BOFSA7jlD2hjzRiYwYaiG8VbvDCy3CzqcBYfButxQw=; b=Iq+bLxnTJmN3von6Wk/6xpXaryqdescTJLXJ4pnCVCsY0h+qNWTlKsu6ONV0QQnLfZ hZjeTQDD6qSS+im4rbZ388g2erWMw08uIXc6FNR6MUaI8x42OBl4M4qJtAFPU+HuOTr6 OtUAf+9lq1j5QL1zog2cKFNCbOg04m8wkMauBn2q3ocK/cj91eqBced33mgu4RA+iUNa Ox5sdKJShV2yJEhJEeMN/L6j91B5tK8S6tdj9sSVGLATALNQPHLB8JdG25Ty8UFz3JeP lVX5+MYNJwwo85hc9CEKBCj2ZBWRIQRCesjU9PfB8wSeRck3OQ0+XAJtRhO5D0jRO9J3 nOEg== 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 m10-20020a50ef0a000000b00435660ad459si123058eds.518.2022.06.17.01.01.18; Fri, 17 Jun 2022 01:01:46 -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 S1380739AbiFQH7Y (ORCPT + 99 others); Fri, 17 Jun 2022 03:59:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380718AbiFQH7X (ORCPT ); Fri, 17 Jun 2022 03:59:23 -0400 Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A0375BE7F; Fri, 17 Jun 2022 00:59:22 -0700 (PDT) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id C26BB201FAF; Fri, 17 Jun 2022 09:59:20 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 3B4AD201F99; Fri, 17 Jun 2022 09:59:20 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 56066180222B; Fri, 17 Jun 2022 15:59:18 +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 4/7] ASoc: fsl_sai: Add pinctrl operation for PDM and DSD Date: Fri, 17 Jun 2022 15:44:34 +0800 Message-Id: <1655451877-16382-5-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1655451877-16382-1-git-send-email-shengjiu.wang@nxp.com> References: <1655451877-16382-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 With DSD format, the pinctrl is different compare with I2S format, because one dataline only has one channel data, and the codec always mux the LRCLK pin to DSD data line, and on i.MX8MQ the BCLK pin can route to codec on DSD case for the MCLK is too high. Add pinctrl operation that the pinctrl can be switched on runtime according to the I2S format or DSD format Signed-off-by: Viorel Suman Signed-off-by: Shengjiu Wang --- sound/soc/fsl/fsl_sai.c | 70 +++++++++++++++++++++++++++++++++++------ sound/soc/fsl/fsl_sai.h | 2 ++ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c index 9d2828b55c07..ddfe28cb7df0 100644 --- a/sound/soc/fsl/fsl_sai.c +++ b/sound/soc/fsl/fsl_sai.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,31 @@ static inline bool fsl_sai_dir_is_synced(struct fsl_sai *sai, int dir) return !sai->synchronous[dir] && sai->synchronous[adir]; } +static struct pinctrl_state *fsl_sai_get_pins_state(struct fsl_sai *sai, u32 bclk) +{ + struct pinctrl_state *state = 0; + + if (sai->is_pdm_mode) { + /* DSD512@44.1kHz, DSD512@48kHz */ + if (bclk >= 22579200) + state = pinctrl_lookup_state(sai->pinctrl, "dsd512"); + + /* Get default DSD state */ + if (IS_ERR_OR_NULL(state)) + state = pinctrl_lookup_state(sai->pinctrl, "dsd"); + } else { + /* 706k32b2c, 768k32b2c, etc */ + if (bclk >= 45158400) + state = pinctrl_lookup_state(sai->pinctrl, "pcm_b2m"); + } + + /* Get default state */ + if (IS_ERR_OR_NULL(state)) + state = pinctrl_lookup_state(sai->pinctrl, "default"); + + return state; +} + static irqreturn_t fsl_sai_isr(int irq, void *devid) { struct fsl_sai *sai = (struct fsl_sai *)devid; @@ -466,7 +492,7 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream, u32 slots = (channels == 1) ? 2 : channels; u32 slot_width = word_width; int adir = tx ? RX : TX; - u32 pins; + u32 pins, bclk; int ret; if (sai->slots) @@ -484,15 +510,21 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream, if (sai->is_pdm_mode) pins = channels; + bclk = params_rate(params) * (sai->bclk_ratio ? sai->bclk_ratio : slots * slot_width); + + if (!IS_ERR_OR_NULL(sai->pinctrl)) { + sai->pins_state = fsl_sai_get_pins_state(sai, bclk); + if (!IS_ERR_OR_NULL(sai->pins_state)) { + ret = pinctrl_select_state(sai->pinctrl, sai->pins_state); + if (ret) { + dev_err(cpu_dai->dev, "failed to set proper pins state: %d\n", ret); + return ret; + } + } + } + if (!sai->is_consumer_mode) { - if (sai->bclk_ratio) - ret = fsl_sai_set_bclk(cpu_dai, tx, - sai->bclk_ratio * - params_rate(params)); - else - ret = fsl_sai_set_bclk(cpu_dai, tx, - slots * slot_width * - params_rate(params)); + ret = fsl_sai_set_bclk(cpu_dai, tx, bclk); if (ret) return ret; @@ -757,6 +789,23 @@ static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai) return 0; } +static int fsl_sai_dai_resume(struct snd_soc_component *component) +{ + struct fsl_sai *sai = snd_soc_component_get_drvdata(component); + struct device *dev = &sai->pdev->dev; + int ret; + + if (!IS_ERR_OR_NULL(sai->pinctrl) && !IS_ERR_OR_NULL(sai->pins_state)) { + ret = pinctrl_select_state(sai->pinctrl, sai->pins_state); + if (ret) { + dev_err(dev, "failed to set proper pins state: %d\n", ret); + return ret; + } + } + + return 0; +} + static struct snd_soc_dai_driver fsl_sai_dai_template = { .probe = fsl_sai_dai_probe, .playback = { @@ -782,6 +831,7 @@ static struct snd_soc_dai_driver fsl_sai_dai_template = { static const struct snd_soc_component_driver fsl_component = { .name = "fsl-sai", + .resume = fsl_sai_dai_resume, }; static struct reg_default fsl_sai_reg_defaults_ofs0[] = { @@ -1147,6 +1197,8 @@ static int fsl_sai_probe(struct platform_device *pdev) sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; sai->dma_params_tx.maxburst = FSL_SAI_MAXBURST_TX; + sai->pinctrl = devm_pinctrl_get(&pdev->dev); + platform_set_drvdata(pdev, sai); pm_runtime_enable(dev); if (!pm_runtime_enabled(dev)) { diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h index e28a49ce12ef..c0b6bc42fc3c 100644 --- a/sound/soc/fsl/fsl_sai.h +++ b/sound/soc/fsl/fsl_sai.h @@ -278,6 +278,8 @@ struct fsl_sai { struct fsl_sai_verid verid; struct fsl_sai_param param; struct pm_qos_request pm_qos_req; + struct pinctrl *pinctrl; + struct pinctrl_state *pins_state; }; #define TX 1 -- 2.17.1