1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Skylake I2S Machine Driver
5 * Copyright (C) 2014-2015, Intel Corporation. All rights reserved.
8 * Intel Broadwell Wildcatpoint SST Audio
10 * Copyright (C) 2013, Intel Corporation. All rights reserved.
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <sound/core.h>
16 #include <sound/pcm.h>
17 #include <sound/soc.h>
18 #include <sound/jack.h>
19 #include <sound/pcm_params.h>
20 #include "../../codecs/rt286.h"
21 #include "../../codecs/hdac_hdmi.h"
23 static struct snd_soc_jack skylake_headset
;
24 static struct snd_soc_jack skylake_hdmi
[3];
27 struct list_head head
;
28 struct snd_soc_dai
*codec_dai
;
32 struct skl_rt286_private
{
33 struct list_head hdmi_pcm_list
;
37 SKL_DPCM_AUDIO_PB
= 0,
40 SKL_DPCM_AUDIO_REF_CP
,
41 SKL_DPCM_AUDIO_DMIC_CP
,
42 SKL_DPCM_AUDIO_HDMI1_PB
,
43 SKL_DPCM_AUDIO_HDMI2_PB
,
44 SKL_DPCM_AUDIO_HDMI3_PB
,
47 /* Headset jack detection DAPM pins */
48 static struct snd_soc_jack_pin skylake_headset_pins
[] = {
51 .mask
= SND_JACK_MICROPHONE
,
54 .pin
= "Headphone Jack",
55 .mask
= SND_JACK_HEADPHONE
,
59 static const struct snd_kcontrol_new skylake_controls
[] = {
60 SOC_DAPM_PIN_SWITCH("Speaker"),
61 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
62 SOC_DAPM_PIN_SWITCH("Mic Jack"),
65 static const struct snd_soc_dapm_widget skylake_widgets
[] = {
66 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
67 SND_SOC_DAPM_SPK("Speaker", NULL
),
68 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
69 SND_SOC_DAPM_MIC("DMIC2", NULL
),
70 SND_SOC_DAPM_MIC("SoC DMIC", NULL
),
71 SND_SOC_DAPM_SPK("HDMI1", NULL
),
72 SND_SOC_DAPM_SPK("HDMI2", NULL
),
73 SND_SOC_DAPM_SPK("HDMI3", NULL
),
76 static const struct snd_soc_dapm_route skylake_rt286_map
[] = {
78 {"Speaker", NULL
, "SPOR"},
79 {"Speaker", NULL
, "SPOL"},
81 /* HP jack connectors - unknown if we have jack deteck */
82 {"Headphone Jack", NULL
, "HPO Pin"},
85 {"MIC1", NULL
, "Mic Jack"},
88 {"DMIC1 Pin", NULL
, "DMIC2"},
89 {"DMic", NULL
, "SoC DMIC"},
91 /* CODEC BE connections */
92 { "AIF1 Playback", NULL
, "ssp0 Tx"},
93 { "ssp0 Tx", NULL
, "codec0_out"},
94 { "ssp0 Tx", NULL
, "codec1_out"},
96 { "codec0_in", NULL
, "ssp0 Rx" },
97 { "codec1_in", NULL
, "ssp0 Rx" },
98 { "ssp0 Rx", NULL
, "AIF1 Capture" },
100 { "dmic01_hifi", NULL
, "DMIC01 Rx" },
101 { "DMIC01 Rx", NULL
, "DMIC AIF" },
103 { "hifi3", NULL
, "iDisp3 Tx"},
104 { "iDisp3 Tx", NULL
, "iDisp3_out"},
105 { "hifi2", NULL
, "iDisp2 Tx"},
106 { "iDisp2 Tx", NULL
, "iDisp2_out"},
107 { "hifi1", NULL
, "iDisp1 Tx"},
108 { "iDisp1 Tx", NULL
, "iDisp1_out"},
112 static int skylake_rt286_fe_init(struct snd_soc_pcm_runtime
*rtd
)
114 struct snd_soc_dapm_context
*dapm
;
115 struct snd_soc_component
*component
= asoc_rtd_to_cpu(rtd
, 0)->component
;
117 dapm
= snd_soc_component_get_dapm(component
);
118 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
123 static int skylake_rt286_codec_init(struct snd_soc_pcm_runtime
*rtd
)
125 struct snd_soc_component
*component
= asoc_rtd_to_codec(rtd
, 0)->component
;
128 ret
= snd_soc_card_jack_new(rtd
->card
, "Headset",
129 SND_JACK_HEADSET
| SND_JACK_BTN_0
,
131 skylake_headset_pins
, ARRAY_SIZE(skylake_headset_pins
));
136 rt286_mic_detect(component
, &skylake_headset
);
138 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
143 static int skylake_hdmi_init(struct snd_soc_pcm_runtime
*rtd
)
145 struct skl_rt286_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
146 struct snd_soc_dai
*dai
= asoc_rtd_to_codec(rtd
, 0);
147 struct skl_hdmi_pcm
*pcm
;
149 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
153 pcm
->device
= SKL_DPCM_AUDIO_HDMI1_PB
+ dai
->id
;
154 pcm
->codec_dai
= dai
;
156 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
161 static const unsigned int rates
[] = {
165 static const struct snd_pcm_hw_constraint_list constraints_rates
= {
166 .count
= ARRAY_SIZE(rates
),
171 static const unsigned int channels
[] = {
175 static const struct snd_pcm_hw_constraint_list constraints_channels
= {
176 .count
= ARRAY_SIZE(channels
),
181 static int skl_fe_startup(struct snd_pcm_substream
*substream
)
183 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
186 * on this platform for PCM device we support,
192 runtime
->hw
.channels_max
= 2;
193 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
194 &constraints_channels
);
196 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
197 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
199 snd_pcm_hw_constraint_list(runtime
, 0,
200 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
205 static const struct snd_soc_ops skylake_rt286_fe_ops
= {
206 .startup
= skl_fe_startup
,
209 static int skylake_ssp0_fixup(struct snd_soc_pcm_runtime
*rtd
,
210 struct snd_pcm_hw_params
*params
)
212 struct snd_interval
*rate
= hw_param_interval(params
,
213 SNDRV_PCM_HW_PARAM_RATE
);
214 struct snd_interval
*chan
= hw_param_interval(params
,
215 SNDRV_PCM_HW_PARAM_CHANNELS
);
216 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
218 /* The output is 48KHz, stereo, 16bits */
219 rate
->min
= rate
->max
= 48000;
220 chan
->min
= chan
->max
= 2;
222 /* set SSP0 to 24 bit */
224 snd_mask_set_format(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
228 static int skylake_rt286_hw_params(struct snd_pcm_substream
*substream
,
229 struct snd_pcm_hw_params
*params
)
231 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
232 struct snd_soc_dai
*codec_dai
= asoc_rtd_to_codec(rtd
, 0);
235 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT286_SCLK_S_PLL
, 24000000,
238 dev_err(rtd
->dev
, "set codec sysclk failed: %d\n", ret
);
243 static const struct snd_soc_ops skylake_rt286_ops
= {
244 .hw_params
= skylake_rt286_hw_params
,
247 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
248 struct snd_pcm_hw_params
*params
)
250 struct snd_interval
*chan
= hw_param_interval(params
,
251 SNDRV_PCM_HW_PARAM_CHANNELS
);
252 if (params_channels(params
) == 2)
253 chan
->min
= chan
->max
= 2;
255 chan
->min
= chan
->max
= 4;
260 static const unsigned int channels_dmic
[] = {
264 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
265 .count
= ARRAY_SIZE(channels_dmic
),
266 .list
= channels_dmic
,
270 static int skylake_dmic_startup(struct snd_pcm_substream
*substream
)
272 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
274 runtime
->hw
.channels_max
= 4;
275 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
276 &constraints_dmic_channels
);
278 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
279 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
282 static const struct snd_soc_ops skylake_dmic_ops
= {
283 .startup
= skylake_dmic_startup
,
286 SND_SOC_DAILINK_DEF(dummy
,
287 DAILINK_COMP_ARRAY(COMP_DUMMY()));
289 SND_SOC_DAILINK_DEF(system
,
290 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
292 SND_SOC_DAILINK_DEF(deepbuffer
,
293 DAILINK_COMP_ARRAY(COMP_CPU("Deepbuffer Pin")));
295 SND_SOC_DAILINK_DEF(reference
,
296 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
298 SND_SOC_DAILINK_DEF(dmic
,
299 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
301 SND_SOC_DAILINK_DEF(hdmi1
,
302 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
304 SND_SOC_DAILINK_DEF(hdmi2
,
305 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
307 SND_SOC_DAILINK_DEF(hdmi3
,
308 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
310 SND_SOC_DAILINK_DEF(ssp0_pin
,
311 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
312 SND_SOC_DAILINK_DEF(ssp0_codec
,
313 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00", "rt286-aif1")));
315 SND_SOC_DAILINK_DEF(dmic01_pin
,
316 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
317 SND_SOC_DAILINK_DEF(dmic_codec
,
318 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
320 SND_SOC_DAILINK_DEF(idisp1_pin
,
321 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
322 SND_SOC_DAILINK_DEF(idisp1_codec
,
323 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
325 SND_SOC_DAILINK_DEF(idisp2_pin
,
326 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
327 SND_SOC_DAILINK_DEF(idisp2_codec
,
328 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
330 SND_SOC_DAILINK_DEF(idisp3_pin
,
331 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
332 SND_SOC_DAILINK_DEF(idisp3_codec
,
333 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
335 SND_SOC_DAILINK_DEF(platform
,
336 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
338 /* skylake digital audio interface glue - connects codec <--> CPU */
339 static struct snd_soc_dai_link skylake_rt286_dais
[] = {
340 /* Front End DAI links */
341 [SKL_DPCM_AUDIO_PB
] = {
342 .name
= "Skl Audio Port",
343 .stream_name
= "Audio",
346 .init
= skylake_rt286_fe_init
,
348 SND_SOC_DPCM_TRIGGER_POST
,
349 SND_SOC_DPCM_TRIGGER_POST
352 .ops
= &skylake_rt286_fe_ops
,
353 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
355 [SKL_DPCM_AUDIO_DB_PB
] = {
356 .name
= "Skl Deepbuffer Port",
357 .stream_name
= "Deep Buffer Audio",
361 SND_SOC_DPCM_TRIGGER_POST
,
362 SND_SOC_DPCM_TRIGGER_POST
365 .ops
= &skylake_rt286_fe_ops
,
366 SND_SOC_DAILINK_REG(deepbuffer
, dummy
, platform
),
368 [SKL_DPCM_AUDIO_CP
] = {
369 .name
= "Skl Audio Capture Port",
370 .stream_name
= "Audio Record",
374 SND_SOC_DPCM_TRIGGER_POST
,
375 SND_SOC_DPCM_TRIGGER_POST
378 .ops
= &skylake_rt286_fe_ops
,
379 SND_SOC_DAILINK_REG(system
, dummy
, platform
),
381 [SKL_DPCM_AUDIO_REF_CP
] = {
382 .name
= "Skl Audio Reference cap",
383 .stream_name
= "refcap",
388 SND_SOC_DAILINK_REG(reference
, dummy
, platform
),
390 [SKL_DPCM_AUDIO_DMIC_CP
] = {
391 .name
= "Skl Audio DMIC cap",
392 .stream_name
= "dmiccap",
397 .ops
= &skylake_dmic_ops
,
398 SND_SOC_DAILINK_REG(dmic
, dummy
, platform
),
400 [SKL_DPCM_AUDIO_HDMI1_PB
] = {
401 .name
= "Skl HDMI Port1",
402 .stream_name
= "Hdmi1",
407 SND_SOC_DAILINK_REG(hdmi1
, dummy
, platform
),
409 [SKL_DPCM_AUDIO_HDMI2_PB
] = {
410 .name
= "Skl HDMI Port2",
411 .stream_name
= "Hdmi2",
416 SND_SOC_DAILINK_REG(hdmi2
, dummy
, platform
),
418 [SKL_DPCM_AUDIO_HDMI3_PB
] = {
419 .name
= "Skl HDMI Port3",
420 .stream_name
= "Hdmi3",
425 SND_SOC_DAILINK_REG(hdmi3
, dummy
, platform
),
428 /* Back End DAI links */
431 .name
= "SSP0-Codec",
434 .init
= skylake_rt286_codec_init
,
435 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
436 SND_SOC_DAIFMT_NB_NF
|
437 SND_SOC_DAIFMT_CBS_CFS
,
438 .ignore_pmdown_time
= 1,
439 .be_hw_params_fixup
= skylake_ssp0_fixup
,
440 .ops
= &skylake_rt286_ops
,
443 SND_SOC_DAILINK_REG(ssp0_pin
, ssp0_codec
, platform
),
448 .be_hw_params_fixup
= skylake_dmic_fixup
,
452 SND_SOC_DAILINK_REG(dmic01_pin
, dmic_codec
, platform
),
457 .init
= skylake_hdmi_init
,
460 SND_SOC_DAILINK_REG(idisp1_pin
, idisp1_codec
, platform
),
465 .init
= skylake_hdmi_init
,
468 SND_SOC_DAILINK_REG(idisp2_pin
, idisp2_codec
, platform
),
473 .init
= skylake_hdmi_init
,
476 SND_SOC_DAILINK_REG(idisp3_pin
, idisp3_codec
, platform
),
481 static int skylake_card_late_probe(struct snd_soc_card
*card
)
483 struct skl_rt286_private
*ctx
= snd_soc_card_get_drvdata(card
);
484 struct skl_hdmi_pcm
*pcm
;
485 struct snd_soc_component
*component
= NULL
;
487 char jack_name
[NAME_SIZE
];
489 list_for_each_entry(pcm
, &ctx
->hdmi_pcm_list
, head
) {
490 component
= pcm
->codec_dai
->component
;
491 snprintf(jack_name
, sizeof(jack_name
),
492 "HDMI/DP, pcm=%d Jack", pcm
->device
);
493 err
= snd_soc_card_jack_new(card
, jack_name
,
494 SND_JACK_AVOUT
, &skylake_hdmi
[i
],
500 err
= hdac_hdmi_jack_init(pcm
->codec_dai
, pcm
->device
,
511 return hdac_hdmi_jack_port_init(component
, &card
->dapm
);
514 /* skylake audio machine driver for SPT + RT286S */
515 static struct snd_soc_card skylake_rt286
= {
516 .name
= "skylake-rt286",
517 .owner
= THIS_MODULE
,
518 .dai_link
= skylake_rt286_dais
,
519 .num_links
= ARRAY_SIZE(skylake_rt286_dais
),
520 .controls
= skylake_controls
,
521 .num_controls
= ARRAY_SIZE(skylake_controls
),
522 .dapm_widgets
= skylake_widgets
,
523 .num_dapm_widgets
= ARRAY_SIZE(skylake_widgets
),
524 .dapm_routes
= skylake_rt286_map
,
525 .num_dapm_routes
= ARRAY_SIZE(skylake_rt286_map
),
526 .fully_routed
= true,
527 .late_probe
= skylake_card_late_probe
,
530 static int skylake_audio_probe(struct platform_device
*pdev
)
532 struct skl_rt286_private
*ctx
;
534 ctx
= devm_kzalloc(&pdev
->dev
, sizeof(*ctx
), GFP_KERNEL
);
538 INIT_LIST_HEAD(&ctx
->hdmi_pcm_list
);
540 skylake_rt286
.dev
= &pdev
->dev
;
541 snd_soc_card_set_drvdata(&skylake_rt286
, ctx
);
543 return devm_snd_soc_register_card(&pdev
->dev
, &skylake_rt286
);
546 static const struct platform_device_id skl_board_ids
[] = {
547 { .name
= "skl_alc286s_i2s" },
548 { .name
= "kbl_alc286s_i2s" },
552 static struct platform_driver skylake_audio
= {
553 .probe
= skylake_audio_probe
,
555 .name
= "skl_alc286s_i2s",
556 .pm
= &snd_soc_pm_ops
,
558 .id_table
= skl_board_ids
,
562 module_platform_driver(skylake_audio
)
564 /* Module information */
565 MODULE_AUTHOR("Omair Mohammed Abdullah <omair.m.abdullah@intel.com>");
566 MODULE_DESCRIPTION("Intel SST Audio for Skylake");
567 MODULE_LICENSE("GPL v2");
568 MODULE_ALIAS("platform:skl_alc286s_i2s");
569 MODULE_ALIAS("platform:kbl_alc286s_i2s");