2 * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 * o Changes power status of internal codec blocks depending on the
14 * dynamic configuration of codec internal audio paths and active
16 * o Platform power domain - can support external components i.e. amps and
17 * mic/meadphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
21 * o Delayed powerdown of audio susbsystem to reduce pops between a quick
25 * o DAPM power change sequencing - allow for configurable per
27 * o Support for analogue bias optimisation.
28 * o Support for reduced codec oversampling rates.
29 * o Support for reduced codec bias currents.
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/init.h>
35 #include <linux/async.h>
36 #include <linux/delay.h>
38 #include <linux/bitops.h>
39 #include <linux/platform_device.h>
40 #include <linux/jiffies.h>
41 #include <linux/debugfs.h>
42 #include <linux/slab.h>
43 #include <sound/core.h>
44 #include <sound/pcm.h>
45 #include <sound/pcm_params.h>
46 #include <sound/soc.h>
47 #include <sound/initval.h>
49 #include <trace/events/asoc.h>
51 /* dapm power sequences - make this per codec in the future */
52 static int dapm_up_seq[] = {
53 [snd_soc_dapm_pre] = 0,
54 [snd_soc_dapm_supply] = 1,
55 [snd_soc_dapm_micbias] = 2,
56 [snd_soc_dapm_aif_in] = 3,
57 [snd_soc_dapm_aif_out] = 3,
58 [snd_soc_dapm_mic] = 4,
59 [snd_soc_dapm_mux] = 5,
60 [snd_soc_dapm_virt_mux] = 5,
61 [snd_soc_dapm_value_mux] = 5,
62 [snd_soc_dapm_dac] = 6,
63 [snd_soc_dapm_mixer] = 7,
64 [snd_soc_dapm_mixer_named_ctl] = 7,
65 [snd_soc_dapm_pga] = 8,
66 [snd_soc_dapm_adc] = 9,
67 [snd_soc_dapm_out_drv] = 10,
68 [snd_soc_dapm_hp] = 10,
69 [snd_soc_dapm_spk] = 10,
70 [snd_soc_dapm_post] = 11,
73 static int dapm_down_seq[] = {
74 [snd_soc_dapm_pre] = 0,
75 [snd_soc_dapm_adc] = 1,
76 [snd_soc_dapm_hp] = 2,
77 [snd_soc_dapm_spk] = 2,
78 [snd_soc_dapm_out_drv] = 2,
79 [snd_soc_dapm_pga] = 4,
80 [snd_soc_dapm_mixer_named_ctl] = 5,
81 [snd_soc_dapm_mixer] = 5,
82 [snd_soc_dapm_dac] = 6,
83 [snd_soc_dapm_mic] = 7,
84 [snd_soc_dapm_micbias] = 8,
85 [snd_soc_dapm_mux] = 9,
86 [snd_soc_dapm_virt_mux] = 9,
87 [snd_soc_dapm_value_mux] = 9,
88 [snd_soc_dapm_aif_in] = 10,
89 [snd_soc_dapm_aif_out] = 10,
90 [snd_soc_dapm_supply] = 11,
91 [snd_soc_dapm_post] = 12,
94 static void pop_wait(u32 pop_time)
97 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
100 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
108 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
113 vsnprintf(buf, PAGE_SIZE, fmt, args);
114 dev_info(dev, "%s", buf);
120 /* create a new dapm widget */
121 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
122 const struct snd_soc_dapm_widget *_widget)
124 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
127 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
130 return snd_soc_read(w->codec, reg);
131 else if (w->platform)
132 return snd_soc_platform_read(w->platform, reg);
134 dev_err(w->dapm->dev, "no valid widget read method\n");
138 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
141 return snd_soc_write(w->codec, reg, val);
142 else if (w->platform)
143 return snd_soc_platform_write(w->platform, reg, val);
145 dev_err(w->dapm->dev, "no valid widget write method\n");
149 static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
150 unsigned short reg, unsigned int mask, unsigned int value)
153 unsigned int old, new;
156 ret = soc_widget_read(w, reg);
161 new = (old & ~mask) | (value & mask);
164 ret = soc_widget_write(w, reg, new);
173 * snd_soc_dapm_set_bias_level - set the bias level for the system
174 * @dapm: DAPM context
175 * @level: level to configure
177 * Configure the bias (power) levels for the SoC audio device.
179 * Returns 0 for success else error.
181 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
182 enum snd_soc_bias_level level)
184 struct snd_soc_card *card = dapm->card;
187 trace_snd_soc_bias_level_start(card, level);
189 if (card && card->set_bias_level)
190 ret = card->set_bias_level(card, dapm, level);
195 if (dapm->codec->driver->set_bias_level)
196 ret = dapm->codec->driver->set_bias_level(dapm->codec,
199 dapm->bias_level = level;
204 if (card && card->set_bias_level_post)
205 ret = card->set_bias_level_post(card, dapm, level);
207 trace_snd_soc_bias_level_done(card, level);
212 /* set up initial codec paths */
213 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
214 struct snd_soc_dapm_path *p, int i)
217 case snd_soc_dapm_switch:
218 case snd_soc_dapm_mixer:
219 case snd_soc_dapm_mixer_named_ctl: {
221 struct soc_mixer_control *mc = (struct soc_mixer_control *)
222 w->kcontrol_news[i].private_value;
223 unsigned int reg = mc->reg;
224 unsigned int shift = mc->shift;
226 unsigned int mask = (1 << fls(max)) - 1;
227 unsigned int invert = mc->invert;
229 val = soc_widget_read(w, reg);
230 val = (val >> shift) & mask;
232 if ((invert && !val) || (!invert && val))
238 case snd_soc_dapm_mux: {
239 struct soc_enum *e = (struct soc_enum *)
240 w->kcontrol_news[i].private_value;
241 int val, item, bitmask;
243 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
245 val = soc_widget_read(w, e->reg);
246 item = (val >> e->shift_l) & (bitmask - 1);
249 for (i = 0; i < e->max; i++) {
250 if (!(strcmp(p->name, e->texts[i])) && item == i)
255 case snd_soc_dapm_virt_mux: {
256 struct soc_enum *e = (struct soc_enum *)
257 w->kcontrol_news[i].private_value;
260 /* since a virtual mux has no backing registers to
261 * decide which path to connect, it will try to match
262 * with the first enumeration. This is to ensure
263 * that the default mux choice (the first) will be
264 * correctly powered up during initialization.
266 if (!strcmp(p->name, e->texts[0]))
270 case snd_soc_dapm_value_mux: {
271 struct soc_enum *e = (struct soc_enum *)
272 w->kcontrol_news[i].private_value;
275 val = soc_widget_read(w, e->reg);
276 val = (val >> e->shift_l) & e->mask;
277 for (item = 0; item < e->max; item++) {
278 if (val == e->values[item])
283 for (i = 0; i < e->max; i++) {
284 if (!(strcmp(p->name, e->texts[i])) && item == i)
289 /* does not effect routing - always connected */
290 case snd_soc_dapm_pga:
291 case snd_soc_dapm_out_drv:
292 case snd_soc_dapm_output:
293 case snd_soc_dapm_adc:
294 case snd_soc_dapm_input:
295 case snd_soc_dapm_dac:
296 case snd_soc_dapm_micbias:
297 case snd_soc_dapm_vmid:
298 case snd_soc_dapm_supply:
299 case snd_soc_dapm_aif_in:
300 case snd_soc_dapm_aif_out:
303 /* does effect routing - dynamically connected */
304 case snd_soc_dapm_hp:
305 case snd_soc_dapm_mic:
306 case snd_soc_dapm_spk:
307 case snd_soc_dapm_line:
308 case snd_soc_dapm_pre:
309 case snd_soc_dapm_post:
315 /* connect mux widget to its interconnecting audio paths */
316 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
317 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
318 struct snd_soc_dapm_path *path, const char *control_name,
319 const struct snd_kcontrol_new *kcontrol)
321 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
324 for (i = 0; i < e->max; i++) {
325 if (!(strcmp(control_name, e->texts[i]))) {
326 list_add(&path->list, &dapm->card->paths);
327 list_add(&path->list_sink, &dest->sources);
328 list_add(&path->list_source, &src->sinks);
329 path->name = (char*)e->texts[i];
330 dapm_set_path_status(dest, path, 0);
338 /* connect mixer widget to its interconnecting audio paths */
339 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
340 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
341 struct snd_soc_dapm_path *path, const char *control_name)
345 /* search for mixer kcontrol */
346 for (i = 0; i < dest->num_kcontrols; i++) {
347 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
348 list_add(&path->list, &dapm->card->paths);
349 list_add(&path->list_sink, &dest->sources);
350 list_add(&path->list_source, &src->sinks);
351 path->name = dest->kcontrol_news[i].name;
352 dapm_set_path_status(dest, path, i);
359 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
360 struct snd_soc_dapm_widget *kcontrolw,
361 const struct snd_kcontrol_new *kcontrol_new,
362 struct snd_kcontrol **kcontrol)
364 struct snd_soc_dapm_widget *w;
369 list_for_each_entry(w, &dapm->card->widgets, list) {
370 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
372 for (i = 0; i < w->num_kcontrols; i++) {
373 if (&w->kcontrol_news[i] == kcontrol_new) {
375 *kcontrol = w->kcontrols[i];
384 /* create new dapm mixer control */
385 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
387 struct snd_soc_dapm_context *dapm = w->dapm;
389 size_t name_len, prefix_len;
390 struct snd_soc_dapm_path *path;
391 struct snd_card *card = dapm->card->snd_card;
393 struct snd_soc_dapm_widget_list *wlist;
397 prefix = dapm->codec->name_prefix;
402 prefix_len = strlen(prefix) + 1;
407 for (i = 0; i < w->num_kcontrols; i++) {
410 list_for_each_entry(path, &w->sources, list_sink) {
412 /* mixer/mux paths name must match control name */
413 if (path->name != (char *)w->kcontrol_news[i].name)
416 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
417 sizeof(struct snd_soc_dapm_widget *),
418 wlist = kzalloc(wlistsize, GFP_KERNEL);
421 "asoc: can't allocate widget list for %s\n",
425 wlist->num_widgets = 1;
426 wlist->widgets[0] = w;
428 /* add dapm control with long name.
429 * for dapm_mixer this is the concatenation of the
430 * mixer and kcontrol name.
431 * for dapm_mixer_named_ctl this is simply the
434 name_len = strlen(w->kcontrol_news[i].name) + 1;
435 if (w->id != snd_soc_dapm_mixer_named_ctl)
436 name_len += 1 + strlen(w->name);
438 path->long_name = kmalloc(name_len, GFP_KERNEL);
440 if (path->long_name == NULL) {
447 /* The control will get a prefix from
448 * the control creation process but
449 * we're also using the same prefix
450 * for widgets so cut the prefix off
451 * the front of the widget name.
453 snprintf(path->long_name, name_len, "%s %s",
454 w->name + prefix_len,
455 w->kcontrol_news[i].name);
457 case snd_soc_dapm_mixer_named_ctl:
458 snprintf(path->long_name, name_len, "%s",
459 w->kcontrol_news[i].name);
463 path->long_name[name_len - 1] = '\0';
465 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
466 wlist, path->long_name,
468 ret = snd_ctl_add(card, path->kcontrol);
471 "asoc: failed to add dapm kcontrol %s: %d\n",
472 path->long_name, ret);
474 kfree(path->long_name);
475 path->long_name = NULL;
478 w->kcontrols[i] = path->kcontrol;
484 /* create new dapm mux control */
485 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
487 struct snd_soc_dapm_context *dapm = w->dapm;
488 struct snd_soc_dapm_path *path = NULL;
489 struct snd_kcontrol *kcontrol;
490 struct snd_card *card = dapm->card->snd_card;
494 struct snd_soc_dapm_widget_list *wlist;
495 int shared, wlistentries;
499 if (w->num_kcontrols != 1) {
501 "asoc: mux %s has incorrect number of controls\n",
506 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
509 wlist = kcontrol->private_data;
510 wlistentries = wlist->num_widgets + 1;
515 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
516 wlistentries * sizeof(struct snd_soc_dapm_widget *),
517 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
520 "asoc: can't allocate widget list for %s\n", w->name);
523 wlist->num_widgets = wlistentries;
524 wlist->widgets[wlistentries - 1] = w;
528 prefix = dapm->codec->name_prefix;
533 name = w->kcontrol_news[0].name;
538 prefix_len = strlen(prefix) + 1;
544 * The control will get a prefix from the control creation
545 * process but we're also using the same prefix for widgets so
546 * cut the prefix off the front of the widget name.
548 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
549 name + prefix_len, prefix);
550 ret = snd_ctl_add(card, kcontrol);
553 "asoc: failed to add kcontrol %s\n", w->name);
559 kcontrol->private_data = wlist;
561 w->kcontrols[0] = kcontrol;
563 list_for_each_entry(path, &w->sources, list_sink)
564 path->kcontrol = kcontrol;
569 /* create new dapm volume control */
570 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
572 if (w->num_kcontrols)
573 dev_err(w->dapm->dev,
574 "asoc: PGA controls not supported: '%s'\n", w->name);
579 /* reset 'walked' bit for each dapm path */
580 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
582 struct snd_soc_dapm_path *p;
584 list_for_each_entry(p, &dapm->card->paths, list)
588 /* We implement power down on suspend by checking the power state of
589 * the ALSA card - when we are suspending the ALSA state for the card
592 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
594 int level = snd_power_get_state(widget->dapm->card->snd_card);
597 case SNDRV_CTL_POWER_D3hot:
598 case SNDRV_CTL_POWER_D3cold:
599 if (widget->ignore_suspend)
600 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
602 return widget->ignore_suspend;
609 * Recursively check for a completed path to an active or physically connected
610 * output widget. Returns number of complete paths.
612 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
614 struct snd_soc_dapm_path *path;
617 if (widget->id == snd_soc_dapm_supply)
620 switch (widget->id) {
621 case snd_soc_dapm_adc:
622 case snd_soc_dapm_aif_out:
624 return snd_soc_dapm_suspend_check(widget);
629 if (widget->connected) {
630 /* connected pin ? */
631 if (widget->id == snd_soc_dapm_output && !widget->ext)
632 return snd_soc_dapm_suspend_check(widget);
634 /* connected jack or spk ? */
635 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
636 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
637 return snd_soc_dapm_suspend_check(widget);
640 list_for_each_entry(path, &widget->sinks, list_source) {
647 if (path->sink && path->connect) {
649 con += is_connected_output_ep(path->sink);
657 * Recursively check for a completed path to an active or physically connected
658 * input widget. Returns number of complete paths.
660 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
662 struct snd_soc_dapm_path *path;
665 if (widget->id == snd_soc_dapm_supply)
668 /* active stream ? */
669 switch (widget->id) {
670 case snd_soc_dapm_dac:
671 case snd_soc_dapm_aif_in:
673 return snd_soc_dapm_suspend_check(widget);
678 if (widget->connected) {
679 /* connected pin ? */
680 if (widget->id == snd_soc_dapm_input && !widget->ext)
681 return snd_soc_dapm_suspend_check(widget);
683 /* connected VMID/Bias for lower pops */
684 if (widget->id == snd_soc_dapm_vmid)
685 return snd_soc_dapm_suspend_check(widget);
687 /* connected jack ? */
688 if (widget->id == snd_soc_dapm_mic ||
689 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
690 return snd_soc_dapm_suspend_check(widget);
693 list_for_each_entry(path, &widget->sources, list_sink) {
700 if (path->source && path->connect) {
702 con += is_connected_input_ep(path->source);
710 * Handler for generic register modifier widget.
712 int dapm_reg_event(struct snd_soc_dapm_widget *w,
713 struct snd_kcontrol *kcontrol, int event)
717 if (SND_SOC_DAPM_EVENT_ON(event))
722 soc_widget_update_bits(w, -(w->reg + 1),
723 w->mask << w->shift, val << w->shift);
727 EXPORT_SYMBOL_GPL(dapm_reg_event);
729 /* Generic check to see if a widget should be powered.
731 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
735 in = is_connected_input_ep(w);
736 dapm_clear_walk(w->dapm);
737 out = is_connected_output_ep(w);
738 dapm_clear_walk(w->dapm);
739 return out != 0 && in != 0;
742 /* Check to see if an ADC has power */
743 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
748 in = is_connected_input_ep(w);
749 dapm_clear_walk(w->dapm);
752 return dapm_generic_check_power(w);
756 /* Check to see if a DAC has power */
757 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
762 out = is_connected_output_ep(w);
763 dapm_clear_walk(w->dapm);
766 return dapm_generic_check_power(w);
770 /* Check to see if a power supply is needed */
771 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
773 struct snd_soc_dapm_path *path;
776 /* Check if one of our outputs is connected */
777 list_for_each_entry(path, &w->sinks, list_source) {
781 if (path->connected &&
782 !path->connected(path->source, path->sink))
788 if (path->sink->force) {
793 if (path->sink->power_check &&
794 path->sink->power_check(path->sink)) {
800 dapm_clear_walk(w->dapm);
805 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
806 struct snd_soc_dapm_widget *b,
814 sort = dapm_down_seq;
816 if (sort[a->id] != sort[b->id])
817 return sort[a->id] - sort[b->id];
818 if (a->subseq != b->subseq) {
820 return a->subseq - b->subseq;
822 return b->subseq - a->subseq;
824 if (a->reg != b->reg)
825 return a->reg - b->reg;
826 if (a->dapm != b->dapm)
827 return (unsigned long)a->dapm - (unsigned long)b->dapm;
832 /* Insert a widget in order into a DAPM power sequence. */
833 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
834 struct list_head *list,
837 struct snd_soc_dapm_widget *w;
839 list_for_each_entry(w, list, power_list)
840 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
841 list_add_tail(&new_widget->power_list, &w->power_list);
845 list_add_tail(&new_widget->power_list, list);
848 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
849 struct snd_soc_dapm_widget *w, int event)
851 struct snd_soc_card *card = dapm->card;
856 case SND_SOC_DAPM_PRE_PMU:
860 case SND_SOC_DAPM_POST_PMU:
861 ev_name = "POST_PMU";
864 case SND_SOC_DAPM_PRE_PMD:
868 case SND_SOC_DAPM_POST_PMD:
869 ev_name = "POST_PMD";
877 if (w->power != power)
880 if (w->event && (w->event_flags & event)) {
881 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
883 trace_snd_soc_dapm_widget_event_start(w, event);
884 ret = w->event(w, NULL, event);
885 trace_snd_soc_dapm_widget_event_done(w, event);
887 pr_err("%s: %s event failed: %d\n",
888 ev_name, w->name, ret);
892 /* Apply the coalesced changes from a DAPM sequence */
893 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
894 struct list_head *pending)
896 struct snd_soc_card *card = dapm->card;
897 struct snd_soc_dapm_widget *w;
899 unsigned int value = 0;
900 unsigned int mask = 0;
901 unsigned int cur_mask;
903 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
906 list_for_each_entry(w, pending, power_list) {
907 cur_mask = 1 << w->shift;
908 BUG_ON(reg != w->reg);
919 pop_dbg(dapm->dev, card->pop_time,
920 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
921 w->name, reg, value, mask);
923 /* Check for events */
924 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
925 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
929 /* Any widget will do, they should all be updating the
932 w = list_first_entry(pending, struct snd_soc_dapm_widget,
935 pop_dbg(dapm->dev, card->pop_time,
936 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
937 value, mask, reg, card->pop_time);
938 pop_wait(card->pop_time);
939 soc_widget_update_bits(w, reg, mask, value);
942 list_for_each_entry(w, pending, power_list) {
943 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
944 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
948 /* Apply a DAPM power sequence.
950 * We walk over a pre-sorted list of widgets to apply power to. In
951 * order to minimise the number of writes to the device required
952 * multiple widgets will be updated in a single write where possible.
953 * Currently anything that requires more than a single write is not
956 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
957 struct list_head *list, int event, bool power_up)
959 struct snd_soc_dapm_widget *w, *n;
963 int cur_reg = SND_SOC_NOPM;
964 struct snd_soc_dapm_context *cur_dapm = NULL;
971 sort = dapm_down_seq;
973 list_for_each_entry_safe(w, n, list, power_list) {
976 /* Do we need to apply any queued changes? */
977 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
978 w->dapm != cur_dapm || w->subseq != cur_subseq) {
979 if (!list_empty(&pending))
980 dapm_seq_run_coalesced(cur_dapm, &pending);
982 if (cur_dapm && cur_dapm->seq_notifier) {
983 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
984 if (sort[i] == cur_sort)
985 cur_dapm->seq_notifier(cur_dapm,
990 INIT_LIST_HEAD(&pending);
992 cur_subseq = INT_MIN;
993 cur_reg = SND_SOC_NOPM;
998 case snd_soc_dapm_pre:
1000 list_for_each_entry_safe_continue(w, n, list,
1003 if (event == SND_SOC_DAPM_STREAM_START)
1005 NULL, SND_SOC_DAPM_PRE_PMU);
1006 else if (event == SND_SOC_DAPM_STREAM_STOP)
1008 NULL, SND_SOC_DAPM_PRE_PMD);
1011 case snd_soc_dapm_post:
1013 list_for_each_entry_safe_continue(w, n, list,
1016 if (event == SND_SOC_DAPM_STREAM_START)
1018 NULL, SND_SOC_DAPM_POST_PMU);
1019 else if (event == SND_SOC_DAPM_STREAM_STOP)
1021 NULL, SND_SOC_DAPM_POST_PMD);
1025 /* Queue it up for application */
1026 cur_sort = sort[w->id];
1027 cur_subseq = w->subseq;
1030 list_move(&w->power_list, &pending);
1035 dev_err(w->dapm->dev,
1036 "Failed to apply widget power: %d\n", ret);
1039 if (!list_empty(&pending))
1040 dapm_seq_run_coalesced(cur_dapm, &pending);
1042 if (cur_dapm && cur_dapm->seq_notifier) {
1043 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1044 if (sort[i] == cur_sort)
1045 cur_dapm->seq_notifier(cur_dapm,
1050 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1052 struct snd_soc_dapm_update *update = dapm->update;
1053 struct snd_soc_dapm_widget *w;
1062 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1063 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1065 pr_err("%s DAPM pre-event failed: %d\n",
1069 ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
1072 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1075 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1076 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1078 pr_err("%s DAPM post-event failed: %d\n",
1083 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1084 * they're changing state.
1086 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1088 struct snd_soc_dapm_context *d = data;
1091 /* If we're off and we're not supposed to be go into STANDBY */
1092 if (d->bias_level == SND_SOC_BIAS_OFF &&
1093 d->target_bias_level != SND_SOC_BIAS_OFF) {
1094 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1097 "Failed to turn on bias: %d\n", ret);
1100 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1101 if (d->bias_level != d->target_bias_level) {
1102 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1105 "Failed to prepare bias: %d\n", ret);
1109 /* Async callback run prior to DAPM sequences - brings to their final
1112 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1114 struct snd_soc_dapm_context *d = data;
1117 /* If we just powered the last thing off drop to standby bias */
1118 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1119 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1120 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1121 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1123 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1127 /* If we're in standby and can support bias off then do that */
1128 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1129 d->target_bias_level == SND_SOC_BIAS_OFF) {
1130 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1132 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1135 /* If we just powered up then move to active bias */
1136 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1137 d->target_bias_level == SND_SOC_BIAS_ON) {
1138 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1140 dev_err(d->dev, "Failed to apply active bias: %d\n",
1146 * Scan each dapm widget for complete audio path.
1147 * A complete path is a route that has valid endpoints i.e.:-
1149 * o DAC to output pin.
1150 * o Input Pin to ADC.
1151 * o Input pin to Output pin (bypass, sidetone)
1152 * o DAC to ADC (loopback).
1154 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1156 struct snd_soc_card *card = dapm->card;
1157 struct snd_soc_dapm_widget *w;
1158 struct snd_soc_dapm_context *d;
1160 LIST_HEAD(down_list);
1161 LIST_HEAD(async_domain);
1162 enum snd_soc_bias_level bias;
1165 trace_snd_soc_dapm_start(card);
1167 list_for_each_entry(d, &card->dapm_list, list) {
1168 if (d->n_widgets || d->codec == NULL) {
1169 if (d->idle_bias_off)
1170 d->target_bias_level = SND_SOC_BIAS_OFF;
1172 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1176 /* Check which widgets we need to power and store them in
1177 * lists indicating if they should be powered up or down.
1179 list_for_each_entry(w, &card->widgets, list) {
1181 case snd_soc_dapm_pre:
1182 dapm_seq_insert(w, &down_list, false);
1184 case snd_soc_dapm_post:
1185 dapm_seq_insert(w, &up_list, true);
1189 if (!w->power_check)
1193 power = w->power_check(w);
1200 /* Supplies and micbiases only bring
1201 * the context up to STANDBY as unless
1202 * something else is active and
1203 * passing audio they generally don't
1204 * require full power.
1207 case snd_soc_dapm_supply:
1208 case snd_soc_dapm_micbias:
1209 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1210 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1213 d->target_bias_level = SND_SOC_BIAS_ON;
1218 if (w->power == power)
1221 trace_snd_soc_dapm_widget_power(w, power);
1224 dapm_seq_insert(w, &up_list, true);
1226 dapm_seq_insert(w, &down_list, false);
1233 /* If there are no DAPM widgets then try to figure out power from the
1236 if (!dapm->n_widgets) {
1238 case SND_SOC_DAPM_STREAM_START:
1239 case SND_SOC_DAPM_STREAM_RESUME:
1240 dapm->target_bias_level = SND_SOC_BIAS_ON;
1242 case SND_SOC_DAPM_STREAM_STOP:
1243 if (dapm->codec->active)
1244 dapm->target_bias_level = SND_SOC_BIAS_ON;
1246 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1248 case SND_SOC_DAPM_STREAM_SUSPEND:
1249 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1251 case SND_SOC_DAPM_STREAM_NOP:
1252 dapm->target_bias_level = dapm->bias_level;
1259 /* Force all contexts in the card to the same bias state */
1260 bias = SND_SOC_BIAS_OFF;
1261 list_for_each_entry(d, &card->dapm_list, list)
1262 if (d->target_bias_level > bias)
1263 bias = d->target_bias_level;
1264 list_for_each_entry(d, &card->dapm_list, list)
1265 d->target_bias_level = bias;
1268 /* Run all the bias changes in parallel */
1269 list_for_each_entry(d, &dapm->card->dapm_list, list)
1270 async_schedule_domain(dapm_pre_sequence_async, d,
1272 async_synchronize_full_domain(&async_domain);
1274 /* Power down widgets first; try to avoid amplifying pops. */
1275 dapm_seq_run(dapm, &down_list, event, false);
1277 dapm_widget_update(dapm);
1280 dapm_seq_run(dapm, &up_list, event, true);
1282 /* Run all the bias changes in parallel */
1283 list_for_each_entry(d, &dapm->card->dapm_list, list)
1284 async_schedule_domain(dapm_post_sequence_async, d,
1286 async_synchronize_full_domain(&async_domain);
1288 pop_dbg(dapm->dev, card->pop_time,
1289 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1290 pop_wait(card->pop_time);
1292 trace_snd_soc_dapm_done(card);
1297 #ifdef CONFIG_DEBUG_FS
1298 static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1300 file->private_data = inode->i_private;
1304 static ssize_t dapm_widget_power_read_file(struct file *file,
1305 char __user *user_buf,
1306 size_t count, loff_t *ppos)
1308 struct snd_soc_dapm_widget *w = file->private_data;
1312 struct snd_soc_dapm_path *p = NULL;
1314 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1318 in = is_connected_input_ep(w);
1319 dapm_clear_walk(w->dapm);
1320 out = is_connected_output_ep(w);
1321 dapm_clear_walk(w->dapm);
1323 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
1324 w->name, w->power ? "On" : "Off", in, out);
1327 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1328 " - R%d(0x%x) bit %d",
1329 w->reg, w->reg, w->shift);
1331 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1334 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1336 w->active ? "active" : "inactive");
1338 list_for_each_entry(p, &w->sources, list_sink) {
1339 if (p->connected && !p->connected(w, p->sink))
1343 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1344 " in \"%s\" \"%s\"\n",
1345 p->name ? p->name : "static",
1348 list_for_each_entry(p, &w->sinks, list_source) {
1349 if (p->connected && !p->connected(w, p->sink))
1353 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1354 " out \"%s\" \"%s\"\n",
1355 p->name ? p->name : "static",
1359 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1365 static const struct file_operations dapm_widget_power_fops = {
1366 .open = dapm_widget_power_open_file,
1367 .read = dapm_widget_power_read_file,
1368 .llseek = default_llseek,
1371 static int dapm_bias_open_file(struct inode *inode, struct file *file)
1373 file->private_data = inode->i_private;
1377 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1378 size_t count, loff_t *ppos)
1380 struct snd_soc_dapm_context *dapm = file->private_data;
1383 switch (dapm->bias_level) {
1384 case SND_SOC_BIAS_ON:
1387 case SND_SOC_BIAS_PREPARE:
1388 level = "Prepare\n";
1390 case SND_SOC_BIAS_STANDBY:
1391 level = "Standby\n";
1393 case SND_SOC_BIAS_OFF:
1398 level = "Unknown\n";
1402 return simple_read_from_buffer(user_buf, count, ppos, level,
1406 static const struct file_operations dapm_bias_fops = {
1407 .open = dapm_bias_open_file,
1408 .read = dapm_bias_read_file,
1409 .llseek = default_llseek,
1412 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1413 struct dentry *parent)
1417 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1419 if (!dapm->debugfs_dapm) {
1421 "Failed to create DAPM debugfs directory\n");
1425 d = debugfs_create_file("bias_level", 0444,
1426 dapm->debugfs_dapm, dapm,
1430 "ASoC: Failed to create bias level debugfs file\n");
1433 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1435 struct snd_soc_dapm_context *dapm = w->dapm;
1438 if (!dapm->debugfs_dapm || !w->name)
1441 d = debugfs_create_file(w->name, 0444,
1442 dapm->debugfs_dapm, w,
1443 &dapm_widget_power_fops);
1445 dev_warn(w->dapm->dev,
1446 "ASoC: Failed to create %s debugfs file\n",
1450 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1452 debugfs_remove_recursive(dapm->debugfs_dapm);
1456 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1457 struct dentry *parent)
1461 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1465 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1471 /* test and update the power status of a mux widget */
1472 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1473 struct snd_kcontrol *kcontrol, int change,
1474 int mux, struct soc_enum *e)
1476 struct snd_soc_dapm_path *path;
1479 if (widget->id != snd_soc_dapm_mux &&
1480 widget->id != snd_soc_dapm_virt_mux &&
1481 widget->id != snd_soc_dapm_value_mux)
1487 /* find dapm widget path assoc with kcontrol */
1488 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1489 if (path->kcontrol != kcontrol)
1492 if (!path->name || !e->texts[mux])
1496 /* we now need to match the string in the enum to the path */
1497 if (!(strcmp(path->name, e->texts[mux])))
1498 path->connect = 1; /* new connection */
1500 path->connect = 0; /* old connection must be powered down */
1504 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1509 /* test and update the power status of a mixer or switch widget */
1510 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1511 struct snd_kcontrol *kcontrol, int connect)
1513 struct snd_soc_dapm_path *path;
1516 if (widget->id != snd_soc_dapm_mixer &&
1517 widget->id != snd_soc_dapm_mixer_named_ctl &&
1518 widget->id != snd_soc_dapm_switch)
1521 /* find dapm widget path assoc with kcontrol */
1522 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1523 if (path->kcontrol != kcontrol)
1526 /* found, now check type */
1528 path->connect = connect;
1533 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1538 /* show dapm widget status in sys fs */
1539 static ssize_t dapm_widget_show(struct device *dev,
1540 struct device_attribute *attr, char *buf)
1542 struct snd_soc_pcm_runtime *rtd =
1543 container_of(dev, struct snd_soc_pcm_runtime, dev);
1544 struct snd_soc_codec *codec =rtd->codec;
1545 struct snd_soc_dapm_widget *w;
1547 char *state = "not set";
1549 list_for_each_entry(w, &codec->card->widgets, list) {
1550 if (w->dapm != &codec->dapm)
1553 /* only display widgets that burnm power */
1555 case snd_soc_dapm_hp:
1556 case snd_soc_dapm_mic:
1557 case snd_soc_dapm_spk:
1558 case snd_soc_dapm_line:
1559 case snd_soc_dapm_micbias:
1560 case snd_soc_dapm_dac:
1561 case snd_soc_dapm_adc:
1562 case snd_soc_dapm_pga:
1563 case snd_soc_dapm_out_drv:
1564 case snd_soc_dapm_mixer:
1565 case snd_soc_dapm_mixer_named_ctl:
1566 case snd_soc_dapm_supply:
1568 count += sprintf(buf + count, "%s: %s\n",
1569 w->name, w->power ? "On":"Off");
1576 switch (codec->dapm.bias_level) {
1577 case SND_SOC_BIAS_ON:
1580 case SND_SOC_BIAS_PREPARE:
1583 case SND_SOC_BIAS_STANDBY:
1586 case SND_SOC_BIAS_OFF:
1590 count += sprintf(buf + count, "PM State: %s\n", state);
1595 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1597 int snd_soc_dapm_sys_add(struct device *dev)
1599 return device_create_file(dev, &dev_attr_dapm_widget);
1602 static void snd_soc_dapm_sys_remove(struct device *dev)
1604 device_remove_file(dev, &dev_attr_dapm_widget);
1607 /* free all dapm widgets and resources */
1608 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1610 struct snd_soc_dapm_widget *w, *next_w;
1611 struct snd_soc_dapm_path *p, *next_p;
1613 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1614 if (w->dapm != dapm)
1618 * remove source and sink paths associated to this widget.
1619 * While removing the path, remove reference to it from both
1620 * source and sink widgets so that path is removed only once.
1622 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1623 list_del(&p->list_sink);
1624 list_del(&p->list_source);
1626 kfree(p->long_name);
1629 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1630 list_del(&p->list_sink);
1631 list_del(&p->list_source);
1633 kfree(p->long_name);
1636 kfree(w->kcontrols);
1642 static struct snd_soc_dapm_widget *dapm_find_widget(
1643 struct snd_soc_dapm_context *dapm, const char *pin,
1644 bool search_other_contexts)
1646 struct snd_soc_dapm_widget *w;
1647 struct snd_soc_dapm_widget *fallback = NULL;
1649 list_for_each_entry(w, &dapm->card->widgets, list) {
1650 if (!strcmp(w->name, pin)) {
1651 if (w->dapm == dapm)
1658 if (search_other_contexts)
1664 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1665 const char *pin, int status)
1667 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
1670 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1674 w->connected = status;
1682 * snd_soc_dapm_sync - scan and power dapm paths
1683 * @dapm: DAPM context
1685 * Walks all dapm audio paths and powers widgets according to their
1686 * stream or path usage.
1688 * Returns 0 for success.
1690 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1692 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1694 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1696 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1697 const struct snd_soc_dapm_route *route)
1699 struct snd_soc_dapm_path *path;
1700 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1701 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1703 const char *control = route->control;
1705 char prefixed_sink[80];
1706 char prefixed_source[80];
1709 if (dapm->codec && dapm->codec->name_prefix) {
1710 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1711 dapm->codec->name_prefix, route->sink);
1712 sink = prefixed_sink;
1713 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1714 dapm->codec->name_prefix, route->source);
1715 source = prefixed_source;
1718 source = route->source;
1722 * find src and dest widgets over all widgets but favor a widget from
1723 * current DAPM context
1725 list_for_each_entry(w, &dapm->card->widgets, list) {
1726 if (!wsink && !(strcmp(w->name, sink))) {
1728 if (w->dapm == dapm)
1732 if (!wsource && !(strcmp(w->name, source))) {
1734 if (w->dapm == dapm)
1738 /* use widget from another DAPM context if not found from this */
1744 if (wsource == NULL || wsink == NULL)
1747 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1751 path->source = wsource;
1753 path->connected = route->connected;
1754 INIT_LIST_HEAD(&path->list);
1755 INIT_LIST_HEAD(&path->list_source);
1756 INIT_LIST_HEAD(&path->list_sink);
1758 /* check for external widgets */
1759 if (wsink->id == snd_soc_dapm_input) {
1760 if (wsource->id == snd_soc_dapm_micbias ||
1761 wsource->id == snd_soc_dapm_mic ||
1762 wsource->id == snd_soc_dapm_line ||
1763 wsource->id == snd_soc_dapm_output)
1766 if (wsource->id == snd_soc_dapm_output) {
1767 if (wsink->id == snd_soc_dapm_spk ||
1768 wsink->id == snd_soc_dapm_hp ||
1769 wsink->id == snd_soc_dapm_line ||
1770 wsink->id == snd_soc_dapm_input)
1774 /* connect static paths */
1775 if (control == NULL) {
1776 list_add(&path->list, &dapm->card->paths);
1777 list_add(&path->list_sink, &wsink->sources);
1778 list_add(&path->list_source, &wsource->sinks);
1783 /* connect dynamic paths */
1784 switch (wsink->id) {
1785 case snd_soc_dapm_adc:
1786 case snd_soc_dapm_dac:
1787 case snd_soc_dapm_pga:
1788 case snd_soc_dapm_out_drv:
1789 case snd_soc_dapm_input:
1790 case snd_soc_dapm_output:
1791 case snd_soc_dapm_micbias:
1792 case snd_soc_dapm_vmid:
1793 case snd_soc_dapm_pre:
1794 case snd_soc_dapm_post:
1795 case snd_soc_dapm_supply:
1796 case snd_soc_dapm_aif_in:
1797 case snd_soc_dapm_aif_out:
1798 list_add(&path->list, &dapm->card->paths);
1799 list_add(&path->list_sink, &wsink->sources);
1800 list_add(&path->list_source, &wsource->sinks);
1803 case snd_soc_dapm_mux:
1804 case snd_soc_dapm_virt_mux:
1805 case snd_soc_dapm_value_mux:
1806 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1807 &wsink->kcontrol_news[0]);
1811 case snd_soc_dapm_switch:
1812 case snd_soc_dapm_mixer:
1813 case snd_soc_dapm_mixer_named_ctl:
1814 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
1818 case snd_soc_dapm_hp:
1819 case snd_soc_dapm_mic:
1820 case snd_soc_dapm_line:
1821 case snd_soc_dapm_spk:
1822 list_add(&path->list, &dapm->card->paths);
1823 list_add(&path->list_sink, &wsink->sources);
1824 list_add(&path->list_source, &wsource->sinks);
1831 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
1832 source, control, sink);
1838 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1839 * @dapm: DAPM context
1840 * @route: audio routes
1841 * @num: number of routes
1843 * Connects 2 dapm widgets together via a named audio path. The sink is
1844 * the widget receiving the audio signal, whilst the source is the sender
1845 * of the audio signal.
1847 * Returns 0 for success else error. On error all resources can be freed
1848 * with a call to snd_soc_card_free().
1850 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1851 const struct snd_soc_dapm_route *route, int num)
1855 for (i = 0; i < num; i++) {
1856 ret = snd_soc_dapm_add_route(dapm, route);
1858 dev_err(dapm->dev, "Failed to add route %s->%s\n",
1859 route->source, route->sink);
1867 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1869 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
1870 const struct snd_soc_dapm_route *route)
1872 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
1875 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
1878 struct snd_soc_dapm_path *path;
1882 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
1888 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
1893 if (route->control || route->connected)
1894 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
1895 route->source, route->sink);
1897 list_for_each_entry(path, &source->sinks, list_source) {
1898 if (path->sink == sink) {
1905 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
1906 route->source, route->sink);
1908 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
1909 count, route->source, route->sink);
1915 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
1916 * @dapm: DAPM context
1917 * @route: audio routes
1918 * @num: number of routes
1920 * Mark existing routes matching those specified in the passed array
1921 * as being weak, meaning that they are ignored for the purpose of
1922 * power decisions. The main intended use case is for sidetone paths
1923 * which couple audio between other independent paths if they are both
1924 * active in order to make the combination work better at the user
1925 * level but which aren't intended to be "used".
1927 * Note that CODEC drivers should not use this as sidetone type paths
1928 * can frequently also be used as bypass paths.
1930 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
1931 const struct snd_soc_dapm_route *route, int num)
1936 for (i = 0; i < num; i++) {
1937 err = snd_soc_dapm_weak_route(dapm, route);
1945 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
1948 * snd_soc_dapm_new_widgets - add new dapm widgets
1949 * @dapm: DAPM context
1951 * Checks the codec for any new dapm widgets and creates them if found.
1953 * Returns 0 for success.
1955 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
1957 struct snd_soc_dapm_widget *w;
1960 list_for_each_entry(w, &dapm->card->widgets, list)
1965 if (w->num_kcontrols) {
1966 w->kcontrols = kzalloc(w->num_kcontrols *
1967 sizeof(struct snd_kcontrol *),
1974 case snd_soc_dapm_switch:
1975 case snd_soc_dapm_mixer:
1976 case snd_soc_dapm_mixer_named_ctl:
1977 w->power_check = dapm_generic_check_power;
1980 case snd_soc_dapm_mux:
1981 case snd_soc_dapm_virt_mux:
1982 case snd_soc_dapm_value_mux:
1983 w->power_check = dapm_generic_check_power;
1986 case snd_soc_dapm_adc:
1987 case snd_soc_dapm_aif_out:
1988 w->power_check = dapm_adc_check_power;
1990 case snd_soc_dapm_dac:
1991 case snd_soc_dapm_aif_in:
1992 w->power_check = dapm_dac_check_power;
1994 case snd_soc_dapm_pga:
1995 case snd_soc_dapm_out_drv:
1996 w->power_check = dapm_generic_check_power;
1999 case snd_soc_dapm_input:
2000 case snd_soc_dapm_output:
2001 case snd_soc_dapm_micbias:
2002 case snd_soc_dapm_spk:
2003 case snd_soc_dapm_hp:
2004 case snd_soc_dapm_mic:
2005 case snd_soc_dapm_line:
2006 w->power_check = dapm_generic_check_power;
2008 case snd_soc_dapm_supply:
2009 w->power_check = dapm_supply_check_power;
2010 case snd_soc_dapm_vmid:
2011 case snd_soc_dapm_pre:
2012 case snd_soc_dapm_post:
2016 /* Read the initial power state from the device */
2018 val = soc_widget_read(w, w->reg);
2019 val &= 1 << w->shift;
2029 dapm_debugfs_add_widget(w);
2032 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2035 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2038 * snd_soc_dapm_get_volsw - dapm mixer get callback
2039 * @kcontrol: mixer control
2040 * @ucontrol: control element information
2042 * Callback to get the value of a dapm mixer control.
2044 * Returns 0 for success.
2046 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2047 struct snd_ctl_elem_value *ucontrol)
2049 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2050 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2051 struct soc_mixer_control *mc =
2052 (struct soc_mixer_control *)kcontrol->private_value;
2053 unsigned int reg = mc->reg;
2054 unsigned int shift = mc->shift;
2055 unsigned int rshift = mc->rshift;
2057 unsigned int invert = mc->invert;
2058 unsigned int mask = (1 << fls(max)) - 1;
2060 ucontrol->value.integer.value[0] =
2061 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2062 if (shift != rshift)
2063 ucontrol->value.integer.value[1] =
2064 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2066 ucontrol->value.integer.value[0] =
2067 max - ucontrol->value.integer.value[0];
2068 if (shift != rshift)
2069 ucontrol->value.integer.value[1] =
2070 max - ucontrol->value.integer.value[1];
2075 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2078 * snd_soc_dapm_put_volsw - dapm mixer set callback
2079 * @kcontrol: mixer control
2080 * @ucontrol: control element information
2082 * Callback to set the value of a dapm mixer control.
2084 * Returns 0 for success.
2086 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2087 struct snd_ctl_elem_value *ucontrol)
2089 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2090 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2091 struct snd_soc_codec *codec = widget->codec;
2092 struct soc_mixer_control *mc =
2093 (struct soc_mixer_control *)kcontrol->private_value;
2094 unsigned int reg = mc->reg;
2095 unsigned int shift = mc->shift;
2097 unsigned int mask = (1 << fls(max)) - 1;
2098 unsigned int invert = mc->invert;
2100 int connect, change;
2101 struct snd_soc_dapm_update update;
2104 val = (ucontrol->value.integer.value[0] & mask);
2108 mask = mask << shift;
2112 /* new connection */
2113 connect = invert ? 0 : 1;
2115 /* old connection must be powered down */
2116 connect = invert ? 1 : 0;
2118 mutex_lock(&codec->mutex);
2120 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2122 for (wi = 0; wi < wlist->num_widgets; wi++) {
2123 widget = wlist->widgets[wi];
2125 widget->value = val;
2127 update.kcontrol = kcontrol;
2128 update.widget = widget;
2132 widget->dapm->update = &update;
2134 dapm_mixer_update_power(widget, kcontrol, connect);
2136 widget->dapm->update = NULL;
2140 mutex_unlock(&codec->mutex);
2143 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2146 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2147 * @kcontrol: mixer control
2148 * @ucontrol: control element information
2150 * Callback to get the value of a dapm enumerated double mixer control.
2152 * Returns 0 for success.
2154 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2155 struct snd_ctl_elem_value *ucontrol)
2157 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2158 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2159 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2160 unsigned int val, bitmask;
2162 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2164 val = snd_soc_read(widget->codec, e->reg);
2165 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2166 if (e->shift_l != e->shift_r)
2167 ucontrol->value.enumerated.item[1] =
2168 (val >> e->shift_r) & (bitmask - 1);
2172 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2175 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2176 * @kcontrol: mixer control
2177 * @ucontrol: control element information
2179 * Callback to set the value of a dapm enumerated double mixer control.
2181 * Returns 0 for success.
2183 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2184 struct snd_ctl_elem_value *ucontrol)
2186 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2187 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2188 struct snd_soc_codec *codec = widget->codec;
2189 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2190 unsigned int val, mux, change;
2191 unsigned int mask, bitmask;
2192 struct snd_soc_dapm_update update;
2195 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2197 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2199 mux = ucontrol->value.enumerated.item[0];
2200 val = mux << e->shift_l;
2201 mask = (bitmask - 1) << e->shift_l;
2202 if (e->shift_l != e->shift_r) {
2203 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2205 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2206 mask |= (bitmask - 1) << e->shift_r;
2209 mutex_lock(&codec->mutex);
2211 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2213 for (wi = 0; wi < wlist->num_widgets; wi++) {
2214 widget = wlist->widgets[wi];
2216 widget->value = val;
2218 update.kcontrol = kcontrol;
2219 update.widget = widget;
2220 update.reg = e->reg;
2223 widget->dapm->update = &update;
2225 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2227 widget->dapm->update = NULL;
2231 mutex_unlock(&codec->mutex);
2234 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2237 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2238 * @kcontrol: mixer control
2239 * @ucontrol: control element information
2241 * Returns 0 for success.
2243 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2244 struct snd_ctl_elem_value *ucontrol)
2246 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2247 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2249 ucontrol->value.enumerated.item[0] = widget->value;
2253 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2256 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2257 * @kcontrol: mixer control
2258 * @ucontrol: control element information
2260 * Returns 0 for success.
2262 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2263 struct snd_ctl_elem_value *ucontrol)
2265 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2266 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2267 struct snd_soc_codec *codec = widget->codec;
2268 struct soc_enum *e =
2269 (struct soc_enum *)kcontrol->private_value;
2274 if (ucontrol->value.enumerated.item[0] >= e->max)
2277 mutex_lock(&codec->mutex);
2279 change = widget->value != ucontrol->value.enumerated.item[0];
2281 for (wi = 0; wi < wlist->num_widgets; wi++) {
2282 widget = wlist->widgets[wi];
2284 widget->value = ucontrol->value.enumerated.item[0];
2286 dapm_mux_update_power(widget, kcontrol, change,
2291 mutex_unlock(&codec->mutex);
2294 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2297 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2299 * @kcontrol: mixer control
2300 * @ucontrol: control element information
2302 * Callback to get the value of a dapm semi enumerated double mixer control.
2304 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2305 * used for handling bitfield coded enumeration for example.
2307 * Returns 0 for success.
2309 int snd_soc_dapm_get_value_enum_double(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];
2314 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2315 unsigned int reg_val, val, mux;
2317 reg_val = snd_soc_read(widget->codec, e->reg);
2318 val = (reg_val >> e->shift_l) & e->mask;
2319 for (mux = 0; mux < e->max; mux++) {
2320 if (val == e->values[mux])
2323 ucontrol->value.enumerated.item[0] = mux;
2324 if (e->shift_l != e->shift_r) {
2325 val = (reg_val >> e->shift_r) & e->mask;
2326 for (mux = 0; mux < e->max; mux++) {
2327 if (val == e->values[mux])
2330 ucontrol->value.enumerated.item[1] = mux;
2335 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2338 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2340 * @kcontrol: mixer control
2341 * @ucontrol: control element information
2343 * Callback to set the value of a dapm semi enumerated double mixer control.
2345 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2346 * used for handling bitfield coded enumeration for example.
2348 * Returns 0 for success.
2350 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2351 struct snd_ctl_elem_value *ucontrol)
2353 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2354 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2355 struct snd_soc_codec *codec = widget->codec;
2356 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2357 unsigned int val, mux, change;
2359 struct snd_soc_dapm_update update;
2362 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2364 mux = ucontrol->value.enumerated.item[0];
2365 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2366 mask = e->mask << e->shift_l;
2367 if (e->shift_l != e->shift_r) {
2368 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2370 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2371 mask |= e->mask << e->shift_r;
2374 mutex_lock(&codec->mutex);
2376 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2378 for (wi = 0; wi < wlist->num_widgets; wi++) {
2379 widget = wlist->widgets[wi];
2381 widget->value = val;
2383 update.kcontrol = kcontrol;
2384 update.widget = widget;
2385 update.reg = e->reg;
2388 widget->dapm->update = &update;
2390 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2392 widget->dapm->update = NULL;
2396 mutex_unlock(&codec->mutex);
2399 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2402 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2404 * @kcontrol: mixer control
2405 * @uinfo: control element information
2407 * Callback to provide information about a pin switch control.
2409 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2410 struct snd_ctl_elem_info *uinfo)
2412 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2414 uinfo->value.integer.min = 0;
2415 uinfo->value.integer.max = 1;
2419 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2422 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2424 * @kcontrol: mixer control
2427 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2428 struct snd_ctl_elem_value *ucontrol)
2430 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2431 const char *pin = (const char *)kcontrol->private_value;
2433 mutex_lock(&codec->mutex);
2435 ucontrol->value.integer.value[0] =
2436 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
2438 mutex_unlock(&codec->mutex);
2442 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2445 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2447 * @kcontrol: mixer control
2450 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2451 struct snd_ctl_elem_value *ucontrol)
2453 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2454 const char *pin = (const char *)kcontrol->private_value;
2456 mutex_lock(&codec->mutex);
2458 if (ucontrol->value.integer.value[0])
2459 snd_soc_dapm_enable_pin(&codec->dapm, pin);
2461 snd_soc_dapm_disable_pin(&codec->dapm, pin);
2463 snd_soc_dapm_sync(&codec->dapm);
2465 mutex_unlock(&codec->mutex);
2469 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2472 * snd_soc_dapm_new_control - create new dapm control
2473 * @dapm: DAPM context
2474 * @widget: widget template
2476 * Creates a new dapm control based upon the template.
2478 * Returns 0 for success else error.
2480 int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2481 const struct snd_soc_dapm_widget *widget)
2483 struct snd_soc_dapm_widget *w;
2486 if ((w = dapm_cnew_widget(widget)) == NULL)
2489 name_len = strlen(widget->name) + 1;
2490 if (dapm->codec && dapm->codec->name_prefix)
2491 name_len += 1 + strlen(dapm->codec->name_prefix);
2492 w->name = kmalloc(name_len, GFP_KERNEL);
2493 if (w->name == NULL) {
2497 if (dapm->codec && dapm->codec->name_prefix)
2498 snprintf(w->name, name_len, "%s %s",
2499 dapm->codec->name_prefix, widget->name);
2501 snprintf(w->name, name_len, "%s", widget->name);
2505 w->codec = dapm->codec;
2506 w->platform = dapm->platform;
2507 INIT_LIST_HEAD(&w->sources);
2508 INIT_LIST_HEAD(&w->sinks);
2509 INIT_LIST_HEAD(&w->list);
2510 list_add(&w->list, &dapm->card->widgets);
2512 /* machine layer set ups unconnected pins and insertions */
2516 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
2519 * snd_soc_dapm_new_controls - create new dapm controls
2520 * @dapm: DAPM context
2521 * @widget: widget array
2522 * @num: number of widgets
2524 * Creates new DAPM controls based upon the templates.
2526 * Returns 0 for success else error.
2528 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2529 const struct snd_soc_dapm_widget *widget,
2534 for (i = 0; i < num; i++) {
2535 ret = snd_soc_dapm_new_control(dapm, widget);
2538 "ASoC: Failed to create DAPM control %s: %d\n",
2546 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2548 static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2549 const char *stream, int event)
2551 struct snd_soc_dapm_widget *w;
2553 list_for_each_entry(w, &dapm->card->widgets, list)
2555 if (!w->sname || w->dapm != dapm)
2557 dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2558 w->name, w->sname, stream, event);
2559 if (strstr(w->sname, stream)) {
2561 case SND_SOC_DAPM_STREAM_START:
2564 case SND_SOC_DAPM_STREAM_STOP:
2567 case SND_SOC_DAPM_STREAM_SUSPEND:
2568 case SND_SOC_DAPM_STREAM_RESUME:
2569 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
2570 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2576 dapm_power_widgets(dapm, event);
2580 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2581 * @rtd: PCM runtime data
2582 * @stream: stream name
2583 * @event: stream event
2585 * Sends a stream event to the dapm core. The core then makes any
2586 * necessary widget power changes.
2588 * Returns 0 for success else error.
2590 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2591 const char *stream, int event)
2593 struct snd_soc_codec *codec = rtd->codec;
2598 mutex_lock(&codec->mutex);
2599 soc_dapm_stream_event(&codec->dapm, stream, event);
2600 mutex_unlock(&codec->mutex);
2605 * snd_soc_dapm_enable_pin - enable pin.
2606 * @dapm: DAPM context
2609 * Enables input/output pin and its parents or children widgets iff there is
2610 * a valid audio route and active audio stream.
2611 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2612 * do any widget power switching.
2614 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2616 return snd_soc_dapm_set_pin(dapm, pin, 1);
2618 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2621 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2622 * @dapm: DAPM context
2625 * Enables input/output pin regardless of any other state. This is
2626 * intended for use with microphone bias supplies used in microphone
2629 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2630 * do any widget power switching.
2632 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2635 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2638 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2642 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
2648 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2651 * snd_soc_dapm_disable_pin - disable pin.
2652 * @dapm: DAPM context
2655 * Disables input/output pin and its parents or children widgets.
2656 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2657 * do any widget power switching.
2659 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2662 return snd_soc_dapm_set_pin(dapm, pin, 0);
2664 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2667 * snd_soc_dapm_nc_pin - permanently disable pin.
2668 * @dapm: DAPM context
2671 * Marks the specified pin as being not connected, disabling it along
2672 * any parent or child widgets. At present this is identical to
2673 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2674 * additional things such as disabling controls which only affect
2675 * paths through the pin.
2677 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2678 * do any widget power switching.
2680 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2682 return snd_soc_dapm_set_pin(dapm, pin, 0);
2684 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2687 * snd_soc_dapm_get_pin_status - get audio pin status
2688 * @dapm: DAPM context
2689 * @pin: audio signal pin endpoint (or start point)
2691 * Get audio pin status - connected or disconnected.
2693 * Returns 1 for connected otherwise 0.
2695 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2698 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2701 return w->connected;
2705 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2708 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2709 * @dapm: DAPM context
2710 * @pin: audio signal pin endpoint (or start point)
2712 * Mark the given endpoint or pin as ignoring suspend. When the
2713 * system is disabled a path between two endpoints flagged as ignoring
2714 * suspend will not be disabled. The path must already be enabled via
2715 * normal means at suspend time, it will not be turned on if it was not
2718 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2721 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
2724 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2728 w->ignore_suspend = 1;
2732 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2735 * snd_soc_dapm_free - free dapm resources
2738 * Free all dapm widgets and resources.
2740 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2742 snd_soc_dapm_sys_remove(dapm->dev);
2743 dapm_debugfs_cleanup(dapm);
2744 dapm_free_widgets(dapm);
2745 list_del(&dapm->list);
2747 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2749 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2751 struct snd_soc_dapm_widget *w;
2752 LIST_HEAD(down_list);
2755 list_for_each_entry(w, &dapm->card->widgets, list) {
2756 if (w->dapm != dapm)
2759 dapm_seq_insert(w, &down_list, false);
2765 /* If there were no widgets to power down we're already in
2769 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
2770 dapm_seq_run(dapm, &down_list, 0, false);
2771 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
2776 * snd_soc_dapm_shutdown - callback for system shutdown
2778 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2780 struct snd_soc_codec *codec;
2782 list_for_each_entry(codec, &card->codec_dev_list, list) {
2783 soc_dapm_shutdown_codec(&codec->dapm);
2784 snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
2788 /* Module information */
2789 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2790 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2791 MODULE_LICENSE("GPL");