2 * Intel Broxton-P I2S Machine Driver
4 * Copyright (C) 2014-2016, Intel Corporation. All rights reserved.
7 * Intel Skylake I2S Machine driver
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/soc.h>
24 #include <sound/jack.h>
25 #include <sound/pcm_params.h>
26 #include "../../codecs/hdac_hdmi.h"
27 #include "../../codecs/rt298.h"
29 /* Headset jack detection DAPM pins */
30 static struct snd_soc_jack broxton_headset;
31 static struct snd_soc_jack broxton_hdmi[3];
34 struct list_head head;
35 struct snd_soc_dai *codec_dai;
39 struct bxt_rt286_private {
40 struct list_head hdmi_pcm_list;
44 BXT_DPCM_AUDIO_PB = 0,
46 BXT_DPCM_AUDIO_REF_CP,
47 BXT_DPCM_AUDIO_DMIC_CP,
48 BXT_DPCM_AUDIO_HDMI1_PB,
49 BXT_DPCM_AUDIO_HDMI2_PB,
50 BXT_DPCM_AUDIO_HDMI3_PB,
53 static struct snd_soc_jack_pin broxton_headset_pins[] = {
56 .mask = SND_JACK_MICROPHONE,
59 .pin = "Headphone Jack",
60 .mask = SND_JACK_HEADPHONE,
64 static const struct snd_kcontrol_new broxton_controls[] = {
65 SOC_DAPM_PIN_SWITCH("Speaker"),
66 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
67 SOC_DAPM_PIN_SWITCH("Mic Jack"),
70 static const struct snd_soc_dapm_widget broxton_widgets[] = {
71 SND_SOC_DAPM_HP("Headphone Jack", NULL),
72 SND_SOC_DAPM_SPK("Speaker", NULL),
73 SND_SOC_DAPM_MIC("Mic Jack", NULL),
74 SND_SOC_DAPM_MIC("DMIC2", NULL),
75 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
76 SND_SOC_DAPM_SPK("HDMI1", NULL),
77 SND_SOC_DAPM_SPK("HDMI2", NULL),
78 SND_SOC_DAPM_SPK("HDMI3", NULL),
81 static const struct snd_soc_dapm_route broxton_rt298_map[] = {
83 {"Speaker", NULL, "SPOR"},
84 {"Speaker", NULL, "SPOL"},
86 /* HP jack connectors - unknown if we have jack detect */
87 {"Headphone Jack", NULL, "HPO Pin"},
90 {"MIC1", NULL, "Mic Jack"},
93 {"DMIC1 Pin", NULL, "DMIC2"},
94 {"DMic", NULL, "SoC DMIC"},
96 {"HDMI1", NULL, "hif5-0 Output"},
97 {"HDMI2", NULL, "hif6-0 Output"},
98 {"HDMI2", NULL, "hif7-0 Output"},
100 /* CODEC BE connections */
101 { "AIF1 Playback", NULL, "ssp5 Tx"},
102 { "ssp5 Tx", NULL, "codec0_out"},
103 { "ssp5 Tx", NULL, "codec1_out"},
105 { "codec0_in", NULL, "ssp5 Rx" },
106 { "ssp5 Rx", NULL, "AIF1 Capture" },
108 { "dmic01_hifi", NULL, "DMIC01 Rx" },
109 { "DMIC01 Rx", NULL, "Capture" },
111 { "hifi3", NULL, "iDisp3 Tx"},
112 { "iDisp3 Tx", NULL, "iDisp3_out"},
113 { "hifi2", NULL, "iDisp2 Tx"},
114 { "iDisp2 Tx", NULL, "iDisp2_out"},
115 { "hifi1", NULL, "iDisp1 Tx"},
116 { "iDisp1 Tx", NULL, "iDisp1_out"},
120 static int broxton_rt298_fe_init(struct snd_soc_pcm_runtime *rtd)
122 struct snd_soc_dapm_context *dapm;
123 struct snd_soc_component *component = rtd->cpu_dai->component;
125 dapm = snd_soc_component_get_dapm(component);
126 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
131 static int broxton_rt298_codec_init(struct snd_soc_pcm_runtime *rtd)
133 struct snd_soc_codec *codec = rtd->codec;
136 ret = snd_soc_card_jack_new(rtd->card, "Headset",
137 SND_JACK_HEADSET | SND_JACK_BTN_0,
139 broxton_headset_pins, ARRAY_SIZE(broxton_headset_pins));
144 rt298_mic_detect(codec, &broxton_headset);
146 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
151 static int broxton_hdmi_init(struct snd_soc_pcm_runtime *rtd)
153 struct bxt_rt286_private *ctx = snd_soc_card_get_drvdata(rtd->card);
154 struct snd_soc_dai *dai = rtd->codec_dai;
155 struct bxt_hdmi_pcm *pcm;
157 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
161 pcm->device = BXT_DPCM_AUDIO_HDMI1_PB + dai->id;
162 pcm->codec_dai = dai;
164 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
169 static int broxton_ssp5_fixup(struct snd_soc_pcm_runtime *rtd,
170 struct snd_pcm_hw_params *params)
172 struct snd_interval *rate = hw_param_interval(params,
173 SNDRV_PCM_HW_PARAM_RATE);
174 struct snd_interval *channels = hw_param_interval(params,
175 SNDRV_PCM_HW_PARAM_CHANNELS);
176 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
178 /* The ADSP will covert the FE rate to 48k, stereo */
179 rate->min = rate->max = 48000;
180 channels->min = channels->max = 2;
182 /* set SSP5 to 24 bit */
184 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
189 static int broxton_rt298_hw_params(struct snd_pcm_substream *substream,
190 struct snd_pcm_hw_params *params)
192 struct snd_soc_pcm_runtime *rtd = substream->private_data;
193 struct snd_soc_dai *codec_dai = rtd->codec_dai;
196 ret = snd_soc_dai_set_sysclk(codec_dai, RT298_SCLK_S_PLL,
197 19200000, SND_SOC_CLOCK_IN);
199 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
206 static const struct snd_soc_ops broxton_rt298_ops = {
207 .hw_params = broxton_rt298_hw_params,
210 static unsigned int rates[] = {
214 static struct snd_pcm_hw_constraint_list constraints_rates = {
215 .count = ARRAY_SIZE(rates),
220 static int broxton_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
221 struct snd_pcm_hw_params *params)
223 struct snd_interval *channels = hw_param_interval(params,
224 SNDRV_PCM_HW_PARAM_CHANNELS);
225 if (params_channels(params) == 2)
226 channels->min = channels->max = 2;
228 channels->min = channels->max = 4;
233 static unsigned int channels_dmic[] = {
237 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
238 .count = ARRAY_SIZE(channels_dmic),
239 .list = channels_dmic,
243 static int broxton_dmic_startup(struct snd_pcm_substream *substream)
245 struct snd_pcm_runtime *runtime = substream->runtime;
247 runtime->hw.channels_max = 4;
248 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
249 &constraints_dmic_channels);
251 return snd_pcm_hw_constraint_list(substream->runtime, 0,
252 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
255 static const struct snd_soc_ops broxton_dmic_ops = {
256 .startup = broxton_dmic_startup,
259 static unsigned int channels[] = {
263 static struct snd_pcm_hw_constraint_list constraints_channels = {
264 .count = ARRAY_SIZE(channels),
269 static int bxt_fe_startup(struct snd_pcm_substream *substream)
271 struct snd_pcm_runtime *runtime = substream->runtime;
274 * on this platform for PCM device we support:
279 runtime->hw.channels_max = 2;
280 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
281 &constraints_channels);
283 snd_pcm_hw_constraint_list(runtime, 0,
284 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
289 static const struct snd_soc_ops broxton_rt286_fe_ops = {
290 .startup = bxt_fe_startup,
293 /* broxton digital audio interface glue - connects codec <--> CPU */
294 static struct snd_soc_dai_link broxton_rt298_dais[] = {
295 /* Front End DAI links */
296 [BXT_DPCM_AUDIO_PB] =
298 .name = "Bxt Audio Port",
299 .stream_name = "Audio",
300 .cpu_dai_name = "System Pin",
301 .platform_name = "0000:00:0e.0",
304 .codec_name = "snd-soc-dummy",
305 .codec_dai_name = "snd-soc-dummy-dai",
306 .init = broxton_rt298_fe_init,
307 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
309 .ops = &broxton_rt286_fe_ops,
311 [BXT_DPCM_AUDIO_CP] =
313 .name = "Bxt Audio Capture Port",
314 .stream_name = "Audio Record",
315 .cpu_dai_name = "System Pin",
316 .platform_name = "0000:00:0e.0",
319 .codec_name = "snd-soc-dummy",
320 .codec_dai_name = "snd-soc-dummy-dai",
321 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
323 .ops = &broxton_rt286_fe_ops,
325 [BXT_DPCM_AUDIO_REF_CP] =
327 .name = "Bxt Audio Reference cap",
328 .stream_name = "refcap",
329 .cpu_dai_name = "Reference Pin",
330 .codec_name = "snd-soc-dummy",
331 .codec_dai_name = "snd-soc-dummy-dai",
332 .platform_name = "0000:00:0e.0",
338 [BXT_DPCM_AUDIO_DMIC_CP] =
340 .name = "Bxt Audio DMIC cap",
341 .stream_name = "dmiccap",
342 .cpu_dai_name = "DMIC Pin",
343 .codec_name = "snd-soc-dummy",
344 .codec_dai_name = "snd-soc-dummy-dai",
345 .platform_name = "0000:00:0e.0",
350 .ops = &broxton_dmic_ops,
352 [BXT_DPCM_AUDIO_HDMI1_PB] =
354 .name = "Bxt HDMI Port1",
355 .stream_name = "Hdmi1",
356 .cpu_dai_name = "HDMI1 Pin",
357 .codec_name = "snd-soc-dummy",
358 .codec_dai_name = "snd-soc-dummy-dai",
359 .platform_name = "0000:00:0e.0",
365 [BXT_DPCM_AUDIO_HDMI2_PB] =
367 .name = "Bxt 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:0e.0",
378 [BXT_DPCM_AUDIO_HDMI3_PB] =
380 .name = "Bxt HDMI Port3",
381 .stream_name = "Hdmi3",
382 .cpu_dai_name = "HDMI3 Pin",
383 .codec_name = "snd-soc-dummy",
384 .codec_dai_name = "snd-soc-dummy-dai",
385 .platform_name = "0000:00:0e.0",
391 /* Back End DAI links */
394 .name = "SSP5-Codec",
396 .cpu_dai_name = "SSP5 Pin",
397 .platform_name = "0000:00:0e.0",
399 .codec_name = "i2c-INT343A:00",
400 .codec_dai_name = "rt298-aif1",
401 .init = broxton_rt298_codec_init,
402 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF |
403 SND_SOC_DAIFMT_CBS_CFS,
404 .ignore_pmdown_time = 1,
405 .be_hw_params_fixup = broxton_ssp5_fixup,
406 .ops = &broxton_rt298_ops,
413 .cpu_dai_name = "DMIC01 Pin",
414 .codec_name = "dmic-codec",
415 .codec_dai_name = "dmic-hifi",
416 .platform_name = "0000:00:0e.0",
417 .be_hw_params_fixup = broxton_dmic_fixup,
425 .cpu_dai_name = "iDisp1 Pin",
426 .codec_name = "ehdaudio0D2",
427 .codec_dai_name = "intel-hdmi-hifi1",
428 .platform_name = "0000:00:0e.0",
429 .init = broxton_hdmi_init,
436 .cpu_dai_name = "iDisp2 Pin",
437 .codec_name = "ehdaudio0D2",
438 .codec_dai_name = "intel-hdmi-hifi2",
439 .platform_name = "0000:00:0e.0",
440 .init = broxton_hdmi_init,
447 .cpu_dai_name = "iDisp3 Pin",
448 .codec_name = "ehdaudio0D2",
449 .codec_dai_name = "intel-hdmi-hifi3",
450 .platform_name = "0000:00:0e.0",
451 .init = broxton_hdmi_init,
458 static int bxt_card_late_probe(struct snd_soc_card *card)
460 struct bxt_rt286_private *ctx = snd_soc_card_get_drvdata(card);
461 struct bxt_hdmi_pcm *pcm;
462 struct snd_soc_codec *codec = NULL;
464 char jack_name[NAME_SIZE];
466 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
467 codec = pcm->codec_dai->codec;
468 snprintf(jack_name, sizeof(jack_name),
469 "HDMI/DP, pcm=%d Jack", pcm->device);
470 err = snd_soc_card_jack_new(card, jack_name,
471 SND_JACK_AVOUT, &broxton_hdmi[i],
477 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
488 return hdac_hdmi_jack_port_init(codec, &card->dapm);
492 /* broxton audio machine driver for SPT + RT298S */
493 static struct snd_soc_card broxton_rt298 = {
494 .name = "broxton-rt298",
495 .owner = THIS_MODULE,
496 .dai_link = broxton_rt298_dais,
497 .num_links = ARRAY_SIZE(broxton_rt298_dais),
498 .controls = broxton_controls,
499 .num_controls = ARRAY_SIZE(broxton_controls),
500 .dapm_widgets = broxton_widgets,
501 .num_dapm_widgets = ARRAY_SIZE(broxton_widgets),
502 .dapm_routes = broxton_rt298_map,
503 .num_dapm_routes = ARRAY_SIZE(broxton_rt298_map),
504 .fully_routed = true,
505 .late_probe = bxt_card_late_probe,
509 static int broxton_audio_probe(struct platform_device *pdev)
511 struct bxt_rt286_private *ctx;
513 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
517 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
519 broxton_rt298.dev = &pdev->dev;
520 snd_soc_card_set_drvdata(&broxton_rt298, ctx);
522 return devm_snd_soc_register_card(&pdev->dev, &broxton_rt298);
525 static struct platform_driver broxton_audio = {
526 .probe = broxton_audio_probe,
528 .name = "bxt_alc298s_i2s",
529 .pm = &snd_soc_pm_ops,
532 module_platform_driver(broxton_audio)
534 /* Module information */
535 MODULE_AUTHOR("Ramesh Babu <Ramesh.Babu@intel.com>");
536 MODULE_AUTHOR("Senthilnathan Veppur <senthilnathanx.veppur@intel.com>");
537 MODULE_DESCRIPTION("Intel SST Audio for Broxton");
538 MODULE_LICENSE("GPL v2");
539 MODULE_ALIAS("platform:bxt_alc298s_i2s");