blob: 77c85f17aca66015888b157fff21b430d4ee23e8 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Intel Broadwell Wildcatpoint SST Audio
4 *
5 * Copyright (C) 2013, Intel Corporation. All rights reserved.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7
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>
David Brazdil0f672f62019-12-10 10:32:29 +000015#include <sound/soc-acpi.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000016
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017#include "../../codecs/rt286.h"
18
19static struct snd_soc_jack broadwell_headset;
20/* Headset jack detection DAPM pins */
21static struct snd_soc_jack_pin broadwell_headset_pins[] = {
22 {
23 .pin = "Mic Jack",
24 .mask = SND_JACK_MICROPHONE,
25 },
26 {
27 .pin = "Headphone Jack",
28 .mask = SND_JACK_HEADPHONE,
29 },
30};
31
32static const struct snd_kcontrol_new broadwell_controls[] = {
33 SOC_DAPM_PIN_SWITCH("Speaker"),
34 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
35};
36
37static const struct snd_soc_dapm_widget broadwell_widgets[] = {
38 SND_SOC_DAPM_HP("Headphone Jack", NULL),
39 SND_SOC_DAPM_SPK("Speaker", NULL),
40 SND_SOC_DAPM_MIC("Mic Jack", NULL),
41 SND_SOC_DAPM_MIC("DMIC1", NULL),
42 SND_SOC_DAPM_MIC("DMIC2", NULL),
43 SND_SOC_DAPM_LINE("Line Jack", NULL),
44};
45
46static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
47
48 /* speaker */
49 {"Speaker", NULL, "SPOR"},
50 {"Speaker", NULL, "SPOL"},
51
52 /* HP jack connectors - unknown if we have jack deteck */
53 {"Headphone Jack", NULL, "HPO Pin"},
54
55 /* other jacks */
56 {"MIC1", NULL, "Mic Jack"},
57 {"LINE1", NULL, "Line Jack"},
58
59 /* digital mics */
60 {"DMIC1 Pin", NULL, "DMIC1"},
61 {"DMIC2 Pin", NULL, "DMIC2"},
62
63 /* CODEC BE connections */
64 {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
65 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
66};
67
68static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
69{
Olivier Deprez157378f2022-04-04 15:47:50 +020070 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000071 int ret = 0;
72 ret = snd_soc_card_jack_new(rtd->card, "Headset",
73 SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset,
74 broadwell_headset_pins, ARRAY_SIZE(broadwell_headset_pins));
75 if (ret)
76 return ret;
77
78 rt286_mic_detect(component, &broadwell_headset);
79 return 0;
80}
81
82
83static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
84 struct snd_pcm_hw_params *params)
85{
86 struct snd_interval *rate = hw_param_interval(params,
Olivier Deprez157378f2022-04-04 15:47:50 +020087 SNDRV_PCM_HW_PARAM_RATE);
88 struct snd_interval *chan = hw_param_interval(params,
89 SNDRV_PCM_HW_PARAM_CHANNELS);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000090
91 /* The ADSP will covert the FE rate to 48k, stereo */
92 rate->min = rate->max = 48000;
Olivier Deprez157378f2022-04-04 15:47:50 +020093 chan->min = chan->max = 2;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000094
95 /* set SSP0 to 16 bit */
96 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
97 return 0;
98}
99
100static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
101 struct snd_pcm_hw_params *params)
102{
Olivier Deprez157378f2022-04-04 15:47:50 +0200103 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
104 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000105 int ret;
106
107 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
108 SND_SOC_CLOCK_IN);
109
110 if (ret < 0) {
111 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
112 return ret;
113 }
114
115 return ret;
116}
117
118static const struct snd_soc_ops broadwell_rt286_ops = {
119 .hw_params = broadwell_rt286_hw_params,
120};
121
Olivier Deprez157378f2022-04-04 15:47:50 +0200122static const unsigned int channels[] = {
123 2,
124};
125
126static const struct snd_pcm_hw_constraint_list constraints_channels = {
127 .count = ARRAY_SIZE(channels),
128 .list = channels,
129 .mask = 0,
130};
131
132static int broadwell_fe_startup(struct snd_pcm_substream *substream)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000133{
Olivier Deprez157378f2022-04-04 15:47:50 +0200134 struct snd_pcm_runtime *runtime = substream->runtime;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000135
Olivier Deprez157378f2022-04-04 15:47:50 +0200136 /* Board supports stereo configuration only */
137 runtime->hw.channels_max = 2;
138 return snd_pcm_hw_constraint_list(runtime, 0,
139 SNDRV_PCM_HW_PARAM_CHANNELS,
140 &constraints_channels);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000141}
Olivier Deprez157378f2022-04-04 15:47:50 +0200142
143static const struct snd_soc_ops broadwell_fe_ops = {
144 .startup = broadwell_fe_startup,
145};
David Brazdil0f672f62019-12-10 10:32:29 +0000146
147SND_SOC_DAILINK_DEF(system,
148 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
149
150SND_SOC_DAILINK_DEF(offload0,
151 DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin")));
152
153SND_SOC_DAILINK_DEF(offload1,
154 DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin")));
155
156SND_SOC_DAILINK_DEF(loopback,
157 DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin")));
158
159SND_SOC_DAILINK_DEF(dummy,
160 DAILINK_COMP_ARRAY(COMP_DUMMY()));
161
162SND_SOC_DAILINK_DEF(platform,
163 DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio")));
164
165SND_SOC_DAILINK_DEF(codec,
166 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00", "rt286-aif1")));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000167
Olivier Deprez157378f2022-04-04 15:47:50 +0200168SND_SOC_DAILINK_DEF(ssp0_port,
169 DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port")));
170
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000171/* broadwell digital audio interface glue - connects codec <--> CPU */
172static struct snd_soc_dai_link broadwell_rt286_dais[] = {
173 /* Front End DAI links */
174 {
175 .name = "System PCM",
176 .stream_name = "System Playback/Capture",
Olivier Deprez157378f2022-04-04 15:47:50 +0200177 .nonatomic = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000178 .dynamic = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000179 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
Olivier Deprez157378f2022-04-04 15:47:50 +0200180 .ops = &broadwell_fe_ops,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000181 .dpcm_playback = 1,
182 .dpcm_capture = 1,
David Brazdil0f672f62019-12-10 10:32:29 +0000183 SND_SOC_DAILINK_REG(system, dummy, platform),
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000184 },
185 {
186 .name = "Offload0",
187 .stream_name = "Offload0 Playback",
Olivier Deprez157378f2022-04-04 15:47:50 +0200188 .nonatomic = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000189 .dynamic = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000190 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
191 .dpcm_playback = 1,
David Brazdil0f672f62019-12-10 10:32:29 +0000192 SND_SOC_DAILINK_REG(offload0, dummy, platform),
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000193 },
194 {
195 .name = "Offload1",
196 .stream_name = "Offload1 Playback",
Olivier Deprez157378f2022-04-04 15:47:50 +0200197 .nonatomic = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000198 .dynamic = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000199 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
200 .dpcm_playback = 1,
David Brazdil0f672f62019-12-10 10:32:29 +0000201 SND_SOC_DAILINK_REG(offload1, dummy, platform),
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000202 },
203 {
204 .name = "Loopback PCM",
205 .stream_name = "Loopback",
Olivier Deprez157378f2022-04-04 15:47:50 +0200206 .nonatomic = 1,
David Brazdil0f672f62019-12-10 10:32:29 +0000207 .dynamic = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000208 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
209 .dpcm_capture = 1,
David Brazdil0f672f62019-12-10 10:32:29 +0000210 SND_SOC_DAILINK_REG(loopback, dummy, platform),
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000211 },
212 /* Back End DAI links */
213 {
214 /* SSP0 - Codec */
215 .name = "Codec",
216 .id = 0,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000217 .no_pcm = 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000218 .init = broadwell_rt286_codec_init,
219 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
220 SND_SOC_DAIFMT_CBS_CFS,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000221 .ignore_pmdown_time = 1,
222 .be_hw_params_fixup = broadwell_ssp0_fixup,
223 .ops = &broadwell_rt286_ops,
224 .dpcm_playback = 1,
225 .dpcm_capture = 1,
Olivier Deprez157378f2022-04-04 15:47:50 +0200226 SND_SOC_DAILINK_REG(ssp0_port, codec, platform),
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000227 },
228};
229
Olivier Deprez157378f2022-04-04 15:47:50 +0200230static int broadwell_disable_jack(struct snd_soc_card *card)
231{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000232 struct snd_soc_component *component;
233
David Brazdil0f672f62019-12-10 10:32:29 +0000234 for_each_card_components(card, component) {
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000235 if (!strcmp(component->name, "i2c-INT343A:00")) {
236
237 dev_dbg(component->dev, "disabling jack detect before going to suspend.\n");
238 rt286_mic_detect(component, NULL);
239 break;
240 }
241 }
Olivier Deprez157378f2022-04-04 15:47:50 +0200242
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000243 return 0;
244}
245
Olivier Deprez157378f2022-04-04 15:47:50 +0200246static int broadwell_suspend(struct snd_soc_card *card)
247{
248 return broadwell_disable_jack(card);
249}
250
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000251static int broadwell_resume(struct snd_soc_card *card){
252 struct snd_soc_component *component;
253
David Brazdil0f672f62019-12-10 10:32:29 +0000254 for_each_card_components(card, component) {
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000255 if (!strcmp(component->name, "i2c-INT343A:00")) {
256
257 dev_dbg(component->dev, "enabling jack detect for resume.\n");
258 rt286_mic_detect(component, &broadwell_headset);
259 break;
260 }
261 }
262 return 0;
263}
264
Olivier Deprez157378f2022-04-04 15:47:50 +0200265#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
266/* use space before codec name to simplify card ID, and simplify driver name */
267#define CARD_NAME "bdw rt286" /* card name will be 'sof-bdw rt286' */
268#define DRIVER_NAME "SOF"
269#else
270#define CARD_NAME "broadwell-rt286"
271#define DRIVER_NAME NULL /* card name will be used for driver name */
272#endif
273
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000274/* broadwell audio machine driver for WPT + RT286S */
275static struct snd_soc_card broadwell_rt286 = {
Olivier Deprez157378f2022-04-04 15:47:50 +0200276 .name = CARD_NAME,
277 .driver_name = DRIVER_NAME,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000278 .owner = THIS_MODULE,
279 .dai_link = broadwell_rt286_dais,
280 .num_links = ARRAY_SIZE(broadwell_rt286_dais),
281 .controls = broadwell_controls,
282 .num_controls = ARRAY_SIZE(broadwell_controls),
283 .dapm_widgets = broadwell_widgets,
284 .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
285 .dapm_routes = broadwell_rt286_map,
286 .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
287 .fully_routed = true,
288 .suspend_pre = broadwell_suspend,
289 .resume_post = broadwell_resume,
290};
291
292static int broadwell_audio_probe(struct platform_device *pdev)
293{
David Brazdil0f672f62019-12-10 10:32:29 +0000294 struct snd_soc_acpi_mach *mach;
295 int ret;
296
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000297 broadwell_rt286.dev = &pdev->dev;
David Brazdil0f672f62019-12-10 10:32:29 +0000298
299 /* override plaform name, if required */
Olivier Deprez157378f2022-04-04 15:47:50 +0200300 mach = pdev->dev.platform_data;
David Brazdil0f672f62019-12-10 10:32:29 +0000301 ret = snd_soc_fixup_dai_links_platform_name(&broadwell_rt286,
302 mach->mach_params.platform);
303 if (ret)
304 return ret;
305
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000306 return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286);
307}
308
Olivier Deprez157378f2022-04-04 15:47:50 +0200309static int broadwell_audio_remove(struct platform_device *pdev)
310{
311 struct snd_soc_card *card = platform_get_drvdata(pdev);
312
313 return broadwell_disable_jack(card);
314}
315
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000316static struct platform_driver broadwell_audio = {
317 .probe = broadwell_audio_probe,
Olivier Deprez157378f2022-04-04 15:47:50 +0200318 .remove = broadwell_audio_remove,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000319 .driver = {
320 .name = "broadwell-audio",
321 },
322};
323
324module_platform_driver(broadwell_audio)
325
326/* Module information */
327MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
328MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
329MODULE_LICENSE("GPL v2");
330MODULE_ALIAS("platform:broadwell-audio");