2 * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 * o Changes power status of internal codec blocks depending on the
14 * dynamic configuration of codec internal audio paths and active
16 * o Platform power domain - can support external components i.e. amps and
17 * mic/headphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
21 * o Delayed power down of audio subsystem to reduce pops between a quick
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/init.h>
29 #include <linux/async.h>
30 #include <linux/delay.h>
32 #include <linux/bitops.h>
33 #include <linux/platform_device.h>
34 #include <linux/jiffies.h>
35 #include <linux/debugfs.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/regulator/consumer.h>
38 #include <linux/clk.h>
39 #include <linux/slab.h>
40 #include <sound/core.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc.h>
44 #include <sound/initval.h>
46 #include <trace/events/asoc.h>
48 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
50 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
51 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
53 int (*connected
)(struct snd_soc_dapm_widget
*source
,
54 struct snd_soc_dapm_widget
*sink
));
56 struct snd_soc_dapm_widget
*
57 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
58 const struct snd_soc_dapm_widget
*widget
);
60 struct snd_soc_dapm_widget
*
61 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context
*dapm
,
62 const struct snd_soc_dapm_widget
*widget
);
64 /* dapm power sequences - make this per codec in the future */
65 static int dapm_up_seq
[] = {
66 [snd_soc_dapm_pre
] = 0,
67 [snd_soc_dapm_regulator_supply
] = 1,
68 [snd_soc_dapm_clock_supply
] = 1,
69 [snd_soc_dapm_supply
] = 2,
70 [snd_soc_dapm_micbias
] = 3,
71 [snd_soc_dapm_dai_link
] = 2,
72 [snd_soc_dapm_dai_in
] = 4,
73 [snd_soc_dapm_dai_out
] = 4,
74 [snd_soc_dapm_aif_in
] = 4,
75 [snd_soc_dapm_aif_out
] = 4,
76 [snd_soc_dapm_mic
] = 5,
77 [snd_soc_dapm_mux
] = 6,
78 [snd_soc_dapm_demux
] = 6,
79 [snd_soc_dapm_dac
] = 7,
80 [snd_soc_dapm_switch
] = 8,
81 [snd_soc_dapm_mixer
] = 8,
82 [snd_soc_dapm_mixer_named_ctl
] = 8,
83 [snd_soc_dapm_pga
] = 9,
84 [snd_soc_dapm_adc
] = 10,
85 [snd_soc_dapm_out_drv
] = 11,
86 [snd_soc_dapm_hp
] = 11,
87 [snd_soc_dapm_spk
] = 11,
88 [snd_soc_dapm_line
] = 11,
89 [snd_soc_dapm_kcontrol
] = 12,
90 [snd_soc_dapm_post
] = 13,
93 static int dapm_down_seq
[] = {
94 [snd_soc_dapm_pre
] = 0,
95 [snd_soc_dapm_kcontrol
] = 1,
96 [snd_soc_dapm_adc
] = 2,
97 [snd_soc_dapm_hp
] = 3,
98 [snd_soc_dapm_spk
] = 3,
99 [snd_soc_dapm_line
] = 3,
100 [snd_soc_dapm_out_drv
] = 3,
101 [snd_soc_dapm_pga
] = 4,
102 [snd_soc_dapm_switch
] = 5,
103 [snd_soc_dapm_mixer_named_ctl
] = 5,
104 [snd_soc_dapm_mixer
] = 5,
105 [snd_soc_dapm_dac
] = 6,
106 [snd_soc_dapm_mic
] = 7,
107 [snd_soc_dapm_micbias
] = 8,
108 [snd_soc_dapm_mux
] = 9,
109 [snd_soc_dapm_demux
] = 9,
110 [snd_soc_dapm_aif_in
] = 10,
111 [snd_soc_dapm_aif_out
] = 10,
112 [snd_soc_dapm_dai_in
] = 10,
113 [snd_soc_dapm_dai_out
] = 10,
114 [snd_soc_dapm_dai_link
] = 11,
115 [snd_soc_dapm_supply
] = 12,
116 [snd_soc_dapm_clock_supply
] = 13,
117 [snd_soc_dapm_regulator_supply
] = 13,
118 [snd_soc_dapm_post
] = 14,
121 static void dapm_assert_locked(struct snd_soc_dapm_context
*dapm
)
123 if (dapm
->card
&& dapm
->card
->instantiated
)
124 lockdep_assert_held(&dapm
->card
->dapm_mutex
);
127 static void pop_wait(u32 pop_time
)
130 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
133 static void pop_dbg(struct device
*dev
, u32 pop_time
, const char *fmt
, ...)
141 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
146 vsnprintf(buf
, PAGE_SIZE
, fmt
, args
);
147 dev_info(dev
, "%s", buf
);
153 static bool dapm_dirty_widget(struct snd_soc_dapm_widget
*w
)
155 return !list_empty(&w
->dirty
);
158 static void dapm_mark_dirty(struct snd_soc_dapm_widget
*w
, const char *reason
)
160 dapm_assert_locked(w
->dapm
);
162 if (!dapm_dirty_widget(w
)) {
163 dev_vdbg(w
->dapm
->dev
, "Marking %s dirty due to %s\n",
165 list_add_tail(&w
->dirty
, &w
->dapm
->card
->dapm_dirty
);
170 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of input
172 * @w: The widget for which to invalidate the cached number of input paths
174 * The function resets the cached number of inputs for the specified widget and
175 * all widgets that can be reached via outgoing paths from the widget.
177 * This function must be called if the number of input paths for a widget might
178 * have changed. E.g. if the source state of a widget changes or a path is added
179 * or activated with the widget as the sink.
181 static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget
*w
)
183 struct snd_soc_dapm_widget
*sink
;
184 struct snd_soc_dapm_path
*p
;
187 dapm_assert_locked(w
->dapm
);
193 list_add_tail(&w
->work_list
, &list
);
195 list_for_each_entry(w
, &list
, work_list
) {
196 list_for_each_entry(p
, &w
->sinks
, list_source
) {
197 if (p
->is_supply
|| p
->weak
|| !p
->connect
)
200 if (sink
->inputs
!= -1) {
202 list_add_tail(&sink
->work_list
, &list
);
209 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of
211 * @w: The widget for which to invalidate the cached number of output paths
213 * Resets the cached number of outputs for the specified widget and all widgets
214 * that can be reached via incoming paths from the widget.
216 * This function must be called if the number of output paths for a widget might
217 * have changed. E.g. if the sink state of a widget changes or a path is added
218 * or activated with the widget as the source.
220 static void dapm_widget_invalidate_output_paths(struct snd_soc_dapm_widget
*w
)
222 struct snd_soc_dapm_widget
*source
;
223 struct snd_soc_dapm_path
*p
;
226 dapm_assert_locked(w
->dapm
);
228 if (w
->outputs
== -1)
232 list_add_tail(&w
->work_list
, &list
);
234 list_for_each_entry(w
, &list
, work_list
) {
235 list_for_each_entry(p
, &w
->sources
, list_sink
) {
236 if (p
->is_supply
|| p
->weak
|| !p
->connect
)
239 if (source
->outputs
!= -1) {
240 source
->outputs
= -1;
241 list_add_tail(&source
->work_list
, &list
);
248 * dapm_path_invalidate() - Invalidates the cached number of inputs and outputs
249 * for the widgets connected to a path
250 * @p: The path to invalidate
252 * Resets the cached number of inputs for the sink of the path and the cached
253 * number of outputs for the source of the path.
255 * This function must be called when a path is added, removed or the connected
258 static void dapm_path_invalidate(struct snd_soc_dapm_path
*p
)
261 * Weak paths or supply paths do not influence the number of input or
262 * output paths of their neighbors.
264 if (p
->weak
|| p
->is_supply
)
268 * The number of connected endpoints is the sum of the number of
269 * connected endpoints of all neighbors. If a node with 0 connected
270 * endpoints is either connected or disconnected that sum won't change,
271 * so there is no need to re-check the path.
273 if (p
->source
->inputs
!= 0)
274 dapm_widget_invalidate_input_paths(p
->sink
);
275 if (p
->sink
->outputs
!= 0)
276 dapm_widget_invalidate_output_paths(p
->source
);
279 void dapm_mark_endpoints_dirty(struct snd_soc_card
*card
)
281 struct snd_soc_dapm_widget
*w
;
283 mutex_lock(&card
->dapm_mutex
);
285 list_for_each_entry(w
, &card
->widgets
, list
) {
286 if (w
->is_sink
|| w
->is_source
) {
287 dapm_mark_dirty(w
, "Rechecking endpoints");
289 dapm_widget_invalidate_output_paths(w
);
291 dapm_widget_invalidate_input_paths(w
);
295 mutex_unlock(&card
->dapm_mutex
);
297 EXPORT_SYMBOL_GPL(dapm_mark_endpoints_dirty
);
299 /* create a new dapm widget */
300 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
301 const struct snd_soc_dapm_widget
*_widget
)
303 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
306 struct dapm_kcontrol_data
{
308 struct snd_soc_dapm_widget
*widget
;
309 struct list_head paths
;
310 struct snd_soc_dapm_widget_list
*wlist
;
313 static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget
*widget
,
314 struct snd_kcontrol
*kcontrol
)
316 struct dapm_kcontrol_data
*data
;
317 struct soc_mixer_control
*mc
;
322 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
326 INIT_LIST_HEAD(&data
->paths
);
328 switch (widget
->id
) {
329 case snd_soc_dapm_switch
:
330 case snd_soc_dapm_mixer
:
331 case snd_soc_dapm_mixer_named_ctl
:
332 mc
= (struct soc_mixer_control
*)kcontrol
->private_value
;
334 if (mc
->autodisable
) {
335 struct snd_soc_dapm_widget
template;
337 name
= kasprintf(GFP_KERNEL
, "%s %s", kcontrol
->id
.name
,
344 memset(&template, 0, sizeof(template));
345 template.reg
= mc
->reg
;
346 template.mask
= (1 << fls(mc
->max
)) - 1;
347 template.shift
= mc
->shift
;
349 template.off_val
= mc
->max
;
351 template.off_val
= 0;
352 template.on_val
= template.off_val
;
353 template.id
= snd_soc_dapm_kcontrol
;
354 template.name
= name
;
356 data
->value
= template.on_val
;
359 snd_soc_dapm_new_control_unlocked(widget
->dapm
,
367 case snd_soc_dapm_demux
:
368 case snd_soc_dapm_mux
:
369 e
= (struct soc_enum
*)kcontrol
->private_value
;
371 if (e
->autodisable
) {
372 struct snd_soc_dapm_widget
template;
374 name
= kasprintf(GFP_KERNEL
, "%s %s", kcontrol
->id
.name
,
381 memset(&template, 0, sizeof(template));
382 template.reg
= e
->reg
;
383 template.mask
= e
->mask
<< e
->shift_l
;
384 template.shift
= e
->shift_l
;
385 template.off_val
= snd_soc_enum_item_to_val(e
, 0);
386 template.on_val
= template.off_val
;
387 template.id
= snd_soc_dapm_kcontrol
;
388 template.name
= name
;
390 data
->value
= template.on_val
;
392 data
->widget
= snd_soc_dapm_new_control_unlocked(
393 widget
->dapm
, &template);
399 snd_soc_dapm_add_path(widget
->dapm
, data
->widget
,
407 kcontrol
->private_data
= data
;
418 static void dapm_kcontrol_free(struct snd_kcontrol
*kctl
)
420 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kctl
);
422 kfree(data
->widget
->name
);
427 static struct snd_soc_dapm_widget_list
*dapm_kcontrol_get_wlist(
428 const struct snd_kcontrol
*kcontrol
)
430 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
435 static int dapm_kcontrol_add_widget(struct snd_kcontrol
*kcontrol
,
436 struct snd_soc_dapm_widget
*widget
)
438 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
439 struct snd_soc_dapm_widget_list
*new_wlist
;
443 n
= data
->wlist
->num_widgets
+ 1;
447 new_wlist
= krealloc(data
->wlist
,
448 sizeof(*new_wlist
) + sizeof(widget
) * n
, GFP_KERNEL
);
452 new_wlist
->widgets
[n
- 1] = widget
;
453 new_wlist
->num_widgets
= n
;
455 data
->wlist
= new_wlist
;
460 static void dapm_kcontrol_add_path(const struct snd_kcontrol
*kcontrol
,
461 struct snd_soc_dapm_path
*path
)
463 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
465 list_add_tail(&path
->list_kcontrol
, &data
->paths
);
468 static bool dapm_kcontrol_is_powered(const struct snd_kcontrol
*kcontrol
)
470 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
475 return data
->widget
->power
;
478 static struct list_head
*dapm_kcontrol_get_path_list(
479 const struct snd_kcontrol
*kcontrol
)
481 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
486 #define dapm_kcontrol_for_each_path(path, kcontrol) \
487 list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \
490 unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol
*kcontrol
)
492 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
496 EXPORT_SYMBOL_GPL(dapm_kcontrol_get_value
);
498 static bool dapm_kcontrol_set_value(const struct snd_kcontrol
*kcontrol
,
501 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
503 if (data
->value
== value
)
507 data
->widget
->on_val
= value
;
515 * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a
517 * @kcontrol: The kcontrol
519 * Note: This function must only be used on kcontrols that are known to have
520 * been registered for a CODEC. Otherwise the behaviour is undefined.
522 struct snd_soc_dapm_context
*snd_soc_dapm_kcontrol_dapm(
523 struct snd_kcontrol
*kcontrol
)
525 return dapm_kcontrol_get_wlist(kcontrol
)->widgets
[0]->dapm
;
527 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm
);
529 static void dapm_reset(struct snd_soc_card
*card
)
531 struct snd_soc_dapm_widget
*w
;
533 lockdep_assert_held(&card
->dapm_mutex
);
535 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
537 list_for_each_entry(w
, &card
->widgets
, list
) {
538 w
->new_power
= w
->power
;
539 w
->power_checked
= false;
543 static const char *soc_dapm_prefix(struct snd_soc_dapm_context
*dapm
)
545 if (!dapm
->component
)
547 return dapm
->component
->name_prefix
;
550 static int soc_dapm_read(struct snd_soc_dapm_context
*dapm
, int reg
,
553 if (!dapm
->component
)
555 return snd_soc_component_read(dapm
->component
, reg
, value
);
558 static int soc_dapm_update_bits(struct snd_soc_dapm_context
*dapm
,
559 int reg
, unsigned int mask
, unsigned int value
)
561 if (!dapm
->component
)
563 return snd_soc_component_update_bits(dapm
->component
, reg
,
567 static int soc_dapm_test_bits(struct snd_soc_dapm_context
*dapm
,
568 int reg
, unsigned int mask
, unsigned int value
)
570 if (!dapm
->component
)
572 return snd_soc_component_test_bits(dapm
->component
, reg
, mask
, value
);
575 static void soc_dapm_async_complete(struct snd_soc_dapm_context
*dapm
)
578 snd_soc_component_async_complete(dapm
->component
);
581 static struct snd_soc_dapm_widget
*
582 dapm_wcache_lookup(struct snd_soc_dapm_wcache
*wcache
, const char *name
)
584 struct snd_soc_dapm_widget
*w
= wcache
->widget
;
585 struct list_head
*wlist
;
590 wlist
= &w
->dapm
->card
->widgets
;
592 list_for_each_entry_from(w
, wlist
, list
) {
593 if (!strcmp(name
, w
->name
))
604 static inline void dapm_wcache_update(struct snd_soc_dapm_wcache
*wcache
,
605 struct snd_soc_dapm_widget
*w
)
611 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
612 * @dapm: The DAPM context for which to set the level
613 * @level: The level to set
615 * Forces the DAPM bias level to a specific state. It will call the bias level
616 * callback of DAPM context with the specified level. This will even happen if
617 * the context is already at the same level. Furthermore it will not go through
618 * the normal bias level sequencing, meaning any intermediate states between the
619 * current and the target state will not be entered.
621 * Note that the change in bias level is only temporary and the next time
622 * snd_soc_dapm_sync() is called the state will be set to the level as
623 * determined by the DAPM core. The function is mainly intended to be used to
624 * used during probe or resume from suspend to power up the device so
625 * initialization can be done, before the DAPM core takes over.
627 int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context
*dapm
,
628 enum snd_soc_bias_level level
)
632 if (dapm
->set_bias_level
)
633 ret
= dapm
->set_bias_level(dapm
, level
);
636 dapm
->bias_level
= level
;
640 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_bias_level
);
643 * snd_soc_dapm_set_bias_level - set the bias level for the system
644 * @dapm: DAPM context
645 * @level: level to configure
647 * Configure the bias (power) levels for the SoC audio device.
649 * Returns 0 for success else error.
651 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
652 enum snd_soc_bias_level level
)
654 struct snd_soc_card
*card
= dapm
->card
;
657 trace_snd_soc_bias_level_start(card
, level
);
659 if (card
&& card
->set_bias_level
)
660 ret
= card
->set_bias_level(card
, dapm
, level
);
664 if (!card
|| dapm
!= &card
->dapm
)
665 ret
= snd_soc_dapm_force_bias_level(dapm
, level
);
670 if (card
&& card
->set_bias_level_post
)
671 ret
= card
->set_bias_level_post(card
, dapm
, level
);
673 trace_snd_soc_bias_level_done(card
, level
);
678 /* connect mux widget to its interconnecting audio paths */
679 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
680 struct snd_soc_dapm_path
*path
, const char *control_name
,
681 struct snd_soc_dapm_widget
*w
)
683 const struct snd_kcontrol_new
*kcontrol
= &w
->kcontrol_news
[0];
684 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
685 unsigned int val
, item
;
688 if (e
->reg
!= SND_SOC_NOPM
) {
689 soc_dapm_read(dapm
, e
->reg
, &val
);
690 val
= (val
>> e
->shift_l
) & e
->mask
;
691 item
= snd_soc_enum_val_to_item(e
, val
);
693 /* since a virtual mux has no backing registers to
694 * decide which path to connect, it will try to match
695 * with the first enumeration. This is to ensure
696 * that the default mux choice (the first) will be
697 * correctly powered up during initialization.
702 for (i
= 0; i
< e
->items
; i
++) {
703 if (!(strcmp(control_name
, e
->texts
[i
]))) {
704 path
->name
= e
->texts
[i
];
716 /* set up initial codec paths */
717 static void dapm_set_mixer_path_status(struct snd_soc_dapm_path
*p
, int i
)
719 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
720 p
->sink
->kcontrol_news
[i
].private_value
;
721 unsigned int reg
= mc
->reg
;
722 unsigned int shift
= mc
->shift
;
723 unsigned int max
= mc
->max
;
724 unsigned int mask
= (1 << fls(max
)) - 1;
725 unsigned int invert
= mc
->invert
;
728 if (reg
!= SND_SOC_NOPM
) {
729 soc_dapm_read(p
->sink
->dapm
, reg
, &val
);
730 val
= (val
>> shift
) & mask
;
739 /* connect mixer widget to its interconnecting audio paths */
740 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
741 struct snd_soc_dapm_path
*path
, const char *control_name
)
745 /* search for mixer kcontrol */
746 for (i
= 0; i
< path
->sink
->num_kcontrols
; i
++) {
747 if (!strcmp(control_name
, path
->sink
->kcontrol_news
[i
].name
)) {
748 path
->name
= path
->sink
->kcontrol_news
[i
].name
;
749 dapm_set_mixer_path_status(path
, i
);
756 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
757 struct snd_soc_dapm_widget
*kcontrolw
,
758 const struct snd_kcontrol_new
*kcontrol_new
,
759 struct snd_kcontrol
**kcontrol
)
761 struct snd_soc_dapm_widget
*w
;
766 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
767 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
769 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
770 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
772 *kcontrol
= w
->kcontrols
[i
];
782 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
783 * create it. Either way, add the widget into the control's widget list
785 static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget
*w
,
788 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
789 struct snd_card
*card
= dapm
->card
->snd_card
;
793 struct snd_kcontrol
*kcontrol
;
794 bool wname_in_long_name
, kcname_in_long_name
;
795 char *long_name
= NULL
;
799 prefix
= soc_dapm_prefix(dapm
);
801 prefix_len
= strlen(prefix
) + 1;
805 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[kci
],
810 wname_in_long_name
= false;
811 kcname_in_long_name
= true;
814 case snd_soc_dapm_switch
:
815 case snd_soc_dapm_mixer
:
816 wname_in_long_name
= true;
817 kcname_in_long_name
= true;
819 case snd_soc_dapm_mixer_named_ctl
:
820 wname_in_long_name
= false;
821 kcname_in_long_name
= true;
823 case snd_soc_dapm_demux
:
824 case snd_soc_dapm_mux
:
825 wname_in_long_name
= true;
826 kcname_in_long_name
= false;
833 if (wname_in_long_name
&& kcname_in_long_name
) {
835 * The control will get a prefix from the control
836 * creation process but we're also using the same
837 * prefix for widgets so cut the prefix off the
838 * front of the widget name.
840 long_name
= kasprintf(GFP_KERNEL
, "%s %s",
841 w
->name
+ prefix_len
,
842 w
->kcontrol_news
[kci
].name
);
843 if (long_name
== NULL
)
847 } else if (wname_in_long_name
) {
849 name
= w
->name
+ prefix_len
;
852 name
= w
->kcontrol_news
[kci
].name
;
855 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[kci
], NULL
, name
,
862 kcontrol
->private_free
= dapm_kcontrol_free
;
864 ret
= dapm_kcontrol_data_alloc(w
, kcontrol
);
866 snd_ctl_free_one(kcontrol
);
870 ret
= snd_ctl_add(card
, kcontrol
);
873 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
879 ret
= dapm_kcontrol_add_widget(kcontrol
, w
);
881 w
->kcontrols
[kci
] = kcontrol
;
889 /* create new dapm mixer control */
890 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
893 struct snd_soc_dapm_path
*path
;
894 struct dapm_kcontrol_data
*data
;
897 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
899 list_for_each_entry(path
, &w
->sources
, list_sink
) {
900 /* mixer/mux paths name must match control name */
901 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
904 if (!w
->kcontrols
[i
]) {
905 ret
= dapm_create_or_share_mixmux_kcontrol(w
, i
);
910 dapm_kcontrol_add_path(w
->kcontrols
[i
], path
);
912 data
= snd_kcontrol_chip(w
->kcontrols
[i
]);
914 snd_soc_dapm_add_path(data
->widget
->dapm
,
924 /* create new dapm mux control */
925 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
927 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
928 struct snd_soc_dapm_path
*path
;
929 struct list_head
*paths
;
934 case snd_soc_dapm_mux
:
938 case snd_soc_dapm_demux
:
946 if (w
->num_kcontrols
!= 1) {
948 "ASoC: %s %s has incorrect number of controls\n", type
,
953 if (list_empty(paths
)) {
954 dev_err(dapm
->dev
, "ASoC: %s %s has no paths\n", type
, w
->name
);
958 ret
= dapm_create_or_share_mixmux_kcontrol(w
, 0);
962 if (w
->id
== snd_soc_dapm_mux
) {
963 list_for_each_entry(path
, &w
->sources
, list_sink
) {
965 dapm_kcontrol_add_path(w
->kcontrols
[0], path
);
968 list_for_each_entry(path
, &w
->sinks
, list_source
) {
970 dapm_kcontrol_add_path(w
->kcontrols
[0], path
);
977 /* create new dapm volume control */
978 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
980 if (w
->num_kcontrols
)
981 dev_err(w
->dapm
->dev
,
982 "ASoC: PGA controls not supported: '%s'\n", w
->name
);
987 /* create new dapm dai link control */
988 static int dapm_new_dai_link(struct snd_soc_dapm_widget
*w
)
991 struct snd_kcontrol
*kcontrol
;
992 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
993 struct snd_card
*card
= dapm
->card
->snd_card
;
995 /* create control for links with > 1 config */
996 if (w
->num_params
<= 1)
1000 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
1001 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
], w
,
1003 ret
= snd_ctl_add(card
, kcontrol
);
1006 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
1007 w
->name
, w
->kcontrol_news
[i
].name
, ret
);
1010 kcontrol
->private_data
= w
;
1011 w
->kcontrols
[i
] = kcontrol
;
1017 /* We implement power down on suspend by checking the power state of
1018 * the ALSA card - when we are suspending the ALSA state for the card
1021 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
1023 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
1026 case SNDRV_CTL_POWER_D3hot
:
1027 case SNDRV_CTL_POWER_D3cold
:
1028 if (widget
->ignore_suspend
)
1029 dev_dbg(widget
->dapm
->dev
, "ASoC: %s ignoring suspend\n",
1031 return widget
->ignore_suspend
;
1037 /* add widget to list if it's not already in the list */
1038 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
1039 struct snd_soc_dapm_widget
*w
)
1041 struct snd_soc_dapm_widget_list
*wlist
;
1042 int wlistsize
, wlistentries
, i
;
1049 /* is this widget already in the list */
1050 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
1051 if (wlist
->widgets
[i
] == w
)
1055 /* allocate some new space */
1056 wlistentries
= wlist
->num_widgets
+ 1;
1057 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
1058 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
1059 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
1060 if (*list
== NULL
) {
1061 dev_err(w
->dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
1067 /* insert the widget */
1068 dev_dbg(w
->dapm
->dev
, "ASoC: added %s in widget list pos %d\n",
1069 w
->name
, wlist
->num_widgets
);
1071 wlist
->widgets
[wlist
->num_widgets
] = w
;
1072 wlist
->num_widgets
++;
1077 * Recursively check for a completed path to an active or physically connected
1078 * output widget. Returns number of complete paths.
1080 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
1081 struct snd_soc_dapm_widget_list
**list
)
1083 struct snd_soc_dapm_path
*path
;
1086 if (widget
->outputs
>= 0)
1087 return widget
->outputs
;
1089 DAPM_UPDATE_STAT(widget
, path_checks
);
1091 if (widget
->is_sink
&& widget
->connected
) {
1092 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
1093 return widget
->outputs
;
1096 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
1097 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1099 if (path
->weak
|| path
->is_supply
)
1105 trace_snd_soc_dapm_output_path(widget
, path
);
1107 if (path
->connect
) {
1110 /* do we need to add this widget to the list ? */
1113 err
= dapm_list_add_widget(list
, path
->sink
);
1115 dev_err(widget
->dapm
->dev
,
1116 "ASoC: could not add widget %s\n",
1123 con
+= is_connected_output_ep(path
->sink
, list
);
1129 widget
->outputs
= con
;
1135 * Recursively check for a completed path to an active or physically connected
1136 * input widget. Returns number of complete paths.
1138 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
1139 struct snd_soc_dapm_widget_list
**list
)
1141 struct snd_soc_dapm_path
*path
;
1144 if (widget
->inputs
>= 0)
1145 return widget
->inputs
;
1147 DAPM_UPDATE_STAT(widget
, path_checks
);
1149 if (widget
->is_source
&& widget
->connected
) {
1150 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1151 return widget
->inputs
;
1154 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
1155 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1157 if (path
->weak
|| path
->is_supply
)
1163 trace_snd_soc_dapm_input_path(widget
, path
);
1165 if (path
->connect
) {
1168 /* do we need to add this widget to the list ? */
1171 err
= dapm_list_add_widget(list
, path
->source
);
1173 dev_err(widget
->dapm
->dev
,
1174 "ASoC: could not add widget %s\n",
1181 con
+= is_connected_input_ep(path
->source
, list
);
1187 widget
->inputs
= con
;
1193 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1194 * @dai: the soc DAI.
1195 * @stream: stream direction.
1196 * @list: list of active widgets for this stream.
1198 * Queries DAPM graph as to whether an valid audio stream path exists for
1199 * the initial stream specified by name. This takes into account
1200 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1202 * Returns the number of valid paths or negative error.
1204 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1205 struct snd_soc_dapm_widget_list
**list
)
1207 struct snd_soc_card
*card
= dai
->component
->card
;
1208 struct snd_soc_dapm_widget
*w
;
1211 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1214 * For is_connected_{output,input}_ep fully discover the graph we need
1215 * to reset the cached number of inputs and outputs.
1217 list_for_each_entry(w
, &card
->widgets
, list
) {
1222 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1223 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
1225 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
1227 trace_snd_soc_dapm_connected(paths
, stream
);
1228 mutex_unlock(&card
->dapm_mutex
);
1234 * Handler for regulator supply widget.
1236 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1237 struct snd_kcontrol
*kcontrol
, int event
)
1241 soc_dapm_async_complete(w
->dapm
);
1243 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1244 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1245 ret
= regulator_allow_bypass(w
->regulator
, false);
1247 dev_warn(w
->dapm
->dev
,
1248 "ASoC: Failed to unbypass %s: %d\n",
1252 return regulator_enable(w
->regulator
);
1254 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1255 ret
= regulator_allow_bypass(w
->regulator
, true);
1257 dev_warn(w
->dapm
->dev
,
1258 "ASoC: Failed to bypass %s: %d\n",
1262 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1265 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1268 * Handler for clock supply widget.
1270 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1271 struct snd_kcontrol
*kcontrol
, int event
)
1276 soc_dapm_async_complete(w
->dapm
);
1278 #ifdef CONFIG_HAVE_CLK
1279 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1280 return clk_prepare_enable(w
->clk
);
1282 clk_disable_unprepare(w
->clk
);
1288 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1290 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1292 if (w
->power_checked
)
1293 return w
->new_power
;
1298 w
->new_power
= w
->power_check(w
);
1300 w
->power_checked
= true;
1302 return w
->new_power
;
1305 /* Generic check to see if a widget should be powered.
1307 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1311 DAPM_UPDATE_STAT(w
, power_checks
);
1313 in
= is_connected_input_ep(w
, NULL
);
1314 out
= is_connected_output_ep(w
, NULL
);
1315 return out
!= 0 && in
!= 0;
1318 /* Check to see if a power supply is needed */
1319 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1321 struct snd_soc_dapm_path
*path
;
1323 DAPM_UPDATE_STAT(w
, power_checks
);
1325 /* Check if one of our outputs is connected */
1326 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1327 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1332 if (path
->connected
&&
1333 !path
->connected(path
->source
, path
->sink
))
1336 if (dapm_widget_power_check(path
->sink
))
1343 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1348 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1349 struct snd_soc_dapm_widget
*b
,
1357 sort
= dapm_down_seq
;
1359 if (sort
[a
->id
] != sort
[b
->id
])
1360 return sort
[a
->id
] - sort
[b
->id
];
1361 if (a
->subseq
!= b
->subseq
) {
1363 return a
->subseq
- b
->subseq
;
1365 return b
->subseq
- a
->subseq
;
1367 if (a
->reg
!= b
->reg
)
1368 return a
->reg
- b
->reg
;
1369 if (a
->dapm
!= b
->dapm
)
1370 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1375 /* Insert a widget in order into a DAPM power sequence. */
1376 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1377 struct list_head
*list
,
1380 struct snd_soc_dapm_widget
*w
;
1382 list_for_each_entry(w
, list
, power_list
)
1383 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1384 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1388 list_add_tail(&new_widget
->power_list
, list
);
1391 static void dapm_seq_check_event(struct snd_soc_card
*card
,
1392 struct snd_soc_dapm_widget
*w
, int event
)
1394 const char *ev_name
;
1398 case SND_SOC_DAPM_PRE_PMU
:
1399 ev_name
= "PRE_PMU";
1402 case SND_SOC_DAPM_POST_PMU
:
1403 ev_name
= "POST_PMU";
1406 case SND_SOC_DAPM_PRE_PMD
:
1407 ev_name
= "PRE_PMD";
1410 case SND_SOC_DAPM_POST_PMD
:
1411 ev_name
= "POST_PMD";
1414 case SND_SOC_DAPM_WILL_PMU
:
1415 ev_name
= "WILL_PMU";
1418 case SND_SOC_DAPM_WILL_PMD
:
1419 ev_name
= "WILL_PMD";
1423 WARN(1, "Unknown event %d\n", event
);
1427 if (w
->new_power
!= power
)
1430 if (w
->event
&& (w
->event_flags
& event
)) {
1431 pop_dbg(w
->dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1433 soc_dapm_async_complete(w
->dapm
);
1434 trace_snd_soc_dapm_widget_event_start(w
, event
);
1435 ret
= w
->event(w
, NULL
, event
);
1436 trace_snd_soc_dapm_widget_event_done(w
, event
);
1438 dev_err(w
->dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1439 ev_name
, w
->name
, ret
);
1443 /* Apply the coalesced changes from a DAPM sequence */
1444 static void dapm_seq_run_coalesced(struct snd_soc_card
*card
,
1445 struct list_head
*pending
)
1447 struct snd_soc_dapm_context
*dapm
;
1448 struct snd_soc_dapm_widget
*w
;
1450 unsigned int value
= 0;
1451 unsigned int mask
= 0;
1453 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
, power_list
);
1457 list_for_each_entry(w
, pending
, power_list
) {
1458 WARN_ON(reg
!= w
->reg
|| dapm
!= w
->dapm
);
1459 w
->power
= w
->new_power
;
1461 mask
|= w
->mask
<< w
->shift
;
1463 value
|= w
->on_val
<< w
->shift
;
1465 value
|= w
->off_val
<< w
->shift
;
1467 pop_dbg(dapm
->dev
, card
->pop_time
,
1468 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1469 w
->name
, reg
, value
, mask
);
1471 /* Check for events */
1472 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMU
);
1473 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMD
);
1477 /* Any widget will do, they should all be updating the
1481 pop_dbg(dapm
->dev
, card
->pop_time
,
1482 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1483 value
, mask
, reg
, card
->pop_time
);
1484 pop_wait(card
->pop_time
);
1485 soc_dapm_update_bits(dapm
, reg
, mask
, value
);
1488 list_for_each_entry(w
, pending
, power_list
) {
1489 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMU
);
1490 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMD
);
1494 /* Apply a DAPM power sequence.
1496 * We walk over a pre-sorted list of widgets to apply power to. In
1497 * order to minimise the number of writes to the device required
1498 * multiple widgets will be updated in a single write where possible.
1499 * Currently anything that requires more than a single write is not
1502 static void dapm_seq_run(struct snd_soc_card
*card
,
1503 struct list_head
*list
, int event
, bool power_up
)
1505 struct snd_soc_dapm_widget
*w
, *n
;
1506 struct snd_soc_dapm_context
*d
;
1509 int cur_subseq
= -1;
1510 int cur_reg
= SND_SOC_NOPM
;
1511 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1518 sort
= dapm_down_seq
;
1520 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1523 /* Do we need to apply any queued changes? */
1524 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1525 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1526 if (!list_empty(&pending
))
1527 dapm_seq_run_coalesced(card
, &pending
);
1529 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1530 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1531 if (sort
[i
] == cur_sort
)
1532 cur_dapm
->seq_notifier(cur_dapm
,
1537 if (cur_dapm
&& w
->dapm
!= cur_dapm
)
1538 soc_dapm_async_complete(cur_dapm
);
1540 INIT_LIST_HEAD(&pending
);
1542 cur_subseq
= INT_MIN
;
1543 cur_reg
= SND_SOC_NOPM
;
1548 case snd_soc_dapm_pre
:
1550 list_for_each_entry_safe_continue(w
, n
, list
,
1553 if (event
== SND_SOC_DAPM_STREAM_START
)
1555 NULL
, SND_SOC_DAPM_PRE_PMU
);
1556 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1558 NULL
, SND_SOC_DAPM_PRE_PMD
);
1561 case snd_soc_dapm_post
:
1563 list_for_each_entry_safe_continue(w
, n
, list
,
1566 if (event
== SND_SOC_DAPM_STREAM_START
)
1568 NULL
, SND_SOC_DAPM_POST_PMU
);
1569 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1571 NULL
, SND_SOC_DAPM_POST_PMD
);
1575 /* Queue it up for application */
1576 cur_sort
= sort
[w
->id
];
1577 cur_subseq
= w
->subseq
;
1580 list_move(&w
->power_list
, &pending
);
1585 dev_err(w
->dapm
->dev
,
1586 "ASoC: Failed to apply widget power: %d\n", ret
);
1589 if (!list_empty(&pending
))
1590 dapm_seq_run_coalesced(card
, &pending
);
1592 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1593 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1594 if (sort
[i
] == cur_sort
)
1595 cur_dapm
->seq_notifier(cur_dapm
,
1599 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1600 soc_dapm_async_complete(d
);
1604 static void dapm_widget_update(struct snd_soc_card
*card
)
1606 struct snd_soc_dapm_update
*update
= card
->update
;
1607 struct snd_soc_dapm_widget_list
*wlist
;
1608 struct snd_soc_dapm_widget
*w
= NULL
;
1612 if (!update
|| !dapm_kcontrol_is_powered(update
->kcontrol
))
1615 wlist
= dapm_kcontrol_get_wlist(update
->kcontrol
);
1617 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1618 w
= wlist
->widgets
[wi
];
1620 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1621 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1623 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1631 ret
= soc_dapm_update_bits(w
->dapm
, update
->reg
, update
->mask
,
1634 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1637 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1638 w
= wlist
->widgets
[wi
];
1640 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1641 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1643 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1649 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1650 * they're changing state.
1652 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1654 struct snd_soc_dapm_context
*d
= data
;
1657 /* If we're off and we're not supposed to be go into STANDBY */
1658 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1659 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1661 pm_runtime_get_sync(d
->dev
);
1663 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1666 "ASoC: Failed to turn on bias: %d\n", ret
);
1669 /* Prepare for a transition to ON or away from ON */
1670 if ((d
->target_bias_level
== SND_SOC_BIAS_ON
&&
1671 d
->bias_level
!= SND_SOC_BIAS_ON
) ||
1672 (d
->target_bias_level
!= SND_SOC_BIAS_ON
&&
1673 d
->bias_level
== SND_SOC_BIAS_ON
)) {
1674 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1677 "ASoC: Failed to prepare bias: %d\n", ret
);
1681 /* Async callback run prior to DAPM sequences - brings to their final
1684 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1686 struct snd_soc_dapm_context
*d
= data
;
1689 /* If we just powered the last thing off drop to standby bias */
1690 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1691 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1692 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1693 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1695 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1699 /* If we're in standby and can support bias off then do that */
1700 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1701 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1702 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1704 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1708 pm_runtime_put(d
->dev
);
1711 /* If we just powered up then move to active bias */
1712 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1713 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1714 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1716 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1721 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1722 bool power
, bool connect
)
1724 /* If a connection is being made or broken then that update
1725 * will have marked the peer dirty, otherwise the widgets are
1726 * not connected and this update has no impact. */
1730 /* If the peer is already in the state we're moving to then we
1731 * won't have an impact on it. */
1732 if (power
!= peer
->power
)
1733 dapm_mark_dirty(peer
, "peer state change");
1736 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1737 struct list_head
*up_list
,
1738 struct list_head
*down_list
)
1740 struct snd_soc_dapm_path
*path
;
1742 if (w
->power
== power
)
1745 trace_snd_soc_dapm_widget_power(w
, power
);
1747 /* If we changed our power state perhaps our neigbours changed
1750 list_for_each_entry(path
, &w
->sources
, list_sink
)
1751 dapm_widget_set_peer_power(path
->source
, power
, path
->connect
);
1753 /* Supplies can't affect their outputs, only their inputs */
1754 if (!w
->is_supply
) {
1755 list_for_each_entry(path
, &w
->sinks
, list_source
)
1756 dapm_widget_set_peer_power(path
->sink
, power
,
1761 dapm_seq_insert(w
, up_list
, true);
1763 dapm_seq_insert(w
, down_list
, false);
1766 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1767 struct list_head
*up_list
,
1768 struct list_head
*down_list
)
1773 case snd_soc_dapm_pre
:
1774 dapm_seq_insert(w
, down_list
, false);
1776 case snd_soc_dapm_post
:
1777 dapm_seq_insert(w
, up_list
, true);
1781 power
= dapm_widget_power_check(w
);
1783 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1788 static bool dapm_idle_bias_off(struct snd_soc_dapm_context
*dapm
)
1790 if (dapm
->idle_bias_off
)
1793 switch (snd_power_get_state(dapm
->card
->snd_card
)) {
1794 case SNDRV_CTL_POWER_D3hot
:
1795 case SNDRV_CTL_POWER_D3cold
:
1796 return dapm
->suspend_bias_off
;
1805 * Scan each dapm widget for complete audio path.
1806 * A complete path is a route that has valid endpoints i.e.:-
1808 * o DAC to output pin.
1809 * o Input Pin to ADC.
1810 * o Input pin to Output pin (bypass, sidetone)
1811 * o DAC to ADC (loopback).
1813 static int dapm_power_widgets(struct snd_soc_card
*card
, int event
)
1815 struct snd_soc_dapm_widget
*w
;
1816 struct snd_soc_dapm_context
*d
;
1818 LIST_HEAD(down_list
);
1819 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1820 enum snd_soc_bias_level bias
;
1822 lockdep_assert_held(&card
->dapm_mutex
);
1824 trace_snd_soc_dapm_start(card
);
1826 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1827 if (dapm_idle_bias_off(d
))
1828 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1830 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1835 /* Check which widgets we need to power and store them in
1836 * lists indicating if they should be powered up or down. We
1837 * only check widgets that have been flagged as dirty but note
1838 * that new widgets may be added to the dirty list while we
1841 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1842 dapm_power_one_widget(w
, &up_list
, &down_list
);
1845 list_for_each_entry(w
, &card
->widgets
, list
) {
1847 case snd_soc_dapm_pre
:
1848 case snd_soc_dapm_post
:
1849 /* These widgets always need to be powered */
1852 list_del_init(&w
->dirty
);
1859 /* Supplies and micbiases only bring the
1860 * context up to STANDBY as unless something
1861 * else is active and passing audio they
1862 * generally don't require full power. Signal
1863 * generators are virtual pins and have no
1864 * power impact themselves.
1867 case snd_soc_dapm_siggen
:
1868 case snd_soc_dapm_vmid
:
1870 case snd_soc_dapm_supply
:
1871 case snd_soc_dapm_regulator_supply
:
1872 case snd_soc_dapm_clock_supply
:
1873 case snd_soc_dapm_micbias
:
1874 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1875 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1878 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1885 /* Force all contexts in the card to the same bias state if
1886 * they're not ground referenced.
1888 bias
= SND_SOC_BIAS_OFF
;
1889 list_for_each_entry(d
, &card
->dapm_list
, list
)
1890 if (d
->target_bias_level
> bias
)
1891 bias
= d
->target_bias_level
;
1892 list_for_each_entry(d
, &card
->dapm_list
, list
)
1893 if (!dapm_idle_bias_off(d
))
1894 d
->target_bias_level
= bias
;
1896 trace_snd_soc_dapm_walk_done(card
);
1898 /* Run card bias changes at first */
1899 dapm_pre_sequence_async(&card
->dapm
, 0);
1900 /* Run other bias changes in parallel */
1901 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1902 if (d
!= &card
->dapm
)
1903 async_schedule_domain(dapm_pre_sequence_async
, d
,
1906 async_synchronize_full_domain(&async_domain
);
1908 list_for_each_entry(w
, &down_list
, power_list
) {
1909 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMD
);
1912 list_for_each_entry(w
, &up_list
, power_list
) {
1913 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMU
);
1916 /* Power down widgets first; try to avoid amplifying pops. */
1917 dapm_seq_run(card
, &down_list
, event
, false);
1919 dapm_widget_update(card
);
1922 dapm_seq_run(card
, &up_list
, event
, true);
1924 /* Run all the bias changes in parallel */
1925 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1926 if (d
!= &card
->dapm
)
1927 async_schedule_domain(dapm_post_sequence_async
, d
,
1930 async_synchronize_full_domain(&async_domain
);
1931 /* Run card bias changes at last */
1932 dapm_post_sequence_async(&card
->dapm
, 0);
1934 /* do we need to notify any clients that DAPM event is complete */
1935 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1936 if (d
->stream_event
)
1937 d
->stream_event(d
, event
);
1940 pop_dbg(card
->dev
, card
->pop_time
,
1941 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1942 pop_wait(card
->pop_time
);
1944 trace_snd_soc_dapm_done(card
);
1949 #ifdef CONFIG_DEBUG_FS
1950 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1951 char __user
*user_buf
,
1952 size_t count
, loff_t
*ppos
)
1954 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1955 struct snd_soc_card
*card
= w
->dapm
->card
;
1959 struct snd_soc_dapm_path
*p
= NULL
;
1961 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1965 mutex_lock(&card
->dapm_mutex
);
1967 /* Supply widgets are not handled by is_connected_{input,output}_ep() */
1972 in
= is_connected_input_ep(w
, NULL
);
1973 out
= is_connected_output_ep(w
, NULL
);
1976 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1977 w
->name
, w
->power
? "On" : "Off",
1978 w
->force
? " (forced)" : "", in
, out
);
1981 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1982 " - R%d(0x%x) mask 0x%x",
1983 w
->reg
, w
->reg
, w
->mask
<< w
->shift
);
1985 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1988 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1990 w
->active
? "active" : "inactive");
1992 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1993 if (p
->connected
&& !p
->connected(w
, p
->source
))
1997 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1998 " in \"%s\" \"%s\"\n",
1999 p
->name
? p
->name
: "static",
2002 list_for_each_entry(p
, &w
->sinks
, list_source
) {
2003 if (p
->connected
&& !p
->connected(w
, p
->sink
))
2007 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
2008 " out \"%s\" \"%s\"\n",
2009 p
->name
? p
->name
: "static",
2013 mutex_unlock(&card
->dapm_mutex
);
2015 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
2021 static const struct file_operations dapm_widget_power_fops
= {
2022 .open
= simple_open
,
2023 .read
= dapm_widget_power_read_file
,
2024 .llseek
= default_llseek
,
2027 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
2028 size_t count
, loff_t
*ppos
)
2030 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
2033 switch (dapm
->bias_level
) {
2034 case SND_SOC_BIAS_ON
:
2037 case SND_SOC_BIAS_PREPARE
:
2038 level
= "Prepare\n";
2040 case SND_SOC_BIAS_STANDBY
:
2041 level
= "Standby\n";
2043 case SND_SOC_BIAS_OFF
:
2047 WARN(1, "Unknown bias_level %d\n", dapm
->bias_level
);
2048 level
= "Unknown\n";
2052 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
2056 static const struct file_operations dapm_bias_fops
= {
2057 .open
= simple_open
,
2058 .read
= dapm_bias_read_file
,
2059 .llseek
= default_llseek
,
2062 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2063 struct dentry
*parent
)
2070 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
2072 if (!dapm
->debugfs_dapm
) {
2074 "ASoC: Failed to create DAPM debugfs directory\n");
2078 d
= debugfs_create_file("bias_level", 0444,
2079 dapm
->debugfs_dapm
, dapm
,
2083 "ASoC: Failed to create bias level debugfs file\n");
2086 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2088 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
2091 if (!dapm
->debugfs_dapm
|| !w
->name
)
2094 d
= debugfs_create_file(w
->name
, 0444,
2095 dapm
->debugfs_dapm
, w
,
2096 &dapm_widget_power_fops
);
2098 dev_warn(w
->dapm
->dev
,
2099 "ASoC: Failed to create %s debugfs file\n",
2103 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2105 debugfs_remove_recursive(dapm
->debugfs_dapm
);
2109 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2110 struct dentry
*parent
)
2114 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2118 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2125 * soc_dapm_connect_path() - Connects or disconnects a path
2126 * @path: The path to update
2127 * @connect: The new connect state of the path. True if the path is connected,
2128 * false if it is disconneted.
2129 * @reason: The reason why the path changed (for debugging only)
2131 static void soc_dapm_connect_path(struct snd_soc_dapm_path
*path
,
2132 bool connect
, const char *reason
)
2134 if (path
->connect
== connect
)
2137 path
->connect
= connect
;
2138 dapm_mark_dirty(path
->source
, reason
);
2139 dapm_mark_dirty(path
->sink
, reason
);
2140 dapm_path_invalidate(path
);
2143 /* test and update the power status of a mux widget */
2144 static int soc_dapm_mux_update_power(struct snd_soc_card
*card
,
2145 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
2147 struct snd_soc_dapm_path
*path
;
2151 lockdep_assert_held(&card
->dapm_mutex
);
2153 /* find dapm widget path assoc with kcontrol */
2154 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2156 /* we now need to match the string in the enum to the path */
2157 if (!(strcmp(path
->name
, e
->texts
[mux
])))
2162 soc_dapm_connect_path(path
, connect
, "mux update");
2166 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2171 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context
*dapm
,
2172 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
,
2173 struct snd_soc_dapm_update
*update
)
2175 struct snd_soc_card
*card
= dapm
->card
;
2178 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2179 card
->update
= update
;
2180 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
2181 card
->update
= NULL
;
2182 mutex_unlock(&card
->dapm_mutex
);
2184 soc_dpcm_runtime_update(card
);
2187 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
2189 /* test and update the power status of a mixer or switch widget */
2190 static int soc_dapm_mixer_update_power(struct snd_soc_card
*card
,
2191 struct snd_kcontrol
*kcontrol
, int connect
)
2193 struct snd_soc_dapm_path
*path
;
2196 lockdep_assert_held(&card
->dapm_mutex
);
2198 /* find dapm widget path assoc with kcontrol */
2199 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2201 soc_dapm_connect_path(path
, connect
, "mixer update");
2205 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2210 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context
*dapm
,
2211 struct snd_kcontrol
*kcontrol
, int connect
,
2212 struct snd_soc_dapm_update
*update
)
2214 struct snd_soc_card
*card
= dapm
->card
;
2217 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2218 card
->update
= update
;
2219 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
2220 card
->update
= NULL
;
2221 mutex_unlock(&card
->dapm_mutex
);
2223 soc_dpcm_runtime_update(card
);
2226 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2228 static ssize_t
dapm_widget_show_codec(struct snd_soc_codec
*codec
, char *buf
)
2230 struct snd_soc_dapm_widget
*w
;
2232 char *state
= "not set";
2234 list_for_each_entry(w
, &codec
->component
.card
->widgets
, list
) {
2235 if (w
->dapm
!= &codec
->dapm
)
2238 /* only display widgets that burnm power */
2240 case snd_soc_dapm_hp
:
2241 case snd_soc_dapm_mic
:
2242 case snd_soc_dapm_spk
:
2243 case snd_soc_dapm_line
:
2244 case snd_soc_dapm_micbias
:
2245 case snd_soc_dapm_dac
:
2246 case snd_soc_dapm_adc
:
2247 case snd_soc_dapm_pga
:
2248 case snd_soc_dapm_out_drv
:
2249 case snd_soc_dapm_mixer
:
2250 case snd_soc_dapm_mixer_named_ctl
:
2251 case snd_soc_dapm_supply
:
2252 case snd_soc_dapm_regulator_supply
:
2253 case snd_soc_dapm_clock_supply
:
2255 count
+= sprintf(buf
+ count
, "%s: %s\n",
2256 w
->name
, w
->power
? "On":"Off");
2263 switch (codec
->dapm
.bias_level
) {
2264 case SND_SOC_BIAS_ON
:
2267 case SND_SOC_BIAS_PREPARE
:
2270 case SND_SOC_BIAS_STANDBY
:
2273 case SND_SOC_BIAS_OFF
:
2277 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2282 /* show dapm widget status in sys fs */
2283 static ssize_t
dapm_widget_show(struct device
*dev
,
2284 struct device_attribute
*attr
, char *buf
)
2286 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2289 mutex_lock(&rtd
->card
->dapm_mutex
);
2291 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
2292 struct snd_soc_codec
*codec
= rtd
->codec_dais
[i
]->codec
;
2293 count
+= dapm_widget_show_codec(codec
, buf
+ count
);
2296 mutex_unlock(&rtd
->card
->dapm_mutex
);
2301 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2303 struct attribute
*soc_dapm_dev_attrs
[] = {
2304 &dev_attr_dapm_widget
.attr
,
2308 static void dapm_free_path(struct snd_soc_dapm_path
*path
)
2310 list_del(&path
->list_sink
);
2311 list_del(&path
->list_source
);
2312 list_del(&path
->list_kcontrol
);
2313 list_del(&path
->list
);
2317 /* free all dapm widgets and resources */
2318 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2320 struct snd_soc_dapm_widget
*w
, *next_w
;
2321 struct snd_soc_dapm_path
*p
, *next_p
;
2323 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2324 if (w
->dapm
!= dapm
)
2328 * remove source and sink paths associated to this widget.
2329 * While removing the path, remove reference to it from both
2330 * source and sink widgets so that path is removed only once.
2332 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
)
2335 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
)
2338 kfree(w
->kcontrols
);
2344 static struct snd_soc_dapm_widget
*dapm_find_widget(
2345 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2346 bool search_other_contexts
)
2348 struct snd_soc_dapm_widget
*w
;
2349 struct snd_soc_dapm_widget
*fallback
= NULL
;
2351 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2352 if (!strcmp(w
->name
, pin
)) {
2353 if (w
->dapm
== dapm
)
2360 if (search_other_contexts
)
2366 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2367 const char *pin
, int status
)
2369 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2371 dapm_assert_locked(dapm
);
2374 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2378 if (w
->connected
!= status
) {
2379 dapm_mark_dirty(w
, "pin configuration");
2380 dapm_widget_invalidate_input_paths(w
);
2381 dapm_widget_invalidate_output_paths(w
);
2384 w
->connected
= status
;
2392 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2393 * @dapm: DAPM context
2395 * Walks all dapm audio paths and powers widgets according to their
2396 * stream or path usage.
2398 * Requires external locking.
2400 * Returns 0 for success.
2402 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context
*dapm
)
2405 * Suppress early reports (eg, jacks syncing their state) to avoid
2406 * silly DAPM runs during card startup.
2408 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2411 return dapm_power_widgets(dapm
->card
, SND_SOC_DAPM_STREAM_NOP
);
2413 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked
);
2416 * snd_soc_dapm_sync - scan and power dapm paths
2417 * @dapm: DAPM context
2419 * Walks all dapm audio paths and powers widgets according to their
2420 * stream or path usage.
2422 * Returns 0 for success.
2424 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2428 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2429 ret
= snd_soc_dapm_sync_unlocked(dapm
);
2430 mutex_unlock(&dapm
->card
->dapm_mutex
);
2433 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2436 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2437 * @w: The widget for which to update the flags
2439 * Some widgets have a dynamic category which depends on which neighbors they
2440 * are connected to. This function update the category for these widgets.
2442 * This function must be called whenever a path is added or removed to a widget.
2444 static void dapm_update_widget_flags(struct snd_soc_dapm_widget
*w
)
2446 struct snd_soc_dapm_path
*p
;
2449 case snd_soc_dapm_input
:
2450 /* On a fully routed card a input is never a source */
2451 if (w
->dapm
->card
->fully_routed
)
2454 list_for_each_entry(p
, &w
->sources
, list_sink
) {
2455 if (p
->source
->id
== snd_soc_dapm_micbias
||
2456 p
->source
->id
== snd_soc_dapm_mic
||
2457 p
->source
->id
== snd_soc_dapm_line
||
2458 p
->source
->id
== snd_soc_dapm_output
) {
2464 case snd_soc_dapm_output
:
2465 /* On a fully routed card a output is never a sink */
2466 if (w
->dapm
->card
->fully_routed
)
2469 list_for_each_entry(p
, &w
->sinks
, list_source
) {
2470 if (p
->sink
->id
== snd_soc_dapm_spk
||
2471 p
->sink
->id
== snd_soc_dapm_hp
||
2472 p
->sink
->id
== snd_soc_dapm_line
||
2473 p
->sink
->id
== snd_soc_dapm_input
) {
2479 case snd_soc_dapm_line
:
2480 w
->is_sink
= !list_empty(&w
->sources
);
2481 w
->is_source
= !list_empty(&w
->sinks
);
2488 static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context
*dapm
,
2489 struct snd_soc_dapm_widget
*source
, struct snd_soc_dapm_widget
*sink
,
2490 const char *control
)
2492 bool dynamic_source
= false;
2493 bool dynamic_sink
= false;
2498 switch (source
->id
) {
2499 case snd_soc_dapm_demux
:
2500 dynamic_source
= true;
2507 case snd_soc_dapm_mux
:
2508 case snd_soc_dapm_switch
:
2509 case snd_soc_dapm_mixer
:
2510 case snd_soc_dapm_mixer_named_ctl
:
2511 dynamic_sink
= true;
2517 if (dynamic_source
&& dynamic_sink
) {
2519 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n",
2520 source
->name
, control
, sink
->name
);
2522 } else if (!dynamic_source
&& !dynamic_sink
) {
2524 "Control not supported for path %s -> [%s] -> %s\n",
2525 source
->name
, control
, sink
->name
);
2532 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
2533 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
2534 const char *control
,
2535 int (*connected
)(struct snd_soc_dapm_widget
*source
,
2536 struct snd_soc_dapm_widget
*sink
))
2538 struct snd_soc_dapm_path
*path
;
2541 if (wsink
->is_supply
&& !wsource
->is_supply
) {
2543 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n",
2544 wsource
->name
, wsink
->name
);
2548 if (connected
&& !wsource
->is_supply
) {
2550 "connected() callback only supported for supply widgets (%s -> %s)\n",
2551 wsource
->name
, wsink
->name
);
2555 if (wsource
->is_supply
&& control
) {
2557 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n",
2558 wsource
->name
, control
, wsink
->name
);
2562 ret
= snd_soc_dapm_check_dynamic_path(dapm
, wsource
, wsink
, control
);
2566 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2570 path
->source
= wsource
;
2572 path
->connected
= connected
;
2573 INIT_LIST_HEAD(&path
->list
);
2574 INIT_LIST_HEAD(&path
->list_kcontrol
);
2575 INIT_LIST_HEAD(&path
->list_source
);
2576 INIT_LIST_HEAD(&path
->list_sink
);
2578 if (wsource
->is_supply
|| wsink
->is_supply
)
2579 path
->is_supply
= 1;
2581 /* connect static paths */
2582 if (control
== NULL
) {
2585 switch (wsource
->id
) {
2586 case snd_soc_dapm_demux
:
2587 ret
= dapm_connect_mux(dapm
, path
, control
, wsource
);
2595 switch (wsink
->id
) {
2596 case snd_soc_dapm_mux
:
2597 ret
= dapm_connect_mux(dapm
, path
, control
, wsink
);
2601 case snd_soc_dapm_switch
:
2602 case snd_soc_dapm_mixer
:
2603 case snd_soc_dapm_mixer_named_ctl
:
2604 ret
= dapm_connect_mixer(dapm
, path
, control
);
2613 list_add(&path
->list
, &dapm
->card
->paths
);
2614 list_add(&path
->list_sink
, &wsink
->sources
);
2615 list_add(&path
->list_source
, &wsource
->sinks
);
2617 dapm_update_widget_flags(wsource
);
2618 dapm_update_widget_flags(wsink
);
2620 dapm_mark_dirty(wsource
, "Route added");
2621 dapm_mark_dirty(wsink
, "Route added");
2623 if (dapm
->card
->instantiated
&& path
->connect
)
2624 dapm_path_invalidate(path
);
2632 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2633 const struct snd_soc_dapm_route
*route
)
2635 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2636 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2639 char prefixed_sink
[80];
2640 char prefixed_source
[80];
2644 prefix
= soc_dapm_prefix(dapm
);
2646 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2647 prefix
, route
->sink
);
2648 sink
= prefixed_sink
;
2649 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2650 prefix
, route
->source
);
2651 source
= prefixed_source
;
2654 source
= route
->source
;
2657 wsource
= dapm_wcache_lookup(&dapm
->path_source_cache
, source
);
2658 wsink
= dapm_wcache_lookup(&dapm
->path_sink_cache
, sink
);
2660 if (wsink
&& wsource
)
2664 * find src and dest widgets over all widgets but favor a widget from
2665 * current DAPM context
2667 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2668 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2670 if (w
->dapm
== dapm
) {
2677 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2679 if (w
->dapm
== dapm
) {
2686 /* use widget from another DAPM context if not found from this */
2692 if (wsource
== NULL
) {
2693 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2697 if (wsink
== NULL
) {
2698 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2704 dapm_wcache_update(&dapm
->path_sink_cache
, wsink
);
2705 dapm_wcache_update(&dapm
->path_source_cache
, wsource
);
2707 ret
= snd_soc_dapm_add_path(dapm
, wsource
, wsink
, route
->control
,
2714 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2715 source
, route
->control
, sink
);
2719 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2720 const struct snd_soc_dapm_route
*route
)
2722 struct snd_soc_dapm_widget
*wsource
, *wsink
;
2723 struct snd_soc_dapm_path
*path
, *p
;
2726 char prefixed_sink
[80];
2727 char prefixed_source
[80];
2730 if (route
->control
) {
2732 "ASoC: Removal of routes with controls not supported\n");
2736 prefix
= soc_dapm_prefix(dapm
);
2738 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2739 prefix
, route
->sink
);
2740 sink
= prefixed_sink
;
2741 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2742 prefix
, route
->source
);
2743 source
= prefixed_source
;
2746 source
= route
->source
;
2750 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2751 if (strcmp(p
->source
->name
, source
) != 0)
2753 if (strcmp(p
->sink
->name
, sink
) != 0)
2760 wsource
= path
->source
;
2763 dapm_mark_dirty(wsource
, "Route removed");
2764 dapm_mark_dirty(wsink
, "Route removed");
2766 dapm_path_invalidate(path
);
2768 dapm_free_path(path
);
2770 /* Update any path related flags */
2771 dapm_update_widget_flags(wsource
);
2772 dapm_update_widget_flags(wsink
);
2774 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
2782 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2783 * @dapm: DAPM context
2784 * @route: audio routes
2785 * @num: number of routes
2787 * Connects 2 dapm widgets together via a named audio path. The sink is
2788 * the widget receiving the audio signal, whilst the source is the sender
2789 * of the audio signal.
2791 * Returns 0 for success else error. On error all resources can be freed
2792 * with a call to snd_soc_card_free().
2794 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2795 const struct snd_soc_dapm_route
*route
, int num
)
2799 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2800 for (i
= 0; i
< num
; i
++) {
2801 r
= snd_soc_dapm_add_route(dapm
, route
);
2803 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
2805 route
->control
? route
->control
: "direct",
2811 mutex_unlock(&dapm
->card
->dapm_mutex
);
2815 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2818 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2819 * @dapm: DAPM context
2820 * @route: audio routes
2821 * @num: number of routes
2823 * Removes routes from the DAPM context.
2825 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2826 const struct snd_soc_dapm_route
*route
, int num
)
2830 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2831 for (i
= 0; i
< num
; i
++) {
2832 snd_soc_dapm_del_route(dapm
, route
);
2835 mutex_unlock(&dapm
->card
->dapm_mutex
);
2839 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2841 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2842 const struct snd_soc_dapm_route
*route
)
2844 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2847 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2850 struct snd_soc_dapm_path
*path
;
2854 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
2860 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
2865 if (route
->control
|| route
->connected
)
2866 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
2867 route
->source
, route
->sink
);
2869 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2870 if (path
->sink
== sink
) {
2877 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
2878 route
->source
, route
->sink
);
2880 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
2881 count
, route
->source
, route
->sink
);
2887 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2888 * @dapm: DAPM context
2889 * @route: audio routes
2890 * @num: number of routes
2892 * Mark existing routes matching those specified in the passed array
2893 * as being weak, meaning that they are ignored for the purpose of
2894 * power decisions. The main intended use case is for sidetone paths
2895 * which couple audio between other independent paths if they are both
2896 * active in order to make the combination work better at the user
2897 * level but which aren't intended to be "used".
2899 * Note that CODEC drivers should not use this as sidetone type paths
2900 * can frequently also be used as bypass paths.
2902 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2903 const struct snd_soc_dapm_route
*route
, int num
)
2908 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2909 for (i
= 0; i
< num
; i
++) {
2910 err
= snd_soc_dapm_weak_route(dapm
, route
);
2915 mutex_unlock(&dapm
->card
->dapm_mutex
);
2919 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2922 * snd_soc_dapm_new_widgets - add new dapm widgets
2923 * @dapm: DAPM context
2925 * Checks the codec for any new dapm widgets and creates them if found.
2927 * Returns 0 for success.
2929 int snd_soc_dapm_new_widgets(struct snd_soc_card
*card
)
2931 struct snd_soc_dapm_widget
*w
;
2934 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2936 list_for_each_entry(w
, &card
->widgets
, list
)
2941 if (w
->num_kcontrols
) {
2942 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2943 sizeof(struct snd_kcontrol
*),
2945 if (!w
->kcontrols
) {
2946 mutex_unlock(&card
->dapm_mutex
);
2952 case snd_soc_dapm_switch
:
2953 case snd_soc_dapm_mixer
:
2954 case snd_soc_dapm_mixer_named_ctl
:
2957 case snd_soc_dapm_mux
:
2958 case snd_soc_dapm_demux
:
2961 case snd_soc_dapm_pga
:
2962 case snd_soc_dapm_out_drv
:
2965 case snd_soc_dapm_dai_link
:
2966 dapm_new_dai_link(w
);
2972 /* Read the initial power state from the device */
2974 soc_dapm_read(w
->dapm
, w
->reg
, &val
);
2975 val
= val
>> w
->shift
;
2977 if (val
== w
->on_val
)
2983 dapm_mark_dirty(w
, "new widget");
2984 dapm_debugfs_add_widget(w
);
2987 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2988 mutex_unlock(&card
->dapm_mutex
);
2991 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2994 * snd_soc_dapm_get_volsw - dapm mixer get callback
2995 * @kcontrol: mixer control
2996 * @ucontrol: control element information
2998 * Callback to get the value of a dapm mixer control.
3000 * Returns 0 for success.
3002 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
3003 struct snd_ctl_elem_value
*ucontrol
)
3005 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3006 struct snd_soc_card
*card
= dapm
->card
;
3007 struct soc_mixer_control
*mc
=
3008 (struct soc_mixer_control
*)kcontrol
->private_value
;
3010 unsigned int shift
= mc
->shift
;
3012 unsigned int mask
= (1 << fls(max
)) - 1;
3013 unsigned int invert
= mc
->invert
;
3017 if (snd_soc_volsw_is_stereo(mc
))
3019 "ASoC: Control '%s' is stereo, which is not supported\n",
3022 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3023 if (dapm_kcontrol_is_powered(kcontrol
) && reg
!= SND_SOC_NOPM
) {
3024 ret
= soc_dapm_read(dapm
, reg
, &val
);
3025 val
= (val
>> shift
) & mask
;
3027 val
= dapm_kcontrol_get_value(kcontrol
);
3029 mutex_unlock(&card
->dapm_mutex
);
3032 ucontrol
->value
.integer
.value
[0] = max
- val
;
3034 ucontrol
->value
.integer
.value
[0] = val
;
3038 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
3041 * snd_soc_dapm_put_volsw - dapm mixer set callback
3042 * @kcontrol: mixer control
3043 * @ucontrol: control element information
3045 * Callback to set the value of a dapm mixer control.
3047 * Returns 0 for success.
3049 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
3050 struct snd_ctl_elem_value
*ucontrol
)
3052 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3053 struct snd_soc_card
*card
= dapm
->card
;
3054 struct soc_mixer_control
*mc
=
3055 (struct soc_mixer_control
*)kcontrol
->private_value
;
3057 unsigned int shift
= mc
->shift
;
3059 unsigned int mask
= (1 << fls(max
)) - 1;
3060 unsigned int invert
= mc
->invert
;
3062 int connect
, change
, reg_change
= 0;
3063 struct snd_soc_dapm_update update
;
3066 if (snd_soc_volsw_is_stereo(mc
))
3068 "ASoC: Control '%s' is stereo, which is not supported\n",
3071 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
3077 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3079 change
= dapm_kcontrol_set_value(kcontrol
, val
);
3081 if (reg
!= SND_SOC_NOPM
) {
3082 mask
= mask
<< shift
;
3085 reg_change
= soc_dapm_test_bits(dapm
, reg
, mask
, val
);
3088 if (change
|| reg_change
) {
3090 update
.kcontrol
= kcontrol
;
3094 card
->update
= &update
;
3096 change
|= reg_change
;
3098 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
3100 card
->update
= NULL
;
3103 mutex_unlock(&card
->dapm_mutex
);
3106 soc_dpcm_runtime_update(card
);
3110 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
3113 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3114 * @kcontrol: mixer control
3115 * @ucontrol: control element information
3117 * Callback to get the value of a dapm enumerated double mixer control.
3119 * Returns 0 for success.
3121 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
3122 struct snd_ctl_elem_value
*ucontrol
)
3124 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3125 struct snd_soc_card
*card
= dapm
->card
;
3126 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3127 unsigned int reg_val
, val
;
3129 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3130 if (e
->reg
!= SND_SOC_NOPM
&& dapm_kcontrol_is_powered(kcontrol
)) {
3131 int ret
= soc_dapm_read(dapm
, e
->reg
, ®_val
);
3133 mutex_unlock(&card
->dapm_mutex
);
3137 reg_val
= dapm_kcontrol_get_value(kcontrol
);
3139 mutex_unlock(&card
->dapm_mutex
);
3141 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
3142 ucontrol
->value
.enumerated
.item
[0] = snd_soc_enum_val_to_item(e
, val
);
3143 if (e
->shift_l
!= e
->shift_r
) {
3144 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
3145 val
= snd_soc_enum_val_to_item(e
, val
);
3146 ucontrol
->value
.enumerated
.item
[1] = val
;
3151 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
3154 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3155 * @kcontrol: mixer control
3156 * @ucontrol: control element information
3158 * Callback to set the value of a dapm enumerated double mixer control.
3160 * Returns 0 for success.
3162 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
3163 struct snd_ctl_elem_value
*ucontrol
)
3165 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3166 struct snd_soc_card
*card
= dapm
->card
;
3167 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3168 unsigned int *item
= ucontrol
->value
.enumerated
.item
;
3169 unsigned int val
, change
, reg_change
= 0;
3171 struct snd_soc_dapm_update update
;
3174 if (item
[0] >= e
->items
)
3177 val
= snd_soc_enum_item_to_val(e
, item
[0]) << e
->shift_l
;
3178 mask
= e
->mask
<< e
->shift_l
;
3179 if (e
->shift_l
!= e
->shift_r
) {
3180 if (item
[1] > e
->items
)
3182 val
|= snd_soc_enum_item_to_val(e
, item
[1]) << e
->shift_l
;
3183 mask
|= e
->mask
<< e
->shift_r
;
3186 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3188 change
= dapm_kcontrol_set_value(kcontrol
, val
);
3190 if (e
->reg
!= SND_SOC_NOPM
)
3191 reg_change
= soc_dapm_test_bits(dapm
, e
->reg
, mask
, val
);
3193 if (change
|| reg_change
) {
3195 update
.kcontrol
= kcontrol
;
3196 update
.reg
= e
->reg
;
3199 card
->update
= &update
;
3201 change
|= reg_change
;
3203 ret
= soc_dapm_mux_update_power(card
, kcontrol
, item
[0], e
);
3205 card
->update
= NULL
;
3208 mutex_unlock(&card
->dapm_mutex
);
3211 soc_dpcm_runtime_update(card
);
3215 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
3218 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3220 * @kcontrol: mixer control
3221 * @uinfo: control element information
3223 * Callback to provide information about a pin switch control.
3225 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
3226 struct snd_ctl_elem_info
*uinfo
)
3228 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3230 uinfo
->value
.integer
.min
= 0;
3231 uinfo
->value
.integer
.max
= 1;
3235 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3238 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3240 * @kcontrol: mixer control
3243 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3244 struct snd_ctl_elem_value
*ucontrol
)
3246 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3247 const char *pin
= (const char *)kcontrol
->private_value
;
3249 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3251 ucontrol
->value
.integer
.value
[0] =
3252 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3254 mutex_unlock(&card
->dapm_mutex
);
3258 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3261 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3263 * @kcontrol: mixer control
3266 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3267 struct snd_ctl_elem_value
*ucontrol
)
3269 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3270 const char *pin
= (const char *)kcontrol
->private_value
;
3272 if (ucontrol
->value
.integer
.value
[0])
3273 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3275 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3277 snd_soc_dapm_sync(&card
->dapm
);
3280 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3282 struct snd_soc_dapm_widget
*
3283 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3284 const struct snd_soc_dapm_widget
*widget
)
3286 struct snd_soc_dapm_widget
*w
;
3288 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3289 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3292 "ASoC: Failed to create DAPM control %s\n",
3295 mutex_unlock(&dapm
->card
->dapm_mutex
);
3299 struct snd_soc_dapm_widget
*
3300 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context
*dapm
,
3301 const struct snd_soc_dapm_widget
*widget
)
3303 struct snd_soc_dapm_widget
*w
;
3307 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3311 case snd_soc_dapm_regulator_supply
:
3312 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3313 if (IS_ERR(w
->regulator
)) {
3314 ret
= PTR_ERR(w
->regulator
);
3315 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3320 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3321 ret
= regulator_allow_bypass(w
->regulator
, true);
3323 dev_warn(w
->dapm
->dev
,
3324 "ASoC: Failed to bypass %s: %d\n",
3328 case snd_soc_dapm_clock_supply
:
3329 #ifdef CONFIG_CLKDEV_LOOKUP
3330 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3331 if (IS_ERR(w
->clk
)) {
3332 ret
= PTR_ERR(w
->clk
);
3333 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3345 prefix
= soc_dapm_prefix(dapm
);
3347 w
->name
= kasprintf(GFP_KERNEL
, "%s %s", prefix
, widget
->name
);
3349 w
->sname
= kasprintf(GFP_KERNEL
, "%s %s", prefix
,
3352 w
->name
= kasprintf(GFP_KERNEL
, "%s", widget
->name
);
3354 w
->sname
= kasprintf(GFP_KERNEL
, "%s", widget
->sname
);
3356 if (w
->name
== NULL
) {
3362 case snd_soc_dapm_mic
:
3364 w
->power_check
= dapm_generic_check_power
;
3366 case snd_soc_dapm_input
:
3367 if (!dapm
->card
->fully_routed
)
3369 w
->power_check
= dapm_generic_check_power
;
3371 case snd_soc_dapm_spk
:
3372 case snd_soc_dapm_hp
:
3374 w
->power_check
= dapm_generic_check_power
;
3376 case snd_soc_dapm_output
:
3377 if (!dapm
->card
->fully_routed
)
3379 w
->power_check
= dapm_generic_check_power
;
3381 case snd_soc_dapm_vmid
:
3382 case snd_soc_dapm_siggen
:
3384 w
->power_check
= dapm_always_on_check_power
;
3386 case snd_soc_dapm_mux
:
3387 case snd_soc_dapm_demux
:
3388 case snd_soc_dapm_switch
:
3389 case snd_soc_dapm_mixer
:
3390 case snd_soc_dapm_mixer_named_ctl
:
3391 case snd_soc_dapm_adc
:
3392 case snd_soc_dapm_aif_out
:
3393 case snd_soc_dapm_dac
:
3394 case snd_soc_dapm_aif_in
:
3395 case snd_soc_dapm_pga
:
3396 case snd_soc_dapm_out_drv
:
3397 case snd_soc_dapm_micbias
:
3398 case snd_soc_dapm_line
:
3399 case snd_soc_dapm_dai_link
:
3400 case snd_soc_dapm_dai_out
:
3401 case snd_soc_dapm_dai_in
:
3402 w
->power_check
= dapm_generic_check_power
;
3404 case snd_soc_dapm_supply
:
3405 case snd_soc_dapm_regulator_supply
:
3406 case snd_soc_dapm_clock_supply
:
3407 case snd_soc_dapm_kcontrol
:
3409 w
->power_check
= dapm_supply_check_power
;
3412 w
->power_check
= dapm_always_on_check_power
;
3417 INIT_LIST_HEAD(&w
->sources
);
3418 INIT_LIST_HEAD(&w
->sinks
);
3419 INIT_LIST_HEAD(&w
->list
);
3420 INIT_LIST_HEAD(&w
->dirty
);
3421 list_add_tail(&w
->list
, &dapm
->card
->widgets
);
3426 /* machine layer set ups unconnected pins and insertions */
3432 * snd_soc_dapm_new_controls - create new dapm controls
3433 * @dapm: DAPM context
3434 * @widget: widget array
3435 * @num: number of widgets
3437 * Creates new DAPM controls based upon the templates.
3439 * Returns 0 for success else error.
3441 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3442 const struct snd_soc_dapm_widget
*widget
,
3445 struct snd_soc_dapm_widget
*w
;
3449 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3450 for (i
= 0; i
< num
; i
++) {
3451 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3454 "ASoC: Failed to create DAPM control %s\n",
3461 mutex_unlock(&dapm
->card
->dapm_mutex
);
3464 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3466 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3467 struct snd_kcontrol
*kcontrol
, int event
)
3469 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3470 struct snd_soc_dai
*source
, *sink
;
3471 const struct snd_soc_pcm_stream
*config
= w
->params
+ w
->params_select
;
3472 struct snd_pcm_substream substream
;
3473 struct snd_pcm_hw_params
*params
= NULL
;
3477 if (WARN_ON(!config
) ||
3478 WARN_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
)))
3481 /* We only support a single source and sink, pick the first */
3482 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3484 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3487 if (WARN_ON(!source_p
|| !sink_p
) ||
3488 WARN_ON(!sink_p
->source
|| !source_p
->sink
) ||
3489 WARN_ON(!source_p
->source
|| !sink_p
->sink
))
3492 source
= source_p
->source
->priv
;
3493 sink
= sink_p
->sink
->priv
;
3495 /* Be a little careful as we don't want to overflow the mask array */
3496 if (config
->formats
) {
3497 fmt
= ffs(config
->formats
) - 1;
3499 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3504 /* Currently very limited parameter selection */
3505 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3510 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3512 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3514 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3517 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3518 = config
->channels_min
;
3519 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3520 = config
->channels_max
;
3522 memset(&substream
, 0, sizeof(substream
));
3525 case SND_SOC_DAPM_PRE_PMU
:
3526 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3527 ret
= soc_dai_hw_params(&substream
, params
, source
);
3531 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3532 ret
= soc_dai_hw_params(&substream
, params
, sink
);
3537 case SND_SOC_DAPM_POST_PMU
:
3538 ret
= snd_soc_dai_digital_mute(sink
, 0,
3539 SNDRV_PCM_STREAM_PLAYBACK
);
3540 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3541 dev_warn(sink
->dev
, "ASoC: Failed to unmute: %d\n", ret
);
3545 case SND_SOC_DAPM_PRE_PMD
:
3546 ret
= snd_soc_dai_digital_mute(sink
, 1,
3547 SNDRV_PCM_STREAM_PLAYBACK
);
3548 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3549 dev_warn(sink
->dev
, "ASoC: Failed to mute: %d\n", ret
);
3554 WARN(1, "Unknown event %d\n", event
);
3563 static int snd_soc_dapm_dai_link_get(struct snd_kcontrol
*kcontrol
,
3564 struct snd_ctl_elem_value
*ucontrol
)
3566 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
3568 ucontrol
->value
.integer
.value
[0] = w
->params_select
;
3573 static int snd_soc_dapm_dai_link_put(struct snd_kcontrol
*kcontrol
,
3574 struct snd_ctl_elem_value
*ucontrol
)
3576 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
3578 /* Can't change the config when widget is already powered */
3582 if (ucontrol
->value
.integer
.value
[0] == w
->params_select
)
3585 if (ucontrol
->value
.integer
.value
[0] >= w
->num_params
)
3588 w
->params_select
= ucontrol
->value
.integer
.value
[0];
3593 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3594 const struct snd_soc_pcm_stream
*params
,
3595 unsigned int num_params
,
3596 struct snd_soc_dapm_widget
*source
,
3597 struct snd_soc_dapm_widget
*sink
)
3599 struct snd_soc_dapm_widget
template;
3600 struct snd_soc_dapm_widget
*w
;
3603 unsigned long private_value
;
3604 const char **w_param_text
;
3605 struct soc_enum w_param_enum
[] = {
3606 SOC_ENUM_SINGLE(0, 0, 0, NULL
),
3608 struct snd_kcontrol_new kcontrol_dai_link
[] = {
3609 SOC_ENUM_EXT(NULL
, w_param_enum
[0],
3610 snd_soc_dapm_dai_link_get
,
3611 snd_soc_dapm_dai_link_put
),
3613 const struct snd_soc_pcm_stream
*config
= params
;
3615 w_param_text
= devm_kcalloc(card
->dev
, num_params
,
3616 sizeof(char *), GFP_KERNEL
);
3620 link_name
= devm_kasprintf(card
->dev
, GFP_KERNEL
, "%s-%s",
3621 source
->name
, sink
->name
);
3624 goto outfree_w_param
;
3627 for (count
= 0 ; count
< num_params
; count
++) {
3628 if (!config
->stream_name
) {
3629 dev_warn(card
->dapm
.dev
,
3630 "ASoC: anonymous config %d for dai link %s\n",
3632 w_param_text
[count
] =
3633 devm_kasprintf(card
->dev
, GFP_KERNEL
,
3634 "Anonymous Configuration %d",
3636 if (!w_param_text
[count
]) {
3638 goto outfree_link_name
;
3641 w_param_text
[count
] = devm_kmemdup(card
->dev
,
3642 config
->stream_name
,
3643 strlen(config
->stream_name
) + 1,
3645 if (!w_param_text
[count
]) {
3647 goto outfree_link_name
;
3652 w_param_enum
[0].items
= num_params
;
3653 w_param_enum
[0].texts
= w_param_text
;
3655 memset(&template, 0, sizeof(template));
3656 template.reg
= SND_SOC_NOPM
;
3657 template.id
= snd_soc_dapm_dai_link
;
3658 template.name
= link_name
;
3659 template.event
= snd_soc_dai_link_event
;
3660 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3661 SND_SOC_DAPM_PRE_PMD
;
3662 template.num_kcontrols
= 1;
3663 /* duplicate w_param_enum on heap so that memory persists */
3665 (unsigned long) devm_kmemdup(card
->dev
,
3666 (void *)(kcontrol_dai_link
[0].private_value
),
3667 sizeof(struct soc_enum
), GFP_KERNEL
);
3668 if (!private_value
) {
3669 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
3672 goto outfree_link_name
;
3674 kcontrol_dai_link
[0].private_value
= private_value
;
3675 /* duplicate kcontrol_dai_link on heap so that memory persists */
3676 template.kcontrol_news
=
3677 devm_kmemdup(card
->dev
, &kcontrol_dai_link
[0],
3678 sizeof(struct snd_kcontrol_new
),
3680 if (!template.kcontrol_news
) {
3681 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
3684 goto outfree_private_value
;
3687 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
3689 w
= snd_soc_dapm_new_control_unlocked(&card
->dapm
, &template);
3691 dev_err(card
->dev
, "ASoC: Failed to create %s widget\n",
3694 goto outfree_kcontrol_news
;
3698 w
->num_params
= num_params
;
3700 ret
= snd_soc_dapm_add_path(&card
->dapm
, source
, w
, NULL
, NULL
);
3703 return snd_soc_dapm_add_path(&card
->dapm
, w
, sink
, NULL
, NULL
);
3706 devm_kfree(card
->dev
, w
);
3707 outfree_kcontrol_news
:
3708 devm_kfree(card
->dev
, (void *)template.kcontrol_news
);
3709 outfree_private_value
:
3710 devm_kfree(card
->dev
, (void *)private_value
);
3712 devm_kfree(card
->dev
, link_name
);
3714 for (count
= 0 ; count
< num_params
; count
++)
3715 devm_kfree(card
->dev
, (void *)w_param_text
[count
]);
3716 devm_kfree(card
->dev
, w_param_text
);
3721 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3722 struct snd_soc_dai
*dai
)
3724 struct snd_soc_dapm_widget
template;
3725 struct snd_soc_dapm_widget
*w
;
3727 WARN_ON(dapm
->dev
!= dai
->dev
);
3729 memset(&template, 0, sizeof(template));
3730 template.reg
= SND_SOC_NOPM
;
3732 if (dai
->driver
->playback
.stream_name
) {
3733 template.id
= snd_soc_dapm_dai_in
;
3734 template.name
= dai
->driver
->playback
.stream_name
;
3735 template.sname
= dai
->driver
->playback
.stream_name
;
3737 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3740 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
3742 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3743 dai
->driver
->playback
.stream_name
);
3748 dai
->playback_widget
= w
;
3751 if (dai
->driver
->capture
.stream_name
) {
3752 template.id
= snd_soc_dapm_dai_out
;
3753 template.name
= dai
->driver
->capture
.stream_name
;
3754 template.sname
= dai
->driver
->capture
.stream_name
;
3756 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3759 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
3761 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3762 dai
->driver
->capture
.stream_name
);
3767 dai
->capture_widget
= w
;
3773 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3775 struct snd_soc_dapm_widget
*dai_w
, *w
;
3776 struct snd_soc_dapm_widget
*src
, *sink
;
3777 struct snd_soc_dai
*dai
;
3779 /* For each DAI widget... */
3780 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3781 switch (dai_w
->id
) {
3782 case snd_soc_dapm_dai_in
:
3783 case snd_soc_dapm_dai_out
:
3791 /* ...find all widgets with the same stream and link them */
3792 list_for_each_entry(w
, &card
->widgets
, list
) {
3793 if (w
->dapm
!= dai_w
->dapm
)
3797 case snd_soc_dapm_dai_in
:
3798 case snd_soc_dapm_dai_out
:
3804 if (!w
->sname
|| !strstr(w
->sname
, dai_w
->name
))
3807 if (dai_w
->id
== snd_soc_dapm_dai_in
) {
3814 dev_dbg(dai
->dev
, "%s -> %s\n", src
->name
, sink
->name
);
3815 snd_soc_dapm_add_path(w
->dapm
, src
, sink
, NULL
, NULL
);
3822 static void dapm_connect_dai_link_widgets(struct snd_soc_card
*card
,
3823 struct snd_soc_pcm_runtime
*rtd
)
3825 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3826 struct snd_soc_dapm_widget
*sink
, *source
;
3829 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
3830 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[i
];
3832 /* there is no point in connecting BE DAI links with dummies */
3833 if (snd_soc_dai_is_dummy(codec_dai
) ||
3834 snd_soc_dai_is_dummy(cpu_dai
))
3837 /* connect BE DAI playback if widgets are valid */
3838 if (codec_dai
->playback_widget
&& cpu_dai
->playback_widget
) {
3839 source
= cpu_dai
->playback_widget
;
3840 sink
= codec_dai
->playback_widget
;
3841 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3842 cpu_dai
->component
->name
, source
->name
,
3843 codec_dai
->component
->name
, sink
->name
);
3845 snd_soc_dapm_add_path(&card
->dapm
, source
, sink
,
3849 /* connect BE DAI capture if widgets are valid */
3850 if (codec_dai
->capture_widget
&& cpu_dai
->capture_widget
) {
3851 source
= codec_dai
->capture_widget
;
3852 sink
= cpu_dai
->capture_widget
;
3853 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3854 codec_dai
->component
->name
, source
->name
,
3855 cpu_dai
->component
->name
, sink
->name
);
3857 snd_soc_dapm_add_path(&card
->dapm
, source
, sink
,
3863 static void soc_dapm_dai_stream_event(struct snd_soc_dai
*dai
, int stream
,
3866 struct snd_soc_dapm_widget
*w
;
3868 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
3869 w
= dai
->playback_widget
;
3871 w
= dai
->capture_widget
;
3874 dapm_mark_dirty(w
, "stream event");
3877 case SND_SOC_DAPM_STREAM_START
:
3880 case SND_SOC_DAPM_STREAM_STOP
:
3883 case SND_SOC_DAPM_STREAM_SUSPEND
:
3884 case SND_SOC_DAPM_STREAM_RESUME
:
3885 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3886 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3890 if (w
->id
== snd_soc_dapm_dai_in
) {
3891 w
->is_source
= w
->active
;
3892 dapm_widget_invalidate_input_paths(w
);
3894 w
->is_sink
= w
->active
;
3895 dapm_widget_invalidate_output_paths(w
);
3900 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card
*card
)
3902 struct snd_soc_pcm_runtime
*rtd
= card
->rtd
;
3905 /* for each BE DAI link... */
3906 for (i
= 0; i
< card
->num_rtd
; i
++) {
3907 rtd
= &card
->rtd
[i
];
3910 * dynamic FE links have no fixed DAI mapping.
3911 * CODEC<->CODEC links have no direct connection.
3913 if (rtd
->dai_link
->dynamic
|| rtd
->dai_link
->params
)
3916 dapm_connect_dai_link_widgets(card
, rtd
);
3920 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3925 soc_dapm_dai_stream_event(rtd
->cpu_dai
, stream
, event
);
3926 for (i
= 0; i
< rtd
->num_codecs
; i
++)
3927 soc_dapm_dai_stream_event(rtd
->codec_dais
[i
], stream
, event
);
3929 dapm_power_widgets(rtd
->card
, event
);
3933 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3934 * @rtd: PCM runtime data
3935 * @stream: stream name
3936 * @event: stream event
3938 * Sends a stream event to the dapm core. The core then makes any
3939 * necessary widget power changes.
3941 * Returns 0 for success else error.
3943 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3946 struct snd_soc_card
*card
= rtd
->card
;
3948 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3949 soc_dapm_stream_event(rtd
, stream
, event
);
3950 mutex_unlock(&card
->dapm_mutex
);
3954 * snd_soc_dapm_enable_pin_unlocked - enable pin.
3955 * @dapm: DAPM context
3958 * Enables input/output pin and its parents or children widgets iff there is
3959 * a valid audio route and active audio stream.
3961 * Requires external locking.
3963 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3964 * do any widget power switching.
3966 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3969 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3971 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked
);
3974 * snd_soc_dapm_enable_pin - enable pin.
3975 * @dapm: DAPM context
3978 * Enables input/output pin and its parents or children widgets iff there is
3979 * a valid audio route and active audio stream.
3981 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3982 * do any widget power switching.
3984 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3988 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3990 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 1);
3992 mutex_unlock(&dapm
->card
->dapm_mutex
);
3996 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3999 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
4000 * @dapm: DAPM context
4003 * Enables input/output pin regardless of any other state. This is
4004 * intended for use with microphone bias supplies used in microphone
4007 * Requires external locking.
4009 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4010 * do any widget power switching.
4012 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4015 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4018 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4022 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
4023 if (!w
->connected
) {
4025 * w->force does not affect the number of input or output paths,
4026 * so we only have to recheck if w->connected is changed
4028 dapm_widget_invalidate_input_paths(w
);
4029 dapm_widget_invalidate_output_paths(w
);
4033 dapm_mark_dirty(w
, "force enable");
4037 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked
);
4040 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4041 * @dapm: DAPM context
4044 * Enables input/output pin regardless of any other state. This is
4045 * intended for use with microphone bias supplies used in microphone
4048 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4049 * do any widget power switching.
4051 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
4056 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4058 ret
= snd_soc_dapm_force_enable_pin_unlocked(dapm
, pin
);
4060 mutex_unlock(&dapm
->card
->dapm_mutex
);
4064 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
4067 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4068 * @dapm: DAPM context
4071 * Disables input/output pin and its parents or children widgets.
4073 * Requires external locking.
4075 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4076 * do any widget power switching.
4078 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4081 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4083 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked
);
4086 * snd_soc_dapm_disable_pin - disable pin.
4087 * @dapm: DAPM context
4090 * Disables input/output pin and its parents or children widgets.
4092 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4093 * do any widget power switching.
4095 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
4100 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4102 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4104 mutex_unlock(&dapm
->card
->dapm_mutex
);
4108 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
4111 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4112 * @dapm: DAPM context
4115 * Marks the specified pin as being not connected, disabling it along
4116 * any parent or child widgets. At present this is identical to
4117 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4118 * additional things such as disabling controls which only affect
4119 * paths through the pin.
4121 * Requires external locking.
4123 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4124 * do any widget power switching.
4126 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4129 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4131 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked
);
4134 * snd_soc_dapm_nc_pin - permanently disable pin.
4135 * @dapm: DAPM context
4138 * Marks the specified pin as being not connected, disabling it along
4139 * any parent or child widgets. At present this is identical to
4140 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4141 * additional things such as disabling controls which only affect
4142 * paths through the pin.
4144 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4145 * do any widget power switching.
4147 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
4151 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4153 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4155 mutex_unlock(&dapm
->card
->dapm_mutex
);
4159 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
4162 * snd_soc_dapm_get_pin_status - get audio pin status
4163 * @dapm: DAPM context
4164 * @pin: audio signal pin endpoint (or start point)
4166 * Get audio pin status - connected or disconnected.
4168 * Returns 1 for connected otherwise 0.
4170 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
4173 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4176 return w
->connected
;
4180 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
4183 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4184 * @dapm: DAPM context
4185 * @pin: audio signal pin endpoint (or start point)
4187 * Mark the given endpoint or pin as ignoring suspend. When the
4188 * system is disabled a path between two endpoints flagged as ignoring
4189 * suspend will not be disabled. The path must already be enabled via
4190 * normal means at suspend time, it will not be turned on if it was not
4193 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
4196 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
4199 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4203 w
->ignore_suspend
= 1;
4207 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
4210 * snd_soc_dapm_free - free dapm resources
4211 * @dapm: DAPM context
4213 * Free all dapm widgets and resources.
4215 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
4217 dapm_debugfs_cleanup(dapm
);
4218 dapm_free_widgets(dapm
);
4219 list_del(&dapm
->list
);
4221 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
4223 static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context
*dapm
)
4225 struct snd_soc_card
*card
= dapm
->card
;
4226 struct snd_soc_dapm_widget
*w
;
4227 LIST_HEAD(down_list
);
4230 mutex_lock(&card
->dapm_mutex
);
4232 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
4233 if (w
->dapm
!= dapm
)
4236 dapm_seq_insert(w
, &down_list
, false);
4242 /* If there were no widgets to power down we're already in
4246 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
4247 snd_soc_dapm_set_bias_level(dapm
,
4248 SND_SOC_BIAS_PREPARE
);
4249 dapm_seq_run(card
, &down_list
, 0, false);
4250 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
4251 snd_soc_dapm_set_bias_level(dapm
,
4252 SND_SOC_BIAS_STANDBY
);
4255 mutex_unlock(&card
->dapm_mutex
);
4259 * snd_soc_dapm_shutdown - callback for system shutdown
4261 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
4263 struct snd_soc_dapm_context
*dapm
;
4265 list_for_each_entry(dapm
, &card
->dapm_list
, list
) {
4266 if (dapm
!= &card
->dapm
) {
4267 soc_dapm_shutdown_dapm(dapm
);
4268 if (dapm
->bias_level
== SND_SOC_BIAS_STANDBY
)
4269 snd_soc_dapm_set_bias_level(dapm
,
4274 soc_dapm_shutdown_dapm(&card
->dapm
);
4275 if (card
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
4276 snd_soc_dapm_set_bias_level(&card
->dapm
,
4280 /* Module information */
4281 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4282 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
4283 MODULE_LICENSE("GPL");