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/async.h>
36 #include <linux/delay.h>
38 #include <linux/bitops.h>
39 #include <linux/platform_device.h>
40 #include <linux/jiffies.h>
41 #include <linux/debugfs.h>
42 #include <linux/slab.h>
43 #include <sound/core.h>
44 #include <sound/pcm.h>
45 #include <sound/pcm_params.h>
46 #include <sound/soc.h>
47 #include <sound/initval.h>
49 #include <trace/events/asoc.h>
51 /* dapm power sequences - make this per codec in the future */
52 static int dapm_up_seq
[] = {
53 [snd_soc_dapm_pre
] = 0,
54 [snd_soc_dapm_supply
] = 1,
55 [snd_soc_dapm_micbias
] = 2,
56 [snd_soc_dapm_aif_in
] = 3,
57 [snd_soc_dapm_aif_out
] = 3,
58 [snd_soc_dapm_mic
] = 4,
59 [snd_soc_dapm_mux
] = 5,
60 [snd_soc_dapm_virt_mux
] = 5,
61 [snd_soc_dapm_value_mux
] = 5,
62 [snd_soc_dapm_dac
] = 6,
63 [snd_soc_dapm_mixer
] = 7,
64 [snd_soc_dapm_mixer_named_ctl
] = 7,
65 [snd_soc_dapm_pga
] = 8,
66 [snd_soc_dapm_adc
] = 9,
67 [snd_soc_dapm_out_drv
] = 10,
68 [snd_soc_dapm_hp
] = 10,
69 [snd_soc_dapm_spk
] = 10,
70 [snd_soc_dapm_post
] = 11,
73 static int dapm_down_seq
[] = {
74 [snd_soc_dapm_pre
] = 0,
75 [snd_soc_dapm_adc
] = 1,
76 [snd_soc_dapm_hp
] = 2,
77 [snd_soc_dapm_spk
] = 2,
78 [snd_soc_dapm_out_drv
] = 2,
79 [snd_soc_dapm_pga
] = 4,
80 [snd_soc_dapm_mixer_named_ctl
] = 5,
81 [snd_soc_dapm_mixer
] = 5,
82 [snd_soc_dapm_dac
] = 6,
83 [snd_soc_dapm_mic
] = 7,
84 [snd_soc_dapm_micbias
] = 8,
85 [snd_soc_dapm_mux
] = 9,
86 [snd_soc_dapm_virt_mux
] = 9,
87 [snd_soc_dapm_value_mux
] = 9,
88 [snd_soc_dapm_aif_in
] = 10,
89 [snd_soc_dapm_aif_out
] = 10,
90 [snd_soc_dapm_supply
] = 11,
91 [snd_soc_dapm_post
] = 12,
94 static void pop_wait(u32 pop_time
)
97 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
100 static void pop_dbg(struct device
*dev
, u32 pop_time
, const char *fmt
, ...)
108 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
113 vsnprintf(buf
, PAGE_SIZE
, fmt
, args
);
114 dev_info(dev
, "%s", buf
);
120 /* create a new dapm widget */
121 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
122 const struct snd_soc_dapm_widget
*_widget
)
124 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
127 /* get snd_card from DAPM context */
128 static inline struct snd_card
*dapm_get_snd_card(
129 struct snd_soc_dapm_context
*dapm
)
132 return dapm
->codec
->card
->snd_card
;
133 else if (dapm
->platform
)
134 return dapm
->platform
->card
->snd_card
;
142 /* get soc_card from DAPM context */
143 static inline struct snd_soc_card
*dapm_get_soc_card(
144 struct snd_soc_dapm_context
*dapm
)
147 return dapm
->codec
->card
;
148 else if (dapm
->platform
)
149 return dapm
->platform
->card
;
157 static int soc_widget_read(struct snd_soc_dapm_widget
*w
, int reg
)
160 return snd_soc_read(w
->codec
, reg
);
161 else if (w
->platform
)
162 return snd_soc_platform_read(w
->platform
, reg
);
164 dev_err(w
->dapm
->dev
, "no valid widget read method\n");
168 static int soc_widget_write(struct snd_soc_dapm_widget
*w
, int reg
, int val
)
171 return snd_soc_write(w
->codec
, reg
, val
);
172 else if (w
->platform
)
173 return snd_soc_platform_write(w
->platform
, reg
, val
);
175 dev_err(w
->dapm
->dev
, "no valid widget write method\n");
179 static int soc_widget_update_bits(struct snd_soc_dapm_widget
*w
,
180 unsigned short reg
, unsigned int mask
, unsigned int value
)
183 unsigned int old
, new;
186 ret
= soc_widget_read(w
, reg
);
191 new = (old
& ~mask
) | (value
& mask
);
194 ret
= soc_widget_write(w
, reg
, new);
203 * snd_soc_dapm_set_bias_level - set the bias level for the system
204 * @dapm: DAPM context
205 * @level: level to configure
207 * Configure the bias (power) levels for the SoC audio device.
209 * Returns 0 for success else error.
211 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
212 enum snd_soc_bias_level level
)
214 struct snd_soc_card
*card
= dapm
->card
;
217 trace_snd_soc_bias_level_start(card
, level
);
219 if (card
&& card
->set_bias_level
)
220 ret
= card
->set_bias_level(card
, dapm
, level
);
225 if (dapm
->codec
->driver
->set_bias_level
)
226 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
229 dapm
->bias_level
= level
;
234 if (card
&& card
->set_bias_level_post
)
235 ret
= card
->set_bias_level_post(card
, dapm
, level
);
237 trace_snd_soc_bias_level_done(card
, level
);
242 /* set up initial codec paths */
243 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
244 struct snd_soc_dapm_path
*p
, int i
)
247 case snd_soc_dapm_switch
:
248 case snd_soc_dapm_mixer
:
249 case snd_soc_dapm_mixer_named_ctl
: {
251 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
252 w
->kcontrol_news
[i
].private_value
;
253 unsigned int reg
= mc
->reg
;
254 unsigned int shift
= mc
->shift
;
256 unsigned int mask
= (1 << fls(max
)) - 1;
257 unsigned int invert
= mc
->invert
;
259 val
= soc_widget_read(w
, reg
);
260 val
= (val
>> shift
) & mask
;
262 if ((invert
&& !val
) || (!invert
&& val
))
268 case snd_soc_dapm_mux
: {
269 struct soc_enum
*e
= (struct soc_enum
*)
270 w
->kcontrol_news
[i
].private_value
;
271 int val
, item
, bitmask
;
273 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
275 val
= soc_widget_read(w
, e
->reg
);
276 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
279 for (i
= 0; i
< e
->max
; i
++) {
280 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
285 case snd_soc_dapm_virt_mux
: {
286 struct soc_enum
*e
= (struct soc_enum
*)
287 w
->kcontrol_news
[i
].private_value
;
290 /* since a virtual mux has no backing registers to
291 * decide which path to connect, it will try to match
292 * with the first enumeration. This is to ensure
293 * that the default mux choice (the first) will be
294 * correctly powered up during initialization.
296 if (!strcmp(p
->name
, e
->texts
[0]))
300 case snd_soc_dapm_value_mux
: {
301 struct soc_enum
*e
= (struct soc_enum
*)
302 w
->kcontrol_news
[i
].private_value
;
305 val
= soc_widget_read(w
, e
->reg
);
306 val
= (val
>> e
->shift_l
) & e
->mask
;
307 for (item
= 0; item
< e
->max
; item
++) {
308 if (val
== e
->values
[item
])
313 for (i
= 0; i
< e
->max
; i
++) {
314 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
319 /* does not effect routing - always connected */
320 case snd_soc_dapm_pga
:
321 case snd_soc_dapm_out_drv
:
322 case snd_soc_dapm_output
:
323 case snd_soc_dapm_adc
:
324 case snd_soc_dapm_input
:
325 case snd_soc_dapm_dac
:
326 case snd_soc_dapm_micbias
:
327 case snd_soc_dapm_vmid
:
328 case snd_soc_dapm_supply
:
329 case snd_soc_dapm_aif_in
:
330 case snd_soc_dapm_aif_out
:
333 /* does effect routing - dynamically connected */
334 case snd_soc_dapm_hp
:
335 case snd_soc_dapm_mic
:
336 case snd_soc_dapm_spk
:
337 case snd_soc_dapm_line
:
338 case snd_soc_dapm_pre
:
339 case snd_soc_dapm_post
:
345 /* connect mux widget to its interconnecting audio paths */
346 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
347 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
348 struct snd_soc_dapm_path
*path
, const char *control_name
,
349 const struct snd_kcontrol_new
*kcontrol
)
351 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
354 for (i
= 0; i
< e
->max
; i
++) {
355 if (!(strcmp(control_name
, e
->texts
[i
]))) {
356 list_add(&path
->list
, &dapm
->card
->paths
);
357 list_add(&path
->list_sink
, &dest
->sources
);
358 list_add(&path
->list_source
, &src
->sinks
);
359 path
->name
= (char*)e
->texts
[i
];
360 dapm_set_path_status(dest
, path
, 0);
368 /* connect mixer widget to its interconnecting audio paths */
369 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
370 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
371 struct snd_soc_dapm_path
*path
, const char *control_name
)
375 /* search for mixer kcontrol */
376 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
377 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
378 list_add(&path
->list
, &dapm
->card
->paths
);
379 list_add(&path
->list_sink
, &dest
->sources
);
380 list_add(&path
->list_source
, &src
->sinks
);
381 path
->name
= dest
->kcontrol_news
[i
].name
;
382 dapm_set_path_status(dest
, path
, i
);
389 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
390 struct snd_soc_dapm_widget
*kcontrolw
,
391 const struct snd_kcontrol_new
*kcontrol_new
,
392 struct snd_kcontrol
**kcontrol
)
394 struct snd_soc_dapm_widget
*w
;
399 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
400 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
402 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
403 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
405 *kcontrol
= w
->kcontrols
[i
];
414 /* create new dapm mixer control */
415 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
417 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
419 size_t name_len
, prefix_len
;
420 struct snd_soc_dapm_path
*path
;
421 struct snd_card
*card
= dapm
->card
->snd_card
;
423 struct snd_soc_dapm_widget_list
*wlist
;
427 prefix
= dapm
->codec
->name_prefix
;
432 prefix_len
= strlen(prefix
) + 1;
437 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
440 list_for_each_entry(path
, &w
->sources
, list_sink
) {
442 /* mixer/mux paths name must match control name */
443 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
446 if (w
->kcontrols
[i
]) {
447 path
->kcontrol
= w
->kcontrols
[i
];
451 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
452 sizeof(struct snd_soc_dapm_widget
*),
453 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
456 "asoc: can't allocate widget list for %s\n",
460 wlist
->num_widgets
= 1;
461 wlist
->widgets
[0] = w
;
463 /* add dapm control with long name.
464 * for dapm_mixer this is the concatenation of the
465 * mixer and kcontrol name.
466 * for dapm_mixer_named_ctl this is simply the
469 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
470 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
471 name_len
+= 1 + strlen(w
->name
);
473 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
475 if (path
->long_name
== NULL
) {
482 /* The control will get a prefix from
483 * the control creation process but
484 * we're also using the same prefix
485 * for widgets so cut the prefix off
486 * the front of the widget name.
488 snprintf(path
->long_name
, name_len
, "%s %s",
489 w
->name
+ prefix_len
,
490 w
->kcontrol_news
[i
].name
);
492 case snd_soc_dapm_mixer_named_ctl
:
493 snprintf(path
->long_name
, name_len
, "%s",
494 w
->kcontrol_news
[i
].name
);
498 path
->long_name
[name_len
- 1] = '\0';
500 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
501 wlist
, path
->long_name
,
503 ret
= snd_ctl_add(card
, path
->kcontrol
);
506 "asoc: failed to add dapm kcontrol %s: %d\n",
507 path
->long_name
, ret
);
509 kfree(path
->long_name
);
510 path
->long_name
= NULL
;
513 w
->kcontrols
[i
] = path
->kcontrol
;
519 /* create new dapm mux control */
520 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
522 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
523 struct snd_soc_dapm_path
*path
= NULL
;
524 struct snd_kcontrol
*kcontrol
;
525 struct snd_card
*card
= dapm
->card
->snd_card
;
529 struct snd_soc_dapm_widget_list
*wlist
;
530 int shared
, wlistentries
;
534 if (w
->num_kcontrols
!= 1) {
536 "asoc: mux %s has incorrect number of controls\n",
541 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[0],
544 wlist
= kcontrol
->private_data
;
545 wlistentries
= wlist
->num_widgets
+ 1;
550 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
551 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
552 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
555 "asoc: can't allocate widget list for %s\n", w
->name
);
558 wlist
->num_widgets
= wlistentries
;
559 wlist
->widgets
[wlistentries
- 1] = w
;
563 prefix
= dapm
->codec
->name_prefix
;
568 name
= w
->kcontrol_news
[0].name
;
573 prefix_len
= strlen(prefix
) + 1;
579 * The control will get a prefix from the control creation
580 * process but we're also using the same prefix for widgets so
581 * cut the prefix off the front of the widget name.
583 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
584 name
+ prefix_len
, prefix
);
585 ret
= snd_ctl_add(card
, kcontrol
);
588 "asoc: failed to add kcontrol %s\n", w
->name
);
594 kcontrol
->private_data
= wlist
;
596 w
->kcontrols
[0] = kcontrol
;
598 list_for_each_entry(path
, &w
->sources
, list_sink
)
599 path
->kcontrol
= kcontrol
;
604 /* create new dapm volume control */
605 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
607 if (w
->num_kcontrols
)
608 dev_err(w
->dapm
->dev
,
609 "asoc: PGA controls not supported: '%s'\n", w
->name
);
614 /* reset 'walked' bit for each dapm path */
615 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
617 struct snd_soc_dapm_path
*p
;
619 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
623 /* We implement power down on suspend by checking the power state of
624 * the ALSA card - when we are suspending the ALSA state for the card
627 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
629 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
632 case SNDRV_CTL_POWER_D3hot
:
633 case SNDRV_CTL_POWER_D3cold
:
634 if (widget
->ignore_suspend
)
635 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
637 return widget
->ignore_suspend
;
644 * Recursively check for a completed path to an active or physically connected
645 * output widget. Returns number of complete paths.
647 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
649 struct snd_soc_dapm_path
*path
;
652 if (widget
->id
== snd_soc_dapm_supply
)
655 switch (widget
->id
) {
656 case snd_soc_dapm_adc
:
657 case snd_soc_dapm_aif_out
:
659 return snd_soc_dapm_suspend_check(widget
);
664 if (widget
->connected
) {
665 /* connected pin ? */
666 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
667 return snd_soc_dapm_suspend_check(widget
);
669 /* connected jack or spk ? */
670 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
671 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sources
)))
672 return snd_soc_dapm_suspend_check(widget
);
675 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
682 if (path
->sink
&& path
->connect
) {
684 con
+= is_connected_output_ep(path
->sink
);
692 * Recursively check for a completed path to an active or physically connected
693 * input widget. Returns number of complete paths.
695 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
697 struct snd_soc_dapm_path
*path
;
700 if (widget
->id
== snd_soc_dapm_supply
)
703 /* active stream ? */
704 switch (widget
->id
) {
705 case snd_soc_dapm_dac
:
706 case snd_soc_dapm_aif_in
:
708 return snd_soc_dapm_suspend_check(widget
);
713 if (widget
->connected
) {
714 /* connected pin ? */
715 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
716 return snd_soc_dapm_suspend_check(widget
);
718 /* connected VMID/Bias for lower pops */
719 if (widget
->id
== snd_soc_dapm_vmid
)
720 return snd_soc_dapm_suspend_check(widget
);
722 /* connected jack ? */
723 if (widget
->id
== snd_soc_dapm_mic
||
724 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sinks
)))
725 return snd_soc_dapm_suspend_check(widget
);
728 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
735 if (path
->source
&& path
->connect
) {
737 con
+= is_connected_input_ep(path
->source
);
745 * Handler for generic register modifier widget.
747 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
748 struct snd_kcontrol
*kcontrol
, int event
)
752 if (SND_SOC_DAPM_EVENT_ON(event
))
757 soc_widget_update_bits(w
, -(w
->reg
+ 1),
758 w
->mask
<< w
->shift
, val
<< w
->shift
);
762 EXPORT_SYMBOL_GPL(dapm_reg_event
);
764 /* Generic check to see if a widget should be powered.
766 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
770 in
= is_connected_input_ep(w
);
771 dapm_clear_walk(w
->dapm
);
772 out
= is_connected_output_ep(w
);
773 dapm_clear_walk(w
->dapm
);
774 return out
!= 0 && in
!= 0;
777 /* Check to see if an ADC has power */
778 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
783 in
= is_connected_input_ep(w
);
784 dapm_clear_walk(w
->dapm
);
787 return dapm_generic_check_power(w
);
791 /* Check to see if a DAC has power */
792 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
797 out
= is_connected_output_ep(w
);
798 dapm_clear_walk(w
->dapm
);
801 return dapm_generic_check_power(w
);
805 /* Check to see if a power supply is needed */
806 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
808 struct snd_soc_dapm_path
*path
;
811 /* Check if one of our outputs is connected */
812 list_for_each_entry(path
, &w
->sinks
, list_source
) {
816 if (path
->connected
&&
817 !path
->connected(path
->source
, path
->sink
))
823 if (path
->sink
->force
) {
828 if (path
->sink
->power_check
&&
829 path
->sink
->power_check(path
->sink
)) {
835 dapm_clear_walk(w
->dapm
);
840 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
841 struct snd_soc_dapm_widget
*b
,
849 sort
= dapm_down_seq
;
851 if (sort
[a
->id
] != sort
[b
->id
])
852 return sort
[a
->id
] - sort
[b
->id
];
853 if (a
->subseq
!= b
->subseq
) {
855 return a
->subseq
- b
->subseq
;
857 return b
->subseq
- a
->subseq
;
859 if (a
->reg
!= b
->reg
)
860 return a
->reg
- b
->reg
;
861 if (a
->dapm
!= b
->dapm
)
862 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
867 /* Insert a widget in order into a DAPM power sequence. */
868 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
869 struct list_head
*list
,
872 struct snd_soc_dapm_widget
*w
;
874 list_for_each_entry(w
, list
, power_list
)
875 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
876 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
880 list_add_tail(&new_widget
->power_list
, list
);
883 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
884 struct snd_soc_dapm_widget
*w
, int event
)
886 struct snd_soc_card
*card
= dapm
->card
;
891 case SND_SOC_DAPM_PRE_PMU
:
895 case SND_SOC_DAPM_POST_PMU
:
896 ev_name
= "POST_PMU";
899 case SND_SOC_DAPM_PRE_PMD
:
903 case SND_SOC_DAPM_POST_PMD
:
904 ev_name
= "POST_PMD";
912 if (w
->power
!= power
)
915 if (w
->event
&& (w
->event_flags
& event
)) {
916 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
918 trace_snd_soc_dapm_widget_event_start(w
, event
);
919 ret
= w
->event(w
, NULL
, event
);
920 trace_snd_soc_dapm_widget_event_done(w
, event
);
922 pr_err("%s: %s event failed: %d\n",
923 ev_name
, w
->name
, ret
);
927 /* Apply the coalesced changes from a DAPM sequence */
928 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
929 struct list_head
*pending
)
931 struct snd_soc_card
*card
= dapm
->card
;
932 struct snd_soc_dapm_widget
*w
;
934 unsigned int value
= 0;
935 unsigned int mask
= 0;
936 unsigned int cur_mask
;
938 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
941 list_for_each_entry(w
, pending
, power_list
) {
942 cur_mask
= 1 << w
->shift
;
943 BUG_ON(reg
!= w
->reg
);
954 pop_dbg(dapm
->dev
, card
->pop_time
,
955 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
956 w
->name
, reg
, value
, mask
);
958 /* Check for events */
959 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
960 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
964 /* Any widget will do, they should all be updating the
967 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
970 pop_dbg(dapm
->dev
, card
->pop_time
,
971 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
972 value
, mask
, reg
, card
->pop_time
);
973 pop_wait(card
->pop_time
);
974 soc_widget_update_bits(w
, reg
, mask
, value
);
977 list_for_each_entry(w
, pending
, power_list
) {
978 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
979 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
983 /* Apply a DAPM power sequence.
985 * We walk over a pre-sorted list of widgets to apply power to. In
986 * order to minimise the number of writes to the device required
987 * multiple widgets will be updated in a single write where possible.
988 * Currently anything that requires more than a single write is not
991 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
992 struct list_head
*list
, int event
, bool power_up
)
994 struct snd_soc_dapm_widget
*w
, *n
;
998 int cur_reg
= SND_SOC_NOPM
;
999 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1006 sort
= dapm_down_seq
;
1008 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1011 /* Do we need to apply any queued changes? */
1012 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1013 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1014 if (!list_empty(&pending
))
1015 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1017 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1018 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1019 if (sort
[i
] == cur_sort
)
1020 cur_dapm
->seq_notifier(cur_dapm
,
1025 INIT_LIST_HEAD(&pending
);
1027 cur_subseq
= INT_MIN
;
1028 cur_reg
= SND_SOC_NOPM
;
1033 case snd_soc_dapm_pre
:
1035 list_for_each_entry_safe_continue(w
, n
, list
,
1038 if (event
== SND_SOC_DAPM_STREAM_START
)
1040 NULL
, SND_SOC_DAPM_PRE_PMU
);
1041 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1043 NULL
, SND_SOC_DAPM_PRE_PMD
);
1046 case snd_soc_dapm_post
:
1048 list_for_each_entry_safe_continue(w
, n
, list
,
1051 if (event
== SND_SOC_DAPM_STREAM_START
)
1053 NULL
, SND_SOC_DAPM_POST_PMU
);
1054 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1056 NULL
, SND_SOC_DAPM_POST_PMD
);
1060 /* Queue it up for application */
1061 cur_sort
= sort
[w
->id
];
1062 cur_subseq
= w
->subseq
;
1065 list_move(&w
->power_list
, &pending
);
1070 dev_err(w
->dapm
->dev
,
1071 "Failed to apply widget power: %d\n", ret
);
1074 if (!list_empty(&pending
))
1075 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1077 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1078 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1079 if (sort
[i
] == cur_sort
)
1080 cur_dapm
->seq_notifier(cur_dapm
,
1085 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1087 struct snd_soc_dapm_update
*update
= dapm
->update
;
1088 struct snd_soc_dapm_widget
*w
;
1097 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1098 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1100 pr_err("%s DAPM pre-event failed: %d\n",
1104 ret
= snd_soc_update_bits(w
->codec
, update
->reg
, update
->mask
,
1107 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1110 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1111 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1113 pr_err("%s DAPM post-event failed: %d\n",
1118 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1119 * they're changing state.
1121 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1123 struct snd_soc_dapm_context
*d
= data
;
1126 /* If we're off and we're not supposed to be go into STANDBY */
1127 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1128 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1129 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1132 "Failed to turn on bias: %d\n", ret
);
1135 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1136 if (d
->bias_level
!= d
->target_bias_level
) {
1137 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1140 "Failed to prepare bias: %d\n", ret
);
1144 /* Async callback run prior to DAPM sequences - brings to their final
1147 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1149 struct snd_soc_dapm_context
*d
= data
;
1152 /* If we just powered the last thing off drop to standby bias */
1153 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1154 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1155 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1156 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1158 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1162 /* If we're in standby and can support bias off then do that */
1163 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1164 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1165 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1167 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1170 /* If we just powered up then move to active bias */
1171 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1172 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1173 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1175 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1181 * Scan each dapm widget for complete audio path.
1182 * A complete path is a route that has valid endpoints i.e.:-
1184 * o DAC to output pin.
1185 * o Input Pin to ADC.
1186 * o Input pin to Output pin (bypass, sidetone)
1187 * o DAC to ADC (loopback).
1189 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1191 struct snd_soc_card
*card
= dapm
->card
;
1192 struct snd_soc_dapm_widget
*w
;
1193 struct snd_soc_dapm_context
*d
;
1195 LIST_HEAD(down_list
);
1196 LIST_HEAD(async_domain
);
1197 enum snd_soc_bias_level bias
;
1200 trace_snd_soc_dapm_start(card
);
1202 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1203 if (d
->n_widgets
|| d
->codec
== NULL
) {
1204 if (d
->idle_bias_off
)
1205 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1207 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1211 /* Check which widgets we need to power and store them in
1212 * lists indicating if they should be powered up or down.
1214 list_for_each_entry(w
, &card
->widgets
, list
) {
1216 case snd_soc_dapm_pre
:
1217 dapm_seq_insert(w
, &down_list
, false);
1219 case snd_soc_dapm_post
:
1220 dapm_seq_insert(w
, &up_list
, true);
1224 if (!w
->power_check
)
1228 power
= w
->power_check(w
);
1235 /* Supplies and micbiases only bring
1236 * the context up to STANDBY as unless
1237 * something else is active and
1238 * passing audio they generally don't
1239 * require full power.
1242 case snd_soc_dapm_supply
:
1243 case snd_soc_dapm_micbias
:
1244 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1245 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1248 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1253 if (w
->power
== power
)
1256 trace_snd_soc_dapm_widget_power(w
, power
);
1259 dapm_seq_insert(w
, &up_list
, true);
1261 dapm_seq_insert(w
, &down_list
, false);
1268 /* If there are no DAPM widgets then try to figure out power from the
1271 if (!dapm
->n_widgets
) {
1273 case SND_SOC_DAPM_STREAM_START
:
1274 case SND_SOC_DAPM_STREAM_RESUME
:
1275 dapm
->target_bias_level
= SND_SOC_BIAS_ON
;
1277 case SND_SOC_DAPM_STREAM_STOP
:
1278 if (dapm
->codec
->active
)
1279 dapm
->target_bias_level
= SND_SOC_BIAS_ON
;
1281 dapm
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1283 case SND_SOC_DAPM_STREAM_SUSPEND
:
1284 dapm
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1286 case SND_SOC_DAPM_STREAM_NOP
:
1287 dapm
->target_bias_level
= dapm
->bias_level
;
1294 /* Force all contexts in the card to the same bias state */
1295 bias
= SND_SOC_BIAS_OFF
;
1296 list_for_each_entry(d
, &card
->dapm_list
, list
)
1297 if (d
->target_bias_level
> bias
)
1298 bias
= d
->target_bias_level
;
1299 list_for_each_entry(d
, &card
->dapm_list
, list
)
1300 d
->target_bias_level
= bias
;
1303 /* Run all the bias changes in parallel */
1304 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1305 async_schedule_domain(dapm_pre_sequence_async
, d
,
1307 async_synchronize_full_domain(&async_domain
);
1309 /* Power down widgets first; try to avoid amplifying pops. */
1310 dapm_seq_run(dapm
, &down_list
, event
, false);
1312 dapm_widget_update(dapm
);
1315 dapm_seq_run(dapm
, &up_list
, event
, true);
1317 /* Run all the bias changes in parallel */
1318 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1319 async_schedule_domain(dapm_post_sequence_async
, d
,
1321 async_synchronize_full_domain(&async_domain
);
1323 pop_dbg(dapm
->dev
, card
->pop_time
,
1324 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1325 pop_wait(card
->pop_time
);
1327 trace_snd_soc_dapm_done(card
);
1332 #ifdef CONFIG_DEBUG_FS
1333 static int dapm_widget_power_open_file(struct inode
*inode
, struct file
*file
)
1335 file
->private_data
= inode
->i_private
;
1339 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1340 char __user
*user_buf
,
1341 size_t count
, loff_t
*ppos
)
1343 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1347 struct snd_soc_dapm_path
*p
= NULL
;
1349 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1353 in
= is_connected_input_ep(w
);
1354 dapm_clear_walk(w
->dapm
);
1355 out
= is_connected_output_ep(w
);
1356 dapm_clear_walk(w
->dapm
);
1358 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s in %d out %d",
1359 w
->name
, w
->power
? "On" : "Off", in
, out
);
1362 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1363 " - R%d(0x%x) bit %d",
1364 w
->reg
, w
->reg
, w
->shift
);
1366 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1369 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1371 w
->active
? "active" : "inactive");
1373 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1374 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1378 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1379 " in \"%s\" \"%s\"\n",
1380 p
->name
? p
->name
: "static",
1383 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1384 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1388 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1389 " out \"%s\" \"%s\"\n",
1390 p
->name
? p
->name
: "static",
1394 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1400 static const struct file_operations dapm_widget_power_fops
= {
1401 .open
= dapm_widget_power_open_file
,
1402 .read
= dapm_widget_power_read_file
,
1403 .llseek
= default_llseek
,
1406 static int dapm_bias_open_file(struct inode
*inode
, struct file
*file
)
1408 file
->private_data
= inode
->i_private
;
1412 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1413 size_t count
, loff_t
*ppos
)
1415 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1418 switch (dapm
->bias_level
) {
1419 case SND_SOC_BIAS_ON
:
1422 case SND_SOC_BIAS_PREPARE
:
1423 level
= "Prepare\n";
1425 case SND_SOC_BIAS_STANDBY
:
1426 level
= "Standby\n";
1428 case SND_SOC_BIAS_OFF
:
1433 level
= "Unknown\n";
1437 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1441 static const struct file_operations dapm_bias_fops
= {
1442 .open
= dapm_bias_open_file
,
1443 .read
= dapm_bias_read_file
,
1444 .llseek
= default_llseek
,
1447 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1448 struct dentry
*parent
)
1452 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1454 if (!dapm
->debugfs_dapm
) {
1456 "Failed to create DAPM debugfs directory\n");
1460 d
= debugfs_create_file("bias_level", 0444,
1461 dapm
->debugfs_dapm
, dapm
,
1465 "ASoC: Failed to create bias level debugfs file\n");
1468 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1470 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1473 if (!dapm
->debugfs_dapm
|| !w
->name
)
1476 d
= debugfs_create_file(w
->name
, 0444,
1477 dapm
->debugfs_dapm
, w
,
1478 &dapm_widget_power_fops
);
1480 dev_warn(w
->dapm
->dev
,
1481 "ASoC: Failed to create %s debugfs file\n",
1485 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1487 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1491 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1492 struct dentry
*parent
)
1496 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1500 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1506 /* test and update the power status of a mux widget */
1507 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1508 struct snd_kcontrol
*kcontrol
, int change
,
1509 int mux
, struct soc_enum
*e
)
1511 struct snd_soc_dapm_path
*path
;
1514 if (widget
->id
!= snd_soc_dapm_mux
&&
1515 widget
->id
!= snd_soc_dapm_virt_mux
&&
1516 widget
->id
!= snd_soc_dapm_value_mux
)
1522 /* find dapm widget path assoc with kcontrol */
1523 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1524 if (path
->kcontrol
!= kcontrol
)
1527 if (!path
->name
|| !e
->texts
[mux
])
1531 /* we now need to match the string in the enum to the path */
1532 if (!(strcmp(path
->name
, e
->texts
[mux
])))
1533 path
->connect
= 1; /* new connection */
1535 path
->connect
= 0; /* old connection must be powered down */
1539 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1544 /* test and update the power status of a mixer or switch widget */
1545 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1546 struct snd_kcontrol
*kcontrol
, int connect
)
1548 struct snd_soc_dapm_path
*path
;
1551 if (widget
->id
!= snd_soc_dapm_mixer
&&
1552 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1553 widget
->id
!= snd_soc_dapm_switch
)
1556 /* find dapm widget path assoc with kcontrol */
1557 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1558 if (path
->kcontrol
!= kcontrol
)
1561 /* found, now check type */
1563 path
->connect
= connect
;
1567 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1572 /* show dapm widget status in sys fs */
1573 static ssize_t
dapm_widget_show(struct device
*dev
,
1574 struct device_attribute
*attr
, char *buf
)
1576 struct snd_soc_pcm_runtime
*rtd
=
1577 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
1578 struct snd_soc_codec
*codec
=rtd
->codec
;
1579 struct snd_soc_dapm_widget
*w
;
1581 char *state
= "not set";
1583 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1584 if (w
->dapm
!= &codec
->dapm
)
1587 /* only display widgets that burnm power */
1589 case snd_soc_dapm_hp
:
1590 case snd_soc_dapm_mic
:
1591 case snd_soc_dapm_spk
:
1592 case snd_soc_dapm_line
:
1593 case snd_soc_dapm_micbias
:
1594 case snd_soc_dapm_dac
:
1595 case snd_soc_dapm_adc
:
1596 case snd_soc_dapm_pga
:
1597 case snd_soc_dapm_out_drv
:
1598 case snd_soc_dapm_mixer
:
1599 case snd_soc_dapm_mixer_named_ctl
:
1600 case snd_soc_dapm_supply
:
1602 count
+= sprintf(buf
+ count
, "%s: %s\n",
1603 w
->name
, w
->power
? "On":"Off");
1610 switch (codec
->dapm
.bias_level
) {
1611 case SND_SOC_BIAS_ON
:
1614 case SND_SOC_BIAS_PREPARE
:
1617 case SND_SOC_BIAS_STANDBY
:
1620 case SND_SOC_BIAS_OFF
:
1624 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1629 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1631 int snd_soc_dapm_sys_add(struct device
*dev
)
1633 return device_create_file(dev
, &dev_attr_dapm_widget
);
1636 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1638 device_remove_file(dev
, &dev_attr_dapm_widget
);
1641 /* free all dapm widgets and resources */
1642 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
1644 struct snd_soc_dapm_widget
*w
, *next_w
;
1645 struct snd_soc_dapm_path
*p
, *next_p
;
1647 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
1648 if (w
->dapm
!= dapm
)
1652 * remove source and sink paths associated to this widget.
1653 * While removing the path, remove reference to it from both
1654 * source and sink widgets so that path is removed only once.
1656 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
1657 list_del(&p
->list_sink
);
1658 list_del(&p
->list_source
);
1660 kfree(p
->long_name
);
1663 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
1664 list_del(&p
->list_sink
);
1665 list_del(&p
->list_source
);
1667 kfree(p
->long_name
);
1670 kfree(w
->kcontrols
);
1676 static struct snd_soc_dapm_widget
*dapm_find_widget(
1677 struct snd_soc_dapm_context
*dapm
, const char *pin
,
1678 bool search_other_contexts
)
1680 struct snd_soc_dapm_widget
*w
;
1681 struct snd_soc_dapm_widget
*fallback
= NULL
;
1683 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1684 if (!strcmp(w
->name
, pin
)) {
1685 if (w
->dapm
== dapm
)
1692 if (search_other_contexts
)
1698 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
1699 const char *pin
, int status
)
1701 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
1704 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
1708 w
->connected
= status
;
1716 * snd_soc_dapm_sync - scan and power dapm paths
1717 * @dapm: DAPM context
1719 * Walks all dapm audio paths and powers widgets according to their
1720 * stream or path usage.
1722 * Returns 0 for success.
1724 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
1726 return dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1728 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1730 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
1731 const struct snd_soc_dapm_route
*route
)
1733 struct snd_soc_dapm_path
*path
;
1734 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1735 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
1737 const char *control
= route
->control
;
1739 char prefixed_sink
[80];
1740 char prefixed_source
[80];
1743 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
1744 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
1745 dapm
->codec
->name_prefix
, route
->sink
);
1746 sink
= prefixed_sink
;
1747 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
1748 dapm
->codec
->name_prefix
, route
->source
);
1749 source
= prefixed_source
;
1752 source
= route
->source
;
1756 * find src and dest widgets over all widgets but favor a widget from
1757 * current DAPM context
1759 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1760 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1762 if (w
->dapm
== dapm
)
1766 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1768 if (w
->dapm
== dapm
)
1772 /* use widget from another DAPM context if not found from this */
1778 if (wsource
== NULL
|| wsink
== NULL
)
1781 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1785 path
->source
= wsource
;
1787 path
->connected
= route
->connected
;
1788 INIT_LIST_HEAD(&path
->list
);
1789 INIT_LIST_HEAD(&path
->list_source
);
1790 INIT_LIST_HEAD(&path
->list_sink
);
1792 /* check for external widgets */
1793 if (wsink
->id
== snd_soc_dapm_input
) {
1794 if (wsource
->id
== snd_soc_dapm_micbias
||
1795 wsource
->id
== snd_soc_dapm_mic
||
1796 wsource
->id
== snd_soc_dapm_line
||
1797 wsource
->id
== snd_soc_dapm_output
)
1800 if (wsource
->id
== snd_soc_dapm_output
) {
1801 if (wsink
->id
== snd_soc_dapm_spk
||
1802 wsink
->id
== snd_soc_dapm_hp
||
1803 wsink
->id
== snd_soc_dapm_line
||
1804 wsink
->id
== snd_soc_dapm_input
)
1808 /* connect static paths */
1809 if (control
== NULL
) {
1810 list_add(&path
->list
, &dapm
->card
->paths
);
1811 list_add(&path
->list_sink
, &wsink
->sources
);
1812 list_add(&path
->list_source
, &wsource
->sinks
);
1817 /* connect dynamic paths */
1818 switch (wsink
->id
) {
1819 case snd_soc_dapm_adc
:
1820 case snd_soc_dapm_dac
:
1821 case snd_soc_dapm_pga
:
1822 case snd_soc_dapm_out_drv
:
1823 case snd_soc_dapm_input
:
1824 case snd_soc_dapm_output
:
1825 case snd_soc_dapm_micbias
:
1826 case snd_soc_dapm_vmid
:
1827 case snd_soc_dapm_pre
:
1828 case snd_soc_dapm_post
:
1829 case snd_soc_dapm_supply
:
1830 case snd_soc_dapm_aif_in
:
1831 case snd_soc_dapm_aif_out
:
1832 list_add(&path
->list
, &dapm
->card
->paths
);
1833 list_add(&path
->list_sink
, &wsink
->sources
);
1834 list_add(&path
->list_source
, &wsource
->sinks
);
1837 case snd_soc_dapm_mux
:
1838 case snd_soc_dapm_virt_mux
:
1839 case snd_soc_dapm_value_mux
:
1840 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
1841 &wsink
->kcontrol_news
[0]);
1845 case snd_soc_dapm_switch
:
1846 case snd_soc_dapm_mixer
:
1847 case snd_soc_dapm_mixer_named_ctl
:
1848 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
1852 case snd_soc_dapm_hp
:
1853 case snd_soc_dapm_mic
:
1854 case snd_soc_dapm_line
:
1855 case snd_soc_dapm_spk
:
1856 list_add(&path
->list
, &dapm
->card
->paths
);
1857 list_add(&path
->list_sink
, &wsink
->sources
);
1858 list_add(&path
->list_source
, &wsource
->sinks
);
1865 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
1866 source
, control
, sink
);
1872 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1873 * @dapm: DAPM context
1874 * @route: audio routes
1875 * @num: number of routes
1877 * Connects 2 dapm widgets together via a named audio path. The sink is
1878 * the widget receiving the audio signal, whilst the source is the sender
1879 * of the audio signal.
1881 * Returns 0 for success else error. On error all resources can be freed
1882 * with a call to snd_soc_card_free().
1884 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
1885 const struct snd_soc_dapm_route
*route
, int num
)
1889 for (i
= 0; i
< num
; i
++) {
1890 ret
= snd_soc_dapm_add_route(dapm
, route
);
1892 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
1893 route
->source
, route
->sink
);
1901 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1903 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
1904 const struct snd_soc_dapm_route
*route
)
1906 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
1909 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
1912 struct snd_soc_dapm_path
*path
;
1916 dev_err(dapm
->dev
, "Unable to find source %s for weak route\n",
1922 dev_err(dapm
->dev
, "Unable to find sink %s for weak route\n",
1927 if (route
->control
|| route
->connected
)
1928 dev_warn(dapm
->dev
, "Ignoring control for weak route %s->%s\n",
1929 route
->source
, route
->sink
);
1931 list_for_each_entry(path
, &source
->sinks
, list_source
) {
1932 if (path
->sink
== sink
) {
1939 dev_err(dapm
->dev
, "No path found for weak route %s->%s\n",
1940 route
->source
, route
->sink
);
1942 dev_warn(dapm
->dev
, "%d paths found for weak route %s->%s\n",
1943 count
, route
->source
, route
->sink
);
1949 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
1950 * @dapm: DAPM context
1951 * @route: audio routes
1952 * @num: number of routes
1954 * Mark existing routes matching those specified in the passed array
1955 * as being weak, meaning that they are ignored for the purpose of
1956 * power decisions. The main intended use case is for sidetone paths
1957 * which couple audio between other independent paths if they are both
1958 * active in order to make the combination work better at the user
1959 * level but which aren't intended to be "used".
1961 * Note that CODEC drivers should not use this as sidetone type paths
1962 * can frequently also be used as bypass paths.
1964 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
1965 const struct snd_soc_dapm_route
*route
, int num
)
1970 for (i
= 0; i
< num
; i
++) {
1971 err
= snd_soc_dapm_weak_route(dapm
, route
);
1979 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
1982 * snd_soc_dapm_new_widgets - add new dapm widgets
1983 * @dapm: DAPM context
1985 * Checks the codec for any new dapm widgets and creates them if found.
1987 * Returns 0 for success.
1989 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
1991 struct snd_soc_dapm_widget
*w
;
1994 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
1999 if (w
->num_kcontrols
) {
2000 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2001 sizeof(struct snd_kcontrol
*),
2008 case snd_soc_dapm_switch
:
2009 case snd_soc_dapm_mixer
:
2010 case snd_soc_dapm_mixer_named_ctl
:
2011 w
->power_check
= dapm_generic_check_power
;
2014 case snd_soc_dapm_mux
:
2015 case snd_soc_dapm_virt_mux
:
2016 case snd_soc_dapm_value_mux
:
2017 w
->power_check
= dapm_generic_check_power
;
2020 case snd_soc_dapm_adc
:
2021 case snd_soc_dapm_aif_out
:
2022 w
->power_check
= dapm_adc_check_power
;
2024 case snd_soc_dapm_dac
:
2025 case snd_soc_dapm_aif_in
:
2026 w
->power_check
= dapm_dac_check_power
;
2028 case snd_soc_dapm_pga
:
2029 case snd_soc_dapm_out_drv
:
2030 w
->power_check
= dapm_generic_check_power
;
2033 case snd_soc_dapm_input
:
2034 case snd_soc_dapm_output
:
2035 case snd_soc_dapm_micbias
:
2036 case snd_soc_dapm_spk
:
2037 case snd_soc_dapm_hp
:
2038 case snd_soc_dapm_mic
:
2039 case snd_soc_dapm_line
:
2040 w
->power_check
= dapm_generic_check_power
;
2042 case snd_soc_dapm_supply
:
2043 w
->power_check
= dapm_supply_check_power
;
2044 case snd_soc_dapm_vmid
:
2045 case snd_soc_dapm_pre
:
2046 case snd_soc_dapm_post
:
2050 /* Read the initial power state from the device */
2052 val
= soc_widget_read(w
, w
->reg
);
2053 val
&= 1 << w
->shift
;
2063 dapm_debugfs_add_widget(w
);
2066 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2069 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2072 * snd_soc_dapm_get_volsw - dapm mixer get callback
2073 * @kcontrol: mixer control
2074 * @ucontrol: control element information
2076 * Callback to get the value of a dapm mixer control.
2078 * Returns 0 for success.
2080 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2081 struct snd_ctl_elem_value
*ucontrol
)
2083 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2084 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2085 struct soc_mixer_control
*mc
=
2086 (struct soc_mixer_control
*)kcontrol
->private_value
;
2087 unsigned int reg
= mc
->reg
;
2088 unsigned int shift
= mc
->shift
;
2089 unsigned int rshift
= mc
->rshift
;
2091 unsigned int invert
= mc
->invert
;
2092 unsigned int mask
= (1 << fls(max
)) - 1;
2094 ucontrol
->value
.integer
.value
[0] =
2095 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
2096 if (shift
!= rshift
)
2097 ucontrol
->value
.integer
.value
[1] =
2098 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
2100 ucontrol
->value
.integer
.value
[0] =
2101 max
- ucontrol
->value
.integer
.value
[0];
2102 if (shift
!= rshift
)
2103 ucontrol
->value
.integer
.value
[1] =
2104 max
- ucontrol
->value
.integer
.value
[1];
2109 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2112 * snd_soc_dapm_put_volsw - dapm mixer set callback
2113 * @kcontrol: mixer control
2114 * @ucontrol: control element information
2116 * Callback to set the value of a dapm mixer control.
2118 * Returns 0 for success.
2120 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2121 struct snd_ctl_elem_value
*ucontrol
)
2123 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2124 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2125 struct snd_soc_codec
*codec
= widget
->codec
;
2126 struct soc_mixer_control
*mc
=
2127 (struct soc_mixer_control
*)kcontrol
->private_value
;
2128 unsigned int reg
= mc
->reg
;
2129 unsigned int shift
= mc
->shift
;
2131 unsigned int mask
= (1 << fls(max
)) - 1;
2132 unsigned int invert
= mc
->invert
;
2134 int connect
, change
;
2135 struct snd_soc_dapm_update update
;
2138 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2142 mask
= mask
<< shift
;
2146 /* new connection */
2147 connect
= invert
? 0 : 1;
2149 /* old connection must be powered down */
2150 connect
= invert
? 1 : 0;
2152 mutex_lock(&codec
->mutex
);
2154 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
2156 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2157 widget
= wlist
->widgets
[wi
];
2159 widget
->value
= val
;
2161 update
.kcontrol
= kcontrol
;
2162 update
.widget
= widget
;
2166 widget
->dapm
->update
= &update
;
2168 dapm_mixer_update_power(widget
, kcontrol
, connect
);
2170 widget
->dapm
->update
= NULL
;
2174 mutex_unlock(&codec
->mutex
);
2177 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2180 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2181 * @kcontrol: mixer control
2182 * @ucontrol: control element information
2184 * Callback to get the value of a dapm enumerated double mixer control.
2186 * Returns 0 for success.
2188 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2189 struct snd_ctl_elem_value
*ucontrol
)
2191 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2192 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2193 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2194 unsigned int val
, bitmask
;
2196 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2198 val
= snd_soc_read(widget
->codec
, e
->reg
);
2199 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
2200 if (e
->shift_l
!= e
->shift_r
)
2201 ucontrol
->value
.enumerated
.item
[1] =
2202 (val
>> e
->shift_r
) & (bitmask
- 1);
2206 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2209 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2210 * @kcontrol: mixer control
2211 * @ucontrol: control element information
2213 * Callback to set the value of a dapm enumerated double mixer control.
2215 * Returns 0 for success.
2217 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2218 struct snd_ctl_elem_value
*ucontrol
)
2220 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2221 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2222 struct snd_soc_codec
*codec
= widget
->codec
;
2223 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2224 unsigned int val
, mux
, change
;
2225 unsigned int mask
, bitmask
;
2226 struct snd_soc_dapm_update update
;
2229 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2231 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2233 mux
= ucontrol
->value
.enumerated
.item
[0];
2234 val
= mux
<< e
->shift_l
;
2235 mask
= (bitmask
- 1) << e
->shift_l
;
2236 if (e
->shift_l
!= e
->shift_r
) {
2237 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2239 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2240 mask
|= (bitmask
- 1) << e
->shift_r
;
2243 mutex_lock(&codec
->mutex
);
2245 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2247 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2248 widget
= wlist
->widgets
[wi
];
2250 widget
->value
= val
;
2252 update
.kcontrol
= kcontrol
;
2253 update
.widget
= widget
;
2254 update
.reg
= e
->reg
;
2257 widget
->dapm
->update
= &update
;
2259 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2261 widget
->dapm
->update
= NULL
;
2265 mutex_unlock(&codec
->mutex
);
2268 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2271 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2272 * @kcontrol: mixer control
2273 * @ucontrol: control element information
2275 * Returns 0 for success.
2277 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2278 struct snd_ctl_elem_value
*ucontrol
)
2280 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2281 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2283 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2287 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2290 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2291 * @kcontrol: mixer control
2292 * @ucontrol: control element information
2294 * Returns 0 for success.
2296 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2297 struct snd_ctl_elem_value
*ucontrol
)
2299 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2300 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2301 struct snd_soc_codec
*codec
= widget
->codec
;
2302 struct soc_enum
*e
=
2303 (struct soc_enum
*)kcontrol
->private_value
;
2308 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2311 mutex_lock(&codec
->mutex
);
2313 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2315 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2316 widget
= wlist
->widgets
[wi
];
2318 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2320 dapm_mux_update_power(widget
, kcontrol
, change
,
2325 mutex_unlock(&codec
->mutex
);
2328 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2331 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2333 * @kcontrol: mixer control
2334 * @ucontrol: control element information
2336 * Callback to get the value of a dapm semi enumerated double mixer control.
2338 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2339 * used for handling bitfield coded enumeration for example.
2341 * Returns 0 for success.
2343 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2344 struct snd_ctl_elem_value
*ucontrol
)
2346 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2347 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2348 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2349 unsigned int reg_val
, val
, mux
;
2351 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2352 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2353 for (mux
= 0; mux
< e
->max
; mux
++) {
2354 if (val
== e
->values
[mux
])
2357 ucontrol
->value
.enumerated
.item
[0] = mux
;
2358 if (e
->shift_l
!= e
->shift_r
) {
2359 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2360 for (mux
= 0; mux
< e
->max
; mux
++) {
2361 if (val
== e
->values
[mux
])
2364 ucontrol
->value
.enumerated
.item
[1] = mux
;
2369 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2372 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2374 * @kcontrol: mixer control
2375 * @ucontrol: control element information
2377 * Callback to set the value of a dapm semi enumerated double mixer control.
2379 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2380 * used for handling bitfield coded enumeration for example.
2382 * Returns 0 for success.
2384 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2385 struct snd_ctl_elem_value
*ucontrol
)
2387 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2388 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2389 struct snd_soc_codec
*codec
= widget
->codec
;
2390 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2391 unsigned int val
, mux
, change
;
2393 struct snd_soc_dapm_update update
;
2396 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2398 mux
= ucontrol
->value
.enumerated
.item
[0];
2399 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2400 mask
= e
->mask
<< e
->shift_l
;
2401 if (e
->shift_l
!= e
->shift_r
) {
2402 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2404 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2405 mask
|= e
->mask
<< e
->shift_r
;
2408 mutex_lock(&codec
->mutex
);
2410 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2412 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2413 widget
= wlist
->widgets
[wi
];
2415 widget
->value
= val
;
2417 update
.kcontrol
= kcontrol
;
2418 update
.widget
= widget
;
2419 update
.reg
= e
->reg
;
2422 widget
->dapm
->update
= &update
;
2424 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2426 widget
->dapm
->update
= NULL
;
2430 mutex_unlock(&codec
->mutex
);
2433 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2436 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2438 * @kcontrol: mixer control
2439 * @uinfo: control element information
2441 * Callback to provide information about a pin switch control.
2443 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2444 struct snd_ctl_elem_info
*uinfo
)
2446 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2448 uinfo
->value
.integer
.min
= 0;
2449 uinfo
->value
.integer
.max
= 1;
2453 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2456 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2458 * @kcontrol: mixer control
2461 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2462 struct snd_ctl_elem_value
*ucontrol
)
2464 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2465 const char *pin
= (const char *)kcontrol
->private_value
;
2467 mutex_lock(&codec
->mutex
);
2469 ucontrol
->value
.integer
.value
[0] =
2470 snd_soc_dapm_get_pin_status(&codec
->dapm
, pin
);
2472 mutex_unlock(&codec
->mutex
);
2476 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2479 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2481 * @kcontrol: mixer control
2484 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2485 struct snd_ctl_elem_value
*ucontrol
)
2487 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2488 const char *pin
= (const char *)kcontrol
->private_value
;
2490 mutex_lock(&codec
->mutex
);
2492 if (ucontrol
->value
.integer
.value
[0])
2493 snd_soc_dapm_enable_pin(&codec
->dapm
, pin
);
2495 snd_soc_dapm_disable_pin(&codec
->dapm
, pin
);
2497 snd_soc_dapm_sync(&codec
->dapm
);
2499 mutex_unlock(&codec
->mutex
);
2503 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2506 * snd_soc_dapm_new_control - create new dapm control
2507 * @dapm: DAPM context
2508 * @widget: widget template
2510 * Creates a new dapm control based upon the template.
2512 * Returns 0 for success else error.
2514 int snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2515 const struct snd_soc_dapm_widget
*widget
)
2517 struct snd_soc_dapm_widget
*w
;
2520 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2523 name_len
= strlen(widget
->name
) + 1;
2524 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2525 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
2526 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
2527 if (w
->name
== NULL
) {
2531 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2532 snprintf(w
->name
, name_len
, "%s %s",
2533 dapm
->codec
->name_prefix
, widget
->name
);
2535 snprintf(w
->name
, name_len
, "%s", widget
->name
);
2539 w
->codec
= dapm
->codec
;
2540 w
->platform
= dapm
->platform
;
2541 INIT_LIST_HEAD(&w
->sources
);
2542 INIT_LIST_HEAD(&w
->sinks
);
2543 INIT_LIST_HEAD(&w
->list
);
2544 list_add(&w
->list
, &dapm
->card
->widgets
);
2546 /* machine layer set ups unconnected pins and insertions */
2550 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
2553 * snd_soc_dapm_new_controls - create new dapm controls
2554 * @dapm: DAPM context
2555 * @widget: widget array
2556 * @num: number of widgets
2558 * Creates new DAPM controls based upon the templates.
2560 * Returns 0 for success else error.
2562 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
2563 const struct snd_soc_dapm_widget
*widget
,
2568 for (i
= 0; i
< num
; i
++) {
2569 ret
= snd_soc_dapm_new_control(dapm
, widget
);
2572 "ASoC: Failed to create DAPM control %s: %d\n",
2580 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
2582 static void soc_dapm_stream_event(struct snd_soc_dapm_context
*dapm
,
2583 const char *stream
, int event
)
2585 struct snd_soc_dapm_widget
*w
;
2587 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2589 if (!w
->sname
|| w
->dapm
!= dapm
)
2591 dev_vdbg(w
->dapm
->dev
, "widget %s\n %s stream %s event %d\n",
2592 w
->name
, w
->sname
, stream
, event
);
2593 if (strstr(w
->sname
, stream
)) {
2595 case SND_SOC_DAPM_STREAM_START
:
2598 case SND_SOC_DAPM_STREAM_STOP
:
2601 case SND_SOC_DAPM_STREAM_SUSPEND
:
2602 case SND_SOC_DAPM_STREAM_RESUME
:
2603 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
2604 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
2610 dapm_power_widgets(dapm
, event
);
2612 /* do we need to notify any clients that DAPM stream is complete */
2613 if (dapm
->stream_event
)
2614 dapm
->stream_event(dapm
, event
);
2618 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2619 * @rtd: PCM runtime data
2620 * @stream: stream name
2621 * @event: stream event
2623 * Sends a stream event to the dapm core. The core then makes any
2624 * necessary widget power changes.
2626 * Returns 0 for success else error.
2628 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
,
2629 const char *stream
, int event
)
2631 struct snd_soc_codec
*codec
= rtd
->codec
;
2636 mutex_lock(&codec
->mutex
);
2637 soc_dapm_stream_event(&codec
->dapm
, stream
, event
);
2638 mutex_unlock(&codec
->mutex
);
2643 * snd_soc_dapm_enable_pin - enable pin.
2644 * @dapm: DAPM context
2647 * Enables input/output pin and its parents or children widgets iff there is
2648 * a valid audio route and active audio stream.
2649 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2650 * do any widget power switching.
2652 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2654 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
2656 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
2659 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2660 * @dapm: DAPM context
2663 * Enables input/output pin regardless of any other state. This is
2664 * intended for use with microphone bias supplies used in microphone
2667 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2668 * do any widget power switching.
2670 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
2673 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2676 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2680 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
2686 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
2689 * snd_soc_dapm_disable_pin - disable pin.
2690 * @dapm: DAPM context
2693 * Disables input/output pin and its parents or children widgets.
2694 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2695 * do any widget power switching.
2697 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
2700 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2702 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
2705 * snd_soc_dapm_nc_pin - permanently disable pin.
2706 * @dapm: DAPM context
2709 * Marks the specified pin as being not connected, disabling it along
2710 * any parent or child widgets. At present this is identical to
2711 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2712 * additional things such as disabling controls which only affect
2713 * paths through the pin.
2715 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2716 * do any widget power switching.
2718 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2720 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2722 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
2725 * snd_soc_dapm_get_pin_status - get audio pin status
2726 * @dapm: DAPM context
2727 * @pin: audio signal pin endpoint (or start point)
2729 * Get audio pin status - connected or disconnected.
2731 * Returns 1 for connected otherwise 0.
2733 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
2736 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2739 return w
->connected
;
2743 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
2746 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2747 * @dapm: DAPM context
2748 * @pin: audio signal pin endpoint (or start point)
2750 * Mark the given endpoint or pin as ignoring suspend. When the
2751 * system is disabled a path between two endpoints flagged as ignoring
2752 * suspend will not be disabled. The path must already be enabled via
2753 * normal means at suspend time, it will not be turned on if it was not
2756 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
2759 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
2762 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2766 w
->ignore_suspend
= 1;
2770 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
2773 * snd_soc_dapm_free - free dapm resources
2776 * Free all dapm widgets and resources.
2778 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
2780 snd_soc_dapm_sys_remove(dapm
->dev
);
2781 dapm_debugfs_cleanup(dapm
);
2782 dapm_free_widgets(dapm
);
2783 list_del(&dapm
->list
);
2785 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
2787 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
2789 struct snd_soc_dapm_widget
*w
;
2790 LIST_HEAD(down_list
);
2793 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2794 if (w
->dapm
!= dapm
)
2797 dapm_seq_insert(w
, &down_list
, false);
2803 /* If there were no widgets to power down we're already in
2807 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_PREPARE
);
2808 dapm_seq_run(dapm
, &down_list
, 0, false);
2809 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_STANDBY
);
2814 * snd_soc_dapm_shutdown - callback for system shutdown
2816 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
2818 struct snd_soc_codec
*codec
;
2820 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
2821 soc_dapm_shutdown_codec(&codec
->dapm
);
2822 snd_soc_dapm_set_bias_level(&codec
->dapm
, SND_SOC_BIAS_OFF
);
2826 /* Module information */
2827 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2828 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2829 MODULE_LICENSE("GPL");