1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Kabylake I2S Machine Driver with MAXIM98927
4 * RT5514 and RT5663 Codecs
6 * Copyright (C) 2017, Intel Corporation. All rights reserved.
9 * Intel Kabylake I2S Machine driver supporting MAXIM98927 and
13 #include <linux/input.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <sound/core.h>
17 #include <sound/jack.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 #include <sound/soc.h>
21 #include <sound/soc-acpi.h>
22 #include "../../codecs/rt5514.h"
23 #include "../../codecs/rt5663.h"
24 #include "../../codecs/hdac_hdmi.h"
25 #include <linux/clk.h>
26 #include <linux/clk-provider.h>
27 #include <linux/clkdev.h>
29 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
30 #define KBL_REALTEK_DMIC_CODEC_DAI "rt5514-aif1"
31 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
32 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
33 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
34 #define RT5514_DEV_NAME "i2c-10EC5514:00"
35 #define RT5663_DEV_NAME "i2c-10EC5663:00"
36 #define RT5514_AIF1_BCLK_FREQ (48000 * 8 * 16)
37 #define RT5514_AIF1_SYSCLK_FREQ 12288000
40 #define DMIC_CH(p) p->list[p->count-1]
43 static struct snd_soc_card kabylake_audio_card
;
44 static const struct snd_pcm_hw_constraint_list
*dmic_constraints
;
47 struct list_head head
;
48 struct snd_soc_dai
*codec_dai
;
52 struct kbl_codec_private
{
53 struct snd_soc_jack kabylake_headset
;
54 struct list_head hdmi_pcm_list
;
55 struct snd_soc_jack kabylake_hdmi
[2];
61 KBL_DPCM_AUDIO_PB
= 0,
64 KBL_DPCM_AUDIO_ECHO_REF_CP
,
65 KBL_DPCM_AUDIO_DMIC_CP
,
66 KBL_DPCM_AUDIO_RT5514_DSP
,
67 KBL_DPCM_AUDIO_HDMI1_PB
,
68 KBL_DPCM_AUDIO_HDMI2_PB
,
71 static const struct snd_kcontrol_new kabylake_controls
[] = {
72 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
73 SOC_DAPM_PIN_SWITCH("Headset Mic"),
74 SOC_DAPM_PIN_SWITCH("Left Spk"),
75 SOC_DAPM_PIN_SWITCH("Right Spk"),
76 SOC_DAPM_PIN_SWITCH("DMIC"),
79 static int platform_clock_control(struct snd_soc_dapm_widget
*w
,
80 struct snd_kcontrol
*k
, int event
)
82 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
83 struct snd_soc_card
*card
= dapm
->card
;
84 struct kbl_codec_private
*priv
= snd_soc_card_get_drvdata(card
);
88 * MCLK/SCLK need to be ON early for a successful synchronization of
89 * codec internal clock. And the clocks are turned off during
90 * POST_PMD after the stream is stopped.
93 case SND_SOC_DAPM_PRE_PMU
:
95 ret
= clk_set_rate(priv
->mclk
, 24000000);
97 dev_err(card
->dev
, "Can't set rate for mclk, err: %d\n",
102 ret
= clk_prepare_enable(priv
->mclk
);
104 dev_err(card
->dev
, "Can't enable mclk, err: %d\n", ret
);
109 ret
= clk_set_rate(priv
->sclk
, 3072000);
111 dev_err(card
->dev
, "Can't set rate for sclk, err: %d\n",
113 clk_disable_unprepare(priv
->mclk
);
117 ret
= clk_prepare_enable(priv
->sclk
);
119 dev_err(card
->dev
, "Can't enable sclk, err: %d\n", ret
);
120 clk_disable_unprepare(priv
->mclk
);
123 case SND_SOC_DAPM_POST_PMD
:
124 clk_disable_unprepare(priv
->mclk
);
125 clk_disable_unprepare(priv
->sclk
);
134 static const struct snd_soc_dapm_widget kabylake_widgets
[] = {
135 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
136 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
137 SND_SOC_DAPM_SPK("Left Spk", NULL
),
138 SND_SOC_DAPM_SPK("Right Spk", NULL
),
139 SND_SOC_DAPM_MIC("DMIC", NULL
),
140 SND_SOC_DAPM_SPK("HDMI1", NULL
),
141 SND_SOC_DAPM_SPK("HDMI2", NULL
),
142 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM
, 0, 0,
143 platform_clock_control
, SND_SOC_DAPM_PRE_PMU
|
144 SND_SOC_DAPM_POST_PMD
),
148 static const struct snd_soc_dapm_route kabylake_map
[] = {
150 { "Headphone Jack", NULL
, "Platform Clock" },
151 { "Headphone Jack", NULL
, "HPOL" },
152 { "Headphone Jack", NULL
, "HPOR" },
155 { "Left Spk", NULL
, "Left BE_OUT" },
156 { "Right Spk", NULL
, "Right BE_OUT" },
159 { "Headset Mic", NULL
, "Platform Clock" },
160 { "IN1P", NULL
, "Headset Mic" },
161 { "IN1N", NULL
, "Headset Mic" },
163 /* CODEC BE connections */
164 { "Left HiFi Playback", NULL
, "ssp0 Tx" },
165 { "Right HiFi Playback", NULL
, "ssp0 Tx" },
166 { "ssp0 Tx", NULL
, "spk_out" },
168 { "AIF Playback", NULL
, "ssp1 Tx" },
169 { "ssp1 Tx", NULL
, "codec1_out" },
171 { "hs_in", NULL
, "ssp1 Rx" },
172 { "ssp1 Rx", NULL
, "AIF Capture" },
174 { "codec1_in", NULL
, "ssp0 Rx" },
175 { "ssp0 Rx", NULL
, "AIF1 Capture" },
177 /* IV feedback path */
178 { "codec0_fb_in", NULL
, "ssp0 Rx"},
179 { "ssp0 Rx", NULL
, "Left HiFi Capture" },
180 { "ssp0 Rx", NULL
, "Right HiFi Capture" },
183 { "DMIC1L", NULL
, "DMIC" },
184 { "DMIC1R", NULL
, "DMIC" },
185 { "DMIC2L", NULL
, "DMIC" },
186 { "DMIC2R", NULL
, "DMIC" },
188 { "hifi2", NULL
, "iDisp2 Tx" },
189 { "iDisp2 Tx", NULL
, "iDisp2_out" },
190 { "hifi1", NULL
, "iDisp1 Tx" },
191 { "iDisp1 Tx", NULL
, "iDisp1_out" },
194 static struct snd_soc_codec_conf max98927_codec_conf
[] = {
196 .dlc
= COMP_CODEC_CONF(MAXIM_DEV0_NAME
),
197 .name_prefix
= "Right",
200 .dlc
= COMP_CODEC_CONF(MAXIM_DEV1_NAME
),
201 .name_prefix
= "Left",
206 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime
*rtd
)
208 struct snd_soc_dapm_context
*dapm
;
209 struct snd_soc_component
*component
= asoc_rtd_to_cpu(rtd
, 0)->component
;
212 dapm
= snd_soc_component_get_dapm(component
);
213 ret
= snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
215 dev_err(rtd
->dev
, "Ref Cap -Ignore suspend failed = %d\n", ret
);
220 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime
*rtd
)
223 struct kbl_codec_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
224 struct snd_soc_component
*component
= asoc_rtd_to_codec(rtd
, 0)->component
;
225 struct snd_soc_jack
*jack
;
228 * Headset buttons map to the google Reference headset.
229 * These can be configured by userspace.
231 ret
= snd_soc_card_jack_new(&kabylake_audio_card
, "Headset Jack",
232 SND_JACK_HEADSET
| SND_JACK_BTN_0
| SND_JACK_BTN_1
|
233 SND_JACK_BTN_2
| SND_JACK_BTN_3
, &ctx
->kabylake_headset
,
236 dev_err(rtd
->dev
, "Headset Jack creation failed %d\n", ret
);
240 jack
= &ctx
->kabylake_headset
;
241 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
242 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
243 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
244 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
246 snd_soc_component_set_jack(component
, &ctx
->kabylake_headset
, NULL
);
248 ret
= snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "DMIC");
250 dev_err(rtd
->dev
, "DMIC - Ignore suspend failed = %d\n", ret
);
255 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime
*rtd
, int device
)
257 struct kbl_codec_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
258 struct snd_soc_dai
*dai
= asoc_rtd_to_codec(rtd
, 0);
259 struct kbl_hdmi_pcm
*pcm
;
261 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
265 pcm
->device
= device
;
266 pcm
->codec_dai
= dai
;
268 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
273 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime
*rtd
)
275 return kabylake_hdmi_init(rtd
, KBL_DPCM_AUDIO_HDMI1_PB
);
278 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime
*rtd
)
280 return kabylake_hdmi_init(rtd
, KBL_DPCM_AUDIO_HDMI2_PB
);
283 static const unsigned int rates
[] = {
287 static const struct snd_pcm_hw_constraint_list constraints_rates
= {
288 .count
= ARRAY_SIZE(rates
),
293 static const unsigned int channels
[] = {
297 static const struct snd_pcm_hw_constraint_list constraints_channels
= {
298 .count
= ARRAY_SIZE(channels
),
303 static int kbl_fe_startup(struct snd_pcm_substream
*substream
)
305 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
308 * On this platform for PCM device we support,
314 runtime
->hw
.channels_max
= 2;
315 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
316 &constraints_channels
);
318 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
319 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
321 snd_pcm_hw_constraint_list(runtime
, 0,
322 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
327 static const struct snd_soc_ops kabylake_rt5663_fe_ops
= {
328 .startup
= kbl_fe_startup
,
331 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
332 struct snd_pcm_hw_params
*params
)
334 struct snd_interval
*rate
= hw_param_interval(params
,
335 SNDRV_PCM_HW_PARAM_RATE
);
336 struct snd_interval
*chan
= hw_param_interval(params
,
337 SNDRV_PCM_HW_PARAM_CHANNELS
);
338 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
339 struct snd_soc_dpcm
*dpcm
, *rtd_dpcm
= NULL
;
342 * The following loop will be called only for playback stream
343 * In this platform, there is only one playback device on every SSP
345 for_each_dpcm_fe(rtd
, SNDRV_PCM_STREAM_PLAYBACK
, dpcm
) {
351 * This following loop will be called only for capture stream
352 * In this platform, there is only one capture device on every SSP
354 for_each_dpcm_fe(rtd
, SNDRV_PCM_STREAM_CAPTURE
, dpcm
) {
363 * The above 2 loops are mutually exclusive based on the stream direction,
364 * thus rtd_dpcm variable will never be overwritten
368 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
370 if (!strcmp(rtd_dpcm
->fe
->dai_link
->name
, "Kbl Audio Port") ||
371 !strcmp(rtd_dpcm
->fe
->dai_link
->name
, "Kbl Audio Headset Playback") ||
372 !strcmp(rtd_dpcm
->fe
->dai_link
->name
, "Kbl Audio Capture Port")) {
373 rate
->min
= rate
->max
= 48000;
374 chan
->min
= chan
->max
= 2;
376 snd_mask_set_format(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
377 } else if (!strcmp(rtd_dpcm
->fe
->dai_link
->name
, "Kbl Audio DMIC cap")) {
378 if (params_channels(params
) == 2 ||
379 DMIC_CH(dmic_constraints
) == 2)
380 chan
->min
= chan
->max
= 2;
382 chan
->min
= chan
->max
= 4;
385 * The speaker on the SSP0 supports S16_LE and not S24_LE.
386 * thus changing the mask here
388 if (!strcmp(rtd_dpcm
->be
->dai_link
->name
, "SSP0-Codec"))
389 snd_mask_set_format(fmt
, SNDRV_PCM_FORMAT_S16_LE
);
394 static int kabylake_rt5663_hw_params(struct snd_pcm_substream
*substream
,
395 struct snd_pcm_hw_params
*params
)
397 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
398 struct snd_soc_dai
*codec_dai
= asoc_rtd_to_codec(rtd
, 0);
401 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
402 rt5663_sel_asrc_clk_src(codec_dai
->component
,
403 RT5663_DA_STEREO_FILTER
| RT5663_AD_STEREO_FILTER
,
404 RT5663_CLK_SEL_I2S1_ASRC
);
406 ret
= snd_soc_dai_set_sysclk(codec_dai
,
407 RT5663_SCLK_S_MCLK
, 24576000, SND_SOC_CLOCK_IN
);
409 dev_err(rtd
->dev
, "snd_soc_dai_set_sysclk err = %d\n", ret
);
414 static struct snd_soc_ops kabylake_rt5663_ops
= {
415 .hw_params
= kabylake_rt5663_hw_params
,
418 static int kabylake_ssp0_hw_params(struct snd_pcm_substream
*substream
,
419 struct snd_pcm_hw_params
*params
)
421 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
422 struct snd_soc_dai
*codec_dai
;
425 for_each_rtd_codec_dais(rtd
, j
, codec_dai
) {
426 if (!strcmp(codec_dai
->component
->name
, RT5514_DEV_NAME
)) {
427 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0xF, 0, 8, 16);
429 dev_err(rtd
->dev
, "set TDM slot err:%d\n", ret
);
433 ret
= snd_soc_dai_set_sysclk(codec_dai
,
434 RT5514_SCLK_S_MCLK
, 24576000, SND_SOC_CLOCK_IN
);
436 dev_err(rtd
->dev
, "set sysclk err: %d\n", ret
);
440 if (!strcmp(codec_dai
->component
->name
, MAXIM_DEV0_NAME
)) {
441 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x30, 3, 8, 16);
443 dev_err(rtd
->dev
, "DEV0 TDM slot err:%d\n", ret
);
448 if (!strcmp(codec_dai
->component
->name
, MAXIM_DEV1_NAME
)) {
449 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0xC0, 3, 8, 16);
451 dev_err(rtd
->dev
, "DEV1 TDM slot err:%d\n", ret
);
459 static struct snd_soc_ops kabylake_ssp0_ops
= {
460 .hw_params
= kabylake_ssp0_hw_params
,
463 static const unsigned int channels_dmic
[] = {
467 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
468 .count
= ARRAY_SIZE(channels_dmic
),
469 .list
= channels_dmic
,
473 static const unsigned int dmic_2ch
[] = {
477 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch
= {
478 .count
= ARRAY_SIZE(dmic_2ch
),
483 static int kabylake_dmic_startup(struct snd_pcm_substream
*substream
)
485 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
487 runtime
->hw
.channels_max
= DMIC_CH(dmic_constraints
);
488 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
491 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
492 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
494 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
495 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
498 static struct snd_soc_ops kabylake_dmic_ops
= {
499 .startup
= kabylake_dmic_startup
,
502 SND_SOC_DAILINK_DEF(dummy
,
503 DAILINK_COMP_ARRAY(COMP_DUMMY()));
505 SND_SOC_DAILINK_DEF(system
,
506 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
508 SND_SOC_DAILINK_DEF(system2
,
509 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
511 SND_SOC_DAILINK_DEF(echoref
,
512 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
514 SND_SOC_DAILINK_DEF(spi_cpu
,
515 DAILINK_COMP_ARRAY(COMP_CPU("spi-PRP0001:00")));
516 SND_SOC_DAILINK_DEF(spi_platform
,
517 DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-PRP0001:00")));
519 SND_SOC_DAILINK_DEF(dmic
,
520 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
522 SND_SOC_DAILINK_DEF(hdmi1
,
523 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
525 SND_SOC_DAILINK_DEF(hdmi2
,
526 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
528 SND_SOC_DAILINK_DEF(ssp0_pin
,
529 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
530 SND_SOC_DAILINK_DEF(ssp0_codec
,
532 /* Left */ COMP_CODEC(MAXIM_DEV0_NAME
, KBL_MAXIM_CODEC_DAI
),
533 /* Right */COMP_CODEC(MAXIM_DEV1_NAME
, KBL_MAXIM_CODEC_DAI
),
534 /* dmic */ COMP_CODEC(RT5514_DEV_NAME
, KBL_REALTEK_DMIC_CODEC_DAI
)));
536 SND_SOC_DAILINK_DEF(ssp1_pin
,
537 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
538 SND_SOC_DAILINK_DEF(ssp1_codec
,
539 DAILINK_COMP_ARRAY(COMP_CODEC(RT5663_DEV_NAME
, KBL_REALTEK_CODEC_DAI
)));
541 SND_SOC_DAILINK_DEF(idisp1_pin
,
542 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
543 SND_SOC_DAILINK_DEF(idisp1_codec
,
544 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
546 SND_SOC_DAILINK_DEF(idisp2_pin
,
547 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
548 SND_SOC_DAILINK_DEF(idisp2_codec
,
549 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
551 SND_SOC_DAILINK_DEF(platform
,
552 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
554 /* kabylake digital audio interface glue - connects codec <--> CPU */
555 static struct snd_soc_dai_link kabylake_dais
[] = {
556 /* Front End DAI links */
557 [KBL_DPCM_AUDIO_PB
] = {
558 .name
= "Kbl Audio Port",
559 .stream_name
= "Audio",
562 .init
= kabylake_rt5663_fe_init
,
564 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
566 .ops
= &kabylake_rt5663_fe_ops
,
567 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
569 [KBL_DPCM_AUDIO_CP
] = {
570 .name
= "Kbl Audio Capture Port",
571 .stream_name
= "Audio Record",
575 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
577 .ops
= &kabylake_rt5663_fe_ops
,
578 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
580 [KBL_DPCM_AUDIO_HS_PB
] = {
581 .name
= "Kbl Audio Headset Playback",
582 .stream_name
= "Headset Audio",
586 SND_SOC_DAILINK_REG(system2
, dummy
, platform
),
588 [KBL_DPCM_AUDIO_ECHO_REF_CP
] = {
589 .name
= "Kbl Audio Echo Reference cap",
590 .stream_name
= "Echoreference Capture",
594 SND_SOC_DAILINK_REG(echoref
, dummy
, platform
),
596 [KBL_DPCM_AUDIO_RT5514_DSP
] = {
597 .name
= "rt5514 dsp",
598 .stream_name
= "Wake on Voice",
599 SND_SOC_DAILINK_REG(spi_cpu
, dummy
, spi_platform
),
601 [KBL_DPCM_AUDIO_DMIC_CP
] = {
602 .name
= "Kbl Audio DMIC cap",
603 .stream_name
= "dmiccap",
608 .ops
= &kabylake_dmic_ops
,
609 SND_SOC_DAILINK_REG(dmic
, dummy
, platform
),
611 [KBL_DPCM_AUDIO_HDMI1_PB
] = {
612 .name
= "Kbl HDMI Port1",
613 .stream_name
= "Hdmi1",
617 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
620 SND_SOC_DAILINK_REG(hdmi1
, dummy
, platform
),
622 [KBL_DPCM_AUDIO_HDMI2_PB
] = {
623 .name
= "Kbl HDMI Port2",
624 .stream_name
= "Hdmi2",
628 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
631 SND_SOC_DAILINK_REG(hdmi2
, dummy
, platform
),
633 /* Back End DAI links */
634 /* single Back end dai for both max speakers and dmic */
637 .name
= "SSP0-Codec",
640 .dai_fmt
= SND_SOC_DAIFMT_DSP_B
|
641 SND_SOC_DAIFMT_NB_NF
|
642 SND_SOC_DAIFMT_CBS_CFS
,
643 .ignore_pmdown_time
= 1,
644 .be_hw_params_fixup
= kabylake_ssp_fixup
,
647 .ops
= &kabylake_ssp0_ops
,
648 SND_SOC_DAILINK_REG(ssp0_pin
, ssp0_codec
, platform
),
651 .name
= "SSP1-Codec",
654 .init
= kabylake_rt5663_codec_init
,
655 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
656 SND_SOC_DAIFMT_CBS_CFS
,
657 .ignore_pmdown_time
= 1,
658 .be_hw_params_fixup
= kabylake_ssp_fixup
,
659 .ops
= &kabylake_rt5663_ops
,
662 SND_SOC_DAILINK_REG(ssp1_pin
, ssp1_codec
, platform
),
668 .init
= kabylake_hdmi1_init
,
670 SND_SOC_DAILINK_REG(idisp1_pin
, idisp1_codec
, platform
),
675 .init
= kabylake_hdmi2_init
,
678 SND_SOC_DAILINK_REG(idisp2_pin
, idisp2_codec
, platform
),
682 static int kabylake_set_bias_level(struct snd_soc_card
*card
,
683 struct snd_soc_dapm_context
*dapm
, enum snd_soc_bias_level level
)
685 struct snd_soc_component
*component
= dapm
->component
;
686 struct kbl_codec_private
*priv
= snd_soc_card_get_drvdata(card
);
689 if (!component
|| strcmp(component
->name
, RT5514_DEV_NAME
))
692 if (IS_ERR(priv
->mclk
))
696 * It's required to control mclk directly in the set_bias_level
697 * function for rt5514 codec or the recording function could
701 case SND_SOC_BIAS_PREPARE
:
702 if (dapm
->bias_level
== SND_SOC_BIAS_ON
) {
703 if (!__clk_is_enabled(priv
->mclk
))
705 dev_dbg(card
->dev
, "Disable mclk");
706 clk_disable_unprepare(priv
->mclk
);
708 dev_dbg(card
->dev
, "Enable mclk");
709 ret
= clk_set_rate(priv
->mclk
, 24000000);
711 dev_err(card
->dev
, "Can't set rate for mclk, err: %d\n",
716 ret
= clk_prepare_enable(priv
->mclk
);
718 dev_err(card
->dev
, "Can't enable mclk, err: %d\n",
721 /* mclk is already enabled in FW */
733 static int kabylake_card_late_probe(struct snd_soc_card
*card
)
735 struct kbl_codec_private
*ctx
= snd_soc_card_get_drvdata(card
);
736 struct kbl_hdmi_pcm
*pcm
;
737 struct snd_soc_component
*component
= NULL
;
739 char jack_name
[NAME_SIZE
];
741 list_for_each_entry(pcm
, &ctx
->hdmi_pcm_list
, head
) {
742 component
= pcm
->codec_dai
->component
;
743 snprintf(jack_name
, sizeof(jack_name
),
744 "HDMI/DP,pcm=%d Jack", pcm
->device
);
745 err
= snd_soc_card_jack_new(card
, jack_name
,
746 SND_JACK_AVOUT
, &ctx
->kabylake_hdmi
[i
],
751 err
= hdac_hdmi_jack_init(pcm
->codec_dai
, pcm
->device
,
752 &ctx
->kabylake_hdmi
[i
]);
761 return hdac_hdmi_jack_port_init(component
, &card
->dapm
);
765 * kabylake audio machine driver for MAX98927 + RT5514 + RT5663
767 static struct snd_soc_card kabylake_audio_card
= {
768 .name
= "kbl-r5514-5663-max",
769 .owner
= THIS_MODULE
,
770 .dai_link
= kabylake_dais
,
771 .num_links
= ARRAY_SIZE(kabylake_dais
),
772 .set_bias_level
= kabylake_set_bias_level
,
773 .controls
= kabylake_controls
,
774 .num_controls
= ARRAY_SIZE(kabylake_controls
),
775 .dapm_widgets
= kabylake_widgets
,
776 .num_dapm_widgets
= ARRAY_SIZE(kabylake_widgets
),
777 .dapm_routes
= kabylake_map
,
778 .num_dapm_routes
= ARRAY_SIZE(kabylake_map
),
779 .codec_conf
= max98927_codec_conf
,
780 .num_configs
= ARRAY_SIZE(max98927_codec_conf
),
781 .fully_routed
= true,
782 .late_probe
= kabylake_card_late_probe
,
785 static int kabylake_audio_probe(struct platform_device
*pdev
)
787 struct kbl_codec_private
*ctx
;
788 struct snd_soc_acpi_mach
*mach
;
791 ctx
= devm_kzalloc(&pdev
->dev
, sizeof(*ctx
), GFP_KERNEL
);
795 INIT_LIST_HEAD(&ctx
->hdmi_pcm_list
);
797 kabylake_audio_card
.dev
= &pdev
->dev
;
798 snd_soc_card_set_drvdata(&kabylake_audio_card
, ctx
);
800 mach
= pdev
->dev
.platform_data
;
802 dmic_constraints
= mach
->mach_params
.dmic_num
== 2 ?
803 &constraints_dmic_2ch
: &constraints_dmic_channels
;
805 ctx
->mclk
= devm_clk_get(&pdev
->dev
, "ssp1_mclk");
806 if (IS_ERR(ctx
->mclk
)) {
807 ret
= PTR_ERR(ctx
->mclk
);
808 if (ret
== -ENOENT
) {
810 "Failed to get ssp1_mclk, defer probe\n");
811 return -EPROBE_DEFER
;
814 dev_err(&pdev
->dev
, "Failed to get ssp1_mclk with err:%d\n",
819 ctx
->sclk
= devm_clk_get(&pdev
->dev
, "ssp1_sclk");
820 if (IS_ERR(ctx
->sclk
)) {
821 ret
= PTR_ERR(ctx
->sclk
);
822 if (ret
== -ENOENT
) {
824 "Failed to get ssp1_sclk, defer probe\n");
825 return -EPROBE_DEFER
;
828 dev_err(&pdev
->dev
, "Failed to get ssp1_sclk with err:%d\n",
833 return devm_snd_soc_register_card(&pdev
->dev
, &kabylake_audio_card
);
836 static const struct platform_device_id kbl_board_ids
[] = {
837 { .name
= "kbl_r5514_5663_max" },
841 static struct platform_driver kabylake_audio
= {
842 .probe
= kabylake_audio_probe
,
844 .name
= "kbl_r5514_5663_max",
845 .pm
= &snd_soc_pm_ops
,
847 .id_table
= kbl_board_ids
,
850 module_platform_driver(kabylake_audio
)
852 /* Module information */
853 MODULE_DESCRIPTION("Audio Machine driver-RT5663 RT5514 & MAX98927");
854 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
855 MODULE_LICENSE("GPL v2");
856 MODULE_ALIAS("platform:kbl_r5514_5663_max");