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