forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/intel/boards/cht_bsw_nau8824.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * cht-bsw-nau8824.c - ASoc Machine driver for Intel Cherryview-based
34 * platforms Cherrytrail and Braswell, with nau8824 codec.
....@@ -8,15 +9,6 @@
89 * Author: Wang, Joseph C <joequant@gmail.com>
910 * Co-author: John Hsu <KCHSU0@nuvoton.com>
1011 * This file is based on cht_bsw_rt5672.c and cht-bsw-max98090.c
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; version 2 of the License.
15
- *
16
- * This program is distributed in the hope that it will be useful, but
17
- * WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
- * General Public License for more details.
2012 */
2113
2214 #include <linux/module.h>
....@@ -25,6 +17,7 @@
2517 #include <sound/pcm.h>
2618 #include <sound/pcm_params.h>
2719 #include <sound/soc.h>
20
+#include <sound/soc-acpi.h>
2821 #include <sound/jack.h>
2922 #include <linux/input.h>
3023 #include "../atom/sst-atom-controls.h"
....@@ -79,8 +72,8 @@
7972 static int cht_aif1_hw_params(struct snd_pcm_substream *substream,
8073 struct snd_pcm_hw_params *params)
8174 {
82
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
83
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
75
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
76
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
8477 int ret;
8578
8679 ret = snd_soc_dai_set_sysclk(codec_dai, NAU8824_CLK_FLL_FS, 0,
....@@ -103,7 +96,7 @@
10396 {
10497 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card);
10598 struct snd_soc_jack *jack = &ctx->jack;
106
- struct snd_soc_dai *codec_dai = runtime->codec_dai;
99
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0);
107100 struct snd_soc_component *component = codec_dai->component;
108101 int ret, jack_type;
109102
....@@ -115,7 +108,7 @@
115108 }
116109
117110 /* NAU88L24 supports 4 butons headset detection
118
- * KEY_MEDIA
111
+ * KEY_PLAYPAUSE
119112 * KEY_VOICECOMMAND
120113 * KEY_VOLUMEUP
121114 * KEY_VOLUMEDOWN
....@@ -129,7 +122,7 @@
129122 "Headset Jack creation failed %d\n", ret);
130123 return ret;
131124 }
132
- snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
125
+ snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
133126 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
134127 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
135128 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
....@@ -174,51 +167,59 @@
174167 .hw_params = cht_aif1_hw_params,
175168 };
176169
170
+SND_SOC_DAILINK_DEF(dummy,
171
+ DAILINK_COMP_ARRAY(COMP_DUMMY()));
172
+
173
+SND_SOC_DAILINK_DEF(media,
174
+ DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
175
+
176
+SND_SOC_DAILINK_DEF(deepbuffer,
177
+ DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
178
+
179
+SND_SOC_DAILINK_DEF(compress,
180
+ DAILINK_COMP_ARRAY(COMP_CPU("compress-cpu-dai")));
181
+
182
+SND_SOC_DAILINK_DEF(ssp2_port,
183
+ DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
184
+SND_SOC_DAILINK_DEF(ssp2_codec,
185
+ DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10508824:00",
186
+ NAU8824_CODEC_DAI)));
187
+
188
+SND_SOC_DAILINK_DEF(platform,
189
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
190
+
177191 static struct snd_soc_dai_link cht_dailink[] = {
178192 /* Front End DAI links */
179193 [MERR_DPCM_AUDIO] = {
180194 .name = "Audio Port",
181195 .stream_name = "Audio",
182
- .cpu_dai_name = "media-cpu-dai",
183
- .codec_dai_name = "snd-soc-dummy-dai",
184
- .codec_name = "snd-soc-dummy",
185
- .platform_name = "sst-mfld-platform",
186196 .nonatomic = true,
187197 .dynamic = 1,
188198 .dpcm_playback = 1,
189199 .dpcm_capture = 1,
190200 .ops = &cht_aif1_ops,
201
+ SND_SOC_DAILINK_REG(media, dummy, platform),
191202 },
192203 [MERR_DPCM_DEEP_BUFFER] = {
193204 .name = "Deep-Buffer Audio Port",
194205 .stream_name = "Deep-Buffer Audio",
195
- .cpu_dai_name = "deepbuffer-cpu-dai",
196
- .codec_dai_name = "snd-soc-dummy-dai",
197
- .codec_name = "snd-soc-dummy",
198
- .platform_name = "sst-mfld-platform",
199206 .nonatomic = true,
200207 .dynamic = 1,
201208 .dpcm_playback = 1,
202209 .ops = &cht_aif1_ops,
210
+ SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
203211 },
204212 [MERR_DPCM_COMPR] = {
205213 .name = "Compressed Port",
206214 .stream_name = "Compress",
207
- .cpu_dai_name = "compress-cpu-dai",
208
- .codec_dai_name = "snd-soc-dummy-dai",
209
- .codec_name = "snd-soc-dummy",
210
- .platform_name = "sst-mfld-platform",
215
+ SND_SOC_DAILINK_REG(compress, dummy, platform),
211216 },
212217 /* Back End DAI links */
213218 {
214219 /* SSP2 - Codec */
215220 .name = "SSP2-Codec",
216221 .id = 1,
217
- .cpu_dai_name = "ssp2-port",
218
- .platform_name = "sst-mfld-platform",
219222 .no_pcm = 1,
220
- .codec_dai_name = NAU8824_CODEC_DAI,
221
- .codec_name = "i2c-10508824:00",
222223 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF
223224 | SND_SOC_DAIFMT_CBS_CFS,
224225 .init = cht_codec_init,
....@@ -226,12 +227,23 @@
226227 .dpcm_playback = 1,
227228 .dpcm_capture = 1,
228229 .ops = &cht_be_ssp2_ops,
230
+ SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
229231 },
230232 };
231233
234
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
235
+/* use space before codec name to simplify card ID, and simplify driver name */
236
+#define CARD_NAME "bytcht nau8824" /* card name will be 'sof-bytcht nau8824 */
237
+#define DRIVER_NAME "SOF"
238
+#else
239
+#define CARD_NAME "chtnau8824"
240
+#define DRIVER_NAME NULL /* card name will be used for driver name */
241
+#endif
242
+
232243 /* SoC card */
233244 static struct snd_soc_card snd_soc_card_cht = {
234
- .name = "chtnau8824",
245
+ .name = CARD_NAME,
246
+ .driver_name = DRIVER_NAME,
235247 .owner = THIS_MODULE,
236248 .dai_link = cht_dailink,
237249 .num_links = ARRAY_SIZE(cht_dailink),
....@@ -246,6 +258,8 @@
246258 static int snd_cht_mc_probe(struct platform_device *pdev)
247259 {
248260 struct cht_mc_private *drv;
261
+ struct snd_soc_acpi_mach *mach;
262
+ const char *platform_name;
249263 int ret_val;
250264
251265 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
....@@ -253,8 +267,17 @@
253267 return -ENOMEM;
254268 snd_soc_card_set_drvdata(&snd_soc_card_cht, drv);
255269
256
- /* register the soc card */
270
+ /* override plaform name, if required */
257271 snd_soc_card_cht.dev = &pdev->dev;
272
+ mach = pdev->dev.platform_data;
273
+ platform_name = mach->mach_params.platform;
274
+
275
+ ret_val = snd_soc_fixup_dai_links_platform_name(&snd_soc_card_cht,
276
+ platform_name);
277
+ if (ret_val)
278
+ return ret_val;
279
+
280
+ /* register the soc card */
258281 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cht);
259282 if (ret_val) {
260283 dev_err(&pdev->dev,
....@@ -269,6 +292,9 @@
269292 static struct platform_driver snd_cht_mc_driver = {
270293 .driver = {
271294 .name = "cht-bsw-nau8824",
295
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
296
+ .pm = &snd_soc_pm_ops,
297
+#endif
272298 },
273299 .probe = snd_cht_mc_probe,
274300 };