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_mixer_named_ctl
, snd_soc_dapm_pga
,
58 snd_soc_dapm_adc
, snd_soc_dapm_hp
, snd_soc_dapm_spk
, snd_soc_dapm_post
61 static int dapm_down_seq
[] = {
62 snd_soc_dapm_pre
, snd_soc_dapm_adc
, snd_soc_dapm_hp
, snd_soc_dapm_spk
,
63 snd_soc_dapm_pga
, snd_soc_dapm_mixer_named_ctl
, snd_soc_dapm_mixer
,
64 snd_soc_dapm_dac
, snd_soc_dapm_mic
, snd_soc_dapm_micbias
,
65 snd_soc_dapm_mux
, snd_soc_dapm_value_mux
, snd_soc_dapm_post
68 static int dapm_status
= 1;
69 module_param(dapm_status
, int, 0);
70 MODULE_PARM_DESC(dapm_status
, "enable DPM sysfs entries");
72 static void pop_wait(u32 pop_time
)
75 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
78 static void pop_dbg(u32 pop_time
, const char *fmt
, ...)
92 /* create a new dapm widget */
93 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
94 const struct snd_soc_dapm_widget
*_widget
)
96 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
99 /* set up initial codec paths */
100 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
101 struct snd_soc_dapm_path
*p
, int i
)
104 case snd_soc_dapm_switch
:
105 case snd_soc_dapm_mixer
:
106 case snd_soc_dapm_mixer_named_ctl
: {
108 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
109 w
->kcontrols
[i
].private_value
;
110 unsigned int reg
= mc
->reg
;
111 unsigned int shift
= mc
->shift
;
113 unsigned int mask
= (1 << fls(max
)) - 1;
114 unsigned int invert
= mc
->invert
;
116 val
= snd_soc_read(w
->codec
, reg
);
117 val
= (val
>> shift
) & mask
;
119 if ((invert
&& !val
) || (!invert
&& val
))
125 case snd_soc_dapm_mux
: {
126 struct soc_enum
*e
= (struct soc_enum
*)w
->kcontrols
[i
].private_value
;
127 int val
, item
, bitmask
;
129 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
131 val
= snd_soc_read(w
->codec
, e
->reg
);
132 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
135 for (i
= 0; i
< e
->max
; i
++) {
136 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
141 case snd_soc_dapm_value_mux
: {
142 struct soc_enum
*e
= (struct soc_enum
*)
143 w
->kcontrols
[i
].private_value
;
146 val
= snd_soc_read(w
->codec
, e
->reg
);
147 val
= (val
>> e
->shift_l
) & e
->mask
;
148 for (item
= 0; item
< e
->max
; item
++) {
149 if (val
== e
->values
[item
])
154 for (i
= 0; i
< e
->max
; i
++) {
155 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
160 /* does not effect routing - always connected */
161 case snd_soc_dapm_pga
:
162 case snd_soc_dapm_output
:
163 case snd_soc_dapm_adc
:
164 case snd_soc_dapm_input
:
165 case snd_soc_dapm_dac
:
166 case snd_soc_dapm_micbias
:
167 case snd_soc_dapm_vmid
:
170 /* does effect routing - dynamically connected */
171 case snd_soc_dapm_hp
:
172 case snd_soc_dapm_mic
:
173 case snd_soc_dapm_spk
:
174 case snd_soc_dapm_line
:
175 case snd_soc_dapm_pre
:
176 case snd_soc_dapm_post
:
182 /* connect mux widget to it's interconnecting audio paths */
183 static int dapm_connect_mux(struct snd_soc_codec
*codec
,
184 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
185 struct snd_soc_dapm_path
*path
, const char *control_name
,
186 const struct snd_kcontrol_new
*kcontrol
)
188 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
191 for (i
= 0; i
< e
->max
; i
++) {
192 if (!(strcmp(control_name
, e
->texts
[i
]))) {
193 list_add(&path
->list
, &codec
->dapm_paths
);
194 list_add(&path
->list_sink
, &dest
->sources
);
195 list_add(&path
->list_source
, &src
->sinks
);
196 path
->name
= (char*)e
->texts
[i
];
197 dapm_set_path_status(dest
, path
, 0);
205 /* connect mixer widget to it's interconnecting audio paths */
206 static int dapm_connect_mixer(struct snd_soc_codec
*codec
,
207 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
208 struct snd_soc_dapm_path
*path
, const char *control_name
)
212 /* search for mixer kcontrol */
213 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
214 if (!strcmp(control_name
, dest
->kcontrols
[i
].name
)) {
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
= dest
->kcontrols
[i
].name
;
219 dapm_set_path_status(dest
, path
, i
);
226 /* update dapm codec register bits */
227 static int dapm_update_bits(struct snd_soc_dapm_widget
*widget
)
230 unsigned short old
, new;
231 struct snd_soc_codec
*codec
= widget
->codec
;
233 /* check for valid widgets */
234 if (widget
->reg
< 0 || widget
->id
== snd_soc_dapm_input
||
235 widget
->id
== snd_soc_dapm_output
||
236 widget
->id
== snd_soc_dapm_hp
||
237 widget
->id
== snd_soc_dapm_mic
||
238 widget
->id
== snd_soc_dapm_line
||
239 widget
->id
== snd_soc_dapm_spk
)
242 power
= widget
->power
;
244 power
= (power
? 0:1);
246 old
= snd_soc_read(codec
, widget
->reg
);
247 new = (old
& ~(0x1 << widget
->shift
)) | (power
<< widget
->shift
);
251 pop_dbg(codec
->pop_time
, "pop test %s : %s in %d ms\n",
252 widget
->name
, widget
->power
? "on" : "off",
254 snd_soc_write(codec
, widget
->reg
, new);
255 pop_wait(codec
->pop_time
);
257 pr_debug("reg %x old %x new %x change %d\n", widget
->reg
,
262 /* ramps the volume up or down to minimise pops before or after a
263 * DAPM power event */
264 static int dapm_set_pga(struct snd_soc_dapm_widget
*widget
, int power
)
266 const struct snd_kcontrol_new
*k
= widget
->kcontrols
;
268 if (widget
->muted
&& !power
)
270 if (!widget
->muted
&& power
)
273 if (widget
->num_kcontrols
&& k
) {
274 struct soc_mixer_control
*mc
=
275 (struct soc_mixer_control
*)k
->private_value
;
276 unsigned int reg
= mc
->reg
;
277 unsigned int shift
= mc
->shift
;
279 unsigned int mask
= (1 << fls(max
)) - 1;
280 unsigned int invert
= mc
->invert
;
284 /* power up has happended, increase volume to last level */
286 for (i
= max
; i
> widget
->saved_value
; i
--)
287 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
289 for (i
= 0; i
< widget
->saved_value
; i
++)
290 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
294 /* power down is about to occur, decrease volume to mute */
295 int val
= snd_soc_read(widget
->codec
, reg
);
296 int i
= widget
->saved_value
= (val
>> shift
) & mask
;
298 for (; i
< mask
; i
++)
299 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
302 snd_soc_update_bits(widget
->codec
, reg
, mask
, i
);
310 /* create new dapm mixer control */
311 static int dapm_new_mixer(struct snd_soc_codec
*codec
,
312 struct snd_soc_dapm_widget
*w
)
316 struct snd_soc_dapm_path
*path
;
319 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
322 list_for_each_entry(path
, &w
->sources
, list_sink
) {
324 /* mixer/mux paths name must match control name */
325 if (path
->name
!= (char*)w
->kcontrols
[i
].name
)
328 /* add dapm control with long name.
329 * for dapm_mixer this is the concatenation of the
330 * mixer and kcontrol name.
331 * for dapm_mixer_named_ctl this is simply the
334 name_len
= strlen(w
->kcontrols
[i
].name
) + 1;
335 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
336 name_len
+= 1 + strlen(w
->name
);
338 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
340 if (path
->long_name
== NULL
)
345 snprintf(path
->long_name
, name_len
, "%s %s",
346 w
->name
, w
->kcontrols
[i
].name
);
348 case snd_soc_dapm_mixer_named_ctl
:
349 snprintf(path
->long_name
, name_len
, "%s",
350 w
->kcontrols
[i
].name
);
354 path
->long_name
[name_len
- 1] = '\0';
356 path
->kcontrol
= snd_soc_cnew(&w
->kcontrols
[i
], w
,
358 ret
= snd_ctl_add(codec
->card
, path
->kcontrol
);
360 printk(KERN_ERR
"asoc: failed to add dapm kcontrol %s: %d\n",
363 kfree(path
->long_name
);
364 path
->long_name
= NULL
;
372 /* create new dapm mux control */
373 static int dapm_new_mux(struct snd_soc_codec
*codec
,
374 struct snd_soc_dapm_widget
*w
)
376 struct snd_soc_dapm_path
*path
= NULL
;
377 struct snd_kcontrol
*kcontrol
;
380 if (!w
->num_kcontrols
) {
381 printk(KERN_ERR
"asoc: mux %s has no controls\n", w
->name
);
385 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
386 ret
= snd_ctl_add(codec
->card
, kcontrol
);
390 list_for_each_entry(path
, &w
->sources
, list_sink
)
391 path
->kcontrol
= kcontrol
;
396 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
400 /* create new dapm volume control */
401 static int dapm_new_pga(struct snd_soc_codec
*codec
,
402 struct snd_soc_dapm_widget
*w
)
404 struct snd_kcontrol
*kcontrol
;
407 if (!w
->num_kcontrols
)
410 kcontrol
= snd_soc_cnew(&w
->kcontrols
[0], w
, w
->name
);
411 ret
= snd_ctl_add(codec
->card
, kcontrol
);
413 printk(KERN_ERR
"asoc: failed to add kcontrol %s\n", w
->name
);
420 /* reset 'walked' bit for each dapm path */
421 static inline void dapm_clear_walk(struct snd_soc_codec
*codec
)
423 struct snd_soc_dapm_path
*p
;
425 list_for_each_entry(p
, &codec
->dapm_paths
, list
)
430 * Recursively check for a completed path to an active or physically connected
431 * output widget. Returns number of complete paths.
433 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
435 struct snd_soc_dapm_path
*path
;
438 if (widget
->id
== snd_soc_dapm_adc
&& widget
->active
)
441 if (widget
->connected
) {
442 /* connected pin ? */
443 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
446 /* connected jack or spk ? */
447 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
448 widget
->id
== snd_soc_dapm_line
)
452 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
456 if (path
->sink
&& path
->connect
) {
458 con
+= is_connected_output_ep(path
->sink
);
466 * Recursively check for a completed path to an active or physically connected
467 * input widget. Returns number of complete paths.
469 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
471 struct snd_soc_dapm_path
*path
;
474 /* active stream ? */
475 if (widget
->id
== snd_soc_dapm_dac
&& widget
->active
)
478 if (widget
->connected
) {
479 /* connected pin ? */
480 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
483 /* connected VMID/Bias for lower pops */
484 if (widget
->id
== snd_soc_dapm_vmid
)
487 /* connected jack ? */
488 if (widget
->id
== snd_soc_dapm_mic
|| widget
->id
== snd_soc_dapm_line
)
492 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
496 if (path
->source
&& path
->connect
) {
498 con
+= is_connected_input_ep(path
->source
);
506 * Handler for generic register modifier widget.
508 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
509 struct snd_kcontrol
*kcontrol
, int event
)
513 if (SND_SOC_DAPM_EVENT_ON(event
))
518 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
519 w
->mask
<< w
->shift
, val
<< w
->shift
);
523 EXPORT_SYMBOL_GPL(dapm_reg_event
);
525 /* Standard power change method, used to apply power changes to most
528 static int dapm_generic_apply_power(struct snd_soc_dapm_widget
*w
)
532 /* call any power change event handlers */
534 pr_debug("power %s event for %s flags %x\n",
535 w
->power
? "on" : "off",
536 w
->name
, w
->event_flags
);
538 /* power up pre event */
539 if (w
->power
&& w
->event
&&
540 (w
->event_flags
& SND_SOC_DAPM_PRE_PMU
)) {
541 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMU
);
546 /* power down pre event */
547 if (!w
->power
&& w
->event
&&
548 (w
->event_flags
& SND_SOC_DAPM_PRE_PMD
)) {
549 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_PRE_PMD
);
554 /* Lower PGA volume to reduce pops */
555 if (w
->id
== snd_soc_dapm_pga
&& !w
->power
)
556 dapm_set_pga(w
, w
->power
);
560 /* Raise PGA volume to reduce pops */
561 if (w
->id
== snd_soc_dapm_pga
&& w
->power
)
562 dapm_set_pga(w
, w
->power
);
564 /* power up post event */
565 if (w
->power
&& w
->event
&&
566 (w
->event_flags
& SND_SOC_DAPM_POST_PMU
)) {
568 NULL
, SND_SOC_DAPM_POST_PMU
);
573 /* power down post event */
574 if (!w
->power
&& w
->event
&&
575 (w
->event_flags
& SND_SOC_DAPM_POST_PMD
)) {
576 ret
= w
->event(w
, NULL
, SND_SOC_DAPM_POST_PMD
);
584 /* Generic check to see if a widget should be powered.
586 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
590 in
= is_connected_input_ep(w
);
591 dapm_clear_walk(w
->codec
);
592 out
= is_connected_output_ep(w
);
593 dapm_clear_walk(w
->codec
);
594 return out
!= 0 && in
!= 0;
597 /* Check to see if an ADC has power */
598 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
603 in
= is_connected_input_ep(w
);
604 dapm_clear_walk(w
->codec
);
607 return dapm_generic_check_power(w
);
611 /* Check to see if a DAC has power */
612 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
617 out
= is_connected_output_ep(w
);
618 dapm_clear_walk(w
->codec
);
621 return dapm_generic_check_power(w
);
626 * Scan a single DAPM widget for a complete audio path and update the
627 * power status appropriately.
629 static int dapm_power_widget(struct snd_soc_codec
*codec
, int event
,
630 struct snd_soc_dapm_widget
*w
)
634 /* Work out the new power state */
636 case snd_soc_dapm_vmid
:
637 /* No action required */
640 case snd_soc_dapm_adc
:
641 power
= dapm_adc_check_power(w
);
644 case snd_soc_dapm_dac
:
645 power
= dapm_dac_check_power(w
);
648 case snd_soc_dapm_pre
:
652 if (event
== SND_SOC_DAPM_STREAM_START
) {
654 NULL
, SND_SOC_DAPM_PRE_PMU
);
657 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
659 NULL
, SND_SOC_DAPM_PRE_PMD
);
665 case snd_soc_dapm_post
:
669 if (event
== SND_SOC_DAPM_STREAM_START
) {
671 NULL
, SND_SOC_DAPM_POST_PMU
);
674 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
676 NULL
, SND_SOC_DAPM_POST_PMD
);
683 power
= dapm_generic_check_power(w
);
687 if (w
->power
== power
)
691 return dapm_generic_apply_power(w
);
695 * Scan each dapm widget for complete audio path.
696 * A complete path is a route that has valid endpoints i.e.:-
698 * o DAC to output pin.
699 * o Input Pin to ADC.
700 * o Input pin to Output pin (bypass, sidetone)
701 * o DAC to ADC (loopback).
703 static int dapm_power_widgets(struct snd_soc_codec
*codec
, int event
)
705 struct snd_soc_dapm_widget
*w
;
706 int i
, c
= 1, *seq
= NULL
, ret
= 0;
708 /* do we have a sequenced stream event */
709 if (event
== SND_SOC_DAPM_STREAM_START
) {
710 c
= ARRAY_SIZE(dapm_up_seq
);
712 } else if (event
== SND_SOC_DAPM_STREAM_STOP
) {
713 c
= ARRAY_SIZE(dapm_down_seq
);
717 for (i
= 0; i
< c
; i
++) {
718 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
720 /* is widget in stream order */
721 if (seq
&& seq
[i
] && w
->id
!= seq
[i
])
724 ret
= dapm_power_widget(codec
, event
, w
);
734 static void dbg_dump_dapm(struct snd_soc_codec
* codec
, const char *action
)
736 struct snd_soc_dapm_widget
*w
;
737 struct snd_soc_dapm_path
*p
= NULL
;
740 printk("DAPM %s %s\n", codec
->name
, action
);
742 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
744 /* only display widgets that effect routing */
746 case snd_soc_dapm_pre
:
747 case snd_soc_dapm_post
:
748 case snd_soc_dapm_vmid
:
750 case snd_soc_dapm_mux
:
751 case snd_soc_dapm_value_mux
:
752 case snd_soc_dapm_output
:
753 case snd_soc_dapm_input
:
754 case snd_soc_dapm_switch
:
755 case snd_soc_dapm_hp
:
756 case snd_soc_dapm_mic
:
757 case snd_soc_dapm_spk
:
758 case snd_soc_dapm_line
:
759 case snd_soc_dapm_micbias
:
760 case snd_soc_dapm_dac
:
761 case snd_soc_dapm_adc
:
762 case snd_soc_dapm_pga
:
763 case snd_soc_dapm_mixer
:
764 case snd_soc_dapm_mixer_named_ctl
:
766 in
= is_connected_input_ep(w
);
767 dapm_clear_walk(w
->codec
);
768 out
= is_connected_output_ep(w
);
769 dapm_clear_walk(w
->codec
);
770 printk("%s: %s in %d out %d\n", w
->name
,
771 w
->power
? "On":"Off",in
, out
);
773 list_for_each_entry(p
, &w
->sources
, list_sink
) {
775 printk(" in %s %s\n", p
->name
? p
->name
: "static",
778 list_for_each_entry(p
, &w
->sinks
, list_source
) {
780 printk(" out %s %s\n", p
->name
? p
->name
: "static",
790 /* test and update the power status of a mux widget */
791 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
792 struct snd_kcontrol
*kcontrol
, int mask
,
793 int mux
, int val
, struct soc_enum
*e
)
795 struct snd_soc_dapm_path
*path
;
798 if (widget
->id
!= snd_soc_dapm_mux
&&
799 widget
->id
!= snd_soc_dapm_value_mux
)
802 if (!snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
))
805 /* find dapm widget path assoc with kcontrol */
806 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
807 if (path
->kcontrol
!= kcontrol
)
810 if (!path
->name
|| !e
->texts
[mux
])
814 /* we now need to match the string in the enum to the path */
815 if (!(strcmp(path
->name
, e
->texts
[mux
])))
816 path
->connect
= 1; /* new connection */
818 path
->connect
= 0; /* old connection must be powered down */
822 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
823 dump_dapm(widget
->codec
, "mux power update");
829 /* test and update the power status of a mixer or switch widget */
830 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
831 struct snd_kcontrol
*kcontrol
, int reg
,
832 int val_mask
, int val
, int invert
)
834 struct snd_soc_dapm_path
*path
;
837 if (widget
->id
!= snd_soc_dapm_mixer
&&
838 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
839 widget
->id
!= snd_soc_dapm_switch
)
842 if (!snd_soc_test_bits(widget
->codec
, reg
, val_mask
, val
))
845 /* find dapm widget path assoc with kcontrol */
846 list_for_each_entry(path
, &widget
->codec
->dapm_paths
, list
) {
847 if (path
->kcontrol
!= kcontrol
)
850 /* found, now check type */
854 path
->connect
= invert
? 0:1;
856 /* old connection must be powered down */
857 path
->connect
= invert
? 1:0;
862 dapm_power_widgets(widget
->codec
, SND_SOC_DAPM_STREAM_NOP
);
863 dump_dapm(widget
->codec
, "mixer power update");
869 /* show dapm widget status in sys fs */
870 static ssize_t
dapm_widget_show(struct device
*dev
,
871 struct device_attribute
*attr
, char *buf
)
873 struct snd_soc_device
*devdata
= dev_get_drvdata(dev
);
874 struct snd_soc_codec
*codec
= devdata
->card
->codec
;
875 struct snd_soc_dapm_widget
*w
;
877 char *state
= "not set";
879 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
881 /* only display widgets that burnm power */
883 case snd_soc_dapm_hp
:
884 case snd_soc_dapm_mic
:
885 case snd_soc_dapm_spk
:
886 case snd_soc_dapm_line
:
887 case snd_soc_dapm_micbias
:
888 case snd_soc_dapm_dac
:
889 case snd_soc_dapm_adc
:
890 case snd_soc_dapm_pga
:
891 case snd_soc_dapm_mixer
:
892 case snd_soc_dapm_mixer_named_ctl
:
894 count
+= sprintf(buf
+ count
, "%s: %s\n",
895 w
->name
, w
->power
? "On":"Off");
902 switch (codec
->bias_level
) {
903 case SND_SOC_BIAS_ON
:
906 case SND_SOC_BIAS_PREPARE
:
909 case SND_SOC_BIAS_STANDBY
:
912 case SND_SOC_BIAS_OFF
:
916 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
921 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
923 int snd_soc_dapm_sys_add(struct device
*dev
)
927 return device_create_file(dev
, &dev_attr_dapm_widget
);
930 static void snd_soc_dapm_sys_remove(struct device
*dev
)
933 device_remove_file(dev
, &dev_attr_dapm_widget
);
937 /* free all dapm widgets and resources */
938 static void dapm_free_widgets(struct snd_soc_codec
*codec
)
940 struct snd_soc_dapm_widget
*w
, *next_w
;
941 struct snd_soc_dapm_path
*p
, *next_p
;
943 list_for_each_entry_safe(w
, next_w
, &codec
->dapm_widgets
, list
) {
948 list_for_each_entry_safe(p
, next_p
, &codec
->dapm_paths
, list
) {
955 static int snd_soc_dapm_set_pin(struct snd_soc_codec
*codec
,
956 const char *pin
, int status
)
958 struct snd_soc_dapm_widget
*w
;
960 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
961 if (!strcmp(w
->name
, pin
)) {
962 pr_debug("dapm: %s: pin %s\n", codec
->name
, pin
);
963 w
->connected
= status
;
968 pr_err("dapm: %s: configuring unknown pin %s\n", codec
->name
, pin
);
973 * snd_soc_dapm_sync - scan and power dapm paths
974 * @codec: audio codec
976 * Walks all dapm audio paths and powers widgets according to their
977 * stream or path usage.
979 * Returns 0 for success.
981 int snd_soc_dapm_sync(struct snd_soc_codec
*codec
)
983 int ret
= dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
984 dump_dapm(codec
, "sync");
987 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
989 static int snd_soc_dapm_add_route(struct snd_soc_codec
*codec
,
990 const char *sink
, const char *control
, const char *source
)
992 struct snd_soc_dapm_path
*path
;
993 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
996 /* find src and dest widgets */
997 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
999 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1003 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1008 if (wsource
== NULL
|| wsink
== NULL
)
1011 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1015 path
->source
= wsource
;
1017 INIT_LIST_HEAD(&path
->list
);
1018 INIT_LIST_HEAD(&path
->list_source
);
1019 INIT_LIST_HEAD(&path
->list_sink
);
1021 /* check for external widgets */
1022 if (wsink
->id
== snd_soc_dapm_input
) {
1023 if (wsource
->id
== snd_soc_dapm_micbias
||
1024 wsource
->id
== snd_soc_dapm_mic
||
1025 wsink
->id
== snd_soc_dapm_line
||
1026 wsink
->id
== snd_soc_dapm_output
)
1029 if (wsource
->id
== snd_soc_dapm_output
) {
1030 if (wsink
->id
== snd_soc_dapm_spk
||
1031 wsink
->id
== snd_soc_dapm_hp
||
1032 wsink
->id
== snd_soc_dapm_line
||
1033 wsink
->id
== snd_soc_dapm_input
)
1037 /* connect static paths */
1038 if (control
== NULL
) {
1039 list_add(&path
->list
, &codec
->dapm_paths
);
1040 list_add(&path
->list_sink
, &wsink
->sources
);
1041 list_add(&path
->list_source
, &wsource
->sinks
);
1046 /* connect dynamic paths */
1048 case snd_soc_dapm_adc
:
1049 case snd_soc_dapm_dac
:
1050 case snd_soc_dapm_pga
:
1051 case snd_soc_dapm_input
:
1052 case snd_soc_dapm_output
:
1053 case snd_soc_dapm_micbias
:
1054 case snd_soc_dapm_vmid
:
1055 case snd_soc_dapm_pre
:
1056 case snd_soc_dapm_post
:
1057 list_add(&path
->list
, &codec
->dapm_paths
);
1058 list_add(&path
->list_sink
, &wsink
->sources
);
1059 list_add(&path
->list_source
, &wsource
->sinks
);
1062 case snd_soc_dapm_mux
:
1063 case snd_soc_dapm_value_mux
:
1064 ret
= dapm_connect_mux(codec
, wsource
, wsink
, path
, control
,
1065 &wsink
->kcontrols
[0]);
1069 case snd_soc_dapm_switch
:
1070 case snd_soc_dapm_mixer
:
1071 case snd_soc_dapm_mixer_named_ctl
:
1072 ret
= dapm_connect_mixer(codec
, wsource
, wsink
, path
, control
);
1076 case snd_soc_dapm_hp
:
1077 case snd_soc_dapm_mic
:
1078 case snd_soc_dapm_line
:
1079 case snd_soc_dapm_spk
:
1080 list_add(&path
->list
, &codec
->dapm_paths
);
1081 list_add(&path
->list_sink
, &wsink
->sources
);
1082 list_add(&path
->list_source
, &wsource
->sinks
);
1089 printk(KERN_WARNING
"asoc: no dapm match for %s --> %s --> %s\n", source
,
1096 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1098 * @route: audio routes
1099 * @num: number of routes
1101 * Connects 2 dapm widgets together via a named audio path. The sink is
1102 * the widget receiving the audio signal, whilst the source is the sender
1103 * of the audio signal.
1105 * Returns 0 for success else error. On error all resources can be freed
1106 * with a call to snd_soc_card_free().
1108 int snd_soc_dapm_add_routes(struct snd_soc_codec
*codec
,
1109 const struct snd_soc_dapm_route
*route
, int num
)
1113 for (i
= 0; i
< num
; i
++) {
1114 ret
= snd_soc_dapm_add_route(codec
, route
->sink
,
1115 route
->control
, route
->source
);
1117 printk(KERN_ERR
"Failed to add route %s->%s\n",
1127 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1130 * snd_soc_dapm_new_widgets - add new dapm widgets
1131 * @codec: audio codec
1133 * Checks the codec for any new dapm widgets and creates them if found.
1135 * Returns 0 for success.
1137 int snd_soc_dapm_new_widgets(struct snd_soc_codec
*codec
)
1139 struct snd_soc_dapm_widget
*w
;
1141 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1147 case snd_soc_dapm_switch
:
1148 case snd_soc_dapm_mixer
:
1149 case snd_soc_dapm_mixer_named_ctl
:
1150 dapm_new_mixer(codec
, w
);
1152 case snd_soc_dapm_mux
:
1153 case snd_soc_dapm_value_mux
:
1154 dapm_new_mux(codec
, w
);
1156 case snd_soc_dapm_adc
:
1157 case snd_soc_dapm_dac
:
1158 case snd_soc_dapm_pga
:
1159 dapm_new_pga(codec
, w
);
1161 case snd_soc_dapm_input
:
1162 case snd_soc_dapm_output
:
1163 case snd_soc_dapm_micbias
:
1164 case snd_soc_dapm_spk
:
1165 case snd_soc_dapm_hp
:
1166 case snd_soc_dapm_mic
:
1167 case snd_soc_dapm_line
:
1168 case snd_soc_dapm_vmid
:
1169 case snd_soc_dapm_pre
:
1170 case snd_soc_dapm_post
:
1176 dapm_power_widgets(codec
, SND_SOC_DAPM_STREAM_NOP
);
1179 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1182 * snd_soc_dapm_get_volsw - dapm mixer get callback
1183 * @kcontrol: mixer control
1184 * @ucontrol: control element information
1186 * Callback to get the value of a dapm mixer control.
1188 * Returns 0 for success.
1190 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1191 struct snd_ctl_elem_value
*ucontrol
)
1193 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1194 struct soc_mixer_control
*mc
=
1195 (struct soc_mixer_control
*)kcontrol
->private_value
;
1196 unsigned int reg
= mc
->reg
;
1197 unsigned int shift
= mc
->shift
;
1198 unsigned int rshift
= mc
->rshift
;
1200 unsigned int invert
= mc
->invert
;
1201 unsigned int mask
= (1 << fls(max
)) - 1;
1203 /* return the saved value if we are powered down */
1204 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1205 ucontrol
->value
.integer
.value
[0] = widget
->saved_value
;
1209 ucontrol
->value
.integer
.value
[0] =
1210 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1211 if (shift
!= rshift
)
1212 ucontrol
->value
.integer
.value
[1] =
1213 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1215 ucontrol
->value
.integer
.value
[0] =
1216 max
- ucontrol
->value
.integer
.value
[0];
1217 if (shift
!= rshift
)
1218 ucontrol
->value
.integer
.value
[1] =
1219 max
- ucontrol
->value
.integer
.value
[1];
1224 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1227 * snd_soc_dapm_put_volsw - dapm mixer set callback
1228 * @kcontrol: mixer control
1229 * @ucontrol: control element information
1231 * Callback to set the value of a dapm mixer control.
1233 * Returns 0 for success.
1235 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1236 struct snd_ctl_elem_value
*ucontrol
)
1238 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1239 struct soc_mixer_control
*mc
=
1240 (struct soc_mixer_control
*)kcontrol
->private_value
;
1241 unsigned int reg
= mc
->reg
;
1242 unsigned int shift
= mc
->shift
;
1243 unsigned int rshift
= mc
->rshift
;
1245 unsigned int mask
= (1 << fls(max
)) - 1;
1246 unsigned int invert
= mc
->invert
;
1247 unsigned short val
, val2
, val_mask
;
1250 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1254 val_mask
= mask
<< shift
;
1256 if (shift
!= rshift
) {
1257 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1260 val_mask
|= mask
<< rshift
;
1261 val
|= val2
<< rshift
;
1264 mutex_lock(&widget
->codec
->mutex
);
1265 widget
->value
= val
;
1267 /* save volume value if the widget is powered down */
1268 if (widget
->id
== snd_soc_dapm_pga
&& !widget
->power
) {
1269 widget
->saved_value
= val
;
1270 mutex_unlock(&widget
->codec
->mutex
);
1274 dapm_mixer_update_power(widget
, kcontrol
, reg
, val_mask
, val
, invert
);
1275 if (widget
->event
) {
1276 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1277 ret
= widget
->event(widget
, kcontrol
,
1278 SND_SOC_DAPM_PRE_REG
);
1284 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1285 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1286 ret
= widget
->event(widget
, kcontrol
,
1287 SND_SOC_DAPM_POST_REG
);
1289 ret
= snd_soc_update_bits(widget
->codec
, reg
, val_mask
, val
);
1292 mutex_unlock(&widget
->codec
->mutex
);
1295 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
1298 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1299 * @kcontrol: mixer control
1300 * @ucontrol: control element information
1302 * Callback to get the value of a dapm enumerated double mixer control.
1304 * Returns 0 for success.
1306 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
1307 struct snd_ctl_elem_value
*ucontrol
)
1309 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1310 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1311 unsigned short val
, bitmask
;
1313 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1315 val
= snd_soc_read(widget
->codec
, e
->reg
);
1316 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
1317 if (e
->shift_l
!= e
->shift_r
)
1318 ucontrol
->value
.enumerated
.item
[1] =
1319 (val
>> e
->shift_r
) & (bitmask
- 1);
1323 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
1326 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1327 * @kcontrol: mixer control
1328 * @ucontrol: control element information
1330 * Callback to set the value of a dapm enumerated double mixer control.
1332 * Returns 0 for success.
1334 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
1335 struct snd_ctl_elem_value
*ucontrol
)
1337 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1338 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1339 unsigned short val
, mux
;
1340 unsigned short mask
, bitmask
;
1343 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1345 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1347 mux
= ucontrol
->value
.enumerated
.item
[0];
1348 val
= mux
<< e
->shift_l
;
1349 mask
= (bitmask
- 1) << e
->shift_l
;
1350 if (e
->shift_l
!= e
->shift_r
) {
1351 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1353 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
1354 mask
|= (bitmask
- 1) << e
->shift_r
;
1357 mutex_lock(&widget
->codec
->mutex
);
1358 widget
->value
= val
;
1359 dapm_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1360 if (widget
->event
) {
1361 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1362 ret
= widget
->event(widget
,
1363 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1367 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1368 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1369 ret
= widget
->event(widget
,
1370 kcontrol
, SND_SOC_DAPM_POST_REG
);
1372 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1375 mutex_unlock(&widget
->codec
->mutex
);
1378 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
1381 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1383 * @kcontrol: mixer control
1384 * @ucontrol: control element information
1386 * Callback to get the value of a dapm semi enumerated double mixer control.
1388 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1389 * used for handling bitfield coded enumeration for example.
1391 * Returns 0 for success.
1393 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
1394 struct snd_ctl_elem_value
*ucontrol
)
1396 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1397 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1398 unsigned short reg_val
, val
, mux
;
1400 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
1401 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
1402 for (mux
= 0; mux
< e
->max
; mux
++) {
1403 if (val
== e
->values
[mux
])
1406 ucontrol
->value
.enumerated
.item
[0] = mux
;
1407 if (e
->shift_l
!= e
->shift_r
) {
1408 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
1409 for (mux
= 0; mux
< e
->max
; mux
++) {
1410 if (val
== e
->values
[mux
])
1413 ucontrol
->value
.enumerated
.item
[1] = mux
;
1418 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
1421 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1423 * @kcontrol: mixer control
1424 * @ucontrol: control element information
1426 * Callback to set the value of a dapm semi enumerated double mixer control.
1428 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1429 * used for handling bitfield coded enumeration for example.
1431 * Returns 0 for success.
1433 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
1434 struct snd_ctl_elem_value
*ucontrol
)
1436 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1437 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1438 unsigned short val
, mux
;
1439 unsigned short mask
;
1442 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1444 mux
= ucontrol
->value
.enumerated
.item
[0];
1445 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
1446 mask
= e
->mask
<< e
->shift_l
;
1447 if (e
->shift_l
!= e
->shift_r
) {
1448 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1450 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
1451 mask
|= e
->mask
<< e
->shift_r
;
1454 mutex_lock(&widget
->codec
->mutex
);
1455 widget
->value
= val
;
1456 dapm_mux_update_power(widget
, kcontrol
, mask
, mux
, val
, e
);
1457 if (widget
->event
) {
1458 if (widget
->event_flags
& SND_SOC_DAPM_PRE_REG
) {
1459 ret
= widget
->event(widget
,
1460 kcontrol
, SND_SOC_DAPM_PRE_REG
);
1464 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1465 if (widget
->event_flags
& SND_SOC_DAPM_POST_REG
)
1466 ret
= widget
->event(widget
,
1467 kcontrol
, SND_SOC_DAPM_POST_REG
);
1469 ret
= snd_soc_update_bits(widget
->codec
, e
->reg
, mask
, val
);
1472 mutex_unlock(&widget
->codec
->mutex
);
1475 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
1478 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1480 * @kcontrol: mixer control
1481 * @uinfo: control element information
1483 * Callback to provide information about a pin switch control.
1485 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
1486 struct snd_ctl_elem_info
*uinfo
)
1488 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1490 uinfo
->value
.integer
.min
= 0;
1491 uinfo
->value
.integer
.max
= 1;
1495 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
1498 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1500 * @kcontrol: mixer control
1503 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
1504 struct snd_ctl_elem_value
*ucontrol
)
1506 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1507 const char *pin
= (const char *)kcontrol
->private_value
;
1509 mutex_lock(&codec
->mutex
);
1511 ucontrol
->value
.integer
.value
[0] =
1512 snd_soc_dapm_get_pin_status(codec
, pin
);
1514 mutex_unlock(&codec
->mutex
);
1518 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
1521 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1523 * @kcontrol: mixer control
1526 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
1527 struct snd_ctl_elem_value
*ucontrol
)
1529 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1530 const char *pin
= (const char *)kcontrol
->private_value
;
1532 mutex_lock(&codec
->mutex
);
1534 if (ucontrol
->value
.integer
.value
[0])
1535 snd_soc_dapm_enable_pin(codec
, pin
);
1537 snd_soc_dapm_disable_pin(codec
, pin
);
1539 snd_soc_dapm_sync(codec
);
1541 mutex_unlock(&codec
->mutex
);
1545 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
1548 * snd_soc_dapm_new_control - create new dapm control
1549 * @codec: audio codec
1550 * @widget: widget template
1552 * Creates a new dapm control based upon the template.
1554 * Returns 0 for success else error.
1556 int snd_soc_dapm_new_control(struct snd_soc_codec
*codec
,
1557 const struct snd_soc_dapm_widget
*widget
)
1559 struct snd_soc_dapm_widget
*w
;
1561 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
1565 INIT_LIST_HEAD(&w
->sources
);
1566 INIT_LIST_HEAD(&w
->sinks
);
1567 INIT_LIST_HEAD(&w
->list
);
1568 list_add(&w
->list
, &codec
->dapm_widgets
);
1570 /* machine layer set ups unconnected pins and insertions */
1574 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
1577 * snd_soc_dapm_new_controls - create new dapm controls
1578 * @codec: audio codec
1579 * @widget: widget array
1580 * @num: number of widgets
1582 * Creates new DAPM controls based upon the templates.
1584 * Returns 0 for success else error.
1586 int snd_soc_dapm_new_controls(struct snd_soc_codec
*codec
,
1587 const struct snd_soc_dapm_widget
*widget
,
1592 for (i
= 0; i
< num
; i
++) {
1593 ret
= snd_soc_dapm_new_control(codec
, widget
);
1596 "ASoC: Failed to create DAPM control %s: %d\n",
1604 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
1608 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1609 * @codec: audio codec
1610 * @stream: stream name
1611 * @event: stream event
1613 * Sends a stream event to the dapm core. The core then makes any
1614 * necessary widget power changes.
1616 * Returns 0 for success else error.
1618 int snd_soc_dapm_stream_event(struct snd_soc_codec
*codec
,
1619 char *stream
, int event
)
1621 struct snd_soc_dapm_widget
*w
;
1626 mutex_lock(&codec
->mutex
);
1627 list_for_each_entry(w
, &codec
->dapm_widgets
, list
)
1631 pr_debug("widget %s\n %s stream %s event %d\n",
1632 w
->name
, w
->sname
, stream
, event
);
1633 if (strstr(w
->sname
, stream
)) {
1635 case SND_SOC_DAPM_STREAM_START
:
1638 case SND_SOC_DAPM_STREAM_STOP
:
1641 case SND_SOC_DAPM_STREAM_SUSPEND
:
1646 case SND_SOC_DAPM_STREAM_RESUME
:
1652 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
1654 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
1659 mutex_unlock(&codec
->mutex
);
1661 dapm_power_widgets(codec
, event
);
1662 dump_dapm(codec
, __func__
);
1665 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event
);
1668 * snd_soc_dapm_set_bias_level - set the bias level for the system
1669 * @socdev: audio device
1670 * @level: level to configure
1672 * Configure the bias (power) levels for the SoC audio device.
1674 * Returns 0 for success else error.
1676 int snd_soc_dapm_set_bias_level(struct snd_soc_device
*socdev
,
1677 enum snd_soc_bias_level level
)
1679 struct snd_soc_card
*card
= socdev
->card
;
1680 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1683 if (card
->set_bias_level
)
1684 ret
= card
->set_bias_level(card
, level
);
1685 if (ret
== 0 && codec
->set_bias_level
)
1686 ret
= codec
->set_bias_level(codec
, level
);
1692 * snd_soc_dapm_enable_pin - enable pin.
1696 * Enables input/output pin and it's parents or children widgets iff there is
1697 * a valid audio route and active audio stream.
1698 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1699 * do any widget power switching.
1701 int snd_soc_dapm_enable_pin(struct snd_soc_codec
*codec
, const char *pin
)
1703 return snd_soc_dapm_set_pin(codec
, pin
, 1);
1705 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
1708 * snd_soc_dapm_disable_pin - disable pin.
1712 * Disables input/output pin and it's parents or children widgets.
1713 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1714 * do any widget power switching.
1716 int snd_soc_dapm_disable_pin(struct snd_soc_codec
*codec
, const char *pin
)
1718 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1720 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
1723 * snd_soc_dapm_nc_pin - permanently disable pin.
1727 * Marks the specified pin as being not connected, disabling it along
1728 * any parent or child widgets. At present this is identical to
1729 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1730 * additional things such as disabling controls which only affect
1731 * paths through the pin.
1733 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1734 * do any widget power switching.
1736 int snd_soc_dapm_nc_pin(struct snd_soc_codec
*codec
, const char *pin
)
1738 return snd_soc_dapm_set_pin(codec
, pin
, 0);
1740 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
1743 * snd_soc_dapm_get_pin_status - get audio pin status
1744 * @codec: audio codec
1745 * @pin: audio signal pin endpoint (or start point)
1747 * Get audio pin status - connected or disconnected.
1749 * Returns 1 for connected otherwise 0.
1751 int snd_soc_dapm_get_pin_status(struct snd_soc_codec
*codec
, const char *pin
)
1753 struct snd_soc_dapm_widget
*w
;
1755 list_for_each_entry(w
, &codec
->dapm_widgets
, list
) {
1756 if (!strcmp(w
->name
, pin
))
1757 return w
->connected
;
1762 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
1765 * snd_soc_dapm_free - free dapm resources
1766 * @socdev: SoC device
1768 * Free all dapm widgets and resources.
1770 void snd_soc_dapm_free(struct snd_soc_device
*socdev
)
1772 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1774 snd_soc_dapm_sys_remove(socdev
->dev
);
1775 dapm_free_widgets(codec
);
1777 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
1779 /* Module information */
1780 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1781 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1782 MODULE_LICENSE("GPL");