1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Kabylake I2S Machine Driver with MAXIM98927
6 * Copyright (C) 2017, Intel Corporation. All rights reserved.
9 * Intel Skylake I2S Machine driver
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 <sound/soc-acpi.h>
21 #include "../../codecs/rt5663.h"
22 #include "../../codecs/hdac_hdmi.h"
23 #include <linux/clk.h>
24 #include <linux/clk-provider.h>
25 #include <linux/clkdev.h>
27 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
28 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
29 #define DMIC_CH(p) p->list[p->count-1]
30 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
31 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
33 static struct snd_soc_card *kabylake_audio_card;
34 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
35 static struct snd_soc_jack skylake_hdmi[3];
38 struct list_head head;
39 struct snd_soc_dai *codec_dai;
43 struct kbl_rt5663_private {
44 struct snd_soc_jack kabylake_headset;
45 struct list_head hdmi_pcm_list;
51 KBL_DPCM_AUDIO_PB = 0,
54 KBL_DPCM_AUDIO_ECHO_REF_CP,
55 KBL_DPCM_AUDIO_REF_CP,
56 KBL_DPCM_AUDIO_DMIC_CP,
57 KBL_DPCM_AUDIO_HDMI1_PB,
58 KBL_DPCM_AUDIO_HDMI2_PB,
59 KBL_DPCM_AUDIO_HDMI3_PB,
62 static const struct snd_kcontrol_new kabylake_controls[] = {
63 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
64 SOC_DAPM_PIN_SWITCH("Headset Mic"),
65 SOC_DAPM_PIN_SWITCH("Left Spk"),
66 SOC_DAPM_PIN_SWITCH("Right Spk"),
69 static int platform_clock_control(struct snd_soc_dapm_widget *w,
70 struct snd_kcontrol *k, int event)
72 struct snd_soc_dapm_context *dapm = w->dapm;
73 struct snd_soc_card *card = dapm->card;
74 struct kbl_rt5663_private *priv = snd_soc_card_get_drvdata(card);
78 * MCLK/SCLK need to be ON early for a successful synchronization of
79 * codec internal clock. And the clocks are turned off during
80 * POST_PMD after the stream is stopped.
83 case SND_SOC_DAPM_PRE_PMU:
85 ret = clk_set_rate(priv->mclk, 24000000);
87 dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
92 ret = clk_prepare_enable(priv->mclk);
94 dev_err(card->dev, "Can't enable mclk, err: %d\n", ret);
99 ret = clk_set_rate(priv->sclk, 3072000);
101 dev_err(card->dev, "Can't set rate for sclk, err: %d\n",
103 clk_disable_unprepare(priv->mclk);
107 ret = clk_prepare_enable(priv->sclk);
109 dev_err(card->dev, "Can't enable sclk, err: %d\n", ret);
110 clk_disable_unprepare(priv->mclk);
113 case SND_SOC_DAPM_POST_PMD:
114 clk_disable_unprepare(priv->mclk);
115 clk_disable_unprepare(priv->sclk);
124 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
125 SND_SOC_DAPM_HP("Headphone Jack", NULL),
126 SND_SOC_DAPM_MIC("Headset Mic", NULL),
127 SND_SOC_DAPM_SPK("Left Spk", NULL),
128 SND_SOC_DAPM_SPK("Right Spk", NULL),
129 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
130 SND_SOC_DAPM_SPK("HDMI1", NULL),
131 SND_SOC_DAPM_SPK("HDMI2", NULL),
132 SND_SOC_DAPM_SPK("HDMI3", NULL),
133 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
134 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
135 SND_SOC_DAPM_POST_PMD),
138 static const struct snd_soc_dapm_route kabylake_map[] = {
139 /* HP jack connectors - unknown if we have jack detection */
140 { "Headphone Jack", NULL, "Platform Clock" },
141 { "Headphone Jack", NULL, "HPOL" },
142 { "Headphone Jack", NULL, "HPOR" },
145 { "Left Spk", NULL, "Left BE_OUT" },
146 { "Right Spk", NULL, "Right BE_OUT" },
149 { "Headset Mic", NULL, "Platform Clock" },
150 { "IN1P", NULL, "Headset Mic" },
151 { "IN1N", NULL, "Headset Mic" },
152 { "DMic", NULL, "SoC DMIC" },
154 {"HDMI1", NULL, "hif5-0 Output"},
155 {"HDMI2", NULL, "hif6-0 Output"},
156 {"HDMI3", NULL, "hif7-0 Output"},
158 /* CODEC BE connections */
159 { "Left HiFi Playback", NULL, "ssp0 Tx" },
160 { "Right HiFi Playback", NULL, "ssp0 Tx" },
161 { "ssp0 Tx", NULL, "spk_out" },
163 { "AIF Playback", NULL, "ssp1 Tx" },
164 { "ssp1 Tx", NULL, "codec1_out" },
166 { "hs_in", NULL, "ssp1 Rx" },
167 { "ssp1 Rx", NULL, "AIF Capture" },
169 /* IV feedback path */
170 { "codec0_fb_in", NULL, "ssp0 Rx"},
171 { "ssp0 Rx", NULL, "Left HiFi Capture" },
172 { "ssp0 Rx", NULL, "Right HiFi Capture" },
175 { "dmic01_hifi", NULL, "DMIC01 Rx" },
176 { "DMIC01 Rx", NULL, "DMIC AIF" },
178 { "hifi3", NULL, "iDisp3 Tx"},
179 { "iDisp3 Tx", NULL, "iDisp3_out"},
180 { "hifi2", NULL, "iDisp2 Tx"},
181 { "iDisp2 Tx", NULL, "iDisp2_out"},
182 { "hifi1", NULL, "iDisp1 Tx"},
183 { "iDisp1 Tx", NULL, "iDisp1_out"},
187 KBL_DPCM_AUDIO_5663_PB = 0,
188 KBL_DPCM_AUDIO_5663_CP,
189 KBL_DPCM_AUDIO_5663_HDMI1_PB,
190 KBL_DPCM_AUDIO_5663_HDMI2_PB,
193 static const struct snd_kcontrol_new kabylake_5663_controls[] = {
194 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
195 SOC_DAPM_PIN_SWITCH("Headset Mic"),
198 static const struct snd_soc_dapm_widget kabylake_5663_widgets[] = {
199 SND_SOC_DAPM_HP("Headphone Jack", NULL),
200 SND_SOC_DAPM_MIC("Headset Mic", NULL),
201 SND_SOC_DAPM_SPK("HDMI1", NULL),
202 SND_SOC_DAPM_SPK("HDMI2", NULL),
203 SND_SOC_DAPM_SPK("HDMI3", NULL),
204 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
205 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
206 SND_SOC_DAPM_POST_PMD),
209 static const struct snd_soc_dapm_route kabylake_5663_map[] = {
210 { "Headphone Jack", NULL, "Platform Clock" },
211 { "Headphone Jack", NULL, "HPOL" },
212 { "Headphone Jack", NULL, "HPOR" },
215 { "Headset Mic", NULL, "Platform Clock" },
216 { "IN1P", NULL, "Headset Mic" },
217 { "IN1N", NULL, "Headset Mic" },
219 {"HDMI1", NULL, "hif5-0 Output"},
220 {"HDMI2", NULL, "hif6-0 Output"},
221 {"HDMI3", NULL, "hif7-0 Output"},
223 /* CODEC BE connections */
224 { "AIF Playback", NULL, "ssp1 Tx" },
225 { "ssp1 Tx", NULL, "codec1_out" },
227 { "codec0_in", NULL, "ssp1 Rx" },
228 { "ssp1 Rx", NULL, "AIF Capture" },
230 { "hifi2", NULL, "iDisp2 Tx"},
231 { "iDisp2 Tx", NULL, "iDisp2_out"},
232 { "hifi1", NULL, "iDisp1 Tx"},
233 { "iDisp1 Tx", NULL, "iDisp1_out"},
236 static struct snd_soc_codec_conf max98927_codec_conf[] = {
238 .dlc = COMP_CODEC_CONF(MAXIM_DEV0_NAME),
239 .name_prefix = "Right",
242 .dlc = COMP_CODEC_CONF(MAXIM_DEV1_NAME),
243 .name_prefix = "Left",
247 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
250 struct snd_soc_dapm_context *dapm;
251 struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
253 dapm = snd_soc_component_get_dapm(component);
254 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
256 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
263 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
266 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
267 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
268 struct snd_soc_jack *jack;
271 * Headset buttons map to the google Reference headset.
272 * These can be configured by userspace.
274 ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
275 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
276 SND_JACK_BTN_2 | SND_JACK_BTN_3,
277 &ctx->kabylake_headset);
279 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
283 jack = &ctx->kabylake_headset;
284 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
285 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
286 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
287 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
289 snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
294 static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime *rtd)
298 ret = kabylake_rt5663_codec_init(rtd);
302 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
304 dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret);
311 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
313 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
314 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
315 struct kbl_hdmi_pcm *pcm;
317 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
321 pcm->device = device;
322 pcm->codec_dai = dai;
324 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
329 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
331 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
334 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
336 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
339 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
341 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
344 static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
346 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI1_PB);
349 static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
351 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB);
354 static unsigned int rates[] = {
358 static const struct snd_pcm_hw_constraint_list constraints_rates = {
359 .count = ARRAY_SIZE(rates),
364 static unsigned int channels[] = {
368 static const struct snd_pcm_hw_constraint_list constraints_channels = {
369 .count = ARRAY_SIZE(channels),
374 static int kbl_fe_startup(struct snd_pcm_substream *substream)
376 struct snd_pcm_runtime *runtime = substream->runtime;
379 * On this platform for PCM device we support,
385 runtime->hw.channels_max = 2;
386 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
387 &constraints_channels);
389 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
390 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
392 snd_pcm_hw_constraint_list(runtime, 0,
393 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
398 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
399 .startup = kbl_fe_startup,
402 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
403 struct snd_pcm_hw_params *params)
405 struct snd_interval *rate = hw_param_interval(params,
406 SNDRV_PCM_HW_PARAM_RATE);
407 struct snd_interval *chan = hw_param_interval(params,
408 SNDRV_PCM_HW_PARAM_CHANNELS);
409 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
410 struct snd_soc_dpcm *dpcm, *rtd_dpcm = NULL;
413 * The following loop will be called only for playback stream
414 * In this platform, there is only one playback device on every SSP
416 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
422 * This following loop will be called only for capture stream
423 * In this platform, there is only one capture device on every SSP
425 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
434 * The above 2 loops are mutually exclusive based on the stream direction,
435 * thus rtd_dpcm variable will never be overwritten
439 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
441 if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
442 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
443 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
444 rate->min = rate->max = 48000;
445 chan->min = chan->max = 2;
447 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
450 * The speaker on the SSP0 supports S16_LE and not S24_LE.
451 * thus changing the mask here
453 if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
454 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
459 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
460 struct snd_pcm_hw_params *params)
462 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
463 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
466 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
467 rt5663_sel_asrc_clk_src(codec_dai->component,
468 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
469 RT5663_CLK_SEL_I2S1_ASRC);
471 ret = snd_soc_dai_set_sysclk(codec_dai,
472 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
474 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
479 static struct snd_soc_ops kabylake_rt5663_ops = {
480 .hw_params = kabylake_rt5663_hw_params,
483 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
484 struct snd_pcm_hw_params *params)
486 struct snd_interval *chan = hw_param_interval(params,
487 SNDRV_PCM_HW_PARAM_CHANNELS);
489 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
490 chan->min = chan->max = 2;
492 chan->min = chan->max = 4;
497 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
498 struct snd_pcm_hw_params *params)
500 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
501 struct snd_soc_dai *codec_dai;
504 for_each_rtd_codec_dais(rtd, j, codec_dai) {
505 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
507 * Use channel 4 and 5 for the first amp
509 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
511 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
515 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
517 * Use channel 6 and 7 for the second amp
519 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
521 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
529 static struct snd_soc_ops kabylake_ssp0_ops = {
530 .hw_params = kabylake_ssp0_hw_params,
533 static unsigned int channels_dmic[] = {
537 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
538 .count = ARRAY_SIZE(channels_dmic),
539 .list = channels_dmic,
543 static const unsigned int dmic_2ch[] = {
547 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
548 .count = ARRAY_SIZE(dmic_2ch),
553 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
555 struct snd_pcm_runtime *runtime = substream->runtime;
557 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
558 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
561 return snd_pcm_hw_constraint_list(substream->runtime, 0,
562 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
565 static struct snd_soc_ops kabylake_dmic_ops = {
566 .startup = kabylake_dmic_startup,
569 static unsigned int rates_16000[] = {
573 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
574 .count = ARRAY_SIZE(rates_16000),
578 static const unsigned int ch_mono[] = {
582 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
583 .count = ARRAY_SIZE(ch_mono),
587 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
589 substream->runtime->hw.channels_max = 1;
590 snd_pcm_hw_constraint_list(substream->runtime, 0,
591 SNDRV_PCM_HW_PARAM_CHANNELS,
592 &constraints_refcap);
594 return snd_pcm_hw_constraint_list(substream->runtime, 0,
595 SNDRV_PCM_HW_PARAM_RATE,
599 static struct snd_soc_ops skylake_refcap_ops = {
600 .startup = kabylake_refcap_startup,
603 SND_SOC_DAILINK_DEF(dummy,
604 DAILINK_COMP_ARRAY(COMP_DUMMY()));
606 SND_SOC_DAILINK_DEF(system,
607 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
609 SND_SOC_DAILINK_DEF(system2,
610 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
612 SND_SOC_DAILINK_DEF(echoref,
613 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
615 SND_SOC_DAILINK_DEF(reference,
616 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
618 SND_SOC_DAILINK_DEF(dmic,
619 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
621 SND_SOC_DAILINK_DEF(hdmi1,
622 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
624 SND_SOC_DAILINK_DEF(hdmi2,
625 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
627 SND_SOC_DAILINK_DEF(hdmi3,
628 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
630 SND_SOC_DAILINK_DEF(ssp0_pin,
631 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
632 SND_SOC_DAILINK_DEF(ssp0_codec,
634 /* Left */ COMP_CODEC(MAXIM_DEV0_NAME, KBL_MAXIM_CODEC_DAI),
635 /* Right */ COMP_CODEC(MAXIM_DEV1_NAME, KBL_MAXIM_CODEC_DAI)));
637 SND_SOC_DAILINK_DEF(ssp1_pin,
638 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
639 SND_SOC_DAILINK_DEF(ssp1_codec,
640 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5663:00",
641 KBL_REALTEK_CODEC_DAI)));
643 SND_SOC_DAILINK_DEF(dmic01_pin,
644 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
645 SND_SOC_DAILINK_DEF(dmic_codec,
646 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
648 SND_SOC_DAILINK_DEF(idisp1_pin,
649 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
650 SND_SOC_DAILINK_DEF(idisp1_codec,
651 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
653 SND_SOC_DAILINK_DEF(idisp2_pin,
654 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
655 SND_SOC_DAILINK_DEF(idisp2_codec,
656 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
658 SND_SOC_DAILINK_DEF(idisp3_pin,
659 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
660 SND_SOC_DAILINK_DEF(idisp3_codec,
661 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
663 SND_SOC_DAILINK_DEF(platform,
664 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
666 /* kabylake digital audio interface glue - connects codec <--> CPU */
667 static struct snd_soc_dai_link kabylake_dais[] = {
668 /* Front End DAI links */
669 [KBL_DPCM_AUDIO_PB] = {
670 .name = "Kbl Audio Port",
671 .stream_name = "Audio",
674 .init = kabylake_rt5663_fe_init,
676 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
678 .ops = &kabylake_rt5663_fe_ops,
679 SND_SOC_DAILINK_REG(system, dummy, platform),
681 [KBL_DPCM_AUDIO_CP] = {
682 .name = "Kbl Audio Capture Port",
683 .stream_name = "Audio Record",
687 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
689 .ops = &kabylake_rt5663_fe_ops,
690 SND_SOC_DAILINK_REG(system, dummy, platform),
692 [KBL_DPCM_AUDIO_HS_PB] = {
693 .name = "Kbl Audio Headset Playback",
694 .stream_name = "Headset Audio",
698 SND_SOC_DAILINK_REG(system2, dummy, platform),
700 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
701 .name = "Kbl Audio Echo Reference cap",
702 .stream_name = "Echoreference Capture",
706 SND_SOC_DAILINK_REG(echoref, dummy, platform),
708 [KBL_DPCM_AUDIO_REF_CP] = {
709 .name = "Kbl Audio Reference cap",
710 .stream_name = "Wake on Voice",
715 .ops = &skylake_refcap_ops,
716 SND_SOC_DAILINK_REG(reference, dummy, platform),
718 [KBL_DPCM_AUDIO_DMIC_CP] = {
719 .name = "Kbl Audio DMIC cap",
720 .stream_name = "dmiccap",
725 .ops = &kabylake_dmic_ops,
726 SND_SOC_DAILINK_REG(dmic, dummy, platform),
728 [KBL_DPCM_AUDIO_HDMI1_PB] = {
729 .name = "Kbl HDMI Port1",
730 .stream_name = "Hdmi1",
734 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
737 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
739 [KBL_DPCM_AUDIO_HDMI2_PB] = {
740 .name = "Kbl HDMI Port2",
741 .stream_name = "Hdmi2",
745 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
748 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
750 [KBL_DPCM_AUDIO_HDMI3_PB] = {
751 .name = "Kbl HDMI Port3",
752 .stream_name = "Hdmi3",
754 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
759 SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
762 /* Back End DAI links */
765 .name = "SSP0-Codec",
768 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
769 SND_SOC_DAIFMT_NB_NF |
770 SND_SOC_DAIFMT_CBC_CFC,
771 .ignore_pmdown_time = 1,
772 .be_hw_params_fixup = kabylake_ssp_fixup,
774 .ops = &kabylake_ssp0_ops,
775 SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
779 .name = "SSP1-Codec",
782 .init = kabylake_rt5663_max98927_codec_init,
783 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
784 SND_SOC_DAIFMT_CBC_CFC,
785 .ignore_pmdown_time = 1,
786 .be_hw_params_fixup = kabylake_ssp_fixup,
787 .ops = &kabylake_rt5663_ops,
790 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
795 .be_hw_params_fixup = kabylake_dmic_fixup,
799 SND_SOC_DAILINK_REG(dmic01_pin, dmic_codec, platform),
805 .init = kabylake_hdmi1_init,
807 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
812 .init = kabylake_hdmi2_init,
815 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
820 .init = kabylake_hdmi3_init,
823 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
827 static struct snd_soc_dai_link kabylake_5663_dais[] = {
828 /* Front End DAI links */
829 [KBL_DPCM_AUDIO_5663_PB] = {
830 .name = "Kbl Audio Port",
831 .stream_name = "Audio",
835 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
837 .ops = &kabylake_rt5663_fe_ops,
838 SND_SOC_DAILINK_REG(system, dummy, platform),
840 [KBL_DPCM_AUDIO_5663_CP] = {
841 .name = "Kbl Audio Capture Port",
842 .stream_name = "Audio Record",
846 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
848 .ops = &kabylake_rt5663_fe_ops,
849 SND_SOC_DAILINK_REG(system, dummy, platform),
851 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
852 .name = "Kbl HDMI Port1",
853 .stream_name = "Hdmi1",
857 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
860 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
862 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
863 .name = "Kbl HDMI Port2",
864 .stream_name = "Hdmi2",
868 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
871 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
874 /* Back End DAI links */
877 .name = "SSP1-Codec",
880 .init = kabylake_rt5663_codec_init,
881 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
882 SND_SOC_DAIFMT_CBC_CFC,
883 .ignore_pmdown_time = 1,
884 .be_hw_params_fixup = kabylake_ssp_fixup,
885 .ops = &kabylake_rt5663_ops,
888 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
894 .init = kabylake_5663_hdmi1_init,
896 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
901 .init = kabylake_5663_hdmi2_init,
904 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
909 static int kabylake_card_late_probe(struct snd_soc_card *card)
911 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
912 struct kbl_hdmi_pcm *pcm;
913 struct snd_soc_component *component = NULL;
915 char jack_name[NAME_SIZE];
917 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
918 component = pcm->codec_dai->component;
919 snprintf(jack_name, sizeof(jack_name),
920 "HDMI/DP, pcm=%d Jack", pcm->device);
921 err = snd_soc_card_jack_new(card, jack_name,
922 SND_JACK_AVOUT, &skylake_hdmi[i]);
927 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
938 return hdac_hdmi_jack_port_init(component, &card->dapm);
941 /* kabylake audio machine driver for SPT + RT5663 */
942 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
943 .name = "kblrt5663max",
944 .owner = THIS_MODULE,
945 .dai_link = kabylake_dais,
946 .num_links = ARRAY_SIZE(kabylake_dais),
947 .controls = kabylake_controls,
948 .num_controls = ARRAY_SIZE(kabylake_controls),
949 .dapm_widgets = kabylake_widgets,
950 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
951 .dapm_routes = kabylake_map,
952 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
953 .codec_conf = max98927_codec_conf,
954 .num_configs = ARRAY_SIZE(max98927_codec_conf),
955 .fully_routed = true,
956 .late_probe = kabylake_card_late_probe,
959 /* kabylake audio machine driver for RT5663 */
960 static struct snd_soc_card kabylake_audio_card_rt5663 = {
962 .owner = THIS_MODULE,
963 .dai_link = kabylake_5663_dais,
964 .num_links = ARRAY_SIZE(kabylake_5663_dais),
965 .controls = kabylake_5663_controls,
966 .num_controls = ARRAY_SIZE(kabylake_5663_controls),
967 .dapm_widgets = kabylake_5663_widgets,
968 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
969 .dapm_routes = kabylake_5663_map,
970 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
971 .fully_routed = true,
972 .late_probe = kabylake_card_late_probe,
975 static int kabylake_audio_probe(struct platform_device *pdev)
977 struct kbl_rt5663_private *ctx;
978 struct snd_soc_acpi_mach *mach;
981 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
985 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
987 kabylake_audio_card =
988 (struct snd_soc_card *)pdev->id_entry->driver_data;
990 kabylake_audio_card->dev = &pdev->dev;
991 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
993 mach = pdev->dev.platform_data;
995 dmic_constraints = mach->mach_params.dmic_num == 2 ?
996 &constraints_dmic_2ch : &constraints_dmic_channels;
998 ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk");
999 if (IS_ERR(ctx->mclk)) {
1000 ret = PTR_ERR(ctx->mclk);
1001 if (ret == -ENOENT) {
1002 dev_info(&pdev->dev,
1003 "Failed to get ssp1_sclk, defer probe\n");
1004 return -EPROBE_DEFER;
1007 dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n",
1012 ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk");
1013 if (IS_ERR(ctx->sclk)) {
1014 ret = PTR_ERR(ctx->sclk);
1015 if (ret == -ENOENT) {
1016 dev_info(&pdev->dev,
1017 "Failed to get ssp1_sclk, defer probe\n");
1018 return -EPROBE_DEFER;
1021 dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n",
1026 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
1029 static const struct platform_device_id kbl_board_ids[] = {
1031 .name = "kbl_rt5663",
1032 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
1035 .name = "kbl_rt5663_m98927",
1037 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
1041 MODULE_DEVICE_TABLE(platform, kbl_board_ids);
1043 static struct platform_driver kabylake_audio = {
1044 .probe = kabylake_audio_probe,
1046 .name = "kbl_rt5663_m98927",
1047 .pm = &snd_soc_pm_ops,
1049 .id_table = kbl_board_ids,
1052 module_platform_driver(kabylake_audio)
1054 /* Module information */
1055 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
1056 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
1057 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
1058 MODULE_LICENSE("GPL v2");