1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Intel Broxton-P I2S Machine Driver
4  *
5  * Copyright (C) 2016, Intel Corporation. All rights reserved.
6  *
7  * Modified from:
8  *   Intel Skylake I2S Machine driver
9  */
10 
11 #include <linux/input.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <sound/core.h>
15 #include <sound/jack.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 #include <sound/soc-acpi.h>
20 #include "../../codecs/hdac_hdmi.h"
21 #include "../../codecs/da7219.h"
22 #include "../common/soc-intel-quirks.h"
23 #include "hda_dsp_common.h"
24 
25 #define BXT_DIALOG_CODEC_DAI	"da7219-hifi"
26 #define BXT_MAXIM_CODEC_DAI	"HiFi"
27 #define MAX98390_DEV0_NAME	"i2c-MX98390:00"
28 #define MAX98390_DEV1_NAME	"i2c-MX98390:01"
29 #define DUAL_CHANNEL		2
30 #define QUAD_CHANNEL		4
31 
32 #define SPKAMP_MAX98357A	1
33 #define SPKAMP_MAX98390	2
34 
35 static struct snd_soc_jack broxton_headset;
36 static struct snd_soc_jack broxton_hdmi[3];
37 
38 struct bxt_hdmi_pcm {
39 	struct list_head head;
40 	struct snd_soc_dai *codec_dai;
41 	int device;
42 };
43 
44 struct bxt_card_private {
45 	struct list_head hdmi_pcm_list;
46 	bool common_hdmi_codec_drv;
47 	int spkamp;
48 };
49 
50 enum {
51 	BXT_DPCM_AUDIO_PB = 0,
52 	BXT_DPCM_AUDIO_CP,
53 	BXT_DPCM_AUDIO_HS_PB,
54 	BXT_DPCM_AUDIO_REF_CP,
55 	BXT_DPCM_AUDIO_DMIC_CP,
56 	BXT_DPCM_AUDIO_HDMI1_PB,
57 	BXT_DPCM_AUDIO_HDMI2_PB,
58 	BXT_DPCM_AUDIO_HDMI3_PB,
59 };
60 
61 static int platform_clock_control(struct snd_soc_dapm_widget *w,
62 	struct snd_kcontrol *k, int  event)
63 {
64 	int ret = 0;
65 	struct snd_soc_dapm_context *dapm = w->dapm;
66 	struct snd_soc_card *card = dapm->card;
67 	struct snd_soc_dai *codec_dai;
68 
69 	codec_dai = snd_soc_card_get_codec_dai(card, BXT_DIALOG_CODEC_DAI);
70 	if (!codec_dai) {
71 		dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
72 		return -EIO;
73 	}
74 
75 	if (SND_SOC_DAPM_EVENT_OFF(event)) {
76 		ret = snd_soc_dai_set_pll(codec_dai, 0,
77 			DA7219_SYSCLK_MCLK, 0, 0);
78 		if (ret)
79 			dev_err(card->dev, "failed to stop PLL: %d\n", ret);
80 	} else if(SND_SOC_DAPM_EVENT_ON(event)) {
81 		ret = snd_soc_dai_set_pll(codec_dai, 0,
82 			DA7219_SYSCLK_PLL_SRM, 0, DA7219_PLL_FREQ_OUT_98304);
83 		if (ret)
84 			dev_err(card->dev, "failed to start PLL: %d\n", ret);
85 	}
86 
87 	return ret;
88 }
89 
90 static const struct snd_kcontrol_new broxton_controls[] = {
91 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
92 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
93 };
94 
95 static const struct snd_kcontrol_new max98357a_controls[] = {
96 	SOC_DAPM_PIN_SWITCH("Spk"),
97 };
98 
99 static const struct snd_kcontrol_new max98390_controls[] = {
100 	SOC_DAPM_PIN_SWITCH("Left Spk"),
101 	SOC_DAPM_PIN_SWITCH("Right Spk"),
102 };
103 
104 static const struct snd_soc_dapm_widget broxton_widgets[] = {
105 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
106 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
107 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
108 	SND_SOC_DAPM_SPK("HDMI1", NULL),
109 	SND_SOC_DAPM_SPK("HDMI2", NULL),
110 	SND_SOC_DAPM_SPK("HDMI3", NULL),
111 	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
112 			platform_clock_control,	SND_SOC_DAPM_POST_PMD|SND_SOC_DAPM_PRE_PMU),
113 };
114 
115 static const struct snd_soc_dapm_widget max98357a_widgets[] = {
116 	SND_SOC_DAPM_SPK("Spk", NULL),
117 };
118 
119 static const struct snd_soc_dapm_widget max98390_widgets[] = {
120 	SND_SOC_DAPM_SPK("Left Spk", NULL),
121 	SND_SOC_DAPM_SPK("Right Spk", NULL),
122 };
123 
124 static const struct snd_soc_dapm_route audio_map[] = {
125 	/* HP jack connectors - unknown if we have jack detection */
126 	{"Headphone Jack", NULL, "HPL"},
127 	{"Headphone Jack", NULL, "HPR"},
128 
129 	/* other jacks */
130 	{"MIC", NULL, "Headset Mic"},
131 
132 	/* digital mics */
133 	{"DMic", NULL, "SoC DMIC"},
134 
135 	/* CODEC BE connections */
136 	{"HDMI1", NULL, "hif5-0 Output"},
137 	{"HDMI2", NULL, "hif6-0 Output"},
138 	{"HDMI2", NULL, "hif7-0 Output"},
139 
140 	{"hifi3", NULL, "iDisp3 Tx"},
141 	{"iDisp3 Tx", NULL, "iDisp3_out"},
142 	{"hifi2", NULL, "iDisp2 Tx"},
143 	{"iDisp2 Tx", NULL, "iDisp2_out"},
144 	{"hifi1", NULL, "iDisp1 Tx"},
145 	{"iDisp1 Tx", NULL, "iDisp1_out"},
146 
147 	/* DMIC */
148 	{"dmic01_hifi", NULL, "DMIC01 Rx"},
149 	{"DMIC01 Rx", NULL, "DMIC AIF"},
150 
151 	{ "Headphone Jack", NULL, "Platform Clock" },
152 	{ "Headset Mic", NULL, "Platform Clock" },
153 };
154 
155 static const struct snd_soc_dapm_route max98357a_routes[] = {
156 	/* speaker */
157 	{"Spk", NULL, "Speaker"},
158 };
159 
160 static const struct snd_soc_dapm_route max98390_routes[] = {
161 	/* Speaker */
162 	{"Left Spk", NULL, "Left BE_OUT"},
163 	{"Right Spk", NULL, "Right BE_OUT"},
164 };
165 
166 static const struct snd_soc_dapm_route broxton_map[] = {
167 	{"HiFi Playback", NULL, "ssp5 Tx"},
168 	{"ssp5 Tx", NULL, "codec0_out"},
169 
170 	{"Playback", NULL, "ssp1 Tx"},
171 	{"ssp1 Tx", NULL, "codec1_out"},
172 
173 	{"codec0_in", NULL, "ssp1 Rx"},
174 	{"ssp1 Rx", NULL, "Capture"},
175 };
176 
177 static const struct snd_soc_dapm_route gemini_map[] = {
178 	{"HiFi Playback", NULL, "ssp1 Tx"},
179 	{"ssp1 Tx", NULL, "codec0_out"},
180 
181 	{"Playback", NULL, "ssp2 Tx"},
182 	{"ssp2 Tx", NULL, "codec1_out"},
183 
184 	{"codec0_in", NULL, "ssp2 Rx"},
185 	{"ssp2 Rx", NULL, "Capture"},
186 };
187 
188 static struct snd_soc_jack_pin jack_pins[] = {
189 	{
190 		.pin    = "Headphone Jack",
191 		.mask   = SND_JACK_HEADPHONE,
192 	},
193 	{
194 		.pin    = "Headset Mic",
195 		.mask   = SND_JACK_MICROPHONE,
196 	},
197 };
198 
199 static int broxton_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
200 			struct snd_pcm_hw_params *params)
201 {
202 	struct snd_interval *rate = hw_param_interval(params,
203 			SNDRV_PCM_HW_PARAM_RATE);
204 	struct snd_interval *chan = hw_param_interval(params,
205 			SNDRV_PCM_HW_PARAM_CHANNELS);
206 	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
207 
208 	/* The ADSP will convert the FE rate to 48k, stereo */
209 	rate->min = rate->max = 48000;
210 	chan->min = chan->max = DUAL_CHANNEL;
211 
212 	/* set SSP to 24 bit */
213 	snd_mask_none(fmt);
214 	snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
215 
216 	return 0;
217 }
218 
219 static int broxton_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
220 {
221 	int ret;
222 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
223 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
224 	int clk_freq;
225 
226 	/* Configure sysclk for codec */
227 	if (soc_intel_is_cml())
228 		clk_freq = 24000000;
229 	else
230 		clk_freq = 19200000;
231 
232 	ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, clk_freq,
233 				     SND_SOC_CLOCK_IN);
234 
235 	if (ret) {
236 		dev_err(rtd->dev, "can't set codec sysclk configuration\n");
237 		return ret;
238 	}
239 
240 	/*
241 	 * Headset buttons map to the google Reference headset.
242 	 * These can be configured by userspace.
243 	 */
244 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
245 					 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
246 					 SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
247 					 &broxton_headset,
248 					 jack_pins,
249 					 ARRAY_SIZE(jack_pins));
250 	if (ret) {
251 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
252 		return ret;
253 	}
254 
255 	snd_jack_set_key(broxton_headset.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
256 	snd_jack_set_key(broxton_headset.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
257 	snd_jack_set_key(broxton_headset.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
258 	snd_jack_set_key(broxton_headset.jack, SND_JACK_BTN_3,
259 			 KEY_VOICECOMMAND);
260 
261 	snd_soc_component_set_jack(component, &broxton_headset, NULL);
262 
263 	snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
264 
265 	return ret;
266 }
267 
268 static int broxton_hdmi_init(struct snd_soc_pcm_runtime *rtd)
269 {
270 	struct bxt_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
271 	struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
272 	struct bxt_hdmi_pcm *pcm;
273 
274 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
275 	if (!pcm)
276 		return -ENOMEM;
277 
278 	pcm->device = BXT_DPCM_AUDIO_HDMI1_PB + dai->id;
279 	pcm->codec_dai = dai;
280 
281 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
282 
283 	return 0;
284 }
285 
286 static int broxton_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
287 {
288 	struct snd_soc_dapm_context *dapm;
289 	struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
290 
291 	dapm = snd_soc_component_get_dapm(component);
292 	snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
293 
294 	return 0;
295 }
296 
297 static const unsigned int rates[] = {
298 	48000,
299 };
300 
301 static const struct snd_pcm_hw_constraint_list constraints_rates = {
302 	.count = ARRAY_SIZE(rates),
303 	.list  = rates,
304 	.mask = 0,
305 };
306 
307 static const unsigned int channels[] = {
308 	DUAL_CHANNEL,
309 };
310 
311 static const struct snd_pcm_hw_constraint_list constraints_channels = {
312 	.count = ARRAY_SIZE(channels),
313 	.list = channels,
314 	.mask = 0,
315 };
316 
317 static const unsigned int channels_quad[] = {
318 	QUAD_CHANNEL,
319 };
320 
321 static const struct snd_pcm_hw_constraint_list constraints_channels_quad = {
322 	.count = ARRAY_SIZE(channels_quad),
323 	.list = channels_quad,
324 	.mask = 0,
325 };
326 
327 static int bxt_fe_startup(struct snd_pcm_substream *substream)
328 {
329 	struct snd_pcm_runtime *runtime = substream->runtime;
330 
331 	/*
332 	 * On this platform for PCM device we support,
333 	 * 48Khz
334 	 * stereo
335 	 * 16 bit audio
336 	 */
337 
338 	runtime->hw.channels_max = DUAL_CHANNEL;
339 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
340 					   &constraints_channels);
341 
342 	runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
343 	snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
344 
345 	snd_pcm_hw_constraint_list(runtime, 0,
346 				SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
347 
348 	return 0;
349 }
350 
351 static const struct snd_soc_ops broxton_da7219_fe_ops = {
352 	.startup = bxt_fe_startup,
353 };
354 
355 static int broxton_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
356 			struct snd_pcm_hw_params *params)
357 {
358 	struct snd_interval *chan = hw_param_interval(params,
359 						SNDRV_PCM_HW_PARAM_CHANNELS);
360 	if (params_channels(params) == 2)
361 		chan->min = chan->max = 2;
362 	else
363 		chan->min = chan->max = 4;
364 
365 	return 0;
366 }
367 
368 static int broxton_dmic_startup(struct snd_pcm_substream *substream)
369 {
370 	struct snd_pcm_runtime *runtime = substream->runtime;
371 
372 	runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
373 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
374 			&constraints_channels_quad);
375 
376 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
377 			SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
378 }
379 
380 static const struct snd_soc_ops broxton_dmic_ops = {
381 	.startup = broxton_dmic_startup,
382 };
383 
384 static const unsigned int rates_16000[] = {
385 	16000,
386 };
387 
388 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
389 	.count = ARRAY_SIZE(rates_16000),
390 	.list  = rates_16000,
391 };
392 
393 static const unsigned int ch_mono[] = {
394 	1,
395 };
396 
397 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
398 	.count = ARRAY_SIZE(ch_mono),
399 	.list  = ch_mono,
400 };
401 
402 static int broxton_refcap_startup(struct snd_pcm_substream *substream)
403 {
404 	substream->runtime->hw.channels_max = 1;
405 	snd_pcm_hw_constraint_list(substream->runtime, 0,
406 				   SNDRV_PCM_HW_PARAM_CHANNELS,
407 				   &constraints_refcap);
408 
409 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
410 			SNDRV_PCM_HW_PARAM_RATE,
411 			&constraints_16000);
412 };
413 
414 static const struct snd_soc_ops broxton_refcap_ops = {
415 	.startup = broxton_refcap_startup,
416 };
417 
418 /* broxton digital audio interface glue - connects codec <--> CPU */
419 SND_SOC_DAILINK_DEF(dummy,
420 	DAILINK_COMP_ARRAY(COMP_DUMMY()));
421 
422 SND_SOC_DAILINK_DEF(system,
423 	DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
424 
425 SND_SOC_DAILINK_DEF(system2,
426 	DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
427 
428 SND_SOC_DAILINK_DEF(reference,
429 	DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
430 
431 SND_SOC_DAILINK_DEF(dmic,
432 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
433 
434 SND_SOC_DAILINK_DEF(hdmi1,
435 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
436 
437 SND_SOC_DAILINK_DEF(hdmi2,
438 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
439 
440 SND_SOC_DAILINK_DEF(hdmi3,
441 	DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
442 
443  /* Back End DAI */
444 SND_SOC_DAILINK_DEF(ssp5_pin,
445 	DAILINK_COMP_ARRAY(COMP_CPU("SSP5 Pin")));
446 SND_SOC_DAILINK_DEF(ssp5_codec,
447 	DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00",
448 				      BXT_MAXIM_CODEC_DAI)));
449 SND_SOC_DAILINK_DEF(max98390_codec,
450 	DAILINK_COMP_ARRAY(
451 	/* Left */	COMP_CODEC(MAX98390_DEV0_NAME, "max98390-aif1"),
452 	/* Right */	COMP_CODEC(MAX98390_DEV1_NAME, "max98390-aif1")));
453 
454 SND_SOC_DAILINK_DEF(ssp1_pin,
455 	DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
456 SND_SOC_DAILINK_DEF(ssp1_codec,
457 	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00",
458 				      BXT_DIALOG_CODEC_DAI)));
459 
460 SND_SOC_DAILINK_DEF(dmic_pin,
461 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
462 
463 SND_SOC_DAILINK_DEF(dmic16k_pin,
464 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC16k Pin")));
465 
466 SND_SOC_DAILINK_DEF(dmic_codec,
467 	DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
468 
469 SND_SOC_DAILINK_DEF(idisp1_pin,
470 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
471 SND_SOC_DAILINK_DEF(idisp1_codec,
472 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
473 
474 SND_SOC_DAILINK_DEF(idisp2_pin,
475 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
476 SND_SOC_DAILINK_DEF(idisp2_codec,
477 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
478 				      "intel-hdmi-hifi2")));
479 
480 SND_SOC_DAILINK_DEF(idisp3_pin,
481 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
482 SND_SOC_DAILINK_DEF(idisp3_codec,
483 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
484 				      "intel-hdmi-hifi3")));
485 
486 SND_SOC_DAILINK_DEF(platform,
487 	DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:0e.0")));
488 
489 static struct snd_soc_dai_link broxton_dais[] = {
490 	/* Front End DAI links */
491 	[BXT_DPCM_AUDIO_PB] =
492 	{
493 		.name = "Bxt Audio Port",
494 		.stream_name = "Audio",
495 		.dynamic = 1,
496 		.nonatomic = 1,
497 		.init = broxton_da7219_fe_init,
498 		.trigger = {
499 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
500 		.dpcm_playback = 1,
501 		.ops = &broxton_da7219_fe_ops,
502 		SND_SOC_DAILINK_REG(system, dummy, platform),
503 	},
504 	[BXT_DPCM_AUDIO_CP] =
505 	{
506 		.name = "Bxt Audio Capture Port",
507 		.stream_name = "Audio Record",
508 		.dynamic = 1,
509 		.nonatomic = 1,
510 		.trigger = {
511 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
512 		.dpcm_capture = 1,
513 		.ops = &broxton_da7219_fe_ops,
514 		SND_SOC_DAILINK_REG(system, dummy, platform),
515 	},
516 	[BXT_DPCM_AUDIO_HS_PB] = {
517 		.name = "Bxt Audio Headset Playback",
518 		.stream_name = "Headset Playback",
519 		.dynamic = 1,
520 		.nonatomic = 1,
521 		.trigger = {
522 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
523 		.dpcm_playback = 1,
524 		.ops = &broxton_da7219_fe_ops,
525 		SND_SOC_DAILINK_REG(system2, dummy, platform),
526 	},
527 	[BXT_DPCM_AUDIO_REF_CP] =
528 	{
529 		.name = "Bxt Audio Reference cap",
530 		.stream_name = "Refcap",
531 		.init = NULL,
532 		.dpcm_capture = 1,
533 		.nonatomic = 1,
534 		.dynamic = 1,
535 		.ops = &broxton_refcap_ops,
536 		SND_SOC_DAILINK_REG(reference, dummy, platform),
537 	},
538 	[BXT_DPCM_AUDIO_DMIC_CP] =
539 	{
540 		.name = "Bxt Audio DMIC cap",
541 		.stream_name = "dmiccap",
542 		.init = NULL,
543 		.dpcm_capture = 1,
544 		.nonatomic = 1,
545 		.dynamic = 1,
546 		.ops = &broxton_dmic_ops,
547 		SND_SOC_DAILINK_REG(dmic, dummy, platform),
548 	},
549 	[BXT_DPCM_AUDIO_HDMI1_PB] =
550 	{
551 		.name = "Bxt HDMI Port1",
552 		.stream_name = "Hdmi1",
553 		.dpcm_playback = 1,
554 		.init = NULL,
555 		.nonatomic = 1,
556 		.dynamic = 1,
557 		SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
558 	},
559 	[BXT_DPCM_AUDIO_HDMI2_PB] =
560 	{
561 		.name = "Bxt HDMI Port2",
562 		.stream_name = "Hdmi2",
563 		.dpcm_playback = 1,
564 		.init = NULL,
565 		.nonatomic = 1,
566 		.dynamic = 1,
567 		SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
568 	},
569 	[BXT_DPCM_AUDIO_HDMI3_PB] =
570 	{
571 		.name = "Bxt HDMI Port3",
572 		.stream_name = "Hdmi3",
573 		.dpcm_playback = 1,
574 		.init = NULL,
575 		.nonatomic = 1,
576 		.dynamic = 1,
577 		SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
578 	},
579 	/* Back End DAI links */
580 	{
581 		/* SSP5 - Codec */
582 		.name = "SSP5-Codec",
583 		.id = 0,
584 		.no_pcm = 1,
585 		.dai_fmt = SND_SOC_DAIFMT_I2S |
586 			SND_SOC_DAIFMT_NB_NF |
587 			SND_SOC_DAIFMT_CBC_CFC,
588 		.ignore_pmdown_time = 1,
589 		.be_hw_params_fixup = broxton_ssp_fixup,
590 		.dpcm_playback = 1,
591 		SND_SOC_DAILINK_REG(ssp5_pin, ssp5_codec, platform),
592 	},
593 	{
594 		/* SSP1 - Codec */
595 		.name = "SSP1-Codec",
596 		.id = 1,
597 		.no_pcm = 1,
598 		.init = broxton_da7219_codec_init,
599 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
600 			SND_SOC_DAIFMT_CBC_CFC,
601 		.ignore_pmdown_time = 1,
602 		.be_hw_params_fixup = broxton_ssp_fixup,
603 		.dpcm_playback = 1,
604 		.dpcm_capture = 1,
605 		SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
606 	},
607 	{
608 		.name = "dmic01",
609 		.id = 2,
610 		.ignore_suspend = 1,
611 		.be_hw_params_fixup = broxton_dmic_fixup,
612 		.dpcm_capture = 1,
613 		.no_pcm = 1,
614 		SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
615 	},
616 	{
617 		.name = "iDisp1",
618 		.id = 3,
619 		.init = broxton_hdmi_init,
620 		.dpcm_playback = 1,
621 		.no_pcm = 1,
622 		SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
623 	},
624 	{
625 		.name = "iDisp2",
626 		.id = 4,
627 		.init = broxton_hdmi_init,
628 		.dpcm_playback = 1,
629 		.no_pcm = 1,
630 		SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
631 	},
632 	{
633 		.name = "iDisp3",
634 		.id = 5,
635 		.init = broxton_hdmi_init,
636 		.dpcm_playback = 1,
637 		.no_pcm = 1,
638 		SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
639 	},
640 	{
641 		.name = "dmic16k",
642 		.id = 6,
643 		.be_hw_params_fixup = broxton_dmic_fixup,
644 		.dpcm_capture = 1,
645 		.no_pcm = 1,
646 		SND_SOC_DAILINK_REG(dmic16k_pin, dmic_codec, platform),
647 	},
648 };
649 
650 static struct snd_soc_codec_conf max98390_codec_confs[] = {
651 	{
652 		.dlc = COMP_CODEC_CONF(MAX98390_DEV0_NAME),
653 		.name_prefix = "Left",
654 	},
655 	{
656 		.dlc = COMP_CODEC_CONF(MAX98390_DEV1_NAME),
657 		.name_prefix = "Right",
658 	},
659 };
660 
661 #define NAME_SIZE	32
662 static int bxt_card_late_probe(struct snd_soc_card *card)
663 {
664 	struct bxt_card_private *ctx = snd_soc_card_get_drvdata(card);
665 	struct bxt_hdmi_pcm *pcm;
666 	struct snd_soc_component *component = NULL;
667 	const struct snd_kcontrol_new *controls;
668 	const struct snd_soc_dapm_widget *widgets;
669 	const struct snd_soc_dapm_route *routes;
670 	int num_controls, num_widgets, num_routes, err, i = 0;
671 	char jack_name[NAME_SIZE];
672 
673 	switch (ctx->spkamp) {
674 	case SPKAMP_MAX98357A:
675 		controls = max98357a_controls;
676 		num_controls = ARRAY_SIZE(max98357a_controls);
677 		widgets = max98357a_widgets;
678 		num_widgets = ARRAY_SIZE(max98357a_widgets);
679 		routes = max98357a_routes;
680 		num_routes = ARRAY_SIZE(max98357a_routes);
681 		break;
682 	case SPKAMP_MAX98390:
683 		controls = max98390_controls;
684 		num_controls = ARRAY_SIZE(max98390_controls);
685 		widgets = max98390_widgets;
686 		num_widgets = ARRAY_SIZE(max98390_widgets);
687 		routes = max98390_routes;
688 		num_routes = ARRAY_SIZE(max98390_routes);
689 		break;
690 	default:
691 		dev_err(card->dev, "Invalid speaker amplifier %d\n", ctx->spkamp);
692 		return -EINVAL;
693 	}
694 
695 	err = snd_soc_dapm_new_controls(&card->dapm, widgets, num_widgets);
696 	if (err) {
697 		dev_err(card->dev, "Fail to new widgets\n");
698 		return err;
699 	}
700 
701 	err = snd_soc_add_card_controls(card, controls, num_controls);
702 	if (err) {
703 		dev_err(card->dev, "Fail to add controls\n");
704 		return err;
705 	}
706 
707 	err = snd_soc_dapm_add_routes(&card->dapm, routes, num_routes);
708 	if (err) {
709 		dev_err(card->dev, "Fail to add routes\n");
710 		return err;
711 	}
712 
713 	if (soc_intel_is_glk())
714 		snd_soc_dapm_add_routes(&card->dapm, gemini_map,
715 					ARRAY_SIZE(gemini_map));
716 	else
717 		snd_soc_dapm_add_routes(&card->dapm, broxton_map,
718 					ARRAY_SIZE(broxton_map));
719 
720 	if (list_empty(&ctx->hdmi_pcm_list))
721 		return -EINVAL;
722 
723 	if (ctx->common_hdmi_codec_drv) {
724 		pcm = list_first_entry(&ctx->hdmi_pcm_list, struct bxt_hdmi_pcm,
725 				       head);
726 		component = pcm->codec_dai->component;
727 		return hda_dsp_hdmi_build_controls(card, component);
728 	}
729 
730 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
731 		component = pcm->codec_dai->component;
732 		snprintf(jack_name, sizeof(jack_name),
733 			"HDMI/DP, pcm=%d Jack", pcm->device);
734 		err = snd_soc_card_jack_new(card, jack_name,
735 					SND_JACK_AVOUT, &broxton_hdmi[i]);
736 
737 		if (err)
738 			return err;
739 
740 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
741 						&broxton_hdmi[i]);
742 		if (err < 0)
743 			return err;
744 
745 		i++;
746 	}
747 
748 	return hdac_hdmi_jack_port_init(component, &card->dapm);
749 }
750 
751 /* broxton audio machine driver for SPT + da7219 */
752 static struct snd_soc_card broxton_audio_card = {
753 	.name = "bxtda7219max",
754 	.owner = THIS_MODULE,
755 	.dai_link = broxton_dais,
756 	.num_links = ARRAY_SIZE(broxton_dais),
757 	.controls = broxton_controls,
758 	.num_controls = ARRAY_SIZE(broxton_controls),
759 	.dapm_widgets = broxton_widgets,
760 	.num_dapm_widgets = ARRAY_SIZE(broxton_widgets),
761 	.dapm_routes = audio_map,
762 	.num_dapm_routes = ARRAY_SIZE(audio_map),
763 	.fully_routed = true,
764 	.late_probe = bxt_card_late_probe,
765 };
766 
767 static int broxton_audio_probe(struct platform_device *pdev)
768 {
769 	struct bxt_card_private *ctx;
770 	struct snd_soc_acpi_mach *mach;
771 	const char *platform_name;
772 	int ret;
773 
774 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
775 	if (!ctx)
776 		return -ENOMEM;
777 
778 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
779 
780 	if (acpi_dev_present("MX98390", NULL, -1))
781 		ctx->spkamp = SPKAMP_MAX98390;
782 	else
783 		ctx->spkamp = SPKAMP_MAX98357A;
784 
785 	broxton_audio_card.dev = &pdev->dev;
786 	snd_soc_card_set_drvdata(&broxton_audio_card, ctx);
787 	if (soc_intel_is_glk()) {
788 		unsigned int i;
789 
790 		broxton_audio_card.name = "glkda7219max";
791 		/* Fixup the SSP entries for geminilake */
792 		for (i = 0; i < ARRAY_SIZE(broxton_dais); i++) {
793 			/* MAXIM_CODEC is connected to SSP1. */
794 			if (!strcmp(broxton_dais[i].codecs->dai_name,
795 				    BXT_MAXIM_CODEC_DAI)) {
796 				broxton_dais[i].name = "SSP1-Codec";
797 				broxton_dais[i].cpus->dai_name = "SSP1 Pin";
798 			}
799 			/* DIALOG_CODE is connected to SSP2 */
800 			else if (!strcmp(broxton_dais[i].codecs->dai_name,
801 					 BXT_DIALOG_CODEC_DAI)) {
802 				broxton_dais[i].name = "SSP2-Codec";
803 				broxton_dais[i].cpus->dai_name = "SSP2 Pin";
804 			}
805 		}
806 	} else if (soc_intel_is_cml()) {
807 		unsigned int i;
808 
809 		if (ctx->spkamp == SPKAMP_MAX98390) {
810 			broxton_audio_card.name = "cml_max98390_da7219";
811 
812 			broxton_audio_card.codec_conf = max98390_codec_confs;
813 			broxton_audio_card.num_configs = ARRAY_SIZE(max98390_codec_confs);
814 		} else
815 			broxton_audio_card.name = "cmlda7219max";
816 
817 		for (i = 0; i < ARRAY_SIZE(broxton_dais); i++) {
818 			/* MAXIM_CODEC is connected to SSP1. */
819 			if (!strcmp(broxton_dais[i].codecs->dai_name,
820 					BXT_MAXIM_CODEC_DAI)) {
821 				broxton_dais[i].name = "SSP1-Codec";
822 				broxton_dais[i].cpus->dai_name = "SSP1 Pin";
823 
824 				if (ctx->spkamp == SPKAMP_MAX98390) {
825 					broxton_dais[i].codecs = max98390_codec;
826 					broxton_dais[i].num_codecs = ARRAY_SIZE(max98390_codec);
827 					broxton_dais[i].dpcm_capture = 1;
828 				}
829 			}
830 			/* DIALOG_CODEC is connected to SSP0 */
831 			else if (!strcmp(broxton_dais[i].codecs->dai_name,
832 					BXT_DIALOG_CODEC_DAI)) {
833 				broxton_dais[i].name = "SSP0-Codec";
834 				broxton_dais[i].cpus->dai_name = "SSP0 Pin";
835 			}
836 		}
837 	}
838 
839 	/* override platform name, if required */
840 	mach = pdev->dev.platform_data;
841 	platform_name = mach->mach_params.platform;
842 
843 	ret = snd_soc_fixup_dai_links_platform_name(&broxton_audio_card,
844 						    platform_name);
845 	if (ret)
846 		return ret;
847 
848 	ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
849 
850 	return devm_snd_soc_register_card(&pdev->dev, &broxton_audio_card);
851 }
852 
853 static const struct platform_device_id bxt_board_ids[] = {
854 	{ .name = "bxt_da7219_mx98357a" },
855 	{ .name = "glk_da7219_mx98357a" },
856 	{ .name = "cml_da7219_mx98357a" },
857 	{ }
858 };
859 MODULE_DEVICE_TABLE(platform, bxt_board_ids);
860 
861 static struct platform_driver broxton_audio = {
862 	.probe = broxton_audio_probe,
863 	.driver = {
864 		.name = "bxt_da7219_max98357a",
865 		.pm = &snd_soc_pm_ops,
866 	},
867 	.id_table = bxt_board_ids,
868 };
869 module_platform_driver(broxton_audio)
870 
871 /* Module information */
872 MODULE_DESCRIPTION("Audio Machine driver-DA7219 & MAX98357A in I2S mode");
873 MODULE_AUTHOR("Sathyanarayana Nujella <sathyanarayana.nujella@intel.com>");
874 MODULE_AUTHOR("Rohit Ainapure <rohit.m.ainapure@intel.com>");
875 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
876 MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
877 MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
878 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
879 MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
880 MODULE_LICENSE("GPL v2");
881 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
882