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) {
680 DAPM_UPDATE_STAT(widget, neighbour_checks);
688 if (path->sink && path->connect) {
690 con += is_connected_output_ep(path->sink);
698 * Recursively check for a completed path to an active or physically connected
699 * input widget. Returns number of complete paths.
701 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
703 struct snd_soc_dapm_path *path;
706 DAPM_UPDATE_STAT(widget, path_checks);
708 if (widget->id == snd_soc_dapm_supply)
711 /* active stream ? */
712 switch (widget->id) {
713 case snd_soc_dapm_dac:
714 case snd_soc_dapm_aif_in:
716 return snd_soc_dapm_suspend_check(widget);
721 if (widget->connected) {
722 /* connected pin ? */
723 if (widget->id == snd_soc_dapm_input && !widget->ext)
724 return snd_soc_dapm_suspend_check(widget);
726 /* connected VMID/Bias for lower pops */
727 if (widget->id == snd_soc_dapm_vmid)
728 return snd_soc_dapm_suspend_check(widget);
730 /* connected jack ? */
731 if (widget->id == snd_soc_dapm_mic ||
732 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
733 return snd_soc_dapm_suspend_check(widget);
736 list_for_each_entry(path, &widget->sources, list_sink) {
737 DAPM_UPDATE_STAT(widget, neighbour_checks);
745 if (path->source && path->connect) {
747 con += is_connected_input_ep(path->source);
755 * Handler for generic register modifier widget.
757 int dapm_reg_event(struct snd_soc_dapm_widget *w,
758 struct snd_kcontrol *kcontrol, int event)
762 if (SND_SOC_DAPM_EVENT_ON(event))
767 soc_widget_update_bits(w, -(w->reg + 1),
768 w->mask << w->shift, val << w->shift);
772 EXPORT_SYMBOL_GPL(dapm_reg_event);
774 /* Generic check to see if a widget should be powered.
776 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
780 DAPM_UPDATE_STAT(w, power_checks);
782 in = is_connected_input_ep(w);
783 dapm_clear_walk(w->dapm);
784 out = is_connected_output_ep(w);
785 dapm_clear_walk(w->dapm);
786 return out != 0 && in != 0;
789 /* Check to see if an ADC has power */
790 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
794 DAPM_UPDATE_STAT(w, power_checks);
797 in = is_connected_input_ep(w);
798 dapm_clear_walk(w->dapm);
801 return dapm_generic_check_power(w);
805 /* Check to see if a DAC has power */
806 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
810 DAPM_UPDATE_STAT(w, power_checks);
813 out = is_connected_output_ep(w);
814 dapm_clear_walk(w->dapm);
817 return dapm_generic_check_power(w);
821 /* Check to see if a power supply is needed */
822 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
824 struct snd_soc_dapm_path *path;
827 DAPM_UPDATE_STAT(w, power_checks);
829 /* Check if one of our outputs is connected */
830 list_for_each_entry(path, &w->sinks, list_source) {
834 if (path->connected &&
835 !path->connected(path->source, path->sink))
841 if (path->sink->force) {
846 if (path->sink->power_check &&
847 path->sink->power_check(path->sink)) {
853 dapm_clear_walk(w->dapm);
858 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
859 struct snd_soc_dapm_widget *b,
867 sort = dapm_down_seq;
869 if (sort[a->id] != sort[b->id])
870 return sort[a->id] - sort[b->id];
871 if (a->subseq != b->subseq) {
873 return a->subseq - b->subseq;
875 return b->subseq - a->subseq;
877 if (a->reg != b->reg)
878 return a->reg - b->reg;
879 if (a->dapm != b->dapm)
880 return (unsigned long)a->dapm - (unsigned long)b->dapm;
885 /* Insert a widget in order into a DAPM power sequence. */
886 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
887 struct list_head *list,
890 struct snd_soc_dapm_widget *w;
892 list_for_each_entry(w, list, power_list)
893 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
894 list_add_tail(&new_widget->power_list, &w->power_list);
898 list_add_tail(&new_widget->power_list, list);
901 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
902 struct snd_soc_dapm_widget *w, int event)
904 struct snd_soc_card *card = dapm->card;
909 case SND_SOC_DAPM_PRE_PMU:
913 case SND_SOC_DAPM_POST_PMU:
914 ev_name = "POST_PMU";
917 case SND_SOC_DAPM_PRE_PMD:
921 case SND_SOC_DAPM_POST_PMD:
922 ev_name = "POST_PMD";
930 if (w->power != power)
933 if (w->event && (w->event_flags & event)) {
934 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
936 trace_snd_soc_dapm_widget_event_start(w, event);
937 ret = w->event(w, NULL, event);
938 trace_snd_soc_dapm_widget_event_done(w, event);
940 pr_err("%s: %s event failed: %d\n",
941 ev_name, w->name, ret);
945 /* Apply the coalesced changes from a DAPM sequence */
946 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
947 struct list_head *pending)
949 struct snd_soc_card *card = dapm->card;
950 struct snd_soc_dapm_widget *w;
952 unsigned int value = 0;
953 unsigned int mask = 0;
954 unsigned int cur_mask;
956 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
959 list_for_each_entry(w, pending, power_list) {
960 cur_mask = 1 << w->shift;
961 BUG_ON(reg != w->reg);
972 pop_dbg(dapm->dev, card->pop_time,
973 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
974 w->name, reg, value, mask);
976 /* Check for events */
977 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
978 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
982 /* Any widget will do, they should all be updating the
985 w = list_first_entry(pending, struct snd_soc_dapm_widget,
988 pop_dbg(dapm->dev, card->pop_time,
989 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
990 value, mask, reg, card->pop_time);
991 pop_wait(card->pop_time);
992 soc_widget_update_bits(w, reg, mask, value);
995 list_for_each_entry(w, pending, power_list) {
996 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
997 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
1001 /* Apply a DAPM power sequence.
1003 * We walk over a pre-sorted list of widgets to apply power to. In
1004 * order to minimise the number of writes to the device required
1005 * multiple widgets will be updated in a single write where possible.
1006 * Currently anything that requires more than a single write is not
1009 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1010 struct list_head *list, int event, bool power_up)
1012 struct snd_soc_dapm_widget *w, *n;
1015 int cur_subseq = -1;
1016 int cur_reg = SND_SOC_NOPM;
1017 struct snd_soc_dapm_context *cur_dapm = NULL;
1024 sort = dapm_down_seq;
1026 list_for_each_entry_safe(w, n, list, power_list) {
1029 /* Do we need to apply any queued changes? */
1030 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1031 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1032 if (!list_empty(&pending))
1033 dapm_seq_run_coalesced(cur_dapm, &pending);
1035 if (cur_dapm && cur_dapm->seq_notifier) {
1036 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1037 if (sort[i] == cur_sort)
1038 cur_dapm->seq_notifier(cur_dapm,
1043 INIT_LIST_HEAD(&pending);
1045 cur_subseq = INT_MIN;
1046 cur_reg = SND_SOC_NOPM;
1051 case snd_soc_dapm_pre:
1053 list_for_each_entry_safe_continue(w, n, list,
1056 if (event == SND_SOC_DAPM_STREAM_START)
1058 NULL, SND_SOC_DAPM_PRE_PMU);
1059 else if (event == SND_SOC_DAPM_STREAM_STOP)
1061 NULL, SND_SOC_DAPM_PRE_PMD);
1064 case snd_soc_dapm_post:
1066 list_for_each_entry_safe_continue(w, n, list,
1069 if (event == SND_SOC_DAPM_STREAM_START)
1071 NULL, SND_SOC_DAPM_POST_PMU);
1072 else if (event == SND_SOC_DAPM_STREAM_STOP)
1074 NULL, SND_SOC_DAPM_POST_PMD);
1078 /* Queue it up for application */
1079 cur_sort = sort[w->id];
1080 cur_subseq = w->subseq;
1083 list_move(&w->power_list, &pending);
1088 dev_err(w->dapm->dev,
1089 "Failed to apply widget power: %d\n", ret);
1092 if (!list_empty(&pending))
1093 dapm_seq_run_coalesced(cur_dapm, &pending);
1095 if (cur_dapm && cur_dapm->seq_notifier) {
1096 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1097 if (sort[i] == cur_sort)
1098 cur_dapm->seq_notifier(cur_dapm,
1103 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1105 struct snd_soc_dapm_update *update = dapm->update;
1106 struct snd_soc_dapm_widget *w;
1115 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1116 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1118 pr_err("%s DAPM pre-event failed: %d\n",
1122 ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
1125 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1128 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1129 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1131 pr_err("%s DAPM post-event failed: %d\n",
1136 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1137 * they're changing state.
1139 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1141 struct snd_soc_dapm_context *d = data;
1144 /* If we're off and we're not supposed to be go into STANDBY */
1145 if (d->bias_level == SND_SOC_BIAS_OFF &&
1146 d->target_bias_level != SND_SOC_BIAS_OFF) {
1147 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1150 "Failed to turn on bias: %d\n", ret);
1153 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1154 if (d->bias_level != d->target_bias_level) {
1155 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1158 "Failed to prepare bias: %d\n", ret);
1162 /* Async callback run prior to DAPM sequences - brings to their final
1165 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1167 struct snd_soc_dapm_context *d = data;
1170 /* If we just powered the last thing off drop to standby bias */
1171 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1172 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1173 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1174 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1176 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1180 /* If we're in standby and can support bias off then do that */
1181 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1182 d->target_bias_level == SND_SOC_BIAS_OFF) {
1183 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1185 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1188 /* If we just powered up then move to active bias */
1189 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1190 d->target_bias_level == SND_SOC_BIAS_ON) {
1191 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1193 dev_err(d->dev, "Failed to apply active bias: %d\n",
1198 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1199 struct list_head *up_list,
1200 struct list_head *down_list)
1202 struct snd_soc_dapm_context *d;
1206 case snd_soc_dapm_pre:
1207 dapm_seq_insert(w, down_list, false);
1209 case snd_soc_dapm_post:
1210 dapm_seq_insert(w, up_list, true);
1214 if (!w->power_check)
1218 power = w->power_check(w);
1225 /* Supplies and micbiases only bring the
1226 * context up to STANDBY as unless something
1227 * else is active and passing audio they
1228 * generally don't require full power.
1231 case snd_soc_dapm_supply:
1232 case snd_soc_dapm_micbias:
1233 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1234 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1237 d->target_bias_level = SND_SOC_BIAS_ON;
1242 if (w->power == power)
1245 trace_snd_soc_dapm_widget_power(w, power);
1248 dapm_seq_insert(w, up_list, true);
1250 dapm_seq_insert(w, down_list, false);
1258 * Scan each dapm widget for complete audio path.
1259 * A complete path is a route that has valid endpoints i.e.:-
1261 * o DAC to output pin.
1262 * o Input Pin to ADC.
1263 * o Input pin to Output pin (bypass, sidetone)
1264 * o DAC to ADC (loopback).
1266 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1268 struct snd_soc_card *card = dapm->card;
1269 struct snd_soc_dapm_widget *w;
1270 struct snd_soc_dapm_context *d;
1272 LIST_HEAD(down_list);
1273 LIST_HEAD(async_domain);
1274 enum snd_soc_bias_level bias;
1276 trace_snd_soc_dapm_start(card);
1278 list_for_each_entry(d, &card->dapm_list, list) {
1279 if (d->n_widgets || d->codec == NULL) {
1280 if (d->idle_bias_off)
1281 d->target_bias_level = SND_SOC_BIAS_OFF;
1283 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1287 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
1289 /* Check which widgets we need to power and store them in
1290 * lists indicating if they should be powered up or down.
1292 list_for_each_entry(w, &card->widgets, list) {
1293 dapm_power_one_widget(w, &up_list, &down_list);
1296 /* If there are no DAPM widgets then try to figure out power from the
1299 if (!dapm->n_widgets) {
1301 case SND_SOC_DAPM_STREAM_START:
1302 case SND_SOC_DAPM_STREAM_RESUME:
1303 dapm->target_bias_level = SND_SOC_BIAS_ON;
1305 case SND_SOC_DAPM_STREAM_STOP:
1306 if (dapm->codec->active)
1307 dapm->target_bias_level = SND_SOC_BIAS_ON;
1309 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1311 case SND_SOC_DAPM_STREAM_SUSPEND:
1312 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1314 case SND_SOC_DAPM_STREAM_NOP:
1315 dapm->target_bias_level = dapm->bias_level;
1322 /* Force all contexts in the card to the same bias state if
1323 * they're not ground referenced.
1325 bias = SND_SOC_BIAS_OFF;
1326 list_for_each_entry(d, &card->dapm_list, list)
1327 if (d->target_bias_level > bias)
1328 bias = d->target_bias_level;
1329 list_for_each_entry(d, &card->dapm_list, list)
1330 if (!d->idle_bias_off)
1331 d->target_bias_level = bias;
1333 trace_snd_soc_dapm_walk_done(card);
1335 /* Run all the bias changes in parallel */
1336 list_for_each_entry(d, &dapm->card->dapm_list, list)
1337 async_schedule_domain(dapm_pre_sequence_async, d,
1339 async_synchronize_full_domain(&async_domain);
1341 /* Power down widgets first; try to avoid amplifying pops. */
1342 dapm_seq_run(dapm, &down_list, event, false);
1344 dapm_widget_update(dapm);
1347 dapm_seq_run(dapm, &up_list, event, true);
1349 /* Run all the bias changes in parallel */
1350 list_for_each_entry(d, &dapm->card->dapm_list, list)
1351 async_schedule_domain(dapm_post_sequence_async, d,
1353 async_synchronize_full_domain(&async_domain);
1355 pop_dbg(dapm->dev, card->pop_time,
1356 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1357 pop_wait(card->pop_time);
1359 trace_snd_soc_dapm_done(card);
1364 #ifdef CONFIG_DEBUG_FS
1365 static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1367 file->private_data = inode->i_private;
1371 static ssize_t dapm_widget_power_read_file(struct file *file,
1372 char __user *user_buf,
1373 size_t count, loff_t *ppos)
1375 struct snd_soc_dapm_widget *w = file->private_data;
1379 struct snd_soc_dapm_path *p = NULL;
1381 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1385 in = is_connected_input_ep(w);
1386 dapm_clear_walk(w->dapm);
1387 out = is_connected_output_ep(w);
1388 dapm_clear_walk(w->dapm);
1390 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
1391 w->name, w->power ? "On" : "Off", in, out);
1394 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1395 " - R%d(0x%x) bit %d",
1396 w->reg, w->reg, w->shift);
1398 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1401 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1403 w->active ? "active" : "inactive");
1405 list_for_each_entry(p, &w->sources, list_sink) {
1406 if (p->connected && !p->connected(w, p->sink))
1410 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1411 " in \"%s\" \"%s\"\n",
1412 p->name ? p->name : "static",
1415 list_for_each_entry(p, &w->sinks, list_source) {
1416 if (p->connected && !p->connected(w, p->sink))
1420 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1421 " out \"%s\" \"%s\"\n",
1422 p->name ? p->name : "static",
1426 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1432 static const struct file_operations dapm_widget_power_fops = {
1433 .open = dapm_widget_power_open_file,
1434 .read = dapm_widget_power_read_file,
1435 .llseek = default_llseek,
1438 static int dapm_bias_open_file(struct inode *inode, struct file *file)
1440 file->private_data = inode->i_private;
1444 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1445 size_t count, loff_t *ppos)
1447 struct snd_soc_dapm_context *dapm = file->private_data;
1450 switch (dapm->bias_level) {
1451 case SND_SOC_BIAS_ON:
1454 case SND_SOC_BIAS_PREPARE:
1455 level = "Prepare\n";
1457 case SND_SOC_BIAS_STANDBY:
1458 level = "Standby\n";
1460 case SND_SOC_BIAS_OFF:
1465 level = "Unknown\n";
1469 return simple_read_from_buffer(user_buf, count, ppos, level,
1473 static const struct file_operations dapm_bias_fops = {
1474 .open = dapm_bias_open_file,
1475 .read = dapm_bias_read_file,
1476 .llseek = default_llseek,
1479 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1480 struct dentry *parent)
1484 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1486 if (!dapm->debugfs_dapm) {
1488 "Failed to create DAPM debugfs directory\n");
1492 d = debugfs_create_file("bias_level", 0444,
1493 dapm->debugfs_dapm, dapm,
1497 "ASoC: Failed to create bias level debugfs file\n");
1500 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1502 struct snd_soc_dapm_context *dapm = w->dapm;
1505 if (!dapm->debugfs_dapm || !w->name)
1508 d = debugfs_create_file(w->name, 0444,
1509 dapm->debugfs_dapm, w,
1510 &dapm_widget_power_fops);
1512 dev_warn(w->dapm->dev,
1513 "ASoC: Failed to create %s debugfs file\n",
1517 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1519 debugfs_remove_recursive(dapm->debugfs_dapm);
1523 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1524 struct dentry *parent)
1528 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1532 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1538 /* test and update the power status of a mux widget */
1539 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1540 struct snd_kcontrol *kcontrol, int change,
1541 int mux, struct soc_enum *e)
1543 struct snd_soc_dapm_path *path;
1546 if (widget->id != snd_soc_dapm_mux &&
1547 widget->id != snd_soc_dapm_virt_mux &&
1548 widget->id != snd_soc_dapm_value_mux)
1554 /* find dapm widget path assoc with kcontrol */
1555 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1556 if (path->kcontrol != kcontrol)
1559 if (!path->name || !e->texts[mux])
1563 /* we now need to match the string in the enum to the path */
1564 if (!(strcmp(path->name, e->texts[mux])))
1565 path->connect = 1; /* new connection */
1567 path->connect = 0; /* old connection must be powered down */
1571 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1576 /* test and update the power status of a mixer or switch widget */
1577 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1578 struct snd_kcontrol *kcontrol, int connect)
1580 struct snd_soc_dapm_path *path;
1583 if (widget->id != snd_soc_dapm_mixer &&
1584 widget->id != snd_soc_dapm_mixer_named_ctl &&
1585 widget->id != snd_soc_dapm_switch)
1588 /* find dapm widget path assoc with kcontrol */
1589 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1590 if (path->kcontrol != kcontrol)
1593 /* found, now check type */
1595 path->connect = connect;
1599 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1604 /* show dapm widget status in sys fs */
1605 static ssize_t dapm_widget_show(struct device *dev,
1606 struct device_attribute *attr, char *buf)
1608 struct snd_soc_pcm_runtime *rtd =
1609 container_of(dev, struct snd_soc_pcm_runtime, dev);
1610 struct snd_soc_codec *codec =rtd->codec;
1611 struct snd_soc_dapm_widget *w;
1613 char *state = "not set";
1615 list_for_each_entry(w, &codec->card->widgets, list) {
1616 if (w->dapm != &codec->dapm)
1619 /* only display widgets that burnm power */
1621 case snd_soc_dapm_hp:
1622 case snd_soc_dapm_mic:
1623 case snd_soc_dapm_spk:
1624 case snd_soc_dapm_line:
1625 case snd_soc_dapm_micbias:
1626 case snd_soc_dapm_dac:
1627 case snd_soc_dapm_adc:
1628 case snd_soc_dapm_pga:
1629 case snd_soc_dapm_out_drv:
1630 case snd_soc_dapm_mixer:
1631 case snd_soc_dapm_mixer_named_ctl:
1632 case snd_soc_dapm_supply:
1634 count += sprintf(buf + count, "%s: %s\n",
1635 w->name, w->power ? "On":"Off");
1642 switch (codec->dapm.bias_level) {
1643 case SND_SOC_BIAS_ON:
1646 case SND_SOC_BIAS_PREPARE:
1649 case SND_SOC_BIAS_STANDBY:
1652 case SND_SOC_BIAS_OFF:
1656 count += sprintf(buf + count, "PM State: %s\n", state);
1661 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1663 int snd_soc_dapm_sys_add(struct device *dev)
1665 return device_create_file(dev, &dev_attr_dapm_widget);
1668 static void snd_soc_dapm_sys_remove(struct device *dev)
1670 device_remove_file(dev, &dev_attr_dapm_widget);
1673 /* free all dapm widgets and resources */
1674 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1676 struct snd_soc_dapm_widget *w, *next_w;
1677 struct snd_soc_dapm_path *p, *next_p;
1679 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1680 if (w->dapm != dapm)
1684 * remove source and sink paths associated to this widget.
1685 * While removing the path, remove reference to it from both
1686 * source and sink widgets so that path is removed only once.
1688 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1689 list_del(&p->list_sink);
1690 list_del(&p->list_source);
1692 kfree(p->long_name);
1695 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1696 list_del(&p->list_sink);
1697 list_del(&p->list_source);
1699 kfree(p->long_name);
1702 kfree(w->kcontrols);
1708 static struct snd_soc_dapm_widget *dapm_find_widget(
1709 struct snd_soc_dapm_context *dapm, const char *pin,
1710 bool search_other_contexts)
1712 struct snd_soc_dapm_widget *w;
1713 struct snd_soc_dapm_widget *fallback = NULL;
1715 list_for_each_entry(w, &dapm->card->widgets, list) {
1716 if (!strcmp(w->name, pin)) {
1717 if (w->dapm == dapm)
1724 if (search_other_contexts)
1730 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1731 const char *pin, int status)
1733 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
1736 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1740 w->connected = status;
1748 * snd_soc_dapm_sync - scan and power dapm paths
1749 * @dapm: DAPM context
1751 * Walks all dapm audio paths and powers widgets according to their
1752 * stream or path usage.
1754 * Returns 0 for success.
1756 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1758 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1760 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1762 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1763 const struct snd_soc_dapm_route *route)
1765 struct snd_soc_dapm_path *path;
1766 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1767 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1769 const char *control = route->control;
1771 char prefixed_sink[80];
1772 char prefixed_source[80];
1775 if (dapm->codec && dapm->codec->name_prefix) {
1776 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1777 dapm->codec->name_prefix, route->sink);
1778 sink = prefixed_sink;
1779 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1780 dapm->codec->name_prefix, route->source);
1781 source = prefixed_source;
1784 source = route->source;
1788 * find src and dest widgets over all widgets but favor a widget from
1789 * current DAPM context
1791 list_for_each_entry(w, &dapm->card->widgets, list) {
1792 if (!wsink && !(strcmp(w->name, sink))) {
1794 if (w->dapm == dapm)
1798 if (!wsource && !(strcmp(w->name, source))) {
1800 if (w->dapm == dapm)
1804 /* use widget from another DAPM context if not found from this */
1810 if (wsource == NULL || wsink == NULL)
1813 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1817 path->source = wsource;
1819 path->connected = route->connected;
1820 INIT_LIST_HEAD(&path->list);
1821 INIT_LIST_HEAD(&path->list_source);
1822 INIT_LIST_HEAD(&path->list_sink);
1824 /* check for external widgets */
1825 if (wsink->id == snd_soc_dapm_input) {
1826 if (wsource->id == snd_soc_dapm_micbias ||
1827 wsource->id == snd_soc_dapm_mic ||
1828 wsource->id == snd_soc_dapm_line ||
1829 wsource->id == snd_soc_dapm_output)
1832 if (wsource->id == snd_soc_dapm_output) {
1833 if (wsink->id == snd_soc_dapm_spk ||
1834 wsink->id == snd_soc_dapm_hp ||
1835 wsink->id == snd_soc_dapm_line ||
1836 wsink->id == snd_soc_dapm_input)
1840 /* connect static paths */
1841 if (control == NULL) {
1842 list_add(&path->list, &dapm->card->paths);
1843 list_add(&path->list_sink, &wsink->sources);
1844 list_add(&path->list_source, &wsource->sinks);
1849 /* connect dynamic paths */
1850 switch (wsink->id) {
1851 case snd_soc_dapm_adc:
1852 case snd_soc_dapm_dac:
1853 case snd_soc_dapm_pga:
1854 case snd_soc_dapm_out_drv:
1855 case snd_soc_dapm_input:
1856 case snd_soc_dapm_output:
1857 case snd_soc_dapm_micbias:
1858 case snd_soc_dapm_vmid:
1859 case snd_soc_dapm_pre:
1860 case snd_soc_dapm_post:
1861 case snd_soc_dapm_supply:
1862 case snd_soc_dapm_aif_in:
1863 case snd_soc_dapm_aif_out:
1864 list_add(&path->list, &dapm->card->paths);
1865 list_add(&path->list_sink, &wsink->sources);
1866 list_add(&path->list_source, &wsource->sinks);
1869 case snd_soc_dapm_mux:
1870 case snd_soc_dapm_virt_mux:
1871 case snd_soc_dapm_value_mux:
1872 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1873 &wsink->kcontrol_news[0]);
1877 case snd_soc_dapm_switch:
1878 case snd_soc_dapm_mixer:
1879 case snd_soc_dapm_mixer_named_ctl:
1880 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
1884 case snd_soc_dapm_hp:
1885 case snd_soc_dapm_mic:
1886 case snd_soc_dapm_line:
1887 case snd_soc_dapm_spk:
1888 list_add(&path->list, &dapm->card->paths);
1889 list_add(&path->list_sink, &wsink->sources);
1890 list_add(&path->list_source, &wsource->sinks);
1897 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
1898 source, control, sink);
1904 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1905 * @dapm: DAPM context
1906 * @route: audio routes
1907 * @num: number of routes
1909 * Connects 2 dapm widgets together via a named audio path. The sink is
1910 * the widget receiving the audio signal, whilst the source is the sender
1911 * of the audio signal.
1913 * Returns 0 for success else error. On error all resources can be freed
1914 * with a call to snd_soc_card_free().
1916 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1917 const struct snd_soc_dapm_route *route, int num)
1921 for (i = 0; i < num; i++) {
1922 ret = snd_soc_dapm_add_route(dapm, route);
1924 dev_err(dapm->dev, "Failed to add route %s->%s\n",
1925 route->source, route->sink);
1933 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1935 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
1936 const struct snd_soc_dapm_route *route)
1938 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
1941 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
1944 struct snd_soc_dapm_path *path;
1948 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
1954 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
1959 if (route->control || route->connected)
1960 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
1961 route->source, route->sink);
1963 list_for_each_entry(path, &source->sinks, list_source) {
1964 if (path->sink == sink) {
1971 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
1972 route->source, route->sink);
1974 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
1975 count, route->source, route->sink);
1981 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
1982 * @dapm: DAPM context
1983 * @route: audio routes
1984 * @num: number of routes
1986 * Mark existing routes matching those specified in the passed array
1987 * as being weak, meaning that they are ignored for the purpose of
1988 * power decisions. The main intended use case is for sidetone paths
1989 * which couple audio between other independent paths if they are both
1990 * active in order to make the combination work better at the user
1991 * level but which aren't intended to be "used".
1993 * Note that CODEC drivers should not use this as sidetone type paths
1994 * can frequently also be used as bypass paths.
1996 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
1997 const struct snd_soc_dapm_route *route, int num)
2002 for (i = 0; i < num; i++) {
2003 err = snd_soc_dapm_weak_route(dapm, route);
2011 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2014 * snd_soc_dapm_new_widgets - add new dapm widgets
2015 * @dapm: DAPM context
2017 * Checks the codec for any new dapm widgets and creates them if found.
2019 * Returns 0 for success.
2021 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2023 struct snd_soc_dapm_widget *w;
2026 list_for_each_entry(w, &dapm->card->widgets, list)
2031 if (w->num_kcontrols) {
2032 w->kcontrols = kzalloc(w->num_kcontrols *
2033 sizeof(struct snd_kcontrol *),
2040 case snd_soc_dapm_switch:
2041 case snd_soc_dapm_mixer:
2042 case snd_soc_dapm_mixer_named_ctl:
2043 w->power_check = dapm_generic_check_power;
2046 case snd_soc_dapm_mux:
2047 case snd_soc_dapm_virt_mux:
2048 case snd_soc_dapm_value_mux:
2049 w->power_check = dapm_generic_check_power;
2052 case snd_soc_dapm_adc:
2053 case snd_soc_dapm_aif_out:
2054 w->power_check = dapm_adc_check_power;
2056 case snd_soc_dapm_dac:
2057 case snd_soc_dapm_aif_in:
2058 w->power_check = dapm_dac_check_power;
2060 case snd_soc_dapm_pga:
2061 case snd_soc_dapm_out_drv:
2062 w->power_check = dapm_generic_check_power;
2065 case snd_soc_dapm_input:
2066 case snd_soc_dapm_output:
2067 case snd_soc_dapm_micbias:
2068 case snd_soc_dapm_spk:
2069 case snd_soc_dapm_hp:
2070 case snd_soc_dapm_mic:
2071 case snd_soc_dapm_line:
2072 w->power_check = dapm_generic_check_power;
2074 case snd_soc_dapm_supply:
2075 w->power_check = dapm_supply_check_power;
2076 case snd_soc_dapm_vmid:
2077 case snd_soc_dapm_pre:
2078 case snd_soc_dapm_post:
2082 /* Read the initial power state from the device */
2084 val = soc_widget_read(w, w->reg);
2085 val &= 1 << w->shift;
2095 dapm_debugfs_add_widget(w);
2098 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2101 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2104 * snd_soc_dapm_get_volsw - dapm mixer get callback
2105 * @kcontrol: mixer control
2106 * @ucontrol: control element information
2108 * Callback to get the value of a dapm mixer control.
2110 * Returns 0 for success.
2112 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2113 struct snd_ctl_elem_value *ucontrol)
2115 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2116 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2117 struct soc_mixer_control *mc =
2118 (struct soc_mixer_control *)kcontrol->private_value;
2119 unsigned int reg = mc->reg;
2120 unsigned int shift = mc->shift;
2121 unsigned int rshift = mc->rshift;
2123 unsigned int invert = mc->invert;
2124 unsigned int mask = (1 << fls(max)) - 1;
2126 ucontrol->value.integer.value[0] =
2127 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2128 if (shift != rshift)
2129 ucontrol->value.integer.value[1] =
2130 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2132 ucontrol->value.integer.value[0] =
2133 max - ucontrol->value.integer.value[0];
2134 if (shift != rshift)
2135 ucontrol->value.integer.value[1] =
2136 max - ucontrol->value.integer.value[1];
2141 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2144 * snd_soc_dapm_put_volsw - dapm mixer set callback
2145 * @kcontrol: mixer control
2146 * @ucontrol: control element information
2148 * Callback to set the value of a dapm mixer control.
2150 * Returns 0 for success.
2152 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2153 struct snd_ctl_elem_value *ucontrol)
2155 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2156 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2157 struct snd_soc_codec *codec = widget->codec;
2158 struct soc_mixer_control *mc =
2159 (struct soc_mixer_control *)kcontrol->private_value;
2160 unsigned int reg = mc->reg;
2161 unsigned int shift = mc->shift;
2163 unsigned int mask = (1 << fls(max)) - 1;
2164 unsigned int invert = mc->invert;
2166 int connect, change;
2167 struct snd_soc_dapm_update update;
2170 val = (ucontrol->value.integer.value[0] & mask);
2174 mask = mask << shift;
2178 /* new connection */
2179 connect = invert ? 0 : 1;
2181 /* old connection must be powered down */
2182 connect = invert ? 1 : 0;
2184 mutex_lock(&codec->mutex);
2186 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2188 for (wi = 0; wi < wlist->num_widgets; wi++) {
2189 widget = wlist->widgets[wi];
2191 widget->value = val;
2193 update.kcontrol = kcontrol;
2194 update.widget = widget;
2198 widget->dapm->update = &update;
2200 dapm_mixer_update_power(widget, kcontrol, connect);
2202 widget->dapm->update = NULL;
2206 mutex_unlock(&codec->mutex);
2209 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2212 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2213 * @kcontrol: mixer control
2214 * @ucontrol: control element information
2216 * Callback to get the value of a dapm enumerated double mixer control.
2218 * Returns 0 for success.
2220 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2221 struct snd_ctl_elem_value *ucontrol)
2223 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2224 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2225 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2226 unsigned int val, bitmask;
2228 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2230 val = snd_soc_read(widget->codec, e->reg);
2231 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2232 if (e->shift_l != e->shift_r)
2233 ucontrol->value.enumerated.item[1] =
2234 (val >> e->shift_r) & (bitmask - 1);
2238 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2241 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2242 * @kcontrol: mixer control
2243 * @ucontrol: control element information
2245 * Callback to set the value of a dapm enumerated double mixer control.
2247 * Returns 0 for success.
2249 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2250 struct snd_ctl_elem_value *ucontrol)
2252 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2253 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2254 struct snd_soc_codec *codec = widget->codec;
2255 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2256 unsigned int val, mux, change;
2257 unsigned int mask, bitmask;
2258 struct snd_soc_dapm_update update;
2261 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2263 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2265 mux = ucontrol->value.enumerated.item[0];
2266 val = mux << e->shift_l;
2267 mask = (bitmask - 1) << e->shift_l;
2268 if (e->shift_l != e->shift_r) {
2269 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2271 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2272 mask |= (bitmask - 1) << e->shift_r;
2275 mutex_lock(&codec->mutex);
2277 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2279 for (wi = 0; wi < wlist->num_widgets; wi++) {
2280 widget = wlist->widgets[wi];
2282 widget->value = val;
2284 update.kcontrol = kcontrol;
2285 update.widget = widget;
2286 update.reg = e->reg;
2289 widget->dapm->update = &update;
2291 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2293 widget->dapm->update = NULL;
2297 mutex_unlock(&codec->mutex);
2300 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2303 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2304 * @kcontrol: mixer control
2305 * @ucontrol: control element information
2307 * Returns 0 for success.
2309 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2310 struct snd_ctl_elem_value *ucontrol)
2312 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2313 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2315 ucontrol->value.enumerated.item[0] = widget->value;
2319 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2322 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2323 * @kcontrol: mixer control
2324 * @ucontrol: control element information
2326 * Returns 0 for success.
2328 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2329 struct snd_ctl_elem_value *ucontrol)
2331 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2332 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2333 struct snd_soc_codec *codec = widget->codec;
2334 struct soc_enum *e =
2335 (struct soc_enum *)kcontrol->private_value;
2340 if (ucontrol->value.enumerated.item[0] >= e->max)
2343 mutex_lock(&codec->mutex);
2345 change = widget->value != ucontrol->value.enumerated.item[0];
2347 for (wi = 0; wi < wlist->num_widgets; wi++) {
2348 widget = wlist->widgets[wi];
2350 widget->value = ucontrol->value.enumerated.item[0];
2352 dapm_mux_update_power(widget, kcontrol, change,
2357 mutex_unlock(&codec->mutex);
2360 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2363 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2365 * @kcontrol: mixer control
2366 * @ucontrol: control element information
2368 * Callback to get the value of a dapm semi enumerated double mixer control.
2370 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2371 * used for handling bitfield coded enumeration for example.
2373 * Returns 0 for success.
2375 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2376 struct snd_ctl_elem_value *ucontrol)
2378 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2379 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2380 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2381 unsigned int reg_val, val, mux;
2383 reg_val = snd_soc_read(widget->codec, e->reg);
2384 val = (reg_val >> e->shift_l) & e->mask;
2385 for (mux = 0; mux < e->max; mux++) {
2386 if (val == e->values[mux])
2389 ucontrol->value.enumerated.item[0] = mux;
2390 if (e->shift_l != e->shift_r) {
2391 val = (reg_val >> e->shift_r) & e->mask;
2392 for (mux = 0; mux < e->max; mux++) {
2393 if (val == e->values[mux])
2396 ucontrol->value.enumerated.item[1] = mux;
2401 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2404 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2406 * @kcontrol: mixer control
2407 * @ucontrol: control element information
2409 * Callback to set the value of a dapm semi enumerated double mixer control.
2411 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2412 * used for handling bitfield coded enumeration for example.
2414 * Returns 0 for success.
2416 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2417 struct snd_ctl_elem_value *ucontrol)
2419 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2420 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2421 struct snd_soc_codec *codec = widget->codec;
2422 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2423 unsigned int val, mux, change;
2425 struct snd_soc_dapm_update update;
2428 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2430 mux = ucontrol->value.enumerated.item[0];
2431 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2432 mask = e->mask << e->shift_l;
2433 if (e->shift_l != e->shift_r) {
2434 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2436 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2437 mask |= e->mask << e->shift_r;
2440 mutex_lock(&codec->mutex);
2442 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2444 for (wi = 0; wi < wlist->num_widgets; wi++) {
2445 widget = wlist->widgets[wi];
2447 widget->value = val;
2449 update.kcontrol = kcontrol;
2450 update.widget = widget;
2451 update.reg = e->reg;
2454 widget->dapm->update = &update;
2456 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2458 widget->dapm->update = NULL;
2462 mutex_unlock(&codec->mutex);
2465 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2468 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2470 * @kcontrol: mixer control
2471 * @uinfo: control element information
2473 * Callback to provide information about a pin switch control.
2475 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2476 struct snd_ctl_elem_info *uinfo)
2478 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2480 uinfo->value.integer.min = 0;
2481 uinfo->value.integer.max = 1;
2485 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2488 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2490 * @kcontrol: mixer control
2493 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2494 struct snd_ctl_elem_value *ucontrol)
2496 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2497 const char *pin = (const char *)kcontrol->private_value;
2499 mutex_lock(&codec->mutex);
2501 ucontrol->value.integer.value[0] =
2502 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
2504 mutex_unlock(&codec->mutex);
2508 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2511 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2513 * @kcontrol: mixer control
2516 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2517 struct snd_ctl_elem_value *ucontrol)
2519 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2520 const char *pin = (const char *)kcontrol->private_value;
2522 mutex_lock(&codec->mutex);
2524 if (ucontrol->value.integer.value[0])
2525 snd_soc_dapm_enable_pin(&codec->dapm, pin);
2527 snd_soc_dapm_disable_pin(&codec->dapm, pin);
2529 snd_soc_dapm_sync(&codec->dapm);
2531 mutex_unlock(&codec->mutex);
2535 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2538 * snd_soc_dapm_new_control - create new dapm control
2539 * @dapm: DAPM context
2540 * @widget: widget template
2542 * Creates a new dapm control based upon the template.
2544 * Returns 0 for success else error.
2546 int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2547 const struct snd_soc_dapm_widget *widget)
2549 struct snd_soc_dapm_widget *w;
2552 if ((w = dapm_cnew_widget(widget)) == NULL)
2555 name_len = strlen(widget->name) + 1;
2556 if (dapm->codec && dapm->codec->name_prefix)
2557 name_len += 1 + strlen(dapm->codec->name_prefix);
2558 w->name = kmalloc(name_len, GFP_KERNEL);
2559 if (w->name == NULL) {
2563 if (dapm->codec && dapm->codec->name_prefix)
2564 snprintf(w->name, name_len, "%s %s",
2565 dapm->codec->name_prefix, widget->name);
2567 snprintf(w->name, name_len, "%s", widget->name);
2571 w->codec = dapm->codec;
2572 w->platform = dapm->platform;
2573 INIT_LIST_HEAD(&w->sources);
2574 INIT_LIST_HEAD(&w->sinks);
2575 INIT_LIST_HEAD(&w->list);
2576 list_add(&w->list, &dapm->card->widgets);
2578 /* machine layer set ups unconnected pins and insertions */
2582 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
2585 * snd_soc_dapm_new_controls - create new dapm controls
2586 * @dapm: DAPM context
2587 * @widget: widget array
2588 * @num: number of widgets
2590 * Creates new DAPM controls based upon the templates.
2592 * Returns 0 for success else error.
2594 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2595 const struct snd_soc_dapm_widget *widget,
2600 for (i = 0; i < num; i++) {
2601 ret = snd_soc_dapm_new_control(dapm, widget);
2604 "ASoC: Failed to create DAPM control %s: %d\n",
2612 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2614 static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2615 const char *stream, int event)
2617 struct snd_soc_dapm_widget *w;
2619 list_for_each_entry(w, &dapm->card->widgets, list)
2621 if (!w->sname || w->dapm != dapm)
2623 dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2624 w->name, w->sname, stream, event);
2625 if (strstr(w->sname, stream)) {
2627 case SND_SOC_DAPM_STREAM_START:
2630 case SND_SOC_DAPM_STREAM_STOP:
2633 case SND_SOC_DAPM_STREAM_SUSPEND:
2634 case SND_SOC_DAPM_STREAM_RESUME:
2635 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
2636 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2642 dapm_power_widgets(dapm, event);
2644 /* do we need to notify any clients that DAPM stream is complete */
2645 if (dapm->stream_event)
2646 dapm->stream_event(dapm, event);
2650 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2651 * @rtd: PCM runtime data
2652 * @stream: stream name
2653 * @event: stream event
2655 * Sends a stream event to the dapm core. The core then makes any
2656 * necessary widget power changes.
2658 * Returns 0 for success else error.
2660 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2661 const char *stream, int event)
2663 struct snd_soc_codec *codec = rtd->codec;
2668 mutex_lock(&codec->mutex);
2669 soc_dapm_stream_event(&codec->dapm, stream, event);
2670 mutex_unlock(&codec->mutex);
2675 * snd_soc_dapm_enable_pin - enable pin.
2676 * @dapm: DAPM context
2679 * Enables input/output pin and its parents or children widgets iff there is
2680 * a valid audio route and active audio stream.
2681 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2682 * do any widget power switching.
2684 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2686 return snd_soc_dapm_set_pin(dapm, pin, 1);
2688 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2691 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2692 * @dapm: DAPM context
2695 * Enables input/output pin regardless of any other state. This is
2696 * intended for use with microphone bias supplies used in microphone
2699 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2700 * do any widget power switching.
2702 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2705 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2708 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2712 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
2718 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2721 * snd_soc_dapm_disable_pin - disable pin.
2722 * @dapm: DAPM context
2725 * Disables input/output pin and its parents or children widgets.
2726 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2727 * do any widget power switching.
2729 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2732 return snd_soc_dapm_set_pin(dapm, pin, 0);
2734 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2737 * snd_soc_dapm_nc_pin - permanently disable pin.
2738 * @dapm: DAPM context
2741 * Marks the specified pin as being not connected, disabling it along
2742 * any parent or child widgets. At present this is identical to
2743 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2744 * additional things such as disabling controls which only affect
2745 * paths through the pin.
2747 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2748 * do any widget power switching.
2750 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2752 return snd_soc_dapm_set_pin(dapm, pin, 0);
2754 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2757 * snd_soc_dapm_get_pin_status - get audio pin status
2758 * @dapm: DAPM context
2759 * @pin: audio signal pin endpoint (or start point)
2761 * Get audio pin status - connected or disconnected.
2763 * Returns 1 for connected otherwise 0.
2765 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2768 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2771 return w->connected;
2775 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2778 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2779 * @dapm: DAPM context
2780 * @pin: audio signal pin endpoint (or start point)
2782 * Mark the given endpoint or pin as ignoring suspend. When the
2783 * system is disabled a path between two endpoints flagged as ignoring
2784 * suspend will not be disabled. The path must already be enabled via
2785 * normal means at suspend time, it will not be turned on if it was not
2788 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2791 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
2794 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2798 w->ignore_suspend = 1;
2802 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2805 * snd_soc_dapm_free - free dapm resources
2806 * @dapm: DAPM context
2808 * Free all dapm widgets and resources.
2810 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2812 snd_soc_dapm_sys_remove(dapm->dev);
2813 dapm_debugfs_cleanup(dapm);
2814 dapm_free_widgets(dapm);
2815 list_del(&dapm->list);
2817 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2819 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2821 struct snd_soc_dapm_widget *w;
2822 LIST_HEAD(down_list);
2825 list_for_each_entry(w, &dapm->card->widgets, list) {
2826 if (w->dapm != dapm)
2829 dapm_seq_insert(w, &down_list, false);
2835 /* If there were no widgets to power down we're already in
2839 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
2840 dapm_seq_run(dapm, &down_list, 0, false);
2841 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
2846 * snd_soc_dapm_shutdown - callback for system shutdown
2848 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2850 struct snd_soc_codec *codec;
2852 list_for_each_entry(codec, &card->codec_dev_list, list) {
2853 soc_dapm_shutdown_codec(&codec->dapm);
2854 snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
2858 /* Module information */
2859 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2860 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2861 MODULE_LICENSE("GPL");