Skip to contentSkip to conversation

ASoC: core - Add direct mapping between DAIs and DAPM

PATCH In review Liam Girdwood 3 participants 8 messages Feb 15, 2012 – Feb 17, 2012

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 2/2 ASoC: core - Add support for direct DAI -> widget mapping stream events.

In reply to Liam Girdwood

Currently a DAPM stream event is strstr() matched on the DAI stream name and the card widget names. This has some performance and naming scope limitations for larger and more modern sound cards.

This patch adds the capability to perform a stream event based upon the new DAI widget pointers if they exist and modifies snd_soc_dapm_stream_event() by removing the stream name and adding the stream direction and power widgets parameters.

void snd_soc_dapm_rtd_stream_event(struct snd_soc_pcm_runtime *rtd,

	int stream, int event, int power_widgets);

The stream event now checks whether the RTD DAIs have widget pointers and if so will perfiorm a stream event using the widget pointers. If no widget pointer is found then it reverts to the existing stream event logic to guarantee correct operation for existing drivers.

The "power widgets" parameter will only walk the DAPM graph and power the widgets when true. This allows the dynamic PCM core to coalesce several stream events togother.

---
 include/sound/soc-dapm.h |    4 +-
 sound/soc/soc-core.c     |   22 +++-----
 sound/soc/soc-dapm.c     |  133 +++++++++++++++++++++++++++++++++++++++++----
 sound/soc/soc-pcm.c      |   25 ++++-----
 4 files changed, 141 insertions(+), 43 deletions(-)
include/sound/soc-dapm.h +2 -2
index db8435a..21b3b06 100644
@@ -367,8 +367,8 @@ int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
 			     const struct snd_soc_dapm_route *route, int num);
 
 /* dapm events */
-int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
-	const char *stream, int event);
+void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
+	int event, int power);
 void snd_soc_dapm_shutdown(struct snd_soc_card *card);
 
 /* external DAPM widget events */
sound/soc/soc-core.c +8 -14
index 733f5de..1423a01 100644
@@ -575,18 +575,15 @@ int snd_soc_suspend(struct device *dev)
 	}
 
 	for (i = 0; i < card->num_rtd; i++) {
-		struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
 
 		if (card->rtd[i].dai_link->ignore_suspend)
 			continue;
 
-		if (driver->playback.stream_name != NULL)
-			snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
-				SND_SOC_DAPM_STREAM_SUSPEND);
+		snd_soc_dapm_stream_event(&card->rtd[i], SNDRV_PCM_STREAM_PLAYBACK,
+				SND_SOC_DAPM_STREAM_SUSPEND, 0);
 
-		if (driver->capture.stream_name != NULL)
-			snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
-				SND_SOC_DAPM_STREAM_SUSPEND);
+		snd_soc_dapm_stream_event(&card->rtd[i], SNDRV_PCM_STREAM_CAPTURE,
+				SND_SOC_DAPM_STREAM_SUSPEND, 1);
 	}
 
 	/* suspend all CODECs */
@@ -689,18 +686,15 @@ static void soc_resume_deferred(struct work_struct *work)
 	}
 
 	for (i = 0; i < card->num_rtd; i++) {
-		struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
 
 		if (card->rtd[i].dai_link->ignore_suspend)
 			continue;
 
-		if (driver->playback.stream_name != NULL)
-			snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
-				SND_SOC_DAPM_STREAM_RESUME);
+		snd_soc_dapm_stream_event(&card->rtd[i], SNDRV_PCM_STREAM_PLAYBACK,
+				SND_SOC_DAPM_STREAM_RESUME, 0);
 
-		if (driver->capture.stream_name != NULL)
-			snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
-				SND_SOC_DAPM_STREAM_RESUME);
+		snd_soc_dapm_stream_event(&card->rtd[i], SNDRV_PCM_STREAM_CAPTURE,
+				SND_SOC_DAPM_STREAM_RESUME, 1);
 	}
 
 	/* unmute any active DACs */
sound/soc/soc-dapm.c +121 -12

150 lines not on this page · raw message

sound/soc/soc-pcm.c +10 -15
index 15816ec..4cd8eee 100644
@@ -307,9 +307,8 @@ static void close_delayed_work(struct work_struct *work)
 	/* are we waiting on this codec DAI stream */
 	if (codec_dai->pop_wait == 1) {
 		codec_dai->pop_wait = 0;
-		snd_soc_dapm_stream_event(rtd,
-			codec_dai->driver->playback.stream_name,
-			SND_SOC_DAPM_STREAM_STOP);
+		snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
+			SND_SOC_DAPM_STREAM_STOP, 1);
 	}
 
 	mutex_unlock(&rtd->pcm_mutex);
@@ -372,9 +371,8 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 		if (!rtd->pmdown_time || codec->ignore_pmdown_time ||
 		    rtd->dai_link->ignore_pmdown_time) {
 			/* powered down playback stream now */
-			snd_soc_dapm_stream_event(rtd,
-				codec_dai->driver->playback.stream_name,
-				SND_SOC_DAPM_STREAM_STOP);
+			snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
+				SND_SOC_DAPM_STREAM_STOP, 1);
 		} else {
 			/* start delayed pop wq here for playback streams */
 			codec_dai->pop_wait = 1;
@@ -383,9 +381,8 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 		}
 	} else {
 		/* capture streams can be powered down now */
-		snd_soc_dapm_stream_event(rtd,
-			codec_dai->driver->capture.stream_name,
-			SND_SOC_DAPM_STREAM_STOP);
+		snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
+			SND_SOC_DAPM_STREAM_STOP, 1);
 	}
 
 	mutex_unlock(&rtd->pcm_mutex);
@@ -455,13 +452,11 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
 	}
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		snd_soc_dapm_stream_event(rtd,
-					  codec_dai->driver->playback.stream_name,
-					  SND_SOC_DAPM_STREAM_START);
+		snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
+					  SND_SOC_DAPM_STREAM_START, 1);
 	else
-		snd_soc_dapm_stream_event(rtd,
-					  codec_dai->driver->capture.stream_name,
-					  SND_SOC_DAPM_STREAM_START);
+		snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
+					  SND_SOC_DAPM_STREAM_START, 1);
 
 	snd_soc_dai_digital_mute(codec_dai, 0);
 
Signature · 1 line
1.7.5.4
#0 lore raw

PATCH 1/2 ASoC: core - Add direct mapping between DAIs and DAPM

Currently we map DAI streams to DAPM widgets based on a string stream name. This can lead to some limitations when working with lots of DAI links as there is a risk of naming collision with similar stream names.

This patch creates a 1:N mapping between a DAI and it's DAPM widgets. It's still string based, but we now directly reference the widget names with the DAI and bind the DAI to the widget ptrs at initialisation. The binding also tales into consideration the parent codec or platform that the DAI and widget belong to so that we can easily support multiple components with the same widget names.

This patch still works in conjunction with the stream based events, but it is intended to eventually replace the DAI stream name.

e.g. to map twl6040 headset DACs to headset DAI

static const char *headset_widgets[] = {"HSDAC Left", "HSDAC Right"};

static struct snd_soc_dai_driver twl6040_dai[] = {
...

{
	.name = "twl6040-dl1",
	.playback = {
		.stream_name = "Headset Playback",
		.channel_widgets = headset_widgets,
		.channels_min = 1,
		.channels_max = ARRAY_SIZE(headset_widgets),
		.rates = TWL6040_RATES,
		.formats = TWL6040_FORMATS,
	},
	.ops = &twl6040_dai_ops,
},

This patch will allow DAI connection to any widget type as not all DAIs connect directly to DACs or ADCs, some can connect via a mux that can swap channels etc.

This patch is also intended to be the starting point for future DAPM channel mapping support as we now have a direct link between PCMs and DAPM widgets. e.g. In the example above we map channel 0 (left) to "HSDAC Left" and channel 1 (right) to "HSDAC Right".

---
 include/sound/soc-dai.h |   11 ++-
 include/sound/soc.h     |    1 +
 sound/soc/soc-core.c    |   42 +++++++++++++
 sound/soc/soc-dapm.c    |  155 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 205 insertions(+), 4 deletions(-)
include/sound/soc-dai.h +7 -4
index 2413acc..ce5beea 100644
@@ -246,14 +246,17 @@ struct snd_soc_dai {
 	unsigned int rate;
 
 	/* parent platform/codec */
-	union {
-		struct snd_soc_platform *platform;
-		struct snd_soc_codec *codec;
-	};
+	struct snd_soc_platform *platform;
+	struct snd_soc_codec *codec;
 	struct snd_soc_card *card;
 
 	struct list_head list;
 	struct list_head card_list;
+
+	/* runtime widgets */
+	struct snd_soc_dapm_widget **playback_widgets;
+	struct snd_soc_dapm_widget **capture_widgets;
+	bool dapm_bind_complete;
 };
 
 static inline void *snd_soc_dai_get_dma_data(const struct snd_soc_dai *dai,
include/sound/soc.h +1 -0
index 8fa4dca..bace9b8 100644
@@ -507,6 +507,7 @@ struct snd_soc_pcm_stream {
 	unsigned int rates;		/* SNDRV_PCM_RATE_* */
 	unsigned int rate_min;		/* min rate */
 	unsigned int rate_max;		/* max rate */
+	const char **channel_widgets;	/* DAPM channel widget names */
 	unsigned int channels_min;	/* min channels */
 	unsigned int channels_max;	/* max channels */
 	unsigned int sig_bits;		/* number of bits of content */
sound/soc/soc-core.c +42 -0

66 lines not on this page · raw message

sound/soc/soc-dapm.c +155 -0

161 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#2 lore raw
Quoted 11 lines · Liam Girdwood

Currently we map DAI streams to DAPM widgets based on a string stream name. This can lead to some limitations when working with lots of DAI links as there is a risk of naming collision with similar stream names.

This patch creates a 1:N mapping between a DAI and it's DAPM widgets. It's still string based, but we now directly reference the widget names with the DAI and bind the DAI to the widget ptrs at initialisation. The binding also tales into consideration the parent codec or platform that the DAI and widget belong to so that we can easily support multiple components with the same widget names.

Quoted 2 lines

This patch still works in conjunction with the stream based events, but it is intended to eventually replace the DAI stream name.

I was thinking about something close to this myself as part of the CODEC<->CODEC automatic DAPM stuff I keep mentioning. In order to make that work what I was going to do was instead of mapping the widgets directly onto the DAI was to add a DAPM widget that represented the stream and link the DAI to that, probably created automatically from the DAI definition. We'd then have the DAIs sitting in the DAPM graph and it gets much simpler to just connect the playback DAI on one device to the capture device on another (and vice versa).

In terms of the API and end result it's pretty similar to what you've got here except it'd probably end up with the DAI<->widget links specified through the DAPM map. What do you think? I'd rather not churn the API more often than we have to.

#3 lore raw
Quoted 24 lines · Mark Brown
Quoted 11 lines · Liam Girdwood

Currently we map DAI streams to DAPM widgets based on a string stream name. This can lead to some limitations when working with lots of DAI links as there is a risk of naming collision with similar stream names.

This patch creates a 1:N mapping between a DAI and it's DAPM widgets. It's still string based, but we now directly reference the widget names with the DAI and bind the DAI to the widget ptrs at initialisation. The binding also tales into consideration the parent codec or platform that the DAI and widget belong to so that we can easily support multiple components with the same widget names.

Quoted 2 lines

This patch still works in conjunction with the stream based events, but it is intended to eventually replace the DAI stream name.

I was thinking about something close to this myself as part of the CODEC<->CODEC automatic DAPM stuff I keep mentioning. In order to make that work what I was going to do was instead of mapping the widgets directly onto the DAI was to add a DAPM widget that represented the stream and link the DAI to that, probably created automatically from the DAI definition. We'd then have the DAIs sitting in the DAPM graph and it gets much simpler to just connect the playback DAI on one device to the capture device on another (and vice versa).

Quoted 4 lines

In terms of the API and end result it's pretty similar to what you've got here except it'd probably end up with the DAI<->widget links specified through the DAPM map. What do you think? I'd rather not churn the API more often than we have to.

I'm easy enough, but I'm not sure how we could map specific PCM channels via the DAPM graph. e.g. we could connect the L and R DAC widgets to the DAI widget but how would we associate the L DAC widget with PCM channel 0 etc.

I do have a subsequent patch that does this based on the mapping atm :-

@@ -1405,6 +1405,17 @@ static int soc_init_card_dai_widgets(struct snd_soc_card *card)
return ret;
}

+ /* create unique channels masks for each DAI in the sound card */
+ dai->playback_channel_map =
+ ((1 << dai->driver->playback.channels_max) - 1)
+ << card->num_playback_channels;
+ card->num_playback_channels += dai->driver->playback.channels_max;
+
+ dai->capture_channel_map =
+ ((1 << dai->driver->capture.channels_max) - 1)
+ << card->num_capture_channels;
+ card->num_capture_channels += dai->driver->capture.channels_max;
+
dai->dapm_bind_complete = 1;
}

To give us a unique channel ID for each PCM channel propagating through each widget (since I can map PCM channels atm).

I did connect the DAIs together in the mach driver via DAPM, but I agree it would be nicer connect the DAI widgets together here rather than DACs, etc.

The dynamic PCM patch is also blocking on having some sort of DAI -> widget mapping so we would need something upstream soonish.

I'll take a quick look and see if I can modify this and try and include a DAI widget too whilst retaining the channel mapping before you have breakfast.

Liam

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

I was thinking about something close to this myself as part of the CODEC<->CODEC automatic DAPM stuff I keep mentioning. In order to make that work what I was going to do was instead of mapping the widgets directly onto the DAI was to add a DAPM widget that represented the stream and link the DAI to that, probably created automatically from the DAI definition. We'd then have the DAIs sitting in the DAPM graph and

Quoted 4 lines

I'm easy enough, but I'm not sure how we could map specific PCM channels via the DAPM graph. e.g. we could connect the L and R DAC widgets to the DAI widget but how would we associate the L DAC widget with PCM channel 0 etc.

We actually need to do that anyway for the CODEC<->CODEC links, I've got use cases where there are multiple independant streams going over the same DAI on different channels (eg, stereo pair on 0 and 1, another stereo pair on 2 and 3).

I can see two ways of doing this. One is simply to teach DAPM about these shiny new things like channel numbers in the same way it knows about mixers and muxes. Obviously that's a bit invasive but clearly it'll do the trick. The other is to hang this in using the connected callback on the route, have the callback look at the DAI to see what channels are active and then report if the link is present or not. The infrastructure for that is there in DAPM itself already which is nice.

Quoted 7 lines

To give us a unique channel ID for each PCM channel propagating through each widget (since I can map PCM channels atm).

I did connect the DAIs together in the mach driver via DAPM, but I agree it would be nicer connect the DAI widgets together here rather than DACs, etc.

Quoted 6 lines

The dynamic PCM patch is also blocking on having some sort of DAI -> widget mapping so we would need something upstream soonish.

I'll take a quick look and see if I can modify this and try and include a DAI widget too whilst retaining the channel mapping before you have breakfast.

I *think* can get something working quickly that doesn't fill in the blanks for CODEC-CODEC links, though the conference is looking quite interesting today. I'll try to send something later.

#5 lore raw
Quoted 15 lines · Mark Brown
Quoted 9 lines · Liam Girdwood
Quoted 6 lines · Mark Brown

I was thinking about something close to this myself as part of the CODEC<->CODEC automatic DAPM stuff I keep mentioning. In order to make that work what I was going to do was instead of mapping the widgets directly onto the DAI was to add a DAPM widget that represented the stream and link the DAI to that, probably created automatically from the DAI definition. We'd then have the DAIs sitting in the DAPM graph and

Quoted 4 lines

I'm easy enough, but I'm not sure how we could map specific PCM channels via the DAPM graph. e.g. we could connect the L and R DAC widgets to the DAI widget but how would we associate the L DAC widget with PCM channel 0 etc.

Quoted 4 lines

We actually need to do that anyway for the CODEC<->CODEC links, I've got use cases where there are multiple independant streams going over the same DAI on different channels (eg, stereo pair on 0 and 1, another stereo pair on 2 and 3).

Is this a TDM DAI you are referring to?

Quoted 8 lines

I can see two ways of doing this. One is simply to teach DAPM about these shiny new things like channel numbers in the same way it knows about mixers and muxes. Obviously that's a bit invasive but clearly it'll do the trick. The other is to hang this in using the connected callback on the route, have the callback look at the DAI to see what channels are active and then report if the link is present or not. The infrastructure for that is there in DAPM itself already which is nice.

My +1 for teaching DAPM about channel numbering. Today I have DAI associated with a stream. This DAI can take 4 channels. But DAPM turns ON all 4 channels even if we have mono or stereo being turned on.

Quoted 11 lines
Quoted 10 lines

To give us a unique channel ID for each PCM channel propagating through each widget (since I can map PCM channels atm).

I did connect the DAIs together in the mach driver via DAPM, but I agree it would be nicer connect the DAI widgets together here rather than DACs, etc.

The dynamic PCM patch is also blocking on having some sort of DAI -> widget mapping so we would need something upstream soonish.

Quoted 7 lines
Quoted 3 lines

I'll take a quick look and see if I can modify this and try and include a DAI widget too whilst retaining the channel mapping before you have breakfast.

I *think* can get something working quickly that doesn't fill in the blanks for CODEC-CODEC links, though the conference is looking quite interesting today. I'll try to send something later.

On conference, when are we planing our next ASoC conference?

Signature · 1 line
~Vinod
#6 lore raw
Quoted 8 lines · Vinod Koul
Quoted 4 lines · Mark Brown

We actually need to do that anyway for the CODEC<->CODEC links, I've got use cases where there are multiple independant streams going over the same DAI on different channels (eg, stereo pair on 0 and 1, another stereo pair on 2 and 3).

Is this a TDM DAI you are referring to?

They can be, they can also be grouped together to make multi-channel links. It's entirely flexible to software on the devices I'm thinking of.

Quoted 5 lines
Quoted 3 lines

I *think* can get something working quickly that doesn't fill in the blanks for CODEC-CODEC links, though the conference is looking quite interesting today. I'll try to send something later.

On conference, when are we planing our next ASoC conference?

Not at present. It would probably have been colocated with ELC but that didn't happen.

#7 lore raw
Quoted 11 lines · Mark Brown
Quoted 7 lines · Vinod Koul
Quoted 3 lines · Mark Brown

I *think* can get something working quickly that doesn't fill in the blanks for CODEC-CODEC links, though the conference is looking quite interesting today. I'll try to send something later.

On conference, when are we planing our next ASoC conference?

Not at present. It would probably have been colocated with ELC but that didn't happen.

Sadly I didn't have enough time to set this up for ELC but I should have more time after Dynamic PCM is upstream. I've had some discussions with the Linux Foundation and they are happy to co-locate. Lets discuss when you get back in the UK.

Liam