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_micbias
, snd_soc_dapm_mic
,
56 snd_soc_dapm_mux
, snd_soc_dapm_value_mux
, snd_soc_dapm_dac
,
57 snd_soc_dapm_mixer
, snd_soc_dapm_pga
, snd_soc_dapm_adc
, snd_soc_dapm_hp
,
58 snd_soc_dapm_spk
, snd_soc_dapm_post
60 static int dapm_down_seq
[] = {
61 snd_soc_dapm_pre
, snd_soc_dapm_adc
, snd_soc_dapm_hp
, snd_soc_dapm_spk
,
62 snd_soc_dapm_pga
, snd_soc_dapm_mixer
, snd_soc_dapm_dac
, snd_soc_dapm_mic
,
63 snd_soc_dapm_micbias
, snd_soc_dapm_mux
, snd_soc_dapm_value_mux
,
67 static int dapm_status
= 1;
68 module_param(dapm_status
, int, 0);
69 MODULE_PARM_DESC(dapm_status
, "enable DPM sysfs entries");
71 static void pop_wait(u32 pop_time
)
74 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
77 static void pop_dbg(u32 pop_time
, const char *fmt
, ...)
91 /* create a new dapm widget */
92 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
93 const struct snd_soc_dapm_widget
*_widget
)
95 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
98 /* set up initial codec paths */
99 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
100 struct snd_soc_dapm_path
*p
, int i
)
103 case snd_soc_dapm_switch
:
104 case snd_soc_dapm_mixer
: {
106 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
107 w
->kcontrols
[i
].private_value
;
108 unsigned int reg
= mc
->reg
;
109 unsigned int shift
= mc
->shift
;
111 unsigned int mask
= (1 << fls(max
)) - 1;
112 unsigned int invert
= mc
->invert
;
114 val
= snd_soc_read(w
->codec
, reg
);
115 val
= (val
>> shift
) & mask
;
117 if ((invert
&& !val
) || (!invert
&& val
))
123 case snd_soc_dapm_mux
: {
124 struct soc_enum
*e
= (struct soc_enum
*)w
->kcontrols
[i
].private_value
;
125 int val
, item
, bitmask
;
127 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
129 val
= snd_soc_read(w
->codec
, e
->reg
);
130 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
133 for (i
= 0; i
< e
->max
; i
++) {
134 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
139 case snd_soc_dapm_value_mux
: {
140 struct soc_value_enum
*e
= (struct soc_value_enum
*)
141 w
->kcontrols
[i
].private_value
;
144 val
= snd_soc_read(w
->codec
, e
->reg
);
145 val
= (val
>> e
->shift_l
) & e
->mask
;
146 for (item
= 0; item
< e
->max
; item
++) {
147 if (val
== e
->values
[item
])
152 for (i
= 0; i
< e
->max
; i
++) {
153 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
158 /* does not effect routing - always connected */
159 case snd_soc_dapm_pga
:
160 case snd_soc_dapm_output
:
161 case snd_soc_dapm_adc
:
162 case snd_soc_dapm_input
:
163 case snd_soc_dapm_dac
:
164 case snd_soc_dapm_micbias
:
165 case snd_soc_dapm_vmid
:
168 /* does effect routing - dynamically connected */
169 case snd_soc_dapm_hp
:
170 case snd_soc_dapm_mic
:
171 case snd_soc_dapm_spk
:
172 case snd_soc_dapm_line
:
173 case snd_soc_dapm_pre
:
174 case snd_soc_dapm_post
:
180 /* connect mux widget to it's interconnecting audio paths */
181 static int dapm_connect_mux(struct snd_soc_codec
*codec
,
182 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
183 struct snd_soc_dapm_path
*path
, const char *control_name
,
184 const struct snd_kcontrol_new
*kcontrol
)
186 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
189 for (i
= 0; i
< e
->max
; i
++) {
190 if (!(strcmp(control_name
, e
->texts
[i
]))) {
191 list_add(&path
->list
, &codec
->dapm_paths
);
192 list_add(&path
->list_sink
, &dest
->sources
);
193 list_add(&path
->list_source
, &src
->sinks
);
194 path
->name
= (char*)e
->texts
[i
];
195 dapm_set_path_status(dest
, path
, 0);
203 /* connect value_mux widget to it's interconnecting audio paths */
204 static int dapm_connect_value_mux(struct snd_soc_codec
*codec
,
205 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
206 struct snd_soc_dapm_path
*path
, const char *control_name
,
207 const struct snd_kcontrol_new
*kcontrol
)
209 struct soc_value_enum
*e
= (struct soc_value_enum
*)
210 kcontrol
->private_value
;
213 for (i
= 0; i
< e
->max
; i
++) {
214 if (!(strcmp(control_name
, e
->texts
[i
]))) {
215 list_add(&path
->list
, &codec
->dapm_paths
);
216 list_add(&path
->list_sink
, &dest
->sources
);
217 list_add(&path
->list_source
, &src
->sinks
);
218 path
->name
= (char *)e
->texts
[i
];
219 dapm_set_path_status(dest
, path
, 0);
227 /* connect mixer widget to it's interconnecting audio paths */
228 static int dapm_connect_mixer(struct snd_soc_codec
*codec
,
229 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
230 struct snd_soc_dapm_path
*path
, const char *control_name
)
234 /* search for mixer kcontrol */
235 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
236 if (!strcmp(control_name
, dest
->kcontrols
[i
].name
)) {
237 list_add(&path
->list
, &codec
->dapm_paths
);
238 list_add(&path
->list_sink
, &dest
->sources
);
239 list_add(&path
->list_source
, &src
->sinks
);
240 path
->name
= dest
->kcontrols
[i
].name
;
241 dapm_set_path_status(dest
, path
, i
);
248 /* update dapm codec register bits */
249 static int dapm_update_bits(struct snd_soc_dapm_widget
*widget
)
252 unsigned short old
, new;
253 struct snd_soc_codec
*codec
= widget
->codec
;
255 /* check for valid widgets */
256 if (widget
->reg
< 0 || widget
->id
== snd_soc_dapm_input
||
257 widget
->id
== snd_soc_dapm_output
||
258 widget
->id
== snd_soc_dapm_hp
||
259 widget
->id
== snd_soc_dapm_mic
||
260 widget
->id
== snd_soc_dapm_line
||
261 widget
->id
== snd_soc_dapm_spk
)
264 power
= widget
->power
;
266 power
= (power
? 0:1);
268 old
= snd_soc_read(codec
, widget
->reg
);
269 new = (old
& ~(0x1 << widget
->shift
)) | (power
<< widget
->shift
);
273 pop_dbg(codec
->pop_time
, "pop test %s : %s in %d ms\n",
274 widget
->name
, widget
->power
? "on" : "off",
276 snd_soc_write(codec
, widget
->reg
, new);
277 pop_wait(codec
->pop_time
);
279 pr_debug("reg %x old %x new %x change %d\n", widget
->reg
,
284 /* ramps the volume up or down to minimise pops before or after a
285 * DAPM power event */
286 static int dapm_set_pga(struct snd_soc_dapm_widget
*widget
, int power
)
288 const struct snd_kcontrol_new
*k
= widget
->kcontrols
;
290 if (widget
->muted
&& !power
)
292 if (!widget
->muted
&& power
)
295 if (widget
->num_kcontrols
&& k
) {
296 struct soc_mixer_control
*mc
=
297 (struct soc_mixer_control
*)k
->private_value
;
298 unsigned int reg
= mc
->reg
;
299 unsigned int shift
= mc
->shift
;
301 unsigned int mask
= (1 << fls(max
)) - 1;
302 unsigned int invert
= mc
->invert
;
306 /* power up has happended, increase volume to last level */
308 for (i
= max
; i
> widget
->saved_value
; i
--)
309 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
311 for (i
= 0; i
< widget
->saved_value
; i
++)
312 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
316 /* power down is about to occur, decrease volume to mute */
317 int val
= snd_soc_read(widget
->codec
, reg
);
318 int i
= widget
->saved_value
= (val
>> shift
) & mask
;
320 for (; i
< mask
; i
++)
321 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
324 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
332 /* create new dapm mixer control */
333 static int dapm_new_mixer(struct snd_soc_codec
*codec
,
334 struct snd_soc_dapm_widget
*w
)
338 struct snd_soc_dapm_path
*path
;
341 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
344 list_for_each_entry(path
, &w
->sources
, list_sink
) {
346 /* mixer/mux paths name must match control name */
347 if (path
->name
!= (char*)w
->kcontrols
[i
].name
)
350 /* add dapm control with long name */
351 name_len
= 2 + strlen(w
->name
)
352 + strlen(w
->kcontrols
[i
].name
);
353 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
354 if (path
->long_name
== NULL
)
357 snprintf(path
->long_name
, name_len
, "%s %s",
358 w
->name
, w
->kcontrols
[i
].name
);
359 path
->long_name
[name_len
- 1] = '\0';
361 path
->kcontrol
= snd_soc_cnew(&w
->kcontrols
[i
], w
,
363 ret
= snd_ctl_add(codec
->card
, path
->kcontrol
);
365 printk(KERN_ERR
"asoc: failed to add dapm kcontrol %s\n",
367 kfree(path
->long_name
);
368 path
->long_name
= NULL
;
376 /* create new dapm mux control */
377 static int dapm_new_mux(struct snd_soc_codec
*codec
,
378 struct snd_soc_dapm_widget
*w
)
380 struct snd_soc_dapm_path
*path
= NULL
;
381 struct snd_kcontrol
*kcontrol
;
384 if (!w
->num_kcontrols
) {
385 printk(KERN_ERR
"asoc: mux %s has no controls\n", w
->name
);
389 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
390 ret
= snd_ctl_add(codec
->card
, kcontrol
);
394 list_for_each_entry(path
, &w
->sources
, list_sink
)
395 path
->kcontrol
= kcontrol
;
400 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
404 /* create new dapm volume control */
405 static int dapm_new_pga(struct snd_soc_codec
*codec
,
406 struct snd_soc_dapm_widget
*w
)
408 struct snd_kcontrol
*kcontrol
;
411 if (!w
->num_kcontrols
)
414 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
415 ret
= snd_ctl_add(codec
->card
, kcontrol
);
417 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
424 /* reset 'walked' bit for each dapm path */
425 static inline void dapm_clear_walk(struct snd_soc_codec
*codec
)
427 struct snd_soc_dapm_path
*p
;
429 list_for_each_entry(p
, &codec
->dapm_paths
, list
)
434 * Recursively check for a completed path to an active or physically connected
435 * output widget. Returns number of complete paths.
437 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
439 struct snd_soc_dapm_path
*path
;
442 if (widget
->id
== snd_soc_dapm_adc
&& widget
->active
)
445 if (widget
->connected
) {
446 /* connected pin ? */
447 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
450 /* connected jack or spk ? */
451 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
452 widget
->id
== snd_soc_dapm_line
)
456 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
460 if (path
->sink
&& path
->connect
) {
462 con
+= is_connected_output_ep(path
->sink
);
470 * Recursively check for a completed path to an active or physically connected
471 * input widget. Returns number of complete paths.
473 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
475 struct snd_soc_dapm_path
*path
;
478 /* active stream ? */
479 if (widget
->id
== snd_soc_dapm_dac
&& widget
->active
)
482 if (widget
->connected
) {
483 /* connected pin ? */
484 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
487 /* connected VMID/Bias for lower pops */
488 if (widget
->id
== snd_soc_dapm_vmid
)
491 /* connected jack ? */
492 if (widget
->id
== snd_soc_dapm_mic
|| widget
->id
== snd_soc_dapm_line
)
496 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
500 if (path
->source
&& path
->connect
) {
502 con
+= is_connected_input_ep(path
->source
);
510 * Handler for generic register modifier widget.
512 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
513 struct snd_kcontrol
*kcontrol
, int event
)
517 if (SND_SOC_DAPM_EVENT_ON(event
))
522 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
523 w
->mask
<< w
->shift
, val
<< w
->shift
);
527 EXPORT_SYMBOL_GPL(dapm_reg_event
);
530 * Scan each dapm widget for complete audio path.
531 * A complete path is a route that has valid endpoints i.e.:-
533 * o DAC to output pin.
534 * o Input Pin to ADC.
535 * o Input pin to Output pin (bypass, sidetone)
536 * o DAC to ADC (loopback).
538 static int dapm_power_widgets(struct snd_soc_codec
*codec
, int event
)
540 struct snd_soc_dapm_widget
*w
;
541 int in
, out
, i
, c
= 1, *seq
= NULL
, ret
= 0, power_change
, power
;
543 /* do we have a sequenced stream event */
544 if (event
== SND_SOC_DAPM_STREAM_START
) {
545 c
= ARRAY_SIZE(dapm_up_seq
);
547 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
548 c
= ARRAY_SIZE(dapm_down_seq
);
552 for(i
= 0; i
< c
; i
++) {
553 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
555 /* is widget in stream order */
556 if (seq
&& seq
[i
] && w
->id
!= seq
[i
])
559 /* vmid - no action */
560 if (w
->id
== snd_soc_dapm_vmid
)
564 if (w
->id
== snd_soc_dapm_adc
&& w
->active
) {
565 in
= is_connected_input_ep(w
);
566 dapm_clear_walk(w
->codec
);
567 w
->power
= (in
!= 0) ? 1 : 0;
573 if (w
->id
== snd_soc_dapm_dac
&& w
->active
) {
574 out
= is_connected_output_ep(w
);
575 dapm_clear_walk(w
->codec
);
576 w
->power
= (out
!= 0) ? 1 : 0;
581 /* pre and post event widgets */
582 if (w
->id
== snd_soc_dapm_pre
) {
586 if (event
== SND_SOC_DAPM_STREAM_START
) {
588 NULL
, SND_SOC_DAPM_PRE_PMU
);
591 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
593 NULL
, SND_SOC_DAPM_PRE_PMD
);
599 if (w
->id
== snd_soc_dapm_post
) {
603 if (event
== SND_SOC_DAPM_STREAM_START
) {
605 NULL
, SND_SOC_DAPM_POST_PMU
);
608 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
610 NULL
, SND_SOC_DAPM_POST_PMD
);
617 /* all other widgets */
618 in
= is_connected_input_ep(w
);
619 dapm_clear_walk(w
->codec
);
620 out
= is_connected_output_ep(w
);
621 dapm_clear_walk(w
->codec
);
622 power
= (out
!= 0 && in
!= 0) ? 1 : 0;
623 power_change
= (w
->power
== power
) ? 0: 1;
629 /* call any power change event handlers */
631 pr_debug("power %s event for %s flags %x\n",
632 w
->power
? "on" : "off",
633 w
->name
, w
->event_flags
);
635 /* power up pre event */
636 if (power
&& w
->event
&&
637 (w
->event_flags
& SND_SOC_DAPM_PRE_PMU
)) {
638 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMU
);
643 /* power down pre event */
644 if (!power
&& w
->event
&&
645 (w
->event_flags
& SND_SOC_DAPM_PRE_PMD
)) {
646 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMD
);
651 /* Lower PGA volume to reduce pops */
652 if (w
->id
== snd_soc_dapm_pga
&& !power
)
653 dapm_set_pga(w
, power
);
657 /* Raise PGA volume to reduce pops */
658 if (w
->id
== snd_soc_dapm_pga
&& power
)
659 dapm_set_pga(w
, power
);
661 /* power up post event */
662 if (power
&& w
->event
&&
663 (w
->event_flags
& SND_SOC_DAPM_POST_PMU
)) {
665 NULL
, SND_SOC_DAPM_POST_PMU
);
670 /* power down post event */
671 if (!power
&& w
->event
&&
672 (w
->event_flags
& SND_SOC_DAPM_POST_PMD
)) {
673 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_POST_PMD
);
684 static void dbg_dump_dapm(struct snd_soc_codec
* codec
, const char *action
)
686 struct snd_soc_dapm_widget
*w
;
687 struct snd_soc_dapm_path
*p
= NULL
;
690 printk("DAPM %s %s\n", codec
->name
, action
);
692 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
694 /* only display widgets that effect routing */
696 case snd_soc_dapm_pre
:
697 case snd_soc_dapm_post
:
698 case snd_soc_dapm_vmid
:
700 case snd_soc_dapm_mux
:
701 case snd_soc_dapm_value_mux
:
702 case snd_soc_dapm_output
:
703 case snd_soc_dapm_input
:
704 case snd_soc_dapm_switch
:
705 case snd_soc_dapm_hp
:
706 case snd_soc_dapm_mic
:
707 case snd_soc_dapm_spk
:
708 case snd_soc_dapm_line
:
709 case snd_soc_dapm_micbias
:
710 case snd_soc_dapm_dac
:
711 case snd_soc_dapm_adc
:
712 case snd_soc_dapm_pga
:
713 case snd_soc_dapm_mixer
:
715 in
= is_connected_input_ep(w
);
716 dapm_clear_walk(w
->codec
);
717 out
= is_connected_output_ep(w
);
718 dapm_clear_walk(w
->codec
);
719 printk("%s: %s in %d out %d\n", w
->name
,
720 w
->power
? "On":"Off",in
, out
);
722 list_for_each_entry(p
, &w
->sources
, list_sink
) {
724 printk(" in %s %s\n", p
->name
? p
->name
: "static",
727 list_for_each_entry(p
, &w
->sinks
, list_source
) {
729 printk(" out %s %s\n", p
->name
? p
->name
: "static",
739 /* test and update the power status of a mux widget */
740 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
741 struct snd_kcontrol
*kcontrol
, int mask
,
742 int mux
, int val
, struct soc_enum
*e
)
744 struct snd_soc_dapm_path
*path
;
747 if (widget
->id
!= snd_soc_dapm_mux
)
750 if (!snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
))
753 /* find dapm widget path assoc with kcontrol */
754 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
755 if (path
->kcontrol
!= kcontrol
)
758 if (!path
->name
|| !e
->texts
[mux
])
762 /* we now need to match the string in the enum to the path */
763 if (!(strcmp(path
->name
, e
->texts
[mux
])))
764 path
->connect
= 1; /* new connection */
766 path
->connect
= 0; /* old connection must be powered down */
770 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
771 dump_dapm(widget
->codec
, "mux power update");
777 /* test and update the power status of a value_mux widget */
778 static int dapm_value_mux_update_power(struct snd_soc_dapm_widget
*widget
,
779 struct snd_kcontrol
*kcontrol
, int mask
,
780 int mux
, int val
, struct soc_value_enum
*e
)
782 struct snd_soc_dapm_path
*path
;
785 if (widget
->id
!= snd_soc_dapm_value_mux
)
788 if (!snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
))
791 /* find dapm widget path assoc with kcontrol */
792 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
793 if (path
->kcontrol
!= kcontrol
)
796 if (!path
->name
|| !e
->texts
[mux
])
800 /* we now need to match the string in the enum to the path */
801 if (!(strcmp(path
->name
, e
->texts
[mux
])))
802 path
->connect
= 1; /* new connection */
804 path
->connect
= 0; /* old connection must be
809 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
810 dump_dapm(widget
->codec
, "mux power update");
816 /* test and update the power status of a mixer or switch widget */
817 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
818 struct snd_kcontrol
*kcontrol
, int reg
,
819 int val_mask
, int val
, int invert
)
821 struct snd_soc_dapm_path
*path
;
824 if (widget
->id
!= snd_soc_dapm_mixer
&&
825 widget
->id
!= snd_soc_dapm_switch
)
828 if (!snd_soc_test_bits(widget
->codec
, reg
, val_mask
, val
))
831 /* find dapm widget path assoc with kcontrol */
832 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
833 if (path
->kcontrol
!= kcontrol
)
836 /* found, now check type */
840 path
->connect
= invert
? 0:1;
842 /* old connection must be powered down */
843 path
->connect
= invert
? 1:0;
848 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
849 dump_dapm(widget
->codec
, "mixer power update");
855 /* show dapm widget status in sys fs */
856 static ssize_t
dapm_widget_show(struct device
*dev
,
857 struct device_attribute
*attr
, char *buf
)
859 struct snd_soc_device
*devdata
= dev_get_drvdata(dev
);
860 struct snd_soc_codec
*codec
= devdata
->codec
;
861 struct snd_soc_dapm_widget
*w
;
863 char *state
= "not set";
865 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
867 /* only display widgets that burnm power */
869 case snd_soc_dapm_hp
:
870 case snd_soc_dapm_mic
:
871 case snd_soc_dapm_spk
:
872 case snd_soc_dapm_line
:
873 case snd_soc_dapm_micbias
:
874 case snd_soc_dapm_dac
:
875 case snd_soc_dapm_adc
:
876 case snd_soc_dapm_pga
:
877 case snd_soc_dapm_mixer
:
879 count
+= sprintf(buf
+ count
, "%s: %s\n",
880 w
->name
, w
->power
? "On":"Off");
887 switch (codec
->bias_level
) {
888 case SND_SOC_BIAS_ON
:
891 case SND_SOC_BIAS_PREPARE
:
894 case SND_SOC_BIAS_STANDBY
:
897 case SND_SOC_BIAS_OFF
:
901 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
906 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
908 int snd_soc_dapm_sys_add(struct device
*dev
)
912 return device_create_file(dev
, &dev_attr_dapm_widget
);
915 static void snd_soc_dapm_sys_remove(struct device
*dev
)
918 device_remove_file(dev
, &dev_attr_dapm_widget
);
922 /* free all dapm widgets and resources */
923 static void dapm_free_widgets(struct snd_soc_codec
*codec
)
925 struct snd_soc_dapm_widget
*w
, *next_w
;
926 struct snd_soc_dapm_path
*p
, *next_p
;
928 list_for_each_entry_safe(w
, next_w
, &codec
->dapm_widgets
, list
) {
933 list_for_each_entry_safe(p
, next_p
, &codec
->dapm_paths
, list
) {
940 static int snd_soc_dapm_set_pin(struct snd_soc_codec
*codec
,
941 char *pin
, int status
)
943 struct snd_soc_dapm_widget
*w
;
945 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
946 if (!strcmp(w
->name
, pin
)) {
947 pr_debug("dapm: %s: pin %s\n", codec
->name
, pin
);
948 w
->connected
= status
;
953 pr_err("dapm: %s: configuring unknown pin %s\n", codec
->name
, pin
);
958 * snd_soc_dapm_sync - scan and power dapm paths
959 * @codec: audio codec
961 * Walks all dapm audio paths and powers widgets according to their
962 * stream or path usage.
964 * Returns 0 for success.
966 int snd_soc_dapm_sync(struct snd_soc_codec
*codec
)
968 int ret
= dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
969 dump_dapm(codec
, "sync");
972 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
974 static int snd_soc_dapm_add_route(struct snd_soc_codec
*codec
,
975 const char *sink
, const char *control
, const char *source
)
977 struct snd_soc_dapm_path
*path
;
978 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
981 /* find src and dest widgets */
982 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
984 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
988 if (!wsource
&& !(strcmp(w
->name
, source
))) {
993 if (wsource
== NULL
|| wsink
== NULL
)
996 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1000 path
->source
= wsource
;
1002 INIT_LIST_HEAD(&path
->list
);
1003 INIT_LIST_HEAD(&path
->list_source
);
1004 INIT_LIST_HEAD(&path
->list_sink
);
1006 /* check for external widgets */
1007 if (wsink
->id
== snd_soc_dapm_input
) {
1008 if (wsource
->id
== snd_soc_dapm_micbias
||
1009 wsource
->id
== snd_soc_dapm_mic
||
1010 wsink
->id
== snd_soc_dapm_line
||
1011 wsink
->id
== snd_soc_dapm_output
)
1014 if (wsource
->id
== snd_soc_dapm_output
) {
1015 if (wsink
->id
== snd_soc_dapm_spk
||
1016 wsink
->id
== snd_soc_dapm_hp
||
1017 wsink
->id
== snd_soc_dapm_line
||
1018 wsink
->id
== snd_soc_dapm_input
)
1022 /* connect static paths */
1023 if (control
== NULL
) {
1024 list_add(&path
->list
, &codec
->dapm_paths
);
1025 list_add(&path
->list_sink
, &wsink
->sources
);
1026 list_add(&path
->list_source
, &wsource
->sinks
);
1031 /* connect dynamic paths */
1033 case snd_soc_dapm_adc
:
1034 case snd_soc_dapm_dac
:
1035 case snd_soc_dapm_pga
:
1036 case snd_soc_dapm_input
:
1037 case snd_soc_dapm_output
:
1038 case snd_soc_dapm_micbias
:
1039 case snd_soc_dapm_vmid
:
1040 case snd_soc_dapm_pre
:
1041 case snd_soc_dapm_post
:
1042 list_add(&path
->list
, &codec
->dapm_paths
);
1043 list_add(&path
->list_sink
, &wsink
->sources
);
1044 list_add(&path
->list_source
, &wsource
->sinks
);
1047 case snd_soc_dapm_mux
:
1048 ret
= dapm_connect_mux(codec
, wsource
, wsink
, path
, control
,
1049 &wsink
->kcontrols
[0]);
1053 case snd_soc_dapm_value_mux
:
1054 ret
= dapm_connect_value_mux(codec
, wsource
, wsink
, path
,
1055 control
, &wsink
->kcontrols
[0]);
1059 case snd_soc_dapm_switch
:
1060 case snd_soc_dapm_mixer
:
1061 ret
= dapm_connect_mixer(codec
, wsource
, wsink
, path
, control
);
1065 case snd_soc_dapm_hp
:
1066 case snd_soc_dapm_mic
:
1067 case snd_soc_dapm_line
:
1068 case snd_soc_dapm_spk
:
1069 list_add(&path
->list
, &codec
->dapm_paths
);
1070 list_add(&path
->list_sink
, &wsink
->sources
);
1071 list_add(&path
->list_source
, &wsource
->sinks
);
1078 printk(KERN_WARNING
"asoc: no dapm match for %s --> %s --> %s\n", source
,
1085 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1087 * @route: audio routes
1088 * @num: number of routes
1090 * Connects 2 dapm widgets together via a named audio path. The sink is
1091 * the widget receiving the audio signal, whilst the source is the sender
1092 * of the audio signal.
1094 * Returns 0 for success else error. On error all resources can be freed
1095 * with a call to snd_soc_card_free().
1097 int snd_soc_dapm_add_routes(struct snd_soc_codec
*codec
,
1098 const struct snd_soc_dapm_route
*route
, int num
)
1102 for (i
= 0; i
< num
; i
++) {
1103 ret
= snd_soc_dapm_add_route(codec
, route
->sink
,
1104 route
->control
, route
->source
);
1106 printk(KERN_ERR
"Failed to add route %s->%s\n",
1116 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1119 * snd_soc_dapm_new_widgets - add new dapm widgets
1120 * @codec: audio codec
1122 * Checks the codec for any new dapm widgets and creates them if found.
1124 * Returns 0 for success.
1126 int snd_soc_dapm_new_widgets(struct snd_soc_codec
*codec
)
1128 struct snd_soc_dapm_widget
*w
;
1130 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1136 case snd_soc_dapm_switch
:
1137 case snd_soc_dapm_mixer
:
1138 dapm_new_mixer(codec
, w
);
1140 case snd_soc_dapm_mux
:
1141 case snd_soc_dapm_value_mux
:
1142 dapm_new_mux(codec
, w
);
1144 case snd_soc_dapm_adc
:
1145 case snd_soc_dapm_dac
:
1146 case snd_soc_dapm_pga
:
1147 dapm_new_pga(codec
, w
);
1149 case snd_soc_dapm_input
:
1150 case snd_soc_dapm_output
:
1151 case snd_soc_dapm_micbias
:
1152 case snd_soc_dapm_spk
:
1153 case snd_soc_dapm_hp
:
1154 case snd_soc_dapm_mic
:
1155 case snd_soc_dapm_line
:
1156 case snd_soc_dapm_vmid
:
1157 case snd_soc_dapm_pre
:
1158 case snd_soc_dapm_post
:
1164 dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
1167 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1170 * snd_soc_dapm_get_volsw - dapm mixer get callback
1171 * @kcontrol: mixer control
1172 * @ucontrol: control element information
1174 * Callback to get the value of a dapm mixer control.
1176 * Returns 0 for success.
1178 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1179 struct snd_ctl_elem_value
*ucontrol
)
1181 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1182 struct soc_mixer_control
*mc
=
1183 (struct soc_mixer_control
*)kcontrol
->private_value
;
1184 unsigned int reg
= mc
->reg
;
1185 unsigned int shift
= mc
->shift
;
1186 unsigned int rshift
= mc
->rshift
;
1188 unsigned int invert
= mc
->invert
;
1189 unsigned int mask
= (1 << fls(max
)) - 1;
1191 /* return the saved value if we are powered down */
1192 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1193 ucontrol
->value
.integer
.value
[0] = widget
->saved_value
;
1197 ucontrol
->value
.integer
.value
[0] =
1198 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1199 if (shift
!= rshift
)
1200 ucontrol
->value
.integer
.value
[1] =
1201 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1203 ucontrol
->value
.integer
.value
[0] =
1204 max
- ucontrol
->value
.integer
.value
[0];
1205 if (shift
!= rshift
)
1206 ucontrol
->value
.integer
.value
[1] =
1207 max
- ucontrol
->value
.integer
.value
[1];
1212 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1215 * snd_soc_dapm_put_volsw - dapm mixer set callback
1216 * @kcontrol: mixer control
1217 * @ucontrol: control element information
1219 * Callback to set the value of a dapm mixer control.
1221 * Returns 0 for success.
1223 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1224 struct snd_ctl_elem_value
*ucontrol
)
1226 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1227 struct soc_mixer_control
*mc
=
1228 (struct soc_mixer_control
*)kcontrol
->private_value
;
1229 unsigned int reg
= mc
->reg
;
1230 unsigned int shift
= mc
->shift
;
1231 unsigned int rshift
= mc
->rshift
;
1233 unsigned int mask
= (1 << fls(max
)) - 1;
1234 unsigned int invert
= mc
->invert
;
1235 unsigned short val
, val2
, val_mask
;
1238 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1242 val_mask
= mask
<< shift
;
1244 if (shift
!= rshift
) {
1245 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1248 val_mask
|= mask
<< rshift
;
1249 val
|= val2
<< rshift
;
1252 mutex_lock(&widget
->codec
->mutex
);
1253 widget
->value
= val
;
1255 /* save volume value if the widget is powered down */
1256 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1257 widget
->saved_value
= val
;
1258 mutex_unlock(&widget
->codec
->mutex
);
1262 dapm_mixer_update_power(widget
, kcontrol
, reg
, val_mask
, val
, invert
);
1263 if (widget
->event
) {
1264 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1265 ret
= widget
->event(widget
, kcontrol
,
1266 SND_SOC_DAPM_PRE_REG
);
1272 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1273 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1274 ret
= widget
->event(widget
, kcontrol
,
1275 SND_SOC_DAPM_POST_REG
);
1277 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1280 mutex_unlock(&widget
->codec
->mutex
);
1283 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
1286 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1287 * @kcontrol: mixer control
1288 * @ucontrol: control element information
1290 * Callback to get the value of a dapm enumerated double mixer control.
1292 * Returns 0 for success.
1294 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
1295 struct snd_ctl_elem_value
*ucontrol
)
1297 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1298 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1299 unsigned short val
, bitmask
;
1301 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1303 val
= snd_soc_read(widget
->codec
, e
->reg
);
1304 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
1305 if (e
->shift_l
!= e
->shift_r
)
1306 ucontrol
->value
.enumerated
.item
[1] =
1307 (val
>> e
->shift_r
) & (bitmask
- 1);
1311 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
1314 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1315 * @kcontrol: mixer control
1316 * @ucontrol: control element information
1318 * Callback to set the value of a dapm enumerated double mixer control.
1320 * Returns 0 for success.
1322 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
1323 struct snd_ctl_elem_value
*ucontrol
)
1325 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1326 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1327 unsigned short val
, mux
;
1328 unsigned short mask
, bitmask
;
1331 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1333 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1335 mux
= ucontrol
->value
.enumerated
.item
[0];
1336 val
= mux
<< e
->shift_l
;
1337 mask
= (bitmask
- 1) << e
->shift_l
;
1338 if (e
->shift_l
!= e
->shift_r
) {
1339 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1341 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
1342 mask
|= (bitmask
- 1) << e
->shift_r
;
1345 mutex_lock(&widget
->codec
->mutex
);
1346 widget
->value
= val
;
1347 dapm_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1348 if (widget
->event
) {
1349 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1350 ret
= widget
->event(widget
,
1351 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1355 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1356 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1357 ret
= widget
->event(widget
,
1358 kcontrol
, SND_SOC_DAPM_POST_REG
);
1360 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1363 mutex_unlock(&widget
->codec
->mutex
);
1366 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
1369 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1371 * @kcontrol: mixer control
1372 * @ucontrol: control element information
1374 * Callback to get the value of a dapm semi enumerated double mixer control.
1376 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1377 * used for handling bitfield coded enumeration for example.
1379 * Returns 0 for success.
1381 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
1382 struct snd_ctl_elem_value
*ucontrol
)
1384 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1385 struct soc_value_enum
*e
= (struct soc_value_enum
*)
1386 kcontrol
->private_value
;
1387 unsigned short reg_val
, val
, mux
;
1389 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
1390 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
1391 for (mux
= 0; mux
< e
->max
; mux
++) {
1392 if (val
== e
->values
[mux
])
1395 ucontrol
->value
.enumerated
.item
[0] = mux
;
1396 if (e
->shift_l
!= e
->shift_r
) {
1397 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
1398 for (mux
= 0; mux
< e
->max
; mux
++) {
1399 if (val
== e
->values
[mux
])
1402 ucontrol
->value
.enumerated
.item
[1] = mux
;
1407 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
1410 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1412 * @kcontrol: mixer control
1413 * @ucontrol: control element information
1415 * Callback to set the value of a dapm semi enumerated double mixer control.
1417 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1418 * used for handling bitfield coded enumeration for example.
1420 * Returns 0 for success.
1422 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
1423 struct snd_ctl_elem_value
*ucontrol
)
1425 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1426 struct soc_value_enum
*e
= (struct soc_value_enum
*)
1427 kcontrol
->private_value
;
1428 unsigned short val
, mux
;
1429 unsigned short mask
;
1432 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1434 mux
= ucontrol
->value
.enumerated
.item
[0];
1435 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
1436 mask
= e
->mask
<< e
->shift_l
;
1437 if (e
->shift_l
!= e
->shift_r
) {
1438 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1440 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
1441 mask
|= e
->mask
<< e
->shift_r
;
1444 mutex_lock(&widget
->codec
->mutex
);
1445 widget
->value
= val
;
1446 dapm_value_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1447 if (widget
->event
) {
1448 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1449 ret
= widget
->event(widget
,
1450 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1454 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1455 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1456 ret
= widget
->event(widget
,
1457 kcontrol
, SND_SOC_DAPM_POST_REG
);
1459 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1462 mutex_unlock(&widget
->codec
->mutex
);
1465 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
1468 * snd_soc_dapm_new_control - create new dapm control
1469 * @codec: audio codec
1470 * @widget: widget template
1472 * Creates a new dapm control based upon the template.
1474 * Returns 0 for success else error.
1476 int snd_soc_dapm_new_control(struct snd_soc_codec
*codec
,
1477 const struct snd_soc_dapm_widget
*widget
)
1479 struct snd_soc_dapm_widget
*w
;
1481 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
1485 INIT_LIST_HEAD(&w
->sources
);
1486 INIT_LIST_HEAD(&w
->sinks
);
1487 INIT_LIST_HEAD(&w
->list
);
1488 list_add(&w
->list
, &codec
->dapm_widgets
);
1490 /* machine layer set ups unconnected pins and insertions */
1494 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
1497 * snd_soc_dapm_new_controls - create new dapm controls
1498 * @codec: audio codec
1499 * @widget: widget array
1500 * @num: number of widgets
1502 * Creates new DAPM controls based upon the templates.
1504 * Returns 0 for success else error.
1506 int snd_soc_dapm_new_controls(struct snd_soc_codec
*codec
,
1507 const struct snd_soc_dapm_widget
*widget
,
1512 for (i
= 0; i
< num
; i
++) {
1513 ret
= snd_soc_dapm_new_control(codec
, widget
);
1516 "ASoC: Failed to create DAPM control %s: %d\n",
1524 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
1528 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1529 * @codec: audio codec
1530 * @stream: stream name
1531 * @event: stream event
1533 * Sends a stream event to the dapm core. The core then makes any
1534 * necessary widget power changes.
1536 * Returns 0 for success else error.
1538 int snd_soc_dapm_stream_event(struct snd_soc_codec
*codec
,
1539 char *stream
, int event
)
1541 struct snd_soc_dapm_widget
*w
;
1546 mutex_lock(&codec
->mutex
);
1547 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1551 pr_debug("widget %s\n %s stream %s event %d\n",
1552 w
->name
, w
->sname
, stream
, event
);
1553 if (strstr(w
->sname
, stream
)) {
1555 case SND_SOC_DAPM_STREAM_START
:
1558 case SND_SOC_DAPM_STREAM_STOP
:
1561 case SND_SOC_DAPM_STREAM_SUSPEND
:
1566 case SND_SOC_DAPM_STREAM_RESUME
:
1572 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
1574 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
1579 mutex_unlock(&codec
->mutex
);
1581 dapm_power_widgets(codec
, event
);
1582 dump_dapm(codec
, __func__
);
1585 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event
);
1588 * snd_soc_dapm_set_bias_level - set the bias level for the system
1589 * @socdev: audio device
1590 * @level: level to configure
1592 * Configure the bias (power) levels for the SoC audio device.
1594 * Returns 0 for success else error.
1596 int snd_soc_dapm_set_bias_level(struct snd_soc_device
*socdev
,
1597 enum snd_soc_bias_level level
)
1599 struct snd_soc_codec
*codec
= socdev
->codec
;
1600 struct snd_soc_card
*card
= socdev
->card
;
1603 if (card
->set_bias_level
)
1604 ret
= card
->set_bias_level(card
, level
);
1605 if (ret
== 0 && codec
->set_bias_level
)
1606 ret
= codec
->set_bias_level(codec
, level
);
1612 * snd_soc_dapm_enable_pin - enable pin.
1616 * Enables input/output pin and it's parents or children widgets iff there is
1617 * a valid audio route and active audio stream.
1618 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1619 * do any widget power switching.
1621 int snd_soc_dapm_enable_pin(struct snd_soc_codec
*codec
, char *pin
)
1623 return snd_soc_dapm_set_pin(codec
, pin
, 1);
1625 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
1628 * snd_soc_dapm_disable_pin - disable pin.
1632 * Disables input/output pin and it's parents or children widgets.
1633 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1634 * do any widget power switching.
1636 int snd_soc_dapm_disable_pin(struct snd_soc_codec
*codec
, char *pin
)
1638 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1640 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
1643 * snd_soc_dapm_nc_pin - permanently disable pin.
1647 * Marks the specified pin as being not connected, disabling it along
1648 * any parent or child widgets. At present this is identical to
1649 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1650 * additional things such as disabling controls which only affect
1651 * paths through the pin.
1653 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1654 * do any widget power switching.
1656 int snd_soc_dapm_nc_pin(struct snd_soc_codec
*codec
, char *pin
)
1658 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1660 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
1663 * snd_soc_dapm_get_pin_status - get audio pin status
1664 * @codec: audio codec
1665 * @pin: audio signal pin endpoint (or start point)
1667 * Get audio pin status - connected or disconnected.
1669 * Returns 1 for connected otherwise 0.
1671 int snd_soc_dapm_get_pin_status(struct snd_soc_codec
*codec
, char *pin
)
1673 struct snd_soc_dapm_widget
*w
;
1675 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1676 if (!strcmp(w
->name
, pin
))
1677 return w
->connected
;
1682 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
1685 * snd_soc_dapm_free - free dapm resources
1686 * @socdev: SoC device
1688 * Free all dapm widgets and resources.
1690 void snd_soc_dapm_free(struct snd_soc_device
*socdev
)
1692 struct snd_soc_codec
*codec
= socdev
->codec
;
1694 snd_soc_dapm_sys_remove(socdev
->dev
);
1695 dapm_free_widgets(codec
);
1697 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
1699 /* Module information */
1700 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1701 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1702 MODULE_LICENSE("GPL");