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 struct snd_soc_jack_pin jack_pins[] = {
211 .pin = "Headphone Jack",
212 .mask = SND_JACK_HEADPHONE,
215 .pin = "Headset Mic",
216 .mask = SND_JACK_MICROPHONE,
220 static const struct snd_soc_dapm_route kabylake_5663_map[] = {
221 { "Headphone Jack", NULL, "Platform Clock" },
222 { "Headphone Jack", NULL, "HPOL" },
223 { "Headphone Jack", NULL, "HPOR" },
226 { "Headset Mic", NULL, "Platform Clock" },
227 { "IN1P", NULL, "Headset Mic" },
228 { "IN1N", NULL, "Headset Mic" },
230 {"HDMI1", NULL, "hif5-0 Output"},
231 {"HDMI2", NULL, "hif6-0 Output"},
232 {"HDMI3", NULL, "hif7-0 Output"},
234 /* CODEC BE connections */
235 { "AIF Playback", NULL, "ssp1 Tx" },
236 { "ssp1 Tx", NULL, "codec1_out" },
238 { "codec0_in", NULL, "ssp1 Rx" },
239 { "ssp1 Rx", NULL, "AIF Capture" },
241 { "hifi2", NULL, "iDisp2 Tx"},
242 { "iDisp2 Tx", NULL, "iDisp2_out"},
243 { "hifi1", NULL, "iDisp1 Tx"},
244 { "iDisp1 Tx", NULL, "iDisp1_out"},
247 static struct snd_soc_codec_conf max98927_codec_conf[] = {
249 .dlc = COMP_CODEC_CONF(MAXIM_DEV0_NAME),
250 .name_prefix = "Right",
253 .dlc = COMP_CODEC_CONF(MAXIM_DEV1_NAME),
254 .name_prefix = "Left",
258 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
261 struct snd_soc_dapm_context *dapm;
262 struct snd_soc_component *component = snd_soc_rtd_to_cpu(rtd, 0)->component;
264 dapm = snd_soc_component_get_dapm(component);
265 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
267 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
274 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
277 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
278 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
279 struct snd_soc_jack *jack;
282 * Headset buttons map to the google Reference headset.
283 * These can be configured by userspace.
285 ret = snd_soc_card_jack_new_pins(kabylake_audio_card, "Headset Jack",
286 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
287 SND_JACK_BTN_2 | SND_JACK_BTN_3,
288 &ctx->kabylake_headset,
290 ARRAY_SIZE(jack_pins));
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 = snd_soc_rtd_to_codec(rtd, 0);
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 *chan = 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, *rtd_dpcm = NULL;
426 * The following loop will be called only for playback stream
427 * In this platform, there is only one playback device on every SSP
429 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
435 * This following loop will be called only for capture stream
436 * In this platform, there is only one capture device on every SSP
438 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
447 * The above 2 loops are mutually exclusive based on the stream direction,
448 * thus rtd_dpcm variable will never be overwritten
452 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
454 if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
455 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
456 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
457 rate->min = rate->max = 48000;
458 chan->min = chan->max = 2;
460 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
463 * The speaker on the SSP0 supports S16_LE and not S24_LE.
464 * thus changing the mask here
466 if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
467 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
472 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
473 struct snd_pcm_hw_params *params)
475 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
476 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
479 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
480 rt5663_sel_asrc_clk_src(codec_dai->component,
481 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
482 RT5663_CLK_SEL_I2S1_ASRC);
484 ret = snd_soc_dai_set_sysclk(codec_dai,
485 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
487 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
492 static struct snd_soc_ops kabylake_rt5663_ops = {
493 .hw_params = kabylake_rt5663_hw_params,
496 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
497 struct snd_pcm_hw_params *params)
499 struct snd_interval *chan = hw_param_interval(params,
500 SNDRV_PCM_HW_PARAM_CHANNELS);
502 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
503 chan->min = chan->max = 2;
505 chan->min = chan->max = 4;
510 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
511 struct snd_pcm_hw_params *params)
513 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
514 struct snd_soc_dai *codec_dai;
517 for_each_rtd_codec_dais(rtd, j, codec_dai) {
518 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
520 * Use channel 4 and 5 for the first amp
522 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
524 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
528 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
530 * Use channel 6 and 7 for the second amp
532 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
534 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
542 static struct snd_soc_ops kabylake_ssp0_ops = {
543 .hw_params = kabylake_ssp0_hw_params,
546 static unsigned int channels_dmic[] = {
550 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
551 .count = ARRAY_SIZE(channels_dmic),
552 .list = channels_dmic,
556 static const unsigned int dmic_2ch[] = {
560 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
561 .count = ARRAY_SIZE(dmic_2ch),
566 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
568 struct snd_pcm_runtime *runtime = substream->runtime;
570 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
571 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
574 return snd_pcm_hw_constraint_list(substream->runtime, 0,
575 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
578 static struct snd_soc_ops kabylake_dmic_ops = {
579 .startup = kabylake_dmic_startup,
582 static unsigned int rates_16000[] = {
586 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
587 .count = ARRAY_SIZE(rates_16000),
591 static const unsigned int ch_mono[] = {
595 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
596 .count = ARRAY_SIZE(ch_mono),
600 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
602 substream->runtime->hw.channels_max = 1;
603 snd_pcm_hw_constraint_list(substream->runtime, 0,
604 SNDRV_PCM_HW_PARAM_CHANNELS,
605 &constraints_refcap);
607 return snd_pcm_hw_constraint_list(substream->runtime, 0,
608 SNDRV_PCM_HW_PARAM_RATE,
612 static struct snd_soc_ops skylake_refcap_ops = {
613 .startup = kabylake_refcap_startup,
616 SND_SOC_DAILINK_DEF(dummy,
617 DAILINK_COMP_ARRAY(COMP_DUMMY()));
619 SND_SOC_DAILINK_DEF(system,
620 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
622 SND_SOC_DAILINK_DEF(system2,
623 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
625 SND_SOC_DAILINK_DEF(echoref,
626 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
628 SND_SOC_DAILINK_DEF(reference,
629 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
631 SND_SOC_DAILINK_DEF(dmic,
632 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
634 SND_SOC_DAILINK_DEF(hdmi1,
635 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
637 SND_SOC_DAILINK_DEF(hdmi2,
638 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
640 SND_SOC_DAILINK_DEF(hdmi3,
641 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
643 SND_SOC_DAILINK_DEF(ssp0_pin,
644 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
645 SND_SOC_DAILINK_DEF(ssp0_codec,
647 /* Left */ COMP_CODEC(MAXIM_DEV0_NAME, KBL_MAXIM_CODEC_DAI),
648 /* Right */ COMP_CODEC(MAXIM_DEV1_NAME, KBL_MAXIM_CODEC_DAI)));
650 SND_SOC_DAILINK_DEF(ssp1_pin,
651 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
652 SND_SOC_DAILINK_DEF(ssp1_codec,
653 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5663:00",
654 KBL_REALTEK_CODEC_DAI)));
656 SND_SOC_DAILINK_DEF(dmic01_pin,
657 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
658 SND_SOC_DAILINK_DEF(dmic_codec,
659 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
661 SND_SOC_DAILINK_DEF(idisp1_pin,
662 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
663 SND_SOC_DAILINK_DEF(idisp1_codec,
664 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
666 SND_SOC_DAILINK_DEF(idisp2_pin,
667 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
668 SND_SOC_DAILINK_DEF(idisp2_codec,
669 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
671 SND_SOC_DAILINK_DEF(idisp3_pin,
672 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
673 SND_SOC_DAILINK_DEF(idisp3_codec,
674 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
676 SND_SOC_DAILINK_DEF(platform,
677 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
679 /* kabylake digital audio interface glue - connects codec <--> CPU */
680 static struct snd_soc_dai_link kabylake_dais[] = {
681 /* Front End DAI links */
682 [KBL_DPCM_AUDIO_PB] = {
683 .name = "Kbl Audio Port",
684 .stream_name = "Audio",
687 .init = kabylake_rt5663_fe_init,
689 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
691 .ops = &kabylake_rt5663_fe_ops,
692 SND_SOC_DAILINK_REG(system, dummy, platform),
694 [KBL_DPCM_AUDIO_CP] = {
695 .name = "Kbl Audio Capture Port",
696 .stream_name = "Audio Record",
700 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
702 .ops = &kabylake_rt5663_fe_ops,
703 SND_SOC_DAILINK_REG(system, dummy, platform),
705 [KBL_DPCM_AUDIO_HS_PB] = {
706 .name = "Kbl Audio Headset Playback",
707 .stream_name = "Headset Audio",
711 SND_SOC_DAILINK_REG(system2, dummy, platform),
713 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
714 .name = "Kbl Audio Echo Reference cap",
715 .stream_name = "Echoreference Capture",
719 SND_SOC_DAILINK_REG(echoref, dummy, platform),
721 [KBL_DPCM_AUDIO_REF_CP] = {
722 .name = "Kbl Audio Reference cap",
723 .stream_name = "Wake on Voice",
728 .ops = &skylake_refcap_ops,
729 SND_SOC_DAILINK_REG(reference, dummy, platform),
731 [KBL_DPCM_AUDIO_DMIC_CP] = {
732 .name = "Kbl Audio DMIC cap",
733 .stream_name = "dmiccap",
738 .ops = &kabylake_dmic_ops,
739 SND_SOC_DAILINK_REG(dmic, dummy, platform),
741 [KBL_DPCM_AUDIO_HDMI1_PB] = {
742 .name = "Kbl HDMI Port1",
743 .stream_name = "Hdmi1",
747 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
750 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
752 [KBL_DPCM_AUDIO_HDMI2_PB] = {
753 .name = "Kbl HDMI Port2",
754 .stream_name = "Hdmi2",
758 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
761 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
763 [KBL_DPCM_AUDIO_HDMI3_PB] = {
764 .name = "Kbl HDMI Port3",
765 .stream_name = "Hdmi3",
767 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
772 SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
775 /* Back End DAI links */
778 .name = "SSP0-Codec",
781 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
782 SND_SOC_DAIFMT_NB_NF |
783 SND_SOC_DAIFMT_CBC_CFC,
784 .ignore_pmdown_time = 1,
785 .be_hw_params_fixup = kabylake_ssp_fixup,
787 .ops = &kabylake_ssp0_ops,
788 SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
792 .name = "SSP1-Codec",
795 .init = kabylake_rt5663_max98927_codec_init,
796 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
797 SND_SOC_DAIFMT_CBC_CFC,
798 .ignore_pmdown_time = 1,
799 .be_hw_params_fixup = kabylake_ssp_fixup,
800 .ops = &kabylake_rt5663_ops,
803 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
808 .be_hw_params_fixup = kabylake_dmic_fixup,
812 SND_SOC_DAILINK_REG(dmic01_pin, dmic_codec, platform),
818 .init = kabylake_hdmi1_init,
820 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
825 .init = kabylake_hdmi2_init,
828 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
833 .init = kabylake_hdmi3_init,
836 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
840 static struct snd_soc_dai_link kabylake_5663_dais[] = {
841 /* Front End DAI links */
842 [KBL_DPCM_AUDIO_5663_PB] = {
843 .name = "Kbl Audio Port",
844 .stream_name = "Audio",
848 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
850 .ops = &kabylake_rt5663_fe_ops,
851 SND_SOC_DAILINK_REG(system, dummy, platform),
853 [KBL_DPCM_AUDIO_5663_CP] = {
854 .name = "Kbl Audio Capture Port",
855 .stream_name = "Audio Record",
859 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
861 .ops = &kabylake_rt5663_fe_ops,
862 SND_SOC_DAILINK_REG(system, dummy, platform),
864 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
865 .name = "Kbl HDMI Port1",
866 .stream_name = "Hdmi1",
870 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
873 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
875 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
876 .name = "Kbl HDMI Port2",
877 .stream_name = "Hdmi2",
881 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
884 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
887 /* Back End DAI links */
890 .name = "SSP1-Codec",
893 .init = kabylake_rt5663_codec_init,
894 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
895 SND_SOC_DAIFMT_CBC_CFC,
896 .ignore_pmdown_time = 1,
897 .be_hw_params_fixup = kabylake_ssp_fixup,
898 .ops = &kabylake_rt5663_ops,
901 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
907 .init = kabylake_5663_hdmi1_init,
909 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
914 .init = kabylake_5663_hdmi2_init,
917 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
922 static int kabylake_card_late_probe(struct snd_soc_card *card)
924 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
925 struct kbl_hdmi_pcm *pcm;
926 struct snd_soc_component *component = NULL;
928 char jack_name[NAME_SIZE];
930 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
931 component = pcm->codec_dai->component;
932 snprintf(jack_name, sizeof(jack_name),
933 "HDMI/DP, pcm=%d Jack", pcm->device);
934 err = snd_soc_card_jack_new(card, jack_name,
935 SND_JACK_AVOUT, &skylake_hdmi[i]);
940 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
951 return hdac_hdmi_jack_port_init(component, &card->dapm);
954 /* kabylake audio machine driver for SPT + RT5663 */
955 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
956 .name = "kblrt5663max",
957 .owner = THIS_MODULE,
958 .dai_link = kabylake_dais,
959 .num_links = ARRAY_SIZE(kabylake_dais),
960 .controls = kabylake_controls,
961 .num_controls = ARRAY_SIZE(kabylake_controls),
962 .dapm_widgets = kabylake_widgets,
963 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
964 .dapm_routes = kabylake_map,
965 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
966 .codec_conf = max98927_codec_conf,
967 .num_configs = ARRAY_SIZE(max98927_codec_conf),
968 .fully_routed = true,
969 .late_probe = kabylake_card_late_probe,
972 /* kabylake audio machine driver for RT5663 */
973 static struct snd_soc_card kabylake_audio_card_rt5663 = {
975 .owner = THIS_MODULE,
976 .dai_link = kabylake_5663_dais,
977 .num_links = ARRAY_SIZE(kabylake_5663_dais),
978 .controls = kabylake_5663_controls,
979 .num_controls = ARRAY_SIZE(kabylake_5663_controls),
980 .dapm_widgets = kabylake_5663_widgets,
981 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
982 .dapm_routes = kabylake_5663_map,
983 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
984 .fully_routed = true,
985 .late_probe = kabylake_card_late_probe,
988 static int kabylake_audio_probe(struct platform_device *pdev)
990 struct kbl_rt5663_private *ctx;
991 struct snd_soc_acpi_mach *mach;
994 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
998 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
1000 kabylake_audio_card =
1001 (struct snd_soc_card *)pdev->id_entry->driver_data;
1003 kabylake_audio_card->dev = &pdev->dev;
1004 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
1006 mach = pdev->dev.platform_data;
1008 dmic_constraints = mach->mach_params.dmic_num == 2 ?
1009 &constraints_dmic_2ch : &constraints_dmic_channels;
1011 ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk");
1012 if (IS_ERR(ctx->mclk)) {
1013 ret = PTR_ERR(ctx->mclk);
1014 if (ret == -ENOENT) {
1015 dev_info(&pdev->dev,
1016 "Failed to get ssp1_sclk, defer probe\n");
1017 return -EPROBE_DEFER;
1020 dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n",
1025 ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk");
1026 if (IS_ERR(ctx->sclk)) {
1027 ret = PTR_ERR(ctx->sclk);
1028 if (ret == -ENOENT) {
1029 dev_info(&pdev->dev,
1030 "Failed to get ssp1_sclk, defer probe\n");
1031 return -EPROBE_DEFER;
1034 dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n",
1039 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
1042 static const struct platform_device_id kbl_board_ids[] = {
1044 .name = "kbl_rt5663",
1045 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
1048 .name = "kbl_rt5663_m98927",
1050 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
1054 MODULE_DEVICE_TABLE(platform, kbl_board_ids);
1056 static struct platform_driver kabylake_audio = {
1057 .probe = kabylake_audio_probe,
1059 .name = "kbl_rt5663_m98927",
1060 .pm = &snd_soc_pm_ops,
1062 .id_table = kbl_board_ids,
1065 module_platform_driver(kabylake_audio)
1067 /* Module information */
1068 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
1069 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
1070 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
1071 MODULE_LICENSE("GPL v2");