hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/sound/soc/amd/acp-da7219-max98357a.c
....@@ -46,14 +46,15 @@
4646 #define DUAL_CHANNEL 2
4747
4848 static struct snd_soc_jack cz_jack;
49
-static struct clk *da7219_dai_clk;
50
-extern int bt_uart_enable;
49
+static struct clk *da7219_dai_wclk;
50
+static struct clk *da7219_dai_bclk;
51
+extern bool bt_uart_enable;
5152
5253 static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd)
5354 {
5455 int ret;
5556 struct snd_soc_card *card = rtd->card;
56
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
57
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
5758 struct snd_soc_component *component = codec_dai->component;
5859
5960 dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
....@@ -72,10 +73,16 @@
7273 return ret;
7374 }
7475
75
- da7219_dai_clk = clk_get(component->dev, "da7219-dai-clks");
76
+ da7219_dai_wclk = devm_clk_get(component->dev, "da7219-dai-wclk");
77
+ if (IS_ERR(da7219_dai_wclk))
78
+ return PTR_ERR(da7219_dai_wclk);
79
+
80
+ da7219_dai_bclk = devm_clk_get(component->dev, "da7219-dai-bclk");
81
+ if (IS_ERR(da7219_dai_bclk))
82
+ return PTR_ERR(da7219_dai_bclk);
7683
7784 ret = snd_soc_card_jack_new(card, "Headset Jack",
78
- SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
85
+ SND_JACK_HEADSET | SND_JACK_LINEOUT |
7986 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
8087 SND_JACK_BTN_2 | SND_JACK_BTN_3,
8188 &cz_jack, NULL, 0);
....@@ -97,9 +104,17 @@
97104 static int da7219_clk_enable(struct snd_pcm_substream *substream)
98105 {
99106 int ret = 0;
100
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
107
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
101108
102
- ret = clk_prepare_enable(da7219_dai_clk);
109
+ /*
110
+ * Set wclk to 48000 because the rate constraint of this driver is
111
+ * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
112
+ * minimum of 64x the LRCLK sample rate." DA7219 is the only clk
113
+ * source so for all codecs we have to limit bclk to 64X lrclk.
114
+ */
115
+ clk_set_rate(da7219_dai_wclk, 48000);
116
+ clk_set_rate(da7219_dai_bclk, 48000 * 64);
117
+ ret = clk_prepare_enable(da7219_dai_bclk);
103118 if (ret < 0) {
104119 dev_err(rtd->dev, "can't enable master clock %d\n", ret);
105120 return ret;
....@@ -110,7 +125,7 @@
110125
111126 static void da7219_clk_disable(void)
112127 {
113
- clk_disable_unprepare(da7219_dai_clk);
128
+ clk_disable_unprepare(da7219_dai_bclk);
114129 }
115130
116131 static const unsigned int channels[] = {
....@@ -133,10 +148,10 @@
133148 .mask = 0,
134149 };
135150
136
-static int cz_da7219_startup(struct snd_pcm_substream *substream)
151
+static int cz_da7219_play_startup(struct snd_pcm_substream *substream)
137152 {
138153 struct snd_pcm_runtime *runtime = substream->runtime;
139
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
154
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
140155 struct snd_soc_card *card = rtd->card;
141156 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
142157
....@@ -150,8 +165,93 @@
150165 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
151166 &constraints_rates);
152167
153
- machine->i2s_instance = I2S_SP_INSTANCE;
168
+ machine->play_i2s_instance = I2S_SP_INSTANCE;
169
+ return da7219_clk_enable(substream);
170
+}
171
+
172
+static int cz_da7219_cap_startup(struct snd_pcm_substream *substream)
173
+{
174
+ struct snd_pcm_runtime *runtime = substream->runtime;
175
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
176
+ struct snd_soc_card *card = rtd->card;
177
+ struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
178
+
179
+ /*
180
+ * On this platform for PCM device we support stereo
181
+ */
182
+
183
+ runtime->hw.channels_max = DUAL_CHANNEL;
184
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
185
+ &constraints_channels);
186
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
187
+ &constraints_rates);
188
+
189
+ machine->cap_i2s_instance = I2S_SP_INSTANCE;
154190 machine->capture_channel = CAP_CHANNEL1;
191
+ return da7219_clk_enable(substream);
192
+}
193
+
194
+static int cz_max_startup(struct snd_pcm_substream *substream)
195
+{
196
+ struct snd_pcm_runtime *runtime = substream->runtime;
197
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
198
+ struct snd_soc_card *card = rtd->card;
199
+ struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
200
+
201
+ /*
202
+ * On this platform for PCM device we support stereo
203
+ */
204
+
205
+ runtime->hw.channels_max = DUAL_CHANNEL;
206
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
207
+ &constraints_channels);
208
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
209
+ &constraints_rates);
210
+
211
+ machine->play_i2s_instance = I2S_BT_INSTANCE;
212
+ return da7219_clk_enable(substream);
213
+}
214
+
215
+static int cz_dmic0_startup(struct snd_pcm_substream *substream)
216
+{
217
+ struct snd_pcm_runtime *runtime = substream->runtime;
218
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
219
+ struct snd_soc_card *card = rtd->card;
220
+ struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
221
+
222
+ /*
223
+ * On this platform for PCM device we support stereo
224
+ */
225
+
226
+ runtime->hw.channels_max = DUAL_CHANNEL;
227
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
228
+ &constraints_channels);
229
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
230
+ &constraints_rates);
231
+
232
+ machine->cap_i2s_instance = I2S_BT_INSTANCE;
233
+ return da7219_clk_enable(substream);
234
+}
235
+
236
+static int cz_dmic1_startup(struct snd_pcm_substream *substream)
237
+{
238
+ struct snd_pcm_runtime *runtime = substream->runtime;
239
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
240
+ struct snd_soc_card *card = rtd->card;
241
+ struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
242
+
243
+ /*
244
+ * On this platform for PCM device we support stereo
245
+ */
246
+
247
+ runtime->hw.channels_max = DUAL_CHANNEL;
248
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
249
+ &constraints_channels);
250
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
251
+ &constraints_rates);
252
+
253
+ machine->cap_i2s_instance = I2S_SP_INSTANCE;
254
+ machine->capture_channel = CAP_CHANNEL0;
155255 return da7219_clk_enable(substream);
156256 }
157257
....@@ -160,130 +260,96 @@
160260 da7219_clk_disable();
161261 }
162262
163
-static int cz_max_startup(struct snd_pcm_substream *substream)
164
-{
165
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
166
- struct snd_soc_card *card = rtd->card;
167
- struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
168
-
169
- machine->i2s_instance = I2S_BT_INSTANCE;
170
- return da7219_clk_enable(substream);
171
-}
172
-
173
-static void cz_max_shutdown(struct snd_pcm_substream *substream)
174
-{
175
- da7219_clk_disable();
176
-}
177
-
178
-static int cz_dmic0_startup(struct snd_pcm_substream *substream)
179
-{
180
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
181
- struct snd_soc_card *card = rtd->card;
182
- struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
183
-
184
- machine->i2s_instance = I2S_BT_INSTANCE;
185
- return da7219_clk_enable(substream);
186
-}
187
-
188
-static int cz_dmic1_startup(struct snd_pcm_substream *substream)
189
-{
190
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
191
- struct snd_soc_card *card = rtd->card;
192
- struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
193
-
194
- machine->i2s_instance = I2S_SP_INSTANCE;
195
- machine->capture_channel = CAP_CHANNEL0;
196
- return da7219_clk_enable(substream);
197
-}
198
-
199
-static void cz_dmic_shutdown(struct snd_pcm_substream *substream)
200
-{
201
- da7219_clk_disable();
202
-}
263
+static const struct snd_soc_ops cz_da7219_play_ops = {
264
+ .startup = cz_da7219_play_startup,
265
+ .shutdown = cz_da7219_shutdown,
266
+};
203267
204268 static const struct snd_soc_ops cz_da7219_cap_ops = {
205
- .startup = cz_da7219_startup,
269
+ .startup = cz_da7219_cap_startup,
206270 .shutdown = cz_da7219_shutdown,
207271 };
208272
209273 static const struct snd_soc_ops cz_max_play_ops = {
210274 .startup = cz_max_startup,
211
- .shutdown = cz_max_shutdown,
275
+ .shutdown = cz_da7219_shutdown,
212276 };
213277
214278 static const struct snd_soc_ops cz_dmic0_cap_ops = {
215279 .startup = cz_dmic0_startup,
216
- .shutdown = cz_dmic_shutdown,
280
+ .shutdown = cz_da7219_shutdown,
217281 };
218282
219283 static const struct snd_soc_ops cz_dmic1_cap_ops = {
220284 .startup = cz_dmic1_startup,
221
- .shutdown = cz_dmic_shutdown,
285
+ .shutdown = cz_da7219_shutdown,
222286 };
287
+
288
+SND_SOC_DAILINK_DEF(designware1,
289
+ DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto")));
290
+SND_SOC_DAILINK_DEF(designware2,
291
+ DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto")));
292
+SND_SOC_DAILINK_DEF(designware3,
293
+ DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto")));
294
+
295
+SND_SOC_DAILINK_DEF(dlgs,
296
+ DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi")));
297
+SND_SOC_DAILINK_DEF(mx,
298
+ DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi")));
299
+SND_SOC_DAILINK_DEF(adau,
300
+ DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi")));
301
+
302
+SND_SOC_DAILINK_DEF(platform,
303
+ DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto")));
223304
224305 static struct snd_soc_dai_link cz_dai_7219_98357[] = {
225306 {
226307 .name = "amd-da7219-play",
227308 .stream_name = "Playback",
228
- .platform_name = "acp_audio_dma.0.auto",
229
- .cpu_dai_name = "designware-i2s.1.auto",
230
- .codec_dai_name = "da7219-hifi",
231
- .codec_name = "i2c-DLGS7219:00",
232309 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
233310 | SND_SOC_DAIFMT_CBM_CFM,
234311 .init = cz_da7219_init,
235312 .dpcm_playback = 1,
236
- .ops = &cz_da7219_cap_ops,
313
+ .ops = &cz_da7219_play_ops,
314
+ SND_SOC_DAILINK_REG(designware1, dlgs, platform),
237315 },
238316 {
239317 .name = "amd-da7219-cap",
240318 .stream_name = "Capture",
241
- .platform_name = "acp_audio_dma.0.auto",
242
- .cpu_dai_name = "designware-i2s.2.auto",
243
- .codec_dai_name = "da7219-hifi",
244
- .codec_name = "i2c-DLGS7219:00",
245319 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
246320 | SND_SOC_DAIFMT_CBM_CFM,
247321 .dpcm_capture = 1,
248322 .ops = &cz_da7219_cap_ops,
323
+ SND_SOC_DAILINK_REG(designware2, dlgs, platform),
249324 },
250325 {
251326 .name = "amd-max98357-play",
252327 .stream_name = "HiFi Playback",
253
- .platform_name = "acp_audio_dma.0.auto",
254
- .cpu_dai_name = "designware-i2s.3.auto",
255
- .codec_dai_name = "HiFi",
256
- .codec_name = "MX98357A:00",
257328 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
258329 | SND_SOC_DAIFMT_CBM_CFM,
259330 .dpcm_playback = 1,
260331 .ops = &cz_max_play_ops,
332
+ SND_SOC_DAILINK_REG(designware3, mx, platform),
261333 },
262334 {
263335 /* C panel DMIC */
264336 .name = "dmic0",
265337 .stream_name = "DMIC0 Capture",
266
- .platform_name = "acp_audio_dma.0.auto",
267
- .cpu_dai_name = "designware-i2s.3.auto",
268
- .codec_dai_name = "adau7002-hifi",
269
- .codec_name = "ADAU7002:00",
270338 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
271339 | SND_SOC_DAIFMT_CBM_CFM,
272340 .dpcm_capture = 1,
273341 .ops = &cz_dmic0_cap_ops,
342
+ SND_SOC_DAILINK_REG(designware3, adau, platform),
274343 },
275344 {
276345 /* A/B panel DMIC */
277346 .name = "dmic1",
278347 .stream_name = "DMIC1 Capture",
279
- .platform_name = "acp_audio_dma.0.auto",
280
- .cpu_dai_name = "designware-i2s.2.auto",
281
- .codec_dai_name = "adau7002-hifi",
282
- .codec_name = "ADAU7002:00",
283348 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
284349 | SND_SOC_DAIFMT_CBM_CFM,
285350 .dpcm_capture = 1,
286351 .ops = &cz_dmic1_cap_ops,
352
+ SND_SOC_DAILINK_REG(designware2, adau, platform),
287353 },
288354 };
289355
....@@ -344,7 +410,7 @@
344410 static struct regulator_ops acp_da7219_ops = {
345411 };
346412
347
-static struct regulator_desc acp_da7219_desc = {
413
+static const struct regulator_desc acp_da7219_desc = {
348414 .name = "reg-fixed-1.8V",
349415 .type = REGULATOR_VOLTAGE,
350416 .owner = THIS_MODULE,
....@@ -389,11 +455,13 @@
389455 return 0;
390456 }
391457
458
+#ifdef CONFIG_ACPI
392459 static const struct acpi_device_id cz_audio_acpi_match[] = {
393460 { "AMD7219", 0 },
394461 {},
395462 };
396463 MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match);
464
+#endif
397465
398466 static struct platform_driver cz_pcm_driver = {
399467 .driver = {