1 // SPDX-License-Identifier: GPL-2.0+
3 // Littlemill 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/wm8994.h"
15 static int sample_rate
= 44100;
17 static int littlemill_set_bias_level(struct snd_soc_card
*card
,
18 struct snd_soc_dapm_context
*dapm
,
19 enum snd_soc_bias_level level
)
21 struct snd_soc_pcm_runtime
*rtd
;
22 struct snd_soc_dai
*aif1_dai
;
25 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[0]);
26 aif1_dai
= snd_soc_rtd_to_codec(rtd
, 0);
28 if (dapm
->dev
!= aif1_dai
->dev
)
32 case SND_SOC_BIAS_PREPARE
:
34 * If we've not already clocked things via hw_params()
35 * then do so now, otherwise these are noops.
37 if (dapm
->bias_level
== SND_SOC_BIAS_STANDBY
) {
38 ret
= snd_soc_dai_set_pll(aif1_dai
, WM8994_FLL1
,
39 WM8994_FLL_SRC_MCLK2
, 32768,
42 pr_err("Failed to start FLL: %d\n", ret
);
46 ret
= snd_soc_dai_set_sysclk(aif1_dai
,
51 pr_err("Failed to set SYSCLK: %d\n", ret
);
64 static int littlemill_set_bias_level_post(struct snd_soc_card
*card
,
65 struct snd_soc_dapm_context
*dapm
,
66 enum snd_soc_bias_level level
)
68 struct snd_soc_pcm_runtime
*rtd
;
69 struct snd_soc_dai
*aif1_dai
;
72 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[0]);
73 aif1_dai
= snd_soc_rtd_to_codec(rtd
, 0);
75 if (dapm
->dev
!= aif1_dai
->dev
)
79 case SND_SOC_BIAS_STANDBY
:
80 ret
= snd_soc_dai_set_sysclk(aif1_dai
, WM8994_SYSCLK_MCLK2
,
81 32768, SND_SOC_CLOCK_IN
);
83 pr_err("Failed to switch away from FLL1: %d\n", ret
);
87 ret
= snd_soc_dai_set_pll(aif1_dai
, WM8994_FLL1
,
90 pr_err("Failed to stop FLL1: %d\n", ret
);
99 dapm
->bias_level
= level
;
104 static int littlemill_hw_params(struct snd_pcm_substream
*substream
,
105 struct snd_pcm_hw_params
*params
)
107 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
108 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
111 sample_rate
= params_rate(params
);
113 ret
= snd_soc_dai_set_pll(codec_dai
, WM8994_FLL1
,
114 WM8994_FLL_SRC_MCLK2
, 32768,
117 pr_err("Failed to start FLL: %d\n", ret
);
121 ret
= snd_soc_dai_set_sysclk(codec_dai
,
126 pr_err("Failed to set SYSCLK: %d\n", ret
);
133 static const struct snd_soc_ops littlemill_ops
= {
134 .hw_params
= littlemill_hw_params
,
137 static const struct snd_soc_pcm_stream baseband_params
= {
138 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
145 SND_SOC_DAILINK_DEFS(cpu
,
146 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
147 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
148 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
150 SND_SOC_DAILINK_DEFS(baseband
,
151 DAILINK_COMP_ARRAY(COMP_CPU("wm8994-aif2")),
152 DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027",
155 static struct snd_soc_dai_link littlemill_dai
[] = {
158 .stream_name
= "CPU",
159 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
160 | SND_SOC_DAIFMT_CBM_CFM
,
161 .ops
= &littlemill_ops
,
162 SND_SOC_DAILINK_REG(cpu
),
166 .stream_name
= "Baseband",
167 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
168 | SND_SOC_DAIFMT_CBM_CFM
,
170 .c2c_params
= &baseband_params
,
172 SND_SOC_DAILINK_REG(baseband
),
176 static int bbclk_ev(struct snd_soc_dapm_widget
*w
,
177 struct snd_kcontrol
*kcontrol
, int event
)
179 struct snd_soc_card
*card
= w
->dapm
->card
;
180 struct snd_soc_pcm_runtime
*rtd
;
181 struct snd_soc_dai
*aif2_dai
;
184 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[1]);
185 aif2_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
188 case SND_SOC_DAPM_PRE_PMU
:
189 ret
= snd_soc_dai_set_pll(aif2_dai
, WM8994_FLL2
,
190 WM8994_FLL_SRC_BCLK
, 64 * 8000,
193 pr_err("Failed to start FLL: %d\n", ret
);
197 ret
= snd_soc_dai_set_sysclk(aif2_dai
, WM8994_SYSCLK_FLL2
,
201 pr_err("Failed to set SYSCLK: %d\n", ret
);
205 case SND_SOC_DAPM_POST_PMD
:
206 ret
= snd_soc_dai_set_sysclk(aif2_dai
, WM8994_SYSCLK_MCLK2
,
207 32768, SND_SOC_CLOCK_IN
);
209 pr_err("Failed to switch away from FLL2: %d\n", ret
);
213 ret
= snd_soc_dai_set_pll(aif2_dai
, WM8994_FLL2
,
216 pr_err("Failed to stop FLL2: %d\n", ret
);
227 static const struct snd_kcontrol_new controls
[] = {
228 SOC_DAPM_PIN_SWITCH("Headphone"),
229 SOC_DAPM_PIN_SWITCH("Headset Mic"),
230 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
231 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
234 static const struct snd_soc_dapm_widget widgets
[] = {
235 SND_SOC_DAPM_HP("Headphone", NULL
),
236 SND_SOC_DAPM_HP("Headset Mic", NULL
),
238 SND_SOC_DAPM_MIC("AMIC", NULL
),
239 SND_SOC_DAPM_MIC("DMIC", NULL
),
241 SND_SOC_DAPM_SUPPLY_S("Baseband Clock", -1, SND_SOC_NOPM
, 0, 0,
243 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
246 static const struct snd_soc_dapm_route audio_paths
[] = {
247 { "Headphone", NULL
, "HPOUT1L" },
248 { "Headphone", NULL
, "HPOUT1R" },
250 { "AMIC", NULL
, "MICBIAS1" }, /* Default for AMICBIAS jumper */
251 { "IN1LN", NULL
, "AMIC" },
253 { "DMIC", NULL
, "MICBIAS2" }, /* Default for DMICBIAS jumper */
254 { "DMIC1DAT", NULL
, "DMIC" },
255 { "DMIC2DAT", NULL
, "DMIC" },
257 { "AIF2CLK", NULL
, "Baseband Clock" },
260 static struct snd_soc_jack littlemill_headset
;
261 static struct snd_soc_jack_pin littlemill_headset_pins
[] = {
264 .mask
= SND_JACK_HEADPHONE
,
267 .pin
= "Headset Mic",
268 .mask
= SND_JACK_MICROPHONE
,
272 static int littlemill_late_probe(struct snd_soc_card
*card
)
274 struct snd_soc_pcm_runtime
*rtd
;
275 struct snd_soc_component
*component
;
276 struct snd_soc_dai
*aif1_dai
;
277 struct snd_soc_dai
*aif2_dai
;
280 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[0]);
281 component
= snd_soc_rtd_to_codec(rtd
, 0)->component
;
282 aif1_dai
= snd_soc_rtd_to_codec(rtd
, 0);
284 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[1]);
285 aif2_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
287 ret
= snd_soc_dai_set_sysclk(aif1_dai
, WM8994_SYSCLK_MCLK2
,
288 32768, SND_SOC_CLOCK_IN
);
292 ret
= snd_soc_dai_set_sysclk(aif2_dai
, WM8994_SYSCLK_MCLK2
,
293 32768, SND_SOC_CLOCK_IN
);
297 ret
= snd_soc_card_jack_new_pins(card
, "Headset",
298 SND_JACK_HEADSET
| SND_JACK_MECHANICAL
|
299 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
300 SND_JACK_BTN_2
| SND_JACK_BTN_3
|
301 SND_JACK_BTN_4
| SND_JACK_BTN_5
,
303 littlemill_headset_pins
,
304 ARRAY_SIZE(littlemill_headset_pins
));
308 /* This will check device compatibility itself */
309 wm8958_mic_detect(component
, &littlemill_headset
, NULL
, NULL
, NULL
, NULL
);
312 wm8994_mic_detect(component
, &littlemill_headset
, 1);
317 static struct snd_soc_card littlemill
= {
318 .name
= "Littlemill",
319 .owner
= THIS_MODULE
,
320 .dai_link
= littlemill_dai
,
321 .num_links
= ARRAY_SIZE(littlemill_dai
),
323 .set_bias_level
= littlemill_set_bias_level
,
324 .set_bias_level_post
= littlemill_set_bias_level_post
,
326 .controls
= controls
,
327 .num_controls
= ARRAY_SIZE(controls
),
328 .dapm_widgets
= widgets
,
329 .num_dapm_widgets
= ARRAY_SIZE(widgets
),
330 .dapm_routes
= audio_paths
,
331 .num_dapm_routes
= ARRAY_SIZE(audio_paths
),
333 .late_probe
= littlemill_late_probe
,
336 static int littlemill_probe(struct platform_device
*pdev
)
338 struct snd_soc_card
*card
= &littlemill
;
341 card
->dev
= &pdev
->dev
;
343 ret
= devm_snd_soc_register_card(&pdev
->dev
, card
);
345 dev_err_probe(&pdev
->dev
, ret
, "snd_soc_register_card() failed\n");
350 static struct platform_driver littlemill_driver
= {
352 .name
= "littlemill",
353 .pm
= &snd_soc_pm_ops
,
355 .probe
= littlemill_probe
,
358 module_platform_driver(littlemill_driver
);
360 MODULE_DESCRIPTION("Littlemill audio support");
361 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
362 MODULE_LICENSE("GPL");
363 MODULE_ALIAS("platform:littlemill");