Skip to content

Commit

Permalink
audio: dai-zephyr: add function for computing DMA slot
Browse files Browse the repository at this point in the history
In the case of some DAIs, the DMA slot may be encoded
differently in the DAI configuration handshake. As such,
we can't count on the fact that the handshake itself can
be used as the DMA slot. To fix this, add a function which
parses the handshake and allows each DAI to use its own
encoding of the DMA slot inside the handshake.

Signed-off-by: Laurentiu Mihalcea <[email protected]>
  • Loading branch information
LaurentiuM1234 committed Feb 22, 2024
1 parent ac362b4 commit 85ccfde
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,37 @@ static int dai_verify_params(struct dai_data *dd, struct comp_dev *dev,
return 0;
}

static int dai_get_dma_slot(struct dai_data *dd, struct comp_dev *dev, uint32_t *slot)
{
struct dai_config cfg;
int ret;
int hs;

ret = dai_config_get(dd->dai->dev, &cfg, dev->direction);
if (ret < 0) {
comp_err(dev, "failed to fetch DAI configuration");
return ret;
}

hs = dai_get_handshake(dd->dai, dev->direction, dd->stream_id);
if (ret < 0) {
comp_err(dev, "failed to fetch DAI handshake");
return ret;
}

switch (cfg.type) {
case DAI_IMX_SAI:
case DAI_IMX_ESAI:
*slot = (hs & GENMASK(15, 8)) >> 8;
break;
default:
*slot = hs;
break;
}

return 0;
}

static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t period_bytes,
uint32_t period_count)
{
Expand All @@ -582,11 +613,15 @@ static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
dd->process = pcm_get_conversion_function(local_fmt, dma_fmt);
config->direction = DMA_DIR_MEM_TO_DEV;
config->dest_dev = dai_get_handshake(dd->dai, dev->direction, dd->stream_id);
err = dai_get_dma_slot(dd, dev, &config->dest_dev);
if (err < 0)
return err;
} else {
dd->process = pcm_get_conversion_function(dma_fmt, local_fmt);
config->direction = DMA_DIR_DEV_TO_MEM;
config->src_dev = dai_get_handshake(dd->dai, dev->direction, dd->stream_id);
err = dai_get_dma_slot(dd, dev, &config->src_dev);
if (err < 0)
return err;
}

if (!dd->process) {
Expand Down

0 comments on commit 85ccfde

Please sign in to comment.