Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Benoit Cousson <bcousson@baylibre.com>
To: Jean-Francois Moine <moinejf@free.fr>, Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org, Xiubo Li <Li.Xiubo@freescale.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@gmail.com>,
	Jyri Sarha <jsarha@ti.com>
Subject: Re: [PATCH] ASoC:simple-card: Add multi-CODEC support
Date: Wed, 10 Sep 2014 13:43:06 +0200	[thread overview]
Message-ID: <5410394A.1030508@baylibre.com> (raw)
In-Reply-To: <54103671.c36bb40a.2743.ffff969aSMTPIN_ADDED_MISSING@mx.google.com>

Hi Jean-Francois,

On 10/09/2014 13:28, Jean-Francois Moine wrote:
> This patch adds multi-CODEC support to the simple-card.
>
> Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
> ---
>   .../devicetree/bindings/sound/simple-card.txt      | 28 +++++++--------
>   sound/soc/generic/simple-card.c                    | 41 +++++++++++++++++++++-
>   2 files changed, 52 insertions(+), 17 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt b/Documentation/devicetree/bindings/sound/simple-card.txt
> index c2e9841..c217687 100644
> --- a/Documentation/devicetree/bindings/sound/simple-card.txt
> +++ b/Documentation/devicetree/bindings/sound/simple-card.txt
> @@ -37,6 +37,8 @@ Required dai-link subnodes:
>
>   - cpu					: CPU   sub-node
>   - codec					: CODEC sub-node
> +					  In case of multi-CODECs, there may
> +					  be many of such sub-nodes.
>
>   Optional dai-link subnode properties:
>
> @@ -115,37 +117,31 @@ sh_fsi2: sh_fsi2@ec230000 {
>   	interrupts = <0 146 0x4>;
>   };
>
> -Example 2 - many DAI links:
> +Example 2 - many DAI links and multi-CODECs:
>
>   sound {
>   	compatible = "simple-audio-card";
>   	simple-audio-card,name = "Cubox Audio";
>
> -	simple-audio-card,dai-link@0 {		/* I2S - HDMI */
> +	simple-audio-card,dai-link@0 {		/* S/PDIF - HDMI & S/PDIF */
>   		format = "i2s";
>   		cpu {
> -			sound-dai = <&audio1 0>;
> -		};
> -		codec {
> -			sound-dai = <&tda998x 0>;
> -		};
> -	};
> -
> -	simple-audio-card,dai-link@1 {		/* S/PDIF - HDMI */
> -		cpu {
>   			sound-dai = <&audio1 1>;
>   		};
> -		codec {
> -			sound-dai = <&tda998x 1>;
> +		codec@0 {
> +			sound-dai = <&hdmi 0>;
> +		};
> +		codec@1 {
> +			sound-dai = <&spdif_codec>;
>   		};

I don't have strong opinion on that, but in my case, I was considering 
using a simple list instead of several nodes.
I don't like having to add fake address just to ensure uniqueness.

Something like that:

  sound-dais = <&spdif_codec 1>, <&hdmi 0>;

That being said, it will require changing the name with a plural form, 
and ensuring we have the same number of parameters for each codec.

That was just my .2 cents.

Regards,
Benoit



>   	};
>
> -	simple-audio-card,dai-link@2 {		/* S/PDIF - S/PDIF */
> +	simple-audio-card,dai-link@1 {		/* I2S - HDMI */
>   		cpu {
> -			sound-dai = <&audio1 1>;
> +			sound-dai = <&audio1 0>;
>   		};
>   		codec {
> -			sound-dai = <&spdif_codec>;
> +			sound-dai = <&hdmi 1>;
>   		};
>   	};
>   };
> diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
> index 4053152..bf0ce08 100644
> --- a/sound/soc/generic/simple-card.c
> +++ b/sound/soc/generic/simple-card.c
> @@ -179,11 +179,12 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
>   	struct device_node *np = NULL;
>   	struct device_node *bitclkmaster = NULL;
>   	struct device_node *framemaster = NULL;
> +	struct snd_soc_dai_link_component *component;
>   	unsigned int daifmt;
>   	char *name;
>   	char prop[128];
>   	char *prefix = "";
> -	int ret, cpu_args;
> +	int ret, cpu_args, num_codec_dais;
>
>   	/* For single DAI link & old style of DT node */
>   	if (is_top_level_node)
> @@ -225,7 +226,16 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
>   	}
>
>   	of_node_put(np);
> +
> +	/* count the number of codec DAIs */
>   	snprintf(prop, sizeof(prop), "%scodec", prefix);
> +	num_codec_dais = 0;
> +	for_each_child_of_node(node, np) {
> +		if (strcmp(np->name, prop) == 0)
> +			num_codec_dais++;
> +	}
> +
> +	/* treat the first DAI */
>   	np = of_get_child_by_name(node, prop);
>   	if (!np) {
>   		ret = -EINVAL;
> @@ -307,6 +317,35 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
>   	if (!cpu_args)
>   		dai_link->cpu_dai_name = NULL;
>
> +	/* handle multi-codec DAIs */
> +	if (num_codec_dais == 1)
> +		goto out;
> +	dai_link->codecs = component =
> +			   devm_kzalloc(dev,
> +					sizeof *component * num_codec_dais,
> +					GFP_KERNEL);
> +	dai_link->num_codecs = num_codec_dais;
> +	component->of_node = dai_link->codec_of_node;
> +	dai_link->codec_of_node = NULL;
> +	component->dai_name = dai_link->codec_dai_name;
> +	dai_link->codec_dai_name = NULL;
> +	for (;;) {
> +		np = of_get_next_child(node, np);
> +		if (!np)
> +			break;
> +		component++;
> +		component->of_node = of_parse_phandle(np, "sound-dai", 0);
> +		if (!component->of_node) {
> +			ret = -ENODEV;
> +			dev_err(dev, "Bad sound-dai\n");
> +			goto dai_link_of_err;
> +		}
> +		ret = snd_soc_of_get_dai_name(np, &component->dai_name);
> +		if (ret < 0)
> +			goto dai_link_of_err;
> +	}
> +
> +out:
>   dai_link_of_err:
>   	if (np)
>   		of_node_put(np);
>


-- 
Benoît Cousson
BayLibre
Embedded Linux Technology Lab
www.baylibre.com

       reply	other threads:[~2014-09-10 11:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <54103671.c36bb40a.2743.ffff969aSMTPIN_ADDED_MISSING@mx.google.com>
2014-09-10 11:43 ` Benoit Cousson [this message]
2014-09-10 16:06   ` [PATCH] ASoC:simple-card: Add multi-CODEC support Jean-Francois Moine
2014-09-10 16:27     ` Benoit Cousson
2014-09-10 17:25       ` Jean-Francois Moine
2014-09-10 11:28 Jean-Francois Moine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5410394A.1030508@baylibre.com \
    --to=bcousson@baylibre.com \
    --cc=Li.Xiubo@freescale.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=jsarha@ti.com \
    --cc=kuninori.morimoto.gx@gmail.com \
    --cc=moinejf@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox