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/meadphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
21 * o Delayed powerdown of audio susbsystem to reduce pops between a quick
25 * o DAPM power change sequencing - allow for configurable per
27 * o Support for analogue bias optimisation.
28 * o Support for reduced codec oversampling rates.
29 * o Support for reduced codec bias currents.
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/init.h>
35 #include <linux/async.h>
36 #include <linux/delay.h>
38 #include <linux/bitops.h>
39 #include <linux/platform_device.h>
40 #include <linux/jiffies.h>
41 #include <linux/debugfs.h>
42 #include <linux/slab.h>
43 #include <sound/core.h>
44 #include <sound/pcm.h>
45 #include <sound/pcm_params.h>
46 #include <sound/soc.h>
47 #include <sound/initval.h>
49 #include <trace/events/asoc.h>
51 /* dapm power sequences - make this per codec in the future */
52 static int dapm_up_seq[] = {
53 [snd_soc_dapm_pre] = 0,
54 [snd_soc_dapm_supply] = 1,
55 [snd_soc_dapm_micbias] = 2,
56 [snd_soc_dapm_aif_in] = 3,
57 [snd_soc_dapm_aif_out] = 3,
58 [snd_soc_dapm_mic] = 4,
59 [snd_soc_dapm_mux] = 5,
60 [snd_soc_dapm_virt_mux] = 5,
61 [snd_soc_dapm_value_mux] = 5,
62 [snd_soc_dapm_dac] = 6,
63 [snd_soc_dapm_mixer] = 7,
64 [snd_soc_dapm_mixer_named_ctl] = 7,
65 [snd_soc_dapm_pga] = 8,
66 [snd_soc_dapm_adc] = 9,
67 [snd_soc_dapm_out_drv] = 10,
68 [snd_soc_dapm_hp] = 10,
69 [snd_soc_dapm_spk] = 10,
70 [snd_soc_dapm_post] = 11,
73 static int dapm_down_seq[] = {
74 [snd_soc_dapm_pre] = 0,
75 [snd_soc_dapm_adc] = 1,
76 [snd_soc_dapm_hp] = 2,
77 [snd_soc_dapm_spk] = 2,
78 [snd_soc_dapm_out_drv] = 2,
79 [snd_soc_dapm_pga] = 4,
80 [snd_soc_dapm_mixer_named_ctl] = 5,
81 [snd_soc_dapm_mixer] = 5,
82 [snd_soc_dapm_dac] = 6,
83 [snd_soc_dapm_mic] = 7,
84 [snd_soc_dapm_micbias] = 8,
85 [snd_soc_dapm_mux] = 9,
86 [snd_soc_dapm_virt_mux] = 9,
87 [snd_soc_dapm_value_mux] = 9,
88 [snd_soc_dapm_aif_in] = 10,
89 [snd_soc_dapm_aif_out] = 10,
90 [snd_soc_dapm_supply] = 11,
91 [snd_soc_dapm_post] = 12,
94 static void pop_wait(u32 pop_time)
97 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
100 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
108 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
113 vsnprintf(buf, PAGE_SIZE, fmt, args);
114 dev_info(dev, "%s", buf);
120 /* create a new dapm widget */
121 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
122 const struct snd_soc_dapm_widget *_widget)
124 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
127 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
130 return snd_soc_read(w->codec, reg);
134 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
137 return snd_soc_write(w->codec, reg, val);
141 static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
142 unsigned short reg, unsigned int mask, unsigned int value)
145 unsigned int old, new;
148 ret = soc_widget_read(w, reg);
153 new = (old & ~mask) | (value & mask);
156 ret = soc_widget_write(w, reg, new);
165 * snd_soc_dapm_set_bias_level - set the bias level for the system
166 * @dapm: DAPM context
167 * @level: level to configure
169 * Configure the bias (power) levels for the SoC audio device.
171 * Returns 0 for success else error.
173 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
174 enum snd_soc_bias_level level)
176 struct snd_soc_card *card = dapm->card;
179 trace_snd_soc_bias_level_start(card, level);
181 if (card && card->set_bias_level)
182 ret = card->set_bias_level(card, dapm, level);
187 if (dapm->codec->driver->set_bias_level)
188 ret = dapm->codec->driver->set_bias_level(dapm->codec,
191 dapm->bias_level = level;
196 if (card && card->set_bias_level_post)
197 ret = card->set_bias_level_post(card, dapm, level);
199 trace_snd_soc_bias_level_done(card, level);
204 /* set up initial codec paths */
205 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
206 struct snd_soc_dapm_path *p, int i)
209 case snd_soc_dapm_switch:
210 case snd_soc_dapm_mixer:
211 case snd_soc_dapm_mixer_named_ctl: {
213 struct soc_mixer_control *mc = (struct soc_mixer_control *)
214 w->kcontrol_news[i].private_value;
215 unsigned int reg = mc->reg;
216 unsigned int shift = mc->shift;
218 unsigned int mask = (1 << fls(max)) - 1;
219 unsigned int invert = mc->invert;
221 val = soc_widget_read(w, reg);
222 val = (val >> shift) & mask;
224 if ((invert && !val) || (!invert && val))
230 case snd_soc_dapm_mux: {
231 struct soc_enum *e = (struct soc_enum *)
232 w->kcontrol_news[i].private_value;
233 int val, item, bitmask;
235 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
237 val = soc_widget_read(w, e->reg);
238 item = (val >> e->shift_l) & (bitmask - 1);
241 for (i = 0; i < e->max; i++) {
242 if (!(strcmp(p->name, e->texts[i])) && item == i)
247 case snd_soc_dapm_virt_mux: {
248 struct soc_enum *e = (struct soc_enum *)
249 w->kcontrol_news[i].private_value;
252 /* since a virtual mux has no backing registers to
253 * decide which path to connect, it will try to match
254 * with the first enumeration. This is to ensure
255 * that the default mux choice (the first) will be
256 * correctly powered up during initialization.
258 if (!strcmp(p->name, e->texts[0]))
262 case snd_soc_dapm_value_mux: {
263 struct soc_enum *e = (struct soc_enum *)
264 w->kcontrol_news[i].private_value;
267 val = soc_widget_read(w, e->reg);
268 val = (val >> e->shift_l) & e->mask;
269 for (item = 0; item < e->max; item++) {
270 if (val == e->values[item])
275 for (i = 0; i < e->max; i++) {
276 if (!(strcmp(p->name, e->texts[i])) && item == i)
281 /* does not effect routing - always connected */
282 case snd_soc_dapm_pga:
283 case snd_soc_dapm_out_drv:
284 case snd_soc_dapm_output:
285 case snd_soc_dapm_adc:
286 case snd_soc_dapm_input:
287 case snd_soc_dapm_dac:
288 case snd_soc_dapm_micbias:
289 case snd_soc_dapm_vmid:
290 case snd_soc_dapm_supply:
291 case snd_soc_dapm_aif_in:
292 case snd_soc_dapm_aif_out:
295 /* does effect routing - dynamically connected */
296 case snd_soc_dapm_hp:
297 case snd_soc_dapm_mic:
298 case snd_soc_dapm_spk:
299 case snd_soc_dapm_line:
300 case snd_soc_dapm_pre:
301 case snd_soc_dapm_post:
307 /* connect mux widget to its interconnecting audio paths */
308 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
309 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
310 struct snd_soc_dapm_path *path, const char *control_name,
311 const struct snd_kcontrol_new *kcontrol)
313 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
316 for (i = 0; i < e->max; i++) {
317 if (!(strcmp(control_name, e->texts[i]))) {
318 list_add(&path->list, &dapm->card->paths);
319 list_add(&path->list_sink, &dest->sources);
320 list_add(&path->list_source, &src->sinks);
321 path->name = (char*)e->texts[i];
322 dapm_set_path_status(dest, path, 0);
330 /* connect mixer widget to its interconnecting audio paths */
331 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
332 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
333 struct snd_soc_dapm_path *path, const char *control_name)
337 /* search for mixer kcontrol */
338 for (i = 0; i < dest->num_kcontrols; i++) {
339 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
340 list_add(&path->list, &dapm->card->paths);
341 list_add(&path->list_sink, &dest->sources);
342 list_add(&path->list_source, &src->sinks);
343 path->name = dest->kcontrol_news[i].name;
344 dapm_set_path_status(dest, path, i);
351 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
352 struct snd_soc_dapm_widget *kcontrolw,
353 const struct snd_kcontrol_new *kcontrol_new,
354 struct snd_kcontrol **kcontrol)
356 struct snd_soc_dapm_widget *w;
361 list_for_each_entry(w, &dapm->card->widgets, list) {
362 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
364 for (i = 0; i < w->num_kcontrols; i++) {
365 if (&w->kcontrol_news[i] == kcontrol_new) {
367 *kcontrol = w->kcontrols[i];
376 /* create new dapm mixer control */
377 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
379 struct snd_soc_dapm_context *dapm = w->dapm;
381 size_t name_len, prefix_len;
382 struct snd_soc_dapm_path *path;
383 struct snd_card *card = dapm->card->snd_card;
385 struct snd_soc_dapm_widget_list *wlist;
389 prefix = dapm->codec->name_prefix;
394 prefix_len = strlen(prefix) + 1;
399 for (i = 0; i < w->num_kcontrols; i++) {
402 list_for_each_entry(path, &w->sources, list_sink) {
404 /* mixer/mux paths name must match control name */
405 if (path->name != (char *)w->kcontrol_news[i].name)
408 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
409 sizeof(struct snd_soc_dapm_widget *),
410 wlist = kzalloc(wlistsize, GFP_KERNEL);
413 "asoc: can't allocate widget list for %s\n",
417 wlist->num_widgets = 1;
418 wlist->widgets[0] = w;
420 /* add dapm control with long name.
421 * for dapm_mixer this is the concatenation of the
422 * mixer and kcontrol name.
423 * for dapm_mixer_named_ctl this is simply the
426 name_len = strlen(w->kcontrol_news[i].name) + 1;
427 if (w->id != snd_soc_dapm_mixer_named_ctl)
428 name_len += 1 + strlen(w->name);
430 path->long_name = kmalloc(name_len, GFP_KERNEL);
432 if (path->long_name == NULL) {
439 /* The control will get a prefix from
440 * the control creation process but
441 * we're also using the same prefix
442 * for widgets so cut the prefix off
443 * the front of the widget name.
445 snprintf(path->long_name, name_len, "%s %s",
446 w->name + prefix_len,
447 w->kcontrol_news[i].name);
449 case snd_soc_dapm_mixer_named_ctl:
450 snprintf(path->long_name, name_len, "%s",
451 w->kcontrol_news[i].name);
455 path->long_name[name_len - 1] = '\0';
457 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
458 wlist, path->long_name,
460 ret = snd_ctl_add(card, path->kcontrol);
463 "asoc: failed to add dapm kcontrol %s: %d\n",
464 path->long_name, ret);
466 kfree(path->long_name);
467 path->long_name = NULL;
470 w->kcontrols[i] = path->kcontrol;
476 /* create new dapm mux control */
477 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
479 struct snd_soc_dapm_context *dapm = w->dapm;
480 struct snd_soc_dapm_path *path = NULL;
481 struct snd_kcontrol *kcontrol;
482 struct snd_card *card = dapm->card->snd_card;
486 struct snd_soc_dapm_widget_list *wlist;
487 int shared, wlistentries;
491 if (w->num_kcontrols != 1) {
493 "asoc: mux %s has incorrect number of controls\n",
498 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
501 wlist = kcontrol->private_data;
502 wlistentries = wlist->num_widgets + 1;
507 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
508 wlistentries * sizeof(struct snd_soc_dapm_widget *),
509 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
512 "asoc: can't allocate widget list for %s\n", w->name);
515 wlist->num_widgets = wlistentries;
516 wlist->widgets[wlistentries - 1] = w;
520 prefix = dapm->codec->name_prefix;
525 name = w->kcontrol_news[0].name;
530 prefix_len = strlen(prefix) + 1;
536 * The control will get a prefix from the control creation
537 * process but we're also using the same prefix for widgets so
538 * cut the prefix off the front of the widget name.
540 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
541 name + prefix_len, prefix);
542 ret = snd_ctl_add(card, kcontrol);
545 "asoc: failed to add kcontrol %s\n", w->name);
551 kcontrol->private_data = wlist;
553 w->kcontrols[0] = kcontrol;
555 list_for_each_entry(path, &w->sources, list_sink)
556 path->kcontrol = kcontrol;
561 /* create new dapm volume control */
562 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
564 if (w->num_kcontrols)
565 dev_err(w->dapm->dev,
566 "asoc: PGA controls not supported: '%s'\n", w->name);
571 /* reset 'walked' bit for each dapm path */
572 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
574 struct snd_soc_dapm_path *p;
576 list_for_each_entry(p, &dapm->card->paths, list)
580 /* We implement power down on suspend by checking the power state of
581 * the ALSA card - when we are suspending the ALSA state for the card
584 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
586 int level = snd_power_get_state(widget->dapm->card->snd_card);
589 case SNDRV_CTL_POWER_D3hot:
590 case SNDRV_CTL_POWER_D3cold:
591 if (widget->ignore_suspend)
592 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
594 return widget->ignore_suspend;
601 * Recursively check for a completed path to an active or physically connected
602 * output widget. Returns number of complete paths.
604 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
606 struct snd_soc_dapm_path *path;
609 if (widget->id == snd_soc_dapm_supply)
612 switch (widget->id) {
613 case snd_soc_dapm_adc:
614 case snd_soc_dapm_aif_out:
616 return snd_soc_dapm_suspend_check(widget);
621 if (widget->connected) {
622 /* connected pin ? */
623 if (widget->id == snd_soc_dapm_output && !widget->ext)
624 return snd_soc_dapm_suspend_check(widget);
626 /* connected jack or spk ? */
627 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
628 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
629 return snd_soc_dapm_suspend_check(widget);
632 list_for_each_entry(path, &widget->sinks, list_source) {
639 if (path->sink && path->connect) {
641 con += is_connected_output_ep(path->sink);
649 * Recursively check for a completed path to an active or physically connected
650 * input widget. Returns number of complete paths.
652 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
654 struct snd_soc_dapm_path *path;
657 if (widget->id == snd_soc_dapm_supply)
660 /* active stream ? */
661 switch (widget->id) {
662 case snd_soc_dapm_dac:
663 case snd_soc_dapm_aif_in:
665 return snd_soc_dapm_suspend_check(widget);
670 if (widget->connected) {
671 /* connected pin ? */
672 if (widget->id == snd_soc_dapm_input && !widget->ext)
673 return snd_soc_dapm_suspend_check(widget);
675 /* connected VMID/Bias for lower pops */
676 if (widget->id == snd_soc_dapm_vmid)
677 return snd_soc_dapm_suspend_check(widget);
679 /* connected jack ? */
680 if (widget->id == snd_soc_dapm_mic ||
681 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
682 return snd_soc_dapm_suspend_check(widget);
685 list_for_each_entry(path, &widget->sources, list_sink) {
692 if (path->source && path->connect) {
694 con += is_connected_input_ep(path->source);
702 * Handler for generic register modifier widget.
704 int dapm_reg_event(struct snd_soc_dapm_widget *w,
705 struct snd_kcontrol *kcontrol, int event)
709 if (SND_SOC_DAPM_EVENT_ON(event))
714 soc_widget_update_bits(w, -(w->reg + 1),
715 w->mask << w->shift, val << w->shift);
719 EXPORT_SYMBOL_GPL(dapm_reg_event);
721 /* Generic check to see if a widget should be powered.
723 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
727 in = is_connected_input_ep(w);
728 dapm_clear_walk(w->dapm);
729 out = is_connected_output_ep(w);
730 dapm_clear_walk(w->dapm);
731 return out != 0 && in != 0;
734 /* Check to see if an ADC has power */
735 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
740 in = is_connected_input_ep(w);
741 dapm_clear_walk(w->dapm);
744 return dapm_generic_check_power(w);
748 /* Check to see if a DAC has power */
749 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
754 out = is_connected_output_ep(w);
755 dapm_clear_walk(w->dapm);
758 return dapm_generic_check_power(w);
762 /* Check to see if a power supply is needed */
763 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
765 struct snd_soc_dapm_path *path;
768 /* Check if one of our outputs is connected */
769 list_for_each_entry(path, &w->sinks, list_source) {
773 if (path->connected &&
774 !path->connected(path->source, path->sink))
780 if (path->sink->force) {
785 if (path->sink->power_check &&
786 path->sink->power_check(path->sink)) {
792 dapm_clear_walk(w->dapm);
797 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
798 struct snd_soc_dapm_widget *b,
806 sort = dapm_down_seq;
808 if (sort[a->id] != sort[b->id])
809 return sort[a->id] - sort[b->id];
810 if (a->subseq != b->subseq) {
812 return a->subseq - b->subseq;
814 return b->subseq - a->subseq;
816 if (a->reg != b->reg)
817 return a->reg - b->reg;
818 if (a->dapm != b->dapm)
819 return (unsigned long)a->dapm - (unsigned long)b->dapm;
824 /* Insert a widget in order into a DAPM power sequence. */
825 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
826 struct list_head *list,
829 struct snd_soc_dapm_widget *w;
831 list_for_each_entry(w, list, power_list)
832 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
833 list_add_tail(&new_widget->power_list, &w->power_list);
837 list_add_tail(&new_widget->power_list, list);
840 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
841 struct snd_soc_dapm_widget *w, int event)
843 struct snd_soc_card *card = dapm->card;
848 case SND_SOC_DAPM_PRE_PMU:
852 case SND_SOC_DAPM_POST_PMU:
853 ev_name = "POST_PMU";
856 case SND_SOC_DAPM_PRE_PMD:
860 case SND_SOC_DAPM_POST_PMD:
861 ev_name = "POST_PMD";
869 if (w->power != power)
872 if (w->event && (w->event_flags & event)) {
873 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
875 trace_snd_soc_dapm_widget_event_start(w, event);
876 ret = w->event(w, NULL, event);
877 trace_snd_soc_dapm_widget_event_done(w, event);
879 pr_err("%s: %s event failed: %d\n",
880 ev_name, w->name, ret);
884 /* Apply the coalesced changes from a DAPM sequence */
885 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
886 struct list_head *pending)
888 struct snd_soc_card *card = dapm->card;
889 struct snd_soc_dapm_widget *w;
891 unsigned int value = 0;
892 unsigned int mask = 0;
893 unsigned int cur_mask;
895 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
898 list_for_each_entry(w, pending, power_list) {
899 cur_mask = 1 << w->shift;
900 BUG_ON(reg != w->reg);
911 pop_dbg(dapm->dev, card->pop_time,
912 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
913 w->name, reg, value, mask);
915 /* Check for events */
916 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
917 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
921 /* Any widget will do, they should all be updating the
924 w = list_first_entry(pending, struct snd_soc_dapm_widget,
927 pop_dbg(dapm->dev, card->pop_time,
928 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
929 value, mask, reg, card->pop_time);
930 pop_wait(card->pop_time);
931 soc_widget_update_bits(w, reg, mask, value);
934 list_for_each_entry(w, pending, power_list) {
935 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
936 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
940 /* Apply a DAPM power sequence.
942 * We walk over a pre-sorted list of widgets to apply power to. In
943 * order to minimise the number of writes to the device required
944 * multiple widgets will be updated in a single write where possible.
945 * Currently anything that requires more than a single write is not
948 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
949 struct list_head *list, int event, bool power_up)
951 struct snd_soc_dapm_widget *w, *n;
955 int cur_reg = SND_SOC_NOPM;
956 struct snd_soc_dapm_context *cur_dapm = NULL;
963 sort = dapm_down_seq;
965 list_for_each_entry_safe(w, n, list, power_list) {
968 /* Do we need to apply any queued changes? */
969 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
970 w->dapm != cur_dapm || w->subseq != cur_subseq) {
971 if (!list_empty(&pending))
972 dapm_seq_run_coalesced(cur_dapm, &pending);
974 if (cur_dapm && cur_dapm->seq_notifier) {
975 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
976 if (sort[i] == cur_sort)
977 cur_dapm->seq_notifier(cur_dapm,
982 INIT_LIST_HEAD(&pending);
985 cur_reg = SND_SOC_NOPM;
990 case snd_soc_dapm_pre:
992 list_for_each_entry_safe_continue(w, n, list,
995 if (event == SND_SOC_DAPM_STREAM_START)
997 NULL, SND_SOC_DAPM_PRE_PMU);
998 else if (event == SND_SOC_DAPM_STREAM_STOP)
1000 NULL, SND_SOC_DAPM_PRE_PMD);
1003 case snd_soc_dapm_post:
1005 list_for_each_entry_safe_continue(w, n, list,
1008 if (event == SND_SOC_DAPM_STREAM_START)
1010 NULL, SND_SOC_DAPM_POST_PMU);
1011 else if (event == SND_SOC_DAPM_STREAM_STOP)
1013 NULL, SND_SOC_DAPM_POST_PMD);
1017 /* Queue it up for application */
1018 cur_sort = sort[w->id];
1019 cur_subseq = w->subseq;
1022 list_move(&w->power_list, &pending);
1027 dev_err(w->dapm->dev,
1028 "Failed to apply widget power: %d\n", ret);
1031 if (!list_empty(&pending))
1032 dapm_seq_run_coalesced(cur_dapm, &pending);
1034 if (cur_dapm && cur_dapm->seq_notifier) {
1035 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1036 if (sort[i] == cur_sort)
1037 cur_dapm->seq_notifier(cur_dapm,
1042 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1044 struct snd_soc_dapm_update *update = dapm->update;
1045 struct snd_soc_dapm_widget *w;
1054 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1055 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1057 pr_err("%s DAPM pre-event failed: %d\n",
1061 ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
1064 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1067 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1068 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1070 pr_err("%s DAPM post-event failed: %d\n",
1075 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1076 * they're changing state.
1078 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1080 struct snd_soc_dapm_context *d = data;
1083 /* If we're off and we're not supposed to be go into STANDBY */
1084 if (d->bias_level == SND_SOC_BIAS_OFF &&
1085 d->target_bias_level != SND_SOC_BIAS_OFF) {
1086 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1089 "Failed to turn on bias: %d\n", ret);
1092 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1093 if (d->bias_level != d->target_bias_level) {
1094 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1097 "Failed to prepare bias: %d\n", ret);
1101 /* Async callback run prior to DAPM sequences - brings to their final
1104 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1106 struct snd_soc_dapm_context *d = data;
1109 /* If we just powered the last thing off drop to standby bias */
1110 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1111 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1112 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1113 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1115 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1119 /* If we're in standby and can support bias off then do that */
1120 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1121 d->target_bias_level == SND_SOC_BIAS_OFF) {
1122 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1124 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1127 /* If we just powered up then move to active bias */
1128 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1129 d->target_bias_level == SND_SOC_BIAS_ON) {
1130 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1132 dev_err(d->dev, "Failed to apply active bias: %d\n",
1138 * Scan each dapm widget for complete audio path.
1139 * A complete path is a route that has valid endpoints i.e.:-
1141 * o DAC to output pin.
1142 * o Input Pin to ADC.
1143 * o Input pin to Output pin (bypass, sidetone)
1144 * o DAC to ADC (loopback).
1146 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1148 struct snd_soc_card *card = dapm->card;
1149 struct snd_soc_dapm_widget *w;
1150 struct snd_soc_dapm_context *d;
1152 LIST_HEAD(down_list);
1153 LIST_HEAD(async_domain);
1154 enum snd_soc_bias_level bias;
1157 trace_snd_soc_dapm_start(card);
1159 list_for_each_entry(d, &card->dapm_list, list) {
1160 if (d->n_widgets || d->codec == NULL) {
1161 if (d->idle_bias_off)
1162 d->target_bias_level = SND_SOC_BIAS_OFF;
1164 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1168 /* Check which widgets we need to power and store them in
1169 * lists indicating if they should be powered up or down.
1171 list_for_each_entry(w, &card->widgets, list) {
1173 case snd_soc_dapm_pre:
1174 dapm_seq_insert(w, &down_list, false);
1176 case snd_soc_dapm_post:
1177 dapm_seq_insert(w, &up_list, true);
1181 if (!w->power_check)
1185 power = w->power_check(w);
1192 /* Supplies and micbiases only bring
1193 * the context up to STANDBY as unless
1194 * something else is active and
1195 * passing audio they generally don't
1196 * require full power.
1199 case snd_soc_dapm_supply:
1200 case snd_soc_dapm_micbias:
1201 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1202 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1205 d->target_bias_level = SND_SOC_BIAS_ON;
1210 if (w->power == power)
1213 trace_snd_soc_dapm_widget_power(w, power);
1216 dapm_seq_insert(w, &up_list, true);
1218 dapm_seq_insert(w, &down_list, false);
1225 /* If there are no DAPM widgets then try to figure out power from the
1228 if (!dapm->n_widgets) {
1230 case SND_SOC_DAPM_STREAM_START:
1231 case SND_SOC_DAPM_STREAM_RESUME:
1232 dapm->target_bias_level = SND_SOC_BIAS_ON;
1234 case SND_SOC_DAPM_STREAM_STOP:
1235 if (dapm->codec->active)
1236 dapm->target_bias_level = SND_SOC_BIAS_ON;
1238 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1240 case SND_SOC_DAPM_STREAM_SUSPEND:
1241 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1243 case SND_SOC_DAPM_STREAM_NOP:
1244 dapm->target_bias_level = dapm->bias_level;
1251 /* Force all contexts in the card to the same bias state */
1252 bias = SND_SOC_BIAS_OFF;
1253 list_for_each_entry(d, &card->dapm_list, list)
1254 if (d->target_bias_level > bias)
1255 bias = d->target_bias_level;
1256 list_for_each_entry(d, &card->dapm_list, list)
1257 d->target_bias_level = bias;
1260 /* Run all the bias changes in parallel */
1261 list_for_each_entry(d, &dapm->card->dapm_list, list)
1262 async_schedule_domain(dapm_pre_sequence_async, d,
1264 async_synchronize_full_domain(&async_domain);
1266 /* Power down widgets first; try to avoid amplifying pops. */
1267 dapm_seq_run(dapm, &down_list, event, false);
1269 dapm_widget_update(dapm);
1272 dapm_seq_run(dapm, &up_list, event, true);
1274 /* Run all the bias changes in parallel */
1275 list_for_each_entry(d, &dapm->card->dapm_list, list)
1276 async_schedule_domain(dapm_post_sequence_async, d,
1278 async_synchronize_full_domain(&async_domain);
1280 pop_dbg(dapm->dev, card->pop_time,
1281 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1282 pop_wait(card->pop_time);
1284 trace_snd_soc_dapm_done(card);
1289 #ifdef CONFIG_DEBUG_FS
1290 static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1292 file->private_data = inode->i_private;
1296 static ssize_t dapm_widget_power_read_file(struct file *file,
1297 char __user *user_buf,
1298 size_t count, loff_t *ppos)
1300 struct snd_soc_dapm_widget *w = file->private_data;
1304 struct snd_soc_dapm_path *p = NULL;
1306 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1310 in = is_connected_input_ep(w);
1311 dapm_clear_walk(w->dapm);
1312 out = is_connected_output_ep(w);
1313 dapm_clear_walk(w->dapm);
1315 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
1316 w->name, w->power ? "On" : "Off", in, out);
1319 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1320 " - R%d(0x%x) bit %d",
1321 w->reg, w->reg, w->shift);
1323 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1326 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1328 w->active ? "active" : "inactive");
1330 list_for_each_entry(p, &w->sources, list_sink) {
1331 if (p->connected && !p->connected(w, p->sink))
1335 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1336 " in \"%s\" \"%s\"\n",
1337 p->name ? p->name : "static",
1340 list_for_each_entry(p, &w->sinks, list_source) {
1341 if (p->connected && !p->connected(w, p->sink))
1345 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1346 " out \"%s\" \"%s\"\n",
1347 p->name ? p->name : "static",
1351 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1357 static const struct file_operations dapm_widget_power_fops = {
1358 .open = dapm_widget_power_open_file,
1359 .read = dapm_widget_power_read_file,
1360 .llseek = default_llseek,
1363 static int dapm_bias_open_file(struct inode *inode, struct file *file)
1365 file->private_data = inode->i_private;
1369 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1370 size_t count, loff_t *ppos)
1372 struct snd_soc_dapm_context *dapm = file->private_data;
1375 switch (dapm->bias_level) {
1376 case SND_SOC_BIAS_ON:
1379 case SND_SOC_BIAS_PREPARE:
1380 level = "Prepare\n";
1382 case SND_SOC_BIAS_STANDBY:
1383 level = "Standby\n";
1385 case SND_SOC_BIAS_OFF:
1390 level = "Unknown\n";
1394 return simple_read_from_buffer(user_buf, count, ppos, level,
1398 static const struct file_operations dapm_bias_fops = {
1399 .open = dapm_bias_open_file,
1400 .read = dapm_bias_read_file,
1401 .llseek = default_llseek,
1404 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1405 struct dentry *parent)
1409 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1411 if (!dapm->debugfs_dapm) {
1413 "Failed to create DAPM debugfs directory\n");
1417 d = debugfs_create_file("bias_level", 0444,
1418 dapm->debugfs_dapm, dapm,
1422 "ASoC: Failed to create bias level debugfs file\n");
1425 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1427 struct snd_soc_dapm_context *dapm = w->dapm;
1430 if (!dapm->debugfs_dapm || !w->name)
1433 d = debugfs_create_file(w->name, 0444,
1434 dapm->debugfs_dapm, w,
1435 &dapm_widget_power_fops);
1437 dev_warn(w->dapm->dev,
1438 "ASoC: Failed to create %s debugfs file\n",
1442 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1444 debugfs_remove_recursive(dapm->debugfs_dapm);
1448 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1449 struct dentry *parent)
1453 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1457 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1463 /* test and update the power status of a mux widget */
1464 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1465 struct snd_kcontrol *kcontrol, int change,
1466 int mux, struct soc_enum *e)
1468 struct snd_soc_dapm_path *path;
1471 if (widget->id != snd_soc_dapm_mux &&
1472 widget->id != snd_soc_dapm_virt_mux &&
1473 widget->id != snd_soc_dapm_value_mux)
1479 /* find dapm widget path assoc with kcontrol */
1480 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1481 if (path->kcontrol != kcontrol)
1484 if (!path->name || !e->texts[mux])
1488 /* we now need to match the string in the enum to the path */
1489 if (!(strcmp(path->name, e->texts[mux])))
1490 path->connect = 1; /* new connection */
1492 path->connect = 0; /* old connection must be powered down */
1496 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1501 /* test and update the power status of a mixer or switch widget */
1502 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1503 struct snd_kcontrol *kcontrol, int connect)
1505 struct snd_soc_dapm_path *path;
1508 if (widget->id != snd_soc_dapm_mixer &&
1509 widget->id != snd_soc_dapm_mixer_named_ctl &&
1510 widget->id != snd_soc_dapm_switch)
1513 /* find dapm widget path assoc with kcontrol */
1514 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1515 if (path->kcontrol != kcontrol)
1518 /* found, now check type */
1520 path->connect = connect;
1525 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1530 /* show dapm widget status in sys fs */
1531 static ssize_t dapm_widget_show(struct device *dev,
1532 struct device_attribute *attr, char *buf)
1534 struct snd_soc_pcm_runtime *rtd =
1535 container_of(dev, struct snd_soc_pcm_runtime, dev);
1536 struct snd_soc_codec *codec =rtd->codec;
1537 struct snd_soc_dapm_widget *w;
1539 char *state = "not set";
1541 list_for_each_entry(w, &codec->card->widgets, list) {
1542 if (w->dapm != &codec->dapm)
1545 /* only display widgets that burnm power */
1547 case snd_soc_dapm_hp:
1548 case snd_soc_dapm_mic:
1549 case snd_soc_dapm_spk:
1550 case snd_soc_dapm_line:
1551 case snd_soc_dapm_micbias:
1552 case snd_soc_dapm_dac:
1553 case snd_soc_dapm_adc:
1554 case snd_soc_dapm_pga:
1555 case snd_soc_dapm_out_drv:
1556 case snd_soc_dapm_mixer:
1557 case snd_soc_dapm_mixer_named_ctl:
1558 case snd_soc_dapm_supply:
1560 count += sprintf(buf + count, "%s: %s\n",
1561 w->name, w->power ? "On":"Off");
1568 switch (codec->dapm.bias_level) {
1569 case SND_SOC_BIAS_ON:
1572 case SND_SOC_BIAS_PREPARE:
1575 case SND_SOC_BIAS_STANDBY:
1578 case SND_SOC_BIAS_OFF:
1582 count += sprintf(buf + count, "PM State: %s\n", state);
1587 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1589 int snd_soc_dapm_sys_add(struct device *dev)
1591 return device_create_file(dev, &dev_attr_dapm_widget);
1594 static void snd_soc_dapm_sys_remove(struct device *dev)
1596 device_remove_file(dev, &dev_attr_dapm_widget);
1599 /* free all dapm widgets and resources */
1600 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1602 struct snd_soc_dapm_widget *w, *next_w;
1603 struct snd_soc_dapm_path *p, *next_p;
1605 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1606 if (w->dapm != dapm)
1610 * remove source and sink paths associated to this widget.
1611 * While removing the path, remove reference to it from both
1612 * source and sink widgets so that path is removed only once.
1614 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1615 list_del(&p->list_sink);
1616 list_del(&p->list_source);
1618 kfree(p->long_name);
1621 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1622 list_del(&p->list_sink);
1623 list_del(&p->list_source);
1625 kfree(p->long_name);
1628 kfree(w->kcontrols);
1634 static struct snd_soc_dapm_widget *dapm_find_widget(
1635 struct snd_soc_dapm_context *dapm, const char *pin,
1636 bool search_other_contexts)
1638 struct snd_soc_dapm_widget *w;
1639 struct snd_soc_dapm_widget *fallback = NULL;
1641 list_for_each_entry(w, &dapm->card->widgets, list) {
1642 if (!strcmp(w->name, pin)) {
1643 if (w->dapm == dapm)
1650 if (search_other_contexts)
1656 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1657 const char *pin, int status)
1659 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
1662 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1666 w->connected = status;
1674 * snd_soc_dapm_sync - scan and power dapm paths
1675 * @dapm: DAPM context
1677 * Walks all dapm audio paths and powers widgets according to their
1678 * stream or path usage.
1680 * Returns 0 for success.
1682 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1684 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1686 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1688 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1689 const struct snd_soc_dapm_route *route)
1691 struct snd_soc_dapm_path *path;
1692 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1693 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1695 const char *control = route->control;
1697 char prefixed_sink[80];
1698 char prefixed_source[80];
1701 if (dapm->codec && dapm->codec->name_prefix) {
1702 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1703 dapm->codec->name_prefix, route->sink);
1704 sink = prefixed_sink;
1705 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1706 dapm->codec->name_prefix, route->source);
1707 source = prefixed_source;
1710 source = route->source;
1714 * find src and dest widgets over all widgets but favor a widget from
1715 * current DAPM context
1717 list_for_each_entry(w, &dapm->card->widgets, list) {
1718 if (!wsink && !(strcmp(w->name, sink))) {
1720 if (w->dapm == dapm)
1724 if (!wsource && !(strcmp(w->name, source))) {
1726 if (w->dapm == dapm)
1730 /* use widget from another DAPM context if not found from this */
1736 if (wsource == NULL || wsink == NULL)
1739 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1743 path->source = wsource;
1745 path->connected = route->connected;
1746 INIT_LIST_HEAD(&path->list);
1747 INIT_LIST_HEAD(&path->list_source);
1748 INIT_LIST_HEAD(&path->list_sink);
1750 /* check for external widgets */
1751 if (wsink->id == snd_soc_dapm_input) {
1752 if (wsource->id == snd_soc_dapm_micbias ||
1753 wsource->id == snd_soc_dapm_mic ||
1754 wsource->id == snd_soc_dapm_line ||
1755 wsource->id == snd_soc_dapm_output)
1758 if (wsource->id == snd_soc_dapm_output) {
1759 if (wsink->id == snd_soc_dapm_spk ||
1760 wsink->id == snd_soc_dapm_hp ||
1761 wsink->id == snd_soc_dapm_line ||
1762 wsink->id == snd_soc_dapm_input)
1766 /* connect static paths */
1767 if (control == NULL) {
1768 list_add(&path->list, &dapm->card->paths);
1769 list_add(&path->list_sink, &wsink->sources);
1770 list_add(&path->list_source, &wsource->sinks);
1775 /* connect dynamic paths */
1776 switch (wsink->id) {
1777 case snd_soc_dapm_adc:
1778 case snd_soc_dapm_dac:
1779 case snd_soc_dapm_pga:
1780 case snd_soc_dapm_out_drv:
1781 case snd_soc_dapm_input:
1782 case snd_soc_dapm_output:
1783 case snd_soc_dapm_micbias:
1784 case snd_soc_dapm_vmid:
1785 case snd_soc_dapm_pre:
1786 case snd_soc_dapm_post:
1787 case snd_soc_dapm_supply:
1788 case snd_soc_dapm_aif_in:
1789 case snd_soc_dapm_aif_out:
1790 list_add(&path->list, &dapm->card->paths);
1791 list_add(&path->list_sink, &wsink->sources);
1792 list_add(&path->list_source, &wsource->sinks);
1795 case snd_soc_dapm_mux:
1796 case snd_soc_dapm_virt_mux:
1797 case snd_soc_dapm_value_mux:
1798 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1799 &wsink->kcontrol_news[0]);
1803 case snd_soc_dapm_switch:
1804 case snd_soc_dapm_mixer:
1805 case snd_soc_dapm_mixer_named_ctl:
1806 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
1810 case snd_soc_dapm_hp:
1811 case snd_soc_dapm_mic:
1812 case snd_soc_dapm_line:
1813 case snd_soc_dapm_spk:
1814 list_add(&path->list, &dapm->card->paths);
1815 list_add(&path->list_sink, &wsink->sources);
1816 list_add(&path->list_source, &wsource->sinks);
1823 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
1824 source, control, sink);
1830 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1831 * @dapm: DAPM context
1832 * @route: audio routes
1833 * @num: number of routes
1835 * Connects 2 dapm widgets together via a named audio path. The sink is
1836 * the widget receiving the audio signal, whilst the source is the sender
1837 * of the audio signal.
1839 * Returns 0 for success else error. On error all resources can be freed
1840 * with a call to snd_soc_card_free().
1842 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1843 const struct snd_soc_dapm_route *route, int num)
1847 for (i = 0; i < num; i++) {
1848 ret = snd_soc_dapm_add_route(dapm, route);
1850 dev_err(dapm->dev, "Failed to add route %s->%s\n",
1851 route->source, route->sink);
1859 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1861 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
1862 const struct snd_soc_dapm_route *route)
1864 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
1867 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
1870 struct snd_soc_dapm_path *path;
1874 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
1880 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
1885 if (route->control || route->connected)
1886 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
1887 route->source, route->sink);
1889 list_for_each_entry(path, &source->sinks, list_source) {
1890 if (path->sink == sink) {
1897 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
1898 route->source, route->sink);
1900 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
1901 count, route->source, route->sink);
1907 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
1908 * @dapm: DAPM context
1909 * @route: audio routes
1910 * @num: number of routes
1912 * Mark existing routes matching those specified in the passed array
1913 * as being weak, meaning that they are ignored for the purpose of
1914 * power decisions. The main intended use case is for sidetone paths
1915 * which couple audio between other independent paths if they are both
1916 * active in order to make the combination work better at the user
1917 * level but which aren't intended to be "used".
1919 * Note that CODEC drivers should not use this as sidetone type paths
1920 * can frequently also be used as bypass paths.
1922 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
1923 const struct snd_soc_dapm_route *route, int num)
1928 for (i = 0; i < num; i++) {
1929 err = snd_soc_dapm_weak_route(dapm, route);
1937 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
1940 * snd_soc_dapm_new_widgets - add new dapm widgets
1941 * @dapm: DAPM context
1943 * Checks the codec for any new dapm widgets and creates them if found.
1945 * Returns 0 for success.
1947 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
1949 struct snd_soc_dapm_widget *w;
1952 list_for_each_entry(w, &dapm->card->widgets, list)
1957 if (w->num_kcontrols) {
1958 w->kcontrols = kzalloc(w->num_kcontrols *
1959 sizeof(struct snd_kcontrol *),
1966 case snd_soc_dapm_switch:
1967 case snd_soc_dapm_mixer:
1968 case snd_soc_dapm_mixer_named_ctl:
1969 w->power_check = dapm_generic_check_power;
1972 case snd_soc_dapm_mux:
1973 case snd_soc_dapm_virt_mux:
1974 case snd_soc_dapm_value_mux:
1975 w->power_check = dapm_generic_check_power;
1978 case snd_soc_dapm_adc:
1979 case snd_soc_dapm_aif_out:
1980 w->power_check = dapm_adc_check_power;
1982 case snd_soc_dapm_dac:
1983 case snd_soc_dapm_aif_in:
1984 w->power_check = dapm_dac_check_power;
1986 case snd_soc_dapm_pga:
1987 case snd_soc_dapm_out_drv:
1988 w->power_check = dapm_generic_check_power;
1991 case snd_soc_dapm_input:
1992 case snd_soc_dapm_output:
1993 case snd_soc_dapm_micbias:
1994 case snd_soc_dapm_spk:
1995 case snd_soc_dapm_hp:
1996 case snd_soc_dapm_mic:
1997 case snd_soc_dapm_line:
1998 w->power_check = dapm_generic_check_power;
2000 case snd_soc_dapm_supply:
2001 w->power_check = dapm_supply_check_power;
2002 case snd_soc_dapm_vmid:
2003 case snd_soc_dapm_pre:
2004 case snd_soc_dapm_post:
2008 /* Read the initial power state from the device */
2010 val = soc_widget_read(w, w->reg);
2011 val &= 1 << w->shift;
2021 dapm_debugfs_add_widget(w);
2024 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2027 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2030 * snd_soc_dapm_get_volsw - dapm mixer get callback
2031 * @kcontrol: mixer control
2032 * @ucontrol: control element information
2034 * Callback to get the value of a dapm mixer control.
2036 * Returns 0 for success.
2038 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2039 struct snd_ctl_elem_value *ucontrol)
2041 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2042 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2043 struct soc_mixer_control *mc =
2044 (struct soc_mixer_control *)kcontrol->private_value;
2045 unsigned int reg = mc->reg;
2046 unsigned int shift = mc->shift;
2047 unsigned int rshift = mc->rshift;
2049 unsigned int invert = mc->invert;
2050 unsigned int mask = (1 << fls(max)) - 1;
2052 ucontrol->value.integer.value[0] =
2053 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2054 if (shift != rshift)
2055 ucontrol->value.integer.value[1] =
2056 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2058 ucontrol->value.integer.value[0] =
2059 max - ucontrol->value.integer.value[0];
2060 if (shift != rshift)
2061 ucontrol->value.integer.value[1] =
2062 max - ucontrol->value.integer.value[1];
2067 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2070 * snd_soc_dapm_put_volsw - dapm mixer set callback
2071 * @kcontrol: mixer control
2072 * @ucontrol: control element information
2074 * Callback to set the value of a dapm mixer control.
2076 * Returns 0 for success.
2078 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2079 struct snd_ctl_elem_value *ucontrol)
2081 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2082 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2083 struct snd_soc_codec *codec = widget->codec;
2084 struct soc_mixer_control *mc =
2085 (struct soc_mixer_control *)kcontrol->private_value;
2086 unsigned int reg = mc->reg;
2087 unsigned int shift = mc->shift;
2089 unsigned int mask = (1 << fls(max)) - 1;
2090 unsigned int invert = mc->invert;
2092 int connect, change;
2093 struct snd_soc_dapm_update update;
2096 val = (ucontrol->value.integer.value[0] & mask);
2100 mask = mask << shift;
2104 /* new connection */
2105 connect = invert ? 0 : 1;
2107 /* old connection must be powered down */
2108 connect = invert ? 1 : 0;
2110 mutex_lock(&codec->mutex);
2112 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2114 for (wi = 0; wi < wlist->num_widgets; wi++) {
2115 widget = wlist->widgets[wi];
2117 widget->value = val;
2119 update.kcontrol = kcontrol;
2120 update.widget = widget;
2124 widget->dapm->update = &update;
2126 dapm_mixer_update_power(widget, kcontrol, connect);
2128 widget->dapm->update = NULL;
2132 mutex_unlock(&codec->mutex);
2135 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2138 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2139 * @kcontrol: mixer control
2140 * @ucontrol: control element information
2142 * Callback to get the value of a dapm enumerated double mixer control.
2144 * Returns 0 for success.
2146 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2147 struct snd_ctl_elem_value *ucontrol)
2149 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2150 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2151 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2152 unsigned int val, bitmask;
2154 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2156 val = snd_soc_read(widget->codec, e->reg);
2157 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2158 if (e->shift_l != e->shift_r)
2159 ucontrol->value.enumerated.item[1] =
2160 (val >> e->shift_r) & (bitmask - 1);
2164 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2167 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2168 * @kcontrol: mixer control
2169 * @ucontrol: control element information
2171 * Callback to set the value of a dapm enumerated double mixer control.
2173 * Returns 0 for success.
2175 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2176 struct snd_ctl_elem_value *ucontrol)
2178 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2179 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2180 struct snd_soc_codec *codec = widget->codec;
2181 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2182 unsigned int val, mux, change;
2183 unsigned int mask, bitmask;
2184 struct snd_soc_dapm_update update;
2187 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2189 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2191 mux = ucontrol->value.enumerated.item[0];
2192 val = mux << e->shift_l;
2193 mask = (bitmask - 1) << e->shift_l;
2194 if (e->shift_l != e->shift_r) {
2195 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2197 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2198 mask |= (bitmask - 1) << e->shift_r;
2201 mutex_lock(&codec->mutex);
2203 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2205 for (wi = 0; wi < wlist->num_widgets; wi++) {
2206 widget = wlist->widgets[wi];
2208 widget->value = val;
2210 update.kcontrol = kcontrol;
2211 update.widget = widget;
2212 update.reg = e->reg;
2215 widget->dapm->update = &update;
2217 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2219 widget->dapm->update = NULL;
2223 mutex_unlock(&codec->mutex);
2226 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2229 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2230 * @kcontrol: mixer control
2231 * @ucontrol: control element information
2233 * Returns 0 for success.
2235 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2236 struct snd_ctl_elem_value *ucontrol)
2238 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2239 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2241 ucontrol->value.enumerated.item[0] = widget->value;
2245 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2248 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2249 * @kcontrol: mixer control
2250 * @ucontrol: control element information
2252 * Returns 0 for success.
2254 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2255 struct snd_ctl_elem_value *ucontrol)
2257 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2258 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2259 struct snd_soc_codec *codec = widget->codec;
2260 struct soc_enum *e =
2261 (struct soc_enum *)kcontrol->private_value;
2266 if (ucontrol->value.enumerated.item[0] >= e->max)
2269 mutex_lock(&codec->mutex);
2271 change = widget->value != ucontrol->value.enumerated.item[0];
2273 for (wi = 0; wi < wlist->num_widgets; wi++) {
2274 widget = wlist->widgets[wi];
2276 widget->value = ucontrol->value.enumerated.item[0];
2278 dapm_mux_update_power(widget, kcontrol, change,
2283 mutex_unlock(&codec->mutex);
2286 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2289 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2291 * @kcontrol: mixer control
2292 * @ucontrol: control element information
2294 * Callback to get the value of a dapm semi enumerated double mixer control.
2296 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2297 * used for handling bitfield coded enumeration for example.
2299 * Returns 0 for success.
2301 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2302 struct snd_ctl_elem_value *ucontrol)
2304 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2305 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2306 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2307 unsigned int reg_val, val, mux;
2309 reg_val = snd_soc_read(widget->codec, e->reg);
2310 val = (reg_val >> e->shift_l) & e->mask;
2311 for (mux = 0; mux < e->max; mux++) {
2312 if (val == e->values[mux])
2315 ucontrol->value.enumerated.item[0] = mux;
2316 if (e->shift_l != e->shift_r) {
2317 val = (reg_val >> e->shift_r) & e->mask;
2318 for (mux = 0; mux < e->max; mux++) {
2319 if (val == e->values[mux])
2322 ucontrol->value.enumerated.item[1] = mux;
2327 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2330 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2332 * @kcontrol: mixer control
2333 * @ucontrol: control element information
2335 * Callback to set the value of a dapm semi enumerated double mixer control.
2337 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2338 * used for handling bitfield coded enumeration for example.
2340 * Returns 0 for success.
2342 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2343 struct snd_ctl_elem_value *ucontrol)
2345 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2346 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2347 struct snd_soc_codec *codec = widget->codec;
2348 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2349 unsigned int val, mux, change;
2351 struct snd_soc_dapm_update update;
2354 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2356 mux = ucontrol->value.enumerated.item[0];
2357 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2358 mask = e->mask << e->shift_l;
2359 if (e->shift_l != e->shift_r) {
2360 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2362 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2363 mask |= e->mask << e->shift_r;
2366 mutex_lock(&codec->mutex);
2368 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2370 for (wi = 0; wi < wlist->num_widgets; wi++) {
2371 widget = wlist->widgets[wi];
2373 widget->value = val;
2375 update.kcontrol = kcontrol;
2376 update.widget = widget;
2377 update.reg = e->reg;
2380 widget->dapm->update = &update;
2382 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2384 widget->dapm->update = NULL;
2388 mutex_unlock(&codec->mutex);
2391 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2394 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2396 * @kcontrol: mixer control
2397 * @uinfo: control element information
2399 * Callback to provide information about a pin switch control.
2401 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2402 struct snd_ctl_elem_info *uinfo)
2404 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2406 uinfo->value.integer.min = 0;
2407 uinfo->value.integer.max = 1;
2411 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2414 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2416 * @kcontrol: mixer control
2419 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2420 struct snd_ctl_elem_value *ucontrol)
2422 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2423 const char *pin = (const char *)kcontrol->private_value;
2425 mutex_lock(&codec->mutex);
2427 ucontrol->value.integer.value[0] =
2428 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
2430 mutex_unlock(&codec->mutex);
2434 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2437 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2439 * @kcontrol: mixer control
2442 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2443 struct snd_ctl_elem_value *ucontrol)
2445 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2446 const char *pin = (const char *)kcontrol->private_value;
2448 mutex_lock(&codec->mutex);
2450 if (ucontrol->value.integer.value[0])
2451 snd_soc_dapm_enable_pin(&codec->dapm, pin);
2453 snd_soc_dapm_disable_pin(&codec->dapm, pin);
2455 snd_soc_dapm_sync(&codec->dapm);
2457 mutex_unlock(&codec->mutex);
2461 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2464 * snd_soc_dapm_new_control - create new dapm control
2465 * @dapm: DAPM context
2466 * @widget: widget template
2468 * Creates a new dapm control based upon the template.
2470 * Returns 0 for success else error.
2472 int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2473 const struct snd_soc_dapm_widget *widget)
2475 struct snd_soc_dapm_widget *w;
2478 if ((w = dapm_cnew_widget(widget)) == NULL)
2481 name_len = strlen(widget->name) + 1;
2482 if (dapm->codec && dapm->codec->name_prefix)
2483 name_len += 1 + strlen(dapm->codec->name_prefix);
2484 w->name = kmalloc(name_len, GFP_KERNEL);
2485 if (w->name == NULL) {
2489 if (dapm->codec && dapm->codec->name_prefix)
2490 snprintf(w->name, name_len, "%s %s",
2491 dapm->codec->name_prefix, widget->name);
2493 snprintf(w->name, name_len, "%s", widget->name);
2497 w->codec = dapm->codec;
2498 INIT_LIST_HEAD(&w->sources);
2499 INIT_LIST_HEAD(&w->sinks);
2500 INIT_LIST_HEAD(&w->list);
2501 list_add(&w->list, &dapm->card->widgets);
2503 /* machine layer set ups unconnected pins and insertions */
2507 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
2510 * snd_soc_dapm_new_controls - create new dapm controls
2511 * @dapm: DAPM context
2512 * @widget: widget array
2513 * @num: number of widgets
2515 * Creates new DAPM controls based upon the templates.
2517 * Returns 0 for success else error.
2519 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2520 const struct snd_soc_dapm_widget *widget,
2525 for (i = 0; i < num; i++) {
2526 ret = snd_soc_dapm_new_control(dapm, widget);
2529 "ASoC: Failed to create DAPM control %s: %d\n",
2537 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2539 static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2540 const char *stream, int event)
2542 struct snd_soc_dapm_widget *w;
2544 list_for_each_entry(w, &dapm->card->widgets, list)
2546 if (!w->sname || w->dapm != dapm)
2548 dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2549 w->name, w->sname, stream, event);
2550 if (strstr(w->sname, stream)) {
2552 case SND_SOC_DAPM_STREAM_START:
2555 case SND_SOC_DAPM_STREAM_STOP:
2558 case SND_SOC_DAPM_STREAM_SUSPEND:
2559 case SND_SOC_DAPM_STREAM_RESUME:
2560 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
2561 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2567 dapm_power_widgets(dapm, event);
2571 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2572 * @rtd: PCM runtime data
2573 * @stream: stream name
2574 * @event: stream event
2576 * Sends a stream event to the dapm core. The core then makes any
2577 * necessary widget power changes.
2579 * Returns 0 for success else error.
2581 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2582 const char *stream, int event)
2584 struct snd_soc_codec *codec = rtd->codec;
2589 mutex_lock(&codec->mutex);
2590 soc_dapm_stream_event(&codec->dapm, stream, event);
2591 mutex_unlock(&codec->mutex);
2596 * snd_soc_dapm_enable_pin - enable pin.
2597 * @dapm: DAPM context
2600 * Enables input/output pin and its parents or children widgets iff there is
2601 * a valid audio route and active audio stream.
2602 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2603 * do any widget power switching.
2605 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2607 return snd_soc_dapm_set_pin(dapm, pin, 1);
2609 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2612 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2613 * @dapm: DAPM context
2616 * Enables input/output pin regardless of any other state. This is
2617 * intended for use with microphone bias supplies used in microphone
2620 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2621 * do any widget power switching.
2623 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2626 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2629 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2633 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
2639 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2642 * snd_soc_dapm_disable_pin - disable pin.
2643 * @dapm: DAPM context
2646 * Disables input/output pin and its parents or children widgets.
2647 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2648 * do any widget power switching.
2650 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2653 return snd_soc_dapm_set_pin(dapm, pin, 0);
2655 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2658 * snd_soc_dapm_nc_pin - permanently disable pin.
2659 * @dapm: DAPM context
2662 * Marks the specified pin as being not connected, disabling it along
2663 * any parent or child widgets. At present this is identical to
2664 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2665 * additional things such as disabling controls which only affect
2666 * paths through the pin.
2668 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2669 * do any widget power switching.
2671 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2673 return snd_soc_dapm_set_pin(dapm, pin, 0);
2675 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2678 * snd_soc_dapm_get_pin_status - get audio pin status
2679 * @dapm: DAPM context
2680 * @pin: audio signal pin endpoint (or start point)
2682 * Get audio pin status - connected or disconnected.
2684 * Returns 1 for connected otherwise 0.
2686 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2689 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2692 return w->connected;
2696 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2699 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2700 * @dapm: DAPM context
2701 * @pin: audio signal pin endpoint (or start point)
2703 * Mark the given endpoint or pin as ignoring suspend. When the
2704 * system is disabled a path between two endpoints flagged as ignoring
2705 * suspend will not be disabled. The path must already be enabled via
2706 * normal means at suspend time, it will not be turned on if it was not
2709 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2712 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
2715 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2719 w->ignore_suspend = 1;
2723 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2726 * snd_soc_dapm_free - free dapm resources
2729 * Free all dapm widgets and resources.
2731 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2733 snd_soc_dapm_sys_remove(dapm->dev);
2734 dapm_debugfs_cleanup(dapm);
2735 dapm_free_widgets(dapm);
2736 list_del(&dapm->list);
2738 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2740 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2742 struct snd_soc_dapm_widget *w;
2743 LIST_HEAD(down_list);
2746 list_for_each_entry(w, &dapm->card->widgets, list) {
2747 if (w->dapm != dapm)
2750 dapm_seq_insert(w, &down_list, false);
2756 /* If there were no widgets to power down we're already in
2760 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
2761 dapm_seq_run(dapm, &down_list, 0, false);
2762 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
2767 * snd_soc_dapm_shutdown - callback for system shutdown
2769 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2771 struct snd_soc_codec *codec;
2773 list_for_each_entry(codec, &card->codec_dev_list, list) {
2774 soc_dapm_shutdown_codec(&codec->dapm);
2775 snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
2779 /* Module information */
2780 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2781 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2782 MODULE_LICENSE("GPL");