1 // SPDX-License-Identifier: GPL-2.0+
5 // Copyright 2012 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/wm5102.h"
14 #include "../codecs/wm9081.h"
16 /* BCLK2 is fixed at this currently */
17 #define BCLK2_RATE (64 * 8000)
20 * Expect a 24.576MHz crystal if one is fitted (the driver will function
21 * if this is not fitted).
23 #define MCLK_RATE 24576000
25 #define SYS_AUDIO_RATE 44100
26 #define SYS_MCLK_RATE (SYS_AUDIO_RATE * 512)
29 #define DAI_DSP_CODEC 1
30 #define DAI_CODEC_CP 2
31 #define DAI_CODEC_SUB 3
33 struct bells_drvdata
{
38 static struct bells_drvdata wm2200_drvdata
= {
39 .sysclk_rate
= 22579200,
42 static struct bells_drvdata wm5102_drvdata
= {
43 .sysclk_rate
= 45158400,
44 .asyncclk_rate
= 49152000,
47 static struct bells_drvdata wm5110_drvdata
= {
48 .sysclk_rate
= 135475200,
49 .asyncclk_rate
= 147456000,
52 static int bells_set_bias_level(struct snd_soc_card
*card
,
53 struct snd_soc_dapm_context
*dapm
,
54 enum snd_soc_bias_level level
)
56 struct snd_soc_pcm_runtime
*rtd
;
57 struct snd_soc_dai
*codec_dai
;
58 struct snd_soc_component
*component
;
59 struct bells_drvdata
*bells
= card
->drvdata
;
62 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[DAI_DSP_CODEC
]);
63 codec_dai
= asoc_rtd_to_codec(rtd
, 0);
64 component
= codec_dai
->component
;
66 if (dapm
->dev
!= codec_dai
->dev
)
70 case SND_SOC_BIAS_PREPARE
:
71 if (dapm
->bias_level
!= SND_SOC_BIAS_STANDBY
)
74 ret
= snd_soc_component_set_pll(component
, WM5102_FLL1
,
75 ARIZONA_FLL_SRC_MCLK1
,
79 pr_err("Failed to start FLL: %d\n", ret
);
81 if (bells
->asyncclk_rate
) {
82 ret
= snd_soc_component_set_pll(component
, WM5102_FLL2
,
83 ARIZONA_FLL_SRC_AIF2BCLK
,
85 bells
->asyncclk_rate
);
87 pr_err("Failed to start FLL: %d\n", ret
);
98 static int bells_set_bias_level_post(struct snd_soc_card
*card
,
99 struct snd_soc_dapm_context
*dapm
,
100 enum snd_soc_bias_level level
)
102 struct snd_soc_pcm_runtime
*rtd
;
103 struct snd_soc_dai
*codec_dai
;
104 struct snd_soc_component
*component
;
105 struct bells_drvdata
*bells
= card
->drvdata
;
108 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[DAI_DSP_CODEC
]);
109 codec_dai
= asoc_rtd_to_codec(rtd
, 0);
110 component
= codec_dai
->component
;
112 if (dapm
->dev
!= codec_dai
->dev
)
116 case SND_SOC_BIAS_STANDBY
:
117 ret
= snd_soc_component_set_pll(component
, WM5102_FLL1
, 0, 0, 0);
119 pr_err("Failed to stop FLL: %d\n", ret
);
123 if (bells
->asyncclk_rate
) {
124 ret
= snd_soc_component_set_pll(component
, WM5102_FLL2
,
127 pr_err("Failed to stop FLL: %d\n", ret
);
137 dapm
->bias_level
= level
;
142 static int bells_late_probe(struct snd_soc_card
*card
)
144 struct bells_drvdata
*bells
= card
->drvdata
;
145 struct snd_soc_pcm_runtime
*rtd
;
146 struct snd_soc_component
*wm0010
;
147 struct snd_soc_component
*component
;
148 struct snd_soc_dai
*aif1_dai
;
149 struct snd_soc_dai
*aif2_dai
;
150 struct snd_soc_dai
*aif3_dai
;
151 struct snd_soc_dai
*wm9081_dai
;
154 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[DAI_AP_DSP
]);
155 wm0010
= asoc_rtd_to_codec(rtd
, 0)->component
;
157 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[DAI_DSP_CODEC
]);
158 component
= asoc_rtd_to_codec(rtd
, 0)->component
;
159 aif1_dai
= asoc_rtd_to_codec(rtd
, 0);
161 ret
= snd_soc_component_set_sysclk(component
, ARIZONA_CLK_SYSCLK
,
162 ARIZONA_CLK_SRC_FLL1
,
166 dev_err(component
->dev
, "Failed to set SYSCLK: %d\n", ret
);
170 ret
= snd_soc_component_set_sysclk(wm0010
, 0, 0, SYS_MCLK_RATE
, 0);
172 dev_err(wm0010
->dev
, "Failed to set WM0010 clock: %d\n", ret
);
176 ret
= snd_soc_dai_set_sysclk(aif1_dai
, ARIZONA_CLK_SYSCLK
, 0, 0);
178 dev_err(aif1_dai
->dev
, "Failed to set AIF1 clock: %d\n", ret
);
180 ret
= snd_soc_component_set_sysclk(component
, ARIZONA_CLK_OPCLK
, 0,
181 SYS_MCLK_RATE
, SND_SOC_CLOCK_OUT
);
183 dev_err(component
->dev
, "Failed to set OPCLK: %d\n", ret
);
185 if (card
->num_rtd
== DAI_CODEC_CP
)
188 ret
= snd_soc_component_set_sysclk(component
, ARIZONA_CLK_ASYNCCLK
,
189 ARIZONA_CLK_SRC_FLL2
,
190 bells
->asyncclk_rate
,
193 dev_err(component
->dev
, "Failed to set ASYNCCLK: %d\n", ret
);
197 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[DAI_CODEC_CP
]);
198 aif2_dai
= asoc_rtd_to_cpu(rtd
, 0);
200 ret
= snd_soc_dai_set_sysclk(aif2_dai
, ARIZONA_CLK_ASYNCCLK
, 0, 0);
202 dev_err(aif2_dai
->dev
, "Failed to set AIF2 clock: %d\n", ret
);
206 if (card
->num_rtd
== DAI_CODEC_SUB
)
209 rtd
= snd_soc_get_pcm_runtime(card
, &card
->dai_link
[DAI_CODEC_SUB
]);
210 aif3_dai
= asoc_rtd_to_cpu(rtd
, 0);
211 wm9081_dai
= asoc_rtd_to_codec(rtd
, 0);
213 ret
= snd_soc_dai_set_sysclk(aif3_dai
, ARIZONA_CLK_SYSCLK
, 0, 0);
215 dev_err(aif1_dai
->dev
, "Failed to set AIF1 clock: %d\n", ret
);
219 ret
= snd_soc_component_set_sysclk(wm9081_dai
->component
, WM9081_SYSCLK_MCLK
,
220 0, SYS_MCLK_RATE
, 0);
222 dev_err(wm9081_dai
->dev
, "Failed to set MCLK: %d\n", ret
);
229 static const struct snd_soc_pcm_stream baseband_params
= {
230 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
237 static const struct snd_soc_pcm_stream sub_params
= {
238 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
239 .rate_min
= SYS_AUDIO_RATE
,
240 .rate_max
= SYS_AUDIO_RATE
,
245 SND_SOC_DAILINK_DEFS(wm2200_cpu_dsp
,
246 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
247 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
248 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
250 SND_SOC_DAILINK_DEFS(wm2200_dsp_codec
,
251 DAILINK_COMP_ARRAY(COMP_CPU("wm0010-sdi2")),
252 DAILINK_COMP_ARRAY(COMP_CODEC("wm2200.1-003a", "wm2200")));
254 static struct snd_soc_dai_link bells_dai_wm2200
[] = {
257 .stream_name
= "CPU-DSP",
258 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
259 | SND_SOC_DAIFMT_CBM_CFM
,
260 SND_SOC_DAILINK_REG(wm2200_cpu_dsp
),
264 .stream_name
= "DSP-CODEC",
265 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
266 | SND_SOC_DAIFMT_CBM_CFM
,
267 .params
= &sub_params
,
269 SND_SOC_DAILINK_REG(wm2200_dsp_codec
),
273 SND_SOC_DAILINK_DEFS(wm5102_cpu_dsp
,
274 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
275 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
276 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
278 SND_SOC_DAILINK_DEFS(wm5102_dsp_codec
,
279 DAILINK_COMP_ARRAY(COMP_CPU("wm0010-sdi2")),
280 DAILINK_COMP_ARRAY(COMP_CODEC("wm5102-codec", "wm5102-aif1")));
282 SND_SOC_DAILINK_DEFS(wm5102_baseband
,
283 DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif2")),
284 DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1")));
286 SND_SOC_DAILINK_DEFS(wm5102_sub
,
287 DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif3")),
288 DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi")));
290 static struct snd_soc_dai_link bells_dai_wm5102
[] = {
293 .stream_name
= "CPU-DSP",
294 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
295 | SND_SOC_DAIFMT_CBM_CFM
,
296 SND_SOC_DAILINK_REG(wm5102_cpu_dsp
),
300 .stream_name
= "DSP-CODEC",
301 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
302 | SND_SOC_DAIFMT_CBM_CFM
,
303 .params
= &sub_params
,
305 SND_SOC_DAILINK_REG(wm5102_dsp_codec
),
309 .stream_name
= "Baseband",
310 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
311 | SND_SOC_DAIFMT_CBM_CFM
,
313 .params
= &baseband_params
,
314 SND_SOC_DAILINK_REG(wm5102_baseband
),
318 .stream_name
= "Sub",
319 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
320 | SND_SOC_DAIFMT_CBS_CFS
,
322 .params
= &sub_params
,
323 SND_SOC_DAILINK_REG(wm5102_sub
),
327 SND_SOC_DAILINK_DEFS(wm5110_cpu_dsp
,
328 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
329 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
330 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
332 SND_SOC_DAILINK_DEFS(wm5110_dsp_codec
,
333 DAILINK_COMP_ARRAY(COMP_CPU("wm0010-sdi2")),
334 DAILINK_COMP_ARRAY(COMP_CODEC("wm5110-codec", "wm5110-aif1")));
336 SND_SOC_DAILINK_DEFS(wm5110_baseband
,
337 DAILINK_COMP_ARRAY(COMP_CPU("wm5110-aif2")),
338 DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1")));
341 SND_SOC_DAILINK_DEFS(wm5110_sub
,
342 DAILINK_COMP_ARRAY(COMP_CPU("wm5110-aif3")),
343 DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi")));
345 static struct snd_soc_dai_link bells_dai_wm5110
[] = {
348 .stream_name
= "CPU-DSP",
349 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
350 | SND_SOC_DAIFMT_CBM_CFM
,
351 SND_SOC_DAILINK_REG(wm5110_cpu_dsp
),
355 .stream_name
= "DSP-CODEC",
356 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
357 | SND_SOC_DAIFMT_CBM_CFM
,
358 .params
= &sub_params
,
360 SND_SOC_DAILINK_REG(wm5110_dsp_codec
),
364 .stream_name
= "Baseband",
365 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
366 | SND_SOC_DAIFMT_CBM_CFM
,
368 .params
= &baseband_params
,
369 SND_SOC_DAILINK_REG(wm5110_baseband
),
373 .stream_name
= "Sub",
374 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
375 | SND_SOC_DAIFMT_CBS_CFS
,
377 .params
= &sub_params
,
378 SND_SOC_DAILINK_REG(wm5110_sub
),
382 static struct snd_soc_codec_conf bells_codec_conf
[] = {
384 .dlc
= COMP_CODEC_CONF("wm9081.1-006c"),
385 .name_prefix
= "Sub",
389 static struct snd_soc_dapm_widget bells_widgets
[] = {
390 SND_SOC_DAPM_MIC("DMIC", NULL
),
393 static struct snd_soc_dapm_route bells_routes
[] = {
394 { "Sub CLK_SYS", NULL
, "OPCLK" },
395 { "CLKIN", NULL
, "OPCLK" },
397 { "DMIC", NULL
, "MICBIAS2" },
398 { "IN2L", NULL
, "DMIC" },
399 { "IN2R", NULL
, "DMIC" },
402 static struct snd_soc_card bells_cards
[] = {
404 .name
= "Bells WM2200",
405 .owner
= THIS_MODULE
,
406 .dai_link
= bells_dai_wm2200
,
407 .num_links
= ARRAY_SIZE(bells_dai_wm2200
),
408 .codec_conf
= bells_codec_conf
,
409 .num_configs
= ARRAY_SIZE(bells_codec_conf
),
411 .late_probe
= bells_late_probe
,
413 .dapm_widgets
= bells_widgets
,
414 .num_dapm_widgets
= ARRAY_SIZE(bells_widgets
),
415 .dapm_routes
= bells_routes
,
416 .num_dapm_routes
= ARRAY_SIZE(bells_routes
),
418 .set_bias_level
= bells_set_bias_level
,
419 .set_bias_level_post
= bells_set_bias_level_post
,
421 .drvdata
= &wm2200_drvdata
,
424 .name
= "Bells WM5102",
425 .owner
= THIS_MODULE
,
426 .dai_link
= bells_dai_wm5102
,
427 .num_links
= ARRAY_SIZE(bells_dai_wm5102
),
428 .codec_conf
= bells_codec_conf
,
429 .num_configs
= ARRAY_SIZE(bells_codec_conf
),
431 .late_probe
= bells_late_probe
,
433 .dapm_widgets
= bells_widgets
,
434 .num_dapm_widgets
= ARRAY_SIZE(bells_widgets
),
435 .dapm_routes
= bells_routes
,
436 .num_dapm_routes
= ARRAY_SIZE(bells_routes
),
438 .set_bias_level
= bells_set_bias_level
,
439 .set_bias_level_post
= bells_set_bias_level_post
,
441 .drvdata
= &wm5102_drvdata
,
444 .name
= "Bells WM5110",
445 .owner
= THIS_MODULE
,
446 .dai_link
= bells_dai_wm5110
,
447 .num_links
= ARRAY_SIZE(bells_dai_wm5110
),
448 .codec_conf
= bells_codec_conf
,
449 .num_configs
= ARRAY_SIZE(bells_codec_conf
),
451 .late_probe
= bells_late_probe
,
453 .dapm_widgets
= bells_widgets
,
454 .num_dapm_widgets
= ARRAY_SIZE(bells_widgets
),
455 .dapm_routes
= bells_routes
,
456 .num_dapm_routes
= ARRAY_SIZE(bells_routes
),
458 .set_bias_level
= bells_set_bias_level
,
459 .set_bias_level_post
= bells_set_bias_level_post
,
461 .drvdata
= &wm5110_drvdata
,
465 static int bells_probe(struct platform_device
*pdev
)
469 bells_cards
[pdev
->id
].dev
= &pdev
->dev
;
471 ret
= devm_snd_soc_register_card(&pdev
->dev
, &bells_cards
[pdev
->id
]);
474 "snd_soc_register_card(%s) failed: %d\n",
475 bells_cards
[pdev
->id
].name
, ret
);
480 static struct platform_driver bells_driver
= {
483 .pm
= &snd_soc_pm_ops
,
485 .probe
= bells_probe
,
488 module_platform_driver(bells_driver
);
490 MODULE_DESCRIPTION("Bells audio support");
491 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
492 MODULE_LICENSE("GPL");
493 MODULE_ALIAS("platform:bells");