forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/mediatek/mt2701/mt2701-wm8960.c
....@@ -24,9 +24,9 @@
2424 static int mt2701_wm8960_be_ops_hw_params(struct snd_pcm_substream *substream,
2525 struct snd_pcm_hw_params *params)
2626 {
27
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
28
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
29
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
27
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
28
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
29
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
3030 unsigned int mclk_rate;
3131 unsigned int rate = params_rate(params);
3232 unsigned int div_mclk_over_bck = rate > 192000 ? 2 : 4;
....@@ -44,41 +44,51 @@
4444 .hw_params = mt2701_wm8960_be_ops_hw_params
4545 };
4646
47
+SND_SOC_DAILINK_DEFS(playback,
48
+ DAILINK_COMP_ARRAY(COMP_CPU("PCMO0")),
49
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
50
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
51
+
52
+SND_SOC_DAILINK_DEFS(capture,
53
+ DAILINK_COMP_ARRAY(COMP_CPU("PCM0")),
54
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
55
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
56
+
57
+SND_SOC_DAILINK_DEFS(codec,
58
+ DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
59
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8960-hifi")),
60
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
61
+
4762 static struct snd_soc_dai_link mt2701_wm8960_dai_links[] = {
4863 /* FE */
4964 {
5065 .name = "wm8960-playback",
5166 .stream_name = "wm8960-playback",
52
- .cpu_dai_name = "PCMO0",
53
- .codec_name = "snd-soc-dummy",
54
- .codec_dai_name = "snd-soc-dummy-dai",
5567 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
5668 SND_SOC_DPCM_TRIGGER_POST},
5769 .dynamic = 1,
5870 .dpcm_playback = 1,
71
+ SND_SOC_DAILINK_REG(playback),
5972 },
6073 {
6174 .name = "wm8960-capture",
6275 .stream_name = "wm8960-capture",
63
- .cpu_dai_name = "PCM0",
64
- .codec_name = "snd-soc-dummy",
65
- .codec_dai_name = "snd-soc-dummy-dai",
6676 .trigger = {SND_SOC_DPCM_TRIGGER_POST,
6777 SND_SOC_DPCM_TRIGGER_POST},
6878 .dynamic = 1,
6979 .dpcm_capture = 1,
80
+ SND_SOC_DAILINK_REG(capture),
7081 },
7182 /* BE */
7283 {
7384 .name = "wm8960-codec",
74
- .cpu_dai_name = "I2S0",
7585 .no_pcm = 1,
76
- .codec_dai_name = "wm8960-hifi",
7786 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS
7887 | SND_SOC_DAIFMT_GATED,
7988 .ops = &mt2701_wm8960_be_ops,
8089 .dpcm_playback = 1,
8190 .dpcm_capture = 1,
91
+ SND_SOC_DAILINK_REG(codec),
8292 },
8393 };
8494
....@@ -97,6 +107,7 @@
97107 {
98108 struct snd_soc_card *card = &mt2701_wm8960_card;
99109 struct device_node *platform_node, *codec_node;
110
+ struct snd_soc_dai_link *dai_link;
100111 int ret, i;
101112
102113 platform_node = of_parse_phandle(pdev->dev.of_node,
....@@ -105,10 +116,10 @@
105116 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
106117 return -EINVAL;
107118 }
108
- for (i = 0; i < card->num_links; i++) {
109
- if (mt2701_wm8960_dai_links[i].platform_name)
119
+ for_each_card_prelinks(card, i, dai_link) {
120
+ if (dai_link->platforms->name)
110121 continue;
111
- mt2701_wm8960_dai_links[i].platform_of_node = platform_node;
122
+ dai_link->platforms->of_node = platform_node;
112123 }
113124
114125 card->dev = &pdev->dev;
....@@ -118,18 +129,19 @@
118129 if (!codec_node) {
119130 dev_err(&pdev->dev,
120131 "Property 'audio-codec' missing or invalid\n");
121
- return -EINVAL;
132
+ ret = -EINVAL;
133
+ goto put_platform_node;
122134 }
123
- for (i = 0; i < card->num_links; i++) {
124
- if (mt2701_wm8960_dai_links[i].codec_name)
135
+ for_each_card_prelinks(card, i, dai_link) {
136
+ if (dai_link->codecs->name)
125137 continue;
126
- mt2701_wm8960_dai_links[i].codec_of_node = codec_node;
138
+ dai_link->codecs->of_node = codec_node;
127139 }
128140
129141 ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
130142 if (ret) {
131143 dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
132
- return ret;
144
+ goto put_codec_node;
133145 }
134146
135147 ret = devm_snd_soc_register_card(&pdev->dev, card);
....@@ -137,6 +149,10 @@
137149 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
138150 __func__, ret);
139151
152
+put_codec_node:
153
+ of_node_put(codec_node);
154
+put_platform_node:
155
+ of_node_put(platform_node);
140156 return ret;
141157 }
142158
....@@ -150,7 +166,6 @@
150166 static struct platform_driver mt2701_wm8960_machine = {
151167 .driver = {
152168 .name = "mt2701-wm8960",
153
- .owner = THIS_MODULE,
154169 #ifdef CONFIG_OF
155170 .of_match_table = mt2701_wm8960_machine_dt_match,
156171 #endif