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 #define SND_SOC_DAPM_DIR_REVERSE(x) ((x == SND_SOC_DAPM_DIR_IN) ? \
51 SND_SOC_DAPM_DIR_OUT : SND_SOC_DAPM_DIR_IN)
53 #define snd_soc_dapm_for_each_direction(dir) \
54 for ((dir) = SND_SOC_DAPM_DIR_IN; (dir) <= SND_SOC_DAPM_DIR_OUT; \
57 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
58 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink,
60 int (*connected)(struct snd_soc_dapm_widget *source,
61 struct snd_soc_dapm_widget *sink));
63 struct snd_soc_dapm_widget *
64 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
65 const struct snd_soc_dapm_widget *widget);
67 struct snd_soc_dapm_widget *
68 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
69 const struct snd_soc_dapm_widget *widget);
71 /* dapm power sequences - make this per codec in the future */
72 static int dapm_up_seq[] = {
73 [snd_soc_dapm_pre] = 0,
74 [snd_soc_dapm_regulator_supply] = 1,
75 [snd_soc_dapm_clock_supply] = 1,
76 [snd_soc_dapm_supply] = 2,
77 [snd_soc_dapm_micbias] = 3,
78 [snd_soc_dapm_dai_link] = 2,
79 [snd_soc_dapm_dai_in] = 4,
80 [snd_soc_dapm_dai_out] = 4,
81 [snd_soc_dapm_adc] = 4,
82 [snd_soc_dapm_mic] = 5,
83 [snd_soc_dapm_mux] = 6,
84 [snd_soc_dapm_demux] = 6,
85 [snd_soc_dapm_dac] = 7,
86 [snd_soc_dapm_switch] = 8,
87 [snd_soc_dapm_mixer] = 8,
88 [snd_soc_dapm_mixer_named_ctl] = 8,
89 [snd_soc_dapm_pga] = 9,
90 [snd_soc_dapm_aif_in] = 9,
91 [snd_soc_dapm_aif_out] = 9,
92 [snd_soc_dapm_out_drv] = 11,
93 [snd_soc_dapm_hp] = 11,
94 [snd_soc_dapm_spk] = 11,
95 [snd_soc_dapm_line] = 11,
96 [snd_soc_dapm_kcontrol] = 12,
97 [snd_soc_dapm_post] = 13,
100 static int dapm_down_seq[] = {
101 [snd_soc_dapm_pre] = 0,
102 [snd_soc_dapm_kcontrol] = 1,
103 [snd_soc_dapm_aif_in] = 2,
104 [snd_soc_dapm_aif_out] = 2,
105 [snd_soc_dapm_adc] = 5,
106 [snd_soc_dapm_hp] = 3,
107 [snd_soc_dapm_spk] = 3,
108 [snd_soc_dapm_line] = 3,
109 [snd_soc_dapm_out_drv] = 3,
110 [snd_soc_dapm_pga] = 4,
111 [snd_soc_dapm_switch] = 5,
112 [snd_soc_dapm_mixer_named_ctl] = 5,
113 [snd_soc_dapm_mixer] = 5,
114 [snd_soc_dapm_dac] = 6,
115 [snd_soc_dapm_mic] = 7,
116 [snd_soc_dapm_micbias] = 8,
117 [snd_soc_dapm_mux] = 9,
118 [snd_soc_dapm_demux] = 9,
119 [snd_soc_dapm_dai_in] = 10,
120 [snd_soc_dapm_dai_out] = 10,
121 [snd_soc_dapm_dai_link] = 11,
122 [snd_soc_dapm_supply] = 12,
123 [snd_soc_dapm_clock_supply] = 13,
124 [snd_soc_dapm_regulator_supply] = 13,
125 [snd_soc_dapm_post] = 14,
128 static void dapm_assert_locked(struct snd_soc_dapm_context *dapm)
130 if (dapm->card && dapm->card->instantiated)
131 lockdep_assert_held(&dapm->card->dapm_mutex);
134 static void pop_wait(u32 pop_time)
137 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
140 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
148 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
153 vsnprintf(buf, PAGE_SIZE, fmt, args);
154 dev_info(dev, "%s", buf);
160 static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
162 return !list_empty(&w->dirty);
165 static void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
167 dapm_assert_locked(w->dapm);
169 if (!dapm_dirty_widget(w)) {
170 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
172 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
177 * Common implementation for dapm_widget_invalidate_input_paths() and
178 * dapm_widget_invalidate_output_paths(). The function is inlined since the
179 * combined size of the two specialized functions is only marginally larger then
180 * the size of the generic function and at the same time the fast path of the
181 * specialized functions is significantly smaller than the generic function.
183 static __always_inline void dapm_widget_invalidate_paths(
184 struct snd_soc_dapm_widget *w, enum snd_soc_dapm_direction dir)
186 enum snd_soc_dapm_direction rdir = SND_SOC_DAPM_DIR_REVERSE(dir);
187 struct snd_soc_dapm_widget *node;
188 struct snd_soc_dapm_path *p;
191 dapm_assert_locked(w->dapm);
193 if (w->endpoints[dir] == -1)
196 list_add_tail(&w->work_list, &list);
197 w->endpoints[dir] = -1;
199 list_for_each_entry(w, &list, work_list) {
200 snd_soc_dapm_widget_for_each_path(w, dir, p) {
201 if (p->is_supply || p->weak || !p->connect)
203 node = p->node[rdir];
204 if (node->endpoints[dir] != -1) {
205 node->endpoints[dir] = -1;
206 list_add_tail(&node->work_list, &list);
213 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of
215 * @w: The widget for which to invalidate the cached number of input paths
217 * Resets the cached number of inputs for the specified widget and all widgets
218 * that can be reached via outcoming paths from the widget.
220 * This function must be called if the number of output paths for a widget might
221 * have changed. E.g. if the source state of a widget changes or a path is added
222 * or activated with the widget as the sink.
224 static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget *w)
226 dapm_widget_invalidate_paths(w, SND_SOC_DAPM_DIR_IN);
230 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of
232 * @w: The widget for which to invalidate the cached number of output paths
234 * Resets the cached number of outputs for the specified widget and all widgets
235 * that can be reached via incoming paths from the widget.
237 * This function must be called if the number of output paths for a widget might
238 * have changed. E.g. if the sink state of a widget changes or a path is added
239 * or activated with the widget as the source.
241 static void dapm_widget_invalidate_output_paths(struct snd_soc_dapm_widget *w)
243 dapm_widget_invalidate_paths(w, SND_SOC_DAPM_DIR_OUT);
247 * dapm_path_invalidate() - Invalidates the cached number of inputs and outputs
248 * for the widgets connected to a path
249 * @p: The path to invalidate
251 * Resets the cached number of inputs for the sink of the path and the cached
252 * number of outputs for the source of the path.
254 * This function must be called when a path is added, removed or the connected
257 static void dapm_path_invalidate(struct snd_soc_dapm_path *p)
260 * Weak paths or supply paths do not influence the number of input or
261 * output paths of their neighbors.
263 if (p->weak || p->is_supply)
267 * The number of connected endpoints is the sum of the number of
268 * connected endpoints of all neighbors. If a node with 0 connected
269 * endpoints is either connected or disconnected that sum won't change,
270 * so there is no need to re-check the path.
272 if (p->source->endpoints[SND_SOC_DAPM_DIR_IN] != 0)
273 dapm_widget_invalidate_input_paths(p->sink);
274 if (p->sink->endpoints[SND_SOC_DAPM_DIR_OUT] != 0)
275 dapm_widget_invalidate_output_paths(p->source);
278 void dapm_mark_endpoints_dirty(struct snd_soc_card *card)
280 struct snd_soc_dapm_widget *w;
282 mutex_lock(&card->dapm_mutex);
284 list_for_each_entry(w, &card->widgets, list) {
285 if (w->ignore_suspend)
288 dapm_mark_dirty(w, "Rechecking endpoints");
289 if (w->is_ep & SND_SOC_DAPM_EP_SINK)
290 dapm_widget_invalidate_output_paths(w);
291 if (w->is_ep & SND_SOC_DAPM_EP_SOURCE)
292 dapm_widget_invalidate_input_paths(w);
296 mutex_unlock(&card->dapm_mutex);
298 EXPORT_SYMBOL_GPL(dapm_mark_endpoints_dirty);
300 /* create a new dapm widget */
301 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
302 const struct snd_soc_dapm_widget *_widget)
304 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
307 struct dapm_kcontrol_data {
309 struct snd_soc_dapm_widget *widget;
310 struct list_head paths;
311 struct snd_soc_dapm_widget_list *wlist;
314 static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
315 struct snd_kcontrol *kcontrol)
317 struct dapm_kcontrol_data *data;
318 struct soc_mixer_control *mc;
323 data = kzalloc(sizeof(*data), GFP_KERNEL);
327 INIT_LIST_HEAD(&data->paths);
329 switch (widget->id) {
330 case snd_soc_dapm_switch:
331 case snd_soc_dapm_mixer:
332 case snd_soc_dapm_mixer_named_ctl:
333 mc = (struct soc_mixer_control *)kcontrol->private_value;
335 if (mc->autodisable) {
336 struct snd_soc_dapm_widget template;
338 name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name,
345 memset(&template, 0, sizeof(template));
346 template.reg = mc->reg;
347 template.mask = (1 << fls(mc->max)) - 1;
348 template.shift = mc->shift;
350 template.off_val = mc->max;
352 template.off_val = 0;
353 template.on_val = template.off_val;
354 template.id = snd_soc_dapm_kcontrol;
355 template.name = name;
357 data->value = template.on_val;
360 snd_soc_dapm_new_control_unlocked(widget->dapm,
363 if (IS_ERR(data->widget)) {
364 ret = PTR_ERR(data->widget);
373 case snd_soc_dapm_demux:
374 case snd_soc_dapm_mux:
375 e = (struct soc_enum *)kcontrol->private_value;
377 if (e->autodisable) {
378 struct snd_soc_dapm_widget template;
380 name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name,
387 memset(&template, 0, sizeof(template));
388 template.reg = e->reg;
389 template.mask = e->mask << e->shift_l;
390 template.shift = e->shift_l;
391 template.off_val = snd_soc_enum_item_to_val(e, 0);
392 template.on_val = template.off_val;
393 template.id = snd_soc_dapm_kcontrol;
394 template.name = name;
396 data->value = template.on_val;
398 data->widget = snd_soc_dapm_new_control_unlocked(
399 widget->dapm, &template);
401 if (IS_ERR(data->widget)) {
402 ret = PTR_ERR(data->widget);
410 snd_soc_dapm_add_path(widget->dapm, data->widget,
418 kcontrol->private_data = data;
427 static void dapm_kcontrol_free(struct snd_kcontrol *kctl)
429 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl);
431 list_del(&data->paths);
436 struct snd_soc_dapm_widget_list *dapm_kcontrol_get_wlist(
437 const struct snd_kcontrol *kcontrol)
439 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
443 EXPORT_SYMBOL(dapm_kcontrol_get_wlist);
445 static int dapm_kcontrol_add_widget(struct snd_kcontrol *kcontrol,
446 struct snd_soc_dapm_widget *widget)
448 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
449 struct snd_soc_dapm_widget_list *new_wlist;
453 n = data->wlist->num_widgets + 1;
457 new_wlist = krealloc(data->wlist,
458 sizeof(*new_wlist) + sizeof(widget) * n, GFP_KERNEL);
462 new_wlist->widgets[n - 1] = widget;
463 new_wlist->num_widgets = n;
465 data->wlist = new_wlist;
470 static void dapm_kcontrol_add_path(const struct snd_kcontrol *kcontrol,
471 struct snd_soc_dapm_path *path)
473 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
475 list_add_tail(&path->list_kcontrol, &data->paths);
478 static bool dapm_kcontrol_is_powered(const struct snd_kcontrol *kcontrol)
480 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
485 return data->widget->power;
488 static struct list_head *dapm_kcontrol_get_path_list(
489 const struct snd_kcontrol *kcontrol)
491 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
496 #define dapm_kcontrol_for_each_path(path, kcontrol) \
497 list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \
500 unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol)
502 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
506 EXPORT_SYMBOL_GPL(dapm_kcontrol_get_value);
508 static bool dapm_kcontrol_set_value(const struct snd_kcontrol *kcontrol,
511 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
513 if (data->value == value)
517 data->widget->on_val = value;
525 * snd_soc_dapm_kcontrol_widget() - Returns the widget associated to a
527 * @kcontrol: The kcontrol
529 struct snd_soc_dapm_widget *snd_soc_dapm_kcontrol_widget(
530 struct snd_kcontrol *kcontrol)
532 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0];
534 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_widget);
537 * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a
539 * @kcontrol: The kcontrol
541 * Note: This function must only be used on kcontrols that are known to have
542 * been registered for a CODEC. Otherwise the behaviour is undefined.
544 struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm(
545 struct snd_kcontrol *kcontrol)
547 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->dapm;
549 EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm);
551 static void dapm_reset(struct snd_soc_card *card)
553 struct snd_soc_dapm_widget *w;
555 lockdep_assert_held(&card->dapm_mutex);
557 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
559 list_for_each_entry(w, &card->widgets, list) {
560 w->new_power = w->power;
561 w->power_checked = false;
565 static const char *soc_dapm_prefix(struct snd_soc_dapm_context *dapm)
567 if (!dapm->component)
569 return dapm->component->name_prefix;
572 static int soc_dapm_read(struct snd_soc_dapm_context *dapm, int reg,
575 if (!dapm->component)
577 return snd_soc_component_read(dapm->component, reg, value);
580 static int soc_dapm_update_bits(struct snd_soc_dapm_context *dapm,
581 int reg, unsigned int mask, unsigned int value)
583 if (!dapm->component)
585 return snd_soc_component_update_bits(dapm->component, reg,
589 static int soc_dapm_test_bits(struct snd_soc_dapm_context *dapm,
590 int reg, unsigned int mask, unsigned int value)
592 if (!dapm->component)
594 return snd_soc_component_test_bits(dapm->component, reg, mask, value);
597 static void soc_dapm_async_complete(struct snd_soc_dapm_context *dapm)
600 snd_soc_component_async_complete(dapm->component);
603 static struct snd_soc_dapm_widget *
604 dapm_wcache_lookup(struct snd_soc_dapm_wcache *wcache, const char *name)
606 struct snd_soc_dapm_widget *w = wcache->widget;
607 struct list_head *wlist;
612 wlist = &w->dapm->card->widgets;
614 list_for_each_entry_from(w, wlist, list) {
615 if (!strcmp(name, w->name))
626 static inline void dapm_wcache_update(struct snd_soc_dapm_wcache *wcache,
627 struct snd_soc_dapm_widget *w)
633 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
634 * @dapm: The DAPM context for which to set the level
635 * @level: The level to set
637 * Forces the DAPM bias level to a specific state. It will call the bias level
638 * callback of DAPM context with the specified level. This will even happen if
639 * the context is already at the same level. Furthermore it will not go through
640 * the normal bias level sequencing, meaning any intermediate states between the
641 * current and the target state will not be entered.
643 * Note that the change in bias level is only temporary and the next time
644 * snd_soc_dapm_sync() is called the state will be set to the level as
645 * determined by the DAPM core. The function is mainly intended to be used to
646 * used during probe or resume from suspend to power up the device so
647 * initialization can be done, before the DAPM core takes over.
649 int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context *dapm,
650 enum snd_soc_bias_level level)
654 if (dapm->set_bias_level)
655 ret = dapm->set_bias_level(dapm, level);
658 dapm->bias_level = level;
662 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_bias_level);
665 * snd_soc_dapm_set_bias_level - set the bias level for the system
666 * @dapm: DAPM context
667 * @level: level to configure
669 * Configure the bias (power) levels for the SoC audio device.
671 * Returns 0 for success else error.
673 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
674 enum snd_soc_bias_level level)
676 struct snd_soc_card *card = dapm->card;
679 trace_snd_soc_bias_level_start(card, level);
681 if (card && card->set_bias_level)
682 ret = card->set_bias_level(card, dapm, level);
686 if (!card || dapm != &card->dapm)
687 ret = snd_soc_dapm_force_bias_level(dapm, level);
692 if (card && card->set_bias_level_post)
693 ret = card->set_bias_level_post(card, dapm, level);
695 trace_snd_soc_bias_level_done(card, level);
700 /* connect mux widget to its interconnecting audio paths */
701 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
702 struct snd_soc_dapm_path *path, const char *control_name,
703 struct snd_soc_dapm_widget *w)
705 const struct snd_kcontrol_new *kcontrol = &w->kcontrol_news[0];
706 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
707 unsigned int val, item;
710 if (e->reg != SND_SOC_NOPM) {
711 soc_dapm_read(dapm, e->reg, &val);
712 val = (val >> e->shift_l) & e->mask;
713 item = snd_soc_enum_val_to_item(e, val);
715 /* since a virtual mux has no backing registers to
716 * decide which path to connect, it will try to match
717 * with the first enumeration. This is to ensure
718 * that the default mux choice (the first) will be
719 * correctly powered up during initialization.
724 for (i = 0; i < e->items; i++) {
725 if (!(strcmp(control_name, e->texts[i]))) {
726 path->name = e->texts[i];
738 /* set up initial codec paths */
739 static void dapm_set_mixer_path_status(struct snd_soc_dapm_path *p, int i)
741 struct soc_mixer_control *mc = (struct soc_mixer_control *)
742 p->sink->kcontrol_news[i].private_value;
743 unsigned int reg = mc->reg;
744 unsigned int shift = mc->shift;
745 unsigned int max = mc->max;
746 unsigned int mask = (1 << fls(max)) - 1;
747 unsigned int invert = mc->invert;
748 unsigned int val = 0;
750 if (reg != SND_SOC_NOPM) {
751 soc_dapm_read(p->sink->dapm, reg, &val);
752 val = (val >> shift) & mask;
761 /* connect mixer widget to its interconnecting audio paths */
762 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
763 struct snd_soc_dapm_path *path, const char *control_name)
767 /* search for mixer kcontrol */
768 for (i = 0; i < path->sink->num_kcontrols; i++) {
769 if (!strcmp(control_name, path->sink->kcontrol_news[i].name)) {
770 path->name = path->sink->kcontrol_news[i].name;
771 dapm_set_mixer_path_status(path, i);
778 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
779 struct snd_soc_dapm_widget *kcontrolw,
780 const struct snd_kcontrol_new *kcontrol_new,
781 struct snd_kcontrol **kcontrol)
783 struct snd_soc_dapm_widget *w;
788 list_for_each_entry(w, &dapm->card->widgets, list) {
789 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
791 for (i = 0; i < w->num_kcontrols; i++) {
792 if (&w->kcontrol_news[i] == kcontrol_new) {
794 *kcontrol = w->kcontrols[i];
804 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
805 * create it. Either way, add the widget into the control's widget list
807 static int dapm_create_or_share_kcontrol(struct snd_soc_dapm_widget *w,
810 struct snd_soc_dapm_context *dapm = w->dapm;
811 struct snd_card *card = dapm->card->snd_card;
815 struct snd_kcontrol *kcontrol;
816 bool wname_in_long_name, kcname_in_long_name;
817 char *long_name = NULL;
821 prefix = soc_dapm_prefix(dapm);
823 prefix_len = strlen(prefix) + 1;
827 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[kci],
832 wname_in_long_name = false;
833 kcname_in_long_name = true;
836 case snd_soc_dapm_switch:
837 case snd_soc_dapm_mixer:
838 case snd_soc_dapm_pga:
839 case snd_soc_dapm_out_drv:
840 wname_in_long_name = true;
841 kcname_in_long_name = true;
843 case snd_soc_dapm_mixer_named_ctl:
844 wname_in_long_name = false;
845 kcname_in_long_name = true;
847 case snd_soc_dapm_demux:
848 case snd_soc_dapm_mux:
849 wname_in_long_name = true;
850 kcname_in_long_name = false;
857 if (wname_in_long_name && kcname_in_long_name) {
859 * The control will get a prefix from the control
860 * creation process but we're also using the same
861 * prefix for widgets so cut the prefix off the
862 * front of the widget name.
864 long_name = kasprintf(GFP_KERNEL, "%s %s",
865 w->name + prefix_len,
866 w->kcontrol_news[kci].name);
867 if (long_name == NULL)
871 } else if (wname_in_long_name) {
873 name = w->name + prefix_len;
876 name = w->kcontrol_news[kci].name;
879 kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name,
886 kcontrol->private_free = dapm_kcontrol_free;
888 ret = dapm_kcontrol_data_alloc(w, kcontrol);
890 snd_ctl_free_one(kcontrol);
894 ret = snd_ctl_add(card, kcontrol);
897 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
903 ret = dapm_kcontrol_add_widget(kcontrol, w);
905 w->kcontrols[kci] = kcontrol;
913 /* create new dapm mixer control */
914 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
917 struct snd_soc_dapm_path *path;
918 struct dapm_kcontrol_data *data;
921 for (i = 0; i < w->num_kcontrols; i++) {
923 snd_soc_dapm_widget_for_each_source_path(w, path) {
924 /* mixer/mux paths name must match control name */
925 if (path->name != (char *)w->kcontrol_news[i].name)
928 if (!w->kcontrols[i]) {
929 ret = dapm_create_or_share_kcontrol(w, i);
934 dapm_kcontrol_add_path(w->kcontrols[i], path);
936 data = snd_kcontrol_chip(w->kcontrols[i]);
938 snd_soc_dapm_add_path(data->widget->dapm,
948 /* create new dapm mux control */
949 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
951 struct snd_soc_dapm_context *dapm = w->dapm;
952 enum snd_soc_dapm_direction dir;
953 struct snd_soc_dapm_path *path;
958 case snd_soc_dapm_mux:
959 dir = SND_SOC_DAPM_DIR_OUT;
962 case snd_soc_dapm_demux:
963 dir = SND_SOC_DAPM_DIR_IN;
970 if (w->num_kcontrols != 1) {
972 "ASoC: %s %s has incorrect number of controls\n", type,
977 if (list_empty(&w->edges[dir])) {
978 dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name);
982 ret = dapm_create_or_share_kcontrol(w, 0);
986 snd_soc_dapm_widget_for_each_path(w, dir, path) {
988 dapm_kcontrol_add_path(w->kcontrols[0], path);
994 /* create new dapm volume control */
995 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
999 for (i = 0; i < w->num_kcontrols; i++) {
1000 ret = dapm_create_or_share_kcontrol(w, i);
1008 /* create new dapm dai link control */
1009 static int dapm_new_dai_link(struct snd_soc_dapm_widget *w)
1012 struct snd_kcontrol *kcontrol;
1013 struct snd_soc_dapm_context *dapm = w->dapm;
1014 struct snd_card *card = dapm->card->snd_card;
1016 /* create control for links with > 1 config */
1017 if (w->num_params <= 1)
1021 for (i = 0; i < w->num_kcontrols; i++) {
1022 kcontrol = snd_soc_cnew(&w->kcontrol_news[i], w,
1024 ret = snd_ctl_add(card, kcontrol);
1027 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
1028 w->name, w->kcontrol_news[i].name, ret);
1031 kcontrol->private_data = w;
1032 w->kcontrols[i] = kcontrol;
1038 /* We implement power down on suspend by checking the power state of
1039 * the ALSA card - when we are suspending the ALSA state for the card
1042 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
1044 int level = snd_power_get_state(widget->dapm->card->snd_card);
1047 case SNDRV_CTL_POWER_D3hot:
1048 case SNDRV_CTL_POWER_D3cold:
1049 if (widget->ignore_suspend)
1050 dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n",
1052 return widget->ignore_suspend;
1058 static int dapm_widget_list_create(struct snd_soc_dapm_widget_list **list,
1059 struct list_head *widgets)
1061 struct snd_soc_dapm_widget *w;
1062 struct list_head *it;
1063 unsigned int size = 0;
1066 list_for_each(it, widgets)
1069 *list = kzalloc(sizeof(**list) + size * sizeof(*w), GFP_KERNEL);
1073 list_for_each_entry(w, widgets, work_list)
1074 (*list)->widgets[i++] = w;
1076 (*list)->num_widgets = i;
1082 * Common implementation for is_connected_output_ep() and
1083 * is_connected_input_ep(). The function is inlined since the combined size of
1084 * the two specialized functions is only marginally larger then the size of the
1085 * generic function and at the same time the fast path of the specialized
1086 * functions is significantly smaller than the generic function.
1088 static __always_inline int is_connected_ep(struct snd_soc_dapm_widget *widget,
1089 struct list_head *list, enum snd_soc_dapm_direction dir,
1090 int (*fn)(struct snd_soc_dapm_widget *, struct list_head *))
1092 enum snd_soc_dapm_direction rdir = SND_SOC_DAPM_DIR_REVERSE(dir);
1093 struct snd_soc_dapm_path *path;
1096 if (widget->endpoints[dir] >= 0)
1097 return widget->endpoints[dir];
1099 DAPM_UPDATE_STAT(widget, path_checks);
1101 /* do we need to add this widget to the list ? */
1103 list_add_tail(&widget->work_list, list);
1105 if ((widget->is_ep & SND_SOC_DAPM_DIR_TO_EP(dir)) && widget->connected) {
1106 widget->endpoints[dir] = snd_soc_dapm_suspend_check(widget);
1107 return widget->endpoints[dir];
1110 snd_soc_dapm_widget_for_each_path(widget, rdir, path) {
1111 DAPM_UPDATE_STAT(widget, neighbour_checks);
1113 if (path->weak || path->is_supply)
1119 trace_snd_soc_dapm_path(widget, dir, path);
1121 if (path->connect) {
1123 con += fn(path->node[dir], list);
1128 widget->endpoints[dir] = con;
1134 * Recursively check for a completed path to an active or physically connected
1135 * output widget. Returns number of complete paths.
1137 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
1138 struct list_head *list)
1140 return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_OUT,
1141 is_connected_output_ep);
1145 * Recursively check for a completed path to an active or physically connected
1146 * input widget. Returns number of complete paths.
1148 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
1149 struct list_head *list)
1151 return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_IN,
1152 is_connected_input_ep);
1156 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1157 * @dai: the soc DAI.
1158 * @stream: stream direction.
1159 * @list: list of active widgets for this stream.
1161 * Queries DAPM graph as to whether an valid audio stream path exists for
1162 * the initial stream specified by name. This takes into account
1163 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1165 * Returns the number of valid paths or negative error.
1167 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
1168 struct snd_soc_dapm_widget_list **list)
1170 struct snd_soc_card *card = dai->component->card;
1171 struct snd_soc_dapm_widget *w;
1176 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1179 * For is_connected_{output,input}_ep fully discover the graph we need
1180 * to reset the cached number of inputs and outputs.
1182 list_for_each_entry(w, &card->widgets, list) {
1183 w->endpoints[SND_SOC_DAPM_DIR_IN] = -1;
1184 w->endpoints[SND_SOC_DAPM_DIR_OUT] = -1;
1187 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1188 paths = is_connected_output_ep(dai->playback_widget, &widgets);
1190 paths = is_connected_input_ep(dai->capture_widget, &widgets);
1192 /* Drop starting point */
1193 list_del(widgets.next);
1195 ret = dapm_widget_list_create(list, &widgets);
1199 trace_snd_soc_dapm_connected(paths, stream);
1200 mutex_unlock(&card->dapm_mutex);
1206 * Handler for regulator supply widget.
1208 int dapm_regulator_event(struct snd_soc_dapm_widget *w,
1209 struct snd_kcontrol *kcontrol, int event)
1213 soc_dapm_async_complete(w->dapm);
1215 if (SND_SOC_DAPM_EVENT_ON(event)) {
1216 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) {
1217 ret = regulator_allow_bypass(w->regulator, false);
1219 dev_warn(w->dapm->dev,
1220 "ASoC: Failed to unbypass %s: %d\n",
1224 return regulator_enable(w->regulator);
1226 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) {
1227 ret = regulator_allow_bypass(w->regulator, true);
1229 dev_warn(w->dapm->dev,
1230 "ASoC: Failed to bypass %s: %d\n",
1234 return regulator_disable_deferred(w->regulator, w->shift);
1237 EXPORT_SYMBOL_GPL(dapm_regulator_event);
1240 * Handler for clock supply widget.
1242 int dapm_clock_event(struct snd_soc_dapm_widget *w,
1243 struct snd_kcontrol *kcontrol, int event)
1248 soc_dapm_async_complete(w->dapm);
1250 #ifdef CONFIG_HAVE_CLK
1251 if (SND_SOC_DAPM_EVENT_ON(event)) {
1252 return clk_prepare_enable(w->clk);
1254 clk_disable_unprepare(w->clk);
1260 EXPORT_SYMBOL_GPL(dapm_clock_event);
1262 static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
1264 if (w->power_checked)
1265 return w->new_power;
1270 w->new_power = w->power_check(w);
1272 w->power_checked = true;
1274 return w->new_power;
1277 /* Generic check to see if a widget should be powered.
1279 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
1283 DAPM_UPDATE_STAT(w, power_checks);
1285 in = is_connected_input_ep(w, NULL);
1286 out = is_connected_output_ep(w, NULL);
1287 return out != 0 && in != 0;
1290 /* Check to see if a power supply is needed */
1291 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1293 struct snd_soc_dapm_path *path;
1295 DAPM_UPDATE_STAT(w, power_checks);
1297 /* Check if one of our outputs is connected */
1298 snd_soc_dapm_widget_for_each_sink_path(w, path) {
1299 DAPM_UPDATE_STAT(w, neighbour_checks);
1304 if (path->connected &&
1305 !path->connected(path->source, path->sink))
1308 if (dapm_widget_power_check(path->sink))
1315 static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
1320 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
1321 struct snd_soc_dapm_widget *b,
1329 sort = dapm_down_seq;
1331 if (sort[a->id] != sort[b->id])
1332 return sort[a->id] - sort[b->id];
1333 if (a->subseq != b->subseq) {
1335 return a->subseq - b->subseq;
1337 return b->subseq - a->subseq;
1339 if (a->reg != b->reg)
1340 return a->reg - b->reg;
1341 if (a->dapm != b->dapm)
1342 return (unsigned long)a->dapm - (unsigned long)b->dapm;
1347 /* Insert a widget in order into a DAPM power sequence. */
1348 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
1349 struct list_head *list,
1352 struct snd_soc_dapm_widget *w;
1354 list_for_each_entry(w, list, power_list)
1355 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
1356 list_add_tail(&new_widget->power_list, &w->power_list);
1360 list_add_tail(&new_widget->power_list, list);
1363 static void dapm_seq_check_event(struct snd_soc_card *card,
1364 struct snd_soc_dapm_widget *w, int event)
1366 const char *ev_name;
1370 case SND_SOC_DAPM_PRE_PMU:
1371 ev_name = "PRE_PMU";
1374 case SND_SOC_DAPM_POST_PMU:
1375 ev_name = "POST_PMU";
1378 case SND_SOC_DAPM_PRE_PMD:
1379 ev_name = "PRE_PMD";
1382 case SND_SOC_DAPM_POST_PMD:
1383 ev_name = "POST_PMD";
1386 case SND_SOC_DAPM_WILL_PMU:
1387 ev_name = "WILL_PMU";
1390 case SND_SOC_DAPM_WILL_PMD:
1391 ev_name = "WILL_PMD";
1395 WARN(1, "Unknown event %d\n", event);
1399 if (w->new_power != power)
1402 if (w->event && (w->event_flags & event)) {
1403 pop_dbg(w->dapm->dev, card->pop_time, "pop test : %s %s\n",
1405 soc_dapm_async_complete(w->dapm);
1406 trace_snd_soc_dapm_widget_event_start(w, event);
1407 ret = w->event(w, NULL, event);
1408 trace_snd_soc_dapm_widget_event_done(w, event);
1410 dev_err(w->dapm->dev, "ASoC: %s: %s event failed: %d\n",
1411 ev_name, w->name, ret);
1415 /* Apply the coalesced changes from a DAPM sequence */
1416 static void dapm_seq_run_coalesced(struct snd_soc_card *card,
1417 struct list_head *pending)
1419 struct snd_soc_dapm_context *dapm;
1420 struct snd_soc_dapm_widget *w;
1422 unsigned int value = 0;
1423 unsigned int mask = 0;
1425 w = list_first_entry(pending, struct snd_soc_dapm_widget, power_list);
1429 list_for_each_entry(w, pending, power_list) {
1430 WARN_ON(reg != w->reg || dapm != w->dapm);
1431 w->power = w->new_power;
1433 mask |= w->mask << w->shift;
1435 value |= w->on_val << w->shift;
1437 value |= w->off_val << w->shift;
1439 pop_dbg(dapm->dev, card->pop_time,
1440 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1441 w->name, reg, value, mask);
1443 /* Check for events */
1444 dapm_seq_check_event(card, w, SND_SOC_DAPM_PRE_PMU);
1445 dapm_seq_check_event(card, w, SND_SOC_DAPM_PRE_PMD);
1449 /* Any widget will do, they should all be updating the
1453 pop_dbg(dapm->dev, card->pop_time,
1454 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1455 value, mask, reg, card->pop_time);
1456 pop_wait(card->pop_time);
1457 soc_dapm_update_bits(dapm, reg, mask, value);
1460 list_for_each_entry(w, pending, power_list) {
1461 dapm_seq_check_event(card, w, SND_SOC_DAPM_POST_PMU);
1462 dapm_seq_check_event(card, w, SND_SOC_DAPM_POST_PMD);
1466 /* Apply a DAPM power sequence.
1468 * We walk over a pre-sorted list of widgets to apply power to. In
1469 * order to minimise the number of writes to the device required
1470 * multiple widgets will be updated in a single write where possible.
1471 * Currently anything that requires more than a single write is not
1474 static void dapm_seq_run(struct snd_soc_card *card,
1475 struct list_head *list, int event, bool power_up)
1477 struct snd_soc_dapm_widget *w, *n;
1478 struct snd_soc_dapm_context *d;
1481 int cur_subseq = -1;
1482 int cur_reg = SND_SOC_NOPM;
1483 struct snd_soc_dapm_context *cur_dapm = NULL;
1490 sort = dapm_down_seq;
1492 list_for_each_entry_safe(w, n, list, power_list) {
1495 /* Do we need to apply any queued changes? */
1496 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1497 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1498 if (cur_dapm && !list_empty(&pending))
1499 dapm_seq_run_coalesced(card, &pending);
1501 if (cur_dapm && cur_dapm->seq_notifier) {
1502 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1503 if (sort[i] == cur_sort)
1504 cur_dapm->seq_notifier(cur_dapm,
1509 if (cur_dapm && w->dapm != cur_dapm)
1510 soc_dapm_async_complete(cur_dapm);
1512 INIT_LIST_HEAD(&pending);
1514 cur_subseq = INT_MIN;
1515 cur_reg = SND_SOC_NOPM;
1520 case snd_soc_dapm_pre:
1522 list_for_each_entry_safe_continue(w, n, list,
1525 if (event == SND_SOC_DAPM_STREAM_START)
1527 NULL, SND_SOC_DAPM_PRE_PMU);
1528 else if (event == SND_SOC_DAPM_STREAM_STOP)
1530 NULL, SND_SOC_DAPM_PRE_PMD);
1533 case snd_soc_dapm_post:
1535 list_for_each_entry_safe_continue(w, n, list,
1538 if (event == SND_SOC_DAPM_STREAM_START)
1540 NULL, SND_SOC_DAPM_POST_PMU);
1541 else if (event == SND_SOC_DAPM_STREAM_STOP)
1543 NULL, SND_SOC_DAPM_POST_PMD);
1547 /* Queue it up for application */
1548 cur_sort = sort[w->id];
1549 cur_subseq = w->subseq;
1552 list_move(&w->power_list, &pending);
1556 /* Add this debug log to keep track of widgets being
1557 * powered-up and powered-down */
1558 dev_dbg(w->dapm->dev, "dapm: powering %s widget %s\n",
1559 power_up ? "up" : "down", w->name);
1562 dev_err(w->dapm->dev,
1563 "ASoC: Failed to apply widget power: %d\n", ret);
1566 if (cur_dapm && !list_empty(&pending))
1567 dapm_seq_run_coalesced(card, &pending);
1569 if (cur_dapm && cur_dapm->seq_notifier) {
1570 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1571 if (sort[i] == cur_sort)
1572 cur_dapm->seq_notifier(cur_dapm,
1576 list_for_each_entry(d, &card->dapm_list, list) {
1577 soc_dapm_async_complete(d);
1581 static void dapm_widget_update(struct snd_soc_card *card)
1583 struct snd_soc_dapm_update *update = card->update;
1584 struct snd_soc_dapm_widget_list *wlist;
1585 struct snd_soc_dapm_widget *w = NULL;
1589 if (!update || !dapm_kcontrol_is_powered(update->kcontrol))
1592 wlist = dapm_kcontrol_get_wlist(update->kcontrol);
1594 for (wi = 0; wi < wlist->num_widgets; wi++) {
1595 w = wlist->widgets[wi];
1597 if (w->event && (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1598 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1600 dev_err(w->dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n",
1608 ret = soc_dapm_update_bits(w->dapm, update->reg, update->mask,
1611 dev_err(w->dapm->dev, "ASoC: %s DAPM update failed: %d\n",
1614 for (wi = 0; wi < wlist->num_widgets; wi++) {
1615 w = wlist->widgets[wi];
1617 if (w->event && (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1618 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1620 dev_err(w->dapm->dev, "ASoC: %s DAPM post-event failed: %d\n",
1626 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1627 * they're changing state.
1629 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1631 struct snd_soc_dapm_context *d = data;
1634 /* If we're off and we're not supposed to be go into STANDBY */
1635 if (d->bias_level == SND_SOC_BIAS_OFF &&
1636 d->target_bias_level != SND_SOC_BIAS_OFF) {
1638 pm_runtime_get_sync(d->dev);
1640 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1643 "ASoC: Failed to turn on bias: %d\n", ret);
1646 /* Prepare for a transition to ON or away from ON */
1647 if ((d->target_bias_level == SND_SOC_BIAS_ON &&
1648 d->bias_level != SND_SOC_BIAS_ON) ||
1649 (d->target_bias_level != SND_SOC_BIAS_ON &&
1650 d->bias_level == SND_SOC_BIAS_ON)) {
1651 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1654 "ASoC: Failed to prepare bias: %d\n", ret);
1658 /* Async callback run prior to DAPM sequences - brings to their final
1661 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1663 struct snd_soc_dapm_context *d = data;
1666 /* If we just powered the last thing off drop to standby bias */
1667 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1668 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1669 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1670 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1672 dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n",
1676 /* If we're in standby and can support bias off then do that */
1677 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1678 d->target_bias_level == SND_SOC_BIAS_OFF) {
1679 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1681 dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n",
1685 pm_runtime_put(d->dev);
1688 /* If we just powered up then move to active bias */
1689 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1690 d->target_bias_level == SND_SOC_BIAS_ON) {
1691 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1693 dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n",
1698 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
1699 bool power, bool connect)
1701 /* If a connection is being made or broken then that update
1702 * will have marked the peer dirty, otherwise the widgets are
1703 * not connected and this update has no impact. */
1707 /* If the peer is already in the state we're moving to then we
1708 * won't have an impact on it. */
1709 if (power != peer->power)
1710 dapm_mark_dirty(peer, "peer state change");
1713 static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1714 struct list_head *up_list,
1715 struct list_head *down_list)
1717 struct snd_soc_dapm_path *path;
1719 if (w->power == power)
1722 trace_snd_soc_dapm_widget_power(w, power);
1724 /* If we changed our power state perhaps our neigbours changed
1727 snd_soc_dapm_widget_for_each_source_path(w, path)
1728 dapm_widget_set_peer_power(path->source, power, path->connect);
1730 /* Supplies can't affect their outputs, only their inputs */
1731 if (!w->is_supply) {
1732 snd_soc_dapm_widget_for_each_sink_path(w, path)
1733 dapm_widget_set_peer_power(path->sink, power,
1738 dapm_seq_insert(w, up_list, true);
1740 dapm_seq_insert(w, down_list, false);
1743 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1744 struct list_head *up_list,
1745 struct list_head *down_list)
1750 case snd_soc_dapm_pre:
1751 dapm_seq_insert(w, down_list, false);
1753 case snd_soc_dapm_post:
1754 dapm_seq_insert(w, up_list, true);
1758 power = dapm_widget_power_check(w);
1760 dapm_widget_set_power(w, power, up_list, down_list);
1765 static bool dapm_idle_bias_off(struct snd_soc_dapm_context *dapm)
1767 if (dapm->idle_bias_off)
1770 switch (snd_power_get_state(dapm->card->snd_card)) {
1771 case SNDRV_CTL_POWER_D3hot:
1772 case SNDRV_CTL_POWER_D3cold:
1773 return dapm->suspend_bias_off;
1782 * Scan each dapm widget for complete audio path.
1783 * A complete path is a route that has valid endpoints i.e.:-
1785 * o DAC to output pin.
1786 * o Input Pin to ADC.
1787 * o Input pin to Output pin (bypass, sidetone)
1788 * o DAC to ADC (loopback).
1790 static int dapm_power_widgets(struct snd_soc_card *card, int event)
1792 struct snd_soc_dapm_widget *w;
1793 struct snd_soc_dapm_context *d;
1795 LIST_HEAD(down_list);
1796 ASYNC_DOMAIN_EXCLUSIVE(async_domain);
1797 enum snd_soc_bias_level bias;
1798 struct snd_soc_platform *p;
1799 struct snd_soc_codec *c;
1801 lockdep_assert_held(&card->dapm_mutex);
1803 trace_snd_soc_dapm_start(card);
1804 mutex_lock(&card->dapm_power_mutex);
1806 list_for_each_entry(d, &card->dapm_list, list) {
1807 if (dapm_idle_bias_off(d))
1808 d->target_bias_level = SND_SOC_BIAS_OFF;
1810 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1815 /* Check which widgets we need to power and store them in
1816 * lists indicating if they should be powered up or down. We
1817 * only check widgets that have been flagged as dirty but note
1818 * that new widgets may be added to the dirty list while we
1821 list_for_each_entry(w, &card->dapm_dirty, dirty) {
1822 dapm_power_one_widget(w, &up_list, &down_list);
1825 list_for_each_entry(w, &card->widgets, list) {
1827 case snd_soc_dapm_pre:
1828 case snd_soc_dapm_post:
1829 /* These widgets always need to be powered */
1832 list_del_init(&w->dirty);
1839 /* Supplies and micbiases only bring the
1840 * context up to STANDBY as unless something
1841 * else is active and passing audio they
1842 * generally don't require full power. Signal
1843 * generators are virtual pins and have no
1844 * power impact themselves.
1847 case snd_soc_dapm_siggen:
1848 case snd_soc_dapm_vmid:
1850 case snd_soc_dapm_supply:
1851 case snd_soc_dapm_regulator_supply:
1852 case snd_soc_dapm_clock_supply:
1853 case snd_soc_dapm_micbias:
1854 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1855 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1858 d->target_bias_level = SND_SOC_BIAS_ON;
1865 /* Force all contexts in the card to the same bias state if
1866 * they're not ground referenced.
1868 bias = SND_SOC_BIAS_OFF;
1869 list_for_each_entry(d, &card->dapm_list, list)
1870 if (d->target_bias_level > bias)
1871 bias = d->target_bias_level;
1872 list_for_each_entry(d, &card->dapm_list, list)
1873 if (!dapm_idle_bias_off(d))
1874 d->target_bias_level = bias;
1876 trace_snd_soc_dapm_walk_done(card);
1878 /* Run card bias changes at first */
1879 dapm_pre_sequence_async(&card->dapm, 0);
1880 /* Run other bias changes in parallel */
1881 list_for_each_entry(d, &card->dapm_list, list) {
1882 p = snd_soc_dapm_to_platform(d);
1883 c = snd_soc_dapm_to_codec(d);
1884 if ((d != &card->dapm) && (c || p))
1885 async_schedule_domain(dapm_pre_sequence_async, d,
1888 async_synchronize_full_domain(&async_domain);
1890 list_for_each_entry(w, &down_list, power_list) {
1891 dapm_seq_check_event(card, w, SND_SOC_DAPM_WILL_PMD);
1894 list_for_each_entry(w, &up_list, power_list) {
1895 dapm_seq_check_event(card, w, SND_SOC_DAPM_WILL_PMU);
1898 /* Power down widgets first; try to avoid amplifying pops. */
1899 dapm_seq_run(card, &down_list, event, false);
1901 dapm_widget_update(card);
1904 dapm_seq_run(card, &up_list, event, true);
1906 /* Run all the bias changes in parallel */
1907 list_for_each_entry(d, &card->dapm_list, list) {
1908 p = snd_soc_dapm_to_platform(d);
1909 c = snd_soc_dapm_to_codec(d);
1910 if ((d != &card->dapm) && (c || p))
1911 async_schedule_domain(dapm_post_sequence_async, d,
1914 async_synchronize_full_domain(&async_domain);
1915 /* Run card bias changes at last */
1916 dapm_post_sequence_async(&card->dapm, 0);
1918 /* do we need to notify any clients that DAPM event is complete */
1919 list_for_each_entry(d, &card->dapm_list, list) {
1920 if (d->stream_event)
1921 d->stream_event(d, event);
1924 pop_dbg(card->dev, card->pop_time,
1925 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1926 pop_wait(card->pop_time);
1927 mutex_unlock(&card->dapm_power_mutex);
1929 trace_snd_soc_dapm_done(card);
1934 #ifdef CONFIG_DEBUG_FS
1935 static ssize_t dapm_widget_power_read_file(struct file *file,
1936 char __user *user_buf,
1937 size_t count, loff_t *ppos)
1939 struct snd_soc_dapm_widget *w = file->private_data;
1940 struct snd_soc_card *card = w->dapm->card;
1941 enum snd_soc_dapm_direction dir, rdir;
1945 struct snd_soc_dapm_path *p = NULL;
1947 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1951 mutex_lock(&card->dapm_mutex);
1953 /* Supply widgets are not handled by is_connected_{input,output}_ep() */
1958 in = is_connected_input_ep(w, NULL);
1959 out = is_connected_output_ep(w, NULL);
1962 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
1963 w->name, w->power ? "On" : "Off",
1964 w->force ? " (forced)" : "", in, out);
1967 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1968 " - R%d(0x%x) mask 0x%x",
1969 w->reg, w->reg, w->mask << w->shift);
1971 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1974 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1976 w->active ? "active" : "inactive");
1978 snd_soc_dapm_for_each_direction(dir) {
1979 rdir = SND_SOC_DAPM_DIR_REVERSE(dir);
1980 snd_soc_dapm_widget_for_each_path(w, dir, p) {
1981 if (p->connected && !p->connected(w, p->node[rdir]))
1987 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1988 " %s \"%s\" \"%s\"\n",
1989 (rdir == SND_SOC_DAPM_DIR_IN) ? "in" : "out",
1990 p->name ? p->name : "static",
1991 p->node[rdir]->name);
1995 mutex_unlock(&card->dapm_mutex);
1997 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
2003 static const struct file_operations dapm_widget_power_fops = {
2004 .open = simple_open,
2005 .read = dapm_widget_power_read_file,
2006 .llseek = default_llseek,
2009 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
2010 size_t count, loff_t *ppos)
2012 struct snd_soc_dapm_context *dapm = file->private_data;
2015 switch (dapm->bias_level) {
2016 case SND_SOC_BIAS_ON:
2019 case SND_SOC_BIAS_PREPARE:
2020 level = "Prepare\n";
2022 case SND_SOC_BIAS_STANDBY:
2023 level = "Standby\n";
2025 case SND_SOC_BIAS_OFF:
2029 WARN(1, "Unknown bias_level %d\n", dapm->bias_level);
2030 level = "Unknown\n";
2034 return simple_read_from_buffer(user_buf, count, ppos, level,
2038 static const struct file_operations dapm_bias_fops = {
2039 .open = simple_open,
2040 .read = dapm_bias_read_file,
2041 .llseek = default_llseek,
2044 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
2045 struct dentry *parent)
2052 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
2054 if (!dapm->debugfs_dapm) {
2056 "ASoC: Failed to create DAPM debugfs directory\n");
2060 d = debugfs_create_file("bias_level", 0444,
2061 dapm->debugfs_dapm, dapm,
2065 "ASoC: Failed to create bias level debugfs file\n");
2068 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
2070 struct snd_soc_dapm_context *dapm = w->dapm;
2073 if (!dapm->debugfs_dapm || !w->name)
2076 d = debugfs_create_file(w->name, 0444,
2077 dapm->debugfs_dapm, w,
2078 &dapm_widget_power_fops);
2080 dev_warn(w->dapm->dev,
2081 "ASoC: Failed to create %s debugfs file\n",
2085 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
2087 debugfs_remove_recursive(dapm->debugfs_dapm);
2091 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
2092 struct dentry *parent)
2096 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
2100 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
2107 * soc_dapm_connect_path() - Connects or disconnects a path
2108 * @path: The path to update
2109 * @connect: The new connect state of the path. True if the path is connected,
2110 * false if it is disconneted.
2111 * @reason: The reason why the path changed (for debugging only)
2113 static void soc_dapm_connect_path(struct snd_soc_dapm_path *path,
2114 bool connect, const char *reason)
2116 if (path->connect == connect)
2119 path->connect = connect;
2120 dapm_mark_dirty(path->source, reason);
2121 dapm_mark_dirty(path->sink, reason);
2122 dapm_path_invalidate(path);
2125 /* test and update the power status of a mux widget */
2126 static int soc_dapm_mux_update_power(struct snd_soc_card *card,
2127 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
2129 struct snd_soc_dapm_path *path;
2133 lockdep_assert_held(&card->dapm_mutex);
2135 /* find dapm widget path assoc with kcontrol */
2136 dapm_kcontrol_for_each_path(path, kcontrol) {
2138 /* we now need to match the string in the enum to the path */
2139 if (!(strcmp(path->name, e->texts[mux])))
2144 soc_dapm_connect_path(path, connect, "mux update");
2148 dapm_power_widgets(card, SND_SOC_DAPM_STREAM_NOP);
2153 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm,
2154 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e,
2155 struct snd_soc_dapm_update *update)
2157 struct snd_soc_card *card = dapm->card;
2160 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2161 card->update = update;
2162 ret = soc_dapm_mux_update_power(card, kcontrol, mux, e);
2163 card->update = NULL;
2164 mutex_unlock(&card->dapm_mutex);
2166 soc_dpcm_runtime_update(card);
2169 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
2171 /* test and update the power status of a mixer or switch widget */
2172 static int soc_dapm_mixer_update_power(struct snd_soc_card *card,
2173 struct snd_kcontrol *kcontrol, int connect)
2175 struct snd_soc_dapm_path *path;
2178 lockdep_assert_held(&card->dapm_mutex);
2180 /* find dapm widget path assoc with kcontrol */
2181 dapm_kcontrol_for_each_path(path, kcontrol) {
2183 soc_dapm_connect_path(path, connect, "mixer update");
2187 dapm_power_widgets(card, SND_SOC_DAPM_STREAM_NOP);
2192 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm,
2193 struct snd_kcontrol *kcontrol, int connect,
2194 struct snd_soc_dapm_update *update)
2196 struct snd_soc_card *card = dapm->card;
2199 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2200 card->update = update;
2201 ret = soc_dapm_mixer_update_power(card, kcontrol, connect);
2202 card->update = NULL;
2203 mutex_unlock(&card->dapm_mutex);
2205 soc_dpcm_runtime_update(card);
2208 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
2210 static ssize_t dapm_widget_show_component(struct snd_soc_component *cmpnt,
2213 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
2214 struct snd_soc_dapm_widget *w;
2216 char *state = "not set";
2218 /* card won't be set for the dummy component, as a spot fix
2219 * we're checking for that case specifically here but in future
2220 * we will ensure that the dummy component looks like others.
2225 list_for_each_entry(w, &cmpnt->card->widgets, list) {
2226 if (w->dapm != dapm)
2229 /* only display widgets that burnm power */
2231 case snd_soc_dapm_hp:
2232 case snd_soc_dapm_mic:
2233 case snd_soc_dapm_spk:
2234 case snd_soc_dapm_line:
2235 case snd_soc_dapm_micbias:
2236 case snd_soc_dapm_dac:
2237 case snd_soc_dapm_adc:
2238 case snd_soc_dapm_pga:
2239 case snd_soc_dapm_out_drv:
2240 case snd_soc_dapm_mixer:
2241 case snd_soc_dapm_mixer_named_ctl:
2242 case snd_soc_dapm_supply:
2243 case snd_soc_dapm_regulator_supply:
2244 case snd_soc_dapm_clock_supply:
2246 count += sprintf(buf + count, "%s: %s\n",
2247 w->name, w->power ? "On":"Off");
2254 switch (snd_soc_dapm_get_bias_level(dapm)) {
2255 case SND_SOC_BIAS_ON:
2258 case SND_SOC_BIAS_PREPARE:
2261 case SND_SOC_BIAS_STANDBY:
2264 case SND_SOC_BIAS_OFF:
2268 count += sprintf(buf + count, "PM State: %s\n", state);
2273 /* show dapm widget status in sys fs */
2274 static ssize_t dapm_widget_show(struct device *dev,
2275 struct device_attribute *attr, char *buf)
2277 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
2280 mutex_lock(&rtd->card->dapm_mutex);
2282 for (i = 0; i < rtd->num_codecs; i++) {
2283 struct snd_soc_component *cmpnt = rtd->codec_dais[i]->component;
2285 count += dapm_widget_show_component(cmpnt, buf + count);
2288 mutex_unlock(&rtd->card->dapm_mutex);
2293 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
2295 struct attribute *soc_dapm_dev_attrs[] = {
2296 &dev_attr_dapm_widget.attr,
2300 static void dapm_free_path(struct snd_soc_dapm_path *path)
2302 list_del(&path->list_node[SND_SOC_DAPM_DIR_IN]);
2303 list_del(&path->list_node[SND_SOC_DAPM_DIR_OUT]);
2304 list_del(&path->list_kcontrol);
2305 list_del(&path->list);
2309 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
2311 struct snd_soc_dapm_path *p, *next_p;
2312 enum snd_soc_dapm_direction dir;
2316 * remove source and sink paths associated to this widget.
2317 * While removing the path, remove reference to it from both
2318 * source and sink widgets so that path is removed only once.
2320 snd_soc_dapm_for_each_direction(dir) {
2321 snd_soc_dapm_widget_for_each_path_safe(w, dir, p, next_p)
2325 kfree(w->kcontrols);
2326 kfree_const(w->name);
2330 void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm)
2332 dapm->path_sink_cache.widget = NULL;
2333 dapm->path_source_cache.widget = NULL;
2336 /* free all dapm widgets and resources */
2337 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
2339 struct snd_soc_dapm_widget *w, *next_w;
2341 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
2342 if (w->dapm != dapm)
2344 snd_soc_dapm_free_widget(w);
2346 snd_soc_dapm_reset_cache(dapm);
2349 static struct snd_soc_dapm_widget *dapm_find_widget(
2350 struct snd_soc_dapm_context *dapm, const char *pin,
2351 bool search_other_contexts)
2353 struct snd_soc_dapm_widget *w;
2354 struct snd_soc_dapm_widget *fallback = NULL;
2356 list_for_each_entry(w, &dapm->card->widgets, list) {
2357 if (!strcmp(w->name, pin)) {
2358 if (w->dapm == dapm)
2365 if (search_other_contexts)
2371 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2372 const char *pin, int status)
2374 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2376 dapm_assert_locked(dapm);
2379 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin);
2383 if (w->connected != status) {
2384 dapm_mark_dirty(w, "pin configuration");
2385 dapm_widget_invalidate_input_paths(w);
2386 dapm_widget_invalidate_output_paths(w);
2389 w->connected = status;
2397 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2398 * @dapm: DAPM context
2400 * Walks all dapm audio paths and powers widgets according to their
2401 * stream or path usage.
2403 * Requires external locking.
2405 * Returns 0 for success.
2407 int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm)
2410 * Suppress early reports (eg, jacks syncing their state) to avoid
2411 * silly DAPM runs during card startup.
2413 if (!dapm->card || !dapm->card->instantiated)
2416 return dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP);
2418 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked);
2421 * snd_soc_dapm_sync - scan and power dapm paths
2422 * @dapm: DAPM context
2424 * Walks all dapm audio paths and powers widgets according to their
2425 * stream or path usage.
2427 * Returns 0 for success.
2429 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2433 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2434 ret = snd_soc_dapm_sync_unlocked(dapm);
2435 mutex_unlock(&dapm->card->dapm_mutex);
2438 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2441 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2442 * @w: The widget for which to update the flags
2444 * Some widgets have a dynamic category which depends on which neighbors they
2445 * are connected to. This function update the category for these widgets.
2447 * This function must be called whenever a path is added or removed to a widget.
2449 static void dapm_update_widget_flags(struct snd_soc_dapm_widget *w)
2451 enum snd_soc_dapm_direction dir;
2452 struct snd_soc_dapm_path *p;
2456 case snd_soc_dapm_input:
2457 /* On a fully routed card a input is never a source */
2458 if (w->dapm->card->fully_routed)
2460 ep = SND_SOC_DAPM_EP_SOURCE;
2461 snd_soc_dapm_widget_for_each_source_path(w, p) {
2462 if (p->source->id == snd_soc_dapm_micbias ||
2463 p->source->id == snd_soc_dapm_mic ||
2464 p->source->id == snd_soc_dapm_line ||
2465 p->source->id == snd_soc_dapm_output) {
2471 case snd_soc_dapm_output:
2472 /* On a fully routed card a output is never a sink */
2473 if (w->dapm->card->fully_routed)
2475 ep = SND_SOC_DAPM_EP_SINK;
2476 snd_soc_dapm_widget_for_each_sink_path(w, p) {
2477 if (p->sink->id == snd_soc_dapm_spk ||
2478 p->sink->id == snd_soc_dapm_hp ||
2479 p->sink->id == snd_soc_dapm_line ||
2480 p->sink->id == snd_soc_dapm_input) {
2486 case snd_soc_dapm_line:
2488 snd_soc_dapm_for_each_direction(dir) {
2489 if (!list_empty(&w->edges[dir]))
2490 ep |= SND_SOC_DAPM_DIR_TO_EP(dir);
2500 static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context *dapm,
2501 struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink,
2502 const char *control)
2504 bool dynamic_source = false;
2505 bool dynamic_sink = false;
2510 switch (source->id) {
2511 case snd_soc_dapm_demux:
2512 dynamic_source = true;
2519 case snd_soc_dapm_mux:
2520 case snd_soc_dapm_switch:
2521 case snd_soc_dapm_mixer:
2522 case snd_soc_dapm_mixer_named_ctl:
2523 dynamic_sink = true;
2529 if (dynamic_source && dynamic_sink) {
2531 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n",
2532 source->name, control, sink->name);
2534 } else if (!dynamic_source && !dynamic_sink) {
2536 "Control not supported for path %s -> [%s] -> %s\n",
2537 source->name, control, sink->name);
2544 static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2545 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink,
2546 const char *control,
2547 int (*connected)(struct snd_soc_dapm_widget *source,
2548 struct snd_soc_dapm_widget *sink))
2550 struct snd_soc_dapm_widget *widgets[2];
2551 enum snd_soc_dapm_direction dir;
2552 struct snd_soc_dapm_path *path;
2555 if (wsink->is_supply && !wsource->is_supply) {
2557 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n",
2558 wsource->name, wsink->name);
2562 if (connected && !wsource->is_supply) {
2564 "connected() callback only supported for supply widgets (%s -> %s)\n",
2565 wsource->name, wsink->name);
2569 if (wsource->is_supply && control) {
2571 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n",
2572 wsource->name, control, wsink->name);
2576 ret = snd_soc_dapm_check_dynamic_path(dapm, wsource, wsink, control);
2580 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2584 path->node[SND_SOC_DAPM_DIR_IN] = wsource;
2585 path->node[SND_SOC_DAPM_DIR_OUT] = wsink;
2586 widgets[SND_SOC_DAPM_DIR_IN] = wsource;
2587 widgets[SND_SOC_DAPM_DIR_OUT] = wsink;
2589 path->connected = connected;
2590 INIT_LIST_HEAD(&path->list);
2591 INIT_LIST_HEAD(&path->list_kcontrol);
2593 if (wsource->is_supply || wsink->is_supply)
2594 path->is_supply = 1;
2596 /* connect static paths */
2597 if (control == NULL) {
2600 switch (wsource->id) {
2601 case snd_soc_dapm_demux:
2602 ret = dapm_connect_mux(dapm, path, control, wsource);
2610 switch (wsink->id) {
2611 case snd_soc_dapm_mux:
2612 ret = dapm_connect_mux(dapm, path, control, wsink);
2616 case snd_soc_dapm_switch:
2617 case snd_soc_dapm_mixer:
2618 case snd_soc_dapm_mixer_named_ctl:
2619 ret = dapm_connect_mixer(dapm, path, control);
2628 list_add(&path->list, &dapm->card->paths);
2629 snd_soc_dapm_for_each_direction(dir)
2630 list_add(&path->list_node[dir], &widgets[dir]->edges[dir]);
2632 snd_soc_dapm_for_each_direction(dir) {
2633 dapm_update_widget_flags(widgets[dir]);
2634 dapm_mark_dirty(widgets[dir], "Route added");
2637 dapm_path_invalidate(path);
2645 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2646 const struct snd_soc_dapm_route *route)
2648 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
2649 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
2652 char prefixed_sink[80];
2653 char prefixed_source[80];
2657 prefix = soc_dapm_prefix(dapm);
2659 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2660 prefix, route->sink);
2661 sink = prefixed_sink;
2662 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2663 prefix, route->source);
2664 source = prefixed_source;
2667 source = route->source;
2670 wsource = dapm_wcache_lookup(&dapm->path_source_cache, source);
2671 wsink = dapm_wcache_lookup(&dapm->path_sink_cache, sink);
2673 if (wsink && wsource)
2677 * find src and dest widgets over all widgets but favor a widget from
2678 * current DAPM context
2680 list_for_each_entry(w, &dapm->card->widgets, list) {
2681 if (!wsink && !(strcmp(w->name, sink))) {
2683 if (w->dapm == dapm) {
2690 if (!wsource && !(strcmp(w->name, source))) {
2692 if (w->dapm == dapm) {
2699 /* use widget from another DAPM context if not found from this */
2705 if (wsource == NULL) {
2706 dev_err(dapm->dev, "ASoC: no source widget found for %s\n",
2710 if (wsink == NULL) {
2711 dev_err(dapm->dev, "ASoC: no sink widget found for %s\n",
2717 dapm_wcache_update(&dapm->path_sink_cache, wsink);
2718 dapm_wcache_update(&dapm->path_source_cache, wsource);
2720 ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control,
2727 dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n",
2728 source, route->control, sink);
2732 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm,
2733 const struct snd_soc_dapm_route *route)
2735 struct snd_soc_dapm_widget *wsource, *wsink;
2736 struct snd_soc_dapm_path *path, *p;
2739 char prefixed_sink[80];
2740 char prefixed_source[80];
2743 if (route->control) {
2745 "ASoC: Removal of routes with controls not supported\n");
2749 prefix = soc_dapm_prefix(dapm);
2751 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2752 prefix, route->sink);
2753 sink = prefixed_sink;
2754 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2755 prefix, route->source);
2756 source = prefixed_source;
2759 source = route->source;
2763 list_for_each_entry(p, &dapm->card->paths, list) {
2764 if (strcmp(p->source->name, source) != 0)
2766 if (strcmp(p->sink->name, sink) != 0)
2773 wsource = path->source;
2776 dapm_mark_dirty(wsource, "Route removed");
2777 dapm_mark_dirty(wsink, "Route removed");
2779 dapm_path_invalidate(path);
2781 dapm_free_path(path);
2783 /* Update any path related flags */
2784 dapm_update_widget_flags(wsource);
2785 dapm_update_widget_flags(wsink);
2787 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n",
2795 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2796 * @dapm: DAPM context
2797 * @route: audio routes
2798 * @num: number of routes
2800 * Connects 2 dapm widgets together via a named audio path. The sink is
2801 * the widget receiving the audio signal, whilst the source is the sender
2802 * of the audio signal.
2804 * Returns 0 for success else error. On error all resources can be freed
2805 * with a call to snd_soc_card_free().
2807 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2808 const struct snd_soc_dapm_route *route, int num)
2812 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2813 for (i = 0; i < num; i++) {
2814 r = snd_soc_dapm_add_route(dapm, route);
2816 dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n",
2818 route->control ? route->control : "direct",
2824 mutex_unlock(&dapm->card->dapm_mutex);
2828 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2831 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2832 * @dapm: DAPM context
2833 * @route: audio routes
2834 * @num: number of routes
2836 * Removes routes from the DAPM context.
2838 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
2839 const struct snd_soc_dapm_route *route, int num)
2843 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2844 for (i = 0; i < num; i++) {
2845 snd_soc_dapm_del_route(dapm, route);
2848 mutex_unlock(&dapm->card->dapm_mutex);
2852 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes);
2854 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2855 const struct snd_soc_dapm_route *route)
2857 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2860 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2863 struct snd_soc_dapm_path *path;
2867 dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n",
2873 dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n",
2878 if (route->control || route->connected)
2879 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n",
2880 route->source, route->sink);
2882 snd_soc_dapm_widget_for_each_sink_path(source, path) {
2883 if (path->sink == sink) {
2890 dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n",
2891 route->source, route->sink);
2893 dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n",
2894 count, route->source, route->sink);
2900 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2901 * @dapm: DAPM context
2902 * @route: audio routes
2903 * @num: number of routes
2905 * Mark existing routes matching those specified in the passed array
2906 * as being weak, meaning that they are ignored for the purpose of
2907 * power decisions. The main intended use case is for sidetone paths
2908 * which couple audio between other independent paths if they are both
2909 * active in order to make the combination work better at the user
2910 * level but which aren't intended to be "used".
2912 * Note that CODEC drivers should not use this as sidetone type paths
2913 * can frequently also be used as bypass paths.
2915 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2916 const struct snd_soc_dapm_route *route, int num)
2921 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2922 for (i = 0; i < num; i++) {
2923 err = snd_soc_dapm_weak_route(dapm, route);
2928 mutex_unlock(&dapm->card->dapm_mutex);
2932 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2935 * snd_soc_dapm_new_widgets - add new dapm widgets
2936 * @card: card to be checked for new dapm widgets
2938 * Checks the codec for any new dapm widgets and creates them if found.
2940 * Returns 0 for success.
2942 int snd_soc_dapm_new_widgets(struct snd_soc_card *card)
2944 struct snd_soc_dapm_widget *w;
2947 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2949 list_for_each_entry(w, &card->widgets, list)
2954 if (w->num_kcontrols) {
2955 w->kcontrols = kzalloc(w->num_kcontrols *
2956 sizeof(struct snd_kcontrol *),
2958 if (!w->kcontrols) {
2959 mutex_unlock(&card->dapm_mutex);
2965 case snd_soc_dapm_switch:
2966 case snd_soc_dapm_mixer:
2967 case snd_soc_dapm_mixer_named_ctl:
2970 case snd_soc_dapm_mux:
2971 case snd_soc_dapm_demux:
2974 case snd_soc_dapm_pga:
2975 case snd_soc_dapm_out_drv:
2978 case snd_soc_dapm_dai_link:
2979 dapm_new_dai_link(w);
2985 /* Read the initial power state from the device */
2987 soc_dapm_read(w->dapm, w->reg, &val);
2988 val = val >> w->shift;
2990 if (val == w->on_val)
2996 dapm_mark_dirty(w, "new widget");
2997 dapm_debugfs_add_widget(w);
3000 dapm_power_widgets(card, SND_SOC_DAPM_STREAM_NOP);
3001 mutex_unlock(&card->dapm_mutex);
3004 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
3007 * snd_soc_dapm_get_volsw - dapm mixer get callback
3008 * @kcontrol: mixer control
3009 * @ucontrol: control element information
3011 * Callback to get the value of a dapm mixer control.
3013 * Returns 0 for success.
3015 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
3016 struct snd_ctl_elem_value *ucontrol)
3018 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
3019 struct snd_soc_card *card = dapm->card;
3020 struct soc_mixer_control *mc =
3021 (struct soc_mixer_control *)kcontrol->private_value;
3023 unsigned int shift = mc->shift;
3025 unsigned int mask = (1 << fls(max)) - 1;
3026 unsigned int invert = mc->invert;
3030 if (snd_soc_volsw_is_stereo(mc))
3032 "ASoC: Control '%s' is stereo, which is not supported\n",
3035 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3036 if (dapm_kcontrol_is_powered(kcontrol) && reg != SND_SOC_NOPM) {
3037 ret = soc_dapm_read(dapm, reg, &val);
3038 val = (val >> shift) & mask;
3040 val = dapm_kcontrol_get_value(kcontrol);
3042 mutex_unlock(&card->dapm_mutex);
3048 ucontrol->value.integer.value[0] = max - val;
3050 ucontrol->value.integer.value[0] = val;
3054 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
3057 * snd_soc_dapm_put_volsw - dapm mixer set callback
3058 * @kcontrol: mixer control
3059 * @ucontrol: control element information
3061 * Callback to set the value of a dapm mixer control.
3063 * Returns 0 for success.
3065 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
3066 struct snd_ctl_elem_value *ucontrol)
3068 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
3069 struct snd_soc_card *card = dapm->card;
3070 struct soc_mixer_control *mc =
3071 (struct soc_mixer_control *)kcontrol->private_value;
3073 unsigned int shift = mc->shift;
3075 unsigned int mask = (1 << fls(max)) - 1;
3076 unsigned int invert = mc->invert;
3078 int connect, change, reg_change = 0;
3079 struct snd_soc_dapm_update update;
3082 if (snd_soc_volsw_is_stereo(mc))
3084 "ASoC: Control '%s' is stereo, which is not supported\n",
3087 val = (ucontrol->value.integer.value[0] & mask);
3093 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3095 change = dapm_kcontrol_set_value(kcontrol, val);
3097 if (reg != SND_SOC_NOPM) {
3098 mask = mask << shift;
3101 reg_change = soc_dapm_test_bits(dapm, reg, mask, val);
3104 if (change || reg_change) {
3106 update.kcontrol = kcontrol;
3110 card->update = &update;
3112 change |= reg_change;
3114 ret = soc_dapm_mixer_update_power(card, kcontrol, connect);
3116 card->update = NULL;
3119 mutex_unlock(&card->dapm_mutex);
3122 soc_dpcm_runtime_update(card);
3126 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
3129 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3130 * @kcontrol: mixer control
3131 * @ucontrol: control element information
3133 * Callback to get the value of a dapm enumerated double mixer control.
3135 * Returns 0 for success.
3137 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
3138 struct snd_ctl_elem_value *ucontrol)
3140 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
3141 struct snd_soc_card *card = dapm->card;
3142 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
3143 unsigned int reg_val, val;
3145 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3146 if (e->reg != SND_SOC_NOPM && dapm_kcontrol_is_powered(kcontrol)) {
3147 int ret = soc_dapm_read(dapm, e->reg, ®_val);
3149 mutex_unlock(&card->dapm_mutex);
3153 reg_val = dapm_kcontrol_get_value(kcontrol);
3155 mutex_unlock(&card->dapm_mutex);
3157 val = (reg_val >> e->shift_l) & e->mask;
3158 ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val);
3159 if (e->shift_l != e->shift_r) {
3160 val = (reg_val >> e->shift_r) & e->mask;
3161 val = snd_soc_enum_val_to_item(e, val);
3162 ucontrol->value.enumerated.item[1] = val;
3167 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
3170 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3171 * @kcontrol: mixer control
3172 * @ucontrol: control element information
3174 * Callback to set the value of a dapm enumerated double mixer control.
3176 * Returns 0 for success.
3178 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
3179 struct snd_ctl_elem_value *ucontrol)
3181 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
3182 struct snd_soc_card *card = dapm->card;
3183 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
3184 unsigned int *item = ucontrol->value.enumerated.item;
3185 unsigned int val, change, reg_change = 0;
3187 struct snd_soc_dapm_update update;
3190 if (item[0] >= e->items)
3193 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
3194 mask = e->mask << e->shift_l;
3195 if (e->shift_l != e->shift_r) {
3196 if (item[1] > e->items)
3198 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r;
3199 mask |= e->mask << e->shift_r;
3202 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3204 change = dapm_kcontrol_set_value(kcontrol, val);
3206 if (e->reg != SND_SOC_NOPM)
3207 reg_change = soc_dapm_test_bits(dapm, e->reg, mask, val);
3209 if (change || reg_change) {
3211 update.kcontrol = kcontrol;
3212 update.reg = e->reg;
3215 card->update = &update;
3217 change |= reg_change;
3219 ret = soc_dapm_mux_update_power(card, kcontrol, item[0], e);
3221 card->update = NULL;
3224 mutex_unlock(&card->dapm_mutex);
3227 soc_dpcm_runtime_update(card);
3231 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
3234 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3236 * @kcontrol: mixer control
3237 * @uinfo: control element information
3239 * Callback to provide information about a pin switch control.
3241 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
3242 struct snd_ctl_elem_info *uinfo)
3244 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3246 uinfo->value.integer.min = 0;
3247 uinfo->value.integer.max = 1;
3251 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
3254 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3256 * @kcontrol: mixer control
3259 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
3260 struct snd_ctl_elem_value *ucontrol)
3262 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
3263 const char *pin = (const char *)kcontrol->private_value;
3265 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3267 ucontrol->value.integer.value[0] =
3268 snd_soc_dapm_get_pin_status(&card->dapm, pin);
3270 mutex_unlock(&card->dapm_mutex);
3274 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
3277 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3279 * @kcontrol: mixer control
3282 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
3283 struct snd_ctl_elem_value *ucontrol)
3285 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
3286 const char *pin = (const char *)kcontrol->private_value;
3288 if (ucontrol->value.integer.value[0])
3289 snd_soc_dapm_enable_pin(&card->dapm, pin);
3291 snd_soc_dapm_disable_pin(&card->dapm, pin);
3293 snd_soc_dapm_sync(&card->dapm);
3296 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
3298 struct snd_soc_dapm_widget *
3299 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3300 const struct snd_soc_dapm_widget *widget)
3302 struct snd_soc_dapm_widget *w;
3304 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3305 w = snd_soc_dapm_new_control_unlocked(dapm, widget);
3306 /* Do not nag about probe deferrals */
3308 int ret = PTR_ERR(w);
3310 if (ret != -EPROBE_DEFER)
3312 "ASoC: Failed to create DAPM control %s (%d)\n",
3318 "ASoC: Failed to create DAPM control %s\n",
3322 mutex_unlock(&dapm->card->dapm_mutex);
3326 struct snd_soc_dapm_widget *
3327 snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
3328 const struct snd_soc_dapm_widget *widget)
3330 enum snd_soc_dapm_direction dir;
3331 struct snd_soc_dapm_widget *w;
3335 if ((w = dapm_cnew_widget(widget)) == NULL)
3339 case snd_soc_dapm_regulator_supply:
3340 w->regulator = devm_regulator_get(dapm->dev, w->name);
3341 if (IS_ERR(w->regulator)) {
3342 ret = PTR_ERR(w->regulator);
3343 if (ret == -EPROBE_DEFER)
3344 return ERR_PTR(ret);
3345 dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
3350 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) {
3351 ret = regulator_allow_bypass(w->regulator, true);
3353 dev_warn(w->dapm->dev,
3354 "ASoC: Failed to bypass %s: %d\n",
3358 case snd_soc_dapm_clock_supply:
3359 #ifdef CONFIG_CLKDEV_LOOKUP
3360 w->clk = devm_clk_get(dapm->dev, w->name);
3361 if (IS_ERR(w->clk)) {
3362 ret = PTR_ERR(w->clk);
3363 if (ret == -EPROBE_DEFER)
3364 return ERR_PTR(ret);
3365 dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
3377 prefix = soc_dapm_prefix(dapm);
3379 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name);
3381 w->name = kstrdup_const(widget->name, GFP_KERNEL);
3382 if (w->name == NULL) {
3388 case snd_soc_dapm_mic:
3389 w->is_ep = SND_SOC_DAPM_EP_SOURCE;
3390 w->power_check = dapm_generic_check_power;
3392 case snd_soc_dapm_input:
3393 if (!dapm->card->fully_routed)
3394 w->is_ep = SND_SOC_DAPM_EP_SOURCE;
3395 w->power_check = dapm_generic_check_power;
3397 case snd_soc_dapm_spk:
3398 case snd_soc_dapm_hp:
3399 w->is_ep = SND_SOC_DAPM_EP_SINK;
3400 w->power_check = dapm_generic_check_power;
3402 case snd_soc_dapm_output:
3403 if (!dapm->card->fully_routed)
3404 w->is_ep = SND_SOC_DAPM_EP_SINK;
3405 w->power_check = dapm_generic_check_power;
3407 case snd_soc_dapm_vmid:
3408 case snd_soc_dapm_siggen:
3409 w->is_ep = SND_SOC_DAPM_EP_SOURCE;
3410 w->power_check = dapm_always_on_check_power;
3412 case snd_soc_dapm_mux:
3413 case snd_soc_dapm_demux:
3414 case snd_soc_dapm_switch:
3415 case snd_soc_dapm_mixer:
3416 case snd_soc_dapm_mixer_named_ctl:
3417 case snd_soc_dapm_adc:
3418 case snd_soc_dapm_aif_out:
3419 case snd_soc_dapm_dac:
3420 case snd_soc_dapm_aif_in:
3421 case snd_soc_dapm_pga:
3422 case snd_soc_dapm_out_drv:
3423 case snd_soc_dapm_micbias:
3424 case snd_soc_dapm_line:
3425 case snd_soc_dapm_dai_link:
3426 case snd_soc_dapm_dai_out:
3427 case snd_soc_dapm_dai_in:
3428 w->power_check = dapm_generic_check_power;
3430 case snd_soc_dapm_supply:
3431 case snd_soc_dapm_regulator_supply:
3432 case snd_soc_dapm_clock_supply:
3433 case snd_soc_dapm_kcontrol:
3435 w->power_check = dapm_supply_check_power;
3438 w->power_check = dapm_always_on_check_power;
3443 INIT_LIST_HEAD(&w->list);
3444 INIT_LIST_HEAD(&w->dirty);
3445 list_add_tail(&w->list, &dapm->card->widgets);
3447 snd_soc_dapm_for_each_direction(dir) {
3448 INIT_LIST_HEAD(&w->edges[dir]);
3449 w->endpoints[dir] = -1;
3452 /* machine layer set ups unconnected pins and insertions */
3458 * snd_soc_dapm_new_controls - create new dapm controls
3459 * @dapm: DAPM context
3460 * @widget: widget array
3461 * @num: number of widgets
3463 * Creates new DAPM controls based upon the templates.
3465 * Returns 0 for success else error.
3467 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
3468 const struct snd_soc_dapm_widget *widget,
3471 struct snd_soc_dapm_widget *w;
3475 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
3476 for (i = 0; i < num; i++) {
3477 w = snd_soc_dapm_new_control_unlocked(dapm, widget);
3480 /* Do not nag about probe deferrals */
3481 if (ret == -EPROBE_DEFER)
3484 "ASoC: Failed to create DAPM control %s (%d)\n",
3490 "ASoC: Failed to create DAPM control %s\n",
3497 mutex_unlock(&dapm->card->dapm_mutex);
3500 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
3502 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3503 struct snd_kcontrol *kcontrol, int event)
3505 struct snd_soc_dapm_path *source_p, *sink_p;
3506 struct snd_soc_dai *source, *sink;
3507 const struct snd_soc_pcm_stream *config = w->params + w->params_select;
3508 struct snd_pcm_substream substream;
3509 struct snd_pcm_hw_params *params = NULL;
3513 if (WARN_ON(!config) ||
3514 WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) ||
3515 list_empty(&w->edges[SND_SOC_DAPM_DIR_IN])))
3518 /* We only support a single source and sink, pick the first */
3519 source_p = list_first_entry(&w->edges[SND_SOC_DAPM_DIR_OUT],
3520 struct snd_soc_dapm_path,
3521 list_node[SND_SOC_DAPM_DIR_OUT]);
3522 sink_p = list_first_entry(&w->edges[SND_SOC_DAPM_DIR_IN],
3523 struct snd_soc_dapm_path,
3524 list_node[SND_SOC_DAPM_DIR_IN]);
3526 source = source_p->source->priv;
3527 sink = sink_p->sink->priv;
3529 /* Be a little careful as we don't want to overflow the mask array */
3530 if (config->formats) {
3531 fmt = ffs(config->formats) - 1;
3533 dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n",
3538 /* Currently very limited parameter selection */
3539 params = kzalloc(sizeof(*params), GFP_KERNEL);
3544 snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
3546 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min =
3548 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max =
3551 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min
3552 = config->channels_min;
3553 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max
3554 = config->channels_max;
3556 memset(&substream, 0, sizeof(substream));
3559 case SND_SOC_DAPM_PRE_PMU:
3560 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3561 if (source->driver->ops && source->driver->ops->startup) {
3562 ret = source->driver->ops->startup(&substream, source);
3564 dev_err(source->dev,
3565 "ASoC: startup() failed: %d\n", ret);
3570 ret = soc_dai_hw_params(&substream, params, source);
3574 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3575 if (sink->driver->ops && sink->driver->ops->startup) {
3576 ret = sink->driver->ops->startup(&substream, sink);
3579 "ASoC: startup() failed: %d\n", ret);
3584 ret = soc_dai_hw_params(&substream, params, sink);
3589 case SND_SOC_DAPM_POST_PMU:
3590 ret = snd_soc_dai_digital_mute(sink, 0,
3591 SNDRV_PCM_STREAM_PLAYBACK);
3592 if (ret != 0 && ret != -ENOTSUPP)
3593 dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret);
3597 case SND_SOC_DAPM_PRE_PMD:
3598 ret = snd_soc_dai_digital_mute(sink, 1,
3599 SNDRV_PCM_STREAM_PLAYBACK);
3600 if (ret != 0 && ret != -ENOTSUPP)
3601 dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret);
3605 if (source->driver->ops && source->driver->ops->shutdown) {
3606 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3607 source->driver->ops->shutdown(&substream, source);
3611 if (sink->driver->ops && sink->driver->ops->shutdown) {
3612 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3613 sink->driver->ops->shutdown(&substream, sink);
3618 WARN(1, "Unknown event %d\n", event);
3627 static int snd_soc_dapm_dai_link_get(struct snd_kcontrol *kcontrol,
3628 struct snd_ctl_elem_value *ucontrol)
3630 struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
3632 ucontrol->value.enumerated.item[0] = w->params_select;
3637 static int snd_soc_dapm_dai_link_put(struct snd_kcontrol *kcontrol,
3638 struct snd_ctl_elem_value *ucontrol)
3640 struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
3642 /* Can't change the config when widget is already powered */
3646 if (ucontrol->value.enumerated.item[0] == w->params_select)
3649 if (ucontrol->value.enumerated.item[0] >= w->num_params)
3652 w->params_select = ucontrol->value.enumerated.item[0];
3657 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3658 const struct snd_soc_pcm_stream *params,
3659 unsigned int num_params,
3660 struct snd_soc_dapm_widget *source,
3661 struct snd_soc_dapm_widget *sink)
3663 struct snd_soc_dapm_widget template;
3664 struct snd_soc_dapm_widget *w;
3667 unsigned long private_value;
3668 const char **w_param_text;
3669 struct soc_enum w_param_enum[] = {
3670 SOC_ENUM_SINGLE(0, 0, 0, NULL),
3672 struct snd_kcontrol_new kcontrol_dai_link[] = {
3673 SOC_ENUM_EXT(NULL, w_param_enum[0],
3674 snd_soc_dapm_dai_link_get,
3675 snd_soc_dapm_dai_link_put),
3677 const struct snd_soc_pcm_stream *config = params;
3679 w_param_text = devm_kcalloc(card->dev, num_params,
3680 sizeof(char *), GFP_KERNEL);
3684 link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s",
3685 source->name, sink->name);
3688 goto outfree_w_param;
3691 for (count = 0 ; count < num_params; count++) {
3692 if (!config->stream_name) {
3693 dev_warn(card->dapm.dev,
3694 "ASoC: anonymous config %d for dai link %s\n",
3696 w_param_text[count] =
3697 devm_kasprintf(card->dev, GFP_KERNEL,
3698 "Anonymous Configuration %d",
3700 if (!w_param_text[count]) {
3702 goto outfree_link_name;
3705 w_param_text[count] = devm_kmemdup(card->dev,
3706 config->stream_name,
3707 strlen(config->stream_name) + 1,
3709 if (!w_param_text[count]) {
3711 goto outfree_link_name;
3716 w_param_enum[0].items = num_params;
3717 w_param_enum[0].texts = w_param_text;
3719 memset(&template, 0, sizeof(template));
3720 template.reg = SND_SOC_NOPM;
3721 template.id = snd_soc_dapm_dai_link;
3722 template.name = link_name;
3723 template.event = snd_soc_dai_link_event;
3724 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3725 SND_SOC_DAPM_PRE_PMD;
3726 template.num_kcontrols = 1;
3727 /* duplicate w_param_enum on heap so that memory persists */
3729 (unsigned long) devm_kmemdup(card->dev,
3730 (void *)(kcontrol_dai_link[0].private_value),
3731 sizeof(struct soc_enum), GFP_KERNEL);
3732 if (!private_value) {
3733 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n",
3736 goto outfree_link_name;
3738 kcontrol_dai_link[0].private_value = private_value;
3739 /* duplicate kcontrol_dai_link on heap so that memory persists */
3740 template.kcontrol_news =
3741 devm_kmemdup(card->dev, &kcontrol_dai_link[0],
3742 sizeof(struct snd_kcontrol_new),
3744 if (!template.kcontrol_news) {
3745 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n",
3748 goto outfree_private_value;
3751 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
3753 w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);
3756 /* Do not nag about probe deferrals */
3757 if (ret != -EPROBE_DEFER)
3759 "ASoC: Failed to create %s widget (%d)\n",
3761 goto outfree_kcontrol_news;
3764 dev_err(card->dev, "ASoC: Failed to create %s widget\n",
3767 goto outfree_kcontrol_news;
3771 w->num_params = num_params;
3773 ret = snd_soc_dapm_add_path(&card->dapm, source, w, NULL, NULL);
3776 return snd_soc_dapm_add_path(&card->dapm, w, sink, NULL, NULL);
3779 devm_kfree(card->dev, w);
3780 outfree_kcontrol_news:
3781 devm_kfree(card->dev, (void *)template.kcontrol_news);
3782 outfree_private_value:
3783 devm_kfree(card->dev, (void *)private_value);
3785 devm_kfree(card->dev, link_name);
3787 for (count = 0 ; count < num_params; count++)
3788 devm_kfree(card->dev, (void *)w_param_text[count]);
3789 devm_kfree(card->dev, w_param_text);
3794 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3795 struct snd_soc_dai *dai)
3797 struct snd_soc_dapm_widget template;
3798 struct snd_soc_dapm_widget *w;
3800 WARN_ON(dapm->dev != dai->dev);
3802 memset(&template, 0, sizeof(template));
3803 template.reg = SND_SOC_NOPM;
3805 if (dai->driver->playback.stream_name) {
3806 template.id = snd_soc_dapm_dai_in;
3807 template.name = dai->driver->playback.stream_name;
3808 template.sname = dai->driver->playback.stream_name;
3810 dev_dbg(dai->dev, "ASoC: adding %s widget\n",
3813 w = snd_soc_dapm_new_control_unlocked(dapm, &template);
3815 int ret = PTR_ERR(w);
3817 /* Do not nag about probe deferrals */
3818 if (ret != -EPROBE_DEFER)
3820 "ASoC: Failed to create %s widget (%d)\n",
3821 dai->driver->playback.stream_name, ret);
3825 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3826 dai->driver->playback.stream_name);
3831 dai->playback_widget = w;
3834 if (dai->driver->capture.stream_name) {
3835 template.id = snd_soc_dapm_dai_out;
3836 template.name = dai->driver->capture.stream_name;
3837 template.sname = dai->driver->capture.stream_name;
3839 dev_dbg(dai->dev, "ASoC: adding %s widget\n",
3842 w = snd_soc_dapm_new_control_unlocked(dapm, &template);
3844 int ret = PTR_ERR(w);
3846 /* Do not nag about probe deferrals */
3847 if (ret != -EPROBE_DEFER)
3849 "ASoC: Failed to create %s widget (%d)\n",
3850 dai->driver->playback.stream_name, ret);
3854 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3855 dai->driver->capture.stream_name);
3860 dai->capture_widget = w;
3866 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3868 struct snd_soc_dapm_widget *dai_w, *w;
3869 struct snd_soc_dapm_widget *src, *sink;
3870 struct snd_soc_dai *dai;
3872 /* For each DAI widget... */
3873 list_for_each_entry(dai_w, &card->widgets, list) {
3874 switch (dai_w->id) {
3875 case snd_soc_dapm_dai_in:
3876 case snd_soc_dapm_dai_out:
3882 /* let users know there is no DAI to link */
3884 dev_dbg(card->dev, "dai widget %s has no DAI\n",
3891 /* ...find all widgets with the same stream and link them */
3892 list_for_each_entry(w, &card->widgets, list) {
3893 if (w->dapm != dai_w->dapm)
3897 case snd_soc_dapm_dai_in:
3898 case snd_soc_dapm_dai_out:
3904 if (!w->sname || !strstr(w->sname, dai_w->sname))
3907 if (dai_w->id == snd_soc_dapm_dai_in) {
3914 dev_dbg(dai->dev, "%s -> %s\n", src->name, sink->name);
3915 snd_soc_dapm_add_path(w->dapm, src, sink, NULL, NULL);
3922 static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
3923 struct snd_soc_pcm_runtime *rtd)
3925 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3926 struct snd_soc_dapm_widget *sink, *source;
3929 for (i = 0; i < rtd->num_codecs; i++) {
3930 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
3932 if (!cpu_dai->component->codec)
3935 /* connect BE DAI playback if widgets are valid */
3936 if (codec_dai->playback_widget && cpu_dai->playback_widget) {
3937 source = cpu_dai->playback_widget;
3938 sink = codec_dai->playback_widget;
3939 dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n",
3940 cpu_dai->component->name, source->name,
3941 codec_dai->component->name, sink->name);
3943 snd_soc_dapm_add_path(&card->dapm, source, sink,
3947 /* connect BE DAI capture if widgets are valid */
3948 if (codec_dai->capture_widget && cpu_dai->capture_widget) {
3949 source = codec_dai->capture_widget;
3950 sink = cpu_dai->capture_widget;
3951 dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n",
3952 codec_dai->component->name, source->name,
3953 cpu_dai->component->name, sink->name);
3955 snd_soc_dapm_add_path(&card->dapm, source, sink,
3961 static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream,
3964 struct snd_soc_dapm_widget *w;
3967 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
3968 w = dai->playback_widget;
3970 w = dai->capture_widget;
3973 dapm_mark_dirty(w, "stream event");
3975 if (w->id == snd_soc_dapm_dai_in) {
3976 ep = SND_SOC_DAPM_EP_SOURCE;
3977 dapm_widget_invalidate_input_paths(w);
3979 ep = SND_SOC_DAPM_EP_SINK;
3980 dapm_widget_invalidate_output_paths(w);
3984 case SND_SOC_DAPM_STREAM_START:
3988 case SND_SOC_DAPM_STREAM_STOP:
3992 case SND_SOC_DAPM_STREAM_SUSPEND:
3993 case SND_SOC_DAPM_STREAM_RESUME:
3994 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3995 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
4001 void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card)
4003 struct snd_soc_pcm_runtime *rtd = card->rtd;
4006 /* for each BE DAI link... */
4007 for (i = 0; i < card->num_rtd; i++) {
4008 rtd = &card->rtd[i];
4011 * dynamic FE links have no fixed DAI mapping.
4012 * CODEC<->CODEC links have no direct connection.
4014 if (rtd->dai_link->dynamic || rtd->dai_link->params)
4017 dapm_connect_dai_link_widgets(card, rtd);
4021 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
4026 soc_dapm_dai_stream_event(rtd->cpu_dai, stream, event);
4027 for (i = 0; i < rtd->num_codecs; i++)
4028 soc_dapm_dai_stream_event(rtd->codec_dais[i], stream, event);
4030 dapm_power_widgets(rtd->card, event);
4034 * snd_soc_dapm_stream_event - send a stream event to the dapm core
4035 * @rtd: PCM runtime data
4036 * @stream: stream name
4037 * @event: stream event
4039 * Sends a stream event to the dapm core. The core then makes any
4040 * necessary widget power changes.
4042 * Returns 0 for success else error.
4044 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
4047 struct snd_soc_card *card = rtd->card;
4049 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
4050 soc_dapm_stream_event(rtd, stream, event);
4051 mutex_unlock(&card->dapm_mutex);
4055 * snd_soc_dapm_enable_pin_unlocked - enable pin.
4056 * @dapm: DAPM context
4059 * Enables input/output pin and its parents or children widgets iff there is
4060 * a valid audio route and active audio stream.
4062 * Requires external locking.
4064 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4065 * do any widget power switching.
4067 int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
4070 return snd_soc_dapm_set_pin(dapm, pin, 1);
4072 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked);
4075 * snd_soc_dapm_enable_pin - enable pin.
4076 * @dapm: DAPM context
4079 * Enables input/output pin and its parents or children widgets iff there is
4080 * a valid audio route and active audio stream.
4082 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4083 * do any widget power switching.
4085 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
4089 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
4091 ret = snd_soc_dapm_set_pin(dapm, pin, 1);
4093 mutex_unlock(&dapm->card->dapm_mutex);
4097 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
4100 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
4101 * @dapm: DAPM context
4104 * Enables input/output pin regardless of any other state. This is
4105 * intended for use with microphone bias supplies used in microphone
4108 * Requires external locking.
4110 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4111 * do any widget power switching.
4113 int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
4116 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
4119 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin);
4123 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin);
4124 if (!w->connected) {
4126 * w->force does not affect the number of input or output paths,
4127 * so we only have to recheck if w->connected is changed
4129 dapm_widget_invalidate_input_paths(w);
4130 dapm_widget_invalidate_output_paths(w);
4134 dapm_mark_dirty(w, "force enable");
4138 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked);
4141 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4142 * @dapm: DAPM context
4145 * Enables input/output pin regardless of any other state. This is
4146 * intended for use with microphone bias supplies used in microphone
4149 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4150 * do any widget power switching.
4152 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
4157 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
4159 ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
4161 mutex_unlock(&dapm->card->dapm_mutex);
4165 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
4168 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4169 * @dapm: DAPM context
4172 * Disables input/output pin and its parents or children widgets.
4174 * Requires external locking.
4176 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4177 * do any widget power switching.
4179 int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context *dapm,
4182 return snd_soc_dapm_set_pin(dapm, pin, 0);
4184 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked);
4187 * snd_soc_dapm_disable_pin - disable pin.
4188 * @dapm: DAPM context
4191 * Disables input/output pin and its parents or children widgets.
4193 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4194 * do any widget power switching.
4196 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
4201 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
4203 ret = snd_soc_dapm_set_pin(dapm, pin, 0);
4205 mutex_unlock(&dapm->card->dapm_mutex);
4209 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
4212 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4213 * @dapm: DAPM context
4216 * Marks the specified pin as being not connected, disabling it along
4217 * any parent or child widgets. At present this is identical to
4218 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4219 * additional things such as disabling controls which only affect
4220 * paths through the pin.
4222 * Requires external locking.
4224 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4225 * do any widget power switching.
4227 int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm,
4230 return snd_soc_dapm_set_pin(dapm, pin, 0);
4232 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked);
4235 * snd_soc_dapm_nc_pin - permanently disable pin.
4236 * @dapm: DAPM context
4239 * Marks the specified pin as being not connected, disabling it along
4240 * any parent or child widgets. At present this is identical to
4241 * snd_soc_dapm_disable_pin() but in future it will be extended to do
4242 * additional things such as disabling controls which only affect
4243 * paths through the pin.
4245 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
4246 * do any widget power switching.
4248 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
4252 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
4254 ret = snd_soc_dapm_set_pin(dapm, pin, 0);
4256 mutex_unlock(&dapm->card->dapm_mutex);
4260 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
4263 * snd_soc_dapm_get_pin_status - get audio pin status
4264 * @dapm: DAPM context
4265 * @pin: audio signal pin endpoint (or start point)
4267 * Get audio pin status - connected or disconnected.
4269 * Returns 1 for connected otherwise 0.
4271 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
4274 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
4277 return w->connected;
4281 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
4284 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4285 * @dapm: DAPM context
4286 * @pin: audio signal pin endpoint (or start point)
4288 * Mark the given endpoint or pin as ignoring suspend. When the
4289 * system is disabled a path between two endpoints flagged as ignoring
4290 * suspend will not be disabled. The path must already be enabled via
4291 * normal means at suspend time, it will not be turned on if it was not
4294 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
4297 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
4300 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin);
4304 w->ignore_suspend = 1;
4308 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
4311 * snd_soc_dapm_free - free dapm resources
4312 * @dapm: DAPM context
4314 * Free all dapm widgets and resources.
4316 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
4318 dapm_debugfs_cleanup(dapm);
4319 dapm_free_widgets(dapm);
4320 list_del(&dapm->list);
4322 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
4324 static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context *dapm)
4326 struct snd_soc_card *card = dapm->card;
4327 struct snd_soc_dapm_widget *w;
4328 LIST_HEAD(down_list);
4331 mutex_lock(&card->dapm_mutex);
4333 list_for_each_entry(w, &dapm->card->widgets, list) {
4334 if (w->dapm != dapm)
4337 dapm_seq_insert(w, &down_list, false);
4343 /* If there were no widgets to power down we're already in
4347 if (dapm->bias_level == SND_SOC_BIAS_ON)
4348 snd_soc_dapm_set_bias_level(dapm,
4349 SND_SOC_BIAS_PREPARE);
4350 dapm_seq_run(card, &down_list, 0, false);
4351 if (dapm->bias_level == SND_SOC_BIAS_PREPARE)
4352 snd_soc_dapm_set_bias_level(dapm,
4353 SND_SOC_BIAS_STANDBY);
4356 mutex_unlock(&card->dapm_mutex);
4360 * snd_soc_dapm_shutdown - callback for system shutdown
4362 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
4364 struct snd_soc_dapm_context *dapm;
4366 list_for_each_entry(dapm, &card->dapm_list, list) {
4367 if (dapm != &card->dapm) {
4368 soc_dapm_shutdown_dapm(dapm);
4369 if (dapm->bias_level == SND_SOC_BIAS_STANDBY)
4370 snd_soc_dapm_set_bias_level(dapm,
4375 soc_dapm_shutdown_dapm(&card->dapm);
4376 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY)
4377 snd_soc_dapm_set_bias_level(&card->dapm,
4381 /* Module information */
4382 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4383 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
4384 MODULE_LICENSE("GPL");