diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index 93cdea4ea..e240ad115 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -931,18 +931,47 @@ static int copier_prepare(struct comp_dev *dev) if (ret == COMP_STATUS_STATE_ALREADY_SET) return PPL_STATUS_PATH_STOP; - if (dev->ipc_config.type == SOF_COMP_HOST && !cd->ipc_gtw) { - ret = host_zephyr_prepare(cd->hd); - if (ret < 0) - return ret; - } - - for (i = 0; i < cd->endpoint_num; i++) { - if (dev->ipc_config.type != SOF_COMP_HOST || cd->ipc_gtw) { - ret = cd->endpoint[i]->drv->ops.prepare(cd->endpoint[i]); + switch (dev->ipc_config.type) { + case SOF_COMP_HOST: + if (!cd->ipc_gtw) { + ret = host_zephyr_prepare(cd->hd); if (ret < 0) return ret; + } else { + /* handle gtw case */ + for (i = 0; i < cd->endpoint_num; i++) { + ret = cd->endpoint[i]->drv->ops.prepare(cd->endpoint[i]); + if (ret < 0) + return ret; + } } + break; + case SOF_COMP_DAI: + if (cd->endpoint_num == 1) { + ret = dai_zephyr_config_prepare(cd->dd[0], cd->endpoint[0]); + if (ret < 0) + return ret; + + ret = comp_set_state(cd->endpoint[0], COMP_TRIGGER_PREPARE); + if (ret < 0) + return ret; + + if (ret == COMP_STATUS_STATE_ALREADY_SET) + return PPL_STATUS_PATH_STOP; + + ret = dai_zephyr_prepare(cd->dd[0], cd->endpoint[0]); + if (ret < 0) + return ret; + } else { + for (i = 0; i < cd->endpoint_num; i++) { + ret = cd->endpoint[i]->drv->ops.prepare(cd->endpoint[i]); + if (ret < 0) + return ret; + } + } + break; + default: + break; } if (!cd->endpoint_num) { diff --git a/src/audio/dai-legacy.c b/src/audio/dai-legacy.c index 1a850e6e6..ca022a52f 100644 --- a/src/audio/dai-legacy.c +++ b/src/audio/dai-legacy.c @@ -618,13 +618,13 @@ static int dai_params(struct comp_dev *dev, dai_capture_params(dev, period_bytes, period_count); } -static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) +int dai_zephyr_config_prepare(struct dai_data *dd, struct comp_dev *dev) { int channel = 0; /* cannot configure DAI while active */ if (dev->state == COMP_STATE_ACTIVE) { - comp_info(dev, "dai_config_prepare(): Component is in active state."); + comp_info(dev, "dai_zephyr_config_prepare(): Component is in active state."); return 0; } @@ -634,13 +634,13 @@ static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) } if (dd->chan) { - comp_info(dev, "dai_config_prepare(): dma channel index %d already configured", + comp_info(dev, "dai_zephyr_config_prepare(): dma channel index %d already configured", dd->chan->index); return 0; } channel = dai_config_dma_channel(dd, dev, dd->dai_spec_config); - comp_info(dev, "dai_config_prepare(), channel = %d", channel); + comp_info(dev, "dai_zephyr_config_prepare(), channel = %d", channel); /* do nothing for asking for channel free, for compatibility. */ if (channel == DMA_CHAN_INVALID) { @@ -651,14 +651,14 @@ static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) /* allocate DMA channel */ dd->chan = dma_channel_get_legacy(dd->dma, channel); if (!dd->chan) { - comp_err(dev, "dai_config_prepare(): dma_channel_get() failed"); + comp_err(dev, "dai_zephyr_config_prepare(): dma_channel_get() failed"); dd->chan = NULL; return -EIO; } dd->chan->dev_data = dd; - comp_info(dev, "dai_config_prepare(): new configured dma channel index %d", + comp_info(dev, "dai_zephyr_config_prepare(): new configured dma channel index %d", dd->chan->index); /* setup callback */ @@ -668,7 +668,7 @@ static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) return 0; } -static int dai_zephyr_prepare(struct dai_data *dd, struct comp_dev *dev) +int dai_zephyr_prepare(struct dai_data *dd, struct comp_dev *dev) { struct comp_buffer __sparse_cache *buffer_c; int ret; @@ -713,7 +713,7 @@ static int dai_prepare(struct comp_dev *dev) comp_info(dev, "dai_prepare()"); - ret = dai_config_prepare(dd, dev); + ret = dai_zephyr_config_prepare(dd, dev); if (ret < 0) return ret; diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 65bb9e506..dc7848222 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -874,13 +874,13 @@ static int dai_params(struct comp_dev *dev, struct sof_ipc_stream_params *params dai_capture_params(dev, period_bytes, period_count); } -static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) +int dai_zephyr_config_prepare(struct dai_data *dd, struct comp_dev *dev) { int channel; /* cannot configure DAI while active */ if (dev->state == COMP_STATE_ACTIVE) { - comp_info(dev, "dai_config_prepare(): Component is in active state."); + comp_info(dev, "dai_zephyr_config_prepare(): Component is in active state."); return 0; } @@ -890,13 +890,13 @@ static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) } if (dd->chan) { - comp_info(dev, "dai_config_prepare(): dma channel index %d already configured", + comp_info(dev, "dai_zephyr_config_prepare(): dma channel index %d already configured", dd->chan->index); return 0; } channel = dai_config_dma_channel(dd, dev, dd->dai_spec_config); - comp_dbg(dev, "dai_config_prepare(), channel = %d", channel); + comp_dbg(dev, "dai_zephyr_config_prepare(), channel = %d", channel); /* do nothing for asking for channel free, for compatibility. */ if (channel == DMA_CHAN_INVALID) { @@ -907,7 +907,7 @@ static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) /* get DMA channel */ channel = dma_request_channel(dd->dma->z_dev, &channel); if (channel < 0) { - comp_err(dev, "dai_config_prepare(): dma_request_channel() failed"); + comp_err(dev, "dai_zephyr_config_prepare(): dma_request_channel() failed"); dd->chan = NULL; return -EIO; } @@ -915,13 +915,13 @@ static int dai_config_prepare(struct dai_data *dd, struct comp_dev *dev) dd->chan = &dd->dma->chan[channel]; dd->chan->dev_data = dd; - comp_dbg(dev, "dai_config_prepare(): new configured dma channel index %d", + comp_dbg(dev, "dai_zephyr_config_prepare(): new configured dma channel index %d", dd->chan->index); return 0; } -static int dai_zephyr_prepare(struct dai_data *dd, struct comp_dev *dev) +int dai_zephyr_prepare(struct dai_data *dd, struct comp_dev *dev) { struct comp_buffer __sparse_cache *buffer_c; int ret; @@ -966,7 +966,7 @@ static int dai_prepare(struct comp_dev *dev) comp_dbg(dev, "dai_prepare()"); - ret = dai_config_prepare(dd, dev); + ret = dai_zephyr_config_prepare(dd, dev); if (ret < 0) return ret; diff --git a/src/include/sof/audio/dai_copier.h b/src/include/sof/audio/dai_copier.h index 5c50263d2..e431d5ce7 100644 --- a/src/include/sof/audio/dai_copier.h +++ b/src/include/sof/audio/dai_copier.h @@ -22,4 +22,7 @@ int dai_zephyr_new(struct dai_data *dd, struct comp_dev *dev, void dai_zephyr_free(struct dai_data *dd); +int dai_zephyr_config_prepare(struct dai_data *dd, struct comp_dev *dev); + +int dai_zephyr_prepare(struct dai_data *dd, struct comp_dev *dev); #endif /* __SOF_LIB_DAI_COPIER_H__ */