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/async.h>
36 #include <linux/delay.h>
38 #include <linux/bitops.h>
39 #include <linux/platform_device.h>
40 #include <linux/jiffies.h>
41 #include <linux/debugfs.h>
42 #include <linux/slab.h>
43 #include <sound/core.h>
44 #include <sound/pcm.h>
45 #include <sound/pcm_params.h>
46 #include <sound/soc.h>
47 #include <sound/initval.h>
49 #include <trace/events/asoc.h>
51 /* dapm power sequences - make this per codec in the future */
52 static int dapm_up_seq
[] = {
53 [snd_soc_dapm_pre
] = 0,
54 [snd_soc_dapm_supply
] = 1,
55 [snd_soc_dapm_micbias
] = 2,
56 [snd_soc_dapm_aif_in
] = 3,
57 [snd_soc_dapm_aif_out
] = 3,
58 [snd_soc_dapm_mic
] = 4,
59 [snd_soc_dapm_mux
] = 5,
60 [snd_soc_dapm_virt_mux
] = 5,
61 [snd_soc_dapm_value_mux
] = 5,
62 [snd_soc_dapm_dac
] = 6,
63 [snd_soc_dapm_mixer
] = 7,
64 [snd_soc_dapm_mixer_named_ctl
] = 7,
65 [snd_soc_dapm_pga
] = 8,
66 [snd_soc_dapm_adc
] = 9,
67 [snd_soc_dapm_out_drv
] = 10,
68 [snd_soc_dapm_hp
] = 10,
69 [snd_soc_dapm_spk
] = 10,
70 [snd_soc_dapm_post
] = 11,
73 static int dapm_down_seq
[] = {
74 [snd_soc_dapm_pre
] = 0,
75 [snd_soc_dapm_adc
] = 1,
76 [snd_soc_dapm_hp
] = 2,
77 [snd_soc_dapm_spk
] = 2,
78 [snd_soc_dapm_out_drv
] = 2,
79 [snd_soc_dapm_pga
] = 4,
80 [snd_soc_dapm_mixer_named_ctl
] = 5,
81 [snd_soc_dapm_mixer
] = 5,
82 [snd_soc_dapm_dac
] = 6,
83 [snd_soc_dapm_mic
] = 7,
84 [snd_soc_dapm_micbias
] = 8,
85 [snd_soc_dapm_mux
] = 9,
86 [snd_soc_dapm_virt_mux
] = 9,
87 [snd_soc_dapm_value_mux
] = 9,
88 [snd_soc_dapm_aif_in
] = 10,
89 [snd_soc_dapm_aif_out
] = 10,
90 [snd_soc_dapm_supply
] = 11,
91 [snd_soc_dapm_post
] = 12,
94 static void pop_wait(u32 pop_time
)
97 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
100 static void pop_dbg(struct device
*dev
, u32 pop_time
, const char *fmt
, ...)
108 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
113 vsnprintf(buf
, PAGE_SIZE
, fmt
, args
);
114 dev_info(dev
, "%s", buf
);
120 /* create a new dapm widget */
121 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
122 const struct snd_soc_dapm_widget
*_widget
)
124 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
128 * snd_soc_dapm_set_bias_level - set the bias level for the system
129 * @dapm: DAPM context
130 * @level: level to configure
132 * Configure the bias (power) levels for the SoC audio device.
134 * Returns 0 for success else error.
136 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
137 enum snd_soc_bias_level level
)
139 struct snd_soc_card
*card
= dapm
->card
;
143 case SND_SOC_BIAS_ON
:
144 dev_dbg(dapm
->dev
, "Setting full bias\n");
146 case SND_SOC_BIAS_PREPARE
:
147 dev_dbg(dapm
->dev
, "Setting bias prepare\n");
149 case SND_SOC_BIAS_STANDBY
:
150 dev_dbg(dapm
->dev
, "Setting standby bias\n");
152 case SND_SOC_BIAS_OFF
:
153 dev_dbg(dapm
->dev
, "Setting bias off\n");
156 dev_err(dapm
->dev
, "Setting invalid bias %d\n", level
);
160 trace_snd_soc_bias_level_start(card
, level
);
162 if (card
&& card
->set_bias_level
)
163 ret
= card
->set_bias_level(card
, level
);
165 if (dapm
->codec
&& dapm
->codec
->driver
->set_bias_level
)
166 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
, level
);
168 dapm
->bias_level
= level
;
171 if (card
&& card
->set_bias_level_post
)
172 ret
= card
->set_bias_level_post(card
, level
);
175 trace_snd_soc_bias_level_done(card
, level
);
180 /* set up initial codec paths */
181 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
182 struct snd_soc_dapm_path
*p
, int i
)
185 case snd_soc_dapm_switch
:
186 case snd_soc_dapm_mixer
:
187 case snd_soc_dapm_mixer_named_ctl
: {
189 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
190 w
->kcontrol_news
[i
].private_value
;
191 unsigned int reg
= mc
->reg
;
192 unsigned int shift
= mc
->shift
;
194 unsigned int mask
= (1 << fls(max
)) - 1;
195 unsigned int invert
= mc
->invert
;
197 val
= snd_soc_read(w
->codec
, reg
);
198 val
= (val
>> shift
) & mask
;
200 if ((invert
&& !val
) || (!invert
&& val
))
206 case snd_soc_dapm_mux
: {
207 struct soc_enum
*e
= (struct soc_enum
*)
208 w
->kcontrol_news
[i
].private_value
;
209 int val
, item
, bitmask
;
211 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
213 val
= snd_soc_read(w
->codec
, e
->reg
);
214 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
217 for (i
= 0; i
< e
->max
; i
++) {
218 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
223 case snd_soc_dapm_virt_mux
: {
224 struct soc_enum
*e
= (struct soc_enum
*)
225 w
->kcontrol_news
[i
].private_value
;
228 /* since a virtual mux has no backing registers to
229 * decide which path to connect, it will try to match
230 * with the first enumeration. This is to ensure
231 * that the default mux choice (the first) will be
232 * correctly powered up during initialization.
234 if (!strcmp(p
->name
, e
->texts
[0]))
238 case snd_soc_dapm_value_mux
: {
239 struct soc_enum
*e
= (struct soc_enum
*)
240 w
->kcontrol_news
[i
].private_value
;
243 val
= snd_soc_read(w
->codec
, e
->reg
);
244 val
= (val
>> e
->shift_l
) & e
->mask
;
245 for (item
= 0; item
< e
->max
; item
++) {
246 if (val
== e
->values
[item
])
251 for (i
= 0; i
< e
->max
; i
++) {
252 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
257 /* does not effect routing - always connected */
258 case snd_soc_dapm_pga
:
259 case snd_soc_dapm_out_drv
:
260 case snd_soc_dapm_output
:
261 case snd_soc_dapm_adc
:
262 case snd_soc_dapm_input
:
263 case snd_soc_dapm_dac
:
264 case snd_soc_dapm_micbias
:
265 case snd_soc_dapm_vmid
:
266 case snd_soc_dapm_supply
:
267 case snd_soc_dapm_aif_in
:
268 case snd_soc_dapm_aif_out
:
271 /* does effect routing - dynamically connected */
272 case snd_soc_dapm_hp
:
273 case snd_soc_dapm_mic
:
274 case snd_soc_dapm_spk
:
275 case snd_soc_dapm_line
:
276 case snd_soc_dapm_pre
:
277 case snd_soc_dapm_post
:
283 /* connect mux widget to its interconnecting audio paths */
284 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
285 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
286 struct snd_soc_dapm_path
*path
, const char *control_name
,
287 const struct snd_kcontrol_new
*kcontrol
)
289 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
292 for (i
= 0; i
< e
->max
; i
++) {
293 if (!(strcmp(control_name
, e
->texts
[i
]))) {
294 list_add(&path
->list
, &dapm
->card
->paths
);
295 list_add(&path
->list_sink
, &dest
->sources
);
296 list_add(&path
->list_source
, &src
->sinks
);
297 path
->name
= (char*)e
->texts
[i
];
298 dapm_set_path_status(dest
, path
, 0);
306 /* connect mixer widget to its interconnecting audio paths */
307 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
308 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
309 struct snd_soc_dapm_path
*path
, const char *control_name
)
313 /* search for mixer kcontrol */
314 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
315 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
316 list_add(&path
->list
, &dapm
->card
->paths
);
317 list_add(&path
->list_sink
, &dest
->sources
);
318 list_add(&path
->list_source
, &src
->sinks
);
319 path
->name
= dest
->kcontrol_news
[i
].name
;
320 dapm_set_path_status(dest
, path
, i
);
327 /* create new dapm mixer control */
328 static int dapm_new_mixer(struct snd_soc_dapm_context
*dapm
,
329 struct snd_soc_dapm_widget
*w
)
332 size_t name_len
, prefix_len
;
333 struct snd_soc_dapm_path
*path
;
334 struct snd_card
*card
= dapm
->card
->snd_card
;
338 prefix
= dapm
->codec
->name_prefix
;
343 prefix_len
= strlen(prefix
) + 1;
348 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
351 list_for_each_entry(path
, &w
->sources
, list_sink
) {
353 /* mixer/mux paths name must match control name */
354 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
357 /* add dapm control with long name.
358 * for dapm_mixer this is the concatenation of the
359 * mixer and kcontrol name.
360 * for dapm_mixer_named_ctl this is simply the
363 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
364 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
365 name_len
+= 1 + strlen(w
->name
);
367 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
369 if (path
->long_name
== NULL
)
374 /* The control will get a prefix from
375 * the control creation process but
376 * we're also using the same prefix
377 * for widgets so cut the prefix off
378 * the front of the widget name.
380 snprintf(path
->long_name
, name_len
, "%s %s",
381 w
->name
+ prefix_len
,
382 w
->kcontrol_news
[i
].name
);
384 case snd_soc_dapm_mixer_named_ctl
:
385 snprintf(path
->long_name
, name_len
, "%s",
386 w
->kcontrol_news
[i
].name
);
390 path
->long_name
[name_len
- 1] = '\0';
392 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
], w
,
393 path
->long_name
, prefix
);
394 ret
= snd_ctl_add(card
, path
->kcontrol
);
397 "asoc: failed to add dapm kcontrol %s: %d\n",
398 path
->long_name
, ret
);
399 kfree(path
->long_name
);
400 path
->long_name
= NULL
;
408 /* create new dapm mux control */
409 static int dapm_new_mux(struct snd_soc_dapm_context
*dapm
,
410 struct snd_soc_dapm_widget
*w
)
412 struct snd_soc_dapm_path
*path
= NULL
;
413 struct snd_kcontrol
*kcontrol
;
414 struct snd_card
*card
= dapm
->card
->snd_card
;
419 if (!w
->num_kcontrols
) {
420 dev_err(dapm
->dev
, "asoc: mux %s has no controls\n", w
->name
);
425 prefix
= dapm
->codec
->name_prefix
;
430 prefix_len
= strlen(prefix
) + 1;
434 /* The control will get a prefix from the control creation
435 * process but we're also using the same prefix for widgets so
436 * cut the prefix off the front of the widget name.
438 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], w
, w
->name
+ prefix_len
,
440 ret
= snd_ctl_add(card
, kcontrol
);
445 list_for_each_entry(path
, &w
->sources
, list_sink
)
446 path
->kcontrol
= kcontrol
;
451 dev_err(dapm
->dev
, "asoc: failed to add kcontrol %s\n", w
->name
);
455 /* create new dapm volume control */
456 static int dapm_new_pga(struct snd_soc_dapm_context
*dapm
,
457 struct snd_soc_dapm_widget
*w
)
459 if (w
->num_kcontrols
)
460 dev_err(w
->dapm
->dev
,
461 "asoc: PGA controls not supported: '%s'\n", w
->name
);
466 /* reset 'walked' bit for each dapm path */
467 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
469 struct snd_soc_dapm_path
*p
;
471 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
475 /* We implement power down on suspend by checking the power state of
476 * the ALSA card - when we are suspending the ALSA state for the card
479 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
481 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
484 case SNDRV_CTL_POWER_D3hot
:
485 case SNDRV_CTL_POWER_D3cold
:
486 if (widget
->ignore_suspend
)
487 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
489 return widget
->ignore_suspend
;
496 * Recursively check for a completed path to an active or physically connected
497 * output widget. Returns number of complete paths.
499 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
501 struct snd_soc_dapm_path
*path
;
504 if (widget
->id
== snd_soc_dapm_supply
)
507 switch (widget
->id
) {
508 case snd_soc_dapm_adc
:
509 case snd_soc_dapm_aif_out
:
511 return snd_soc_dapm_suspend_check(widget
);
516 if (widget
->connected
) {
517 /* connected pin ? */
518 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
519 return snd_soc_dapm_suspend_check(widget
);
521 /* connected jack or spk ? */
522 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
523 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sources
)))
524 return snd_soc_dapm_suspend_check(widget
);
527 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
531 if (path
->sink
&& path
->connect
) {
533 con
+= is_connected_output_ep(path
->sink
);
541 * Recursively check for a completed path to an active or physically connected
542 * input widget. Returns number of complete paths.
544 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
546 struct snd_soc_dapm_path
*path
;
549 if (widget
->id
== snd_soc_dapm_supply
)
552 /* active stream ? */
553 switch (widget
->id
) {
554 case snd_soc_dapm_dac
:
555 case snd_soc_dapm_aif_in
:
557 return snd_soc_dapm_suspend_check(widget
);
562 if (widget
->connected
) {
563 /* connected pin ? */
564 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
565 return snd_soc_dapm_suspend_check(widget
);
567 /* connected VMID/Bias for lower pops */
568 if (widget
->id
== snd_soc_dapm_vmid
)
569 return snd_soc_dapm_suspend_check(widget
);
571 /* connected jack ? */
572 if (widget
->id
== snd_soc_dapm_mic
||
573 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sinks
)))
574 return snd_soc_dapm_suspend_check(widget
);
577 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
581 if (path
->source
&& path
->connect
) {
583 con
+= is_connected_input_ep(path
->source
);
591 * Handler for generic register modifier widget.
593 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
594 struct snd_kcontrol
*kcontrol
, int event
)
598 if (SND_SOC_DAPM_EVENT_ON(event
))
603 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
604 w
->mask
<< w
->shift
, val
<< w
->shift
);
608 EXPORT_SYMBOL_GPL(dapm_reg_event
);
610 /* Generic check to see if a widget should be powered.
612 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
616 in
= is_connected_input_ep(w
);
617 dapm_clear_walk(w
->dapm
);
618 out
= is_connected_output_ep(w
);
619 dapm_clear_walk(w
->dapm
);
620 return out
!= 0 && in
!= 0;
623 /* Check to see if an ADC has power */
624 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
629 in
= is_connected_input_ep(w
);
630 dapm_clear_walk(w
->dapm
);
633 return dapm_generic_check_power(w
);
637 /* Check to see if a DAC has power */
638 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
643 out
= is_connected_output_ep(w
);
644 dapm_clear_walk(w
->dapm
);
647 return dapm_generic_check_power(w
);
651 /* Check to see if a power supply is needed */
652 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
654 struct snd_soc_dapm_path
*path
;
657 /* Check if one of our outputs is connected */
658 list_for_each_entry(path
, &w
->sinks
, list_source
) {
659 if (path
->connected
&&
660 !path
->connected(path
->source
, path
->sink
))
666 if (path
->sink
->force
) {
671 if (path
->sink
->power_check
&&
672 path
->sink
->power_check(path
->sink
)) {
678 dapm_clear_walk(w
->dapm
);
683 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
684 struct snd_soc_dapm_widget
*b
,
692 sort
= dapm_down_seq
;
694 if (sort
[a
->id
] != sort
[b
->id
])
695 return sort
[a
->id
] - sort
[b
->id
];
696 if (a
->subseq
!= b
->subseq
) {
698 return a
->subseq
- b
->subseq
;
700 return b
->subseq
- a
->subseq
;
702 if (a
->reg
!= b
->reg
)
703 return a
->reg
- b
->reg
;
704 if (a
->dapm
!= b
->dapm
)
705 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
710 /* Insert a widget in order into a DAPM power sequence. */
711 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
712 struct list_head
*list
,
715 struct snd_soc_dapm_widget
*w
;
717 list_for_each_entry(w
, list
, power_list
)
718 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
719 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
723 list_add_tail(&new_widget
->power_list
, list
);
726 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
727 struct snd_soc_dapm_widget
*w
, int event
)
729 struct snd_soc_card
*card
= dapm
->card
;
734 case SND_SOC_DAPM_PRE_PMU
:
738 case SND_SOC_DAPM_POST_PMU
:
739 ev_name
= "POST_PMU";
742 case SND_SOC_DAPM_PRE_PMD
:
746 case SND_SOC_DAPM_POST_PMD
:
747 ev_name
= "POST_PMD";
755 if (w
->power
!= power
)
758 if (w
->event
&& (w
->event_flags
& event
)) {
759 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
761 trace_snd_soc_dapm_widget_event_start(w
, event
);
762 ret
= w
->event(w
, NULL
, event
);
763 trace_snd_soc_dapm_widget_event_done(w
, event
);
765 pr_err("%s: %s event failed: %d\n",
766 ev_name
, w
->name
, ret
);
770 /* Apply the coalesced changes from a DAPM sequence */
771 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
772 struct list_head
*pending
)
774 struct snd_soc_card
*card
= dapm
->card
;
775 struct snd_soc_dapm_widget
*w
;
777 unsigned int value
= 0;
778 unsigned int mask
= 0;
779 unsigned int cur_mask
;
781 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
784 list_for_each_entry(w
, pending
, power_list
) {
785 cur_mask
= 1 << w
->shift
;
786 BUG_ON(reg
!= w
->reg
);
797 pop_dbg(dapm
->dev
, card
->pop_time
,
798 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
799 w
->name
, reg
, value
, mask
);
801 /* Check for events */
802 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
803 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
807 pop_dbg(dapm
->dev
, card
->pop_time
,
808 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
809 value
, mask
, reg
, card
->pop_time
);
810 pop_wait(card
->pop_time
);
811 snd_soc_update_bits(dapm
->codec
, reg
, mask
, value
);
814 list_for_each_entry(w
, pending
, power_list
) {
815 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
816 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
820 /* Apply a DAPM power sequence.
822 * We walk over a pre-sorted list of widgets to apply power to. In
823 * order to minimise the number of writes to the device required
824 * multiple widgets will be updated in a single write where possible.
825 * Currently anything that requires more than a single write is not
828 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
829 struct list_head
*list
, int event
, bool power_up
)
831 struct snd_soc_dapm_widget
*w
, *n
;
835 int cur_reg
= SND_SOC_NOPM
;
836 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
843 sort
= dapm_down_seq
;
845 list_for_each_entry_safe(w
, n
, list
, power_list
) {
848 /* Do we need to apply any queued changes? */
849 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
850 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
851 if (!list_empty(&pending
))
852 dapm_seq_run_coalesced(cur_dapm
, &pending
);
854 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
855 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
856 if (sort
[i
] == cur_sort
)
857 cur_dapm
->seq_notifier(cur_dapm
,
862 INIT_LIST_HEAD(&pending
);
865 cur_reg
= SND_SOC_NOPM
;
870 case snd_soc_dapm_pre
:
872 list_for_each_entry_safe_continue(w
, n
, list
,
875 if (event
== SND_SOC_DAPM_STREAM_START
)
877 NULL
, SND_SOC_DAPM_PRE_PMU
);
878 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
880 NULL
, SND_SOC_DAPM_PRE_PMD
);
883 case snd_soc_dapm_post
:
885 list_for_each_entry_safe_continue(w
, n
, list
,
888 if (event
== SND_SOC_DAPM_STREAM_START
)
890 NULL
, SND_SOC_DAPM_POST_PMU
);
891 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
893 NULL
, SND_SOC_DAPM_POST_PMD
);
897 /* Queue it up for application */
898 cur_sort
= sort
[w
->id
];
899 cur_subseq
= w
->subseq
;
902 list_move(&w
->power_list
, &pending
);
907 dev_err(w
->dapm
->dev
,
908 "Failed to apply widget power: %d\n", ret
);
911 if (!list_empty(&pending
))
912 dapm_seq_run_coalesced(cur_dapm
, &pending
);
914 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
915 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
916 if (sort
[i
] == cur_sort
)
917 cur_dapm
->seq_notifier(cur_dapm
,
922 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
924 struct snd_soc_dapm_update
*update
= dapm
->update
;
925 struct snd_soc_dapm_widget
*w
;
934 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
935 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
937 pr_err("%s DAPM pre-event failed: %d\n",
941 ret
= snd_soc_update_bits(w
->codec
, update
->reg
, update
->mask
,
944 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
947 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
948 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
950 pr_err("%s DAPM post-event failed: %d\n",
955 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
956 * they're changing state.
958 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
960 struct snd_soc_dapm_context
*d
= data
;
963 if (d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_OFF
) {
964 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
967 "Failed to turn on bias: %d\n", ret
);
970 /* If we're changing to all on or all off then prepare */
971 if ((d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_STANDBY
) ||
972 (!d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_ON
)) {
973 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
976 "Failed to prepare bias: %d\n", ret
);
980 /* Async callback run prior to DAPM sequences - brings to their final
983 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
985 struct snd_soc_dapm_context
*d
= data
;
988 /* If we just powered the last thing off drop to standby bias */
989 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&& !d
->dev_power
) {
990 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
992 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
996 /* If we're in standby and can support bias off then do that */
997 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&& d
->idle_bias_off
) {
998 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1000 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1003 /* If we just powered up then move to active bias */
1004 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&& d
->dev_power
) {
1005 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1007 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1013 * Scan each dapm widget for complete audio path.
1014 * A complete path is a route that has valid endpoints i.e.:-
1016 * o DAC to output pin.
1017 * o Input Pin to ADC.
1018 * o Input pin to Output pin (bypass, sidetone)
1019 * o DAC to ADC (loopback).
1021 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1023 struct snd_soc_card
*card
= dapm
->card
;
1024 struct snd_soc_dapm_widget
*w
;
1025 struct snd_soc_dapm_context
*d
;
1027 LIST_HEAD(down_list
);
1028 LIST_HEAD(async_domain
);
1031 trace_snd_soc_dapm_start(card
);
1033 list_for_each_entry(d
, &card
->dapm_list
, list
)
1037 /* Check which widgets we need to power and store them in
1038 * lists indicating if they should be powered up or down.
1040 list_for_each_entry(w
, &card
->widgets
, list
) {
1042 case snd_soc_dapm_pre
:
1043 dapm_seq_insert(w
, &down_list
, false);
1045 case snd_soc_dapm_post
:
1046 dapm_seq_insert(w
, &up_list
, true);
1050 if (!w
->power_check
)
1054 power
= w
->power_check(w
);
1058 w
->dapm
->dev_power
= 1;
1060 if (w
->power
== power
)
1063 trace_snd_soc_dapm_widget_power(w
, power
);
1066 dapm_seq_insert(w
, &up_list
, true);
1068 dapm_seq_insert(w
, &down_list
, false);
1075 /* If there are no DAPM widgets then try to figure out power from the
1078 if (!dapm
->n_widgets
) {
1080 case SND_SOC_DAPM_STREAM_START
:
1081 case SND_SOC_DAPM_STREAM_RESUME
:
1082 dapm
->dev_power
= 1;
1084 case SND_SOC_DAPM_STREAM_STOP
:
1085 dapm
->dev_power
= !!dapm
->codec
->active
;
1087 case SND_SOC_DAPM_STREAM_SUSPEND
:
1088 dapm
->dev_power
= 0;
1090 case SND_SOC_DAPM_STREAM_NOP
:
1091 switch (dapm
->bias_level
) {
1092 case SND_SOC_BIAS_STANDBY
:
1093 case SND_SOC_BIAS_OFF
:
1094 dapm
->dev_power
= 0;
1097 dapm
->dev_power
= 1;
1106 /* Force all contexts in the card to the same bias state */
1108 list_for_each_entry(d
, &card
->dapm_list
, list
)
1111 list_for_each_entry(d
, &card
->dapm_list
, list
)
1112 d
->dev_power
= power
;
1115 /* Run all the bias changes in parallel */
1116 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1117 async_schedule_domain(dapm_pre_sequence_async
, d
,
1119 async_synchronize_full_domain(&async_domain
);
1121 /* Power down widgets first; try to avoid amplifying pops. */
1122 dapm_seq_run(dapm
, &down_list
, event
, false);
1124 dapm_widget_update(dapm
);
1127 dapm_seq_run(dapm
, &up_list
, event
, true);
1129 /* Run all the bias changes in parallel */
1130 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1131 async_schedule_domain(dapm_post_sequence_async
, d
,
1133 async_synchronize_full_domain(&async_domain
);
1135 pop_dbg(dapm
->dev
, card
->pop_time
,
1136 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1137 pop_wait(card
->pop_time
);
1139 trace_snd_soc_dapm_done(card
);
1144 #ifdef CONFIG_DEBUG_FS
1145 static int dapm_widget_power_open_file(struct inode
*inode
, struct file
*file
)
1147 file
->private_data
= inode
->i_private
;
1151 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1152 char __user
*user_buf
,
1153 size_t count
, loff_t
*ppos
)
1155 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1159 struct snd_soc_dapm_path
*p
= NULL
;
1161 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1165 in
= is_connected_input_ep(w
);
1166 dapm_clear_walk(w
->dapm
);
1167 out
= is_connected_output_ep(w
);
1168 dapm_clear_walk(w
->dapm
);
1170 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s in %d out %d",
1171 w
->name
, w
->power
? "On" : "Off", in
, out
);
1174 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1175 " - R%d(0x%x) bit %d",
1176 w
->reg
, w
->reg
, w
->shift
);
1178 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1181 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1183 w
->active
? "active" : "inactive");
1185 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1186 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1190 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1191 " in \"%s\" \"%s\"\n",
1192 p
->name
? p
->name
: "static",
1195 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1196 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1200 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1201 " out \"%s\" \"%s\"\n",
1202 p
->name
? p
->name
: "static",
1206 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1212 static const struct file_operations dapm_widget_power_fops
= {
1213 .open
= dapm_widget_power_open_file
,
1214 .read
= dapm_widget_power_read_file
,
1215 .llseek
= default_llseek
,
1218 static int dapm_bias_open_file(struct inode
*inode
, struct file
*file
)
1220 file
->private_data
= inode
->i_private
;
1224 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1225 size_t count
, loff_t
*ppos
)
1227 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1230 switch (dapm
->bias_level
) {
1231 case SND_SOC_BIAS_ON
:
1234 case SND_SOC_BIAS_PREPARE
:
1235 level
= "Prepare\n";
1237 case SND_SOC_BIAS_STANDBY
:
1238 level
= "Standby\n";
1240 case SND_SOC_BIAS_OFF
:
1245 level
= "Unknown\n";
1249 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1253 static const struct file_operations dapm_bias_fops
= {
1254 .open
= dapm_bias_open_file
,
1255 .read
= dapm_bias_read_file
,
1256 .llseek
= default_llseek
,
1259 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1260 struct dentry
*parent
)
1264 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1266 if (!dapm
->debugfs_dapm
) {
1268 "Failed to create DAPM debugfs directory\n");
1272 d
= debugfs_create_file("bias_level", 0444,
1273 dapm
->debugfs_dapm
, dapm
,
1277 "ASoC: Failed to create bias level debugfs file\n");
1280 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1282 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1285 if (!dapm
->debugfs_dapm
|| !w
->name
)
1288 d
= debugfs_create_file(w
->name
, 0444,
1289 dapm
->debugfs_dapm
, w
,
1290 &dapm_widget_power_fops
);
1292 dev_warn(w
->dapm
->dev
,
1293 "ASoC: Failed to create %s debugfs file\n",
1297 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1299 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1303 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1304 struct dentry
*parent
)
1308 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1312 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1318 /* test and update the power status of a mux widget */
1319 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1320 struct snd_kcontrol
*kcontrol
, int change
,
1321 int mux
, struct soc_enum
*e
)
1323 struct snd_soc_dapm_path
*path
;
1326 if (widget
->id
!= snd_soc_dapm_mux
&&
1327 widget
->id
!= snd_soc_dapm_virt_mux
&&
1328 widget
->id
!= snd_soc_dapm_value_mux
)
1334 /* find dapm widget path assoc with kcontrol */
1335 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1336 if (path
->kcontrol
!= kcontrol
)
1339 if (!path
->name
|| !e
->texts
[mux
])
1343 /* we now need to match the string in the enum to the path */
1344 if (!(strcmp(path
->name
, e
->texts
[mux
])))
1345 path
->connect
= 1; /* new connection */
1347 path
->connect
= 0; /* old connection must be powered down */
1351 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1356 /* test and update the power status of a mixer or switch widget */
1357 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1358 struct snd_kcontrol
*kcontrol
, int connect
)
1360 struct snd_soc_dapm_path
*path
;
1363 if (widget
->id
!= snd_soc_dapm_mixer
&&
1364 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1365 widget
->id
!= snd_soc_dapm_switch
)
1368 /* find dapm widget path assoc with kcontrol */
1369 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1370 if (path
->kcontrol
!= kcontrol
)
1373 /* found, now check type */
1375 path
->connect
= connect
;
1380 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1385 /* show dapm widget status in sys fs */
1386 static ssize_t
dapm_widget_show(struct device
*dev
,
1387 struct device_attribute
*attr
, char *buf
)
1389 struct snd_soc_pcm_runtime
*rtd
=
1390 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
1391 struct snd_soc_codec
*codec
=rtd
->codec
;
1392 struct snd_soc_dapm_widget
*w
;
1394 char *state
= "not set";
1396 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1397 if (w
->dapm
!= &codec
->dapm
)
1400 /* only display widgets that burnm power */
1402 case snd_soc_dapm_hp
:
1403 case snd_soc_dapm_mic
:
1404 case snd_soc_dapm_spk
:
1405 case snd_soc_dapm_line
:
1406 case snd_soc_dapm_micbias
:
1407 case snd_soc_dapm_dac
:
1408 case snd_soc_dapm_adc
:
1409 case snd_soc_dapm_pga
:
1410 case snd_soc_dapm_out_drv
:
1411 case snd_soc_dapm_mixer
:
1412 case snd_soc_dapm_mixer_named_ctl
:
1413 case snd_soc_dapm_supply
:
1415 count
+= sprintf(buf
+ count
, "%s: %s\n",
1416 w
->name
, w
->power
? "On":"Off");
1423 switch (codec
->dapm
.bias_level
) {
1424 case SND_SOC_BIAS_ON
:
1427 case SND_SOC_BIAS_PREPARE
:
1430 case SND_SOC_BIAS_STANDBY
:
1433 case SND_SOC_BIAS_OFF
:
1437 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1442 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1444 int snd_soc_dapm_sys_add(struct device
*dev
)
1446 return device_create_file(dev
, &dev_attr_dapm_widget
);
1449 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1451 device_remove_file(dev
, &dev_attr_dapm_widget
);
1454 /* free all dapm widgets and resources */
1455 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
1457 struct snd_soc_dapm_widget
*w
, *next_w
;
1458 struct snd_soc_dapm_path
*p
, *next_p
;
1460 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
1461 if (w
->dapm
!= dapm
)
1465 * remove source and sink paths associated to this widget.
1466 * While removing the path, remove reference to it from both
1467 * source and sink widgets so that path is removed only once.
1469 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
1470 list_del(&p
->list_sink
);
1471 list_del(&p
->list_source
);
1473 kfree(p
->long_name
);
1476 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
1477 list_del(&p
->list_sink
);
1478 list_del(&p
->list_source
);
1480 kfree(p
->long_name
);
1488 static struct snd_soc_dapm_widget
*dapm_find_widget(
1489 struct snd_soc_dapm_context
*dapm
, const char *pin
,
1490 bool search_other_contexts
)
1492 struct snd_soc_dapm_widget
*w
;
1493 struct snd_soc_dapm_widget
*fallback
= NULL
;
1495 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1496 if (!strcmp(w
->name
, pin
)) {
1497 if (w
->dapm
== dapm
)
1504 if (search_other_contexts
)
1510 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
1511 const char *pin
, int status
)
1513 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
1516 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
1520 w
->connected
= status
;
1528 * snd_soc_dapm_sync - scan and power dapm paths
1529 * @dapm: DAPM context
1531 * Walks all dapm audio paths and powers widgets according to their
1532 * stream or path usage.
1534 * Returns 0 for success.
1536 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
1538 return dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1540 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1542 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
1543 const struct snd_soc_dapm_route
*route
)
1545 struct snd_soc_dapm_path
*path
;
1546 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1547 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
1549 const char *control
= route
->control
;
1551 char prefixed_sink
[80];
1552 char prefixed_source
[80];
1555 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
1556 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
1557 dapm
->codec
->name_prefix
, route
->sink
);
1558 sink
= prefixed_sink
;
1559 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
1560 dapm
->codec
->name_prefix
, route
->source
);
1561 source
= prefixed_source
;
1564 source
= route
->source
;
1568 * find src and dest widgets over all widgets but favor a widget from
1569 * current DAPM context
1571 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1572 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1574 if (w
->dapm
== dapm
)
1578 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1580 if (w
->dapm
== dapm
)
1584 /* use widget from another DAPM context if not found from this */
1590 if (wsource
== NULL
|| wsink
== NULL
)
1593 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1597 path
->source
= wsource
;
1599 path
->connected
= route
->connected
;
1600 INIT_LIST_HEAD(&path
->list
);
1601 INIT_LIST_HEAD(&path
->list_source
);
1602 INIT_LIST_HEAD(&path
->list_sink
);
1604 /* check for external widgets */
1605 if (wsink
->id
== snd_soc_dapm_input
) {
1606 if (wsource
->id
== snd_soc_dapm_micbias
||
1607 wsource
->id
== snd_soc_dapm_mic
||
1608 wsource
->id
== snd_soc_dapm_line
||
1609 wsource
->id
== snd_soc_dapm_output
)
1612 if (wsource
->id
== snd_soc_dapm_output
) {
1613 if (wsink
->id
== snd_soc_dapm_spk
||
1614 wsink
->id
== snd_soc_dapm_hp
||
1615 wsink
->id
== snd_soc_dapm_line
||
1616 wsink
->id
== snd_soc_dapm_input
)
1620 /* connect static paths */
1621 if (control
== NULL
) {
1622 list_add(&path
->list
, &dapm
->card
->paths
);
1623 list_add(&path
->list_sink
, &wsink
->sources
);
1624 list_add(&path
->list_source
, &wsource
->sinks
);
1629 /* connect dynamic paths */
1630 switch (wsink
->id
) {
1631 case snd_soc_dapm_adc
:
1632 case snd_soc_dapm_dac
:
1633 case snd_soc_dapm_pga
:
1634 case snd_soc_dapm_out_drv
:
1635 case snd_soc_dapm_input
:
1636 case snd_soc_dapm_output
:
1637 case snd_soc_dapm_micbias
:
1638 case snd_soc_dapm_vmid
:
1639 case snd_soc_dapm_pre
:
1640 case snd_soc_dapm_post
:
1641 case snd_soc_dapm_supply
:
1642 case snd_soc_dapm_aif_in
:
1643 case snd_soc_dapm_aif_out
:
1644 list_add(&path
->list
, &dapm
->card
->paths
);
1645 list_add(&path
->list_sink
, &wsink
->sources
);
1646 list_add(&path
->list_source
, &wsource
->sinks
);
1649 case snd_soc_dapm_mux
:
1650 case snd_soc_dapm_virt_mux
:
1651 case snd_soc_dapm_value_mux
:
1652 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
1653 &wsink
->kcontrol_news
[0]);
1657 case snd_soc_dapm_switch
:
1658 case snd_soc_dapm_mixer
:
1659 case snd_soc_dapm_mixer_named_ctl
:
1660 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
1664 case snd_soc_dapm_hp
:
1665 case snd_soc_dapm_mic
:
1666 case snd_soc_dapm_line
:
1667 case snd_soc_dapm_spk
:
1668 list_add(&path
->list
, &dapm
->card
->paths
);
1669 list_add(&path
->list_sink
, &wsink
->sources
);
1670 list_add(&path
->list_source
, &wsource
->sinks
);
1677 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
1678 source
, control
, sink
);
1684 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1685 * @dapm: DAPM context
1686 * @route: audio routes
1687 * @num: number of routes
1689 * Connects 2 dapm widgets together via a named audio path. The sink is
1690 * the widget receiving the audio signal, whilst the source is the sender
1691 * of the audio signal.
1693 * Returns 0 for success else error. On error all resources can be freed
1694 * with a call to snd_soc_card_free().
1696 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
1697 const struct snd_soc_dapm_route
*route
, int num
)
1701 for (i
= 0; i
< num
; i
++) {
1702 ret
= snd_soc_dapm_add_route(dapm
, route
);
1704 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
1705 route
->source
, route
->sink
);
1713 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1716 * snd_soc_dapm_new_widgets - add new dapm widgets
1717 * @dapm: DAPM context
1719 * Checks the codec for any new dapm widgets and creates them if found.
1721 * Returns 0 for success.
1723 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
1725 struct snd_soc_dapm_widget
*w
;
1728 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
1734 case snd_soc_dapm_switch
:
1735 case snd_soc_dapm_mixer
:
1736 case snd_soc_dapm_mixer_named_ctl
:
1737 w
->power_check
= dapm_generic_check_power
;
1738 dapm_new_mixer(dapm
, w
);
1740 case snd_soc_dapm_mux
:
1741 case snd_soc_dapm_virt_mux
:
1742 case snd_soc_dapm_value_mux
:
1743 w
->power_check
= dapm_generic_check_power
;
1744 dapm_new_mux(dapm
, w
);
1746 case snd_soc_dapm_adc
:
1747 case snd_soc_dapm_aif_out
:
1748 w
->power_check
= dapm_adc_check_power
;
1750 case snd_soc_dapm_dac
:
1751 case snd_soc_dapm_aif_in
:
1752 w
->power_check
= dapm_dac_check_power
;
1754 case snd_soc_dapm_pga
:
1755 case snd_soc_dapm_out_drv
:
1756 w
->power_check
= dapm_generic_check_power
;
1757 dapm_new_pga(dapm
, w
);
1759 case snd_soc_dapm_input
:
1760 case snd_soc_dapm_output
:
1761 case snd_soc_dapm_micbias
:
1762 case snd_soc_dapm_spk
:
1763 case snd_soc_dapm_hp
:
1764 case snd_soc_dapm_mic
:
1765 case snd_soc_dapm_line
:
1766 w
->power_check
= dapm_generic_check_power
;
1768 case snd_soc_dapm_supply
:
1769 w
->power_check
= dapm_supply_check_power
;
1770 case snd_soc_dapm_vmid
:
1771 case snd_soc_dapm_pre
:
1772 case snd_soc_dapm_post
:
1776 /* Read the initial power state from the device */
1778 val
= snd_soc_read(w
->codec
, w
->reg
);
1779 val
&= 1 << w
->shift
;
1789 dapm_debugfs_add_widget(w
);
1792 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1795 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1798 * snd_soc_dapm_get_volsw - dapm mixer get callback
1799 * @kcontrol: mixer control
1800 * @ucontrol: control element information
1802 * Callback to get the value of a dapm mixer control.
1804 * Returns 0 for success.
1806 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1807 struct snd_ctl_elem_value
*ucontrol
)
1809 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1810 struct soc_mixer_control
*mc
=
1811 (struct soc_mixer_control
*)kcontrol
->private_value
;
1812 unsigned int reg
= mc
->reg
;
1813 unsigned int shift
= mc
->shift
;
1814 unsigned int rshift
= mc
->rshift
;
1816 unsigned int invert
= mc
->invert
;
1817 unsigned int mask
= (1 << fls(max
)) - 1;
1819 ucontrol
->value
.integer
.value
[0] =
1820 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1821 if (shift
!= rshift
)
1822 ucontrol
->value
.integer
.value
[1] =
1823 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1825 ucontrol
->value
.integer
.value
[0] =
1826 max
- ucontrol
->value
.integer
.value
[0];
1827 if (shift
!= rshift
)
1828 ucontrol
->value
.integer
.value
[1] =
1829 max
- ucontrol
->value
.integer
.value
[1];
1834 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1837 * snd_soc_dapm_put_volsw - dapm mixer set callback
1838 * @kcontrol: mixer control
1839 * @ucontrol: control element information
1841 * Callback to set the value of a dapm mixer control.
1843 * Returns 0 for success.
1845 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1846 struct snd_ctl_elem_value
*ucontrol
)
1848 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1849 struct soc_mixer_control
*mc
=
1850 (struct soc_mixer_control
*)kcontrol
->private_value
;
1851 unsigned int reg
= mc
->reg
;
1852 unsigned int shift
= mc
->shift
;
1854 unsigned int mask
= (1 << fls(max
)) - 1;
1855 unsigned int invert
= mc
->invert
;
1857 int connect
, change
;
1858 struct snd_soc_dapm_update update
;
1860 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1864 mask
= mask
<< shift
;
1867 mutex_lock(&widget
->codec
->mutex
);
1868 widget
->value
= val
;
1870 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
1873 /* new connection */
1874 connect
= invert
? 0:1;
1876 /* old connection must be powered down */
1877 connect
= invert
? 1:0;
1879 update
.kcontrol
= kcontrol
;
1880 update
.widget
= widget
;
1884 widget
->dapm
->update
= &update
;
1886 dapm_mixer_update_power(widget
, kcontrol
, connect
);
1888 widget
->dapm
->update
= NULL
;
1891 mutex_unlock(&widget
->codec
->mutex
);
1894 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
1897 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1898 * @kcontrol: mixer control
1899 * @ucontrol: control element information
1901 * Callback to get the value of a dapm enumerated double mixer control.
1903 * Returns 0 for success.
1905 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
1906 struct snd_ctl_elem_value
*ucontrol
)
1908 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1909 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1910 unsigned int val
, bitmask
;
1912 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1914 val
= snd_soc_read(widget
->codec
, e
->reg
);
1915 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
1916 if (e
->shift_l
!= e
->shift_r
)
1917 ucontrol
->value
.enumerated
.item
[1] =
1918 (val
>> e
->shift_r
) & (bitmask
- 1);
1922 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
1925 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1926 * @kcontrol: mixer control
1927 * @ucontrol: control element information
1929 * Callback to set the value of a dapm enumerated double mixer control.
1931 * Returns 0 for success.
1933 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
1934 struct snd_ctl_elem_value
*ucontrol
)
1936 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1937 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1938 unsigned int val
, mux
, change
;
1939 unsigned int mask
, bitmask
;
1940 struct snd_soc_dapm_update update
;
1942 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1944 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1946 mux
= ucontrol
->value
.enumerated
.item
[0];
1947 val
= mux
<< e
->shift_l
;
1948 mask
= (bitmask
- 1) << e
->shift_l
;
1949 if (e
->shift_l
!= e
->shift_r
) {
1950 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1952 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
1953 mask
|= (bitmask
- 1) << e
->shift_r
;
1956 mutex_lock(&widget
->codec
->mutex
);
1957 widget
->value
= val
;
1958 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
1960 update
.kcontrol
= kcontrol
;
1961 update
.widget
= widget
;
1962 update
.reg
= e
->reg
;
1965 widget
->dapm
->update
= &update
;
1967 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
1969 widget
->dapm
->update
= NULL
;
1971 mutex_unlock(&widget
->codec
->mutex
);
1974 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
1977 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
1978 * @kcontrol: mixer control
1979 * @ucontrol: control element information
1981 * Returns 0 for success.
1983 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
1984 struct snd_ctl_elem_value
*ucontrol
)
1986 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
1988 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
1992 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
1995 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
1996 * @kcontrol: mixer control
1997 * @ucontrol: control element information
1999 * Returns 0 for success.
2001 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2002 struct snd_ctl_elem_value
*ucontrol
)
2004 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
2005 struct soc_enum
*e
=
2006 (struct soc_enum
*)kcontrol
->private_value
;
2010 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2013 mutex_lock(&widget
->codec
->mutex
);
2015 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2016 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2017 dapm_mux_update_power(widget
, kcontrol
, change
, widget
->value
, e
);
2019 mutex_unlock(&widget
->codec
->mutex
);
2022 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2025 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2027 * @kcontrol: mixer control
2028 * @ucontrol: control element information
2030 * Callback to get the value of a dapm semi enumerated double mixer control.
2032 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2033 * used for handling bitfield coded enumeration for example.
2035 * Returns 0 for success.
2037 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2038 struct snd_ctl_elem_value
*ucontrol
)
2040 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
2041 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2042 unsigned int reg_val
, val
, mux
;
2044 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2045 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2046 for (mux
= 0; mux
< e
->max
; mux
++) {
2047 if (val
== e
->values
[mux
])
2050 ucontrol
->value
.enumerated
.item
[0] = mux
;
2051 if (e
->shift_l
!= e
->shift_r
) {
2052 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2053 for (mux
= 0; mux
< e
->max
; mux
++) {
2054 if (val
== e
->values
[mux
])
2057 ucontrol
->value
.enumerated
.item
[1] = mux
;
2062 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2065 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2067 * @kcontrol: mixer control
2068 * @ucontrol: control element information
2070 * Callback to set the value of a dapm semi enumerated double mixer control.
2072 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2073 * used for handling bitfield coded enumeration for example.
2075 * Returns 0 for success.
2077 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2078 struct snd_ctl_elem_value
*ucontrol
)
2080 struct snd_soc_dapm_widget
*widget
= snd_kcontrol_chip(kcontrol
);
2081 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2082 unsigned int val
, mux
, change
;
2084 struct snd_soc_dapm_update update
;
2086 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2088 mux
= ucontrol
->value
.enumerated
.item
[0];
2089 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2090 mask
= e
->mask
<< e
->shift_l
;
2091 if (e
->shift_l
!= e
->shift_r
) {
2092 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2094 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2095 mask
|= e
->mask
<< e
->shift_r
;
2098 mutex_lock(&widget
->codec
->mutex
);
2099 widget
->value
= val
;
2100 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2102 update
.kcontrol
= kcontrol
;
2103 update
.widget
= widget
;
2104 update
.reg
= e
->reg
;
2107 widget
->dapm
->update
= &update
;
2109 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2111 widget
->dapm
->update
= NULL
;
2113 mutex_unlock(&widget
->codec
->mutex
);
2116 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2119 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2121 * @kcontrol: mixer control
2122 * @uinfo: control element information
2124 * Callback to provide information about a pin switch control.
2126 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2127 struct snd_ctl_elem_info
*uinfo
)
2129 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2131 uinfo
->value
.integer
.min
= 0;
2132 uinfo
->value
.integer
.max
= 1;
2136 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2139 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2141 * @kcontrol: mixer control
2144 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2145 struct snd_ctl_elem_value
*ucontrol
)
2147 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2148 const char *pin
= (const char *)kcontrol
->private_value
;
2150 mutex_lock(&codec
->mutex
);
2152 ucontrol
->value
.integer
.value
[0] =
2153 snd_soc_dapm_get_pin_status(&codec
->dapm
, pin
);
2155 mutex_unlock(&codec
->mutex
);
2159 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2162 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2164 * @kcontrol: mixer control
2167 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2168 struct snd_ctl_elem_value
*ucontrol
)
2170 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2171 const char *pin
= (const char *)kcontrol
->private_value
;
2173 mutex_lock(&codec
->mutex
);
2175 if (ucontrol
->value
.integer
.value
[0])
2176 snd_soc_dapm_enable_pin(&codec
->dapm
, pin
);
2178 snd_soc_dapm_disable_pin(&codec
->dapm
, pin
);
2180 snd_soc_dapm_sync(&codec
->dapm
);
2182 mutex_unlock(&codec
->mutex
);
2186 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2189 * snd_soc_dapm_new_control - create new dapm control
2190 * @dapm: DAPM context
2191 * @widget: widget template
2193 * Creates a new dapm control based upon the template.
2195 * Returns 0 for success else error.
2197 int snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2198 const struct snd_soc_dapm_widget
*widget
)
2200 struct snd_soc_dapm_widget
*w
;
2203 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2206 name_len
= strlen(widget
->name
) + 1;
2207 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2208 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
2209 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
2210 if (w
->name
== NULL
) {
2214 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2215 snprintf(w
->name
, name_len
, "%s %s",
2216 dapm
->codec
->name_prefix
, widget
->name
);
2218 snprintf(w
->name
, name_len
, "%s", widget
->name
);
2222 w
->codec
= dapm
->codec
;
2223 INIT_LIST_HEAD(&w
->sources
);
2224 INIT_LIST_HEAD(&w
->sinks
);
2225 INIT_LIST_HEAD(&w
->list
);
2226 list_add(&w
->list
, &dapm
->card
->widgets
);
2228 /* machine layer set ups unconnected pins and insertions */
2232 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
2235 * snd_soc_dapm_new_controls - create new dapm controls
2236 * @dapm: DAPM context
2237 * @widget: widget array
2238 * @num: number of widgets
2240 * Creates new DAPM controls based upon the templates.
2242 * Returns 0 for success else error.
2244 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
2245 const struct snd_soc_dapm_widget
*widget
,
2250 for (i
= 0; i
< num
; i
++) {
2251 ret
= snd_soc_dapm_new_control(dapm
, widget
);
2254 "ASoC: Failed to create DAPM control %s: %d\n",
2262 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
2264 static void soc_dapm_stream_event(struct snd_soc_dapm_context
*dapm
,
2265 const char *stream
, int event
)
2267 struct snd_soc_dapm_widget
*w
;
2269 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2271 if (!w
->sname
|| w
->dapm
!= dapm
)
2273 dev_dbg(w
->dapm
->dev
, "widget %s\n %s stream %s event %d\n",
2274 w
->name
, w
->sname
, stream
, event
);
2275 if (strstr(w
->sname
, stream
)) {
2277 case SND_SOC_DAPM_STREAM_START
:
2280 case SND_SOC_DAPM_STREAM_STOP
:
2283 case SND_SOC_DAPM_STREAM_SUSPEND
:
2284 case SND_SOC_DAPM_STREAM_RESUME
:
2285 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
2286 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
2292 dapm_power_widgets(dapm
, event
);
2296 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2297 * @rtd: PCM runtime data
2298 * @stream: stream name
2299 * @event: stream event
2301 * Sends a stream event to the dapm core. The core then makes any
2302 * necessary widget power changes.
2304 * Returns 0 for success else error.
2306 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
,
2307 const char *stream
, int event
)
2309 struct snd_soc_codec
*codec
= rtd
->codec
;
2314 mutex_lock(&codec
->mutex
);
2315 soc_dapm_stream_event(&codec
->dapm
, stream
, event
);
2316 mutex_unlock(&codec
->mutex
);
2321 * snd_soc_dapm_enable_pin - enable pin.
2322 * @dapm: DAPM context
2325 * Enables input/output pin and its parents or children widgets iff there is
2326 * a valid audio route and active audio stream.
2327 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2328 * do any widget power switching.
2330 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2332 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
2334 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
2337 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2338 * @dapm: DAPM context
2341 * Enables input/output pin regardless of any other state. This is
2342 * intended for use with microphone bias supplies used in microphone
2345 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2346 * do any widget power switching.
2348 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
2351 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2354 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2358 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
2364 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
2367 * snd_soc_dapm_disable_pin - disable pin.
2368 * @dapm: DAPM context
2371 * Disables input/output pin and its parents or children widgets.
2372 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2373 * do any widget power switching.
2375 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
2378 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2380 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
2383 * snd_soc_dapm_nc_pin - permanently disable pin.
2384 * @dapm: DAPM context
2387 * Marks the specified pin as being not connected, disabling it along
2388 * any parent or child widgets. At present this is identical to
2389 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2390 * additional things such as disabling controls which only affect
2391 * paths through the pin.
2393 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2394 * do any widget power switching.
2396 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2398 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2400 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
2403 * snd_soc_dapm_get_pin_status - get audio pin status
2404 * @dapm: DAPM context
2405 * @pin: audio signal pin endpoint (or start point)
2407 * Get audio pin status - connected or disconnected.
2409 * Returns 1 for connected otherwise 0.
2411 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
2414 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2417 return w
->connected
;
2421 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
2424 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2425 * @dapm: DAPM context
2426 * @pin: audio signal pin endpoint (or start point)
2428 * Mark the given endpoint or pin as ignoring suspend. When the
2429 * system is disabled a path between two endpoints flagged as ignoring
2430 * suspend will not be disabled. The path must already be enabled via
2431 * normal means at suspend time, it will not be turned on if it was not
2434 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
2437 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
2440 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2444 w
->ignore_suspend
= 1;
2448 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
2451 * snd_soc_dapm_free - free dapm resources
2454 * Free all dapm widgets and resources.
2456 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
2458 snd_soc_dapm_sys_remove(dapm
->dev
);
2459 dapm_debugfs_cleanup(dapm
);
2460 dapm_free_widgets(dapm
);
2461 list_del(&dapm
->list
);
2463 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
2465 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
2467 struct snd_soc_dapm_widget
*w
;
2468 LIST_HEAD(down_list
);
2471 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2472 if (w
->dapm
!= dapm
)
2475 dapm_seq_insert(w
, &down_list
, false);
2481 /* If there were no widgets to power down we're already in
2485 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_PREPARE
);
2486 dapm_seq_run(dapm
, &down_list
, 0, false);
2487 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_STANDBY
);
2492 * snd_soc_dapm_shutdown - callback for system shutdown
2494 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
2496 struct snd_soc_codec
*codec
;
2498 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
2499 soc_dapm_shutdown_codec(&codec
->dapm
);
2500 snd_soc_dapm_set_bias_level(&codec
->dapm
, SND_SOC_BIAS_OFF
);
2504 /* Module information */
2505 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2506 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2507 MODULE_LICENSE("GPL");