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 int dapm_status
= 1;
71 module_param(dapm_status
, int, 0);
72 MODULE_PARM_DESC(dapm_status
, "enable DPM sysfs entries");
74 static void pop_wait(u32 pop_time
)
77 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
80 static void pop_dbg(u32 pop_time
, const char *fmt
, ...)
94 /* create a new dapm widget */
95 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
96 const struct snd_soc_dapm_widget
*_widget
)
98 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
101 /* set up initial codec paths */
102 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
103 struct snd_soc_dapm_path
*p
, int i
)
106 case snd_soc_dapm_switch
:
107 case snd_soc_dapm_mixer
:
108 case snd_soc_dapm_mixer_named_ctl
: {
110 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
111 w
->kcontrols
[i
].private_value
;
112 unsigned int reg
= mc
->reg
;
113 unsigned int shift
= mc
->shift
;
115 unsigned int mask
= (1 << fls(max
)) - 1;
116 unsigned int invert
= mc
->invert
;
118 val
= snd_soc_read(w
->codec
, reg
);
119 val
= (val
>> shift
) & mask
;
121 if ((invert
&& !val
) || (!invert
&& val
))
127 case snd_soc_dapm_mux
: {
128 struct soc_enum
*e
= (struct soc_enum
*)w
->kcontrols
[i
].private_value
;
129 int val
, item
, bitmask
;
131 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
133 val
= snd_soc_read(w
->codec
, e
->reg
);
134 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
137 for (i
= 0; i
< e
->max
; i
++) {
138 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
143 case snd_soc_dapm_value_mux
: {
144 struct soc_enum
*e
= (struct soc_enum
*)
145 w
->kcontrols
[i
].private_value
;
148 val
= snd_soc_read(w
->codec
, e
->reg
);
149 val
= (val
>> e
->shift_l
) & e
->mask
;
150 for (item
= 0; item
< e
->max
; item
++) {
151 if (val
== e
->values
[item
])
156 for (i
= 0; i
< e
->max
; i
++) {
157 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
162 /* does not effect routing - always connected */
163 case snd_soc_dapm_pga
:
164 case snd_soc_dapm_output
:
165 case snd_soc_dapm_adc
:
166 case snd_soc_dapm_input
:
167 case snd_soc_dapm_dac
:
168 case snd_soc_dapm_micbias
:
169 case snd_soc_dapm_vmid
:
170 case snd_soc_dapm_supply
:
173 /* does effect routing - dynamically connected */
174 case snd_soc_dapm_hp
:
175 case snd_soc_dapm_mic
:
176 case snd_soc_dapm_spk
:
177 case snd_soc_dapm_line
:
178 case snd_soc_dapm_pre
:
179 case snd_soc_dapm_post
:
185 /* connect mux widget to it's interconnecting audio paths */
186 static int dapm_connect_mux(struct snd_soc_codec
*codec
,
187 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
188 struct snd_soc_dapm_path
*path
, const char *control_name
,
189 const struct snd_kcontrol_new
*kcontrol
)
191 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
194 for (i
= 0; i
< e
->max
; i
++) {
195 if (!(strcmp(control_name
, e
->texts
[i
]))) {
196 list_add(&path
->list
, &codec
->dapm_paths
);
197 list_add(&path
->list_sink
, &dest
->sources
);
198 list_add(&path
->list_source
, &src
->sinks
);
199 path
->name
= (char*)e
->texts
[i
];
200 dapm_set_path_status(dest
, path
, 0);
208 /* connect mixer widget to it's interconnecting audio paths */
209 static int dapm_connect_mixer(struct snd_soc_codec
*codec
,
210 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
211 struct snd_soc_dapm_path
*path
, const char *control_name
)
215 /* search for mixer kcontrol */
216 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
217 if (!strcmp(control_name
, dest
->kcontrols
[i
].name
)) {
218 list_add(&path
->list
, &codec
->dapm_paths
);
219 list_add(&path
->list_sink
, &dest
->sources
);
220 list_add(&path
->list_source
, &src
->sinks
);
221 path
->name
= dest
->kcontrols
[i
].name
;
222 dapm_set_path_status(dest
, path
, i
);
229 /* update dapm codec register bits */
230 static int dapm_update_bits(struct snd_soc_dapm_widget
*widget
)
233 unsigned short old
, new;
234 struct snd_soc_codec
*codec
= widget
->codec
;
236 /* check for valid widgets */
237 if (widget
->reg
< 0 || widget
->id
== snd_soc_dapm_input
||
238 widget
->id
== snd_soc_dapm_output
||
239 widget
->id
== snd_soc_dapm_hp
||
240 widget
->id
== snd_soc_dapm_mic
||
241 widget
->id
== snd_soc_dapm_line
||
242 widget
->id
== snd_soc_dapm_spk
)
245 power
= widget
->power
;
247 power
= (power
? 0:1);
249 old
= snd_soc_read(codec
, widget
->reg
);
250 new = (old
& ~(0x1 << widget
->shift
)) | (power
<< widget
->shift
);
254 pop_dbg(codec
->pop_time
, "pop test %s : %s in %d ms\n",
255 widget
->name
, widget
->power
? "on" : "off",
257 snd_soc_write(codec
, widget
->reg
, new);
258 pop_wait(codec
->pop_time
);
260 pr_debug("reg %x old %x new %x change %d\n", widget
->reg
,
265 /* ramps the volume up or down to minimise pops before or after a
266 * DAPM power event */
267 static int dapm_set_pga(struct snd_soc_dapm_widget
*widget
, int power
)
269 const struct snd_kcontrol_new
*k
= widget
->kcontrols
;
271 if (widget
->muted
&& !power
)
273 if (!widget
->muted
&& power
)
276 if (widget
->num_kcontrols
&& k
) {
277 struct soc_mixer_control
*mc
=
278 (struct soc_mixer_control
*)k
->private_value
;
279 unsigned int reg
= mc
->reg
;
280 unsigned int shift
= mc
->shift
;
282 unsigned int mask
= (1 << fls(max
)) - 1;
283 unsigned int invert
= mc
->invert
;
287 /* power up has happended, increase volume to last level */
289 for (i
= max
; i
> widget
->saved_value
; i
--)
290 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
292 for (i
= 0; i
< widget
->saved_value
; i
++)
293 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
297 /* power down is about to occur, decrease volume to mute */
298 int val
= snd_soc_read(widget
->codec
, reg
);
299 int i
= widget
->saved_value
= (val
>> shift
) & mask
;
301 for (; i
< mask
; i
++)
302 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
305 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
313 /* create new dapm mixer control */
314 static int dapm_new_mixer(struct snd_soc_codec
*codec
,
315 struct snd_soc_dapm_widget
*w
)
319 struct snd_soc_dapm_path
*path
;
322 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
325 list_for_each_entry(path
, &w
->sources
, list_sink
) {
327 /* mixer/mux paths name must match control name */
328 if (path
->name
!= (char*)w
->kcontrols
[i
].name
)
331 /* add dapm control with long name.
332 * for dapm_mixer this is the concatenation of the
333 * mixer and kcontrol name.
334 * for dapm_mixer_named_ctl this is simply the
337 name_len
= strlen(w
->kcontrols
[i
].name
) + 1;
338 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
339 name_len
+= 1 + strlen(w
->name
);
341 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
343 if (path
->long_name
== NULL
)
348 snprintf(path
->long_name
, name_len
, "%s %s",
349 w
->name
, w
->kcontrols
[i
].name
);
351 case snd_soc_dapm_mixer_named_ctl
:
352 snprintf(path
->long_name
, name_len
, "%s",
353 w
->kcontrols
[i
].name
);
357 path
->long_name
[name_len
- 1] = '\0';
359 path
->kcontrol
= snd_soc_cnew(&w
->kcontrols
[i
], w
,
361 ret
= snd_ctl_add(codec
->card
, path
->kcontrol
);
363 printk(KERN_ERR
"asoc: failed to add dapm kcontrol %s: %d\n",
366 kfree(path
->long_name
);
367 path
->long_name
= NULL
;
375 /* create new dapm mux control */
376 static int dapm_new_mux(struct snd_soc_codec
*codec
,
377 struct snd_soc_dapm_widget
*w
)
379 struct snd_soc_dapm_path
*path
= NULL
;
380 struct snd_kcontrol
*kcontrol
;
383 if (!w
->num_kcontrols
) {
384 printk(KERN_ERR
"asoc: mux %s has no controls\n", w
->name
);
388 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
389 ret
= snd_ctl_add(codec
->card
, kcontrol
);
393 list_for_each_entry(path
, &w
->sources
, list_sink
)
394 path
->kcontrol
= kcontrol
;
399 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
403 /* create new dapm volume control */
404 static int dapm_new_pga(struct snd_soc_codec
*codec
,
405 struct snd_soc_dapm_widget
*w
)
407 struct snd_kcontrol
*kcontrol
;
410 if (!w
->num_kcontrols
)
413 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
414 ret
= snd_ctl_add(codec
->card
, kcontrol
);
416 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
423 /* reset 'walked' bit for each dapm path */
424 static inline void dapm_clear_walk(struct snd_soc_codec
*codec
)
426 struct snd_soc_dapm_path
*p
;
428 list_for_each_entry(p
, &codec
->dapm_paths
, list
)
433 * Recursively check for a completed path to an active or physically connected
434 * output widget. Returns number of complete paths.
436 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
438 struct snd_soc_dapm_path
*path
;
441 if (widget
->id
== snd_soc_dapm_supply
)
444 if (widget
->id
== snd_soc_dapm_adc
&& widget
->active
)
447 if (widget
->connected
) {
448 /* connected pin ? */
449 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
452 /* connected jack or spk ? */
453 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
454 widget
->id
== snd_soc_dapm_line
)
458 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
462 if (path
->sink
&& path
->connect
) {
464 con
+= is_connected_output_ep(path
->sink
);
472 * Recursively check for a completed path to an active or physically connected
473 * input widget. Returns number of complete paths.
475 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
477 struct snd_soc_dapm_path
*path
;
480 if (widget
->id
== snd_soc_dapm_supply
)
483 /* active stream ? */
484 if (widget
->id
== snd_soc_dapm_dac
&& widget
->active
)
487 if (widget
->connected
) {
488 /* connected pin ? */
489 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
492 /* connected VMID/Bias for lower pops */
493 if (widget
->id
== snd_soc_dapm_vmid
)
496 /* connected jack ? */
497 if (widget
->id
== snd_soc_dapm_mic
|| widget
->id
== snd_soc_dapm_line
)
501 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
505 if (path
->source
&& path
->connect
) {
507 con
+= is_connected_input_ep(path
->source
);
515 * Handler for generic register modifier widget.
517 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
518 struct snd_kcontrol
*kcontrol
, int event
)
522 if (SND_SOC_DAPM_EVENT_ON(event
))
527 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
528 w
->mask
<< w
->shift
, val
<< w
->shift
);
532 EXPORT_SYMBOL_GPL(dapm_reg_event
);
534 /* Standard power change method, used to apply power changes to most
537 static int dapm_generic_apply_power(struct snd_soc_dapm_widget
*w
)
541 /* call any power change event handlers */
543 pr_debug("power %s event for %s flags %x\n",
544 w
->power
? "on" : "off",
545 w
->name
, w
->event_flags
);
547 /* power up pre event */
548 if (w
->power
&& w
->event
&&
549 (w
->event_flags
& SND_SOC_DAPM_PRE_PMU
)) {
550 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMU
);
555 /* power down pre event */
556 if (!w
->power
&& w
->event
&&
557 (w
->event_flags
& SND_SOC_DAPM_PRE_PMD
)) {
558 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMD
);
563 /* Lower PGA volume to reduce pops */
564 if (w
->id
== snd_soc_dapm_pga
&& !w
->power
)
565 dapm_set_pga(w
, w
->power
);
569 /* Raise PGA volume to reduce pops */
570 if (w
->id
== snd_soc_dapm_pga
&& w
->power
)
571 dapm_set_pga(w
, w
->power
);
573 /* power up post event */
574 if (w
->power
&& w
->event
&&
575 (w
->event_flags
& SND_SOC_DAPM_POST_PMU
)) {
577 NULL
, SND_SOC_DAPM_POST_PMU
);
582 /* power down post event */
583 if (!w
->power
&& w
->event
&&
584 (w
->event_flags
& SND_SOC_DAPM_POST_PMD
)) {
585 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_POST_PMD
);
593 /* Generic check to see if a widget should be powered.
595 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
599 in
= is_connected_input_ep(w
);
600 dapm_clear_walk(w
->codec
);
601 out
= is_connected_output_ep(w
);
602 dapm_clear_walk(w
->codec
);
603 return out
!= 0 && in
!= 0;
606 /* Check to see if an ADC has power */
607 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
612 in
= is_connected_input_ep(w
);
613 dapm_clear_walk(w
->codec
);
616 return dapm_generic_check_power(w
);
620 /* Check to see if a DAC has power */
621 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
626 out
= is_connected_output_ep(w
);
627 dapm_clear_walk(w
->codec
);
630 return dapm_generic_check_power(w
);
634 /* Check to see if a power supply is needed */
635 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
637 struct snd_soc_dapm_path
*path
;
640 /* Check if one of our outputs is connected */
641 list_for_each_entry(path
, &w
->sinks
, list_source
) {
642 if (path
->sink
&& path
->sink
->power_check
&&
643 path
->sink
->power_check(path
->sink
)) {
649 dapm_clear_walk(w
->codec
);
655 * Scan a single DAPM widget for a complete audio path and update the
656 * power status appropriately.
658 static int dapm_power_widget(struct snd_soc_codec
*codec
, int event
,
659 struct snd_soc_dapm_widget
*w
)
664 case snd_soc_dapm_pre
:
668 if (event
== SND_SOC_DAPM_STREAM_START
) {
670 NULL
, SND_SOC_DAPM_PRE_PMU
);
673 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
675 NULL
, SND_SOC_DAPM_PRE_PMD
);
681 case snd_soc_dapm_post
:
685 if (event
== SND_SOC_DAPM_STREAM_START
) {
687 NULL
, SND_SOC_DAPM_POST_PMU
);
690 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
692 NULL
, SND_SOC_DAPM_POST_PMD
);
699 return dapm_generic_apply_power(w
);
704 * Scan each dapm widget for complete audio path.
705 * A complete path is a route that has valid endpoints i.e.:-
707 * o DAC to output pin.
708 * o Input Pin to ADC.
709 * o Input pin to Output pin (bypass, sidetone)
710 * o DAC to ADC (loopback).
712 static int dapm_power_widgets(struct snd_soc_codec
*codec
, int event
)
714 struct snd_soc_dapm_widget
*w
;
718 INIT_LIST_HEAD(&codec
->up_list
);
719 INIT_LIST_HEAD(&codec
->down_list
);
721 /* Check which widgets we need to power and store them in
722 * lists indicating if they should be powered up or down.
724 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
726 case snd_soc_dapm_pre
:
727 list_add_tail(&codec
->down_list
, &w
->power_list
);
729 case snd_soc_dapm_post
:
730 list_add_tail(&codec
->up_list
, &w
->power_list
);
737 power
= w
->power_check(w
);
738 if (w
->power
== power
)
742 list_add_tail(&w
->power_list
, &codec
->up_list
);
744 list_add_tail(&w
->power_list
,
752 /* Power down widgets first; try to avoid amplifying pops. */
753 for (i
= 0; i
< ARRAY_SIZE(dapm_down_seq
); i
++) {
754 list_for_each_entry(w
, &codec
->down_list
, power_list
) {
755 /* is widget in stream order */
756 if (w
->id
!= dapm_down_seq
[i
])
759 ret
= dapm_power_widget(codec
, event
, w
);
761 pr_err("Failed to power down %s: %d\n",
767 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++) {
768 list_for_each_entry(w
, &codec
->up_list
, power_list
) {
769 /* is widget in stream order */
770 if (w
->id
!= dapm_up_seq
[i
])
773 ret
= dapm_power_widget(codec
, event
, w
);
775 pr_err("Failed to power up %s: %d\n",
784 static void dbg_dump_dapm(struct snd_soc_codec
* codec
, const char *action
)
786 struct snd_soc_dapm_widget
*w
;
787 struct snd_soc_dapm_path
*p
= NULL
;
790 printk("DAPM %s %s\n", codec
->name
, action
);
792 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
794 /* only display widgets that effect routing */
796 case snd_soc_dapm_pre
:
797 case snd_soc_dapm_post
:
798 case snd_soc_dapm_vmid
:
800 case snd_soc_dapm_mux
:
801 case snd_soc_dapm_value_mux
:
802 case snd_soc_dapm_output
:
803 case snd_soc_dapm_input
:
804 case snd_soc_dapm_switch
:
805 case snd_soc_dapm_hp
:
806 case snd_soc_dapm_mic
:
807 case snd_soc_dapm_spk
:
808 case snd_soc_dapm_line
:
809 case snd_soc_dapm_micbias
:
810 case snd_soc_dapm_dac
:
811 case snd_soc_dapm_adc
:
812 case snd_soc_dapm_pga
:
813 case snd_soc_dapm_mixer
:
814 case snd_soc_dapm_mixer_named_ctl
:
815 case snd_soc_dapm_supply
:
817 in
= is_connected_input_ep(w
);
818 dapm_clear_walk(w
->codec
);
819 out
= is_connected_output_ep(w
);
820 dapm_clear_walk(w
->codec
);
821 printk("%s: %s in %d out %d\n", w
->name
,
822 w
->power
? "On":"Off",in
, out
);
824 list_for_each_entry(p
, &w
->sources
, list_sink
) {
826 printk(" in %s %s\n", p
->name
? p
->name
: "static",
829 list_for_each_entry(p
, &w
->sinks
, list_source
) {
831 printk(" out %s %s\n", p
->name
? p
->name
: "static",
841 /* test and update the power status of a mux widget */
842 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
843 struct snd_kcontrol
*kcontrol
, int mask
,
844 int mux
, int val
, struct soc_enum
*e
)
846 struct snd_soc_dapm_path
*path
;
849 if (widget
->id
!= snd_soc_dapm_mux
&&
850 widget
->id
!= snd_soc_dapm_value_mux
)
853 if (!snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
))
856 /* find dapm widget path assoc with kcontrol */
857 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
858 if (path
->kcontrol
!= kcontrol
)
861 if (!path
->name
|| !e
->texts
[mux
])
865 /* we now need to match the string in the enum to the path */
866 if (!(strcmp(path
->name
, e
->texts
[mux
])))
867 path
->connect
= 1; /* new connection */
869 path
->connect
= 0; /* old connection must be powered down */
873 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
874 dump_dapm(widget
->codec
, "mux power update");
880 /* test and update the power status of a mixer or switch widget */
881 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
882 struct snd_kcontrol
*kcontrol
, int reg
,
883 int val_mask
, int val
, int invert
)
885 struct snd_soc_dapm_path
*path
;
888 if (widget
->id
!= snd_soc_dapm_mixer
&&
889 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
890 widget
->id
!= snd_soc_dapm_switch
)
893 if (!snd_soc_test_bits(widget
->codec
, reg
, val_mask
, val
))
896 /* find dapm widget path assoc with kcontrol */
897 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
898 if (path
->kcontrol
!= kcontrol
)
901 /* found, now check type */
905 path
->connect
= invert
? 0:1;
907 /* old connection must be powered down */
908 path
->connect
= invert
? 1:0;
913 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
914 dump_dapm(widget
->codec
, "mixer power update");
920 /* show dapm widget status in sys fs */
921 static ssize_t
dapm_widget_show(struct device
*dev
,
922 struct device_attribute
*attr
, char *buf
)
924 struct snd_soc_device
*devdata
= dev_get_drvdata(dev
);
925 struct snd_soc_codec
*codec
= devdata
->card
->codec
;
926 struct snd_soc_dapm_widget
*w
;
928 char *state
= "not set";
930 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
932 /* only display widgets that burnm power */
934 case snd_soc_dapm_hp
:
935 case snd_soc_dapm_mic
:
936 case snd_soc_dapm_spk
:
937 case snd_soc_dapm_line
:
938 case snd_soc_dapm_micbias
:
939 case snd_soc_dapm_dac
:
940 case snd_soc_dapm_adc
:
941 case snd_soc_dapm_pga
:
942 case snd_soc_dapm_mixer
:
943 case snd_soc_dapm_mixer_named_ctl
:
944 case snd_soc_dapm_supply
:
946 count
+= sprintf(buf
+ count
, "%s: %s\n",
947 w
->name
, w
->power
? "On":"Off");
954 switch (codec
->bias_level
) {
955 case SND_SOC_BIAS_ON
:
958 case SND_SOC_BIAS_PREPARE
:
961 case SND_SOC_BIAS_STANDBY
:
964 case SND_SOC_BIAS_OFF
:
968 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
973 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
975 int snd_soc_dapm_sys_add(struct device
*dev
)
979 return device_create_file(dev
, &dev_attr_dapm_widget
);
982 static void snd_soc_dapm_sys_remove(struct device
*dev
)
985 device_remove_file(dev
, &dev_attr_dapm_widget
);
989 /* free all dapm widgets and resources */
990 static void dapm_free_widgets(struct snd_soc_codec
*codec
)
992 struct snd_soc_dapm_widget
*w
, *next_w
;
993 struct snd_soc_dapm_path
*p
, *next_p
;
995 list_for_each_entry_safe(w
, next_w
, &codec
->dapm_widgets
, list
) {
1000 list_for_each_entry_safe(p
, next_p
, &codec
->dapm_paths
, list
) {
1002 kfree(p
->long_name
);
1007 static int snd_soc_dapm_set_pin(struct snd_soc_codec
*codec
,
1008 const char *pin
, int status
)
1010 struct snd_soc_dapm_widget
*w
;
1012 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1013 if (!strcmp(w
->name
, pin
)) {
1014 pr_debug("dapm: %s: pin %s\n", codec
->name
, pin
);
1015 w
->connected
= status
;
1020 pr_err("dapm: %s: configuring unknown pin %s\n", codec
->name
, pin
);
1025 * snd_soc_dapm_sync - scan and power dapm paths
1026 * @codec: audio codec
1028 * Walks all dapm audio paths and powers widgets according to their
1029 * stream or path usage.
1031 * Returns 0 for success.
1033 int snd_soc_dapm_sync(struct snd_soc_codec
*codec
)
1035 int ret
= dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
1036 dump_dapm(codec
, "sync");
1039 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1041 static int snd_soc_dapm_add_route(struct snd_soc_codec
*codec
,
1042 const char *sink
, const char *control
, const char *source
)
1044 struct snd_soc_dapm_path
*path
;
1045 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1048 /* find src and dest widgets */
1049 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1051 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1055 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1060 if (wsource
== NULL
|| wsink
== NULL
)
1063 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1067 path
->source
= wsource
;
1069 INIT_LIST_HEAD(&path
->list
);
1070 INIT_LIST_HEAD(&path
->list_source
);
1071 INIT_LIST_HEAD(&path
->list_sink
);
1073 /* check for external widgets */
1074 if (wsink
->id
== snd_soc_dapm_input
) {
1075 if (wsource
->id
== snd_soc_dapm_micbias
||
1076 wsource
->id
== snd_soc_dapm_mic
||
1077 wsink
->id
== snd_soc_dapm_line
||
1078 wsink
->id
== snd_soc_dapm_output
)
1081 if (wsource
->id
== snd_soc_dapm_output
) {
1082 if (wsink
->id
== snd_soc_dapm_spk
||
1083 wsink
->id
== snd_soc_dapm_hp
||
1084 wsink
->id
== snd_soc_dapm_line
||
1085 wsink
->id
== snd_soc_dapm_input
)
1089 /* connect static paths */
1090 if (control
== NULL
) {
1091 list_add(&path
->list
, &codec
->dapm_paths
);
1092 list_add(&path
->list_sink
, &wsink
->sources
);
1093 list_add(&path
->list_source
, &wsource
->sinks
);
1098 /* connect dynamic paths */
1100 case snd_soc_dapm_adc
:
1101 case snd_soc_dapm_dac
:
1102 case snd_soc_dapm_pga
:
1103 case snd_soc_dapm_input
:
1104 case snd_soc_dapm_output
:
1105 case snd_soc_dapm_micbias
:
1106 case snd_soc_dapm_vmid
:
1107 case snd_soc_dapm_pre
:
1108 case snd_soc_dapm_post
:
1109 case snd_soc_dapm_supply
:
1110 list_add(&path
->list
, &codec
->dapm_paths
);
1111 list_add(&path
->list_sink
, &wsink
->sources
);
1112 list_add(&path
->list_source
, &wsource
->sinks
);
1115 case snd_soc_dapm_mux
:
1116 case snd_soc_dapm_value_mux
:
1117 ret
= dapm_connect_mux(codec
, wsource
, wsink
, path
, control
,
1118 &wsink
->kcontrols
[0]);
1122 case snd_soc_dapm_switch
:
1123 case snd_soc_dapm_mixer
:
1124 case snd_soc_dapm_mixer_named_ctl
:
1125 ret
= dapm_connect_mixer(codec
, wsource
, wsink
, path
, control
);
1129 case snd_soc_dapm_hp
:
1130 case snd_soc_dapm_mic
:
1131 case snd_soc_dapm_line
:
1132 case snd_soc_dapm_spk
:
1133 list_add(&path
->list
, &codec
->dapm_paths
);
1134 list_add(&path
->list_sink
, &wsink
->sources
);
1135 list_add(&path
->list_source
, &wsource
->sinks
);
1142 printk(KERN_WARNING
"asoc: no dapm match for %s --> %s --> %s\n", source
,
1149 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1151 * @route: audio routes
1152 * @num: number of routes
1154 * Connects 2 dapm widgets together via a named audio path. The sink is
1155 * the widget receiving the audio signal, whilst the source is the sender
1156 * of the audio signal.
1158 * Returns 0 for success else error. On error all resources can be freed
1159 * with a call to snd_soc_card_free().
1161 int snd_soc_dapm_add_routes(struct snd_soc_codec
*codec
,
1162 const struct snd_soc_dapm_route
*route
, int num
)
1166 for (i
= 0; i
< num
; i
++) {
1167 ret
= snd_soc_dapm_add_route(codec
, route
->sink
,
1168 route
->control
, route
->source
);
1170 printk(KERN_ERR
"Failed to add route %s->%s\n",
1180 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1183 * snd_soc_dapm_new_widgets - add new dapm widgets
1184 * @codec: audio codec
1186 * Checks the codec for any new dapm widgets and creates them if found.
1188 * Returns 0 for success.
1190 int snd_soc_dapm_new_widgets(struct snd_soc_codec
*codec
)
1192 struct snd_soc_dapm_widget
*w
;
1194 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1200 case snd_soc_dapm_switch
:
1201 case snd_soc_dapm_mixer
:
1202 case snd_soc_dapm_mixer_named_ctl
:
1203 w
->power_check
= dapm_generic_check_power
;
1204 dapm_new_mixer(codec
, w
);
1206 case snd_soc_dapm_mux
:
1207 case snd_soc_dapm_value_mux
:
1208 w
->power_check
= dapm_generic_check_power
;
1209 dapm_new_mux(codec
, w
);
1211 case snd_soc_dapm_adc
:
1212 w
->power_check
= dapm_adc_check_power
;
1214 case snd_soc_dapm_dac
:
1215 w
->power_check
= dapm_dac_check_power
;
1217 case snd_soc_dapm_pga
:
1218 w
->power_check
= dapm_generic_check_power
;
1219 dapm_new_pga(codec
, w
);
1221 case snd_soc_dapm_input
:
1222 case snd_soc_dapm_output
:
1223 case snd_soc_dapm_micbias
:
1224 case snd_soc_dapm_spk
:
1225 case snd_soc_dapm_hp
:
1226 case snd_soc_dapm_mic
:
1227 case snd_soc_dapm_line
:
1228 w
->power_check
= dapm_generic_check_power
;
1230 case snd_soc_dapm_supply
:
1231 w
->power_check
= dapm_supply_check_power
;
1232 case snd_soc_dapm_vmid
:
1233 case snd_soc_dapm_pre
:
1234 case snd_soc_dapm_post
:
1240 dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
1243 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1246 * snd_soc_dapm_get_volsw - dapm mixer get callback
1247 * @kcontrol: mixer control
1248 * @ucontrol: control element information
1250 * Callback to get the value of a dapm mixer control.
1252 * Returns 0 for success.
1254 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1255 struct snd_ctl_elem_value
*ucontrol
)
1257 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1258 struct soc_mixer_control
*mc
=
1259 (struct soc_mixer_control
*)kcontrol
->private_value
;
1260 unsigned int reg
= mc
->reg
;
1261 unsigned int shift
= mc
->shift
;
1262 unsigned int rshift
= mc
->rshift
;
1264 unsigned int invert
= mc
->invert
;
1265 unsigned int mask
= (1 << fls(max
)) - 1;
1267 /* return the saved value if we are powered down */
1268 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1269 ucontrol
->value
.integer
.value
[0] = widget
->saved_value
;
1273 ucontrol
->value
.integer
.value
[0] =
1274 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1275 if (shift
!= rshift
)
1276 ucontrol
->value
.integer
.value
[1] =
1277 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1279 ucontrol
->value
.integer
.value
[0] =
1280 max
- ucontrol
->value
.integer
.value
[0];
1281 if (shift
!= rshift
)
1282 ucontrol
->value
.integer
.value
[1] =
1283 max
- ucontrol
->value
.integer
.value
[1];
1288 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1291 * snd_soc_dapm_put_volsw - dapm mixer set callback
1292 * @kcontrol: mixer control
1293 * @ucontrol: control element information
1295 * Callback to set the value of a dapm mixer control.
1297 * Returns 0 for success.
1299 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1300 struct snd_ctl_elem_value
*ucontrol
)
1302 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1303 struct soc_mixer_control
*mc
=
1304 (struct soc_mixer_control
*)kcontrol
->private_value
;
1305 unsigned int reg
= mc
->reg
;
1306 unsigned int shift
= mc
->shift
;
1307 unsigned int rshift
= mc
->rshift
;
1309 unsigned int mask
= (1 << fls(max
)) - 1;
1310 unsigned int invert
= mc
->invert
;
1311 unsigned short val
, val2
, val_mask
;
1314 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1318 val_mask
= mask
<< shift
;
1320 if (shift
!= rshift
) {
1321 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1324 val_mask
|= mask
<< rshift
;
1325 val
|= val2
<< rshift
;
1328 mutex_lock(&widget
->codec
->mutex
);
1329 widget
->value
= val
;
1331 /* save volume value if the widget is powered down */
1332 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1333 widget
->saved_value
= val
;
1334 mutex_unlock(&widget
->codec
->mutex
);
1338 dapm_mixer_update_power(widget
, kcontrol
, reg
, val_mask
, val
, invert
);
1339 if (widget
->event
) {
1340 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1341 ret
= widget
->event(widget
, kcontrol
,
1342 SND_SOC_DAPM_PRE_REG
);
1348 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1349 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1350 ret
= widget
->event(widget
, kcontrol
,
1351 SND_SOC_DAPM_POST_REG
);
1353 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1356 mutex_unlock(&widget
->codec
->mutex
);
1359 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
1362 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1363 * @kcontrol: mixer control
1364 * @ucontrol: control element information
1366 * Callback to get the value of a dapm enumerated double mixer control.
1368 * Returns 0 for success.
1370 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
1371 struct snd_ctl_elem_value
*ucontrol
)
1373 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1374 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1375 unsigned short val
, bitmask
;
1377 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1379 val
= snd_soc_read(widget
->codec
, e
->reg
);
1380 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
1381 if (e
->shift_l
!= e
->shift_r
)
1382 ucontrol
->value
.enumerated
.item
[1] =
1383 (val
>> e
->shift_r
) & (bitmask
- 1);
1387 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
1390 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1391 * @kcontrol: mixer control
1392 * @ucontrol: control element information
1394 * Callback to set the value of a dapm enumerated double mixer control.
1396 * Returns 0 for success.
1398 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
1399 struct snd_ctl_elem_value
*ucontrol
)
1401 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1402 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1403 unsigned short val
, mux
;
1404 unsigned short mask
, bitmask
;
1407 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1409 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1411 mux
= ucontrol
->value
.enumerated
.item
[0];
1412 val
= mux
<< e
->shift_l
;
1413 mask
= (bitmask
- 1) << e
->shift_l
;
1414 if (e
->shift_l
!= e
->shift_r
) {
1415 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1417 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
1418 mask
|= (bitmask
- 1) << e
->shift_r
;
1421 mutex_lock(&widget
->codec
->mutex
);
1422 widget
->value
= val
;
1423 dapm_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1424 if (widget
->event
) {
1425 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1426 ret
= widget
->event(widget
,
1427 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1431 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1432 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1433 ret
= widget
->event(widget
,
1434 kcontrol
, SND_SOC_DAPM_POST_REG
);
1436 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1439 mutex_unlock(&widget
->codec
->mutex
);
1442 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
1445 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1447 * @kcontrol: mixer control
1448 * @ucontrol: control element information
1450 * Callback to get the value of a dapm semi enumerated double mixer control.
1452 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1453 * used for handling bitfield coded enumeration for example.
1455 * Returns 0 for success.
1457 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
1458 struct snd_ctl_elem_value
*ucontrol
)
1460 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1461 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1462 unsigned short reg_val
, val
, mux
;
1464 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
1465 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
1466 for (mux
= 0; mux
< e
->max
; mux
++) {
1467 if (val
== e
->values
[mux
])
1470 ucontrol
->value
.enumerated
.item
[0] = mux
;
1471 if (e
->shift_l
!= e
->shift_r
) {
1472 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
1473 for (mux
= 0; mux
< e
->max
; mux
++) {
1474 if (val
== e
->values
[mux
])
1477 ucontrol
->value
.enumerated
.item
[1] = mux
;
1482 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
1485 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1487 * @kcontrol: mixer control
1488 * @ucontrol: control element information
1490 * Callback to set the value of a dapm semi enumerated double mixer control.
1492 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1493 * used for handling bitfield coded enumeration for example.
1495 * Returns 0 for success.
1497 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
1498 struct snd_ctl_elem_value
*ucontrol
)
1500 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1501 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1502 unsigned short val
, mux
;
1503 unsigned short mask
;
1506 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1508 mux
= ucontrol
->value
.enumerated
.item
[0];
1509 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
1510 mask
= e
->mask
<< e
->shift_l
;
1511 if (e
->shift_l
!= e
->shift_r
) {
1512 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1514 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
1515 mask
|= e
->mask
<< e
->shift_r
;
1518 mutex_lock(&widget
->codec
->mutex
);
1519 widget
->value
= val
;
1520 dapm_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1521 if (widget
->event
) {
1522 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1523 ret
= widget
->event(widget
,
1524 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1528 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1529 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1530 ret
= widget
->event(widget
,
1531 kcontrol
, SND_SOC_DAPM_POST_REG
);
1533 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1536 mutex_unlock(&widget
->codec
->mutex
);
1539 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
1542 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1544 * @kcontrol: mixer control
1545 * @uinfo: control element information
1547 * Callback to provide information about a pin switch control.
1549 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
1550 struct snd_ctl_elem_info
*uinfo
)
1552 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1554 uinfo
->value
.integer
.min
= 0;
1555 uinfo
->value
.integer
.max
= 1;
1559 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
1562 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1564 * @kcontrol: mixer control
1567 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
1568 struct snd_ctl_elem_value
*ucontrol
)
1570 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1571 const char *pin
= (const char *)kcontrol
->private_value
;
1573 mutex_lock(&codec
->mutex
);
1575 ucontrol
->value
.integer
.value
[0] =
1576 snd_soc_dapm_get_pin_status(codec
, pin
);
1578 mutex_unlock(&codec
->mutex
);
1582 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
1585 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1587 * @kcontrol: mixer control
1590 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
1591 struct snd_ctl_elem_value
*ucontrol
)
1593 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1594 const char *pin
= (const char *)kcontrol
->private_value
;
1596 mutex_lock(&codec
->mutex
);
1598 if (ucontrol
->value
.integer
.value
[0])
1599 snd_soc_dapm_enable_pin(codec
, pin
);
1601 snd_soc_dapm_disable_pin(codec
, pin
);
1603 snd_soc_dapm_sync(codec
);
1605 mutex_unlock(&codec
->mutex
);
1609 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
1612 * snd_soc_dapm_new_control - create new dapm control
1613 * @codec: audio codec
1614 * @widget: widget template
1616 * Creates a new dapm control based upon the template.
1618 * Returns 0 for success else error.
1620 int snd_soc_dapm_new_control(struct snd_soc_codec
*codec
,
1621 const struct snd_soc_dapm_widget
*widget
)
1623 struct snd_soc_dapm_widget
*w
;
1625 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
1629 INIT_LIST_HEAD(&w
->sources
);
1630 INIT_LIST_HEAD(&w
->sinks
);
1631 INIT_LIST_HEAD(&w
->list
);
1632 list_add(&w
->list
, &codec
->dapm_widgets
);
1634 /* machine layer set ups unconnected pins and insertions */
1638 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
1641 * snd_soc_dapm_new_controls - create new dapm controls
1642 * @codec: audio codec
1643 * @widget: widget array
1644 * @num: number of widgets
1646 * Creates new DAPM controls based upon the templates.
1648 * Returns 0 for success else error.
1650 int snd_soc_dapm_new_controls(struct snd_soc_codec
*codec
,
1651 const struct snd_soc_dapm_widget
*widget
,
1656 for (i
= 0; i
< num
; i
++) {
1657 ret
= snd_soc_dapm_new_control(codec
, widget
);
1660 "ASoC: Failed to create DAPM control %s: %d\n",
1668 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
1672 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1673 * @codec: audio codec
1674 * @stream: stream name
1675 * @event: stream event
1677 * Sends a stream event to the dapm core. The core then makes any
1678 * necessary widget power changes.
1680 * Returns 0 for success else error.
1682 int snd_soc_dapm_stream_event(struct snd_soc_codec
*codec
,
1683 char *stream
, int event
)
1685 struct snd_soc_dapm_widget
*w
;
1690 mutex_lock(&codec
->mutex
);
1691 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1695 pr_debug("widget %s\n %s stream %s event %d\n",
1696 w
->name
, w
->sname
, stream
, event
);
1697 if (strstr(w
->sname
, stream
)) {
1699 case SND_SOC_DAPM_STREAM_START
:
1702 case SND_SOC_DAPM_STREAM_STOP
:
1705 case SND_SOC_DAPM_STREAM_SUSPEND
:
1710 case SND_SOC_DAPM_STREAM_RESUME
:
1716 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
1718 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
1723 mutex_unlock(&codec
->mutex
);
1725 dapm_power_widgets(codec
, event
);
1726 dump_dapm(codec
, __func__
);
1729 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event
);
1732 * snd_soc_dapm_set_bias_level - set the bias level for the system
1733 * @socdev: audio device
1734 * @level: level to configure
1736 * Configure the bias (power) levels for the SoC audio device.
1738 * Returns 0 for success else error.
1740 int snd_soc_dapm_set_bias_level(struct snd_soc_device
*socdev
,
1741 enum snd_soc_bias_level level
)
1743 struct snd_soc_card
*card
= socdev
->card
;
1744 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1747 if (card
->set_bias_level
)
1748 ret
= card
->set_bias_level(card
, level
);
1749 if (ret
== 0 && codec
->set_bias_level
)
1750 ret
= codec
->set_bias_level(codec
, level
);
1756 * snd_soc_dapm_enable_pin - enable pin.
1760 * Enables input/output pin and it's parents or children widgets iff there is
1761 * a valid audio route and active audio stream.
1762 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1763 * do any widget power switching.
1765 int snd_soc_dapm_enable_pin(struct snd_soc_codec
*codec
, const char *pin
)
1767 return snd_soc_dapm_set_pin(codec
, pin
, 1);
1769 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
1772 * snd_soc_dapm_disable_pin - disable pin.
1776 * Disables input/output pin and it's parents or children widgets.
1777 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1778 * do any widget power switching.
1780 int snd_soc_dapm_disable_pin(struct snd_soc_codec
*codec
, const char *pin
)
1782 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1784 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
1787 * snd_soc_dapm_nc_pin - permanently disable pin.
1791 * Marks the specified pin as being not connected, disabling it along
1792 * any parent or child widgets. At present this is identical to
1793 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1794 * additional things such as disabling controls which only affect
1795 * paths through the pin.
1797 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1798 * do any widget power switching.
1800 int snd_soc_dapm_nc_pin(struct snd_soc_codec
*codec
, const char *pin
)
1802 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1804 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
1807 * snd_soc_dapm_get_pin_status - get audio pin status
1808 * @codec: audio codec
1809 * @pin: audio signal pin endpoint (or start point)
1811 * Get audio pin status - connected or disconnected.
1813 * Returns 1 for connected otherwise 0.
1815 int snd_soc_dapm_get_pin_status(struct snd_soc_codec
*codec
, const char *pin
)
1817 struct snd_soc_dapm_widget
*w
;
1819 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1820 if (!strcmp(w
->name
, pin
))
1821 return w
->connected
;
1826 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
1829 * snd_soc_dapm_free - free dapm resources
1830 * @socdev: SoC device
1832 * Free all dapm widgets and resources.
1834 void snd_soc_dapm_free(struct snd_soc_device
*socdev
)
1836 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1838 snd_soc_dapm_sys_remove(socdev
->dev
);
1839 dapm_free_widgets(codec
);
1841 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
1843 /* Module information */
1844 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1845 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1846 MODULE_LICENSE("GPL");