Skip to content

Commit 6742064

Browse files
Piotr Stankiewiczbroonie
authored andcommitted
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. Signed-off-by: Piotr Stankiewicz <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 1a695a9 commit 6742064

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

include/sound/soc-dapm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ struct snd_soc_dapm_context;
358358
struct regulator;
359359
struct snd_soc_dapm_widget_list;
360360
struct snd_soc_dapm_update;
361+
enum snd_soc_dapm_direction;
361362

362363
int dapm_regulator_event(struct snd_soc_dapm_widget *w,
363364
struct snd_kcontrol *kcontrol, int event);
@@ -451,7 +452,9 @@ void dapm_mark_endpoints_dirty(struct snd_soc_card *card);
451452

452453
/* dapm path query */
453454
int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
454-
struct snd_soc_dapm_widget_list **list);
455+
struct snd_soc_dapm_widget_list **list,
456+
bool (*custom_stop_condition)(struct snd_soc_dapm_widget *,
457+
enum snd_soc_dapm_direction));
455458

456459
struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm(
457460
struct snd_kcontrol *kcontrol);

sound/soc/soc-dapm.c

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,11 @@ static int dapm_widget_list_create(struct snd_soc_dapm_widget_list **list,
10731073
*/
10741074
static __always_inline int is_connected_ep(struct snd_soc_dapm_widget *widget,
10751075
struct list_head *list, enum snd_soc_dapm_direction dir,
1076-
int (*fn)(struct snd_soc_dapm_widget *, struct list_head *))
1076+
int (*fn)(struct snd_soc_dapm_widget *, struct list_head *,
1077+
bool (*custom_stop_condition)(struct snd_soc_dapm_widget *,
1078+
enum snd_soc_dapm_direction)),
1079+
bool (*custom_stop_condition)(struct snd_soc_dapm_widget *,
1080+
enum snd_soc_dapm_direction))
10771081
{
10781082
enum snd_soc_dapm_direction rdir = SND_SOC_DAPM_DIR_REVERSE(dir);
10791083
struct snd_soc_dapm_path *path;
@@ -1088,6 +1092,9 @@ static __always_inline int is_connected_ep(struct snd_soc_dapm_widget *widget,
10881092
if (list)
10891093
list_add_tail(&widget->work_list, list);
10901094

1095+
if (custom_stop_condition && custom_stop_condition(widget, dir))
1096+
return con;
1097+
10911098
if ((widget->is_ep & SND_SOC_DAPM_DIR_TO_EP(dir)) && widget->connected) {
10921099
widget->endpoints[dir] = snd_soc_dapm_suspend_check(widget);
10931100
return widget->endpoints[dir];
@@ -1106,7 +1113,7 @@ static __always_inline int is_connected_ep(struct snd_soc_dapm_widget *widget,
11061113

11071114
if (path->connect) {
11081115
path->walking = 1;
1109-
con += fn(path->node[dir], list);
1116+
con += fn(path->node[dir], list, custom_stop_condition);
11101117
path->walking = 0;
11111118
}
11121119
}
@@ -1119,39 +1126,62 @@ static __always_inline int is_connected_ep(struct snd_soc_dapm_widget *widget,
11191126
/*
11201127
* Recursively check for a completed path to an active or physically connected
11211128
* output widget. Returns number of complete paths.
1129+
*
1130+
* Optionally, can be supplied with a function acting as a stopping condition.
1131+
* This function takes the dapm widget currently being examined and the walk
1132+
* direction as an arguments, it should return true if the walk should be
1133+
* stopped and false otherwise.
11221134
*/
11231135
static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
1124-
struct list_head *list)
1136+
struct list_head *list,
1137+
bool (*custom_stop_condition)(struct snd_soc_dapm_widget *i,
1138+
enum snd_soc_dapm_direction))
11251139
{
11261140
return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_OUT,
1127-
is_connected_output_ep);
1141+
is_connected_output_ep, custom_stop_condition);
11281142
}
11291143

11301144
/*
11311145
* Recursively check for a completed path to an active or physically connected
11321146
* input widget. Returns number of complete paths.
1147+
*
1148+
* Optionally, can be supplied with a function acting as a stopping condition.
1149+
* This function takes the dapm widget currently being examined and the walk
1150+
* direction as an arguments, it should return true if the walk should be
1151+
* stopped and false otherwise.
11331152
*/
11341153
static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
1135-
struct list_head *list)
1154+
struct list_head *list,
1155+
bool (*custom_stop_condition)(struct snd_soc_dapm_widget *i,
1156+
enum snd_soc_dapm_direction))
11361157
{
11371158
return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_IN,
1138-
is_connected_input_ep);
1159+
is_connected_input_ep, custom_stop_condition);
11391160
}
11401161

11411162
/**
11421163
* snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
11431164
* @dai: the soc DAI.
11441165
* @stream: stream direction.
11451166
* @list: list of active widgets for this stream.
1167+
* @custom_stop_condition: (optional) a function meant to stop the widget graph
1168+
* walk based on custom logic.
11461169
*
11471170
* Queries DAPM graph as to whether an valid audio stream path exists for
11481171
* the initial stream specified by name. This takes into account
11491172
* current mixer and mux kcontrol settings. Creates list of valid widgets.
11501173
*
1174+
* Optionally, can be supplied with a function acting as a stopping condition.
1175+
* This function takes the dapm widget currently being examined and the walk
1176+
* direction as an arguments, it should return true if the walk should be
1177+
* stopped and false otherwise.
1178+
*
11511179
* Returns the number of valid paths or negative error.
11521180
*/
11531181
int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
1154-
struct snd_soc_dapm_widget_list **list)
1182+
struct snd_soc_dapm_widget_list **list,
1183+
bool (*custom_stop_condition)(struct snd_soc_dapm_widget *,
1184+
enum snd_soc_dapm_direction))
11551185
{
11561186
struct snd_soc_card *card = dai->component->card;
11571187
struct snd_soc_dapm_widget *w;
@@ -1171,9 +1201,11 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
11711201
}
11721202

11731203
if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1174-
paths = is_connected_output_ep(dai->playback_widget, &widgets);
1204+
paths = is_connected_output_ep(dai->playback_widget, &widgets,
1205+
custom_stop_condition);
11751206
else
1176-
paths = is_connected_input_ep(dai->capture_widget, &widgets);
1207+
paths = is_connected_input_ep(dai->capture_widget, &widgets,
1208+
custom_stop_condition);
11771209

11781210
/* Drop starting point */
11791211
list_del(widgets.next);
@@ -1268,8 +1300,8 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
12681300

12691301
DAPM_UPDATE_STAT(w, power_checks);
12701302

1271-
in = is_connected_input_ep(w, NULL);
1272-
out = is_connected_output_ep(w, NULL);
1303+
in = is_connected_input_ep(w, NULL, NULL);
1304+
out = is_connected_output_ep(w, NULL, NULL);
12731305
return out != 0 && in != 0;
12741306
}
12751307

@@ -1928,8 +1960,8 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
19281960
in = 0;
19291961
out = 0;
19301962
} else {
1931-
in = is_connected_input_ep(w, NULL);
1932-
out = is_connected_output_ep(w, NULL);
1963+
in = is_connected_input_ep(w, NULL, NULL);
1964+
out = is_connected_output_ep(w, NULL, NULL);
19331965
}
19341966

19351967
ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",

sound/soc/soc-pcm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@ int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
12941294
int paths;
12951295

12961296
/* get number of valid DAI paths and their widgets */
1297-
paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list);
1297+
paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list,
1298+
NULL);
12981299

12991300
dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
13001301
stream ? "capture" : "playback");

0 commit comments

Comments
 (0)