Commit | Line | Data |
---|---|---|
c25e295c R |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | // Copyright (c) 2018, Linaro Limited. | |
3 | // Copyright (c) 2018, The Linux Foundation. All rights reserved. | |
4 | ||
5 | #include <linux/module.h> | |
6 | #include "common.h" | |
7 | ||
8 | int qcom_snd_parse_of(struct snd_soc_card *card) | |
9 | { | |
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; | |
67fd1437 | 16 | struct of_phandle_args args; |
1e36ea36 | 17 | struct snd_soc_dai_link_component *dlc; |
c25e295c R |
18 | int ret, num_links; |
19 | ||
20 | ret = snd_soc_of_parse_card_name(card, "model"); | |
21 | if (ret) { | |
22 | dev_err(dev, "Error parsing card name: %d\n", ret); | |
23 | return ret; | |
24 | } | |
25 | ||
26 | /* DAPM routes */ | |
27 | if (of_property_read_bool(dev->of_node, "audio-routing")) { | |
28 | ret = snd_soc_of_parse_audio_routing(card, | |
29 | "audio-routing"); | |
30 | if (ret) | |
31 | return ret; | |
32 | } | |
33 | ||
34 | /* Populate links */ | |
35 | num_links = of_get_child_count(dev->of_node); | |
36 | ||
37 | /* Allocate the DAI link array */ | |
38 | card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL); | |
39 | if (!card->dai_link) | |
40 | return -ENOMEM; | |
41 | ||
42 | card->num_links = num_links; | |
43 | link = card->dai_link; | |
1e36ea36 | 44 | |
c25e295c | 45 | for_each_child_of_node(dev->of_node, np) { |
16395cee BA |
46 | dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL); |
47 | if (!dlc) | |
48 | return -ENOMEM; | |
1e36ea36 | 49 | |
16395cee BA |
50 | link->cpus = &dlc[0]; |
51 | link->platforms = &dlc[1]; | |
1e36ea36 | 52 | |
16395cee BA |
53 | link->num_cpus = 1; |
54 | link->num_platforms = 1; | |
1e36ea36 | 55 | |
c25e295c | 56 | cpu = of_get_child_by_name(np, "cpu"); |
70b77321 TI |
57 | platform = of_get_child_by_name(np, "platform"); |
58 | codec = of_get_child_by_name(np, "codec"); | |
59 | ||
c25e295c R |
60 | if (!cpu) { |
61 | dev_err(dev, "Can't find cpu DT node\n"); | |
62 | ret = -EINVAL; | |
63 | goto err; | |
64 | } | |
65 | ||
67fd1437 R |
66 | ret = of_parse_phandle_with_args(cpu, "sound-dai", |
67 | "#sound-dai-cells", 0, &args); | |
68 | if (ret) { | |
c25e295c | 69 | dev_err(card->dev, "error getting cpu phandle\n"); |
c25e295c R |
70 | goto err; |
71 | } | |
1e36ea36 | 72 | link->cpus->of_node = args.np; |
67fd1437 | 73 | link->id = args.args[0]; |
c25e295c | 74 | |
1e36ea36 | 75 | ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name); |
c25e295c R |
76 | if (ret) { |
77 | dev_err(card->dev, "error getting cpu dai name\n"); | |
78 | goto err; | |
79 | } | |
80 | ||
c25e295c | 81 | if (codec && platform) { |
1e36ea36 | 82 | link->platforms->of_node = of_parse_phandle(platform, |
c25e295c R |
83 | "sound-dai", |
84 | 0); | |
1e36ea36 | 85 | if (!link->platforms->of_node) { |
c25e295c R |
86 | dev_err(card->dev, "platform dai not found\n"); |
87 | ret = -EINVAL; | |
88 | goto err; | |
89 | } | |
90 | ||
91 | ret = snd_soc_of_get_dai_link_codecs(dev, codec, link); | |
92 | if (ret < 0) { | |
93 | dev_err(card->dev, "codec dai not found\n"); | |
94 | goto err; | |
95 | } | |
96 | link->no_pcm = 1; | |
97 | link->ignore_pmdown_time = 1; | |
98 | } else { | |
1e36ea36 KM |
99 | dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL); |
100 | if (!dlc) | |
101 | return -ENOMEM; | |
102 | ||
103 | link->codecs = dlc; | |
104 | link->num_codecs = 1; | |
105 | ||
0751154f | 106 | link->platforms->of_node = link->cpus->of_node; |
1e36ea36 KM |
107 | link->codecs->dai_name = "snd-soc-dummy-dai"; |
108 | link->codecs->name = "snd-soc-dummy"; | |
c25e295c R |
109 | link->dynamic = 1; |
110 | } | |
111 | ||
112 | link->ignore_suspend = 1; | |
113 | ret = of_property_read_string(np, "link-name", &link->name); | |
114 | if (ret) { | |
115 | dev_err(card->dev, "error getting codec dai_link name\n"); | |
116 | goto err; | |
117 | } | |
118 | ||
c054b416 | 119 | link->nonatomic = 1; |
c25e295c R |
120 | link->dpcm_playback = 1; |
121 | link->dpcm_capture = 1; | |
122 | link->stream_name = link->name; | |
123 | link++; | |
70b77321 TI |
124 | |
125 | of_node_put(cpu); | |
126 | of_node_put(codec); | |
127 | of_node_put(platform); | |
c25e295c R |
128 | } |
129 | ||
130 | return 0; | |
131 | err: | |
70b77321 | 132 | of_node_put(np); |
c25e295c R |
133 | of_node_put(cpu); |
134 | of_node_put(codec); | |
135 | of_node_put(platform); | |
136 | kfree(card->dai_link); | |
137 | return ret; | |
138 | } | |
139 | EXPORT_SYMBOL(qcom_snd_parse_of); | |
140 | ||
141 | MODULE_LICENSE("GPL v2"); |