1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2019-2020 Intel Corporation.
5 * Intel SOF Machine Driver with Realtek rt5682 Codec
6 * and speaker codec MAX98357A or RT1015.
9 #include <linux/input.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/clk.h>
13 #include <linux/dmi.h>
14 #include <sound/core.h>
15 #include <sound/jack.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 #include <sound/sof.h>
20 #include <sound/rt5682.h>
21 #include <sound/soc-acpi.h>
22 #include "../../codecs/rt1015.h"
23 #include "../../codecs/rt5682.h"
24 #include "../../codecs/hdac_hdmi.h"
25 #include "../common/soc-intel-quirks.h"
26 #include "hda_dsp_common.h"
27 #include "sof_maxim_common.h"
28 #include "sof_realtek_common.h"
32 #define SOF_RT5682_SSP_CODEC(quirk) ((quirk) & GENMASK(2, 0))
33 #define SOF_RT5682_SSP_CODEC_MASK (GENMASK(2, 0))
34 #define SOF_RT5682_MCLK_EN BIT(3)
35 #define SOF_RT5682_MCLK_24MHZ BIT(4)
36 #define SOF_SPEAKER_AMP_PRESENT BIT(5)
37 #define SOF_RT5682_SSP_AMP_SHIFT 6
38 #define SOF_RT5682_SSP_AMP_MASK (GENMASK(8, 6))
39 #define SOF_RT5682_SSP_AMP(quirk) \
40 (((quirk) << SOF_RT5682_SSP_AMP_SHIFT) & SOF_RT5682_SSP_AMP_MASK)
41 #define SOF_RT5682_MCLK_BYTCHT_EN BIT(9)
42 #define SOF_RT5682_NUM_HDMIDEV_SHIFT 10
43 #define SOF_RT5682_NUM_HDMIDEV_MASK (GENMASK(12, 10))
44 #define SOF_RT5682_NUM_HDMIDEV(quirk) \
45 ((quirk << SOF_RT5682_NUM_HDMIDEV_SHIFT) & SOF_RT5682_NUM_HDMIDEV_MASK)
46 #define SOF_RT1011_SPEAKER_AMP_PRESENT BIT(13)
47 #define SOF_RT1015_SPEAKER_AMP_PRESENT BIT(14)
48 #define SOF_RT1015_SPEAKER_AMP_100FS BIT(15)
49 #define SOF_RT1015P_SPEAKER_AMP_PRESENT BIT(16)
50 #define SOF_MAX98373_SPEAKER_AMP_PRESENT BIT(17)
51 #define SOF_MAX98360A_SPEAKER_AMP_PRESENT BIT(18)
53 /* BT audio offload: reserve 3 bits for future */
54 #define SOF_BT_OFFLOAD_SSP_SHIFT 19
55 #define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(21, 19))
56 #define SOF_BT_OFFLOAD_SSP(quirk) \
57 (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
58 #define SOF_SSP_BT_OFFLOAD_PRESENT BIT(22)
60 /* Default: MCLK on, MCLK 19.2M, SSP0 */
61 static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
62 SOF_RT5682_SSP_CODEC(0);
64 static int is_legacy_cpu;
66 static struct snd_soc_jack sof_hdmi[3];
69 struct list_head head;
70 struct snd_soc_dai *codec_dai;
74 struct sof_card_private {
76 struct snd_soc_jack sof_headset;
77 struct list_head hdmi_pcm_list;
78 bool common_hdmi_codec_drv;
81 static int sof_rt5682_quirk_cb(const struct dmi_system_id *id)
83 sof_rt5682_quirk = (unsigned long)id->driver_data;
87 static const struct dmi_system_id sof_rt5682_quirk_table[] = {
89 .callback = sof_rt5682_quirk_cb,
91 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
92 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max"),
94 .driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
97 .callback = sof_rt5682_quirk_cb,
99 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
100 DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
102 .driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
105 .callback = sof_rt5682_quirk_cb,
107 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
108 DMI_MATCH(DMI_PRODUCT_NAME, "WhiskeyLake Client"),
110 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
111 SOF_RT5682_MCLK_24MHZ |
112 SOF_RT5682_SSP_CODEC(1)),
116 * Dooly is hatch family but using rt1015 amp so it
117 * requires a quirk before "Google_Hatch".
119 .callback = sof_rt5682_quirk_cb,
121 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
122 DMI_MATCH(DMI_PRODUCT_NAME, "Dooly"),
124 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
125 SOF_RT5682_MCLK_24MHZ |
126 SOF_RT5682_SSP_CODEC(0) |
127 SOF_SPEAKER_AMP_PRESENT |
128 SOF_RT1015_SPEAKER_AMP_PRESENT |
129 SOF_RT1015_SPEAKER_AMP_100FS |
130 SOF_RT5682_SSP_AMP(1)),
133 .callback = sof_rt5682_quirk_cb,
135 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Hatch"),
137 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
138 SOF_RT5682_MCLK_24MHZ |
139 SOF_RT5682_SSP_CODEC(0) |
140 SOF_SPEAKER_AMP_PRESENT |
141 SOF_RT5682_SSP_AMP(1)),
144 .callback = sof_rt5682_quirk_cb,
146 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
147 DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"),
149 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
150 SOF_RT5682_SSP_CODEC(0)),
153 .callback = sof_rt5682_quirk_cb,
155 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
156 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
158 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
159 SOF_RT5682_SSP_CODEC(0) |
160 SOF_SPEAKER_AMP_PRESENT |
161 SOF_MAX98373_SPEAKER_AMP_PRESENT |
162 SOF_RT5682_SSP_AMP(2) |
163 SOF_RT5682_NUM_HDMIDEV(4)),
168 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
170 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
171 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
172 struct sof_hdmi_pcm *pcm;
174 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
178 /* dai_link id is 1:1 mapped to the PCM device */
179 pcm->device = rtd->dai_link->id;
180 pcm->codec_dai = dai;
182 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
187 static int sof_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
189 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
190 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
191 struct snd_soc_jack *jack;
194 /* need to enable ASRC function for 24MHz mclk rate */
195 if ((sof_rt5682_quirk & SOF_RT5682_MCLK_EN) &&
196 (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ)) {
197 rt5682_sel_asrc_clk_src(component, RT5682_DA_STEREO1_FILTER |
198 RT5682_AD_STEREO1_FILTER,
199 RT5682_CLK_SEL_I2S1_ASRC);
202 if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
204 * The firmware might enable the clock at
205 * boot (this information may or may not
206 * be reflected in the enable clock register).
207 * To change the rate we must disable the clock
208 * first to cover these cases. Due to common
209 * clock framework restrictions that do not allow
210 * to disable a clock that has not been enabled,
211 * we need to enable the clock first.
213 ret = clk_prepare_enable(ctx->mclk);
215 clk_disable_unprepare(ctx->mclk);
217 ret = clk_set_rate(ctx->mclk, 19200000);
220 dev_err(rtd->dev, "unable to set MCLK rate\n");
224 * Headset buttons map to the google Reference headset.
225 * These can be configured by userspace.
227 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
228 SND_JACK_HEADSET | SND_JACK_BTN_0 |
229 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
231 &ctx->sof_headset, NULL, 0);
233 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
237 jack = &ctx->sof_headset;
239 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
240 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
241 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
242 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
243 ret = snd_soc_component_set_jack(component, jack, NULL);
246 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
253 static void sof_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
255 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
257 snd_soc_component_set_jack(component, NULL, NULL);
260 static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
261 struct snd_pcm_hw_params *params)
263 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
264 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
265 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
266 int clk_id, clk_freq, pll_out, ret;
268 if (sof_rt5682_quirk & SOF_RT5682_MCLK_EN) {
269 if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
270 ret = clk_prepare_enable(ctx->mclk);
273 "could not configure MCLK state");
278 clk_id = RT5682_PLL1_S_MCLK;
280 /* get the tplg configured mclk. */
281 clk_freq = sof_dai_get_mclk(rtd);
283 /* mclk from the quirk is the first choice */
284 if (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ) {
285 if (clk_freq != 24000000)
286 dev_warn(rtd->dev, "configure wrong mclk in tplg, please use 24MHz.\n");
288 } else if (clk_freq == 0) {
289 /* use default mclk if not specified correct in topology */
291 } else if (clk_freq < 0) {
295 clk_id = RT5682_PLL1_S_BCLK1;
296 clk_freq = params_rate(params) * 50;
299 pll_out = params_rate(params) * 512;
301 ret = snd_soc_dai_set_pll(codec_dai, 0, clk_id, clk_freq, pll_out);
303 dev_err(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
305 /* Configure sysclk for codec */
306 ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1,
307 pll_out, SND_SOC_CLOCK_IN);
309 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
312 * slot_width should equal or large than data length, set them
315 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
316 params_width(params));
318 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
325 static struct snd_soc_ops sof_rt5682_ops = {
326 .hw_params = sof_rt5682_hw_params,
329 static int sof_rt1015_hw_params(struct snd_pcm_substream *substream,
330 struct snd_pcm_hw_params *params)
332 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
333 struct snd_soc_card *card = rtd->card;
334 struct snd_soc_dai *codec_dai;
337 if (!snd_soc_card_get_codec_dai(card, "rt1015-aif"))
340 if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_100FS)
345 for_each_rtd_codec_dais(rtd, i, codec_dai) {
346 ret = snd_soc_dai_set_pll(codec_dai, 0, RT1015_PLL_S_BCLK,
347 params_rate(params) * fs,
348 params_rate(params) * 256);
350 dev_err(card->dev, "failed to set pll\n");
353 /* Configure sysclk for codec */
354 ret = snd_soc_dai_set_sysclk(codec_dai, RT1015_SCLK_S_PLL,
355 params_rate(params) * 256,
358 dev_err(card->dev, "failed to set sysclk\n");
362 if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_100FS) {
363 if (!strcmp(codec_dai->component->name, "i2c-10EC1015:00")) {
364 ret = snd_soc_dai_set_tdm_slot(codec_dai,
367 dev_err(card->dev, "failed to set tdm slot\n");
372 if (!strcmp(codec_dai->component->name, "i2c-10EC1015:01")) {
373 ret = snd_soc_dai_set_tdm_slot(codec_dai,
376 dev_err(card->dev, "failed to set tdm slot\n");
386 static struct snd_soc_ops sof_rt1015_ops = {
387 .hw_params = sof_rt1015_hw_params,
390 static struct snd_soc_dai_link_component platform_component[] = {
392 /* name might be overridden during probe */
393 .name = "0000:00:1f.3"
397 static int sof_card_late_probe(struct snd_soc_card *card)
399 struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
400 struct snd_soc_component *component = NULL;
401 struct snd_soc_dapm_context *dapm = &card->dapm;
402 char jack_name[NAME_SIZE];
403 struct sof_hdmi_pcm *pcm;
407 /* HDMI is not supported by SOF on Baytrail/CherryTrail */
411 if (list_empty(&ctx->hdmi_pcm_list))
414 if (ctx->common_hdmi_codec_drv) {
415 pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
417 component = pcm->codec_dai->component;
418 return hda_dsp_hdmi_build_controls(card, component);
421 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
422 component = pcm->codec_dai->component;
423 snprintf(jack_name, sizeof(jack_name),
424 "HDMI/DP, pcm=%d Jack", pcm->device);
425 err = snd_soc_card_jack_new(card, jack_name,
426 SND_JACK_AVOUT, &sof_hdmi[i],
432 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
440 if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
441 /* Disable Left and Right Spk pin after boot */
442 snd_soc_dapm_disable_pin(dapm, "Left Spk");
443 snd_soc_dapm_disable_pin(dapm, "Right Spk");
444 err = snd_soc_dapm_sync(dapm);
448 return hdac_hdmi_jack_port_init(component, &card->dapm);
451 static const struct snd_kcontrol_new sof_controls[] = {
452 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
453 SOC_DAPM_PIN_SWITCH("Headset Mic"),
454 SOC_DAPM_PIN_SWITCH("Spk"),
455 SOC_DAPM_PIN_SWITCH("Left Spk"),
456 SOC_DAPM_PIN_SWITCH("Right Spk"),
460 static const struct snd_soc_dapm_widget sof_widgets[] = {
461 SND_SOC_DAPM_HP("Headphone Jack", NULL),
462 SND_SOC_DAPM_MIC("Headset Mic", NULL),
463 SND_SOC_DAPM_SPK("Spk", NULL),
464 SND_SOC_DAPM_SPK("Left Spk", NULL),
465 SND_SOC_DAPM_SPK("Right Spk", NULL),
468 static const struct snd_soc_dapm_widget dmic_widgets[] = {
469 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
472 static const struct snd_soc_dapm_route sof_map[] = {
473 /* HP jack connectors - unknown if we have jack detection */
474 { "Headphone Jack", NULL, "HPOL" },
475 { "Headphone Jack", NULL, "HPOR" },
478 { "IN1P", NULL, "Headset Mic" },
481 static const struct snd_soc_dapm_route speaker_map[] = {
483 { "Spk", NULL, "Speaker" },
486 static const struct snd_soc_dapm_route speaker_map_lr[] = {
487 { "Left Spk", NULL, "Left SPO" },
488 { "Right Spk", NULL, "Right SPO" },
491 static const struct snd_soc_dapm_route dmic_map[] = {
493 {"DMic", NULL, "SoC DMIC"},
496 static int speaker_codec_init_lr(struct snd_soc_pcm_runtime *rtd)
498 return snd_soc_dapm_add_routes(&rtd->card->dapm, speaker_map_lr,
499 ARRAY_SIZE(speaker_map_lr));
502 static int speaker_codec_init(struct snd_soc_pcm_runtime *rtd)
504 struct snd_soc_card *card = rtd->card;
507 ret = snd_soc_dapm_add_routes(&card->dapm, speaker_map,
508 ARRAY_SIZE(speaker_map));
511 dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
515 static int dmic_init(struct snd_soc_pcm_runtime *rtd)
517 struct snd_soc_card *card = rtd->card;
520 ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
521 ARRAY_SIZE(dmic_widgets));
523 dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
524 /* Don't need to add routes if widget addition failed */
528 ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
529 ARRAY_SIZE(dmic_map));
532 dev_err(card->dev, "DMic map addition failed: %d\n", ret);
537 static struct snd_soc_codec_conf rt1015_amp_conf[] = {
539 .dlc = COMP_CODEC_CONF("i2c-10EC1015:00"),
540 .name_prefix = "Left",
543 .dlc = COMP_CODEC_CONF("i2c-10EC1015:01"),
544 .name_prefix = "Right",
548 /* sof audio machine driver for rt5682 codec */
549 static struct snd_soc_card sof_audio_card_rt5682 = {
550 .name = "rt5682", /* the sof- prefix is added by the core */
551 .owner = THIS_MODULE,
552 .controls = sof_controls,
553 .num_controls = ARRAY_SIZE(sof_controls),
554 .dapm_widgets = sof_widgets,
555 .num_dapm_widgets = ARRAY_SIZE(sof_widgets),
556 .dapm_routes = sof_map,
557 .num_dapm_routes = ARRAY_SIZE(sof_map),
558 .fully_routed = true,
559 .late_probe = sof_card_late_probe,
562 static struct snd_soc_dai_link_component rt5682_component[] = {
564 .name = "i2c-10EC5682:00",
565 .dai_name = "rt5682-aif1",
569 static struct snd_soc_dai_link_component dmic_component[] = {
571 .name = "dmic-codec",
572 .dai_name = "dmic-hifi",
576 static struct snd_soc_dai_link_component max98357a_component[] = {
578 .name = "MX98357A:00",
583 static struct snd_soc_dai_link_component max98360a_component[] = {
585 .name = "MX98360A:00",
590 static struct snd_soc_dai_link_component rt1015_components[] = {
592 .name = "i2c-10EC1015:00",
593 .dai_name = "rt1015-aif",
596 .name = "i2c-10EC1015:01",
597 .dai_name = "rt1015-aif",
601 static struct snd_soc_dai_link_component dummy_component[] = {
603 .name = "snd-soc-dummy",
604 .dai_name = "snd-soc-dummy-dai",
608 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
614 struct snd_soc_dai_link_component *idisp_components;
615 struct snd_soc_dai_link_component *cpus;
616 struct snd_soc_dai_link *links;
619 links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) *
620 sof_audio_card_rt5682.num_links, GFP_KERNEL);
621 cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component) *
622 sof_audio_card_rt5682.num_links, GFP_KERNEL);
627 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
628 "SSP%d-Codec", ssp_codec);
633 links[id].codecs = rt5682_component;
634 links[id].num_codecs = ARRAY_SIZE(rt5682_component);
635 links[id].platforms = platform_component;
636 links[id].num_platforms = ARRAY_SIZE(platform_component);
637 links[id].init = sof_rt5682_codec_init;
638 links[id].exit = sof_rt5682_codec_exit;
639 links[id].ops = &sof_rt5682_ops;
640 links[id].dpcm_playback = 1;
641 links[id].dpcm_capture = 1;
642 links[id].no_pcm = 1;
643 links[id].cpus = &cpus[id];
644 links[id].num_cpus = 1;
646 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
649 if (!links[id].cpus->dai_name)
653 * Currently, On SKL+ platforms MCLK will be turned off in sof
654 * runtime suspended, and it will go into runtime suspended
655 * right after playback is stop. However, rt5682 will output
656 * static noise if sysclk turns off during playback. Set
657 * ignore_pmdown_time to power down rt5682 immediately and
659 * It can be removed once we can control MCLK by driver.
661 links[id].ignore_pmdown_time = 1;
662 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
665 if (!links[id].cpus->dai_name)
671 if (dmic_be_num > 0) {
672 /* at least we have dmic01 */
673 links[id].name = "dmic01";
674 links[id].cpus = &cpus[id];
675 links[id].cpus->dai_name = "DMIC01 Pin";
676 links[id].init = dmic_init;
677 if (dmic_be_num > 1) {
678 /* set up 2 BE links at most */
679 links[id + 1].name = "dmic16k";
680 links[id + 1].cpus = &cpus[id + 1];
681 links[id + 1].cpus->dai_name = "DMIC16k Pin";
686 for (i = 0; i < dmic_be_num; i++) {
688 links[id].num_cpus = 1;
689 links[id].codecs = dmic_component;
690 links[id].num_codecs = ARRAY_SIZE(dmic_component);
691 links[id].platforms = platform_component;
692 links[id].num_platforms = ARRAY_SIZE(platform_component);
693 links[id].ignore_suspend = 1;
694 links[id].dpcm_capture = 1;
695 links[id].no_pcm = 1;
701 idisp_components = devm_kzalloc(dev,
702 sizeof(struct snd_soc_dai_link_component) *
703 hdmi_num, GFP_KERNEL);
704 if (!idisp_components)
707 for (i = 1; i <= hdmi_num; i++) {
708 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
714 links[id].cpus = &cpus[id];
715 links[id].num_cpus = 1;
716 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
718 if (!links[id].cpus->dai_name)
721 idisp_components[i - 1].name = "ehdaudio0D2";
722 idisp_components[i - 1].dai_name = devm_kasprintf(dev,
726 if (!idisp_components[i - 1].dai_name)
729 links[id].codecs = &idisp_components[i - 1];
730 links[id].num_codecs = 1;
731 links[id].platforms = platform_component;
732 links[id].num_platforms = ARRAY_SIZE(platform_component);
733 links[id].init = sof_hdmi_init;
734 links[id].dpcm_playback = 1;
735 links[id].no_pcm = 1;
740 if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) {
741 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
742 "SSP%d-Codec", ssp_amp);
747 if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT) {
748 links[id].codecs = rt1015_components;
749 links[id].num_codecs = ARRAY_SIZE(rt1015_components);
750 links[id].init = speaker_codec_init_lr;
751 links[id].ops = &sof_rt1015_ops;
752 } else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT) {
753 sof_rt1015p_dai_link(&links[id]);
754 } else if (sof_rt5682_quirk &
755 SOF_MAX98373_SPEAKER_AMP_PRESENT) {
756 links[id].codecs = max_98373_components;
757 links[id].num_codecs = ARRAY_SIZE(max_98373_components);
758 links[id].init = max_98373_spk_codec_init;
759 links[id].ops = &max_98373_ops;
760 /* feedback stream */
761 links[id].dpcm_capture = 1;
762 } else if (sof_rt5682_quirk &
763 SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
764 links[id].codecs = max98360a_component;
765 links[id].num_codecs = ARRAY_SIZE(max98360a_component);
766 links[id].init = speaker_codec_init;
767 } else if (sof_rt5682_quirk &
768 SOF_RT1011_SPEAKER_AMP_PRESENT) {
769 sof_rt1011_dai_link(&links[id]);
771 links[id].codecs = max98357a_component;
772 links[id].num_codecs = ARRAY_SIZE(max98357a_component);
773 links[id].init = speaker_codec_init;
775 links[id].platforms = platform_component;
776 links[id].num_platforms = ARRAY_SIZE(platform_component);
777 links[id].dpcm_playback = 1;
778 links[id].no_pcm = 1;
779 links[id].cpus = &cpus[id];
780 links[id].num_cpus = 1;
782 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
785 if (!links[id].cpus->dai_name)
789 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
792 if (!links[id].cpus->dai_name)
798 /* BT audio offload */
799 if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
800 int port = (sof_rt5682_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
801 SOF_BT_OFFLOAD_SSP_SHIFT;
804 links[id].cpus = &cpus[id];
805 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
807 if (!links[id].cpus->dai_name)
809 links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
812 links[id].codecs = dummy_component;
813 links[id].num_codecs = ARRAY_SIZE(dummy_component);
814 links[id].platforms = platform_component;
815 links[id].num_platforms = ARRAY_SIZE(platform_component);
816 links[id].dpcm_playback = 1;
817 links[id].dpcm_capture = 1;
818 links[id].no_pcm = 1;
819 links[id].num_cpus = 1;
827 static int sof_audio_probe(struct platform_device *pdev)
829 struct snd_soc_dai_link *dai_links;
830 struct snd_soc_acpi_mach *mach;
831 struct sof_card_private *ctx;
832 int dmic_be_num, hdmi_num;
833 int ret, ssp_amp, ssp_codec;
835 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
839 if (pdev->id_entry && pdev->id_entry->driver_data)
840 sof_rt5682_quirk = (unsigned long)pdev->id_entry->driver_data;
842 dmi_check_system(sof_rt5682_quirk_table);
844 mach = pdev->dev.platform_data;
846 /* A speaker amp might not be present when the quirk claims one is.
847 * Detect this via whether the machine driver match includes quirk_data.
849 if ((sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) && !mach->quirk_data)
850 sof_rt5682_quirk &= ~SOF_SPEAKER_AMP_PRESENT;
852 if (soc_intel_is_byt() || soc_intel_is_cht()) {
856 /* default quirk for legacy cpu */
857 sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
858 SOF_RT5682_MCLK_BYTCHT_EN |
859 SOF_RT5682_SSP_CODEC(2);
862 hdmi_num = (sof_rt5682_quirk & SOF_RT5682_NUM_HDMIDEV_MASK) >>
863 SOF_RT5682_NUM_HDMIDEV_SHIFT;
864 /* default number of HDMI DAI's */
869 /* need to get main clock from pmc */
870 if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
871 ctx->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
872 if (IS_ERR(ctx->mclk)) {
873 ret = PTR_ERR(ctx->mclk);
876 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
881 ret = clk_prepare_enable(ctx->mclk);
884 "could not configure MCLK state");
889 dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk);
891 ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
892 SOF_RT5682_SSP_AMP_SHIFT;
894 ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;
896 /* compute number of dai links */
897 sof_audio_card_rt5682.num_links = 1 + dmic_be_num + hdmi_num;
899 if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT)
900 sof_audio_card_rt5682.num_links++;
902 if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT)
903 max_98373_set_codec_conf(&sof_audio_card_rt5682);
904 else if (sof_rt5682_quirk & SOF_RT1011_SPEAKER_AMP_PRESENT)
905 sof_rt1011_codec_conf(&sof_audio_card_rt5682);
906 else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
907 sof_rt1015p_codec_conf(&sof_audio_card_rt5682);
909 if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
910 sof_audio_card_rt5682.num_links++;
912 dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
913 dmic_be_num, hdmi_num);
917 sof_audio_card_rt5682.dai_link = dai_links;
919 if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT) {
920 sof_audio_card_rt5682.codec_conf = rt1015_amp_conf;
921 sof_audio_card_rt5682.num_configs = ARRAY_SIZE(rt1015_amp_conf);
924 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
926 sof_audio_card_rt5682.dev = &pdev->dev;
928 /* set platform name for each dailink */
929 ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_rt5682,
930 mach->mach_params.platform);
934 ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
936 snd_soc_card_set_drvdata(&sof_audio_card_rt5682, ctx);
938 return devm_snd_soc_register_card(&pdev->dev,
939 &sof_audio_card_rt5682);
942 static const struct platform_device_id board_ids[] = {
944 .name = "sof_rt5682",
947 .name = "tgl_max98357a_rt5682",
948 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
949 SOF_RT5682_SSP_CODEC(0) |
950 SOF_SPEAKER_AMP_PRESENT |
951 SOF_RT5682_SSP_AMP(1) |
952 SOF_RT5682_NUM_HDMIDEV(4) |
953 SOF_BT_OFFLOAD_SSP(2) |
954 SOF_SSP_BT_OFFLOAD_PRESENT),
957 .name = "jsl_rt5682_rt1015",
958 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
959 SOF_RT5682_MCLK_24MHZ |
960 SOF_RT5682_SSP_CODEC(0) |
961 SOF_SPEAKER_AMP_PRESENT |
962 SOF_RT1015_SPEAKER_AMP_PRESENT |
963 SOF_RT5682_SSP_AMP(1)),
966 .name = "tgl_max98373_rt5682",
967 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
968 SOF_RT5682_SSP_CODEC(0) |
969 SOF_SPEAKER_AMP_PRESENT |
970 SOF_MAX98373_SPEAKER_AMP_PRESENT |
971 SOF_RT5682_SSP_AMP(1) |
972 SOF_RT5682_NUM_HDMIDEV(4) |
973 SOF_BT_OFFLOAD_SSP(2) |
974 SOF_SSP_BT_OFFLOAD_PRESENT),
977 .name = "jsl_rt5682_max98360a",
978 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
979 SOF_RT5682_MCLK_24MHZ |
980 SOF_RT5682_SSP_CODEC(0) |
981 SOF_SPEAKER_AMP_PRESENT |
982 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
983 SOF_RT5682_SSP_AMP(1)),
986 .name = "cml_rt1015_rt5682",
987 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
988 SOF_RT5682_MCLK_24MHZ |
989 SOF_RT5682_SSP_CODEC(0) |
990 SOF_SPEAKER_AMP_PRESENT |
991 SOF_RT1015_SPEAKER_AMP_PRESENT |
992 SOF_RT1015_SPEAKER_AMP_100FS |
993 SOF_RT5682_SSP_AMP(1)),
996 .name = "tgl_rt1011_rt5682",
997 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
998 SOF_RT5682_SSP_CODEC(0) |
999 SOF_SPEAKER_AMP_PRESENT |
1000 SOF_RT1011_SPEAKER_AMP_PRESENT |
1001 SOF_RT5682_SSP_AMP(1) |
1002 SOF_RT5682_NUM_HDMIDEV(4) |
1003 SOF_BT_OFFLOAD_SSP(2) |
1004 SOF_SSP_BT_OFFLOAD_PRESENT),
1007 .name = "jsl_rt5682_rt1015p",
1008 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1009 SOF_RT5682_MCLK_24MHZ |
1010 SOF_RT5682_SSP_CODEC(0) |
1011 SOF_SPEAKER_AMP_PRESENT |
1012 SOF_RT1015P_SPEAKER_AMP_PRESENT |
1013 SOF_RT5682_SSP_AMP(1)),
1016 .name = "adl_max98373_rt5682",
1017 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1018 SOF_RT5682_SSP_CODEC(0) |
1019 SOF_SPEAKER_AMP_PRESENT |
1020 SOF_MAX98373_SPEAKER_AMP_PRESENT |
1021 SOF_RT5682_SSP_AMP(1) |
1022 SOF_RT5682_NUM_HDMIDEV(4) |
1023 SOF_BT_OFFLOAD_SSP(2) |
1024 SOF_SSP_BT_OFFLOAD_PRESENT),
1027 .name = "adl_max98357a_rt5682",
1028 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1029 SOF_RT5682_SSP_CODEC(0) |
1030 SOF_SPEAKER_AMP_PRESENT |
1031 SOF_RT5682_SSP_AMP(2) |
1032 SOF_RT5682_NUM_HDMIDEV(4)),
1037 static struct platform_driver sof_audio = {
1038 .probe = sof_audio_probe,
1040 .name = "sof_rt5682",
1041 .pm = &snd_soc_pm_ops,
1043 .id_table = board_ids,
1045 module_platform_driver(sof_audio)
1047 /* Module information */
1048 MODULE_DESCRIPTION("SOF Audio Machine driver");
1049 MODULE_AUTHOR("Bard Liao <bard.liao@intel.com>");
1050 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
1051 MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
1052 MODULE_LICENSE("GPL v2");
1053 MODULE_ALIAS("platform:sof_rt5682");
1054 MODULE_ALIAS("platform:tgl_max98357a_rt5682");
1055 MODULE_ALIAS("platform:jsl_rt5682_rt1015");
1056 MODULE_ALIAS("platform:tgl_max98373_rt5682");
1057 MODULE_ALIAS("platform:jsl_rt5682_max98360a");
1058 MODULE_ALIAS("platform:cml_rt1015_rt5682");
1059 MODULE_ALIAS("platform:tgl_rt1011_rt5682");
1060 MODULE_ALIAS("platform:jsl_rt5682_rt1015p");
1061 MODULE_ALIAS("platform:adl_max98373_rt5682");
1062 MODULE_ALIAS("platform:adl_max98357a_rt5682");
1063 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
1064 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);