Commit 3067e020 authored by Mark Brown's avatar Mark Brown

add snd_soc_{of_}get_dlc()

Merge series from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

Current soc-core.c has snd_soc_{of_}get_dai_name() to get DAI name
for dlc (snd_soc_dai_link_component). It gets .dai_name, but we need
.of_node too. Therefor user need to arrange.

It will be more useful if it gets both .dai_name and .of_node.
This patch adds snd_soc_{of_}get_dlc() for it, and convert to use it.
parents 0a087781 0baa2c3a
......@@ -1309,11 +1309,17 @@ unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix))
int snd_soc_get_stream_cpu(struct snd_soc_dai_link *dai_link, int stream);
int snd_soc_get_dlc(const struct of_phandle_args *args,
struct snd_soc_dai_link_component *dlc);
int snd_soc_of_get_dlc(struct device_node *of_node,
struct of_phandle_args *args,
struct snd_soc_dai_link_component *dlc,
int index);
int snd_soc_get_dai_id(struct device_node *ep);
int snd_soc_get_dai_name(const struct of_phandle_args *args,
const char **dai_name);
int snd_soc_of_get_dai_name(struct device_node *of_node,
const char **dai_name);
const char **dai_name, int index);
int snd_soc_of_get_dai_link_codecs(struct device *dev,
struct device_node *of_node,
struct snd_soc_dai_link *dai_link);
......
......@@ -551,10 +551,10 @@ static int imx_card_parse_of(struct imx_card_data *data)
goto err;
}
ret = of_parse_phandle_with_args(cpu, "sound-dai",
"#sound-dai-cells", 0, &args);
ret = snd_soc_of_get_dlc(cpu, &args, link->cpus, 0);
if (ret) {
dev_err(card->dev, "%s: error getting cpu phandle\n", link->name);
dev_err_probe(card->dev, ret,
"%s: error getting cpu dai info\n", link->name);
goto err;
}
......@@ -582,17 +582,9 @@ static int imx_card_parse_of(struct imx_card_data *data)
}
}
link->cpus->of_node = args.np;
link->platforms->of_node = link->cpus->of_node;
link->id = args.args[0];
ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
if (ret) {
dev_err_probe(card->dev, ret,
"%s: error getting cpu dai name\n", link->name);
goto err;
}
codec = of_get_child_by_name(np, "codec");
if (codec) {
ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
......
......@@ -96,8 +96,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
} else {
struct clk *clk;
data->dai.codecs->of_node = args.np;
ret = snd_soc_get_dai_name(&args, &data->dai.codecs->dai_name);
ret = snd_soc_get_dlc(&args, data->dai.codecs);
if (ret) {
dev_err(&pdev->dev, "Unable to get codec_dai_name\n");
goto fail;
......
......@@ -1103,14 +1103,12 @@ int asoc_graph_parse_dai(struct device_node *ep,
* 2) user need to rebind Sound Card everytime
* if he unbinded CPU or Codec.
*/
ret = snd_soc_get_dai_name(&args, &dlc->dai_name);
ret = snd_soc_get_dlc(&args, dlc);
if (ret < 0) {
of_node_put(node);
return ret;
}
dlc->of_node = node;
if (is_single_link)
*is_single_link = of_graph_get_endpoint_count(node) == 1;
......
......@@ -89,12 +89,10 @@ static int asoc_simple_parse_dai(struct device_node *node,
* 2) user need to rebind Sound Card everytime
* if he unbinded CPU or Codec.
*/
ret = snd_soc_of_get_dai_name(node, &dlc->dai_name);
ret = snd_soc_get_dlc(&args, dlc);
if (ret < 0)
return ret;
dlc->of_node = args.np;
if (is_single_link)
*is_single_link = !args.args_count;
......
......@@ -114,11 +114,9 @@ static int loongson_card_parse_acpi(struct loongson_card_data *data)
static int loongson_card_parse_of(struct loongson_card_data *data)
{
const char *cpu_dai_name, *codec_dai_name;
struct device_node *cpu, *codec;
struct snd_soc_card *card = &data->snd_card;
struct device *dev = card->dev;
struct of_phandle_args args;
int ret, i;
cpu = of_get_child_by_name(dev->of_node, "cpu");
......@@ -133,30 +131,20 @@ static int loongson_card_parse_of(struct loongson_card_data *data)
goto err;
}
ret = of_parse_phandle_with_args(cpu, "sound-dai",
"#sound-dai-cells", 0, &args);
if (ret) {
dev_err(dev, "codec node missing #sound-dai-cells\n");
goto err;
}
for (i = 0; i < card->num_links; i++)
loongson_dai_links[i].cpus->of_node = args.np;
for (i = 0; i < card->num_links; i++) {
ret = snd_soc_of_get_dlc(cpu, NULL, loongson_dai_links[i].cpus, 0);
if (ret < 0) {
dev_err(dev, "getting cpu dlc error (%d)\n", ret);
goto err;
}
ret = of_parse_phandle_with_args(codec, "sound-dai",
"#sound-dai-cells", 0, &args);
if (ret) {
dev_err(dev, "codec node missing #sound-dai-cells\n");
goto err;
ret = snd_soc_of_get_dlc(codec, NULL, loongson_dai_links[i].codecs, 0);
if (ret < 0) {
dev_err(dev, "getting codec dlc error (%d)\n", ret);
goto err;
}
}
for (i = 0; i < card->num_links; i++)
loongson_dai_links[i].codecs->of_node = args.np;
snd_soc_of_get_dai_name(cpu, &cpu_dai_name);
snd_soc_of_get_dai_name(codec, &codec_dai_name);
for (i = 0; i < card->num_links; i++) {
loongson_dai_links[i].cpus->dai_name = cpu_dai_name;
loongson_dai_links[i].codecs->dai_name = codec_dai_name;
}
of_node_put(cpu);
of_node_put(codec);
......
......@@ -288,7 +288,7 @@ static int mt8173_rt5650_dev_probe(struct platform_device *pdev)
np = of_get_child_by_name(pdev->dev.of_node, "codec-capture");
if (np) {
ret = snd_soc_of_get_dai_name(np, &codec_capture_dai);
ret = snd_soc_of_get_dai_name(np, &codec_capture_dai, 0);
of_node_put(np);
if (ret < 0) {
dev_err(&pdev->dev,
......
......@@ -319,8 +319,7 @@ static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np,
dai_link->cpus = cpu;
dai_link->num_cpus = 1;
ret = meson_card_parse_dai(card, np, &dai_link->cpus->of_node,
&dai_link->cpus->dai_name);
ret = meson_card_parse_dai(card, np, dai_link->cpus);
if (ret)
return ret;
......
......@@ -90,8 +90,7 @@ static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np,
dai_link->cpus = cpu;
dai_link->num_cpus = 1;
ret = meson_card_parse_dai(card, np, &dai_link->cpus->of_node,
&dai_link->cpus->dai_name);
ret = meson_card_parse_dai(card, np, dai_link->cpus);
if (ret)
return ret;
......
......@@ -74,23 +74,18 @@ EXPORT_SYMBOL_GPL(meson_card_reallocate_links);
int meson_card_parse_dai(struct snd_soc_card *card,
struct device_node *node,
struct device_node **dai_of_node,
const char **dai_name)
struct snd_soc_dai_link_component *dlc)
{
struct of_phandle_args args;
int ret;
if (!dai_name || !dai_of_node || !node)
if (!dlc || !node)
return -EINVAL;
ret = of_parse_phandle_with_args(node, "sound-dai",
"#sound-dai-cells", 0, &args);
ret = snd_soc_of_get_dlc(node, NULL, dlc, 0);
if (ret)
return dev_err_probe(card->dev, ret, "can't parse dai\n");
*dai_of_node = args.np;
return snd_soc_get_dai_name(&args, dai_name);
return ret;
}
EXPORT_SYMBOL_GPL(meson_card_parse_dai);
......@@ -160,8 +155,7 @@ int meson_card_set_be_link(struct snd_soc_card *card,
link->num_codecs = num_codecs;
for_each_child_of_node(node, np) {
ret = meson_card_parse_dai(card, np, &codec->of_node,
&codec->dai_name);
ret = meson_card_parse_dai(card, np, codec);
if (ret) {
of_node_put(np);
return ret;
......
......@@ -39,8 +39,7 @@ int meson_card_reallocate_links(struct snd_soc_card *card,
unsigned int num_links);
int meson_card_parse_dai(struct snd_soc_card *card,
struct device_node *node,
struct device_node **dai_of_node,
const char **dai_name);
struct snd_soc_dai_link_component *dlc);
int meson_card_set_be_link(struct snd_soc_card *card,
struct snd_soc_dai_link *link,
struct device_node *node);
......
......@@ -96,22 +96,15 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
goto err;
}
ret = of_parse_phandle_with_args(cpu, "sound-dai",
"#sound-dai-cells", 0, &args);
if (ret) {
dev_err(card->dev, "%s: error getting cpu phandle\n", link->name);
goto err;
}
link->cpus->of_node = args.np;
link->id = args.args[0];
ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
ret = snd_soc_of_get_dlc(cpu, &args, link->cpus, 0);
if (ret) {
dev_err_probe(card->dev, ret,
"%s: error getting cpu dai name\n", link->name);
goto err;
}
link->id = args.args[0];
if (platform) {
link->platforms->of_node = of_parse_phandle(platform,
"sound-dai",
......
......@@ -205,7 +205,6 @@ static int odroid_audio_probe(struct platform_device *pdev)
struct snd_soc_card *card;
struct snd_soc_dai_link *link, *codec_link;
int num_pcms, ret, i;
struct of_phandle_args args = {};
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
......@@ -260,20 +259,7 @@ static int odroid_audio_probe(struct platform_device *pdev)
}
for (i = 0; i < num_pcms; i++, link += 2) {
ret = of_parse_phandle_with_args(cpu, "sound-dai",
"#sound-dai-cells", i, &args);
if (ret < 0)
break;
if (!args.np) {
dev_err(dev, "sound-dai property parse error: %d\n", ret);
ret = -EINVAL;
break;
}
ret = snd_soc_get_dai_name(&args, &link->cpus->dai_name);
of_node_put(args.np);
ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name, i);
if (ret < 0)
break;
}
......
......@@ -3257,8 +3257,7 @@ int snd_soc_get_dai_id(struct device_node *ep)
}
EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
int snd_soc_get_dai_name(const struct of_phandle_args *args,
const char **dai_name)
int snd_soc_get_dlc(const struct of_phandle_args *args, struct snd_soc_dai_link_component *dlc)
{
struct snd_soc_component *pos;
int ret = -EPROBE_DEFER;
......@@ -3270,7 +3269,7 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
if (component_of_node != args->np || !pos->num_dai)
continue;
ret = snd_soc_component_of_xlate_dai_name(pos, args, dai_name);
ret = snd_soc_component_of_xlate_dai_name(pos, args, &dlc->dai_name);
if (ret == -ENOTSUPP) {
struct snd_soc_dai *dai;
int id = -1;
......@@ -3301,9 +3300,10 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
id--;
}
*dai_name = dai->driver->name;
if (!*dai_name)
*dai_name = pos->name;
dlc->of_node = args->np;
dlc->dai_name = dai->driver->name;
if (!dlc->dai_name)
dlc->dai_name = pos->name;
} else if (ret) {
/*
* if another error than ENOTSUPP is returned go on and
......@@ -3319,22 +3319,49 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
mutex_unlock(&client_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
EXPORT_SYMBOL_GPL(snd_soc_get_dlc);
int snd_soc_of_get_dai_name(struct device_node *of_node,
const char **dai_name)
int snd_soc_of_get_dlc(struct device_node *of_node,
struct of_phandle_args *args,
struct snd_soc_dai_link_component *dlc,
int index)
{
struct of_phandle_args args;
struct of_phandle_args __args;
int ret;
if (!args)
args = &__args;
ret = of_parse_phandle_with_args(of_node, "sound-dai",
"#sound-dai-cells", 0, &args);
"#sound-dai-cells", index, args);
if (ret)
return ret;
ret = snd_soc_get_dai_name(&args, dai_name);
return snd_soc_get_dlc(args, dlc);
}
EXPORT_SYMBOL_GPL(snd_soc_of_get_dlc);
int snd_soc_get_dai_name(const struct of_phandle_args *args,
const char **dai_name)
{
struct snd_soc_dai_link_component dlc;
int ret = snd_soc_get_dlc(args, &dlc);
if (ret == 0)
*dai_name = dlc.dai_name;
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
int snd_soc_of_get_dai_name(struct device_node *of_node,
const char **dai_name, int index)
{
struct snd_soc_dai_link_component dlc;
int ret = snd_soc_of_get_dlc(of_node, NULL, &dlc, index);
of_node_put(args.np);
if (ret == 0)
*dai_name = dlc.dai_name;
return ret;
}
......@@ -3375,26 +3402,6 @@ static int __snd_soc_of_get_dai_link_component_alloc(
return 0;
}
static int __snd_soc_of_get_dai_link_component_parse(
struct device_node *of_node,
struct snd_soc_dai_link_component *component, int index)
{
struct of_phandle_args args;
int ret;
ret = of_parse_phandle_with_args(of_node, "sound-dai", "#sound-dai-cells",
index, &args);
if (ret)
return ret;
ret = snd_soc_get_dai_name(&args, &component->dai_name);
if (ret < 0)
return ret;
component->of_node = args.np;
return 0;
}
/*
* snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
* @dai_link: DAI link
......@@ -3439,7 +3446,7 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,
/* Parse the list */
for_each_link_codecs(dai_link, index, component) {
ret = __snd_soc_of_get_dai_link_component_parse(of_node, component, index);
ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
if (ret)
goto err;
}
......@@ -3494,7 +3501,7 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev,
/* Parse the list */
for_each_link_cpus(dai_link, index, component) {
ret = __snd_soc_of_get_dai_link_component_parse(of_node, component, index);
ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
if (ret)
goto err;
}
......
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