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 /* CODEC BE connections */
155 { "Left HiFi Playback", NULL
, "ssp0 Tx" },
156 { "Right HiFi Playback", NULL
, "ssp0 Tx" },
157 { "ssp0 Tx", NULL
, "spk_out" },
159 { "AIF Playback", NULL
, "ssp1 Tx" },
160 { "ssp1 Tx", NULL
, "codec1_out" },
162 { "hs_in", NULL
, "ssp1 Rx" },
163 { "ssp1 Rx", NULL
, "AIF Capture" },
165 /* IV feedback path */
166 { "codec0_fb_in", NULL
, "ssp0 Rx"},
167 { "ssp0 Rx", NULL
, "Left HiFi Capture" },
168 { "ssp0 Rx", NULL
, "Right HiFi Capture" },
171 { "dmic01_hifi", NULL
, "DMIC01 Rx" },
172 { "DMIC01 Rx", NULL
, "DMIC AIF" },
174 { "hifi3", NULL
, "iDisp3 Tx"},
175 { "iDisp3 Tx", NULL
, "iDisp3_out"},
176 { "hifi2", NULL
, "iDisp2 Tx"},
177 { "iDisp2 Tx", NULL
, "iDisp2_out"},
178 { "hifi1", NULL
, "iDisp1 Tx"},
179 { "iDisp1 Tx", NULL
, "iDisp1_out"},
183 KBL_DPCM_AUDIO_5663_PB
= 0,
184 KBL_DPCM_AUDIO_5663_CP
,
185 KBL_DPCM_AUDIO_5663_HDMI1_PB
,
186 KBL_DPCM_AUDIO_5663_HDMI2_PB
,
189 static const struct snd_kcontrol_new kabylake_5663_controls
[] = {
190 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
191 SOC_DAPM_PIN_SWITCH("Headset Mic"),
194 static const struct snd_soc_dapm_widget kabylake_5663_widgets
[] = {
195 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
196 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
197 SND_SOC_DAPM_SPK("DP", NULL
),
198 SND_SOC_DAPM_SPK("HDMI", NULL
),
199 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM
, 0, 0,
200 platform_clock_control
, SND_SOC_DAPM_PRE_PMU
|
201 SND_SOC_DAPM_POST_PMD
),
204 static const struct snd_soc_dapm_route kabylake_5663_map
[] = {
205 { "Headphone Jack", NULL
, "Platform Clock" },
206 { "Headphone Jack", NULL
, "HPOL" },
207 { "Headphone Jack", NULL
, "HPOR" },
210 { "Headset Mic", NULL
, "Platform Clock" },
211 { "IN1P", NULL
, "Headset Mic" },
212 { "IN1N", NULL
, "Headset Mic" },
214 { "HDMI", NULL
, "hif5 Output" },
215 { "DP", NULL
, "hif6 Output" },
217 /* CODEC BE connections */
218 { "AIF Playback", NULL
, "ssp1 Tx" },
219 { "ssp1 Tx", NULL
, "codec1_out" },
221 { "codec0_in", NULL
, "ssp1 Rx" },
222 { "ssp1 Rx", NULL
, "AIF Capture" },
224 { "hifi2", NULL
, "iDisp2 Tx"},
225 { "iDisp2 Tx", NULL
, "iDisp2_out"},
226 { "hifi1", NULL
, "iDisp1 Tx"},
227 { "iDisp1 Tx", NULL
, "iDisp1_out"},
230 static struct snd_soc_codec_conf max98927_codec_conf
[] = {
232 .dlc
= COMP_CODEC_CONF(MAXIM_DEV0_NAME
),
233 .name_prefix
= "Right",
236 .dlc
= COMP_CODEC_CONF(MAXIM_DEV1_NAME
),
237 .name_prefix
= "Left",
241 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime
*rtd
)
244 struct snd_soc_dapm_context
*dapm
;
245 struct snd_soc_component
*component
= asoc_rtd_to_cpu(rtd
, 0)->component
;
247 dapm
= snd_soc_component_get_dapm(component
);
248 ret
= snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
250 dev_err(rtd
->dev
, "Ref Cap ignore suspend failed %d\n", ret
);
257 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime
*rtd
)
260 struct kbl_rt5663_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
261 struct snd_soc_component
*component
= asoc_rtd_to_codec(rtd
, 0)->component
;
262 struct snd_soc_jack
*jack
;
265 * Headset buttons map to the google Reference headset.
266 * These can be configured by userspace.
268 ret
= snd_soc_card_jack_new(kabylake_audio_card
, "Headset Jack",
269 SND_JACK_HEADSET
| SND_JACK_BTN_0
| SND_JACK_BTN_1
|
270 SND_JACK_BTN_2
| SND_JACK_BTN_3
, &ctx
->kabylake_headset
,
273 dev_err(rtd
->dev
, "Headset Jack creation failed %d\n", ret
);
277 jack
= &ctx
->kabylake_headset
;
278 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
279 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
280 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
281 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
283 snd_soc_component_set_jack(component
, &ctx
->kabylake_headset
, NULL
);
288 static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime
*rtd
)
292 ret
= kabylake_rt5663_codec_init(rtd
);
296 ret
= snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
298 dev_err(rtd
->dev
, "SoC DMIC ignore suspend failed %d\n", ret
);
305 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime
*rtd
, int device
)
307 struct kbl_rt5663_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
308 struct snd_soc_dai
*dai
= asoc_rtd_to_codec(rtd
, 0);
309 struct kbl_hdmi_pcm
*pcm
;
311 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
315 pcm
->device
= device
;
316 pcm
->codec_dai
= dai
;
318 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
323 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime
*rtd
)
325 return kabylake_hdmi_init(rtd
, KBL_DPCM_AUDIO_HDMI1_PB
);
328 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime
*rtd
)
330 return kabylake_hdmi_init(rtd
, KBL_DPCM_AUDIO_HDMI2_PB
);
333 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime
*rtd
)
335 return kabylake_hdmi_init(rtd
, KBL_DPCM_AUDIO_HDMI3_PB
);
338 static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime
*rtd
)
340 return kabylake_hdmi_init(rtd
, KBL_DPCM_AUDIO_5663_HDMI1_PB
);
343 static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime
*rtd
)
345 return kabylake_hdmi_init(rtd
, KBL_DPCM_AUDIO_5663_HDMI2_PB
);
348 static unsigned int rates
[] = {
352 static const struct snd_pcm_hw_constraint_list constraints_rates
= {
353 .count
= ARRAY_SIZE(rates
),
358 static unsigned int channels
[] = {
362 static const struct snd_pcm_hw_constraint_list constraints_channels
= {
363 .count
= ARRAY_SIZE(channels
),
368 static int kbl_fe_startup(struct snd_pcm_substream
*substream
)
370 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
373 * On this platform for PCM device we support,
379 runtime
->hw
.channels_max
= 2;
380 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
381 &constraints_channels
);
383 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
384 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
386 snd_pcm_hw_constraint_list(runtime
, 0,
387 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
392 static const struct snd_soc_ops kabylake_rt5663_fe_ops
= {
393 .startup
= kbl_fe_startup
,
396 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
397 struct snd_pcm_hw_params
*params
)
399 struct snd_interval
*rate
= hw_param_interval(params
,
400 SNDRV_PCM_HW_PARAM_RATE
);
401 struct snd_interval
*chan
= hw_param_interval(params
,
402 SNDRV_PCM_HW_PARAM_CHANNELS
);
403 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
404 struct snd_soc_dpcm
*dpcm
, *rtd_dpcm
= NULL
;
407 * The following loop will be called only for playback stream
408 * In this platform, there is only one playback device on every SSP
410 for_each_dpcm_fe(rtd
, SNDRV_PCM_STREAM_PLAYBACK
, dpcm
) {
416 * This following loop will be called only for capture stream
417 * In this platform, there is only one capture device on every SSP
419 for_each_dpcm_fe(rtd
, SNDRV_PCM_STREAM_CAPTURE
, dpcm
) {
428 * The above 2 loops are mutually exclusive based on the stream direction,
429 * thus rtd_dpcm variable will never be overwritten
433 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
435 if (!strcmp(rtd_dpcm
->fe
->dai_link
->name
, "Kbl Audio Port") ||
436 !strcmp(rtd_dpcm
->fe
->dai_link
->name
, "Kbl Audio Headset Playback") ||
437 !strcmp(rtd_dpcm
->fe
->dai_link
->name
, "Kbl Audio Capture Port")) {
438 rate
->min
= rate
->max
= 48000;
439 chan
->min
= chan
->max
= 2;
441 snd_mask_set_format(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
444 * The speaker on the SSP0 supports S16_LE and not S24_LE.
445 * thus changing the mask here
447 if (!strcmp(rtd_dpcm
->be
->dai_link
->name
, "SSP0-Codec"))
448 snd_mask_set_format(fmt
, SNDRV_PCM_FORMAT_S16_LE
);
453 static int kabylake_rt5663_hw_params(struct snd_pcm_substream
*substream
,
454 struct snd_pcm_hw_params
*params
)
456 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
457 struct snd_soc_dai
*codec_dai
= asoc_rtd_to_codec(rtd
, 0);
460 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
461 rt5663_sel_asrc_clk_src(codec_dai
->component
,
462 RT5663_DA_STEREO_FILTER
| RT5663_AD_STEREO_FILTER
,
463 RT5663_CLK_SEL_I2S1_ASRC
);
465 ret
= snd_soc_dai_set_sysclk(codec_dai
,
466 RT5663_SCLK_S_MCLK
, 24576000, SND_SOC_CLOCK_IN
);
468 dev_err(rtd
->dev
, "snd_soc_dai_set_sysclk err = %d\n", ret
);
473 static struct snd_soc_ops kabylake_rt5663_ops
= {
474 .hw_params
= kabylake_rt5663_hw_params
,
477 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
478 struct snd_pcm_hw_params
*params
)
480 struct snd_interval
*chan
= hw_param_interval(params
,
481 SNDRV_PCM_HW_PARAM_CHANNELS
);
483 if (params_channels(params
) == 2 || DMIC_CH(dmic_constraints
) == 2)
484 chan
->min
= chan
->max
= 2;
486 chan
->min
= chan
->max
= 4;
491 static int kabylake_ssp0_hw_params(struct snd_pcm_substream
*substream
,
492 struct snd_pcm_hw_params
*params
)
494 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
495 struct snd_soc_dai
*codec_dai
;
498 for_each_rtd_codec_dais(rtd
, j
, codec_dai
) {
499 if (!strcmp(codec_dai
->component
->name
, MAXIM_DEV0_NAME
)) {
501 * Use channel 4 and 5 for the first amp
503 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x30, 3, 8, 16);
505 dev_err(rtd
->dev
, "set TDM slot err:%d\n", ret
);
509 if (!strcmp(codec_dai
->component
->name
, MAXIM_DEV1_NAME
)) {
511 * Use channel 6 and 7 for the second amp
513 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0xC0, 3, 8, 16);
515 dev_err(rtd
->dev
, "set TDM slot err:%d\n", ret
);
523 static struct snd_soc_ops kabylake_ssp0_ops
= {
524 .hw_params
= kabylake_ssp0_hw_params
,
527 static unsigned int channels_dmic
[] = {
531 static struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
532 .count
= ARRAY_SIZE(channels_dmic
),
533 .list
= channels_dmic
,
537 static const unsigned int dmic_2ch
[] = {
541 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch
= {
542 .count
= ARRAY_SIZE(dmic_2ch
),
547 static int kabylake_dmic_startup(struct snd_pcm_substream
*substream
)
549 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
551 runtime
->hw
.channels_max
= DMIC_CH(dmic_constraints
);
552 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
555 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
556 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
559 static struct snd_soc_ops kabylake_dmic_ops
= {
560 .startup
= kabylake_dmic_startup
,
563 static unsigned int rates_16000
[] = {
567 static const struct snd_pcm_hw_constraint_list constraints_16000
= {
568 .count
= ARRAY_SIZE(rates_16000
),
572 static const unsigned int ch_mono
[] = {
576 static const struct snd_pcm_hw_constraint_list constraints_refcap
= {
577 .count
= ARRAY_SIZE(ch_mono
),
581 static int kabylake_refcap_startup(struct snd_pcm_substream
*substream
)
583 substream
->runtime
->hw
.channels_max
= 1;
584 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
585 SNDRV_PCM_HW_PARAM_CHANNELS
,
586 &constraints_refcap
);
588 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
589 SNDRV_PCM_HW_PARAM_RATE
,
593 static struct snd_soc_ops skylake_refcap_ops
= {
594 .startup
= kabylake_refcap_startup
,
597 SND_SOC_DAILINK_DEF(dummy
,
598 DAILINK_COMP_ARRAY(COMP_DUMMY()));
600 SND_SOC_DAILINK_DEF(system
,
601 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
603 SND_SOC_DAILINK_DEF(system2
,
604 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
606 SND_SOC_DAILINK_DEF(echoref
,
607 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
609 SND_SOC_DAILINK_DEF(reference
,
610 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
612 SND_SOC_DAILINK_DEF(dmic
,
613 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
615 SND_SOC_DAILINK_DEF(hdmi1
,
616 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
618 SND_SOC_DAILINK_DEF(hdmi2
,
619 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
621 SND_SOC_DAILINK_DEF(hdmi3
,
622 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
624 SND_SOC_DAILINK_DEF(ssp0_pin
,
625 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
626 SND_SOC_DAILINK_DEF(ssp0_codec
,
628 /* Left */ COMP_CODEC(MAXIM_DEV0_NAME
, KBL_MAXIM_CODEC_DAI
),
629 /* Right */ COMP_CODEC(MAXIM_DEV1_NAME
, KBL_MAXIM_CODEC_DAI
)));
631 SND_SOC_DAILINK_DEF(ssp1_pin
,
632 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
633 SND_SOC_DAILINK_DEF(ssp1_codec
,
634 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5663:00",
635 KBL_REALTEK_CODEC_DAI
)));
637 SND_SOC_DAILINK_DEF(dmic01_pin
,
638 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
639 SND_SOC_DAILINK_DEF(dmic_codec
,
640 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
642 SND_SOC_DAILINK_DEF(idisp1_pin
,
643 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
644 SND_SOC_DAILINK_DEF(idisp1_codec
,
645 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
647 SND_SOC_DAILINK_DEF(idisp2_pin
,
648 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
649 SND_SOC_DAILINK_DEF(idisp2_codec
,
650 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
652 SND_SOC_DAILINK_DEF(idisp3_pin
,
653 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
654 SND_SOC_DAILINK_DEF(idisp3_codec
,
655 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
657 SND_SOC_DAILINK_DEF(platform
,
658 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
660 /* kabylake digital audio interface glue - connects codec <--> CPU */
661 static struct snd_soc_dai_link kabylake_dais
[] = {
662 /* Front End DAI links */
663 [KBL_DPCM_AUDIO_PB
] = {
664 .name
= "Kbl Audio Port",
665 .stream_name
= "Audio",
668 .init
= kabylake_rt5663_fe_init
,
670 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
672 .ops
= &kabylake_rt5663_fe_ops
,
673 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
675 [KBL_DPCM_AUDIO_CP
] = {
676 .name
= "Kbl Audio Capture Port",
677 .stream_name
= "Audio Record",
681 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
683 .ops
= &kabylake_rt5663_fe_ops
,
684 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
686 [KBL_DPCM_AUDIO_HS_PB
] = {
687 .name
= "Kbl Audio Headset Playback",
688 .stream_name
= "Headset Audio",
692 SND_SOC_DAILINK_REG(system2
, dummy
, platform
),
694 [KBL_DPCM_AUDIO_ECHO_REF_CP
] = {
695 .name
= "Kbl Audio Echo Reference cap",
696 .stream_name
= "Echoreference Capture",
700 SND_SOC_DAILINK_REG(echoref
, dummy
, platform
),
702 [KBL_DPCM_AUDIO_REF_CP
] = {
703 .name
= "Kbl Audio Reference cap",
704 .stream_name
= "Wake on Voice",
709 .ops
= &skylake_refcap_ops
,
710 SND_SOC_DAILINK_REG(reference
, dummy
, platform
),
712 [KBL_DPCM_AUDIO_DMIC_CP
] = {
713 .name
= "Kbl Audio DMIC cap",
714 .stream_name
= "dmiccap",
719 .ops
= &kabylake_dmic_ops
,
720 SND_SOC_DAILINK_REG(dmic
, dummy
, platform
),
722 [KBL_DPCM_AUDIO_HDMI1_PB
] = {
723 .name
= "Kbl HDMI Port1",
724 .stream_name
= "Hdmi1",
728 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
731 SND_SOC_DAILINK_REG(hdmi1
, dummy
, platform
),
733 [KBL_DPCM_AUDIO_HDMI2_PB
] = {
734 .name
= "Kbl HDMI Port2",
735 .stream_name
= "Hdmi2",
739 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
742 SND_SOC_DAILINK_REG(hdmi2
, dummy
, platform
),
744 [KBL_DPCM_AUDIO_HDMI3_PB
] = {
745 .name
= "Kbl HDMI Port3",
746 .stream_name
= "Hdmi3",
748 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
753 SND_SOC_DAILINK_REG(hdmi3
, dummy
, platform
),
756 /* Back End DAI links */
759 .name
= "SSP0-Codec",
762 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
|
763 SND_SOC_DAIFMT_NB_NF
|
764 SND_SOC_DAIFMT_CBS_CFS
,
765 .ignore_pmdown_time
= 1,
766 .be_hw_params_fixup
= kabylake_ssp_fixup
,
768 .ops
= &kabylake_ssp0_ops
,
769 SND_SOC_DAILINK_REG(ssp0_pin
, ssp0_codec
, platform
),
773 .name
= "SSP1-Codec",
776 .init
= kabylake_rt5663_max98927_codec_init
,
777 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
778 SND_SOC_DAIFMT_CBS_CFS
,
779 .ignore_pmdown_time
= 1,
780 .be_hw_params_fixup
= kabylake_ssp_fixup
,
781 .ops
= &kabylake_rt5663_ops
,
784 SND_SOC_DAILINK_REG(ssp1_pin
, ssp1_codec
, platform
),
789 .be_hw_params_fixup
= kabylake_dmic_fixup
,
793 SND_SOC_DAILINK_REG(dmic01_pin
, dmic_codec
, platform
),
799 .init
= kabylake_hdmi1_init
,
801 SND_SOC_DAILINK_REG(idisp1_pin
, idisp1_codec
, platform
),
806 .init
= kabylake_hdmi2_init
,
809 SND_SOC_DAILINK_REG(idisp2_pin
, idisp2_codec
, platform
),
814 .init
= kabylake_hdmi3_init
,
817 SND_SOC_DAILINK_REG(idisp3_pin
, idisp3_codec
, platform
),
821 static struct snd_soc_dai_link kabylake_5663_dais
[] = {
822 /* Front End DAI links */
823 [KBL_DPCM_AUDIO_5663_PB
] = {
824 .name
= "Kbl Audio Port",
825 .stream_name
= "Audio",
829 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
831 .ops
= &kabylake_rt5663_fe_ops
,
832 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
834 [KBL_DPCM_AUDIO_5663_CP
] = {
835 .name
= "Kbl Audio Capture Port",
836 .stream_name
= "Audio Record",
840 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
842 .ops
= &kabylake_rt5663_fe_ops
,
843 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
845 [KBL_DPCM_AUDIO_5663_HDMI1_PB
] = {
846 .name
= "Kbl HDMI Port1",
847 .stream_name
= "Hdmi1",
851 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
854 SND_SOC_DAILINK_REG(hdmi1
, dummy
, platform
),
856 [KBL_DPCM_AUDIO_5663_HDMI2_PB
] = {
857 .name
= "Kbl HDMI Port2",
858 .stream_name
= "Hdmi2",
862 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
865 SND_SOC_DAILINK_REG(hdmi2
, dummy
, platform
),
868 /* Back End DAI links */
871 .name
= "SSP1-Codec",
874 .init
= kabylake_rt5663_codec_init
,
875 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
876 SND_SOC_DAIFMT_CBS_CFS
,
877 .ignore_pmdown_time
= 1,
878 .be_hw_params_fixup
= kabylake_ssp_fixup
,
879 .ops
= &kabylake_rt5663_ops
,
882 SND_SOC_DAILINK_REG(ssp1_pin
, ssp1_codec
, platform
),
888 .init
= kabylake_5663_hdmi1_init
,
890 SND_SOC_DAILINK_REG(idisp1_pin
, idisp1_codec
, platform
),
895 .init
= kabylake_5663_hdmi2_init
,
898 SND_SOC_DAILINK_REG(idisp2_pin
, idisp2_codec
, platform
),
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 snd_soc_acpi_mach
*mach
;
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 mach
= pdev
->dev
.platform_data
;
990 dmic_constraints
= mach
->mach_params
.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");