ASoC: Introduce snd_soc_of_get_dai_link_cpus
This function is an analogue of snd_soc_of_get_dai_link_codecs to help machine drivers read CPU DAI lists from devicetrees. Signed-off-by: Martin Povišer <povik+lin@cutebit.org> Link: https://lore.kernel.org/r/20220331000449.41062-5-povik+lin@cutebit.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
1a8ee4cf84
commit
900dedd7e4
2 changed files with 84 additions and 0 deletions
|
@ -1263,6 +1263,10 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,
|
||||||
struct device_node *of_node,
|
struct device_node *of_node,
|
||||||
struct snd_soc_dai_link *dai_link);
|
struct snd_soc_dai_link *dai_link);
|
||||||
void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
|
void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link);
|
||||||
|
int snd_soc_of_get_dai_link_cpus(struct device *dev,
|
||||||
|
struct device_node *of_node,
|
||||||
|
struct snd_soc_dai_link *dai_link);
|
||||||
|
void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link);
|
||||||
|
|
||||||
int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
|
int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
|
||||||
struct snd_soc_dai_link *dai_link);
|
struct snd_soc_dai_link *dai_link);
|
||||||
|
|
|
@ -3390,6 +3390,86 @@ err:
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
|
EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* snd_soc_of_put_dai_link_cpus - Dereference device nodes in the codecs array
|
||||||
|
* @dai_link: DAI link
|
||||||
|
*
|
||||||
|
* Dereference device nodes acquired by snd_soc_of_get_dai_link_cpus().
|
||||||
|
*/
|
||||||
|
void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link)
|
||||||
|
{
|
||||||
|
struct snd_soc_dai_link_component *component;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
for_each_link_cpus(dai_link, index, component) {
|
||||||
|
if (!component->of_node)
|
||||||
|
break;
|
||||||
|
of_node_put(component->of_node);
|
||||||
|
component->of_node = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_cpus);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* snd_soc_of_get_dai_link_cpus - Parse a list of CPU DAIs in the devicetree
|
||||||
|
* @dev: Card device
|
||||||
|
* @of_node: Device node
|
||||||
|
* @dai_link: DAI link
|
||||||
|
*
|
||||||
|
* Is analogous to snd_soc_of_get_dai_link_codecs but parses a list of CPU DAIs
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* Returns 0 for success
|
||||||
|
*/
|
||||||
|
int snd_soc_of_get_dai_link_cpus(struct device *dev,
|
||||||
|
struct device_node *of_node,
|
||||||
|
struct snd_soc_dai_link *dai_link)
|
||||||
|
{
|
||||||
|
struct of_phandle_args args;
|
||||||
|
struct snd_soc_dai_link_component *component;
|
||||||
|
char *name;
|
||||||
|
int index, num_codecs, ret;
|
||||||
|
|
||||||
|
/* Count the number of CODECs */
|
||||||
|
name = "sound-dai";
|
||||||
|
num_codecs = of_count_phandle_with_args(of_node, name,
|
||||||
|
"#sound-dai-cells");
|
||||||
|
if (num_codecs <= 0) {
|
||||||
|
if (num_codecs == -ENOENT)
|
||||||
|
dev_err(dev, "No 'sound-dai' property\n");
|
||||||
|
else
|
||||||
|
dev_err(dev, "Bad phandle in 'sound-dai'\n");
|
||||||
|
return num_codecs;
|
||||||
|
}
|
||||||
|
component = devm_kcalloc(dev,
|
||||||
|
num_codecs, sizeof(*component),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!component)
|
||||||
|
return -ENOMEM;
|
||||||
|
dai_link->cpus = component;
|
||||||
|
dai_link->num_cpus = num_codecs;
|
||||||
|
|
||||||
|
/* Parse the list */
|
||||||
|
for_each_link_cpus(dai_link, index, component) {
|
||||||
|
ret = of_parse_phandle_with_args(of_node, name,
|
||||||
|
"#sound-dai-cells",
|
||||||
|
index, &args);
|
||||||
|
if (ret)
|
||||||
|
goto err;
|
||||||
|
component->of_node = args.np;
|
||||||
|
ret = snd_soc_get_dai_name(&args, &component->dai_name);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
snd_soc_of_put_dai_link_codecs(dai_link);
|
||||||
|
dai_link->cpus = NULL;
|
||||||
|
dai_link->num_cpus = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_cpus);
|
||||||
|
|
||||||
static int __init snd_soc_init(void)
|
static int __init snd_soc_init(void)
|
||||||
{
|
{
|
||||||
snd_soc_debugfs_init();
|
snd_soc_debugfs_init();
|
||||||
|
|
Loading…
Add table
Reference in a new issue