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/meadphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
21 * o Delayed powerdown of audio susbsystem to reduce pops between a quick
25 * o DAPM power change sequencing - allow for configurable per
27 * o Support for analogue bias optimisation.
28 * o Support for reduced codec oversampling rates.
29 * o Support for reduced codec bias currents.
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/init.h>
35 #include <linux/delay.h>
37 #include <linux/bitops.h>
38 #include <linux/platform_device.h>
39 #include <linux/jiffies.h>
40 #include <sound/core.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc-dapm.h>
44 #include <sound/initval.h>
48 #define dump_dapm(codec, action) dbg_dump_dapm(codec, action)
50 #define dump_dapm(codec, action)
53 /* dapm power sequences - make this per codec in the future */
54 static int dapm_up_seq[] = {
55 snd_soc_dapm_pre, snd_soc_dapm_supply, snd_soc_dapm_micbias,
56 snd_soc_dapm_mic, snd_soc_dapm_mux, snd_soc_dapm_value_mux,
57 snd_soc_dapm_dac, snd_soc_dapm_mixer, snd_soc_dapm_mixer_named_ctl,
58 snd_soc_dapm_pga, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk,
62 static int dapm_down_seq[] = {
63 snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk,
64 snd_soc_dapm_pga, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_mixer,
65 snd_soc_dapm_dac, snd_soc_dapm_mic, snd_soc_dapm_micbias,
66 snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_supply,
70 static void pop_wait(u32 pop_time)
73 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
76 static void pop_dbg(u32 pop_time, const char *fmt, ...)
90 /* create a new dapm widget */
91 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
92 const struct snd_soc_dapm_widget *_widget)
94 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
98 * snd_soc_dapm_set_bias_level - set the bias level for the system
99 * @socdev: audio device
100 * @level: level to configure
102 * Configure the bias (power) levels for the SoC audio device.
104 * Returns 0 for success else error.
106 static int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
107 enum snd_soc_bias_level level)
109 struct snd_soc_card *card = socdev->card;
110 struct snd_soc_codec *codec = socdev->card->codec;
113 if (card->set_bias_level)
114 ret = card->set_bias_level(card, level);
115 if (ret == 0 && codec->set_bias_level)
116 ret = codec->set_bias_level(codec, level);
121 /* set up initial codec paths */
122 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
123 struct snd_soc_dapm_path *p, int i)
126 case snd_soc_dapm_switch:
127 case snd_soc_dapm_mixer:
128 case snd_soc_dapm_mixer_named_ctl: {
130 struct soc_mixer_control *mc = (struct soc_mixer_control *)
131 w->kcontrols[i].private_value;
132 unsigned int reg = mc->reg;
133 unsigned int shift = mc->shift;
135 unsigned int mask = (1 << fls(max)) - 1;
136 unsigned int invert = mc->invert;
138 val = snd_soc_read(w->codec, reg);
139 val = (val >> shift) & mask;
141 if ((invert && !val) || (!invert && val))
147 case snd_soc_dapm_mux: {
148 struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
149 int val, item, bitmask;
151 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
153 val = snd_soc_read(w->codec, e->reg);
154 item = (val >> e->shift_l) & (bitmask - 1);
157 for (i = 0; i < e->max; i++) {
158 if (!(strcmp(p->name, e->texts[i])) && item == i)
163 case snd_soc_dapm_value_mux: {
164 struct soc_enum *e = (struct soc_enum *)
165 w->kcontrols[i].private_value;
168 val = snd_soc_read(w->codec, e->reg);
169 val = (val >> e->shift_l) & e->mask;
170 for (item = 0; item < e->max; item++) {
171 if (val == e->values[item])
176 for (i = 0; i < e->max; i++) {
177 if (!(strcmp(p->name, e->texts[i])) && item == i)
182 /* does not effect routing - always connected */
183 case snd_soc_dapm_pga:
184 case snd_soc_dapm_output:
185 case snd_soc_dapm_adc:
186 case snd_soc_dapm_input:
187 case snd_soc_dapm_dac:
188 case snd_soc_dapm_micbias:
189 case snd_soc_dapm_vmid:
190 case snd_soc_dapm_supply:
193 /* does effect routing - dynamically connected */
194 case snd_soc_dapm_hp:
195 case snd_soc_dapm_mic:
196 case snd_soc_dapm_spk:
197 case snd_soc_dapm_line:
198 case snd_soc_dapm_pre:
199 case snd_soc_dapm_post:
205 /* connect mux widget to it's interconnecting audio paths */
206 static int dapm_connect_mux(struct snd_soc_codec *codec,
207 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
208 struct snd_soc_dapm_path *path, const char *control_name,
209 const struct snd_kcontrol_new *kcontrol)
211 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
214 for (i = 0; i < e->max; i++) {
215 if (!(strcmp(control_name, e->texts[i]))) {
216 list_add(&path->list, &codec->dapm_paths);
217 list_add(&path->list_sink, &dest->sources);
218 list_add(&path->list_source, &src->sinks);
219 path->name = (char*)e->texts[i];
220 dapm_set_path_status(dest, path, 0);
228 /* connect mixer widget to it's interconnecting audio paths */
229 static int dapm_connect_mixer(struct snd_soc_codec *codec,
230 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
231 struct snd_soc_dapm_path *path, const char *control_name)
235 /* search for mixer kcontrol */
236 for (i = 0; i < dest->num_kcontrols; i++) {
237 if (!strcmp(control_name, dest->kcontrols[i].name)) {
238 list_add(&path->list, &codec->dapm_paths);
239 list_add(&path->list_sink, &dest->sources);
240 list_add(&path->list_source, &src->sinks);
241 path->name = dest->kcontrols[i].name;
242 dapm_set_path_status(dest, path, i);
249 /* update dapm codec register bits */
250 static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
253 unsigned short old, new;
254 struct snd_soc_codec *codec = widget->codec;
256 /* check for valid widgets */
257 if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
258 widget->id == snd_soc_dapm_output ||
259 widget->id == snd_soc_dapm_hp ||
260 widget->id == snd_soc_dapm_mic ||
261 widget->id == snd_soc_dapm_line ||
262 widget->id == snd_soc_dapm_spk)
265 power = widget->power;
267 power = (power ? 0:1);
269 old = snd_soc_read(codec, widget->reg);
270 new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
274 pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n",
275 widget->name, widget->power ? "on" : "off",
277 snd_soc_write(codec, widget->reg, new);
278 pop_wait(codec->pop_time);
280 pr_debug("reg %x old %x new %x change %d\n", widget->reg,
285 /* ramps the volume up or down to minimise pops before or after a
286 * DAPM power event */
287 static int dapm_set_pga(struct snd_soc_dapm_widget *widget, int power)
289 const struct snd_kcontrol_new *k = widget->kcontrols;
291 if (widget->muted && !power)
293 if (!widget->muted && power)
296 if (widget->num_kcontrols && k) {
297 struct soc_mixer_control *mc =
298 (struct soc_mixer_control *)k->private_value;
299 unsigned int reg = mc->reg;
300 unsigned int shift = mc->shift;
302 unsigned int mask = (1 << fls(max)) - 1;
303 unsigned int invert = mc->invert;
307 /* power up has happended, increase volume to last level */
309 for (i = max; i > widget->saved_value; i--)
310 snd_soc_update_bits(widget->codec, reg, mask, i);
312 for (i = 0; i < widget->saved_value; i++)
313 snd_soc_update_bits(widget->codec, reg, mask, i);
317 /* power down is about to occur, decrease volume to mute */
318 int val = snd_soc_read(widget->codec, reg);
319 int i = widget->saved_value = (val >> shift) & mask;
321 for (; i < mask; i++)
322 snd_soc_update_bits(widget->codec, reg, mask, i);
325 snd_soc_update_bits(widget->codec, reg, mask, i);
333 /* create new dapm mixer control */
334 static int dapm_new_mixer(struct snd_soc_codec *codec,
335 struct snd_soc_dapm_widget *w)
339 struct snd_soc_dapm_path *path;
342 for (i = 0; i < w->num_kcontrols; i++) {
345 list_for_each_entry(path, &w->sources, list_sink) {
347 /* mixer/mux paths name must match control name */
348 if (path->name != (char*)w->kcontrols[i].name)
351 /* add dapm control with long name.
352 * for dapm_mixer this is the concatenation of the
353 * mixer and kcontrol name.
354 * for dapm_mixer_named_ctl this is simply the
357 name_len = strlen(w->kcontrols[i].name) + 1;
358 if (w->id != snd_soc_dapm_mixer_named_ctl)
359 name_len += 1 + strlen(w->name);
361 path->long_name = kmalloc(name_len, GFP_KERNEL);
363 if (path->long_name == NULL)
368 snprintf(path->long_name, name_len, "%s %s",
369 w->name, w->kcontrols[i].name);
371 case snd_soc_dapm_mixer_named_ctl:
372 snprintf(path->long_name, name_len, "%s",
373 w->kcontrols[i].name);
377 path->long_name[name_len - 1] = '\0';
379 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
381 ret = snd_ctl_add(codec->card, path->kcontrol);
383 printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n",
386 kfree(path->long_name);
387 path->long_name = NULL;
395 /* create new dapm mux control */
396 static int dapm_new_mux(struct snd_soc_codec *codec,
397 struct snd_soc_dapm_widget *w)
399 struct snd_soc_dapm_path *path = NULL;
400 struct snd_kcontrol *kcontrol;
403 if (!w->num_kcontrols) {
404 printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
408 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
409 ret = snd_ctl_add(codec->card, kcontrol);
413 list_for_each_entry(path, &w->sources, list_sink)
414 path->kcontrol = kcontrol;
419 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
423 /* create new dapm volume control */
424 static int dapm_new_pga(struct snd_soc_codec *codec,
425 struct snd_soc_dapm_widget *w)
427 struct snd_kcontrol *kcontrol;
430 if (!w->num_kcontrols)
433 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
434 ret = snd_ctl_add(codec->card, kcontrol);
436 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
443 /* reset 'walked' bit for each dapm path */
444 static inline void dapm_clear_walk(struct snd_soc_codec *codec)
446 struct snd_soc_dapm_path *p;
448 list_for_each_entry(p, &codec->dapm_paths, list)
453 * Recursively check for a completed path to an active or physically connected
454 * output widget. Returns number of complete paths.
456 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
458 struct snd_soc_dapm_path *path;
461 if (widget->id == snd_soc_dapm_supply)
464 if (widget->id == snd_soc_dapm_adc && widget->active)
467 if (widget->connected) {
468 /* connected pin ? */
469 if (widget->id == snd_soc_dapm_output && !widget->ext)
472 /* connected jack or spk ? */
473 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
474 widget->id == snd_soc_dapm_line)
478 list_for_each_entry(path, &widget->sinks, list_source) {
482 if (path->sink && path->connect) {
484 con += is_connected_output_ep(path->sink);
492 * Recursively check for a completed path to an active or physically connected
493 * input widget. Returns number of complete paths.
495 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
497 struct snd_soc_dapm_path *path;
500 if (widget->id == snd_soc_dapm_supply)
503 /* active stream ? */
504 if (widget->id == snd_soc_dapm_dac && widget->active)
507 if (widget->connected) {
508 /* connected pin ? */
509 if (widget->id == snd_soc_dapm_input && !widget->ext)
512 /* connected VMID/Bias for lower pops */
513 if (widget->id == snd_soc_dapm_vmid)
516 /* connected jack ? */
517 if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line)
521 list_for_each_entry(path, &widget->sources, list_sink) {
525 if (path->source && path->connect) {
527 con += is_connected_input_ep(path->source);
535 * Handler for generic register modifier widget.
537 int dapm_reg_event(struct snd_soc_dapm_widget *w,
538 struct snd_kcontrol *kcontrol, int event)
542 if (SND_SOC_DAPM_EVENT_ON(event))
547 snd_soc_update_bits(w->codec, -(w->reg + 1),
548 w->mask << w->shift, val << w->shift);
552 EXPORT_SYMBOL_GPL(dapm_reg_event);
554 /* Standard power change method, used to apply power changes to most
557 static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
561 /* call any power change event handlers */
563 pr_debug("power %s event for %s flags %x\n",
564 w->power ? "on" : "off",
565 w->name, w->event_flags);
567 /* power up pre event */
568 if (w->power && w->event &&
569 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
570 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
575 /* power down pre event */
576 if (!w->power && w->event &&
577 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
578 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
583 /* Lower PGA volume to reduce pops */
584 if (w->id == snd_soc_dapm_pga && !w->power)
585 dapm_set_pga(w, w->power);
589 /* Raise PGA volume to reduce pops */
590 if (w->id == snd_soc_dapm_pga && w->power)
591 dapm_set_pga(w, w->power);
593 /* power up post event */
594 if (w->power && w->event &&
595 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
597 NULL, SND_SOC_DAPM_POST_PMU);
602 /* power down post event */
603 if (!w->power && w->event &&
604 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
605 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
613 /* Generic check to see if a widget should be powered.
615 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
619 in = is_connected_input_ep(w);
620 dapm_clear_walk(w->codec);
621 out = is_connected_output_ep(w);
622 dapm_clear_walk(w->codec);
623 return out != 0 && in != 0;
626 /* Check to see if an ADC has power */
627 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
632 in = is_connected_input_ep(w);
633 dapm_clear_walk(w->codec);
636 return dapm_generic_check_power(w);
640 /* Check to see if a DAC has power */
641 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
646 out = is_connected_output_ep(w);
647 dapm_clear_walk(w->codec);
650 return dapm_generic_check_power(w);
654 /* Check to see if a power supply is needed */
655 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
657 struct snd_soc_dapm_path *path;
660 /* Check if one of our outputs is connected */
661 list_for_each_entry(path, &w->sinks, list_source) {
662 if (path->sink && path->sink->power_check &&
663 path->sink->power_check(path->sink)) {
669 dapm_clear_walk(w->codec);
675 * Scan a single DAPM widget for a complete audio path and update the
676 * power status appropriately.
678 static int dapm_power_widget(struct snd_soc_codec *codec, int event,
679 struct snd_soc_dapm_widget *w)
684 case snd_soc_dapm_pre:
688 if (event == SND_SOC_DAPM_STREAM_START) {
690 NULL, SND_SOC_DAPM_PRE_PMU);
693 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
695 NULL, SND_SOC_DAPM_PRE_PMD);
701 case snd_soc_dapm_post:
705 if (event == SND_SOC_DAPM_STREAM_START) {
707 NULL, SND_SOC_DAPM_POST_PMU);
710 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
712 NULL, SND_SOC_DAPM_POST_PMD);
719 return dapm_generic_apply_power(w);
724 * Scan each dapm widget for complete audio path.
725 * A complete path is a route that has valid endpoints i.e.:-
727 * o DAC to output pin.
728 * o Input Pin to ADC.
729 * o Input pin to Output pin (bypass, sidetone)
730 * o DAC to ADC (loopback).
732 static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
734 struct snd_soc_device *socdev = codec->socdev;
735 struct snd_soc_dapm_widget *w;
740 INIT_LIST_HEAD(&codec->up_list);
741 INIT_LIST_HEAD(&codec->down_list);
743 /* Check which widgets we need to power and store them in
744 * lists indicating if they should be powered up or down.
746 list_for_each_entry(w, &codec->dapm_widgets, list) {
748 case snd_soc_dapm_pre:
749 list_add_tail(&codec->down_list, &w->power_list);
751 case snd_soc_dapm_post:
752 list_add_tail(&codec->up_list, &w->power_list);
759 power = w->power_check(w);
763 if (w->power == power)
767 list_add_tail(&w->power_list, &codec->up_list);
769 list_add_tail(&w->power_list,
777 /* If we're changing to all on or all off then prepare */
778 if ((sys_power && codec->bias_level == SND_SOC_BIAS_STANDBY) ||
779 (!sys_power && codec->bias_level == SND_SOC_BIAS_ON)) {
780 ret = snd_soc_dapm_set_bias_level(socdev,
781 SND_SOC_BIAS_PREPARE);
783 pr_err("Failed to prepare bias: %d\n", ret);
786 /* Power down widgets first; try to avoid amplifying pops. */
787 for (i = 0; i < ARRAY_SIZE(dapm_down_seq); i++) {
788 list_for_each_entry(w, &codec->down_list, power_list) {
789 /* is widget in stream order */
790 if (w->id != dapm_down_seq[i])
793 ret = dapm_power_widget(codec, event, w);
795 pr_err("Failed to power down %s: %d\n",
801 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) {
802 list_for_each_entry(w, &codec->up_list, power_list) {
803 /* is widget in stream order */
804 if (w->id != dapm_up_seq[i])
807 ret = dapm_power_widget(codec, event, w);
809 pr_err("Failed to power up %s: %d\n",
814 /* If we just powered the last thing off drop to standby bias */
815 if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) {
816 ret = snd_soc_dapm_set_bias_level(socdev,
817 SND_SOC_BIAS_STANDBY);
819 pr_err("Failed to apply standby bias: %d\n", ret);
822 /* If we just powered up then move to active bias */
823 if (codec->bias_level == SND_SOC_BIAS_PREPARE && sys_power) {
824 ret = snd_soc_dapm_set_bias_level(socdev,
827 pr_err("Failed to apply active bias: %d\n", ret);
834 static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
836 struct snd_soc_dapm_widget *w;
837 struct snd_soc_dapm_path *p = NULL;
840 printk("DAPM %s %s\n", codec->name, action);
842 list_for_each_entry(w, &codec->dapm_widgets, list) {
844 /* only display widgets that effect routing */
846 case snd_soc_dapm_pre:
847 case snd_soc_dapm_post:
848 case snd_soc_dapm_vmid:
850 case snd_soc_dapm_mux:
851 case snd_soc_dapm_value_mux:
852 case snd_soc_dapm_output:
853 case snd_soc_dapm_input:
854 case snd_soc_dapm_switch:
855 case snd_soc_dapm_hp:
856 case snd_soc_dapm_mic:
857 case snd_soc_dapm_spk:
858 case snd_soc_dapm_line:
859 case snd_soc_dapm_micbias:
860 case snd_soc_dapm_dac:
861 case snd_soc_dapm_adc:
862 case snd_soc_dapm_pga:
863 case snd_soc_dapm_mixer:
864 case snd_soc_dapm_mixer_named_ctl:
865 case snd_soc_dapm_supply:
867 in = is_connected_input_ep(w);
868 dapm_clear_walk(w->codec);
869 out = is_connected_output_ep(w);
870 dapm_clear_walk(w->codec);
871 printk("%s: %s in %d out %d\n", w->name,
872 w->power ? "On":"Off",in, out);
874 list_for_each_entry(p, &w->sources, list_sink) {
876 printk(" in %s %s\n", p->name ? p->name : "static",
879 list_for_each_entry(p, &w->sinks, list_source) {
881 printk(" out %s %s\n", p->name ? p->name : "static",
891 /* test and update the power status of a mux widget */
892 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
893 struct snd_kcontrol *kcontrol, int mask,
894 int mux, int val, struct soc_enum *e)
896 struct snd_soc_dapm_path *path;
899 if (widget->id != snd_soc_dapm_mux &&
900 widget->id != snd_soc_dapm_value_mux)
903 if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
906 /* find dapm widget path assoc with kcontrol */
907 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
908 if (path->kcontrol != kcontrol)
911 if (!path->name || !e->texts[mux])
915 /* we now need to match the string in the enum to the path */
916 if (!(strcmp(path->name, e->texts[mux])))
917 path->connect = 1; /* new connection */
919 path->connect = 0; /* old connection must be powered down */
923 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
924 dump_dapm(widget->codec, "mux power update");
930 /* test and update the power status of a mixer or switch widget */
931 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
932 struct snd_kcontrol *kcontrol, int reg,
933 int val_mask, int val, int invert)
935 struct snd_soc_dapm_path *path;
938 if (widget->id != snd_soc_dapm_mixer &&
939 widget->id != snd_soc_dapm_mixer_named_ctl &&
940 widget->id != snd_soc_dapm_switch)
943 if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
946 /* find dapm widget path assoc with kcontrol */
947 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
948 if (path->kcontrol != kcontrol)
951 /* found, now check type */
955 path->connect = invert ? 0:1;
957 /* old connection must be powered down */
958 path->connect = invert ? 1:0;
963 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
964 dump_dapm(widget->codec, "mixer power update");
970 /* show dapm widget status in sys fs */
971 static ssize_t dapm_widget_show(struct device *dev,
972 struct device_attribute *attr, char *buf)
974 struct snd_soc_device *devdata = dev_get_drvdata(dev);
975 struct snd_soc_codec *codec = devdata->card->codec;
976 struct snd_soc_dapm_widget *w;
978 char *state = "not set";
980 list_for_each_entry(w, &codec->dapm_widgets, list) {
982 /* only display widgets that burnm power */
984 case snd_soc_dapm_hp:
985 case snd_soc_dapm_mic:
986 case snd_soc_dapm_spk:
987 case snd_soc_dapm_line:
988 case snd_soc_dapm_micbias:
989 case snd_soc_dapm_dac:
990 case snd_soc_dapm_adc:
991 case snd_soc_dapm_pga:
992 case snd_soc_dapm_mixer:
993 case snd_soc_dapm_mixer_named_ctl:
994 case snd_soc_dapm_supply:
996 count += sprintf(buf + count, "%s: %s\n",
997 w->name, w->power ? "On":"Off");
1004 switch (codec->bias_level) {
1005 case SND_SOC_BIAS_ON:
1008 case SND_SOC_BIAS_PREPARE:
1011 case SND_SOC_BIAS_STANDBY:
1014 case SND_SOC_BIAS_OFF:
1018 count += sprintf(buf + count, "PM State: %s\n", state);
1023 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1025 int snd_soc_dapm_sys_add(struct device *dev)
1027 return device_create_file(dev, &dev_attr_dapm_widget);
1030 static void snd_soc_dapm_sys_remove(struct device *dev)
1032 device_remove_file(dev, &dev_attr_dapm_widget);
1035 /* free all dapm widgets and resources */
1036 static void dapm_free_widgets(struct snd_soc_codec *codec)
1038 struct snd_soc_dapm_widget *w, *next_w;
1039 struct snd_soc_dapm_path *p, *next_p;
1041 list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) {
1046 list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) {
1048 kfree(p->long_name);
1053 static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
1054 const char *pin, int status)
1056 struct snd_soc_dapm_widget *w;
1058 list_for_each_entry(w, &codec->dapm_widgets, list) {
1059 if (!strcmp(w->name, pin)) {
1060 pr_debug("dapm: %s: pin %s\n", codec->name, pin);
1061 w->connected = status;
1066 pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
1071 * snd_soc_dapm_sync - scan and power dapm paths
1072 * @codec: audio codec
1074 * Walks all dapm audio paths and powers widgets according to their
1075 * stream or path usage.
1077 * Returns 0 for success.
1079 int snd_soc_dapm_sync(struct snd_soc_codec *codec)
1081 int ret = dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
1082 dump_dapm(codec, "sync");
1085 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1087 static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1088 const char *sink, const char *control, const char *source)
1090 struct snd_soc_dapm_path *path;
1091 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1094 /* find src and dest widgets */
1095 list_for_each_entry(w, &codec->dapm_widgets, list) {
1097 if (!wsink && !(strcmp(w->name, sink))) {
1101 if (!wsource && !(strcmp(w->name, source))) {
1106 if (wsource == NULL || wsink == NULL)
1109 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1113 path->source = wsource;
1115 INIT_LIST_HEAD(&path->list);
1116 INIT_LIST_HEAD(&path->list_source);
1117 INIT_LIST_HEAD(&path->list_sink);
1119 /* check for external widgets */
1120 if (wsink->id == snd_soc_dapm_input) {
1121 if (wsource->id == snd_soc_dapm_micbias ||
1122 wsource->id == snd_soc_dapm_mic ||
1123 wsink->id == snd_soc_dapm_line ||
1124 wsink->id == snd_soc_dapm_output)
1127 if (wsource->id == snd_soc_dapm_output) {
1128 if (wsink->id == snd_soc_dapm_spk ||
1129 wsink->id == snd_soc_dapm_hp ||
1130 wsink->id == snd_soc_dapm_line ||
1131 wsink->id == snd_soc_dapm_input)
1135 /* connect static paths */
1136 if (control == NULL) {
1137 list_add(&path->list, &codec->dapm_paths);
1138 list_add(&path->list_sink, &wsink->sources);
1139 list_add(&path->list_source, &wsource->sinks);
1144 /* connect dynamic paths */
1146 case snd_soc_dapm_adc:
1147 case snd_soc_dapm_dac:
1148 case snd_soc_dapm_pga:
1149 case snd_soc_dapm_input:
1150 case snd_soc_dapm_output:
1151 case snd_soc_dapm_micbias:
1152 case snd_soc_dapm_vmid:
1153 case snd_soc_dapm_pre:
1154 case snd_soc_dapm_post:
1155 case snd_soc_dapm_supply:
1156 list_add(&path->list, &codec->dapm_paths);
1157 list_add(&path->list_sink, &wsink->sources);
1158 list_add(&path->list_source, &wsource->sinks);
1161 case snd_soc_dapm_mux:
1162 case snd_soc_dapm_value_mux:
1163 ret = dapm_connect_mux(codec, wsource, wsink, path, control,
1164 &wsink->kcontrols[0]);
1168 case snd_soc_dapm_switch:
1169 case snd_soc_dapm_mixer:
1170 case snd_soc_dapm_mixer_named_ctl:
1171 ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
1175 case snd_soc_dapm_hp:
1176 case snd_soc_dapm_mic:
1177 case snd_soc_dapm_line:
1178 case snd_soc_dapm_spk:
1179 list_add(&path->list, &codec->dapm_paths);
1180 list_add(&path->list_sink, &wsink->sources);
1181 list_add(&path->list_source, &wsource->sinks);
1188 printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
1195 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1197 * @route: audio routes
1198 * @num: number of routes
1200 * Connects 2 dapm widgets together via a named audio path. The sink is
1201 * the widget receiving the audio signal, whilst the source is the sender
1202 * of the audio signal.
1204 * Returns 0 for success else error. On error all resources can be freed
1205 * with a call to snd_soc_card_free().
1207 int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
1208 const struct snd_soc_dapm_route *route, int num)
1212 for (i = 0; i < num; i++) {
1213 ret = snd_soc_dapm_add_route(codec, route->sink,
1214 route->control, route->source);
1216 printk(KERN_ERR "Failed to add route %s->%s\n",
1226 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1229 * snd_soc_dapm_new_widgets - add new dapm widgets
1230 * @codec: audio codec
1232 * Checks the codec for any new dapm widgets and creates them if found.
1234 * Returns 0 for success.
1236 int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1238 struct snd_soc_dapm_widget *w;
1240 list_for_each_entry(w, &codec->dapm_widgets, list)
1246 case snd_soc_dapm_switch:
1247 case snd_soc_dapm_mixer:
1248 case snd_soc_dapm_mixer_named_ctl:
1249 w->power_check = dapm_generic_check_power;
1250 dapm_new_mixer(codec, w);
1252 case snd_soc_dapm_mux:
1253 case snd_soc_dapm_value_mux:
1254 w->power_check = dapm_generic_check_power;
1255 dapm_new_mux(codec, w);
1257 case snd_soc_dapm_adc:
1258 w->power_check = dapm_adc_check_power;
1260 case snd_soc_dapm_dac:
1261 w->power_check = dapm_dac_check_power;
1263 case snd_soc_dapm_pga:
1264 w->power_check = dapm_generic_check_power;
1265 dapm_new_pga(codec, w);
1267 case snd_soc_dapm_input:
1268 case snd_soc_dapm_output:
1269 case snd_soc_dapm_micbias:
1270 case snd_soc_dapm_spk:
1271 case snd_soc_dapm_hp:
1272 case snd_soc_dapm_mic:
1273 case snd_soc_dapm_line:
1274 w->power_check = dapm_generic_check_power;
1276 case snd_soc_dapm_supply:
1277 w->power_check = dapm_supply_check_power;
1278 case snd_soc_dapm_vmid:
1279 case snd_soc_dapm_pre:
1280 case snd_soc_dapm_post:
1286 dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
1289 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
1292 * snd_soc_dapm_get_volsw - dapm mixer get callback
1293 * @kcontrol: mixer control
1294 * @ucontrol: control element information
1296 * Callback to get the value of a dapm mixer control.
1298 * Returns 0 for success.
1300 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
1301 struct snd_ctl_elem_value *ucontrol)
1303 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1304 struct soc_mixer_control *mc =
1305 (struct soc_mixer_control *)kcontrol->private_value;
1306 unsigned int reg = mc->reg;
1307 unsigned int shift = mc->shift;
1308 unsigned int rshift = mc->rshift;
1310 unsigned int invert = mc->invert;
1311 unsigned int mask = (1 << fls(max)) - 1;
1313 /* return the saved value if we are powered down */
1314 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1315 ucontrol->value.integer.value[0] = widget->saved_value;
1319 ucontrol->value.integer.value[0] =
1320 (snd_soc_read(widget->codec, reg) >> shift) & mask;
1321 if (shift != rshift)
1322 ucontrol->value.integer.value[1] =
1323 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
1325 ucontrol->value.integer.value[0] =
1326 max - ucontrol->value.integer.value[0];
1327 if (shift != rshift)
1328 ucontrol->value.integer.value[1] =
1329 max - ucontrol->value.integer.value[1];
1334 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
1337 * snd_soc_dapm_put_volsw - dapm mixer set callback
1338 * @kcontrol: mixer control
1339 * @ucontrol: control element information
1341 * Callback to set the value of a dapm mixer control.
1343 * Returns 0 for success.
1345 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1346 struct snd_ctl_elem_value *ucontrol)
1348 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1349 struct soc_mixer_control *mc =
1350 (struct soc_mixer_control *)kcontrol->private_value;
1351 unsigned int reg = mc->reg;
1352 unsigned int shift = mc->shift;
1353 unsigned int rshift = mc->rshift;
1355 unsigned int mask = (1 << fls(max)) - 1;
1356 unsigned int invert = mc->invert;
1357 unsigned short val, val2, val_mask;
1360 val = (ucontrol->value.integer.value[0] & mask);
1364 val_mask = mask << shift;
1366 if (shift != rshift) {
1367 val2 = (ucontrol->value.integer.value[1] & mask);
1370 val_mask |= mask << rshift;
1371 val |= val2 << rshift;
1374 mutex_lock(&widget->codec->mutex);
1375 widget->value = val;
1377 /* save volume value if the widget is powered down */
1378 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1379 widget->saved_value = val;
1380 mutex_unlock(&widget->codec->mutex);
1384 dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
1385 if (widget->event) {
1386 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1387 ret = widget->event(widget, kcontrol,
1388 SND_SOC_DAPM_PRE_REG);
1394 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1395 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1396 ret = widget->event(widget, kcontrol,
1397 SND_SOC_DAPM_POST_REG);
1399 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1402 mutex_unlock(&widget->codec->mutex);
1405 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1408 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1409 * @kcontrol: mixer control
1410 * @ucontrol: control element information
1412 * Callback to get the value of a dapm enumerated double mixer control.
1414 * Returns 0 for success.
1416 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
1417 struct snd_ctl_elem_value *ucontrol)
1419 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1420 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1421 unsigned short val, bitmask;
1423 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1425 val = snd_soc_read(widget->codec, e->reg);
1426 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1427 if (e->shift_l != e->shift_r)
1428 ucontrol->value.enumerated.item[1] =
1429 (val >> e->shift_r) & (bitmask - 1);
1433 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
1436 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1437 * @kcontrol: mixer control
1438 * @ucontrol: control element information
1440 * Callback to set the value of a dapm enumerated double mixer control.
1442 * Returns 0 for success.
1444 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1445 struct snd_ctl_elem_value *ucontrol)
1447 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1448 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1449 unsigned short val, mux;
1450 unsigned short mask, bitmask;
1453 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1455 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1457 mux = ucontrol->value.enumerated.item[0];
1458 val = mux << e->shift_l;
1459 mask = (bitmask - 1) << e->shift_l;
1460 if (e->shift_l != e->shift_r) {
1461 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1463 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1464 mask |= (bitmask - 1) << e->shift_r;
1467 mutex_lock(&widget->codec->mutex);
1468 widget->value = val;
1469 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
1470 if (widget->event) {
1471 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1472 ret = widget->event(widget,
1473 kcontrol, SND_SOC_DAPM_PRE_REG);
1477 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1478 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1479 ret = widget->event(widget,
1480 kcontrol, SND_SOC_DAPM_POST_REG);
1482 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1485 mutex_unlock(&widget->codec->mutex);
1488 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1491 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1493 * @kcontrol: mixer control
1494 * @ucontrol: control element information
1496 * Callback to get the value of a dapm semi enumerated double mixer control.
1498 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1499 * used for handling bitfield coded enumeration for example.
1501 * Returns 0 for success.
1503 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
1504 struct snd_ctl_elem_value *ucontrol)
1506 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1507 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1508 unsigned short reg_val, val, mux;
1510 reg_val = snd_soc_read(widget->codec, e->reg);
1511 val = (reg_val >> e->shift_l) & e->mask;
1512 for (mux = 0; mux < e->max; mux++) {
1513 if (val == e->values[mux])
1516 ucontrol->value.enumerated.item[0] = mux;
1517 if (e->shift_l != e->shift_r) {
1518 val = (reg_val >> e->shift_r) & e->mask;
1519 for (mux = 0; mux < e->max; mux++) {
1520 if (val == e->values[mux])
1523 ucontrol->value.enumerated.item[1] = mux;
1528 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
1531 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1533 * @kcontrol: mixer control
1534 * @ucontrol: control element information
1536 * Callback to set the value of a dapm semi enumerated double mixer control.
1538 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1539 * used for handling bitfield coded enumeration for example.
1541 * Returns 0 for success.
1543 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1544 struct snd_ctl_elem_value *ucontrol)
1546 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1547 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1548 unsigned short val, mux;
1549 unsigned short mask;
1552 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1554 mux = ucontrol->value.enumerated.item[0];
1555 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1556 mask = e->mask << e->shift_l;
1557 if (e->shift_l != e->shift_r) {
1558 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1560 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1561 mask |= e->mask << e->shift_r;
1564 mutex_lock(&widget->codec->mutex);
1565 widget->value = val;
1566 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
1567 if (widget->event) {
1568 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1569 ret = widget->event(widget,
1570 kcontrol, SND_SOC_DAPM_PRE_REG);
1574 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1575 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1576 ret = widget->event(widget,
1577 kcontrol, SND_SOC_DAPM_POST_REG);
1579 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1582 mutex_unlock(&widget->codec->mutex);
1585 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1588 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1590 * @kcontrol: mixer control
1591 * @uinfo: control element information
1593 * Callback to provide information about a pin switch control.
1595 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
1596 struct snd_ctl_elem_info *uinfo)
1598 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1600 uinfo->value.integer.min = 0;
1601 uinfo->value.integer.max = 1;
1605 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
1608 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1610 * @kcontrol: mixer control
1613 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
1614 struct snd_ctl_elem_value *ucontrol)
1616 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1617 const char *pin = (const char *)kcontrol->private_value;
1619 mutex_lock(&codec->mutex);
1621 ucontrol->value.integer.value[0] =
1622 snd_soc_dapm_get_pin_status(codec, pin);
1624 mutex_unlock(&codec->mutex);
1628 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
1631 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1633 * @kcontrol: mixer control
1636 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1639 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1640 const char *pin = (const char *)kcontrol->private_value;
1642 mutex_lock(&codec->mutex);
1644 if (ucontrol->value.integer.value[0])
1645 snd_soc_dapm_enable_pin(codec, pin);
1647 snd_soc_dapm_disable_pin(codec, pin);
1649 snd_soc_dapm_sync(codec);
1651 mutex_unlock(&codec->mutex);
1655 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
1658 * snd_soc_dapm_new_control - create new dapm control
1659 * @codec: audio codec
1660 * @widget: widget template
1662 * Creates a new dapm control based upon the template.
1664 * Returns 0 for success else error.
1666 int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
1667 const struct snd_soc_dapm_widget *widget)
1669 struct snd_soc_dapm_widget *w;
1671 if ((w = dapm_cnew_widget(widget)) == NULL)
1675 INIT_LIST_HEAD(&w->sources);
1676 INIT_LIST_HEAD(&w->sinks);
1677 INIT_LIST_HEAD(&w->list);
1678 list_add(&w->list, &codec->dapm_widgets);
1680 /* machine layer set ups unconnected pins and insertions */
1684 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1687 * snd_soc_dapm_new_controls - create new dapm controls
1688 * @codec: audio codec
1689 * @widget: widget array
1690 * @num: number of widgets
1692 * Creates new DAPM controls based upon the templates.
1694 * Returns 0 for success else error.
1696 int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
1697 const struct snd_soc_dapm_widget *widget,
1702 for (i = 0; i < num; i++) {
1703 ret = snd_soc_dapm_new_control(codec, widget);
1706 "ASoC: Failed to create DAPM control %s: %d\n",
1714 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1718 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1719 * @codec: audio codec
1720 * @stream: stream name
1721 * @event: stream event
1723 * Sends a stream event to the dapm core. The core then makes any
1724 * necessary widget power changes.
1726 * Returns 0 for success else error.
1728 int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1729 char *stream, int event)
1731 struct snd_soc_dapm_widget *w;
1736 mutex_lock(&codec->mutex);
1737 list_for_each_entry(w, &codec->dapm_widgets, list)
1741 pr_debug("widget %s\n %s stream %s event %d\n",
1742 w->name, w->sname, stream, event);
1743 if (strstr(w->sname, stream)) {
1745 case SND_SOC_DAPM_STREAM_START:
1748 case SND_SOC_DAPM_STREAM_STOP:
1751 case SND_SOC_DAPM_STREAM_SUSPEND:
1756 case SND_SOC_DAPM_STREAM_RESUME:
1762 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
1764 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
1769 mutex_unlock(&codec->mutex);
1771 dapm_power_widgets(codec, event);
1772 dump_dapm(codec, __func__);
1775 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
1778 * snd_soc_dapm_enable_pin - enable pin.
1782 * Enables input/output pin and it's parents or children widgets iff there is
1783 * a valid audio route and active audio stream.
1784 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1785 * do any widget power switching.
1787 int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
1789 return snd_soc_dapm_set_pin(codec, pin, 1);
1791 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
1794 * snd_soc_dapm_disable_pin - disable pin.
1798 * Disables input/output pin and it's parents or children widgets.
1799 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1800 * do any widget power switching.
1802 int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin)
1804 return snd_soc_dapm_set_pin(codec, pin, 0);
1806 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
1809 * snd_soc_dapm_nc_pin - permanently disable pin.
1813 * Marks the specified pin as being not connected, disabling it along
1814 * any parent or child widgets. At present this is identical to
1815 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1816 * additional things such as disabling controls which only affect
1817 * paths through the pin.
1819 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1820 * do any widget power switching.
1822 int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin)
1824 return snd_soc_dapm_set_pin(codec, pin, 0);
1826 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
1829 * snd_soc_dapm_get_pin_status - get audio pin status
1830 * @codec: audio codec
1831 * @pin: audio signal pin endpoint (or start point)
1833 * Get audio pin status - connected or disconnected.
1835 * Returns 1 for connected otherwise 0.
1837 int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin)
1839 struct snd_soc_dapm_widget *w;
1841 list_for_each_entry(w, &codec->dapm_widgets, list) {
1842 if (!strcmp(w->name, pin))
1843 return w->connected;
1848 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
1851 * snd_soc_dapm_free - free dapm resources
1852 * @socdev: SoC device
1854 * Free all dapm widgets and resources.
1856 void snd_soc_dapm_free(struct snd_soc_device *socdev)
1858 struct snd_soc_codec *codec = socdev->card->codec;
1860 snd_soc_dapm_sys_remove(socdev->dev);
1861 dapm_free_widgets(codec);
1863 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
1865 /* Module information */
1866 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1867 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1868 MODULE_LICENSE("GPL");