Skip to content

Commit 32d5f79

Browse files
committed
ASoC: Improvements for mchp-pdmc
Merge series from Andrei Simion <andrei.simion@microchip.com>: This patch set is intended to enhance the functionality and maintainability of the mchp-pdmc driver: - Enhances performance by refining maxburst logic. - Introduces a name for better identification and management.
2 parents 448aa89 + e6b95bd commit 32d5f79

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

sound/soc/atmel/mchp-pdmc.c

Lines changed: 29 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

@@ -760,6 +777,7 @@ static const struct snd_soc_dai_ops mchp_pdmc_dai_ops = {
760777
};
761778

762779
static struct snd_soc_dai_driver mchp_pdmc_dai = {
780+
.name = "mchp-pdmc",
763781
.capture = {
764782
.stream_name = "Capture",
765783
.channels_min = 1,

0 commit comments

Comments
 (0)