summaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorStephen Warren2011-12-12 23:55:35 +0100
committerMark Brown2011-12-20 02:05:34 +0100
commita4a54dd5bb1bb01010f46147d6d8b452255957bf (patch)
treef4f101cd8ceb909c32ebc0c6112446d2f483327d /sound/soc/soc-core.c
parentASoC: Add utility to set a card's name from device tree (diff)
downloadkernel-qcow2-linux-a4a54dd5bb1bb01010f46147d6d8b452255957bf.tar.gz
kernel-qcow2-linux-a4a54dd5bb1bb01010f46147d6d8b452255957bf.tar.xz
kernel-qcow2-linux-a4a54dd5bb1bb01010f46147d6d8b452255957bf.zip
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. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 51eef9b7b53f..42ad2db8f082 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3342,6 +3342,63 @@ int snd_soc_of_parse_card_name(struct snd_soc_card *card,
}
EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
+int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
+ const char *propname)
+{
+ struct device_node *np = card->dev->of_node;
+ int num_routes;
+ struct snd_soc_dapm_route *routes;
+ int i, ret;
+
+ num_routes = of_property_count_strings(np, propname);
+ if (num_routes & 1) {
+ dev_err(card->dev,
+ "Property '%s's length is not even\n",
+ propname);
+ return -EINVAL;
+ }
+ num_routes /= 2;
+ if (!num_routes) {
+ dev_err(card->dev,
+ "Property '%s's length is zero\n",
+ propname);
+ return -EINVAL;
+ }
+
+ routes = devm_kzalloc(card->dev, 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++) {
+ ret = of_property_read_string_index(np, propname,
+ 2 * i, &routes[i].sink);
+ if (ret) {
+ dev_err(card->dev,
+ "Property '%s' index %d could not be read: %d\n",
+ propname, 2 * i, ret);
+ return -EINVAL;
+ }
+ ret = of_property_read_string_index(np, propname,
+ (2 * i) + 1, &routes[i].source);
+ if (ret) {
+ dev_err(card->dev,
+ "Property '%s' index %d could not be read: %d\n",
+ propname, (2 * i) + 1, ret);
+ return -EINVAL;
+ }
+ }
+
+ card->num_dapm_routes = num_routes;
+ card->dapm_routes = routes;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
+
static int __init snd_soc_init(void)
{
#ifdef CONFIG_DEBUG_FS