Skip to content

Commit fef58ee

Browse files
abonislawskikv2019i
authored andcommitted
dai-zephyr: check max block count supported by DMA
Check max block count supported by DMA using new Zephyr API This will allow to prepare a correct config regardless of specific DMA capabilities Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
1 parent 0658767 commit fef58ee

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

src/audio/dai-zephyr.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ static int dai_playback_params(struct comp_dev *dev, uint32_t period_bytes,
452452
*local_buf = buffer_acquire(dd->local_buffer);
453453
uint32_t local_fmt = local_buf->stream.frame_fmt;
454454
uint32_t dma_fmt = dma_buf->stream.frame_fmt;
455-
uint32_t fifo;
455+
uint32_t fifo, max_block_count, buf_size;
456456
int i, err = 0;
457457

458458
buffer_release(local_buf);
@@ -487,6 +487,27 @@ static int dai_playback_params(struct comp_dev *dev, uint32_t period_bytes,
487487

488488
comp_dbg(dev, "dai_playback_params() fifo 0x%x", fifo);
489489

490+
err = dma_get_attribute(dd->dma->z_dev, DMA_ATTR_MAX_BLOCK_COUNT,
491+
&max_block_count);
492+
if (err < 0) {
493+
comp_err(dev, "dai_playback_params(): could not get dma attr max block count, err = %d", err);
494+
goto out;
495+
}
496+
497+
if (max_block_count < period_count) {
498+
comp_dbg(dev, "dai_playback_params(): block count = %d not supported by DMA", period_count);
499+
buf_size = period_count * period_bytes;
500+
do {
501+
if (IS_ALIGNED(buf_size, max_block_count)) {
502+
period_count = max_block_count;
503+
period_bytes = buf_size / period_count;
504+
break;
505+
} else {
506+
comp_warn(dev, "dai_playback_params(): alignment error for buffer = %d, block count = %d", buf_size, max_block_count);
507+
}
508+
} while (--max_block_count > 0);
509+
}
510+
490511
err = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_RUNTIME,
491512
config->direction,
492513
period_count,
@@ -569,7 +590,7 @@ static int dai_capture_params(struct comp_dev *dev, uint32_t period_bytes,
569590
*local_buf = buffer_acquire(dd->local_buffer);
570591
uint32_t local_fmt = local_buf->stream.frame_fmt;
571592
uint32_t dma_fmt = dma_buf->stream.frame_fmt;
572-
uint32_t fifo;
593+
uint32_t fifo, max_block_count, buf_size;
573594
int i, err = 0;
574595

575596
buffer_release(local_buf);
@@ -616,6 +637,27 @@ static int dai_capture_params(struct comp_dev *dev, uint32_t period_bytes,
616637

617638
comp_dbg(dev, "dai_capture_params() fifo 0x%x", fifo);
618639

640+
err = dma_get_attribute(dd->dma->z_dev, DMA_ATTR_MAX_BLOCK_COUNT,
641+
&max_block_count);
642+
if (err < 0) {
643+
comp_err(dev, "dai_capture_params(): could not get dma attr max block count, err = %d", err);
644+
goto out;
645+
}
646+
647+
if (max_block_count < period_count) {
648+
comp_dbg(dev, "dai_capture_params(): block count = %d not supported by DMA", period_count);
649+
buf_size = period_count * period_bytes;
650+
do {
651+
if (IS_ALIGNED(buf_size, max_block_count)) {
652+
period_count = max_block_count;
653+
period_bytes = buf_size / period_count;
654+
break;
655+
} else {
656+
comp_warn(dev, "dai_capture_params(): alignment error for buffer = %d, block count = %d", buf_size, max_block_count);
657+
}
658+
} while (--max_block_count > 0);
659+
}
660+
619661
err = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_RUNTIME,
620662
config->direction,
621663
period_count,

0 commit comments

Comments
 (0)