ASoC: Add utility to set a card's name from device tree
authorStephen Warren <swarren@nvidia.com>
Mon, 12 Dec 2011 22:55:34 +0000 (15:55 -0700)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 20 Dec 2011 01:05:34 +0000 (01:05 +0000)
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.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
include/sound/soc.h
sound/soc/soc-core.c

index a35cf14a8eb14ac7f867a9e13bb624e27c15463e..278f3b892ca680e4aa9c9bae1772d5ae8d9178c4 100644 (file)
@@ -961,6 +961,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
index 1252ab1ebf6940a2652b028c2f41fc9c92a4b260..51eef9b7b53f01534a619fb5d5794f91ede96937 100644 (file)
@@ -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>
@@ -3317,6 +3318,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