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 2/6] ASoC: Allow the DAPM routes to be stored in device tree
Date: Wed,  7 Dec 2011 15:13:43 -0700	[thread overview]
Message-ID: <1323296033-28730-5-git-send-email-swarren@nvidia.com> (raw)
In-Reply-To: <1323296033-28730-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

If a card's device was instantiated from device tree, and card's device
did not specify a DAPM route map, and the device tree has an "audio-
routing" property, parse this to construct the DAPM route array.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
v2: New patch; separated this code out of the Tegra+WM8903 machine driver
into a generic feature.

Note that this binding does not allow the "control" field of the routes
to be specified via device tree. Should the binding be expanded to allow
this? Representing this while still keeping the binding generic enough
to be useful outside ASoC might be difficult. I'm not sure if this
feature is useful at the card level? I quickly checked, and couldn't see
any in-tree users of this functionality.

 .../bindings/sound/soc-audio-complex.txt           |   15 ++++++
 sound/soc/soc-core.c                               |   48 ++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/soc-audio-complex.txt b/Documentation/devicetree/bindings/sound/soc-audio-complex.txt
index 1cc7059..f8e73cc 100644
--- a/Documentation/devicetree/bindings/sound/soc-audio-complex.txt
+++ b/Documentation/devicetree/bindings/sound/soc-audio-complex.txt
@@ -4,6 +4,12 @@ Required properties:
 - compatible : "generic,soc-audio-complex". Other compatible values
   indicating the specific HW model will typically be present too.
 - user-visible-name : The user-visible name of this sound complex.
+- audio-routing : A list of the connections between audio components.
+  Each entry is a pair of strings, the first being the connection's sink,
+  the second being the connection's source. Valid names for sources and
+  sinks are the determined by the binding for the HW that comprises the
+  audio complex, e.g. the names of an audio codec's pins, the names of
+  the user-visible jacks (plugs) on the board, etc.
 
 Example:
 
@@ -11,4 +17,13 @@ sound {
 	compatible = "nvidia,tegra-audio-wm8903",
 		     "generic,soc-audio-complex";
 	user-visible-name = "tegra-wm8903-harmony";
+	audio-routing =
+		"Headphone Jack", "HPOUTR",
+		"Headphone Jack", "HPOUTL",
+		"Int Spk", "ROP",
+		"Int Spk", "RON",
+		"Int Spk", "LOP",
+		"Int Spk", "LON",
+		"Mic Jack", "MICBIAS",
+		"IN1L", "Mic Jack";
 };
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 56d1bc5..f60e04f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2829,6 +2829,48 @@ static int snd_soc_of_parse_card_name(struct snd_soc_card *card)
 	return 0;
 }
 
+int snd_soc_of_parse_audio_routing(struct snd_soc_card *card)
+{
+	struct device_node *np = card->dev->of_node;
+	int num_routes;
+	struct snd_soc_dapm_route *routes;
+	int i;
+
+	num_routes = of_property_count_strings(np, "audio-routing");
+	if (num_routes & 1) {
+		dev_err(card->dev,
+			"Property 'audio-routing's length is not even\n");
+		return -EINVAL;
+	}
+	num_routes /= 2;
+	if (!num_routes) {
+		dev_err(card->dev,
+			"Property 'audio-routing's length is zero\n");
+		return -EINVAL;
+	}
+
+	routes = kzalloc(
+		num_routes * sizeof(*routes),
+		GFP_KERNEL);
+	if (!routes) {
+		dev_err(card->dev,
+			"Could not allocate DAPM route table\n");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < num_routes; i++) {
+		of_property_read_string_index(np, "audio-routing",
+			2 * i, &routes[i].sink);
+		of_property_read_string_index(np, "audio-routing",
+			(2 * i) + 1, &routes[i].source);
+	}
+
+	card->num_dapm_routes = num_routes;
+	card->dapm_routes = routes;
+
+	return 0;
+}
+
 /**
  * snd_soc_register_card - Register a card with the ASoC core
  *
@@ -2846,6 +2888,12 @@ int snd_soc_register_card(struct snd_soc_card *card)
 		ret = snd_soc_of_parse_card_name(card);
 		if (ret < 0)
 			return ret;
+
+		if (!card->num_dapm_routes && !card->dapm_routes) {
+			ret = snd_soc_of_parse_audio_routing(card);
+			if (ret < 0)
+				return ret;
+		}
 	}
 
 	if (!card->name) {
-- 
1.7.0.4

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

Thread overview: 33+ 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   ` Stephen Warren [this message]
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   ` [PATCH v2 4/6] ASoC: Allow DAI links to be specified using device tree nodes Stephen Warren
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 2/6] ASoC: Allow the DAPM routes to be stored in device tree Stephen Warren
     [not found]     ` <1323291510-22338-2-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-08  4:31       ` Mark Brown
     [not found]         ` <20111208043149.GA31372-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2011-12-09 21:52           ` Stephen Warren
     [not found]             ` <74CDBE0F657A3D45AFBB94109FB122FF17518605B1-C7FfzLzN0UxDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
2011-12-10 12:49               ` Mark Brown
     [not found]                 ` <20111210124921.GA20568-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2011-12-12 19:08                   ` Stephen Warren
     [not found]                     ` <4EE65128.2090209-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-13  1:32                       ` Mark Brown
2011-12-12 19:34                   ` Stephen Warren
2011-12-13  4:07                     ` 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-5-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).