All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Hancock <robert.hancock@calian.com>
To: alsa-devel@alsa-project.org
Cc: kuninori.morimoto.gx@renesas.com,
	Devarsh Thakkar <devarsh.thakkar@xilinx.com>,
	michal.simek@xilinx.com, maruthi.srinivas.bayyavarapu@xilinx.com,
	tiwai@suse.com, Robert Hancock <robert.hancock@calian.com>,
	broonie@kernel.org
Subject: [PATCH v2 1/6] ASoC: xilinx: xlnx_formatter_pcm: Make buffer bytes multiple of period bytes
Date: Fri,  7 Jan 2022 15:47:06 -0600	[thread overview]
Message-ID: <20220107214711.1100162-2-robert.hancock@calian.com> (raw)
In-Reply-To: <20220107214711.1100162-1-robert.hancock@calian.com>

This patch is based on one in the Xilinx kernel tree, "ASoc: xlnx: Make
buffer bytes multiple of period bytes" by Devarsh Thakkar. The same
issue exists in the mainline version of the driver. The original
patch description is as follows:

"The Xilinx Audio Formatter IP has a constraint on period
bytes to be multiple of 64. This leads to driver changing
the period size to suitable frames such that period bytes
are multiple of 64.

Now since period bytes and period size are updated but not
the buffer bytes, this may make the buffer bytes unaligned
and not multiple of period bytes.

When this happens we hear popping noise as while DMA is being
done the buffer bytes are not enough to complete DMA access
for last period of frame within the application buffer boundary.

To avoid this, align buffer bytes too as multiple of 64, and
set another constraint to always enforce number of periods as
integer. Now since, there is already a rule in alsa core
to enforce Buffer size = Number of Periods * Period Size
this automatically aligns buffer bytes as multiple of period
bytes."

Fixes: 6f6c3c36f091 ("ASoC: xlnx: add pcm formatter platform driver")
Cc: Devarsh Thakkar <devarsh.thakkar@xilinx.com>
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
---
 sound/soc/xilinx/xlnx_formatter_pcm.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/sound/soc/xilinx/xlnx_formatter_pcm.c b/sound/soc/xilinx/xlnx_formatter_pcm.c
index 91afea9d5de6..ce19a6058b27 100644
--- a/sound/soc/xilinx/xlnx_formatter_pcm.c
+++ b/sound/soc/xilinx/xlnx_formatter_pcm.c
@@ -37,6 +37,7 @@
 #define XLNX_AUD_XFER_COUNT	0x28
 #define XLNX_AUD_CH_STS_START	0x2C
 #define XLNX_BYTES_PER_CH	0x44
+#define XLNX_AUD_ALIGN_BYTES	64
 
 #define AUD_STS_IOC_IRQ_MASK	BIT(31)
 #define AUD_STS_CH_STS_MASK	BIT(29)
@@ -368,12 +369,32 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
 	snd_soc_set_runtime_hwparams(substream, &xlnx_pcm_hardware);
 	runtime->private_data = stream_data;
 
-	/* Resize the period size divisible by 64 */
+	/* Resize the period bytes as divisible by 64 */
 	err = snd_pcm_hw_constraint_step(runtime, 0,
-					 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64);
+					 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
+					 XLNX_AUD_ALIGN_BYTES);
 	if (err) {
 		dev_err(component->dev,
-			"unable to set constraint on period bytes\n");
+			"Unable to set constraint on period bytes\n");
+		return err;
+	}
+
+	/* Resize the buffer bytes as divisible by 64 */
+	err = snd_pcm_hw_constraint_step(runtime, 0,
+					 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+					 XLNX_AUD_ALIGN_BYTES);
+	if (err) {
+		dev_err(component->dev,
+			"Unable to set constraint on buffer bytes\n");
+		return err;
+	}
+
+	/* Set periods as integer multiple */
+	err = snd_pcm_hw_constraint_integer(runtime,
+					    SNDRV_PCM_HW_PARAM_PERIODS);
+	if (err < 0) {
+		dev_err(component->dev,
+			"Unable to set constraint on periods to be integer\n");
 		return err;
 	}
 
-- 
2.31.1


  reply	other threads:[~2022-01-07 21:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07 21:47 [PATCH v2 0/6] ASoC: Xilinx fixes Robert Hancock
2022-01-07 21:47 ` Robert Hancock [this message]
2022-01-07 21:47 ` [PATCH v2 2/6] ASoC: xilinx: xlnx_formatter_pcm: Handle sysclk setting Robert Hancock
2022-01-10 14:46   ` Mark Brown
2022-01-10 18:28     ` Robert Hancock
2022-01-10 20:31       ` Mark Brown
2022-01-10 21:24         ` Robert Hancock
2022-01-11 13:13           ` Mark Brown
2022-01-07 21:47 ` [PATCH v2 3/6] ASoC: xilinx: xlnx_i2s: create drvdata structure Robert Hancock
2022-01-07 21:47 ` [PATCH v2 4/6] ASoC: xilinx: xlnx_i2s: Handle sysclk setting Robert Hancock
2022-01-07 21:47 ` [PATCH v2 5/6] ASoC: simple-card: fix probe failure on platform component Robert Hancock
2022-01-07 21:47 ` [PATCH v2 6/6] ASoC: simple-card-utils: Set sysclk on all components Robert Hancock
2022-01-10 15:51 ` (subset) [PATCH v2 0/6] ASoC: Xilinx fixes Mark Brown
2022-01-11 14:21 ` 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=20220107214711.1100162-2-robert.hancock@calian.com \
    --to=robert.hancock@calian.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=devarsh.thakkar@xilinx.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=maruthi.srinivas.bayyavarapu@xilinx.com \
    --cc=michal.simek@xilinx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.