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_SINK("WoV Sink"),
96 SND_SOC_DAPM_SPK("DP", NULL
),
97 SND_SOC_DAPM_SPK("HDMI", NULL
),
98 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM
, 0, 0,
99 platform_clock_control
, SND_SOC_DAPM_PRE_PMU
|
100 SND_SOC_DAPM_POST_PMD
),
103 static const struct snd_soc_dapm_route skylake_map
[] = {
104 /* HP jack connectors - unknown if we have jack detection */
105 {"Headphone Jack", NULL
, "HPOL"},
106 {"Headphone Jack", NULL
, "HPOR"},
109 {"Left Speaker", NULL
, "Left OUT"},
110 {"Right Speaker", NULL
, "Right OUT"},
113 {"MIC", NULL
, "Headset Mic"},
114 {"DMic", NULL
, "SoC DMIC"},
116 {"WoV Sink", NULL
, "hwd_in sink"},
118 {"HDMI", NULL
, "hif5 Output"},
119 {"DP", NULL
, "hif6 Output"},
120 /* CODEC BE connections */
121 { "Left Playback", NULL
, "ssp0 Tx"},
122 { "Right Playback", NULL
, "ssp0 Tx"},
123 { "ssp0 Tx", NULL
, "codec0_out"},
125 { "Playback", NULL
, "ssp1 Tx"},
126 { "ssp1 Tx", NULL
, "codec1_out"},
128 { "codec0_in", NULL
, "ssp1 Rx" },
129 { "ssp1 Rx", NULL
, "Capture" },
132 { "dmic01_hifi", NULL
, "DMIC01 Rx" },
133 { "DMIC01 Rx", NULL
, "DMIC AIF" },
134 { "hifi1", NULL
, "iDisp Tx"},
135 { "iDisp Tx", NULL
, "iDisp_out"},
136 { "Headphone Jack", NULL
, "Platform Clock" },
137 { "Headset Mic", NULL
, "Platform Clock" },
140 static struct snd_soc_codec_conf ssm4567_codec_conf
[] = {
142 .dev_name
= "i2c-INT343B:00",
143 .name_prefix
= "Left",
146 .dev_name
= "i2c-INT343B:01",
147 .name_prefix
= "Right",
151 static struct snd_soc_dai_link_component ssm4567_codec_components
[] = {
153 .name
= "i2c-INT343B:00",
154 .dai_name
= SKL_SSM_CODEC_DAI
,
157 .name
= "i2c-INT343B:01",
158 .dai_name
= SKL_SSM_CODEC_DAI
,
162 static int skylake_ssm4567_codec_init(struct snd_soc_pcm_runtime
*rtd
)
166 /* Slot 1 for left */
167 ret
= snd_soc_dai_set_tdm_slot(rtd
->codec_dais
[0], 0x01, 0x01, 2, 48);
171 /* Slot 2 for right */
172 ret
= snd_soc_dai_set_tdm_slot(rtd
->codec_dais
[1], 0x02, 0x02, 2, 48);
179 static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime
*rtd
)
182 struct snd_soc_codec
*codec
= rtd
->codec
;
185 * 4 buttons here map to the google Reference headset
186 * The use of these buttons can be decided by the user space.
188 ret
= snd_soc_card_jack_new(&skylake_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
, &skylake_headset
,
193 dev_err(rtd
->dev
, "Headset Jack creation failed %d\n", ret
);
197 nau8825_enable_jack_detect(codec
, &skylake_headset
);
199 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
200 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "WoV Sink");
205 static int skylake_nau8825_fe_init(struct snd_soc_pcm_runtime
*rtd
)
207 struct snd_soc_dapm_context
*dapm
;
208 struct snd_soc_component
*component
= rtd
->cpu_dai
->component
;
210 dapm
= snd_soc_component_get_dapm(component
);
211 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
216 static unsigned int rates
[] = {
220 static struct snd_pcm_hw_constraint_list constraints_rates
= {
221 .count
= ARRAY_SIZE(rates
),
226 static unsigned int channels
[] = {
230 static struct snd_pcm_hw_constraint_list constraints_channels
= {
231 .count
= ARRAY_SIZE(channels
),
236 static int skl_fe_startup(struct snd_pcm_substream
*substream
)
238 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
241 * on this platform for PCM device we support,
247 runtime
->hw
.channels_max
= 2;
248 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
249 &constraints_channels
);
251 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
252 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
254 snd_pcm_hw_constraint_list(runtime
, 0,
255 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
260 static const struct snd_soc_ops skylake_nau8825_fe_ops
= {
261 .startup
= skl_fe_startup
,
264 static int skylake_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
265 struct snd_pcm_hw_params
*params
)
267 struct snd_interval
*rate
= hw_param_interval(params
,
268 SNDRV_PCM_HW_PARAM_RATE
);
269 struct snd_interval
*channels
= hw_param_interval(params
,
270 SNDRV_PCM_HW_PARAM_CHANNELS
);
271 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
273 /* The ADSP will covert the FE rate to 48k, stereo */
274 rate
->min
= rate
->max
= 48000;
275 channels
->min
= channels
->max
= 2;
277 /* set SSP0 to 24 bit */
279 snd_mask_set(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
283 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
284 struct snd_pcm_hw_params
*params
)
286 struct snd_interval
*channels
= hw_param_interval(params
,
287 SNDRV_PCM_HW_PARAM_CHANNELS
);
288 if (params_channels(params
) == 2)
289 channels
->min
= channels
->max
= 2;
291 channels
->min
= channels
->max
= 4;
296 static int skylake_nau8825_hw_params(struct snd_pcm_substream
*substream
,
297 struct snd_pcm_hw_params
*params
)
299 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
300 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
303 ret
= snd_soc_dai_set_sysclk(codec_dai
,
304 NAU8825_CLK_MCLK
, 24000000, SND_SOC_CLOCK_IN
);
307 dev_err(rtd
->dev
, "snd_soc_dai_set_sysclk err = %d\n", ret
);
312 static struct snd_soc_ops skylake_nau8825_ops
= {
313 .hw_params
= skylake_nau8825_hw_params
,
316 static unsigned int channels_dmic
[] = {
320 static struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
321 .count
= ARRAY_SIZE(channels_dmic
),
322 .list
= channels_dmic
,
326 static int skylake_dmic_startup(struct snd_pcm_substream
*substream
)
328 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
330 runtime
->hw
.channels_max
= 4;
331 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
332 &constraints_dmic_channels
);
334 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
335 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
338 static struct snd_soc_ops skylake_dmic_ops
= {
339 .startup
= skylake_dmic_startup
,
342 static unsigned int rates_16000
[] = {
346 static struct snd_pcm_hw_constraint_list constraints_16000
= {
347 .count
= ARRAY_SIZE(rates_16000
),
351 static int skylake_refcap_startup(struct snd_pcm_substream
*substream
)
353 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
354 SNDRV_PCM_HW_PARAM_RATE
,
358 static struct snd_soc_ops skylaye_refcap_ops
= {
359 .startup
= skylake_refcap_startup
,
362 /* skylake digital audio interface glue - connects codec <--> CPU */
363 static struct snd_soc_dai_link skylake_dais
[] = {
364 /* Front End DAI links */
366 .name
= "Skl Audio Port",
367 .stream_name
= "Audio",
368 .cpu_dai_name
= "System Pin",
369 .platform_name
= "0000:00:1f.3",
371 .codec_name
= "snd-soc-dummy",
372 .codec_dai_name
= "snd-soc-dummy-dai",
374 .init
= skylake_nau8825_fe_init
,
376 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
378 .ops
= &skylake_nau8825_fe_ops
,
381 .name
= "Skl Audio Capture Port",
382 .stream_name
= "Audio Record",
383 .cpu_dai_name
= "System Pin",
384 .platform_name
= "0000:00:1f.3",
386 .codec_name
= "snd-soc-dummy",
387 .codec_dai_name
= "snd-soc-dummy-dai",
390 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
392 .ops
= &skylake_nau8825_fe_ops
,
395 .name
= "Skl Audio Reference cap",
396 .stream_name
= "Wake on Voice",
397 .cpu_dai_name
= "Reference Pin",
398 .codec_name
= "snd-soc-dummy",
399 .codec_dai_name
= "snd-soc-dummy-dai",
400 .platform_name
= "0000:00:1f.3",
406 .ops
= &skylaye_refcap_ops
,
409 .name
= "Skl Audio DMIC cap",
410 .stream_name
= "dmiccap",
411 .cpu_dai_name
= "DMIC Pin",
412 .codec_name
= "snd-soc-dummy",
413 .codec_dai_name
= "snd-soc-dummy-dai",
414 .platform_name
= "0000:00:1f.3",
419 .ops
= &skylake_dmic_ops
,
422 .name
= "Skl HDMI Port",
423 .stream_name
= "Hdmi",
424 .cpu_dai_name
= "HDMI Pin",
425 .codec_name
= "snd-soc-dummy",
426 .codec_dai_name
= "snd-soc-dummy-dai",
427 .platform_name
= "0000:00:1f.3",
434 /* Back End DAI links */
437 .name
= "SSP0-Codec",
439 .cpu_dai_name
= "SSP0 Pin",
440 .platform_name
= "0000:00:1f.3",
442 .codecs
= ssm4567_codec_components
,
443 .num_codecs
= ARRAY_SIZE(ssm4567_codec_components
),
444 .dai_fmt
= SND_SOC_DAIFMT_DSP_A
|
445 SND_SOC_DAIFMT_IB_NF
|
446 SND_SOC_DAIFMT_CBS_CFS
,
447 .init
= skylake_ssm4567_codec_init
,
448 .ignore_pmdown_time
= 1,
449 .be_hw_params_fixup
= skylake_ssp_fixup
,
454 .name
= "SSP1-Codec",
456 .cpu_dai_name
= "SSP1 Pin",
457 .platform_name
= "0000:00:1f.3",
459 .codec_name
= "i2c-10508825:00",
460 .codec_dai_name
= SKL_NUVOTON_CODEC_DAI
,
461 .init
= skylake_nau8825_codec_init
,
462 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
463 SND_SOC_DAIFMT_CBS_CFS
,
464 .ignore_pmdown_time
= 1,
465 .be_hw_params_fixup
= skylake_ssp_fixup
,
466 .ops
= &skylake_nau8825_ops
,
473 .cpu_dai_name
= "DMIC01 Pin",
474 .codec_name
= "dmic-codec",
475 .codec_dai_name
= "dmic-hifi",
476 .platform_name
= "0000:00:1f.3",
478 .be_hw_params_fixup
= skylake_dmic_fixup
,
485 .cpu_dai_name
= "iDisp Pin",
486 .codec_name
= "ehdaudio0D2",
487 .codec_dai_name
= "intel-hdmi-hifi1",
488 .platform_name
= "0000:00:1f.3",
494 /* skylake audio machine driver for SPT + NAU88L25 */
495 static struct snd_soc_card skylake_audio_card
= {
496 .name
= "sklnau8825adi",
497 .owner
= THIS_MODULE
,
498 .dai_link
= skylake_dais
,
499 .num_links
= ARRAY_SIZE(skylake_dais
),
500 .controls
= skylake_controls
,
501 .num_controls
= ARRAY_SIZE(skylake_controls
),
502 .dapm_widgets
= skylake_widgets
,
503 .num_dapm_widgets
= ARRAY_SIZE(skylake_widgets
),
504 .dapm_routes
= skylake_map
,
505 .num_dapm_routes
= ARRAY_SIZE(skylake_map
),
506 .codec_conf
= ssm4567_codec_conf
,
507 .num_configs
= ARRAY_SIZE(ssm4567_codec_conf
),
508 .fully_routed
= true,
511 static int skylake_audio_probe(struct platform_device
*pdev
)
513 skylake_audio_card
.dev
= &pdev
->dev
;
515 return devm_snd_soc_register_card(&pdev
->dev
, &skylake_audio_card
);
518 static struct platform_driver skylake_audio
= {
519 .probe
= skylake_audio_probe
,
521 .name
= "skl_nau88l25_ssm4567_i2s",
522 .pm
= &snd_soc_pm_ops
,
526 module_platform_driver(skylake_audio
)
528 /* Module information */
529 MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
530 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
531 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
532 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
533 MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>");
534 MODULE_DESCRIPTION("Intel Audio Machine driver for SKL with NAU88L25 and SSM4567 in I2S Mode");
535 MODULE_LICENSE("GPL v2");
536 MODULE_ALIAS("platform:skl_nau88l25_ssm4567_i2s");