1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
5 // Copyright 2005 Wolfson Microelectronics PLC.
6 // Author: Liam Girdwood <lrg@slimlogic.co.uk>
9 // o Changes power status of internal codec blocks depending on the
10 // dynamic configuration of codec internal audio paths and active
12 // o Platform power domain - can support external components i.e. amps and
13 // mic/headphone insertion events.
14 // o Automatic Mic Bias support
15 // o Jack insertion power event initiation - e.g. hp insertion will enable
17 // o Delayed power down of audio subsystem to reduce pops between a quick
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/async.h>
23 #include <linux/delay.h>
25 #include <linux/bitops.h>
26 #include <linux/platform_device.h>
27 #include <linux/jiffies.h>
28 #include <linux/debugfs.h>
29 #include <linux/pm_runtime.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/pinctrl/consumer.h>
32 #include <linux/clk.h>
33 #include <linux/slab.h>
34 #include <sound/core.h>
35 #include <sound/pcm.h>
36 #include <sound/pcm_params.h>
37 #include <sound/soc.h>
38 #include <sound/initval.h>
40 #include <trace/events/asoc.h>
42 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
44 #define SND_SOC_DAPM_DIR_REVERSE(x) ((x == SND_SOC_DAPM_DIR_IN) ? \
45 SND_SOC_DAPM_DIR_OUT : SND_SOC_DAPM_DIR_IN)
47 #define snd_soc_dapm_for_each_direction(dir) \
48 for ((dir) = SND_SOC_DAPM_DIR_IN; (dir) <= SND_SOC_DAPM_DIR_OUT; \
51 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
52 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
54 int (*connected
)(struct snd_soc_dapm_widget
*source
,
55 struct snd_soc_dapm_widget
*sink
));
57 struct snd_soc_dapm_widget
*
58 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
59 const struct snd_soc_dapm_widget
*widget
);
61 struct snd_soc_dapm_widget
*
62 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context
*dapm
,
63 const struct snd_soc_dapm_widget
*widget
);
65 /* dapm power sequences - make this per codec in the future */
66 static int dapm_up_seq
[] = {
67 [snd_soc_dapm_pre
] = 1,
68 [snd_soc_dapm_regulator_supply
] = 2,
69 [snd_soc_dapm_pinctrl
] = 2,
70 [snd_soc_dapm_clock_supply
] = 2,
71 [snd_soc_dapm_supply
] = 3,
72 [snd_soc_dapm_micbias
] = 4,
73 [snd_soc_dapm_vmid
] = 4,
74 [snd_soc_dapm_dai_link
] = 3,
75 [snd_soc_dapm_dai_in
] = 5,
76 [snd_soc_dapm_dai_out
] = 5,
77 [snd_soc_dapm_aif_in
] = 5,
78 [snd_soc_dapm_aif_out
] = 5,
79 [snd_soc_dapm_mic
] = 6,
80 [snd_soc_dapm_siggen
] = 6,
81 [snd_soc_dapm_input
] = 6,
82 [snd_soc_dapm_output
] = 6,
83 [snd_soc_dapm_mux
] = 7,
84 [snd_soc_dapm_demux
] = 7,
85 [snd_soc_dapm_dac
] = 8,
86 [snd_soc_dapm_switch
] = 9,
87 [snd_soc_dapm_mixer
] = 9,
88 [snd_soc_dapm_mixer_named_ctl
] = 9,
89 [snd_soc_dapm_pga
] = 10,
90 [snd_soc_dapm_buffer
] = 10,
91 [snd_soc_dapm_scheduler
] = 10,
92 [snd_soc_dapm_effect
] = 10,
93 [snd_soc_dapm_src
] = 10,
94 [snd_soc_dapm_asrc
] = 10,
95 [snd_soc_dapm_encoder
] = 10,
96 [snd_soc_dapm_decoder
] = 10,
97 [snd_soc_dapm_adc
] = 11,
98 [snd_soc_dapm_out_drv
] = 12,
99 [snd_soc_dapm_hp
] = 12,
100 [snd_soc_dapm_spk
] = 12,
101 [snd_soc_dapm_line
] = 12,
102 [snd_soc_dapm_sink
] = 12,
103 [snd_soc_dapm_kcontrol
] = 13,
104 [snd_soc_dapm_post
] = 14,
107 static int dapm_down_seq
[] = {
108 [snd_soc_dapm_pre
] = 1,
109 [snd_soc_dapm_kcontrol
] = 2,
110 [snd_soc_dapm_adc
] = 3,
111 [snd_soc_dapm_hp
] = 4,
112 [snd_soc_dapm_spk
] = 4,
113 [snd_soc_dapm_line
] = 4,
114 [snd_soc_dapm_out_drv
] = 4,
115 [snd_soc_dapm_sink
] = 4,
116 [snd_soc_dapm_pga
] = 5,
117 [snd_soc_dapm_buffer
] = 5,
118 [snd_soc_dapm_scheduler
] = 5,
119 [snd_soc_dapm_effect
] = 5,
120 [snd_soc_dapm_src
] = 5,
121 [snd_soc_dapm_asrc
] = 5,
122 [snd_soc_dapm_encoder
] = 5,
123 [snd_soc_dapm_decoder
] = 5,
124 [snd_soc_dapm_switch
] = 6,
125 [snd_soc_dapm_mixer_named_ctl
] = 6,
126 [snd_soc_dapm_mixer
] = 6,
127 [snd_soc_dapm_dac
] = 7,
128 [snd_soc_dapm_mic
] = 8,
129 [snd_soc_dapm_siggen
] = 8,
130 [snd_soc_dapm_input
] = 8,
131 [snd_soc_dapm_output
] = 8,
132 [snd_soc_dapm_micbias
] = 9,
133 [snd_soc_dapm_vmid
] = 9,
134 [snd_soc_dapm_mux
] = 10,
135 [snd_soc_dapm_demux
] = 10,
136 [snd_soc_dapm_aif_in
] = 11,
137 [snd_soc_dapm_aif_out
] = 11,
138 [snd_soc_dapm_dai_in
] = 11,
139 [snd_soc_dapm_dai_out
] = 11,
140 [snd_soc_dapm_dai_link
] = 12,
141 [snd_soc_dapm_supply
] = 13,
142 [snd_soc_dapm_clock_supply
] = 14,
143 [snd_soc_dapm_pinctrl
] = 14,
144 [snd_soc_dapm_regulator_supply
] = 14,
145 [snd_soc_dapm_post
] = 15,
148 static void dapm_assert_locked(struct snd_soc_dapm_context
*dapm
)
150 if (dapm
->card
&& dapm
->card
->instantiated
)
151 lockdep_assert_held(&dapm
->card
->dapm_mutex
);
154 static void pop_wait(u32 pop_time
)
157 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
161 static void pop_dbg(struct device
*dev
, u32 pop_time
, const char *fmt
, ...)
169 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
174 vsnprintf(buf
, PAGE_SIZE
, fmt
, args
);
175 dev_info(dev
, "%s", buf
);
181 static bool dapm_dirty_widget(struct snd_soc_dapm_widget
*w
)
183 return !list_empty(&w
->dirty
);
186 static void dapm_mark_dirty(struct snd_soc_dapm_widget
*w
, const char *reason
)
188 dapm_assert_locked(w
->dapm
);
190 if (!dapm_dirty_widget(w
)) {
191 dev_vdbg(w
->dapm
->dev
, "Marking %s dirty due to %s\n",
193 list_add_tail(&w
->dirty
, &w
->dapm
->card
->dapm_dirty
);
198 * Common implementation for dapm_widget_invalidate_input_paths() and
199 * dapm_widget_invalidate_output_paths(). The function is inlined since the
200 * combined size of the two specialized functions is only marginally larger then
201 * the size of the generic function and at the same time the fast path of the
202 * specialized functions is significantly smaller than the generic function.
204 static __always_inline
void dapm_widget_invalidate_paths(
205 struct snd_soc_dapm_widget
*w
, enum snd_soc_dapm_direction dir
)
207 enum snd_soc_dapm_direction rdir
= SND_SOC_DAPM_DIR_REVERSE(dir
);
208 struct snd_soc_dapm_widget
*node
;
209 struct snd_soc_dapm_path
*p
;
212 dapm_assert_locked(w
->dapm
);
214 if (w
->endpoints
[dir
] == -1)
217 list_add_tail(&w
->work_list
, &list
);
218 w
->endpoints
[dir
] = -1;
220 list_for_each_entry(w
, &list
, work_list
) {
221 snd_soc_dapm_widget_for_each_path(w
, dir
, p
) {
222 if (p
->is_supply
|| p
->weak
|| !p
->connect
)
224 node
= p
->node
[rdir
];
225 if (node
->endpoints
[dir
] != -1) {
226 node
->endpoints
[dir
] = -1;
227 list_add_tail(&node
->work_list
, &list
);
234 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of
236 * @w: The widget for which to invalidate the cached number of input paths
238 * Resets the cached number of inputs for the specified widget and all widgets
239 * that can be reached via outcoming paths from the widget.
241 * This function must be called if the number of output paths for a widget might
242 * have changed. E.g. if the source state of a widget changes or a path is added
243 * or activated with the widget as the sink.
245 static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget
*w
)
247 dapm_widget_invalidate_paths(w
, SND_SOC_DAPM_DIR_IN
);
251 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of
253 * @w: The widget for which to invalidate the cached number of output paths
255 * Resets the cached number of outputs for the specified widget and all widgets
256 * that can be reached via incoming paths from the widget.
258 * This function must be called if the number of output paths for a widget might
259 * have changed. E.g. if the sink state of a widget changes or a path is added
260 * or activated with the widget as the source.
262 static void dapm_widget_invalidate_output_paths(struct snd_soc_dapm_widget
*w
)
264 dapm_widget_invalidate_paths(w
, SND_SOC_DAPM_DIR_OUT
);
268 * dapm_path_invalidate() - Invalidates the cached number of inputs and outputs
269 * for the widgets connected to a path
270 * @p: The path to invalidate
272 * Resets the cached number of inputs for the sink of the path and the cached
273 * number of outputs for the source of the path.
275 * This function must be called when a path is added, removed or the connected
278 static void dapm_path_invalidate(struct snd_soc_dapm_path
*p
)
281 * Weak paths or supply paths do not influence the number of input or
282 * output paths of their neighbors.
284 if (p
->weak
|| p
->is_supply
)
288 * The number of connected endpoints is the sum of the number of
289 * connected endpoints of all neighbors. If a node with 0 connected
290 * endpoints is either connected or disconnected that sum won't change,
291 * so there is no need to re-check the path.
293 if (p
->source
->endpoints
[SND_SOC_DAPM_DIR_IN
] != 0)
294 dapm_widget_invalidate_input_paths(p
->sink
);
295 if (p
->sink
->endpoints
[SND_SOC_DAPM_DIR_OUT
] != 0)
296 dapm_widget_invalidate_output_paths(p
->source
);
299 void dapm_mark_endpoints_dirty(struct snd_soc_card
*card
)
301 struct snd_soc_dapm_widget
*w
;
303 mutex_lock(&card
->dapm_mutex
);
305 list_for_each_entry(w
, &card
->widgets
, list
) {
307 dapm_mark_dirty(w
, "Rechecking endpoints");
308 if (w
->is_ep
& SND_SOC_DAPM_EP_SINK
)
309 dapm_widget_invalidate_output_paths(w
);
310 if (w
->is_ep
& SND_SOC_DAPM_EP_SOURCE
)
311 dapm_widget_invalidate_input_paths(w
);
315 mutex_unlock(&card
->dapm_mutex
);
317 EXPORT_SYMBOL_GPL(dapm_mark_endpoints_dirty
);
319 /* create a new dapm widget */
320 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
321 const struct snd_soc_dapm_widget
*_widget
)
323 struct snd_soc_dapm_widget
*w
;
325 w
= kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
330 * w->name is duplicated in caller, but w->sname isn't.
331 * Duplicate it here if defined
333 if (_widget
->sname
) {
334 w
->sname
= kstrdup_const(_widget
->sname
, GFP_KERNEL
);
343 struct dapm_kcontrol_data
{
345 struct snd_soc_dapm_widget
*widget
;
346 struct list_head paths
;
347 struct snd_soc_dapm_widget_list
*wlist
;
350 static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget
*widget
,
351 struct snd_kcontrol
*kcontrol
, const char *ctrl_name
)
353 struct dapm_kcontrol_data
*data
;
354 struct soc_mixer_control
*mc
;
359 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
363 INIT_LIST_HEAD(&data
->paths
);
365 switch (widget
->id
) {
366 case snd_soc_dapm_switch
:
367 case snd_soc_dapm_mixer
:
368 case snd_soc_dapm_mixer_named_ctl
:
369 mc
= (struct soc_mixer_control
*)kcontrol
->private_value
;
371 if (mc
->autodisable
&& snd_soc_volsw_is_stereo(mc
))
372 dev_warn(widget
->dapm
->dev
,
373 "ASoC: Unsupported stereo autodisable control '%s'\n",
376 if (mc
->autodisable
) {
377 struct snd_soc_dapm_widget
template;
379 name
= kasprintf(GFP_KERNEL
, "%s %s", ctrl_name
,
386 memset(&template, 0, sizeof(template));
387 template.reg
= mc
->reg
;
388 template.mask
= (1 << fls(mc
->max
)) - 1;
389 template.shift
= mc
->shift
;
391 template.off_val
= mc
->max
;
393 template.off_val
= 0;
394 template.on_val
= template.off_val
;
395 template.id
= snd_soc_dapm_kcontrol
;
396 template.name
= name
;
398 data
->value
= template.on_val
;
401 snd_soc_dapm_new_control_unlocked(widget
->dapm
,
404 if (IS_ERR(data
->widget
)) {
405 ret
= PTR_ERR(data
->widget
);
410 case snd_soc_dapm_demux
:
411 case snd_soc_dapm_mux
:
412 e
= (struct soc_enum
*)kcontrol
->private_value
;
414 if (e
->autodisable
) {
415 struct snd_soc_dapm_widget
template;
417 name
= kasprintf(GFP_KERNEL
, "%s %s", ctrl_name
,
424 memset(&template, 0, sizeof(template));
425 template.reg
= e
->reg
;
426 template.mask
= e
->mask
<< e
->shift_l
;
427 template.shift
= e
->shift_l
;
428 template.off_val
= snd_soc_enum_item_to_val(e
, 0);
429 template.on_val
= template.off_val
;
430 template.id
= snd_soc_dapm_kcontrol
;
431 template.name
= name
;
433 data
->value
= template.on_val
;
435 data
->widget
= snd_soc_dapm_new_control_unlocked(
436 widget
->dapm
, &template);
438 if (IS_ERR(data
->widget
)) {
439 ret
= PTR_ERR(data
->widget
);
443 snd_soc_dapm_add_path(widget
->dapm
, data
->widget
,
451 kcontrol
->private_data
= data
;
460 static void dapm_kcontrol_free(struct snd_kcontrol
*kctl
)
462 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kctl
);
464 list_del(&data
->paths
);
469 static struct snd_soc_dapm_widget_list
*dapm_kcontrol_get_wlist(
470 const struct snd_kcontrol
*kcontrol
)
472 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
477 static int dapm_kcontrol_add_widget(struct snd_kcontrol
*kcontrol
,
478 struct snd_soc_dapm_widget
*widget
)
480 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
481 struct snd_soc_dapm_widget_list
*new_wlist
;
485 n
= data
->wlist
->num_widgets
+ 1;
489 new_wlist
= krealloc(data
->wlist
,
490 struct_size(new_wlist
, widgets
, n
),
495 new_wlist
->widgets
[n
- 1] = widget
;
496 new_wlist
->num_widgets
= n
;
498 data
->wlist
= new_wlist
;
503 static void dapm_kcontrol_add_path(const struct snd_kcontrol
*kcontrol
,
504 struct snd_soc_dapm_path
*path
)
506 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
508 list_add_tail(&path
->list_kcontrol
, &data
->paths
);
511 static bool dapm_kcontrol_is_powered(const struct snd_kcontrol
*kcontrol
)
513 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
518 return data
->widget
->power
;
521 static struct list_head
*dapm_kcontrol_get_path_list(
522 const struct snd_kcontrol
*kcontrol
)
524 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
529 #define dapm_kcontrol_for_each_path(path, kcontrol) \
530 list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \
533 unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol
*kcontrol
)
535 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
539 EXPORT_SYMBOL_GPL(dapm_kcontrol_get_value
);
541 static bool dapm_kcontrol_set_value(const struct snd_kcontrol
*kcontrol
,
544 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
546 if (data
->value
== value
)
550 data
->widget
->on_val
= value
;
558 * snd_soc_dapm_kcontrol_widget() - Returns the widget associated to a
560 * @kcontrol: The kcontrol
562 struct snd_soc_dapm_widget
*snd_soc_dapm_kcontrol_widget(
563 struct snd_kcontrol
*kcontrol
)
565 return dapm_kcontrol_get_wlist(kcontrol
)->widgets
[0];
567 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_widget
);
570 * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a
572 * @kcontrol: The kcontrol
574 * Note: This function must only be used on kcontrols that are known to have
575 * been registered for a CODEC. Otherwise the behaviour is undefined.
577 struct snd_soc_dapm_context
*snd_soc_dapm_kcontrol_dapm(
578 struct snd_kcontrol
*kcontrol
)
580 return dapm_kcontrol_get_wlist(kcontrol
)->widgets
[0]->dapm
;
582 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm
);
584 static void dapm_reset(struct snd_soc_card
*card
)
586 struct snd_soc_dapm_widget
*w
;
588 lockdep_assert_held(&card
->dapm_mutex
);
590 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
592 list_for_each_entry(w
, &card
->widgets
, list
) {
593 w
->new_power
= w
->power
;
594 w
->power_checked
= false;
598 static const char *soc_dapm_prefix(struct snd_soc_dapm_context
*dapm
)
600 if (!dapm
->component
)
602 return dapm
->component
->name_prefix
;
605 static int soc_dapm_read(struct snd_soc_dapm_context
*dapm
, int reg
,
608 if (!dapm
->component
)
610 return snd_soc_component_read(dapm
->component
, reg
, value
);
613 static int soc_dapm_update_bits(struct snd_soc_dapm_context
*dapm
,
614 int reg
, unsigned int mask
, unsigned int value
)
616 if (!dapm
->component
)
618 return snd_soc_component_update_bits(dapm
->component
, reg
,
622 static int soc_dapm_test_bits(struct snd_soc_dapm_context
*dapm
,
623 int reg
, unsigned int mask
, unsigned int value
)
625 if (!dapm
->component
)
627 return snd_soc_component_test_bits(dapm
->component
, reg
, mask
, value
);
630 static void soc_dapm_async_complete(struct snd_soc_dapm_context
*dapm
)
633 snd_soc_component_async_complete(dapm
->component
);
636 static struct snd_soc_dapm_widget
*
637 dapm_wcache_lookup(struct snd_soc_dapm_wcache
*wcache
, const char *name
)
639 struct snd_soc_dapm_widget
*w
= wcache
->widget
;
640 struct list_head
*wlist
;
645 wlist
= &w
->dapm
->card
->widgets
;
647 list_for_each_entry_from(w
, wlist
, list
) {
648 if (!strcmp(name
, w
->name
))
659 static inline void dapm_wcache_update(struct snd_soc_dapm_wcache
*wcache
,
660 struct snd_soc_dapm_widget
*w
)
666 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
667 * @dapm: The DAPM context for which to set the level
668 * @level: The level to set
670 * Forces the DAPM bias level to a specific state. It will call the bias level
671 * callback of DAPM context with the specified level. This will even happen if
672 * the context is already at the same level. Furthermore it will not go through
673 * the normal bias level sequencing, meaning any intermediate states between the
674 * current and the target state will not be entered.
676 * Note that the change in bias level is only temporary and the next time
677 * snd_soc_dapm_sync() is called the state will be set to the level as
678 * determined by the DAPM core. The function is mainly intended to be used to
679 * used during probe or resume from suspend to power up the device so
680 * initialization can be done, before the DAPM core takes over.
682 int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context
*dapm
,
683 enum snd_soc_bias_level level
)
687 if (dapm
->set_bias_level
)
688 ret
= dapm
->set_bias_level(dapm
, level
);
691 dapm
->bias_level
= level
;
695 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_bias_level
);
698 * snd_soc_dapm_set_bias_level - set the bias level for the system
699 * @dapm: DAPM context
700 * @level: level to configure
702 * Configure the bias (power) levels for the SoC audio device.
704 * Returns 0 for success else error.
706 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
707 enum snd_soc_bias_level level
)
709 struct snd_soc_card
*card
= dapm
->card
;
712 trace_snd_soc_bias_level_start(card
, level
);
714 if (card
&& card
->set_bias_level
)
715 ret
= card
->set_bias_level(card
, dapm
, level
);
719 if (!card
|| dapm
!= &card
->dapm
)
720 ret
= snd_soc_dapm_force_bias_level(dapm
, level
);
725 if (card
&& card
->set_bias_level_post
)
726 ret
= card
->set_bias_level_post(card
, dapm
, level
);
728 trace_snd_soc_bias_level_done(card
, level
);
733 /* connect mux widget to its interconnecting audio paths */
734 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
735 struct snd_soc_dapm_path
*path
, const char *control_name
,
736 struct snd_soc_dapm_widget
*w
)
738 const struct snd_kcontrol_new
*kcontrol
= &w
->kcontrol_news
[0];
739 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
740 unsigned int val
, item
;
743 if (e
->reg
!= SND_SOC_NOPM
) {
744 soc_dapm_read(dapm
, e
->reg
, &val
);
745 val
= (val
>> e
->shift_l
) & e
->mask
;
746 item
= snd_soc_enum_val_to_item(e
, val
);
748 /* since a virtual mux has no backing registers to
749 * decide which path to connect, it will try to match
750 * with the first enumeration. This is to ensure
751 * that the default mux choice (the first) will be
752 * correctly powered up during initialization.
757 i
= match_string(e
->texts
, e
->items
, control_name
);
761 path
->name
= e
->texts
[i
];
762 path
->connect
= (i
== item
);
767 /* set up initial codec paths */
768 static void dapm_set_mixer_path_status(struct snd_soc_dapm_path
*p
, int i
,
771 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
772 p
->sink
->kcontrol_news
[i
].private_value
;
773 unsigned int reg
= mc
->reg
;
774 unsigned int shift
= mc
->shift
;
775 unsigned int max
= mc
->max
;
776 unsigned int mask
= (1 << fls(max
)) - 1;
777 unsigned int invert
= mc
->invert
;
780 if (reg
!= SND_SOC_NOPM
) {
781 soc_dapm_read(p
->sink
->dapm
, reg
, &val
);
783 * The nth_path argument allows this function to know
784 * which path of a kcontrol it is setting the initial
785 * status for. Ideally this would support any number
786 * of paths and channels. But since kcontrols only come
787 * in mono and stereo variants, we are limited to 2
790 * The following code assumes for stereo controls the
791 * first path is the left channel, and all remaining
792 * paths are the right channel.
794 if (snd_soc_volsw_is_stereo(mc
) && nth_path
> 0) {
796 soc_dapm_read(p
->sink
->dapm
, mc
->rreg
, &val
);
797 val
= (val
>> mc
->rshift
) & mask
;
799 val
= (val
>> shift
) & mask
;
809 /* connect mixer widget to its interconnecting audio paths */
810 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
811 struct snd_soc_dapm_path
*path
, const char *control_name
)
815 /* search for mixer kcontrol */
816 for (i
= 0; i
< path
->sink
->num_kcontrols
; i
++) {
817 if (!strcmp(control_name
, path
->sink
->kcontrol_news
[i
].name
)) {
818 path
->name
= path
->sink
->kcontrol_news
[i
].name
;
819 dapm_set_mixer_path_status(path
, i
, nth_path
++);
826 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
827 struct snd_soc_dapm_widget
*kcontrolw
,
828 const struct snd_kcontrol_new
*kcontrol_new
,
829 struct snd_kcontrol
**kcontrol
)
831 struct snd_soc_dapm_widget
*w
;
836 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
837 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
839 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
840 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
842 *kcontrol
= w
->kcontrols
[i
];
852 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
853 * create it. Either way, add the widget into the control's widget list
855 static int dapm_create_or_share_kcontrol(struct snd_soc_dapm_widget
*w
,
858 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
859 struct snd_card
*card
= dapm
->card
->snd_card
;
863 struct snd_kcontrol
*kcontrol
;
864 bool wname_in_long_name
, kcname_in_long_name
;
865 char *long_name
= NULL
;
869 prefix
= soc_dapm_prefix(dapm
);
871 prefix_len
= strlen(prefix
) + 1;
875 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[kci
],
880 wname_in_long_name
= false;
881 kcname_in_long_name
= true;
884 case snd_soc_dapm_switch
:
885 case snd_soc_dapm_mixer
:
886 case snd_soc_dapm_pga
:
887 case snd_soc_dapm_effect
:
888 case snd_soc_dapm_out_drv
:
889 wname_in_long_name
= true;
890 kcname_in_long_name
= true;
892 case snd_soc_dapm_mixer_named_ctl
:
893 wname_in_long_name
= false;
894 kcname_in_long_name
= true;
896 case snd_soc_dapm_demux
:
897 case snd_soc_dapm_mux
:
898 wname_in_long_name
= true;
899 kcname_in_long_name
= false;
906 if (wname_in_long_name
&& kcname_in_long_name
) {
908 * The control will get a prefix from the control
909 * creation process but we're also using the same
910 * prefix for widgets so cut the prefix off the
911 * front of the widget name.
913 long_name
= kasprintf(GFP_KERNEL
, "%s %s",
914 w
->name
+ prefix_len
,
915 w
->kcontrol_news
[kci
].name
);
916 if (long_name
== NULL
)
920 } else if (wname_in_long_name
) {
922 name
= w
->name
+ prefix_len
;
925 name
= w
->kcontrol_news
[kci
].name
;
928 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[kci
], NULL
, name
,
935 kcontrol
->private_free
= dapm_kcontrol_free
;
937 ret
= dapm_kcontrol_data_alloc(w
, kcontrol
, name
);
939 snd_ctl_free_one(kcontrol
);
943 ret
= snd_ctl_add(card
, kcontrol
);
946 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
952 ret
= dapm_kcontrol_add_widget(kcontrol
, w
);
954 w
->kcontrols
[kci
] = kcontrol
;
962 /* create new dapm mixer control */
963 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
966 struct snd_soc_dapm_path
*path
;
967 struct dapm_kcontrol_data
*data
;
970 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
972 snd_soc_dapm_widget_for_each_source_path(w
, path
) {
973 /* mixer/mux paths name must match control name */
974 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
977 if (!w
->kcontrols
[i
]) {
978 ret
= dapm_create_or_share_kcontrol(w
, i
);
983 dapm_kcontrol_add_path(w
->kcontrols
[i
], path
);
985 data
= snd_kcontrol_chip(w
->kcontrols
[i
]);
987 snd_soc_dapm_add_path(data
->widget
->dapm
,
997 /* create new dapm mux control */
998 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
1000 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1001 enum snd_soc_dapm_direction dir
;
1002 struct snd_soc_dapm_path
*path
;
1007 case snd_soc_dapm_mux
:
1008 dir
= SND_SOC_DAPM_DIR_OUT
;
1011 case snd_soc_dapm_demux
:
1012 dir
= SND_SOC_DAPM_DIR_IN
;
1019 if (w
->num_kcontrols
!= 1) {
1021 "ASoC: %s %s has incorrect number of controls\n", type
,
1026 if (list_empty(&w
->edges
[dir
])) {
1027 dev_err(dapm
->dev
, "ASoC: %s %s has no paths\n", type
, w
->name
);
1031 ret
= dapm_create_or_share_kcontrol(w
, 0);
1035 snd_soc_dapm_widget_for_each_path(w
, dir
, path
) {
1037 dapm_kcontrol_add_path(w
->kcontrols
[0], path
);
1043 /* create new dapm volume control */
1044 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
1048 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
1049 ret
= dapm_create_or_share_kcontrol(w
, i
);
1057 /* create new dapm dai link control */
1058 static int dapm_new_dai_link(struct snd_soc_dapm_widget
*w
)
1061 struct snd_kcontrol
*kcontrol
;
1062 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1063 struct snd_card
*card
= dapm
->card
->snd_card
;
1064 struct snd_soc_pcm_runtime
*rtd
= w
->priv
;
1066 /* create control for links with > 1 config */
1067 if (rtd
->dai_link
->num_params
<= 1)
1071 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
1072 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
], w
,
1074 ret
= snd_ctl_add(card
, kcontrol
);
1077 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
1078 w
->name
, w
->kcontrol_news
[i
].name
, ret
);
1081 kcontrol
->private_data
= w
;
1082 w
->kcontrols
[i
] = kcontrol
;
1088 /* We implement power down on suspend by checking the power state of
1089 * the ALSA card - when we are suspending the ALSA state for the card
1092 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
1094 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
1097 case SNDRV_CTL_POWER_D3hot
:
1098 case SNDRV_CTL_POWER_D3cold
:
1099 if (widget
->ignore_suspend
)
1100 dev_dbg(widget
->dapm
->dev
, "ASoC: %s ignoring suspend\n",
1102 return widget
->ignore_suspend
;
1108 static int dapm_widget_list_create(struct snd_soc_dapm_widget_list
**list
,
1109 struct list_head
*widgets
)
1111 struct snd_soc_dapm_widget
*w
;
1112 struct list_head
*it
;
1113 unsigned int size
= 0;
1116 list_for_each(it
, widgets
)
1119 *list
= kzalloc(struct_size(*list
, widgets
, size
), GFP_KERNEL
);
1123 list_for_each_entry(w
, widgets
, work_list
)
1124 (*list
)->widgets
[i
++] = w
;
1126 (*list
)->num_widgets
= i
;
1132 * Common implementation for is_connected_output_ep() and
1133 * is_connected_input_ep(). The function is inlined since the combined size of
1134 * the two specialized functions is only marginally larger then the size of the
1135 * generic function and at the same time the fast path of the specialized
1136 * functions is significantly smaller than the generic function.
1138 static __always_inline
int is_connected_ep(struct snd_soc_dapm_widget
*widget
,
1139 struct list_head
*list
, enum snd_soc_dapm_direction dir
,
1140 int (*fn
)(struct snd_soc_dapm_widget
*, struct list_head
*,
1141 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*,
1142 enum snd_soc_dapm_direction
)),
1143 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*,
1144 enum snd_soc_dapm_direction
))
1146 enum snd_soc_dapm_direction rdir
= SND_SOC_DAPM_DIR_REVERSE(dir
);
1147 struct snd_soc_dapm_path
*path
;
1150 if (widget
->endpoints
[dir
] >= 0)
1151 return widget
->endpoints
[dir
];
1153 DAPM_UPDATE_STAT(widget
, path_checks
);
1155 /* do we need to add this widget to the list ? */
1157 list_add_tail(&widget
->work_list
, list
);
1159 if (custom_stop_condition
&& custom_stop_condition(widget
, dir
)) {
1161 custom_stop_condition
= NULL
;
1164 if ((widget
->is_ep
& SND_SOC_DAPM_DIR_TO_EP(dir
)) && widget
->connected
) {
1165 widget
->endpoints
[dir
] = snd_soc_dapm_suspend_check(widget
);
1166 return widget
->endpoints
[dir
];
1169 snd_soc_dapm_widget_for_each_path(widget
, rdir
, path
) {
1170 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1172 if (path
->weak
|| path
->is_supply
)
1178 trace_snd_soc_dapm_path(widget
, dir
, path
);
1180 if (path
->connect
) {
1182 con
+= fn(path
->node
[dir
], list
, custom_stop_condition
);
1187 widget
->endpoints
[dir
] = con
;
1193 * Recursively check for a completed path to an active or physically connected
1194 * output widget. Returns number of complete paths.
1196 * Optionally, can be supplied with a function acting as a stopping condition.
1197 * This function takes the dapm widget currently being examined and the walk
1198 * direction as an arguments, it should return true if widgets from that point
1199 * in the graph onwards should not be added to the widget list.
1201 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
1202 struct list_head
*list
,
1203 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*i
,
1204 enum snd_soc_dapm_direction
))
1206 return is_connected_ep(widget
, list
, SND_SOC_DAPM_DIR_OUT
,
1207 is_connected_output_ep
, custom_stop_condition
);
1211 * Recursively check for a completed path to an active or physically connected
1212 * input widget. Returns number of complete paths.
1214 * Optionally, can be supplied with a function acting as a stopping condition.
1215 * This function takes the dapm widget currently being examined and the walk
1216 * direction as an arguments, it should return true if the walk should be
1217 * stopped and false otherwise.
1219 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
1220 struct list_head
*list
,
1221 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*i
,
1222 enum snd_soc_dapm_direction
))
1224 return is_connected_ep(widget
, list
, SND_SOC_DAPM_DIR_IN
,
1225 is_connected_input_ep
, custom_stop_condition
);
1229 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1230 * @dai: the soc DAI.
1231 * @stream: stream direction.
1232 * @list: list of active widgets for this stream.
1233 * @custom_stop_condition: (optional) a function meant to stop the widget graph
1234 * walk based on custom logic.
1236 * Queries DAPM graph as to whether a valid audio stream path exists for
1237 * the initial stream specified by name. This takes into account
1238 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1240 * Optionally, can be supplied with a function acting as a stopping condition.
1241 * This function takes the dapm widget currently being examined and the walk
1242 * direction as an arguments, it should return true if the walk should be
1243 * stopped and false otherwise.
1245 * Returns the number of valid paths or negative error.
1247 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1248 struct snd_soc_dapm_widget_list
**list
,
1249 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*,
1250 enum snd_soc_dapm_direction
))
1252 struct snd_soc_card
*card
= dai
->component
->card
;
1253 struct snd_soc_dapm_widget
*w
;
1258 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1261 * For is_connected_{output,input}_ep fully discover the graph we need
1262 * to reset the cached number of inputs and outputs.
1264 list_for_each_entry(w
, &card
->widgets
, list
) {
1265 w
->endpoints
[SND_SOC_DAPM_DIR_IN
] = -1;
1266 w
->endpoints
[SND_SOC_DAPM_DIR_OUT
] = -1;
1269 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1270 paths
= is_connected_output_ep(dai
->playback_widget
, &widgets
,
1271 custom_stop_condition
);
1273 paths
= is_connected_input_ep(dai
->capture_widget
, &widgets
,
1274 custom_stop_condition
);
1276 /* Drop starting point */
1277 list_del(widgets
.next
);
1279 ret
= dapm_widget_list_create(list
, &widgets
);
1283 trace_snd_soc_dapm_connected(paths
, stream
);
1284 mutex_unlock(&card
->dapm_mutex
);
1290 * Handler for regulator supply widget.
1292 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1293 struct snd_kcontrol
*kcontrol
, int event
)
1297 soc_dapm_async_complete(w
->dapm
);
1299 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1300 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1301 ret
= regulator_allow_bypass(w
->regulator
, false);
1303 dev_warn(w
->dapm
->dev
,
1304 "ASoC: Failed to unbypass %s: %d\n",
1308 return regulator_enable(w
->regulator
);
1310 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1311 ret
= regulator_allow_bypass(w
->regulator
, true);
1313 dev_warn(w
->dapm
->dev
,
1314 "ASoC: Failed to bypass %s: %d\n",
1318 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1321 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1324 * Handler for pinctrl widget.
1326 int dapm_pinctrl_event(struct snd_soc_dapm_widget
*w
,
1327 struct snd_kcontrol
*kcontrol
, int event
)
1329 struct snd_soc_dapm_pinctrl_priv
*priv
= w
->priv
;
1330 struct pinctrl
*p
= w
->pinctrl
;
1331 struct pinctrl_state
*s
;
1336 if (SND_SOC_DAPM_EVENT_ON(event
))
1337 s
= pinctrl_lookup_state(p
, priv
->active_state
);
1339 s
= pinctrl_lookup_state(p
, priv
->sleep_state
);
1344 return pinctrl_select_state(p
, s
);
1346 EXPORT_SYMBOL_GPL(dapm_pinctrl_event
);
1349 * Handler for clock supply widget.
1351 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1352 struct snd_kcontrol
*kcontrol
, int event
)
1357 soc_dapm_async_complete(w
->dapm
);
1359 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1360 return clk_prepare_enable(w
->clk
);
1362 clk_disable_unprepare(w
->clk
);
1368 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1370 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1372 if (w
->power_checked
)
1373 return w
->new_power
;
1378 w
->new_power
= w
->power_check(w
);
1380 w
->power_checked
= true;
1382 return w
->new_power
;
1385 /* Generic check to see if a widget should be powered. */
1386 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1390 DAPM_UPDATE_STAT(w
, power_checks
);
1392 in
= is_connected_input_ep(w
, NULL
, NULL
);
1393 out
= is_connected_output_ep(w
, NULL
, NULL
);
1394 return out
!= 0 && in
!= 0;
1397 /* Check to see if a power supply is needed */
1398 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1400 struct snd_soc_dapm_path
*path
;
1402 DAPM_UPDATE_STAT(w
, power_checks
);
1404 /* Check if one of our outputs is connected */
1405 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
1406 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1411 if (path
->connected
&&
1412 !path
->connected(path
->source
, path
->sink
))
1415 if (dapm_widget_power_check(path
->sink
))
1422 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1424 return w
->connected
;
1427 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1428 struct snd_soc_dapm_widget
*b
,
1433 BUILD_BUG_ON(ARRAY_SIZE(dapm_up_seq
) != SND_SOC_DAPM_TYPE_COUNT
);
1434 BUILD_BUG_ON(ARRAY_SIZE(dapm_down_seq
) != SND_SOC_DAPM_TYPE_COUNT
);
1439 sort
= dapm_down_seq
;
1441 WARN_ONCE(sort
[a
->id
] == 0, "offset a->id %d not initialized\n", a
->id
);
1442 WARN_ONCE(sort
[b
->id
] == 0, "offset b->id %d not initialized\n", b
->id
);
1444 if (sort
[a
->id
] != sort
[b
->id
])
1445 return sort
[a
->id
] - sort
[b
->id
];
1446 if (a
->subseq
!= b
->subseq
) {
1448 return a
->subseq
- b
->subseq
;
1450 return b
->subseq
- a
->subseq
;
1452 if (a
->reg
!= b
->reg
)
1453 return a
->reg
- b
->reg
;
1454 if (a
->dapm
!= b
->dapm
)
1455 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1460 /* Insert a widget in order into a DAPM power sequence. */
1461 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1462 struct list_head
*list
,
1465 struct snd_soc_dapm_widget
*w
;
1467 list_for_each_entry(w
, list
, power_list
)
1468 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1469 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1473 list_add_tail(&new_widget
->power_list
, list
);
1476 static void dapm_seq_check_event(struct snd_soc_card
*card
,
1477 struct snd_soc_dapm_widget
*w
, int event
)
1479 const char *ev_name
;
1483 case SND_SOC_DAPM_PRE_PMU
:
1484 ev_name
= "PRE_PMU";
1487 case SND_SOC_DAPM_POST_PMU
:
1488 ev_name
= "POST_PMU";
1491 case SND_SOC_DAPM_PRE_PMD
:
1492 ev_name
= "PRE_PMD";
1495 case SND_SOC_DAPM_POST_PMD
:
1496 ev_name
= "POST_PMD";
1499 case SND_SOC_DAPM_WILL_PMU
:
1500 ev_name
= "WILL_PMU";
1503 case SND_SOC_DAPM_WILL_PMD
:
1504 ev_name
= "WILL_PMD";
1508 WARN(1, "Unknown event %d\n", event
);
1512 if (w
->new_power
!= power
)
1515 if (w
->event
&& (w
->event_flags
& event
)) {
1516 pop_dbg(w
->dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1518 soc_dapm_async_complete(w
->dapm
);
1519 trace_snd_soc_dapm_widget_event_start(w
, event
);
1520 ret
= w
->event(w
, NULL
, event
);
1521 trace_snd_soc_dapm_widget_event_done(w
, event
);
1523 dev_err(w
->dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1524 ev_name
, w
->name
, ret
);
1528 /* Apply the coalesced changes from a DAPM sequence */
1529 static void dapm_seq_run_coalesced(struct snd_soc_card
*card
,
1530 struct list_head
*pending
)
1532 struct snd_soc_dapm_context
*dapm
;
1533 struct snd_soc_dapm_widget
*w
;
1535 unsigned int value
= 0;
1536 unsigned int mask
= 0;
1538 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
, power_list
);
1542 list_for_each_entry(w
, pending
, power_list
) {
1543 WARN_ON(reg
!= w
->reg
|| dapm
!= w
->dapm
);
1544 w
->power
= w
->new_power
;
1546 mask
|= w
->mask
<< w
->shift
;
1548 value
|= w
->on_val
<< w
->shift
;
1550 value
|= w
->off_val
<< w
->shift
;
1552 pop_dbg(dapm
->dev
, card
->pop_time
,
1553 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1554 w
->name
, reg
, value
, mask
);
1556 /* Check for events */
1557 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMU
);
1558 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMD
);
1562 /* Any widget will do, they should all be updating the
1566 pop_dbg(dapm
->dev
, card
->pop_time
,
1567 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1568 value
, mask
, reg
, card
->pop_time
);
1569 pop_wait(card
->pop_time
);
1570 soc_dapm_update_bits(dapm
, reg
, mask
, value
);
1573 list_for_each_entry(w
, pending
, power_list
) {
1574 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMU
);
1575 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMD
);
1579 /* Apply a DAPM power sequence.
1581 * We walk over a pre-sorted list of widgets to apply power to. In
1582 * order to minimise the number of writes to the device required
1583 * multiple widgets will be updated in a single write where possible.
1584 * Currently anything that requires more than a single write is not
1587 static void dapm_seq_run(struct snd_soc_card
*card
,
1588 struct list_head
*list
, int event
, bool power_up
)
1590 struct snd_soc_dapm_widget
*w
, *n
;
1591 struct snd_soc_dapm_context
*d
;
1594 int cur_subseq
= -1;
1595 int cur_reg
= SND_SOC_NOPM
;
1596 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1603 sort
= dapm_down_seq
;
1605 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1608 /* Do we need to apply any queued changes? */
1609 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1610 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1611 if (!list_empty(&pending
))
1612 dapm_seq_run_coalesced(card
, &pending
);
1614 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1615 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1616 if (sort
[i
] == cur_sort
)
1617 cur_dapm
->seq_notifier(cur_dapm
,
1622 if (cur_dapm
&& w
->dapm
!= cur_dapm
)
1623 soc_dapm_async_complete(cur_dapm
);
1625 INIT_LIST_HEAD(&pending
);
1627 cur_subseq
= INT_MIN
;
1628 cur_reg
= SND_SOC_NOPM
;
1633 case snd_soc_dapm_pre
:
1635 list_for_each_entry_safe_continue(w
, n
, list
,
1638 if (event
== SND_SOC_DAPM_STREAM_START
)
1640 NULL
, SND_SOC_DAPM_PRE_PMU
);
1641 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1643 NULL
, SND_SOC_DAPM_PRE_PMD
);
1646 case snd_soc_dapm_post
:
1648 list_for_each_entry_safe_continue(w
, n
, list
,
1651 if (event
== SND_SOC_DAPM_STREAM_START
)
1653 NULL
, SND_SOC_DAPM_POST_PMU
);
1654 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1656 NULL
, SND_SOC_DAPM_POST_PMD
);
1660 /* Queue it up for application */
1661 cur_sort
= sort
[w
->id
];
1662 cur_subseq
= w
->subseq
;
1665 list_move(&w
->power_list
, &pending
);
1670 dev_err(w
->dapm
->dev
,
1671 "ASoC: Failed to apply widget power: %d\n", ret
);
1674 if (!list_empty(&pending
))
1675 dapm_seq_run_coalesced(card
, &pending
);
1677 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1678 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1679 if (sort
[i
] == cur_sort
)
1680 cur_dapm
->seq_notifier(cur_dapm
,
1684 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1685 soc_dapm_async_complete(d
);
1689 static void dapm_widget_update(struct snd_soc_card
*card
)
1691 struct snd_soc_dapm_update
*update
= card
->update
;
1692 struct snd_soc_dapm_widget_list
*wlist
;
1693 struct snd_soc_dapm_widget
*w
= NULL
;
1697 if (!update
|| !dapm_kcontrol_is_powered(update
->kcontrol
))
1700 wlist
= dapm_kcontrol_get_wlist(update
->kcontrol
);
1702 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1703 w
= wlist
->widgets
[wi
];
1705 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1706 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1708 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1716 ret
= soc_dapm_update_bits(w
->dapm
, update
->reg
, update
->mask
,
1719 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1722 if (update
->has_second_set
) {
1723 ret
= soc_dapm_update_bits(w
->dapm
, update
->reg2
,
1724 update
->mask2
, update
->val2
);
1726 dev_err(w
->dapm
->dev
,
1727 "ASoC: %s DAPM update failed: %d\n",
1731 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1732 w
= wlist
->widgets
[wi
];
1734 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1735 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1737 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1743 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1744 * they're changing state.
1746 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1748 struct snd_soc_dapm_context
*d
= data
;
1751 /* If we're off and we're not supposed to go into STANDBY */
1752 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1753 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1755 pm_runtime_get_sync(d
->dev
);
1757 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1760 "ASoC: Failed to turn on bias: %d\n", ret
);
1763 /* Prepare for a transition to ON or away from ON */
1764 if ((d
->target_bias_level
== SND_SOC_BIAS_ON
&&
1765 d
->bias_level
!= SND_SOC_BIAS_ON
) ||
1766 (d
->target_bias_level
!= SND_SOC_BIAS_ON
&&
1767 d
->bias_level
== SND_SOC_BIAS_ON
)) {
1768 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1771 "ASoC: Failed to prepare bias: %d\n", ret
);
1775 /* Async callback run prior to DAPM sequences - brings to their final
1778 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1780 struct snd_soc_dapm_context
*d
= data
;
1783 /* If we just powered the last thing off drop to standby bias */
1784 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1785 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1786 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1787 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1789 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1793 /* If we're in standby and can support bias off then do that */
1794 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1795 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1796 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1798 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1802 pm_runtime_put(d
->dev
);
1805 /* If we just powered up then move to active bias */
1806 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1807 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1808 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1810 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1815 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1816 bool power
, bool connect
)
1818 /* If a connection is being made or broken then that update
1819 * will have marked the peer dirty, otherwise the widgets are
1820 * not connected and this update has no impact. */
1824 /* If the peer is already in the state we're moving to then we
1825 * won't have an impact on it. */
1826 if (power
!= peer
->power
)
1827 dapm_mark_dirty(peer
, "peer state change");
1830 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1831 struct list_head
*up_list
,
1832 struct list_head
*down_list
)
1834 struct snd_soc_dapm_path
*path
;
1836 if (w
->power
== power
)
1839 trace_snd_soc_dapm_widget_power(w
, power
);
1841 /* If we changed our power state perhaps our neigbours changed
1844 snd_soc_dapm_widget_for_each_source_path(w
, path
)
1845 dapm_widget_set_peer_power(path
->source
, power
, path
->connect
);
1847 /* Supplies can't affect their outputs, only their inputs */
1848 if (!w
->is_supply
) {
1849 snd_soc_dapm_widget_for_each_sink_path(w
, path
)
1850 dapm_widget_set_peer_power(path
->sink
, power
,
1855 dapm_seq_insert(w
, up_list
, true);
1857 dapm_seq_insert(w
, down_list
, false);
1860 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1861 struct list_head
*up_list
,
1862 struct list_head
*down_list
)
1867 case snd_soc_dapm_pre
:
1868 dapm_seq_insert(w
, down_list
, false);
1870 case snd_soc_dapm_post
:
1871 dapm_seq_insert(w
, up_list
, true);
1875 power
= dapm_widget_power_check(w
);
1877 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1882 static bool dapm_idle_bias_off(struct snd_soc_dapm_context
*dapm
)
1884 if (dapm
->idle_bias_off
)
1887 switch (snd_power_get_state(dapm
->card
->snd_card
)) {
1888 case SNDRV_CTL_POWER_D3hot
:
1889 case SNDRV_CTL_POWER_D3cold
:
1890 return dapm
->suspend_bias_off
;
1899 * Scan each dapm widget for complete audio path.
1900 * A complete path is a route that has valid endpoints i.e.:-
1902 * o DAC to output pin.
1903 * o Input pin to ADC.
1904 * o Input pin to Output pin (bypass, sidetone)
1905 * o DAC to ADC (loopback).
1907 static int dapm_power_widgets(struct snd_soc_card
*card
, int event
)
1909 struct snd_soc_dapm_widget
*w
;
1910 struct snd_soc_dapm_context
*d
;
1912 LIST_HEAD(down_list
);
1913 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1914 enum snd_soc_bias_level bias
;
1916 lockdep_assert_held(&card
->dapm_mutex
);
1918 trace_snd_soc_dapm_start(card
);
1920 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1921 if (dapm_idle_bias_off(d
))
1922 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1924 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1929 /* Check which widgets we need to power and store them in
1930 * lists indicating if they should be powered up or down. We
1931 * only check widgets that have been flagged as dirty but note
1932 * that new widgets may be added to the dirty list while we
1935 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1936 dapm_power_one_widget(w
, &up_list
, &down_list
);
1939 list_for_each_entry(w
, &card
->widgets
, list
) {
1941 case snd_soc_dapm_pre
:
1942 case snd_soc_dapm_post
:
1943 /* These widgets always need to be powered */
1946 list_del_init(&w
->dirty
);
1953 /* Supplies and micbiases only bring the
1954 * context up to STANDBY as unless something
1955 * else is active and passing audio they
1956 * generally don't require full power. Signal
1957 * generators are virtual pins and have no
1958 * power impact themselves.
1961 case snd_soc_dapm_siggen
:
1962 case snd_soc_dapm_vmid
:
1964 case snd_soc_dapm_supply
:
1965 case snd_soc_dapm_regulator_supply
:
1966 case snd_soc_dapm_pinctrl
:
1967 case snd_soc_dapm_clock_supply
:
1968 case snd_soc_dapm_micbias
:
1969 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1970 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1973 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1980 /* Force all contexts in the card to the same bias state if
1981 * they're not ground referenced.
1983 bias
= SND_SOC_BIAS_OFF
;
1984 list_for_each_entry(d
, &card
->dapm_list
, list
)
1985 if (d
->target_bias_level
> bias
)
1986 bias
= d
->target_bias_level
;
1987 list_for_each_entry(d
, &card
->dapm_list
, list
)
1988 if (!dapm_idle_bias_off(d
))
1989 d
->target_bias_level
= bias
;
1991 trace_snd_soc_dapm_walk_done(card
);
1993 /* Run card bias changes at first */
1994 dapm_pre_sequence_async(&card
->dapm
, 0);
1995 /* Run other bias changes in parallel */
1996 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1997 if (d
!= &card
->dapm
&& d
->bias_level
!= d
->target_bias_level
)
1998 async_schedule_domain(dapm_pre_sequence_async
, d
,
2001 async_synchronize_full_domain(&async_domain
);
2003 list_for_each_entry(w
, &down_list
, power_list
) {
2004 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMD
);
2007 list_for_each_entry(w
, &up_list
, power_list
) {
2008 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMU
);
2011 /* Power down widgets first; try to avoid amplifying pops. */
2012 dapm_seq_run(card
, &down_list
, event
, false);
2014 dapm_widget_update(card
);
2017 dapm_seq_run(card
, &up_list
, event
, true);
2019 /* Run all the bias changes in parallel */
2020 list_for_each_entry(d
, &card
->dapm_list
, list
) {
2021 if (d
!= &card
->dapm
&& d
->bias_level
!= d
->target_bias_level
)
2022 async_schedule_domain(dapm_post_sequence_async
, d
,
2025 async_synchronize_full_domain(&async_domain
);
2026 /* Run card bias changes at last */
2027 dapm_post_sequence_async(&card
->dapm
, 0);
2029 /* do we need to notify any clients that DAPM event is complete */
2030 list_for_each_entry(d
, &card
->dapm_list
, list
) {
2031 if (d
->stream_event
)
2032 d
->stream_event(d
, event
);
2035 pop_dbg(card
->dev
, card
->pop_time
,
2036 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
2037 pop_wait(card
->pop_time
);
2039 trace_snd_soc_dapm_done(card
);
2044 #ifdef CONFIG_DEBUG_FS
2045 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
2046 char __user
*user_buf
,
2047 size_t count
, loff_t
*ppos
)
2049 struct snd_soc_dapm_widget
*w
= file
->private_data
;
2050 struct snd_soc_card
*card
= w
->dapm
->card
;
2051 enum snd_soc_dapm_direction dir
, rdir
;
2055 struct snd_soc_dapm_path
*p
= NULL
;
2057 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
2061 mutex_lock(&card
->dapm_mutex
);
2063 /* Supply widgets are not handled by is_connected_{input,output}_ep() */
2068 in
= is_connected_input_ep(w
, NULL
, NULL
);
2069 out
= is_connected_output_ep(w
, NULL
, NULL
);
2072 ret
= scnprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
2073 w
->name
, w
->power
? "On" : "Off",
2074 w
->force
? " (forced)" : "", in
, out
);
2077 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
,
2078 " - R%d(0x%x) mask 0x%x",
2079 w
->reg
, w
->reg
, w
->mask
<< w
->shift
);
2081 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
2084 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
2086 w
->active
? "active" : "inactive");
2088 snd_soc_dapm_for_each_direction(dir
) {
2089 rdir
= SND_SOC_DAPM_DIR_REVERSE(dir
);
2090 snd_soc_dapm_widget_for_each_path(w
, dir
, p
) {
2091 if (p
->connected
&& !p
->connected(p
->source
, p
->sink
))
2097 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
,
2098 " %s \"%s\" \"%s\"\n",
2099 (rdir
== SND_SOC_DAPM_DIR_IN
) ? "in" : "out",
2100 p
->name
? p
->name
: "static",
2101 p
->node
[rdir
]->name
);
2105 mutex_unlock(&card
->dapm_mutex
);
2107 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
2113 static const struct file_operations dapm_widget_power_fops
= {
2114 .open
= simple_open
,
2115 .read
= dapm_widget_power_read_file
,
2116 .llseek
= default_llseek
,
2119 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
2120 size_t count
, loff_t
*ppos
)
2122 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
2125 switch (dapm
->bias_level
) {
2126 case SND_SOC_BIAS_ON
:
2129 case SND_SOC_BIAS_PREPARE
:
2130 level
= "Prepare\n";
2132 case SND_SOC_BIAS_STANDBY
:
2133 level
= "Standby\n";
2135 case SND_SOC_BIAS_OFF
:
2139 WARN(1, "Unknown bias_level %d\n", dapm
->bias_level
);
2140 level
= "Unknown\n";
2144 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
2148 static const struct file_operations dapm_bias_fops
= {
2149 .open
= simple_open
,
2150 .read
= dapm_bias_read_file
,
2151 .llseek
= default_llseek
,
2154 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2155 struct dentry
*parent
)
2159 if (!parent
|| IS_ERR(parent
))
2162 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
2164 if (IS_ERR(dapm
->debugfs_dapm
)) {
2166 "ASoC: Failed to create DAPM debugfs directory %ld\n",
2167 PTR_ERR(dapm
->debugfs_dapm
));
2171 d
= debugfs_create_file("bias_level", 0444,
2172 dapm
->debugfs_dapm
, dapm
,
2176 "ASoC: Failed to create bias level debugfs file: %ld\n",
2180 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2182 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
2185 if (!dapm
->debugfs_dapm
|| !w
->name
)
2188 d
= debugfs_create_file(w
->name
, 0444,
2189 dapm
->debugfs_dapm
, w
,
2190 &dapm_widget_power_fops
);
2192 dev_warn(w
->dapm
->dev
,
2193 "ASoC: Failed to create %s debugfs file: %ld\n",
2194 w
->name
, PTR_ERR(d
));
2197 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2199 if (!dapm
->debugfs_dapm
)
2201 debugfs_remove_recursive(dapm
->debugfs_dapm
);
2202 dapm
->debugfs_dapm
= NULL
;
2206 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2207 struct dentry
*parent
)
2211 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2215 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2222 * soc_dapm_connect_path() - Connects or disconnects a path
2223 * @path: The path to update
2224 * @connect: The new connect state of the path. True if the path is connected,
2225 * false if it is disconnected.
2226 * @reason: The reason why the path changed (for debugging only)
2228 static void soc_dapm_connect_path(struct snd_soc_dapm_path
*path
,
2229 bool connect
, const char *reason
)
2231 if (path
->connect
== connect
)
2234 path
->connect
= connect
;
2235 dapm_mark_dirty(path
->source
, reason
);
2236 dapm_mark_dirty(path
->sink
, reason
);
2237 dapm_path_invalidate(path
);
2240 /* test and update the power status of a mux widget */
2241 static int soc_dapm_mux_update_power(struct snd_soc_card
*card
,
2242 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
2244 struct snd_soc_dapm_path
*path
;
2248 lockdep_assert_held(&card
->dapm_mutex
);
2250 /* find dapm widget path assoc with kcontrol */
2251 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2253 /* we now need to match the string in the enum to the path */
2254 if (e
&& !(strcmp(path
->name
, e
->texts
[mux
])))
2259 soc_dapm_connect_path(path
, connect
, "mux update");
2263 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2268 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context
*dapm
,
2269 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
,
2270 struct snd_soc_dapm_update
*update
)
2272 struct snd_soc_card
*card
= dapm
->card
;
2275 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2276 card
->update
= update
;
2277 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
2278 card
->update
= NULL
;
2279 mutex_unlock(&card
->dapm_mutex
);
2281 soc_dpcm_runtime_update(card
);
2284 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
2286 /* test and update the power status of a mixer or switch widget */
2287 static int soc_dapm_mixer_update_power(struct snd_soc_card
*card
,
2288 struct snd_kcontrol
*kcontrol
,
2289 int connect
, int rconnect
)
2291 struct snd_soc_dapm_path
*path
;
2294 lockdep_assert_held(&card
->dapm_mutex
);
2296 /* find dapm widget path assoc with kcontrol */
2297 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2299 * Ideally this function should support any number of
2300 * paths and channels. But since kcontrols only come
2301 * in mono and stereo variants, we are limited to 2
2304 * The following code assumes for stereo controls the
2305 * first path (when 'found == 0') is the left channel,
2306 * and all remaining paths (when 'found == 1') are the
2309 * A stereo control is signified by a valid 'rconnect'
2310 * value, either 0 for unconnected, or >= 0 for connected.
2311 * This is chosen instead of using snd_soc_volsw_is_stereo,
2312 * so that the behavior of snd_soc_dapm_mixer_update_power
2313 * doesn't change even when the kcontrol passed in is
2316 * It passes 'connect' as the path connect status for
2317 * the left channel, and 'rconnect' for the right
2320 if (found
&& rconnect
>= 0)
2321 soc_dapm_connect_path(path
, rconnect
, "mixer update");
2323 soc_dapm_connect_path(path
, connect
, "mixer update");
2328 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2333 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context
*dapm
,
2334 struct snd_kcontrol
*kcontrol
, int connect
,
2335 struct snd_soc_dapm_update
*update
)
2337 struct snd_soc_card
*card
= dapm
->card
;
2340 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2341 card
->update
= update
;
2342 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
, -1);
2343 card
->update
= NULL
;
2344 mutex_unlock(&card
->dapm_mutex
);
2346 soc_dpcm_runtime_update(card
);
2349 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2351 static ssize_t
dapm_widget_show_component(struct snd_soc_component
*cmpnt
,
2354 struct snd_soc_dapm_context
*dapm
= snd_soc_component_get_dapm(cmpnt
);
2355 struct snd_soc_dapm_widget
*w
;
2357 char *state
= "not set";
2359 /* card won't be set for the dummy component, as a spot fix
2360 * we're checking for that case specifically here but in future
2361 * we will ensure that the dummy component looks like others.
2366 list_for_each_entry(w
, &cmpnt
->card
->widgets
, list
) {
2367 if (w
->dapm
!= dapm
)
2370 /* only display widgets that burn power */
2372 case snd_soc_dapm_hp
:
2373 case snd_soc_dapm_mic
:
2374 case snd_soc_dapm_spk
:
2375 case snd_soc_dapm_line
:
2376 case snd_soc_dapm_micbias
:
2377 case snd_soc_dapm_dac
:
2378 case snd_soc_dapm_adc
:
2379 case snd_soc_dapm_pga
:
2380 case snd_soc_dapm_effect
:
2381 case snd_soc_dapm_out_drv
:
2382 case snd_soc_dapm_mixer
:
2383 case snd_soc_dapm_mixer_named_ctl
:
2384 case snd_soc_dapm_supply
:
2385 case snd_soc_dapm_regulator_supply
:
2386 case snd_soc_dapm_pinctrl
:
2387 case snd_soc_dapm_clock_supply
:
2389 count
+= sprintf(buf
+ count
, "%s: %s\n",
2390 w
->name
, w
->power
? "On":"Off");
2397 switch (snd_soc_dapm_get_bias_level(dapm
)) {
2398 case SND_SOC_BIAS_ON
:
2401 case SND_SOC_BIAS_PREPARE
:
2404 case SND_SOC_BIAS_STANDBY
:
2407 case SND_SOC_BIAS_OFF
:
2411 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2416 /* show dapm widget status in sys fs */
2417 static ssize_t
dapm_widget_show(struct device
*dev
,
2418 struct device_attribute
*attr
, char *buf
)
2420 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2421 struct snd_soc_dai
*codec_dai
;
2424 mutex_lock(&rtd
->card
->dapm_mutex
);
2426 for_each_rtd_codec_dai(rtd
, i
, codec_dai
) {
2427 struct snd_soc_component
*cmpnt
= codec_dai
->component
;
2429 count
+= dapm_widget_show_component(cmpnt
, buf
+ count
);
2432 mutex_unlock(&rtd
->card
->dapm_mutex
);
2437 static DEVICE_ATTR_RO(dapm_widget
);
2439 struct attribute
*soc_dapm_dev_attrs
[] = {
2440 &dev_attr_dapm_widget
.attr
,
2444 static void dapm_free_path(struct snd_soc_dapm_path
*path
)
2446 list_del(&path
->list_node
[SND_SOC_DAPM_DIR_IN
]);
2447 list_del(&path
->list_node
[SND_SOC_DAPM_DIR_OUT
]);
2448 list_del(&path
->list_kcontrol
);
2449 list_del(&path
->list
);
2453 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget
*w
)
2455 struct snd_soc_dapm_path
*p
, *next_p
;
2456 enum snd_soc_dapm_direction dir
;
2460 * remove source and sink paths associated to this widget.
2461 * While removing the path, remove reference to it from both
2462 * source and sink widgets so that path is removed only once.
2464 snd_soc_dapm_for_each_direction(dir
) {
2465 snd_soc_dapm_widget_for_each_path_safe(w
, dir
, p
, next_p
)
2469 kfree(w
->kcontrols
);
2470 kfree_const(w
->name
);
2471 kfree_const(w
->sname
);
2475 void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context
*dapm
)
2477 dapm
->path_sink_cache
.widget
= NULL
;
2478 dapm
->path_source_cache
.widget
= NULL
;
2481 /* free all dapm widgets and resources */
2482 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2484 struct snd_soc_dapm_widget
*w
, *next_w
;
2486 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2487 if (w
->dapm
!= dapm
)
2489 snd_soc_dapm_free_widget(w
);
2491 snd_soc_dapm_reset_cache(dapm
);
2494 static struct snd_soc_dapm_widget
*dapm_find_widget(
2495 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2496 bool search_other_contexts
)
2498 struct snd_soc_dapm_widget
*w
;
2499 struct snd_soc_dapm_widget
*fallback
= NULL
;
2501 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2502 if (!strcmp(w
->name
, pin
)) {
2503 if (w
->dapm
== dapm
)
2510 if (search_other_contexts
)
2516 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2517 const char *pin
, int status
)
2519 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2521 dapm_assert_locked(dapm
);
2524 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2528 if (w
->connected
!= status
) {
2529 dapm_mark_dirty(w
, "pin configuration");
2530 dapm_widget_invalidate_input_paths(w
);
2531 dapm_widget_invalidate_output_paths(w
);
2534 w
->connected
= status
;
2542 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2543 * @dapm: DAPM context
2545 * Walks all dapm audio paths and powers widgets according to their
2546 * stream or path usage.
2548 * Requires external locking.
2550 * Returns 0 for success.
2552 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context
*dapm
)
2555 * Suppress early reports (eg, jacks syncing their state) to avoid
2556 * silly DAPM runs during card startup.
2558 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2561 return dapm_power_widgets(dapm
->card
, SND_SOC_DAPM_STREAM_NOP
);
2563 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked
);
2566 * snd_soc_dapm_sync - scan and power dapm paths
2567 * @dapm: DAPM context
2569 * Walks all dapm audio paths and powers widgets according to their
2570 * stream or path usage.
2572 * Returns 0 for success.
2574 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2578 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2579 ret
= snd_soc_dapm_sync_unlocked(dapm
);
2580 mutex_unlock(&dapm
->card
->dapm_mutex
);
2583 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2585 static int dapm_update_dai_chan(struct snd_soc_dapm_path
*p
,
2586 struct snd_soc_dapm_widget
*w
,
2590 case snd_soc_dapm_aif_out
:
2591 case snd_soc_dapm_aif_in
:
2597 dev_dbg(w
->dapm
->dev
, "%s DAI route %s -> %s\n",
2598 w
->channel
< channels
? "Connecting" : "Disconnecting",
2599 p
->source
->name
, p
->sink
->name
);
2601 if (w
->channel
< channels
)
2602 soc_dapm_connect_path(p
, true, "dai update");
2604 soc_dapm_connect_path(p
, false, "dai update");
2609 static int dapm_update_dai_unlocked(struct snd_pcm_substream
*substream
,
2610 struct snd_pcm_hw_params
*params
,
2611 struct snd_soc_dai
*dai
)
2613 int dir
= substream
->stream
;
2614 int channels
= params_channels(params
);
2615 struct snd_soc_dapm_path
*p
;
2616 struct snd_soc_dapm_widget
*w
;
2619 if (dir
== SNDRV_PCM_STREAM_PLAYBACK
)
2620 w
= dai
->playback_widget
;
2622 w
= dai
->capture_widget
;
2627 dev_dbg(dai
->dev
, "Update DAI routes for %s %s\n", dai
->name
,
2628 dir
== SNDRV_PCM_STREAM_PLAYBACK
? "playback" : "capture");
2630 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
2631 ret
= dapm_update_dai_chan(p
, p
->sink
, channels
);
2636 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
2637 ret
= dapm_update_dai_chan(p
, p
->source
, channels
);
2645 int snd_soc_dapm_update_dai(struct snd_pcm_substream
*substream
,
2646 struct snd_pcm_hw_params
*params
,
2647 struct snd_soc_dai
*dai
)
2649 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
2652 mutex_lock_nested(&rtd
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2653 ret
= dapm_update_dai_unlocked(substream
, params
, dai
);
2654 mutex_unlock(&rtd
->card
->dapm_mutex
);
2658 EXPORT_SYMBOL_GPL(snd_soc_dapm_update_dai
);
2661 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2662 * @w: The widget for which to update the flags
2664 * Some widgets have a dynamic category which depends on which neighbors they
2665 * are connected to. This function update the category for these widgets.
2667 * This function must be called whenever a path is added or removed to a widget.
2669 static void dapm_update_widget_flags(struct snd_soc_dapm_widget
*w
)
2671 enum snd_soc_dapm_direction dir
;
2672 struct snd_soc_dapm_path
*p
;
2676 case snd_soc_dapm_input
:
2677 /* On a fully routed card an input is never a source */
2678 if (w
->dapm
->card
->fully_routed
)
2680 ep
= SND_SOC_DAPM_EP_SOURCE
;
2681 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
2682 if (p
->source
->id
== snd_soc_dapm_micbias
||
2683 p
->source
->id
== snd_soc_dapm_mic
||
2684 p
->source
->id
== snd_soc_dapm_line
||
2685 p
->source
->id
== snd_soc_dapm_output
) {
2691 case snd_soc_dapm_output
:
2692 /* On a fully routed card a output is never a sink */
2693 if (w
->dapm
->card
->fully_routed
)
2695 ep
= SND_SOC_DAPM_EP_SINK
;
2696 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
2697 if (p
->sink
->id
== snd_soc_dapm_spk
||
2698 p
->sink
->id
== snd_soc_dapm_hp
||
2699 p
->sink
->id
== snd_soc_dapm_line
||
2700 p
->sink
->id
== snd_soc_dapm_input
) {
2706 case snd_soc_dapm_line
:
2708 snd_soc_dapm_for_each_direction(dir
) {
2709 if (!list_empty(&w
->edges
[dir
]))
2710 ep
|= SND_SOC_DAPM_DIR_TO_EP(dir
);
2720 static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context
*dapm
,
2721 struct snd_soc_dapm_widget
*source
, struct snd_soc_dapm_widget
*sink
,
2722 const char *control
)
2724 bool dynamic_source
= false;
2725 bool dynamic_sink
= false;
2730 switch (source
->id
) {
2731 case snd_soc_dapm_demux
:
2732 dynamic_source
= true;
2739 case snd_soc_dapm_mux
:
2740 case snd_soc_dapm_switch
:
2741 case snd_soc_dapm_mixer
:
2742 case snd_soc_dapm_mixer_named_ctl
:
2743 dynamic_sink
= true;
2749 if (dynamic_source
&& dynamic_sink
) {
2751 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n",
2752 source
->name
, control
, sink
->name
);
2754 } else if (!dynamic_source
&& !dynamic_sink
) {
2756 "Control not supported for path %s -> [%s] -> %s\n",
2757 source
->name
, control
, sink
->name
);
2764 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
2765 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
2766 const char *control
,
2767 int (*connected
)(struct snd_soc_dapm_widget
*source
,
2768 struct snd_soc_dapm_widget
*sink
))
2770 struct snd_soc_dapm_widget
*widgets
[2];
2771 enum snd_soc_dapm_direction dir
;
2772 struct snd_soc_dapm_path
*path
;
2775 if (wsink
->is_supply
&& !wsource
->is_supply
) {
2777 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n",
2778 wsource
->name
, wsink
->name
);
2782 if (connected
&& !wsource
->is_supply
) {
2784 "connected() callback only supported for supply widgets (%s -> %s)\n",
2785 wsource
->name
, wsink
->name
);
2789 if (wsource
->is_supply
&& control
) {
2791 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n",
2792 wsource
->name
, control
, wsink
->name
);
2796 ret
= snd_soc_dapm_check_dynamic_path(dapm
, wsource
, wsink
, control
);
2800 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2804 path
->node
[SND_SOC_DAPM_DIR_IN
] = wsource
;
2805 path
->node
[SND_SOC_DAPM_DIR_OUT
] = wsink
;
2806 widgets
[SND_SOC_DAPM_DIR_IN
] = wsource
;
2807 widgets
[SND_SOC_DAPM_DIR_OUT
] = wsink
;
2809 path
->connected
= connected
;
2810 INIT_LIST_HEAD(&path
->list
);
2811 INIT_LIST_HEAD(&path
->list_kcontrol
);
2813 if (wsource
->is_supply
|| wsink
->is_supply
)
2814 path
->is_supply
= 1;
2816 /* connect static paths */
2817 if (control
== NULL
) {
2820 switch (wsource
->id
) {
2821 case snd_soc_dapm_demux
:
2822 ret
= dapm_connect_mux(dapm
, path
, control
, wsource
);
2830 switch (wsink
->id
) {
2831 case snd_soc_dapm_mux
:
2832 ret
= dapm_connect_mux(dapm
, path
, control
, wsink
);
2836 case snd_soc_dapm_switch
:
2837 case snd_soc_dapm_mixer
:
2838 case snd_soc_dapm_mixer_named_ctl
:
2839 ret
= dapm_connect_mixer(dapm
, path
, control
);
2848 list_add(&path
->list
, &dapm
->card
->paths
);
2849 snd_soc_dapm_for_each_direction(dir
)
2850 list_add(&path
->list_node
[dir
], &widgets
[dir
]->edges
[dir
]);
2852 snd_soc_dapm_for_each_direction(dir
) {
2853 dapm_update_widget_flags(widgets
[dir
]);
2854 dapm_mark_dirty(widgets
[dir
], "Route added");
2857 if (dapm
->card
->instantiated
&& path
->connect
)
2858 dapm_path_invalidate(path
);
2866 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2867 const struct snd_soc_dapm_route
*route
)
2869 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2870 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2873 char prefixed_sink
[80];
2874 char prefixed_source
[80];
2876 unsigned int sink_ref
= 0;
2877 unsigned int source_ref
= 0;
2880 prefix
= soc_dapm_prefix(dapm
);
2882 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2883 prefix
, route
->sink
);
2884 sink
= prefixed_sink
;
2885 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2886 prefix
, route
->source
);
2887 source
= prefixed_source
;
2890 source
= route
->source
;
2893 wsource
= dapm_wcache_lookup(&dapm
->path_source_cache
, source
);
2894 wsink
= dapm_wcache_lookup(&dapm
->path_sink_cache
, sink
);
2896 if (wsink
&& wsource
)
2900 * find src and dest widgets over all widgets but favor a widget from
2901 * current DAPM context
2903 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2904 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2906 if (w
->dapm
== dapm
) {
2914 "ASoC: sink widget %s overwritten\n",
2918 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2920 if (w
->dapm
== dapm
) {
2928 "ASoC: source widget %s overwritten\n",
2932 /* use widget from another DAPM context if not found from this */
2938 if (wsource
== NULL
) {
2939 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2943 if (wsink
== NULL
) {
2944 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2950 dapm_wcache_update(&dapm
->path_sink_cache
, wsink
);
2951 dapm_wcache_update(&dapm
->path_source_cache
, wsource
);
2953 ret
= snd_soc_dapm_add_path(dapm
, wsource
, wsink
, route
->control
,
2960 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2961 source
, route
->control
, sink
);
2965 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2966 const struct snd_soc_dapm_route
*route
)
2968 struct snd_soc_dapm_widget
*wsource
, *wsink
;
2969 struct snd_soc_dapm_path
*path
, *p
;
2972 char prefixed_sink
[80];
2973 char prefixed_source
[80];
2976 if (route
->control
) {
2978 "ASoC: Removal of routes with controls not supported\n");
2982 prefix
= soc_dapm_prefix(dapm
);
2984 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2985 prefix
, route
->sink
);
2986 sink
= prefixed_sink
;
2987 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2988 prefix
, route
->source
);
2989 source
= prefixed_source
;
2992 source
= route
->source
;
2996 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2997 if (strcmp(p
->source
->name
, source
) != 0)
2999 if (strcmp(p
->sink
->name
, sink
) != 0)
3006 wsource
= path
->source
;
3009 dapm_mark_dirty(wsource
, "Route removed");
3010 dapm_mark_dirty(wsink
, "Route removed");
3012 dapm_path_invalidate(path
);
3014 dapm_free_path(path
);
3016 /* Update any path related flags */
3017 dapm_update_widget_flags(wsource
);
3018 dapm_update_widget_flags(wsink
);
3020 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
3028 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
3029 * @dapm: DAPM context
3030 * @route: audio routes
3031 * @num: number of routes
3033 * Connects 2 dapm widgets together via a named audio path. The sink is
3034 * the widget receiving the audio signal, whilst the source is the sender
3035 * of the audio signal.
3037 * Returns 0 for success else error. On error all resources can be freed
3038 * with a call to snd_soc_card_free().
3040 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
3041 const struct snd_soc_dapm_route
*route
, int num
)
3045 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3046 for (i
= 0; i
< num
; i
++) {
3047 r
= snd_soc_dapm_add_route(dapm
, route
);
3049 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
3051 route
->control
? route
->control
: "direct",
3057 mutex_unlock(&dapm
->card
->dapm_mutex
);
3061 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
3064 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
3065 * @dapm: DAPM context
3066 * @route: audio routes
3067 * @num: number of routes
3069 * Removes routes from the DAPM context.
3071 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
3072 const struct snd_soc_dapm_route
*route
, int num
)
3076 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3077 for (i
= 0; i
< num
; i
++) {
3078 snd_soc_dapm_del_route(dapm
, route
);
3081 mutex_unlock(&dapm
->card
->dapm_mutex
);
3085 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
3087 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
3088 const struct snd_soc_dapm_route
*route
)
3090 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
3093 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
3096 struct snd_soc_dapm_path
*path
;
3100 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
3106 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
3111 if (route
->control
|| route
->connected
)
3112 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
3113 route
->source
, route
->sink
);
3115 snd_soc_dapm_widget_for_each_sink_path(source
, path
) {
3116 if (path
->sink
== sink
) {
3123 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
3124 route
->source
, route
->sink
);
3126 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
3127 count
, route
->source
, route
->sink
);
3133 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
3134 * @dapm: DAPM context
3135 * @route: audio routes
3136 * @num: number of routes
3138 * Mark existing routes matching those specified in the passed array
3139 * as being weak, meaning that they are ignored for the purpose of
3140 * power decisions. The main intended use case is for sidetone paths
3141 * which couple audio between other independent paths if they are both
3142 * active in order to make the combination work better at the user
3143 * level but which aren't intended to be "used".
3145 * Note that CODEC drivers should not use this as sidetone type paths
3146 * can frequently also be used as bypass paths.
3148 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
3149 const struct snd_soc_dapm_route
*route
, int num
)
3154 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3155 for (i
= 0; i
< num
; i
++) {
3156 err
= snd_soc_dapm_weak_route(dapm
, route
);
3161 mutex_unlock(&dapm
->card
->dapm_mutex
);
3165 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
3168 * snd_soc_dapm_new_widgets - add new dapm widgets
3169 * @card: card to be checked for new dapm widgets
3171 * Checks the codec for any new dapm widgets and creates them if found.
3173 * Returns 0 for success.
3175 int snd_soc_dapm_new_widgets(struct snd_soc_card
*card
)
3177 struct snd_soc_dapm_widget
*w
;
3180 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3182 list_for_each_entry(w
, &card
->widgets
, list
)
3187 if (w
->num_kcontrols
) {
3188 w
->kcontrols
= kcalloc(w
->num_kcontrols
,
3189 sizeof(struct snd_kcontrol
*),
3191 if (!w
->kcontrols
) {
3192 mutex_unlock(&card
->dapm_mutex
);
3198 case snd_soc_dapm_switch
:
3199 case snd_soc_dapm_mixer
:
3200 case snd_soc_dapm_mixer_named_ctl
:
3203 case snd_soc_dapm_mux
:
3204 case snd_soc_dapm_demux
:
3207 case snd_soc_dapm_pga
:
3208 case snd_soc_dapm_effect
:
3209 case snd_soc_dapm_out_drv
:
3212 case snd_soc_dapm_dai_link
:
3213 dapm_new_dai_link(w
);
3219 /* Read the initial power state from the device */
3221 soc_dapm_read(w
->dapm
, w
->reg
, &val
);
3222 val
= val
>> w
->shift
;
3224 if (val
== w
->on_val
)
3230 dapm_mark_dirty(w
, "new widget");
3231 dapm_debugfs_add_widget(w
);
3234 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
3235 mutex_unlock(&card
->dapm_mutex
);
3238 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
3241 * snd_soc_dapm_get_volsw - dapm mixer get callback
3242 * @kcontrol: mixer control
3243 * @ucontrol: control element information
3245 * Callback to get the value of a dapm mixer control.
3247 * Returns 0 for success.
3249 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
3250 struct snd_ctl_elem_value
*ucontrol
)
3252 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3253 struct snd_soc_card
*card
= dapm
->card
;
3254 struct soc_mixer_control
*mc
=
3255 (struct soc_mixer_control
*)kcontrol
->private_value
;
3257 unsigned int shift
= mc
->shift
;
3259 unsigned int width
= fls(max
);
3260 unsigned int mask
= (1 << fls(max
)) - 1;
3261 unsigned int invert
= mc
->invert
;
3262 unsigned int reg_val
, val
, rval
= 0;
3265 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3266 if (dapm_kcontrol_is_powered(kcontrol
) && reg
!= SND_SOC_NOPM
) {
3267 ret
= soc_dapm_read(dapm
, reg
, ®_val
);
3268 val
= (reg_val
>> shift
) & mask
;
3270 if (ret
== 0 && reg
!= mc
->rreg
)
3271 ret
= soc_dapm_read(dapm
, mc
->rreg
, ®_val
);
3273 if (snd_soc_volsw_is_stereo(mc
))
3274 rval
= (reg_val
>> mc
->rshift
) & mask
;
3276 reg_val
= dapm_kcontrol_get_value(kcontrol
);
3277 val
= reg_val
& mask
;
3279 if (snd_soc_volsw_is_stereo(mc
))
3280 rval
= (reg_val
>> width
) & mask
;
3282 mutex_unlock(&card
->dapm_mutex
);
3288 ucontrol
->value
.integer
.value
[0] = max
- val
;
3290 ucontrol
->value
.integer
.value
[0] = val
;
3292 if (snd_soc_volsw_is_stereo(mc
)) {
3294 ucontrol
->value
.integer
.value
[1] = max
- rval
;
3296 ucontrol
->value
.integer
.value
[1] = rval
;
3301 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
3304 * snd_soc_dapm_put_volsw - dapm mixer set callback
3305 * @kcontrol: mixer control
3306 * @ucontrol: control element information
3308 * Callback to set the value of a dapm mixer control.
3310 * Returns 0 for success.
3312 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
3313 struct snd_ctl_elem_value
*ucontrol
)
3315 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3316 struct snd_soc_card
*card
= dapm
->card
;
3317 struct soc_mixer_control
*mc
=
3318 (struct soc_mixer_control
*)kcontrol
->private_value
;
3320 unsigned int shift
= mc
->shift
;
3322 unsigned int width
= fls(max
);
3323 unsigned int mask
= (1 << width
) - 1;
3324 unsigned int invert
= mc
->invert
;
3325 unsigned int val
, rval
= 0;
3326 int connect
, rconnect
= -1, change
, reg_change
= 0;
3327 struct snd_soc_dapm_update update
= {};
3330 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
3336 if (snd_soc_volsw_is_stereo(mc
)) {
3337 rval
= (ucontrol
->value
.integer
.value
[1] & mask
);
3343 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3345 /* This assumes field width < (bits in unsigned int / 2) */
3346 if (width
> sizeof(unsigned int) * 8 / 2)
3348 "ASoC: control %s field width limit exceeded\n",
3350 change
= dapm_kcontrol_set_value(kcontrol
, val
| (rval
<< width
));
3352 if (reg
!= SND_SOC_NOPM
) {
3354 rval
= rval
<< mc
->rshift
;
3356 reg_change
= soc_dapm_test_bits(dapm
, reg
, mask
<< shift
, val
);
3358 if (snd_soc_volsw_is_stereo(mc
))
3359 reg_change
|= soc_dapm_test_bits(dapm
, mc
->rreg
,
3364 if (change
|| reg_change
) {
3366 if (snd_soc_volsw_is_stereo(mc
)) {
3367 update
.has_second_set
= true;
3368 update
.reg2
= mc
->rreg
;
3369 update
.mask2
= mask
<< mc
->rshift
;
3372 update
.kcontrol
= kcontrol
;
3374 update
.mask
= mask
<< shift
;
3376 card
->update
= &update
;
3378 change
|= reg_change
;
3380 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
,
3383 card
->update
= NULL
;
3386 mutex_unlock(&card
->dapm_mutex
);
3389 soc_dpcm_runtime_update(card
);
3393 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
3396 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3397 * @kcontrol: mixer control
3398 * @ucontrol: control element information
3400 * Callback to get the value of a dapm enumerated double mixer control.
3402 * Returns 0 for success.
3404 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
3405 struct snd_ctl_elem_value
*ucontrol
)
3407 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3408 struct snd_soc_card
*card
= dapm
->card
;
3409 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3410 unsigned int reg_val
, val
;
3412 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3413 if (e
->reg
!= SND_SOC_NOPM
&& dapm_kcontrol_is_powered(kcontrol
)) {
3414 int ret
= soc_dapm_read(dapm
, e
->reg
, ®_val
);
3416 mutex_unlock(&card
->dapm_mutex
);
3420 reg_val
= dapm_kcontrol_get_value(kcontrol
);
3422 mutex_unlock(&card
->dapm_mutex
);
3424 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
3425 ucontrol
->value
.enumerated
.item
[0] = snd_soc_enum_val_to_item(e
, val
);
3426 if (e
->shift_l
!= e
->shift_r
) {
3427 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
3428 val
= snd_soc_enum_val_to_item(e
, val
);
3429 ucontrol
->value
.enumerated
.item
[1] = val
;
3434 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
3437 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3438 * @kcontrol: mixer control
3439 * @ucontrol: control element information
3441 * Callback to set the value of a dapm enumerated double mixer control.
3443 * Returns 0 for success.
3445 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
3446 struct snd_ctl_elem_value
*ucontrol
)
3448 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3449 struct snd_soc_card
*card
= dapm
->card
;
3450 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3451 unsigned int *item
= ucontrol
->value
.enumerated
.item
;
3452 unsigned int val
, change
, reg_change
= 0;
3454 struct snd_soc_dapm_update update
= {};
3457 if (item
[0] >= e
->items
)
3460 val
= snd_soc_enum_item_to_val(e
, item
[0]) << e
->shift_l
;
3461 mask
= e
->mask
<< e
->shift_l
;
3462 if (e
->shift_l
!= e
->shift_r
) {
3463 if (item
[1] > e
->items
)
3465 val
|= snd_soc_enum_item_to_val(e
, item
[1]) << e
->shift_r
;
3466 mask
|= e
->mask
<< e
->shift_r
;
3469 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3471 change
= dapm_kcontrol_set_value(kcontrol
, val
);
3473 if (e
->reg
!= SND_SOC_NOPM
)
3474 reg_change
= soc_dapm_test_bits(dapm
, e
->reg
, mask
, val
);
3476 if (change
|| reg_change
) {
3478 update
.kcontrol
= kcontrol
;
3479 update
.reg
= e
->reg
;
3482 card
->update
= &update
;
3484 change
|= reg_change
;
3486 ret
= soc_dapm_mux_update_power(card
, kcontrol
, item
[0], e
);
3488 card
->update
= NULL
;
3491 mutex_unlock(&card
->dapm_mutex
);
3494 soc_dpcm_runtime_update(card
);
3498 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
3501 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3503 * @kcontrol: mixer control
3504 * @uinfo: control element information
3506 * Callback to provide information about a pin switch control.
3508 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
3509 struct snd_ctl_elem_info
*uinfo
)
3511 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3513 uinfo
->value
.integer
.min
= 0;
3514 uinfo
->value
.integer
.max
= 1;
3518 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3521 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3523 * @kcontrol: mixer control
3526 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3527 struct snd_ctl_elem_value
*ucontrol
)
3529 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3530 const char *pin
= (const char *)kcontrol
->private_value
;
3532 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3534 ucontrol
->value
.integer
.value
[0] =
3535 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3537 mutex_unlock(&card
->dapm_mutex
);
3541 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3544 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3546 * @kcontrol: mixer control
3549 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3550 struct snd_ctl_elem_value
*ucontrol
)
3552 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3553 const char *pin
= (const char *)kcontrol
->private_value
;
3555 if (ucontrol
->value
.integer
.value
[0])
3556 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3558 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3560 snd_soc_dapm_sync(&card
->dapm
);
3563 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3565 struct snd_soc_dapm_widget
*
3566 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context
*dapm
,
3567 const struct snd_soc_dapm_widget
*widget
)
3569 enum snd_soc_dapm_direction dir
;
3570 struct snd_soc_dapm_widget
*w
;
3574 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3575 return ERR_PTR(-ENOMEM
);
3578 case snd_soc_dapm_regulator_supply
:
3579 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3580 if (IS_ERR(w
->regulator
)) {
3581 ret
= PTR_ERR(w
->regulator
);
3582 goto request_failed
;
3585 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3586 ret
= regulator_allow_bypass(w
->regulator
, true);
3589 "ASoC: Failed to bypass %s: %d\n",
3593 case snd_soc_dapm_pinctrl
:
3594 w
->pinctrl
= devm_pinctrl_get(dapm
->dev
);
3595 if (IS_ERR(w
->pinctrl
)) {
3596 ret
= PTR_ERR(w
->pinctrl
);
3597 goto request_failed
;
3600 case snd_soc_dapm_clock_supply
:
3601 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3602 if (IS_ERR(w
->clk
)) {
3603 ret
= PTR_ERR(w
->clk
);
3604 goto request_failed
;
3611 prefix
= soc_dapm_prefix(dapm
);
3613 w
->name
= kasprintf(GFP_KERNEL
, "%s %s", prefix
, widget
->name
);
3615 w
->name
= kstrdup_const(widget
->name
, GFP_KERNEL
);
3616 if (w
->name
== NULL
) {
3617 kfree_const(w
->sname
);
3619 return ERR_PTR(-ENOMEM
);
3623 case snd_soc_dapm_mic
:
3624 w
->is_ep
= SND_SOC_DAPM_EP_SOURCE
;
3625 w
->power_check
= dapm_generic_check_power
;
3627 case snd_soc_dapm_input
:
3628 if (!dapm
->card
->fully_routed
)
3629 w
->is_ep
= SND_SOC_DAPM_EP_SOURCE
;
3630 w
->power_check
= dapm_generic_check_power
;
3632 case snd_soc_dapm_spk
:
3633 case snd_soc_dapm_hp
:
3634 w
->is_ep
= SND_SOC_DAPM_EP_SINK
;
3635 w
->power_check
= dapm_generic_check_power
;
3637 case snd_soc_dapm_output
:
3638 if (!dapm
->card
->fully_routed
)
3639 w
->is_ep
= SND_SOC_DAPM_EP_SINK
;
3640 w
->power_check
= dapm_generic_check_power
;
3642 case snd_soc_dapm_vmid
:
3643 case snd_soc_dapm_siggen
:
3644 w
->is_ep
= SND_SOC_DAPM_EP_SOURCE
;
3645 w
->power_check
= dapm_always_on_check_power
;
3647 case snd_soc_dapm_sink
:
3648 w
->is_ep
= SND_SOC_DAPM_EP_SINK
;
3649 w
->power_check
= dapm_always_on_check_power
;
3652 case snd_soc_dapm_mux
:
3653 case snd_soc_dapm_demux
:
3654 case snd_soc_dapm_switch
:
3655 case snd_soc_dapm_mixer
:
3656 case snd_soc_dapm_mixer_named_ctl
:
3657 case snd_soc_dapm_adc
:
3658 case snd_soc_dapm_aif_out
:
3659 case snd_soc_dapm_dac
:
3660 case snd_soc_dapm_aif_in
:
3661 case snd_soc_dapm_pga
:
3662 case snd_soc_dapm_buffer
:
3663 case snd_soc_dapm_scheduler
:
3664 case snd_soc_dapm_effect
:
3665 case snd_soc_dapm_src
:
3666 case snd_soc_dapm_asrc
:
3667 case snd_soc_dapm_encoder
:
3668 case snd_soc_dapm_decoder
:
3669 case snd_soc_dapm_out_drv
:
3670 case snd_soc_dapm_micbias
:
3671 case snd_soc_dapm_line
:
3672 case snd_soc_dapm_dai_link
:
3673 case snd_soc_dapm_dai_out
:
3674 case snd_soc_dapm_dai_in
:
3675 w
->power_check
= dapm_generic_check_power
;
3677 case snd_soc_dapm_supply
:
3678 case snd_soc_dapm_regulator_supply
:
3679 case snd_soc_dapm_pinctrl
:
3680 case snd_soc_dapm_clock_supply
:
3681 case snd_soc_dapm_kcontrol
:
3683 w
->power_check
= dapm_supply_check_power
;
3686 w
->power_check
= dapm_always_on_check_power
;
3691 INIT_LIST_HEAD(&w
->list
);
3692 INIT_LIST_HEAD(&w
->dirty
);
3693 list_add_tail(&w
->list
, &dapm
->card
->widgets
);
3695 snd_soc_dapm_for_each_direction(dir
) {
3696 INIT_LIST_HEAD(&w
->edges
[dir
]);
3697 w
->endpoints
[dir
] = -1;
3700 /* machine layer sets up unconnected pins and insertions */
3705 if (ret
!= -EPROBE_DEFER
)
3706 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3709 kfree_const(w
->sname
);
3711 return ERR_PTR(ret
);
3715 * snd_soc_dapm_new_control - create new dapm control
3716 * @dapm: DAPM context
3717 * @widget: widget template
3719 * Creates new DAPM control based upon a template.
3721 * Returns a widget pointer on success or an error pointer on failure
3723 struct snd_soc_dapm_widget
*
3724 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3725 const struct snd_soc_dapm_widget
*widget
)
3727 struct snd_soc_dapm_widget
*w
;
3729 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3730 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3731 mutex_unlock(&dapm
->card
->dapm_mutex
);
3735 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
3738 * snd_soc_dapm_new_controls - create new dapm controls
3739 * @dapm: DAPM context
3740 * @widget: widget array
3741 * @num: number of widgets
3743 * Creates new DAPM controls based upon the templates.
3745 * Returns 0 for success else error.
3747 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3748 const struct snd_soc_dapm_widget
*widget
,
3751 struct snd_soc_dapm_widget
*w
;
3755 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3756 for (i
= 0; i
< num
; i
++) {
3757 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3764 mutex_unlock(&dapm
->card
->dapm_mutex
);
3767 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3769 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3770 struct snd_kcontrol
*kcontrol
, int event
)
3772 struct snd_soc_dapm_path
*path
;
3773 struct snd_soc_dai
*source
, *sink
;
3774 struct snd_soc_pcm_runtime
*rtd
= w
->priv
;
3775 const struct snd_soc_pcm_stream
*config
;
3776 struct snd_pcm_substream substream
;
3777 struct snd_pcm_hw_params
*params
= NULL
;
3778 struct snd_pcm_runtime
*runtime
= NULL
;
3782 config
= rtd
->dai_link
->params
+ rtd
->params_select
;
3784 if (WARN_ON(!config
) ||
3785 WARN_ON(list_empty(&w
->edges
[SND_SOC_DAPM_DIR_OUT
]) ||
3786 list_empty(&w
->edges
[SND_SOC_DAPM_DIR_IN
])))
3789 /* Be a little careful as we don't want to overflow the mask array */
3790 if (config
->formats
) {
3791 fmt
= ffs(config
->formats
) - 1;
3793 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3798 /* Currently very limited parameter selection */
3799 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3804 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3806 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3808 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3811 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3812 = config
->channels_min
;
3813 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3814 = config
->channels_max
;
3816 memset(&substream
, 0, sizeof(substream
));
3818 /* Allocate a dummy snd_pcm_runtime for startup() and other ops() */
3819 runtime
= kzalloc(sizeof(*runtime
), GFP_KERNEL
);
3824 substream
.runtime
= runtime
;
3825 substream
.private_data
= rtd
;
3828 case SND_SOC_DAPM_PRE_PMU
:
3829 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3830 snd_soc_dapm_widget_for_each_source_path(w
, path
) {
3831 source
= path
->source
->priv
;
3833 if (source
->driver
->ops
->startup
) {
3834 ret
= source
->driver
->ops
->startup(&substream
,
3837 dev_err(source
->dev
,
3838 "ASoC: startup() failed: %d\n",
3844 ret
= soc_dai_hw_params(&substream
, params
, source
);
3848 dapm_update_dai_unlocked(&substream
, params
, source
);
3851 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3852 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3853 sink
= path
->sink
->priv
;
3855 if (sink
->driver
->ops
->startup
) {
3856 ret
= sink
->driver
->ops
->startup(&substream
,
3860 "ASoC: startup() failed: %d\n",
3866 ret
= soc_dai_hw_params(&substream
, params
, sink
);
3870 dapm_update_dai_unlocked(&substream
, params
, sink
);
3874 case SND_SOC_DAPM_POST_PMU
:
3875 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3876 sink
= path
->sink
->priv
;
3878 ret
= snd_soc_dai_digital_mute(sink
, 0,
3879 SNDRV_PCM_STREAM_PLAYBACK
);
3880 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3882 "ASoC: Failed to unmute: %d\n", ret
);
3887 case SND_SOC_DAPM_PRE_PMD
:
3888 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3889 sink
= path
->sink
->priv
;
3891 ret
= snd_soc_dai_digital_mute(sink
, 1,
3892 SNDRV_PCM_STREAM_PLAYBACK
);
3893 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3895 "ASoC: Failed to mute: %d\n", ret
);
3899 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3900 snd_soc_dapm_widget_for_each_source_path(w
, path
) {
3901 source
= path
->source
->priv
;
3903 if (source
->driver
->ops
->hw_free
)
3904 source
->driver
->ops
->hw_free(&substream
,
3908 if (source
->driver
->ops
->shutdown
)
3909 source
->driver
->ops
->shutdown(&substream
,
3913 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3914 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3915 sink
= path
->sink
->priv
;
3917 if (sink
->driver
->ops
->hw_free
)
3918 sink
->driver
->ops
->hw_free(&substream
, sink
);
3921 if (sink
->driver
->ops
->shutdown
)
3922 sink
->driver
->ops
->shutdown(&substream
, sink
);
3927 WARN(1, "Unknown event %d\n", event
);
3937 static int snd_soc_dapm_dai_link_get(struct snd_kcontrol
*kcontrol
,
3938 struct snd_ctl_elem_value
*ucontrol
)
3940 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
3941 struct snd_soc_pcm_runtime
*rtd
= w
->priv
;
3943 ucontrol
->value
.enumerated
.item
[0] = rtd
->params_select
;
3948 static int snd_soc_dapm_dai_link_put(struct snd_kcontrol
*kcontrol
,
3949 struct snd_ctl_elem_value
*ucontrol
)
3951 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
3952 struct snd_soc_pcm_runtime
*rtd
= w
->priv
;
3954 /* Can't change the config when widget is already powered */
3958 if (ucontrol
->value
.enumerated
.item
[0] == rtd
->params_select
)
3961 if (ucontrol
->value
.enumerated
.item
[0] >= rtd
->dai_link
->num_params
)
3964 rtd
->params_select
= ucontrol
->value
.enumerated
.item
[0];
3970 snd_soc_dapm_free_kcontrol(struct snd_soc_card
*card
,
3971 unsigned long *private_value
,
3973 const char **w_param_text
)
3977 devm_kfree(card
->dev
, (void *)*private_value
);
3982 for (count
= 0 ; count
< num_params
; count
++)
3983 devm_kfree(card
->dev
, (void *)w_param_text
[count
]);
3984 devm_kfree(card
->dev
, w_param_text
);
3987 static struct snd_kcontrol_new
*
3988 snd_soc_dapm_alloc_kcontrol(struct snd_soc_card
*card
,
3990 const struct snd_soc_pcm_stream
*params
,
3991 int num_params
, const char **w_param_text
,
3992 unsigned long *private_value
)
3994 struct soc_enum w_param_enum
[] = {
3995 SOC_ENUM_SINGLE(0, 0, 0, NULL
),
3997 struct snd_kcontrol_new kcontrol_dai_link
[] = {
3998 SOC_ENUM_EXT(NULL
, w_param_enum
[0],
3999 snd_soc_dapm_dai_link_get
,
4000 snd_soc_dapm_dai_link_put
),
4002 struct snd_kcontrol_new
*kcontrol_news
;
4003 const struct snd_soc_pcm_stream
*config
= params
;
4006 for (count
= 0 ; count
< num_params
; count
++) {
4007 if (!config
->stream_name
) {
4008 dev_warn(card
->dapm
.dev
,
4009 "ASoC: anonymous config %d for dai link %s\n",
4011 w_param_text
[count
] =
4012 devm_kasprintf(card
->dev
, GFP_KERNEL
,
4013 "Anonymous Configuration %d",
4016 w_param_text
[count
] = devm_kmemdup(card
->dev
,
4017 config
->stream_name
,
4018 strlen(config
->stream_name
) + 1,
4021 if (!w_param_text
[count
])
4022 goto outfree_w_param
;
4026 w_param_enum
[0].items
= num_params
;
4027 w_param_enum
[0].texts
= w_param_text
;
4030 (unsigned long) devm_kmemdup(card
->dev
,
4031 (void *)(kcontrol_dai_link
[0].private_value
),
4032 sizeof(struct soc_enum
), GFP_KERNEL
);
4033 if (!*private_value
) {
4034 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
4036 goto outfree_w_param
;
4038 kcontrol_dai_link
[0].private_value
= *private_value
;
4039 /* duplicate kcontrol_dai_link on heap so that memory persists */
4040 kcontrol_news
= devm_kmemdup(card
->dev
, &kcontrol_dai_link
[0],
4041 sizeof(struct snd_kcontrol_new
),
4043 if (!kcontrol_news
) {
4044 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
4046 goto outfree_w_param
;
4048 return kcontrol_news
;
4051 snd_soc_dapm_free_kcontrol(card
, private_value
, num_params
, w_param_text
);
4055 static struct snd_soc_dapm_widget
*
4056 snd_soc_dapm_new_dai(struct snd_soc_card
*card
, struct snd_soc_pcm_runtime
*rtd
,
4057 struct snd_soc_dapm_widget
*source
,
4058 struct snd_soc_dapm_widget
*sink
)
4060 struct snd_soc_dapm_widget
template;
4061 struct snd_soc_dapm_widget
*w
;
4062 const char **w_param_text
;
4063 unsigned long private_value
= 0;
4067 link_name
= devm_kasprintf(card
->dev
, GFP_KERNEL
, "%s-%s",
4068 source
->name
, sink
->name
);
4070 return ERR_PTR(-ENOMEM
);
4072 memset(&template, 0, sizeof(template));
4073 template.reg
= SND_SOC_NOPM
;
4074 template.id
= snd_soc_dapm_dai_link
;
4075 template.name
= link_name
;
4076 template.event
= snd_soc_dai_link_event
;
4077 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4078 SND_SOC_DAPM_PRE_PMD
;
4079 template.kcontrol_news
= NULL
;
4081 /* allocate memory for control, only in case of multiple configs */
4082 if (rtd
->dai_link
->num_params
> 1) {
4083 w_param_text
= devm_kcalloc(card
->dev
,
4084 rtd
->dai_link
->num_params
,
4085 sizeof(char *), GFP_KERNEL
);
4086 if (!w_param_text
) {
4091 template.num_kcontrols
= 1;
4092 template.kcontrol_news
=
4093 snd_soc_dapm_alloc_kcontrol(card
,
4095 rtd
->dai_link
->params
,
4096 rtd
->dai_link
->num_params
,
4097 w_param_text
, &private_value
);
4098 if (!template.kcontrol_news
) {
4103 w_param_text
= NULL
;
4105 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
4107 w
= snd_soc_dapm_new_control_unlocked(&card
->dapm
, &template);
4110 goto outfree_kcontrol_news
;
4117 outfree_kcontrol_news
:
4118 devm_kfree(card
->dev
, (void *)template.kcontrol_news
);
4119 snd_soc_dapm_free_kcontrol(card
, &private_value
,
4120 rtd
->dai_link
->num_params
, w_param_text
);
4122 devm_kfree(card
->dev
, link_name
);
4123 return ERR_PTR(ret
);
4126 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
4127 struct snd_soc_dai
*dai
)
4129 struct snd_soc_dapm_widget
template;
4130 struct snd_soc_dapm_widget
*w
;
4132 WARN_ON(dapm
->dev
!= dai
->dev
);
4134 memset(&template, 0, sizeof(template));
4135 template.reg
= SND_SOC_NOPM
;
4137 if (dai
->driver
->playback
.stream_name
) {
4138 template.id
= snd_soc_dapm_dai_in
;
4139 template.name
= dai
->driver
->playback
.stream_name
;
4140 template.sname
= dai
->driver
->playback
.stream_name
;
4142 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
4145 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
4150 dai
->playback_widget
= w
;
4153 if (dai
->driver
->capture
.stream_name
) {
4154 template.id
= snd_soc_dapm_dai_out
;
4155 template.name
= dai
->driver
->capture
.stream_name
;
4156 template.sname
= dai
->driver
->capture
.stream_name
;
4158 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
4161 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
4166 dai
->capture_widget
= w
;
4172 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
4174 struct snd_soc_dapm_widget
*dai_w
, *w
;
4175 struct snd_soc_dapm_widget
*src
, *sink
;
4176 struct snd_soc_dai
*dai
;
4178 /* For each DAI widget... */
4179 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
4180 switch (dai_w
->id
) {
4181 case snd_soc_dapm_dai_in
:
4182 case snd_soc_dapm_dai_out
:
4188 /* let users know there is no DAI to link */
4190 dev_dbg(card
->dev
, "dai widget %s has no DAI\n",
4197 /* ...find all widgets with the same stream and link them */
4198 list_for_each_entry(w
, &card
->widgets
, list
) {
4199 if (w
->dapm
!= dai_w
->dapm
)
4203 case snd_soc_dapm_dai_in
:
4204 case snd_soc_dapm_dai_out
:
4210 if (!w
->sname
|| !strstr(w
->sname
, dai_w
->sname
))
4213 if (dai_w
->id
== snd_soc_dapm_dai_in
) {
4220 dev_dbg(dai
->dev
, "%s -> %s\n", src
->name
, sink
->name
);
4221 snd_soc_dapm_add_path(w
->dapm
, src
, sink
, NULL
, NULL
);
4228 static void dapm_connect_dai_link_widgets(struct snd_soc_card
*card
,
4229 struct snd_soc_pcm_runtime
*rtd
)
4231 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
4232 struct snd_soc_dai
*codec_dai
;
4233 struct snd_soc_dapm_widget
*playback
= NULL
, *capture
= NULL
;
4234 struct snd_soc_dapm_widget
*codec
, *playback_cpu
, *capture_cpu
;
4237 if (rtd
->dai_link
->params
) {
4238 playback_cpu
= cpu_dai
->capture_widget
;
4239 capture_cpu
= cpu_dai
->playback_widget
;
4241 playback
= cpu_dai
->playback_widget
;
4242 capture
= cpu_dai
->capture_widget
;
4243 playback_cpu
= playback
;
4244 capture_cpu
= capture
;
4247 for_each_rtd_codec_dai(rtd
, i
, codec_dai
) {
4249 /* connect BE DAI playback if widgets are valid */
4250 codec
= codec_dai
->playback_widget
;
4252 if (playback_cpu
&& codec
) {
4254 playback
= snd_soc_dapm_new_dai(card
, rtd
,
4257 if (IS_ERR(playback
)) {
4259 "ASoC: Failed to create DAI %s: %ld\n",
4265 snd_soc_dapm_add_path(&card
->dapm
, playback_cpu
,
4266 playback
, NULL
, NULL
);
4269 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
4270 cpu_dai
->component
->name
, playback_cpu
->name
,
4271 codec_dai
->component
->name
, codec
->name
);
4273 snd_soc_dapm_add_path(&card
->dapm
, playback
, codec
,
4278 for_each_rtd_codec_dai(rtd
, i
, codec_dai
) {
4279 /* connect BE DAI capture if widgets are valid */
4280 codec
= codec_dai
->capture_widget
;
4282 if (codec
&& capture_cpu
) {
4284 capture
= snd_soc_dapm_new_dai(card
, rtd
,
4287 if (IS_ERR(capture
)) {
4289 "ASoC: Failed to create DAI %s: %ld\n",
4295 snd_soc_dapm_add_path(&card
->dapm
, capture
,
4296 capture_cpu
, NULL
, NULL
);
4299 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
4300 codec_dai
->component
->name
, codec
->name
,
4301 cpu_dai
->component
->name
, capture_cpu
->name
);
4303 snd_soc_dapm_add_path(&card
->dapm
, codec
, capture
,
4309 static void soc_dapm_dai_stream_event(struct snd_soc_dai
*dai
, int stream
,
4312 struct snd_soc_dapm_widget
*w
;
4315 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4316 w
= dai
->playback_widget
;
4318 w
= dai
->capture_widget
;
4321 dapm_mark_dirty(w
, "stream event");
4323 if (w
->id
== snd_soc_dapm_dai_in
) {
4324 ep
= SND_SOC_DAPM_EP_SOURCE
;
4325 dapm_widget_invalidate_input_paths(w
);
4327 ep
= SND_SOC_DAPM_EP_SINK
;
4328 dapm_widget_invalidate_output_paths(w
);
4332 case SND_SOC_DAPM_STREAM_START
:
4336 case SND_SOC_DAPM_STREAM_STOP
:
4340 case SND_SOC_DAPM_STREAM_SUSPEND
:
4341 case SND_SOC_DAPM_STREAM_RESUME
:
4342 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
4343 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
4349 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card
*card
)
4351 struct snd_soc_pcm_runtime
*rtd
;
4353 /* for each BE DAI link... */
4354 for_each_card_rtds(card
, rtd
) {
4356 * dynamic FE links have no fixed DAI mapping.
4357 * CODEC<->CODEC links have no direct connection.
4359 if (rtd
->dai_link
->dynamic
)
4362 dapm_connect_dai_link_widgets(card
, rtd
);
4366 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
4369 struct snd_soc_dai
*codec_dai
;
4372 soc_dapm_dai_stream_event(rtd
->cpu_dai
, stream
, event
);
4373 for_each_rtd_codec_dai(rtd
, i
, codec_dai
)
4374 soc_dapm_dai_stream_event(codec_dai
, stream
, event
);
4376 dapm_power_widgets(rtd
->card
, event
);
4380 * snd_soc_dapm_stream_event - send a stream event to the dapm core
4381 * @rtd: PCM runtime data
4382 * @stream: stream name
4383 * @event: stream event
4385 * Sends a stream event to the dapm core. The core then makes any
4386 * necessary widget power changes.
4388 * Returns 0 for success else error.
4390 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
4393 struct snd_soc_card
*card
= rtd
->card
;
4395 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4396 soc_dapm_stream_event(rtd
, stream
, event
);
4397 mutex_unlock(&card
->dapm_mutex
);
4401 * snd_soc_dapm_enable_pin_unlocked - enable pin.
4402 * @dapm: DAPM context
4405 * Enables input/output pin and its parents or children widgets iff there is
4406 * a valid audio route and active audio stream.
4408 * Requires external locking.
4410 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4411 * do any widget power switching.
4413 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4416 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
4418 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked
);
4421 * snd_soc_dapm_enable_pin - enable pin.
4422 * @dapm: DAPM context
4425 * Enables input/output pin and its parents or children widgets iff there is
4426 * a valid audio route and active audio stream.
4428 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4429 * do any widget power switching.
4431 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
4435 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4437 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 1);
4439 mutex_unlock(&dapm
->card
->dapm_mutex
);
4443 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
4446 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
4447 * @dapm: DAPM context
4450 * Enables input/output pin regardless of any other state. This is
4451 * intended for use with microphone bias supplies used in microphone
4454 * Requires external locking.
4456 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4457 * do any widget power switching.
4459 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4462 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4465 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4469 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
4470 if (!w
->connected
) {
4472 * w->force does not affect the number of input or output paths,
4473 * so we only have to recheck if w->connected is changed
4475 dapm_widget_invalidate_input_paths(w
);
4476 dapm_widget_invalidate_output_paths(w
);
4480 dapm_mark_dirty(w
, "force enable");
4484 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked
);
4487 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4488 * @dapm: DAPM context
4491 * Enables input/output pin regardless of any other state. This is
4492 * intended for use with microphone bias supplies used in microphone
4495 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4496 * do any widget power switching.
4498 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
4503 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4505 ret
= snd_soc_dapm_force_enable_pin_unlocked(dapm
, pin
);
4507 mutex_unlock(&dapm
->card
->dapm_mutex
);
4511 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
4514 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4515 * @dapm: DAPM context
4518 * Disables input/output pin and its parents or children widgets.
4520 * Requires external locking.
4522 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4523 * do any widget power switching.
4525 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4528 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4530 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked
);
4533 * snd_soc_dapm_disable_pin - disable pin.
4534 * @dapm: DAPM context
4537 * Disables input/output pin and its parents or children widgets.
4539 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4540 * do any widget power switching.
4542 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
4547 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4549 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4551 mutex_unlock(&dapm
->card
->dapm_mutex
);
4555 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
4558 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4559 * @dapm: DAPM context
4562 * Marks the specified pin as being not connected, disabling it along
4563 * any parent or child widgets. At present this is identical to
4564 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4565 * additional things such as disabling controls which only affect
4566 * paths through the pin.
4568 * Requires external locking.
4570 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4571 * do any widget power switching.
4573 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4576 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4578 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked
);
4581 * snd_soc_dapm_nc_pin - permanently disable pin.
4582 * @dapm: DAPM context
4585 * Marks the specified pin as being not connected, disabling it along
4586 * any parent or child widgets. At present this is identical to
4587 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4588 * additional things such as disabling controls which only affect
4589 * paths through the pin.
4591 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4592 * do any widget power switching.
4594 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
4598 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4600 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4602 mutex_unlock(&dapm
->card
->dapm_mutex
);
4606 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
4609 * snd_soc_dapm_get_pin_status - get audio pin status
4610 * @dapm: DAPM context
4611 * @pin: audio signal pin endpoint (or start point)
4613 * Get audio pin status - connected or disconnected.
4615 * Returns 1 for connected otherwise 0.
4617 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
4620 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4623 return w
->connected
;
4627 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
4630 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4631 * @dapm: DAPM context
4632 * @pin: audio signal pin endpoint (or start point)
4634 * Mark the given endpoint or pin as ignoring suspend. When the
4635 * system is disabled a path between two endpoints flagged as ignoring
4636 * suspend will not be disabled. The path must already be enabled via
4637 * normal means at suspend time, it will not be turned on if it was not
4640 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
4643 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
4646 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4650 w
->ignore_suspend
= 1;
4654 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
4657 * snd_soc_dapm_free - free dapm resources
4658 * @dapm: DAPM context
4660 * Free all dapm widgets and resources.
4662 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
4664 dapm_debugfs_cleanup(dapm
);
4665 dapm_free_widgets(dapm
);
4666 list_del(&dapm
->list
);
4668 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
4670 static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context
*dapm
)
4672 struct snd_soc_card
*card
= dapm
->card
;
4673 struct snd_soc_dapm_widget
*w
;
4674 LIST_HEAD(down_list
);
4677 mutex_lock(&card
->dapm_mutex
);
4679 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
4680 if (w
->dapm
!= dapm
)
4683 dapm_seq_insert(w
, &down_list
, false);
4689 /* If there were no widgets to power down we're already in
4693 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
4694 snd_soc_dapm_set_bias_level(dapm
,
4695 SND_SOC_BIAS_PREPARE
);
4696 dapm_seq_run(card
, &down_list
, 0, false);
4697 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
4698 snd_soc_dapm_set_bias_level(dapm
,
4699 SND_SOC_BIAS_STANDBY
);
4702 mutex_unlock(&card
->dapm_mutex
);
4706 * snd_soc_dapm_shutdown - callback for system shutdown
4708 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
4710 struct snd_soc_dapm_context
*dapm
;
4712 list_for_each_entry(dapm
, &card
->dapm_list
, list
) {
4713 if (dapm
!= &card
->dapm
) {
4714 soc_dapm_shutdown_dapm(dapm
);
4715 if (dapm
->bias_level
== SND_SOC_BIAS_STANDBY
)
4716 snd_soc_dapm_set_bias_level(dapm
,
4721 soc_dapm_shutdown_dapm(&card
->dapm
);
4722 if (card
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
4723 snd_soc_dapm_set_bias_level(&card
->dapm
,
4727 /* Module information */
4728 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4729 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
4730 MODULE_LICENSE("GPL");