2 * Intel Kabylake I2S Machine Driver with MAXIM98927
3 * RT5514 and RT5663 Codecs
5 * Copyright (C) 2017, Intel Corporation. All rights reserved.
8 * Intel Kabylake I2S Machine driver supporting MAXIM98927 and
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License version
13 * 2 as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/input.h>
22 #include <linux/module.h>
23 #include <linux/platform_device.h>
24 #include <sound/core.h>
25 #include <sound/jack.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include "../../codecs/rt5514.h"
30 #include "../../codecs/rt5663.h"
31 #include "../../codecs/hdac_hdmi.h"
32 #include "../skylake/skl.h"
34 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
35 #define KBL_REALTEK_DMIC_CODEC_DAI "rt5514-aif1"
36 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
37 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
38 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
39 #define RT5514_DEV_NAME "i2c-10EC5514:00"
40 #define RT5663_DEV_NAME "i2c-10EC5663:00"
41 #define RT5514_AIF1_BCLK_FREQ (48000 * 8 * 16)
42 #define RT5514_AIF1_SYSCLK_FREQ 12288000
45 #define DMIC_CH(p) p->list[p->count-1]
48 static struct snd_soc_card kabylake_audio_card;
49 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
52 struct list_head head;
53 struct snd_soc_dai *codec_dai;
57 struct kbl_codec_private {
58 struct snd_soc_jack kabylake_headset;
59 struct list_head hdmi_pcm_list;
60 struct snd_soc_jack kabylake_hdmi[2];
64 KBL_DPCM_AUDIO_PB = 0,
67 KBL_DPCM_AUDIO_ECHO_REF_CP,
68 KBL_DPCM_AUDIO_DMIC_CP,
69 KBL_DPCM_AUDIO_RT5514_DSP,
70 KBL_DPCM_AUDIO_HDMI1_PB,
71 KBL_DPCM_AUDIO_HDMI2_PB,
74 static const struct snd_kcontrol_new kabylake_controls[] = {
75 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
76 SOC_DAPM_PIN_SWITCH("Headset Mic"),
77 SOC_DAPM_PIN_SWITCH("Left Spk"),
78 SOC_DAPM_PIN_SWITCH("Right Spk"),
79 SOC_DAPM_PIN_SWITCH("DMIC"),
82 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
83 SND_SOC_DAPM_HP("Headphone Jack", NULL),
84 SND_SOC_DAPM_MIC("Headset Mic", NULL),
85 SND_SOC_DAPM_SPK("Left Spk", NULL),
86 SND_SOC_DAPM_SPK("Right Spk", NULL),
87 SND_SOC_DAPM_MIC("DMIC", NULL),
88 SND_SOC_DAPM_SPK("HDMI1", NULL),
89 SND_SOC_DAPM_SPK("HDMI2", NULL),
93 static const struct snd_soc_dapm_route kabylake_map[] = {
95 { "Headphone Jack", NULL, "HPOL" },
96 { "Headphone Jack", NULL, "HPOR" },
99 { "Left Spk", NULL, "Left BE_OUT" },
100 { "Right Spk", NULL, "Right BE_OUT" },
103 { "IN1P", NULL, "Headset Mic" },
104 { "IN1N", NULL, "Headset Mic" },
106 /* CODEC BE connections */
107 { "Left HiFi Playback", NULL, "ssp0 Tx" },
108 { "Right HiFi Playback", NULL, "ssp0 Tx" },
109 { "ssp0 Tx", NULL, "spk_out" },
111 { "AIF Playback", NULL, "ssp1 Tx" },
112 { "ssp1 Tx", NULL, "codec1_out" },
114 { "hs_in", NULL, "ssp1 Rx" },
115 { "ssp1 Rx", NULL, "AIF Capture" },
117 { "codec1_in", NULL, "ssp0 Rx" },
118 { "ssp0 Rx", NULL, "AIF1 Capture" },
120 /* IV feedback path */
121 { "codec0_fb_in", NULL, "ssp0 Rx"},
122 { "ssp0 Rx", NULL, "Left HiFi Capture" },
123 { "ssp0 Rx", NULL, "Right HiFi Capture" },
126 { "DMIC1L", NULL, "DMIC" },
127 { "DMIC1R", NULL, "DMIC" },
128 { "DMIC2L", NULL, "DMIC" },
129 { "DMIC2R", NULL, "DMIC" },
131 { "hifi2", NULL, "iDisp2 Tx" },
132 { "iDisp2 Tx", NULL, "iDisp2_out" },
133 { "hifi1", NULL, "iDisp1 Tx" },
134 { "iDisp1 Tx", NULL, "iDisp1_out" },
137 static struct snd_soc_codec_conf max98927_codec_conf[] = {
139 .dev_name = MAXIM_DEV0_NAME,
140 .name_prefix = "Right",
143 .dev_name = MAXIM_DEV1_NAME,
144 .name_prefix = "Left",
148 static struct snd_soc_dai_link_component ssp0_codec_components[] = {
150 .name = MAXIM_DEV0_NAME,
151 .dai_name = KBL_MAXIM_CODEC_DAI,
154 .name = MAXIM_DEV1_NAME,
155 .dai_name = KBL_MAXIM_CODEC_DAI,
158 .name = RT5514_DEV_NAME,
159 .dai_name = KBL_REALTEK_DMIC_CODEC_DAI,
163 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
165 struct snd_soc_dapm_context *dapm;
166 struct snd_soc_component *component = rtd->cpu_dai->component;
169 dapm = snd_soc_component_get_dapm(component);
170 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
172 dev_err(rtd->dev, "Ref Cap -Ignore suspend failed = %d\n", ret);
177 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
180 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
181 struct snd_soc_component *component = rtd->codec_dai->component;
182 struct snd_soc_jack *jack;
185 * Headset buttons map to the google Reference headset.
186 * These can be configured by userspace.
188 ret = snd_soc_card_jack_new(&kabylake_audio_card, "Headset Jack",
189 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
190 SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
193 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
197 jack = &ctx->kabylake_headset;
198 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
199 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
200 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
201 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
203 snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL);
205 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "DMIC");
207 dev_err(rtd->dev, "DMIC - Ignore suspend failed = %d\n", ret);
212 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
214 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
215 struct snd_soc_dai *dai = rtd->codec_dai;
216 struct kbl_hdmi_pcm *pcm;
218 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
222 pcm->device = device;
223 pcm->codec_dai = dai;
225 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
230 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
232 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
235 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
237 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
240 static const unsigned int rates[] = {
244 static const struct snd_pcm_hw_constraint_list constraints_rates = {
245 .count = ARRAY_SIZE(rates),
250 static const unsigned int channels[] = {
254 static const struct snd_pcm_hw_constraint_list constraints_channels = {
255 .count = ARRAY_SIZE(channels),
260 static int kbl_fe_startup(struct snd_pcm_substream *substream)
262 struct snd_pcm_runtime *runtime = substream->runtime;
265 * On this platform for PCM device we support,
271 runtime->hw.channels_max = 2;
272 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
273 &constraints_channels);
275 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
276 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
278 snd_pcm_hw_constraint_list(runtime, 0,
279 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
284 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
285 .startup = kbl_fe_startup,
288 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
289 struct snd_pcm_hw_params *params)
291 struct snd_interval *rate = hw_param_interval(params,
292 SNDRV_PCM_HW_PARAM_RATE);
293 struct snd_interval *channels = hw_param_interval(params,
294 SNDRV_PCM_HW_PARAM_CHANNELS);
295 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
296 struct snd_soc_dpcm *dpcm = container_of(
297 params, struct snd_soc_dpcm, hw_params);
298 struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
299 struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
302 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
304 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
305 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
306 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
307 rate->min = rate->max = 48000;
308 channels->min = channels->max = 2;
310 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
311 } else if (!strcmp(fe_dai_link->name, "Kbl Audio DMIC cap")) {
312 if (params_channels(params) == 2 ||
313 DMIC_CH(dmic_constraints) == 2)
314 channels->min = channels->max = 2;
316 channels->min = channels->max = 4;
319 * The speaker on the SSP0 supports S16_LE and not S24_LE.
320 * thus changing the mask here
322 if (!strcmp(be_dai_link->name, "SSP0-Codec"))
323 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
328 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
329 struct snd_pcm_hw_params *params)
331 struct snd_soc_pcm_runtime *rtd = substream->private_data;
332 struct snd_soc_dai *codec_dai = rtd->codec_dai;
335 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
336 rt5663_sel_asrc_clk_src(codec_dai->component,
337 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
338 RT5663_CLK_SEL_I2S1_ASRC);
340 ret = snd_soc_dai_set_sysclk(codec_dai,
341 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
343 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
348 static struct snd_soc_ops kabylake_rt5663_ops = {
349 .hw_params = kabylake_rt5663_hw_params,
352 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
353 struct snd_pcm_hw_params *params)
355 struct snd_soc_pcm_runtime *rtd = substream->private_data;
358 for (j = 0; j < rtd->num_codecs; j++) {
359 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
361 if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) {
362 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16);
364 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
368 ret = snd_soc_dai_set_sysclk(codec_dai,
369 RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
371 dev_err(rtd->dev, "set sysclk err: %d\n", ret);
375 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
376 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
378 dev_err(rtd->dev, "DEV0 TDM slot err:%d\n", ret);
383 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
384 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
386 dev_err(rtd->dev, "DEV1 TDM slot err:%d\n", ret);
394 static struct snd_soc_ops kabylake_ssp0_ops = {
395 .hw_params = kabylake_ssp0_hw_params,
398 static const unsigned int channels_dmic[] = {
402 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
403 .count = ARRAY_SIZE(channels_dmic),
404 .list = channels_dmic,
408 static const unsigned int dmic_2ch[] = {
412 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
413 .count = ARRAY_SIZE(dmic_2ch),
418 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
420 struct snd_pcm_runtime *runtime = substream->runtime;
422 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
423 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
426 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
427 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
429 return snd_pcm_hw_constraint_list(substream->runtime, 0,
430 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
433 static struct snd_soc_ops kabylake_dmic_ops = {
434 .startup = kabylake_dmic_startup,
437 /* kabylake digital audio interface glue - connects codec <--> CPU */
438 static struct snd_soc_dai_link kabylake_dais[] = {
439 /* Front End DAI links */
440 [KBL_DPCM_AUDIO_PB] = {
441 .name = "Kbl Audio Port",
442 .stream_name = "Audio",
443 .cpu_dai_name = "System Pin",
444 .platform_name = "0000:00:1f.3",
446 .codec_name = "snd-soc-dummy",
447 .codec_dai_name = "snd-soc-dummy-dai",
449 .init = kabylake_rt5663_fe_init,
451 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
453 .ops = &kabylake_rt5663_fe_ops,
455 [KBL_DPCM_AUDIO_CP] = {
456 .name = "Kbl Audio Capture Port",
457 .stream_name = "Audio Record",
458 .cpu_dai_name = "System Pin",
459 .platform_name = "0000:00:1f.3",
461 .codec_name = "snd-soc-dummy",
462 .codec_dai_name = "snd-soc-dummy-dai",
465 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
467 .ops = &kabylake_rt5663_fe_ops,
469 [KBL_DPCM_AUDIO_HS_PB] = {
470 .name = "Kbl Audio Headset Playback",
471 .stream_name = "Headset Audio",
472 .cpu_dai_name = "System Pin2",
473 .codec_name = "snd-soc-dummy",
474 .codec_dai_name = "snd-soc-dummy-dai",
475 .platform_name = "0000:00:1f.3",
480 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
481 .name = "Kbl Audio Echo Reference cap",
482 .stream_name = "Echoreference Capture",
483 .cpu_dai_name = "Echoref Pin",
484 .codec_name = "snd-soc-dummy",
485 .codec_dai_name = "snd-soc-dummy-dai",
486 .platform_name = "0000:00:1f.3",
491 [KBL_DPCM_AUDIO_RT5514_DSP] = {
492 .name = "rt5514 dsp",
493 .stream_name = "Wake on Voice",
494 .cpu_dai_name = "spi-PRP0001:00",
495 .platform_name = "spi-PRP0001:00",
496 .codec_name = "snd-soc-dummy",
497 .codec_dai_name = "snd-soc-dummy-dai",
499 [KBL_DPCM_AUDIO_DMIC_CP] = {
500 .name = "Kbl Audio DMIC cap",
501 .stream_name = "dmiccap",
502 .cpu_dai_name = "DMIC Pin",
503 .codec_name = "snd-soc-dummy",
504 .codec_dai_name = "snd-soc-dummy-dai",
505 .platform_name = "0000:00:1f.3",
510 .ops = &kabylake_dmic_ops,
512 [KBL_DPCM_AUDIO_HDMI1_PB] = {
513 .name = "Kbl HDMI Port1",
514 .stream_name = "Hdmi1",
515 .cpu_dai_name = "HDMI1 Pin",
516 .codec_name = "snd-soc-dummy",
517 .codec_dai_name = "snd-soc-dummy-dai",
518 .platform_name = "0000:00:1f.3",
522 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
526 [KBL_DPCM_AUDIO_HDMI2_PB] = {
527 .name = "Kbl HDMI Port2",
528 .stream_name = "Hdmi2",
529 .cpu_dai_name = "HDMI2 Pin",
530 .codec_name = "snd-soc-dummy",
531 .codec_dai_name = "snd-soc-dummy-dai",
532 .platform_name = "0000:00:1f.3",
536 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
540 /* Back End DAI links */
541 /* single Back end dai for both max speakers and dmic */
544 .name = "SSP0-Codec",
546 .cpu_dai_name = "SSP0 Pin",
547 .platform_name = "0000:00:1f.3",
549 .codecs = ssp0_codec_components,
550 .num_codecs = ARRAY_SIZE(ssp0_codec_components),
551 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
552 SND_SOC_DAIFMT_NB_NF |
553 SND_SOC_DAIFMT_CBS_CFS,
554 .ignore_pmdown_time = 1,
555 .be_hw_params_fixup = kabylake_ssp_fixup,
558 .ops = &kabylake_ssp0_ops,
561 .name = "SSP1-Codec",
563 .cpu_dai_name = "SSP1 Pin",
564 .platform_name = "0000:00:1f.3",
566 .codec_name = RT5663_DEV_NAME,
567 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
568 .init = kabylake_rt5663_codec_init,
569 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
570 SND_SOC_DAIFMT_CBS_CFS,
571 .ignore_pmdown_time = 1,
572 .be_hw_params_fixup = kabylake_ssp_fixup,
573 .ops = &kabylake_rt5663_ops,
580 .cpu_dai_name = "iDisp1 Pin",
581 .codec_name = "ehdaudio0D2",
582 .codec_dai_name = "intel-hdmi-hifi1",
583 .platform_name = "0000:00:1f.3",
585 .init = kabylake_hdmi1_init,
591 .cpu_dai_name = "iDisp2 Pin",
592 .codec_name = "ehdaudio0D2",
593 .codec_dai_name = "intel-hdmi-hifi2",
594 .platform_name = "0000:00:1f.3",
595 .init = kabylake_hdmi2_init,
601 static int kabylake_card_late_probe(struct snd_soc_card *card)
603 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
604 struct kbl_hdmi_pcm *pcm;
605 struct snd_soc_component *component = NULL;
607 char jack_name[NAME_SIZE];
609 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
610 component = pcm->codec_dai->component;
611 snprintf(jack_name, sizeof(jack_name),
612 "HDMI/DP,pcm=%d Jack", pcm->device);
613 err = snd_soc_card_jack_new(card, jack_name,
614 SND_JACK_AVOUT, &ctx->kabylake_hdmi[i],
619 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
620 &ctx->kabylake_hdmi[i]);
629 return hdac_hdmi_jack_port_init(component, &card->dapm);
633 * kabylake audio machine driver for MAX98927 + RT5514 + RT5663
635 static struct snd_soc_card kabylake_audio_card = {
636 .name = "kbl_r5514_5663_max",
637 .owner = THIS_MODULE,
638 .dai_link = kabylake_dais,
639 .num_links = ARRAY_SIZE(kabylake_dais),
640 .controls = kabylake_controls,
641 .num_controls = ARRAY_SIZE(kabylake_controls),
642 .dapm_widgets = kabylake_widgets,
643 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
644 .dapm_routes = kabylake_map,
645 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
646 .codec_conf = max98927_codec_conf,
647 .num_configs = ARRAY_SIZE(max98927_codec_conf),
648 .fully_routed = true,
649 .late_probe = kabylake_card_late_probe,
652 static int kabylake_audio_probe(struct platform_device *pdev)
654 struct kbl_codec_private *ctx;
655 struct skl_machine_pdata *pdata;
657 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
661 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
663 kabylake_audio_card.dev = &pdev->dev;
664 snd_soc_card_set_drvdata(&kabylake_audio_card, ctx);
666 pdata = dev_get_drvdata(&pdev->dev);
668 dmic_constraints = pdata->dmic_num == 2 ?
669 &constraints_dmic_2ch : &constraints_dmic_channels;
671 return devm_snd_soc_register_card(&pdev->dev, &kabylake_audio_card);
674 static const struct platform_device_id kbl_board_ids[] = {
675 { .name = "kbl_r5514_5663_max" },
679 static struct platform_driver kabylake_audio = {
680 .probe = kabylake_audio_probe,
682 .name = "kbl_r5514_5663_max",
683 .pm = &snd_soc_pm_ops,
685 .id_table = kbl_board_ids,
688 module_platform_driver(kabylake_audio)
690 /* Module information */
691 MODULE_DESCRIPTION("Audio Machine driver-RT5663 RT5514 & MAX98927");
692 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
693 MODULE_LICENSE("GPL v2");
694 MODULE_ALIAS("platform:kbl_r5514_5663_max");