1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018, Linaro Limited.
3 // Copyright (c) 2018, The Linux Foundation. All rights reserved.
5 #include <linux/module.h>
8 int qcom_snd_parse_of(struct snd_soc_card *card)
10 struct device_node *np;
11 struct device_node *codec = NULL;
12 struct device_node *platform = NULL;
13 struct device_node *cpu = NULL;
14 struct device *dev = card->dev;
15 struct snd_soc_dai_link *link;
16 struct of_phandle_args args;
19 ret = snd_soc_of_parse_card_name(card, "model");
21 dev_err(dev, "Error parsing card name: %d\n", ret);
26 if (of_property_read_bool(dev->of_node, "audio-routing")) {
27 ret = snd_soc_of_parse_audio_routing(card,
34 num_links = of_get_child_count(dev->of_node);
36 /* Allocate the DAI link array */
37 card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
41 card->num_links = num_links;
42 link = card->dai_link;
43 for_each_child_of_node(dev->of_node, np) {
44 cpu = of_get_child_by_name(np, "cpu");
45 platform = of_get_child_by_name(np, "platform");
46 codec = of_get_child_by_name(np, "codec");
49 dev_err(dev, "Can't find cpu DT node\n");
54 ret = of_parse_phandle_with_args(cpu, "sound-dai",
55 "#sound-dai-cells", 0, &args);
57 dev_err(card->dev, "error getting cpu phandle\n");
60 link->cpu_of_node = args.np;
61 link->id = args.args[0];
63 ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name);
65 dev_err(card->dev, "error getting cpu dai name\n");
69 if (codec && platform) {
70 link->platform_of_node = of_parse_phandle(platform,
73 if (!link->platform_of_node) {
74 dev_err(card->dev, "platform dai not found\n");
79 ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
81 dev_err(card->dev, "codec dai not found\n");
85 link->ignore_pmdown_time = 1;
87 link->platform_of_node = link->cpu_of_node;
88 link->codec_dai_name = "snd-soc-dummy-dai";
89 link->codec_name = "snd-soc-dummy";
93 link->ignore_suspend = 1;
94 ret = of_property_read_string(np, "link-name", &link->name);
96 dev_err(card->dev, "error getting codec dai_link name\n");
100 link->dpcm_playback = 1;
101 link->dpcm_capture = 1;
102 link->stream_name = link->name;
107 of_node_put(platform);
115 of_node_put(platform);
116 kfree(card->dai_link);
119 EXPORT_SYMBOL(qcom_snd_parse_of);
121 MODULE_LICENSE("GPL v2");