forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/sound/soc/mediatek/mt8173/mt8173-rt5650.c
....@@ -57,8 +57,9 @@
5757 static int mt8173_rt5650_hw_params(struct snd_pcm_substream *substream,
5858 struct snd_pcm_hw_params *params)
5959 {
60
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
60
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
6161 unsigned int mclk_clock;
62
+ struct snd_soc_dai *codec_dai;
6263 int i, ret;
6364
6465 switch (mt8173_rt5650_priv.pll_from) {
....@@ -76,9 +77,7 @@
7677 break;
7778 }
7879
79
- for (i = 0; i < rtd->num_codecs; i++) {
80
- struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
81
-
80
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
8281 /* pll from mclk */
8382 ret = snd_soc_dai_set_pll(codec_dai, 0, 0, mclk_clock,
8483 params_rate(params) * 512);
....@@ -99,13 +98,13 @@
9998 .hw_params = mt8173_rt5650_hw_params,
10099 };
101100
102
-static struct snd_soc_jack mt8173_rt5650_jack;
101
+static struct snd_soc_jack mt8173_rt5650_jack, mt8173_rt5650_hdmi_jack;
103102
104103 static int mt8173_rt5650_init(struct snd_soc_pcm_runtime *runtime)
105104 {
106105 struct snd_soc_card *card = runtime->card;
107
- struct snd_soc_component *component = runtime->codec_dais[0]->component;
108
- const char *codec_capture_dai = runtime->codec_dais[1]->name;
106
+ struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
107
+ const char *codec_capture_dai = asoc_rtd_to_codec(runtime, 1)->name;
109108 int ret;
110109
111110 rt5645_sel_asrc_clk_src(component,
....@@ -145,16 +144,18 @@
145144 &mt8173_rt5650_jack);
146145 }
147146
148
-static struct snd_soc_dai_link_component mt8173_rt5650_codecs[] = {
149
- {
150
- /* Playback */
151
- .dai_name = "rt5645-aif1",
152
- },
153
- {
154
- /* Capture */
155
- .dai_name = "rt5645-aif1",
156
- },
157
-};
147
+static int mt8173_rt5650_hdmi_init(struct snd_soc_pcm_runtime *rtd)
148
+{
149
+ int ret;
150
+
151
+ ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
152
+ &mt8173_rt5650_hdmi_jack, NULL, 0);
153
+ if (ret)
154
+ return ret;
155
+
156
+ return snd_soc_component_set_jack(asoc_rtd_to_codec(rtd, 0)->component,
157
+ &mt8173_rt5650_hdmi_jack, NULL);
158
+}
158159
159160 enum {
160161 DAI_LINK_PLAYBACK,
....@@ -164,46 +165,63 @@
164165 DAI_LINK_HDMI_I2S,
165166 };
166167
168
+SND_SOC_DAILINK_DEFS(playback,
169
+ DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
170
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
171
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
172
+
173
+SND_SOC_DAILINK_DEFS(capture,
174
+ DAILINK_COMP_ARRAY(COMP_CPU("VUL")),
175
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
176
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
177
+
178
+SND_SOC_DAILINK_DEFS(hdmi_pcm,
179
+ DAILINK_COMP_ARRAY(COMP_CPU("HDMI")),
180
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
181
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
182
+
183
+SND_SOC_DAILINK_DEFS(codec,
184
+ DAILINK_COMP_ARRAY(COMP_CPU("I2S")),
185
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5645-aif1"), /* Playback */
186
+ COMP_CODEC(NULL, "rt5645-aif1")),/* Capture */
187
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
188
+
189
+SND_SOC_DAILINK_DEFS(hdmi_be,
190
+ DAILINK_COMP_ARRAY(COMP_CPU("HDMIO")),
191
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
192
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
193
+
167194 /* Digital audio interface glue - connects codec <---> CPU */
168195 static struct snd_soc_dai_link mt8173_rt5650_dais[] = {
169196 /* Front End DAI links */
170197 [DAI_LINK_PLAYBACK] = {
171198 .name = "rt5650 Playback",
172199 .stream_name = "rt5650 Playback",
173
- .cpu_dai_name = "DL1",
174
- .codec_name = "snd-soc-dummy",
175
- .codec_dai_name = "snd-soc-dummy-dai",
176200 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
177201 .dynamic = 1,
178202 .dpcm_playback = 1,
203
+ SND_SOC_DAILINK_REG(playback),
179204 },
180205 [DAI_LINK_CAPTURE] = {
181206 .name = "rt5650 Capture",
182207 .stream_name = "rt5650 Capture",
183
- .cpu_dai_name = "VUL",
184
- .codec_name = "snd-soc-dummy",
185
- .codec_dai_name = "snd-soc-dummy-dai",
186208 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
187209 .dynamic = 1,
188210 .dpcm_capture = 1,
211
+ SND_SOC_DAILINK_REG(capture),
189212 },
190213 [DAI_LINK_HDMI] = {
191214 .name = "HDMI",
192215 .stream_name = "HDMI PCM",
193
- .cpu_dai_name = "HDMI",
194
- .codec_name = "snd-soc-dummy",
195
- .codec_dai_name = "snd-soc-dummy-dai",
196216 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
197217 .dynamic = 1,
198218 .dpcm_playback = 1,
219
+ SND_SOC_DAILINK_REG(hdmi_pcm),
199220 },
200221 /* Back End DAI links */
201222 [DAI_LINK_CODEC_I2S] = {
202223 .name = "Codec",
203
- .cpu_dai_name = "I2S",
204224 .no_pcm = 1,
205
- .codecs = mt8173_rt5650_codecs,
206
- .num_codecs = 2,
207225 .init = mt8173_rt5650_init,
208226 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
209227 SND_SOC_DAIFMT_CBS_CFS,
....@@ -211,13 +229,14 @@
211229 .ignore_pmdown_time = 1,
212230 .dpcm_playback = 1,
213231 .dpcm_capture = 1,
232
+ SND_SOC_DAILINK_REG(codec),
214233 },
215234 [DAI_LINK_HDMI_I2S] = {
216235 .name = "HDMI BE",
217
- .cpu_dai_name = "HDMIO",
218236 .no_pcm = 1,
219
- .codec_dai_name = "i2s-hifi",
220237 .dpcm_playback = 1,
238
+ .init = mt8173_rt5650_hdmi_init,
239
+ SND_SOC_DAILINK_REG(hdmi_be),
221240 },
222241 };
223242
....@@ -240,6 +259,7 @@
240259 struct device_node *platform_node;
241260 struct device_node *np;
242261 const char *codec_capture_dai;
262
+ struct snd_soc_dai_link *dai_link;
243263 int i, ret;
244264
245265 platform_node = of_parse_phandle(pdev->dev.of_node,
....@@ -249,20 +269,22 @@
249269 return -EINVAL;
250270 }
251271
252
- for (i = 0; i < card->num_links; i++) {
253
- if (mt8173_rt5650_dais[i].platform_name)
272
+ for_each_card_prelinks(card, i, dai_link) {
273
+ if (dai_link->platforms->name)
254274 continue;
255
- mt8173_rt5650_dais[i].platform_of_node = platform_node;
275
+ dai_link->platforms->of_node = platform_node;
256276 }
257277
258
- mt8173_rt5650_codecs[0].of_node =
278
+ mt8173_rt5650_dais[DAI_LINK_CODEC_I2S].codecs[0].of_node =
259279 of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 0);
260
- if (!mt8173_rt5650_codecs[0].of_node) {
280
+ if (!mt8173_rt5650_dais[DAI_LINK_CODEC_I2S].codecs[0].of_node) {
261281 dev_err(&pdev->dev,
262282 "Property 'audio-codec' missing or invalid\n");
263
- return -EINVAL;
283
+ ret = -EINVAL;
284
+ goto put_platform_node;
264285 }
265
- mt8173_rt5650_codecs[1].of_node = mt8173_rt5650_codecs[0].of_node;
286
+ mt8173_rt5650_dais[DAI_LINK_CODEC_I2S].codecs[1].of_node =
287
+ mt8173_rt5650_dais[DAI_LINK_CODEC_I2S].codecs[0].of_node;
266288
267289 np = of_get_child_by_name(pdev->dev.of_node, "codec-capture");
268290 if (np) {
....@@ -272,9 +294,10 @@
272294 dev_err(&pdev->dev,
273295 "%s codec_capture_dai name fail %d\n",
274296 __func__, ret);
275
- return ret;
297
+ goto put_platform_node;
276298 }
277
- mt8173_rt5650_codecs[1].dai_name = codec_capture_dai;
299
+ mt8173_rt5650_dais[DAI_LINK_CODEC_I2S].codecs[1].dai_name =
300
+ codec_capture_dai;
278301 }
279302
280303 if (device_property_present(&pdev->dev, "mediatek,mclk")) {
....@@ -288,12 +311,13 @@
288311 }
289312 }
290313
291
- mt8173_rt5650_dais[DAI_LINK_HDMI_I2S].codec_of_node =
314
+ mt8173_rt5650_dais[DAI_LINK_HDMI_I2S].codecs->of_node =
292315 of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 1);
293
- if (!mt8173_rt5650_dais[DAI_LINK_HDMI_I2S].codec_of_node) {
316
+ if (!mt8173_rt5650_dais[DAI_LINK_HDMI_I2S].codecs->of_node) {
294317 dev_err(&pdev->dev,
295318 "Property 'audio-codec' missing or invalid\n");
296
- return -EINVAL;
319
+ ret = -EINVAL;
320
+ goto put_platform_node;
297321 }
298322 card->dev = &pdev->dev;
299323
....@@ -302,6 +326,7 @@
302326 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
303327 __func__, ret);
304328
329
+put_platform_node:
305330 of_node_put(platform_node);
306331 return ret;
307332 }