2 * Intel Kabylake I2S Machine Driver with MAXIM98927
5 * Copyright (C) 2017, Intel Corporation. All rights reserved.
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"
31 #include <linux/clk.h>
32 #include <linux/clk-provider.h>
33 #include <linux/clkdev.h>
35 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
36 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
37 #define DMIC_CH(p) p->list[p->count-1]
38 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
39 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
41 static struct snd_soc_card *kabylake_audio_card;
42 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
43 static struct snd_soc_jack skylake_hdmi[3];
46 struct list_head head;
47 struct snd_soc_dai *codec_dai;
51 struct kbl_rt5663_private {
52 struct snd_soc_jack kabylake_headset;
53 struct list_head hdmi_pcm_list;
59 KBL_DPCM_AUDIO_PB = 0,
62 KBL_DPCM_AUDIO_ECHO_REF_CP,
63 KBL_DPCM_AUDIO_REF_CP,
64 KBL_DPCM_AUDIO_DMIC_CP,
65 KBL_DPCM_AUDIO_HDMI1_PB,
66 KBL_DPCM_AUDIO_HDMI2_PB,
67 KBL_DPCM_AUDIO_HDMI3_PB,
70 static const struct snd_kcontrol_new kabylake_controls[] = {
71 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
72 SOC_DAPM_PIN_SWITCH("Headset Mic"),
73 SOC_DAPM_PIN_SWITCH("Left Spk"),
74 SOC_DAPM_PIN_SWITCH("Right Spk"),
77 static int platform_clock_control(struct snd_soc_dapm_widget *w,
78 struct snd_kcontrol *k, int event)
80 struct snd_soc_dapm_context *dapm = w->dapm;
81 struct snd_soc_card *card = dapm->card;
82 struct kbl_rt5663_private *priv = snd_soc_card_get_drvdata(card);
86 * MCLK/SCLK need to be ON early for a successful synchronization of
87 * codec internal clock. And the clocks are turned off during
88 * POST_PMD after the stream is stopped.
91 case SND_SOC_DAPM_PRE_PMU:
93 ret = clk_set_rate(priv->mclk, 24000000);
95 dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
100 ret = clk_prepare_enable(priv->mclk);
102 dev_err(card->dev, "Can't enable mclk, err: %d\n", ret);
107 ret = clk_set_rate(priv->sclk, 3072000);
109 dev_err(card->dev, "Can't set rate for sclk, err: %d\n",
111 clk_disable_unprepare(priv->mclk);
115 ret = clk_prepare_enable(priv->sclk);
117 dev_err(card->dev, "Can't enable sclk, err: %d\n", ret);
118 clk_disable_unprepare(priv->mclk);
121 case SND_SOC_DAPM_POST_PMD:
122 clk_disable_unprepare(priv->mclk);
123 clk_disable_unprepare(priv->sclk);
132 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
133 SND_SOC_DAPM_HP("Headphone Jack", NULL),
134 SND_SOC_DAPM_MIC("Headset Mic", NULL),
135 SND_SOC_DAPM_SPK("Left Spk", NULL),
136 SND_SOC_DAPM_SPK("Right Spk", NULL),
137 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
138 SND_SOC_DAPM_SPK("HDMI1", NULL),
139 SND_SOC_DAPM_SPK("HDMI2", NULL),
140 SND_SOC_DAPM_SPK("HDMI3", NULL),
141 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
142 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
143 SND_SOC_DAPM_POST_PMD),
146 static const struct snd_soc_dapm_route kabylake_map[] = {
147 /* HP jack connectors - unknown if we have jack detection */
148 { "Headphone Jack", NULL, "Platform Clock" },
149 { "Headphone Jack", NULL, "HPOL" },
150 { "Headphone Jack", NULL, "HPOR" },
153 { "Left Spk", NULL, "Left BE_OUT" },
154 { "Right Spk", NULL, "Right BE_OUT" },
157 { "Headset Mic", NULL, "Platform Clock" },
158 { "IN1P", NULL, "Headset Mic" },
159 { "IN1N", NULL, "Headset Mic" },
160 { "DMic", NULL, "SoC DMIC" },
162 /* CODEC BE connections */
163 { "Left HiFi Playback", NULL, "ssp0 Tx" },
164 { "Right HiFi Playback", NULL, "ssp0 Tx" },
165 { "ssp0 Tx", NULL, "spk_out" },
167 { "AIF Playback", NULL, "ssp1 Tx" },
168 { "ssp1 Tx", NULL, "codec1_out" },
170 { "hs_in", NULL, "ssp1 Rx" },
171 { "ssp1 Rx", NULL, "AIF Capture" },
173 /* IV feedback path */
174 { "codec0_fb_in", NULL, "ssp0 Rx"},
175 { "ssp0 Rx", NULL, "Left HiFi Capture" },
176 { "ssp0 Rx", NULL, "Right HiFi Capture" },
179 { "dmic01_hifi", NULL, "DMIC01 Rx" },
180 { "DMIC01 Rx", NULL, "DMIC AIF" },
182 { "hifi3", NULL, "iDisp3 Tx"},
183 { "iDisp3 Tx", NULL, "iDisp3_out"},
184 { "hifi2", NULL, "iDisp2 Tx"},
185 { "iDisp2 Tx", NULL, "iDisp2_out"},
186 { "hifi1", NULL, "iDisp1 Tx"},
187 { "iDisp1 Tx", NULL, "iDisp1_out"},
191 KBL_DPCM_AUDIO_5663_PB = 0,
192 KBL_DPCM_AUDIO_5663_CP,
193 KBL_DPCM_AUDIO_5663_HDMI1_PB,
194 KBL_DPCM_AUDIO_5663_HDMI2_PB,
197 static const struct snd_kcontrol_new kabylake_5663_controls[] = {
198 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
199 SOC_DAPM_PIN_SWITCH("Headset Mic"),
202 static const struct snd_soc_dapm_widget kabylake_5663_widgets[] = {
203 SND_SOC_DAPM_HP("Headphone Jack", NULL),
204 SND_SOC_DAPM_MIC("Headset Mic", NULL),
205 SND_SOC_DAPM_SPK("DP", NULL),
206 SND_SOC_DAPM_SPK("HDMI", NULL),
207 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
208 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
209 SND_SOC_DAPM_POST_PMD),
212 static const struct snd_soc_dapm_route kabylake_5663_map[] = {
213 { "Headphone Jack", NULL, "Platform Clock" },
214 { "Headphone Jack", NULL, "HPOL" },
215 { "Headphone Jack", NULL, "HPOR" },
218 { "Headset Mic", NULL, "Platform Clock" },
219 { "IN1P", NULL, "Headset Mic" },
220 { "IN1N", NULL, "Headset Mic" },
222 { "HDMI", NULL, "hif5 Output" },
223 { "DP", NULL, "hif6 Output" },
225 /* CODEC BE connections */
226 { "AIF Playback", NULL, "ssp1 Tx" },
227 { "ssp1 Tx", NULL, "codec1_out" },
229 { "codec0_in", NULL, "ssp1 Rx" },
230 { "ssp1 Rx", NULL, "AIF Capture" },
232 { "hifi2", NULL, "iDisp2 Tx"},
233 { "iDisp2 Tx", NULL, "iDisp2_out"},
234 { "hifi1", NULL, "iDisp1 Tx"},
235 { "iDisp1 Tx", NULL, "iDisp1_out"},
238 static struct snd_soc_codec_conf max98927_codec_conf[] = {
240 .dev_name = MAXIM_DEV0_NAME,
241 .name_prefix = "Right",
244 .dev_name = MAXIM_DEV1_NAME,
245 .name_prefix = "Left",
249 static struct snd_soc_dai_link_component max98927_codec_components[] = {
251 .name = MAXIM_DEV0_NAME,
252 .dai_name = KBL_MAXIM_CODEC_DAI,
255 .name = MAXIM_DEV1_NAME,
256 .dai_name = KBL_MAXIM_CODEC_DAI,
260 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
263 struct snd_soc_dapm_context *dapm;
264 struct snd_soc_component *component = rtd->cpu_dai->component;
266 dapm = snd_soc_component_get_dapm(component);
267 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
269 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
276 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
279 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
280 struct snd_soc_component *component = rtd->codec_dai->component;
281 struct snd_soc_jack *jack;
284 * Headset buttons map to the google Reference headset.
285 * These can be configured by userspace.
287 ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
288 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
289 SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
292 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
296 jack = &ctx->kabylake_headset;
297 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
298 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
299 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
300 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
302 snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
307 static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime *rtd)
311 ret = kabylake_rt5663_codec_init(rtd);
315 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
317 dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret);
324 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
326 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
327 struct snd_soc_dai *dai = rtd->codec_dai;
328 struct kbl_hdmi_pcm *pcm;
330 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
334 pcm->device = device;
335 pcm->codec_dai = dai;
337 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
342 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
344 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
347 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
349 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
352 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
354 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
357 static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
359 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI1_PB);
362 static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
364 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB);
367 static unsigned int rates[] = {
371 static const struct snd_pcm_hw_constraint_list constraints_rates = {
372 .count = ARRAY_SIZE(rates),
377 static unsigned int channels[] = {
381 static const struct snd_pcm_hw_constraint_list constraints_channels = {
382 .count = ARRAY_SIZE(channels),
387 static int kbl_fe_startup(struct snd_pcm_substream *substream)
389 struct snd_pcm_runtime *runtime = substream->runtime;
392 * On this platform for PCM device we support,
398 runtime->hw.channels_max = 2;
399 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
400 &constraints_channels);
402 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
403 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
405 snd_pcm_hw_constraint_list(runtime, 0,
406 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
411 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
412 .startup = kbl_fe_startup,
415 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
416 struct snd_pcm_hw_params *params)
418 struct snd_interval *rate = hw_param_interval(params,
419 SNDRV_PCM_HW_PARAM_RATE);
420 struct snd_interval *channels = hw_param_interval(params,
421 SNDRV_PCM_HW_PARAM_CHANNELS);
422 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
423 struct snd_soc_dpcm *dpcm = container_of(
424 params, struct snd_soc_dpcm, hw_params);
425 struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
426 struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
429 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
431 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
432 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
433 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
434 rate->min = rate->max = 48000;
435 channels->min = channels->max = 2;
437 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
440 * The speaker on the SSP0 supports S16_LE and not S24_LE.
441 * thus changing the mask here
443 if (!strcmp(be_dai_link->name, "SSP0-Codec"))
444 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
449 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
450 struct snd_pcm_hw_params *params)
452 struct snd_soc_pcm_runtime *rtd = substream->private_data;
453 struct snd_soc_dai *codec_dai = rtd->codec_dai;
456 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
457 rt5663_sel_asrc_clk_src(codec_dai->component,
458 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
459 RT5663_CLK_SEL_I2S1_ASRC);
461 ret = snd_soc_dai_set_sysclk(codec_dai,
462 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
464 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
469 static struct snd_soc_ops kabylake_rt5663_ops = {
470 .hw_params = kabylake_rt5663_hw_params,
473 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
474 struct snd_pcm_hw_params *params)
476 struct snd_interval *channels = hw_param_interval(params,
477 SNDRV_PCM_HW_PARAM_CHANNELS);
479 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
480 channels->min = channels->max = 2;
482 channels->min = channels->max = 4;
487 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
488 struct snd_pcm_hw_params *params)
490 struct snd_soc_pcm_runtime *rtd = substream->private_data;
493 for (j = 0; j < rtd->num_codecs; j++) {
494 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
496 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
498 * Use channel 4 and 5 for the first amp
500 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
502 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
506 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
508 * Use channel 6 and 7 for the second amp
510 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
512 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
520 static struct snd_soc_ops kabylake_ssp0_ops = {
521 .hw_params = kabylake_ssp0_hw_params,
524 static unsigned int channels_dmic[] = {
528 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
529 .count = ARRAY_SIZE(channels_dmic),
530 .list = channels_dmic,
534 static const unsigned int dmic_2ch[] = {
538 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
539 .count = ARRAY_SIZE(dmic_2ch),
544 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
546 struct snd_pcm_runtime *runtime = substream->runtime;
548 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
549 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
552 return snd_pcm_hw_constraint_list(substream->runtime, 0,
553 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
556 static struct snd_soc_ops kabylake_dmic_ops = {
557 .startup = kabylake_dmic_startup,
560 static unsigned int rates_16000[] = {
564 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
565 .count = ARRAY_SIZE(rates_16000),
569 static const unsigned int ch_mono[] = {
573 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
574 .count = ARRAY_SIZE(ch_mono),
578 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
580 substream->runtime->hw.channels_max = 1;
581 snd_pcm_hw_constraint_list(substream->runtime, 0,
582 SNDRV_PCM_HW_PARAM_CHANNELS,
583 &constraints_refcap);
585 return snd_pcm_hw_constraint_list(substream->runtime, 0,
586 SNDRV_PCM_HW_PARAM_RATE,
590 static struct snd_soc_ops skylaye_refcap_ops = {
591 .startup = kabylake_refcap_startup,
594 /* kabylake digital audio interface glue - connects codec <--> CPU */
595 static struct snd_soc_dai_link kabylake_dais[] = {
596 /* Front End DAI links */
597 [KBL_DPCM_AUDIO_PB] = {
598 .name = "Kbl Audio Port",
599 .stream_name = "Audio",
600 .cpu_dai_name = "System Pin",
601 .platform_name = "0000:00:1f.3",
603 .codec_name = "snd-soc-dummy",
604 .codec_dai_name = "snd-soc-dummy-dai",
606 .init = kabylake_rt5663_fe_init,
608 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
610 .ops = &kabylake_rt5663_fe_ops,
612 [KBL_DPCM_AUDIO_CP] = {
613 .name = "Kbl Audio Capture Port",
614 .stream_name = "Audio Record",
615 .cpu_dai_name = "System Pin",
616 .platform_name = "0000:00:1f.3",
618 .codec_name = "snd-soc-dummy",
619 .codec_dai_name = "snd-soc-dummy-dai",
622 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
624 .ops = &kabylake_rt5663_fe_ops,
626 [KBL_DPCM_AUDIO_HS_PB] = {
627 .name = "Kbl Audio Headset Playback",
628 .stream_name = "Headset Audio",
629 .cpu_dai_name = "System Pin2",
630 .codec_name = "snd-soc-dummy",
631 .codec_dai_name = "snd-soc-dummy-dai",
632 .platform_name = "0000:00:1f.3",
637 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
638 .name = "Kbl Audio Echo Reference cap",
639 .stream_name = "Echoreference Capture",
640 .cpu_dai_name = "Echoref Pin",
641 .codec_name = "snd-soc-dummy",
642 .codec_dai_name = "snd-soc-dummy-dai",
643 .platform_name = "0000:00:1f.3",
648 [KBL_DPCM_AUDIO_REF_CP] = {
649 .name = "Kbl Audio Reference cap",
650 .stream_name = "Wake on Voice",
651 .cpu_dai_name = "Reference Pin",
652 .codec_name = "snd-soc-dummy",
653 .codec_dai_name = "snd-soc-dummy-dai",
654 .platform_name = "0000:00:1f.3",
659 .ops = &skylaye_refcap_ops,
661 [KBL_DPCM_AUDIO_DMIC_CP] = {
662 .name = "Kbl Audio DMIC cap",
663 .stream_name = "dmiccap",
664 .cpu_dai_name = "DMIC Pin",
665 .codec_name = "snd-soc-dummy",
666 .codec_dai_name = "snd-soc-dummy-dai",
667 .platform_name = "0000:00:1f.3",
672 .ops = &kabylake_dmic_ops,
674 [KBL_DPCM_AUDIO_HDMI1_PB] = {
675 .name = "Kbl HDMI Port1",
676 .stream_name = "Hdmi1",
677 .cpu_dai_name = "HDMI1 Pin",
678 .codec_name = "snd-soc-dummy",
679 .codec_dai_name = "snd-soc-dummy-dai",
680 .platform_name = "0000:00:1f.3",
684 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
688 [KBL_DPCM_AUDIO_HDMI2_PB] = {
689 .name = "Kbl HDMI Port2",
690 .stream_name = "Hdmi2",
691 .cpu_dai_name = "HDMI2 Pin",
692 .codec_name = "snd-soc-dummy",
693 .codec_dai_name = "snd-soc-dummy-dai",
694 .platform_name = "0000:00:1f.3",
698 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
702 [KBL_DPCM_AUDIO_HDMI3_PB] = {
703 .name = "Kbl HDMI Port3",
704 .stream_name = "Hdmi3",
705 .cpu_dai_name = "HDMI3 Pin",
706 .codec_name = "snd-soc-dummy",
707 .codec_dai_name = "snd-soc-dummy-dai",
708 .platform_name = "0000:00:1f.3",
710 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
717 /* Back End DAI links */
720 .name = "SSP0-Codec",
722 .cpu_dai_name = "SSP0 Pin",
723 .platform_name = "0000:00:1f.3",
725 .codecs = max98927_codec_components,
726 .num_codecs = ARRAY_SIZE(max98927_codec_components),
727 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
728 SND_SOC_DAIFMT_NB_NF |
729 SND_SOC_DAIFMT_CBS_CFS,
730 .ignore_pmdown_time = 1,
731 .be_hw_params_fixup = kabylake_ssp_fixup,
733 .ops = &kabylake_ssp0_ops,
737 .name = "SSP1-Codec",
739 .cpu_dai_name = "SSP1 Pin",
740 .platform_name = "0000:00:1f.3",
742 .codec_name = "i2c-10EC5663:00",
743 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
744 .init = kabylake_rt5663_max98927_codec_init,
745 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
746 SND_SOC_DAIFMT_CBS_CFS,
747 .ignore_pmdown_time = 1,
748 .be_hw_params_fixup = kabylake_ssp_fixup,
749 .ops = &kabylake_rt5663_ops,
756 .cpu_dai_name = "DMIC01 Pin",
757 .codec_name = "dmic-codec",
758 .codec_dai_name = "dmic-hifi",
759 .platform_name = "0000:00:1f.3",
760 .be_hw_params_fixup = kabylake_dmic_fixup,
768 .cpu_dai_name = "iDisp1 Pin",
769 .codec_name = "ehdaudio0D2",
770 .codec_dai_name = "intel-hdmi-hifi1",
771 .platform_name = "0000:00:1f.3",
773 .init = kabylake_hdmi1_init,
779 .cpu_dai_name = "iDisp2 Pin",
780 .codec_name = "ehdaudio0D2",
781 .codec_dai_name = "intel-hdmi-hifi2",
782 .platform_name = "0000:00:1f.3",
783 .init = kabylake_hdmi2_init,
790 .cpu_dai_name = "iDisp3 Pin",
791 .codec_name = "ehdaudio0D2",
792 .codec_dai_name = "intel-hdmi-hifi3",
793 .platform_name = "0000:00:1f.3",
794 .init = kabylake_hdmi3_init,
800 static struct snd_soc_dai_link kabylake_5663_dais[] = {
801 /* Front End DAI links */
802 [KBL_DPCM_AUDIO_5663_PB] = {
803 .name = "Kbl Audio Port",
804 .stream_name = "Audio",
805 .cpu_dai_name = "System Pin",
806 .platform_name = "0000:00:1f.3",
808 .codec_name = "snd-soc-dummy",
809 .codec_dai_name = "snd-soc-dummy-dai",
812 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
814 .ops = &kabylake_rt5663_fe_ops,
816 [KBL_DPCM_AUDIO_5663_CP] = {
817 .name = "Kbl Audio Capture Port",
818 .stream_name = "Audio Record",
819 .cpu_dai_name = "System Pin",
820 .platform_name = "0000:00:1f.3",
822 .codec_name = "snd-soc-dummy",
823 .codec_dai_name = "snd-soc-dummy-dai",
826 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
828 .ops = &kabylake_rt5663_fe_ops,
830 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
831 .name = "Kbl HDMI Port1",
832 .stream_name = "Hdmi1",
833 .cpu_dai_name = "HDMI1 Pin",
834 .codec_name = "snd-soc-dummy",
835 .codec_dai_name = "snd-soc-dummy-dai",
836 .platform_name = "0000:00:1f.3",
840 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
844 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
845 .name = "Kbl HDMI Port2",
846 .stream_name = "Hdmi2",
847 .cpu_dai_name = "HDMI2 Pin",
848 .codec_name = "snd-soc-dummy",
849 .codec_dai_name = "snd-soc-dummy-dai",
850 .platform_name = "0000:00:1f.3",
854 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
859 /* Back End DAI links */
862 .name = "SSP1-Codec",
864 .cpu_dai_name = "SSP1 Pin",
865 .platform_name = "0000:00:1f.3",
867 .codec_name = "i2c-10EC5663:00",
868 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
869 .init = kabylake_rt5663_codec_init,
870 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
871 SND_SOC_DAIFMT_CBS_CFS,
872 .ignore_pmdown_time = 1,
873 .be_hw_params_fixup = kabylake_ssp_fixup,
874 .ops = &kabylake_rt5663_ops,
881 .cpu_dai_name = "iDisp1 Pin",
882 .codec_name = "ehdaudio0D2",
883 .codec_dai_name = "intel-hdmi-hifi1",
884 .platform_name = "0000:00:1f.3",
886 .init = kabylake_5663_hdmi1_init,
892 .cpu_dai_name = "iDisp2 Pin",
893 .codec_name = "ehdaudio0D2",
894 .codec_dai_name = "intel-hdmi-hifi2",
895 .platform_name = "0000:00:1f.3",
896 .init = kabylake_5663_hdmi2_init,
903 static int kabylake_card_late_probe(struct snd_soc_card *card)
905 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
906 struct kbl_hdmi_pcm *pcm;
907 struct snd_soc_component *component = NULL;
909 char jack_name[NAME_SIZE];
911 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
912 component = pcm->codec_dai->component;
913 snprintf(jack_name, sizeof(jack_name),
914 "HDMI/DP, pcm=%d Jack", pcm->device);
915 err = snd_soc_card_jack_new(card, jack_name,
916 SND_JACK_AVOUT, &skylake_hdmi[i],
922 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
933 return hdac_hdmi_jack_port_init(component, &card->dapm);
936 /* kabylake audio machine driver for SPT + RT5663 */
937 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
938 .name = "kblrt5663max",
939 .owner = THIS_MODULE,
940 .dai_link = kabylake_dais,
941 .num_links = ARRAY_SIZE(kabylake_dais),
942 .controls = kabylake_controls,
943 .num_controls = ARRAY_SIZE(kabylake_controls),
944 .dapm_widgets = kabylake_widgets,
945 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
946 .dapm_routes = kabylake_map,
947 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
948 .codec_conf = max98927_codec_conf,
949 .num_configs = ARRAY_SIZE(max98927_codec_conf),
950 .fully_routed = true,
951 .late_probe = kabylake_card_late_probe,
954 /* kabylake audio machine driver for RT5663 */
955 static struct snd_soc_card kabylake_audio_card_rt5663 = {
957 .owner = THIS_MODULE,
958 .dai_link = kabylake_5663_dais,
959 .num_links = ARRAY_SIZE(kabylake_5663_dais),
960 .controls = kabylake_5663_controls,
961 .num_controls = ARRAY_SIZE(kabylake_5663_controls),
962 .dapm_widgets = kabylake_5663_widgets,
963 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
964 .dapm_routes = kabylake_5663_map,
965 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
966 .fully_routed = true,
967 .late_probe = kabylake_card_late_probe,
970 static int kabylake_audio_probe(struct platform_device *pdev)
972 struct kbl_rt5663_private *ctx;
973 struct skl_machine_pdata *pdata;
976 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
980 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
982 kabylake_audio_card =
983 (struct snd_soc_card *)pdev->id_entry->driver_data;
985 kabylake_audio_card->dev = &pdev->dev;
986 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
988 pdata = dev_get_drvdata(&pdev->dev);
990 dmic_constraints = pdata->dmic_num == 2 ?
991 &constraints_dmic_2ch : &constraints_dmic_channels;
993 ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk");
994 if (IS_ERR(ctx->mclk)) {
995 ret = PTR_ERR(ctx->mclk);
996 if (ret == -ENOENT) {
998 "Failed to get ssp1_sclk, defer probe\n");
999 return -EPROBE_DEFER;
1002 dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n",
1007 ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk");
1008 if (IS_ERR(ctx->sclk)) {
1009 ret = PTR_ERR(ctx->sclk);
1010 if (ret == -ENOENT) {
1011 dev_info(&pdev->dev,
1012 "Failed to get ssp1_sclk, defer probe\n");
1013 return -EPROBE_DEFER;
1016 dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n",
1021 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
1024 static const struct platform_device_id kbl_board_ids[] = {
1026 .name = "kbl_rt5663",
1027 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
1030 .name = "kbl_rt5663_m98927",
1032 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
1037 static struct platform_driver kabylake_audio = {
1038 .probe = kabylake_audio_probe,
1040 .name = "kbl_rt5663_m98927",
1041 .pm = &snd_soc_pm_ops,
1043 .id_table = kbl_board_ids,
1046 module_platform_driver(kabylake_audio)
1048 /* Module information */
1049 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
1050 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
1051 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
1052 MODULE_LICENSE("GPL v2");
1053 MODULE_ALIAS("platform:kbl_rt5663");
1054 MODULE_ALIAS("platform:kbl_rt5663_m98927");