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/module.h>
21 #include <linux/platform_device.h>
22 #include <sound/core.h>
23 #include <sound/jack.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
27 #include "../../codecs/rt5663.h"
28 #include "../../codecs/hdac_hdmi.h"
29 #include "../skylake/skl.h"
31 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
32 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
33 #define DMIC_CH(p) p->list[p->count-1]
34 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
35 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
37 static struct snd_soc_card kabylake_audio_card;
38 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
39 static struct snd_soc_jack skylake_hdmi[3];
42 struct list_head head;
43 struct snd_soc_dai *codec_dai;
47 struct kbl_rt5663_private {
48 struct snd_soc_jack kabylake_headset;
49 struct list_head hdmi_pcm_list;
53 KBL_DPCM_AUDIO_PB = 0,
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 const struct snd_soc_dapm_widget kabylake_widgets[] = {
70 SND_SOC_DAPM_HP("Headphone Jack", NULL),
71 SND_SOC_DAPM_MIC("Headset Mic", NULL),
72 SND_SOC_DAPM_SPK("Left Spk", NULL),
73 SND_SOC_DAPM_SPK("Right Spk", NULL),
74 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
75 SND_SOC_DAPM_SPK("DP", NULL),
76 SND_SOC_DAPM_SPK("HDMI", NULL),
80 static const struct snd_soc_dapm_route kabylake_map[] = {
81 /* HP jack connectors - unknown if we have jack detection */
82 { "Headphone Jack", NULL, "HPOL" },
83 { "Headphone Jack", NULL, "HPOR" },
86 { "Left Spk", NULL, "Left BE_OUT" },
87 { "Right Spk", NULL, "Right BE_OUT" },
90 { "IN1P", NULL, "Headset Mic" },
91 { "IN1N", NULL, "Headset Mic" },
92 { "DMic", NULL, "SoC DMIC" },
94 { "HDMI", NULL, "hif5 Output" },
95 { "DP", NULL, "hif6 Output" },
97 /* CODEC BE connections */
98 { "Left HiFi Playback", NULL, "ssp0 Tx" },
99 { "Right HiFi Playback", NULL, "ssp0 Tx" },
100 { "ssp0 Tx", NULL, "codec0_out" },
102 { "AIF Playback", NULL, "ssp1 Tx" },
103 { "ssp1 Tx", NULL, "codec1_out" },
105 { "codec0_in", NULL, "ssp1 Rx" },
106 { "ssp1 Rx", NULL, "AIF Capture" },
109 { "dmic01_hifi", NULL, "DMIC01 Rx" },
110 { "DMIC01 Rx", NULL, "DMIC AIF" },
112 { "hifi3", NULL, "iDisp3 Tx"},
113 { "iDisp3 Tx", NULL, "iDisp3_out"},
114 { "hifi2", NULL, "iDisp2 Tx"},
115 { "iDisp2 Tx", NULL, "iDisp2_out"},
116 { "hifi1", NULL, "iDisp1 Tx"},
117 { "iDisp1 Tx", NULL, "iDisp1_out"},
120 static struct snd_soc_codec_conf max98927_codec_conf[] = {
122 .dev_name = MAXIM_DEV0_NAME,
123 .name_prefix = "Right",
126 .dev_name = MAXIM_DEV1_NAME,
127 .name_prefix = "Left",
131 static struct snd_soc_dai_link_component max98927_codec_components[] = {
133 .name = MAXIM_DEV0_NAME,
134 .dai_name = KBL_MAXIM_CODEC_DAI,
137 .name = MAXIM_DEV1_NAME,
138 .dai_name = KBL_MAXIM_CODEC_DAI,
142 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
145 struct snd_soc_dapm_context *dapm;
146 struct snd_soc_component *component = rtd->cpu_dai->component;
148 dapm = snd_soc_component_get_dapm(component);
149 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
151 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
158 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
161 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
162 struct snd_soc_codec *codec = rtd->codec;
165 * Headset buttons map to the google Reference headset.
166 * These can be configured by userspace.
168 ret = snd_soc_card_jack_new(&kabylake_audio_card, "Headset Jack",
169 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
170 SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
173 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
177 rt5663_set_jack_detect(codec, &ctx->kabylake_headset);
178 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
180 dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret);
187 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
189 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
190 struct snd_soc_dai *dai = rtd->codec_dai;
191 struct kbl_hdmi_pcm *pcm;
193 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
197 pcm->device = KBL_DPCM_AUDIO_HDMI1_PB;
198 pcm->codec_dai = dai;
200 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
205 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
207 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
208 struct snd_soc_dai *dai = rtd->codec_dai;
209 struct kbl_hdmi_pcm *pcm;
211 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
215 pcm->device = KBL_DPCM_AUDIO_HDMI2_PB;
216 pcm->codec_dai = dai;
218 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
223 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
225 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
226 struct snd_soc_dai *dai = rtd->codec_dai;
227 struct kbl_hdmi_pcm *pcm;
229 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
233 pcm->device = KBL_DPCM_AUDIO_HDMI3_PB;
234 pcm->codec_dai = dai;
236 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
241 static unsigned int rates[] = {
245 static struct snd_pcm_hw_constraint_list constraints_rates = {
246 .count = ARRAY_SIZE(rates),
251 static unsigned int channels[] = {
255 static struct snd_pcm_hw_constraint_list constraints_channels = {
256 .count = ARRAY_SIZE(channels),
261 static int kbl_fe_startup(struct snd_pcm_substream *substream)
263 struct snd_pcm_runtime *runtime = substream->runtime;
266 * On this platform for PCM device we support,
272 runtime->hw.channels_max = 2;
273 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
274 &constraints_channels);
276 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
277 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
279 snd_pcm_hw_constraint_list(runtime, 0,
280 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
285 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
286 .startup = kbl_fe_startup,
289 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
290 struct snd_pcm_hw_params *params)
292 struct snd_interval *rate = hw_param_interval(params,
293 SNDRV_PCM_HW_PARAM_RATE);
294 struct snd_interval *channels = hw_param_interval(params,
295 SNDRV_PCM_HW_PARAM_CHANNELS);
296 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
298 /* The ADSP will convert the FE rate to 48k, stereo */
299 rate->min = rate->max = 48000;
300 channels->min = channels->max = 2;
301 /* set SSP1 to 24 bit */
303 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
308 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
309 struct snd_pcm_hw_params *params)
311 struct snd_soc_pcm_runtime *rtd = substream->private_data;
312 struct snd_soc_dai *codec_dai = rtd->codec_dai;
315 ret = snd_soc_dai_set_sysclk(codec_dai,
316 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
317 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
318 rt5663_sel_asrc_clk_src(codec_dai->codec, RT5663_DA_STEREO_FILTER, 1);
321 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
326 static struct snd_soc_ops kabylake_rt5663_ops = {
327 .hw_params = kabylake_rt5663_hw_params,
330 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
331 struct snd_pcm_hw_params *params)
333 struct snd_interval *channels = hw_param_interval(params,
334 SNDRV_PCM_HW_PARAM_CHANNELS);
336 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
337 channels->min = channels->max = 2;
339 channels->min = channels->max = 4;
344 static unsigned int channels_dmic[] = {
348 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
349 .count = ARRAY_SIZE(channels_dmic),
350 .list = channels_dmic,
354 static const unsigned int dmic_2ch[] = {
358 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
359 .count = ARRAY_SIZE(dmic_2ch),
364 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
366 struct snd_pcm_runtime *runtime = substream->runtime;
368 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
369 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
372 return snd_pcm_hw_constraint_list(substream->runtime, 0,
373 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
376 static struct snd_soc_ops kabylake_dmic_ops = {
377 .startup = kabylake_dmic_startup,
380 static unsigned int rates_16000[] = {
384 static struct snd_pcm_hw_constraint_list constraints_16000 = {
385 .count = ARRAY_SIZE(rates_16000),
389 static const unsigned int ch_mono[] = {
393 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
394 .count = ARRAY_SIZE(ch_mono),
398 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
400 substream->runtime->hw.channels_max = 1;
401 snd_pcm_hw_constraint_list(substream->runtime, 0,
402 SNDRV_PCM_HW_PARAM_CHANNELS,
403 &constraints_refcap);
405 return snd_pcm_hw_constraint_list(substream->runtime, 0,
406 SNDRV_PCM_HW_PARAM_RATE,
410 static struct snd_soc_ops skylaye_refcap_ops = {
411 .startup = kabylake_refcap_startup,
414 /* kabylake digital audio interface glue - connects codec <--> CPU */
415 static struct snd_soc_dai_link kabylake_dais[] = {
416 /* Front End DAI links */
417 [KBL_DPCM_AUDIO_PB] = {
418 .name = "Kbl Audio Port",
419 .stream_name = "Audio",
420 .cpu_dai_name = "System Pin",
421 .platform_name = "0000:00:1f.3",
423 .codec_name = "snd-soc-dummy",
424 .codec_dai_name = "snd-soc-dummy-dai",
426 .init = kabylake_rt5663_fe_init,
428 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
430 .ops = &kabylake_rt5663_fe_ops,
432 [KBL_DPCM_AUDIO_CP] = {
433 .name = "Kbl Audio Capture Port",
434 .stream_name = "Audio Record",
435 .cpu_dai_name = "System Pin",
436 .platform_name = "0000:00:1f.3",
438 .codec_name = "snd-soc-dummy",
439 .codec_dai_name = "snd-soc-dummy-dai",
442 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
444 .ops = &kabylake_rt5663_fe_ops,
446 [KBL_DPCM_AUDIO_REF_CP] = {
447 .name = "Kbl Audio Reference cap",
448 .stream_name = "Wake on Voice",
449 .cpu_dai_name = "Reference Pin",
450 .codec_name = "snd-soc-dummy",
451 .codec_dai_name = "snd-soc-dummy-dai",
452 .platform_name = "0000:00:1f.3",
457 .ops = &skylaye_refcap_ops,
459 [KBL_DPCM_AUDIO_DMIC_CP] = {
460 .name = "Kbl Audio DMIC cap",
461 .stream_name = "dmiccap",
462 .cpu_dai_name = "DMIC Pin",
463 .codec_name = "snd-soc-dummy",
464 .codec_dai_name = "snd-soc-dummy-dai",
465 .platform_name = "0000:00:1f.3",
470 .ops = &kabylake_dmic_ops,
472 [KBL_DPCM_AUDIO_HDMI1_PB] = {
473 .name = "Kbl HDMI Port1",
474 .stream_name = "Hdmi1",
475 .cpu_dai_name = "HDMI1 Pin",
476 .codec_name = "snd-soc-dummy",
477 .codec_dai_name = "snd-soc-dummy-dai",
478 .platform_name = "0000:00:1f.3",
482 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
486 [KBL_DPCM_AUDIO_HDMI2_PB] = {
487 .name = "Kbl HDMI Port2",
488 .stream_name = "Hdmi2",
489 .cpu_dai_name = "HDMI2 Pin",
490 .codec_name = "snd-soc-dummy",
491 .codec_dai_name = "snd-soc-dummy-dai",
492 .platform_name = "0000:00:1f.3",
496 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
500 [KBL_DPCM_AUDIO_HDMI3_PB] = {
501 .name = "Kbl HDMI Port3",
502 .stream_name = "Hdmi3",
503 .cpu_dai_name = "HDMI3 Pin",
504 .codec_name = "snd-soc-dummy",
505 .codec_dai_name = "snd-soc-dummy-dai",
506 .platform_name = "0000:00:1f.3",
508 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
515 /* Back End DAI links */
518 .name = "SSP0-Codec",
520 .cpu_dai_name = "SSP0 Pin",
521 .platform_name = "0000:00:1f.3",
523 .codecs = max98927_codec_components,
524 .num_codecs = ARRAY_SIZE(max98927_codec_components),
525 .dai_fmt = SND_SOC_DAIFMT_I2S |
526 SND_SOC_DAIFMT_NB_NF |
527 SND_SOC_DAIFMT_CBS_CFS,
528 .ignore_pmdown_time = 1,
529 .be_hw_params_fixup = kabylake_ssp_fixup,
534 .name = "SSP1-Codec",
536 .cpu_dai_name = "SSP1 Pin",
537 .platform_name = "0000:00:1f.3",
539 .codec_name = "i2c-10EC5663:00",
540 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
541 .init = kabylake_rt5663_codec_init,
542 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
543 SND_SOC_DAIFMT_CBS_CFS,
544 .ignore_pmdown_time = 1,
545 .be_hw_params_fixup = kabylake_ssp_fixup,
546 .ops = &kabylake_rt5663_ops,
553 .cpu_dai_name = "DMIC01 Pin",
554 .codec_name = "dmic-codec",
555 .codec_dai_name = "dmic-hifi",
556 .platform_name = "0000:00:1f.3",
557 .be_hw_params_fixup = kabylake_dmic_fixup,
565 .cpu_dai_name = "iDisp1 Pin",
566 .codec_name = "ehdaudio0D2",
567 .codec_dai_name = "intel-hdmi-hifi1",
568 .platform_name = "0000:00:1f.3",
570 .init = kabylake_hdmi1_init,
576 .cpu_dai_name = "iDisp2 Pin",
577 .codec_name = "ehdaudio0D2",
578 .codec_dai_name = "intel-hdmi-hifi2",
579 .platform_name = "0000:00:1f.3",
580 .init = kabylake_hdmi2_init,
587 .cpu_dai_name = "iDisp3 Pin",
588 .codec_name = "ehdaudio0D2",
589 .codec_dai_name = "intel-hdmi-hifi3",
590 .platform_name = "0000:00:1f.3",
591 .init = kabylake_hdmi3_init,
598 static int kabylake_card_late_probe(struct snd_soc_card *card)
600 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
601 struct kbl_hdmi_pcm *pcm;
603 char jack_name[NAME_SIZE];
605 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
606 snprintf(jack_name, sizeof(jack_name),
607 "HDMI/DP, pcm=%d Jack", pcm->device);
608 err = snd_soc_card_jack_new(card, jack_name,
609 SND_JACK_AVOUT, &skylake_hdmi[i],
615 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
626 /* kabylake audio machine driver for SPT + RT5663 */
627 static struct snd_soc_card kabylake_audio_card = {
628 .name = "kblrt5663max",
629 .owner = THIS_MODULE,
630 .dai_link = kabylake_dais,
631 .num_links = ARRAY_SIZE(kabylake_dais),
632 .controls = kabylake_controls,
633 .num_controls = ARRAY_SIZE(kabylake_controls),
634 .dapm_widgets = kabylake_widgets,
635 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
636 .dapm_routes = kabylake_map,
637 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
638 .codec_conf = max98927_codec_conf,
639 .num_configs = ARRAY_SIZE(max98927_codec_conf),
640 .fully_routed = true,
641 .late_probe = kabylake_card_late_probe,
644 static int kabylake_audio_probe(struct platform_device *pdev)
646 struct kbl_rt5663_private *ctx;
647 struct skl_machine_pdata *pdata;
649 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
653 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
655 kabylake_audio_card.dev = &pdev->dev;
656 snd_soc_card_set_drvdata(&kabylake_audio_card, ctx);
658 pdata = dev_get_drvdata(&pdev->dev);
660 dmic_constraints = pdata->dmic_num == 2 ?
661 &constraints_dmic_2ch : &constraints_dmic_channels;
663 return devm_snd_soc_register_card(&pdev->dev, &kabylake_audio_card);
666 static const struct platform_device_id kbl_board_ids[] = {
667 { .name = "kbl_rt5663_m98927" },
671 static struct platform_driver kabylake_audio = {
672 .probe = kabylake_audio_probe,
674 .name = "kbl_rt5663_m98927",
675 .pm = &snd_soc_pm_ops,
677 .id_table = kbl_board_ids,
680 module_platform_driver(kabylake_audio)
682 /* Module information */
683 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
684 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
685 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
686 MODULE_LICENSE("GPL v2");
687 MODULE_ALIAS("platform:kbl_rt5663_m98927");