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] = 3,
59 [snd_soc_dapm_aif_in] = 3,
60 [snd_soc_dapm_aif_out] = 3,
61 [snd_soc_dapm_mic] = 4,
62 [snd_soc_dapm_mux] = 5,
63 [snd_soc_dapm_virt_mux] = 5,
64 [snd_soc_dapm_value_mux] = 5,
65 [snd_soc_dapm_dac] = 6,
66 [snd_soc_dapm_mixer] = 7,
67 [snd_soc_dapm_mixer_named_ctl] = 7,
68 [snd_soc_dapm_pga] = 8,
69 [snd_soc_dapm_adc] = 9,
70 [snd_soc_dapm_out_drv] = 10,
71 [snd_soc_dapm_hp] = 10,
72 [snd_soc_dapm_spk] = 10,
73 [snd_soc_dapm_line] = 10,
74 [snd_soc_dapm_post] = 11,
77 static int dapm_down_seq[] = {
78 [snd_soc_dapm_pre] = 0,
79 [snd_soc_dapm_adc] = 1,
80 [snd_soc_dapm_hp] = 2,
81 [snd_soc_dapm_spk] = 2,
82 [snd_soc_dapm_line] = 2,
83 [snd_soc_dapm_out_drv] = 2,
84 [snd_soc_dapm_pga] = 4,
85 [snd_soc_dapm_mixer_named_ctl] = 5,
86 [snd_soc_dapm_mixer] = 5,
87 [snd_soc_dapm_dac] = 6,
88 [snd_soc_dapm_mic] = 7,
89 [snd_soc_dapm_micbias] = 8,
90 [snd_soc_dapm_mux] = 9,
91 [snd_soc_dapm_virt_mux] = 9,
92 [snd_soc_dapm_value_mux] = 9,
93 [snd_soc_dapm_aif_in] = 10,
94 [snd_soc_dapm_aif_out] = 10,
95 [snd_soc_dapm_dai] = 10,
96 [snd_soc_dapm_dai_link] = 11,
97 [snd_soc_dapm_clock_supply] = 12,
98 [snd_soc_dapm_regulator_supply] = 12,
99 [snd_soc_dapm_supply] = 12,
100 [snd_soc_dapm_post] = 13,
103 static void pop_wait(u32 pop_time)
106 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
109 static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
117 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
122 vsnprintf(buf, PAGE_SIZE, fmt, args);
123 dev_info(dev, "%s", buf);
129 static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
131 return !list_empty(&w->dirty);
134 void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
136 if (!dapm_dirty_widget(w)) {
137 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
139 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
142 EXPORT_SYMBOL_GPL(dapm_mark_dirty);
144 void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm)
146 struct snd_soc_card *card = dapm->card;
147 struct snd_soc_dapm_widget *w;
149 mutex_lock(&card->dapm_mutex);
151 list_for_each_entry(w, &card->widgets, list) {
153 case snd_soc_dapm_input:
154 case snd_soc_dapm_output:
155 dapm_mark_dirty(w, "Rechecking inputs and outputs");
162 mutex_unlock(&card->dapm_mutex);
164 EXPORT_SYMBOL_GPL(dapm_mark_io_dirty);
166 /* create a new dapm widget */
167 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
168 const struct snd_soc_dapm_widget *_widget)
170 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
173 /* get snd_card from DAPM context */
174 static inline struct snd_card *dapm_get_snd_card(
175 struct snd_soc_dapm_context *dapm)
178 return dapm->codec->card->snd_card;
179 else if (dapm->platform)
180 return dapm->platform->card->snd_card;
188 /* get soc_card from DAPM context */
189 static inline struct snd_soc_card *dapm_get_soc_card(
190 struct snd_soc_dapm_context *dapm)
193 return dapm->codec->card;
194 else if (dapm->platform)
195 return dapm->platform->card;
203 static void dapm_reset(struct snd_soc_card *card)
205 struct snd_soc_dapm_widget *w;
207 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
209 list_for_each_entry(w, &card->widgets, list) {
210 w->power_checked = false;
216 static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
219 return snd_soc_read(w->codec, reg);
220 else if (w->platform)
221 return snd_soc_platform_read(w->platform, reg);
223 dev_err(w->dapm->dev, "ASoC: no valid widget read method\n");
227 static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
230 return snd_soc_write(w->codec, reg, val);
231 else if (w->platform)
232 return snd_soc_platform_write(w->platform, reg, val);
234 dev_err(w->dapm->dev, "ASoC: no valid widget write method\n");
238 static inline void soc_widget_lock(struct snd_soc_dapm_widget *w)
240 if (w->codec && !w->codec->using_regmap)
241 mutex_lock(&w->codec->mutex);
242 else if (w->platform)
243 mutex_lock(&w->platform->mutex);
246 static inline void soc_widget_unlock(struct snd_soc_dapm_widget *w)
248 if (w->codec && !w->codec->using_regmap)
249 mutex_unlock(&w->codec->mutex);
250 else if (w->platform)
251 mutex_unlock(&w->platform->mutex);
254 static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
255 unsigned short reg, unsigned int mask, unsigned int value)
258 unsigned int old, new;
261 if (w->codec && w->codec->using_regmap) {
262 ret = regmap_update_bits_check(w->codec->control_data,
263 reg, mask, value, &change);
268 ret = soc_widget_read(w, reg);
270 soc_widget_unlock(w);
275 new = (old & ~mask) | (value & mask);
278 ret = soc_widget_write(w, reg, new);
280 soc_widget_unlock(w);
284 soc_widget_unlock(w);
291 * snd_soc_dapm_set_bias_level - set the bias level for the system
292 * @dapm: DAPM context
293 * @level: level to configure
295 * Configure the bias (power) levels for the SoC audio device.
297 * Returns 0 for success else error.
299 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
300 enum snd_soc_bias_level level)
302 struct snd_soc_card *card = dapm->card;
305 trace_snd_soc_bias_level_start(card, level);
307 if (card && card->set_bias_level)
308 ret = card->set_bias_level(card, dapm, level);
313 if (dapm->codec->driver->set_bias_level)
314 ret = dapm->codec->driver->set_bias_level(dapm->codec,
317 dapm->bias_level = level;
318 } else if (!card || dapm != &card->dapm) {
319 dapm->bias_level = level;
325 if (card && card->set_bias_level_post)
326 ret = card->set_bias_level_post(card, dapm, level);
328 trace_snd_soc_bias_level_done(card, level);
333 /* set up initial codec paths */
334 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
335 struct snd_soc_dapm_path *p, int i)
338 case snd_soc_dapm_switch:
339 case snd_soc_dapm_mixer:
340 case snd_soc_dapm_mixer_named_ctl: {
342 struct soc_mixer_control *mc = (struct soc_mixer_control *)
343 w->kcontrol_news[i].private_value;
344 unsigned int reg = mc->reg;
345 unsigned int shift = mc->shift;
347 unsigned int mask = (1 << fls(max)) - 1;
348 unsigned int invert = mc->invert;
350 val = soc_widget_read(w, reg);
351 val = (val >> shift) & mask;
358 case snd_soc_dapm_mux: {
359 struct soc_enum *e = (struct soc_enum *)
360 w->kcontrol_news[i].private_value;
363 val = soc_widget_read(w, e->reg);
364 item = (val >> e->shift_l) & e->mask;
367 for (i = 0; i < e->max; i++) {
368 if (!(strcmp(p->name, e->texts[i])) && item == i)
373 case snd_soc_dapm_virt_mux: {
374 struct soc_enum *e = (struct soc_enum *)
375 w->kcontrol_news[i].private_value;
378 /* since a virtual mux has no backing registers to
379 * decide which path to connect, it will try to match
380 * with the first enumeration. This is to ensure
381 * that the default mux choice (the first) will be
382 * correctly powered up during initialization.
384 if (!strcmp(p->name, e->texts[0]))
388 case snd_soc_dapm_value_mux: {
389 struct soc_enum *e = (struct soc_enum *)
390 w->kcontrol_news[i].private_value;
393 val = soc_widget_read(w, e->reg);
394 val = (val >> e->shift_l) & e->mask;
395 for (item = 0; item < e->max; item++) {
396 if (val == e->values[item])
401 for (i = 0; i < e->max; i++) {
402 if (!(strcmp(p->name, e->texts[i])) && item == i)
407 /* does not affect routing - always connected */
408 case snd_soc_dapm_pga:
409 case snd_soc_dapm_out_drv:
410 case snd_soc_dapm_output:
411 case snd_soc_dapm_adc:
412 case snd_soc_dapm_input:
413 case snd_soc_dapm_siggen:
414 case snd_soc_dapm_dac:
415 case snd_soc_dapm_micbias:
416 case snd_soc_dapm_vmid:
417 case snd_soc_dapm_supply:
418 case snd_soc_dapm_regulator_supply:
419 case snd_soc_dapm_clock_supply:
420 case snd_soc_dapm_aif_in:
421 case snd_soc_dapm_aif_out:
422 case snd_soc_dapm_dai:
423 case snd_soc_dapm_hp:
424 case snd_soc_dapm_mic:
425 case snd_soc_dapm_spk:
426 case snd_soc_dapm_line:
427 case snd_soc_dapm_dai_link:
430 /* does affect routing - dynamically connected */
431 case snd_soc_dapm_pre:
432 case snd_soc_dapm_post:
438 /* connect mux widget to its interconnecting audio paths */
439 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
440 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
441 struct snd_soc_dapm_path *path, const char *control_name,
442 const struct snd_kcontrol_new *kcontrol)
444 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
447 for (i = 0; i < e->max; i++) {
448 if (!(strcmp(control_name, e->texts[i]))) {
449 list_add(&path->list, &dapm->card->paths);
450 list_add(&path->list_sink, &dest->sources);
451 list_add(&path->list_source, &src->sinks);
452 path->name = (char*)e->texts[i];
453 dapm_set_path_status(dest, path, 0);
461 /* connect mixer widget to its interconnecting audio paths */
462 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
463 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
464 struct snd_soc_dapm_path *path, const char *control_name)
468 /* search for mixer kcontrol */
469 for (i = 0; i < dest->num_kcontrols; i++) {
470 if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
471 list_add(&path->list, &dapm->card->paths);
472 list_add(&path->list_sink, &dest->sources);
473 list_add(&path->list_source, &src->sinks);
474 path->name = dest->kcontrol_news[i].name;
475 dapm_set_path_status(dest, path, i);
482 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
483 struct snd_soc_dapm_widget *kcontrolw,
484 const struct snd_kcontrol_new *kcontrol_new,
485 struct snd_kcontrol **kcontrol)
487 struct snd_soc_dapm_widget *w;
492 list_for_each_entry(w, &dapm->card->widgets, list) {
493 if (w == kcontrolw || w->dapm != kcontrolw->dapm)
495 for (i = 0; i < w->num_kcontrols; i++) {
496 if (&w->kcontrol_news[i] == kcontrol_new) {
498 *kcontrol = w->kcontrols[i];
507 /* create new dapm mixer control */
508 static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
510 struct snd_soc_dapm_context *dapm = w->dapm;
512 size_t name_len, prefix_len;
513 struct snd_soc_dapm_path *path;
514 struct snd_card *card = dapm->card->snd_card;
516 struct snd_soc_dapm_widget_list *wlist;
520 prefix = dapm->codec->name_prefix;
525 prefix_len = strlen(prefix) + 1;
530 for (i = 0; i < w->num_kcontrols; i++) {
533 list_for_each_entry(path, &w->sources, list_sink) {
535 /* mixer/mux paths name must match control name */
536 if (path->name != (char *)w->kcontrol_news[i].name)
539 if (w->kcontrols[i]) {
540 path->kcontrol = w->kcontrols[i];
544 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
545 sizeof(struct snd_soc_dapm_widget *),
546 wlist = kzalloc(wlistsize, GFP_KERNEL);
549 "ASoC: can't allocate widget list for %s\n",
553 wlist->num_widgets = 1;
554 wlist->widgets[0] = w;
556 /* add dapm control with long name.
557 * for dapm_mixer this is the concatenation of the
558 * mixer and kcontrol name.
559 * for dapm_mixer_named_ctl this is simply the
562 name_len = strlen(w->kcontrol_news[i].name) + 1;
563 if (w->id != snd_soc_dapm_mixer_named_ctl)
564 name_len += 1 + strlen(w->name);
566 path->long_name = kmalloc(name_len, GFP_KERNEL);
568 if (path->long_name == NULL) {
575 /* The control will get a prefix from
576 * the control creation process but
577 * we're also using the same prefix
578 * for widgets so cut the prefix off
579 * the front of the widget name.
581 snprintf((char *)path->long_name, name_len,
582 "%s %s", w->name + prefix_len,
583 w->kcontrol_news[i].name);
585 case snd_soc_dapm_mixer_named_ctl:
586 snprintf((char *)path->long_name, name_len,
587 "%s", w->kcontrol_news[i].name);
591 ((char *)path->long_name)[name_len - 1] = '\0';
593 path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
594 wlist, path->long_name,
596 ret = snd_ctl_add(card, path->kcontrol);
598 dev_err(dapm->dev, "ASoC: failed to add widget"
599 " %s dapm kcontrol %s: %d\n",
600 w->name, path->long_name, ret);
602 kfree(path->long_name);
603 path->long_name = NULL;
606 w->kcontrols[i] = path->kcontrol;
612 /* create new dapm mux control */
613 static int dapm_new_mux(struct snd_soc_dapm_widget *w)
615 struct snd_soc_dapm_context *dapm = w->dapm;
616 struct snd_soc_dapm_path *path = NULL;
617 struct snd_kcontrol *kcontrol;
618 struct snd_card *card = dapm->card->snd_card;
622 struct snd_soc_dapm_widget_list *wlist;
623 int shared, wlistentries;
627 if (w->num_kcontrols != 1) {
629 "ASoC: mux %s has incorrect number of controls\n",
634 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
637 wlist = kcontrol->private_data;
638 wlistentries = wlist->num_widgets + 1;
643 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
644 wlistentries * sizeof(struct snd_soc_dapm_widget *),
645 wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
648 "ASoC: can't allocate widget list for %s\n", w->name);
651 wlist->num_widgets = wlistentries;
652 wlist->widgets[wlistentries - 1] = w;
656 prefix = dapm->codec->name_prefix;
661 name = w->kcontrol_news[0].name;
666 prefix_len = strlen(prefix) + 1;
672 * The control will get a prefix from the control creation
673 * process but we're also using the same prefix for widgets so
674 * cut the prefix off the front of the widget name.
676 kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
677 name + prefix_len, prefix);
678 ret = snd_ctl_add(card, kcontrol);
680 dev_err(dapm->dev, "ASoC: failed to add kcontrol %s: %d\n",
687 kcontrol->private_data = wlist;
689 w->kcontrols[0] = kcontrol;
691 list_for_each_entry(path, &w->sources, list_sink)
692 path->kcontrol = kcontrol;
697 /* create new dapm volume control */
698 static int dapm_new_pga(struct snd_soc_dapm_widget *w)
700 if (w->num_kcontrols)
701 dev_err(w->dapm->dev,
702 "ASoC: PGA controls not supported: '%s'\n", w->name);
707 /* reset 'walked' bit for each dapm path */
708 static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
710 struct snd_soc_dapm_path *p;
712 list_for_each_entry(p, &dapm->card->paths, list)
716 /* We implement power down on suspend by checking the power state of
717 * the ALSA card - when we are suspending the ALSA state for the card
720 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
722 int level = snd_power_get_state(widget->dapm->card->snd_card);
725 case SNDRV_CTL_POWER_D3hot:
726 case SNDRV_CTL_POWER_D3cold:
727 if (widget->ignore_suspend)
728 dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n",
730 return widget->ignore_suspend;
736 /* add widget to list if it's not already in the list */
737 static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list,
738 struct snd_soc_dapm_widget *w)
740 struct snd_soc_dapm_widget_list *wlist;
741 int wlistsize, wlistentries, i;
748 /* is this widget already in the list */
749 for (i = 0; i < wlist->num_widgets; i++) {
750 if (wlist->widgets[i] == w)
754 /* allocate some new space */
755 wlistentries = wlist->num_widgets + 1;
756 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
757 wlistentries * sizeof(struct snd_soc_dapm_widget *);
758 *list = krealloc(wlist, wlistsize, GFP_KERNEL);
760 dev_err(w->dapm->dev, "ASoC: can't allocate widget list for %s\n",
766 /* insert the widget */
767 dev_dbg(w->dapm->dev, "ASoC: added %s in widget list pos %d\n",
768 w->name, wlist->num_widgets);
770 wlist->widgets[wlist->num_widgets] = w;
771 wlist->num_widgets++;
776 * Recursively check for a completed path to an active or physically connected
777 * output widget. Returns number of complete paths.
779 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
780 struct snd_soc_dapm_widget_list **list)
782 struct snd_soc_dapm_path *path;
785 if (widget->outputs >= 0)
786 return widget->outputs;
788 DAPM_UPDATE_STAT(widget, path_checks);
790 switch (widget->id) {
791 case snd_soc_dapm_supply:
792 case snd_soc_dapm_regulator_supply:
793 case snd_soc_dapm_clock_supply:
799 switch (widget->id) {
800 case snd_soc_dapm_adc:
801 case snd_soc_dapm_aif_out:
802 case snd_soc_dapm_dai:
803 if (widget->active) {
804 widget->outputs = snd_soc_dapm_suspend_check(widget);
805 return widget->outputs;
811 if (widget->connected) {
812 /* connected pin ? */
813 if (widget->id == snd_soc_dapm_output && !widget->ext) {
814 widget->outputs = snd_soc_dapm_suspend_check(widget);
815 return widget->outputs;
818 /* connected jack or spk ? */
819 if (widget->id == snd_soc_dapm_hp ||
820 widget->id == snd_soc_dapm_spk ||
821 (widget->id == snd_soc_dapm_line &&
822 !list_empty(&widget->sources))) {
823 widget->outputs = snd_soc_dapm_suspend_check(widget);
824 return widget->outputs;
828 list_for_each_entry(path, &widget->sinks, list_source) {
829 DAPM_UPDATE_STAT(widget, neighbour_checks);
840 trace_snd_soc_dapm_output_path(widget, path);
842 if (path->sink && path->connect) {
846 /* do we need to add this widget to the list ? */
849 err = dapm_list_add_widget(list, path->sink);
851 dev_err(widget->dapm->dev,
852 "ASoC: could not add widget %s\n",
859 con += is_connected_output_ep(path->sink, list);
865 widget->outputs = con;
871 * Recursively check for a completed path to an active or physically connected
872 * input widget. Returns number of complete paths.
874 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
875 struct snd_soc_dapm_widget_list **list)
877 struct snd_soc_dapm_path *path;
880 if (widget->inputs >= 0)
881 return widget->inputs;
883 DAPM_UPDATE_STAT(widget, path_checks);
885 switch (widget->id) {
886 case snd_soc_dapm_supply:
887 case snd_soc_dapm_regulator_supply:
888 case snd_soc_dapm_clock_supply:
894 /* active stream ? */
895 switch (widget->id) {
896 case snd_soc_dapm_dac:
897 case snd_soc_dapm_aif_in:
898 case snd_soc_dapm_dai:
899 if (widget->active) {
900 widget->inputs = snd_soc_dapm_suspend_check(widget);
901 return widget->inputs;
907 if (widget->connected) {
908 /* connected pin ? */
909 if (widget->id == snd_soc_dapm_input && !widget->ext) {
910 widget->inputs = snd_soc_dapm_suspend_check(widget);
911 return widget->inputs;
914 /* connected VMID/Bias for lower pops */
915 if (widget->id == snd_soc_dapm_vmid) {
916 widget->inputs = snd_soc_dapm_suspend_check(widget);
917 return widget->inputs;
920 /* connected jack ? */
921 if (widget->id == snd_soc_dapm_mic ||
922 (widget->id == snd_soc_dapm_line &&
923 !list_empty(&widget->sinks))) {
924 widget->inputs = snd_soc_dapm_suspend_check(widget);
925 return widget->inputs;
928 /* signal generator */
929 if (widget->id == snd_soc_dapm_siggen) {
930 widget->inputs = snd_soc_dapm_suspend_check(widget);
931 return widget->inputs;
935 list_for_each_entry(path, &widget->sources, list_sink) {
936 DAPM_UPDATE_STAT(widget, neighbour_checks);
947 trace_snd_soc_dapm_input_path(widget, path);
949 if (path->source && path->connect) {
953 /* do we need to add this widget to the list ? */
956 err = dapm_list_add_widget(list, path->source);
958 dev_err(widget->dapm->dev,
959 "ASoC: could not add widget %s\n",
966 con += is_connected_input_ep(path->source, list);
972 widget->inputs = con;
978 * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets.
980 * @stream: stream direction.
981 * @list: list of active widgets for this stream.
983 * Queries DAPM graph as to whether an valid audio stream path exists for
984 * the initial stream specified by name. This takes into account
985 * current mixer and mux kcontrol settings. Creates list of valid widgets.
987 * Returns the number of valid paths or negative error.
989 int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
990 struct snd_soc_dapm_widget_list **list)
992 struct snd_soc_card *card = dai->card;
995 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
998 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
999 paths = is_connected_output_ep(dai->playback_widget, list);
1001 paths = is_connected_input_ep(dai->capture_widget, list);
1003 trace_snd_soc_dapm_connected(paths, stream);
1004 dapm_clear_walk(&card->dapm);
1005 mutex_unlock(&card->dapm_mutex);
1011 * Handler for generic register modifier widget.
1013 int dapm_reg_event(struct snd_soc_dapm_widget *w,
1014 struct snd_kcontrol *kcontrol, int event)
1018 if (SND_SOC_DAPM_EVENT_ON(event))
1023 soc_widget_update_bits_locked(w, -(w->reg + 1),
1024 w->mask << w->shift, val << w->shift);
1028 EXPORT_SYMBOL_GPL(dapm_reg_event);
1031 * Handler for regulator supply widget.
1033 int dapm_regulator_event(struct snd_soc_dapm_widget *w,
1034 struct snd_kcontrol *kcontrol, int event)
1038 if (SND_SOC_DAPM_EVENT_ON(event)) {
1039 if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) {
1040 ret = regulator_allow_bypass(w->regulator, false);
1042 dev_warn(w->dapm->dev,
1043 "ASoC: Failed to bypass %s: %d\n",
1047 return regulator_enable(w->regulator);
1049 if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) {
1050 ret = regulator_allow_bypass(w->regulator, true);
1052 dev_warn(w->dapm->dev,
1053 "ASoC: Failed to unbypass %s: %d\n",
1057 return regulator_disable_deferred(w->regulator, w->shift);
1060 EXPORT_SYMBOL_GPL(dapm_regulator_event);
1063 * Handler for clock supply widget.
1065 int dapm_clock_event(struct snd_soc_dapm_widget *w,
1066 struct snd_kcontrol *kcontrol, int event)
1071 #ifdef CONFIG_HAVE_CLK
1072 if (SND_SOC_DAPM_EVENT_ON(event)) {
1073 return clk_enable(w->clk);
1075 clk_disable(w->clk);
1081 EXPORT_SYMBOL_GPL(dapm_clock_event);
1083 static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
1085 if (w->power_checked)
1086 return w->new_power;
1091 w->new_power = w->power_check(w);
1093 w->power_checked = true;
1095 return w->new_power;
1098 /* Generic check to see if a widget should be powered.
1100 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
1104 DAPM_UPDATE_STAT(w, power_checks);
1106 in = is_connected_input_ep(w, NULL);
1107 dapm_clear_walk(w->dapm);
1108 out = is_connected_output_ep(w, NULL);
1109 dapm_clear_walk(w->dapm);
1110 return out != 0 && in != 0;
1113 static int dapm_dai_check_power(struct snd_soc_dapm_widget *w)
1115 DAPM_UPDATE_STAT(w, power_checks);
1120 return dapm_generic_check_power(w);
1123 /* Check to see if an ADC has power */
1124 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
1128 DAPM_UPDATE_STAT(w, power_checks);
1131 in = is_connected_input_ep(w, NULL);
1132 dapm_clear_walk(w->dapm);
1135 return dapm_generic_check_power(w);
1139 /* Check to see if a DAC has power */
1140 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
1144 DAPM_UPDATE_STAT(w, power_checks);
1147 out = is_connected_output_ep(w, NULL);
1148 dapm_clear_walk(w->dapm);
1151 return dapm_generic_check_power(w);
1155 /* Check to see if a power supply is needed */
1156 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1158 struct snd_soc_dapm_path *path;
1160 DAPM_UPDATE_STAT(w, power_checks);
1162 /* Check if one of our outputs is connected */
1163 list_for_each_entry(path, &w->sinks, list_source) {
1164 DAPM_UPDATE_STAT(w, neighbour_checks);
1169 if (path->connected &&
1170 !path->connected(path->source, path->sink))
1176 if (dapm_widget_power_check(path->sink))
1180 dapm_clear_walk(w->dapm);
1185 static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
1190 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
1191 struct snd_soc_dapm_widget *b,
1199 sort = dapm_down_seq;
1201 if (sort[a->id] != sort[b->id])
1202 return sort[a->id] - sort[b->id];
1203 if (a->subseq != b->subseq) {
1205 return a->subseq - b->subseq;
1207 return b->subseq - a->subseq;
1209 if (a->reg != b->reg)
1210 return a->reg - b->reg;
1211 if (a->dapm != b->dapm)
1212 return (unsigned long)a->dapm - (unsigned long)b->dapm;
1217 /* Insert a widget in order into a DAPM power sequence. */
1218 static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
1219 struct list_head *list,
1222 struct snd_soc_dapm_widget *w;
1224 list_for_each_entry(w, list, power_list)
1225 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
1226 list_add_tail(&new_widget->power_list, &w->power_list);
1230 list_add_tail(&new_widget->power_list, list);
1233 static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
1234 struct snd_soc_dapm_widget *w, int event)
1236 struct snd_soc_card *card = dapm->card;
1237 const char *ev_name;
1241 case SND_SOC_DAPM_PRE_PMU:
1242 ev_name = "PRE_PMU";
1245 case SND_SOC_DAPM_POST_PMU:
1246 ev_name = "POST_PMU";
1249 case SND_SOC_DAPM_PRE_PMD:
1250 ev_name = "PRE_PMD";
1253 case SND_SOC_DAPM_POST_PMD:
1254 ev_name = "POST_PMD";
1262 if (w->power != power)
1265 if (w->event && (w->event_flags & event)) {
1266 pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
1268 trace_snd_soc_dapm_widget_event_start(w, event);
1269 ret = w->event(w, NULL, event);
1270 trace_snd_soc_dapm_widget_event_done(w, event);
1272 dev_err(dapm->dev, "ASoC: %s: %s event failed: %d\n",
1273 ev_name, w->name, ret);
1277 /* Apply the coalesced changes from a DAPM sequence */
1278 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
1279 struct list_head *pending)
1281 struct snd_soc_card *card = dapm->card;
1282 struct snd_soc_dapm_widget *w;
1284 unsigned int value = 0;
1285 unsigned int mask = 0;
1286 unsigned int cur_mask;
1288 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
1291 list_for_each_entry(w, pending, power_list) {
1292 cur_mask = 1 << w->shift;
1293 BUG_ON(reg != w->reg);
1304 pop_dbg(dapm->dev, card->pop_time,
1305 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1306 w->name, reg, value, mask);
1308 /* Check for events */
1309 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
1310 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
1314 /* Any widget will do, they should all be updating the
1317 w = list_first_entry(pending, struct snd_soc_dapm_widget,
1320 pop_dbg(dapm->dev, card->pop_time,
1321 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1322 value, mask, reg, card->pop_time);
1323 pop_wait(card->pop_time);
1324 soc_widget_update_bits_locked(w, reg, mask, value);
1327 list_for_each_entry(w, pending, power_list) {
1328 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
1329 dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
1333 /* Apply a DAPM power sequence.
1335 * We walk over a pre-sorted list of widgets to apply power to. In
1336 * order to minimise the number of writes to the device required
1337 * multiple widgets will be updated in a single write where possible.
1338 * Currently anything that requires more than a single write is not
1341 static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
1342 struct list_head *list, int event, bool power_up)
1344 struct snd_soc_dapm_widget *w, *n;
1347 int cur_subseq = -1;
1348 int cur_reg = SND_SOC_NOPM;
1349 struct snd_soc_dapm_context *cur_dapm = NULL;
1356 sort = dapm_down_seq;
1358 list_for_each_entry_safe(w, n, list, power_list) {
1361 /* Do we need to apply any queued changes? */
1362 if (sort[w->id] != cur_sort || w->reg != cur_reg ||
1363 w->dapm != cur_dapm || w->subseq != cur_subseq) {
1364 if (!list_empty(&pending))
1365 dapm_seq_run_coalesced(cur_dapm, &pending);
1367 if (cur_dapm && cur_dapm->seq_notifier) {
1368 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1369 if (sort[i] == cur_sort)
1370 cur_dapm->seq_notifier(cur_dapm,
1375 INIT_LIST_HEAD(&pending);
1377 cur_subseq = INT_MIN;
1378 cur_reg = SND_SOC_NOPM;
1383 case snd_soc_dapm_pre:
1385 list_for_each_entry_safe_continue(w, n, list,
1388 if (event == SND_SOC_DAPM_STREAM_START)
1390 NULL, SND_SOC_DAPM_PRE_PMU);
1391 else if (event == SND_SOC_DAPM_STREAM_STOP)
1393 NULL, SND_SOC_DAPM_PRE_PMD);
1396 case snd_soc_dapm_post:
1398 list_for_each_entry_safe_continue(w, n, list,
1401 if (event == SND_SOC_DAPM_STREAM_START)
1403 NULL, SND_SOC_DAPM_POST_PMU);
1404 else if (event == SND_SOC_DAPM_STREAM_STOP)
1406 NULL, SND_SOC_DAPM_POST_PMD);
1410 /* Queue it up for application */
1411 cur_sort = sort[w->id];
1412 cur_subseq = w->subseq;
1415 list_move(&w->power_list, &pending);
1420 dev_err(w->dapm->dev,
1421 "ASoC: Failed to apply widget power: %d\n", ret);
1424 if (!list_empty(&pending))
1425 dapm_seq_run_coalesced(cur_dapm, &pending);
1427 if (cur_dapm && cur_dapm->seq_notifier) {
1428 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
1429 if (sort[i] == cur_sort)
1430 cur_dapm->seq_notifier(cur_dapm,
1435 static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
1437 struct snd_soc_dapm_update *update = dapm->update;
1438 struct snd_soc_dapm_widget *w;
1447 (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
1448 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
1450 dev_err(dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n",
1454 ret = soc_widget_update_bits_locked(w, update->reg, update->mask,
1457 dev_err(dapm->dev, "ASoC: %s DAPM update failed: %d\n",
1461 (w->event_flags & SND_SOC_DAPM_POST_REG)) {
1462 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
1464 dev_err(dapm->dev, "ASoC: %s DAPM post-event failed: %d\n",
1469 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1470 * they're changing state.
1472 static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
1474 struct snd_soc_dapm_context *d = data;
1477 /* If we're off and we're not supposed to be go into STANDBY */
1478 if (d->bias_level == SND_SOC_BIAS_OFF &&
1479 d->target_bias_level != SND_SOC_BIAS_OFF) {
1481 pm_runtime_get_sync(d->dev);
1483 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1486 "ASoC: Failed to turn on bias: %d\n", ret);
1489 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1490 if (d->bias_level != d->target_bias_level) {
1491 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
1494 "ASoC: Failed to prepare bias: %d\n", ret);
1498 /* Async callback run prior to DAPM sequences - brings to their final
1501 static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
1503 struct snd_soc_dapm_context *d = data;
1506 /* If we just powered the last thing off drop to standby bias */
1507 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1508 (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
1509 d->target_bias_level == SND_SOC_BIAS_OFF)) {
1510 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
1512 dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n",
1516 /* If we're in standby and can support bias off then do that */
1517 if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1518 d->target_bias_level == SND_SOC_BIAS_OFF) {
1519 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
1521 dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n",
1525 pm_runtime_put(d->dev);
1528 /* If we just powered up then move to active bias */
1529 if (d->bias_level == SND_SOC_BIAS_PREPARE &&
1530 d->target_bias_level == SND_SOC_BIAS_ON) {
1531 ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
1533 dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n",
1538 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
1539 bool power, bool connect)
1541 /* If a connection is being made or broken then that update
1542 * will have marked the peer dirty, otherwise the widgets are
1543 * not connected and this update has no impact. */
1547 /* If the peer is already in the state we're moving to then we
1548 * won't have an impact on it. */
1549 if (power != peer->power)
1550 dapm_mark_dirty(peer, "peer state change");
1553 static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1554 struct list_head *up_list,
1555 struct list_head *down_list)
1557 struct snd_soc_dapm_path *path;
1559 if (w->power == power)
1562 trace_snd_soc_dapm_widget_power(w, power);
1564 /* If we changed our power state perhaps our neigbours changed
1567 list_for_each_entry(path, &w->sources, list_sink) {
1569 dapm_widget_set_peer_power(path->source, power,
1574 case snd_soc_dapm_supply:
1575 case snd_soc_dapm_regulator_supply:
1576 case snd_soc_dapm_clock_supply:
1577 /* Supplies can't affect their outputs, only their inputs */
1580 list_for_each_entry(path, &w->sinks, list_source) {
1582 dapm_widget_set_peer_power(path->sink, power,
1590 dapm_seq_insert(w, up_list, true);
1592 dapm_seq_insert(w, down_list, false);
1597 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
1598 struct list_head *up_list,
1599 struct list_head *down_list)
1604 case snd_soc_dapm_pre:
1605 dapm_seq_insert(w, down_list, false);
1607 case snd_soc_dapm_post:
1608 dapm_seq_insert(w, up_list, true);
1612 power = dapm_widget_power_check(w);
1614 dapm_widget_set_power(w, power, up_list, down_list);
1620 * Scan each dapm widget for complete audio path.
1621 * A complete path is a route that has valid endpoints i.e.:-
1623 * o DAC to output pin.
1624 * o Input Pin to ADC.
1625 * o Input pin to Output pin (bypass, sidetone)
1626 * o DAC to ADC (loopback).
1628 static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
1630 struct snd_soc_card *card = dapm->card;
1631 struct snd_soc_dapm_widget *w;
1632 struct snd_soc_dapm_context *d;
1634 LIST_HEAD(down_list);
1635 ASYNC_DOMAIN_EXCLUSIVE(async_domain);
1636 enum snd_soc_bias_level bias;
1638 trace_snd_soc_dapm_start(card);
1640 list_for_each_entry(d, &card->dapm_list, list) {
1641 if (d->idle_bias_off)
1642 d->target_bias_level = SND_SOC_BIAS_OFF;
1644 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1649 /* Check which widgets we need to power and store them in
1650 * lists indicating if they should be powered up or down. We
1651 * only check widgets that have been flagged as dirty but note
1652 * that new widgets may be added to the dirty list while we
1655 list_for_each_entry(w, &card->dapm_dirty, dirty) {
1656 dapm_power_one_widget(w, &up_list, &down_list);
1659 list_for_each_entry(w, &card->widgets, list) {
1661 case snd_soc_dapm_pre:
1662 case snd_soc_dapm_post:
1663 /* These widgets always need to be powered */
1666 list_del_init(&w->dirty);
1673 /* Supplies and micbiases only bring the
1674 * context up to STANDBY as unless something
1675 * else is active and passing audio they
1676 * generally don't require full power. Signal
1677 * generators are virtual pins and have no
1678 * power impact themselves.
1681 case snd_soc_dapm_siggen:
1683 case snd_soc_dapm_supply:
1684 case snd_soc_dapm_regulator_supply:
1685 case snd_soc_dapm_clock_supply:
1686 case snd_soc_dapm_micbias:
1687 if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
1688 d->target_bias_level = SND_SOC_BIAS_STANDBY;
1691 d->target_bias_level = SND_SOC_BIAS_ON;
1698 /* Force all contexts in the card to the same bias state if
1699 * they're not ground referenced.
1701 bias = SND_SOC_BIAS_OFF;
1702 list_for_each_entry(d, &card->dapm_list, list)
1703 if (d->target_bias_level > bias)
1704 bias = d->target_bias_level;
1705 list_for_each_entry(d, &card->dapm_list, list)
1706 if (!d->idle_bias_off)
1707 d->target_bias_level = bias;
1709 trace_snd_soc_dapm_walk_done(card);
1711 /* Run all the bias changes in parallel */
1712 list_for_each_entry(d, &dapm->card->dapm_list, list)
1713 async_schedule_domain(dapm_pre_sequence_async, d,
1715 async_synchronize_full_domain(&async_domain);
1717 /* Power down widgets first; try to avoid amplifying pops. */
1718 dapm_seq_run(dapm, &down_list, event, false);
1720 dapm_widget_update(dapm);
1723 dapm_seq_run(dapm, &up_list, event, true);
1725 /* Run all the bias changes in parallel */
1726 list_for_each_entry(d, &dapm->card->dapm_list, list)
1727 async_schedule_domain(dapm_post_sequence_async, d,
1729 async_synchronize_full_domain(&async_domain);
1731 /* do we need to notify any clients that DAPM event is complete */
1732 list_for_each_entry(d, &card->dapm_list, list) {
1733 if (d->stream_event)
1734 d->stream_event(d, event);
1737 pop_dbg(dapm->dev, card->pop_time,
1738 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1739 pop_wait(card->pop_time);
1741 trace_snd_soc_dapm_done(card);
1746 #ifdef CONFIG_DEBUG_FS
1747 static ssize_t dapm_widget_power_read_file(struct file *file,
1748 char __user *user_buf,
1749 size_t count, loff_t *ppos)
1751 struct snd_soc_dapm_widget *w = file->private_data;
1755 struct snd_soc_dapm_path *p = NULL;
1757 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1761 in = is_connected_input_ep(w, NULL);
1762 dapm_clear_walk(w->dapm);
1763 out = is_connected_output_ep(w, NULL);
1764 dapm_clear_walk(w->dapm);
1766 ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d",
1767 w->name, w->power ? "On" : "Off",
1768 w->force ? " (forced)" : "", in, out);
1771 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1772 " - R%d(0x%x) bit %d",
1773 w->reg, w->reg, w->shift);
1775 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1778 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1780 w->active ? "active" : "inactive");
1782 list_for_each_entry(p, &w->sources, list_sink) {
1783 if (p->connected && !p->connected(w, p->sink))
1787 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1788 " in \"%s\" \"%s\"\n",
1789 p->name ? p->name : "static",
1792 list_for_each_entry(p, &w->sinks, list_source) {
1793 if (p->connected && !p->connected(w, p->sink))
1797 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1798 " out \"%s\" \"%s\"\n",
1799 p->name ? p->name : "static",
1803 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1809 static const struct file_operations dapm_widget_power_fops = {
1810 .open = simple_open,
1811 .read = dapm_widget_power_read_file,
1812 .llseek = default_llseek,
1815 static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
1816 size_t count, loff_t *ppos)
1818 struct snd_soc_dapm_context *dapm = file->private_data;
1821 switch (dapm->bias_level) {
1822 case SND_SOC_BIAS_ON:
1825 case SND_SOC_BIAS_PREPARE:
1826 level = "Prepare\n";
1828 case SND_SOC_BIAS_STANDBY:
1829 level = "Standby\n";
1831 case SND_SOC_BIAS_OFF:
1836 level = "Unknown\n";
1840 return simple_read_from_buffer(user_buf, count, ppos, level,
1844 static const struct file_operations dapm_bias_fops = {
1845 .open = simple_open,
1846 .read = dapm_bias_read_file,
1847 .llseek = default_llseek,
1850 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1851 struct dentry *parent)
1855 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
1857 if (!dapm->debugfs_dapm) {
1859 "ASoC: Failed to create DAPM debugfs directory\n");
1863 d = debugfs_create_file("bias_level", 0444,
1864 dapm->debugfs_dapm, dapm,
1868 "ASoC: Failed to create bias level debugfs file\n");
1871 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1873 struct snd_soc_dapm_context *dapm = w->dapm;
1876 if (!dapm->debugfs_dapm || !w->name)
1879 d = debugfs_create_file(w->name, 0444,
1880 dapm->debugfs_dapm, w,
1881 &dapm_widget_power_fops);
1883 dev_warn(w->dapm->dev,
1884 "ASoC: Failed to create %s debugfs file\n",
1888 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1890 debugfs_remove_recursive(dapm->debugfs_dapm);
1894 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
1895 struct dentry *parent)
1899 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
1903 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
1909 /* test and update the power status of a mux widget */
1910 static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1911 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1913 struct snd_soc_dapm_path *path;
1916 if (widget->id != snd_soc_dapm_mux &&
1917 widget->id != snd_soc_dapm_virt_mux &&
1918 widget->id != snd_soc_dapm_value_mux)
1921 /* find dapm widget path assoc with kcontrol */
1922 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1923 if (path->kcontrol != kcontrol)
1926 if (!path->name || !e->texts[mux])
1930 /* we now need to match the string in the enum to the path */
1931 if (!(strcmp(path->name, e->texts[mux]))) {
1932 path->connect = 1; /* new connection */
1933 dapm_mark_dirty(path->source, "mux connection");
1936 dapm_mark_dirty(path->source,
1937 "mux disconnection");
1938 path->connect = 0; /* old connection must be powered down */
1943 dapm_mark_dirty(widget, "mux change");
1944 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1950 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
1951 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
1953 struct snd_soc_card *card = widget->dapm->card;
1956 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1957 ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
1958 mutex_unlock(&card->dapm_mutex);
1960 soc_dpcm_runtime_update(widget);
1963 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
1965 /* test and update the power status of a mixer or switch widget */
1966 static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1967 struct snd_kcontrol *kcontrol, int connect)
1969 struct snd_soc_dapm_path *path;
1972 if (widget->id != snd_soc_dapm_mixer &&
1973 widget->id != snd_soc_dapm_mixer_named_ctl &&
1974 widget->id != snd_soc_dapm_switch)
1977 /* find dapm widget path assoc with kcontrol */
1978 list_for_each_entry(path, &widget->dapm->card->paths, list) {
1979 if (path->kcontrol != kcontrol)
1982 /* found, now check type */
1984 path->connect = connect;
1985 dapm_mark_dirty(path->source, "mixer connection");
1989 dapm_mark_dirty(widget, "mixer update");
1990 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
1996 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
1997 struct snd_kcontrol *kcontrol, int connect)
1999 struct snd_soc_card *card = widget->dapm->card;
2002 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2003 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
2004 mutex_unlock(&card->dapm_mutex);
2006 soc_dpcm_runtime_update(widget);
2009 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
2011 /* show dapm widget status in sys fs */
2012 static ssize_t dapm_widget_show(struct device *dev,
2013 struct device_attribute *attr, char *buf)
2015 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
2016 struct snd_soc_codec *codec =rtd->codec;
2017 struct snd_soc_dapm_widget *w;
2019 char *state = "not set";
2021 list_for_each_entry(w, &codec->card->widgets, list) {
2022 if (w->dapm != &codec->dapm)
2025 /* only display widgets that burnm power */
2027 case snd_soc_dapm_hp:
2028 case snd_soc_dapm_mic:
2029 case snd_soc_dapm_spk:
2030 case snd_soc_dapm_line:
2031 case snd_soc_dapm_micbias:
2032 case snd_soc_dapm_dac:
2033 case snd_soc_dapm_adc:
2034 case snd_soc_dapm_pga:
2035 case snd_soc_dapm_out_drv:
2036 case snd_soc_dapm_mixer:
2037 case snd_soc_dapm_mixer_named_ctl:
2038 case snd_soc_dapm_supply:
2039 case snd_soc_dapm_regulator_supply:
2040 case snd_soc_dapm_clock_supply:
2042 count += sprintf(buf + count, "%s: %s\n",
2043 w->name, w->power ? "On":"Off");
2050 switch (codec->dapm.bias_level) {
2051 case SND_SOC_BIAS_ON:
2054 case SND_SOC_BIAS_PREPARE:
2057 case SND_SOC_BIAS_STANDBY:
2060 case SND_SOC_BIAS_OFF:
2064 count += sprintf(buf + count, "PM State: %s\n", state);
2069 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
2071 int snd_soc_dapm_sys_add(struct device *dev)
2073 return device_create_file(dev, &dev_attr_dapm_widget);
2076 static void snd_soc_dapm_sys_remove(struct device *dev)
2078 device_remove_file(dev, &dev_attr_dapm_widget);
2081 /* free all dapm widgets and resources */
2082 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
2084 struct snd_soc_dapm_widget *w, *next_w;
2085 struct snd_soc_dapm_path *p, *next_p;
2087 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
2088 if (w->dapm != dapm)
2092 * remove source and sink paths associated to this widget.
2093 * While removing the path, remove reference to it from both
2094 * source and sink widgets so that path is removed only once.
2096 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
2097 list_del(&p->list_sink);
2098 list_del(&p->list_source);
2100 kfree(p->long_name);
2103 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
2104 list_del(&p->list_sink);
2105 list_del(&p->list_source);
2107 kfree(p->long_name);
2110 kfree(w->kcontrols);
2116 static struct snd_soc_dapm_widget *dapm_find_widget(
2117 struct snd_soc_dapm_context *dapm, const char *pin,
2118 bool search_other_contexts)
2120 struct snd_soc_dapm_widget *w;
2121 struct snd_soc_dapm_widget *fallback = NULL;
2123 list_for_each_entry(w, &dapm->card->widgets, list) {
2124 if (!strcmp(w->name, pin)) {
2125 if (w->dapm == dapm)
2132 if (search_other_contexts)
2138 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2139 const char *pin, int status)
2141 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2144 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin);
2148 if (w->connected != status)
2149 dapm_mark_dirty(w, "pin configuration");
2151 w->connected = status;
2159 * snd_soc_dapm_sync - scan and power dapm paths
2160 * @dapm: DAPM context
2162 * Walks all dapm audio paths and powers widgets according to their
2163 * stream or path usage.
2165 * Returns 0 for success.
2167 int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2172 * Suppress early reports (eg, jacks syncing their state) to avoid
2173 * silly DAPM runs during card startup.
2175 if (!dapm->card || !dapm->card->instantiated)
2178 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2179 ret = dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2180 mutex_unlock(&dapm->card->dapm_mutex);
2183 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2185 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2186 const struct snd_soc_dapm_route *route)
2188 struct snd_soc_dapm_path *path;
2189 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
2190 struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
2192 const char *control = route->control;
2194 char prefixed_sink[80];
2195 char prefixed_source[80];
2198 if (dapm->codec && dapm->codec->name_prefix) {
2199 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2200 dapm->codec->name_prefix, route->sink);
2201 sink = prefixed_sink;
2202 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2203 dapm->codec->name_prefix, route->source);
2204 source = prefixed_source;
2207 source = route->source;
2211 * find src and dest widgets over all widgets but favor a widget from
2212 * current DAPM context
2214 list_for_each_entry(w, &dapm->card->widgets, list) {
2215 if (!wsink && !(strcmp(w->name, sink))) {
2217 if (w->dapm == dapm)
2221 if (!wsource && !(strcmp(w->name, source))) {
2223 if (w->dapm == dapm)
2227 /* use widget from another DAPM context if not found from this */
2233 if (wsource == NULL) {
2234 dev_err(dapm->dev, "ASoC: no source widget found for %s\n",
2238 if (wsink == NULL) {
2239 dev_err(dapm->dev, "ASoC: no sink widget found for %s\n",
2244 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2248 path->source = wsource;
2250 path->connected = route->connected;
2251 INIT_LIST_HEAD(&path->list);
2252 INIT_LIST_HEAD(&path->list_source);
2253 INIT_LIST_HEAD(&path->list_sink);
2255 /* check for external widgets */
2256 if (wsink->id == snd_soc_dapm_input) {
2257 if (wsource->id == snd_soc_dapm_micbias ||
2258 wsource->id == snd_soc_dapm_mic ||
2259 wsource->id == snd_soc_dapm_line ||
2260 wsource->id == snd_soc_dapm_output)
2263 if (wsource->id == snd_soc_dapm_output) {
2264 if (wsink->id == snd_soc_dapm_spk ||
2265 wsink->id == snd_soc_dapm_hp ||
2266 wsink->id == snd_soc_dapm_line ||
2267 wsink->id == snd_soc_dapm_input)
2271 /* connect static paths */
2272 if (control == NULL) {
2273 list_add(&path->list, &dapm->card->paths);
2274 list_add(&path->list_sink, &wsink->sources);
2275 list_add(&path->list_source, &wsource->sinks);
2280 /* connect dynamic paths */
2281 switch (wsink->id) {
2282 case snd_soc_dapm_adc:
2283 case snd_soc_dapm_dac:
2284 case snd_soc_dapm_pga:
2285 case snd_soc_dapm_out_drv:
2286 case snd_soc_dapm_input:
2287 case snd_soc_dapm_output:
2288 case snd_soc_dapm_siggen:
2289 case snd_soc_dapm_micbias:
2290 case snd_soc_dapm_vmid:
2291 case snd_soc_dapm_pre:
2292 case snd_soc_dapm_post:
2293 case snd_soc_dapm_supply:
2294 case snd_soc_dapm_regulator_supply:
2295 case snd_soc_dapm_clock_supply:
2296 case snd_soc_dapm_aif_in:
2297 case snd_soc_dapm_aif_out:
2298 case snd_soc_dapm_dai:
2299 case snd_soc_dapm_dai_link:
2300 list_add(&path->list, &dapm->card->paths);
2301 list_add(&path->list_sink, &wsink->sources);
2302 list_add(&path->list_source, &wsource->sinks);
2305 case snd_soc_dapm_mux:
2306 case snd_soc_dapm_virt_mux:
2307 case snd_soc_dapm_value_mux:
2308 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2309 &wsink->kcontrol_news[0]);
2313 case snd_soc_dapm_switch:
2314 case snd_soc_dapm_mixer:
2315 case snd_soc_dapm_mixer_named_ctl:
2316 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2320 case snd_soc_dapm_hp:
2321 case snd_soc_dapm_mic:
2322 case snd_soc_dapm_line:
2323 case snd_soc_dapm_spk:
2324 list_add(&path->list, &dapm->card->paths);
2325 list_add(&path->list_sink, &wsink->sources);
2326 list_add(&path->list_source, &wsource->sinks);
2331 dapm_mark_dirty(wsource, "Route added");
2332 dapm_mark_dirty(wsink, "Route added");
2337 dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n",
2338 source, control, sink);
2343 static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm,
2344 const struct snd_soc_dapm_route *route)
2346 struct snd_soc_dapm_path *path, *p;
2349 char prefixed_sink[80];
2350 char prefixed_source[80];
2352 if (route->control) {
2354 "ASoC: Removal of routes with controls not supported\n");
2358 if (dapm->codec && dapm->codec->name_prefix) {
2359 snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
2360 dapm->codec->name_prefix, route->sink);
2361 sink = prefixed_sink;
2362 snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
2363 dapm->codec->name_prefix, route->source);
2364 source = prefixed_source;
2367 source = route->source;
2371 list_for_each_entry(p, &dapm->card->paths, list) {
2372 if (strcmp(p->source->name, source) != 0)
2374 if (strcmp(p->sink->name, sink) != 0)
2381 dapm_mark_dirty(path->source, "Route removed");
2382 dapm_mark_dirty(path->sink, "Route removed");
2384 list_del(&path->list);
2385 list_del(&path->list_sink);
2386 list_del(&path->list_source);
2389 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n",
2397 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2398 * @dapm: DAPM context
2399 * @route: audio routes
2400 * @num: number of routes
2402 * Connects 2 dapm widgets together via a named audio path. The sink is
2403 * the widget receiving the audio signal, whilst the source is the sender
2404 * of the audio signal.
2406 * Returns 0 for success else error. On error all resources can be freed
2407 * with a call to snd_soc_card_free().
2409 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2410 const struct snd_soc_dapm_route *route, int num)
2414 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2415 for (i = 0; i < num; i++) {
2416 r = snd_soc_dapm_add_route(dapm, route);
2418 dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n",
2420 route->control ? route->control : "direct",
2426 mutex_unlock(&dapm->card->dapm_mutex);
2430 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
2433 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
2434 * @dapm: DAPM context
2435 * @route: audio routes
2436 * @num: number of routes
2438 * Removes routes from the DAPM context.
2440 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
2441 const struct snd_soc_dapm_route *route, int num)
2445 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2446 for (i = 0; i < num; i++) {
2447 snd_soc_dapm_del_route(dapm, route);
2450 mutex_unlock(&dapm->card->dapm_mutex);
2454 EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes);
2456 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2457 const struct snd_soc_dapm_route *route)
2459 struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
2462 struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
2465 struct snd_soc_dapm_path *path;
2469 dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n",
2475 dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n",
2480 if (route->control || route->connected)
2481 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n",
2482 route->source, route->sink);
2484 list_for_each_entry(path, &source->sinks, list_source) {
2485 if (path->sink == sink) {
2492 dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n",
2493 route->source, route->sink);
2495 dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n",
2496 count, route->source, route->sink);
2502 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2503 * @dapm: DAPM context
2504 * @route: audio routes
2505 * @num: number of routes
2507 * Mark existing routes matching those specified in the passed array
2508 * as being weak, meaning that they are ignored for the purpose of
2509 * power decisions. The main intended use case is for sidetone paths
2510 * which couple audio between other independent paths if they are both
2511 * active in order to make the combination work better at the user
2512 * level but which aren't intended to be "used".
2514 * Note that CODEC drivers should not use this as sidetone type paths
2515 * can frequently also be used as bypass paths.
2517 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
2518 const struct snd_soc_dapm_route *route, int num)
2523 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2524 for (i = 0; i < num; i++) {
2525 err = snd_soc_dapm_weak_route(dapm, route);
2530 mutex_unlock(&dapm->card->dapm_mutex);
2534 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2537 * snd_soc_dapm_new_widgets - add new dapm widgets
2538 * @dapm: DAPM context
2540 * Checks the codec for any new dapm widgets and creates them if found.
2542 * Returns 0 for success.
2544 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
2546 struct snd_soc_dapm_widget *w;
2549 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
2551 list_for_each_entry(w, &dapm->card->widgets, list)
2556 if (w->num_kcontrols) {
2557 w->kcontrols = kzalloc(w->num_kcontrols *
2558 sizeof(struct snd_kcontrol *),
2560 if (!w->kcontrols) {
2561 mutex_unlock(&dapm->card->dapm_mutex);
2567 case snd_soc_dapm_switch:
2568 case snd_soc_dapm_mixer:
2569 case snd_soc_dapm_mixer_named_ctl:
2572 case snd_soc_dapm_mux:
2573 case snd_soc_dapm_virt_mux:
2574 case snd_soc_dapm_value_mux:
2577 case snd_soc_dapm_pga:
2578 case snd_soc_dapm_out_drv:
2585 /* Read the initial power state from the device */
2587 val = soc_widget_read(w, w->reg);
2588 val &= 1 << w->shift;
2598 dapm_mark_dirty(w, "new widget");
2599 dapm_debugfs_add_widget(w);
2602 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
2603 mutex_unlock(&dapm->card->dapm_mutex);
2606 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
2609 * snd_soc_dapm_get_volsw - dapm mixer get callback
2610 * @kcontrol: mixer control
2611 * @ucontrol: control element information
2613 * Callback to get the value of a dapm mixer control.
2615 * Returns 0 for success.
2617 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
2618 struct snd_ctl_elem_value *ucontrol)
2620 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2621 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2622 struct soc_mixer_control *mc =
2623 (struct soc_mixer_control *)kcontrol->private_value;
2624 unsigned int reg = mc->reg;
2625 unsigned int shift = mc->shift;
2627 unsigned int mask = (1 << fls(max)) - 1;
2628 unsigned int invert = mc->invert;
2630 if (snd_soc_volsw_is_stereo(mc))
2631 dev_warn(widget->dapm->dev,
2632 "ASoC: Control '%s' is stereo, which is not supported\n",
2635 ucontrol->value.integer.value[0] =
2636 (snd_soc_read(widget->codec, reg) >> shift) & mask;
2638 ucontrol->value.integer.value[0] =
2639 max - ucontrol->value.integer.value[0];
2643 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
2646 * snd_soc_dapm_put_volsw - dapm mixer set callback
2647 * @kcontrol: mixer control
2648 * @ucontrol: control element information
2650 * Callback to set the value of a dapm mixer control.
2652 * Returns 0 for success.
2654 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
2655 struct snd_ctl_elem_value *ucontrol)
2657 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2658 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2659 struct snd_soc_codec *codec = widget->codec;
2660 struct snd_soc_card *card = codec->card;
2661 struct soc_mixer_control *mc =
2662 (struct soc_mixer_control *)kcontrol->private_value;
2663 unsigned int reg = mc->reg;
2664 unsigned int shift = mc->shift;
2666 unsigned int mask = (1 << fls(max)) - 1;
2667 unsigned int invert = mc->invert;
2669 int connect, change;
2670 struct snd_soc_dapm_update update;
2673 if (snd_soc_volsw_is_stereo(mc))
2674 dev_warn(widget->dapm->dev,
2675 "ASoC: Control '%s' is stereo, which is not supported\n",
2678 val = (ucontrol->value.integer.value[0] & mask);
2683 mask = mask << shift;
2686 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2688 change = snd_soc_test_bits(widget->codec, reg, mask, val);
2690 for (wi = 0; wi < wlist->num_widgets; wi++) {
2691 widget = wlist->widgets[wi];
2693 widget->value = val;
2695 update.kcontrol = kcontrol;
2696 update.widget = widget;
2700 widget->dapm->update = &update;
2702 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2704 widget->dapm->update = NULL;
2708 mutex_unlock(&card->dapm_mutex);
2711 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
2714 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2715 * @kcontrol: mixer control
2716 * @ucontrol: control element information
2718 * Callback to get the value of a dapm enumerated double mixer control.
2720 * Returns 0 for success.
2722 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2723 struct snd_ctl_elem_value *ucontrol)
2725 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2726 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2727 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2730 val = snd_soc_read(widget->codec, e->reg);
2731 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & e->mask;
2732 if (e->shift_l != e->shift_r)
2733 ucontrol->value.enumerated.item[1] =
2734 (val >> e->shift_r) & e->mask;
2738 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2741 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2742 * @kcontrol: mixer control
2743 * @ucontrol: control element information
2745 * Callback to set the value of a dapm enumerated double mixer control.
2747 * Returns 0 for success.
2749 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2750 struct snd_ctl_elem_value *ucontrol)
2752 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2753 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2754 struct snd_soc_codec *codec = widget->codec;
2755 struct snd_soc_card *card = codec->card;
2756 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2757 unsigned int val, mux, change;
2759 struct snd_soc_dapm_update update;
2762 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2764 mux = ucontrol->value.enumerated.item[0];
2765 val = mux << e->shift_l;
2766 mask = e->mask << e->shift_l;
2767 if (e->shift_l != e->shift_r) {
2768 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2770 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2771 mask |= e->mask << e->shift_r;
2774 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2776 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2778 for (wi = 0; wi < wlist->num_widgets; wi++) {
2779 widget = wlist->widgets[wi];
2781 widget->value = val;
2783 update.kcontrol = kcontrol;
2784 update.widget = widget;
2785 update.reg = e->reg;
2788 widget->dapm->update = &update;
2790 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2792 widget->dapm->update = NULL;
2796 mutex_unlock(&card->dapm_mutex);
2799 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
2802 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2803 * @kcontrol: mixer control
2804 * @ucontrol: control element information
2806 * Returns 0 for success.
2808 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
2809 struct snd_ctl_elem_value *ucontrol)
2811 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2812 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2814 ucontrol->value.enumerated.item[0] = widget->value;
2818 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
2821 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2822 * @kcontrol: mixer control
2823 * @ucontrol: control element information
2825 * Returns 0 for success.
2827 int snd_soc_dapm_put_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];
2832 struct snd_soc_codec *codec = widget->codec;
2833 struct snd_soc_card *card = codec->card;
2834 struct soc_enum *e =
2835 (struct soc_enum *)kcontrol->private_value;
2840 if (ucontrol->value.enumerated.item[0] >= e->max)
2843 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2845 change = widget->value != ucontrol->value.enumerated.item[0];
2847 for (wi = 0; wi < wlist->num_widgets; wi++) {
2848 widget = wlist->widgets[wi];
2850 widget->value = ucontrol->value.enumerated.item[0];
2852 soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
2856 mutex_unlock(&card->dapm_mutex);
2859 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
2862 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2864 * @kcontrol: mixer control
2865 * @ucontrol: control element information
2867 * Callback to get the value of a dapm semi enumerated double mixer control.
2869 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2870 * used for handling bitfield coded enumeration for example.
2872 * Returns 0 for success.
2874 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
2875 struct snd_ctl_elem_value *ucontrol)
2877 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2878 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2879 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2880 unsigned int reg_val, val, mux;
2882 reg_val = snd_soc_read(widget->codec, e->reg);
2883 val = (reg_val >> e->shift_l) & e->mask;
2884 for (mux = 0; mux < e->max; mux++) {
2885 if (val == e->values[mux])
2888 ucontrol->value.enumerated.item[0] = mux;
2889 if (e->shift_l != e->shift_r) {
2890 val = (reg_val >> e->shift_r) & e->mask;
2891 for (mux = 0; mux < e->max; mux++) {
2892 if (val == e->values[mux])
2895 ucontrol->value.enumerated.item[1] = mux;
2900 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
2903 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2905 * @kcontrol: mixer control
2906 * @ucontrol: control element information
2908 * Callback to set the value of a dapm semi enumerated double mixer control.
2910 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2911 * used for handling bitfield coded enumeration for example.
2913 * Returns 0 for success.
2915 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
2916 struct snd_ctl_elem_value *ucontrol)
2918 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2919 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2920 struct snd_soc_codec *codec = widget->codec;
2921 struct snd_soc_card *card = codec->card;
2922 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2923 unsigned int val, mux, change;
2925 struct snd_soc_dapm_update update;
2928 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2930 mux = ucontrol->value.enumerated.item[0];
2931 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2932 mask = e->mask << e->shift_l;
2933 if (e->shift_l != e->shift_r) {
2934 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2936 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2937 mask |= e->mask << e->shift_r;
2940 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2942 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
2944 for (wi = 0; wi < wlist->num_widgets; wi++) {
2945 widget = wlist->widgets[wi];
2947 widget->value = val;
2949 update.kcontrol = kcontrol;
2950 update.widget = widget;
2951 update.reg = e->reg;
2954 widget->dapm->update = &update;
2956 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2958 widget->dapm->update = NULL;
2962 mutex_unlock(&card->dapm_mutex);
2965 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
2968 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2970 * @kcontrol: mixer control
2971 * @uinfo: control element information
2973 * Callback to provide information about a pin switch control.
2975 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
2976 struct snd_ctl_elem_info *uinfo)
2978 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2980 uinfo->value.integer.min = 0;
2981 uinfo->value.integer.max = 1;
2985 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
2988 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2990 * @kcontrol: mixer control
2993 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
2994 struct snd_ctl_elem_value *ucontrol)
2996 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
2997 const char *pin = (const char *)kcontrol->private_value;
2999 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3001 ucontrol->value.integer.value[0] =
3002 snd_soc_dapm_get_pin_status(&card->dapm, pin);
3004 mutex_unlock(&card->dapm_mutex);
3008 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
3011 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3013 * @kcontrol: mixer control
3016 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
3017 struct snd_ctl_elem_value *ucontrol)
3019 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
3020 const char *pin = (const char *)kcontrol->private_value;
3022 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3024 if (ucontrol->value.integer.value[0])
3025 snd_soc_dapm_enable_pin(&card->dapm, pin);
3027 snd_soc_dapm_disable_pin(&card->dapm, pin);
3029 mutex_unlock(&card->dapm_mutex);
3031 snd_soc_dapm_sync(&card->dapm);
3034 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
3036 static struct snd_soc_dapm_widget *
3037 snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3038 const struct snd_soc_dapm_widget *widget)
3040 struct snd_soc_dapm_widget *w;
3044 if ((w = dapm_cnew_widget(widget)) == NULL)
3048 case snd_soc_dapm_regulator_supply:
3049 w->regulator = devm_regulator_get(dapm->dev, w->name);
3050 if (IS_ERR(w->regulator)) {
3051 ret = PTR_ERR(w->regulator);
3052 dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
3057 if (w->invert & SND_SOC_DAPM_REGULATOR_BYPASS) {
3058 ret = regulator_allow_bypass(w->regulator, true);
3060 dev_warn(w->dapm->dev,
3061 "ASoC: Failed to unbypass %s: %d\n",
3065 case snd_soc_dapm_clock_supply:
3066 #ifdef CONFIG_CLKDEV_LOOKUP
3067 w->clk = devm_clk_get(dapm->dev, w->name);
3068 if (IS_ERR(w->clk)) {
3069 ret = PTR_ERR(w->clk);
3070 dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
3082 name_len = strlen(widget->name) + 1;
3083 if (dapm->codec && dapm->codec->name_prefix)
3084 name_len += 1 + strlen(dapm->codec->name_prefix);
3085 w->name = kmalloc(name_len, GFP_KERNEL);
3086 if (w->name == NULL) {
3090 if (dapm->codec && dapm->codec->name_prefix)
3091 snprintf((char *)w->name, name_len, "%s %s",
3092 dapm->codec->name_prefix, widget->name);
3094 snprintf((char *)w->name, name_len, "%s", widget->name);
3097 case snd_soc_dapm_switch:
3098 case snd_soc_dapm_mixer:
3099 case snd_soc_dapm_mixer_named_ctl:
3100 w->power_check = dapm_generic_check_power;
3102 case snd_soc_dapm_mux:
3103 case snd_soc_dapm_virt_mux:
3104 case snd_soc_dapm_value_mux:
3105 w->power_check = dapm_generic_check_power;
3107 case snd_soc_dapm_adc:
3108 case snd_soc_dapm_aif_out:
3109 w->power_check = dapm_adc_check_power;
3111 case snd_soc_dapm_dac:
3112 case snd_soc_dapm_aif_in:
3113 w->power_check = dapm_dac_check_power;
3115 case snd_soc_dapm_pga:
3116 case snd_soc_dapm_out_drv:
3117 case snd_soc_dapm_input:
3118 case snd_soc_dapm_output:
3119 case snd_soc_dapm_micbias:
3120 case snd_soc_dapm_spk:
3121 case snd_soc_dapm_hp:
3122 case snd_soc_dapm_mic:
3123 case snd_soc_dapm_line:
3124 case snd_soc_dapm_dai_link:
3125 w->power_check = dapm_generic_check_power;
3127 case snd_soc_dapm_supply:
3128 case snd_soc_dapm_regulator_supply:
3129 case snd_soc_dapm_clock_supply:
3130 w->power_check = dapm_supply_check_power;
3132 case snd_soc_dapm_dai:
3133 w->power_check = dapm_dai_check_power;
3136 w->power_check = dapm_always_on_check_power;
3141 w->codec = dapm->codec;
3142 w->platform = dapm->platform;
3143 INIT_LIST_HEAD(&w->sources);
3144 INIT_LIST_HEAD(&w->sinks);
3145 INIT_LIST_HEAD(&w->list);
3146 INIT_LIST_HEAD(&w->dirty);
3147 list_add(&w->list, &dapm->card->widgets);
3149 /* machine layer set ups unconnected pins and insertions */
3155 * snd_soc_dapm_new_controls - create new dapm controls
3156 * @dapm: DAPM context
3157 * @widget: widget array
3158 * @num: number of widgets
3160 * Creates new DAPM controls based upon the templates.
3162 * Returns 0 for success else error.
3164 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
3165 const struct snd_soc_dapm_widget *widget,
3168 struct snd_soc_dapm_widget *w;
3172 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
3173 for (i = 0; i < num; i++) {
3174 w = snd_soc_dapm_new_control(dapm, widget);
3177 "ASoC: Failed to create DAPM control %s\n",
3184 mutex_unlock(&dapm->card->dapm_mutex);
3187 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
3189 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3190 struct snd_kcontrol *kcontrol, int event)
3192 struct snd_soc_dapm_path *source_p, *sink_p;
3193 struct snd_soc_dai *source, *sink;
3194 const struct snd_soc_pcm_stream *config = w->params;
3195 struct snd_pcm_substream substream;
3196 struct snd_pcm_hw_params *params = NULL;
3201 BUG_ON(list_empty(&w->sources) || list_empty(&w->sinks));
3203 /* We only support a single source and sink, pick the first */
3204 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path,
3206 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,
3209 BUG_ON(!source_p || !sink_p);
3210 BUG_ON(!sink_p->source || !source_p->sink);
3211 BUG_ON(!source_p->source || !sink_p->sink);
3213 source = source_p->source->priv;
3214 sink = sink_p->sink->priv;
3216 /* Be a little careful as we don't want to overflow the mask array */
3217 if (config->formats) {
3218 fmt = ffs(config->formats) - 1;
3220 dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n",
3225 /* Currently very limited parameter selection */
3226 params = kzalloc(sizeof(*params), GFP_KERNEL);
3231 snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
3233 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min =
3235 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max =
3238 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min
3239 = config->channels_min;
3240 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max
3241 = config->channels_max;
3243 memset(&substream, 0, sizeof(substream));
3246 case SND_SOC_DAPM_PRE_PMU:
3247 if (source->driver->ops && source->driver->ops->hw_params) {
3248 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3249 ret = source->driver->ops->hw_params(&substream,
3252 dev_err(source->dev,
3253 "ASoC: hw_params() failed: %d\n", ret);
3258 if (sink->driver->ops && sink->driver->ops->hw_params) {
3259 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3260 ret = sink->driver->ops->hw_params(&substream, params,
3264 "ASoC: hw_params() failed: %d\n", ret);
3270 case SND_SOC_DAPM_POST_PMU:
3271 ret = snd_soc_dai_digital_mute(sink, 0,
3272 SNDRV_PCM_STREAM_PLAYBACK);
3273 if (ret != 0 && ret != -ENOTSUPP)
3274 dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret);
3278 case SND_SOC_DAPM_PRE_PMD:
3279 ret = snd_soc_dai_digital_mute(sink, 1,
3280 SNDRV_PCM_STREAM_PLAYBACK);
3281 if (ret != 0 && ret != -ENOTSUPP)
3282 dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret);
3296 int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3297 const struct snd_soc_pcm_stream *params,
3298 struct snd_soc_dapm_widget *source,
3299 struct snd_soc_dapm_widget *sink)
3301 struct snd_soc_dapm_route routes[2];
3302 struct snd_soc_dapm_widget template;
3303 struct snd_soc_dapm_widget *w;
3307 len = strlen(source->name) + strlen(sink->name) + 2;
3308 link_name = devm_kzalloc(card->dev, len, GFP_KERNEL);
3311 snprintf(link_name, len, "%s-%s", source->name, sink->name);
3313 memset(&template, 0, sizeof(template));
3314 template.reg = SND_SOC_NOPM;
3315 template.id = snd_soc_dapm_dai_link;
3316 template.name = link_name;
3317 template.event = snd_soc_dai_link_event;
3318 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3319 SND_SOC_DAPM_PRE_PMD;
3321 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
3323 w = snd_soc_dapm_new_control(&card->dapm, &template);
3325 dev_err(card->dev, "ASoC: Failed to create %s widget\n",
3332 memset(&routes, 0, sizeof(routes));
3334 routes[0].source = source->name;
3335 routes[0].sink = link_name;
3336 routes[1].source = link_name;
3337 routes[1].sink = sink->name;
3339 return snd_soc_dapm_add_routes(&card->dapm, routes,
3340 ARRAY_SIZE(routes));
3343 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3344 struct snd_soc_dai *dai)
3346 struct snd_soc_dapm_widget template;
3347 struct snd_soc_dapm_widget *w;
3349 WARN_ON(dapm->dev != dai->dev);
3351 memset(&template, 0, sizeof(template));
3352 template.reg = SND_SOC_NOPM;
3354 if (dai->driver->playback.stream_name) {
3355 template.id = snd_soc_dapm_dai;
3356 template.name = dai->driver->playback.stream_name;
3357 template.sname = dai->driver->playback.stream_name;
3359 dev_dbg(dai->dev, "ASoC: adding %s widget\n",
3362 w = snd_soc_dapm_new_control(dapm, &template);
3364 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3365 dai->driver->playback.stream_name);
3369 dai->playback_widget = w;
3372 if (dai->driver->capture.stream_name) {
3373 template.id = snd_soc_dapm_dai;
3374 template.name = dai->driver->capture.stream_name;
3375 template.sname = dai->driver->capture.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->capture.stream_name);
3387 dai->capture_widget = w;
3393 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3395 struct snd_soc_dapm_widget *dai_w, *w;
3396 struct snd_soc_dai *dai;
3397 struct snd_soc_dapm_route r;
3399 memset(&r, 0, sizeof(r));
3401 /* For each DAI widget... */
3402 list_for_each_entry(dai_w, &card->widgets, list) {
3403 if (dai_w->id != snd_soc_dapm_dai)
3408 /* ...find all widgets with the same stream and link them */
3409 list_for_each_entry(w, &card->widgets, list) {
3410 if (w->dapm != dai_w->dapm)
3413 if (w->id == snd_soc_dapm_dai)
3419 if (dai->driver->playback.stream_name &&
3421 dai->driver->playback.stream_name)) {
3422 r.source = dai->playback_widget->name;
3424 dev_dbg(dai->dev, "%s -> %s\n",
3427 snd_soc_dapm_add_route(w->dapm, &r);
3430 if (dai->driver->capture.stream_name &&
3432 dai->driver->capture.stream_name)) {
3434 r.sink = dai->capture_widget->name;
3435 dev_dbg(dai->dev, "%s -> %s\n",
3438 snd_soc_dapm_add_route(w->dapm, &r);
3446 static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3450 struct snd_soc_dapm_widget *w_cpu, *w_codec;
3451 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
3452 struct snd_soc_dai *codec_dai = rtd->codec_dai;
3454 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
3455 w_cpu = cpu_dai->playback_widget;
3456 w_codec = codec_dai->playback_widget;
3458 w_cpu = cpu_dai->capture_widget;
3459 w_codec = codec_dai->capture_widget;
3464 dapm_mark_dirty(w_cpu, "stream event");
3467 case SND_SOC_DAPM_STREAM_START:
3470 case SND_SOC_DAPM_STREAM_STOP:
3473 case SND_SOC_DAPM_STREAM_SUSPEND:
3474 case SND_SOC_DAPM_STREAM_RESUME:
3475 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3476 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3483 dapm_mark_dirty(w_codec, "stream event");
3486 case SND_SOC_DAPM_STREAM_START:
3487 w_codec->active = 1;
3489 case SND_SOC_DAPM_STREAM_STOP:
3490 w_codec->active = 0;
3492 case SND_SOC_DAPM_STREAM_SUSPEND:
3493 case SND_SOC_DAPM_STREAM_RESUME:
3494 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
3495 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3500 dapm_power_widgets(&rtd->card->dapm, event);
3504 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3505 * @rtd: PCM runtime data
3506 * @stream: stream name
3507 * @event: stream event
3509 * Sends a stream event to the dapm core. The core then makes any
3510 * necessary widget power changes.
3512 * Returns 0 for success else error.
3514 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
3517 struct snd_soc_card *card = rtd->card;
3519 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3520 soc_dapm_stream_event(rtd, stream, event);
3521 mutex_unlock(&card->dapm_mutex);
3525 * snd_soc_dapm_enable_pin - enable pin.
3526 * @dapm: DAPM context
3529 * Enables input/output pin and its parents or children widgets iff there is
3530 * a valid audio route and active audio stream.
3531 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3532 * do any widget power switching.
3534 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3536 return snd_soc_dapm_set_pin(dapm, pin, 1);
3538 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
3541 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3542 * @dapm: DAPM context
3545 * Enables input/output pin regardless of any other state. This is
3546 * intended for use with microphone bias supplies used in microphone
3549 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3550 * do any widget power switching.
3552 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
3555 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3558 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin);
3562 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin);
3565 dapm_mark_dirty(w, "force enable");
3569 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
3572 * snd_soc_dapm_disable_pin - disable pin.
3573 * @dapm: DAPM context
3576 * Disables input/output pin and its parents or children widgets.
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_disable_pin(struct snd_soc_dapm_context *dapm,
3583 return snd_soc_dapm_set_pin(dapm, pin, 0);
3585 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
3588 * snd_soc_dapm_nc_pin - permanently disable pin.
3589 * @dapm: DAPM context
3592 * Marks the specified pin as being not connected, disabling it along
3593 * any parent or child widgets. At present this is identical to
3594 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3595 * additional things such as disabling controls which only affect
3596 * paths through the pin.
3598 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3599 * do any widget power switching.
3601 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
3603 return snd_soc_dapm_set_pin(dapm, pin, 0);
3605 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
3608 * snd_soc_dapm_get_pin_status - get audio pin status
3609 * @dapm: DAPM context
3610 * @pin: audio signal pin endpoint (or start point)
3612 * Get audio pin status - connected or disconnected.
3614 * Returns 1 for connected otherwise 0.
3616 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
3619 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
3622 return w->connected;
3626 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
3629 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3630 * @dapm: DAPM context
3631 * @pin: audio signal pin endpoint (or start point)
3633 * Mark the given endpoint or pin as ignoring suspend. When the
3634 * system is disabled a path between two endpoints flagged as ignoring
3635 * suspend will not be disabled. The path must already be enabled via
3636 * normal means at suspend time, it will not be turned on if it was not
3639 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
3642 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
3645 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin);
3649 w->ignore_suspend = 1;
3653 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3655 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
3656 struct snd_soc_dapm_widget *w)
3658 struct snd_soc_dapm_path *p;
3660 list_for_each_entry(p, &card->paths, list) {
3661 if ((p->source == w) || (p->sink == w)) {
3663 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3664 p->source->name, p->source->id, p->source->dapm,
3665 p->sink->name, p->sink->id, p->sink->dapm);
3667 /* Connected to something other than the codec */
3668 if (p->source->dapm != p->sink->dapm)
3671 * Loopback connection from codec external pin to
3672 * codec external pin
3674 if (p->sink->id == snd_soc_dapm_input) {
3675 switch (p->source->id) {
3676 case snd_soc_dapm_output:
3677 case snd_soc_dapm_micbias:
3690 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3691 * @codec: The codec whose pins should be processed
3693 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3694 * which are unused. Pins are used if they are connected externally to the
3695 * codec, whether that be to some other device, or a loop-back connection to
3698 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
3700 struct snd_soc_card *card = codec->card;
3701 struct snd_soc_dapm_context *dapm = &codec->dapm;
3702 struct snd_soc_dapm_widget *w;
3704 dev_dbg(codec->dev, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n",
3705 &card->dapm, &codec->dapm);
3707 list_for_each_entry(w, &card->widgets, list) {
3708 if (w->dapm != dapm)
3711 case snd_soc_dapm_input:
3712 case snd_soc_dapm_output:
3713 case snd_soc_dapm_micbias:
3714 dev_dbg(codec->dev, "ASoC: Auto NC: Checking widget %s\n",
3716 if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
3718 "... Not in map; disabling\n");
3719 snd_soc_dapm_nc_pin(dapm, w->name);
3729 * snd_soc_dapm_free - free dapm resources
3730 * @dapm: DAPM context
3732 * Free all dapm widgets and resources.
3734 void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
3736 snd_soc_dapm_sys_remove(dapm->dev);
3737 dapm_debugfs_cleanup(dapm);
3738 dapm_free_widgets(dapm);
3739 list_del(&dapm->list);
3741 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
3743 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
3745 struct snd_soc_card *card = dapm->card;
3746 struct snd_soc_dapm_widget *w;
3747 LIST_HEAD(down_list);
3750 mutex_lock(&card->dapm_mutex);
3752 list_for_each_entry(w, &dapm->card->widgets, list) {
3753 if (w->dapm != dapm)
3756 dapm_seq_insert(w, &down_list, false);
3762 /* If there were no widgets to power down we're already in
3766 if (dapm->bias_level == SND_SOC_BIAS_ON)
3767 snd_soc_dapm_set_bias_level(dapm,
3768 SND_SOC_BIAS_PREPARE);
3769 dapm_seq_run(dapm, &down_list, 0, false);
3770 if (dapm->bias_level == SND_SOC_BIAS_PREPARE)
3771 snd_soc_dapm_set_bias_level(dapm,
3772 SND_SOC_BIAS_STANDBY);
3775 mutex_unlock(&card->dapm_mutex);
3779 * snd_soc_dapm_shutdown - callback for system shutdown
3781 void snd_soc_dapm_shutdown(struct snd_soc_card *card)
3783 struct snd_soc_codec *codec;
3785 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
3786 soc_dapm_shutdown_codec(&codec->dapm);
3787 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
3788 snd_soc_dapm_set_bias_level(&codec->dapm,
3793 /* Module information */
3794 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3795 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3796 MODULE_LICENSE("GPL");