Commit 1ae0965d authored by Stephan Gerhold's avatar Stephan Gerhold Committed by Mark Brown

ASoC: core: Add common helper to parse aux devs from device tree

simple-card.c and meson-card-utils.c use pretty much the same
helper function to parse auxiliary devices from the device tree.

Make it easier for other drivers to parse these from the device tree
as well by adding a shared helper function to soc-core.c.

snd_soc_of_parse_aux_devs() is pretty much a copy of
meson_card_add_aux_devices() from meson-card-utils.c
with two minor changes:

  - Make property name configurable as parameter
  - Change dev_err() message slightly for consistency with other
    error messages in soc-core.c
Signed-off-by: default avatarStephan Gerhold <stephan@gerhold.net>
Reviewed-by: default avatarJerome Brunet <jbrunet@baylibre.com>
Link: https://lore.kernel.org/r/20200801100257.22658-1-stephan@gerhold.netSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 7e3096e8
...@@ -1331,6 +1331,7 @@ void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card, ...@@ -1331,6 +1331,7 @@ void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
const char *propname); const char *propname);
int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname);
unsigned int snd_soc_of_parse_daifmt(struct device_node *np, unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
const char *prefix, const char *prefix,
struct device_node **bitclkmaster, struct device_node **bitclkmaster,
......
...@@ -2827,6 +2827,37 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, ...@@ -2827,6 +2827,37 @@ int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
} }
EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname)
{
struct device_node *node = card->dev->of_node;
struct snd_soc_aux_dev *aux;
int num, i;
num = of_count_phandle_with_args(node, propname, NULL);
if (num == -ENOENT) {
return 0;
} else if (num < 0) {
dev_err(card->dev, "ASOC: Property '%s' could not be read: %d\n",
propname, num);
return num;
}
aux = devm_kcalloc(card->dev, num, sizeof(*aux), GFP_KERNEL);
if (!aux)
return -ENOMEM;
card->aux_dev = aux;
card->num_aux_devs = num;
for_each_card_pre_auxs(card, i, aux) {
aux->dlc.of_node = of_parse_phandle(node, propname, i);
if (!aux->dlc.of_node)
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_of_parse_aux_devs);
unsigned int snd_soc_of_parse_daifmt(struct device_node *np, unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
const char *prefix, const char *prefix,
struct device_node **bitclkmaster, struct device_node **bitclkmaster,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment