From 72af409f3347a624f5266f6d5393360c57814fa0 Mon Sep 17 00:00:00 2001 From: Dragos Tarcatu Date: Thu, 28 Mar 2019 10:26:35 +0200 Subject: [PATCH] ASoC: SOF: topology: use the default hw_config in DAI link init If multiple hw_configs are provided in the topology, look for the default one instead of loading the first one found. Signed-off-by: Dragos Tarcatu --- sound/soc/sof/topology.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 07243a3af4c685..f4c01a5af18f6c 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -2514,7 +2514,9 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_soc_tplg_private *private = &cfg->priv; struct sof_ipc_dai_config config; struct snd_soc_tplg_hw_config *hw_config; + int num_hw_configs; int ret = 0; + int i = 0; link->platform_name = dev_name(sdev->dev); @@ -2552,15 +2554,31 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, * DAI links are expected to have at least 1 hw_config. * But some older topologies might have no hw_config for HDA dai links. */ - if (!le32_to_cpu(cfg->num_hw_configs) && - config.type != SOF_DAI_INTEL_HDA) { - dev_err(sdev->dev, "error: unexpected DAI config count %d!\n", - le32_to_cpu(cfg->num_hw_configs)); - return -EINVAL; + num_hw_configs = le32_to_cpu(cfg->num_hw_configs); + if (!num_hw_configs) { + if (config.type != SOF_DAI_INTEL_HDA) { + dev_err(sdev->dev, "error: unexpected DAI config count %d!\n", + le32_to_cpu(cfg->num_hw_configs)); + return -EINVAL; + } + } else { + dev_dbg(sdev->dev, "tplg: %d hw_configs found, default id: %d!\n", + cfg->num_hw_configs, le32_to_cpu(cfg->default_hw_config_id)); + + for (i = 0; i < num_hw_configs; i++) { + if (cfg->hw_config[i].id == cfg->default_hw_config_id) + break; + } + + if (i == num_hw_configs) { + dev_err(sdev->dev, "error: default hw_config id: %d not found!\n", + le32_to_cpu(cfg->default_hw_config_id)); + return -EINVAL; + } } /* configure dai IPC message */ - hw_config = &cfg->hw_config[0]; + hw_config = &cfg->hw_config[i]; config.hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG; config.format = le32_to_cpu(hw_config->fmt);