Skip to content

Commit 2c28eca

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: topology: Add new token for dynamic pipeline
Today, we set up all widgets required for all PCM streams at the time of topology parsing even if they are not used. An optimization would be to only set up the widgets required for currently active PCM streams. This would give the FW the opportunity to power gate unused memory blocks, thereby saving power. For dynamic pipelines, the widgets in the connected DAPM path for each PCM will need to be set up at runtime. This patch introduces a new token, DYNAMIC_PIPELINE, for scheduler type widgets that indicate whether a pipeline should be set up statically during topology load or at runtime when the PCM is opened. Introduce a new field called dynamic_pipeline_widget in struct snd_sof_widget to save the value of the parsed token. The token is set only for the pipeline (scheduler type) widget and must be propagated to all widgets in the same pipeline during topology load. Introduce another field called pipe_widget in struct snd_sof_widget that saves the pointer to the scheduler widget with the same pipeline ID as that of the widget. This field is populated when the pipeline completion callback is invoked during topology loading. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Link: https://lore.kernel.org/r/20210927120517.20505-4-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 199a375 commit 2c28eca

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

include/uapi/sound/sof/tokens.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#define SOF_TKN_SCHED_CORE 203
5252
#define SOF_TKN_SCHED_FRAMES 204
5353
#define SOF_TKN_SCHED_TIME_DOMAIN 205
54+
#define SOF_TKN_SCHED_DYNAMIC_PIPELINE 206
5455

5556
/* volume */
5657
#define SOF_TKN_VOLUME_RAMP_STEP_TYPE 250

sound/soc/sof/sof-audio.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ struct snd_sof_control {
8181
bool comp_data_dirty;
8282
};
8383

84+
struct snd_sof_widget;
85+
8486
/* ASoC SOF DAPM widget */
8587
struct snd_sof_widget {
8688
struct snd_soc_component *scomp;
@@ -90,8 +92,19 @@ struct snd_sof_widget {
9092
int core;
9193
int id;
9294

95+
/*
96+
* Flag indicating if the widget should be set up dynamically when a PCM is opened.
97+
* This flag is only set for the scheduler type widget in topology. During topology
98+
* loading, this flag is propagated to all the widgets belonging to the same pipeline.
99+
* When this flag is not set, a widget is set up at the time of topology loading
100+
* and retained until the DSP enters D3. It will need to be set up again when resuming
101+
* from D3.
102+
*/
103+
bool dynamic_pipeline_widget;
104+
93105
struct snd_soc_dapm_widget *widget;
94106
struct list_head list; /* list in sdev widget list */
107+
struct snd_sof_widget *pipe_widget;
95108

96109
/* extended data for UUID components */
97110
struct sof_ipc_comp_ext comp_ext;

sound/soc/sof/topology.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,12 @@ static const struct sof_topology_token sched_tokens[] = {
572572
offsetof(struct sof_ipc_pipe_new, time_domain), 0},
573573
};
574574

575+
static const struct sof_topology_token pipeline_tokens[] = {
576+
{SOF_TKN_SCHED_DYNAMIC_PIPELINE, SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16,
577+
offsetof(struct snd_sof_widget, dynamic_pipeline_widget), 0},
578+
579+
};
580+
575581
/* volume */
576582
static const struct sof_topology_token volume_tokens[] = {
577583
{SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
@@ -1765,6 +1771,15 @@ static int sof_widget_load_pipeline(struct snd_soc_component *scomp, int index,
17651771
goto err;
17661772
}
17671773

1774+
ret = sof_parse_tokens(scomp, swidget, pipeline_tokens,
1775+
ARRAY_SIZE(pipeline_tokens), private->array,
1776+
le32_to_cpu(private->size));
1777+
if (ret != 0) {
1778+
dev_err(scomp->dev, "error: parse dynamic pipeline token failed %d\n",
1779+
private->size);
1780+
goto err;
1781+
}
1782+
17681783
dev_dbg(scomp->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d\n",
17691784
swidget->widget->name, pipeline->period, pipeline->priority,
17701785
pipeline->period_mips, pipeline->core, pipeline->frames_per_sched);
@@ -3567,11 +3582,45 @@ int snd_sof_complete_pipeline(struct device *dev,
35673582
return 1;
35683583
}
35693584

3585+
/**
3586+
* sof_set_pipe_widget - Set pipe_widget for a component
3587+
* @sdev: pointer to struct snd_sof_dev
3588+
* @pipe_widget: pointer to struct snd_sof_widget of type snd_soc_dapm_scheduler
3589+
* @swidget: pointer to struct snd_sof_widget that has the same pipeline ID as @pipe_widget
3590+
*
3591+
* Return: 0 if successful, -EINVAL on error.
3592+
* The function checks if @swidget is associated with any volatile controls. If so, setting
3593+
* the dynamic_pipeline_widget is disallowed.
3594+
*/
3595+
static int sof_set_pipe_widget(struct snd_sof_dev *sdev, struct snd_sof_widget *pipe_widget,
3596+
struct snd_sof_widget *swidget)
3597+
{
3598+
struct snd_sof_control *scontrol;
3599+
3600+
if (pipe_widget->dynamic_pipeline_widget) {
3601+
/* dynamic widgets cannot have volatile kcontrols */
3602+
list_for_each_entry(scontrol, &sdev->kcontrol_list, list)
3603+
if (scontrol->comp_id == swidget->comp_id &&
3604+
(scontrol->access & SNDRV_CTL_ELEM_ACCESS_VOLATILE)) {
3605+
dev_err(sdev->dev,
3606+
"error: volatile control found for dynamic widget %s\n",
3607+
swidget->widget->name);
3608+
return -EINVAL;
3609+
}
3610+
}
3611+
3612+
/* set the pipe_widget and apply the dynamic_pipeline_widget_flag */
3613+
swidget->pipe_widget = pipe_widget;
3614+
swidget->dynamic_pipeline_widget = pipe_widget->dynamic_pipeline_widget;
3615+
3616+
return 0;
3617+
}
3618+
35703619
/* completion - called at completion of firmware loading */
35713620
static int sof_complete(struct snd_soc_component *scomp)
35723621
{
35733622
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
3574-
struct snd_sof_widget *swidget;
3623+
struct snd_sof_widget *swidget, *comp_swidget;
35753624
int ret;
35763625

35773626
/* some widget types require completion notificattion */
@@ -3586,6 +3635,17 @@ static int sof_complete(struct snd_soc_component *scomp)
35863635
return ret;
35873636

35883637
swidget->complete = ret;
3638+
3639+
/*
3640+
* Apply the dynamic_pipeline_widget flag and set the pipe_widget field
3641+
* for all widgets that have the same pipeline ID as the scheduler widget
3642+
*/
3643+
list_for_each_entry_reverse(comp_swidget, &sdev->widget_list, list)
3644+
if (comp_swidget->pipeline_id == swidget->pipeline_id) {
3645+
ret = sof_set_pipe_widget(sdev, swidget, comp_swidget);
3646+
if (ret < 0)
3647+
return ret;
3648+
}
35893649
break;
35903650
default:
35913651
break;

0 commit comments

Comments
 (0)