1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2019-2020 Intel Corporation.
3 
4 /*
5  * Intel SOF Machine Driver with Realtek rt5682 Codec
6  * and speaker codec MAX98357A or RT1015.
7  */
8 #include <linux/i2c.h>
9 #include <linux/input.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/clk.h>
13 #include <linux/dmi.h>
14 #include <sound/core.h>
15 #include <sound/jack.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 #include <sound/sof.h>
20 #include <sound/rt5682.h>
21 #include <sound/rt5682s.h>
22 #include <sound/soc-acpi.h>
23 #include "../../codecs/rt5682.h"
24 #include "../../codecs/rt5682s.h"
25 #include "../../codecs/hdac_hdmi.h"
26 #include "../common/soc-intel-quirks.h"
27 #include "hda_dsp_common.h"
28 #include "sof_maxim_common.h"
29 #include "sof_realtek_common.h"
30 
31 #define NAME_SIZE 32
32 
33 #define SOF_RT5682_SSP_CODEC(quirk)		((quirk) & GENMASK(2, 0))
34 #define SOF_RT5682_SSP_CODEC_MASK			(GENMASK(2, 0))
35 #define SOF_RT5682_MCLK_EN			BIT(3)
36 #define SOF_RT5682_MCLK_24MHZ			BIT(4)
37 #define SOF_SPEAKER_AMP_PRESENT		BIT(5)
38 #define SOF_RT5682_SSP_AMP_SHIFT		6
39 #define SOF_RT5682_SSP_AMP_MASK                 (GENMASK(8, 6))
40 #define SOF_RT5682_SSP_AMP(quirk)	\
41 	(((quirk) << SOF_RT5682_SSP_AMP_SHIFT) & SOF_RT5682_SSP_AMP_MASK)
42 #define SOF_RT5682_MCLK_BYTCHT_EN		BIT(9)
43 #define SOF_RT5682_NUM_HDMIDEV_SHIFT		10
44 #define SOF_RT5682_NUM_HDMIDEV_MASK		(GENMASK(12, 10))
45 #define SOF_RT5682_NUM_HDMIDEV(quirk)	\
46 	((quirk << SOF_RT5682_NUM_HDMIDEV_SHIFT) & SOF_RT5682_NUM_HDMIDEV_MASK)
47 #define SOF_RT1011_SPEAKER_AMP_PRESENT		BIT(13)
48 #define SOF_RT1015_SPEAKER_AMP_PRESENT		BIT(14)
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)
52 
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)
59 #define SOF_RT5682S_HEADPHONE_CODEC_PRESENT	BIT(23)
60 #define SOF_MAX98390_SPEAKER_AMP_PRESENT	BIT(24)
61 #define SOF_MAX98390_TWEETER_SPEAKER_PRESENT	BIT(25)
62 #define SOF_RT1019_SPEAKER_AMP_PRESENT	BIT(26)
63 
64 
65 /* Default: MCLK on, MCLK 19.2M, SSP0  */
66 static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
67 					SOF_RT5682_SSP_CODEC(0);
68 
69 static int is_legacy_cpu;
70 
71 struct sof_hdmi_pcm {
72 	struct list_head head;
73 	struct snd_soc_dai *codec_dai;
74 	struct snd_soc_jack hdmi_jack;
75 	int device;
76 };
77 
78 struct sof_card_private {
79 	struct clk *mclk;
80 	struct snd_soc_jack sof_headset;
81 	struct list_head hdmi_pcm_list;
82 	bool common_hdmi_codec_drv;
83 	bool idisp_codec;
84 };
85 
86 static int sof_rt5682_quirk_cb(const struct dmi_system_id *id)
87 {
88 	sof_rt5682_quirk = (unsigned long)id->driver_data;
89 	return 1;
90 }
91 
92 static const struct dmi_system_id sof_rt5682_quirk_table[] = {
93 	{
94 		.callback = sof_rt5682_quirk_cb,
95 		.matches = {
96 			DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
97 			DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max"),
98 		},
99 		.driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
100 	},
101 	{
102 		.callback = sof_rt5682_quirk_cb,
103 		.matches = {
104 			DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
105 			DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
106 		},
107 		.driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
108 	},
109 	{
110 		.callback = sof_rt5682_quirk_cb,
111 		.matches = {
112 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
113 			DMI_MATCH(DMI_PRODUCT_NAME, "WhiskeyLake Client"),
114 		},
115 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
116 					SOF_RT5682_MCLK_24MHZ |
117 					SOF_RT5682_SSP_CODEC(1)),
118 	},
119 	{
120 		/*
121 		 * Dooly is hatch family but using rt1015 amp so it
122 		 * requires a quirk before "Google_Hatch".
123 		 */
124 		.callback = sof_rt5682_quirk_cb,
125 		.matches = {
126 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
127 			DMI_MATCH(DMI_PRODUCT_NAME, "Dooly"),
128 		},
129 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
130 					SOF_RT5682_MCLK_24MHZ |
131 					SOF_RT5682_SSP_CODEC(0) |
132 					SOF_SPEAKER_AMP_PRESENT |
133 					SOF_RT1015_SPEAKER_AMP_PRESENT |
134 					SOF_RT5682_SSP_AMP(1)),
135 	},
136 	{
137 		.callback = sof_rt5682_quirk_cb,
138 		.matches = {
139 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Hatch"),
140 		},
141 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
142 					SOF_RT5682_MCLK_24MHZ |
143 					SOF_RT5682_SSP_CODEC(0) |
144 					SOF_SPEAKER_AMP_PRESENT |
145 					SOF_RT5682_SSP_AMP(1)),
146 	},
147 	{
148 		.callback = sof_rt5682_quirk_cb,
149 		.matches = {
150 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
151 			DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"),
152 		},
153 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
154 					SOF_RT5682_SSP_CODEC(0)),
155 	},
156 	{
157 		.callback = sof_rt5682_quirk_cb,
158 		.matches = {
159 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
160 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
161 		},
162 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
163 					SOF_RT5682_SSP_CODEC(0) |
164 					SOF_SPEAKER_AMP_PRESENT |
165 					SOF_MAX98373_SPEAKER_AMP_PRESENT |
166 					SOF_RT5682_SSP_AMP(2) |
167 					SOF_RT5682_NUM_HDMIDEV(4)),
168 	},
169 	{
170 		.callback = sof_rt5682_quirk_cb,
171 		.matches = {
172 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
173 			DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
174 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
175 		},
176 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
177 					SOF_RT5682_SSP_CODEC(0) |
178 					SOF_SPEAKER_AMP_PRESENT |
179 					SOF_MAX98373_SPEAKER_AMP_PRESENT |
180 					SOF_RT5682_SSP_AMP(2) |
181 					SOF_RT5682_NUM_HDMIDEV(4)),
182 	},
183 	{
184 		.callback = sof_rt5682_quirk_cb,
185 		.matches = {
186 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
187 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
188 		},
189 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
190 					SOF_RT5682_SSP_CODEC(0) |
191 					SOF_SPEAKER_AMP_PRESENT |
192 					SOF_MAX98390_SPEAKER_AMP_PRESENT |
193 					SOF_RT5682_SSP_AMP(2) |
194 					SOF_RT5682_NUM_HDMIDEV(4)),
195 	},
196 	{
197 		.callback = sof_rt5682_quirk_cb,
198 		.matches = {
199 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
200 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S_4SPK"),
201 		},
202 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
203 					SOF_RT5682_SSP_CODEC(0) |
204 					SOF_SPEAKER_AMP_PRESENT |
205 					SOF_MAX98390_SPEAKER_AMP_PRESENT |
206 					SOF_MAX98390_TWEETER_SPEAKER_PRESENT |
207 					SOF_RT5682_SSP_AMP(1) |
208 					SOF_RT5682_NUM_HDMIDEV(4) |
209 					SOF_BT_OFFLOAD_SSP(2) |
210 					SOF_SSP_BT_OFFLOAD_PRESENT),
211 
212 	},
213 	{
214 		.callback = sof_rt5682_quirk_cb,
215 		.matches = {
216 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
217 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
218 		},
219 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
220 					SOF_RT5682_SSP_CODEC(0) |
221 					SOF_SPEAKER_AMP_PRESENT |
222 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
223 					SOF_RT5682_SSP_AMP(2) |
224 					SOF_RT5682_NUM_HDMIDEV(4)),
225 	},
226 	{}
227 };
228 
229 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
230 {
231 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
232 	struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
233 	struct sof_hdmi_pcm *pcm;
234 
235 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
236 	if (!pcm)
237 		return -ENOMEM;
238 
239 	/* dai_link id is 1:1 mapped to the PCM device */
240 	pcm->device = rtd->dai_link->id;
241 	pcm->codec_dai = dai;
242 
243 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
244 
245 	return 0;
246 }
247 
248 static struct snd_soc_jack_pin jack_pins[] = {
249 	{
250 		.pin    = "Headphone Jack",
251 		.mask   = SND_JACK_HEADPHONE,
252 	},
253 	{
254 		.pin    = "Headset Mic",
255 		.mask   = SND_JACK_MICROPHONE,
256 	},
257 };
258 
259 static int sof_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
260 {
261 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
262 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
263 	struct snd_soc_jack *jack;
264 	int ret;
265 
266 	/* need to enable ASRC function for 24MHz mclk rate */
267 	if ((sof_rt5682_quirk & SOF_RT5682_MCLK_EN) &&
268 	    (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ)) {
269 		if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
270 			rt5682s_sel_asrc_clk_src(component,
271 						 RT5682S_DA_STEREO1_FILTER |
272 						 RT5682S_AD_STEREO1_FILTER,
273 						 RT5682S_CLK_SEL_I2S1_ASRC);
274 		else
275 			rt5682_sel_asrc_clk_src(component,
276 						RT5682_DA_STEREO1_FILTER |
277 						RT5682_AD_STEREO1_FILTER,
278 						RT5682_CLK_SEL_I2S1_ASRC);
279 	}
280 
281 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
282 		/*
283 		 * The firmware might enable the clock at
284 		 * boot (this information may or may not
285 		 * be reflected in the enable clock register).
286 		 * To change the rate we must disable the clock
287 		 * first to cover these cases. Due to common
288 		 * clock framework restrictions that do not allow
289 		 * to disable a clock that has not been enabled,
290 		 * we need to enable the clock first.
291 		 */
292 		ret = clk_prepare_enable(ctx->mclk);
293 		if (!ret)
294 			clk_disable_unprepare(ctx->mclk);
295 
296 		ret = clk_set_rate(ctx->mclk, 19200000);
297 
298 		if (ret)
299 			dev_err(rtd->dev, "unable to set MCLK rate\n");
300 	}
301 
302 	/*
303 	 * Headset buttons map to the google Reference headset.
304 	 * These can be configured by userspace.
305 	 */
306 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
307 					 SND_JACK_HEADSET | SND_JACK_BTN_0 |
308 					 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
309 					 SND_JACK_BTN_3,
310 					 &ctx->sof_headset,
311 					 jack_pins,
312 					 ARRAY_SIZE(jack_pins));
313 	if (ret) {
314 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
315 		return ret;
316 	}
317 
318 	jack = &ctx->sof_headset;
319 
320 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
321 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
322 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
323 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
324 	ret = snd_soc_component_set_jack(component, jack, NULL);
325 
326 	if (ret) {
327 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
328 		return ret;
329 	}
330 
331 	return ret;
332 };
333 
334 static void sof_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
335 {
336 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
337 
338 	snd_soc_component_set_jack(component, NULL, NULL);
339 }
340 
341 static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
342 				struct snd_pcm_hw_params *params)
343 {
344 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
345 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
346 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
347 	int pll_id, pll_source, pll_in, pll_out, clk_id, ret;
348 
349 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_EN) {
350 		if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
351 			ret = clk_prepare_enable(ctx->mclk);
352 			if (ret < 0) {
353 				dev_err(rtd->dev,
354 					"could not configure MCLK state");
355 				return ret;
356 			}
357 		}
358 
359 		if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
360 			pll_source = RT5682S_PLL_S_MCLK;
361 		else
362 			pll_source = RT5682_PLL1_S_MCLK;
363 
364 		/* get the tplg configured mclk. */
365 		pll_in = sof_dai_get_mclk(rtd);
366 
367 		/* mclk from the quirk is the first choice */
368 		if (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ) {
369 			if (pll_in != 24000000)
370 				dev_warn(rtd->dev, "configure wrong mclk in tplg, please use 24MHz.\n");
371 			pll_in = 24000000;
372 		} else if (pll_in == 0) {
373 			/* use default mclk if not specified correct in topology */
374 			pll_in = 19200000;
375 		} else if (pll_in < 0) {
376 			return pll_in;
377 		}
378 	} else {
379 		if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
380 			pll_source = RT5682S_PLL_S_BCLK1;
381 		else
382 			pll_source = RT5682_PLL1_S_BCLK1;
383 
384 		pll_in = params_rate(params) * 50;
385 	}
386 
387 	if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT) {
388 		pll_id = RT5682S_PLL2;
389 		clk_id = RT5682S_SCLK_S_PLL2;
390 	} else {
391 		pll_id = RT5682_PLL1;
392 		clk_id = RT5682_SCLK_S_PLL1;
393 	}
394 
395 	pll_out = params_rate(params) * 512;
396 
397 	/* when MCLK is 512FS, no need to set PLL configuration additionally. */
398 	if (pll_in == pll_out)
399 		clk_id = RT5682S_SCLK_S_MCLK;
400 	else {
401 		/* Configure pll for codec */
402 		ret = snd_soc_dai_set_pll(codec_dai, pll_id, pll_source, pll_in,
403 					  pll_out);
404 		if (ret < 0)
405 			dev_err(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
406 	}
407 
408 	/* Configure sysclk for codec */
409 	ret = snd_soc_dai_set_sysclk(codec_dai, clk_id,
410 				     pll_out, SND_SOC_CLOCK_IN);
411 	if (ret < 0)
412 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
413 
414 	/*
415 	 * slot_width should equal or large than data length, set them
416 	 * be the same
417 	 */
418 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
419 				       params_width(params));
420 	if (ret < 0) {
421 		dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
422 		return ret;
423 	}
424 
425 	return ret;
426 }
427 
428 static struct snd_soc_ops sof_rt5682_ops = {
429 	.hw_params = sof_rt5682_hw_params,
430 };
431 
432 static struct snd_soc_dai_link_component platform_component[] = {
433 	{
434 		/* name might be overridden during probe */
435 		.name = "0000:00:1f.3"
436 	}
437 };
438 
439 static int sof_card_late_probe(struct snd_soc_card *card)
440 {
441 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
442 	struct snd_soc_component *component = NULL;
443 	struct snd_soc_dapm_context *dapm = &card->dapm;
444 	char jack_name[NAME_SIZE];
445 	struct sof_hdmi_pcm *pcm;
446 	int err;
447 
448 	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
449 		/* Disable Left and Right Spk pin after boot */
450 		snd_soc_dapm_disable_pin(dapm, "Left Spk");
451 		snd_soc_dapm_disable_pin(dapm, "Right Spk");
452 		err = snd_soc_dapm_sync(dapm);
453 		if (err < 0)
454 			return err;
455 	}
456 
457 	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
458 	if (is_legacy_cpu || !ctx->idisp_codec)
459 		return 0;
460 
461 	if (list_empty(&ctx->hdmi_pcm_list))
462 		return -EINVAL;
463 
464 	if (ctx->common_hdmi_codec_drv) {
465 		pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
466 				       head);
467 		component = pcm->codec_dai->component;
468 		return hda_dsp_hdmi_build_controls(card, component);
469 	}
470 
471 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
472 		component = pcm->codec_dai->component;
473 		snprintf(jack_name, sizeof(jack_name),
474 			 "HDMI/DP, pcm=%d Jack", pcm->device);
475 		err = snd_soc_card_jack_new(card, jack_name,
476 					    SND_JACK_AVOUT, &pcm->hdmi_jack);
477 
478 		if (err)
479 			return err;
480 
481 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
482 					  &pcm->hdmi_jack);
483 		if (err < 0)
484 			return err;
485 	}
486 
487 	return hdac_hdmi_jack_port_init(component, &card->dapm);
488 }
489 
490 static const struct snd_kcontrol_new sof_controls[] = {
491 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
492 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
493 	SOC_DAPM_PIN_SWITCH("Left Spk"),
494 	SOC_DAPM_PIN_SWITCH("Right Spk"),
495 
496 };
497 
498 static const struct snd_soc_dapm_widget sof_widgets[] = {
499 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
500 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
501 	SND_SOC_DAPM_SPK("Left Spk", NULL),
502 	SND_SOC_DAPM_SPK("Right Spk", NULL),
503 };
504 
505 static const struct snd_soc_dapm_widget dmic_widgets[] = {
506 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
507 };
508 
509 static const struct snd_soc_dapm_route sof_map[] = {
510 	/* HP jack connectors - unknown if we have jack detection */
511 	{ "Headphone Jack", NULL, "HPOL" },
512 	{ "Headphone Jack", NULL, "HPOR" },
513 
514 	/* other jacks */
515 	{ "IN1P", NULL, "Headset Mic" },
516 };
517 
518 static const struct snd_soc_dapm_route dmic_map[] = {
519 	/* digital mics */
520 	{"DMic", NULL, "SoC DMIC"},
521 };
522 
523 static int dmic_init(struct snd_soc_pcm_runtime *rtd)
524 {
525 	struct snd_soc_card *card = rtd->card;
526 	int ret;
527 
528 	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
529 					ARRAY_SIZE(dmic_widgets));
530 	if (ret) {
531 		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
532 		/* Don't need to add routes if widget addition failed */
533 		return ret;
534 	}
535 
536 	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
537 				      ARRAY_SIZE(dmic_map));
538 
539 	if (ret)
540 		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
541 
542 	return ret;
543 }
544 
545 /* sof audio machine driver for rt5682 codec */
546 static struct snd_soc_card sof_audio_card_rt5682 = {
547 	.name = "rt5682", /* the sof- prefix is added by the core */
548 	.owner = THIS_MODULE,
549 	.controls = sof_controls,
550 	.num_controls = ARRAY_SIZE(sof_controls),
551 	.dapm_widgets = sof_widgets,
552 	.num_dapm_widgets = ARRAY_SIZE(sof_widgets),
553 	.dapm_routes = sof_map,
554 	.num_dapm_routes = ARRAY_SIZE(sof_map),
555 	.fully_routed = true,
556 	.late_probe = sof_card_late_probe,
557 };
558 
559 static struct snd_soc_dai_link_component rt5682_component[] = {
560 	{
561 		.name = "i2c-10EC5682:00",
562 		.dai_name = "rt5682-aif1",
563 	}
564 };
565 
566 static struct snd_soc_dai_link_component rt5682s_component[] = {
567 	{
568 		.name = "i2c-RTL5682:00",
569 		.dai_name = "rt5682s-aif1",
570 	}
571 };
572 
573 static struct snd_soc_dai_link_component dmic_component[] = {
574 	{
575 		.name = "dmic-codec",
576 		.dai_name = "dmic-hifi",
577 	}
578 };
579 
580 static struct snd_soc_dai_link_component dummy_component[] = {
581 	{
582 		.name = "snd-soc-dummy",
583 		.dai_name = "snd-soc-dummy-dai",
584 	}
585 };
586 
587 #define IDISP_CODEC_MASK	0x4
588 
589 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
590 							  int ssp_codec,
591 							  int ssp_amp,
592 							  int dmic_be_num,
593 							  int hdmi_num,
594 							  bool idisp_codec)
595 {
596 	struct snd_soc_dai_link_component *idisp_components;
597 	struct snd_soc_dai_link_component *cpus;
598 	struct snd_soc_dai_link *links;
599 	int i, id = 0;
600 
601 	links = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
602 			    sizeof(struct snd_soc_dai_link), GFP_KERNEL);
603 	cpus = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
604 			    sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
605 	if (!links || !cpus)
606 		goto devm_err;
607 
608 	/* codec SSP */
609 	links[id].name = devm_kasprintf(dev, GFP_KERNEL,
610 					"SSP%d-Codec", ssp_codec);
611 	if (!links[id].name)
612 		goto devm_err;
613 
614 	links[id].id = id;
615 	if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT) {
616 		links[id].codecs = rt5682s_component;
617 		links[id].num_codecs = ARRAY_SIZE(rt5682s_component);
618 	} else {
619 		links[id].codecs = rt5682_component;
620 		links[id].num_codecs = ARRAY_SIZE(rt5682_component);
621 	}
622 	links[id].platforms = platform_component;
623 	links[id].num_platforms = ARRAY_SIZE(platform_component);
624 	links[id].init = sof_rt5682_codec_init;
625 	links[id].exit = sof_rt5682_codec_exit;
626 	links[id].ops = &sof_rt5682_ops;
627 	links[id].dpcm_playback = 1;
628 	links[id].dpcm_capture = 1;
629 	links[id].no_pcm = 1;
630 	links[id].cpus = &cpus[id];
631 	links[id].num_cpus = 1;
632 	if (is_legacy_cpu) {
633 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
634 							  "ssp%d-port",
635 							  ssp_codec);
636 		if (!links[id].cpus->dai_name)
637 			goto devm_err;
638 	} else {
639 		/*
640 		 * Currently, On SKL+ platforms MCLK will be turned off in sof
641 		 * runtime suspended, and it will go into runtime suspended
642 		 * right after playback is stop. However, rt5682 will output
643 		 * static noise if sysclk turns off during playback. Set
644 		 * ignore_pmdown_time to power down rt5682 immediately and
645 		 * avoid the noise.
646 		 * It can be removed once we can control MCLK by driver.
647 		 */
648 		links[id].ignore_pmdown_time = 1;
649 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
650 							  "SSP%d Pin",
651 							  ssp_codec);
652 		if (!links[id].cpus->dai_name)
653 			goto devm_err;
654 	}
655 	id++;
656 
657 	/* dmic */
658 	if (dmic_be_num > 0) {
659 		/* at least we have dmic01 */
660 		links[id].name = "dmic01";
661 		links[id].cpus = &cpus[id];
662 		links[id].cpus->dai_name = "DMIC01 Pin";
663 		links[id].init = dmic_init;
664 		if (dmic_be_num > 1) {
665 			/* set up 2 BE links at most */
666 			links[id + 1].name = "dmic16k";
667 			links[id + 1].cpus = &cpus[id + 1];
668 			links[id + 1].cpus->dai_name = "DMIC16k Pin";
669 			dmic_be_num = 2;
670 		}
671 	}
672 
673 	for (i = 0; i < dmic_be_num; i++) {
674 		links[id].id = id;
675 		links[id].num_cpus = 1;
676 		links[id].codecs = dmic_component;
677 		links[id].num_codecs = ARRAY_SIZE(dmic_component);
678 		links[id].platforms = platform_component;
679 		links[id].num_platforms = ARRAY_SIZE(platform_component);
680 		links[id].ignore_suspend = 1;
681 		links[id].dpcm_capture = 1;
682 		links[id].no_pcm = 1;
683 		id++;
684 	}
685 
686 	/* HDMI */
687 	if (hdmi_num > 0) {
688 		idisp_components = devm_kcalloc(dev,
689 				   hdmi_num,
690 				   sizeof(struct snd_soc_dai_link_component),
691 				   GFP_KERNEL);
692 		if (!idisp_components)
693 			goto devm_err;
694 	}
695 	for (i = 1; i <= hdmi_num; i++) {
696 		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
697 						"iDisp%d", i);
698 		if (!links[id].name)
699 			goto devm_err;
700 
701 		links[id].id = id;
702 		links[id].cpus = &cpus[id];
703 		links[id].num_cpus = 1;
704 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
705 							  "iDisp%d Pin", i);
706 		if (!links[id].cpus->dai_name)
707 			goto devm_err;
708 
709 		if (idisp_codec) {
710 			idisp_components[i - 1].name = "ehdaudio0D2";
711 			idisp_components[i - 1].dai_name = devm_kasprintf(dev,
712 									  GFP_KERNEL,
713 									  "intel-hdmi-hifi%d",
714 									  i);
715 			if (!idisp_components[i - 1].dai_name)
716 				goto devm_err;
717 		} else {
718 			idisp_components[i - 1].name = "snd-soc-dummy";
719 			idisp_components[i - 1].dai_name = "snd-soc-dummy-dai";
720 		}
721 
722 		links[id].codecs = &idisp_components[i - 1];
723 		links[id].num_codecs = 1;
724 		links[id].platforms = platform_component;
725 		links[id].num_platforms = ARRAY_SIZE(platform_component);
726 		links[id].init = sof_hdmi_init;
727 		links[id].dpcm_playback = 1;
728 		links[id].no_pcm = 1;
729 		id++;
730 	}
731 
732 	/* speaker amp */
733 	if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) {
734 		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
735 						"SSP%d-Codec", ssp_amp);
736 		if (!links[id].name)
737 			goto devm_err;
738 
739 		links[id].id = id;
740 		if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT) {
741 			sof_rt1015_dai_link(&links[id]);
742 		} else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT) {
743 			sof_rt1015p_dai_link(&links[id]);
744 		} else if (sof_rt5682_quirk & SOF_RT1019_SPEAKER_AMP_PRESENT) {
745 			sof_rt1019p_dai_link(&links[id]);
746 		} else if (sof_rt5682_quirk &
747 				SOF_MAX98373_SPEAKER_AMP_PRESENT) {
748 			links[id].codecs = max_98373_components;
749 			links[id].num_codecs = ARRAY_SIZE(max_98373_components);
750 			links[id].init = max_98373_spk_codec_init;
751 			links[id].ops = &max_98373_ops;
752 			/* feedback stream */
753 			links[id].dpcm_capture = 1;
754 		} else if (sof_rt5682_quirk &
755 				SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
756 			max_98360a_dai_link(&links[id]);
757 		} else if (sof_rt5682_quirk &
758 				SOF_RT1011_SPEAKER_AMP_PRESENT) {
759 			sof_rt1011_dai_link(&links[id]);
760 		} else if (sof_rt5682_quirk &
761 				SOF_MAX98390_SPEAKER_AMP_PRESENT) {
762 			if (sof_rt5682_quirk &
763 				SOF_MAX98390_TWEETER_SPEAKER_PRESENT) {
764 				links[id].codecs = max_98390_4spk_components;
765 				links[id].num_codecs = ARRAY_SIZE(max_98390_4spk_components);
766 			} else {
767 				links[id].codecs = max_98390_components;
768 				links[id].num_codecs = ARRAY_SIZE(max_98390_components);
769 			}
770 			links[id].init = max_98390_spk_codec_init;
771 			links[id].ops = &max_98390_ops;
772 			links[id].dpcm_capture = 1;
773 
774 		} else {
775 			max_98357a_dai_link(&links[id]);
776 		}
777 		links[id].platforms = platform_component;
778 		links[id].num_platforms = ARRAY_SIZE(platform_component);
779 		links[id].dpcm_playback = 1;
780 		links[id].no_pcm = 1;
781 		links[id].cpus = &cpus[id];
782 		links[id].num_cpus = 1;
783 		if (is_legacy_cpu) {
784 			links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
785 								  "ssp%d-port",
786 								  ssp_amp);
787 			if (!links[id].cpus->dai_name)
788 				goto devm_err;
789 
790 		} else {
791 			links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
792 								  "SSP%d Pin",
793 								  ssp_amp);
794 			if (!links[id].cpus->dai_name)
795 				goto devm_err;
796 		}
797 		id++;
798 	}
799 
800 	/* BT audio offload */
801 	if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
802 		int port = (sof_rt5682_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
803 				SOF_BT_OFFLOAD_SSP_SHIFT;
804 
805 		links[id].id = id;
806 		links[id].cpus = &cpus[id];
807 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
808 							  "SSP%d Pin", port);
809 		if (!links[id].cpus->dai_name)
810 			goto devm_err;
811 		links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
812 		if (!links[id].name)
813 			goto devm_err;
814 		links[id].codecs = dummy_component;
815 		links[id].num_codecs = ARRAY_SIZE(dummy_component);
816 		links[id].platforms = platform_component;
817 		links[id].num_platforms = ARRAY_SIZE(platform_component);
818 		links[id].dpcm_playback = 1;
819 		links[id].dpcm_capture = 1;
820 		links[id].no_pcm = 1;
821 		links[id].num_cpus = 1;
822 	}
823 
824 	return links;
825 devm_err:
826 	return NULL;
827 }
828 
829 static int sof_audio_probe(struct platform_device *pdev)
830 {
831 	struct snd_soc_dai_link *dai_links;
832 	struct snd_soc_acpi_mach *mach;
833 	struct sof_card_private *ctx;
834 	int dmic_be_num, hdmi_num;
835 	int ret, ssp_amp, ssp_codec;
836 
837 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
838 	if (!ctx)
839 		return -ENOMEM;
840 
841 	if (pdev->id_entry && pdev->id_entry->driver_data)
842 		sof_rt5682_quirk = (unsigned long)pdev->id_entry->driver_data;
843 
844 	dmi_check_system(sof_rt5682_quirk_table);
845 
846 	mach = pdev->dev.platform_data;
847 
848 	/* A speaker amp might not be present when the quirk claims one is.
849 	 * Detect this via whether the machine driver match includes quirk_data.
850 	 */
851 	if ((sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) && !mach->quirk_data)
852 		sof_rt5682_quirk &= ~SOF_SPEAKER_AMP_PRESENT;
853 
854 	/* Detect the headset codec variant */
855 	if (acpi_dev_present("RTL5682", NULL, -1))
856 		sof_rt5682_quirk |= SOF_RT5682S_HEADPHONE_CODEC_PRESENT;
857 
858 	/* Detect the headset codec variant to support machines in DMI quirk */
859 	if (acpi_dev_present("RTL5682", NULL, -1))
860 		sof_rt5682_quirk |= SOF_RT5682S_HEADPHONE_CODEC_PRESENT;
861 
862 	if (soc_intel_is_byt() || soc_intel_is_cht()) {
863 		is_legacy_cpu = 1;
864 		dmic_be_num = 0;
865 		hdmi_num = 0;
866 		/* default quirk for legacy cpu */
867 		sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
868 						SOF_RT5682_MCLK_BYTCHT_EN |
869 						SOF_RT5682_SSP_CODEC(2);
870 	} else {
871 		dmic_be_num = 2;
872 		hdmi_num = (sof_rt5682_quirk & SOF_RT5682_NUM_HDMIDEV_MASK) >>
873 			 SOF_RT5682_NUM_HDMIDEV_SHIFT;
874 		/* default number of HDMI DAI's */
875 		if (!hdmi_num)
876 			hdmi_num = 3;
877 
878 		if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
879 			ctx->idisp_codec = true;
880 	}
881 
882 	/* need to get main clock from pmc */
883 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
884 		ctx->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
885 		if (IS_ERR(ctx->mclk)) {
886 			ret = PTR_ERR(ctx->mclk);
887 
888 			dev_err(&pdev->dev,
889 				"Failed to get MCLK from pmc_plt_clk_3: %d\n",
890 				ret);
891 			return ret;
892 		}
893 
894 		ret = clk_prepare_enable(ctx->mclk);
895 		if (ret < 0) {
896 			dev_err(&pdev->dev,
897 				"could not configure MCLK state");
898 			return ret;
899 		}
900 	}
901 
902 	dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk);
903 
904 	ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
905 			SOF_RT5682_SSP_AMP_SHIFT;
906 
907 	ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;
908 
909 	/* compute number of dai links */
910 	sof_audio_card_rt5682.num_links = 1 + dmic_be_num + hdmi_num;
911 
912 	if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT)
913 		sof_audio_card_rt5682.num_links++;
914 
915 	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT)
916 		max_98373_set_codec_conf(&sof_audio_card_rt5682);
917 	else if (sof_rt5682_quirk & SOF_RT1011_SPEAKER_AMP_PRESENT)
918 		sof_rt1011_codec_conf(&sof_audio_card_rt5682);
919 	else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
920 		sof_rt1015p_codec_conf(&sof_audio_card_rt5682);
921 	else if (sof_rt5682_quirk & SOF_MAX98390_SPEAKER_AMP_PRESENT) {
922 		if (sof_rt5682_quirk & SOF_MAX98390_TWEETER_SPEAKER_PRESENT)
923 			max_98390_set_codec_conf(&sof_audio_card_rt5682,
924 						 ARRAY_SIZE(max_98390_4spk_components));
925 		else
926 			max_98390_set_codec_conf(&sof_audio_card_rt5682,
927 						 ARRAY_SIZE(max_98390_components));
928 	}
929 
930 	if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
931 		sof_audio_card_rt5682.num_links++;
932 
933 	dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
934 					      dmic_be_num, hdmi_num, ctx->idisp_codec);
935 	if (!dai_links)
936 		return -ENOMEM;
937 
938 	sof_audio_card_rt5682.dai_link = dai_links;
939 
940 	if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT)
941 		sof_rt1015_codec_conf(&sof_audio_card_rt5682);
942 
943 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
944 
945 	sof_audio_card_rt5682.dev = &pdev->dev;
946 
947 	/* set platform name for each dailink */
948 	ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_rt5682,
949 						    mach->mach_params.platform);
950 	if (ret)
951 		return ret;
952 
953 	ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
954 
955 	snd_soc_card_set_drvdata(&sof_audio_card_rt5682, ctx);
956 
957 	return devm_snd_soc_register_card(&pdev->dev,
958 					  &sof_audio_card_rt5682);
959 }
960 
961 static const struct platform_device_id board_ids[] = {
962 	{
963 		.name = "sof_rt5682",
964 	},
965 	{
966 		.name = "tgl_mx98357_rt5682",
967 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
968 					SOF_RT5682_SSP_CODEC(0) |
969 					SOF_SPEAKER_AMP_PRESENT |
970 					SOF_RT5682_SSP_AMP(1) |
971 					SOF_RT5682_NUM_HDMIDEV(4) |
972 					SOF_BT_OFFLOAD_SSP(2) |
973 					SOF_SSP_BT_OFFLOAD_PRESENT),
974 	},
975 	{
976 		.name = "jsl_rt5682_rt1015",
977 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
978 					SOF_RT5682_MCLK_24MHZ |
979 					SOF_RT5682_SSP_CODEC(0) |
980 					SOF_SPEAKER_AMP_PRESENT |
981 					SOF_RT1015_SPEAKER_AMP_PRESENT |
982 					SOF_RT5682_SSP_AMP(1)),
983 	},
984 	{
985 		.name = "tgl_mx98373_rt5682",
986 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
987 					SOF_RT5682_SSP_CODEC(0) |
988 					SOF_SPEAKER_AMP_PRESENT |
989 					SOF_MAX98373_SPEAKER_AMP_PRESENT |
990 					SOF_RT5682_SSP_AMP(1) |
991 					SOF_RT5682_NUM_HDMIDEV(4) |
992 					SOF_BT_OFFLOAD_SSP(2) |
993 					SOF_SSP_BT_OFFLOAD_PRESENT),
994 	},
995 	{
996 		.name = "jsl_rt5682_mx98360",
997 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
998 					SOF_RT5682_MCLK_24MHZ |
999 					SOF_RT5682_SSP_CODEC(0) |
1000 					SOF_SPEAKER_AMP_PRESENT |
1001 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1002 					SOF_RT5682_SSP_AMP(1)),
1003 	},
1004 	{
1005 		.name = "cml_rt1015_rt5682",
1006 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1007 					SOF_RT5682_MCLK_24MHZ |
1008 					SOF_RT5682_SSP_CODEC(0) |
1009 					SOF_SPEAKER_AMP_PRESENT |
1010 					SOF_RT1015_SPEAKER_AMP_PRESENT |
1011 					SOF_RT5682_SSP_AMP(1)),
1012 	},
1013 	{
1014 		.name = "tgl_rt1011_rt5682",
1015 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1016 					SOF_RT5682_SSP_CODEC(0) |
1017 					SOF_SPEAKER_AMP_PRESENT |
1018 					SOF_RT1011_SPEAKER_AMP_PRESENT |
1019 					SOF_RT5682_SSP_AMP(1) |
1020 					SOF_RT5682_NUM_HDMIDEV(4) |
1021 					SOF_BT_OFFLOAD_SSP(2) |
1022 					SOF_SSP_BT_OFFLOAD_PRESENT),
1023 	},
1024 	{
1025 		.name = "jsl_rt5682_rt1015p",
1026 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1027 					SOF_RT5682_MCLK_24MHZ |
1028 					SOF_RT5682_SSP_CODEC(0) |
1029 					SOF_SPEAKER_AMP_PRESENT |
1030 					SOF_RT1015P_SPEAKER_AMP_PRESENT |
1031 					SOF_RT5682_SSP_AMP(1)),
1032 	},
1033 	{
1034 		.name = "adl_mx98373_rt5682",
1035 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1036 					SOF_RT5682_SSP_CODEC(0) |
1037 					SOF_SPEAKER_AMP_PRESENT |
1038 					SOF_MAX98373_SPEAKER_AMP_PRESENT |
1039 					SOF_RT5682_SSP_AMP(1) |
1040 					SOF_RT5682_NUM_HDMIDEV(4) |
1041 					SOF_BT_OFFLOAD_SSP(2) |
1042 					SOF_SSP_BT_OFFLOAD_PRESENT),
1043 	},
1044 	{
1045 		.name = "adl_mx98357_rt5682",
1046 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1047 					SOF_RT5682_SSP_CODEC(0) |
1048 					SOF_SPEAKER_AMP_PRESENT |
1049 					SOF_RT5682_SSP_AMP(2) |
1050 					SOF_RT5682_NUM_HDMIDEV(4)),
1051 	},
1052 	{
1053 		.name = "adl_max98390_rt5682",
1054 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1055 					SOF_RT5682_SSP_CODEC(0) |
1056 					SOF_SPEAKER_AMP_PRESENT |
1057 					SOF_MAX98390_SPEAKER_AMP_PRESENT |
1058 					SOF_RT5682_SSP_AMP(1) |
1059 					SOF_RT5682_NUM_HDMIDEV(4) |
1060 					SOF_BT_OFFLOAD_SSP(2) |
1061 					SOF_SSP_BT_OFFLOAD_PRESENT),
1062 	},
1063 	{
1064 		.name = "adl_mx98360_rt5682",
1065 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1066 					SOF_RT5682_SSP_CODEC(0) |
1067 					SOF_SPEAKER_AMP_PRESENT |
1068 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1069 					SOF_RT5682_SSP_AMP(1) |
1070 					SOF_RT5682_NUM_HDMIDEV(4) |
1071 					SOF_BT_OFFLOAD_SSP(2) |
1072 					SOF_SSP_BT_OFFLOAD_PRESENT),
1073 	},
1074 	{
1075 		.name = "adl_rt5682",
1076 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1077 					SOF_RT5682_SSP_CODEC(0) |
1078 					SOF_RT5682_NUM_HDMIDEV(4) |
1079 					SOF_BT_OFFLOAD_SSP(2) |
1080 					SOF_SSP_BT_OFFLOAD_PRESENT),
1081 	},
1082 	{
1083 		.name = "adl_rt1019_rt5682s",
1084 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1085 					SOF_RT5682_SSP_CODEC(0) |
1086 					SOF_RT5682S_HEADPHONE_CODEC_PRESENT |
1087 					SOF_SPEAKER_AMP_PRESENT |
1088 					SOF_RT1019_SPEAKER_AMP_PRESENT |
1089 					SOF_RT5682_SSP_AMP(1) |
1090 					SOF_RT5682_NUM_HDMIDEV(4)),
1091 	},
1092 	{
1093 		.name = "mtl_mx98357_rt5682",
1094 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1095 					SOF_RT5682_SSP_CODEC(0) |
1096 					SOF_SPEAKER_AMP_PRESENT |
1097 					SOF_RT5682_SSP_AMP(1) |
1098 					SOF_RT5682_NUM_HDMIDEV(4)),
1099 	},
1100 	{ }
1101 };
1102 MODULE_DEVICE_TABLE(platform, board_ids);
1103 
1104 static struct platform_driver sof_audio = {
1105 	.probe = sof_audio_probe,
1106 	.driver = {
1107 		.name = "sof_rt5682",
1108 		.pm = &snd_soc_pm_ops,
1109 	},
1110 	.id_table = board_ids,
1111 };
1112 module_platform_driver(sof_audio)
1113 
1114 /* Module information */
1115 MODULE_DESCRIPTION("SOF Audio Machine driver");
1116 MODULE_AUTHOR("Bard Liao <bard.liao@intel.com>");
1117 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
1118 MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
1119 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
1120 MODULE_LICENSE("GPL v2");
1121 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
1122 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
1123 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);
1124