Skip to content

Commit 3067e02

Browse files
committed
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.
2 parents 0a08778 + 0baa2c3 commit 3067e02

14 files changed

Lines changed: 79 additions & 121 deletions

File tree

include/sound/soc.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,17 @@ unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
13091309
snd_soc_daifmt_parse_clock_provider_as_bitmap(np, prefix))
13101310

13111311
int snd_soc_get_stream_cpu(struct snd_soc_dai_link *dai_link, int stream);
1312+
int snd_soc_get_dlc(const struct of_phandle_args *args,
1313+
struct snd_soc_dai_link_component *dlc);
1314+
int snd_soc_of_get_dlc(struct device_node *of_node,
1315+
struct of_phandle_args *args,
1316+
struct snd_soc_dai_link_component *dlc,
1317+
int index);
13121318
int snd_soc_get_dai_id(struct device_node *ep);
13131319
int snd_soc_get_dai_name(const struct of_phandle_args *args,
13141320
const char **dai_name);
13151321
int snd_soc_of_get_dai_name(struct device_node *of_node,
1316-
const char **dai_name);
1322+
const char **dai_name, int index);
13171323
int snd_soc_of_get_dai_link_codecs(struct device *dev,
13181324
struct device_node *of_node,
13191325
struct snd_soc_dai_link *dai_link);

sound/soc/fsl/imx-card.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,10 @@ static int imx_card_parse_of(struct imx_card_data *data)
551551
goto err;
552552
}
553553

554-
ret = of_parse_phandle_with_args(cpu, "sound-dai",
555-
"#sound-dai-cells", 0, &args);
554+
ret = snd_soc_of_get_dlc(cpu, &args, link->cpus, 0);
556555
if (ret) {
557-
dev_err(card->dev, "%s: error getting cpu phandle\n", link->name);
556+
dev_err_probe(card->dev, ret,
557+
"%s: error getting cpu dai info\n", link->name);
558558
goto err;
559559
}
560560

@@ -582,17 +582,9 @@ static int imx_card_parse_of(struct imx_card_data *data)
582582
}
583583
}
584584

585-
link->cpus->of_node = args.np;
586585
link->platforms->of_node = link->cpus->of_node;
587586
link->id = args.args[0];
588587

589-
ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
590-
if (ret) {
591-
dev_err_probe(card->dev, ret,
592-
"%s: error getting cpu dai name\n", link->name);
593-
goto err;
594-
}
595-
596588
codec = of_get_child_by_name(np, "codec");
597589
if (codec) {
598590
ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);

sound/soc/fsl/imx-rpmsg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
9696
} else {
9797
struct clk *clk;
9898

99-
data->dai.codecs->of_node = args.np;
100-
ret = snd_soc_get_dai_name(&args, &data->dai.codecs->dai_name);
99+
ret = snd_soc_get_dlc(&args, data->dai.codecs);
101100
if (ret) {
102101
dev_err(&pdev->dev, "Unable to get codec_dai_name\n");
103102
goto fail;

sound/soc/generic/simple-card-utils.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,14 +1103,12 @@ int asoc_graph_parse_dai(struct device_node *ep,
11031103
* 2) user need to rebind Sound Card everytime
11041104
* if he unbinded CPU or Codec.
11051105
*/
1106-
ret = snd_soc_get_dai_name(&args, &dlc->dai_name);
1106+
ret = snd_soc_get_dlc(&args, dlc);
11071107
if (ret < 0) {
11081108
of_node_put(node);
11091109
return ret;
11101110
}
11111111

1112-
dlc->of_node = node;
1113-
11141112
if (is_single_link)
11151113
*is_single_link = of_graph_get_endpoint_count(node) == 1;
11161114

sound/soc/generic/simple-card.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ static int asoc_simple_parse_dai(struct device_node *node,
8989
* 2) user need to rebind Sound Card everytime
9090
* if he unbinded CPU or Codec.
9191
*/
92-
ret = snd_soc_of_get_dai_name(node, &dlc->dai_name);
92+
ret = snd_soc_get_dlc(&args, dlc);
9393
if (ret < 0)
9494
return ret;
9595

96-
dlc->of_node = args.np;
97-
9896
if (is_single_link)
9997
*is_single_link = !args.args_count;
10098

sound/soc/loongson/loongson_card.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,9 @@ static int loongson_card_parse_acpi(struct loongson_card_data *data)
114114

115115
static int loongson_card_parse_of(struct loongson_card_data *data)
116116
{
117-
const char *cpu_dai_name, *codec_dai_name;
118117
struct device_node *cpu, *codec;
119118
struct snd_soc_card *card = &data->snd_card;
120119
struct device *dev = card->dev;
121-
struct of_phandle_args args;
122120
int ret, i;
123121

124122
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)
133131
goto err;
134132
}
135133

136-
ret = of_parse_phandle_with_args(cpu, "sound-dai",
137-
"#sound-dai-cells", 0, &args);
138-
if (ret) {
139-
dev_err(dev, "codec node missing #sound-dai-cells\n");
140-
goto err;
141-
}
142-
for (i = 0; i < card->num_links; i++)
143-
loongson_dai_links[i].cpus->of_node = args.np;
134+
for (i = 0; i < card->num_links; i++) {
135+
ret = snd_soc_of_get_dlc(cpu, NULL, loongson_dai_links[i].cpus, 0);
136+
if (ret < 0) {
137+
dev_err(dev, "getting cpu dlc error (%d)\n", ret);
138+
goto err;
139+
}
144140

145-
ret = of_parse_phandle_with_args(codec, "sound-dai",
146-
"#sound-dai-cells", 0, &args);
147-
if (ret) {
148-
dev_err(dev, "codec node missing #sound-dai-cells\n");
149-
goto err;
141+
ret = snd_soc_of_get_dlc(codec, NULL, loongson_dai_links[i].codecs, 0);
142+
if (ret < 0) {
143+
dev_err(dev, "getting codec dlc error (%d)\n", ret);
144+
goto err;
145+
}
150146
}
151-
for (i = 0; i < card->num_links; i++)
152-
loongson_dai_links[i].codecs->of_node = args.np;
153147

154-
snd_soc_of_get_dai_name(cpu, &cpu_dai_name);
155-
snd_soc_of_get_dai_name(codec, &codec_dai_name);
156-
for (i = 0; i < card->num_links; i++) {
157-
loongson_dai_links[i].cpus->dai_name = cpu_dai_name;
158-
loongson_dai_links[i].codecs->dai_name = codec_dai_name;
159-
}
160148
of_node_put(cpu);
161149
of_node_put(codec);
162150

sound/soc/mediatek/mt8173/mt8173-rt5650.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static int mt8173_rt5650_dev_probe(struct platform_device *pdev)
288288

289289
np = of_get_child_by_name(pdev->dev.of_node, "codec-capture");
290290
if (np) {
291-
ret = snd_soc_of_get_dai_name(np, &codec_capture_dai);
291+
ret = snd_soc_of_get_dai_name(np, &codec_capture_dai, 0);
292292
of_node_put(np);
293293
if (ret < 0) {
294294
dev_err(&pdev->dev,

sound/soc/meson/axg-card.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np,
319319
dai_link->cpus = cpu;
320320
dai_link->num_cpus = 1;
321321

322-
ret = meson_card_parse_dai(card, np, &dai_link->cpus->of_node,
323-
&dai_link->cpus->dai_name);
322+
ret = meson_card_parse_dai(card, np, dai_link->cpus);
324323
if (ret)
325324
return ret;
326325

sound/soc/meson/gx-card.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np,
9090
dai_link->cpus = cpu;
9191
dai_link->num_cpus = 1;
9292

93-
ret = meson_card_parse_dai(card, np, &dai_link->cpus->of_node,
94-
&dai_link->cpus->dai_name);
93+
ret = meson_card_parse_dai(card, np, dai_link->cpus);
9594
if (ret)
9695
return ret;
9796

sound/soc/meson/meson-card-utils.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,18 @@ EXPORT_SYMBOL_GPL(meson_card_reallocate_links);
7474

7575
int meson_card_parse_dai(struct snd_soc_card *card,
7676
struct device_node *node,
77-
struct device_node **dai_of_node,
78-
const char **dai_name)
77+
struct snd_soc_dai_link_component *dlc)
7978
{
80-
struct of_phandle_args args;
8179
int ret;
8280

83-
if (!dai_name || !dai_of_node || !node)
81+
if (!dlc || !node)
8482
return -EINVAL;
8583

86-
ret = of_parse_phandle_with_args(node, "sound-dai",
87-
"#sound-dai-cells", 0, &args);
84+
ret = snd_soc_of_get_dlc(node, NULL, dlc, 0);
8885
if (ret)
8986
return dev_err_probe(card->dev, ret, "can't parse dai\n");
9087

91-
*dai_of_node = args.np;
92-
93-
return snd_soc_get_dai_name(&args, dai_name);
88+
return ret;
9489
}
9590
EXPORT_SYMBOL_GPL(meson_card_parse_dai);
9691

@@ -160,8 +155,7 @@ int meson_card_set_be_link(struct snd_soc_card *card,
160155
link->num_codecs = num_codecs;
161156

162157
for_each_child_of_node(node, np) {
163-
ret = meson_card_parse_dai(card, np, &codec->of_node,
164-
&codec->dai_name);
158+
ret = meson_card_parse_dai(card, np, codec);
165159
if (ret) {
166160
of_node_put(np);
167161
return ret;

0 commit comments

Comments
 (0)