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
)
688 ret
= snd_soc_component_set_bias_level(dapm
->component
, 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 * Recursively reset the cached number of inputs or outputs for the specified
1133 * widget and all widgets that can be reached via incoming or outcoming paths
1136 static void invalidate_paths_ep(struct snd_soc_dapm_widget
*widget
,
1137 enum snd_soc_dapm_direction dir
)
1139 enum snd_soc_dapm_direction rdir
= SND_SOC_DAPM_DIR_REVERSE(dir
);
1140 struct snd_soc_dapm_path
*path
;
1142 widget
->endpoints
[dir
] = -1;
1144 snd_soc_dapm_widget_for_each_path(widget
, rdir
, path
) {
1145 if (path
->weak
|| path
->is_supply
)
1151 if (path
->connect
) {
1153 invalidate_paths_ep(path
->node
[dir
], dir
);
1160 * Common implementation for is_connected_output_ep() and
1161 * is_connected_input_ep(). The function is inlined since the combined size of
1162 * the two specialized functions is only marginally larger then the size of the
1163 * generic function and at the same time the fast path of the specialized
1164 * functions is significantly smaller than the generic function.
1166 static __always_inline
int is_connected_ep(struct snd_soc_dapm_widget
*widget
,
1167 struct list_head
*list
, enum snd_soc_dapm_direction dir
,
1168 int (*fn
)(struct snd_soc_dapm_widget
*, struct list_head
*,
1169 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*,
1170 enum snd_soc_dapm_direction
)),
1171 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*,
1172 enum snd_soc_dapm_direction
))
1174 enum snd_soc_dapm_direction rdir
= SND_SOC_DAPM_DIR_REVERSE(dir
);
1175 struct snd_soc_dapm_path
*path
;
1178 if (widget
->endpoints
[dir
] >= 0)
1179 return widget
->endpoints
[dir
];
1181 DAPM_UPDATE_STAT(widget
, path_checks
);
1183 /* do we need to add this widget to the list ? */
1185 list_add_tail(&widget
->work_list
, list
);
1187 if (custom_stop_condition
&& custom_stop_condition(widget
, dir
)) {
1189 custom_stop_condition
= NULL
;
1192 if ((widget
->is_ep
& SND_SOC_DAPM_DIR_TO_EP(dir
)) && widget
->connected
) {
1193 widget
->endpoints
[dir
] = snd_soc_dapm_suspend_check(widget
);
1194 return widget
->endpoints
[dir
];
1197 snd_soc_dapm_widget_for_each_path(widget
, rdir
, path
) {
1198 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1200 if (path
->weak
|| path
->is_supply
)
1206 trace_snd_soc_dapm_path(widget
, dir
, path
);
1208 if (path
->connect
) {
1210 con
+= fn(path
->node
[dir
], list
, custom_stop_condition
);
1215 widget
->endpoints
[dir
] = con
;
1221 * Recursively check for a completed path to an active or physically connected
1222 * output widget. Returns number of complete paths.
1224 * Optionally, can be supplied with a function acting as a stopping condition.
1225 * This function takes the dapm widget currently being examined and the walk
1226 * direction as an arguments, it should return true if widgets from that point
1227 * in the graph onwards should not be added to the widget list.
1229 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
1230 struct list_head
*list
,
1231 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*i
,
1232 enum snd_soc_dapm_direction
))
1234 return is_connected_ep(widget
, list
, SND_SOC_DAPM_DIR_OUT
,
1235 is_connected_output_ep
, custom_stop_condition
);
1239 * Recursively check for a completed path to an active or physically connected
1240 * input widget. Returns number of complete paths.
1242 * Optionally, can be supplied with a function acting as a stopping condition.
1243 * This function takes the dapm widget currently being examined and the walk
1244 * direction as an arguments, it should return true if the walk should be
1245 * stopped and false otherwise.
1247 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
1248 struct list_head
*list
,
1249 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*i
,
1250 enum snd_soc_dapm_direction
))
1252 return is_connected_ep(widget
, list
, SND_SOC_DAPM_DIR_IN
,
1253 is_connected_input_ep
, custom_stop_condition
);
1257 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1258 * @dai: the soc DAI.
1259 * @stream: stream direction.
1260 * @list: list of active widgets for this stream.
1261 * @custom_stop_condition: (optional) a function meant to stop the widget graph
1262 * walk based on custom logic.
1264 * Queries DAPM graph as to whether a valid audio stream path exists for
1265 * the initial stream specified by name. This takes into account
1266 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1268 * Optionally, can be supplied with a function acting as a stopping condition.
1269 * This function takes the dapm widget currently being examined and the walk
1270 * direction as an arguments, it should return true if the walk should be
1271 * stopped and false otherwise.
1273 * Returns the number of valid paths or negative error.
1275 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1276 struct snd_soc_dapm_widget_list
**list
,
1277 bool (*custom_stop_condition
)(struct snd_soc_dapm_widget
*,
1278 enum snd_soc_dapm_direction
))
1280 struct snd_soc_card
*card
= dai
->component
->card
;
1281 struct snd_soc_dapm_widget
*w
;
1286 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1288 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1289 w
= dai
->playback_widget
;
1290 invalidate_paths_ep(w
, SND_SOC_DAPM_DIR_OUT
);
1291 paths
= is_connected_output_ep(w
, &widgets
,
1292 custom_stop_condition
);
1294 w
= dai
->capture_widget
;
1295 invalidate_paths_ep(w
, SND_SOC_DAPM_DIR_IN
);
1296 paths
= is_connected_input_ep(w
, &widgets
,
1297 custom_stop_condition
);
1300 /* Drop starting point */
1301 list_del(widgets
.next
);
1303 ret
= dapm_widget_list_create(list
, &widgets
);
1307 trace_snd_soc_dapm_connected(paths
, stream
);
1308 mutex_unlock(&card
->dapm_mutex
);
1314 * Handler for regulator supply widget.
1316 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1317 struct snd_kcontrol
*kcontrol
, int event
)
1321 soc_dapm_async_complete(w
->dapm
);
1323 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1324 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1325 ret
= regulator_allow_bypass(w
->regulator
, false);
1327 dev_warn(w
->dapm
->dev
,
1328 "ASoC: Failed to unbypass %s: %d\n",
1332 return regulator_enable(w
->regulator
);
1334 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1335 ret
= regulator_allow_bypass(w
->regulator
, true);
1337 dev_warn(w
->dapm
->dev
,
1338 "ASoC: Failed to bypass %s: %d\n",
1342 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1345 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1348 * Handler for pinctrl widget.
1350 int dapm_pinctrl_event(struct snd_soc_dapm_widget
*w
,
1351 struct snd_kcontrol
*kcontrol
, int event
)
1353 struct snd_soc_dapm_pinctrl_priv
*priv
= w
->priv
;
1354 struct pinctrl
*p
= w
->pinctrl
;
1355 struct pinctrl_state
*s
;
1360 if (SND_SOC_DAPM_EVENT_ON(event
))
1361 s
= pinctrl_lookup_state(p
, priv
->active_state
);
1363 s
= pinctrl_lookup_state(p
, priv
->sleep_state
);
1368 return pinctrl_select_state(p
, s
);
1370 EXPORT_SYMBOL_GPL(dapm_pinctrl_event
);
1373 * Handler for clock supply widget.
1375 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1376 struct snd_kcontrol
*kcontrol
, int event
)
1381 soc_dapm_async_complete(w
->dapm
);
1383 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1384 return clk_prepare_enable(w
->clk
);
1386 clk_disable_unprepare(w
->clk
);
1392 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1394 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1396 if (w
->power_checked
)
1397 return w
->new_power
;
1402 w
->new_power
= w
->power_check(w
);
1404 w
->power_checked
= true;
1406 return w
->new_power
;
1409 /* Generic check to see if a widget should be powered. */
1410 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1414 DAPM_UPDATE_STAT(w
, power_checks
);
1416 in
= is_connected_input_ep(w
, NULL
, NULL
);
1417 out
= is_connected_output_ep(w
, NULL
, NULL
);
1418 return out
!= 0 && in
!= 0;
1421 /* Check to see if a power supply is needed */
1422 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1424 struct snd_soc_dapm_path
*path
;
1426 DAPM_UPDATE_STAT(w
, power_checks
);
1428 /* Check if one of our outputs is connected */
1429 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
1430 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1435 if (path
->connected
&&
1436 !path
->connected(path
->source
, path
->sink
))
1439 if (dapm_widget_power_check(path
->sink
))
1446 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1448 return w
->connected
;
1451 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1452 struct snd_soc_dapm_widget
*b
,
1457 BUILD_BUG_ON(ARRAY_SIZE(dapm_up_seq
) != SND_SOC_DAPM_TYPE_COUNT
);
1458 BUILD_BUG_ON(ARRAY_SIZE(dapm_down_seq
) != SND_SOC_DAPM_TYPE_COUNT
);
1463 sort
= dapm_down_seq
;
1465 WARN_ONCE(sort
[a
->id
] == 0, "offset a->id %d not initialized\n", a
->id
);
1466 WARN_ONCE(sort
[b
->id
] == 0, "offset b->id %d not initialized\n", b
->id
);
1468 if (sort
[a
->id
] != sort
[b
->id
])
1469 return sort
[a
->id
] - sort
[b
->id
];
1470 if (a
->subseq
!= b
->subseq
) {
1472 return a
->subseq
- b
->subseq
;
1474 return b
->subseq
- a
->subseq
;
1476 if (a
->reg
!= b
->reg
)
1477 return a
->reg
- b
->reg
;
1478 if (a
->dapm
!= b
->dapm
)
1479 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1484 /* Insert a widget in order into a DAPM power sequence. */
1485 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1486 struct list_head
*list
,
1489 struct snd_soc_dapm_widget
*w
;
1491 list_for_each_entry(w
, list
, power_list
)
1492 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1493 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1497 list_add_tail(&new_widget
->power_list
, list
);
1500 static void dapm_seq_check_event(struct snd_soc_card
*card
,
1501 struct snd_soc_dapm_widget
*w
, int event
)
1503 const char *ev_name
;
1507 case SND_SOC_DAPM_PRE_PMU
:
1508 ev_name
= "PRE_PMU";
1511 case SND_SOC_DAPM_POST_PMU
:
1512 ev_name
= "POST_PMU";
1515 case SND_SOC_DAPM_PRE_PMD
:
1516 ev_name
= "PRE_PMD";
1519 case SND_SOC_DAPM_POST_PMD
:
1520 ev_name
= "POST_PMD";
1523 case SND_SOC_DAPM_WILL_PMU
:
1524 ev_name
= "WILL_PMU";
1527 case SND_SOC_DAPM_WILL_PMD
:
1528 ev_name
= "WILL_PMD";
1532 WARN(1, "Unknown event %d\n", event
);
1536 if (w
->new_power
!= power
)
1539 if (w
->event
&& (w
->event_flags
& event
)) {
1540 pop_dbg(w
->dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1542 soc_dapm_async_complete(w
->dapm
);
1543 trace_snd_soc_dapm_widget_event_start(w
, event
);
1544 ret
= w
->event(w
, NULL
, event
);
1545 trace_snd_soc_dapm_widget_event_done(w
, event
);
1547 dev_err(w
->dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1548 ev_name
, w
->name
, ret
);
1552 /* Apply the coalesced changes from a DAPM sequence */
1553 static void dapm_seq_run_coalesced(struct snd_soc_card
*card
,
1554 struct list_head
*pending
)
1556 struct snd_soc_dapm_context
*dapm
;
1557 struct snd_soc_dapm_widget
*w
;
1559 unsigned int value
= 0;
1560 unsigned int mask
= 0;
1562 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
, power_list
);
1566 list_for_each_entry(w
, pending
, power_list
) {
1567 WARN_ON(reg
!= w
->reg
|| dapm
!= w
->dapm
);
1568 w
->power
= w
->new_power
;
1570 mask
|= w
->mask
<< w
->shift
;
1572 value
|= w
->on_val
<< w
->shift
;
1574 value
|= w
->off_val
<< w
->shift
;
1576 pop_dbg(dapm
->dev
, card
->pop_time
,
1577 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1578 w
->name
, reg
, value
, mask
);
1580 /* Check for events */
1581 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMU
);
1582 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMD
);
1586 /* Any widget will do, they should all be updating the
1590 pop_dbg(dapm
->dev
, card
->pop_time
,
1591 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1592 value
, mask
, reg
, card
->pop_time
);
1593 pop_wait(card
->pop_time
);
1594 soc_dapm_update_bits(dapm
, reg
, mask
, value
);
1597 list_for_each_entry(w
, pending
, power_list
) {
1598 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMU
);
1599 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMD
);
1603 /* Apply a DAPM power sequence.
1605 * We walk over a pre-sorted list of widgets to apply power to. In
1606 * order to minimise the number of writes to the device required
1607 * multiple widgets will be updated in a single write where possible.
1608 * Currently anything that requires more than a single write is not
1611 static void dapm_seq_run(struct snd_soc_card
*card
,
1612 struct list_head
*list
, int event
, bool power_up
)
1614 struct snd_soc_dapm_widget
*w
, *n
;
1615 struct snd_soc_dapm_context
*d
;
1618 int cur_subseq
= -1;
1619 int cur_reg
= SND_SOC_NOPM
;
1620 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1627 sort
= dapm_down_seq
;
1629 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1632 /* Do we need to apply any queued changes? */
1633 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1634 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1635 if (!list_empty(&pending
))
1636 dapm_seq_run_coalesced(card
, &pending
);
1638 if (cur_dapm
&& cur_dapm
->component
) {
1639 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1640 if (sort
[i
] == cur_sort
)
1641 snd_soc_component_seq_notifier(
1642 cur_dapm
->component
,
1646 if (cur_dapm
&& w
->dapm
!= cur_dapm
)
1647 soc_dapm_async_complete(cur_dapm
);
1649 INIT_LIST_HEAD(&pending
);
1651 cur_subseq
= INT_MIN
;
1652 cur_reg
= SND_SOC_NOPM
;
1657 case snd_soc_dapm_pre
:
1659 list_for_each_entry_safe_continue(w
, n
, list
,
1662 if (event
== SND_SOC_DAPM_STREAM_START
)
1664 NULL
, SND_SOC_DAPM_PRE_PMU
);
1665 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1667 NULL
, SND_SOC_DAPM_PRE_PMD
);
1670 case snd_soc_dapm_post
:
1672 list_for_each_entry_safe_continue(w
, n
, list
,
1675 if (event
== SND_SOC_DAPM_STREAM_START
)
1677 NULL
, SND_SOC_DAPM_POST_PMU
);
1678 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1680 NULL
, SND_SOC_DAPM_POST_PMD
);
1684 /* Queue it up for application */
1685 cur_sort
= sort
[w
->id
];
1686 cur_subseq
= w
->subseq
;
1689 list_move(&w
->power_list
, &pending
);
1694 dev_err(w
->dapm
->dev
,
1695 "ASoC: Failed to apply widget power: %d\n", ret
);
1698 if (!list_empty(&pending
))
1699 dapm_seq_run_coalesced(card
, &pending
);
1701 if (cur_dapm
&& cur_dapm
->component
) {
1702 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1703 if (sort
[i
] == cur_sort
)
1704 snd_soc_component_seq_notifier(
1705 cur_dapm
->component
,
1709 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1710 soc_dapm_async_complete(d
);
1714 static void dapm_widget_update(struct snd_soc_card
*card
)
1716 struct snd_soc_dapm_update
*update
= card
->update
;
1717 struct snd_soc_dapm_widget_list
*wlist
;
1718 struct snd_soc_dapm_widget
*w
= NULL
;
1722 if (!update
|| !dapm_kcontrol_is_powered(update
->kcontrol
))
1725 wlist
= dapm_kcontrol_get_wlist(update
->kcontrol
);
1727 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1728 w
= wlist
->widgets
[wi
];
1730 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1731 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1733 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1741 ret
= soc_dapm_update_bits(w
->dapm
, update
->reg
, update
->mask
,
1744 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1747 if (update
->has_second_set
) {
1748 ret
= soc_dapm_update_bits(w
->dapm
, update
->reg2
,
1749 update
->mask2
, update
->val2
);
1751 dev_err(w
->dapm
->dev
,
1752 "ASoC: %s DAPM update failed: %d\n",
1756 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1757 w
= wlist
->widgets
[wi
];
1759 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1760 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1762 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1768 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1769 * they're changing state.
1771 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1773 struct snd_soc_dapm_context
*d
= data
;
1776 /* If we're off and we're not supposed to go into STANDBY */
1777 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1778 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1780 pm_runtime_get_sync(d
->dev
);
1782 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1785 "ASoC: Failed to turn on bias: %d\n", ret
);
1788 /* Prepare for a transition to ON or away from ON */
1789 if ((d
->target_bias_level
== SND_SOC_BIAS_ON
&&
1790 d
->bias_level
!= SND_SOC_BIAS_ON
) ||
1791 (d
->target_bias_level
!= SND_SOC_BIAS_ON
&&
1792 d
->bias_level
== SND_SOC_BIAS_ON
)) {
1793 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1796 "ASoC: Failed to prepare bias: %d\n", ret
);
1800 /* Async callback run prior to DAPM sequences - brings to their final
1803 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1805 struct snd_soc_dapm_context
*d
= data
;
1808 /* If we just powered the last thing off drop to standby bias */
1809 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1810 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1811 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1812 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1814 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1818 /* If we're in standby and can support bias off then do that */
1819 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1820 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1821 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1823 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1827 pm_runtime_put(d
->dev
);
1830 /* If we just powered up then move to active bias */
1831 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1832 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1833 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1835 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1840 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1841 bool power
, bool connect
)
1843 /* If a connection is being made or broken then that update
1844 * will have marked the peer dirty, otherwise the widgets are
1845 * not connected and this update has no impact. */
1849 /* If the peer is already in the state we're moving to then we
1850 * won't have an impact on it. */
1851 if (power
!= peer
->power
)
1852 dapm_mark_dirty(peer
, "peer state change");
1855 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1856 struct list_head
*up_list
,
1857 struct list_head
*down_list
)
1859 struct snd_soc_dapm_path
*path
;
1861 if (w
->power
== power
)
1864 trace_snd_soc_dapm_widget_power(w
, power
);
1866 /* If we changed our power state perhaps our neigbours changed
1869 snd_soc_dapm_widget_for_each_source_path(w
, path
)
1870 dapm_widget_set_peer_power(path
->source
, power
, path
->connect
);
1872 /* Supplies can't affect their outputs, only their inputs */
1873 if (!w
->is_supply
) {
1874 snd_soc_dapm_widget_for_each_sink_path(w
, path
)
1875 dapm_widget_set_peer_power(path
->sink
, power
,
1880 dapm_seq_insert(w
, up_list
, true);
1882 dapm_seq_insert(w
, down_list
, false);
1885 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1886 struct list_head
*up_list
,
1887 struct list_head
*down_list
)
1892 case snd_soc_dapm_pre
:
1893 dapm_seq_insert(w
, down_list
, false);
1895 case snd_soc_dapm_post
:
1896 dapm_seq_insert(w
, up_list
, true);
1900 power
= dapm_widget_power_check(w
);
1902 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1907 static bool dapm_idle_bias_off(struct snd_soc_dapm_context
*dapm
)
1909 if (dapm
->idle_bias_off
)
1912 switch (snd_power_get_state(dapm
->card
->snd_card
)) {
1913 case SNDRV_CTL_POWER_D3hot
:
1914 case SNDRV_CTL_POWER_D3cold
:
1915 return dapm
->suspend_bias_off
;
1924 * Scan each dapm widget for complete audio path.
1925 * A complete path is a route that has valid endpoints i.e.:-
1927 * o DAC to output pin.
1928 * o Input pin to ADC.
1929 * o Input pin to Output pin (bypass, sidetone)
1930 * o DAC to ADC (loopback).
1932 static int dapm_power_widgets(struct snd_soc_card
*card
, int event
)
1934 struct snd_soc_dapm_widget
*w
;
1935 struct snd_soc_dapm_context
*d
;
1937 LIST_HEAD(down_list
);
1938 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1939 enum snd_soc_bias_level bias
;
1942 lockdep_assert_held(&card
->dapm_mutex
);
1944 trace_snd_soc_dapm_start(card
);
1946 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1947 if (dapm_idle_bias_off(d
))
1948 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1950 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1955 /* Check which widgets we need to power and store them in
1956 * lists indicating if they should be powered up or down. We
1957 * only check widgets that have been flagged as dirty but note
1958 * that new widgets may be added to the dirty list while we
1961 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1962 dapm_power_one_widget(w
, &up_list
, &down_list
);
1965 list_for_each_entry(w
, &card
->widgets
, list
) {
1967 case snd_soc_dapm_pre
:
1968 case snd_soc_dapm_post
:
1969 /* These widgets always need to be powered */
1972 list_del_init(&w
->dirty
);
1979 /* Supplies and micbiases only bring the
1980 * context up to STANDBY as unless something
1981 * else is active and passing audio they
1982 * generally don't require full power. Signal
1983 * generators are virtual pins and have no
1984 * power impact themselves.
1987 case snd_soc_dapm_siggen
:
1988 case snd_soc_dapm_vmid
:
1990 case snd_soc_dapm_supply
:
1991 case snd_soc_dapm_regulator_supply
:
1992 case snd_soc_dapm_pinctrl
:
1993 case snd_soc_dapm_clock_supply
:
1994 case snd_soc_dapm_micbias
:
1995 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1996 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1999 d
->target_bias_level
= SND_SOC_BIAS_ON
;
2006 /* Force all contexts in the card to the same bias state if
2007 * they're not ground referenced.
2009 bias
= SND_SOC_BIAS_OFF
;
2010 list_for_each_entry(d
, &card
->dapm_list
, list
)
2011 if (d
->target_bias_level
> bias
)
2012 bias
= d
->target_bias_level
;
2013 list_for_each_entry(d
, &card
->dapm_list
, list
)
2014 if (!dapm_idle_bias_off(d
))
2015 d
->target_bias_level
= bias
;
2017 trace_snd_soc_dapm_walk_done(card
);
2019 /* Run card bias changes at first */
2020 dapm_pre_sequence_async(&card
->dapm
, 0);
2021 /* Run other bias changes in parallel */
2022 list_for_each_entry(d
, &card
->dapm_list
, list
) {
2023 if (d
!= &card
->dapm
&& d
->bias_level
!= d
->target_bias_level
)
2024 async_schedule_domain(dapm_pre_sequence_async
, d
,
2027 async_synchronize_full_domain(&async_domain
);
2029 list_for_each_entry(w
, &down_list
, power_list
) {
2030 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMD
);
2033 list_for_each_entry(w
, &up_list
, power_list
) {
2034 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMU
);
2037 /* Power down widgets first; try to avoid amplifying pops. */
2038 dapm_seq_run(card
, &down_list
, event
, false);
2040 dapm_widget_update(card
);
2043 dapm_seq_run(card
, &up_list
, event
, true);
2045 /* Run all the bias changes in parallel */
2046 list_for_each_entry(d
, &card
->dapm_list
, list
) {
2047 if (d
!= &card
->dapm
&& d
->bias_level
!= d
->target_bias_level
)
2048 async_schedule_domain(dapm_post_sequence_async
, d
,
2051 async_synchronize_full_domain(&async_domain
);
2052 /* Run card bias changes at last */
2053 dapm_post_sequence_async(&card
->dapm
, 0);
2055 /* do we need to notify any clients that DAPM event is complete */
2056 list_for_each_entry(d
, &card
->dapm_list
, list
) {
2060 ret
= snd_soc_component_stream_event(d
->component
, event
);
2065 pop_dbg(card
->dev
, card
->pop_time
,
2066 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
2067 pop_wait(card
->pop_time
);
2069 trace_snd_soc_dapm_done(card
);
2074 #ifdef CONFIG_DEBUG_FS
2075 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
2076 char __user
*user_buf
,
2077 size_t count
, loff_t
*ppos
)
2079 struct snd_soc_dapm_widget
*w
= file
->private_data
;
2080 struct snd_soc_card
*card
= w
->dapm
->card
;
2081 enum snd_soc_dapm_direction dir
, rdir
;
2085 struct snd_soc_dapm_path
*p
= NULL
;
2087 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
2091 mutex_lock(&card
->dapm_mutex
);
2093 /* Supply widgets are not handled by is_connected_{input,output}_ep() */
2098 in
= is_connected_input_ep(w
, NULL
, NULL
);
2099 out
= is_connected_output_ep(w
, NULL
, NULL
);
2102 ret
= scnprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
2103 w
->name
, w
->power
? "On" : "Off",
2104 w
->force
? " (forced)" : "", in
, out
);
2107 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
,
2108 " - R%d(0x%x) mask 0x%x",
2109 w
->reg
, w
->reg
, w
->mask
<< w
->shift
);
2111 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
2114 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
2116 w
->active
? "active" : "inactive");
2118 snd_soc_dapm_for_each_direction(dir
) {
2119 rdir
= SND_SOC_DAPM_DIR_REVERSE(dir
);
2120 snd_soc_dapm_widget_for_each_path(w
, dir
, p
) {
2121 if (p
->connected
&& !p
->connected(p
->source
, p
->sink
))
2127 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
,
2128 " %s \"%s\" \"%s\"\n",
2129 (rdir
== SND_SOC_DAPM_DIR_IN
) ? "in" : "out",
2130 p
->name
? p
->name
: "static",
2131 p
->node
[rdir
]->name
);
2135 mutex_unlock(&card
->dapm_mutex
);
2137 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
2143 static const struct file_operations dapm_widget_power_fops
= {
2144 .open
= simple_open
,
2145 .read
= dapm_widget_power_read_file
,
2146 .llseek
= default_llseek
,
2149 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
2150 size_t count
, loff_t
*ppos
)
2152 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
2155 switch (dapm
->bias_level
) {
2156 case SND_SOC_BIAS_ON
:
2159 case SND_SOC_BIAS_PREPARE
:
2160 level
= "Prepare\n";
2162 case SND_SOC_BIAS_STANDBY
:
2163 level
= "Standby\n";
2165 case SND_SOC_BIAS_OFF
:
2169 WARN(1, "Unknown bias_level %d\n", dapm
->bias_level
);
2170 level
= "Unknown\n";
2174 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
2178 static const struct file_operations dapm_bias_fops
= {
2179 .open
= simple_open
,
2180 .read
= dapm_bias_read_file
,
2181 .llseek
= default_llseek
,
2184 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2185 struct dentry
*parent
)
2187 if (!parent
|| IS_ERR(parent
))
2190 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
2192 debugfs_create_file("bias_level", 0444, dapm
->debugfs_dapm
, dapm
,
2196 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2198 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
2200 if (!dapm
->debugfs_dapm
|| !w
->name
)
2203 debugfs_create_file(w
->name
, 0444, dapm
->debugfs_dapm
, w
,
2204 &dapm_widget_power_fops
);
2207 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2209 debugfs_remove_recursive(dapm
->debugfs_dapm
);
2210 dapm
->debugfs_dapm
= NULL
;
2214 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2215 struct dentry
*parent
)
2219 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2223 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2230 * soc_dapm_connect_path() - Connects or disconnects a path
2231 * @path: The path to update
2232 * @connect: The new connect state of the path. True if the path is connected,
2233 * false if it is disconnected.
2234 * @reason: The reason why the path changed (for debugging only)
2236 static void soc_dapm_connect_path(struct snd_soc_dapm_path
*path
,
2237 bool connect
, const char *reason
)
2239 if (path
->connect
== connect
)
2242 path
->connect
= connect
;
2243 dapm_mark_dirty(path
->source
, reason
);
2244 dapm_mark_dirty(path
->sink
, reason
);
2245 dapm_path_invalidate(path
);
2248 /* test and update the power status of a mux widget */
2249 static int soc_dapm_mux_update_power(struct snd_soc_card
*card
,
2250 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
2252 struct snd_soc_dapm_path
*path
;
2256 lockdep_assert_held(&card
->dapm_mutex
);
2258 /* find dapm widget path assoc with kcontrol */
2259 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2261 /* we now need to match the string in the enum to the path */
2262 if (e
&& !(strcmp(path
->name
, e
->texts
[mux
])))
2267 soc_dapm_connect_path(path
, connect
, "mux update");
2271 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2276 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context
*dapm
,
2277 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
,
2278 struct snd_soc_dapm_update
*update
)
2280 struct snd_soc_card
*card
= dapm
->card
;
2283 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2284 card
->update
= update
;
2285 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
2286 card
->update
= NULL
;
2287 mutex_unlock(&card
->dapm_mutex
);
2289 soc_dpcm_runtime_update(card
);
2292 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
2294 /* test and update the power status of a mixer or switch widget */
2295 static int soc_dapm_mixer_update_power(struct snd_soc_card
*card
,
2296 struct snd_kcontrol
*kcontrol
,
2297 int connect
, int rconnect
)
2299 struct snd_soc_dapm_path
*path
;
2302 lockdep_assert_held(&card
->dapm_mutex
);
2304 /* find dapm widget path assoc with kcontrol */
2305 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2307 * Ideally this function should support any number of
2308 * paths and channels. But since kcontrols only come
2309 * in mono and stereo variants, we are limited to 2
2312 * The following code assumes for stereo controls the
2313 * first path (when 'found == 0') is the left channel,
2314 * and all remaining paths (when 'found == 1') are the
2317 * A stereo control is signified by a valid 'rconnect'
2318 * value, either 0 for unconnected, or >= 0 for connected.
2319 * This is chosen instead of using snd_soc_volsw_is_stereo,
2320 * so that the behavior of snd_soc_dapm_mixer_update_power
2321 * doesn't change even when the kcontrol passed in is
2324 * It passes 'connect' as the path connect status for
2325 * the left channel, and 'rconnect' for the right
2328 if (found
&& rconnect
>= 0)
2329 soc_dapm_connect_path(path
, rconnect
, "mixer update");
2331 soc_dapm_connect_path(path
, connect
, "mixer update");
2336 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2341 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context
*dapm
,
2342 struct snd_kcontrol
*kcontrol
, int connect
,
2343 struct snd_soc_dapm_update
*update
)
2345 struct snd_soc_card
*card
= dapm
->card
;
2348 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2349 card
->update
= update
;
2350 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
, -1);
2351 card
->update
= NULL
;
2352 mutex_unlock(&card
->dapm_mutex
);
2354 soc_dpcm_runtime_update(card
);
2357 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2359 static ssize_t
dapm_widget_show_component(struct snd_soc_component
*cmpnt
,
2362 struct snd_soc_dapm_context
*dapm
= snd_soc_component_get_dapm(cmpnt
);
2363 struct snd_soc_dapm_widget
*w
;
2365 char *state
= "not set";
2367 /* card won't be set for the dummy component, as a spot fix
2368 * we're checking for that case specifically here but in future
2369 * we will ensure that the dummy component looks like others.
2374 list_for_each_entry(w
, &cmpnt
->card
->widgets
, list
) {
2375 if (w
->dapm
!= dapm
)
2378 /* only display widgets that burn power */
2380 case snd_soc_dapm_hp
:
2381 case snd_soc_dapm_mic
:
2382 case snd_soc_dapm_spk
:
2383 case snd_soc_dapm_line
:
2384 case snd_soc_dapm_micbias
:
2385 case snd_soc_dapm_dac
:
2386 case snd_soc_dapm_adc
:
2387 case snd_soc_dapm_pga
:
2388 case snd_soc_dapm_effect
:
2389 case snd_soc_dapm_out_drv
:
2390 case snd_soc_dapm_mixer
:
2391 case snd_soc_dapm_mixer_named_ctl
:
2392 case snd_soc_dapm_supply
:
2393 case snd_soc_dapm_regulator_supply
:
2394 case snd_soc_dapm_pinctrl
:
2395 case snd_soc_dapm_clock_supply
:
2397 count
+= sprintf(buf
+ count
, "%s: %s\n",
2398 w
->name
, w
->power
? "On":"Off");
2405 switch (snd_soc_dapm_get_bias_level(dapm
)) {
2406 case SND_SOC_BIAS_ON
:
2409 case SND_SOC_BIAS_PREPARE
:
2412 case SND_SOC_BIAS_STANDBY
:
2415 case SND_SOC_BIAS_OFF
:
2419 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2424 /* show dapm widget status in sys fs */
2425 static ssize_t
dapm_widget_show(struct device
*dev
,
2426 struct device_attribute
*attr
, char *buf
)
2428 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2429 struct snd_soc_dai
*codec_dai
;
2432 mutex_lock(&rtd
->card
->dapm_mutex
);
2434 for_each_rtd_codec_dai(rtd
, i
, codec_dai
) {
2435 struct snd_soc_component
*cmpnt
= codec_dai
->component
;
2437 count
+= dapm_widget_show_component(cmpnt
, buf
+ count
);
2440 mutex_unlock(&rtd
->card
->dapm_mutex
);
2445 static DEVICE_ATTR_RO(dapm_widget
);
2447 struct attribute
*soc_dapm_dev_attrs
[] = {
2448 &dev_attr_dapm_widget
.attr
,
2452 static void dapm_free_path(struct snd_soc_dapm_path
*path
)
2454 list_del(&path
->list_node
[SND_SOC_DAPM_DIR_IN
]);
2455 list_del(&path
->list_node
[SND_SOC_DAPM_DIR_OUT
]);
2456 list_del(&path
->list_kcontrol
);
2457 list_del(&path
->list
);
2461 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget
*w
)
2463 struct snd_soc_dapm_path
*p
, *next_p
;
2464 enum snd_soc_dapm_direction dir
;
2468 * remove source and sink paths associated to this widget.
2469 * While removing the path, remove reference to it from both
2470 * source and sink widgets so that path is removed only once.
2472 snd_soc_dapm_for_each_direction(dir
) {
2473 snd_soc_dapm_widget_for_each_path_safe(w
, dir
, p
, next_p
)
2477 kfree(w
->kcontrols
);
2478 kfree_const(w
->name
);
2479 kfree_const(w
->sname
);
2483 void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context
*dapm
)
2485 dapm
->path_sink_cache
.widget
= NULL
;
2486 dapm
->path_source_cache
.widget
= NULL
;
2489 /* free all dapm widgets and resources */
2490 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2492 struct snd_soc_dapm_widget
*w
, *next_w
;
2494 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2495 if (w
->dapm
!= dapm
)
2497 snd_soc_dapm_free_widget(w
);
2499 snd_soc_dapm_reset_cache(dapm
);
2502 static struct snd_soc_dapm_widget
*dapm_find_widget(
2503 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2504 bool search_other_contexts
)
2506 struct snd_soc_dapm_widget
*w
;
2507 struct snd_soc_dapm_widget
*fallback
= NULL
;
2509 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2510 if (!strcmp(w
->name
, pin
)) {
2511 if (w
->dapm
== dapm
)
2518 if (search_other_contexts
)
2524 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2525 const char *pin
, int status
)
2527 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2529 dapm_assert_locked(dapm
);
2532 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2536 if (w
->connected
!= status
) {
2537 dapm_mark_dirty(w
, "pin configuration");
2538 dapm_widget_invalidate_input_paths(w
);
2539 dapm_widget_invalidate_output_paths(w
);
2542 w
->connected
= status
;
2550 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2551 * @dapm: DAPM context
2553 * Walks all dapm audio paths and powers widgets according to their
2554 * stream or path usage.
2556 * Requires external locking.
2558 * Returns 0 for success.
2560 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context
*dapm
)
2563 * Suppress early reports (eg, jacks syncing their state) to avoid
2564 * silly DAPM runs during card startup.
2566 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2569 return dapm_power_widgets(dapm
->card
, SND_SOC_DAPM_STREAM_NOP
);
2571 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked
);
2574 * snd_soc_dapm_sync - scan and power dapm paths
2575 * @dapm: DAPM context
2577 * Walks all dapm audio paths and powers widgets according to their
2578 * stream or path usage.
2580 * Returns 0 for success.
2582 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2586 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2587 ret
= snd_soc_dapm_sync_unlocked(dapm
);
2588 mutex_unlock(&dapm
->card
->dapm_mutex
);
2591 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2593 static int dapm_update_dai_chan(struct snd_soc_dapm_path
*p
,
2594 struct snd_soc_dapm_widget
*w
,
2598 case snd_soc_dapm_aif_out
:
2599 case snd_soc_dapm_aif_in
:
2605 dev_dbg(w
->dapm
->dev
, "%s DAI route %s -> %s\n",
2606 w
->channel
< channels
? "Connecting" : "Disconnecting",
2607 p
->source
->name
, p
->sink
->name
);
2609 if (w
->channel
< channels
)
2610 soc_dapm_connect_path(p
, true, "dai update");
2612 soc_dapm_connect_path(p
, false, "dai update");
2617 static int dapm_update_dai_unlocked(struct snd_pcm_substream
*substream
,
2618 struct snd_pcm_hw_params
*params
,
2619 struct snd_soc_dai
*dai
)
2621 int dir
= substream
->stream
;
2622 int channels
= params_channels(params
);
2623 struct snd_soc_dapm_path
*p
;
2624 struct snd_soc_dapm_widget
*w
;
2627 if (dir
== SNDRV_PCM_STREAM_PLAYBACK
)
2628 w
= dai
->playback_widget
;
2630 w
= dai
->capture_widget
;
2635 dev_dbg(dai
->dev
, "Update DAI routes for %s %s\n", dai
->name
,
2636 dir
== SNDRV_PCM_STREAM_PLAYBACK
? "playback" : "capture");
2638 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
2639 ret
= dapm_update_dai_chan(p
, p
->sink
, channels
);
2644 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
2645 ret
= dapm_update_dai_chan(p
, p
->source
, channels
);
2653 int snd_soc_dapm_update_dai(struct snd_pcm_substream
*substream
,
2654 struct snd_pcm_hw_params
*params
,
2655 struct snd_soc_dai
*dai
)
2657 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
2660 mutex_lock_nested(&rtd
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2661 ret
= dapm_update_dai_unlocked(substream
, params
, dai
);
2662 mutex_unlock(&rtd
->card
->dapm_mutex
);
2666 EXPORT_SYMBOL_GPL(snd_soc_dapm_update_dai
);
2669 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2670 * @w: The widget for which to update the flags
2672 * Some widgets have a dynamic category which depends on which neighbors they
2673 * are connected to. This function update the category for these widgets.
2675 * This function must be called whenever a path is added or removed to a widget.
2677 static void dapm_update_widget_flags(struct snd_soc_dapm_widget
*w
)
2679 enum snd_soc_dapm_direction dir
;
2680 struct snd_soc_dapm_path
*p
;
2684 case snd_soc_dapm_input
:
2685 /* On a fully routed card an input is never a source */
2686 if (w
->dapm
->card
->fully_routed
)
2688 ep
= SND_SOC_DAPM_EP_SOURCE
;
2689 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
2690 if (p
->source
->id
== snd_soc_dapm_micbias
||
2691 p
->source
->id
== snd_soc_dapm_mic
||
2692 p
->source
->id
== snd_soc_dapm_line
||
2693 p
->source
->id
== snd_soc_dapm_output
) {
2699 case snd_soc_dapm_output
:
2700 /* On a fully routed card a output is never a sink */
2701 if (w
->dapm
->card
->fully_routed
)
2703 ep
= SND_SOC_DAPM_EP_SINK
;
2704 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
2705 if (p
->sink
->id
== snd_soc_dapm_spk
||
2706 p
->sink
->id
== snd_soc_dapm_hp
||
2707 p
->sink
->id
== snd_soc_dapm_line
||
2708 p
->sink
->id
== snd_soc_dapm_input
) {
2714 case snd_soc_dapm_line
:
2716 snd_soc_dapm_for_each_direction(dir
) {
2717 if (!list_empty(&w
->edges
[dir
]))
2718 ep
|= SND_SOC_DAPM_DIR_TO_EP(dir
);
2728 static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context
*dapm
,
2729 struct snd_soc_dapm_widget
*source
, struct snd_soc_dapm_widget
*sink
,
2730 const char *control
)
2732 bool dynamic_source
= false;
2733 bool dynamic_sink
= false;
2738 switch (source
->id
) {
2739 case snd_soc_dapm_demux
:
2740 dynamic_source
= true;
2747 case snd_soc_dapm_mux
:
2748 case snd_soc_dapm_switch
:
2749 case snd_soc_dapm_mixer
:
2750 case snd_soc_dapm_mixer_named_ctl
:
2751 dynamic_sink
= true;
2757 if (dynamic_source
&& dynamic_sink
) {
2759 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n",
2760 source
->name
, control
, sink
->name
);
2762 } else if (!dynamic_source
&& !dynamic_sink
) {
2764 "Control not supported for path %s -> [%s] -> %s\n",
2765 source
->name
, control
, sink
->name
);
2772 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
2773 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
2774 const char *control
,
2775 int (*connected
)(struct snd_soc_dapm_widget
*source
,
2776 struct snd_soc_dapm_widget
*sink
))
2778 struct snd_soc_dapm_widget
*widgets
[2];
2779 enum snd_soc_dapm_direction dir
;
2780 struct snd_soc_dapm_path
*path
;
2783 if (wsink
->is_supply
&& !wsource
->is_supply
) {
2785 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n",
2786 wsource
->name
, wsink
->name
);
2790 if (connected
&& !wsource
->is_supply
) {
2792 "connected() callback only supported for supply widgets (%s -> %s)\n",
2793 wsource
->name
, wsink
->name
);
2797 if (wsource
->is_supply
&& control
) {
2799 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n",
2800 wsource
->name
, control
, wsink
->name
);
2804 ret
= snd_soc_dapm_check_dynamic_path(dapm
, wsource
, wsink
, control
);
2808 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2812 path
->node
[SND_SOC_DAPM_DIR_IN
] = wsource
;
2813 path
->node
[SND_SOC_DAPM_DIR_OUT
] = wsink
;
2814 widgets
[SND_SOC_DAPM_DIR_IN
] = wsource
;
2815 widgets
[SND_SOC_DAPM_DIR_OUT
] = wsink
;
2817 path
->connected
= connected
;
2818 INIT_LIST_HEAD(&path
->list
);
2819 INIT_LIST_HEAD(&path
->list_kcontrol
);
2821 if (wsource
->is_supply
|| wsink
->is_supply
)
2822 path
->is_supply
= 1;
2824 /* connect static paths */
2825 if (control
== NULL
) {
2828 switch (wsource
->id
) {
2829 case snd_soc_dapm_demux
:
2830 ret
= dapm_connect_mux(dapm
, path
, control
, wsource
);
2838 switch (wsink
->id
) {
2839 case snd_soc_dapm_mux
:
2840 ret
= dapm_connect_mux(dapm
, path
, control
, wsink
);
2844 case snd_soc_dapm_switch
:
2845 case snd_soc_dapm_mixer
:
2846 case snd_soc_dapm_mixer_named_ctl
:
2847 ret
= dapm_connect_mixer(dapm
, path
, control
);
2856 list_add(&path
->list
, &dapm
->card
->paths
);
2857 snd_soc_dapm_for_each_direction(dir
)
2858 list_add(&path
->list_node
[dir
], &widgets
[dir
]->edges
[dir
]);
2860 snd_soc_dapm_for_each_direction(dir
) {
2861 dapm_update_widget_flags(widgets
[dir
]);
2862 dapm_mark_dirty(widgets
[dir
], "Route added");
2865 if (dapm
->card
->instantiated
&& path
->connect
)
2866 dapm_path_invalidate(path
);
2874 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2875 const struct snd_soc_dapm_route
*route
)
2877 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2878 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2881 char prefixed_sink
[80];
2882 char prefixed_source
[80];
2884 unsigned int sink_ref
= 0;
2885 unsigned int source_ref
= 0;
2888 prefix
= soc_dapm_prefix(dapm
);
2890 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2891 prefix
, route
->sink
);
2892 sink
= prefixed_sink
;
2893 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2894 prefix
, route
->source
);
2895 source
= prefixed_source
;
2898 source
= route
->source
;
2901 wsource
= dapm_wcache_lookup(&dapm
->path_source_cache
, source
);
2902 wsink
= dapm_wcache_lookup(&dapm
->path_sink_cache
, sink
);
2904 if (wsink
&& wsource
)
2908 * find src and dest widgets over all widgets but favor a widget from
2909 * current DAPM context
2911 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2912 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2914 if (w
->dapm
== dapm
) {
2922 "ASoC: sink widget %s overwritten\n",
2926 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2928 if (w
->dapm
== dapm
) {
2936 "ASoC: source widget %s overwritten\n",
2940 /* use widget from another DAPM context if not found from this */
2946 if (wsource
== NULL
) {
2947 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2951 if (wsink
== NULL
) {
2952 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2958 dapm_wcache_update(&dapm
->path_sink_cache
, wsink
);
2959 dapm_wcache_update(&dapm
->path_source_cache
, wsource
);
2961 ret
= snd_soc_dapm_add_path(dapm
, wsource
, wsink
, route
->control
,
2968 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2969 source
, route
->control
, sink
);
2973 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2974 const struct snd_soc_dapm_route
*route
)
2976 struct snd_soc_dapm_widget
*wsource
, *wsink
;
2977 struct snd_soc_dapm_path
*path
, *p
;
2980 char prefixed_sink
[80];
2981 char prefixed_source
[80];
2984 if (route
->control
) {
2986 "ASoC: Removal of routes with controls not supported\n");
2990 prefix
= soc_dapm_prefix(dapm
);
2992 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2993 prefix
, route
->sink
);
2994 sink
= prefixed_sink
;
2995 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2996 prefix
, route
->source
);
2997 source
= prefixed_source
;
3000 source
= route
->source
;
3004 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
3005 if (strcmp(p
->source
->name
, source
) != 0)
3007 if (strcmp(p
->sink
->name
, sink
) != 0)
3014 wsource
= path
->source
;
3017 dapm_mark_dirty(wsource
, "Route removed");
3018 dapm_mark_dirty(wsink
, "Route removed");
3020 dapm_path_invalidate(path
);
3022 dapm_free_path(path
);
3024 /* Update any path related flags */
3025 dapm_update_widget_flags(wsource
);
3026 dapm_update_widget_flags(wsink
);
3028 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
3036 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
3037 * @dapm: DAPM context
3038 * @route: audio routes
3039 * @num: number of routes
3041 * Connects 2 dapm widgets together via a named audio path. The sink is
3042 * the widget receiving the audio signal, whilst the source is the sender
3043 * of the audio signal.
3045 * Returns 0 for success else error. On error all resources can be freed
3046 * with a call to snd_soc_card_free().
3048 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
3049 const struct snd_soc_dapm_route
*route
, int num
)
3053 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3054 for (i
= 0; i
< num
; i
++) {
3055 r
= snd_soc_dapm_add_route(dapm
, route
);
3057 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
3059 route
->control
? route
->control
: "direct",
3065 mutex_unlock(&dapm
->card
->dapm_mutex
);
3069 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
3072 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
3073 * @dapm: DAPM context
3074 * @route: audio routes
3075 * @num: number of routes
3077 * Removes routes from the DAPM context.
3079 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
3080 const struct snd_soc_dapm_route
*route
, int num
)
3084 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3085 for (i
= 0; i
< num
; i
++) {
3086 snd_soc_dapm_del_route(dapm
, route
);
3089 mutex_unlock(&dapm
->card
->dapm_mutex
);
3093 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
3095 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
3096 const struct snd_soc_dapm_route
*route
)
3098 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
3101 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
3104 struct snd_soc_dapm_path
*path
;
3108 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
3114 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
3119 if (route
->control
|| route
->connected
)
3120 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
3121 route
->source
, route
->sink
);
3123 snd_soc_dapm_widget_for_each_sink_path(source
, path
) {
3124 if (path
->sink
== sink
) {
3131 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
3132 route
->source
, route
->sink
);
3134 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
3135 count
, route
->source
, route
->sink
);
3141 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
3142 * @dapm: DAPM context
3143 * @route: audio routes
3144 * @num: number of routes
3146 * Mark existing routes matching those specified in the passed array
3147 * as being weak, meaning that they are ignored for the purpose of
3148 * power decisions. The main intended use case is for sidetone paths
3149 * which couple audio between other independent paths if they are both
3150 * active in order to make the combination work better at the user
3151 * level but which aren't intended to be "used".
3153 * Note that CODEC drivers should not use this as sidetone type paths
3154 * can frequently also be used as bypass paths.
3156 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
3157 const struct snd_soc_dapm_route
*route
, int num
)
3162 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3163 for (i
= 0; i
< num
; i
++) {
3164 err
= snd_soc_dapm_weak_route(dapm
, route
);
3169 mutex_unlock(&dapm
->card
->dapm_mutex
);
3173 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
3176 * snd_soc_dapm_new_widgets - add new dapm widgets
3177 * @card: card to be checked for new dapm widgets
3179 * Checks the codec for any new dapm widgets and creates them if found.
3181 * Returns 0 for success.
3183 int snd_soc_dapm_new_widgets(struct snd_soc_card
*card
)
3185 struct snd_soc_dapm_widget
*w
;
3188 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3190 list_for_each_entry(w
, &card
->widgets
, list
)
3195 if (w
->num_kcontrols
) {
3196 w
->kcontrols
= kcalloc(w
->num_kcontrols
,
3197 sizeof(struct snd_kcontrol
*),
3199 if (!w
->kcontrols
) {
3200 mutex_unlock(&card
->dapm_mutex
);
3206 case snd_soc_dapm_switch
:
3207 case snd_soc_dapm_mixer
:
3208 case snd_soc_dapm_mixer_named_ctl
:
3211 case snd_soc_dapm_mux
:
3212 case snd_soc_dapm_demux
:
3215 case snd_soc_dapm_pga
:
3216 case snd_soc_dapm_effect
:
3217 case snd_soc_dapm_out_drv
:
3220 case snd_soc_dapm_dai_link
:
3221 dapm_new_dai_link(w
);
3227 /* Read the initial power state from the device */
3229 soc_dapm_read(w
->dapm
, w
->reg
, &val
);
3230 val
= val
>> w
->shift
;
3232 if (val
== w
->on_val
)
3238 dapm_mark_dirty(w
, "new widget");
3239 dapm_debugfs_add_widget(w
);
3242 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
3243 mutex_unlock(&card
->dapm_mutex
);
3246 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
3249 * snd_soc_dapm_get_volsw - dapm mixer get callback
3250 * @kcontrol: mixer control
3251 * @ucontrol: control element information
3253 * Callback to get the value of a dapm mixer control.
3255 * Returns 0 for success.
3257 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
3258 struct snd_ctl_elem_value
*ucontrol
)
3260 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3261 struct snd_soc_card
*card
= dapm
->card
;
3262 struct soc_mixer_control
*mc
=
3263 (struct soc_mixer_control
*)kcontrol
->private_value
;
3265 unsigned int shift
= mc
->shift
;
3267 unsigned int width
= fls(max
);
3268 unsigned int mask
= (1 << fls(max
)) - 1;
3269 unsigned int invert
= mc
->invert
;
3270 unsigned int reg_val
, val
, rval
= 0;
3273 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3274 if (dapm_kcontrol_is_powered(kcontrol
) && reg
!= SND_SOC_NOPM
) {
3275 ret
= soc_dapm_read(dapm
, reg
, ®_val
);
3276 val
= (reg_val
>> shift
) & mask
;
3278 if (ret
== 0 && reg
!= mc
->rreg
)
3279 ret
= soc_dapm_read(dapm
, mc
->rreg
, ®_val
);
3281 if (snd_soc_volsw_is_stereo(mc
))
3282 rval
= (reg_val
>> mc
->rshift
) & mask
;
3284 reg_val
= dapm_kcontrol_get_value(kcontrol
);
3285 val
= reg_val
& mask
;
3287 if (snd_soc_volsw_is_stereo(mc
))
3288 rval
= (reg_val
>> width
) & mask
;
3290 mutex_unlock(&card
->dapm_mutex
);
3296 ucontrol
->value
.integer
.value
[0] = max
- val
;
3298 ucontrol
->value
.integer
.value
[0] = val
;
3300 if (snd_soc_volsw_is_stereo(mc
)) {
3302 ucontrol
->value
.integer
.value
[1] = max
- rval
;
3304 ucontrol
->value
.integer
.value
[1] = rval
;
3309 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
3312 * snd_soc_dapm_put_volsw - dapm mixer set callback
3313 * @kcontrol: mixer control
3314 * @ucontrol: control element information
3316 * Callback to set the value of a dapm mixer control.
3318 * Returns 0 for success.
3320 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
3321 struct snd_ctl_elem_value
*ucontrol
)
3323 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3324 struct snd_soc_card
*card
= dapm
->card
;
3325 struct soc_mixer_control
*mc
=
3326 (struct soc_mixer_control
*)kcontrol
->private_value
;
3328 unsigned int shift
= mc
->shift
;
3330 unsigned int width
= fls(max
);
3331 unsigned int mask
= (1 << width
) - 1;
3332 unsigned int invert
= mc
->invert
;
3333 unsigned int val
, rval
= 0;
3334 int connect
, rconnect
= -1, change
, reg_change
= 0;
3335 struct snd_soc_dapm_update update
= {};
3338 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
3344 if (snd_soc_volsw_is_stereo(mc
)) {
3345 rval
= (ucontrol
->value
.integer
.value
[1] & mask
);
3351 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3353 /* This assumes field width < (bits in unsigned int / 2) */
3354 if (width
> sizeof(unsigned int) * 8 / 2)
3356 "ASoC: control %s field width limit exceeded\n",
3358 change
= dapm_kcontrol_set_value(kcontrol
, val
| (rval
<< width
));
3360 if (reg
!= SND_SOC_NOPM
) {
3362 rval
= rval
<< mc
->rshift
;
3364 reg_change
= soc_dapm_test_bits(dapm
, reg
, mask
<< shift
, val
);
3366 if (snd_soc_volsw_is_stereo(mc
))
3367 reg_change
|= soc_dapm_test_bits(dapm
, mc
->rreg
,
3372 if (change
|| reg_change
) {
3374 if (snd_soc_volsw_is_stereo(mc
)) {
3375 update
.has_second_set
= true;
3376 update
.reg2
= mc
->rreg
;
3377 update
.mask2
= mask
<< mc
->rshift
;
3380 update
.kcontrol
= kcontrol
;
3382 update
.mask
= mask
<< shift
;
3384 card
->update
= &update
;
3386 change
|= reg_change
;
3388 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
,
3391 card
->update
= NULL
;
3394 mutex_unlock(&card
->dapm_mutex
);
3397 soc_dpcm_runtime_update(card
);
3401 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
3404 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3405 * @kcontrol: mixer control
3406 * @ucontrol: control element information
3408 * Callback to get the value of a dapm enumerated double mixer control.
3410 * Returns 0 for success.
3412 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
3413 struct snd_ctl_elem_value
*ucontrol
)
3415 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3416 struct snd_soc_card
*card
= dapm
->card
;
3417 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3418 unsigned int reg_val
, val
;
3420 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3421 if (e
->reg
!= SND_SOC_NOPM
&& dapm_kcontrol_is_powered(kcontrol
)) {
3422 int ret
= soc_dapm_read(dapm
, e
->reg
, ®_val
);
3424 mutex_unlock(&card
->dapm_mutex
);
3428 reg_val
= dapm_kcontrol_get_value(kcontrol
);
3430 mutex_unlock(&card
->dapm_mutex
);
3432 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
3433 ucontrol
->value
.enumerated
.item
[0] = snd_soc_enum_val_to_item(e
, val
);
3434 if (e
->shift_l
!= e
->shift_r
) {
3435 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
3436 val
= snd_soc_enum_val_to_item(e
, val
);
3437 ucontrol
->value
.enumerated
.item
[1] = val
;
3442 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
3444 static int __snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
3445 struct snd_ctl_elem_value
*ucontrol
, int locked
)
3447 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3448 struct snd_soc_card
*card
= dapm
->card
;
3449 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3450 unsigned int *item
= ucontrol
->value
.enumerated
.item
;
3451 unsigned int val
, change
, reg_change
= 0;
3453 struct snd_soc_dapm_update update
= {};
3456 if (item
[0] >= e
->items
)
3459 val
= snd_soc_enum_item_to_val(e
, item
[0]) << e
->shift_l
;
3460 mask
= e
->mask
<< e
->shift_l
;
3461 if (e
->shift_l
!= e
->shift_r
) {
3462 if (item
[1] > e
->items
)
3464 val
|= snd_soc_enum_item_to_val(e
, item
[1]) << e
->shift_r
;
3465 mask
|= e
->mask
<< e
->shift_r
;
3469 mutex_lock_nested(&card
->dapm_mutex
,
3470 SND_SOC_DAPM_CLASS_RUNTIME
);
3472 change
= dapm_kcontrol_set_value(kcontrol
, val
);
3474 if (e
->reg
!= SND_SOC_NOPM
)
3475 reg_change
= soc_dapm_test_bits(dapm
, e
->reg
, mask
, val
);
3477 if (change
|| reg_change
) {
3479 update
.kcontrol
= kcontrol
;
3480 update
.reg
= e
->reg
;
3483 card
->update
= &update
;
3485 change
|= reg_change
;
3487 ret
= soc_dapm_mux_update_power(card
, kcontrol
, item
[0], e
);
3489 card
->update
= NULL
;
3493 mutex_unlock(&card
->dapm_mutex
);
3496 soc_dpcm_runtime_update(card
);
3502 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3503 * @kcontrol: mixer control
3504 * @ucontrol: control element information
3506 * Callback to set the value of a dapm enumerated double mixer control.
3508 * Returns 0 for success.
3510 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
3511 struct snd_ctl_elem_value
*ucontrol
)
3513 return __snd_soc_dapm_put_enum_double(kcontrol
, ucontrol
, 0);
3515 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
3518 * snd_soc_dapm_put_enum_double_locked - dapm enumerated double mixer set
3520 * @kcontrol: mixer control
3521 * @ucontrol: control element information
3523 * Callback to set the value of a dapm enumerated double mixer control.
3524 * Must acquire dapm_mutex before calling the function.
3526 * Returns 0 for success.
3528 int snd_soc_dapm_put_enum_double_locked(struct snd_kcontrol
*kcontrol
,
3529 struct snd_ctl_elem_value
*ucontrol
)
3531 dapm_assert_locked(snd_soc_dapm_kcontrol_dapm(kcontrol
));
3532 return __snd_soc_dapm_put_enum_double(kcontrol
, ucontrol
, 1);
3534 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double_locked
);
3537 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3539 * @kcontrol: mixer control
3540 * @uinfo: control element information
3542 * Callback to provide information about a pin switch control.
3544 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
3545 struct snd_ctl_elem_info
*uinfo
)
3547 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3549 uinfo
->value
.integer
.min
= 0;
3550 uinfo
->value
.integer
.max
= 1;
3554 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3557 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3559 * @kcontrol: mixer control
3562 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3563 struct snd_ctl_elem_value
*ucontrol
)
3565 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3566 const char *pin
= (const char *)kcontrol
->private_value
;
3568 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3570 ucontrol
->value
.integer
.value
[0] =
3571 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3573 mutex_unlock(&card
->dapm_mutex
);
3577 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3580 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3582 * @kcontrol: mixer control
3585 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3586 struct snd_ctl_elem_value
*ucontrol
)
3588 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3589 const char *pin
= (const char *)kcontrol
->private_value
;
3591 if (ucontrol
->value
.integer
.value
[0])
3592 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3594 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3596 snd_soc_dapm_sync(&card
->dapm
);
3599 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3601 struct snd_soc_dapm_widget
*
3602 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context
*dapm
,
3603 const struct snd_soc_dapm_widget
*widget
)
3605 enum snd_soc_dapm_direction dir
;
3606 struct snd_soc_dapm_widget
*w
;
3610 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3611 return ERR_PTR(-ENOMEM
);
3614 case snd_soc_dapm_regulator_supply
:
3615 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3616 if (IS_ERR(w
->regulator
)) {
3617 ret
= PTR_ERR(w
->regulator
);
3618 goto request_failed
;
3621 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3622 ret
= regulator_allow_bypass(w
->regulator
, true);
3625 "ASoC: Failed to bypass %s: %d\n",
3629 case snd_soc_dapm_pinctrl
:
3630 w
->pinctrl
= devm_pinctrl_get(dapm
->dev
);
3631 if (IS_ERR(w
->pinctrl
)) {
3632 ret
= PTR_ERR(w
->pinctrl
);
3633 goto request_failed
;
3636 case snd_soc_dapm_clock_supply
:
3637 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3638 if (IS_ERR(w
->clk
)) {
3639 ret
= PTR_ERR(w
->clk
);
3640 goto request_failed
;
3647 prefix
= soc_dapm_prefix(dapm
);
3649 w
->name
= kasprintf(GFP_KERNEL
, "%s %s", prefix
, widget
->name
);
3651 w
->name
= kstrdup_const(widget
->name
, GFP_KERNEL
);
3652 if (w
->name
== NULL
) {
3653 kfree_const(w
->sname
);
3655 return ERR_PTR(-ENOMEM
);
3659 case snd_soc_dapm_mic
:
3660 w
->is_ep
= SND_SOC_DAPM_EP_SOURCE
;
3661 w
->power_check
= dapm_generic_check_power
;
3663 case snd_soc_dapm_input
:
3664 if (!dapm
->card
->fully_routed
)
3665 w
->is_ep
= SND_SOC_DAPM_EP_SOURCE
;
3666 w
->power_check
= dapm_generic_check_power
;
3668 case snd_soc_dapm_spk
:
3669 case snd_soc_dapm_hp
:
3670 w
->is_ep
= SND_SOC_DAPM_EP_SINK
;
3671 w
->power_check
= dapm_generic_check_power
;
3673 case snd_soc_dapm_output
:
3674 if (!dapm
->card
->fully_routed
)
3675 w
->is_ep
= SND_SOC_DAPM_EP_SINK
;
3676 w
->power_check
= dapm_generic_check_power
;
3678 case snd_soc_dapm_vmid
:
3679 case snd_soc_dapm_siggen
:
3680 w
->is_ep
= SND_SOC_DAPM_EP_SOURCE
;
3681 w
->power_check
= dapm_always_on_check_power
;
3683 case snd_soc_dapm_sink
:
3684 w
->is_ep
= SND_SOC_DAPM_EP_SINK
;
3685 w
->power_check
= dapm_always_on_check_power
;
3688 case snd_soc_dapm_mux
:
3689 case snd_soc_dapm_demux
:
3690 case snd_soc_dapm_switch
:
3691 case snd_soc_dapm_mixer
:
3692 case snd_soc_dapm_mixer_named_ctl
:
3693 case snd_soc_dapm_adc
:
3694 case snd_soc_dapm_aif_out
:
3695 case snd_soc_dapm_dac
:
3696 case snd_soc_dapm_aif_in
:
3697 case snd_soc_dapm_pga
:
3698 case snd_soc_dapm_buffer
:
3699 case snd_soc_dapm_scheduler
:
3700 case snd_soc_dapm_effect
:
3701 case snd_soc_dapm_src
:
3702 case snd_soc_dapm_asrc
:
3703 case snd_soc_dapm_encoder
:
3704 case snd_soc_dapm_decoder
:
3705 case snd_soc_dapm_out_drv
:
3706 case snd_soc_dapm_micbias
:
3707 case snd_soc_dapm_line
:
3708 case snd_soc_dapm_dai_link
:
3709 case snd_soc_dapm_dai_out
:
3710 case snd_soc_dapm_dai_in
:
3711 w
->power_check
= dapm_generic_check_power
;
3713 case snd_soc_dapm_supply
:
3714 case snd_soc_dapm_regulator_supply
:
3715 case snd_soc_dapm_pinctrl
:
3716 case snd_soc_dapm_clock_supply
:
3717 case snd_soc_dapm_kcontrol
:
3719 w
->power_check
= dapm_supply_check_power
;
3722 w
->power_check
= dapm_always_on_check_power
;
3727 INIT_LIST_HEAD(&w
->list
);
3728 INIT_LIST_HEAD(&w
->dirty
);
3729 list_add_tail(&w
->list
, &dapm
->card
->widgets
);
3731 snd_soc_dapm_for_each_direction(dir
) {
3732 INIT_LIST_HEAD(&w
->edges
[dir
]);
3733 w
->endpoints
[dir
] = -1;
3736 /* machine layer sets up unconnected pins and insertions */
3741 if (ret
!= -EPROBE_DEFER
)
3742 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3745 kfree_const(w
->sname
);
3747 return ERR_PTR(ret
);
3751 * snd_soc_dapm_new_control - create new dapm control
3752 * @dapm: DAPM context
3753 * @widget: widget template
3755 * Creates new DAPM control based upon a template.
3757 * Returns a widget pointer on success or an error pointer on failure
3759 struct snd_soc_dapm_widget
*
3760 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3761 const struct snd_soc_dapm_widget
*widget
)
3763 struct snd_soc_dapm_widget
*w
;
3765 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3766 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3767 mutex_unlock(&dapm
->card
->dapm_mutex
);
3771 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
3774 * snd_soc_dapm_new_controls - create new dapm controls
3775 * @dapm: DAPM context
3776 * @widget: widget array
3777 * @num: number of widgets
3779 * Creates new DAPM controls based upon the templates.
3781 * Returns 0 for success else error.
3783 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3784 const struct snd_soc_dapm_widget
*widget
,
3787 struct snd_soc_dapm_widget
*w
;
3791 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3792 for (i
= 0; i
< num
; i
++) {
3793 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3800 mutex_unlock(&dapm
->card
->dapm_mutex
);
3803 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3806 snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget
*w
,
3807 struct snd_pcm_substream
*substream
)
3809 struct snd_soc_dapm_path
*path
;
3810 struct snd_soc_dai
*source
, *sink
;
3811 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
3812 struct snd_pcm_hw_params
*params
= NULL
;
3813 const struct snd_soc_pcm_stream
*config
= NULL
;
3814 struct snd_pcm_runtime
*runtime
= NULL
;
3818 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3822 runtime
= kzalloc(sizeof(*runtime
), GFP_KERNEL
);
3828 substream
->runtime
= runtime
;
3830 substream
->stream
= SNDRV_PCM_STREAM_CAPTURE
;
3831 snd_soc_dapm_widget_for_each_source_path(w
, path
) {
3832 source
= path
->source
->priv
;
3834 ret
= snd_soc_dai_startup(source
, substream
);
3836 dev_err(source
->dev
,
3837 "ASoC: startup() failed: %d\n", ret
);
3843 substream
->stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3844 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3845 sink
= path
->sink
->priv
;
3847 ret
= snd_soc_dai_startup(sink
, substream
);
3850 "ASoC: startup() failed: %d\n", ret
);
3856 substream
->hw_opened
= 1;
3859 * Note: getting the config after .startup() gives a chance to
3860 * either party on the link to alter the configuration if
3863 config
= rtd
->dai_link
->params
+ rtd
->params_select
;
3864 if (WARN_ON(!config
)) {
3865 dev_err(w
->dapm
->dev
, "ASoC: link config missing\n");
3870 /* Be a little careful as we don't want to overflow the mask array */
3871 if (config
->formats
) {
3872 fmt
= ffs(config
->formats
) - 1;
3874 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3881 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3882 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3884 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3886 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3887 = config
->channels_min
;
3888 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3889 = config
->channels_max
;
3891 substream
->stream
= SNDRV_PCM_STREAM_CAPTURE
;
3892 snd_soc_dapm_widget_for_each_source_path(w
, path
) {
3893 source
= path
->source
->priv
;
3895 ret
= snd_soc_dai_hw_params(source
, substream
, params
);
3899 dapm_update_dai_unlocked(substream
, params
, source
);
3902 substream
->stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3903 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3904 sink
= path
->sink
->priv
;
3906 ret
= snd_soc_dai_hw_params(sink
, substream
, params
);
3910 dapm_update_dai_unlocked(substream
, params
, sink
);
3913 runtime
->format
= params_format(params
);
3914 runtime
->subformat
= params_subformat(params
);
3915 runtime
->channels
= params_channels(params
);
3916 runtime
->rate
= params_rate(params
);
3926 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3927 struct snd_kcontrol
*kcontrol
, int event
)
3929 struct snd_soc_dapm_path
*path
;
3930 struct snd_soc_dai
*source
, *sink
;
3931 struct snd_pcm_substream
*substream
= w
->priv
;
3932 int ret
= 0, saved_stream
= substream
->stream
;
3934 if (WARN_ON(list_empty(&w
->edges
[SND_SOC_DAPM_DIR_OUT
]) ||
3935 list_empty(&w
->edges
[SND_SOC_DAPM_DIR_IN
])))
3939 case SND_SOC_DAPM_PRE_PMU
:
3940 ret
= snd_soc_dai_link_event_pre_pmu(w
, substream
);
3946 case SND_SOC_DAPM_POST_PMU
:
3947 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3948 sink
= path
->sink
->priv
;
3950 ret
= snd_soc_dai_digital_mute(sink
, 0,
3951 SNDRV_PCM_STREAM_PLAYBACK
);
3952 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3954 "ASoC: Failed to unmute: %d\n", ret
);
3959 case SND_SOC_DAPM_PRE_PMD
:
3960 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3961 sink
= path
->sink
->priv
;
3963 ret
= snd_soc_dai_digital_mute(sink
, 1,
3964 SNDRV_PCM_STREAM_PLAYBACK
);
3965 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3967 "ASoC: Failed to mute: %d\n", ret
);
3971 substream
->stream
= SNDRV_PCM_STREAM_CAPTURE
;
3972 snd_soc_dapm_widget_for_each_source_path(w
, path
) {
3973 source
= path
->source
->priv
;
3974 snd_soc_dai_hw_free(source
, substream
);
3977 substream
->stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3978 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3979 sink
= path
->sink
->priv
;
3980 snd_soc_dai_hw_free(sink
, substream
);
3983 substream
->stream
= SNDRV_PCM_STREAM_CAPTURE
;
3984 snd_soc_dapm_widget_for_each_source_path(w
, path
) {
3985 source
= path
->source
->priv
;
3987 snd_soc_dai_shutdown(source
, substream
);
3990 substream
->stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3991 snd_soc_dapm_widget_for_each_sink_path(w
, path
) {
3992 sink
= path
->sink
->priv
;
3994 snd_soc_dai_shutdown(sink
, substream
);
3998 case SND_SOC_DAPM_POST_PMD
:
3999 kfree(substream
->runtime
);
4003 WARN(1, "Unknown event %d\n", event
);
4008 /* Restore the substream direction */
4009 substream
->stream
= saved_stream
;
4013 static int snd_soc_dapm_dai_link_get(struct snd_kcontrol
*kcontrol
,
4014 struct snd_ctl_elem_value
*ucontrol
)
4016 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
4017 struct snd_soc_pcm_runtime
*rtd
= w
->priv
;
4019 ucontrol
->value
.enumerated
.item
[0] = rtd
->params_select
;
4024 static int snd_soc_dapm_dai_link_put(struct snd_kcontrol
*kcontrol
,
4025 struct snd_ctl_elem_value
*ucontrol
)
4027 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
4028 struct snd_soc_pcm_runtime
*rtd
= w
->priv
;
4030 /* Can't change the config when widget is already powered */
4034 if (ucontrol
->value
.enumerated
.item
[0] == rtd
->params_select
)
4037 if (ucontrol
->value
.enumerated
.item
[0] >= rtd
->dai_link
->num_params
)
4040 rtd
->params_select
= ucontrol
->value
.enumerated
.item
[0];
4046 snd_soc_dapm_free_kcontrol(struct snd_soc_card
*card
,
4047 unsigned long *private_value
,
4049 const char **w_param_text
)
4053 devm_kfree(card
->dev
, (void *)*private_value
);
4058 for (count
= 0 ; count
< num_params
; count
++)
4059 devm_kfree(card
->dev
, (void *)w_param_text
[count
]);
4060 devm_kfree(card
->dev
, w_param_text
);
4063 static struct snd_kcontrol_new
*
4064 snd_soc_dapm_alloc_kcontrol(struct snd_soc_card
*card
,
4066 const struct snd_soc_pcm_stream
*params
,
4067 int num_params
, const char **w_param_text
,
4068 unsigned long *private_value
)
4070 struct soc_enum w_param_enum
[] = {
4071 SOC_ENUM_SINGLE(0, 0, 0, NULL
),
4073 struct snd_kcontrol_new kcontrol_dai_link
[] = {
4074 SOC_ENUM_EXT(NULL
, w_param_enum
[0],
4075 snd_soc_dapm_dai_link_get
,
4076 snd_soc_dapm_dai_link_put
),
4078 struct snd_kcontrol_new
*kcontrol_news
;
4079 const struct snd_soc_pcm_stream
*config
= params
;
4082 for (count
= 0 ; count
< num_params
; count
++) {
4083 if (!config
->stream_name
) {
4084 dev_warn(card
->dapm
.dev
,
4085 "ASoC: anonymous config %d for dai link %s\n",
4087 w_param_text
[count
] =
4088 devm_kasprintf(card
->dev
, GFP_KERNEL
,
4089 "Anonymous Configuration %d",
4092 w_param_text
[count
] = devm_kmemdup(card
->dev
,
4093 config
->stream_name
,
4094 strlen(config
->stream_name
) + 1,
4097 if (!w_param_text
[count
])
4098 goto outfree_w_param
;
4102 w_param_enum
[0].items
= num_params
;
4103 w_param_enum
[0].texts
= w_param_text
;
4106 (unsigned long) devm_kmemdup(card
->dev
,
4107 (void *)(kcontrol_dai_link
[0].private_value
),
4108 sizeof(struct soc_enum
), GFP_KERNEL
);
4109 if (!*private_value
) {
4110 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
4112 goto outfree_w_param
;
4114 kcontrol_dai_link
[0].private_value
= *private_value
;
4115 /* duplicate kcontrol_dai_link on heap so that memory persists */
4116 kcontrol_news
= devm_kmemdup(card
->dev
, &kcontrol_dai_link
[0],
4117 sizeof(struct snd_kcontrol_new
),
4119 if (!kcontrol_news
) {
4120 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
4122 goto outfree_w_param
;
4124 return kcontrol_news
;
4127 snd_soc_dapm_free_kcontrol(card
, private_value
, num_params
, w_param_text
);
4131 static struct snd_soc_dapm_widget
*
4132 snd_soc_dapm_new_dai(struct snd_soc_card
*card
,
4133 struct snd_pcm_substream
*substream
,
4136 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
4137 struct snd_soc_dapm_widget
template;
4138 struct snd_soc_dapm_widget
*w
;
4139 const char **w_param_text
;
4140 unsigned long private_value
= 0;
4144 link_name
= devm_kasprintf(card
->dev
, GFP_KERNEL
, "%s-%s",
4145 rtd
->dai_link
->name
, id
);
4147 return ERR_PTR(-ENOMEM
);
4149 memset(&template, 0, sizeof(template));
4150 template.reg
= SND_SOC_NOPM
;
4151 template.id
= snd_soc_dapm_dai_link
;
4152 template.name
= link_name
;
4153 template.event
= snd_soc_dai_link_event
;
4154 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4155 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
;
4156 template.kcontrol_news
= NULL
;
4158 /* allocate memory for control, only in case of multiple configs */
4159 if (rtd
->dai_link
->num_params
> 1) {
4160 w_param_text
= devm_kcalloc(card
->dev
,
4161 rtd
->dai_link
->num_params
,
4162 sizeof(char *), GFP_KERNEL
);
4163 if (!w_param_text
) {
4168 template.num_kcontrols
= 1;
4169 template.kcontrol_news
=
4170 snd_soc_dapm_alloc_kcontrol(card
,
4172 rtd
->dai_link
->params
,
4173 rtd
->dai_link
->num_params
,
4174 w_param_text
, &private_value
);
4175 if (!template.kcontrol_news
) {
4180 w_param_text
= NULL
;
4182 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
4184 w
= snd_soc_dapm_new_control_unlocked(&card
->dapm
, &template);
4187 goto outfree_kcontrol_news
;
4190 w
->priv
= substream
;
4194 outfree_kcontrol_news
:
4195 devm_kfree(card
->dev
, (void *)template.kcontrol_news
);
4196 snd_soc_dapm_free_kcontrol(card
, &private_value
,
4197 rtd
->dai_link
->num_params
, w_param_text
);
4199 devm_kfree(card
->dev
, link_name
);
4200 return ERR_PTR(ret
);
4203 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
4204 struct snd_soc_dai
*dai
)
4206 struct snd_soc_dapm_widget
template;
4207 struct snd_soc_dapm_widget
*w
;
4209 WARN_ON(dapm
->dev
!= dai
->dev
);
4211 memset(&template, 0, sizeof(template));
4212 template.reg
= SND_SOC_NOPM
;
4214 if (dai
->driver
->playback
.stream_name
) {
4215 template.id
= snd_soc_dapm_dai_in
;
4216 template.name
= dai
->driver
->playback
.stream_name
;
4217 template.sname
= dai
->driver
->playback
.stream_name
;
4219 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
4222 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
4227 dai
->playback_widget
= w
;
4230 if (dai
->driver
->capture
.stream_name
) {
4231 template.id
= snd_soc_dapm_dai_out
;
4232 template.name
= dai
->driver
->capture
.stream_name
;
4233 template.sname
= dai
->driver
->capture
.stream_name
;
4235 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
4238 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
4243 dai
->capture_widget
= w
;
4249 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
4251 struct snd_soc_dapm_widget
*dai_w
, *w
;
4252 struct snd_soc_dapm_widget
*src
, *sink
;
4253 struct snd_soc_dai
*dai
;
4255 /* For each DAI widget... */
4256 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
4257 switch (dai_w
->id
) {
4258 case snd_soc_dapm_dai_in
:
4259 case snd_soc_dapm_dai_out
:
4265 /* let users know there is no DAI to link */
4267 dev_dbg(card
->dev
, "dai widget %s has no DAI\n",
4274 /* ...find all widgets with the same stream and link them */
4275 list_for_each_entry(w
, &card
->widgets
, list
) {
4276 if (w
->dapm
!= dai_w
->dapm
)
4280 case snd_soc_dapm_dai_in
:
4281 case snd_soc_dapm_dai_out
:
4287 if (!w
->sname
|| !strstr(w
->sname
, dai_w
->sname
))
4290 if (dai_w
->id
== snd_soc_dapm_dai_in
) {
4297 dev_dbg(dai
->dev
, "%s -> %s\n", src
->name
, sink
->name
);
4298 snd_soc_dapm_add_path(w
->dapm
, src
, sink
, NULL
, NULL
);
4305 static void dapm_connect_dai_link_widgets(struct snd_soc_card
*card
,
4306 struct snd_soc_pcm_runtime
*rtd
)
4308 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
4309 struct snd_soc_dai
*codec_dai
;
4310 struct snd_soc_dapm_widget
*playback
= NULL
, *capture
= NULL
;
4311 struct snd_soc_dapm_widget
*codec
, *playback_cpu
, *capture_cpu
;
4312 struct snd_pcm_substream
*substream
;
4313 struct snd_pcm_str
*streams
= rtd
->pcm
->streams
;
4316 if (rtd
->dai_link
->params
) {
4317 playback_cpu
= cpu_dai
->capture_widget
;
4318 capture_cpu
= cpu_dai
->playback_widget
;
4320 playback
= cpu_dai
->playback_widget
;
4321 capture
= cpu_dai
->capture_widget
;
4322 playback_cpu
= playback
;
4323 capture_cpu
= capture
;
4326 for_each_rtd_codec_dai(rtd
, i
, codec_dai
) {
4327 /* connect BE DAI playback if widgets are valid */
4328 codec
= codec_dai
->playback_widget
;
4330 if (playback_cpu
&& codec
) {
4332 substream
= streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
;
4333 playback
= snd_soc_dapm_new_dai(card
, substream
,
4335 if (IS_ERR(playback
)) {
4337 "ASoC: Failed to create DAI %s: %ld\n",
4343 snd_soc_dapm_add_path(&card
->dapm
, playback_cpu
,
4344 playback
, NULL
, NULL
);
4347 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
4348 cpu_dai
->component
->name
, playback_cpu
->name
,
4349 codec_dai
->component
->name
, codec
->name
);
4351 snd_soc_dapm_add_path(&card
->dapm
, playback
, codec
,
4356 for_each_rtd_codec_dai(rtd
, i
, codec_dai
) {
4357 /* connect BE DAI capture if widgets are valid */
4358 codec
= codec_dai
->capture_widget
;
4360 if (codec
&& capture_cpu
) {
4362 substream
= streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
;
4363 capture
= snd_soc_dapm_new_dai(card
, substream
,
4365 if (IS_ERR(capture
)) {
4367 "ASoC: Failed to create DAI %s: %ld\n",
4373 snd_soc_dapm_add_path(&card
->dapm
, capture
,
4374 capture_cpu
, NULL
, NULL
);
4377 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
4378 codec_dai
->component
->name
, codec
->name
,
4379 cpu_dai
->component
->name
, capture_cpu
->name
);
4381 snd_soc_dapm_add_path(&card
->dapm
, codec
, capture
,
4387 static void soc_dapm_dai_stream_event(struct snd_soc_dai
*dai
, int stream
,
4390 struct snd_soc_dapm_widget
*w
;
4393 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4394 w
= dai
->playback_widget
;
4396 w
= dai
->capture_widget
;
4399 dapm_mark_dirty(w
, "stream event");
4401 if (w
->id
== snd_soc_dapm_dai_in
) {
4402 ep
= SND_SOC_DAPM_EP_SOURCE
;
4403 dapm_widget_invalidate_input_paths(w
);
4405 ep
= SND_SOC_DAPM_EP_SINK
;
4406 dapm_widget_invalidate_output_paths(w
);
4410 case SND_SOC_DAPM_STREAM_START
:
4414 case SND_SOC_DAPM_STREAM_STOP
:
4418 case SND_SOC_DAPM_STREAM_SUSPEND
:
4419 case SND_SOC_DAPM_STREAM_RESUME
:
4420 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
4421 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
4427 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card
*card
)
4429 struct snd_soc_pcm_runtime
*rtd
;
4431 /* for each BE DAI link... */
4432 for_each_card_rtds(card
, rtd
) {
4434 * dynamic FE links have no fixed DAI mapping.
4435 * CODEC<->CODEC links have no direct connection.
4437 if (rtd
->dai_link
->dynamic
)
4440 dapm_connect_dai_link_widgets(card
, rtd
);
4444 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
4447 struct snd_soc_dai
*codec_dai
;
4450 soc_dapm_dai_stream_event(rtd
->cpu_dai
, stream
, event
);
4451 for_each_rtd_codec_dai(rtd
, i
, codec_dai
)
4452 soc_dapm_dai_stream_event(codec_dai
, stream
, event
);
4454 dapm_power_widgets(rtd
->card
, event
);
4458 * snd_soc_dapm_stream_event - send a stream event to the dapm core
4459 * @rtd: PCM runtime data
4460 * @stream: stream name
4461 * @event: stream event
4463 * Sends a stream event to the dapm core. The core then makes any
4464 * necessary widget power changes.
4466 * Returns 0 for success else error.
4468 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
4471 struct snd_soc_card
*card
= rtd
->card
;
4473 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4474 soc_dapm_stream_event(rtd
, stream
, event
);
4475 mutex_unlock(&card
->dapm_mutex
);
4478 void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime
*rtd
, int stream
)
4480 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
4481 if (snd_soc_runtime_ignore_pmdown_time(rtd
)) {
4482 /* powered down playback stream now */
4483 snd_soc_dapm_stream_event(rtd
,
4484 SNDRV_PCM_STREAM_PLAYBACK
,
4485 SND_SOC_DAPM_STREAM_STOP
);
4487 /* start delayed pop wq here for playback streams */
4489 queue_delayed_work(system_power_efficient_wq
,
4491 msecs_to_jiffies(rtd
->pmdown_time
));
4494 /* capture streams can be powered down now */
4495 snd_soc_dapm_stream_event(rtd
, SNDRV_PCM_STREAM_CAPTURE
,
4496 SND_SOC_DAPM_STREAM_STOP
);
4499 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_stop
);
4502 * snd_soc_dapm_enable_pin_unlocked - enable pin.
4503 * @dapm: DAPM context
4506 * Enables input/output pin and its parents or children widgets iff there is
4507 * a valid audio route and active audio stream.
4509 * Requires external locking.
4511 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4512 * do any widget power switching.
4514 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4517 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
4519 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked
);
4522 * snd_soc_dapm_enable_pin - enable pin.
4523 * @dapm: DAPM context
4526 * Enables input/output pin and its parents or children widgets iff there is
4527 * a valid audio route and active audio stream.
4529 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4530 * do any widget power switching.
4532 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
4536 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4538 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 1);
4540 mutex_unlock(&dapm
->card
->dapm_mutex
);
4544 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
4547 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
4548 * @dapm: DAPM context
4551 * Enables input/output pin regardless of any other state. This is
4552 * intended for use with microphone bias supplies used in microphone
4555 * Requires external locking.
4557 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4558 * do any widget power switching.
4560 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4563 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4566 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4570 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
4571 if (!w
->connected
) {
4573 * w->force does not affect the number of input or output paths,
4574 * so we only have to recheck if w->connected is changed
4576 dapm_widget_invalidate_input_paths(w
);
4577 dapm_widget_invalidate_output_paths(w
);
4581 dapm_mark_dirty(w
, "force enable");
4585 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked
);
4588 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4589 * @dapm: DAPM context
4592 * Enables input/output pin regardless of any other state. This is
4593 * intended for use with microphone bias supplies used in microphone
4596 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4597 * do any widget power switching.
4599 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
4604 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4606 ret
= snd_soc_dapm_force_enable_pin_unlocked(dapm
, pin
);
4608 mutex_unlock(&dapm
->card
->dapm_mutex
);
4612 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
4615 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4616 * @dapm: DAPM context
4619 * Disables input/output pin and its parents or children widgets.
4621 * Requires external locking.
4623 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4624 * do any widget power switching.
4626 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4629 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4631 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked
);
4634 * snd_soc_dapm_disable_pin - disable pin.
4635 * @dapm: DAPM context
4638 * Disables input/output pin and its parents or children widgets.
4640 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4641 * do any widget power switching.
4643 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
4648 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4650 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4652 mutex_unlock(&dapm
->card
->dapm_mutex
);
4656 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
4659 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4660 * @dapm: DAPM context
4663 * Marks the specified pin as being not connected, disabling it along
4664 * any parent or child widgets. At present this is identical to
4665 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4666 * additional things such as disabling controls which only affect
4667 * paths through the pin.
4669 * Requires external locking.
4671 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4672 * do any widget power switching.
4674 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4677 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4679 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked
);
4682 * snd_soc_dapm_nc_pin - permanently disable pin.
4683 * @dapm: DAPM context
4686 * Marks the specified pin as being not connected, disabling it along
4687 * any parent or child widgets. At present this is identical to
4688 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4689 * additional things such as disabling controls which only affect
4690 * paths through the pin.
4692 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4693 * do any widget power switching.
4695 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
4699 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4701 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4703 mutex_unlock(&dapm
->card
->dapm_mutex
);
4707 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
4710 * snd_soc_dapm_get_pin_status - get audio pin status
4711 * @dapm: DAPM context
4712 * @pin: audio signal pin endpoint (or start point)
4714 * Get audio pin status - connected or disconnected.
4716 * Returns 1 for connected otherwise 0.
4718 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
4721 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4724 return w
->connected
;
4728 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
4731 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4732 * @dapm: DAPM context
4733 * @pin: audio signal pin endpoint (or start point)
4735 * Mark the given endpoint or pin as ignoring suspend. When the
4736 * system is disabled a path between two endpoints flagged as ignoring
4737 * suspend will not be disabled. The path must already be enabled via
4738 * normal means at suspend time, it will not be turned on if it was not
4741 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
4744 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
4747 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4751 w
->ignore_suspend
= 1;
4755 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
4758 * snd_soc_dapm_free - free dapm resources
4759 * @dapm: DAPM context
4761 * Free all dapm widgets and resources.
4763 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
4765 dapm_debugfs_cleanup(dapm
);
4766 dapm_free_widgets(dapm
);
4767 list_del(&dapm
->list
);
4769 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
4771 void snd_soc_dapm_init(struct snd_soc_dapm_context
*dapm
,
4772 struct snd_soc_card
*card
,
4773 struct snd_soc_component
*component
)
4776 dapm
->component
= component
;
4777 dapm
->bias_level
= SND_SOC_BIAS_OFF
;
4780 dapm
->dev
= component
->dev
;
4781 dapm
->idle_bias_off
= !component
->driver
->idle_bias_on
,
4782 dapm
->suspend_bias_off
= component
->driver
->suspend_bias_off
;
4784 dapm
->dev
= card
->dev
;
4787 INIT_LIST_HEAD(&dapm
->list
);
4788 list_add(&dapm
->list
, &card
->dapm_list
);
4790 EXPORT_SYMBOL_GPL(snd_soc_dapm_init
);
4792 static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context
*dapm
)
4794 struct snd_soc_card
*card
= dapm
->card
;
4795 struct snd_soc_dapm_widget
*w
;
4796 LIST_HEAD(down_list
);
4799 mutex_lock(&card
->dapm_mutex
);
4801 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
4802 if (w
->dapm
!= dapm
)
4805 dapm_seq_insert(w
, &down_list
, false);
4811 /* If there were no widgets to power down we're already in
4815 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
4816 snd_soc_dapm_set_bias_level(dapm
,
4817 SND_SOC_BIAS_PREPARE
);
4818 dapm_seq_run(card
, &down_list
, 0, false);
4819 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
4820 snd_soc_dapm_set_bias_level(dapm
,
4821 SND_SOC_BIAS_STANDBY
);
4824 mutex_unlock(&card
->dapm_mutex
);
4828 * snd_soc_dapm_shutdown - callback for system shutdown
4830 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
4832 struct snd_soc_dapm_context
*dapm
;
4834 list_for_each_entry(dapm
, &card
->dapm_list
, list
) {
4835 if (dapm
!= &card
->dapm
) {
4836 soc_dapm_shutdown_dapm(dapm
);
4837 if (dapm
->bias_level
== SND_SOC_BIAS_STANDBY
)
4838 snd_soc_dapm_set_bias_level(dapm
,
4843 soc_dapm_shutdown_dapm(&card
->dapm
);
4844 if (card
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
4845 snd_soc_dapm_set_bias_level(&card
->dapm
,
4849 /* Module information */
4850 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4851 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
4852 MODULE_LICENSE("GPL");