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 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
328 const struct snd_kcontrol_new
*kcontrol_new
,
329 struct snd_kcontrol
**kcontrol
)
331 struct snd_soc_dapm_widget
*w
;
336 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
337 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
338 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
340 *kcontrol
= w
->kcontrols
[i
];
349 /* create new dapm mixer control */
350 static int dapm_new_mixer(struct snd_soc_dapm_context
*dapm
,
351 struct snd_soc_dapm_widget
*w
)
354 size_t name_len
, prefix_len
;
355 struct snd_soc_dapm_path
*path
;
356 struct snd_card
*card
= dapm
->card
->snd_card
;
358 struct snd_soc_dapm_widget_list
*wlist
;
362 prefix
= dapm
->codec
->name_prefix
;
367 prefix_len
= strlen(prefix
) + 1;
372 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
375 list_for_each_entry(path
, &w
->sources
, list_sink
) {
377 /* mixer/mux paths name must match control name */
378 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
381 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
382 sizeof(struct snd_soc_dapm_widget
*),
383 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
386 "asoc: can't allocate widget list for %s\n",
390 wlist
->num_widgets
= 1;
391 wlist
->widgets
[0] = w
;
393 /* add dapm control with long name.
394 * for dapm_mixer this is the concatenation of the
395 * mixer and kcontrol name.
396 * for dapm_mixer_named_ctl this is simply the
399 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
400 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
401 name_len
+= 1 + strlen(w
->name
);
403 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
405 if (path
->long_name
== NULL
) {
412 /* The control will get a prefix from
413 * the control creation process but
414 * we're also using the same prefix
415 * for widgets so cut the prefix off
416 * the front of the widget name.
418 snprintf(path
->long_name
, name_len
, "%s %s",
419 w
->name
+ prefix_len
,
420 w
->kcontrol_news
[i
].name
);
422 case snd_soc_dapm_mixer_named_ctl
:
423 snprintf(path
->long_name
, name_len
, "%s",
424 w
->kcontrol_news
[i
].name
);
428 path
->long_name
[name_len
- 1] = '\0';
430 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
431 wlist
, path
->long_name
,
433 ret
= snd_ctl_add(card
, path
->kcontrol
);
436 "asoc: failed to add dapm kcontrol %s: %d\n",
437 path
->long_name
, ret
);
439 kfree(path
->long_name
);
440 path
->long_name
= NULL
;
443 w
->kcontrols
[i
] = path
->kcontrol
;
449 /* create new dapm mux control */
450 static int dapm_new_mux(struct snd_soc_dapm_context
*dapm
,
451 struct snd_soc_dapm_widget
*w
)
453 struct snd_soc_dapm_path
*path
= NULL
;
454 struct snd_kcontrol
*kcontrol
;
455 struct snd_card
*card
= dapm
->card
->snd_card
;
459 struct snd_soc_dapm_widget_list
*wlist
;
460 int shared
, wlistentries
;
464 if (w
->num_kcontrols
!= 1) {
466 "asoc: mux %s has incorrect number of controls\n",
471 shared
= dapm_is_shared_kcontrol(dapm
, &w
->kcontrol_news
[0],
474 wlist
= kcontrol
->private_data
;
475 wlistentries
= wlist
->num_widgets
+ 1;
480 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
481 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
482 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
485 "asoc: can't allocate widget list for %s\n", w
->name
);
488 wlist
->num_widgets
= wlistentries
;
489 wlist
->widgets
[wlistentries
- 1] = w
;
493 prefix
= dapm
->codec
->name_prefix
;
498 name
= w
->kcontrol_news
[0].name
;
503 prefix_len
= strlen(prefix
) + 1;
509 * The control will get a prefix from the control creation
510 * process but we're also using the same prefix for widgets so
511 * cut the prefix off the front of the widget name.
513 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
514 name
+ prefix_len
, prefix
);
515 ret
= snd_ctl_add(card
, kcontrol
);
518 "asoc: failed to add kcontrol %s\n", w
->name
);
524 kcontrol
->private_data
= wlist
;
526 w
->kcontrols
[0] = kcontrol
;
528 list_for_each_entry(path
, &w
->sources
, list_sink
)
529 path
->kcontrol
= kcontrol
;
534 /* create new dapm volume control */
535 static int dapm_new_pga(struct snd_soc_dapm_context
*dapm
,
536 struct snd_soc_dapm_widget
*w
)
538 if (w
->num_kcontrols
)
539 dev_err(w
->dapm
->dev
,
540 "asoc: PGA controls not supported: '%s'\n", w
->name
);
545 /* reset 'walked' bit for each dapm path */
546 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
548 struct snd_soc_dapm_path
*p
;
550 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
554 /* We implement power down on suspend by checking the power state of
555 * the ALSA card - when we are suspending the ALSA state for the card
558 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
560 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
563 case SNDRV_CTL_POWER_D3hot
:
564 case SNDRV_CTL_POWER_D3cold
:
565 if (widget
->ignore_suspend
)
566 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
568 return widget
->ignore_suspend
;
575 * Recursively check for a completed path to an active or physically connected
576 * output widget. Returns number of complete paths.
578 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
580 struct snd_soc_dapm_path
*path
;
583 if (widget
->id
== snd_soc_dapm_supply
)
586 switch (widget
->id
) {
587 case snd_soc_dapm_adc
:
588 case snd_soc_dapm_aif_out
:
590 return snd_soc_dapm_suspend_check(widget
);
595 if (widget
->connected
) {
596 /* connected pin ? */
597 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
598 return snd_soc_dapm_suspend_check(widget
);
600 /* connected jack or spk ? */
601 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
602 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sources
)))
603 return snd_soc_dapm_suspend_check(widget
);
606 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
610 if (path
->sink
&& path
->connect
) {
612 con
+= is_connected_output_ep(path
->sink
);
620 * Recursively check for a completed path to an active or physically connected
621 * input widget. Returns number of complete paths.
623 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
625 struct snd_soc_dapm_path
*path
;
628 if (widget
->id
== snd_soc_dapm_supply
)
631 /* active stream ? */
632 switch (widget
->id
) {
633 case snd_soc_dapm_dac
:
634 case snd_soc_dapm_aif_in
:
636 return snd_soc_dapm_suspend_check(widget
);
641 if (widget
->connected
) {
642 /* connected pin ? */
643 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
644 return snd_soc_dapm_suspend_check(widget
);
646 /* connected VMID/Bias for lower pops */
647 if (widget
->id
== snd_soc_dapm_vmid
)
648 return snd_soc_dapm_suspend_check(widget
);
650 /* connected jack ? */
651 if (widget
->id
== snd_soc_dapm_mic
||
652 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sinks
)))
653 return snd_soc_dapm_suspend_check(widget
);
656 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
660 if (path
->source
&& path
->connect
) {
662 con
+= is_connected_input_ep(path
->source
);
670 * Handler for generic register modifier widget.
672 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
673 struct snd_kcontrol
*kcontrol
, int event
)
677 if (SND_SOC_DAPM_EVENT_ON(event
))
682 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
683 w
->mask
<< w
->shift
, val
<< w
->shift
);
687 EXPORT_SYMBOL_GPL(dapm_reg_event
);
689 /* Generic check to see if a widget should be powered.
691 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
695 in
= is_connected_input_ep(w
);
696 dapm_clear_walk(w
->dapm
);
697 out
= is_connected_output_ep(w
);
698 dapm_clear_walk(w
->dapm
);
699 return out
!= 0 && in
!= 0;
702 /* Check to see if an ADC has power */
703 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
708 in
= is_connected_input_ep(w
);
709 dapm_clear_walk(w
->dapm
);
712 return dapm_generic_check_power(w
);
716 /* Check to see if a DAC has power */
717 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
722 out
= is_connected_output_ep(w
);
723 dapm_clear_walk(w
->dapm
);
726 return dapm_generic_check_power(w
);
730 /* Check to see if a power supply is needed */
731 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
733 struct snd_soc_dapm_path
*path
;
736 /* Check if one of our outputs is connected */
737 list_for_each_entry(path
, &w
->sinks
, list_source
) {
738 if (path
->connected
&&
739 !path
->connected(path
->source
, path
->sink
))
745 if (path
->sink
->force
) {
750 if (path
->sink
->power_check
&&
751 path
->sink
->power_check(path
->sink
)) {
757 dapm_clear_walk(w
->dapm
);
762 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
763 struct snd_soc_dapm_widget
*b
,
771 sort
= dapm_down_seq
;
773 if (sort
[a
->id
] != sort
[b
->id
])
774 return sort
[a
->id
] - sort
[b
->id
];
775 if (a
->subseq
!= b
->subseq
) {
777 return a
->subseq
- b
->subseq
;
779 return b
->subseq
- a
->subseq
;
781 if (a
->reg
!= b
->reg
)
782 return a
->reg
- b
->reg
;
783 if (a
->dapm
!= b
->dapm
)
784 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
789 /* Insert a widget in order into a DAPM power sequence. */
790 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
791 struct list_head
*list
,
794 struct snd_soc_dapm_widget
*w
;
796 list_for_each_entry(w
, list
, power_list
)
797 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
798 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
802 list_add_tail(&new_widget
->power_list
, list
);
805 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
806 struct snd_soc_dapm_widget
*w
, int event
)
808 struct snd_soc_card
*card
= dapm
->card
;
813 case SND_SOC_DAPM_PRE_PMU
:
817 case SND_SOC_DAPM_POST_PMU
:
818 ev_name
= "POST_PMU";
821 case SND_SOC_DAPM_PRE_PMD
:
825 case SND_SOC_DAPM_POST_PMD
:
826 ev_name
= "POST_PMD";
834 if (w
->power
!= power
)
837 if (w
->event
&& (w
->event_flags
& event
)) {
838 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
840 trace_snd_soc_dapm_widget_event_start(w
, event
);
841 ret
= w
->event(w
, NULL
, event
);
842 trace_snd_soc_dapm_widget_event_done(w
, event
);
844 pr_err("%s: %s event failed: %d\n",
845 ev_name
, w
->name
, ret
);
849 /* Apply the coalesced changes from a DAPM sequence */
850 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
851 struct list_head
*pending
)
853 struct snd_soc_card
*card
= dapm
->card
;
854 struct snd_soc_dapm_widget
*w
;
856 unsigned int value
= 0;
857 unsigned int mask
= 0;
858 unsigned int cur_mask
;
860 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
863 list_for_each_entry(w
, pending
, power_list
) {
864 cur_mask
= 1 << w
->shift
;
865 BUG_ON(reg
!= w
->reg
);
876 pop_dbg(dapm
->dev
, card
->pop_time
,
877 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
878 w
->name
, reg
, value
, mask
);
880 /* Check for events */
881 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
882 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
886 pop_dbg(dapm
->dev
, card
->pop_time
,
887 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
888 value
, mask
, reg
, card
->pop_time
);
889 pop_wait(card
->pop_time
);
890 snd_soc_update_bits(dapm
->codec
, reg
, mask
, value
);
893 list_for_each_entry(w
, pending
, power_list
) {
894 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
895 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
899 /* Apply a DAPM power sequence.
901 * We walk over a pre-sorted list of widgets to apply power to. In
902 * order to minimise the number of writes to the device required
903 * multiple widgets will be updated in a single write where possible.
904 * Currently anything that requires more than a single write is not
907 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
908 struct list_head
*list
, int event
, bool power_up
)
910 struct snd_soc_dapm_widget
*w
, *n
;
914 int cur_reg
= SND_SOC_NOPM
;
915 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
922 sort
= dapm_down_seq
;
924 list_for_each_entry_safe(w
, n
, list
, power_list
) {
927 /* Do we need to apply any queued changes? */
928 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
929 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
930 if (!list_empty(&pending
))
931 dapm_seq_run_coalesced(cur_dapm
, &pending
);
933 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
934 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
935 if (sort
[i
] == cur_sort
)
936 cur_dapm
->seq_notifier(cur_dapm
,
941 INIT_LIST_HEAD(&pending
);
944 cur_reg
= SND_SOC_NOPM
;
949 case snd_soc_dapm_pre
:
951 list_for_each_entry_safe_continue(w
, n
, list
,
954 if (event
== SND_SOC_DAPM_STREAM_START
)
956 NULL
, SND_SOC_DAPM_PRE_PMU
);
957 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
959 NULL
, SND_SOC_DAPM_PRE_PMD
);
962 case snd_soc_dapm_post
:
964 list_for_each_entry_safe_continue(w
, n
, list
,
967 if (event
== SND_SOC_DAPM_STREAM_START
)
969 NULL
, SND_SOC_DAPM_POST_PMU
);
970 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
972 NULL
, SND_SOC_DAPM_POST_PMD
);
976 /* Queue it up for application */
977 cur_sort
= sort
[w
->id
];
978 cur_subseq
= w
->subseq
;
981 list_move(&w
->power_list
, &pending
);
986 dev_err(w
->dapm
->dev
,
987 "Failed to apply widget power: %d\n", ret
);
990 if (!list_empty(&pending
))
991 dapm_seq_run_coalesced(cur_dapm
, &pending
);
993 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
994 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
995 if (sort
[i
] == cur_sort
)
996 cur_dapm
->seq_notifier(cur_dapm
,
1001 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1003 struct snd_soc_dapm_update
*update
= dapm
->update
;
1004 struct snd_soc_dapm_widget
*w
;
1013 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1014 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1016 pr_err("%s DAPM pre-event failed: %d\n",
1020 ret
= snd_soc_update_bits(w
->codec
, update
->reg
, update
->mask
,
1023 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1026 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1027 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1029 pr_err("%s DAPM post-event failed: %d\n",
1034 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1035 * they're changing state.
1037 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1039 struct snd_soc_dapm_context
*d
= data
;
1042 if (d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_OFF
) {
1043 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1046 "Failed to turn on bias: %d\n", ret
);
1049 /* If we're changing to all on or all off then prepare */
1050 if ((d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_STANDBY
) ||
1051 (!d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_ON
)) {
1052 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1055 "Failed to prepare bias: %d\n", ret
);
1059 /* Async callback run prior to DAPM sequences - brings to their final
1062 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1064 struct snd_soc_dapm_context
*d
= data
;
1067 /* If we just powered the last thing off drop to standby bias */
1068 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&& !d
->dev_power
) {
1069 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1071 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1075 /* If we're in standby and can support bias off then do that */
1076 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&& d
->idle_bias_off
) {
1077 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1079 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1082 /* If we just powered up then move to active bias */
1083 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&& d
->dev_power
) {
1084 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1086 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1092 * Scan each dapm widget for complete audio path.
1093 * A complete path is a route that has valid endpoints i.e.:-
1095 * o DAC to output pin.
1096 * o Input Pin to ADC.
1097 * o Input pin to Output pin (bypass, sidetone)
1098 * o DAC to ADC (loopback).
1100 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1102 struct snd_soc_card
*card
= dapm
->card
;
1103 struct snd_soc_dapm_widget
*w
;
1104 struct snd_soc_dapm_context
*d
;
1106 LIST_HEAD(down_list
);
1107 LIST_HEAD(async_domain
);
1110 trace_snd_soc_dapm_start(card
);
1112 list_for_each_entry(d
, &card
->dapm_list
, list
)
1116 /* Check which widgets we need to power and store them in
1117 * lists indicating if they should be powered up or down.
1119 list_for_each_entry(w
, &card
->widgets
, list
) {
1121 case snd_soc_dapm_pre
:
1122 dapm_seq_insert(w
, &down_list
, false);
1124 case snd_soc_dapm_post
:
1125 dapm_seq_insert(w
, &up_list
, true);
1129 if (!w
->power_check
)
1133 power
= w
->power_check(w
);
1137 w
->dapm
->dev_power
= 1;
1139 if (w
->power
== power
)
1142 trace_snd_soc_dapm_widget_power(w
, power
);
1145 dapm_seq_insert(w
, &up_list
, true);
1147 dapm_seq_insert(w
, &down_list
, false);
1154 /* If there are no DAPM widgets then try to figure out power from the
1157 if (!dapm
->n_widgets
) {
1159 case SND_SOC_DAPM_STREAM_START
:
1160 case SND_SOC_DAPM_STREAM_RESUME
:
1161 dapm
->dev_power
= 1;
1163 case SND_SOC_DAPM_STREAM_STOP
:
1164 dapm
->dev_power
= !!dapm
->codec
->active
;
1166 case SND_SOC_DAPM_STREAM_SUSPEND
:
1167 dapm
->dev_power
= 0;
1169 case SND_SOC_DAPM_STREAM_NOP
:
1170 switch (dapm
->bias_level
) {
1171 case SND_SOC_BIAS_STANDBY
:
1172 case SND_SOC_BIAS_OFF
:
1173 dapm
->dev_power
= 0;
1176 dapm
->dev_power
= 1;
1185 /* Force all contexts in the card to the same bias state */
1187 list_for_each_entry(d
, &card
->dapm_list
, list
)
1190 list_for_each_entry(d
, &card
->dapm_list
, list
)
1191 d
->dev_power
= power
;
1194 /* Run all the bias changes in parallel */
1195 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1196 async_schedule_domain(dapm_pre_sequence_async
, d
,
1198 async_synchronize_full_domain(&async_domain
);
1200 /* Power down widgets first; try to avoid amplifying pops. */
1201 dapm_seq_run(dapm
, &down_list
, event
, false);
1203 dapm_widget_update(dapm
);
1206 dapm_seq_run(dapm
, &up_list
, event
, true);
1208 /* Run all the bias changes in parallel */
1209 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1210 async_schedule_domain(dapm_post_sequence_async
, d
,
1212 async_synchronize_full_domain(&async_domain
);
1214 pop_dbg(dapm
->dev
, card
->pop_time
,
1215 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1216 pop_wait(card
->pop_time
);
1218 trace_snd_soc_dapm_done(card
);
1223 #ifdef CONFIG_DEBUG_FS
1224 static int dapm_widget_power_open_file(struct inode
*inode
, struct file
*file
)
1226 file
->private_data
= inode
->i_private
;
1230 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1231 char __user
*user_buf
,
1232 size_t count
, loff_t
*ppos
)
1234 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1238 struct snd_soc_dapm_path
*p
= NULL
;
1240 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1244 in
= is_connected_input_ep(w
);
1245 dapm_clear_walk(w
->dapm
);
1246 out
= is_connected_output_ep(w
);
1247 dapm_clear_walk(w
->dapm
);
1249 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s in %d out %d",
1250 w
->name
, w
->power
? "On" : "Off", in
, out
);
1253 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1254 " - R%d(0x%x) bit %d",
1255 w
->reg
, w
->reg
, w
->shift
);
1257 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1260 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1262 w
->active
? "active" : "inactive");
1264 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1265 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1269 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1270 " in \"%s\" \"%s\"\n",
1271 p
->name
? p
->name
: "static",
1274 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1275 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1279 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1280 " out \"%s\" \"%s\"\n",
1281 p
->name
? p
->name
: "static",
1285 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1291 static const struct file_operations dapm_widget_power_fops
= {
1292 .open
= dapm_widget_power_open_file
,
1293 .read
= dapm_widget_power_read_file
,
1294 .llseek
= default_llseek
,
1297 static int dapm_bias_open_file(struct inode
*inode
, struct file
*file
)
1299 file
->private_data
= inode
->i_private
;
1303 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1304 size_t count
, loff_t
*ppos
)
1306 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1309 switch (dapm
->bias_level
) {
1310 case SND_SOC_BIAS_ON
:
1313 case SND_SOC_BIAS_PREPARE
:
1314 level
= "Prepare\n";
1316 case SND_SOC_BIAS_STANDBY
:
1317 level
= "Standby\n";
1319 case SND_SOC_BIAS_OFF
:
1324 level
= "Unknown\n";
1328 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1332 static const struct file_operations dapm_bias_fops
= {
1333 .open
= dapm_bias_open_file
,
1334 .read
= dapm_bias_read_file
,
1335 .llseek
= default_llseek
,
1338 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1339 struct dentry
*parent
)
1343 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1345 if (!dapm
->debugfs_dapm
) {
1347 "Failed to create DAPM debugfs directory\n");
1351 d
= debugfs_create_file("bias_level", 0444,
1352 dapm
->debugfs_dapm
, dapm
,
1356 "ASoC: Failed to create bias level debugfs file\n");
1359 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1361 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1364 if (!dapm
->debugfs_dapm
|| !w
->name
)
1367 d
= debugfs_create_file(w
->name
, 0444,
1368 dapm
->debugfs_dapm
, w
,
1369 &dapm_widget_power_fops
);
1371 dev_warn(w
->dapm
->dev
,
1372 "ASoC: Failed to create %s debugfs file\n",
1376 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1378 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1382 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1383 struct dentry
*parent
)
1387 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1391 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1397 /* test and update the power status of a mux widget */
1398 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1399 struct snd_kcontrol
*kcontrol
, int change
,
1400 int mux
, struct soc_enum
*e
)
1402 struct snd_soc_dapm_path
*path
;
1405 if (widget
->id
!= snd_soc_dapm_mux
&&
1406 widget
->id
!= snd_soc_dapm_virt_mux
&&
1407 widget
->id
!= snd_soc_dapm_value_mux
)
1413 /* find dapm widget path assoc with kcontrol */
1414 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1415 if (path
->kcontrol
!= kcontrol
)
1418 if (!path
->name
|| !e
->texts
[mux
])
1422 /* we now need to match the string in the enum to the path */
1423 if (!(strcmp(path
->name
, e
->texts
[mux
])))
1424 path
->connect
= 1; /* new connection */
1426 path
->connect
= 0; /* old connection must be powered down */
1430 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1435 /* test and update the power status of a mixer or switch widget */
1436 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1437 struct snd_kcontrol
*kcontrol
, int connect
)
1439 struct snd_soc_dapm_path
*path
;
1442 if (widget
->id
!= snd_soc_dapm_mixer
&&
1443 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1444 widget
->id
!= snd_soc_dapm_switch
)
1447 /* find dapm widget path assoc with kcontrol */
1448 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1449 if (path
->kcontrol
!= kcontrol
)
1452 /* found, now check type */
1454 path
->connect
= connect
;
1459 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1464 /* show dapm widget status in sys fs */
1465 static ssize_t
dapm_widget_show(struct device
*dev
,
1466 struct device_attribute
*attr
, char *buf
)
1468 struct snd_soc_pcm_runtime
*rtd
=
1469 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
1470 struct snd_soc_codec
*codec
=rtd
->codec
;
1471 struct snd_soc_dapm_widget
*w
;
1473 char *state
= "not set";
1475 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1476 if (w
->dapm
!= &codec
->dapm
)
1479 /* only display widgets that burnm power */
1481 case snd_soc_dapm_hp
:
1482 case snd_soc_dapm_mic
:
1483 case snd_soc_dapm_spk
:
1484 case snd_soc_dapm_line
:
1485 case snd_soc_dapm_micbias
:
1486 case snd_soc_dapm_dac
:
1487 case snd_soc_dapm_adc
:
1488 case snd_soc_dapm_pga
:
1489 case snd_soc_dapm_out_drv
:
1490 case snd_soc_dapm_mixer
:
1491 case snd_soc_dapm_mixer_named_ctl
:
1492 case snd_soc_dapm_supply
:
1494 count
+= sprintf(buf
+ count
, "%s: %s\n",
1495 w
->name
, w
->power
? "On":"Off");
1502 switch (codec
->dapm
.bias_level
) {
1503 case SND_SOC_BIAS_ON
:
1506 case SND_SOC_BIAS_PREPARE
:
1509 case SND_SOC_BIAS_STANDBY
:
1512 case SND_SOC_BIAS_OFF
:
1516 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1521 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1523 int snd_soc_dapm_sys_add(struct device
*dev
)
1525 return device_create_file(dev
, &dev_attr_dapm_widget
);
1528 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1530 device_remove_file(dev
, &dev_attr_dapm_widget
);
1533 /* free all dapm widgets and resources */
1534 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
1536 struct snd_soc_dapm_widget
*w
, *next_w
;
1537 struct snd_soc_dapm_path
*p
, *next_p
;
1539 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
1540 if (w
->dapm
!= dapm
)
1544 * remove source and sink paths associated to this widget.
1545 * While removing the path, remove reference to it from both
1546 * source and sink widgets so that path is removed only once.
1548 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
1549 list_del(&p
->list_sink
);
1550 list_del(&p
->list_source
);
1552 kfree(p
->long_name
);
1555 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
1556 list_del(&p
->list_sink
);
1557 list_del(&p
->list_source
);
1559 kfree(p
->long_name
);
1562 kfree(w
->kcontrols
);
1568 static struct snd_soc_dapm_widget
*dapm_find_widget(
1569 struct snd_soc_dapm_context
*dapm
, const char *pin
,
1570 bool search_other_contexts
)
1572 struct snd_soc_dapm_widget
*w
;
1573 struct snd_soc_dapm_widget
*fallback
= NULL
;
1575 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1576 if (!strcmp(w
->name
, pin
)) {
1577 if (w
->dapm
== dapm
)
1584 if (search_other_contexts
)
1590 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
1591 const char *pin
, int status
)
1593 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
1596 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
1600 w
->connected
= status
;
1608 * snd_soc_dapm_sync - scan and power dapm paths
1609 * @dapm: DAPM context
1611 * Walks all dapm audio paths and powers widgets according to their
1612 * stream or path usage.
1614 * Returns 0 for success.
1616 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
1618 return dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1620 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1622 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
1623 const struct snd_soc_dapm_route
*route
)
1625 struct snd_soc_dapm_path
*path
;
1626 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1627 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
1629 const char *control
= route
->control
;
1631 char prefixed_sink
[80];
1632 char prefixed_source
[80];
1635 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
1636 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
1637 dapm
->codec
->name_prefix
, route
->sink
);
1638 sink
= prefixed_sink
;
1639 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
1640 dapm
->codec
->name_prefix
, route
->source
);
1641 source
= prefixed_source
;
1644 source
= route
->source
;
1648 * find src and dest widgets over all widgets but favor a widget from
1649 * current DAPM context
1651 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1652 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1654 if (w
->dapm
== dapm
)
1658 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1660 if (w
->dapm
== dapm
)
1664 /* use widget from another DAPM context if not found from this */
1670 if (wsource
== NULL
|| wsink
== NULL
)
1673 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1677 path
->source
= wsource
;
1679 path
->connected
= route
->connected
;
1680 INIT_LIST_HEAD(&path
->list
);
1681 INIT_LIST_HEAD(&path
->list_source
);
1682 INIT_LIST_HEAD(&path
->list_sink
);
1684 /* check for external widgets */
1685 if (wsink
->id
== snd_soc_dapm_input
) {
1686 if (wsource
->id
== snd_soc_dapm_micbias
||
1687 wsource
->id
== snd_soc_dapm_mic
||
1688 wsource
->id
== snd_soc_dapm_line
||
1689 wsource
->id
== snd_soc_dapm_output
)
1692 if (wsource
->id
== snd_soc_dapm_output
) {
1693 if (wsink
->id
== snd_soc_dapm_spk
||
1694 wsink
->id
== snd_soc_dapm_hp
||
1695 wsink
->id
== snd_soc_dapm_line
||
1696 wsink
->id
== snd_soc_dapm_input
)
1700 /* connect static paths */
1701 if (control
== NULL
) {
1702 list_add(&path
->list
, &dapm
->card
->paths
);
1703 list_add(&path
->list_sink
, &wsink
->sources
);
1704 list_add(&path
->list_source
, &wsource
->sinks
);
1709 /* connect dynamic paths */
1710 switch (wsink
->id
) {
1711 case snd_soc_dapm_adc
:
1712 case snd_soc_dapm_dac
:
1713 case snd_soc_dapm_pga
:
1714 case snd_soc_dapm_out_drv
:
1715 case snd_soc_dapm_input
:
1716 case snd_soc_dapm_output
:
1717 case snd_soc_dapm_micbias
:
1718 case snd_soc_dapm_vmid
:
1719 case snd_soc_dapm_pre
:
1720 case snd_soc_dapm_post
:
1721 case snd_soc_dapm_supply
:
1722 case snd_soc_dapm_aif_in
:
1723 case snd_soc_dapm_aif_out
:
1724 list_add(&path
->list
, &dapm
->card
->paths
);
1725 list_add(&path
->list_sink
, &wsink
->sources
);
1726 list_add(&path
->list_source
, &wsource
->sinks
);
1729 case snd_soc_dapm_mux
:
1730 case snd_soc_dapm_virt_mux
:
1731 case snd_soc_dapm_value_mux
:
1732 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
1733 &wsink
->kcontrol_news
[0]);
1737 case snd_soc_dapm_switch
:
1738 case snd_soc_dapm_mixer
:
1739 case snd_soc_dapm_mixer_named_ctl
:
1740 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
1744 case snd_soc_dapm_hp
:
1745 case snd_soc_dapm_mic
:
1746 case snd_soc_dapm_line
:
1747 case snd_soc_dapm_spk
:
1748 list_add(&path
->list
, &dapm
->card
->paths
);
1749 list_add(&path
->list_sink
, &wsink
->sources
);
1750 list_add(&path
->list_source
, &wsource
->sinks
);
1757 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
1758 source
, control
, sink
);
1764 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1765 * @dapm: DAPM context
1766 * @route: audio routes
1767 * @num: number of routes
1769 * Connects 2 dapm widgets together via a named audio path. The sink is
1770 * the widget receiving the audio signal, whilst the source is the sender
1771 * of the audio signal.
1773 * Returns 0 for success else error. On error all resources can be freed
1774 * with a call to snd_soc_card_free().
1776 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
1777 const struct snd_soc_dapm_route
*route
, int num
)
1781 for (i
= 0; i
< num
; i
++) {
1782 ret
= snd_soc_dapm_add_route(dapm
, route
);
1784 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
1785 route
->source
, route
->sink
);
1793 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1796 * snd_soc_dapm_new_widgets - add new dapm widgets
1797 * @dapm: DAPM context
1799 * Checks the codec for any new dapm widgets and creates them if found.
1801 * Returns 0 for success.
1803 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
1805 struct snd_soc_dapm_widget
*w
;
1808 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
1813 if (w
->num_kcontrols
) {
1814 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
1815 sizeof(struct snd_kcontrol
*),
1822 case snd_soc_dapm_switch
:
1823 case snd_soc_dapm_mixer
:
1824 case snd_soc_dapm_mixer_named_ctl
:
1825 w
->power_check
= dapm_generic_check_power
;
1826 dapm_new_mixer(dapm
, w
);
1828 case snd_soc_dapm_mux
:
1829 case snd_soc_dapm_virt_mux
:
1830 case snd_soc_dapm_value_mux
:
1831 w
->power_check
= dapm_generic_check_power
;
1832 dapm_new_mux(dapm
, w
);
1834 case snd_soc_dapm_adc
:
1835 case snd_soc_dapm_aif_out
:
1836 w
->power_check
= dapm_adc_check_power
;
1838 case snd_soc_dapm_dac
:
1839 case snd_soc_dapm_aif_in
:
1840 w
->power_check
= dapm_dac_check_power
;
1842 case snd_soc_dapm_pga
:
1843 case snd_soc_dapm_out_drv
:
1844 w
->power_check
= dapm_generic_check_power
;
1845 dapm_new_pga(dapm
, w
);
1847 case snd_soc_dapm_input
:
1848 case snd_soc_dapm_output
:
1849 case snd_soc_dapm_micbias
:
1850 case snd_soc_dapm_spk
:
1851 case snd_soc_dapm_hp
:
1852 case snd_soc_dapm_mic
:
1853 case snd_soc_dapm_line
:
1854 w
->power_check
= dapm_generic_check_power
;
1856 case snd_soc_dapm_supply
:
1857 w
->power_check
= dapm_supply_check_power
;
1858 case snd_soc_dapm_vmid
:
1859 case snd_soc_dapm_pre
:
1860 case snd_soc_dapm_post
:
1864 /* Read the initial power state from the device */
1866 val
= snd_soc_read(w
->codec
, w
->reg
);
1867 val
&= 1 << w
->shift
;
1877 dapm_debugfs_add_widget(w
);
1880 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1883 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1886 * snd_soc_dapm_get_volsw - dapm mixer get callback
1887 * @kcontrol: mixer control
1888 * @ucontrol: control element information
1890 * Callback to get the value of a dapm mixer control.
1892 * Returns 0 for success.
1894 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1895 struct snd_ctl_elem_value
*ucontrol
)
1897 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
1898 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
1899 struct soc_mixer_control
*mc
=
1900 (struct soc_mixer_control
*)kcontrol
->private_value
;
1901 unsigned int reg
= mc
->reg
;
1902 unsigned int shift
= mc
->shift
;
1903 unsigned int rshift
= mc
->rshift
;
1905 unsigned int invert
= mc
->invert
;
1906 unsigned int mask
= (1 << fls(max
)) - 1;
1908 ucontrol
->value
.integer
.value
[0] =
1909 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1910 if (shift
!= rshift
)
1911 ucontrol
->value
.integer
.value
[1] =
1912 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1914 ucontrol
->value
.integer
.value
[0] =
1915 max
- ucontrol
->value
.integer
.value
[0];
1916 if (shift
!= rshift
)
1917 ucontrol
->value
.integer
.value
[1] =
1918 max
- ucontrol
->value
.integer
.value
[1];
1923 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1926 * snd_soc_dapm_put_volsw - dapm mixer set callback
1927 * @kcontrol: mixer control
1928 * @ucontrol: control element information
1930 * Callback to set the value of a dapm mixer control.
1932 * Returns 0 for success.
1934 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1935 struct snd_ctl_elem_value
*ucontrol
)
1937 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
1938 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
1939 struct snd_soc_codec
*codec
= widget
->codec
;
1940 struct soc_mixer_control
*mc
=
1941 (struct soc_mixer_control
*)kcontrol
->private_value
;
1942 unsigned int reg
= mc
->reg
;
1943 unsigned int shift
= mc
->shift
;
1945 unsigned int mask
= (1 << fls(max
)) - 1;
1946 unsigned int invert
= mc
->invert
;
1948 int connect
, change
;
1949 struct snd_soc_dapm_update update
;
1952 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1956 mask
= mask
<< shift
;
1960 /* new connection */
1961 connect
= invert
? 0 : 1;
1963 /* old connection must be powered down */
1964 connect
= invert
? 1 : 0;
1966 mutex_lock(&codec
->mutex
);
1968 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
1970 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1971 widget
= wlist
->widgets
[wi
];
1973 widget
->value
= val
;
1975 update
.kcontrol
= kcontrol
;
1976 update
.widget
= widget
;
1980 widget
->dapm
->update
= &update
;
1982 dapm_mixer_update_power(widget
, kcontrol
, connect
);
1984 widget
->dapm
->update
= NULL
;
1988 mutex_unlock(&codec
->mutex
);
1991 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
1994 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1995 * @kcontrol: mixer control
1996 * @ucontrol: control element information
1998 * Callback to get the value of a dapm enumerated double mixer control.
2000 * Returns 0 for success.
2002 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2003 struct snd_ctl_elem_value
*ucontrol
)
2005 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2006 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2007 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2008 unsigned int val
, bitmask
;
2010 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2012 val
= snd_soc_read(widget
->codec
, e
->reg
);
2013 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
2014 if (e
->shift_l
!= e
->shift_r
)
2015 ucontrol
->value
.enumerated
.item
[1] =
2016 (val
>> e
->shift_r
) & (bitmask
- 1);
2020 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2023 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2024 * @kcontrol: mixer control
2025 * @ucontrol: control element information
2027 * Callback to set the value of a dapm enumerated double mixer control.
2029 * Returns 0 for success.
2031 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2032 struct snd_ctl_elem_value
*ucontrol
)
2034 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2035 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2036 struct snd_soc_codec
*codec
= widget
->codec
;
2037 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2038 unsigned int val
, mux
, change
;
2039 unsigned int mask
, bitmask
;
2040 struct snd_soc_dapm_update update
;
2043 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2045 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2047 mux
= ucontrol
->value
.enumerated
.item
[0];
2048 val
= mux
<< e
->shift_l
;
2049 mask
= (bitmask
- 1) << e
->shift_l
;
2050 if (e
->shift_l
!= e
->shift_r
) {
2051 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2053 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2054 mask
|= (bitmask
- 1) << e
->shift_r
;
2057 mutex_lock(&codec
->mutex
);
2059 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2061 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2062 widget
= wlist
->widgets
[wi
];
2064 widget
->value
= val
;
2066 update
.kcontrol
= kcontrol
;
2067 update
.widget
= widget
;
2068 update
.reg
= e
->reg
;
2071 widget
->dapm
->update
= &update
;
2073 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2075 widget
->dapm
->update
= NULL
;
2079 mutex_unlock(&codec
->mutex
);
2082 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2085 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2086 * @kcontrol: mixer control
2087 * @ucontrol: control element information
2089 * Returns 0 for success.
2091 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2092 struct snd_ctl_elem_value
*ucontrol
)
2094 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2095 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2097 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2101 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2104 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2105 * @kcontrol: mixer control
2106 * @ucontrol: control element information
2108 * Returns 0 for success.
2110 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2111 struct snd_ctl_elem_value
*ucontrol
)
2113 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2114 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2115 struct snd_soc_codec
*codec
= widget
->codec
;
2116 struct soc_enum
*e
=
2117 (struct soc_enum
*)kcontrol
->private_value
;
2122 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2125 mutex_lock(&codec
->mutex
);
2127 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2129 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2130 widget
= wlist
->widgets
[wi
];
2132 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2134 dapm_mux_update_power(widget
, kcontrol
, change
,
2139 mutex_unlock(&codec
->mutex
);
2142 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2145 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2147 * @kcontrol: mixer control
2148 * @ucontrol: control element information
2150 * Callback to get the value of a dapm semi enumerated double mixer control.
2152 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2153 * used for handling bitfield coded enumeration for example.
2155 * Returns 0 for success.
2157 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2158 struct snd_ctl_elem_value
*ucontrol
)
2160 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2161 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2162 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2163 unsigned int reg_val
, val
, mux
;
2165 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2166 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2167 for (mux
= 0; mux
< e
->max
; mux
++) {
2168 if (val
== e
->values
[mux
])
2171 ucontrol
->value
.enumerated
.item
[0] = mux
;
2172 if (e
->shift_l
!= e
->shift_r
) {
2173 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2174 for (mux
= 0; mux
< e
->max
; mux
++) {
2175 if (val
== e
->values
[mux
])
2178 ucontrol
->value
.enumerated
.item
[1] = mux
;
2183 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2186 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2188 * @kcontrol: mixer control
2189 * @ucontrol: control element information
2191 * Callback to set the value of a dapm semi enumerated double mixer control.
2193 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2194 * used for handling bitfield coded enumeration for example.
2196 * Returns 0 for success.
2198 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2199 struct snd_ctl_elem_value
*ucontrol
)
2201 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2202 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2203 struct snd_soc_codec
*codec
= widget
->codec
;
2204 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2205 unsigned int val
, mux
, change
;
2207 struct snd_soc_dapm_update update
;
2210 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2212 mux
= ucontrol
->value
.enumerated
.item
[0];
2213 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2214 mask
= e
->mask
<< e
->shift_l
;
2215 if (e
->shift_l
!= e
->shift_r
) {
2216 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2218 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2219 mask
|= e
->mask
<< e
->shift_r
;
2222 mutex_lock(&codec
->mutex
);
2224 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2226 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2227 widget
= wlist
->widgets
[wi
];
2229 widget
->value
= val
;
2231 update
.kcontrol
= kcontrol
;
2232 update
.widget
= widget
;
2233 update
.reg
= e
->reg
;
2236 widget
->dapm
->update
= &update
;
2238 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2240 widget
->dapm
->update
= NULL
;
2244 mutex_unlock(&codec
->mutex
);
2247 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2250 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2252 * @kcontrol: mixer control
2253 * @uinfo: control element information
2255 * Callback to provide information about a pin switch control.
2257 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2258 struct snd_ctl_elem_info
*uinfo
)
2260 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2262 uinfo
->value
.integer
.min
= 0;
2263 uinfo
->value
.integer
.max
= 1;
2267 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2270 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2272 * @kcontrol: mixer control
2275 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2276 struct snd_ctl_elem_value
*ucontrol
)
2278 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2279 const char *pin
= (const char *)kcontrol
->private_value
;
2281 mutex_lock(&codec
->mutex
);
2283 ucontrol
->value
.integer
.value
[0] =
2284 snd_soc_dapm_get_pin_status(&codec
->dapm
, pin
);
2286 mutex_unlock(&codec
->mutex
);
2290 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2293 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2295 * @kcontrol: mixer control
2298 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2299 struct snd_ctl_elem_value
*ucontrol
)
2301 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2302 const char *pin
= (const char *)kcontrol
->private_value
;
2304 mutex_lock(&codec
->mutex
);
2306 if (ucontrol
->value
.integer
.value
[0])
2307 snd_soc_dapm_enable_pin(&codec
->dapm
, pin
);
2309 snd_soc_dapm_disable_pin(&codec
->dapm
, pin
);
2311 snd_soc_dapm_sync(&codec
->dapm
);
2313 mutex_unlock(&codec
->mutex
);
2317 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2320 * snd_soc_dapm_new_control - create new dapm control
2321 * @dapm: DAPM context
2322 * @widget: widget template
2324 * Creates a new dapm control based upon the template.
2326 * Returns 0 for success else error.
2328 int snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2329 const struct snd_soc_dapm_widget
*widget
)
2331 struct snd_soc_dapm_widget
*w
;
2334 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2337 name_len
= strlen(widget
->name
) + 1;
2338 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2339 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
2340 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
2341 if (w
->name
== NULL
) {
2345 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2346 snprintf(w
->name
, name_len
, "%s %s",
2347 dapm
->codec
->name_prefix
, widget
->name
);
2349 snprintf(w
->name
, name_len
, "%s", widget
->name
);
2353 w
->codec
= dapm
->codec
;
2354 INIT_LIST_HEAD(&w
->sources
);
2355 INIT_LIST_HEAD(&w
->sinks
);
2356 INIT_LIST_HEAD(&w
->list
);
2357 list_add(&w
->list
, &dapm
->card
->widgets
);
2359 /* machine layer set ups unconnected pins and insertions */
2363 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
2366 * snd_soc_dapm_new_controls - create new dapm controls
2367 * @dapm: DAPM context
2368 * @widget: widget array
2369 * @num: number of widgets
2371 * Creates new DAPM controls based upon the templates.
2373 * Returns 0 for success else error.
2375 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
2376 const struct snd_soc_dapm_widget
*widget
,
2381 for (i
= 0; i
< num
; i
++) {
2382 ret
= snd_soc_dapm_new_control(dapm
, widget
);
2385 "ASoC: Failed to create DAPM control %s: %d\n",
2393 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
2395 static void soc_dapm_stream_event(struct snd_soc_dapm_context
*dapm
,
2396 const char *stream
, int event
)
2398 struct snd_soc_dapm_widget
*w
;
2400 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2402 if (!w
->sname
|| w
->dapm
!= dapm
)
2404 dev_dbg(w
->dapm
->dev
, "widget %s\n %s stream %s event %d\n",
2405 w
->name
, w
->sname
, stream
, event
);
2406 if (strstr(w
->sname
, stream
)) {
2408 case SND_SOC_DAPM_STREAM_START
:
2411 case SND_SOC_DAPM_STREAM_STOP
:
2414 case SND_SOC_DAPM_STREAM_SUSPEND
:
2415 case SND_SOC_DAPM_STREAM_RESUME
:
2416 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
2417 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
2423 dapm_power_widgets(dapm
, event
);
2427 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2428 * @rtd: PCM runtime data
2429 * @stream: stream name
2430 * @event: stream event
2432 * Sends a stream event to the dapm core. The core then makes any
2433 * necessary widget power changes.
2435 * Returns 0 for success else error.
2437 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
,
2438 const char *stream
, int event
)
2440 struct snd_soc_codec
*codec
= rtd
->codec
;
2445 mutex_lock(&codec
->mutex
);
2446 soc_dapm_stream_event(&codec
->dapm
, stream
, event
);
2447 mutex_unlock(&codec
->mutex
);
2452 * snd_soc_dapm_enable_pin - enable pin.
2453 * @dapm: DAPM context
2456 * Enables input/output pin and its parents or children widgets iff there is
2457 * a valid audio route and active audio stream.
2458 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2459 * do any widget power switching.
2461 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2463 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
2465 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
2468 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2469 * @dapm: DAPM context
2472 * Enables input/output pin regardless of any other state. This is
2473 * intended for use with microphone bias supplies used in microphone
2476 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2477 * do any widget power switching.
2479 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
2482 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2485 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2489 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
2495 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
2498 * snd_soc_dapm_disable_pin - disable pin.
2499 * @dapm: DAPM context
2502 * Disables input/output pin and its parents or children widgets.
2503 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2504 * do any widget power switching.
2506 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
2509 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2511 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
2514 * snd_soc_dapm_nc_pin - permanently disable pin.
2515 * @dapm: DAPM context
2518 * Marks the specified pin as being not connected, disabling it along
2519 * any parent or child widgets. At present this is identical to
2520 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2521 * additional things such as disabling controls which only affect
2522 * paths through the pin.
2524 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2525 * do any widget power switching.
2527 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2529 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2531 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
2534 * snd_soc_dapm_get_pin_status - get audio pin status
2535 * @dapm: DAPM context
2536 * @pin: audio signal pin endpoint (or start point)
2538 * Get audio pin status - connected or disconnected.
2540 * Returns 1 for connected otherwise 0.
2542 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
2545 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2548 return w
->connected
;
2552 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
2555 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2556 * @dapm: DAPM context
2557 * @pin: audio signal pin endpoint (or start point)
2559 * Mark the given endpoint or pin as ignoring suspend. When the
2560 * system is disabled a path between two endpoints flagged as ignoring
2561 * suspend will not be disabled. The path must already be enabled via
2562 * normal means at suspend time, it will not be turned on if it was not
2565 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
2568 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
2571 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2575 w
->ignore_suspend
= 1;
2579 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
2582 * snd_soc_dapm_free - free dapm resources
2585 * Free all dapm widgets and resources.
2587 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
2589 snd_soc_dapm_sys_remove(dapm
->dev
);
2590 dapm_debugfs_cleanup(dapm
);
2591 dapm_free_widgets(dapm
);
2592 list_del(&dapm
->list
);
2594 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
2596 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
2598 struct snd_soc_dapm_widget
*w
;
2599 LIST_HEAD(down_list
);
2602 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2603 if (w
->dapm
!= dapm
)
2606 dapm_seq_insert(w
, &down_list
, false);
2612 /* If there were no widgets to power down we're already in
2616 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_PREPARE
);
2617 dapm_seq_run(dapm
, &down_list
, 0, false);
2618 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_STANDBY
);
2623 * snd_soc_dapm_shutdown - callback for system shutdown
2625 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
2627 struct snd_soc_codec
*codec
;
2629 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
2630 soc_dapm_shutdown_codec(&codec
->dapm
);
2631 snd_soc_dapm_set_bias_level(&codec
->dapm
, SND_SOC_BIAS_OFF
);
2635 /* Module information */
2636 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2637 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2638 MODULE_LICENSE("GPL");