Linux 4.15.6
[linux/fpc-iii.git] / sound / soc / intel / boards / kbl_rt5663_max98927.c
blob6dcad0a8a0d045969873d983fa8b89bbe1f91e96
1 /*
2 * Intel Kabylake I2S Machine Driver with MAXIM98927
3 * and RT5663 Codecs
5 * Copyright (C) 2017, Intel Corporation. All rights reserved.
7 * Modified from:
8 * Intel Skylake I2S Machine driver
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License version
12 * 2 as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #include <linux/input.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <sound/core.h>
24 #include <sound/jack.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/soc.h>
28 #include "../../codecs/rt5663.h"
29 #include "../../codecs/hdac_hdmi.h"
30 #include "../skylake/skl.h"
32 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
33 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
34 #define DMIC_CH(p) p->list[p->count-1]
35 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
36 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
38 static struct snd_soc_card *kabylake_audio_card;
39 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
40 static struct snd_soc_jack skylake_hdmi[3];
42 struct kbl_hdmi_pcm {
43 struct list_head head;
44 struct snd_soc_dai *codec_dai;
45 int device;
48 struct kbl_rt5663_private {
49 struct snd_soc_jack kabylake_headset;
50 struct list_head hdmi_pcm_list;
53 enum {
54 KBL_DPCM_AUDIO_PB = 0,
55 KBL_DPCM_AUDIO_CP,
56 KBL_DPCM_AUDIO_HS_PB,
57 KBL_DPCM_AUDIO_ECHO_REF_CP,
58 KBL_DPCM_AUDIO_REF_CP,
59 KBL_DPCM_AUDIO_DMIC_CP,
60 KBL_DPCM_AUDIO_HDMI1_PB,
61 KBL_DPCM_AUDIO_HDMI2_PB,
62 KBL_DPCM_AUDIO_HDMI3_PB,
65 static const struct snd_kcontrol_new kabylake_controls[] = {
66 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
67 SOC_DAPM_PIN_SWITCH("Headset Mic"),
68 SOC_DAPM_PIN_SWITCH("Left Spk"),
69 SOC_DAPM_PIN_SWITCH("Right Spk"),
72 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
73 SND_SOC_DAPM_HP("Headphone Jack", NULL),
74 SND_SOC_DAPM_MIC("Headset Mic", NULL),
75 SND_SOC_DAPM_SPK("Left Spk", NULL),
76 SND_SOC_DAPM_SPK("Right Spk", NULL),
77 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
78 SND_SOC_DAPM_SPK("HDMI1", NULL),
79 SND_SOC_DAPM_SPK("HDMI2", NULL),
80 SND_SOC_DAPM_SPK("HDMI3", NULL),
84 static const struct snd_soc_dapm_route kabylake_map[] = {
85 /* HP jack connectors - unknown if we have jack detection */
86 { "Headphone Jack", NULL, "HPOL" },
87 { "Headphone Jack", NULL, "HPOR" },
89 /* speaker */
90 { "Left Spk", NULL, "Left BE_OUT" },
91 { "Right Spk", NULL, "Right BE_OUT" },
93 /* other jacks */
94 { "IN1P", NULL, "Headset Mic" },
95 { "IN1N", NULL, "Headset Mic" },
96 { "DMic", NULL, "SoC DMIC" },
98 /* CODEC BE connections */
99 { "Left HiFi Playback", NULL, "ssp0 Tx" },
100 { "Right HiFi Playback", NULL, "ssp0 Tx" },
101 { "ssp0 Tx", NULL, "spk_out" },
103 { "AIF Playback", NULL, "ssp1 Tx" },
104 { "ssp1 Tx", NULL, "codec1_out" },
106 { "hs_in", NULL, "ssp1 Rx" },
107 { "ssp1 Rx", NULL, "AIF Capture" },
109 /* IV feedback path */
110 { "codec0_fb_in", NULL, "ssp0 Rx"},
111 { "ssp0 Rx", NULL, "Left HiFi Capture" },
112 { "ssp0 Rx", NULL, "Right HiFi Capture" },
114 /* DMIC */
115 { "dmic01_hifi", NULL, "DMIC01 Rx" },
116 { "DMIC01 Rx", NULL, "DMIC AIF" },
118 { "hifi3", NULL, "iDisp3 Tx"},
119 { "iDisp3 Tx", NULL, "iDisp3_out"},
120 { "hifi2", NULL, "iDisp2 Tx"},
121 { "iDisp2 Tx", NULL, "iDisp2_out"},
122 { "hifi1", NULL, "iDisp1 Tx"},
123 { "iDisp1 Tx", NULL, "iDisp1_out"},
126 enum {
127 KBL_DPCM_AUDIO_5663_PB = 0,
128 KBL_DPCM_AUDIO_5663_CP,
129 KBL_DPCM_AUDIO_5663_HDMI1_PB,
130 KBL_DPCM_AUDIO_5663_HDMI2_PB,
133 static const struct snd_kcontrol_new kabylake_5663_controls[] = {
134 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
135 SOC_DAPM_PIN_SWITCH("Headset Mic"),
138 static const struct snd_soc_dapm_widget kabylake_5663_widgets[] = {
139 SND_SOC_DAPM_HP("Headphone Jack", NULL),
140 SND_SOC_DAPM_MIC("Headset Mic", NULL),
141 SND_SOC_DAPM_SPK("DP", NULL),
142 SND_SOC_DAPM_SPK("HDMI", NULL),
145 static const struct snd_soc_dapm_route kabylake_5663_map[] = {
146 { "Headphone Jack", NULL, "HPOL" },
147 { "Headphone Jack", NULL, "HPOR" },
149 /* other jacks */
150 { "IN1P", NULL, "Headset Mic" },
151 { "IN1N", NULL, "Headset Mic" },
153 { "HDMI", NULL, "hif5 Output" },
154 { "DP", NULL, "hif6 Output" },
156 /* CODEC BE connections */
157 { "AIF Playback", NULL, "ssp1 Tx" },
158 { "ssp1 Tx", NULL, "codec1_out" },
160 { "codec0_in", NULL, "ssp1 Rx" },
161 { "ssp1 Rx", NULL, "AIF Capture" },
163 { "hifi2", NULL, "iDisp2 Tx"},
164 { "iDisp2 Tx", NULL, "iDisp2_out"},
165 { "hifi1", NULL, "iDisp1 Tx"},
166 { "iDisp1 Tx", NULL, "iDisp1_out"},
169 static struct snd_soc_codec_conf max98927_codec_conf[] = {
171 .dev_name = MAXIM_DEV0_NAME,
172 .name_prefix = "Right",
175 .dev_name = MAXIM_DEV1_NAME,
176 .name_prefix = "Left",
180 static struct snd_soc_dai_link_component max98927_codec_components[] = {
181 { /* Left */
182 .name = MAXIM_DEV0_NAME,
183 .dai_name = KBL_MAXIM_CODEC_DAI,
185 { /* Right */
186 .name = MAXIM_DEV1_NAME,
187 .dai_name = KBL_MAXIM_CODEC_DAI,
191 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
193 int ret;
194 struct snd_soc_dapm_context *dapm;
195 struct snd_soc_component *component = rtd->cpu_dai->component;
197 dapm = snd_soc_component_get_dapm(component);
198 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
199 if (ret) {
200 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
201 return ret;
204 return ret;
207 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
209 int ret;
210 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
211 struct snd_soc_codec *codec = rtd->codec;
212 struct snd_soc_jack *jack;
215 * Headset buttons map to the google Reference headset.
216 * These can be configured by userspace.
218 ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
219 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
220 SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
221 NULL, 0);
222 if (ret) {
223 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
224 return ret;
227 jack = &ctx->kabylake_headset;
228 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
229 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
230 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
231 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
233 rt5663_set_jack_detect(codec, &ctx->kabylake_headset);
234 return ret;
237 static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime *rtd)
239 int ret;
241 ret = kabylake_rt5663_codec_init(rtd);
242 if (ret)
243 return ret;
245 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
246 if (ret) {
247 dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret);
248 return ret;
251 return ret;
254 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
256 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
257 struct snd_soc_dai *dai = rtd->codec_dai;
258 struct kbl_hdmi_pcm *pcm;
260 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
261 if (!pcm)
262 return -ENOMEM;
264 pcm->device = device;
265 pcm->codec_dai = dai;
267 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
269 return 0;
272 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
274 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
277 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
279 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
282 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
284 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
287 static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
289 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI1_PB);
292 static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
294 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB);
297 static unsigned int rates[] = {
298 48000,
301 static const struct snd_pcm_hw_constraint_list constraints_rates = {
302 .count = ARRAY_SIZE(rates),
303 .list = rates,
304 .mask = 0,
307 static unsigned int channels[] = {
311 static const struct snd_pcm_hw_constraint_list constraints_channels = {
312 .count = ARRAY_SIZE(channels),
313 .list = channels,
314 .mask = 0,
317 static int kbl_fe_startup(struct snd_pcm_substream *substream)
319 struct snd_pcm_runtime *runtime = substream->runtime;
322 * On this platform for PCM device we support,
323 * 48Khz
324 * stereo
325 * 16 bit audio
328 runtime->hw.channels_max = 2;
329 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
330 &constraints_channels);
332 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
333 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
335 snd_pcm_hw_constraint_list(runtime, 0,
336 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
338 return 0;
341 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
342 .startup = kbl_fe_startup,
345 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
346 struct snd_pcm_hw_params *params)
348 struct snd_interval *rate = hw_param_interval(params,
349 SNDRV_PCM_HW_PARAM_RATE);
350 struct snd_interval *channels = hw_param_interval(params,
351 SNDRV_PCM_HW_PARAM_CHANNELS);
352 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
353 struct snd_soc_dpcm *dpcm = container_of(
354 params, struct snd_soc_dpcm, hw_params);
355 struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
356 struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
359 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
361 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
362 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
363 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
364 rate->min = rate->max = 48000;
365 channels->min = channels->max = 2;
366 snd_mask_none(fmt);
367 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
370 * The speaker on the SSP0 supports S16_LE and not S24_LE.
371 * thus changing the mask here
373 if (!strcmp(be_dai_link->name, "SSP0-Codec"))
374 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S16_LE);
376 return 0;
379 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
380 struct snd_pcm_hw_params *params)
382 struct snd_soc_pcm_runtime *rtd = substream->private_data;
383 struct snd_soc_dai *codec_dai = rtd->codec_dai;
384 int ret;
386 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
387 rt5663_sel_asrc_clk_src(codec_dai->codec,
388 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
389 RT5663_CLK_SEL_I2S1_ASRC);
391 ret = snd_soc_dai_set_sysclk(codec_dai,
392 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
393 if (ret < 0)
394 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
396 return ret;
399 static struct snd_soc_ops kabylake_rt5663_ops = {
400 .hw_params = kabylake_rt5663_hw_params,
403 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
404 struct snd_pcm_hw_params *params)
406 struct snd_interval *channels = hw_param_interval(params,
407 SNDRV_PCM_HW_PARAM_CHANNELS);
409 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
410 channels->min = channels->max = 2;
411 else
412 channels->min = channels->max = 4;
414 return 0;
417 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
418 struct snd_pcm_hw_params *params)
420 struct snd_soc_pcm_runtime *rtd = substream->private_data;
421 int ret = 0, j;
423 for (j = 0; j < rtd->num_codecs; j++) {
424 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
426 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
428 * Use channel 4 and 5 for the first amp
430 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
431 if (ret < 0) {
432 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
433 return ret;
436 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
438 * Use channel 6 and 7 for the second amp
440 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
441 if (ret < 0) {
442 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
443 return ret;
447 return ret;
450 static struct snd_soc_ops kabylake_ssp0_ops = {
451 .hw_params = kabylake_ssp0_hw_params,
454 static unsigned int channels_dmic[] = {
455 2, 4,
458 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
459 .count = ARRAY_SIZE(channels_dmic),
460 .list = channels_dmic,
461 .mask = 0,
464 static const unsigned int dmic_2ch[] = {
468 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
469 .count = ARRAY_SIZE(dmic_2ch),
470 .list = dmic_2ch,
471 .mask = 0,
474 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
476 struct snd_pcm_runtime *runtime = substream->runtime;
478 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
479 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
480 dmic_constraints);
482 return snd_pcm_hw_constraint_list(substream->runtime, 0,
483 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
486 static struct snd_soc_ops kabylake_dmic_ops = {
487 .startup = kabylake_dmic_startup,
490 static unsigned int rates_16000[] = {
491 16000,
494 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
495 .count = ARRAY_SIZE(rates_16000),
496 .list = rates_16000,
499 static const unsigned int ch_mono[] = {
503 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
504 .count = ARRAY_SIZE(ch_mono),
505 .list = ch_mono,
508 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
510 substream->runtime->hw.channels_max = 1;
511 snd_pcm_hw_constraint_list(substream->runtime, 0,
512 SNDRV_PCM_HW_PARAM_CHANNELS,
513 &constraints_refcap);
515 return snd_pcm_hw_constraint_list(substream->runtime, 0,
516 SNDRV_PCM_HW_PARAM_RATE,
517 &constraints_16000);
520 static struct snd_soc_ops skylaye_refcap_ops = {
521 .startup = kabylake_refcap_startup,
524 /* kabylake digital audio interface glue - connects codec <--> CPU */
525 static struct snd_soc_dai_link kabylake_dais[] = {
526 /* Front End DAI links */
527 [KBL_DPCM_AUDIO_PB] = {
528 .name = "Kbl Audio Port",
529 .stream_name = "Audio",
530 .cpu_dai_name = "System Pin",
531 .platform_name = "0000:00:1f.3",
532 .dynamic = 1,
533 .codec_name = "snd-soc-dummy",
534 .codec_dai_name = "snd-soc-dummy-dai",
535 .nonatomic = 1,
536 .init = kabylake_rt5663_fe_init,
537 .trigger = {
538 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
539 .dpcm_playback = 1,
540 .ops = &kabylake_rt5663_fe_ops,
542 [KBL_DPCM_AUDIO_CP] = {
543 .name = "Kbl Audio Capture Port",
544 .stream_name = "Audio Record",
545 .cpu_dai_name = "System Pin",
546 .platform_name = "0000:00:1f.3",
547 .dynamic = 1,
548 .codec_name = "snd-soc-dummy",
549 .codec_dai_name = "snd-soc-dummy-dai",
550 .nonatomic = 1,
551 .trigger = {
552 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
553 .dpcm_capture = 1,
554 .ops = &kabylake_rt5663_fe_ops,
556 [KBL_DPCM_AUDIO_HS_PB] = {
557 .name = "Kbl Audio Headset Playback",
558 .stream_name = "Headset Audio",
559 .cpu_dai_name = "System Pin2",
560 .codec_name = "snd-soc-dummy",
561 .codec_dai_name = "snd-soc-dummy-dai",
562 .platform_name = "0000:00:1f.3",
563 .dpcm_playback = 1,
564 .nonatomic = 1,
565 .dynamic = 1,
567 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
568 .name = "Kbl Audio Echo Reference cap",
569 .stream_name = "Echoreference Capture",
570 .cpu_dai_name = "Echoref Pin",
571 .codec_name = "snd-soc-dummy",
572 .codec_dai_name = "snd-soc-dummy-dai",
573 .platform_name = "0000:00:1f.3",
574 .init = NULL,
575 .capture_only = 1,
576 .nonatomic = 1,
578 [KBL_DPCM_AUDIO_REF_CP] = {
579 .name = "Kbl Audio Reference cap",
580 .stream_name = "Wake on Voice",
581 .cpu_dai_name = "Reference Pin",
582 .codec_name = "snd-soc-dummy",
583 .codec_dai_name = "snd-soc-dummy-dai",
584 .platform_name = "0000:00:1f.3",
585 .init = NULL,
586 .dpcm_capture = 1,
587 .nonatomic = 1,
588 .dynamic = 1,
589 .ops = &skylaye_refcap_ops,
591 [KBL_DPCM_AUDIO_DMIC_CP] = {
592 .name = "Kbl Audio DMIC cap",
593 .stream_name = "dmiccap",
594 .cpu_dai_name = "DMIC Pin",
595 .codec_name = "snd-soc-dummy",
596 .codec_dai_name = "snd-soc-dummy-dai",
597 .platform_name = "0000:00:1f.3",
598 .init = NULL,
599 .dpcm_capture = 1,
600 .nonatomic = 1,
601 .dynamic = 1,
602 .ops = &kabylake_dmic_ops,
604 [KBL_DPCM_AUDIO_HDMI1_PB] = {
605 .name = "Kbl HDMI Port1",
606 .stream_name = "Hdmi1",
607 .cpu_dai_name = "HDMI1 Pin",
608 .codec_name = "snd-soc-dummy",
609 .codec_dai_name = "snd-soc-dummy-dai",
610 .platform_name = "0000:00:1f.3",
611 .dpcm_playback = 1,
612 .init = NULL,
613 .trigger = {
614 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
615 .nonatomic = 1,
616 .dynamic = 1,
618 [KBL_DPCM_AUDIO_HDMI2_PB] = {
619 .name = "Kbl HDMI Port2",
620 .stream_name = "Hdmi2",
621 .cpu_dai_name = "HDMI2 Pin",
622 .codec_name = "snd-soc-dummy",
623 .codec_dai_name = "snd-soc-dummy-dai",
624 .platform_name = "0000:00:1f.3",
625 .dpcm_playback = 1,
626 .init = NULL,
627 .trigger = {
628 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
629 .nonatomic = 1,
630 .dynamic = 1,
632 [KBL_DPCM_AUDIO_HDMI3_PB] = {
633 .name = "Kbl HDMI Port3",
634 .stream_name = "Hdmi3",
635 .cpu_dai_name = "HDMI3 Pin",
636 .codec_name = "snd-soc-dummy",
637 .codec_dai_name = "snd-soc-dummy-dai",
638 .platform_name = "0000:00:1f.3",
639 .trigger = {
640 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
641 .dpcm_playback = 1,
642 .init = NULL,
643 .nonatomic = 1,
644 .dynamic = 1,
647 /* Back End DAI links */
649 /* SSP0 - Codec */
650 .name = "SSP0-Codec",
651 .id = 0,
652 .cpu_dai_name = "SSP0 Pin",
653 .platform_name = "0000:00:1f.3",
654 .no_pcm = 1,
655 .codecs = max98927_codec_components,
656 .num_codecs = ARRAY_SIZE(max98927_codec_components),
657 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
658 SND_SOC_DAIFMT_NB_NF |
659 SND_SOC_DAIFMT_CBS_CFS,
660 .ignore_pmdown_time = 1,
661 .be_hw_params_fixup = kabylake_ssp_fixup,
662 .dpcm_playback = 1,
663 .ops = &kabylake_ssp0_ops,
666 /* SSP1 - Codec */
667 .name = "SSP1-Codec",
668 .id = 1,
669 .cpu_dai_name = "SSP1 Pin",
670 .platform_name = "0000:00:1f.3",
671 .no_pcm = 1,
672 .codec_name = "i2c-10EC5663:00",
673 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
674 .init = kabylake_rt5663_max98927_codec_init,
675 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
676 SND_SOC_DAIFMT_CBS_CFS,
677 .ignore_pmdown_time = 1,
678 .be_hw_params_fixup = kabylake_ssp_fixup,
679 .ops = &kabylake_rt5663_ops,
680 .dpcm_playback = 1,
681 .dpcm_capture = 1,
684 .name = "dmic01",
685 .id = 2,
686 .cpu_dai_name = "DMIC01 Pin",
687 .codec_name = "dmic-codec",
688 .codec_dai_name = "dmic-hifi",
689 .platform_name = "0000:00:1f.3",
690 .be_hw_params_fixup = kabylake_dmic_fixup,
691 .ignore_suspend = 1,
692 .dpcm_capture = 1,
693 .no_pcm = 1,
696 .name = "iDisp1",
697 .id = 3,
698 .cpu_dai_name = "iDisp1 Pin",
699 .codec_name = "ehdaudio0D2",
700 .codec_dai_name = "intel-hdmi-hifi1",
701 .platform_name = "0000:00:1f.3",
702 .dpcm_playback = 1,
703 .init = kabylake_hdmi1_init,
704 .no_pcm = 1,
707 .name = "iDisp2",
708 .id = 4,
709 .cpu_dai_name = "iDisp2 Pin",
710 .codec_name = "ehdaudio0D2",
711 .codec_dai_name = "intel-hdmi-hifi2",
712 .platform_name = "0000:00:1f.3",
713 .init = kabylake_hdmi2_init,
714 .dpcm_playback = 1,
715 .no_pcm = 1,
718 .name = "iDisp3",
719 .id = 5,
720 .cpu_dai_name = "iDisp3 Pin",
721 .codec_name = "ehdaudio0D2",
722 .codec_dai_name = "intel-hdmi-hifi3",
723 .platform_name = "0000:00:1f.3",
724 .init = kabylake_hdmi3_init,
725 .dpcm_playback = 1,
726 .no_pcm = 1,
730 static struct snd_soc_dai_link kabylake_5663_dais[] = {
731 /* Front End DAI links */
732 [KBL_DPCM_AUDIO_5663_PB] = {
733 .name = "Kbl Audio Port",
734 .stream_name = "Audio",
735 .cpu_dai_name = "System Pin",
736 .platform_name = "0000:00:1f.3",
737 .dynamic = 1,
738 .codec_name = "snd-soc-dummy",
739 .codec_dai_name = "snd-soc-dummy-dai",
740 .nonatomic = 1,
741 .trigger = {
742 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
743 .dpcm_playback = 1,
744 .ops = &kabylake_rt5663_fe_ops,
746 [KBL_DPCM_AUDIO_5663_CP] = {
747 .name = "Kbl Audio Capture Port",
748 .stream_name = "Audio Record",
749 .cpu_dai_name = "System Pin",
750 .platform_name = "0000:00:1f.3",
751 .dynamic = 1,
752 .codec_name = "snd-soc-dummy",
753 .codec_dai_name = "snd-soc-dummy-dai",
754 .nonatomic = 1,
755 .trigger = {
756 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
757 .dpcm_capture = 1,
758 .ops = &kabylake_rt5663_fe_ops,
760 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
761 .name = "Kbl HDMI Port1",
762 .stream_name = "Hdmi1",
763 .cpu_dai_name = "HDMI1 Pin",
764 .codec_name = "snd-soc-dummy",
765 .codec_dai_name = "snd-soc-dummy-dai",
766 .platform_name = "0000:00:1f.3",
767 .dpcm_playback = 1,
768 .init = NULL,
769 .trigger = {
770 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
771 .nonatomic = 1,
772 .dynamic = 1,
774 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
775 .name = "Kbl HDMI Port2",
776 .stream_name = "Hdmi2",
777 .cpu_dai_name = "HDMI2 Pin",
778 .codec_name = "snd-soc-dummy",
779 .codec_dai_name = "snd-soc-dummy-dai",
780 .platform_name = "0000:00:1f.3",
781 .dpcm_playback = 1,
782 .init = NULL,
783 .trigger = {
784 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
785 .nonatomic = 1,
786 .dynamic = 1,
789 /* Back End DAI links */
791 /* SSP1 - Codec */
792 .name = "SSP1-Codec",
793 .id = 0,
794 .cpu_dai_name = "SSP1 Pin",
795 .platform_name = "0000:00:1f.3",
796 .no_pcm = 1,
797 .codec_name = "i2c-10EC5663:00",
798 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
799 .init = kabylake_rt5663_codec_init,
800 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
801 SND_SOC_DAIFMT_CBS_CFS,
802 .ignore_pmdown_time = 1,
803 .be_hw_params_fixup = kabylake_ssp_fixup,
804 .ops = &kabylake_rt5663_ops,
805 .dpcm_playback = 1,
806 .dpcm_capture = 1,
809 .name = "iDisp1",
810 .id = 1,
811 .cpu_dai_name = "iDisp1 Pin",
812 .codec_name = "ehdaudio0D2",
813 .codec_dai_name = "intel-hdmi-hifi1",
814 .platform_name = "0000:00:1f.3",
815 .dpcm_playback = 1,
816 .init = kabylake_5663_hdmi1_init,
817 .no_pcm = 1,
820 .name = "iDisp2",
821 .id = 2,
822 .cpu_dai_name = "iDisp2 Pin",
823 .codec_name = "ehdaudio0D2",
824 .codec_dai_name = "intel-hdmi-hifi2",
825 .platform_name = "0000:00:1f.3",
826 .init = kabylake_5663_hdmi2_init,
827 .dpcm_playback = 1,
828 .no_pcm = 1,
832 #define NAME_SIZE 32
833 static int kabylake_card_late_probe(struct snd_soc_card *card)
835 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
836 struct kbl_hdmi_pcm *pcm;
837 struct snd_soc_codec *codec = NULL;
838 int err, i = 0;
839 char jack_name[NAME_SIZE];
841 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
842 codec = pcm->codec_dai->codec;
843 snprintf(jack_name, sizeof(jack_name),
844 "HDMI/DP, pcm=%d Jack", pcm->device);
845 err = snd_soc_card_jack_new(card, jack_name,
846 SND_JACK_AVOUT, &skylake_hdmi[i],
847 NULL, 0);
849 if (err)
850 return err;
852 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
853 &skylake_hdmi[i]);
854 if (err < 0)
855 return err;
857 i++;
860 if (!codec)
861 return -EINVAL;
863 return hdac_hdmi_jack_port_init(codec, &card->dapm);
866 /* kabylake audio machine driver for SPT + RT5663 */
867 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
868 .name = "kblrt5663max",
869 .owner = THIS_MODULE,
870 .dai_link = kabylake_dais,
871 .num_links = ARRAY_SIZE(kabylake_dais),
872 .controls = kabylake_controls,
873 .num_controls = ARRAY_SIZE(kabylake_controls),
874 .dapm_widgets = kabylake_widgets,
875 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
876 .dapm_routes = kabylake_map,
877 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
878 .codec_conf = max98927_codec_conf,
879 .num_configs = ARRAY_SIZE(max98927_codec_conf),
880 .fully_routed = true,
881 .late_probe = kabylake_card_late_probe,
884 /* kabylake audio machine driver for RT5663 */
885 static struct snd_soc_card kabylake_audio_card_rt5663 = {
886 .name = "kblrt5663",
887 .owner = THIS_MODULE,
888 .dai_link = kabylake_5663_dais,
889 .num_links = ARRAY_SIZE(kabylake_5663_dais),
890 .controls = kabylake_5663_controls,
891 .num_controls = ARRAY_SIZE(kabylake_5663_controls),
892 .dapm_widgets = kabylake_5663_widgets,
893 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
894 .dapm_routes = kabylake_5663_map,
895 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
896 .fully_routed = true,
897 .late_probe = kabylake_card_late_probe,
900 static int kabylake_audio_probe(struct platform_device *pdev)
902 struct kbl_rt5663_private *ctx;
903 struct skl_machine_pdata *pdata;
905 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
906 if (!ctx)
907 return -ENOMEM;
909 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
911 kabylake_audio_card =
912 (struct snd_soc_card *)pdev->id_entry->driver_data;
914 kabylake_audio_card->dev = &pdev->dev;
915 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
917 pdata = dev_get_drvdata(&pdev->dev);
918 if (pdata)
919 dmic_constraints = pdata->dmic_num == 2 ?
920 &constraints_dmic_2ch : &constraints_dmic_channels;
922 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
925 static const struct platform_device_id kbl_board_ids[] = {
927 .name = "kbl_rt5663",
928 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
931 .name = "kbl_rt5663_m98927",
932 .driver_data =
933 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
938 static struct platform_driver kabylake_audio = {
939 .probe = kabylake_audio_probe,
940 .driver = {
941 .name = "kbl_rt5663_m98927",
942 .pm = &snd_soc_pm_ops,
944 .id_table = kbl_board_ids,
947 module_platform_driver(kabylake_audio)
949 /* Module information */
950 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
951 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
952 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
953 MODULE_LICENSE("GPL v2");
954 MODULE_ALIAS("platform:kbl_rt5663");
955 MODULE_ALIAS("platform:kbl_rt5663_m98927");