forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/sound/soc/qcom/apq8016_sbc.c
....@@ -1,15 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2015 The Linux Foundation. All rights reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 and
6
- * only version 2 as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
134 */
145
156 #include <linux/device.h>
....@@ -25,13 +16,14 @@
2516 #include <sound/soc.h>
2617 #include <uapi/linux/input-event-codes.h>
2718 #include <dt-bindings/sound/apq8016-lpass.h>
19
+#include "common.h"
2820
2921 struct apq8016_sbc_data {
22
+ struct snd_soc_card card;
3023 void __iomem *mic_iomux;
3124 void __iomem *spkr_iomux;
3225 struct snd_soc_jack jack;
3326 bool jack_setup;
34
- struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
3527 };
3628
3729 #define MIC_CTRL_TER_WS_SLAVE_SEL BIT(21)
....@@ -42,9 +34,9 @@
4234
4335 static int apq8016_sbc_dai_init(struct snd_soc_pcm_runtime *rtd)
4436 {
45
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
37
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
38
+ struct snd_soc_dai *codec_dai;
4639 struct snd_soc_component *component;
47
- struct snd_soc_dai_link *dai_link = rtd->dai_link;
4840 struct snd_soc_card *card = rtd->card;
4941 struct apq8016_sbc_data *pdata = snd_soc_card_get_drvdata(card);
5042 int i, rval;
....@@ -99,10 +91,9 @@
9991 pdata->jack_setup = true;
10092 }
10193
102
- for (i = 0 ; i < dai_link->num_codecs; i++) {
103
- struct snd_soc_dai *dai = rtd->codec_dais[i];
94
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
10495
105
- component = dai->component;
96
+ component = codec_dai->component;
10697 /* Set default mclk for internal codec */
10798 rval = snd_soc_component_set_sysclk(component, 0, 0, DEFAULT_MCLK_RATE,
10899 SND_SOC_CLOCK_IN);
....@@ -120,96 +111,13 @@
120111 return 0;
121112 }
122113
123
-static struct apq8016_sbc_data *apq8016_sbc_parse_of(struct snd_soc_card *card)
114
+static void apq8016_sbc_add_ops(struct snd_soc_card *card)
124115 {
125
- struct device *dev = card->dev;
126116 struct snd_soc_dai_link *link;
127
- struct device_node *np, *codec, *cpu, *node = dev->of_node;
128
- struct apq8016_sbc_data *data;
129
- int ret, num_links;
117
+ int i;
130118
131
- ret = snd_soc_of_parse_card_name(card, "qcom,model");
132
- if (ret) {
133
- dev_err(dev, "Error parsing card name: %d\n", ret);
134
- return ERR_PTR(ret);
135
- }
136
-
137
- /* DAPM routes */
138
- if (of_property_read_bool(node, "qcom,audio-routing")) {
139
- ret = snd_soc_of_parse_audio_routing(card,
140
- "qcom,audio-routing");
141
- if (ret)
142
- return ERR_PTR(ret);
143
- }
144
-
145
-
146
- /* Populate links */
147
- num_links = of_get_child_count(node);
148
-
149
- /* Allocate the private data and the DAI link array */
150
- data = devm_kzalloc(dev,
151
- struct_size(data, dai_link, num_links),
152
- GFP_KERNEL);
153
- if (!data)
154
- return ERR_PTR(-ENOMEM);
155
-
156
- card->dai_link = &data->dai_link[0];
157
- card->num_links = num_links;
158
-
159
- link = data->dai_link;
160
-
161
- for_each_child_of_node(node, np) {
162
- cpu = of_get_child_by_name(np, "cpu");
163
- codec = of_get_child_by_name(np, "codec");
164
-
165
- if (!cpu || !codec) {
166
- dev_err(dev, "Can't find cpu/codec DT node\n");
167
- ret = -EINVAL;
168
- goto error;
169
- }
170
-
171
- link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
172
- if (!link->cpu_of_node) {
173
- dev_err(card->dev, "error getting cpu phandle\n");
174
- ret = -EINVAL;
175
- goto error;
176
- }
177
-
178
- ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name);
179
- if (ret) {
180
- dev_err(card->dev, "error getting cpu dai name\n");
181
- goto error;
182
- }
183
-
184
- ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
185
-
186
- if (ret < 0) {
187
- dev_err(card->dev, "error getting codec dai name\n");
188
- goto error;
189
- }
190
-
191
- link->platform_of_node = link->cpu_of_node;
192
- ret = of_property_read_string(np, "link-name", &link->name);
193
- if (ret) {
194
- dev_err(card->dev, "error getting codec dai_link name\n");
195
- goto error;
196
- }
197
-
198
- link->stream_name = link->name;
119
+ for_each_card_prelinks(card, i, link)
199120 link->init = apq8016_sbc_dai_init;
200
- link++;
201
-
202
- of_node_put(cpu);
203
- of_node_put(codec);
204
- }
205
-
206
- return data;
207
-
208
- error:
209
- of_node_put(np);
210
- of_node_put(cpu);
211
- of_node_put(codec);
212
- return ERR_PTR(ret);
213121 }
214122
215123 static const struct snd_soc_dapm_widget apq8016_sbc_dapm_widgets[] = {
....@@ -227,21 +135,21 @@
227135 struct snd_soc_card *card;
228136 struct apq8016_sbc_data *data;
229137 struct resource *res;
138
+ int ret;
230139
231
- card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
232
- if (!card)
140
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
141
+ if (!data)
233142 return -ENOMEM;
234143
144
+ card = &data->card;
235145 card->dev = dev;
236146 card->owner = THIS_MODULE;
237147 card->dapm_widgets = apq8016_sbc_dapm_widgets;
238148 card->num_dapm_widgets = ARRAY_SIZE(apq8016_sbc_dapm_widgets);
239
- data = apq8016_sbc_parse_of(card);
240
- if (IS_ERR(data)) {
241
- dev_err(&pdev->dev, "Error resolving dai links: %ld\n",
242
- PTR_ERR(data));
243
- return PTR_ERR(data);
244
- }
149
+
150
+ ret = qcom_snd_parse_of(card);
151
+ if (ret)
152
+ return ret;
245153
246154 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mic-iomux");
247155 data->mic_iomux = devm_ioremap_resource(dev, res);
....@@ -255,6 +163,7 @@
255163
256164 snd_soc_card_set_drvdata(card, data);
257165
166
+ apq8016_sbc_add_ops(card);
258167 return devm_snd_soc_register_card(&pdev->dev, card);
259168 }
260169