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