diff mbox

[v2,3/4] ASoC: simple-card: accept many DAI links

Message ID d71a2b62b331302772d35b3cd35c6dc5da1e9e5d.1394533640.git.moinejf@free.fr (mailing list archive)
State New, archived
Headers show

Commit Message

Jean-Francois Moine March 11, 2014, 9:36 a.m. UTC
Some simple audio cards may have many DAI links.
This patch extends the simple-card driver for handling such cards.

Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
---
 sound/soc/generic/simple-card.c | 132 ++++++++++++++++++++++++++--------------
 1 file changed, 85 insertions(+), 47 deletions(-)

Comments

Xiubo Li March 12, 2014, 5:20 a.m. UTC | #1
> Subject: [PATCH v2 3/4] ASoC: simple-card: accept many DAI links
> 
> Some simple audio cards may have many DAI links.
> This patch extends the simple-card driver for handling such cards.
> 
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> ---
>  sound/soc/generic/simple-card.c | 132 ++++++++++++++++++++++++++-------------
> -
>  1 file changed, 85 insertions(+), 47 deletions(-)
> 
> diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
> index 2710b52..8188c34 100644
> --- a/sound/soc/generic/simple-card.c
> +++ b/sound/soc/generic/simple-card.c
> @@ -107,6 +107,9 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
>  	if (ret < 0)
>  		return ret;
> 
> +	if (!dai)
> +		return 0;
> +
>  	/* parse TDM slot */
>  	ret = snd_soc_of_parse_tdm_slot(np, &dai->slots, &dai->slot_width);
>  	if (ret)
> @@ -154,7 +157,7 @@ static int asoc_simple_card_parse_of(struct device_node
> *node,
>  	struct snd_soc_dai_link *dai_link = priv->snd_card.dai_link;
>  	struct device_node *np;
>  	char *name;
> -	int ret;
> +	int first_link, ret;
> 
>  	/* parsing the card name from DT */
>  	snd_soc_of_parse_card_name(&priv->snd_card, "simple-audio-card,name");
> @@ -179,50 +182,67 @@ static int asoc_simple_card_parse_of(struct device_node
> *node,
>  			return ret;
>  	}
> 
> -	/* CPU sub-node */
> -	ret = -EINVAL;
> -	np = of_get_child_by_name(node, "simple-audio-card,cpu");
> -	if (np) {
> +	/* loop on the DAI links */
> +	np = NULL;
> +	first_link = 1;
> +	for (;;) {
> +		np = of_get_next_child(node, np);
> +		if (!np)
> +			break;
> +
> +		/* CPU sub-node */
> +		if (strcmp(np->name, "simple-audio-card,cpu") != 0) {
> +			dev_err(dev, "Bad CPU DAI\n");
> +			ret = -EINVAL;
> +			goto err;
> +		}
>  		ret = asoc_simple_card_sub_parse_of(np, priv->daifmt,
> -						  &priv->cpu_dai,
> +					first_link ? &priv->cpu_dai : NULL,

@Jean-Francois,

I'm not sure why only the first link needs parsing the DAIFMT ?

On my LS1 platform there are two CODECs and two CPU SAI deivces,
SGTL5000 <---> SAI
CS42888  <---> ESAI

Could the many dai links feature support this case? 

I my understanding is correct here, this patch will support the
Board, in which board there maybe only one CODEC supporting many
DAIs...


Thanks,

--
Best Regards,
Xiubo




>  						  &dai_link->cpu_of_node,
>  						  &dai_link->cpu_dai_name);
> -		of_node_put(np);
> -	}
> -	if (ret < 0)
> -		return ret;
> +		if (ret < 0)
> +			goto err;
> 
> -	/* CODEC sub-node */
> -	ret = -EINVAL;
> -	np = of_get_child_by_name(node, "simple-audio-card,codec");
> -	if (np) {
> +		/* CODEC sub-node */
> +		np = of_get_next_child(node, np);
> +		if (strcmp(np->name, "simple-audio-card,codec") != 0) {
> +			dev_err(dev, "Bad CODEC DAI\n");
> +			ret = -EINVAL;
> +			goto err;
> +		}
>  		ret = asoc_simple_card_sub_parse_of(np, priv->daifmt,
> -						  &priv->codec_dai,
> +					first_link ? &priv->codec_dai : NULL,
>  						  &dai_link->codec_of_node,
>  						  &dai_link->codec_dai_name);
> -		of_node_put(np);
> -	}
> -	if (ret < 0)
> -		return ret;
> +		if (ret < 0)
> +			goto err;
> +
> +		if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) {
> +			ret = -EINVAL;
> +			goto err;
> +		}
> 
> -	if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name)
> -		return -EINVAL;
> +		/* simple-card assumes platform == cpu */
> +		dai_link->platform_of_node = dai_link->cpu_of_node;
> +
> +		name = devm_kzalloc(dev,
> +				    strlen(dai_link->cpu_dai_name)   +
> +				    strlen(dai_link->codec_dai_name) + 2,
> +				    GFP_KERNEL);
> +		sprintf(name, "%s-%s", dai_link->cpu_dai_name,
> +					dai_link->codec_dai_name);
> +		dai_link->name = dai_link->stream_name = name;
> +
> +		dai_link++;
> +		first_link = 0;
> +	}
> 
>  	/* card name is created from CPU/CODEC dai name */
> -	name = devm_kzalloc(dev,
> -			    strlen(dai_link->cpu_dai_name)   +
> -			    strlen(dai_link->codec_dai_name) + 2,
> -			    GFP_KERNEL);
> -	sprintf(name, "%s-%s", dai_link->cpu_dai_name,
> -				dai_link->codec_dai_name);
> +	dai_link = priv->snd_card.dai_link;
>  	if (!priv->snd_card.name)
> -		priv->snd_card.name = name;
> -	dai_link->name = dai_link->stream_name = name;
> +		priv->snd_card.name = dai_link->name;
> 
> -	/* simple-card assumes platform == cpu */
> -	dai_link->platform_of_node = dai_link->cpu_of_node;
> -
> -	dev_dbg(dev, "card-name : %s\n", name);
> +	dev_dbg(dev, "card-name : %s\n", priv->snd_card.name);
>  	dev_dbg(dev, "platform : %04x\n", priv->daifmt);
>  	dev_dbg(dev, "cpu : %s / %04x / %d\n",
>  		dai_link->cpu_dai_name,
> @@ -233,18 +253,11 @@ static int asoc_simple_card_parse_of(struct device_node
> *node,
>  		priv->codec_dai.fmt,
>  		priv->codec_dai.sysclk);
> 
> -	/*
> -	 * soc_bind_dai_link() will check cpu name
> -	 * after of_node matching if dai_link has cpu_dai_name.
> -	 * but, it will never match if name was created by fmt_single_name()
> -	 * remove cpu_dai_name to escape name matching.
> -	 * see
> -	 *	fmt_single_name()
> -	 *	fmt_multiple_name()
> -	 */
> -	dai_link->cpu_dai_name = NULL;
> -
>  	return 0;
> +
> +err:
> +	of_node_put(np);
> +	return ret;
>  }
> 
>  /* update the reference count of the devices nodes at end of probe */
> @@ -274,10 +287,22 @@ static int asoc_simple_card_probe(struct platform_device
> *pdev)
>  	struct snd_soc_dai_link *dai_link;
>  	struct device_node *np = pdev->dev.of_node;
>  	struct device *dev = &pdev->dev;
> -	int ret;
> +	int num_links, ret;
> +
> +	/* get the number of DAI links */
> +	if (np) {
> +		num_links = of_get_child_count(np);
> +		if (num_links == 0 || (num_links & 1)) {
> +			dev_err(&pdev->dev, "Bad number of DAI links\n");
> +			return -EINVAL;
> +		}
> +		num_links /= 2;
> +	} else {
> +		num_links = 1;
> +	}
> 
>  	priv = devm_kzalloc(dev,
> -			sizeof(*priv) + sizeof(*dai_link),
> +			sizeof(*priv) + sizeof(*dai_link) * num_links,
>  			GFP_KERNEL);
>  	if (!priv)
>  		return -ENOMEM;
> @@ -289,7 +314,7 @@ static int asoc_simple_card_probe(struct platform_device
> *pdev)
>  	priv->snd_card.dev = dev;
>  	dai_link = priv->dai_link;
>  	priv->snd_card.dai_link = dai_link;
> -	priv->snd_card.num_links = 1;
> +	priv->snd_card.num_links = num_links;
> 
>  	if (np && of_device_is_available(np)) {
> 
> @@ -299,6 +324,19 @@ static int asoc_simple_card_probe(struct platform_device
> *pdev)
>  				dev_err(dev, "parse error %d\n", ret);
>  			goto err;
>  		}
> +
> +		/*
> +		 * soc_bind_dai_link() will check cpu name
> +		 * after of_node matching if dai_link has cpu_dai_name.
> +		 * but, it will never match if name was created by
> fmt_single_name()
> +		 * remove cpu_dai_name to escape name matching.
> +		 * see
> +		 *	fmt_single_name()
> +		 *	fmt_multiple_name()
> +		 */
> +		if (num_links == 1)
> +			dai_link->cpu_dai_name = NULL;
> +
>  	} else {
>  		struct asoc_simple_card_info *cinfo;
> 
> --
> 1.9.0
> 
>
Jyri Sarha March 14, 2014, 11:16 a.m. UTC | #2
On 03/11/2014 11:36 AM, Jean-Francois Moine wrote:
> Some simple audio cards may have many DAI links.
> This patch extends the simple-card driver for handling such cards.
>
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> ---
[...]

Why can't you just use two simple-card instances in your setup?

You need to update the DT-binding document too when you are changing the 
binding. That way it would also be easier to follow what you are trying 
to accomplish here.

The sysclk and tdm properties appear to only work in the dais of the 
first dai-link and __asoc_simple_card_dai_init() will not be called for 
other dais at all. The DT-binding of this implementation would look 
pretty hairy to me.

Best regards,
Jyri
Jean-Francois Moine March 14, 2014, 6:40 p.m. UTC | #3
On Fri, 14 Mar 2014 13:16:12 +0200
Jyri Sarha <jsarha@ti.com> wrote:

> On 03/11/2014 11:36 AM, Jean-Francois Moine wrote:
> > Some simple audio cards may have many DAI links.
> > This patch extends the simple-card driver for handling such cards.
> >
> > Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> > ---
> [...]
> 
> Why can't you just use two simple-card instances in your setup?

My machine has only one audio device (kirkwood). This one has two
outputs. The first one (I2S) is connected to the HDMI transmitter, and
the other one (S/PDIF) is connected to both the HDMI transmitter and the
S/PDIF connector. There can be only one playback stream, either via
I2S, or S/PDIF, or both, with the final output either to HDMI or S/PDIF
or both:

           /--> I2S -----+-> HDMI
platform -+             /
           \-> S/PDIF -+
                        \--> S/PDIF

DPCM permits to activate both I2S and S/PDIF, but it does not handle
the format and rate constraints (both outputs are always activated with
the platform constraints).

So, the actual solution I use is 3 DAI links (= 3 PCMs):
- HDMI via I2S
- HDMI via S/PDIF (no S/PDIF output)
- S/PDIF via S/PDIF (no HDMI output)

> You need to update the DT-binding document too when you are changing the 
> binding. That way it would also be easier to follow what you are trying 
> to accomplish here.

Some people want to have 2 different patchs: one for the code and the
other one for the DT change. Some other people like you want only one
patch. Which is the right way?

> The sysclk and tdm properties appear to only work in the dais of the 
> first dai-link and __asoc_simple_card_dai_init() will not be called for 
> other dais at all. The DT-binding of this implementation would look 
> pretty hairy to me.

I will add an other dynamic structure for these properties.
Jean-Francois Moine March 14, 2014, 6:58 p.m. UTC | #4
On Wed, 12 Mar 2014 05:20:17 +0000
"Li.Xiubo@freescale.com" <Li.Xiubo@freescale.com> wrote:

> I'm not sure why only the first link needs parsing the DAIFMT ?

In my machine, there is only one audio device and the CODECs don't need
any format, sysclk or TDM slot.

But, as Jyri asked it too, I will add these properties.

> On my LS1 platform there are two CODECs and two CPU SAI deivces,
> SGTL5000 <---> SAI
> CS42888  <---> ESAI
> 
> Could the many dai links feature support this case? 

As Jyri said: why not two simple-cards?

> I my understanding is correct here, this patch will support the
> Board, in which board there maybe only one CODEC supporting many
> DAIs...

The audio (platform) device of my machine has two outputs (I2S and
S/PDIF = CPU DAIs) which are connected to different CODECs (HDMI
transmitter and S/PDIF connector).

There must be two different HDMI CODECs because the format and rate
constraints of the wires (I2S and S/PDIF) are different.

There is only one playback stream.
Jyri Sarha March 15, 2014, 9:14 a.m. UTC | #5
On 2014-03-14 20:40, Jean-Francois Moine wrote:
> On Fri, 14 Mar 2014 13:16:12 +0200
> Jyri Sarha <jsarha@ti.com> wrote:
> 
>> On 03/11/2014 11:36 AM, Jean-Francois Moine wrote:
>> > Some simple audio cards may have many DAI links.
>> > This patch extends the simple-card driver for handling such cards.
>> >
>> > Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
>> > ---
>> [...]
>> 
>> Why can't you just use two simple-card instances in your setup?
> 
> My machine has only one audio device (kirkwood). This one has two
> outputs. The first one (I2S) is connected to the HDMI transmitter, and
> the other one (S/PDIF) is connected to both the HDMI transmitter and 
> the
> S/PDIF connector. There can be only one playback stream, either via
> I2S, or S/PDIF, or both, with the final output either to HDMI or S/PDIF
> or both:
> 
>            /--> I2S -----+-> HDMI
> platform -+             /
>            \-> S/PDIF -+
>                         \--> S/PDIF
> 
> DPCM permits to activate both I2S and S/PDIF, but it does not handle
> the format and rate constraints (both outputs are always activated with
> the platform constraints).
> 
> So, the actual solution I use is 3 DAI links (= 3 PCMs):
> - HDMI via I2S
> - HDMI via S/PDIF (no S/PDIF output)
> - S/PDIF via S/PDIF (no HDMI output)
> 

Maybe a HW specific machine-driver would serve your case better. Of 
course it would be great to have a generic implementation that can 
handle this case too, but I am not sure if it should be called a 
simple-card anymore :).

>> You need to update the DT-binding document too when you are changing 
>> the
>> binding. That way it would also be easier to follow what you are 
>> trying
>> to accomplish here.
> 
> Some people want to have 2 different patchs: one for the code and the
> other one for the DT change. Some other people like you want only one
> patch. Which is the right way?
> 

I did not mean it should be in the same patch. Part of the same series 
is fine with me. It is up to maintainer to decide these things anyway. I 
would just like to compare the document with the implementation.

>> The sysclk and tdm properties appear to only work in the dais of the
>> first dai-link and __asoc_simple_card_dai_init() will not be called 
>> for
>> other dais at all. The DT-binding of this implementation would look
>> pretty hairy to me.
> 
> I will add an other dynamic structure for these properties.

Best regards,
Jyri
Mark Brown March 17, 2014, 4:19 p.m. UTC | #6
On Sat, Mar 15, 2014 at 11:14:13AM +0200, Jyri Sarha wrote:
> On 2014-03-14 20:40, Jean-Francois Moine wrote:

> >So, the actual solution I use is 3 DAI links (= 3 PCMs):
> >- HDMI via I2S
> >- HDMI via S/PDIF (no S/PDIF output)
> >- S/PDIF via S/PDIF (no HDMI output)

> Maybe a HW specific machine-driver would serve your case better. Of course
> it would be great to have a generic implementation that can handle this case
> too, but I am not sure if it should be called a simple-card anymore :).

I am a bit concerned about that I have to say.

> >>You need to update the DT-binding document too when you are changing the
> >>binding. That way it would also be easier to follow what you are trying
> >>to accomplish here.

> >Some people want to have 2 different patchs: one for the code and the
> >other one for the DT change. Some other people like you want only one
> >patch. Which is the right way?

> I did not mean it should be in the same patch. Part of the same series is
> fine with me. It is up to maintainer to decide these things anyway. I would
> just like to compare the document with the implementation.

If the binding is being changed in the code the documentation absolutely
must be updated as part of the same patch series if it's not already
been changed previously.  You can have documentation without code but
not code without documentation.
diff mbox

Patch

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 2710b52..8188c34 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -107,6 +107,9 @@  asoc_simple_card_sub_parse_of(struct device_node *np,
 	if (ret < 0)
 		return ret;
 
+	if (!dai)
+		return 0;
+
 	/* parse TDM slot */
 	ret = snd_soc_of_parse_tdm_slot(np, &dai->slots, &dai->slot_width);
 	if (ret)
@@ -154,7 +157,7 @@  static int asoc_simple_card_parse_of(struct device_node *node,
 	struct snd_soc_dai_link *dai_link = priv->snd_card.dai_link;
 	struct device_node *np;
 	char *name;
-	int ret;
+	int first_link, ret;
 
 	/* parsing the card name from DT */
 	snd_soc_of_parse_card_name(&priv->snd_card, "simple-audio-card,name");
@@ -179,50 +182,67 @@  static int asoc_simple_card_parse_of(struct device_node *node,
 			return ret;
 	}
 
-	/* CPU sub-node */
-	ret = -EINVAL;
-	np = of_get_child_by_name(node, "simple-audio-card,cpu");
-	if (np) {
+	/* loop on the DAI links */
+	np = NULL;
+	first_link = 1;
+	for (;;) {
+		np = of_get_next_child(node, np);
+		if (!np)
+			break;
+
+		/* CPU sub-node */
+		if (strcmp(np->name, "simple-audio-card,cpu") != 0) {
+			dev_err(dev, "Bad CPU DAI\n");
+			ret = -EINVAL;
+			goto err;
+		}
 		ret = asoc_simple_card_sub_parse_of(np, priv->daifmt,
-						  &priv->cpu_dai,
+					first_link ? &priv->cpu_dai : NULL,
 						  &dai_link->cpu_of_node,
 						  &dai_link->cpu_dai_name);
-		of_node_put(np);
-	}
-	if (ret < 0)
-		return ret;
+		if (ret < 0)
+			goto err;
 
-	/* CODEC sub-node */
-	ret = -EINVAL;
-	np = of_get_child_by_name(node, "simple-audio-card,codec");
-	if (np) {
+		/* CODEC sub-node */
+		np = of_get_next_child(node, np);
+		if (strcmp(np->name, "simple-audio-card,codec") != 0) {
+			dev_err(dev, "Bad CODEC DAI\n");
+			ret = -EINVAL;
+			goto err;
+		}
 		ret = asoc_simple_card_sub_parse_of(np, priv->daifmt,
-						  &priv->codec_dai,
+					first_link ? &priv->codec_dai : NULL,
 						  &dai_link->codec_of_node,
 						  &dai_link->codec_dai_name);
-		of_node_put(np);
-	}
-	if (ret < 0)
-		return ret;
+		if (ret < 0)
+			goto err;
+
+		if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) {
+			ret = -EINVAL;
+			goto err;
+		}
 
-	if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name)
-		return -EINVAL;
+		/* simple-card assumes platform == cpu */
+		dai_link->platform_of_node = dai_link->cpu_of_node;
+
+		name = devm_kzalloc(dev,
+				    strlen(dai_link->cpu_dai_name)   +
+				    strlen(dai_link->codec_dai_name) + 2,
+				    GFP_KERNEL);
+		sprintf(name, "%s-%s", dai_link->cpu_dai_name,
+					dai_link->codec_dai_name);
+		dai_link->name = dai_link->stream_name = name;
+
+		dai_link++;
+		first_link = 0;
+	}
 
 	/* card name is created from CPU/CODEC dai name */
-	name = devm_kzalloc(dev,
-			    strlen(dai_link->cpu_dai_name)   +
-			    strlen(dai_link->codec_dai_name) + 2,
-			    GFP_KERNEL);
-	sprintf(name, "%s-%s", dai_link->cpu_dai_name,
-				dai_link->codec_dai_name);
+	dai_link = priv->snd_card.dai_link;
 	if (!priv->snd_card.name)
-		priv->snd_card.name = name;
-	dai_link->name = dai_link->stream_name = name;
+		priv->snd_card.name = dai_link->name;
 
-	/* simple-card assumes platform == cpu */
-	dai_link->platform_of_node = dai_link->cpu_of_node;
-
-	dev_dbg(dev, "card-name : %s\n", name);
+	dev_dbg(dev, "card-name : %s\n", priv->snd_card.name);
 	dev_dbg(dev, "platform : %04x\n", priv->daifmt);
 	dev_dbg(dev, "cpu : %s / %04x / %d\n",
 		dai_link->cpu_dai_name,
@@ -233,18 +253,11 @@  static int asoc_simple_card_parse_of(struct device_node *node,
 		priv->codec_dai.fmt,
 		priv->codec_dai.sysclk);
 
-	/*
-	 * soc_bind_dai_link() will check cpu name
-	 * after of_node matching if dai_link has cpu_dai_name.
-	 * but, it will never match if name was created by fmt_single_name()
-	 * remove cpu_dai_name to escape name matching.
-	 * see
-	 *	fmt_single_name()
-	 *	fmt_multiple_name()
-	 */
-	dai_link->cpu_dai_name = NULL;
-
 	return 0;
+
+err:
+	of_node_put(np);
+	return ret;
 }
 
 /* update the reference count of the devices nodes at end of probe */
@@ -274,10 +287,22 @@  static int asoc_simple_card_probe(struct platform_device *pdev)
 	struct snd_soc_dai_link *dai_link;
 	struct device_node *np = pdev->dev.of_node;
 	struct device *dev = &pdev->dev;
-	int ret;
+	int num_links, ret;
+
+	/* get the number of DAI links */
+	if (np) {
+		num_links = of_get_child_count(np);
+		if (num_links == 0 || (num_links & 1)) {
+			dev_err(&pdev->dev, "Bad number of DAI links\n");
+			return -EINVAL;
+		}
+		num_links /= 2;
+	} else {
+		num_links = 1;
+	}
 
 	priv = devm_kzalloc(dev,
-			sizeof(*priv) + sizeof(*dai_link),
+			sizeof(*priv) + sizeof(*dai_link) * num_links,
 			GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
@@ -289,7 +314,7 @@  static int asoc_simple_card_probe(struct platform_device *pdev)
 	priv->snd_card.dev = dev;
 	dai_link = priv->dai_link;
 	priv->snd_card.dai_link = dai_link;
-	priv->snd_card.num_links = 1;
+	priv->snd_card.num_links = num_links;
 
 	if (np && of_device_is_available(np)) {
 
@@ -299,6 +324,19 @@  static int asoc_simple_card_probe(struct platform_device *pdev)
 				dev_err(dev, "parse error %d\n", ret);
 			goto err;
 		}
+
+		/*
+		 * soc_bind_dai_link() will check cpu name
+		 * after of_node matching if dai_link has cpu_dai_name.
+		 * but, it will never match if name was created by fmt_single_name()
+		 * remove cpu_dai_name to escape name matching.
+		 * see
+		 *	fmt_single_name()
+		 *	fmt_multiple_name()
+		 */
+		if (num_links == 1)
+			dai_link->cpu_dai_name = NULL;
+
 	} else {
 		struct asoc_simple_card_info *cinfo;