2 * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 * o Changes power status of internal codec blocks depending on the
14 * dynamic configuration of codec internal audio paths and active
16 * o Platform power domain - can support external components i.e. amps and
17 * mic/meadphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
21 * o Delayed powerdown of audio susbsystem to reduce pops between a quick
25 * o DAPM power change sequencing - allow for configurable per
27 * o Support for analogue bias optimisation.
28 * o Support for reduced codec oversampling rates.
29 * o Support for reduced codec bias currents.
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/init.h>
35 #include <linux/delay.h>
37 #include <linux/bitops.h>
38 #include <linux/platform_device.h>
39 #include <linux/jiffies.h>
40 #include <sound/core.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc-dapm.h>
44 #include <sound/initval.h>
48 #define dump_dapm(codec, action) dbg_dump_dapm(codec, action)
50 #define dump_dapm(codec, action)
53 /* dapm power sequences - make this per codec in the future */
54 static int dapm_up_seq
[] = {
55 snd_soc_dapm_pre
, snd_soc_dapm_supply
, snd_soc_dapm_micbias
,
56 snd_soc_dapm_mic
, snd_soc_dapm_mux
, snd_soc_dapm_value_mux
,
57 snd_soc_dapm_dac
, snd_soc_dapm_mixer
, snd_soc_dapm_mixer_named_ctl
,
58 snd_soc_dapm_pga
, snd_soc_dapm_adc
, snd_soc_dapm_hp
, snd_soc_dapm_spk
,
62 static int dapm_down_seq
[] = {
63 snd_soc_dapm_pre
, snd_soc_dapm_adc
, snd_soc_dapm_hp
, snd_soc_dapm_spk
,
64 snd_soc_dapm_pga
, snd_soc_dapm_mixer_named_ctl
, snd_soc_dapm_mixer
,
65 snd_soc_dapm_dac
, snd_soc_dapm_mic
, snd_soc_dapm_micbias
,
66 snd_soc_dapm_mux
, snd_soc_dapm_value_mux
, snd_soc_dapm_supply
,
70 static void pop_wait(u32 pop_time
)
73 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
76 static void pop_dbg(u32 pop_time
, const char *fmt
, ...)
90 /* create a new dapm widget */
91 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
92 const struct snd_soc_dapm_widget
*_widget
)
94 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
98 * snd_soc_dapm_set_bias_level - set the bias level for the system
99 * @socdev: audio device
100 * @level: level to configure
102 * Configure the bias (power) levels for the SoC audio device.
104 * Returns 0 for success else error.
106 static int snd_soc_dapm_set_bias_level(struct snd_soc_device
*socdev
,
107 enum snd_soc_bias_level level
)
109 struct snd_soc_card
*card
= socdev
->card
;
110 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
114 case SND_SOC_BIAS_ON
:
115 dev_dbg(socdev
->dev
, "Setting full bias\n");
117 case SND_SOC_BIAS_PREPARE
:
118 dev_dbg(socdev
->dev
, "Setting bias prepare\n");
120 case SND_SOC_BIAS_STANDBY
:
121 dev_dbg(socdev
->dev
, "Setting standby bias\n");
123 case SND_SOC_BIAS_OFF
:
124 dev_dbg(socdev
->dev
, "Setting bias off\n");
127 dev_err(socdev
->dev
, "Setting invalid bias %d\n", level
);
131 if (card
->set_bias_level
)
132 ret
= card
->set_bias_level(card
, level
);
133 if (ret
== 0 && codec
->set_bias_level
)
134 ret
= codec
->set_bias_level(codec
, level
);
139 /* set up initial codec paths */
140 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
141 struct snd_soc_dapm_path
*p
, int i
)
144 case snd_soc_dapm_switch
:
145 case snd_soc_dapm_mixer
:
146 case snd_soc_dapm_mixer_named_ctl
: {
148 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
149 w
->kcontrols
[i
].private_value
;
150 unsigned int reg
= mc
->reg
;
151 unsigned int shift
= mc
->shift
;
153 unsigned int mask
= (1 << fls(max
)) - 1;
154 unsigned int invert
= mc
->invert
;
156 val
= snd_soc_read(w
->codec
, reg
);
157 val
= (val
>> shift
) & mask
;
159 if ((invert
&& !val
) || (!invert
&& val
))
165 case snd_soc_dapm_mux
: {
166 struct soc_enum
*e
= (struct soc_enum
*)w
->kcontrols
[i
].private_value
;
167 int val
, item
, bitmask
;
169 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
171 val
= snd_soc_read(w
->codec
, e
->reg
);
172 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
175 for (i
= 0; i
< e
->max
; i
++) {
176 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
181 case snd_soc_dapm_value_mux
: {
182 struct soc_enum
*e
= (struct soc_enum
*)
183 w
->kcontrols
[i
].private_value
;
186 val
= snd_soc_read(w
->codec
, e
->reg
);
187 val
= (val
>> e
->shift_l
) & e
->mask
;
188 for (item
= 0; item
< e
->max
; item
++) {
189 if (val
== e
->values
[item
])
194 for (i
= 0; i
< e
->max
; i
++) {
195 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
200 /* does not effect routing - always connected */
201 case snd_soc_dapm_pga
:
202 case snd_soc_dapm_output
:
203 case snd_soc_dapm_adc
:
204 case snd_soc_dapm_input
:
205 case snd_soc_dapm_dac
:
206 case snd_soc_dapm_micbias
:
207 case snd_soc_dapm_vmid
:
208 case snd_soc_dapm_supply
:
211 /* does effect routing - dynamically connected */
212 case snd_soc_dapm_hp
:
213 case snd_soc_dapm_mic
:
214 case snd_soc_dapm_spk
:
215 case snd_soc_dapm_line
:
216 case snd_soc_dapm_pre
:
217 case snd_soc_dapm_post
:
223 /* connect mux widget to its interconnecting audio paths */
224 static int dapm_connect_mux(struct snd_soc_codec
*codec
,
225 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
226 struct snd_soc_dapm_path
*path
, const char *control_name
,
227 const struct snd_kcontrol_new
*kcontrol
)
229 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
232 for (i
= 0; i
< e
->max
; i
++) {
233 if (!(strcmp(control_name
, e
->texts
[i
]))) {
234 list_add(&path
->list
, &codec
->dapm_paths
);
235 list_add(&path
->list_sink
, &dest
->sources
);
236 list_add(&path
->list_source
, &src
->sinks
);
237 path
->name
= (char*)e
->texts
[i
];
238 dapm_set_path_status(dest
, path
, 0);
246 /* connect mixer widget to its interconnecting audio paths */
247 static int dapm_connect_mixer(struct snd_soc_codec
*codec
,
248 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
249 struct snd_soc_dapm_path
*path
, const char *control_name
)
253 /* search for mixer kcontrol */
254 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
255 if (!strcmp(control_name
, dest
->kcontrols
[i
].name
)) {
256 list_add(&path
->list
, &codec
->dapm_paths
);
257 list_add(&path
->list_sink
, &dest
->sources
);
258 list_add(&path
->list_source
, &src
->sinks
);
259 path
->name
= dest
->kcontrols
[i
].name
;
260 dapm_set_path_status(dest
, path
, i
);
267 /* update dapm codec register bits */
268 static int dapm_update_bits(struct snd_soc_dapm_widget
*widget
)
271 unsigned short old
, new;
272 struct snd_soc_codec
*codec
= widget
->codec
;
274 /* check for valid widgets */
275 if (widget
->reg
< 0 || widget
->id
== snd_soc_dapm_input
||
276 widget
->id
== snd_soc_dapm_output
||
277 widget
->id
== snd_soc_dapm_hp
||
278 widget
->id
== snd_soc_dapm_mic
||
279 widget
->id
== snd_soc_dapm_line
||
280 widget
->id
== snd_soc_dapm_spk
)
283 power
= widget
->power
;
285 power
= (power
? 0:1);
287 old
= snd_soc_read(codec
, widget
->reg
);
288 new = (old
& ~(0x1 << widget
->shift
)) | (power
<< widget
->shift
);
292 pop_dbg(codec
->pop_time
, "pop test %s : %s in %d ms\n",
293 widget
->name
, widget
->power
? "on" : "off",
295 snd_soc_write(codec
, widget
->reg
, new);
296 pop_wait(codec
->pop_time
);
298 pr_debug("reg %x old %x new %x change %d\n", widget
->reg
,
303 /* ramps the volume up or down to minimise pops before or after a
304 * DAPM power event */
305 static int dapm_set_pga(struct snd_soc_dapm_widget
*widget
, int power
)
307 const struct snd_kcontrol_new
*k
= widget
->kcontrols
;
309 if (widget
->muted
&& !power
)
311 if (!widget
->muted
&& power
)
314 if (widget
->num_kcontrols
&& k
) {
315 struct soc_mixer_control
*mc
=
316 (struct soc_mixer_control
*)k
->private_value
;
317 unsigned int reg
= mc
->reg
;
318 unsigned int shift
= mc
->shift
;
320 unsigned int mask
= (1 << fls(max
)) - 1;
321 unsigned int invert
= mc
->invert
;
325 /* power up has happended, increase volume to last level */
327 for (i
= max
; i
> widget
->saved_value
; i
--)
328 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
330 for (i
= 0; i
< widget
->saved_value
; i
++)
331 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
335 /* power down is about to occur, decrease volume to mute */
336 int val
= snd_soc_read(widget
->codec
, reg
);
337 int i
= widget
->saved_value
= (val
>> shift
) & mask
;
339 for (; i
< mask
; i
++)
340 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
343 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
351 /* create new dapm mixer control */
352 static int dapm_new_mixer(struct snd_soc_codec
*codec
,
353 struct snd_soc_dapm_widget
*w
)
357 struct snd_soc_dapm_path
*path
;
360 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
363 list_for_each_entry(path
, &w
->sources
, list_sink
) {
365 /* mixer/mux paths name must match control name */
366 if (path
->name
!= (char*)w
->kcontrols
[i
].name
)
369 /* add dapm control with long name.
370 * for dapm_mixer this is the concatenation of the
371 * mixer and kcontrol name.
372 * for dapm_mixer_named_ctl this is simply the
375 name_len
= strlen(w
->kcontrols
[i
].name
) + 1;
376 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
377 name_len
+= 1 + strlen(w
->name
);
379 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
381 if (path
->long_name
== NULL
)
386 snprintf(path
->long_name
, name_len
, "%s %s",
387 w
->name
, w
->kcontrols
[i
].name
);
389 case snd_soc_dapm_mixer_named_ctl
:
390 snprintf(path
->long_name
, name_len
, "%s",
391 w
->kcontrols
[i
].name
);
395 path
->long_name
[name_len
- 1] = '\0';
397 path
->kcontrol
= snd_soc_cnew(&w
->kcontrols
[i
], w
,
399 ret
= snd_ctl_add(codec
->card
, path
->kcontrol
);
401 printk(KERN_ERR
"asoc: failed to add dapm kcontrol %s: %d\n",
404 kfree(path
->long_name
);
405 path
->long_name
= NULL
;
413 /* create new dapm mux control */
414 static int dapm_new_mux(struct snd_soc_codec
*codec
,
415 struct snd_soc_dapm_widget
*w
)
417 struct snd_soc_dapm_path
*path
= NULL
;
418 struct snd_kcontrol
*kcontrol
;
421 if (!w
->num_kcontrols
) {
422 printk(KERN_ERR
"asoc: mux %s has no controls\n", w
->name
);
426 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
427 ret
= snd_ctl_add(codec
->card
, kcontrol
);
431 list_for_each_entry(path
, &w
->sources
, list_sink
)
432 path
->kcontrol
= kcontrol
;
437 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
441 /* create new dapm volume control */
442 static int dapm_new_pga(struct snd_soc_codec
*codec
,
443 struct snd_soc_dapm_widget
*w
)
445 struct snd_kcontrol
*kcontrol
;
448 if (!w
->num_kcontrols
)
451 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
452 ret
= snd_ctl_add(codec
->card
, kcontrol
);
454 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
461 /* reset 'walked' bit for each dapm path */
462 static inline void dapm_clear_walk(struct snd_soc_codec
*codec
)
464 struct snd_soc_dapm_path
*p
;
466 list_for_each_entry(p
, &codec
->dapm_paths
, list
)
471 * Recursively check for a completed path to an active or physically connected
472 * output widget. Returns number of complete paths.
474 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
476 struct snd_soc_dapm_path
*path
;
479 if (widget
->id
== snd_soc_dapm_supply
)
482 if (widget
->id
== snd_soc_dapm_adc
&& widget
->active
)
485 if (widget
->connected
) {
486 /* connected pin ? */
487 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
490 /* connected jack or spk ? */
491 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
492 widget
->id
== snd_soc_dapm_line
)
496 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
500 if (path
->sink
&& path
->connect
) {
502 con
+= is_connected_output_ep(path
->sink
);
510 * Recursively check for a completed path to an active or physically connected
511 * input widget. Returns number of complete paths.
513 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
515 struct snd_soc_dapm_path
*path
;
518 if (widget
->id
== snd_soc_dapm_supply
)
521 /* active stream ? */
522 if (widget
->id
== snd_soc_dapm_dac
&& widget
->active
)
525 if (widget
->connected
) {
526 /* connected pin ? */
527 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
530 /* connected VMID/Bias for lower pops */
531 if (widget
->id
== snd_soc_dapm_vmid
)
534 /* connected jack ? */
535 if (widget
->id
== snd_soc_dapm_mic
|| widget
->id
== snd_soc_dapm_line
)
539 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
543 if (path
->source
&& path
->connect
) {
545 con
+= is_connected_input_ep(path
->source
);
553 * Handler for generic register modifier widget.
555 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
556 struct snd_kcontrol
*kcontrol
, int event
)
560 if (SND_SOC_DAPM_EVENT_ON(event
))
565 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
566 w
->mask
<< w
->shift
, val
<< w
->shift
);
570 EXPORT_SYMBOL_GPL(dapm_reg_event
);
572 /* Standard power change method, used to apply power changes to most
575 static int dapm_generic_apply_power(struct snd_soc_dapm_widget
*w
)
579 /* call any power change event handlers */
581 pr_debug("power %s event for %s flags %x\n",
582 w
->power
? "on" : "off",
583 w
->name
, w
->event_flags
);
585 /* power up pre event */
586 if (w
->power
&& w
->event
&&
587 (w
->event_flags
& SND_SOC_DAPM_PRE_PMU
)) {
588 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMU
);
593 /* power down pre event */
594 if (!w
->power
&& w
->event
&&
595 (w
->event_flags
& SND_SOC_DAPM_PRE_PMD
)) {
596 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMD
);
601 /* Lower PGA volume to reduce pops */
602 if (w
->id
== snd_soc_dapm_pga
&& !w
->power
)
603 dapm_set_pga(w
, w
->power
);
607 /* Raise PGA volume to reduce pops */
608 if (w
->id
== snd_soc_dapm_pga
&& w
->power
)
609 dapm_set_pga(w
, w
->power
);
611 /* power up post event */
612 if (w
->power
&& w
->event
&&
613 (w
->event_flags
& SND_SOC_DAPM_POST_PMU
)) {
615 NULL
, SND_SOC_DAPM_POST_PMU
);
620 /* power down post event */
621 if (!w
->power
&& w
->event
&&
622 (w
->event_flags
& SND_SOC_DAPM_POST_PMD
)) {
623 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_POST_PMD
);
631 /* Generic check to see if a widget should be powered.
633 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
637 in
= is_connected_input_ep(w
);
638 dapm_clear_walk(w
->codec
);
639 out
= is_connected_output_ep(w
);
640 dapm_clear_walk(w
->codec
);
641 return out
!= 0 && in
!= 0;
644 /* Check to see if an ADC has power */
645 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
650 in
= is_connected_input_ep(w
);
651 dapm_clear_walk(w
->codec
);
654 return dapm_generic_check_power(w
);
658 /* Check to see if a DAC has power */
659 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
664 out
= is_connected_output_ep(w
);
665 dapm_clear_walk(w
->codec
);
668 return dapm_generic_check_power(w
);
672 /* Check to see if a power supply is needed */
673 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
675 struct snd_soc_dapm_path
*path
;
678 /* Check if one of our outputs is connected */
679 list_for_each_entry(path
, &w
->sinks
, list_source
) {
680 if (path
->sink
&& path
->sink
->power_check
&&
681 path
->sink
->power_check(path
->sink
)) {
687 dapm_clear_walk(w
->codec
);
693 * Scan a single DAPM widget for a complete audio path and update the
694 * power status appropriately.
696 static int dapm_power_widget(struct snd_soc_codec
*codec
, int event
,
697 struct snd_soc_dapm_widget
*w
)
702 case snd_soc_dapm_pre
:
706 if (event
== SND_SOC_DAPM_STREAM_START
) {
708 NULL
, SND_SOC_DAPM_PRE_PMU
);
711 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
713 NULL
, SND_SOC_DAPM_PRE_PMD
);
719 case snd_soc_dapm_post
:
723 if (event
== SND_SOC_DAPM_STREAM_START
) {
725 NULL
, SND_SOC_DAPM_POST_PMU
);
728 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
730 NULL
, SND_SOC_DAPM_POST_PMD
);
737 return dapm_generic_apply_power(w
);
742 * Scan each dapm widget for complete audio path.
743 * A complete path is a route that has valid endpoints i.e.:-
745 * o DAC to output pin.
746 * o Input Pin to ADC.
747 * o Input pin to Output pin (bypass, sidetone)
748 * o DAC to ADC (loopback).
750 static int dapm_power_widgets(struct snd_soc_codec
*codec
, int event
)
752 struct snd_soc_device
*socdev
= codec
->socdev
;
753 struct snd_soc_dapm_widget
*w
;
758 INIT_LIST_HEAD(&codec
->up_list
);
759 INIT_LIST_HEAD(&codec
->down_list
);
761 /* Check which widgets we need to power and store them in
762 * lists indicating if they should be powered up or down.
764 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
766 case snd_soc_dapm_pre
:
767 list_add_tail(&codec
->down_list
, &w
->power_list
);
769 case snd_soc_dapm_post
:
770 list_add_tail(&codec
->up_list
, &w
->power_list
);
777 power
= w
->power_check(w
);
781 if (w
->power
== power
)
785 list_add_tail(&w
->power_list
, &codec
->up_list
);
787 list_add_tail(&w
->power_list
,
795 /* If we're changing to all on or all off then prepare */
796 if ((sys_power
&& codec
->bias_level
== SND_SOC_BIAS_STANDBY
) ||
797 (!sys_power
&& codec
->bias_level
== SND_SOC_BIAS_ON
)) {
798 ret
= snd_soc_dapm_set_bias_level(socdev
,
799 SND_SOC_BIAS_PREPARE
);
801 pr_err("Failed to prepare bias: %d\n", ret
);
804 /* Power down widgets first; try to avoid amplifying pops. */
805 for (i
= 0; i
< ARRAY_SIZE(dapm_down_seq
); i
++) {
806 list_for_each_entry(w
, &codec
->down_list
, power_list
) {
807 /* is widget in stream order */
808 if (w
->id
!= dapm_down_seq
[i
])
811 ret
= dapm_power_widget(codec
, event
, w
);
813 pr_err("Failed to power down %s: %d\n",
819 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++) {
820 list_for_each_entry(w
, &codec
->up_list
, power_list
) {
821 /* is widget in stream order */
822 if (w
->id
!= dapm_up_seq
[i
])
825 ret
= dapm_power_widget(codec
, event
, w
);
827 pr_err("Failed to power up %s: %d\n",
832 /* If we just powered the last thing off drop to standby bias */
833 if (codec
->bias_level
== SND_SOC_BIAS_PREPARE
&& !sys_power
) {
834 ret
= snd_soc_dapm_set_bias_level(socdev
,
835 SND_SOC_BIAS_STANDBY
);
837 pr_err("Failed to apply standby bias: %d\n", ret
);
840 /* If we just powered up then move to active bias */
841 if (codec
->bias_level
== SND_SOC_BIAS_PREPARE
&& sys_power
) {
842 ret
= snd_soc_dapm_set_bias_level(socdev
,
845 pr_err("Failed to apply active bias: %d\n", ret
);
852 static void dbg_dump_dapm(struct snd_soc_codec
* codec
, const char *action
)
854 struct snd_soc_dapm_widget
*w
;
855 struct snd_soc_dapm_path
*p
= NULL
;
858 printk("DAPM %s %s\n", codec
->name
, action
);
860 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
862 /* only display widgets that effect routing */
864 case snd_soc_dapm_pre
:
865 case snd_soc_dapm_post
:
866 case snd_soc_dapm_vmid
:
868 case snd_soc_dapm_mux
:
869 case snd_soc_dapm_value_mux
:
870 case snd_soc_dapm_output
:
871 case snd_soc_dapm_input
:
872 case snd_soc_dapm_switch
:
873 case snd_soc_dapm_hp
:
874 case snd_soc_dapm_mic
:
875 case snd_soc_dapm_spk
:
876 case snd_soc_dapm_line
:
877 case snd_soc_dapm_micbias
:
878 case snd_soc_dapm_dac
:
879 case snd_soc_dapm_adc
:
880 case snd_soc_dapm_pga
:
881 case snd_soc_dapm_mixer
:
882 case snd_soc_dapm_mixer_named_ctl
:
883 case snd_soc_dapm_supply
:
885 in
= is_connected_input_ep(w
);
886 dapm_clear_walk(w
->codec
);
887 out
= is_connected_output_ep(w
);
888 dapm_clear_walk(w
->codec
);
889 printk("%s: %s in %d out %d\n", w
->name
,
890 w
->power
? "On":"Off",in
, out
);
892 list_for_each_entry(p
, &w
->sources
, list_sink
) {
894 printk(" in %s %s\n", p
->name
? p
->name
: "static",
897 list_for_each_entry(p
, &w
->sinks
, list_source
) {
899 printk(" out %s %s\n", p
->name
? p
->name
: "static",
909 /* test and update the power status of a mux widget */
910 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
911 struct snd_kcontrol
*kcontrol
, int mask
,
912 int mux
, int val
, struct soc_enum
*e
)
914 struct snd_soc_dapm_path
*path
;
917 if (widget
->id
!= snd_soc_dapm_mux
&&
918 widget
->id
!= snd_soc_dapm_value_mux
)
921 if (!snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
))
924 /* find dapm widget path assoc with kcontrol */
925 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
926 if (path
->kcontrol
!= kcontrol
)
929 if (!path
->name
|| !e
->texts
[mux
])
933 /* we now need to match the string in the enum to the path */
934 if (!(strcmp(path
->name
, e
->texts
[mux
])))
935 path
->connect
= 1; /* new connection */
937 path
->connect
= 0; /* old connection must be powered down */
941 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
942 dump_dapm(widget
->codec
, "mux power update");
948 /* test and update the power status of a mixer or switch widget */
949 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
950 struct snd_kcontrol
*kcontrol
, int reg
,
951 int val_mask
, int val
, int invert
)
953 struct snd_soc_dapm_path
*path
;
956 if (widget
->id
!= snd_soc_dapm_mixer
&&
957 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
958 widget
->id
!= snd_soc_dapm_switch
)
961 if (!snd_soc_test_bits(widget
->codec
, reg
, val_mask
, val
))
964 /* find dapm widget path assoc with kcontrol */
965 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
966 if (path
->kcontrol
!= kcontrol
)
969 /* found, now check type */
973 path
->connect
= invert
? 0:1;
975 /* old connection must be powered down */
976 path
->connect
= invert
? 1:0;
981 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
982 dump_dapm(widget
->codec
, "mixer power update");
988 /* show dapm widget status in sys fs */
989 static ssize_t
dapm_widget_show(struct device
*dev
,
990 struct device_attribute
*attr
, char *buf
)
992 struct snd_soc_device
*devdata
= dev_get_drvdata(dev
);
993 struct snd_soc_codec
*codec
= devdata
->card
->codec
;
994 struct snd_soc_dapm_widget
*w
;
996 char *state
= "not set";
998 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1000 /* only display widgets that burnm power */
1002 case snd_soc_dapm_hp
:
1003 case snd_soc_dapm_mic
:
1004 case snd_soc_dapm_spk
:
1005 case snd_soc_dapm_line
:
1006 case snd_soc_dapm_micbias
:
1007 case snd_soc_dapm_dac
:
1008 case snd_soc_dapm_adc
:
1009 case snd_soc_dapm_pga
:
1010 case snd_soc_dapm_mixer
:
1011 case snd_soc_dapm_mixer_named_ctl
:
1012 case snd_soc_dapm_supply
:
1014 count
+= sprintf(buf
+ count
, "%s: %s\n",
1015 w
->name
, w
->power
? "On":"Off");
1022 switch (codec
->bias_level
) {
1023 case SND_SOC_BIAS_ON
:
1026 case SND_SOC_BIAS_PREPARE
:
1029 case SND_SOC_BIAS_STANDBY
:
1032 case SND_SOC_BIAS_OFF
:
1036 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1041 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1043 int snd_soc_dapm_sys_add(struct device
*dev
)
1045 return device_create_file(dev
, &dev_attr_dapm_widget
);
1048 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1050 device_remove_file(dev
, &dev_attr_dapm_widget
);
1053 /* free all dapm widgets and resources */
1054 static void dapm_free_widgets(struct snd_soc_codec
*codec
)
1056 struct snd_soc_dapm_widget
*w
, *next_w
;
1057 struct snd_soc_dapm_path
*p
, *next_p
;
1059 list_for_each_entry_safe(w
, next_w
, &codec
->dapm_widgets
, list
) {
1064 list_for_each_entry_safe(p
, next_p
, &codec
->dapm_paths
, list
) {
1066 kfree(p
->long_name
);
1071 static int snd_soc_dapm_set_pin(struct snd_soc_codec
*codec
,
1072 const char *pin
, int status
)
1074 struct snd_soc_dapm_widget
*w
;
1076 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1077 if (!strcmp(w
->name
, pin
)) {
1078 pr_debug("dapm: %s: pin %s\n", codec
->name
, pin
);
1079 w
->connected
= status
;
1084 pr_err("dapm: %s: configuring unknown pin %s\n", codec
->name
, pin
);
1089 * snd_soc_dapm_sync - scan and power dapm paths
1090 * @codec: audio codec
1092 * Walks all dapm audio paths and powers widgets according to their
1093 * stream or path usage.
1095 * Returns 0 for success.
1097 int snd_soc_dapm_sync(struct snd_soc_codec
*codec
)
1099 int ret
= dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
1100 dump_dapm(codec
, "sync");
1103 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1105 static int snd_soc_dapm_add_route(struct snd_soc_codec
*codec
,
1106 const char *sink
, const char *control
, const char *source
)
1108 struct snd_soc_dapm_path
*path
;
1109 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1112 /* find src and dest widgets */
1113 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1115 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1119 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1124 if (wsource
== NULL
|| wsink
== NULL
)
1127 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1131 path
->source
= wsource
;
1133 INIT_LIST_HEAD(&path
->list
);
1134 INIT_LIST_HEAD(&path
->list_source
);
1135 INIT_LIST_HEAD(&path
->list_sink
);
1137 /* check for external widgets */
1138 if (wsink
->id
== snd_soc_dapm_input
) {
1139 if (wsource
->id
== snd_soc_dapm_micbias
||
1140 wsource
->id
== snd_soc_dapm_mic
||
1141 wsink
->id
== snd_soc_dapm_line
||
1142 wsink
->id
== snd_soc_dapm_output
)
1145 if (wsource
->id
== snd_soc_dapm_output
) {
1146 if (wsink
->id
== snd_soc_dapm_spk
||
1147 wsink
->id
== snd_soc_dapm_hp
||
1148 wsink
->id
== snd_soc_dapm_line
||
1149 wsink
->id
== snd_soc_dapm_input
)
1153 /* connect static paths */
1154 if (control
== NULL
) {
1155 list_add(&path
->list
, &codec
->dapm_paths
);
1156 list_add(&path
->list_sink
, &wsink
->sources
);
1157 list_add(&path
->list_source
, &wsource
->sinks
);
1162 /* connect dynamic paths */
1164 case snd_soc_dapm_adc
:
1165 case snd_soc_dapm_dac
:
1166 case snd_soc_dapm_pga
:
1167 case snd_soc_dapm_input
:
1168 case snd_soc_dapm_output
:
1169 case snd_soc_dapm_micbias
:
1170 case snd_soc_dapm_vmid
:
1171 case snd_soc_dapm_pre
:
1172 case snd_soc_dapm_post
:
1173 case snd_soc_dapm_supply
:
1174 list_add(&path
->list
, &codec
->dapm_paths
);
1175 list_add(&path
->list_sink
, &wsink
->sources
);
1176 list_add(&path
->list_source
, &wsource
->sinks
);
1179 case snd_soc_dapm_mux
:
1180 case snd_soc_dapm_value_mux
:
1181 ret
= dapm_connect_mux(codec
, wsource
, wsink
, path
, control
,
1182 &wsink
->kcontrols
[0]);
1186 case snd_soc_dapm_switch
:
1187 case snd_soc_dapm_mixer
:
1188 case snd_soc_dapm_mixer_named_ctl
:
1189 ret
= dapm_connect_mixer(codec
, wsource
, wsink
, path
, control
);
1193 case snd_soc_dapm_hp
:
1194 case snd_soc_dapm_mic
:
1195 case snd_soc_dapm_line
:
1196 case snd_soc_dapm_spk
:
1197 list_add(&path
->list
, &codec
->dapm_paths
);
1198 list_add(&path
->list_sink
, &wsink
->sources
);
1199 list_add(&path
->list_source
, &wsource
->sinks
);
1206 printk(KERN_WARNING
"asoc: no dapm match for %s --> %s --> %s\n", source
,
1213 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1215 * @route: audio routes
1216 * @num: number of routes
1218 * Connects 2 dapm widgets together via a named audio path. The sink is
1219 * the widget receiving the audio signal, whilst the source is the sender
1220 * of the audio signal.
1222 * Returns 0 for success else error. On error all resources can be freed
1223 * with a call to snd_soc_card_free().
1225 int snd_soc_dapm_add_routes(struct snd_soc_codec
*codec
,
1226 const struct snd_soc_dapm_route
*route
, int num
)
1230 for (i
= 0; i
< num
; i
++) {
1231 ret
= snd_soc_dapm_add_route(codec
, route
->sink
,
1232 route
->control
, route
->source
);
1234 printk(KERN_ERR
"Failed to add route %s->%s\n",
1244 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1247 * snd_soc_dapm_new_widgets - add new dapm widgets
1248 * @codec: audio codec
1250 * Checks the codec for any new dapm widgets and creates them if found.
1252 * Returns 0 for success.
1254 int snd_soc_dapm_new_widgets(struct snd_soc_codec
*codec
)
1256 struct snd_soc_dapm_widget
*w
;
1258 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1264 case snd_soc_dapm_switch
:
1265 case snd_soc_dapm_mixer
:
1266 case snd_soc_dapm_mixer_named_ctl
:
1267 w
->power_check
= dapm_generic_check_power
;
1268 dapm_new_mixer(codec
, w
);
1270 case snd_soc_dapm_mux
:
1271 case snd_soc_dapm_value_mux
:
1272 w
->power_check
= dapm_generic_check_power
;
1273 dapm_new_mux(codec
, w
);
1275 case snd_soc_dapm_adc
:
1276 w
->power_check
= dapm_adc_check_power
;
1278 case snd_soc_dapm_dac
:
1279 w
->power_check
= dapm_dac_check_power
;
1281 case snd_soc_dapm_pga
:
1282 w
->power_check
= dapm_generic_check_power
;
1283 dapm_new_pga(codec
, w
);
1285 case snd_soc_dapm_input
:
1286 case snd_soc_dapm_output
:
1287 case snd_soc_dapm_micbias
:
1288 case snd_soc_dapm_spk
:
1289 case snd_soc_dapm_hp
:
1290 case snd_soc_dapm_mic
:
1291 case snd_soc_dapm_line
:
1292 w
->power_check
= dapm_generic_check_power
;
1294 case snd_soc_dapm_supply
:
1295 w
->power_check
= dapm_supply_check_power
;
1296 case snd_soc_dapm_vmid
:
1297 case snd_soc_dapm_pre
:
1298 case snd_soc_dapm_post
:
1304 dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
1307 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1310 * snd_soc_dapm_get_volsw - dapm mixer get callback
1311 * @kcontrol: mixer control
1312 * @ucontrol: control element information
1314 * Callback to get the value of a dapm mixer control.
1316 * Returns 0 for success.
1318 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1319 struct snd_ctl_elem_value
*ucontrol
)
1321 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1322 struct soc_mixer_control
*mc
=
1323 (struct soc_mixer_control
*)kcontrol
->private_value
;
1324 unsigned int reg
= mc
->reg
;
1325 unsigned int shift
= mc
->shift
;
1326 unsigned int rshift
= mc
->rshift
;
1328 unsigned int invert
= mc
->invert
;
1329 unsigned int mask
= (1 << fls(max
)) - 1;
1331 /* return the saved value if we are powered down */
1332 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1333 ucontrol
->value
.integer
.value
[0] = widget
->saved_value
;
1337 ucontrol
->value
.integer
.value
[0] =
1338 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1339 if (shift
!= rshift
)
1340 ucontrol
->value
.integer
.value
[1] =
1341 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1343 ucontrol
->value
.integer
.value
[0] =
1344 max
- ucontrol
->value
.integer
.value
[0];
1345 if (shift
!= rshift
)
1346 ucontrol
->value
.integer
.value
[1] =
1347 max
- ucontrol
->value
.integer
.value
[1];
1352 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1355 * snd_soc_dapm_put_volsw - dapm mixer set callback
1356 * @kcontrol: mixer control
1357 * @ucontrol: control element information
1359 * Callback to set the value of a dapm mixer control.
1361 * Returns 0 for success.
1363 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1364 struct snd_ctl_elem_value
*ucontrol
)
1366 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1367 struct soc_mixer_control
*mc
=
1368 (struct soc_mixer_control
*)kcontrol
->private_value
;
1369 unsigned int reg
= mc
->reg
;
1370 unsigned int shift
= mc
->shift
;
1371 unsigned int rshift
= mc
->rshift
;
1373 unsigned int mask
= (1 << fls(max
)) - 1;
1374 unsigned int invert
= mc
->invert
;
1375 unsigned short val
, val2
, val_mask
;
1378 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1382 val_mask
= mask
<< shift
;
1384 if (shift
!= rshift
) {
1385 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1388 val_mask
|= mask
<< rshift
;
1389 val
|= val2
<< rshift
;
1392 mutex_lock(&widget
->codec
->mutex
);
1393 widget
->value
= val
;
1395 /* save volume value if the widget is powered down */
1396 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1397 widget
->saved_value
= val
;
1398 mutex_unlock(&widget
->codec
->mutex
);
1402 dapm_mixer_update_power(widget
, kcontrol
, reg
, val_mask
, val
, invert
);
1403 if (widget
->event
) {
1404 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1405 ret
= widget
->event(widget
, kcontrol
,
1406 SND_SOC_DAPM_PRE_REG
);
1412 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1413 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1414 ret
= widget
->event(widget
, kcontrol
,
1415 SND_SOC_DAPM_POST_REG
);
1417 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1420 mutex_unlock(&widget
->codec
->mutex
);
1423 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
1426 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1427 * @kcontrol: mixer control
1428 * @ucontrol: control element information
1430 * Callback to get the value of a dapm enumerated double mixer control.
1432 * Returns 0 for success.
1434 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
1435 struct snd_ctl_elem_value
*ucontrol
)
1437 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1438 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1439 unsigned short val
, bitmask
;
1441 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1443 val
= snd_soc_read(widget
->codec
, e
->reg
);
1444 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
1445 if (e
->shift_l
!= e
->shift_r
)
1446 ucontrol
->value
.enumerated
.item
[1] =
1447 (val
>> e
->shift_r
) & (bitmask
- 1);
1451 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
1454 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1455 * @kcontrol: mixer control
1456 * @ucontrol: control element information
1458 * Callback to set the value of a dapm enumerated double mixer control.
1460 * Returns 0 for success.
1462 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
1463 struct snd_ctl_elem_value
*ucontrol
)
1465 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1466 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1467 unsigned short val
, mux
;
1468 unsigned short mask
, bitmask
;
1471 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1473 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1475 mux
= ucontrol
->value
.enumerated
.item
[0];
1476 val
= mux
<< e
->shift_l
;
1477 mask
= (bitmask
- 1) << e
->shift_l
;
1478 if (e
->shift_l
!= e
->shift_r
) {
1479 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1481 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
1482 mask
|= (bitmask
- 1) << e
->shift_r
;
1485 mutex_lock(&widget
->codec
->mutex
);
1486 widget
->value
= val
;
1487 dapm_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1488 if (widget
->event
) {
1489 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1490 ret
= widget
->event(widget
,
1491 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1495 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1496 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1497 ret
= widget
->event(widget
,
1498 kcontrol
, SND_SOC_DAPM_POST_REG
);
1500 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1503 mutex_unlock(&widget
->codec
->mutex
);
1506 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
1509 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1511 * @kcontrol: mixer control
1512 * @ucontrol: control element information
1514 * Callback to get the value of a dapm semi enumerated double mixer control.
1516 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1517 * used for handling bitfield coded enumeration for example.
1519 * Returns 0 for success.
1521 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
1522 struct snd_ctl_elem_value
*ucontrol
)
1524 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1525 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1526 unsigned short reg_val
, val
, mux
;
1528 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
1529 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
1530 for (mux
= 0; mux
< e
->max
; mux
++) {
1531 if (val
== e
->values
[mux
])
1534 ucontrol
->value
.enumerated
.item
[0] = mux
;
1535 if (e
->shift_l
!= e
->shift_r
) {
1536 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
1537 for (mux
= 0; mux
< e
->max
; mux
++) {
1538 if (val
== e
->values
[mux
])
1541 ucontrol
->value
.enumerated
.item
[1] = mux
;
1546 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
1549 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1551 * @kcontrol: mixer control
1552 * @ucontrol: control element information
1554 * Callback to set the value of a dapm semi enumerated double mixer control.
1556 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1557 * used for handling bitfield coded enumeration for example.
1559 * Returns 0 for success.
1561 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
1562 struct snd_ctl_elem_value
*ucontrol
)
1564 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1565 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1566 unsigned short val
, mux
;
1567 unsigned short mask
;
1570 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1572 mux
= ucontrol
->value
.enumerated
.item
[0];
1573 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
1574 mask
= e
->mask
<< e
->shift_l
;
1575 if (e
->shift_l
!= e
->shift_r
) {
1576 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1578 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
1579 mask
|= e
->mask
<< e
->shift_r
;
1582 mutex_lock(&widget
->codec
->mutex
);
1583 widget
->value
= val
;
1584 dapm_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1585 if (widget
->event
) {
1586 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1587 ret
= widget
->event(widget
,
1588 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1592 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1593 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1594 ret
= widget
->event(widget
,
1595 kcontrol
, SND_SOC_DAPM_POST_REG
);
1597 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1600 mutex_unlock(&widget
->codec
->mutex
);
1603 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
1606 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1608 * @kcontrol: mixer control
1609 * @uinfo: control element information
1611 * Callback to provide information about a pin switch control.
1613 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
1614 struct snd_ctl_elem_info
*uinfo
)
1616 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1618 uinfo
->value
.integer
.min
= 0;
1619 uinfo
->value
.integer
.max
= 1;
1623 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
1626 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1628 * @kcontrol: mixer control
1631 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
1632 struct snd_ctl_elem_value
*ucontrol
)
1634 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1635 const char *pin
= (const char *)kcontrol
->private_value
;
1637 mutex_lock(&codec
->mutex
);
1639 ucontrol
->value
.integer
.value
[0] =
1640 snd_soc_dapm_get_pin_status(codec
, pin
);
1642 mutex_unlock(&codec
->mutex
);
1646 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
1649 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1651 * @kcontrol: mixer control
1654 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
1655 struct snd_ctl_elem_value
*ucontrol
)
1657 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1658 const char *pin
= (const char *)kcontrol
->private_value
;
1660 mutex_lock(&codec
->mutex
);
1662 if (ucontrol
->value
.integer
.value
[0])
1663 snd_soc_dapm_enable_pin(codec
, pin
);
1665 snd_soc_dapm_disable_pin(codec
, pin
);
1667 snd_soc_dapm_sync(codec
);
1669 mutex_unlock(&codec
->mutex
);
1673 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
1676 * snd_soc_dapm_new_control - create new dapm control
1677 * @codec: audio codec
1678 * @widget: widget template
1680 * Creates a new dapm control based upon the template.
1682 * Returns 0 for success else error.
1684 int snd_soc_dapm_new_control(struct snd_soc_codec
*codec
,
1685 const struct snd_soc_dapm_widget
*widget
)
1687 struct snd_soc_dapm_widget
*w
;
1689 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
1693 INIT_LIST_HEAD(&w
->sources
);
1694 INIT_LIST_HEAD(&w
->sinks
);
1695 INIT_LIST_HEAD(&w
->list
);
1696 list_add(&w
->list
, &codec
->dapm_widgets
);
1698 /* machine layer set ups unconnected pins and insertions */
1702 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
1705 * snd_soc_dapm_new_controls - create new dapm controls
1706 * @codec: audio codec
1707 * @widget: widget array
1708 * @num: number of widgets
1710 * Creates new DAPM controls based upon the templates.
1712 * Returns 0 for success else error.
1714 int snd_soc_dapm_new_controls(struct snd_soc_codec
*codec
,
1715 const struct snd_soc_dapm_widget
*widget
,
1720 for (i
= 0; i
< num
; i
++) {
1721 ret
= snd_soc_dapm_new_control(codec
, widget
);
1724 "ASoC: Failed to create DAPM control %s: %d\n",
1732 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
1736 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1737 * @codec: audio codec
1738 * @stream: stream name
1739 * @event: stream event
1741 * Sends a stream event to the dapm core. The core then makes any
1742 * necessary widget power changes.
1744 * Returns 0 for success else error.
1746 int snd_soc_dapm_stream_event(struct snd_soc_codec
*codec
,
1747 char *stream
, int event
)
1749 struct snd_soc_dapm_widget
*w
;
1754 mutex_lock(&codec
->mutex
);
1755 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1759 pr_debug("widget %s\n %s stream %s event %d\n",
1760 w
->name
, w
->sname
, stream
, event
);
1761 if (strstr(w
->sname
, stream
)) {
1763 case SND_SOC_DAPM_STREAM_START
:
1766 case SND_SOC_DAPM_STREAM_STOP
:
1769 case SND_SOC_DAPM_STREAM_SUSPEND
:
1774 case SND_SOC_DAPM_STREAM_RESUME
:
1780 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
1782 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
1787 mutex_unlock(&codec
->mutex
);
1789 dapm_power_widgets(codec
, event
);
1790 dump_dapm(codec
, __func__
);
1793 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event
);
1796 * snd_soc_dapm_enable_pin - enable pin.
1800 * Enables input/output pin and its parents or children widgets iff there is
1801 * a valid audio route and active audio stream.
1802 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1803 * do any widget power switching.
1805 int snd_soc_dapm_enable_pin(struct snd_soc_codec
*codec
, const char *pin
)
1807 return snd_soc_dapm_set_pin(codec
, pin
, 1);
1809 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
1812 * snd_soc_dapm_disable_pin - disable pin.
1816 * Disables input/output pin and its parents or children widgets.
1817 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1818 * do any widget power switching.
1820 int snd_soc_dapm_disable_pin(struct snd_soc_codec
*codec
, const char *pin
)
1822 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1824 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
1827 * snd_soc_dapm_nc_pin - permanently disable pin.
1831 * Marks the specified pin as being not connected, disabling it along
1832 * any parent or child widgets. At present this is identical to
1833 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1834 * additional things such as disabling controls which only affect
1835 * paths through the pin.
1837 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1838 * do any widget power switching.
1840 int snd_soc_dapm_nc_pin(struct snd_soc_codec
*codec
, const char *pin
)
1842 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1844 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
1847 * snd_soc_dapm_get_pin_status - get audio pin status
1848 * @codec: audio codec
1849 * @pin: audio signal pin endpoint (or start point)
1851 * Get audio pin status - connected or disconnected.
1853 * Returns 1 for connected otherwise 0.
1855 int snd_soc_dapm_get_pin_status(struct snd_soc_codec
*codec
, const char *pin
)
1857 struct snd_soc_dapm_widget
*w
;
1859 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1860 if (!strcmp(w
->name
, pin
))
1861 return w
->connected
;
1866 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
1869 * snd_soc_dapm_free - free dapm resources
1870 * @socdev: SoC device
1872 * Free all dapm widgets and resources.
1874 void snd_soc_dapm_free(struct snd_soc_device
*socdev
)
1876 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1878 snd_soc_dapm_sys_remove(socdev
->dev
);
1879 dapm_free_widgets(codec
);
1881 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
1883 /* Module information */
1884 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1885 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1886 MODULE_LICENSE("GPL");