1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2018 Intel Corporation.
3 
4 /*
5  * Intel Kabylake I2S Machine Driver with MAX98927, MAX98373 & DA7219 Codecs
6  *
7  * Modified from:
8  *   Intel Kabylake I2S Machine driver supporting MAX98927 and
9  *   RT5663 codecs
10  */
11 
12 #include <linux/input.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <sound/core.h>
16 #include <sound/jack.h>
17 #include <sound/pcm.h>
18 #include <sound/pcm_params.h>
19 #include <sound/soc.h>
20 #include "../../codecs/da7219.h"
21 #include "../../codecs/hdac_hdmi.h"
22 #include "../../codecs/da7219-aad.h"
23 
24 #define KBL_DIALOG_CODEC_DAI	"da7219-hifi"
25 #define MAX98927_CODEC_DAI	"max98927-aif1"
26 #define MAX98927_DEV0_NAME	"i2c-MX98927:00"
27 #define MAX98927_DEV1_NAME	"i2c-MX98927:01"
28 
29 #define MAX98373_CODEC_DAI	"max98373-aif1"
30 #define MAX98373_DEV0_NAME	"i2c-MX98373:00"
31 #define MAX98373_DEV1_NAME	"i2c-MX98373:01"
32 
33 
34 #define DUAL_CHANNEL	2
35 #define QUAD_CHANNEL	4
36 #define NAME_SIZE	32
37 
38 static struct snd_soc_card *kabylake_audio_card;
39 static struct snd_soc_jack kabylake_hdmi[3];
40 
41 struct kbl_hdmi_pcm {
42 	struct list_head head;
43 	struct snd_soc_dai *codec_dai;
44 	int device;
45 };
46 
47 struct kbl_codec_private {
48 	struct snd_soc_jack kabylake_headset;
49 	struct list_head hdmi_pcm_list;
50 };
51 
52 enum {
53 	KBL_DPCM_AUDIO_PB = 0,
54 	KBL_DPCM_AUDIO_ECHO_REF_CP,
55 	KBL_DPCM_AUDIO_REF_CP,
56 	KBL_DPCM_AUDIO_DMIC_CP,
57 	KBL_DPCM_AUDIO_HDMI1_PB,
58 	KBL_DPCM_AUDIO_HDMI2_PB,
59 	KBL_DPCM_AUDIO_HDMI3_PB,
60 	KBL_DPCM_AUDIO_HS_PB,
61 	KBL_DPCM_AUDIO_CP,
62 };
63 
64 static int platform_clock_control(struct snd_soc_dapm_widget *w,
65 					struct snd_kcontrol *k, int  event)
66 {
67 	struct snd_soc_dapm_context *dapm = w->dapm;
68 	struct snd_soc_card *card = dapm->card;
69 	struct snd_soc_dai *codec_dai;
70 	int ret = 0;
71 
72 	codec_dai = snd_soc_card_get_codec_dai(card, KBL_DIALOG_CODEC_DAI);
73 	if (!codec_dai) {
74 		dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
75 		return -EIO;
76 	}
77 
78 	/* Configure sysclk for codec */
79 	ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24576000,
80 				     SND_SOC_CLOCK_IN);
81 	if (ret) {
82 		dev_err(card->dev, "can't set codec sysclk configuration\n");
83 		return ret;
84 	}
85 
86 	if (SND_SOC_DAPM_EVENT_OFF(event)) {
87 		ret = snd_soc_dai_set_pll(codec_dai, 0,
88 				     DA7219_SYSCLK_MCLK, 0, 0);
89 		if (ret)
90 			dev_err(card->dev, "failed to stop PLL: %d\n", ret);
91 	} else if (SND_SOC_DAPM_EVENT_ON(event)) {
92 		ret = snd_soc_dai_set_pll(codec_dai, 0,	DA7219_SYSCLK_PLL_SRM,
93 				     0, DA7219_PLL_FREQ_OUT_98304);
94 		if (ret)
95 			dev_err(card->dev, "failed to start PLL: %d\n", ret);
96 	}
97 
98 	return ret;
99 }
100 
101 static const struct snd_kcontrol_new kabylake_controls[] = {
102 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
103 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
104 	SOC_DAPM_PIN_SWITCH("Left Spk"),
105 	SOC_DAPM_PIN_SWITCH("Right Spk"),
106 };
107 
108 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
109 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
110 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
111 	SND_SOC_DAPM_SPK("Left Spk", NULL),
112 	SND_SOC_DAPM_SPK("Right Spk", NULL),
113 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
114 	SND_SOC_DAPM_SPK("HDMI1", NULL),
115 	SND_SOC_DAPM_SPK("HDMI2", NULL),
116 	SND_SOC_DAPM_SPK("HDMI3", NULL),
117 	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
118 			platform_clock_control, SND_SOC_DAPM_PRE_PMU |
119 			SND_SOC_DAPM_POST_PMD),
120 };
121 
122 static const struct snd_soc_dapm_route kabylake_map[] = {
123 	/* speaker */
124 	{ "Left Spk", NULL, "Left BE_OUT" },
125 	{ "Right Spk", NULL, "Right BE_OUT" },
126 
127 	/* other jacks */
128 	{ "DMic", NULL, "SoC DMIC" },
129 
130 	{"HDMI1", NULL, "hif5-0 Output"},
131 	{"HDMI2", NULL, "hif6-0 Output"},
132 	{"HDMI3", NULL, "hif7-0 Output"},
133 
134 	/* CODEC BE connections */
135 	{ "Left HiFi Playback", NULL, "ssp0 Tx" },
136 	{ "Right HiFi Playback", NULL, "ssp0 Tx" },
137 	{ "ssp0 Tx", NULL, "spk_out" },
138 
139 	/* IV feedback path */
140 	{ "codec0_fb_in", NULL, "ssp0 Rx"},
141 	{ "ssp0 Rx", NULL, "Left HiFi Capture" },
142 	{ "ssp0 Rx", NULL, "Right HiFi Capture" },
143 
144 	/* AEC capture path */
145 	{ "echo_ref_out", NULL, "ssp0 Rx" },
146 
147 	/* DMIC */
148 	{ "dmic01_hifi", NULL, "DMIC01 Rx" },
149 	{ "DMIC01 Rx", NULL, "DMIC AIF" },
150 
151 	{ "hifi1", NULL, "iDisp1 Tx" },
152 	{ "iDisp1 Tx", NULL, "iDisp1_out" },
153 	{ "hifi2", NULL, "iDisp2 Tx" },
154 	{ "iDisp2 Tx", NULL, "iDisp2_out" },
155 	{ "hifi3", NULL, "iDisp3 Tx"},
156 	{ "iDisp3 Tx", NULL, "iDisp3_out"},
157 };
158 
159 static const struct snd_soc_dapm_route kabylake_ssp1_map[] = {
160 	{ "Headphone Jack", NULL, "HPL" },
161 	{ "Headphone Jack", NULL, "HPR" },
162 
163 	/* other jacks */
164 	{ "MIC", NULL, "Headset Mic" },
165 
166 	/* CODEC BE connections */
167 	{ "Playback", NULL, "ssp1 Tx" },
168 	{ "ssp1 Tx", NULL, "codec1_out" },
169 
170 	{ "hs_in", NULL, "ssp1 Rx" },
171 	{ "ssp1 Rx", NULL, "Capture" },
172 
173 	{ "Headphone Jack", NULL, "Platform Clock" },
174 	{ "Headset Mic", NULL, "Platform Clock" },
175 };
176 
177 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
178 	struct snd_pcm_hw_params *params)
179 {
180 	struct snd_soc_pcm_runtime *runtime = asoc_substream_to_rtd(substream);
181 	struct snd_soc_dai *codec_dai;
182 	int ret, j;
183 
184 	for_each_rtd_codec_dais(runtime, j, codec_dai) {
185 
186 		if (!strcmp(codec_dai->component->name, MAX98927_DEV0_NAME)) {
187 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
188 			if (ret < 0) {
189 				dev_err(runtime->dev, "DEV0 TDM slot err:%d\n", ret);
190 				return ret;
191 			}
192 		}
193 		if (!strcmp(codec_dai->component->name, MAX98927_DEV1_NAME)) {
194 			ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
195 			if (ret < 0) {
196 				dev_err(runtime->dev, "DEV1 TDM slot err:%d\n", ret);
197 				return ret;
198 			}
199 		}
200 		if (!strcmp(codec_dai->component->name, MAX98373_DEV0_NAME)) {
201 			ret = snd_soc_dai_set_tdm_slot(codec_dai,
202 							0x03, 3, 8, 24);
203 			if (ret < 0) {
204 				dev_err(runtime->dev,
205 						"DEV0 TDM slot err:%d\n", ret);
206 				return ret;
207 			}
208 		}
209 		if (!strcmp(codec_dai->component->name, MAX98373_DEV1_NAME)) {
210 			ret = snd_soc_dai_set_tdm_slot(codec_dai,
211 							0x0C, 3, 8, 24);
212 			if (ret < 0) {
213 				dev_err(runtime->dev,
214 						"DEV0 TDM slot err:%d\n", ret);
215 				return ret;
216 			}
217 		}
218 	}
219 
220 	return 0;
221 }
222 
223 static int kabylake_ssp0_trigger(struct snd_pcm_substream *substream, int cmd)
224 {
225 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
226 	struct snd_soc_dai *codec_dai;
227 	int j, ret;
228 
229 	for_each_rtd_codec_dais(rtd, j, codec_dai) {
230 		const char *name = codec_dai->component->name;
231 		struct snd_soc_component *component = codec_dai->component;
232 		struct snd_soc_dapm_context *dapm =
233 				snd_soc_component_get_dapm(component);
234 		char pin_name[20];
235 
236 		if (strcmp(name, MAX98927_DEV0_NAME) &&
237 			strcmp(name, MAX98927_DEV1_NAME) &&
238 			strcmp(name, MAX98373_DEV0_NAME) &&
239 			strcmp(name, MAX98373_DEV1_NAME))
240 			continue;
241 
242 		snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
243 			codec_dai->component->name_prefix);
244 
245 		switch (cmd) {
246 		case SNDRV_PCM_TRIGGER_START:
247 		case SNDRV_PCM_TRIGGER_RESUME:
248 		case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
249 			ret = snd_soc_dapm_enable_pin(dapm, pin_name);
250 			if (ret) {
251 				dev_err(rtd->dev, "failed to enable %s: %d\n",
252 				pin_name, ret);
253 				return ret;
254 			}
255 			snd_soc_dapm_sync(dapm);
256 			break;
257 		case SNDRV_PCM_TRIGGER_STOP:
258 		case SNDRV_PCM_TRIGGER_SUSPEND:
259 		case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
260 			ret = snd_soc_dapm_disable_pin(dapm, pin_name);
261 			if (ret) {
262 				dev_err(rtd->dev, "failed to disable %s: %d\n",
263 				pin_name, ret);
264 				return ret;
265 			}
266 			snd_soc_dapm_sync(dapm);
267 			break;
268 		}
269 	}
270 
271 	return 0;
272 }
273 
274 static struct snd_soc_ops kabylake_ssp0_ops = {
275 	.hw_params = kabylake_ssp0_hw_params,
276 	.trigger = kabylake_ssp0_trigger,
277 };
278 
279 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
280 			struct snd_pcm_hw_params *params)
281 {
282 	struct snd_interval *rate = hw_param_interval(params,
283 			SNDRV_PCM_HW_PARAM_RATE);
284 	struct snd_interval *chan = hw_param_interval(params,
285 			SNDRV_PCM_HW_PARAM_CHANNELS);
286 	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
287 	struct snd_soc_dpcm *dpcm, *rtd_dpcm = NULL;
288 
289 	/*
290 	 * The following loop will be called only for playback stream
291 	 * In this platform, there is only one playback device on every SSP
292 	 */
293 	for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
294 		rtd_dpcm = dpcm;
295 		break;
296 	}
297 
298 	/*
299 	 * This following loop will be called only for capture stream
300 	 * In this platform, there is only one capture device on every SSP
301 	 */
302 	for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
303 		rtd_dpcm = dpcm;
304 		break;
305 	}
306 
307 	if (!rtd_dpcm)
308 		return -EINVAL;
309 
310 	/*
311 	 * The above 2 loops are mutually exclusive based on the stream direction,
312 	 * thus rtd_dpcm variable will never be overwritten
313 	 */
314 	/*
315 	 * Topology for kblda7219m98373 & kblmax98373 supports only S24_LE,
316 	 * where as kblda7219m98927 & kblmax98927 supports S16_LE by default.
317 	 * Skipping the port wise FE and BE configuration for kblda7219m98373 &
318 	 * kblmax98373 as the topology (FE & BE) supports S24_LE only.
319 	 */
320 
321 	if (!strcmp(rtd->card->name, "kblda7219m98373") ||
322 		!strcmp(rtd->card->name, "kblmax98373")) {
323 		/* The ADSP will convert the FE rate to 48k, stereo */
324 		rate->min = rate->max = 48000;
325 		chan->min = chan->max = DUAL_CHANNEL;
326 
327 		/* set SSP to 24 bit */
328 		snd_mask_none(fmt);
329 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
330 		return 0;
331 	}
332 
333 	/*
334 	 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
335 	 */
336 	if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
337 	    !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
338 	    !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
339 		rate->min = rate->max = 48000;
340 		chan->min = chan->max = 2;
341 		snd_mask_none(fmt);
342 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
343 	}
344 
345 	/*
346 	 * The speaker on the SSP0 supports S16_LE and not S24_LE.
347 	 * thus changing the mask here
348 	 */
349 	if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
350 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
351 
352 	return 0;
353 }
354 
355 static int kabylake_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
356 {
357 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
358 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
359 	struct snd_soc_jack *jack;
360 	struct snd_soc_card *card = rtd->card;
361 	int ret;
362 
363 
364 	ret = snd_soc_dapm_add_routes(&card->dapm,
365 			kabylake_ssp1_map,
366 			ARRAY_SIZE(kabylake_ssp1_map));
367 
368 	if (ret)
369 		return ret;
370 
371 	/*
372 	 * Headset buttons map to the google Reference headset.
373 	 * These can be configured by userspace.
374 	 */
375 	ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
376 			SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
377 			SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
378 			&ctx->kabylake_headset, NULL, 0);
379 	if (ret) {
380 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
381 		return ret;
382 	}
383 
384 	jack = &ctx->kabylake_headset;
385 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
386 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
387 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
388 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
389 
390 	da7219_aad_jack_det(component, &ctx->kabylake_headset);
391 
392 	return 0;
393 }
394 
395 static int kabylake_dmic_init(struct snd_soc_pcm_runtime *rtd)
396 {
397 	int ret;
398 	ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
399 	if (ret)
400 		dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret);
401 
402 	return ret;
403 }
404 
405 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
406 {
407 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
408 	struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
409 	struct kbl_hdmi_pcm *pcm;
410 
411 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
412 	if (!pcm)
413 		return -ENOMEM;
414 
415 	pcm->device = device;
416 	pcm->codec_dai = dai;
417 
418 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
419 
420 	return 0;
421 }
422 
423 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
424 {
425 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
426 }
427 
428 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
429 {
430 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
431 }
432 
433 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
434 {
435 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
436 }
437 
438 static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
439 {
440 	struct snd_soc_dapm_context *dapm;
441 	struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
442 
443 	dapm = snd_soc_component_get_dapm(component);
444 	snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
445 
446 	return 0;
447 }
448 
449 static const unsigned int rates[] = {
450 	48000,
451 };
452 
453 static const struct snd_pcm_hw_constraint_list constraints_rates = {
454 	.count = ARRAY_SIZE(rates),
455 	.list  = rates,
456 	.mask = 0,
457 };
458 
459 static const unsigned int channels[] = {
460 	DUAL_CHANNEL,
461 };
462 
463 static const struct snd_pcm_hw_constraint_list constraints_channels = {
464 	.count = ARRAY_SIZE(channels),
465 	.list = channels,
466 	.mask = 0,
467 };
468 
469 static unsigned int channels_quad[] = {
470 	QUAD_CHANNEL,
471 };
472 
473 static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
474 	.count = ARRAY_SIZE(channels_quad),
475 	.list = channels_quad,
476 	.mask = 0,
477 };
478 
479 static int kbl_fe_startup(struct snd_pcm_substream *substream)
480 {
481 	struct snd_pcm_runtime *runtime = substream->runtime;
482 	struct snd_soc_pcm_runtime *soc_rt = asoc_substream_to_rtd(substream);
483 
484 	/*
485 	 * On this platform for PCM device we support,
486 	 * 48Khz
487 	 * stereo
488 	 */
489 
490 	runtime->hw.channels_max = DUAL_CHANNEL;
491 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
492 					   &constraints_channels);
493 	/*
494 	 * Setup S24_LE (32 bit container and 24 bit valid data) for
495 	 * kblda7219m98373 & kblmax98373. For kblda7219m98927 &
496 	 * kblmax98927 keeping it as 16/16 due to topology FW dependency.
497 	 */
498 	if (!strcmp(soc_rt->card->name, "kblda7219m98373") ||
499 		!strcmp(soc_rt->card->name, "kblmax98373")) {
500 		runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_LE;
501 		snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
502 
503 	} else {
504 		runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
505 		snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
506 	}
507 
508 	snd_pcm_hw_constraint_list(runtime, 0,
509 				SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
510 
511 	return 0;
512 }
513 
514 static const struct snd_soc_ops kabylake_da7219_fe_ops = {
515 	.startup = kbl_fe_startup,
516 };
517 
518 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
519 		struct snd_pcm_hw_params *params)
520 {
521 	struct snd_interval *chan = hw_param_interval(params,
522 				SNDRV_PCM_HW_PARAM_CHANNELS);
523 
524 	/*
525 	 * set BE channel constraint as user FE channels
526 	 */
527 
528 	if (params_channels(params) == 2)
529 		chan->min = chan->max = 2;
530 	else
531 		chan->min = chan->max = 4;
532 
533 	return 0;
534 }
535 
536 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
537 {
538 	struct snd_pcm_runtime *runtime = substream->runtime;
539 	struct snd_soc_pcm_runtime *soc_rt = asoc_substream_to_rtd(substream);
540 
541 	runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
542 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
543 			&constraints_channels_quad);
544 
545 	/*
546 	 * Topology for kblda7219m98373 & kblmax98373 supports only S24_LE.
547 	 * The DMIC also configured for S24_LE. Forcing the DMIC format to
548 	 * S24_LE due to the topology FW dependency.
549 	 */
550 	if (!strcmp(soc_rt->card->name, "kblda7219m98373") ||
551 		!strcmp(soc_rt->card->name, "kblmax98373")) {
552 		runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_LE;
553 		snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
554 	}
555 
556 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
557 			SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
558 }
559 
560 static struct snd_soc_ops kabylake_dmic_ops = {
561 	.startup = kabylake_dmic_startup,
562 };
563 
564 static const unsigned int rates_16000[] = {
565 	16000,
566 };
567 
568 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
569 	.count = ARRAY_SIZE(rates_16000),
570 	.list  = rates_16000,
571 };
572 
573 static const unsigned int ch_mono[] = {
574 	1,
575 };
576 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
577 	.count = ARRAY_SIZE(ch_mono),
578 	.list  = ch_mono,
579 };
580 
581 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
582 {
583 	substream->runtime->hw.channels_max = 1;
584 	snd_pcm_hw_constraint_list(substream->runtime, 0,
585 					SNDRV_PCM_HW_PARAM_CHANNELS,
586 					&constraints_refcap);
587 
588 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
589 				SNDRV_PCM_HW_PARAM_RATE,
590 				&constraints_16000);
591 }
592 
593 
594 static struct snd_soc_ops skylake_refcap_ops = {
595 	.startup = kabylake_refcap_startup,
596 };
597 
598 static struct snd_soc_codec_conf max98927_codec_conf[] = {
599 
600 	{
601 		.dlc = COMP_CODEC_CONF(MAX98927_DEV0_NAME),
602 		.name_prefix = "Right",
603 	},
604 
605 	{
606 		.dlc = COMP_CODEC_CONF(MAX98927_DEV1_NAME),
607 		.name_prefix = "Left",
608 	},
609 };
610 
611 static struct snd_soc_codec_conf max98373_codec_conf[] = {
612 
613 	{
614 		.dlc = COMP_CODEC_CONF(MAX98373_DEV0_NAME),
615 		.name_prefix = "Right",
616 	},
617 
618 	{
619 		.dlc = COMP_CODEC_CONF(MAX98373_DEV1_NAME),
620 		.name_prefix = "Left",
621 	},
622 };
623 
624 static struct snd_soc_dai_link_component max98373_ssp0_codec_components[] = {
625 	{ /* Left */
626 		.name = MAX98373_DEV0_NAME,
627 		.dai_name = MAX98373_CODEC_DAI,
628 	},
629 
630 	{  /* For Right */
631 		.name = MAX98373_DEV1_NAME,
632 		.dai_name = MAX98373_CODEC_DAI,
633 	},
634 
635 };
636 
637 SND_SOC_DAILINK_DEF(dummy,
638 	DAILINK_COMP_ARRAY(COMP_DUMMY()));
639 
640 SND_SOC_DAILINK_DEF(system,
641 	DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
642 
643 SND_SOC_DAILINK_DEF(echoref,
644 	DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
645 
646 SND_SOC_DAILINK_DEF(reference,
647 	DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
648 
649 SND_SOC_DAILINK_DEF(dmic,
650 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
651 
652 SND_SOC_DAILINK_DEF(hdmi1,
653 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
654 
655 SND_SOC_DAILINK_DEF(hdmi2,
656 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
657 
658 SND_SOC_DAILINK_DEF(hdmi3,
659 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
660 
661 SND_SOC_DAILINK_DEF(system2,
662 	DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
663 
664 SND_SOC_DAILINK_DEF(ssp0_pin,
665 	DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
666 SND_SOC_DAILINK_DEF(ssp0_codec,
667 	DAILINK_COMP_ARRAY(
668 	/* Left */	COMP_CODEC(MAX98927_DEV0_NAME, MAX98927_CODEC_DAI),
669 	/* For Right */	COMP_CODEC(MAX98927_DEV1_NAME, MAX98927_CODEC_DAI)));
670 
671 SND_SOC_DAILINK_DEF(ssp1_pin,
672 	DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
673 SND_SOC_DAILINK_DEF(ssp1_codec,
674 	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00",
675 				      KBL_DIALOG_CODEC_DAI)));
676 
677 SND_SOC_DAILINK_DEF(dmic_pin,
678 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
679 SND_SOC_DAILINK_DEF(dmic_codec,
680 	DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
681 
682 SND_SOC_DAILINK_DEF(idisp1_pin,
683 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
684 SND_SOC_DAILINK_DEF(idisp1_codec,
685 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
686 
687 SND_SOC_DAILINK_DEF(idisp2_pin,
688 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
689 SND_SOC_DAILINK_DEF(idisp2_codec,
690 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
691 
692 SND_SOC_DAILINK_DEF(idisp3_pin,
693 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
694 SND_SOC_DAILINK_DEF(idisp3_codec,
695 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
696 
697 SND_SOC_DAILINK_DEF(platform,
698 	DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
699 
700 /* kabylake digital audio interface glue - connects codec <--> CPU */
701 static struct snd_soc_dai_link kabylake_dais[] = {
702 	/* Front End DAI links */
703 	[KBL_DPCM_AUDIO_PB] = {
704 		.name = "Kbl Audio Port",
705 		.stream_name = "Audio",
706 		.dynamic = 1,
707 		.nonatomic = 1,
708 		.init = kabylake_da7219_fe_init,
709 		.trigger = {
710 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
711 		.dpcm_playback = 1,
712 		.ops = &kabylake_da7219_fe_ops,
713 		SND_SOC_DAILINK_REG(system, dummy, platform),
714 	},
715 	[KBL_DPCM_AUDIO_ECHO_REF_CP] = {
716 		.name = "Kbl Audio Echo Reference cap",
717 		.stream_name = "Echoreference Capture",
718 		.init = NULL,
719 		.dpcm_capture = 1,
720 		.nonatomic = 1,
721 		SND_SOC_DAILINK_REG(echoref, dummy, platform),
722 	},
723 	[KBL_DPCM_AUDIO_REF_CP] = {
724 		.name = "Kbl Audio Reference cap",
725 		.stream_name = "Wake on Voice",
726 		.init = NULL,
727 		.dpcm_capture = 1,
728 		.nonatomic = 1,
729 		.dynamic = 1,
730 		.ops = &skylake_refcap_ops,
731 		SND_SOC_DAILINK_REG(reference, dummy, platform),
732 	},
733 	[KBL_DPCM_AUDIO_DMIC_CP] = {
734 		.name = "Kbl Audio DMIC cap",
735 		.stream_name = "dmiccap",
736 		.init = NULL,
737 		.dpcm_capture = 1,
738 		.nonatomic = 1,
739 		.dynamic = 1,
740 		.ops = &kabylake_dmic_ops,
741 		SND_SOC_DAILINK_REG(dmic, dummy, platform),
742 	},
743 	[KBL_DPCM_AUDIO_HDMI1_PB] = {
744 		.name = "Kbl HDMI Port1",
745 		.stream_name = "Hdmi1",
746 		.dpcm_playback = 1,
747 		.init = NULL,
748 		.trigger = {
749 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
750 		.nonatomic = 1,
751 		.dynamic = 1,
752 		SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
753 	},
754 	[KBL_DPCM_AUDIO_HDMI2_PB] = {
755 		.name = "Kbl HDMI Port2",
756 		.stream_name = "Hdmi2",
757 		.dpcm_playback = 1,
758 		.init = NULL,
759 		.trigger = {
760 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
761 		.nonatomic = 1,
762 		.dynamic = 1,
763 		SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
764 	},
765 	[KBL_DPCM_AUDIO_HDMI3_PB] = {
766 		.name = "Kbl HDMI Port3",
767 		.stream_name = "Hdmi3",
768 		.trigger = {
769 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
770 		.dpcm_playback = 1,
771 		.init = NULL,
772 		.nonatomic = 1,
773 		.dynamic = 1,
774 		SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
775 	},
776 	[KBL_DPCM_AUDIO_HS_PB] = {
777 		.name = "Kbl Audio Headset Playback",
778 		.stream_name = "Headset Audio",
779 		.dpcm_playback = 1,
780 		.nonatomic = 1,
781 		.dynamic = 1,
782 		.init = kabylake_da7219_fe_init,
783 		.trigger = {
784 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
785 		.ops = &kabylake_da7219_fe_ops,
786 		SND_SOC_DAILINK_REG(system2, dummy, platform),
787 	},
788 	[KBL_DPCM_AUDIO_CP] = {
789 		.name = "Kbl Audio Capture Port",
790 		.stream_name = "Audio Record",
791 		.dynamic = 1,
792 		.nonatomic = 1,
793 		.trigger = {
794 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
795 		.dpcm_capture = 1,
796 		.ops = &kabylake_da7219_fe_ops,
797 		SND_SOC_DAILINK_REG(system, dummy, platform),
798 	},
799 
800 	/* Back End DAI links */
801 	{
802 		/* SSP0 - Codec */
803 		.name = "SSP0-Codec",
804 		.id = 0,
805 		.no_pcm = 1,
806 		.dai_fmt = SND_SOC_DAIFMT_DSP_B |
807 			SND_SOC_DAIFMT_NB_NF |
808 			SND_SOC_DAIFMT_CBS_CFS,
809 		.dpcm_playback = 1,
810 		.dpcm_capture = 1,
811 		.ignore_pmdown_time = 1,
812 		.be_hw_params_fixup = kabylake_ssp_fixup,
813 		.ops = &kabylake_ssp0_ops,
814 		SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
815 	},
816 	{
817 		/* SSP1 - Codec */
818 		.name = "SSP1-Codec",
819 		.id = 1,
820 		.no_pcm = 1,
821 		.init = kabylake_da7219_codec_init,
822 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
823 			SND_SOC_DAIFMT_CBS_CFS,
824 		.ignore_pmdown_time = 1,
825 		.be_hw_params_fixup = kabylake_ssp_fixup,
826 		.dpcm_playback = 1,
827 		.dpcm_capture = 1,
828 		SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
829 	},
830 	{
831 		.name = "dmic01",
832 		.id = 2,
833 		.init = kabylake_dmic_init,
834 		.be_hw_params_fixup = kabylake_dmic_fixup,
835 		.ignore_suspend = 1,
836 		.dpcm_capture = 1,
837 		.no_pcm = 1,
838 		SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
839 	},
840 	{
841 		.name = "iDisp1",
842 		.id = 3,
843 		.dpcm_playback = 1,
844 		.init = kabylake_hdmi1_init,
845 		.no_pcm = 1,
846 		SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
847 	},
848 	{
849 		.name = "iDisp2",
850 		.id = 4,
851 		.init = kabylake_hdmi2_init,
852 		.dpcm_playback = 1,
853 		.no_pcm = 1,
854 		SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
855 	},
856 	{
857 		.name = "iDisp3",
858 		.id = 5,
859 		.init = kabylake_hdmi3_init,
860 		.dpcm_playback = 1,
861 		.no_pcm = 1,
862 		SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
863 	},
864 };
865 
866 /* kabylake digital audio interface glue - connects codec <--> CPU */
867 static struct snd_soc_dai_link kabylake_max98_927_373_dais[] = {
868 	/* Front End DAI links */
869 	[KBL_DPCM_AUDIO_PB] = {
870 		.name = "Kbl Audio Port",
871 		.stream_name = "Audio",
872 		.dynamic = 1,
873 		.nonatomic = 1,
874 		.init = kabylake_da7219_fe_init,
875 		.trigger = {
876 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
877 		.dpcm_playback = 1,
878 		.ops = &kabylake_da7219_fe_ops,
879 		SND_SOC_DAILINK_REG(system, dummy, platform),
880 	},
881 	[KBL_DPCM_AUDIO_ECHO_REF_CP] = {
882 		.name = "Kbl Audio Echo Reference cap",
883 		.stream_name = "Echoreference Capture",
884 		.init = NULL,
885 		.dpcm_capture = 1,
886 		.nonatomic = 1,
887 		SND_SOC_DAILINK_REG(echoref, dummy, platform),
888 	},
889 	[KBL_DPCM_AUDIO_REF_CP] = {
890 		.name = "Kbl Audio Reference cap",
891 		.stream_name = "Wake on Voice",
892 		.init = NULL,
893 		.dpcm_capture = 1,
894 		.nonatomic = 1,
895 		.dynamic = 1,
896 		.ops = &skylake_refcap_ops,
897 		SND_SOC_DAILINK_REG(reference, dummy, platform),
898 	},
899 	[KBL_DPCM_AUDIO_DMIC_CP] = {
900 		.name = "Kbl Audio DMIC cap",
901 		.stream_name = "dmiccap",
902 		.init = NULL,
903 		.dpcm_capture = 1,
904 		.nonatomic = 1,
905 		.dynamic = 1,
906 		.ops = &kabylake_dmic_ops,
907 		SND_SOC_DAILINK_REG(dmic, dummy, platform),
908 	},
909 	[KBL_DPCM_AUDIO_HDMI1_PB] = {
910 		.name = "Kbl HDMI Port1",
911 		.stream_name = "Hdmi1",
912 		.dpcm_playback = 1,
913 		.init = NULL,
914 		.trigger = {
915 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
916 		.nonatomic = 1,
917 		.dynamic = 1,
918 		SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
919 	},
920 	[KBL_DPCM_AUDIO_HDMI2_PB] = {
921 		.name = "Kbl HDMI Port2",
922 		.stream_name = "Hdmi2",
923 		.dpcm_playback = 1,
924 		.init = NULL,
925 		.trigger = {
926 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
927 		.nonatomic = 1,
928 		.dynamic = 1,
929 		SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
930 	},
931 	[KBL_DPCM_AUDIO_HDMI3_PB] = {
932 		.name = "Kbl HDMI Port3",
933 		.stream_name = "Hdmi3",
934 		.trigger = {
935 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
936 		.dpcm_playback = 1,
937 		.init = NULL,
938 		.nonatomic = 1,
939 		.dynamic = 1,
940 		SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
941 	},
942 
943 	/* Back End DAI links */
944 	{
945 		/* SSP0 - Codec */
946 		.name = "SSP0-Codec",
947 		.id = 0,
948 		.no_pcm = 1,
949 		.dai_fmt = SND_SOC_DAIFMT_DSP_B |
950 			SND_SOC_DAIFMT_NB_NF |
951 			SND_SOC_DAIFMT_CBS_CFS,
952 		.dpcm_playback = 1,
953 		.dpcm_capture = 1,
954 		.ignore_pmdown_time = 1,
955 		.be_hw_params_fixup = kabylake_ssp_fixup,
956 		.ops = &kabylake_ssp0_ops,
957 		SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec),
958 	},
959 	{
960 		.name = "dmic01",
961 		.id = 1,
962 		.init = kabylake_dmic_init,
963 		.be_hw_params_fixup = kabylake_dmic_fixup,
964 		.ignore_suspend = 1,
965 		.dpcm_capture = 1,
966 		.no_pcm = 1,
967 		SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
968 	},
969 	{
970 		.name = "iDisp1",
971 		.id = 2,
972 		.dpcm_playback = 1,
973 		.init = kabylake_hdmi1_init,
974 		.no_pcm = 1,
975 		SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
976 	},
977 	{
978 		.name = "iDisp2",
979 		.id = 3,
980 		.init = kabylake_hdmi2_init,
981 		.dpcm_playback = 1,
982 		.no_pcm = 1,
983 		SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
984 	},
985 	{
986 		.name = "iDisp3",
987 		.id = 4,
988 		.init = kabylake_hdmi3_init,
989 		.dpcm_playback = 1,
990 		.no_pcm = 1,
991 		SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
992 	},
993 };
994 
995 static int kabylake_card_late_probe(struct snd_soc_card *card)
996 {
997 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
998 	struct kbl_hdmi_pcm *pcm;
999 	struct snd_soc_dapm_context *dapm = &card->dapm;
1000 	struct snd_soc_component *component = NULL;
1001 	int err, i = 0;
1002 	char jack_name[NAME_SIZE];
1003 
1004 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
1005 		component = pcm->codec_dai->component;
1006 		snprintf(jack_name, sizeof(jack_name),
1007 			"HDMI/DP, pcm=%d Jack", pcm->device);
1008 		err = snd_soc_card_jack_new(card, jack_name,
1009 					SND_JACK_AVOUT, &kabylake_hdmi[i],
1010 					NULL, 0);
1011 
1012 		if (err)
1013 			return err;
1014 
1015 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
1016 						&kabylake_hdmi[i]);
1017 		if (err < 0)
1018 			return err;
1019 
1020 		i++;
1021 	}
1022 
1023 	if (!component)
1024 		return -EINVAL;
1025 
1026 
1027 	err = hdac_hdmi_jack_port_init(component, &card->dapm);
1028 
1029 	if (err < 0)
1030 		return err;
1031 
1032 	err = snd_soc_dapm_disable_pin(dapm, "Left Spk");
1033 	if (err) {
1034 		dev_err(card->dev, "failed to disable Left Spk: %d\n", err);
1035 		return err;
1036 	}
1037 
1038 	err = snd_soc_dapm_disable_pin(dapm, "Right Spk");
1039 	if (err) {
1040 		dev_err(card->dev, "failed to disable Right Spk: %d\n", err);
1041 		return err;
1042 	}
1043 
1044 	return snd_soc_dapm_sync(dapm);
1045 }
1046 
1047 /* kabylake audio machine driver for SPT + DA7219 */
1048 static struct snd_soc_card kbl_audio_card_da7219_m98927 = {
1049 	.name = "kblda7219m98927",
1050 	.owner = THIS_MODULE,
1051 	.dai_link = kabylake_dais,
1052 	.num_links = ARRAY_SIZE(kabylake_dais),
1053 	.controls = kabylake_controls,
1054 	.num_controls = ARRAY_SIZE(kabylake_controls),
1055 	.dapm_widgets = kabylake_widgets,
1056 	.num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1057 	.dapm_routes = kabylake_map,
1058 	.num_dapm_routes = ARRAY_SIZE(kabylake_map),
1059 	.codec_conf = max98927_codec_conf,
1060 	.num_configs = ARRAY_SIZE(max98927_codec_conf),
1061 	.fully_routed = true,
1062 	.late_probe = kabylake_card_late_probe,
1063 };
1064 
1065 /* kabylake audio machine driver for Maxim98927 */
1066 static struct snd_soc_card kbl_audio_card_max98927 = {
1067 	.name = "kblmax98927",
1068 	.owner = THIS_MODULE,
1069 	.dai_link = kabylake_max98_927_373_dais,
1070 	.num_links = ARRAY_SIZE(kabylake_max98_927_373_dais),
1071 	.controls = kabylake_controls,
1072 	.num_controls = ARRAY_SIZE(kabylake_controls),
1073 	.dapm_widgets = kabylake_widgets,
1074 	.num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1075 	.dapm_routes = kabylake_map,
1076 	.num_dapm_routes = ARRAY_SIZE(kabylake_map),
1077 	.codec_conf = max98927_codec_conf,
1078 	.num_configs = ARRAY_SIZE(max98927_codec_conf),
1079 	.fully_routed = true,
1080 	.late_probe = kabylake_card_late_probe,
1081 };
1082 
1083 static struct snd_soc_card kbl_audio_card_da7219_m98373 = {
1084 	.name = "kblda7219m98373",
1085 	.owner = THIS_MODULE,
1086 	.dai_link = kabylake_dais,
1087 	.num_links = ARRAY_SIZE(kabylake_dais),
1088 	.controls = kabylake_controls,
1089 	.num_controls = ARRAY_SIZE(kabylake_controls),
1090 	.dapm_widgets = kabylake_widgets,
1091 	.num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1092 	.dapm_routes = kabylake_map,
1093 	.num_dapm_routes = ARRAY_SIZE(kabylake_map),
1094 	.codec_conf = max98373_codec_conf,
1095 	.num_configs = ARRAY_SIZE(max98373_codec_conf),
1096 	.fully_routed = true,
1097 	.late_probe = kabylake_card_late_probe,
1098 };
1099 
1100 static struct snd_soc_card kbl_audio_card_max98373 = {
1101 	.name = "kblmax98373",
1102 	.owner = THIS_MODULE,
1103 	.dai_link = kabylake_max98_927_373_dais,
1104 	.num_links = ARRAY_SIZE(kabylake_max98_927_373_dais),
1105 	.controls = kabylake_controls,
1106 	.num_controls = ARRAY_SIZE(kabylake_controls),
1107 	.dapm_widgets = kabylake_widgets,
1108 	.num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1109 	.dapm_routes = kabylake_map,
1110 	.num_dapm_routes = ARRAY_SIZE(kabylake_map),
1111 	.codec_conf = max98373_codec_conf,
1112 	.num_configs = ARRAY_SIZE(max98373_codec_conf),
1113 	.fully_routed = true,
1114 	.late_probe = kabylake_card_late_probe,
1115 };
1116 
1117 static int kabylake_audio_probe(struct platform_device *pdev)
1118 {
1119 	struct kbl_codec_private *ctx;
1120 	struct snd_soc_dai_link *kbl_dai_link;
1121 	struct snd_soc_dai_link_component **codecs;
1122 	int i;
1123 
1124 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1125 	if (!ctx)
1126 		return -ENOMEM;
1127 
1128 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
1129 
1130 	kabylake_audio_card =
1131 		(struct snd_soc_card *)pdev->id_entry->driver_data;
1132 
1133 	kbl_dai_link = kabylake_audio_card->dai_link;
1134 
1135 	/* Update codecs for SSP0 with max98373 codec info */
1136 	if (!strcmp(pdev->name, "kbl_da7219_max98373") ||
1137 		(!strcmp(pdev->name, "kbl_max98373"))) {
1138 		for (i = 0; i < kabylake_audio_card->num_links; ++i) {
1139 			if (strcmp(kbl_dai_link[i].name, "SSP0-Codec"))
1140 				continue;
1141 
1142 			codecs = &(kbl_dai_link[i].codecs);
1143 			*codecs = max98373_ssp0_codec_components;
1144 			kbl_dai_link[i].num_codecs =
1145 				ARRAY_SIZE(max98373_ssp0_codec_components);
1146 			break;
1147 		}
1148 	}
1149 	kabylake_audio_card->dev = &pdev->dev;
1150 	snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
1151 
1152 	return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
1153 }
1154 
1155 static const struct platform_device_id kbl_board_ids[] = {
1156 	{
1157 		.name = "kbl_da7219_max98927",
1158 		.driver_data =
1159 			(kernel_ulong_t)&kbl_audio_card_da7219_m98927,
1160 	},
1161 	{
1162 		.name = "kbl_max98927",
1163 		.driver_data =
1164 			(kernel_ulong_t)&kbl_audio_card_max98927,
1165 	},
1166 	{
1167 		.name = "kbl_da7219_max98373",
1168 		.driver_data =
1169 			(kernel_ulong_t)&kbl_audio_card_da7219_m98373,
1170 	},
1171 	{
1172 		.name = "kbl_max98373",
1173 		.driver_data =
1174 			(kernel_ulong_t)&kbl_audio_card_max98373,
1175 	},
1176 	{ }
1177 };
1178 
1179 static struct platform_driver kabylake_audio = {
1180 	.probe = kabylake_audio_probe,
1181 	.driver = {
1182 		.name = "kbl_da7219_max98_927_373",
1183 		.pm = &snd_soc_pm_ops,
1184 	},
1185 	.id_table = kbl_board_ids,
1186 };
1187 
1188 module_platform_driver(kabylake_audio)
1189 
1190 /* Module information */
1191 MODULE_DESCRIPTION("Audio KabyLake Machine driver for MAX98927/MAX98373 & DA7219");
1192 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
1193 MODULE_LICENSE("GPL v2");
1194 MODULE_ALIAS("platform:kbl_da7219_max98927");
1195 MODULE_ALIAS("platform:kbl_max98927");
1196 MODULE_ALIAS("platform:kbl_da7219_max98373");
1197 MODULE_ALIAS("platform:kbl_max98373");
1198