2 * Intel Skylake I2S Machine Driver
4 * Copyright (C) 2014-2015, Intel Corporation. All rights reserved.
7 * Intel Broadwell Wildcatpoint SST Audio
9 * Copyright (C) 2013, 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/rt286.h"
29 #include "../../codecs/hdac_hdmi.h"
31 static struct snd_soc_jack skylake_headset
;
34 struct list_head head
;
35 struct snd_soc_dai
*codec_dai
;
39 struct skl_rt286_private
{
40 struct list_head hdmi_pcm_list
;
44 SKL_DPCM_AUDIO_PB
= 0,
46 SKL_DPCM_AUDIO_REF_CP
,
47 SKL_DPCM_AUDIO_DMIC_CP
,
48 SKL_DPCM_AUDIO_HDMI1_PB
,
49 SKL_DPCM_AUDIO_HDMI2_PB
,
50 SKL_DPCM_AUDIO_HDMI3_PB
,
53 /* Headset jack detection DAPM pins */
54 static struct snd_soc_jack_pin skylake_headset_pins
[] = {
57 .mask
= SND_JACK_MICROPHONE
,
60 .pin
= "Headphone Jack",
61 .mask
= SND_JACK_HEADPHONE
,
65 static const struct snd_kcontrol_new skylake_controls
[] = {
66 SOC_DAPM_PIN_SWITCH("Speaker"),
67 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
68 SOC_DAPM_PIN_SWITCH("Mic Jack"),
71 static const struct snd_soc_dapm_widget skylake_widgets
[] = {
72 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
73 SND_SOC_DAPM_SPK("Speaker", NULL
),
74 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
75 SND_SOC_DAPM_MIC("DMIC2", NULL
),
76 SND_SOC_DAPM_MIC("SoC DMIC", NULL
),
77 SND_SOC_DAPM_SPK("HDMI1", NULL
),
78 SND_SOC_DAPM_SPK("HDMI2", NULL
),
79 SND_SOC_DAPM_SPK("HDMI3", NULL
),
82 static const struct snd_soc_dapm_route skylake_rt286_map
[] = {
84 {"Speaker", NULL
, "SPOR"},
85 {"Speaker", NULL
, "SPOL"},
87 /* HP jack connectors - unknown if we have jack deteck */
88 {"Headphone Jack", NULL
, "HPO Pin"},
91 {"MIC1", NULL
, "Mic Jack"},
94 {"DMIC1 Pin", NULL
, "DMIC2"},
95 {"DMic", NULL
, "SoC DMIC"},
97 {"HDMI1", NULL
, "hif5 Output"},
98 {"HDMI2", NULL
, "hif6 Output"},
99 {"HDMI3", NULL
, "hif7 Output"},
101 /* CODEC BE connections */
102 { "AIF1 Playback", NULL
, "ssp0 Tx"},
103 { "ssp0 Tx", NULL
, "codec0_out"},
104 { "ssp0 Tx", NULL
, "codec1_out"},
106 { "codec0_in", NULL
, "ssp0 Rx" },
107 { "codec1_in", NULL
, "ssp0 Rx" },
108 { "ssp0 Rx", NULL
, "AIF1 Capture" },
110 { "dmic01_hifi", NULL
, "DMIC01 Rx" },
111 { "DMIC01 Rx", NULL
, "DMIC AIF" },
113 { "hifi3", NULL
, "iDisp3 Tx"},
114 { "iDisp3 Tx", NULL
, "iDisp3_out"},
115 { "hifi2", NULL
, "iDisp2 Tx"},
116 { "iDisp2 Tx", NULL
, "iDisp2_out"},
117 { "hifi1", NULL
, "iDisp1 Tx"},
118 { "iDisp1 Tx", NULL
, "iDisp1_out"},
122 static int skylake_rt286_fe_init(struct snd_soc_pcm_runtime
*rtd
)
124 struct snd_soc_dapm_context
*dapm
;
125 struct snd_soc_component
*component
= rtd
->cpu_dai
->component
;
127 dapm
= snd_soc_component_get_dapm(component
);
128 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
133 static int skylake_rt286_codec_init(struct snd_soc_pcm_runtime
*rtd
)
135 struct snd_soc_codec
*codec
= rtd
->codec
;
138 ret
= snd_soc_card_jack_new(rtd
->card
, "Headset",
139 SND_JACK_HEADSET
| SND_JACK_BTN_0
,
141 skylake_headset_pins
, ARRAY_SIZE(skylake_headset_pins
));
146 rt286_mic_detect(codec
, &skylake_headset
);
148 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
153 static int skylake_hdmi_init(struct snd_soc_pcm_runtime
*rtd
)
155 struct skl_rt286_private
*ctx
= snd_soc_card_get_drvdata(rtd
->card
);
156 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
157 struct skl_hdmi_pcm
*pcm
;
159 pcm
= devm_kzalloc(rtd
->card
->dev
, sizeof(*pcm
), GFP_KERNEL
);
163 pcm
->device
= SKL_DPCM_AUDIO_HDMI1_PB
+ dai
->id
;
164 pcm
->codec_dai
= dai
;
166 list_add_tail(&pcm
->head
, &ctx
->hdmi_pcm_list
);
171 static unsigned int rates
[] = {
175 static struct snd_pcm_hw_constraint_list constraints_rates
= {
176 .count
= ARRAY_SIZE(rates
),
181 static unsigned int channels
[] = {
185 static struct snd_pcm_hw_constraint_list constraints_channels
= {
186 .count
= ARRAY_SIZE(channels
),
191 static int skl_fe_startup(struct snd_pcm_substream
*substream
)
193 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
196 * on this platform for PCM device we support,
202 runtime
->hw
.channels_max
= 2;
203 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
204 &constraints_channels
);
206 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
207 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
209 snd_pcm_hw_constraint_list(runtime
, 0,
210 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
215 static const struct snd_soc_ops skylake_rt286_fe_ops
= {
216 .startup
= skl_fe_startup
,
219 static int skylake_ssp0_fixup(struct snd_soc_pcm_runtime
*rtd
,
220 struct snd_pcm_hw_params
*params
)
222 struct snd_interval
*rate
= hw_param_interval(params
,
223 SNDRV_PCM_HW_PARAM_RATE
);
224 struct snd_interval
*channels
= hw_param_interval(params
,
225 SNDRV_PCM_HW_PARAM_CHANNELS
);
226 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
228 /* The output is 48KHz, stereo, 16bits */
229 rate
->min
= rate
->max
= 48000;
230 channels
->min
= channels
->max
= 2;
232 /* set SSP0 to 24 bit */
234 snd_mask_set(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
238 static int skylake_rt286_hw_params(struct snd_pcm_substream
*substream
,
239 struct snd_pcm_hw_params
*params
)
241 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
242 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
245 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT286_SCLK_S_PLL
, 24000000,
248 dev_err(rtd
->dev
, "set codec sysclk failed: %d\n", ret
);
253 static struct snd_soc_ops skylake_rt286_ops
= {
254 .hw_params
= skylake_rt286_hw_params
,
257 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
258 struct snd_pcm_hw_params
*params
)
260 struct snd_interval
*channels
= hw_param_interval(params
,
261 SNDRV_PCM_HW_PARAM_CHANNELS
);
262 if (params_channels(params
) == 2)
263 channels
->min
= channels
->max
= 2;
265 channels
->min
= channels
->max
= 4;
270 static unsigned int channels_dmic
[] = {
274 static struct snd_pcm_hw_constraint_list constraints_dmic_channels
= {
275 .count
= ARRAY_SIZE(channels_dmic
),
276 .list
= channels_dmic
,
280 static int skylake_dmic_startup(struct snd_pcm_substream
*substream
)
282 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
284 runtime
->hw
.channels_max
= 4;
285 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
286 &constraints_dmic_channels
);
288 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
289 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
292 static struct snd_soc_ops skylake_dmic_ops
= {
293 .startup
= skylake_dmic_startup
,
296 /* skylake digital audio interface glue - connects codec <--> CPU */
297 static struct snd_soc_dai_link skylake_rt286_dais
[] = {
298 /* Front End DAI links */
299 [SKL_DPCM_AUDIO_PB
] = {
300 .name
= "Skl Audio Port",
301 .stream_name
= "Audio",
302 .cpu_dai_name
= "System Pin",
303 .platform_name
= "0000:00:1f.3",
306 .codec_name
= "snd-soc-dummy",
307 .codec_dai_name
= "snd-soc-dummy-dai",
308 .init
= skylake_rt286_fe_init
,
310 SND_SOC_DPCM_TRIGGER_POST
,
311 SND_SOC_DPCM_TRIGGER_POST
314 .ops
= &skylake_rt286_fe_ops
,
316 [SKL_DPCM_AUDIO_CP
] = {
317 .name
= "Skl Audio Capture Port",
318 .stream_name
= "Audio Record",
319 .cpu_dai_name
= "System Pin",
320 .platform_name
= "0000:00:1f.3",
323 .codec_name
= "snd-soc-dummy",
324 .codec_dai_name
= "snd-soc-dummy-dai",
326 SND_SOC_DPCM_TRIGGER_POST
,
327 SND_SOC_DPCM_TRIGGER_POST
330 .ops
= &skylake_rt286_fe_ops
,
332 [SKL_DPCM_AUDIO_REF_CP
] = {
333 .name
= "Skl Audio Reference cap",
334 .stream_name
= "refcap",
335 .cpu_dai_name
= "Reference Pin",
336 .codec_name
= "snd-soc-dummy",
337 .codec_dai_name
= "snd-soc-dummy-dai",
338 .platform_name
= "0000:00:1f.3",
344 [SKL_DPCM_AUDIO_DMIC_CP
] = {
345 .name
= "Skl Audio DMIC cap",
346 .stream_name
= "dmiccap",
347 .cpu_dai_name
= "DMIC Pin",
348 .codec_name
= "snd-soc-dummy",
349 .codec_dai_name
= "snd-soc-dummy-dai",
350 .platform_name
= "0000:00:1f.3",
355 .ops
= &skylake_dmic_ops
,
357 [SKL_DPCM_AUDIO_HDMI1_PB
] = {
358 .name
= "Skl HDMI Port1",
359 .stream_name
= "Hdmi1",
360 .cpu_dai_name
= "HDMI1 Pin",
361 .codec_name
= "snd-soc-dummy",
362 .codec_dai_name
= "snd-soc-dummy-dai",
363 .platform_name
= "0000:00:1f.3",
369 [SKL_DPCM_AUDIO_HDMI2_PB
] = {
370 .name
= "Skl HDMI Port2",
371 .stream_name
= "Hdmi2",
372 .cpu_dai_name
= "HDMI2 Pin",
373 .codec_name
= "snd-soc-dummy",
374 .codec_dai_name
= "snd-soc-dummy-dai",
375 .platform_name
= "0000:00:1f.3",
381 [SKL_DPCM_AUDIO_HDMI3_PB
] = {
382 .name
= "Skl HDMI Port3",
383 .stream_name
= "Hdmi3",
384 .cpu_dai_name
= "HDMI3 Pin",
385 .codec_name
= "snd-soc-dummy",
386 .codec_dai_name
= "snd-soc-dummy-dai",
387 .platform_name
= "0000:00:1f.3",
394 /* Back End DAI links */
397 .name
= "SSP0-Codec",
399 .cpu_dai_name
= "SSP0 Pin",
400 .platform_name
= "0000:00:1f.3",
402 .codec_name
= "i2c-INT343A:00",
403 .codec_dai_name
= "rt286-aif1",
404 .init
= skylake_rt286_codec_init
,
405 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
406 SND_SOC_DAIFMT_NB_NF
|
407 SND_SOC_DAIFMT_CBS_CFS
,
408 .ignore_pmdown_time
= 1,
409 .be_hw_params_fixup
= skylake_ssp0_fixup
,
410 .ops
= &skylake_rt286_ops
,
417 .cpu_dai_name
= "DMIC01 Pin",
418 .codec_name
= "dmic-codec",
419 .codec_dai_name
= "dmic-hifi",
420 .platform_name
= "0000:00:1f.3",
421 .be_hw_params_fixup
= skylake_dmic_fixup
,
429 .cpu_dai_name
= "iDisp1 Pin",
430 .codec_name
= "ehdaudio0D2",
431 .codec_dai_name
= "intel-hdmi-hifi1",
432 .platform_name
= "0000:00:1f.3",
433 .init
= skylake_hdmi_init
,
440 .cpu_dai_name
= "iDisp2 Pin",
441 .codec_name
= "ehdaudio0D2",
442 .codec_dai_name
= "intel-hdmi-hifi2",
443 .platform_name
= "0000:00:1f.3",
444 .init
= skylake_hdmi_init
,
451 .cpu_dai_name
= "iDisp3 Pin",
452 .codec_name
= "ehdaudio0D2",
453 .codec_dai_name
= "intel-hdmi-hifi3",
454 .platform_name
= "0000:00:1f.3",
455 .init
= skylake_hdmi_init
,
461 static int skylake_card_late_probe(struct snd_soc_card
*card
)
463 struct skl_rt286_private
*ctx
= snd_soc_card_get_drvdata(card
);
464 struct skl_hdmi_pcm
*pcm
;
467 list_for_each_entry(pcm
, &ctx
->hdmi_pcm_list
, head
) {
468 err
= hdac_hdmi_jack_init(pcm
->codec_dai
, pcm
->device
);
476 /* skylake audio machine driver for SPT + RT286S */
477 static struct snd_soc_card skylake_rt286
= {
478 .name
= "skylake-rt286",
479 .owner
= THIS_MODULE
,
480 .dai_link
= skylake_rt286_dais
,
481 .num_links
= ARRAY_SIZE(skylake_rt286_dais
),
482 .controls
= skylake_controls
,
483 .num_controls
= ARRAY_SIZE(skylake_controls
),
484 .dapm_widgets
= skylake_widgets
,
485 .num_dapm_widgets
= ARRAY_SIZE(skylake_widgets
),
486 .dapm_routes
= skylake_rt286_map
,
487 .num_dapm_routes
= ARRAY_SIZE(skylake_rt286_map
),
488 .fully_routed
= true,
489 .late_probe
= skylake_card_late_probe
,
492 static int skylake_audio_probe(struct platform_device
*pdev
)
494 struct skl_rt286_private
*ctx
;
496 ctx
= devm_kzalloc(&pdev
->dev
, sizeof(*ctx
), GFP_ATOMIC
);
500 INIT_LIST_HEAD(&ctx
->hdmi_pcm_list
);
502 skylake_rt286
.dev
= &pdev
->dev
;
503 snd_soc_card_set_drvdata(&skylake_rt286
, ctx
);
505 return devm_snd_soc_register_card(&pdev
->dev
, &skylake_rt286
);
508 static struct platform_driver skylake_audio
= {
509 .probe
= skylake_audio_probe
,
511 .name
= "skl_alc286s_i2s",
512 .pm
= &snd_soc_pm_ops
,
516 module_platform_driver(skylake_audio
)
518 /* Module information */
519 MODULE_AUTHOR("Omair Mohammed Abdullah <omair.m.abdullah@intel.com>");
520 MODULE_DESCRIPTION("Intel SST Audio for Skylake");
521 MODULE_LICENSE("GPL v2");
522 MODULE_ALIAS("platform:skl_alc286s_i2s");