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/headphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
21 * o Delayed power down of audio subsystem to reduce pops between a quick
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/init.h>
29 #include <linux/async.h>
30 #include <linux/delay.h>
32 #include <linux/bitops.h>
33 #include <linux/platform_device.h>
34 #include <linux/jiffies.h>
35 #include <linux/debugfs.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/regulator/consumer.h>
38 #include <linux/slab.h>
39 #include <sound/core.h>
40 #include <sound/pcm.h>
41 #include <sound/pcm_params.h>
42 #include <sound/soc.h>
43 #include <sound/initval.h>
45 #include <trace/events/asoc.h>
47 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
49 /* dapm power sequences - make this per codec in the future */
50 static int dapm_up_seq[] = {
51 [snd_soc_dapm_pre] = 0,
52 [snd_soc_dapm_supply] = 1,
53 [snd_soc_dapm_regulator_supply] = 1,
54 [snd_soc_dapm_micbias] = 2,
55 [snd_soc_dapm_dai_link] = 2,
56 [snd_soc_dapm_dai] = 3,
57 [snd_soc_dapm_aif_in] = 3,
58 [snd_soc_dapm_aif_out] = 3,
59 [snd_soc_dapm_mic] = 4,
60 [snd_soc_dapm_mux] = 5,
61 [snd_soc_dapm_virt_mux] = 5,
62 [snd_soc_dapm_value_mux] = 5,
63 [snd_soc_dapm_dac] = 6,
64 [snd_soc_dapm_mixer] = 7,
65 [snd_soc_dapm_mixer_named_ctl] = 7,
66 [snd_soc_dapm_pga] = 8,
67 [snd_soc_dapm_adc] = 9,
68 [snd_soc_dapm_out_drv] = 10,
69 [snd_soc_dapm_hp] = 10,
70 [snd_soc_dapm_spk] = 10,
71 [snd_soc_dapm_post] = 11,
74 static int dapm_down_seq[] = {
75 [snd_soc_dapm_pre] = 0,
76 [snd_soc_dapm_adc] = 1,
77 [snd_soc_dapm_hp] = 2,
78 [snd_soc_dapm_spk] = 2,
79 [snd_soc_dapm_out_drv] = 2,
80 [snd_soc_dapm_pga] = 4,
81 [snd_soc_dapm_mixer_named_ctl] = 5,
82 [snd_soc_dapm_mixer] = 5,
83 [snd_soc_dapm_dac] = 6,
84 [snd_soc_dapm_mic] = 7,
85 [snd_soc_dapm_micbias] = 8,
86 [snd_soc_dapm_mux] = 9,
87 [snd_soc_dapm_virt_mux] = 9,
88 [snd_soc_dapm_value_mux] = 9,
89 [snd_soc_dapm_aif_in] = 10,
90 [snd_soc_dapm_aif_out] = 10,
91 [snd_soc_dapm_dai] = 10,
92 [snd_soc_dapm_dai_link] = 11,
93 [snd_soc_dapm_regulator_supply] = 12,
94 [snd_soc_dapm_supply] = 12,
95 [snd_soc_dapm_post] = 13,
98 static void pop_wait(u32 pop_time)
101 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
104 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
112 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
117 vsnprintf(buf, PAGE_SIZE, fmt, args);
118 dev_info(dev, "%s", buf);
124 static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
126 return !list_empty(&w->dirty);
129 void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
131 if (!dapm_dirty_widget(w)) {
132 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
134 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
137 EXPORT_SYMBOL_GPL(dapm_mark_dirty);
139 /* create a new dapm widget */
140 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
141 const struct snd_soc_dapm_widget *_widget)
143 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
146 /* get snd_card from DAPM context */
147 static inline struct snd_card *dapm_get_snd_card(
148 struct snd_soc_dapm_context *dapm)
151 return dapm->codec->card->snd_card;
152 else if (dapm->platform)
153 return dapm->platform->card->snd_card;
161 /* get soc_card from DAPM context */
162 static inline struct snd_soc_card *dapm_get_soc_card(
163 struct snd_soc_dapm_context *dapm)
166 return dapm->codec->card;
167 else if (dapm->platform)
168 return dapm->platform->card;
176 static void dapm_reset(struct snd_soc_card *card)
178 struct snd_soc_dapm_widget *w;
180 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
182 list_for_each_entry(w, &card->widgets, list) {
183 w->power_checked = false;
189 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
192 return snd_soc_read(w->codec, reg);
193 else if (w->platform)
194 return snd_soc_platform_read(w->platform, reg);
196 dev_err(w->dapm->dev, "no valid widget read method\n");
200 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
203 return snd_soc_write(w->codec, reg, val);
204 else if (w->platform)
205 return snd_soc_platform_write(w->platform, reg, val);
207 dev_err(w->dapm->dev, "no valid widget write method\n");
211 static inline void soc_widget_lock(struct snd_soc_dapm_widget *w)
213 if (w->codec && !w->codec->using_regmap)
214 mutex_lock(&w->codec->mutex);
215 else if (w->platform)
216 mutex_lock(&w->platform->mutex);
219 static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w)
221 if (w->codec && !w->codec->using_regmap)
222 mutex_unlock(&w->codec->mutex);
223 else if (w->platform)
224 mutex_unlock(&w->platform->mutex);
227 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
228 unsigned short reg, unsigned int mask, unsigned int value)
231 unsigned int old, new;
234 if (w->codec && w->codec->using_regmap) {
235 ret = regmap_update_bits_check(w->codec->control_data,
236 reg, mask, value, &change);
241 ret = soc_widget_read(w, reg);
243 soc_widget_unlock(w);
248 new = (old & ~mask) | (value & mask);
251 ret = soc_widget_write(w, reg, new);
253 soc_widget_unlock(w);
257 soc_widget_unlock(w);
264 * snd_soc_dapm_set_bias_level - set the bias level for the system
265 * @dapm: DAPM context
266 * @level: level to configure
268 * Configure the bias (power) levels for the SoC audio device.
270 * Returns 0 for success else error.
272 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
273 enum snd_soc_bias_level level)
275 struct snd_soc_card *card = dapm->card;
278 trace_snd_soc_bias_level_start(card, level);
280 if (card && card->set_bias_level)
281 ret = card->set_bias_level(card, dapm, level);
286 if (dapm->codec->driver->set_bias_level)
287 ret = dapm->codec->driver->set_bias_level(dapm->codec,
290 dapm->bias_level = level;
295 if (card && card->set_bias_level_post)
296 ret = card->set_bias_level_post(card, dapm, level);
298 trace_snd_soc_bias_level_done(card, level);
303 /* set up initial codec paths */
304 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
305 struct snd_soc_dapm_path *p, int i)
308 case snd_soc_dapm_switch:
309 case snd_soc_dapm_mixer:
310 case snd_soc_dapm_mixer_named_ctl: {
312 struct soc_mixer_control *mc = (struct soc_mixer_control *)
313 w->kcontrol_news[i].private_value;
314 unsigned int reg = mc->reg;
315 unsigned int shift = mc->shift;
317 unsigned int mask = (1 << fls(max)) - 1;
318 unsigned int invert = mc->invert;
320 val = soc_widget_read(w, reg);
321 val = (val >> shift) & mask;
323 if ((invert && !val) || (!invert && val))
329 case snd_soc_dapm_mux: {
330 struct soc_enum *e = (struct soc_enum *)
331 w->kcontrol_news[i].private_value;
332 int val, item, bitmask;
334 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
336 val = soc_widget_read(w, e->reg);
337 item = (val >> e->shift_l) & (bitmask - 1);
340 for (i = 0; i < e->max; i++) {
341 if (!(strcmp(p->name, e->texts[i])) && item == i)
346 case snd_soc_dapm_virt_mux: {
347 struct soc_enum *e = (struct soc_enum *)
348 w->kcontrol_news[i].private_value;
351 /* since a virtual mux has no backing registers to
352 * decide which path to connect, it will try to match
353 * with the first enumeration. This is to ensure
354 * that the default mux choice (the first) will be
355 * correctly powered up during initialization.
357 if (!strcmp(p->name, e->texts[0]))
361 case snd_soc_dapm_value_mux: {
362 struct soc_enum *e = (struct soc_enum *)
363 w->kcontrol_news[i].private_value;
366 val = soc_widget_read(w, e->reg);
367 val = (val >> e->shift_l) & e->mask;
368 for (item = 0; item < e->max; item++) {
369 if (val == e->values[item])
374 for (i = 0; i < e->max; i++) {
375 if (!(strcmp(p->name, e->texts[i])) && item == i)
380 /* does not affect routing - always connected */
381 case snd_soc_dapm_pga:
382 case snd_soc_dapm_out_drv:
383 case snd_soc_dapm_output:
384 case snd_soc_dapm_adc:
385 case snd_soc_dapm_input:
386 case snd_soc_dapm_siggen:
387 case snd_soc_dapm_dac:
388 case snd_soc_dapm_micbias:
389 case snd_soc_dapm_vmid:
390 case snd_soc_dapm_supply:
391 case snd_soc_dapm_regulator_supply:
392 case snd_soc_dapm_aif_in:
393 case snd_soc_dapm_aif_out:
394 case snd_soc_dapm_dai:
395 case snd_soc_dapm_hp:
396 case snd_soc_dapm_mic:
397 case snd_soc_dapm_spk:
398 case snd_soc_dapm_line:
399 case snd_soc_dapm_dai_link:
402 /* does affect routing - dynamically connected */
403 case snd_soc_dapm_pre:
404 case snd_soc_dapm_post:
410 /* connect mux widget to its interconnecting audio paths */
411 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
412 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
413 struct snd_soc_dapm_path *path, const char *control_name,
414 const struct snd_kcontrol_new *kcontrol)
416 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
419 for (i = 0; i < e->max; i++) {
420 if (!(strcmp(control_name, e->texts[i]))) {
421 list_add(&path->list, &dapm->card->paths);
422 list_add(&path->list_sink, &dest->sources);
423 list_add(&path->list_source, &src->sinks);
424 path->name = (char*)e->texts[i];
425 dapm_set_path_status(dest, path, 0);
433 /* connect mixer widget to its interconnecting audio paths */
434 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
435 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
436 struct snd_soc_dapm_path *path, const char *control_name)
440 /* search for mixer kcontrol */
441 for (i = 0; i < dest->num_kcontrols; i++) {
442 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
443 list_add(&path->list, &dapm->card->paths);
444 list_add(&path->list_sink, &dest->sources);
445 list_add(&path->list_source, &src->sinks);
446 path->name = dest->kcontrol_news[i].name;
447 dapm_set_path_status(dest, path, i);
454 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
455 struct snd_soc_dapm_widget *kcontrolw,
456 const struct snd_kcontrol_new *kcontrol_new,
457 struct snd_kcontrol **kcontrol)
459 struct snd_soc_dapm_widget *w;
464 list_for_each_entry(w, &dapm->card->widgets, list) {
465 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
467 for (i = 0; i < w->num_kcontrols; i++) {
468 if (&w->kcontrol_news[i] == kcontrol_new) {
470 *kcontrol = w->kcontrols[i];
479 /* create new dapm mixer control */
480 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
482 struct snd_soc_dapm_context *dapm = w->dapm;
484 size_t name_len, prefix_len;
485 struct snd_soc_dapm_path *path;
486 struct snd_card *card = dapm->card->snd_card;
488 struct snd_soc_dapm_widget_list *wlist;
492 prefix = dapm->codec->name_prefix;
497 prefix_len = strlen(prefix) + 1;
502 for (i = 0; i < w->num_kcontrols; i++) {
505 list_for_each_entry(path, &w->sources, list_sink) {
507 /* mixer/mux paths name must match control name */
508 if (path->name != (char *)w->kcontrol_news[i].name)
511 if (w->kcontrols[i]) {
512 path->kcontrol = w->kcontrols[i];
516 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
517 sizeof(struct snd_soc_dapm_widget *),
518 wlist = kzalloc(wlistsize, GFP_KERNEL);
521 "asoc: can't allocate widget list for %s\n",
525 wlist->num_widgets = 1;
526 wlist->widgets[0] = w;
528 /* add dapm control with long name.
529 * for dapm_mixer this is the concatenation of the
530 * mixer and kcontrol name.
531 * for dapm_mixer_named_ctl this is simply the
534 name_len = strlen(w->kcontrol_news[i].name) + 1;
535 if (w->id != snd_soc_dapm_mixer_named_ctl)
536 name_len += 1 + strlen(w->name);
538 path->long_name = kmalloc(name_len, GFP_KERNEL);
540 if (path->long_name == NULL) {
547 /* The control will get a prefix from
548 * the control creation process but
549 * we're also using the same prefix
550 * for widgets so cut the prefix off
551 * the front of the widget name.
553 snprintf((char *)path->long_name, name_len,
554 "%s %s", w->name + prefix_len,
555 w->kcontrol_news[i].name);
557 case snd_soc_dapm_mixer_named_ctl:
558 snprintf((char *)path->long_name, name_len,
559 "%s", w->kcontrol_news[i].name);
563 ((char *)path->long_name)[name_len - 1] = '\0';
565 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
566 wlist, path->long_name,
568 ret = snd_ctl_add(card, path->kcontrol);
571 "asoc: failed to add dapm kcontrol %s: %d\n",
572 path->long_name, ret);
574 kfree(path->long_name);
575 path->long_name = NULL;
578 w->kcontrols[i] = path->kcontrol;
584 /* create new dapm mux control */
585 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
587 struct snd_soc_dapm_context *dapm = w->dapm;
588 struct snd_soc_dapm_path *path = NULL;
589 struct snd_kcontrol *kcontrol;
590 struct snd_card *card = dapm->card->snd_card;
594 struct snd_soc_dapm_widget_list *wlist;
595 int shared, wlistentries;
599 if (w->num_kcontrols != 1) {
601 "asoc: mux %s has incorrect number of controls\n",
606 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
609 wlist = kcontrol->private_data;
610 wlistentries = wlist->num_widgets + 1;
615 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
616 wlistentries * sizeof(struct snd_soc_dapm_widget *),
617 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
620 "asoc: can't allocate widget list for %s\n", w->name);
623 wlist->num_widgets = wlistentries;
624 wlist->widgets[wlistentries - 1] = w;
628 prefix = dapm->codec->name_prefix;
633 name = w->kcontrol_news[0].name;
638 prefix_len = strlen(prefix) + 1;
644 * The control will get a prefix from the control creation
645 * process but we're also using the same prefix for widgets so
646 * cut the prefix off the front of the widget name.
648 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
649 name + prefix_len, prefix);
650 ret = snd_ctl_add(card, kcontrol);
652 dev_err(dapm->dev, "failed to add kcontrol %s: %d\n",
659 kcontrol->private_data = wlist;
661 w->kcontrols[0] = kcontrol;
663 list_for_each_entry(path, &w->sources, list_sink)
664 path->kcontrol = kcontrol;
669 /* create new dapm volume control */
670 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
672 if (w->num_kcontrols)
673 dev_err(w->dapm->dev,
674 "asoc: PGA controls not supported: '%s'\n", w->name);
679 /* reset 'walked' bit for each dapm path */
680 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
682 struct snd_soc_dapm_path *p;
684 list_for_each_entry(p, &dapm->card->paths, list)
688 /* We implement power down on suspend by checking the power state of
689 * the ALSA card - when we are suspending the ALSA state for the card
692 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
694 int level = snd_power_get_state(widget->dapm->card->snd_card);
697 case SNDRV_CTL_POWER_D3hot:
698 case SNDRV_CTL_POWER_D3cold:
699 if (widget->ignore_suspend)
700 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
702 return widget->ignore_suspend;
708 /* add widget to list if it's not already in the list */
709 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list,
710 struct snd_soc_dapm_widget *w)
712 struct snd_soc_dapm_widget_list *wlist;
713 int wlistsize, wlistentries, i;
720 /* is this widget already in the list */
721 for (i = 0; i < wlist->num_widgets; i++) {
722 if (wlist->widgets[i] == w)
726 /* allocate some new space */
727 wlistentries = wlist->num_widgets + 1;
728 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
729 wlistentries * sizeof(struct snd_soc_dapm_widget *);
730 *list = krealloc(wlist, wlistsize, GFP_KERNEL);
732 dev_err(w->dapm->dev, "can't allocate widget list for %s\n",
738 /* insert the widget */
739 dev_dbg(w->dapm->dev, "added %s in widget list pos %d\n",
740 w->name, wlist->num_widgets);
742 wlist->widgets[wlist->num_widgets] = w;
743 wlist->num_widgets++;
748 * Recursively check for a completed path to an active or physically connected
749 * output widget. Returns number of complete paths.
751 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
752 struct snd_soc_dapm_widget_list **list)
754 struct snd_soc_dapm_path *path;
757 if (widget->outputs >= 0)
758 return widget->outputs;
760 DAPM_UPDATE_STAT(widget, path_checks);
762 switch (widget->id) {
763 case snd_soc_dapm_supply:
764 case snd_soc_dapm_regulator_supply:
770 switch (widget->id) {
771 case snd_soc_dapm_adc:
772 case snd_soc_dapm_aif_out:
773 case snd_soc_dapm_dai:
774 if (widget->active) {
775 widget->outputs = snd_soc_dapm_suspend_check(widget);
776 return widget->outputs;
782 if (widget->connected) {
783 /* connected pin ? */
784 if (widget->id == snd_soc_dapm_output && !widget->ext) {
785 widget->outputs = snd_soc_dapm_suspend_check(widget);
786 return widget->outputs;
789 /* connected jack or spk ? */
790 if (widget->id == snd_soc_dapm_hp ||
791 widget->id == snd_soc_dapm_spk ||
792 (widget->id == snd_soc_dapm_line &&
793 !list_empty(&widget->sources))) {
794 widget->outputs = snd_soc_dapm_suspend_check(widget);
795 return widget->outputs;
799 list_for_each_entry(path, &widget->sinks, list_source) {
800 DAPM_UPDATE_STAT(widget, neighbour_checks);
808 trace_snd_soc_dapm_output_path(widget, path);
810 if (path->sink && path->connect) {
813 /* do we need to add this widget to the list ? */
816 err = dapm_list_add_widget(list, path->sink);
818 dev_err(widget->dapm->dev, "could not add widget %s\n",
824 con += is_connected_output_ep(path->sink, list);
828 widget->outputs = con;
834 * Recursively check for a completed path to an active or physically connected
835 * input widget. Returns number of complete paths.
837 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
838 struct snd_soc_dapm_widget_list **list)
840 struct snd_soc_dapm_path *path;
843 if (widget->inputs >= 0)
844 return widget->inputs;
846 DAPM_UPDATE_STAT(widget, path_checks);
848 switch (widget->id) {
849 case snd_soc_dapm_supply:
850 case snd_soc_dapm_regulator_supply:
856 /* active stream ? */
857 switch (widget->id) {
858 case snd_soc_dapm_dac:
859 case snd_soc_dapm_aif_in:
860 case snd_soc_dapm_dai:
861 if (widget->active) {
862 widget->inputs = snd_soc_dapm_suspend_check(widget);
863 return widget->inputs;
869 if (widget->connected) {
870 /* connected pin ? */
871 if (widget->id == snd_soc_dapm_input && !widget->ext) {
872 widget->inputs = snd_soc_dapm_suspend_check(widget);
873 return widget->inputs;
876 /* connected VMID/Bias for lower pops */
877 if (widget->id == snd_soc_dapm_vmid) {
878 widget->inputs = snd_soc_dapm_suspend_check(widget);
879 return widget->inputs;
882 /* connected jack ? */
883 if (widget->id == snd_soc_dapm_mic ||
884 (widget->id == snd_soc_dapm_line &&
885 !list_empty(&widget->sinks))) {
886 widget->inputs = snd_soc_dapm_suspend_check(widget);
887 return widget->inputs;
890 /* signal generator */
891 if (widget->id == snd_soc_dapm_siggen) {
892 widget->inputs = snd_soc_dapm_suspend_check(widget);
893 return widget->inputs;
897 list_for_each_entry(path, &widget->sources, list_sink) {
898 DAPM_UPDATE_STAT(widget, neighbour_checks);
906 trace_snd_soc_dapm_input_path(widget, path);
908 if (path->source && path->connect) {
911 /* do we need to add this widget to the list ? */
914 err = dapm_list_add_widget(list, path->sink);
916 dev_err(widget->dapm->dev, "could not add widget %s\n",
922 con += is_connected_input_ep(path->source, list);
926 widget->inputs = con;
932 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
934 * @stream: stream direction.
935 * @list: list of active widgets for this stream.
937 * Queries DAPM graph as to whether an valid audio stream path exists for
938 * the initial stream specified by name. This takes into account
939 * current mixer and mux kcontrol settings. Creates list of valid widgets.
941 * Returns the number of valid paths or negative error.
943 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
944 struct snd_soc_dapm_widget_list **list)
946 struct snd_soc_card *card = dai->card;
949 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
952 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
953 paths = is_connected_output_ep(dai->playback_widget, list);
955 paths = is_connected_input_ep(dai->playback_widget, list);
957 trace_snd_soc_dapm_connected(paths, stream);
958 dapm_clear_walk(&card->dapm);
959 mutex_unlock(&card->dapm_mutex);
965 * Handler for generic register modifier widget.
967 int dapm_reg_event(struct snd_soc_dapm_widget *w,
968 struct snd_kcontrol *kcontrol, int event)
972 if (SND_SOC_DAPM_EVENT_ON(event))
977 soc_widget_update_bits_locked(w, -(w->reg + 1),
978 w->mask << w->shift, val << w->shift);
982 EXPORT_SYMBOL_GPL(dapm_reg_event);
985 * Handler for regulator supply widget.
987 int dapm_regulator_event(struct snd_soc_dapm_widget *w,
988 struct snd_kcontrol *kcontrol, int event)
990 if (SND_SOC_DAPM_EVENT_ON(event))
991 return regulator_enable(w->regulator);
993 return regulator_disable_deferred(w->regulator, w->shift);
995 EXPORT_SYMBOL_GPL(dapm_regulator_event);
997 static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
999 if (w->power_checked)
1000 return w->new_power;
1005 w->new_power = w->power_check(w);
1007 w->power_checked = true;
1009 return w->new_power;
1012 /* Generic check to see if a widget should be powered.
1014 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
1018 DAPM_UPDATE_STAT(w, power_checks);
1020 in = is_connected_input_ep(w, NULL);
1021 dapm_clear_walk(w->dapm);
1022 out = is_connected_output_ep(w, NULL);
1023 dapm_clear_walk(w->dapm);
1024 return out != 0 && in != 0;
1027 static int dapm_dai_check_power(struct snd_soc_dapm_widget *w)
1029 DAPM_UPDATE_STAT(w, power_checks);
1034 return dapm_generic_check_power(w);
1037 /* Check to see if an ADC has power */
1038 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
1042 DAPM_UPDATE_STAT(w, power_checks);
1045 in = is_connected_input_ep(w, NULL);
1046 dapm_clear_walk(w->dapm);
1049 return dapm_generic_check_power(w);
1053 /* Check to see if a DAC has power */
1054 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
1058 DAPM_UPDATE_STAT(w, power_checks);
1061 out = is_connected_output_ep(w, NULL);
1062 dapm_clear_walk(w->dapm);
1065 return dapm_generic_check_power(w);
1069 /* Check to see if a power supply is needed */
1070 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1072 struct snd_soc_dapm_path *path;
1074 DAPM_UPDATE_STAT(w, power_checks);
1076 /* Check if one of our outputs is connected */
1077 list_for_each_entry(path, &w->sinks, list_source) {
1078 DAPM_UPDATE_STAT(w, neighbour_checks);
1083 if (path->connected &&
1084 !path->connected(path->source, path->sink))
1090 if (dapm_widget_power_check(path->sink))
1094 dapm_clear_walk(w->dapm);
1099 static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
1104 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
1105 struct snd_soc_dapm_widget *b,
1113 sort = dapm_down_seq;
1115 if (sort[a->id] != sort[b->id])
1116 return sort[a->id] - sort[b->id];
1117 if (a->subseq != b->subseq) {
1119 return a->subseq - b->subseq;
1121 return b->subseq - a->subseq;
1123 if (a->reg != b->reg)
1124 return a->reg - b->reg;
1125 if (a->dapm != b->dapm)
1126 return (unsigned long)a->dapm - (unsigned long)b->dapm;
1131 /* Insert a widget in order into a DAPM power sequence. */
1132 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
1133 struct list_head *list,
1136 struct snd_soc_dapm_widget *w;
1138 list_for_each_entry(w, list, power_list)
1139 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
1140 list_add_tail(&new_widget->power_list, &w->power_list);
1144 list_add_tail(&new_widget->power_list, list);
1147 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
1148 struct snd_soc_dapm_widget *w, int event)
1150 struct snd_soc_card *card = dapm->card;
1151 const char *ev_name;
1155 case SND_SOC_DAPM_PRE_PMU:
1156 ev_name = "PRE_PMU";
1159 case SND_SOC_DAPM_POST_PMU:
1160 ev_name = "POST_PMU";
1163 case SND_SOC_DAPM_PRE_PMD:
1164 ev_name = "PRE_PMD";
1167 case SND_SOC_DAPM_POST_PMD:
1168 ev_name = "POST_PMD";
1176 if (w->power != power)
1179 if (w->event && (w->event_flags & event)) {
1180 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
1182 trace_snd_soc_dapm_widget_event_start(w, event);
1183 ret = w->event(w, NULL, event);
1184 trace_snd_soc_dapm_widget_event_done(w, event);
1186 pr_err("%s: %s event failed: %d\n",
1187 ev_name, w->name, ret);
1191 /* Apply the coalesced changes from a DAPM sequence */
1192 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
1193 struct list_head *pending)
1195 struct snd_soc_card *card = dapm->card;
1196 struct snd_soc_dapm_widget *w;
1198 unsigned int value = 0;
1199 unsigned int mask = 0;
1200 unsigned int cur_mask;
1202 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
1205 list_for_each_entry(w, pending, power_list) {
1206 cur_mask = 1 << w->shift;
1207 BUG_ON(reg != w->reg);
1218 pop_dbg(dapm->dev, card->pop_time,
1219 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1220 w->name, reg, value, mask);
1222 /* Check for events */
1223 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
1224 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
1228 /* Any widget will do, they should all be updating the
1231 w = list_first_entry(pending, struct snd_soc_dapm_widget,
1234 pop_dbg(dapm->dev, card->pop_time,
1235 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1236 value, mask, reg, card->pop_time);
1237 pop_wait(card->pop_time);
1238 soc_widget_update_bits_locked(w, reg, mask, value);
1241 list_for_each_entry(w, pending, power_list) {
1242 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
1243 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
1247 /* Apply a DAPM power sequence.
1249 * We walk over a pre-sorted list of widgets to apply power to. In
1250 * order to minimise the number of writes to the device required
1251 * multiple widgets will be updated in a single write where possible.
1252 * Currently anything that requires more than a single write is not
1255 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1256 struct list_head *list, int event, bool power_up)
1258 struct snd_soc_dapm_widget *w, *n;
1261 int cur_subseq = -1;
1262 int cur_reg = SND_SOC_NOPM;
1263 struct snd_soc_dapm_context *cur_dapm = NULL;
1270 sort = dapm_down_seq;
1272 list_for_each_entry_safe(w, n, list, power_list) {
1275 /* Do we need to apply any queued changes? */
1276 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1277 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1278 if (!list_empty(&pending))
1279 dapm_seq_run_coalesced(cur_dapm, &pending);
1281 if (cur_dapm && cur_dapm->seq_notifier) {
1282 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1283 if (sort[i] == cur_sort)
1284 cur_dapm->seq_notifier(cur_dapm,
1289 INIT_LIST_HEAD(&pending);
1291 cur_subseq = INT_MIN;
1292 cur_reg = SND_SOC_NOPM;
1297 case snd_soc_dapm_pre:
1299 list_for_each_entry_safe_continue(w, n, list,
1302 if (event == SND_SOC_DAPM_STREAM_START)
1304 NULL, SND_SOC_DAPM_PRE_PMU);
1305 else if (event == SND_SOC_DAPM_STREAM_STOP)
1307 NULL, SND_SOC_DAPM_PRE_PMD);
1310 case snd_soc_dapm_post:
1312 list_for_each_entry_safe_continue(w, n, list,
1315 if (event == SND_SOC_DAPM_STREAM_START)
1317 NULL, SND_SOC_DAPM_POST_PMU);
1318 else if (event == SND_SOC_DAPM_STREAM_STOP)
1320 NULL, SND_SOC_DAPM_POST_PMD);
1324 /* Queue it up for application */
1325 cur_sort = sort[w->id];
1326 cur_subseq = w->subseq;
1329 list_move(&w->power_list, &pending);
1334 dev_err(w->dapm->dev,
1335 "Failed to apply widget power: %d\n", ret);
1338 if (!list_empty(&pending))
1339 dapm_seq_run_coalesced(cur_dapm, &pending);
1341 if (cur_dapm && cur_dapm->seq_notifier) {
1342 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1343 if (sort[i] == cur_sort)
1344 cur_dapm->seq_notifier(cur_dapm,
1349 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1351 struct snd_soc_dapm_update *update = dapm->update;
1352 struct snd_soc_dapm_widget *w;
1361 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1362 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1364 pr_err("%s DAPM pre-event failed: %d\n",
1368 ret = soc_widget_update_bits_locked(w, update->reg, update->mask,
1371 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1374 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1375 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1377 pr_err("%s DAPM post-event failed: %d\n",
1382 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1383 * they're changing state.
1385 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1387 struct snd_soc_dapm_context *d = data;
1390 /* If we're off and we're not supposed to be go into STANDBY */
1391 if (d->bias_level == SND_SOC_BIAS_OFF &&
1392 d->target_bias_level != SND_SOC_BIAS_OFF) {
1394 pm_runtime_get_sync(d->dev);
1396 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1399 "Failed to turn on bias: %d\n", ret);
1402 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1403 if (d->bias_level != d->target_bias_level) {
1404 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1407 "Failed to prepare bias: %d\n", ret);
1411 /* Async callback run prior to DAPM sequences - brings to their final
1414 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1416 struct snd_soc_dapm_context *d = data;
1419 /* If we just powered the last thing off drop to standby bias */
1420 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1421 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1422 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1423 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1425 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1429 /* If we're in standby and can support bias off then do that */
1430 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1431 d->target_bias_level == SND_SOC_BIAS_OFF) {
1432 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1434 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1437 pm_runtime_put(d->dev);
1440 /* If we just powered up then move to active bias */
1441 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1442 d->target_bias_level == SND_SOC_BIAS_ON) {
1443 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1445 dev_err(d->dev, "Failed to apply active bias: %d\n",
1450 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
1451 bool power, bool connect)
1453 /* If a connection is being made or broken then that update
1454 * will have marked the peer dirty, otherwise the widgets are
1455 * not connected and this update has no impact. */
1459 /* If the peer is already in the state we're moving to then we
1460 * won't have an impact on it. */
1461 if (power != peer->power)
1462 dapm_mark_dirty(peer, "peer state change");
1465 static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1466 struct list_head *up_list,
1467 struct list_head *down_list)
1469 struct snd_soc_dapm_path *path;
1471 if (w->power == power)
1474 trace_snd_soc_dapm_widget_power(w, power);
1476 /* If we changed our power state perhaps our neigbours changed
1479 list_for_each_entry(path, &w->sources, list_sink) {
1481 dapm_widget_set_peer_power(path->source, power,
1486 case snd_soc_dapm_supply:
1487 case snd_soc_dapm_regulator_supply:
1488 /* Supplies can't affect their outputs, only their inputs */
1491 list_for_each_entry(path, &w->sinks, list_source) {
1493 dapm_widget_set_peer_power(path->sink, power,
1501 dapm_seq_insert(w, up_list, true);
1503 dapm_seq_insert(w, down_list, false);
1508 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1509 struct list_head *up_list,
1510 struct list_head *down_list)
1515 case snd_soc_dapm_pre:
1516 dapm_seq_insert(w, down_list, false);
1518 case snd_soc_dapm_post:
1519 dapm_seq_insert(w, up_list, true);
1523 power = dapm_widget_power_check(w);
1525 dapm_widget_set_power(w, power, up_list, down_list);
1531 * Scan each dapm widget for complete audio path.
1532 * A complete path is a route that has valid endpoints i.e.:-
1534 * o DAC to output pin.
1535 * o Input Pin to ADC.
1536 * o Input pin to Output pin (bypass, sidetone)
1537 * o DAC to ADC (loopback).
1539 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1541 struct snd_soc_card *card = dapm->card;
1542 struct snd_soc_dapm_widget *w;
1543 struct snd_soc_dapm_context *d;
1545 LIST_HEAD(down_list);
1546 LIST_HEAD(async_domain);
1547 enum snd_soc_bias_level bias;
1549 trace_snd_soc_dapm_start(card);
1551 list_for_each_entry(d, &card->dapm_list, list) {
1552 if (d->idle_bias_off)
1553 d->target_bias_level = SND_SOC_BIAS_OFF;
1555 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1560 /* Check which widgets we need to power and store them in
1561 * lists indicating if they should be powered up or down. We
1562 * only check widgets that have been flagged as dirty but note
1563 * that new widgets may be added to the dirty list while we
1566 list_for_each_entry(w, &card->dapm_dirty, dirty) {
1567 dapm_power_one_widget(w, &up_list, &down_list);
1570 list_for_each_entry(w, &card->widgets, list) {
1571 list_del_init(&w->dirty);
1576 /* Supplies and micbiases only bring the
1577 * context up to STANDBY as unless something
1578 * else is active and passing audio they
1579 * generally don't require full power. Signal
1580 * generators are virtual pins and have no
1581 * power impact themselves.
1584 case snd_soc_dapm_siggen:
1586 case snd_soc_dapm_supply:
1587 case snd_soc_dapm_regulator_supply:
1588 case snd_soc_dapm_micbias:
1589 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1590 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1593 d->target_bias_level = SND_SOC_BIAS_ON;
1600 /* Force all contexts in the card to the same bias state if
1601 * they're not ground referenced.
1603 bias = SND_SOC_BIAS_OFF;
1604 list_for_each_entry(d, &card->dapm_list, list)
1605 if (d->target_bias_level > bias)
1606 bias = d->target_bias_level;
1607 list_for_each_entry(d, &card->dapm_list, list)
1608 if (!d->idle_bias_off)
1609 d->target_bias_level = bias;
1611 trace_snd_soc_dapm_walk_done(card);
1613 /* Run all the bias changes in parallel */
1614 list_for_each_entry(d, &dapm->card->dapm_list, list)
1615 async_schedule_domain(dapm_pre_sequence_async, d,
1617 async_synchronize_full_domain(&async_domain);
1619 /* Power down widgets first; try to avoid amplifying pops. */
1620 dapm_seq_run(dapm, &down_list, event, false);
1622 dapm_widget_update(dapm);
1625 dapm_seq_run(dapm, &up_list, event, true);
1627 /* Run all the bias changes in parallel */
1628 list_for_each_entry(d, &dapm->card->dapm_list, list)
1629 async_schedule_domain(dapm_post_sequence_async, d,
1631 async_synchronize_full_domain(&async_domain);
1633 /* do we need to notify any clients that DAPM event is complete */
1634 list_for_each_entry(d, &card->dapm_list, list) {
1635 if (d->stream_event)
1636 d->stream_event(d, event);
1639 pop_dbg(dapm->dev, card->pop_time,
1640 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1641 pop_wait(card->pop_time);
1643 trace_snd_soc_dapm_done(card);
1648 #ifdef CONFIG_DEBUG_FS
1649 static ssize_t dapm_widget_power_read_file(struct file *file,
1650 char __user *user_buf,
1651 size_t count, loff_t *ppos)
1653 struct snd_soc_dapm_widget *w = file->private_data;
1657 struct snd_soc_dapm_path *p = NULL;
1659 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1663 in = is_connected_input_ep(w, NULL);
1664 dapm_clear_walk(w->dapm);
1665 out = is_connected_output_ep(w, NULL);
1666 dapm_clear_walk(w->dapm);
1668 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
1669 w->name, w->power ? "On" : "Off",
1670 w->force ? " (forced)" : "", in, out);
1673 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1674 " - R%d(0x%x) bit %d",
1675 w->reg, w->reg, w->shift);
1677 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1680 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1682 w->active ? "active" : "inactive");
1684 list_for_each_entry(p, &w->sources, list_sink) {
1685 if (p->connected && !p->connected(w, p->sink))
1689 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1690 " in \"%s\" \"%s\"\n",
1691 p->name ? p->name : "static",
1694 list_for_each_entry(p, &w->sinks, list_source) {
1695 if (p->connected && !p->connected(w, p->sink))
1699 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1700 " out \"%s\" \"%s\"\n",
1701 p->name ? p->name : "static",
1705 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1711 static const struct file_operations dapm_widget_power_fops = {
1712 .open = simple_open,
1713 .read = dapm_widget_power_read_file,
1714 .llseek = default_llseek,
1717 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1718 size_t count, loff_t *ppos)
1720 struct snd_soc_dapm_context *dapm = file->private_data;
1723 switch (dapm->bias_level) {
1724 case SND_SOC_BIAS_ON:
1727 case SND_SOC_BIAS_PREPARE:
1728 level = "Prepare\n";
1730 case SND_SOC_BIAS_STANDBY:
1731 level = "Standby\n";
1733 case SND_SOC_BIAS_OFF:
1738 level = "Unknown\n";
1742 return simple_read_from_buffer(user_buf, count, ppos, level,
1746 static const struct file_operations dapm_bias_fops = {
1747 .open = simple_open,
1748 .read = dapm_bias_read_file,
1749 .llseek = default_llseek,
1752 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1753 struct dentry *parent)
1757 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1759 if (!dapm->debugfs_dapm) {
1761 "Failed to create DAPM debugfs directory\n");
1765 d = debugfs_create_file("bias_level", 0444,
1766 dapm->debugfs_dapm, dapm,
1770 "ASoC: Failed to create bias level debugfs file\n");
1773 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1775 struct snd_soc_dapm_context *dapm = w->dapm;
1778 if (!dapm->debugfs_dapm || !w->name)
1781 d = debugfs_create_file(w->name, 0444,
1782 dapm->debugfs_dapm, w,
1783 &dapm_widget_power_fops);
1785 dev_warn(w->dapm->dev,
1786 "ASoC: Failed to create %s debugfs file\n",
1790 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1792 debugfs_remove_recursive(dapm->debugfs_dapm);
1796 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1797 struct dentry *parent)
1801 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1805 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1811 /* test and update the power status of a mux widget */
1812 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1813 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1815 struct snd_soc_dapm_path *path;
1818 if (widget->id != snd_soc_dapm_mux &&
1819 widget->id != snd_soc_dapm_virt_mux &&
1820 widget->id != snd_soc_dapm_value_mux)
1823 /* find dapm widget path assoc with kcontrol */
1824 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1825 if (path->kcontrol != kcontrol)
1828 if (!path->name || !e->texts[mux])
1832 /* we now need to match the string in the enum to the path */
1833 if (!(strcmp(path->name, e->texts[mux]))) {
1834 path->connect = 1; /* new connection */
1835 dapm_mark_dirty(path->source, "mux connection");
1838 dapm_mark_dirty(path->source,
1839 "mux disconnection");
1840 path->connect = 0; /* old connection must be powered down */
1845 dapm_mark_dirty(widget, "mux change");
1846 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1852 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1853 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1855 struct snd_soc_card *card = widget->dapm->card;
1858 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1859 ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
1860 mutex_unlock(&card->dapm_mutex);
1863 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
1865 /* test and update the power status of a mixer or switch widget */
1866 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1867 struct snd_kcontrol *kcontrol, int connect)
1869 struct snd_soc_dapm_path *path;
1872 if (widget->id != snd_soc_dapm_mixer &&
1873 widget->id != snd_soc_dapm_mixer_named_ctl &&
1874 widget->id != snd_soc_dapm_switch)
1877 /* find dapm widget path assoc with kcontrol */
1878 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1879 if (path->kcontrol != kcontrol)
1882 /* found, now check type */
1884 path->connect = connect;
1885 dapm_mark_dirty(path->source, "mixer connection");
1889 dapm_mark_dirty(widget, "mixer update");
1890 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1896 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1897 struct snd_kcontrol *kcontrol, int connect)
1899 struct snd_soc_card *card = widget->dapm->card;
1902 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1903 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
1904 mutex_unlock(&card->dapm_mutex);
1907 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
1909 /* show dapm widget status in sys fs */
1910 static ssize_t dapm_widget_show(struct device *dev,
1911 struct device_attribute *attr, char *buf)
1913 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
1914 struct snd_soc_codec *codec =rtd->codec;
1915 struct snd_soc_dapm_widget *w;
1917 char *state = "not set";
1919 list_for_each_entry(w, &codec->card->widgets, list) {
1920 if (w->dapm != &codec->dapm)
1923 /* only display widgets that burnm power */
1925 case snd_soc_dapm_hp:
1926 case snd_soc_dapm_mic:
1927 case snd_soc_dapm_spk:
1928 case snd_soc_dapm_line:
1929 case snd_soc_dapm_micbias:
1930 case snd_soc_dapm_dac:
1931 case snd_soc_dapm_adc:
1932 case snd_soc_dapm_pga:
1933 case snd_soc_dapm_out_drv:
1934 case snd_soc_dapm_mixer:
1935 case snd_soc_dapm_mixer_named_ctl:
1936 case snd_soc_dapm_supply:
1937 case snd_soc_dapm_regulator_supply:
1939 count += sprintf(buf + count, "%s: %s\n",
1940 w->name, w->power ? "On":"Off");
1947 switch (codec->dapm.bias_level) {
1948 case SND_SOC_BIAS_ON:
1951 case SND_SOC_BIAS_PREPARE:
1954 case SND_SOC_BIAS_STANDBY:
1957 case SND_SOC_BIAS_OFF:
1961 count += sprintf(buf + count, "PM State: %s\n", state);
1966 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1968 int snd_soc_dapm_sys_add(struct device *dev)
1970 return device_create_file(dev, &dev_attr_dapm_widget);
1973 static void snd_soc_dapm_sys_remove(struct device *dev)
1975 device_remove_file(dev, &dev_attr_dapm_widget);
1978 /* free all dapm widgets and resources */
1979 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1981 struct snd_soc_dapm_widget *w, *next_w;
1982 struct snd_soc_dapm_path *p, *next_p;
1984 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1985 if (w->dapm != dapm)
1989 * remove source and sink paths associated to this widget.
1990 * While removing the path, remove reference to it from both
1991 * source and sink widgets so that path is removed only once.
1993 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1994 list_del(&p->list_sink);
1995 list_del(&p->list_source);
1997 kfree(p->long_name);
2000 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
2001 list_del(&p->list_sink);
2002 list_del(&p->list_source);
2004 kfree(p->long_name);
2007 kfree(w->kcontrols);
2013 static struct snd_soc_dapm_widget *dapm_find_widget(
2014 struct snd_soc_dapm_context *dapm, const char *pin,
2015 bool search_other_contexts)
2017 struct snd_soc_dapm_widget *w;
2018 struct snd_soc_dapm_widget *fallback = NULL;
2020 list_for_each_entry(w, &dapm->card->widgets, list) {
2021 if (!strcmp(w->name, pin)) {
2022 if (w->dapm == dapm)
2029 if (search_other_contexts)
2035 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2036 const char *pin, int status)
2038 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2041 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2045 if (w->connected != status)
2046 dapm_mark_dirty(w, "pin configuration");
2048 w->connected = status;
2056 * snd_soc_dapm_sync - scan and power dapm paths
2057 * @dapm: DAPM context
2059 * Walks all dapm audio paths and powers widgets according to their
2060 * stream or path usage.
2062 * Returns 0 for success.
2064 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2069 * Suppress early reports (eg, jacks syncing their state) to avoid
2070 * silly DAPM runs during card startup.
2072 if (!dapm->card || !dapm->card->instantiated)
2075 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2076 ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2077 mutex_unlock(&dapm->card->dapm_mutex);
2080 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2082 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2083 const struct snd_soc_dapm_route *route)
2085 struct snd_soc_dapm_path *path;
2086 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
2087 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
2089 const char *control = route->control;
2091 char prefixed_sink[80];
2092 char prefixed_source[80];
2095 if (dapm->codec && dapm->codec->name_prefix) {
2096 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2097 dapm->codec->name_prefix, route->sink);
2098 sink = prefixed_sink;
2099 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2100 dapm->codec->name_prefix, route->source);
2101 source = prefixed_source;
2104 source = route->source;
2108 * find src and dest widgets over all widgets but favor a widget from
2109 * current DAPM context
2111 list_for_each_entry(w, &dapm->card->widgets, list) {
2112 if (!wsink && !(strcmp(w->name, sink))) {
2114 if (w->dapm == dapm)
2118 if (!wsource && !(strcmp(w->name, source))) {
2120 if (w->dapm == dapm)
2124 /* use widget from another DAPM context if not found from this */
2130 if (wsource == NULL || wsink == NULL)
2133 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2137 path->source = wsource;
2139 path->connected = route->connected;
2140 INIT_LIST_HEAD(&path->list);
2141 INIT_LIST_HEAD(&path->list_source);
2142 INIT_LIST_HEAD(&path->list_sink);
2144 /* check for external widgets */
2145 if (wsink->id == snd_soc_dapm_input) {
2146 if (wsource->id == snd_soc_dapm_micbias ||
2147 wsource->id == snd_soc_dapm_mic ||
2148 wsource->id == snd_soc_dapm_line ||
2149 wsource->id == snd_soc_dapm_output)
2152 if (wsource->id == snd_soc_dapm_output) {
2153 if (wsink->id == snd_soc_dapm_spk ||
2154 wsink->id == snd_soc_dapm_hp ||
2155 wsink->id == snd_soc_dapm_line ||
2156 wsink->id == snd_soc_dapm_input)
2160 /* connect static paths */
2161 if (control == NULL) {
2162 list_add(&path->list, &dapm->card->paths);
2163 list_add(&path->list_sink, &wsink->sources);
2164 list_add(&path->list_source, &wsource->sinks);
2169 /* connect dynamic paths */
2170 switch (wsink->id) {
2171 case snd_soc_dapm_adc:
2172 case snd_soc_dapm_dac:
2173 case snd_soc_dapm_pga:
2174 case snd_soc_dapm_out_drv:
2175 case snd_soc_dapm_input:
2176 case snd_soc_dapm_output:
2177 case snd_soc_dapm_siggen:
2178 case snd_soc_dapm_micbias:
2179 case snd_soc_dapm_vmid:
2180 case snd_soc_dapm_pre:
2181 case snd_soc_dapm_post:
2182 case snd_soc_dapm_supply:
2183 case snd_soc_dapm_regulator_supply:
2184 case snd_soc_dapm_aif_in:
2185 case snd_soc_dapm_aif_out:
2186 case snd_soc_dapm_dai:
2187 case snd_soc_dapm_dai_link:
2188 list_add(&path->list, &dapm->card->paths);
2189 list_add(&path->list_sink, &wsink->sources);
2190 list_add(&path->list_source, &wsource->sinks);
2193 case snd_soc_dapm_mux:
2194 case snd_soc_dapm_virt_mux:
2195 case snd_soc_dapm_value_mux:
2196 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2197 &wsink->kcontrol_news[0]);
2201 case snd_soc_dapm_switch:
2202 case snd_soc_dapm_mixer:
2203 case snd_soc_dapm_mixer_named_ctl:
2204 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2208 case snd_soc_dapm_hp:
2209 case snd_soc_dapm_mic:
2210 case snd_soc_dapm_line:
2211 case snd_soc_dapm_spk:
2212 list_add(&path->list, &dapm->card->paths);
2213 list_add(&path->list_sink, &wsink->sources);
2214 list_add(&path->list_source, &wsource->sinks);
2221 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
2222 source, control, sink);
2228 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2229 * @dapm: DAPM context
2230 * @route: audio routes
2231 * @num: number of routes
2233 * Connects 2 dapm widgets together via a named audio path. The sink is
2234 * the widget receiving the audio signal, whilst the source is the sender
2235 * of the audio signal.
2237 * Returns 0 for success else error. On error all resources can be freed
2238 * with a call to snd_soc_card_free().
2240 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2241 const struct snd_soc_dapm_route *route, int num)
2245 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2246 for (i = 0; i < num; i++) {
2247 ret = snd_soc_dapm_add_route(dapm, route);
2249 dev_err(dapm->dev, "Failed to add route %s->%s\n",
2250 route->source, route->sink);
2255 mutex_unlock(&dapm->card->dapm_mutex);
2259 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2261 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2262 const struct snd_soc_dapm_route *route)
2264 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2267 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2270 struct snd_soc_dapm_path *path;
2274 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
2280 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
2285 if (route->control || route->connected)
2286 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
2287 route->source, route->sink);
2289 list_for_each_entry(path, &source->sinks, list_source) {
2290 if (path->sink == sink) {
2297 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
2298 route->source, route->sink);
2300 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
2301 count, route->source, route->sink);
2307 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2308 * @dapm: DAPM context
2309 * @route: audio routes
2310 * @num: number of routes
2312 * Mark existing routes matching those specified in the passed array
2313 * as being weak, meaning that they are ignored for the purpose of
2314 * power decisions. The main intended use case is for sidetone paths
2315 * which couple audio between other independent paths if they are both
2316 * active in order to make the combination work better at the user
2317 * level but which aren't intended to be "used".
2319 * Note that CODEC drivers should not use this as sidetone type paths
2320 * can frequently also be used as bypass paths.
2322 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2323 const struct snd_soc_dapm_route *route, int num)
2328 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2329 for (i = 0; i < num; i++) {
2330 err = snd_soc_dapm_weak_route(dapm, route);
2335 mutex_unlock(&dapm->card->dapm_mutex);
2339 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2342 * snd_soc_dapm_new_widgets - add new dapm widgets
2343 * @dapm: DAPM context
2345 * Checks the codec for any new dapm widgets and creates them if found.
2347 * Returns 0 for success.
2349 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2351 struct snd_soc_dapm_widget *w;
2354 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2356 list_for_each_entry(w, &dapm->card->widgets, list)
2361 if (w->num_kcontrols) {
2362 w->kcontrols = kzalloc(w->num_kcontrols *
2363 sizeof(struct snd_kcontrol *),
2365 if (!w->kcontrols) {
2366 mutex_unlock(&dapm->card->dapm_mutex);
2372 case snd_soc_dapm_switch:
2373 case snd_soc_dapm_mixer:
2374 case snd_soc_dapm_mixer_named_ctl:
2377 case snd_soc_dapm_mux:
2378 case snd_soc_dapm_virt_mux:
2379 case snd_soc_dapm_value_mux:
2382 case snd_soc_dapm_pga:
2383 case snd_soc_dapm_out_drv:
2390 /* Read the initial power state from the device */
2392 val = soc_widget_read(w, w->reg);
2393 val &= 1 << w->shift;
2403 dapm_mark_dirty(w, "new widget");
2404 dapm_debugfs_add_widget(w);
2407 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2408 mutex_unlock(&dapm->card->dapm_mutex);
2411 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2414 * snd_soc_dapm_get_volsw - dapm mixer get callback
2415 * @kcontrol: mixer control
2416 * @ucontrol: control element information
2418 * Callback to get the value of a dapm mixer control.
2420 * Returns 0 for success.
2422 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2423 struct snd_ctl_elem_value *ucontrol)
2425 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2426 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2427 struct soc_mixer_control *mc =
2428 (struct soc_mixer_control *)kcontrol->private_value;
2429 unsigned int reg = mc->reg;
2430 unsigned int shift = mc->shift;
2431 unsigned int rshift = mc->rshift;
2433 unsigned int invert = mc->invert;
2434 unsigned int mask = (1 << fls(max)) - 1;
2436 ucontrol->value.integer.value[0] =
2437 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2438 if (shift != rshift)
2439 ucontrol->value.integer.value[1] =
2440 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2442 ucontrol->value.integer.value[0] =
2443 max - ucontrol->value.integer.value[0];
2444 if (shift != rshift)
2445 ucontrol->value.integer.value[1] =
2446 max - ucontrol->value.integer.value[1];
2451 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2454 * snd_soc_dapm_put_volsw - dapm mixer set callback
2455 * @kcontrol: mixer control
2456 * @ucontrol: control element information
2458 * Callback to set the value of a dapm mixer control.
2460 * Returns 0 for success.
2462 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2463 struct snd_ctl_elem_value *ucontrol)
2465 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2466 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2467 struct snd_soc_codec *codec = widget->codec;
2468 struct snd_soc_card *card = codec->card;
2469 struct soc_mixer_control *mc =
2470 (struct soc_mixer_control *)kcontrol->private_value;
2471 unsigned int reg = mc->reg;
2472 unsigned int shift = mc->shift;
2474 unsigned int mask = (1 << fls(max)) - 1;
2475 unsigned int invert = mc->invert;
2477 int connect, change;
2478 struct snd_soc_dapm_update update;
2481 val = (ucontrol->value.integer.value[0] & mask);
2485 mask = mask << shift;
2489 /* new connection */
2490 connect = invert ? 0 : 1;
2492 /* old connection must be powered down */
2493 connect = invert ? 1 : 0;
2495 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2497 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2499 for (wi = 0; wi < wlist->num_widgets; wi++) {
2500 widget = wlist->widgets[wi];
2502 widget->value = val;
2504 update.kcontrol = kcontrol;
2505 update.widget = widget;
2509 widget->dapm->update = &update;
2511 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2513 widget->dapm->update = NULL;
2517 mutex_unlock(&card->dapm_mutex);
2520 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2523 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2524 * @kcontrol: mixer control
2525 * @ucontrol: control element information
2527 * Callback to get the value of a dapm enumerated double mixer control.
2529 * Returns 0 for success.
2531 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2532 struct snd_ctl_elem_value *ucontrol)
2534 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2535 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2536 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2537 unsigned int val, bitmask;
2539 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2541 val = snd_soc_read(widget->codec, e->reg);
2542 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2543 if (e->shift_l != e->shift_r)
2544 ucontrol->value.enumerated.item[1] =
2545 (val >> e->shift_r) & (bitmask - 1);
2549 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2552 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2553 * @kcontrol: mixer control
2554 * @ucontrol: control element information
2556 * Callback to set the value of a dapm enumerated double mixer control.
2558 * Returns 0 for success.
2560 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2561 struct snd_ctl_elem_value *ucontrol)
2563 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2564 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2565 struct snd_soc_codec *codec = widget->codec;
2566 struct snd_soc_card *card = codec->card;
2567 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2568 unsigned int val, mux, change;
2569 unsigned int mask, bitmask;
2570 struct snd_soc_dapm_update update;
2573 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2575 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2577 mux = ucontrol->value.enumerated.item[0];
2578 val = mux << e->shift_l;
2579 mask = (bitmask - 1) << e->shift_l;
2580 if (e->shift_l != e->shift_r) {
2581 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2583 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2584 mask |= (bitmask - 1) << e->shift_r;
2587 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2589 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2591 for (wi = 0; wi < wlist->num_widgets; wi++) {
2592 widget = wlist->widgets[wi];
2594 widget->value = val;
2596 update.kcontrol = kcontrol;
2597 update.widget = widget;
2598 update.reg = e->reg;
2601 widget->dapm->update = &update;
2603 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2605 widget->dapm->update = NULL;
2609 mutex_unlock(&card->dapm_mutex);
2612 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2615 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2616 * @kcontrol: mixer control
2617 * @ucontrol: control element information
2619 * Returns 0 for success.
2621 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2622 struct snd_ctl_elem_value *ucontrol)
2624 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2625 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2627 ucontrol->value.enumerated.item[0] = widget->value;
2631 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2634 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2635 * @kcontrol: mixer control
2636 * @ucontrol: control element information
2638 * Returns 0 for success.
2640 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2641 struct snd_ctl_elem_value *ucontrol)
2643 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2644 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2645 struct snd_soc_codec *codec = widget->codec;
2646 struct snd_soc_card *card = codec->card;
2647 struct soc_enum *e =
2648 (struct soc_enum *)kcontrol->private_value;
2653 if (ucontrol->value.enumerated.item[0] >= e->max)
2656 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2658 change = widget->value != ucontrol->value.enumerated.item[0];
2660 for (wi = 0; wi < wlist->num_widgets; wi++) {
2661 widget = wlist->widgets[wi];
2663 widget->value = ucontrol->value.enumerated.item[0];
2665 soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
2669 mutex_unlock(&card->dapm_mutex);
2672 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2675 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2677 * @kcontrol: mixer control
2678 * @ucontrol: control element information
2680 * Callback to get the value of a dapm semi enumerated double mixer control.
2682 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2683 * used for handling bitfield coded enumeration for example.
2685 * Returns 0 for success.
2687 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2688 struct snd_ctl_elem_value *ucontrol)
2690 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2691 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2692 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2693 unsigned int reg_val, val, mux;
2695 reg_val = snd_soc_read(widget->codec, e->reg);
2696 val = (reg_val >> e->shift_l) & e->mask;
2697 for (mux = 0; mux < e->max; mux++) {
2698 if (val == e->values[mux])
2701 ucontrol->value.enumerated.item[0] = mux;
2702 if (e->shift_l != e->shift_r) {
2703 val = (reg_val >> e->shift_r) & e->mask;
2704 for (mux = 0; mux < e->max; mux++) {
2705 if (val == e->values[mux])
2708 ucontrol->value.enumerated.item[1] = mux;
2713 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2716 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2718 * @kcontrol: mixer control
2719 * @ucontrol: control element information
2721 * Callback to set the value of a dapm semi enumerated double mixer control.
2723 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2724 * used for handling bitfield coded enumeration for example.
2726 * Returns 0 for success.
2728 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2729 struct snd_ctl_elem_value *ucontrol)
2731 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2732 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2733 struct snd_soc_codec *codec = widget->codec;
2734 struct snd_soc_card *card = codec->card;
2735 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2736 unsigned int val, mux, change;
2738 struct snd_soc_dapm_update update;
2741 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2743 mux = ucontrol->value.enumerated.item[0];
2744 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2745 mask = e->mask << e->shift_l;
2746 if (e->shift_l != e->shift_r) {
2747 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2749 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2750 mask |= e->mask << e->shift_r;
2753 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2755 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2757 for (wi = 0; wi < wlist->num_widgets; wi++) {
2758 widget = wlist->widgets[wi];
2760 widget->value = val;
2762 update.kcontrol = kcontrol;
2763 update.widget = widget;
2764 update.reg = e->reg;
2767 widget->dapm->update = &update;
2769 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2771 widget->dapm->update = NULL;
2775 mutex_unlock(&card->dapm_mutex);
2778 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2781 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2783 * @kcontrol: mixer control
2784 * @uinfo: control element information
2786 * Callback to provide information about a pin switch control.
2788 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2789 struct snd_ctl_elem_info *uinfo)
2791 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2793 uinfo->value.integer.min = 0;
2794 uinfo->value.integer.max = 1;
2798 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2801 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2803 * @kcontrol: mixer control
2806 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2807 struct snd_ctl_elem_value *ucontrol)
2809 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2810 const char *pin = (const char *)kcontrol->private_value;
2812 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2814 ucontrol->value.integer.value[0] =
2815 snd_soc_dapm_get_pin_status(&card->dapm, pin);
2817 mutex_unlock(&card->dapm_mutex);
2821 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2824 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2826 * @kcontrol: mixer control
2829 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2830 struct snd_ctl_elem_value *ucontrol)
2832 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2833 const char *pin = (const char *)kcontrol->private_value;
2835 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2837 if (ucontrol->value.integer.value[0])
2838 snd_soc_dapm_enable_pin(&card->dapm, pin);
2840 snd_soc_dapm_disable_pin(&card->dapm, pin);
2842 mutex_unlock(&card->dapm_mutex);
2844 snd_soc_dapm_sync(&card->dapm);
2847 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2849 static struct snd_soc_dapm_widget *
2850 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2851 const struct snd_soc_dapm_widget *widget)
2853 struct snd_soc_dapm_widget *w;
2857 if ((w = dapm_cnew_widget(widget)) == NULL)
2861 case snd_soc_dapm_regulator_supply:
2862 w->regulator = devm_regulator_get(dapm->dev, w->name);
2863 if (IS_ERR(w->regulator)) {
2864 ret = PTR_ERR(w->regulator);
2865 dev_err(dapm->dev, "Failed to request %s: %d\n",
2874 name_len = strlen(widget->name) + 1;
2875 if (dapm->codec && dapm->codec->name_prefix)
2876 name_len += 1 + strlen(dapm->codec->name_prefix);
2877 w->name = kmalloc(name_len, GFP_KERNEL);
2878 if (w->name == NULL) {
2882 if (dapm->codec && dapm->codec->name_prefix)
2883 snprintf((char *)w->name, name_len, "%s %s",
2884 dapm->codec->name_prefix, widget->name);
2886 snprintf((char *)w->name, name_len, "%s", widget->name);
2889 case snd_soc_dapm_switch:
2890 case snd_soc_dapm_mixer:
2891 case snd_soc_dapm_mixer_named_ctl:
2892 w->power_check = dapm_generic_check_power;
2894 case snd_soc_dapm_mux:
2895 case snd_soc_dapm_virt_mux:
2896 case snd_soc_dapm_value_mux:
2897 w->power_check = dapm_generic_check_power;
2899 case snd_soc_dapm_adc:
2900 case snd_soc_dapm_aif_out:
2901 w->power_check = dapm_adc_check_power;
2903 case snd_soc_dapm_dac:
2904 case snd_soc_dapm_aif_in:
2905 w->power_check = dapm_dac_check_power;
2907 case snd_soc_dapm_pga:
2908 case snd_soc_dapm_out_drv:
2909 case snd_soc_dapm_input:
2910 case snd_soc_dapm_output:
2911 case snd_soc_dapm_micbias:
2912 case snd_soc_dapm_spk:
2913 case snd_soc_dapm_hp:
2914 case snd_soc_dapm_mic:
2915 case snd_soc_dapm_line:
2916 case snd_soc_dapm_dai_link:
2917 w->power_check = dapm_generic_check_power;
2919 case snd_soc_dapm_supply:
2920 case snd_soc_dapm_regulator_supply:
2921 w->power_check = dapm_supply_check_power;
2923 case snd_soc_dapm_dai:
2924 w->power_check = dapm_dai_check_power;
2927 w->power_check = dapm_always_on_check_power;
2933 w->codec = dapm->codec;
2934 w->platform = dapm->platform;
2935 INIT_LIST_HEAD(&w->sources);
2936 INIT_LIST_HEAD(&w->sinks);
2937 INIT_LIST_HEAD(&w->list);
2938 INIT_LIST_HEAD(&w->dirty);
2939 list_add(&w->list, &dapm->card->widgets);
2941 /* machine layer set ups unconnected pins and insertions */
2947 * snd_soc_dapm_new_controls - create new dapm controls
2948 * @dapm: DAPM context
2949 * @widget: widget array
2950 * @num: number of widgets
2952 * Creates new DAPM controls based upon the templates.
2954 * Returns 0 for success else error.
2956 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2957 const struct snd_soc_dapm_widget *widget,
2960 struct snd_soc_dapm_widget *w;
2964 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2965 for (i = 0; i < num; i++) {
2966 w = snd_soc_dapm_new_control(dapm, widget);
2969 "ASoC: Failed to create DAPM control %s\n",
2976 mutex_unlock(&dapm->card->dapm_mutex);
2979 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2981 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
2982 struct snd_kcontrol *kcontrol, int event)
2984 struct snd_soc_dapm_path *source_p, *sink_p;
2985 struct snd_soc_dai *source, *sink;
2986 const struct snd_soc_pcm_stream *config = w->params;
2987 struct snd_pcm_substream substream;
2988 struct snd_pcm_hw_params params;
2993 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks));
2995 /* We only support a single source and sink, pick the first */
2996 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
2998 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
3001 BUG_ON(!source_p || !sink_p);
3002 BUG_ON(!sink_p->source || !source_p->sink);
3003 BUG_ON(!source_p->source || !sink_p->sink);
3005 source = source_p->source->priv;
3006 sink = sink_p->sink->priv;
3008 /* Be a little careful as we don't want to overflow the mask array */
3009 if (config->formats) {
3010 fmt = ffs(config->formats) - 1;
3012 dev_warn(w->dapm->dev, "Invalid format %llx specified\n",
3017 /* Currently very limited parameter selection */
3018 memset(¶ms, 0, sizeof(params));
3019 snd_mask_set(hw_param_mask(¶ms, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
3021 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->min =
3023 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->max =
3026 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS)->min
3027 = config->channels_min;
3028 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS)->max
3029 = config->channels_max;
3031 memset(&substream, 0, sizeof(substream));
3034 case SND_SOC_DAPM_PRE_PMU:
3035 if (source->driver->ops && source->driver->ops->hw_params) {
3036 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3037 ret = source->driver->ops->hw_params(&substream,
3040 dev_err(source->dev,
3041 "hw_params() failed: %d\n", ret);
3046 if (sink->driver->ops && sink->driver->ops->hw_params) {
3047 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3048 ret = sink->driver->ops->hw_params(&substream, ¶ms,
3052 "hw_params() failed: %d\n", ret);
3058 case SND_SOC_DAPM_POST_PMU:
3059 ret = snd_soc_dai_digital_mute(sink, 0);
3060 if (ret != 0 && ret != -ENOTSUPP)
3061 dev_warn(sink->dev, "Failed to unmute: %d\n", ret);
3064 case SND_SOC_DAPM_PRE_PMD:
3065 ret = snd_soc_dai_digital_mute(sink, 1);
3066 if (ret != 0 && ret != -ENOTSUPP)
3067 dev_warn(sink->dev, "Failed to mute: %d\n", ret);
3078 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3079 const struct snd_soc_pcm_stream *params,
3080 struct snd_soc_dapm_widget *source,
3081 struct snd_soc_dapm_widget *sink)
3083 struct snd_soc_dapm_route routes[2];
3084 struct snd_soc_dapm_widget template;
3085 struct snd_soc_dapm_widget *w;
3089 len = strlen(source->name) + strlen(sink->name) + 2;
3090 link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
3093 snprintf(link_name, len, "%s-%s", source->name, sink->name);
3095 memset(&template, 0, sizeof(template));
3096 template.reg = SND_SOC_NOPM;
3097 template.id = snd_soc_dapm_dai_link;
3098 template.name = link_name;
3099 template.event = snd_soc_dai_link_event;
3100 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3101 SND_SOC_DAPM_PRE_PMD;
3103 dev_dbg(card->dev, "adding %s widget\n", link_name);
3105 w = snd_soc_dapm_new_control(&card->dapm, &template);
3107 dev_err(card->dev, "Failed to create %s widget\n",
3114 memset(&routes, 0, sizeof(routes));
3116 routes[0].source = source->name;
3117 routes[0].sink = link_name;
3118 routes[1].source = link_name;
3119 routes[1].sink = sink->name;
3121 return snd_soc_dapm_add_routes(&card->dapm, routes,
3122 ARRAY_SIZE(routes));
3125 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3126 struct snd_soc_dai *dai)
3128 struct snd_soc_dapm_widget template;
3129 struct snd_soc_dapm_widget *w;
3131 WARN_ON(dapm->dev != dai->dev);
3133 memset(&template, 0, sizeof(template));
3134 template.reg = SND_SOC_NOPM;
3136 if (dai->driver->playback.stream_name) {
3137 template.id = snd_soc_dapm_dai;
3138 template.name = dai->driver->playback.stream_name;
3139 template.sname = dai->driver->playback.stream_name;
3141 dev_dbg(dai->dev, "adding %s widget\n",
3144 w = snd_soc_dapm_new_control(dapm, &template);
3146 dev_err(dapm->dev, "Failed to create %s widget\n",
3147 dai->driver->playback.stream_name);
3151 dai->playback_widget = w;
3154 if (dai->driver->capture.stream_name) {
3155 template.id = snd_soc_dapm_dai;
3156 template.name = dai->driver->capture.stream_name;
3157 template.sname = dai->driver->capture.stream_name;
3159 dev_dbg(dai->dev, "adding %s widget\n",
3162 w = snd_soc_dapm_new_control(dapm, &template);
3164 dev_err(dapm->dev, "Failed to create %s widget\n",
3165 dai->driver->capture.stream_name);
3169 dai->capture_widget = w;
3175 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3177 struct snd_soc_dapm_widget *dai_w, *w;
3178 struct snd_soc_dai *dai;
3179 struct snd_soc_dapm_route r;
3181 memset(&r, 0, sizeof(r));
3183 /* For each DAI widget... */
3184 list_for_each_entry(dai_w, &card->widgets, list) {
3185 if (dai_w->id != snd_soc_dapm_dai)
3190 /* ...find all widgets with the same stream and link them */
3191 list_for_each_entry(w, &card->widgets, list) {
3192 if (w->dapm != dai_w->dapm)
3195 if (w->id == snd_soc_dapm_dai)
3201 if (dai->driver->playback.stream_name &&
3203 dai->driver->playback.stream_name)) {
3204 r.source = dai->playback_widget->name;
3206 dev_dbg(dai->dev, "%s -> %s\n",
3209 snd_soc_dapm_add_route(w->dapm, &r);
3212 if (dai->driver->capture.stream_name &&
3214 dai->driver->capture.stream_name)) {
3216 r.sink = dai->capture_widget->name;
3217 dev_dbg(dai->dev, "%s -> %s\n",
3220 snd_soc_dapm_add_route(w->dapm, &r);
3228 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3232 struct snd_soc_dapm_widget *w_cpu, *w_codec;
3233 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3234 struct snd_soc_dai *codec_dai = rtd->codec_dai;
3236 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
3237 w_cpu = cpu_dai->playback_widget;
3238 w_codec = codec_dai->playback_widget;
3240 w_cpu = cpu_dai->capture_widget;
3241 w_codec = codec_dai->capture_widget;
3246 dapm_mark_dirty(w_cpu, "stream event");
3249 case SND_SOC_DAPM_STREAM_START:
3252 case SND_SOC_DAPM_STREAM_STOP:
3255 case SND_SOC_DAPM_STREAM_SUSPEND:
3256 case SND_SOC_DAPM_STREAM_RESUME:
3257 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3258 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3265 dapm_mark_dirty(w_codec, "stream event");
3268 case SND_SOC_DAPM_STREAM_START:
3269 w_codec->active = 1;
3271 case SND_SOC_DAPM_STREAM_STOP:
3272 w_codec->active = 0;
3274 case SND_SOC_DAPM_STREAM_SUSPEND:
3275 case SND_SOC_DAPM_STREAM_RESUME:
3276 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3277 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3282 dapm_power_widgets(&rtd->card->dapm, event);
3286 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3287 * @rtd: PCM runtime data
3288 * @stream: stream name
3289 * @event: stream event
3291 * Sends a stream event to the dapm core. The core then makes any
3292 * necessary widget power changes.
3294 * Returns 0 for success else error.
3296 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3299 struct snd_soc_card *card = rtd->card;
3301 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3302 soc_dapm_stream_event(rtd, stream, event);
3303 mutex_unlock(&card->dapm_mutex);
3307 * snd_soc_dapm_enable_pin - enable pin.
3308 * @dapm: DAPM context
3311 * Enables input/output pin and its parents or children widgets iff there is
3312 * a valid audio route and active audio stream.
3313 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3314 * do any widget power switching.
3316 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3318 return snd_soc_dapm_set_pin(dapm, pin, 1);
3320 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3323 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3324 * @dapm: DAPM context
3327 * Enables input/output pin regardless of any other state. This is
3328 * intended for use with microphone bias supplies used in microphone
3331 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3332 * do any widget power switching.
3334 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3337 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3340 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3344 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
3347 dapm_mark_dirty(w, "force enable");
3351 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
3354 * snd_soc_dapm_disable_pin - disable pin.
3355 * @dapm: DAPM context
3358 * Disables input/output pin and its parents or children widgets.
3359 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3360 * do any widget power switching.
3362 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
3365 return snd_soc_dapm_set_pin(dapm, pin, 0);
3367 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3370 * snd_soc_dapm_nc_pin - permanently disable pin.
3371 * @dapm: DAPM context
3374 * Marks the specified pin as being not connected, disabling it along
3375 * any parent or child widgets. At present this is identical to
3376 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3377 * additional things such as disabling controls which only affect
3378 * paths through the pin.
3380 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3381 * do any widget power switching.
3383 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3385 return snd_soc_dapm_set_pin(dapm, pin, 0);
3387 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
3390 * snd_soc_dapm_get_pin_status - get audio pin status
3391 * @dapm: DAPM context
3392 * @pin: audio signal pin endpoint (or start point)
3394 * Get audio pin status - connected or disconnected.
3396 * Returns 1 for connected otherwise 0.
3398 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
3401 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3404 return w->connected;
3408 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
3411 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3412 * @dapm: DAPM context
3413 * @pin: audio signal pin endpoint (or start point)
3415 * Mark the given endpoint or pin as ignoring suspend. When the
3416 * system is disabled a path between two endpoints flagged as ignoring
3417 * suspend will not be disabled. The path must already be enabled via
3418 * normal means at suspend time, it will not be turned on if it was not
3421 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
3424 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
3427 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3431 w->ignore_suspend = 1;
3435 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3437 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
3438 struct snd_soc_dapm_widget *w)
3440 struct snd_soc_dapm_path *p;
3442 list_for_each_entry(p, &card->paths, list) {
3443 if ((p->source == w) || (p->sink == w)) {
3445 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3446 p->source->name, p->source->id, p->source->dapm,
3447 p->sink->name, p->sink->id, p->sink->dapm);
3449 /* Connected to something other than the codec */
3450 if (p->source->dapm != p->sink->dapm)
3453 * Loopback connection from codec external pin to
3454 * codec external pin
3456 if (p->sink->id == snd_soc_dapm_input) {
3457 switch (p->source->id) {
3458 case snd_soc_dapm_output:
3459 case snd_soc_dapm_micbias:
3472 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3473 * @codec: The codec whose pins should be processed
3475 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3476 * which are unused. Pins are used if they are connected externally to the
3477 * codec, whether that be to some other device, or a loop-back connection to
3480 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
3482 struct snd_soc_card *card = codec->card;
3483 struct snd_soc_dapm_context *dapm = &codec->dapm;
3484 struct snd_soc_dapm_widget *w;
3486 dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n",
3487 &card->dapm, &codec->dapm);
3489 list_for_each_entry(w, &card->widgets, list) {
3490 if (w->dapm != dapm)
3493 case snd_soc_dapm_input:
3494 case snd_soc_dapm_output:
3495 case snd_soc_dapm_micbias:
3496 dev_dbg(codec->dev, "Auto NC: Checking widget %s\n",
3498 if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
3500 "... Not in map; disabling\n");
3501 snd_soc_dapm_nc_pin(dapm, w->name);
3511 * snd_soc_dapm_free - free dapm resources
3512 * @dapm: DAPM context
3514 * Free all dapm widgets and resources.
3516 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
3518 snd_soc_dapm_sys_remove(dapm->dev);
3519 dapm_debugfs_cleanup(dapm);
3520 dapm_free_widgets(dapm);
3521 list_del(&dapm->list);
3523 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
3525 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
3527 struct snd_soc_dapm_widget *w;
3528 LIST_HEAD(down_list);
3531 list_for_each_entry(w, &dapm->card->widgets, list) {
3532 if (w->dapm != dapm)
3535 dapm_seq_insert(w, &down_list, false);
3541 /* If there were no widgets to power down we're already in
3545 if (dapm->bias_level == SND_SOC_BIAS_ON)
3546 snd_soc_dapm_set_bias_level(dapm,
3547 SND_SOC_BIAS_PREPARE);
3548 dapm_seq_run(dapm, &down_list, 0, false);
3549 if (dapm->bias_level == SND_SOC_BIAS_PREPARE)
3550 snd_soc_dapm_set_bias_level(dapm,
3551 SND_SOC_BIAS_STANDBY);
3556 * snd_soc_dapm_shutdown - callback for system shutdown
3558 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
3560 struct snd_soc_codec *codec;
3562 list_for_each_entry(codec, &card->codec_dev_list, list) {
3563 soc_dapm_shutdown_codec(&codec->dapm);
3564 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
3565 snd_soc_dapm_set_bias_level(&codec->dapm,
3570 /* Module information */
3571 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3572 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3573 MODULE_LICENSE("GPL");