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 static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
124 return !list_empty(&w->dirty);
127 static void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
129 if (!dapm_dirty_widget(w)) {
130 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
132 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
136 /* create a new dapm widget */
137 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
138 const struct snd_soc_dapm_widget *_widget)
140 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
143 /* get snd_card from DAPM context */
144 static inline struct snd_card *dapm_get_snd_card(
145 struct snd_soc_dapm_context *dapm)
148 return dapm->codec->card->snd_card;
149 else if (dapm->platform)
150 return dapm->platform->card->snd_card;
158 /* get soc_card from DAPM context */
159 static inline struct snd_soc_card *dapm_get_soc_card(
160 struct snd_soc_dapm_context *dapm)
163 return dapm->codec->card;
164 else if (dapm->platform)
165 return dapm->platform->card;
173 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
176 return snd_soc_read(w->codec, reg);
177 else if (w->platform)
178 return snd_soc_platform_read(w->platform, reg);
180 dev_err(w->dapm->dev, "no valid widget read method\n");
184 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
187 return snd_soc_write(w->codec, reg, val);
188 else if (w->platform)
189 return snd_soc_platform_write(w->platform, reg, val);
191 dev_err(w->dapm->dev, "no valid widget write method\n");
195 static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
196 unsigned short reg, unsigned int mask, unsigned int value)
199 unsigned int old, new;
202 ret = soc_widget_read(w, reg);
207 new = (old & ~mask) | (value & mask);
210 ret = soc_widget_write(w, reg, new);
219 * snd_soc_dapm_set_bias_level - set the bias level for the system
220 * @dapm: DAPM context
221 * @level: level to configure
223 * Configure the bias (power) levels for the SoC audio device.
225 * Returns 0 for success else error.
227 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
228 enum snd_soc_bias_level level)
230 struct snd_soc_card *card = dapm->card;
233 trace_snd_soc_bias_level_start(card, level);
235 if (card && card->set_bias_level)
236 ret = card->set_bias_level(card, dapm, level);
241 if (dapm->codec->driver->set_bias_level)
242 ret = dapm->codec->driver->set_bias_level(dapm->codec,
245 dapm->bias_level = level;
250 if (card && card->set_bias_level_post)
251 ret = card->set_bias_level_post(card, dapm, level);
253 trace_snd_soc_bias_level_done(card, level);
258 /* set up initial codec paths */
259 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
260 struct snd_soc_dapm_path *p, int i)
263 case snd_soc_dapm_switch:
264 case snd_soc_dapm_mixer:
265 case snd_soc_dapm_mixer_named_ctl: {
267 struct soc_mixer_control *mc = (struct soc_mixer_control *)
268 w->kcontrol_news[i].private_value;
269 unsigned int reg = mc->reg;
270 unsigned int shift = mc->shift;
272 unsigned int mask = (1 << fls(max)) - 1;
273 unsigned int invert = mc->invert;
275 val = soc_widget_read(w, reg);
276 val = (val >> shift) & mask;
278 if ((invert && !val) || (!invert && val))
284 case snd_soc_dapm_mux: {
285 struct soc_enum *e = (struct soc_enum *)
286 w->kcontrol_news[i].private_value;
287 int val, item, bitmask;
289 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
291 val = soc_widget_read(w, e->reg);
292 item = (val >> e->shift_l) & (bitmask - 1);
295 for (i = 0; i < e->max; i++) {
296 if (!(strcmp(p->name, e->texts[i])) && item == i)
301 case snd_soc_dapm_virt_mux: {
302 struct soc_enum *e = (struct soc_enum *)
303 w->kcontrol_news[i].private_value;
306 /* since a virtual mux has no backing registers to
307 * decide which path to connect, it will try to match
308 * with the first enumeration. This is to ensure
309 * that the default mux choice (the first) will be
310 * correctly powered up during initialization.
312 if (!strcmp(p->name, e->texts[0]))
316 case snd_soc_dapm_value_mux: {
317 struct soc_enum *e = (struct soc_enum *)
318 w->kcontrol_news[i].private_value;
321 val = soc_widget_read(w, e->reg);
322 val = (val >> e->shift_l) & e->mask;
323 for (item = 0; item < e->max; item++) {
324 if (val == e->values[item])
329 for (i = 0; i < e->max; i++) {
330 if (!(strcmp(p->name, e->texts[i])) && item == i)
335 /* does not affect routing - always connected */
336 case snd_soc_dapm_pga:
337 case snd_soc_dapm_out_drv:
338 case snd_soc_dapm_output:
339 case snd_soc_dapm_adc:
340 case snd_soc_dapm_input:
341 case snd_soc_dapm_dac:
342 case snd_soc_dapm_micbias:
343 case snd_soc_dapm_vmid:
344 case snd_soc_dapm_supply:
345 case snd_soc_dapm_aif_in:
346 case snd_soc_dapm_aif_out:
347 case snd_soc_dapm_hp:
348 case snd_soc_dapm_mic:
349 case snd_soc_dapm_spk:
350 case snd_soc_dapm_line:
353 /* does affect routing - dynamically connected */
354 case snd_soc_dapm_pre:
355 case snd_soc_dapm_post:
361 /* connect mux widget to its interconnecting audio paths */
362 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
363 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
364 struct snd_soc_dapm_path *path, const char *control_name,
365 const struct snd_kcontrol_new *kcontrol)
367 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
370 for (i = 0; i < e->max; i++) {
371 if (!(strcmp(control_name, e->texts[i]))) {
372 list_add(&path->list, &dapm->card->paths);
373 list_add(&path->list_sink, &dest->sources);
374 list_add(&path->list_source, &src->sinks);
375 path->name = (char*)e->texts[i];
376 dapm_set_path_status(dest, path, 0);
384 /* connect mixer widget to its interconnecting audio paths */
385 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
386 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
387 struct snd_soc_dapm_path *path, const char *control_name)
391 /* search for mixer kcontrol */
392 for (i = 0; i < dest->num_kcontrols; i++) {
393 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
394 list_add(&path->list, &dapm->card->paths);
395 list_add(&path->list_sink, &dest->sources);
396 list_add(&path->list_source, &src->sinks);
397 path->name = dest->kcontrol_news[i].name;
398 dapm_set_path_status(dest, path, i);
405 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
406 struct snd_soc_dapm_widget *kcontrolw,
407 const struct snd_kcontrol_new *kcontrol_new,
408 struct snd_kcontrol **kcontrol)
410 struct snd_soc_dapm_widget *w;
415 list_for_each_entry(w, &dapm->card->widgets, list) {
416 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
418 for (i = 0; i < w->num_kcontrols; i++) {
419 if (&w->kcontrol_news[i] == kcontrol_new) {
421 *kcontrol = w->kcontrols[i];
430 /* create new dapm mixer control */
431 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
433 struct snd_soc_dapm_context *dapm = w->dapm;
435 size_t name_len, prefix_len;
436 struct snd_soc_dapm_path *path;
437 struct snd_card *card = dapm->card->snd_card;
439 struct snd_soc_dapm_widget_list *wlist;
443 prefix = dapm->codec->name_prefix;
448 prefix_len = strlen(prefix) + 1;
453 for (i = 0; i < w->num_kcontrols; i++) {
456 list_for_each_entry(path, &w->sources, list_sink) {
458 /* mixer/mux paths name must match control name */
459 if (path->name != (char *)w->kcontrol_news[i].name)
462 if (w->kcontrols[i]) {
463 path->kcontrol = w->kcontrols[i];
467 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
468 sizeof(struct snd_soc_dapm_widget *),
469 wlist = kzalloc(wlistsize, GFP_KERNEL);
472 "asoc: can't allocate widget list for %s\n",
476 wlist->num_widgets = 1;
477 wlist->widgets[0] = w;
479 /* add dapm control with long name.
480 * for dapm_mixer this is the concatenation of the
481 * mixer and kcontrol name.
482 * for dapm_mixer_named_ctl this is simply the
485 name_len = strlen(w->kcontrol_news[i].name) + 1;
486 if (w->id != snd_soc_dapm_mixer_named_ctl)
487 name_len += 1 + strlen(w->name);
489 path->long_name = kmalloc(name_len, GFP_KERNEL);
491 if (path->long_name == NULL) {
498 /* The control will get a prefix from
499 * the control creation process but
500 * we're also using the same prefix
501 * for widgets so cut the prefix off
502 * the front of the widget name.
504 snprintf(path->long_name, name_len, "%s %s",
505 w->name + prefix_len,
506 w->kcontrol_news[i].name);
508 case snd_soc_dapm_mixer_named_ctl:
509 snprintf(path->long_name, name_len, "%s",
510 w->kcontrol_news[i].name);
514 path->long_name[name_len - 1] = '\0';
516 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
517 wlist, path->long_name,
519 ret = snd_ctl_add(card, path->kcontrol);
522 "asoc: failed to add dapm kcontrol %s: %d\n",
523 path->long_name, ret);
525 kfree(path->long_name);
526 path->long_name = NULL;
529 w->kcontrols[i] = path->kcontrol;
535 /* create new dapm mux control */
536 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
538 struct snd_soc_dapm_context *dapm = w->dapm;
539 struct snd_soc_dapm_path *path = NULL;
540 struct snd_kcontrol *kcontrol;
541 struct snd_card *card = dapm->card->snd_card;
545 struct snd_soc_dapm_widget_list *wlist;
546 int shared, wlistentries;
550 if (w->num_kcontrols != 1) {
552 "asoc: mux %s has incorrect number of controls\n",
557 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
560 wlist = kcontrol->private_data;
561 wlistentries = wlist->num_widgets + 1;
566 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
567 wlistentries * sizeof(struct snd_soc_dapm_widget *),
568 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
571 "asoc: can't allocate widget list for %s\n", w->name);
574 wlist->num_widgets = wlistentries;
575 wlist->widgets[wlistentries - 1] = w;
579 prefix = dapm->codec->name_prefix;
584 name = w->kcontrol_news[0].name;
589 prefix_len = strlen(prefix) + 1;
595 * The control will get a prefix from the control creation
596 * process but we're also using the same prefix for widgets so
597 * cut the prefix off the front of the widget name.
599 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
600 name + prefix_len, prefix);
601 ret = snd_ctl_add(card, kcontrol);
603 dev_err(dapm->dev, "failed to add kcontrol %s: %d\n",
610 kcontrol->private_data = wlist;
612 w->kcontrols[0] = kcontrol;
614 list_for_each_entry(path, &w->sources, list_sink)
615 path->kcontrol = kcontrol;
620 /* create new dapm volume control */
621 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
623 if (w->num_kcontrols)
624 dev_err(w->dapm->dev,
625 "asoc: PGA controls not supported: '%s'\n", w->name);
630 /* reset 'walked' bit for each dapm path */
631 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
633 struct snd_soc_dapm_path *p;
635 list_for_each_entry(p, &dapm->card->paths, list)
639 /* We implement power down on suspend by checking the power state of
640 * the ALSA card - when we are suspending the ALSA state for the card
643 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
645 int level = snd_power_get_state(widget->dapm->card->snd_card);
648 case SNDRV_CTL_POWER_D3hot:
649 case SNDRV_CTL_POWER_D3cold:
650 if (widget->ignore_suspend)
651 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
653 return widget->ignore_suspend;
660 * Recursively check for a completed path to an active or physically connected
661 * output widget. Returns number of complete paths.
663 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
665 struct snd_soc_dapm_path *path;
668 DAPM_UPDATE_STAT(widget, path_checks);
670 if (widget->id == snd_soc_dapm_supply)
673 switch (widget->id) {
674 case snd_soc_dapm_adc:
675 case snd_soc_dapm_aif_out:
677 return snd_soc_dapm_suspend_check(widget);
682 if (widget->connected) {
683 /* connected pin ? */
684 if (widget->id == snd_soc_dapm_output && !widget->ext)
685 return snd_soc_dapm_suspend_check(widget);
687 /* connected jack or spk ? */
688 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
689 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
690 return snd_soc_dapm_suspend_check(widget);
693 list_for_each_entry(path, &widget->sinks, list_source) {
694 DAPM_UPDATE_STAT(widget, neighbour_checks);
702 if (path->sink && path->connect) {
704 con += is_connected_output_ep(path->sink);
712 * Recursively check for a completed path to an active or physically connected
713 * input widget. Returns number of complete paths.
715 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
717 struct snd_soc_dapm_path *path;
720 DAPM_UPDATE_STAT(widget, path_checks);
722 if (widget->id == snd_soc_dapm_supply)
725 /* active stream ? */
726 switch (widget->id) {
727 case snd_soc_dapm_dac:
728 case snd_soc_dapm_aif_in:
730 return snd_soc_dapm_suspend_check(widget);
735 if (widget->connected) {
736 /* connected pin ? */
737 if (widget->id == snd_soc_dapm_input && !widget->ext)
738 return snd_soc_dapm_suspend_check(widget);
740 /* connected VMID/Bias for lower pops */
741 if (widget->id == snd_soc_dapm_vmid)
742 return snd_soc_dapm_suspend_check(widget);
744 /* connected jack ? */
745 if (widget->id == snd_soc_dapm_mic ||
746 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
747 return snd_soc_dapm_suspend_check(widget);
750 list_for_each_entry(path, &widget->sources, list_sink) {
751 DAPM_UPDATE_STAT(widget, neighbour_checks);
759 if (path->source && path->connect) {
761 con += is_connected_input_ep(path->source);
769 * Handler for generic register modifier widget.
771 int dapm_reg_event(struct snd_soc_dapm_widget *w,
772 struct snd_kcontrol *kcontrol, int event)
776 if (SND_SOC_DAPM_EVENT_ON(event))
781 soc_widget_update_bits(w, -(w->reg + 1),
782 w->mask << w->shift, val << w->shift);
786 EXPORT_SYMBOL_GPL(dapm_reg_event);
788 static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
793 return w->power_check(w);
796 /* Generic check to see if a widget should be powered.
798 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
802 DAPM_UPDATE_STAT(w, power_checks);
804 in = is_connected_input_ep(w);
805 dapm_clear_walk(w->dapm);
806 out = is_connected_output_ep(w);
807 dapm_clear_walk(w->dapm);
808 return out != 0 && in != 0;
811 /* Check to see if an ADC has power */
812 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
816 DAPM_UPDATE_STAT(w, power_checks);
819 in = is_connected_input_ep(w);
820 dapm_clear_walk(w->dapm);
823 return dapm_generic_check_power(w);
827 /* Check to see if a DAC has power */
828 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
832 DAPM_UPDATE_STAT(w, power_checks);
835 out = is_connected_output_ep(w);
836 dapm_clear_walk(w->dapm);
839 return dapm_generic_check_power(w);
843 /* Check to see if a power supply is needed */
844 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
846 struct snd_soc_dapm_path *path;
849 DAPM_UPDATE_STAT(w, power_checks);
851 /* Check if one of our outputs is connected */
852 list_for_each_entry(path, &w->sinks, list_source) {
853 DAPM_UPDATE_STAT(w, neighbour_checks);
858 if (path->connected &&
859 !path->connected(path->source, path->sink))
865 if (dapm_widget_power_check(path->sink)) {
871 dapm_clear_walk(w->dapm);
876 static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
881 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
882 struct snd_soc_dapm_widget *b,
890 sort = dapm_down_seq;
892 if (sort[a->id] != sort[b->id])
893 return sort[a->id] - sort[b->id];
894 if (a->subseq != b->subseq) {
896 return a->subseq - b->subseq;
898 return b->subseq - a->subseq;
900 if (a->reg != b->reg)
901 return a->reg - b->reg;
902 if (a->dapm != b->dapm)
903 return (unsigned long)a->dapm - (unsigned long)b->dapm;
908 /* Insert a widget in order into a DAPM power sequence. */
909 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
910 struct list_head *list,
913 struct snd_soc_dapm_widget *w;
915 list_for_each_entry(w, list, power_list)
916 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
917 list_add_tail(&new_widget->power_list, &w->power_list);
921 list_add_tail(&new_widget->power_list, list);
924 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
925 struct snd_soc_dapm_widget *w, int event)
927 struct snd_soc_card *card = dapm->card;
932 case SND_SOC_DAPM_PRE_PMU:
936 case SND_SOC_DAPM_POST_PMU:
937 ev_name = "POST_PMU";
940 case SND_SOC_DAPM_PRE_PMD:
944 case SND_SOC_DAPM_POST_PMD:
945 ev_name = "POST_PMD";
953 if (w->power != power)
956 if (w->event && (w->event_flags & event)) {
957 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
959 trace_snd_soc_dapm_widget_event_start(w, event);
960 ret = w->event(w, NULL, event);
961 trace_snd_soc_dapm_widget_event_done(w, event);
963 pr_err("%s: %s event failed: %d\n",
964 ev_name, w->name, ret);
968 /* Apply the coalesced changes from a DAPM sequence */
969 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
970 struct list_head *pending)
972 struct snd_soc_card *card = dapm->card;
973 struct snd_soc_dapm_widget *w;
975 unsigned int value = 0;
976 unsigned int mask = 0;
977 unsigned int cur_mask;
979 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
982 list_for_each_entry(w, pending, power_list) {
983 cur_mask = 1 << w->shift;
984 BUG_ON(reg != w->reg);
995 pop_dbg(dapm->dev, card->pop_time,
996 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
997 w->name, reg, value, mask);
999 /* Check for events */
1000 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
1001 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
1005 /* Any widget will do, they should all be updating the
1008 w = list_first_entry(pending, struct snd_soc_dapm_widget,
1011 pop_dbg(dapm->dev, card->pop_time,
1012 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1013 value, mask, reg, card->pop_time);
1014 pop_wait(card->pop_time);
1015 soc_widget_update_bits(w, reg, mask, value);
1018 list_for_each_entry(w, pending, power_list) {
1019 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
1020 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
1024 /* Apply a DAPM power sequence.
1026 * We walk over a pre-sorted list of widgets to apply power to. In
1027 * order to minimise the number of writes to the device required
1028 * multiple widgets will be updated in a single write where possible.
1029 * Currently anything that requires more than a single write is not
1032 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1033 struct list_head *list, int event, bool power_up)
1035 struct snd_soc_dapm_widget *w, *n;
1038 int cur_subseq = -1;
1039 int cur_reg = SND_SOC_NOPM;
1040 struct snd_soc_dapm_context *cur_dapm = NULL;
1047 sort = dapm_down_seq;
1049 list_for_each_entry_safe(w, n, list, power_list) {
1052 /* Do we need to apply any queued changes? */
1053 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1054 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1055 if (!list_empty(&pending))
1056 dapm_seq_run_coalesced(cur_dapm, &pending);
1058 if (cur_dapm && cur_dapm->seq_notifier) {
1059 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1060 if (sort[i] == cur_sort)
1061 cur_dapm->seq_notifier(cur_dapm,
1066 INIT_LIST_HEAD(&pending);
1068 cur_subseq = INT_MIN;
1069 cur_reg = SND_SOC_NOPM;
1074 case snd_soc_dapm_pre:
1076 list_for_each_entry_safe_continue(w, n, list,
1079 if (event == SND_SOC_DAPM_STREAM_START)
1081 NULL, SND_SOC_DAPM_PRE_PMU);
1082 else if (event == SND_SOC_DAPM_STREAM_STOP)
1084 NULL, SND_SOC_DAPM_PRE_PMD);
1087 case snd_soc_dapm_post:
1089 list_for_each_entry_safe_continue(w, n, list,
1092 if (event == SND_SOC_DAPM_STREAM_START)
1094 NULL, SND_SOC_DAPM_POST_PMU);
1095 else if (event == SND_SOC_DAPM_STREAM_STOP)
1097 NULL, SND_SOC_DAPM_POST_PMD);
1101 /* Queue it up for application */
1102 cur_sort = sort[w->id];
1103 cur_subseq = w->subseq;
1106 list_move(&w->power_list, &pending);
1111 dev_err(w->dapm->dev,
1112 "Failed to apply widget power: %d\n", ret);
1115 if (!list_empty(&pending))
1116 dapm_seq_run_coalesced(cur_dapm, &pending);
1118 if (cur_dapm && cur_dapm->seq_notifier) {
1119 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1120 if (sort[i] == cur_sort)
1121 cur_dapm->seq_notifier(cur_dapm,
1126 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1128 struct snd_soc_dapm_update *update = dapm->update;
1129 struct snd_soc_dapm_widget *w;
1138 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1139 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1141 pr_err("%s DAPM pre-event failed: %d\n",
1145 ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
1148 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1151 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1152 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1154 pr_err("%s DAPM post-event failed: %d\n",
1159 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1160 * they're changing state.
1162 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1164 struct snd_soc_dapm_context *d = data;
1167 /* If we're off and we're not supposed to be go into STANDBY */
1168 if (d->bias_level == SND_SOC_BIAS_OFF &&
1169 d->target_bias_level != SND_SOC_BIAS_OFF) {
1170 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1173 "Failed to turn on bias: %d\n", ret);
1176 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1177 if (d->bias_level != d->target_bias_level) {
1178 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1181 "Failed to prepare bias: %d\n", ret);
1185 /* Async callback run prior to DAPM sequences - brings to their final
1188 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1190 struct snd_soc_dapm_context *d = data;
1193 /* If we just powered the last thing off drop to standby bias */
1194 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1195 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1196 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1197 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1199 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1203 /* If we're in standby and can support bias off then do that */
1204 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1205 d->target_bias_level == SND_SOC_BIAS_OFF) {
1206 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1208 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1211 /* If we just powered up then move to active bias */
1212 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1213 d->target_bias_level == SND_SOC_BIAS_ON) {
1214 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1216 dev_err(d->dev, "Failed to apply active bias: %d\n",
1221 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
1222 bool power, bool connect)
1224 /* If a connection is being made or broken then that update
1225 * will have marked the peer dirty, otherwise the widgets are
1226 * not connected and this update has no impact. */
1230 /* If the peer is already in the state we're moving to then we
1231 * won't have an impact on it. */
1232 if (power != peer->power)
1233 dapm_mark_dirty(peer, "peer state change");
1236 static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1237 struct list_head *up_list,
1238 struct list_head *down_list)
1240 struct snd_soc_dapm_path *path;
1242 if (w->power == power)
1245 trace_snd_soc_dapm_widget_power(w, power);
1247 /* If we changed our power state perhaps our neigbours changed
1250 list_for_each_entry(path, &w->sources, list_sink) {
1252 dapm_widget_set_peer_power(path->source, power,
1256 list_for_each_entry(path, &w->sinks, list_source) {
1258 dapm_widget_set_peer_power(path->sink, power,
1264 dapm_seq_insert(w, up_list, true);
1266 dapm_seq_insert(w, down_list, false);
1271 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1272 struct list_head *up_list,
1273 struct list_head *down_list)
1278 case snd_soc_dapm_pre:
1279 dapm_seq_insert(w, down_list, false);
1281 case snd_soc_dapm_post:
1282 dapm_seq_insert(w, up_list, true);
1286 power = dapm_widget_power_check(w);
1288 dapm_widget_set_power(w, power, up_list, down_list);
1294 * Scan each dapm widget for complete audio path.
1295 * A complete path is a route that has valid endpoints i.e.:-
1297 * o DAC to output pin.
1298 * o Input Pin to ADC.
1299 * o Input pin to Output pin (bypass, sidetone)
1300 * o DAC to ADC (loopback).
1302 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1304 struct snd_soc_card *card = dapm->card;
1305 struct snd_soc_dapm_widget *w;
1306 struct snd_soc_dapm_context *d;
1308 LIST_HEAD(down_list);
1309 LIST_HEAD(async_domain);
1310 enum snd_soc_bias_level bias;
1312 trace_snd_soc_dapm_start(card);
1314 list_for_each_entry(d, &card->dapm_list, list) {
1315 if (d->n_widgets || d->codec == NULL) {
1316 if (d->idle_bias_off)
1317 d->target_bias_level = SND_SOC_BIAS_OFF;
1319 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1323 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
1325 /* Check which widgets we need to power and store them in
1326 * lists indicating if they should be powered up or down. We
1327 * only check widgets that have been flagged as dirty but note
1328 * that new widgets may be added to the dirty list while we
1331 list_for_each_entry(w, &card->dapm_dirty, dirty) {
1332 dapm_power_one_widget(w, &up_list, &down_list);
1335 list_for_each_entry(w, &card->widgets, list) {
1336 list_del_init(&w->dirty);
1341 /* Supplies and micbiases only bring the
1342 * context up to STANDBY as unless something
1343 * else is active and passing audio they
1344 * generally don't require full power.
1347 case snd_soc_dapm_supply:
1348 case snd_soc_dapm_micbias:
1349 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1350 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1353 d->target_bias_level = SND_SOC_BIAS_ON;
1360 /* If there are no DAPM widgets then try to figure out power from the
1363 if (!dapm->n_widgets) {
1365 case SND_SOC_DAPM_STREAM_START:
1366 case SND_SOC_DAPM_STREAM_RESUME:
1367 dapm->target_bias_level = SND_SOC_BIAS_ON;
1369 case SND_SOC_DAPM_STREAM_STOP:
1370 if (dapm->codec->active)
1371 dapm->target_bias_level = SND_SOC_BIAS_ON;
1373 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1375 case SND_SOC_DAPM_STREAM_SUSPEND:
1376 dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
1378 case SND_SOC_DAPM_STREAM_NOP:
1379 dapm->target_bias_level = dapm->bias_level;
1386 /* Force all contexts in the card to the same bias state if
1387 * they're not ground referenced.
1389 bias = SND_SOC_BIAS_OFF;
1390 list_for_each_entry(d, &card->dapm_list, list)
1391 if (d->target_bias_level > bias)
1392 bias = d->target_bias_level;
1393 list_for_each_entry(d, &card->dapm_list, list)
1394 if (!d->idle_bias_off)
1395 d->target_bias_level = bias;
1397 trace_snd_soc_dapm_walk_done(card);
1399 /* Run all the bias changes in parallel */
1400 list_for_each_entry(d, &dapm->card->dapm_list, list)
1401 async_schedule_domain(dapm_pre_sequence_async, d,
1403 async_synchronize_full_domain(&async_domain);
1405 /* Power down widgets first; try to avoid amplifying pops. */
1406 dapm_seq_run(dapm, &down_list, event, false);
1408 dapm_widget_update(dapm);
1411 dapm_seq_run(dapm, &up_list, event, true);
1413 /* Run all the bias changes in parallel */
1414 list_for_each_entry(d, &dapm->card->dapm_list, list)
1415 async_schedule_domain(dapm_post_sequence_async, d,
1417 async_synchronize_full_domain(&async_domain);
1419 pop_dbg(dapm->dev, card->pop_time,
1420 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1421 pop_wait(card->pop_time);
1423 trace_snd_soc_dapm_done(card);
1428 #ifdef CONFIG_DEBUG_FS
1429 static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1431 file->private_data = inode->i_private;
1435 static ssize_t dapm_widget_power_read_file(struct file *file,
1436 char __user *user_buf,
1437 size_t count, loff_t *ppos)
1439 struct snd_soc_dapm_widget *w = file->private_data;
1443 struct snd_soc_dapm_path *p = NULL;
1445 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1449 in = is_connected_input_ep(w);
1450 dapm_clear_walk(w->dapm);
1451 out = is_connected_output_ep(w);
1452 dapm_clear_walk(w->dapm);
1454 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
1455 w->name, w->power ? "On" : "Off", in, out);
1458 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1459 " - R%d(0x%x) bit %d",
1460 w->reg, w->reg, w->shift);
1462 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1465 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1467 w->active ? "active" : "inactive");
1469 list_for_each_entry(p, &w->sources, list_sink) {
1470 if (p->connected && !p->connected(w, p->sink))
1474 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1475 " in \"%s\" \"%s\"\n",
1476 p->name ? p->name : "static",
1479 list_for_each_entry(p, &w->sinks, list_source) {
1480 if (p->connected && !p->connected(w, p->sink))
1484 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1485 " out \"%s\" \"%s\"\n",
1486 p->name ? p->name : "static",
1490 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1496 static const struct file_operations dapm_widget_power_fops = {
1497 .open = dapm_widget_power_open_file,
1498 .read = dapm_widget_power_read_file,
1499 .llseek = default_llseek,
1502 static int dapm_bias_open_file(struct inode *inode, struct file *file)
1504 file->private_data = inode->i_private;
1508 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1509 size_t count, loff_t *ppos)
1511 struct snd_soc_dapm_context *dapm = file->private_data;
1514 switch (dapm->bias_level) {
1515 case SND_SOC_BIAS_ON:
1518 case SND_SOC_BIAS_PREPARE:
1519 level = "Prepare\n";
1521 case SND_SOC_BIAS_STANDBY:
1522 level = "Standby\n";
1524 case SND_SOC_BIAS_OFF:
1529 level = "Unknown\n";
1533 return simple_read_from_buffer(user_buf, count, ppos, level,
1537 static const struct file_operations dapm_bias_fops = {
1538 .open = dapm_bias_open_file,
1539 .read = dapm_bias_read_file,
1540 .llseek = default_llseek,
1543 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1544 struct dentry *parent)
1548 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1550 if (!dapm->debugfs_dapm) {
1552 "Failed to create DAPM debugfs directory\n");
1556 d = debugfs_create_file("bias_level", 0444,
1557 dapm->debugfs_dapm, dapm,
1561 "ASoC: Failed to create bias level debugfs file\n");
1564 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1566 struct snd_soc_dapm_context *dapm = w->dapm;
1569 if (!dapm->debugfs_dapm || !w->name)
1572 d = debugfs_create_file(w->name, 0444,
1573 dapm->debugfs_dapm, w,
1574 &dapm_widget_power_fops);
1576 dev_warn(w->dapm->dev,
1577 "ASoC: Failed to create %s debugfs file\n",
1581 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1583 debugfs_remove_recursive(dapm->debugfs_dapm);
1587 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1588 struct dentry *parent)
1592 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1596 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1602 /* test and update the power status of a mux widget */
1603 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1604 struct snd_kcontrol *kcontrol, int change,
1605 int mux, struct soc_enum *e)
1607 struct snd_soc_dapm_path *path;
1610 if (widget->id != snd_soc_dapm_mux &&
1611 widget->id != snd_soc_dapm_virt_mux &&
1612 widget->id != snd_soc_dapm_value_mux)
1618 /* find dapm widget path assoc with kcontrol */
1619 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1620 if (path->kcontrol != kcontrol)
1623 if (!path->name || !e->texts[mux])
1627 /* we now need to match the string in the enum to the path */
1628 if (!(strcmp(path->name, e->texts[mux]))) {
1629 path->connect = 1; /* new connection */
1630 dapm_mark_dirty(path->source, "mux connection");
1633 dapm_mark_dirty(path->source,
1634 "mux disconnection");
1635 path->connect = 0; /* old connection must be powered down */
1640 dapm_mark_dirty(widget, "mux change");
1641 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1647 /* test and update the power status of a mixer or switch widget */
1648 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1649 struct snd_kcontrol *kcontrol, int connect)
1651 struct snd_soc_dapm_path *path;
1654 if (widget->id != snd_soc_dapm_mixer &&
1655 widget->id != snd_soc_dapm_mixer_named_ctl &&
1656 widget->id != snd_soc_dapm_switch)
1659 /* find dapm widget path assoc with kcontrol */
1660 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1661 if (path->kcontrol != kcontrol)
1664 /* found, now check type */
1666 path->connect = connect;
1667 dapm_mark_dirty(path->source, "mixer connection");
1671 dapm_mark_dirty(widget, "mixer update");
1672 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1678 /* show dapm widget status in sys fs */
1679 static ssize_t dapm_widget_show(struct device *dev,
1680 struct device_attribute *attr, char *buf)
1682 struct snd_soc_pcm_runtime *rtd =
1683 container_of(dev, struct snd_soc_pcm_runtime, dev);
1684 struct snd_soc_codec *codec =rtd->codec;
1685 struct snd_soc_dapm_widget *w;
1687 char *state = "not set";
1689 list_for_each_entry(w, &codec->card->widgets, list) {
1690 if (w->dapm != &codec->dapm)
1693 /* only display widgets that burnm power */
1695 case snd_soc_dapm_hp:
1696 case snd_soc_dapm_mic:
1697 case snd_soc_dapm_spk:
1698 case snd_soc_dapm_line:
1699 case snd_soc_dapm_micbias:
1700 case snd_soc_dapm_dac:
1701 case snd_soc_dapm_adc:
1702 case snd_soc_dapm_pga:
1703 case snd_soc_dapm_out_drv:
1704 case snd_soc_dapm_mixer:
1705 case snd_soc_dapm_mixer_named_ctl:
1706 case snd_soc_dapm_supply:
1708 count += sprintf(buf + count, "%s: %s\n",
1709 w->name, w->power ? "On":"Off");
1716 switch (codec->dapm.bias_level) {
1717 case SND_SOC_BIAS_ON:
1720 case SND_SOC_BIAS_PREPARE:
1723 case SND_SOC_BIAS_STANDBY:
1726 case SND_SOC_BIAS_OFF:
1730 count += sprintf(buf + count, "PM State: %s\n", state);
1735 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1737 int snd_soc_dapm_sys_add(struct device *dev)
1739 return device_create_file(dev, &dev_attr_dapm_widget);
1742 static void snd_soc_dapm_sys_remove(struct device *dev)
1744 device_remove_file(dev, &dev_attr_dapm_widget);
1747 /* free all dapm widgets and resources */
1748 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1750 struct snd_soc_dapm_widget *w, *next_w;
1751 struct snd_soc_dapm_path *p, *next_p;
1753 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1754 if (w->dapm != dapm)
1758 * remove source and sink paths associated to this widget.
1759 * While removing the path, remove reference to it from both
1760 * source and sink widgets so that path is removed only once.
1762 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1763 list_del(&p->list_sink);
1764 list_del(&p->list_source);
1766 kfree(p->long_name);
1769 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1770 list_del(&p->list_sink);
1771 list_del(&p->list_source);
1773 kfree(p->long_name);
1776 kfree(w->kcontrols);
1782 static struct snd_soc_dapm_widget *dapm_find_widget(
1783 struct snd_soc_dapm_context *dapm, const char *pin,
1784 bool search_other_contexts)
1786 struct snd_soc_dapm_widget *w;
1787 struct snd_soc_dapm_widget *fallback = NULL;
1789 list_for_each_entry(w, &dapm->card->widgets, list) {
1790 if (!strcmp(w->name, pin)) {
1791 if (w->dapm == dapm)
1798 if (search_other_contexts)
1804 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1805 const char *pin, int status)
1807 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
1810 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1814 w->connected = status;
1817 dapm_mark_dirty(w, "pin configuration");
1823 * snd_soc_dapm_sync - scan and power dapm paths
1824 * @dapm: DAPM context
1826 * Walks all dapm audio paths and powers widgets according to their
1827 * stream or path usage.
1829 * Returns 0 for success.
1831 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1833 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1835 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1837 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1838 const struct snd_soc_dapm_route *route)
1840 struct snd_soc_dapm_path *path;
1841 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1842 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1844 const char *control = route->control;
1846 char prefixed_sink[80];
1847 char prefixed_source[80];
1850 if (dapm->codec && dapm->codec->name_prefix) {
1851 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1852 dapm->codec->name_prefix, route->sink);
1853 sink = prefixed_sink;
1854 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1855 dapm->codec->name_prefix, route->source);
1856 source = prefixed_source;
1859 source = route->source;
1863 * find src and dest widgets over all widgets but favor a widget from
1864 * current DAPM context
1866 list_for_each_entry(w, &dapm->card->widgets, list) {
1867 if (!wsink && !(strcmp(w->name, sink))) {
1869 if (w->dapm == dapm)
1873 if (!wsource && !(strcmp(w->name, source))) {
1875 if (w->dapm == dapm)
1879 /* use widget from another DAPM context if not found from this */
1885 if (wsource == NULL || wsink == NULL)
1888 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1892 path->source = wsource;
1894 path->connected = route->connected;
1895 INIT_LIST_HEAD(&path->list);
1896 INIT_LIST_HEAD(&path->list_source);
1897 INIT_LIST_HEAD(&path->list_sink);
1899 /* check for external widgets */
1900 if (wsink->id == snd_soc_dapm_input) {
1901 if (wsource->id == snd_soc_dapm_micbias ||
1902 wsource->id == snd_soc_dapm_mic ||
1903 wsource->id == snd_soc_dapm_line ||
1904 wsource->id == snd_soc_dapm_output)
1907 if (wsource->id == snd_soc_dapm_output) {
1908 if (wsink->id == snd_soc_dapm_spk ||
1909 wsink->id == snd_soc_dapm_hp ||
1910 wsink->id == snd_soc_dapm_line ||
1911 wsink->id == snd_soc_dapm_input)
1915 /* connect static paths */
1916 if (control == NULL) {
1917 list_add(&path->list, &dapm->card->paths);
1918 list_add(&path->list_sink, &wsink->sources);
1919 list_add(&path->list_source, &wsource->sinks);
1924 /* connect dynamic paths */
1925 switch (wsink->id) {
1926 case snd_soc_dapm_adc:
1927 case snd_soc_dapm_dac:
1928 case snd_soc_dapm_pga:
1929 case snd_soc_dapm_out_drv:
1930 case snd_soc_dapm_input:
1931 case snd_soc_dapm_output:
1932 case snd_soc_dapm_micbias:
1933 case snd_soc_dapm_vmid:
1934 case snd_soc_dapm_pre:
1935 case snd_soc_dapm_post:
1936 case snd_soc_dapm_supply:
1937 case snd_soc_dapm_aif_in:
1938 case snd_soc_dapm_aif_out:
1939 list_add(&path->list, &dapm->card->paths);
1940 list_add(&path->list_sink, &wsink->sources);
1941 list_add(&path->list_source, &wsource->sinks);
1944 case snd_soc_dapm_mux:
1945 case snd_soc_dapm_virt_mux:
1946 case snd_soc_dapm_value_mux:
1947 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1948 &wsink->kcontrol_news[0]);
1952 case snd_soc_dapm_switch:
1953 case snd_soc_dapm_mixer:
1954 case snd_soc_dapm_mixer_named_ctl:
1955 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
1959 case snd_soc_dapm_hp:
1960 case snd_soc_dapm_mic:
1961 case snd_soc_dapm_line:
1962 case snd_soc_dapm_spk:
1963 list_add(&path->list, &dapm->card->paths);
1964 list_add(&path->list_sink, &wsink->sources);
1965 list_add(&path->list_source, &wsource->sinks);
1972 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
1973 source, control, sink);
1979 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1980 * @dapm: DAPM context
1981 * @route: audio routes
1982 * @num: number of routes
1984 * Connects 2 dapm widgets together via a named audio path. The sink is
1985 * the widget receiving the audio signal, whilst the source is the sender
1986 * of the audio signal.
1988 * Returns 0 for success else error. On error all resources can be freed
1989 * with a call to snd_soc_card_free().
1991 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1992 const struct snd_soc_dapm_route *route, int num)
1996 for (i = 0; i < num; i++) {
1997 ret = snd_soc_dapm_add_route(dapm, route);
1999 dev_err(dapm->dev, "Failed to add route %s->%s\n",
2000 route->source, route->sink);
2008 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2010 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2011 const struct snd_soc_dapm_route *route)
2013 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2016 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2019 struct snd_soc_dapm_path *path;
2023 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
2029 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
2034 if (route->control || route->connected)
2035 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
2036 route->source, route->sink);
2038 list_for_each_entry(path, &source->sinks, list_source) {
2039 if (path->sink == sink) {
2046 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
2047 route->source, route->sink);
2049 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
2050 count, route->source, route->sink);
2056 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2057 * @dapm: DAPM context
2058 * @route: audio routes
2059 * @num: number of routes
2061 * Mark existing routes matching those specified in the passed array
2062 * as being weak, meaning that they are ignored for the purpose of
2063 * power decisions. The main intended use case is for sidetone paths
2064 * which couple audio between other independent paths if they are both
2065 * active in order to make the combination work better at the user
2066 * level but which aren't intended to be "used".
2068 * Note that CODEC drivers should not use this as sidetone type paths
2069 * can frequently also be used as bypass paths.
2071 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2072 const struct snd_soc_dapm_route *route, int num)
2077 for (i = 0; i < num; i++) {
2078 err = snd_soc_dapm_weak_route(dapm, route);
2086 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2089 * snd_soc_dapm_new_widgets - add new dapm widgets
2090 * @dapm: DAPM context
2092 * Checks the codec for any new dapm widgets and creates them if found.
2094 * Returns 0 for success.
2096 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2098 struct snd_soc_dapm_widget *w;
2101 list_for_each_entry(w, &dapm->card->widgets, list)
2106 if (w->num_kcontrols) {
2107 w->kcontrols = kzalloc(w->num_kcontrols *
2108 sizeof(struct snd_kcontrol *),
2115 case snd_soc_dapm_switch:
2116 case snd_soc_dapm_mixer:
2117 case snd_soc_dapm_mixer_named_ctl:
2118 w->power_check = dapm_generic_check_power;
2121 case snd_soc_dapm_mux:
2122 case snd_soc_dapm_virt_mux:
2123 case snd_soc_dapm_value_mux:
2124 w->power_check = dapm_generic_check_power;
2127 case snd_soc_dapm_adc:
2128 case snd_soc_dapm_aif_out:
2129 w->power_check = dapm_adc_check_power;
2131 case snd_soc_dapm_dac:
2132 case snd_soc_dapm_aif_in:
2133 w->power_check = dapm_dac_check_power;
2135 case snd_soc_dapm_pga:
2136 case snd_soc_dapm_out_drv:
2137 w->power_check = dapm_generic_check_power;
2140 case snd_soc_dapm_input:
2141 case snd_soc_dapm_output:
2142 case snd_soc_dapm_micbias:
2143 case snd_soc_dapm_spk:
2144 case snd_soc_dapm_hp:
2145 case snd_soc_dapm_mic:
2146 case snd_soc_dapm_line:
2147 w->power_check = dapm_generic_check_power;
2149 case snd_soc_dapm_supply:
2150 w->power_check = dapm_supply_check_power;
2151 case snd_soc_dapm_vmid:
2152 case snd_soc_dapm_pre:
2153 case snd_soc_dapm_post:
2157 if (!w->power_check)
2158 w->power_check = dapm_always_on_check_power;
2160 /* Read the initial power state from the device */
2162 val = soc_widget_read(w, w->reg);
2163 val &= 1 << w->shift;
2173 list_add(&w->dirty, &(w->dapm->card->dapm_dirty));
2174 dapm_debugfs_add_widget(w);
2177 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2180 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2183 * snd_soc_dapm_get_volsw - dapm mixer get callback
2184 * @kcontrol: mixer control
2185 * @ucontrol: control element information
2187 * Callback to get the value of a dapm mixer control.
2189 * Returns 0 for success.
2191 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2192 struct snd_ctl_elem_value *ucontrol)
2194 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2195 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2196 struct soc_mixer_control *mc =
2197 (struct soc_mixer_control *)kcontrol->private_value;
2198 unsigned int reg = mc->reg;
2199 unsigned int shift = mc->shift;
2200 unsigned int rshift = mc->rshift;
2202 unsigned int invert = mc->invert;
2203 unsigned int mask = (1 << fls(max)) - 1;
2205 ucontrol->value.integer.value[0] =
2206 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2207 if (shift != rshift)
2208 ucontrol->value.integer.value[1] =
2209 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2211 ucontrol->value.integer.value[0] =
2212 max - ucontrol->value.integer.value[0];
2213 if (shift != rshift)
2214 ucontrol->value.integer.value[1] =
2215 max - ucontrol->value.integer.value[1];
2220 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2223 * snd_soc_dapm_put_volsw - dapm mixer set callback
2224 * @kcontrol: mixer control
2225 * @ucontrol: control element information
2227 * Callback to set the value of a dapm mixer control.
2229 * Returns 0 for success.
2231 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2232 struct snd_ctl_elem_value *ucontrol)
2234 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2235 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2236 struct snd_soc_codec *codec = widget->codec;
2237 struct soc_mixer_control *mc =
2238 (struct soc_mixer_control *)kcontrol->private_value;
2239 unsigned int reg = mc->reg;
2240 unsigned int shift = mc->shift;
2242 unsigned int mask = (1 << fls(max)) - 1;
2243 unsigned int invert = mc->invert;
2245 int connect, change;
2246 struct snd_soc_dapm_update update;
2249 val = (ucontrol->value.integer.value[0] & mask);
2253 mask = mask << shift;
2257 /* new connection */
2258 connect = invert ? 0 : 1;
2260 /* old connection must be powered down */
2261 connect = invert ? 1 : 0;
2263 mutex_lock(&codec->mutex);
2265 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2267 for (wi = 0; wi < wlist->num_widgets; wi++) {
2268 widget = wlist->widgets[wi];
2270 widget->value = val;
2272 update.kcontrol = kcontrol;
2273 update.widget = widget;
2277 widget->dapm->update = &update;
2279 dapm_mixer_update_power(widget, kcontrol, connect);
2281 widget->dapm->update = NULL;
2285 mutex_unlock(&codec->mutex);
2288 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2291 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2292 * @kcontrol: mixer control
2293 * @ucontrol: control element information
2295 * Callback to get the value of a dapm enumerated double mixer control.
2297 * Returns 0 for success.
2299 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2300 struct snd_ctl_elem_value *ucontrol)
2302 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2303 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2304 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2305 unsigned int val, bitmask;
2307 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2309 val = snd_soc_read(widget->codec, e->reg);
2310 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2311 if (e->shift_l != e->shift_r)
2312 ucontrol->value.enumerated.item[1] =
2313 (val >> e->shift_r) & (bitmask - 1);
2317 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2320 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2321 * @kcontrol: mixer control
2322 * @ucontrol: control element information
2324 * Callback to set the value of a dapm enumerated double mixer control.
2326 * Returns 0 for success.
2328 int snd_soc_dapm_put_enum_double(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 = (struct soc_enum *)kcontrol->private_value;
2335 unsigned int val, mux, change;
2336 unsigned int mask, bitmask;
2337 struct snd_soc_dapm_update update;
2340 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2342 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2344 mux = ucontrol->value.enumerated.item[0];
2345 val = mux << e->shift_l;
2346 mask = (bitmask - 1) << e->shift_l;
2347 if (e->shift_l != e->shift_r) {
2348 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2350 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2351 mask |= (bitmask - 1) << e->shift_r;
2354 mutex_lock(&codec->mutex);
2356 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2358 for (wi = 0; wi < wlist->num_widgets; wi++) {
2359 widget = wlist->widgets[wi];
2361 widget->value = val;
2363 update.kcontrol = kcontrol;
2364 update.widget = widget;
2365 update.reg = e->reg;
2368 widget->dapm->update = &update;
2370 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2372 widget->dapm->update = NULL;
2376 mutex_unlock(&codec->mutex);
2379 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2382 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2383 * @kcontrol: mixer control
2384 * @ucontrol: control element information
2386 * Returns 0 for success.
2388 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2389 struct snd_ctl_elem_value *ucontrol)
2391 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2392 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2394 ucontrol->value.enumerated.item[0] = widget->value;
2398 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2401 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2402 * @kcontrol: mixer control
2403 * @ucontrol: control element information
2405 * Returns 0 for success.
2407 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2408 struct snd_ctl_elem_value *ucontrol)
2410 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2411 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2412 struct snd_soc_codec *codec = widget->codec;
2413 struct soc_enum *e =
2414 (struct soc_enum *)kcontrol->private_value;
2419 if (ucontrol->value.enumerated.item[0] >= e->max)
2422 mutex_lock(&codec->mutex);
2424 change = widget->value != ucontrol->value.enumerated.item[0];
2426 for (wi = 0; wi < wlist->num_widgets; wi++) {
2427 widget = wlist->widgets[wi];
2429 widget->value = ucontrol->value.enumerated.item[0];
2431 dapm_mux_update_power(widget, kcontrol, change,
2436 mutex_unlock(&codec->mutex);
2439 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2442 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2444 * @kcontrol: mixer control
2445 * @ucontrol: control element information
2447 * Callback to get the value of a dapm semi enumerated double mixer control.
2449 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2450 * used for handling bitfield coded enumeration for example.
2452 * Returns 0 for success.
2454 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2455 struct snd_ctl_elem_value *ucontrol)
2457 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2458 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2459 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2460 unsigned int reg_val, val, mux;
2462 reg_val = snd_soc_read(widget->codec, e->reg);
2463 val = (reg_val >> e->shift_l) & e->mask;
2464 for (mux = 0; mux < e->max; mux++) {
2465 if (val == e->values[mux])
2468 ucontrol->value.enumerated.item[0] = mux;
2469 if (e->shift_l != e->shift_r) {
2470 val = (reg_val >> e->shift_r) & e->mask;
2471 for (mux = 0; mux < e->max; mux++) {
2472 if (val == e->values[mux])
2475 ucontrol->value.enumerated.item[1] = mux;
2480 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2483 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2485 * @kcontrol: mixer control
2486 * @ucontrol: control element information
2488 * Callback to set the value of a dapm semi enumerated double mixer control.
2490 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2491 * used for handling bitfield coded enumeration for example.
2493 * Returns 0 for success.
2495 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2496 struct snd_ctl_elem_value *ucontrol)
2498 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2499 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2500 struct snd_soc_codec *codec = widget->codec;
2501 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2502 unsigned int val, mux, change;
2504 struct snd_soc_dapm_update update;
2507 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2509 mux = ucontrol->value.enumerated.item[0];
2510 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2511 mask = e->mask << e->shift_l;
2512 if (e->shift_l != e->shift_r) {
2513 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2515 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2516 mask |= e->mask << e->shift_r;
2519 mutex_lock(&codec->mutex);
2521 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2523 for (wi = 0; wi < wlist->num_widgets; wi++) {
2524 widget = wlist->widgets[wi];
2526 widget->value = val;
2528 update.kcontrol = kcontrol;
2529 update.widget = widget;
2530 update.reg = e->reg;
2533 widget->dapm->update = &update;
2535 dapm_mux_update_power(widget, kcontrol, change, mux, e);
2537 widget->dapm->update = NULL;
2541 mutex_unlock(&codec->mutex);
2544 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2547 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2549 * @kcontrol: mixer control
2550 * @uinfo: control element information
2552 * Callback to provide information about a pin switch control.
2554 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_info *uinfo)
2557 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2559 uinfo->value.integer.min = 0;
2560 uinfo->value.integer.max = 1;
2564 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2567 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2569 * @kcontrol: mixer control
2572 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2573 struct snd_ctl_elem_value *ucontrol)
2575 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2576 const char *pin = (const char *)kcontrol->private_value;
2578 mutex_lock(&codec->mutex);
2580 ucontrol->value.integer.value[0] =
2581 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
2583 mutex_unlock(&codec->mutex);
2587 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2590 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2592 * @kcontrol: mixer control
2595 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2596 struct snd_ctl_elem_value *ucontrol)
2598 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2599 const char *pin = (const char *)kcontrol->private_value;
2601 mutex_lock(&codec->mutex);
2603 if (ucontrol->value.integer.value[0])
2604 snd_soc_dapm_enable_pin(&codec->dapm, pin);
2606 snd_soc_dapm_disable_pin(&codec->dapm, pin);
2608 snd_soc_dapm_sync(&codec->dapm);
2610 mutex_unlock(&codec->mutex);
2614 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2617 * snd_soc_dapm_new_control - create new dapm control
2618 * @dapm: DAPM context
2619 * @widget: widget template
2621 * Creates a new dapm control based upon the template.
2623 * Returns 0 for success else error.
2625 int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2626 const struct snd_soc_dapm_widget *widget)
2628 struct snd_soc_dapm_widget *w;
2631 if ((w = dapm_cnew_widget(widget)) == NULL)
2634 name_len = strlen(widget->name) + 1;
2635 if (dapm->codec && dapm->codec->name_prefix)
2636 name_len += 1 + strlen(dapm->codec->name_prefix);
2637 w->name = kmalloc(name_len, GFP_KERNEL);
2638 if (w->name == NULL) {
2642 if (dapm->codec && dapm->codec->name_prefix)
2643 snprintf(w->name, name_len, "%s %s",
2644 dapm->codec->name_prefix, widget->name);
2646 snprintf(w->name, name_len, "%s", widget->name);
2650 w->codec = dapm->codec;
2651 w->platform = dapm->platform;
2652 INIT_LIST_HEAD(&w->sources);
2653 INIT_LIST_HEAD(&w->sinks);
2654 INIT_LIST_HEAD(&w->list);
2655 INIT_LIST_HEAD(&w->dirty);
2656 list_add(&w->list, &dapm->card->widgets);
2658 /* machine layer set ups unconnected pins and insertions */
2662 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
2665 * snd_soc_dapm_new_controls - create new dapm controls
2666 * @dapm: DAPM context
2667 * @widget: widget array
2668 * @num: number of widgets
2670 * Creates new DAPM controls based upon the templates.
2672 * Returns 0 for success else error.
2674 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2675 const struct snd_soc_dapm_widget *widget,
2680 for (i = 0; i < num; i++) {
2681 ret = snd_soc_dapm_new_control(dapm, widget);
2684 "ASoC: Failed to create DAPM control %s: %d\n",
2692 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2694 static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2695 const char *stream, int event)
2697 struct snd_soc_dapm_widget *w;
2699 list_for_each_entry(w, &dapm->card->widgets, list)
2701 if (!w->sname || w->dapm != dapm)
2703 dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2704 w->name, w->sname, stream, event);
2705 if (strstr(w->sname, stream)) {
2706 dapm_mark_dirty(w, "stream event");
2708 case SND_SOC_DAPM_STREAM_START:
2711 case SND_SOC_DAPM_STREAM_STOP:
2714 case SND_SOC_DAPM_STREAM_SUSPEND:
2715 case SND_SOC_DAPM_STREAM_RESUME:
2716 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
2717 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2723 dapm_power_widgets(dapm, event);
2725 /* do we need to notify any clients that DAPM stream is complete */
2726 if (dapm->stream_event)
2727 dapm->stream_event(dapm, event);
2731 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2732 * @rtd: PCM runtime data
2733 * @stream: stream name
2734 * @event: stream event
2736 * Sends a stream event to the dapm core. The core then makes any
2737 * necessary widget power changes.
2739 * Returns 0 for success else error.
2741 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2742 const char *stream, int event)
2744 struct snd_soc_codec *codec = rtd->codec;
2749 mutex_lock(&codec->mutex);
2750 soc_dapm_stream_event(&codec->dapm, stream, event);
2751 mutex_unlock(&codec->mutex);
2756 * snd_soc_dapm_enable_pin - enable pin.
2757 * @dapm: DAPM context
2760 * Enables input/output pin and its parents or children widgets iff there is
2761 * a valid audio route and active audio stream.
2762 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2763 * do any widget power switching.
2765 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2767 return snd_soc_dapm_set_pin(dapm, pin, 1);
2769 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2772 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2773 * @dapm: DAPM context
2776 * Enables input/output pin regardless of any other state. This is
2777 * intended for use with microphone bias supplies used in microphone
2780 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2781 * do any widget power switching.
2783 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2786 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2789 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2793 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
2796 dapm_mark_dirty(w, "force enable");
2800 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2803 * snd_soc_dapm_disable_pin - disable pin.
2804 * @dapm: DAPM context
2807 * Disables input/output pin and its parents or children widgets.
2808 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2809 * do any widget power switching.
2811 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2814 return snd_soc_dapm_set_pin(dapm, pin, 0);
2816 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2819 * snd_soc_dapm_nc_pin - permanently disable pin.
2820 * @dapm: DAPM context
2823 * Marks the specified pin as being not connected, disabling it along
2824 * any parent or child widgets. At present this is identical to
2825 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2826 * additional things such as disabling controls which only affect
2827 * paths through the pin.
2829 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2830 * do any widget power switching.
2832 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2834 return snd_soc_dapm_set_pin(dapm, pin, 0);
2836 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2839 * snd_soc_dapm_get_pin_status - get audio pin status
2840 * @dapm: DAPM context
2841 * @pin: audio signal pin endpoint (or start point)
2843 * Get audio pin status - connected or disconnected.
2845 * Returns 1 for connected otherwise 0.
2847 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2850 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2853 return w->connected;
2857 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2860 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2861 * @dapm: DAPM context
2862 * @pin: audio signal pin endpoint (or start point)
2864 * Mark the given endpoint or pin as ignoring suspend. When the
2865 * system is disabled a path between two endpoints flagged as ignoring
2866 * suspend will not be disabled. The path must already be enabled via
2867 * normal means at suspend time, it will not be turned on if it was not
2870 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2873 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
2876 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2880 w->ignore_suspend = 1;
2884 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2887 * snd_soc_dapm_free - free dapm resources
2888 * @dapm: DAPM context
2890 * Free all dapm widgets and resources.
2892 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2894 snd_soc_dapm_sys_remove(dapm->dev);
2895 dapm_debugfs_cleanup(dapm);
2896 dapm_free_widgets(dapm);
2897 list_del(&dapm->list);
2899 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2901 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2903 struct snd_soc_dapm_widget *w;
2904 LIST_HEAD(down_list);
2907 list_for_each_entry(w, &dapm->card->widgets, list) {
2908 if (w->dapm != dapm)
2911 dapm_seq_insert(w, &down_list, false);
2917 /* If there were no widgets to power down we're already in
2921 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
2922 dapm_seq_run(dapm, &down_list, 0, false);
2923 snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
2928 * snd_soc_dapm_shutdown - callback for system shutdown
2930 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2932 struct snd_soc_codec *codec;
2934 list_for_each_entry(codec, &card->codec_dev_list, list) {
2935 soc_dapm_shutdown_codec(&codec->dapm);
2936 snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
2940 /* Module information */
2941 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2942 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2943 MODULE_LICENSE("GPL");