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;
32 static struct snd_soc_jack skylake_hdmi[3];
35 struct list_head head;
36 struct snd_soc_dai *codec_dai;
40 struct skl_rt286_private {
41 struct list_head hdmi_pcm_list;
45 SKL_DPCM_AUDIO_PB = 0,
47 SKL_DPCM_AUDIO_REF_CP,
48 SKL_DPCM_AUDIO_DMIC_CP,
49 SKL_DPCM_AUDIO_HDMI1_PB,
50 SKL_DPCM_AUDIO_HDMI2_PB,
51 SKL_DPCM_AUDIO_HDMI3_PB,
54 /* Headset jack detection DAPM pins */
55 static struct snd_soc_jack_pin skylake_headset_pins[] = {
58 .mask = SND_JACK_MICROPHONE,
61 .pin = "Headphone Jack",
62 .mask = SND_JACK_HEADPHONE,
66 static const struct snd_kcontrol_new skylake_controls[] = {
67 SOC_DAPM_PIN_SWITCH("Speaker"),
68 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
69 SOC_DAPM_PIN_SWITCH("Mic Jack"),
72 static const struct snd_soc_dapm_widget skylake_widgets[] = {
73 SND_SOC_DAPM_HP("Headphone Jack", NULL),
74 SND_SOC_DAPM_SPK("Speaker", NULL),
75 SND_SOC_DAPM_MIC("Mic Jack", NULL),
76 SND_SOC_DAPM_MIC("DMIC2", NULL),
77 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
78 SND_SOC_DAPM_SPK("HDMI1", NULL),
79 SND_SOC_DAPM_SPK("HDMI2", NULL),
80 SND_SOC_DAPM_SPK("HDMI3", NULL),
83 static const struct snd_soc_dapm_route skylake_rt286_map[] = {
85 {"Speaker", NULL, "SPOR"},
86 {"Speaker", NULL, "SPOL"},
88 /* HP jack connectors - unknown if we have jack deteck */
89 {"Headphone Jack", NULL, "HPO Pin"},
92 {"MIC1", NULL, "Mic Jack"},
95 {"DMIC1 Pin", NULL, "DMIC2"},
96 {"DMic", NULL, "SoC DMIC"},
98 /* CODEC BE connections */
99 { "AIF1 Playback", NULL, "ssp0 Tx"},
100 { "ssp0 Tx", NULL, "codec0_out"},
101 { "ssp0 Tx", NULL, "codec1_out"},
103 { "codec0_in", NULL, "ssp0 Rx" },
104 { "codec1_in", NULL, "ssp0 Rx" },
105 { "ssp0 Rx", NULL, "AIF1 Capture" },
107 { "dmic01_hifi", NULL, "DMIC01 Rx" },
108 { "DMIC01 Rx", NULL, "DMIC AIF" },
110 { "hifi3", NULL, "iDisp3 Tx"},
111 { "iDisp3 Tx", NULL, "iDisp3_out"},
112 { "hifi2", NULL, "iDisp2 Tx"},
113 { "iDisp2 Tx", NULL, "iDisp2_out"},
114 { "hifi1", NULL, "iDisp1 Tx"},
115 { "iDisp1 Tx", NULL, "iDisp1_out"},
119 static int skylake_rt286_fe_init(struct snd_soc_pcm_runtime *rtd)
121 struct snd_soc_dapm_context *dapm;
122 struct snd_soc_component *component = rtd->cpu_dai->component;
124 dapm = snd_soc_component_get_dapm(component);
125 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
130 static int skylake_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
132 struct snd_soc_codec *codec = rtd->codec;
135 ret = snd_soc_card_jack_new(rtd->card, "Headset",
136 SND_JACK_HEADSET | SND_JACK_BTN_0,
138 skylake_headset_pins, ARRAY_SIZE(skylake_headset_pins));
143 rt286_mic_detect(codec, &skylake_headset);
145 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
150 static int skylake_hdmi_init(struct snd_soc_pcm_runtime *rtd)
152 struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(rtd->card);
153 struct snd_soc_dai *dai = rtd->codec_dai;
154 struct skl_hdmi_pcm *pcm;
156 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
160 pcm->device = SKL_DPCM_AUDIO_HDMI1_PB + dai->id;
161 pcm->codec_dai = dai;
163 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
168 static unsigned int rates[] = {
172 static struct snd_pcm_hw_constraint_list constraints_rates = {
173 .count = ARRAY_SIZE(rates),
178 static unsigned int channels[] = {
182 static struct snd_pcm_hw_constraint_list constraints_channels = {
183 .count = ARRAY_SIZE(channels),
188 static int skl_fe_startup(struct snd_pcm_substream *substream)
190 struct snd_pcm_runtime *runtime = substream->runtime;
193 * on this platform for PCM device we support,
199 runtime->hw.channels_max = 2;
200 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
201 &constraints_channels);
203 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
204 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
206 snd_pcm_hw_constraint_list(runtime, 0,
207 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
212 static const struct snd_soc_ops skylake_rt286_fe_ops = {
213 .startup = skl_fe_startup,
216 static int skylake_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
217 struct snd_pcm_hw_params *params)
219 struct snd_interval *rate = hw_param_interval(params,
220 SNDRV_PCM_HW_PARAM_RATE);
221 struct snd_interval *channels = hw_param_interval(params,
222 SNDRV_PCM_HW_PARAM_CHANNELS);
223 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
225 /* The output is 48KHz, stereo, 16bits */
226 rate->min = rate->max = 48000;
227 channels->min = channels->max = 2;
229 /* set SSP0 to 24 bit */
231 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
235 static int skylake_rt286_hw_params(struct snd_pcm_substream *substream,
236 struct snd_pcm_hw_params *params)
238 struct snd_soc_pcm_runtime *rtd = substream->private_data;
239 struct snd_soc_dai *codec_dai = rtd->codec_dai;
242 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
245 dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret);
250 static const struct snd_soc_ops skylake_rt286_ops = {
251 .hw_params = skylake_rt286_hw_params,
254 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
255 struct snd_pcm_hw_params *params)
257 struct snd_interval *channels = hw_param_interval(params,
258 SNDRV_PCM_HW_PARAM_CHANNELS);
259 if (params_channels(params) == 2)
260 channels->min = channels->max = 2;
262 channels->min = channels->max = 4;
267 static unsigned int channels_dmic[] = {
271 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
272 .count = ARRAY_SIZE(channels_dmic),
273 .list = channels_dmic,
277 static int skylake_dmic_startup(struct snd_pcm_substream *substream)
279 struct snd_pcm_runtime *runtime = substream->runtime;
281 runtime->hw.channels_max = 4;
282 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
283 &constraints_dmic_channels);
285 return snd_pcm_hw_constraint_list(substream->runtime, 0,
286 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
289 static const struct snd_soc_ops skylake_dmic_ops = {
290 .startup = skylake_dmic_startup,
293 /* skylake digital audio interface glue - connects codec <--> CPU */
294 static struct snd_soc_dai_link skylake_rt286_dais[] = {
295 /* Front End DAI links */
296 [SKL_DPCM_AUDIO_PB] = {
297 .name = "Skl Audio Port",
298 .stream_name = "Audio",
299 .cpu_dai_name = "System Pin",
300 .platform_name = "0000:00:1f.3",
303 .codec_name = "snd-soc-dummy",
304 .codec_dai_name = "snd-soc-dummy-dai",
305 .init = skylake_rt286_fe_init,
307 SND_SOC_DPCM_TRIGGER_POST,
308 SND_SOC_DPCM_TRIGGER_POST
311 .ops = &skylake_rt286_fe_ops,
313 [SKL_DPCM_AUDIO_CP] = {
314 .name = "Skl Audio Capture Port",
315 .stream_name = "Audio Record",
316 .cpu_dai_name = "System Pin",
317 .platform_name = "0000:00:1f.3",
320 .codec_name = "snd-soc-dummy",
321 .codec_dai_name = "snd-soc-dummy-dai",
323 SND_SOC_DPCM_TRIGGER_POST,
324 SND_SOC_DPCM_TRIGGER_POST
327 .ops = &skylake_rt286_fe_ops,
329 [SKL_DPCM_AUDIO_REF_CP] = {
330 .name = "Skl Audio Reference cap",
331 .stream_name = "refcap",
332 .cpu_dai_name = "Reference Pin",
333 .codec_name = "snd-soc-dummy",
334 .codec_dai_name = "snd-soc-dummy-dai",
335 .platform_name = "0000:00:1f.3",
341 [SKL_DPCM_AUDIO_DMIC_CP] = {
342 .name = "Skl Audio DMIC cap",
343 .stream_name = "dmiccap",
344 .cpu_dai_name = "DMIC Pin",
345 .codec_name = "snd-soc-dummy",
346 .codec_dai_name = "snd-soc-dummy-dai",
347 .platform_name = "0000:00:1f.3",
352 .ops = &skylake_dmic_ops,
354 [SKL_DPCM_AUDIO_HDMI1_PB] = {
355 .name = "Skl HDMI Port1",
356 .stream_name = "Hdmi1",
357 .cpu_dai_name = "HDMI1 Pin",
358 .codec_name = "snd-soc-dummy",
359 .codec_dai_name = "snd-soc-dummy-dai",
360 .platform_name = "0000:00:1f.3",
366 [SKL_DPCM_AUDIO_HDMI2_PB] = {
367 .name = "Skl HDMI Port2",
368 .stream_name = "Hdmi2",
369 .cpu_dai_name = "HDMI2 Pin",
370 .codec_name = "snd-soc-dummy",
371 .codec_dai_name = "snd-soc-dummy-dai",
372 .platform_name = "0000:00:1f.3",
378 [SKL_DPCM_AUDIO_HDMI3_PB] = {
379 .name = "Skl HDMI Port3",
380 .stream_name = "Hdmi3",
381 .cpu_dai_name = "HDMI3 Pin",
382 .codec_name = "snd-soc-dummy",
383 .codec_dai_name = "snd-soc-dummy-dai",
384 .platform_name = "0000:00:1f.3",
391 /* Back End DAI links */
394 .name = "SSP0-Codec",
396 .cpu_dai_name = "SSP0 Pin",
397 .platform_name = "0000:00:1f.3",
399 .codec_name = "i2c-INT343A:00",
400 .codec_dai_name = "rt286-aif1",
401 .init = skylake_rt286_codec_init,
402 .dai_fmt = SND_SOC_DAIFMT_I2S |
403 SND_SOC_DAIFMT_NB_NF |
404 SND_SOC_DAIFMT_CBS_CFS,
405 .ignore_pmdown_time = 1,
406 .be_hw_params_fixup = skylake_ssp0_fixup,
407 .ops = &skylake_rt286_ops,
414 .cpu_dai_name = "DMIC01 Pin",
415 .codec_name = "dmic-codec",
416 .codec_dai_name = "dmic-hifi",
417 .platform_name = "0000:00:1f.3",
418 .be_hw_params_fixup = skylake_dmic_fixup,
426 .cpu_dai_name = "iDisp1 Pin",
427 .codec_name = "ehdaudio0D2",
428 .codec_dai_name = "intel-hdmi-hifi1",
429 .platform_name = "0000:00:1f.3",
430 .init = skylake_hdmi_init,
437 .cpu_dai_name = "iDisp2 Pin",
438 .codec_name = "ehdaudio0D2",
439 .codec_dai_name = "intel-hdmi-hifi2",
440 .platform_name = "0000:00:1f.3",
441 .init = skylake_hdmi_init,
448 .cpu_dai_name = "iDisp3 Pin",
449 .codec_name = "ehdaudio0D2",
450 .codec_dai_name = "intel-hdmi-hifi3",
451 .platform_name = "0000:00:1f.3",
452 .init = skylake_hdmi_init,
459 static int skylake_card_late_probe(struct snd_soc_card *card)
461 struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(card);
462 struct skl_hdmi_pcm *pcm;
463 struct snd_soc_codec *codec = NULL;
465 char jack_name[NAME_SIZE];
467 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
468 codec = pcm->codec_dai->codec;
469 snprintf(jack_name, sizeof(jack_name),
470 "HDMI/DP, pcm=%d Jack", pcm->device);
471 err = snd_soc_card_jack_new(card, jack_name,
472 SND_JACK_AVOUT, &skylake_hdmi[i],
478 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
489 return hdac_hdmi_jack_port_init(codec, &card->dapm);
492 /* skylake audio machine driver for SPT + RT286S */
493 static struct snd_soc_card skylake_rt286 = {
494 .name = "skylake-rt286",
495 .owner = THIS_MODULE,
496 .dai_link = skylake_rt286_dais,
497 .num_links = ARRAY_SIZE(skylake_rt286_dais),
498 .controls = skylake_controls,
499 .num_controls = ARRAY_SIZE(skylake_controls),
500 .dapm_widgets = skylake_widgets,
501 .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
502 .dapm_routes = skylake_rt286_map,
503 .num_dapm_routes = ARRAY_SIZE(skylake_rt286_map),
504 .fully_routed = true,
505 .late_probe = skylake_card_late_probe,
508 static int skylake_audio_probe(struct platform_device *pdev)
510 struct skl_rt286_private *ctx;
512 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
516 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
518 skylake_rt286.dev = &pdev->dev;
519 snd_soc_card_set_drvdata(&skylake_rt286, ctx);
521 return devm_snd_soc_register_card(&pdev->dev, &skylake_rt286);
524 static const struct platform_device_id skl_board_ids[] = {
525 { .name = "skl_alc286s_i2s" },
526 { .name = "kbl_alc286s_i2s" },
530 static struct platform_driver skylake_audio = {
531 .probe = skylake_audio_probe,
533 .name = "skl_alc286s_i2s",
534 .pm = &snd_soc_pm_ops,
536 .id_table = skl_board_ids,
540 module_platform_driver(skylake_audio)
542 /* Module information */
543 MODULE_AUTHOR("Omair Mohammed Abdullah <omair.m.abdullah@intel.com>");
544 MODULE_DESCRIPTION("Intel SST Audio for Skylake");
545 MODULE_LICENSE("GPL v2");
546 MODULE_ALIAS("platform:skl_alc286s_i2s");
547 MODULE_ALIAS("platform:kbl_alc286s_i2s");