xref: /linux/sound/soc/intel/boards/sof_rt5682.c (revision 340d79a14d6ab5066ba40651764db20bd151aea7)
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/rt5645.h"
26 #include "../../codecs/hdac_hdmi.h"
27 #include "../common/soc-intel-quirks.h"
28 #include "hda_dsp_common.h"
29 #include "sof_maxim_common.h"
30 #include "sof_realtek_common.h"
31 #include "sof_ssp_common.h"
32 
33 #define NAME_SIZE 32
34 
35 #define SOF_RT5682_SSP_CODEC(quirk)		((quirk) & GENMASK(2, 0))
36 #define SOF_RT5682_SSP_CODEC_MASK			(GENMASK(2, 0))
37 #define SOF_RT5682_MCLK_EN			BIT(3)
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 
48 /* BT audio offload: reserve 3 bits for future */
49 #define SOF_BT_OFFLOAD_SSP_SHIFT		19
50 #define SOF_BT_OFFLOAD_SSP_MASK		(GENMASK(21, 19))
51 #define SOF_BT_OFFLOAD_SSP(quirk)	\
52 	(((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
53 #define SOF_SSP_BT_OFFLOAD_PRESENT		BIT(22)
54 
55 /* HDMI capture*/
56 #define SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT  27
57 #define SOF_SSP_HDMI_CAPTURE_PRESENT_MASK (GENMASK(30, 27))
58 #define SOF_HDMI_CAPTURE_SSP_MASK(quirk)   \
59 	(((quirk) << SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT) & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK)
60 
61 /* Default: MCLK on, MCLK 19.2M, SSP0  */
62 static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
63 					SOF_RT5682_SSP_CODEC(0);
64 
65 static int is_legacy_cpu;
66 
67 struct sof_hdmi_pcm {
68 	struct list_head head;
69 	struct snd_soc_dai *codec_dai;
70 	struct snd_soc_jack hdmi_jack;
71 	int device;
72 };
73 
74 struct sof_card_private {
75 	struct clk *mclk;
76 	struct snd_soc_jack sof_headset;
77 	struct list_head hdmi_pcm_list;
78 	bool common_hdmi_codec_drv;
79 	bool idisp_codec;
80 	enum sof_ssp_codec codec_type;
81 	enum sof_ssp_codec amp_type;
82 };
83 
84 static int sof_rt5682_quirk_cb(const struct dmi_system_id *id)
85 {
86 	sof_rt5682_quirk = (unsigned long)id->driver_data;
87 	return 1;
88 }
89 
90 static const struct dmi_system_id sof_rt5682_quirk_table[] = {
91 	{
92 		.callback = sof_rt5682_quirk_cb,
93 		.matches = {
94 			DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
95 			DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max"),
96 		},
97 		.driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
98 	},
99 	{
100 		.callback = sof_rt5682_quirk_cb,
101 		.matches = {
102 			DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
103 			DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
104 		},
105 		.driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
106 	},
107 	{
108 		.callback = sof_rt5682_quirk_cb,
109 		.matches = {
110 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
111 			DMI_MATCH(DMI_PRODUCT_NAME, "WhiskeyLake Client"),
112 		},
113 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
114 					SOF_RT5682_SSP_CODEC(1)),
115 	},
116 	{
117 		.callback = sof_rt5682_quirk_cb,
118 		.matches = {
119 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Hatch"),
120 		},
121 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
122 					SOF_RT5682_SSP_CODEC(0) |
123 					SOF_RT5682_SSP_AMP(1)),
124 	},
125 	{
126 		.callback = sof_rt5682_quirk_cb,
127 		.matches = {
128 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
129 			DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"),
130 		},
131 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
132 					SOF_RT5682_SSP_CODEC(0)),
133 	},
134 	{
135 		.callback = sof_rt5682_quirk_cb,
136 		.matches = {
137 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
138 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
139 		},
140 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
141 					SOF_RT5682_SSP_CODEC(0) |
142 					SOF_RT5682_SSP_AMP(2) |
143 					SOF_RT5682_NUM_HDMIDEV(4)),
144 	},
145 	{
146 		.callback = sof_rt5682_quirk_cb,
147 		.matches = {
148 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
149 			DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
150 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
151 		},
152 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
153 					SOF_RT5682_SSP_CODEC(0) |
154 					SOF_RT5682_SSP_AMP(2) |
155 					SOF_RT5682_NUM_HDMIDEV(4)),
156 	},
157 	{
158 		.callback = sof_rt5682_quirk_cb,
159 		.matches = {
160 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
161 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
162 		},
163 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
164 					SOF_RT5682_SSP_CODEC(0) |
165 					SOF_RT5682_SSP_AMP(2) |
166 					SOF_RT5682_NUM_HDMIDEV(4)),
167 	},
168 	{
169 		.callback = sof_rt5682_quirk_cb,
170 		.matches = {
171 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
172 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
173 		},
174 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
175 					SOF_RT5682_SSP_CODEC(0) |
176 					SOF_RT5682_SSP_AMP(2) |
177 					SOF_RT5682_NUM_HDMIDEV(4)),
178 	},
179 	{
180 		.callback = sof_rt5682_quirk_cb,
181 		.matches = {
182 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
183 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S"),
184 		},
185 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
186 					SOF_RT5682_SSP_CODEC(2) |
187 					SOF_RT5682_SSP_AMP(0) |
188 					SOF_RT5682_NUM_HDMIDEV(3) |
189 					SOF_BT_OFFLOAD_SSP(1) |
190 					SOF_SSP_BT_OFFLOAD_PRESENT
191 					),
192 	},
193 	{
194 		.callback = sof_rt5682_quirk_cb,
195 		.matches = {
196 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
197 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_DISCRETE_I2S_BT"),
198 		},
199 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
200 					SOF_RT5682_SSP_CODEC(2) |
201 					SOF_RT5682_SSP_AMP(0) |
202 					SOF_RT5682_NUM_HDMIDEV(3) |
203 					SOF_BT_OFFLOAD_SSP(1) |
204 					SOF_SSP_BT_OFFLOAD_PRESENT
205 					),
206 	},
207 	{
208 		.callback = sof_rt5682_quirk_cb,
209 		.matches = {
210 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
211 			DMI_MATCH(DMI_OEM_STRING, "AUDIO-ALC1019_ALC5682I_I2S"),
212 		},
213 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
214 					SOF_RT5682_SSP_CODEC(2) |
215 					SOF_RT5682_SSP_AMP(0) |
216 					SOF_RT5682_NUM_HDMIDEV(3)
217 					),
218 	},
219 	{
220 		.callback = sof_rt5682_quirk_cb,
221 		.matches = {
222 			DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
223 		},
224 		.driver_data = (void *)(SOF_RT5682_MCLK_EN |
225 					SOF_RT5682_SSP_CODEC(2) |
226 					SOF_RT5682_SSP_AMP(0) |
227 					SOF_RT5682_NUM_HDMIDEV(3) |
228 					SOF_BT_OFFLOAD_SSP(1) |
229 					SOF_SSP_BT_OFFLOAD_PRESENT
230 					),
231 	},
232 	{}
233 };
234 
235 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
236 {
237 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
238 	struct snd_soc_dai *dai = snd_soc_rtd_to_codec(rtd, 0);
239 	struct sof_hdmi_pcm *pcm;
240 
241 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
242 	if (!pcm)
243 		return -ENOMEM;
244 
245 	/* dai_link id is 1:1 mapped to the PCM device */
246 	pcm->device = rtd->dai_link->id;
247 	pcm->codec_dai = dai;
248 
249 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
250 
251 	return 0;
252 }
253 
254 static struct snd_soc_jack_pin jack_pins[] = {
255 	{
256 		.pin    = "Headphone Jack",
257 		.mask   = SND_JACK_HEADPHONE,
258 	},
259 	{
260 		.pin    = "Headset Mic",
261 		.mask   = SND_JACK_MICROPHONE,
262 	},
263 };
264 
265 static int sof_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
266 {
267 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
268 	struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
269 	struct snd_soc_jack *jack;
270 	int extra_jack_data;
271 	int ret, mclk_freq;
272 
273 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_EN) {
274 		mclk_freq = sof_dai_get_mclk(rtd);
275 		if (mclk_freq <= 0) {
276 			dev_err(rtd->dev, "invalid mclk freq %d\n", mclk_freq);
277 			return -EINVAL;
278 		}
279 
280 		/* need to enable ASRC function for 24MHz mclk rate */
281 		if (mclk_freq == 24000000) {
282 			dev_info(rtd->dev, "enable ASRC\n");
283 
284 			switch (ctx->codec_type) {
285 			case CODEC_RT5650:
286 				rt5645_sel_asrc_clk_src(component,
287 							RT5645_DA_STEREO_FILTER |
288 							RT5645_AD_STEREO_FILTER,
289 							RT5645_CLK_SEL_I2S1_ASRC);
290 				rt5645_sel_asrc_clk_src(component,
291 							RT5645_DA_MONO_L_FILTER |
292 							RT5645_DA_MONO_R_FILTER,
293 							RT5645_CLK_SEL_I2S2_ASRC);
294 				break;
295 			case CODEC_RT5682:
296 				rt5682_sel_asrc_clk_src(component,
297 							RT5682_DA_STEREO1_FILTER |
298 							RT5682_AD_STEREO1_FILTER,
299 							RT5682_CLK_SEL_I2S1_ASRC);
300 				break;
301 			case CODEC_RT5682S:
302 				rt5682s_sel_asrc_clk_src(component,
303 							 RT5682S_DA_STEREO1_FILTER |
304 							 RT5682S_AD_STEREO1_FILTER,
305 							 RT5682S_CLK_SEL_I2S1_ASRC);
306 				break;
307 			default:
308 				dev_err(rtd->dev, "invalid codec type %d\n",
309 					ctx->codec_type);
310 				return -EINVAL;
311 			}
312 		}
313 
314 		if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
315 			/*
316 			 * The firmware might enable the clock at
317 			 * boot (this information may or may not
318 			 * be reflected in the enable clock register).
319 			 * To change the rate we must disable the clock
320 			 * first to cover these cases. Due to common
321 			 * clock framework restrictions that do not allow
322 			 * to disable a clock that has not been enabled,
323 			 * we need to enable the clock first.
324 			 */
325 			ret = clk_prepare_enable(ctx->mclk);
326 			if (!ret)
327 				clk_disable_unprepare(ctx->mclk);
328 
329 			ret = clk_set_rate(ctx->mclk, 19200000);
330 
331 			if (ret)
332 				dev_err(rtd->dev, "unable to set MCLK rate\n");
333 		}
334 	}
335 
336 	/*
337 	 * Headset buttons map to the google Reference headset.
338 	 * These can be configured by userspace.
339 	 */
340 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
341 					 SND_JACK_HEADSET | SND_JACK_BTN_0 |
342 					 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
343 					 SND_JACK_BTN_3,
344 					 &ctx->sof_headset,
345 					 jack_pins,
346 					 ARRAY_SIZE(jack_pins));
347 	if (ret) {
348 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
349 		return ret;
350 	}
351 
352 	jack = &ctx->sof_headset;
353 
354 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
355 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
356 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
357 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
358 
359 	if (ctx->codec_type == CODEC_RT5650) {
360 		extra_jack_data = SND_JACK_MICROPHONE | SND_JACK_BTN_0;
361 		ret = snd_soc_component_set_jack(component, jack, &extra_jack_data);
362 	} else
363 		ret = snd_soc_component_set_jack(component, jack, NULL);
364 
365 	if (ret) {
366 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
367 		return ret;
368 	}
369 
370 	return ret;
371 };
372 
373 static void sof_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
374 {
375 	struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
376 
377 	snd_soc_component_set_jack(component, NULL, NULL);
378 }
379 
380 static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
381 				struct snd_pcm_hw_params *params)
382 {
383 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
384 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
385 	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
386 	int pll_id, pll_source, pll_in, pll_out, clk_id, ret;
387 
388 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_EN) {
389 		if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
390 			ret = clk_prepare_enable(ctx->mclk);
391 			if (ret < 0) {
392 				dev_err(rtd->dev,
393 					"could not configure MCLK state");
394 				return ret;
395 			}
396 		}
397 
398 		switch (ctx->codec_type) {
399 		case CODEC_RT5650:
400 			pll_source = RT5645_PLL1_S_MCLK;
401 			break;
402 		case CODEC_RT5682:
403 			pll_source = RT5682_PLL1_S_MCLK;
404 			break;
405 		case CODEC_RT5682S:
406 			pll_source = RT5682S_PLL_S_MCLK;
407 			break;
408 		default:
409 			dev_err(rtd->dev, "invalid codec type %d\n",
410 				ctx->codec_type);
411 			return -EINVAL;
412 		}
413 
414 		/* get the tplg configured mclk. */
415 		pll_in = sof_dai_get_mclk(rtd);
416 		if (pll_in <= 0) {
417 			dev_err(rtd->dev, "invalid mclk freq %d\n", pll_in);
418 			return -EINVAL;
419 		}
420 	} else {
421 		switch (ctx->codec_type) {
422 		case CODEC_RT5650:
423 			pll_source = RT5645_PLL1_S_BCLK1;
424 			break;
425 		case CODEC_RT5682:
426 			pll_source = RT5682_PLL1_S_BCLK1;
427 			break;
428 		case CODEC_RT5682S:
429 			pll_source = RT5682S_PLL_S_BCLK1;
430 			break;
431 		default:
432 			dev_err(rtd->dev, "invalid codec type %d\n",
433 				ctx->codec_type);
434 			return -EINVAL;
435 		}
436 
437 		pll_in = params_rate(params) * 50;
438 	}
439 
440 	switch (ctx->codec_type) {
441 	case CODEC_RT5650:
442 		pll_id = 0; /* not used in codec driver */
443 		clk_id = RT5645_SCLK_S_PLL1;
444 		break;
445 	case CODEC_RT5682:
446 		pll_id = RT5682_PLL1;
447 		clk_id = RT5682_SCLK_S_PLL1;
448 		break;
449 	case CODEC_RT5682S:
450 		pll_id = RT5682S_PLL2;
451 		clk_id = RT5682S_SCLK_S_PLL2;
452 		break;
453 	default:
454 		dev_err(rtd->dev, "invalid codec type %d\n", ctx->codec_type);
455 		return -EINVAL;
456 	}
457 
458 	pll_out = params_rate(params) * 512;
459 
460 	/* when MCLK is 512FS, no need to set PLL configuration additionally. */
461 	if (pll_in == pll_out) {
462 		switch (ctx->codec_type) {
463 		case CODEC_RT5650:
464 			clk_id = RT5645_SCLK_S_MCLK;
465 			break;
466 		case CODEC_RT5682:
467 			clk_id = RT5682_SCLK_S_MCLK;
468 			break;
469 		case CODEC_RT5682S:
470 			clk_id = RT5682S_SCLK_S_MCLK;
471 			break;
472 		default:
473 			dev_err(rtd->dev, "invalid codec type %d\n",
474 				ctx->codec_type);
475 			return -EINVAL;
476 		}
477 	} else {
478 		/* Configure pll for codec */
479 		ret = snd_soc_dai_set_pll(codec_dai, pll_id, pll_source, pll_in,
480 					  pll_out);
481 		if (ret < 0)
482 			dev_err(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
483 	}
484 
485 	/* Configure sysclk for codec */
486 	ret = snd_soc_dai_set_sysclk(codec_dai, clk_id,
487 				     pll_out, SND_SOC_CLOCK_IN);
488 	if (ret < 0)
489 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
490 
491 	/*
492 	 * slot_width should equal or large than data length, set them
493 	 * be the same
494 	 */
495 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
496 				       params_width(params));
497 	if (ret < 0) {
498 		dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
499 		return ret;
500 	}
501 
502 	return ret;
503 }
504 
505 static struct snd_soc_ops sof_rt5682_ops = {
506 	.hw_params = sof_rt5682_hw_params,
507 };
508 
509 static struct snd_soc_dai_link_component platform_component[] = {
510 	{
511 		/* name might be overridden during probe */
512 		.name = "0000:00:1f.3"
513 	}
514 };
515 
516 static int sof_card_late_probe(struct snd_soc_card *card)
517 {
518 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
519 	struct snd_soc_component *component = NULL;
520 	struct snd_soc_dapm_context *dapm = &card->dapm;
521 	char jack_name[NAME_SIZE];
522 	struct sof_hdmi_pcm *pcm;
523 	int err;
524 
525 	if (ctx->amp_type == CODEC_MAX98373) {
526 		/* Disable Left and Right Spk pin after boot */
527 		snd_soc_dapm_disable_pin(dapm, "Left Spk");
528 		snd_soc_dapm_disable_pin(dapm, "Right Spk");
529 		err = snd_soc_dapm_sync(dapm);
530 		if (err < 0)
531 			return err;
532 	}
533 
534 	/* HDMI is not supported by SOF on Baytrail/CherryTrail */
535 	if (is_legacy_cpu || !ctx->idisp_codec)
536 		return 0;
537 
538 	if (list_empty(&ctx->hdmi_pcm_list))
539 		return -EINVAL;
540 
541 	if (ctx->common_hdmi_codec_drv) {
542 		pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
543 				       head);
544 		component = pcm->codec_dai->component;
545 		return hda_dsp_hdmi_build_controls(card, component);
546 	}
547 
548 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
549 		component = pcm->codec_dai->component;
550 		snprintf(jack_name, sizeof(jack_name),
551 			 "HDMI/DP, pcm=%d Jack", pcm->device);
552 		err = snd_soc_card_jack_new(card, jack_name,
553 					    SND_JACK_AVOUT, &pcm->hdmi_jack);
554 
555 		if (err)
556 			return err;
557 
558 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
559 					  &pcm->hdmi_jack);
560 		if (err < 0)
561 			return err;
562 	}
563 
564 	return hdac_hdmi_jack_port_init(component, &card->dapm);
565 }
566 
567 static const struct snd_kcontrol_new sof_controls[] = {
568 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
569 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
570 	SOC_DAPM_PIN_SWITCH("Left Spk"),
571 	SOC_DAPM_PIN_SWITCH("Right Spk"),
572 
573 };
574 
575 static const struct snd_soc_dapm_widget sof_widgets[] = {
576 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
577 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
578 	SND_SOC_DAPM_SPK("Left Spk", NULL),
579 	SND_SOC_DAPM_SPK("Right Spk", NULL),
580 };
581 
582 static const struct snd_soc_dapm_widget dmic_widgets[] = {
583 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
584 };
585 
586 static const struct snd_soc_dapm_route sof_map[] = {
587 	/* HP jack connectors - unknown if we have jack detection */
588 	{ "Headphone Jack", NULL, "HPOL" },
589 	{ "Headphone Jack", NULL, "HPOR" },
590 
591 	/* other jacks */
592 	{ "IN1P", NULL, "Headset Mic" },
593 };
594 
595 static const struct snd_soc_dapm_route rt5650_spk_dapm_routes[] = {
596 	/* speaker */
597 	{ "Left Spk", NULL, "SPOL" },
598 	{ "Right Spk", NULL, "SPOR" },
599 };
600 
601 static const struct snd_soc_dapm_route dmic_map[] = {
602 	/* digital mics */
603 	{"DMic", NULL, "SoC DMIC"},
604 };
605 
606 static int rt5650_spk_init(struct snd_soc_pcm_runtime *rtd)
607 {
608 	struct snd_soc_card *card = rtd->card;
609 	int ret;
610 
611 	ret = snd_soc_dapm_add_routes(&card->dapm, rt5650_spk_dapm_routes,
612 				      ARRAY_SIZE(rt5650_spk_dapm_routes));
613 	if (ret)
614 		dev_err(rtd->dev, "fail to add dapm routes, ret=%d\n", ret);
615 
616 	return ret;
617 }
618 
619 static int dmic_init(struct snd_soc_pcm_runtime *rtd)
620 {
621 	struct snd_soc_card *card = rtd->card;
622 	int ret;
623 
624 	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
625 					ARRAY_SIZE(dmic_widgets));
626 	if (ret) {
627 		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
628 		/* Don't need to add routes if widget addition failed */
629 		return ret;
630 	}
631 
632 	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
633 				      ARRAY_SIZE(dmic_map));
634 
635 	if (ret)
636 		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
637 
638 	return ret;
639 }
640 
641 /* sof audio machine driver for rt5682 codec */
642 static struct snd_soc_card sof_audio_card_rt5682 = {
643 	.name = "rt5682", /* the sof- prefix is added by the core */
644 	.owner = THIS_MODULE,
645 	.controls = sof_controls,
646 	.num_controls = ARRAY_SIZE(sof_controls),
647 	.dapm_widgets = sof_widgets,
648 	.num_dapm_widgets = ARRAY_SIZE(sof_widgets),
649 	.dapm_routes = sof_map,
650 	.num_dapm_routes = ARRAY_SIZE(sof_map),
651 	.fully_routed = true,
652 	.late_probe = sof_card_late_probe,
653 };
654 
655 static struct snd_soc_dai_link_component rt5682_component[] = {
656 	{
657 		.name = "i2c-10EC5682:00",
658 		.dai_name = "rt5682-aif1",
659 	}
660 };
661 
662 static struct snd_soc_dai_link_component rt5682s_component[] = {
663 	{
664 		.name = "i2c-RTL5682:00",
665 		.dai_name = "rt5682s-aif1",
666 	}
667 };
668 
669 static struct snd_soc_dai_link_component rt5650_components[] = {
670 	{
671 		.name = "i2c-10EC5650:00",
672 		.dai_name = "rt5645-aif1",
673 	},
674 	{
675 		.name = "i2c-10EC5650:00",
676 		.dai_name = "rt5645-aif2",
677 	}
678 };
679 
680 static struct snd_soc_dai_link_component dmic_component[] = {
681 	{
682 		.name = "dmic-codec",
683 		.dai_name = "dmic-hifi",
684 	}
685 };
686 
687 #define IDISP_CODEC_MASK	0x4
688 
689 static struct snd_soc_dai_link *
690 sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec codec_type,
691 			  enum sof_ssp_codec amp_type, int ssp_codec,
692 			  int ssp_amp, int dmic_be_num, int hdmi_num,
693 			  bool idisp_codec)
694 {
695 	struct snd_soc_dai_link_component *idisp_components;
696 	struct snd_soc_dai_link_component *cpus;
697 	struct snd_soc_dai_link *links;
698 	int i, id = 0;
699 	int hdmi_id_offset = 0;
700 
701 	links = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
702 			    sizeof(struct snd_soc_dai_link), GFP_KERNEL);
703 	cpus = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
704 			    sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
705 	if (!links || !cpus)
706 		goto devm_err;
707 
708 	/* codec SSP */
709 	links[id].name = devm_kasprintf(dev, GFP_KERNEL,
710 					"SSP%d-Codec", ssp_codec);
711 	if (!links[id].name)
712 		goto devm_err;
713 
714 	links[id].id = id;
715 
716 	switch (codec_type) {
717 	case CODEC_RT5650:
718 		links[id].codecs = &rt5650_components[0];
719 		links[id].num_codecs = 1;
720 		break;
721 	case CODEC_RT5682:
722 		links[id].codecs = rt5682_component;
723 		links[id].num_codecs = ARRAY_SIZE(rt5682_component);
724 		break;
725 	case CODEC_RT5682S:
726 		links[id].codecs = rt5682s_component;
727 		links[id].num_codecs = ARRAY_SIZE(rt5682s_component);
728 		break;
729 	default:
730 		dev_err(dev, "invalid codec type %d\n", codec_type);
731 		return NULL;
732 	}
733 
734 	links[id].platforms = platform_component;
735 	links[id].num_platforms = ARRAY_SIZE(platform_component);
736 	links[id].init = sof_rt5682_codec_init;
737 	links[id].exit = sof_rt5682_codec_exit;
738 	links[id].ops = &sof_rt5682_ops;
739 	links[id].dpcm_playback = 1;
740 	links[id].dpcm_capture = 1;
741 	links[id].no_pcm = 1;
742 	links[id].cpus = &cpus[id];
743 	links[id].num_cpus = 1;
744 	if (is_legacy_cpu) {
745 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
746 							  "ssp%d-port",
747 							  ssp_codec);
748 		if (!links[id].cpus->dai_name)
749 			goto devm_err;
750 	} else {
751 		/*
752 		 * Currently, On SKL+ platforms MCLK will be turned off in sof
753 		 * runtime suspended, and it will go into runtime suspended
754 		 * right after playback is stop. However, rt5682 will output
755 		 * static noise if sysclk turns off during playback. Set
756 		 * ignore_pmdown_time to power down rt5682 immediately and
757 		 * avoid the noise.
758 		 * It can be removed once we can control MCLK by driver.
759 		 */
760 		links[id].ignore_pmdown_time = 1;
761 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
762 							  "SSP%d Pin",
763 							  ssp_codec);
764 		if (!links[id].cpus->dai_name)
765 			goto devm_err;
766 	}
767 	id++;
768 
769 	/* dmic */
770 	if (dmic_be_num > 0) {
771 		/* at least we have dmic01 */
772 		links[id].name = "dmic01";
773 		links[id].cpus = &cpus[id];
774 		links[id].cpus->dai_name = "DMIC01 Pin";
775 		links[id].init = dmic_init;
776 		if (dmic_be_num > 1) {
777 			/* set up 2 BE links at most */
778 			links[id + 1].name = "dmic16k";
779 			links[id + 1].cpus = &cpus[id + 1];
780 			links[id + 1].cpus->dai_name = "DMIC16k Pin";
781 			dmic_be_num = 2;
782 		}
783 	}
784 
785 	for (i = 0; i < dmic_be_num; i++) {
786 		links[id].id = id;
787 		links[id].num_cpus = 1;
788 		links[id].codecs = dmic_component;
789 		links[id].num_codecs = ARRAY_SIZE(dmic_component);
790 		links[id].platforms = platform_component;
791 		links[id].num_platforms = ARRAY_SIZE(platform_component);
792 		links[id].ignore_suspend = 1;
793 		links[id].dpcm_capture = 1;
794 		links[id].no_pcm = 1;
795 		id++;
796 	}
797 
798 	/* HDMI */
799 	if (hdmi_num > 0) {
800 		idisp_components = devm_kcalloc(dev,
801 				   hdmi_num,
802 				   sizeof(struct snd_soc_dai_link_component),
803 				   GFP_KERNEL);
804 		if (!idisp_components)
805 			goto devm_err;
806 	}
807 	for (i = 1; i <= hdmi_num; i++) {
808 		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
809 						"iDisp%d", i);
810 		if (!links[id].name)
811 			goto devm_err;
812 
813 		links[id].id = id;
814 		links[id].cpus = &cpus[id];
815 		links[id].num_cpus = 1;
816 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
817 							  "iDisp%d Pin", i);
818 		if (!links[id].cpus->dai_name)
819 			goto devm_err;
820 
821 		if (idisp_codec) {
822 			idisp_components[i - 1].name = "ehdaudio0D2";
823 			idisp_components[i - 1].dai_name = devm_kasprintf(dev,
824 									  GFP_KERNEL,
825 									  "intel-hdmi-hifi%d",
826 									  i);
827 			if (!idisp_components[i - 1].dai_name)
828 				goto devm_err;
829 		} else {
830 			idisp_components[i - 1] = snd_soc_dummy_dlc;
831 		}
832 
833 		links[id].codecs = &idisp_components[i - 1];
834 		links[id].num_codecs = 1;
835 		links[id].platforms = platform_component;
836 		links[id].num_platforms = ARRAY_SIZE(platform_component);
837 		links[id].init = sof_hdmi_init;
838 		links[id].dpcm_playback = 1;
839 		links[id].no_pcm = 1;
840 		id++;
841 	}
842 
843 	/* speaker amp */
844 	if (amp_type != CODEC_NONE) {
845 		links[id].name = devm_kasprintf(dev, GFP_KERNEL,
846 						"SSP%d-Codec", ssp_amp);
847 		if (!links[id].name)
848 			goto devm_err;
849 
850 		links[id].id = id;
851 
852 		switch (amp_type) {
853 		case CODEC_MAX98357A:
854 			max_98357a_dai_link(&links[id]);
855 			break;
856 		case CODEC_MAX98360A:
857 			max_98360a_dai_link(&links[id]);
858 			break;
859 		case CODEC_MAX98373:
860 			links[id].codecs = max_98373_components;
861 			links[id].num_codecs = ARRAY_SIZE(max_98373_components);
862 			links[id].init = max_98373_spk_codec_init;
863 			links[id].ops = &max_98373_ops;
864 			break;
865 		case CODEC_MAX98390:
866 			max_98390_dai_link(dev, &links[id]);
867 			break;
868 		case CODEC_RT1011:
869 			sof_rt1011_dai_link(&links[id]);
870 			break;
871 		case CODEC_RT1015:
872 			sof_rt1015_dai_link(&links[id]);
873 			break;
874 		case CODEC_RT1015P:
875 			sof_rt1015p_dai_link(&links[id]);
876 			break;
877 		case CODEC_RT1019P:
878 			sof_rt1019p_dai_link(&links[id]);
879 			break;
880 		case CODEC_RT5650:
881 			/* use AIF2 to support speaker pipeline */
882 			links[id].codecs = &rt5650_components[1];
883 			links[id].num_codecs = 1;
884 			links[id].init = rt5650_spk_init;
885 			links[id].ops = &sof_rt5682_ops;
886 			break;
887 		default:
888 			dev_err(dev, "invalid amp type %d\n", amp_type);
889 			return NULL;
890 		}
891 
892 		links[id].platforms = platform_component;
893 		links[id].num_platforms = ARRAY_SIZE(platform_component);
894 		links[id].dpcm_playback = 1;
895 		/* feedback stream or firmware-generated echo reference */
896 		links[id].dpcm_capture = 1;
897 
898 		links[id].no_pcm = 1;
899 		links[id].cpus = &cpus[id];
900 		links[id].num_cpus = 1;
901 		if (is_legacy_cpu) {
902 			links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
903 								  "ssp%d-port",
904 								  ssp_amp);
905 			if (!links[id].cpus->dai_name)
906 				goto devm_err;
907 
908 		} else {
909 			links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
910 								  "SSP%d Pin",
911 								  ssp_amp);
912 			if (!links[id].cpus->dai_name)
913 				goto devm_err;
914 		}
915 		id++;
916 	}
917 
918 	/* BT audio offload */
919 	if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
920 		int port = (sof_rt5682_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
921 				SOF_BT_OFFLOAD_SSP_SHIFT;
922 
923 		links[id].id = id;
924 		links[id].cpus = &cpus[id];
925 		links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
926 							  "SSP%d Pin", port);
927 		if (!links[id].cpus->dai_name)
928 			goto devm_err;
929 		links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
930 		if (!links[id].name)
931 			goto devm_err;
932 		links[id].codecs = &snd_soc_dummy_dlc;
933 		links[id].num_codecs = 1;
934 		links[id].platforms = platform_component;
935 		links[id].num_platforms = ARRAY_SIZE(platform_component);
936 		links[id].dpcm_playback = 1;
937 		links[id].dpcm_capture = 1;
938 		links[id].no_pcm = 1;
939 		links[id].num_cpus = 1;
940 	}
941 
942 	/* HDMI-In SSP */
943 	if (sof_rt5682_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK) {
944 		unsigned long hdmi_in_ssp = (sof_rt5682_quirk &
945 				SOF_SSP_HDMI_CAPTURE_PRESENT_MASK) >>
946 				SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT;
947 		int port = 0;
948 
949 		for_each_set_bit(port, &hdmi_in_ssp, 32) {
950 			links[id].cpus = &cpus[id];
951 			links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
952 								  "SSP%d Pin", port);
953 			if (!links[id].cpus->dai_name)
954 				return NULL;
955 			links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-HDMI", port);
956 			if (!links[id].name)
957 				return NULL;
958 			links[id].id = id + hdmi_id_offset;
959 			links[id].codecs = &snd_soc_dummy_dlc;
960 			links[id].num_codecs = 1;
961 			links[id].platforms = platform_component;
962 			links[id].num_platforms = ARRAY_SIZE(platform_component);
963 			links[id].dpcm_capture = 1;
964 			links[id].no_pcm = 1;
965 			links[id].num_cpus = 1;
966 			id++;
967 		}
968 	}
969 
970 	return links;
971 devm_err:
972 	return NULL;
973 }
974 
975 static int sof_audio_probe(struct platform_device *pdev)
976 {
977 	struct snd_soc_dai_link *dai_links;
978 	struct snd_soc_acpi_mach *mach;
979 	struct sof_card_private *ctx;
980 	int dmic_be_num, hdmi_num;
981 	int ret, ssp_amp, ssp_codec;
982 
983 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
984 	if (!ctx)
985 		return -ENOMEM;
986 
987 	if (pdev->id_entry && pdev->id_entry->driver_data)
988 		sof_rt5682_quirk = (unsigned long)pdev->id_entry->driver_data;
989 
990 	dmi_check_system(sof_rt5682_quirk_table);
991 
992 	mach = pdev->dev.platform_data;
993 
994 	ctx->codec_type = sof_ssp_detect_codec_type(&pdev->dev);
995 	ctx->amp_type = sof_ssp_detect_amp_type(&pdev->dev);
996 
997 	if (ctx->codec_type == CODEC_RT5650) {
998 		sof_audio_card_rt5682.name = devm_kstrdup(&pdev->dev, "rt5650",
999 							  GFP_KERNEL);
1000 
1001 		/* create speaker dai link also */
1002 		if (ctx->amp_type == CODEC_NONE)
1003 			ctx->amp_type = CODEC_RT5650;
1004 	}
1005 
1006 	if (soc_intel_is_byt() || soc_intel_is_cht()) {
1007 		is_legacy_cpu = 1;
1008 		dmic_be_num = 0;
1009 		hdmi_num = 0;
1010 		/* default quirk for legacy cpu */
1011 		sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
1012 						SOF_RT5682_MCLK_BYTCHT_EN |
1013 						SOF_RT5682_SSP_CODEC(2);
1014 	} else {
1015 		dmic_be_num = 2;
1016 		hdmi_num = (sof_rt5682_quirk & SOF_RT5682_NUM_HDMIDEV_MASK) >>
1017 			 SOF_RT5682_NUM_HDMIDEV_SHIFT;
1018 		/* default number of HDMI DAI's */
1019 		if (!hdmi_num)
1020 			hdmi_num = 3;
1021 
1022 		if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
1023 			ctx->idisp_codec = true;
1024 	}
1025 
1026 	/* need to get main clock from pmc */
1027 	if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
1028 		ctx->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1029 		if (IS_ERR(ctx->mclk)) {
1030 			ret = PTR_ERR(ctx->mclk);
1031 
1032 			dev_err(&pdev->dev,
1033 				"Failed to get MCLK from pmc_plt_clk_3: %d\n",
1034 				ret);
1035 			return ret;
1036 		}
1037 
1038 		ret = clk_prepare_enable(ctx->mclk);
1039 		if (ret < 0) {
1040 			dev_err(&pdev->dev,
1041 				"could not configure MCLK state");
1042 			return ret;
1043 		}
1044 	}
1045 
1046 	dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk);
1047 
1048 	ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
1049 			SOF_RT5682_SSP_AMP_SHIFT;
1050 
1051 	ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;
1052 
1053 	/* compute number of dai links */
1054 	sof_audio_card_rt5682.num_links = 1 + dmic_be_num + hdmi_num;
1055 
1056 	if (ctx->amp_type != CODEC_NONE)
1057 		sof_audio_card_rt5682.num_links++;
1058 
1059 	if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
1060 		sof_audio_card_rt5682.num_links++;
1061 
1062 	if (sof_rt5682_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK)
1063 		sof_audio_card_rt5682.num_links +=
1064 			hweight32((sof_rt5682_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK) >>
1065 					SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT);
1066 
1067 	dai_links = sof_card_dai_links_create(&pdev->dev, ctx->codec_type,
1068 					      ctx->amp_type, ssp_codec, ssp_amp,
1069 					      dmic_be_num, hdmi_num,
1070 					      ctx->idisp_codec);
1071 	if (!dai_links)
1072 		return -ENOMEM;
1073 
1074 	sof_audio_card_rt5682.dai_link = dai_links;
1075 
1076 	/* update codec_conf */
1077 	switch (ctx->amp_type) {
1078 	case CODEC_MAX98373:
1079 		max_98373_set_codec_conf(&sof_audio_card_rt5682);
1080 		break;
1081 	case CODEC_MAX98390:
1082 		max_98390_set_codec_conf(&pdev->dev, &sof_audio_card_rt5682);
1083 		break;
1084 	case CODEC_RT1011:
1085 		sof_rt1011_codec_conf(&sof_audio_card_rt5682);
1086 		break;
1087 	case CODEC_RT1015:
1088 		sof_rt1015_codec_conf(&sof_audio_card_rt5682);
1089 		break;
1090 	case CODEC_RT1015P:
1091 		sof_rt1015p_codec_conf(&sof_audio_card_rt5682);
1092 		break;
1093 	case CODEC_NONE:
1094 	case CODEC_MAX98357A:
1095 	case CODEC_MAX98360A:
1096 	case CODEC_RT1019P:
1097 	case CODEC_RT5650:
1098 		/* no codec conf required */
1099 		break;
1100 	default:
1101 		dev_err(&pdev->dev, "invalid amp type %d\n", ctx->amp_type);
1102 		return -EINVAL;
1103 	}
1104 
1105 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
1106 
1107 	sof_audio_card_rt5682.dev = &pdev->dev;
1108 
1109 	/* set platform name for each dailink */
1110 	ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_rt5682,
1111 						    mach->mach_params.platform);
1112 	if (ret)
1113 		return ret;
1114 
1115 	ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
1116 
1117 	snd_soc_card_set_drvdata(&sof_audio_card_rt5682, ctx);
1118 
1119 	return devm_snd_soc_register_card(&pdev->dev,
1120 					  &sof_audio_card_rt5682);
1121 }
1122 
1123 static const struct platform_device_id board_ids[] = {
1124 	{
1125 		.name = "sof_rt5682",
1126 	},
1127 	{
1128 		.name = "cml_rt1015_rt5682",
1129 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1130 					SOF_RT5682_SSP_CODEC(0) |
1131 					SOF_RT5682_SSP_AMP(1)),
1132 	},
1133 	{
1134 		.name = "jsl_rt5682_rt1015",
1135 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1136 					SOF_RT5682_SSP_CODEC(0) |
1137 					SOF_RT5682_SSP_AMP(1)),
1138 	},
1139 	{
1140 		.name = "jsl_rt5682_mx98360",
1141 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1142 					SOF_RT5682_SSP_CODEC(0) |
1143 					SOF_RT5682_SSP_AMP(1)),
1144 	},
1145 	{
1146 		.name = "jsl_rt5682_rt1015p",
1147 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1148 					SOF_RT5682_SSP_CODEC(0) |
1149 					SOF_RT5682_SSP_AMP(1)),
1150 	},
1151 	{
1152 		.name = "jsl_rt5682",
1153 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1154 					SOF_RT5682_SSP_CODEC(0)),
1155 	},
1156 	{
1157 		.name = "jsl_rt5650",
1158 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1159 					SOF_RT5682_SSP_CODEC(0) |
1160 					SOF_RT5682_SSP_AMP(1)),
1161 	},
1162 	{
1163 		.name = "tgl_mx98357_rt5682",
1164 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1165 					SOF_RT5682_SSP_CODEC(0) |
1166 					SOF_RT5682_SSP_AMP(1) |
1167 					SOF_RT5682_NUM_HDMIDEV(4) |
1168 					SOF_BT_OFFLOAD_SSP(2) |
1169 					SOF_SSP_BT_OFFLOAD_PRESENT),
1170 	},
1171 	{
1172 		.name = "tgl_rt1011_rt5682",
1173 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1174 					SOF_RT5682_SSP_CODEC(0) |
1175 					SOF_RT5682_SSP_AMP(1) |
1176 					SOF_RT5682_NUM_HDMIDEV(4) |
1177 					SOF_BT_OFFLOAD_SSP(2) |
1178 					SOF_SSP_BT_OFFLOAD_PRESENT),
1179 	},
1180 	{
1181 		.name = "tgl_mx98373_rt5682",
1182 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1183 					SOF_RT5682_SSP_CODEC(0) |
1184 					SOF_RT5682_SSP_AMP(1) |
1185 					SOF_RT5682_NUM_HDMIDEV(4) |
1186 					SOF_BT_OFFLOAD_SSP(2) |
1187 					SOF_SSP_BT_OFFLOAD_PRESENT),
1188 	},
1189 	{
1190 		.name = "adl_mx98373_rt5682",
1191 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1192 					SOF_RT5682_SSP_CODEC(0) |
1193 					SOF_RT5682_SSP_AMP(1) |
1194 					SOF_RT5682_NUM_HDMIDEV(4) |
1195 					SOF_BT_OFFLOAD_SSP(2) |
1196 					SOF_SSP_BT_OFFLOAD_PRESENT),
1197 	},
1198 	{
1199 		.name = "adl_mx98357_rt5682",
1200 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1201 					SOF_RT5682_SSP_CODEC(0) |
1202 					SOF_RT5682_SSP_AMP(2) |
1203 					SOF_RT5682_NUM_HDMIDEV(4)),
1204 	},
1205 	{
1206 		.name = "adl_max98390_rt5682",
1207 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1208 					SOF_RT5682_SSP_CODEC(0) |
1209 					SOF_RT5682_SSP_AMP(1) |
1210 					SOF_RT5682_NUM_HDMIDEV(4) |
1211 					SOF_BT_OFFLOAD_SSP(2) |
1212 					SOF_SSP_BT_OFFLOAD_PRESENT),
1213 	},
1214 	{
1215 		.name = "adl_mx98360_rt5682",
1216 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1217 					SOF_RT5682_SSP_CODEC(0) |
1218 					SOF_RT5682_SSP_AMP(1) |
1219 					SOF_RT5682_NUM_HDMIDEV(4) |
1220 					SOF_BT_OFFLOAD_SSP(2) |
1221 					SOF_SSP_BT_OFFLOAD_PRESENT),
1222 	},
1223 	{
1224 		.name = "adl_rt5682",
1225 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1226 					SOF_RT5682_SSP_CODEC(0) |
1227 					SOF_RT5682_NUM_HDMIDEV(4) |
1228 					SOF_BT_OFFLOAD_SSP(2) |
1229 					SOF_SSP_BT_OFFLOAD_PRESENT),
1230 	},
1231 	{
1232 		.name = "adl_rt1019_rt5682",
1233 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1234 					SOF_RT5682_SSP_CODEC(0) |
1235 					SOF_RT5682_SSP_AMP(1) |
1236 					SOF_RT5682_NUM_HDMIDEV(4) |
1237 					SOF_BT_OFFLOAD_SSP(2) |
1238 					SOF_SSP_BT_OFFLOAD_PRESENT),
1239 	},
1240 	{
1241 		.name = "adl_rt5682_c1_h02",
1242 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1243 					SOF_RT5682_SSP_CODEC(1) |
1244 					SOF_RT5682_NUM_HDMIDEV(3) |
1245 					/* SSP 0 and SSP 2 are used for HDMI IN */
1246 					SOF_HDMI_CAPTURE_SSP_MASK(0x5)),
1247 	},
1248 	{
1249 		.name = "adl_rt5650",
1250 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1251 					SOF_RT5682_SSP_CODEC(0) |
1252 					SOF_RT5682_SSP_AMP(1) |
1253 					SOF_RT5682_NUM_HDMIDEV(4) |
1254 					SOF_BT_OFFLOAD_SSP(2) |
1255 					SOF_SSP_BT_OFFLOAD_PRESENT),
1256 	},
1257 	{
1258 		.name = "rpl_mx98357_rt5682",
1259 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1260 					SOF_RT5682_SSP_CODEC(0) |
1261 					SOF_RT5682_SSP_AMP(2) |
1262 					SOF_RT5682_NUM_HDMIDEV(4)),
1263 	},
1264 	{
1265 		.name = "rpl_mx98360_rt5682",
1266 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1267 					SOF_RT5682_SSP_CODEC(0) |
1268 					SOF_RT5682_SSP_AMP(1) |
1269 					SOF_RT5682_NUM_HDMIDEV(4) |
1270 					SOF_BT_OFFLOAD_SSP(2) |
1271 					SOF_SSP_BT_OFFLOAD_PRESENT),
1272 	},
1273 	{
1274 		.name = "rpl_rt1019_rt5682",
1275 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1276 					SOF_RT5682_SSP_CODEC(0) |
1277 					SOF_RT5682_SSP_AMP(1) |
1278 					SOF_RT5682_NUM_HDMIDEV(4) |
1279 					SOF_BT_OFFLOAD_SSP(2) |
1280 					SOF_SSP_BT_OFFLOAD_PRESENT),
1281 	},
1282 	{
1283 		.name = "rpl_rt5682_c1_h02",
1284 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1285 					SOF_RT5682_SSP_CODEC(1) |
1286 					SOF_RT5682_NUM_HDMIDEV(3) |
1287 					/* SSP 0 and SSP 2 are used for HDMI IN */
1288 					SOF_HDMI_CAPTURE_SSP_MASK(0x5)),
1289 	},
1290 	{
1291 		.name = "mtl_mx98357_rt5682",
1292 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1293 					SOF_RT5682_SSP_CODEC(0) |
1294 					SOF_RT5682_SSP_AMP(1) |
1295 					SOF_RT5682_NUM_HDMIDEV(3) |
1296 					SOF_BT_OFFLOAD_SSP(2) |
1297 					SOF_SSP_BT_OFFLOAD_PRESENT),
1298 	},
1299 	{
1300 		.name = "mtl_mx98360_rt5682",
1301 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1302 					SOF_RT5682_SSP_CODEC(0) |
1303 					SOF_RT5682_SSP_AMP(1) |
1304 					SOF_RT5682_NUM_HDMIDEV(3)),
1305 	},
1306 	{
1307 		.name = "mtl_rt1019_rt5682",
1308 		.driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1309 					SOF_RT5682_SSP_CODEC(2) |
1310 					SOF_RT5682_SSP_AMP(0) |
1311 					SOF_RT5682_NUM_HDMIDEV(3)),
1312 	},
1313 	{ }
1314 };
1315 MODULE_DEVICE_TABLE(platform, board_ids);
1316 
1317 static struct platform_driver sof_audio = {
1318 	.probe = sof_audio_probe,
1319 	.driver = {
1320 		.name = "sof_rt5682",
1321 		.pm = &snd_soc_pm_ops,
1322 	},
1323 	.id_table = board_ids,
1324 };
1325 module_platform_driver(sof_audio)
1326 
1327 /* Module information */
1328 MODULE_DESCRIPTION("SOF Audio Machine driver");
1329 MODULE_AUTHOR("Bard Liao <bard.liao@intel.com>");
1330 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
1331 MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
1332 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
1333 MODULE_LICENSE("GPL v2");
1334 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
1335 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
1336 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);
1337 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_SSP_COMMON);
1338