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 int dapm_status = 1;
71 module_param(dapm_status, int, 0);
72 MODULE_PARM_DESC(dapm_status, "enable DPM sysfs entries");
74 static void pop_wait(u32 pop_time)
77 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
80 static void pop_dbg(u32 pop_time, const char *fmt, ...)
94 /* create a new dapm widget */
95 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
96 const struct snd_soc_dapm_widget *_widget)
98 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
101 /* set up initial codec paths */
102 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
103 struct snd_soc_dapm_path *p, int i)
106 case snd_soc_dapm_switch:
107 case snd_soc_dapm_mixer:
108 case snd_soc_dapm_mixer_named_ctl: {
110 struct soc_mixer_control *mc = (struct soc_mixer_control *)
111 w->kcontrols[i].private_value;
112 unsigned int reg = mc->reg;
113 unsigned int shift = mc->shift;
115 unsigned int mask = (1 << fls(max)) - 1;
116 unsigned int invert = mc->invert;
118 val = snd_soc_read(w->codec, reg);
119 val = (val >> shift) & mask;
121 if ((invert && !val) || (!invert && val))
127 case snd_soc_dapm_mux: {
128 struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
129 int val, item, bitmask;
131 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
133 val = snd_soc_read(w->codec, e->reg);
134 item = (val >> e->shift_l) & (bitmask - 1);
137 for (i = 0; i < e->max; i++) {
138 if (!(strcmp(p->name, e->texts[i])) && item == i)
143 case snd_soc_dapm_value_mux: {
144 struct soc_enum *e = (struct soc_enum *)
145 w->kcontrols[i].private_value;
148 val = snd_soc_read(w->codec, e->reg);
149 val = (val >> e->shift_l) & e->mask;
150 for (item = 0; item < e->max; item++) {
151 if (val == e->values[item])
156 for (i = 0; i < e->max; i++) {
157 if (!(strcmp(p->name, e->texts[i])) && item == i)
162 /* does not effect routing - always connected */
163 case snd_soc_dapm_pga:
164 case snd_soc_dapm_output:
165 case snd_soc_dapm_adc:
166 case snd_soc_dapm_input:
167 case snd_soc_dapm_dac:
168 case snd_soc_dapm_micbias:
169 case snd_soc_dapm_vmid:
170 case snd_soc_dapm_supply:
173 /* does effect routing - dynamically connected */
174 case snd_soc_dapm_hp:
175 case snd_soc_dapm_mic:
176 case snd_soc_dapm_spk:
177 case snd_soc_dapm_line:
178 case snd_soc_dapm_pre:
179 case snd_soc_dapm_post:
185 /* connect mux widget to it's interconnecting audio paths */
186 static int dapm_connect_mux(struct snd_soc_codec *codec,
187 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
188 struct snd_soc_dapm_path *path, const char *control_name,
189 const struct snd_kcontrol_new *kcontrol)
191 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
194 for (i = 0; i < e->max; i++) {
195 if (!(strcmp(control_name, e->texts[i]))) {
196 list_add(&path->list, &codec->dapm_paths);
197 list_add(&path->list_sink, &dest->sources);
198 list_add(&path->list_source, &src->sinks);
199 path->name = (char*)e->texts[i];
200 dapm_set_path_status(dest, path, 0);
208 /* connect mixer widget to it's interconnecting audio paths */
209 static int dapm_connect_mixer(struct snd_soc_codec *codec,
210 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
211 struct snd_soc_dapm_path *path, const char *control_name)
215 /* search for mixer kcontrol */
216 for (i = 0; i < dest->num_kcontrols; i++) {
217 if (!strcmp(control_name, dest->kcontrols[i].name)) {
218 list_add(&path->list, &codec->dapm_paths);
219 list_add(&path->list_sink, &dest->sources);
220 list_add(&path->list_source, &src->sinks);
221 path->name = dest->kcontrols[i].name;
222 dapm_set_path_status(dest, path, i);
229 /* update dapm codec register bits */
230 static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
233 unsigned short old, new;
234 struct snd_soc_codec *codec = widget->codec;
236 /* check for valid widgets */
237 if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
238 widget->id == snd_soc_dapm_output ||
239 widget->id == snd_soc_dapm_hp ||
240 widget->id == snd_soc_dapm_mic ||
241 widget->id == snd_soc_dapm_line ||
242 widget->id == snd_soc_dapm_spk)
245 power = widget->power;
247 power = (power ? 0:1);
249 old = snd_soc_read(codec, widget->reg);
250 new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
254 pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n",
255 widget->name, widget->power ? "on" : "off",
257 snd_soc_write(codec, widget->reg, new);
258 pop_wait(codec->pop_time);
260 pr_debug("reg %x old %x new %x change %d\n", widget->reg,
265 /* ramps the volume up or down to minimise pops before or after a
266 * DAPM power event */
267 static int dapm_set_pga(struct snd_soc_dapm_widget *widget, int power)
269 const struct snd_kcontrol_new *k = widget->kcontrols;
271 if (widget->muted && !power)
273 if (!widget->muted && power)
276 if (widget->num_kcontrols && k) {
277 struct soc_mixer_control *mc =
278 (struct soc_mixer_control *)k->private_value;
279 unsigned int reg = mc->reg;
280 unsigned int shift = mc->shift;
282 unsigned int mask = (1 << fls(max)) - 1;
283 unsigned int invert = mc->invert;
287 /* power up has happended, increase volume to last level */
289 for (i = max; i > widget->saved_value; i--)
290 snd_soc_update_bits(widget->codec, reg, mask, i);
292 for (i = 0; i < widget->saved_value; i++)
293 snd_soc_update_bits(widget->codec, reg, mask, i);
297 /* power down is about to occur, decrease volume to mute */
298 int val = snd_soc_read(widget->codec, reg);
299 int i = widget->saved_value = (val >> shift) & mask;
301 for (; i < mask; i++)
302 snd_soc_update_bits(widget->codec, reg, mask, i);
305 snd_soc_update_bits(widget->codec, reg, mask, i);
313 /* create new dapm mixer control */
314 static int dapm_new_mixer(struct snd_soc_codec *codec,
315 struct snd_soc_dapm_widget *w)
319 struct snd_soc_dapm_path *path;
322 for (i = 0; i < w->num_kcontrols; i++) {
325 list_for_each_entry(path, &w->sources, list_sink) {
327 /* mixer/mux paths name must match control name */
328 if (path->name != (char*)w->kcontrols[i].name)
331 /* add dapm control with long name.
332 * for dapm_mixer this is the concatenation of the
333 * mixer and kcontrol name.
334 * for dapm_mixer_named_ctl this is simply the
337 name_len = strlen(w->kcontrols[i].name) + 1;
338 if (w->id != snd_soc_dapm_mixer_named_ctl)
339 name_len += 1 + strlen(w->name);
341 path->long_name = kmalloc(name_len, GFP_KERNEL);
343 if (path->long_name == NULL)
348 snprintf(path->long_name, name_len, "%s %s",
349 w->name, w->kcontrols[i].name);
351 case snd_soc_dapm_mixer_named_ctl:
352 snprintf(path->long_name, name_len, "%s",
353 w->kcontrols[i].name);
357 path->long_name[name_len - 1] = '\0';
359 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
361 ret = snd_ctl_add(codec->card, path->kcontrol);
363 printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n",
366 kfree(path->long_name);
367 path->long_name = NULL;
375 /* create new dapm mux control */
376 static int dapm_new_mux(struct snd_soc_codec *codec,
377 struct snd_soc_dapm_widget *w)
379 struct snd_soc_dapm_path *path = NULL;
380 struct snd_kcontrol *kcontrol;
383 if (!w->num_kcontrols) {
384 printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
388 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
389 ret = snd_ctl_add(codec->card, kcontrol);
393 list_for_each_entry(path, &w->sources, list_sink)
394 path->kcontrol = kcontrol;
399 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
403 /* create new dapm volume control */
404 static int dapm_new_pga(struct snd_soc_codec *codec,
405 struct snd_soc_dapm_widget *w)
407 struct snd_kcontrol *kcontrol;
410 if (!w->num_kcontrols)
413 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
414 ret = snd_ctl_add(codec->card, kcontrol);
416 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
423 /* reset 'walked' bit for each dapm path */
424 static inline void dapm_clear_walk(struct snd_soc_codec *codec)
426 struct snd_soc_dapm_path *p;
428 list_for_each_entry(p, &codec->dapm_paths, list)
433 * Recursively check for a completed path to an active or physically connected
434 * output widget. Returns number of complete paths.
436 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
438 struct snd_soc_dapm_path *path;
441 if (widget->id == snd_soc_dapm_supply)
444 if (widget->id == snd_soc_dapm_adc && widget->active)
447 if (widget->connected) {
448 /* connected pin ? */
449 if (widget->id == snd_soc_dapm_output && !widget->ext)
452 /* connected jack or spk ? */
453 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
454 widget->id == snd_soc_dapm_line)
458 list_for_each_entry(path, &widget->sinks, list_source) {
462 if (path->sink && path->connect) {
464 con += is_connected_output_ep(path->sink);
472 * Recursively check for a completed path to an active or physically connected
473 * input widget. Returns number of complete paths.
475 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
477 struct snd_soc_dapm_path *path;
480 if (widget->id == snd_soc_dapm_supply)
483 /* active stream ? */
484 if (widget->id == snd_soc_dapm_dac && widget->active)
487 if (widget->connected) {
488 /* connected pin ? */
489 if (widget->id == snd_soc_dapm_input && !widget->ext)
492 /* connected VMID/Bias for lower pops */
493 if (widget->id == snd_soc_dapm_vmid)
496 /* connected jack ? */
497 if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line)
501 list_for_each_entry(path, &widget->sources, list_sink) {
505 if (path->source && path->connect) {
507 con += is_connected_input_ep(path->source);
515 * Handler for generic register modifier widget.
517 int dapm_reg_event(struct snd_soc_dapm_widget *w,
518 struct snd_kcontrol *kcontrol, int event)
522 if (SND_SOC_DAPM_EVENT_ON(event))
527 snd_soc_update_bits(w->codec, -(w->reg + 1),
528 w->mask << w->shift, val << w->shift);
532 EXPORT_SYMBOL_GPL(dapm_reg_event);
534 /* Standard power change method, used to apply power changes to most
537 static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
541 /* call any power change event handlers */
543 pr_debug("power %s event for %s flags %x\n",
544 w->power ? "on" : "off",
545 w->name, w->event_flags);
547 /* power up pre event */
548 if (w->power && w->event &&
549 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
550 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
555 /* power down pre event */
556 if (!w->power && w->event &&
557 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
558 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
563 /* Lower PGA volume to reduce pops */
564 if (w->id == snd_soc_dapm_pga && !w->power)
565 dapm_set_pga(w, w->power);
569 /* Raise PGA volume to reduce pops */
570 if (w->id == snd_soc_dapm_pga && w->power)
571 dapm_set_pga(w, w->power);
573 /* power up post event */
574 if (w->power && w->event &&
575 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
577 NULL, SND_SOC_DAPM_POST_PMU);
582 /* power down post event */
583 if (!w->power && w->event &&
584 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
585 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
593 /* Generic check to see if a widget should be powered.
595 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
599 in = is_connected_input_ep(w);
600 dapm_clear_walk(w->codec);
601 out = is_connected_output_ep(w);
602 dapm_clear_walk(w->codec);
603 return out != 0 && in != 0;
606 /* Check to see if an ADC has power */
607 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
612 in = is_connected_input_ep(w);
613 dapm_clear_walk(w->codec);
616 return dapm_generic_check_power(w);
620 /* Check to see if a DAC has power */
621 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
626 out = is_connected_output_ep(w);
627 dapm_clear_walk(w->codec);
630 return dapm_generic_check_power(w);
634 /* Check to see if a power supply is needed */
635 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
637 struct snd_soc_dapm_path *path;
640 /* Check if one of our outputs is connected */
641 list_for_each_entry(path, &w->sinks, list_source) {
642 if (path->sink && path->sink->power_check &&
643 path->sink->power_check(path->sink)) {
649 dapm_clear_walk(w->codec);
655 * Scan a single DAPM widget for a complete audio path and update the
656 * power status appropriately.
658 static int dapm_power_widget(struct snd_soc_codec *codec, int event,
659 struct snd_soc_dapm_widget *w)
664 case snd_soc_dapm_pre:
668 if (event == SND_SOC_DAPM_STREAM_START) {
670 NULL, SND_SOC_DAPM_PRE_PMU);
673 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
675 NULL, SND_SOC_DAPM_PRE_PMD);
681 case snd_soc_dapm_post:
685 if (event == SND_SOC_DAPM_STREAM_START) {
687 NULL, SND_SOC_DAPM_POST_PMU);
690 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
692 NULL, SND_SOC_DAPM_POST_PMD);
705 power = w->power_check(w);
706 if (w->power == power)
710 return dapm_generic_apply_power(w);
714 * Scan each dapm widget for complete audio path.
715 * A complete path is a route that has valid endpoints i.e.:-
717 * o DAC to output pin.
718 * o Input Pin to ADC.
719 * o Input pin to Output pin (bypass, sidetone)
720 * o DAC to ADC (loopback).
722 static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
724 struct snd_soc_dapm_widget *w;
725 int i, c = 1, *seq = NULL, ret = 0;
727 /* do we have a sequenced stream event */
728 if (event == SND_SOC_DAPM_STREAM_START) {
729 c = ARRAY_SIZE(dapm_up_seq);
731 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
732 c = ARRAY_SIZE(dapm_down_seq);
736 for (i = 0; i < c; i++) {
737 list_for_each_entry(w, &codec->dapm_widgets, list) {
739 /* is widget in stream order */
740 if (seq && seq[i] && w->id != seq[i])
743 ret = dapm_power_widget(codec, event, w);
753 static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
755 struct snd_soc_dapm_widget *w;
756 struct snd_soc_dapm_path *p = NULL;
759 printk("DAPM %s %s\n", codec->name, action);
761 list_for_each_entry(w, &codec->dapm_widgets, list) {
763 /* only display widgets that effect routing */
765 case snd_soc_dapm_pre:
766 case snd_soc_dapm_post:
767 case snd_soc_dapm_vmid:
769 case snd_soc_dapm_mux:
770 case snd_soc_dapm_value_mux:
771 case snd_soc_dapm_output:
772 case snd_soc_dapm_input:
773 case snd_soc_dapm_switch:
774 case snd_soc_dapm_hp:
775 case snd_soc_dapm_mic:
776 case snd_soc_dapm_spk:
777 case snd_soc_dapm_line:
778 case snd_soc_dapm_micbias:
779 case snd_soc_dapm_dac:
780 case snd_soc_dapm_adc:
781 case snd_soc_dapm_pga:
782 case snd_soc_dapm_mixer:
783 case snd_soc_dapm_mixer_named_ctl:
784 case snd_soc_dapm_supply:
786 in = is_connected_input_ep(w);
787 dapm_clear_walk(w->codec);
788 out = is_connected_output_ep(w);
789 dapm_clear_walk(w->codec);
790 printk("%s: %s in %d out %d\n", w->name,
791 w->power ? "On":"Off",in, out);
793 list_for_each_entry(p, &w->sources, list_sink) {
795 printk(" in %s %s\n", p->name ? p->name : "static",
798 list_for_each_entry(p, &w->sinks, list_source) {
800 printk(" out %s %s\n", p->name ? p->name : "static",
810 /* test and update the power status of a mux widget */
811 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
812 struct snd_kcontrol *kcontrol, int mask,
813 int mux, int val, struct soc_enum *e)
815 struct snd_soc_dapm_path *path;
818 if (widget->id != snd_soc_dapm_mux &&
819 widget->id != snd_soc_dapm_value_mux)
822 if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
825 /* find dapm widget path assoc with kcontrol */
826 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
827 if (path->kcontrol != kcontrol)
830 if (!path->name || !e->texts[mux])
834 /* we now need to match the string in the enum to the path */
835 if (!(strcmp(path->name, e->texts[mux])))
836 path->connect = 1; /* new connection */
838 path->connect = 0; /* old connection must be powered down */
842 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
843 dump_dapm(widget->codec, "mux power update");
849 /* test and update the power status of a mixer or switch widget */
850 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
851 struct snd_kcontrol *kcontrol, int reg,
852 int val_mask, int val, int invert)
854 struct snd_soc_dapm_path *path;
857 if (widget->id != snd_soc_dapm_mixer &&
858 widget->id != snd_soc_dapm_mixer_named_ctl &&
859 widget->id != snd_soc_dapm_switch)
862 if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
865 /* find dapm widget path assoc with kcontrol */
866 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
867 if (path->kcontrol != kcontrol)
870 /* found, now check type */
874 path->connect = invert ? 0:1;
876 /* old connection must be powered down */
877 path->connect = invert ? 1:0;
882 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
883 dump_dapm(widget->codec, "mixer power update");
889 /* show dapm widget status in sys fs */
890 static ssize_t dapm_widget_show(struct device *dev,
891 struct device_attribute *attr, char *buf)
893 struct snd_soc_device *devdata = dev_get_drvdata(dev);
894 struct snd_soc_codec *codec = devdata->card->codec;
895 struct snd_soc_dapm_widget *w;
897 char *state = "not set";
899 list_for_each_entry(w, &codec->dapm_widgets, list) {
901 /* only display widgets that burnm power */
903 case snd_soc_dapm_hp:
904 case snd_soc_dapm_mic:
905 case snd_soc_dapm_spk:
906 case snd_soc_dapm_line:
907 case snd_soc_dapm_micbias:
908 case snd_soc_dapm_dac:
909 case snd_soc_dapm_adc:
910 case snd_soc_dapm_pga:
911 case snd_soc_dapm_mixer:
912 case snd_soc_dapm_mixer_named_ctl:
913 case snd_soc_dapm_supply:
915 count += sprintf(buf + count, "%s: %s\n",
916 w->name, w->power ? "On":"Off");
923 switch (codec->bias_level) {
924 case SND_SOC_BIAS_ON:
927 case SND_SOC_BIAS_PREPARE:
930 case SND_SOC_BIAS_STANDBY:
933 case SND_SOC_BIAS_OFF:
937 count += sprintf(buf + count, "PM State: %s\n", state);
942 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
944 int snd_soc_dapm_sys_add(struct device *dev)
948 return device_create_file(dev, &dev_attr_dapm_widget);
951 static void snd_soc_dapm_sys_remove(struct device *dev)
954 device_remove_file(dev, &dev_attr_dapm_widget);
958 /* free all dapm widgets and resources */
959 static void dapm_free_widgets(struct snd_soc_codec *codec)
961 struct snd_soc_dapm_widget *w, *next_w;
962 struct snd_soc_dapm_path *p, *next_p;
964 list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) {
969 list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) {
976 static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
977 const char *pin, int status)
979 struct snd_soc_dapm_widget *w;
981 list_for_each_entry(w, &codec->dapm_widgets, list) {
982 if (!strcmp(w->name, pin)) {
983 pr_debug("dapm: %s: pin %s\n", codec->name, pin);
984 w->connected = status;
989 pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
994 * snd_soc_dapm_sync - scan and power dapm paths
995 * @codec: audio codec
997 * Walks all dapm audio paths and powers widgets according to their
998 * stream or path usage.
1000 * Returns 0 for success.
1002 int snd_soc_dapm_sync(struct snd_soc_codec *codec)
1004 int ret = dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
1005 dump_dapm(codec, "sync");
1008 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1010 static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1011 const char *sink, const char *control, const char *source)
1013 struct snd_soc_dapm_path *path;
1014 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1017 /* find src and dest widgets */
1018 list_for_each_entry(w, &codec->dapm_widgets, list) {
1020 if (!wsink && !(strcmp(w->name, sink))) {
1024 if (!wsource && !(strcmp(w->name, source))) {
1029 if (wsource == NULL || wsink == NULL)
1032 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1036 path->source = wsource;
1038 INIT_LIST_HEAD(&path->list);
1039 INIT_LIST_HEAD(&path->list_source);
1040 INIT_LIST_HEAD(&path->list_sink);
1042 /* check for external widgets */
1043 if (wsink->id == snd_soc_dapm_input) {
1044 if (wsource->id == snd_soc_dapm_micbias ||
1045 wsource->id == snd_soc_dapm_mic ||
1046 wsink->id == snd_soc_dapm_line ||
1047 wsink->id == snd_soc_dapm_output)
1050 if (wsource->id == snd_soc_dapm_output) {
1051 if (wsink->id == snd_soc_dapm_spk ||
1052 wsink->id == snd_soc_dapm_hp ||
1053 wsink->id == snd_soc_dapm_line ||
1054 wsink->id == snd_soc_dapm_input)
1058 /* connect static paths */
1059 if (control == NULL) {
1060 list_add(&path->list, &codec->dapm_paths);
1061 list_add(&path->list_sink, &wsink->sources);
1062 list_add(&path->list_source, &wsource->sinks);
1067 /* connect dynamic paths */
1069 case snd_soc_dapm_adc:
1070 case snd_soc_dapm_dac:
1071 case snd_soc_dapm_pga:
1072 case snd_soc_dapm_input:
1073 case snd_soc_dapm_output:
1074 case snd_soc_dapm_micbias:
1075 case snd_soc_dapm_vmid:
1076 case snd_soc_dapm_pre:
1077 case snd_soc_dapm_post:
1078 case snd_soc_dapm_supply:
1079 list_add(&path->list, &codec->dapm_paths);
1080 list_add(&path->list_sink, &wsink->sources);
1081 list_add(&path->list_source, &wsource->sinks);
1084 case snd_soc_dapm_mux:
1085 case snd_soc_dapm_value_mux:
1086 ret = dapm_connect_mux(codec, wsource, wsink, path, control,
1087 &wsink->kcontrols[0]);
1091 case snd_soc_dapm_switch:
1092 case snd_soc_dapm_mixer:
1093 case snd_soc_dapm_mixer_named_ctl:
1094 ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
1098 case snd_soc_dapm_hp:
1099 case snd_soc_dapm_mic:
1100 case snd_soc_dapm_line:
1101 case snd_soc_dapm_spk:
1102 list_add(&path->list, &codec->dapm_paths);
1103 list_add(&path->list_sink, &wsink->sources);
1104 list_add(&path->list_source, &wsource->sinks);
1111 printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
1118 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1120 * @route: audio routes
1121 * @num: number of routes
1123 * Connects 2 dapm widgets together via a named audio path. The sink is
1124 * the widget receiving the audio signal, whilst the source is the sender
1125 * of the audio signal.
1127 * Returns 0 for success else error. On error all resources can be freed
1128 * with a call to snd_soc_card_free().
1130 int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
1131 const struct snd_soc_dapm_route *route, int num)
1135 for (i = 0; i < num; i++) {
1136 ret = snd_soc_dapm_add_route(codec, route->sink,
1137 route->control, route->source);
1139 printk(KERN_ERR "Failed to add route %s->%s\n",
1149 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1152 * snd_soc_dapm_new_widgets - add new dapm widgets
1153 * @codec: audio codec
1155 * Checks the codec for any new dapm widgets and creates them if found.
1157 * Returns 0 for success.
1159 int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1161 struct snd_soc_dapm_widget *w;
1163 list_for_each_entry(w, &codec->dapm_widgets, list)
1169 case snd_soc_dapm_switch:
1170 case snd_soc_dapm_mixer:
1171 case snd_soc_dapm_mixer_named_ctl:
1172 w->power_check = dapm_generic_check_power;
1173 dapm_new_mixer(codec, w);
1175 case snd_soc_dapm_mux:
1176 case snd_soc_dapm_value_mux:
1177 w->power_check = dapm_generic_check_power;
1178 dapm_new_mux(codec, w);
1180 case snd_soc_dapm_adc:
1181 w->power_check = dapm_adc_check_power;
1183 case snd_soc_dapm_dac:
1184 w->power_check = dapm_dac_check_power;
1186 case snd_soc_dapm_pga:
1187 w->power_check = dapm_generic_check_power;
1188 dapm_new_pga(codec, w);
1190 case snd_soc_dapm_input:
1191 case snd_soc_dapm_output:
1192 case snd_soc_dapm_micbias:
1193 case snd_soc_dapm_spk:
1194 case snd_soc_dapm_hp:
1195 case snd_soc_dapm_mic:
1196 case snd_soc_dapm_line:
1197 w->power_check = dapm_generic_check_power;
1199 case snd_soc_dapm_supply:
1200 w->power_check = dapm_supply_check_power;
1201 case snd_soc_dapm_vmid:
1202 case snd_soc_dapm_pre:
1203 case snd_soc_dapm_post:
1209 dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
1212 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
1215 * snd_soc_dapm_get_volsw - dapm mixer get callback
1216 * @kcontrol: mixer control
1217 * @ucontrol: control element information
1219 * Callback to get the value of a dapm mixer control.
1221 * Returns 0 for success.
1223 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
1224 struct snd_ctl_elem_value *ucontrol)
1226 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1227 struct soc_mixer_control *mc =
1228 (struct soc_mixer_control *)kcontrol->private_value;
1229 unsigned int reg = mc->reg;
1230 unsigned int shift = mc->shift;
1231 unsigned int rshift = mc->rshift;
1233 unsigned int invert = mc->invert;
1234 unsigned int mask = (1 << fls(max)) - 1;
1236 /* return the saved value if we are powered down */
1237 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1238 ucontrol->value.integer.value[0] = widget->saved_value;
1242 ucontrol->value.integer.value[0] =
1243 (snd_soc_read(widget->codec, reg) >> shift) & mask;
1244 if (shift != rshift)
1245 ucontrol->value.integer.value[1] =
1246 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
1248 ucontrol->value.integer.value[0] =
1249 max - ucontrol->value.integer.value[0];
1250 if (shift != rshift)
1251 ucontrol->value.integer.value[1] =
1252 max - ucontrol->value.integer.value[1];
1257 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
1260 * snd_soc_dapm_put_volsw - dapm mixer set callback
1261 * @kcontrol: mixer control
1262 * @ucontrol: control element information
1264 * Callback to set the value of a dapm mixer control.
1266 * Returns 0 for success.
1268 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1269 struct snd_ctl_elem_value *ucontrol)
1271 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1272 struct soc_mixer_control *mc =
1273 (struct soc_mixer_control *)kcontrol->private_value;
1274 unsigned int reg = mc->reg;
1275 unsigned int shift = mc->shift;
1276 unsigned int rshift = mc->rshift;
1278 unsigned int mask = (1 << fls(max)) - 1;
1279 unsigned int invert = mc->invert;
1280 unsigned short val, val2, val_mask;
1283 val = (ucontrol->value.integer.value[0] & mask);
1287 val_mask = mask << shift;
1289 if (shift != rshift) {
1290 val2 = (ucontrol->value.integer.value[1] & mask);
1293 val_mask |= mask << rshift;
1294 val |= val2 << rshift;
1297 mutex_lock(&widget->codec->mutex);
1298 widget->value = val;
1300 /* save volume value if the widget is powered down */
1301 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1302 widget->saved_value = val;
1303 mutex_unlock(&widget->codec->mutex);
1307 dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
1308 if (widget->event) {
1309 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1310 ret = widget->event(widget, kcontrol,
1311 SND_SOC_DAPM_PRE_REG);
1317 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1318 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1319 ret = widget->event(widget, kcontrol,
1320 SND_SOC_DAPM_POST_REG);
1322 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1325 mutex_unlock(&widget->codec->mutex);
1328 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1331 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1332 * @kcontrol: mixer control
1333 * @ucontrol: control element information
1335 * Callback to get the value of a dapm enumerated double mixer control.
1337 * Returns 0 for success.
1339 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
1340 struct snd_ctl_elem_value *ucontrol)
1342 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1343 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1344 unsigned short val, bitmask;
1346 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1348 val = snd_soc_read(widget->codec, e->reg);
1349 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1350 if (e->shift_l != e->shift_r)
1351 ucontrol->value.enumerated.item[1] =
1352 (val >> e->shift_r) & (bitmask - 1);
1356 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
1359 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1360 * @kcontrol: mixer control
1361 * @ucontrol: control element information
1363 * Callback to set the value of a dapm enumerated double mixer control.
1365 * Returns 0 for success.
1367 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1368 struct snd_ctl_elem_value *ucontrol)
1370 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1371 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1372 unsigned short val, mux;
1373 unsigned short mask, bitmask;
1376 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1378 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1380 mux = ucontrol->value.enumerated.item[0];
1381 val = mux << e->shift_l;
1382 mask = (bitmask - 1) << e->shift_l;
1383 if (e->shift_l != e->shift_r) {
1384 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1386 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1387 mask |= (bitmask - 1) << e->shift_r;
1390 mutex_lock(&widget->codec->mutex);
1391 widget->value = val;
1392 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
1393 if (widget->event) {
1394 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1395 ret = widget->event(widget,
1396 kcontrol, SND_SOC_DAPM_PRE_REG);
1400 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1401 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1402 ret = widget->event(widget,
1403 kcontrol, SND_SOC_DAPM_POST_REG);
1405 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1408 mutex_unlock(&widget->codec->mutex);
1411 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1414 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1416 * @kcontrol: mixer control
1417 * @ucontrol: control element information
1419 * Callback to get the value of a dapm semi enumerated double mixer control.
1421 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1422 * used for handling bitfield coded enumeration for example.
1424 * Returns 0 for success.
1426 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
1427 struct snd_ctl_elem_value *ucontrol)
1429 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1430 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1431 unsigned short reg_val, val, mux;
1433 reg_val = snd_soc_read(widget->codec, e->reg);
1434 val = (reg_val >> e->shift_l) & e->mask;
1435 for (mux = 0; mux < e->max; mux++) {
1436 if (val == e->values[mux])
1439 ucontrol->value.enumerated.item[0] = mux;
1440 if (e->shift_l != e->shift_r) {
1441 val = (reg_val >> e->shift_r) & e->mask;
1442 for (mux = 0; mux < e->max; mux++) {
1443 if (val == e->values[mux])
1446 ucontrol->value.enumerated.item[1] = mux;
1451 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
1454 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1456 * @kcontrol: mixer control
1457 * @ucontrol: control element information
1459 * Callback to set the value of a dapm semi enumerated double mixer control.
1461 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1462 * used for handling bitfield coded enumeration for example.
1464 * Returns 0 for success.
1466 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1467 struct snd_ctl_elem_value *ucontrol)
1469 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1470 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1471 unsigned short val, mux;
1472 unsigned short mask;
1475 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1477 mux = ucontrol->value.enumerated.item[0];
1478 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1479 mask = e->mask << e->shift_l;
1480 if (e->shift_l != e->shift_r) {
1481 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1483 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1484 mask |= e->mask << e->shift_r;
1487 mutex_lock(&widget->codec->mutex);
1488 widget->value = val;
1489 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
1490 if (widget->event) {
1491 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1492 ret = widget->event(widget,
1493 kcontrol, SND_SOC_DAPM_PRE_REG);
1497 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1498 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1499 ret = widget->event(widget,
1500 kcontrol, SND_SOC_DAPM_POST_REG);
1502 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1505 mutex_unlock(&widget->codec->mutex);
1508 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1511 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1513 * @kcontrol: mixer control
1514 * @uinfo: control element information
1516 * Callback to provide information about a pin switch control.
1518 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
1519 struct snd_ctl_elem_info *uinfo)
1521 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1523 uinfo->value.integer.min = 0;
1524 uinfo->value.integer.max = 1;
1528 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
1531 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1533 * @kcontrol: mixer control
1536 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
1537 struct snd_ctl_elem_value *ucontrol)
1539 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1540 const char *pin = (const char *)kcontrol->private_value;
1542 mutex_lock(&codec->mutex);
1544 ucontrol->value.integer.value[0] =
1545 snd_soc_dapm_get_pin_status(codec, pin);
1547 mutex_unlock(&codec->mutex);
1551 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
1554 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1556 * @kcontrol: mixer control
1559 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
1560 struct snd_ctl_elem_value *ucontrol)
1562 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1563 const char *pin = (const char *)kcontrol->private_value;
1565 mutex_lock(&codec->mutex);
1567 if (ucontrol->value.integer.value[0])
1568 snd_soc_dapm_enable_pin(codec, pin);
1570 snd_soc_dapm_disable_pin(codec, pin);
1572 snd_soc_dapm_sync(codec);
1574 mutex_unlock(&codec->mutex);
1578 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
1581 * snd_soc_dapm_new_control - create new dapm control
1582 * @codec: audio codec
1583 * @widget: widget template
1585 * Creates a new dapm control based upon the template.
1587 * Returns 0 for success else error.
1589 int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
1590 const struct snd_soc_dapm_widget *widget)
1592 struct snd_soc_dapm_widget *w;
1594 if ((w = dapm_cnew_widget(widget)) == NULL)
1598 INIT_LIST_HEAD(&w->sources);
1599 INIT_LIST_HEAD(&w->sinks);
1600 INIT_LIST_HEAD(&w->list);
1601 list_add(&w->list, &codec->dapm_widgets);
1603 /* machine layer set ups unconnected pins and insertions */
1607 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1610 * snd_soc_dapm_new_controls - create new dapm controls
1611 * @codec: audio codec
1612 * @widget: widget array
1613 * @num: number of widgets
1615 * Creates new DAPM controls based upon the templates.
1617 * Returns 0 for success else error.
1619 int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
1620 const struct snd_soc_dapm_widget *widget,
1625 for (i = 0; i < num; i++) {
1626 ret = snd_soc_dapm_new_control(codec, widget);
1629 "ASoC: Failed to create DAPM control %s: %d\n",
1637 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1641 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1642 * @codec: audio codec
1643 * @stream: stream name
1644 * @event: stream event
1646 * Sends a stream event to the dapm core. The core then makes any
1647 * necessary widget power changes.
1649 * Returns 0 for success else error.
1651 int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1652 char *stream, int event)
1654 struct snd_soc_dapm_widget *w;
1659 mutex_lock(&codec->mutex);
1660 list_for_each_entry(w, &codec->dapm_widgets, list)
1664 pr_debug("widget %s\n %s stream %s event %d\n",
1665 w->name, w->sname, stream, event);
1666 if (strstr(w->sname, stream)) {
1668 case SND_SOC_DAPM_STREAM_START:
1671 case SND_SOC_DAPM_STREAM_STOP:
1674 case SND_SOC_DAPM_STREAM_SUSPEND:
1679 case SND_SOC_DAPM_STREAM_RESUME:
1685 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
1687 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
1692 mutex_unlock(&codec->mutex);
1694 dapm_power_widgets(codec, event);
1695 dump_dapm(codec, __func__);
1698 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
1701 * snd_soc_dapm_set_bias_level - set the bias level for the system
1702 * @socdev: audio device
1703 * @level: level to configure
1705 * Configure the bias (power) levels for the SoC audio device.
1707 * Returns 0 for success else error.
1709 int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
1710 enum snd_soc_bias_level level)
1712 struct snd_soc_card *card = socdev->card;
1713 struct snd_soc_codec *codec = socdev->card->codec;
1716 if (card->set_bias_level)
1717 ret = card->set_bias_level(card, level);
1718 if (ret == 0 && codec->set_bias_level)
1719 ret = codec->set_bias_level(codec, level);
1725 * snd_soc_dapm_enable_pin - enable pin.
1729 * Enables input/output pin and it's parents or children widgets iff there is
1730 * a valid audio route and active audio stream.
1731 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1732 * do any widget power switching.
1734 int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
1736 return snd_soc_dapm_set_pin(codec, pin, 1);
1738 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
1741 * snd_soc_dapm_disable_pin - disable pin.
1745 * Disables input/output pin and it's parents or children widgets.
1746 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1747 * do any widget power switching.
1749 int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin)
1751 return snd_soc_dapm_set_pin(codec, pin, 0);
1753 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
1756 * snd_soc_dapm_nc_pin - permanently disable pin.
1760 * Marks the specified pin as being not connected, disabling it along
1761 * any parent or child widgets. At present this is identical to
1762 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1763 * additional things such as disabling controls which only affect
1764 * paths through the pin.
1766 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1767 * do any widget power switching.
1769 int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin)
1771 return snd_soc_dapm_set_pin(codec, pin, 0);
1773 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
1776 * snd_soc_dapm_get_pin_status - get audio pin status
1777 * @codec: audio codec
1778 * @pin: audio signal pin endpoint (or start point)
1780 * Get audio pin status - connected or disconnected.
1782 * Returns 1 for connected otherwise 0.
1784 int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin)
1786 struct snd_soc_dapm_widget *w;
1788 list_for_each_entry(w, &codec->dapm_widgets, list) {
1789 if (!strcmp(w->name, pin))
1790 return w->connected;
1795 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
1798 * snd_soc_dapm_free - free dapm resources
1799 * @socdev: SoC device
1801 * Free all dapm widgets and resources.
1803 void snd_soc_dapm_free(struct snd_soc_device *socdev)
1805 struct snd_soc_codec *codec = socdev->card->codec;
1807 snd_soc_dapm_sys_remove(socdev->dev);
1808 dapm_free_widgets(codec);
1810 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
1812 /* Module information */
1813 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1814 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1815 MODULE_LICENSE("GPL");