1 // SPDX-License-Identifier: GPL-2.0+
3 // Speyside audio support
5 // Copyright 2011 Wolfson Microelectronics
8 #include <sound/soc-dapm.h>
9 #include <sound/jack.h>
10 #include <linux/gpio.h>
11 #include <linux/module.h>
13 #include "../codecs/wm8996.h"
14 #include "../codecs/wm9081.h"
16 #define WM8996_HPSEL_GPIO 214
17 #define MCLK_AUDIO_RATE (512 * 48000)
19 static int speyside_set_bias_level(struct snd_soc_card *card,
20 struct snd_soc_dapm_context *dapm,
21 enum snd_soc_bias_level level)
23 struct snd_soc_pcm_runtime *rtd;
24 struct snd_soc_dai *codec_dai;
27 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
28 codec_dai = rtd->codec_dai;
30 if (dapm->dev != codec_dai->dev)
34 case SND_SOC_BIAS_STANDBY:
35 ret = snd_soc_dai_set_sysclk(codec_dai, WM8996_SYSCLK_MCLK2,
36 32768, SND_SOC_CLOCK_IN);
40 ret = snd_soc_dai_set_pll(codec_dai, WM8996_FLL_MCLK2,
43 pr_err("Failed to stop FLL\n");
55 static int speyside_set_bias_level_post(struct snd_soc_card *card,
56 struct snd_soc_dapm_context *dapm,
57 enum snd_soc_bias_level level)
59 struct snd_soc_pcm_runtime *rtd;
60 struct snd_soc_dai *codec_dai;
63 rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
64 codec_dai = rtd->codec_dai;
66 if (dapm->dev != codec_dai->dev)
70 case SND_SOC_BIAS_PREPARE:
71 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
72 ret = snd_soc_dai_set_pll(codec_dai, 0,
74 32768, MCLK_AUDIO_RATE);
76 pr_err("Failed to start FLL\n");
80 ret = snd_soc_dai_set_sysclk(codec_dai,
93 card->dapm.bias_level = level;
98 static struct snd_soc_jack speyside_headset;
100 /* Headset jack detection DAPM pins */
101 static struct snd_soc_jack_pin speyside_headset_pins[] = {
103 .pin = "Headset Mic",
104 .mask = SND_JACK_MICROPHONE,
108 /* Default the headphone selection to active high */
109 static int speyside_jack_polarity;
111 static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
112 struct snd_soc_dapm_widget *sink)
114 if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
116 if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
122 static void speyside_set_polarity(struct snd_soc_component *component,
125 speyside_jack_polarity = !polarity;
126 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
128 /* Re-run DAPM to make sure we're using the correct mic bias */
129 snd_soc_dapm_sync(snd_soc_component_get_dapm(component));
132 static int speyside_wm0010_init(struct snd_soc_pcm_runtime *rtd)
134 struct snd_soc_dai *dai = rtd->codec_dai;
137 ret = snd_soc_dai_set_sysclk(dai, 0, MCLK_AUDIO_RATE, 0);
144 static int speyside_wm8996_init(struct snd_soc_pcm_runtime *rtd)
146 struct snd_soc_dai *dai = rtd->codec_dai;
147 struct snd_soc_component *component = dai->component;
150 ret = snd_soc_dai_set_sysclk(dai, WM8996_SYSCLK_MCLK2, 32768, 0);
154 ret = gpio_request(WM8996_HPSEL_GPIO, "HP_SEL");
156 pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
157 gpio_direction_output(WM8996_HPSEL_GPIO, speyside_jack_polarity);
159 ret = snd_soc_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT |
160 SND_JACK_HEADSET | SND_JACK_BTN_0,
161 &speyside_headset, speyside_headset_pins,
162 ARRAY_SIZE(speyside_headset_pins));
166 wm8996_detect(component, &speyside_headset, speyside_set_polarity);
171 static int speyside_late_probe(struct snd_soc_card *card)
173 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
174 snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
175 snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC");
176 snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC");
177 snd_soc_dapm_ignore_suspend(&card->dapm, "Main Speaker");
178 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
179 snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
184 static const struct snd_soc_pcm_stream dsp_codec_params = {
185 .formats = SNDRV_PCM_FMTBIT_S32_LE,
192 static struct snd_soc_dai_link speyside_dai[] = {
195 .stream_name = "CPU-DSP",
196 .cpu_dai_name = "samsung-i2s.0",
197 .codec_dai_name = "wm0010-sdi1",
198 .platform_name = "samsung-i2s.0",
199 .codec_name = "spi0.0",
200 .init = speyside_wm0010_init,
201 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
202 | SND_SOC_DAIFMT_CBM_CFM,
206 .stream_name = "DSP-CODEC",
207 .cpu_dai_name = "wm0010-sdi2",
208 .codec_dai_name = "wm8996-aif1",
209 .codec_name = "wm8996.1-001a",
210 .init = speyside_wm8996_init,
211 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
212 | SND_SOC_DAIFMT_CBM_CFM,
213 .params = &dsp_codec_params,
218 .stream_name = "Baseband",
219 .cpu_dai_name = "wm8996-aif2",
220 .codec_dai_name = "wm1250-ev1",
221 .codec_name = "wm1250-ev1.1-0027",
222 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
223 | SND_SOC_DAIFMT_CBM_CFM,
228 static int speyside_wm9081_init(struct snd_soc_component *component)
230 /* At any time the WM9081 is active it will have this clock */
231 return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
235 static struct snd_soc_aux_dev speyside_aux_dev[] = {
238 .codec_name = "wm9081.1-006c",
239 .init = speyside_wm9081_init,
243 static struct snd_soc_codec_conf speyside_codec_conf[] = {
245 .dev_name = "wm9081.1-006c",
246 .name_prefix = "Sub",
250 static const struct snd_kcontrol_new controls[] = {
251 SOC_DAPM_PIN_SWITCH("Main Speaker"),
252 SOC_DAPM_PIN_SWITCH("Main DMIC"),
253 SOC_DAPM_PIN_SWITCH("Main AMIC"),
254 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
255 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
256 SOC_DAPM_PIN_SWITCH("Headphone"),
259 static struct snd_soc_dapm_widget widgets[] = {
260 SND_SOC_DAPM_HP("Headphone", NULL),
261 SND_SOC_DAPM_MIC("Headset Mic", NULL),
263 SND_SOC_DAPM_SPK("Main Speaker", NULL),
265 SND_SOC_DAPM_MIC("Main AMIC", NULL),
266 SND_SOC_DAPM_MIC("Main DMIC", NULL),
269 static struct snd_soc_dapm_route audio_paths[] = {
270 { "IN1RN", NULL, "MICB1" },
271 { "IN1RP", NULL, "MICB1" },
272 { "IN1RN", NULL, "MICB2" },
273 { "IN1RP", NULL, "MICB2" },
274 { "MICB1", NULL, "Headset Mic", speyside_get_micbias },
275 { "MICB2", NULL, "Headset Mic", speyside_get_micbias },
277 { "IN1LP", NULL, "MICB2" },
278 { "IN1RN", NULL, "MICB1" },
279 { "MICB2", NULL, "Main AMIC" },
281 { "DMIC1DAT", NULL, "MICB1" },
282 { "DMIC2DAT", NULL, "MICB1" },
283 { "MICB1", NULL, "Main DMIC" },
285 { "Headphone", NULL, "HPOUT1L" },
286 { "Headphone", NULL, "HPOUT1R" },
288 { "Sub IN1", NULL, "HPOUT2L" },
289 { "Sub IN2", NULL, "HPOUT2R" },
291 { "Main Speaker", NULL, "Sub SPKN" },
292 { "Main Speaker", NULL, "Sub SPKP" },
293 { "Main Speaker", NULL, "SPKDAT" },
296 static struct snd_soc_card speyside = {
298 .owner = THIS_MODULE,
299 .dai_link = speyside_dai,
300 .num_links = ARRAY_SIZE(speyside_dai),
301 .aux_dev = speyside_aux_dev,
302 .num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
303 .codec_conf = speyside_codec_conf,
304 .num_configs = ARRAY_SIZE(speyside_codec_conf),
306 .set_bias_level = speyside_set_bias_level,
307 .set_bias_level_post = speyside_set_bias_level_post,
309 .controls = controls,
310 .num_controls = ARRAY_SIZE(controls),
311 .dapm_widgets = widgets,
312 .num_dapm_widgets = ARRAY_SIZE(widgets),
313 .dapm_routes = audio_paths,
314 .num_dapm_routes = ARRAY_SIZE(audio_paths),
315 .fully_routed = true,
317 .late_probe = speyside_late_probe,
320 static int speyside_probe(struct platform_device *pdev)
322 struct snd_soc_card *card = &speyside;
325 card->dev = &pdev->dev;
327 ret = devm_snd_soc_register_card(&pdev->dev, card);
329 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
335 static struct platform_driver speyside_driver = {
338 .pm = &snd_soc_pm_ops,
340 .probe = speyside_probe,
343 module_platform_driver(speyside_driver);
345 MODULE_DESCRIPTION("Speyside audio support");
346 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
347 MODULE_LICENSE("GPL");
348 MODULE_ALIAS("platform:speyside");