Skip to content

Commit e958b58

Browse files
robhancocksedbroonie
authored andcommitted
ASoC: xilinx: xlnx_formatter_pcm: Make buffer bytes multiple of period bytes
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: 6f6c3c3 ("ASoC: xlnx: add pcm formatter platform driver") Cc: Devarsh Thakkar <[email protected]> Signed-off-by: Robert Hancock <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f517ba4 commit e958b58

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

sound/soc/xilinx/xlnx_formatter_pcm.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define XLNX_AUD_XFER_COUNT 0x28
3838
#define XLNX_AUD_CH_STS_START 0x2C
3939
#define XLNX_BYTES_PER_CH 0x44
40+
#define XLNX_AUD_ALIGN_BYTES 64
4041

4142
#define AUD_STS_IOC_IRQ_MASK BIT(31)
4243
#define AUD_STS_CH_STS_MASK BIT(29)
@@ -368,12 +369,32 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
368369
snd_soc_set_runtime_hwparams(substream, &xlnx_pcm_hardware);
369370
runtime->private_data = stream_data;
370371

371-
/* Resize the period size divisible by 64 */
372+
/* Resize the period bytes as divisible by 64 */
372373
err = snd_pcm_hw_constraint_step(runtime, 0,
373-
SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64);
374+
SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
375+
XLNX_AUD_ALIGN_BYTES);
374376
if (err) {
375377
dev_err(component->dev,
376-
"unable to set constraint on period bytes\n");
378+
"Unable to set constraint on period bytes\n");
379+
return err;
380+
}
381+
382+
/* Resize the buffer bytes as divisible by 64 */
383+
err = snd_pcm_hw_constraint_step(runtime, 0,
384+
SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
385+
XLNX_AUD_ALIGN_BYTES);
386+
if (err) {
387+
dev_err(component->dev,
388+
"Unable to set constraint on buffer bytes\n");
389+
return err;
390+
}
391+
392+
/* Set periods as integer multiple */
393+
err = snd_pcm_hw_constraint_integer(runtime,
394+
SNDRV_PCM_HW_PARAM_PERIODS);
395+
if (err < 0) {
396+
dev_err(component->dev,
397+
"Unable to set constraint on periods to be integer\n");
377398
return err;
378399
}
379400

0 commit comments

Comments
 (0)