1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2020 Intel Corporation
5 * sof_sdw - ASOC Machine driver for Intel SoundWire platforms
8 #include <linux/device.h>
10 #include <linux/module.h>
11 #include <linux/soundwire/sdw.h>
12 #include <linux/soundwire/sdw_type.h>
13 #include <sound/soc.h>
14 #include <sound/soc-acpi.h>
15 #include "sof_sdw_common.h"
16 #include "../../codecs/rt711.h"
18 unsigned long sof_sdw_quirk = RT711_JD1;
19 static int quirk_override = -1;
20 module_param_named(quirk, quirk_override, int, 0444);
21 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
23 #define INC_ID(BE, CPU, LINK) do { (BE)++; (CPU)++; (LINK)++; } while (0)
25 #define SDW_MAX_LINKS 4
27 /* To store SDW Pin index for each SoundWire link */
28 static unsigned int sdw_pin_index[SDW_MAX_LINKS];
30 static void log_quirks(struct device *dev)
32 if (SOF_JACK_JDSRC(sof_sdw_quirk))
33 dev_dbg(dev, "quirk realtek,jack-detect-source %ld\n",
34 SOF_JACK_JDSRC(sof_sdw_quirk));
35 if (sof_sdw_quirk & SOF_SDW_FOUR_SPK)
36 dev_dbg(dev, "quirk SOF_SDW_FOUR_SPK enabled\n");
37 if (sof_sdw_quirk & SOF_SDW_TGL_HDMI)
38 dev_dbg(dev, "quirk SOF_SDW_TGL_HDMI enabled\n");
39 if (sof_sdw_quirk & SOF_SDW_PCH_DMIC)
40 dev_dbg(dev, "quirk SOF_SDW_PCH_DMIC enabled\n");
41 if (SOF_SSP_GET_PORT(sof_sdw_quirk))
42 dev_dbg(dev, "SSP port %ld\n",
43 SOF_SSP_GET_PORT(sof_sdw_quirk));
44 if (sof_sdw_quirk & SOF_SDW_NO_AGGREGATION)
45 dev_dbg(dev, "quirk SOF_SDW_NO_AGGREGATION enabled\n");
48 static int sof_sdw_quirk_cb(const struct dmi_system_id *id)
50 sof_sdw_quirk = (unsigned long)id->driver_data;
54 static const struct dmi_system_id sof_sdw_quirk_table[] = {
55 /* CometLake devices */
57 .callback = sof_sdw_quirk_cb,
59 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
60 DMI_MATCH(DMI_PRODUCT_NAME, "CometLake Client"),
62 .driver_data = (void *)SOF_SDW_PCH_DMIC,
65 .callback = sof_sdw_quirk_cb,
67 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
68 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "09C6")
70 .driver_data = (void *)RT711_JD2,
73 /* early version of SKU 09C6 */
74 .callback = sof_sdw_quirk_cb,
76 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
77 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0983")
79 .driver_data = (void *)RT711_JD2,
82 .callback = sof_sdw_quirk_cb,
84 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
85 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "098F"),
87 .driver_data = (void *)(RT711_JD2 |
91 .callback = sof_sdw_quirk_cb,
93 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
94 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0990"),
96 .driver_data = (void *)(RT711_JD2 |
101 .callback = sof_sdw_quirk_cb,
103 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
104 DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"),
106 .driver_data = (void *)SOF_SDW_PCH_DMIC,
108 /* TigerLake devices */
110 .callback = sof_sdw_quirk_cb,
112 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
113 DMI_MATCH(DMI_PRODUCT_NAME,
114 "Tiger Lake Client Platform"),
116 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
119 SOF_SSP_PORT(SOF_I2S_SSP2)),
122 .callback = sof_sdw_quirk_cb,
124 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
125 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A3E")
127 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
131 /* another SKU of Dell Latitude 9520 */
132 .callback = sof_sdw_quirk_cb,
134 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
135 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A3F")
137 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
142 .callback = sof_sdw_quirk_cb,
144 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
145 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A5D")
147 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
152 .callback = sof_sdw_quirk_cb,
154 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
155 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A5E")
157 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
162 .callback = sof_sdw_quirk_cb,
164 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
165 DMI_MATCH(DMI_PRODUCT_NAME, "Volteer"),
167 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
170 SOF_BT_OFFLOAD_SSP(2) |
171 SOF_SSP_BT_OFFLOAD_PRESENT),
174 .callback = sof_sdw_quirk_cb,
176 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
177 DMI_MATCH(DMI_PRODUCT_NAME, "Ripto"),
179 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
185 * this entry covers multiple HP SKUs. The family name
186 * does not seem robust enough, so we use a partial
187 * match that ignores the product name suffix
188 * (e.g. 15-eb1xxx, 14t-ea000 or 13-aw2xxx)
190 .callback = sof_sdw_quirk_cb,
192 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
193 DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x360 Conv"),
195 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
201 * this entry covers HP Spectre x360 where the DMI information
204 .callback = sof_sdw_quirk_cb,
206 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
207 DMI_MATCH(DMI_BOARD_NAME, "8709"),
209 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
214 /* NUC15 'Bishop County' LAPBC510 and LAPBC710 skews */
215 .callback = sof_sdw_quirk_cb,
217 DMI_MATCH(DMI_SYS_VENDOR, "Intel(R) Client Systems"),
218 DMI_MATCH(DMI_PRODUCT_NAME, "LAPBC"),
220 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
225 /* NUC15 LAPBC710 skews */
226 .callback = sof_sdw_quirk_cb,
228 DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
229 DMI_MATCH(DMI_BOARD_NAME, "LAPBC710"),
231 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
236 /* NUC15 'Rooks County' LAPRC510 and LAPRC710 skews */
237 .callback = sof_sdw_quirk_cb,
239 DMI_MATCH(DMI_SYS_VENDOR, "Intel(R) Client Systems"),
240 DMI_MATCH(DMI_PRODUCT_NAME, "LAPRC"),
242 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
246 /* TigerLake-SDCA devices */
248 .callback = sof_sdw_quirk_cb,
250 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
251 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A32")
253 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
258 .callback = sof_sdw_quirk_cb,
260 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
261 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A45")
263 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
266 /* AlderLake devices */
268 .callback = sof_sdw_quirk_cb,
270 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
271 DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
273 .driver_data = (void *)(RT711_JD2_100K |
275 SOF_BT_OFFLOAD_SSP(2) |
276 SOF_SSP_BT_OFFLOAD_PRESENT),
279 .callback = sof_sdw_quirk_cb,
281 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
282 DMI_MATCH(DMI_PRODUCT_NAME, "Brya"),
284 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
287 SOF_BT_OFFLOAD_SSP(2) |
288 SOF_SSP_BT_OFFLOAD_PRESENT),
291 .callback = sof_sdw_quirk_cb,
293 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
294 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AF0")
296 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
301 .callback = sof_sdw_quirk_cb,
303 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
304 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AF3"),
307 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
311 .callback = sof_sdw_quirk_cb,
313 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
314 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AFE")
316 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
321 .callback = sof_sdw_quirk_cb,
323 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
324 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AFF")
326 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
331 .callback = sof_sdw_quirk_cb,
333 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
334 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B00")
336 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
341 .callback = sof_sdw_quirk_cb,
343 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
344 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B01")
346 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
351 .callback = sof_sdw_quirk_cb,
353 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
354 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B11")
356 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
361 .callback = sof_sdw_quirk_cb,
363 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
364 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B12")
366 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
371 .callback = sof_sdw_quirk_cb,
373 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
374 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B13"),
377 .driver_data = (void *)SOF_SDW_TGL_HDMI,
380 .callback = sof_sdw_quirk_cb,
382 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
383 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B14"),
386 .driver_data = (void *)SOF_SDW_TGL_HDMI,
390 .callback = sof_sdw_quirk_cb,
392 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
393 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B29"),
395 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
400 .callback = sof_sdw_quirk_cb,
402 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
403 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B34"),
406 .driver_data = (void *)SOF_SDW_TGL_HDMI,
409 .callback = sof_sdw_quirk_cb,
411 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
412 DMI_MATCH(DMI_PRODUCT_NAME, "OMEN by HP Gaming Laptop 16-k0xxx"),
414 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
417 /* RaptorLake devices */
419 .callback = sof_sdw_quirk_cb,
421 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
422 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0BDA")
424 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
429 .callback = sof_sdw_quirk_cb,
431 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
432 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C10"),
435 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
439 .callback = sof_sdw_quirk_cb,
441 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
442 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C11")
444 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
449 .callback = sof_sdw_quirk_cb,
451 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
452 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C40")
454 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
459 .callback = sof_sdw_quirk_cb,
461 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
462 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C4F")
464 .driver_data = (void *)(SOF_SDW_TGL_HDMI |
468 /* MeteorLake devices */
470 .callback = sof_sdw_quirk_cb,
472 DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_mtlrvp"),
474 .driver_data = (void *)(RT711_JD1),
477 .callback = sof_sdw_quirk_cb,
479 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
480 DMI_MATCH(DMI_PRODUCT_NAME, "Meteor Lake Client Platform"),
482 .driver_data = (void *)(RT711_JD2_100K),
485 .callback = sof_sdw_quirk_cb,
487 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
488 DMI_MATCH(DMI_PRODUCT_NAME, "Rex"),
490 .driver_data = (void *)(SOF_SDW_PCH_DMIC |
491 SOF_BT_OFFLOAD_SSP(1) |
492 SOF_SSP_BT_OFFLOAD_PRESENT),
494 /* LunarLake devices */
496 .callback = sof_sdw_quirk_cb,
498 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
499 DMI_MATCH(DMI_PRODUCT_NAME, "Lunar Lake Client Platform"),
501 .driver_data = (void *)(RT711_JD2),
506 static struct snd_soc_dai_link_component dmic_component[] = {
508 .name = "dmic-codec",
509 .dai_name = "dmic-hifi",
513 static struct snd_soc_dai_link_component platform_component[] = {
515 /* name might be overridden during probe */
516 .name = "0000:00:1f.3"
520 /* these wrappers are only needed to avoid typecast compilation errors */
521 int sdw_startup(struct snd_pcm_substream *substream)
523 return sdw_startup_stream(substream);
526 int sdw_prepare(struct snd_pcm_substream *substream)
528 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
529 struct sdw_stream_runtime *sdw_stream;
530 struct snd_soc_dai *dai;
532 /* Find stream from first CPU DAI */
533 dai = asoc_rtd_to_cpu(rtd, 0);
535 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
536 if (IS_ERR(sdw_stream)) {
537 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name);
538 return PTR_ERR(sdw_stream);
541 return sdw_prepare_stream(sdw_stream);
544 int sdw_trigger(struct snd_pcm_substream *substream, int cmd)
546 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
547 struct sdw_stream_runtime *sdw_stream;
548 struct snd_soc_dai *dai;
551 /* Find stream from first CPU DAI */
552 dai = asoc_rtd_to_cpu(rtd, 0);
554 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
555 if (IS_ERR(sdw_stream)) {
556 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name);
557 return PTR_ERR(sdw_stream);
561 case SNDRV_PCM_TRIGGER_START:
562 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
563 case SNDRV_PCM_TRIGGER_RESUME:
564 ret = sdw_enable_stream(sdw_stream);
567 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
568 case SNDRV_PCM_TRIGGER_SUSPEND:
569 case SNDRV_PCM_TRIGGER_STOP:
570 ret = sdw_disable_stream(sdw_stream);
578 dev_err(rtd->dev, "%s trigger %d failed: %d\n", __func__, cmd, ret);
583 int sdw_hw_params(struct snd_pcm_substream *substream,
584 struct snd_pcm_hw_params *params)
586 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
587 int ch = params_channels(params);
588 struct snd_soc_dai *codec_dai;
589 struct snd_soc_dai *cpu_dai;
590 unsigned int ch_mask;
596 if (!rtd->dai_link->codec_ch_maps)
599 /* Identical data will be sent to all codecs in playback */
600 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
601 ch_mask = GENMASK(ch - 1, 0);
604 num_codecs = rtd->dai_link->num_codecs;
606 if (ch < num_codecs || ch % num_codecs != 0) {
607 dev_err(rtd->dev, "Channels number %d is invalid when codec number = %d\n",
612 ch_mask = GENMASK(ch / num_codecs - 1, 0);
613 step = hweight_long(ch_mask);
618 * The captured data will be combined from each cpu DAI if the dai
619 * link has more than one codec DAIs. Set codec channel mask and
620 * ASoC will set the corresponding channel numbers for each cpu dai.
622 for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
623 for_each_rtd_codec_dais(rtd, j, codec_dai) {
624 if (rtd->dai_link->codec_ch_maps[j].connected_cpu_id != i)
626 rtd->dai_link->codec_ch_maps[j].ch_mask = ch_mask << (j * step);
632 int sdw_hw_free(struct snd_pcm_substream *substream)
634 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
635 struct sdw_stream_runtime *sdw_stream;
636 struct snd_soc_dai *dai;
638 /* Find stream from first CPU DAI */
639 dai = asoc_rtd_to_cpu(rtd, 0);
641 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
642 if (IS_ERR(sdw_stream)) {
643 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name);
644 return PTR_ERR(sdw_stream);
647 return sdw_deprepare_stream(sdw_stream);
650 void sdw_shutdown(struct snd_pcm_substream *substream)
652 sdw_shutdown_stream(substream);
655 static const struct snd_soc_ops sdw_ops = {
656 .startup = sdw_startup,
657 .prepare = sdw_prepare,
658 .trigger = sdw_trigger,
659 .hw_params = sdw_hw_params,
660 .hw_free = sdw_hw_free,
661 .shutdown = sdw_shutdown,
664 static struct sof_sdw_codec_info codec_info_list[] = {
669 .direction = {true, true},
670 .dai_name = "rt700-aif1",
671 .dai_type = SOF_SDW_DAI_TYPE_JACK,
672 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
673 .init = sof_sdw_rt700_init,
683 .direction = {true, true},
684 .dai_name = "rt711-sdca-aif1",
685 .dai_type = SOF_SDW_DAI_TYPE_JACK,
686 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
687 .init = sof_sdw_rt_sdca_jack_init,
688 .exit = sof_sdw_rt_sdca_jack_exit,
698 .direction = {true, true},
699 .dai_name = "rt711-aif1",
700 .dai_type = SOF_SDW_DAI_TYPE_JACK,
701 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
702 .init = sof_sdw_rt711_init,
703 .exit = sof_sdw_rt711_exit,
713 .direction = {true, true},
714 .dai_name = "rt712-sdca-aif1",
715 .dai_type = SOF_SDW_DAI_TYPE_JACK,
716 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
717 .init = sof_sdw_rt_sdca_jack_init,
718 .exit = sof_sdw_rt_sdca_jack_exit,
721 .direction = {true, false},
722 .dai_name = "rt712-sdca-aif2",
723 .dai_type = SOF_SDW_DAI_TYPE_AMP,
724 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_UNUSED_DAI_ID},
725 .init = sof_sdw_rt712_spk_init,
735 .direction = {false, true},
736 .dai_name = "rt712-sdca-dmic-aif1",
737 .dai_type = SOF_SDW_DAI_TYPE_MIC,
738 .dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
739 .init = sof_sdw_rt712_sdca_dmic_init,
749 .direction = {true, true},
750 .dai_name = "rt712-sdca-aif1",
751 .dai_type = SOF_SDW_DAI_TYPE_JACK,
752 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
753 .init = sof_sdw_rt_sdca_jack_init,
754 .exit = sof_sdw_rt_sdca_jack_exit,
764 .direction = {false, true},
765 .dai_name = "rt712-sdca-dmic-aif1",
766 .dai_type = SOF_SDW_DAI_TYPE_MIC,
767 .dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
768 .init = sof_sdw_rt712_sdca_dmic_init,
775 .acpi_id = "10EC1308",
778 .direction = {true, false},
779 .dai_name = "rt1308-aif",
780 .dai_type = SOF_SDW_DAI_TYPE_AMP,
781 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_UNUSED_DAI_ID},
782 .init = sof_sdw_rt_amp_init,
783 .exit = sof_sdw_rt_amp_exit,
787 .ops = &sof_sdw_rt1308_i2s_ops,
793 .direction = {true, true},
794 .dai_name = "rt1316-aif",
795 .dai_type = SOF_SDW_DAI_TYPE_AMP,
796 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_AMP_IN_DAI_ID},
797 .init = sof_sdw_rt_amp_init,
798 .exit = sof_sdw_rt_amp_exit,
807 .direction = {true, true},
808 .dai_name = "rt1318-aif",
809 .dai_type = SOF_SDW_DAI_TYPE_AMP,
810 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_AMP_IN_DAI_ID},
811 .init = sof_sdw_rt_amp_init,
812 .exit = sof_sdw_rt_amp_exit,
820 .ignore_pch_dmic = true,
823 .direction = {false, true},
824 .dai_name = "rt715-aif2",
825 .dai_type = SOF_SDW_DAI_TYPE_MIC,
826 .dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
827 .init = sof_sdw_rt715_sdca_init,
835 .ignore_pch_dmic = true,
838 .direction = {false, true},
839 .dai_name = "rt715-aif2",
840 .dai_type = SOF_SDW_DAI_TYPE_MIC,
841 .dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
842 .init = sof_sdw_rt715_sdca_init,
850 .ignore_pch_dmic = true,
853 .direction = {false, true},
854 .dai_name = "rt715-aif2",
855 .dai_type = SOF_SDW_DAI_TYPE_MIC,
856 .dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
857 .init = sof_sdw_rt715_init,
865 .ignore_pch_dmic = true,
868 .direction = {false, true},
869 .dai_name = "rt715-aif2",
870 .dai_type = SOF_SDW_DAI_TYPE_MIC,
871 .dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
872 .init = sof_sdw_rt715_init,
881 .direction = {true, true},
882 .dai_name = "max98373-aif1",
883 .dai_type = SOF_SDW_DAI_TYPE_AMP,
884 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_AMP_IN_DAI_ID},
885 .init = sof_sdw_maxim_init,
894 .direction = {true, false},
895 .dai_name = "max98363-aif1",
896 .dai_type = SOF_SDW_DAI_TYPE_AMP,
897 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_UNUSED_DAI_ID},
898 .init = sof_sdw_maxim_init,
907 .direction = {true, true},
908 .dai_name = "rt5682-sdw",
909 .dai_type = SOF_SDW_DAI_TYPE_JACK,
910 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
911 .init = sof_sdw_rt5682_init,
920 .direction = {true, true},
921 .dai_name = "cs35l56-sdw1",
922 .dai_type = SOF_SDW_DAI_TYPE_AMP,
923 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_AMP_IN_DAI_ID},
924 .init = sof_sdw_cs_amp_init,
933 .direction = {true, true},
934 .dai_name = "cs42l42-sdw",
935 .dai_type = SOF_SDW_DAI_TYPE_JACK,
936 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
937 .init = sof_sdw_cs42l42_init,
943 .part_id = 0xaaaa, /* generic codec mockup */
947 .direction = {true, true},
948 .dai_name = "sdw-mockup-aif1",
949 .dai_type = SOF_SDW_DAI_TYPE_JACK,
950 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
957 .part_id = 0xaa55, /* headset codec mockup */
961 .direction = {true, true},
962 .dai_name = "sdw-mockup-aif1",
963 .dai_type = SOF_SDW_DAI_TYPE_JACK,
964 .dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
971 .part_id = 0x55aa, /* amplifier mockup */
975 .direction = {true, true},
976 .dai_name = "sdw-mockup-aif1",
977 .dai_type = SOF_SDW_DAI_TYPE_AMP,
978 .dailink = {SDW_AMP_OUT_DAI_ID, SDW_AMP_IN_DAI_ID},
989 .dai_name = "sdw-mockup-aif1",
990 .direction = {false, true},
991 .dai_type = SOF_SDW_DAI_TYPE_MIC,
992 .dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
1000 static inline int find_codec_info_part(const u64 adr)
1002 unsigned int part_id, sdw_version;
1005 part_id = SDW_PART_ID(adr);
1006 sdw_version = SDW_VERSION(adr);
1007 for (i = 0; i < ARRAY_SIZE(codec_info_list); i++)
1009 * A codec info is for all sdw version with the part id if
1010 * version_id is not specified in the codec info.
1012 if (part_id == codec_info_list[i].part_id &&
1013 (!codec_info_list[i].version_id ||
1014 sdw_version == codec_info_list[i].version_id))
1021 static inline int find_codec_info_acpi(const u8 *acpi_id)
1028 for (i = 0; i < ARRAY_SIZE(codec_info_list); i++)
1029 if (!memcmp(codec_info_list[i].acpi_id, acpi_id, ACPI_ID_LEN))
1036 * get BE dailink number and CPU DAI number based on sdw link adr.
1037 * Since some sdw slaves may be aggregated, the CPU DAI number
1038 * may be larger than the number of BE dailinks.
1040 static int get_dailink_info(struct device *dev,
1041 const struct snd_soc_acpi_link_adr *adr_link,
1042 int *sdw_be_num, int *sdw_cpu_dai_num, int *codecs_num)
1044 bool group_visited[SDW_MAX_GROUPS];
1045 bool no_aggregation;
1049 no_aggregation = sof_sdw_quirk & SOF_SDW_NO_AGGREGATION;
1050 *sdw_cpu_dai_num = 0;
1056 for (i = 0; i < SDW_MAX_GROUPS; i++)
1057 group_visited[i] = false;
1059 for (; adr_link->num_adr; adr_link++) {
1060 const struct snd_soc_acpi_endpoint *endpoint;
1061 struct sof_sdw_codec_info *codec_info;
1066 /* make sure the link mask has a single bit set */
1067 if (!is_power_of_2(adr_link->mask))
1070 for (i = 0; i < adr_link->num_adr; i++) {
1071 adr = adr_link->adr_d[i].adr;
1072 codec_index = find_codec_info_part(adr);
1073 if (codec_index < 0)
1076 codec_info = &codec_info_list[codec_index];
1078 *codecs_num += codec_info->dai_num;
1080 if (!adr_link->adr_d[i].name_prefix) {
1081 dev_err(dev, "codec 0x%llx does not have a name prefix\n",
1082 adr_link->adr_d[i].adr);
1086 endpoint = adr_link->adr_d[i].endpoints;
1087 if (endpoint->aggregated && !endpoint->group_id) {
1088 dev_err(dev, "invalid group id on link %x\n",
1093 for (j = 0; j < codec_info->dai_num; j++) {
1094 /* count DAI number for playback and capture */
1095 for_each_pcm_streams(stream) {
1096 if (!codec_info->dais[j].direction[stream])
1099 (*sdw_cpu_dai_num)++;
1101 /* count BE for each non-aggregated slave or group */
1102 if (!endpoint->aggregated || no_aggregation ||
1103 !group_visited[endpoint->group_id])
1108 if (endpoint->aggregated)
1109 group_visited[endpoint->group_id] = true;
1116 static void init_dai_link(struct device *dev, struct snd_soc_dai_link *dai_links,
1117 int be_id, char *name, int playback, int capture,
1118 struct snd_soc_dai_link_component *cpus, int cpus_num,
1119 struct snd_soc_dai_link_component *codecs, int codecs_num,
1120 int (*init)(struct snd_soc_pcm_runtime *rtd),
1121 const struct snd_soc_ops *ops)
1123 dev_dbg(dev, "create dai link %s, id %d\n", name, be_id);
1124 dai_links->id = be_id;
1125 dai_links->name = name;
1126 dai_links->platforms = platform_component;
1127 dai_links->num_platforms = ARRAY_SIZE(platform_component);
1128 dai_links->no_pcm = 1;
1129 dai_links->cpus = cpus;
1130 dai_links->num_cpus = cpus_num;
1131 dai_links->codecs = codecs;
1132 dai_links->num_codecs = codecs_num;
1133 dai_links->dpcm_playback = playback;
1134 dai_links->dpcm_capture = capture;
1135 dai_links->init = init;
1136 dai_links->ops = ops;
1139 static bool is_unique_device(const struct snd_soc_acpi_link_adr *adr_link,
1140 unsigned int sdw_version,
1141 unsigned int mfg_id,
1142 unsigned int part_id,
1143 unsigned int class_id,
1148 for (i = 0; i < adr_link->num_adr; i++) {
1149 unsigned int sdw1_version, mfg1_id, part1_id, class1_id;
1153 if (i == index_in_link)
1156 adr = adr_link->adr_d[i].adr;
1158 sdw1_version = SDW_VERSION(adr);
1159 mfg1_id = SDW_MFG_ID(adr);
1160 part1_id = SDW_PART_ID(adr);
1161 class1_id = SDW_CLASS_ID(adr);
1163 if (sdw_version == sdw1_version &&
1164 mfg_id == mfg1_id &&
1165 part_id == part1_id &&
1166 class_id == class1_id)
1173 static int fill_sdw_codec_dlc(struct device *dev,
1174 const struct snd_soc_acpi_link_adr *adr_link,
1175 struct snd_soc_dai_link_component *codec,
1176 int adr_index, int dai_index)
1178 unsigned int sdw_version, unique_id, mfg_id, link_id, part_id, class_id;
1179 u64 adr = adr_link->adr_d[adr_index].adr;
1182 codec_index = find_codec_info_part(adr);
1183 if (codec_index < 0)
1186 sdw_version = SDW_VERSION(adr);
1187 link_id = SDW_DISCO_LINK_ID(adr);
1188 unique_id = SDW_UNIQUE_ID(adr);
1189 mfg_id = SDW_MFG_ID(adr);
1190 part_id = SDW_PART_ID(adr);
1191 class_id = SDW_CLASS_ID(adr);
1193 if (codec_info_list[codec_index].codec_name)
1194 codec->name = devm_kstrdup(dev,
1195 codec_info_list[codec_index].codec_name,
1197 else if (is_unique_device(adr_link, sdw_version, mfg_id, part_id,
1198 class_id, adr_index))
1199 codec->name = devm_kasprintf(dev, GFP_KERNEL,
1200 "sdw:%01x:%04x:%04x:%02x", link_id,
1201 mfg_id, part_id, class_id);
1203 codec->name = devm_kasprintf(dev, GFP_KERNEL,
1204 "sdw:%01x:%04x:%04x:%02x:%01x", link_id,
1205 mfg_id, part_id, class_id, unique_id);
1210 codec->dai_name = codec_info_list[codec_index].dais[dai_index].dai_name;
1215 static int set_codec_init_func(struct snd_soc_card *card,
1216 const struct snd_soc_acpi_link_adr *adr_link,
1217 struct snd_soc_dai_link *dai_links,
1218 bool playback, int group_id, int adr_index, int dai_index)
1224 * Initialize the codec. If codec is part of an aggregated
1225 * group (group_id>0), initialize all codecs belonging to
1227 * The first link should start with adr_link->adr_d[adr_index]
1228 * because that is the device that we want to initialize and
1229 * we should end immediately if it is not aggregated (group_id=0)
1231 for ( ; i < adr_link->num_adr; i++) {
1234 codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
1235 if (codec_index < 0)
1238 /* The group_id is > 0 iff the codec is aggregated */
1239 if (adr_link->adr_d[i].endpoints->group_id != group_id)
1242 if (codec_info_list[codec_index].dais[dai_index].init)
1243 codec_info_list[codec_index].dais[dai_index].init(card,
1246 &codec_info_list[codec_index],
1254 } while (adr_link->mask);
1260 * check endpoint status in slaves and gather link ID for all slaves in
1261 * the same group to generate different CPU DAI. Now only support
1262 * one sdw link with all slaves set with only single group id.
1264 * one slave on one sdw link with aggregated = 0
1265 * one sdw BE DAI <---> one-cpu DAI <---> one-codec DAI
1267 * two or more slaves on one sdw link with aggregated = 0
1268 * one sdw BE DAI <---> one-cpu DAI <---> multi-codec DAIs
1270 * multiple links with multiple slaves with aggregated = 1
1271 * one sdw BE DAI <---> 1 .. N CPU DAIs <----> 1 .. N codec DAIs
1273 static int get_slave_info(const struct snd_soc_acpi_link_adr *adr_link,
1274 struct device *dev, int *cpu_dai_id, int *cpu_dai_num,
1275 int *codec_num, unsigned int *group_id,
1278 bool no_aggregation = sof_sdw_quirk & SOF_SDW_NO_AGGREGATION;
1281 if (!adr_link->adr_d[adr_index].endpoints->aggregated || no_aggregation) {
1282 cpu_dai_id[0] = ffs(adr_link->mask) - 1;
1291 *group_id = adr_link->adr_d[adr_index].endpoints->group_id;
1293 /* Count endpoints with the same group_id in the adr_link */
1294 for (; adr_link && adr_link->num_adr; adr_link++) {
1295 unsigned int link_codecs = 0;
1297 for (i = 0; i < adr_link->num_adr; i++) {
1298 if (adr_link->adr_d[i].endpoints->aggregated &&
1299 adr_link->adr_d[i].endpoints->group_id == *group_id)
1304 *codec_num += link_codecs;
1306 if (*cpu_dai_num >= SDW_MAX_CPU_DAIS) {
1307 dev_err(dev, "cpu_dai_id array overflowed\n");
1311 cpu_dai_id[(*cpu_dai_num)++] = ffs(adr_link->mask) - 1;
1318 static void set_dailink_map(struct snd_soc_dai_link_codec_ch_map *sdw_codec_ch_maps,
1319 int codec_num, int cpu_num)
1324 step = codec_num / cpu_num;
1325 for (i = 0; i < codec_num; i++)
1326 sdw_codec_ch_maps[i].connected_cpu_id = i / step;
1329 static const char * const type_strings[] = {"SimpleJack", "SmartAmp", "SmartMic"};
1331 static int create_sdw_dailink(struct snd_soc_card *card, int *link_index,
1332 struct snd_soc_dai_link *dai_links,
1333 int sdw_be_num, int sdw_cpu_dai_num,
1334 struct snd_soc_dai_link_component *cpus,
1335 const struct snd_soc_acpi_link_adr *adr_link,
1336 int *cpu_id, struct snd_soc_codec_conf *codec_conf,
1337 int codec_count, int *be_id,
1338 int *codec_conf_index,
1339 bool *ignore_pch_dmic,
1340 bool append_dai_type,
1344 struct device *dev = card->dev;
1345 const struct snd_soc_acpi_link_adr *adr_link_next;
1346 struct snd_soc_dai_link_component *codecs;
1347 struct sof_sdw_codec_info *codec_info;
1348 int cpu_dai_id[SDW_MAX_CPU_DAIS];
1349 int cpu_dai_num, cpu_dai_index;
1350 unsigned int group_id;
1351 int codec_dlc_index = 0;
1359 ret = get_slave_info(adr_link, dev, cpu_dai_id, &cpu_dai_num, &codec_num,
1360 &group_id, adr_index);
1364 codecs = devm_kcalloc(dev, codec_num, sizeof(*codecs), GFP_KERNEL);
1368 /* generate codec name on different links in the same group */
1370 for (adr_link_next = adr_link; adr_link_next && adr_link_next->num_adr &&
1371 i < cpu_dai_num; adr_link_next++) {
1372 /* skip the link excluded by this processed group */
1373 if (cpu_dai_id[i] != ffs(adr_link_next->mask) - 1)
1376 /* j reset after loop, adr_index only applies to first link */
1377 for (; j < adr_link_next->num_adr; j++) {
1378 const struct snd_soc_acpi_endpoint *endpoints;
1380 endpoints = adr_link_next->adr_d[j].endpoints;
1382 if (group_id && (!endpoints->aggregated ||
1383 endpoints->group_id != group_id))
1387 if (*codec_conf_index >= codec_count) {
1388 dev_err(dev, "codec_conf array overflowed\n");
1392 ret = fill_sdw_codec_dlc(dev, adr_link_next,
1393 &codecs[codec_dlc_index],
1398 codec_conf[*codec_conf_index].dlc = codecs[codec_dlc_index];
1399 codec_conf[*codec_conf_index].name_prefix =
1400 adr_link_next->adr_d[j].name_prefix;
1403 (*codec_conf_index)++;
1407 /* check next link to create codec dai in the processed group */
1411 /* find codec info to create BE DAI */
1412 codec_index = find_codec_info_part(adr_link->adr_d[adr_index].adr);
1413 if (codec_index < 0)
1415 codec_info = &codec_info_list[codec_index];
1417 if (codec_info->ignore_pch_dmic)
1418 *ignore_pch_dmic = true;
1420 cpu_dai_index = *cpu_id;
1421 for_each_pcm_streams(stream) {
1422 struct snd_soc_dai_link_codec_ch_map *sdw_codec_ch_maps;
1423 char *name, *cpu_name;
1424 int playback, capture;
1425 static const char * const sdw_stream_name[] = {
1428 "SDW%d-Playback-%s",
1432 if (!codec_info->dais[dai_index].direction[stream])
1435 *be_id = codec_info->dais[dai_index].dailink[stream];
1437 dev_err(dev, "Invalid dailink id %d\n", *be_id);
1441 sdw_codec_ch_maps = devm_kcalloc(dev, codec_num,
1442 sizeof(*sdw_codec_ch_maps), GFP_KERNEL);
1443 if (!sdw_codec_ch_maps)
1446 /* create stream name according to first link id */
1447 if (append_dai_type) {
1448 name = devm_kasprintf(dev, GFP_KERNEL,
1449 sdw_stream_name[stream + 2], cpu_dai_id[0],
1450 type_strings[codec_info->dais[dai_index].dai_type]);
1452 name = devm_kasprintf(dev, GFP_KERNEL,
1453 sdw_stream_name[stream], cpu_dai_id[0]);
1459 * generate CPU DAI name base on the sdw link ID and
1460 * PIN ID with offset of 2 according to sdw dai driver.
1462 for (k = 0; k < cpu_dai_num; k++) {
1463 cpu_name = devm_kasprintf(dev, GFP_KERNEL,
1464 "SDW%d Pin%d", cpu_dai_id[k],
1465 sdw_pin_index[cpu_dai_id[k]]++);
1469 if (cpu_dai_index >= sdw_cpu_dai_num) {
1470 dev_err(dev, "invalid cpu dai index %d\n",
1475 cpus[cpu_dai_index++].dai_name = cpu_name;
1479 * We create sdw dai links at first stage, so link index should
1480 * not be larger than sdw_be_num
1482 if (*link_index >= sdw_be_num) {
1483 dev_err(dev, "invalid dai link index %d\n", *link_index);
1487 if (*cpu_id >= sdw_cpu_dai_num) {
1488 dev_err(dev, "invalid cpu dai index %d\n", *cpu_id);
1492 playback = (stream == SNDRV_PCM_STREAM_PLAYBACK);
1493 capture = (stream == SNDRV_PCM_STREAM_CAPTURE);
1494 init_dai_link(dev, dai_links + *link_index, (*be_id)++, name,
1496 cpus + *cpu_id, cpu_dai_num,
1501 * SoundWire DAILINKs use 'stream' functions and Bank Switch operations
1502 * based on wait_for_completion(), tag them as 'nonatomic'.
1504 dai_links[*link_index].nonatomic = true;
1506 set_dailink_map(sdw_codec_ch_maps, codec_num, cpu_dai_num);
1507 dai_links[*link_index].codec_ch_maps = sdw_codec_ch_maps;
1508 ret = set_codec_init_func(card, adr_link, dai_links + (*link_index)++,
1509 playback, group_id, adr_index, dai_index);
1511 dev_err(dev, "failed to init codec %d\n", codec_index);
1515 *cpu_id += cpu_dai_num;
1521 #define IDISP_CODEC_MASK 0x4
1523 static int sof_card_dai_links_create(struct snd_soc_card *card)
1525 struct device *dev = card->dev;
1526 struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev);
1527 int sdw_be_num = 0, ssp_num = 0, dmic_num = 0, hdmi_num = 0, bt_num = 0;
1528 struct mc_private *ctx = snd_soc_card_get_drvdata(card);
1529 struct snd_soc_dai_link_component *idisp_components;
1530 struct snd_soc_dai_link_component *ssp_components;
1531 struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params;
1532 const struct snd_soc_acpi_link_adr *adr_link = mach_params->links;
1533 bool aggregation = !(sof_sdw_quirk & SOF_SDW_NO_AGGREGATION);
1534 struct snd_soc_dai_link_component *cpus;
1535 struct snd_soc_codec_conf *codec_conf;
1536 bool append_dai_type = false;
1537 bool ignore_pch_dmic = false;
1538 int codec_conf_num = 0;
1539 int codec_conf_index = 0;
1540 bool group_generated[SDW_MAX_GROUPS] = { };
1541 int ssp_codec_index, ssp_mask;
1542 struct snd_soc_dai_link *dai_links;
1543 int num_links, link_index = 0;
1544 char *name, *cpu_name;
1545 int total_cpu_dai_num;
1546 int sdw_cpu_dai_num;
1547 int i, j, be_id = 0;
1552 ret = get_dailink_info(dev, adr_link, &sdw_be_num, &sdw_cpu_dai_num,
1555 dev_err(dev, "failed to get sdw link info %d\n", ret);
1560 * on generic tgl platform, I2S or sdw mode is supported
1561 * based on board rework. A ACPI device is registered in
1562 * system only when I2S mode is supported, not sdw mode.
1563 * Here check ACPI ID to confirm I2S is supported.
1565 ssp_codec_index = find_codec_info_acpi(mach->id);
1566 if (ssp_codec_index >= 0) {
1567 ssp_mask = SOF_SSP_GET_PORT(sof_sdw_quirk);
1568 ssp_num = hweight_long(ssp_mask);
1571 if (mach_params->codec_mask & IDISP_CODEC_MASK) {
1572 ctx->idisp_codec = true;
1574 if (sof_sdw_quirk & SOF_SDW_TGL_HDMI)
1575 hdmi_num = SOF_TGL_HDMI_COUNT;
1577 hdmi_num = SOF_PRE_TGL_HDMI_COUNT;
1580 /* enable dmic01 & dmic16k */
1581 if (sof_sdw_quirk & SOF_SDW_PCH_DMIC || mach_params->dmic_num)
1584 if (sof_sdw_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
1587 dev_dbg(dev, "sdw %d, ssp %d, dmic %d, hdmi %d, bt: %d\n",
1588 sdw_be_num, ssp_num, dmic_num, hdmi_num, bt_num);
1590 /* allocate BE dailinks */
1591 num_links = sdw_be_num + ssp_num + dmic_num + hdmi_num + bt_num;
1592 dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL);
1596 /* allocated CPU DAIs */
1597 total_cpu_dai_num = sdw_cpu_dai_num + ssp_num + dmic_num + hdmi_num + bt_num;
1598 cpus = devm_kcalloc(dev, total_cpu_dai_num, sizeof(*cpus), GFP_KERNEL);
1602 /* allocate codec conf, will be populated when dailinks are created */
1603 codec_conf = devm_kcalloc(dev, codec_conf_num, sizeof(*codec_conf),
1612 for (i = 0; i < SDW_MAX_LINKS; i++)
1613 sdw_pin_index[i] = SDW_INTEL_BIDIR_PDI_BASE;
1615 for (; adr_link->num_adr; adr_link++) {
1617 * If there are two or more different devices on the same sdw link, we have to
1618 * append the codec type to the dai link name to prevent duplicated dai link name.
1619 * The same type devices on the same sdw link will be in the same
1620 * snd_soc_acpi_adr_device array. They won't be described in different adr_links.
1622 for (i = 0; i < adr_link->num_adr; i++) {
1623 /* find codec info to get dai_num */
1624 codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
1625 if (codec_index < 0)
1627 if (codec_info_list[codec_index].dai_num > 1) {
1628 append_dai_type = true;
1631 for (j = 0; j < i; j++) {
1632 if ((SDW_PART_ID(adr_link->adr_d[i].adr) !=
1633 SDW_PART_ID(adr_link->adr_d[j].adr)) ||
1634 (SDW_MFG_ID(adr_link->adr_d[i].adr) !=
1635 SDW_MFG_ID(adr_link->adr_d[j].adr))) {
1636 append_dai_type = true;
1644 /* generate DAI links by each sdw link */
1645 for (adr_link = mach_params->links ; adr_link->num_adr; adr_link++) {
1646 for (i = 0; i < adr_link->num_adr; i++) {
1647 const struct snd_soc_acpi_endpoint *endpoint;
1649 endpoint = adr_link->adr_d[i].endpoints;
1651 /* this group has been generated */
1652 if (endpoint->aggregated &&
1653 group_generated[endpoint->group_id])
1656 /* find codec info to get dai_num */
1657 codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
1658 if (codec_index < 0)
1661 for (j = 0; j < codec_info_list[codec_index].dai_num ; j++) {
1662 ret = create_sdw_dailink(card, &link_index, dai_links,
1663 sdw_be_num, sdw_cpu_dai_num, cpus,
1665 codec_conf, codec_conf_num,
1666 &be_id, &codec_conf_index,
1667 &ignore_pch_dmic, append_dai_type, i, j);
1669 dev_err(dev, "failed to create dai link %d\n", link_index);
1674 if (aggregation && endpoint->aggregated)
1675 group_generated[endpoint->group_id] = true;
1684 for (i = 0, j = 0; ssp_mask; i++, ssp_mask >>= 1) {
1685 struct sof_sdw_codec_info *info;
1686 int playback, capture;
1689 if (!(ssp_mask & 0x1))
1692 name = devm_kasprintf(dev, GFP_KERNEL,
1697 cpu_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", i);
1701 ssp_components = devm_kzalloc(dev, sizeof(*ssp_components),
1703 if (!ssp_components)
1706 info = &codec_info_list[ssp_codec_index];
1707 codec_name = devm_kasprintf(dev, GFP_KERNEL, "i2c-%s:0%d",
1708 info->acpi_id, j++);
1712 ssp_components->name = codec_name;
1713 /* TODO: support multi codec dai on SSP when it is needed */
1714 ssp_components->dai_name = info->dais[0].dai_name;
1715 cpus[cpu_id].dai_name = cpu_name;
1717 playback = info->dais[0].direction[SNDRV_PCM_STREAM_PLAYBACK];
1718 capture = info->dais[0].direction[SNDRV_PCM_STREAM_CAPTURE];
1719 init_dai_link(dev, dai_links + link_index, be_id, name,
1725 ret = info->dais[0].init(card, NULL, dai_links + link_index, info, 0);
1729 INC_ID(be_id, cpu_id, link_index);
1735 if (ignore_pch_dmic) {
1736 dev_warn(dev, "Ignoring PCH DMIC\n");
1739 cpus[cpu_id].dai_name = "DMIC01 Pin";
1740 init_dai_link(dev, dai_links + link_index, be_id, "dmic01",
1741 0, 1, // DMIC only supports capture
1744 sof_sdw_dmic_init, NULL);
1745 INC_ID(be_id, cpu_id, link_index);
1747 cpus[cpu_id].dai_name = "DMIC16k Pin";
1748 init_dai_link(dev, dai_links + link_index, be_id, "dmic16k",
1749 0, 1, // DMIC only supports capture
1752 /* don't call sof_sdw_dmic_init() twice */
1754 INC_ID(be_id, cpu_id, link_index);
1760 idisp_components = devm_kcalloc(dev, hdmi_num,
1761 sizeof(*idisp_components),
1763 if (!idisp_components)
1767 for (i = 0; i < hdmi_num; i++) {
1768 name = devm_kasprintf(dev, GFP_KERNEL,
1773 if (ctx->idisp_codec) {
1774 idisp_components[i].name = "ehdaudio0D2";
1775 idisp_components[i].dai_name = devm_kasprintf(dev,
1777 "intel-hdmi-hifi%d",
1779 if (!idisp_components[i].dai_name)
1782 idisp_components[i] = asoc_dummy_dlc;
1785 cpu_name = devm_kasprintf(dev, GFP_KERNEL,
1786 "iDisp%d Pin", i + 1);
1790 cpus[cpu_id].dai_name = cpu_name;
1791 init_dai_link(dev, dai_links + link_index, be_id, name,
1792 1, 0, // HDMI only supports playback
1794 idisp_components + i, 1,
1795 sof_sdw_hdmi_init, NULL);
1796 INC_ID(be_id, cpu_id, link_index);
1799 if (sof_sdw_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
1800 int port = (sof_sdw_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
1801 SOF_BT_OFFLOAD_SSP_SHIFT;
1803 name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
1807 cpu_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", port);
1811 cpus[cpu_id].dai_name = cpu_name;
1812 init_dai_link(dev, dai_links + link_index, be_id, name, 1, 1,
1813 cpus + cpu_id, 1, &asoc_dummy_dlc, 1, NULL, NULL);
1816 card->dai_link = dai_links;
1817 card->num_links = num_links;
1819 card->codec_conf = codec_conf;
1820 card->num_configs = codec_conf_num;
1825 static int sof_sdw_card_late_probe(struct snd_soc_card *card)
1827 struct mc_private *ctx = snd_soc_card_get_drvdata(card);
1831 for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) {
1832 if (codec_info_list[i].codec_card_late_probe) {
1833 ret = codec_info_list[i].codec_card_late_probe(card);
1840 if (ctx->idisp_codec)
1841 ret = sof_sdw_hdmi_card_late_probe(card);
1847 static const char sdw_card_long_name[] = "Intel Soundwire SOF";
1849 static struct snd_soc_card card_sof_sdw = {
1850 .name = "soundwire",
1851 .owner = THIS_MODULE,
1852 .late_probe = sof_sdw_card_late_probe,
1855 /* helper to get the link that the codec DAI is used */
1856 static struct snd_soc_dai_link *mc_find_codec_dai_used(struct snd_soc_card *card,
1857 const char *dai_name)
1859 struct snd_soc_dai_link *dai_link;
1863 for_each_card_prelinks(card, i, dai_link) {
1864 for (j = 0; j < dai_link->num_codecs; j++) {
1865 /* Check each codec in a link */
1866 if (!strcmp(dai_link->codecs[j].dai_name, dai_name))
1873 static void mc_dailink_exit_loop(struct snd_soc_card *card)
1875 struct snd_soc_dai_link *dai_link;
1879 for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) {
1880 for (j = 0; j < codec_info_list[i].dai_num; j++) {
1881 /* Check each dai in codec_info_lis to see if it is used in the link */
1882 if (!codec_info_list[i].dais[j].exit)
1885 * We don't need to call .exit function if there is no matched
1888 dai_link = mc_find_codec_dai_used(card,
1889 codec_info_list[i].dais[j].dai_name);
1891 /* Do the .exit function if the codec dai is used in the link */
1892 ret = codec_info_list[i].dais[j].exit(card, dai_link);
1895 "codec exit failed %d\n",
1903 static int mc_probe(struct platform_device *pdev)
1905 struct snd_soc_card *card = &card_sof_sdw;
1906 struct snd_soc_acpi_mach *mach = dev_get_platdata(&pdev->dev);
1907 struct mc_private *ctx;
1911 card->dev = &pdev->dev;
1913 dev_dbg(card->dev, "Entry\n");
1915 ctx = devm_kzalloc(card->dev, sizeof(*ctx), GFP_KERNEL);
1919 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
1921 snd_soc_card_set_drvdata(card, ctx);
1923 dmi_check_system(sof_sdw_quirk_table);
1925 if (quirk_override != -1) {
1926 dev_info(card->dev, "Overriding quirk 0x%lx => 0x%x\n",
1927 sof_sdw_quirk, quirk_override);
1928 sof_sdw_quirk = quirk_override;
1931 log_quirks(card->dev);
1933 /* reset amp_num to ensure amp_num++ starts from 0 in each probe */
1934 for (i = 0; i < ARRAY_SIZE(codec_info_list); i++)
1935 codec_info_list[i].amp_num = 0;
1937 ret = sof_card_dai_links_create(card);
1942 * the default amp_num is zero for each codec and
1943 * amp_num will only be increased for active amp
1944 * codecs on used platform
1946 for (i = 0; i < ARRAY_SIZE(codec_info_list); i++)
1947 amp_num += codec_info_list[i].amp_num;
1949 card->components = devm_kasprintf(card->dev, GFP_KERNEL,
1950 "cfg-spk:%d cfg-amp:%d",
1951 (sof_sdw_quirk & SOF_SDW_FOUR_SPK)
1953 if (!card->components)
1956 if (mach->mach_params.dmic_num) {
1957 card->components = devm_kasprintf(card->dev, GFP_KERNEL,
1958 "%s mic:dmic cfg-mics:%d",
1960 mach->mach_params.dmic_num);
1961 if (!card->components)
1965 card->long_name = sdw_card_long_name;
1967 /* Register the card */
1968 ret = devm_snd_soc_register_card(card->dev, card);
1970 dev_err(card->dev, "snd_soc_register_card failed %d\n", ret);
1971 mc_dailink_exit_loop(card);
1975 platform_set_drvdata(pdev, card);
1980 static void mc_remove(struct platform_device *pdev)
1982 struct snd_soc_card *card = platform_get_drvdata(pdev);
1984 mc_dailink_exit_loop(card);
1987 static const struct platform_device_id mc_id_table[] = {
1991 MODULE_DEVICE_TABLE(platform, mc_id_table);
1993 static struct platform_driver sof_sdw_driver = {
1996 .pm = &snd_soc_pm_ops,
1999 .remove_new = mc_remove,
2000 .id_table = mc_id_table,
2003 module_platform_driver(sof_sdw_driver);
2005 MODULE_DESCRIPTION("ASoC SoundWire Generic Machine driver");
2006 MODULE_AUTHOR("Bard Liao <yung-chuan.liao@linux.intel.com>");
2007 MODULE_AUTHOR("Rander Wang <rander.wang@linux.intel.com>");
2008 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>");
2009 MODULE_LICENSE("GPL v2");
2010 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
2011 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);