2 * Intel Skylake I2S Machine Driver with MAXIM98357A
5 * Copyright (C) 2015, Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <sound/core.h>
20 #include <sound/jack.h>
21 #include <sound/pcm.h>
22 #include <sound/pcm_params.h>
23 #include <sound/soc.h>
24 #include "../../codecs/nau8825.h"
25 #include "../../codecs/hdac_hdmi.h"
27 #define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
28 #define SKL_MAXIM_CODEC_DAI "HiFi"
30 static struct snd_soc_jack skylake_headset
;
31 static struct snd_soc_card skylake_audio_card
;
34 SKL_DPCM_AUDIO_PB
= 0,
36 SKL_DPCM_AUDIO_REF_CP
,
37 SKL_DPCM_AUDIO_DMIC_CP
,
38 SKL_DPCM_AUDIO_HDMI1_PB
,
39 SKL_DPCM_AUDIO_HDMI2_PB
,
40 SKL_DPCM_AUDIO_HDMI3_PB
,
43 static inline struct snd_soc_dai
*skl_get_codec_dai(struct snd_soc_card
*card
)
45 struct snd_soc_pcm_runtime
*rtd
;
47 list_for_each_entry(rtd
, &card
->rtd_list
, list
) {
49 if (!strncmp(rtd
->codec_dai
->name
, SKL_NUVOTON_CODEC_DAI
,
50 strlen(SKL_NUVOTON_CODEC_DAI
)))
51 return rtd
->codec_dai
;
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; Unable to set platform clock\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
);
90 static const struct snd_kcontrol_new skylake_controls
[] = {
91 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
92 SOC_DAPM_PIN_SWITCH("Headset Mic"),
93 SOC_DAPM_PIN_SWITCH("Spk"),
96 static const struct snd_soc_dapm_widget skylake_widgets
[] = {
97 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
98 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
99 SND_SOC_DAPM_SPK("Spk", NULL
),
100 SND_SOC_DAPM_MIC("SoC DMIC", NULL
),
101 SND_SOC_DAPM_SPK("DP", NULL
),
102 SND_SOC_DAPM_SPK("HDMI", NULL
),
103 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM
, 0, 0,
104 platform_clock_control
, SND_SOC_DAPM_PRE_PMU
|
105 SND_SOC_DAPM_POST_PMD
),
108 static const struct snd_soc_dapm_route skylake_map
[] = {
109 /* HP jack connectors - unknown if we have jack detection */
110 { "Headphone Jack", NULL
, "HPOL" },
111 { "Headphone Jack", NULL
, "HPOR" },
114 { "Spk", NULL
, "Speaker" },
117 { "MIC", NULL
, "Headset Mic" },
118 { "DMic", NULL
, "SoC DMIC" },
120 {"HDMI", NULL
, "hif5 Output"},
121 {"DP", NULL
, "hif6 Output"},
123 /* CODEC BE connections */
124 { "HiFi Playback", NULL
, "ssp0 Tx" },
125 { "ssp0 Tx", NULL
, "codec0_out" },
127 { "Playback", NULL
, "ssp1 Tx" },
128 { "ssp1 Tx", NULL
, "codec1_out" },
130 { "codec0_in", NULL
, "ssp1 Rx" },
131 { "ssp1 Rx", NULL
, "Capture" },
134 { "dmic01_hifi", NULL
, "DMIC01 Rx" },
135 { "DMIC01 Rx", NULL
, "DMIC AIF" },
137 { "hifi3", NULL
, "iDisp3 Tx"},
138 { "iDisp3 Tx", NULL
, "iDisp3_out"},
139 { "hifi2", NULL
, "iDisp2 Tx"},
140 { "iDisp2 Tx", NULL
, "iDisp2_out"},
141 { "hifi1", NULL
, "iDisp1 Tx"},
142 { "iDisp1 Tx", NULL
, "iDisp1_out"},
144 { "Headphone Jack", NULL
, "Platform Clock" },
145 { "Headset Mic", NULL
, "Platform Clock" },
148 static int skylake_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
149 struct snd_pcm_hw_params
*params
)
151 struct snd_interval
*rate
= hw_param_interval(params
,
152 SNDRV_PCM_HW_PARAM_RATE
);
153 struct snd_interval
*channels
= hw_param_interval(params
,
154 SNDRV_PCM_HW_PARAM_CHANNELS
);
155 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
157 /* The ADSP will covert the FE rate to 48k, stereo */
158 rate
->min
= rate
->max
= 48000;
159 channels
->min
= channels
->max
= 2;
161 /* set SSP0 to 24 bit */
163 snd_mask_set(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
168 static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime
*rtd
)
171 struct snd_soc_codec
*codec
= rtd
->codec
;
174 * Headset buttons map to the google Reference headset.
175 * These can be configured by userspace.
177 ret
= snd_soc_card_jack_new(&skylake_audio_card
, "Headset Jack",
178 SND_JACK_HEADSET
| SND_JACK_BTN_0
| SND_JACK_BTN_1
|
179 SND_JACK_BTN_2
| SND_JACK_BTN_3
, &skylake_headset
,
182 dev_err(rtd
->dev
, "Headset Jack creation failed %d\n", ret
);
186 nau8825_enable_jack_detect(codec
, &skylake_headset
);
188 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
193 static int skylake_hdmi1_init(struct snd_soc_pcm_runtime
*rtd
)
195 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
197 return hdac_hdmi_jack_init(dai
, SKL_DPCM_AUDIO_HDMI1_PB
);
200 static int skylake_hdmi2_init(struct snd_soc_pcm_runtime
*rtd
)
202 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
204 return hdac_hdmi_jack_init(dai
, SKL_DPCM_AUDIO_HDMI2_PB
);
207 static int skylake_hdmi3_init(struct snd_soc_pcm_runtime
*rtd
)
209 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
211 return hdac_hdmi_jack_init(dai
, SKL_DPCM_AUDIO_HDMI3_PB
);
214 static int skylake_nau8825_fe_init(struct snd_soc_pcm_runtime
*rtd
)
216 struct snd_soc_dapm_context
*dapm
;
217 struct snd_soc_component
*component
= rtd
->cpu_dai
->component
;
219 dapm
= snd_soc_component_get_dapm(component
);
220 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
225 static unsigned int rates
[] = {
229 static struct snd_pcm_hw_constraint_list constraints_rates
= {
230 .count
= ARRAY_SIZE(rates
),
235 static unsigned int channels
[] = {
239 static struct snd_pcm_hw_constraint_list constraints_channels
= {
240 .count
= ARRAY_SIZE(channels
),
245 static int skl_fe_startup(struct snd_pcm_substream
*substream
)
247 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
250 * On this platform for PCM device we support,
256 runtime
->hw
.channels_max
= 2;
257 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
258 &constraints_channels
);
260 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
261 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
263 snd_pcm_hw_constraint_list(runtime
, 0,
264 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
269 static const struct snd_soc_ops skylake_nau8825_fe_ops
= {
270 .startup
= skl_fe_startup
,
273 static int skylake_nau8825_hw_params(struct snd_pcm_substream
*substream
,
274 struct snd_pcm_hw_params
*params
)
276 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
277 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
280 ret
= snd_soc_dai_set_sysclk(codec_dai
,
281 NAU8825_CLK_MCLK
, 24000000, SND_SOC_CLOCK_IN
);
284 dev_err(rtd
->dev
, "snd_soc_dai_set_sysclk err = %d\n", ret
);
289 static struct snd_soc_ops skylake_nau8825_ops
= {
290 .hw_params
= skylake_nau8825_hw_params
,
293 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
294 struct snd_pcm_hw_params
*params
)
296 struct snd_interval
*channels
= hw_param_interval(params
,
297 SNDRV_PCM_HW_PARAM_CHANNELS
);
299 if (params_channels(params
) == 2)
300 channels
->min
= channels
->max
= 2;
302 channels
->min
= channels
->max
= 4;
307 static unsigned int channels_dmic
[] = {
311 static struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
312 .count
= ARRAY_SIZE(channels_dmic
),
313 .list
= channels_dmic
,
317 static int skylake_dmic_startup(struct snd_pcm_substream
*substream
)
319 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
321 runtime
->hw
.channels_max
= 4;
322 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
323 &constraints_dmic_channels
);
325 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
326 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
329 static struct snd_soc_ops skylake_dmic_ops
= {
330 .startup
= skylake_dmic_startup
,
333 static unsigned int rates_16000
[] = {
337 static struct snd_pcm_hw_constraint_list constraints_16000
= {
338 .count
= ARRAY_SIZE(rates_16000
),
342 static int skylake_refcap_startup(struct snd_pcm_substream
*substream
)
344 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
345 SNDRV_PCM_HW_PARAM_RATE
,
349 static struct snd_soc_ops skylaye_refcap_ops
= {
350 .startup
= skylake_refcap_startup
,
353 /* skylake digital audio interface glue - connects codec <--> CPU */
354 static struct snd_soc_dai_link skylake_dais
[] = {
355 /* Front End DAI links */
356 [SKL_DPCM_AUDIO_PB
] = {
357 .name
= "Skl Audio Port",
358 .stream_name
= "Audio",
359 .cpu_dai_name
= "System Pin",
360 .platform_name
= "0000:00:1f.3",
362 .codec_name
= "snd-soc-dummy",
363 .codec_dai_name
= "snd-soc-dummy-dai",
365 .init
= skylake_nau8825_fe_init
,
367 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
369 .ops
= &skylake_nau8825_fe_ops
,
371 [SKL_DPCM_AUDIO_CP
] = {
372 .name
= "Skl Audio Capture Port",
373 .stream_name
= "Audio Record",
374 .cpu_dai_name
= "System Pin",
375 .platform_name
= "0000:00:1f.3",
377 .codec_name
= "snd-soc-dummy",
378 .codec_dai_name
= "snd-soc-dummy-dai",
381 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
383 .ops
= &skylake_nau8825_fe_ops
,
385 [SKL_DPCM_AUDIO_REF_CP
] = {
386 .name
= "Skl Audio Reference cap",
387 .stream_name
= "Wake on Voice",
388 .cpu_dai_name
= "Reference Pin",
389 .codec_name
= "snd-soc-dummy",
390 .codec_dai_name
= "snd-soc-dummy-dai",
391 .platform_name
= "0000:00:1f.3",
396 .ops
= &skylaye_refcap_ops
,
398 [SKL_DPCM_AUDIO_DMIC_CP
] = {
399 .name
= "Skl Audio DMIC cap",
400 .stream_name
= "dmiccap",
401 .cpu_dai_name
= "DMIC Pin",
402 .codec_name
= "snd-soc-dummy",
403 .codec_dai_name
= "snd-soc-dummy-dai",
404 .platform_name
= "0000:00:1f.3",
409 .ops
= &skylake_dmic_ops
,
411 [SKL_DPCM_AUDIO_HDMI1_PB
] = {
412 .name
= "Skl HDMI Port1",
413 .stream_name
= "Hdmi1",
414 .cpu_dai_name
= "HDMI1 Pin",
415 .codec_name
= "snd-soc-dummy",
416 .codec_dai_name
= "snd-soc-dummy-dai",
417 .platform_name
= "0000:00:1f.3",
421 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
425 [SKL_DPCM_AUDIO_HDMI2_PB
] = {
426 .name
= "Skl HDMI Port2",
427 .stream_name
= "Hdmi2",
428 .cpu_dai_name
= "HDMI2 Pin",
429 .codec_name
= "snd-soc-dummy",
430 .codec_dai_name
= "snd-soc-dummy-dai",
431 .platform_name
= "0000:00:1f.3",
435 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
439 [SKL_DPCM_AUDIO_HDMI3_PB
] = {
440 .name
= "Skl HDMI Port3",
441 .stream_name
= "Hdmi3",
442 .cpu_dai_name
= "HDMI3 Pin",
443 .codec_name
= "snd-soc-dummy",
444 .codec_dai_name
= "snd-soc-dummy-dai",
445 .platform_name
= "0000:00:1f.3",
447 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
454 /* Back End DAI links */
457 .name
= "SSP0-Codec",
459 .cpu_dai_name
= "SSP0 Pin",
460 .platform_name
= "0000:00:1f.3",
462 .codec_name
= "MX98357A:00",
463 .codec_dai_name
= SKL_MAXIM_CODEC_DAI
,
464 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
465 SND_SOC_DAIFMT_NB_NF
|
466 SND_SOC_DAIFMT_CBS_CFS
,
467 .ignore_pmdown_time
= 1,
468 .be_hw_params_fixup
= skylake_ssp_fixup
,
473 .name
= "SSP1-Codec",
475 .cpu_dai_name
= "SSP1 Pin",
476 .platform_name
= "0000:00:1f.3",
478 .codec_name
= "i2c-10508825:00",
479 .codec_dai_name
= SKL_NUVOTON_CODEC_DAI
,
480 .init
= skylake_nau8825_codec_init
,
481 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
482 SND_SOC_DAIFMT_CBS_CFS
,
483 .ignore_pmdown_time
= 1,
484 .be_hw_params_fixup
= skylake_ssp_fixup
,
485 .ops
= &skylake_nau8825_ops
,
492 .cpu_dai_name
= "DMIC01 Pin",
493 .codec_name
= "dmic-codec",
494 .codec_dai_name
= "dmic-hifi",
495 .platform_name
= "0000:00:1f.3",
496 .be_hw_params_fixup
= skylake_dmic_fixup
,
504 .cpu_dai_name
= "iDisp1 Pin",
505 .codec_name
= "ehdaudio0D2",
506 .codec_dai_name
= "intel-hdmi-hifi1",
507 .platform_name
= "0000:00:1f.3",
509 .init
= skylake_hdmi1_init
,
515 .cpu_dai_name
= "iDisp2 Pin",
516 .codec_name
= "ehdaudio0D2",
517 .codec_dai_name
= "intel-hdmi-hifi2",
518 .platform_name
= "0000:00:1f.3",
519 .init
= skylake_hdmi2_init
,
526 .cpu_dai_name
= "iDisp3 Pin",
527 .codec_name
= "ehdaudio0D2",
528 .codec_dai_name
= "intel-hdmi-hifi3",
529 .platform_name
= "0000:00:1f.3",
530 .init
= skylake_hdmi3_init
,
536 /* skylake audio machine driver for SPT + NAU88L25 */
537 static struct snd_soc_card skylake_audio_card
= {
538 .name
= "sklnau8825max",
539 .owner
= THIS_MODULE
,
540 .dai_link
= skylake_dais
,
541 .num_links
= ARRAY_SIZE(skylake_dais
),
542 .controls
= skylake_controls
,
543 .num_controls
= ARRAY_SIZE(skylake_controls
),
544 .dapm_widgets
= skylake_widgets
,
545 .num_dapm_widgets
= ARRAY_SIZE(skylake_widgets
),
546 .dapm_routes
= skylake_map
,
547 .num_dapm_routes
= ARRAY_SIZE(skylake_map
),
548 .fully_routed
= true,
551 static int skylake_audio_probe(struct platform_device
*pdev
)
553 skylake_audio_card
.dev
= &pdev
->dev
;
555 return devm_snd_soc_register_card(&pdev
->dev
, &skylake_audio_card
);
558 static struct platform_driver skylake_audio
= {
559 .probe
= skylake_audio_probe
,
561 .name
= "skl_nau88l25_max98357a_i2s",
562 .pm
= &snd_soc_pm_ops
,
566 module_platform_driver(skylake_audio
)
568 /* Module information */
569 MODULE_DESCRIPTION("Audio Machine driver-NAU88L25 & MAX98357A in I2S mode");
570 MODULE_AUTHOR("Rohit Ainapure <rohit.m.ainapure@intel.com");
571 MODULE_LICENSE("GPL v2");
572 MODULE_ALIAS("platform:skl_nau88l25_max98357a_i2s");