1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Broxton-P I2S Machine Driver
5 * Copyright (C) 2014-2016, Intel Corporation. All rights reserved.
8 * Intel Skylake I2S Machine driver
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <sound/core.h>
14 #include <sound/pcm.h>
15 #include <sound/soc.h>
16 #include <sound/soc-acpi.h>
17 #include <sound/jack.h>
18 #include <sound/pcm_params.h>
19 #include "../../codecs/hdac_hdmi.h"
20 #include "../../codecs/rt298.h"
21 #include "hda_dsp_common.h"
23 /* Headset jack detection DAPM pins */
24 static struct snd_soc_jack broxton_headset;
25 static struct snd_soc_jack broxton_hdmi[3];
28 struct list_head head;
29 struct snd_soc_dai *codec_dai;
33 struct bxt_rt286_private {
34 struct list_head hdmi_pcm_list;
35 bool common_hdmi_codec_drv;
39 BXT_DPCM_AUDIO_PB = 0,
41 BXT_DPCM_AUDIO_REF_CP,
42 BXT_DPCM_AUDIO_DMIC_CP,
43 BXT_DPCM_AUDIO_HDMI1_PB,
44 BXT_DPCM_AUDIO_HDMI2_PB,
45 BXT_DPCM_AUDIO_HDMI3_PB,
48 static struct snd_soc_jack_pin broxton_headset_pins[] = {
51 .mask = SND_JACK_MICROPHONE,
54 .pin = "Headphone Jack",
55 .mask = SND_JACK_HEADPHONE,
59 static const struct snd_kcontrol_new broxton_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 broxton_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 broxton_rt298_map[] = {
78 {"Speaker", NULL, "SPOR"},
79 {"Speaker", NULL, "SPOL"},
81 /* HP jack connectors - unknown if we have jack detect */
82 {"Headphone Jack", NULL, "HPO Pin"},
85 {"MIC1", NULL, "Mic Jack"},
88 {"DMIC1 Pin", NULL, "DMIC2"},
89 {"DMic", NULL, "SoC DMIC"},
91 {"HDMI1", NULL, "hif5-0 Output"},
92 {"HDMI2", NULL, "hif6-0 Output"},
93 {"HDMI2", NULL, "hif7-0 Output"},
95 /* CODEC BE connections */
96 { "AIF1 Playback", NULL, "ssp5 Tx"},
97 { "ssp5 Tx", NULL, "codec0_out"},
98 { "ssp5 Tx", NULL, "codec1_out"},
100 { "codec0_in", NULL, "ssp5 Rx" },
101 { "ssp5 Rx", NULL, "AIF1 Capture" },
103 { "dmic01_hifi", NULL, "DMIC01 Rx" },
104 { "DMIC01 Rx", NULL, "Capture" },
106 { "hifi3", NULL, "iDisp3 Tx"},
107 { "iDisp3 Tx", NULL, "iDisp3_out"},
108 { "hifi2", NULL, "iDisp2 Tx"},
109 { "iDisp2 Tx", NULL, "iDisp2_out"},
110 { "hifi1", NULL, "iDisp1 Tx"},
111 { "iDisp1 Tx", NULL, "iDisp1_out"},
114 static const struct snd_soc_dapm_route geminilake_rt298_map[] = {
116 {"Speaker", NULL, "SPOR"},
117 {"Speaker", NULL, "SPOL"},
119 /* HP jack connectors - unknown if we have jack detect */
120 {"Headphone Jack", NULL, "HPO Pin"},
123 {"MIC1", NULL, "Mic Jack"},
126 {"DMIC1 Pin", NULL, "DMIC2"},
127 {"DMic", NULL, "SoC DMIC"},
129 {"HDMI1", NULL, "hif5-0 Output"},
130 {"HDMI2", NULL, "hif6-0 Output"},
131 {"HDMI2", NULL, "hif7-0 Output"},
133 /* CODEC BE connections */
134 { "AIF1 Playback", NULL, "ssp2 Tx"},
135 { "ssp2 Tx", NULL, "codec0_out"},
136 { "ssp2 Tx", NULL, "codec1_out"},
138 { "codec0_in", NULL, "ssp2 Rx" },
139 { "ssp2 Rx", NULL, "AIF1 Capture" },
141 { "dmic01_hifi", NULL, "DMIC01 Rx" },
142 { "DMIC01 Rx", NULL, "Capture" },
144 { "dmic_voice", NULL, "DMIC16k Rx" },
145 { "DMIC16k Rx", NULL, "Capture" },
147 { "hifi3", NULL, "iDisp3 Tx"},
148 { "iDisp3 Tx", NULL, "iDisp3_out"},
149 { "hifi2", NULL, "iDisp2 Tx"},
150 { "iDisp2 Tx", NULL, "iDisp2_out"},
151 { "hifi1", NULL, "iDisp1 Tx"},
152 { "iDisp1 Tx", NULL, "iDisp1_out"},
155 static int broxton_rt298_fe_init(struct snd_soc_pcm_runtime *rtd)
157 struct snd_soc_dapm_context *dapm;
158 struct snd_soc_component *component = snd_soc_rtd_to_cpu(rtd, 0)->component;
160 dapm = snd_soc_component_get_dapm(component);
161 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
166 static int broxton_rt298_codec_init(struct snd_soc_pcm_runtime *rtd)
168 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
171 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset",
172 SND_JACK_HEADSET | SND_JACK_BTN_0,
174 broxton_headset_pins, ARRAY_SIZE(broxton_headset_pins));
179 snd_soc_component_set_jack(component, &broxton_headset, NULL);
181 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
186 static int broxton_hdmi_init(struct snd_soc_pcm_runtime *rtd)
188 struct bxt_rt286_private *ctx = snd_soc_card_get_drvdata(rtd->card);
189 struct snd_soc_dai *dai = snd_soc_rtd_to_codec(rtd, 0);
190 struct bxt_hdmi_pcm *pcm;
192 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
196 pcm->device = BXT_DPCM_AUDIO_HDMI1_PB + dai->id;
197 pcm->codec_dai = dai;
199 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
204 static int broxton_ssp5_fixup(struct snd_soc_pcm_runtime *rtd,
205 struct snd_pcm_hw_params *params)
207 struct snd_interval *rate = hw_param_interval(params,
208 SNDRV_PCM_HW_PARAM_RATE);
209 struct snd_interval *chan = hw_param_interval(params,
210 SNDRV_PCM_HW_PARAM_CHANNELS);
211 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
213 /* The ADSP will convert the FE rate to 48k, stereo */
214 rate->min = rate->max = 48000;
215 chan->min = chan->max = 2;
217 /* set SSP5 to 24 bit */
219 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
224 static int broxton_rt298_hw_params(struct snd_pcm_substream *substream,
225 struct snd_pcm_hw_params *params)
227 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
228 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
231 ret = snd_soc_dai_set_sysclk(codec_dai, RT298_SCLK_S_PLL,
232 19200000, SND_SOC_CLOCK_IN);
234 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
241 static const struct snd_soc_ops broxton_rt298_ops = {
242 .hw_params = broxton_rt298_hw_params,
245 static const unsigned int rates[] = {
249 static const struct snd_pcm_hw_constraint_list constraints_rates = {
250 .count = ARRAY_SIZE(rates),
255 static int broxton_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
256 struct snd_pcm_hw_params *params)
258 struct snd_interval *chan = hw_param_interval(params,
259 SNDRV_PCM_HW_PARAM_CHANNELS);
260 chan->min = chan->max = 4;
265 static const unsigned int channels_dmic[] = {
269 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
270 .count = ARRAY_SIZE(channels_dmic),
271 .list = channels_dmic,
275 static int broxton_dmic_startup(struct snd_pcm_substream *substream)
277 struct snd_pcm_runtime *runtime = substream->runtime;
279 runtime->hw.channels_max = 4;
280 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
281 &constraints_dmic_channels);
283 return snd_pcm_hw_constraint_list(substream->runtime, 0,
284 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
287 static const struct snd_soc_ops broxton_dmic_ops = {
288 .startup = broxton_dmic_startup,
291 static const unsigned int channels[] = {
295 static const struct snd_pcm_hw_constraint_list constraints_channels = {
296 .count = ARRAY_SIZE(channels),
301 static int bxt_fe_startup(struct snd_pcm_substream *substream)
303 struct snd_pcm_runtime *runtime = substream->runtime;
306 * on this platform for PCM device we support:
312 runtime->hw.channels_max = 2;
313 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
314 &constraints_channels);
316 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
317 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
318 snd_pcm_hw_constraint_list(runtime, 0,
319 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
324 static const struct snd_soc_ops broxton_rt286_fe_ops = {
325 .startup = bxt_fe_startup,
328 SND_SOC_DAILINK_DEF(dummy,
329 DAILINK_COMP_ARRAY(COMP_DUMMY()));
331 SND_SOC_DAILINK_DEF(system,
332 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
334 SND_SOC_DAILINK_DEF(reference,
335 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
337 SND_SOC_DAILINK_DEF(dmic,
338 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
340 SND_SOC_DAILINK_DEF(hdmi1,
341 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
343 SND_SOC_DAILINK_DEF(hdmi2,
344 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
346 SND_SOC_DAILINK_DEF(hdmi3,
347 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
349 SND_SOC_DAILINK_DEF(ssp5_pin,
350 DAILINK_COMP_ARRAY(COMP_CPU("SSP5 Pin")));
351 SND_SOC_DAILINK_DEF(ssp5_codec,
352 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00",
355 SND_SOC_DAILINK_DEF(dmic_pin,
356 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
358 SND_SOC_DAILINK_DEF(dmic_codec,
359 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec",
362 SND_SOC_DAILINK_DEF(dmic16k,
363 DAILINK_COMP_ARRAY(COMP_CPU("DMIC16k Pin")));
365 SND_SOC_DAILINK_DEF(idisp1_pin,
366 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
367 SND_SOC_DAILINK_DEF(idisp1_codec,
368 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
369 "intel-hdmi-hifi1")));
371 SND_SOC_DAILINK_DEF(idisp2_pin,
372 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
373 SND_SOC_DAILINK_DEF(idisp2_codec,
374 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
375 "intel-hdmi-hifi2")));
377 SND_SOC_DAILINK_DEF(idisp3_pin,
378 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
379 SND_SOC_DAILINK_DEF(idisp3_codec,
380 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
381 "intel-hdmi-hifi3")));
383 SND_SOC_DAILINK_DEF(platform,
384 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:0e.0")));
386 /* broxton digital audio interface glue - connects codec <--> CPU */
387 static struct snd_soc_dai_link broxton_rt298_dais[] = {
388 /* Front End DAI links */
389 [BXT_DPCM_AUDIO_PB] =
391 .name = "Bxt Audio Port",
392 .stream_name = "Audio",
395 .init = broxton_rt298_fe_init,
396 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
398 .ops = &broxton_rt286_fe_ops,
399 SND_SOC_DAILINK_REG(system, dummy, platform),
401 [BXT_DPCM_AUDIO_CP] =
403 .name = "Bxt Audio Capture Port",
404 .stream_name = "Audio Record",
407 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
409 .ops = &broxton_rt286_fe_ops,
410 SND_SOC_DAILINK_REG(system, dummy, platform),
412 [BXT_DPCM_AUDIO_REF_CP] =
414 .name = "Bxt Audio Reference cap",
415 .stream_name = "refcap",
420 SND_SOC_DAILINK_REG(reference, dummy, platform),
422 [BXT_DPCM_AUDIO_DMIC_CP] =
424 .name = "Bxt Audio DMIC cap",
425 .stream_name = "dmiccap",
430 .ops = &broxton_dmic_ops,
431 SND_SOC_DAILINK_REG(dmic, dummy, platform),
433 [BXT_DPCM_AUDIO_HDMI1_PB] =
435 .name = "Bxt HDMI Port1",
436 .stream_name = "Hdmi1",
441 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
443 [BXT_DPCM_AUDIO_HDMI2_PB] =
445 .name = "Bxt HDMI Port2",
446 .stream_name = "Hdmi2",
451 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
453 [BXT_DPCM_AUDIO_HDMI3_PB] =
455 .name = "Bxt HDMI Port3",
456 .stream_name = "Hdmi3",
461 SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
463 /* Back End DAI links */
466 .name = "SSP5-Codec",
469 .init = broxton_rt298_codec_init,
470 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF |
471 SND_SOC_DAIFMT_CBC_CFC,
472 .ignore_pmdown_time = 1,
473 .be_hw_params_fixup = broxton_ssp5_fixup,
474 .ops = &broxton_rt298_ops,
477 SND_SOC_DAILINK_REG(ssp5_pin, ssp5_codec, platform),
482 .be_hw_params_fixup = broxton_dmic_fixup,
486 SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
491 .be_hw_params_fixup = broxton_dmic_fixup,
495 SND_SOC_DAILINK_REG(dmic16k, dmic_codec, platform),
500 .init = broxton_hdmi_init,
503 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
508 .init = broxton_hdmi_init,
511 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
516 .init = broxton_hdmi_init,
519 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
524 static int bxt_card_late_probe(struct snd_soc_card *card)
526 struct bxt_rt286_private *ctx = snd_soc_card_get_drvdata(card);
527 struct bxt_hdmi_pcm *pcm;
528 struct snd_soc_component *component = NULL;
530 char jack_name[NAME_SIZE];
532 if (list_empty(&ctx->hdmi_pcm_list))
535 if (ctx->common_hdmi_codec_drv) {
536 pcm = list_first_entry(&ctx->hdmi_pcm_list, struct bxt_hdmi_pcm,
538 component = pcm->codec_dai->component;
539 return hda_dsp_hdmi_build_controls(card, component);
542 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
543 component = pcm->codec_dai->component;
544 snprintf(jack_name, sizeof(jack_name),
545 "HDMI/DP, pcm=%d Jack", pcm->device);
546 err = snd_soc_card_jack_new(card, jack_name,
547 SND_JACK_AVOUT, &broxton_hdmi[i]);
552 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
560 return hdac_hdmi_jack_port_init(component, &card->dapm);
564 /* broxton audio machine driver for SPT + RT298S */
565 static struct snd_soc_card broxton_rt298 = {
566 .name = "broxton-rt298",
567 .owner = THIS_MODULE,
568 .dai_link = broxton_rt298_dais,
569 .num_links = ARRAY_SIZE(broxton_rt298_dais),
570 .controls = broxton_controls,
571 .num_controls = ARRAY_SIZE(broxton_controls),
572 .dapm_widgets = broxton_widgets,
573 .num_dapm_widgets = ARRAY_SIZE(broxton_widgets),
574 .dapm_routes = broxton_rt298_map,
575 .num_dapm_routes = ARRAY_SIZE(broxton_rt298_map),
576 .fully_routed = true,
577 .late_probe = bxt_card_late_probe,
581 static struct snd_soc_card geminilake_rt298 = {
582 .name = "geminilake-rt298",
583 .owner = THIS_MODULE,
584 .dai_link = broxton_rt298_dais,
585 .num_links = ARRAY_SIZE(broxton_rt298_dais),
586 .controls = broxton_controls,
587 .num_controls = ARRAY_SIZE(broxton_controls),
588 .dapm_widgets = broxton_widgets,
589 .num_dapm_widgets = ARRAY_SIZE(broxton_widgets),
590 .dapm_routes = geminilake_rt298_map,
591 .num_dapm_routes = ARRAY_SIZE(geminilake_rt298_map),
592 .fully_routed = true,
593 .late_probe = bxt_card_late_probe,
596 static int broxton_audio_probe(struct platform_device *pdev)
598 struct bxt_rt286_private *ctx;
599 struct snd_soc_card *card =
600 (struct snd_soc_card *)pdev->id_entry->driver_data;
601 struct snd_soc_acpi_mach *mach;
602 const char *platform_name;
606 for (i = 0; i < ARRAY_SIZE(broxton_rt298_dais); i++) {
607 if (!strncmp(card->dai_link[i].codecs->name, "i2c-INT343A:00",
609 if (!strncmp(card->name, "broxton-rt298",
610 PLATFORM_NAME_SIZE)) {
611 card->dai_link[i].name = "SSP5-Codec";
612 card->dai_link[i].cpus->dai_name = "SSP5 Pin";
613 } else if (!strncmp(card->name, "geminilake-rt298",
614 PLATFORM_NAME_SIZE)) {
615 card->dai_link[i].name = "SSP2-Codec";
616 card->dai_link[i].cpus->dai_name = "SSP2 Pin";
621 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
625 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
627 card->dev = &pdev->dev;
628 snd_soc_card_set_drvdata(card, ctx);
630 /* override platform name, if required */
631 mach = pdev->dev.platform_data;
632 platform_name = mach->mach_params.platform;
634 ret = snd_soc_fixup_dai_links_platform_name(card,
639 ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
641 return devm_snd_soc_register_card(&pdev->dev, card);
644 static const struct platform_device_id bxt_board_ids[] = {
645 { .name = "bxt_alc298s_i2s", .driver_data =
646 (unsigned long)&broxton_rt298 },
647 { .name = "glk_alc298s_i2s", .driver_data =
648 (unsigned long)&geminilake_rt298 },
651 MODULE_DEVICE_TABLE(platform, bxt_board_ids);
653 static struct platform_driver broxton_audio = {
654 .probe = broxton_audio_probe,
656 .name = "bxt_alc298s_i2s",
657 .pm = &snd_soc_pm_ops,
659 .id_table = bxt_board_ids,
661 module_platform_driver(broxton_audio)
663 /* Module information */
664 MODULE_AUTHOR("Ramesh Babu <Ramesh.Babu@intel.com>");
665 MODULE_AUTHOR("Senthilnathan Veppur <senthilnathanx.veppur@intel.com>");
666 MODULE_DESCRIPTION("Intel SST Audio for Broxton");
667 MODULE_LICENSE("GPL v2");
668 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);