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 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
53 /* dapm power sequences - make this per codec in the future */
54 static int dapm_up_seq[] = {
55 [snd_soc_dapm_pre] = 0,
56 [snd_soc_dapm_supply] = 1,
57 [snd_soc_dapm_micbias] = 2,
58 [snd_soc_dapm_aif_in] = 3,
59 [snd_soc_dapm_aif_out] = 3,
60 [snd_soc_dapm_mic] = 4,
61 [snd_soc_dapm_mux] = 5,
62 [snd_soc_dapm_virt_mux] = 5,
63 [snd_soc_dapm_value_mux] = 5,
64 [snd_soc_dapm_dac] = 6,
65 [snd_soc_dapm_mixer] = 7,
66 [snd_soc_dapm_mixer_named_ctl] = 7,
67 [snd_soc_dapm_pga] = 8,
68 [snd_soc_dapm_adc] = 9,
69 [snd_soc_dapm_out_drv] = 10,
70 [snd_soc_dapm_hp] = 10,
71 [snd_soc_dapm_spk] = 10,
72 [snd_soc_dapm_post] = 11,
75 static int dapm_down_seq[] = {
76 [snd_soc_dapm_pre] = 0,
77 [snd_soc_dapm_adc] = 1,
78 [snd_soc_dapm_hp] = 2,
79 [snd_soc_dapm_spk] = 2,
80 [snd_soc_dapm_out_drv] = 2,
81 [snd_soc_dapm_pga] = 4,
82 [snd_soc_dapm_mixer_named_ctl] = 5,
83 [snd_soc_dapm_mixer] = 5,
84 [snd_soc_dapm_dac] = 6,
85 [snd_soc_dapm_mic] = 7,
86 [snd_soc_dapm_micbias] = 8,
87 [snd_soc_dapm_mux] = 9,
88 [snd_soc_dapm_virt_mux] = 9,
89 [snd_soc_dapm_value_mux] = 9,
90 [snd_soc_dapm_aif_in] = 10,
91 [snd_soc_dapm_aif_out] = 10,
92 [snd_soc_dapm_supply] = 11,
93 [snd_soc_dapm_post] = 12,
96 static void pop_wait(u32 pop_time)
99 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
102 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
110 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
115 vsnprintf(buf, PAGE_SIZE, fmt, args);
116 dev_info(dev, "%s", buf);
122 /* create a new dapm widget */
123 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
124 const struct snd_soc_dapm_widget *_widget)
126 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
129 /* get snd_card from DAPM context */
130 static inline struct snd_card *dapm_get_snd_card(
131 struct snd_soc_dapm_context *dapm)
134 return dapm->codec->card->snd_card;
135 else if (dapm->platform)
136 return dapm->platform->card->snd_card;
144 /* get soc_card from DAPM context */
145 static inline struct snd_soc_card *dapm_get_soc_card(
146 struct snd_soc_dapm_context *dapm)
149 return dapm->codec->card;
150 else if (dapm->platform)
151 return dapm->platform->card;
159 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
162 return snd_soc_read(w->codec, reg);
163 else if (w->platform)
164 return snd_soc_platform_read(w->platform, reg);
166 dev_err(w->dapm->dev, "no valid widget read method\n");
170 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
173 return snd_soc_write(w->codec, reg, val);
174 else if (w->platform)
175 return snd_soc_platform_write(w->platform, reg, val);
177 dev_err(w->dapm->dev, "no valid widget write method\n");
181 static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
182 unsigned short reg, unsigned int mask, unsigned int value)
185 unsigned int old, new;
188 ret = soc_widget_read(w, reg);
193 new = (old & ~mask) | (value & mask);
196 ret = soc_widget_write(w, reg, new);
205 * snd_soc_dapm_set_bias_level - set the bias level for the system
206 * @dapm: DAPM context
207 * @level: level to configure
209 * Configure the bias (power) levels for the SoC audio device.
211 * Returns 0 for success else error.
213 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
214 enum snd_soc_bias_level level)
216 struct snd_soc_card *card = dapm->card;
219 trace_snd_soc_bias_level_start(card, level);
221 if (card && card->set_bias_level)
222 ret = card->set_bias_level(card, dapm, level);
227 if (dapm->codec->driver->set_bias_level)
228 ret = dapm->codec->driver->set_bias_level(dapm->codec,
231 dapm->bias_level = level;
236 if (card && card->set_bias_level_post)
237 ret = card->set_bias_level_post(card, dapm, level);
239 trace_snd_soc_bias_level_done(card, level);
244 /* set up initial codec paths */
245 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
246 struct snd_soc_dapm_path *p, int i)
249 case snd_soc_dapm_switch:
250 case snd_soc_dapm_mixer:
251 case snd_soc_dapm_mixer_named_ctl: {
253 struct soc_mixer_control *mc = (struct soc_mixer_control *)
254 w->kcontrol_news[i].private_value;
255 unsigned int reg = mc->reg;
256 unsigned int shift = mc->shift;
258 unsigned int mask = (1 << fls(max)) - 1;
259 unsigned int invert = mc->invert;
261 val = soc_widget_read(w, reg);
262 val = (val >> shift) & mask;
264 if ((invert && !val) || (!invert && val))
270 case snd_soc_dapm_mux: {
271 struct soc_enum *e = (struct soc_enum *)
272 w->kcontrol_news[i].private_value;
273 int val, item, bitmask;
275 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
277 val = soc_widget_read(w, e->reg);
278 item = (val >> e->shift_l) & (bitmask - 1);
281 for (i = 0; i < e->max; i++) {
282 if (!(strcmp(p->name, e->texts[i])) && item == i)
287 case snd_soc_dapm_virt_mux: {
288 struct soc_enum *e = (struct soc_enum *)
289 w->kcontrol_news[i].private_value;
292 /* since a virtual mux has no backing registers to
293 * decide which path to connect, it will try to match
294 * with the first enumeration. This is to ensure
295 * that the default mux choice (the first) will be
296 * correctly powered up during initialization.
298 if (!strcmp(p->name, e->texts[0]))
302 case snd_soc_dapm_value_mux: {
303 struct soc_enum *e = (struct soc_enum *)
304 w->kcontrol_news[i].private_value;
307 val = soc_widget_read(w, e->reg);
308 val = (val >> e->shift_l) & e->mask;
309 for (item = 0; item < e->max; item++) {
310 if (val == e->values[item])
315 for (i = 0; i < e->max; i++) {
316 if (!(strcmp(p->name, e->texts[i])) && item == i)
321 /* does not effect routing - always connected */
322 case snd_soc_dapm_pga:
323 case snd_soc_dapm_out_drv:
324 case snd_soc_dapm_output:
325 case snd_soc_dapm_adc:
326 case snd_soc_dapm_input:
327 case snd_soc_dapm_dac:
328 case snd_soc_dapm_micbias:
329 case snd_soc_dapm_vmid:
330 case snd_soc_dapm_supply:
331 case snd_soc_dapm_aif_in:
332 case snd_soc_dapm_aif_out:
335 /* does effect routing - dynamically connected */
336 case snd_soc_dapm_hp:
337 case snd_soc_dapm_mic:
338 case snd_soc_dapm_spk:
339 case snd_soc_dapm_line:
340 case snd_soc_dapm_pre:
341 case snd_soc_dapm_post:
347 /* connect mux widget to its interconnecting audio paths */
348 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
349 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
350 struct snd_soc_dapm_path *path, const char *control_name,
351 const struct snd_kcontrol_new *kcontrol)
353 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
356 for (i = 0; i < e->max; i++) {
357 if (!(strcmp(control_name, e->texts[i]))) {
358 list_add(&path->list, &dapm->card->paths);
359 list_add(&path->list_sink, &dest->sources);
360 list_add(&path->list_source, &src->sinks);
361 path->name = (char*)e->texts[i];
362 dapm_set_path_status(dest, path, 0);
370 /* connect mixer widget to its interconnecting audio paths */
371 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
372 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
373 struct snd_soc_dapm_path *path, const char *control_name)
377 /* search for mixer kcontrol */
378 for (i = 0; i < dest->num_kcontrols; i++) {
379 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
380 list_add(&path->list, &dapm->card->paths);
381 list_add(&path->list_sink, &dest->sources);
382 list_add(&path->list_source, &src->sinks);
383 path->name = dest->kcontrol_news[i].name;
384 dapm_set_path_status(dest, path, i);
391 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
392 struct snd_soc_dapm_widget *kcontrolw,
393 const struct snd_kcontrol_new *kcontrol_new,
394 struct snd_kcontrol **kcontrol)
396 struct snd_soc_dapm_widget *w;
401 list_for_each_entry(w, &dapm->card->widgets, list) {
402 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
404 for (i = 0; i < w->num_kcontrols; i++) {
405 if (&w->kcontrol_news[i] == kcontrol_new) {
407 *kcontrol = w->kcontrols[i];
416 /* create new dapm mixer control */
417 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
419 struct snd_soc_dapm_context *dapm = w->dapm;
421 size_t name_len, prefix_len;
422 struct snd_soc_dapm_path *path;
423 struct snd_card *card = dapm->card->snd_card;
425 struct snd_soc_dapm_widget_list *wlist;
429 prefix = dapm->codec->name_prefix;
434 prefix_len = strlen(prefix) + 1;
439 for (i = 0; i < w->num_kcontrols; i++) {
442 list_for_each_entry(path, &w->sources, list_sink) {
444 /* mixer/mux paths name must match control name */
445 if (path->name != (char *)w->kcontrol_news[i].name)
448 if (w->kcontrols[i]) {
449 path->kcontrol = w->kcontrols[i];
453 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
454 sizeof(struct snd_soc_dapm_widget *),
455 wlist = kzalloc(wlistsize, GFP_KERNEL);
458 "asoc: can't allocate widget list for %s\n",
462 wlist->num_widgets = 1;
463 wlist->widgets[0] = w;
465 /* add dapm control with long name.
466 * for dapm_mixer this is the concatenation of the
467 * mixer and kcontrol name.
468 * for dapm_mixer_named_ctl this is simply the
471 name_len = strlen(w->kcontrol_news[i].name) + 1;
472 if (w->id != snd_soc_dapm_mixer_named_ctl)
473 name_len += 1 + strlen(w->name);
475 path->long_name = kmalloc(name_len, GFP_KERNEL);
477 if (path->long_name == NULL) {
484 /* The control will get a prefix from
485 * the control creation process but
486 * we're also using the same prefix
487 * for widgets so cut the prefix off
488 * the front of the widget name.
490 snprintf(path->long_name, name_len, "%s %s",
491 w->name + prefix_len,
492 w->kcontrol_news[i].name);
494 case snd_soc_dapm_mixer_named_ctl:
495 snprintf(path->long_name, name_len, "%s",
496 w->kcontrol_news[i].name);
500 path->long_name[name_len - 1] = '\0';
502 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
503 wlist, path->long_name,
505 ret = snd_ctl_add(card, path->kcontrol);
508 "asoc: failed to add dapm kcontrol %s: %d\n",
509 path->long_name, ret);
511 kfree(path->long_name);
512 path->long_name = NULL;
515 w->kcontrols[i] = path->kcontrol;
521 /* create new dapm mux control */
522 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
524 struct snd_soc_dapm_context *dapm = w->dapm;
525 struct snd_soc_dapm_path *path = NULL;
526 struct snd_kcontrol *kcontrol;
527 struct snd_card *card = dapm->card->snd_card;
531 struct snd_soc_dapm_widget_list *wlist;
532 int shared, wlistentries;
536 if (w->num_kcontrols != 1) {
538 "asoc: mux %s has incorrect number of controls\n",
543 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
546 wlist = kcontrol->private_data;
547 wlistentries = wlist->num_widgets + 1;
552 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
553 wlistentries * sizeof(struct snd_soc_dapm_widget *),
554 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
557 "asoc: can't allocate widget list for %s\n", w->name);
560 wlist->num_widgets = wlistentries;
561 wlist->widgets[wlistentries - 1] = w;
565 prefix = dapm->codec->name_prefix;
570 name = w->kcontrol_news[0].name;
575 prefix_len = strlen(prefix) + 1;
581 * The control will get a prefix from the control creation
582 * process but we're also using the same prefix for widgets so
583 * cut the prefix off the front of the widget name.
585 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
586 name + prefix_len, prefix);
587 ret = snd_ctl_add(card, kcontrol);
589 dev_err(dapm->dev, "failed to add kcontrol %s: %d\n",
596 kcontrol->private_data = wlist;
598 w->kcontrols[0] = kcontrol;
600 list_for_each_entry(path, &w->sources, list_sink)
601 path->kcontrol = kcontrol;
606 /* create new dapm volume control */
607 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
609 if (w->num_kcontrols)
610 dev_err(w->dapm->dev,
611 "asoc: PGA controls not supported: '%s'\n", w->name);
616 /* reset 'walked' bit for each dapm path */
617 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
619 struct snd_soc_dapm_path *p;
621 list_for_each_entry(p, &dapm->card->paths, list)
625 /* We implement power down on suspend by checking the power state of
626 * the ALSA card - when we are suspending the ALSA state for the card
629 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
631 int level = snd_power_get_state(widget->dapm->card->snd_card);
634 case SNDRV_CTL_POWER_D3hot:
635 case SNDRV_CTL_POWER_D3cold:
636 if (widget->ignore_suspend)
637 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
639 return widget->ignore_suspend;
646 * Recursively check for a completed path to an active or physically connected
647 * output widget. Returns number of complete paths.
649 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
651 struct snd_soc_dapm_path *path;
654 DAPM_UPDATE_STAT(widget, path_checks);
656 if (widget->id == snd_soc_dapm_supply)
659 switch (widget->id) {
660 case snd_soc_dapm_adc:
661 case snd_soc_dapm_aif_out:
663 return snd_soc_dapm_suspend_check(widget);
668 if (widget->connected) {
669 /* connected pin ? */
670 if (widget->id == snd_soc_dapm_output && !widget->ext)
671 return snd_soc_dapm_suspend_check(widget);
673 /* connected jack or spk ? */
674 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
675 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
676 return snd_soc_dapm_suspend_check(widget);
679 list_for_each_entry(path, &widget->sinks, list_source) {
686 if (path->sink && path->connect) {
688 con += is_connected_output_ep(path->sink);
696 * Recursively check for a completed path to an active or physically connected
697 * input widget. Returns number of complete paths.
699 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
701 struct snd_soc_dapm_path *path;
704 DAPM_UPDATE_STAT(widget, path_checks);
706 if (widget->id == snd_soc_dapm_supply)
709 /* active stream ? */
710 switch (widget->id) {
711 case snd_soc_dapm_dac:
712 case snd_soc_dapm_aif_in:
714 return snd_soc_dapm_suspend_check(widget);
719 if (widget->connected) {
720 /* connected pin ? */
721 if (widget->id == snd_soc_dapm_input && !widget->ext)
722 return snd_soc_dapm_suspend_check(widget);
724 /* connected VMID/Bias for lower pops */
725 if (widget->id == snd_soc_dapm_vmid)
726 return snd_soc_dapm_suspend_check(widget);
728 /* connected jack ? */
729 if (widget->id == snd_soc_dapm_mic ||
730 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
731 return snd_soc_dapm_suspend_check(widget);
734 list_for_each_entry(path, &widget->sources, list_sink) {
741 if (path->source && path->connect) {
743 con += is_connected_input_ep(path->source);
751 * Handler for generic register modifier widget.
753 int dapm_reg_event(struct snd_soc_dapm_widget *w,
754 struct snd_kcontrol *kcontrol, int event)
758 if (SND_SOC_DAPM_EVENT_ON(event))
763 soc_widget_update_bits(w, -(w->reg + 1),
764 w->mask << w->shift, val << w->shift);
768 EXPORT_SYMBOL_GPL(dapm_reg_event);
770 /* Generic check to see if a widget should be powered.
772 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
776 DAPM_UPDATE_STAT(w, power_checks);
778 in = is_connected_input_ep(w);
779 dapm_clear_walk(w->dapm);
780 out = is_connected_output_ep(w);
781 dapm_clear_walk(w->dapm);
782 return out != 0 && in != 0;
785 /* Check to see if an ADC has power */
786 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
790 DAPM_UPDATE_STAT(w, power_checks);
793 in = is_connected_input_ep(w);
794 dapm_clear_walk(w->dapm);
797 return dapm_generic_check_power(w);
801 /* Check to see if a DAC has power */
802 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
806 DAPM_UPDATE_STAT(w, power_checks);
809 out = is_connected_output_ep(w);
810 dapm_clear_walk(w->dapm);
813 return dapm_generic_check_power(w);
817 /* Check to see if a power supply is needed */
818 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
820 struct snd_soc_dapm_path *path;
823 DAPM_UPDATE_STAT(w, power_checks);
825 /* Check if one of our outputs is connected */
826 list_for_each_entry(path, &w->sinks, list_source) {
830 if (path->connected &&
831 !path->connected(path->source, path->sink))
837 if (path->sink->force) {
842 if (path->sink->power_check &&
843 path->sink->power_check(path->sink)) {
849 dapm_clear_walk(w->dapm);
854 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
855 struct snd_soc_dapm_widget *b,
863 sort = dapm_down_seq;
865 if (sort[a->id] != sort[b->id])
866 return sort[a->id] - sort[b->id];
867 if (a->subseq != b->subseq) {
869 return a->subseq - b->subseq;
871 return b->subseq - a->subseq;
873 if (a->reg != b->reg)
874 return a->reg - b->reg;
875 if (a->dapm != b->dapm)
876 return (unsigned long)a->dapm - (unsigned long)b->dapm;
881 /* Insert a widget in order into a DAPM power sequence. */
882 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
883 struct list_head *list,
886 struct snd_soc_dapm_widget *w;
888 list_for_each_entry(w, list, power_list)
889 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
890 list_add_tail(&new_widget->power_list, &w->power_list);
894 list_add_tail(&new_widget->power_list, list);
897 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
898 struct snd_soc_dapm_widget *w, int event)
900 struct snd_soc_card *card = dapm->card;
905 case SND_SOC_DAPM_PRE_PMU:
909 case SND_SOC_DAPM_POST_PMU:
910 ev_name = "POST_PMU";
913 case SND_SOC_DAPM_PRE_PMD:
917 case SND_SOC_DAPM_POST_PMD:
918 ev_name = "POST_PMD";
926 if (w->power != power)
929 if (w->event && (w->event_flags & event)) {
930 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
932 trace_snd_soc_dapm_widget_event_start(w, event);
933 ret = w->event(w, NULL, event);
934 trace_snd_soc_dapm_widget_event_done(w, event);
936 pr_err("%s: %s event failed: %d\n",
937 ev_name, w->name, ret);
941 /* Apply the coalesced changes from a DAPM sequence */
942 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
943 struct list_head *pending)
945 struct snd_soc_card *card = dapm->card;
946 struct snd_soc_dapm_widget *w;
948 unsigned int value = 0;
949 unsigned int mask = 0;
950 unsigned int cur_mask;
952 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
955 list_for_each_entry(w, pending, power_list) {
956 cur_mask = 1 << w->shift;
957 BUG_ON(reg != w->reg);
968 pop_dbg(dapm->dev, card->pop_time,
969 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
970 w->name, reg, value, mask);
972 /* Check for events */
973 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
974 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
978 /* Any widget will do, they should all be updating the
981 w = list_first_entry(pending, struct snd_soc_dapm_widget,
984 pop_dbg(dapm->dev, card->pop_time,
985 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
986 value, mask, reg, card->pop_time);
987 pop_wait(card->pop_time);
988 soc_widget_update_bits(w, reg, mask, value);
991 list_for_each_entry(w, pending, power_list) {
992 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
993 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
997 /* Apply a DAPM power sequence.
999 * We walk over a pre-sorted list of widgets to apply power to. In
1000 * order to minimise the number of writes to the device required
1001 * multiple widgets will be updated in a single write where possible.
1002 * Currently anything that requires more than a single write is not
1005 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1006 struct list_head *list, int event, bool power_up)
1008 struct snd_soc_dapm_widget *w, *n;
1011 int cur_subseq = -1;
1012 int cur_reg = SND_SOC_NOPM;
1013 struct snd_soc_dapm_context *cur_dapm = NULL;
1020 sort = dapm_down_seq;
1022 list_for_each_entry_safe(w, n, list, power_list) {
1025 /* Do we need to apply any queued changes? */
1026 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1027 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1028 if (!list_empty(&pending))
1029 dapm_seq_run_coalesced(cur_dapm, &pending);
1031 if (cur_dapm && cur_dapm->seq_notifier) {
1032 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1033 if (sort[i] == cur_sort)
1034 cur_dapm->seq_notifier(cur_dapm,
1039 INIT_LIST_HEAD(&pending);
1041 cur_subseq = INT_MIN;
1042 cur_reg = SND_SOC_NOPM;
1047 case snd_soc_dapm_pre:
1049 list_for_each_entry_safe_continue(w, n, list,
1052 if (event == SND_SOC_DAPM_STREAM_START)
1054 NULL, SND_SOC_DAPM_PRE_PMU);
1055 else if (event == SND_SOC_DAPM_STREAM_STOP)
1057 NULL, SND_SOC_DAPM_PRE_PMD);
1060 case snd_soc_dapm_post:
1062 list_for_each_entry_safe_continue(w, n, list,
1065 if (event == SND_SOC_DAPM_STREAM_START)
1067 NULL, SND_SOC_DAPM_POST_PMU);
1068 else if (event == SND_SOC_DAPM_STREAM_STOP)
1070 NULL, SND_SOC_DAPM_POST_PMD);
1074 /* Queue it up for application */
1075 cur_sort = sort[w->id];
1076 cur_subseq = w->subseq;
1079 list_move(&w->power_list, &pending);
1084 dev_err(w->dapm->dev,
1085 "Failed to apply widget power: %d\n", ret);
1088 if (!list_empty(&pending))
1089 dapm_seq_run_coalesced(cur_dapm, &pending);
1091 if (cur_dapm && cur_dapm->seq_notifier) {
1092 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1093 if (sort[i] == cur_sort)
1094 cur_dapm->seq_notifier(cur_dapm,
1099 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1101 struct snd_soc_dapm_update *update = dapm->update;
1102 struct snd_soc_dapm_widget *w;
1111 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1112 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1114 pr_err("%s DAPM pre-event failed: %d\n",
1118 ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
1121 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1124 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1125 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1127 pr_err("%s DAPM post-event failed: %d\n",
1132 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1133 * they're changing state.
1135 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1137 struct snd_soc_dapm_context *d = data;
1140 /* If we're off and we're not supposed to be go into STANDBY */
1141 if (d->bias_level == SND_SOC_BIAS_OFF &&
1142 d->target_bias_level != SND_SOC_BIAS_OFF) {
1143 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1146 "Failed to turn on bias: %d\n", ret);
1149 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1150 if (d->bias_level != d->target_bias_level) {
1151 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1154 "Failed to prepare bias: %d\n", ret);
1158 /* Async callback run prior to DAPM sequences - brings to their final
1161 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1163 struct snd_soc_dapm_context *d = data;
1166 /* If we just powered the last thing off drop to standby bias */
1167 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1168 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1169 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1170 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1172 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1176 /* If we're in standby and can support bias off then do that */
1177 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1178 d->target_bias_level == SND_SOC_BIAS_OFF) {
1179 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1181 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1184 /* If we just powered up then move to active bias */
1185 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1186 d->target_bias_level == SND_SOC_BIAS_ON) {
1187 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1189 dev_err(d->dev, "Failed to apply active bias: %d\n",
1195 * Scan each dapm widget for complete audio path.
1196 * A complete path is a route that has valid endpoints i.e.:-
1198 * o DAC to output pin.
1199 * o Input Pin to ADC.
1200 * o Input pin to Output pin (bypass, sidetone)
1201 * o DAC to ADC (loopback).
1203 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1205 struct snd_soc_card *card = dapm->card;
1206 struct snd_soc_dapm_widget *w;
1207 struct snd_soc_dapm_context *d;
1209 LIST_HEAD(down_list);
1210 LIST_HEAD(async_domain);
1211 enum snd_soc_bias_level bias;
1214 trace_snd_soc_dapm_start(card);
1216 list_for_each_entry(d, &card->dapm_list, list) {
1217 if (d->n_widgets || d->codec == NULL) {
1218 if (d->idle_bias_off)
1219 d->target_bias_level = SND_SOC_BIAS_OFF;
1221 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1225 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
1227 /* Check which widgets we need to power and store them in
1228 * lists indicating if they should be powered up or down.
1230 list_for_each_entry(w, &card->widgets, list) {
1232 case snd_soc_dapm_pre:
1233 dapm_seq_insert(w, &down_list, false);
1235 case snd_soc_dapm_post:
1236 dapm_seq_insert(w, &up_list, true);
1240 if (!w->power_check)
1244 power = w->power_check(w);
1251 /* Supplies and micbiases only bring
1252 * the context up to STANDBY as unless
1253 * something else is active and
1254 * passing audio they generally don't
1255 * require full power.
1258 case snd_soc_dapm_supply:
1259 case snd_soc_dapm_micbias:
1260 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1261 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1264 d->target_bias_level = SND_SOC_BIAS_ON;
1269 if (w->power == power)
1272 trace_snd_soc_dapm_widget_power(w, power);
1275 dapm_seq_insert(w, &up_list, true);
1277 dapm_seq_insert(w, &down_list, false);
1284 /* If there are no DAPM widgets then try to figure out power from the
1287 if (!dapm->n_widgets) {
1289 case SND_SOC_DAPM_STREAM_START:
1290 case SND_SOC_DAPM_STREAM_RESUME:
1291 dapm->target_bias_level = SND_SOC_BIAS_ON;
1293 case SND_SOC_DAPM_STREAM_STOP:
1294 if (dapm->codec->active)
1295 dapm->target_bias_level = SND_SOC_BIAS_ON;
1297 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1299 case SND_SOC_DAPM_STREAM_SUSPEND:
1300 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1302 case SND_SOC_DAPM_STREAM_NOP:
1303 dapm->target_bias_level = dapm->bias_level;
1310 /* Force all contexts in the card to the same bias state */
1311 bias = SND_SOC_BIAS_OFF;
1312 list_for_each_entry(d, &card->dapm_list, list)
1313 if (d->target_bias_level > bias)
1314 bias = d->target_bias_level;
1315 list_for_each_entry(d, &card->dapm_list, list)
1316 d->target_bias_level = bias;
1318 trace_snd_soc_dapm_walk_done(card);
1320 /* Run all the bias changes in parallel */
1321 list_for_each_entry(d, &dapm->card->dapm_list, list)
1322 async_schedule_domain(dapm_pre_sequence_async, d,
1324 async_synchronize_full_domain(&async_domain);
1326 /* Power down widgets first; try to avoid amplifying pops. */
1327 dapm_seq_run(dapm, &down_list, event, false);
1329 dapm_widget_update(dapm);
1332 dapm_seq_run(dapm, &up_list, event, true);
1334 /* Run all the bias changes in parallel */
1335 list_for_each_entry(d, &dapm->card->dapm_list, list)
1336 async_schedule_domain(dapm_post_sequence_async, d,
1338 async_synchronize_full_domain(&async_domain);
1340 pop_dbg(dapm->dev, card->pop_time,
1341 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1342 pop_wait(card->pop_time);
1344 trace_snd_soc_dapm_done(card);
1349 #ifdef CONFIG_DEBUG_FS
1350 static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1352 file->private_data = inode->i_private;
1356 static ssize_t dapm_widget_power_read_file(struct file *file,
1357 char __user *user_buf,
1358 size_t count, loff_t *ppos)
1360 struct snd_soc_dapm_widget *w = file->private_data;
1364 struct snd_soc_dapm_path *p = NULL;
1366 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1370 in = is_connected_input_ep(w);
1371 dapm_clear_walk(w->dapm);
1372 out = is_connected_output_ep(w);
1373 dapm_clear_walk(w->dapm);
1375 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
1376 w->name, w->power ? "On" : "Off", in, out);
1379 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1380 " - R%d(0x%x) bit %d",
1381 w->reg, w->reg, w->shift);
1383 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1386 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1388 w->active ? "active" : "inactive");
1390 list_for_each_entry(p, &w->sources, list_sink) {
1391 if (p->connected && !p->connected(w, p->sink))
1395 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1396 " in \"%s\" \"%s\"\n",
1397 p->name ? p->name : "static",
1400 list_for_each_entry(p, &w->sinks, list_source) {
1401 if (p->connected && !p->connected(w, p->sink))
1405 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1406 " out \"%s\" \"%s\"\n",
1407 p->name ? p->name : "static",
1411 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1417 static const struct file_operations dapm_widget_power_fops = {
1418 .open = dapm_widget_power_open_file,
1419 .read = dapm_widget_power_read_file,
1420 .llseek = default_llseek,
1423 static int dapm_bias_open_file(struct inode *inode, struct file *file)
1425 file->private_data = inode->i_private;
1429 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1430 size_t count, loff_t *ppos)
1432 struct snd_soc_dapm_context *dapm = file->private_data;
1435 switch (dapm->bias_level) {
1436 case SND_SOC_BIAS_ON:
1439 case SND_SOC_BIAS_PREPARE:
1440 level = "Prepare\n";
1442 case SND_SOC_BIAS_STANDBY:
1443 level = "Standby\n";
1445 case SND_SOC_BIAS_OFF:
1450 level = "Unknown\n";
1454 return simple_read_from_buffer(user_buf, count, ppos, level,
1458 static const struct file_operations dapm_bias_fops = {
1459 .open = dapm_bias_open_file,
1460 .read = dapm_bias_read_file,
1461 .llseek = default_llseek,
1464 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1465 struct dentry *parent)
1469 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1471 if (!dapm->debugfs_dapm) {
1473 "Failed to create DAPM debugfs directory\n");
1477 d = debugfs_create_file("bias_level", 0444,
1478 dapm->debugfs_dapm, dapm,
1482 "ASoC: Failed to create bias level debugfs file\n");
1485 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1487 struct snd_soc_dapm_context *dapm = w->dapm;
1490 if (!dapm->debugfs_dapm || !w->name)
1493 d = debugfs_create_file(w->name, 0444,
1494 dapm->debugfs_dapm, w,
1495 &dapm_widget_power_fops);
1497 dev_warn(w->dapm->dev,
1498 "ASoC: Failed to create %s debugfs file\n",
1502 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1504 debugfs_remove_recursive(dapm->debugfs_dapm);
1508 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1509 struct dentry *parent)
1513 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1517 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1523 /* test and update the power status of a mux widget */
1524 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1525 struct snd_kcontrol *kcontrol, int change,
1526 int mux, struct soc_enum *e)
1528 struct snd_soc_dapm_path *path;
1531 if (widget->id != snd_soc_dapm_mux &&
1532 widget->id != snd_soc_dapm_virt_mux &&
1533 widget->id != snd_soc_dapm_value_mux)
1539 /* find dapm widget path assoc with kcontrol */
1540 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1541 if (path->kcontrol != kcontrol)
1544 if (!path->name || !e->texts[mux])
1548 /* we now need to match the string in the enum to the path */
1549 if (!(strcmp(path->name, e->texts[mux])))
1550 path->connect = 1; /* new connection */
1552 path->connect = 0; /* old connection must be powered down */
1556 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1561 /* test and update the power status of a mixer or switch widget */
1562 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1563 struct snd_kcontrol *kcontrol, int connect)
1565 struct snd_soc_dapm_path *path;
1568 if (widget->id != snd_soc_dapm_mixer &&
1569 widget->id != snd_soc_dapm_mixer_named_ctl &&
1570 widget->id != snd_soc_dapm_switch)
1573 /* find dapm widget path assoc with kcontrol */
1574 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1575 if (path->kcontrol != kcontrol)
1578 /* found, now check type */
1580 path->connect = connect;
1584 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1589 /* show dapm widget status in sys fs */
1590 static ssize_t dapm_widget_show(struct device *dev,
1591 struct device_attribute *attr, char *buf)
1593 struct snd_soc_pcm_runtime *rtd =
1594 container_of(dev, struct snd_soc_pcm_runtime, dev);
1595 struct snd_soc_codec *codec =rtd->codec;
1596 struct snd_soc_dapm_widget *w;
1598 char *state = "not set";
1600 list_for_each_entry(w, &codec->card->widgets, list) {
1601 if (w->dapm != &codec->dapm)
1604 /* only display widgets that burnm power */
1606 case snd_soc_dapm_hp:
1607 case snd_soc_dapm_mic:
1608 case snd_soc_dapm_spk:
1609 case snd_soc_dapm_line:
1610 case snd_soc_dapm_micbias:
1611 case snd_soc_dapm_dac:
1612 case snd_soc_dapm_adc:
1613 case snd_soc_dapm_pga:
1614 case snd_soc_dapm_out_drv:
1615 case snd_soc_dapm_mixer:
1616 case snd_soc_dapm_mixer_named_ctl:
1617 case snd_soc_dapm_supply:
1619 count += sprintf(buf + count, "%s: %s\n",
1620 w->name, w->power ? "On":"Off");
1627 switch (codec->dapm.bias_level) {
1628 case SND_SOC_BIAS_ON:
1631 case SND_SOC_BIAS_PREPARE:
1634 case SND_SOC_BIAS_STANDBY:
1637 case SND_SOC_BIAS_OFF:
1641 count += sprintf(buf + count, "PM State: %s\n", state);
1646 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1648 int snd_soc_dapm_sys_add(struct device *dev)
1650 return device_create_file(dev, &dev_attr_dapm_widget);
1653 static void snd_soc_dapm_sys_remove(struct device *dev)
1655 device_remove_file(dev, &dev_attr_dapm_widget);
1658 /* free all dapm widgets and resources */
1659 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1661 struct snd_soc_dapm_widget *w, *next_w;
1662 struct snd_soc_dapm_path *p, *next_p;
1664 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1665 if (w->dapm != dapm)
1669 * remove source and sink paths associated to this widget.
1670 * While removing the path, remove reference to it from both
1671 * source and sink widgets so that path is removed only once.
1673 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1674 list_del(&p->list_sink);
1675 list_del(&p->list_source);
1677 kfree(p->long_name);
1680 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1681 list_del(&p->list_sink);
1682 list_del(&p->list_source);
1684 kfree(p->long_name);
1687 kfree(w->kcontrols);
1693 static struct snd_soc_dapm_widget *dapm_find_widget(
1694 struct snd_soc_dapm_context *dapm, const char *pin,
1695 bool search_other_contexts)
1697 struct snd_soc_dapm_widget *w;
1698 struct snd_soc_dapm_widget *fallback = NULL;
1700 list_for_each_entry(w, &dapm->card->widgets, list) {
1701 if (!strcmp(w->name, pin)) {
1702 if (w->dapm == dapm)
1709 if (search_other_contexts)
1715 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1716 const char *pin, int status)
1718 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
1721 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1725 w->connected = status;
1733 * snd_soc_dapm_sync - scan and power dapm paths
1734 * @dapm: DAPM context
1736 * Walks all dapm audio paths and powers widgets according to their
1737 * stream or path usage.
1739 * Returns 0 for success.
1741 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1743 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1745 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1747 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1748 const struct snd_soc_dapm_route *route)
1750 struct snd_soc_dapm_path *path;
1751 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1752 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1754 const char *control = route->control;
1756 char prefixed_sink[80];
1757 char prefixed_source[80];
1760 if (dapm->codec && dapm->codec->name_prefix) {
1761 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1762 dapm->codec->name_prefix, route->sink);
1763 sink = prefixed_sink;
1764 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1765 dapm->codec->name_prefix, route->source);
1766 source = prefixed_source;
1769 source = route->source;
1773 * find src and dest widgets over all widgets but favor a widget from
1774 * current DAPM context
1776 list_for_each_entry(w, &dapm->card->widgets, list) {
1777 if (!wsink && !(strcmp(w->name, sink))) {
1779 if (w->dapm == dapm)
1783 if (!wsource && !(strcmp(w->name, source))) {
1785 if (w->dapm == dapm)
1789 /* use widget from another DAPM context if not found from this */
1795 if (wsource == NULL || wsink == NULL)
1798 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1802 path->source = wsource;
1804 path->connected = route->connected;
1805 INIT_LIST_HEAD(&path->list);
1806 INIT_LIST_HEAD(&path->list_source);
1807 INIT_LIST_HEAD(&path->list_sink);
1809 /* check for external widgets */
1810 if (wsink->id == snd_soc_dapm_input) {
1811 if (wsource->id == snd_soc_dapm_micbias ||
1812 wsource->id == snd_soc_dapm_mic ||
1813 wsource->id == snd_soc_dapm_line ||
1814 wsource->id == snd_soc_dapm_output)
1817 if (wsource->id == snd_soc_dapm_output) {
1818 if (wsink->id == snd_soc_dapm_spk ||
1819 wsink->id == snd_soc_dapm_hp ||
1820 wsink->id == snd_soc_dapm_line ||
1821 wsink->id == snd_soc_dapm_input)
1825 /* connect static paths */
1826 if (control == NULL) {
1827 list_add(&path->list, &dapm->card->paths);
1828 list_add(&path->list_sink, &wsink->sources);
1829 list_add(&path->list_source, &wsource->sinks);
1834 /* connect dynamic paths */
1835 switch (wsink->id) {
1836 case snd_soc_dapm_adc:
1837 case snd_soc_dapm_dac:
1838 case snd_soc_dapm_pga:
1839 case snd_soc_dapm_out_drv:
1840 case snd_soc_dapm_input:
1841 case snd_soc_dapm_output:
1842 case snd_soc_dapm_micbias:
1843 case snd_soc_dapm_vmid:
1844 case snd_soc_dapm_pre:
1845 case snd_soc_dapm_post:
1846 case snd_soc_dapm_supply:
1847 case snd_soc_dapm_aif_in:
1848 case snd_soc_dapm_aif_out:
1849 list_add(&path->list, &dapm->card->paths);
1850 list_add(&path->list_sink, &wsink->sources);
1851 list_add(&path->list_source, &wsource->sinks);
1854 case snd_soc_dapm_mux:
1855 case snd_soc_dapm_virt_mux:
1856 case snd_soc_dapm_value_mux:
1857 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1858 &wsink->kcontrol_news[0]);
1862 case snd_soc_dapm_switch:
1863 case snd_soc_dapm_mixer:
1864 case snd_soc_dapm_mixer_named_ctl:
1865 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
1869 case snd_soc_dapm_hp:
1870 case snd_soc_dapm_mic:
1871 case snd_soc_dapm_line:
1872 case snd_soc_dapm_spk:
1873 list_add(&path->list, &dapm->card->paths);
1874 list_add(&path->list_sink, &wsink->sources);
1875 list_add(&path->list_source, &wsource->sinks);
1882 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
1883 source, control, sink);
1889 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1890 * @dapm: DAPM context
1891 * @route: audio routes
1892 * @num: number of routes
1894 * Connects 2 dapm widgets together via a named audio path. The sink is
1895 * the widget receiving the audio signal, whilst the source is the sender
1896 * of the audio signal.
1898 * Returns 0 for success else error. On error all resources can be freed
1899 * with a call to snd_soc_card_free().
1901 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1902 const struct snd_soc_dapm_route *route, int num)
1906 for (i = 0; i < num; i++) {
1907 ret = snd_soc_dapm_add_route(dapm, route);
1909 dev_err(dapm->dev, "Failed to add route %s->%s\n",
1910 route->source, route->sink);
1918 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1920 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
1921 const struct snd_soc_dapm_route *route)
1923 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
1926 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
1929 struct snd_soc_dapm_path *path;
1933 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
1939 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
1944 if (route->control || route->connected)
1945 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
1946 route->source, route->sink);
1948 list_for_each_entry(path, &source->sinks, list_source) {
1949 if (path->sink == sink) {
1956 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
1957 route->source, route->sink);
1959 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
1960 count, route->source, route->sink);
1966 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
1967 * @dapm: DAPM context
1968 * @route: audio routes
1969 * @num: number of routes
1971 * Mark existing routes matching those specified in the passed array
1972 * as being weak, meaning that they are ignored for the purpose of
1973 * power decisions. The main intended use case is for sidetone paths
1974 * which couple audio between other independent paths if they are both
1975 * active in order to make the combination work better at the user
1976 * level but which aren't intended to be "used".
1978 * Note that CODEC drivers should not use this as sidetone type paths
1979 * can frequently also be used as bypass paths.
1981 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
1982 const struct snd_soc_dapm_route *route, int num)
1987 for (i = 0; i < num; i++) {
1988 err = snd_soc_dapm_weak_route(dapm, route);
1996 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
1999 * snd_soc_dapm_new_widgets - add new dapm widgets
2000 * @dapm: DAPM context
2002 * Checks the codec for any new dapm widgets and creates them if found.
2004 * Returns 0 for success.
2006 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2008 struct snd_soc_dapm_widget *w;
2011 list_for_each_entry(w, &dapm->card->widgets, list)
2016 if (w->num_kcontrols) {
2017 w->kcontrols = kzalloc(w->num_kcontrols *
2018 sizeof(struct snd_kcontrol *),
2025 case snd_soc_dapm_switch:
2026 case snd_soc_dapm_mixer:
2027 case snd_soc_dapm_mixer_named_ctl:
2028 w->power_check = dapm_generic_check_power;
2031 case snd_soc_dapm_mux:
2032 case snd_soc_dapm_virt_mux:
2033 case snd_soc_dapm_value_mux:
2034 w->power_check = dapm_generic_check_power;
2037 case snd_soc_dapm_adc:
2038 case snd_soc_dapm_aif_out:
2039 w->power_check = dapm_adc_check_power;
2041 case snd_soc_dapm_dac:
2042 case snd_soc_dapm_aif_in:
2043 w->power_check = dapm_dac_check_power;
2045 case snd_soc_dapm_pga:
2046 case snd_soc_dapm_out_drv:
2047 w->power_check = dapm_generic_check_power;
2050 case snd_soc_dapm_input:
2051 case snd_soc_dapm_output:
2052 case snd_soc_dapm_micbias:
2053 case snd_soc_dapm_spk:
2054 case snd_soc_dapm_hp:
2055 case snd_soc_dapm_mic:
2056 case snd_soc_dapm_line:
2057 w->power_check = dapm_generic_check_power;
2059 case snd_soc_dapm_supply:
2060 w->power_check = dapm_supply_check_power;
2061 case snd_soc_dapm_vmid:
2062 case snd_soc_dapm_pre:
2063 case snd_soc_dapm_post:
2067 /* Read the initial power state from the device */
2069 val = soc_widget_read(w, w->reg);
2070 val &= 1 << w->shift;
2080 dapm_debugfs_add_widget(w);
2083 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2086 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2089 * snd_soc_dapm_get_volsw - dapm mixer get callback
2090 * @kcontrol: mixer control
2091 * @ucontrol: control element information
2093 * Callback to get the value of a dapm mixer control.
2095 * Returns 0 for success.
2097 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2098 struct snd_ctl_elem_value *ucontrol)
2100 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2101 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2102 struct soc_mixer_control *mc =
2103 (struct soc_mixer_control *)kcontrol->private_value;
2104 unsigned int reg = mc->reg;
2105 unsigned int shift = mc->shift;
2106 unsigned int rshift = mc->rshift;
2108 unsigned int invert = mc->invert;
2109 unsigned int mask = (1 << fls(max)) - 1;
2111 ucontrol->value.integer.value[0] =
2112 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2113 if (shift != rshift)
2114 ucontrol->value.integer.value[1] =
2115 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2117 ucontrol->value.integer.value[0] =
2118 max - ucontrol->value.integer.value[0];
2119 if (shift != rshift)
2120 ucontrol->value.integer.value[1] =
2121 max - ucontrol->value.integer.value[1];
2126 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2129 * snd_soc_dapm_put_volsw - dapm mixer set callback
2130 * @kcontrol: mixer control
2131 * @ucontrol: control element information
2133 * Callback to set the value of a dapm mixer control.
2135 * Returns 0 for success.
2137 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2138 struct snd_ctl_elem_value *ucontrol)
2140 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2141 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2142 struct snd_soc_codec *codec = widget->codec;
2143 struct soc_mixer_control *mc =
2144 (struct soc_mixer_control *)kcontrol->private_value;
2145 unsigned int reg = mc->reg;
2146 unsigned int shift = mc->shift;
2148 unsigned int mask = (1 << fls(max)) - 1;
2149 unsigned int invert = mc->invert;
2151 int connect, change;
2152 struct snd_soc_dapm_update update;
2155 val = (ucontrol->value.integer.value[0] & mask);
2159 mask = mask << shift;
2163 /* new connection */
2164 connect = invert ? 0 : 1;
2166 /* old connection must be powered down */
2167 connect = invert ? 1 : 0;
2169 mutex_lock(&codec->mutex);
2171 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2173 for (wi = 0; wi < wlist->num_widgets; wi++) {
2174 widget = wlist->widgets[wi];
2176 widget->value = val;
2178 update.kcontrol = kcontrol;
2179 update.widget = widget;
2183 widget->dapm->update = &update;
2185 dapm_mixer_update_power(widget, kcontrol, connect);
2187 widget->dapm->update = NULL;
2191 mutex_unlock(&codec->mutex);
2194 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2197 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2198 * @kcontrol: mixer control
2199 * @ucontrol: control element information
2201 * Callback to get the value of a dapm enumerated double mixer control.
2203 * Returns 0 for success.
2205 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2206 struct snd_ctl_elem_value *ucontrol)
2208 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2209 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2210 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2211 unsigned int val, bitmask;
2213 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2215 val = snd_soc_read(widget->codec, e->reg);
2216 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2217 if (e->shift_l != e->shift_r)
2218 ucontrol->value.enumerated.item[1] =
2219 (val >> e->shift_r) & (bitmask - 1);
2223 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2226 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2227 * @kcontrol: mixer control
2228 * @ucontrol: control element information
2230 * Callback to set the value of a dapm enumerated double mixer control.
2232 * Returns 0 for success.
2234 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2235 struct snd_ctl_elem_value *ucontrol)
2237 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2238 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2239 struct snd_soc_codec *codec = widget->codec;
2240 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2241 unsigned int val, mux, change;
2242 unsigned int mask, bitmask;
2243 struct snd_soc_dapm_update update;
2246 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2248 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2250 mux = ucontrol->value.enumerated.item[0];
2251 val = mux << e->shift_l;
2252 mask = (bitmask - 1) << e->shift_l;
2253 if (e->shift_l != e->shift_r) {
2254 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2256 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2257 mask |= (bitmask - 1) << e->shift_r;
2260 mutex_lock(&codec->mutex);
2262 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2264 for (wi = 0; wi < wlist->num_widgets; wi++) {
2265 widget = wlist->widgets[wi];
2267 widget->value = val;
2269 update.kcontrol = kcontrol;
2270 update.widget = widget;
2271 update.reg = e->reg;
2274 widget->dapm->update = &update;
2276 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2278 widget->dapm->update = NULL;
2282 mutex_unlock(&codec->mutex);
2285 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2288 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2289 * @kcontrol: mixer control
2290 * @ucontrol: control element information
2292 * Returns 0 for success.
2294 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2295 struct snd_ctl_elem_value *ucontrol)
2297 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2298 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2300 ucontrol->value.enumerated.item[0] = widget->value;
2304 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2307 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2308 * @kcontrol: mixer control
2309 * @ucontrol: control element information
2311 * Returns 0 for success.
2313 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2314 struct snd_ctl_elem_value *ucontrol)
2316 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2317 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2318 struct snd_soc_codec *codec = widget->codec;
2319 struct soc_enum *e =
2320 (struct soc_enum *)kcontrol->private_value;
2325 if (ucontrol->value.enumerated.item[0] >= e->max)
2328 mutex_lock(&codec->mutex);
2330 change = widget->value != ucontrol->value.enumerated.item[0];
2332 for (wi = 0; wi < wlist->num_widgets; wi++) {
2333 widget = wlist->widgets[wi];
2335 widget->value = ucontrol->value.enumerated.item[0];
2337 dapm_mux_update_power(widget, kcontrol, change,
2342 mutex_unlock(&codec->mutex);
2345 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2348 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2350 * @kcontrol: mixer control
2351 * @ucontrol: control element information
2353 * Callback to get the value of a dapm semi enumerated double mixer control.
2355 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2356 * used for handling bitfield coded enumeration for example.
2358 * Returns 0 for success.
2360 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2361 struct snd_ctl_elem_value *ucontrol)
2363 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2364 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2365 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2366 unsigned int reg_val, val, mux;
2368 reg_val = snd_soc_read(widget->codec, e->reg);
2369 val = (reg_val >> e->shift_l) & e->mask;
2370 for (mux = 0; mux < e->max; mux++) {
2371 if (val == e->values[mux])
2374 ucontrol->value.enumerated.item[0] = mux;
2375 if (e->shift_l != e->shift_r) {
2376 val = (reg_val >> e->shift_r) & e->mask;
2377 for (mux = 0; mux < e->max; mux++) {
2378 if (val == e->values[mux])
2381 ucontrol->value.enumerated.item[1] = mux;
2386 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2389 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2391 * @kcontrol: mixer control
2392 * @ucontrol: control element information
2394 * Callback to set the value of a dapm semi enumerated double mixer control.
2396 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2397 * used for handling bitfield coded enumeration for example.
2399 * Returns 0 for success.
2401 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2402 struct snd_ctl_elem_value *ucontrol)
2404 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2405 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2406 struct snd_soc_codec *codec = widget->codec;
2407 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2408 unsigned int val, mux, change;
2410 struct snd_soc_dapm_update update;
2413 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2415 mux = ucontrol->value.enumerated.item[0];
2416 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2417 mask = e->mask << e->shift_l;
2418 if (e->shift_l != e->shift_r) {
2419 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2421 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2422 mask |= e->mask << e->shift_r;
2425 mutex_lock(&codec->mutex);
2427 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2429 for (wi = 0; wi < wlist->num_widgets; wi++) {
2430 widget = wlist->widgets[wi];
2432 widget->value = val;
2434 update.kcontrol = kcontrol;
2435 update.widget = widget;
2436 update.reg = e->reg;
2439 widget->dapm->update = &update;
2441 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2443 widget->dapm->update = NULL;
2447 mutex_unlock(&codec->mutex);
2450 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2453 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2455 * @kcontrol: mixer control
2456 * @uinfo: control element information
2458 * Callback to provide information about a pin switch control.
2460 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2461 struct snd_ctl_elem_info *uinfo)
2463 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2465 uinfo->value.integer.min = 0;
2466 uinfo->value.integer.max = 1;
2470 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2473 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2475 * @kcontrol: mixer control
2478 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2479 struct snd_ctl_elem_value *ucontrol)
2481 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2482 const char *pin = (const char *)kcontrol->private_value;
2484 mutex_lock(&codec->mutex);
2486 ucontrol->value.integer.value[0] =
2487 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
2489 mutex_unlock(&codec->mutex);
2493 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2496 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2498 * @kcontrol: mixer control
2501 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2502 struct snd_ctl_elem_value *ucontrol)
2504 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2505 const char *pin = (const char *)kcontrol->private_value;
2507 mutex_lock(&codec->mutex);
2509 if (ucontrol->value.integer.value[0])
2510 snd_soc_dapm_enable_pin(&codec->dapm, pin);
2512 snd_soc_dapm_disable_pin(&codec->dapm, pin);
2514 snd_soc_dapm_sync(&codec->dapm);
2516 mutex_unlock(&codec->mutex);
2520 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2523 * snd_soc_dapm_new_control - create new dapm control
2524 * @dapm: DAPM context
2525 * @widget: widget template
2527 * Creates a new dapm control based upon the template.
2529 * Returns 0 for success else error.
2531 int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2532 const struct snd_soc_dapm_widget *widget)
2534 struct snd_soc_dapm_widget *w;
2537 if ((w = dapm_cnew_widget(widget)) == NULL)
2540 name_len = strlen(widget->name) + 1;
2541 if (dapm->codec && dapm->codec->name_prefix)
2542 name_len += 1 + strlen(dapm->codec->name_prefix);
2543 w->name = kmalloc(name_len, GFP_KERNEL);
2544 if (w->name == NULL) {
2548 if (dapm->codec && dapm->codec->name_prefix)
2549 snprintf(w->name, name_len, "%s %s",
2550 dapm->codec->name_prefix, widget->name);
2552 snprintf(w->name, name_len, "%s", widget->name);
2556 w->codec = dapm->codec;
2557 w->platform = dapm->platform;
2558 INIT_LIST_HEAD(&w->sources);
2559 INIT_LIST_HEAD(&w->sinks);
2560 INIT_LIST_HEAD(&w->list);
2561 list_add(&w->list, &dapm->card->widgets);
2563 /* machine layer set ups unconnected pins and insertions */
2567 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
2570 * snd_soc_dapm_new_controls - create new dapm controls
2571 * @dapm: DAPM context
2572 * @widget: widget array
2573 * @num: number of widgets
2575 * Creates new DAPM controls based upon the templates.
2577 * Returns 0 for success else error.
2579 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2580 const struct snd_soc_dapm_widget *widget,
2585 for (i = 0; i < num; i++) {
2586 ret = snd_soc_dapm_new_control(dapm, widget);
2589 "ASoC: Failed to create DAPM control %s: %d\n",
2597 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2599 static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2600 const char *stream, int event)
2602 struct snd_soc_dapm_widget *w;
2604 list_for_each_entry(w, &dapm->card->widgets, list)
2606 if (!w->sname || w->dapm != dapm)
2608 dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2609 w->name, w->sname, stream, event);
2610 if (strstr(w->sname, stream)) {
2612 case SND_SOC_DAPM_STREAM_START:
2615 case SND_SOC_DAPM_STREAM_STOP:
2618 case SND_SOC_DAPM_STREAM_SUSPEND:
2619 case SND_SOC_DAPM_STREAM_RESUME:
2620 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
2621 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2627 dapm_power_widgets(dapm, event);
2629 /* do we need to notify any clients that DAPM stream is complete */
2630 if (dapm->stream_event)
2631 dapm->stream_event(dapm, event);
2635 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2636 * @rtd: PCM runtime data
2637 * @stream: stream name
2638 * @event: stream event
2640 * Sends a stream event to the dapm core. The core then makes any
2641 * necessary widget power changes.
2643 * Returns 0 for success else error.
2645 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2646 const char *stream, int event)
2648 struct snd_soc_codec *codec = rtd->codec;
2653 mutex_lock(&codec->mutex);
2654 soc_dapm_stream_event(&codec->dapm, stream, event);
2655 mutex_unlock(&codec->mutex);
2660 * snd_soc_dapm_enable_pin - enable pin.
2661 * @dapm: DAPM context
2664 * Enables input/output pin and its parents or children widgets iff there is
2665 * a valid audio route and active audio stream.
2666 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2667 * do any widget power switching.
2669 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2671 return snd_soc_dapm_set_pin(dapm, pin, 1);
2673 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2676 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2677 * @dapm: DAPM context
2680 * Enables input/output pin regardless of any other state. This is
2681 * intended for use with microphone bias supplies used in microphone
2684 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2685 * do any widget power switching.
2687 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2690 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2693 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2697 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
2703 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2706 * snd_soc_dapm_disable_pin - disable pin.
2707 * @dapm: DAPM context
2710 * Disables input/output pin and its parents or children widgets.
2711 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2712 * do any widget power switching.
2714 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2717 return snd_soc_dapm_set_pin(dapm, pin, 0);
2719 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2722 * snd_soc_dapm_nc_pin - permanently disable pin.
2723 * @dapm: DAPM context
2726 * Marks the specified pin as being not connected, disabling it along
2727 * any parent or child widgets. At present this is identical to
2728 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2729 * additional things such as disabling controls which only affect
2730 * paths through the pin.
2732 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2733 * do any widget power switching.
2735 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2737 return snd_soc_dapm_set_pin(dapm, pin, 0);
2739 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2742 * snd_soc_dapm_get_pin_status - get audio pin status
2743 * @dapm: DAPM context
2744 * @pin: audio signal pin endpoint (or start point)
2746 * Get audio pin status - connected or disconnected.
2748 * Returns 1 for connected otherwise 0.
2750 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2753 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2756 return w->connected;
2760 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2763 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2764 * @dapm: DAPM context
2765 * @pin: audio signal pin endpoint (or start point)
2767 * Mark the given endpoint or pin as ignoring suspend. When the
2768 * system is disabled a path between two endpoints flagged as ignoring
2769 * suspend will not be disabled. The path must already be enabled via
2770 * normal means at suspend time, it will not be turned on if it was not
2773 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2776 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
2779 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2783 w->ignore_suspend = 1;
2787 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2790 * snd_soc_dapm_free - free dapm resources
2791 * @dapm: DAPM context
2793 * Free all dapm widgets and resources.
2795 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2797 snd_soc_dapm_sys_remove(dapm->dev);
2798 dapm_debugfs_cleanup(dapm);
2799 dapm_free_widgets(dapm);
2800 list_del(&dapm->list);
2802 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2804 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2806 struct snd_soc_dapm_widget *w;
2807 LIST_HEAD(down_list);
2810 list_for_each_entry(w, &dapm->card->widgets, list) {
2811 if (w->dapm != dapm)
2814 dapm_seq_insert(w, &down_list, false);
2820 /* If there were no widgets to power down we're already in
2824 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
2825 dapm_seq_run(dapm, &down_list, 0, false);
2826 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
2831 * snd_soc_dapm_shutdown - callback for system shutdown
2833 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2835 struct snd_soc_codec *codec;
2837 list_for_each_entry(codec, &card->codec_dev_list, list) {
2838 soc_dapm_shutdown_codec(&codec->dapm);
2839 snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
2843 /* Module information */
2844 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2845 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2846 MODULE_LICENSE("GPL");