Skip to contentSkip to conversation

ASoC: dapm - Add API calls to query valid DAPM paths.

PATCH Superseded Liam Girdwood 2 participants 5 messages Jul 6, 2011 – Jul 11, 2011

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: dapm - Add API calls to query valid DAPM paths.

In preparation for ASoC Dynamic PCM (AKA DSP) support.

Add DAPM API calls to determine whether a DAPM audio path is valid between source and sink widgets and return a lits of active widgets in that path. This also takes into account all kcontrol mux and mixer settings in between the source and sink widgets to validate the audio path.

This will be used by the DSP core to determine the runtime DAI mappings between FE and BE DAIs in order to run PCM operations.

---
 include/sound/soc-dapm.h |   14 ++
 sound/soc/soc-dapm.c     |  371 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 376 insertions(+), 9 deletions(-)
include/sound/soc-dapm.h +14 -0
index e09505c..5a7dae6 100644
@@ -310,6 +310,7 @@ struct snd_soc_dapm_path;
 struct snd_soc_dapm_pin;
 struct snd_soc_dapm_route;
 struct snd_soc_dapm_context;
+struct snd_soc_dapm_widget_list;
 
 int dapm_reg_event(struct snd_soc_dapm_widget *w,
 		   struct snd_kcontrol *kcontrol, int event);
@@ -375,6 +376,13 @@ int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
 				const char *pin);
 
+/* dapm path query */
+int snd_soc_dapm_get_connected_widgets_type(struct snd_soc_dapm_context *dapm,
+		const char *stream_name, struct snd_soc_dapm_widget_list **list,
+		int stream, enum snd_soc_dapm_type type);
+int snd_soc_dapm_get_connected_widgets_name(struct snd_soc_dapm_context *dapm,
+		const char *name, struct snd_soc_dapm_widget_list **list, int stream);
+
 /* dapm widget types */
 enum snd_soc_dapm_type {
 	snd_soc_dapm_input = 0,		/* input pin */
@@ -432,6 +440,8 @@ struct snd_soc_dapm_path {
 	u32 connect:1;	/* source and sink widgets are connected */
 	u32 walked:1;	/* path has been walked */
 	u32 weak:1;	/* path ignored for power management */
+	u32 length:6;	/* path length - used by route checker */
+
 
 	int (*connected)(struct snd_soc_dapm_widget *source,
 			 struct snd_soc_dapm_widget *sink);
@@ -456,6 +466,8 @@ struct snd_soc_dapm_widget {
 	unsigned char shift;			/* bits to shift */
 	unsigned int saved_value;		/* widget saved value */
 	unsigned int value;				/* widget current value */
+	unsigned int path_idx;
+	unsigned int hops;
 	unsigned int mask;			/* non-shifted mask */
 	unsigned int on_val;			/* on state value */
 	unsigned int off_val;			/* off state value */
@@ -518,6 +530,8 @@ struct snd_soc_dapm_context {
 	enum snd_soc_bias_level target_bias_level;
 	struct list_head list;
 
+	int num_valid_paths; /* valid paths for route checker */
+
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs_dapm;
 #endif
sound/soc/soc-dapm.c +362 -9

389 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 4 lines · Liam Girdwood

Add DAPM API calls to determine whether a DAPM audio path is valid between source and sink widgets and return a lits of active widgets in that path. This also takes into account all kcontrol mux and mixer settings in between the source and sink widgets to validate the audio path.

Hrm, I'm not entirely sure about this. My overall feeling is that it feels complicated and I'm not comfortable that it's doing something different to the rest of DAPM that doesn't normally get used. It doesn't seem like the tree walk we're doing here should be different enough to the walk we do for the normal power check to require a completely separate implementation and having the two checks feels like it's going to cause issues later on. I may be missing something but shouldn't we be able to replace the current list walk with a walk which uses this sort of interface on each relevant widget it finds?

There's already some drift with things like the callbacks for dynamic routes not being implemented...

It does also occur to me that perhaps what we want to do here is allow widgets to find out about paths when they're being activated anyway? That'd also be useful for things like DVFS charge pumps, sometimes they can easily be controlled with a fake widget but not always if there's complicated digital routing within the device.

include/sound/soc-dapm.h struct snd_soc_dapm_path { · line 444

Quoted 6 lines
include/sound/soc-dapm.h +2 -0
@@ -432,6 +440,8 @@ struct snd_soc_dapm_path {
 	u32 connect:1;	/* source and sink widgets are connected */
 	u32 walked:1;	/* path has been walked */
 	u32 weak:1;	/* path ignored for power management */
+	u32 length:6;	/* path length - used by route checker */
+

The :6 seems very odd here.

sound/soc/soc-dapm.c line 52

Quoted 9 lines

index 0a78482..800af10 100644

sound/soc/soc-dapm.c +2 -0
@@ -48,6 +48,8 @@
 
 #include <trace/events/asoc.h>
 
+#define DAPM_MAX_HOPS 16
+

This seems too low, if we need a limit I'd expect it to be an order of magnitude higher. I'm not sure we should need a limit, though.

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 230

Quoted 4 lines
sound/soc/soc-dapm.c +4 -0
+/* add widget to list if it's not already in the list */
+static int dapm_add_unique_widget(struct snd_soc_dapm_context *dapm,
+	struct snd_soc_dapm_widget_list **list,
+	struct snd_soc_dapm_widget *w)

Just make this plain old add_widget()? I can't see us ever wanting a non-unique version, and it's going to have fun with the standard list implementation if we do. Perhaps also shove a list in the name.

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 244

Quoted 10 lines
sound/soc/soc-dapm.c +10 -0
+	/* is the list empty ? */
+	if (*list == NULL) {
+
+		wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
+				sizeof(struct snd_soc_dapm_widget *);
+		*list = kzalloc(wlistsize, GFP_KERNEL);
+		if (*list == NULL) {
+			dev_err(dapm->dev, "can't allocate widget list for %s\n",
+				w->name);
+			return -ENOMEM;

It seems really odd to be allocating here rather than in the caller.

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 263

Quoted 6 lines
sound/soc/soc-dapm.c +6 -0
+		*list = krealloc(wlist, wlistsize, GFP_KERNEL);
+		if (*list == NULL) {
+			dev_err(dapm->dev, "can't allocate widget list for %s\n",
+				w->name);
+			return -ENOMEM;
+		}

This will leak the pointer to the list when it fails.

Quoted 8 lines
sound/soc/soc-dapm.c +8 -0
+/* is widget an output endpoint */
+static int is_output_widget_ep(struct snd_soc_dapm_widget *widget)
+{
+	switch (widget->id) {
+	case snd_soc_dapm_adc:
+	case snd_soc_dapm_aif_out:
+		return 1;
+	case snd_soc_dapm_output:

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 292

Quoted 10 lines
sound/soc/soc-dapm.c +10 -0
+		if (widget->connected && !widget->ext)
+			return 1;
+		else
+			return 0;
+	case snd_soc_dapm_hp:
+	case snd_soc_dapm_spk:
+	case snd_soc_dapm_line:
+		return !list_empty(&widget->sources);
+	default:
+		return 0;

With both this and the input version we're duplicating sort of the logic that's in is_connected_foo_ep. I'd feel much happier if we factored the shared logic out of those functions rather than duplicating it, as it is I'm worried the two could drift apart over time.

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 309

Quoted 2 lines
sound/soc/soc-dapm.c +2 -0
+	case snd_soc_dapm_mic:
+		return !list_empty(&widget->sources);

That doesn't seem right?

Quoted 11 lines

+/**
+ * snd_soc_dapm_get_connected_widgets_type - query audio path and it's widgets.
+ * @dapm: the dapm context.
+ * @stream_name: stream name.
+ * @list: list of active widgets for this stream.
+ * @stream: stream direction.
+ * @type: Initial widget type.
+ *
+ * Queries DAPM graph as to whether an valid audio stream path exists for
+ * the DAPM stream and initial widget type specified. This takes into account
+ * current mixer and mux kcontrol settings. Creates list of valid widgets.

Why would someone want to query by type? That seems surprising. Name and/or direction yes but type seems hard to find a use for.

#2 lore raw
Quoted 17 lines · Mark Brown
Quoted 4 lines · Liam Girdwood

Add DAPM API calls to determine whether a DAPM audio path is valid between source and sink widgets and return a lits of active widgets in that path. This also takes into account all kcontrol mux and mixer settings in between the source and sink widgets to validate the audio path.

Hrm, I'm not entirely sure about this. My overall feeling is that it feels complicated and I'm not comfortable that it's doing something different to the rest of DAPM that doesn't normally get used. It doesn't seem like the tree walk we're doing here should be different enough to the walk we do for the normal power check to require a completely separate implementation and having the two checks feels like it's going to cause issues later on. I may be missing something but shouldn't we be able to replace the current list walk with a walk which uses this sort of interface on each relevant widget it finds?

Quoted 3 lines

There's already some drift with things like the callbacks for dynamic routes not being implemented...

The reason for using a separate walk here was because this code is taken from my old auto-router and it was to avoid the extra logic introduced by the auto-router. The auto-router did need to check for loops and always select the shortest path when > 1 path was viable (interesting as WM9713 has both loops and multiple paths). Let me see how cleanly I can merge it into the current walk.

Quoted 2 lines

It does also occur to me that perhaps what we want to do here is allow widgets to find out about paths when they're being activated anyway?

For dynamic PCM, we need to also work out which DAIs are active based on the graph. Hence for playback we can supply the DAC/AIF and find out all the connected output AIF/Speakers/Pins/etc. This is required at the start of open() in order that we can call the other PCM ops for each DAI, codec and platform.

Quoted 4 lines

That'd also be useful for things like DVFS charge pumps, sometimes they can easily be controlled with a fake widget but not always if there's complicated digital routing within the device.

Yeah, this can also be used to figure out the paths when widgets are activated too. I can export the API calls in order for components to make use of this information when their widgets are activated.

Quoted 8 lines

include/sound/soc-dapm.h struct snd_soc_dapm_path { · line 444

Quoted 6 lines
include/sound/soc-dapm.h +2 -0
@@ -432,6 +440,8 @@ struct snd_soc_dapm_path {
 	u32 connect:1;	/* source and sink widgets are connected */
 	u32 walked:1;	/* path has been walked */
 	u32 weak:1;	/* path ignored for power management */
+	u32 length:6;	/* path length - used by route checker */
+

The :6 seems very odd here.

Yeah, this came from auto-router when I think we cared about squeezing this all into a u32.

Quoted 6 lines
Quoted 6 lines

index 0a78482..800af10 100644

sound/soc/soc-dapm.c +0 -0
@@ -48,6 +48,8 @@
 
Quoted 7 lines

sound/soc/soc-dapm.c line 52

Quoted 4 lines
sound/soc/soc-dapm.c +2 -0
 #include <trace/events/asoc.h>
 
+#define DAPM_MAX_HOPS 16
+

This seems too low, if we need a limit I'd expect it to be an order of magnitude higher. I'm not sure we should need a limit, though.

Agreed, I will remove it.

Quoted 9 lines

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 230

Quoted 5 lines
sound/soc/soc-dapm.c +4 -0
+/* add widget to list if it's not already in the list */
+static int dapm_add_unique_widget(struct snd_soc_dapm_context *dapm,
+	struct snd_soc_dapm_widget_list **list,
+	struct snd_soc_dapm_widget *w)

Just make this plain old add_widget()? I can't see us ever wanting a non-unique version, and it's going to have fun with the standard list implementation if we do. Perhaps also shove a list in the name.

Yeah, that does sound better.

Quoted 64 lines

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 244

Quoted 11 lines
sound/soc/soc-dapm.c +10 -0
+	/* is the list empty ? */
+	if (*list == NULL) {
+
+		wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
+				sizeof(struct snd_soc_dapm_widget *);
+		*list = kzalloc(wlistsize, GFP_KERNEL);
+		if (*list == NULL) {
+			dev_err(dapm->dev, "can't allocate widget list for %s\n",
+				w->name);
+			return -ENOMEM;

It seems really odd to be allocating here rather than in the caller.

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 263

Quoted 6 lines
sound/soc/soc-dapm.c +6 -0
+		*list = krealloc(wlist, wlistsize, GFP_KERNEL);
+		if (*list == NULL) {
+			dev_err(dapm->dev, "can't allocate widget list for %s\n",
+				w->name);
+			return -ENOMEM;
+		}

This will leak the pointer to the list when it fails.

Quoted 8 lines
sound/soc/soc-dapm.c +8 -0
+/* is widget an output endpoint */
+static int is_output_widget_ep(struct snd_soc_dapm_widget *widget)
+{
+	switch (widget->id) {
+	case snd_soc_dapm_adc:
+	case snd_soc_dapm_aif_out:
+		return 1;
+	case snd_soc_dapm_output:

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 292

Quoted 10 lines
sound/soc/soc-dapm.c +10 -0
+		if (widget->connected && !widget->ext)
+			return 1;
+		else
+			return 0;
+	case snd_soc_dapm_hp:
+	case snd_soc_dapm_spk:
+	case snd_soc_dapm_line:
+		return !list_empty(&widget->sources);
+	default:
+		return 0;

With both this and the input version we're duplicating sort of the logic that's in is_connected_foo_ep. I'd feel much happier if we factored the shared logic out of those functions rather than duplicating it, as it is I'm worried the two could drift apart over time.

sound/soc/soc-dapm.c static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, · line 309

Quoted 2 lines
sound/soc/soc-dapm.c +2 -0
+	case snd_soc_dapm_mic:
+		return !list_empty(&widget->sources);

That doesn't seem right?

Quoted 11 lines

+/**
+ * snd_soc_dapm_get_connected_widgets_type - query audio path and it's widgets.
+ * @dapm: the dapm context.
+ * @stream_name: stream name.
+ * @list: list of active widgets for this stream.
+ * @stream: stream direction.
+ * @type: Initial widget type.
+ *
+ * Queries DAPM graph as to whether an valid audio stream path exists for
+ * the DAPM stream and initial widget type specified. This takes into account
+ * current mixer and mux kcontrol settings. Creates list of valid widgets.

Quoted 2 lines

Why would someone want to query by type? That seems surprising. Name and/or direction yes but type seems hard to find a use for.

We query by type so that we can qualify the root widget for a shared common stream name. i.e. Dynamic DSP needs to find the AIF rather than a DAC for stream X.

Liam

#3 lore raw

On Thu, Jul 07, 2011 at 05:18:47PM +0100, Liam Girdwood wrote:

[Please fix your mailer to word wrap within paragraphs, I've reflowed all your text.]

Quoted 6 lines

The reason for using a separate walk here was because this code is taken from my old auto-router and it was to avoid the extra logic introduced by the auto-router. The auto-router did need to check for loops and always select the shortest path when > 1 path was viable (interesting as WM9713 has both loops and multiple paths). Let me see how cleanly I can merge it into the current walk.

Alternatively could we replace the current walk? It's O(n^2) or so in the number of widgets so it's not the greatest treasure ever. So long as we only have one walk and it works I'm happy.

Quoted 8 lines
Quoted 2 lines

It does also occur to me that perhaps what we want to do here is allow widgets to find out about paths when they're being activated anyway?

For dynamic PCM, we need to also work out which DAIs are active based on the graph. Hence for playback we can supply the DAC/AIF and find out all the connected output AIF/Speakers/Pins/etc. This is required at the start of open() in order that we can call the other PCM ops for each DAI, codec and platform.

Right, that's not really what I'm saying though - I'm saying that widgets in general could be interested in this information. For example, some charge pumps can save additional power with some input signal paths (which is currently handled but this would make that code more general).

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

+ * snd_soc_dapm_get_connected_widgets_type - query audio path and it's widgets.
+ * @dapm: the dapm context.
+ * @stream_name: stream name.
+ * @list: list of active widgets for this stream.
+ * @stream: stream direction.
+ * @type: Initial widget type.
+ *
+ * Queries DAPM graph as to whether an valid audio stream path exists for
+ * the DAPM stream and initial widget type specified. This takes into account
+ * current mixer and mux kcontrol settings. Creates list of valid widgets.

Quoted 6 lines
Quoted 2 lines

Why would someone want to query by type? That seems surprising. Name and/or direction yes but type seems hard to find a use for.

We query by type so that we can qualify the root widget for a shared common stream name. i.e. Dynamic DSP needs to find the AIF rather than a DAC for stream X.

It does? Hrm. Perhaps it would make life simpler if we just mandated the use of explicit AIF widgets?

#4 lore raw
Quoted 22 lines · Mark Brown
Quoted 6 lines · Liam Girdwood

The reason for using a separate walk here was because this code is taken from my old auto-router and it was to avoid the extra logic introduced by the auto-router. The auto-router did need to check for loops and always select the shortest path when > 1 path was viable (interesting as WM9713 has both loops and multiple paths). Let me see how cleanly I can merge it into the current walk.

Alternatively could we replace the current walk? It's O(n^2) or so in the number of widgets so it's not the greatest treasure ever. So long as we only have one walk and it works I'm happy.

Quoted 8 lines
Quoted 2 lines

It does also occur to me that perhaps what we want to do here is allow widgets to find out about paths when they're being activated anyway?

For dynamic PCM, we need to also work out which DAIs are active based on the graph. Hence for playback we can supply the DAC/AIF and find out all the connected output AIF/Speakers/Pins/etc. This is required at the start of open() in order that we can call the other PCM ops for each DAI, codec and platform.

Quoted 5 lines

Right, that's not really what I'm saying though - I'm saying that widgets in general could be interested in this information. For example, some charge pumps can save additional power with some input signal paths (which is currently handled but this would make that code more general).

Ok, but I'm not stopping this sort of functionality from being added later. Right now this is not a priority (for me anyway).

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines

+ * snd_soc_dapm_get_connected_widgets_type - query audio path and it's widgets.
+ * @dapm: the dapm context.
+ * @stream_name: stream name.
+ * @list: list of active widgets for this stream.
+ * @stream: stream direction.
+ * @type: Initial widget type.
+ *
+ * Queries DAPM graph as to whether an valid audio stream path exists for
+ * the DAPM stream and initial widget type specified. This takes into account
+ * current mixer and mux kcontrol settings. Creates list of valid widgets.

Why would someone want to query by type? That seems surprising. Name and/or direction yes but type seems hard to find a use for.

Quoted 6 lines
Quoted 3 lines

We query by type so that we can qualify the root widget for a shared common stream name. i.e. Dynamic DSP needs to find the AIF rather than a DAC for stream X.

It does? Hrm. Perhaps it would make life simpler if we just mandated the use of explicit AIF widgets?

But we may also want to know what was after a DAC. I'm thinking back from the conference discussions where we could use this information to selectively enable/disable kcontrols. However, this is not going to be used at the moment either so I'll stick by the AIF widgets.

Liam