dai-zephyr: Prioritize HW params channels over base config params

When the hardware is able to return a valid number of DMA buffer audio
channels (e.g., extracted from a blob), give the returned number
of channels higher precedence over the number supplied via the base config
params.

Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com>
This commit is contained in:
Serhiy Katsyuba 2024-06-14 18:55:34 +02:00 committed by Kai Vehmanen
parent 8082006042
commit eda6029736
1 changed files with 24 additions and 4 deletions

View File

@ -794,7 +794,8 @@ static int dai_set_dma_config(struct dai_data *dd, struct comp_dev *dev)
}
static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
struct sof_ipc_stream_params *params, uint32_t *pb, uint32_t *pc)
const struct sof_ipc_stream_params *params,
uint32_t *pb, uint32_t *pc)
{
struct sof_ipc_stream_params hw_params = *params;
uint32_t frame_size;
@ -916,8 +917,10 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
}
int dai_common_params(struct dai_data *dd, struct comp_dev *dev,
struct sof_ipc_stream_params *params)
struct sof_ipc_stream_params *base_cfg_params)
{
struct sof_ipc_stream_params params = *base_cfg_params;
struct sof_ipc_stream_params hw_params;
struct dma_sg_config *config = &dd->config;
uint32_t period_bytes = 0;
uint32_t period_count = 0;
@ -932,13 +935,30 @@ int dai_common_params(struct dai_data *dd, struct comp_dev *dev,
return err;
}
err = dai_verify_params(dd, dev, params);
/* When the hardware is able to return a valid number of DMA buffer audio channels
* (e.g., extracted from a blob), give the returned number of channels higher precedence
* over the number supplied via the base config params.
*/
memset(&hw_params, 0, sizeof(hw_params));
err = dai_common_get_hw_params(dd, dev, &hw_params, params.direction);
if (err < 0) {
comp_err(dev, "dai_common_get_hw_params() failed: %d", err);
return err;
}
if (hw_params.channels != 0 && hw_params.channels != params.channels) {
params.channels = hw_params.channels;
comp_info(dev, "Replacing %d base config channels with %d hw params channels.",
base_cfg_params->channels, params.channels);
}
err = dai_verify_params(dd, dev, &params);
if (err < 0) {
comp_err(dev, "dai_zephyr_params(): pcm params verification failed.");
return -EINVAL;
}
err = dai_set_dma_buffer(dd, dev, params, &period_bytes, &period_count);
err = dai_set_dma_buffer(dd, dev, &params, &period_bytes, &period_count);
if (err < 0) {
comp_err(dev, "dai_zephyr_params(): alloc dma buffer failed.");
goto out;