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/slab.h>
39 #include <sound/core.h>
40 #include <sound/pcm.h>
41 #include <sound/pcm_params.h>
42 #include <sound/soc.h>
43 #include <sound/initval.h>
45 #include <trace/events/asoc.h>
47 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
49 /* dapm power sequences - make this per codec in the future */
50 static int dapm_up_seq[] = {
51 [snd_soc_dapm_pre] = 0,
52 [snd_soc_dapm_supply] = 1,
53 [snd_soc_dapm_regulator_supply] = 1,
54 [snd_soc_dapm_micbias] = 2,
55 [snd_soc_dapm_dai_link] = 2,
56 [snd_soc_dapm_dai] = 3,
57 [snd_soc_dapm_aif_in] = 3,
58 [snd_soc_dapm_aif_out] = 3,
59 [snd_soc_dapm_mic] = 4,
60 [snd_soc_dapm_mux] = 5,
61 [snd_soc_dapm_virt_mux] = 5,
62 [snd_soc_dapm_value_mux] = 5,
63 [snd_soc_dapm_dac] = 6,
64 [snd_soc_dapm_mixer] = 7,
65 [snd_soc_dapm_mixer_named_ctl] = 7,
66 [snd_soc_dapm_pga] = 8,
67 [snd_soc_dapm_adc] = 9,
68 [snd_soc_dapm_out_drv] = 10,
69 [snd_soc_dapm_hp] = 10,
70 [snd_soc_dapm_spk] = 10,
71 [snd_soc_dapm_post] = 11,
74 static int dapm_down_seq[] = {
75 [snd_soc_dapm_pre] = 0,
76 [snd_soc_dapm_adc] = 1,
77 [snd_soc_dapm_hp] = 2,
78 [snd_soc_dapm_spk] = 2,
79 [snd_soc_dapm_out_drv] = 2,
80 [snd_soc_dapm_pga] = 4,
81 [snd_soc_dapm_mixer_named_ctl] = 5,
82 [snd_soc_dapm_mixer] = 5,
83 [snd_soc_dapm_dac] = 6,
84 [snd_soc_dapm_mic] = 7,
85 [snd_soc_dapm_micbias] = 8,
86 [snd_soc_dapm_mux] = 9,
87 [snd_soc_dapm_virt_mux] = 9,
88 [snd_soc_dapm_value_mux] = 9,
89 [snd_soc_dapm_aif_in] = 10,
90 [snd_soc_dapm_aif_out] = 10,
91 [snd_soc_dapm_dai] = 10,
92 [snd_soc_dapm_dai_link] = 11,
93 [snd_soc_dapm_regulator_supply] = 12,
94 [snd_soc_dapm_supply] = 12,
95 [snd_soc_dapm_post] = 13,
98 static void pop_wait(u32 pop_time)
101 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
104 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
112 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
117 vsnprintf(buf, PAGE_SIZE, fmt, args);
118 dev_info(dev, "%s", buf);
124 static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
126 return !list_empty(&w->dirty);
129 void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
131 if (!dapm_dirty_widget(w)) {
132 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
134 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
137 EXPORT_SYMBOL_GPL(dapm_mark_dirty);
139 /* create a new dapm widget */
140 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
141 const struct snd_soc_dapm_widget *_widget)
143 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
146 /* get snd_card from DAPM context */
147 static inline struct snd_card *dapm_get_snd_card(
148 struct snd_soc_dapm_context *dapm)
151 return dapm->codec->card->snd_card;
152 else if (dapm->platform)
153 return dapm->platform->card->snd_card;
161 /* get soc_card from DAPM context */
162 static inline struct snd_soc_card *dapm_get_soc_card(
163 struct snd_soc_dapm_context *dapm)
166 return dapm->codec->card;
167 else if (dapm->platform)
168 return dapm->platform->card;
176 static void dapm_reset(struct snd_soc_card *card)
178 struct snd_soc_dapm_widget *w;
180 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
182 list_for_each_entry(w, &card->widgets, list) {
183 w->power_checked = false;
189 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
192 return snd_soc_read(w->codec, reg);
193 else if (w->platform)
194 return snd_soc_platform_read(w->platform, reg);
196 dev_err(w->dapm->dev, "no valid widget read method\n");
200 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
203 return snd_soc_write(w->codec, reg, val);
204 else if (w->platform)
205 return snd_soc_platform_write(w->platform, reg, val);
207 dev_err(w->dapm->dev, "no valid widget write method\n");
211 static inline void soc_widget_lock(struct snd_soc_dapm_widget *w)
213 if (w->codec && !w->codec->using_regmap)
214 mutex_lock(&w->codec->mutex);
215 else if (w->platform)
216 mutex_lock(&w->platform->mutex);
219 static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w)
221 if (w->codec && !w->codec->using_regmap)
222 mutex_unlock(&w->codec->mutex);
223 else if (w->platform)
224 mutex_unlock(&w->platform->mutex);
227 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
228 unsigned short reg, unsigned int mask, unsigned int value)
231 unsigned int old, new;
234 if (w->codec && w->codec->using_regmap) {
235 ret = regmap_update_bits_check(w->codec->control_data,
236 reg, mask, value, &change);
241 ret = soc_widget_read(w, reg);
243 soc_widget_unlock(w);
248 new = (old & ~mask) | (value & mask);
251 ret = soc_widget_write(w, reg, new);
253 soc_widget_unlock(w);
257 soc_widget_unlock(w);
264 * snd_soc_dapm_set_bias_level - set the bias level for the system
265 * @dapm: DAPM context
266 * @level: level to configure
268 * Configure the bias (power) levels for the SoC audio device.
270 * Returns 0 for success else error.
272 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
273 enum snd_soc_bias_level level)
275 struct snd_soc_card *card = dapm->card;
278 trace_snd_soc_bias_level_start(card, level);
280 if (card && card->set_bias_level)
281 ret = card->set_bias_level(card, dapm, level);
286 if (dapm->codec->driver->set_bias_level)
287 ret = dapm->codec->driver->set_bias_level(dapm->codec,
290 dapm->bias_level = level;
295 if (card && card->set_bias_level_post)
296 ret = card->set_bias_level_post(card, dapm, level);
298 trace_snd_soc_bias_level_done(card, level);
303 /* set up initial codec paths */
304 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
305 struct snd_soc_dapm_path *p, int i)
308 case snd_soc_dapm_switch:
309 case snd_soc_dapm_mixer:
310 case snd_soc_dapm_mixer_named_ctl: {
312 struct soc_mixer_control *mc = (struct soc_mixer_control *)
313 w->kcontrol_news[i].private_value;
314 unsigned int reg = mc->reg;
315 unsigned int shift = mc->shift;
317 unsigned int mask = (1 << fls(max)) - 1;
318 unsigned int invert = mc->invert;
320 val = soc_widget_read(w, reg);
321 val = (val >> shift) & mask;
323 if ((invert && !val) || (!invert && val))
329 case snd_soc_dapm_mux: {
330 struct soc_enum *e = (struct soc_enum *)
331 w->kcontrol_news[i].private_value;
332 int val, item, bitmask;
334 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
336 val = soc_widget_read(w, e->reg);
337 item = (val >> e->shift_l) & (bitmask - 1);
340 for (i = 0; i < e->max; i++) {
341 if (!(strcmp(p->name, e->texts[i])) && item == i)
346 case snd_soc_dapm_virt_mux: {
347 struct soc_enum *e = (struct soc_enum *)
348 w->kcontrol_news[i].private_value;
351 /* since a virtual mux has no backing registers to
352 * decide which path to connect, it will try to match
353 * with the first enumeration. This is to ensure
354 * that the default mux choice (the first) will be
355 * correctly powered up during initialization.
357 if (!strcmp(p->name, e->texts[0]))
361 case snd_soc_dapm_value_mux: {
362 struct soc_enum *e = (struct soc_enum *)
363 w->kcontrol_news[i].private_value;
366 val = soc_widget_read(w, e->reg);
367 val = (val >> e->shift_l) & e->mask;
368 for (item = 0; item < e->max; item++) {
369 if (val == e->values[item])
374 for (i = 0; i < e->max; i++) {
375 if (!(strcmp(p->name, e->texts[i])) && item == i)
380 /* does not affect routing - always connected */
381 case snd_soc_dapm_pga:
382 case snd_soc_dapm_out_drv:
383 case snd_soc_dapm_output:
384 case snd_soc_dapm_adc:
385 case snd_soc_dapm_input:
386 case snd_soc_dapm_siggen:
387 case snd_soc_dapm_dac:
388 case snd_soc_dapm_micbias:
389 case snd_soc_dapm_vmid:
390 case snd_soc_dapm_supply:
391 case snd_soc_dapm_regulator_supply:
392 case snd_soc_dapm_aif_in:
393 case snd_soc_dapm_aif_out:
394 case snd_soc_dapm_dai:
395 case snd_soc_dapm_hp:
396 case snd_soc_dapm_mic:
397 case snd_soc_dapm_spk:
398 case snd_soc_dapm_line:
399 case snd_soc_dapm_dai_link:
402 /* does affect routing - dynamically connected */
403 case snd_soc_dapm_pre:
404 case snd_soc_dapm_post:
410 /* connect mux widget to its interconnecting audio paths */
411 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
412 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
413 struct snd_soc_dapm_path *path, const char *control_name,
414 const struct snd_kcontrol_new *kcontrol)
416 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
419 for (i = 0; i < e->max; i++) {
420 if (!(strcmp(control_name, e->texts[i]))) {
421 list_add(&path->list, &dapm->card->paths);
422 list_add(&path->list_sink, &dest->sources);
423 list_add(&path->list_source, &src->sinks);
424 path->name = (char*)e->texts[i];
425 dapm_set_path_status(dest, path, 0);
433 /* connect mixer widget to its interconnecting audio paths */
434 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
435 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
436 struct snd_soc_dapm_path *path, const char *control_name)
440 /* search for mixer kcontrol */
441 for (i = 0; i < dest->num_kcontrols; i++) {
442 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
443 list_add(&path->list, &dapm->card->paths);
444 list_add(&path->list_sink, &dest->sources);
445 list_add(&path->list_source, &src->sinks);
446 path->name = dest->kcontrol_news[i].name;
447 dapm_set_path_status(dest, path, i);
454 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
455 struct snd_soc_dapm_widget *kcontrolw,
456 const struct snd_kcontrol_new *kcontrol_new,
457 struct snd_kcontrol **kcontrol)
459 struct snd_soc_dapm_widget *w;
464 list_for_each_entry(w, &dapm->card->widgets, list) {
465 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
467 for (i = 0; i < w->num_kcontrols; i++) {
468 if (&w->kcontrol_news[i] == kcontrol_new) {
470 *kcontrol = w->kcontrols[i];
479 /* create new dapm mixer control */
480 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
482 struct snd_soc_dapm_context *dapm = w->dapm;
484 size_t name_len, prefix_len;
485 struct snd_soc_dapm_path *path;
486 struct snd_card *card = dapm->card->snd_card;
488 struct snd_soc_dapm_widget_list *wlist;
492 prefix = dapm->codec->name_prefix;
497 prefix_len = strlen(prefix) + 1;
502 for (i = 0; i < w->num_kcontrols; i++) {
505 list_for_each_entry(path, &w->sources, list_sink) {
507 /* mixer/mux paths name must match control name */
508 if (path->name != (char *)w->kcontrol_news[i].name)
511 if (w->kcontrols[i]) {
512 path->kcontrol = w->kcontrols[i];
516 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
517 sizeof(struct snd_soc_dapm_widget *),
518 wlist = kzalloc(wlistsize, GFP_KERNEL);
521 "asoc: can't allocate widget list for %s\n",
525 wlist->num_widgets = 1;
526 wlist->widgets[0] = w;
528 /* add dapm control with long name.
529 * for dapm_mixer this is the concatenation of the
530 * mixer and kcontrol name.
531 * for dapm_mixer_named_ctl this is simply the
534 name_len = strlen(w->kcontrol_news[i].name) + 1;
535 if (w->id != snd_soc_dapm_mixer_named_ctl)
536 name_len += 1 + strlen(w->name);
538 path->long_name = kmalloc(name_len, GFP_KERNEL);
540 if (path->long_name == NULL) {
547 /* The control will get a prefix from
548 * the control creation process but
549 * we're also using the same prefix
550 * for widgets so cut the prefix off
551 * the front of the widget name.
553 snprintf((char *)path->long_name, name_len,
554 "%s %s", w->name + prefix_len,
555 w->kcontrol_news[i].name);
557 case snd_soc_dapm_mixer_named_ctl:
558 snprintf((char *)path->long_name, name_len,
559 "%s", w->kcontrol_news[i].name);
563 ((char *)path->long_name)[name_len - 1] = '\0';
565 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
566 wlist, path->long_name,
568 ret = snd_ctl_add(card, path->kcontrol);
571 "asoc: failed to add dapm kcontrol %s: %d\n",
572 path->long_name, ret);
574 kfree(path->long_name);
575 path->long_name = NULL;
578 w->kcontrols[i] = path->kcontrol;
584 /* create new dapm mux control */
585 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
587 struct snd_soc_dapm_context *dapm = w->dapm;
588 struct snd_soc_dapm_path *path = NULL;
589 struct snd_kcontrol *kcontrol;
590 struct snd_card *card = dapm->card->snd_card;
594 struct snd_soc_dapm_widget_list *wlist;
595 int shared, wlistentries;
599 if (w->num_kcontrols != 1) {
601 "asoc: mux %s has incorrect number of controls\n",
606 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
609 wlist = kcontrol->private_data;
610 wlistentries = wlist->num_widgets + 1;
615 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
616 wlistentries * sizeof(struct snd_soc_dapm_widget *),
617 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
620 "asoc: can't allocate widget list for %s\n", w->name);
623 wlist->num_widgets = wlistentries;
624 wlist->widgets[wlistentries - 1] = w;
628 prefix = dapm->codec->name_prefix;
633 name = w->kcontrol_news[0].name;
638 prefix_len = strlen(prefix) + 1;
644 * The control will get a prefix from the control creation
645 * process but we're also using the same prefix for widgets so
646 * cut the prefix off the front of the widget name.
648 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
649 name + prefix_len, prefix);
650 ret = snd_ctl_add(card, kcontrol);
652 dev_err(dapm->dev, "failed to add kcontrol %s: %d\n",
659 kcontrol->private_data = wlist;
661 w->kcontrols[0] = kcontrol;
663 list_for_each_entry(path, &w->sources, list_sink)
664 path->kcontrol = kcontrol;
669 /* create new dapm volume control */
670 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
672 if (w->num_kcontrols)
673 dev_err(w->dapm->dev,
674 "asoc: PGA controls not supported: '%s'\n", w->name);
679 /* reset 'walked' bit for each dapm path */
680 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
682 struct snd_soc_dapm_path *p;
684 list_for_each_entry(p, &dapm->card->paths, list)
688 /* We implement power down on suspend by checking the power state of
689 * the ALSA card - when we are suspending the ALSA state for the card
692 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
694 int level = snd_power_get_state(widget->dapm->card->snd_card);
697 case SNDRV_CTL_POWER_D3hot:
698 case SNDRV_CTL_POWER_D3cold:
699 if (widget->ignore_suspend)
700 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
702 return widget->ignore_suspend;
709 * Recursively check for a completed path to an active or physically connected
710 * output widget. Returns number of complete paths.
712 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
714 struct snd_soc_dapm_path *path;
717 if (widget->outputs >= 0)
718 return widget->outputs;
720 DAPM_UPDATE_STAT(widget, path_checks);
722 switch (widget->id) {
723 case snd_soc_dapm_supply:
724 case snd_soc_dapm_regulator_supply:
730 switch (widget->id) {
731 case snd_soc_dapm_adc:
732 case snd_soc_dapm_aif_out:
733 case snd_soc_dapm_dai:
734 if (widget->active) {
735 widget->outputs = snd_soc_dapm_suspend_check(widget);
736 return widget->outputs;
742 if (widget->connected) {
743 /* connected pin ? */
744 if (widget->id == snd_soc_dapm_output && !widget->ext) {
745 widget->outputs = snd_soc_dapm_suspend_check(widget);
746 return widget->outputs;
749 /* connected jack or spk ? */
750 if (widget->id == snd_soc_dapm_hp ||
751 widget->id == snd_soc_dapm_spk ||
752 (widget->id == snd_soc_dapm_line &&
753 !list_empty(&widget->sources))) {
754 widget->outputs = snd_soc_dapm_suspend_check(widget);
755 return widget->outputs;
759 list_for_each_entry(path, &widget->sinks, list_source) {
760 DAPM_UPDATE_STAT(widget, neighbour_checks);
768 if (path->sink && path->connect) {
770 con += is_connected_output_ep(path->sink);
774 widget->outputs = con;
780 * Recursively check for a completed path to an active or physically connected
781 * input widget. Returns number of complete paths.
783 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
785 struct snd_soc_dapm_path *path;
788 if (widget->inputs >= 0)
789 return widget->inputs;
791 DAPM_UPDATE_STAT(widget, path_checks);
793 switch (widget->id) {
794 case snd_soc_dapm_supply:
795 case snd_soc_dapm_regulator_supply:
801 /* active stream ? */
802 switch (widget->id) {
803 case snd_soc_dapm_dac:
804 case snd_soc_dapm_aif_in:
805 case snd_soc_dapm_dai:
806 if (widget->active) {
807 widget->inputs = snd_soc_dapm_suspend_check(widget);
808 return widget->inputs;
814 if (widget->connected) {
815 /* connected pin ? */
816 if (widget->id == snd_soc_dapm_input && !widget->ext) {
817 widget->inputs = snd_soc_dapm_suspend_check(widget);
818 return widget->inputs;
821 /* connected VMID/Bias for lower pops */
822 if (widget->id == snd_soc_dapm_vmid) {
823 widget->inputs = snd_soc_dapm_suspend_check(widget);
824 return widget->inputs;
827 /* connected jack ? */
828 if (widget->id == snd_soc_dapm_mic ||
829 (widget->id == snd_soc_dapm_line &&
830 !list_empty(&widget->sinks))) {
831 widget->inputs = snd_soc_dapm_suspend_check(widget);
832 return widget->inputs;
835 /* signal generator */
836 if (widget->id == snd_soc_dapm_siggen) {
837 widget->inputs = snd_soc_dapm_suspend_check(widget);
838 return widget->inputs;
842 list_for_each_entry(path, &widget->sources, list_sink) {
843 DAPM_UPDATE_STAT(widget, neighbour_checks);
851 if (path->source && path->connect) {
853 con += is_connected_input_ep(path->source);
857 widget->inputs = con;
863 * Handler for generic register modifier widget.
865 int dapm_reg_event(struct snd_soc_dapm_widget *w,
866 struct snd_kcontrol *kcontrol, int event)
870 if (SND_SOC_DAPM_EVENT_ON(event))
875 soc_widget_update_bits_locked(w, -(w->reg + 1),
876 w->mask << w->shift, val << w->shift);
880 EXPORT_SYMBOL_GPL(dapm_reg_event);
883 * Handler for regulator supply widget.
885 int dapm_regulator_event(struct snd_soc_dapm_widget *w,
886 struct snd_kcontrol *kcontrol, int event)
888 if (SND_SOC_DAPM_EVENT_ON(event))
889 return regulator_enable(w->regulator);
891 return regulator_disable_deferred(w->regulator, w->shift);
893 EXPORT_SYMBOL_GPL(dapm_regulator_event);
895 static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
897 if (w->power_checked)
903 w->new_power = w->power_check(w);
905 w->power_checked = true;
910 /* Generic check to see if a widget should be powered.
912 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
916 DAPM_UPDATE_STAT(w, power_checks);
918 in = is_connected_input_ep(w);
919 dapm_clear_walk(w->dapm);
920 out = is_connected_output_ep(w);
921 dapm_clear_walk(w->dapm);
922 return out != 0 && in != 0;
925 static int dapm_dai_check_power(struct snd_soc_dapm_widget *w)
927 DAPM_UPDATE_STAT(w, power_checks);
932 return dapm_generic_check_power(w);
935 /* Check to see if an ADC has power */
936 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
940 DAPM_UPDATE_STAT(w, power_checks);
943 in = is_connected_input_ep(w);
944 dapm_clear_walk(w->dapm);
947 return dapm_generic_check_power(w);
951 /* Check to see if a DAC has power */
952 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
956 DAPM_UPDATE_STAT(w, power_checks);
959 out = is_connected_output_ep(w);
960 dapm_clear_walk(w->dapm);
963 return dapm_generic_check_power(w);
967 /* Check to see if a power supply is needed */
968 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
970 struct snd_soc_dapm_path *path;
972 DAPM_UPDATE_STAT(w, power_checks);
974 /* Check if one of our outputs is connected */
975 list_for_each_entry(path, &w->sinks, list_source) {
976 DAPM_UPDATE_STAT(w, neighbour_checks);
981 if (path->connected &&
982 !path->connected(path->source, path->sink))
988 if (dapm_widget_power_check(path->sink))
992 dapm_clear_walk(w->dapm);
997 static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
1002 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
1003 struct snd_soc_dapm_widget *b,
1011 sort = dapm_down_seq;
1013 if (sort[a->id] != sort[b->id])
1014 return sort[a->id] - sort[b->id];
1015 if (a->subseq != b->subseq) {
1017 return a->subseq - b->subseq;
1019 return b->subseq - a->subseq;
1021 if (a->reg != b->reg)
1022 return a->reg - b->reg;
1023 if (a->dapm != b->dapm)
1024 return (unsigned long)a->dapm - (unsigned long)b->dapm;
1029 /* Insert a widget in order into a DAPM power sequence. */
1030 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
1031 struct list_head *list,
1034 struct snd_soc_dapm_widget *w;
1036 list_for_each_entry(w, list, power_list)
1037 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
1038 list_add_tail(&new_widget->power_list, &w->power_list);
1042 list_add_tail(&new_widget->power_list, list);
1045 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
1046 struct snd_soc_dapm_widget *w, int event)
1048 struct snd_soc_card *card = dapm->card;
1049 const char *ev_name;
1053 case SND_SOC_DAPM_PRE_PMU:
1054 ev_name = "PRE_PMU";
1057 case SND_SOC_DAPM_POST_PMU:
1058 ev_name = "POST_PMU";
1061 case SND_SOC_DAPM_PRE_PMD:
1062 ev_name = "PRE_PMD";
1065 case SND_SOC_DAPM_POST_PMD:
1066 ev_name = "POST_PMD";
1074 if (w->power != power)
1077 if (w->event && (w->event_flags & event)) {
1078 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
1080 trace_snd_soc_dapm_widget_event_start(w, event);
1081 ret = w->event(w, NULL, event);
1082 trace_snd_soc_dapm_widget_event_done(w, event);
1084 pr_err("%s: %s event failed: %d\n",
1085 ev_name, w->name, ret);
1089 /* Apply the coalesced changes from a DAPM sequence */
1090 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
1091 struct list_head *pending)
1093 struct snd_soc_card *card = dapm->card;
1094 struct snd_soc_dapm_widget *w;
1096 unsigned int value = 0;
1097 unsigned int mask = 0;
1098 unsigned int cur_mask;
1100 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
1103 list_for_each_entry(w, pending, power_list) {
1104 cur_mask = 1 << w->shift;
1105 BUG_ON(reg != w->reg);
1116 pop_dbg(dapm->dev, card->pop_time,
1117 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1118 w->name, reg, value, mask);
1120 /* Check for events */
1121 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
1122 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
1126 /* Any widget will do, they should all be updating the
1129 w = list_first_entry(pending, struct snd_soc_dapm_widget,
1132 pop_dbg(dapm->dev, card->pop_time,
1133 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1134 value, mask, reg, card->pop_time);
1135 pop_wait(card->pop_time);
1136 soc_widget_update_bits_locked(w, reg, mask, value);
1139 list_for_each_entry(w, pending, power_list) {
1140 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
1141 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
1145 /* Apply a DAPM power sequence.
1147 * We walk over a pre-sorted list of widgets to apply power to. In
1148 * order to minimise the number of writes to the device required
1149 * multiple widgets will be updated in a single write where possible.
1150 * Currently anything that requires more than a single write is not
1153 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1154 struct list_head *list, int event, bool power_up)
1156 struct snd_soc_dapm_widget *w, *n;
1159 int cur_subseq = -1;
1160 int cur_reg = SND_SOC_NOPM;
1161 struct snd_soc_dapm_context *cur_dapm = NULL;
1168 sort = dapm_down_seq;
1170 list_for_each_entry_safe(w, n, list, power_list) {
1173 /* Do we need to apply any queued changes? */
1174 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1175 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1176 if (!list_empty(&pending))
1177 dapm_seq_run_coalesced(cur_dapm, &pending);
1179 if (cur_dapm && cur_dapm->seq_notifier) {
1180 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1181 if (sort[i] == cur_sort)
1182 cur_dapm->seq_notifier(cur_dapm,
1187 INIT_LIST_HEAD(&pending);
1189 cur_subseq = INT_MIN;
1190 cur_reg = SND_SOC_NOPM;
1195 case snd_soc_dapm_pre:
1197 list_for_each_entry_safe_continue(w, n, list,
1200 if (event == SND_SOC_DAPM_STREAM_START)
1202 NULL, SND_SOC_DAPM_PRE_PMU);
1203 else if (event == SND_SOC_DAPM_STREAM_STOP)
1205 NULL, SND_SOC_DAPM_PRE_PMD);
1208 case snd_soc_dapm_post:
1210 list_for_each_entry_safe_continue(w, n, list,
1213 if (event == SND_SOC_DAPM_STREAM_START)
1215 NULL, SND_SOC_DAPM_POST_PMU);
1216 else if (event == SND_SOC_DAPM_STREAM_STOP)
1218 NULL, SND_SOC_DAPM_POST_PMD);
1222 /* Queue it up for application */
1223 cur_sort = sort[w->id];
1224 cur_subseq = w->subseq;
1227 list_move(&w->power_list, &pending);
1232 dev_err(w->dapm->dev,
1233 "Failed to apply widget power: %d\n", ret);
1236 if (!list_empty(&pending))
1237 dapm_seq_run_coalesced(cur_dapm, &pending);
1239 if (cur_dapm && cur_dapm->seq_notifier) {
1240 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1241 if (sort[i] == cur_sort)
1242 cur_dapm->seq_notifier(cur_dapm,
1247 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1249 struct snd_soc_dapm_update *update = dapm->update;
1250 struct snd_soc_dapm_widget *w;
1259 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1260 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1262 pr_err("%s DAPM pre-event failed: %d\n",
1266 ret = soc_widget_update_bits_locked(w, update->reg, update->mask,
1269 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1272 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1273 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1275 pr_err("%s DAPM post-event failed: %d\n",
1280 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1281 * they're changing state.
1283 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1285 struct snd_soc_dapm_context *d = data;
1288 /* If we're off and we're not supposed to be go into STANDBY */
1289 if (d->bias_level == SND_SOC_BIAS_OFF &&
1290 d->target_bias_level != SND_SOC_BIAS_OFF) {
1292 pm_runtime_get_sync(d->dev);
1294 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1297 "Failed to turn on bias: %d\n", ret);
1300 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1301 if (d->bias_level != d->target_bias_level) {
1302 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1305 "Failed to prepare bias: %d\n", ret);
1309 /* Async callback run prior to DAPM sequences - brings to their final
1312 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1314 struct snd_soc_dapm_context *d = data;
1317 /* If we just powered the last thing off drop to standby bias */
1318 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1319 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1320 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1321 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1323 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1327 /* If we're in standby and can support bias off then do that */
1328 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1329 d->target_bias_level == SND_SOC_BIAS_OFF) {
1330 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1332 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1335 pm_runtime_put(d->dev);
1338 /* If we just powered up then move to active bias */
1339 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1340 d->target_bias_level == SND_SOC_BIAS_ON) {
1341 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1343 dev_err(d->dev, "Failed to apply active bias: %d\n",
1348 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
1349 bool power, bool connect)
1351 /* If a connection is being made or broken then that update
1352 * will have marked the peer dirty, otherwise the widgets are
1353 * not connected and this update has no impact. */
1357 /* If the peer is already in the state we're moving to then we
1358 * won't have an impact on it. */
1359 if (power != peer->power)
1360 dapm_mark_dirty(peer, "peer state change");
1363 static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1364 struct list_head *up_list,
1365 struct list_head *down_list)
1367 struct snd_soc_dapm_path *path;
1369 if (w->power == power)
1372 trace_snd_soc_dapm_widget_power(w, power);
1374 /* If we changed our power state perhaps our neigbours changed
1377 list_for_each_entry(path, &w->sources, list_sink) {
1379 dapm_widget_set_peer_power(path->source, power,
1384 case snd_soc_dapm_supply:
1385 case snd_soc_dapm_regulator_supply:
1386 /* Supplies can't affect their outputs, only their inputs */
1389 list_for_each_entry(path, &w->sinks, list_source) {
1391 dapm_widget_set_peer_power(path->sink, power,
1399 dapm_seq_insert(w, up_list, true);
1401 dapm_seq_insert(w, down_list, false);
1406 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1407 struct list_head *up_list,
1408 struct list_head *down_list)
1413 case snd_soc_dapm_pre:
1414 dapm_seq_insert(w, down_list, false);
1416 case snd_soc_dapm_post:
1417 dapm_seq_insert(w, up_list, true);
1421 power = dapm_widget_power_check(w);
1423 dapm_widget_set_power(w, power, up_list, down_list);
1429 * Scan each dapm widget for complete audio path.
1430 * A complete path is a route that has valid endpoints i.e.:-
1432 * o DAC to output pin.
1433 * o Input Pin to ADC.
1434 * o Input pin to Output pin (bypass, sidetone)
1435 * o DAC to ADC (loopback).
1437 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1439 struct snd_soc_card *card = dapm->card;
1440 struct snd_soc_dapm_widget *w;
1441 struct snd_soc_dapm_context *d;
1443 LIST_HEAD(down_list);
1444 LIST_HEAD(async_domain);
1445 enum snd_soc_bias_level bias;
1447 trace_snd_soc_dapm_start(card);
1449 list_for_each_entry(d, &card->dapm_list, list) {
1450 if (d->idle_bias_off)
1451 d->target_bias_level = SND_SOC_BIAS_OFF;
1453 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1458 /* Check which widgets we need to power and store them in
1459 * lists indicating if they should be powered up or down. We
1460 * only check widgets that have been flagged as dirty but note
1461 * that new widgets may be added to the dirty list while we
1464 list_for_each_entry(w, &card->dapm_dirty, dirty) {
1465 dapm_power_one_widget(w, &up_list, &down_list);
1468 list_for_each_entry(w, &card->widgets, list) {
1469 list_del_init(&w->dirty);
1474 /* Supplies and micbiases only bring the
1475 * context up to STANDBY as unless something
1476 * else is active and passing audio they
1477 * generally don't require full power. Signal
1478 * generators are virtual pins and have no
1479 * power impact themselves.
1482 case snd_soc_dapm_siggen:
1484 case snd_soc_dapm_supply:
1485 case snd_soc_dapm_regulator_supply:
1486 case snd_soc_dapm_micbias:
1487 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1488 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1491 d->target_bias_level = SND_SOC_BIAS_ON;
1498 /* Force all contexts in the card to the same bias state if
1499 * they're not ground referenced.
1501 bias = SND_SOC_BIAS_OFF;
1502 list_for_each_entry(d, &card->dapm_list, list)
1503 if (d->target_bias_level > bias)
1504 bias = d->target_bias_level;
1505 list_for_each_entry(d, &card->dapm_list, list)
1506 if (!d->idle_bias_off)
1507 d->target_bias_level = bias;
1509 trace_snd_soc_dapm_walk_done(card);
1511 /* Run all the bias changes in parallel */
1512 list_for_each_entry(d, &dapm->card->dapm_list, list)
1513 async_schedule_domain(dapm_pre_sequence_async, d,
1515 async_synchronize_full_domain(&async_domain);
1517 /* Power down widgets first; try to avoid amplifying pops. */
1518 dapm_seq_run(dapm, &down_list, event, false);
1520 dapm_widget_update(dapm);
1523 dapm_seq_run(dapm, &up_list, event, true);
1525 /* Run all the bias changes in parallel */
1526 list_for_each_entry(d, &dapm->card->dapm_list, list)
1527 async_schedule_domain(dapm_post_sequence_async, d,
1529 async_synchronize_full_domain(&async_domain);
1531 /* do we need to notify any clients that DAPM event is complete */
1532 list_for_each_entry(d, &card->dapm_list, list) {
1533 if (d->stream_event)
1534 d->stream_event(d, event);
1537 pop_dbg(dapm->dev, card->pop_time,
1538 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1539 pop_wait(card->pop_time);
1541 trace_snd_soc_dapm_done(card);
1546 #ifdef CONFIG_DEBUG_FS
1547 static ssize_t dapm_widget_power_read_file(struct file *file,
1548 char __user *user_buf,
1549 size_t count, loff_t *ppos)
1551 struct snd_soc_dapm_widget *w = file->private_data;
1555 struct snd_soc_dapm_path *p = NULL;
1557 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1561 in = is_connected_input_ep(w);
1562 dapm_clear_walk(w->dapm);
1563 out = is_connected_output_ep(w);
1564 dapm_clear_walk(w->dapm);
1566 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
1567 w->name, w->power ? "On" : "Off",
1568 w->force ? " (forced)" : "", in, out);
1571 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1572 " - R%d(0x%x) bit %d",
1573 w->reg, w->reg, w->shift);
1575 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1578 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1580 w->active ? "active" : "inactive");
1582 list_for_each_entry(p, &w->sources, list_sink) {
1583 if (p->connected && !p->connected(w, p->sink))
1587 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1588 " in \"%s\" \"%s\"\n",
1589 p->name ? p->name : "static",
1592 list_for_each_entry(p, &w->sinks, list_source) {
1593 if (p->connected && !p->connected(w, p->sink))
1597 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1598 " out \"%s\" \"%s\"\n",
1599 p->name ? p->name : "static",
1603 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1609 static const struct file_operations dapm_widget_power_fops = {
1610 .open = simple_open,
1611 .read = dapm_widget_power_read_file,
1612 .llseek = default_llseek,
1615 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1616 size_t count, loff_t *ppos)
1618 struct snd_soc_dapm_context *dapm = file->private_data;
1621 switch (dapm->bias_level) {
1622 case SND_SOC_BIAS_ON:
1625 case SND_SOC_BIAS_PREPARE:
1626 level = "Prepare\n";
1628 case SND_SOC_BIAS_STANDBY:
1629 level = "Standby\n";
1631 case SND_SOC_BIAS_OFF:
1636 level = "Unknown\n";
1640 return simple_read_from_buffer(user_buf, count, ppos, level,
1644 static const struct file_operations dapm_bias_fops = {
1645 .open = simple_open,
1646 .read = dapm_bias_read_file,
1647 .llseek = default_llseek,
1650 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1651 struct dentry *parent)
1655 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1657 if (!dapm->debugfs_dapm) {
1659 "Failed to create DAPM debugfs directory\n");
1663 d = debugfs_create_file("bias_level", 0444,
1664 dapm->debugfs_dapm, dapm,
1668 "ASoC: Failed to create bias level debugfs file\n");
1671 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1673 struct snd_soc_dapm_context *dapm = w->dapm;
1676 if (!dapm->debugfs_dapm || !w->name)
1679 d = debugfs_create_file(w->name, 0444,
1680 dapm->debugfs_dapm, w,
1681 &dapm_widget_power_fops);
1683 dev_warn(w->dapm->dev,
1684 "ASoC: Failed to create %s debugfs file\n",
1688 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1690 debugfs_remove_recursive(dapm->debugfs_dapm);
1694 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1695 struct dentry *parent)
1699 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1703 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1709 /* test and update the power status of a mux widget */
1710 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1711 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1713 struct snd_soc_dapm_path *path;
1716 if (widget->id != snd_soc_dapm_mux &&
1717 widget->id != snd_soc_dapm_virt_mux &&
1718 widget->id != snd_soc_dapm_value_mux)
1721 /* find dapm widget path assoc with kcontrol */
1722 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1723 if (path->kcontrol != kcontrol)
1726 if (!path->name || !e->texts[mux])
1730 /* we now need to match the string in the enum to the path */
1731 if (!(strcmp(path->name, e->texts[mux]))) {
1732 path->connect = 1; /* new connection */
1733 dapm_mark_dirty(path->source, "mux connection");
1736 dapm_mark_dirty(path->source,
1737 "mux disconnection");
1738 path->connect = 0; /* old connection must be powered down */
1743 dapm_mark_dirty(widget, "mux change");
1744 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1750 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1751 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1753 struct snd_soc_card *card = widget->dapm->card;
1756 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1757 ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
1758 mutex_unlock(&card->dapm_mutex);
1761 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
1763 /* test and update the power status of a mixer or switch widget */
1764 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1765 struct snd_kcontrol *kcontrol, int connect)
1767 struct snd_soc_dapm_path *path;
1770 if (widget->id != snd_soc_dapm_mixer &&
1771 widget->id != snd_soc_dapm_mixer_named_ctl &&
1772 widget->id != snd_soc_dapm_switch)
1775 /* find dapm widget path assoc with kcontrol */
1776 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1777 if (path->kcontrol != kcontrol)
1780 /* found, now check type */
1782 path->connect = connect;
1783 dapm_mark_dirty(path->source, "mixer connection");
1787 dapm_mark_dirty(widget, "mixer update");
1788 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1794 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1795 struct snd_kcontrol *kcontrol, int connect)
1797 struct snd_soc_card *card = widget->dapm->card;
1800 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1801 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
1802 mutex_unlock(&card->dapm_mutex);
1805 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
1807 /* show dapm widget status in sys fs */
1808 static ssize_t dapm_widget_show(struct device *dev,
1809 struct device_attribute *attr, char *buf)
1811 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
1812 struct snd_soc_codec *codec =rtd->codec;
1813 struct snd_soc_dapm_widget *w;
1815 char *state = "not set";
1817 list_for_each_entry(w, &codec->card->widgets, list) {
1818 if (w->dapm != &codec->dapm)
1821 /* only display widgets that burnm power */
1823 case snd_soc_dapm_hp:
1824 case snd_soc_dapm_mic:
1825 case snd_soc_dapm_spk:
1826 case snd_soc_dapm_line:
1827 case snd_soc_dapm_micbias:
1828 case snd_soc_dapm_dac:
1829 case snd_soc_dapm_adc:
1830 case snd_soc_dapm_pga:
1831 case snd_soc_dapm_out_drv:
1832 case snd_soc_dapm_mixer:
1833 case snd_soc_dapm_mixer_named_ctl:
1834 case snd_soc_dapm_supply:
1835 case snd_soc_dapm_regulator_supply:
1837 count += sprintf(buf + count, "%s: %s\n",
1838 w->name, w->power ? "On":"Off");
1845 switch (codec->dapm.bias_level) {
1846 case SND_SOC_BIAS_ON:
1849 case SND_SOC_BIAS_PREPARE:
1852 case SND_SOC_BIAS_STANDBY:
1855 case SND_SOC_BIAS_OFF:
1859 count += sprintf(buf + count, "PM State: %s\n", state);
1864 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1866 int snd_soc_dapm_sys_add(struct device *dev)
1868 return device_create_file(dev, &dev_attr_dapm_widget);
1871 static void snd_soc_dapm_sys_remove(struct device *dev)
1873 device_remove_file(dev, &dev_attr_dapm_widget);
1876 /* free all dapm widgets and resources */
1877 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1879 struct snd_soc_dapm_widget *w, *next_w;
1880 struct snd_soc_dapm_path *p, *next_p;
1882 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1883 if (w->dapm != dapm)
1887 * remove source and sink paths associated to this widget.
1888 * While removing the path, remove reference to it from both
1889 * source and sink widgets so that path is removed only once.
1891 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1892 list_del(&p->list_sink);
1893 list_del(&p->list_source);
1895 kfree(p->long_name);
1898 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1899 list_del(&p->list_sink);
1900 list_del(&p->list_source);
1902 kfree(p->long_name);
1905 kfree(w->kcontrols);
1911 static struct snd_soc_dapm_widget *dapm_find_widget(
1912 struct snd_soc_dapm_context *dapm, const char *pin,
1913 bool search_other_contexts)
1915 struct snd_soc_dapm_widget *w;
1916 struct snd_soc_dapm_widget *fallback = NULL;
1918 list_for_each_entry(w, &dapm->card->widgets, list) {
1919 if (!strcmp(w->name, pin)) {
1920 if (w->dapm == dapm)
1927 if (search_other_contexts)
1933 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1934 const char *pin, int status)
1936 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
1939 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1943 if (w->connected != status)
1944 dapm_mark_dirty(w, "pin configuration");
1946 w->connected = status;
1954 * snd_soc_dapm_sync - scan and power dapm paths
1955 * @dapm: DAPM context
1957 * Walks all dapm audio paths and powers widgets according to their
1958 * stream or path usage.
1960 * Returns 0 for success.
1962 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1967 * Suppress early reports (eg, jacks syncing their state) to avoid
1968 * silly DAPM runs during card startup.
1970 if (!dapm->card || !dapm->card->instantiated)
1973 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1974 ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1975 mutex_unlock(&dapm->card->dapm_mutex);
1978 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1980 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1981 const struct snd_soc_dapm_route *route)
1983 struct snd_soc_dapm_path *path;
1984 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1985 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1987 const char *control = route->control;
1989 char prefixed_sink[80];
1990 char prefixed_source[80];
1993 if (dapm->codec && dapm->codec->name_prefix) {
1994 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1995 dapm->codec->name_prefix, route->sink);
1996 sink = prefixed_sink;
1997 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1998 dapm->codec->name_prefix, route->source);
1999 source = prefixed_source;
2002 source = route->source;
2006 * find src and dest widgets over all widgets but favor a widget from
2007 * current DAPM context
2009 list_for_each_entry(w, &dapm->card->widgets, list) {
2010 if (!wsink && !(strcmp(w->name, sink))) {
2012 if (w->dapm == dapm)
2016 if (!wsource && !(strcmp(w->name, source))) {
2018 if (w->dapm == dapm)
2022 /* use widget from another DAPM context if not found from this */
2028 if (wsource == NULL || wsink == NULL)
2031 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2035 path->source = wsource;
2037 path->connected = route->connected;
2038 INIT_LIST_HEAD(&path->list);
2039 INIT_LIST_HEAD(&path->list_source);
2040 INIT_LIST_HEAD(&path->list_sink);
2042 /* check for external widgets */
2043 if (wsink->id == snd_soc_dapm_input) {
2044 if (wsource->id == snd_soc_dapm_micbias ||
2045 wsource->id == snd_soc_dapm_mic ||
2046 wsource->id == snd_soc_dapm_line ||
2047 wsource->id == snd_soc_dapm_output)
2050 if (wsource->id == snd_soc_dapm_output) {
2051 if (wsink->id == snd_soc_dapm_spk ||
2052 wsink->id == snd_soc_dapm_hp ||
2053 wsink->id == snd_soc_dapm_line ||
2054 wsink->id == snd_soc_dapm_input)
2058 /* connect static paths */
2059 if (control == NULL) {
2060 list_add(&path->list, &dapm->card->paths);
2061 list_add(&path->list_sink, &wsink->sources);
2062 list_add(&path->list_source, &wsource->sinks);
2067 /* connect dynamic paths */
2068 switch (wsink->id) {
2069 case snd_soc_dapm_adc:
2070 case snd_soc_dapm_dac:
2071 case snd_soc_dapm_pga:
2072 case snd_soc_dapm_out_drv:
2073 case snd_soc_dapm_input:
2074 case snd_soc_dapm_output:
2075 case snd_soc_dapm_siggen:
2076 case snd_soc_dapm_micbias:
2077 case snd_soc_dapm_vmid:
2078 case snd_soc_dapm_pre:
2079 case snd_soc_dapm_post:
2080 case snd_soc_dapm_supply:
2081 case snd_soc_dapm_regulator_supply:
2082 case snd_soc_dapm_aif_in:
2083 case snd_soc_dapm_aif_out:
2084 case snd_soc_dapm_dai:
2085 case snd_soc_dapm_dai_link:
2086 list_add(&path->list, &dapm->card->paths);
2087 list_add(&path->list_sink, &wsink->sources);
2088 list_add(&path->list_source, &wsource->sinks);
2091 case snd_soc_dapm_mux:
2092 case snd_soc_dapm_virt_mux:
2093 case snd_soc_dapm_value_mux:
2094 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2095 &wsink->kcontrol_news[0]);
2099 case snd_soc_dapm_switch:
2100 case snd_soc_dapm_mixer:
2101 case snd_soc_dapm_mixer_named_ctl:
2102 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2106 case snd_soc_dapm_hp:
2107 case snd_soc_dapm_mic:
2108 case snd_soc_dapm_line:
2109 case snd_soc_dapm_spk:
2110 list_add(&path->list, &dapm->card->paths);
2111 list_add(&path->list_sink, &wsink->sources);
2112 list_add(&path->list_source, &wsource->sinks);
2119 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
2120 source, control, sink);
2126 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2127 * @dapm: DAPM context
2128 * @route: audio routes
2129 * @num: number of routes
2131 * Connects 2 dapm widgets together via a named audio path. The sink is
2132 * the widget receiving the audio signal, whilst the source is the sender
2133 * of the audio signal.
2135 * Returns 0 for success else error. On error all resources can be freed
2136 * with a call to snd_soc_card_free().
2138 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2139 const struct snd_soc_dapm_route *route, int num)
2143 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2144 for (i = 0; i < num; i++) {
2145 ret = snd_soc_dapm_add_route(dapm, route);
2147 dev_err(dapm->dev, "Failed to add route %s->%s\n",
2148 route->source, route->sink);
2153 mutex_unlock(&dapm->card->dapm_mutex);
2157 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2159 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2160 const struct snd_soc_dapm_route *route)
2162 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2165 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2168 struct snd_soc_dapm_path *path;
2172 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
2178 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
2183 if (route->control || route->connected)
2184 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
2185 route->source, route->sink);
2187 list_for_each_entry(path, &source->sinks, list_source) {
2188 if (path->sink == sink) {
2195 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
2196 route->source, route->sink);
2198 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
2199 count, route->source, route->sink);
2205 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2206 * @dapm: DAPM context
2207 * @route: audio routes
2208 * @num: number of routes
2210 * Mark existing routes matching those specified in the passed array
2211 * as being weak, meaning that they are ignored for the purpose of
2212 * power decisions. The main intended use case is for sidetone paths
2213 * which couple audio between other independent paths if they are both
2214 * active in order to make the combination work better at the user
2215 * level but which aren't intended to be "used".
2217 * Note that CODEC drivers should not use this as sidetone type paths
2218 * can frequently also be used as bypass paths.
2220 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2221 const struct snd_soc_dapm_route *route, int num)
2226 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2227 for (i = 0; i < num; i++) {
2228 err = snd_soc_dapm_weak_route(dapm, route);
2233 mutex_unlock(&dapm->card->dapm_mutex);
2237 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2240 * snd_soc_dapm_new_widgets - add new dapm widgets
2241 * @dapm: DAPM context
2243 * Checks the codec for any new dapm widgets and creates them if found.
2245 * Returns 0 for success.
2247 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2249 struct snd_soc_dapm_widget *w;
2252 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2254 list_for_each_entry(w, &dapm->card->widgets, list)
2259 if (w->num_kcontrols) {
2260 w->kcontrols = kzalloc(w->num_kcontrols *
2261 sizeof(struct snd_kcontrol *),
2263 if (!w->kcontrols) {
2264 mutex_unlock(&dapm->card->dapm_mutex);
2270 case snd_soc_dapm_switch:
2271 case snd_soc_dapm_mixer:
2272 case snd_soc_dapm_mixer_named_ctl:
2275 case snd_soc_dapm_mux:
2276 case snd_soc_dapm_virt_mux:
2277 case snd_soc_dapm_value_mux:
2280 case snd_soc_dapm_pga:
2281 case snd_soc_dapm_out_drv:
2288 /* Read the initial power state from the device */
2290 val = soc_widget_read(w, w->reg);
2291 val &= 1 << w->shift;
2301 dapm_mark_dirty(w, "new widget");
2302 dapm_debugfs_add_widget(w);
2305 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2306 mutex_unlock(&dapm->card->dapm_mutex);
2309 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2312 * snd_soc_dapm_get_volsw - dapm mixer get callback
2313 * @kcontrol: mixer control
2314 * @ucontrol: control element information
2316 * Callback to get the value of a dapm mixer control.
2318 * Returns 0 for success.
2320 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2321 struct snd_ctl_elem_value *ucontrol)
2323 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2324 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2325 struct soc_mixer_control *mc =
2326 (struct soc_mixer_control *)kcontrol->private_value;
2327 unsigned int reg = mc->reg;
2328 unsigned int shift = mc->shift;
2329 unsigned int rshift = mc->rshift;
2331 unsigned int invert = mc->invert;
2332 unsigned int mask = (1 << fls(max)) - 1;
2334 ucontrol->value.integer.value[0] =
2335 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2336 if (shift != rshift)
2337 ucontrol->value.integer.value[1] =
2338 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2340 ucontrol->value.integer.value[0] =
2341 max - ucontrol->value.integer.value[0];
2342 if (shift != rshift)
2343 ucontrol->value.integer.value[1] =
2344 max - ucontrol->value.integer.value[1];
2349 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2352 * snd_soc_dapm_put_volsw - dapm mixer set callback
2353 * @kcontrol: mixer control
2354 * @ucontrol: control element information
2356 * Callback to set the value of a dapm mixer control.
2358 * Returns 0 for success.
2360 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2361 struct snd_ctl_elem_value *ucontrol)
2363 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2364 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2365 struct snd_soc_codec *codec = widget->codec;
2366 struct snd_soc_card *card = codec->card;
2367 struct soc_mixer_control *mc =
2368 (struct soc_mixer_control *)kcontrol->private_value;
2369 unsigned int reg = mc->reg;
2370 unsigned int shift = mc->shift;
2372 unsigned int mask = (1 << fls(max)) - 1;
2373 unsigned int invert = mc->invert;
2375 int connect, change;
2376 struct snd_soc_dapm_update update;
2379 val = (ucontrol->value.integer.value[0] & mask);
2383 mask = mask << shift;
2387 /* new connection */
2388 connect = invert ? 0 : 1;
2390 /* old connection must be powered down */
2391 connect = invert ? 1 : 0;
2393 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2395 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2397 for (wi = 0; wi < wlist->num_widgets; wi++) {
2398 widget = wlist->widgets[wi];
2400 widget->value = val;
2402 update.kcontrol = kcontrol;
2403 update.widget = widget;
2407 widget->dapm->update = &update;
2409 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2411 widget->dapm->update = NULL;
2415 mutex_unlock(&card->dapm_mutex);
2418 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2421 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2422 * @kcontrol: mixer control
2423 * @ucontrol: control element information
2425 * Callback to get the value of a dapm enumerated double mixer control.
2427 * Returns 0 for success.
2429 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2430 struct snd_ctl_elem_value *ucontrol)
2432 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2433 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2434 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2435 unsigned int val, bitmask;
2437 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2439 val = snd_soc_read(widget->codec, e->reg);
2440 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2441 if (e->shift_l != e->shift_r)
2442 ucontrol->value.enumerated.item[1] =
2443 (val >> e->shift_r) & (bitmask - 1);
2447 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2450 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2451 * @kcontrol: mixer control
2452 * @ucontrol: control element information
2454 * Callback to set the value of a dapm enumerated double mixer control.
2456 * Returns 0 for success.
2458 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2459 struct snd_ctl_elem_value *ucontrol)
2461 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2462 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2463 struct snd_soc_codec *codec = widget->codec;
2464 struct snd_soc_card *card = codec->card;
2465 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2466 unsigned int val, mux, change;
2467 unsigned int mask, bitmask;
2468 struct snd_soc_dapm_update update;
2471 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2473 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2475 mux = ucontrol->value.enumerated.item[0];
2476 val = mux << e->shift_l;
2477 mask = (bitmask - 1) << e->shift_l;
2478 if (e->shift_l != e->shift_r) {
2479 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2481 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2482 mask |= (bitmask - 1) << e->shift_r;
2485 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2487 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2489 for (wi = 0; wi < wlist->num_widgets; wi++) {
2490 widget = wlist->widgets[wi];
2492 widget->value = val;
2494 update.kcontrol = kcontrol;
2495 update.widget = widget;
2496 update.reg = e->reg;
2499 widget->dapm->update = &update;
2501 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2503 widget->dapm->update = NULL;
2507 mutex_unlock(&card->dapm_mutex);
2510 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2513 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2514 * @kcontrol: mixer control
2515 * @ucontrol: control element information
2517 * Returns 0 for success.
2519 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2520 struct snd_ctl_elem_value *ucontrol)
2522 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2523 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2525 ucontrol->value.enumerated.item[0] = widget->value;
2529 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2532 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2533 * @kcontrol: mixer control
2534 * @ucontrol: control element information
2536 * Returns 0 for success.
2538 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2539 struct snd_ctl_elem_value *ucontrol)
2541 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2542 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2543 struct snd_soc_codec *codec = widget->codec;
2544 struct snd_soc_card *card = codec->card;
2545 struct soc_enum *e =
2546 (struct soc_enum *)kcontrol->private_value;
2551 if (ucontrol->value.enumerated.item[0] >= e->max)
2554 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2556 change = widget->value != ucontrol->value.enumerated.item[0];
2558 for (wi = 0; wi < wlist->num_widgets; wi++) {
2559 widget = wlist->widgets[wi];
2561 widget->value = ucontrol->value.enumerated.item[0];
2563 soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
2567 mutex_unlock(&card->dapm_mutex);
2570 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2573 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2575 * @kcontrol: mixer control
2576 * @ucontrol: control element information
2578 * Callback to get the value of a dapm semi enumerated double mixer control.
2580 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2581 * used for handling bitfield coded enumeration for example.
2583 * Returns 0 for success.
2585 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2586 struct snd_ctl_elem_value *ucontrol)
2588 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2589 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2590 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2591 unsigned int reg_val, val, mux;
2593 reg_val = snd_soc_read(widget->codec, e->reg);
2594 val = (reg_val >> e->shift_l) & e->mask;
2595 for (mux = 0; mux < e->max; mux++) {
2596 if (val == e->values[mux])
2599 ucontrol->value.enumerated.item[0] = mux;
2600 if (e->shift_l != e->shift_r) {
2601 val = (reg_val >> e->shift_r) & e->mask;
2602 for (mux = 0; mux < e->max; mux++) {
2603 if (val == e->values[mux])
2606 ucontrol->value.enumerated.item[1] = mux;
2611 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2614 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2616 * @kcontrol: mixer control
2617 * @ucontrol: control element information
2619 * Callback to set the value of a dapm semi enumerated double mixer control.
2621 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2622 * used for handling bitfield coded enumeration for example.
2624 * Returns 0 for success.
2626 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2627 struct snd_ctl_elem_value *ucontrol)
2629 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2630 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2631 struct snd_soc_codec *codec = widget->codec;
2632 struct snd_soc_card *card = codec->card;
2633 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2634 unsigned int val, mux, change;
2636 struct snd_soc_dapm_update update;
2639 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2641 mux = ucontrol->value.enumerated.item[0];
2642 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2643 mask = e->mask << e->shift_l;
2644 if (e->shift_l != e->shift_r) {
2645 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2647 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2648 mask |= e->mask << e->shift_r;
2651 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2653 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2655 for (wi = 0; wi < wlist->num_widgets; wi++) {
2656 widget = wlist->widgets[wi];
2658 widget->value = val;
2660 update.kcontrol = kcontrol;
2661 update.widget = widget;
2662 update.reg = e->reg;
2665 widget->dapm->update = &update;
2667 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2669 widget->dapm->update = NULL;
2673 mutex_unlock(&card->dapm_mutex);
2676 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2679 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2681 * @kcontrol: mixer control
2682 * @uinfo: control element information
2684 * Callback to provide information about a pin switch control.
2686 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2687 struct snd_ctl_elem_info *uinfo)
2689 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2691 uinfo->value.integer.min = 0;
2692 uinfo->value.integer.max = 1;
2696 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2699 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2701 * @kcontrol: mixer control
2704 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2705 struct snd_ctl_elem_value *ucontrol)
2707 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2708 const char *pin = (const char *)kcontrol->private_value;
2710 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2712 ucontrol->value.integer.value[0] =
2713 snd_soc_dapm_get_pin_status(&card->dapm, pin);
2715 mutex_unlock(&card->dapm_mutex);
2719 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2722 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2724 * @kcontrol: mixer control
2727 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2728 struct snd_ctl_elem_value *ucontrol)
2730 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2731 const char *pin = (const char *)kcontrol->private_value;
2733 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2735 if (ucontrol->value.integer.value[0])
2736 snd_soc_dapm_enable_pin(&card->dapm, pin);
2738 snd_soc_dapm_disable_pin(&card->dapm, pin);
2740 mutex_unlock(&card->dapm_mutex);
2742 snd_soc_dapm_sync(&card->dapm);
2745 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2747 static struct snd_soc_dapm_widget *
2748 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2749 const struct snd_soc_dapm_widget *widget)
2751 struct snd_soc_dapm_widget *w;
2755 if ((w = dapm_cnew_widget(widget)) == NULL)
2759 case snd_soc_dapm_regulator_supply:
2760 w->regulator = devm_regulator_get(dapm->dev, w->name);
2761 if (IS_ERR(w->regulator)) {
2762 ret = PTR_ERR(w->regulator);
2763 dev_err(dapm->dev, "Failed to request %s: %d\n",
2772 name_len = strlen(widget->name) + 1;
2773 if (dapm->codec && dapm->codec->name_prefix)
2774 name_len += 1 + strlen(dapm->codec->name_prefix);
2775 w->name = kmalloc(name_len, GFP_KERNEL);
2776 if (w->name == NULL) {
2780 if (dapm->codec && dapm->codec->name_prefix)
2781 snprintf((char *)w->name, name_len, "%s %s",
2782 dapm->codec->name_prefix, widget->name);
2784 snprintf((char *)w->name, name_len, "%s", widget->name);
2787 case snd_soc_dapm_switch:
2788 case snd_soc_dapm_mixer:
2789 case snd_soc_dapm_mixer_named_ctl:
2790 w->power_check = dapm_generic_check_power;
2792 case snd_soc_dapm_mux:
2793 case snd_soc_dapm_virt_mux:
2794 case snd_soc_dapm_value_mux:
2795 w->power_check = dapm_generic_check_power;
2797 case snd_soc_dapm_adc:
2798 case snd_soc_dapm_aif_out:
2799 w->power_check = dapm_adc_check_power;
2801 case snd_soc_dapm_dac:
2802 case snd_soc_dapm_aif_in:
2803 w->power_check = dapm_dac_check_power;
2805 case snd_soc_dapm_pga:
2806 case snd_soc_dapm_out_drv:
2807 case snd_soc_dapm_input:
2808 case snd_soc_dapm_output:
2809 case snd_soc_dapm_micbias:
2810 case snd_soc_dapm_spk:
2811 case snd_soc_dapm_hp:
2812 case snd_soc_dapm_mic:
2813 case snd_soc_dapm_line:
2814 case snd_soc_dapm_dai_link:
2815 w->power_check = dapm_generic_check_power;
2817 case snd_soc_dapm_supply:
2818 case snd_soc_dapm_regulator_supply:
2819 w->power_check = dapm_supply_check_power;
2821 case snd_soc_dapm_dai:
2822 w->power_check = dapm_dai_check_power;
2825 w->power_check = dapm_always_on_check_power;
2831 w->codec = dapm->codec;
2832 w->platform = dapm->platform;
2833 INIT_LIST_HEAD(&w->sources);
2834 INIT_LIST_HEAD(&w->sinks);
2835 INIT_LIST_HEAD(&w->list);
2836 INIT_LIST_HEAD(&w->dirty);
2837 list_add(&w->list, &dapm->card->widgets);
2839 /* machine layer set ups unconnected pins and insertions */
2845 * snd_soc_dapm_new_controls - create new dapm controls
2846 * @dapm: DAPM context
2847 * @widget: widget array
2848 * @num: number of widgets
2850 * Creates new DAPM controls based upon the templates.
2852 * Returns 0 for success else error.
2854 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2855 const struct snd_soc_dapm_widget *widget,
2858 struct snd_soc_dapm_widget *w;
2862 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2863 for (i = 0; i < num; i++) {
2864 w = snd_soc_dapm_new_control(dapm, widget);
2867 "ASoC: Failed to create DAPM control %s\n",
2874 mutex_unlock(&dapm->card->dapm_mutex);
2877 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2879 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
2880 struct snd_kcontrol *kcontrol, int event)
2882 struct snd_soc_dapm_path *source_p, *sink_p;
2883 struct snd_soc_dai *source, *sink;
2884 const struct snd_soc_pcm_stream *config = w->params;
2885 struct snd_pcm_substream substream;
2886 struct snd_pcm_hw_params params;
2891 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks));
2893 /* We only support a single source and sink, pick the first */
2894 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
2896 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
2899 BUG_ON(!source_p || !sink_p);
2900 BUG_ON(!sink_p->source || !source_p->sink);
2901 BUG_ON(!source_p->source || !sink_p->sink);
2903 source = source_p->source->priv;
2904 sink = sink_p->sink->priv;
2906 /* Be a little careful as we don't want to overflow the mask array */
2907 if (config->formats) {
2908 fmt = ffs(config->formats) - 1;
2910 dev_warn(w->dapm->dev, "Invalid format %lx specified\n",
2915 /* Currently very limited parameter selection */
2916 memset(¶ms, 0, sizeof(params));
2917 snd_mask_set(hw_param_mask(¶ms, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
2919 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->min =
2921 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->max =
2924 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS)->min
2925 = config->channels_min;
2926 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS)->max
2927 = config->channels_max;
2929 memset(&substream, 0, sizeof(substream));
2932 case SND_SOC_DAPM_PRE_PMU:
2933 if (source->driver->ops && source->driver->ops->hw_params) {
2934 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
2935 ret = source->driver->ops->hw_params(&substream,
2938 dev_err(source->dev,
2939 "hw_params() failed: %d\n", ret);
2944 if (sink->driver->ops && sink->driver->ops->hw_params) {
2945 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
2946 ret = sink->driver->ops->hw_params(&substream, ¶ms,
2950 "hw_params() failed: %d\n", ret);
2956 case SND_SOC_DAPM_POST_PMU:
2957 ret = snd_soc_dai_digital_mute(sink, 0);
2958 if (ret != 0 && ret != -ENOTSUPP)
2959 dev_warn(sink->dev, "Failed to unmute: %d\n", ret);
2962 case SND_SOC_DAPM_PRE_PMD:
2963 ret = snd_soc_dai_digital_mute(sink, 1);
2964 if (ret != 0 && ret != -ENOTSUPP)
2965 dev_warn(sink->dev, "Failed to mute: %d\n", ret);
2976 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
2977 const struct snd_soc_pcm_stream *params,
2978 struct snd_soc_dapm_widget *source,
2979 struct snd_soc_dapm_widget *sink)
2981 struct snd_soc_dapm_route routes[2];
2982 struct snd_soc_dapm_widget template;
2983 struct snd_soc_dapm_widget *w;
2987 len = strlen(source->name) + strlen(sink->name) + 2;
2988 link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
2991 snprintf(link_name, len, "%s-%s", source->name, sink->name);
2993 memset(&template, 0, sizeof(template));
2994 template.reg = SND_SOC_NOPM;
2995 template.id = snd_soc_dapm_dai_link;
2996 template.name = link_name;
2997 template.event = snd_soc_dai_link_event;
2998 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
2999 SND_SOC_DAPM_PRE_PMD;
3001 dev_dbg(card->dev, "adding %s widget\n", link_name);
3003 w = snd_soc_dapm_new_control(&card->dapm, &template);
3005 dev_err(card->dev, "Failed to create %s widget\n",
3012 memset(&routes, 0, sizeof(routes));
3014 routes[0].source = source->name;
3015 routes[0].sink = link_name;
3016 routes[1].source = link_name;
3017 routes[1].sink = sink->name;
3019 return snd_soc_dapm_add_routes(&card->dapm, routes,
3020 ARRAY_SIZE(routes));
3023 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3024 struct snd_soc_dai *dai)
3026 struct snd_soc_dapm_widget template;
3027 struct snd_soc_dapm_widget *w;
3029 WARN_ON(dapm->dev != dai->dev);
3031 memset(&template, 0, sizeof(template));
3032 template.reg = SND_SOC_NOPM;
3034 if (dai->driver->playback.stream_name) {
3035 template.id = snd_soc_dapm_dai;
3036 template.name = dai->driver->playback.stream_name;
3037 template.sname = dai->driver->playback.stream_name;
3039 dev_dbg(dai->dev, "adding %s widget\n",
3042 w = snd_soc_dapm_new_control(dapm, &template);
3044 dev_err(dapm->dev, "Failed to create %s widget\n",
3045 dai->driver->playback.stream_name);
3049 dai->playback_widget = w;
3052 if (dai->driver->capture.stream_name) {
3053 template.id = snd_soc_dapm_dai;
3054 template.name = dai->driver->capture.stream_name;
3055 template.sname = dai->driver->capture.stream_name;
3057 dev_dbg(dai->dev, "adding %s widget\n",
3060 w = snd_soc_dapm_new_control(dapm, &template);
3062 dev_err(dapm->dev, "Failed to create %s widget\n",
3063 dai->driver->capture.stream_name);
3067 dai->capture_widget = w;
3073 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3075 struct snd_soc_dapm_widget *dai_w, *w;
3076 struct snd_soc_dai *dai;
3077 struct snd_soc_dapm_route r;
3079 memset(&r, 0, sizeof(r));
3081 /* For each DAI widget... */
3082 list_for_each_entry(dai_w, &card->widgets, list) {
3083 if (dai_w->id != snd_soc_dapm_dai)
3088 /* ...find all widgets with the same stream and link them */
3089 list_for_each_entry(w, &card->widgets, list) {
3090 if (w->dapm != dai_w->dapm)
3093 if (w->id == snd_soc_dapm_dai)
3099 if (dai->driver->playback.stream_name &&
3101 dai->driver->playback.stream_name)) {
3102 r.source = dai->playback_widget->name;
3104 dev_dbg(dai->dev, "%s -> %s\n",
3107 snd_soc_dapm_add_route(w->dapm, &r);
3110 if (dai->driver->capture.stream_name &&
3112 dai->driver->capture.stream_name)) {
3114 r.sink = dai->capture_widget->name;
3115 dev_dbg(dai->dev, "%s -> %s\n",
3118 snd_soc_dapm_add_route(w->dapm, &r);
3126 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3130 struct snd_soc_dapm_widget *w_cpu, *w_codec;
3131 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3132 struct snd_soc_dai *codec_dai = rtd->codec_dai;
3134 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
3135 w_cpu = cpu_dai->playback_widget;
3136 w_codec = codec_dai->playback_widget;
3138 w_cpu = cpu_dai->capture_widget;
3139 w_codec = codec_dai->capture_widget;
3144 dapm_mark_dirty(w_cpu, "stream event");
3147 case SND_SOC_DAPM_STREAM_START:
3150 case SND_SOC_DAPM_STREAM_STOP:
3153 case SND_SOC_DAPM_STREAM_SUSPEND:
3154 case SND_SOC_DAPM_STREAM_RESUME:
3155 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3156 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3163 dapm_mark_dirty(w_codec, "stream event");
3166 case SND_SOC_DAPM_STREAM_START:
3167 w_codec->active = 1;
3169 case SND_SOC_DAPM_STREAM_STOP:
3170 w_codec->active = 0;
3172 case SND_SOC_DAPM_STREAM_SUSPEND:
3173 case SND_SOC_DAPM_STREAM_RESUME:
3174 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3175 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3180 dapm_power_widgets(&rtd->card->dapm, event);
3184 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3185 * @rtd: PCM runtime data
3186 * @stream: stream name
3187 * @event: stream event
3189 * Sends a stream event to the dapm core. The core then makes any
3190 * necessary widget power changes.
3192 * Returns 0 for success else error.
3194 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3197 struct snd_soc_card *card = rtd->card;
3199 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3200 soc_dapm_stream_event(rtd, stream, event);
3201 mutex_unlock(&card->dapm_mutex);
3205 * snd_soc_dapm_enable_pin - enable pin.
3206 * @dapm: DAPM context
3209 * Enables input/output pin and its parents or children widgets iff there is
3210 * a valid audio route and active audio stream.
3211 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3212 * do any widget power switching.
3214 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3216 return snd_soc_dapm_set_pin(dapm, pin, 1);
3218 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3221 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3222 * @dapm: DAPM context
3225 * Enables input/output pin regardless of any other state. This is
3226 * intended for use with microphone bias supplies used in microphone
3229 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3230 * do any widget power switching.
3232 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3235 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3238 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3242 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
3245 dapm_mark_dirty(w, "force enable");
3249 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
3252 * snd_soc_dapm_disable_pin - disable pin.
3253 * @dapm: DAPM context
3256 * Disables input/output pin and its parents or children widgets.
3257 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3258 * do any widget power switching.
3260 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
3263 return snd_soc_dapm_set_pin(dapm, pin, 0);
3265 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3268 * snd_soc_dapm_nc_pin - permanently disable pin.
3269 * @dapm: DAPM context
3272 * Marks the specified pin as being not connected, disabling it along
3273 * any parent or child widgets. At present this is identical to
3274 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3275 * additional things such as disabling controls which only affect
3276 * paths through the pin.
3278 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3279 * do any widget power switching.
3281 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3283 return snd_soc_dapm_set_pin(dapm, pin, 0);
3285 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
3288 * snd_soc_dapm_get_pin_status - get audio pin status
3289 * @dapm: DAPM context
3290 * @pin: audio signal pin endpoint (or start point)
3292 * Get audio pin status - connected or disconnected.
3294 * Returns 1 for connected otherwise 0.
3296 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
3299 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3302 return w->connected;
3306 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
3309 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3310 * @dapm: DAPM context
3311 * @pin: audio signal pin endpoint (or start point)
3313 * Mark the given endpoint or pin as ignoring suspend. When the
3314 * system is disabled a path between two endpoints flagged as ignoring
3315 * suspend will not be disabled. The path must already be enabled via
3316 * normal means at suspend time, it will not be turned on if it was not
3319 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
3322 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
3325 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3329 w->ignore_suspend = 1;
3333 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3335 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
3336 struct snd_soc_dapm_widget *w)
3338 struct snd_soc_dapm_path *p;
3340 list_for_each_entry(p, &card->paths, list) {
3341 if ((p->source == w) || (p->sink == w)) {
3343 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3344 p->source->name, p->source->id, p->source->dapm,
3345 p->sink->name, p->sink->id, p->sink->dapm);
3347 /* Connected to something other than the codec */
3348 if (p->source->dapm != p->sink->dapm)
3351 * Loopback connection from codec external pin to
3352 * codec external pin
3354 if (p->sink->id == snd_soc_dapm_input) {
3355 switch (p->source->id) {
3356 case snd_soc_dapm_output:
3357 case snd_soc_dapm_micbias:
3370 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3371 * @codec: The codec whose pins should be processed
3373 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3374 * which are unused. Pins are used if they are connected externally to the
3375 * codec, whether that be to some other device, or a loop-back connection to
3378 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
3380 struct snd_soc_card *card = codec->card;
3381 struct snd_soc_dapm_context *dapm = &codec->dapm;
3382 struct snd_soc_dapm_widget *w;
3384 dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n",
3385 &card->dapm, &codec->dapm);
3387 list_for_each_entry(w, &card->widgets, list) {
3388 if (w->dapm != dapm)
3391 case snd_soc_dapm_input:
3392 case snd_soc_dapm_output:
3393 case snd_soc_dapm_micbias:
3394 dev_dbg(codec->dev, "Auto NC: Checking widget %s\n",
3396 if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
3398 "... Not in map; disabling\n");
3399 snd_soc_dapm_nc_pin(dapm, w->name);
3409 * snd_soc_dapm_free - free dapm resources
3410 * @dapm: DAPM context
3412 * Free all dapm widgets and resources.
3414 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
3416 snd_soc_dapm_sys_remove(dapm->dev);
3417 dapm_debugfs_cleanup(dapm);
3418 dapm_free_widgets(dapm);
3419 list_del(&dapm->list);
3421 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
3423 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
3425 struct snd_soc_dapm_widget *w;
3426 LIST_HEAD(down_list);
3429 list_for_each_entry(w, &dapm->card->widgets, list) {
3430 if (w->dapm != dapm)
3433 dapm_seq_insert(w, &down_list, false);
3439 /* If there were no widgets to power down we're already in
3443 if (dapm->bias_level == SND_SOC_BIAS_ON)
3444 snd_soc_dapm_set_bias_level(dapm,
3445 SND_SOC_BIAS_PREPARE);
3446 dapm_seq_run(dapm, &down_list, 0, false);
3447 if (dapm->bias_level == SND_SOC_BIAS_PREPARE)
3448 snd_soc_dapm_set_bias_level(dapm,
3449 SND_SOC_BIAS_STANDBY);
3454 * snd_soc_dapm_shutdown - callback for system shutdown
3456 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
3458 struct snd_soc_codec *codec;
3460 list_for_each_entry(codec, &card->codec_dev_list, list) {
3461 soc_dapm_shutdown_codec(&codec->dapm);
3462 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
3463 snd_soc_dapm_set_bias_level(&codec->dapm,
3468 /* Module information */
3469 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3470 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3471 MODULE_LICENSE("GPL");