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 		.callback = sof_rt5682_quirk_cb,
228 		.matches = {
229 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
230 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S"),
231 		},
232 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
233 					SOF_RT5682_SSP_CODEC(2) |
234 					SOF_SPEAKER_AMP_PRESENT |
235 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
236 					SOF_RT5682_SSP_AMP(0) |
237 					SOF_RT5682_NUM_HDMIDEV(4) |
238 					SOF_BT_OFFLOAD_SSP(1) |
239 					SOF_SSP_BT_OFFLOAD_PRESENT
240 					),
241 	},
242 	{
243 		.callback = sof_rt5682_quirk_cb,
244 		.matches = {
245 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
246 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-ALC1019_ALC5682I_I2S"),
247 		},
248 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
249 					SOF_RT5682_SSP_CODEC(2) |
250 					SOF_SPEAKER_AMP_PRESENT |
251 					SOF_RT1019_SPEAKER_AMP_PRESENT |
252 					SOF_RT5682_SSP_AMP(0) |
253 					SOF_RT5682_NUM_HDMIDEV(3)
254 					),
255 	},
256 	{
257 		.callback = sof_rt5682_quirk_cb,
258 		.matches = {
259 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
260 		},
261 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
262 					SOF_RT5682_SSP_CODEC(2) |
263 					SOF_SPEAKER_AMP_PRESENT |
264 					SOF_RT5682_SSP_AMP(0) |
265 					SOF_RT5682_NUM_HDMIDEV(4) |
266 					SOF_BT_OFFLOAD_SSP(1) |
267 					SOF_SSP_BT_OFFLOAD_PRESENT
268 					),
269 	},
270 	{}
271 };
272 
273 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
274 {
275 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
276 	struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
277 	struct sof_hdmi_pcm *pcm;
278 
279 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
280 	if (!pcm)
281 		return -ENOMEM;
282 
283 	/* dai_link id is 1:1 mapped to the PCM device */
284 	pcm->device = rtd->dai_link->id;
285 	pcm->codec_dai = dai;
286 
287 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
288 
289 	return 0;
290 }
291 
292 static struct snd_soc_jack_pin jack_pins[] = {
293 	{
294 		.pin    = "Headphone Jack",
295 		.mask   = SND_JACK_HEADPHONE,
296 	},
297 	{
298 		.pin    = "Headset Mic",
299 		.mask   = SND_JACK_MICROPHONE,
300 	},
301 };
302 
303 static int sof_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
304 {
305 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
306 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
307 	struct snd_soc_jack *jack;
308 	int ret;
309 
310 	/* need to enable ASRC function for 24MHz mclk rate */
311 	if ((sof_rt5682_quirk & SOF_RT5682_MCLK_EN) &&
312 	    (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ)) {
313 		if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
314 			rt5682s_sel_asrc_clk_src(component,
315 						 RT5682S_DA_STEREO1_FILTER |
316 						 RT5682S_AD_STEREO1_FILTER,
317 						 RT5682S_CLK_SEL_I2S1_ASRC);
318 		else
319 			rt5682_sel_asrc_clk_src(component,
320 						RT5682_DA_STEREO1_FILTER |
321 						RT5682_AD_STEREO1_FILTER,
322 						RT5682_CLK_SEL_I2S1_ASRC);
323 	}
324 
325 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
326 		/*
327 		 * The firmware might enable the clock at
328 		 * boot (this information may or may not
329 		 * be reflected in the enable clock register).
330 		 * To change the rate we must disable the clock
331 		 * first to cover these cases. Due to common
332 		 * clock framework restrictions that do not allow
333 		 * to disable a clock that has not been enabled,
334 		 * we need to enable the clock first.
335 		 */
336 		ret = clk_prepare_enable(ctx->mclk);
337 		if (!ret)
338 			clk_disable_unprepare(ctx->mclk);
339 
340 		ret = clk_set_rate(ctx->mclk, 19200000);
341 
342 		if (ret)
343 			dev_err(rtd->dev, "unable to set MCLK rate\n");
344 	}
345 
346 	/*
347 	 * Headset buttons map to the google Reference headset.
348 	 * These can be configured by userspace.
349 	 */
350 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
351 					 SND_JACK_HEADSET | SND_JACK_BTN_0 |
352 					 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
353 					 SND_JACK_BTN_3,
354 					 &ctx->sof_headset,
355 					 jack_pins,
356 					 ARRAY_SIZE(jack_pins));
357 	if (ret) {
358 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
359 		return ret;
360 	}
361 
362 	jack = &ctx->sof_headset;
363 
364 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
365 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
366 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
367 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
368 	ret = snd_soc_component_set_jack(component, jack, NULL);
369 
370 	if (ret) {
371 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
372 		return ret;
373 	}
374 
375 	return ret;
376 };
377 
378 static void sof_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
379 {
380 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
381 
382 	snd_soc_component_set_jack(component, NULL, NULL);
383 }
384 
385 static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
386 				struct snd_pcm_hw_params *params)
387 {
388 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
389 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
390 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
391 	int pll_id, pll_source, pll_in, pll_out, clk_id, ret;
392 
393 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_EN) {
394 		if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
395 			ret = clk_prepare_enable(ctx->mclk);
396 			if (ret < 0) {
397 				dev_err(rtd->dev,
398 					"could not configure MCLK state");
399 				return ret;
400 			}
401 		}
402 
403 		if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
404 			pll_source = RT5682S_PLL_S_MCLK;
405 		else
406 			pll_source = RT5682_PLL1_S_MCLK;
407 
408 		/* get the tplg configured mclk. */
409 		pll_in = sof_dai_get_mclk(rtd);
410 
411 		/* mclk from the quirk is the first choice */
412 		if (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ) {
413 			if (pll_in != 24000000)
414 				dev_warn(rtd->dev, "configure wrong mclk in tplg, please use 24MHz.\n");
415 			pll_in = 24000000;
416 		} else if (pll_in == 0) {
417 			/* use default mclk if not specified correct in topology */
418 			pll_in = 19200000;
419 		} else if (pll_in < 0) {
420 			return pll_in;
421 		}
422 	} else {
423 		if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
424 			pll_source = RT5682S_PLL_S_BCLK1;
425 		else
426 			pll_source = RT5682_PLL1_S_BCLK1;
427 
428 		pll_in = params_rate(params) * 50;
429 	}
430 
431 	if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT) {
432 		pll_id = RT5682S_PLL2;
433 		clk_id = RT5682S_SCLK_S_PLL2;
434 	} else {
435 		pll_id = RT5682_PLL1;
436 		clk_id = RT5682_SCLK_S_PLL1;
437 	}
438 
439 	pll_out = params_rate(params) * 512;
440 
441 	/* when MCLK is 512FS, no need to set PLL configuration additionally. */
442 	if (pll_in == pll_out)
443 		clk_id = RT5682S_SCLK_S_MCLK;
444 	else {
445 		/* Configure pll for codec */
446 		ret = snd_soc_dai_set_pll(codec_dai, pll_id, pll_source, pll_in,
447 					  pll_out);
448 		if (ret < 0)
449 			dev_err(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
450 	}
451 
452 	/* Configure sysclk for codec */
453 	ret = snd_soc_dai_set_sysclk(codec_dai, clk_id,
454 				     pll_out, SND_SOC_CLOCK_IN);
455 	if (ret < 0)
456 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
457 
458 	/*
459 	 * slot_width should equal or large than data length, set them
460 	 * be the same
461 	 */
462 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
463 				       params_width(params));
464 	if (ret < 0) {
465 		dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
466 		return ret;
467 	}
468 
469 	return ret;
470 }
471 
472 static struct snd_soc_ops sof_rt5682_ops = {
473 	.hw_params = sof_rt5682_hw_params,
474 };
475 
476 static struct snd_soc_dai_link_component platform_component[] = {
477 	{
478 		/* name might be overridden during probe */
479 		.name = "0000:00:1f.3"
480 	}
481 };
482 
483 static int sof_card_late_probe(struct snd_soc_card *card)
484 {
485 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
486 	struct snd_soc_component *component = NULL;
487 	struct snd_soc_dapm_context *dapm = &card->dapm;
488 	char jack_name[NAME_SIZE];
489 	struct sof_hdmi_pcm *pcm;
490 	int err;
491 
492 	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
493 		/* Disable Left and Right Spk pin after boot */
494 		snd_soc_dapm_disable_pin(dapm, "Left Spk");
495 		snd_soc_dapm_disable_pin(dapm, "Right Spk");
496 		err = snd_soc_dapm_sync(dapm);
497 		if (err < 0)
498 			return err;
499 	}
500 
501 	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
502 	if (is_legacy_cpu || !ctx->idisp_codec)
503 		return 0;
504 
505 	if (list_empty(&ctx->hdmi_pcm_list))
506 		return -EINVAL;
507 
508 	if (ctx->common_hdmi_codec_drv) {
509 		pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
510 				       head);
511 		component = pcm->codec_dai->component;
512 		return hda_dsp_hdmi_build_controls(card, component);
513 	}
514 
515 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
516 		component = pcm->codec_dai->component;
517 		snprintf(jack_name, sizeof(jack_name),
518 			 "HDMI/DP, pcm=%d Jack", pcm->device);
519 		err = snd_soc_card_jack_new(card, jack_name,
520 					    SND_JACK_AVOUT, &pcm->hdmi_jack);
521 
522 		if (err)
523 			return err;
524 
525 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
526 					  &pcm->hdmi_jack);
527 		if (err < 0)
528 			return err;
529 	}
530 
531 	return hdac_hdmi_jack_port_init(component, &card->dapm);
532 }
533 
534 static const struct snd_kcontrol_new sof_controls[] = {
535 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
536 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
537 	SOC_DAPM_PIN_SWITCH("Left Spk"),
538 	SOC_DAPM_PIN_SWITCH("Right Spk"),
539 
540 };
541 
542 static const struct snd_soc_dapm_widget sof_widgets[] = {
543 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
544 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
545 	SND_SOC_DAPM_SPK("Left Spk", NULL),
546 	SND_SOC_DAPM_SPK("Right Spk", NULL),
547 };
548 
549 static const struct snd_soc_dapm_widget dmic_widgets[] = {
550 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
551 };
552 
553 static const struct snd_soc_dapm_route sof_map[] = {
554 	/* HP jack connectors - unknown if we have jack detection */
555 	{ "Headphone Jack", NULL, "HPOL" },
556 	{ "Headphone Jack", NULL, "HPOR" },
557 
558 	/* other jacks */
559 	{ "IN1P", NULL, "Headset Mic" },
560 };
561 
562 static const struct snd_soc_dapm_route dmic_map[] = {
563 	/* digital mics */
564 	{"DMic", NULL, "SoC DMIC"},
565 };
566 
567 static int dmic_init(struct snd_soc_pcm_runtime *rtd)
568 {
569 	struct snd_soc_card *card = rtd->card;
570 	int ret;
571 
572 	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
573 					ARRAY_SIZE(dmic_widgets));
574 	if (ret) {
575 		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
576 		/* Don't need to add routes if widget addition failed */
577 		return ret;
578 	}
579 
580 	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
581 				      ARRAY_SIZE(dmic_map));
582 
583 	if (ret)
584 		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
585 
586 	return ret;
587 }
588 
589 /* sof audio machine driver for rt5682 codec */
590 static struct snd_soc_card sof_audio_card_rt5682 = {
591 	.name = "rt5682", /* the sof- prefix is added by the core */
592 	.owner = THIS_MODULE,
593 	.controls = sof_controls,
594 	.num_controls = ARRAY_SIZE(sof_controls),
595 	.dapm_widgets = sof_widgets,
596 	.num_dapm_widgets = ARRAY_SIZE(sof_widgets),
597 	.dapm_routes = sof_map,
598 	.num_dapm_routes = ARRAY_SIZE(sof_map),
599 	.fully_routed = true,
600 	.late_probe = sof_card_late_probe,
601 };
602 
603 static struct snd_soc_dai_link_component rt5682_component[] = {
604 	{
605 		.name = "i2c-10EC5682:00",
606 		.dai_name = "rt5682-aif1",
607 	}
608 };
609 
610 static struct snd_soc_dai_link_component rt5682s_component[] = {
611 	{
612 		.name = "i2c-RTL5682:00",
613 		.dai_name = "rt5682s-aif1",
614 	}
615 };
616 
617 static struct snd_soc_dai_link_component dmic_component[] = {
618 	{
619 		.name = "dmic-codec",
620 		.dai_name = "dmic-hifi",
621 	}
622 };
623 
624 #define IDISP_CODEC_MASK	0x4
625 
626 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
627 							  int ssp_codec,
628 							  int ssp_amp,
629 							  int dmic_be_num,
630 							  int hdmi_num,
631 							  bool idisp_codec)
632 {
633 	struct snd_soc_dai_link_component *idisp_components;
634 	struct snd_soc_dai_link_component *cpus;
635 	struct snd_soc_dai_link *links;
636 	int i, id = 0;
637 
638 	links = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
639 			    sizeof(struct snd_soc_dai_link), GFP_KERNEL);
640 	cpus = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
641 			    sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
642 	if (!links || !cpus)
643 		goto devm_err;
644 
645 	/* codec SSP */
646 	links[id].name = devm_kasprintf(dev, GFP_KERNEL,
647 					"SSP%d-Codec", ssp_codec);
648 	if (!links[id].name)
649 		goto devm_err;
650 
651 	links[id].id = id;
652 	if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT) {
653 		links[id].codecs = rt5682s_component;
654 		links[id].num_codecs = ARRAY_SIZE(rt5682s_component);
655 	} else {
656 		links[id].codecs = rt5682_component;
657 		links[id].num_codecs = ARRAY_SIZE(rt5682_component);
658 	}
659 	links[id].platforms = platform_component;
660 	links[id].num_platforms = ARRAY_SIZE(platform_component);
661 	links[id].init = sof_rt5682_codec_init;
662 	links[id].exit = sof_rt5682_codec_exit;
663 	links[id].ops = &sof_rt5682_ops;
664 	links[id].dpcm_playback = 1;
665 	links[id].dpcm_capture = 1;
666 	links[id].no_pcm = 1;
667 	links[id].cpus = &cpus[id];
668 	links[id].num_cpus = 1;
669 	if (is_legacy_cpu) {
670 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
671 							  "ssp%d-port",
672 							  ssp_codec);
673 		if (!links[id].cpus->dai_name)
674 			goto devm_err;
675 	} else {
676 		/*
677 		 * Currently, On SKL+ platforms MCLK will be turned off in sof
678 		 * runtime suspended, and it will go into runtime suspended
679 		 * right after playback is stop. However, rt5682 will output
680 		 * static noise if sysclk turns off during playback. Set
681 		 * ignore_pmdown_time to power down rt5682 immediately and
682 		 * avoid the noise.
683 		 * It can be removed once we can control MCLK by driver.
684 		 */
685 		links[id].ignore_pmdown_time = 1;
686 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
687 							  "SSP%d Pin",
688 							  ssp_codec);
689 		if (!links[id].cpus->dai_name)
690 			goto devm_err;
691 	}
692 	id++;
693 
694 	/* dmic */
695 	if (dmic_be_num > 0) {
696 		/* at least we have dmic01 */
697 		links[id].name = "dmic01";
698 		links[id].cpus = &cpus[id];
699 		links[id].cpus->dai_name = "DMIC01 Pin";
700 		links[id].init = dmic_init;
701 		if (dmic_be_num > 1) {
702 			/* set up 2 BE links at most */
703 			links[id + 1].name = "dmic16k";
704 			links[id + 1].cpus = &cpus[id + 1];
705 			links[id + 1].cpus->dai_name = "DMIC16k Pin";
706 			dmic_be_num = 2;
707 		}
708 	}
709 
710 	for (i = 0; i < dmic_be_num; i++) {
711 		links[id].id = id;
712 		links[id].num_cpus = 1;
713 		links[id].codecs = dmic_component;
714 		links[id].num_codecs = ARRAY_SIZE(dmic_component);
715 		links[id].platforms = platform_component;
716 		links[id].num_platforms = ARRAY_SIZE(platform_component);
717 		links[id].ignore_suspend = 1;
718 		links[id].dpcm_capture = 1;
719 		links[id].no_pcm = 1;
720 		id++;
721 	}
722 
723 	/* HDMI */
724 	if (hdmi_num > 0) {
725 		idisp_components = devm_kcalloc(dev,
726 				   hdmi_num,
727 				   sizeof(struct snd_soc_dai_link_component),
728 				   GFP_KERNEL);
729 		if (!idisp_components)
730 			goto devm_err;
731 	}
732 	for (i = 1; i <= hdmi_num; i++) {
733 		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
734 						"iDisp%d", i);
735 		if (!links[id].name)
736 			goto devm_err;
737 
738 		links[id].id = id;
739 		links[id].cpus = &cpus[id];
740 		links[id].num_cpus = 1;
741 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
742 							  "iDisp%d Pin", i);
743 		if (!links[id].cpus->dai_name)
744 			goto devm_err;
745 
746 		if (idisp_codec) {
747 			idisp_components[i - 1].name = "ehdaudio0D2";
748 			idisp_components[i - 1].dai_name = devm_kasprintf(dev,
749 									  GFP_KERNEL,
750 									  "intel-hdmi-hifi%d",
751 									  i);
752 			if (!idisp_components[i - 1].dai_name)
753 				goto devm_err;
754 		} else {
755 			idisp_components[i - 1] = asoc_dummy_dlc;
756 		}
757 
758 		links[id].codecs = &idisp_components[i - 1];
759 		links[id].num_codecs = 1;
760 		links[id].platforms = platform_component;
761 		links[id].num_platforms = ARRAY_SIZE(platform_component);
762 		links[id].init = sof_hdmi_init;
763 		links[id].dpcm_playback = 1;
764 		links[id].no_pcm = 1;
765 		id++;
766 	}
767 
768 	/* speaker amp */
769 	if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) {
770 		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
771 						"SSP%d-Codec", ssp_amp);
772 		if (!links[id].name)
773 			goto devm_err;
774 
775 		links[id].id = id;
776 		if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT) {
777 			sof_rt1015_dai_link(&links[id]);
778 		} else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT) {
779 			sof_rt1015p_dai_link(&links[id]);
780 		} else if (sof_rt5682_quirk & SOF_RT1019_SPEAKER_AMP_PRESENT) {
781 			sof_rt1019p_dai_link(&links[id]);
782 		} else if (sof_rt5682_quirk &
783 				SOF_MAX98373_SPEAKER_AMP_PRESENT) {
784 			links[id].codecs = max_98373_components;
785 			links[id].num_codecs = ARRAY_SIZE(max_98373_components);
786 			links[id].init = max_98373_spk_codec_init;
787 			links[id].ops = &max_98373_ops;
788 		} else if (sof_rt5682_quirk &
789 				SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
790 			max_98360a_dai_link(&links[id]);
791 		} else if (sof_rt5682_quirk &
792 				SOF_RT1011_SPEAKER_AMP_PRESENT) {
793 			sof_rt1011_dai_link(&links[id]);
794 		} else if (sof_rt5682_quirk &
795 				SOF_MAX98390_SPEAKER_AMP_PRESENT) {
796 			if (sof_rt5682_quirk &
797 				SOF_MAX98390_TWEETER_SPEAKER_PRESENT) {
798 				links[id].codecs = max_98390_4spk_components;
799 				links[id].num_codecs = ARRAY_SIZE(max_98390_4spk_components);
800 			} else {
801 				links[id].codecs = max_98390_components;
802 				links[id].num_codecs = ARRAY_SIZE(max_98390_components);
803 			}
804 			links[id].init = max_98390_spk_codec_init;
805 			links[id].ops = &max_98390_ops;
806 
807 		} else {
808 			max_98357a_dai_link(&links[id]);
809 		}
810 		links[id].platforms = platform_component;
811 		links[id].num_platforms = ARRAY_SIZE(platform_component);
812 		links[id].dpcm_playback = 1;
813 		/* feedback stream or firmware-generated echo reference */
814 		links[id].dpcm_capture = 1;
815 
816 		links[id].no_pcm = 1;
817 		links[id].cpus = &cpus[id];
818 		links[id].num_cpus = 1;
819 		if (is_legacy_cpu) {
820 			links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
821 								  "ssp%d-port",
822 								  ssp_amp);
823 			if (!links[id].cpus->dai_name)
824 				goto devm_err;
825 
826 		} else {
827 			links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
828 								  "SSP%d Pin",
829 								  ssp_amp);
830 			if (!links[id].cpus->dai_name)
831 				goto devm_err;
832 		}
833 		id++;
834 	}
835 
836 	/* BT audio offload */
837 	if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
838 		int port = (sof_rt5682_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
839 				SOF_BT_OFFLOAD_SSP_SHIFT;
840 
841 		links[id].id = id;
842 		links[id].cpus = &cpus[id];
843 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
844 							  "SSP%d Pin", port);
845 		if (!links[id].cpus->dai_name)
846 			goto devm_err;
847 		links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
848 		if (!links[id].name)
849 			goto devm_err;
850 		links[id].codecs = &asoc_dummy_dlc;
851 		links[id].num_codecs = 1;
852 		links[id].platforms = platform_component;
853 		links[id].num_platforms = ARRAY_SIZE(platform_component);
854 		links[id].dpcm_playback = 1;
855 		links[id].dpcm_capture = 1;
856 		links[id].no_pcm = 1;
857 		links[id].num_cpus = 1;
858 	}
859 
860 	return links;
861 devm_err:
862 	return NULL;
863 }
864 
865 static int sof_audio_probe(struct platform_device *pdev)
866 {
867 	struct snd_soc_dai_link *dai_links;
868 	struct snd_soc_acpi_mach *mach;
869 	struct sof_card_private *ctx;
870 	int dmic_be_num, hdmi_num;
871 	int ret, ssp_amp, ssp_codec;
872 
873 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
874 	if (!ctx)
875 		return -ENOMEM;
876 
877 	if (pdev->id_entry && pdev->id_entry->driver_data)
878 		sof_rt5682_quirk = (unsigned long)pdev->id_entry->driver_data;
879 
880 	dmi_check_system(sof_rt5682_quirk_table);
881 
882 	mach = pdev->dev.platform_data;
883 
884 	/* A speaker amp might not be present when the quirk claims one is.
885 	 * Detect this via whether the machine driver match includes quirk_data.
886 	 */
887 	if ((sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) && !mach->quirk_data)
888 		sof_rt5682_quirk &= ~SOF_SPEAKER_AMP_PRESENT;
889 
890 	/* Detect the headset codec variant */
891 	if (acpi_dev_present("RTL5682", NULL, -1))
892 		sof_rt5682_quirk |= SOF_RT5682S_HEADPHONE_CODEC_PRESENT;
893 
894 	if (soc_intel_is_byt() || soc_intel_is_cht()) {
895 		is_legacy_cpu = 1;
896 		dmic_be_num = 0;
897 		hdmi_num = 0;
898 		/* default quirk for legacy cpu */
899 		sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
900 						SOF_RT5682_MCLK_BYTCHT_EN |
901 						SOF_RT5682_SSP_CODEC(2);
902 	} else {
903 		dmic_be_num = 2;
904 		hdmi_num = (sof_rt5682_quirk & SOF_RT5682_NUM_HDMIDEV_MASK) >>
905 			 SOF_RT5682_NUM_HDMIDEV_SHIFT;
906 		/* default number of HDMI DAI's */
907 		if (!hdmi_num)
908 			hdmi_num = 3;
909 
910 		if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
911 			ctx->idisp_codec = true;
912 	}
913 
914 	/* need to get main clock from pmc */
915 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
916 		ctx->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
917 		if (IS_ERR(ctx->mclk)) {
918 			ret = PTR_ERR(ctx->mclk);
919 
920 			dev_err(&pdev->dev,
921 				"Failed to get MCLK from pmc_plt_clk_3: %d\n",
922 				ret);
923 			return ret;
924 		}
925 
926 		ret = clk_prepare_enable(ctx->mclk);
927 		if (ret < 0) {
928 			dev_err(&pdev->dev,
929 				"could not configure MCLK state");
930 			return ret;
931 		}
932 	}
933 
934 	dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk);
935 
936 	ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
937 			SOF_RT5682_SSP_AMP_SHIFT;
938 
939 	ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;
940 
941 	/* compute number of dai links */
942 	sof_audio_card_rt5682.num_links = 1 + dmic_be_num + hdmi_num;
943 
944 	if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT)
945 		sof_audio_card_rt5682.num_links++;
946 
947 	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT)
948 		max_98373_set_codec_conf(&sof_audio_card_rt5682);
949 	else if (sof_rt5682_quirk & SOF_RT1011_SPEAKER_AMP_PRESENT)
950 		sof_rt1011_codec_conf(&sof_audio_card_rt5682);
951 	else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
952 		sof_rt1015p_codec_conf(&sof_audio_card_rt5682);
953 	else if (sof_rt5682_quirk & SOF_MAX98390_SPEAKER_AMP_PRESENT) {
954 		if (sof_rt5682_quirk & SOF_MAX98390_TWEETER_SPEAKER_PRESENT)
955 			max_98390_set_codec_conf(&sof_audio_card_rt5682,
956 						 ARRAY_SIZE(max_98390_4spk_components));
957 		else
958 			max_98390_set_codec_conf(&sof_audio_card_rt5682,
959 						 ARRAY_SIZE(max_98390_components));
960 	}
961 
962 	if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
963 		sof_audio_card_rt5682.num_links++;
964 
965 	dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
966 					      dmic_be_num, hdmi_num, ctx->idisp_codec);
967 	if (!dai_links)
968 		return -ENOMEM;
969 
970 	sof_audio_card_rt5682.dai_link = dai_links;
971 
972 	if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT)
973 		sof_rt1015_codec_conf(&sof_audio_card_rt5682);
974 
975 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
976 
977 	sof_audio_card_rt5682.dev = &pdev->dev;
978 
979 	/* set platform name for each dailink */
980 	ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_rt5682,
981 						    mach->mach_params.platform);
982 	if (ret)
983 		return ret;
984 
985 	ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
986 
987 	snd_soc_card_set_drvdata(&sof_audio_card_rt5682, ctx);
988 
989 	return devm_snd_soc_register_card(&pdev->dev,
990 					  &sof_audio_card_rt5682);
991 }
992 
993 static const struct platform_device_id board_ids[] = {
994 	{
995 		.name = "sof_rt5682",
996 	},
997 	{
998 		.name = "cml_rt1015_rt5682",
999 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1000 					SOF_RT5682_MCLK_24MHZ |
1001 					SOF_RT5682_SSP_CODEC(0) |
1002 					SOF_SPEAKER_AMP_PRESENT |
1003 					SOF_RT1015_SPEAKER_AMP_PRESENT |
1004 					SOF_RT5682_SSP_AMP(1)),
1005 	},
1006 	{
1007 		.name = "jsl_rt5682_rt1015",
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_RT1015_SPEAKER_AMP_PRESENT |
1013 					SOF_RT5682_SSP_AMP(1)),
1014 	},
1015 	{
1016 		.name = "jsl_rt5682_mx98360",
1017 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1018 					SOF_RT5682_MCLK_24MHZ |
1019 					SOF_RT5682_SSP_CODEC(0) |
1020 					SOF_SPEAKER_AMP_PRESENT |
1021 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1022 					SOF_RT5682_SSP_AMP(1)),
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 = "jsl_rt5682",
1035 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1036 					SOF_RT5682_MCLK_24MHZ |
1037 					SOF_RT5682_SSP_CODEC(0)),
1038 	},
1039 	{
1040 		.name = "tgl_mx98357_rt5682",
1041 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1042 					SOF_RT5682_SSP_CODEC(0) |
1043 					SOF_SPEAKER_AMP_PRESENT |
1044 					SOF_RT5682_SSP_AMP(1) |
1045 					SOF_RT5682_NUM_HDMIDEV(4) |
1046 					SOF_BT_OFFLOAD_SSP(2) |
1047 					SOF_SSP_BT_OFFLOAD_PRESENT),
1048 	},
1049 	{
1050 		.name = "tgl_rt1011_rt5682",
1051 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1052 					SOF_RT5682_SSP_CODEC(0) |
1053 					SOF_SPEAKER_AMP_PRESENT |
1054 					SOF_RT1011_SPEAKER_AMP_PRESENT |
1055 					SOF_RT5682_SSP_AMP(1) |
1056 					SOF_RT5682_NUM_HDMIDEV(4) |
1057 					SOF_BT_OFFLOAD_SSP(2) |
1058 					SOF_SSP_BT_OFFLOAD_PRESENT),
1059 	},
1060 	{
1061 		.name = "tgl_mx98373_rt5682",
1062 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1063 					SOF_RT5682_SSP_CODEC(0) |
1064 					SOF_SPEAKER_AMP_PRESENT |
1065 					SOF_MAX98373_SPEAKER_AMP_PRESENT |
1066 					SOF_RT5682_SSP_AMP(1) |
1067 					SOF_RT5682_NUM_HDMIDEV(4) |
1068 					SOF_BT_OFFLOAD_SSP(2) |
1069 					SOF_SSP_BT_OFFLOAD_PRESENT),
1070 	},
1071 	{
1072 		.name = "adl_mx98373_rt5682",
1073 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1074 					SOF_RT5682_SSP_CODEC(0) |
1075 					SOF_SPEAKER_AMP_PRESENT |
1076 					SOF_MAX98373_SPEAKER_AMP_PRESENT |
1077 					SOF_RT5682_SSP_AMP(1) |
1078 					SOF_RT5682_NUM_HDMIDEV(4) |
1079 					SOF_BT_OFFLOAD_SSP(2) |
1080 					SOF_SSP_BT_OFFLOAD_PRESENT),
1081 	},
1082 	{
1083 		.name = "adl_mx98357_rt5682",
1084 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1085 					SOF_RT5682_SSP_CODEC(0) |
1086 					SOF_SPEAKER_AMP_PRESENT |
1087 					SOF_RT5682_SSP_AMP(2) |
1088 					SOF_RT5682_NUM_HDMIDEV(4)),
1089 	},
1090 	{
1091 		.name = "adl_max98390_rt5682",
1092 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1093 					SOF_RT5682_SSP_CODEC(0) |
1094 					SOF_SPEAKER_AMP_PRESENT |
1095 					SOF_MAX98390_SPEAKER_AMP_PRESENT |
1096 					SOF_RT5682_SSP_AMP(1) |
1097 					SOF_RT5682_NUM_HDMIDEV(4) |
1098 					SOF_BT_OFFLOAD_SSP(2) |
1099 					SOF_SSP_BT_OFFLOAD_PRESENT),
1100 	},
1101 	{
1102 		.name = "adl_mx98360_rt5682",
1103 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1104 					SOF_RT5682_SSP_CODEC(0) |
1105 					SOF_SPEAKER_AMP_PRESENT |
1106 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1107 					SOF_RT5682_SSP_AMP(1) |
1108 					SOF_RT5682_NUM_HDMIDEV(4) |
1109 					SOF_BT_OFFLOAD_SSP(2) |
1110 					SOF_SSP_BT_OFFLOAD_PRESENT),
1111 	},
1112 	{
1113 		.name = "adl_rt5682",
1114 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1115 					SOF_RT5682_SSP_CODEC(0) |
1116 					SOF_RT5682_NUM_HDMIDEV(4) |
1117 					SOF_BT_OFFLOAD_SSP(2) |
1118 					SOF_SSP_BT_OFFLOAD_PRESENT),
1119 	},
1120 	{
1121 		.name = "adl_rt1019_rt5682",
1122 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1123 					SOF_RT5682_SSP_CODEC(0) |
1124 					SOF_SPEAKER_AMP_PRESENT |
1125 					SOF_RT1019_SPEAKER_AMP_PRESENT |
1126 					SOF_RT5682_SSP_AMP(1) |
1127 					SOF_RT5682_NUM_HDMIDEV(4) |
1128 					SOF_BT_OFFLOAD_SSP(2) |
1129 					SOF_SSP_BT_OFFLOAD_PRESENT),
1130 	},
1131 	{
1132 		.name = "rpl_mx98360_rt5682",
1133 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1134 					SOF_RT5682_SSP_CODEC(0) |
1135 					SOF_SPEAKER_AMP_PRESENT |
1136 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1137 					SOF_RT5682_SSP_AMP(1) |
1138 					SOF_RT5682_NUM_HDMIDEV(4) |
1139 					SOF_BT_OFFLOAD_SSP(2) |
1140 					SOF_SSP_BT_OFFLOAD_PRESENT),
1141 	},
1142 	{
1143 		.name = "rpl_rt1019_rt5682",
1144 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1145 					SOF_RT5682_SSP_CODEC(0) |
1146 					SOF_SPEAKER_AMP_PRESENT |
1147 					SOF_RT1019_SPEAKER_AMP_PRESENT |
1148 					SOF_RT5682_SSP_AMP(1) |
1149 					SOF_RT5682_NUM_HDMIDEV(4) |
1150 					SOF_BT_OFFLOAD_SSP(2) |
1151 					SOF_SSP_BT_OFFLOAD_PRESENT),
1152 	},
1153 	{
1154 		.name = "mtl_mx98357_rt5682",
1155 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1156 					SOF_RT5682_SSP_CODEC(0) |
1157 					SOF_SPEAKER_AMP_PRESENT |
1158 					SOF_RT5682_SSP_AMP(1) |
1159 					SOF_RT5682_NUM_HDMIDEV(4) |
1160 					SOF_BT_OFFLOAD_SSP(2) |
1161 					SOF_SSP_BT_OFFLOAD_PRESENT),
1162 	},
1163 	{
1164 		.name = "mtl_mx98360_rt5682",
1165 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1166 					SOF_RT5682_SSP_CODEC(0) |
1167 					SOF_SPEAKER_AMP_PRESENT |
1168 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1169 					SOF_RT5682_SSP_AMP(1) |
1170 					SOF_RT5682_NUM_HDMIDEV(4)),
1171 	},
1172 	{
1173 		.name = "mtl_rt1019_rt5682",
1174 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1175 					SOF_RT5682_SSP_CODEC(2) |
1176 					SOF_SPEAKER_AMP_PRESENT |
1177 					SOF_RT1019_SPEAKER_AMP_PRESENT |
1178 					SOF_RT5682_SSP_AMP(0) |
1179 					SOF_RT5682_NUM_HDMIDEV(3)),
1180 	},
1181 	{ }
1182 };
1183 MODULE_DEVICE_TABLE(platform, board_ids);
1184 
1185 static struct platform_driver sof_audio = {
1186 	.probe = sof_audio_probe,
1187 	.driver = {
1188 		.name = "sof_rt5682",
1189 		.pm = &snd_soc_pm_ops,
1190 	},
1191 	.id_table = board_ids,
1192 };
1193 module_platform_driver(sof_audio)
1194 
1195 /* Module information */
1196 MODULE_DESCRIPTION("SOF Audio Machine driver");
1197 MODULE_AUTHOR("Bard Liao <bard.liao@intel.com>");
1198 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
1199 MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
1200 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
1201 MODULE_LICENSE("GPL v2");
1202 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
1203 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
1204 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);
1205