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
,
368 case snd_soc_dapm_demux
:
369 case snd_soc_dapm_mux
:
370 e
= (struct soc_enum
*)kcontrol
->private_value
;
372 if (e
->autodisable
) {
373 struct snd_soc_dapm_widget
template;
375 name
= kasprintf(GFP_KERNEL
, "%s %s", kcontrol
->id
.name
,
382 memset(&template, 0, sizeof(template));
383 template.reg
= e
->reg
;
384 template.mask
= e
->mask
<< e
->shift_l
;
385 template.shift
= e
->shift_l
;
386 template.off_val
= snd_soc_enum_item_to_val(e
, 0);
387 template.on_val
= template.off_val
;
388 template.id
= snd_soc_dapm_kcontrol
;
389 template.name
= name
;
391 data
->value
= template.on_val
;
393 data
->widget
= snd_soc_dapm_new_control_unlocked(
394 widget
->dapm
, &template);
401 snd_soc_dapm_add_path(widget
->dapm
, data
->widget
,
409 kcontrol
->private_data
= data
;
418 static void dapm_kcontrol_free(struct snd_kcontrol
*kctl
)
420 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kctl
);
425 static struct snd_soc_dapm_widget_list
*dapm_kcontrol_get_wlist(
426 const struct snd_kcontrol
*kcontrol
)
428 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
433 static int dapm_kcontrol_add_widget(struct snd_kcontrol
*kcontrol
,
434 struct snd_soc_dapm_widget
*widget
)
436 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
437 struct snd_soc_dapm_widget_list
*new_wlist
;
441 n
= data
->wlist
->num_widgets
+ 1;
445 new_wlist
= krealloc(data
->wlist
,
446 sizeof(*new_wlist
) + sizeof(widget
) * n
, GFP_KERNEL
);
450 new_wlist
->widgets
[n
- 1] = widget
;
451 new_wlist
->num_widgets
= n
;
453 data
->wlist
= new_wlist
;
458 static void dapm_kcontrol_add_path(const struct snd_kcontrol
*kcontrol
,
459 struct snd_soc_dapm_path
*path
)
461 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
463 list_add_tail(&path
->list_kcontrol
, &data
->paths
);
466 static bool dapm_kcontrol_is_powered(const struct snd_kcontrol
*kcontrol
)
468 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
473 return data
->widget
->power
;
476 static struct list_head
*dapm_kcontrol_get_path_list(
477 const struct snd_kcontrol
*kcontrol
)
479 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
484 #define dapm_kcontrol_for_each_path(path, kcontrol) \
485 list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \
488 unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol
*kcontrol
)
490 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
494 EXPORT_SYMBOL_GPL(dapm_kcontrol_get_value
);
496 static bool dapm_kcontrol_set_value(const struct snd_kcontrol
*kcontrol
,
499 struct dapm_kcontrol_data
*data
= snd_kcontrol_chip(kcontrol
);
501 if (data
->value
== value
)
505 data
->widget
->on_val
= value
;
513 * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a
515 * @kcontrol: The kcontrol
517 * Note: This function must only be used on kcontrols that are known to have
518 * been registered for a CODEC. Otherwise the behaviour is undefined.
520 struct snd_soc_dapm_context
*snd_soc_dapm_kcontrol_dapm(
521 struct snd_kcontrol
*kcontrol
)
523 return dapm_kcontrol_get_wlist(kcontrol
)->widgets
[0]->dapm
;
525 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm
);
527 static void dapm_reset(struct snd_soc_card
*card
)
529 struct snd_soc_dapm_widget
*w
;
531 lockdep_assert_held(&card
->dapm_mutex
);
533 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
535 list_for_each_entry(w
, &card
->widgets
, list
) {
536 w
->new_power
= w
->power
;
537 w
->power_checked
= false;
541 static const char *soc_dapm_prefix(struct snd_soc_dapm_context
*dapm
)
543 if (!dapm
->component
)
545 return dapm
->component
->name_prefix
;
548 static int soc_dapm_read(struct snd_soc_dapm_context
*dapm
, int reg
,
551 if (!dapm
->component
)
553 return snd_soc_component_read(dapm
->component
, reg
, value
);
556 static int soc_dapm_update_bits(struct snd_soc_dapm_context
*dapm
,
557 int reg
, unsigned int mask
, unsigned int value
)
559 if (!dapm
->component
)
561 return snd_soc_component_update_bits(dapm
->component
, reg
,
565 static int soc_dapm_test_bits(struct snd_soc_dapm_context
*dapm
,
566 int reg
, unsigned int mask
, unsigned int value
)
568 if (!dapm
->component
)
570 return snd_soc_component_test_bits(dapm
->component
, reg
, mask
, value
);
573 static void soc_dapm_async_complete(struct snd_soc_dapm_context
*dapm
)
576 snd_soc_component_async_complete(dapm
->component
);
579 static struct snd_soc_dapm_widget
*
580 dapm_wcache_lookup(struct snd_soc_dapm_wcache
*wcache
, const char *name
)
582 struct snd_soc_dapm_widget
*w
= wcache
->widget
;
583 struct list_head
*wlist
;
588 wlist
= &w
->dapm
->card
->widgets
;
590 list_for_each_entry_from(w
, wlist
, list
) {
591 if (!strcmp(name
, w
->name
))
602 static inline void dapm_wcache_update(struct snd_soc_dapm_wcache
*wcache
,
603 struct snd_soc_dapm_widget
*w
)
609 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
610 * @dapm: The DAPM context for which to set the level
611 * @level: The level to set
613 * Forces the DAPM bias level to a specific state. It will call the bias level
614 * callback of DAPM context with the specified level. This will even happen if
615 * the context is already at the same level. Furthermore it will not go through
616 * the normal bias level sequencing, meaning any intermediate states between the
617 * current and the target state will not be entered.
619 * Note that the change in bias level is only temporary and the next time
620 * snd_soc_dapm_sync() is called the state will be set to the level as
621 * determined by the DAPM core. The function is mainly intended to be used to
622 * used during probe or resume from suspend to power up the device so
623 * initialization can be done, before the DAPM core takes over.
625 int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context
*dapm
,
626 enum snd_soc_bias_level level
)
630 if (dapm
->set_bias_level
)
631 ret
= dapm
->set_bias_level(dapm
, level
);
634 dapm
->bias_level
= level
;
638 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_bias_level
);
641 * snd_soc_dapm_set_bias_level - set the bias level for the system
642 * @dapm: DAPM context
643 * @level: level to configure
645 * Configure the bias (power) levels for the SoC audio device.
647 * Returns 0 for success else error.
649 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
650 enum snd_soc_bias_level level
)
652 struct snd_soc_card
*card
= dapm
->card
;
655 trace_snd_soc_bias_level_start(card
, level
);
657 if (card
&& card
->set_bias_level
)
658 ret
= card
->set_bias_level(card
, dapm
, level
);
662 if (!card
|| dapm
!= &card
->dapm
)
663 ret
= snd_soc_dapm_force_bias_level(dapm
, level
);
668 if (card
&& card
->set_bias_level_post
)
669 ret
= card
->set_bias_level_post(card
, dapm
, level
);
671 trace_snd_soc_bias_level_done(card
, level
);
676 /* connect mux widget to its interconnecting audio paths */
677 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
678 struct snd_soc_dapm_path
*path
, const char *control_name
,
679 struct snd_soc_dapm_widget
*w
)
681 const struct snd_kcontrol_new
*kcontrol
= &w
->kcontrol_news
[0];
682 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
683 unsigned int val
, item
;
686 if (e
->reg
!= SND_SOC_NOPM
) {
687 soc_dapm_read(dapm
, e
->reg
, &val
);
688 val
= (val
>> e
->shift_l
) & e
->mask
;
689 item
= snd_soc_enum_val_to_item(e
, val
);
691 /* since a virtual mux has no backing registers to
692 * decide which path to connect, it will try to match
693 * with the first enumeration. This is to ensure
694 * that the default mux choice (the first) will be
695 * correctly powered up during initialization.
700 for (i
= 0; i
< e
->items
; i
++) {
701 if (!(strcmp(control_name
, e
->texts
[i
]))) {
702 path
->name
= e
->texts
[i
];
714 /* set up initial codec paths */
715 static void dapm_set_mixer_path_status(struct snd_soc_dapm_path
*p
, int i
)
717 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
718 p
->sink
->kcontrol_news
[i
].private_value
;
719 unsigned int reg
= mc
->reg
;
720 unsigned int shift
= mc
->shift
;
721 unsigned int max
= mc
->max
;
722 unsigned int mask
= (1 << fls(max
)) - 1;
723 unsigned int invert
= mc
->invert
;
726 if (reg
!= SND_SOC_NOPM
) {
727 soc_dapm_read(p
->sink
->dapm
, reg
, &val
);
728 val
= (val
>> shift
) & mask
;
737 /* connect mixer widget to its interconnecting audio paths */
738 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
739 struct snd_soc_dapm_path
*path
, const char *control_name
)
743 /* search for mixer kcontrol */
744 for (i
= 0; i
< path
->sink
->num_kcontrols
; i
++) {
745 if (!strcmp(control_name
, path
->sink
->kcontrol_news
[i
].name
)) {
746 path
->name
= path
->sink
->kcontrol_news
[i
].name
;
747 dapm_set_mixer_path_status(path
, i
);
754 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
755 struct snd_soc_dapm_widget
*kcontrolw
,
756 const struct snd_kcontrol_new
*kcontrol_new
,
757 struct snd_kcontrol
**kcontrol
)
759 struct snd_soc_dapm_widget
*w
;
764 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
765 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
767 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
768 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
770 *kcontrol
= w
->kcontrols
[i
];
780 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
781 * create it. Either way, add the widget into the control's widget list
783 static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget
*w
,
786 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
787 struct snd_card
*card
= dapm
->card
->snd_card
;
791 struct snd_kcontrol
*kcontrol
;
792 bool wname_in_long_name
, kcname_in_long_name
;
793 char *long_name
= NULL
;
797 prefix
= soc_dapm_prefix(dapm
);
799 prefix_len
= strlen(prefix
) + 1;
803 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[kci
],
808 wname_in_long_name
= false;
809 kcname_in_long_name
= true;
812 case snd_soc_dapm_switch
:
813 case snd_soc_dapm_mixer
:
814 wname_in_long_name
= true;
815 kcname_in_long_name
= true;
817 case snd_soc_dapm_mixer_named_ctl
:
818 wname_in_long_name
= false;
819 kcname_in_long_name
= true;
821 case snd_soc_dapm_demux
:
822 case snd_soc_dapm_mux
:
823 wname_in_long_name
= true;
824 kcname_in_long_name
= false;
831 if (wname_in_long_name
&& kcname_in_long_name
) {
833 * The control will get a prefix from the control
834 * creation process but we're also using the same
835 * prefix for widgets so cut the prefix off the
836 * front of the widget name.
838 long_name
= kasprintf(GFP_KERNEL
, "%s %s",
839 w
->name
+ prefix_len
,
840 w
->kcontrol_news
[kci
].name
);
841 if (long_name
== NULL
)
845 } else if (wname_in_long_name
) {
847 name
= w
->name
+ prefix_len
;
850 name
= w
->kcontrol_news
[kci
].name
;
853 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[kci
], NULL
, name
,
860 kcontrol
->private_free
= dapm_kcontrol_free
;
862 ret
= dapm_kcontrol_data_alloc(w
, kcontrol
);
864 snd_ctl_free_one(kcontrol
);
868 ret
= snd_ctl_add(card
, kcontrol
);
871 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
877 ret
= dapm_kcontrol_add_widget(kcontrol
, w
);
879 w
->kcontrols
[kci
] = kcontrol
;
887 /* create new dapm mixer control */
888 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
891 struct snd_soc_dapm_path
*path
;
892 struct dapm_kcontrol_data
*data
;
895 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
897 list_for_each_entry(path
, &w
->sources
, list_sink
) {
898 /* mixer/mux paths name must match control name */
899 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
902 if (!w
->kcontrols
[i
]) {
903 ret
= dapm_create_or_share_mixmux_kcontrol(w
, i
);
908 dapm_kcontrol_add_path(w
->kcontrols
[i
], path
);
910 data
= snd_kcontrol_chip(w
->kcontrols
[i
]);
912 snd_soc_dapm_add_path(data
->widget
->dapm
,
922 /* create new dapm mux control */
923 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
925 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
926 struct snd_soc_dapm_path
*path
;
927 struct list_head
*paths
;
932 case snd_soc_dapm_mux
:
936 case snd_soc_dapm_demux
:
944 if (w
->num_kcontrols
!= 1) {
946 "ASoC: %s %s has incorrect number of controls\n", type
,
951 if (list_empty(paths
)) {
952 dev_err(dapm
->dev
, "ASoC: %s %s has no paths\n", type
, w
->name
);
956 ret
= dapm_create_or_share_mixmux_kcontrol(w
, 0);
960 if (w
->id
== snd_soc_dapm_mux
) {
961 list_for_each_entry(path
, &w
->sources
, list_sink
) {
963 dapm_kcontrol_add_path(w
->kcontrols
[0], path
);
966 list_for_each_entry(path
, &w
->sinks
, list_source
) {
968 dapm_kcontrol_add_path(w
->kcontrols
[0], path
);
975 /* create new dapm volume control */
976 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
978 if (w
->num_kcontrols
)
979 dev_err(w
->dapm
->dev
,
980 "ASoC: PGA controls not supported: '%s'\n", w
->name
);
985 /* create new dapm dai link control */
986 static int dapm_new_dai_link(struct snd_soc_dapm_widget
*w
)
989 struct snd_kcontrol
*kcontrol
;
990 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
991 struct snd_card
*card
= dapm
->card
->snd_card
;
993 /* create control for links with > 1 config */
994 if (w
->num_params
<= 1)
998 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
999 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
], w
,
1001 ret
= snd_ctl_add(card
, kcontrol
);
1004 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
1005 w
->name
, w
->kcontrol_news
[i
].name
, ret
);
1008 kcontrol
->private_data
= w
;
1009 w
->kcontrols
[i
] = kcontrol
;
1015 /* We implement power down on suspend by checking the power state of
1016 * the ALSA card - when we are suspending the ALSA state for the card
1019 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
1021 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
1024 case SNDRV_CTL_POWER_D3hot
:
1025 case SNDRV_CTL_POWER_D3cold
:
1026 if (widget
->ignore_suspend
)
1027 dev_dbg(widget
->dapm
->dev
, "ASoC: %s ignoring suspend\n",
1029 return widget
->ignore_suspend
;
1035 /* add widget to list if it's not already in the list */
1036 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list
**list
,
1037 struct snd_soc_dapm_widget
*w
)
1039 struct snd_soc_dapm_widget_list
*wlist
;
1040 int wlistsize
, wlistentries
, i
;
1047 /* is this widget already in the list */
1048 for (i
= 0; i
< wlist
->num_widgets
; i
++) {
1049 if (wlist
->widgets
[i
] == w
)
1053 /* allocate some new space */
1054 wlistentries
= wlist
->num_widgets
+ 1;
1055 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
1056 wlistentries
* sizeof(struct snd_soc_dapm_widget
*);
1057 *list
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
1058 if (*list
== NULL
) {
1059 dev_err(w
->dapm
->dev
, "ASoC: can't allocate widget list for %s\n",
1065 /* insert the widget */
1066 dev_dbg(w
->dapm
->dev
, "ASoC: added %s in widget list pos %d\n",
1067 w
->name
, wlist
->num_widgets
);
1069 wlist
->widgets
[wlist
->num_widgets
] = w
;
1070 wlist
->num_widgets
++;
1075 * Recursively check for a completed path to an active or physically connected
1076 * output widget. Returns number of complete paths.
1078 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
,
1079 struct snd_soc_dapm_widget_list
**list
)
1081 struct snd_soc_dapm_path
*path
;
1084 if (widget
->outputs
>= 0)
1085 return widget
->outputs
;
1087 DAPM_UPDATE_STAT(widget
, path_checks
);
1089 if (widget
->is_sink
&& widget
->connected
) {
1090 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
1091 return widget
->outputs
;
1094 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
1095 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1097 if (path
->weak
|| path
->is_supply
)
1103 trace_snd_soc_dapm_output_path(widget
, path
);
1105 if (path
->connect
) {
1108 /* do we need to add this widget to the list ? */
1111 err
= dapm_list_add_widget(list
, path
->sink
);
1113 dev_err(widget
->dapm
->dev
,
1114 "ASoC: could not add widget %s\n",
1121 con
+= is_connected_output_ep(path
->sink
, list
);
1127 widget
->outputs
= con
;
1133 * Recursively check for a completed path to an active or physically connected
1134 * input widget. Returns number of complete paths.
1136 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
,
1137 struct snd_soc_dapm_widget_list
**list
)
1139 struct snd_soc_dapm_path
*path
;
1142 if (widget
->inputs
>= 0)
1143 return widget
->inputs
;
1145 DAPM_UPDATE_STAT(widget
, path_checks
);
1147 if (widget
->is_source
&& widget
->connected
) {
1148 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
1149 return widget
->inputs
;
1152 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
1153 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
1155 if (path
->weak
|| path
->is_supply
)
1161 trace_snd_soc_dapm_input_path(widget
, path
);
1163 if (path
->connect
) {
1166 /* do we need to add this widget to the list ? */
1169 err
= dapm_list_add_widget(list
, path
->source
);
1171 dev_err(widget
->dapm
->dev
,
1172 "ASoC: could not add widget %s\n",
1179 con
+= is_connected_input_ep(path
->source
, list
);
1185 widget
->inputs
= con
;
1191 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1192 * @dai: the soc DAI.
1193 * @stream: stream direction.
1194 * @list: list of active widgets for this stream.
1196 * Queries DAPM graph as to whether an valid audio stream path exists for
1197 * the initial stream specified by name. This takes into account
1198 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1200 * Returns the number of valid paths or negative error.
1202 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai
*dai
, int stream
,
1203 struct snd_soc_dapm_widget_list
**list
)
1205 struct snd_soc_card
*card
= dai
->component
->card
;
1206 struct snd_soc_dapm_widget
*w
;
1209 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
1212 * For is_connected_{output,input}_ep fully discover the graph we need
1213 * to reset the cached number of inputs and outputs.
1215 list_for_each_entry(w
, &card
->widgets
, list
) {
1220 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1221 paths
= is_connected_output_ep(dai
->playback_widget
, list
);
1223 paths
= is_connected_input_ep(dai
->capture_widget
, list
);
1225 trace_snd_soc_dapm_connected(paths
, stream
);
1226 mutex_unlock(&card
->dapm_mutex
);
1232 * Handler for regulator supply widget.
1234 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
1235 struct snd_kcontrol
*kcontrol
, int event
)
1239 soc_dapm_async_complete(w
->dapm
);
1241 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1242 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1243 ret
= regulator_allow_bypass(w
->regulator
, false);
1245 dev_warn(w
->dapm
->dev
,
1246 "ASoC: Failed to unbypass %s: %d\n",
1250 return regulator_enable(w
->regulator
);
1252 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
1253 ret
= regulator_allow_bypass(w
->regulator
, true);
1255 dev_warn(w
->dapm
->dev
,
1256 "ASoC: Failed to bypass %s: %d\n",
1260 return regulator_disable_deferred(w
->regulator
, w
->shift
);
1263 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
1266 * Handler for clock supply widget.
1268 int dapm_clock_event(struct snd_soc_dapm_widget
*w
,
1269 struct snd_kcontrol
*kcontrol
, int event
)
1274 soc_dapm_async_complete(w
->dapm
);
1276 #ifdef CONFIG_HAVE_CLK
1277 if (SND_SOC_DAPM_EVENT_ON(event
)) {
1278 return clk_prepare_enable(w
->clk
);
1280 clk_disable_unprepare(w
->clk
);
1286 EXPORT_SYMBOL_GPL(dapm_clock_event
);
1288 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
1290 if (w
->power_checked
)
1291 return w
->new_power
;
1296 w
->new_power
= w
->power_check(w
);
1298 w
->power_checked
= true;
1300 return w
->new_power
;
1303 /* Generic check to see if a widget should be powered.
1305 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
1309 DAPM_UPDATE_STAT(w
, power_checks
);
1311 in
= is_connected_input_ep(w
, NULL
);
1312 out
= is_connected_output_ep(w
, NULL
);
1313 return out
!= 0 && in
!= 0;
1316 /* Check to see if a power supply is needed */
1317 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
1319 struct snd_soc_dapm_path
*path
;
1321 DAPM_UPDATE_STAT(w
, power_checks
);
1323 /* Check if one of our outputs is connected */
1324 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1325 DAPM_UPDATE_STAT(w
, neighbour_checks
);
1330 if (path
->connected
&&
1331 !path
->connected(path
->source
, path
->sink
))
1334 if (dapm_widget_power_check(path
->sink
))
1341 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
1346 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
1347 struct snd_soc_dapm_widget
*b
,
1355 sort
= dapm_down_seq
;
1357 if (sort
[a
->id
] != sort
[b
->id
])
1358 return sort
[a
->id
] - sort
[b
->id
];
1359 if (a
->subseq
!= b
->subseq
) {
1361 return a
->subseq
- b
->subseq
;
1363 return b
->subseq
- a
->subseq
;
1365 if (a
->reg
!= b
->reg
)
1366 return a
->reg
- b
->reg
;
1367 if (a
->dapm
!= b
->dapm
)
1368 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1373 /* Insert a widget in order into a DAPM power sequence. */
1374 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1375 struct list_head
*list
,
1378 struct snd_soc_dapm_widget
*w
;
1380 list_for_each_entry(w
, list
, power_list
)
1381 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1382 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1386 list_add_tail(&new_widget
->power_list
, list
);
1389 static void dapm_seq_check_event(struct snd_soc_card
*card
,
1390 struct snd_soc_dapm_widget
*w
, int event
)
1392 const char *ev_name
;
1396 case SND_SOC_DAPM_PRE_PMU
:
1397 ev_name
= "PRE_PMU";
1400 case SND_SOC_DAPM_POST_PMU
:
1401 ev_name
= "POST_PMU";
1404 case SND_SOC_DAPM_PRE_PMD
:
1405 ev_name
= "PRE_PMD";
1408 case SND_SOC_DAPM_POST_PMD
:
1409 ev_name
= "POST_PMD";
1412 case SND_SOC_DAPM_WILL_PMU
:
1413 ev_name
= "WILL_PMU";
1416 case SND_SOC_DAPM_WILL_PMD
:
1417 ev_name
= "WILL_PMD";
1421 WARN(1, "Unknown event %d\n", event
);
1425 if (w
->new_power
!= power
)
1428 if (w
->event
&& (w
->event_flags
& event
)) {
1429 pop_dbg(w
->dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1431 soc_dapm_async_complete(w
->dapm
);
1432 trace_snd_soc_dapm_widget_event_start(w
, event
);
1433 ret
= w
->event(w
, NULL
, event
);
1434 trace_snd_soc_dapm_widget_event_done(w
, event
);
1436 dev_err(w
->dapm
->dev
, "ASoC: %s: %s event failed: %d\n",
1437 ev_name
, w
->name
, ret
);
1441 /* Apply the coalesced changes from a DAPM sequence */
1442 static void dapm_seq_run_coalesced(struct snd_soc_card
*card
,
1443 struct list_head
*pending
)
1445 struct snd_soc_dapm_context
*dapm
;
1446 struct snd_soc_dapm_widget
*w
;
1448 unsigned int value
= 0;
1449 unsigned int mask
= 0;
1451 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
, power_list
);
1455 list_for_each_entry(w
, pending
, power_list
) {
1456 WARN_ON(reg
!= w
->reg
|| dapm
!= w
->dapm
);
1457 w
->power
= w
->new_power
;
1459 mask
|= w
->mask
<< w
->shift
;
1461 value
|= w
->on_val
<< w
->shift
;
1463 value
|= w
->off_val
<< w
->shift
;
1465 pop_dbg(dapm
->dev
, card
->pop_time
,
1466 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1467 w
->name
, reg
, value
, mask
);
1469 /* Check for events */
1470 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMU
);
1471 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_PRE_PMD
);
1475 /* Any widget will do, they should all be updating the
1479 pop_dbg(dapm
->dev
, card
->pop_time
,
1480 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1481 value
, mask
, reg
, card
->pop_time
);
1482 pop_wait(card
->pop_time
);
1483 soc_dapm_update_bits(dapm
, reg
, mask
, value
);
1486 list_for_each_entry(w
, pending
, power_list
) {
1487 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMU
);
1488 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_POST_PMD
);
1492 /* Apply a DAPM power sequence.
1494 * We walk over a pre-sorted list of widgets to apply power to. In
1495 * order to minimise the number of writes to the device required
1496 * multiple widgets will be updated in a single write where possible.
1497 * Currently anything that requires more than a single write is not
1500 static void dapm_seq_run(struct snd_soc_card
*card
,
1501 struct list_head
*list
, int event
, bool power_up
)
1503 struct snd_soc_dapm_widget
*w
, *n
;
1504 struct snd_soc_dapm_context
*d
;
1507 int cur_subseq
= -1;
1508 int cur_reg
= SND_SOC_NOPM
;
1509 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1516 sort
= dapm_down_seq
;
1518 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1521 /* Do we need to apply any queued changes? */
1522 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1523 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1524 if (!list_empty(&pending
))
1525 dapm_seq_run_coalesced(card
, &pending
);
1527 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1528 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1529 if (sort
[i
] == cur_sort
)
1530 cur_dapm
->seq_notifier(cur_dapm
,
1535 if (cur_dapm
&& w
->dapm
!= cur_dapm
)
1536 soc_dapm_async_complete(cur_dapm
);
1538 INIT_LIST_HEAD(&pending
);
1540 cur_subseq
= INT_MIN
;
1541 cur_reg
= SND_SOC_NOPM
;
1546 case snd_soc_dapm_pre
:
1548 list_for_each_entry_safe_continue(w
, n
, list
,
1551 if (event
== SND_SOC_DAPM_STREAM_START
)
1553 NULL
, SND_SOC_DAPM_PRE_PMU
);
1554 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1556 NULL
, SND_SOC_DAPM_PRE_PMD
);
1559 case snd_soc_dapm_post
:
1561 list_for_each_entry_safe_continue(w
, n
, list
,
1564 if (event
== SND_SOC_DAPM_STREAM_START
)
1566 NULL
, SND_SOC_DAPM_POST_PMU
);
1567 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1569 NULL
, SND_SOC_DAPM_POST_PMD
);
1573 /* Queue it up for application */
1574 cur_sort
= sort
[w
->id
];
1575 cur_subseq
= w
->subseq
;
1578 list_move(&w
->power_list
, &pending
);
1583 dev_err(w
->dapm
->dev
,
1584 "ASoC: Failed to apply widget power: %d\n", ret
);
1587 if (!list_empty(&pending
))
1588 dapm_seq_run_coalesced(card
, &pending
);
1590 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1591 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1592 if (sort
[i
] == cur_sort
)
1593 cur_dapm
->seq_notifier(cur_dapm
,
1597 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1598 soc_dapm_async_complete(d
);
1602 static void dapm_widget_update(struct snd_soc_card
*card
)
1604 struct snd_soc_dapm_update
*update
= card
->update
;
1605 struct snd_soc_dapm_widget_list
*wlist
;
1606 struct snd_soc_dapm_widget
*w
= NULL
;
1610 if (!update
|| !dapm_kcontrol_is_powered(update
->kcontrol
))
1613 wlist
= dapm_kcontrol_get_wlist(update
->kcontrol
);
1615 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1616 w
= wlist
->widgets
[wi
];
1618 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1619 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1621 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM pre-event failed: %d\n",
1629 ret
= soc_dapm_update_bits(w
->dapm
, update
->reg
, update
->mask
,
1632 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM update failed: %d\n",
1635 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1636 w
= wlist
->widgets
[wi
];
1638 if (w
->event
&& (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1639 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1641 dev_err(w
->dapm
->dev
, "ASoC: %s DAPM post-event failed: %d\n",
1647 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1648 * they're changing state.
1650 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1652 struct snd_soc_dapm_context
*d
= data
;
1655 /* If we're off and we're not supposed to be go into STANDBY */
1656 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1657 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1659 pm_runtime_get_sync(d
->dev
);
1661 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1664 "ASoC: Failed to turn on bias: %d\n", ret
);
1667 /* Prepare for a transition to ON or away from ON */
1668 if ((d
->target_bias_level
== SND_SOC_BIAS_ON
&&
1669 d
->bias_level
!= SND_SOC_BIAS_ON
) ||
1670 (d
->target_bias_level
!= SND_SOC_BIAS_ON
&&
1671 d
->bias_level
== SND_SOC_BIAS_ON
)) {
1672 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1675 "ASoC: Failed to prepare bias: %d\n", ret
);
1679 /* Async callback run prior to DAPM sequences - brings to their final
1682 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1684 struct snd_soc_dapm_context
*d
= data
;
1687 /* If we just powered the last thing off drop to standby bias */
1688 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1689 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1690 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1691 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1693 dev_err(d
->dev
, "ASoC: Failed to apply standby bias: %d\n",
1697 /* If we're in standby and can support bias off then do that */
1698 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1699 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1700 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1702 dev_err(d
->dev
, "ASoC: Failed to turn off bias: %d\n",
1706 pm_runtime_put(d
->dev
);
1709 /* If we just powered up then move to active bias */
1710 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1711 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1712 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1714 dev_err(d
->dev
, "ASoC: Failed to apply active bias: %d\n",
1719 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1720 bool power
, bool connect
)
1722 /* If a connection is being made or broken then that update
1723 * will have marked the peer dirty, otherwise the widgets are
1724 * not connected and this update has no impact. */
1728 /* If the peer is already in the state we're moving to then we
1729 * won't have an impact on it. */
1730 if (power
!= peer
->power
)
1731 dapm_mark_dirty(peer
, "peer state change");
1734 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1735 struct list_head
*up_list
,
1736 struct list_head
*down_list
)
1738 struct snd_soc_dapm_path
*path
;
1740 if (w
->power
== power
)
1743 trace_snd_soc_dapm_widget_power(w
, power
);
1745 /* If we changed our power state perhaps our neigbours changed
1748 list_for_each_entry(path
, &w
->sources
, list_sink
)
1749 dapm_widget_set_peer_power(path
->source
, power
, path
->connect
);
1751 /* Supplies can't affect their outputs, only their inputs */
1752 if (!w
->is_supply
) {
1753 list_for_each_entry(path
, &w
->sinks
, list_source
)
1754 dapm_widget_set_peer_power(path
->sink
, power
,
1759 dapm_seq_insert(w
, up_list
, true);
1761 dapm_seq_insert(w
, down_list
, false);
1764 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1765 struct list_head
*up_list
,
1766 struct list_head
*down_list
)
1771 case snd_soc_dapm_pre
:
1772 dapm_seq_insert(w
, down_list
, false);
1774 case snd_soc_dapm_post
:
1775 dapm_seq_insert(w
, up_list
, true);
1779 power
= dapm_widget_power_check(w
);
1781 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1786 static bool dapm_idle_bias_off(struct snd_soc_dapm_context
*dapm
)
1788 if (dapm
->idle_bias_off
)
1791 switch (snd_power_get_state(dapm
->card
->snd_card
)) {
1792 case SNDRV_CTL_POWER_D3hot
:
1793 case SNDRV_CTL_POWER_D3cold
:
1794 return dapm
->suspend_bias_off
;
1803 * Scan each dapm widget for complete audio path.
1804 * A complete path is a route that has valid endpoints i.e.:-
1806 * o DAC to output pin.
1807 * o Input Pin to ADC.
1808 * o Input pin to Output pin (bypass, sidetone)
1809 * o DAC to ADC (loopback).
1811 static int dapm_power_widgets(struct snd_soc_card
*card
, int event
)
1813 struct snd_soc_dapm_widget
*w
;
1814 struct snd_soc_dapm_context
*d
;
1816 LIST_HEAD(down_list
);
1817 ASYNC_DOMAIN_EXCLUSIVE(async_domain
);
1818 enum snd_soc_bias_level bias
;
1820 lockdep_assert_held(&card
->dapm_mutex
);
1822 trace_snd_soc_dapm_start(card
);
1824 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1825 if (dapm_idle_bias_off(d
))
1826 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1828 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1833 /* Check which widgets we need to power and store them in
1834 * lists indicating if they should be powered up or down. We
1835 * only check widgets that have been flagged as dirty but note
1836 * that new widgets may be added to the dirty list while we
1839 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1840 dapm_power_one_widget(w
, &up_list
, &down_list
);
1843 list_for_each_entry(w
, &card
->widgets
, list
) {
1845 case snd_soc_dapm_pre
:
1846 case snd_soc_dapm_post
:
1847 /* These widgets always need to be powered */
1850 list_del_init(&w
->dirty
);
1857 /* Supplies and micbiases only bring the
1858 * context up to STANDBY as unless something
1859 * else is active and passing audio they
1860 * generally don't require full power. Signal
1861 * generators are virtual pins and have no
1862 * power impact themselves.
1865 case snd_soc_dapm_siggen
:
1866 case snd_soc_dapm_vmid
:
1868 case snd_soc_dapm_supply
:
1869 case snd_soc_dapm_regulator_supply
:
1870 case snd_soc_dapm_clock_supply
:
1871 case snd_soc_dapm_micbias
:
1872 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1873 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1876 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1883 /* Force all contexts in the card to the same bias state if
1884 * they're not ground referenced.
1886 bias
= SND_SOC_BIAS_OFF
;
1887 list_for_each_entry(d
, &card
->dapm_list
, list
)
1888 if (d
->target_bias_level
> bias
)
1889 bias
= d
->target_bias_level
;
1890 list_for_each_entry(d
, &card
->dapm_list
, list
)
1891 if (!dapm_idle_bias_off(d
))
1892 d
->target_bias_level
= bias
;
1894 trace_snd_soc_dapm_walk_done(card
);
1896 /* Run card bias changes at first */
1897 dapm_pre_sequence_async(&card
->dapm
, 0);
1898 /* Run other bias changes in parallel */
1899 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1900 if (d
!= &card
->dapm
)
1901 async_schedule_domain(dapm_pre_sequence_async
, d
,
1904 async_synchronize_full_domain(&async_domain
);
1906 list_for_each_entry(w
, &down_list
, power_list
) {
1907 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMD
);
1910 list_for_each_entry(w
, &up_list
, power_list
) {
1911 dapm_seq_check_event(card
, w
, SND_SOC_DAPM_WILL_PMU
);
1914 /* Power down widgets first; try to avoid amplifying pops. */
1915 dapm_seq_run(card
, &down_list
, event
, false);
1917 dapm_widget_update(card
);
1920 dapm_seq_run(card
, &up_list
, event
, true);
1922 /* Run all the bias changes in parallel */
1923 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1924 if (d
!= &card
->dapm
)
1925 async_schedule_domain(dapm_post_sequence_async
, d
,
1928 async_synchronize_full_domain(&async_domain
);
1929 /* Run card bias changes at last */
1930 dapm_post_sequence_async(&card
->dapm
, 0);
1932 /* do we need to notify any clients that DAPM event is complete */
1933 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1934 if (d
->stream_event
)
1935 d
->stream_event(d
, event
);
1938 pop_dbg(card
->dev
, card
->pop_time
,
1939 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1940 pop_wait(card
->pop_time
);
1942 trace_snd_soc_dapm_done(card
);
1947 #ifdef CONFIG_DEBUG_FS
1948 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1949 char __user
*user_buf
,
1950 size_t count
, loff_t
*ppos
)
1952 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1953 struct snd_soc_card
*card
= w
->dapm
->card
;
1957 struct snd_soc_dapm_path
*p
= NULL
;
1959 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1963 mutex_lock(&card
->dapm_mutex
);
1965 /* Supply widgets are not handled by is_connected_{input,output}_ep() */
1970 in
= is_connected_input_ep(w
, NULL
);
1971 out
= is_connected_output_ep(w
, NULL
);
1974 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1975 w
->name
, w
->power
? "On" : "Off",
1976 w
->force
? " (forced)" : "", in
, out
);
1979 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1980 " - R%d(0x%x) mask 0x%x",
1981 w
->reg
, w
->reg
, w
->mask
<< w
->shift
);
1983 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1986 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1988 w
->active
? "active" : "inactive");
1990 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1991 if (p
->connected
&& !p
->connected(w
, p
->source
))
1995 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1996 " in \"%s\" \"%s\"\n",
1997 p
->name
? p
->name
: "static",
2000 list_for_each_entry(p
, &w
->sinks
, list_source
) {
2001 if (p
->connected
&& !p
->connected(w
, p
->sink
))
2005 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
2006 " out \"%s\" \"%s\"\n",
2007 p
->name
? p
->name
: "static",
2011 mutex_unlock(&card
->dapm_mutex
);
2013 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
2019 static const struct file_operations dapm_widget_power_fops
= {
2020 .open
= simple_open
,
2021 .read
= dapm_widget_power_read_file
,
2022 .llseek
= default_llseek
,
2025 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
2026 size_t count
, loff_t
*ppos
)
2028 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
2031 switch (dapm
->bias_level
) {
2032 case SND_SOC_BIAS_ON
:
2035 case SND_SOC_BIAS_PREPARE
:
2036 level
= "Prepare\n";
2038 case SND_SOC_BIAS_STANDBY
:
2039 level
= "Standby\n";
2041 case SND_SOC_BIAS_OFF
:
2045 WARN(1, "Unknown bias_level %d\n", dapm
->bias_level
);
2046 level
= "Unknown\n";
2050 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
2054 static const struct file_operations dapm_bias_fops
= {
2055 .open
= simple_open
,
2056 .read
= dapm_bias_read_file
,
2057 .llseek
= default_llseek
,
2060 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2061 struct dentry
*parent
)
2068 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
2070 if (!dapm
->debugfs_dapm
) {
2072 "ASoC: Failed to create DAPM debugfs directory\n");
2076 d
= debugfs_create_file("bias_level", 0444,
2077 dapm
->debugfs_dapm
, dapm
,
2081 "ASoC: Failed to create bias level debugfs file\n");
2084 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2086 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
2089 if (!dapm
->debugfs_dapm
|| !w
->name
)
2092 d
= debugfs_create_file(w
->name
, 0444,
2093 dapm
->debugfs_dapm
, w
,
2094 &dapm_widget_power_fops
);
2096 dev_warn(w
->dapm
->dev
,
2097 "ASoC: Failed to create %s debugfs file\n",
2101 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2103 debugfs_remove_recursive(dapm
->debugfs_dapm
);
2107 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
2108 struct dentry
*parent
)
2112 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
2116 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
2123 * soc_dapm_connect_path() - Connects or disconnects a path
2124 * @path: The path to update
2125 * @connect: The new connect state of the path. True if the path is connected,
2126 * false if it is disconneted.
2127 * @reason: The reason why the path changed (for debugging only)
2129 static void soc_dapm_connect_path(struct snd_soc_dapm_path
*path
,
2130 bool connect
, const char *reason
)
2132 if (path
->connect
== connect
)
2135 path
->connect
= connect
;
2136 dapm_mark_dirty(path
->source
, reason
);
2137 dapm_mark_dirty(path
->sink
, reason
);
2138 dapm_path_invalidate(path
);
2141 /* test and update the power status of a mux widget */
2142 static int soc_dapm_mux_update_power(struct snd_soc_card
*card
,
2143 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
2145 struct snd_soc_dapm_path
*path
;
2149 lockdep_assert_held(&card
->dapm_mutex
);
2151 /* find dapm widget path assoc with kcontrol */
2152 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2154 /* we now need to match the string in the enum to the path */
2155 if (!(strcmp(path
->name
, e
->texts
[mux
])))
2160 soc_dapm_connect_path(path
, connect
, "mux update");
2164 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2169 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context
*dapm
,
2170 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
,
2171 struct snd_soc_dapm_update
*update
)
2173 struct snd_soc_card
*card
= dapm
->card
;
2176 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2177 card
->update
= update
;
2178 ret
= soc_dapm_mux_update_power(card
, kcontrol
, mux
, e
);
2179 card
->update
= NULL
;
2180 mutex_unlock(&card
->dapm_mutex
);
2182 soc_dpcm_runtime_update(card
);
2185 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
2187 /* test and update the power status of a mixer or switch widget */
2188 static int soc_dapm_mixer_update_power(struct snd_soc_card
*card
,
2189 struct snd_kcontrol
*kcontrol
, int connect
)
2191 struct snd_soc_dapm_path
*path
;
2194 lockdep_assert_held(&card
->dapm_mutex
);
2196 /* find dapm widget path assoc with kcontrol */
2197 dapm_kcontrol_for_each_path(path
, kcontrol
) {
2199 soc_dapm_connect_path(path
, connect
, "mixer update");
2203 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2208 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context
*dapm
,
2209 struct snd_kcontrol
*kcontrol
, int connect
,
2210 struct snd_soc_dapm_update
*update
)
2212 struct snd_soc_card
*card
= dapm
->card
;
2215 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2216 card
->update
= update
;
2217 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
2218 card
->update
= NULL
;
2219 mutex_unlock(&card
->dapm_mutex
);
2221 soc_dpcm_runtime_update(card
);
2224 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
2226 static ssize_t
dapm_widget_show_codec(struct snd_soc_codec
*codec
, char *buf
)
2228 struct snd_soc_dapm_widget
*w
;
2230 char *state
= "not set";
2232 list_for_each_entry(w
, &codec
->component
.card
->widgets
, list
) {
2233 if (w
->dapm
!= &codec
->dapm
)
2236 /* only display widgets that burnm power */
2238 case snd_soc_dapm_hp
:
2239 case snd_soc_dapm_mic
:
2240 case snd_soc_dapm_spk
:
2241 case snd_soc_dapm_line
:
2242 case snd_soc_dapm_micbias
:
2243 case snd_soc_dapm_dac
:
2244 case snd_soc_dapm_adc
:
2245 case snd_soc_dapm_pga
:
2246 case snd_soc_dapm_out_drv
:
2247 case snd_soc_dapm_mixer
:
2248 case snd_soc_dapm_mixer_named_ctl
:
2249 case snd_soc_dapm_supply
:
2250 case snd_soc_dapm_regulator_supply
:
2251 case snd_soc_dapm_clock_supply
:
2253 count
+= sprintf(buf
+ count
, "%s: %s\n",
2254 w
->name
, w
->power
? "On":"Off");
2261 switch (codec
->dapm
.bias_level
) {
2262 case SND_SOC_BIAS_ON
:
2265 case SND_SOC_BIAS_PREPARE
:
2268 case SND_SOC_BIAS_STANDBY
:
2271 case SND_SOC_BIAS_OFF
:
2275 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
2280 /* show dapm widget status in sys fs */
2281 static ssize_t
dapm_widget_show(struct device
*dev
,
2282 struct device_attribute
*attr
, char *buf
)
2284 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
2287 mutex_lock(&rtd
->card
->dapm_mutex
);
2289 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
2290 struct snd_soc_codec
*codec
= rtd
->codec_dais
[i
]->codec
;
2291 count
+= dapm_widget_show_codec(codec
, buf
+ count
);
2294 mutex_unlock(&rtd
->card
->dapm_mutex
);
2299 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
2301 struct attribute
*soc_dapm_dev_attrs
[] = {
2302 &dev_attr_dapm_widget
.attr
,
2306 static void dapm_free_path(struct snd_soc_dapm_path
*path
)
2308 list_del(&path
->list_sink
);
2309 list_del(&path
->list_source
);
2310 list_del(&path
->list_kcontrol
);
2311 list_del(&path
->list
);
2315 /* free all dapm widgets and resources */
2316 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
2318 struct snd_soc_dapm_widget
*w
, *next_w
;
2319 struct snd_soc_dapm_path
*p
, *next_p
;
2321 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
2322 if (w
->dapm
!= dapm
)
2326 * remove source and sink paths associated to this widget.
2327 * While removing the path, remove reference to it from both
2328 * source and sink widgets so that path is removed only once.
2330 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
)
2333 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
)
2336 kfree(w
->kcontrols
);
2342 static struct snd_soc_dapm_widget
*dapm_find_widget(
2343 struct snd_soc_dapm_context
*dapm
, const char *pin
,
2344 bool search_other_contexts
)
2346 struct snd_soc_dapm_widget
*w
;
2347 struct snd_soc_dapm_widget
*fallback
= NULL
;
2349 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2350 if (!strcmp(w
->name
, pin
)) {
2351 if (w
->dapm
== dapm
)
2358 if (search_other_contexts
)
2364 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
2365 const char *pin
, int status
)
2367 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2369 dapm_assert_locked(dapm
);
2372 dev_err(dapm
->dev
, "ASoC: DAPM unknown pin %s\n", pin
);
2376 if (w
->connected
!= status
) {
2377 dapm_mark_dirty(w
, "pin configuration");
2378 dapm_widget_invalidate_input_paths(w
);
2379 dapm_widget_invalidate_output_paths(w
);
2382 w
->connected
= status
;
2390 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2391 * @dapm: DAPM context
2393 * Walks all dapm audio paths and powers widgets according to their
2394 * stream or path usage.
2396 * Requires external locking.
2398 * Returns 0 for success.
2400 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context
*dapm
)
2403 * Suppress early reports (eg, jacks syncing their state) to avoid
2404 * silly DAPM runs during card startup.
2406 if (!dapm
->card
|| !dapm
->card
->instantiated
)
2409 return dapm_power_widgets(dapm
->card
, SND_SOC_DAPM_STREAM_NOP
);
2411 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked
);
2414 * snd_soc_dapm_sync - scan and power dapm paths
2415 * @dapm: DAPM context
2417 * Walks all dapm audio paths and powers widgets according to their
2418 * stream or path usage.
2420 * Returns 0 for success.
2422 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
2426 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
2427 ret
= snd_soc_dapm_sync_unlocked(dapm
);
2428 mutex_unlock(&dapm
->card
->dapm_mutex
);
2431 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
2434 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2435 * @w: The widget for which to update the flags
2437 * Some widgets have a dynamic category which depends on which neighbors they
2438 * are connected to. This function update the category for these widgets.
2440 * This function must be called whenever a path is added or removed to a widget.
2442 static void dapm_update_widget_flags(struct snd_soc_dapm_widget
*w
)
2444 struct snd_soc_dapm_path
*p
;
2447 case snd_soc_dapm_input
:
2448 /* On a fully routed card a input is never a source */
2449 if (w
->dapm
->card
->fully_routed
)
2452 list_for_each_entry(p
, &w
->sources
, list_sink
) {
2453 if (p
->source
->id
== snd_soc_dapm_micbias
||
2454 p
->source
->id
== snd_soc_dapm_mic
||
2455 p
->source
->id
== snd_soc_dapm_line
||
2456 p
->source
->id
== snd_soc_dapm_output
) {
2462 case snd_soc_dapm_output
:
2463 /* On a fully routed card a output is never a sink */
2464 if (w
->dapm
->card
->fully_routed
)
2467 list_for_each_entry(p
, &w
->sinks
, list_source
) {
2468 if (p
->sink
->id
== snd_soc_dapm_spk
||
2469 p
->sink
->id
== snd_soc_dapm_hp
||
2470 p
->sink
->id
== snd_soc_dapm_line
||
2471 p
->sink
->id
== snd_soc_dapm_input
) {
2477 case snd_soc_dapm_line
:
2478 w
->is_sink
= !list_empty(&w
->sources
);
2479 w
->is_source
= !list_empty(&w
->sinks
);
2486 static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context
*dapm
,
2487 struct snd_soc_dapm_widget
*source
, struct snd_soc_dapm_widget
*sink
,
2488 const char *control
)
2490 bool dynamic_source
= false;
2491 bool dynamic_sink
= false;
2496 switch (source
->id
) {
2497 case snd_soc_dapm_demux
:
2498 dynamic_source
= true;
2505 case snd_soc_dapm_mux
:
2506 case snd_soc_dapm_switch
:
2507 case snd_soc_dapm_mixer
:
2508 case snd_soc_dapm_mixer_named_ctl
:
2509 dynamic_sink
= true;
2515 if (dynamic_source
&& dynamic_sink
) {
2517 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n",
2518 source
->name
, control
, sink
->name
);
2520 } else if (!dynamic_source
&& !dynamic_sink
) {
2522 "Control not supported for path %s -> [%s] -> %s\n",
2523 source
->name
, control
, sink
->name
);
2530 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context
*dapm
,
2531 struct snd_soc_dapm_widget
*wsource
, struct snd_soc_dapm_widget
*wsink
,
2532 const char *control
,
2533 int (*connected
)(struct snd_soc_dapm_widget
*source
,
2534 struct snd_soc_dapm_widget
*sink
))
2536 struct snd_soc_dapm_path
*path
;
2539 if (wsink
->is_supply
&& !wsource
->is_supply
) {
2541 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n",
2542 wsource
->name
, wsink
->name
);
2546 if (connected
&& !wsource
->is_supply
) {
2548 "connected() callback only supported for supply widgets (%s -> %s)\n",
2549 wsource
->name
, wsink
->name
);
2553 if (wsource
->is_supply
&& control
) {
2555 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n",
2556 wsource
->name
, control
, wsink
->name
);
2560 ret
= snd_soc_dapm_check_dynamic_path(dapm
, wsource
, wsink
, control
);
2564 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2568 path
->source
= wsource
;
2570 path
->connected
= connected
;
2571 INIT_LIST_HEAD(&path
->list
);
2572 INIT_LIST_HEAD(&path
->list_kcontrol
);
2573 INIT_LIST_HEAD(&path
->list_source
);
2574 INIT_LIST_HEAD(&path
->list_sink
);
2576 if (wsource
->is_supply
|| wsink
->is_supply
)
2577 path
->is_supply
= 1;
2579 /* connect static paths */
2580 if (control
== NULL
) {
2583 switch (wsource
->id
) {
2584 case snd_soc_dapm_demux
:
2585 ret
= dapm_connect_mux(dapm
, path
, control
, wsource
);
2593 switch (wsink
->id
) {
2594 case snd_soc_dapm_mux
:
2595 ret
= dapm_connect_mux(dapm
, path
, control
, wsink
);
2599 case snd_soc_dapm_switch
:
2600 case snd_soc_dapm_mixer
:
2601 case snd_soc_dapm_mixer_named_ctl
:
2602 ret
= dapm_connect_mixer(dapm
, path
, control
);
2611 list_add(&path
->list
, &dapm
->card
->paths
);
2612 list_add(&path
->list_sink
, &wsink
->sources
);
2613 list_add(&path
->list_source
, &wsource
->sinks
);
2615 dapm_update_widget_flags(wsource
);
2616 dapm_update_widget_flags(wsink
);
2618 dapm_mark_dirty(wsource
, "Route added");
2619 dapm_mark_dirty(wsink
, "Route added");
2621 if (dapm
->card
->instantiated
&& path
->connect
)
2622 dapm_path_invalidate(path
);
2630 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
2631 const struct snd_soc_dapm_route
*route
)
2633 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
2634 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
2637 char prefixed_sink
[80];
2638 char prefixed_source
[80];
2642 prefix
= soc_dapm_prefix(dapm
);
2644 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2645 prefix
, route
->sink
);
2646 sink
= prefixed_sink
;
2647 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2648 prefix
, route
->source
);
2649 source
= prefixed_source
;
2652 source
= route
->source
;
2655 wsource
= dapm_wcache_lookup(&dapm
->path_source_cache
, source
);
2656 wsink
= dapm_wcache_lookup(&dapm
->path_sink_cache
, sink
);
2658 if (wsink
&& wsource
)
2662 * find src and dest widgets over all widgets but favor a widget from
2663 * current DAPM context
2665 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2666 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2668 if (w
->dapm
== dapm
) {
2675 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2677 if (w
->dapm
== dapm
) {
2684 /* use widget from another DAPM context if not found from this */
2690 if (wsource
== NULL
) {
2691 dev_err(dapm
->dev
, "ASoC: no source widget found for %s\n",
2695 if (wsink
== NULL
) {
2696 dev_err(dapm
->dev
, "ASoC: no sink widget found for %s\n",
2702 dapm_wcache_update(&dapm
->path_sink_cache
, wsink
);
2703 dapm_wcache_update(&dapm
->path_source_cache
, wsource
);
2705 ret
= snd_soc_dapm_add_path(dapm
, wsource
, wsink
, route
->control
,
2712 dev_warn(dapm
->dev
, "ASoC: no dapm match for %s --> %s --> %s\n",
2713 source
, route
->control
, sink
);
2717 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context
*dapm
,
2718 const struct snd_soc_dapm_route
*route
)
2720 struct snd_soc_dapm_widget
*wsource
, *wsink
;
2721 struct snd_soc_dapm_path
*path
, *p
;
2724 char prefixed_sink
[80];
2725 char prefixed_source
[80];
2728 if (route
->control
) {
2730 "ASoC: Removal of routes with controls not supported\n");
2734 prefix
= soc_dapm_prefix(dapm
);
2736 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
2737 prefix
, route
->sink
);
2738 sink
= prefixed_sink
;
2739 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
2740 prefix
, route
->source
);
2741 source
= prefixed_source
;
2744 source
= route
->source
;
2748 list_for_each_entry(p
, &dapm
->card
->paths
, list
) {
2749 if (strcmp(p
->source
->name
, source
) != 0)
2751 if (strcmp(p
->sink
->name
, sink
) != 0)
2758 wsource
= path
->source
;
2761 dapm_mark_dirty(wsource
, "Route removed");
2762 dapm_mark_dirty(wsink
, "Route removed");
2764 dapm_path_invalidate(path
);
2766 dapm_free_path(path
);
2768 /* Update any path related flags */
2769 dapm_update_widget_flags(wsource
);
2770 dapm_update_widget_flags(wsink
);
2772 dev_warn(dapm
->dev
, "ASoC: Route %s->%s does not exist\n",
2780 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2781 * @dapm: DAPM context
2782 * @route: audio routes
2783 * @num: number of routes
2785 * Connects 2 dapm widgets together via a named audio path. The sink is
2786 * the widget receiving the audio signal, whilst the source is the sender
2787 * of the audio signal.
2789 * Returns 0 for success else error. On error all resources can be freed
2790 * with a call to snd_soc_card_free().
2792 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2793 const struct snd_soc_dapm_route
*route
, int num
)
2797 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2798 for (i
= 0; i
< num
; i
++) {
2799 r
= snd_soc_dapm_add_route(dapm
, route
);
2801 dev_err(dapm
->dev
, "ASoC: Failed to add route %s -> %s -> %s\n",
2803 route
->control
? route
->control
: "direct",
2809 mutex_unlock(&dapm
->card
->dapm_mutex
);
2813 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2816 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2817 * @dapm: DAPM context
2818 * @route: audio routes
2819 * @num: number of routes
2821 * Removes routes from the DAPM context.
2823 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context
*dapm
,
2824 const struct snd_soc_dapm_route
*route
, int num
)
2828 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2829 for (i
= 0; i
< num
; i
++) {
2830 snd_soc_dapm_del_route(dapm
, route
);
2833 mutex_unlock(&dapm
->card
->dapm_mutex
);
2837 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes
);
2839 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2840 const struct snd_soc_dapm_route
*route
)
2842 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2845 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2848 struct snd_soc_dapm_path
*path
;
2852 dev_err(dapm
->dev
, "ASoC: Unable to find source %s for weak route\n",
2858 dev_err(dapm
->dev
, "ASoC: Unable to find sink %s for weak route\n",
2863 if (route
->control
|| route
->connected
)
2864 dev_warn(dapm
->dev
, "ASoC: Ignoring control for weak route %s->%s\n",
2865 route
->source
, route
->sink
);
2867 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2868 if (path
->sink
== sink
) {
2875 dev_err(dapm
->dev
, "ASoC: No path found for weak route %s->%s\n",
2876 route
->source
, route
->sink
);
2878 dev_warn(dapm
->dev
, "ASoC: %d paths found for weak route %s->%s\n",
2879 count
, route
->source
, route
->sink
);
2885 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2886 * @dapm: DAPM context
2887 * @route: audio routes
2888 * @num: number of routes
2890 * Mark existing routes matching those specified in the passed array
2891 * as being weak, meaning that they are ignored for the purpose of
2892 * power decisions. The main intended use case is for sidetone paths
2893 * which couple audio between other independent paths if they are both
2894 * active in order to make the combination work better at the user
2895 * level but which aren't intended to be "used".
2897 * Note that CODEC drivers should not use this as sidetone type paths
2898 * can frequently also be used as bypass paths.
2900 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2901 const struct snd_soc_dapm_route
*route
, int num
)
2906 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2907 for (i
= 0; i
< num
; i
++) {
2908 err
= snd_soc_dapm_weak_route(dapm
, route
);
2913 mutex_unlock(&dapm
->card
->dapm_mutex
);
2917 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2920 * snd_soc_dapm_new_widgets - add new dapm widgets
2921 * @dapm: DAPM context
2923 * Checks the codec for any new dapm widgets and creates them if found.
2925 * Returns 0 for success.
2927 int snd_soc_dapm_new_widgets(struct snd_soc_card
*card
)
2929 struct snd_soc_dapm_widget
*w
;
2932 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2934 list_for_each_entry(w
, &card
->widgets
, list
)
2939 if (w
->num_kcontrols
) {
2940 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2941 sizeof(struct snd_kcontrol
*),
2943 if (!w
->kcontrols
) {
2944 mutex_unlock(&card
->dapm_mutex
);
2950 case snd_soc_dapm_switch
:
2951 case snd_soc_dapm_mixer
:
2952 case snd_soc_dapm_mixer_named_ctl
:
2955 case snd_soc_dapm_mux
:
2956 case snd_soc_dapm_demux
:
2959 case snd_soc_dapm_pga
:
2960 case snd_soc_dapm_out_drv
:
2963 case snd_soc_dapm_dai_link
:
2964 dapm_new_dai_link(w
);
2970 /* Read the initial power state from the device */
2972 soc_dapm_read(w
->dapm
, w
->reg
, &val
);
2973 val
= val
>> w
->shift
;
2975 if (val
== w
->on_val
)
2981 dapm_mark_dirty(w
, "new widget");
2982 dapm_debugfs_add_widget(w
);
2985 dapm_power_widgets(card
, SND_SOC_DAPM_STREAM_NOP
);
2986 mutex_unlock(&card
->dapm_mutex
);
2989 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2992 * snd_soc_dapm_get_volsw - dapm mixer get callback
2993 * @kcontrol: mixer control
2994 * @ucontrol: control element information
2996 * Callback to get the value of a dapm mixer control.
2998 * Returns 0 for success.
3000 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
3001 struct snd_ctl_elem_value
*ucontrol
)
3003 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3004 struct snd_soc_card
*card
= dapm
->card
;
3005 struct soc_mixer_control
*mc
=
3006 (struct soc_mixer_control
*)kcontrol
->private_value
;
3008 unsigned int shift
= mc
->shift
;
3010 unsigned int mask
= (1 << fls(max
)) - 1;
3011 unsigned int invert
= mc
->invert
;
3015 if (snd_soc_volsw_is_stereo(mc
))
3017 "ASoC: Control '%s' is stereo, which is not supported\n",
3020 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3021 if (dapm_kcontrol_is_powered(kcontrol
) && reg
!= SND_SOC_NOPM
) {
3022 ret
= soc_dapm_read(dapm
, reg
, &val
);
3023 val
= (val
>> shift
) & mask
;
3025 val
= dapm_kcontrol_get_value(kcontrol
);
3027 mutex_unlock(&card
->dapm_mutex
);
3030 ucontrol
->value
.integer
.value
[0] = max
- val
;
3032 ucontrol
->value
.integer
.value
[0] = val
;
3036 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
3039 * snd_soc_dapm_put_volsw - dapm mixer set callback
3040 * @kcontrol: mixer control
3041 * @ucontrol: control element information
3043 * Callback to set the value of a dapm mixer control.
3045 * Returns 0 for success.
3047 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
3048 struct snd_ctl_elem_value
*ucontrol
)
3050 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3051 struct snd_soc_card
*card
= dapm
->card
;
3052 struct soc_mixer_control
*mc
=
3053 (struct soc_mixer_control
*)kcontrol
->private_value
;
3055 unsigned int shift
= mc
->shift
;
3057 unsigned int mask
= (1 << fls(max
)) - 1;
3058 unsigned int invert
= mc
->invert
;
3060 int connect
, change
, reg_change
= 0;
3061 struct snd_soc_dapm_update update
;
3064 if (snd_soc_volsw_is_stereo(mc
))
3066 "ASoC: Control '%s' is stereo, which is not supported\n",
3069 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
3075 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3077 change
= dapm_kcontrol_set_value(kcontrol
, val
);
3079 if (reg
!= SND_SOC_NOPM
) {
3080 mask
= mask
<< shift
;
3083 reg_change
= soc_dapm_test_bits(dapm
, reg
, mask
, val
);
3086 if (change
|| reg_change
) {
3088 update
.kcontrol
= kcontrol
;
3092 card
->update
= &update
;
3094 change
|= reg_change
;
3096 ret
= soc_dapm_mixer_update_power(card
, kcontrol
, connect
);
3098 card
->update
= NULL
;
3101 mutex_unlock(&card
->dapm_mutex
);
3104 soc_dpcm_runtime_update(card
);
3108 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
3111 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3112 * @kcontrol: mixer control
3113 * @ucontrol: control element information
3115 * Callback to get the value of a dapm enumerated double mixer control.
3117 * Returns 0 for success.
3119 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
3120 struct snd_ctl_elem_value
*ucontrol
)
3122 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3123 struct snd_soc_card
*card
= dapm
->card
;
3124 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3125 unsigned int reg_val
, val
;
3127 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3128 if (e
->reg
!= SND_SOC_NOPM
&& dapm_kcontrol_is_powered(kcontrol
)) {
3129 int ret
= soc_dapm_read(dapm
, e
->reg
, ®_val
);
3131 mutex_unlock(&card
->dapm_mutex
);
3135 reg_val
= dapm_kcontrol_get_value(kcontrol
);
3137 mutex_unlock(&card
->dapm_mutex
);
3139 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
3140 ucontrol
->value
.enumerated
.item
[0] = snd_soc_enum_val_to_item(e
, val
);
3141 if (e
->shift_l
!= e
->shift_r
) {
3142 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
3143 val
= snd_soc_enum_val_to_item(e
, val
);
3144 ucontrol
->value
.enumerated
.item
[1] = val
;
3149 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
3152 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3153 * @kcontrol: mixer control
3154 * @ucontrol: control element information
3156 * Callback to set the value of a dapm enumerated double mixer control.
3158 * Returns 0 for success.
3160 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
3161 struct snd_ctl_elem_value
*ucontrol
)
3163 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kcontrol
);
3164 struct snd_soc_card
*card
= dapm
->card
;
3165 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
3166 unsigned int *item
= ucontrol
->value
.enumerated
.item
;
3167 unsigned int val
, change
, reg_change
= 0;
3169 struct snd_soc_dapm_update update
;
3172 if (item
[0] >= e
->items
)
3175 val
= snd_soc_enum_item_to_val(e
, item
[0]) << e
->shift_l
;
3176 mask
= e
->mask
<< e
->shift_l
;
3177 if (e
->shift_l
!= e
->shift_r
) {
3178 if (item
[1] > e
->items
)
3180 val
|= snd_soc_enum_item_to_val(e
, item
[1]) << e
->shift_l
;
3181 mask
|= e
->mask
<< e
->shift_r
;
3184 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3186 change
= dapm_kcontrol_set_value(kcontrol
, val
);
3188 if (e
->reg
!= SND_SOC_NOPM
)
3189 reg_change
= soc_dapm_test_bits(dapm
, e
->reg
, mask
, val
);
3191 if (change
|| reg_change
) {
3193 update
.kcontrol
= kcontrol
;
3194 update
.reg
= e
->reg
;
3197 card
->update
= &update
;
3199 change
|= reg_change
;
3201 ret
= soc_dapm_mux_update_power(card
, kcontrol
, item
[0], e
);
3203 card
->update
= NULL
;
3206 mutex_unlock(&card
->dapm_mutex
);
3209 soc_dpcm_runtime_update(card
);
3213 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
3216 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3218 * @kcontrol: mixer control
3219 * @uinfo: control element information
3221 * Callback to provide information about a pin switch control.
3223 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
3224 struct snd_ctl_elem_info
*uinfo
)
3226 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3228 uinfo
->value
.integer
.min
= 0;
3229 uinfo
->value
.integer
.max
= 1;
3233 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
3236 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3238 * @kcontrol: mixer control
3241 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
3242 struct snd_ctl_elem_value
*ucontrol
)
3244 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3245 const char *pin
= (const char *)kcontrol
->private_value
;
3247 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3249 ucontrol
->value
.integer
.value
[0] =
3250 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
3252 mutex_unlock(&card
->dapm_mutex
);
3256 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
3259 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3261 * @kcontrol: mixer control
3264 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
3265 struct snd_ctl_elem_value
*ucontrol
)
3267 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
3268 const char *pin
= (const char *)kcontrol
->private_value
;
3270 if (ucontrol
->value
.integer
.value
[0])
3271 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
3273 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
3275 snd_soc_dapm_sync(&card
->dapm
);
3278 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
3280 struct snd_soc_dapm_widget
*
3281 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
3282 const struct snd_soc_dapm_widget
*widget
)
3284 struct snd_soc_dapm_widget
*w
;
3286 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3287 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3290 "ASoC: Failed to create DAPM control %s\n",
3293 mutex_unlock(&dapm
->card
->dapm_mutex
);
3297 struct snd_soc_dapm_widget
*
3298 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context
*dapm
,
3299 const struct snd_soc_dapm_widget
*widget
)
3301 struct snd_soc_dapm_widget
*w
;
3305 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
3309 case snd_soc_dapm_regulator_supply
:
3310 w
->regulator
= devm_regulator_get(dapm
->dev
, w
->name
);
3311 if (IS_ERR(w
->regulator
)) {
3312 ret
= PTR_ERR(w
->regulator
);
3313 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3318 if (w
->on_val
& SND_SOC_DAPM_REGULATOR_BYPASS
) {
3319 ret
= regulator_allow_bypass(w
->regulator
, true);
3321 dev_warn(w
->dapm
->dev
,
3322 "ASoC: Failed to bypass %s: %d\n",
3326 case snd_soc_dapm_clock_supply
:
3327 #ifdef CONFIG_CLKDEV_LOOKUP
3328 w
->clk
= devm_clk_get(dapm
->dev
, w
->name
);
3329 if (IS_ERR(w
->clk
)) {
3330 ret
= PTR_ERR(w
->clk
);
3331 dev_err(dapm
->dev
, "ASoC: Failed to request %s: %d\n",
3343 prefix
= soc_dapm_prefix(dapm
);
3345 w
->name
= kasprintf(GFP_KERNEL
, "%s %s", prefix
, widget
->name
);
3347 w
->name
= kasprintf(GFP_KERNEL
, "%s", widget
->name
);
3348 if (w
->name
== NULL
) {
3354 case snd_soc_dapm_mic
:
3356 w
->power_check
= dapm_generic_check_power
;
3358 case snd_soc_dapm_input
:
3359 if (!dapm
->card
->fully_routed
)
3361 w
->power_check
= dapm_generic_check_power
;
3363 case snd_soc_dapm_spk
:
3364 case snd_soc_dapm_hp
:
3366 w
->power_check
= dapm_generic_check_power
;
3368 case snd_soc_dapm_output
:
3369 if (!dapm
->card
->fully_routed
)
3371 w
->power_check
= dapm_generic_check_power
;
3373 case snd_soc_dapm_vmid
:
3374 case snd_soc_dapm_siggen
:
3376 w
->power_check
= dapm_always_on_check_power
;
3378 case snd_soc_dapm_mux
:
3379 case snd_soc_dapm_demux
:
3380 case snd_soc_dapm_switch
:
3381 case snd_soc_dapm_mixer
:
3382 case snd_soc_dapm_mixer_named_ctl
:
3383 case snd_soc_dapm_adc
:
3384 case snd_soc_dapm_aif_out
:
3385 case snd_soc_dapm_dac
:
3386 case snd_soc_dapm_aif_in
:
3387 case snd_soc_dapm_pga
:
3388 case snd_soc_dapm_out_drv
:
3389 case snd_soc_dapm_micbias
:
3390 case snd_soc_dapm_line
:
3391 case snd_soc_dapm_dai_link
:
3392 case snd_soc_dapm_dai_out
:
3393 case snd_soc_dapm_dai_in
:
3394 w
->power_check
= dapm_generic_check_power
;
3396 case snd_soc_dapm_supply
:
3397 case snd_soc_dapm_regulator_supply
:
3398 case snd_soc_dapm_clock_supply
:
3399 case snd_soc_dapm_kcontrol
:
3401 w
->power_check
= dapm_supply_check_power
;
3404 w
->power_check
= dapm_always_on_check_power
;
3409 INIT_LIST_HEAD(&w
->sources
);
3410 INIT_LIST_HEAD(&w
->sinks
);
3411 INIT_LIST_HEAD(&w
->list
);
3412 INIT_LIST_HEAD(&w
->dirty
);
3413 list_add_tail(&w
->list
, &dapm
->card
->widgets
);
3418 /* machine layer set ups unconnected pins and insertions */
3424 * snd_soc_dapm_new_controls - create new dapm controls
3425 * @dapm: DAPM context
3426 * @widget: widget array
3427 * @num: number of widgets
3429 * Creates new DAPM controls based upon the templates.
3431 * Returns 0 for success else error.
3433 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
3434 const struct snd_soc_dapm_widget
*widget
,
3437 struct snd_soc_dapm_widget
*w
;
3441 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
3442 for (i
= 0; i
< num
; i
++) {
3443 w
= snd_soc_dapm_new_control_unlocked(dapm
, widget
);
3446 "ASoC: Failed to create DAPM control %s\n",
3453 mutex_unlock(&dapm
->card
->dapm_mutex
);
3456 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
3458 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget
*w
,
3459 struct snd_kcontrol
*kcontrol
, int event
)
3461 struct snd_soc_dapm_path
*source_p
, *sink_p
;
3462 struct snd_soc_dai
*source
, *sink
;
3463 const struct snd_soc_pcm_stream
*config
= w
->params
+ w
->params_select
;
3464 struct snd_pcm_substream substream
;
3465 struct snd_pcm_hw_params
*params
= NULL
;
3469 if (WARN_ON(!config
) ||
3470 WARN_ON(list_empty(&w
->sources
) || list_empty(&w
->sinks
)))
3473 /* We only support a single source and sink, pick the first */
3474 source_p
= list_first_entry(&w
->sources
, struct snd_soc_dapm_path
,
3476 sink_p
= list_first_entry(&w
->sinks
, struct snd_soc_dapm_path
,
3479 if (WARN_ON(!source_p
|| !sink_p
) ||
3480 WARN_ON(!sink_p
->source
|| !source_p
->sink
) ||
3481 WARN_ON(!source_p
->source
|| !sink_p
->sink
))
3484 source
= source_p
->source
->priv
;
3485 sink
= sink_p
->sink
->priv
;
3487 /* Be a little careful as we don't want to overflow the mask array */
3488 if (config
->formats
) {
3489 fmt
= ffs(config
->formats
) - 1;
3491 dev_warn(w
->dapm
->dev
, "ASoC: Invalid format %llx specified\n",
3496 /* Currently very limited parameter selection */
3497 params
= kzalloc(sizeof(*params
), GFP_KERNEL
);
3502 snd_mask_set(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), fmt
);
3504 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->min
=
3506 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
)->max
=
3509 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->min
3510 = config
->channels_min
;
3511 hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
)->max
3512 = config
->channels_max
;
3514 memset(&substream
, 0, sizeof(substream
));
3517 case SND_SOC_DAPM_PRE_PMU
:
3518 substream
.stream
= SNDRV_PCM_STREAM_CAPTURE
;
3519 ret
= soc_dai_hw_params(&substream
, params
, source
);
3523 substream
.stream
= SNDRV_PCM_STREAM_PLAYBACK
;
3524 ret
= soc_dai_hw_params(&substream
, params
, sink
);
3529 case SND_SOC_DAPM_POST_PMU
:
3530 ret
= snd_soc_dai_digital_mute(sink
, 0,
3531 SNDRV_PCM_STREAM_PLAYBACK
);
3532 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3533 dev_warn(sink
->dev
, "ASoC: Failed to unmute: %d\n", ret
);
3537 case SND_SOC_DAPM_PRE_PMD
:
3538 ret
= snd_soc_dai_digital_mute(sink
, 1,
3539 SNDRV_PCM_STREAM_PLAYBACK
);
3540 if (ret
!= 0 && ret
!= -ENOTSUPP
)
3541 dev_warn(sink
->dev
, "ASoC: Failed to mute: %d\n", ret
);
3546 WARN(1, "Unknown event %d\n", event
);
3555 static int snd_soc_dapm_dai_link_get(struct snd_kcontrol
*kcontrol
,
3556 struct snd_ctl_elem_value
*ucontrol
)
3558 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
3560 ucontrol
->value
.integer
.value
[0] = w
->params_select
;
3565 static int snd_soc_dapm_dai_link_put(struct snd_kcontrol
*kcontrol
,
3566 struct snd_ctl_elem_value
*ucontrol
)
3568 struct snd_soc_dapm_widget
*w
= snd_kcontrol_chip(kcontrol
);
3570 /* Can't change the config when widget is already powered */
3574 if (ucontrol
->value
.integer
.value
[0] == w
->params_select
)
3577 if (ucontrol
->value
.integer
.value
[0] >= w
->num_params
)
3580 w
->params_select
= ucontrol
->value
.integer
.value
[0];
3585 int snd_soc_dapm_new_pcm(struct snd_soc_card
*card
,
3586 const struct snd_soc_pcm_stream
*params
,
3587 unsigned int num_params
,
3588 struct snd_soc_dapm_widget
*source
,
3589 struct snd_soc_dapm_widget
*sink
)
3591 struct snd_soc_dapm_widget
template;
3592 struct snd_soc_dapm_widget
*w
;
3595 unsigned long private_value
;
3596 const char **w_param_text
;
3597 struct soc_enum w_param_enum
[] = {
3598 SOC_ENUM_SINGLE(0, 0, 0, NULL
),
3600 struct snd_kcontrol_new kcontrol_dai_link
[] = {
3601 SOC_ENUM_EXT(NULL
, w_param_enum
[0],
3602 snd_soc_dapm_dai_link_get
,
3603 snd_soc_dapm_dai_link_put
),
3605 const struct snd_soc_pcm_stream
*config
= params
;
3607 w_param_text
= devm_kcalloc(card
->dev
, num_params
,
3608 sizeof(char *), GFP_KERNEL
);
3612 link_name
= devm_kasprintf(card
->dev
, GFP_KERNEL
, "%s-%s",
3613 source
->name
, sink
->name
);
3616 goto outfree_w_param
;
3619 for (count
= 0 ; count
< num_params
; count
++) {
3620 if (!config
->stream_name
) {
3621 dev_warn(card
->dapm
.dev
,
3622 "ASoC: anonymous config %d for dai link %s\n",
3624 w_param_text
[count
] =
3625 devm_kasprintf(card
->dev
, GFP_KERNEL
,
3626 "Anonymous Configuration %d",
3628 if (!w_param_text
[count
]) {
3630 goto outfree_link_name
;
3633 w_param_text
[count
] = devm_kmemdup(card
->dev
,
3634 config
->stream_name
,
3635 strlen(config
->stream_name
) + 1,
3637 if (!w_param_text
[count
]) {
3639 goto outfree_link_name
;
3644 w_param_enum
[0].items
= num_params
;
3645 w_param_enum
[0].texts
= w_param_text
;
3647 memset(&template, 0, sizeof(template));
3648 template.reg
= SND_SOC_NOPM
;
3649 template.id
= snd_soc_dapm_dai_link
;
3650 template.name
= link_name
;
3651 template.event
= snd_soc_dai_link_event
;
3652 template.event_flags
= SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
3653 SND_SOC_DAPM_PRE_PMD
;
3654 template.num_kcontrols
= 1;
3655 /* duplicate w_param_enum on heap so that memory persists */
3657 (unsigned long) devm_kmemdup(card
->dev
,
3658 (void *)(kcontrol_dai_link
[0].private_value
),
3659 sizeof(struct soc_enum
), GFP_KERNEL
);
3660 if (!private_value
) {
3661 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
3664 goto outfree_link_name
;
3666 kcontrol_dai_link
[0].private_value
= private_value
;
3667 /* duplicate kcontrol_dai_link on heap so that memory persists */
3668 template.kcontrol_news
=
3669 devm_kmemdup(card
->dev
, &kcontrol_dai_link
[0],
3670 sizeof(struct snd_kcontrol_new
),
3672 if (!template.kcontrol_news
) {
3673 dev_err(card
->dev
, "ASoC: Failed to create control for %s widget\n",
3676 goto outfree_private_value
;
3679 dev_dbg(card
->dev
, "ASoC: adding %s widget\n", link_name
);
3681 w
= snd_soc_dapm_new_control_unlocked(&card
->dapm
, &template);
3683 dev_err(card
->dev
, "ASoC: Failed to create %s widget\n",
3686 goto outfree_kcontrol_news
;
3690 w
->num_params
= num_params
;
3692 ret
= snd_soc_dapm_add_path(&card
->dapm
, source
, w
, NULL
, NULL
);
3695 return snd_soc_dapm_add_path(&card
->dapm
, w
, sink
, NULL
, NULL
);
3698 devm_kfree(card
->dev
, w
);
3699 outfree_kcontrol_news
:
3700 devm_kfree(card
->dev
, (void *)template.kcontrol_news
);
3701 outfree_private_value
:
3702 devm_kfree(card
->dev
, (void *)private_value
);
3704 devm_kfree(card
->dev
, link_name
);
3706 for (count
= 0 ; count
< num_params
; count
++)
3707 devm_kfree(card
->dev
, (void *)w_param_text
[count
]);
3708 devm_kfree(card
->dev
, w_param_text
);
3713 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
3714 struct snd_soc_dai
*dai
)
3716 struct snd_soc_dapm_widget
template;
3717 struct snd_soc_dapm_widget
*w
;
3719 WARN_ON(dapm
->dev
!= dai
->dev
);
3721 memset(&template, 0, sizeof(template));
3722 template.reg
= SND_SOC_NOPM
;
3724 if (dai
->driver
->playback
.stream_name
) {
3725 template.id
= snd_soc_dapm_dai_in
;
3726 template.name
= dai
->driver
->playback
.stream_name
;
3727 template.sname
= dai
->driver
->playback
.stream_name
;
3729 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3732 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
3734 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3735 dai
->driver
->playback
.stream_name
);
3740 dai
->playback_widget
= w
;
3743 if (dai
->driver
->capture
.stream_name
) {
3744 template.id
= snd_soc_dapm_dai_out
;
3745 template.name
= dai
->driver
->capture
.stream_name
;
3746 template.sname
= dai
->driver
->capture
.stream_name
;
3748 dev_dbg(dai
->dev
, "ASoC: adding %s widget\n",
3751 w
= snd_soc_dapm_new_control_unlocked(dapm
, &template);
3753 dev_err(dapm
->dev
, "ASoC: Failed to create %s widget\n",
3754 dai
->driver
->capture
.stream_name
);
3759 dai
->capture_widget
= w
;
3765 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
3767 struct snd_soc_dapm_widget
*dai_w
, *w
;
3768 struct snd_soc_dapm_widget
*src
, *sink
;
3769 struct snd_soc_dai
*dai
;
3771 /* For each DAI widget... */
3772 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
3773 switch (dai_w
->id
) {
3774 case snd_soc_dapm_dai_in
:
3775 case snd_soc_dapm_dai_out
:
3783 /* ...find all widgets with the same stream and link them */
3784 list_for_each_entry(w
, &card
->widgets
, list
) {
3785 if (w
->dapm
!= dai_w
->dapm
)
3789 case snd_soc_dapm_dai_in
:
3790 case snd_soc_dapm_dai_out
:
3796 if (!w
->sname
|| !strstr(w
->sname
, dai_w
->sname
))
3799 if (dai_w
->id
== snd_soc_dapm_dai_in
) {
3806 dev_dbg(dai
->dev
, "%s -> %s\n", src
->name
, sink
->name
);
3807 snd_soc_dapm_add_path(w
->dapm
, src
, sink
, NULL
, NULL
);
3814 static void dapm_connect_dai_link_widgets(struct snd_soc_card
*card
,
3815 struct snd_soc_pcm_runtime
*rtd
)
3817 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3818 struct snd_soc_dapm_widget
*sink
, *source
;
3821 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
3822 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[i
];
3824 /* there is no point in connecting BE DAI links with dummies */
3825 if (snd_soc_dai_is_dummy(codec_dai
) ||
3826 snd_soc_dai_is_dummy(cpu_dai
))
3829 /* connect BE DAI playback if widgets are valid */
3830 if (codec_dai
->playback_widget
&& cpu_dai
->playback_widget
) {
3831 source
= cpu_dai
->playback_widget
;
3832 sink
= codec_dai
->playback_widget
;
3833 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3834 cpu_dai
->component
->name
, source
->name
,
3835 codec_dai
->component
->name
, sink
->name
);
3837 snd_soc_dapm_add_path(&card
->dapm
, source
, sink
,
3841 /* connect BE DAI capture if widgets are valid */
3842 if (codec_dai
->capture_widget
&& cpu_dai
->capture_widget
) {
3843 source
= codec_dai
->capture_widget
;
3844 sink
= cpu_dai
->capture_widget
;
3845 dev_dbg(rtd
->dev
, "connected DAI link %s:%s -> %s:%s\n",
3846 codec_dai
->component
->name
, source
->name
,
3847 cpu_dai
->component
->name
, sink
->name
);
3849 snd_soc_dapm_add_path(&card
->dapm
, source
, sink
,
3855 static void soc_dapm_dai_stream_event(struct snd_soc_dai
*dai
, int stream
,
3858 struct snd_soc_dapm_widget
*w
;
3860 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
3861 w
= dai
->playback_widget
;
3863 w
= dai
->capture_widget
;
3866 dapm_mark_dirty(w
, "stream event");
3869 case SND_SOC_DAPM_STREAM_START
:
3872 case SND_SOC_DAPM_STREAM_STOP
:
3875 case SND_SOC_DAPM_STREAM_SUSPEND
:
3876 case SND_SOC_DAPM_STREAM_RESUME
:
3877 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
3878 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
3882 if (w
->id
== snd_soc_dapm_dai_in
) {
3883 w
->is_source
= w
->active
;
3884 dapm_widget_invalidate_input_paths(w
);
3886 w
->is_sink
= w
->active
;
3887 dapm_widget_invalidate_output_paths(w
);
3892 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card
*card
)
3894 struct snd_soc_pcm_runtime
*rtd
= card
->rtd
;
3897 /* for each BE DAI link... */
3898 for (i
= 0; i
< card
->num_rtd
; i
++) {
3899 rtd
= &card
->rtd
[i
];
3902 * dynamic FE links have no fixed DAI mapping.
3903 * CODEC<->CODEC links have no direct connection.
3905 if (rtd
->dai_link
->dynamic
|| rtd
->dai_link
->params
)
3908 dapm_connect_dai_link_widgets(card
, rtd
);
3912 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3917 soc_dapm_dai_stream_event(rtd
->cpu_dai
, stream
, event
);
3918 for (i
= 0; i
< rtd
->num_codecs
; i
++)
3919 soc_dapm_dai_stream_event(rtd
->codec_dais
[i
], stream
, event
);
3921 dapm_power_widgets(rtd
->card
, event
);
3925 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3926 * @rtd: PCM runtime data
3927 * @stream: stream name
3928 * @event: stream event
3930 * Sends a stream event to the dapm core. The core then makes any
3931 * necessary widget power changes.
3933 * Returns 0 for success else error.
3935 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3938 struct snd_soc_card
*card
= rtd
->card
;
3940 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3941 soc_dapm_stream_event(rtd
, stream
, event
);
3942 mutex_unlock(&card
->dapm_mutex
);
3946 * snd_soc_dapm_enable_pin_unlocked - enable pin.
3947 * @dapm: DAPM context
3950 * Enables input/output pin and its parents or children widgets iff there is
3951 * a valid audio route and active audio stream.
3953 * Requires external locking.
3955 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3956 * do any widget power switching.
3958 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
3961 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3963 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked
);
3966 * snd_soc_dapm_enable_pin - enable pin.
3967 * @dapm: DAPM context
3970 * Enables input/output pin and its parents or children widgets iff there is
3971 * a valid audio route and active audio stream.
3973 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3974 * do any widget power switching.
3976 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3980 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
3982 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 1);
3984 mutex_unlock(&dapm
->card
->dapm_mutex
);
3988 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3991 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
3992 * @dapm: DAPM context
3995 * Enables input/output pin regardless of any other state. This is
3996 * intended for use with microphone bias supplies used in microphone
3999 * Requires external locking.
4001 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4002 * do any widget power switching.
4004 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4007 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4010 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4014 dev_dbg(w
->dapm
->dev
, "ASoC: force enable pin %s\n", pin
);
4015 if (!w
->connected
) {
4017 * w->force does not affect the number of input or output paths,
4018 * so we only have to recheck if w->connected is changed
4020 dapm_widget_invalidate_input_paths(w
);
4021 dapm_widget_invalidate_output_paths(w
);
4025 dapm_mark_dirty(w
, "force enable");
4029 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked
);
4032 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4033 * @dapm: DAPM context
4036 * Enables input/output pin regardless of any other state. This is
4037 * intended for use with microphone bias supplies used in microphone
4040 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4041 * do any widget power switching.
4043 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
4048 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4050 ret
= snd_soc_dapm_force_enable_pin_unlocked(dapm
, pin
);
4052 mutex_unlock(&dapm
->card
->dapm_mutex
);
4056 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
4059 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4060 * @dapm: DAPM context
4063 * Disables input/output pin and its parents or children widgets.
4065 * Requires external locking.
4067 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4068 * do any widget power switching.
4070 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4073 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4075 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked
);
4078 * snd_soc_dapm_disable_pin - disable pin.
4079 * @dapm: DAPM context
4082 * Disables input/output pin and its parents or children widgets.
4084 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4085 * do any widget power switching.
4087 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
4092 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4094 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4096 mutex_unlock(&dapm
->card
->dapm_mutex
);
4100 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
4103 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4104 * @dapm: DAPM context
4107 * Marks the specified pin as being not connected, disabling it along
4108 * any parent or child widgets. At present this is identical to
4109 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4110 * additional things such as disabling controls which only affect
4111 * paths through the pin.
4113 * Requires external locking.
4115 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4116 * do any widget power switching.
4118 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context
*dapm
,
4121 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
4123 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked
);
4126 * snd_soc_dapm_nc_pin - permanently disable pin.
4127 * @dapm: DAPM context
4130 * Marks the specified pin as being not connected, disabling it along
4131 * any parent or child widgets. At present this is identical to
4132 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4133 * additional things such as disabling controls which only affect
4134 * paths through the pin.
4136 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4137 * do any widget power switching.
4139 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
4143 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_RUNTIME
);
4145 ret
= snd_soc_dapm_set_pin(dapm
, pin
, 0);
4147 mutex_unlock(&dapm
->card
->dapm_mutex
);
4151 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
4154 * snd_soc_dapm_get_pin_status - get audio pin status
4155 * @dapm: DAPM context
4156 * @pin: audio signal pin endpoint (or start point)
4158 * Get audio pin status - connected or disconnected.
4160 * Returns 1 for connected otherwise 0.
4162 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
4165 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
4168 return w
->connected
;
4172 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
4175 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4176 * @dapm: DAPM context
4177 * @pin: audio signal pin endpoint (or start point)
4179 * Mark the given endpoint or pin as ignoring suspend. When the
4180 * system is disabled a path between two endpoints flagged as ignoring
4181 * suspend will not be disabled. The path must already be enabled via
4182 * normal means at suspend time, it will not be turned on if it was not
4185 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
4188 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
4191 dev_err(dapm
->dev
, "ASoC: unknown pin %s\n", pin
);
4195 w
->ignore_suspend
= 1;
4199 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
4202 * snd_soc_dapm_free - free dapm resources
4203 * @dapm: DAPM context
4205 * Free all dapm widgets and resources.
4207 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
4209 dapm_debugfs_cleanup(dapm
);
4210 dapm_free_widgets(dapm
);
4211 list_del(&dapm
->list
);
4213 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
4215 static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context
*dapm
)
4217 struct snd_soc_card
*card
= dapm
->card
;
4218 struct snd_soc_dapm_widget
*w
;
4219 LIST_HEAD(down_list
);
4222 mutex_lock(&card
->dapm_mutex
);
4224 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
4225 if (w
->dapm
!= dapm
)
4228 dapm_seq_insert(w
, &down_list
, false);
4234 /* If there were no widgets to power down we're already in
4238 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
4239 snd_soc_dapm_set_bias_level(dapm
,
4240 SND_SOC_BIAS_PREPARE
);
4241 dapm_seq_run(card
, &down_list
, 0, false);
4242 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
4243 snd_soc_dapm_set_bias_level(dapm
,
4244 SND_SOC_BIAS_STANDBY
);
4247 mutex_unlock(&card
->dapm_mutex
);
4251 * snd_soc_dapm_shutdown - callback for system shutdown
4253 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
4255 struct snd_soc_dapm_context
*dapm
;
4257 list_for_each_entry(dapm
, &card
->dapm_list
, list
) {
4258 if (dapm
!= &card
->dapm
) {
4259 soc_dapm_shutdown_dapm(dapm
);
4260 if (dapm
->bias_level
== SND_SOC_BIAS_STANDBY
)
4261 snd_soc_dapm_set_bias_level(dapm
,
4266 soc_dapm_shutdown_dapm(&card
->dapm
);
4267 if (card
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
4268 snd_soc_dapm_set_bias_level(&card
->dapm
,
4272 /* Module information */
4273 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4274 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
4275 MODULE_LICENSE("GPL");