Alsa-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] ASoC: fsl_sai: Fix noise when using EDMA
@ 2019-08-30 20:09 Daniel Baluta
  2019-08-30 20:09 ` [alsa-devel] " Daniel Baluta
  2019-09-06  1:24 ` Nicolin Chen
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Baluta @ 2019-08-30 20:09 UTC (permalink / raw)
  To: broonie
  Cc: festevam, nicoleotsuka, Xiubo.Lee, shengjiu.wang, alsa-devel,
	linux-kernel, timur, mihai.serban, Mihai Serban, NXP Linux Team,
	Daniel Baluta

From: Mihai Serban <mihai.serban@nxp.com>

EDMA requires the period size to be multiple of maxburst. Otherwise the
remaining bytes are not transferred and thus noise is produced.

We can handle this issue by adding a constraint on
SNDRV_PCM_HW_PARAM_PERIOD_SIZE to be multiple of tx/rx maxburst value.

Cc: NXP Linux Team <linux-imx@nxp.com>
Signed-off-by: Mihai Serban <mihai.serban@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
---
 sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
 sound/soc/fsl/fsl_sai.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 728307acab90..fe126029f4e3 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
 			   FSL_SAI_CR3_TRCE_MASK,
 			   FSL_SAI_CR3_TRCE);
 
+	/*
+	 * some DMA controllers need period size to be a multiple of
+	 * tx/rx maxburst
+	 */
+	if (sai->soc_data->use_constraint_period_size)
+		snd_pcm_hw_constraint_step(substream->runtime, 0,
+					   SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+					   tx ? sai->dma_params_tx.maxburst :
+					   sai->dma_params_rx.maxburst);
+
 	ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
 			SNDRV_PCM_HW_PARAM_RATE, &fsl_sai_rate_constraints);
 
@@ -1011,30 +1021,35 @@ static const struct fsl_sai_soc_data fsl_sai_vf610_data = {
 	.use_imx_pcm = false,
 	.fifo_depth = 32,
 	.reg_offset = 0,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx6sx_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 32,
 	.reg_offset = 0,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx7ulp_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 16,
 	.reg_offset = 8,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx8mq_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 128,
 	.reg_offset = 8,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx8qm_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 64,
 	.reg_offset = 0,
+	.use_constraint_period_size = true,
 };
 
 static const struct of_device_id fsl_sai_ids[] = {
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
index b89b0ca26053..3a3f6f8e5595 100644
--- a/sound/soc/fsl/fsl_sai.h
+++ b/sound/soc/fsl/fsl_sai.h
@@ -157,6 +157,7 @@
 
 struct fsl_sai_soc_data {
 	bool use_imx_pcm;
+	bool use_constraint_period_size;
 	unsigned int fifo_depth;
 	unsigned int reg_offset;
 };
-- 
2.17.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [alsa-devel] [PATCH] ASoC: fsl_sai: Fix noise when using EDMA
  2019-08-30 20:09 [PATCH] ASoC: fsl_sai: Fix noise when using EDMA Daniel Baluta
@ 2019-08-30 20:09 ` " Daniel Baluta
  2019-09-06  1:24 ` Nicolin Chen
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Baluta @ 2019-08-30 20:09 UTC (permalink / raw)
  To: broonie
  Cc: alsa-devel, timur, Xiubo.Lee, Daniel Baluta, shengjiu.wang,
	linux-kernel, nicoleotsuka, NXP Linux Team, Mihai Serban,
	festevam, mihai.serban

From: Mihai Serban <mihai.serban@nxp.com>

EDMA requires the period size to be multiple of maxburst. Otherwise the
remaining bytes are not transferred and thus noise is produced.

We can handle this issue by adding a constraint on
SNDRV_PCM_HW_PARAM_PERIOD_SIZE to be multiple of tx/rx maxburst value.

Cc: NXP Linux Team <linux-imx@nxp.com>
Signed-off-by: Mihai Serban <mihai.serban@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
---
 sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
 sound/soc/fsl/fsl_sai.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 728307acab90..fe126029f4e3 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
 			   FSL_SAI_CR3_TRCE_MASK,
 			   FSL_SAI_CR3_TRCE);
 
+	/*
+	 * some DMA controllers need period size to be a multiple of
+	 * tx/rx maxburst
+	 */
+	if (sai->soc_data->use_constraint_period_size)
+		snd_pcm_hw_constraint_step(substream->runtime, 0,
+					   SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+					   tx ? sai->dma_params_tx.maxburst :
+					   sai->dma_params_rx.maxburst);
+
 	ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
 			SNDRV_PCM_HW_PARAM_RATE, &fsl_sai_rate_constraints);
 
@@ -1011,30 +1021,35 @@ static const struct fsl_sai_soc_data fsl_sai_vf610_data = {
 	.use_imx_pcm = false,
 	.fifo_depth = 32,
 	.reg_offset = 0,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx6sx_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 32,
 	.reg_offset = 0,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx7ulp_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 16,
 	.reg_offset = 8,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx8mq_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 128,
 	.reg_offset = 8,
+	.use_constraint_period_size = false,
 };
 
 static const struct fsl_sai_soc_data fsl_sai_imx8qm_data = {
 	.use_imx_pcm = true,
 	.fifo_depth = 64,
 	.reg_offset = 0,
+	.use_constraint_period_size = true,
 };
 
 static const struct of_device_id fsl_sai_ids[] = {
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
index b89b0ca26053..3a3f6f8e5595 100644
--- a/sound/soc/fsl/fsl_sai.h
+++ b/sound/soc/fsl/fsl_sai.h
@@ -157,6 +157,7 @@
 
 struct fsl_sai_soc_data {
 	bool use_imx_pcm;
+	bool use_constraint_period_size;
 	unsigned int fifo_depth;
 	unsigned int reg_offset;
 };
-- 
2.17.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: fsl_sai: Fix noise when using EDMA
  2019-08-30 20:09 [PATCH] ASoC: fsl_sai: Fix noise when using EDMA Daniel Baluta
  2019-08-30 20:09 ` [alsa-devel] " Daniel Baluta
@ 2019-09-06  1:24 ` Nicolin Chen
  2019-09-06  6:46   ` Daniel Baluta
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolin Chen @ 2019-09-06  1:24 UTC (permalink / raw)
  To: Daniel Baluta
  Cc: alsa-devel, timur, Xiubo.Lee, shengjiu.wang, linux-kernel,
	broonie, NXP Linux Team, Mihai Serban, festevam, mihai.serban

On Fri, Aug 30, 2019 at 11:09:00PM +0300, Daniel Baluta wrote:
> From: Mihai Serban <mihai.serban@nxp.com>
> 
> EDMA requires the period size to be multiple of maxburst. Otherwise the
> remaining bytes are not transferred and thus noise is produced.
> 
> We can handle this issue by adding a constraint on
> SNDRV_PCM_HW_PARAM_PERIOD_SIZE to be multiple of tx/rx maxburst value.
> 
> Cc: NXP Linux Team <linux-imx@nxp.com>
> Signed-off-by: Mihai Serban <mihai.serban@nxp.com>
> Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
> ---
>  sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
>  sound/soc/fsl/fsl_sai.h |  1 +
>  2 files changed, 16 insertions(+)
> 
> diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> index 728307acab90..fe126029f4e3 100644
> --- a/sound/soc/fsl/fsl_sai.c
> +++ b/sound/soc/fsl/fsl_sai.c
> @@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
>  			   FSL_SAI_CR3_TRCE_MASK,
>  			   FSL_SAI_CR3_TRCE);
>  
> +	/*
> +	 * some DMA controllers need period size to be a multiple of
> +	 * tx/rx maxburst
> +	 */
> +	if (sai->soc_data->use_constraint_period_size)
> +		snd_pcm_hw_constraint_step(substream->runtime, 0,
> +					   SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
> +					   tx ? sai->dma_params_tx.maxburst :
> +					   sai->dma_params_rx.maxburst);

I feel that PERIOD_SIZE could be used for some other cases than
being related to maxburst....
  
>  static const struct of_device_id fsl_sai_ids[] = {
> diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
> index b89b0ca26053..3a3f6f8e5595 100644
> --- a/sound/soc/fsl/fsl_sai.h
> +++ b/sound/soc/fsl/fsl_sai.h
> @@ -157,6 +157,7 @@
>  
>  struct fsl_sai_soc_data {
>  	bool use_imx_pcm;
> +	bool use_constraint_period_size;

....so maybe the soc specific flag here could be something like
	bool use_edma;

What do you think?
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: fsl_sai: Fix noise when using EDMA
  2019-09-06  1:24 ` Nicolin Chen
@ 2019-09-06  6:46   ` Daniel Baluta
  2019-09-09 19:32     ` Nicolin Chen
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Baluta @ 2019-09-06  6:46 UTC (permalink / raw)
  To: Nicolin Chen
  Cc: Linux-ALSA, Timur Tabi, Xiubo Li, Fabio Estevam, S.j. Wang,
	Linux Kernel Mailing List, Mark Brown, NXP Linux Team,
	Mihai Serban, Daniel Baluta, Mihai Serban

On Fri, Sep 6, 2019 at 4:25 AM Nicolin Chen <nicoleotsuka@gmail.com> wrote:
>
> On Fri, Aug 30, 2019 at 11:09:00PM +0300, Daniel Baluta wrote:
> > From: Mihai Serban <mihai.serban@nxp.com>
> >
> > EDMA requires the period size to be multiple of maxburst. Otherwise the
> > remaining bytes are not transferred and thus noise is produced.
> >
> > We can handle this issue by adding a constraint on
> > SNDRV_PCM_HW_PARAM_PERIOD_SIZE to be multiple of tx/rx maxburst value.
> >
> > Cc: NXP Linux Team <linux-imx@nxp.com>
> > Signed-off-by: Mihai Serban <mihai.serban@nxp.com>
> > Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
> > ---
> >  sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
> >  sound/soc/fsl/fsl_sai.h |  1 +
> >  2 files changed, 16 insertions(+)
> >
> > diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> > index 728307acab90..fe126029f4e3 100644
> > --- a/sound/soc/fsl/fsl_sai.c
> > +++ b/sound/soc/fsl/fsl_sai.c
> > @@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
> >                          FSL_SAI_CR3_TRCE_MASK,
> >                          FSL_SAI_CR3_TRCE);
> >
> > +     /*
> > +      * some DMA controllers need period size to be a multiple of
> > +      * tx/rx maxburst
> > +      */
> > +     if (sai->soc_data->use_constraint_period_size)
> > +             snd_pcm_hw_constraint_step(substream->runtime, 0,
> > +                                        SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
> > +                                        tx ? sai->dma_params_tx.maxburst :
> > +                                        sai->dma_params_rx.maxburst);
>
> I feel that PERIOD_SIZE could be used for some other cases than
> being related to maxburst....
>
> >  static const struct of_device_id fsl_sai_ids[] = {
> > diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
> > index b89b0ca26053..3a3f6f8e5595 100644
> > --- a/sound/soc/fsl/fsl_sai.h
> > +++ b/sound/soc/fsl/fsl_sai.h
> > @@ -157,6 +157,7 @@
> >
> >  struct fsl_sai_soc_data {
> >       bool use_imx_pcm;
> > +     bool use_constraint_period_size;
>
> ....so maybe the soc specific flag here could be something like
>         bool use_edma;
>
> What do you think?

I think your suggestion is a little bit better than what we have. But what if
in the future another DMA controler (not eDMA) will need the same constraint.

Wouldn't it be confusing?
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: fsl_sai: Fix noise when using EDMA
  2019-09-06  6:46   ` Daniel Baluta
@ 2019-09-09 19:32     ` Nicolin Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolin Chen @ 2019-09-09 19:32 UTC (permalink / raw)
  To: Daniel Baluta
  Cc: Linux-ALSA, Timur Tabi, Xiubo Li, Fabio Estevam, S.j. Wang,
	Linux Kernel Mailing List, Mark Brown, NXP Linux Team,
	Mihai Serban, Daniel Baluta, Mihai Serban

On Fri, Sep 06, 2019 at 09:46:12AM +0300, Daniel Baluta wrote:
> On Fri, Sep 6, 2019 at 4:25 AM Nicolin Chen <nicoleotsuka@gmail.com> wrote:
> >
> > On Fri, Aug 30, 2019 at 11:09:00PM +0300, Daniel Baluta wrote:
> > > From: Mihai Serban <mihai.serban@nxp.com>
> > >
> > > EDMA requires the period size to be multiple of maxburst. Otherwise the
> > > remaining bytes are not transferred and thus noise is produced.
> > >
> > > We can handle this issue by adding a constraint on
> > > SNDRV_PCM_HW_PARAM_PERIOD_SIZE to be multiple of tx/rx maxburst value.
> > >
> > > Cc: NXP Linux Team <linux-imx@nxp.com>
> > > Signed-off-by: Mihai Serban <mihai.serban@nxp.com>
> > > Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
> > > ---
> > >  sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
> > >  sound/soc/fsl/fsl_sai.h |  1 +
> > >  2 files changed, 16 insertions(+)
> > >
> > > diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> > > index 728307acab90..fe126029f4e3 100644
> > > --- a/sound/soc/fsl/fsl_sai.c
> > > +++ b/sound/soc/fsl/fsl_sai.c
> > > @@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
> > >                          FSL_SAI_CR3_TRCE_MASK,
> > >                          FSL_SAI_CR3_TRCE);
> > >
> > > +     /*
> > > +      * some DMA controllers need period size to be a multiple of
> > > +      * tx/rx maxburst
> > > +      */
> > > +     if (sai->soc_data->use_constraint_period_size)
> > > +             snd_pcm_hw_constraint_step(substream->runtime, 0,:
> > > +                                        SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
> > > +                                        tx ? sai->dma_params_tx.maxburst :
> > > +                                        sai->dma_params_rx.maxburst);
> >
> > I feel that PERIOD_SIZE could be used for some other cases than
> > being related to maxburst....
> >
> > >  static const struct of_device_id fsl_sai_ids[] = {
> > > diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
> > > index b89b0ca26053..3a3f6f8e5595 100644
> > > --- a/sound/soc/fsl/fsl_sai.h
> > > +++ b/sound/soc/fsl/fsl_sai.h
> > > @@ -157,6 +157,7 @@
> > >
> > >  struct fsl_sai_soc_data {
> > >       bool use_imx_pcm;
> > > +     bool use_constraint_period_size;
> >
> > ....so maybe the soc specific flag here could be something like
> >         bool use_edma;
> >
> > What do you think?
> 
> I think your suggestion is a little bit better than what we have. But what if

The better part of using "edma" word, I felt, is to match this
"soc" word in the structure name.

> in the future another DMA controler (not eDMA) will need the same constraint.

That sounds like a valid point to me, I don't feel it'd happen
that often though. I'd be okay if you insist to keep yours :)
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30 20:09 [PATCH] ASoC: fsl_sai: Fix noise when using EDMA Daniel Baluta
2019-08-30 20:09 ` [alsa-devel] " Daniel Baluta
2019-09-06  1:24 ` Nicolin Chen
2019-09-06  6:46   ` Daniel Baluta
2019-09-09 19:32     ` Nicolin Chen

Alsa-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/alsa-devel/0 alsa-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 alsa-devel alsa-devel/ https://lore.kernel.org/alsa-devel \
		alsa-devel@alsa-project.org alsa-devel@archiver.kernel.org
	public-inbox-index alsa-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.alsa-project.alsa-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox