hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/samsung/tm2_wm5110.c
....@@ -1,14 +1,9 @@
1
-/*
2
- * Copyright (C) 2015 - 2016 Samsung Electronics Co., Ltd.
3
- *
4
- * Authors: Inha Song <ideal.song@samsung.com>
5
- * Sylwester Nawrocki <s.nawrocki@samsung.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the
9
- * Free Software Foundation; either version 2 of the License, or (at your
10
- * option) any later version.
11
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// Copyright (C) 2015 - 2016 Samsung Electronics Co., Ltd.
4
+//
5
+// Authors: Inha Song <ideal.song@samsung.com>
6
+// Sylwester Nawrocki <s.nawrocki@samsung.com>
127
138 #include <linux/clk.h>
149 #include <linux/gpio.h>
....@@ -97,8 +92,8 @@
9792 static int tm2_aif1_hw_params(struct snd_pcm_substream *substream,
9893 struct snd_pcm_hw_params *params)
9994 {
100
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
101
- struct snd_soc_component *component = rtd->codec_dai->component;
95
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
96
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
10297 struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(rtd->card);
10398
10499 switch (params_rate(params)) {
....@@ -138,8 +133,8 @@
138133 static int tm2_aif2_hw_params(struct snd_pcm_substream *substream,
139134 struct snd_pcm_hw_params *params)
140135 {
141
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
142
- struct snd_soc_component *component = rtd->codec_dai->component;
136
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
137
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
143138 unsigned int asyncclk_rate;
144139 int ret;
145140
....@@ -192,8 +187,8 @@
192187
193188 static int tm2_aif2_hw_free(struct snd_pcm_substream *substream)
194189 {
195
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
196
- struct snd_soc_component *component = rtd->codec_dai->component;
190
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
191
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
197192 int ret;
198193
199194 /* disable FLL2 */
....@@ -213,8 +208,8 @@
213208 static int tm2_hdmi_hw_params(struct snd_pcm_substream *substream,
214209 struct snd_pcm_hw_params *params)
215210 {
216
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
217
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
211
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
212
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
218213 unsigned int bfs;
219214 int bitwidth, ret;
220215
....@@ -287,9 +282,9 @@
287282 {
288283 struct snd_soc_pcm_runtime *rtd;
289284
290
- rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
285
+ rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
291286
292
- if (dapm->dev != rtd->codec_dai->dev)
287
+ if (dapm->dev != asoc_rtd_to_codec(rtd, 0)->dev)
293288 return 0;
294289
295290 switch (level) {
....@@ -312,7 +307,6 @@
312307 static int tm2_late_probe(struct snd_soc_card *card)
313308 {
314309 struct tm2_machine_priv *priv = snd_soc_card_get_drvdata(card);
315
- struct snd_soc_dai_link_component dlc = { 0 };
316310 unsigned int ch_map[] = { 0, 1 };
317311 struct snd_soc_dai *amp_pdm_dai;
318312 struct snd_soc_pcm_runtime *rtd;
....@@ -320,9 +314,9 @@
320314 struct snd_soc_dai *aif2_dai;
321315 int ret;
322316
323
- rtd = snd_soc_get_pcm_runtime(card, card->dai_link[TM2_DAI_AIF1].name);
324
- aif1_dai = rtd->codec_dai;
325
- priv->component = rtd->codec_dai->component;
317
+ rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[TM2_DAI_AIF1]);
318
+ aif1_dai = asoc_rtd_to_codec(rtd, 0);
319
+ priv->component = asoc_rtd_to_codec(rtd, 0)->component;
326320
327321 ret = snd_soc_dai_set_sysclk(aif1_dai, ARIZONA_CLK_SYSCLK, 0, 0);
328322 if (ret < 0) {
....@@ -330,8 +324,8 @@
330324 return ret;
331325 }
332326
333
- rtd = snd_soc_get_pcm_runtime(card, card->dai_link[TM2_DAI_AIF2].name);
334
- aif2_dai = rtd->codec_dai;
327
+ rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[TM2_DAI_AIF2]);
328
+ aif2_dai = asoc_rtd_to_codec(rtd, 0);
335329
336330 ret = snd_soc_dai_set_sysclk(aif2_dai, ARIZONA_CLK_ASYNCCLK, 0, 0);
337331 if (ret < 0) {
....@@ -339,8 +333,7 @@
339333 return ret;
340334 }
341335
342
- dlc.of_node = tm2_speaker_amp_dev.codec_of_node;
343
- amp_pdm_dai = snd_soc_find_dai(&dlc);
336
+ amp_pdm_dai = snd_soc_find_dai(&tm2_speaker_amp_dev.dlc);
344337 if (!amp_pdm_dai)
345338 return -ENODEV;
346339
....@@ -432,38 +425,56 @@
432425 },
433426 };
434427
428
+SND_SOC_DAILINK_DEFS(aif1,
429
+ DAILINK_COMP_ARRAY(COMP_CPU(SAMSUNG_I2S_DAI)),
430
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm5110-aif1")),
431
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
432
+
433
+SND_SOC_DAILINK_DEFS(voice,
434
+ DAILINK_COMP_ARRAY(COMP_CPU(SAMSUNG_I2S_DAI)),
435
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm5110-aif2")),
436
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
437
+
438
+SND_SOC_DAILINK_DEFS(bt,
439
+ DAILINK_COMP_ARRAY(COMP_CPU(SAMSUNG_I2S_DAI)),
440
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm5110-aif3")),
441
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
442
+
443
+SND_SOC_DAILINK_DEFS(hdmi,
444
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
445
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
446
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
447
+
435448 static struct snd_soc_dai_link tm2_dai_links[] = {
436449 {
437450 .name = "WM5110 AIF1",
438451 .stream_name = "HiFi Primary",
439
- .cpu_dai_name = SAMSUNG_I2S_DAI,
440
- .codec_dai_name = "wm5110-aif1",
441452 .ops = &tm2_aif1_ops,
442453 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
443454 SND_SOC_DAIFMT_CBM_CFM,
455
+ SND_SOC_DAILINK_REG(aif1),
444456 }, {
445457 .name = "WM5110 Voice",
446458 .stream_name = "Voice call",
447
- .cpu_dai_name = SAMSUNG_I2S_DAI,
448
- .codec_dai_name = "wm5110-aif2",
449459 .ops = &tm2_aif2_ops,
450460 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
451461 SND_SOC_DAIFMT_CBM_CFM,
452462 .ignore_suspend = 1,
463
+ SND_SOC_DAILINK_REG(voice),
453464 }, {
454465 .name = "WM5110 BT",
455466 .stream_name = "Bluetooth",
456
- .cpu_dai_name = SAMSUNG_I2S_DAI,
457
- .codec_dai_name = "wm5110-aif3",
458467 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
459468 SND_SOC_DAIFMT_CBM_CFM,
460469 .ignore_suspend = 1,
470
+ SND_SOC_DAILINK_REG(bt),
461471 }, {
462472 .name = "HDMI",
463473 .stream_name = "i2s1",
464474 .ops = &tm2_hdmi_ops,
465475 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
466476 SND_SOC_DAIFMT_CBS_CFS,
477
+ SND_SOC_DAILINK_REG(hdmi),
467478 }
468479 };
469480
....@@ -491,6 +502,7 @@
491502 struct snd_soc_card *card = &tm2_card;
492503 struct tm2_machine_priv *priv;
493504 struct of_phandle_args args;
505
+ struct snd_soc_dai_link *dai_link;
494506 int num_codecs, ret, i;
495507
496508 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
....@@ -518,9 +530,9 @@
518530 return ret;
519531 }
520532
521
- card->aux_dev[0].codec_of_node = of_parse_phandle(dev->of_node,
533
+ card->aux_dev[0].dlc.of_node = of_parse_phandle(dev->of_node,
522534 "audio-amplifier", 0);
523
- if (!card->aux_dev[0].codec_of_node) {
535
+ if (!card->aux_dev[0].dlc.of_node) {
524536 dev_err(dev, "audio-amplifier property invalid or missing\n");
525537 return -EINVAL;
526538 }
....@@ -558,18 +570,18 @@
558570 }
559571
560572 /* Initialize WM5110 - I2S and HDMI - I2S1 DAI links */
561
- for (i = 0; i < card->num_links; i++) {
573
+ for_each_card_prelinks(card, i, dai_link) {
562574 unsigned int dai_index = 0; /* WM5110 */
563575
564
- card->dai_link[i].cpu_name = NULL;
565
- card->dai_link[i].platform_name = NULL;
576
+ dai_link->cpus->name = NULL;
577
+ dai_link->platforms->name = NULL;
566578
567579 if (num_codecs > 1 && i == card->num_links - 1)
568580 dai_index = 1; /* HDMI */
569581
570
- card->dai_link[i].codec_of_node = codec_dai_node[dai_index];
571
- card->dai_link[i].cpu_of_node = cpu_dai_node[dai_index];
572
- card->dai_link[i].platform_of_node = cpu_dai_node[dai_index];
582
+ dai_link->codecs->of_node = codec_dai_node[dai_index];
583
+ dai_link->cpus->of_node = cpu_dai_node[dai_index];
584
+ dai_link->platforms->of_node = cpu_dai_node[dai_index];
573585 }
574586
575587 if (num_codecs > 1) {
....@@ -583,7 +595,7 @@
583595 goto dai_node_put;
584596 }
585597
586
- ret = snd_soc_get_dai_name(&args, &card->dai_link[i].codec_dai_name);
598
+ ret = snd_soc_get_dai_name(&args, &card->dai_link[i].codecs->dai_name);
587599 if (ret) {
588600 dev_err(dev, "Unable to get codec_dai_name\n");
589601 goto dai_node_put;
....@@ -599,7 +611,7 @@
599611
600612 ret = devm_snd_soc_register_card(dev, card);
601613 if (ret < 0) {
602
- dev_err(dev, "Failed to register card: %d\n", ret);
614
+ dev_err_probe(dev, ret, "Failed to register card\n");
603615 goto dai_node_put;
604616 }
605617
....@@ -609,7 +621,7 @@
609621 of_node_put(cpu_dai_node[i]);
610622 }
611623
612
- of_node_put(card->aux_dev[0].codec_of_node);
624
+ of_node_put(card->aux_dev[0].dlc.of_node);
613625
614626 return ret;
615627 }