diff --git a/include/sound/soc.h b/include/sound/soc.h index 278f3b892ca680e4aa9c9bae1772d5ae8d9178c4..db8acd2990435091270be18d3e04c2145e7b41a5 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -963,6 +963,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 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 51eef9b7b53f01534a619fb5d5794f91ede96937..42ad2db8f08271b0a4dc81756fb8c72ac89c627f 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