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_line] = 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_line] = 2,
81 [snd_soc_dapm_out_drv] = 2,
82 [snd_soc_dapm_pga] = 4,
83 [snd_soc_dapm_mixer_named_ctl] = 5,
84 [snd_soc_dapm_mixer] = 5,
85 [snd_soc_dapm_dac] = 6,
86 [snd_soc_dapm_mic] = 7,
87 [snd_soc_dapm_micbias] = 8,
88 [snd_soc_dapm_mux] = 9,
89 [snd_soc_dapm_virt_mux] = 9,
90 [snd_soc_dapm_value_mux] = 9,
91 [snd_soc_dapm_aif_in] = 10,
92 [snd_soc_dapm_aif_out] = 10,
93 [snd_soc_dapm_dai] = 10,
94 [snd_soc_dapm_dai_link] = 11,
95 [snd_soc_dapm_regulator_supply] = 12,
96 [snd_soc_dapm_supply] = 12,
97 [snd_soc_dapm_post] = 13,
100 static void pop_wait(u32 pop_time)
103 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
106 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
114 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
119 vsnprintf(buf, PAGE_SIZE, fmt, args);
120 dev_info(dev, "%s", buf);
126 static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
128 return !list_empty(&w->dirty);
131 void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
133 if (!dapm_dirty_widget(w)) {
134 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
136 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
139 EXPORT_SYMBOL_GPL(dapm_mark_dirty);
141 /* create a new dapm widget */
142 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
143 const struct snd_soc_dapm_widget *_widget)
145 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
148 /* get snd_card from DAPM context */
149 static inline struct snd_card *dapm_get_snd_card(
150 struct snd_soc_dapm_context *dapm)
153 return dapm->codec->card->snd_card;
154 else if (dapm->platform)
155 return dapm->platform->card->snd_card;
163 /* get soc_card from DAPM context */
164 static inline struct snd_soc_card *dapm_get_soc_card(
165 struct snd_soc_dapm_context *dapm)
168 return dapm->codec->card;
169 else if (dapm->platform)
170 return dapm->platform->card;
178 static void dapm_reset(struct snd_soc_card *card)
180 struct snd_soc_dapm_widget *w;
182 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
184 list_for_each_entry(w, &card->widgets, list) {
185 w->power_checked = false;
191 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
194 return snd_soc_read(w->codec, reg);
195 else if (w->platform)
196 return snd_soc_platform_read(w->platform, reg);
198 dev_err(w->dapm->dev, "no valid widget read method\n");
202 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
205 return snd_soc_write(w->codec, reg, val);
206 else if (w->platform)
207 return snd_soc_platform_write(w->platform, reg, val);
209 dev_err(w->dapm->dev, "no valid widget write method\n");
213 static inline void soc_widget_lock(struct snd_soc_dapm_widget *w)
215 if (w->codec && !w->codec->using_regmap)
216 mutex_lock(&w->codec->mutex);
217 else if (w->platform)
218 mutex_lock(&w->platform->mutex);
221 static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w)
223 if (w->codec && !w->codec->using_regmap)
224 mutex_unlock(&w->codec->mutex);
225 else if (w->platform)
226 mutex_unlock(&w->platform->mutex);
229 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
230 unsigned short reg, unsigned int mask, unsigned int value)
233 unsigned int old, new;
236 if (w->codec && w->codec->using_regmap) {
237 ret = regmap_update_bits_check(w->codec->control_data,
238 reg, mask, value, &change);
243 ret = soc_widget_read(w, reg);
245 soc_widget_unlock(w);
250 new = (old & ~mask) | (value & mask);
253 ret = soc_widget_write(w, reg, new);
255 soc_widget_unlock(w);
259 soc_widget_unlock(w);
266 * snd_soc_dapm_set_bias_level - set the bias level for the system
267 * @dapm: DAPM context
268 * @level: level to configure
270 * Configure the bias (power) levels for the SoC audio device.
272 * Returns 0 for success else error.
274 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
275 enum snd_soc_bias_level level)
277 struct snd_soc_card *card = dapm->card;
280 trace_snd_soc_bias_level_start(card, level);
282 if (card && card->set_bias_level)
283 ret = card->set_bias_level(card, dapm, level);
288 if (dapm->codec->driver->set_bias_level)
289 ret = dapm->codec->driver->set_bias_level(dapm->codec,
292 dapm->bias_level = level;
297 if (card && card->set_bias_level_post)
298 ret = card->set_bias_level_post(card, dapm, level);
300 trace_snd_soc_bias_level_done(card, level);
305 /* set up initial codec paths */
306 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
307 struct snd_soc_dapm_path *p, int i)
310 case snd_soc_dapm_switch:
311 case snd_soc_dapm_mixer:
312 case snd_soc_dapm_mixer_named_ctl: {
314 struct soc_mixer_control *mc = (struct soc_mixer_control *)
315 w->kcontrol_news[i].private_value;
316 unsigned int reg = mc->reg;
317 unsigned int shift = mc->shift;
319 unsigned int mask = (1 << fls(max)) - 1;
320 unsigned int invert = mc->invert;
322 val = soc_widget_read(w, reg);
323 val = (val >> shift) & mask;
325 if ((invert && !val) || (!invert && val))
331 case snd_soc_dapm_mux: {
332 struct soc_enum *e = (struct soc_enum *)
333 w->kcontrol_news[i].private_value;
334 int val, item, bitmask;
336 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
338 val = soc_widget_read(w, e->reg);
339 item = (val >> e->shift_l) & (bitmask - 1);
342 for (i = 0; i < e->max; i++) {
343 if (!(strcmp(p->name, e->texts[i])) && item == i)
348 case snd_soc_dapm_virt_mux: {
349 struct soc_enum *e = (struct soc_enum *)
350 w->kcontrol_news[i].private_value;
353 /* since a virtual mux has no backing registers to
354 * decide which path to connect, it will try to match
355 * with the first enumeration. This is to ensure
356 * that the default mux choice (the first) will be
357 * correctly powered up during initialization.
359 if (!strcmp(p->name, e->texts[0]))
363 case snd_soc_dapm_value_mux: {
364 struct soc_enum *e = (struct soc_enum *)
365 w->kcontrol_news[i].private_value;
368 val = soc_widget_read(w, e->reg);
369 val = (val >> e->shift_l) & e->mask;
370 for (item = 0; item < e->max; item++) {
371 if (val == e->values[item])
376 for (i = 0; i < e->max; i++) {
377 if (!(strcmp(p->name, e->texts[i])) && item == i)
382 /* does not affect routing - always connected */
383 case snd_soc_dapm_pga:
384 case snd_soc_dapm_out_drv:
385 case snd_soc_dapm_output:
386 case snd_soc_dapm_adc:
387 case snd_soc_dapm_input:
388 case snd_soc_dapm_siggen:
389 case snd_soc_dapm_dac:
390 case snd_soc_dapm_micbias:
391 case snd_soc_dapm_vmid:
392 case snd_soc_dapm_supply:
393 case snd_soc_dapm_regulator_supply:
394 case snd_soc_dapm_aif_in:
395 case snd_soc_dapm_aif_out:
396 case snd_soc_dapm_dai:
397 case snd_soc_dapm_hp:
398 case snd_soc_dapm_mic:
399 case snd_soc_dapm_spk:
400 case snd_soc_dapm_line:
401 case snd_soc_dapm_dai_link:
404 /* does affect routing - dynamically connected */
405 case snd_soc_dapm_pre:
406 case snd_soc_dapm_post:
412 /* connect mux widget to its interconnecting audio paths */
413 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
414 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
415 struct snd_soc_dapm_path *path, const char *control_name,
416 const struct snd_kcontrol_new *kcontrol)
418 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
421 for (i = 0; i < e->max; i++) {
422 if (!(strcmp(control_name, e->texts[i]))) {
423 list_add(&path->list, &dapm->card->paths);
424 list_add(&path->list_sink, &dest->sources);
425 list_add(&path->list_source, &src->sinks);
426 path->name = (char*)e->texts[i];
427 dapm_set_path_status(dest, path, 0);
435 /* connect mixer widget to its interconnecting audio paths */
436 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
437 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
438 struct snd_soc_dapm_path *path, const char *control_name)
442 /* search for mixer kcontrol */
443 for (i = 0; i < dest->num_kcontrols; i++) {
444 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
445 list_add(&path->list, &dapm->card->paths);
446 list_add(&path->list_sink, &dest->sources);
447 list_add(&path->list_source, &src->sinks);
448 path->name = dest->kcontrol_news[i].name;
449 dapm_set_path_status(dest, path, i);
456 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
457 struct snd_soc_dapm_widget *kcontrolw,
458 const struct snd_kcontrol_new *kcontrol_new,
459 struct snd_kcontrol **kcontrol)
461 struct snd_soc_dapm_widget *w;
466 list_for_each_entry(w, &dapm->card->widgets, list) {
467 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
469 for (i = 0; i < w->num_kcontrols; i++) {
470 if (&w->kcontrol_news[i] == kcontrol_new) {
472 *kcontrol = w->kcontrols[i];
481 /* create new dapm mixer control */
482 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
484 struct snd_soc_dapm_context *dapm = w->dapm;
486 size_t name_len, prefix_len;
487 struct snd_soc_dapm_path *path;
488 struct snd_card *card = dapm->card->snd_card;
490 struct snd_soc_dapm_widget_list *wlist;
494 prefix = dapm->codec->name_prefix;
499 prefix_len = strlen(prefix) + 1;
504 for (i = 0; i < w->num_kcontrols; i++) {
507 list_for_each_entry(path, &w->sources, list_sink) {
509 /* mixer/mux paths name must match control name */
510 if (path->name != (char *)w->kcontrol_news[i].name)
513 if (w->kcontrols[i]) {
514 path->kcontrol = w->kcontrols[i];
518 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
519 sizeof(struct snd_soc_dapm_widget *),
520 wlist = kzalloc(wlistsize, GFP_KERNEL);
523 "asoc: can't allocate widget list for %s\n",
527 wlist->num_widgets = 1;
528 wlist->widgets[0] = w;
530 /* add dapm control with long name.
531 * for dapm_mixer this is the concatenation of the
532 * mixer and kcontrol name.
533 * for dapm_mixer_named_ctl this is simply the
536 name_len = strlen(w->kcontrol_news[i].name) + 1;
537 if (w->id != snd_soc_dapm_mixer_named_ctl)
538 name_len += 1 + strlen(w->name);
540 path->long_name = kmalloc(name_len, GFP_KERNEL);
542 if (path->long_name == NULL) {
549 /* The control will get a prefix from
550 * the control creation process but
551 * we're also using the same prefix
552 * for widgets so cut the prefix off
553 * the front of the widget name.
555 snprintf((char *)path->long_name, name_len,
556 "%s %s", w->name + prefix_len,
557 w->kcontrol_news[i].name);
559 case snd_soc_dapm_mixer_named_ctl:
560 snprintf((char *)path->long_name, name_len,
561 "%s", w->kcontrol_news[i].name);
565 ((char *)path->long_name)[name_len - 1] = '\0';
567 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
568 wlist, path->long_name,
570 ret = snd_ctl_add(card, path->kcontrol);
573 "asoc: failed to add dapm kcontrol %s: %d\n",
574 path->long_name, ret);
576 kfree(path->long_name);
577 path->long_name = NULL;
580 w->kcontrols[i] = path->kcontrol;
586 /* create new dapm mux control */
587 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
589 struct snd_soc_dapm_context *dapm = w->dapm;
590 struct snd_soc_dapm_path *path = NULL;
591 struct snd_kcontrol *kcontrol;
592 struct snd_card *card = dapm->card->snd_card;
596 struct snd_soc_dapm_widget_list *wlist;
597 int shared, wlistentries;
601 if (w->num_kcontrols != 1) {
603 "asoc: mux %s has incorrect number of controls\n",
608 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
611 wlist = kcontrol->private_data;
612 wlistentries = wlist->num_widgets + 1;
617 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
618 wlistentries * sizeof(struct snd_soc_dapm_widget *),
619 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
622 "asoc: can't allocate widget list for %s\n", w->name);
625 wlist->num_widgets = wlistentries;
626 wlist->widgets[wlistentries - 1] = w;
630 prefix = dapm->codec->name_prefix;
635 name = w->kcontrol_news[0].name;
640 prefix_len = strlen(prefix) + 1;
646 * The control will get a prefix from the control creation
647 * process but we're also using the same prefix for widgets so
648 * cut the prefix off the front of the widget name.
650 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
651 name + prefix_len, prefix);
652 ret = snd_ctl_add(card, kcontrol);
654 dev_err(dapm->dev, "failed to add kcontrol %s: %d\n",
661 kcontrol->private_data = wlist;
663 w->kcontrols[0] = kcontrol;
665 list_for_each_entry(path, &w->sources, list_sink)
666 path->kcontrol = kcontrol;
671 /* create new dapm volume control */
672 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
674 if (w->num_kcontrols)
675 dev_err(w->dapm->dev,
676 "asoc: PGA controls not supported: '%s'\n", w->name);
681 /* reset 'walked' bit for each dapm path */
682 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
684 struct snd_soc_dapm_path *p;
686 list_for_each_entry(p, &dapm->card->paths, list)
690 /* We implement power down on suspend by checking the power state of
691 * the ALSA card - when we are suspending the ALSA state for the card
694 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
696 int level = snd_power_get_state(widget->dapm->card->snd_card);
699 case SNDRV_CTL_POWER_D3hot:
700 case SNDRV_CTL_POWER_D3cold:
701 if (widget->ignore_suspend)
702 dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
704 return widget->ignore_suspend;
710 /* add widget to list if it's not already in the list */
711 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list,
712 struct snd_soc_dapm_widget *w)
714 struct snd_soc_dapm_widget_list *wlist;
715 int wlistsize, wlistentries, i;
722 /* is this widget already in the list */
723 for (i = 0; i < wlist->num_widgets; i++) {
724 if (wlist->widgets[i] == w)
728 /* allocate some new space */
729 wlistentries = wlist->num_widgets + 1;
730 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
731 wlistentries * sizeof(struct snd_soc_dapm_widget *);
732 *list = krealloc(wlist, wlistsize, GFP_KERNEL);
734 dev_err(w->dapm->dev, "can't allocate widget list for %s\n",
740 /* insert the widget */
741 dev_dbg(w->dapm->dev, "added %s in widget list pos %d\n",
742 w->name, wlist->num_widgets);
744 wlist->widgets[wlist->num_widgets] = w;
745 wlist->num_widgets++;
750 * Recursively check for a completed path to an active or physically connected
751 * output widget. Returns number of complete paths.
753 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
754 struct snd_soc_dapm_widget_list **list)
756 struct snd_soc_dapm_path *path;
759 if (widget->outputs >= 0)
760 return widget->outputs;
762 DAPM_UPDATE_STAT(widget, path_checks);
764 switch (widget->id) {
765 case snd_soc_dapm_supply:
766 case snd_soc_dapm_regulator_supply:
772 switch (widget->id) {
773 case snd_soc_dapm_adc:
774 case snd_soc_dapm_aif_out:
775 case snd_soc_dapm_dai:
776 if (widget->active) {
777 widget->outputs = snd_soc_dapm_suspend_check(widget);
778 return widget->outputs;
784 if (widget->connected) {
785 /* connected pin ? */
786 if (widget->id == snd_soc_dapm_output && !widget->ext) {
787 widget->outputs = snd_soc_dapm_suspend_check(widget);
788 return widget->outputs;
791 /* connected jack or spk ? */
792 if (widget->id == snd_soc_dapm_hp ||
793 widget->id == snd_soc_dapm_spk ||
794 (widget->id == snd_soc_dapm_line &&
795 !list_empty(&widget->sources))) {
796 widget->outputs = snd_soc_dapm_suspend_check(widget);
797 return widget->outputs;
801 list_for_each_entry(path, &widget->sinks, list_source) {
802 DAPM_UPDATE_STAT(widget, neighbour_checks);
810 trace_snd_soc_dapm_output_path(widget, path);
812 if (path->sink && path->connect) {
815 /* do we need to add this widget to the list ? */
818 err = dapm_list_add_widget(list, path->sink);
820 dev_err(widget->dapm->dev, "could not add widget %s\n",
826 con += is_connected_output_ep(path->sink, list);
830 widget->outputs = con;
836 * Recursively check for a completed path to an active or physically connected
837 * input widget. Returns number of complete paths.
839 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
840 struct snd_soc_dapm_widget_list **list)
842 struct snd_soc_dapm_path *path;
845 if (widget->inputs >= 0)
846 return widget->inputs;
848 DAPM_UPDATE_STAT(widget, path_checks);
850 switch (widget->id) {
851 case snd_soc_dapm_supply:
852 case snd_soc_dapm_regulator_supply:
858 /* active stream ? */
859 switch (widget->id) {
860 case snd_soc_dapm_dac:
861 case snd_soc_dapm_aif_in:
862 case snd_soc_dapm_dai:
863 if (widget->active) {
864 widget->inputs = snd_soc_dapm_suspend_check(widget);
865 return widget->inputs;
871 if (widget->connected) {
872 /* connected pin ? */
873 if (widget->id == snd_soc_dapm_input && !widget->ext) {
874 widget->inputs = snd_soc_dapm_suspend_check(widget);
875 return widget->inputs;
878 /* connected VMID/Bias for lower pops */
879 if (widget->id == snd_soc_dapm_vmid) {
880 widget->inputs = snd_soc_dapm_suspend_check(widget);
881 return widget->inputs;
884 /* connected jack ? */
885 if (widget->id == snd_soc_dapm_mic ||
886 (widget->id == snd_soc_dapm_line &&
887 !list_empty(&widget->sinks))) {
888 widget->inputs = snd_soc_dapm_suspend_check(widget);
889 return widget->inputs;
892 /* signal generator */
893 if (widget->id == snd_soc_dapm_siggen) {
894 widget->inputs = snd_soc_dapm_suspend_check(widget);
895 return widget->inputs;
899 list_for_each_entry(path, &widget->sources, list_sink) {
900 DAPM_UPDATE_STAT(widget, neighbour_checks);
908 trace_snd_soc_dapm_input_path(widget, path);
910 if (path->source && path->connect) {
913 /* do we need to add this widget to the list ? */
916 err = dapm_list_add_widget(list, path->source);
918 dev_err(widget->dapm->dev, "could not add widget %s\n",
924 con += is_connected_input_ep(path->source, list);
928 widget->inputs = con;
934 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
936 * @stream: stream direction.
937 * @list: list of active widgets for this stream.
939 * Queries DAPM graph as to whether an valid audio stream path exists for
940 * the initial stream specified by name. This takes into account
941 * current mixer and mux kcontrol settings. Creates list of valid widgets.
943 * Returns the number of valid paths or negative error.
945 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
946 struct snd_soc_dapm_widget_list **list)
948 struct snd_soc_card *card = dai->card;
951 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
954 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
955 paths = is_connected_output_ep(dai->playback_widget, list);
957 paths = is_connected_input_ep(dai->capture_widget, list);
959 trace_snd_soc_dapm_connected(paths, stream);
960 dapm_clear_walk(&card->dapm);
961 mutex_unlock(&card->dapm_mutex);
967 * Handler for generic register modifier widget.
969 int dapm_reg_event(struct snd_soc_dapm_widget *w,
970 struct snd_kcontrol *kcontrol, int event)
974 if (SND_SOC_DAPM_EVENT_ON(event))
979 soc_widget_update_bits_locked(w, -(w->reg + 1),
980 w->mask << w->shift, val << w->shift);
984 EXPORT_SYMBOL_GPL(dapm_reg_event);
987 * Handler for regulator supply widget.
989 int dapm_regulator_event(struct snd_soc_dapm_widget *w,
990 struct snd_kcontrol *kcontrol, int event)
992 if (SND_SOC_DAPM_EVENT_ON(event))
993 return regulator_enable(w->regulator);
995 return regulator_disable_deferred(w->regulator, w->shift);
997 EXPORT_SYMBOL_GPL(dapm_regulator_event);
999 static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
1001 if (w->power_checked)
1002 return w->new_power;
1007 w->new_power = w->power_check(w);
1009 w->power_checked = true;
1011 return w->new_power;
1014 /* Generic check to see if a widget should be powered.
1016 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
1020 DAPM_UPDATE_STAT(w, power_checks);
1022 in = is_connected_input_ep(w, NULL);
1023 dapm_clear_walk(w->dapm);
1024 out = is_connected_output_ep(w, NULL);
1025 dapm_clear_walk(w->dapm);
1026 return out != 0 && in != 0;
1029 static int dapm_dai_check_power(struct snd_soc_dapm_widget *w)
1031 DAPM_UPDATE_STAT(w, power_checks);
1036 return dapm_generic_check_power(w);
1039 /* Check to see if an ADC has power */
1040 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
1044 DAPM_UPDATE_STAT(w, power_checks);
1047 in = is_connected_input_ep(w, NULL);
1048 dapm_clear_walk(w->dapm);
1051 return dapm_generic_check_power(w);
1055 /* Check to see if a DAC has power */
1056 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
1060 DAPM_UPDATE_STAT(w, power_checks);
1063 out = is_connected_output_ep(w, NULL);
1064 dapm_clear_walk(w->dapm);
1067 return dapm_generic_check_power(w);
1071 /* Check to see if a power supply is needed */
1072 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1074 struct snd_soc_dapm_path *path;
1076 DAPM_UPDATE_STAT(w, power_checks);
1078 /* Check if one of our outputs is connected */
1079 list_for_each_entry(path, &w->sinks, list_source) {
1080 DAPM_UPDATE_STAT(w, neighbour_checks);
1085 if (path->connected &&
1086 !path->connected(path->source, path->sink))
1092 if (dapm_widget_power_check(path->sink))
1096 dapm_clear_walk(w->dapm);
1101 static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
1106 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
1107 struct snd_soc_dapm_widget *b,
1115 sort = dapm_down_seq;
1117 if (sort[a->id] != sort[b->id])
1118 return sort[a->id] - sort[b->id];
1119 if (a->subseq != b->subseq) {
1121 return a->subseq - b->subseq;
1123 return b->subseq - a->subseq;
1125 if (a->reg != b->reg)
1126 return a->reg - b->reg;
1127 if (a->dapm != b->dapm)
1128 return (unsigned long)a->dapm - (unsigned long)b->dapm;
1133 /* Insert a widget in order into a DAPM power sequence. */
1134 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
1135 struct list_head *list,
1138 struct snd_soc_dapm_widget *w;
1140 list_for_each_entry(w, list, power_list)
1141 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
1142 list_add_tail(&new_widget->power_list, &w->power_list);
1146 list_add_tail(&new_widget->power_list, list);
1149 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
1150 struct snd_soc_dapm_widget *w, int event)
1152 struct snd_soc_card *card = dapm->card;
1153 const char *ev_name;
1157 case SND_SOC_DAPM_PRE_PMU:
1158 ev_name = "PRE_PMU";
1161 case SND_SOC_DAPM_POST_PMU:
1162 ev_name = "POST_PMU";
1165 case SND_SOC_DAPM_PRE_PMD:
1166 ev_name = "PRE_PMD";
1169 case SND_SOC_DAPM_POST_PMD:
1170 ev_name = "POST_PMD";
1178 if (w->power != power)
1181 if (w->event && (w->event_flags & event)) {
1182 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
1184 trace_snd_soc_dapm_widget_event_start(w, event);
1185 ret = w->event(w, NULL, event);
1186 trace_snd_soc_dapm_widget_event_done(w, event);
1188 pr_err("%s: %s event failed: %d\n",
1189 ev_name, w->name, ret);
1193 /* Apply the coalesced changes from a DAPM sequence */
1194 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
1195 struct list_head *pending)
1197 struct snd_soc_card *card = dapm->card;
1198 struct snd_soc_dapm_widget *w;
1200 unsigned int value = 0;
1201 unsigned int mask = 0;
1202 unsigned int cur_mask;
1204 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
1207 list_for_each_entry(w, pending, power_list) {
1208 cur_mask = 1 << w->shift;
1209 BUG_ON(reg != w->reg);
1220 pop_dbg(dapm->dev, card->pop_time,
1221 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1222 w->name, reg, value, mask);
1224 /* Check for events */
1225 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
1226 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
1230 /* Any widget will do, they should all be updating the
1233 w = list_first_entry(pending, struct snd_soc_dapm_widget,
1236 pop_dbg(dapm->dev, card->pop_time,
1237 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1238 value, mask, reg, card->pop_time);
1239 pop_wait(card->pop_time);
1240 soc_widget_update_bits_locked(w, reg, mask, value);
1243 list_for_each_entry(w, pending, power_list) {
1244 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
1245 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
1249 /* Apply a DAPM power sequence.
1251 * We walk over a pre-sorted list of widgets to apply power to. In
1252 * order to minimise the number of writes to the device required
1253 * multiple widgets will be updated in a single write where possible.
1254 * Currently anything that requires more than a single write is not
1257 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1258 struct list_head *list, int event, bool power_up)
1260 struct snd_soc_dapm_widget *w, *n;
1263 int cur_subseq = -1;
1264 int cur_reg = SND_SOC_NOPM;
1265 struct snd_soc_dapm_context *cur_dapm = NULL;
1272 sort = dapm_down_seq;
1274 list_for_each_entry_safe(w, n, list, power_list) {
1277 /* Do we need to apply any queued changes? */
1278 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1279 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1280 if (!list_empty(&pending))
1281 dapm_seq_run_coalesced(cur_dapm, &pending);
1283 if (cur_dapm && cur_dapm->seq_notifier) {
1284 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1285 if (sort[i] == cur_sort)
1286 cur_dapm->seq_notifier(cur_dapm,
1291 INIT_LIST_HEAD(&pending);
1293 cur_subseq = INT_MIN;
1294 cur_reg = SND_SOC_NOPM;
1299 case snd_soc_dapm_pre:
1301 list_for_each_entry_safe_continue(w, n, list,
1304 if (event == SND_SOC_DAPM_STREAM_START)
1306 NULL, SND_SOC_DAPM_PRE_PMU);
1307 else if (event == SND_SOC_DAPM_STREAM_STOP)
1309 NULL, SND_SOC_DAPM_PRE_PMD);
1312 case snd_soc_dapm_post:
1314 list_for_each_entry_safe_continue(w, n, list,
1317 if (event == SND_SOC_DAPM_STREAM_START)
1319 NULL, SND_SOC_DAPM_POST_PMU);
1320 else if (event == SND_SOC_DAPM_STREAM_STOP)
1322 NULL, SND_SOC_DAPM_POST_PMD);
1326 /* Queue it up for application */
1327 cur_sort = sort[w->id];
1328 cur_subseq = w->subseq;
1331 list_move(&w->power_list, &pending);
1336 dev_err(w->dapm->dev,
1337 "Failed to apply widget power: %d\n", ret);
1340 if (!list_empty(&pending))
1341 dapm_seq_run_coalesced(cur_dapm, &pending);
1343 if (cur_dapm && cur_dapm->seq_notifier) {
1344 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1345 if (sort[i] == cur_sort)
1346 cur_dapm->seq_notifier(cur_dapm,
1351 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1353 struct snd_soc_dapm_update *update = dapm->update;
1354 struct snd_soc_dapm_widget *w;
1363 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1364 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1366 pr_err("%s DAPM pre-event failed: %d\n",
1370 ret = soc_widget_update_bits_locked(w, update->reg, update->mask,
1373 pr_err("%s DAPM update failed: %d\n", w->name, ret);
1376 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1377 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1379 pr_err("%s DAPM post-event failed: %d\n",
1384 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1385 * they're changing state.
1387 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1389 struct snd_soc_dapm_context *d = data;
1392 /* If we're off and we're not supposed to be go into STANDBY */
1393 if (d->bias_level == SND_SOC_BIAS_OFF &&
1394 d->target_bias_level != SND_SOC_BIAS_OFF) {
1396 pm_runtime_get_sync(d->dev);
1398 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1401 "Failed to turn on bias: %d\n", ret);
1404 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1405 if (d->bias_level != d->target_bias_level) {
1406 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1409 "Failed to prepare bias: %d\n", ret);
1413 /* Async callback run prior to DAPM sequences - brings to their final
1416 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1418 struct snd_soc_dapm_context *d = data;
1421 /* If we just powered the last thing off drop to standby bias */
1422 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1423 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1424 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1425 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1427 dev_err(d->dev, "Failed to apply standby bias: %d\n",
1431 /* If we're in standby and can support bias off then do that */
1432 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1433 d->target_bias_level == SND_SOC_BIAS_OFF) {
1434 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1436 dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
1439 pm_runtime_put(d->dev);
1442 /* If we just powered up then move to active bias */
1443 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1444 d->target_bias_level == SND_SOC_BIAS_ON) {
1445 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1447 dev_err(d->dev, "Failed to apply active bias: %d\n",
1452 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
1453 bool power, bool connect)
1455 /* If a connection is being made or broken then that update
1456 * will have marked the peer dirty, otherwise the widgets are
1457 * not connected and this update has no impact. */
1461 /* If the peer is already in the state we're moving to then we
1462 * won't have an impact on it. */
1463 if (power != peer->power)
1464 dapm_mark_dirty(peer, "peer state change");
1467 static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1468 struct list_head *up_list,
1469 struct list_head *down_list)
1471 struct snd_soc_dapm_path *path;
1473 if (w->power == power)
1476 trace_snd_soc_dapm_widget_power(w, power);
1478 /* If we changed our power state perhaps our neigbours changed
1481 list_for_each_entry(path, &w->sources, list_sink) {
1483 dapm_widget_set_peer_power(path->source, power,
1488 case snd_soc_dapm_supply:
1489 case snd_soc_dapm_regulator_supply:
1490 /* Supplies can't affect their outputs, only their inputs */
1493 list_for_each_entry(path, &w->sinks, list_source) {
1495 dapm_widget_set_peer_power(path->sink, power,
1503 dapm_seq_insert(w, up_list, true);
1505 dapm_seq_insert(w, down_list, false);
1510 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1511 struct list_head *up_list,
1512 struct list_head *down_list)
1517 case snd_soc_dapm_pre:
1518 dapm_seq_insert(w, down_list, false);
1520 case snd_soc_dapm_post:
1521 dapm_seq_insert(w, up_list, true);
1525 power = dapm_widget_power_check(w);
1527 dapm_widget_set_power(w, power, up_list, down_list);
1533 * Scan each dapm widget for complete audio path.
1534 * A complete path is a route that has valid endpoints i.e.:-
1536 * o DAC to output pin.
1537 * o Input Pin to ADC.
1538 * o Input pin to Output pin (bypass, sidetone)
1539 * o DAC to ADC (loopback).
1541 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1543 struct snd_soc_card *card = dapm->card;
1544 struct snd_soc_dapm_widget *w;
1545 struct snd_soc_dapm_context *d;
1547 LIST_HEAD(down_list);
1548 LIST_HEAD(async_domain);
1549 enum snd_soc_bias_level bias;
1551 trace_snd_soc_dapm_start(card);
1553 list_for_each_entry(d, &card->dapm_list, list) {
1554 if (d->idle_bias_off)
1555 d->target_bias_level = SND_SOC_BIAS_OFF;
1557 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1562 /* Check which widgets we need to power and store them in
1563 * lists indicating if they should be powered up or down. We
1564 * only check widgets that have been flagged as dirty but note
1565 * that new widgets may be added to the dirty list while we
1568 list_for_each_entry(w, &card->dapm_dirty, dirty) {
1569 dapm_power_one_widget(w, &up_list, &down_list);
1572 list_for_each_entry(w, &card->widgets, list) {
1573 list_del_init(&w->dirty);
1578 /* Supplies and micbiases only bring the
1579 * context up to STANDBY as unless something
1580 * else is active and passing audio they
1581 * generally don't require full power. Signal
1582 * generators are virtual pins and have no
1583 * power impact themselves.
1586 case snd_soc_dapm_siggen:
1588 case snd_soc_dapm_supply:
1589 case snd_soc_dapm_regulator_supply:
1590 case snd_soc_dapm_micbias:
1591 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1592 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1595 d->target_bias_level = SND_SOC_BIAS_ON;
1602 /* Force all contexts in the card to the same bias state if
1603 * they're not ground referenced.
1605 bias = SND_SOC_BIAS_OFF;
1606 list_for_each_entry(d, &card->dapm_list, list)
1607 if (d->target_bias_level > bias)
1608 bias = d->target_bias_level;
1609 list_for_each_entry(d, &card->dapm_list, list)
1610 if (!d->idle_bias_off)
1611 d->target_bias_level = bias;
1613 trace_snd_soc_dapm_walk_done(card);
1615 /* Run all the bias changes in parallel */
1616 list_for_each_entry(d, &dapm->card->dapm_list, list)
1617 async_schedule_domain(dapm_pre_sequence_async, d,
1619 async_synchronize_full_domain(&async_domain);
1621 /* Power down widgets first; try to avoid amplifying pops. */
1622 dapm_seq_run(dapm, &down_list, event, false);
1624 dapm_widget_update(dapm);
1627 dapm_seq_run(dapm, &up_list, event, true);
1629 /* Run all the bias changes in parallel */
1630 list_for_each_entry(d, &dapm->card->dapm_list, list)
1631 async_schedule_domain(dapm_post_sequence_async, d,
1633 async_synchronize_full_domain(&async_domain);
1635 /* do we need to notify any clients that DAPM event is complete */
1636 list_for_each_entry(d, &card->dapm_list, list) {
1637 if (d->stream_event)
1638 d->stream_event(d, event);
1641 pop_dbg(dapm->dev, card->pop_time,
1642 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1643 pop_wait(card->pop_time);
1645 trace_snd_soc_dapm_done(card);
1650 #ifdef CONFIG_DEBUG_FS
1651 static ssize_t dapm_widget_power_read_file(struct file *file,
1652 char __user *user_buf,
1653 size_t count, loff_t *ppos)
1655 struct snd_soc_dapm_widget *w = file->private_data;
1659 struct snd_soc_dapm_path *p = NULL;
1661 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1665 in = is_connected_input_ep(w, NULL);
1666 dapm_clear_walk(w->dapm);
1667 out = is_connected_output_ep(w, NULL);
1668 dapm_clear_walk(w->dapm);
1670 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
1671 w->name, w->power ? "On" : "Off",
1672 w->force ? " (forced)" : "", in, out);
1675 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1676 " - R%d(0x%x) bit %d",
1677 w->reg, w->reg, w->shift);
1679 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1682 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1684 w->active ? "active" : "inactive");
1686 list_for_each_entry(p, &w->sources, list_sink) {
1687 if (p->connected && !p->connected(w, p->sink))
1691 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1692 " in \"%s\" \"%s\"\n",
1693 p->name ? p->name : "static",
1696 list_for_each_entry(p, &w->sinks, list_source) {
1697 if (p->connected && !p->connected(w, p->sink))
1701 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1702 " out \"%s\" \"%s\"\n",
1703 p->name ? p->name : "static",
1707 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1713 static const struct file_operations dapm_widget_power_fops = {
1714 .open = simple_open,
1715 .read = dapm_widget_power_read_file,
1716 .llseek = default_llseek,
1719 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1720 size_t count, loff_t *ppos)
1722 struct snd_soc_dapm_context *dapm = file->private_data;
1725 switch (dapm->bias_level) {
1726 case SND_SOC_BIAS_ON:
1729 case SND_SOC_BIAS_PREPARE:
1730 level = "Prepare\n";
1732 case SND_SOC_BIAS_STANDBY:
1733 level = "Standby\n";
1735 case SND_SOC_BIAS_OFF:
1740 level = "Unknown\n";
1744 return simple_read_from_buffer(user_buf, count, ppos, level,
1748 static const struct file_operations dapm_bias_fops = {
1749 .open = simple_open,
1750 .read = dapm_bias_read_file,
1751 .llseek = default_llseek,
1754 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1755 struct dentry *parent)
1759 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1761 if (!dapm->debugfs_dapm) {
1763 "Failed to create DAPM debugfs directory\n");
1767 d = debugfs_create_file("bias_level", 0444,
1768 dapm->debugfs_dapm, dapm,
1772 "ASoC: Failed to create bias level debugfs file\n");
1775 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1777 struct snd_soc_dapm_context *dapm = w->dapm;
1780 if (!dapm->debugfs_dapm || !w->name)
1783 d = debugfs_create_file(w->name, 0444,
1784 dapm->debugfs_dapm, w,
1785 &dapm_widget_power_fops);
1787 dev_warn(w->dapm->dev,
1788 "ASoC: Failed to create %s debugfs file\n",
1792 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1794 debugfs_remove_recursive(dapm->debugfs_dapm);
1798 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1799 struct dentry *parent)
1803 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1807 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1813 /* test and update the power status of a mux widget */
1814 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1815 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1817 struct snd_soc_dapm_path *path;
1820 if (widget->id != snd_soc_dapm_mux &&
1821 widget->id != snd_soc_dapm_virt_mux &&
1822 widget->id != snd_soc_dapm_value_mux)
1825 /* find dapm widget path assoc with kcontrol */
1826 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1827 if (path->kcontrol != kcontrol)
1830 if (!path->name || !e->texts[mux])
1834 /* we now need to match the string in the enum to the path */
1835 if (!(strcmp(path->name, e->texts[mux]))) {
1836 path->connect = 1; /* new connection */
1837 dapm_mark_dirty(path->source, "mux connection");
1840 dapm_mark_dirty(path->source,
1841 "mux disconnection");
1842 path->connect = 0; /* old connection must be powered down */
1847 dapm_mark_dirty(widget, "mux change");
1848 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1854 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1855 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1857 struct snd_soc_card *card = widget->dapm->card;
1860 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1861 ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
1862 mutex_unlock(&card->dapm_mutex);
1864 soc_dpcm_runtime_update(widget);
1867 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
1869 /* test and update the power status of a mixer or switch widget */
1870 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1871 struct snd_kcontrol *kcontrol, int connect)
1873 struct snd_soc_dapm_path *path;
1876 if (widget->id != snd_soc_dapm_mixer &&
1877 widget->id != snd_soc_dapm_mixer_named_ctl &&
1878 widget->id != snd_soc_dapm_switch)
1881 /* find dapm widget path assoc with kcontrol */
1882 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1883 if (path->kcontrol != kcontrol)
1886 /* found, now check type */
1888 path->connect = connect;
1889 dapm_mark_dirty(path->source, "mixer connection");
1893 dapm_mark_dirty(widget, "mixer update");
1894 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1900 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1901 struct snd_kcontrol *kcontrol, int connect)
1903 struct snd_soc_card *card = widget->dapm->card;
1906 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1907 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
1908 mutex_unlock(&card->dapm_mutex);
1910 soc_dpcm_runtime_update(widget);
1913 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
1915 /* show dapm widget status in sys fs */
1916 static ssize_t dapm_widget_show(struct device *dev,
1917 struct device_attribute *attr, char *buf)
1919 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
1920 struct snd_soc_codec *codec =rtd->codec;
1921 struct snd_soc_dapm_widget *w;
1923 char *state = "not set";
1925 list_for_each_entry(w, &codec->card->widgets, list) {
1926 if (w->dapm != &codec->dapm)
1929 /* only display widgets that burnm power */
1931 case snd_soc_dapm_hp:
1932 case snd_soc_dapm_mic:
1933 case snd_soc_dapm_spk:
1934 case snd_soc_dapm_line:
1935 case snd_soc_dapm_micbias:
1936 case snd_soc_dapm_dac:
1937 case snd_soc_dapm_adc:
1938 case snd_soc_dapm_pga:
1939 case snd_soc_dapm_out_drv:
1940 case snd_soc_dapm_mixer:
1941 case snd_soc_dapm_mixer_named_ctl:
1942 case snd_soc_dapm_supply:
1943 case snd_soc_dapm_regulator_supply:
1945 count += sprintf(buf + count, "%s: %s\n",
1946 w->name, w->power ? "On":"Off");
1953 switch (codec->dapm.bias_level) {
1954 case SND_SOC_BIAS_ON:
1957 case SND_SOC_BIAS_PREPARE:
1960 case SND_SOC_BIAS_STANDBY:
1963 case SND_SOC_BIAS_OFF:
1967 count += sprintf(buf + count, "PM State: %s\n", state);
1972 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1974 int snd_soc_dapm_sys_add(struct device *dev)
1976 return device_create_file(dev, &dev_attr_dapm_widget);
1979 static void snd_soc_dapm_sys_remove(struct device *dev)
1981 device_remove_file(dev, &dev_attr_dapm_widget);
1984 /* free all dapm widgets and resources */
1985 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1987 struct snd_soc_dapm_widget *w, *next_w;
1988 struct snd_soc_dapm_path *p, *next_p;
1990 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1991 if (w->dapm != dapm)
1995 * remove source and sink paths associated to this widget.
1996 * While removing the path, remove reference to it from both
1997 * source and sink widgets so that path is removed only once.
1999 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
2000 list_del(&p->list_sink);
2001 list_del(&p->list_source);
2003 kfree(p->long_name);
2006 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
2007 list_del(&p->list_sink);
2008 list_del(&p->list_source);
2010 kfree(p->long_name);
2013 kfree(w->kcontrols);
2019 static struct snd_soc_dapm_widget *dapm_find_widget(
2020 struct snd_soc_dapm_context *dapm, const char *pin,
2021 bool search_other_contexts)
2023 struct snd_soc_dapm_widget *w;
2024 struct snd_soc_dapm_widget *fallback = NULL;
2026 list_for_each_entry(w, &dapm->card->widgets, list) {
2027 if (!strcmp(w->name, pin)) {
2028 if (w->dapm == dapm)
2035 if (search_other_contexts)
2041 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2042 const char *pin, int status)
2044 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2047 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2051 if (w->connected != status)
2052 dapm_mark_dirty(w, "pin configuration");
2054 w->connected = status;
2062 * snd_soc_dapm_sync - scan and power dapm paths
2063 * @dapm: DAPM context
2065 * Walks all dapm audio paths and powers widgets according to their
2066 * stream or path usage.
2068 * Returns 0 for success.
2070 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2075 * Suppress early reports (eg, jacks syncing their state) to avoid
2076 * silly DAPM runs during card startup.
2078 if (!dapm->card || !dapm->card->instantiated)
2081 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2082 ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2083 mutex_unlock(&dapm->card->dapm_mutex);
2086 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2088 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2089 const struct snd_soc_dapm_route *route)
2091 struct snd_soc_dapm_path *path;
2092 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
2093 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
2095 const char *control = route->control;
2097 char prefixed_sink[80];
2098 char prefixed_source[80];
2101 if (dapm->codec && dapm->codec->name_prefix) {
2102 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2103 dapm->codec->name_prefix, route->sink);
2104 sink = prefixed_sink;
2105 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2106 dapm->codec->name_prefix, route->source);
2107 source = prefixed_source;
2110 source = route->source;
2114 * find src and dest widgets over all widgets but favor a widget from
2115 * current DAPM context
2117 list_for_each_entry(w, &dapm->card->widgets, list) {
2118 if (!wsink && !(strcmp(w->name, sink))) {
2120 if (w->dapm == dapm)
2124 if (!wsource && !(strcmp(w->name, source))) {
2126 if (w->dapm == dapm)
2130 /* use widget from another DAPM context if not found from this */
2136 if (wsource == NULL || wsink == NULL)
2139 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2143 path->source = wsource;
2145 path->connected = route->connected;
2146 INIT_LIST_HEAD(&path->list);
2147 INIT_LIST_HEAD(&path->list_source);
2148 INIT_LIST_HEAD(&path->list_sink);
2150 /* check for external widgets */
2151 if (wsink->id == snd_soc_dapm_input) {
2152 if (wsource->id == snd_soc_dapm_micbias ||
2153 wsource->id == snd_soc_dapm_mic ||
2154 wsource->id == snd_soc_dapm_line ||
2155 wsource->id == snd_soc_dapm_output)
2158 if (wsource->id == snd_soc_dapm_output) {
2159 if (wsink->id == snd_soc_dapm_spk ||
2160 wsink->id == snd_soc_dapm_hp ||
2161 wsink->id == snd_soc_dapm_line ||
2162 wsink->id == snd_soc_dapm_input)
2166 /* connect static paths */
2167 if (control == NULL) {
2168 list_add(&path->list, &dapm->card->paths);
2169 list_add(&path->list_sink, &wsink->sources);
2170 list_add(&path->list_source, &wsource->sinks);
2175 /* connect dynamic paths */
2176 switch (wsink->id) {
2177 case snd_soc_dapm_adc:
2178 case snd_soc_dapm_dac:
2179 case snd_soc_dapm_pga:
2180 case snd_soc_dapm_out_drv:
2181 case snd_soc_dapm_input:
2182 case snd_soc_dapm_output:
2183 case snd_soc_dapm_siggen:
2184 case snd_soc_dapm_micbias:
2185 case snd_soc_dapm_vmid:
2186 case snd_soc_dapm_pre:
2187 case snd_soc_dapm_post:
2188 case snd_soc_dapm_supply:
2189 case snd_soc_dapm_regulator_supply:
2190 case snd_soc_dapm_aif_in:
2191 case snd_soc_dapm_aif_out:
2192 case snd_soc_dapm_dai:
2193 case snd_soc_dapm_dai_link:
2194 list_add(&path->list, &dapm->card->paths);
2195 list_add(&path->list_sink, &wsink->sources);
2196 list_add(&path->list_source, &wsource->sinks);
2199 case snd_soc_dapm_mux:
2200 case snd_soc_dapm_virt_mux:
2201 case snd_soc_dapm_value_mux:
2202 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2203 &wsink->kcontrol_news[0]);
2207 case snd_soc_dapm_switch:
2208 case snd_soc_dapm_mixer:
2209 case snd_soc_dapm_mixer_named_ctl:
2210 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2214 case snd_soc_dapm_hp:
2215 case snd_soc_dapm_mic:
2216 case snd_soc_dapm_line:
2217 case snd_soc_dapm_spk:
2218 list_add(&path->list, &dapm->card->paths);
2219 list_add(&path->list_sink, &wsink->sources);
2220 list_add(&path->list_source, &wsource->sinks);
2227 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
2228 source, control, sink);
2234 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2235 * @dapm: DAPM context
2236 * @route: audio routes
2237 * @num: number of routes
2239 * Connects 2 dapm widgets together via a named audio path. The sink is
2240 * the widget receiving the audio signal, whilst the source is the sender
2241 * of the audio signal.
2243 * Returns 0 for success else error. On error all resources can be freed
2244 * with a call to snd_soc_card_free().
2246 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2247 const struct snd_soc_dapm_route *route, int num)
2251 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2252 for (i = 0; i < num; i++) {
2253 ret = snd_soc_dapm_add_route(dapm, route);
2255 dev_err(dapm->dev, "Failed to add route %s->%s\n",
2256 route->source, route->sink);
2261 mutex_unlock(&dapm->card->dapm_mutex);
2265 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2267 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2268 const struct snd_soc_dapm_route *route)
2270 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2273 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2276 struct snd_soc_dapm_path *path;
2280 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
2286 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
2291 if (route->control || route->connected)
2292 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
2293 route->source, route->sink);
2295 list_for_each_entry(path, &source->sinks, list_source) {
2296 if (path->sink == sink) {
2303 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
2304 route->source, route->sink);
2306 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
2307 count, route->source, route->sink);
2313 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2314 * @dapm: DAPM context
2315 * @route: audio routes
2316 * @num: number of routes
2318 * Mark existing routes matching those specified in the passed array
2319 * as being weak, meaning that they are ignored for the purpose of
2320 * power decisions. The main intended use case is for sidetone paths
2321 * which couple audio between other independent paths if they are both
2322 * active in order to make the combination work better at the user
2323 * level but which aren't intended to be "used".
2325 * Note that CODEC drivers should not use this as sidetone type paths
2326 * can frequently also be used as bypass paths.
2328 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2329 const struct snd_soc_dapm_route *route, int num)
2334 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2335 for (i = 0; i < num; i++) {
2336 err = snd_soc_dapm_weak_route(dapm, route);
2341 mutex_unlock(&dapm->card->dapm_mutex);
2345 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2348 * snd_soc_dapm_new_widgets - add new dapm widgets
2349 * @dapm: DAPM context
2351 * Checks the codec for any new dapm widgets and creates them if found.
2353 * Returns 0 for success.
2355 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2357 struct snd_soc_dapm_widget *w;
2360 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2362 list_for_each_entry(w, &dapm->card->widgets, list)
2367 if (w->num_kcontrols) {
2368 w->kcontrols = kzalloc(w->num_kcontrols *
2369 sizeof(struct snd_kcontrol *),
2371 if (!w->kcontrols) {
2372 mutex_unlock(&dapm->card->dapm_mutex);
2378 case snd_soc_dapm_switch:
2379 case snd_soc_dapm_mixer:
2380 case snd_soc_dapm_mixer_named_ctl:
2383 case snd_soc_dapm_mux:
2384 case snd_soc_dapm_virt_mux:
2385 case snd_soc_dapm_value_mux:
2388 case snd_soc_dapm_pga:
2389 case snd_soc_dapm_out_drv:
2396 /* Read the initial power state from the device */
2398 val = soc_widget_read(w, w->reg);
2399 val &= 1 << w->shift;
2409 dapm_mark_dirty(w, "new widget");
2410 dapm_debugfs_add_widget(w);
2413 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2414 mutex_unlock(&dapm->card->dapm_mutex);
2417 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2420 * snd_soc_dapm_get_volsw - dapm mixer get callback
2421 * @kcontrol: mixer control
2422 * @ucontrol: control element information
2424 * Callback to get the value of a dapm mixer control.
2426 * Returns 0 for success.
2428 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2429 struct snd_ctl_elem_value *ucontrol)
2431 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2432 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2433 struct soc_mixer_control *mc =
2434 (struct soc_mixer_control *)kcontrol->private_value;
2435 unsigned int reg = mc->reg;
2436 unsigned int shift = mc->shift;
2437 unsigned int rshift = mc->rshift;
2439 unsigned int invert = mc->invert;
2440 unsigned int mask = (1 << fls(max)) - 1;
2442 ucontrol->value.integer.value[0] =
2443 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2444 if (shift != rshift)
2445 ucontrol->value.integer.value[1] =
2446 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2448 ucontrol->value.integer.value[0] =
2449 max - ucontrol->value.integer.value[0];
2450 if (shift != rshift)
2451 ucontrol->value.integer.value[1] =
2452 max - ucontrol->value.integer.value[1];
2457 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2460 * snd_soc_dapm_put_volsw - dapm mixer set callback
2461 * @kcontrol: mixer control
2462 * @ucontrol: control element information
2464 * Callback to set the value of a dapm mixer control.
2466 * Returns 0 for success.
2468 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2469 struct snd_ctl_elem_value *ucontrol)
2471 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2472 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2473 struct snd_soc_codec *codec = widget->codec;
2474 struct snd_soc_card *card = codec->card;
2475 struct soc_mixer_control *mc =
2476 (struct soc_mixer_control *)kcontrol->private_value;
2477 unsigned int reg = mc->reg;
2478 unsigned int shift = mc->shift;
2480 unsigned int mask = (1 << fls(max)) - 1;
2481 unsigned int invert = mc->invert;
2483 int connect, change;
2484 struct snd_soc_dapm_update update;
2487 val = (ucontrol->value.integer.value[0] & mask);
2491 mask = mask << shift;
2495 /* new connection */
2496 connect = invert ? 0 : 1;
2498 /* old connection must be powered down */
2499 connect = invert ? 1 : 0;
2501 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2503 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2505 for (wi = 0; wi < wlist->num_widgets; wi++) {
2506 widget = wlist->widgets[wi];
2508 widget->value = val;
2510 update.kcontrol = kcontrol;
2511 update.widget = widget;
2515 widget->dapm->update = &update;
2517 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2519 widget->dapm->update = NULL;
2523 mutex_unlock(&card->dapm_mutex);
2526 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2529 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2530 * @kcontrol: mixer control
2531 * @ucontrol: control element information
2533 * Callback to get the value of a dapm enumerated double mixer control.
2535 * Returns 0 for success.
2537 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2538 struct snd_ctl_elem_value *ucontrol)
2540 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2541 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2542 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2543 unsigned int val, bitmask;
2545 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2547 val = snd_soc_read(widget->codec, e->reg);
2548 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2549 if (e->shift_l != e->shift_r)
2550 ucontrol->value.enumerated.item[1] =
2551 (val >> e->shift_r) & (bitmask - 1);
2555 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2558 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2559 * @kcontrol: mixer control
2560 * @ucontrol: control element information
2562 * Callback to set the value of a dapm enumerated double mixer control.
2564 * Returns 0 for success.
2566 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2567 struct snd_ctl_elem_value *ucontrol)
2569 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2570 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2571 struct snd_soc_codec *codec = widget->codec;
2572 struct snd_soc_card *card = codec->card;
2573 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2574 unsigned int val, mux, change;
2575 unsigned int mask, bitmask;
2576 struct snd_soc_dapm_update update;
2579 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2581 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2583 mux = ucontrol->value.enumerated.item[0];
2584 val = mux << e->shift_l;
2585 mask = (bitmask - 1) << e->shift_l;
2586 if (e->shift_l != e->shift_r) {
2587 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2589 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2590 mask |= (bitmask - 1) << e->shift_r;
2593 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2595 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2597 for (wi = 0; wi < wlist->num_widgets; wi++) {
2598 widget = wlist->widgets[wi];
2600 widget->value = val;
2602 update.kcontrol = kcontrol;
2603 update.widget = widget;
2604 update.reg = e->reg;
2607 widget->dapm->update = &update;
2609 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2611 widget->dapm->update = NULL;
2615 mutex_unlock(&card->dapm_mutex);
2618 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2621 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2622 * @kcontrol: mixer control
2623 * @ucontrol: control element information
2625 * Returns 0 for success.
2627 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2628 struct snd_ctl_elem_value *ucontrol)
2630 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2631 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2633 ucontrol->value.enumerated.item[0] = widget->value;
2637 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2640 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2641 * @kcontrol: mixer control
2642 * @ucontrol: control element information
2644 * Returns 0 for success.
2646 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2647 struct snd_ctl_elem_value *ucontrol)
2649 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2650 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2651 struct snd_soc_codec *codec = widget->codec;
2652 struct snd_soc_card *card = codec->card;
2653 struct soc_enum *e =
2654 (struct soc_enum *)kcontrol->private_value;
2659 if (ucontrol->value.enumerated.item[0] >= e->max)
2662 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2664 change = widget->value != ucontrol->value.enumerated.item[0];
2666 for (wi = 0; wi < wlist->num_widgets; wi++) {
2667 widget = wlist->widgets[wi];
2669 widget->value = ucontrol->value.enumerated.item[0];
2671 soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
2675 mutex_unlock(&card->dapm_mutex);
2678 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2681 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2683 * @kcontrol: mixer control
2684 * @ucontrol: control element information
2686 * Callback to get the value of a dapm semi enumerated double mixer control.
2688 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2689 * used for handling bitfield coded enumeration for example.
2691 * Returns 0 for success.
2693 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2694 struct snd_ctl_elem_value *ucontrol)
2696 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2697 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2698 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2699 unsigned int reg_val, val, mux;
2701 reg_val = snd_soc_read(widget->codec, e->reg);
2702 val = (reg_val >> e->shift_l) & e->mask;
2703 for (mux = 0; mux < e->max; mux++) {
2704 if (val == e->values[mux])
2707 ucontrol->value.enumerated.item[0] = mux;
2708 if (e->shift_l != e->shift_r) {
2709 val = (reg_val >> e->shift_r) & e->mask;
2710 for (mux = 0; mux < e->max; mux++) {
2711 if (val == e->values[mux])
2714 ucontrol->value.enumerated.item[1] = mux;
2719 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2722 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2724 * @kcontrol: mixer control
2725 * @ucontrol: control element information
2727 * Callback to set the value of a dapm semi enumerated double mixer control.
2729 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2730 * used for handling bitfield coded enumeration for example.
2732 * Returns 0 for success.
2734 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2735 struct snd_ctl_elem_value *ucontrol)
2737 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2738 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2739 struct snd_soc_codec *codec = widget->codec;
2740 struct snd_soc_card *card = codec->card;
2741 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2742 unsigned int val, mux, change;
2744 struct snd_soc_dapm_update update;
2747 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2749 mux = ucontrol->value.enumerated.item[0];
2750 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2751 mask = e->mask << e->shift_l;
2752 if (e->shift_l != e->shift_r) {
2753 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2755 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2756 mask |= e->mask << e->shift_r;
2759 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2761 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2763 for (wi = 0; wi < wlist->num_widgets; wi++) {
2764 widget = wlist->widgets[wi];
2766 widget->value = val;
2768 update.kcontrol = kcontrol;
2769 update.widget = widget;
2770 update.reg = e->reg;
2773 widget->dapm->update = &update;
2775 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2777 widget->dapm->update = NULL;
2781 mutex_unlock(&card->dapm_mutex);
2784 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2787 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2789 * @kcontrol: mixer control
2790 * @uinfo: control element information
2792 * Callback to provide information about a pin switch control.
2794 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2795 struct snd_ctl_elem_info *uinfo)
2797 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2799 uinfo->value.integer.min = 0;
2800 uinfo->value.integer.max = 1;
2804 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2807 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2809 * @kcontrol: mixer control
2812 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2813 struct snd_ctl_elem_value *ucontrol)
2815 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2816 const char *pin = (const char *)kcontrol->private_value;
2818 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2820 ucontrol->value.integer.value[0] =
2821 snd_soc_dapm_get_pin_status(&card->dapm, pin);
2823 mutex_unlock(&card->dapm_mutex);
2827 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2830 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2832 * @kcontrol: mixer control
2835 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2836 struct snd_ctl_elem_value *ucontrol)
2838 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2839 const char *pin = (const char *)kcontrol->private_value;
2841 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2843 if (ucontrol->value.integer.value[0])
2844 snd_soc_dapm_enable_pin(&card->dapm, pin);
2846 snd_soc_dapm_disable_pin(&card->dapm, pin);
2848 mutex_unlock(&card->dapm_mutex);
2850 snd_soc_dapm_sync(&card->dapm);
2853 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2855 static struct snd_soc_dapm_widget *
2856 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2857 const struct snd_soc_dapm_widget *widget)
2859 struct snd_soc_dapm_widget *w;
2863 if ((w = dapm_cnew_widget(widget)) == NULL)
2867 case snd_soc_dapm_regulator_supply:
2868 w->regulator = devm_regulator_get(dapm->dev, w->name);
2869 if (IS_ERR(w->regulator)) {
2870 ret = PTR_ERR(w->regulator);
2871 dev_err(dapm->dev, "Failed to request %s: %d\n",
2880 name_len = strlen(widget->name) + 1;
2881 if (dapm->codec && dapm->codec->name_prefix)
2882 name_len += 1 + strlen(dapm->codec->name_prefix);
2883 w->name = kmalloc(name_len, GFP_KERNEL);
2884 if (w->name == NULL) {
2888 if (dapm->codec && dapm->codec->name_prefix)
2889 snprintf((char *)w->name, name_len, "%s %s",
2890 dapm->codec->name_prefix, widget->name);
2892 snprintf((char *)w->name, name_len, "%s", widget->name);
2895 case snd_soc_dapm_switch:
2896 case snd_soc_dapm_mixer:
2897 case snd_soc_dapm_mixer_named_ctl:
2898 w->power_check = dapm_generic_check_power;
2900 case snd_soc_dapm_mux:
2901 case snd_soc_dapm_virt_mux:
2902 case snd_soc_dapm_value_mux:
2903 w->power_check = dapm_generic_check_power;
2905 case snd_soc_dapm_adc:
2906 case snd_soc_dapm_aif_out:
2907 w->power_check = dapm_adc_check_power;
2909 case snd_soc_dapm_dac:
2910 case snd_soc_dapm_aif_in:
2911 w->power_check = dapm_dac_check_power;
2913 case snd_soc_dapm_pga:
2914 case snd_soc_dapm_out_drv:
2915 case snd_soc_dapm_input:
2916 case snd_soc_dapm_output:
2917 case snd_soc_dapm_micbias:
2918 case snd_soc_dapm_spk:
2919 case snd_soc_dapm_hp:
2920 case snd_soc_dapm_mic:
2921 case snd_soc_dapm_line:
2922 case snd_soc_dapm_dai_link:
2923 w->power_check = dapm_generic_check_power;
2925 case snd_soc_dapm_supply:
2926 case snd_soc_dapm_regulator_supply:
2927 w->power_check = dapm_supply_check_power;
2929 case snd_soc_dapm_dai:
2930 w->power_check = dapm_dai_check_power;
2933 w->power_check = dapm_always_on_check_power;
2939 w->codec = dapm->codec;
2940 w->platform = dapm->platform;
2941 INIT_LIST_HEAD(&w->sources);
2942 INIT_LIST_HEAD(&w->sinks);
2943 INIT_LIST_HEAD(&w->list);
2944 INIT_LIST_HEAD(&w->dirty);
2945 list_add(&w->list, &dapm->card->widgets);
2947 /* machine layer set ups unconnected pins and insertions */
2953 * snd_soc_dapm_new_controls - create new dapm controls
2954 * @dapm: DAPM context
2955 * @widget: widget array
2956 * @num: number of widgets
2958 * Creates new DAPM controls based upon the templates.
2960 * Returns 0 for success else error.
2962 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2963 const struct snd_soc_dapm_widget *widget,
2966 struct snd_soc_dapm_widget *w;
2970 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2971 for (i = 0; i < num; i++) {
2972 w = snd_soc_dapm_new_control(dapm, widget);
2975 "ASoC: Failed to create DAPM control %s\n",
2982 mutex_unlock(&dapm->card->dapm_mutex);
2985 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2987 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
2988 struct snd_kcontrol *kcontrol, int event)
2990 struct snd_soc_dapm_path *source_p, *sink_p;
2991 struct snd_soc_dai *source, *sink;
2992 const struct snd_soc_pcm_stream *config = w->params;
2993 struct snd_pcm_substream substream;
2994 struct snd_pcm_hw_params *params = NULL;
2999 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks));
3001 /* We only support a single source and sink, pick the first */
3002 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
3004 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
3007 BUG_ON(!source_p || !sink_p);
3008 BUG_ON(!sink_p->source || !source_p->sink);
3009 BUG_ON(!source_p->source || !sink_p->sink);
3011 source = source_p->source->priv;
3012 sink = sink_p->sink->priv;
3014 /* Be a little careful as we don't want to overflow the mask array */
3015 if (config->formats) {
3016 fmt = ffs(config->formats) - 1;
3018 dev_warn(w->dapm->dev, "Invalid format %llx specified\n",
3023 /* Currently very limited parameter selection */
3024 params = kzalloc(sizeof(*params), GFP_KERNEL);
3029 snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
3031 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min =
3033 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max =
3036 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min
3037 = config->channels_min;
3038 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max
3039 = config->channels_max;
3041 memset(&substream, 0, sizeof(substream));
3044 case SND_SOC_DAPM_PRE_PMU:
3045 if (source->driver->ops && source->driver->ops->hw_params) {
3046 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3047 ret = source->driver->ops->hw_params(&substream,
3050 dev_err(source->dev,
3051 "hw_params() failed: %d\n", ret);
3056 if (sink->driver->ops && sink->driver->ops->hw_params) {
3057 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3058 ret = sink->driver->ops->hw_params(&substream, params,
3062 "hw_params() failed: %d\n", ret);
3068 case SND_SOC_DAPM_POST_PMU:
3069 ret = snd_soc_dai_digital_mute(sink, 0);
3070 if (ret != 0 && ret != -ENOTSUPP)
3071 dev_warn(sink->dev, "Failed to unmute: %d\n", ret);
3075 case SND_SOC_DAPM_PRE_PMD:
3076 ret = snd_soc_dai_digital_mute(sink, 1);
3077 if (ret != 0 && ret != -ENOTSUPP)
3078 dev_warn(sink->dev, "Failed to mute: %d\n", ret);
3092 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3093 const struct snd_soc_pcm_stream *params,
3094 struct snd_soc_dapm_widget *source,
3095 struct snd_soc_dapm_widget *sink)
3097 struct snd_soc_dapm_route routes[2];
3098 struct snd_soc_dapm_widget template;
3099 struct snd_soc_dapm_widget *w;
3103 len = strlen(source->name) + strlen(sink->name) + 2;
3104 link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
3107 snprintf(link_name, len, "%s-%s", source->name, sink->name);
3109 memset(&template, 0, sizeof(template));
3110 template.reg = SND_SOC_NOPM;
3111 template.id = snd_soc_dapm_dai_link;
3112 template.name = link_name;
3113 template.event = snd_soc_dai_link_event;
3114 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3115 SND_SOC_DAPM_PRE_PMD;
3117 dev_dbg(card->dev, "adding %s widget\n", link_name);
3119 w = snd_soc_dapm_new_control(&card->dapm, &template);
3121 dev_err(card->dev, "Failed to create %s widget\n",
3128 memset(&routes, 0, sizeof(routes));
3130 routes[0].source = source->name;
3131 routes[0].sink = link_name;
3132 routes[1].source = link_name;
3133 routes[1].sink = sink->name;
3135 return snd_soc_dapm_add_routes(&card->dapm, routes,
3136 ARRAY_SIZE(routes));
3139 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3140 struct snd_soc_dai *dai)
3142 struct snd_soc_dapm_widget template;
3143 struct snd_soc_dapm_widget *w;
3145 WARN_ON(dapm->dev != dai->dev);
3147 memset(&template, 0, sizeof(template));
3148 template.reg = SND_SOC_NOPM;
3150 if (dai->driver->playback.stream_name) {
3151 template.id = snd_soc_dapm_dai;
3152 template.name = dai->driver->playback.stream_name;
3153 template.sname = dai->driver->playback.stream_name;
3155 dev_dbg(dai->dev, "adding %s widget\n",
3158 w = snd_soc_dapm_new_control(dapm, &template);
3160 dev_err(dapm->dev, "Failed to create %s widget\n",
3161 dai->driver->playback.stream_name);
3165 dai->playback_widget = w;
3168 if (dai->driver->capture.stream_name) {
3169 template.id = snd_soc_dapm_dai;
3170 template.name = dai->driver->capture.stream_name;
3171 template.sname = dai->driver->capture.stream_name;
3173 dev_dbg(dai->dev, "adding %s widget\n",
3176 w = snd_soc_dapm_new_control(dapm, &template);
3178 dev_err(dapm->dev, "Failed to create %s widget\n",
3179 dai->driver->capture.stream_name);
3183 dai->capture_widget = w;
3189 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3191 struct snd_soc_dapm_widget *dai_w, *w;
3192 struct snd_soc_dai *dai;
3193 struct snd_soc_dapm_route r;
3195 memset(&r, 0, sizeof(r));
3197 /* For each DAI widget... */
3198 list_for_each_entry(dai_w, &card->widgets, list) {
3199 if (dai_w->id != snd_soc_dapm_dai)
3204 /* ...find all widgets with the same stream and link them */
3205 list_for_each_entry(w, &card->widgets, list) {
3206 if (w->dapm != dai_w->dapm)
3209 if (w->id == snd_soc_dapm_dai)
3215 if (dai->driver->playback.stream_name &&
3217 dai->driver->playback.stream_name)) {
3218 r.source = dai->playback_widget->name;
3220 dev_dbg(dai->dev, "%s -> %s\n",
3223 snd_soc_dapm_add_route(w->dapm, &r);
3226 if (dai->driver->capture.stream_name &&
3228 dai->driver->capture.stream_name)) {
3230 r.sink = dai->capture_widget->name;
3231 dev_dbg(dai->dev, "%s -> %s\n",
3234 snd_soc_dapm_add_route(w->dapm, &r);
3242 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3246 struct snd_soc_dapm_widget *w_cpu, *w_codec;
3247 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3248 struct snd_soc_dai *codec_dai = rtd->codec_dai;
3250 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
3251 w_cpu = cpu_dai->playback_widget;
3252 w_codec = codec_dai->playback_widget;
3254 w_cpu = cpu_dai->capture_widget;
3255 w_codec = codec_dai->capture_widget;
3260 dapm_mark_dirty(w_cpu, "stream event");
3263 case SND_SOC_DAPM_STREAM_START:
3266 case SND_SOC_DAPM_STREAM_STOP:
3269 case SND_SOC_DAPM_STREAM_SUSPEND:
3270 case SND_SOC_DAPM_STREAM_RESUME:
3271 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3272 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3279 dapm_mark_dirty(w_codec, "stream event");
3282 case SND_SOC_DAPM_STREAM_START:
3283 w_codec->active = 1;
3285 case SND_SOC_DAPM_STREAM_STOP:
3286 w_codec->active = 0;
3288 case SND_SOC_DAPM_STREAM_SUSPEND:
3289 case SND_SOC_DAPM_STREAM_RESUME:
3290 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3291 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3296 dapm_power_widgets(&rtd->card->dapm, event);
3300 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3301 * @rtd: PCM runtime data
3302 * @stream: stream name
3303 * @event: stream event
3305 * Sends a stream event to the dapm core. The core then makes any
3306 * necessary widget power changes.
3308 * Returns 0 for success else error.
3310 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3313 struct snd_soc_card *card = rtd->card;
3315 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3316 soc_dapm_stream_event(rtd, stream, event);
3317 mutex_unlock(&card->dapm_mutex);
3321 * snd_soc_dapm_enable_pin - enable pin.
3322 * @dapm: DAPM context
3325 * Enables input/output pin and its parents or children widgets iff there is
3326 * a valid audio route and active audio stream.
3327 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3328 * do any widget power switching.
3330 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3332 return snd_soc_dapm_set_pin(dapm, pin, 1);
3334 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3337 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3338 * @dapm: DAPM context
3341 * Enables input/output pin regardless of any other state. This is
3342 * intended for use with microphone bias supplies used in microphone
3345 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3346 * do any widget power switching.
3348 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3351 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3354 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3358 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
3361 dapm_mark_dirty(w, "force enable");
3365 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
3368 * snd_soc_dapm_disable_pin - disable pin.
3369 * @dapm: DAPM context
3372 * Disables input/output pin and its parents or children widgets.
3373 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3374 * do any widget power switching.
3376 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
3379 return snd_soc_dapm_set_pin(dapm, pin, 0);
3381 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3384 * snd_soc_dapm_nc_pin - permanently disable pin.
3385 * @dapm: DAPM context
3388 * Marks the specified pin as being not connected, disabling it along
3389 * any parent or child widgets. At present this is identical to
3390 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3391 * additional things such as disabling controls which only affect
3392 * paths through the pin.
3394 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3395 * do any widget power switching.
3397 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3399 return snd_soc_dapm_set_pin(dapm, pin, 0);
3401 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
3404 * snd_soc_dapm_get_pin_status - get audio pin status
3405 * @dapm: DAPM context
3406 * @pin: audio signal pin endpoint (or start point)
3408 * Get audio pin status - connected or disconnected.
3410 * Returns 1 for connected otherwise 0.
3412 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
3415 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3418 return w->connected;
3422 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
3425 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3426 * @dapm: DAPM context
3427 * @pin: audio signal pin endpoint (or start point)
3429 * Mark the given endpoint or pin as ignoring suspend. When the
3430 * system is disabled a path between two endpoints flagged as ignoring
3431 * suspend will not be disabled. The path must already be enabled via
3432 * normal means at suspend time, it will not be turned on if it was not
3435 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
3438 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
3441 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3445 w->ignore_suspend = 1;
3449 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3451 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
3452 struct snd_soc_dapm_widget *w)
3454 struct snd_soc_dapm_path *p;
3456 list_for_each_entry(p, &card->paths, list) {
3457 if ((p->source == w) || (p->sink == w)) {
3459 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3460 p->source->name, p->source->id, p->source->dapm,
3461 p->sink->name, p->sink->id, p->sink->dapm);
3463 /* Connected to something other than the codec */
3464 if (p->source->dapm != p->sink->dapm)
3467 * Loopback connection from codec external pin to
3468 * codec external pin
3470 if (p->sink->id == snd_soc_dapm_input) {
3471 switch (p->source->id) {
3472 case snd_soc_dapm_output:
3473 case snd_soc_dapm_micbias:
3486 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3487 * @codec: The codec whose pins should be processed
3489 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3490 * which are unused. Pins are used if they are connected externally to the
3491 * codec, whether that be to some other device, or a loop-back connection to
3494 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
3496 struct snd_soc_card *card = codec->card;
3497 struct snd_soc_dapm_context *dapm = &codec->dapm;
3498 struct snd_soc_dapm_widget *w;
3500 dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n",
3501 &card->dapm, &codec->dapm);
3503 list_for_each_entry(w, &card->widgets, list) {
3504 if (w->dapm != dapm)
3507 case snd_soc_dapm_input:
3508 case snd_soc_dapm_output:
3509 case snd_soc_dapm_micbias:
3510 dev_dbg(codec->dev, "Auto NC: Checking widget %s\n",
3512 if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
3514 "... Not in map; disabling\n");
3515 snd_soc_dapm_nc_pin(dapm, w->name);
3525 * snd_soc_dapm_free - free dapm resources
3526 * @dapm: DAPM context
3528 * Free all dapm widgets and resources.
3530 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
3532 snd_soc_dapm_sys_remove(dapm->dev);
3533 dapm_debugfs_cleanup(dapm);
3534 dapm_free_widgets(dapm);
3535 list_del(&dapm->list);
3537 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
3539 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
3541 struct snd_soc_dapm_widget *w;
3542 LIST_HEAD(down_list);
3545 list_for_each_entry(w, &dapm->card->widgets, list) {
3546 if (w->dapm != dapm)
3549 dapm_seq_insert(w, &down_list, false);
3555 /* If there were no widgets to power down we're already in
3559 if (dapm->bias_level == SND_SOC_BIAS_ON)
3560 snd_soc_dapm_set_bias_level(dapm,
3561 SND_SOC_BIAS_PREPARE);
3562 dapm_seq_run(dapm, &down_list, 0, false);
3563 if (dapm->bias_level == SND_SOC_BIAS_PREPARE)
3564 snd_soc_dapm_set_bias_level(dapm,
3565 SND_SOC_BIAS_STANDBY);
3570 * snd_soc_dapm_shutdown - callback for system shutdown
3572 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
3574 struct snd_soc_codec *codec;
3576 list_for_each_entry(codec, &card->codec_dev_list, list) {
3577 soc_dapm_shutdown_codec(&codec->dapm);
3578 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
3579 snd_soc_dapm_set_bias_level(&codec->dapm,
3584 /* Module information */
3585 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3586 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3587 MODULE_LICENSE("GPL");