Merge branch 'asoc-5.3' into asoc-linus
[platform/kernel/linux-starfive.git] / sound / soc / intel / boards / sof_rt5682.c
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright(c) 2019 Intel Corporation.
3
4 /*
5  * Intel SOF Machine Driver with Realtek rt5682 Codec
6  * and speaker codec MAX98357A
7  */
8 #include <linux/i2c.h>
9 #include <linux/input.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/clk.h>
13 #include <linux/dmi.h>
14 #include <sound/core.h>
15 #include <sound/jack.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 #include <sound/rt5682.h>
20 #include <sound/soc-acpi.h>
21 #include "../../codecs/rt5682.h"
22 #include "../../codecs/hdac_hdmi.h"
23 #include "../common/soc-intel-quirks.h"
24
25 #define NAME_SIZE 32
26
27 #define SOF_RT5682_SSP_CODEC(quirk)             ((quirk) & GENMASK(2, 0))
28 #define SOF_RT5682_SSP_CODEC_MASK                       (GENMASK(2, 0))
29 #define SOF_RT5682_MCLK_EN                      BIT(3)
30 #define SOF_RT5682_MCLK_24MHZ                   BIT(4)
31 #define SOF_SPEAKER_AMP_PRESENT         BIT(5)
32 #define SOF_RT5682_SSP_AMP_SHIFT                6
33 #define SOF_RT5682_SSP_AMP_MASK                 (GENMASK(8, 6))
34 #define SOF_RT5682_SSP_AMP(quirk)       \
35         (((quirk) << SOF_RT5682_SSP_AMP_SHIFT) & SOF_RT5682_SSP_AMP_MASK)
36 #define SOF_RT5682_MCLK_BYTCHT_EN               BIT(9)
37
38 /* Default: MCLK on, MCLK 19.2M, SSP0  */
39 static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
40                                         SOF_RT5682_SSP_CODEC(0);
41
42 static int is_legacy_cpu;
43
44 static struct snd_soc_jack sof_hdmi[3];
45
46 struct sof_hdmi_pcm {
47         struct list_head head;
48         struct snd_soc_dai *codec_dai;
49         int device;
50 };
51
52 struct sof_card_private {
53         struct clk *mclk;
54         struct snd_soc_jack sof_headset;
55         struct list_head hdmi_pcm_list;
56 };
57
58 static int sof_rt5682_quirk_cb(const struct dmi_system_id *id)
59 {
60         sof_rt5682_quirk = (unsigned long)id->driver_data;
61         return 1;
62 }
63
64 static const struct dmi_system_id sof_rt5682_quirk_table[] = {
65         {
66                 .callback = sof_rt5682_quirk_cb,
67                 .matches = {
68                         DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
69                         DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max"),
70                 },
71                 .driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
72         },
73         {
74                 .callback = sof_rt5682_quirk_cb,
75                 .matches = {
76                         DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
77                         DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
78                 },
79                 .driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
80         },
81         {
82                 .callback = sof_rt5682_quirk_cb,
83                 .matches = {
84                         DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
85                         DMI_MATCH(DMI_PRODUCT_NAME, "WhiskeyLake Client"),
86                 },
87                 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
88                                         SOF_RT5682_MCLK_24MHZ |
89                                         SOF_RT5682_SSP_CODEC(1)),
90         },
91         {
92                 .callback = sof_rt5682_quirk_cb,
93                 .matches = {
94                         DMI_MATCH(DMI_SYS_VENDOR, "Google"),
95                         DMI_MATCH(DMI_PRODUCT_NAME, "Hatch"),
96                 },
97                 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
98                                         SOF_RT5682_MCLK_24MHZ |
99                                         SOF_RT5682_SSP_CODEC(0) |
100                                         SOF_SPEAKER_AMP_PRESENT |
101                                         SOF_RT5682_SSP_AMP(1)),
102         },
103         {
104                 .callback = sof_rt5682_quirk_cb,
105                 .matches = {
106                         DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
107                         DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"),
108                 },
109                 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
110                                         SOF_RT5682_SSP_CODEC(0)),
111         },
112         {}
113 };
114
115 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
116 {
117         struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
118         struct snd_soc_dai *dai = rtd->codec_dai;
119         struct sof_hdmi_pcm *pcm;
120
121         pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
122         if (!pcm)
123                 return -ENOMEM;
124
125         /* dai_link id is 1:1 mapped to the PCM device */
126         pcm->device = rtd->dai_link->id;
127         pcm->codec_dai = dai;
128
129         list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
130
131         return 0;
132 }
133
134 static int sof_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
135 {
136         struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
137         struct snd_soc_component *component = rtd->codec_dai->component;
138         struct snd_soc_jack *jack;
139         int ret;
140
141         /* need to enable ASRC function for 24MHz mclk rate */
142         if ((sof_rt5682_quirk & SOF_RT5682_MCLK_EN) &&
143             (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ)) {
144                 rt5682_sel_asrc_clk_src(component, RT5682_DA_STEREO1_FILTER |
145                                         RT5682_AD_STEREO1_FILTER,
146                                         RT5682_CLK_SEL_I2S1_ASRC);
147         }
148
149         if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
150                 /*
151                  * The firmware might enable the clock at
152                  * boot (this information may or may not
153                  * be reflected in the enable clock register).
154                  * To change the rate we must disable the clock
155                  * first to cover these cases. Due to common
156                  * clock framework restrictions that do not allow
157                  * to disable a clock that has not been enabled,
158                  * we need to enable the clock first.
159                  */
160                 ret = clk_prepare_enable(ctx->mclk);
161                 if (!ret)
162                         clk_disable_unprepare(ctx->mclk);
163
164                 ret = clk_set_rate(ctx->mclk, 19200000);
165
166                 if (ret)
167                         dev_err(rtd->dev, "unable to set MCLK rate\n");
168         }
169
170         /*
171          * Headset buttons map to the google Reference headset.
172          * These can be configured by userspace.
173          */
174         ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
175                                     SND_JACK_HEADSET | SND_JACK_BTN_0 |
176                                     SND_JACK_BTN_1 | SND_JACK_BTN_2 |
177                                     SND_JACK_BTN_3,
178                                     &ctx->sof_headset, NULL, 0);
179         if (ret) {
180                 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
181                 return ret;
182         }
183
184         jack = &ctx->sof_headset;
185
186         snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
187         snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
188         snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
189         snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
190         ret = snd_soc_component_set_jack(component, jack, NULL);
191
192         if (ret) {
193                 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
194                 return ret;
195         }
196
197         return ret;
198 };
199
200 static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
201                                 struct snd_pcm_hw_params *params)
202 {
203         struct snd_soc_pcm_runtime *rtd = substream->private_data;
204         struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
205         struct snd_soc_dai *codec_dai = rtd->codec_dai;
206         int clk_id, clk_freq, pll_out, ret;
207
208         if (sof_rt5682_quirk & SOF_RT5682_MCLK_EN) {
209                 if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
210                         ret = clk_prepare_enable(ctx->mclk);
211                         if (ret < 0) {
212                                 dev_err(rtd->dev,
213                                         "could not configure MCLK state");
214                                 return ret;
215                         }
216                 }
217
218                 clk_id = RT5682_PLL1_S_MCLK;
219                 if (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ)
220                         clk_freq = 24000000;
221                 else
222                         clk_freq = 19200000;
223         } else {
224                 clk_id = RT5682_PLL1_S_BCLK1;
225                 clk_freq = params_rate(params) * 50;
226         }
227
228         pll_out = params_rate(params) * 512;
229
230         ret = snd_soc_dai_set_pll(codec_dai, 0, clk_id, clk_freq, pll_out);
231         if (ret < 0)
232                 dev_err(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
233
234         /* Configure sysclk for codec */
235         ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1,
236                                      pll_out, SND_SOC_CLOCK_IN);
237         if (ret < 0)
238                 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
239
240         /*
241          * slot_width should equal or large than data length, set them
242          * be the same
243          */
244         ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
245                                        params_width(params));
246         if (ret < 0) {
247                 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
248                 return ret;
249         }
250
251         return ret;
252 }
253
254 static struct snd_soc_ops sof_rt5682_ops = {
255         .hw_params = sof_rt5682_hw_params,
256 };
257
258 static struct snd_soc_dai_link_component platform_component[] = {
259         {
260                 /* name might be overridden during probe */
261                 .name = "0000:00:1f.3"
262         }
263 };
264
265 static int sof_card_late_probe(struct snd_soc_card *card)
266 {
267         struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
268         struct snd_soc_component *component = NULL;
269         char jack_name[NAME_SIZE];
270         struct sof_hdmi_pcm *pcm;
271         int err = 0;
272         int i = 0;
273
274         /* HDMI is not supported by SOF on Baytrail/CherryTrail */
275         if (is_legacy_cpu)
276                 return 0;
277
278         list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
279                 component = pcm->codec_dai->component;
280                 snprintf(jack_name, sizeof(jack_name),
281                          "HDMI/DP, pcm=%d Jack", pcm->device);
282                 err = snd_soc_card_jack_new(card, jack_name,
283                                             SND_JACK_AVOUT, &sof_hdmi[i],
284                                             NULL, 0);
285
286                 if (err)
287                         return err;
288
289                 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
290                                           &sof_hdmi[i]);
291                 if (err < 0)
292                         return err;
293
294                 i++;
295         }
296         if (!component)
297                 return -EINVAL;
298
299         return hdac_hdmi_jack_port_init(component, &card->dapm);
300 }
301
302 static const struct snd_kcontrol_new sof_controls[] = {
303         SOC_DAPM_PIN_SWITCH("Headphone Jack"),
304         SOC_DAPM_PIN_SWITCH("Headset Mic"),
305         SOC_DAPM_PIN_SWITCH("Spk"),
306 };
307
308 static const struct snd_soc_dapm_widget sof_widgets[] = {
309         SND_SOC_DAPM_HP("Headphone Jack", NULL),
310         SND_SOC_DAPM_MIC("Headset Mic", NULL),
311         SND_SOC_DAPM_SPK("Spk", NULL),
312         SND_SOC_DAPM_MIC("SoC DMIC", NULL),
313 };
314
315 static const struct snd_soc_dapm_route sof_map[] = {
316         /* HP jack connectors - unknown if we have jack detection */
317         { "Headphone Jack", NULL, "HPOL" },
318         { "Headphone Jack", NULL, "HPOR" },
319
320         /* other jacks */
321         { "IN1P", NULL, "Headset Mic" },
322
323         /* digital mics */
324         {"DMic", NULL, "SoC DMIC"},
325
326 };
327
328 static const struct snd_soc_dapm_route speaker_map[] = {
329         /* speaker */
330         { "Spk", NULL, "Speaker" },
331 };
332
333 static int speaker_codec_init(struct snd_soc_pcm_runtime *rtd)
334 {
335         struct snd_soc_card *card = rtd->card;
336         int ret;
337
338         ret = snd_soc_dapm_add_routes(&card->dapm, speaker_map,
339                                       ARRAY_SIZE(speaker_map));
340
341         if (ret)
342                 dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
343         return ret;
344 }
345
346 /* sof audio machine driver for rt5682 codec */
347 static struct snd_soc_card sof_audio_card_rt5682 = {
348         .name = "sof_rt5682",
349         .owner = THIS_MODULE,
350         .controls = sof_controls,
351         .num_controls = ARRAY_SIZE(sof_controls),
352         .dapm_widgets = sof_widgets,
353         .num_dapm_widgets = ARRAY_SIZE(sof_widgets),
354         .dapm_routes = sof_map,
355         .num_dapm_routes = ARRAY_SIZE(sof_map),
356         .fully_routed = true,
357         .late_probe = sof_card_late_probe,
358 };
359
360 static struct snd_soc_dai_link_component rt5682_component[] = {
361         {
362                 .name = "i2c-10EC5682:00",
363                 .dai_name = "rt5682-aif1",
364         }
365 };
366
367 static struct snd_soc_dai_link_component dmic_component[] = {
368         {
369                 .name = "dmic-codec",
370                 .dai_name = "dmic-hifi",
371         }
372 };
373
374 static struct snd_soc_dai_link_component max98357a_component[] = {
375         {
376                 .name = "MX98357A:00",
377                 .dai_name = "HiFi",
378         }
379 };
380
381 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
382                                                           int ssp_codec,
383                                                           int ssp_amp,
384                                                           int dmic_be_num,
385                                                           int hdmi_num)
386 {
387         struct snd_soc_dai_link_component *idisp_components;
388         struct snd_soc_dai_link_component *cpus;
389         struct snd_soc_dai_link *links;
390         int i, id = 0;
391
392         links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) *
393                              sof_audio_card_rt5682.num_links, GFP_KERNEL);
394         cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component) *
395                              sof_audio_card_rt5682.num_links, GFP_KERNEL);
396         if (!links || !cpus)
397                 goto devm_err;
398
399         /* codec SSP */
400         links[id].name = devm_kasprintf(dev, GFP_KERNEL,
401                                         "SSP%d-Codec", ssp_codec);
402         if (!links[id].name)
403                 goto devm_err;
404
405         links[id].id = id;
406         links[id].codecs = rt5682_component;
407         links[id].num_codecs = ARRAY_SIZE(rt5682_component);
408         links[id].platforms = platform_component;
409         links[id].num_platforms = ARRAY_SIZE(platform_component);
410         links[id].init = sof_rt5682_codec_init;
411         links[id].ops = &sof_rt5682_ops;
412         links[id].nonatomic = true;
413         links[id].dpcm_playback = 1;
414         links[id].dpcm_capture = 1;
415         links[id].no_pcm = 1;
416         links[id].cpus = &cpus[id];
417         links[id].num_cpus = 1;
418         if (is_legacy_cpu) {
419                 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
420                                                           "ssp%d-port",
421                                                           ssp_codec);
422                 if (!links[id].cpus->dai_name)
423                         goto devm_err;
424         } else {
425                 /*
426                  * Currently, On SKL+ platforms MCLK will be turned off in sof
427                  * runtime suspended, and it will go into runtime suspended
428                  * right after playback is stop. However, rt5682 will output
429                  * static noise if sysclk turns off during playback. Set
430                  * ignore_pmdown_time to power down rt5682 immediately and
431                  * avoid the noise.
432                  * It can be removed once we can control MCLK by driver.
433                  */
434                 links[id].ignore_pmdown_time = 1;
435                 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
436                                                           "SSP%d Pin",
437                                                           ssp_codec);
438                 if (!links[id].cpus->dai_name)
439                         goto devm_err;
440         }
441         id++;
442
443         /* dmic */
444         if (dmic_be_num > 0) {
445                 /* at least we have dmic01 */
446                 links[id].name = "dmic01";
447                 links[id].cpus = &cpus[id];
448                 links[id].cpus->dai_name = "DMIC01 Pin";
449                 if (dmic_be_num > 1) {
450                         /* set up 2 BE links at most */
451                         links[id + 1].name = "dmic16k";
452                         links[id + 1].cpus = &cpus[id + 1];
453                         links[id + 1].cpus->dai_name = "DMIC16k Pin";
454                         dmic_be_num = 2;
455                 }
456         }
457
458         for (i = 0; i < dmic_be_num; i++) {
459                 links[id].id = id;
460                 links[id].num_cpus = 1;
461                 links[id].codecs = dmic_component;
462                 links[id].num_codecs = ARRAY_SIZE(dmic_component);
463                 links[id].platforms = platform_component;
464                 links[id].num_platforms = ARRAY_SIZE(platform_component);
465                 links[id].ignore_suspend = 1;
466                 links[id].dpcm_capture = 1;
467                 links[id].no_pcm = 1;
468                 id++;
469         }
470
471         /* HDMI */
472         if (hdmi_num > 0) {
473                 idisp_components = devm_kzalloc(dev,
474                                    sizeof(struct snd_soc_dai_link_component) *
475                                    hdmi_num, GFP_KERNEL);
476                 if (!idisp_components)
477                         goto devm_err;
478         }
479         for (i = 1; i <= hdmi_num; i++) {
480                 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
481                                                 "iDisp%d", i);
482                 if (!links[id].name)
483                         goto devm_err;
484
485                 links[id].id = id;
486                 links[id].cpus = &cpus[id];
487                 links[id].num_cpus = 1;
488                 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
489                                                           "iDisp%d Pin", i);
490                 if (!links[id].cpus->dai_name)
491                         goto devm_err;
492
493                 idisp_components[i - 1].name = "ehdaudio0D2";
494                 idisp_components[i - 1].dai_name = devm_kasprintf(dev,
495                                                                   GFP_KERNEL,
496                                                                   "intel-hdmi-hifi%d",
497                                                                   i);
498                 if (!idisp_components[i - 1].dai_name)
499                         goto devm_err;
500
501                 links[id].codecs = &idisp_components[i - 1];
502                 links[id].num_codecs = 1;
503                 links[id].platforms = platform_component;
504                 links[id].num_platforms = ARRAY_SIZE(platform_component);
505                 links[id].init = sof_hdmi_init;
506                 links[id].dpcm_playback = 1;
507                 links[id].no_pcm = 1;
508                 id++;
509         }
510
511         /* speaker amp */
512         if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) {
513                 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
514                                                 "SSP%d-Codec", ssp_amp);
515                 if (!links[id].name)
516                         goto devm_err;
517
518                 links[id].id = id;
519                 links[id].codecs = max98357a_component;
520                 links[id].num_codecs = ARRAY_SIZE(max98357a_component);
521                 links[id].platforms = platform_component;
522                 links[id].num_platforms = ARRAY_SIZE(platform_component);
523                 links[id].init = speaker_codec_init,
524                 links[id].nonatomic = true;
525                 links[id].dpcm_playback = 1;
526                 links[id].no_pcm = 1;
527                 links[id].cpus = &cpus[id];
528                 links[id].num_cpus = 1;
529                 if (is_legacy_cpu) {
530                         links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
531                                                                   "ssp%d-port",
532                                                                   ssp_amp);
533                         if (!links[id].cpus->dai_name)
534                                 goto devm_err;
535
536                 } else {
537                         links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
538                                                                   "SSP%d Pin",
539                                                                   ssp_amp);
540                         if (!links[id].cpus->dai_name)
541                                 goto devm_err;
542                 }
543         }
544
545         return links;
546 devm_err:
547         return NULL;
548 }
549
550 static int sof_audio_probe(struct platform_device *pdev)
551 {
552         struct snd_soc_dai_link *dai_links;
553         struct snd_soc_acpi_mach *mach;
554         struct sof_card_private *ctx;
555         int dmic_be_num, hdmi_num;
556         int ret, ssp_amp, ssp_codec;
557
558         ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
559         if (!ctx)
560                 return -ENOMEM;
561
562         if (soc_intel_is_byt() || soc_intel_is_cht()) {
563                 is_legacy_cpu = 1;
564                 dmic_be_num = 0;
565                 hdmi_num = 0;
566                 /* default quirk for legacy cpu */
567                 sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
568                                                 SOF_RT5682_MCLK_BYTCHT_EN |
569                                                 SOF_RT5682_SSP_CODEC(2);
570         } else {
571                 dmic_be_num = 2;
572                 hdmi_num = 3;
573         }
574
575         dmi_check_system(sof_rt5682_quirk_table);
576
577         /* need to get main clock from pmc */
578         if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
579                 ctx->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
580                 ret = clk_prepare_enable(ctx->mclk);
581                 if (ret < 0) {
582                         dev_err(&pdev->dev,
583                                 "could not configure MCLK state");
584                         return ret;
585                 }
586         }
587
588         dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk);
589
590         ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
591                         SOF_RT5682_SSP_AMP_SHIFT;
592
593         ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;
594
595         /* compute number of dai links */
596         sof_audio_card_rt5682.num_links = 1 + dmic_be_num + hdmi_num;
597
598         if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT)
599                 sof_audio_card_rt5682.num_links++;
600
601         dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
602                                               dmic_be_num, hdmi_num);
603         if (!dai_links)
604                 return -ENOMEM;
605
606         sof_audio_card_rt5682.dai_link = dai_links;
607
608         INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
609
610         sof_audio_card_rt5682.dev = &pdev->dev;
611         mach = (&pdev->dev)->platform_data;
612
613         /* set platform name for each dailink */
614         ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_rt5682,
615                                                     mach->mach_params.platform);
616         if (ret)
617                 return ret;
618
619         snd_soc_card_set_drvdata(&sof_audio_card_rt5682, ctx);
620
621         return devm_snd_soc_register_card(&pdev->dev,
622                                           &sof_audio_card_rt5682);
623 }
624
625 static struct platform_driver sof_audio = {
626         .probe = sof_audio_probe,
627         .driver = {
628                 .name = "sof_rt5682",
629                 .pm = &snd_soc_pm_ops,
630         },
631 };
632 module_platform_driver(sof_audio)
633
634 /* Module information */
635 MODULE_DESCRIPTION("SOF Audio Machine driver");
636 MODULE_AUTHOR("Bard Liao <bard.liao@intel.com>");
637 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
638 MODULE_LICENSE("GPL v2");
639 MODULE_ALIAS("platform:sof_rt5682");