Skip to contentSkip to conversation

ASoC: dapm: add code to configure dai link parameters

PATCH Superseded Nikesh Oswal 2 participants 2 messages Sep 12, 2014 – Nov 4, 2014

Subsystems (2)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 ASoC: dapm: add code to configure dai link parameters

dai-link params for codec-codec links were fixed. The fixed link between codec and another chip which may be another codec, baseband, bluetooth codec etc may require run time configuaration changes. This change provides an optional alsa control to select one of the params from a list of params.

---
 include/sound/soc-dapm.h |    3 +
 include/sound/soc.h      |    1 +
 sound/soc/soc-core.c     |    6 +-
 sound/soc/soc-dapm.c     |  143 ++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 146 insertions(+), 7 deletions(-)
include/sound/soc-dapm.h +3 -0
index 6b59471..3ee031e 100644
@@ -378,6 +378,7 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);
 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
 			 const struct snd_soc_pcm_stream *params,
+			 unsigned int num_params,
 			 struct snd_soc_dapm_widget *source,
 			 struct snd_soc_dapm_widget *sink);
 
@@ -531,6 +532,8 @@ struct snd_soc_dapm_widget {
 	void *priv;				/* widget specific data */
 	struct regulator *regulator;		/* attached regulator */
 	const struct snd_soc_pcm_stream *params; /* params for dai links */
+	unsigned int num_params; /* number of params for dai links */
+	unsigned int params_select; /* currently selected param for dai link */
 
 	/* dapm control */
 	int reg;				/* negative reg = no direct dapm */
include/sound/soc.h +1 -0
index ed9e2d7..51c6c4f 100644
@@ -906,6 +906,7 @@ struct snd_soc_dai_link {
 	int be_id;	/* optional ID for machine driver BE identification */
 
 	const struct snd_soc_pcm_stream *params;
+	unsigned int num_params;
 
 	unsigned int dai_fmt;           /* format to set on init */
 
sound/soc/soc-core.c +4 -2
index b87d7d8..1db2168 100644
@@ -1461,7 +1461,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,
 	capture_w = cpu_dai->capture_widget;
 	if (play_w && capture_w) {
 		ret = snd_soc_dapm_new_pcm(card, dai_link->params,
-					   capture_w, play_w);
+					   dai_link->num_params, capture_w,
+					   play_w);
 		if (ret != 0) {
 			dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
 				play_w->name, capture_w->name, ret);
@@ -1473,7 +1474,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,
 	capture_w = codec_dai->capture_widget;
 	if (play_w && capture_w) {
 		ret = snd_soc_dapm_new_pcm(card, dai_link->params,
-					   capture_w, play_w);
+					   dai_link->num_params, capture_w,
+					   play_w);
 		if (ret != 0) {
 			dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
 				play_w->name, capture_w->name, ret);
sound/soc/soc-dapm.c +138 -5

199 lines not on this page · raw message

Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 5 lines · Nikesh Oswal

dai-link params for codec-codec links were fixed. The fixed link between codec and another chip which may be another codec, baseband, bluetooth codec etc may require run time configuaration changes. This change provides an optional alsa control to select one of the params from a list of params.

The shape of this looks OK, though there are some issues below. I intend to test this before applying but couldn't do that since it doesn't apply against current code.

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

Quoted 3 lines
sound/soc/soc-dapm.c +3 -0
+	/* Select the configuration set by alsa control */
+	config += w->params_select;
+

Do an array lookup, code legibility is important.

Quoted 5 lines
sound/soc/soc-dapm.c +5 -0
+static int snd_soc_dapm_dai_link_put(struct snd_kcontrol *kcontrol,
+			  struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
+

sound/soc/soc-dapm.c out: · line 3285

Quoted 10 lines
sound/soc/soc-dapm.c +10 -0
+	if (ucontrol->value.integer.value[0] == w->params_select)
+		return 0;
+
+	if (ucontrol->value.integer.value[0] >= w->num_params)
+		return -EINVAL;
+
+	w->params_select = ucontrol->value.integer.value[0];
+
+	return 0;
+}

This will just silently not immediately do anything if an attempt is made to change the parameters while the link is active. There needs to at least be a log message, and probably it's better to return -EBUSY as well otherwise userspace might be going on reconfiguring things assuming that this succeeded.

It'd be even better to actually reconfigure the link but that's a more involved operation which might need us to power things down and can be punted for now.

sound/soc/soc-dapm.c int snd_soc_dapm_new_pcm(struct snd_soc_card *card, · line 3319

Quoted 8 lines
sound/soc/soc-dapm.c +4 -2
 	len = strlen(source->name) + strlen(sink->name) + 2;
 	link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
-	if (!link_name)
-		return -ENOMEM;
+	if (!link_name) {
+		ret = -ENOMEM;
+		goto  outfree_w_param;
+	}

Random extra space here and in some other gotos.

sound/soc/soc-dapm.c int snd_soc_dapm_new_pcm(struct snd_soc_card *card, · line 3329

Quoted 7 lines
sound/soc/soc-dapm.c +7 -0
+	for (count = 0 ; count < num_params; count++) {
+		if (!config->stream_name)
+			dev_warn(card->dapm.dev,
+				"ASoC: anonymous config %d for dai link %s\n",
+				count, link_name);
+		w_param_text[count] = kmemdup((void *)(config->stream_name),
+			strlen(config->stream_name) + 1, GFP_KERNEL);

Why are you casting to void * here? This looks like it's open coding kstrdup() and we're mixing devm_ and non-devm_ allocations in this function.

This is also dereferencing stream_name immediately after finding that it's NULL which isn't good.

sound/soc/soc-dapm.c int snd_soc_dapm_new_pcm(struct snd_soc_card *card, · line 3351

Quoted 6 lines
sound/soc/soc-dapm.c +6 -0
+	template.num_kcontrols = 1;
+	private_value =
+	(unsigned long) kmemdup((void *)(kcontrol_dai_link[0].private_value),
+		sizeof(struct soc_enum), GFP_KERNEL);
+	if (!private_value) {
+		dev_err(card->dev, "ASoC: Failed to create control for %s widget\n",

So, we need to kmemdup() this thing that we just allocated? If this is needed it should be clear to the reader why we're doing this, especially given all the funky casts.