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
++) {
221 out1_complete
= 1, out2_complete
= 1;
222 if (out1
->ramp
!= WM8350_RAMP_NONE
)
223 out1_complete
= wm8350_out1_ramp_step(wm8350_data
);
224 if (out2
->ramp
!= WM8350_RAMP_NONE
)
225 out2_complete
= wm8350_out2_ramp_step(wm8350_data
);
227 /* ramp finished ? */
228 if (out1_complete
&& out2_complete
)
231 /* we need to delay longer on the up ramp */
232 if (out1
->ramp
== WM8350_RAMP_UP
||
233 out2
->ramp
== WM8350_RAMP_UP
) {
234 /* delay is longer over 0dB as increases are larger */
235 if (i
>= WM8350_OUTn_0dB
)
236 schedule_timeout_interruptible(msecs_to_jiffies
239 schedule_timeout_interruptible(msecs_to_jiffies
242 udelay(50); /* doesn't matter if we delay longer */
245 out1
->ramp
= WM8350_RAMP_NONE
;
246 out2
->ramp
= WM8350_RAMP_NONE
;
253 static int pga_event(struct snd_soc_dapm_widget
*w
,
254 struct snd_kcontrol
*kcontrol
, int event
)
256 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
257 struct wm8350_data
*wm8350_data
= snd_soc_component_get_drvdata(component
);
258 struct wm8350_output
*out
;
263 out
= &wm8350_data
->out1
;
267 out
= &wm8350_data
->out2
;
271 WARN(1, "Invalid shift %d\n", w
->shift
);
276 case SND_SOC_DAPM_POST_PMU
:
277 out
->ramp
= WM8350_RAMP_UP
;
280 schedule_delayed_work(&wm8350_data
->pga_work
,
281 msecs_to_jiffies(1));
284 case SND_SOC_DAPM_PRE_PMD
:
285 out
->ramp
= WM8350_RAMP_DOWN
;
288 schedule_delayed_work(&wm8350_data
->pga_work
,
289 msecs_to_jiffies(1));
296 static int wm8350_put_volsw_2r_vu(struct snd_kcontrol
*kcontrol
,
297 struct snd_ctl_elem_value
*ucontrol
)
299 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
300 struct wm8350_data
*wm8350_priv
= snd_soc_component_get_drvdata(component
);
301 struct wm8350_output
*out
= NULL
;
302 struct soc_mixer_control
*mc
=
303 (struct soc_mixer_control
*)kcontrol
->private_value
;
305 unsigned int reg
= mc
->reg
;
308 /* For OUT1 and OUT2 we shadow the values and only actually write
309 * them out when active in order to ensure the amplifier comes on
310 * as quietly as possible. */
312 case WM8350_LOUT1_VOLUME
:
313 out
= &wm8350_priv
->out1
;
315 case WM8350_LOUT2_VOLUME
:
316 out
= &wm8350_priv
->out2
;
323 out
->left_vol
= ucontrol
->value
.integer
.value
[0];
324 out
->right_vol
= ucontrol
->value
.integer
.value
[1];
329 ret
= snd_soc_put_volsw(kcontrol
, ucontrol
);
333 /* now hit the volume update bits (always bit 8) */
334 val
= snd_soc_component_read32(component
, reg
);
335 snd_soc_component_write(component
, reg
, val
| WM8350_OUT1_VU
);
339 static int wm8350_get_volsw_2r(struct snd_kcontrol
*kcontrol
,
340 struct snd_ctl_elem_value
*ucontrol
)
342 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
343 struct wm8350_data
*wm8350_priv
= snd_soc_component_get_drvdata(component
);
344 struct wm8350_output
*out1
= &wm8350_priv
->out1
;
345 struct wm8350_output
*out2
= &wm8350_priv
->out2
;
346 struct soc_mixer_control
*mc
=
347 (struct soc_mixer_control
*)kcontrol
->private_value
;
348 unsigned int reg
= mc
->reg
;
350 /* If these are cached registers use the cache */
352 case WM8350_LOUT1_VOLUME
:
353 ucontrol
->value
.integer
.value
[0] = out1
->left_vol
;
354 ucontrol
->value
.integer
.value
[1] = out1
->right_vol
;
357 case WM8350_LOUT2_VOLUME
:
358 ucontrol
->value
.integer
.value
[0] = out2
->left_vol
;
359 ucontrol
->value
.integer
.value
[1] = out2
->right_vol
;
366 return snd_soc_get_volsw(kcontrol
, ucontrol
);
369 static const char *wm8350_deemp
[] = { "None", "32kHz", "44.1kHz", "48kHz" };
370 static const char *wm8350_pol
[] = { "Normal", "Inv R", "Inv L", "Inv L & R" };
371 static const char *wm8350_dacmutem
[] = { "Normal", "Soft" };
372 static const char *wm8350_dacmutes
[] = { "Fast", "Slow" };
373 static const char *wm8350_adcfilter
[] = { "None", "High Pass" };
374 static const char *wm8350_adchp
[] = { "44.1kHz", "8kHz", "16kHz", "32kHz" };
375 static const char *wm8350_lr
[] = { "Left", "Right" };
377 static const struct soc_enum wm8350_enum
[] = {
378 SOC_ENUM_SINGLE(WM8350_DAC_CONTROL
, 4, 4, wm8350_deemp
),
379 SOC_ENUM_SINGLE(WM8350_DAC_CONTROL
, 0, 4, wm8350_pol
),
380 SOC_ENUM_SINGLE(WM8350_DAC_MUTE_VOLUME
, 14, 2, wm8350_dacmutem
),
381 SOC_ENUM_SINGLE(WM8350_DAC_MUTE_VOLUME
, 13, 2, wm8350_dacmutes
),
382 SOC_ENUM_SINGLE(WM8350_ADC_CONTROL
, 15, 2, wm8350_adcfilter
),
383 SOC_ENUM_SINGLE(WM8350_ADC_CONTROL
, 8, 4, wm8350_adchp
),
384 SOC_ENUM_SINGLE(WM8350_ADC_CONTROL
, 0, 4, wm8350_pol
),
385 SOC_ENUM_SINGLE(WM8350_INPUT_MIXER_VOLUME
, 15, 2, wm8350_lr
),
388 static DECLARE_TLV_DB_SCALE(pre_amp_tlv
, -1200, 3525, 0);
389 static DECLARE_TLV_DB_SCALE(out_pga_tlv
, -5700, 600, 0);
390 static DECLARE_TLV_DB_SCALE(dac_pcm_tlv
, -7163, 36, 1);
391 static DECLARE_TLV_DB_SCALE(adc_pcm_tlv
, -12700, 50, 1);
392 static DECLARE_TLV_DB_SCALE(out_mix_tlv
, -1500, 300, 1);
394 static const DECLARE_TLV_DB_RANGE(capture_sd_tlv
,
395 0, 12, TLV_DB_SCALE_ITEM(-3600, 300, 1),
396 13, 15, TLV_DB_SCALE_ITEM(0, 0, 0)
399 static const struct snd_kcontrol_new wm8350_snd_controls
[] = {
400 SOC_ENUM("Playback Deemphasis", wm8350_enum
[0]),
401 SOC_ENUM("Playback DAC Inversion", wm8350_enum
[1]),
402 SOC_DOUBLE_R_EXT_TLV("Playback PCM Volume",
403 WM8350_DAC_DIGITAL_VOLUME_L
,
404 WM8350_DAC_DIGITAL_VOLUME_R
,
405 0, 255, 0, wm8350_get_volsw_2r
,
406 wm8350_put_volsw_2r_vu
, dac_pcm_tlv
),
407 SOC_ENUM("Playback PCM Mute Function", wm8350_enum
[2]),
408 SOC_ENUM("Playback PCM Mute Speed", wm8350_enum
[3]),
409 SOC_ENUM("Capture PCM Filter", wm8350_enum
[4]),
410 SOC_ENUM("Capture PCM HP Filter", wm8350_enum
[5]),
411 SOC_ENUM("Capture ADC Inversion", wm8350_enum
[6]),
412 SOC_DOUBLE_R_EXT_TLV("Capture PCM Volume",
413 WM8350_ADC_DIGITAL_VOLUME_L
,
414 WM8350_ADC_DIGITAL_VOLUME_R
,
415 0, 255, 0, wm8350_get_volsw_2r
,
416 wm8350_put_volsw_2r_vu
, adc_pcm_tlv
),
417 SOC_DOUBLE_TLV("Capture Sidetone Volume",
419 8, 4, 15, 1, capture_sd_tlv
),
420 SOC_DOUBLE_R_EXT_TLV("Capture Volume",
421 WM8350_LEFT_INPUT_VOLUME
,
422 WM8350_RIGHT_INPUT_VOLUME
,
423 2, 63, 0, wm8350_get_volsw_2r
,
424 wm8350_put_volsw_2r_vu
, pre_amp_tlv
),
425 SOC_DOUBLE_R("Capture ZC Switch",
426 WM8350_LEFT_INPUT_VOLUME
,
427 WM8350_RIGHT_INPUT_VOLUME
, 13, 1, 0),
428 SOC_SINGLE_TLV("Left Input Left Sidetone Volume",
429 WM8350_OUTPUT_LEFT_MIXER_VOLUME
, 1, 7, 0, out_mix_tlv
),
430 SOC_SINGLE_TLV("Left Input Right Sidetone Volume",
431 WM8350_OUTPUT_LEFT_MIXER_VOLUME
,
432 5, 7, 0, out_mix_tlv
),
433 SOC_SINGLE_TLV("Left Input Bypass Volume",
434 WM8350_OUTPUT_LEFT_MIXER_VOLUME
,
435 9, 7, 0, out_mix_tlv
),
436 SOC_SINGLE_TLV("Right Input Left Sidetone Volume",
437 WM8350_OUTPUT_RIGHT_MIXER_VOLUME
,
438 1, 7, 0, out_mix_tlv
),
439 SOC_SINGLE_TLV("Right Input Right Sidetone Volume",
440 WM8350_OUTPUT_RIGHT_MIXER_VOLUME
,
441 5, 7, 0, out_mix_tlv
),
442 SOC_SINGLE_TLV("Right Input Bypass Volume",
443 WM8350_OUTPUT_RIGHT_MIXER_VOLUME
,
444 13, 7, 0, out_mix_tlv
),
445 SOC_SINGLE("Left Input Mixer +20dB Switch",
446 WM8350_INPUT_MIXER_VOLUME_L
, 0, 1, 0),
447 SOC_SINGLE("Right Input Mixer +20dB Switch",
448 WM8350_INPUT_MIXER_VOLUME_R
, 0, 1, 0),
449 SOC_SINGLE_TLV("Out4 Capture Volume",
450 WM8350_INPUT_MIXER_VOLUME
,
451 1, 7, 0, out_mix_tlv
),
452 SOC_DOUBLE_R_EXT_TLV("Out1 Playback Volume",
455 2, 63, 0, wm8350_get_volsw_2r
,
456 wm8350_put_volsw_2r_vu
, out_pga_tlv
),
457 SOC_DOUBLE_R("Out1 Playback ZC Switch",
459 WM8350_ROUT1_VOLUME
, 13, 1, 0),
460 SOC_DOUBLE_R_EXT_TLV("Out2 Playback Volume",
463 2, 63, 0, wm8350_get_volsw_2r
,
464 wm8350_put_volsw_2r_vu
, out_pga_tlv
),
465 SOC_DOUBLE_R("Out2 Playback ZC Switch", WM8350_LOUT2_VOLUME
,
466 WM8350_ROUT2_VOLUME
, 13, 1, 0),
467 SOC_SINGLE("Out2 Right Invert Switch", WM8350_ROUT2_VOLUME
, 10, 1, 0),
468 SOC_SINGLE_TLV("Out2 Beep Volume", WM8350_BEEP_VOLUME
,
469 5, 7, 0, out_mix_tlv
),
471 SOC_DOUBLE_R("Out1 Playback Switch",
475 SOC_DOUBLE_R("Out2 Playback Switch",
485 /* Left Playback Mixer */
486 static const struct snd_kcontrol_new wm8350_left_play_mixer_controls
[] = {
487 SOC_DAPM_SINGLE("Playback Switch",
488 WM8350_LEFT_MIXER_CONTROL
, 11, 1, 0),
489 SOC_DAPM_SINGLE("Left Bypass Switch",
490 WM8350_LEFT_MIXER_CONTROL
, 2, 1, 0),
491 SOC_DAPM_SINGLE("Right Playback Switch",
492 WM8350_LEFT_MIXER_CONTROL
, 12, 1, 0),
493 SOC_DAPM_SINGLE("Left Sidetone Switch",
494 WM8350_LEFT_MIXER_CONTROL
, 0, 1, 0),
495 SOC_DAPM_SINGLE("Right Sidetone Switch",
496 WM8350_LEFT_MIXER_CONTROL
, 1, 1, 0),
499 /* Right Playback Mixer */
500 static const struct snd_kcontrol_new wm8350_right_play_mixer_controls
[] = {
501 SOC_DAPM_SINGLE("Playback Switch",
502 WM8350_RIGHT_MIXER_CONTROL
, 12, 1, 0),
503 SOC_DAPM_SINGLE("Right Bypass Switch",
504 WM8350_RIGHT_MIXER_CONTROL
, 3, 1, 0),
505 SOC_DAPM_SINGLE("Left Playback Switch",
506 WM8350_RIGHT_MIXER_CONTROL
, 11, 1, 0),
507 SOC_DAPM_SINGLE("Left Sidetone Switch",
508 WM8350_RIGHT_MIXER_CONTROL
, 0, 1, 0),
509 SOC_DAPM_SINGLE("Right Sidetone Switch",
510 WM8350_RIGHT_MIXER_CONTROL
, 1, 1, 0),
514 static const struct snd_kcontrol_new wm8350_out4_mixer_controls
[] = {
515 SOC_DAPM_SINGLE("Right Playback Switch",
516 WM8350_OUT4_MIXER_CONTROL
, 12, 1, 0),
517 SOC_DAPM_SINGLE("Left Playback Switch",
518 WM8350_OUT4_MIXER_CONTROL
, 11, 1, 0),
519 SOC_DAPM_SINGLE("Right Capture Switch",
520 WM8350_OUT4_MIXER_CONTROL
, 9, 1, 0),
521 SOC_DAPM_SINGLE("Out3 Playback Switch",
522 WM8350_OUT4_MIXER_CONTROL
, 2, 1, 0),
523 SOC_DAPM_SINGLE("Right Mixer Switch",
524 WM8350_OUT4_MIXER_CONTROL
, 1, 1, 0),
525 SOC_DAPM_SINGLE("Left Mixer Switch",
526 WM8350_OUT4_MIXER_CONTROL
, 0, 1, 0),
530 static const struct snd_kcontrol_new wm8350_out3_mixer_controls
[] = {
531 SOC_DAPM_SINGLE("Left Playback Switch",
532 WM8350_OUT3_MIXER_CONTROL
, 11, 1, 0),
533 SOC_DAPM_SINGLE("Left Capture Switch",
534 WM8350_OUT3_MIXER_CONTROL
, 8, 1, 0),
535 SOC_DAPM_SINGLE("Out4 Playback Switch",
536 WM8350_OUT3_MIXER_CONTROL
, 3, 1, 0),
537 SOC_DAPM_SINGLE("Left Mixer Switch",
538 WM8350_OUT3_MIXER_CONTROL
, 0, 1, 0),
541 /* Left Input Mixer */
542 static const struct snd_kcontrol_new wm8350_left_capt_mixer_controls
[] = {
543 SOC_DAPM_SINGLE_TLV("L2 Capture Volume",
544 WM8350_INPUT_MIXER_VOLUME_L
, 1, 7, 0, out_mix_tlv
),
545 SOC_DAPM_SINGLE_TLV("L3 Capture Volume",
546 WM8350_INPUT_MIXER_VOLUME_L
, 9, 7, 0, out_mix_tlv
),
547 SOC_DAPM_SINGLE("PGA Capture Switch",
548 WM8350_LEFT_INPUT_VOLUME
, 14, 1, 1),
551 /* Right Input Mixer */
552 static const struct snd_kcontrol_new wm8350_right_capt_mixer_controls
[] = {
553 SOC_DAPM_SINGLE_TLV("L2 Capture Volume",
554 WM8350_INPUT_MIXER_VOLUME_R
, 5, 7, 0, out_mix_tlv
),
555 SOC_DAPM_SINGLE_TLV("L3 Capture Volume",
556 WM8350_INPUT_MIXER_VOLUME_R
, 13, 7, 0, out_mix_tlv
),
557 SOC_DAPM_SINGLE("PGA Capture Switch",
558 WM8350_RIGHT_INPUT_VOLUME
, 14, 1, 1),
562 static const struct snd_kcontrol_new wm8350_left_mic_mixer_controls
[] = {
563 SOC_DAPM_SINGLE("INN Capture Switch", WM8350_INPUT_CONTROL
, 1, 1, 0),
564 SOC_DAPM_SINGLE("INP Capture Switch", WM8350_INPUT_CONTROL
, 0, 1, 0),
565 SOC_DAPM_SINGLE("IN2 Capture Switch", WM8350_INPUT_CONTROL
, 2, 1, 0),
568 /* Right Mic Mixer */
569 static const struct snd_kcontrol_new wm8350_right_mic_mixer_controls
[] = {
570 SOC_DAPM_SINGLE("INN Capture Switch", WM8350_INPUT_CONTROL
, 9, 1, 0),
571 SOC_DAPM_SINGLE("INP Capture Switch", WM8350_INPUT_CONTROL
, 8, 1, 0),
572 SOC_DAPM_SINGLE("IN2 Capture Switch", WM8350_INPUT_CONTROL
, 10, 1, 0),
576 static const struct snd_kcontrol_new wm8350_beep_switch_controls
=
577 SOC_DAPM_SINGLE("Switch", WM8350_BEEP_VOLUME
, 15, 1, 1);
579 /* Out4 Capture Mux */
580 static const struct snd_kcontrol_new wm8350_out4_capture_controls
=
581 SOC_DAPM_ENUM("Route", wm8350_enum
[7]);
583 static const struct snd_soc_dapm_widget wm8350_dapm_widgets
[] = {
585 SND_SOC_DAPM_PGA("IN3R PGA", WM8350_POWER_MGMT_2
, 11, 0, NULL
, 0),
586 SND_SOC_DAPM_PGA("IN3L PGA", WM8350_POWER_MGMT_2
, 10, 0, NULL
, 0),
587 SND_SOC_DAPM_PGA_E("Right Out2 PGA", WM8350_POWER_MGMT_3
, 3, 0, NULL
,
589 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
590 SND_SOC_DAPM_PGA_E("Left Out2 PGA", WM8350_POWER_MGMT_3
, 2, 0, NULL
, 0,
592 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
593 SND_SOC_DAPM_PGA_E("Right Out1 PGA", WM8350_POWER_MGMT_3
, 1, 0, NULL
,
595 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
596 SND_SOC_DAPM_PGA_E("Left Out1 PGA", WM8350_POWER_MGMT_3
, 0, 0, NULL
, 0,
598 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
600 SND_SOC_DAPM_MIXER("Right Capture Mixer", WM8350_POWER_MGMT_2
,
601 7, 0, &wm8350_right_capt_mixer_controls
[0],
602 ARRAY_SIZE(wm8350_right_capt_mixer_controls
)),
604 SND_SOC_DAPM_MIXER("Left Capture Mixer", WM8350_POWER_MGMT_2
,
605 6, 0, &wm8350_left_capt_mixer_controls
[0],
606 ARRAY_SIZE(wm8350_left_capt_mixer_controls
)),
608 SND_SOC_DAPM_MIXER("Out4 Mixer", WM8350_POWER_MGMT_2
, 5, 0,
609 &wm8350_out4_mixer_controls
[0],
610 ARRAY_SIZE(wm8350_out4_mixer_controls
)),
612 SND_SOC_DAPM_MIXER("Out3 Mixer", WM8350_POWER_MGMT_2
, 4, 0,
613 &wm8350_out3_mixer_controls
[0],
614 ARRAY_SIZE(wm8350_out3_mixer_controls
)),
616 SND_SOC_DAPM_MIXER("Right Playback Mixer", WM8350_POWER_MGMT_2
, 1, 0,
617 &wm8350_right_play_mixer_controls
[0],
618 ARRAY_SIZE(wm8350_right_play_mixer_controls
)),
620 SND_SOC_DAPM_MIXER("Left Playback Mixer", WM8350_POWER_MGMT_2
, 0, 0,
621 &wm8350_left_play_mixer_controls
[0],
622 ARRAY_SIZE(wm8350_left_play_mixer_controls
)),
624 SND_SOC_DAPM_MIXER("Left Mic Mixer", WM8350_POWER_MGMT_2
, 8, 0,
625 &wm8350_left_mic_mixer_controls
[0],
626 ARRAY_SIZE(wm8350_left_mic_mixer_controls
)),
628 SND_SOC_DAPM_MIXER("Right Mic Mixer", WM8350_POWER_MGMT_2
, 9, 0,
629 &wm8350_right_mic_mixer_controls
[0],
630 ARRAY_SIZE(wm8350_right_mic_mixer_controls
)),
632 /* virtual mixer for Beep and Out2R */
633 SND_SOC_DAPM_MIXER("Out2 Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
635 SND_SOC_DAPM_SWITCH("Beep", WM8350_POWER_MGMT_3
, 7, 0,
636 &wm8350_beep_switch_controls
),
638 SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
639 WM8350_POWER_MGMT_4
, 3, 0),
640 SND_SOC_DAPM_ADC("Left ADC", "Left Capture",
641 WM8350_POWER_MGMT_4
, 2, 0),
642 SND_SOC_DAPM_DAC("Right DAC", "Right Playback",
643 WM8350_POWER_MGMT_4
, 5, 0),
644 SND_SOC_DAPM_DAC("Left DAC", "Left Playback",
645 WM8350_POWER_MGMT_4
, 4, 0),
647 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8350_POWER_MGMT_1
, 4, 0),
649 SND_SOC_DAPM_MUX("Out4 Capture Channel", SND_SOC_NOPM
, 0, 0,
650 &wm8350_out4_capture_controls
),
652 SND_SOC_DAPM_OUTPUT("OUT1R"),
653 SND_SOC_DAPM_OUTPUT("OUT1L"),
654 SND_SOC_DAPM_OUTPUT("OUT2R"),
655 SND_SOC_DAPM_OUTPUT("OUT2L"),
656 SND_SOC_DAPM_OUTPUT("OUT3"),
657 SND_SOC_DAPM_OUTPUT("OUT4"),
659 SND_SOC_DAPM_INPUT("IN1RN"),
660 SND_SOC_DAPM_INPUT("IN1RP"),
661 SND_SOC_DAPM_INPUT("IN2R"),
662 SND_SOC_DAPM_INPUT("IN1LP"),
663 SND_SOC_DAPM_INPUT("IN1LN"),
664 SND_SOC_DAPM_INPUT("IN2L"),
665 SND_SOC_DAPM_INPUT("IN3R"),
666 SND_SOC_DAPM_INPUT("IN3L"),
669 static const struct snd_soc_dapm_route wm8350_dapm_routes
[] = {
671 /* left playback mixer */
672 {"Left Playback Mixer", "Playback Switch", "Left DAC"},
673 {"Left Playback Mixer", "Left Bypass Switch", "IN3L PGA"},
674 {"Left Playback Mixer", "Right Playback Switch", "Right DAC"},
675 {"Left Playback Mixer", "Left Sidetone Switch", "Left Mic Mixer"},
676 {"Left Playback Mixer", "Right Sidetone Switch", "Right Mic Mixer"},
678 /* right playback mixer */
679 {"Right Playback Mixer", "Playback Switch", "Right DAC"},
680 {"Right Playback Mixer", "Right Bypass Switch", "IN3R PGA"},
681 {"Right Playback Mixer", "Left Playback Switch", "Left DAC"},
682 {"Right Playback Mixer", "Left Sidetone Switch", "Left Mic Mixer"},
683 {"Right Playback Mixer", "Right Sidetone Switch", "Right Mic Mixer"},
685 /* out4 playback mixer */
686 {"Out4 Mixer", "Right Playback Switch", "Right DAC"},
687 {"Out4 Mixer", "Left Playback Switch", "Left DAC"},
688 {"Out4 Mixer", "Right Capture Switch", "Right Capture Mixer"},
689 {"Out4 Mixer", "Out3 Playback Switch", "Out3 Mixer"},
690 {"Out4 Mixer", "Right Mixer Switch", "Right Playback Mixer"},
691 {"Out4 Mixer", "Left Mixer Switch", "Left Playback Mixer"},
692 {"OUT4", NULL
, "Out4 Mixer"},
694 /* out3 playback mixer */
695 {"Out3 Mixer", "Left Playback Switch", "Left DAC"},
696 {"Out3 Mixer", "Left Capture Switch", "Left Capture Mixer"},
697 {"Out3 Mixer", "Left Mixer Switch", "Left Playback Mixer"},
698 {"Out3 Mixer", "Out4 Playback Switch", "Out4 Mixer"},
699 {"OUT3", NULL
, "Out3 Mixer"},
702 {"Right Out2 PGA", NULL
, "Right Playback Mixer"},
703 {"Left Out2 PGA", NULL
, "Left Playback Mixer"},
704 {"OUT2L", NULL
, "Left Out2 PGA"},
705 {"OUT2R", NULL
, "Right Out2 PGA"},
708 {"Right Out1 PGA", NULL
, "Right Playback Mixer"},
709 {"Left Out1 PGA", NULL
, "Left Playback Mixer"},
710 {"OUT1L", NULL
, "Left Out1 PGA"},
711 {"OUT1R", NULL
, "Right Out1 PGA"},
714 {"Left ADC", NULL
, "Left Capture Mixer"},
715 {"Right ADC", NULL
, "Right Capture Mixer"},
717 /* Left capture mixer */
718 {"Left Capture Mixer", "L2 Capture Volume", "IN2L"},
719 {"Left Capture Mixer", "L3 Capture Volume", "IN3L PGA"},
720 {"Left Capture Mixer", "PGA Capture Switch", "Left Mic Mixer"},
721 {"Left Capture Mixer", NULL
, "Out4 Capture Channel"},
723 /* Right capture mixer */
724 {"Right Capture Mixer", "L2 Capture Volume", "IN2R"},
725 {"Right Capture Mixer", "L3 Capture Volume", "IN3R PGA"},
726 {"Right Capture Mixer", "PGA Capture Switch", "Right Mic Mixer"},
727 {"Right Capture Mixer", NULL
, "Out4 Capture Channel"},
730 {"IN3L PGA", NULL
, "IN3L"},
731 {"IN3R PGA", NULL
, "IN3R"},
734 {"Left Mic Mixer", "INN Capture Switch", "IN1LN"},
735 {"Left Mic Mixer", "INP Capture Switch", "IN1LP"},
736 {"Left Mic Mixer", "IN2 Capture Switch", "IN2L"},
738 /* Right Mic mixer */
739 {"Right Mic Mixer", "INN Capture Switch", "IN1RN"},
740 {"Right Mic Mixer", "INP Capture Switch", "IN1RP"},
741 {"Right Mic Mixer", "IN2 Capture Switch", "IN2R"},
744 {"Out4 Capture Channel", NULL
, "Out4 Mixer"},
747 {"Beep", NULL
, "IN3R PGA"},
750 static int wm8350_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
751 int clk_id
, unsigned int freq
, int dir
)
753 struct snd_soc_component
*component
= codec_dai
->component
;
754 struct wm8350_data
*wm8350_data
= snd_soc_component_get_drvdata(component
);
755 struct wm8350
*wm8350
= wm8350_data
->wm8350
;
759 case WM8350_MCLK_SEL_MCLK
:
760 wm8350_clear_bits(wm8350
, WM8350_CLOCK_CONTROL_1
,
763 case WM8350_MCLK_SEL_PLL_MCLK
:
764 case WM8350_MCLK_SEL_PLL_DAC
:
765 case WM8350_MCLK_SEL_PLL_ADC
:
766 case WM8350_MCLK_SEL_PLL_32K
:
767 wm8350_set_bits(wm8350
, WM8350_CLOCK_CONTROL_1
,
769 fll_4
= snd_soc_component_read32(component
, WM8350_FLL_CONTROL_4
) &
770 ~WM8350_FLL_CLK_SRC_MASK
;
771 snd_soc_component_write(component
, WM8350_FLL_CONTROL_4
, fll_4
| clk_id
);
776 if (dir
== SND_SOC_CLOCK_OUT
)
777 wm8350_set_bits(wm8350
, WM8350_CLOCK_CONTROL_2
,
780 wm8350_clear_bits(wm8350
, WM8350_CLOCK_CONTROL_2
,
786 static int wm8350_set_clkdiv(struct snd_soc_dai
*codec_dai
, int div_id
, int div
)
788 struct snd_soc_component
*component
= codec_dai
->component
;
792 case WM8350_ADC_CLKDIV
:
793 val
= snd_soc_component_read32(component
, WM8350_ADC_DIVIDER
) &
794 ~WM8350_ADC_CLKDIV_MASK
;
795 snd_soc_component_write(component
, WM8350_ADC_DIVIDER
, val
| div
);
797 case WM8350_DAC_CLKDIV
:
798 val
= snd_soc_component_read32(component
, WM8350_DAC_CLOCK_CONTROL
) &
799 ~WM8350_DAC_CLKDIV_MASK
;
800 snd_soc_component_write(component
, WM8350_DAC_CLOCK_CONTROL
, val
| div
);
802 case WM8350_BCLK_CLKDIV
:
803 val
= snd_soc_component_read32(component
, WM8350_CLOCK_CONTROL_1
) &
804 ~WM8350_BCLK_DIV_MASK
;
805 snd_soc_component_write(component
, WM8350_CLOCK_CONTROL_1
, val
| div
);
807 case WM8350_OPCLK_CLKDIV
:
808 val
= snd_soc_component_read32(component
, WM8350_CLOCK_CONTROL_1
) &
809 ~WM8350_OPCLK_DIV_MASK
;
810 snd_soc_component_write(component
, WM8350_CLOCK_CONTROL_1
, val
| div
);
812 case WM8350_SYS_CLKDIV
:
813 val
= snd_soc_component_read32(component
, WM8350_CLOCK_CONTROL_1
) &
814 ~WM8350_MCLK_DIV_MASK
;
815 snd_soc_component_write(component
, WM8350_CLOCK_CONTROL_1
, val
| div
);
817 case WM8350_DACLR_CLKDIV
:
818 val
= snd_soc_component_read32(component
, WM8350_DAC_LR_RATE
) &
819 ~WM8350_DACLRC_RATE_MASK
;
820 snd_soc_component_write(component
, WM8350_DAC_LR_RATE
, val
| div
);
822 case WM8350_ADCLR_CLKDIV
:
823 val
= snd_soc_component_read32(component
, WM8350_ADC_LR_RATE
) &
824 ~WM8350_ADCLRC_RATE_MASK
;
825 snd_soc_component_write(component
, WM8350_ADC_LR_RATE
, val
| div
);
834 static int wm8350_set_dai_fmt(struct snd_soc_dai
*codec_dai
, unsigned int fmt
)
836 struct snd_soc_component
*component
= codec_dai
->component
;
837 u16 iface
= snd_soc_component_read32(component
, WM8350_AI_FORMATING
) &
838 ~(WM8350_AIF_BCLK_INV
| WM8350_AIF_LRCLK_INV
| WM8350_AIF_FMT_MASK
);
839 u16 master
= snd_soc_component_read32(component
, WM8350_AI_DAC_CONTROL
) &
841 u16 dac_lrc
= snd_soc_component_read32(component
, WM8350_DAC_LR_RATE
) &
843 u16 adc_lrc
= snd_soc_component_read32(component
, WM8350_ADC_LR_RATE
) &
846 /* set master/slave audio interface */
847 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
848 case SND_SOC_DAIFMT_CBM_CFM
:
849 master
|= WM8350_BCLK_MSTR
;
850 dac_lrc
|= WM8350_DACLRC_ENA
;
851 adc_lrc
|= WM8350_ADCLRC_ENA
;
853 case SND_SOC_DAIFMT_CBS_CFS
:
859 /* interface format */
860 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
861 case SND_SOC_DAIFMT_I2S
:
864 case SND_SOC_DAIFMT_RIGHT_J
:
866 case SND_SOC_DAIFMT_LEFT_J
:
869 case SND_SOC_DAIFMT_DSP_A
:
872 case SND_SOC_DAIFMT_DSP_B
:
873 iface
|= 0x3 << 8 | WM8350_AIF_LRCLK_INV
;
879 /* clock inversion */
880 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
881 case SND_SOC_DAIFMT_NB_NF
:
883 case SND_SOC_DAIFMT_IB_IF
:
884 iface
|= WM8350_AIF_LRCLK_INV
| WM8350_AIF_BCLK_INV
;
886 case SND_SOC_DAIFMT_IB_NF
:
887 iface
|= WM8350_AIF_BCLK_INV
;
889 case SND_SOC_DAIFMT_NB_IF
:
890 iface
|= WM8350_AIF_LRCLK_INV
;
896 snd_soc_component_write(component
, WM8350_AI_FORMATING
, iface
);
897 snd_soc_component_write(component
, WM8350_AI_DAC_CONTROL
, master
);
898 snd_soc_component_write(component
, WM8350_DAC_LR_RATE
, dac_lrc
);
899 snd_soc_component_write(component
, WM8350_ADC_LR_RATE
, adc_lrc
);
903 static int wm8350_pcm_hw_params(struct snd_pcm_substream
*substream
,
904 struct snd_pcm_hw_params
*params
,
905 struct snd_soc_dai
*codec_dai
)
907 struct snd_soc_component
*component
= codec_dai
->component
;
908 struct wm8350_data
*wm8350_data
= snd_soc_component_get_drvdata(component
);
909 struct wm8350
*wm8350
= wm8350_data
->wm8350
;
910 u16 iface
= snd_soc_component_read32(component
, WM8350_AI_FORMATING
) &
914 switch (params_width(params
)) {
928 snd_soc_component_write(component
, WM8350_AI_FORMATING
, iface
);
930 /* The sloping stopband filter is recommended for use with
931 * lower sample rates to improve performance.
933 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
934 if (params_rate(params
) < 24000)
935 wm8350_set_bits(wm8350
, WM8350_DAC_MUTE_VOLUME
,
938 wm8350_clear_bits(wm8350
, WM8350_DAC_MUTE_VOLUME
,
945 static int wm8350_mute(struct snd_soc_dai
*dai
, int mute
)
947 struct snd_soc_component
*component
= dai
->component
;
951 val
= WM8350_DAC_MUTE_ENA
;
955 snd_soc_component_update_bits(component
, WM8350_DAC_MUTE
, WM8350_DAC_MUTE_ENA
, val
);
962 int div
; /* FLL_OUTDIV */
965 int ratio
; /* FLL_FRATIO */
968 /* The size in bits of the fll divide multiplied by 10
969 * to allow rounding later */
970 #define FIXED_FLL_SIZE ((1 << 16) * 10)
972 static inline int fll_factors(struct _fll_div
*fll_div
, unsigned int input
,
976 unsigned int t1
, t2
, K
, Nmod
;
978 if (output
>= 2815250 && output
<= 3125000)
980 else if (output
>= 5625000 && output
<= 6250000)
982 else if (output
>= 11250000 && output
<= 12500000)
984 else if (output
>= 22500000 && output
<= 25000000)
987 printk(KERN_ERR
"wm8350: fll freq %d out of range\n", output
);
996 t1
= output
* (1 << (fll_div
->div
+ 1));
997 t2
= input
* fll_div
->ratio
;
999 fll_div
->n
= t1
/ t2
;
1003 Kpart
= FIXED_FLL_SIZE
* (long long)Nmod
;
1005 K
= Kpart
& 0xFFFFFFFF;
1007 /* Check if we need to round */
1011 /* Move down to proper range now rounding is done */
1020 static int wm8350_set_fll(struct snd_soc_dai
*codec_dai
,
1021 int pll_id
, int source
, unsigned int freq_in
,
1022 unsigned int freq_out
)
1024 struct snd_soc_component
*component
= codec_dai
->component
;
1025 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1026 struct wm8350
*wm8350
= priv
->wm8350
;
1027 struct _fll_div fll_div
;
1031 if (freq_in
== priv
->fll_freq_in
&& freq_out
== priv
->fll_freq_out
)
1034 /* power down FLL - we need to do this for reconfiguration */
1035 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_4
,
1036 WM8350_FLL_ENA
| WM8350_FLL_OSC_ENA
);
1038 if (freq_out
== 0 || freq_in
== 0)
1041 ret
= fll_factors(&fll_div
, freq_in
, freq_out
);
1044 dev_dbg(wm8350
->dev
,
1045 "FLL in %u FLL out %u N 0x%x K 0x%x div %d ratio %d",
1046 freq_in
, freq_out
, fll_div
.n
, fll_div
.k
, fll_div
.div
,
1049 /* set up N.K & dividers */
1050 fll_1
= snd_soc_component_read32(component
, WM8350_FLL_CONTROL_1
) &
1051 ~(WM8350_FLL_OUTDIV_MASK
| WM8350_FLL_RSP_RATE_MASK
| 0xc000);
1052 snd_soc_component_write(component
, WM8350_FLL_CONTROL_1
,
1053 fll_1
| (fll_div
.div
<< 8) | 0x50);
1054 snd_soc_component_write(component
, WM8350_FLL_CONTROL_2
,
1055 (fll_div
.ratio
<< 11) | (fll_div
.
1056 n
& WM8350_FLL_N_MASK
));
1057 snd_soc_component_write(component
, WM8350_FLL_CONTROL_3
, fll_div
.k
);
1058 fll_4
= snd_soc_component_read32(component
, WM8350_FLL_CONTROL_4
) &
1059 ~(WM8350_FLL_FRAC
| WM8350_FLL_SLOW_LOCK_REF
);
1060 snd_soc_component_write(component
, WM8350_FLL_CONTROL_4
,
1061 fll_4
| (fll_div
.k
? WM8350_FLL_FRAC
: 0) |
1062 (fll_div
.ratio
== 8 ? WM8350_FLL_SLOW_LOCK_REF
: 0));
1065 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_FLL_OSC_ENA
);
1066 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_FLL_ENA
);
1068 priv
->fll_freq_out
= freq_out
;
1069 priv
->fll_freq_in
= freq_in
;
1074 static int wm8350_set_bias_level(struct snd_soc_component
*component
,
1075 enum snd_soc_bias_level level
)
1077 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1078 struct wm8350
*wm8350
= priv
->wm8350
;
1079 struct wm8350_audio_platform_data
*platform
=
1080 wm8350
->codec
.platform_data
;
1085 case SND_SOC_BIAS_ON
:
1086 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1087 ~(WM8350_VMID_MASK
| WM8350_CODEC_ISEL_MASK
);
1088 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1089 pm1
| WM8350_VMID_50K
|
1090 platform
->codec_current_on
<< 14);
1093 case SND_SOC_BIAS_PREPARE
:
1094 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
);
1095 pm1
&= ~WM8350_VMID_MASK
;
1096 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1097 pm1
| WM8350_VMID_50K
);
1100 case SND_SOC_BIAS_STANDBY
:
1101 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
1102 ret
= regulator_bulk_enable(ARRAY_SIZE(priv
->supplies
),
1107 /* Enable the system clock */
1108 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
,
1111 /* mute DAC & outputs */
1112 wm8350_set_bits(wm8350
, WM8350_DAC_MUTE
,
1113 WM8350_DAC_MUTE_ENA
);
1115 /* discharge cap memory */
1116 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1117 platform
->dis_out1
|
1118 (platform
->dis_out2
<< 2) |
1119 (platform
->dis_out3
<< 4) |
1120 (platform
->dis_out4
<< 6));
1122 /* wait for discharge */
1123 schedule_timeout_interruptible(msecs_to_jiffies
1125 cap_discharge_msecs
));
1127 /* enable antipop */
1128 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1129 (platform
->vmid_s_curve
<< 8));
1132 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1134 codec_current_charge
<< 14) |
1135 WM8350_VMID_5K
| WM8350_VMIDEN
|
1139 schedule_timeout_interruptible(msecs_to_jiffies
1141 vmid_charge_msecs
));
1143 /* turn on vmid 300k */
1144 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1145 ~(WM8350_VMID_MASK
| WM8350_CODEC_ISEL_MASK
);
1146 pm1
|= WM8350_VMID_300K
|
1147 (platform
->codec_current_standby
<< 14);
1148 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1152 /* enable analogue bias */
1153 pm1
|= WM8350_BIASEN
;
1154 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
, pm1
);
1156 /* disable antipop */
1157 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
, 0);
1160 /* turn on vmid 300k and reduce current */
1161 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1162 ~(WM8350_VMID_MASK
| WM8350_CODEC_ISEL_MASK
);
1163 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1164 pm1
| WM8350_VMID_300K
|
1166 codec_current_standby
<< 14));
1171 case SND_SOC_BIAS_OFF
:
1173 /* mute DAC & enable outputs */
1174 wm8350_set_bits(wm8350
, WM8350_DAC_MUTE
, WM8350_DAC_MUTE_ENA
);
1176 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_3
,
1177 WM8350_OUT1L_ENA
| WM8350_OUT1R_ENA
|
1178 WM8350_OUT2L_ENA
| WM8350_OUT2R_ENA
);
1180 /* enable anti pop S curve */
1181 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1182 (platform
->vmid_s_curve
<< 8));
1185 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1187 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
, pm1
);
1190 schedule_timeout_interruptible(msecs_to_jiffies
1192 vmid_discharge_msecs
));
1194 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
,
1195 (platform
->vmid_s_curve
<< 8) |
1196 platform
->dis_out1
|
1197 (platform
->dis_out2
<< 2) |
1198 (platform
->dis_out3
<< 4) |
1199 (platform
->dis_out4
<< 6));
1201 /* turn off VBuf and drain */
1202 pm1
= wm8350_reg_read(wm8350
, WM8350_POWER_MGMT_1
) &
1203 ~(WM8350_VBUFEN
| WM8350_VMID_MASK
);
1204 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
,
1205 pm1
| WM8350_OUTPUT_DRAIN_EN
);
1208 schedule_timeout_interruptible(msecs_to_jiffies
1209 (platform
->drain_msecs
));
1211 pm1
&= ~WM8350_BIASEN
;
1212 wm8350_reg_write(wm8350
, WM8350_POWER_MGMT_1
, pm1
);
1214 /* disable anti-pop */
1215 wm8350_reg_write(wm8350
, WM8350_ANTI_POP_CONTROL
, 0);
1217 wm8350_clear_bits(wm8350
, WM8350_LOUT1_VOLUME
,
1219 wm8350_clear_bits(wm8350
, WM8350_ROUT1_VOLUME
,
1221 wm8350_clear_bits(wm8350
, WM8350_LOUT2_VOLUME
,
1223 wm8350_clear_bits(wm8350
, WM8350_ROUT2_VOLUME
,
1226 /* disable clock gen */
1227 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_4
,
1230 regulator_bulk_disable(ARRAY_SIZE(priv
->supplies
),
1237 static void wm8350_hp_work(struct wm8350_data
*priv
,
1238 struct wm8350_jack_data
*jack
,
1241 struct wm8350
*wm8350
= priv
->wm8350
;
1245 reg
= wm8350_reg_read(wm8350
, WM8350_JACK_PIN_STATUS
);
1247 report
= jack
->report
;
1251 snd_soc_jack_report(jack
->jack
, report
, jack
->report
);
1255 static void wm8350_hpl_work(struct work_struct
*work
)
1257 struct wm8350_data
*priv
=
1258 container_of(work
, struct wm8350_data
, hpl
.work
.work
);
1260 wm8350_hp_work(priv
, &priv
->hpl
, WM8350_JACK_L_LVL
);
1263 static void wm8350_hpr_work(struct work_struct
*work
)
1265 struct wm8350_data
*priv
=
1266 container_of(work
, struct wm8350_data
, hpr
.work
.work
);
1268 wm8350_hp_work(priv
, &priv
->hpr
, WM8350_JACK_R_LVL
);
1271 static irqreturn_t
wm8350_hpl_jack_handler(int irq
, void *data
)
1273 struct wm8350_data
*priv
= data
;
1274 struct wm8350
*wm8350
= priv
->wm8350
;
1276 #ifndef CONFIG_SND_SOC_WM8350_MODULE
1277 trace_snd_soc_jack_irq("WM8350 HPL");
1280 if (device_may_wakeup(wm8350
->dev
))
1281 pm_wakeup_event(wm8350
->dev
, 250);
1283 queue_delayed_work(system_power_efficient_wq
,
1284 &priv
->hpl
.work
, msecs_to_jiffies(200));
1289 static irqreturn_t
wm8350_hpr_jack_handler(int irq
, void *data
)
1291 struct wm8350_data
*priv
= data
;
1292 struct wm8350
*wm8350
= priv
->wm8350
;
1294 #ifndef CONFIG_SND_SOC_WM8350_MODULE
1295 trace_snd_soc_jack_irq("WM8350 HPR");
1298 if (device_may_wakeup(wm8350
->dev
))
1299 pm_wakeup_event(wm8350
->dev
, 250);
1301 queue_delayed_work(system_power_efficient_wq
,
1302 &priv
->hpr
.work
, msecs_to_jiffies(200));
1308 * wm8350_hp_jack_detect - Enable headphone jack detection.
1310 * @component: WM8350 component
1311 * @which: left or right jack detect signal
1312 * @jack: jack to report detection events on
1313 * @report: value to report
1315 * Enables the headphone jack detection of the WM8350. If no report
1316 * is specified then detection is disabled.
1318 int wm8350_hp_jack_detect(struct snd_soc_component
*component
, enum wm8350_jack which
,
1319 struct snd_soc_jack
*jack
, int report
)
1321 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1322 struct wm8350
*wm8350
= priv
->wm8350
;
1327 priv
->hpl
.jack
= jack
;
1328 priv
->hpl
.report
= report
;
1329 ena
= WM8350_JDL_ENA
;
1333 priv
->hpr
.jack
= jack
;
1334 priv
->hpr
.report
= report
;
1335 ena
= WM8350_JDR_ENA
;
1343 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_TOCLK_ENA
);
1344 wm8350_set_bits(wm8350
, WM8350_JACK_DETECT
, ena
);
1346 wm8350_clear_bits(wm8350
, WM8350_JACK_DETECT
, ena
);
1352 wm8350_hpl_jack_handler(0, priv
);
1355 wm8350_hpr_jack_handler(0, priv
);
1361 EXPORT_SYMBOL_GPL(wm8350_hp_jack_detect
);
1363 static irqreturn_t
wm8350_mic_handler(int irq
, void *data
)
1365 struct wm8350_data
*priv
= data
;
1366 struct wm8350
*wm8350
= priv
->wm8350
;
1370 #ifndef CONFIG_SND_SOC_WM8350_MODULE
1371 trace_snd_soc_jack_irq("WM8350 mic");
1374 reg
= wm8350_reg_read(wm8350
, WM8350_JACK_PIN_STATUS
);
1375 if (reg
& WM8350_JACK_MICSCD_LVL
)
1376 report
|= priv
->mic
.short_report
;
1377 if (reg
& WM8350_JACK_MICSD_LVL
)
1378 report
|= priv
->mic
.report
;
1380 snd_soc_jack_report(priv
->mic
.jack
, report
,
1381 priv
->mic
.report
| priv
->mic
.short_report
);
1387 * wm8350_mic_jack_detect - Enable microphone jack detection.
1389 * @component: WM8350 component
1390 * @jack: jack to report detection events on
1391 * @detect_report: value to report when presence detected
1392 * @short_report: value to report when microphone short detected
1394 * Enables the microphone jack detection of the WM8350. If both reports
1395 * are specified as zero then detection is disabled.
1397 int wm8350_mic_jack_detect(struct snd_soc_component
*component
,
1398 struct snd_soc_jack
*jack
,
1399 int detect_report
, int short_report
)
1401 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1402 struct wm8350
*wm8350
= priv
->wm8350
;
1404 priv
->mic
.jack
= jack
;
1405 priv
->mic
.report
= detect_report
;
1406 priv
->mic
.short_report
= short_report
;
1408 if (detect_report
|| short_report
) {
1409 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_TOCLK_ENA
);
1410 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_1
,
1411 WM8350_MIC_DET_ENA
);
1413 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_1
,
1414 WM8350_MIC_DET_ENA
);
1419 EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect
);
1421 #define WM8350_RATES (SNDRV_PCM_RATE_8000_96000)
1423 #define WM8350_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
1424 SNDRV_PCM_FMTBIT_S20_3LE |\
1425 SNDRV_PCM_FMTBIT_S24_LE)
1427 static const struct snd_soc_dai_ops wm8350_dai_ops
= {
1428 .hw_params
= wm8350_pcm_hw_params
,
1429 .digital_mute
= wm8350_mute
,
1430 .set_fmt
= wm8350_set_dai_fmt
,
1431 .set_sysclk
= wm8350_set_dai_sysclk
,
1432 .set_pll
= wm8350_set_fll
,
1433 .set_clkdiv
= wm8350_set_clkdiv
,
1436 static struct snd_soc_dai_driver wm8350_dai
= {
1437 .name
= "wm8350-hifi",
1439 .stream_name
= "Playback",
1442 .rates
= WM8350_RATES
,
1443 .formats
= WM8350_FORMATS
,
1446 .stream_name
= "Capture",
1449 .rates
= WM8350_RATES
,
1450 .formats
= WM8350_FORMATS
,
1452 .ops
= &wm8350_dai_ops
,
1455 static int wm8350_component_probe(struct snd_soc_component
*component
)
1457 struct wm8350
*wm8350
= dev_get_platdata(component
->dev
);
1458 struct wm8350_data
*priv
;
1459 struct wm8350_output
*out1
;
1460 struct wm8350_output
*out2
;
1463 if (wm8350
->codec
.platform_data
== NULL
) {
1464 dev_err(component
->dev
, "No audio platform data supplied\n");
1468 priv
= devm_kzalloc(component
->dev
, sizeof(struct wm8350_data
),
1473 snd_soc_component_init_regmap(component
, wm8350
->regmap
);
1474 snd_soc_component_set_drvdata(component
, priv
);
1476 priv
->wm8350
= wm8350
;
1478 for (i
= 0; i
< ARRAY_SIZE(supply_names
); i
++)
1479 priv
->supplies
[i
].supply
= supply_names
[i
];
1481 ret
= devm_regulator_bulk_get(wm8350
->dev
, ARRAY_SIZE(priv
->supplies
),
1486 /* Put the codec into reset if it wasn't already */
1487 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_5
, WM8350_CODEC_ENA
);
1489 INIT_DELAYED_WORK(&priv
->pga_work
, wm8350_pga_work
);
1490 INIT_DELAYED_WORK(&priv
->hpl
.work
, wm8350_hpl_work
);
1491 INIT_DELAYED_WORK(&priv
->hpr
.work
, wm8350_hpr_work
);
1493 /* Enable the codec */
1494 wm8350_set_bits(wm8350
, WM8350_POWER_MGMT_5
, WM8350_CODEC_ENA
);
1496 /* Enable robust clocking mode in ADC */
1497 snd_soc_component_write(component
, WM8350_SECURITY
, 0xa7);
1498 snd_soc_component_write(component
, 0xde, 0x13);
1499 snd_soc_component_write(component
, WM8350_SECURITY
, 0);
1501 /* read OUT1 & OUT2 volumes */
1504 out1
->left_vol
= (wm8350_reg_read(wm8350
, WM8350_LOUT1_VOLUME
) &
1505 WM8350_OUT1L_VOL_MASK
) >> WM8350_OUT1L_VOL_SHIFT
;
1506 out1
->right_vol
= (wm8350_reg_read(wm8350
, WM8350_ROUT1_VOLUME
) &
1507 WM8350_OUT1R_VOL_MASK
) >> WM8350_OUT1R_VOL_SHIFT
;
1508 out2
->left_vol
= (wm8350_reg_read(wm8350
, WM8350_LOUT2_VOLUME
) &
1509 WM8350_OUT2L_VOL_MASK
) >> WM8350_OUT1L_VOL_SHIFT
;
1510 out2
->right_vol
= (wm8350_reg_read(wm8350
, WM8350_ROUT2_VOLUME
) &
1511 WM8350_OUT2R_VOL_MASK
) >> WM8350_OUT1R_VOL_SHIFT
;
1512 wm8350_reg_write(wm8350
, WM8350_LOUT1_VOLUME
, 0);
1513 wm8350_reg_write(wm8350
, WM8350_ROUT1_VOLUME
, 0);
1514 wm8350_reg_write(wm8350
, WM8350_LOUT2_VOLUME
, 0);
1515 wm8350_reg_write(wm8350
, WM8350_ROUT2_VOLUME
, 0);
1517 /* Latch VU bits & mute */
1518 wm8350_set_bits(wm8350
, WM8350_LOUT1_VOLUME
,
1519 WM8350_OUT1_VU
| WM8350_OUT1L_MUTE
);
1520 wm8350_set_bits(wm8350
, WM8350_LOUT2_VOLUME
,
1521 WM8350_OUT2_VU
| WM8350_OUT2L_MUTE
);
1522 wm8350_set_bits(wm8350
, WM8350_ROUT1_VOLUME
,
1523 WM8350_OUT1_VU
| WM8350_OUT1R_MUTE
);
1524 wm8350_set_bits(wm8350
, WM8350_ROUT2_VOLUME
,
1525 WM8350_OUT2_VU
| WM8350_OUT2R_MUTE
);
1527 /* Make sure AIF tristating is disabled by default */
1528 wm8350_clear_bits(wm8350
, WM8350_AI_FORMATING
, WM8350_AIF_TRI
);
1530 /* Make sure we've got a sane companding setup too */
1531 wm8350_clear_bits(wm8350
, WM8350_ADC_DAC_COMP
,
1532 WM8350_DAC_COMP
| WM8350_LOOPBACK
);
1534 /* Make sure jack detect is disabled to start off with */
1535 wm8350_clear_bits(wm8350
, WM8350_JACK_DETECT
,
1536 WM8350_JDL_ENA
| WM8350_JDR_ENA
);
1538 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_L
,
1539 wm8350_hpl_jack_handler
, 0, "Left jack detect",
1541 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_R
,
1542 wm8350_hpr_jack_handler
, 0, "Right jack detect",
1544 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_MICSCD
,
1545 wm8350_mic_handler
, 0, "Microphone short", priv
);
1546 wm8350_register_irq(wm8350
, WM8350_IRQ_CODEC_MICD
,
1547 wm8350_mic_handler
, 0, "Microphone detect", priv
);
1552 static void wm8350_component_remove(struct snd_soc_component
*component
)
1554 struct wm8350_data
*priv
= snd_soc_component_get_drvdata(component
);
1555 struct wm8350
*wm8350
= dev_get_platdata(component
->dev
);
1557 wm8350_clear_bits(wm8350
, WM8350_JACK_DETECT
,
1558 WM8350_JDL_ENA
| WM8350_JDR_ENA
);
1559 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_4
, WM8350_TOCLK_ENA
);
1561 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_MICD
, priv
);
1562 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_MICSCD
, priv
);
1563 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_L
, priv
);
1564 wm8350_free_irq(wm8350
, WM8350_IRQ_CODEC_JCK_DET_R
, priv
);
1566 priv
->hpl
.jack
= NULL
;
1567 priv
->hpr
.jack
= NULL
;
1568 priv
->mic
.jack
= NULL
;
1570 cancel_delayed_work_sync(&priv
->hpl
.work
);
1571 cancel_delayed_work_sync(&priv
->hpr
.work
);
1573 /* if there was any work waiting then we run it now and
1574 * wait for its completion */
1575 flush_delayed_work(&priv
->pga_work
);
1577 wm8350_clear_bits(wm8350
, WM8350_POWER_MGMT_5
, WM8350_CODEC_ENA
);
1580 static const struct snd_soc_component_driver soc_component_dev_wm8350
= {
1581 .probe
= wm8350_component_probe
,
1582 .remove
= wm8350_component_remove
,
1583 .set_bias_level
= wm8350_set_bias_level
,
1584 .controls
= wm8350_snd_controls
,
1585 .num_controls
= ARRAY_SIZE(wm8350_snd_controls
),
1586 .dapm_widgets
= wm8350_dapm_widgets
,
1587 .num_dapm_widgets
= ARRAY_SIZE(wm8350_dapm_widgets
),
1588 .dapm_routes
= wm8350_dapm_routes
,
1589 .num_dapm_routes
= ARRAY_SIZE(wm8350_dapm_routes
),
1590 .suspend_bias_off
= 1,
1592 .use_pmdown_time
= 1,
1594 .non_legacy_dai_naming
= 1,
1597 static int wm8350_probe(struct platform_device
*pdev
)
1599 return devm_snd_soc_register_component(&pdev
->dev
,
1600 &soc_component_dev_wm8350
,
1604 static struct platform_driver wm8350_codec_driver
= {
1606 .name
= "wm8350-codec",
1608 .probe
= wm8350_probe
,
1611 module_platform_driver(wm8350_codec_driver
);
1613 MODULE_DESCRIPTION("ASoC WM8350 driver");
1614 MODULE_AUTHOR("Liam Girdwood");
1615 MODULE_LICENSE("GPL");
1616 MODULE_ALIAS("platform:wm8350-codec");