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 struct snd_soc_jack_pin jack_pins[] = {
150 .pin = "Headphone Jack",
151 .mask = SND_JACK_HEADPHONE,
154 .pin = "Headset Mic",
155 .mask = SND_JACK_MICROPHONE,
159 static const struct snd_soc_dapm_route kabylake_map[] = {
161 { "Headphone Jack", NULL, "Platform Clock" },
162 { "Headphone Jack", NULL, "HPOL" },
163 { "Headphone Jack", NULL, "HPOR" },
166 { "Left Spk", NULL, "Left BE_OUT" },
167 { "Right Spk", NULL, "Right BE_OUT" },
170 { "Headset Mic", NULL, "Platform Clock" },
171 { "IN1P", NULL, "Headset Mic" },
172 { "IN1N", NULL, "Headset Mic" },
174 /* CODEC BE connections */
175 { "Left HiFi Playback", NULL, "ssp0 Tx" },
176 { "Right HiFi Playback", NULL, "ssp0 Tx" },
177 { "ssp0 Tx", NULL, "spk_out" },
179 { "AIF Playback", NULL, "ssp1 Tx" },
180 { "ssp1 Tx", NULL, "codec1_out" },
182 { "hs_in", NULL, "ssp1 Rx" },
183 { "ssp1 Rx", NULL, "AIF Capture" },
185 { "codec1_in", NULL, "ssp0 Rx" },
186 { "ssp0 Rx", NULL, "AIF1 Capture" },
188 /* IV feedback path */
189 { "codec0_fb_in", NULL, "ssp0 Rx"},
190 { "ssp0 Rx", NULL, "Left HiFi Capture" },
191 { "ssp0 Rx", NULL, "Right HiFi Capture" },
194 { "DMIC1L", NULL, "DMIC" },
195 { "DMIC1R", NULL, "DMIC" },
196 { "DMIC2L", NULL, "DMIC" },
197 { "DMIC2R", NULL, "DMIC" },
199 { "hifi2", NULL, "iDisp2 Tx" },
200 { "iDisp2 Tx", NULL, "iDisp2_out" },
201 { "hifi1", NULL, "iDisp1 Tx" },
202 { "iDisp1 Tx", NULL, "iDisp1_out" },
205 static struct snd_soc_codec_conf max98927_codec_conf[] = {
207 .dlc = COMP_CODEC_CONF(MAXIM_DEV0_NAME),
208 .name_prefix = "Right",
211 .dlc = COMP_CODEC_CONF(MAXIM_DEV1_NAME),
212 .name_prefix = "Left",
217 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
219 struct snd_soc_dapm_context *dapm;
220 struct snd_soc_component *component = snd_soc_rtd_to_cpu(rtd, 0)->component;
223 dapm = snd_soc_component_get_dapm(component);
224 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
226 dev_err(rtd->dev, "Ref Cap -Ignore suspend failed = %d\n", ret);
231 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
234 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
235 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
236 struct snd_soc_jack *jack;
239 * Headset buttons map to the google Reference headset.
240 * These can be configured by userspace.
242 ret = snd_soc_card_jack_new_pins(&kabylake_audio_card, "Headset Jack",
243 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
244 SND_JACK_BTN_2 | SND_JACK_BTN_3,
245 &ctx->kabylake_headset,
247 ARRAY_SIZE(jack_pins));
249 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
253 jack = &ctx->kabylake_headset;
254 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
255 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
256 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
257 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
259 snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
261 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "DMIC");
263 dev_err(rtd->dev, "DMIC - Ignore suspend failed = %d\n", ret);
268 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
270 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
271 struct snd_soc_dai *dai = snd_soc_rtd_to_codec(rtd, 0);
272 struct kbl_hdmi_pcm *pcm;
274 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
278 pcm->device = device;
279 pcm->codec_dai = dai;
281 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
286 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
288 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
291 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
293 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
296 static const unsigned int rates[] = {
300 static const struct snd_pcm_hw_constraint_list constraints_rates = {
301 .count = ARRAY_SIZE(rates),
306 static const unsigned int channels[] = {
310 static const struct snd_pcm_hw_constraint_list constraints_channels = {
311 .count = ARRAY_SIZE(channels),
316 static int kbl_fe_startup(struct snd_pcm_substream *substream)
318 struct snd_pcm_runtime *runtime = substream->runtime;
321 * On this platform for PCM device we support,
327 runtime->hw.channels_max = 2;
328 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
329 &constraints_channels);
331 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
332 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
334 snd_pcm_hw_constraint_list(runtime, 0,
335 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
340 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
341 .startup = kbl_fe_startup,
344 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
345 struct snd_pcm_hw_params *params)
347 struct snd_interval *rate = hw_param_interval(params,
348 SNDRV_PCM_HW_PARAM_RATE);
349 struct snd_interval *chan = hw_param_interval(params,
350 SNDRV_PCM_HW_PARAM_CHANNELS);
351 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
352 struct snd_soc_dpcm *dpcm, *rtd_dpcm = NULL;
355 * The following loop will be called only for playback stream
356 * In this platform, there is only one playback device on every SSP
358 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
364 * This following loop will be called only for capture stream
365 * In this platform, there is only one capture device on every SSP
367 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
376 * The above 2 loops are mutually exclusive based on the stream direction,
377 * thus rtd_dpcm variable will never be overwritten
381 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
383 if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
384 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
385 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
386 rate->min = rate->max = 48000;
387 chan->min = chan->max = 2;
389 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
390 } else if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio DMIC cap")) {
391 if (params_channels(params) == 2 ||
392 DMIC_CH(dmic_constraints) == 2)
393 chan->min = chan->max = 2;
395 chan->min = chan->max = 4;
398 * The speaker on the SSP0 supports S16_LE and not S24_LE.
399 * thus changing the mask here
401 if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
402 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
407 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
408 struct snd_pcm_hw_params *params)
410 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
411 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
414 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
415 rt5663_sel_asrc_clk_src(codec_dai->component,
416 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
417 RT5663_CLK_SEL_I2S1_ASRC);
419 ret = snd_soc_dai_set_sysclk(codec_dai,
420 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
422 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
427 static struct snd_soc_ops kabylake_rt5663_ops = {
428 .hw_params = kabylake_rt5663_hw_params,
431 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
432 struct snd_pcm_hw_params *params)
434 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
435 struct snd_soc_dai *codec_dai;
438 for_each_rtd_codec_dais(rtd, j, codec_dai) {
439 if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) {
440 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16);
442 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
446 ret = snd_soc_dai_set_sysclk(codec_dai,
447 RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
449 dev_err(rtd->dev, "set sysclk err: %d\n", ret);
453 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
454 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
456 dev_err(rtd->dev, "DEV0 TDM slot err:%d\n", ret);
461 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
462 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
464 dev_err(rtd->dev, "DEV1 TDM slot err:%d\n", ret);
472 static struct snd_soc_ops kabylake_ssp0_ops = {
473 .hw_params = kabylake_ssp0_hw_params,
476 static const unsigned int channels_dmic[] = {
480 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
481 .count = ARRAY_SIZE(channels_dmic),
482 .list = channels_dmic,
486 static const unsigned int dmic_2ch[] = {
490 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
491 .count = ARRAY_SIZE(dmic_2ch),
496 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
498 struct snd_pcm_runtime *runtime = substream->runtime;
500 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
501 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
504 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
505 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
507 return snd_pcm_hw_constraint_list(substream->runtime, 0,
508 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
511 static struct snd_soc_ops kabylake_dmic_ops = {
512 .startup = kabylake_dmic_startup,
515 SND_SOC_DAILINK_DEF(dummy,
516 DAILINK_COMP_ARRAY(COMP_DUMMY()));
518 SND_SOC_DAILINK_DEF(system,
519 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
521 SND_SOC_DAILINK_DEF(system2,
522 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
524 SND_SOC_DAILINK_DEF(echoref,
525 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
527 SND_SOC_DAILINK_DEF(spi_cpu,
528 DAILINK_COMP_ARRAY(COMP_CPU("spi-PRP0001:00")));
529 SND_SOC_DAILINK_DEF(spi_platform,
530 DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-PRP0001:00")));
532 SND_SOC_DAILINK_DEF(dmic,
533 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
535 SND_SOC_DAILINK_DEF(hdmi1,
536 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
538 SND_SOC_DAILINK_DEF(hdmi2,
539 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
541 SND_SOC_DAILINK_DEF(ssp0_pin,
542 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
543 SND_SOC_DAILINK_DEF(ssp0_codec,
545 /* Left */ COMP_CODEC(MAXIM_DEV0_NAME, KBL_MAXIM_CODEC_DAI),
546 /* Right */COMP_CODEC(MAXIM_DEV1_NAME, KBL_MAXIM_CODEC_DAI),
547 /* dmic */ COMP_CODEC(RT5514_DEV_NAME, KBL_REALTEK_DMIC_CODEC_DAI)));
549 SND_SOC_DAILINK_DEF(ssp1_pin,
550 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
551 SND_SOC_DAILINK_DEF(ssp1_codec,
552 DAILINK_COMP_ARRAY(COMP_CODEC(RT5663_DEV_NAME, KBL_REALTEK_CODEC_DAI)));
554 SND_SOC_DAILINK_DEF(idisp1_pin,
555 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
556 SND_SOC_DAILINK_DEF(idisp1_codec,
557 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
559 SND_SOC_DAILINK_DEF(idisp2_pin,
560 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
561 SND_SOC_DAILINK_DEF(idisp2_codec,
562 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
564 SND_SOC_DAILINK_DEF(platform,
565 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
567 /* kabylake digital audio interface glue - connects codec <--> CPU */
568 static struct snd_soc_dai_link kabylake_dais[] = {
569 /* Front End DAI links */
570 [KBL_DPCM_AUDIO_PB] = {
571 .name = "Kbl Audio Port",
572 .stream_name = "Audio",
575 .init = kabylake_rt5663_fe_init,
577 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
579 .ops = &kabylake_rt5663_fe_ops,
580 SND_SOC_DAILINK_REG(system, dummy, platform),
582 [KBL_DPCM_AUDIO_CP] = {
583 .name = "Kbl Audio Capture Port",
584 .stream_name = "Audio Record",
588 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
590 .ops = &kabylake_rt5663_fe_ops,
591 SND_SOC_DAILINK_REG(system, dummy, platform),
593 [KBL_DPCM_AUDIO_HS_PB] = {
594 .name = "Kbl Audio Headset Playback",
595 .stream_name = "Headset Audio",
599 SND_SOC_DAILINK_REG(system2, dummy, platform),
601 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
602 .name = "Kbl Audio Echo Reference cap",
603 .stream_name = "Echoreference Capture",
607 SND_SOC_DAILINK_REG(echoref, dummy, platform),
609 [KBL_DPCM_AUDIO_RT5514_DSP] = {
610 .name = "rt5514 dsp",
611 .stream_name = "Wake on Voice",
612 SND_SOC_DAILINK_REG(spi_cpu, dummy, spi_platform),
614 [KBL_DPCM_AUDIO_DMIC_CP] = {
615 .name = "Kbl Audio DMIC cap",
616 .stream_name = "dmiccap",
621 .ops = &kabylake_dmic_ops,
622 SND_SOC_DAILINK_REG(dmic, dummy, platform),
624 [KBL_DPCM_AUDIO_HDMI1_PB] = {
625 .name = "Kbl HDMI Port1",
626 .stream_name = "Hdmi1",
630 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
633 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
635 [KBL_DPCM_AUDIO_HDMI2_PB] = {
636 .name = "Kbl HDMI Port2",
637 .stream_name = "Hdmi2",
641 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
644 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
646 /* Back End DAI links */
647 /* single Back end dai for both max speakers and dmic */
650 .name = "SSP0-Codec",
653 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
654 SND_SOC_DAIFMT_NB_NF |
655 SND_SOC_DAIFMT_CBC_CFC,
656 .ignore_pmdown_time = 1,
657 .be_hw_params_fixup = kabylake_ssp_fixup,
660 .ops = &kabylake_ssp0_ops,
661 SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
664 .name = "SSP1-Codec",
667 .init = kabylake_rt5663_codec_init,
668 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
669 SND_SOC_DAIFMT_CBC_CFC,
670 .ignore_pmdown_time = 1,
671 .be_hw_params_fixup = kabylake_ssp_fixup,
672 .ops = &kabylake_rt5663_ops,
675 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
681 .init = kabylake_hdmi1_init,
683 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
688 .init = kabylake_hdmi2_init,
691 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
695 static int kabylake_set_bias_level(struct snd_soc_card *card,
696 struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
698 struct snd_soc_component *component = dapm->component;
699 struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card);
702 if (!component || strcmp(component->name, RT5514_DEV_NAME))
705 if (IS_ERR(priv->mclk))
709 * It's required to control mclk directly in the set_bias_level
710 * function for rt5514 codec or the recording function could
714 case SND_SOC_BIAS_PREPARE:
715 if (dapm->bias_level == SND_SOC_BIAS_ON) {
716 if (!__clk_is_enabled(priv->mclk))
718 dev_dbg(card->dev, "Disable mclk");
719 clk_disable_unprepare(priv->mclk);
721 dev_dbg(card->dev, "Enable mclk");
722 ret = clk_set_rate(priv->mclk, 24000000);
724 dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
729 ret = clk_prepare_enable(priv->mclk);
731 dev_err(card->dev, "Can't enable mclk, err: %d\n",
734 /* mclk is already enabled in FW */
746 static int kabylake_card_late_probe(struct snd_soc_card *card)
748 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
749 struct kbl_hdmi_pcm *pcm;
750 struct snd_soc_component *component = NULL;
752 char jack_name[NAME_SIZE];
754 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
755 component = pcm->codec_dai->component;
756 snprintf(jack_name, sizeof(jack_name),
757 "HDMI/DP,pcm=%d Jack", pcm->device);
758 err = snd_soc_card_jack_new(card, jack_name,
759 SND_JACK_AVOUT, &ctx->kabylake_hdmi[i]);
763 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
764 &ctx->kabylake_hdmi[i]);
773 return hdac_hdmi_jack_port_init(component, &card->dapm);
777 * kabylake audio machine driver for MAX98927 + RT5514 + RT5663
779 static struct snd_soc_card kabylake_audio_card = {
780 .name = "kbl-r5514-5663-max",
781 .owner = THIS_MODULE,
782 .dai_link = kabylake_dais,
783 .num_links = ARRAY_SIZE(kabylake_dais),
784 .set_bias_level = kabylake_set_bias_level,
785 .controls = kabylake_controls,
786 .num_controls = ARRAY_SIZE(kabylake_controls),
787 .dapm_widgets = kabylake_widgets,
788 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
789 .dapm_routes = kabylake_map,
790 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
791 .codec_conf = max98927_codec_conf,
792 .num_configs = ARRAY_SIZE(max98927_codec_conf),
793 .fully_routed = true,
794 .late_probe = kabylake_card_late_probe,
797 static int kabylake_audio_probe(struct platform_device *pdev)
799 struct kbl_codec_private *ctx;
800 struct snd_soc_acpi_mach *mach;
803 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
807 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
809 kabylake_audio_card.dev = &pdev->dev;
810 snd_soc_card_set_drvdata(&kabylake_audio_card, ctx);
812 mach = pdev->dev.platform_data;
814 dmic_constraints = mach->mach_params.dmic_num == 2 ?
815 &constraints_dmic_2ch : &constraints_dmic_channels;
817 ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk");
818 if (IS_ERR(ctx->mclk)) {
819 ret = PTR_ERR(ctx->mclk);
820 if (ret == -ENOENT) {
822 "Failed to get ssp1_mclk, defer probe\n");
823 return -EPROBE_DEFER;
826 dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n",
831 ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk");
832 if (IS_ERR(ctx->sclk)) {
833 ret = PTR_ERR(ctx->sclk);
834 if (ret == -ENOENT) {
836 "Failed to get ssp1_sclk, defer probe\n");
837 return -EPROBE_DEFER;
840 dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n",
845 return devm_snd_soc_register_card(&pdev->dev, &kabylake_audio_card);
848 static const struct platform_device_id kbl_board_ids[] = {
849 { .name = "kbl_r5514_5663_max" },
852 MODULE_DEVICE_TABLE(platform, kbl_board_ids);
854 static struct platform_driver kabylake_audio = {
855 .probe = kabylake_audio_probe,
857 .name = "kbl_r5514_5663_max",
858 .pm = &snd_soc_pm_ops,
860 .id_table = kbl_board_ids,
863 module_platform_driver(kabylake_audio)
865 /* Module information */
866 MODULE_DESCRIPTION("Audio Machine driver-RT5663 RT5514 & MAX98927");
867 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
868 MODULE_LICENSE("GPL v2");