forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/intel/boards/bytcht_da7213.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * bytcht-da7213.c - ASoc Machine driver for Intel Baytrail and
34 * Cherrytrail-based platforms, with Dialog DA7213 codec
....@@ -7,15 +8,6 @@
78 *
89 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
910 *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; version 2 of the License.
13
- *
14
- * This program is distributed in the hope that it will be useful, but
15
- * WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- * General Public License for more details.
18
- *
1911 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2012 */
2113
....@@ -23,7 +15,6 @@
2315 #include <linux/acpi.h>
2416 #include <linux/platform_device.h>
2517 #include <linux/slab.h>
26
-#include <asm/platform_sst_audio.h>
2718 #include <sound/pcm.h>
2819 #include <sound/pcm_params.h>
2920 #include <sound/soc.h>
....@@ -87,7 +78,7 @@
8778 * with explicit setting to I2S 2ch 24-bit. The word length is set with
8879 * dai_set_tdm_slot() since there is no other API exposed
8980 */
90
- ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
81
+ ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
9182 SND_SOC_DAIFMT_I2S |
9283 SND_SOC_DAIFMT_NB_NF |
9384 SND_SOC_DAIFMT_CBS_CFS);
....@@ -96,7 +87,7 @@
9687 return ret;
9788 }
9889
99
- ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
90
+ ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, 24);
10091 if (ret < 0) {
10192 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
10293 return ret;
....@@ -114,8 +105,8 @@
114105 static int aif1_hw_params(struct snd_pcm_substream *substream,
115106 struct snd_pcm_hw_params *params)
116107 {
117
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
118
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
108
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
109
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
119110 int ret;
120111
121112 ret = snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK,
....@@ -135,8 +126,8 @@
135126
136127 static int aif1_hw_free(struct snd_pcm_substream *substream)
137128 {
138
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
139
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
129
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
130
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
140131 int ret;
141132
142133 ret = snd_soc_dai_set_pll(codec_dai, 0,
....@@ -159,42 +150,50 @@
159150
160151 };
161152
153
+SND_SOC_DAILINK_DEF(dummy,
154
+ DAILINK_COMP_ARRAY(COMP_DUMMY()));
155
+
156
+SND_SOC_DAILINK_DEF(media,
157
+ DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
158
+
159
+SND_SOC_DAILINK_DEF(deepbuffer,
160
+ DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
161
+
162
+SND_SOC_DAILINK_DEF(ssp2_port,
163
+ DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
164
+SND_SOC_DAILINK_DEF(ssp2_codec,
165
+ DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7213:00",
166
+ "da7213-hifi")));
167
+
168
+SND_SOC_DAILINK_DEF(platform,
169
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
170
+
162171 static struct snd_soc_dai_link dailink[] = {
163172 [MERR_DPCM_AUDIO] = {
164173 .name = "Audio Port",
165174 .stream_name = "Audio",
166
- .cpu_dai_name = "media-cpu-dai",
167
- .codec_dai_name = "snd-soc-dummy-dai",
168
- .codec_name = "snd-soc-dummy",
169
- .platform_name = "sst-mfld-platform",
170175 .nonatomic = true,
171176 .dynamic = 1,
172177 .dpcm_playback = 1,
173178 .dpcm_capture = 1,
174179 .ops = &aif1_ops,
180
+ SND_SOC_DAILINK_REG(media, dummy, platform),
175181 },
176182 [MERR_DPCM_DEEP_BUFFER] = {
177183 .name = "Deep-Buffer Audio Port",
178184 .stream_name = "Deep-Buffer Audio",
179
- .cpu_dai_name = "deepbuffer-cpu-dai",
180
- .codec_dai_name = "snd-soc-dummy-dai",
181
- .codec_name = "snd-soc-dummy",
182
- .platform_name = "sst-mfld-platform",
183185 .nonatomic = true,
184186 .dynamic = 1,
185187 .dpcm_playback = 1,
186188 .ops = &aif1_ops,
189
+ SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
187190 },
188191 /* CODEC<->CODEC link */
189192 /* back ends */
190193 {
191194 .name = "SSP2-Codec",
192195 .id = 0,
193
- .cpu_dai_name = "ssp2-port",
194
- .platform_name = "sst-mfld-platform",
195196 .no_pcm = 1,
196
- .codec_dai_name = "da7213-hifi",
197
- .codec_name = "i2c-DLGS7213:00",
198197 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
199198 | SND_SOC_DAIFMT_CBS_CFS,
200199 .be_hw_params_fixup = codec_fixup,
....@@ -202,12 +201,23 @@
202201 .dpcm_playback = 1,
203202 .dpcm_capture = 1,
204203 .ops = &ssp2_ops,
204
+ SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
205205 },
206206 };
207207
208
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
209
+/* use space before codec name to simplify card ID, and simplify driver name */
210
+#define CARD_NAME "bytcht da7213" /* card name will be 'sof-bytcht da7213' */
211
+#define DRIVER_NAME "SOF"
212
+#else
213
+#define CARD_NAME "bytcht-da7213"
214
+#define DRIVER_NAME NULL /* card name will be used for driver name */
215
+#endif
216
+
208217 /* SoC card */
209218 static struct snd_soc_card bytcht_da7213_card = {
210
- .name = "bytcht-da7213",
219
+ .name = CARD_NAME,
220
+ .driver_name = DRIVER_NAME,
211221 .owner = THIS_MODULE,
212222 .dai_link = dailink,
213223 .num_links = ARRAY_SIZE(dailink),
....@@ -225,30 +235,39 @@
225235 {
226236 struct snd_soc_card *card;
227237 struct snd_soc_acpi_mach *mach;
228
- const char *i2c_name = NULL;
238
+ const char *platform_name;
239
+ struct acpi_device *adev;
229240 int dai_index = 0;
230241 int ret_val = 0;
231242 int i;
232243
233
- mach = (&pdev->dev)->platform_data;
244
+ mach = pdev->dev.platform_data;
234245 card = &bytcht_da7213_card;
235246 card->dev = &pdev->dev;
236247
237248 /* fix index of codec dai */
238249 for (i = 0; i < ARRAY_SIZE(dailink); i++) {
239
- if (!strcmp(dailink[i].codec_name, "i2c-DLGS7213:00")) {
250
+ if (!strcmp(dailink[i].codecs->name, "i2c-DLGS7213:00")) {
240251 dai_index = i;
241252 break;
242253 }
243254 }
244255
245256 /* fixup codec name based on HID */
246
- i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1);
247
- if (i2c_name) {
257
+ adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
258
+ if (adev) {
248259 snprintf(codec_name, sizeof(codec_name),
249
- "%s%s", "i2c-", i2c_name);
250
- dailink[dai_index].codec_name = codec_name;
260
+ "i2c-%s", acpi_dev_name(adev));
261
+ put_device(&adev->dev);
262
+ dailink[dai_index].codecs->name = codec_name;
251263 }
264
+
265
+ /* override plaform name, if required */
266
+ platform_name = mach->mach_params.platform;
267
+
268
+ ret_val = snd_soc_fixup_dai_links_platform_name(card, platform_name);
269
+ if (ret_val)
270
+ return ret_val;
252271
253272 ret_val = devm_snd_soc_register_card(&pdev->dev, card);
254273 if (ret_val) {
....@@ -263,6 +282,9 @@
263282 static struct platform_driver bytcht_da7213_driver = {
264283 .driver = {
265284 .name = "bytcht_da7213",
285
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
286
+ .pm = &snd_soc_pm_ops,
287
+#endif
266288 },
267289 .probe = bytcht_da7213_probe,
268290 };