1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Intel Kabylake I2S Machine Driver with MAXIM98927
4  * RT5514 and RT5663 Codecs
5  *
6  * Copyright (C) 2017, Intel Corporation. All rights reserved.
7  *
8  * Modified from:
9  *   Intel Kabylake I2S Machine driver supporting MAXIM98927 and
10  *   RT5663 codecs
11  */
12 
13 #include <linux/input.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <sound/core.h>
17 #include <sound/jack.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 #include <sound/soc.h>
21 #include <sound/soc-acpi.h>
22 #include "../../codecs/rt5514.h"
23 #include "../../codecs/rt5663.h"
24 #include "../../codecs/hdac_hdmi.h"
25 
26 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
27 #define KBL_REALTEK_DMIC_CODEC_DAI "rt5514-aif1"
28 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
29 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
30 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
31 #define RT5514_DEV_NAME "i2c-10EC5514:00"
32 #define RT5663_DEV_NAME "i2c-10EC5663:00"
33 #define RT5514_AIF1_BCLK_FREQ (48000 * 8 * 16)
34 #define RT5514_AIF1_SYSCLK_FREQ 12288000
35 #define NAME_SIZE 32
36 
37 #define DMIC_CH(p) p->list[p->count-1]
38 
39 
40 static struct snd_soc_card kabylake_audio_card;
41 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
42 
43 struct kbl_hdmi_pcm {
44 	struct list_head head;
45 	struct snd_soc_dai *codec_dai;
46 	int device;
47 };
48 
49 struct kbl_codec_private {
50 	struct snd_soc_jack kabylake_headset;
51 	struct list_head hdmi_pcm_list;
52 	struct snd_soc_jack kabylake_hdmi[2];
53 };
54 
55 enum {
56 	KBL_DPCM_AUDIO_PB = 0,
57 	KBL_DPCM_AUDIO_CP,
58 	KBL_DPCM_AUDIO_HS_PB,
59 	KBL_DPCM_AUDIO_ECHO_REF_CP,
60 	KBL_DPCM_AUDIO_DMIC_CP,
61 	KBL_DPCM_AUDIO_RT5514_DSP,
62 	KBL_DPCM_AUDIO_HDMI1_PB,
63 	KBL_DPCM_AUDIO_HDMI2_PB,
64 };
65 
66 static const struct snd_kcontrol_new kabylake_controls[] = {
67 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
68 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
69 	SOC_DAPM_PIN_SWITCH("Left Spk"),
70 	SOC_DAPM_PIN_SWITCH("Right Spk"),
71 	SOC_DAPM_PIN_SWITCH("DMIC"),
72 };
73 
74 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
75 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
76 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
77 	SND_SOC_DAPM_SPK("Left Spk", NULL),
78 	SND_SOC_DAPM_SPK("Right Spk", NULL),
79 	SND_SOC_DAPM_MIC("DMIC", NULL),
80 	SND_SOC_DAPM_SPK("HDMI1", NULL),
81 	SND_SOC_DAPM_SPK("HDMI2", NULL),
82 
83 };
84 
85 static const struct snd_soc_dapm_route kabylake_map[] = {
86 	/* Headphones */
87 	{ "Headphone Jack", NULL, "HPOL" },
88 	{ "Headphone Jack", NULL, "HPOR" },
89 
90 	/* speaker */
91 	{ "Left Spk", NULL, "Left BE_OUT" },
92 	{ "Right Spk", NULL, "Right BE_OUT" },
93 
94 	/* other jacks */
95 	{ "IN1P", NULL, "Headset Mic" },
96 	{ "IN1N", NULL, "Headset Mic" },
97 
98 	/* CODEC BE connections */
99 	{ "Left HiFi Playback", NULL, "ssp0 Tx" },
100 	{ "Right HiFi Playback", NULL, "ssp0 Tx" },
101 	{ "ssp0 Tx", NULL, "spk_out" },
102 
103 	{ "AIF Playback", NULL, "ssp1 Tx" },
104 	{ "ssp1 Tx", NULL, "codec1_out" },
105 
106 	{ "hs_in", NULL, "ssp1 Rx" },
107 	{ "ssp1 Rx", NULL, "AIF Capture" },
108 
109 	{ "codec1_in", NULL, "ssp0 Rx" },
110 	{ "ssp0 Rx", NULL, "AIF1 Capture" },
111 
112 	/* IV feedback path */
113 	{ "codec0_fb_in", NULL, "ssp0 Rx"},
114 	{ "ssp0 Rx", NULL, "Left HiFi Capture" },
115 	{ "ssp0 Rx", NULL, "Right HiFi Capture" },
116 
117 	/* DMIC */
118 	{ "DMIC1L", NULL, "DMIC" },
119 	{ "DMIC1R", NULL, "DMIC" },
120 	{ "DMIC2L", NULL, "DMIC" },
121 	{ "DMIC2R", NULL, "DMIC" },
122 
123 	{ "hifi2", NULL, "iDisp2 Tx" },
124 	{ "iDisp2 Tx", NULL, "iDisp2_out" },
125 	{ "hifi1", NULL, "iDisp1 Tx" },
126 	{ "iDisp1 Tx", NULL, "iDisp1_out" },
127 };
128 
129 static struct snd_soc_codec_conf max98927_codec_conf[] = {
130 	{
131 		.dev_name = MAXIM_DEV0_NAME,
132 		.name_prefix = "Right",
133 	},
134 	{
135 		.dev_name = MAXIM_DEV1_NAME,
136 		.name_prefix = "Left",
137 	},
138 };
139 
140 
141 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
142 {
143 	struct snd_soc_dapm_context *dapm;
144 	struct snd_soc_component *component = rtd->cpu_dai->component;
145 	int ret;
146 
147 	dapm = snd_soc_component_get_dapm(component);
148 	ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
149 	if (ret)
150 		dev_err(rtd->dev, "Ref Cap -Ignore suspend failed = %d\n", ret);
151 
152 	return ret;
153 }
154 
155 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
156 {
157 	int ret;
158 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
159 	struct snd_soc_component *component = rtd->codec_dai->component;
160 	struct snd_soc_jack *jack;
161 
162 	/*
163 	 * Headset buttons map to the google Reference headset.
164 	 * These can be configured by userspace.
165 	 */
166 	ret = snd_soc_card_jack_new(&kabylake_audio_card, "Headset Jack",
167 			SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
168 			SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
169 			NULL, 0);
170 	if (ret) {
171 		dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
172 		return ret;
173 	}
174 
175 	jack = &ctx->kabylake_headset;
176 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
177 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
178 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
179 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
180 
181 	snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
182 
183 	ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "DMIC");
184 	if (ret)
185 		dev_err(rtd->dev, "DMIC - Ignore suspend failed = %d\n", ret);
186 
187 	return ret;
188 }
189 
190 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
191 {
192 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
193 	struct snd_soc_dai *dai = rtd->codec_dai;
194 	struct kbl_hdmi_pcm *pcm;
195 
196 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
197 	if (!pcm)
198 		return -ENOMEM;
199 
200 	pcm->device = device;
201 	pcm->codec_dai = dai;
202 
203 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
204 
205 	return 0;
206 }
207 
208 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
209 {
210 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
211 }
212 
213 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
214 {
215 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
216 }
217 
218 static const unsigned int rates[] = {
219 	48000,
220 };
221 
222 static const struct snd_pcm_hw_constraint_list constraints_rates = {
223 	.count = ARRAY_SIZE(rates),
224 	.list  = rates,
225 	.mask = 0,
226 };
227 
228 static const unsigned int channels[] = {
229 	2,
230 };
231 
232 static const struct snd_pcm_hw_constraint_list constraints_channels = {
233 	.count = ARRAY_SIZE(channels),
234 	.list = channels,
235 	.mask = 0,
236 };
237 
238 static int kbl_fe_startup(struct snd_pcm_substream *substream)
239 {
240 	struct snd_pcm_runtime *runtime = substream->runtime;
241 
242 	/*
243 	 * On this platform for PCM device we support,
244 	 * 48Khz
245 	 * stereo
246 	 * 16 bit audio
247 	 */
248 
249 	runtime->hw.channels_max = 2;
250 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
251 					   &constraints_channels);
252 
253 	runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
254 	snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
255 
256 	snd_pcm_hw_constraint_list(runtime, 0,
257 				SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
258 
259 	return 0;
260 }
261 
262 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
263 	.startup = kbl_fe_startup,
264 };
265 
266 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
267 					struct snd_pcm_hw_params *params)
268 {
269 	struct snd_interval *rate = hw_param_interval(params,
270 			SNDRV_PCM_HW_PARAM_RATE);
271 	struct snd_interval *channels = hw_param_interval(params,
272 			SNDRV_PCM_HW_PARAM_CHANNELS);
273 	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
274 	struct snd_soc_dpcm *dpcm = container_of(
275 			params, struct snd_soc_dpcm, hw_params);
276 	struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
277 	struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
278 
279 	/*
280 	 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
281 	 */
282 	if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
283 	    !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
284 	    !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
285 		rate->min = rate->max = 48000;
286 		channels->min = channels->max = 2;
287 		snd_mask_none(fmt);
288 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
289 	} else if (!strcmp(fe_dai_link->name, "Kbl Audio DMIC cap")) {
290 		if (params_channels(params) == 2 ||
291 				DMIC_CH(dmic_constraints) == 2)
292 			channels->min = channels->max = 2;
293 		else
294 			channels->min = channels->max = 4;
295 	}
296 	/*
297 	 * The speaker on the SSP0 supports S16_LE and not S24_LE.
298 	 * thus changing the mask here
299 	 */
300 	if (!strcmp(be_dai_link->name, "SSP0-Codec"))
301 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
302 
303 	return 0;
304 }
305 
306 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
307 	struct snd_pcm_hw_params *params)
308 {
309 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
310 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
311 	int ret;
312 
313 	/* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
314 	rt5663_sel_asrc_clk_src(codec_dai->component,
315 			RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
316 			RT5663_CLK_SEL_I2S1_ASRC);
317 
318 	ret = snd_soc_dai_set_sysclk(codec_dai,
319 			RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
320 	if (ret < 0)
321 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
322 
323 	return ret;
324 }
325 
326 static struct snd_soc_ops kabylake_rt5663_ops = {
327 	.hw_params = kabylake_rt5663_hw_params,
328 };
329 
330 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
331 	struct snd_pcm_hw_params *params)
332 {
333 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
334 	struct snd_soc_dai *codec_dai;
335 	int ret = 0, j;
336 
337 	for_each_rtd_codec_dai(rtd, j, codec_dai) {
338 		if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) {
339 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16);
340 			if (ret < 0) {
341 				dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
342 				return ret;
343 			}
344 
345 			ret = snd_soc_dai_set_sysclk(codec_dai,
346 				RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
347 			if (ret < 0) {
348 				dev_err(rtd->dev, "set sysclk err: %d\n", ret);
349 				return ret;
350 			}
351 		}
352 		if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
353 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
354 			if (ret < 0) {
355 				dev_err(rtd->dev, "DEV0 TDM slot err:%d\n", ret);
356 				return ret;
357 			}
358 		}
359 
360 		if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
361 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
362 			if (ret < 0) {
363 				dev_err(rtd->dev, "DEV1 TDM slot err:%d\n", ret);
364 				return ret;
365 			}
366 		}
367 	}
368 	return ret;
369 }
370 
371 static struct snd_soc_ops kabylake_ssp0_ops = {
372 	.hw_params = kabylake_ssp0_hw_params,
373 };
374 
375 static const unsigned int channels_dmic[] = {
376 	4,
377 };
378 
379 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
380 	.count = ARRAY_SIZE(channels_dmic),
381 	.list = channels_dmic,
382 	.mask = 0,
383 };
384 
385 static const unsigned int dmic_2ch[] = {
386 	2,
387 };
388 
389 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
390 	.count = ARRAY_SIZE(dmic_2ch),
391 	.list = dmic_2ch,
392 	.mask = 0,
393 };
394 
395 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
396 {
397 	struct snd_pcm_runtime *runtime = substream->runtime;
398 
399 	runtime->hw.channels_max = DMIC_CH(dmic_constraints);
400 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
401 			dmic_constraints);
402 
403 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
404 			SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
405 }
406 
407 static struct snd_soc_ops kabylake_dmic_ops = {
408 	.startup = kabylake_dmic_startup,
409 };
410 
411 SND_SOC_DAILINK_DEF(dummy,
412 	DAILINK_COMP_ARRAY(COMP_DUMMY()));
413 
414 SND_SOC_DAILINK_DEF(system,
415 	DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
416 
417 SND_SOC_DAILINK_DEF(system2,
418 	DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
419 
420 SND_SOC_DAILINK_DEF(echoref,
421 	DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
422 
423 SND_SOC_DAILINK_DEF(spi_cpu,
424 	DAILINK_COMP_ARRAY(COMP_CPU("spi-PRP0001:00")));
425 SND_SOC_DAILINK_DEF(spi_platform,
426 	DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-PRP0001:00")));
427 
428 SND_SOC_DAILINK_DEF(dmic,
429 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
430 
431 SND_SOC_DAILINK_DEF(hdmi1,
432 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
433 
434 SND_SOC_DAILINK_DEF(hdmi2,
435 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
436 
437 SND_SOC_DAILINK_DEF(ssp0_pin,
438 	DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
439 SND_SOC_DAILINK_DEF(ssp0_codec,
440 	DAILINK_COMP_ARRAY(
441 	/* Left */ COMP_CODEC(MAXIM_DEV0_NAME, KBL_MAXIM_CODEC_DAI),
442 	/* Right */COMP_CODEC(MAXIM_DEV1_NAME, KBL_MAXIM_CODEC_DAI),
443 	/* dmic */ COMP_CODEC(RT5514_DEV_NAME, KBL_REALTEK_DMIC_CODEC_DAI)));
444 
445 SND_SOC_DAILINK_DEF(ssp1_pin,
446 	DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
447 SND_SOC_DAILINK_DEF(ssp1_codec,
448 	DAILINK_COMP_ARRAY(COMP_CODEC(RT5663_DEV_NAME, KBL_REALTEK_CODEC_DAI)));
449 
450 SND_SOC_DAILINK_DEF(idisp1_pin,
451 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
452 SND_SOC_DAILINK_DEF(idisp1_codec,
453 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
454 
455 SND_SOC_DAILINK_DEF(idisp2_pin,
456 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
457 SND_SOC_DAILINK_DEF(idisp2_codec,
458 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
459 
460 SND_SOC_DAILINK_DEF(platform,
461 	DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
462 
463 /* kabylake digital audio interface glue - connects codec <--> CPU */
464 static struct snd_soc_dai_link kabylake_dais[] = {
465 	/* Front End DAI links */
466 	[KBL_DPCM_AUDIO_PB] = {
467 		.name = "Kbl Audio Port",
468 		.stream_name = "Audio",
469 		.dynamic = 1,
470 		.nonatomic = 1,
471 		.init = kabylake_rt5663_fe_init,
472 		.trigger = {
473 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
474 		.dpcm_playback = 1,
475 		.ops = &kabylake_rt5663_fe_ops,
476 		SND_SOC_DAILINK_REG(system, dummy, platform),
477 	},
478 	[KBL_DPCM_AUDIO_CP] = {
479 		.name = "Kbl Audio Capture Port",
480 		.stream_name = "Audio Record",
481 		.dynamic = 1,
482 		.nonatomic = 1,
483 		.trigger = {
484 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
485 		.dpcm_capture = 1,
486 		.ops = &kabylake_rt5663_fe_ops,
487 		SND_SOC_DAILINK_REG(system, dummy, platform),
488 	},
489 	[KBL_DPCM_AUDIO_HS_PB] = {
490 		.name = "Kbl Audio Headset Playback",
491 		.stream_name = "Headset Audio",
492 		.dpcm_playback = 1,
493 		.nonatomic = 1,
494 		.dynamic = 1,
495 		SND_SOC_DAILINK_REG(system2, dummy, platform),
496 	},
497 	[KBL_DPCM_AUDIO_ECHO_REF_CP] = {
498 		.name = "Kbl Audio Echo Reference cap",
499 		.stream_name = "Echoreference Capture",
500 		.init = NULL,
501 		.capture_only = 1,
502 		.nonatomic = 1,
503 		SND_SOC_DAILINK_REG(echoref, dummy, platform),
504 	},
505 	[KBL_DPCM_AUDIO_RT5514_DSP] = {
506 		.name = "rt5514 dsp",
507 		.stream_name = "Wake on Voice",
508 		SND_SOC_DAILINK_REG(spi_cpu, dummy, spi_platform),
509 	},
510 	[KBL_DPCM_AUDIO_DMIC_CP] = {
511 		.name = "Kbl Audio DMIC cap",
512 		.stream_name = "dmiccap",
513 		.init = NULL,
514 		.dpcm_capture = 1,
515 		.nonatomic = 1,
516 		.dynamic = 1,
517 		.ops = &kabylake_dmic_ops,
518 		SND_SOC_DAILINK_REG(dmic, dummy, platform),
519 	},
520 	[KBL_DPCM_AUDIO_HDMI1_PB] = {
521 		.name = "Kbl HDMI Port1",
522 		.stream_name = "Hdmi1",
523 		.dpcm_playback = 1,
524 		.init = NULL,
525 		.trigger = {
526 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
527 		.nonatomic = 1,
528 		.dynamic = 1,
529 		SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
530 	},
531 	[KBL_DPCM_AUDIO_HDMI2_PB] = {
532 		.name = "Kbl HDMI Port2",
533 		.stream_name = "Hdmi2",
534 		.dpcm_playback = 1,
535 		.init = NULL,
536 		.trigger = {
537 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
538 		.nonatomic = 1,
539 		.dynamic = 1,
540 		SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
541 	},
542 	/* Back End DAI links */
543 	/* single Back end dai for both max speakers and dmic */
544 	{
545 		/* SSP0 - Codec */
546 		.name = "SSP0-Codec",
547 		.id = 0,
548 		.no_pcm = 1,
549 		.dai_fmt = SND_SOC_DAIFMT_DSP_B |
550 			SND_SOC_DAIFMT_NB_NF |
551 			SND_SOC_DAIFMT_CBS_CFS,
552 		.ignore_pmdown_time = 1,
553 		.be_hw_params_fixup = kabylake_ssp_fixup,
554 		.dpcm_playback = 1,
555 		.dpcm_capture = 1,
556 		.ops = &kabylake_ssp0_ops,
557 		SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
558 	},
559 	{
560 		.name = "SSP1-Codec",
561 		.id = 1,
562 		.no_pcm = 1,
563 		.init = kabylake_rt5663_codec_init,
564 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
565 			SND_SOC_DAIFMT_CBS_CFS,
566 		.ignore_pmdown_time = 1,
567 		.be_hw_params_fixup = kabylake_ssp_fixup,
568 		.ops = &kabylake_rt5663_ops,
569 		.dpcm_playback = 1,
570 		.dpcm_capture = 1,
571 		SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
572 	},
573 	{
574 		.name = "iDisp1",
575 		.id = 3,
576 		.dpcm_playback = 1,
577 		.init = kabylake_hdmi1_init,
578 		.no_pcm = 1,
579 		SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
580 	},
581 	{
582 		.name = "iDisp2",
583 		.id = 4,
584 		.init = kabylake_hdmi2_init,
585 		.dpcm_playback = 1,
586 		.no_pcm = 1,
587 		SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
588 	},
589 };
590 
591 static int kabylake_card_late_probe(struct snd_soc_card *card)
592 {
593 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
594 	struct kbl_hdmi_pcm *pcm;
595 	struct snd_soc_component *component = NULL;
596 	int err, i = 0;
597 	char jack_name[NAME_SIZE];
598 
599 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
600 		component = pcm->codec_dai->component;
601 		snprintf(jack_name, sizeof(jack_name),
602 			"HDMI/DP,pcm=%d Jack", pcm->device);
603 		err = snd_soc_card_jack_new(card, jack_name,
604 				SND_JACK_AVOUT, &ctx->kabylake_hdmi[i],
605 				NULL, 0);
606 
607 		if (err)
608 			return err;
609 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
610 						&ctx->kabylake_hdmi[i]);
611 		if (err < 0)
612 			return err;
613 		i++;
614 	}
615 
616 	if (!component)
617 		return -EINVAL;
618 
619 	return hdac_hdmi_jack_port_init(component, &card->dapm);
620 }
621 
622 /*
623  * kabylake audio machine driver for  MAX98927 + RT5514 + RT5663
624  */
625 static struct snd_soc_card kabylake_audio_card = {
626 	.name = "kbl_r5514_5663_max",
627 	.owner = THIS_MODULE,
628 	.dai_link = kabylake_dais,
629 	.num_links = ARRAY_SIZE(kabylake_dais),
630 	.controls = kabylake_controls,
631 	.num_controls = ARRAY_SIZE(kabylake_controls),
632 	.dapm_widgets = kabylake_widgets,
633 	.num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
634 	.dapm_routes = kabylake_map,
635 	.num_dapm_routes = ARRAY_SIZE(kabylake_map),
636 	.codec_conf = max98927_codec_conf,
637 	.num_configs = ARRAY_SIZE(max98927_codec_conf),
638 	.fully_routed = true,
639 	.late_probe = kabylake_card_late_probe,
640 };
641 
642 static int kabylake_audio_probe(struct platform_device *pdev)
643 {
644 	struct kbl_codec_private *ctx;
645 	struct snd_soc_acpi_mach *mach;
646 
647 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
648 	if (!ctx)
649 		return -ENOMEM;
650 
651 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
652 
653 	kabylake_audio_card.dev = &pdev->dev;
654 	snd_soc_card_set_drvdata(&kabylake_audio_card, ctx);
655 
656 	mach = (&pdev->dev)->platform_data;
657 	if (mach)
658 		dmic_constraints = mach->mach_params.dmic_num == 2 ?
659 			&constraints_dmic_2ch : &constraints_dmic_channels;
660 
661 	return devm_snd_soc_register_card(&pdev->dev, &kabylake_audio_card);
662 }
663 
664 static const struct platform_device_id kbl_board_ids[] = {
665 	{ .name = "kbl_r5514_5663_max" },
666 	{ }
667 };
668 
669 static struct platform_driver kabylake_audio = {
670 	.probe = kabylake_audio_probe,
671 	.driver = {
672 		.name = "kbl_r5514_5663_max",
673 		.pm = &snd_soc_pm_ops,
674 	},
675 	.id_table = kbl_board_ids,
676 };
677 
678 module_platform_driver(kabylake_audio)
679 
680 /* Module information */
681 MODULE_DESCRIPTION("Audio Machine driver-RT5663 RT5514 & MAX98927");
682 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
683 MODULE_LICENSE("GPL v2");
684 MODULE_ALIAS("platform:kbl_r5514_5663_max");
685