linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Viorel Suman <viorel.suman@nxp.com>
To: Daniel Baluta <daniel.baluta@nxp.com>,
	"broonie@kernel.org" <broonie@kernel.org>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	"lgirdwood@gmail.com" <lgirdwood@gmail.com>,
	"timur@kernel.org" <timur@kernel.org>,
	"Xiubo.Lee@gmail.com" <Xiubo.Lee@gmail.com>,
	"festevam@gmail.com" <festevam@gmail.com>,
	"S.j. Wang" <shengjiu.wang@nxp.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"tiwai@suse.com" <tiwai@suse.com>,
	"nicoleotsuka@gmail.com" <nicoleotsuka@gmail.com>,
	dl-linux-imx <linux-imx@nxp.com>,
	"perex@perex.cz" <perex@perex.cz>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH 3/3 v3] ASoC: fsl_sai: Move clock operation to PM runtime
Date: Mon, 22 Apr 2019 11:06:12 +0000	[thread overview]
Message-ID: <1555931172.31656.6.camel@nxp.com> (raw)
In-Reply-To: <20190421193853.10188-4-daniel.baluta@nxp.com>

Hi Daniel,

On Du, 2019-04-21 at 19:39 +0000, Daniel Baluta wrote:
> From: Shengjiu Wang <shengjiu.wang@nxp.com>
> 
> Turn off/on clocks when device enters suspend/resume. This
> can help saving power.
> 
> As a further optimization, we turn off/on mclk only when SAI
> is in master mode because otherwise mclk is externally provided.
> 
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
> ---
>  sound/soc/fsl/fsl_sai.c | 60 ++++++++++++++++++++++++++++++++++-------
>  1 file changed, 50 insertions(+), 10 deletions(-)
> 
> diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> index 8623b7f882b9..13a462360ed3 100644
> --- a/sound/soc/fsl/fsl_sai.c
> +++ b/sound/soc/fsl/fsl_sai.c
> @@ -596,15 +596,8 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
>  {
>  	struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
>  	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
> -	struct device *dev = &sai->pdev->dev;
>  	int ret;
>  
> -	ret = clk_prepare_enable(sai->bus_clk);
> -	if (ret) {
> -		dev_err(dev, "failed to enable bus clock: %d\n", ret);
> -		return ret;
> -	}
> -
>  	regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx), FSL_SAI_CR3_TRCE,
>  			   FSL_SAI_CR3_TRCE);
>  
> @@ -621,8 +614,6 @@ static void fsl_sai_shutdown(struct snd_pcm_substream *substream,
>  	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
>  
>  	regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx), FSL_SAI_CR3_TRCE, 0);
> -
> -	clk_disable_unprepare(sai->bus_clk);
>  }
>  
>  static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = {
> @@ -932,6 +923,16 @@ static int fsl_sai_runtime_suspend(struct device *dev)
>  {
>  	struct fsl_sai *sai = dev_get_drvdata(dev);
>  
> +	if (!sai->is_slave_mode) {
This check is redundant as the bits in sai->mclk_streams are set/unset for master
mode only, please check fsl_sai_hw_params and fsl_sai_hw_free functions.

> +		if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE))
> +			clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[0]]);
> +
> +		if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK))
> +			clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[1]]);
> +	}
> +
> +	clk_disable_unprepare(sai->bus_clk);
> +
>  	regcache_cache_only(sai->regmap, true);
>  	regcache_mark_dirty(sai->regmap);
>  
> @@ -941,6 +942,27 @@ static int fsl_sai_runtime_suspend(struct device *dev)
>  static int fsl_sai_runtime_resume(struct device *dev)
>  {
>  	struct fsl_sai *sai = dev_get_drvdata(dev);
> +	int ret;
> +
> +	ret = clk_prepare_enable(sai->bus_clk);
> +	if (ret) {
> +		dev_err(dev, "failed to enable bus clock: %d\n", ret);
> +		return ret;
> +	}
> +
> +	if (!sai->is_slave_mode) {
> +		if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)) {
> +			ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[1]]);
> +			if (ret)
> +				goto disable_bus_clk;
> +		}
> +
> +		if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)) {
> +			ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[0]]);
> +			if (ret)
> +				goto disable_tx_clk;
> +		}
> +	}
>  
>  	regcache_cache_only(sai->regmap, false);
>  	regmap_write(sai->regmap, FSL_SAI_TCSR, FSL_SAI_CSR_SR);
> @@ -948,7 +970,25 @@ static int fsl_sai_runtime_resume(struct device *dev)
>  	usleep_range(1000, 2000);
>  	regmap_write(sai->regmap, FSL_SAI_TCSR, 0);
>  	regmap_write(sai->regmap, FSL_SAI_RCSR, 0);
> -	return regcache_sync(sai->regmap);
> +
> +	ret = regcache_sync(sai->regmap);
> +	if (ret)
> +		goto disable_rx_clk;
> +
> +	return 0;
> +
> +disable_rx_clk:
> +	if (!sai->is_slave_mode &&
> +	    (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)))
> +		clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[0]]);
> +disable_tx_clk:
> +	if (!sai->is_slave_mode &&
> +	    (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)))
> +		clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[1]]);
> +disable_bus_clk:
> +	clk_disable_unprepare(sai->bus_clk);
> +
> +	return ret;
>  }
>  #endif /* CONFIG_PM */
>  
> -- 
> 2.17.1
> 

  parent reply	other threads:[~2019-04-22 11:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-21 19:39 [PATCH 0/3] Add runtime PM for SAI digital audio interface Daniel Baluta
2019-04-21 19:39 ` [PATCH 1/3 v2] ASoC: fsl_sai: Update is_slave_mode with correct value Daniel Baluta
2019-04-22  1:08   ` Nicolin Chen
2019-04-25 19:24   ` Applied "ASoC: fsl_sai: Update is_slave_mode with correct value" to the asoc tree Mark Brown
2019-04-25 19:26   ` Mark Brown
2019-04-21 19:39 ` [PATCH 2/3 v2] ASoC: fsl_sai: Add support for runtime pm Daniel Baluta
2019-04-22  1:09   ` Nicolin Chen
2019-04-26 10:00   ` Mark Brown
2019-04-26 12:10     ` Daniel Baluta
2019-04-27 17:17       ` Mark Brown
2019-04-21 19:39 ` [PATCH 3/3 v3] ASoC: fsl_sai: Move clock operation to PM runtime Daniel Baluta
2019-04-22  1:20   ` Nicolin Chen
2019-04-22 11:06   ` Viorel Suman [this message]
2019-04-22 11:25     ` [alsa-devel] " Daniel Baluta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1555931172.31656.6.camel@nxp.com \
    --to=viorel.suman@nxp.com \
    --cc=Xiubo.Lee@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@nxp.com \
    --cc=festevam@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=nicoleotsuka@gmail.com \
    --cc=perex@perex.cz \
    --cc=shengjiu.wang@nxp.com \
    --cc=timur@kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).