From 6d06701649e970470355e3a90bb9e5a5112aadd3 Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Fri, 21 Dec 2018 12:57:39 +0800 Subject: [PATCH 1/2] ASoC: SOF: refine the algorithm of dai config setting Add direction check in sof_set_dai_config because dai config is different between playback and capture on HDA platform now, so dai config would be saved by name and direction. Signed-off-by: Rander Wang --- sound/soc/sof/topology.c | 55 +++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 79bf2b255c9bc9..184b3aaab72951 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -1920,7 +1920,8 @@ static void sof_dai_set_format(struct snd_soc_tplg_hw_config *hw_config, /* set config for all DAI's with name matching the link name */ static int sof_set_dai_config(struct snd_sof_dev *sdev, u32 size, struct snd_soc_dai_link *link, - struct sof_ipc_dai_config *config) + struct sof_ipc_dai_config *config, + int direction) { struct snd_sof_dai *dai; @@ -1928,7 +1929,8 @@ static int sof_set_dai_config(struct snd_sof_dev *sdev, u32 size, if (!dai->name) continue; - if (strcmp(link->name, dai->name) == 0) { + if (strcmp(link->name, dai->name) == 0 && + dai->comp_dai.direction == direction) { dai->dai_config = kmemdup(config, size, GFP_KERNEL); if (!dai->dai_config) return -ENOMEM; @@ -1993,11 +1995,23 @@ static int sof_link_ssp_load(struct snd_soc_component *scomp, int index, return ret; } - /* set config for all DAI's with name matching the link name */ - ret = sof_set_dai_config(sdev, size, link, config); - if (ret < 0) - dev_err(sdev->dev, "error: failed to save DAI config for SSP%d\n", - config->dai_index); + /* set config to dai component of playback */ + if (link->dpcm_playback) { + ret = sof_set_dai_config(sdev, size, link, config, + SNDRV_PCM_STREAM_PLAYBACK); + if (ret < 0) + dev_err(sdev->dev, "error: failed to save DAI config in dai component of playback for SSP%d\n", + config->dai_index); + } + + /* set config to dai component of capture */ + if (link->dpcm_capture) { + ret = sof_set_dai_config(sdev, size, link, config, + SNDRV_PCM_STREAM_CAPTURE); + if (ret < 0) + dev_err(sdev->dev, "error: failed to save DAI config in dai component of capture for SSP%d\n", + config->dai_index); + } return ret; } @@ -2113,8 +2127,9 @@ static int sof_link_dmic_load(struct snd_soc_component *scomp, int index, goto err; } - /* set config for all DAI's with name matching the link name */ - ret = sof_set_dai_config(sdev, size, link, ipc_config); + /* set config to dai component of capture */ + ret = sof_set_dai_config(sdev, size, link, ipc_config, + SNDRV_PCM_STREAM_CAPTURE); if (ret < 0) dev_err(sdev->dev, "error: failed to save DAI config for DMIC%d\n", config->dai_index); @@ -2237,6 +2252,14 @@ static int sof_link_hda_load(struct snd_soc_component *scomp, int index, return ret; } + + /* set config to dai component of playback */ + ret = sof_set_dai_config(sdev, size, link, config, + SNDRV_PCM_STREAM_PLAYBACK); + if (ret < 0) { + dev_err(sdev->dev, "error: failed to save DAI config for playback HDA%d\n", + config->dai_index); + } } if (link->dpcm_capture) { @@ -2248,18 +2271,14 @@ static int sof_link_hda_load(struct snd_soc_component *scomp, int index, return ret; } - } - /* set config for all DAI's with name matching the link name */ - ret = sof_set_dai_config(sdev, size, link, config); - if (ret < 0) { - if (link->dpcm_playback) - dev_err(sdev->dev, "error: failed to save DAI config for playback HDA%d\n", - config->dai_index); - - if (link->dpcm_capture) + /* set config to dai component of capture */ + ret = sof_set_dai_config(sdev, size, link, config, + SNDRV_PCM_STREAM_CAPTURE); + if (ret < 0) { dev_err(sdev->dev, "error: failed to save DAI config for capture HDA%d\n", config->dai_index); + } } return ret; From 356a0ea93b066742a275bbc8882dc999b84863e5 Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Thu, 20 Dec 2018 16:44:14 +0800 Subject: [PATCH 2/2] ASoC: SOF: PM: refine algorithm of dai link restoring Dai link is restored by each dai component. This is wrong because there maybe two dai components, playback and capture, or one (playback or capture) in one dai link, so a dai link may be restored two times, but only one dai link is needed. Now restore dai link from index 0 to max index, each dai link is restored only one time Signed-off-by: Rander Wang Signed-off-by: Zhu Yingjiang Signed-off-by: Ranjani Sridharan --- sound/soc/sof/pm.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/sound/soc/sof/pm.c b/sound/soc/sof/pm.c index 64833396a50d98..e10985fa766d8e 100644 --- a/sound/soc/sof/pm.c +++ b/sound/soc/sof/pm.c @@ -62,11 +62,14 @@ static int sof_restore_pipelines(struct snd_sof_dev *sdev) struct snd_sof_dai *dai; struct sof_ipc_comp_dai *comp_dai; struct sof_ipc_cmd_hdr *hdr; + int max_index = 0; + int link_index = 0; int ret = 0; /* restore pipeline components */ list_for_each_entry_reverse(swidget, &sdev->widget_list, list) { struct sof_ipc_comp_reply r; + struct sof_ipc_dai_config *config; /* skip if there is no private data */ if (!swidget->private) @@ -82,6 +85,11 @@ static int sof_restore_pipelines(struct snd_sof_dev *sdev) comp_dai->comp.hdr.cmd, comp_dai, sizeof(*comp_dai), &r, sizeof(r)); + + config = dai->dai_config; + if (config->dai_index > max_index) + max_index = config->dai_index; + break; case snd_soc_dapm_scheduler: @@ -138,23 +146,32 @@ static int sof_restore_pipelines(struct snd_sof_dev *sdev) } } - /* restore dai links */ - list_for_each_entry_reverse(dai, &sdev->dai_list, list) { - struct sof_ipc_reply reply; - struct sof_ipc_dai_config *config = dai->dai_config; + /* restore dai links from index 0 to max index */ + while (link_index <= max_index) { + list_for_each_entry_reverse(dai, &sdev->dai_list, list) { + struct sof_ipc_reply reply; + struct sof_ipc_dai_config *config = dai->dai_config; - ret = sof_ipc_tx_message(sdev->ipc, - config->hdr.cmd, config, - config->hdr.size, - &reply, sizeof(reply)); + if (config->dai_index == link_index) { + ret = sof_ipc_tx_message(sdev->ipc, + config->hdr.cmd, + config, + config->hdr.size, + &reply, sizeof(reply)); - if (ret < 0) { - dev_err(sdev->dev, - "error: failed to set dai config for %s\n", - dai->name); + if (ret < 0) { + dev_err(sdev->dev, + "error: failed to set dai config for %s\n", + dai->name); - return ret; + return ret; + } + + break; + } } + + link_index++; } /* complete pipeline */