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