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);
1862 soc_dpcm_runtime_update(widget);
1865 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
1867 /* test and update the power status of a mixer or switch widget */
1868 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1869 struct snd_kcontrol *kcontrol, int connect)
1871 struct snd_soc_dapm_path *path;
1874 if (widget->id != snd_soc_dapm_mixer &&
1875 widget->id != snd_soc_dapm_mixer_named_ctl &&
1876 widget->id != snd_soc_dapm_switch)
1879 /* find dapm widget path assoc with kcontrol */
1880 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1881 if (path->kcontrol != kcontrol)
1884 /* found, now check type */
1886 path->connect = connect;
1887 dapm_mark_dirty(path->source, "mixer connection");
1891 dapm_mark_dirty(widget, "mixer update");
1892 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1898 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1899 struct snd_kcontrol *kcontrol, int connect)
1901 struct snd_soc_card *card = widget->dapm->card;
1904 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1905 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
1906 mutex_unlock(&card->dapm_mutex);
1908 soc_dpcm_runtime_update(widget);
1911 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
1913 /* show dapm widget status in sys fs */
1914 static ssize_t dapm_widget_show(struct device *dev,
1915 struct device_attribute *attr, char *buf)
1917 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
1918 struct snd_soc_codec *codec =rtd->codec;
1919 struct snd_soc_dapm_widget *w;
1921 char *state = "not set";
1923 list_for_each_entry(w, &codec->card->widgets, list) {
1924 if (w->dapm != &codec->dapm)
1927 /* only display widgets that burnm power */
1929 case snd_soc_dapm_hp:
1930 case snd_soc_dapm_mic:
1931 case snd_soc_dapm_spk:
1932 case snd_soc_dapm_line:
1933 case snd_soc_dapm_micbias:
1934 case snd_soc_dapm_dac:
1935 case snd_soc_dapm_adc:
1936 case snd_soc_dapm_pga:
1937 case snd_soc_dapm_out_drv:
1938 case snd_soc_dapm_mixer:
1939 case snd_soc_dapm_mixer_named_ctl:
1940 case snd_soc_dapm_supply:
1941 case snd_soc_dapm_regulator_supply:
1943 count += sprintf(buf + count, "%s: %s\n",
1944 w->name, w->power ? "On":"Off");
1951 switch (codec->dapm.bias_level) {
1952 case SND_SOC_BIAS_ON:
1955 case SND_SOC_BIAS_PREPARE:
1958 case SND_SOC_BIAS_STANDBY:
1961 case SND_SOC_BIAS_OFF:
1965 count += sprintf(buf + count, "PM State: %s\n", state);
1970 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1972 int snd_soc_dapm_sys_add(struct device *dev)
1974 return device_create_file(dev, &dev_attr_dapm_widget);
1977 static void snd_soc_dapm_sys_remove(struct device *dev)
1979 device_remove_file(dev, &dev_attr_dapm_widget);
1982 /* free all dapm widgets and resources */
1983 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1985 struct snd_soc_dapm_widget *w, *next_w;
1986 struct snd_soc_dapm_path *p, *next_p;
1988 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1989 if (w->dapm != dapm)
1993 * remove source and sink paths associated to this widget.
1994 * While removing the path, remove reference to it from both
1995 * source and sink widgets so that path is removed only once.
1997 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1998 list_del(&p->list_sink);
1999 list_del(&p->list_source);
2001 kfree(p->long_name);
2004 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
2005 list_del(&p->list_sink);
2006 list_del(&p->list_source);
2008 kfree(p->long_name);
2011 kfree(w->kcontrols);
2017 static struct snd_soc_dapm_widget *dapm_find_widget(
2018 struct snd_soc_dapm_context *dapm, const char *pin,
2019 bool search_other_contexts)
2021 struct snd_soc_dapm_widget *w;
2022 struct snd_soc_dapm_widget *fallback = NULL;
2024 list_for_each_entry(w, &dapm->card->widgets, list) {
2025 if (!strcmp(w->name, pin)) {
2026 if (w->dapm == dapm)
2033 if (search_other_contexts)
2039 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2040 const char *pin, int status)
2042 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2045 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2049 if (w->connected != status)
2050 dapm_mark_dirty(w, "pin configuration");
2052 w->connected = status;
2060 * snd_soc_dapm_sync - scan and power dapm paths
2061 * @dapm: DAPM context
2063 * Walks all dapm audio paths and powers widgets according to their
2064 * stream or path usage.
2066 * Returns 0 for success.
2068 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2073 * Suppress early reports (eg, jacks syncing their state) to avoid
2074 * silly DAPM runs during card startup.
2076 if (!dapm->card || !dapm->card->instantiated)
2079 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2080 ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2081 mutex_unlock(&dapm->card->dapm_mutex);
2084 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2086 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2087 const struct snd_soc_dapm_route *route)
2089 struct snd_soc_dapm_path *path;
2090 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
2091 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
2093 const char *control = route->control;
2095 char prefixed_sink[80];
2096 char prefixed_source[80];
2099 if (dapm->codec && dapm->codec->name_prefix) {
2100 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2101 dapm->codec->name_prefix, route->sink);
2102 sink = prefixed_sink;
2103 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2104 dapm->codec->name_prefix, route->source);
2105 source = prefixed_source;
2108 source = route->source;
2112 * find src and dest widgets over all widgets but favor a widget from
2113 * current DAPM context
2115 list_for_each_entry(w, &dapm->card->widgets, list) {
2116 if (!wsink && !(strcmp(w->name, sink))) {
2118 if (w->dapm == dapm)
2122 if (!wsource && !(strcmp(w->name, source))) {
2124 if (w->dapm == dapm)
2128 /* use widget from another DAPM context if not found from this */
2134 if (wsource == NULL || wsink == NULL)
2137 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2141 path->source = wsource;
2143 path->connected = route->connected;
2144 INIT_LIST_HEAD(&path->list);
2145 INIT_LIST_HEAD(&path->list_source);
2146 INIT_LIST_HEAD(&path->list_sink);
2148 /* check for external widgets */
2149 if (wsink->id == snd_soc_dapm_input) {
2150 if (wsource->id == snd_soc_dapm_micbias ||
2151 wsource->id == snd_soc_dapm_mic ||
2152 wsource->id == snd_soc_dapm_line ||
2153 wsource->id == snd_soc_dapm_output)
2156 if (wsource->id == snd_soc_dapm_output) {
2157 if (wsink->id == snd_soc_dapm_spk ||
2158 wsink->id == snd_soc_dapm_hp ||
2159 wsink->id == snd_soc_dapm_line ||
2160 wsink->id == snd_soc_dapm_input)
2164 /* connect static paths */
2165 if (control == NULL) {
2166 list_add(&path->list, &dapm->card->paths);
2167 list_add(&path->list_sink, &wsink->sources);
2168 list_add(&path->list_source, &wsource->sinks);
2173 /* connect dynamic paths */
2174 switch (wsink->id) {
2175 case snd_soc_dapm_adc:
2176 case snd_soc_dapm_dac:
2177 case snd_soc_dapm_pga:
2178 case snd_soc_dapm_out_drv:
2179 case snd_soc_dapm_input:
2180 case snd_soc_dapm_output:
2181 case snd_soc_dapm_siggen:
2182 case snd_soc_dapm_micbias:
2183 case snd_soc_dapm_vmid:
2184 case snd_soc_dapm_pre:
2185 case snd_soc_dapm_post:
2186 case snd_soc_dapm_supply:
2187 case snd_soc_dapm_regulator_supply:
2188 case snd_soc_dapm_aif_in:
2189 case snd_soc_dapm_aif_out:
2190 case snd_soc_dapm_dai:
2191 case snd_soc_dapm_dai_link:
2192 list_add(&path->list, &dapm->card->paths);
2193 list_add(&path->list_sink, &wsink->sources);
2194 list_add(&path->list_source, &wsource->sinks);
2197 case snd_soc_dapm_mux:
2198 case snd_soc_dapm_virt_mux:
2199 case snd_soc_dapm_value_mux:
2200 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2201 &wsink->kcontrol_news[0]);
2205 case snd_soc_dapm_switch:
2206 case snd_soc_dapm_mixer:
2207 case snd_soc_dapm_mixer_named_ctl:
2208 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2212 case snd_soc_dapm_hp:
2213 case snd_soc_dapm_mic:
2214 case snd_soc_dapm_line:
2215 case snd_soc_dapm_spk:
2216 list_add(&path->list, &dapm->card->paths);
2217 list_add(&path->list_sink, &wsink->sources);
2218 list_add(&path->list_source, &wsource->sinks);
2225 dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
2226 source, control, sink);
2232 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2233 * @dapm: DAPM context
2234 * @route: audio routes
2235 * @num: number of routes
2237 * Connects 2 dapm widgets together via a named audio path. The sink is
2238 * the widget receiving the audio signal, whilst the source is the sender
2239 * of the audio signal.
2241 * Returns 0 for success else error. On error all resources can be freed
2242 * with a call to snd_soc_card_free().
2244 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2245 const struct snd_soc_dapm_route *route, int num)
2249 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2250 for (i = 0; i < num; i++) {
2251 ret = snd_soc_dapm_add_route(dapm, route);
2253 dev_err(dapm->dev, "Failed to add route %s->%s\n",
2254 route->source, route->sink);
2259 mutex_unlock(&dapm->card->dapm_mutex);
2263 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2265 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2266 const struct snd_soc_dapm_route *route)
2268 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2271 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2274 struct snd_soc_dapm_path *path;
2278 dev_err(dapm->dev, "Unable to find source %s for weak route\n",
2284 dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
2289 if (route->control || route->connected)
2290 dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
2291 route->source, route->sink);
2293 list_for_each_entry(path, &source->sinks, list_source) {
2294 if (path->sink == sink) {
2301 dev_err(dapm->dev, "No path found for weak route %s->%s\n",
2302 route->source, route->sink);
2304 dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
2305 count, route->source, route->sink);
2311 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2312 * @dapm: DAPM context
2313 * @route: audio routes
2314 * @num: number of routes
2316 * Mark existing routes matching those specified in the passed array
2317 * as being weak, meaning that they are ignored for the purpose of
2318 * power decisions. The main intended use case is for sidetone paths
2319 * which couple audio between other independent paths if they are both
2320 * active in order to make the combination work better at the user
2321 * level but which aren't intended to be "used".
2323 * Note that CODEC drivers should not use this as sidetone type paths
2324 * can frequently also be used as bypass paths.
2326 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2327 const struct snd_soc_dapm_route *route, int num)
2332 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2333 for (i = 0; i < num; i++) {
2334 err = snd_soc_dapm_weak_route(dapm, route);
2339 mutex_unlock(&dapm->card->dapm_mutex);
2343 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2346 * snd_soc_dapm_new_widgets - add new dapm widgets
2347 * @dapm: DAPM context
2349 * Checks the codec for any new dapm widgets and creates them if found.
2351 * Returns 0 for success.
2353 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2355 struct snd_soc_dapm_widget *w;
2358 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2360 list_for_each_entry(w, &dapm->card->widgets, list)
2365 if (w->num_kcontrols) {
2366 w->kcontrols = kzalloc(w->num_kcontrols *
2367 sizeof(struct snd_kcontrol *),
2369 if (!w->kcontrols) {
2370 mutex_unlock(&dapm->card->dapm_mutex);
2376 case snd_soc_dapm_switch:
2377 case snd_soc_dapm_mixer:
2378 case snd_soc_dapm_mixer_named_ctl:
2381 case snd_soc_dapm_mux:
2382 case snd_soc_dapm_virt_mux:
2383 case snd_soc_dapm_value_mux:
2386 case snd_soc_dapm_pga:
2387 case snd_soc_dapm_out_drv:
2394 /* Read the initial power state from the device */
2396 val = soc_widget_read(w, w->reg);
2397 val &= 1 << w->shift;
2407 dapm_mark_dirty(w, "new widget");
2408 dapm_debugfs_add_widget(w);
2411 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2412 mutex_unlock(&dapm->card->dapm_mutex);
2415 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2418 * snd_soc_dapm_get_volsw - dapm mixer get callback
2419 * @kcontrol: mixer control
2420 * @ucontrol: control element information
2422 * Callback to get the value of a dapm mixer control.
2424 * Returns 0 for success.
2426 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2427 struct snd_ctl_elem_value *ucontrol)
2429 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2430 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2431 struct soc_mixer_control *mc =
2432 (struct soc_mixer_control *)kcontrol->private_value;
2433 unsigned int reg = mc->reg;
2434 unsigned int shift = mc->shift;
2435 unsigned int rshift = mc->rshift;
2437 unsigned int invert = mc->invert;
2438 unsigned int mask = (1 << fls(max)) - 1;
2440 ucontrol->value.integer.value[0] =
2441 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2442 if (shift != rshift)
2443 ucontrol->value.integer.value[1] =
2444 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
2446 ucontrol->value.integer.value[0] =
2447 max - ucontrol->value.integer.value[0];
2448 if (shift != rshift)
2449 ucontrol->value.integer.value[1] =
2450 max - ucontrol->value.integer.value[1];
2455 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2458 * snd_soc_dapm_put_volsw - dapm mixer set callback
2459 * @kcontrol: mixer control
2460 * @ucontrol: control element information
2462 * Callback to set the value of a dapm mixer control.
2464 * Returns 0 for success.
2466 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2467 struct snd_ctl_elem_value *ucontrol)
2469 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2470 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2471 struct snd_soc_codec *codec = widget->codec;
2472 struct snd_soc_card *card = codec->card;
2473 struct soc_mixer_control *mc =
2474 (struct soc_mixer_control *)kcontrol->private_value;
2475 unsigned int reg = mc->reg;
2476 unsigned int shift = mc->shift;
2478 unsigned int mask = (1 << fls(max)) - 1;
2479 unsigned int invert = mc->invert;
2481 int connect, change;
2482 struct snd_soc_dapm_update update;
2485 val = (ucontrol->value.integer.value[0] & mask);
2489 mask = mask << shift;
2493 /* new connection */
2494 connect = invert ? 0 : 1;
2496 /* old connection must be powered down */
2497 connect = invert ? 1 : 0;
2499 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2501 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2503 for (wi = 0; wi < wlist->num_widgets; wi++) {
2504 widget = wlist->widgets[wi];
2506 widget->value = val;
2508 update.kcontrol = kcontrol;
2509 update.widget = widget;
2513 widget->dapm->update = &update;
2515 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2517 widget->dapm->update = NULL;
2521 mutex_unlock(&card->dapm_mutex);
2524 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2527 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2528 * @kcontrol: mixer control
2529 * @ucontrol: control element information
2531 * Callback to get the value of a dapm enumerated double mixer control.
2533 * Returns 0 for success.
2535 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2536 struct snd_ctl_elem_value *ucontrol)
2538 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2539 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2540 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2541 unsigned int val, bitmask;
2543 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2545 val = snd_soc_read(widget->codec, e->reg);
2546 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
2547 if (e->shift_l != e->shift_r)
2548 ucontrol->value.enumerated.item[1] =
2549 (val >> e->shift_r) & (bitmask - 1);
2553 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2556 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2557 * @kcontrol: mixer control
2558 * @ucontrol: control element information
2560 * Callback to set the value of a dapm enumerated double mixer control.
2562 * Returns 0 for success.
2564 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2565 struct snd_ctl_elem_value *ucontrol)
2567 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2568 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2569 struct snd_soc_codec *codec = widget->codec;
2570 struct snd_soc_card *card = codec->card;
2571 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2572 unsigned int val, mux, change;
2573 unsigned int mask, bitmask;
2574 struct snd_soc_dapm_update update;
2577 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2579 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2581 mux = ucontrol->value.enumerated.item[0];
2582 val = mux << e->shift_l;
2583 mask = (bitmask - 1) << e->shift_l;
2584 if (e->shift_l != e->shift_r) {
2585 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2587 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2588 mask |= (bitmask - 1) << e->shift_r;
2591 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2593 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2595 for (wi = 0; wi < wlist->num_widgets; wi++) {
2596 widget = wlist->widgets[wi];
2598 widget->value = val;
2600 update.kcontrol = kcontrol;
2601 update.widget = widget;
2602 update.reg = e->reg;
2605 widget->dapm->update = &update;
2607 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2609 widget->dapm->update = NULL;
2613 mutex_unlock(&card->dapm_mutex);
2616 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2619 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2620 * @kcontrol: mixer control
2621 * @ucontrol: control element information
2623 * Returns 0 for success.
2625 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2626 struct snd_ctl_elem_value *ucontrol)
2628 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2629 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2631 ucontrol->value.enumerated.item[0] = widget->value;
2635 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2638 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2639 * @kcontrol: mixer control
2640 * @ucontrol: control element information
2642 * Returns 0 for success.
2644 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2645 struct snd_ctl_elem_value *ucontrol)
2647 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2648 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2649 struct snd_soc_codec *codec = widget->codec;
2650 struct snd_soc_card *card = codec->card;
2651 struct soc_enum *e =
2652 (struct soc_enum *)kcontrol->private_value;
2657 if (ucontrol->value.enumerated.item[0] >= e->max)
2660 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2662 change = widget->value != ucontrol->value.enumerated.item[0];
2664 for (wi = 0; wi < wlist->num_widgets; wi++) {
2665 widget = wlist->widgets[wi];
2667 widget->value = ucontrol->value.enumerated.item[0];
2669 soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
2673 mutex_unlock(&card->dapm_mutex);
2676 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2679 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2681 * @kcontrol: mixer control
2682 * @ucontrol: control element information
2684 * Callback to get the value of a dapm semi enumerated double mixer control.
2686 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2687 * used for handling bitfield coded enumeration for example.
2689 * Returns 0 for success.
2691 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2692 struct snd_ctl_elem_value *ucontrol)
2694 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2695 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2696 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2697 unsigned int reg_val, val, mux;
2699 reg_val = snd_soc_read(widget->codec, e->reg);
2700 val = (reg_val >> e->shift_l) & e->mask;
2701 for (mux = 0; mux < e->max; mux++) {
2702 if (val == e->values[mux])
2705 ucontrol->value.enumerated.item[0] = mux;
2706 if (e->shift_l != e->shift_r) {
2707 val = (reg_val >> e->shift_r) & e->mask;
2708 for (mux = 0; mux < e->max; mux++) {
2709 if (val == e->values[mux])
2712 ucontrol->value.enumerated.item[1] = mux;
2717 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2720 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2722 * @kcontrol: mixer control
2723 * @ucontrol: control element information
2725 * Callback to set the value of a dapm semi enumerated double mixer control.
2727 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2728 * used for handling bitfield coded enumeration for example.
2730 * Returns 0 for success.
2732 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2733 struct snd_ctl_elem_value *ucontrol)
2735 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2736 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2737 struct snd_soc_codec *codec = widget->codec;
2738 struct snd_soc_card *card = codec->card;
2739 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2740 unsigned int val, mux, change;
2742 struct snd_soc_dapm_update update;
2745 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2747 mux = ucontrol->value.enumerated.item[0];
2748 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2749 mask = e->mask << e->shift_l;
2750 if (e->shift_l != e->shift_r) {
2751 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2753 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2754 mask |= e->mask << e->shift_r;
2757 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2759 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2761 for (wi = 0; wi < wlist->num_widgets; wi++) {
2762 widget = wlist->widgets[wi];
2764 widget->value = val;
2766 update.kcontrol = kcontrol;
2767 update.widget = widget;
2768 update.reg = e->reg;
2771 widget->dapm->update = &update;
2773 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2775 widget->dapm->update = NULL;
2779 mutex_unlock(&card->dapm_mutex);
2782 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2785 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2787 * @kcontrol: mixer control
2788 * @uinfo: control element information
2790 * Callback to provide information about a pin switch control.
2792 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2793 struct snd_ctl_elem_info *uinfo)
2795 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2797 uinfo->value.integer.min = 0;
2798 uinfo->value.integer.max = 1;
2802 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2805 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2807 * @kcontrol: mixer control
2810 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2811 struct snd_ctl_elem_value *ucontrol)
2813 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2814 const char *pin = (const char *)kcontrol->private_value;
2816 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2818 ucontrol->value.integer.value[0] =
2819 snd_soc_dapm_get_pin_status(&card->dapm, pin);
2821 mutex_unlock(&card->dapm_mutex);
2825 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
2828 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2830 * @kcontrol: mixer control
2833 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
2834 struct snd_ctl_elem_value *ucontrol)
2836 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2837 const char *pin = (const char *)kcontrol->private_value;
2839 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2841 if (ucontrol->value.integer.value[0])
2842 snd_soc_dapm_enable_pin(&card->dapm, pin);
2844 snd_soc_dapm_disable_pin(&card->dapm, pin);
2846 mutex_unlock(&card->dapm_mutex);
2848 snd_soc_dapm_sync(&card->dapm);
2851 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
2853 static struct snd_soc_dapm_widget *
2854 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
2855 const struct snd_soc_dapm_widget *widget)
2857 struct snd_soc_dapm_widget *w;
2861 if ((w = dapm_cnew_widget(widget)) == NULL)
2865 case snd_soc_dapm_regulator_supply:
2866 w->regulator = devm_regulator_get(dapm->dev, w->name);
2867 if (IS_ERR(w->regulator)) {
2868 ret = PTR_ERR(w->regulator);
2869 dev_err(dapm->dev, "Failed to request %s: %d\n",
2878 name_len = strlen(widget->name) + 1;
2879 if (dapm->codec && dapm->codec->name_prefix)
2880 name_len += 1 + strlen(dapm->codec->name_prefix);
2881 w->name = kmalloc(name_len, GFP_KERNEL);
2882 if (w->name == NULL) {
2886 if (dapm->codec && dapm->codec->name_prefix)
2887 snprintf((char *)w->name, name_len, "%s %s",
2888 dapm->codec->name_prefix, widget->name);
2890 snprintf((char *)w->name, name_len, "%s", widget->name);
2893 case snd_soc_dapm_switch:
2894 case snd_soc_dapm_mixer:
2895 case snd_soc_dapm_mixer_named_ctl:
2896 w->power_check = dapm_generic_check_power;
2898 case snd_soc_dapm_mux:
2899 case snd_soc_dapm_virt_mux:
2900 case snd_soc_dapm_value_mux:
2901 w->power_check = dapm_generic_check_power;
2903 case snd_soc_dapm_adc:
2904 case snd_soc_dapm_aif_out:
2905 w->power_check = dapm_adc_check_power;
2907 case snd_soc_dapm_dac:
2908 case snd_soc_dapm_aif_in:
2909 w->power_check = dapm_dac_check_power;
2911 case snd_soc_dapm_pga:
2912 case snd_soc_dapm_out_drv:
2913 case snd_soc_dapm_input:
2914 case snd_soc_dapm_output:
2915 case snd_soc_dapm_micbias:
2916 case snd_soc_dapm_spk:
2917 case snd_soc_dapm_hp:
2918 case snd_soc_dapm_mic:
2919 case snd_soc_dapm_line:
2920 case snd_soc_dapm_dai_link:
2921 w->power_check = dapm_generic_check_power;
2923 case snd_soc_dapm_supply:
2924 case snd_soc_dapm_regulator_supply:
2925 w->power_check = dapm_supply_check_power;
2927 case snd_soc_dapm_dai:
2928 w->power_check = dapm_dai_check_power;
2931 w->power_check = dapm_always_on_check_power;
2937 w->codec = dapm->codec;
2938 w->platform = dapm->platform;
2939 INIT_LIST_HEAD(&w->sources);
2940 INIT_LIST_HEAD(&w->sinks);
2941 INIT_LIST_HEAD(&w->list);
2942 INIT_LIST_HEAD(&w->dirty);
2943 list_add(&w->list, &dapm->card->widgets);
2945 /* machine layer set ups unconnected pins and insertions */
2951 * snd_soc_dapm_new_controls - create new dapm controls
2952 * @dapm: DAPM context
2953 * @widget: widget array
2954 * @num: number of widgets
2956 * Creates new DAPM controls based upon the templates.
2958 * Returns 0 for success else error.
2960 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
2961 const struct snd_soc_dapm_widget *widget,
2964 struct snd_soc_dapm_widget *w;
2968 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2969 for (i = 0; i < num; i++) {
2970 w = snd_soc_dapm_new_control(dapm, widget);
2973 "ASoC: Failed to create DAPM control %s\n",
2980 mutex_unlock(&dapm->card->dapm_mutex);
2983 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
2985 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
2986 struct snd_kcontrol *kcontrol, int event)
2988 struct snd_soc_dapm_path *source_p, *sink_p;
2989 struct snd_soc_dai *source, *sink;
2990 const struct snd_soc_pcm_stream *config = w->params;
2991 struct snd_pcm_substream substream;
2992 struct snd_pcm_hw_params params;
2997 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks));
2999 /* We only support a single source and sink, pick the first */
3000 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
3002 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
3005 BUG_ON(!source_p || !sink_p);
3006 BUG_ON(!sink_p->source || !source_p->sink);
3007 BUG_ON(!source_p->source || !sink_p->sink);
3009 source = source_p->source->priv;
3010 sink = sink_p->sink->priv;
3012 /* Be a little careful as we don't want to overflow the mask array */
3013 if (config->formats) {
3014 fmt = ffs(config->formats) - 1;
3016 dev_warn(w->dapm->dev, "Invalid format %llx specified\n",
3021 /* Currently very limited parameter selection */
3022 memset(¶ms, 0, sizeof(params));
3023 snd_mask_set(hw_param_mask(¶ms, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
3025 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->min =
3027 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE)->max =
3030 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS)->min
3031 = config->channels_min;
3032 hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS)->max
3033 = config->channels_max;
3035 memset(&substream, 0, sizeof(substream));
3038 case SND_SOC_DAPM_PRE_PMU:
3039 if (source->driver->ops && source->driver->ops->hw_params) {
3040 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3041 ret = source->driver->ops->hw_params(&substream,
3044 dev_err(source->dev,
3045 "hw_params() failed: %d\n", ret);
3050 if (sink->driver->ops && sink->driver->ops->hw_params) {
3051 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3052 ret = sink->driver->ops->hw_params(&substream, ¶ms,
3056 "hw_params() failed: %d\n", ret);
3062 case SND_SOC_DAPM_POST_PMU:
3063 ret = snd_soc_dai_digital_mute(sink, 0);
3064 if (ret != 0 && ret != -ENOTSUPP)
3065 dev_warn(sink->dev, "Failed to unmute: %d\n", ret);
3068 case SND_SOC_DAPM_PRE_PMD:
3069 ret = snd_soc_dai_digital_mute(sink, 1);
3070 if (ret != 0 && ret != -ENOTSUPP)
3071 dev_warn(sink->dev, "Failed to mute: %d\n", ret);
3082 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3083 const struct snd_soc_pcm_stream *params,
3084 struct snd_soc_dapm_widget *source,
3085 struct snd_soc_dapm_widget *sink)
3087 struct snd_soc_dapm_route routes[2];
3088 struct snd_soc_dapm_widget template;
3089 struct snd_soc_dapm_widget *w;
3093 len = strlen(source->name) + strlen(sink->name) + 2;
3094 link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
3097 snprintf(link_name, len, "%s-%s", source->name, sink->name);
3099 memset(&template, 0, sizeof(template));
3100 template.reg = SND_SOC_NOPM;
3101 template.id = snd_soc_dapm_dai_link;
3102 template.name = link_name;
3103 template.event = snd_soc_dai_link_event;
3104 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3105 SND_SOC_DAPM_PRE_PMD;
3107 dev_dbg(card->dev, "adding %s widget\n", link_name);
3109 w = snd_soc_dapm_new_control(&card->dapm, &template);
3111 dev_err(card->dev, "Failed to create %s widget\n",
3118 memset(&routes, 0, sizeof(routes));
3120 routes[0].source = source->name;
3121 routes[0].sink = link_name;
3122 routes[1].source = link_name;
3123 routes[1].sink = sink->name;
3125 return snd_soc_dapm_add_routes(&card->dapm, routes,
3126 ARRAY_SIZE(routes));
3129 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3130 struct snd_soc_dai *dai)
3132 struct snd_soc_dapm_widget template;
3133 struct snd_soc_dapm_widget *w;
3135 WARN_ON(dapm->dev != dai->dev);
3137 memset(&template, 0, sizeof(template));
3138 template.reg = SND_SOC_NOPM;
3140 if (dai->driver->playback.stream_name) {
3141 template.id = snd_soc_dapm_dai;
3142 template.name = dai->driver->playback.stream_name;
3143 template.sname = dai->driver->playback.stream_name;
3145 dev_dbg(dai->dev, "adding %s widget\n",
3148 w = snd_soc_dapm_new_control(dapm, &template);
3150 dev_err(dapm->dev, "Failed to create %s widget\n",
3151 dai->driver->playback.stream_name);
3155 dai->playback_widget = w;
3158 if (dai->driver->capture.stream_name) {
3159 template.id = snd_soc_dapm_dai;
3160 template.name = dai->driver->capture.stream_name;
3161 template.sname = dai->driver->capture.stream_name;
3163 dev_dbg(dai->dev, "adding %s widget\n",
3166 w = snd_soc_dapm_new_control(dapm, &template);
3168 dev_err(dapm->dev, "Failed to create %s widget\n",
3169 dai->driver->capture.stream_name);
3173 dai->capture_widget = w;
3179 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3181 struct snd_soc_dapm_widget *dai_w, *w;
3182 struct snd_soc_dai *dai;
3183 struct snd_soc_dapm_route r;
3185 memset(&r, 0, sizeof(r));
3187 /* For each DAI widget... */
3188 list_for_each_entry(dai_w, &card->widgets, list) {
3189 if (dai_w->id != snd_soc_dapm_dai)
3194 /* ...find all widgets with the same stream and link them */
3195 list_for_each_entry(w, &card->widgets, list) {
3196 if (w->dapm != dai_w->dapm)
3199 if (w->id == snd_soc_dapm_dai)
3205 if (dai->driver->playback.stream_name &&
3207 dai->driver->playback.stream_name)) {
3208 r.source = dai->playback_widget->name;
3210 dev_dbg(dai->dev, "%s -> %s\n",
3213 snd_soc_dapm_add_route(w->dapm, &r);
3216 if (dai->driver->capture.stream_name &&
3218 dai->driver->capture.stream_name)) {
3220 r.sink = dai->capture_widget->name;
3221 dev_dbg(dai->dev, "%s -> %s\n",
3224 snd_soc_dapm_add_route(w->dapm, &r);
3232 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3236 struct snd_soc_dapm_widget *w_cpu, *w_codec;
3237 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3238 struct snd_soc_dai *codec_dai = rtd->codec_dai;
3240 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
3241 w_cpu = cpu_dai->playback_widget;
3242 w_codec = codec_dai->playback_widget;
3244 w_cpu = cpu_dai->capture_widget;
3245 w_codec = codec_dai->capture_widget;
3250 dapm_mark_dirty(w_cpu, "stream event");
3253 case SND_SOC_DAPM_STREAM_START:
3256 case SND_SOC_DAPM_STREAM_STOP:
3259 case SND_SOC_DAPM_STREAM_SUSPEND:
3260 case SND_SOC_DAPM_STREAM_RESUME:
3261 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3262 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3269 dapm_mark_dirty(w_codec, "stream event");
3272 case SND_SOC_DAPM_STREAM_START:
3273 w_codec->active = 1;
3275 case SND_SOC_DAPM_STREAM_STOP:
3276 w_codec->active = 0;
3278 case SND_SOC_DAPM_STREAM_SUSPEND:
3279 case SND_SOC_DAPM_STREAM_RESUME:
3280 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3281 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3286 dapm_power_widgets(&rtd->card->dapm, event);
3290 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3291 * @rtd: PCM runtime data
3292 * @stream: stream name
3293 * @event: stream event
3295 * Sends a stream event to the dapm core. The core then makes any
3296 * necessary widget power changes.
3298 * Returns 0 for success else error.
3300 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3303 struct snd_soc_card *card = rtd->card;
3305 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3306 soc_dapm_stream_event(rtd, stream, event);
3307 mutex_unlock(&card->dapm_mutex);
3311 * snd_soc_dapm_enable_pin - enable pin.
3312 * @dapm: DAPM context
3315 * Enables input/output pin and its parents or children widgets iff there is
3316 * a valid audio route and active audio stream.
3317 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3318 * do any widget power switching.
3320 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3322 return snd_soc_dapm_set_pin(dapm, pin, 1);
3324 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3327 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3328 * @dapm: DAPM context
3331 * Enables input/output pin regardless of any other state. This is
3332 * intended for use with microphone bias supplies used in microphone
3335 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3336 * do any widget power switching.
3338 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3341 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3344 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3348 dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
3351 dapm_mark_dirty(w, "force enable");
3355 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
3358 * snd_soc_dapm_disable_pin - disable pin.
3359 * @dapm: DAPM context
3362 * Disables input/output pin and its parents or children widgets.
3363 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3364 * do any widget power switching.
3366 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
3369 return snd_soc_dapm_set_pin(dapm, pin, 0);
3371 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3374 * snd_soc_dapm_nc_pin - permanently disable pin.
3375 * @dapm: DAPM context
3378 * Marks the specified pin as being not connected, disabling it along
3379 * any parent or child widgets. At present this is identical to
3380 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3381 * additional things such as disabling controls which only affect
3382 * paths through the pin.
3384 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3385 * do any widget power switching.
3387 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3389 return snd_soc_dapm_set_pin(dapm, pin, 0);
3391 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
3394 * snd_soc_dapm_get_pin_status - get audio pin status
3395 * @dapm: DAPM context
3396 * @pin: audio signal pin endpoint (or start point)
3398 * Get audio pin status - connected or disconnected.
3400 * Returns 1 for connected otherwise 0.
3402 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
3405 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3408 return w->connected;
3412 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
3415 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3416 * @dapm: DAPM context
3417 * @pin: audio signal pin endpoint (or start point)
3419 * Mark the given endpoint or pin as ignoring suspend. When the
3420 * system is disabled a path between two endpoints flagged as ignoring
3421 * suspend will not be disabled. The path must already be enabled via
3422 * normal means at suspend time, it will not be turned on if it was not
3425 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
3428 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
3431 dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
3435 w->ignore_suspend = 1;
3439 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3441 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
3442 struct snd_soc_dapm_widget *w)
3444 struct snd_soc_dapm_path *p;
3446 list_for_each_entry(p, &card->paths, list) {
3447 if ((p->source == w) || (p->sink == w)) {
3449 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3450 p->source->name, p->source->id, p->source->dapm,
3451 p->sink->name, p->sink->id, p->sink->dapm);
3453 /* Connected to something other than the codec */
3454 if (p->source->dapm != p->sink->dapm)
3457 * Loopback connection from codec external pin to
3458 * codec external pin
3460 if (p->sink->id == snd_soc_dapm_input) {
3461 switch (p->source->id) {
3462 case snd_soc_dapm_output:
3463 case snd_soc_dapm_micbias:
3476 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3477 * @codec: The codec whose pins should be processed
3479 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3480 * which are unused. Pins are used if they are connected externally to the
3481 * codec, whether that be to some other device, or a loop-back connection to
3484 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
3486 struct snd_soc_card *card = codec->card;
3487 struct snd_soc_dapm_context *dapm = &codec->dapm;
3488 struct snd_soc_dapm_widget *w;
3490 dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n",
3491 &card->dapm, &codec->dapm);
3493 list_for_each_entry(w, &card->widgets, list) {
3494 if (w->dapm != dapm)
3497 case snd_soc_dapm_input:
3498 case snd_soc_dapm_output:
3499 case snd_soc_dapm_micbias:
3500 dev_dbg(codec->dev, "Auto NC: Checking widget %s\n",
3502 if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
3504 "... Not in map; disabling\n");
3505 snd_soc_dapm_nc_pin(dapm, w->name);
3515 * snd_soc_dapm_free - free dapm resources
3516 * @dapm: DAPM context
3518 * Free all dapm widgets and resources.
3520 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
3522 snd_soc_dapm_sys_remove(dapm->dev);
3523 dapm_debugfs_cleanup(dapm);
3524 dapm_free_widgets(dapm);
3525 list_del(&dapm->list);
3527 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
3529 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
3531 struct snd_soc_dapm_widget *w;
3532 LIST_HEAD(down_list);
3535 list_for_each_entry(w, &dapm->card->widgets, list) {
3536 if (w->dapm != dapm)
3539 dapm_seq_insert(w, &down_list, false);
3545 /* If there were no widgets to power down we're already in
3549 if (dapm->bias_level == SND_SOC_BIAS_ON)
3550 snd_soc_dapm_set_bias_level(dapm,
3551 SND_SOC_BIAS_PREPARE);
3552 dapm_seq_run(dapm, &down_list, 0, false);
3553 if (dapm->bias_level == SND_SOC_BIAS_PREPARE)
3554 snd_soc_dapm_set_bias_level(dapm,
3555 SND_SOC_BIAS_STANDBY);
3560 * snd_soc_dapm_shutdown - callback for system shutdown
3562 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
3564 struct snd_soc_codec *codec;
3566 list_for_each_entry(codec, &card->codec_dev_list, list) {
3567 soc_dapm_shutdown_codec(&codec->dapm);
3568 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
3569 snd_soc_dapm_set_bias_level(&codec->dapm,
3574 /* Module information */
3575 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3576 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3577 MODULE_LICENSE("GPL");