1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2017-18 Intel Corporation.
3
4 /*
5 * Intel Kabylake I2S Machine Driver with MAX98357A & DA7219 Codecs
6 *
7 * Modified from:
8 * Intel Kabylake I2S Machine driver supporting MAXIM98927 and
9 * RT5663 codecs
10 */
11
12 #include <linux/input.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <sound/core.h>
16 #include <sound/jack.h>
17 #include <sound/pcm.h>
18 #include <sound/pcm_params.h>
19 #include <sound/soc.h>
20 #include "../../codecs/da7219.h"
21 #include "../../codecs/hdac_hdmi.h"
22
23 #define KBL_DIALOG_CODEC_DAI "da7219-hifi"
24 #define KBL_MAXIM_CODEC_DAI "HiFi"
25 #define MAXIM_DEV0_NAME "MX98357A:00"
26 #define DUAL_CHANNEL 2
27 #define QUAD_CHANNEL 4
28
29 static struct snd_soc_card *kabylake_audio_card;
30 static struct snd_soc_jack skylake_hdmi[3];
31
32 struct kbl_hdmi_pcm {
33 struct list_head head;
34 struct snd_soc_dai *codec_dai;
35 int device;
36 };
37
38 struct kbl_codec_private {
39 struct snd_soc_jack kabylake_headset;
40 struct list_head hdmi_pcm_list;
41 };
42
43 enum {
44 KBL_DPCM_AUDIO_PB = 0,
45 KBL_DPCM_AUDIO_CP,
46 KBL_DPCM_AUDIO_REF_CP,
47 KBL_DPCM_AUDIO_DMIC_CP,
48 KBL_DPCM_AUDIO_HDMI1_PB,
49 KBL_DPCM_AUDIO_HDMI2_PB,
50 KBL_DPCM_AUDIO_HDMI3_PB,
51 };
52
platform_clock_control(struct snd_soc_dapm_widget * w,struct snd_kcontrol * k,int event)53 static int platform_clock_control(struct snd_soc_dapm_widget *w,
54 struct snd_kcontrol *k, int event)
55 {
56 struct snd_soc_dapm_context *dapm = w->dapm;
57 struct snd_soc_card *card = dapm->card;
58 struct snd_soc_dai *codec_dai;
59 int ret = 0;
60
61 codec_dai = snd_soc_card_get_codec_dai(card, KBL_DIALOG_CODEC_DAI);
62 if (!codec_dai) {
63 dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
64 return -EIO;
65 }
66
67 if (SND_SOC_DAPM_EVENT_OFF(event)) {
68 ret = snd_soc_dai_set_pll(codec_dai, 0,
69 DA7219_SYSCLK_MCLK, 0, 0);
70 if (ret)
71 dev_err(card->dev, "failed to stop PLL: %d\n", ret);
72 } else if (SND_SOC_DAPM_EVENT_ON(event)) {
73 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
74 0, DA7219_PLL_FREQ_OUT_98304);
75 if (ret)
76 dev_err(card->dev, "failed to start PLL: %d\n", ret);
77 }
78
79 return ret;
80 }
81
82 static const struct snd_kcontrol_new kabylake_controls[] = {
83 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
84 SOC_DAPM_PIN_SWITCH("Headset Mic"),
85 SOC_DAPM_PIN_SWITCH("Spk"),
86 SOC_DAPM_PIN_SWITCH("Line Out"),
87 };
88
89 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
90 SND_SOC_DAPM_HP("Headphone Jack", NULL),
91 SND_SOC_DAPM_MIC("Headset Mic", NULL),
92 SND_SOC_DAPM_SPK("Spk", NULL),
93 SND_SOC_DAPM_LINE("Line Out", NULL),
94 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
95 SND_SOC_DAPM_SPK("HDMI1", NULL),
96 SND_SOC_DAPM_SPK("HDMI2", NULL),
97 SND_SOC_DAPM_SPK("HDMI3", NULL),
98 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
99 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
100 SND_SOC_DAPM_POST_PMD),
101 };
102
103 static struct snd_soc_jack_pin jack_pins[] = {
104 {
105 .pin = "Headphone Jack",
106 .mask = SND_JACK_HEADPHONE,
107 },
108 {
109 .pin = "Headset Mic",
110 .mask = SND_JACK_MICROPHONE,
111 },
112 {
113 .pin = "Line Out",
114 .mask = SND_JACK_LINEOUT,
115 },
116 };
117
118 static const struct snd_soc_dapm_route kabylake_map[] = {
119 { "Headphone Jack", NULL, "HPL" },
120 { "Headphone Jack", NULL, "HPR" },
121
122 /* speaker */
123 { "Spk", NULL, "Speaker" },
124
125 /* other jacks */
126 { "MIC", NULL, "Headset Mic" },
127 { "DMic", NULL, "SoC DMIC" },
128
129 {"HDMI1", NULL, "hif5-0 Output"},
130 {"HDMI2", NULL, "hif6-0 Output"},
131 {"HDMI3", NULL, "hif7-0 Output"},
132
133 /* CODEC BE connections */
134 { "HiFi Playback", NULL, "ssp0 Tx" },
135 { "ssp0 Tx", NULL, "codec0_out" },
136
137 { "Playback", NULL, "ssp1 Tx" },
138 { "ssp1 Tx", NULL, "codec1_out" },
139
140 { "codec0_in", NULL, "ssp1 Rx" },
141 { "ssp1 Rx", NULL, "Capture" },
142
143 /* DMIC */
144 { "dmic01_hifi", NULL, "DMIC01 Rx" },
145 { "DMIC01 Rx", NULL, "DMIC AIF" },
146
147 { "hifi1", NULL, "iDisp1 Tx" },
148 { "iDisp1 Tx", NULL, "iDisp1_out" },
149 { "hifi2", NULL, "iDisp2 Tx" },
150 { "iDisp2 Tx", NULL, "iDisp2_out" },
151 { "hifi3", NULL, "iDisp3 Tx"},
152 { "iDisp3 Tx", NULL, "iDisp3_out"},
153
154 { "Headphone Jack", NULL, "Platform Clock" },
155 { "Headset Mic", NULL, "Platform Clock" },
156 { "Line Out", NULL, "Platform Clock" },
157 };
158
kabylake_ssp_fixup(struct snd_soc_pcm_runtime * rtd,struct snd_pcm_hw_params * params)159 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
160 struct snd_pcm_hw_params *params)
161 {
162 struct snd_interval *rate = hw_param_interval(params,
163 SNDRV_PCM_HW_PARAM_RATE);
164 struct snd_interval *chan = hw_param_interval(params,
165 SNDRV_PCM_HW_PARAM_CHANNELS);
166 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
167
168 /* The ADSP will convert the FE rate to 48k, stereo */
169 rate->min = rate->max = 48000;
170 chan->min = chan->max = DUAL_CHANNEL;
171
172 /* set SSP to 24 bit */
173 snd_mask_none(fmt);
174 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
175
176 return 0;
177 }
178
kabylake_da7219_codec_init(struct snd_soc_pcm_runtime * rtd)179 static int kabylake_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
180 {
181 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
182 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
183 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
184 struct snd_soc_jack *jack;
185 int ret;
186
187 /* Configure sysclk for codec */
188 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24576000,
189 SND_SOC_CLOCK_IN);
190 if (ret) {
191 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
192 return ret;
193 }
194
195 /*
196 * Headset buttons map to the google Reference headset.
197 * These can be configured by userspace.
198 */
199 ret = snd_soc_card_jack_new_pins(kabylake_audio_card, "Headset Jack",
200 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
201 SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
202 &ctx->kabylake_headset,
203 jack_pins,
204 ARRAY_SIZE(jack_pins));
205 if (ret) {
206 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
207 return ret;
208 }
209
210 jack = &ctx->kabylake_headset;
211
212 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
213 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
214 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
215 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
216 snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
217
218 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
219 if (ret)
220 dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret);
221
222 return ret;
223 }
224
kabylake_hdmi_init(struct snd_soc_pcm_runtime * rtd,int device)225 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
226 {
227 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
228 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
229 struct kbl_hdmi_pcm *pcm;
230
231 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
232 if (!pcm)
233 return -ENOMEM;
234
235 pcm->device = device;
236 pcm->codec_dai = dai;
237
238 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
239
240 return 0;
241 }
242
kabylake_hdmi1_init(struct snd_soc_pcm_runtime * rtd)243 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
244 {
245 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
246 }
247
kabylake_hdmi2_init(struct snd_soc_pcm_runtime * rtd)248 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
249 {
250 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
251 }
252
kabylake_hdmi3_init(struct snd_soc_pcm_runtime * rtd)253 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
254 {
255 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
256 }
257
kabylake_da7219_fe_init(struct snd_soc_pcm_runtime * rtd)258 static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
259 {
260 struct snd_soc_dapm_context *dapm;
261 struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
262
263 dapm = snd_soc_component_get_dapm(component);
264 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
265
266 return 0;
267 }
268
269 static const unsigned int rates[] = {
270 48000,
271 };
272
273 static const struct snd_pcm_hw_constraint_list constraints_rates = {
274 .count = ARRAY_SIZE(rates),
275 .list = rates,
276 .mask = 0,
277 };
278
279 static const unsigned int channels[] = {
280 DUAL_CHANNEL,
281 };
282
283 static const struct snd_pcm_hw_constraint_list constraints_channels = {
284 .count = ARRAY_SIZE(channels),
285 .list = channels,
286 .mask = 0,
287 };
288
289 static unsigned int channels_quad[] = {
290 QUAD_CHANNEL,
291 };
292
293 static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
294 .count = ARRAY_SIZE(channels_quad),
295 .list = channels_quad,
296 .mask = 0,
297 };
298
kbl_fe_startup(struct snd_pcm_substream * substream)299 static int kbl_fe_startup(struct snd_pcm_substream *substream)
300 {
301 struct snd_pcm_runtime *runtime = substream->runtime;
302
303 /*
304 * On this platform for PCM device we support,
305 * 48Khz
306 * stereo
307 * 16 bit audio
308 */
309
310 runtime->hw.channels_max = DUAL_CHANNEL;
311 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
312 &constraints_channels);
313
314 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
315 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
316
317 snd_pcm_hw_constraint_list(runtime, 0,
318 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
319
320 return 0;
321 }
322
323 static const struct snd_soc_ops kabylake_da7219_fe_ops = {
324 .startup = kbl_fe_startup,
325 };
326
kabylake_dmic_fixup(struct snd_soc_pcm_runtime * rtd,struct snd_pcm_hw_params * params)327 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
328 struct snd_pcm_hw_params *params)
329 {
330 struct snd_interval *chan = hw_param_interval(params,
331 SNDRV_PCM_HW_PARAM_CHANNELS);
332
333 /*
334 * set BE channel constraint as user FE channels
335 */
336
337 if (params_channels(params) == 2)
338 chan->min = chan->max = 2;
339 else
340 chan->min = chan->max = 4;
341
342 return 0;
343 }
344
kabylake_dmic_startup(struct snd_pcm_substream * substream)345 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
346 {
347 struct snd_pcm_runtime *runtime = substream->runtime;
348
349 runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
350 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
351 &constraints_channels_quad);
352
353 return snd_pcm_hw_constraint_list(substream->runtime, 0,
354 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
355 }
356
357 static struct snd_soc_ops kabylake_dmic_ops = {
358 .startup = kabylake_dmic_startup,
359 };
360
361 static unsigned int rates_16000[] = {
362 16000,
363 };
364
365 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
366 .count = ARRAY_SIZE(rates_16000),
367 .list = rates_16000,
368 };
369
370 static const unsigned int ch_mono[] = {
371 1,
372 };
373
374 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
375 .count = ARRAY_SIZE(ch_mono),
376 .list = ch_mono,
377 };
378
kabylake_refcap_startup(struct snd_pcm_substream * substream)379 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
380 {
381 substream->runtime->hw.channels_max = 1;
382 snd_pcm_hw_constraint_list(substream->runtime, 0,
383 SNDRV_PCM_HW_PARAM_CHANNELS,
384 &constraints_refcap);
385
386 return snd_pcm_hw_constraint_list(substream->runtime, 0,
387 SNDRV_PCM_HW_PARAM_RATE,
388 &constraints_16000);
389 }
390
391 static struct snd_soc_ops skylake_refcap_ops = {
392 .startup = kabylake_refcap_startup,
393 };
394
395 SND_SOC_DAILINK_DEF(dummy,
396 DAILINK_COMP_ARRAY(COMP_DUMMY()));
397
398 SND_SOC_DAILINK_DEF(system,
399 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
400
401 SND_SOC_DAILINK_DEF(reference,
402 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
403
404 SND_SOC_DAILINK_DEF(dmic,
405 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
406
407 SND_SOC_DAILINK_DEF(hdmi1,
408 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
409
410 SND_SOC_DAILINK_DEF(hdmi2,
411 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
412
413 SND_SOC_DAILINK_DEF(hdmi3,
414 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
415
416 SND_SOC_DAILINK_DEF(ssp0_pin,
417 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
418 SND_SOC_DAILINK_DEF(ssp0_codec,
419 DAILINK_COMP_ARRAY(COMP_CODEC(MAXIM_DEV0_NAME,
420 KBL_MAXIM_CODEC_DAI)));
421
422 SND_SOC_DAILINK_DEF(ssp1_pin,
423 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
424 SND_SOC_DAILINK_DEF(ssp1_codec,
425 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00",
426 KBL_DIALOG_CODEC_DAI)));
427
428 SND_SOC_DAILINK_DEF(dmic_pin,
429 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
430 SND_SOC_DAILINK_DEF(dmic_codec,
431 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
432
433 SND_SOC_DAILINK_DEF(idisp1_pin,
434 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
435 SND_SOC_DAILINK_DEF(idisp1_codec,
436 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
437 "intel-hdmi-hifi1")));
438
439 SND_SOC_DAILINK_DEF(idisp2_pin,
440 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
441 SND_SOC_DAILINK_DEF(idisp2_codec,
442 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
443
444 SND_SOC_DAILINK_DEF(idisp3_pin,
445 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
446 SND_SOC_DAILINK_DEF(idisp3_codec,
447 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
448
449 SND_SOC_DAILINK_DEF(platform,
450 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
451
452 /* kabylake digital audio interface glue - connects codec <--> CPU */
453 static struct snd_soc_dai_link kabylake_dais[] = {
454 /* Front End DAI links */
455 [KBL_DPCM_AUDIO_PB] = {
456 .name = "Kbl Audio Port",
457 .stream_name = "Audio",
458 .dynamic = 1,
459 .nonatomic = 1,
460 .init = kabylake_da7219_fe_init,
461 .trigger = {
462 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
463 .dpcm_playback = 1,
464 .ops = &kabylake_da7219_fe_ops,
465 SND_SOC_DAILINK_REG(system, dummy, platform),
466 },
467 [KBL_DPCM_AUDIO_CP] = {
468 .name = "Kbl Audio Capture Port",
469 .stream_name = "Audio Record",
470 .dynamic = 1,
471 .nonatomic = 1,
472 .trigger = {
473 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
474 .dpcm_capture = 1,
475 .ops = &kabylake_da7219_fe_ops,
476 SND_SOC_DAILINK_REG(system, dummy, platform),
477 },
478 [KBL_DPCM_AUDIO_REF_CP] = {
479 .name = "Kbl Audio Reference cap",
480 .stream_name = "Wake on Voice",
481 .init = NULL,
482 .dpcm_capture = 1,
483 .nonatomic = 1,
484 .dynamic = 1,
485 .ops = &skylake_refcap_ops,
486 SND_SOC_DAILINK_REG(reference, dummy, platform),
487 },
488 [KBL_DPCM_AUDIO_DMIC_CP] = {
489 .name = "Kbl Audio DMIC cap",
490 .stream_name = "dmiccap",
491 .init = NULL,
492 .dpcm_capture = 1,
493 .nonatomic = 1,
494 .dynamic = 1,
495 .ops = &kabylake_dmic_ops,
496 SND_SOC_DAILINK_REG(dmic, dummy, platform),
497 },
498 [KBL_DPCM_AUDIO_HDMI1_PB] = {
499 .name = "Kbl HDMI Port1",
500 .stream_name = "Hdmi1",
501 .dpcm_playback = 1,
502 .init = NULL,
503 .trigger = {
504 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
505 .nonatomic = 1,
506 .dynamic = 1,
507 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
508 },
509 [KBL_DPCM_AUDIO_HDMI2_PB] = {
510 .name = "Kbl HDMI Port2",
511 .stream_name = "Hdmi2",
512 .dpcm_playback = 1,
513 .init = NULL,
514 .trigger = {
515 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
516 .nonatomic = 1,
517 .dynamic = 1,
518 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
519 },
520 [KBL_DPCM_AUDIO_HDMI3_PB] = {
521 .name = "Kbl HDMI Port3",
522 .stream_name = "Hdmi3",
523 .trigger = {
524 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
525 .dpcm_playback = 1,
526 .init = NULL,
527 .nonatomic = 1,
528 .dynamic = 1,
529 SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
530 },
531
532 /* Back End DAI links */
533 {
534 /* SSP0 - Codec */
535 .name = "SSP0-Codec",
536 .id = 0,
537 .no_pcm = 1,
538 .dai_fmt = SND_SOC_DAIFMT_I2S |
539 SND_SOC_DAIFMT_NB_NF |
540 SND_SOC_DAIFMT_CBC_CFC,
541 .ignore_pmdown_time = 1,
542 .be_hw_params_fixup = kabylake_ssp_fixup,
543 .dpcm_playback = 1,
544 SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
545 },
546 {
547 /* SSP1 - Codec */
548 .name = "SSP1-Codec",
549 .id = 1,
550 .no_pcm = 1,
551 .init = kabylake_da7219_codec_init,
552 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
553 SND_SOC_DAIFMT_CBC_CFC,
554 .ignore_pmdown_time = 1,
555 .be_hw_params_fixup = kabylake_ssp_fixup,
556 .dpcm_playback = 1,
557 .dpcm_capture = 1,
558 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
559 },
560 {
561 .name = "dmic01",
562 .id = 2,
563 .be_hw_params_fixup = kabylake_dmic_fixup,
564 .ignore_suspend = 1,
565 .dpcm_capture = 1,
566 .no_pcm = 1,
567 SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
568 },
569 {
570 .name = "iDisp1",
571 .id = 3,
572 .dpcm_playback = 1,
573 .init = kabylake_hdmi1_init,
574 .no_pcm = 1,
575 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
576 },
577 {
578 .name = "iDisp2",
579 .id = 4,
580 .init = kabylake_hdmi2_init,
581 .dpcm_playback = 1,
582 .no_pcm = 1,
583 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
584 },
585 {
586 .name = "iDisp3",
587 .id = 5,
588 .init = kabylake_hdmi3_init,
589 .dpcm_playback = 1,
590 .no_pcm = 1,
591 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
592 },
593 };
594
595 #define NAME_SIZE 32
kabylake_card_late_probe(struct snd_soc_card * card)596 static int kabylake_card_late_probe(struct snd_soc_card *card)
597 {
598 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
599 struct kbl_hdmi_pcm *pcm;
600 struct snd_soc_component *component = NULL;
601 int err, i = 0;
602 char jack_name[NAME_SIZE];
603
604 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
605 component = pcm->codec_dai->component;
606 snprintf(jack_name, sizeof(jack_name),
607 "HDMI/DP, pcm=%d Jack", pcm->device);
608 err = snd_soc_card_jack_new(card, jack_name,
609 SND_JACK_AVOUT, &skylake_hdmi[i]);
610
611 if (err)
612 return err;
613
614 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
615 &skylake_hdmi[i]);
616 if (err < 0)
617 return err;
618
619 i++;
620
621 }
622
623 if (!component)
624 return -EINVAL;
625
626 return hdac_hdmi_jack_port_init(component, &card->dapm);
627 }
628
629 /* kabylake audio machine driver for SPT + DA7219 */
630 static struct snd_soc_card kabylake_audio_card_da7219_m98357a = {
631 .name = "kblda7219max",
632 .owner = THIS_MODULE,
633 .dai_link = kabylake_dais,
634 .num_links = ARRAY_SIZE(kabylake_dais),
635 .controls = kabylake_controls,
636 .num_controls = ARRAY_SIZE(kabylake_controls),
637 .dapm_widgets = kabylake_widgets,
638 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
639 .dapm_routes = kabylake_map,
640 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
641 .fully_routed = true,
642 .late_probe = kabylake_card_late_probe,
643 };
644
kabylake_audio_probe(struct platform_device * pdev)645 static int kabylake_audio_probe(struct platform_device *pdev)
646 {
647 struct kbl_codec_private *ctx;
648
649 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
650 if (!ctx)
651 return -ENOMEM;
652
653 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
654
655 kabylake_audio_card =
656 (struct snd_soc_card *)pdev->id_entry->driver_data;
657
658 kabylake_audio_card->dev = &pdev->dev;
659 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
660 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
661 }
662
663 static const struct platform_device_id kbl_board_ids[] = {
664 {
665 .name = "kbl_da7219_mx98357a",
666 .driver_data =
667 (kernel_ulong_t)&kabylake_audio_card_da7219_m98357a,
668 },
669 { }
670 };
671 MODULE_DEVICE_TABLE(platform, kbl_board_ids);
672
673 static struct platform_driver kabylake_audio = {
674 .probe = kabylake_audio_probe,
675 .driver = {
676 .name = "kbl_da7219_max98357a",
677 .pm = &snd_soc_pm_ops,
678 },
679 .id_table = kbl_board_ids,
680 };
681
682 module_platform_driver(kabylake_audio)
683
684 /* Module information */
685 MODULE_DESCRIPTION("Audio Machine driver-DA7219 & MAX98357A in I2S mode");
686 MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
687 MODULE_LICENSE("GPL v2");
688