Skip to contentSkip to conversation

ASoC: fsl_sai: Fix noise when using EDMA

PATCH Superseded Daniel Baluta 3 participants 4 messages Aug 30, 2019 – Sep 9, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: fsl_sai: Fix noise when using EDMA

From: Mihai Serban <[email protected]>

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.

---
 sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
 sound/soc/fsl/fsl_sai.h |  1 +
 2 files changed, 16 insertions(+)
sound/soc/fsl/fsl_sai.c +15 -0
index 728307acab90..fe126029f4e3 100644
@@ -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[] = {
sound/soc/fsl/fsl_sai.h +1 -0
index b89b0ca26053..3a3f6f8e5595 100644
@@ -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;
 };
Signature · 1 line
2.17.1
reviewer
#1 lore raw
Quoted 23 lines · Daniel Baluta

From: Mihai Serban <[email protected]>

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.

---
 sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
 sound/soc/fsl/fsl_sai.h |  1 +
 2 files changed, 16 insertions(+)
sound/soc/fsl/fsl_sai.c +0 -0
index 728307acab90..fe126029f4e3 100644
@@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
 			   FSL_SAI_CR3_TRCE_MASK,
 			   FSL_SAI_CR3_TRCE);

sound/soc/fsl/fsl_sai.c static int fsl_sai_startup(struct snd_pcm_substream *substream, · line 623

Quoted 10 lines
sound/soc/fsl/fsl_sai.c +9 -0
 
+	/*
+	 * 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....

sound/soc/fsl/fsl_sai.h line 160

Quoted 10 lines
sound/soc/fsl/fsl_sai.c +0 -0
 static const struct of_device_id fsl_sai_ids[] = {
sound/soc/fsl/fsl_sai.h +1 -0
index b89b0ca26053..3a3f6f8e5595 100644
@@ -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?

#2 lore raw
Quoted 46 lines · Nicolin Chen
Quoted 23 lines · Daniel Baluta

From: Mihai Serban <[email protected]>

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.

---
 sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
 sound/soc/fsl/fsl_sai.h |  1 +
 2 files changed, 16 insertions(+)
sound/soc/fsl/fsl_sai.c +0 -0
index 728307acab90..fe126029f4e3 100644
@@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
                         FSL_SAI_CR3_TRCE_MASK,
                         FSL_SAI_CR3_TRCE);

sound/soc/fsl/fsl_sai.c static int fsl_sai_startup(struct snd_pcm_substream *substream, · line 623

Quoted 10 lines
sound/soc/fsl/fsl_sai.c +9 -0
 
+     /*
+      * 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....

Quoted 7 lines
sound/soc/fsl/fsl_sai.c +0 -0
 static const struct of_device_id fsl_sai_ids[] = {
sound/soc/fsl/fsl_sai.h +0 -0
index b89b0ca26053..3a3f6f8e5595 100644
@@ -157,6 +157,7 @@
 
Quoted 8 lines

sound/soc/fsl/fsl_sai.h line 160

Quoted 3 lines
sound/soc/fsl/fsl_sai.h +1 -0
 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?

reviewer
#3 lore raw
Quoted 54 lines · Daniel Baluta
Quoted 53 lines · Nicolin Chen
Quoted 23 lines · Daniel Baluta

From: Mihai Serban <[email protected]>

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.

---
 sound/soc/fsl/fsl_sai.c | 15 +++++++++++++++
 sound/soc/fsl/fsl_sai.h |  1 +
 2 files changed, 16 insertions(+)
sound/soc/fsl/fsl_sai.c +0 -0
index 728307acab90..fe126029f4e3 100644
@@ -612,6 +612,16 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
                         FSL_SAI_CR3_TRCE_MASK,
                         FSL_SAI_CR3_TRCE);

sound/soc/fsl/fsl_sai.c static int fsl_sai_startup(struct snd_pcm_substream *substream, · line 623

Quoted 10 lines
sound/soc/fsl/fsl_sai.c +9 -0
 
+     /*
+      * 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....

sound/soc/fsl/fsl_sai.h line 160

Quoted 10 lines
sound/soc/fsl/fsl_sai.c +0 -0
 static const struct of_device_id fsl_sai_ids[] = {
sound/soc/fsl/fsl_sai.h +1 -0
index b89b0ca26053..3a3f6f8e5595 100644
@@ -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;
Quoted 3 lines
Quoted 1 line

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.

Quoted 1 line

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 :)