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