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 pop_dbg(dapm->dev, card->pop_time,
922 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
923 value, mask, reg, card->pop_time);
924 pop_wait(card->pop_time);
925 soc_widget_update_bits(w, reg, mask, value);
928 list_for_each_entry(w, pending, power_list) {
929 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
930 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
934 /* Apply a DAPM power sequence.
936 * We walk over a pre-sorted list of widgets to apply power to. In
937 * order to minimise the number of writes to the device required
938 * multiple widgets will be updated in a single write where possible.
939 * Currently anything that requires more than a single write is not
942 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
943 struct list_head *list, int event, bool power_up)
945 struct snd_soc_dapm_widget *w, *n;
949 int cur_reg = SND_SOC_NOPM;
950 struct snd_soc_dapm_context *cur_dapm = NULL;
957 sort = dapm_down_seq;
959 list_for_each_entry_safe(w, n, list, power_list) {
962 /* Do we need to apply any queued changes? */
963 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
964 w->dapm != cur_dapm || w->subseq != cur_subseq) {
965 if (!list_empty(&pending))
966 dapm_seq_run_coalesced(cur_dapm, &pending);
968 if (cur_dapm && cur_dapm->seq_notifier) {
969 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
970 if (sort[i] == cur_sort)
971 cur_dapm->seq_notifier(cur_dapm,
976 INIT_LIST_HEAD(&pending);
979 cur_reg = SND_SOC_NOPM;
984 case snd_soc_dapm_pre:
986 list_for_each_entry_safe_continue(w, n, list,
989 if (event == SND_SOC_DAPM_STREAM_START)
991 NULL, SND_SOC_DAPM_PRE_PMU);
992 else if (event == SND_SOC_DAPM_STREAM_STOP)
994 NULL, SND_SOC_DAPM_PRE_PMD);
997 case snd_soc_dapm_post:
999 list_for_each_entry_safe_continue(w, n, list,
1002 if (event == SND_SOC_DAPM_STREAM_START)
1004 NULL, SND_SOC_DAPM_POST_PMU);
1005 else if (event == SND_SOC_DAPM_STREAM_STOP)
1007 NULL, SND_SOC_DAPM_POST_PMD);
1011 /* Queue it up for application */
1012 cur_sort = sort[w->id];
1013 cur_subseq = w->subseq;
1016 list_move(&w->power_list, &pending);
1021 dev_err(w->dapm->dev,
1022 "Failed to apply widget power: %d\n", ret);
1025 if (!list_empty(&pending))
1026 dapm_seq_run_coalesced(cur_dapm, &pending);
1028 if (cur_dapm && cur_dapm->seq_notifier) {
1029 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1030 if (sort[i] == cur_sort)
1031 cur_dapm->seq_notifier(cur_dapm,
1036 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1038 struct snd_soc_dapm_update *update = dapm->update;
1039 struct snd_soc_dapm_widget *w;
1048 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1049 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1051 pr_err("%s DAPM pre-event failed: %d\n",
1055 ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
1058 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1061 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1062 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1064 pr_err("%s DAPM post-event failed: %d\n",
1069 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1070 * they're changing state.
1072 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1074 struct snd_soc_dapm_context *d = data;
1077 /* If we're off and we're not supposed to be go into STANDBY */
1078 if (d->bias_level == SND_SOC_BIAS_OFF &&
1079 d->target_bias_level != SND_SOC_BIAS_OFF) {
1080 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1083 "Failed to turn on bias: %d\n", ret);
1086 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1087 if (d->bias_level != d->target_bias_level) {
1088 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1091 "Failed to prepare bias: %d\n", ret);
1095 /* Async callback run prior to DAPM sequences - brings to their final
1098 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1100 struct snd_soc_dapm_context *d = data;
1103 /* If we just powered the last thing off drop to standby bias */
1104 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1105 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1106 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1107 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1109 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1113 /* If we're in standby and can support bias off then do that */
1114 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1115 d->target_bias_level == SND_SOC_BIAS_OFF) {
1116 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1118 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1121 /* If we just powered up then move to active bias */
1122 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1123 d->target_bias_level == SND_SOC_BIAS_ON) {
1124 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1126 dev_err(d->dev, "Failed to apply active bias: %d\n",
1132 * Scan each dapm widget for complete audio path.
1133 * A complete path is a route that has valid endpoints i.e.:-
1135 * o DAC to output pin.
1136 * o Input Pin to ADC.
1137 * o Input pin to Output pin (bypass, sidetone)
1138 * o DAC to ADC (loopback).
1140 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1142 struct snd_soc_card *card = dapm->card;
1143 struct snd_soc_dapm_widget *w;
1144 struct snd_soc_dapm_context *d;
1146 LIST_HEAD(down_list);
1147 LIST_HEAD(async_domain);
1148 enum snd_soc_bias_level bias;
1151 trace_snd_soc_dapm_start(card);
1153 list_for_each_entry(d, &card->dapm_list, list) {
1154 if (d->n_widgets || d->codec == NULL) {
1155 if (d->idle_bias_off)
1156 d->target_bias_level = SND_SOC_BIAS_OFF;
1158 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1162 /* Check which widgets we need to power and store them in
1163 * lists indicating if they should be powered up or down.
1165 list_for_each_entry(w, &card->widgets, list) {
1167 case snd_soc_dapm_pre:
1168 dapm_seq_insert(w, &down_list, false);
1170 case snd_soc_dapm_post:
1171 dapm_seq_insert(w, &up_list, true);
1175 if (!w->power_check)
1179 power = w->power_check(w);
1186 /* Supplies and micbiases only bring
1187 * the context up to STANDBY as unless
1188 * something else is active and
1189 * passing audio they generally don't
1190 * require full power.
1193 case snd_soc_dapm_supply:
1194 case snd_soc_dapm_micbias:
1195 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1196 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1199 d->target_bias_level = SND_SOC_BIAS_ON;
1204 if (w->power == power)
1207 trace_snd_soc_dapm_widget_power(w, power);
1210 dapm_seq_insert(w, &up_list, true);
1212 dapm_seq_insert(w, &down_list, false);
1219 /* If there are no DAPM widgets then try to figure out power from the
1222 if (!dapm->n_widgets) {
1224 case SND_SOC_DAPM_STREAM_START:
1225 case SND_SOC_DAPM_STREAM_RESUME:
1226 dapm->target_bias_level = SND_SOC_BIAS_ON;
1228 case SND_SOC_DAPM_STREAM_STOP:
1229 if (dapm->codec->active)
1230 dapm->target_bias_level = SND_SOC_BIAS_ON;
1232 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1234 case SND_SOC_DAPM_STREAM_SUSPEND:
1235 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1237 case SND_SOC_DAPM_STREAM_NOP:
1238 dapm->target_bias_level = dapm->bias_level;
1245 /* Force all contexts in the card to the same bias state */
1246 bias = SND_SOC_BIAS_OFF;
1247 list_for_each_entry(d, &card->dapm_list, list)
1248 if (d->target_bias_level > bias)
1249 bias = d->target_bias_level;
1250 list_for_each_entry(d, &card->dapm_list, list)
1251 d->target_bias_level = bias;
1254 /* Run all the bias changes in parallel */
1255 list_for_each_entry(d, &dapm->card->dapm_list, list)
1256 async_schedule_domain(dapm_pre_sequence_async, d,
1258 async_synchronize_full_domain(&async_domain);
1260 /* Power down widgets first; try to avoid amplifying pops. */
1261 dapm_seq_run(dapm, &down_list, event, false);
1263 dapm_widget_update(dapm);
1266 dapm_seq_run(dapm, &up_list, event, true);
1268 /* Run all the bias changes in parallel */
1269 list_for_each_entry(d, &dapm->card->dapm_list, list)
1270 async_schedule_domain(dapm_post_sequence_async, d,
1272 async_synchronize_full_domain(&async_domain);
1274 pop_dbg(dapm->dev, card->pop_time,
1275 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1276 pop_wait(card->pop_time);
1278 trace_snd_soc_dapm_done(card);
1283 #ifdef CONFIG_DEBUG_FS
1284 static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1286 file->private_data = inode->i_private;
1290 static ssize_t dapm_widget_power_read_file(struct file *file,
1291 char __user *user_buf,
1292 size_t count, loff_t *ppos)
1294 struct snd_soc_dapm_widget *w = file->private_data;
1298 struct snd_soc_dapm_path *p = NULL;
1300 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1304 in = is_connected_input_ep(w);
1305 dapm_clear_walk(w->dapm);
1306 out = is_connected_output_ep(w);
1307 dapm_clear_walk(w->dapm);
1309 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
1310 w->name, w->power ? "On" : "Off", in, out);
1313 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1314 " - R%d(0x%x) bit %d",
1315 w->reg, w->reg, w->shift);
1317 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1320 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1322 w->active ? "active" : "inactive");
1324 list_for_each_entry(p, &w->sources, list_sink) {
1325 if (p->connected && !p->connected(w, p->sink))
1329 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1330 " in \"%s\" \"%s\"\n",
1331 p->name ? p->name : "static",
1334 list_for_each_entry(p, &w->sinks, list_source) {
1335 if (p->connected && !p->connected(w, p->sink))
1339 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1340 " out \"%s\" \"%s\"\n",
1341 p->name ? p->name : "static",
1345 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1351 static const struct file_operations dapm_widget_power_fops = {
1352 .open = dapm_widget_power_open_file,
1353 .read = dapm_widget_power_read_file,
1354 .llseek = default_llseek,
1357 static int dapm_bias_open_file(struct inode *inode, struct file *file)
1359 file->private_data = inode->i_private;
1363 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1364 size_t count, loff_t *ppos)
1366 struct snd_soc_dapm_context *dapm = file->private_data;
1369 switch (dapm->bias_level) {
1370 case SND_SOC_BIAS_ON:
1373 case SND_SOC_BIAS_PREPARE:
1374 level = "Prepare\n";
1376 case SND_SOC_BIAS_STANDBY:
1377 level = "Standby\n";
1379 case SND_SOC_BIAS_OFF:
1384 level = "Unknown\n";
1388 return simple_read_from_buffer(user_buf, count, ppos, level,
1392 static const struct file_operations dapm_bias_fops = {
1393 .open = dapm_bias_open_file,
1394 .read = dapm_bias_read_file,
1395 .llseek = default_llseek,
1398 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1399 struct dentry *parent)
1403 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1405 if (!dapm->debugfs_dapm) {
1407 "Failed to create DAPM debugfs directory\n");
1411 d = debugfs_create_file("bias_level", 0444,
1412 dapm->debugfs_dapm, dapm,
1416 "ASoC: Failed to create bias level debugfs file\n");
1419 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1421 struct snd_soc_dapm_context *dapm = w->dapm;
1424 if (!dapm->debugfs_dapm || !w->name)
1427 d = debugfs_create_file(w->name, 0444,
1428 dapm->debugfs_dapm, w,
1429 &dapm_widget_power_fops);
1431 dev_warn(w->dapm->dev,
1432 "ASoC: Failed to create %s debugfs file\n",
1436 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1438 debugfs_remove_recursive(dapm->debugfs_dapm);
1442 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1443 struct dentry *parent)
1447 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1451 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1457 /* test and update the power status of a mux widget */
1458 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1459 struct snd_kcontrol *kcontrol, int change,
1460 int mux, struct soc_enum *e)
1462 struct snd_soc_dapm_path *path;
1465 if (widget->id != snd_soc_dapm_mux &&
1466 widget->id != snd_soc_dapm_virt_mux &&
1467 widget->id != snd_soc_dapm_value_mux)
1473 /* find dapm widget path assoc with kcontrol */
1474 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1475 if (path->kcontrol != kcontrol)
1478 if (!path->name || !e->texts[mux])
1482 /* we now need to match the string in the enum to the path */
1483 if (!(strcmp(path->name, e->texts[mux])))
1484 path->connect = 1; /* new connection */
1486 path->connect = 0; /* old connection must be powered down */
1490 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1495 /* test and update the power status of a mixer or switch widget */
1496 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1497 struct snd_kcontrol *kcontrol, int connect)
1499 struct snd_soc_dapm_path *path;
1502 if (widget->id != snd_soc_dapm_mixer &&
1503 widget->id != snd_soc_dapm_mixer_named_ctl &&
1504 widget->id != snd_soc_dapm_switch)
1507 /* find dapm widget path assoc with kcontrol */
1508 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1509 if (path->kcontrol != kcontrol)
1512 /* found, now check type */
1514 path->connect = connect;
1519 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1524 /* show dapm widget status in sys fs */
1525 static ssize_t dapm_widget_show(struct device *dev,
1526 struct device_attribute *attr, char *buf)
1528 struct snd_soc_pcm_runtime *rtd =
1529 container_of(dev, struct snd_soc_pcm_runtime, dev);
1530 struct snd_soc_codec *codec =rtd->codec;
1531 struct snd_soc_dapm_widget *w;
1533 char *state = "not set";
1535 list_for_each_entry(w, &codec->card->widgets, list) {
1536 if (w->dapm != &codec->dapm)
1539 /* only display widgets that burnm power */
1541 case snd_soc_dapm_hp:
1542 case snd_soc_dapm_mic:
1543 case snd_soc_dapm_spk:
1544 case snd_soc_dapm_line:
1545 case snd_soc_dapm_micbias:
1546 case snd_soc_dapm_dac:
1547 case snd_soc_dapm_adc:
1548 case snd_soc_dapm_pga:
1549 case snd_soc_dapm_out_drv:
1550 case snd_soc_dapm_mixer:
1551 case snd_soc_dapm_mixer_named_ctl:
1552 case snd_soc_dapm_supply:
1554 count += sprintf(buf + count, "%s: %s\n",
1555 w->name, w->power ? "On":"Off");
1562 switch (codec->dapm.bias_level) {
1563 case SND_SOC_BIAS_ON:
1566 case SND_SOC_BIAS_PREPARE:
1569 case SND_SOC_BIAS_STANDBY:
1572 case SND_SOC_BIAS_OFF:
1576 count += sprintf(buf + count, "PM State: %s\n", state);
1581 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1583 int snd_soc_dapm_sys_add(struct device *dev)
1585 return device_create_file(dev, &dev_attr_dapm_widget);
1588 static void snd_soc_dapm_sys_remove(struct device *dev)
1590 device_remove_file(dev, &dev_attr_dapm_widget);
1593 /* free all dapm widgets and resources */
1594 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1596 struct snd_soc_dapm_widget *w, *next_w;
1597 struct snd_soc_dapm_path *p, *next_p;
1599 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1600 if (w->dapm != dapm)
1604 * remove source and sink paths associated to this widget.
1605 * While removing the path, remove reference to it from both
1606 * source and sink widgets so that path is removed only once.
1608 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1609 list_del(&p->list_sink);
1610 list_del(&p->list_source);
1612 kfree(p->long_name);
1615 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1616 list_del(&p->list_sink);
1617 list_del(&p->list_source);
1619 kfree(p->long_name);
1622 kfree(w->kcontrols);
1628 static struct snd_soc_dapm_widget *dapm_find_widget(
1629 struct snd_soc_dapm_context *dapm, const char *pin,
1630 bool search_other_contexts)
1632 struct snd_soc_dapm_widget *w;
1633 struct snd_soc_dapm_widget *fallback = NULL;
1635 list_for_each_entry(w, &dapm->card->widgets, list) {
1636 if (!strcmp(w->name, pin)) {
1637 if (w->dapm == dapm)
1644 if (search_other_contexts)
1650 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1651 const char *pin, int status)
1653 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
1656 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1660 w->connected = status;
1668 * snd_soc_dapm_sync - scan and power dapm paths
1669 * @dapm: DAPM context
1671 * Walks all dapm audio paths and powers widgets according to their
1672 * stream or path usage.
1674 * Returns 0 for success.
1676 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1678 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1680 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1682 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1683 const struct snd_soc_dapm_route *route)
1685 struct snd_soc_dapm_path *path;
1686 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1687 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1689 const char *control = route->control;
1691 char prefixed_sink[80];
1692 char prefixed_source[80];
1695 if (dapm->codec && dapm->codec->name_prefix) {
1696 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1697 dapm->codec->name_prefix, route->sink);
1698 sink = prefixed_sink;
1699 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1700 dapm->codec->name_prefix, route->source);
1701 source = prefixed_source;
1704 source = route->source;
1708 * find src and dest widgets over all widgets but favor a widget from
1709 * current DAPM context
1711 list_for_each_entry(w, &dapm->card->widgets, list) {
1712 if (!wsink && !(strcmp(w->name, sink))) {
1714 if (w->dapm == dapm)
1718 if (!wsource && !(strcmp(w->name, source))) {
1720 if (w->dapm == dapm)
1724 /* use widget from another DAPM context if not found from this */
1730 if (wsource == NULL || wsink == NULL)
1733 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1737 path->source = wsource;
1739 path->connected = route->connected;
1740 INIT_LIST_HEAD(&path->list);
1741 INIT_LIST_HEAD(&path->list_source);
1742 INIT_LIST_HEAD(&path->list_sink);
1744 /* check for external widgets */
1745 if (wsink->id == snd_soc_dapm_input) {
1746 if (wsource->id == snd_soc_dapm_micbias ||
1747 wsource->id == snd_soc_dapm_mic ||
1748 wsource->id == snd_soc_dapm_line ||
1749 wsource->id == snd_soc_dapm_output)
1752 if (wsource->id == snd_soc_dapm_output) {
1753 if (wsink->id == snd_soc_dapm_spk ||
1754 wsink->id == snd_soc_dapm_hp ||
1755 wsink->id == snd_soc_dapm_line ||
1756 wsink->id == snd_soc_dapm_input)
1760 /* connect static paths */
1761 if (control == NULL) {
1762 list_add(&path->list, &dapm->card->paths);
1763 list_add(&path->list_sink, &wsink->sources);
1764 list_add(&path->list_source, &wsource->sinks);
1769 /* connect dynamic paths */
1770 switch (wsink->id) {
1771 case snd_soc_dapm_adc:
1772 case snd_soc_dapm_dac:
1773 case snd_soc_dapm_pga:
1774 case snd_soc_dapm_out_drv:
1775 case snd_soc_dapm_input:
1776 case snd_soc_dapm_output:
1777 case snd_soc_dapm_micbias:
1778 case snd_soc_dapm_vmid:
1779 case snd_soc_dapm_pre:
1780 case snd_soc_dapm_post:
1781 case snd_soc_dapm_supply:
1782 case snd_soc_dapm_aif_in:
1783 case snd_soc_dapm_aif_out:
1784 list_add(&path->list, &dapm->card->paths);
1785 list_add(&path->list_sink, &wsink->sources);
1786 list_add(&path->list_source, &wsource->sinks);
1789 case snd_soc_dapm_mux:
1790 case snd_soc_dapm_virt_mux:
1791 case snd_soc_dapm_value_mux:
1792 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1793 &wsink->kcontrol_news[0]);
1797 case snd_soc_dapm_switch:
1798 case snd_soc_dapm_mixer:
1799 case snd_soc_dapm_mixer_named_ctl:
1800 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
1804 case snd_soc_dapm_hp:
1805 case snd_soc_dapm_mic:
1806 case snd_soc_dapm_line:
1807 case snd_soc_dapm_spk:
1808 list_add(&path->list, &dapm->card->paths);
1809 list_add(&path->list_sink, &wsink->sources);
1810 list_add(&path->list_source, &wsource->sinks);
1817 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
1818 source, control, sink);
1824 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1825 * @dapm: DAPM context
1826 * @route: audio routes
1827 * @num: number of routes
1829 * Connects 2 dapm widgets together via a named audio path. The sink is
1830 * the widget receiving the audio signal, whilst the source is the sender
1831 * of the audio signal.
1833 * Returns 0 for success else error. On error all resources can be freed
1834 * with a call to snd_soc_card_free().
1836 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1837 const struct snd_soc_dapm_route *route, int num)
1841 for (i = 0; i < num; i++) {
1842 ret = snd_soc_dapm_add_route(dapm, route);
1844 dev_err(dapm->dev, "Failed to add route %s->%s\n",
1845 route->source, route->sink);
1853 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1855 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
1856 const struct snd_soc_dapm_route *route)
1858 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
1861 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
1864 struct snd_soc_dapm_path *path;
1868 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
1874 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
1879 if (route->control || route->connected)
1880 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
1881 route->source, route->sink);
1883 list_for_each_entry(path, &source->sinks, list_source) {
1884 if (path->sink == sink) {
1891 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
1892 route->source, route->sink);
1894 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
1895 count, route->source, route->sink);
1901 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
1902 * @dapm: DAPM context
1903 * @route: audio routes
1904 * @num: number of routes
1906 * Mark existing routes matching those specified in the passed array
1907 * as being weak, meaning that they are ignored for the purpose of
1908 * power decisions. The main intended use case is for sidetone paths
1909 * which couple audio between other independent paths if they are both
1910 * active in order to make the combination work better at the user
1911 * level but which aren't intended to be "used".
1913 * Note that CODEC drivers should not use this as sidetone type paths
1914 * can frequently also be used as bypass paths.
1916 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
1917 const struct snd_soc_dapm_route *route, int num)
1922 for (i = 0; i < num; i++) {
1923 err = snd_soc_dapm_weak_route(dapm, route);
1931 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
1934 * snd_soc_dapm_new_widgets - add new dapm widgets
1935 * @dapm: DAPM context
1937 * Checks the codec for any new dapm widgets and creates them if found.
1939 * Returns 0 for success.
1941 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
1943 struct snd_soc_dapm_widget *w;
1946 list_for_each_entry(w, &dapm->card->widgets, list)
1951 if (w->num_kcontrols) {
1952 w->kcontrols = kzalloc(w->num_kcontrols *
1953 sizeof(struct snd_kcontrol *),
1960 case snd_soc_dapm_switch:
1961 case snd_soc_dapm_mixer:
1962 case snd_soc_dapm_mixer_named_ctl:
1963 w->power_check = dapm_generic_check_power;
1966 case snd_soc_dapm_mux:
1967 case snd_soc_dapm_virt_mux:
1968 case snd_soc_dapm_value_mux:
1969 w->power_check = dapm_generic_check_power;
1972 case snd_soc_dapm_adc:
1973 case snd_soc_dapm_aif_out:
1974 w->power_check = dapm_adc_check_power;
1976 case snd_soc_dapm_dac:
1977 case snd_soc_dapm_aif_in:
1978 w->power_check = dapm_dac_check_power;
1980 case snd_soc_dapm_pga:
1981 case snd_soc_dapm_out_drv:
1982 w->power_check = dapm_generic_check_power;
1985 case snd_soc_dapm_input:
1986 case snd_soc_dapm_output:
1987 case snd_soc_dapm_micbias:
1988 case snd_soc_dapm_spk:
1989 case snd_soc_dapm_hp:
1990 case snd_soc_dapm_mic:
1991 case snd_soc_dapm_line:
1992 w->power_check = dapm_generic_check_power;
1994 case snd_soc_dapm_supply:
1995 w->power_check = dapm_supply_check_power;
1996 case snd_soc_dapm_vmid:
1997 case snd_soc_dapm_pre:
1998 case snd_soc_dapm_post:
2002 /* Read the initial power state from the device */
2004 val = soc_widget_read(w, w->reg);
2005 val &= 1 << w->shift;
2015 dapm_debugfs_add_widget(w);
2018 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2021 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2024 * snd_soc_dapm_get_volsw - dapm mixer get callback
2025 * @kcontrol: mixer control
2026 * @ucontrol: control element information
2028 * Callback to get the value of a dapm mixer control.
2030 * Returns 0 for success.
2032 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2033 struct snd_ctl_elem_value *ucontrol)
2035 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2036 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2037 struct soc_mixer_control *mc =
2038 (struct soc_mixer_control *)kcontrol->private_value;
2039 unsigned int reg = mc->reg;
2040 unsigned int shift = mc->shift;
2041 unsigned int rshift = mc->rshift;
2043 unsigned int invert = mc->invert;
2044 unsigned int mask = (1 << fls(max)) - 1;
2046 ucontrol->value.integer.value[0] =
2047 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2048 if (shift != rshift)
2049 ucontrol->value.integer.value[1] =
2050 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2052 ucontrol->value.integer.value[0] =
2053 max - ucontrol->value.integer.value[0];
2054 if (shift != rshift)
2055 ucontrol->value.integer.value[1] =
2056 max - ucontrol->value.integer.value[1];
2061 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2064 * snd_soc_dapm_put_volsw - dapm mixer set callback
2065 * @kcontrol: mixer control
2066 * @ucontrol: control element information
2068 * Callback to set the value of a dapm mixer control.
2070 * Returns 0 for success.
2072 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2073 struct snd_ctl_elem_value *ucontrol)
2075 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2076 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2077 struct snd_soc_codec *codec = widget->codec;
2078 struct soc_mixer_control *mc =
2079 (struct soc_mixer_control *)kcontrol->private_value;
2080 unsigned int reg = mc->reg;
2081 unsigned int shift = mc->shift;
2083 unsigned int mask = (1 << fls(max)) - 1;
2084 unsigned int invert = mc->invert;
2086 int connect, change;
2087 struct snd_soc_dapm_update update;
2090 val = (ucontrol->value.integer.value[0] & mask);
2094 mask = mask << shift;
2098 /* new connection */
2099 connect = invert ? 0 : 1;
2101 /* old connection must be powered down */
2102 connect = invert ? 1 : 0;
2104 mutex_lock(&codec->mutex);
2106 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2108 for (wi = 0; wi < wlist->num_widgets; wi++) {
2109 widget = wlist->widgets[wi];
2111 widget->value = val;
2113 update.kcontrol = kcontrol;
2114 update.widget = widget;
2118 widget->dapm->update = &update;
2120 dapm_mixer_update_power(widget, kcontrol, connect);
2122 widget->dapm->update = NULL;
2126 mutex_unlock(&codec->mutex);
2129 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2132 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2133 * @kcontrol: mixer control
2134 * @ucontrol: control element information
2136 * Callback to get the value of a dapm enumerated double mixer control.
2138 * Returns 0 for success.
2140 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2141 struct snd_ctl_elem_value *ucontrol)
2143 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2144 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2145 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2146 unsigned int val, bitmask;
2148 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2150 val = snd_soc_read(widget->codec, e->reg);
2151 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2152 if (e->shift_l != e->shift_r)
2153 ucontrol->value.enumerated.item[1] =
2154 (val >> e->shift_r) & (bitmask - 1);
2158 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2161 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2162 * @kcontrol: mixer control
2163 * @ucontrol: control element information
2165 * Callback to set the value of a dapm enumerated double mixer control.
2167 * Returns 0 for success.
2169 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2170 struct snd_ctl_elem_value *ucontrol)
2172 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2173 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2174 struct snd_soc_codec *codec = widget->codec;
2175 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2176 unsigned int val, mux, change;
2177 unsigned int mask, bitmask;
2178 struct snd_soc_dapm_update update;
2181 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2183 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2185 mux = ucontrol->value.enumerated.item[0];
2186 val = mux << e->shift_l;
2187 mask = (bitmask - 1) << e->shift_l;
2188 if (e->shift_l != e->shift_r) {
2189 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2191 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2192 mask |= (bitmask - 1) << e->shift_r;
2195 mutex_lock(&codec->mutex);
2197 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2199 for (wi = 0; wi < wlist->num_widgets; wi++) {
2200 widget = wlist->widgets[wi];
2202 widget->value = val;
2204 update.kcontrol = kcontrol;
2205 update.widget = widget;
2206 update.reg = e->reg;
2209 widget->dapm->update = &update;
2211 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2213 widget->dapm->update = NULL;
2217 mutex_unlock(&codec->mutex);
2220 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2223 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2224 * @kcontrol: mixer control
2225 * @ucontrol: control element information
2227 * Returns 0 for success.
2229 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2230 struct snd_ctl_elem_value *ucontrol)
2232 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2233 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2235 ucontrol->value.enumerated.item[0] = widget->value;
2239 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2242 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2243 * @kcontrol: mixer control
2244 * @ucontrol: control element information
2246 * Returns 0 for success.
2248 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2249 struct snd_ctl_elem_value *ucontrol)
2251 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2252 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2253 struct snd_soc_codec *codec = widget->codec;
2254 struct soc_enum *e =
2255 (struct soc_enum *)kcontrol->private_value;
2260 if (ucontrol->value.enumerated.item[0] >= e->max)
2263 mutex_lock(&codec->mutex);
2265 change = widget->value != ucontrol->value.enumerated.item[0];
2267 for (wi = 0; wi < wlist->num_widgets; wi++) {
2268 widget = wlist->widgets[wi];
2270 widget->value = ucontrol->value.enumerated.item[0];
2272 dapm_mux_update_power(widget, kcontrol, change,
2277 mutex_unlock(&codec->mutex);
2280 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2283 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2285 * @kcontrol: mixer control
2286 * @ucontrol: control element information
2288 * Callback to get the value of a dapm semi enumerated double mixer control.
2290 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2291 * used for handling bitfield coded enumeration for example.
2293 * Returns 0 for success.
2295 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2296 struct snd_ctl_elem_value *ucontrol)
2298 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2299 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2300 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2301 unsigned int reg_val, val, mux;
2303 reg_val = snd_soc_read(widget->codec, e->reg);
2304 val = (reg_val >> e->shift_l) & e->mask;
2305 for (mux = 0; mux < e->max; mux++) {
2306 if (val == e->values[mux])
2309 ucontrol->value.enumerated.item[0] = mux;
2310 if (e->shift_l != e->shift_r) {
2311 val = (reg_val >> e->shift_r) & e->mask;
2312 for (mux = 0; mux < e->max; mux++) {
2313 if (val == e->values[mux])
2316 ucontrol->value.enumerated.item[1] = mux;
2321 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2324 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2326 * @kcontrol: mixer control
2327 * @ucontrol: control element information
2329 * Callback to set the value of a dapm semi enumerated double mixer control.
2331 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2332 * used for handling bitfield coded enumeration for example.
2334 * Returns 0 for success.
2336 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2337 struct snd_ctl_elem_value *ucontrol)
2339 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2340 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2341 struct snd_soc_codec *codec = widget->codec;
2342 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2343 unsigned int val, mux, change;
2345 struct snd_soc_dapm_update update;
2348 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2350 mux = ucontrol->value.enumerated.item[0];
2351 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2352 mask = e->mask << e->shift_l;
2353 if (e->shift_l != e->shift_r) {
2354 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2356 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2357 mask |= e->mask << e->shift_r;
2360 mutex_lock(&codec->mutex);
2362 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2364 for (wi = 0; wi < wlist->num_widgets; wi++) {
2365 widget = wlist->widgets[wi];
2367 widget->value = val;
2369 update.kcontrol = kcontrol;
2370 update.widget = widget;
2371 update.reg = e->reg;
2374 widget->dapm->update = &update;
2376 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2378 widget->dapm->update = NULL;
2382 mutex_unlock(&codec->mutex);
2385 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2388 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2390 * @kcontrol: mixer control
2391 * @uinfo: control element information
2393 * Callback to provide information about a pin switch control.
2395 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2396 struct snd_ctl_elem_info *uinfo)
2398 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2400 uinfo->value.integer.min = 0;
2401 uinfo->value.integer.max = 1;
2405 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2408 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2410 * @kcontrol: mixer control
2413 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2414 struct snd_ctl_elem_value *ucontrol)
2416 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2417 const char *pin = (const char *)kcontrol->private_value;
2419 mutex_lock(&codec->mutex);
2421 ucontrol->value.integer.value[0] =
2422 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
2424 mutex_unlock(&codec->mutex);
2428 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2431 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2433 * @kcontrol: mixer control
2436 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2437 struct snd_ctl_elem_value *ucontrol)
2439 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2440 const char *pin = (const char *)kcontrol->private_value;
2442 mutex_lock(&codec->mutex);
2444 if (ucontrol->value.integer.value[0])
2445 snd_soc_dapm_enable_pin(&codec->dapm, pin);
2447 snd_soc_dapm_disable_pin(&codec->dapm, pin);
2449 snd_soc_dapm_sync(&codec->dapm);
2451 mutex_unlock(&codec->mutex);
2455 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2458 * snd_soc_dapm_new_control - create new dapm control
2459 * @dapm: DAPM context
2460 * @widget: widget template
2462 * Creates a new dapm control based upon the template.
2464 * Returns 0 for success else error.
2466 int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2467 const struct snd_soc_dapm_widget *widget)
2469 struct snd_soc_dapm_widget *w;
2472 if ((w = dapm_cnew_widget(widget)) == NULL)
2475 name_len = strlen(widget->name) + 1;
2476 if (dapm->codec && dapm->codec->name_prefix)
2477 name_len += 1 + strlen(dapm->codec->name_prefix);
2478 w->name = kmalloc(name_len, GFP_KERNEL);
2479 if (w->name == NULL) {
2483 if (dapm->codec && dapm->codec->name_prefix)
2484 snprintf(w->name, name_len, "%s %s",
2485 dapm->codec->name_prefix, widget->name);
2487 snprintf(w->name, name_len, "%s", widget->name);
2491 w->codec = dapm->codec;
2492 INIT_LIST_HEAD(&w->sources);
2493 INIT_LIST_HEAD(&w->sinks);
2494 INIT_LIST_HEAD(&w->list);
2495 list_add(&w->list, &dapm->card->widgets);
2497 /* machine layer set ups unconnected pins and insertions */
2501 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
2504 * snd_soc_dapm_new_controls - create new dapm controls
2505 * @dapm: DAPM context
2506 * @widget: widget array
2507 * @num: number of widgets
2509 * Creates new DAPM controls based upon the templates.
2511 * Returns 0 for success else error.
2513 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2514 const struct snd_soc_dapm_widget *widget,
2519 for (i = 0; i < num; i++) {
2520 ret = snd_soc_dapm_new_control(dapm, widget);
2523 "ASoC: Failed to create DAPM control %s: %d\n",
2531 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2533 static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2534 const char *stream, int event)
2536 struct snd_soc_dapm_widget *w;
2538 list_for_each_entry(w, &dapm->card->widgets, list)
2540 if (!w->sname || w->dapm != dapm)
2542 dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2543 w->name, w->sname, stream, event);
2544 if (strstr(w->sname, stream)) {
2546 case SND_SOC_DAPM_STREAM_START:
2549 case SND_SOC_DAPM_STREAM_STOP:
2552 case SND_SOC_DAPM_STREAM_SUSPEND:
2553 case SND_SOC_DAPM_STREAM_RESUME:
2554 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
2555 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2561 dapm_power_widgets(dapm, event);
2565 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2566 * @rtd: PCM runtime data
2567 * @stream: stream name
2568 * @event: stream event
2570 * Sends a stream event to the dapm core. The core then makes any
2571 * necessary widget power changes.
2573 * Returns 0 for success else error.
2575 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2576 const char *stream, int event)
2578 struct snd_soc_codec *codec = rtd->codec;
2583 mutex_lock(&codec->mutex);
2584 soc_dapm_stream_event(&codec->dapm, stream, event);
2585 mutex_unlock(&codec->mutex);
2590 * snd_soc_dapm_enable_pin - enable pin.
2591 * @dapm: DAPM context
2594 * Enables input/output pin and its parents or children widgets iff there is
2595 * a valid audio route and active audio stream.
2596 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2597 * do any widget power switching.
2599 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2601 return snd_soc_dapm_set_pin(dapm, pin, 1);
2603 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2606 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2607 * @dapm: DAPM context
2610 * Enables input/output pin regardless of any other state. This is
2611 * intended for use with microphone bias supplies used in microphone
2614 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2615 * do any widget power switching.
2617 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2620 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2623 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2627 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
2633 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2636 * snd_soc_dapm_disable_pin - disable pin.
2637 * @dapm: DAPM context
2640 * Disables input/output pin and its parents or children widgets.
2641 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2642 * do any widget power switching.
2644 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2647 return snd_soc_dapm_set_pin(dapm, pin, 0);
2649 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2652 * snd_soc_dapm_nc_pin - permanently disable pin.
2653 * @dapm: DAPM context
2656 * Marks the specified pin as being not connected, disabling it along
2657 * any parent or child widgets. At present this is identical to
2658 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2659 * additional things such as disabling controls which only affect
2660 * paths through the pin.
2662 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2663 * do any widget power switching.
2665 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2667 return snd_soc_dapm_set_pin(dapm, pin, 0);
2669 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2672 * snd_soc_dapm_get_pin_status - get audio pin status
2673 * @dapm: DAPM context
2674 * @pin: audio signal pin endpoint (or start point)
2676 * Get audio pin status - connected or disconnected.
2678 * Returns 1 for connected otherwise 0.
2680 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2683 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2686 return w->connected;
2690 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2693 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2694 * @dapm: DAPM context
2695 * @pin: audio signal pin endpoint (or start point)
2697 * Mark the given endpoint or pin as ignoring suspend. When the
2698 * system is disabled a path between two endpoints flagged as ignoring
2699 * suspend will not be disabled. The path must already be enabled via
2700 * normal means at suspend time, it will not be turned on if it was not
2703 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2706 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
2709 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2713 w->ignore_suspend = 1;
2717 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2720 * snd_soc_dapm_free - free dapm resources
2723 * Free all dapm widgets and resources.
2725 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2727 snd_soc_dapm_sys_remove(dapm->dev);
2728 dapm_debugfs_cleanup(dapm);
2729 dapm_free_widgets(dapm);
2730 list_del(&dapm->list);
2732 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2734 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2736 struct snd_soc_dapm_widget *w;
2737 LIST_HEAD(down_list);
2740 list_for_each_entry(w, &dapm->card->widgets, list) {
2741 if (w->dapm != dapm)
2744 dapm_seq_insert(w, &down_list, false);
2750 /* If there were no widgets to power down we're already in
2754 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
2755 dapm_seq_run(dapm, &down_list, 0, false);
2756 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
2761 * snd_soc_dapm_shutdown - callback for system shutdown
2763 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2765 struct snd_soc_codec *codec;
2767 list_for_each_entry(codec, &card->codec_dev_list, list) {
2768 soc_dapm_shutdown_codec(&codec->dapm);
2769 snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
2773 /* Module information */
2774 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2775 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2776 MODULE_LICENSE("GPL");