From 65a300d02a1333f6c4a641872e692ee94acbcedb Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Thu, 8 Feb 2024 11:48:54 +0200 Subject: [PATCH 1/2] audio: dai-zephyr: add function for computing DMA slot 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 --- src/audio/dai-zephyr.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index ca5488c07231..4ae770013cd4 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -565,6 +565,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; + return 0; + } + + return 0; +} + static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t period_bytes, uint32_t period_count) { @@ -578,11 +609,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) { From 5cbf0be5eed9d4ff82e267337ffccd983c15759a Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Thu, 8 Feb 2024 11:51:43 +0200 Subject: [PATCH 2/2] ipc3: dai: change channel decoding function for native SAI and ESAI The native SAI and ESAI drivers use a different handshake encoding. As such, when using native Zephyr drivers use a different function for decoding the channel from the handshake. Signed-off-by: Laurentiu Mihalcea --- src/ipc/ipc3/dai.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ipc/ipc3/dai.c b/src/ipc/ipc3/dai.c index 697b00c960ca..8586dc779cff 100644 --- a/src/ipc/ipc3/dai.c +++ b/src/ipc/ipc3/dai.c @@ -63,7 +63,12 @@ int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void case SOF_DAI_IMX_ESAI: handshake = dai_get_handshake(dd->dai, dai->direction, dd->stream_id); +/* TODO: remove this when transition to native drivers is complete on all NXP platforms */ +#ifndef CONFIG_ZEPHYR_NATIVE_DRIVERS channel = EDMA_HS_GET_CHAN(handshake); +#else + channel = handshake & GENMASK(7, 0); +#endif /* CONFIG_ZEPHYR_NATIVE_DRIVERS */ break; case SOF_DAI_IMX_MICFIL: channel = dai_get_handshake(dd->dai, dai->direction,