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 <sound/soc-acpi.h>
29 #include "../../codecs/rt5663.h"
30 #include "../../codecs/hdac_hdmi.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;
491 struct snd_soc_dai *codec_dai;
494 for_each_rtd_codec_dai(rtd, j, codec_dai) {
495 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
497 * Use channel 4 and 5 for the first amp
499 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
501 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
505 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
507 * Use channel 6 and 7 for the second amp
509 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
511 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
519 static struct snd_soc_ops kabylake_ssp0_ops = {
520 .hw_params = kabylake_ssp0_hw_params,
523 static unsigned int channels_dmic[] = {
527 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
528 .count = ARRAY_SIZE(channels_dmic),
529 .list = channels_dmic,
533 static const unsigned int dmic_2ch[] = {
537 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
538 .count = ARRAY_SIZE(dmic_2ch),
543 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
545 struct snd_pcm_runtime *runtime = substream->runtime;
547 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
548 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
551 return snd_pcm_hw_constraint_list(substream->runtime, 0,
552 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
555 static struct snd_soc_ops kabylake_dmic_ops = {
556 .startup = kabylake_dmic_startup,
559 static unsigned int rates_16000[] = {
563 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
564 .count = ARRAY_SIZE(rates_16000),
568 static const unsigned int ch_mono[] = {
572 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
573 .count = ARRAY_SIZE(ch_mono),
577 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
579 substream->runtime->hw.channels_max = 1;
580 snd_pcm_hw_constraint_list(substream->runtime, 0,
581 SNDRV_PCM_HW_PARAM_CHANNELS,
582 &constraints_refcap);
584 return snd_pcm_hw_constraint_list(substream->runtime, 0,
585 SNDRV_PCM_HW_PARAM_RATE,
589 static struct snd_soc_ops skylake_refcap_ops = {
590 .startup = kabylake_refcap_startup,
593 /* kabylake digital audio interface glue - connects codec <--> CPU */
594 static struct snd_soc_dai_link kabylake_dais[] = {
595 /* Front End DAI links */
596 [KBL_DPCM_AUDIO_PB] = {
597 .name = "Kbl Audio Port",
598 .stream_name = "Audio",
599 .cpu_dai_name = "System Pin",
600 .platform_name = "0000:00:1f.3",
602 .codec_name = "snd-soc-dummy",
603 .codec_dai_name = "snd-soc-dummy-dai",
605 .init = kabylake_rt5663_fe_init,
607 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
609 .ops = &kabylake_rt5663_fe_ops,
611 [KBL_DPCM_AUDIO_CP] = {
612 .name = "Kbl Audio Capture Port",
613 .stream_name = "Audio Record",
614 .cpu_dai_name = "System Pin",
615 .platform_name = "0000:00:1f.3",
617 .codec_name = "snd-soc-dummy",
618 .codec_dai_name = "snd-soc-dummy-dai",
621 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
623 .ops = &kabylake_rt5663_fe_ops,
625 [KBL_DPCM_AUDIO_HS_PB] = {
626 .name = "Kbl Audio Headset Playback",
627 .stream_name = "Headset Audio",
628 .cpu_dai_name = "System Pin2",
629 .codec_name = "snd-soc-dummy",
630 .codec_dai_name = "snd-soc-dummy-dai",
631 .platform_name = "0000:00:1f.3",
636 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
637 .name = "Kbl Audio Echo Reference cap",
638 .stream_name = "Echoreference Capture",
639 .cpu_dai_name = "Echoref Pin",
640 .codec_name = "snd-soc-dummy",
641 .codec_dai_name = "snd-soc-dummy-dai",
642 .platform_name = "0000:00:1f.3",
647 [KBL_DPCM_AUDIO_REF_CP] = {
648 .name = "Kbl Audio Reference cap",
649 .stream_name = "Wake on Voice",
650 .cpu_dai_name = "Reference Pin",
651 .codec_name = "snd-soc-dummy",
652 .codec_dai_name = "snd-soc-dummy-dai",
653 .platform_name = "0000:00:1f.3",
658 .ops = &skylake_refcap_ops,
660 [KBL_DPCM_AUDIO_DMIC_CP] = {
661 .name = "Kbl Audio DMIC cap",
662 .stream_name = "dmiccap",
663 .cpu_dai_name = "DMIC Pin",
664 .codec_name = "snd-soc-dummy",
665 .codec_dai_name = "snd-soc-dummy-dai",
666 .platform_name = "0000:00:1f.3",
671 .ops = &kabylake_dmic_ops,
673 [KBL_DPCM_AUDIO_HDMI1_PB] = {
674 .name = "Kbl HDMI Port1",
675 .stream_name = "Hdmi1",
676 .cpu_dai_name = "HDMI1 Pin",
677 .codec_name = "snd-soc-dummy",
678 .codec_dai_name = "snd-soc-dummy-dai",
679 .platform_name = "0000:00:1f.3",
683 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
687 [KBL_DPCM_AUDIO_HDMI2_PB] = {
688 .name = "Kbl HDMI Port2",
689 .stream_name = "Hdmi2",
690 .cpu_dai_name = "HDMI2 Pin",
691 .codec_name = "snd-soc-dummy",
692 .codec_dai_name = "snd-soc-dummy-dai",
693 .platform_name = "0000:00:1f.3",
697 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
701 [KBL_DPCM_AUDIO_HDMI3_PB] = {
702 .name = "Kbl HDMI Port3",
703 .stream_name = "Hdmi3",
704 .cpu_dai_name = "HDMI3 Pin",
705 .codec_name = "snd-soc-dummy",
706 .codec_dai_name = "snd-soc-dummy-dai",
707 .platform_name = "0000:00:1f.3",
709 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
716 /* Back End DAI links */
719 .name = "SSP0-Codec",
721 .cpu_dai_name = "SSP0 Pin",
722 .platform_name = "0000:00:1f.3",
724 .codecs = max98927_codec_components,
725 .num_codecs = ARRAY_SIZE(max98927_codec_components),
726 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
727 SND_SOC_DAIFMT_NB_NF |
728 SND_SOC_DAIFMT_CBS_CFS,
729 .ignore_pmdown_time = 1,
730 .be_hw_params_fixup = kabylake_ssp_fixup,
732 .ops = &kabylake_ssp0_ops,
736 .name = "SSP1-Codec",
738 .cpu_dai_name = "SSP1 Pin",
739 .platform_name = "0000:00:1f.3",
741 .codec_name = "i2c-10EC5663:00",
742 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
743 .init = kabylake_rt5663_max98927_codec_init,
744 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
745 SND_SOC_DAIFMT_CBS_CFS,
746 .ignore_pmdown_time = 1,
747 .be_hw_params_fixup = kabylake_ssp_fixup,
748 .ops = &kabylake_rt5663_ops,
755 .cpu_dai_name = "DMIC01 Pin",
756 .codec_name = "dmic-codec",
757 .codec_dai_name = "dmic-hifi",
758 .platform_name = "0000:00:1f.3",
759 .be_hw_params_fixup = kabylake_dmic_fixup,
767 .cpu_dai_name = "iDisp1 Pin",
768 .codec_name = "ehdaudio0D2",
769 .codec_dai_name = "intel-hdmi-hifi1",
770 .platform_name = "0000:00:1f.3",
772 .init = kabylake_hdmi1_init,
778 .cpu_dai_name = "iDisp2 Pin",
779 .codec_name = "ehdaudio0D2",
780 .codec_dai_name = "intel-hdmi-hifi2",
781 .platform_name = "0000:00:1f.3",
782 .init = kabylake_hdmi2_init,
789 .cpu_dai_name = "iDisp3 Pin",
790 .codec_name = "ehdaudio0D2",
791 .codec_dai_name = "intel-hdmi-hifi3",
792 .platform_name = "0000:00:1f.3",
793 .init = kabylake_hdmi3_init,
799 static struct snd_soc_dai_link kabylake_5663_dais[] = {
800 /* Front End DAI links */
801 [KBL_DPCM_AUDIO_5663_PB] = {
802 .name = "Kbl Audio Port",
803 .stream_name = "Audio",
804 .cpu_dai_name = "System Pin",
805 .platform_name = "0000:00:1f.3",
807 .codec_name = "snd-soc-dummy",
808 .codec_dai_name = "snd-soc-dummy-dai",
811 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
813 .ops = &kabylake_rt5663_fe_ops,
815 [KBL_DPCM_AUDIO_5663_CP] = {
816 .name = "Kbl Audio Capture Port",
817 .stream_name = "Audio Record",
818 .cpu_dai_name = "System Pin",
819 .platform_name = "0000:00:1f.3",
821 .codec_name = "snd-soc-dummy",
822 .codec_dai_name = "snd-soc-dummy-dai",
825 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
827 .ops = &kabylake_rt5663_fe_ops,
829 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
830 .name = "Kbl HDMI Port1",
831 .stream_name = "Hdmi1",
832 .cpu_dai_name = "HDMI1 Pin",
833 .codec_name = "snd-soc-dummy",
834 .codec_dai_name = "snd-soc-dummy-dai",
835 .platform_name = "0000:00:1f.3",
839 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
843 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
844 .name = "Kbl HDMI Port2",
845 .stream_name = "Hdmi2",
846 .cpu_dai_name = "HDMI2 Pin",
847 .codec_name = "snd-soc-dummy",
848 .codec_dai_name = "snd-soc-dummy-dai",
849 .platform_name = "0000:00:1f.3",
853 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
858 /* Back End DAI links */
861 .name = "SSP1-Codec",
863 .cpu_dai_name = "SSP1 Pin",
864 .platform_name = "0000:00:1f.3",
866 .codec_name = "i2c-10EC5663:00",
867 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
868 .init = kabylake_rt5663_codec_init,
869 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
870 SND_SOC_DAIFMT_CBS_CFS,
871 .ignore_pmdown_time = 1,
872 .be_hw_params_fixup = kabylake_ssp_fixup,
873 .ops = &kabylake_rt5663_ops,
880 .cpu_dai_name = "iDisp1 Pin",
881 .codec_name = "ehdaudio0D2",
882 .codec_dai_name = "intel-hdmi-hifi1",
883 .platform_name = "0000:00:1f.3",
885 .init = kabylake_5663_hdmi1_init,
891 .cpu_dai_name = "iDisp2 Pin",
892 .codec_name = "ehdaudio0D2",
893 .codec_dai_name = "intel-hdmi-hifi2",
894 .platform_name = "0000:00:1f.3",
895 .init = kabylake_5663_hdmi2_init,
902 static int kabylake_card_late_probe(struct snd_soc_card *card)
904 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
905 struct kbl_hdmi_pcm *pcm;
906 struct snd_soc_component *component = NULL;
908 char jack_name[NAME_SIZE];
910 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
911 component = pcm->codec_dai->component;
912 snprintf(jack_name, sizeof(jack_name),
913 "HDMI/DP, pcm=%d Jack", pcm->device);
914 err = snd_soc_card_jack_new(card, jack_name,
915 SND_JACK_AVOUT, &skylake_hdmi[i],
921 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
932 return hdac_hdmi_jack_port_init(component, &card->dapm);
935 /* kabylake audio machine driver for SPT + RT5663 */
936 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
937 .name = "kblrt5663max",
938 .owner = THIS_MODULE,
939 .dai_link = kabylake_dais,
940 .num_links = ARRAY_SIZE(kabylake_dais),
941 .controls = kabylake_controls,
942 .num_controls = ARRAY_SIZE(kabylake_controls),
943 .dapm_widgets = kabylake_widgets,
944 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
945 .dapm_routes = kabylake_map,
946 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
947 .codec_conf = max98927_codec_conf,
948 .num_configs = ARRAY_SIZE(max98927_codec_conf),
949 .fully_routed = true,
950 .late_probe = kabylake_card_late_probe,
953 /* kabylake audio machine driver for RT5663 */
954 static struct snd_soc_card kabylake_audio_card_rt5663 = {
956 .owner = THIS_MODULE,
957 .dai_link = kabylake_5663_dais,
958 .num_links = ARRAY_SIZE(kabylake_5663_dais),
959 .controls = kabylake_5663_controls,
960 .num_controls = ARRAY_SIZE(kabylake_5663_controls),
961 .dapm_widgets = kabylake_5663_widgets,
962 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
963 .dapm_routes = kabylake_5663_map,
964 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
965 .fully_routed = true,
966 .late_probe = kabylake_card_late_probe,
969 static int kabylake_audio_probe(struct platform_device *pdev)
971 struct kbl_rt5663_private *ctx;
972 struct snd_soc_acpi_mach *mach;
975 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
979 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
981 kabylake_audio_card =
982 (struct snd_soc_card *)pdev->id_entry->driver_data;
984 kabylake_audio_card->dev = &pdev->dev;
985 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
987 mach = dev_get_drvdata(&pdev->dev);
989 dmic_constraints = mach->mach_params.dmic_num == 2 ?
990 &constraints_dmic_2ch : &constraints_dmic_channels;
992 ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk");
993 if (IS_ERR(ctx->mclk)) {
994 ret = PTR_ERR(ctx->mclk);
995 if (ret == -ENOENT) {
997 "Failed to get ssp1_sclk, defer probe\n");
998 return -EPROBE_DEFER;
1001 dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n",
1006 ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk");
1007 if (IS_ERR(ctx->sclk)) {
1008 ret = PTR_ERR(ctx->sclk);
1009 if (ret == -ENOENT) {
1010 dev_info(&pdev->dev,
1011 "Failed to get ssp1_sclk, defer probe\n");
1012 return -EPROBE_DEFER;
1015 dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n",
1020 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
1023 static const struct platform_device_id kbl_board_ids[] = {
1025 .name = "kbl_rt5663",
1026 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
1029 .name = "kbl_rt5663_m98927",
1031 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
1036 static struct platform_driver kabylake_audio = {
1037 .probe = kabylake_audio_probe,
1039 .name = "kbl_rt5663_m98927",
1040 .pm = &snd_soc_pm_ops,
1042 .id_table = kbl_board_ids,
1045 module_platform_driver(kabylake_audio)
1047 /* Module information */
1048 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
1049 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
1050 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
1051 MODULE_LICENSE("GPL v2");
1052 MODULE_ALIAS("platform:kbl_rt5663");
1053 MODULE_ALIAS("platform:kbl_rt5663_m98927");