summaryrefslogtreecommitdiff
path: root/sound/soc/sof/sof-audio.c
diff options
context:
space:
mode:
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>2022-03-17 20:50:27 +0300
committerMark Brown <broonie@kernel.org>2022-03-18 19:04:35 +0300
commit051744b1bf0b13f63af5de3c296d04ab0cc6117c (patch)
tree7b0e5b3453713d67e2faa2bf12521fc928497ab0 /sound/soc/sof/sof-audio.c
parent40c2c63ac40d26bb0b8e17ada32e84541363f1b0 (diff)
downloadlinux-051744b1bf0b13f63af5de3c296d04ab0cc6117c.tar.xz
ASoC: SOF: Make sof_widget_setup/free IPC agnostic
Add 3 new topology IPC ops for widget_setup, widget_free and dai_config in order to make the pipeline management code IPC agnostic and implement the ops for IPC3. Use the newly introduced tplg dai_config op to configure the DAI during BE DAI hw_params and hw_free. Also, in preparation for IPC4, modify BE hw_params callback to skip setting up the DAI widget. All widgets will be set up during FW hw_params and the DAI_CONFIG IPC should be sent only if the widget use_count is > 0. With setting up/freeing removed from the BE hw_params, remove the configured flag as it is no longer needed. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Link: https://lore.kernel.org/r/20220317175044.1752400-3-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/sof/sof-audio.c')
-rw-r--r--sound/soc/sof/sof-audio.c136
1 files changed, 22 insertions, 114 deletions
diff --git a/sound/soc/sof/sof-audio.c b/sound/soc/sof/sof-audio.c
index cc0d647a2d0d..7aa4ac313de3 100644
--- a/sound/soc/sof/sof-audio.c
+++ b/sound/soc/sof/sof-audio.c
@@ -27,31 +27,6 @@ static int sof_kcontrol_setup(struct snd_sof_dev *sdev, struct snd_sof_control *
return ret;
}
-static int sof_dai_config_setup(struct snd_sof_dev *sdev, struct snd_sof_dai *dai)
-{
- struct sof_dai_private_data *private = dai->private;
- struct sof_ipc_dai_config *config;
- struct sof_ipc_reply reply;
- int ret;
-
- config = &private->dai_config[dai->current_config];
- if (!config) {
- dev_err(sdev->dev, "error: no config for DAI %s\n", dai->name);
- return -EINVAL;
- }
-
- /* set NONE flag to clear all previous settings */
- config->flags = SOF_DAI_CONFIG_FLAGS_NONE;
-
- 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);
-
- return ret;
-}
-
static int sof_widget_kcontrol_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
struct snd_sof_control *scontrol;
@@ -96,15 +71,9 @@ static void sof_reset_route_setup_status(struct snd_sof_dev *sdev, struct snd_so
int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
- struct sof_ipc_free ipc_free = {
- .hdr = {
- .size = sizeof(ipc_free),
- .cmd = SOF_IPC_GLB_TPLG_MSG,
- },
- .id = swidget->comp_id,
- };
- struct sof_ipc_reply reply;
- int ret, err;
+ const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
+ int err = 0;
+ int ret;
if (!swidget->private)
return 0;
@@ -113,33 +82,9 @@ int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
if (--swidget->use_count)
return 0;
- switch (swidget->id) {
- case snd_soc_dapm_scheduler:
- {
- ipc_free.hdr.cmd |= SOF_IPC_TPLG_PIPE_FREE;
- break;
- }
- case snd_soc_dapm_buffer:
- ipc_free.hdr.cmd |= SOF_IPC_TPLG_BUFFER_FREE;
- break;
- case snd_soc_dapm_dai_in:
- case snd_soc_dapm_dai_out:
- {
- struct snd_sof_dai *dai = swidget->private;
-
- dai->configured = false;
- fallthrough;
- }
- default:
- ipc_free.hdr.cmd |= SOF_IPC_TPLG_COMP_FREE;
- break;
- }
-
/* continue to disable core even if IPC fails */
- err = sof_ipc_tx_message(sdev->ipc, ipc_free.hdr.cmd, &ipc_free, sizeof(ipc_free),
- &reply, sizeof(reply));
- if (err < 0)
- dev_err(sdev->dev, "error: failed to free widget %s\n", swidget->widget->name);
+ if (tplg_ops->widget_free)
+ err = tplg_ops->widget_free(sdev, swidget);
/*
* disable widget core. continue to route setup status and complete flag
@@ -176,11 +121,7 @@ EXPORT_SYMBOL(sof_widget_free);
int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
- struct sof_ipc_pipe_new *pipeline;
- struct sof_ipc_comp_reply r;
- struct sof_ipc_cmd_hdr *hdr;
- struct sof_ipc_comp *comp;
- struct snd_sof_dai *dai;
+ const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
int ret;
/* skip if there is no private data */
@@ -219,53 +160,22 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
goto pipe_widget_free;
}
- switch (swidget->id) {
- case snd_soc_dapm_dai_in:
- case snd_soc_dapm_dai_out:
- {
- struct sof_dai_private_data *dai_data;
-
- dai = swidget->private;
- dai_data = dai->private;
- comp = &dai_data->comp_dai->comp;
- dai->configured = false;
-
- ret = sof_ipc_tx_message(sdev->ipc, comp->hdr.cmd, dai_data->comp_dai,
- comp->hdr.size, &r, sizeof(r));
- if (ret < 0) {
- dev_err(sdev->dev, "error: failed to load widget %s\n",
- swidget->widget->name);
+ /* setup widget in the DSP */
+ if (tplg_ops->widget_setup) {
+ ret = tplg_ops->widget_setup(sdev, swidget);
+ if (ret < 0)
goto core_put;
- }
+ }
- ret = sof_dai_config_setup(sdev, dai);
- if (ret < 0) {
- dev_err(sdev->dev, "error: failed to load dai config for DAI %s\n",
- swidget->widget->name);
+ /* send config for DAI components */
+ if (WIDGET_IS_DAI(swidget->id)) {
+ unsigned int flags = SOF_DAI_CONFIG_FLAGS_NONE;
- /*
- * widget use_count and core ref_count will both be decremented by
- * sof_widget_free()
- */
- sof_widget_free(sdev, swidget);
- return ret;
+ if (tplg_ops->dai_config) {
+ ret = tplg_ops->dai_config(sdev, swidget, flags, NULL);
+ if (ret < 0)
+ goto widget_free;
}
- break;
- }
- case snd_soc_dapm_scheduler:
- pipeline = swidget->private;
- ret = sof_ipc_tx_message(sdev->ipc, pipeline->hdr.cmd, pipeline,
- sizeof(*pipeline), &r, sizeof(r));
- break;
- default:
- hdr = swidget->private;
- ret = sof_ipc_tx_message(sdev->ipc, hdr->cmd, swidget->private, hdr->size,
- &r, sizeof(r));
- break;
- }
- if (ret < 0) {
- dev_err(sdev->dev, "error: failed to load widget %s\n", swidget->widget->name);
- goto core_put;
}
/* restore kcontrols for widget */
@@ -273,18 +183,16 @@ int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
if (ret < 0) {
dev_err(sdev->dev, "error: failed to restore kcontrols for widget %s\n",
swidget->widget->name);
- /*
- * widget use_count and core ref_count will both be decremented by
- * sof_widget_free()
- */
- sof_widget_free(sdev, swidget);
- return ret;
+ goto widget_free;
}
dev_dbg(sdev->dev, "widget %s setup complete\n", swidget->widget->name);
return 0;
+widget_free:
+ /* widget use_count and core ref_count will both be decremented by sof_widget_free() */
+ sof_widget_free(sdev, swidget);
core_put:
snd_sof_dsp_core_put(sdev, swidget->core);
pipe_widget_free: