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