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;
17 struct snd_soc_dai_link_component *dlc;
20 ret = snd_soc_of_parse_card_name(card, "model");
22 dev_err(dev, "Error parsing card name: %d\n", ret);
27 if (of_property_read_bool(dev->of_node, "audio-routing")) {
28 ret = snd_soc_of_parse_audio_routing(card,
35 num_links = of_get_child_count(dev->of_node);
37 /* Allocate the DAI link array */
38 card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
42 card->num_links = num_links;
43 link = card->dai_link;
45 for_each_child_of_node(dev->of_node, np) {
46 dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
51 link->platforms = &dlc[1];
54 link->num_platforms = 1;
56 ret = of_property_read_string(np, "link-name", &link->name);
58 dev_err(card->dev, "error getting codec dai_link name\n");
62 cpu = of_get_child_by_name(np, "cpu");
63 platform = of_get_child_by_name(np, "platform");
64 codec = of_get_child_by_name(np, "codec");
67 dev_err(dev, "%s: Can't find cpu DT node\n", link->name);
72 ret = of_parse_phandle_with_args(cpu, "sound-dai",
73 "#sound-dai-cells", 0, &args);
75 dev_err(card->dev, "%s: error getting cpu phandle\n", link->name);
78 link->cpus->of_node = args.np;
79 link->id = args.args[0];
81 ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
83 dev_err(card->dev, "%s: error getting cpu dai name\n", link->name);
87 if (codec && platform) {
88 link->platforms->of_node = of_parse_phandle(platform,
91 if (!link->platforms->of_node) {
92 dev_err(card->dev, "%s: platform dai not found\n", link->name);
97 ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
99 dev_err(card->dev, "%s: codec dai not found\n", link->name);
103 link->ignore_pmdown_time = 1;
105 dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
110 link->num_codecs = 1;
112 link->platforms->of_node = link->cpus->of_node;
113 link->codecs->dai_name = "snd-soc-dummy-dai";
114 link->codecs->name = "snd-soc-dummy";
118 link->ignore_suspend = 1;
120 link->dpcm_playback = 1;
121 link->dpcm_capture = 1;
122 link->stream_name = link->name;
127 of_node_put(platform);
135 of_node_put(platform);
136 kfree(card->dai_link);
139 EXPORT_SYMBOL(qcom_snd_parse_of);
141 MODULE_LICENSE("GPL v2");