1 // SPDX-License-Identifier: GPL-2.0-only
3 * wm8350.c -- WM8350 ALSA SoC audio driver
5 * Copyright (C) 2007-12 Wolfson Microelectronics PLC.
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/delay.h>
16 #include <linux/platform_device.h>
17 #include <linux/mfd/wm8350/audio.h>
18 #include <linux/mfd/wm8350/core.h>
19 #include <linux/regulator/consumer.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/pcm_params.h>
23 #include <sound/soc.h>
24 #include <sound/initval.h>
25 #include <sound/tlv.h>
26 #include <trace/events/asoc.h>
30 #define WM8350_OUTn_0dB 0x39
32 #define WM8350_RAMP_NONE 0
33 #define WM8350_RAMP_UP 1
34 #define WM8350_RAMP_DOWN 2
36 /* We only include the analogue supplies here; the digital supplies
37 * need to be available well before this driver can be probed.
39 static const char *supply_names
[] = {
44 struct wm8350_output
{
52 struct wm8350_jack_data
{
53 struct snd_soc_jack
*jack
;
54 struct delayed_work work
;
60 struct wm8350
*wm8350
;
61 struct wm8350_output out1
;
62 struct wm8350_output out2
;
63 struct wm8350_jack_data hpl
;
64 struct wm8350_jack_data hpr
;
65 struct wm8350_jack_data mic
;
66 struct regulator_bulk_data supplies
[ARRAY_SIZE(supply_names
)];
69 struct delayed_work pga_work
;
73 * Ramp OUT1 PGA volume to minimise pops at stream startup and shutdown.
75 static inline int wm8350_out1_ramp_step(struct wm8350_data
*wm8350_data
)
77 struct wm8350_output
*out1
= &wm8350_data
->out1
;
78 struct wm8350
*wm8350
= wm8350_data
->wm8350
;
79 int left_complete
= 0, right_complete
= 0;
83 reg
= wm8350_reg_read(wm8350
, WM8350_LOUT1_VOLUME
);
84 val
= (reg
& WM8350_OUT1L_VOL_MASK
) >> WM8350_OUT1L_VOL_SHIFT
;
86 if (out1
->ramp
== WM8350_RAMP_UP
) {
88 if (val
< out1
->left_vol
) {
90 reg
&= ~WM8350_OUT1L_VOL_MASK
;
91 wm8350_reg_write(wm8350
, WM8350_LOUT1_VOLUME
,
92 reg
| (val
<< WM8350_OUT1L_VOL_SHIFT
));
95 } else if (out1
->ramp
== WM8350_RAMP_DOWN
) {
99 reg
&= ~WM8350_OUT1L_VOL_MASK
;
100 wm8350_reg_write(wm8350
, WM8350_LOUT1_VOLUME
,
101 reg
| (val
<< WM8350_OUT1L_VOL_SHIFT
));
108 reg
= wm8350_reg_read(wm8350
, WM8350_ROUT1_VOLUME
);
109 val
= (reg
& WM8350_OUT1R_VOL_MASK
) >> WM8350_OUT1R_VOL_SHIFT
;
110 if (out1
->ramp
== WM8350_RAMP_UP
) {
112 if (val
< out1
->right_vol
) {
114 reg
&= ~WM8350_OUT1R_VOL_MASK
;
115 wm8350_reg_write(wm8350
, WM8350_ROUT1_VOLUME
,
116 reg
| (val
<< WM8350_OUT1R_VOL_SHIFT
));
119 } else if (out1
->ramp
== WM8350_RAMP_DOWN
) {
123 reg
&= ~WM8350_OUT1R_VOL_MASK
;
124 wm8350_reg_write(wm8350
, WM8350_ROUT1_VOLUME
,
125 reg
| (val
<< WM8350_OUT1R_VOL_SHIFT
));
130 /* only hit the update bit if either volume has changed this step */
131 if (!left_complete
|| !right_complete
)
132 wm8350_set_bits(wm8350
, WM8350_LOUT1_VOLUME
, WM8350_OUT1_VU
);
134 return left_complete
& right_complete
;
138 * Ramp OUT2 PGA volume to minimise pops at stream startup and shutdown.
140 static inline int wm8350_out2_ramp_step(struct wm8350_data
*wm8350_data
)
142 struct wm8350_output
*out2
= &wm8350_data
->out2
;
143 struct wm8350
*wm8350
= wm8350_data
->wm8350
;
144 int left_complete
= 0, right_complete
= 0;
148 reg
= wm8350_reg_read(wm8350
, WM8350_LOUT2_VOLUME
);
149 val
= (reg
& WM8350_OUT2L_VOL_MASK
) >> WM8350_OUT1L_VOL_SHIFT
;
150 if (out2
->ramp
== WM8350_RAMP_UP
) {
152 if (val
< out2
->left_vol
) {
154 reg
&= ~WM8350_OUT2L_VOL_MASK
;
155 wm8350_reg_write(wm8350
, WM8350_LOUT2_VOLUME
,
156 reg
| (val
<< WM8350_OUT1L_VOL_SHIFT
));
159 } else if (out2
->ramp
== WM8350_RAMP_DOWN
) {
163 reg
&= ~WM8350_OUT2L_VOL_MASK
;
164 wm8350_reg_write(wm8350
, WM8350_LOUT2_VOLUME
,
165 reg
| (val
<< WM8350_OUT1L_VOL_SHIFT
));
172 reg
= wm8350_reg_read(wm8350
, WM8350_ROUT2_VOLUME
);
173 val
= (reg
& WM8350_OUT2R_VOL_MASK
) >> WM8350_OUT1R_VOL_SHIFT
;
174 if (out2
->ramp
== WM8350_RAMP_UP
) {
176 if (val
< out2
->right_vol
) {
178 reg
&= ~WM8350_OUT2R_VOL_MASK
;
179 wm8350_reg_write(wm8350
, WM8350_ROUT2_VOLUME
,
180 reg
| (val
<< WM8350_OUT1R_VOL_SHIFT
));
183 } else if (out2
->ramp
== WM8350_RAMP_DOWN
) {
187 reg
&= ~WM8350_OUT2R_VOL_MASK
;
188 wm8350_reg_write(wm8350
, WM8350_ROUT2_VOLUME
,
189 reg
| (val
<< WM8350_OUT1R_VOL_SHIFT
));
194 /* only hit the update bit if either volume has changed this step */
195 if (!left_complete
|| !right_complete
)
196 wm8350_set_bits(wm8350
, WM8350_LOUT2_VOLUME
, WM8350_OUT2_VU
);
198 return left_complete
& right_complete
;
202 * This work ramps both output PGAs at stream start/stop time to
203 * minimise pop associated with DAPM power switching.
204 * It's best to enable Zero Cross when ramping occurs to minimise any
207 static void wm8350_pga_work(struct work_struct
*work
)
209 struct wm8350_data
*wm8350_data
=
210 container_of(work
, struct wm8350_data
, pga_work
.work
);
211 struct wm8350_output
*out1
= &wm8350_data
->out1
,
212 *out2
= &wm8350_data
->out2
;
213 int i
, out1_complete
, out2_complete
;
215 /* do we need to ramp at all ? */
216 if (out1
->ramp
== WM8350_RAMP_NONE
&& out2
->ramp
== WM8350_RAMP_NONE
)
219 /* PGA volumes have 6 bits of resolution to ramp */
220 for (i
= 0; i
<= 63; i
++) {
223 if (out1
->ramp
!= WM8350_RAMP_NONE
)
224 out1_complete
= wm8350_out1_ramp_step(wm8350_data
);
225 if (out2
->ramp
!= WM8350_RAMP_NONE
)
226 out2_complete
= wm8350_out2_ramp_step(wm8350_data
);
228 /* ramp finished ? */
229 if (out1_complete
&& out2_complete
)
232 /* we need to delay longer on the up ramp */
233 if (out1
->ramp
== WM8350_RAMP_UP
||
234 out2
->ramp
== WM8350_RAMP_UP
) {
235 /* delay is longer over 0dB as increases are larger */
236 if (i
>= WM8350_OUTn_0dB
)
237 schedule_timeout_interruptible(msecs_to_jiffies
240 schedule_timeout_interruptible(msecs_to_jiffies
243 udelay(50); /* doesn't matter if we delay longer */
246 out1
->ramp
= WM8350_RAMP_NONE
;
247 out2
->ramp
= WM8350_RAMP_NONE
;
254 static int pga_event(struct snd_soc_dapm_widget
*w
,
255 struct snd_kcontrol
*kcontrol
, int event
)
257 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
258 struct wm8350_data
*wm8350_data
= snd_soc_component_get_drvdata(component
);
259 struct wm8350_output
*out
;
264 out
= &wm8350_data
->out1
;
268 out
= &wm8350_data
->out2
;
272 WARN(1, "Invalid shift %d\n", w
->shift
);
277 case SND_SOC_DAPM_POST_PMU
:
278 out
->ramp
= WM8350_RAMP_UP
;
281 schedule_delayed_work(&wm8350_data
->pga_work
,
282 msecs_to_jiffies(1));
285 case SND_SOC_DAPM_PRE_PMD
:
286 out
->ramp
= WM8350_RAMP_DOWN
;
289 schedule_delayed_work(&wm8350_data
->pga_work
,
290 msecs_to_jiffies(1));
297 static int wm8350_put_volsw_2r_vu(struct snd_kcontrol
*kcontrol
,
298 struct snd_ctl_elem_value
*ucontrol
)
300 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
301 struct wm8350_data
*wm8350_priv
= snd_soc_component_get_drvdata(component
);
302 struct wm8350_output
*out
= NULL
;
303 struct soc_mixer_control
*mc
=
304 (struct soc_mixer_control
*)kcontrol
->private_value
;
306 unsigned int reg
= mc
->reg
;
309 /* For OUT1 and OUT2 we shadow the values and only actually write
310 * them out when active in order to ensure the amplifier comes on
311 * as quietly as possible. */
313 case WM8350_LOUT1_VOLUME
:
314 out
= &wm8350_priv
->out1
;
316 case WM8350_LOUT2_VOLUME
:
317 out
= &wm8350_priv
->out2
;
324 out
->left_vol
= ucontrol
->value
.integer
.value
[0];
325 out
->right_vol
= ucontrol
->value
.integer
.value
[1];
330 ret
= snd_soc_put_volsw(kcontrol
, ucontrol
);
334 /* now hit the volume update bits (always bit 8) */
335 val
= snd_soc_component_read(component
, reg
);
336 snd_soc_component_write(component
, reg
, val
| WM8350_OUT1_VU
);
340 static int wm8350_get_volsw_2r(struct snd_kcontrol
*kcontrol
,
341 struct snd_ctl_elem_value
*ucontrol
)
343 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
344 struct wm8350_data
*wm8350_priv
= snd_soc_component_get_drvdata(component
);
345 struct wm8350_output
*out1
= &wm8350_priv
->out1
;
346 struct wm8350_output
*out2
= &wm8350_priv
->out2
;
347 struct soc_mixer_control
*mc
=
348 (struct soc_mixer_control
*)kcontrol
->private_value
;
349 unsigned int reg
= mc
->reg
;
351 /* If these are cached registers use the cache */
353 case WM8350_LOUT1_VOLUME
:
354 ucontrol
->value
.integer
.value
[0] = out1
->left_vol
;
355 ucontrol
->value
.integer
.value
[1] = out1
->right_vol
;
358 case WM8350_LOUT2_VOLUME
:
359 ucontrol
->value
.integer
.value
[0] = out2
->left_vol
;
360 ucontrol
->value
.integer
.value
[1] = out2
->right_vol
;
367 return snd_soc_get_volsw(kcontrol
, ucontrol
);
370 static const char *wm8350_deemp
[] = { "None", "32kHz", "44.1kHz", "48kHz" };
371 static const char *wm8350_pol
[] = { "Normal", "Inv R", "Inv L", "Inv L & R" };
372 static const char *wm8350_dacmutem
[] = { "Normal", "Soft" };
373 static const char *wm8350_dacmutes
[] = { "Fast", "Slow" };
374 static const char *wm8350_adcfilter
[] = { "None", "High Pass" };
375 static const char *wm8350_adchp
[] = { "44.1kHz", "8kHz", "16kHz", "32kHz" };
376 static const char *wm8350_lr
[] = { "Left", "Right" };
378 static const struct soc_enum wm8350_enum
[] = {
379 SOC_ENUM_SINGLE(WM8350_DAC_CONTROL
, 4, 4, wm8350_deemp
),
380 SOC_ENUM_SINGLE(WM8350_DAC_CONTROL
, 0, 4, wm8350_pol
),
381 SOC_ENUM_SINGLE(WM8350_DAC_MUTE_VOLUME
, 14, 2, wm8350_dacmutem
),
382 SOC_ENUM_SINGLE(WM8350_DAC_MUTE_VOLUME
, 13, 2, wm8350_dacmutes
),
383 SOC_ENUM_SINGLE(WM8350_ADC_CONTROL
, 15, 2, wm8350_adcfilter
),
384 SOC_ENUM_SINGLE(WM8350_ADC_CONTROL
, 8, 4, wm8350_adchp
),
385 SOC_ENUM_SINGLE(WM8350_ADC_CONTROL
, 0, 4, wm8350_pol
),
386 SOC_ENUM_SINGLE(WM8350_INPUT_MIXER_VOLUME
, 15, 2, wm8350_lr
),
389 static DECLARE_TLV_DB_SCALE(pre_amp_tlv
, -1200, 3525, 0);
390 static DECLARE_TLV_DB_SCALE(out_pga_tlv
, -5700, 600, 0);
391 static DECLARE_TLV_DB_SCALE(dac_pcm_tlv
, -7163, 36, 1);
392 static DECLARE_TLV_DB_SCALE(adc_pcm_tlv
, -12700, 50, 1);
393 static DECLARE_TLV_DB_SCALE(out_mix_tlv
, -1500, 300, 1);
395 static const DECLARE_TLV_DB_RANGE(capture_sd_tlv
,
396 0, 12, TLV_DB_SCALE_ITEM(-3600, 300, 1),
397 13, 15, TLV_DB_SCALE_ITEM(0, 0, 0)
400 static const struct snd_kcontrol_new wm8350_snd_controls
[] = {
401 SOC_ENUM("Playback Deemphasis", wm8350_enum
[0]),
402 SOC_ENUM("Playback DAC Inversion", wm8350_enum
[1]),
403 SOC_DOUBLE_R_EXT_TLV("Playback PCM Volume",
404 WM8350_DAC_DIGITAL_VOLUME_L
,
405 WM8350_DAC_DIGITAL_VOLUME_R
,
406 0, 255, 0, wm8350_get_volsw_2r
,
407 wm8350_put_volsw_2r_vu
, dac_pcm_tlv
),
408 SOC_ENUM("Playback PCM Mute Function", wm8350_enum
[2]),
409 SOC_ENUM("Playback PCM Mute Speed", wm8350_enum
[3]),
410 SOC_ENUM("Capture PCM Filter", wm8350_enum
[4]),
411 SOC_ENUM("Capture PCM HP Filter", wm8350_enum
[5]),
412 SOC_ENUM("Capture ADC Inversion", wm8350_enum
[6]),
413 SOC_DOUBLE_R_EXT_TLV("Capture PCM Volume",
414 WM8350_ADC_DIGITAL_VOLUME_L
,
415 WM8350_ADC_DIGITAL_VOLUME_R
,
416 0, 255, 0, wm8350_get_volsw_2r
,
417 wm8350_put_volsw_2r_vu
, adc_pcm_tlv
),
418 SOC_DOUBLE_TLV("Capture Sidetone Volume",
420 8, 4, 15, 1, capture_sd_tlv
),
421 SOC_DOUBLE_R_EXT_TLV("Capture Volume",
422 WM8350_LEFT_INPUT_VOLUME
,
423 WM8350_RIGHT_INPUT_VOLUME
,
424 2, 63, 0, wm8350_get_volsw_2r
,
425 wm8350_put_volsw_2r_vu
, pre_amp_tlv
),
426 SOC_DOUBLE_R("Capture ZC Switch",
427 WM8350_LEFT_INPUT_VOLUME
,
428 WM8350_RIGHT_INPUT_VOLUME
, 13, 1, 0),
429 SOC_SINGLE_TLV("Left Input Left Sidetone Volume",
430 WM8350_OUTPUT_LEFT_MIXER_VOLUME
, 1, 7, 0, out_mix_tlv
),
431 SOC_SINGLE_TLV("Left Input Right Sidetone Volume",
432 WM8350_OUTPUT_LEFT_MIXER_VOLUME
,
433 5, 7, 0, out_mix_tlv
),
434 SOC_SINGLE_TLV("Left Input Bypass Volume",
435 WM8350_OUTPUT_LEFT_MIXER_VOLUME
,
436 9, 7, 0, out_mix_tlv
),
437 SOC_SINGLE_TLV("Right Input Left Sidetone Volume",
438 WM8350_OUTPUT_RIGHT_MIXER_VOLUME
,
439 1, 7, 0, out_mix_tlv
),
440 SOC_SINGLE_TLV("Right Input Right Sidetone Volume",
441 WM8350_OUTPUT_RIGHT_MIXER_VOLUME
,
442 5, 7, 0, out_mix_tlv
),
443 SOC_SINGLE_TLV("Right Input Bypass Volume",
444 WM8350_OUTPUT_RIGHT_MIXER_VOLUME
,
445 13, 7, 0, out_mix_tlv
),
446 SOC_SINGLE("Left Input Mixer +20dB Switch",
447 WM8350_INPUT_MIXER_VOLUME_L
, 0, 1, 0),
448 SOC_SINGLE("Right Input Mixer +20dB Switch",
449 WM8350_INPUT_MIXER_VOLUME_R
, 0, 1, 0),
450 SOC_SINGLE_TLV("Out4 Capture Volume",
451 WM8350_INPUT_MIXER_VOLUME
,
452 1, 7, 0, out_mix_tlv
),
453 SOC_DOUBLE_R_EXT_TLV("Out1 Playback Volume",
456 2, 63, 0, wm8350_get_volsw_2r
,
457 wm8350_put_volsw_2r_vu
, out_pga_tlv
),
458 SOC_DOUBLE_R("Out1 Playback ZC Switch",
460 WM8350_ROUT1_VOLUME
, 13, 1, 0),
461 SOC_DOUBLE_R_EXT_TLV("Out2 Playback Volume",
464 2, 63, 0, wm8350_get_volsw_2r
,
465 wm8350_put_volsw_2r_vu
, out_pga_tlv
),
466 SOC_DOUBLE_R("Out2 Playback ZC Switch", WM8350_LOUT2_VOLUME
,
467 WM8350_ROUT2_VOLUME
, 13, 1, 0),
468 SOC_SINGLE("Out2 Right Invert Switch", WM8350_ROUT2_VOLUME
, 10, 1, 0),
469 SOC_SINGLE_TLV("Out2 Beep Volume", WM8350_BEEP_VOLUME
,
470 5, 7, 0, out_mix_tlv
),
472 SOC_DOUBLE_R("Out1 Playback Switch",
476 SOC_DOUBLE_R("Out2 Playback Switch",
486 /* Left Playback Mixer */
487 static const struct snd_kcontrol_new wm8350_left_play_mixer_controls
[] = {
488 SOC_DAPM_SINGLE("Playback Switch",
489 WM8350_LEFT_MIXER_CONTROL
, 11, 1, 0),
490 SOC_DAPM_SINGLE("Left Bypass Switch",
491 WM8350_LEFT_MIXER_CONTROL
, 2, 1, 0),
492 SOC_DAPM_SINGLE("Right Playback Switch",
493 WM8350_LEFT_MIXER_CONTROL
, 12, 1, 0),
494 SOC_DAPM_SINGLE("Left Sidetone Switch",
495 WM8350_LEFT_MIXER_CONTROL
, 0, 1, 0),
496 SOC_DAPM_SINGLE("Right Sidetone Switch",
497 WM8350_LEFT_MIXER_CONTROL
, 1, 1, 0),
500 /* Right Playback Mixer */
501 static const struct snd_kcontrol_new wm8350_right_play_mixer_controls
[] = {
502 SOC_DAPM_SINGLE("Playback Switch",
503 WM8350_RIGHT_MIXER_CONTROL
, 12, 1, 0),
504 SOC_DAPM_SINGLE("Right Bypass Switch",
505 WM8350_RIGHT_MIXER_CONTROL
, 3, 1, 0),
506 SOC_DAPM_SINGLE("Left Playback Switch",
507 WM8350_RIGHT_MIXER_CONTROL
, 11, 1, 0),
508 SOC_DAPM_SINGLE("Left Sidetone Switch",
509 WM8350_RIGHT_MIXER_CONTROL
, 0, 1, 0),
510 SOC_DAPM_SINGLE("Right Sidetone Switch",
511 WM8350_RIGHT_MIXER_CONTROL
, 1, 1, 0),
515 static const struct snd_kcontrol_new wm8350_out4_mixer_controls
[] = {
516 SOC_DAPM_SINGLE("Right Playback Switch",
517 WM8350_OUT4_MIXER_CONTROL
, 12, 1, 0),
518 SOC_DAPM_SINGLE("Left Playback Switch",
519 WM8350_OUT4_MIXER_CONTROL
, 11, 1, 0),
520 SOC_DAPM_SINGLE("Right Capture Switch",
521 WM8350_OUT4_MIXER_CONTROL
, 9, 1, 0),
522 SOC_DAPM_SINGLE("Out3 Playback Switch",
523 WM8350_OUT4_MIXER_CONTROL
, 2, 1, 0),
524 SOC_DAPM_SINGLE("Right Mixer Switch",
525 WM8350_OUT4_MIXER_CONTROL
, 1, 1, 0),
526 SOC_DAPM_SINGLE("Left Mixer Switch",
527 WM8350_OUT4_MIXER_CONTROL
, 0, 1, 0),
531 static const struct snd_kcontrol_new wm8350_out3_mixer_controls
[] = {
532 SOC_DAPM_SINGLE("Left Playback Switch",
533 WM8350_OUT3_MIXER_CONTROL
, 11, 1, 0),
534 SOC_DAPM_SINGLE("Left Capture Switch",
535 WM8350_OUT3_MIXER_CONTROL
, 8, 1, 0),
536 SOC_DAPM_SINGLE("Out4 Playback Switch",
537 WM8350_OUT3_MIXER_CONTROL
, 3, 1, 0),
538 SOC_DAPM_SINGLE("Left Mixer Switch",
539 WM8350_OUT3_MIXER_CONTROL
, 0, 1, 0),
542 /* Left Input Mixer */
543 static const struct snd_kcontrol_new wm8350_left_capt_mixer_controls
[] = {
544 SOC_DAPM_SINGLE_TLV("L2 Capture Volume",
545 WM8350_INPUT_MIXER_VOLUME_L
, 1, 7, 0, out_mix_tlv
),
546 SOC_DAPM_SINGLE_TLV("L3 Capture Volume",
547 WM8350_INPUT_MIXER_VOLUME_L
, 9, 7, 0, out_mix_tlv
),
548 SOC_DAPM_SINGLE("PGA Capture Switch",
549 WM8350_LEFT_INPUT_VOLUME
, 14, 1, 1),
552 /* Right Input Mixer */
553 static const struct snd_kcontrol_new wm8350_right_capt_mixer_controls
[] = {
554 SOC_DAPM_SINGLE_TLV("L2 Capture Volume",
555 WM8350_INPUT_MIXER_VOLUME_R
, 5, 7, 0, out_mix_tlv
),
556 SOC_DAPM_SINGLE_TLV("L3 Capture Volume",
557 WM8350_INPUT_MIXER_VOLUME_R
, 13, 7, 0, out_mix_tlv
),
558 SOC_DAPM_SINGLE("PGA Capture Switch",
559 WM8350_RIGHT_INPUT_VOLUME
, 14, 1, 1),
563 static const struct snd_kcontrol_new wm8350_left_mic_mixer_controls
[] = {
564 SOC_DAPM_SINGLE("INN Capture Switch", WM8350_INPUT_CONTROL
, 1, 1, 0),
565 SOC_DAPM_SINGLE("INP Capture Switch", WM8350_INPUT_CONTROL
, 0, 1, 0),
566 SOC_DAPM_SINGLE("IN2 Capture Switch", WM8350_INPUT_CONTROL
, 2, 1, 0),
569 /* Right Mic Mixer */
570 static const struct snd_kcontrol_new wm8350_right_mic_mixer_controls
[] = {
571 SOC_DAPM_SINGLE("INN Capture Switch", WM8350_INPUT_CONTROL
, 9, 1, 0),
572 SOC_DAPM_SINGLE("INP Capture Switch", WM8350_INPUT_CONTROL
, 8, 1, 0),
573 SOC_DAPM_SINGLE("IN2 Capture Switch", WM8350_INPUT_CONTROL
, 10, 1, 0),
577 static const struct snd_kcontrol_new wm8350_beep_switch_controls
=
578 SOC_DAPM_SINGLE("Switch", WM8350_BEEP_VOLUME
, 15, 1, 1);
580 /* Out4 Capture Mux */
581 static const struct snd_kcontrol_new wm8350_out4_capture_controls
=
582 SOC_DAPM_ENUM("Route", wm8350_enum
[7]);
584 static const struct snd_soc_dapm_widget wm8350_dapm_widgets
[] = {
586 SND_SOC_DAPM_PGA("IN3R PGA", WM8350_POWER_MGMT_2
, 11, 0, NULL
, 0),
587 SND_SOC_DAPM_PGA("IN3L PGA", WM8350_POWER_MGMT_2
, 10, 0, NULL
, 0),
588 SND_SOC_DAPM_PGA_E("Right Out2 PGA", WM8350_POWER_MGMT_3
, 3, 0, NULL
,
590 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
591 SND_SOC_DAPM_PGA_E("Left Out2 PGA", WM8350_POWER_MGMT_3
, 2, 0, NULL
, 0,
593 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
594 SND_SOC_DAPM_PGA_E("Right Out1 PGA", WM8350_POWER_MGMT_3
, 1, 0, NULL
,
596 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
597 SND_SOC_DAPM_PGA_E("Left Out1 PGA", WM8350_POWER_MGMT_3
, 0, 0, NULL
, 0,
599 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
601 SND_SOC_DAPM_MIXER("Right Capture Mixer", WM8350_POWER_MGMT_2
,
602 7, 0, &wm8350_right_capt_mixer_controls
[0],
603 ARRAY_SIZE(wm8350_right_capt_mixer_controls
)),
605 SND_SOC_DAPM_MIXER("Left Capture Mixer", WM8350_POWER_MGMT_2
,
606 6, 0, &wm8350_left_capt_mixer_controls
[0],
607 ARRAY_SIZE(wm8350_left_capt_mixer_controls
)),
609 SND_SOC_DAPM_MIXER("Out4 Mixer", WM8350_POWER_MGMT_2
, 5, 0,
610 &wm8350_out4_mixer_controls
[0],
611 ARRAY_SIZE(wm8350_out4_mixer_controls
)),
613 SND_SOC_DAPM_MIXER("Out3 Mixer", WM8350_POWER_MGMT_2
, 4, 0,
614 &wm8350_out3_mixer_controls
[0],
615 ARRAY_SIZE(wm8350_out3_mixer_controls
)),
617 SND_SOC_DAPM_MIXER("Right Playback Mixer", WM8350_POWER_MGMT_2
, 1, 0,
618 &wm8350_right_play_mixer_controls
[0],
619 ARRAY_SIZE(wm8350_right_play_mixer_controls
)),
621 SND_SOC_DAPM_MIXER("Left Playback Mixer", WM8350_POWER_MGMT_2
, 0, 0,
622 &wm8350_left_play_mixer_controls
[0],
623 ARRAY_SIZE(wm8350_left_play_mixer_controls
)),
625 SND_SOC_DAPM_MIXER("Left Mic Mixer", WM8350_POWER_MGMT_2
, 8, 0,
626 &wm8350_left_mic_mixer_controls
[0],
627 ARRAY_SIZE(wm8350_left_mic_mixer_controls
)),
629 SND_SOC_DAPM_MIXER("Right Mic Mixer", WM8350_POWER_MGMT_2
, 9, 0,
630 &wm8350_right_mic_mixer_controls
[0],
631 ARRAY_SIZE(wm8350_right_mic_mixer_controls
)),
633 /* virtual mixer for Beep and Out2R */
634 SND_SOC_DAPM_MIXER("Out2 Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
636 SND_SOC_DAPM_SWITCH("Beep", WM8350_POWER_MGMT_3
, 7, 0,
637 &wm8350_beep_switch_controls
),
639 SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
640 WM8350_POWER_MGMT_4
, 3, 0),
641 SND_SOC_DAPM_ADC("Left ADC", "Left Capture",
642 WM8350_POWER_MGMT_4
, 2, 0),
643 SND_SOC_DAPM_DAC("Right DAC", "Right Playback",
644 WM8350_POWER_MGMT_4
, 5, 0),
645 SND_SOC_DAPM_DAC("Left DAC", "Left Playback",
646 WM8350_POWER_MGMT_4
, 4, 0),
648 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8350_POWER_MGMT_1
, 4, 0),
650 SND_SOC_DAPM_MUX("Out4 Capture Channel", SND_SOC_NOPM
, 0, 0,
651 &wm8350_out4_capture_controls
),
653 SND_SOC_DAPM_OUTPUT("OUT1R"),
654 SND_SOC_DAPM_OUTPUT("OUT1L"),
655 SND_SOC_DAPM_OUTPUT("OUT2R"),
656 SND_SOC_DAPM_OUTPUT("OUT2L"),
657 SND_SOC_DAPM_OUTPUT("OUT3"),
658 SND_SOC_DAPM_OUTPUT("OUT4"),
660 SND_SOC_DAPM_INPUT("IN1RN"),
661 SND_SOC_DAPM_INPUT("IN1RP"),
662 SND_SOC_DAPM_INPUT("IN2R"),
663 SND_SOC_DAPM_INPUT("IN1LP"),
664 SND_SOC_DAPM_INPUT("IN1LN"),
665 SND_SOC_DAPM_INPUT("IN2L"),
666 SND_SOC_DAPM_INPUT("IN3R"),
667 SND_SOC_DAPM_INPUT("IN3L"),
670 static const struct snd_soc_dapm_route wm8350_dapm_routes
[] = {
672 /* left playback mixer */
673 {"Left Playback Mixer", "Playback Switch", "Left DAC"},
674 {"Left Playback Mixer", "Left Bypass Switch", "IN3L PGA"},
675 {"Left Playback Mixer", "Right Playback Switch", "Right DAC"},
676 {"Left Playback Mixer", "Left Sidetone Switch", "Left Mic Mixer"},
677 {"Left Playback Mixer", "Right Sidetone Switch", "Right Mic Mixer"},
679 /* right playback mixer */
680 {"Right Playback Mixer", "Playback Switch", "Right DAC"},
681 {"Right Playback Mixer", "Right Bypass Switch", "IN3R PGA"},
682 {"Right Playback Mixer", "Left Playback Switch", "Left DAC"},
683 {"Right Playback Mixer", "Left Sidetone Switch", "Left Mic Mixer"},
684 {"Right Playback Mixer", "Right Sidetone Switch", "Right Mic Mixer"},
686 /* out4 playback mixer */
687 {"Out4 Mixer", "Right Playback Switch", "Right DAC"},
688 {"Out4 Mixer", "Left Playback Switch", "Left DAC"},
689 {"Out4 Mixer", "Right Capture Switch", "Right Capture Mixer"},
690 {"Out4 Mixer", "Out3 Playback Switch", "Out3 Mixer"},
691 {"Out4 Mixer", "Right Mixer Switch", "Right Playback Mixer"},
692 {"Out4 Mixer", "Left Mixer Switch", "Left Playback Mixer"},
693 {"OUT4", NULL
, "Out4 Mixer"},
695 /* out3 playback mixer */
696 {"Out3 Mixer", "Left Playback Switch", "Left DAC"},
697 {"Out3 Mixer", "Left Capture Switch", "Left Capture Mixer"},
698 {"Out3 Mixer", "Left Mixer Switch", "Left Playback Mixer"},
699 {"Out3 Mixer", "Out4 Playback Switch", "Out4 Mixer"},
700 {"OUT3", NULL
, "Out3 Mixer"},
703 {"Right Out2 PGA", NULL
, "Right Playback Mixer"},
704 {"Left Out2 PGA", NULL
, "Left Playback Mixer"},
705 {"OUT2L", NULL
, "Left Out2 PGA"},
706 {"OUT2R", NULL
, "Right Out2 PGA"},
709 {"Right Out1 PGA", NULL
, "Right Playback Mixer"},
710 {"Left Out1 PGA", NULL
, "Left Playback Mixer"},
711 {"OUT1L", NULL
, "Left Out1 PGA"},
712 {"OUT1R", NULL
, "Right Out1 PGA"},
715 {"Left ADC", NULL
, "Left Capture Mixer"},
716 {"Right ADC", NULL
, "Right Capture Mixer"},
718 /* Left capture mixer */
719 {"Left Capture Mixer", "L2 Capture Volume", "IN2L"},
720 {"Left Capture Mixer", "L3 Capture Volume", "IN3L PGA"},
721 {"Left Capture Mixer", "PGA Capture Switch", "Left Mic Mixer"},
722 {"Left Capture Mixer", NULL
, "Out4 Capture Channel"},
724 /* Right capture mixer */
725 {"Right Capture Mixer", "L2 Capture Volume", "IN2R"},
726 {"Right Capture Mixer", "L3 Capture Volume", "IN3R PGA"},
727 {"Right Capture Mixer", "PGA Capture Switch", "Right Mic Mixer"},
728 {"Right Capture Mixer", NULL
, "Out4 Capture Channel"},
731 {"IN3L PGA", NULL
, "IN3L"},
732 {"IN3R PGA", NULL
, "IN3R"},
735 {"Left Mic Mixer", "INN Capture Switch", "IN1LN"},
736 {"Left Mic Mixer", "INP Capture Switch", "IN1LP"},
737 {"Left Mic Mixer", "IN2 Capture Switch", "IN2L"},
739 /* Right Mic mixer */
740 {"Right Mic Mixer", "INN Capture Switch", "IN1RN"},
741 {"Right Mic Mixer", "INP Capture Switch", "IN1RP"},
742 {"Right Mic Mixer", "IN2 Capture Switch", "IN2R"},
745 {"Out4 Capture Channel", NULL
, "Out4 Mixer"},
748 {"Beep", NULL
, "IN3R PGA"},
751 static int wm8350_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
752 int clk_id
, unsigned int freq
, int dir
)
754 struct snd_soc_component
*component
= codec_dai
->component
;
755 struct wm8350_data
*wm8350_data
= snd_soc_component_get_drvdata(component
);
756 struct wm8350
*wm8350
= wm8350_data
->wm8350
;
760 case WM8350_MCLK_SEL_MCLK
:
761 wm8350_clear_bits(wm8350
, WM8350_CLOCK_CONTROL_1
,
764 case WM8350_MCLK_SEL_PLL_MCLK
:
765 case WM8350_MCLK_SEL_PLL_DAC
:
766 case WM8350_MCLK_SEL_PLL_ADC
:
767 case WM8350_MCLK_SEL_PLL_32K
:
768 wm8350_set_bits(wm8350
, WM8350_CLOCK_CONTROL_1
,
770 fll_4
= snd_soc_component_read(component
, WM8350_FLL_CONTROL_4
) &
771 ~WM8350_FLL_CLK_SRC_MASK
;
772 snd_soc_component_write(component
, WM8350_FLL_CONTROL_4
, fll_4
| clk_id
);
777 if (dir
== SND_SOC_CLOCK_OUT
)
778 wm8350_set_bits(wm8350
, WM8350_CLOCK_CONTROL_2
,
781 wm8350_clear_bits(wm8350
, WM8350_CLOCK_CONTROL_2
,
787 static int wm8350_set_clkdiv(struct snd_soc_dai
*codec_dai
, int div_id
, int div
)
789 struct snd_soc_component
*component
= codec_dai
->component
;
793 case WM8350_ADC_CLKDIV
:
794 val
= snd_soc_component_read(component
, WM8350_ADC_DIVIDER
) &
795 ~WM8350_ADC_CLKDIV_MASK
;
796 snd_soc_component_write(component
, WM8350_ADC_DIVIDER
, val
| div
);
798 case WM8350_DAC_CLKDIV
:
799 val
= snd_soc_component_read(component
, WM8350_DAC_CLOCK_CONTROL
) &
800 ~WM8350_DAC_CLKDIV_MASK
;
801 snd_soc_component_write(component
, WM8350_DAC_CLOCK_CONTROL
, val
| div
);
803 case WM8350_BCLK_CLKDIV
:
804 val
= snd_soc_component_read(component
, WM8350_CLOCK_CONTROL_1
) &
805 ~WM8350_BCLK_DIV_MASK
;
806 snd_soc_component_write(component
, WM8350_CLOCK_CONTROL_1
, val
| div
);
808 case WM8350_OPCLK_CLKDIV
:
809 val
= snd_soc_component_read(component
, WM8350_CLOCK_CONTROL_1
) &
810 ~WM8350_OPCLK_DIV_MASK
;
811 snd_soc_component_write(component
, WM8350_CLOCK_CONTROL_1
, val
| div
);
813 case WM8350_SYS_CLKDIV
:
814 val
= snd_soc_component_read(component
, WM8350_CLOCK_CONTROL_1
) &
815 ~WM8350_MCLK_DIV_MASK
;
816 snd_soc_component_write(component
, WM8350_CLOCK_CONTROL_1
, val
| div
);
818 case WM8350_DACLR_CLKDIV
:
819 val
= snd_soc_component_read(component
, WM8350_DAC_LR_RATE
) &
820 ~WM8350_DACLRC_RATE_MASK
;
821 snd_soc_component_write(component
, WM8350_DAC_LR_RATE
, val
| div
);
823 case WM8350_ADCLR_CLKDIV
:
824 val
= snd_soc_component_read(component
, WM8350_ADC_LR_RATE
) &
825 ~WM8350_ADCLRC_RATE_MASK
;
826 snd_soc_component_write(component
, WM8350_ADC_LR_RATE
, val
| div
);
835 static int wm8350_set_dai_fmt(struct snd_soc_dai
*codec_dai
, unsigned int fmt
)
837 struct snd_soc_component
*component
= codec_dai
->component
;
838 u16 iface
= snd_soc_component_read(component
, WM8350_AI_FORMATING
) &
839 ~(WM8350_AIF_BCLK_INV
| WM8350_AIF_LRCLK_INV
| WM8350_AIF_FMT_MASK
);
840 u16 master
= snd_soc_component_read(component
, WM8350_AI_DAC_CONTROL
) &
842 u16 dac_lrc
= snd_soc_component_read(component
, WM8350_DAC_LR_RATE
) &
844 u16 adc_lrc
= snd_soc_component_read(component
, WM8350_ADC_LR_RATE
) &
847 /* set master/slave audio interface */
848 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
849 case SND_SOC_DAIFMT_CBM_CFM
:
850 master
|= WM8350_BCLK_MSTR
;
851 dac_lrc
|= WM8350_DACLRC_ENA
;
852 adc_lrc
|= WM8350_ADCLRC_ENA
;
854 case SND_SOC_DAIFMT_CBS_CFS
:
860 /* interface format */
861 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
862 case SND_SOC_DAIFMT_I2S
:
865 case SND_SOC_DAIFMT_RIGHT_J
:
867 case SND_SOC_DAIFMT_LEFT_J
:
870 case SND_SOC_DAIFMT_DSP_A
:
873 case SND_SOC_DAIFMT_DSP_B
:
874 iface
|= 0x3 << 8 | WM8350_AIF_LRCLK_INV
;
880 /* clock inversion */
881 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
882 case SND_SOC_DAIFMT_NB_NF
:
884 case SND_SOC_DAIFMT_IB_IF
:
885 iface
|= WM8350_AIF_LRCLK_INV
| WM8350_AIF_BCLK_INV
;
887 case SND_SOC_DAIFMT_IB_NF
:
888 iface
|= WM8350_AIF_BCLK_INV
;
890 case SND_SOC_DAIFMT_NB_IF
:
891 iface
|= WM8350_AIF_LRCLK_INV
;
897 snd_soc_component_write(component
, WM8350_AI_FORMATING
, iface
);
898 snd_soc_component_write(component
, WM8350_AI_DAC_CONTROL
, master
);
899 snd_soc_component_write(component
, WM8350_DAC_LR_RATE
, dac_lrc
);
900 snd_soc_component_write(component
, WM8350_ADC_LR_RATE
, adc_lrc
);
904 static int wm8350_pcm_hw_params(struct snd_pcm_substream
*substream
,
905 struct snd_pcm_hw_params
*params
,
906 struct snd_soc_dai
*codec_dai
)
908 struct snd_soc_component
*component
= codec_dai
->component
;
909 struct wm8350_data
*wm8350_data
= snd_soc_component_get_drvdata(component
);
910 struct wm8350
*wm8350
= wm8350_data
->wm8350
;
911 u16 iface
= snd_soc_component_read(component
, WM8350_AI_FORMATING
) &
915 switch (params_width(params
)) {
929 snd_soc_component_write(component
, WM8350_AI_FORMATING
, iface
);
931 /* The sloping stopband filter is recommended for use with
932 * lower sample rates to improve performance.
934 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
935 if (params_rate(params
) < 24000)
936 wm8350_set_bits(wm8350
, WM8350_DAC_MUTE_VOLUME
,
939 wm8350_clear_bits(wm8350
, WM8350_DAC_MUTE_VOLUME
,
946 static int wm8350_mute(struct snd_soc_dai
*dai
, int mute
, int direction
)
948 struct snd_soc_component
*component
= dai
->component
;
952 val
= WM8350_DAC_MUTE_ENA
;
956 snd_soc_component_update_bits(component
, WM8350_DAC_MUTE
, WM8350_DAC_MUTE_ENA
, val
);
963 int div
; /* FLL_OUTDIV */
966 int ratio
; /* FLL_FRATIO */
969 /* The size in bits of the fll divide multiplied by 10
970 * to allow rounding later */
971 #define FIXED_FLL_SIZE ((1 << 16) * 10)
973 static inline int fll_factors(struct _fll_div
*fll_div
, unsigned int input
,
977 unsigned int t1
, t2
, K
, Nmod
;
979 if (output
>= 2815250 && output
<= 3125000)
981 else if (output
>= 5625000 && output
<= 6250000)
983 else if (output
>= 11250000 && output
<= 12500000)
985 else if (output
>= 22500000 && output
<= 25000000)
988 printk(KERN_ERR
"wm8350: fll freq %d out of range\n", output
);
997 t1
= output
* (1 << (fll_div
->div
+ 1));
998 t2
= input
* fll_div
->ratio
;
1000 fll_div
->n
= t1
/ t2
;
1004 Kpart
= FIXED_FLL_SIZE
* (long long)Nmod
;
1006 K
= Kpart
& 0xFFFFFFFF;
1008 /* Check if we need to round */
1012 /* Move down to proper range now rounding is done */
1021 static int wm8350_set_fll(struct snd_soc_dai
*codec_dai
,
1022 int pll_id
, int source
, unsigned int freq_in
,
1023 unsigned int freq_out
)
1025 struct snd_soc_component
*component
= codec_dai
->component
;
1026 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1027 struct wm8350
*wm8350
= priv
->wm8350
;
1028 struct _fll_div fll_div
;
1032 if (freq_in
== priv
->fll_freq_in
&& freq_out
== priv
->fll_freq_out
)
1035 /* power down FLL - we need to do this for reconfiguration */
1036 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_4
,
1037 WM8350_FLL_ENA
| WM8350_FLL_OSC_ENA
);
1039 if (freq_out
== 0 || freq_in
== 0)
1042 ret
= fll_factors(&fll_div
, freq_in
, freq_out
);
1045 dev_dbg(wm8350
->dev
,
1046 "FLL in %u FLL out %u N 0x%x K 0x%x div %d ratio %d",
1047 freq_in
, freq_out
, fll_div
.n
, fll_div
.k
, fll_div
.div
,
1050 /* set up N.K & dividers */
1051 fll_1
= snd_soc_component_read(component
, WM8350_FLL_CONTROL_1
) &
1052 ~(WM8350_FLL_OUTDIV_MASK
| WM8350_FLL_RSP_RATE_MASK
| 0xc000);
1053 snd_soc_component_write(component
, WM8350_FLL_CONTROL_1
,
1054 fll_1
| (fll_div
.div
<< 8) | 0x50);
1055 snd_soc_component_write(component
, WM8350_FLL_CONTROL_2
,
1056 (fll_div
.ratio
<< 11) | (fll_div
.
1057 n
& WM8350_FLL_N_MASK
));
1058 snd_soc_component_write(component
, WM8350_FLL_CONTROL_3
, fll_div
.k
);
1059 fll_4
= snd_soc_component_read(component
, WM8350_FLL_CONTROL_4
) &
1060 ~(WM8350_FLL_FRAC
| WM8350_FLL_SLOW_LOCK_REF
);
1061 snd_soc_component_write(component
, WM8350_FLL_CONTROL_4
,
1062 fll_4
| (fll_div
.k
? WM8350_FLL_FRAC
: 0) |
1063 (fll_div
.ratio
== 8 ? WM8350_FLL_SLOW_LOCK_REF
: 0));
1066 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_FLL_OSC_ENA
);
1067 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_FLL_ENA
);
1069 priv
->fll_freq_out
= freq_out
;
1070 priv
->fll_freq_in
= freq_in
;
1075 static int wm8350_set_bias_level(struct snd_soc_component
*component
,
1076 enum snd_soc_bias_level level
)
1078 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1079 struct wm8350
*wm8350
= priv
->wm8350
;
1080 struct wm8350_audio_platform_data
*platform
=
1081 wm8350
->codec
.platform_data
;
1086 case SND_SOC_BIAS_ON
:
1087 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1088 ~(WM8350_VMID_MASK
| WM8350_CODEC_ISEL_MASK
);
1089 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1090 pm1
| WM8350_VMID_50K
|
1091 platform
->codec_current_on
<< 14);
1094 case SND_SOC_BIAS_PREPARE
:
1095 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
);
1096 pm1
&= ~WM8350_VMID_MASK
;
1097 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1098 pm1
| WM8350_VMID_50K
);
1101 case SND_SOC_BIAS_STANDBY
:
1102 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
1103 ret
= regulator_bulk_enable(ARRAY_SIZE(priv
->supplies
),
1108 /* Enable the system clock */
1109 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
,
1112 /* mute DAC & outputs */
1113 wm8350_set_bits(wm8350
, WM8350_DAC_MUTE
,
1114 WM8350_DAC_MUTE_ENA
);
1116 /* discharge cap memory */
1117 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1118 platform
->dis_out1
|
1119 (platform
->dis_out2
<< 2) |
1120 (platform
->dis_out3
<< 4) |
1121 (platform
->dis_out4
<< 6));
1123 /* wait for discharge */
1124 schedule_timeout_interruptible(msecs_to_jiffies
1126 cap_discharge_msecs
));
1128 /* enable antipop */
1129 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1130 (platform
->vmid_s_curve
<< 8));
1133 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1135 codec_current_charge
<< 14) |
1136 WM8350_VMID_5K
| WM8350_VMIDEN
|
1140 schedule_timeout_interruptible(msecs_to_jiffies
1142 vmid_charge_msecs
));
1144 /* turn on vmid 300k */
1145 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1146 ~(WM8350_VMID_MASK
| WM8350_CODEC_ISEL_MASK
);
1147 pm1
|= WM8350_VMID_300K
|
1148 (platform
->codec_current_standby
<< 14);
1149 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1153 /* enable analogue bias */
1154 pm1
|= WM8350_BIASEN
;
1155 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
, pm1
);
1157 /* disable antipop */
1158 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
, 0);
1161 /* turn on vmid 300k and reduce current */
1162 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1163 ~(WM8350_VMID_MASK
| WM8350_CODEC_ISEL_MASK
);
1164 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1165 pm1
| WM8350_VMID_300K
|
1167 codec_current_standby
<< 14));
1172 case SND_SOC_BIAS_OFF
:
1174 /* mute DAC & enable outputs */
1175 wm8350_set_bits(wm8350
, WM8350_DAC_MUTE
, WM8350_DAC_MUTE_ENA
);
1177 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_3
,
1178 WM8350_OUT1L_ENA
| WM8350_OUT1R_ENA
|
1179 WM8350_OUT2L_ENA
| WM8350_OUT2R_ENA
);
1181 /* enable anti pop S curve */
1182 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1183 (platform
->vmid_s_curve
<< 8));
1186 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1188 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
, pm1
);
1191 schedule_timeout_interruptible(msecs_to_jiffies
1193 vmid_discharge_msecs
));
1195 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1196 (platform
->vmid_s_curve
<< 8) |
1197 platform
->dis_out1
|
1198 (platform
->dis_out2
<< 2) |
1199 (platform
->dis_out3
<< 4) |
1200 (platform
->dis_out4
<< 6));
1202 /* turn off VBuf and drain */
1203 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1204 ~(WM8350_VBUFEN
| WM8350_VMID_MASK
);
1205 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1206 pm1
| WM8350_OUTPUT_DRAIN_EN
);
1209 schedule_timeout_interruptible(msecs_to_jiffies
1210 (platform
->drain_msecs
));
1212 pm1
&= ~WM8350_BIASEN
;
1213 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
, pm1
);
1215 /* disable anti-pop */
1216 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
, 0);
1218 wm8350_clear_bits(wm8350
, WM8350_LOUT1_VOLUME
,
1220 wm8350_clear_bits(wm8350
, WM8350_ROUT1_VOLUME
,
1222 wm8350_clear_bits(wm8350
, WM8350_LOUT2_VOLUME
,
1224 wm8350_clear_bits(wm8350
, WM8350_ROUT2_VOLUME
,
1227 /* disable clock gen */
1228 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_4
,
1231 regulator_bulk_disable(ARRAY_SIZE(priv
->supplies
),
1238 static void wm8350_hp_work(struct wm8350_data
*priv
,
1239 struct wm8350_jack_data
*jack
,
1242 struct wm8350
*wm8350
= priv
->wm8350
;
1246 reg
= wm8350_reg_read(wm8350
, WM8350_JACK_PIN_STATUS
);
1248 report
= jack
->report
;
1252 snd_soc_jack_report(jack
->jack
, report
, jack
->report
);
1256 static void wm8350_hpl_work(struct work_struct
*work
)
1258 struct wm8350_data
*priv
=
1259 container_of(work
, struct wm8350_data
, hpl
.work
.work
);
1261 wm8350_hp_work(priv
, &priv
->hpl
, WM8350_JACK_L_LVL
);
1264 static void wm8350_hpr_work(struct work_struct
*work
)
1266 struct wm8350_data
*priv
=
1267 container_of(work
, struct wm8350_data
, hpr
.work
.work
);
1269 wm8350_hp_work(priv
, &priv
->hpr
, WM8350_JACK_R_LVL
);
1272 static irqreturn_t
wm8350_hpl_jack_handler(int irq
, void *data
)
1274 struct wm8350_data
*priv
= data
;
1275 struct wm8350
*wm8350
= priv
->wm8350
;
1277 #ifndef CONFIG_SND_SOC_WM8350_MODULE
1278 trace_snd_soc_jack_irq("WM8350 HPL");
1281 if (device_may_wakeup(wm8350
->dev
))
1282 pm_wakeup_event(wm8350
->dev
, 250);
1284 queue_delayed_work(system_power_efficient_wq
,
1285 &priv
->hpl
.work
, msecs_to_jiffies(200));
1290 static irqreturn_t
wm8350_hpr_jack_handler(int irq
, void *data
)
1292 struct wm8350_data
*priv
= data
;
1293 struct wm8350
*wm8350
= priv
->wm8350
;
1295 #ifndef CONFIG_SND_SOC_WM8350_MODULE
1296 trace_snd_soc_jack_irq("WM8350 HPR");
1299 if (device_may_wakeup(wm8350
->dev
))
1300 pm_wakeup_event(wm8350
->dev
, 250);
1302 queue_delayed_work(system_power_efficient_wq
,
1303 &priv
->hpr
.work
, msecs_to_jiffies(200));
1309 * wm8350_hp_jack_detect - Enable headphone jack detection.
1311 * @component: WM8350 component
1312 * @which: left or right jack detect signal
1313 * @jack: jack to report detection events on
1314 * @report: value to report
1316 * Enables the headphone jack detection of the WM8350. If no report
1317 * is specified then detection is disabled.
1319 int wm8350_hp_jack_detect(struct snd_soc_component
*component
, enum wm8350_jack which
,
1320 struct snd_soc_jack
*jack
, int report
)
1322 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1323 struct wm8350
*wm8350
= priv
->wm8350
;
1328 priv
->hpl
.jack
= jack
;
1329 priv
->hpl
.report
= report
;
1330 ena
= WM8350_JDL_ENA
;
1334 priv
->hpr
.jack
= jack
;
1335 priv
->hpr
.report
= report
;
1336 ena
= WM8350_JDR_ENA
;
1344 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_TOCLK_ENA
);
1345 wm8350_set_bits(wm8350
, WM8350_JACK_DETECT
, ena
);
1347 wm8350_clear_bits(wm8350
, WM8350_JACK_DETECT
, ena
);
1353 wm8350_hpl_jack_handler(0, priv
);
1356 wm8350_hpr_jack_handler(0, priv
);
1362 EXPORT_SYMBOL_GPL(wm8350_hp_jack_detect
);
1364 static irqreturn_t
wm8350_mic_handler(int irq
, void *data
)
1366 struct wm8350_data
*priv
= data
;
1367 struct wm8350
*wm8350
= priv
->wm8350
;
1371 #ifndef CONFIG_SND_SOC_WM8350_MODULE
1372 trace_snd_soc_jack_irq("WM8350 mic");
1375 reg
= wm8350_reg_read(wm8350
, WM8350_JACK_PIN_STATUS
);
1376 if (reg
& WM8350_JACK_MICSCD_LVL
)
1377 report
|= priv
->mic
.short_report
;
1378 if (reg
& WM8350_JACK_MICSD_LVL
)
1379 report
|= priv
->mic
.report
;
1381 snd_soc_jack_report(priv
->mic
.jack
, report
,
1382 priv
->mic
.report
| priv
->mic
.short_report
);
1388 * wm8350_mic_jack_detect - Enable microphone jack detection.
1390 * @component: WM8350 component
1391 * @jack: jack to report detection events on
1392 * @detect_report: value to report when presence detected
1393 * @short_report: value to report when microphone short detected
1395 * Enables the microphone jack detection of the WM8350. If both reports
1396 * are specified as zero then detection is disabled.
1398 int wm8350_mic_jack_detect(struct snd_soc_component
*component
,
1399 struct snd_soc_jack
*jack
,
1400 int detect_report
, int short_report
)
1402 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1403 struct wm8350
*wm8350
= priv
->wm8350
;
1405 priv
->mic
.jack
= jack
;
1406 priv
->mic
.report
= detect_report
;
1407 priv
->mic
.short_report
= short_report
;
1409 if (detect_report
|| short_report
) {
1410 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_TOCLK_ENA
);
1411 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_1
,
1412 WM8350_MIC_DET_ENA
);
1414 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_1
,
1415 WM8350_MIC_DET_ENA
);
1420 EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect
);
1422 #define WM8350_RATES (SNDRV_PCM_RATE_8000_96000)
1424 #define WM8350_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
1425 SNDRV_PCM_FMTBIT_S20_3LE |\
1426 SNDRV_PCM_FMTBIT_S24_LE)
1428 static const struct snd_soc_dai_ops wm8350_dai_ops
= {
1429 .hw_params
= wm8350_pcm_hw_params
,
1430 .mute_stream
= wm8350_mute
,
1431 .set_fmt
= wm8350_set_dai_fmt
,
1432 .set_sysclk
= wm8350_set_dai_sysclk
,
1433 .set_pll
= wm8350_set_fll
,
1434 .set_clkdiv
= wm8350_set_clkdiv
,
1435 .no_capture_mute
= 1,
1438 static struct snd_soc_dai_driver wm8350_dai
= {
1439 .name
= "wm8350-hifi",
1441 .stream_name
= "Playback",
1444 .rates
= WM8350_RATES
,
1445 .formats
= WM8350_FORMATS
,
1448 .stream_name
= "Capture",
1451 .rates
= WM8350_RATES
,
1452 .formats
= WM8350_FORMATS
,
1454 .ops
= &wm8350_dai_ops
,
1457 static int wm8350_component_probe(struct snd_soc_component
*component
)
1459 struct wm8350
*wm8350
= dev_get_platdata(component
->dev
);
1460 struct wm8350_data
*priv
;
1461 struct wm8350_output
*out1
;
1462 struct wm8350_output
*out2
;
1465 if (wm8350
->codec
.platform_data
== NULL
) {
1466 dev_err(component
->dev
, "No audio platform data supplied\n");
1470 priv
= devm_kzalloc(component
->dev
, sizeof(struct wm8350_data
),
1475 snd_soc_component_init_regmap(component
, wm8350
->regmap
);
1476 snd_soc_component_set_drvdata(component
, priv
);
1478 priv
->wm8350
= wm8350
;
1480 for (i
= 0; i
< ARRAY_SIZE(supply_names
); i
++)
1481 priv
->supplies
[i
].supply
= supply_names
[i
];
1483 ret
= devm_regulator_bulk_get(wm8350
->dev
, ARRAY_SIZE(priv
->supplies
),
1488 /* Put the codec into reset if it wasn't already */
1489 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_5
, WM8350_CODEC_ENA
);
1491 INIT_DELAYED_WORK(&priv
->pga_work
, wm8350_pga_work
);
1492 INIT_DELAYED_WORK(&priv
->hpl
.work
, wm8350_hpl_work
);
1493 INIT_DELAYED_WORK(&priv
->hpr
.work
, wm8350_hpr_work
);
1495 /* Enable the codec */
1496 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_5
, WM8350_CODEC_ENA
);
1498 /* Enable robust clocking mode in ADC */
1499 snd_soc_component_write(component
, WM8350_SECURITY
, 0xa7);
1500 snd_soc_component_write(component
, 0xde, 0x13);
1501 snd_soc_component_write(component
, WM8350_SECURITY
, 0);
1503 /* read OUT1 & OUT2 volumes */
1506 out1
->left_vol
= (wm8350_reg_read(wm8350
, WM8350_LOUT1_VOLUME
) &
1507 WM8350_OUT1L_VOL_MASK
) >> WM8350_OUT1L_VOL_SHIFT
;
1508 out1
->right_vol
= (wm8350_reg_read(wm8350
, WM8350_ROUT1_VOLUME
) &
1509 WM8350_OUT1R_VOL_MASK
) >> WM8350_OUT1R_VOL_SHIFT
;
1510 out2
->left_vol
= (wm8350_reg_read(wm8350
, WM8350_LOUT2_VOLUME
) &
1511 WM8350_OUT2L_VOL_MASK
) >> WM8350_OUT1L_VOL_SHIFT
;
1512 out2
->right_vol
= (wm8350_reg_read(wm8350
, WM8350_ROUT2_VOLUME
) &
1513 WM8350_OUT2R_VOL_MASK
) >> WM8350_OUT1R_VOL_SHIFT
;
1514 wm8350_reg_write(wm8350
, WM8350_LOUT1_VOLUME
, 0);
1515 wm8350_reg_write(wm8350
, WM8350_ROUT1_VOLUME
, 0);
1516 wm8350_reg_write(wm8350
, WM8350_LOUT2_VOLUME
, 0);
1517 wm8350_reg_write(wm8350
, WM8350_ROUT2_VOLUME
, 0);
1519 /* Latch VU bits & mute */
1520 wm8350_set_bits(wm8350
, WM8350_LOUT1_VOLUME
,
1521 WM8350_OUT1_VU
| WM8350_OUT1L_MUTE
);
1522 wm8350_set_bits(wm8350
, WM8350_LOUT2_VOLUME
,
1523 WM8350_OUT2_VU
| WM8350_OUT2L_MUTE
);
1524 wm8350_set_bits(wm8350
, WM8350_ROUT1_VOLUME
,
1525 WM8350_OUT1_VU
| WM8350_OUT1R_MUTE
);
1526 wm8350_set_bits(wm8350
, WM8350_ROUT2_VOLUME
,
1527 WM8350_OUT2_VU
| WM8350_OUT2R_MUTE
);
1529 /* Make sure AIF tristating is disabled by default */
1530 wm8350_clear_bits(wm8350
, WM8350_AI_FORMATING
, WM8350_AIF_TRI
);
1532 /* Make sure we've got a sane companding setup too */
1533 wm8350_clear_bits(wm8350
, WM8350_ADC_DAC_COMP
,
1534 WM8350_DAC_COMP
| WM8350_LOOPBACK
);
1536 /* Make sure jack detect is disabled to start off with */
1537 wm8350_clear_bits(wm8350
, WM8350_JACK_DETECT
,
1538 WM8350_JDL_ENA
| WM8350_JDR_ENA
);
1540 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_L
,
1541 wm8350_hpl_jack_handler
, 0, "Left jack detect",
1543 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_R
,
1544 wm8350_hpr_jack_handler
, 0, "Right jack detect",
1546 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_MICSCD
,
1547 wm8350_mic_handler
, 0, "Microphone short", priv
);
1548 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_MICD
,
1549 wm8350_mic_handler
, 0, "Microphone detect", priv
);
1554 static void wm8350_component_remove(struct snd_soc_component
*component
)
1556 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1557 struct wm8350
*wm8350
= dev_get_platdata(component
->dev
);
1559 wm8350_clear_bits(wm8350
, WM8350_JACK_DETECT
,
1560 WM8350_JDL_ENA
| WM8350_JDR_ENA
);
1561 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_TOCLK_ENA
);
1563 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_MICD
, priv
);
1564 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_MICSCD
, priv
);
1565 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_L
, priv
);
1566 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_R
, priv
);
1568 priv
->hpl
.jack
= NULL
;
1569 priv
->hpr
.jack
= NULL
;
1570 priv
->mic
.jack
= NULL
;
1572 cancel_delayed_work_sync(&priv
->hpl
.work
);
1573 cancel_delayed_work_sync(&priv
->hpr
.work
);
1575 /* if there was any work waiting then we run it now and
1576 * wait for its completion */
1577 flush_delayed_work(&priv
->pga_work
);
1579 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_5
, WM8350_CODEC_ENA
);
1582 static const struct snd_soc_component_driver soc_component_dev_wm8350
= {
1583 .probe
= wm8350_component_probe
,
1584 .remove
= wm8350_component_remove
,
1585 .set_bias_level
= wm8350_set_bias_level
,
1586 .controls
= wm8350_snd_controls
,
1587 .num_controls
= ARRAY_SIZE(wm8350_snd_controls
),
1588 .dapm_widgets
= wm8350_dapm_widgets
,
1589 .num_dapm_widgets
= ARRAY_SIZE(wm8350_dapm_widgets
),
1590 .dapm_routes
= wm8350_dapm_routes
,
1591 .num_dapm_routes
= ARRAY_SIZE(wm8350_dapm_routes
),
1592 .suspend_bias_off
= 1,
1594 .use_pmdown_time
= 1,
1596 .non_legacy_dai_naming
= 1,
1599 static int wm8350_probe(struct platform_device
*pdev
)
1601 return devm_snd_soc_register_component(&pdev
->dev
,
1602 &soc_component_dev_wm8350
,
1606 static struct platform_driver wm8350_codec_driver
= {
1608 .name
= "wm8350-codec",
1610 .probe
= wm8350_probe
,
1613 module_platform_driver(wm8350_codec_driver
);
1615 MODULE_DESCRIPTION("ASoC WM8350 driver");
1616 MODULE_AUTHOR("Liam Girdwood");
1617 MODULE_LICENSE("GPL");
1618 MODULE_ALIAS("platform:wm8350-codec");