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"
30 #define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
31 #define SKL_SSM_CODEC_DAI "ssm4567-hifi"
33 static struct snd_soc_jack skylake_headset;
34 static struct snd_soc_card skylake_audio_card;
36 static inline struct snd_soc_dai *skl_get_codec_dai(struct snd_soc_card *card)
38 struct snd_soc_pcm_runtime *rtd;
40 list_for_each_entry(rtd, &card->rtd_list, list) {
42 if (!strncmp(rtd->codec_dai->name, SKL_NUVOTON_CODEC_DAI,
43 strlen(SKL_NUVOTON_CODEC_DAI)))
44 return rtd->codec_dai;
50 static const struct snd_kcontrol_new skylake_controls[] = {
51 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
52 SOC_DAPM_PIN_SWITCH("Headset Mic"),
53 SOC_DAPM_PIN_SWITCH("Left Speaker"),
54 SOC_DAPM_PIN_SWITCH("Right Speaker"),
57 static int platform_clock_control(struct snd_soc_dapm_widget *w,
58 struct snd_kcontrol *k, int event)
60 struct snd_soc_dapm_context *dapm = w->dapm;
61 struct snd_soc_card *card = dapm->card;
62 struct snd_soc_dai *codec_dai;
65 codec_dai = skl_get_codec_dai(card);
67 dev_err(card->dev, "Codec dai not found\n");
71 if (SND_SOC_DAPM_EVENT_ON(event)) {
72 ret = snd_soc_dai_set_sysclk(codec_dai,
73 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
75 dev_err(card->dev, "set sysclk err = %d\n", ret);
79 ret = snd_soc_dai_set_sysclk(codec_dai,
80 NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
82 dev_err(card->dev, "set sysclk err = %d\n", ret);
89 static const struct snd_soc_dapm_widget skylake_widgets[] = {
90 SND_SOC_DAPM_HP("Headphone Jack", NULL),
91 SND_SOC_DAPM_MIC("Headset Mic", NULL),
92 SND_SOC_DAPM_SPK("Left Speaker", NULL),
93 SND_SOC_DAPM_SPK("Right Speaker", NULL),
94 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
95 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
96 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
97 SND_SOC_DAPM_POST_PMD),
100 static const struct snd_soc_dapm_route skylake_map[] = {
101 /* HP jack connectors - unknown if we have jack detection */
102 {"Headphone Jack", NULL, "HPOL"},
103 {"Headphone Jack", NULL, "HPOR"},
106 {"Left Speaker", NULL, "Left OUT"},
107 {"Right Speaker", NULL, "Right OUT"},
110 {"MIC", NULL, "Headset Mic"},
111 {"DMic", NULL, "SoC DMIC"},
113 /* CODEC BE connections */
114 { "Left Playback", NULL, "ssp0 Tx"},
115 { "Right Playback", NULL, "ssp0 Tx"},
116 { "ssp0 Tx", NULL, "codec0_out"},
118 { "Playback", NULL, "ssp1 Tx"},
119 { "ssp1 Tx", NULL, "codec1_out"},
121 { "codec0_in", NULL, "ssp1 Rx" },
122 { "ssp1 Rx", NULL, "Capture" },
125 { "dmic01_hifi", NULL, "DMIC01 Rx" },
126 { "DMIC01 Rx", NULL, "DMIC AIF" },
127 { "Headphone Jack", NULL, "Platform Clock" },
128 { "Headset Mic", NULL, "Platform Clock" },
131 static struct snd_soc_codec_conf ssm4567_codec_conf[] = {
133 .dev_name = "i2c-INT343B:00",
134 .name_prefix = "Left",
137 .dev_name = "i2c-INT343B:01",
138 .name_prefix = "Right",
142 static struct snd_soc_dai_link_component ssm4567_codec_components[] = {
144 .name = "i2c-INT343B:00",
145 .dai_name = SKL_SSM_CODEC_DAI,
148 .name = "i2c-INT343B:01",
149 .dai_name = SKL_SSM_CODEC_DAI,
153 static int skylake_ssm4567_codec_init(struct snd_soc_pcm_runtime *rtd)
157 /* Slot 1 for left */
158 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[0], 0x01, 0x01, 2, 48);
162 /* Slot 2 for right */
163 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[1], 0x02, 0x02, 2, 48);
170 static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
173 struct snd_soc_codec *codec = rtd->codec;
176 * 4 buttons here map to the google Reference headset
177 * The use of these buttons can be decided by the user space.
179 ret = snd_soc_card_jack_new(&skylake_audio_card, "Headset Jack",
180 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
181 SND_JACK_BTN_2 | SND_JACK_BTN_3, &skylake_headset,
184 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
188 nau8825_enable_jack_detect(codec, &skylake_headset);
193 static int skylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
194 struct snd_pcm_hw_params *params)
196 struct snd_interval *rate = hw_param_interval(params,
197 SNDRV_PCM_HW_PARAM_RATE);
198 struct snd_interval *channels = hw_param_interval(params,
199 SNDRV_PCM_HW_PARAM_CHANNELS);
200 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
202 /* The ADSP will covert the FE rate to 48k, stereo */
203 rate->min = rate->max = 48000;
204 channels->min = channels->max = 2;
206 /* set SSP0 to 24 bit */
208 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
212 static int skylake_nau8825_hw_params(struct snd_pcm_substream *substream,
213 struct snd_pcm_hw_params *params)
215 struct snd_soc_pcm_runtime *rtd = substream->private_data;
216 struct snd_soc_dai *codec_dai = rtd->codec_dai;
219 ret = snd_soc_dai_set_sysclk(codec_dai,
220 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
223 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
228 static struct snd_soc_ops skylake_nau8825_ops = {
229 .hw_params = skylake_nau8825_hw_params,
232 /* skylake digital audio interface glue - connects codec <--> CPU */
233 static struct snd_soc_dai_link skylake_dais[] = {
234 /* Front End DAI links */
236 .name = "Skl Audio Port",
237 .stream_name = "Audio",
238 .cpu_dai_name = "System Pin",
239 .platform_name = "0000:00:1f.3",
241 .codec_name = "snd-soc-dummy",
242 .codec_dai_name = "snd-soc-dummy-dai",
245 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
249 .name = "Skl Audio Capture Port",
250 .stream_name = "Audio Record",
251 .cpu_dai_name = "System Pin",
252 .platform_name = "0000:00:1f.3",
254 .codec_name = "snd-soc-dummy",
255 .codec_dai_name = "snd-soc-dummy-dai",
258 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
262 .name = "Skl Audio Reference cap",
263 .stream_name = "refcap",
264 .cpu_dai_name = "Reference Pin",
265 .codec_name = "snd-soc-dummy",
266 .codec_dai_name = "snd-soc-dummy-dai",
267 .platform_name = "0000:00:1f.3",
274 /* Back End DAI links */
277 .name = "SSP0-Codec",
279 .cpu_dai_name = "SSP0 Pin",
280 .platform_name = "0000:00:1f.3",
282 .codecs = ssm4567_codec_components,
283 .num_codecs = ARRAY_SIZE(ssm4567_codec_components),
284 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
285 SND_SOC_DAIFMT_IB_NF |
286 SND_SOC_DAIFMT_CBS_CFS,
287 .init = skylake_ssm4567_codec_init,
289 .ignore_pmdown_time = 1,
290 .be_hw_params_fixup = skylake_ssp_fixup,
295 .name = "SSP1-Codec",
297 .cpu_dai_name = "SSP1 Pin",
298 .platform_name = "0000:00:1f.3",
300 .codec_name = "i2c-10508825:00",
301 .codec_dai_name = SKL_NUVOTON_CODEC_DAI,
302 .init = skylake_nau8825_codec_init,
303 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
304 SND_SOC_DAIFMT_CBS_CFS,
306 .ignore_pmdown_time = 1,
307 .be_hw_params_fixup = skylake_ssp_fixup,
308 .ops = &skylake_nau8825_ops,
315 .cpu_dai_name = "DMIC01 Pin",
316 .codec_name = "dmic-codec",
317 .codec_dai_name = "dmic-hifi",
318 .platform_name = "0000:00:1f.3",
325 /* skylake audio machine driver for SPT + NAU88L25 */
326 static struct snd_soc_card skylake_audio_card = {
327 .name = "sklnau8825adi",
328 .owner = THIS_MODULE,
329 .dai_link = skylake_dais,
330 .num_links = ARRAY_SIZE(skylake_dais),
331 .controls = skylake_controls,
332 .num_controls = ARRAY_SIZE(skylake_controls),
333 .dapm_widgets = skylake_widgets,
334 .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
335 .dapm_routes = skylake_map,
336 .num_dapm_routes = ARRAY_SIZE(skylake_map),
337 .codec_conf = ssm4567_codec_conf,
338 .num_configs = ARRAY_SIZE(ssm4567_codec_conf),
339 .fully_routed = true,
342 static int skylake_audio_probe(struct platform_device *pdev)
344 skylake_audio_card.dev = &pdev->dev;
346 return devm_snd_soc_register_card(&pdev->dev, &skylake_audio_card);
349 static struct platform_driver skylake_audio = {
350 .probe = skylake_audio_probe,
352 .name = "skl_nau88l25_ssm4567_i2s",
353 .pm = &snd_soc_pm_ops,
357 module_platform_driver(skylake_audio)
359 /* Module information */
360 MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
361 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
362 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
363 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
364 MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>");
365 MODULE_DESCRIPTION("Intel Audio Machine driver for SKL with NAU88L25 and SSM4567 in I2S Mode");
366 MODULE_LICENSE("GPL v2");
367 MODULE_ALIAS("platform:skl_nau88l25_ssm4567_i2s");