devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>,
	Colin Cross <ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org>
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH v2 4/6] ASoC: Allow DAI links to be specified using device tree nodes
Date: Wed,  7 Dec 2011 15:13:47 -0700	[thread overview]
Message-ID: <1323296033-28730-9-git-send-email-swarren@nvidia.com> (raw)
In-Reply-To: <1323296033-28730-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

DAI link endpoints and platform (DMA) devices are currently specified
by name. When instantiating sound cards from device tree, it may be more
convenient to refer to these devices by phandle in the device tree, and
for code to describe DAI links using the "struct device_node *"
("of_node") those phandles map to.

This change adds new fields to snd_soc_dai_link which can "name" devices
using of_node, enhances soc_bind_dai_link() to allow binding based on
of_node, and enhances snd_soc_register_card() to ensure that illegal
combinations of name and of_node are not used.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
v2: New patch implementing a new feature

 include/sound/soc.h  |    4 +++
 sound/soc/soc-core.c |   64 ++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index d9aa66b..40c256e 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -231,6 +231,7 @@ enum snd_soc_bias_level {
 	SND_SOC_BIAS_ON = 3,
 };
 
+struct device_node;
 struct snd_jack;
 struct snd_soc_card;
 struct snd_soc_pcm_stream;
@@ -704,8 +705,11 @@ struct snd_soc_dai_link {
 	const char *name;			/* Codec name */
 	const char *stream_name;		/* Stream name */
 	const char *codec_name;		/* for multi-codec */
+	const struct device_node *codec_of_node;
 	const char *platform_name;	/* for multi-platform */
+	const struct device_node *platform_of_node;
 	const char *cpu_dai_name;
+	const struct device_node *cpu_dai_of_node;
 	const char *codec_dai_name;
 
 	unsigned int dai_fmt;           /* format to set on init */
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index d2f9df5..07e536f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -764,8 +764,13 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 	}
 	/* no, then find CPU DAI from registered DAIs*/
 	list_for_each_entry(cpu_dai, &dai_list, list) {
-		if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
-			continue;
+		if (dai_link->cpu_dai_of_node) {
+			if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
+				continue;
+		} else {
+			if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
+				continue;
+		}
 
 		rtd->cpu_dai = cpu_dai;
 		goto find_codec;
@@ -781,8 +786,13 @@ find_codec:
 
 	/* no, then find CODEC from registered CODECs*/
 	list_for_each_entry(codec, &codec_list, list) {
-		if (strcmp(codec->name, dai_link->codec_name))
-			continue;
+		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;
 
@@ -814,13 +824,19 @@ find_platform:
 
 	/* if there's no platform we match on the empty platform */
 	platform_name = dai_link->platform_name;
-	if (!platform_name)
+	if (!platform_name && !dai_link->platform_of_node)
 		platform_name = "snd-soc-dummy";
 
 	/* no, then find one from the set of registered platforms */
 	list_for_each_entry(platform, &platform_list, list) {
-		if (strcmp(platform->name, platform_name))
-			continue;
+		if (dai_link->platform_of_node) {
+			if (platform->dev->of_node !=
+			    dai_link->platform_of_node)
+				continue;
+		} else {
+			if (strcmp(platform->name, platform_name))
+				continue;
+		}
 
 		rtd->platform = platform;
 		goto out;
@@ -2909,6 +2925,40 @@ int snd_soc_register_card(struct snd_soc_card *card)
 		return -EINVAL;
 	}
 
+	for (i = 0; i < card->num_links; i++) {
+		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.
+		 */
+		if (!!link->codec_name == !!link->codec_of_node) {
+			dev_err(card->dev,
+				"Neither/both codec name/of_node are set\n");
+			return -EINVAL;
+		}
+
+		/*
+		 * Platform may be specified by either name or OF node, but
+		 * can be left unspecified, and a dummy platform will be used.
+		 */
+		if (link->platform_name && link->platform_of_node) {
+			dev_err(card->dev,
+				"Both platform name/of_node are set\n");
+			return -EINVAL;
+		}
+
+		/*
+		 * CPU DAI must be specified by 1 of name or OF node,
+		 * not both or neither.
+		 */
+		if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) {
+			dev_err(card->dev,
+				"Neither/both cpu_dai name/of_node are set\n");
+			return -EINVAL;
+		}
+	}
+
 	dev_set_drvdata(card->dev, card);
 
 	snd_soc_initialize_card_lists(card);
-- 
1.7.0.4

  parent reply	other threads:[~2011-12-07 22:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-07 22:13 [PATCH v2 0/8] arm/tegra: Device tree support for audio Stephen Warren
     [not found] ` <1323296033-28730-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-07 22:13   ` [PATCH v2 1/8] arm/tegra: board-dt: Fix AUXDATA typo Stephen Warren
     [not found]     ` <1323296033-28730-2-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-07 23:54       ` Olof Johansson
2011-12-07 22:13   ` [PATCH v2 1/6] ASoC: Allow device tree to specify a card's name Stephen Warren
     [not found]     ` <1323296033-28730-3-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-07 23:58       ` Olof Johansson
     [not found]         ` <20111207235818.GB12945-O5ziIzlqnXUVNXGz7ipsyg@public.gmane.org>
2011-12-08  0:15           ` Rob Herring
     [not found]             ` <4EE001BB.7010808-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-12-08  0:22               ` Stephen Warren
2011-12-07 22:13   ` [PATCH v2 2/8] arm/tegra: board-dt: Enable audio-related clocks Stephen Warren
     [not found]     ` <1323296033-28730-4-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-08  0:09       ` Olof Johansson
2011-12-07 22:13   ` [PATCH v2 2/6] ASoC: Allow the DAPM routes to be stored in device tree Stephen Warren
2011-12-07 22:13   ` [PATCH v2 3/8] arm/tegra: Split Seaboard GPIO table to allow for Ventana Stephen Warren
     [not found]     ` <1323296033-28730-6-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-08  0:11       ` Olof Johansson
     [not found]         ` <20111208001125.GD12945-O5ziIzlqnXUVNXGz7ipsyg@public.gmane.org>
2011-12-08  0:16           ` Stephen Warren
2011-12-07 22:13   ` [PATCH v2 3/6] ASoC: Refactor some conditions and loop in soc_bind_dai_link() Stephen Warren
2011-12-07 22:13   ` [PATCH v2 4/8] arm/dt: tegra: Add Tegra APB DMA device tree binding Stephen Warren
     [not found]     ` <1323296033-28730-8-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-08  0:13       ` Olof Johansson
     [not found]         ` <20111208001305.GE12945-O5ziIzlqnXUVNXGz7ipsyg@public.gmane.org>
2011-12-08  0:28           ` Olof Johansson
2011-12-07 22:13   ` Stephen Warren [this message]
2011-12-07 22:13   ` [PATCH v2 5/8] arm/dt: tegra: Clean up I2S and DAS nodes Stephen Warren
     [not found]     ` <1323296033-28730-10-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-08  0:14       ` Olof Johansson
2011-12-07 22:13   ` [PATCH v2 5/6] ASoC: Tegra: Move DAS configuration into DAS driver Stephen Warren
2011-12-07 22:13   ` [PATCH v2 6/8] arm/dt: tegra: Modify I2S nodes to match binding Stephen Warren
2011-12-07 22:13   ` [PATCH v2 6/6] ASoC: Tegra+WM8903 machine: Add device tree binding Stephen Warren
2011-12-07 22:13   ` [PATCH v2 7/8] arm/dt: tegra: Add labels for I2S controllers Stephen Warren
2011-12-07 22:13   ` [PATCH v2 8/8] arm/dt: tegra: Enable audio on WM8903 boards, disable others Stephen Warren
  -- strict thread matches above, loose matches on Subject: below --
2011-12-07 20:58 [PATCH v2 1/6] ASoC: Allow device tree to specify a card's name Stephen Warren
     [not found] ` <1323291510-22338-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-07 20:58   ` [PATCH v2 4/6] ASoC: Allow DAI links to be specified using device tree nodes Stephen Warren
     [not found]     ` <1323291510-22338-4-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-09  6:03       ` Mark Brown

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=1323296033-28730-9-git-send-email-swarren@nvidia.com \
    --to=swarren-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).