All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: make snd_soc_dai_link more symmetrical
@ 2013-12-12 17:59 ` Jean-Francois Moine
  0 siblings, 0 replies; 6+ messages in thread
From: Jean-Francois Moine @ 2013-12-12 17:59 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

This patch renders optional the CODEC name / OF node on sound card register,
as it is done for the CPU side, in the case the CODEC DAI name is unique.

This simplifies the definition of CODECs with multiple DAIs, especially
in DTs, while keeping compatibility.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 include/sound/soc.h  |  6 ++++--
 sound/soc/soc-core.c | 73 ++++++++++++++++++++++++++++++++++++++++----------------------
 2 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 1f741cb..67c382e 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -852,8 +852,10 @@ struct snd_soc_dai_link {
 	 */
 	const char *cpu_dai_name;
 	/*
-	 * You MUST specify the link's codec, either by device name, or by
-	 * DT/OF node, but not both.
+	 * You MAY specify the link's codec, either by device name, or by
+	 * DT/OF node, but not both. If this information is omitted,
+	 * the CODEC DAI is matched using .codec_dai_name only, which hence
+	 * must be globally unique.
 	 */
 	const char *codec_name;
 	const struct device_node *codec_of_node;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4e53d87..11b729c 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -883,28 +883,54 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 		return -EPROBE_DEFER;
 	}
 
-	/* Find CODEC from registered CODECs */
-	list_for_each_entry(codec, &codec_list, list) {
-		if (dai_link->codec_of_node) {
-			if (codec->dev->of_node != dai_link->codec_of_node)
-				continue;
-		} else {
-			if (strcmp(codec->name, dai_link->codec_name))
-				continue;
+	if (dai_link->codec_of_node || dai_link->codec_name) {
+
+		/* Find CODEC from registered CODECs */
+		list_for_each_entry(codec, &codec_list, list) {
+			if (dai_link->codec_of_node) {
+				if (codec->dev->of_node != dai_link->codec_of_node)
+					continue;
+			} else {
+				if (strcmp(codec->name, dai_link->codec_name))
+					continue;
+			}
+
+			rtd->codec = codec;
+
+			/*
+			 * CODEC found, so find CODEC DAI from registered DAIs from
+			 * this CODEC
+			 */
+			list_for_each_entry(codec_dai, &dai_list, list) {
+				if (codec->dev == codec_dai->dev &&
+					!strcmp(codec_dai->name,
+						dai_link->codec_dai_name)) {
+
+					rtd->codec_dai = codec_dai;
+				}
+			}
+
+			if (!rtd->codec_dai) {
+				dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+					dai_link->codec_dai_name);
+				return -EPROBE_DEFER;
+			}
 		}
 
-		rtd->codec = codec;
+		if (!rtd->codec) {
+			dev_err(card->dev, "ASoC: CODEC %s not registered\n",
+				dai_link->codec_name);
+			return -EPROBE_DEFER;
+		}
+	} else {
 
-		/*
-		 * CODEC found, so find CODEC DAI from registered DAIs from
-		 * this CODEC
-		 */
+		/* find CODEC DAI from registered DAIs */
 		list_for_each_entry(codec_dai, &dai_list, list) {
-			if (codec->dev == codec_dai->dev &&
-				!strcmp(codec_dai->name,
+			if (!strcmp(codec_dai->name,
 					dai_link->codec_dai_name)) {
-
 				rtd->codec_dai = codec_dai;
+				rtd->codec = codec_dai->codec;
+				break;
 			}
 		}
 
@@ -915,12 +941,6 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 		}
 	}
 
-	if (!rtd->codec) {
-		dev_err(card->dev, "ASoC: CODEC %s not registered\n",
-			dai_link->codec_name);
-		return -EPROBE_DEFER;
-	}
-
 	/* if there's no platform we match on the empty platform */
 	platform_name = dai_link->platform_name;
 	if (!platform_name && !dai_link->platform_of_node)
@@ -3710,12 +3730,13 @@ int snd_soc_register_card(struct snd_soc_card *card)
 		struct snd_soc_dai_link *link = &card->dai_link[i];
 
 		/*
-		 * Codec must be specified by 1 of name or OF node,
-		 * not both or neither.
+		 * Codec may be specified by either name or OF node,
+		 * but can be left unspecified
+		 * and will be matched based on CODEC DAI name alone.
 		 */
-		if (!!link->codec_name == !!link->codec_of_node) {
+		if (link->codec_name && link->codec_of_node) {
 			dev_err(card->dev,
-				"ASoC: Neither/both codec name/of_node are set for %s\n",
+				"ASoC: Both codec name/of_node are set for %s\n",
 				link->name);
 			return -EINVAL;
 		}


-- 
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] ASoC: make snd_soc_dai_link more symmetrical
@ 2013-12-12 17:59 ` Jean-Francois Moine
  0 siblings, 0 replies; 6+ messages in thread
From: Jean-Francois Moine @ 2013-12-12 17:59 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown; +Cc: Takashi Iwai, alsa-devel, linux-kernel

This patch renders optional the CODEC name / OF node on sound card register,
as it is done for the CPU side, in the case the CODEC DAI name is unique.

This simplifies the definition of CODECs with multiple DAIs, especially
in DTs, while keeping compatibility.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 include/sound/soc.h  |  6 ++++--
 sound/soc/soc-core.c | 73 ++++++++++++++++++++++++++++++++++++++++----------------------
 2 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 1f741cb..67c382e 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -852,8 +852,10 @@ struct snd_soc_dai_link {
 	 */
 	const char *cpu_dai_name;
 	/*
-	 * You MUST specify the link's codec, either by device name, or by
-	 * DT/OF node, but not both.
+	 * You MAY specify the link's codec, either by device name, or by
+	 * DT/OF node, but not both. If this information is omitted,
+	 * the CODEC DAI is matched using .codec_dai_name only, which hence
+	 * must be globally unique.
 	 */
 	const char *codec_name;
 	const struct device_node *codec_of_node;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4e53d87..11b729c 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -883,28 +883,54 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 		return -EPROBE_DEFER;
 	}
 
-	/* Find CODEC from registered CODECs */
-	list_for_each_entry(codec, &codec_list, list) {
-		if (dai_link->codec_of_node) {
-			if (codec->dev->of_node != dai_link->codec_of_node)
-				continue;
-		} else {
-			if (strcmp(codec->name, dai_link->codec_name))
-				continue;
+	if (dai_link->codec_of_node || dai_link->codec_name) {
+
+		/* Find CODEC from registered CODECs */
+		list_for_each_entry(codec, &codec_list, list) {
+			if (dai_link->codec_of_node) {
+				if (codec->dev->of_node != dai_link->codec_of_node)
+					continue;
+			} else {
+				if (strcmp(codec->name, dai_link->codec_name))
+					continue;
+			}
+
+			rtd->codec = codec;
+
+			/*
+			 * CODEC found, so find CODEC DAI from registered DAIs from
+			 * this CODEC
+			 */
+			list_for_each_entry(codec_dai, &dai_list, list) {
+				if (codec->dev == codec_dai->dev &&
+					!strcmp(codec_dai->name,
+						dai_link->codec_dai_name)) {
+
+					rtd->codec_dai = codec_dai;
+				}
+			}
+
+			if (!rtd->codec_dai) {
+				dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+					dai_link->codec_dai_name);
+				return -EPROBE_DEFER;
+			}
 		}
 
-		rtd->codec = codec;
+		if (!rtd->codec) {
+			dev_err(card->dev, "ASoC: CODEC %s not registered\n",
+				dai_link->codec_name);
+			return -EPROBE_DEFER;
+		}
+	} else {
 
-		/*
-		 * CODEC found, so find CODEC DAI from registered DAIs from
-		 * this CODEC
-		 */
+		/* find CODEC DAI from registered DAIs */
 		list_for_each_entry(codec_dai, &dai_list, list) {
-			if (codec->dev == codec_dai->dev &&
-				!strcmp(codec_dai->name,
+			if (!strcmp(codec_dai->name,
 					dai_link->codec_dai_name)) {
-
 				rtd->codec_dai = codec_dai;
+				rtd->codec = codec_dai->codec;
+				break;
 			}
 		}
 
@@ -915,12 +941,6 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 		}
 	}
 
-	if (!rtd->codec) {
-		dev_err(card->dev, "ASoC: CODEC %s not registered\n",
-			dai_link->codec_name);
-		return -EPROBE_DEFER;
-	}
-
 	/* if there's no platform we match on the empty platform */
 	platform_name = dai_link->platform_name;
 	if (!platform_name && !dai_link->platform_of_node)
@@ -3710,12 +3730,13 @@ int snd_soc_register_card(struct snd_soc_card *card)
 		struct snd_soc_dai_link *link = &card->dai_link[i];
 
 		/*
-		 * Codec must be specified by 1 of name or OF node,
-		 * not both or neither.
+		 * Codec may be specified by either name or OF node,
+		 * but can be left unspecified
+		 * and will be matched based on CODEC DAI name alone.
 		 */
-		if (!!link->codec_name == !!link->codec_of_node) {
+		if (link->codec_name && link->codec_of_node) {
 			dev_err(card->dev,
-				"ASoC: Neither/both codec name/of_node are set for %s\n",
+				"ASoC: Both codec name/of_node are set for %s\n",
 				link->name);
 			return -EINVAL;
 		}


-- 
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ASoC: make snd_soc_dai_link more symmetrical
  2013-12-12 17:59 ` Jean-Francois Moine
  (?)
@ 2013-12-31 16:55 ` Mark Brown
  2013-12-31 17:44   ` Jean-Francois Moine
  -1 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2013-12-31 16:55 UTC (permalink / raw)
  To: Jean-Francois Moine
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1073 bytes --]

On Thu, Dec 12, 2013 at 06:59:17PM +0100, Jean-Francois Moine wrote:

> This patch renders optional the CODEC name / OF node on sound card register,
> as it is done for the CPU side, in the case the CODEC DAI name is unique.

> This simplifies the definition of CODECs with multiple DAIs, especially
> in DTs, while keeping compatibility.

So, this is similar to one of the comments I made on the DT patch you
sent today: you're saying that this makes things better but you're not
saying why it makes things better.  I've been sitting on this partly
because I've been wanting to sit down and try to work out what the
benefit is.  This information should be readily avaiable and omiting it
seems like it will make things more fragile.

If anything I'd expect DT to want to move towards specifying things by
CODEC plus optional DAI index rather than anything else, that's the more
common pattern for DT based things (really phandle plus index) and it's
what the current generic card is doing.

It's possible there is a benefit I'm just not seeing but you'll need to
tell me.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ASoC: make snd_soc_dai_link more symmetrical
  2013-12-31 16:55 ` Mark Brown
@ 2013-12-31 17:44   ` Jean-Francois Moine
  2014-01-01 12:59       ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Jean-Francois Moine @ 2013-12-31 17:44 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

On Tue, 31 Dec 2013 16:55:33 +0000
Mark Brown <broonie@kernel.org> wrote:

> On Thu, Dec 12, 2013 at 06:59:17PM +0100, Jean-Francois Moine wrote:
> 
> > This patch renders optional the CODEC name / OF node on sound card register,
> > as it is done for the CPU side, in the case the CODEC DAI name is unique.
> 
> > This simplifies the definition of CODECs with multiple DAIs, especially
> > in DTs, while keeping compatibility.
> 
> So, this is similar to one of the comments I made on the DT patch you
> sent today: you're saying that this makes things better but you're not
> saying why it makes things better.  I've been sitting on this partly
> because I've been wanting to sit down and try to work out what the
> benefit is.  This information should be readily avaiable and omiting it
> seems like it will make things more fragile.
> 
> If anything I'd expect DT to want to move towards specifying things by
> CODEC plus optional DAI index rather than anything else, that's the more
> common pattern for DT based things (really phandle plus index) and it's
> what the current generic card is doing.
> 
> It's possible there is a benefit I'm just not seeing but you'll need to
> tell me.

The first benefit I got was in the front-end definition: the codec side
is the dummy codec, and this one has no phandle.

Then, finding the CODEC DAI from phandle asks for more code
(of_xlate_dai_name in the CODEC drivers) and finding it from the CODEC
name asks for a double loop in soc_bind_dai_link. On the other way, a
simple loop without any more change may be used when the DAI is simply
specified by its name. I would say that the DAI name is more meaningful
than a DAI index and that it is less subject to internal changes of the
CODEC driver.

Eventually, I don't think that, using only the name of the CODEC side
DAI to identify it, is not more fragile than identifying the CPU side
of the DAI link by its name.

-- 
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ASoC: make snd_soc_dai_link more symmetrical
  2013-12-31 17:44   ` Jean-Francois Moine
@ 2014-01-01 12:59       ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2014-01-01 12:59 UTC (permalink / raw)
  To: Jean-Francois Moine
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1793 bytes --]

On Tue, Dec 31, 2013 at 06:44:30PM +0100, Jean-Francois Moine wrote:
> Mark Brown <broonie@kernel.org> wrote:

> > It's possible there is a benefit I'm just not seeing but you'll need to
> > tell me.

> The first benefit I got was in the front-end definition: the codec side
> is the dummy codec, and this one has no phandle.

That's a sign that you're putting Linux implementation details into your
DT - remember, DT is supposed to be implementation neutral.

> Then, finding the CODEC DAI from phandle asks for more code
> (of_xlate_dai_name in the CODEC drivers) and finding it from the CODEC

They should be able to use a default there; I'd expect that just to be
making the IDs the same as the index into the array or the ID field.

> name asks for a double loop in soc_bind_dai_link. On the other way, a
> simple loop without any more change may be used when the DAI is simply
> specified by its name. I would say that the DAI name is more meaningful

Then as soon as anything else starts using the same name for some reason
the binding stops being useful.

> than a DAI index and that it is less subject to internal changes of the
> CODEC driver.

Obviously the numbers that get assigned become a part of the ABI and
can't be changed.  Now that we have preprocessor support for DT the
plain text can be done with that, though for a lot of devices that won't
be needed as the devices are just numbered anyway.

> Eventually, I don't think that, using only the name of the CODEC side
> DAI to identify it, is not more fragile than identifying the CPU side
> of the DAI link by its name.

This doesn't mean it's a good idea to do it - as you will remember I
said I expected things to want to go more towards using phandle plus ID 
for everything.  

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ASoC: make snd_soc_dai_link more symmetrical
@ 2014-01-01 12:59       ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2014-01-01 12:59 UTC (permalink / raw)
  To: Jean-Francois Moine; +Cc: Takashi Iwai, linux-kernel, alsa-devel, Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 1793 bytes --]

On Tue, Dec 31, 2013 at 06:44:30PM +0100, Jean-Francois Moine wrote:
> Mark Brown <broonie@kernel.org> wrote:

> > It's possible there is a benefit I'm just not seeing but you'll need to
> > tell me.

> The first benefit I got was in the front-end definition: the codec side
> is the dummy codec, and this one has no phandle.

That's a sign that you're putting Linux implementation details into your
DT - remember, DT is supposed to be implementation neutral.

> Then, finding the CODEC DAI from phandle asks for more code
> (of_xlate_dai_name in the CODEC drivers) and finding it from the CODEC

They should be able to use a default there; I'd expect that just to be
making the IDs the same as the index into the array or the ID field.

> name asks for a double loop in soc_bind_dai_link. On the other way, a
> simple loop without any more change may be used when the DAI is simply
> specified by its name. I would say that the DAI name is more meaningful

Then as soon as anything else starts using the same name for some reason
the binding stops being useful.

> than a DAI index and that it is less subject to internal changes of the
> CODEC driver.

Obviously the numbers that get assigned become a part of the ABI and
can't be changed.  Now that we have preprocessor support for DT the
plain text can be done with that, though for a lot of devices that won't
be needed as the devices are just numbered anyway.

> Eventually, I don't think that, using only the name of the CODEC side
> DAI to identify it, is not more fragile than identifying the CPU side
> of the DAI link by its name.

This doesn't mean it's a good idea to do it - as you will remember I
said I expected things to want to go more towards using phandle plus ID 
for everything.  

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-01-01 13:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-12 17:59 [PATCH] ASoC: make snd_soc_dai_link more symmetrical Jean-Francois Moine
2013-12-12 17:59 ` Jean-Francois Moine
2013-12-31 16:55 ` Mark Brown
2013-12-31 17:44   ` Jean-Francois Moine
2014-01-01 12:59     ` Mark Brown
2014-01-01 12:59       ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.