ASoC: dapm: support user-defined stop condition in dai_get_connected_widgets
PATCH v2 1/2 ASoC: dapm: support user-defined stop condition in dai_get_connected_widgets
Certain situations may warrant examining DAPM paths only to a certain arbitrary point, as opposed to always following them to the end. For instance, when establishing a connection between a front-end DAI link and a back-end DAI link in a DPCM path, it does not make sense to walk the DAPM graph beyond the first widget associated with a back-end link.
This patch introduces a mechanism which lets a user of dai_get_connected_widgets supply a function which will be called for every node during the graph walk. When invoked, this function can execute arbitrary logic to decide whether the walk, given a DAPM widget and walk direction, should be terminated at that point or continued as normal.
--- include/sound/soc-dapm.h | 5 +++- sound/soc/soc-dapm.c | 68 +++++++++++++++++++++++++++++++++++++--------- sound/soc/soc-pcm.c | 3 +- 3 files changed, 61 insertions(+), 15 deletions(-)
include/sound/soc-dapm.h +4 -1
@@ -357,6 +357,7 @@ struct snd_soc_dapm_context;struct regulator ;struct snd_soc_dapm_widget_list ;struct snd_soc_dapm_update ; +enum snd_soc_dapm_direction ;int dapm_regulator_event (struct snd_soc_dapm_widget *w,struct snd_kcontrol *kcontrol,int event);
@@ -450,7 +451,9 @@ void dapm_mark_endpoints_dirty(struct snd_soc_card *card);/* dapm path query */ int snd_soc_dapm_dai_get_connected_widgets (struct snd_soc_dai *dai,int stream, -struct snd_soc_dapm_widget_list **list); +struct snd_soc_dapm_widget_list **list, +int (*custom_stop_condition)(struct snd_soc_dapm_widget *, +enum snd_soc_dapm_direction ));struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm (struct snd_kcontrol *kcontrol);
sound/soc/soc-dapm.c +55 -13
138 lines not on this page · raw message
sound/soc/soc-pcm.c +2 -1
@@ -1294,7 +1294,8 @@ int dpcm_path_get(struct snd_soc_pcm_runtime *fe,int paths;/* get number of valid DAI paths and their widgets */ - paths =snd_soc_dapm_dai_get_connected_widgets (cpu_dai, stream, list); + paths =snd_soc_dapm_dai_get_connected_widgets (cpu_dai, stream, list, +NULL );dev_dbg (fe->dev,"ASoC: found %d audio %s paths\n" , paths, stream ?"capture" :"playback" );
Signature · 1 line
1.7.10.4
PATCH v2 2/2 ASoC: dpcm: play nice with CODEC<->CODEC links
Currently in situations where a normal CODEC to CODEC link follows a DPCM DAI, an error in the following form will be logged:
ASoC: can't get [playback|capture] BE for <widget name>
ASoC: no BE found for <widget name>
This happens because all widgets in a path containing a DPCM DAI will be passed to dpcm_add_paths, which will try to interpret the CODEC<->CODEC as if it were a DPCM DAI, in turn causing the error.
This patch aims to resolve the described issue by stopping the DPCM graph walk, initiated from dpcm_path_get, at the first widget associated with a DPCM BE.
--- sound/soc/soc-pcm.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
sound/soc/soc-pcm.c +41 -1
@@ -1287,6 +1287,46 @@ static int widget_in_list(struct snd_soc_dapm_widget_list *list,return 0 ; } +static int dpcm_end_walk_at_be (struct snd_soc_dapm_widget *widget, +enum snd_soc_dapm_direction dir) +{ +struct snd_soc_card *card = widget->dapm->card; +struct snd_soc_pcm_runtime *rtd; +int i; + +if (dir ==SND_SOC_DAPM_DIR_OUT ) { +list_for_each_entry (rtd, &card->rtd_list, list) { +if (!rtd->dai_link->no_pcm) +continue ; + +if (rtd->cpu_dai->playback_widget == widget) +return 0 ; + +for (i =0 ; i < rtd->num_codecs; ++i) { +struct snd_soc_dai *dai = rtd->codec_dais[i]; +if (dai->playback_widget == widget) +return 0 ; + } + } + }else {/* SND_SOC_DAPM_DIR_IN */ +list_for_each_entry (rtd, &card->rtd_list, list) { +if (!rtd->dai_link->no_pcm) +continue ; + +if (rtd->cpu_dai->capture_widget == widget) +return 0 ; + +for (i =0 ; i < rtd->num_codecs; ++i) { +struct snd_soc_dai *dai = rtd->codec_dais[i]; +if (dai->capture_widget == widget) +return 0 ; + } + } + } + +return -1 ; +} +int dpcm_path_get (struct snd_soc_pcm_runtime *fe,int stream,struct snd_soc_dapm_widget_list **list) {
@@ -1295,7 +1335,7 @@ int dpcm_path_get(struct snd_soc_pcm_runtime *fe,/* get number of valid DAI paths and their widgets */ paths =snd_soc_dapm_dai_get_connected_widgets (cpu_dai, stream, list, -NULL ); + dpcm_end_walk_at_be);dev_dbg (fe->dev,"ASoC: found %d audio %s paths\n" , paths, stream ?"capture" :"playback" );
Signature · 1 line
1.7.10.4
Mark Brown
maintainerQuoted 6 lines · Piotr Stankiewicz
+ * Optionally, can be supplied with a function acting as a stopping condition.
+ * This function takes the dapm widget currently being examined and the walk
+ * direction as an arguments, and should return an integer, as follows:
+ * - >=0: if the walk is to be stopped (this should indicate the number of
+ * endpoints the widget has),
+ * - <0 : if the walk is to be continued as normal.
This seems really weird and uncomfortable. From the naming I would expect it to be a boolean function and I'm struggling to understand when it would be useful to report multiple endpoints on a widget (edge widgets normally being single objects). The whole counting thing is mainly a combination of debugging and an artefact of the implementation. What's the motivation here?
Quoted 9 lines · Mark Brown
Quoted 6 lines · Piotr Stankiewicz
+ * Optionally, can be supplied with a function acting as a stopping condition.
+ * This function takes the dapm widget currently being examined and the walk
+ * direction as an arguments, and should return an integer, as follows:
+ * - >=0: if the walk is to be stopped (this should indicate the number of
+ * endpoints the widget has),
+ * - <0 : if the walk is to be continued as normal.
Quoted 6 lines
This seems really weird and uncomfortable. From the naming I would expect it to be a boolean function and I'm struggling to understand when it would be useful to report multiple endpoints on a widget (edge widgets normally being single objects). The whole counting thing is mainly a combination of debugging and an artefact of the implementation. What's the motivation here?
I don't have a strong reason for this. My motivation here was - since I am adding support for stopping an arbitrary point, it could be that someone would find a use in stopping the graph walk part-way through, and still reporting the number of endpoints as normal. But, if that's unlikely to be of use, I'm happy to make it a boolean function.
Mark Brown
maintainerQuoted 9 lines · Piotr Stankiewicz
Quoted 6 lines · Mark Brown
This seems really weird and uncomfortable. From the naming I would expect it to be a boolean function and I'm struggling to understand when it would be useful to report multiple endpoints on a widget (edge widgets normally being single objects). The whole counting thing is mainly a combination of debugging and an artefact of the implementation. What's the motivation here?
Quoted 5 lines
I don't have a strong reason for this. My motivation here was - since I am adding support for stopping an arbitrary point, it could be that someone would find a use in stopping the graph walk part-way through, and still reporting the number of endpoints as normal. But, if that's unlikely to be of use, I'm happy to make it a boolean function.
Why would the number of endpoints at the edge of the graph ever be something other than 0 or 1?
Quoted 10 lines · Mark Brown
Quoted 8 lines · Piotr Stankiewicz
Quoted 6 lines · Mark Brown
This seems really weird and uncomfortable. From the naming I would expect it to be a boolean function and I'm struggling to understand when it would be useful to report multiple endpoints on a widget (edge widgets normally being single objects). The whole counting thing is mainly a combination of debugging and an artefact of the implementation. What's the motivation here?
Quoted 8 lines
Quoted 5 lines
I don't have a strong reason for this. My motivation here was - since I am adding support for stopping an arbitrary point, it could be that someone would find a use in stopping the graph walk part-way through, and still reporting the number of endpoints as normal. But, if that's unlikely to be of use, I'm happy to make it a boolean function.
Why would the number of endpoints at the edge of the graph ever be something other than 0 or 1?
Now that I think about it, indeed it does not make sense. I'll respin my pathes with custom_stop_condition returning a bool.