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);
97 /* set up initial codec paths */
98 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
99 struct snd_soc_dapm_path *p, int i)
102 case snd_soc_dapm_switch:
103 case snd_soc_dapm_mixer:
104 case snd_soc_dapm_mixer_named_ctl: {
106 struct soc_mixer_control *mc = (struct soc_mixer_control *)
107 w->kcontrols[i].private_value;
108 unsigned int reg = mc->reg;
109 unsigned int shift = mc->shift;
111 unsigned int mask = (1 << fls(max)) - 1;
112 unsigned int invert = mc->invert;
114 val = snd_soc_read(w->codec, reg);
115 val = (val >> shift) & mask;
117 if ((invert && !val) || (!invert && val))
123 case snd_soc_dapm_mux: {
124 struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
125 int val, item, bitmask;
127 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
129 val = snd_soc_read(w->codec, e->reg);
130 item = (val >> e->shift_l) & (bitmask - 1);
133 for (i = 0; i < e->max; i++) {
134 if (!(strcmp(p->name, e->texts[i])) && item == i)
139 case snd_soc_dapm_value_mux: {
140 struct soc_enum *e = (struct soc_enum *)
141 w->kcontrols[i].private_value;
144 val = snd_soc_read(w->codec, e->reg);
145 val = (val >> e->shift_l) & e->mask;
146 for (item = 0; item < e->max; item++) {
147 if (val == e->values[item])
152 for (i = 0; i < e->max; i++) {
153 if (!(strcmp(p->name, e->texts[i])) && item == i)
158 /* does not effect routing - always connected */
159 case snd_soc_dapm_pga:
160 case snd_soc_dapm_output:
161 case snd_soc_dapm_adc:
162 case snd_soc_dapm_input:
163 case snd_soc_dapm_dac:
164 case snd_soc_dapm_micbias:
165 case snd_soc_dapm_vmid:
166 case snd_soc_dapm_supply:
169 /* does effect routing - dynamically connected */
170 case snd_soc_dapm_hp:
171 case snd_soc_dapm_mic:
172 case snd_soc_dapm_spk:
173 case snd_soc_dapm_line:
174 case snd_soc_dapm_pre:
175 case snd_soc_dapm_post:
181 /* connect mux widget to it's interconnecting audio paths */
182 static int dapm_connect_mux(struct snd_soc_codec *codec,
183 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
184 struct snd_soc_dapm_path *path, const char *control_name,
185 const struct snd_kcontrol_new *kcontrol)
187 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
190 for (i = 0; i < e->max; i++) {
191 if (!(strcmp(control_name, e->texts[i]))) {
192 list_add(&path->list, &codec->dapm_paths);
193 list_add(&path->list_sink, &dest->sources);
194 list_add(&path->list_source, &src->sinks);
195 path->name = (char*)e->texts[i];
196 dapm_set_path_status(dest, path, 0);
204 /* connect mixer widget to it's interconnecting audio paths */
205 static int dapm_connect_mixer(struct snd_soc_codec *codec,
206 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
207 struct snd_soc_dapm_path *path, const char *control_name)
211 /* search for mixer kcontrol */
212 for (i = 0; i < dest->num_kcontrols; i++) {
213 if (!strcmp(control_name, dest->kcontrols[i].name)) {
214 list_add(&path->list, &codec->dapm_paths);
215 list_add(&path->list_sink, &dest->sources);
216 list_add(&path->list_source, &src->sinks);
217 path->name = dest->kcontrols[i].name;
218 dapm_set_path_status(dest, path, i);
225 /* update dapm codec register bits */
226 static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
229 unsigned short old, new;
230 struct snd_soc_codec *codec = widget->codec;
232 /* check for valid widgets */
233 if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
234 widget->id == snd_soc_dapm_output ||
235 widget->id == snd_soc_dapm_hp ||
236 widget->id == snd_soc_dapm_mic ||
237 widget->id == snd_soc_dapm_line ||
238 widget->id == snd_soc_dapm_spk)
241 power = widget->power;
243 power = (power ? 0:1);
245 old = snd_soc_read(codec, widget->reg);
246 new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
250 pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n",
251 widget->name, widget->power ? "on" : "off",
253 snd_soc_write(codec, widget->reg, new);
254 pop_wait(codec->pop_time);
256 pr_debug("reg %x old %x new %x change %d\n", widget->reg,
261 /* ramps the volume up or down to minimise pops before or after a
262 * DAPM power event */
263 static int dapm_set_pga(struct snd_soc_dapm_widget *widget, int power)
265 const struct snd_kcontrol_new *k = widget->kcontrols;
267 if (widget->muted && !power)
269 if (!widget->muted && power)
272 if (widget->num_kcontrols && k) {
273 struct soc_mixer_control *mc =
274 (struct soc_mixer_control *)k->private_value;
275 unsigned int reg = mc->reg;
276 unsigned int shift = mc->shift;
278 unsigned int mask = (1 << fls(max)) - 1;
279 unsigned int invert = mc->invert;
283 /* power up has happended, increase volume to last level */
285 for (i = max; i > widget->saved_value; i--)
286 snd_soc_update_bits(widget->codec, reg, mask, i);
288 for (i = 0; i < widget->saved_value; i++)
289 snd_soc_update_bits(widget->codec, reg, mask, i);
293 /* power down is about to occur, decrease volume to mute */
294 int val = snd_soc_read(widget->codec, reg);
295 int i = widget->saved_value = (val >> shift) & mask;
297 for (; i < mask; i++)
298 snd_soc_update_bits(widget->codec, reg, mask, i);
301 snd_soc_update_bits(widget->codec, reg, mask, i);
309 /* create new dapm mixer control */
310 static int dapm_new_mixer(struct snd_soc_codec *codec,
311 struct snd_soc_dapm_widget *w)
315 struct snd_soc_dapm_path *path;
318 for (i = 0; i < w->num_kcontrols; i++) {
321 list_for_each_entry(path, &w->sources, list_sink) {
323 /* mixer/mux paths name must match control name */
324 if (path->name != (char*)w->kcontrols[i].name)
327 /* add dapm control with long name.
328 * for dapm_mixer this is the concatenation of the
329 * mixer and kcontrol name.
330 * for dapm_mixer_named_ctl this is simply the
333 name_len = strlen(w->kcontrols[i].name) + 1;
334 if (w->id != snd_soc_dapm_mixer_named_ctl)
335 name_len += 1 + strlen(w->name);
337 path->long_name = kmalloc(name_len, GFP_KERNEL);
339 if (path->long_name == NULL)
344 snprintf(path->long_name, name_len, "%s %s",
345 w->name, w->kcontrols[i].name);
347 case snd_soc_dapm_mixer_named_ctl:
348 snprintf(path->long_name, name_len, "%s",
349 w->kcontrols[i].name);
353 path->long_name[name_len - 1] = '\0';
355 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
357 ret = snd_ctl_add(codec->card, path->kcontrol);
359 printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n",
362 kfree(path->long_name);
363 path->long_name = NULL;
371 /* create new dapm mux control */
372 static int dapm_new_mux(struct snd_soc_codec *codec,
373 struct snd_soc_dapm_widget *w)
375 struct snd_soc_dapm_path *path = NULL;
376 struct snd_kcontrol *kcontrol;
379 if (!w->num_kcontrols) {
380 printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
384 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
385 ret = snd_ctl_add(codec->card, kcontrol);
389 list_for_each_entry(path, &w->sources, list_sink)
390 path->kcontrol = kcontrol;
395 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
399 /* create new dapm volume control */
400 static int dapm_new_pga(struct snd_soc_codec *codec,
401 struct snd_soc_dapm_widget *w)
403 struct snd_kcontrol *kcontrol;
406 if (!w->num_kcontrols)
409 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
410 ret = snd_ctl_add(codec->card, kcontrol);
412 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
419 /* reset 'walked' bit for each dapm path */
420 static inline void dapm_clear_walk(struct snd_soc_codec *codec)
422 struct snd_soc_dapm_path *p;
424 list_for_each_entry(p, &codec->dapm_paths, list)
429 * Recursively check for a completed path to an active or physically connected
430 * output widget. Returns number of complete paths.
432 static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
434 struct snd_soc_dapm_path *path;
437 if (widget->id == snd_soc_dapm_supply)
440 if (widget->id == snd_soc_dapm_adc && widget->active)
443 if (widget->connected) {
444 /* connected pin ? */
445 if (widget->id == snd_soc_dapm_output && !widget->ext)
448 /* connected jack or spk ? */
449 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
450 widget->id == snd_soc_dapm_line)
454 list_for_each_entry(path, &widget->sinks, list_source) {
458 if (path->sink && path->connect) {
460 con += is_connected_output_ep(path->sink);
468 * Recursively check for a completed path to an active or physically connected
469 * input widget. Returns number of complete paths.
471 static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
473 struct snd_soc_dapm_path *path;
476 if (widget->id == snd_soc_dapm_supply)
479 /* active stream ? */
480 if (widget->id == snd_soc_dapm_dac && widget->active)
483 if (widget->connected) {
484 /* connected pin ? */
485 if (widget->id == snd_soc_dapm_input && !widget->ext)
488 /* connected VMID/Bias for lower pops */
489 if (widget->id == snd_soc_dapm_vmid)
492 /* connected jack ? */
493 if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line)
497 list_for_each_entry(path, &widget->sources, list_sink) {
501 if (path->source && path->connect) {
503 con += is_connected_input_ep(path->source);
511 * Handler for generic register modifier widget.
513 int dapm_reg_event(struct snd_soc_dapm_widget *w,
514 struct snd_kcontrol *kcontrol, int event)
518 if (SND_SOC_DAPM_EVENT_ON(event))
523 snd_soc_update_bits(w->codec, -(w->reg + 1),
524 w->mask << w->shift, val << w->shift);
528 EXPORT_SYMBOL_GPL(dapm_reg_event);
530 /* Standard power change method, used to apply power changes to most
533 static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
537 /* call any power change event handlers */
539 pr_debug("power %s event for %s flags %x\n",
540 w->power ? "on" : "off",
541 w->name, w->event_flags);
543 /* power up pre event */
544 if (w->power && w->event &&
545 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
546 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
551 /* power down pre event */
552 if (!w->power && w->event &&
553 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
554 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
559 /* Lower PGA volume to reduce pops */
560 if (w->id == snd_soc_dapm_pga && !w->power)
561 dapm_set_pga(w, w->power);
565 /* Raise PGA volume to reduce pops */
566 if (w->id == snd_soc_dapm_pga && w->power)
567 dapm_set_pga(w, w->power);
569 /* power up post event */
570 if (w->power && w->event &&
571 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
573 NULL, SND_SOC_DAPM_POST_PMU);
578 /* power down post event */
579 if (!w->power && w->event &&
580 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
581 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
589 /* Generic check to see if a widget should be powered.
591 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
595 in = is_connected_input_ep(w);
596 dapm_clear_walk(w->codec);
597 out = is_connected_output_ep(w);
598 dapm_clear_walk(w->codec);
599 return out != 0 && in != 0;
602 /* Check to see if an ADC has power */
603 static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
608 in = is_connected_input_ep(w);
609 dapm_clear_walk(w->codec);
612 return dapm_generic_check_power(w);
616 /* Check to see if a DAC has power */
617 static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
622 out = is_connected_output_ep(w);
623 dapm_clear_walk(w->codec);
626 return dapm_generic_check_power(w);
630 /* Check to see if a power supply is needed */
631 static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
633 struct snd_soc_dapm_path *path;
636 /* Check if one of our outputs is connected */
637 list_for_each_entry(path, &w->sinks, list_source) {
638 if (path->sink && path->sink->power_check &&
639 path->sink->power_check(path->sink)) {
645 dapm_clear_walk(w->codec);
651 * Scan a single DAPM widget for a complete audio path and update the
652 * power status appropriately.
654 static int dapm_power_widget(struct snd_soc_codec *codec, int event,
655 struct snd_soc_dapm_widget *w)
660 case snd_soc_dapm_pre:
664 if (event == SND_SOC_DAPM_STREAM_START) {
666 NULL, SND_SOC_DAPM_PRE_PMU);
669 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
671 NULL, SND_SOC_DAPM_PRE_PMD);
677 case snd_soc_dapm_post:
681 if (event == SND_SOC_DAPM_STREAM_START) {
683 NULL, SND_SOC_DAPM_POST_PMU);
686 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
688 NULL, SND_SOC_DAPM_POST_PMD);
695 return dapm_generic_apply_power(w);
700 * Scan each dapm widget for complete audio path.
701 * A complete path is a route that has valid endpoints i.e.:-
703 * o DAC to output pin.
704 * o Input Pin to ADC.
705 * o Input pin to Output pin (bypass, sidetone)
706 * o DAC to ADC (loopback).
708 static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
710 struct snd_soc_dapm_widget *w;
714 INIT_LIST_HEAD(&codec->up_list);
715 INIT_LIST_HEAD(&codec->down_list);
717 /* Check which widgets we need to power and store them in
718 * lists indicating if they should be powered up or down.
720 list_for_each_entry(w, &codec->dapm_widgets, list) {
722 case snd_soc_dapm_pre:
723 list_add_tail(&codec->down_list, &w->power_list);
725 case snd_soc_dapm_post:
726 list_add_tail(&codec->up_list, &w->power_list);
733 power = w->power_check(w);
734 if (w->power == power)
738 list_add_tail(&w->power_list, &codec->up_list);
740 list_add_tail(&w->power_list,
748 /* Power down widgets first; try to avoid amplifying pops. */
749 for (i = 0; i < ARRAY_SIZE(dapm_down_seq); i++) {
750 list_for_each_entry(w, &codec->down_list, power_list) {
751 /* is widget in stream order */
752 if (w->id != dapm_down_seq[i])
755 ret = dapm_power_widget(codec, event, w);
757 pr_err("Failed to power down %s: %d\n",
763 for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) {
764 list_for_each_entry(w, &codec->up_list, power_list) {
765 /* is widget in stream order */
766 if (w->id != dapm_up_seq[i])
769 ret = dapm_power_widget(codec, event, w);
771 pr_err("Failed to power up %s: %d\n",
780 static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
782 struct snd_soc_dapm_widget *w;
783 struct snd_soc_dapm_path *p = NULL;
786 printk("DAPM %s %s\n", codec->name, action);
788 list_for_each_entry(w, &codec->dapm_widgets, list) {
790 /* only display widgets that effect routing */
792 case snd_soc_dapm_pre:
793 case snd_soc_dapm_post:
794 case snd_soc_dapm_vmid:
796 case snd_soc_dapm_mux:
797 case snd_soc_dapm_value_mux:
798 case snd_soc_dapm_output:
799 case snd_soc_dapm_input:
800 case snd_soc_dapm_switch:
801 case snd_soc_dapm_hp:
802 case snd_soc_dapm_mic:
803 case snd_soc_dapm_spk:
804 case snd_soc_dapm_line:
805 case snd_soc_dapm_micbias:
806 case snd_soc_dapm_dac:
807 case snd_soc_dapm_adc:
808 case snd_soc_dapm_pga:
809 case snd_soc_dapm_mixer:
810 case snd_soc_dapm_mixer_named_ctl:
811 case snd_soc_dapm_supply:
813 in = is_connected_input_ep(w);
814 dapm_clear_walk(w->codec);
815 out = is_connected_output_ep(w);
816 dapm_clear_walk(w->codec);
817 printk("%s: %s in %d out %d\n", w->name,
818 w->power ? "On":"Off",in, out);
820 list_for_each_entry(p, &w->sources, list_sink) {
822 printk(" in %s %s\n", p->name ? p->name : "static",
825 list_for_each_entry(p, &w->sinks, list_source) {
827 printk(" out %s %s\n", p->name ? p->name : "static",
837 /* test and update the power status of a mux widget */
838 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
839 struct snd_kcontrol *kcontrol, int mask,
840 int mux, int val, struct soc_enum *e)
842 struct snd_soc_dapm_path *path;
845 if (widget->id != snd_soc_dapm_mux &&
846 widget->id != snd_soc_dapm_value_mux)
849 if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
852 /* find dapm widget path assoc with kcontrol */
853 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
854 if (path->kcontrol != kcontrol)
857 if (!path->name || !e->texts[mux])
861 /* we now need to match the string in the enum to the path */
862 if (!(strcmp(path->name, e->texts[mux])))
863 path->connect = 1; /* new connection */
865 path->connect = 0; /* old connection must be powered down */
869 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
870 dump_dapm(widget->codec, "mux power update");
876 /* test and update the power status of a mixer or switch widget */
877 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
878 struct snd_kcontrol *kcontrol, int reg,
879 int val_mask, int val, int invert)
881 struct snd_soc_dapm_path *path;
884 if (widget->id != snd_soc_dapm_mixer &&
885 widget->id != snd_soc_dapm_mixer_named_ctl &&
886 widget->id != snd_soc_dapm_switch)
889 if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
892 /* find dapm widget path assoc with kcontrol */
893 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
894 if (path->kcontrol != kcontrol)
897 /* found, now check type */
901 path->connect = invert ? 0:1;
903 /* old connection must be powered down */
904 path->connect = invert ? 1:0;
909 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
910 dump_dapm(widget->codec, "mixer power update");
916 /* show dapm widget status in sys fs */
917 static ssize_t dapm_widget_show(struct device *dev,
918 struct device_attribute *attr, char *buf)
920 struct snd_soc_device *devdata = dev_get_drvdata(dev);
921 struct snd_soc_codec *codec = devdata->card->codec;
922 struct snd_soc_dapm_widget *w;
924 char *state = "not set";
926 list_for_each_entry(w, &codec->dapm_widgets, list) {
928 /* only display widgets that burnm power */
930 case snd_soc_dapm_hp:
931 case snd_soc_dapm_mic:
932 case snd_soc_dapm_spk:
933 case snd_soc_dapm_line:
934 case snd_soc_dapm_micbias:
935 case snd_soc_dapm_dac:
936 case snd_soc_dapm_adc:
937 case snd_soc_dapm_pga:
938 case snd_soc_dapm_mixer:
939 case snd_soc_dapm_mixer_named_ctl:
940 case snd_soc_dapm_supply:
942 count += sprintf(buf + count, "%s: %s\n",
943 w->name, w->power ? "On":"Off");
950 switch (codec->bias_level) {
951 case SND_SOC_BIAS_ON:
954 case SND_SOC_BIAS_PREPARE:
957 case SND_SOC_BIAS_STANDBY:
960 case SND_SOC_BIAS_OFF:
964 count += sprintf(buf + count, "PM State: %s\n", state);
969 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
971 int snd_soc_dapm_sys_add(struct device *dev)
973 return device_create_file(dev, &dev_attr_dapm_widget);
976 static void snd_soc_dapm_sys_remove(struct device *dev)
978 device_remove_file(dev, &dev_attr_dapm_widget);
981 /* free all dapm widgets and resources */
982 static void dapm_free_widgets(struct snd_soc_codec *codec)
984 struct snd_soc_dapm_widget *w, *next_w;
985 struct snd_soc_dapm_path *p, *next_p;
987 list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) {
992 list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) {
999 static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
1000 const char *pin, int status)
1002 struct snd_soc_dapm_widget *w;
1004 list_for_each_entry(w, &codec->dapm_widgets, list) {
1005 if (!strcmp(w->name, pin)) {
1006 pr_debug("dapm: %s: pin %s\n", codec->name, pin);
1007 w->connected = status;
1012 pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
1017 * snd_soc_dapm_sync - scan and power dapm paths
1018 * @codec: audio codec
1020 * Walks all dapm audio paths and powers widgets according to their
1021 * stream or path usage.
1023 * Returns 0 for success.
1025 int snd_soc_dapm_sync(struct snd_soc_codec *codec)
1027 int ret = dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
1028 dump_dapm(codec, "sync");
1031 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1033 static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1034 const char *sink, const char *control, const char *source)
1036 struct snd_soc_dapm_path *path;
1037 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1040 /* find src and dest widgets */
1041 list_for_each_entry(w, &codec->dapm_widgets, list) {
1043 if (!wsink && !(strcmp(w->name, sink))) {
1047 if (!wsource && !(strcmp(w->name, source))) {
1052 if (wsource == NULL || wsink == NULL)
1055 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1059 path->source = wsource;
1061 INIT_LIST_HEAD(&path->list);
1062 INIT_LIST_HEAD(&path->list_source);
1063 INIT_LIST_HEAD(&path->list_sink);
1065 /* check for external widgets */
1066 if (wsink->id == snd_soc_dapm_input) {
1067 if (wsource->id == snd_soc_dapm_micbias ||
1068 wsource->id == snd_soc_dapm_mic ||
1069 wsink->id == snd_soc_dapm_line ||
1070 wsink->id == snd_soc_dapm_output)
1073 if (wsource->id == snd_soc_dapm_output) {
1074 if (wsink->id == snd_soc_dapm_spk ||
1075 wsink->id == snd_soc_dapm_hp ||
1076 wsink->id == snd_soc_dapm_line ||
1077 wsink->id == snd_soc_dapm_input)
1081 /* connect static paths */
1082 if (control == NULL) {
1083 list_add(&path->list, &codec->dapm_paths);
1084 list_add(&path->list_sink, &wsink->sources);
1085 list_add(&path->list_source, &wsource->sinks);
1090 /* connect dynamic paths */
1092 case snd_soc_dapm_adc:
1093 case snd_soc_dapm_dac:
1094 case snd_soc_dapm_pga:
1095 case snd_soc_dapm_input:
1096 case snd_soc_dapm_output:
1097 case snd_soc_dapm_micbias:
1098 case snd_soc_dapm_vmid:
1099 case snd_soc_dapm_pre:
1100 case snd_soc_dapm_post:
1101 case snd_soc_dapm_supply:
1102 list_add(&path->list, &codec->dapm_paths);
1103 list_add(&path->list_sink, &wsink->sources);
1104 list_add(&path->list_source, &wsource->sinks);
1107 case snd_soc_dapm_mux:
1108 case snd_soc_dapm_value_mux:
1109 ret = dapm_connect_mux(codec, wsource, wsink, path, control,
1110 &wsink->kcontrols[0]);
1114 case snd_soc_dapm_switch:
1115 case snd_soc_dapm_mixer:
1116 case snd_soc_dapm_mixer_named_ctl:
1117 ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
1121 case snd_soc_dapm_hp:
1122 case snd_soc_dapm_mic:
1123 case snd_soc_dapm_line:
1124 case snd_soc_dapm_spk:
1125 list_add(&path->list, &codec->dapm_paths);
1126 list_add(&path->list_sink, &wsink->sources);
1127 list_add(&path->list_source, &wsource->sinks);
1134 printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
1141 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1143 * @route: audio routes
1144 * @num: number of routes
1146 * Connects 2 dapm widgets together via a named audio path. The sink is
1147 * the widget receiving the audio signal, whilst the source is the sender
1148 * of the audio signal.
1150 * Returns 0 for success else error. On error all resources can be freed
1151 * with a call to snd_soc_card_free().
1153 int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
1154 const struct snd_soc_dapm_route *route, int num)
1158 for (i = 0; i < num; i++) {
1159 ret = snd_soc_dapm_add_route(codec, route->sink,
1160 route->control, route->source);
1162 printk(KERN_ERR "Failed to add route %s->%s\n",
1172 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1175 * snd_soc_dapm_new_widgets - add new dapm widgets
1176 * @codec: audio codec
1178 * Checks the codec for any new dapm widgets and creates them if found.
1180 * Returns 0 for success.
1182 int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1184 struct snd_soc_dapm_widget *w;
1186 list_for_each_entry(w, &codec->dapm_widgets, list)
1192 case snd_soc_dapm_switch:
1193 case snd_soc_dapm_mixer:
1194 case snd_soc_dapm_mixer_named_ctl:
1195 w->power_check = dapm_generic_check_power;
1196 dapm_new_mixer(codec, w);
1198 case snd_soc_dapm_mux:
1199 case snd_soc_dapm_value_mux:
1200 w->power_check = dapm_generic_check_power;
1201 dapm_new_mux(codec, w);
1203 case snd_soc_dapm_adc:
1204 w->power_check = dapm_adc_check_power;
1206 case snd_soc_dapm_dac:
1207 w->power_check = dapm_dac_check_power;
1209 case snd_soc_dapm_pga:
1210 w->power_check = dapm_generic_check_power;
1211 dapm_new_pga(codec, w);
1213 case snd_soc_dapm_input:
1214 case snd_soc_dapm_output:
1215 case snd_soc_dapm_micbias:
1216 case snd_soc_dapm_spk:
1217 case snd_soc_dapm_hp:
1218 case snd_soc_dapm_mic:
1219 case snd_soc_dapm_line:
1220 w->power_check = dapm_generic_check_power;
1222 case snd_soc_dapm_supply:
1223 w->power_check = dapm_supply_check_power;
1224 case snd_soc_dapm_vmid:
1225 case snd_soc_dapm_pre:
1226 case snd_soc_dapm_post:
1232 dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
1235 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
1238 * snd_soc_dapm_get_volsw - dapm mixer get callback
1239 * @kcontrol: mixer control
1240 * @ucontrol: control element information
1242 * Callback to get the value of a dapm mixer control.
1244 * Returns 0 for success.
1246 int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
1247 struct snd_ctl_elem_value *ucontrol)
1249 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1250 struct soc_mixer_control *mc =
1251 (struct soc_mixer_control *)kcontrol->private_value;
1252 unsigned int reg = mc->reg;
1253 unsigned int shift = mc->shift;
1254 unsigned int rshift = mc->rshift;
1256 unsigned int invert = mc->invert;
1257 unsigned int mask = (1 << fls(max)) - 1;
1259 /* return the saved value if we are powered down */
1260 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1261 ucontrol->value.integer.value[0] = widget->saved_value;
1265 ucontrol->value.integer.value[0] =
1266 (snd_soc_read(widget->codec, reg) >> shift) & mask;
1267 if (shift != rshift)
1268 ucontrol->value.integer.value[1] =
1269 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
1271 ucontrol->value.integer.value[0] =
1272 max - ucontrol->value.integer.value[0];
1273 if (shift != rshift)
1274 ucontrol->value.integer.value[1] =
1275 max - ucontrol->value.integer.value[1];
1280 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
1283 * snd_soc_dapm_put_volsw - dapm mixer set callback
1284 * @kcontrol: mixer control
1285 * @ucontrol: control element information
1287 * Callback to set the value of a dapm mixer control.
1289 * Returns 0 for success.
1291 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1292 struct snd_ctl_elem_value *ucontrol)
1294 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1295 struct soc_mixer_control *mc =
1296 (struct soc_mixer_control *)kcontrol->private_value;
1297 unsigned int reg = mc->reg;
1298 unsigned int shift = mc->shift;
1299 unsigned int rshift = mc->rshift;
1301 unsigned int mask = (1 << fls(max)) - 1;
1302 unsigned int invert = mc->invert;
1303 unsigned short val, val2, val_mask;
1306 val = (ucontrol->value.integer.value[0] & mask);
1310 val_mask = mask << shift;
1312 if (shift != rshift) {
1313 val2 = (ucontrol->value.integer.value[1] & mask);
1316 val_mask |= mask << rshift;
1317 val |= val2 << rshift;
1320 mutex_lock(&widget->codec->mutex);
1321 widget->value = val;
1323 /* save volume value if the widget is powered down */
1324 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1325 widget->saved_value = val;
1326 mutex_unlock(&widget->codec->mutex);
1330 dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
1331 if (widget->event) {
1332 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1333 ret = widget->event(widget, kcontrol,
1334 SND_SOC_DAPM_PRE_REG);
1340 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1341 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1342 ret = widget->event(widget, kcontrol,
1343 SND_SOC_DAPM_POST_REG);
1345 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1348 mutex_unlock(&widget->codec->mutex);
1351 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1354 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1355 * @kcontrol: mixer control
1356 * @ucontrol: control element information
1358 * Callback to get the value of a dapm enumerated double mixer control.
1360 * Returns 0 for success.
1362 int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
1363 struct snd_ctl_elem_value *ucontrol)
1365 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1366 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1367 unsigned short val, bitmask;
1369 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1371 val = snd_soc_read(widget->codec, e->reg);
1372 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1373 if (e->shift_l != e->shift_r)
1374 ucontrol->value.enumerated.item[1] =
1375 (val >> e->shift_r) & (bitmask - 1);
1379 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
1382 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1383 * @kcontrol: mixer control
1384 * @ucontrol: control element information
1386 * Callback to set the value of a dapm enumerated double mixer control.
1388 * Returns 0 for success.
1390 int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1391 struct snd_ctl_elem_value *ucontrol)
1393 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1394 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1395 unsigned short val, mux;
1396 unsigned short mask, bitmask;
1399 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1401 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1403 mux = ucontrol->value.enumerated.item[0];
1404 val = mux << e->shift_l;
1405 mask = (bitmask - 1) << e->shift_l;
1406 if (e->shift_l != e->shift_r) {
1407 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1409 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1410 mask |= (bitmask - 1) << e->shift_r;
1413 mutex_lock(&widget->codec->mutex);
1414 widget->value = val;
1415 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
1416 if (widget->event) {
1417 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1418 ret = widget->event(widget,
1419 kcontrol, SND_SOC_DAPM_PRE_REG);
1423 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1424 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1425 ret = widget->event(widget,
1426 kcontrol, SND_SOC_DAPM_POST_REG);
1428 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1431 mutex_unlock(&widget->codec->mutex);
1434 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1437 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1439 * @kcontrol: mixer control
1440 * @ucontrol: control element information
1442 * Callback to get the value of a dapm semi enumerated double mixer control.
1444 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1445 * used for handling bitfield coded enumeration for example.
1447 * Returns 0 for success.
1449 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
1450 struct snd_ctl_elem_value *ucontrol)
1452 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1453 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1454 unsigned short reg_val, val, mux;
1456 reg_val = snd_soc_read(widget->codec, e->reg);
1457 val = (reg_val >> e->shift_l) & e->mask;
1458 for (mux = 0; mux < e->max; mux++) {
1459 if (val == e->values[mux])
1462 ucontrol->value.enumerated.item[0] = mux;
1463 if (e->shift_l != e->shift_r) {
1464 val = (reg_val >> e->shift_r) & e->mask;
1465 for (mux = 0; mux < e->max; mux++) {
1466 if (val == e->values[mux])
1469 ucontrol->value.enumerated.item[1] = mux;
1474 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
1477 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1479 * @kcontrol: mixer control
1480 * @ucontrol: control element information
1482 * Callback to set the value of a dapm semi enumerated double mixer control.
1484 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1485 * used for handling bitfield coded enumeration for example.
1487 * Returns 0 for success.
1489 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1490 struct snd_ctl_elem_value *ucontrol)
1492 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1493 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1494 unsigned short val, mux;
1495 unsigned short mask;
1498 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1500 mux = ucontrol->value.enumerated.item[0];
1501 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1502 mask = e->mask << e->shift_l;
1503 if (e->shift_l != e->shift_r) {
1504 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1506 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1507 mask |= e->mask << e->shift_r;
1510 mutex_lock(&widget->codec->mutex);
1511 widget->value = val;
1512 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
1513 if (widget->event) {
1514 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1515 ret = widget->event(widget,
1516 kcontrol, SND_SOC_DAPM_PRE_REG);
1520 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1521 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1522 ret = widget->event(widget,
1523 kcontrol, SND_SOC_DAPM_POST_REG);
1525 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1528 mutex_unlock(&widget->codec->mutex);
1531 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1534 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1536 * @kcontrol: mixer control
1537 * @uinfo: control element information
1539 * Callback to provide information about a pin switch control.
1541 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
1542 struct snd_ctl_elem_info *uinfo)
1544 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1546 uinfo->value.integer.min = 0;
1547 uinfo->value.integer.max = 1;
1551 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
1554 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1556 * @kcontrol: mixer control
1559 int snd_soc_dapm_get_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 ucontrol->value.integer.value[0] =
1568 snd_soc_dapm_get_pin_status(codec, pin);
1570 mutex_unlock(&codec->mutex);
1574 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
1577 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1579 * @kcontrol: mixer control
1582 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
1583 struct snd_ctl_elem_value *ucontrol)
1585 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1586 const char *pin = (const char *)kcontrol->private_value;
1588 mutex_lock(&codec->mutex);
1590 if (ucontrol->value.integer.value[0])
1591 snd_soc_dapm_enable_pin(codec, pin);
1593 snd_soc_dapm_disable_pin(codec, pin);
1595 snd_soc_dapm_sync(codec);
1597 mutex_unlock(&codec->mutex);
1601 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
1604 * snd_soc_dapm_new_control - create new dapm control
1605 * @codec: audio codec
1606 * @widget: widget template
1608 * Creates a new dapm control based upon the template.
1610 * Returns 0 for success else error.
1612 int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
1613 const struct snd_soc_dapm_widget *widget)
1615 struct snd_soc_dapm_widget *w;
1617 if ((w = dapm_cnew_widget(widget)) == NULL)
1621 INIT_LIST_HEAD(&w->sources);
1622 INIT_LIST_HEAD(&w->sinks);
1623 INIT_LIST_HEAD(&w->list);
1624 list_add(&w->list, &codec->dapm_widgets);
1626 /* machine layer set ups unconnected pins and insertions */
1630 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1633 * snd_soc_dapm_new_controls - create new dapm controls
1634 * @codec: audio codec
1635 * @widget: widget array
1636 * @num: number of widgets
1638 * Creates new DAPM controls based upon the templates.
1640 * Returns 0 for success else error.
1642 int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
1643 const struct snd_soc_dapm_widget *widget,
1648 for (i = 0; i < num; i++) {
1649 ret = snd_soc_dapm_new_control(codec, widget);
1652 "ASoC: Failed to create DAPM control %s: %d\n",
1660 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1664 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1665 * @codec: audio codec
1666 * @stream: stream name
1667 * @event: stream event
1669 * Sends a stream event to the dapm core. The core then makes any
1670 * necessary widget power changes.
1672 * Returns 0 for success else error.
1674 int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1675 char *stream, int event)
1677 struct snd_soc_dapm_widget *w;
1682 mutex_lock(&codec->mutex);
1683 list_for_each_entry(w, &codec->dapm_widgets, list)
1687 pr_debug("widget %s\n %s stream %s event %d\n",
1688 w->name, w->sname, stream, event);
1689 if (strstr(w->sname, stream)) {
1691 case SND_SOC_DAPM_STREAM_START:
1694 case SND_SOC_DAPM_STREAM_STOP:
1697 case SND_SOC_DAPM_STREAM_SUSPEND:
1702 case SND_SOC_DAPM_STREAM_RESUME:
1708 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
1710 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
1715 mutex_unlock(&codec->mutex);
1717 dapm_power_widgets(codec, event);
1718 dump_dapm(codec, __func__);
1721 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
1724 * snd_soc_dapm_set_bias_level - set the bias level for the system
1725 * @socdev: audio device
1726 * @level: level to configure
1728 * Configure the bias (power) levels for the SoC audio device.
1730 * Returns 0 for success else error.
1732 int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
1733 enum snd_soc_bias_level level)
1735 struct snd_soc_card *card = socdev->card;
1736 struct snd_soc_codec *codec = socdev->card->codec;
1739 if (card->set_bias_level)
1740 ret = card->set_bias_level(card, level);
1741 if (ret == 0 && codec->set_bias_level)
1742 ret = codec->set_bias_level(codec, level);
1748 * snd_soc_dapm_enable_pin - enable pin.
1752 * Enables input/output pin and it's parents or children widgets iff there is
1753 * a valid audio route and active audio stream.
1754 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1755 * do any widget power switching.
1757 int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
1759 return snd_soc_dapm_set_pin(codec, pin, 1);
1761 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
1764 * snd_soc_dapm_disable_pin - disable pin.
1768 * Disables input/output pin and it's parents or children widgets.
1769 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1770 * do any widget power switching.
1772 int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin)
1774 return snd_soc_dapm_set_pin(codec, pin, 0);
1776 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
1779 * snd_soc_dapm_nc_pin - permanently disable pin.
1783 * Marks the specified pin as being not connected, disabling it along
1784 * any parent or child widgets. At present this is identical to
1785 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1786 * additional things such as disabling controls which only affect
1787 * paths through the pin.
1789 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1790 * do any widget power switching.
1792 int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin)
1794 return snd_soc_dapm_set_pin(codec, pin, 0);
1796 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
1799 * snd_soc_dapm_get_pin_status - get audio pin status
1800 * @codec: audio codec
1801 * @pin: audio signal pin endpoint (or start point)
1803 * Get audio pin status - connected or disconnected.
1805 * Returns 1 for connected otherwise 0.
1807 int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin)
1809 struct snd_soc_dapm_widget *w;
1811 list_for_each_entry(w, &codec->dapm_widgets, list) {
1812 if (!strcmp(w->name, pin))
1813 return w->connected;
1818 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
1821 * snd_soc_dapm_free - free dapm resources
1822 * @socdev: SoC device
1824 * Free all dapm widgets and resources.
1826 void snd_soc_dapm_free(struct snd_soc_device *socdev)
1828 struct snd_soc_codec *codec = socdev->card->codec;
1830 snd_soc_dapm_sys_remove(socdev->dev);
1831 dapm_free_widgets(codec);
1833 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
1835 /* Module information */
1836 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1837 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1838 MODULE_LICENSE("GPL");