diff options
| author | Stephen Warren <swarren@nvidia.com> | 2011-12-12 17:55:35 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-12-19 20:05:34 -0500 |
| commit | a4a54dd5bb1bb01010f46147d6d8b452255957bf (patch) | |
| tree | f4f101cd8ceb909c32ebc0c6112446d2f483327d | |
| parent | bec4fa05e25f7e78ec67df389539acc6bb352a2a (diff) | |
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>
| -rw-r--r-- | include/sound/soc.h | 2 | ||||
| -rw-r--r-- | sound/soc/soc-core.c | 57 |
2 files changed, 59 insertions, 0 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h index 278f3b892ca6..db8acd299043 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h | |||
| @@ -963,6 +963,8 @@ void snd_soc_util_exit(void); | |||
| 963 | 963 | ||
| 964 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, | 964 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, |
| 965 | const char *propname); | 965 | const char *propname); |
| 966 | int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, | ||
| 967 | const char *propname); | ||
| 966 | 968 | ||
| 967 | #include <sound/soc-dai.h> | 969 | #include <sound/soc-dai.h> |
| 968 | 970 | ||
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, | |||
| 3342 | } | 3342 | } |
| 3343 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); | 3343 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); |
| 3344 | 3344 | ||
| 3345 | int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, | ||
| 3346 | const char *propname) | ||
| 3347 | { | ||
| 3348 | struct device_node *np = card->dev->of_node; | ||
| 3349 | int num_routes; | ||
| 3350 | struct snd_soc_dapm_route *routes; | ||
| 3351 | int i, ret; | ||
| 3352 | |||
| 3353 | num_routes = of_property_count_strings(np, propname); | ||
| 3354 | if (num_routes & 1) { | ||
| 3355 | dev_err(card->dev, | ||
| 3356 | "Property '%s's length is not even\n", | ||
| 3357 | propname); | ||
| 3358 | return -EINVAL; | ||
| 3359 | } | ||
| 3360 | num_routes /= 2; | ||
| 3361 | if (!num_routes) { | ||
| 3362 | dev_err(card->dev, | ||
| 3363 | "Property '%s's length is zero\n", | ||
| 3364 | propname); | ||
| 3365 | return -EINVAL; | ||
| 3366 | } | ||
| 3367 | |||
| 3368 | routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), | ||
| 3369 | GFP_KERNEL); | ||
| 3370 | if (!routes) { | ||
| 3371 | dev_err(card->dev, | ||
| 3372 | "Could not allocate DAPM route table\n"); | ||
| 3373 | return -EINVAL; | ||
| 3374 | } | ||
| 3375 | |||
| 3376 | for (i = 0; i < num_routes; i++) { | ||
| 3377 | ret = of_property_read_string_index(np, propname, | ||
| 3378 | 2 * i, &routes[i].sink); | ||
| 3379 | if (ret) { | ||
| 3380 | dev_err(card->dev, | ||
| 3381 | "Property '%s' index %d could not be read: %d\n", | ||
| 3382 | propname, 2 * i, ret); | ||
| 3383 | return -EINVAL; | ||
| 3384 | } | ||
| 3385 | ret = of_property_read_string_index(np, propname, | ||
| 3386 | (2 * i) + 1, &routes[i].source); | ||
| 3387 | if (ret) { | ||
| 3388 | dev_err(card->dev, | ||
| 3389 | "Property '%s' index %d could not be read: %d\n", | ||
| 3390 | propname, (2 * i) + 1, ret); | ||
| 3391 | return -EINVAL; | ||
| 3392 | } | ||
| 3393 | } | ||
| 3394 | |||
| 3395 | card->num_dapm_routes = num_routes; | ||
| 3396 | card->dapm_routes = routes; | ||
| 3397 | |||
| 3398 | return 0; | ||
| 3399 | } | ||
| 3400 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); | ||
| 3401 | |||
| 3345 | static int __init snd_soc_init(void) | 3402 | static int __init snd_soc_init(void) |
| 3346 | { | 3403 | { |
| 3347 | #ifdef CONFIG_DEBUG_FS | 3404 | #ifdef CONFIG_DEBUG_FS |
