public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Shengjiu Wang <shengjiu.wang@nxp.com>
Cc: lgirdwood@gmail.com, broonie@kernel.org, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, kernel@pengutronix.de,
	festevam@gmail.com, linux-sound@vger.kernel.org,
	devicetree@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, shengjiu.wang@gmail.com,
	Xiubo.Lee@gmail.com, nicoleotsuka@gmail.com, perex@perex.cz,
	tiwai@suse.com, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v4 2/4] ASoC: fsl_asrc_m2m: Add option to start ASRC before DMA device for M2M
Date: Fri, 6 Feb 2026 11:43:46 -0500	[thread overview]
Message-ID: <aYYaQtF46oDTR-Mi@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260206014805.3897764-3-shengjiu.wang@nxp.com>

On Fri, Feb 06, 2026 at 09:48:03AM +0800, Shengjiu Wang wrote:
> There is a limitation on i.MX952 that dma request is not cleared at the
> end of conversion with dma slave mode. Which causes sample is dropped
> from the input fifo on the second time if dma is triggered before the
> client device and EDMA may copy wrong data from output fifo as the output
> fifo is not ready in the beginning.
>
> The solution is to trigger asrc before dma on i.MX952, and add delay to
> wait output data is generated then start the EDMA for output, otherwise
> the m2m function has noise issues.
>
> So add an option to start ASRC first for M2M before ASRC is enabled on
> i.MX952.
>
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>
>  sound/soc/fsl/fsl_asrc.c        | 22 ++++++++++++++++++++++
>  sound/soc/fsl/fsl_asrc.h        |  4 ++++
>  sound/soc/fsl/fsl_asrc_common.h |  4 ++++
>  sound/soc/fsl/fsl_asrc_m2m.c    |  8 +++++++-
>  4 files changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
> index 92fb16f7be45..2fe25667c888 100644
> --- a/sound/soc/fsl/fsl_asrc.c
> +++ b/sound/soc/fsl/fsl_asrc.c
> @@ -1078,6 +1078,26 @@ static unsigned int fsl_asrc_get_output_fifo_size(struct fsl_asrc_pair *pair)
>  	return val >> ASRFSTi_OUTPUT_FIFO_SHIFT;
>  }
>
> +static bool fsl_asrc_m2m_output_ready(struct fsl_asrc_pair *pair)
> +{
> +	struct fsl_asrc *asrc = pair->asrc;
> +	enum asrc_pair_index index = pair->index;
> +	u32 val;
> +	int ret;
> +
> +	/* Check output fifo status if it exceeds the watermark. */
> +	ret = regmap_read_poll_timeout(asrc->regmap, REG_ASRFST(index), val,
> +				       (ASRFSTi_OUTPUT_FIFO_FILL(val) >= ASRC_M2M_OUTPUTFIFO_WML),
> +				       1, 1000);
> +
> +	if (ret) {
> +		pair_warn("output is not ready\n");
> +		return false;
> +	}
> +
> +	return true;
> +}
> +
>  static int fsl_asrc_m2m_prepare(struct fsl_asrc_pair *pair)
>  {
>  	struct fsl_asrc_pair_priv *pair_priv = pair->private;
> @@ -1275,6 +1295,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
>
>  	asrc_priv->soc = of_device_get_match_data(&pdev->dev);
>  	asrc->use_edma = asrc_priv->soc->use_edma;
> +	asrc->start_before_dma = asrc_priv->soc->start_before_dma;
>  	asrc->get_dma_channel = fsl_asrc_get_dma_channel;
>  	asrc->request_pair = fsl_asrc_request_pair;
>  	asrc->release_pair = fsl_asrc_release_pair;
> @@ -1289,6 +1310,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
>  	asrc->m2m_get_maxburst = fsl_asrc_m2m_get_maxburst;
>  	asrc->m2m_pair_resume = fsl_asrc_m2m_pair_resume;
>  	asrc->m2m_get_cap = fsl_asrc_m2m_get_cap;
> +	asrc->m2m_output_ready = fsl_asrc_m2m_output_ready;
>
>  	if (of_device_is_compatible(np, "fsl,imx35-asrc")) {
>  		asrc_priv->clk_map[IN] = input_clk_map_imx35;
> diff --git a/sound/soc/fsl/fsl_asrc.h b/sound/soc/fsl/fsl_asrc.h
> index 1c492eb237f5..60b6865ca952 100644
> --- a/sound/soc/fsl/fsl_asrc.h
> +++ b/sound/soc/fsl/fsl_asrc.h
> @@ -257,6 +257,8 @@
>  #define ASRFSTi_OUTPUT_FIFO_WIDTH	7
>  #define ASRFSTi_OUTPUT_FIFO_SHIFT	12
>  #define ASRFSTi_OUTPUT_FIFO_MASK	(((1 << ASRFSTi_OUTPUT_FIFO_WIDTH) - 1) << ASRFSTi_OUTPUT_FIFO_SHIFT)
> +#define ASRFSTi_OUTPUT_FIFO_FILL(v)	\
> +	(((v) & ASRFSTi_OUTPUT_FIFO_MASK) >> ASRFSTi_OUTPUT_FIFO_SHIFT)
>  #define ASRFSTi_IAEi_SHIFT		11
>  #define ASRFSTi_IAEi_MASK		(1 << ASRFSTi_IAEi_SHIFT)
>  #define ASRFSTi_IAEi			(1 << ASRFSTi_IAEi_SHIFT)
> @@ -432,10 +434,12 @@ struct dma_block {
>   *
>   * @use_edma: using edma as dma device or not
>   * @channel_bits: width of ASRCNCR register for each pair
> + * @start_before_dma: start asrc before dma
>   */
>  struct fsl_asrc_soc_data {
>  	bool use_edma;
>  	unsigned int channel_bits;
> +	bool start_before_dma;
>  };
>
>  /**
> diff --git a/sound/soc/fsl/fsl_asrc_common.h b/sound/soc/fsl/fsl_asrc_common.h
> index 0cd595b0f629..c8a1a2b5915d 100644
> --- a/sound/soc/fsl/fsl_asrc_common.h
> +++ b/sound/soc/fsl/fsl_asrc_common.h
> @@ -107,6 +107,7 @@ struct fsl_asrc_pair {
>   * @asrc_rate: default sample rate for ASoC Back-Ends
>   * @asrc_format: default sample format for ASoC Back-Ends
>   * @use_edma: edma is used
> + * @start_before_dma: start asrc before dma
>   * @get_dma_channel: function pointer
>   * @request_pair: function pointer
>   * @release_pair: function pointer
> @@ -116,6 +117,7 @@ struct fsl_asrc_pair {
>   * @m2m_start: function pointer
>   * @m2m_unprepare: function pointer
>   * @m2m_stop: function pointer
> + * @m2m_output_ready: function pointer, check output fifo ready or not
>   * @m2m_calc_out_len: function pointer
>   * @m2m_get_maxburst: function pointer
>   * @m2m_pair_suspend: function pointer
> @@ -143,6 +145,7 @@ struct fsl_asrc {
>  	int asrc_rate;
>  	snd_pcm_format_t asrc_format;
>  	bool use_edma;
> +	bool start_before_dma;
>
>  	struct dma_chan *(*get_dma_channel)(struct fsl_asrc_pair *pair, bool dir);
>  	int (*request_pair)(int channels, struct fsl_asrc_pair *pair);
> @@ -154,6 +157,7 @@ struct fsl_asrc {
>  	int (*m2m_start)(struct fsl_asrc_pair *pair);
>  	int (*m2m_unprepare)(struct fsl_asrc_pair *pair);
>  	int (*m2m_stop)(struct fsl_asrc_pair *pair);
> +	bool (*m2m_output_ready)(struct fsl_asrc_pair *pair);
>
>  	int (*m2m_calc_out_len)(struct fsl_asrc_pair *pair, int input_buffer_length);
>  	int (*m2m_get_maxburst)(u8 dir, struct fsl_asrc_pair *pair);
> diff --git a/sound/soc/fsl/fsl_asrc_m2m.c b/sound/soc/fsl/fsl_asrc_m2m.c
> index f46881f71e43..77999526dd9e 100644
> --- a/sound/soc/fsl/fsl_asrc_m2m.c
> +++ b/sound/soc/fsl/fsl_asrc_m2m.c
> @@ -253,15 +253,21 @@ static int asrc_m2m_device_run(struct fsl_asrc_pair *pair, struct snd_compr_task
>  	reinit_completion(&pair->complete[IN]);
>  	reinit_completion(&pair->complete[OUT]);
>
> +	if (asrc->start_before_dma)
> +		asrc->m2m_start(pair);
> +
>  	/* Submit DMA request */
>  	dmaengine_submit(pair->desc[IN]);
>  	dma_async_issue_pending(pair->desc[IN]->chan);
>  	if (out_dma_len > 0) {
> +		if (asrc->start_before_dma && asrc->m2m_output_ready)
> +			asrc->m2m_output_ready(pair);
>  		dmaengine_submit(pair->desc[OUT]);
>  		dma_async_issue_pending(pair->desc[OUT]->chan);
>  	}
>
> -	asrc->m2m_start(pair);
> +	if (!asrc->start_before_dma)
> +		asrc->m2m_start(pair);
>
>  	if (!wait_for_completion_interruptible_timeout(&pair->complete[IN], 10 * HZ)) {
>  		dev_err(dev, "out DMA task timeout\n");
> --
> 2.34.1
>


  reply	other threads:[~2026-02-06 16:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-06  1:48 [PATCH v4 0/4] ASoC: fsl_asrc: support the i.MX952 platform Shengjiu Wang
2026-02-06  1:48 ` [PATCH v4 1/4] ASoC: dt-bindings: fsl,imx-asrc: Add support for " Shengjiu Wang
2026-02-06  1:48 ` [PATCH v4 2/4] ASoC: fsl_asrc_m2m: Add option to start ASRC before DMA device for M2M Shengjiu Wang
2026-02-06 16:43   ` Frank Li [this message]
2026-02-06  1:48 ` [PATCH v4 3/4] ASoC: fsl_asrc: Add support for i.MX952 platform Shengjiu Wang
2026-02-06 16:44   ` Frank Li
2026-02-06  1:48 ` [PATCH v4 4/4] ASoC: fsl_asrc_dma: allocate memory from dma device Shengjiu Wang
2026-02-08 21:21 ` [PATCH v4 0/4] ASoC: fsl_asrc: support the i.MX952 platform Mark Brown

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=aYYaQtF46oDTR-Mi@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=Xiubo.Lee@gmail.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=nicoleotsuka@gmail.com \
    --cc=perex@perex.cz \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=shengjiu.wang@gmail.com \
    --cc=shengjiu.wang@nxp.com \
    --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