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
sof_hdmi_init(struct snd_soc_pcm_runtime * rtd)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
sof_nau8825_codec_init(struct snd_soc_pcm_runtime * rtd)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
sof_nau8825_codec_exit(struct snd_soc_pcm_runtime * rtd)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
sof_nau8825_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)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
sof_card_late_probe(struct snd_soc_card * card)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
speaker_codec_init(struct snd_soc_pcm_runtime * rtd)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
dmic_init(struct snd_soc_pcm_runtime * rtd)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
sof_card_dai_links_create(struct device * dev,int ssp_codec,int ssp_amp,int dmic_be_num,int hdmi_num)349 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
350 int ssp_codec,
351 int ssp_amp,
352 int dmic_be_num,
353 int hdmi_num)
354 {
355 struct snd_soc_dai_link_component *idisp_components;
356 struct snd_soc_dai_link_component *cpus;
357 struct snd_soc_dai_link *links;
358 int i, id = 0;
359
360 links = devm_kcalloc(dev, sof_audio_card_nau8825.num_links,
361 sizeof(struct snd_soc_dai_link), GFP_KERNEL);
362 cpus = devm_kcalloc(dev, sof_audio_card_nau8825.num_links,
363 sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
364 if (!links || !cpus)
365 goto devm_err;
366
367 /* codec SSP */
368 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
369 "SSP%d-Codec", ssp_codec);
370 if (!links[id].name)
371 goto devm_err;
372
373 links[id].id = id;
374 links[id].codecs = nau8825_component;
375 links[id].num_codecs = ARRAY_SIZE(nau8825_component);
376 links[id].platforms = platform_component;
377 links[id].num_platforms = ARRAY_SIZE(platform_component);
378 links[id].init = sof_nau8825_codec_init;
379 links[id].exit = sof_nau8825_codec_exit;
380 links[id].ops = &sof_nau8825_ops;
381 links[id].dpcm_playback = 1;
382 links[id].dpcm_capture = 1;
383 links[id].no_pcm = 1;
384 links[id].cpus = &cpus[id];
385 links[id].num_cpus = 1;
386
387 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
388 "SSP%d Pin",
389 ssp_codec);
390 if (!links[id].cpus->dai_name)
391 goto devm_err;
392
393 id++;
394
395 /* dmic */
396 if (dmic_be_num > 0) {
397 /* at least we have dmic01 */
398 links[id].name = "dmic01";
399 links[id].cpus = &cpus[id];
400 links[id].cpus->dai_name = "DMIC01 Pin";
401 links[id].init = dmic_init;
402 if (dmic_be_num > 1) {
403 /* set up 2 BE links at most */
404 links[id + 1].name = "dmic16k";
405 links[id + 1].cpus = &cpus[id + 1];
406 links[id + 1].cpus->dai_name = "DMIC16k Pin";
407 dmic_be_num = 2;
408 }
409 }
410
411 for (i = 0; i < dmic_be_num; i++) {
412 links[id].id = id;
413 links[id].num_cpus = 1;
414 links[id].codecs = dmic_component;
415 links[id].num_codecs = ARRAY_SIZE(dmic_component);
416 links[id].platforms = platform_component;
417 links[id].num_platforms = ARRAY_SIZE(platform_component);
418 links[id].ignore_suspend = 1;
419 links[id].dpcm_capture = 1;
420 links[id].no_pcm = 1;
421 id++;
422 }
423
424 /* HDMI */
425 if (hdmi_num > 0) {
426 idisp_components = devm_kcalloc(dev,
427 hdmi_num,
428 sizeof(struct snd_soc_dai_link_component),
429 GFP_KERNEL);
430 if (!idisp_components)
431 goto devm_err;
432 }
433 for (i = 1; i <= hdmi_num; i++) {
434 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
435 "iDisp%d", i);
436 if (!links[id].name)
437 goto devm_err;
438
439 links[id].id = id;
440 links[id].cpus = &cpus[id];
441 links[id].num_cpus = 1;
442 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
443 "iDisp%d Pin", i);
444 if (!links[id].cpus->dai_name)
445 goto devm_err;
446
447 idisp_components[i - 1].name = "ehdaudio0D2";
448 idisp_components[i - 1].dai_name = devm_kasprintf(dev,
449 GFP_KERNEL,
450 "intel-hdmi-hifi%d",
451 i);
452 if (!idisp_components[i - 1].dai_name)
453 goto devm_err;
454
455 links[id].codecs = &idisp_components[i - 1];
456 links[id].num_codecs = 1;
457 links[id].platforms = platform_component;
458 links[id].num_platforms = ARRAY_SIZE(platform_component);
459 links[id].init = sof_hdmi_init;
460 links[id].dpcm_playback = 1;
461 links[id].no_pcm = 1;
462 id++;
463 }
464
465 /* speaker amp */
466 if (sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT) {
467 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
468 "SSP%d-Codec", ssp_amp);
469 if (!links[id].name)
470 goto devm_err;
471
472 links[id].id = id;
473 if (sof_nau8825_quirk & SOF_RT1019P_SPEAKER_AMP_PRESENT) {
474 links[id].codecs = rt1019p_component;
475 links[id].num_codecs = ARRAY_SIZE(rt1019p_component);
476 links[id].init = speaker_codec_init;
477 } else if (sof_nau8825_quirk &
478 SOF_MAX98373_SPEAKER_AMP_PRESENT) {
479 links[id].codecs = max_98373_components;
480 links[id].num_codecs = ARRAY_SIZE(max_98373_components);
481 links[id].init = max_98373_spk_codec_init;
482 links[id].ops = &max_98373_ops;
483 } else if (sof_nau8825_quirk &
484 SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
485 max_98360a_dai_link(&links[id]);
486 } else if (sof_nau8825_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT) {
487 sof_rt1015p_dai_link(&links[id]);
488 } else if (sof_nau8825_quirk &
489 SOF_NAU8318_SPEAKER_AMP_PRESENT) {
490 links[id].codecs = nau8318_components;
491 links[id].num_codecs = ARRAY_SIZE(nau8318_components);
492 links[id].init = speaker_codec_init;
493 } else {
494 goto devm_err;
495 }
496
497 links[id].platforms = platform_component;
498 links[id].num_platforms = ARRAY_SIZE(platform_component);
499 links[id].dpcm_playback = 1;
500 /* feedback stream or firmware-generated echo reference */
501 links[id].dpcm_capture = 1;
502
503 links[id].no_pcm = 1;
504 links[id].cpus = &cpus[id];
505 links[id].num_cpus = 1;
506 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
507 "SSP%d Pin",
508 ssp_amp);
509 if (!links[id].cpus->dai_name)
510 goto devm_err;
511 id++;
512 }
513
514 /* BT audio offload */
515 if (sof_nau8825_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
516 int port = (sof_nau8825_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
517 SOF_BT_OFFLOAD_SSP_SHIFT;
518
519 links[id].id = id;
520 links[id].cpus = &cpus[id];
521 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
522 "SSP%d Pin", port);
523 if (!links[id].cpus->dai_name)
524 goto devm_err;
525 links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
526 if (!links[id].name)
527 goto devm_err;
528 links[id].codecs = &asoc_dummy_dlc;
529 links[id].num_codecs = 1;
530 links[id].platforms = platform_component;
531 links[id].num_platforms = ARRAY_SIZE(platform_component);
532 links[id].dpcm_playback = 1;
533 links[id].dpcm_capture = 1;
534 links[id].no_pcm = 1;
535 links[id].num_cpus = 1;
536 }
537
538 return links;
539 devm_err:
540 return NULL;
541 }
542
sof_audio_probe(struct platform_device * pdev)543 static int sof_audio_probe(struct platform_device *pdev)
544 {
545 struct snd_soc_dai_link *dai_links;
546 struct snd_soc_acpi_mach *mach;
547 struct sof_card_private *ctx;
548 int dmic_be_num, hdmi_num;
549 int ret, ssp_amp, ssp_codec;
550
551 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
552 if (!ctx)
553 return -ENOMEM;
554
555 if (pdev->id_entry && pdev->id_entry->driver_data)
556 sof_nau8825_quirk = (unsigned long)pdev->id_entry->driver_data;
557
558 mach = pdev->dev.platform_data;
559
560 /* A speaker amp might not be present when the quirk claims one is.
561 * Detect this via whether the machine driver match includes quirk_data.
562 */
563 if ((sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT) && !mach->quirk_data)
564 sof_nau8825_quirk &= ~SOF_SPEAKER_AMP_PRESENT;
565
566 dev_dbg(&pdev->dev, "sof_nau8825_quirk = %lx\n", sof_nau8825_quirk);
567
568 /* default number of DMIC DAI's */
569 dmic_be_num = 2;
570 hdmi_num = (sof_nau8825_quirk & SOF_NAU8825_NUM_HDMIDEV_MASK) >>
571 SOF_NAU8825_NUM_HDMIDEV_SHIFT;
572 /* default number of HDMI DAI's */
573 if (!hdmi_num)
574 hdmi_num = 3;
575
576 ssp_amp = (sof_nau8825_quirk & SOF_NAU8825_SSP_AMP_MASK) >>
577 SOF_NAU8825_SSP_AMP_SHIFT;
578
579 ssp_codec = sof_nau8825_quirk & SOF_NAU8825_SSP_CODEC_MASK;
580
581 /* compute number of dai links */
582 sof_audio_card_nau8825.num_links = 1 + dmic_be_num + hdmi_num;
583
584 if (sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT)
585 sof_audio_card_nau8825.num_links++;
586
587 if (sof_nau8825_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT)
588 max_98373_set_codec_conf(&sof_audio_card_nau8825);
589 else if (sof_nau8825_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
590 sof_rt1015p_codec_conf(&sof_audio_card_nau8825);
591
592 if (sof_nau8825_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
593 sof_audio_card_nau8825.num_links++;
594
595 dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
596 dmic_be_num, hdmi_num);
597 if (!dai_links)
598 return -ENOMEM;
599
600 sof_audio_card_nau8825.dai_link = dai_links;
601
602 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
603
604 sof_audio_card_nau8825.dev = &pdev->dev;
605
606 /* set platform name for each dailink */
607 ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_nau8825,
608 mach->mach_params.platform);
609 if (ret)
610 return ret;
611
612 snd_soc_card_set_drvdata(&sof_audio_card_nau8825, ctx);
613
614 return devm_snd_soc_register_card(&pdev->dev,
615 &sof_audio_card_nau8825);
616 }
617
618 static const struct platform_device_id board_ids[] = {
619 {
620 .name = "sof_nau8825",
621 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
622 SOF_NAU8825_NUM_HDMIDEV(4) |
623 SOF_BT_OFFLOAD_SSP(2) |
624 SOF_SSP_BT_OFFLOAD_PRESENT),
625
626 },
627 {
628 .name = "adl_rt1019p_8825",
629 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
630 SOF_SPEAKER_AMP_PRESENT |
631 SOF_RT1019P_SPEAKER_AMP_PRESENT |
632 SOF_NAU8825_SSP_AMP(2) |
633 SOF_NAU8825_NUM_HDMIDEV(4)),
634 },
635 {
636 .name = "adl_max98373_8825",
637 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
638 SOF_SPEAKER_AMP_PRESENT |
639 SOF_MAX98373_SPEAKER_AMP_PRESENT |
640 SOF_NAU8825_SSP_AMP(1) |
641 SOF_NAU8825_NUM_HDMIDEV(4) |
642 SOF_BT_OFFLOAD_SSP(2) |
643 SOF_SSP_BT_OFFLOAD_PRESENT),
644 },
645 {
646 /* The limitation of length of char array, shorten the name */
647 .name = "adl_mx98360a_8825",
648 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
649 SOF_SPEAKER_AMP_PRESENT |
650 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
651 SOF_NAU8825_SSP_AMP(1) |
652 SOF_NAU8825_NUM_HDMIDEV(4) |
653 SOF_BT_OFFLOAD_SSP(2) |
654 SOF_SSP_BT_OFFLOAD_PRESENT),
655
656 },
657 {
658 .name = "adl_rt1015p_8825",
659 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
660 SOF_SPEAKER_AMP_PRESENT |
661 SOF_RT1015P_SPEAKER_AMP_PRESENT |
662 SOF_NAU8825_SSP_AMP(1) |
663 SOF_NAU8825_NUM_HDMIDEV(4) |
664 SOF_BT_OFFLOAD_SSP(2) |
665 SOF_SSP_BT_OFFLOAD_PRESENT),
666 },
667 {
668 .name = "adl_nau8318_8825",
669 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
670 SOF_SPEAKER_AMP_PRESENT |
671 SOF_NAU8318_SPEAKER_AMP_PRESENT |
672 SOF_NAU8825_SSP_AMP(1) |
673 SOF_NAU8825_NUM_HDMIDEV(4) |
674 SOF_BT_OFFLOAD_SSP(2) |
675 SOF_SSP_BT_OFFLOAD_PRESENT),
676 },
677 {
678 .name = "rpl_max98373_8825",
679 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
680 SOF_SPEAKER_AMP_PRESENT |
681 SOF_MAX98373_SPEAKER_AMP_PRESENT |
682 SOF_NAU8825_SSP_AMP(1) |
683 SOF_NAU8825_NUM_HDMIDEV(4) |
684 SOF_BT_OFFLOAD_SSP(2) |
685 SOF_SSP_BT_OFFLOAD_PRESENT),
686 },
687 {
688 .name = "rpl_nau8318_8825",
689 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
690 SOF_SPEAKER_AMP_PRESENT |
691 SOF_NAU8318_SPEAKER_AMP_PRESENT |
692 SOF_NAU8825_SSP_AMP(1) |
693 SOF_NAU8825_NUM_HDMIDEV(4) |
694 SOF_BT_OFFLOAD_SSP(2) |
695 SOF_SSP_BT_OFFLOAD_PRESENT),
696 },
697 { }
698 };
699 MODULE_DEVICE_TABLE(platform, board_ids);
700
701 static struct platform_driver sof_audio = {
702 .probe = sof_audio_probe,
703 .driver = {
704 .name = "sof_nau8825",
705 .pm = &snd_soc_pm_ops,
706 },
707 .id_table = board_ids,
708 };
709 module_platform_driver(sof_audio)
710
711 /* Module information */
712 MODULE_DESCRIPTION("SOF Audio Machine driver for NAU8825");
713 MODULE_AUTHOR("David Lin <ctlin0@nuvoton.com>");
714 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
715 MODULE_LICENSE("GPL");
716 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
717 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
718 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);
719