Skip to content

Commit 8f0280c

Browse files
Codrin Ciubotariubroonie
authored andcommitted
ASoC: atmel: mchp-pdmc: Improve maxburst calculation for better performance
Improve the DMA descriptor calculation by dividing the period size by the product of sample size and DMA chunk size, rather than just DMA chunk size. Ensure that all DMA descriptors start from a well-aligned address to improve the reliability and efficiency of DMA operations and avoid potential issues related to misaligned descriptors. [andrei.simion@microchip.com: Adjust the commit title. Reword the commit message. Add MACROS for each DMA size chunk supported by mchp-pdmc. Add DMA_BURST_ALIGNED preprocesor function to check the alignment of the DMA burst.] Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> Signed-off-by: Andrei Simion <andrei.simion@microchip.com> Link: https://patch.msgid.link/20240911122909.133399-2-andrei.simion@microchip.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 0b0aa67 commit 8f0280c

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

sound/soc/atmel/mchp-pdmc.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@
9090
#define MCHP_PDMC_DS_NO 2
9191
#define MCHP_PDMC_EDGE_NO 2
9292

93+
/*
94+
* ---- DMA chunk size allowed ----
95+
*/
96+
#define MCHP_PDMC_DMA_8_WORD_CHUNK 8
97+
#define MCHP_PDMC_DMA_4_WORD_CHUNK 4
98+
#define MCHP_PDMC_DMA_2_WORD_CHUNK 2
99+
#define MCHP_PDMC_DMA_1_WORD_CHUNK 1
100+
#define DMA_BURST_ALIGNED(_p, _s, _w) !(_p % (_s * _w))
101+
93102
struct mic_map {
94103
int ds_pos;
95104
int clk_edge;
@@ -511,15 +520,18 @@ static u32 mchp_pdmc_mr_set_osr(int audio_filter_en, unsigned int osr)
511520
return 0;
512521
}
513522

514-
static inline int mchp_pdmc_period_to_maxburst(int period_size)
523+
static inline int mchp_pdmc_period_to_maxburst(int period_size, int sample_size)
515524
{
516-
if (!(period_size % 8))
517-
return 8;
518-
if (!(period_size % 4))
519-
return 4;
520-
if (!(period_size % 2))
521-
return 2;
522-
return 1;
525+
int p_size = period_size;
526+
int s_size = sample_size;
527+
528+
if (DMA_BURST_ALIGNED(p_size, s_size, MCHP_PDMC_DMA_8_WORD_CHUNK))
529+
return MCHP_PDMC_DMA_8_WORD_CHUNK;
530+
if (DMA_BURST_ALIGNED(p_size, s_size, MCHP_PDMC_DMA_4_WORD_CHUNK))
531+
return MCHP_PDMC_DMA_4_WORD_CHUNK;
532+
if (DMA_BURST_ALIGNED(p_size, s_size, MCHP_PDMC_DMA_2_WORD_CHUNK))
533+
return MCHP_PDMC_DMA_2_WORD_CHUNK;
534+
return MCHP_PDMC_DMA_1_WORD_CHUNK;
523535
}
524536

525537
static struct snd_pcm_chmap_elem mchp_pdmc_std_chmaps[] = {
@@ -547,14 +559,18 @@ static int mchp_pdmc_hw_params(struct snd_pcm_substream *substream,
547559
unsigned int channels = params_channels(params);
548560
unsigned int osr = 0, osr_start;
549561
unsigned int fs = params_rate(params);
562+
int sample_bytes = params_physical_width(params) / 8;
563+
int period_bytes = params_period_size(params) *
564+
params_channels(params) * sample_bytes;
565+
int maxburst;
550566
u32 mr_val = 0;
551567
u32 cfgr_val = 0;
552568
int i;
553569
int ret;
554570

555-
dev_dbg(comp->dev, "%s() rate=%u format=%#x width=%u channels=%u\n",
571+
dev_dbg(comp->dev, "%s() rate=%u format=%#x width=%u channels=%u period_bytes=%d\n",
556572
__func__, params_rate(params), params_format(params),
557-
params_width(params), params_channels(params));
573+
params_width(params), params_channels(params), period_bytes);
558574

559575
if (channels > dd->mic_no) {
560576
dev_err(comp->dev, "more channels %u than microphones %d\n",
@@ -608,7 +624,8 @@ static int mchp_pdmc_hw_params(struct snd_pcm_substream *substream,
608624

609625
mr_val |= FIELD_PREP(MCHP_PDMC_MR_SINCORDER_MASK, dd->sinc_order);
610626

611-
dd->addr.maxburst = mchp_pdmc_period_to_maxburst(snd_pcm_lib_period_bytes(substream));
627+
maxburst = mchp_pdmc_period_to_maxburst(period_bytes, sample_bytes);
628+
dd->addr.maxburst = maxburst;
612629
mr_val |= FIELD_PREP(MCHP_PDMC_MR_CHUNK_MASK, dd->addr.maxburst);
613630
dev_dbg(comp->dev, "maxburst set to %d\n", dd->addr.maxburst);
614631

0 commit comments

Comments
 (0)