1 /*
2  * Intel Kabylake I2S Machine Driver with MAXIM98927
3  * and RT5663 Codecs
4  *
5  * Copyright (C) 2017, Intel Corporation. All rights reserved.
6  *
7  * Modified from:
8  *   Intel Skylake I2S Machine driver
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License version
12  * 2 as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  */
19 
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <sound/core.h>
23 #include <sound/jack.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
27 #include "../../codecs/rt5663.h"
28 #include "../../codecs/hdac_hdmi.h"
29 #include "../skylake/skl.h"
30 
31 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
32 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
33 #define DMIC_CH(p) p->list[p->count-1]
34 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
35 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
36 
37 static struct snd_soc_card *kabylake_audio_card;
38 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
39 static struct snd_soc_jack skylake_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_rt5663_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_CP,
55 	KBL_DPCM_AUDIO_HS_PB,
56 	KBL_DPCM_AUDIO_ECHO_REF_CP,
57 	KBL_DPCM_AUDIO_REF_CP,
58 	KBL_DPCM_AUDIO_DMIC_CP,
59 	KBL_DPCM_AUDIO_HDMI1_PB,
60 	KBL_DPCM_AUDIO_HDMI2_PB,
61 	KBL_DPCM_AUDIO_HDMI3_PB,
62 };
63 
64 static const struct snd_kcontrol_new kabylake_controls[] = {
65 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
66 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
67 	SOC_DAPM_PIN_SWITCH("Left Spk"),
68 	SOC_DAPM_PIN_SWITCH("Right Spk"),
69 };
70 
71 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
72 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
73 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
74 	SND_SOC_DAPM_SPK("Left Spk", NULL),
75 	SND_SOC_DAPM_SPK("Right Spk", NULL),
76 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
77 	SND_SOC_DAPM_SPK("HDMI1", NULL),
78 	SND_SOC_DAPM_SPK("HDMI2", NULL),
79 	SND_SOC_DAPM_SPK("HDMI3", NULL),
80 
81 };
82 
83 static const struct snd_soc_dapm_route kabylake_map[] = {
84 	/* HP jack connectors - unknown if we have jack detection */
85 	{ "Headphone Jack", NULL, "HPOL" },
86 	{ "Headphone Jack", NULL, "HPOR" },
87 
88 	/* speaker */
89 	{ "Left Spk", NULL, "Left BE_OUT" },
90 	{ "Right Spk", NULL, "Right BE_OUT" },
91 
92 	/* other jacks */
93 	{ "IN1P", NULL, "Headset Mic" },
94 	{ "IN1N", NULL, "Headset Mic" },
95 	{ "DMic", NULL, "SoC DMIC" },
96 
97 	/* CODEC BE connections */
98 	{ "Left HiFi Playback", NULL, "ssp0 Tx" },
99 	{ "Right HiFi Playback", NULL, "ssp0 Tx" },
100 	{ "ssp0 Tx", NULL, "spk_out" },
101 
102 	{ "AIF Playback", NULL, "ssp1 Tx" },
103 	{ "ssp1 Tx", NULL, "hs_out" },
104 
105 	{ "hs_in", NULL, "ssp1 Rx" },
106 	{ "ssp1 Rx", NULL, "AIF Capture" },
107 
108 	/* DMIC */
109 	{ "dmic01_hifi", NULL, "DMIC01 Rx" },
110 	{ "DMIC01 Rx", NULL, "DMIC AIF" },
111 
112 	{ "hifi3", NULL, "iDisp3 Tx"},
113 	{ "iDisp3 Tx", NULL, "iDisp3_out"},
114 	{ "hifi2", NULL, "iDisp2 Tx"},
115 	{ "iDisp2 Tx", NULL, "iDisp2_out"},
116 	{ "hifi1", NULL, "iDisp1 Tx"},
117 	{ "iDisp1 Tx", NULL, "iDisp1_out"},
118 };
119 
120 enum {
121 	KBL_DPCM_AUDIO_5663_PB = 0,
122 	KBL_DPCM_AUDIO_5663_CP,
123 	KBL_DPCM_AUDIO_5663_HDMI1_PB,
124 	KBL_DPCM_AUDIO_5663_HDMI2_PB,
125 };
126 
127 static const struct snd_kcontrol_new kabylake_5663_controls[] = {
128 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
129 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
130 };
131 
132 static const struct snd_soc_dapm_widget kabylake_5663_widgets[] = {
133 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
134 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
135 	SND_SOC_DAPM_SPK("DP", NULL),
136 	SND_SOC_DAPM_SPK("HDMI", NULL),
137 };
138 
139 static const struct snd_soc_dapm_route kabylake_5663_map[] = {
140 	{ "Headphone Jack", NULL, "HPOL" },
141 	{ "Headphone Jack", NULL, "HPOR" },
142 
143 	/* other jacks */
144 	{ "IN1P", NULL, "Headset Mic" },
145 	{ "IN1N", NULL, "Headset Mic" },
146 
147 	{ "HDMI", NULL, "hif5 Output" },
148 	{ "DP", NULL, "hif6 Output" },
149 
150 	/* CODEC BE connections */
151 	{ "AIF Playback", NULL, "ssp1 Tx" },
152 	{ "ssp1 Tx", NULL, "codec1_out" },
153 
154 	{ "codec0_in", NULL, "ssp1 Rx" },
155 	{ "ssp1 Rx", NULL, "AIF Capture" },
156 
157 	{ "hifi2", NULL, "iDisp2 Tx"},
158 	{ "iDisp2 Tx", NULL, "iDisp2_out"},
159 	{ "hifi1", NULL, "iDisp1 Tx"},
160 	{ "iDisp1 Tx", NULL, "iDisp1_out"},
161 };
162 
163 static struct snd_soc_codec_conf max98927_codec_conf[] = {
164 	{
165 		.dev_name = MAXIM_DEV0_NAME,
166 		.name_prefix = "Right",
167 	},
168 	{
169 		.dev_name = MAXIM_DEV1_NAME,
170 		.name_prefix = "Left",
171 	},
172 };
173 
174 static struct snd_soc_dai_link_component max98927_codec_components[] = {
175 	{ /* Left */
176 		.name = MAXIM_DEV0_NAME,
177 		.dai_name = KBL_MAXIM_CODEC_DAI,
178 	},
179 	{ /* Right */
180 		.name = MAXIM_DEV1_NAME,
181 		.dai_name = KBL_MAXIM_CODEC_DAI,
182 	},
183 };
184 
185 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
186 {
187 	int ret;
188 	struct snd_soc_dapm_context *dapm;
189 	struct snd_soc_component *component = rtd->cpu_dai->component;
190 
191 	dapm = snd_soc_component_get_dapm(component);
192 	ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
193 	if (ret) {
194 		dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
195 		return ret;
196 	}
197 
198 	return ret;
199 }
200 
201 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
202 {
203 	int ret;
204 	struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
205 	struct snd_soc_codec *codec = rtd->codec;
206 
207 	/*
208 	 * Headset buttons map to the google Reference headset.
209 	 * These can be configured by userspace.
210 	 */
211 	ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
212 			SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
213 			SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
214 			NULL, 0);
215 	if (ret) {
216 		dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
217 		return ret;
218 	}
219 	rt5663_set_jack_detect(codec, &ctx->kabylake_headset);
220 	return ret;
221 }
222 
223 static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime *rtd)
224 {
225 	int ret;
226 
227 	ret = kabylake_rt5663_codec_init(rtd);
228 	if (ret)
229 		return ret;
230 
231 	ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
232 	if (ret) {
233 		dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret);
234 		return ret;
235 	}
236 
237 	return ret;
238 }
239 
240 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
241 {
242 	struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
243 	struct snd_soc_dai *dai = rtd->codec_dai;
244 	struct kbl_hdmi_pcm *pcm;
245 
246 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
247 	if (!pcm)
248 		return -ENOMEM;
249 
250 	pcm->device = device;
251 	pcm->codec_dai = dai;
252 
253 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
254 
255 	return 0;
256 }
257 
258 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
259 {
260 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
261 }
262 
263 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
264 {
265 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
266 }
267 
268 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
269 {
270 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
271 }
272 
273 static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
274 {
275 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI1_PB);
276 }
277 
278 static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
279 {
280 	return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB);
281 }
282 
283 static unsigned int rates[] = {
284 	48000,
285 };
286 
287 static const struct snd_pcm_hw_constraint_list constraints_rates = {
288 	.count = ARRAY_SIZE(rates),
289 	.list  = rates,
290 	.mask = 0,
291 };
292 
293 static unsigned int channels[] = {
294 	2,
295 };
296 
297 static const struct snd_pcm_hw_constraint_list constraints_channels = {
298 	.count = ARRAY_SIZE(channels),
299 	.list = channels,
300 	.mask = 0,
301 };
302 
303 static int kbl_fe_startup(struct snd_pcm_substream *substream)
304 {
305 	struct snd_pcm_runtime *runtime = substream->runtime;
306 
307 	/*
308 	 * On this platform for PCM device we support,
309 	 * 48Khz
310 	 * stereo
311 	 * 16 bit audio
312 	 */
313 
314 	runtime->hw.channels_max = 2;
315 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
316 					   &constraints_channels);
317 
318 	runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
319 	snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
320 
321 	snd_pcm_hw_constraint_list(runtime, 0,
322 				SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
323 
324 	return 0;
325 }
326 
327 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
328 	.startup = kbl_fe_startup,
329 };
330 
331 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
332 	struct snd_pcm_hw_params *params)
333 {
334 	struct snd_interval *rate = hw_param_interval(params,
335 			SNDRV_PCM_HW_PARAM_RATE);
336 	struct snd_interval *channels = hw_param_interval(params,
337 			SNDRV_PCM_HW_PARAM_CHANNELS);
338 	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
339 
340 	/* The ADSP will convert the FE rate to 48k, stereo */
341 	rate->min = rate->max = 48000;
342 	channels->min = channels->max = 2;
343 	/* set SSP1 to 24 bit */
344 	snd_mask_none(fmt);
345 	snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
346 
347 	return 0;
348 }
349 
350 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
351 	struct snd_pcm_hw_params *params)
352 {
353 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
354 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
355 	int ret;
356 
357 	/* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
358 	rt5663_sel_asrc_clk_src(codec_dai->codec,
359 			RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
360 			RT5663_CLK_SEL_I2S1_ASRC);
361 
362 	ret = snd_soc_dai_set_sysclk(codec_dai,
363 			RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
364 	if (ret < 0)
365 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
366 
367 	return ret;
368 }
369 
370 static struct snd_soc_ops kabylake_rt5663_ops = {
371 	.hw_params = kabylake_rt5663_hw_params,
372 };
373 
374 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
375 		struct snd_pcm_hw_params *params)
376 {
377 	struct snd_interval *channels = hw_param_interval(params,
378 				SNDRV_PCM_HW_PARAM_CHANNELS);
379 
380 	if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
381 		channels->min = channels->max = 2;
382 	else
383 		channels->min = channels->max = 4;
384 
385 	return 0;
386 }
387 
388 static unsigned int channels_dmic[] = {
389 	2, 4,
390 };
391 
392 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
393 	.count = ARRAY_SIZE(channels_dmic),
394 	.list = channels_dmic,
395 	.mask = 0,
396 };
397 
398 static const unsigned int dmic_2ch[] = {
399 	2,
400 };
401 
402 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
403 	.count = ARRAY_SIZE(dmic_2ch),
404 	.list = dmic_2ch,
405 	.mask = 0,
406 };
407 
408 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
409 {
410 	struct snd_pcm_runtime *runtime = substream->runtime;
411 
412 	runtime->hw.channels_max = DMIC_CH(dmic_constraints);
413 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
414 			dmic_constraints);
415 
416 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
417 			SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
418 }
419 
420 static struct snd_soc_ops kabylake_dmic_ops = {
421 	.startup = kabylake_dmic_startup,
422 };
423 
424 static unsigned int rates_16000[] = {
425 	16000,
426 };
427 
428 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
429 	.count = ARRAY_SIZE(rates_16000),
430 	.list  = rates_16000,
431 };
432 
433 static const unsigned int ch_mono[] = {
434 	1,
435 };
436 
437 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
438 	.count = ARRAY_SIZE(ch_mono),
439 	.list  = ch_mono,
440 };
441 
442 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
443 {
444 	substream->runtime->hw.channels_max = 1;
445 	snd_pcm_hw_constraint_list(substream->runtime, 0,
446 					SNDRV_PCM_HW_PARAM_CHANNELS,
447 					&constraints_refcap);
448 
449 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
450 				SNDRV_PCM_HW_PARAM_RATE,
451 				&constraints_16000);
452 }
453 
454 static struct snd_soc_ops skylaye_refcap_ops = {
455 	.startup = kabylake_refcap_startup,
456 };
457 
458 /* kabylake digital audio interface glue - connects codec <--> CPU */
459 static struct snd_soc_dai_link kabylake_dais[] = {
460 	/* Front End DAI links */
461 	[KBL_DPCM_AUDIO_PB] = {
462 		.name = "Kbl Audio Port",
463 		.stream_name = "Audio",
464 		.cpu_dai_name = "System Pin",
465 		.platform_name = "0000:00:1f.3",
466 		.dynamic = 1,
467 		.codec_name = "snd-soc-dummy",
468 		.codec_dai_name = "snd-soc-dummy-dai",
469 		.nonatomic = 1,
470 		.init = kabylake_rt5663_fe_init,
471 		.trigger = {
472 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
473 		.dpcm_playback = 1,
474 		.ops = &kabylake_rt5663_fe_ops,
475 	},
476 	[KBL_DPCM_AUDIO_CP] = {
477 		.name = "Kbl Audio Capture Port",
478 		.stream_name = "Audio Record",
479 		.cpu_dai_name = "System Pin",
480 		.platform_name = "0000:00:1f.3",
481 		.dynamic = 1,
482 		.codec_name = "snd-soc-dummy",
483 		.codec_dai_name = "snd-soc-dummy-dai",
484 		.nonatomic = 1,
485 		.trigger = {
486 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
487 		.dpcm_capture = 1,
488 		.ops = &kabylake_rt5663_fe_ops,
489 	},
490 	[KBL_DPCM_AUDIO_HS_PB] = {
491 		.name = "Kbl Audio Headset Playback",
492 		.stream_name = "Headset Audio",
493 		.cpu_dai_name = "System Pin2",
494 		.codec_name = "snd-soc-dummy",
495 		.codec_dai_name = "snd-soc-dummy-dai",
496 		.platform_name = "0000:00:1f.3",
497 		.dpcm_playback = 1,
498 		.nonatomic = 1,
499 		.dynamic = 1,
500 	},
501 	[KBL_DPCM_AUDIO_ECHO_REF_CP] = {
502 		.name = "Kbl Audio Echo Reference cap",
503 		.stream_name = "Echoreference Capture",
504 		.cpu_dai_name = "Echoref Pin",
505 		.codec_name = "snd-soc-dummy",
506 		.codec_dai_name = "snd-soc-dummy-dai",
507 		.platform_name = "0000:00:1f.3",
508 		.init = NULL,
509 		.capture_only = 1,
510 		.nonatomic = 1,
511 	},
512 	[KBL_DPCM_AUDIO_REF_CP] = {
513 		.name = "Kbl Audio Reference cap",
514 		.stream_name = "Wake on Voice",
515 		.cpu_dai_name = "Reference Pin",
516 		.codec_name = "snd-soc-dummy",
517 		.codec_dai_name = "snd-soc-dummy-dai",
518 		.platform_name = "0000:00:1f.3",
519 		.init = NULL,
520 		.dpcm_capture = 1,
521 		.nonatomic = 1,
522 		.dynamic = 1,
523 		.ops = &skylaye_refcap_ops,
524 	},
525 	[KBL_DPCM_AUDIO_DMIC_CP] = {
526 		.name = "Kbl Audio DMIC cap",
527 		.stream_name = "dmiccap",
528 		.cpu_dai_name = "DMIC Pin",
529 		.codec_name = "snd-soc-dummy",
530 		.codec_dai_name = "snd-soc-dummy-dai",
531 		.platform_name = "0000:00:1f.3",
532 		.init = NULL,
533 		.dpcm_capture = 1,
534 		.nonatomic = 1,
535 		.dynamic = 1,
536 		.ops = &kabylake_dmic_ops,
537 	},
538 	[KBL_DPCM_AUDIO_HDMI1_PB] = {
539 		.name = "Kbl HDMI Port1",
540 		.stream_name = "Hdmi1",
541 		.cpu_dai_name = "HDMI1 Pin",
542 		.codec_name = "snd-soc-dummy",
543 		.codec_dai_name = "snd-soc-dummy-dai",
544 		.platform_name = "0000:00:1f.3",
545 		.dpcm_playback = 1,
546 		.init = NULL,
547 		.trigger = {
548 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
549 		.nonatomic = 1,
550 		.dynamic = 1,
551 	},
552 	[KBL_DPCM_AUDIO_HDMI2_PB] = {
553 		.name = "Kbl HDMI Port2",
554 		.stream_name = "Hdmi2",
555 		.cpu_dai_name = "HDMI2 Pin",
556 		.codec_name = "snd-soc-dummy",
557 		.codec_dai_name = "snd-soc-dummy-dai",
558 		.platform_name = "0000:00:1f.3",
559 		.dpcm_playback = 1,
560 		.init = NULL,
561 		.trigger = {
562 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
563 		.nonatomic = 1,
564 		.dynamic = 1,
565 	},
566 	[KBL_DPCM_AUDIO_HDMI3_PB] = {
567 		.name = "Kbl HDMI Port3",
568 		.stream_name = "Hdmi3",
569 		.cpu_dai_name = "HDMI3 Pin",
570 		.codec_name = "snd-soc-dummy",
571 		.codec_dai_name = "snd-soc-dummy-dai",
572 		.platform_name = "0000:00:1f.3",
573 		.trigger = {
574 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
575 		.dpcm_playback = 1,
576 		.init = NULL,
577 		.nonatomic = 1,
578 		.dynamic = 1,
579 	},
580 
581 	/* Back End DAI links */
582 	{
583 		/* SSP0 - Codec */
584 		.name = "SSP0-Codec",
585 		.id = 0,
586 		.cpu_dai_name = "SSP0 Pin",
587 		.platform_name = "0000:00:1f.3",
588 		.no_pcm = 1,
589 		.codecs = max98927_codec_components,
590 		.num_codecs = ARRAY_SIZE(max98927_codec_components),
591 		.dai_fmt = SND_SOC_DAIFMT_I2S |
592 			SND_SOC_DAIFMT_NB_NF |
593 			SND_SOC_DAIFMT_CBS_CFS,
594 		.ignore_pmdown_time = 1,
595 		.be_hw_params_fixup = kabylake_ssp_fixup,
596 		.dpcm_playback = 1,
597 	},
598 	{
599 		/* SSP1 - Codec */
600 		.name = "SSP1-Codec",
601 		.id = 1,
602 		.cpu_dai_name = "SSP1 Pin",
603 		.platform_name = "0000:00:1f.3",
604 		.no_pcm = 1,
605 		.codec_name = "i2c-10EC5663:00",
606 		.codec_dai_name = KBL_REALTEK_CODEC_DAI,
607 		.init = kabylake_rt5663_max98927_codec_init,
608 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
609 			SND_SOC_DAIFMT_CBS_CFS,
610 		.ignore_pmdown_time = 1,
611 		.be_hw_params_fixup = kabylake_ssp_fixup,
612 		.ops = &kabylake_rt5663_ops,
613 		.dpcm_playback = 1,
614 		.dpcm_capture = 1,
615 	},
616 	{
617 		.name = "dmic01",
618 		.id = 2,
619 		.cpu_dai_name = "DMIC01 Pin",
620 		.codec_name = "dmic-codec",
621 		.codec_dai_name = "dmic-hifi",
622 		.platform_name = "0000:00:1f.3",
623 		.be_hw_params_fixup = kabylake_dmic_fixup,
624 		.ignore_suspend = 1,
625 		.dpcm_capture = 1,
626 		.no_pcm = 1,
627 	},
628 	{
629 		.name = "iDisp1",
630 		.id = 3,
631 		.cpu_dai_name = "iDisp1 Pin",
632 		.codec_name = "ehdaudio0D2",
633 		.codec_dai_name = "intel-hdmi-hifi1",
634 		.platform_name = "0000:00:1f.3",
635 		.dpcm_playback = 1,
636 		.init = kabylake_hdmi1_init,
637 		.no_pcm = 1,
638 	},
639 	{
640 		.name = "iDisp2",
641 		.id = 4,
642 		.cpu_dai_name = "iDisp2 Pin",
643 		.codec_name = "ehdaudio0D2",
644 		.codec_dai_name = "intel-hdmi-hifi2",
645 		.platform_name = "0000:00:1f.3",
646 		.init = kabylake_hdmi2_init,
647 		.dpcm_playback = 1,
648 		.no_pcm = 1,
649 	},
650 	{
651 		.name = "iDisp3",
652 		.id = 5,
653 		.cpu_dai_name = "iDisp3 Pin",
654 		.codec_name = "ehdaudio0D2",
655 		.codec_dai_name = "intel-hdmi-hifi3",
656 		.platform_name = "0000:00:1f.3",
657 		.init = kabylake_hdmi3_init,
658 		.dpcm_playback = 1,
659 		.no_pcm = 1,
660 	},
661 };
662 
663 static struct snd_soc_dai_link kabylake_5663_dais[] = {
664 	/* Front End DAI links */
665 	[KBL_DPCM_AUDIO_5663_PB] = {
666 		.name = "Kbl Audio Port",
667 		.stream_name = "Audio",
668 		.cpu_dai_name = "System Pin",
669 		.platform_name = "0000:00:1f.3",
670 		.dynamic = 1,
671 		.codec_name = "snd-soc-dummy",
672 		.codec_dai_name = "snd-soc-dummy-dai",
673 		.nonatomic = 1,
674 		.trigger = {
675 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
676 		.dpcm_playback = 1,
677 		.ops = &kabylake_rt5663_fe_ops,
678 	},
679 	[KBL_DPCM_AUDIO_5663_CP] = {
680 		.name = "Kbl Audio Capture Port",
681 		.stream_name = "Audio Record",
682 		.cpu_dai_name = "System Pin",
683 		.platform_name = "0000:00:1f.3",
684 		.dynamic = 1,
685 		.codec_name = "snd-soc-dummy",
686 		.codec_dai_name = "snd-soc-dummy-dai",
687 		.nonatomic = 1,
688 		.trigger = {
689 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
690 		.dpcm_capture = 1,
691 		.ops = &kabylake_rt5663_fe_ops,
692 	},
693 	[KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
694 		.name = "Kbl HDMI Port1",
695 		.stream_name = "Hdmi1",
696 		.cpu_dai_name = "HDMI1 Pin",
697 		.codec_name = "snd-soc-dummy",
698 		.codec_dai_name = "snd-soc-dummy-dai",
699 		.platform_name = "0000:00:1f.3",
700 		.dpcm_playback = 1,
701 		.init = NULL,
702 		.trigger = {
703 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
704 		.nonatomic = 1,
705 		.dynamic = 1,
706 	},
707 	[KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
708 		.name = "Kbl HDMI Port2",
709 		.stream_name = "Hdmi2",
710 		.cpu_dai_name = "HDMI2 Pin",
711 		.codec_name = "snd-soc-dummy",
712 		.codec_dai_name = "snd-soc-dummy-dai",
713 		.platform_name = "0000:00:1f.3",
714 		.dpcm_playback = 1,
715 		.init = NULL,
716 		.trigger = {
717 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
718 		.nonatomic = 1,
719 		.dynamic = 1,
720 	},
721 
722 	/* Back End DAI links */
723 	{
724 		/* SSP1 - Codec */
725 		.name = "SSP1-Codec",
726 		.id = 0,
727 		.cpu_dai_name = "SSP1 Pin",
728 		.platform_name = "0000:00:1f.3",
729 		.no_pcm = 1,
730 		.codec_name = "i2c-10EC5663:00",
731 		.codec_dai_name = KBL_REALTEK_CODEC_DAI,
732 		.init = kabylake_rt5663_codec_init,
733 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
734 			SND_SOC_DAIFMT_CBS_CFS,
735 		.ignore_pmdown_time = 1,
736 		.be_hw_params_fixup = kabylake_ssp_fixup,
737 		.ops = &kabylake_rt5663_ops,
738 		.dpcm_playback = 1,
739 		.dpcm_capture = 1,
740 	},
741 	{
742 		.name = "iDisp1",
743 		.id = 1,
744 		.cpu_dai_name = "iDisp1 Pin",
745 		.codec_name = "ehdaudio0D2",
746 		.codec_dai_name = "intel-hdmi-hifi1",
747 		.platform_name = "0000:00:1f.3",
748 		.dpcm_playback = 1,
749 		.init = kabylake_5663_hdmi1_init,
750 		.no_pcm = 1,
751 	},
752 	{
753 		.name = "iDisp2",
754 		.id = 2,
755 		.cpu_dai_name = "iDisp2 Pin",
756 		.codec_name = "ehdaudio0D2",
757 		.codec_dai_name = "intel-hdmi-hifi2",
758 		.platform_name = "0000:00:1f.3",
759 		.init = kabylake_5663_hdmi2_init,
760 		.dpcm_playback = 1,
761 		.no_pcm = 1,
762 	},
763 };
764 
765 #define NAME_SIZE	32
766 static int kabylake_card_late_probe(struct snd_soc_card *card)
767 {
768 	struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
769 	struct kbl_hdmi_pcm *pcm;
770 	struct snd_soc_codec *codec = NULL;
771 	int err, i = 0;
772 	char jack_name[NAME_SIZE];
773 
774 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
775 		codec = pcm->codec_dai->codec;
776 		snprintf(jack_name, sizeof(jack_name),
777 			"HDMI/DP, pcm=%d Jack", pcm->device);
778 		err = snd_soc_card_jack_new(card, jack_name,
779 					SND_JACK_AVOUT, &skylake_hdmi[i],
780 					NULL, 0);
781 
782 		if (err)
783 			return err;
784 
785 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
786 						&skylake_hdmi[i]);
787 		if (err < 0)
788 			return err;
789 
790 		i++;
791 	}
792 
793 	if (!codec)
794 		return -EINVAL;
795 
796 	return hdac_hdmi_jack_port_init(codec, &card->dapm);
797 }
798 
799 /* kabylake audio machine driver for SPT + RT5663 */
800 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
801 	.name = "kblrt5663max",
802 	.owner = THIS_MODULE,
803 	.dai_link = kabylake_dais,
804 	.num_links = ARRAY_SIZE(kabylake_dais),
805 	.controls = kabylake_controls,
806 	.num_controls = ARRAY_SIZE(kabylake_controls),
807 	.dapm_widgets = kabylake_widgets,
808 	.num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
809 	.dapm_routes = kabylake_map,
810 	.num_dapm_routes = ARRAY_SIZE(kabylake_map),
811 	.codec_conf = max98927_codec_conf,
812 	.num_configs = ARRAY_SIZE(max98927_codec_conf),
813 	.fully_routed = true,
814 	.late_probe = kabylake_card_late_probe,
815 };
816 
817 /* kabylake audio machine driver for RT5663 */
818 static struct snd_soc_card kabylake_audio_card_rt5663 = {
819 	.name = "kblrt5663",
820 	.owner = THIS_MODULE,
821 	.dai_link = kabylake_5663_dais,
822 	.num_links = ARRAY_SIZE(kabylake_5663_dais),
823 	.controls = kabylake_5663_controls,
824 	.num_controls = ARRAY_SIZE(kabylake_5663_controls),
825 	.dapm_widgets = kabylake_5663_widgets,
826 	.num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
827 	.dapm_routes = kabylake_5663_map,
828 	.num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
829 	.fully_routed = true,
830 	.late_probe = kabylake_card_late_probe,
831 };
832 
833 static int kabylake_audio_probe(struct platform_device *pdev)
834 {
835 	struct kbl_rt5663_private *ctx;
836 	struct skl_machine_pdata *pdata;
837 
838 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
839 	if (!ctx)
840 		return -ENOMEM;
841 
842 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
843 
844 	kabylake_audio_card =
845 		(struct snd_soc_card *)pdev->id_entry->driver_data;
846 
847 	kabylake_audio_card->dev = &pdev->dev;
848 	snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
849 
850 	pdata = dev_get_drvdata(&pdev->dev);
851 	if (pdata)
852 		dmic_constraints = pdata->dmic_num == 2 ?
853 			&constraints_dmic_2ch : &constraints_dmic_channels;
854 
855 	return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
856 }
857 
858 static const struct platform_device_id kbl_board_ids[] = {
859 	{
860 		.name = "kbl_rt5663",
861 		.driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
862 	},
863 	{
864 		.name = "kbl_rt5663_m98927",
865 		.driver_data =
866 			(kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
867 	},
868 	{ }
869 };
870 
871 static struct platform_driver kabylake_audio = {
872 	.probe = kabylake_audio_probe,
873 	.driver = {
874 		.name = "kbl_rt5663_m98927",
875 		.pm = &snd_soc_pm_ops,
876 	},
877 	.id_table = kbl_board_ids,
878 };
879 
880 module_platform_driver(kabylake_audio)
881 
882 /* Module information */
883 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
884 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
885 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
886 MODULE_LICENSE("GPL v2");
887 MODULE_ALIAS("platform:kbl_rt5663");
888 MODULE_ALIAS("platform:kbl_rt5663_m98927");
889