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/clk.h>
39 #include <linux/slab.h>
40 #include <sound/core.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc.h>
44 #include <sound/initval.h>
46 #include <trace/events/asoc.h>
48 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
50 /* dapm power sequences - make this per codec in the future */
51 static int dapm_up_seq[] = {
52 [snd_soc_dapm_pre] = 0,
53 [snd_soc_dapm_supply] = 1,
54 [snd_soc_dapm_regulator_supply] = 1,
55 [snd_soc_dapm_clock_supply] = 1,
56 [snd_soc_dapm_micbias] = 2,
57 [snd_soc_dapm_dai_link] = 2,
58 [snd_soc_dapm_dai_in] = 3,
59 [snd_soc_dapm_dai_out] = 3,
60 [snd_soc_dapm_aif_in] = 3,
61 [snd_soc_dapm_aif_out] = 3,
62 [snd_soc_dapm_mic] = 4,
63 [snd_soc_dapm_mux] = 5,
64 [snd_soc_dapm_virt_mux] = 5,
65 [snd_soc_dapm_value_mux] = 5,
66 [snd_soc_dapm_dac] = 6,
67 [snd_soc_dapm_switch] = 7,
68 [snd_soc_dapm_mixer] = 7,
69 [snd_soc_dapm_mixer_named_ctl] = 7,
70 [snd_soc_dapm_pga] = 8,
71 [snd_soc_dapm_adc] = 9,
72 [snd_soc_dapm_out_drv] = 10,
73 [snd_soc_dapm_hp] = 10,
74 [snd_soc_dapm_spk] = 10,
75 [snd_soc_dapm_line] = 10,
76 [snd_soc_dapm_post] = 11,
79 static int dapm_down_seq[] = {
80 [snd_soc_dapm_pre] = 0,
81 [snd_soc_dapm_adc] = 1,
82 [snd_soc_dapm_hp] = 2,
83 [snd_soc_dapm_spk] = 2,
84 [snd_soc_dapm_line] = 2,
85 [snd_soc_dapm_out_drv] = 2,
86 [snd_soc_dapm_pga] = 4,
87 [snd_soc_dapm_switch] = 5,
88 [snd_soc_dapm_mixer_named_ctl] = 5,
89 [snd_soc_dapm_mixer] = 5,
90 [snd_soc_dapm_dac] = 6,
91 [snd_soc_dapm_mic] = 7,
92 [snd_soc_dapm_micbias] = 8,
93 [snd_soc_dapm_mux] = 9,
94 [snd_soc_dapm_virt_mux] = 9,
95 [snd_soc_dapm_value_mux] = 9,
96 [snd_soc_dapm_aif_in] = 10,
97 [snd_soc_dapm_aif_out] = 10,
98 [snd_soc_dapm_dai_in] = 10,
99 [snd_soc_dapm_dai_out] = 10,
100 [snd_soc_dapm_dai_link] = 11,
101 [snd_soc_dapm_clock_supply] = 12,
102 [snd_soc_dapm_regulator_supply] = 12,
103 [snd_soc_dapm_supply] = 12,
104 [snd_soc_dapm_post] = 13,
107 static void pop_wait(u32 pop_time)
110 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
113 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
121 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
126 vsnprintf(buf, PAGE_SIZE, fmt, args);
127 dev_info(dev, "%s", buf);
133 static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
135 return !list_empty(&w->dirty);
138 void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
140 if (!dapm_dirty_widget(w)) {
141 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
143 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
146 EXPORT_SYMBOL_GPL(dapm_mark_dirty);
148 void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm)
150 struct snd_soc_card *card = dapm->card;
151 struct snd_soc_dapm_widget *w;
153 mutex_lock(&card->dapm_mutex);
155 list_for_each_entry(w, &card->widgets, list) {
157 case snd_soc_dapm_input:
158 case snd_soc_dapm_output:
159 dapm_mark_dirty(w, "Rechecking inputs and outputs");
166 mutex_unlock(&card->dapm_mutex);
168 EXPORT_SYMBOL_GPL(dapm_mark_io_dirty);
170 /* create a new dapm widget */
171 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
172 const struct snd_soc_dapm_widget *_widget)
174 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
177 /* get snd_card from DAPM context */
178 static inline struct snd_card *dapm_get_snd_card(
179 struct snd_soc_dapm_context *dapm)
182 return dapm->codec->card->snd_card;
183 else if (dapm->platform)
184 return dapm->platform->card->snd_card;
192 /* get soc_card from DAPM context */
193 static inline struct snd_soc_card *dapm_get_soc_card(
194 struct snd_soc_dapm_context *dapm)
197 return dapm->codec->card;
198 else if (dapm->platform)
199 return dapm->platform->card;
207 static void dapm_reset(struct snd_soc_card *card)
209 struct snd_soc_dapm_widget *w;
211 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
213 list_for_each_entry(w, &card->widgets, list) {
214 w->power_checked = false;
220 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
223 return snd_soc_read(w->codec, reg);
224 else if (w->platform)
225 return snd_soc_platform_read(w->platform, reg);
227 dev_err(w->dapm->dev, "ASoC: no valid widget read method\n");
231 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
234 return snd_soc_write(w->codec, reg, val);
235 else if (w->platform)
236 return snd_soc_platform_write(w->platform, reg, val);
238 dev_err(w->dapm->dev, "ASoC: no valid widget write method\n");
242 static inline void soc_widget_lock(struct snd_soc_dapm_widget *w)
244 if (w->codec && !w->codec->using_regmap)
245 mutex_lock(&w->codec->mutex);
246 else if (w->platform)
247 mutex_lock(&w->platform->mutex);
250 static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w)
252 if (w->codec && !w->codec->using_regmap)
253 mutex_unlock(&w->codec->mutex);
254 else if (w->platform)
255 mutex_unlock(&w->platform->mutex);
258 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
259 unsigned short reg, unsigned int mask, unsigned int value)
262 unsigned int old, new;
265 if (w->codec && w->codec->using_regmap) {
266 ret = regmap_update_bits_check(w->codec->control_data,
267 reg, mask, value, &change);
272 ret = soc_widget_read(w, reg);
274 soc_widget_unlock(w);
279 new = (old & ~mask) | (value & mask);
282 ret = soc_widget_write(w, reg, new);
284 soc_widget_unlock(w);
288 soc_widget_unlock(w);
295 * snd_soc_dapm_set_bias_level - set the bias level for the system
296 * @dapm: DAPM context
297 * @level: level to configure
299 * Configure the bias (power) levels for the SoC audio device.
301 * Returns 0 for success else error.
303 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
304 enum snd_soc_bias_level level)
306 struct snd_soc_card *card = dapm->card;
309 trace_snd_soc_bias_level_start(card, level);
311 if (card && card->set_bias_level)
312 ret = card->set_bias_level(card, dapm, level);
317 if (dapm->codec->driver->set_bias_level)
318 ret = dapm->codec->driver->set_bias_level(dapm->codec,
321 dapm->bias_level = level;
322 } else if (!card || dapm != &card->dapm) {
323 dapm->bias_level = level;
329 if (card && card->set_bias_level_post)
330 ret = card->set_bias_level_post(card, dapm, level);
332 trace_snd_soc_bias_level_done(card, level);
337 /* set up initial codec paths */
338 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
339 struct snd_soc_dapm_path *p, int i)
342 case snd_soc_dapm_switch:
343 case snd_soc_dapm_mixer:
344 case snd_soc_dapm_mixer_named_ctl: {
346 struct soc_mixer_control *mc = (struct soc_mixer_control *)
347 w->kcontrol_news[i].private_value;
348 unsigned int reg = mc->reg;
349 unsigned int shift = mc->shift;
351 unsigned int mask = (1 << fls(max)) - 1;
352 unsigned int invert = mc->invert;
354 val = soc_widget_read(w, reg);
355 val = (val >> shift) & mask;
362 case snd_soc_dapm_mux: {
363 struct soc_enum *e = (struct soc_enum *)
364 w->kcontrol_news[i].private_value;
367 val = soc_widget_read(w, e->reg);
368 item = (val >> e->shift_l) & e->mask;
371 for (i = 0; i < e->max; i++) {
372 if (!(strcmp(p->name, e->texts[i])) && item == i)
377 case snd_soc_dapm_virt_mux: {
378 struct soc_enum *e = (struct soc_enum *)
379 w->kcontrol_news[i].private_value;
382 /* since a virtual mux has no backing registers to
383 * decide which path to connect, it will try to match
384 * with the first enumeration. This is to ensure
385 * that the default mux choice (the first) will be
386 * correctly powered up during initialization.
388 if (!strcmp(p->name, e->texts[0]))
392 case snd_soc_dapm_value_mux: {
393 struct soc_enum *e = (struct soc_enum *)
394 w->kcontrol_news[i].private_value;
397 val = soc_widget_read(w, e->reg);
398 val = (val >> e->shift_l) & e->mask;
399 for (item = 0; item < e->max; item++) {
400 if (val == e->values[item])
405 for (i = 0; i < e->max; i++) {
406 if (!(strcmp(p->name, e->texts[i])) && item == i)
411 /* does not affect routing - always connected */
412 case snd_soc_dapm_pga:
413 case snd_soc_dapm_out_drv:
414 case snd_soc_dapm_output:
415 case snd_soc_dapm_adc:
416 case snd_soc_dapm_input:
417 case snd_soc_dapm_siggen:
418 case snd_soc_dapm_dac:
419 case snd_soc_dapm_micbias:
420 case snd_soc_dapm_vmid:
421 case snd_soc_dapm_supply:
422 case snd_soc_dapm_regulator_supply:
423 case snd_soc_dapm_clock_supply:
424 case snd_soc_dapm_aif_in:
425 case snd_soc_dapm_aif_out:
426 case snd_soc_dapm_dai_in:
427 case snd_soc_dapm_dai_out:
428 case snd_soc_dapm_hp:
429 case snd_soc_dapm_mic:
430 case snd_soc_dapm_spk:
431 case snd_soc_dapm_line:
432 case snd_soc_dapm_dai_link:
435 /* does affect routing - dynamically connected */
436 case snd_soc_dapm_pre:
437 case snd_soc_dapm_post:
443 /* connect mux widget to its interconnecting audio paths */
444 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
445 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
446 struct snd_soc_dapm_path *path, const char *control_name,
447 const struct snd_kcontrol_new *kcontrol)
449 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
452 for (i = 0; i < e->max; i++) {
453 if (!(strcmp(control_name, e->texts[i]))) {
454 list_add(&path->list, &dapm->card->paths);
455 list_add(&path->list_sink, &dest->sources);
456 list_add(&path->list_source, &src->sinks);
457 path->name = (char*)e->texts[i];
458 dapm_set_path_status(dest, path, 0);
466 /* connect mixer widget to its interconnecting audio paths */
467 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
468 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
469 struct snd_soc_dapm_path *path, const char *control_name)
473 /* search for mixer kcontrol */
474 for (i = 0; i < dest->num_kcontrols; i++) {
475 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
476 list_add(&path->list, &dapm->card->paths);
477 list_add(&path->list_sink, &dest->sources);
478 list_add(&path->list_source, &src->sinks);
479 path->name = dest->kcontrol_news[i].name;
480 dapm_set_path_status(dest, path, i);
487 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
488 struct snd_soc_dapm_widget *kcontrolw,
489 const struct snd_kcontrol_new *kcontrol_new,
490 struct snd_kcontrol **kcontrol)
492 struct snd_soc_dapm_widget *w;
497 list_for_each_entry(w, &dapm->card->widgets, list) {
498 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
500 for (i = 0; i < w->num_kcontrols; i++) {
501 if (&w->kcontrol_news[i] == kcontrol_new) {
503 *kcontrol = w->kcontrols[i];
513 * Determine if a kcontrol is shared. If it is, look it up. If it isn't,
514 * create it. Either way, add the widget into the control's widget list
516 static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
517 int kci, struct snd_soc_dapm_path *path)
519 struct snd_soc_dapm_context *dapm = w->dapm;
520 struct snd_card *card = dapm->card->snd_card;
524 struct snd_kcontrol *kcontrol;
525 struct snd_soc_dapm_widget_list *wlist;
528 bool wname_in_long_name, kcname_in_long_name;
535 prefix = dapm->codec->name_prefix;
540 prefix_len = strlen(prefix) + 1;
544 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[kci],
548 wlist = kcontrol->private_data;
549 wlistentries = wlist->num_widgets + 1;
555 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
556 wlistentries * sizeof(struct snd_soc_dapm_widget *);
557 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
559 dev_err(dapm->dev, "ASoC: can't allocate widget list for %s\n",
563 wlist->num_widgets = wlistentries;
564 wlist->widgets[wlistentries - 1] = w;
568 wname_in_long_name = false;
569 kcname_in_long_name = true;
572 case snd_soc_dapm_switch:
573 case snd_soc_dapm_mixer:
574 wname_in_long_name = true;
575 kcname_in_long_name = true;
577 case snd_soc_dapm_mixer_named_ctl:
578 wname_in_long_name = false;
579 kcname_in_long_name = true;
581 case snd_soc_dapm_mux:
582 case snd_soc_dapm_virt_mux:
583 case snd_soc_dapm_value_mux:
584 wname_in_long_name = true;
585 kcname_in_long_name = false;
593 if (wname_in_long_name && kcname_in_long_name) {
594 name_len = strlen(w->name) - prefix_len + 1 +
595 strlen(w->kcontrol_news[kci].name) + 1;
597 long_name = kmalloc(name_len, GFP_KERNEL);
598 if (long_name == NULL) {
604 * The control will get a prefix from the control
605 * creation process but we're also using the same
606 * prefix for widgets so cut the prefix off the
607 * front of the widget name.
609 snprintf(long_name, name_len, "%s %s",
610 w->name + prefix_len,
611 w->kcontrol_news[kci].name);
612 long_name[name_len - 1] = '\0';
615 } else if (wname_in_long_name) {
617 name = w->name + prefix_len;
620 name = w->kcontrol_news[kci].name;
623 kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], wlist, name,
625 ret = snd_ctl_add(card, kcontrol);
628 "ASoC: failed to add widget %s dapm kcontrol %s: %d\n",
635 path->long_name = long_name;
638 kcontrol->private_data = wlist;
639 w->kcontrols[kci] = kcontrol;
640 path->kcontrol = kcontrol;
645 /* create new dapm mixer control */
646 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
649 struct snd_soc_dapm_path *path;
652 for (i = 0; i < w->num_kcontrols; i++) {
654 list_for_each_entry(path, &w->sources, list_sink) {
655 /* mixer/mux paths name must match control name */
656 if (path->name != (char *)w->kcontrol_news[i].name)
659 if (w->kcontrols[i]) {
660 path->kcontrol = w->kcontrols[i];
664 ret = dapm_create_or_share_mixmux_kcontrol(w, i, path);
673 /* create new dapm mux control */
674 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
676 struct snd_soc_dapm_context *dapm = w->dapm;
677 struct snd_soc_dapm_path *path;
680 if (w->num_kcontrols != 1) {
682 "ASoC: mux %s has incorrect number of controls\n",
687 path = list_first_entry(&w->sources, struct snd_soc_dapm_path,
690 dev_err(dapm->dev, "ASoC: mux %s has no paths\n", w->name);
694 ret = dapm_create_or_share_mixmux_kcontrol(w, 0, path);
698 list_for_each_entry(path, &w->sources, list_sink)
699 path->kcontrol = w->kcontrols[0];
704 /* create new dapm volume control */
705 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
707 if (w->num_kcontrols)
708 dev_err(w->dapm->dev,
709 "ASoC: PGA controls not supported: '%s'\n", w->name);
714 /* reset 'walked' bit for each dapm path */
715 static void dapm_clear_walk_output(struct snd_soc_dapm_context *dapm,
716 struct list_head *sink)
718 struct snd_soc_dapm_path *p;
720 list_for_each_entry(p, sink, list_source) {
723 dapm_clear_walk_output(dapm, &p->sink->sinks);
728 static void dapm_clear_walk_input(struct snd_soc_dapm_context *dapm,
729 struct list_head *source)
731 struct snd_soc_dapm_path *p;
733 list_for_each_entry(p, source, list_sink) {
736 dapm_clear_walk_input(dapm, &p->source->sources);
742 /* We implement power down on suspend by checking the power state of
743 * the ALSA card - when we are suspending the ALSA state for the card
746 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
748 int level = snd_power_get_state(widget->dapm->card->snd_card);
751 case SNDRV_CTL_POWER_D3hot:
752 case SNDRV_CTL_POWER_D3cold:
753 if (widget->ignore_suspend)
754 dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n",
756 return widget->ignore_suspend;
762 /* add widget to list if it's not already in the list */
763 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list,
764 struct snd_soc_dapm_widget *w)
766 struct snd_soc_dapm_widget_list *wlist;
767 int wlistsize, wlistentries, i;
774 /* is this widget already in the list */
775 for (i = 0; i < wlist->num_widgets; i++) {
776 if (wlist->widgets[i] == w)
780 /* allocate some new space */
781 wlistentries = wlist->num_widgets + 1;
782 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
783 wlistentries * sizeof(struct snd_soc_dapm_widget *);
784 *list = krealloc(wlist, wlistsize, GFP_KERNEL);
786 dev_err(w->dapm->dev, "ASoC: can't allocate widget list for %s\n",
792 /* insert the widget */
793 dev_dbg(w->dapm->dev, "ASoC: added %s in widget list pos %d\n",
794 w->name, wlist->num_widgets);
796 wlist->widgets[wlist->num_widgets] = w;
797 wlist->num_widgets++;
802 * Recursively check for a completed path to an active or physically connected
803 * output widget. Returns number of complete paths.
805 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
806 struct snd_soc_dapm_widget_list **list)
808 struct snd_soc_dapm_path *path;
811 if (widget->outputs >= 0)
812 return widget->outputs;
814 DAPM_UPDATE_STAT(widget, path_checks);
816 switch (widget->id) {
817 case snd_soc_dapm_supply:
818 case snd_soc_dapm_regulator_supply:
819 case snd_soc_dapm_clock_supply:
825 switch (widget->id) {
826 case snd_soc_dapm_adc:
827 case snd_soc_dapm_aif_out:
828 case snd_soc_dapm_dai_out:
829 if (widget->active) {
830 widget->outputs = snd_soc_dapm_suspend_check(widget);
831 return widget->outputs;
837 if (widget->connected) {
838 /* connected pin ? */
839 if (widget->id == snd_soc_dapm_output && !widget->ext) {
840 widget->outputs = snd_soc_dapm_suspend_check(widget);
841 return widget->outputs;
844 /* connected jack or spk ? */
845 if (widget->id == snd_soc_dapm_hp ||
846 widget->id == snd_soc_dapm_spk ||
847 (widget->id == snd_soc_dapm_line &&
848 !list_empty(&widget->sources))) {
849 widget->outputs = snd_soc_dapm_suspend_check(widget);
850 return widget->outputs;
854 list_for_each_entry(path, &widget->sinks, list_source) {
855 DAPM_UPDATE_STAT(widget, neighbour_checks);
866 trace_snd_soc_dapm_output_path(widget, path);
868 if (path->sink && path->connect) {
872 /* do we need to add this widget to the list ? */
875 err = dapm_list_add_widget(list, path->sink);
877 dev_err(widget->dapm->dev,
878 "ASoC: could not add widget %s\n",
885 con += is_connected_output_ep(path->sink, list);
891 widget->outputs = con;
897 * Recursively check for a completed path to an active or physically connected
898 * input widget. Returns number of complete paths.
900 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
901 struct snd_soc_dapm_widget_list **list)
903 struct snd_soc_dapm_path *path;
906 if (widget->inputs >= 0)
907 return widget->inputs;
909 DAPM_UPDATE_STAT(widget, path_checks);
911 switch (widget->id) {
912 case snd_soc_dapm_supply:
913 case snd_soc_dapm_regulator_supply:
914 case snd_soc_dapm_clock_supply:
920 /* active stream ? */
921 switch (widget->id) {
922 case snd_soc_dapm_dac:
923 case snd_soc_dapm_aif_in:
924 case snd_soc_dapm_dai_in:
925 if (widget->active) {
926 widget->inputs = snd_soc_dapm_suspend_check(widget);
927 return widget->inputs;
933 if (widget->connected) {
934 /* connected pin ? */
935 if (widget->id == snd_soc_dapm_input && !widget->ext) {
936 widget->inputs = snd_soc_dapm_suspend_check(widget);
937 return widget->inputs;
940 /* connected VMID/Bias for lower pops */
941 if (widget->id == snd_soc_dapm_vmid) {
942 widget->inputs = snd_soc_dapm_suspend_check(widget);
943 return widget->inputs;
946 /* connected jack ? */
947 if (widget->id == snd_soc_dapm_mic ||
948 (widget->id == snd_soc_dapm_line &&
949 !list_empty(&widget->sinks))) {
950 widget->inputs = snd_soc_dapm_suspend_check(widget);
951 return widget->inputs;
954 /* signal generator */
955 if (widget->id == snd_soc_dapm_siggen) {
956 widget->inputs = snd_soc_dapm_suspend_check(widget);
957 return widget->inputs;
961 list_for_each_entry(path, &widget->sources, list_sink) {
962 DAPM_UPDATE_STAT(widget, neighbour_checks);
973 trace_snd_soc_dapm_input_path(widget, path);
975 if (path->source && path->connect) {
979 /* do we need to add this widget to the list ? */
982 err = dapm_list_add_widget(list, path->source);
984 dev_err(widget->dapm->dev,
985 "ASoC: could not add widget %s\n",
992 con += is_connected_input_ep(path->source, list);
998 widget->inputs = con;
1004 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
1005 * @dai: the soc DAI.
1006 * @stream: stream direction.
1007 * @list: list of active widgets for this stream.
1009 * Queries DAPM graph as to whether an valid audio stream path exists for
1010 * the initial stream specified by name. This takes into account
1011 * current mixer and mux kcontrol settings. Creates list of valid widgets.
1013 * Returns the number of valid paths or negative error.
1015 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
1016 struct snd_soc_dapm_widget_list **list)
1018 struct snd_soc_card *card = dai->card;
1021 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1024 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
1025 paths = is_connected_output_ep(dai->playback_widget, list);
1026 dapm_clear_walk_output(&card->dapm,
1027 &dai->playback_widget->sinks);
1029 paths = is_connected_input_ep(dai->capture_widget, list);
1030 dapm_clear_walk_input(&card->dapm,
1031 &dai->capture_widget->sources);
1034 trace_snd_soc_dapm_connected(paths, stream);
1035 mutex_unlock(&card->dapm_mutex);
1041 * Handler for generic register modifier widget.
1043 int dapm_reg_event(struct snd_soc_dapm_widget *w,
1044 struct snd_kcontrol *kcontrol, int event)
1048 if (SND_SOC_DAPM_EVENT_ON(event))
1053 soc_widget_update_bits_locked(w, -(w->reg + 1),
1054 w->mask << w->shift, val << w->shift);
1058 EXPORT_SYMBOL_GPL(dapm_reg_event);
1061 * Handler for regulator supply widget.
1063 int dapm_regulator_event(struct snd_soc_dapm_widget *w,
1064 struct snd_kcontrol *kcontrol, int event)
1068 if (SND_SOC_DAPM_EVENT_ON(event)) {
1069 if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) {
1070 ret = regulator_allow_bypass(w->regulator, false);
1072 dev_warn(w->dapm->dev,
1073 "ASoC: Failed to bypass %s: %d\n",
1077 return regulator_enable(w->regulator);
1079 if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) {
1080 ret = regulator_allow_bypass(w->regulator, true);
1082 dev_warn(w->dapm->dev,
1083 "ASoC: Failed to unbypass %s: %d\n",
1087 return regulator_disable_deferred(w->regulator, w->shift);
1090 EXPORT_SYMBOL_GPL(dapm_regulator_event);
1093 * Handler for clock supply widget.
1095 int dapm_clock_event(struct snd_soc_dapm_widget *w,
1096 struct snd_kcontrol *kcontrol, int event)
1101 #ifdef CONFIG_HAVE_CLK
1102 if (SND_SOC_DAPM_EVENT_ON(event)) {
1103 return clk_prepare_enable(w->clk);
1105 clk_disable_unprepare(w->clk);
1111 EXPORT_SYMBOL_GPL(dapm_clock_event);
1113 static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
1115 if (w->power_checked)
1116 return w->new_power;
1121 w->new_power = w->power_check(w);
1123 w->power_checked = true;
1125 return w->new_power;
1128 /* Generic check to see if a widget should be powered.
1130 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
1134 DAPM_UPDATE_STAT(w, power_checks);
1136 in = is_connected_input_ep(w, NULL);
1137 dapm_clear_walk_input(w->dapm, &w->sources);
1138 out = is_connected_output_ep(w, NULL);
1139 dapm_clear_walk_output(w->dapm, &w->sinks);
1140 return out != 0 && in != 0;
1143 /* Check to see if an ADC has power */
1144 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
1148 DAPM_UPDATE_STAT(w, power_checks);
1151 in = is_connected_input_ep(w, NULL);
1152 dapm_clear_walk_input(w->dapm, &w->sources);
1155 return dapm_generic_check_power(w);
1159 /* Check to see if a DAC has power */
1160 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
1164 DAPM_UPDATE_STAT(w, power_checks);
1167 out = is_connected_output_ep(w, NULL);
1168 dapm_clear_walk_output(w->dapm, &w->sinks);
1171 return dapm_generic_check_power(w);
1175 /* Check to see if a power supply is needed */
1176 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1178 struct snd_soc_dapm_path *path;
1180 DAPM_UPDATE_STAT(w, power_checks);
1182 /* Check if one of our outputs is connected */
1183 list_for_each_entry(path, &w->sinks, list_source) {
1184 DAPM_UPDATE_STAT(w, neighbour_checks);
1189 if (path->connected &&
1190 !path->connected(path->source, path->sink))
1196 if (dapm_widget_power_check(path->sink))
1203 static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
1208 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
1209 struct snd_soc_dapm_widget *b,
1217 sort = dapm_down_seq;
1219 if (sort[a->id] != sort[b->id])
1220 return sort[a->id] - sort[b->id];
1221 if (a->subseq != b->subseq) {
1223 return a->subseq - b->subseq;
1225 return b->subseq - a->subseq;
1227 if (a->reg != b->reg)
1228 return a->reg - b->reg;
1229 if (a->dapm != b->dapm)
1230 return (unsigned long)a->dapm - (unsigned long)b->dapm;
1235 /* Insert a widget in order into a DAPM power sequence. */
1236 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
1237 struct list_head *list,
1240 struct snd_soc_dapm_widget *w;
1242 list_for_each_entry(w, list, power_list)
1243 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
1244 list_add_tail(&new_widget->power_list, &w->power_list);
1248 list_add_tail(&new_widget->power_list, list);
1251 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
1252 struct snd_soc_dapm_widget *w, int event)
1254 struct snd_soc_card *card = dapm->card;
1255 const char *ev_name;
1259 case SND_SOC_DAPM_PRE_PMU:
1260 ev_name = "PRE_PMU";
1263 case SND_SOC_DAPM_POST_PMU:
1264 ev_name = "POST_PMU";
1267 case SND_SOC_DAPM_PRE_PMD:
1268 ev_name = "PRE_PMD";
1271 case SND_SOC_DAPM_POST_PMD:
1272 ev_name = "POST_PMD";
1280 if (w->power != power)
1283 if (w->event && (w->event_flags & event)) {
1284 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
1286 trace_snd_soc_dapm_widget_event_start(w, event);
1287 ret = w->event(w, NULL, event);
1288 trace_snd_soc_dapm_widget_event_done(w, event);
1290 dev_err(dapm->dev, "ASoC: %s: %s event failed: %d\n",
1291 ev_name, w->name, ret);
1295 /* Apply the coalesced changes from a DAPM sequence */
1296 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
1297 struct list_head *pending)
1299 struct snd_soc_card *card = dapm->card;
1300 struct snd_soc_dapm_widget *w;
1302 unsigned int value = 0;
1303 unsigned int mask = 0;
1304 unsigned int cur_mask;
1306 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
1309 list_for_each_entry(w, pending, power_list) {
1310 cur_mask = 1 << w->shift;
1311 BUG_ON(reg != w->reg);
1322 pop_dbg(dapm->dev, card->pop_time,
1323 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1324 w->name, reg, value, mask);
1326 /* Check for events */
1327 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
1328 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
1332 /* Any widget will do, they should all be updating the
1335 w = list_first_entry(pending, struct snd_soc_dapm_widget,
1338 pop_dbg(dapm->dev, card->pop_time,
1339 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1340 value, mask, reg, card->pop_time);
1341 pop_wait(card->pop_time);
1342 soc_widget_update_bits_locked(w, reg, mask, value);
1345 list_for_each_entry(w, pending, power_list) {
1346 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
1347 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
1351 /* Apply a DAPM power sequence.
1353 * We walk over a pre-sorted list of widgets to apply power to. In
1354 * order to minimise the number of writes to the device required
1355 * multiple widgets will be updated in a single write where possible.
1356 * Currently anything that requires more than a single write is not
1359 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1360 struct list_head *list, int event, bool power_up)
1362 struct snd_soc_dapm_widget *w, *n;
1365 int cur_subseq = -1;
1366 int cur_reg = SND_SOC_NOPM;
1367 struct snd_soc_dapm_context *cur_dapm = NULL;
1374 sort = dapm_down_seq;
1376 list_for_each_entry_safe(w, n, list, power_list) {
1379 /* Do we need to apply any queued changes? */
1380 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1381 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1382 if (!list_empty(&pending))
1383 dapm_seq_run_coalesced(cur_dapm, &pending);
1385 if (cur_dapm && cur_dapm->seq_notifier) {
1386 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1387 if (sort[i] == cur_sort)
1388 cur_dapm->seq_notifier(cur_dapm,
1393 INIT_LIST_HEAD(&pending);
1395 cur_subseq = INT_MIN;
1396 cur_reg = SND_SOC_NOPM;
1401 case snd_soc_dapm_pre:
1403 list_for_each_entry_safe_continue(w, n, list,
1406 if (event == SND_SOC_DAPM_STREAM_START)
1408 NULL, SND_SOC_DAPM_PRE_PMU);
1409 else if (event == SND_SOC_DAPM_STREAM_STOP)
1411 NULL, SND_SOC_DAPM_PRE_PMD);
1414 case snd_soc_dapm_post:
1416 list_for_each_entry_safe_continue(w, n, list,
1419 if (event == SND_SOC_DAPM_STREAM_START)
1421 NULL, SND_SOC_DAPM_POST_PMU);
1422 else if (event == SND_SOC_DAPM_STREAM_STOP)
1424 NULL, SND_SOC_DAPM_POST_PMD);
1428 /* Queue it up for application */
1429 cur_sort = sort[w->id];
1430 cur_subseq = w->subseq;
1433 list_move(&w->power_list, &pending);
1438 dev_err(w->dapm->dev,
1439 "ASoC: Failed to apply widget power: %d\n", ret);
1442 if (!list_empty(&pending))
1443 dapm_seq_run_coalesced(cur_dapm, &pending);
1445 if (cur_dapm && cur_dapm->seq_notifier) {
1446 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1447 if (sort[i] == cur_sort)
1448 cur_dapm->seq_notifier(cur_dapm,
1453 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1455 struct snd_soc_dapm_update *update = dapm->update;
1456 struct snd_soc_dapm_widget *w;
1465 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1466 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1468 dev_err(dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n",
1472 ret = soc_widget_update_bits_locked(w, update->reg, update->mask,
1475 dev_err(dapm->dev, "ASoC: %s DAPM update failed: %d\n",
1479 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1480 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1482 dev_err(dapm->dev, "ASoC: %s DAPM post-event failed: %d\n",
1487 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1488 * they're changing state.
1490 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1492 struct snd_soc_dapm_context *d = data;
1495 /* If we're off and we're not supposed to be go into STANDBY */
1496 if (d->bias_level == SND_SOC_BIAS_OFF &&
1497 d->target_bias_level != SND_SOC_BIAS_OFF) {
1499 pm_runtime_get_sync(d->dev);
1501 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1504 "ASoC: Failed to turn on bias: %d\n", ret);
1507 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1508 if (d->bias_level != d->target_bias_level) {
1509 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1512 "ASoC: Failed to prepare bias: %d\n", ret);
1516 /* Async callback run prior to DAPM sequences - brings to their final
1519 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1521 struct snd_soc_dapm_context *d = data;
1524 /* If we just powered the last thing off drop to standby bias */
1525 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1526 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1527 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1528 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1530 dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n",
1534 /* If we're in standby and can support bias off then do that */
1535 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1536 d->target_bias_level == SND_SOC_BIAS_OFF) {
1537 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1539 dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n",
1543 pm_runtime_put(d->dev);
1546 /* If we just powered up then move to active bias */
1547 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1548 d->target_bias_level == SND_SOC_BIAS_ON) {
1549 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1551 dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n",
1556 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
1557 bool power, bool connect)
1559 /* If a connection is being made or broken then that update
1560 * will have marked the peer dirty, otherwise the widgets are
1561 * not connected and this update has no impact. */
1565 /* If the peer is already in the state we're moving to then we
1566 * won't have an impact on it. */
1567 if (power != peer->power)
1568 dapm_mark_dirty(peer, "peer state change");
1571 static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1572 struct list_head *up_list,
1573 struct list_head *down_list)
1575 struct snd_soc_dapm_path *path;
1577 if (w->power == power)
1580 trace_snd_soc_dapm_widget_power(w, power);
1582 /* If we changed our power state perhaps our neigbours changed
1585 list_for_each_entry(path, &w->sources, list_sink) {
1587 dapm_widget_set_peer_power(path->source, power,
1592 case snd_soc_dapm_supply:
1593 case snd_soc_dapm_regulator_supply:
1594 case snd_soc_dapm_clock_supply:
1595 /* Supplies can't affect their outputs, only their inputs */
1598 list_for_each_entry(path, &w->sinks, list_source) {
1600 dapm_widget_set_peer_power(path->sink, power,
1608 dapm_seq_insert(w, up_list, true);
1610 dapm_seq_insert(w, down_list, false);
1615 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1616 struct list_head *up_list,
1617 struct list_head *down_list)
1622 case snd_soc_dapm_pre:
1623 dapm_seq_insert(w, down_list, false);
1625 case snd_soc_dapm_post:
1626 dapm_seq_insert(w, up_list, true);
1630 power = dapm_widget_power_check(w);
1632 dapm_widget_set_power(w, power, up_list, down_list);
1638 * Scan each dapm widget for complete audio path.
1639 * A complete path is a route that has valid endpoints i.e.:-
1641 * o DAC to output pin.
1642 * o Input Pin to ADC.
1643 * o Input pin to Output pin (bypass, sidetone)
1644 * o DAC to ADC (loopback).
1646 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1648 struct snd_soc_card *card = dapm->card;
1649 struct snd_soc_dapm_widget *w;
1650 struct snd_soc_dapm_context *d;
1652 LIST_HEAD(down_list);
1653 ASYNC_DOMAIN_EXCLUSIVE(async_domain);
1654 enum snd_soc_bias_level bias;
1656 trace_snd_soc_dapm_start(card);
1658 list_for_each_entry(d, &card->dapm_list, list) {
1659 if (d->idle_bias_off)
1660 d->target_bias_level = SND_SOC_BIAS_OFF;
1662 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1667 /* Check which widgets we need to power and store them in
1668 * lists indicating if they should be powered up or down. We
1669 * only check widgets that have been flagged as dirty but note
1670 * that new widgets may be added to the dirty list while we
1673 list_for_each_entry(w, &card->dapm_dirty, dirty) {
1674 dapm_power_one_widget(w, &up_list, &down_list);
1677 list_for_each_entry(w, &card->widgets, list) {
1679 case snd_soc_dapm_pre:
1680 case snd_soc_dapm_post:
1681 /* These widgets always need to be powered */
1684 list_del_init(&w->dirty);
1691 /* Supplies and micbiases only bring the
1692 * context up to STANDBY as unless something
1693 * else is active and passing audio they
1694 * generally don't require full power. Signal
1695 * generators are virtual pins and have no
1696 * power impact themselves.
1699 case snd_soc_dapm_siggen:
1701 case snd_soc_dapm_supply:
1702 case snd_soc_dapm_regulator_supply:
1703 case snd_soc_dapm_clock_supply:
1704 case snd_soc_dapm_micbias:
1705 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1706 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1709 d->target_bias_level = SND_SOC_BIAS_ON;
1716 /* Force all contexts in the card to the same bias state if
1717 * they're not ground referenced.
1719 bias = SND_SOC_BIAS_OFF;
1720 list_for_each_entry(d, &card->dapm_list, list)
1721 if (d->target_bias_level > bias)
1722 bias = d->target_bias_level;
1723 list_for_each_entry(d, &card->dapm_list, list)
1724 if (!d->idle_bias_off)
1725 d->target_bias_level = bias;
1727 trace_snd_soc_dapm_walk_done(card);
1729 /* Run all the bias changes in parallel */
1730 list_for_each_entry(d, &dapm->card->dapm_list, list)
1731 async_schedule_domain(dapm_pre_sequence_async, d,
1733 async_synchronize_full_domain(&async_domain);
1735 /* Power down widgets first; try to avoid amplifying pops. */
1736 dapm_seq_run(dapm, &down_list, event, false);
1738 dapm_widget_update(dapm);
1741 dapm_seq_run(dapm, &up_list, event, true);
1743 /* Run all the bias changes in parallel */
1744 list_for_each_entry(d, &dapm->card->dapm_list, list)
1745 async_schedule_domain(dapm_post_sequence_async, d,
1747 async_synchronize_full_domain(&async_domain);
1749 /* do we need to notify any clients that DAPM event is complete */
1750 list_for_each_entry(d, &card->dapm_list, list) {
1751 if (d->stream_event)
1752 d->stream_event(d, event);
1755 pop_dbg(dapm->dev, card->pop_time,
1756 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1757 pop_wait(card->pop_time);
1759 trace_snd_soc_dapm_done(card);
1764 #ifdef CONFIG_DEBUG_FS
1765 static ssize_t dapm_widget_power_read_file(struct file *file,
1766 char __user *user_buf,
1767 size_t count, loff_t *ppos)
1769 struct snd_soc_dapm_widget *w = file->private_data;
1773 struct snd_soc_dapm_path *p = NULL;
1775 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1779 in = is_connected_input_ep(w, NULL);
1780 dapm_clear_walk_input(w->dapm, &w->sources);
1781 out = is_connected_output_ep(w, NULL);
1782 dapm_clear_walk_output(w->dapm, &w->sinks);
1784 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
1785 w->name, w->power ? "On" : "Off",
1786 w->force ? " (forced)" : "", in, out);
1789 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1790 " - R%d(0x%x) bit %d",
1791 w->reg, w->reg, w->shift);
1793 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1796 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1798 w->active ? "active" : "inactive");
1800 list_for_each_entry(p, &w->sources, list_sink) {
1801 if (p->connected && !p->connected(w, p->sink))
1805 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1806 " in \"%s\" \"%s\"\n",
1807 p->name ? p->name : "static",
1810 list_for_each_entry(p, &w->sinks, list_source) {
1811 if (p->connected && !p->connected(w, p->sink))
1815 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1816 " out \"%s\" \"%s\"\n",
1817 p->name ? p->name : "static",
1821 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1827 static const struct file_operations dapm_widget_power_fops = {
1828 .open = simple_open,
1829 .read = dapm_widget_power_read_file,
1830 .llseek = default_llseek,
1833 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1834 size_t count, loff_t *ppos)
1836 struct snd_soc_dapm_context *dapm = file->private_data;
1839 switch (dapm->bias_level) {
1840 case SND_SOC_BIAS_ON:
1843 case SND_SOC_BIAS_PREPARE:
1844 level = "Prepare\n";
1846 case SND_SOC_BIAS_STANDBY:
1847 level = "Standby\n";
1849 case SND_SOC_BIAS_OFF:
1854 level = "Unknown\n";
1858 return simple_read_from_buffer(user_buf, count, ppos, level,
1862 static const struct file_operations dapm_bias_fops = {
1863 .open = simple_open,
1864 .read = dapm_bias_read_file,
1865 .llseek = default_llseek,
1868 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1869 struct dentry *parent)
1873 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1875 if (!dapm->debugfs_dapm) {
1877 "ASoC: Failed to create DAPM debugfs directory\n");
1881 d = debugfs_create_file("bias_level", 0444,
1882 dapm->debugfs_dapm, dapm,
1886 "ASoC: Failed to create bias level debugfs file\n");
1889 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1891 struct snd_soc_dapm_context *dapm = w->dapm;
1894 if (!dapm->debugfs_dapm || !w->name)
1897 d = debugfs_create_file(w->name, 0444,
1898 dapm->debugfs_dapm, w,
1899 &dapm_widget_power_fops);
1901 dev_warn(w->dapm->dev,
1902 "ASoC: Failed to create %s debugfs file\n",
1906 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1908 debugfs_remove_recursive(dapm->debugfs_dapm);
1912 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1913 struct dentry *parent)
1917 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1921 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1927 /* test and update the power status of a mux widget */
1928 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1929 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1931 struct snd_soc_dapm_path *path;
1934 if (widget->id != snd_soc_dapm_mux &&
1935 widget->id != snd_soc_dapm_virt_mux &&
1936 widget->id != snd_soc_dapm_value_mux)
1939 /* find dapm widget path assoc with kcontrol */
1940 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1941 if (path->kcontrol != kcontrol)
1944 if (!path->name || !e->texts[mux])
1948 /* we now need to match the string in the enum to the path */
1949 if (!(strcmp(path->name, e->texts[mux]))) {
1950 path->connect = 1; /* new connection */
1951 dapm_mark_dirty(path->source, "mux connection");
1954 dapm_mark_dirty(path->source,
1955 "mux disconnection");
1956 path->connect = 0; /* old connection must be powered down */
1961 dapm_mark_dirty(widget, "mux change");
1962 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1968 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1969 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1971 struct snd_soc_card *card = widget->dapm->card;
1974 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1975 ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
1976 mutex_unlock(&card->dapm_mutex);
1978 soc_dpcm_runtime_update(widget);
1981 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
1983 /* test and update the power status of a mixer or switch widget */
1984 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1985 struct snd_kcontrol *kcontrol, int connect)
1987 struct snd_soc_dapm_path *path;
1990 if (widget->id != snd_soc_dapm_mixer &&
1991 widget->id != snd_soc_dapm_mixer_named_ctl &&
1992 widget->id != snd_soc_dapm_switch)
1995 /* find dapm widget path assoc with kcontrol */
1996 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1997 if (path->kcontrol != kcontrol)
2000 /* found, now check type */
2002 path->connect = connect;
2003 dapm_mark_dirty(path->source, "mixer connection");
2007 dapm_mark_dirty(widget, "mixer update");
2008 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
2014 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
2015 struct snd_kcontrol *kcontrol, int connect)
2017 struct snd_soc_card *card = widget->dapm->card;
2020 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2021 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
2022 mutex_unlock(&card->dapm_mutex);
2024 soc_dpcm_runtime_update(widget);
2027 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
2029 /* show dapm widget status in sys fs */
2030 static ssize_t dapm_widget_show(struct device *dev,
2031 struct device_attribute *attr, char *buf)
2033 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
2034 struct snd_soc_codec *codec =rtd->codec;
2035 struct snd_soc_dapm_widget *w;
2037 char *state = "not set";
2039 list_for_each_entry(w, &codec->card->widgets, list) {
2040 if (w->dapm != &codec->dapm)
2043 /* only display widgets that burnm power */
2045 case snd_soc_dapm_hp:
2046 case snd_soc_dapm_mic:
2047 case snd_soc_dapm_spk:
2048 case snd_soc_dapm_line:
2049 case snd_soc_dapm_micbias:
2050 case snd_soc_dapm_dac:
2051 case snd_soc_dapm_adc:
2052 case snd_soc_dapm_pga:
2053 case snd_soc_dapm_out_drv:
2054 case snd_soc_dapm_mixer:
2055 case snd_soc_dapm_mixer_named_ctl:
2056 case snd_soc_dapm_supply:
2057 case snd_soc_dapm_regulator_supply:
2058 case snd_soc_dapm_clock_supply:
2060 count += sprintf(buf + count, "%s: %s\n",
2061 w->name, w->power ? "On":"Off");
2068 switch (codec->dapm.bias_level) {
2069 case SND_SOC_BIAS_ON:
2072 case SND_SOC_BIAS_PREPARE:
2075 case SND_SOC_BIAS_STANDBY:
2078 case SND_SOC_BIAS_OFF:
2082 count += sprintf(buf + count, "PM State: %s\n", state);
2087 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
2089 int snd_soc_dapm_sys_add(struct device *dev)
2091 return device_create_file(dev, &dev_attr_dapm_widget);
2094 static void snd_soc_dapm_sys_remove(struct device *dev)
2096 device_remove_file(dev, &dev_attr_dapm_widget);
2099 /* free all dapm widgets and resources */
2100 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
2102 struct snd_soc_dapm_widget *w, *next_w;
2103 struct snd_soc_dapm_path *p, *next_p;
2105 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
2106 if (w->dapm != dapm)
2110 * remove source and sink paths associated to this widget.
2111 * While removing the path, remove reference to it from both
2112 * source and sink widgets so that path is removed only once.
2114 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
2115 list_del(&p->list_sink);
2116 list_del(&p->list_source);
2118 kfree(p->long_name);
2121 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
2122 list_del(&p->list_sink);
2123 list_del(&p->list_source);
2125 kfree(p->long_name);
2128 kfree(w->kcontrols);
2134 static struct snd_soc_dapm_widget *dapm_find_widget(
2135 struct snd_soc_dapm_context *dapm, const char *pin,
2136 bool search_other_contexts)
2138 struct snd_soc_dapm_widget *w;
2139 struct snd_soc_dapm_widget *fallback = NULL;
2141 list_for_each_entry(w, &dapm->card->widgets, list) {
2142 if (!strcmp(w->name, pin)) {
2143 if (w->dapm == dapm)
2150 if (search_other_contexts)
2156 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2157 const char *pin, int status)
2159 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2162 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin);
2166 if (w->connected != status)
2167 dapm_mark_dirty(w, "pin configuration");
2169 w->connected = status;
2177 * snd_soc_dapm_sync - scan and power dapm paths
2178 * @dapm: DAPM context
2180 * Walks all dapm audio paths and powers widgets according to their
2181 * stream or path usage.
2183 * Returns 0 for success.
2185 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2190 * Suppress early reports (eg, jacks syncing their state) to avoid
2191 * silly DAPM runs during card startup.
2193 if (!dapm->card || !dapm->card->instantiated)
2196 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2197 ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2198 mutex_unlock(&dapm->card->dapm_mutex);
2201 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2203 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2204 const struct snd_soc_dapm_route *route)
2206 struct snd_soc_dapm_path *path;
2207 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
2208 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
2210 const char *control = route->control;
2212 char prefixed_sink[80];
2213 char prefixed_source[80];
2216 if (dapm->codec && dapm->codec->name_prefix) {
2217 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2218 dapm->codec->name_prefix, route->sink);
2219 sink = prefixed_sink;
2220 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2221 dapm->codec->name_prefix, route->source);
2222 source = prefixed_source;
2225 source = route->source;
2229 * find src and dest widgets over all widgets but favor a widget from
2230 * current DAPM context
2232 list_for_each_entry(w, &dapm->card->widgets, list) {
2233 if (!wsink && !(strcmp(w->name, sink))) {
2235 if (w->dapm == dapm)
2239 if (!wsource && !(strcmp(w->name, source))) {
2241 if (w->dapm == dapm)
2245 /* use widget from another DAPM context if not found from this */
2251 if (wsource == NULL) {
2252 dev_err(dapm->dev, "ASoC: no source widget found for %s\n",
2256 if (wsink == NULL) {
2257 dev_err(dapm->dev, "ASoC: no sink widget found for %s\n",
2262 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2266 path->source = wsource;
2268 path->connected = route->connected;
2269 INIT_LIST_HEAD(&path->list);
2270 INIT_LIST_HEAD(&path->list_source);
2271 INIT_LIST_HEAD(&path->list_sink);
2273 /* check for external widgets */
2274 if (wsink->id == snd_soc_dapm_input) {
2275 if (wsource->id == snd_soc_dapm_micbias ||
2276 wsource->id == snd_soc_dapm_mic ||
2277 wsource->id == snd_soc_dapm_line ||
2278 wsource->id == snd_soc_dapm_output)
2281 if (wsource->id == snd_soc_dapm_output) {
2282 if (wsink->id == snd_soc_dapm_spk ||
2283 wsink->id == snd_soc_dapm_hp ||
2284 wsink->id == snd_soc_dapm_line ||
2285 wsink->id == snd_soc_dapm_input)
2289 /* connect static paths */
2290 if (control == NULL) {
2291 list_add(&path->list, &dapm->card->paths);
2292 list_add(&path->list_sink, &wsink->sources);
2293 list_add(&path->list_source, &wsource->sinks);
2298 /* connect dynamic paths */
2299 switch (wsink->id) {
2300 case snd_soc_dapm_adc:
2301 case snd_soc_dapm_dac:
2302 case snd_soc_dapm_pga:
2303 case snd_soc_dapm_out_drv:
2304 case snd_soc_dapm_input:
2305 case snd_soc_dapm_output:
2306 case snd_soc_dapm_siggen:
2307 case snd_soc_dapm_micbias:
2308 case snd_soc_dapm_vmid:
2309 case snd_soc_dapm_pre:
2310 case snd_soc_dapm_post:
2311 case snd_soc_dapm_supply:
2312 case snd_soc_dapm_regulator_supply:
2313 case snd_soc_dapm_clock_supply:
2314 case snd_soc_dapm_aif_in:
2315 case snd_soc_dapm_aif_out:
2316 case snd_soc_dapm_dai_in:
2317 case snd_soc_dapm_dai_out:
2318 case snd_soc_dapm_dai_link:
2319 list_add(&path->list, &dapm->card->paths);
2320 list_add(&path->list_sink, &wsink->sources);
2321 list_add(&path->list_source, &wsource->sinks);
2324 case snd_soc_dapm_mux:
2325 case snd_soc_dapm_virt_mux:
2326 case snd_soc_dapm_value_mux:
2327 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2328 &wsink->kcontrol_news[0]);
2332 case snd_soc_dapm_switch:
2333 case snd_soc_dapm_mixer:
2334 case snd_soc_dapm_mixer_named_ctl:
2335 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2339 case snd_soc_dapm_hp:
2340 case snd_soc_dapm_mic:
2341 case snd_soc_dapm_line:
2342 case snd_soc_dapm_spk:
2343 list_add(&path->list, &dapm->card->paths);
2344 list_add(&path->list_sink, &wsink->sources);
2345 list_add(&path->list_source, &wsource->sinks);
2350 dapm_mark_dirty(wsource, "Route added");
2351 dapm_mark_dirty(wsink, "Route added");
2356 dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n",
2357 source, control, sink);
2362 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm,
2363 const struct snd_soc_dapm_route *route)
2365 struct snd_soc_dapm_path *path, *p;
2368 char prefixed_sink[80];
2369 char prefixed_source[80];
2371 if (route->control) {
2373 "ASoC: Removal of routes with controls not supported\n");
2377 if (dapm->codec && dapm->codec->name_prefix) {
2378 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2379 dapm->codec->name_prefix, route->sink);
2380 sink = prefixed_sink;
2381 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2382 dapm->codec->name_prefix, route->source);
2383 source = prefixed_source;
2386 source = route->source;
2390 list_for_each_entry(p, &dapm->card->paths, list) {
2391 if (strcmp(p->source->name, source) != 0)
2393 if (strcmp(p->sink->name, sink) != 0)
2400 dapm_mark_dirty(path->source, "Route removed");
2401 dapm_mark_dirty(path->sink, "Route removed");
2403 list_del(&path->list);
2404 list_del(&path->list_sink);
2405 list_del(&path->list_source);
2408 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n",
2416 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2417 * @dapm: DAPM context
2418 * @route: audio routes
2419 * @num: number of routes
2421 * Connects 2 dapm widgets together via a named audio path. The sink is
2422 * the widget receiving the audio signal, whilst the source is the sender
2423 * of the audio signal.
2425 * Returns 0 for success else error. On error all resources can be freed
2426 * with a call to snd_soc_card_free().
2428 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2429 const struct snd_soc_dapm_route *route, int num)
2433 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2434 for (i = 0; i < num; i++) {
2435 r = snd_soc_dapm_add_route(dapm, route);
2437 dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n",
2439 route->control ? route->control : "direct",
2445 mutex_unlock(&dapm->card->dapm_mutex);
2449 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2452 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2453 * @dapm: DAPM context
2454 * @route: audio routes
2455 * @num: number of routes
2457 * Removes routes from the DAPM context.
2459 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
2460 const struct snd_soc_dapm_route *route, int num)
2464 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2465 for (i = 0; i < num; i++) {
2466 snd_soc_dapm_del_route(dapm, route);
2469 mutex_unlock(&dapm->card->dapm_mutex);
2473 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes);
2475 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2476 const struct snd_soc_dapm_route *route)
2478 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2481 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2484 struct snd_soc_dapm_path *path;
2488 dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n",
2494 dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n",
2499 if (route->control || route->connected)
2500 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n",
2501 route->source, route->sink);
2503 list_for_each_entry(path, &source->sinks, list_source) {
2504 if (path->sink == sink) {
2511 dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n",
2512 route->source, route->sink);
2514 dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n",
2515 count, route->source, route->sink);
2521 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2522 * @dapm: DAPM context
2523 * @route: audio routes
2524 * @num: number of routes
2526 * Mark existing routes matching those specified in the passed array
2527 * as being weak, meaning that they are ignored for the purpose of
2528 * power decisions. The main intended use case is for sidetone paths
2529 * which couple audio between other independent paths if they are both
2530 * active in order to make the combination work better at the user
2531 * level but which aren't intended to be "used".
2533 * Note that CODEC drivers should not use this as sidetone type paths
2534 * can frequently also be used as bypass paths.
2536 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2537 const struct snd_soc_dapm_route *route, int num)
2542 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2543 for (i = 0; i < num; i++) {
2544 err = snd_soc_dapm_weak_route(dapm, route);
2549 mutex_unlock(&dapm->card->dapm_mutex);
2553 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2556 * snd_soc_dapm_new_widgets - add new dapm widgets
2557 * @dapm: DAPM context
2559 * Checks the codec for any new dapm widgets and creates them if found.
2561 * Returns 0 for success.
2563 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2565 struct snd_soc_dapm_widget *w;
2568 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2570 list_for_each_entry(w, &dapm->card->widgets, list)
2575 if (w->num_kcontrols) {
2576 w->kcontrols = kzalloc(w->num_kcontrols *
2577 sizeof(struct snd_kcontrol *),
2579 if (!w->kcontrols) {
2580 mutex_unlock(&dapm->card->dapm_mutex);
2586 case snd_soc_dapm_switch:
2587 case snd_soc_dapm_mixer:
2588 case snd_soc_dapm_mixer_named_ctl:
2591 case snd_soc_dapm_mux:
2592 case snd_soc_dapm_virt_mux:
2593 case snd_soc_dapm_value_mux:
2596 case snd_soc_dapm_pga:
2597 case snd_soc_dapm_out_drv:
2604 /* Read the initial power state from the device */
2606 val = soc_widget_read(w, w->reg);
2607 val &= 1 << w->shift;
2617 dapm_mark_dirty(w, "new widget");
2618 dapm_debugfs_add_widget(w);
2621 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2622 mutex_unlock(&dapm->card->dapm_mutex);
2625 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2628 * snd_soc_dapm_get_volsw - dapm mixer get callback
2629 * @kcontrol: mixer control
2630 * @ucontrol: control element information
2632 * Callback to get the value of a dapm mixer control.
2634 * Returns 0 for success.
2636 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2637 struct snd_ctl_elem_value *ucontrol)
2639 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2640 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2641 struct soc_mixer_control *mc =
2642 (struct soc_mixer_control *)kcontrol->private_value;
2643 unsigned int reg = mc->reg;
2644 unsigned int shift = mc->shift;
2646 unsigned int mask = (1 << fls(max)) - 1;
2647 unsigned int invert = mc->invert;
2649 if (snd_soc_volsw_is_stereo(mc))
2650 dev_warn(widget->dapm->dev,
2651 "ASoC: Control '%s' is stereo, which is not supported\n",
2654 ucontrol->value.integer.value[0] =
2655 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2657 ucontrol->value.integer.value[0] =
2658 max - ucontrol->value.integer.value[0];
2662 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2665 * snd_soc_dapm_put_volsw - dapm mixer set callback
2666 * @kcontrol: mixer control
2667 * @ucontrol: control element information
2669 * Callback to set the value of a dapm mixer control.
2671 * Returns 0 for success.
2673 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2674 struct snd_ctl_elem_value *ucontrol)
2676 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2677 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2678 struct snd_soc_codec *codec = widget->codec;
2679 struct snd_soc_card *card = codec->card;
2680 struct soc_mixer_control *mc =
2681 (struct soc_mixer_control *)kcontrol->private_value;
2682 unsigned int reg = mc->reg;
2683 unsigned int shift = mc->shift;
2685 unsigned int mask = (1 << fls(max)) - 1;
2686 unsigned int invert = mc->invert;
2688 int connect, change;
2689 struct snd_soc_dapm_update update;
2692 if (snd_soc_volsw_is_stereo(mc))
2693 dev_warn(widget->dapm->dev,
2694 "ASoC: Control '%s' is stereo, which is not supported\n",
2697 val = (ucontrol->value.integer.value[0] & mask);
2702 mask = mask << shift;
2705 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2707 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2709 for (wi = 0; wi < wlist->num_widgets; wi++) {
2710 widget = wlist->widgets[wi];
2712 widget->value = val;
2714 update.kcontrol = kcontrol;
2715 update.widget = widget;
2719 widget->dapm->update = &update;
2721 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2723 widget->dapm->update = NULL;
2727 mutex_unlock(&card->dapm_mutex);
2730 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2733 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2734 * @kcontrol: mixer control
2735 * @ucontrol: control element information
2737 * Callback to get the value of a dapm enumerated double mixer control.
2739 * Returns 0 for success.
2741 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2742 struct snd_ctl_elem_value *ucontrol)
2744 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2745 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2746 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2749 val = snd_soc_read(widget->codec, e->reg);
2750 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & e->mask;
2751 if (e->shift_l != e->shift_r)
2752 ucontrol->value.enumerated.item[1] =
2753 (val >> e->shift_r) & e->mask;
2757 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2760 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2761 * @kcontrol: mixer control
2762 * @ucontrol: control element information
2764 * Callback to set the value of a dapm enumerated double mixer control.
2766 * Returns 0 for success.
2768 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2769 struct snd_ctl_elem_value *ucontrol)
2771 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2772 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2773 struct snd_soc_codec *codec = widget->codec;
2774 struct snd_soc_card *card = codec->card;
2775 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2776 unsigned int val, mux, change;
2778 struct snd_soc_dapm_update update;
2781 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2783 mux = ucontrol->value.enumerated.item[0];
2784 val = mux << e->shift_l;
2785 mask = e->mask << e->shift_l;
2786 if (e->shift_l != e->shift_r) {
2787 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2789 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2790 mask |= e->mask << e->shift_r;
2793 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2795 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2797 for (wi = 0; wi < wlist->num_widgets; wi++) {
2798 widget = wlist->widgets[wi];
2800 widget->value = val;
2802 update.kcontrol = kcontrol;
2803 update.widget = widget;
2804 update.reg = e->reg;
2807 widget->dapm->update = &update;
2809 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2811 widget->dapm->update = NULL;
2815 mutex_unlock(&card->dapm_mutex);
2818 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2821 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2822 * @kcontrol: mixer control
2823 * @ucontrol: control element information
2825 * Returns 0 for success.
2827 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2828 struct snd_ctl_elem_value *ucontrol)
2830 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2831 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2833 ucontrol->value.enumerated.item[0] = widget->value;
2837 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2840 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2841 * @kcontrol: mixer control
2842 * @ucontrol: control element information
2844 * Returns 0 for success.
2846 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
2847 struct snd_ctl_elem_value *ucontrol)
2849 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2850 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2851 struct snd_soc_codec *codec = widget->codec;
2852 struct snd_soc_card *card = codec->card;
2853 struct soc_enum *e =
2854 (struct soc_enum *)kcontrol->private_value;
2859 if (ucontrol->value.enumerated.item[0] >= e->max)
2862 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2864 change = widget->value != ucontrol->value.enumerated.item[0];
2866 for (wi = 0; wi < wlist->num_widgets; wi++) {
2867 widget = wlist->widgets[wi];
2869 widget->value = ucontrol->value.enumerated.item[0];
2871 soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
2875 mutex_unlock(&card->dapm_mutex);
2878 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2881 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2883 * @kcontrol: mixer control
2884 * @ucontrol: control element information
2886 * Callback to get the value of a dapm semi enumerated double mixer control.
2888 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2889 * used for handling bitfield coded enumeration for example.
2891 * Returns 0 for success.
2893 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2894 struct snd_ctl_elem_value *ucontrol)
2896 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2897 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2898 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2899 unsigned int reg_val, val, mux;
2901 reg_val = snd_soc_read(widget->codec, e->reg);
2902 val = (reg_val >> e->shift_l) & e->mask;
2903 for (mux = 0; mux < e->max; mux++) {
2904 if (val == e->values[mux])
2907 ucontrol->value.enumerated.item[0] = mux;
2908 if (e->shift_l != e->shift_r) {
2909 val = (reg_val >> e->shift_r) & e->mask;
2910 for (mux = 0; mux < e->max; mux++) {
2911 if (val == e->values[mux])
2914 ucontrol->value.enumerated.item[1] = mux;
2919 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2922 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2924 * @kcontrol: mixer control
2925 * @ucontrol: control element information
2927 * Callback to set the value of a dapm semi enumerated double mixer control.
2929 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2930 * used for handling bitfield coded enumeration for example.
2932 * Returns 0 for success.
2934 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2935 struct snd_ctl_elem_value *ucontrol)
2937 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2938 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2939 struct snd_soc_codec *codec = widget->codec;
2940 struct snd_soc_card *card = codec->card;
2941 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2942 unsigned int val, mux, change;
2944 struct snd_soc_dapm_update update;
2947 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2949 mux = ucontrol->value.enumerated.item[0];
2950 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2951 mask = e->mask << e->shift_l;
2952 if (e->shift_l != e->shift_r) {
2953 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2955 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2956 mask |= e->mask << e->shift_r;
2959 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2961 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2963 for (wi = 0; wi < wlist->num_widgets; wi++) {
2964 widget = wlist->widgets[wi];
2966 widget->value = val;
2968 update.kcontrol = kcontrol;
2969 update.widget = widget;
2970 update.reg = e->reg;
2973 widget->dapm->update = &update;
2975 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2977 widget->dapm->update = NULL;
2981 mutex_unlock(&card->dapm_mutex);
2984 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2987 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2989 * @kcontrol: mixer control
2990 * @uinfo: control element information
2992 * Callback to provide information about a pin switch control.
2994 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2995 struct snd_ctl_elem_info *uinfo)
2997 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2999 uinfo->value.integer.min = 0;
3000 uinfo->value.integer.max = 1;
3004 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
3007 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3009 * @kcontrol: mixer control
3012 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
3013 struct snd_ctl_elem_value *ucontrol)
3015 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
3016 const char *pin = (const char *)kcontrol->private_value;
3018 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3020 ucontrol->value.integer.value[0] =
3021 snd_soc_dapm_get_pin_status(&card->dapm, pin);
3023 mutex_unlock(&card->dapm_mutex);
3027 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
3030 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3032 * @kcontrol: mixer control
3035 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
3036 struct snd_ctl_elem_value *ucontrol)
3038 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
3039 const char *pin = (const char *)kcontrol->private_value;
3041 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3043 if (ucontrol->value.integer.value[0])
3044 snd_soc_dapm_enable_pin(&card->dapm, pin);
3046 snd_soc_dapm_disable_pin(&card->dapm, pin);
3048 mutex_unlock(&card->dapm_mutex);
3050 snd_soc_dapm_sync(&card->dapm);
3053 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
3055 static struct snd_soc_dapm_widget *
3056 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3057 const struct snd_soc_dapm_widget *widget)
3059 struct snd_soc_dapm_widget *w;
3063 if ((w = dapm_cnew_widget(widget)) == NULL)
3067 case snd_soc_dapm_regulator_supply:
3068 w->regulator = devm_regulator_get(dapm->dev, w->name);
3069 if (IS_ERR(w->regulator)) {
3070 ret = PTR_ERR(w->regulator);
3071 dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
3076 if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) {
3077 ret = regulator_allow_bypass(w->regulator, true);
3079 dev_warn(w->dapm->dev,
3080 "ASoC: Failed to unbypass %s: %d\n",
3084 case snd_soc_dapm_clock_supply:
3085 #ifdef CONFIG_CLKDEV_LOOKUP
3086 w->clk = devm_clk_get(dapm->dev, w->name);
3087 if (IS_ERR(w->clk)) {
3088 ret = PTR_ERR(w->clk);
3089 dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
3101 name_len = strlen(widget->name) + 1;
3102 if (dapm->codec && dapm->codec->name_prefix)
3103 name_len += 1 + strlen(dapm->codec->name_prefix);
3104 w->name = kmalloc(name_len, GFP_KERNEL);
3105 if (w->name == NULL) {
3109 if (dapm->codec && dapm->codec->name_prefix)
3110 snprintf((char *)w->name, name_len, "%s %s",
3111 dapm->codec->name_prefix, widget->name);
3113 snprintf((char *)w->name, name_len, "%s", widget->name);
3116 case snd_soc_dapm_switch:
3117 case snd_soc_dapm_mixer:
3118 case snd_soc_dapm_mixer_named_ctl:
3119 w->power_check = dapm_generic_check_power;
3121 case snd_soc_dapm_mux:
3122 case snd_soc_dapm_virt_mux:
3123 case snd_soc_dapm_value_mux:
3124 w->power_check = dapm_generic_check_power;
3126 case snd_soc_dapm_adc:
3127 case snd_soc_dapm_aif_out:
3128 case snd_soc_dapm_dai_out:
3129 w->power_check = dapm_adc_check_power;
3131 case snd_soc_dapm_dac:
3132 case snd_soc_dapm_aif_in:
3133 case snd_soc_dapm_dai_in:
3134 w->power_check = dapm_dac_check_power;
3136 case snd_soc_dapm_pga:
3137 case snd_soc_dapm_out_drv:
3138 case snd_soc_dapm_input:
3139 case snd_soc_dapm_output:
3140 case snd_soc_dapm_micbias:
3141 case snd_soc_dapm_spk:
3142 case snd_soc_dapm_hp:
3143 case snd_soc_dapm_mic:
3144 case snd_soc_dapm_line:
3145 case snd_soc_dapm_dai_link:
3146 w->power_check = dapm_generic_check_power;
3148 case snd_soc_dapm_supply:
3149 case snd_soc_dapm_regulator_supply:
3150 case snd_soc_dapm_clock_supply:
3151 w->power_check = dapm_supply_check_power;
3154 w->power_check = dapm_always_on_check_power;
3159 w->codec = dapm->codec;
3160 w->platform = dapm->platform;
3161 INIT_LIST_HEAD(&w->sources);
3162 INIT_LIST_HEAD(&w->sinks);
3163 INIT_LIST_HEAD(&w->list);
3164 INIT_LIST_HEAD(&w->dirty);
3165 list_add(&w->list, &dapm->card->widgets);
3167 /* machine layer set ups unconnected pins and insertions */
3173 * snd_soc_dapm_new_controls - create new dapm controls
3174 * @dapm: DAPM context
3175 * @widget: widget array
3176 * @num: number of widgets
3178 * Creates new DAPM controls based upon the templates.
3180 * Returns 0 for success else error.
3182 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
3183 const struct snd_soc_dapm_widget *widget,
3186 struct snd_soc_dapm_widget *w;
3190 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
3191 for (i = 0; i < num; i++) {
3192 w = snd_soc_dapm_new_control(dapm, widget);
3195 "ASoC: Failed to create DAPM control %s\n",
3202 mutex_unlock(&dapm->card->dapm_mutex);
3205 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
3207 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3208 struct snd_kcontrol *kcontrol, int event)
3210 struct snd_soc_dapm_path *source_p, *sink_p;
3211 struct snd_soc_dai *source, *sink;
3212 const struct snd_soc_pcm_stream *config = w->params;
3213 struct snd_pcm_substream substream;
3214 struct snd_pcm_hw_params *params = NULL;
3219 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks));
3221 /* We only support a single source and sink, pick the first */
3222 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
3224 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
3227 BUG_ON(!source_p || !sink_p);
3228 BUG_ON(!sink_p->source || !source_p->sink);
3229 BUG_ON(!source_p->source || !sink_p->sink);
3231 source = source_p->source->priv;
3232 sink = sink_p->sink->priv;
3234 /* Be a little careful as we don't want to overflow the mask array */
3235 if (config->formats) {
3236 fmt = ffs(config->formats) - 1;
3238 dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n",
3243 /* Currently very limited parameter selection */
3244 params = kzalloc(sizeof(*params), GFP_KERNEL);
3249 snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
3251 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min =
3253 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max =
3256 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min
3257 = config->channels_min;
3258 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max
3259 = config->channels_max;
3261 memset(&substream, 0, sizeof(substream));
3264 case SND_SOC_DAPM_PRE_PMU:
3265 if (source->driver->ops && source->driver->ops->hw_params) {
3266 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3267 ret = source->driver->ops->hw_params(&substream,
3270 dev_err(source->dev,
3271 "ASoC: hw_params() failed: %d\n", ret);
3276 if (sink->driver->ops && sink->driver->ops->hw_params) {
3277 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3278 ret = sink->driver->ops->hw_params(&substream, params,
3282 "ASoC: hw_params() failed: %d\n", ret);
3288 case SND_SOC_DAPM_POST_PMU:
3289 ret = snd_soc_dai_digital_mute(sink, 0,
3290 SNDRV_PCM_STREAM_PLAYBACK);
3291 if (ret != 0 && ret != -ENOTSUPP)
3292 dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret);
3296 case SND_SOC_DAPM_PRE_PMD:
3297 ret = snd_soc_dai_digital_mute(sink, 1,
3298 SNDRV_PCM_STREAM_PLAYBACK);
3299 if (ret != 0 && ret != -ENOTSUPP)
3300 dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret);
3314 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3315 const struct snd_soc_pcm_stream *params,
3316 struct snd_soc_dapm_widget *source,
3317 struct snd_soc_dapm_widget *sink)
3319 struct snd_soc_dapm_route routes[2];
3320 struct snd_soc_dapm_widget template;
3321 struct snd_soc_dapm_widget *w;
3325 len = strlen(source->name) + strlen(sink->name) + 2;
3326 link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
3329 snprintf(link_name, len, "%s-%s", source->name, sink->name);
3331 memset(&template, 0, sizeof(template));
3332 template.reg = SND_SOC_NOPM;
3333 template.id = snd_soc_dapm_dai_link;
3334 template.name = link_name;
3335 template.event = snd_soc_dai_link_event;
3336 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3337 SND_SOC_DAPM_PRE_PMD;
3339 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
3341 w = snd_soc_dapm_new_control(&card->dapm, &template);
3343 dev_err(card->dev, "ASoC: Failed to create %s widget\n",
3350 memset(&routes, 0, sizeof(routes));
3352 routes[0].source = source->name;
3353 routes[0].sink = link_name;
3354 routes[1].source = link_name;
3355 routes[1].sink = sink->name;
3357 return snd_soc_dapm_add_routes(&card->dapm, routes,
3358 ARRAY_SIZE(routes));
3361 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3362 struct snd_soc_dai *dai)
3364 struct snd_soc_dapm_widget template;
3365 struct snd_soc_dapm_widget *w;
3367 WARN_ON(dapm->dev != dai->dev);
3369 memset(&template, 0, sizeof(template));
3370 template.reg = SND_SOC_NOPM;
3372 if (dai->driver->playback.stream_name) {
3373 template.id = snd_soc_dapm_dai_in;
3374 template.name = dai->driver->playback.stream_name;
3375 template.sname = dai->driver->playback.stream_name;
3377 dev_dbg(dai->dev, "ASoC: adding %s widget\n",
3380 w = snd_soc_dapm_new_control(dapm, &template);
3382 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3383 dai->driver->playback.stream_name);
3387 dai->playback_widget = w;
3390 if (dai->driver->capture.stream_name) {
3391 template.id = snd_soc_dapm_dai_out;
3392 template.name = dai->driver->capture.stream_name;
3393 template.sname = dai->driver->capture.stream_name;
3395 dev_dbg(dai->dev, "ASoC: adding %s widget\n",
3398 w = snd_soc_dapm_new_control(dapm, &template);
3400 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3401 dai->driver->capture.stream_name);
3405 dai->capture_widget = w;
3411 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3413 struct snd_soc_dapm_widget *dai_w, *w;
3414 struct snd_soc_dai *dai;
3415 struct snd_soc_dapm_route r;
3417 memset(&r, 0, sizeof(r));
3419 /* For each DAI widget... */
3420 list_for_each_entry(dai_w, &card->widgets, list) {
3421 switch (dai_w->id) {
3422 case snd_soc_dapm_dai_in:
3423 case snd_soc_dapm_dai_out:
3431 /* ...find all widgets with the same stream and link them */
3432 list_for_each_entry(w, &card->widgets, list) {
3433 if (w->dapm != dai_w->dapm)
3437 case snd_soc_dapm_dai_in:
3438 case snd_soc_dapm_dai_out:
3447 if (dai->driver->playback.stream_name &&
3449 dai->driver->playback.stream_name)) {
3450 r.source = dai->playback_widget->name;
3452 dev_dbg(dai->dev, "%s -> %s\n",
3455 snd_soc_dapm_add_route(w->dapm, &r);
3458 if (dai->driver->capture.stream_name &&
3460 dai->driver->capture.stream_name)) {
3462 r.sink = dai->capture_widget->name;
3463 dev_dbg(dai->dev, "%s -> %s\n",
3466 snd_soc_dapm_add_route(w->dapm, &r);
3474 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3478 struct snd_soc_dapm_widget *w_cpu, *w_codec;
3479 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3480 struct snd_soc_dai *codec_dai = rtd->codec_dai;
3482 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
3483 w_cpu = cpu_dai->playback_widget;
3484 w_codec = codec_dai->playback_widget;
3486 w_cpu = cpu_dai->capture_widget;
3487 w_codec = codec_dai->capture_widget;
3492 dapm_mark_dirty(w_cpu, "stream event");
3495 case SND_SOC_DAPM_STREAM_START:
3498 case SND_SOC_DAPM_STREAM_STOP:
3501 case SND_SOC_DAPM_STREAM_SUSPEND:
3502 case SND_SOC_DAPM_STREAM_RESUME:
3503 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3504 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3511 dapm_mark_dirty(w_codec, "stream event");
3514 case SND_SOC_DAPM_STREAM_START:
3515 w_codec->active = 1;
3517 case SND_SOC_DAPM_STREAM_STOP:
3518 w_codec->active = 0;
3520 case SND_SOC_DAPM_STREAM_SUSPEND:
3521 case SND_SOC_DAPM_STREAM_RESUME:
3522 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3523 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3528 dapm_power_widgets(&rtd->card->dapm, event);
3532 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3533 * @rtd: PCM runtime data
3534 * @stream: stream name
3535 * @event: stream event
3537 * Sends a stream event to the dapm core. The core then makes any
3538 * necessary widget power changes.
3540 * Returns 0 for success else error.
3542 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3545 struct snd_soc_card *card = rtd->card;
3547 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3548 soc_dapm_stream_event(rtd, stream, event);
3549 mutex_unlock(&card->dapm_mutex);
3553 * snd_soc_dapm_enable_pin - enable pin.
3554 * @dapm: DAPM context
3557 * Enables input/output pin and its parents or children widgets iff there is
3558 * a valid audio route and active audio stream.
3559 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3560 * do any widget power switching.
3562 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3564 return snd_soc_dapm_set_pin(dapm, pin, 1);
3566 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3569 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3570 * @dapm: DAPM context
3573 * Enables input/output pin regardless of any other state. This is
3574 * intended for use with microphone bias supplies used in microphone
3577 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3578 * do any widget power switching.
3580 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3583 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3586 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin);
3590 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin);
3593 dapm_mark_dirty(w, "force enable");
3597 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
3600 * snd_soc_dapm_disable_pin - disable pin.
3601 * @dapm: DAPM context
3604 * Disables input/output pin and its parents or children widgets.
3605 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3606 * do any widget power switching.
3608 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
3611 return snd_soc_dapm_set_pin(dapm, pin, 0);
3613 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3616 * snd_soc_dapm_nc_pin - permanently disable pin.
3617 * @dapm: DAPM context
3620 * Marks the specified pin as being not connected, disabling it along
3621 * any parent or child widgets. At present this is identical to
3622 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3623 * additional things such as disabling controls which only affect
3624 * paths through the pin.
3626 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3627 * do any widget power switching.
3629 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3631 return snd_soc_dapm_set_pin(dapm, pin, 0);
3633 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
3636 * snd_soc_dapm_get_pin_status - get audio pin status
3637 * @dapm: DAPM context
3638 * @pin: audio signal pin endpoint (or start point)
3640 * Get audio pin status - connected or disconnected.
3642 * Returns 1 for connected otherwise 0.
3644 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
3647 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3650 return w->connected;
3654 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
3657 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3658 * @dapm: DAPM context
3659 * @pin: audio signal pin endpoint (or start point)
3661 * Mark the given endpoint or pin as ignoring suspend. When the
3662 * system is disabled a path between two endpoints flagged as ignoring
3663 * suspend will not be disabled. The path must already be enabled via
3664 * normal means at suspend time, it will not be turned on if it was not
3667 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
3670 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
3673 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin);
3677 w->ignore_suspend = 1;
3681 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3683 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
3684 struct snd_soc_dapm_widget *w)
3686 struct snd_soc_dapm_path *p;
3688 list_for_each_entry(p, &card->paths, list) {
3689 if ((p->source == w) || (p->sink == w)) {
3691 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3692 p->source->name, p->source->id, p->source->dapm,
3693 p->sink->name, p->sink->id, p->sink->dapm);
3695 /* Connected to something other than the codec */
3696 if (p->source->dapm != p->sink->dapm)
3699 * Loopback connection from codec external pin to
3700 * codec external pin
3702 if (p->sink->id == snd_soc_dapm_input) {
3703 switch (p->source->id) {
3704 case snd_soc_dapm_output:
3705 case snd_soc_dapm_micbias:
3718 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3719 * @codec: The codec whose pins should be processed
3721 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3722 * which are unused. Pins are used if they are connected externally to the
3723 * codec, whether that be to some other device, or a loop-back connection to
3726 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
3728 struct snd_soc_card *card = codec->card;
3729 struct snd_soc_dapm_context *dapm = &codec->dapm;
3730 struct snd_soc_dapm_widget *w;
3732 dev_dbg(codec->dev, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n",
3733 &card->dapm, &codec->dapm);
3735 list_for_each_entry(w, &card->widgets, list) {
3736 if (w->dapm != dapm)
3739 case snd_soc_dapm_input:
3740 case snd_soc_dapm_output:
3741 case snd_soc_dapm_micbias:
3742 dev_dbg(codec->dev, "ASoC: Auto NC: Checking widget %s\n",
3744 if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
3746 "... Not in map; disabling\n");
3747 snd_soc_dapm_nc_pin(dapm, w->name);
3757 * snd_soc_dapm_free - free dapm resources
3758 * @dapm: DAPM context
3760 * Free all dapm widgets and resources.
3762 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
3764 snd_soc_dapm_sys_remove(dapm->dev);
3765 dapm_debugfs_cleanup(dapm);
3766 dapm_free_widgets(dapm);
3767 list_del(&dapm->list);
3769 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
3771 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
3773 struct snd_soc_card *card = dapm->card;
3774 struct snd_soc_dapm_widget *w;
3775 LIST_HEAD(down_list);
3778 mutex_lock(&card->dapm_mutex);
3780 list_for_each_entry(w, &dapm->card->widgets, list) {
3781 if (w->dapm != dapm)
3784 dapm_seq_insert(w, &down_list, false);
3790 /* If there were no widgets to power down we're already in
3794 if (dapm->bias_level == SND_SOC_BIAS_ON)
3795 snd_soc_dapm_set_bias_level(dapm,
3796 SND_SOC_BIAS_PREPARE);
3797 dapm_seq_run(dapm, &down_list, 0, false);
3798 if (dapm->bias_level == SND_SOC_BIAS_PREPARE)
3799 snd_soc_dapm_set_bias_level(dapm,
3800 SND_SOC_BIAS_STANDBY);
3803 mutex_unlock(&card->dapm_mutex);
3807 * snd_soc_dapm_shutdown - callback for system shutdown
3809 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
3811 struct snd_soc_codec *codec;
3813 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
3814 soc_dapm_shutdown_codec(&codec->dapm);
3815 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
3816 snd_soc_dapm_set_bias_level(&codec->dapm,
3821 /* Module information */
3822 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3823 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3824 MODULE_LICENSE("GPL");