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