1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Broadwell Wildcatpoint SST Audio
5 * Copyright (C) 2013, Intel Corporation. All rights reserved.
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <sound/core.h>
11 #include <sound/pcm.h>
12 #include <sound/soc.h>
13 #include <sound/jack.h>
14 #include <sound/pcm_params.h>
15 #include <sound/soc-acpi.h>
17 #include "../common/sst-dsp.h"
18 #include "../haswell/sst-haswell-ipc.h"
20 #include "../../codecs/rt286.h"
22 static struct snd_soc_jack broadwell_headset;
23 /* Headset jack detection DAPM pins */
24 static struct snd_soc_jack_pin broadwell_headset_pins[] = {
27 .mask = SND_JACK_MICROPHONE,
30 .pin = "Headphone Jack",
31 .mask = SND_JACK_HEADPHONE,
35 static const struct snd_kcontrol_new broadwell_controls[] = {
36 SOC_DAPM_PIN_SWITCH("Speaker"),
37 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
40 static const struct snd_soc_dapm_widget broadwell_widgets[] = {
41 SND_SOC_DAPM_HP("Headphone Jack", NULL),
42 SND_SOC_DAPM_SPK("Speaker", NULL),
43 SND_SOC_DAPM_MIC("Mic Jack", NULL),
44 SND_SOC_DAPM_MIC("DMIC1", NULL),
45 SND_SOC_DAPM_MIC("DMIC2", NULL),
46 SND_SOC_DAPM_LINE("Line Jack", NULL),
49 static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
52 {"Speaker", NULL, "SPOR"},
53 {"Speaker", NULL, "SPOL"},
55 /* HP jack connectors - unknown if we have jack deteck */
56 {"Headphone Jack", NULL, "HPO Pin"},
59 {"MIC1", NULL, "Mic Jack"},
60 {"LINE1", NULL, "Line Jack"},
63 {"DMIC1 Pin", NULL, "DMIC1"},
64 {"DMIC2 Pin", NULL, "DMIC2"},
66 /* CODEC BE connections */
67 {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
68 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
71 static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
73 struct snd_soc_component *component = rtd->codec_dai->component;
75 ret = snd_soc_card_jack_new(rtd->card, "Headset",
76 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset,
77 broadwell_headset_pins, ARRAY_SIZE(broadwell_headset_pins));
81 rt286_mic_detect(component, &broadwell_headset);
86 static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
87 struct snd_pcm_hw_params *params)
89 struct snd_interval *rate = hw_param_interval(params,
90 SNDRV_PCM_HW_PARAM_RATE);
91 struct snd_interval *channels = hw_param_interval(params,
92 SNDRV_PCM_HW_PARAM_CHANNELS);
94 /* The ADSP will covert the FE rate to 48k, stereo */
95 rate->min = rate->max = 48000;
96 channels->min = channels->max = 2;
98 /* set SSP0 to 16 bit */
99 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
103 static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
104 struct snd_pcm_hw_params *params)
106 struct snd_soc_pcm_runtime *rtd = substream->private_data;
107 struct snd_soc_dai *codec_dai = rtd->codec_dai;
110 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
114 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
121 static const struct snd_soc_ops broadwell_rt286_ops = {
122 .hw_params = broadwell_rt286_hw_params,
125 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
126 static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
128 struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
129 struct sst_pdata *pdata = dev_get_platdata(component->dev);
130 struct sst_hsw *broadwell = pdata->dsp;
133 /* Set ADSP SSP port settings */
134 ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
135 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
136 SST_HSW_DEVICE_CLOCK_MASTER, 9);
138 dev_err(rtd->dev, "error: failed to set device config\n");
146 /* broadwell digital audio interface glue - connects codec <--> CPU */
147 static struct snd_soc_dai_link broadwell_rt286_dais[] = {
148 /* Front End DAI links */
150 .name = "System PCM",
151 .stream_name = "System Playback/Capture",
152 .cpu_dai_name = "System Pin",
153 .platform_name = "haswell-pcm-audio",
155 .codec_name = "snd-soc-dummy",
156 .codec_dai_name = "snd-soc-dummy-dai",
157 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
158 .init = broadwell_rtd_init,
160 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
166 .stream_name = "Offload0 Playback",
167 .cpu_dai_name = "Offload0 Pin",
168 .platform_name = "haswell-pcm-audio",
170 .codec_name = "snd-soc-dummy",
171 .codec_dai_name = "snd-soc-dummy-dai",
172 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
177 .stream_name = "Offload1 Playback",
178 .cpu_dai_name = "Offload1 Pin",
179 .platform_name = "haswell-pcm-audio",
181 .codec_name = "snd-soc-dummy",
182 .codec_dai_name = "snd-soc-dummy-dai",
183 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
187 .name = "Loopback PCM",
188 .stream_name = "Loopback",
189 .cpu_dai_name = "Loopback Pin",
190 .platform_name = "haswell-pcm-audio",
192 .codec_name = "snd-soc-dummy",
193 .codec_dai_name = "snd-soc-dummy-dai",
194 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
197 /* Back End DAI links */
202 .cpu_dai_name = "snd-soc-dummy-dai",
203 .platform_name = "snd-soc-dummy",
205 .codec_name = "i2c-INT343A:00",
206 .codec_dai_name = "rt286-aif1",
207 .init = broadwell_rt286_codec_init,
208 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
209 SND_SOC_DAIFMT_CBS_CFS,
211 .ignore_pmdown_time = 1,
212 .be_hw_params_fixup = broadwell_ssp0_fixup,
213 .ops = &broadwell_rt286_ops,
219 static int broadwell_suspend(struct snd_soc_card *card){
220 struct snd_soc_component *component;
222 for_each_card_components(card, component) {
223 if (!strcmp(component->name, "i2c-INT343A:00")) {
225 dev_dbg(component->dev, "disabling jack detect before going to suspend.\n");
226 rt286_mic_detect(component, NULL);
233 static int broadwell_resume(struct snd_soc_card *card){
234 struct snd_soc_component *component;
236 for_each_card_components(card, component) {
237 if (!strcmp(component->name, "i2c-INT343A:00")) {
239 dev_dbg(component->dev, "enabling jack detect for resume.\n");
240 rt286_mic_detect(component, &broadwell_headset);
247 /* broadwell audio machine driver for WPT + RT286S */
248 static struct snd_soc_card broadwell_rt286 = {
249 .name = "broadwell-rt286",
250 .owner = THIS_MODULE,
251 .dai_link = broadwell_rt286_dais,
252 .num_links = ARRAY_SIZE(broadwell_rt286_dais),
253 .controls = broadwell_controls,
254 .num_controls = ARRAY_SIZE(broadwell_controls),
255 .dapm_widgets = broadwell_widgets,
256 .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
257 .dapm_routes = broadwell_rt286_map,
258 .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
259 .fully_routed = true,
260 .suspend_pre = broadwell_suspend,
261 .resume_post = broadwell_resume,
264 static int broadwell_audio_probe(struct platform_device *pdev)
266 struct snd_soc_acpi_mach *mach;
267 const char *platform_name = NULL;
270 broadwell_rt286.dev = &pdev->dev;
272 /* override plaform name, if required */
273 mach = (&pdev->dev)->platform_data;
274 if (mach) /* extra check since legacy does not pass parameters */
275 platform_name = mach->mach_params.platform;
277 ret = snd_soc_fixup_dai_links_platform_name(&broadwell_rt286,
282 return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286);
285 static struct platform_driver broadwell_audio = {
286 .probe = broadwell_audio_probe,
288 .name = "broadwell-audio",
292 module_platform_driver(broadwell_audio)
294 /* Module information */
295 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
296 MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
297 MODULE_LICENSE("GPL v2");
298 MODULE_ALIAS("platform:broadwell-audio");