hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/sound/soc/rockchip/rk3399_gru_sound.c
....@@ -1,19 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Rockchip machine ASoC driver for boards using MAX98357A/RT5514/DA7219
34 *
45 * Copyright (c) 2016, ROCKCHIP CORPORATION. All rights reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms and conditions of the GNU General Public License,
8
- * version 2, as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
176 */
187
198 #include <linux/module.h>
....@@ -43,6 +32,19 @@
4332
4433 static struct snd_soc_jack rockchip_sound_jack;
4534
35
+/* Headset jack detection DAPM pins */
36
+static struct snd_soc_jack_pin rockchip_sound_jack_pins[] = {
37
+ {
38
+ .pin = "Headphones",
39
+ .mask = SND_JACK_HEADPHONE,
40
+ },
41
+ {
42
+ .pin = "Headset Mic",
43
+ .mask = SND_JACK_MICROPHONE,
44
+ },
45
+
46
+};
47
+
4648 static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
4749 SND_SOC_DAPM_HP("Headphones", NULL),
4850 SND_SOC_DAPM_SPK("Speakers", NULL),
....@@ -62,25 +64,13 @@
6264 static int rockchip_sound_max98357a_hw_params(struct snd_pcm_substream *substream,
6365 struct snd_pcm_hw_params *params)
6466 {
65
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
67
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
6668 unsigned int mclk;
6769 int ret;
6870
69
- /* max98357a supports these sample rates */
70
- switch (params_rate(params)) {
71
- case 8000:
72
- case 16000:
73
- case 48000:
74
- case 96000:
75
- mclk = params_rate(params) * SOUND_FS;
76
- break;
77
- default:
78
- dev_err(rtd->card->dev, "%s() doesn't support this sample rate: %d\n",
79
- __func__, params_rate(params));
80
- return -EINVAL;
81
- }
71
+ mclk = params_rate(params) * SOUND_FS;
8272
83
- ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, 0, mclk, 0);
73
+ ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, mclk, 0);
8474 if (ret) {
8575 dev_err(rtd->card->dev, "%s() error setting sysclk to %u: %d\n",
8676 __func__, mclk, ret);
....@@ -93,9 +83,9 @@
9383 static int rockchip_sound_rt5514_hw_params(struct snd_pcm_substream *substream,
9484 struct snd_pcm_hw_params *params)
9585 {
96
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
97
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
98
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
86
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
87
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
88
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
9989 unsigned int mclk;
10090 int ret;
10191
....@@ -125,9 +115,9 @@
125115 static int rockchip_sound_da7219_hw_params(struct snd_pcm_substream *substream,
126116 struct snd_pcm_hw_params *params)
127117 {
128
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
129
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
130
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
118
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
119
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
120
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
131121 int mclk, ret;
132122
133123 /* in bypass mode, the mclk has to be one of the frequencies below */
....@@ -176,8 +166,8 @@
176166
177167 static int rockchip_sound_da7219_init(struct snd_soc_pcm_runtime *rtd)
178168 {
179
- struct snd_soc_component *component = rtd->codec_dais[0]->component;
180
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
169
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
170
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
181171 int ret;
182172
183173 /* We need default MCLK and PLL settings for the accessory detection */
....@@ -199,7 +189,9 @@
199189 SND_JACK_HEADSET | SND_JACK_LINEOUT |
200190 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
201191 SND_JACK_BTN_2 | SND_JACK_BTN_3,
202
- &rockchip_sound_jack, NULL, 0);
192
+ &rockchip_sound_jack,
193
+ rockchip_sound_jack_pins,
194
+ ARRAY_SIZE(rockchip_sound_jack_pins));
203195
204196 if (ret) {
205197 dev_err(rtd->card->dev, "New Headset Jack failed! (%d)\n", ret);
....@@ -223,13 +215,13 @@
223215 static int rockchip_sound_dmic_hw_params(struct snd_pcm_substream *substream,
224216 struct snd_pcm_hw_params *params)
225217 {
226
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
218
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
227219 unsigned int mclk;
228220 int ret;
229221
230222 mclk = params_rate(params) * SOUND_FS;
231223
232
- ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, 0, mclk, 0);
224
+ ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 0, mclk, 0);
233225 if (ret) {
234226 dev_err(rtd->card->dev, "%s() error setting sysclk to %u: %d\n",
235227 __func__, mclk, ret);
....@@ -242,19 +234,32 @@
242234 return 0;
243235 }
244236
237
+static int rockchip_sound_startup(struct snd_pcm_substream *substream)
238
+{
239
+ struct snd_pcm_runtime *runtime = substream->runtime;
240
+
241
+ runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
242
+ return snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
243
+ 8000, 96000);
244
+}
245
+
245246 static const struct snd_soc_ops rockchip_sound_max98357a_ops = {
247
+ .startup = rockchip_sound_startup,
246248 .hw_params = rockchip_sound_max98357a_hw_params,
247249 };
248250
249251 static const struct snd_soc_ops rockchip_sound_rt5514_ops = {
252
+ .startup = rockchip_sound_startup,
250253 .hw_params = rockchip_sound_rt5514_hw_params,
251254 };
252255
253256 static const struct snd_soc_ops rockchip_sound_da7219_ops = {
257
+ .startup = rockchip_sound_startup,
254258 .hw_params = rockchip_sound_da7219_hw_params,
255259 };
256260
257261 static const struct snd_soc_ops rockchip_sound_dmic_ops = {
262
+ .startup = rockchip_sound_startup,
258263 .hw_params = rockchip_sound_dmic_hw_params,
259264 };
260265
....@@ -276,56 +281,85 @@
276281 DAILINK_RT5514_DSP,
277282 };
278283
284
+SND_SOC_DAILINK_DEFS(cdndp,
285
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
286
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "spdif-hifi")),
287
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
288
+
289
+SND_SOC_DAILINK_DEFS(da7219,
290
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
291
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "da7219-hifi")),
292
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
293
+
294
+SND_SOC_DAILINK_DEFS(dmic,
295
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
296
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "dmic-hifi")),
297
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
298
+
299
+SND_SOC_DAILINK_DEFS(max98357a,
300
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
301
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")),
302
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
303
+
304
+SND_SOC_DAILINK_DEFS(rt5514,
305
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
306
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5514-aif1")),
307
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
308
+
309
+SND_SOC_DAILINK_DEFS(rt5514_dsp,
310
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
311
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
312
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
313
+
279314 static const struct snd_soc_dai_link rockchip_dais[] = {
280315 [DAILINK_CDNDP] = {
281316 .name = "DP",
282317 .stream_name = "DP PCM",
283
- .codec_dai_name = "spdif-hifi",
284318 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
285319 SND_SOC_DAIFMT_CBS_CFS,
320
+ SND_SOC_DAILINK_REG(cdndp),
286321 },
287322 [DAILINK_DA7219] = {
288323 .name = "DA7219",
289324 .stream_name = "DA7219 PCM",
290
- .codec_dai_name = "da7219-hifi",
291325 .init = rockchip_sound_da7219_init,
292326 .ops = &rockchip_sound_da7219_ops,
293327 /* set da7219 as slave */
294328 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
295329 SND_SOC_DAIFMT_CBS_CFS,
330
+ SND_SOC_DAILINK_REG(da7219),
296331 },
297332 [DAILINK_DMIC] = {
298333 .name = "DMIC",
299334 .stream_name = "DMIC PCM",
300
- .codec_dai_name = "dmic-hifi",
301335 .ops = &rockchip_sound_dmic_ops,
302336 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
303337 SND_SOC_DAIFMT_CBS_CFS,
338
+ SND_SOC_DAILINK_REG(dmic),
304339 },
305340 [DAILINK_MAX98357A] = {
306341 .name = "MAX98357A",
307342 .stream_name = "MAX98357A PCM",
308
- .codec_dai_name = "HiFi",
309343 .ops = &rockchip_sound_max98357a_ops,
310344 /* set max98357a as slave */
311345 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
312346 SND_SOC_DAIFMT_CBS_CFS,
347
+ SND_SOC_DAILINK_REG(max98357a),
313348 },
314349 [DAILINK_RT5514] = {
315350 .name = "RT5514",
316351 .stream_name = "RT5514 PCM",
317
- .codec_dai_name = "rt5514-aif1",
318352 .ops = &rockchip_sound_rt5514_ops,
319353 /* set rt5514 as slave */
320354 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
321355 SND_SOC_DAIFMT_CBS_CFS,
356
+ SND_SOC_DAILINK_REG(rt5514),
322357 },
323358 /* RT5514 DSP for voice wakeup via spi bus */
324359 [DAILINK_RT5514_DSP] = {
325360 .name = "RT5514 DSP",
326361 .stream_name = "Wake on Voice",
327
- .codec_name = "snd-soc-dummy",
328
- .codec_dai_name = "snd-soc-dummy-dai",
362
+ SND_SOC_DAILINK_REG(rt5514_dsp),
329363 },
330364 };
331365
....@@ -416,11 +450,6 @@
416450 },
417451 };
418452
419
-static int of_dev_node_match(struct device *dev, void *data)
420
-{
421
- return dev->of_node == data;
422
-}
423
-
424453 static int rockchip_sound_codec_node_match(struct device_node *np_codec)
425454 {
426455 struct device *dev;
....@@ -432,8 +461,8 @@
432461 continue;
433462
434463 if (dailink_match[i].bus_type) {
435
- dev = bus_find_device(dailink_match[i].bus_type, NULL,
436
- np_codec, of_dev_node_match);
464
+ dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
465
+ np_codec);
437466 if (!dev)
438467 continue;
439468 put_device(dev);
....@@ -507,10 +536,10 @@
507536 dai = &card->dai_link[card->num_links++];
508537 *dai = rockchip_dais[index];
509538
510
- if (!dai->codec_name)
511
- dai->codec_of_node = np_codec;
512
- dai->platform_of_node = np_cpu;
513
- dai->cpu_of_node = np_cpu;
539
+ if (!dai->codecs->name)
540
+ dai->codecs->of_node = np_codec;
541
+ dai->platforms->of_node = np_cpu;
542
+ dai->cpus->of_node = np_cpu;
514543
515544 if (card->num_dapm_routes + rockchip_routes[index].num_routes >
516545 num_routes) {