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
;
35 static struct snd_soc_jack skylake_hdmi
[3];
38 struct list_head head
;
39 struct snd_soc_dai
*codec_dai
;
43 struct skl_nau8825_private
{
44 struct list_head hdmi_pcm_list
;
48 SKL_DPCM_AUDIO_PB
= 0,
50 SKL_DPCM_AUDIO_REF_CP
,
51 SKL_DPCM_AUDIO_DMIC_CP
,
52 SKL_DPCM_AUDIO_HDMI1_PB
,
53 SKL_DPCM_AUDIO_HDMI2_PB
,
54 SKL_DPCM_AUDIO_HDMI3_PB
,
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
= snd_soc_card_get_codec_dai(card
, SKL_NUVOTON_CODEC_DAI
);
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("DP1", NULL
),
102 SND_SOC_DAPM_SPK("DP2", 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 /* CODEC BE connections */
121 { "HiFi Playback", NULL
, "ssp0 Tx" },
122 { "ssp0 Tx", NULL
, "codec0_out" },
124 { "Playback", NULL
, "ssp1 Tx" },
125 { "ssp1 Tx", NULL
, "codec1_out" },
127 { "codec0_in", NULL
, "ssp1 Rx" },
128 { "ssp1 Rx", NULL
, "Capture" },
131 { "dmic01_hifi", NULL
, "DMIC01 Rx" },
132 { "DMIC01 Rx", NULL
, "DMIC AIF" },
134 { "hifi3", NULL
, "iDisp3 Tx"},
135 { "iDisp3 Tx", NULL
, "iDisp3_out"},
136 { "hifi2", NULL
, "iDisp2 Tx"},
137 { "iDisp2 Tx", NULL
, "iDisp2_out"},
138 { "hifi1", NULL
, "iDisp1 Tx"},
139 { "iDisp1 Tx", NULL
, "iDisp1_out"},
141 { "Headphone Jack", NULL
, "Platform Clock" },
142 { "Headset Mic", NULL
, "Platform Clock" },
145 static int skylake_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
146 struct snd_pcm_hw_params
*params
)
148 struct snd_interval
*rate
= hw_param_interval(params
,
149 SNDRV_PCM_HW_PARAM_RATE
);
150 struct snd_interval
*channels
= hw_param_interval(params
,
151 SNDRV_PCM_HW_PARAM_CHANNELS
);
152 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
154 /* The ADSP will covert the FE rate to 48k, stereo */
155 rate
->min
= rate
->max
= 48000;
156 channels
->min
= channels
->max
= 2;
158 /* set SSP0 to 24 bit */
160 snd_mask_set(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
165 static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime
*rtd
)
168 struct snd_soc_codec
*codec
= rtd
->codec
;
171 * Headset buttons map to the google Reference headset.
172 * These can be configured by userspace.
174 ret
= snd_soc_card_jack_new(&skylake_audio_card
, "Headset Jack",
175 SND_JACK_HEADSET
| SND_JACK_BTN_0
| SND_JACK_BTN_1
|
176 SND_JACK_BTN_2
| SND_JACK_BTN_3
, &skylake_headset
,
179 dev_err(rtd
->dev
, "Headset Jack creation failed %d\n", ret
);
183 nau8825_enable_jack_detect(codec
, &skylake_headset
);
185 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
190 static int skylake_hdmi1_init(struct snd_soc_pcm_runtime
*rtd
)
192 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
193 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
194 struct skl_hdmi_pcm
*pcm
;
196 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
200 pcm
->device
= SKL_DPCM_AUDIO_HDMI1_PB
;
201 pcm
->codec_dai
= dai
;
203 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
208 static int skylake_hdmi2_init(struct snd_soc_pcm_runtime
*rtd
)
210 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
211 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
212 struct skl_hdmi_pcm
*pcm
;
214 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
218 pcm
->device
= SKL_DPCM_AUDIO_HDMI2_PB
;
219 pcm
->codec_dai
= dai
;
221 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
226 static int skylake_hdmi3_init(struct snd_soc_pcm_runtime
*rtd
)
228 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
229 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
230 struct skl_hdmi_pcm
*pcm
;
232 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
236 pcm
->device
= SKL_DPCM_AUDIO_HDMI3_PB
;
237 pcm
->codec_dai
= dai
;
239 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
244 static int skylake_nau8825_fe_init(struct snd_soc_pcm_runtime
*rtd
)
246 struct snd_soc_dapm_context
*dapm
;
247 struct snd_soc_component
*component
= rtd
->cpu_dai
->component
;
249 dapm
= snd_soc_component_get_dapm(component
);
250 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
255 static const unsigned int rates
[] = {
259 static const struct snd_pcm_hw_constraint_list constraints_rates
= {
260 .count
= ARRAY_SIZE(rates
),
265 static const unsigned int channels
[] = {
269 static const struct snd_pcm_hw_constraint_list constraints_channels
= {
270 .count
= ARRAY_SIZE(channels
),
275 static int skl_fe_startup(struct snd_pcm_substream
*substream
)
277 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
280 * On this platform for PCM device we support,
286 runtime
->hw
.channels_max
= 2;
287 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
288 &constraints_channels
);
290 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
291 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
293 snd_pcm_hw_constraint_list(runtime
, 0,
294 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
299 static const struct snd_soc_ops skylake_nau8825_fe_ops
= {
300 .startup
= skl_fe_startup
,
303 static int skylake_nau8825_hw_params(struct snd_pcm_substream
*substream
,
304 struct snd_pcm_hw_params
*params
)
306 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
307 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
310 ret
= snd_soc_dai_set_sysclk(codec_dai
,
311 NAU8825_CLK_MCLK
, 24000000, SND_SOC_CLOCK_IN
);
314 dev_err(rtd
->dev
, "snd_soc_dai_set_sysclk err = %d\n", ret
);
319 static const struct snd_soc_ops skylake_nau8825_ops
= {
320 .hw_params
= skylake_nau8825_hw_params
,
323 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
324 struct snd_pcm_hw_params
*params
)
326 struct snd_interval
*channels
= hw_param_interval(params
,
327 SNDRV_PCM_HW_PARAM_CHANNELS
);
329 if (params_channels(params
) == 2 || DMIC_CH(dmic_constraints
) == 2)
330 channels
->min
= channels
->max
= 2;
332 channels
->min
= channels
->max
= 4;
337 static const unsigned int channels_dmic
[] = {
341 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
342 .count
= ARRAY_SIZE(channels_dmic
),
343 .list
= channels_dmic
,
347 static const unsigned int dmic_2ch
[] = {
351 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch
= {
352 .count
= ARRAY_SIZE(dmic_2ch
),
357 static int skylake_dmic_startup(struct snd_pcm_substream
*substream
)
359 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
361 runtime
->hw
.channels_max
= DMIC_CH(dmic_constraints
);
362 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
365 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
366 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
369 static const struct snd_soc_ops skylake_dmic_ops
= {
370 .startup
= skylake_dmic_startup
,
373 static const unsigned int rates_16000
[] = {
377 static const struct snd_pcm_hw_constraint_list constraints_16000
= {
378 .count
= ARRAY_SIZE(rates_16000
),
382 static const unsigned int ch_mono
[] = {
386 static const struct snd_pcm_hw_constraint_list constraints_refcap
= {
387 .count
= ARRAY_SIZE(ch_mono
),
391 static int skylake_refcap_startup(struct snd_pcm_substream
*substream
)
393 substream
->runtime
->hw
.channels_max
= 1;
394 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
395 SNDRV_PCM_HW_PARAM_CHANNELS
,
396 &constraints_refcap
);
398 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
399 SNDRV_PCM_HW_PARAM_RATE
,
403 static const struct snd_soc_ops skylaye_refcap_ops
= {
404 .startup
= skylake_refcap_startup
,
407 /* skylake digital audio interface glue - connects codec <--> CPU */
408 static struct snd_soc_dai_link skylake_dais
[] = {
409 /* Front End DAI links */
410 [SKL_DPCM_AUDIO_PB
] = {
411 .name
= "Skl Audio Port",
412 .stream_name
= "Audio",
413 .cpu_dai_name
= "System Pin",
414 .platform_name
= "0000:00:1f.3",
416 .codec_name
= "snd-soc-dummy",
417 .codec_dai_name
= "snd-soc-dummy-dai",
419 .init
= skylake_nau8825_fe_init
,
421 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
423 .ops
= &skylake_nau8825_fe_ops
,
425 [SKL_DPCM_AUDIO_CP
] = {
426 .name
= "Skl Audio Capture Port",
427 .stream_name
= "Audio Record",
428 .cpu_dai_name
= "System Pin",
429 .platform_name
= "0000:00:1f.3",
431 .codec_name
= "snd-soc-dummy",
432 .codec_dai_name
= "snd-soc-dummy-dai",
435 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
437 .ops
= &skylake_nau8825_fe_ops
,
439 [SKL_DPCM_AUDIO_REF_CP
] = {
440 .name
= "Skl Audio Reference cap",
441 .stream_name
= "Wake on Voice",
442 .cpu_dai_name
= "Reference Pin",
443 .codec_name
= "snd-soc-dummy",
444 .codec_dai_name
= "snd-soc-dummy-dai",
445 .platform_name
= "0000:00:1f.3",
450 .ops
= &skylaye_refcap_ops
,
452 [SKL_DPCM_AUDIO_DMIC_CP
] = {
453 .name
= "Skl Audio DMIC cap",
454 .stream_name
= "dmiccap",
455 .cpu_dai_name
= "DMIC Pin",
456 .codec_name
= "snd-soc-dummy",
457 .codec_dai_name
= "snd-soc-dummy-dai",
458 .platform_name
= "0000:00:1f.3",
463 .ops
= &skylake_dmic_ops
,
465 [SKL_DPCM_AUDIO_HDMI1_PB
] = {
466 .name
= "Skl HDMI Port1",
467 .stream_name
= "Hdmi1",
468 .cpu_dai_name
= "HDMI1 Pin",
469 .codec_name
= "snd-soc-dummy",
470 .codec_dai_name
= "snd-soc-dummy-dai",
471 .platform_name
= "0000:00:1f.3",
475 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
479 [SKL_DPCM_AUDIO_HDMI2_PB
] = {
480 .name
= "Skl HDMI Port2",
481 .stream_name
= "Hdmi2",
482 .cpu_dai_name
= "HDMI2 Pin",
483 .codec_name
= "snd-soc-dummy",
484 .codec_dai_name
= "snd-soc-dummy-dai",
485 .platform_name
= "0000:00:1f.3",
489 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
493 [SKL_DPCM_AUDIO_HDMI3_PB
] = {
494 .name
= "Skl HDMI Port3",
495 .stream_name
= "Hdmi3",
496 .cpu_dai_name
= "HDMI3 Pin",
497 .codec_name
= "snd-soc-dummy",
498 .codec_dai_name
= "snd-soc-dummy-dai",
499 .platform_name
= "0000:00:1f.3",
501 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
508 /* Back End DAI links */
511 .name
= "SSP0-Codec",
513 .cpu_dai_name
= "SSP0 Pin",
514 .platform_name
= "0000:00:1f.3",
516 .codec_name
= "MX98357A:00",
517 .codec_dai_name
= SKL_MAXIM_CODEC_DAI
,
518 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
519 SND_SOC_DAIFMT_NB_NF
|
520 SND_SOC_DAIFMT_CBS_CFS
,
521 .ignore_pmdown_time
= 1,
522 .be_hw_params_fixup
= skylake_ssp_fixup
,
527 .name
= "SSP1-Codec",
529 .cpu_dai_name
= "SSP1 Pin",
530 .platform_name
= "0000:00:1f.3",
532 .codec_name
= "i2c-10508825:00",
533 .codec_dai_name
= SKL_NUVOTON_CODEC_DAI
,
534 .init
= skylake_nau8825_codec_init
,
535 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
536 SND_SOC_DAIFMT_CBS_CFS
,
537 .ignore_pmdown_time
= 1,
538 .be_hw_params_fixup
= skylake_ssp_fixup
,
539 .ops
= &skylake_nau8825_ops
,
546 .cpu_dai_name
= "DMIC01 Pin",
547 .codec_name
= "dmic-codec",
548 .codec_dai_name
= "dmic-hifi",
549 .platform_name
= "0000:00:1f.3",
550 .be_hw_params_fixup
= skylake_dmic_fixup
,
558 .cpu_dai_name
= "iDisp1 Pin",
559 .codec_name
= "ehdaudio0D2",
560 .codec_dai_name
= "intel-hdmi-hifi1",
561 .platform_name
= "0000:00:1f.3",
563 .init
= skylake_hdmi1_init
,
569 .cpu_dai_name
= "iDisp2 Pin",
570 .codec_name
= "ehdaudio0D2",
571 .codec_dai_name
= "intel-hdmi-hifi2",
572 .platform_name
= "0000:00:1f.3",
573 .init
= skylake_hdmi2_init
,
580 .cpu_dai_name
= "iDisp3 Pin",
581 .codec_name
= "ehdaudio0D2",
582 .codec_dai_name
= "intel-hdmi-hifi3",
583 .platform_name
= "0000:00:1f.3",
584 .init
= skylake_hdmi3_init
,
591 static int skylake_card_late_probe(struct snd_soc_card
*card
)
593 struct skl_nau8825_private
*ctx
= snd_soc_card_get_drvdata(card
);
594 struct skl_hdmi_pcm
*pcm
;
595 struct snd_soc_codec
*codec
= NULL
;
597 char jack_name
[NAME_SIZE
];
599 list_for_each_entry(pcm
, &ctx
->hdmi_pcm_list
, head
) {
600 codec
= pcm
->codec_dai
->codec
;
601 snprintf(jack_name
, sizeof(jack_name
),
602 "HDMI/DP, pcm=%d Jack", pcm
->device
);
603 err
= snd_soc_card_jack_new(card
, jack_name
,
611 err
= hdac_hdmi_jack_init(pcm
->codec_dai
, pcm
->device
,
622 return hdac_hdmi_jack_port_init(codec
, &card
->dapm
);
625 /* skylake audio machine driver for SPT + NAU88L25 */
626 static struct snd_soc_card skylake_audio_card
= {
627 .name
= "sklnau8825max",
628 .owner
= THIS_MODULE
,
629 .dai_link
= skylake_dais
,
630 .num_links
= ARRAY_SIZE(skylake_dais
),
631 .controls
= skylake_controls
,
632 .num_controls
= ARRAY_SIZE(skylake_controls
),
633 .dapm_widgets
= skylake_widgets
,
634 .num_dapm_widgets
= ARRAY_SIZE(skylake_widgets
),
635 .dapm_routes
= skylake_map
,
636 .num_dapm_routes
= ARRAY_SIZE(skylake_map
),
637 .fully_routed
= true,
638 .late_probe
= skylake_card_late_probe
,
641 static int skylake_audio_probe(struct platform_device
*pdev
)
643 struct skl_nau8825_private
*ctx
;
644 struct skl_machine_pdata
*pdata
;
646 ctx
= devm_kzalloc(&pdev
->dev
, sizeof(*ctx
), GFP_ATOMIC
);
650 INIT_LIST_HEAD(&ctx
->hdmi_pcm_list
);
652 skylake_audio_card
.dev
= &pdev
->dev
;
653 snd_soc_card_set_drvdata(&skylake_audio_card
, ctx
);
655 pdata
= dev_get_drvdata(&pdev
->dev
);
657 dmic_constraints
= pdata
->dmic_num
== 2 ?
658 &constraints_dmic_2ch
: &constraints_dmic_channels
;
660 return devm_snd_soc_register_card(&pdev
->dev
, &skylake_audio_card
);
663 static const struct platform_device_id skl_board_ids
[] = {
664 { .name
= "skl_n88l25_m98357a" },
665 { .name
= "kbl_n88l25_m98357a" },
669 static struct platform_driver skylake_audio
= {
670 .probe
= skylake_audio_probe
,
672 .name
= "skl_n88l25_m98357a",
673 .pm
= &snd_soc_pm_ops
,
675 .id_table
= skl_board_ids
,
678 module_platform_driver(skylake_audio
)
680 /* Module information */
681 MODULE_DESCRIPTION("Audio Machine driver-NAU88L25 & MAX98357A in I2S mode");
682 MODULE_AUTHOR("Rohit Ainapure <rohit.m.ainapure@intel.com");
683 MODULE_LICENSE("GPL v2");
684 MODULE_ALIAS("platform:skl_n88l25_m98357a");
685 MODULE_ALIAS("platform:kbl_n88l25_m98357a");