Skip to contentSkip to conversation

ASoC: Add utility to set a card's name from device tree

PATCH Applied Stephen Warren 2 participants 4 messages Dec 12, 2011 – Dec 20, 2011 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 ASoC: Add utility to set a card's name from device tree

Implement snd_soc_of_parse_card_name(), a utility function that sets a card's name from device tree. The machine driver specifies the DT property to use, since this is binding-specific.

---
This series is based on my previously posted patch "ASoC: Allow DAI links to be specified using device tree nodes" v4. Patches 1 & 2 at most rely on that for context. Patch 3 relies on it for functionality.

v2: New patch implementing new functionality
v3: Name this embedded-audio-complex instead of soc-audio-complex.
Change property name from user-visible-name to model. Remove compatible property from binding.
v4: Convert this to a utility function that cards can call if desired.
Modify snd_soc_register_card() not to call this automatically. Allow cards to specify the name of the device tree property that stores that card's name. Don't specify the property as a generic binding; remove embedded-audio-complex.txt

 include/sound/soc.h  |    3 +++
 sound/soc/soc-core.c |   25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
include/sound/soc.h +3 -0
index 40c256e..6e51a3f 100644
@@ -966,6 +966,9 @@ static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
 int snd_soc_util_init(void);
 void snd_soc_util_exit(void);
 
+int snd_soc_of_parse_card_name(struct snd_soc_card *card,
+			       const char *propname);
+
 #include <sound/soc-dai.h>
 
 #ifdef CONFIG_DEBUG_FS
sound/soc/soc-core.c +25 -0
index 83aa82e..4e8d762 100644
@@ -32,6 +32,7 @@
 #include <linux/platform_device.h>
 #include <linux/ctype.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 #include <sound/ac97_codec.h>
 #include <sound/core.h>
 #include <sound/jack.h>
@@ -3367,6 +3368,30 @@ found:
 }
 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
 
+/* Retrieve a card's name from device tree */
+int snd_soc_of_parse_card_name(struct snd_soc_card *card,
+			       const char *propname)
+{
+	struct device_node *np = card->dev->of_node;
+	int ret;
+
+	ret = of_property_read_string_index(np, propname, 0, &card->name);
+	/*
+	 * EINVAL means the property does not exist. This is fine providing
+	 * card->name was previously set, which is checked later in
+	 * snd_soc_register_card.
+	 */
+	if (ret < 0 && ret != -EINVAL) {
+		dev_err(card->dev,
+			"Property '%s' could not be read: %d\n",
+			propname, ret);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
+
 static int __init snd_soc_init(void)
 {
 #ifdef CONFIG_DEBUG_FS
Signature · 1 line
1.7.0.4

A message that is not in the archive (sent off-list or not yet received): 1323730536-19915-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH v4 2/3 ASoC: Add utility to parse DAPM routes from device tree

Implement snd_soc_of_parse_audio_routing(), a utility function that can parses a simple DAPM route table from device tree.The machine driver specifies the DT property to use, since this is binding-specific.

---
v2: New patch; separated this code out of the Tegra+WM8903 machine driver into a generic feature.
v3: No changes.
v4: Convert this to a utility function that cards can call if desired.
Modify snd_soc_register_card() not to call this automatically. Allow cards to specify the name of the device tree property that stores that card's name. Don't specify the property as a generic binding; remove embedded-audio-complex.txt

 include/sound/soc.h  |    2 +
 sound/soc/soc-core.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)
include/sound/soc.h +2 -0
index 6e51a3f..1e68661 100644
@@ -968,6 +968,8 @@ void snd_soc_util_exit(void);
 
 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
 			       const char *propname);
+int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
+				   const char *propname);
 
 #include <sound/soc-dai.h>
 
sound/soc/soc-core.c +57 -0

63 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#3 lore raw

PATCH v4 3/3 ASoC: Tegra+WM8903 machine: Add device tree binding

In reply to a message not in the archive

This driver is parameterized in two ways:

a) Platform data, which supplies the set of GPIOs used by the driver. These GPIOs can now be parsed out of device tree.

b) Machine-specific DAPM route arrays embedded into the ASoC machine driver itself. Historically, the driver picks the appropriate array to use using machine_is_*(). The driver now requires this array to be parsed from device tree when instantiated through device tree, using the core ASoC support for this parsing.

Based on work by John Bonesio, but significantly reworked since then.

---
v2:
* Split DAPM map parsing into a core ASoC feature.
* Updating binding to require codec and I2S controller phandles, use new ASoC core feature to bind DAI links using OF nodes rather than device names.
* Rebase on top of WM8903 MICBIAS supply conversion.
* Other minor cleanups.
v3:
* Numbering discontinuity due to patch series splitting/merging. v4:
* Call snd_soc_of_parse_card_name() and snd_soc_of_parse_audio_routing() explicitly, rather than relying on snd_soc_register_card() to do this.
* Restore complete binding documentation into tegra-audio-wm8903.txt instead of referencing embedded-audio-complex.txt

 .../bindings/sound/tegra-audio-wm8903.txt          |   71 +++++++++++
 sound/soc/tegra/tegra_wm8903.c                     |  128 ++++++++++++++++----
 2 files changed, 174 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/tegra-audio-wm8903.txt
Documentation/devicetree/bindings/sound/tegra-audio-wm8903.txt new file +71 -0
new file mode 100644
index 0000000..d5b0da8
@@ -0,0 +1,71 @@
+NVIDIA Tegra audio complex
+
+Required properties:
+- compatible : "nvidia,tegra-audio-wm8903"
+- nvidia,model : The user-visible name of this sound complex.
+- nvidia,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 WM8903's pins, and the jacks on the board:
+
+  WM8903 pins:
+
+  * IN1L
+  * IN1R
+  * IN2L
+  * IN2R
+  * IN3L
+  * IN3R
+  * DMICDAT
+  * HPOUTL
+  * HPOUTR
+  * LINEOUTL
+  * LINEOUTR
+  * LOP
+  * LON
+  * ROP
+  * RON
+  * MICBIAS
+
+  Board connectors:
+
+  * Headphone Jack
+  * Int Spk
+  * Mic Jack
+
+- nvidia,i2s-controller : The phandle of the Tegra I2S1 controller
+- nvidia,audio-codec : The phandle of the WM8903 audio codec
+
+Optional properties:
+- nvidia,spkr-en-gpios : The GPIO that enables the speakers
+- nvidia,hp-mute-gpios : The GPIO that mutes the headphones
+- nvidia,hp-det-gpios : The GPIO that detect headphones are plugged in
+- nvidia,int-mic-en-gpios : The GPIO that enables the internal microphone
+- nvidia,ext-mic-en-gpios : The GPIO that enables the external microphone
+
+Example:
+
+sound {
+	compatible = "nvidia,tegra-audio-wm8903-harmony",
+		     "nvidia,tegra-audio-wm8903"
+	nvidia,model = "tegra-wm8903-harmony";
+
+	nvidia,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";
+
+	nvidia,i2s-controller = <&i2s1>;
+	nvidia,audio-codec = <&wm8903>;
+
+	nvidia,spkr-en-gpios = <&codec 2 0>;
+	nvidia,hp-det-gpios = <&gpio 178 0>; /* gpio PW2 */
+	nvidia,int-mic-en-gpios = <&gpio 184 0>; /*gpio PX0 */
+	nvidia,ext-mic-en-gpios = <&gpio 185 0>; /* gpio PX1 */
+};
+
sound/soc/tegra/tegra_wm8903.c +103 -25

213 lines not on this page · raw message

Signature · 1 line
1.7.0.4
Applied
#4 lore raw
In reply to a message not in the archive
Quoted 3 lines · Stephen Warren

Implement snd_soc_of_parse_card_name(), a utility function that sets a card's name from device tree. The machine driver specifies the DT property to use, since this is binding-specific.

Applied all three, thanks.