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 static struct snd_soc_dai_link_component ssp0_codec_components[] = {
141 	{ /* Left */
142 		.name = MAXIM_DEV0_NAME,
143 		.dai_name = KBL_MAXIM_CODEC_DAI,
144 	},
145 	{ /* Right */
146 		.name = MAXIM_DEV1_NAME,
147 		.dai_name = KBL_MAXIM_CODEC_DAI,
148 	},
149 	{ /*dmic */
150 		.name = RT5514_DEV_NAME,
151 		.dai_name = KBL_REALTEK_DMIC_CODEC_DAI,
152 	},
153 };
154 
155 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
156 {
157 	struct snd_soc_dapm_context *dapm;
158 	struct snd_soc_component *component = rtd->cpu_dai->component;
159 	int ret;
160 
161 	dapm = snd_soc_component_get_dapm(component);
162 	ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
163 	if (ret)
164 		dev_err(rtd->dev, "Ref Cap -Ignore suspend failed = %d\n", ret);
165 
166 	return ret;
167 }
168 
169 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
170 {
171 	int ret;
172 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
173 	struct snd_soc_component *component = rtd->codec_dai->component;
174 	struct snd_soc_jack *jack;
175 
176 	/*
177 	 * Headset buttons map to the google Reference headset.
178 	 * These can be configured by userspace.
179 	 */
180 	ret = snd_soc_card_jack_new(&kabylake_audio_card, "Headset Jack",
181 			SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
182 			SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
183 			NULL, 0);
184 	if (ret) {
185 		dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
186 		return ret;
187 	}
188 
189 	jack = &ctx->kabylake_headset;
190 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
191 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
192 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
193 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
194 
195 	snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
196 
197 	ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "DMIC");
198 	if (ret)
199 		dev_err(rtd->dev, "DMIC - Ignore suspend failed = %d\n", ret);
200 
201 	return ret;
202 }
203 
204 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
205 {
206 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
207 	struct snd_soc_dai *dai = rtd->codec_dai;
208 	struct kbl_hdmi_pcm *pcm;
209 
210 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
211 	if (!pcm)
212 		return -ENOMEM;
213 
214 	pcm->device = device;
215 	pcm->codec_dai = dai;
216 
217 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
218 
219 	return 0;
220 }
221 
222 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
223 {
224 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
225 }
226 
227 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
228 {
229 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
230 }
231 
232 static const unsigned int rates[] = {
233 	48000,
234 };
235 
236 static const struct snd_pcm_hw_constraint_list constraints_rates = {
237 	.count = ARRAY_SIZE(rates),
238 	.list  = rates,
239 	.mask = 0,
240 };
241 
242 static const unsigned int channels[] = {
243 	2,
244 };
245 
246 static const struct snd_pcm_hw_constraint_list constraints_channels = {
247 	.count = ARRAY_SIZE(channels),
248 	.list = channels,
249 	.mask = 0,
250 };
251 
252 static int kbl_fe_startup(struct snd_pcm_substream *substream)
253 {
254 	struct snd_pcm_runtime *runtime = substream->runtime;
255 
256 	/*
257 	 * On this platform for PCM device we support,
258 	 * 48Khz
259 	 * stereo
260 	 * 16 bit audio
261 	 */
262 
263 	runtime->hw.channels_max = 2;
264 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
265 					   &constraints_channels);
266 
267 	runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
268 	snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
269 
270 	snd_pcm_hw_constraint_list(runtime, 0,
271 				SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
272 
273 	return 0;
274 }
275 
276 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
277 	.startup = kbl_fe_startup,
278 };
279 
280 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
281 					struct snd_pcm_hw_params *params)
282 {
283 	struct snd_interval *rate = hw_param_interval(params,
284 			SNDRV_PCM_HW_PARAM_RATE);
285 	struct snd_interval *channels = hw_param_interval(params,
286 			SNDRV_PCM_HW_PARAM_CHANNELS);
287 	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
288 	struct snd_soc_dpcm *dpcm = container_of(
289 			params, struct snd_soc_dpcm, hw_params);
290 	struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
291 	struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
292 
293 	/*
294 	 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
295 	 */
296 	if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
297 	    !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
298 	    !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
299 		rate->min = rate->max = 48000;
300 		channels->min = channels->max = 2;
301 		snd_mask_none(fmt);
302 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
303 	} else if (!strcmp(fe_dai_link->name, "Kbl Audio DMIC cap")) {
304 		if (params_channels(params) == 2 ||
305 				DMIC_CH(dmic_constraints) == 2)
306 			channels->min = channels->max = 2;
307 		else
308 			channels->min = channels->max = 4;
309 	}
310 	/*
311 	 * The speaker on the SSP0 supports S16_LE and not S24_LE.
312 	 * thus changing the mask here
313 	 */
314 	if (!strcmp(be_dai_link->name, "SSP0-Codec"))
315 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
316 
317 	return 0;
318 }
319 
320 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
321 	struct snd_pcm_hw_params *params)
322 {
323 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
324 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
325 	int ret;
326 
327 	/* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
328 	rt5663_sel_asrc_clk_src(codec_dai->component,
329 			RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
330 			RT5663_CLK_SEL_I2S1_ASRC);
331 
332 	ret = snd_soc_dai_set_sysclk(codec_dai,
333 			RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
334 	if (ret < 0)
335 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
336 
337 	return ret;
338 }
339 
340 static struct snd_soc_ops kabylake_rt5663_ops = {
341 	.hw_params = kabylake_rt5663_hw_params,
342 };
343 
344 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
345 	struct snd_pcm_hw_params *params)
346 {
347 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
348 	struct snd_soc_dai *codec_dai;
349 	int ret = 0, j;
350 
351 	for_each_rtd_codec_dai(rtd, j, codec_dai) {
352 		if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) {
353 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16);
354 			if (ret < 0) {
355 				dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
356 				return ret;
357 			}
358 
359 			ret = snd_soc_dai_set_sysclk(codec_dai,
360 				RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
361 			if (ret < 0) {
362 				dev_err(rtd->dev, "set sysclk err: %d\n", ret);
363 				return ret;
364 			}
365 		}
366 		if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
367 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
368 			if (ret < 0) {
369 				dev_err(rtd->dev, "DEV0 TDM slot err:%d\n", ret);
370 				return ret;
371 			}
372 		}
373 
374 		if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
375 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
376 			if (ret < 0) {
377 				dev_err(rtd->dev, "DEV1 TDM slot err:%d\n", ret);
378 				return ret;
379 			}
380 		}
381 	}
382 	return ret;
383 }
384 
385 static struct snd_soc_ops kabylake_ssp0_ops = {
386 	.hw_params = kabylake_ssp0_hw_params,
387 };
388 
389 static const unsigned int channels_dmic[] = {
390 	4,
391 };
392 
393 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
394 	.count = ARRAY_SIZE(channels_dmic),
395 	.list = channels_dmic,
396 	.mask = 0,
397 };
398 
399 static const unsigned int dmic_2ch[] = {
400 	2,
401 };
402 
403 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
404 	.count = ARRAY_SIZE(dmic_2ch),
405 	.list = dmic_2ch,
406 	.mask = 0,
407 };
408 
409 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
410 {
411 	struct snd_pcm_runtime *runtime = substream->runtime;
412 
413 	runtime->hw.channels_max = DMIC_CH(dmic_constraints);
414 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
415 			dmic_constraints);
416 
417 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
418 			SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
419 }
420 
421 static struct snd_soc_ops kabylake_dmic_ops = {
422 	.startup = kabylake_dmic_startup,
423 };
424 
425 /* kabylake digital audio interface glue - connects codec <--> CPU */
426 static struct snd_soc_dai_link kabylake_dais[] = {
427 	/* Front End DAI links */
428 	[KBL_DPCM_AUDIO_PB] = {
429 		.name = "Kbl Audio Port",
430 		.stream_name = "Audio",
431 		.cpu_dai_name = "System Pin",
432 		.platform_name = "0000:00:1f.3",
433 		.dynamic = 1,
434 		.codec_name = "snd-soc-dummy",
435 		.codec_dai_name = "snd-soc-dummy-dai",
436 		.nonatomic = 1,
437 		.init = kabylake_rt5663_fe_init,
438 		.trigger = {
439 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
440 		.dpcm_playback = 1,
441 		.ops = &kabylake_rt5663_fe_ops,
442 	},
443 	[KBL_DPCM_AUDIO_CP] = {
444 		.name = "Kbl Audio Capture Port",
445 		.stream_name = "Audio Record",
446 		.cpu_dai_name = "System Pin",
447 		.platform_name = "0000:00:1f.3",
448 		.dynamic = 1,
449 		.codec_name = "snd-soc-dummy",
450 		.codec_dai_name = "snd-soc-dummy-dai",
451 		.nonatomic = 1,
452 		.trigger = {
453 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
454 		.dpcm_capture = 1,
455 		.ops = &kabylake_rt5663_fe_ops,
456 	},
457 	[KBL_DPCM_AUDIO_HS_PB] = {
458 		.name = "Kbl Audio Headset Playback",
459 		.stream_name = "Headset Audio",
460 		.cpu_dai_name = "System Pin2",
461 		.codec_name = "snd-soc-dummy",
462 		.codec_dai_name = "snd-soc-dummy-dai",
463 		.platform_name = "0000:00:1f.3",
464 		.dpcm_playback = 1,
465 		.nonatomic = 1,
466 		.dynamic = 1,
467 	},
468 	[KBL_DPCM_AUDIO_ECHO_REF_CP] = {
469 		.name = "Kbl Audio Echo Reference cap",
470 		.stream_name = "Echoreference Capture",
471 		.cpu_dai_name = "Echoref Pin",
472 		.codec_name = "snd-soc-dummy",
473 		.codec_dai_name = "snd-soc-dummy-dai",
474 		.platform_name = "0000:00:1f.3",
475 		.init = NULL,
476 		.capture_only = 1,
477 		.nonatomic = 1,
478 	},
479 	[KBL_DPCM_AUDIO_RT5514_DSP] = {
480 		.name = "rt5514 dsp",
481 		.stream_name = "Wake on Voice",
482 		.cpu_dai_name = "spi-PRP0001:00",
483 		.platform_name = "spi-PRP0001:00",
484 		.codec_name = "snd-soc-dummy",
485 		.codec_dai_name = "snd-soc-dummy-dai",
486 	},
487 	[KBL_DPCM_AUDIO_DMIC_CP] = {
488 		.name = "Kbl Audio DMIC cap",
489 		.stream_name = "dmiccap",
490 		.cpu_dai_name = "DMIC Pin",
491 		.codec_name = "snd-soc-dummy",
492 		.codec_dai_name = "snd-soc-dummy-dai",
493 		.platform_name = "0000:00:1f.3",
494 		.init = NULL,
495 		.dpcm_capture = 1,
496 		.nonatomic = 1,
497 		.dynamic = 1,
498 		.ops = &kabylake_dmic_ops,
499 	},
500 	[KBL_DPCM_AUDIO_HDMI1_PB] = {
501 		.name = "Kbl HDMI Port1",
502 		.stream_name = "Hdmi1",
503 		.cpu_dai_name = "HDMI1 Pin",
504 		.codec_name = "snd-soc-dummy",
505 		.codec_dai_name = "snd-soc-dummy-dai",
506 		.platform_name = "0000:00:1f.3",
507 		.dpcm_playback = 1,
508 		.init = NULL,
509 		.trigger = {
510 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
511 		.nonatomic = 1,
512 		.dynamic = 1,
513 	},
514 	[KBL_DPCM_AUDIO_HDMI2_PB] = {
515 		.name = "Kbl HDMI Port2",
516 		.stream_name = "Hdmi2",
517 		.cpu_dai_name = "HDMI2 Pin",
518 		.codec_name = "snd-soc-dummy",
519 		.codec_dai_name = "snd-soc-dummy-dai",
520 		.platform_name = "0000:00:1f.3",
521 		.dpcm_playback = 1,
522 		.init = NULL,
523 		.trigger = {
524 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
525 		.nonatomic = 1,
526 		.dynamic = 1,
527 	},
528 	/* Back End DAI links */
529 	/* single Back end dai for both max speakers and dmic */
530 	{
531 		/* SSP0 - Codec */
532 		.name = "SSP0-Codec",
533 		.id = 0,
534 		.cpu_dai_name = "SSP0 Pin",
535 		.platform_name = "0000:00:1f.3",
536 		.no_pcm = 1,
537 		.codecs = ssp0_codec_components,
538 		.num_codecs = ARRAY_SIZE(ssp0_codec_components),
539 		.dai_fmt = SND_SOC_DAIFMT_DSP_B |
540 			SND_SOC_DAIFMT_NB_NF |
541 			SND_SOC_DAIFMT_CBS_CFS,
542 		.ignore_pmdown_time = 1,
543 		.be_hw_params_fixup = kabylake_ssp_fixup,
544 		.dpcm_playback = 1,
545 		.dpcm_capture = 1,
546 		.ops = &kabylake_ssp0_ops,
547 	},
548 	{
549 		.name = "SSP1-Codec",
550 		.id = 1,
551 		.cpu_dai_name = "SSP1 Pin",
552 		.platform_name = "0000:00:1f.3",
553 		.no_pcm = 1,
554 		.codec_name = RT5663_DEV_NAME,
555 		.codec_dai_name = KBL_REALTEK_CODEC_DAI,
556 		.init = kabylake_rt5663_codec_init,
557 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
558 			SND_SOC_DAIFMT_CBS_CFS,
559 		.ignore_pmdown_time = 1,
560 		.be_hw_params_fixup = kabylake_ssp_fixup,
561 		.ops = &kabylake_rt5663_ops,
562 		.dpcm_playback = 1,
563 		.dpcm_capture = 1,
564 	},
565 	{
566 		.name = "iDisp1",
567 		.id = 3,
568 		.cpu_dai_name = "iDisp1 Pin",
569 		.codec_name = "ehdaudio0D2",
570 		.codec_dai_name = "intel-hdmi-hifi1",
571 		.platform_name = "0000:00:1f.3",
572 		.dpcm_playback = 1,
573 		.init = kabylake_hdmi1_init,
574 		.no_pcm = 1,
575 	},
576 	{
577 		.name = "iDisp2",
578 		.id = 4,
579 		.cpu_dai_name = "iDisp2 Pin",
580 		.codec_name = "ehdaudio0D2",
581 		.codec_dai_name = "intel-hdmi-hifi2",
582 		.platform_name = "0000:00:1f.3",
583 		.init = kabylake_hdmi2_init,
584 		.dpcm_playback = 1,
585 		.no_pcm = 1,
586 	},
587 };
588 
589 static int kabylake_card_late_probe(struct snd_soc_card *card)
590 {
591 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
592 	struct kbl_hdmi_pcm *pcm;
593 	struct snd_soc_component *component = NULL;
594 	int err, i = 0;
595 	char jack_name[NAME_SIZE];
596 
597 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
598 		component = pcm->codec_dai->component;
599 		snprintf(jack_name, sizeof(jack_name),
600 			"HDMI/DP,pcm=%d Jack", pcm->device);
601 		err = snd_soc_card_jack_new(card, jack_name,
602 				SND_JACK_AVOUT, &ctx->kabylake_hdmi[i],
603 				NULL, 0);
604 
605 		if (err)
606 			return err;
607 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
608 						&ctx->kabylake_hdmi[i]);
609 		if (err < 0)
610 			return err;
611 		i++;
612 	}
613 
614 	if (!component)
615 		return -EINVAL;
616 
617 	return hdac_hdmi_jack_port_init(component, &card->dapm);
618 }
619 
620 /*
621  * kabylake audio machine driver for  MAX98927 + RT5514 + RT5663
622  */
623 static struct snd_soc_card kabylake_audio_card = {
624 	.name = "kbl_r5514_5663_max",
625 	.owner = THIS_MODULE,
626 	.dai_link = kabylake_dais,
627 	.num_links = ARRAY_SIZE(kabylake_dais),
628 	.controls = kabylake_controls,
629 	.num_controls = ARRAY_SIZE(kabylake_controls),
630 	.dapm_widgets = kabylake_widgets,
631 	.num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
632 	.dapm_routes = kabylake_map,
633 	.num_dapm_routes = ARRAY_SIZE(kabylake_map),
634 	.codec_conf = max98927_codec_conf,
635 	.num_configs = ARRAY_SIZE(max98927_codec_conf),
636 	.fully_routed = true,
637 	.late_probe = kabylake_card_late_probe,
638 };
639 
640 static int kabylake_audio_probe(struct platform_device *pdev)
641 {
642 	struct kbl_codec_private *ctx;
643 	struct snd_soc_acpi_mach *mach;
644 
645 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
646 	if (!ctx)
647 		return -ENOMEM;
648 
649 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
650 
651 	kabylake_audio_card.dev = &pdev->dev;
652 	snd_soc_card_set_drvdata(&kabylake_audio_card, ctx);
653 
654 	mach = (&pdev->dev)->platform_data;
655 	if (mach)
656 		dmic_constraints = mach->mach_params.dmic_num == 2 ?
657 			&constraints_dmic_2ch : &constraints_dmic_channels;
658 
659 	return devm_snd_soc_register_card(&pdev->dev, &kabylake_audio_card);
660 }
661 
662 static const struct platform_device_id kbl_board_ids[] = {
663 	{ .name = "kbl_r5514_5663_max" },
664 	{ }
665 };
666 
667 static struct platform_driver kabylake_audio = {
668 	.probe = kabylake_audio_probe,
669 	.driver = {
670 		.name = "kbl_r5514_5663_max",
671 		.pm = &snd_soc_pm_ops,
672 	},
673 	.id_table = kbl_board_ids,
674 };
675 
676 module_platform_driver(kabylake_audio)
677 
678 /* Module information */
679 MODULE_DESCRIPTION("Audio Machine driver-RT5663 RT5514 & MAX98927");
680 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
681 MODULE_LICENSE("GPL v2");
682 MODULE_ALIAS("platform:kbl_r5514_5663_max");
683