78d84527081a9e8774de2894951c5649b99aaa3c
[platform/kernel/linux-starfive.git] / sound / soc / intel / boards / sof_nau8825.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2021 Intel Corporation.
3 // Copyright(c) 2021 Nuvoton Corporation.
4
5 /*
6  * Intel SOF Machine Driver with Nuvoton headphone codec NAU8825
7  * and speaker codec RT1019P MAX98360a or MAX98373
8  */
9 #include <linux/i2c.h>
10 #include <linux/input.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.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/sof.h>
20 #include <sound/soc-acpi.h>
21 #include "../../codecs/nau8825.h"
22 #include "../common/soc-intel-quirks.h"
23 #include "hda_dsp_common.h"
24 #include "sof_realtek_common.h"
25 #include "sof_maxim_common.h"
26
27 #define NAME_SIZE 32
28
29 #define SOF_NAU8825_SSP_CODEC(quirk)            ((quirk) & GENMASK(2, 0))
30 #define SOF_NAU8825_SSP_CODEC_MASK              (GENMASK(2, 0))
31 #define SOF_SPEAKER_AMP_PRESENT         BIT(3)
32 #define SOF_NAU8825_SSP_AMP_SHIFT               4
33 #define SOF_NAU8825_SSP_AMP_MASK                (GENMASK(6, 4))
34 #define SOF_NAU8825_SSP_AMP(quirk)      \
35         (((quirk) << SOF_NAU8825_SSP_AMP_SHIFT) & SOF_NAU8825_SSP_AMP_MASK)
36 #define SOF_NAU8825_NUM_HDMIDEV_SHIFT           7
37 #define SOF_NAU8825_NUM_HDMIDEV_MASK            (GENMASK(9, 7))
38 #define SOF_NAU8825_NUM_HDMIDEV(quirk)  \
39         (((quirk) << SOF_NAU8825_NUM_HDMIDEV_SHIFT) & SOF_NAU8825_NUM_HDMIDEV_MASK)
40
41 /* BT audio offload: reserve 3 bits for future */
42 #define SOF_BT_OFFLOAD_SSP_SHIFT                10
43 #define SOF_BT_OFFLOAD_SSP_MASK         (GENMASK(12, 10))
44 #define SOF_BT_OFFLOAD_SSP(quirk)       \
45         (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
46 #define SOF_SSP_BT_OFFLOAD_PRESENT              BIT(13)
47 #define SOF_RT1019P_SPEAKER_AMP_PRESENT BIT(14)
48 #define SOF_MAX98373_SPEAKER_AMP_PRESENT        BIT(15)
49 #define SOF_MAX98360A_SPEAKER_AMP_PRESENT       BIT(16)
50 #define SOF_RT1015P_SPEAKER_AMP_PRESENT BIT(17)
51 #define SOF_NAU8318_SPEAKER_AMP_PRESENT BIT(18)
52
53 static unsigned long sof_nau8825_quirk = SOF_NAU8825_SSP_CODEC(0);
54
55 struct sof_hdmi_pcm {
56         struct list_head head;
57         struct snd_soc_dai *codec_dai;
58         int device;
59 };
60
61 struct sof_card_private {
62         struct clk *mclk;
63         struct snd_soc_jack sof_headset;
64         struct list_head hdmi_pcm_list;
65 };
66
67 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
68 {
69         struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
70         struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
71         struct sof_hdmi_pcm *pcm;
72
73         pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
74         if (!pcm)
75                 return -ENOMEM;
76
77         /* dai_link id is 1:1 mapped to the PCM device */
78         pcm->device = rtd->dai_link->id;
79         pcm->codec_dai = dai;
80
81         list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
82
83         return 0;
84 }
85
86 static struct snd_soc_jack_pin jack_pins[] = {
87         {
88                 .pin    = "Headphone Jack",
89                 .mask   = SND_JACK_HEADPHONE,
90         },
91         {
92                 .pin    = "Headset Mic",
93                 .mask   = SND_JACK_MICROPHONE,
94         },
95 };
96
97 static int sof_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
98 {
99         struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
100         struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
101
102         struct snd_soc_jack *jack;
103         int ret;
104
105         /*
106          * Headset buttons map to the google Reference headset.
107          * These can be configured by userspace.
108          */
109         ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
110                                          SND_JACK_HEADSET | SND_JACK_BTN_0 |
111                                          SND_JACK_BTN_1 | SND_JACK_BTN_2 |
112                                          SND_JACK_BTN_3,
113                                          &ctx->sof_headset,
114                                          jack_pins,
115                                          ARRAY_SIZE(jack_pins));
116         if (ret) {
117                 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
118                 return ret;
119         }
120
121         jack = &ctx->sof_headset;
122
123         snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
124         snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
125         snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
126         snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
127         ret = snd_soc_component_set_jack(component, jack, NULL);
128
129         if (ret) {
130                 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
131                 return ret;
132         }
133
134         return ret;
135 };
136
137 static void sof_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd)
138 {
139         struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
140
141         snd_soc_component_set_jack(component, NULL, NULL);
142 }
143
144 static int sof_nau8825_hw_params(struct snd_pcm_substream *substream,
145                                  struct snd_pcm_hw_params *params)
146 {
147         struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
148         struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
149         int clk_freq, ret;
150
151         clk_freq = sof_dai_get_bclk(rtd); /* BCLK freq */
152
153         if (clk_freq <= 0) {
154                 dev_err(rtd->dev, "get bclk freq failed: %d\n", clk_freq);
155                 return -EINVAL;
156         }
157
158         /* Configure clock for codec */
159         ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_BLK, 0,
160                                      SND_SOC_CLOCK_IN);
161         if (ret < 0) {
162                 dev_err(codec_dai->dev, "can't set BCLK clock %d\n", ret);
163                 return ret;
164         }
165
166         /* Configure pll for codec */
167         ret = snd_soc_dai_set_pll(codec_dai, 0, 0, clk_freq,
168                                   params_rate(params) * 256);
169         if (ret < 0) {
170                 dev_err(codec_dai->dev, "can't set BCLK: %d\n", ret);
171                 return ret;
172         }
173
174         return ret;
175 }
176
177 static struct snd_soc_ops sof_nau8825_ops = {
178         .hw_params = sof_nau8825_hw_params,
179 };
180
181 static struct snd_soc_dai_link_component platform_component[] = {
182         {
183                 /* name might be overridden during probe */
184                 .name = "0000:00:1f.3"
185         }
186 };
187
188 static int sof_card_late_probe(struct snd_soc_card *card)
189 {
190         struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
191         struct snd_soc_dapm_context *dapm = &card->dapm;
192         struct sof_hdmi_pcm *pcm;
193         int err;
194
195         if (sof_nau8825_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
196                 /* Disable Left and Right Spk pin after boot */
197                 snd_soc_dapm_disable_pin(dapm, "Left Spk");
198                 snd_soc_dapm_disable_pin(dapm, "Right Spk");
199                 err = snd_soc_dapm_sync(dapm);
200                 if (err < 0)
201                         return err;
202         }
203
204         if (list_empty(&ctx->hdmi_pcm_list))
205                 return -EINVAL;
206
207         pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm, head);
208
209         return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component);
210 }
211
212 static const struct snd_kcontrol_new sof_controls[] = {
213         SOC_DAPM_PIN_SWITCH("Headphone Jack"),
214         SOC_DAPM_PIN_SWITCH("Headset Mic"),
215         SOC_DAPM_PIN_SWITCH("Left Spk"),
216         SOC_DAPM_PIN_SWITCH("Right Spk"),
217 };
218
219 static const struct snd_kcontrol_new speaker_controls[] = {
220         SOC_DAPM_PIN_SWITCH("Spk"),
221 };
222
223 static const struct snd_soc_dapm_widget sof_widgets[] = {
224         SND_SOC_DAPM_HP("Headphone Jack", NULL),
225         SND_SOC_DAPM_MIC("Headset Mic", NULL),
226         SND_SOC_DAPM_SPK("Left Spk", NULL),
227         SND_SOC_DAPM_SPK("Right Spk", NULL),
228 };
229
230 static const struct snd_soc_dapm_widget speaker_widgets[] = {
231         SND_SOC_DAPM_SPK("Spk", NULL),
232 };
233
234 static const struct snd_soc_dapm_widget dmic_widgets[] = {
235         SND_SOC_DAPM_MIC("SoC DMIC", NULL),
236 };
237
238 static const struct snd_soc_dapm_route sof_map[] = {
239         /* HP jack connectors - unknown if we have jack detection */
240         { "Headphone Jack", NULL, "HPOL" },
241         { "Headphone Jack", NULL, "HPOR" },
242
243         /* other jacks */
244         { "MIC", NULL, "Headset Mic" },
245 };
246
247 static const struct snd_soc_dapm_route speaker_map[] = {
248         /* speaker */
249         { "Spk", NULL, "Speaker" },
250 };
251
252 static const struct snd_soc_dapm_route dmic_map[] = {
253         /* digital mics */
254         {"DMic", NULL, "SoC DMIC"},
255 };
256
257 static int speaker_codec_init(struct snd_soc_pcm_runtime *rtd)
258 {
259         struct snd_soc_card *card = rtd->card;
260         int ret;
261
262         ret = snd_soc_dapm_new_controls(&card->dapm, speaker_widgets,
263                                         ARRAY_SIZE(speaker_widgets));
264         if (ret) {
265                 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
266                 /* Don't need to add routes if widget addition failed */
267                 return ret;
268         }
269
270         ret = snd_soc_add_card_controls(card, speaker_controls,
271                                         ARRAY_SIZE(speaker_controls));
272         if (ret) {
273                 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
274                 return ret;
275         }
276
277         ret = snd_soc_dapm_add_routes(&card->dapm, speaker_map,
278                                       ARRAY_SIZE(speaker_map));
279
280         if (ret)
281                 dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
282         return ret;
283 }
284
285 static int dmic_init(struct snd_soc_pcm_runtime *rtd)
286 {
287         struct snd_soc_card *card = rtd->card;
288         int ret;
289
290         ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
291                                         ARRAY_SIZE(dmic_widgets));
292         if (ret) {
293                 dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
294                 /* Don't need to add routes if widget addition failed */
295                 return ret;
296         }
297
298         ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
299                                       ARRAY_SIZE(dmic_map));
300
301         if (ret)
302                 dev_err(card->dev, "DMic map addition failed: %d\n", ret);
303
304         return ret;
305 }
306
307 /* sof audio machine driver for nau8825 codec */
308 static struct snd_soc_card sof_audio_card_nau8825 = {
309         .name = "nau8825", /* the sof- prefix is added by the core */
310         .owner = THIS_MODULE,
311         .controls = sof_controls,
312         .num_controls = ARRAY_SIZE(sof_controls),
313         .dapm_widgets = sof_widgets,
314         .num_dapm_widgets = ARRAY_SIZE(sof_widgets),
315         .dapm_routes = sof_map,
316         .num_dapm_routes = ARRAY_SIZE(sof_map),
317         .fully_routed = true,
318         .late_probe = sof_card_late_probe,
319 };
320
321 static struct snd_soc_dai_link_component nau8825_component[] = {
322         {
323                 .name = "i2c-10508825:00",
324                 .dai_name = "nau8825-hifi",
325         }
326 };
327
328 static struct snd_soc_dai_link_component dmic_component[] = {
329         {
330                 .name = "dmic-codec",
331                 .dai_name = "dmic-hifi",
332         }
333 };
334
335 static struct snd_soc_dai_link_component rt1019p_component[] = {
336         {
337                 .name = "RTL1019:00",
338                 .dai_name = "HiFi",
339         }
340 };
341
342 static struct snd_soc_dai_link_component nau8318_components[] = {
343         {
344                 .name = "NVTN2012:00",
345                 .dai_name = "nau8315-hifi",
346         }
347 };
348
349 static struct snd_soc_dai_link_component dummy_component[] = {
350         {
351                 .name = "snd-soc-dummy",
352                 .dai_name = "snd-soc-dummy-dai",
353         }
354 };
355
356 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
357                                                           int ssp_codec,
358                                                           int ssp_amp,
359                                                           int dmic_be_num,
360                                                           int hdmi_num)
361 {
362         struct snd_soc_dai_link_component *idisp_components;
363         struct snd_soc_dai_link_component *cpus;
364         struct snd_soc_dai_link *links;
365         int i, id = 0;
366
367         links = devm_kcalloc(dev, sof_audio_card_nau8825.num_links,
368                             sizeof(struct snd_soc_dai_link), GFP_KERNEL);
369         cpus = devm_kcalloc(dev, sof_audio_card_nau8825.num_links,
370                             sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
371         if (!links || !cpus)
372                 goto devm_err;
373
374         /* codec SSP */
375         links[id].name = devm_kasprintf(dev, GFP_KERNEL,
376                                         "SSP%d-Codec", ssp_codec);
377         if (!links[id].name)
378                 goto devm_err;
379
380         links[id].id = id;
381         links[id].codecs = nau8825_component;
382         links[id].num_codecs = ARRAY_SIZE(nau8825_component);
383         links[id].platforms = platform_component;
384         links[id].num_platforms = ARRAY_SIZE(platform_component);
385         links[id].init = sof_nau8825_codec_init;
386         links[id].exit = sof_nau8825_codec_exit;
387         links[id].ops = &sof_nau8825_ops;
388         links[id].dpcm_playback = 1;
389         links[id].dpcm_capture = 1;
390         links[id].no_pcm = 1;
391         links[id].cpus = &cpus[id];
392         links[id].num_cpus = 1;
393
394         links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
395                                                   "SSP%d Pin",
396                                                   ssp_codec);
397         if (!links[id].cpus->dai_name)
398                 goto devm_err;
399
400         id++;
401
402         /* dmic */
403         if (dmic_be_num > 0) {
404                 /* at least we have dmic01 */
405                 links[id].name = "dmic01";
406                 links[id].cpus = &cpus[id];
407                 links[id].cpus->dai_name = "DMIC01 Pin";
408                 links[id].init = dmic_init;
409                 if (dmic_be_num > 1) {
410                         /* set up 2 BE links at most */
411                         links[id + 1].name = "dmic16k";
412                         links[id + 1].cpus = &cpus[id + 1];
413                         links[id + 1].cpus->dai_name = "DMIC16k Pin";
414                         dmic_be_num = 2;
415                 }
416         }
417
418         for (i = 0; i < dmic_be_num; i++) {
419                 links[id].id = id;
420                 links[id].num_cpus = 1;
421                 links[id].codecs = dmic_component;
422                 links[id].num_codecs = ARRAY_SIZE(dmic_component);
423                 links[id].platforms = platform_component;
424                 links[id].num_platforms = ARRAY_SIZE(platform_component);
425                 links[id].ignore_suspend = 1;
426                 links[id].dpcm_capture = 1;
427                 links[id].no_pcm = 1;
428                 id++;
429         }
430
431         /* HDMI */
432         if (hdmi_num > 0) {
433                 idisp_components = devm_kcalloc(dev,
434                                                 hdmi_num,
435                                                 sizeof(struct snd_soc_dai_link_component),
436                                                 GFP_KERNEL);
437                 if (!idisp_components)
438                         goto devm_err;
439         }
440         for (i = 1; i <= hdmi_num; i++) {
441                 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
442                                                 "iDisp%d", i);
443                 if (!links[id].name)
444                         goto devm_err;
445
446                 links[id].id = id;
447                 links[id].cpus = &cpus[id];
448                 links[id].num_cpus = 1;
449                 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
450                                                           "iDisp%d Pin", i);
451                 if (!links[id].cpus->dai_name)
452                         goto devm_err;
453
454                 idisp_components[i - 1].name = "ehdaudio0D2";
455                 idisp_components[i - 1].dai_name = devm_kasprintf(dev,
456                                                                   GFP_KERNEL,
457                                                                   "intel-hdmi-hifi%d",
458                                                                   i);
459                 if (!idisp_components[i - 1].dai_name)
460                         goto devm_err;
461
462                 links[id].codecs = &idisp_components[i - 1];
463                 links[id].num_codecs = 1;
464                 links[id].platforms = platform_component;
465                 links[id].num_platforms = ARRAY_SIZE(platform_component);
466                 links[id].init = sof_hdmi_init;
467                 links[id].dpcm_playback = 1;
468                 links[id].no_pcm = 1;
469                 id++;
470         }
471
472         /* speaker amp */
473         if (sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT) {
474                 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
475                                                 "SSP%d-Codec", ssp_amp);
476                 if (!links[id].name)
477                         goto devm_err;
478
479                 links[id].id = id;
480                 if (sof_nau8825_quirk & SOF_RT1019P_SPEAKER_AMP_PRESENT) {
481                         links[id].codecs = rt1019p_component;
482                         links[id].num_codecs = ARRAY_SIZE(rt1019p_component);
483                         links[id].init = speaker_codec_init;
484                 } else if (sof_nau8825_quirk &
485                                 SOF_MAX98373_SPEAKER_AMP_PRESENT) {
486                         links[id].codecs = max_98373_components;
487                         links[id].num_codecs = ARRAY_SIZE(max_98373_components);
488                         links[id].init = max_98373_spk_codec_init;
489                         links[id].ops = &max_98373_ops;
490                         /* feedback stream */
491                         links[id].dpcm_capture = 1;
492                 } else if (sof_nau8825_quirk &
493                                 SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
494                         max_98360a_dai_link(&links[id]);
495                 } else if (sof_nau8825_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT) {
496                         sof_rt1015p_dai_link(&links[id]);
497                 } else if (sof_nau8825_quirk &
498                                 SOF_NAU8318_SPEAKER_AMP_PRESENT) {
499                         links[id].codecs = nau8318_components;
500                         links[id].num_codecs = ARRAY_SIZE(nau8318_components);
501                         links[id].init = speaker_codec_init;
502                 } else {
503                         goto devm_err;
504                 }
505
506                 links[id].platforms = platform_component;
507                 links[id].num_platforms = ARRAY_SIZE(platform_component);
508                 links[id].dpcm_playback = 1;
509                 links[id].no_pcm = 1;
510                 links[id].cpus = &cpus[id];
511                 links[id].num_cpus = 1;
512                 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
513                                                           "SSP%d Pin",
514                                                           ssp_amp);
515                 if (!links[id].cpus->dai_name)
516                         goto devm_err;
517                 id++;
518         }
519
520         /* BT audio offload */
521         if (sof_nau8825_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
522                 int port = (sof_nau8825_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
523                                 SOF_BT_OFFLOAD_SSP_SHIFT;
524
525                 links[id].id = id;
526                 links[id].cpus = &cpus[id];
527                 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
528                                                           "SSP%d Pin", port);
529                 if (!links[id].cpus->dai_name)
530                         goto devm_err;
531                 links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
532                 if (!links[id].name)
533                         goto devm_err;
534                 links[id].codecs = dummy_component;
535                 links[id].num_codecs = ARRAY_SIZE(dummy_component);
536                 links[id].platforms = platform_component;
537                 links[id].num_platforms = ARRAY_SIZE(platform_component);
538                 links[id].dpcm_playback = 1;
539                 links[id].dpcm_capture = 1;
540                 links[id].no_pcm = 1;
541                 links[id].num_cpus = 1;
542         }
543
544         return links;
545 devm_err:
546         return NULL;
547 }
548
549 static int sof_audio_probe(struct platform_device *pdev)
550 {
551         struct snd_soc_dai_link *dai_links;
552         struct snd_soc_acpi_mach *mach;
553         struct sof_card_private *ctx;
554         int dmic_be_num, hdmi_num;
555         int ret, ssp_amp, ssp_codec;
556
557         ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
558         if (!ctx)
559                 return -ENOMEM;
560
561         if (pdev->id_entry && pdev->id_entry->driver_data)
562                 sof_nau8825_quirk = (unsigned long)pdev->id_entry->driver_data;
563
564         mach = pdev->dev.platform_data;
565
566         /* A speaker amp might not be present when the quirk claims one is.
567          * Detect this via whether the machine driver match includes quirk_data.
568          */
569         if ((sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT) && !mach->quirk_data)
570                 sof_nau8825_quirk &= ~SOF_SPEAKER_AMP_PRESENT;
571
572         dev_dbg(&pdev->dev, "sof_nau8825_quirk = %lx\n", sof_nau8825_quirk);
573
574         /* default number of DMIC DAI's */
575         dmic_be_num = 2;
576         hdmi_num = (sof_nau8825_quirk & SOF_NAU8825_NUM_HDMIDEV_MASK) >>
577                         SOF_NAU8825_NUM_HDMIDEV_SHIFT;
578         /* default number of HDMI DAI's */
579         if (!hdmi_num)
580                 hdmi_num = 3;
581
582         ssp_amp = (sof_nau8825_quirk & SOF_NAU8825_SSP_AMP_MASK) >>
583                         SOF_NAU8825_SSP_AMP_SHIFT;
584
585         ssp_codec = sof_nau8825_quirk & SOF_NAU8825_SSP_CODEC_MASK;
586
587         /* compute number of dai links */
588         sof_audio_card_nau8825.num_links = 1 + dmic_be_num + hdmi_num;
589
590         if (sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT)
591                 sof_audio_card_nau8825.num_links++;
592
593         if (sof_nau8825_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT)
594                 max_98373_set_codec_conf(&sof_audio_card_nau8825);
595         else if (sof_nau8825_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
596                 sof_rt1015p_codec_conf(&sof_audio_card_nau8825);
597
598         if (sof_nau8825_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
599                 sof_audio_card_nau8825.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_nau8825.dai_link = dai_links;
607
608         INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
609
610         sof_audio_card_nau8825.dev = &pdev->dev;
611
612         /* set platform name for each dailink */
613         ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_nau8825,
614                                                     mach->mach_params.platform);
615         if (ret)
616                 return ret;
617
618         snd_soc_card_set_drvdata(&sof_audio_card_nau8825, ctx);
619
620         return devm_snd_soc_register_card(&pdev->dev,
621                                           &sof_audio_card_nau8825);
622 }
623
624 static const struct platform_device_id board_ids[] = {
625         {
626                 .name = "sof_nau8825",
627                 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
628                                         SOF_NAU8825_NUM_HDMIDEV(4) |
629                                         SOF_BT_OFFLOAD_SSP(2) |
630                                         SOF_SSP_BT_OFFLOAD_PRESENT),
631
632         },
633         {
634                 .name = "adl_rt1019p_nau8825",
635                 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
636                                         SOF_SPEAKER_AMP_PRESENT |
637                                         SOF_RT1019P_SPEAKER_AMP_PRESENT |
638                                         SOF_NAU8825_SSP_AMP(2) |
639                                         SOF_NAU8825_NUM_HDMIDEV(4)),
640         },
641         {
642                 .name = "adl_max98373_nau8825",
643                 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
644                                         SOF_SPEAKER_AMP_PRESENT |
645                                         SOF_MAX98373_SPEAKER_AMP_PRESENT |
646                                         SOF_NAU8825_SSP_AMP(1) |
647                                         SOF_NAU8825_NUM_HDMIDEV(4) |
648                                         SOF_BT_OFFLOAD_SSP(2) |
649                                         SOF_SSP_BT_OFFLOAD_PRESENT),
650         },
651         {
652                 /* The limitation of length of char array, shorten the name */
653                 .name = "adl_mx98360a_nau8825",
654                 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
655                                         SOF_SPEAKER_AMP_PRESENT |
656                                         SOF_MAX98360A_SPEAKER_AMP_PRESENT |
657                                         SOF_NAU8825_SSP_AMP(1) |
658                                         SOF_NAU8825_NUM_HDMIDEV(4) |
659                                         SOF_BT_OFFLOAD_SSP(2) |
660                                         SOF_SSP_BT_OFFLOAD_PRESENT),
661
662         },
663         {
664                 .name = "adl_rt1015p_nau8825",
665                 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
666                                         SOF_SPEAKER_AMP_PRESENT |
667                                         SOF_RT1015P_SPEAKER_AMP_PRESENT |
668                                         SOF_NAU8825_SSP_AMP(1) |
669                                         SOF_NAU8825_NUM_HDMIDEV(4) |
670                                         SOF_BT_OFFLOAD_SSP(2) |
671                                         SOF_SSP_BT_OFFLOAD_PRESENT),
672         },
673         {
674                 .name = "adl_nau8318_8825",
675                 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
676                                         SOF_SPEAKER_AMP_PRESENT |
677                                         SOF_NAU8318_SPEAKER_AMP_PRESENT |
678                                         SOF_NAU8825_SSP_AMP(1) |
679                                         SOF_NAU8825_NUM_HDMIDEV(4) |
680                                         SOF_BT_OFFLOAD_SSP(2) |
681                                         SOF_SSP_BT_OFFLOAD_PRESENT),
682         },
683         { }
684 };
685 MODULE_DEVICE_TABLE(platform, board_ids);
686
687 static struct platform_driver sof_audio = {
688         .probe = sof_audio_probe,
689         .driver = {
690                 .name = "sof_nau8825",
691                 .pm = &snd_soc_pm_ops,
692         },
693         .id_table = board_ids,
694 };
695 module_platform_driver(sof_audio)
696
697 /* Module information */
698 MODULE_DESCRIPTION("SOF Audio Machine driver for NAU8825");
699 MODULE_AUTHOR("David Lin <ctlin0@nuvoton.com>");
700 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
701 MODULE_LICENSE("GPL");
702 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
703 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
704 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);