forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/intel/boards/broadwell.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Intel Broadwell Wildcatpoint SST Audio
34 *
45 * Copyright (C) 2013, Intel Corporation. All rights reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License version
8
- * 2 as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
156 */
167
178 #include <linux/module.h>
....@@ -21,9 +12,7 @@
2112 #include <sound/soc.h>
2213 #include <sound/jack.h>
2314 #include <sound/pcm_params.h>
24
-
25
-#include "../common/sst-dsp.h"
26
-#include "../haswell/sst-haswell-ipc.h"
15
+#include <sound/soc-acpi.h>
2716
2817 #include "../../codecs/rt286.h"
2918
....@@ -78,7 +67,7 @@
7867
7968 static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
8069 {
81
- struct snd_soc_component *component = rtd->codec_dai->component;
70
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
8271 int ret = 0;
8372 ret = snd_soc_card_jack_new(rtd->card, "Headset",
8473 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset,
....@@ -95,13 +84,13 @@
9584 struct snd_pcm_hw_params *params)
9685 {
9786 struct snd_interval *rate = hw_param_interval(params,
98
- SNDRV_PCM_HW_PARAM_RATE);
99
- struct snd_interval *channels = hw_param_interval(params,
100
- SNDRV_PCM_HW_PARAM_CHANNELS);
87
+ SNDRV_PCM_HW_PARAM_RATE);
88
+ struct snd_interval *chan = hw_param_interval(params,
89
+ SNDRV_PCM_HW_PARAM_CHANNELS);
10190
10291 /* The ADSP will covert the FE rate to 48k, stereo */
10392 rate->min = rate->max = 48000;
104
- channels->min = channels->max = 2;
93
+ chan->min = chan->max = 2;
10594
10695 /* set SSP0 to 16 bit */
10796 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
....@@ -111,8 +100,8 @@
111100 static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
112101 struct snd_pcm_hw_params *params)
113102 {
114
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
115
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
103
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
104
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
116105 int ret;
117106
118107 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
....@@ -130,24 +119,54 @@
130119 .hw_params = broadwell_rt286_hw_params,
131120 };
132121
133
-static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
122
+static const unsigned int channels[] = {
123
+ 2,
124
+};
125
+
126
+static const struct snd_pcm_hw_constraint_list constraints_channels = {
127
+ .count = ARRAY_SIZE(channels),
128
+ .list = channels,
129
+ .mask = 0,
130
+};
131
+
132
+static int broadwell_fe_startup(struct snd_pcm_substream *substream)
134133 {
135
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
136
- struct sst_pdata *pdata = dev_get_platdata(component->dev);
137
- struct sst_hsw *broadwell = pdata->dsp;
138
- int ret;
134
+ struct snd_pcm_runtime *runtime = substream->runtime;
139135
140
- /* Set ADSP SSP port settings */
141
- ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
142
- SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
143
- SST_HSW_DEVICE_CLOCK_MASTER, 9);
144
- if (ret < 0) {
145
- dev_err(rtd->dev, "error: failed to set device config\n");
146
- return ret;
147
- }
148
-
149
- return 0;
136
+ /* Board supports stereo configuration only */
137
+ runtime->hw.channels_max = 2;
138
+ return snd_pcm_hw_constraint_list(runtime, 0,
139
+ SNDRV_PCM_HW_PARAM_CHANNELS,
140
+ &constraints_channels);
150141 }
142
+
143
+static const struct snd_soc_ops broadwell_fe_ops = {
144
+ .startup = broadwell_fe_startup,
145
+};
146
+
147
+SND_SOC_DAILINK_DEF(system,
148
+ DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
149
+
150
+SND_SOC_DAILINK_DEF(offload0,
151
+ DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin")));
152
+
153
+SND_SOC_DAILINK_DEF(offload1,
154
+ DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin")));
155
+
156
+SND_SOC_DAILINK_DEF(loopback,
157
+ DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin")));
158
+
159
+SND_SOC_DAILINK_DEF(dummy,
160
+ DAILINK_COMP_ARRAY(COMP_DUMMY()));
161
+
162
+SND_SOC_DAILINK_DEF(platform,
163
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio")));
164
+
165
+SND_SOC_DAILINK_DEF(codec,
166
+ DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00", "rt286-aif1")));
167
+
168
+SND_SOC_DAILINK_DEF(ssp0_port,
169
+ DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port")));
151170
152171 /* broadwell digital audio interface glue - connects codec <--> CPU */
153172 static struct snd_soc_dai_link broadwell_rt286_dais[] = {
....@@ -155,75 +174,64 @@
155174 {
156175 .name = "System PCM",
157176 .stream_name = "System Playback/Capture",
158
- .cpu_dai_name = "System Pin",
159
- .platform_name = "haswell-pcm-audio",
177
+ .nonatomic = 1,
160178 .dynamic = 1,
161
- .codec_name = "snd-soc-dummy",
162
- .codec_dai_name = "snd-soc-dummy-dai",
163
- .init = broadwell_rtd_init,
164179 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
180
+ .ops = &broadwell_fe_ops,
165181 .dpcm_playback = 1,
166182 .dpcm_capture = 1,
183
+ SND_SOC_DAILINK_REG(system, dummy, platform),
167184 },
168185 {
169186 .name = "Offload0",
170187 .stream_name = "Offload0 Playback",
171
- .cpu_dai_name = "Offload0 Pin",
172
- .platform_name = "haswell-pcm-audio",
188
+ .nonatomic = 1,
173189 .dynamic = 1,
174
- .codec_name = "snd-soc-dummy",
175
- .codec_dai_name = "snd-soc-dummy-dai",
176190 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
177191 .dpcm_playback = 1,
192
+ SND_SOC_DAILINK_REG(offload0, dummy, platform),
178193 },
179194 {
180195 .name = "Offload1",
181196 .stream_name = "Offload1 Playback",
182
- .cpu_dai_name = "Offload1 Pin",
183
- .platform_name = "haswell-pcm-audio",
197
+ .nonatomic = 1,
184198 .dynamic = 1,
185
- .codec_name = "snd-soc-dummy",
186
- .codec_dai_name = "snd-soc-dummy-dai",
187199 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
188200 .dpcm_playback = 1,
201
+ SND_SOC_DAILINK_REG(offload1, dummy, platform),
189202 },
190203 {
191204 .name = "Loopback PCM",
192205 .stream_name = "Loopback",
193
- .cpu_dai_name = "Loopback Pin",
194
- .platform_name = "haswell-pcm-audio",
206
+ .nonatomic = 1,
195207 .dynamic = 1,
196
- .codec_name = "snd-soc-dummy",
197
- .codec_dai_name = "snd-soc-dummy-dai",
198208 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
199209 .dpcm_capture = 1,
210
+ SND_SOC_DAILINK_REG(loopback, dummy, platform),
200211 },
201212 /* Back End DAI links */
202213 {
203214 /* SSP0 - Codec */
204215 .name = "Codec",
205216 .id = 0,
206
- .cpu_dai_name = "snd-soc-dummy-dai",
207
- .platform_name = "snd-soc-dummy",
208217 .no_pcm = 1,
209
- .codec_name = "i2c-INT343A:00",
210
- .codec_dai_name = "rt286-aif1",
211218 .init = broadwell_rt286_codec_init,
212219 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
213220 SND_SOC_DAIFMT_CBS_CFS,
214
- .ignore_suspend = 1,
215221 .ignore_pmdown_time = 1,
216222 .be_hw_params_fixup = broadwell_ssp0_fixup,
217223 .ops = &broadwell_rt286_ops,
218224 .dpcm_playback = 1,
219225 .dpcm_capture = 1,
226
+ SND_SOC_DAILINK_REG(ssp0_port, codec, platform),
220227 },
221228 };
222229
223
-static int broadwell_suspend(struct snd_soc_card *card){
230
+static int broadwell_disable_jack(struct snd_soc_card *card)
231
+{
224232 struct snd_soc_component *component;
225233
226
- list_for_each_entry(component, &card->component_dev_list, card_list) {
234
+ for_each_card_components(card, component) {
227235 if (!strcmp(component->name, "i2c-INT343A:00")) {
228236
229237 dev_dbg(component->dev, "disabling jack detect before going to suspend.\n");
....@@ -231,13 +239,19 @@
231239 break;
232240 }
233241 }
242
+
234243 return 0;
244
+}
245
+
246
+static int broadwell_suspend(struct snd_soc_card *card)
247
+{
248
+ return broadwell_disable_jack(card);
235249 }
236250
237251 static int broadwell_resume(struct snd_soc_card *card){
238252 struct snd_soc_component *component;
239253
240
- list_for_each_entry(component, &card->component_dev_list, card_list) {
254
+ for_each_card_components(card, component) {
241255 if (!strcmp(component->name, "i2c-INT343A:00")) {
242256
243257 dev_dbg(component->dev, "enabling jack detect for resume.\n");
....@@ -248,9 +262,19 @@
248262 return 0;
249263 }
250264
265
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
266
+/* use space before codec name to simplify card ID, and simplify driver name */
267
+#define CARD_NAME "bdw rt286" /* card name will be 'sof-bdw rt286' */
268
+#define DRIVER_NAME "SOF"
269
+#else
270
+#define CARD_NAME "broadwell-rt286"
271
+#define DRIVER_NAME NULL /* card name will be used for driver name */
272
+#endif
273
+
251274 /* broadwell audio machine driver for WPT + RT286S */
252275 static struct snd_soc_card broadwell_rt286 = {
253
- .name = "broadwell-rt286",
276
+ .name = CARD_NAME,
277
+ .driver_name = DRIVER_NAME,
254278 .owner = THIS_MODULE,
255279 .dai_link = broadwell_rt286_dais,
256280 .num_links = ARRAY_SIZE(broadwell_rt286_dais),
....@@ -267,12 +291,31 @@
267291
268292 static int broadwell_audio_probe(struct platform_device *pdev)
269293 {
294
+ struct snd_soc_acpi_mach *mach;
295
+ int ret;
296
+
270297 broadwell_rt286.dev = &pdev->dev;
298
+
299
+ /* override plaform name, if required */
300
+ mach = pdev->dev.platform_data;
301
+ ret = snd_soc_fixup_dai_links_platform_name(&broadwell_rt286,
302
+ mach->mach_params.platform);
303
+ if (ret)
304
+ return ret;
305
+
271306 return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286);
307
+}
308
+
309
+static int broadwell_audio_remove(struct platform_device *pdev)
310
+{
311
+ struct snd_soc_card *card = platform_get_drvdata(pdev);
312
+
313
+ return broadwell_disable_jack(card);
272314 }
273315
274316 static struct platform_driver broadwell_audio = {
275317 .probe = broadwell_audio_probe,
318
+ .remove = broadwell_audio_remove,
276319 .driver = {
277320 .name = "broadwell-audio",
278321 },