2 * Intel Skylake I2S Machine Driver for NAU88L25+SSM4567
4 * Copyright (C) 2015, Intel Corporation. All rights reserved.
7 * Intel Skylake I2S Machine Driver for NAU88L25 and SSM4567
9 * Copyright (C) 2015, Intel Corporation. All rights reserved.
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/module.h>
22 #include <linux/platform_device.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/soc.h>
26 #include <sound/jack.h>
27 #include <sound/pcm_params.h>
28 #include "../../codecs/nau8825.h"
29 #include "../../codecs/hdac_hdmi.h"
31 #define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
32 #define SKL_SSM_CODEC_DAI "ssm4567-hifi"
34 static struct snd_soc_jack skylake_headset;
35 static struct snd_soc_card skylake_audio_card;
38 struct list_head head;
39 struct snd_soc_dai *codec_dai;
43 struct skl_nau88125_private {
44 struct list_head hdmi_pcm_list;
47 SKL_DPCM_AUDIO_PB = 0,
49 SKL_DPCM_AUDIO_REF_CP,
50 SKL_DPCM_AUDIO_DMIC_CP,
51 SKL_DPCM_AUDIO_HDMI1_PB,
52 SKL_DPCM_AUDIO_HDMI2_PB,
53 SKL_DPCM_AUDIO_HDMI3_PB,
56 static inline struct snd_soc_dai *skl_get_codec_dai(struct snd_soc_card *card)
58 struct snd_soc_pcm_runtime *rtd;
60 list_for_each_entry(rtd, &card->rtd_list, list) {
62 if (!strncmp(rtd->codec_dai->name, SKL_NUVOTON_CODEC_DAI,
63 strlen(SKL_NUVOTON_CODEC_DAI)))
64 return rtd->codec_dai;
70 static const struct snd_kcontrol_new skylake_controls[] = {
71 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
72 SOC_DAPM_PIN_SWITCH("Headset Mic"),
73 SOC_DAPM_PIN_SWITCH("Left Speaker"),
74 SOC_DAPM_PIN_SWITCH("Right Speaker"),
77 static int platform_clock_control(struct snd_soc_dapm_widget *w,
78 struct snd_kcontrol *k, int event)
80 struct snd_soc_dapm_context *dapm = w->dapm;
81 struct snd_soc_card *card = dapm->card;
82 struct snd_soc_dai *codec_dai;
85 codec_dai = skl_get_codec_dai(card);
87 dev_err(card->dev, "Codec dai not found\n");
91 if (SND_SOC_DAPM_EVENT_ON(event)) {
92 ret = snd_soc_dai_set_sysclk(codec_dai,
93 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
95 dev_err(card->dev, "set sysclk err = %d\n", ret);
99 ret = snd_soc_dai_set_sysclk(codec_dai,
100 NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
102 dev_err(card->dev, "set sysclk err = %d\n", ret);
109 static const struct snd_soc_dapm_widget skylake_widgets[] = {
110 SND_SOC_DAPM_HP("Headphone Jack", NULL),
111 SND_SOC_DAPM_MIC("Headset Mic", NULL),
112 SND_SOC_DAPM_SPK("Left Speaker", NULL),
113 SND_SOC_DAPM_SPK("Right Speaker", NULL),
114 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
115 SND_SOC_DAPM_SPK("DP", NULL),
116 SND_SOC_DAPM_SPK("HDMI", NULL),
117 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
118 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
119 SND_SOC_DAPM_POST_PMD),
122 static const struct snd_soc_dapm_route skylake_map[] = {
123 /* HP jack connectors - unknown if we have jack detection */
124 {"Headphone Jack", NULL, "HPOL"},
125 {"Headphone Jack", NULL, "HPOR"},
128 {"Left Speaker", NULL, "Left OUT"},
129 {"Right Speaker", NULL, "Right OUT"},
132 {"MIC", NULL, "Headset Mic"},
133 {"DMic", NULL, "SoC DMIC"},
135 {"HDMI", NULL, "hif5 Output"},
136 {"DP", NULL, "hif6 Output"},
137 /* CODEC BE connections */
138 { "Left Playback", NULL, "ssp0 Tx"},
139 { "Right Playback", NULL, "ssp0 Tx"},
140 { "ssp0 Tx", NULL, "codec0_out"},
142 /* IV feedback path */
143 { "codec0_lp_in", NULL, "ssp0 Rx"},
144 { "ssp0 Rx", NULL, "Left Capture Sense" },
145 { "ssp0 Rx", NULL, "Right Capture Sense" },
147 { "Playback", NULL, "ssp1 Tx"},
148 { "ssp1 Tx", NULL, "codec1_out"},
150 { "codec0_in", NULL, "ssp1 Rx" },
151 { "ssp1 Rx", NULL, "Capture" },
154 { "dmic01_hifi", NULL, "DMIC01 Rx" },
155 { "DMIC01 Rx", NULL, "DMIC AIF" },
157 { "hifi3", NULL, "iDisp3 Tx"},
158 { "iDisp3 Tx", NULL, "iDisp3_out"},
159 { "hifi2", NULL, "iDisp2 Tx"},
160 { "iDisp2 Tx", NULL, "iDisp2_out"},
161 { "hifi1", NULL, "iDisp1 Tx"},
162 { "iDisp1 Tx", NULL, "iDisp1_out"},
164 { "Headphone Jack", NULL, "Platform Clock" },
165 { "Headset Mic", NULL, "Platform Clock" },
168 static struct snd_soc_codec_conf ssm4567_codec_conf[] = {
170 .dev_name = "i2c-INT343B:00",
171 .name_prefix = "Left",
174 .dev_name = "i2c-INT343B:01",
175 .name_prefix = "Right",
179 static struct snd_soc_dai_link_component ssm4567_codec_components[] = {
181 .name = "i2c-INT343B:00",
182 .dai_name = SKL_SSM_CODEC_DAI,
185 .name = "i2c-INT343B:01",
186 .dai_name = SKL_SSM_CODEC_DAI,
190 static int skylake_ssm4567_codec_init(struct snd_soc_pcm_runtime *rtd)
194 /* Slot 1 for left */
195 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[0], 0x01, 0x01, 2, 48);
199 /* Slot 2 for right */
200 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[1], 0x02, 0x02, 2, 48);
207 static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
210 struct snd_soc_codec *codec = rtd->codec;
213 * 4 buttons here map to the google Reference headset
214 * The use of these buttons can be decided by the user space.
216 ret = snd_soc_card_jack_new(&skylake_audio_card, "Headset Jack",
217 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
218 SND_JACK_BTN_2 | SND_JACK_BTN_3, &skylake_headset,
221 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
225 nau8825_enable_jack_detect(codec, &skylake_headset);
227 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
232 static int skylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
234 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(rtd->card);
235 struct snd_soc_dai *dai = rtd->codec_dai;
236 struct skl_hdmi_pcm *pcm;
238 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
242 pcm->device = SKL_DPCM_AUDIO_HDMI1_PB;
243 pcm->codec_dai = dai;
245 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
250 static int skylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
252 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(rtd->card);
253 struct snd_soc_dai *dai = rtd->codec_dai;
254 struct skl_hdmi_pcm *pcm;
256 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
260 pcm->device = SKL_DPCM_AUDIO_HDMI2_PB;
261 pcm->codec_dai = dai;
263 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
269 static int skylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
271 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(rtd->card);
272 struct snd_soc_dai *dai = rtd->codec_dai;
273 struct skl_hdmi_pcm *pcm;
275 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
279 pcm->device = SKL_DPCM_AUDIO_HDMI3_PB;
280 pcm->codec_dai = dai;
282 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
287 static int skylake_nau8825_fe_init(struct snd_soc_pcm_runtime *rtd)
289 struct snd_soc_dapm_context *dapm;
290 struct snd_soc_component *component = rtd->cpu_dai->component;
292 dapm = snd_soc_component_get_dapm(component);
293 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
298 static unsigned int rates[] = {
302 static struct snd_pcm_hw_constraint_list constraints_rates = {
303 .count = ARRAY_SIZE(rates),
308 static unsigned int channels[] = {
312 static struct snd_pcm_hw_constraint_list constraints_channels = {
313 .count = ARRAY_SIZE(channels),
318 static int skl_fe_startup(struct snd_pcm_substream *substream)
320 struct snd_pcm_runtime *runtime = substream->runtime;
323 * on this platform for PCM device we support,
329 runtime->hw.channels_max = 2;
330 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
331 &constraints_channels);
333 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
334 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
336 snd_pcm_hw_constraint_list(runtime, 0,
337 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
342 static const struct snd_soc_ops skylake_nau8825_fe_ops = {
343 .startup = skl_fe_startup,
346 static int skylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
347 struct snd_pcm_hw_params *params)
349 struct snd_interval *rate = hw_param_interval(params,
350 SNDRV_PCM_HW_PARAM_RATE);
351 struct snd_interval *channels = hw_param_interval(params,
352 SNDRV_PCM_HW_PARAM_CHANNELS);
353 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
355 /* The ADSP will covert the FE rate to 48k, stereo */
356 rate->min = rate->max = 48000;
357 channels->min = channels->max = 2;
359 /* set SSP0 to 24 bit */
361 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
365 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
366 struct snd_pcm_hw_params *params)
368 struct snd_interval *channels = hw_param_interval(params,
369 SNDRV_PCM_HW_PARAM_CHANNELS);
370 if (params_channels(params) == 2)
371 channels->min = channels->max = 2;
373 channels->min = channels->max = 4;
378 static int skylake_nau8825_hw_params(struct snd_pcm_substream *substream,
379 struct snd_pcm_hw_params *params)
381 struct snd_soc_pcm_runtime *rtd = substream->private_data;
382 struct snd_soc_dai *codec_dai = rtd->codec_dai;
385 ret = snd_soc_dai_set_sysclk(codec_dai,
386 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
389 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
394 static struct snd_soc_ops skylake_nau8825_ops = {
395 .hw_params = skylake_nau8825_hw_params,
398 static unsigned int channels_dmic[] = {
402 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
403 .count = ARRAY_SIZE(channels_dmic),
404 .list = channels_dmic,
408 static int skylake_dmic_startup(struct snd_pcm_substream *substream)
410 struct snd_pcm_runtime *runtime = substream->runtime;
412 runtime->hw.channels_max = 4;
413 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
414 &constraints_dmic_channels);
416 return snd_pcm_hw_constraint_list(substream->runtime, 0,
417 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
420 static struct snd_soc_ops skylake_dmic_ops = {
421 .startup = skylake_dmic_startup,
424 static unsigned int rates_16000[] = {
428 static struct snd_pcm_hw_constraint_list constraints_16000 = {
429 .count = ARRAY_SIZE(rates_16000),
433 static int skylake_refcap_startup(struct snd_pcm_substream *substream)
435 return snd_pcm_hw_constraint_list(substream->runtime, 0,
436 SNDRV_PCM_HW_PARAM_RATE,
440 static struct snd_soc_ops skylaye_refcap_ops = {
441 .startup = skylake_refcap_startup,
444 /* skylake digital audio interface glue - connects codec <--> CPU */
445 static struct snd_soc_dai_link skylake_dais[] = {
446 /* Front End DAI links */
447 [SKL_DPCM_AUDIO_PB] = {
448 .name = "Skl Audio Port",
449 .stream_name = "Audio",
450 .cpu_dai_name = "System Pin",
451 .platform_name = "0000:00:1f.3",
453 .codec_name = "snd-soc-dummy",
454 .codec_dai_name = "snd-soc-dummy-dai",
456 .init = skylake_nau8825_fe_init,
458 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
460 .ops = &skylake_nau8825_fe_ops,
462 [SKL_DPCM_AUDIO_CP] = {
463 .name = "Skl Audio Capture Port",
464 .stream_name = "Audio Record",
465 .cpu_dai_name = "System Pin",
466 .platform_name = "0000:00:1f.3",
468 .codec_name = "snd-soc-dummy",
469 .codec_dai_name = "snd-soc-dummy-dai",
472 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
474 .ops = &skylake_nau8825_fe_ops,
476 [SKL_DPCM_AUDIO_REF_CP] = {
477 .name = "Skl Audio Reference cap",
478 .stream_name = "Wake on Voice",
479 .cpu_dai_name = "Reference Pin",
480 .codec_name = "snd-soc-dummy",
481 .codec_dai_name = "snd-soc-dummy-dai",
482 .platform_name = "0000:00:1f.3",
487 .ops = &skylaye_refcap_ops,
489 [SKL_DPCM_AUDIO_DMIC_CP] = {
490 .name = "Skl Audio DMIC cap",
491 .stream_name = "dmiccap",
492 .cpu_dai_name = "DMIC Pin",
493 .codec_name = "snd-soc-dummy",
494 .codec_dai_name = "snd-soc-dummy-dai",
495 .platform_name = "0000:00:1f.3",
500 .ops = &skylake_dmic_ops,
502 [SKL_DPCM_AUDIO_HDMI1_PB] = {
503 .name = "Skl HDMI Port1",
504 .stream_name = "Hdmi1",
505 .cpu_dai_name = "HDMI1 Pin",
506 .codec_name = "snd-soc-dummy",
507 .codec_dai_name = "snd-soc-dummy-dai",
508 .platform_name = "0000:00:1f.3",
512 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
516 [SKL_DPCM_AUDIO_HDMI2_PB] = {
517 .name = "Skl HDMI Port2",
518 .stream_name = "Hdmi2",
519 .cpu_dai_name = "HDMI2 Pin",
520 .codec_name = "snd-soc-dummy",
521 .codec_dai_name = "snd-soc-dummy-dai",
522 .platform_name = "0000:00:1f.3",
526 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
530 [SKL_DPCM_AUDIO_HDMI3_PB] = {
531 .name = "Skl HDMI Port3",
532 .stream_name = "Hdmi3",
533 .cpu_dai_name = "HDMI3 Pin",
534 .codec_name = "snd-soc-dummy",
535 .codec_dai_name = "snd-soc-dummy-dai",
536 .platform_name = "0000:00:1f.3",
538 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
545 /* Back End DAI links */
548 .name = "SSP0-Codec",
550 .cpu_dai_name = "SSP0 Pin",
551 .platform_name = "0000:00:1f.3",
553 .codecs = ssm4567_codec_components,
554 .num_codecs = ARRAY_SIZE(ssm4567_codec_components),
555 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
556 SND_SOC_DAIFMT_IB_NF |
557 SND_SOC_DAIFMT_CBS_CFS,
558 .init = skylake_ssm4567_codec_init,
559 .ignore_pmdown_time = 1,
560 .be_hw_params_fixup = skylake_ssp_fixup,
566 .name = "SSP1-Codec",
568 .cpu_dai_name = "SSP1 Pin",
569 .platform_name = "0000:00:1f.3",
571 .codec_name = "i2c-10508825:00",
572 .codec_dai_name = SKL_NUVOTON_CODEC_DAI,
573 .init = skylake_nau8825_codec_init,
574 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
575 SND_SOC_DAIFMT_CBS_CFS,
576 .ignore_pmdown_time = 1,
577 .be_hw_params_fixup = skylake_ssp_fixup,
578 .ops = &skylake_nau8825_ops,
585 .cpu_dai_name = "DMIC01 Pin",
586 .codec_name = "dmic-codec",
587 .codec_dai_name = "dmic-hifi",
588 .platform_name = "0000:00:1f.3",
590 .be_hw_params_fixup = skylake_dmic_fixup,
597 .cpu_dai_name = "iDisp1 Pin",
598 .codec_name = "ehdaudio0D2",
599 .codec_dai_name = "intel-hdmi-hifi1",
600 .platform_name = "0000:00:1f.3",
602 .init = skylake_hdmi1_init,
608 .cpu_dai_name = "iDisp2 Pin",
609 .codec_name = "ehdaudio0D2",
610 .codec_dai_name = "intel-hdmi-hifi2",
611 .platform_name = "0000:00:1f.3",
612 .init = skylake_hdmi2_init,
619 .cpu_dai_name = "iDisp3 Pin",
620 .codec_name = "ehdaudio0D2",
621 .codec_dai_name = "intel-hdmi-hifi3",
622 .platform_name = "0000:00:1f.3",
623 .init = skylake_hdmi3_init,
629 static int skylake_card_late_probe(struct snd_soc_card *card)
631 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(card);
632 struct skl_hdmi_pcm *pcm;
635 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
636 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device);
644 /* skylake audio machine driver for SPT + NAU88L25 */
645 static struct snd_soc_card skylake_audio_card = {
646 .name = "sklnau8825adi",
647 .owner = THIS_MODULE,
648 .dai_link = skylake_dais,
649 .num_links = ARRAY_SIZE(skylake_dais),
650 .controls = skylake_controls,
651 .num_controls = ARRAY_SIZE(skylake_controls),
652 .dapm_widgets = skylake_widgets,
653 .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
654 .dapm_routes = skylake_map,
655 .num_dapm_routes = ARRAY_SIZE(skylake_map),
656 .codec_conf = ssm4567_codec_conf,
657 .num_configs = ARRAY_SIZE(ssm4567_codec_conf),
658 .fully_routed = true,
659 .late_probe = skylake_card_late_probe,
662 static int skylake_audio_probe(struct platform_device *pdev)
664 struct skl_nau88125_private *ctx;
666 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
670 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
672 skylake_audio_card.dev = &pdev->dev;
673 snd_soc_card_set_drvdata(&skylake_audio_card, ctx);
675 return devm_snd_soc_register_card(&pdev->dev, &skylake_audio_card);
678 static struct platform_driver skylake_audio = {
679 .probe = skylake_audio_probe,
681 .name = "skl_nau88l25_ssm4567_i2s",
682 .pm = &snd_soc_pm_ops,
686 module_platform_driver(skylake_audio)
688 /* Module information */
689 MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
690 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
691 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
692 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
693 MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>");
694 MODULE_DESCRIPTION("Intel Audio Machine driver for SKL with NAU88L25 and SSM4567 in I2S Mode");
695 MODULE_LICENSE("GPL v2");
696 MODULE_ALIAS("platform:skl_nau88l25_ssm4567_i2s");