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"
26 #include "../skylake/skl.h"
28 #define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
29 #define SKL_MAXIM_CODEC_DAI "HiFi"
30 #define DMIC_CH(p) p->list[p->count-1]
32 static struct snd_soc_jack skylake_headset
;
33 static struct snd_soc_card skylake_audio_card
;
34 static const struct snd_pcm_hw_constraint_list
*dmic_constraints
;
37 struct list_head head
;
38 struct snd_soc_dai
*codec_dai
;
42 struct skl_nau8825_private
{
43 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 int platform_clock_control(struct snd_soc_dapm_widget
*w
,
71 struct snd_kcontrol
*k
, int event
)
73 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
74 struct snd_soc_card
*card
= dapm
->card
;
75 struct snd_soc_dai
*codec_dai
;
78 codec_dai
= skl_get_codec_dai(card
);
80 dev_err(card
->dev
, "Codec dai not found; Unable to set platform clock\n");
84 if (SND_SOC_DAPM_EVENT_ON(event
)) {
85 ret
= snd_soc_dai_set_sysclk(codec_dai
,
86 NAU8825_CLK_MCLK
, 24000000, SND_SOC_CLOCK_IN
);
88 dev_err(card
->dev
, "set sysclk err = %d\n", ret
);
92 ret
= snd_soc_dai_set_sysclk(codec_dai
,
93 NAU8825_CLK_INTERNAL
, 0, SND_SOC_CLOCK_IN
);
95 dev_err(card
->dev
, "set sysclk err = %d\n", ret
);
103 static const struct snd_kcontrol_new skylake_controls
[] = {
104 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
105 SOC_DAPM_PIN_SWITCH("Headset Mic"),
106 SOC_DAPM_PIN_SWITCH("Spk"),
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("Spk", NULL
),
113 SND_SOC_DAPM_MIC("SoC DMIC", NULL
),
114 SND_SOC_DAPM_SPK("DP", NULL
),
115 SND_SOC_DAPM_SPK("HDMI", NULL
),
116 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM
, 0, 0,
117 platform_clock_control
, SND_SOC_DAPM_PRE_PMU
|
118 SND_SOC_DAPM_POST_PMD
),
121 static const struct snd_soc_dapm_route skylake_map
[] = {
122 /* HP jack connectors - unknown if we have jack detection */
123 { "Headphone Jack", NULL
, "HPOL" },
124 { "Headphone Jack", NULL
, "HPOR" },
127 { "Spk", NULL
, "Speaker" },
130 { "MIC", NULL
, "Headset Mic" },
131 { "DMic", NULL
, "SoC DMIC" },
133 {"HDMI", NULL
, "hif5 Output"},
134 {"DP", NULL
, "hif6 Output"},
136 /* CODEC BE connections */
137 { "HiFi Playback", NULL
, "ssp0 Tx" },
138 { "ssp0 Tx", NULL
, "codec0_out" },
140 { "Playback", NULL
, "ssp1 Tx" },
141 { "ssp1 Tx", NULL
, "codec1_out" },
143 { "codec0_in", NULL
, "ssp1 Rx" },
144 { "ssp1 Rx", NULL
, "Capture" },
147 { "dmic01_hifi", NULL
, "DMIC01 Rx" },
148 { "DMIC01 Rx", NULL
, "DMIC AIF" },
150 { "hifi3", NULL
, "iDisp3 Tx"},
151 { "iDisp3 Tx", NULL
, "iDisp3_out"},
152 { "hifi2", NULL
, "iDisp2 Tx"},
153 { "iDisp2 Tx", NULL
, "iDisp2_out"},
154 { "hifi1", NULL
, "iDisp1 Tx"},
155 { "iDisp1 Tx", NULL
, "iDisp1_out"},
157 { "Headphone Jack", NULL
, "Platform Clock" },
158 { "Headset Mic", NULL
, "Platform Clock" },
161 static int skylake_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
162 struct snd_pcm_hw_params
*params
)
164 struct snd_interval
*rate
= hw_param_interval(params
,
165 SNDRV_PCM_HW_PARAM_RATE
);
166 struct snd_interval
*channels
= hw_param_interval(params
,
167 SNDRV_PCM_HW_PARAM_CHANNELS
);
168 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
170 /* The ADSP will covert the FE rate to 48k, stereo */
171 rate
->min
= rate
->max
= 48000;
172 channels
->min
= channels
->max
= 2;
174 /* set SSP0 to 24 bit */
176 snd_mask_set(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
181 static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime
*rtd
)
184 struct snd_soc_codec
*codec
= rtd
->codec
;
187 * Headset buttons map to the google Reference headset.
188 * These can be configured by userspace.
190 ret
= snd_soc_card_jack_new(&skylake_audio_card
, "Headset Jack",
191 SND_JACK_HEADSET
| SND_JACK_BTN_0
| SND_JACK_BTN_1
|
192 SND_JACK_BTN_2
| SND_JACK_BTN_3
, &skylake_headset
,
195 dev_err(rtd
->dev
, "Headset Jack creation failed %d\n", ret
);
199 nau8825_enable_jack_detect(codec
, &skylake_headset
);
201 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
206 static int skylake_hdmi1_init(struct snd_soc_pcm_runtime
*rtd
)
208 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
209 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
210 struct skl_hdmi_pcm
*pcm
;
212 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
216 pcm
->device
= SKL_DPCM_AUDIO_HDMI1_PB
;
217 pcm
->codec_dai
= dai
;
219 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
224 static int skylake_hdmi2_init(struct snd_soc_pcm_runtime
*rtd
)
226 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
227 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
228 struct skl_hdmi_pcm
*pcm
;
230 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
234 pcm
->device
= SKL_DPCM_AUDIO_HDMI2_PB
;
235 pcm
->codec_dai
= dai
;
237 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
242 static int skylake_hdmi3_init(struct snd_soc_pcm_runtime
*rtd
)
244 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
245 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
246 struct skl_hdmi_pcm
*pcm
;
248 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
252 pcm
->device
= SKL_DPCM_AUDIO_HDMI3_PB
;
253 pcm
->codec_dai
= dai
;
255 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
260 static int skylake_nau8825_fe_init(struct snd_soc_pcm_runtime
*rtd
)
262 struct snd_soc_dapm_context
*dapm
;
263 struct snd_soc_component
*component
= rtd
->cpu_dai
->component
;
265 dapm
= snd_soc_component_get_dapm(component
);
266 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
271 static unsigned int rates
[] = {
275 static struct snd_pcm_hw_constraint_list constraints_rates
= {
276 .count
= ARRAY_SIZE(rates
),
281 static unsigned int channels
[] = {
285 static struct snd_pcm_hw_constraint_list constraints_channels
= {
286 .count
= ARRAY_SIZE(channels
),
291 static int skl_fe_startup(struct snd_pcm_substream
*substream
)
293 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
296 * On this platform for PCM device we support,
302 runtime
->hw
.channels_max
= 2;
303 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
304 &constraints_channels
);
306 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
307 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
309 snd_pcm_hw_constraint_list(runtime
, 0,
310 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
315 static const struct snd_soc_ops skylake_nau8825_fe_ops
= {
316 .startup
= skl_fe_startup
,
319 static int skylake_nau8825_hw_params(struct snd_pcm_substream
*substream
,
320 struct snd_pcm_hw_params
*params
)
322 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
323 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
326 ret
= snd_soc_dai_set_sysclk(codec_dai
,
327 NAU8825_CLK_MCLK
, 24000000, SND_SOC_CLOCK_IN
);
330 dev_err(rtd
->dev
, "snd_soc_dai_set_sysclk err = %d\n", ret
);
335 static const struct snd_soc_ops skylake_nau8825_ops
= {
336 .hw_params
= skylake_nau8825_hw_params
,
339 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
340 struct snd_pcm_hw_params
*params
)
342 struct snd_interval
*channels
= hw_param_interval(params
,
343 SNDRV_PCM_HW_PARAM_CHANNELS
);
345 if (params_channels(params
) == 2 || DMIC_CH(dmic_constraints
) == 2)
346 channels
->min
= channels
->max
= 2;
348 channels
->min
= channels
->max
= 4;
353 static unsigned int channels_dmic
[] = {
357 static struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
358 .count
= ARRAY_SIZE(channels_dmic
),
359 .list
= channels_dmic
,
363 static const unsigned int dmic_2ch
[] = {
367 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch
= {
368 .count
= ARRAY_SIZE(dmic_2ch
),
373 static int skylake_dmic_startup(struct snd_pcm_substream
*substream
)
375 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
377 runtime
->hw
.channels_max
= DMIC_CH(dmic_constraints
);
378 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
381 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
382 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
385 static const struct snd_soc_ops skylake_dmic_ops
= {
386 .startup
= skylake_dmic_startup
,
389 static unsigned int rates_16000
[] = {
393 static struct snd_pcm_hw_constraint_list constraints_16000
= {
394 .count
= ARRAY_SIZE(rates_16000
),
398 static const unsigned int ch_mono
[] = {
402 static const struct snd_pcm_hw_constraint_list constraints_refcap
= {
403 .count
= ARRAY_SIZE(ch_mono
),
407 static int skylake_refcap_startup(struct snd_pcm_substream
*substream
)
409 substream
->runtime
->hw
.channels_max
= 1;
410 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
411 SNDRV_PCM_HW_PARAM_CHANNELS
,
412 &constraints_refcap
);
414 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
415 SNDRV_PCM_HW_PARAM_RATE
,
419 static const struct snd_soc_ops skylaye_refcap_ops
= {
420 .startup
= skylake_refcap_startup
,
423 /* skylake digital audio interface glue - connects codec <--> CPU */
424 static struct snd_soc_dai_link skylake_dais
[] = {
425 /* Front End DAI links */
426 [SKL_DPCM_AUDIO_PB
] = {
427 .name
= "Skl Audio Port",
428 .stream_name
= "Audio",
429 .cpu_dai_name
= "System Pin",
430 .platform_name
= "0000:00:1f.3",
432 .codec_name
= "snd-soc-dummy",
433 .codec_dai_name
= "snd-soc-dummy-dai",
435 .init
= skylake_nau8825_fe_init
,
437 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
439 .ops
= &skylake_nau8825_fe_ops
,
441 [SKL_DPCM_AUDIO_CP
] = {
442 .name
= "Skl Audio Capture Port",
443 .stream_name
= "Audio Record",
444 .cpu_dai_name
= "System Pin",
445 .platform_name
= "0000:00:1f.3",
447 .codec_name
= "snd-soc-dummy",
448 .codec_dai_name
= "snd-soc-dummy-dai",
451 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
453 .ops
= &skylake_nau8825_fe_ops
,
455 [SKL_DPCM_AUDIO_REF_CP
] = {
456 .name
= "Skl Audio Reference cap",
457 .stream_name
= "Wake on Voice",
458 .cpu_dai_name
= "Reference Pin",
459 .codec_name
= "snd-soc-dummy",
460 .codec_dai_name
= "snd-soc-dummy-dai",
461 .platform_name
= "0000:00:1f.3",
466 .ops
= &skylaye_refcap_ops
,
468 [SKL_DPCM_AUDIO_DMIC_CP
] = {
469 .name
= "Skl Audio DMIC cap",
470 .stream_name
= "dmiccap",
471 .cpu_dai_name
= "DMIC Pin",
472 .codec_name
= "snd-soc-dummy",
473 .codec_dai_name
= "snd-soc-dummy-dai",
474 .platform_name
= "0000:00:1f.3",
479 .ops
= &skylake_dmic_ops
,
481 [SKL_DPCM_AUDIO_HDMI1_PB
] = {
482 .name
= "Skl HDMI Port1",
483 .stream_name
= "Hdmi1",
484 .cpu_dai_name
= "HDMI1 Pin",
485 .codec_name
= "snd-soc-dummy",
486 .codec_dai_name
= "snd-soc-dummy-dai",
487 .platform_name
= "0000:00:1f.3",
491 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
495 [SKL_DPCM_AUDIO_HDMI2_PB
] = {
496 .name
= "Skl HDMI Port2",
497 .stream_name
= "Hdmi2",
498 .cpu_dai_name
= "HDMI2 Pin",
499 .codec_name
= "snd-soc-dummy",
500 .codec_dai_name
= "snd-soc-dummy-dai",
501 .platform_name
= "0000:00:1f.3",
505 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
509 [SKL_DPCM_AUDIO_HDMI3_PB
] = {
510 .name
= "Skl HDMI Port3",
511 .stream_name
= "Hdmi3",
512 .cpu_dai_name
= "HDMI3 Pin",
513 .codec_name
= "snd-soc-dummy",
514 .codec_dai_name
= "snd-soc-dummy-dai",
515 .platform_name
= "0000:00:1f.3",
517 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
524 /* Back End DAI links */
527 .name
= "SSP0-Codec",
529 .cpu_dai_name
= "SSP0 Pin",
530 .platform_name
= "0000:00:1f.3",
532 .codec_name
= "MX98357A:00",
533 .codec_dai_name
= SKL_MAXIM_CODEC_DAI
,
534 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
535 SND_SOC_DAIFMT_NB_NF
|
536 SND_SOC_DAIFMT_CBS_CFS
,
537 .ignore_pmdown_time
= 1,
538 .be_hw_params_fixup
= skylake_ssp_fixup
,
543 .name
= "SSP1-Codec",
545 .cpu_dai_name
= "SSP1 Pin",
546 .platform_name
= "0000:00:1f.3",
548 .codec_name
= "i2c-10508825:00",
549 .codec_dai_name
= SKL_NUVOTON_CODEC_DAI
,
550 .init
= skylake_nau8825_codec_init
,
551 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
552 SND_SOC_DAIFMT_CBS_CFS
,
553 .ignore_pmdown_time
= 1,
554 .be_hw_params_fixup
= skylake_ssp_fixup
,
555 .ops
= &skylake_nau8825_ops
,
562 .cpu_dai_name
= "DMIC01 Pin",
563 .codec_name
= "dmic-codec",
564 .codec_dai_name
= "dmic-hifi",
565 .platform_name
= "0000:00:1f.3",
566 .be_hw_params_fixup
= skylake_dmic_fixup
,
574 .cpu_dai_name
= "iDisp1 Pin",
575 .codec_name
= "ehdaudio0D2",
576 .codec_dai_name
= "intel-hdmi-hifi1",
577 .platform_name
= "0000:00:1f.3",
579 .init
= skylake_hdmi1_init
,
585 .cpu_dai_name
= "iDisp2 Pin",
586 .codec_name
= "ehdaudio0D2",
587 .codec_dai_name
= "intel-hdmi-hifi2",
588 .platform_name
= "0000:00:1f.3",
589 .init
= skylake_hdmi2_init
,
596 .cpu_dai_name
= "iDisp3 Pin",
597 .codec_name
= "ehdaudio0D2",
598 .codec_dai_name
= "intel-hdmi-hifi3",
599 .platform_name
= "0000:00:1f.3",
600 .init
= skylake_hdmi3_init
,
606 static int skylake_card_late_probe(struct snd_soc_card
*card
)
608 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(card
);
609 struct skl_hdmi_pcm
*pcm
;
612 list_for_each_entry(pcm
, &ctx
->hdmi_pcm_list
, head
) {
613 err
= hdac_hdmi_jack_init(pcm
->codec_dai
, pcm
->device
);
621 /* skylake audio machine driver for SPT + NAU88L25 */
622 static struct snd_soc_card skylake_audio_card
= {
623 .name
= "sklnau8825max",
624 .owner
= THIS_MODULE
,
625 .dai_link
= skylake_dais
,
626 .num_links
= ARRAY_SIZE(skylake_dais
),
627 .controls
= skylake_controls
,
628 .num_controls
= ARRAY_SIZE(skylake_controls
),
629 .dapm_widgets
= skylake_widgets
,
630 .num_dapm_widgets
= ARRAY_SIZE(skylake_widgets
),
631 .dapm_routes
= skylake_map
,
632 .num_dapm_routes
= ARRAY_SIZE(skylake_map
),
633 .fully_routed
= true,
634 .late_probe
= skylake_card_late_probe
,
637 static int skylake_audio_probe(struct platform_device
*pdev
)
639 struct skl_nau8825_private
*ctx
;
640 struct skl_machine_pdata
*pdata
;
642 ctx
= devm_kzalloc(&pdev
->dev
, sizeof(*ctx
), GFP_ATOMIC
);
646 INIT_LIST_HEAD(&ctx
->hdmi_pcm_list
);
648 skylake_audio_card
.dev
= &pdev
->dev
;
649 snd_soc_card_set_drvdata(&skylake_audio_card
, ctx
);
651 pdata
= dev_get_drvdata(&pdev
->dev
);
653 dmic_constraints
= pdata
->dmic_num
== 2 ?
654 &constraints_dmic_2ch
: &constraints_dmic_channels
;
656 return devm_snd_soc_register_card(&pdev
->dev
, &skylake_audio_card
);
659 static const struct platform_device_id skl_board_ids
[] = {
660 { .name
= "skl_n88l25_m98357a" },
661 { .name
= "kbl_n88l25_m98357a" },
665 static struct platform_driver skylake_audio
= {
666 .probe
= skylake_audio_probe
,
668 .name
= "skl_n88l25_m98357a",
669 .pm
= &snd_soc_pm_ops
,
671 .id_table
= skl_board_ids
,
674 module_platform_driver(skylake_audio
)
676 /* Module information */
677 MODULE_DESCRIPTION("Audio Machine driver-NAU88L25 & MAX98357A in I2S mode");
678 MODULE_AUTHOR("Rohit Ainapure <rohit.m.ainapure@intel.com");
679 MODULE_LICENSE("GPL v2");
680 MODULE_ALIAS("platform:skl_n88l25_m98357a");
681 MODULE_ALIAS("platform:kbl_n88l25_m98357a");