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
);
128 * snd_soc_dapm_set_bias_level - set the bias level for the system
129 * @dapm: DAPM context
130 * @level: level to configure
132 * Configure the bias (power) levels for the SoC audio device.
134 * Returns 0 for success else error.
136 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
137 enum snd_soc_bias_level level
)
139 struct snd_soc_card
*card
= dapm
->card
;
142 trace_snd_soc_bias_level_start(card
, level
);
144 if (card
&& card
->set_bias_level
)
145 ret
= card
->set_bias_level(card
, dapm
, level
);
149 if (dapm
->codec
&& dapm
->codec
->driver
->set_bias_level
)
150 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
, level
);
152 dapm
->bias_level
= level
;
156 if (card
&& card
->set_bias_level_post
)
157 ret
= card
->set_bias_level_post(card
, dapm
, level
);
159 trace_snd_soc_bias_level_done(card
, level
);
164 /* set up initial codec paths */
165 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
166 struct snd_soc_dapm_path
*p
, int i
)
169 case snd_soc_dapm_switch
:
170 case snd_soc_dapm_mixer
:
171 case snd_soc_dapm_mixer_named_ctl
: {
173 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
174 w
->kcontrol_news
[i
].private_value
;
175 unsigned int reg
= mc
->reg
;
176 unsigned int shift
= mc
->shift
;
178 unsigned int mask
= (1 << fls(max
)) - 1;
179 unsigned int invert
= mc
->invert
;
181 val
= snd_soc_read(w
->codec
, reg
);
182 val
= (val
>> shift
) & mask
;
184 if ((invert
&& !val
) || (!invert
&& val
))
190 case snd_soc_dapm_mux
: {
191 struct soc_enum
*e
= (struct soc_enum
*)
192 w
->kcontrol_news
[i
].private_value
;
193 int val
, item
, bitmask
;
195 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
197 val
= snd_soc_read(w
->codec
, e
->reg
);
198 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
201 for (i
= 0; i
< e
->max
; i
++) {
202 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
207 case snd_soc_dapm_virt_mux
: {
208 struct soc_enum
*e
= (struct soc_enum
*)
209 w
->kcontrol_news
[i
].private_value
;
212 /* since a virtual mux has no backing registers to
213 * decide which path to connect, it will try to match
214 * with the first enumeration. This is to ensure
215 * that the default mux choice (the first) will be
216 * correctly powered up during initialization.
218 if (!strcmp(p
->name
, e
->texts
[0]))
222 case snd_soc_dapm_value_mux
: {
223 struct soc_enum
*e
= (struct soc_enum
*)
224 w
->kcontrol_news
[i
].private_value
;
227 val
= snd_soc_read(w
->codec
, e
->reg
);
228 val
= (val
>> e
->shift_l
) & e
->mask
;
229 for (item
= 0; item
< e
->max
; item
++) {
230 if (val
== e
->values
[item
])
235 for (i
= 0; i
< e
->max
; i
++) {
236 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
241 /* does not effect routing - always connected */
242 case snd_soc_dapm_pga
:
243 case snd_soc_dapm_out_drv
:
244 case snd_soc_dapm_output
:
245 case snd_soc_dapm_adc
:
246 case snd_soc_dapm_input
:
247 case snd_soc_dapm_dac
:
248 case snd_soc_dapm_micbias
:
249 case snd_soc_dapm_vmid
:
250 case snd_soc_dapm_supply
:
251 case snd_soc_dapm_aif_in
:
252 case snd_soc_dapm_aif_out
:
255 /* does effect routing - dynamically connected */
256 case snd_soc_dapm_hp
:
257 case snd_soc_dapm_mic
:
258 case snd_soc_dapm_spk
:
259 case snd_soc_dapm_line
:
260 case snd_soc_dapm_pre
:
261 case snd_soc_dapm_post
:
267 /* connect mux widget to its interconnecting audio paths */
268 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
269 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
270 struct snd_soc_dapm_path
*path
, const char *control_name
,
271 const struct snd_kcontrol_new
*kcontrol
)
273 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
276 for (i
= 0; i
< e
->max
; i
++) {
277 if (!(strcmp(control_name
, e
->texts
[i
]))) {
278 list_add(&path
->list
, &dapm
->card
->paths
);
279 list_add(&path
->list_sink
, &dest
->sources
);
280 list_add(&path
->list_source
, &src
->sinks
);
281 path
->name
= (char*)e
->texts
[i
];
282 dapm_set_path_status(dest
, path
, 0);
290 /* connect mixer widget to its interconnecting audio paths */
291 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
292 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
293 struct snd_soc_dapm_path
*path
, const char *control_name
)
297 /* search for mixer kcontrol */
298 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
299 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
300 list_add(&path
->list
, &dapm
->card
->paths
);
301 list_add(&path
->list_sink
, &dest
->sources
);
302 list_add(&path
->list_source
, &src
->sinks
);
303 path
->name
= dest
->kcontrol_news
[i
].name
;
304 dapm_set_path_status(dest
, path
, i
);
311 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
312 struct snd_soc_dapm_widget
*kcontrolw
,
313 const struct snd_kcontrol_new
*kcontrol_new
,
314 struct snd_kcontrol
**kcontrol
)
316 struct snd_soc_dapm_widget
*w
;
321 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
322 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
324 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
325 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
327 *kcontrol
= w
->kcontrols
[i
];
336 /* create new dapm mixer control */
337 static int dapm_new_mixer(struct snd_soc_dapm_context
*dapm
,
338 struct snd_soc_dapm_widget
*w
)
341 size_t name_len
, prefix_len
;
342 struct snd_soc_dapm_path
*path
;
343 struct snd_card
*card
= dapm
->card
->snd_card
;
345 struct snd_soc_dapm_widget_list
*wlist
;
349 prefix
= dapm
->codec
->name_prefix
;
354 prefix_len
= strlen(prefix
) + 1;
359 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
362 list_for_each_entry(path
, &w
->sources
, list_sink
) {
364 /* mixer/mux paths name must match control name */
365 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
368 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
369 sizeof(struct snd_soc_dapm_widget
*),
370 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
373 "asoc: can't allocate widget list for %s\n",
377 wlist
->num_widgets
= 1;
378 wlist
->widgets
[0] = w
;
380 /* add dapm control with long name.
381 * for dapm_mixer this is the concatenation of the
382 * mixer and kcontrol name.
383 * for dapm_mixer_named_ctl this is simply the
386 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
387 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
388 name_len
+= 1 + strlen(w
->name
);
390 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
392 if (path
->long_name
== NULL
) {
399 /* The control will get a prefix from
400 * the control creation process but
401 * we're also using the same prefix
402 * for widgets so cut the prefix off
403 * the front of the widget name.
405 snprintf(path
->long_name
, name_len
, "%s %s",
406 w
->name
+ prefix_len
,
407 w
->kcontrol_news
[i
].name
);
409 case snd_soc_dapm_mixer_named_ctl
:
410 snprintf(path
->long_name
, name_len
, "%s",
411 w
->kcontrol_news
[i
].name
);
415 path
->long_name
[name_len
- 1] = '\0';
417 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
418 wlist
, path
->long_name
,
420 ret
= snd_ctl_add(card
, path
->kcontrol
);
423 "asoc: failed to add dapm kcontrol %s: %d\n",
424 path
->long_name
, ret
);
426 kfree(path
->long_name
);
427 path
->long_name
= NULL
;
430 w
->kcontrols
[i
] = path
->kcontrol
;
436 /* create new dapm mux control */
437 static int dapm_new_mux(struct snd_soc_dapm_context
*dapm
,
438 struct snd_soc_dapm_widget
*w
)
440 struct snd_soc_dapm_path
*path
= NULL
;
441 struct snd_kcontrol
*kcontrol
;
442 struct snd_card
*card
= dapm
->card
->snd_card
;
446 struct snd_soc_dapm_widget_list
*wlist
;
447 int shared
, wlistentries
;
451 if (w
->num_kcontrols
!= 1) {
453 "asoc: mux %s has incorrect number of controls\n",
458 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[0],
461 wlist
= kcontrol
->private_data
;
462 wlistentries
= wlist
->num_widgets
+ 1;
467 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
468 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
469 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
472 "asoc: can't allocate widget list for %s\n", w
->name
);
475 wlist
->num_widgets
= wlistentries
;
476 wlist
->widgets
[wlistentries
- 1] = w
;
480 prefix
= dapm
->codec
->name_prefix
;
485 name
= w
->kcontrol_news
[0].name
;
490 prefix_len
= strlen(prefix
) + 1;
496 * The control will get a prefix from the control creation
497 * process but we're also using the same prefix for widgets so
498 * cut the prefix off the front of the widget name.
500 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
501 name
+ prefix_len
, prefix
);
502 ret
= snd_ctl_add(card
, kcontrol
);
505 "asoc: failed to add kcontrol %s\n", w
->name
);
511 kcontrol
->private_data
= wlist
;
513 w
->kcontrols
[0] = kcontrol
;
515 list_for_each_entry(path
, &w
->sources
, list_sink
)
516 path
->kcontrol
= kcontrol
;
521 /* create new dapm volume control */
522 static int dapm_new_pga(struct snd_soc_dapm_context
*dapm
,
523 struct snd_soc_dapm_widget
*w
)
525 if (w
->num_kcontrols
)
526 dev_err(w
->dapm
->dev
,
527 "asoc: PGA controls not supported: '%s'\n", w
->name
);
532 /* reset 'walked' bit for each dapm path */
533 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
535 struct snd_soc_dapm_path
*p
;
537 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
541 /* We implement power down on suspend by checking the power state of
542 * the ALSA card - when we are suspending the ALSA state for the card
545 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
547 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
550 case SNDRV_CTL_POWER_D3hot
:
551 case SNDRV_CTL_POWER_D3cold
:
552 if (widget
->ignore_suspend
)
553 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
555 return widget
->ignore_suspend
;
562 * Recursively check for a completed path to an active or physically connected
563 * output widget. Returns number of complete paths.
565 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
567 struct snd_soc_dapm_path
*path
;
570 if (widget
->id
== snd_soc_dapm_supply
)
573 switch (widget
->id
) {
574 case snd_soc_dapm_adc
:
575 case snd_soc_dapm_aif_out
:
577 return snd_soc_dapm_suspend_check(widget
);
582 if (widget
->connected
) {
583 /* connected pin ? */
584 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
585 return snd_soc_dapm_suspend_check(widget
);
587 /* connected jack or spk ? */
588 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
589 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sources
)))
590 return snd_soc_dapm_suspend_check(widget
);
593 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
597 if (path
->sink
&& path
->connect
) {
599 con
+= is_connected_output_ep(path
->sink
);
607 * Recursively check for a completed path to an active or physically connected
608 * input widget. Returns number of complete paths.
610 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
612 struct snd_soc_dapm_path
*path
;
615 if (widget
->id
== snd_soc_dapm_supply
)
618 /* active stream ? */
619 switch (widget
->id
) {
620 case snd_soc_dapm_dac
:
621 case snd_soc_dapm_aif_in
:
623 return snd_soc_dapm_suspend_check(widget
);
628 if (widget
->connected
) {
629 /* connected pin ? */
630 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
631 return snd_soc_dapm_suspend_check(widget
);
633 /* connected VMID/Bias for lower pops */
634 if (widget
->id
== snd_soc_dapm_vmid
)
635 return snd_soc_dapm_suspend_check(widget
);
637 /* connected jack ? */
638 if (widget
->id
== snd_soc_dapm_mic
||
639 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sinks
)))
640 return snd_soc_dapm_suspend_check(widget
);
643 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
647 if (path
->source
&& path
->connect
) {
649 con
+= is_connected_input_ep(path
->source
);
657 * Handler for generic register modifier widget.
659 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
660 struct snd_kcontrol
*kcontrol
, int event
)
664 if (SND_SOC_DAPM_EVENT_ON(event
))
669 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
670 w
->mask
<< w
->shift
, val
<< w
->shift
);
674 EXPORT_SYMBOL_GPL(dapm_reg_event
);
676 /* Generic check to see if a widget should be powered.
678 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
682 in
= is_connected_input_ep(w
);
683 dapm_clear_walk(w
->dapm
);
684 out
= is_connected_output_ep(w
);
685 dapm_clear_walk(w
->dapm
);
686 return out
!= 0 && in
!= 0;
689 /* Check to see if an ADC has power */
690 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
695 in
= is_connected_input_ep(w
);
696 dapm_clear_walk(w
->dapm
);
699 return dapm_generic_check_power(w
);
703 /* Check to see if a DAC has power */
704 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
709 out
= is_connected_output_ep(w
);
710 dapm_clear_walk(w
->dapm
);
713 return dapm_generic_check_power(w
);
717 /* Check to see if a power supply is needed */
718 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
720 struct snd_soc_dapm_path
*path
;
723 /* Check if one of our outputs is connected */
724 list_for_each_entry(path
, &w
->sinks
, list_source
) {
725 if (path
->connected
&&
726 !path
->connected(path
->source
, path
->sink
))
732 if (path
->sink
->force
) {
737 if (path
->sink
->power_check
&&
738 path
->sink
->power_check(path
->sink
)) {
744 dapm_clear_walk(w
->dapm
);
749 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
750 struct snd_soc_dapm_widget
*b
,
758 sort
= dapm_down_seq
;
760 if (sort
[a
->id
] != sort
[b
->id
])
761 return sort
[a
->id
] - sort
[b
->id
];
762 if (a
->subseq
!= b
->subseq
) {
764 return a
->subseq
- b
->subseq
;
766 return b
->subseq
- a
->subseq
;
768 if (a
->reg
!= b
->reg
)
769 return a
->reg
- b
->reg
;
770 if (a
->dapm
!= b
->dapm
)
771 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
776 /* Insert a widget in order into a DAPM power sequence. */
777 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
778 struct list_head
*list
,
781 struct snd_soc_dapm_widget
*w
;
783 list_for_each_entry(w
, list
, power_list
)
784 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
785 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
789 list_add_tail(&new_widget
->power_list
, list
);
792 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
793 struct snd_soc_dapm_widget
*w
, int event
)
795 struct snd_soc_card
*card
= dapm
->card
;
800 case SND_SOC_DAPM_PRE_PMU
:
804 case SND_SOC_DAPM_POST_PMU
:
805 ev_name
= "POST_PMU";
808 case SND_SOC_DAPM_PRE_PMD
:
812 case SND_SOC_DAPM_POST_PMD
:
813 ev_name
= "POST_PMD";
821 if (w
->power
!= power
)
824 if (w
->event
&& (w
->event_flags
& event
)) {
825 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
827 trace_snd_soc_dapm_widget_event_start(w
, event
);
828 ret
= w
->event(w
, NULL
, event
);
829 trace_snd_soc_dapm_widget_event_done(w
, event
);
831 pr_err("%s: %s event failed: %d\n",
832 ev_name
, w
->name
, ret
);
836 /* Apply the coalesced changes from a DAPM sequence */
837 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
838 struct list_head
*pending
)
840 struct snd_soc_card
*card
= dapm
->card
;
841 struct snd_soc_dapm_widget
*w
;
843 unsigned int value
= 0;
844 unsigned int mask
= 0;
845 unsigned int cur_mask
;
847 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
850 list_for_each_entry(w
, pending
, power_list
) {
851 cur_mask
= 1 << w
->shift
;
852 BUG_ON(reg
!= w
->reg
);
863 pop_dbg(dapm
->dev
, card
->pop_time
,
864 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
865 w
->name
, reg
, value
, mask
);
867 /* Check for events */
868 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
869 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
873 pop_dbg(dapm
->dev
, card
->pop_time
,
874 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
875 value
, mask
, reg
, card
->pop_time
);
876 pop_wait(card
->pop_time
);
877 snd_soc_update_bits(dapm
->codec
, reg
, mask
, value
);
880 list_for_each_entry(w
, pending
, power_list
) {
881 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
882 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
886 /* Apply a DAPM power sequence.
888 * We walk over a pre-sorted list of widgets to apply power to. In
889 * order to minimise the number of writes to the device required
890 * multiple widgets will be updated in a single write where possible.
891 * Currently anything that requires more than a single write is not
894 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
895 struct list_head
*list
, int event
, bool power_up
)
897 struct snd_soc_dapm_widget
*w
, *n
;
901 int cur_reg
= SND_SOC_NOPM
;
902 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
909 sort
= dapm_down_seq
;
911 list_for_each_entry_safe(w
, n
, list
, power_list
) {
914 /* Do we need to apply any queued changes? */
915 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
916 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
917 if (!list_empty(&pending
))
918 dapm_seq_run_coalesced(cur_dapm
, &pending
);
920 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
921 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
922 if (sort
[i
] == cur_sort
)
923 cur_dapm
->seq_notifier(cur_dapm
,
928 INIT_LIST_HEAD(&pending
);
931 cur_reg
= SND_SOC_NOPM
;
936 case snd_soc_dapm_pre
:
938 list_for_each_entry_safe_continue(w
, n
, list
,
941 if (event
== SND_SOC_DAPM_STREAM_START
)
943 NULL
, SND_SOC_DAPM_PRE_PMU
);
944 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
946 NULL
, SND_SOC_DAPM_PRE_PMD
);
949 case snd_soc_dapm_post
:
951 list_for_each_entry_safe_continue(w
, n
, list
,
954 if (event
== SND_SOC_DAPM_STREAM_START
)
956 NULL
, SND_SOC_DAPM_POST_PMU
);
957 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
959 NULL
, SND_SOC_DAPM_POST_PMD
);
963 /* Queue it up for application */
964 cur_sort
= sort
[w
->id
];
965 cur_subseq
= w
->subseq
;
968 list_move(&w
->power_list
, &pending
);
973 dev_err(w
->dapm
->dev
,
974 "Failed to apply widget power: %d\n", ret
);
977 if (!list_empty(&pending
))
978 dapm_seq_run_coalesced(cur_dapm
, &pending
);
980 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
981 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
982 if (sort
[i
] == cur_sort
)
983 cur_dapm
->seq_notifier(cur_dapm
,
988 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
990 struct snd_soc_dapm_update
*update
= dapm
->update
;
991 struct snd_soc_dapm_widget
*w
;
1000 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1001 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1003 pr_err("%s DAPM pre-event failed: %d\n",
1007 ret
= snd_soc_update_bits(w
->codec
, update
->reg
, update
->mask
,
1010 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1013 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1014 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1016 pr_err("%s DAPM post-event failed: %d\n",
1021 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1022 * they're changing state.
1024 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1026 struct snd_soc_dapm_context
*d
= data
;
1029 /* If we're off and we're not supposed to be go into STANDBY */
1030 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1031 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1032 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1035 "Failed to turn on bias: %d\n", ret
);
1038 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1039 if (d
->bias_level
!= d
->target_bias_level
) {
1040 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1043 "Failed to prepare bias: %d\n", ret
);
1047 /* Async callback run prior to DAPM sequences - brings to their final
1050 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1052 struct snd_soc_dapm_context
*d
= data
;
1055 /* If we just powered the last thing off drop to standby bias */
1056 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1057 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1058 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1059 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1061 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1065 /* If we're in standby and can support bias off then do that */
1066 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1067 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1068 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1070 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1073 /* If we just powered up then move to active bias */
1074 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1075 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1076 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1078 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1084 * Scan each dapm widget for complete audio path.
1085 * A complete path is a route that has valid endpoints i.e.:-
1087 * o DAC to output pin.
1088 * o Input Pin to ADC.
1089 * o Input pin to Output pin (bypass, sidetone)
1090 * o DAC to ADC (loopback).
1092 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1094 struct snd_soc_card
*card
= dapm
->card
;
1095 struct snd_soc_dapm_widget
*w
;
1096 struct snd_soc_dapm_context
*d
;
1098 LIST_HEAD(down_list
);
1099 LIST_HEAD(async_domain
);
1100 enum snd_soc_bias_level bias
;
1103 trace_snd_soc_dapm_start(card
);
1105 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1106 if (d
->n_widgets
|| d
->codec
== NULL
) {
1107 if (d
->idle_bias_off
)
1108 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1110 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1114 /* Check which widgets we need to power and store them in
1115 * lists indicating if they should be powered up or down.
1117 list_for_each_entry(w
, &card
->widgets
, list
) {
1119 case snd_soc_dapm_pre
:
1120 dapm_seq_insert(w
, &down_list
, false);
1122 case snd_soc_dapm_post
:
1123 dapm_seq_insert(w
, &up_list
, true);
1127 if (!w
->power_check
)
1131 power
= w
->power_check(w
);
1138 /* Supplies and micbiases only bring
1139 * the context up to STANDBY as unless
1140 * something else is active and
1141 * passing audio they generally don't
1142 * require full power.
1145 case snd_soc_dapm_supply
:
1146 case snd_soc_dapm_micbias
:
1147 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1148 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1151 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1156 if (w
->power
== power
)
1159 trace_snd_soc_dapm_widget_power(w
, power
);
1162 dapm_seq_insert(w
, &up_list
, true);
1164 dapm_seq_insert(w
, &down_list
, false);
1171 /* If there are no DAPM widgets then try to figure out power from the
1174 if (!dapm
->n_widgets
) {
1176 case SND_SOC_DAPM_STREAM_START
:
1177 case SND_SOC_DAPM_STREAM_RESUME
:
1178 dapm
->target_bias_level
= SND_SOC_BIAS_ON
;
1180 case SND_SOC_DAPM_STREAM_STOP
:
1181 if (dapm
->codec
->active
)
1182 dapm
->target_bias_level
= SND_SOC_BIAS_ON
;
1184 dapm
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1186 case SND_SOC_DAPM_STREAM_SUSPEND
:
1187 dapm
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1189 case SND_SOC_DAPM_STREAM_NOP
:
1190 dapm
->target_bias_level
= dapm
->bias_level
;
1197 /* Force all contexts in the card to the same bias state */
1198 bias
= SND_SOC_BIAS_OFF
;
1199 list_for_each_entry(d
, &card
->dapm_list
, list
)
1200 if (d
->target_bias_level
> bias
)
1201 bias
= d
->target_bias_level
;
1202 list_for_each_entry(d
, &card
->dapm_list
, list
)
1203 d
->target_bias_level
= bias
;
1206 /* Run all the bias changes in parallel */
1207 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1208 async_schedule_domain(dapm_pre_sequence_async
, d
,
1210 async_synchronize_full_domain(&async_domain
);
1212 /* Power down widgets first; try to avoid amplifying pops. */
1213 dapm_seq_run(dapm
, &down_list
, event
, false);
1215 dapm_widget_update(dapm
);
1218 dapm_seq_run(dapm
, &up_list
, event
, true);
1220 /* Run all the bias changes in parallel */
1221 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1222 async_schedule_domain(dapm_post_sequence_async
, d
,
1224 async_synchronize_full_domain(&async_domain
);
1226 pop_dbg(dapm
->dev
, card
->pop_time
,
1227 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1228 pop_wait(card
->pop_time
);
1230 trace_snd_soc_dapm_done(card
);
1235 #ifdef CONFIG_DEBUG_FS
1236 static int dapm_widget_power_open_file(struct inode
*inode
, struct file
*file
)
1238 file
->private_data
= inode
->i_private
;
1242 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1243 char __user
*user_buf
,
1244 size_t count
, loff_t
*ppos
)
1246 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1250 struct snd_soc_dapm_path
*p
= NULL
;
1252 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1256 in
= is_connected_input_ep(w
);
1257 dapm_clear_walk(w
->dapm
);
1258 out
= is_connected_output_ep(w
);
1259 dapm_clear_walk(w
->dapm
);
1261 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s in %d out %d",
1262 w
->name
, w
->power
? "On" : "Off", in
, out
);
1265 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1266 " - R%d(0x%x) bit %d",
1267 w
->reg
, w
->reg
, w
->shift
);
1269 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1272 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1274 w
->active
? "active" : "inactive");
1276 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1277 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1281 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1282 " in \"%s\" \"%s\"\n",
1283 p
->name
? p
->name
: "static",
1286 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1287 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1291 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1292 " out \"%s\" \"%s\"\n",
1293 p
->name
? p
->name
: "static",
1297 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1303 static const struct file_operations dapm_widget_power_fops
= {
1304 .open
= dapm_widget_power_open_file
,
1305 .read
= dapm_widget_power_read_file
,
1306 .llseek
= default_llseek
,
1309 static int dapm_bias_open_file(struct inode
*inode
, struct file
*file
)
1311 file
->private_data
= inode
->i_private
;
1315 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1316 size_t count
, loff_t
*ppos
)
1318 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1321 switch (dapm
->bias_level
) {
1322 case SND_SOC_BIAS_ON
:
1325 case SND_SOC_BIAS_PREPARE
:
1326 level
= "Prepare\n";
1328 case SND_SOC_BIAS_STANDBY
:
1329 level
= "Standby\n";
1331 case SND_SOC_BIAS_OFF
:
1336 level
= "Unknown\n";
1340 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1344 static const struct file_operations dapm_bias_fops
= {
1345 .open
= dapm_bias_open_file
,
1346 .read
= dapm_bias_read_file
,
1347 .llseek
= default_llseek
,
1350 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1351 struct dentry
*parent
)
1355 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1357 if (!dapm
->debugfs_dapm
) {
1359 "Failed to create DAPM debugfs directory\n");
1363 d
= debugfs_create_file("bias_level", 0444,
1364 dapm
->debugfs_dapm
, dapm
,
1368 "ASoC: Failed to create bias level debugfs file\n");
1371 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1373 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1376 if (!dapm
->debugfs_dapm
|| !w
->name
)
1379 d
= debugfs_create_file(w
->name
, 0444,
1380 dapm
->debugfs_dapm
, w
,
1381 &dapm_widget_power_fops
);
1383 dev_warn(w
->dapm
->dev
,
1384 "ASoC: Failed to create %s debugfs file\n",
1388 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1390 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1394 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1395 struct dentry
*parent
)
1399 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1403 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1409 /* test and update the power status of a mux widget */
1410 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1411 struct snd_kcontrol
*kcontrol
, int change
,
1412 int mux
, struct soc_enum
*e
)
1414 struct snd_soc_dapm_path
*path
;
1417 if (widget
->id
!= snd_soc_dapm_mux
&&
1418 widget
->id
!= snd_soc_dapm_virt_mux
&&
1419 widget
->id
!= snd_soc_dapm_value_mux
)
1425 /* find dapm widget path assoc with kcontrol */
1426 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1427 if (path
->kcontrol
!= kcontrol
)
1430 if (!path
->name
|| !e
->texts
[mux
])
1434 /* we now need to match the string in the enum to the path */
1435 if (!(strcmp(path
->name
, e
->texts
[mux
])))
1436 path
->connect
= 1; /* new connection */
1438 path
->connect
= 0; /* old connection must be powered down */
1442 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1447 /* test and update the power status of a mixer or switch widget */
1448 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1449 struct snd_kcontrol
*kcontrol
, int connect
)
1451 struct snd_soc_dapm_path
*path
;
1454 if (widget
->id
!= snd_soc_dapm_mixer
&&
1455 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1456 widget
->id
!= snd_soc_dapm_switch
)
1459 /* find dapm widget path assoc with kcontrol */
1460 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1461 if (path
->kcontrol
!= kcontrol
)
1464 /* found, now check type */
1466 path
->connect
= connect
;
1471 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1476 /* show dapm widget status in sys fs */
1477 static ssize_t
dapm_widget_show(struct device
*dev
,
1478 struct device_attribute
*attr
, char *buf
)
1480 struct snd_soc_pcm_runtime
*rtd
=
1481 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
1482 struct snd_soc_codec
*codec
=rtd
->codec
;
1483 struct snd_soc_dapm_widget
*w
;
1485 char *state
= "not set";
1487 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1488 if (w
->dapm
!= &codec
->dapm
)
1491 /* only display widgets that burnm power */
1493 case snd_soc_dapm_hp
:
1494 case snd_soc_dapm_mic
:
1495 case snd_soc_dapm_spk
:
1496 case snd_soc_dapm_line
:
1497 case snd_soc_dapm_micbias
:
1498 case snd_soc_dapm_dac
:
1499 case snd_soc_dapm_adc
:
1500 case snd_soc_dapm_pga
:
1501 case snd_soc_dapm_out_drv
:
1502 case snd_soc_dapm_mixer
:
1503 case snd_soc_dapm_mixer_named_ctl
:
1504 case snd_soc_dapm_supply
:
1506 count
+= sprintf(buf
+ count
, "%s: %s\n",
1507 w
->name
, w
->power
? "On":"Off");
1514 switch (codec
->dapm
.bias_level
) {
1515 case SND_SOC_BIAS_ON
:
1518 case SND_SOC_BIAS_PREPARE
:
1521 case SND_SOC_BIAS_STANDBY
:
1524 case SND_SOC_BIAS_OFF
:
1528 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1533 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1535 int snd_soc_dapm_sys_add(struct device
*dev
)
1537 return device_create_file(dev
, &dev_attr_dapm_widget
);
1540 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1542 device_remove_file(dev
, &dev_attr_dapm_widget
);
1545 /* free all dapm widgets and resources */
1546 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
1548 struct snd_soc_dapm_widget
*w
, *next_w
;
1549 struct snd_soc_dapm_path
*p
, *next_p
;
1551 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
1552 if (w
->dapm
!= dapm
)
1556 * remove source and sink paths associated to this widget.
1557 * While removing the path, remove reference to it from both
1558 * source and sink widgets so that path is removed only once.
1560 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
1561 list_del(&p
->list_sink
);
1562 list_del(&p
->list_source
);
1564 kfree(p
->long_name
);
1567 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
1568 list_del(&p
->list_sink
);
1569 list_del(&p
->list_source
);
1571 kfree(p
->long_name
);
1574 kfree(w
->kcontrols
);
1580 static struct snd_soc_dapm_widget
*dapm_find_widget(
1581 struct snd_soc_dapm_context
*dapm
, const char *pin
,
1582 bool search_other_contexts
)
1584 struct snd_soc_dapm_widget
*w
;
1585 struct snd_soc_dapm_widget
*fallback
= NULL
;
1587 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1588 if (!strcmp(w
->name
, pin
)) {
1589 if (w
->dapm
== dapm
)
1596 if (search_other_contexts
)
1602 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
1603 const char *pin
, int status
)
1605 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
1608 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
1612 w
->connected
= status
;
1620 * snd_soc_dapm_sync - scan and power dapm paths
1621 * @dapm: DAPM context
1623 * Walks all dapm audio paths and powers widgets according to their
1624 * stream or path usage.
1626 * Returns 0 for success.
1628 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
1630 return dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1632 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1634 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
1635 const struct snd_soc_dapm_route
*route
)
1637 struct snd_soc_dapm_path
*path
;
1638 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1639 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
1641 const char *control
= route
->control
;
1643 char prefixed_sink
[80];
1644 char prefixed_source
[80];
1647 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
1648 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
1649 dapm
->codec
->name_prefix
, route
->sink
);
1650 sink
= prefixed_sink
;
1651 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
1652 dapm
->codec
->name_prefix
, route
->source
);
1653 source
= prefixed_source
;
1656 source
= route
->source
;
1660 * find src and dest widgets over all widgets but favor a widget from
1661 * current DAPM context
1663 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1664 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1666 if (w
->dapm
== dapm
)
1670 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1672 if (w
->dapm
== dapm
)
1676 /* use widget from another DAPM context if not found from this */
1682 if (wsource
== NULL
|| wsink
== NULL
)
1685 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1689 path
->source
= wsource
;
1691 path
->connected
= route
->connected
;
1692 INIT_LIST_HEAD(&path
->list
);
1693 INIT_LIST_HEAD(&path
->list_source
);
1694 INIT_LIST_HEAD(&path
->list_sink
);
1696 /* check for external widgets */
1697 if (wsink
->id
== snd_soc_dapm_input
) {
1698 if (wsource
->id
== snd_soc_dapm_micbias
||
1699 wsource
->id
== snd_soc_dapm_mic
||
1700 wsource
->id
== snd_soc_dapm_line
||
1701 wsource
->id
== snd_soc_dapm_output
)
1704 if (wsource
->id
== snd_soc_dapm_output
) {
1705 if (wsink
->id
== snd_soc_dapm_spk
||
1706 wsink
->id
== snd_soc_dapm_hp
||
1707 wsink
->id
== snd_soc_dapm_line
||
1708 wsink
->id
== snd_soc_dapm_input
)
1712 /* connect static paths */
1713 if (control
== NULL
) {
1714 list_add(&path
->list
, &dapm
->card
->paths
);
1715 list_add(&path
->list_sink
, &wsink
->sources
);
1716 list_add(&path
->list_source
, &wsource
->sinks
);
1721 /* connect dynamic paths */
1722 switch (wsink
->id
) {
1723 case snd_soc_dapm_adc
:
1724 case snd_soc_dapm_dac
:
1725 case snd_soc_dapm_pga
:
1726 case snd_soc_dapm_out_drv
:
1727 case snd_soc_dapm_input
:
1728 case snd_soc_dapm_output
:
1729 case snd_soc_dapm_micbias
:
1730 case snd_soc_dapm_vmid
:
1731 case snd_soc_dapm_pre
:
1732 case snd_soc_dapm_post
:
1733 case snd_soc_dapm_supply
:
1734 case snd_soc_dapm_aif_in
:
1735 case snd_soc_dapm_aif_out
:
1736 list_add(&path
->list
, &dapm
->card
->paths
);
1737 list_add(&path
->list_sink
, &wsink
->sources
);
1738 list_add(&path
->list_source
, &wsource
->sinks
);
1741 case snd_soc_dapm_mux
:
1742 case snd_soc_dapm_virt_mux
:
1743 case snd_soc_dapm_value_mux
:
1744 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
1745 &wsink
->kcontrol_news
[0]);
1749 case snd_soc_dapm_switch
:
1750 case snd_soc_dapm_mixer
:
1751 case snd_soc_dapm_mixer_named_ctl
:
1752 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
1756 case snd_soc_dapm_hp
:
1757 case snd_soc_dapm_mic
:
1758 case snd_soc_dapm_line
:
1759 case snd_soc_dapm_spk
:
1760 list_add(&path
->list
, &dapm
->card
->paths
);
1761 list_add(&path
->list_sink
, &wsink
->sources
);
1762 list_add(&path
->list_source
, &wsource
->sinks
);
1769 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
1770 source
, control
, sink
);
1776 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1777 * @dapm: DAPM context
1778 * @route: audio routes
1779 * @num: number of routes
1781 * Connects 2 dapm widgets together via a named audio path. The sink is
1782 * the widget receiving the audio signal, whilst the source is the sender
1783 * of the audio signal.
1785 * Returns 0 for success else error. On error all resources can be freed
1786 * with a call to snd_soc_card_free().
1788 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
1789 const struct snd_soc_dapm_route
*route
, int num
)
1793 for (i
= 0; i
< num
; i
++) {
1794 ret
= snd_soc_dapm_add_route(dapm
, route
);
1796 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
1797 route
->source
, route
->sink
);
1805 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1808 * snd_soc_dapm_new_widgets - add new dapm widgets
1809 * @dapm: DAPM context
1811 * Checks the codec for any new dapm widgets and creates them if found.
1813 * Returns 0 for success.
1815 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
1817 struct snd_soc_dapm_widget
*w
;
1820 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
1825 if (w
->num_kcontrols
) {
1826 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
1827 sizeof(struct snd_kcontrol
*),
1834 case snd_soc_dapm_switch
:
1835 case snd_soc_dapm_mixer
:
1836 case snd_soc_dapm_mixer_named_ctl
:
1837 w
->power_check
= dapm_generic_check_power
;
1838 dapm_new_mixer(dapm
, w
);
1840 case snd_soc_dapm_mux
:
1841 case snd_soc_dapm_virt_mux
:
1842 case snd_soc_dapm_value_mux
:
1843 w
->power_check
= dapm_generic_check_power
;
1844 dapm_new_mux(dapm
, w
);
1846 case snd_soc_dapm_adc
:
1847 case snd_soc_dapm_aif_out
:
1848 w
->power_check
= dapm_adc_check_power
;
1850 case snd_soc_dapm_dac
:
1851 case snd_soc_dapm_aif_in
:
1852 w
->power_check
= dapm_dac_check_power
;
1854 case snd_soc_dapm_pga
:
1855 case snd_soc_dapm_out_drv
:
1856 w
->power_check
= dapm_generic_check_power
;
1857 dapm_new_pga(dapm
, w
);
1859 case snd_soc_dapm_input
:
1860 case snd_soc_dapm_output
:
1861 case snd_soc_dapm_micbias
:
1862 case snd_soc_dapm_spk
:
1863 case snd_soc_dapm_hp
:
1864 case snd_soc_dapm_mic
:
1865 case snd_soc_dapm_line
:
1866 w
->power_check
= dapm_generic_check_power
;
1868 case snd_soc_dapm_supply
:
1869 w
->power_check
= dapm_supply_check_power
;
1870 case snd_soc_dapm_vmid
:
1871 case snd_soc_dapm_pre
:
1872 case snd_soc_dapm_post
:
1876 /* Read the initial power state from the device */
1878 val
= snd_soc_read(w
->codec
, w
->reg
);
1879 val
&= 1 << w
->shift
;
1889 dapm_debugfs_add_widget(w
);
1892 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1895 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1898 * snd_soc_dapm_get_volsw - dapm mixer get callback
1899 * @kcontrol: mixer control
1900 * @ucontrol: control element information
1902 * Callback to get the value of a dapm mixer control.
1904 * Returns 0 for success.
1906 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1907 struct snd_ctl_elem_value
*ucontrol
)
1909 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
1910 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
1911 struct soc_mixer_control
*mc
=
1912 (struct soc_mixer_control
*)kcontrol
->private_value
;
1913 unsigned int reg
= mc
->reg
;
1914 unsigned int shift
= mc
->shift
;
1915 unsigned int rshift
= mc
->rshift
;
1917 unsigned int invert
= mc
->invert
;
1918 unsigned int mask
= (1 << fls(max
)) - 1;
1920 ucontrol
->value
.integer
.value
[0] =
1921 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1922 if (shift
!= rshift
)
1923 ucontrol
->value
.integer
.value
[1] =
1924 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1926 ucontrol
->value
.integer
.value
[0] =
1927 max
- ucontrol
->value
.integer
.value
[0];
1928 if (shift
!= rshift
)
1929 ucontrol
->value
.integer
.value
[1] =
1930 max
- ucontrol
->value
.integer
.value
[1];
1935 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1938 * snd_soc_dapm_put_volsw - dapm mixer set callback
1939 * @kcontrol: mixer control
1940 * @ucontrol: control element information
1942 * Callback to set the value of a dapm mixer control.
1944 * Returns 0 for success.
1946 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1947 struct snd_ctl_elem_value
*ucontrol
)
1949 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
1950 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
1951 struct snd_soc_codec
*codec
= widget
->codec
;
1952 struct soc_mixer_control
*mc
=
1953 (struct soc_mixer_control
*)kcontrol
->private_value
;
1954 unsigned int reg
= mc
->reg
;
1955 unsigned int shift
= mc
->shift
;
1957 unsigned int mask
= (1 << fls(max
)) - 1;
1958 unsigned int invert
= mc
->invert
;
1960 int connect
, change
;
1961 struct snd_soc_dapm_update update
;
1964 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1968 mask
= mask
<< shift
;
1972 /* new connection */
1973 connect
= invert
? 0 : 1;
1975 /* old connection must be powered down */
1976 connect
= invert
? 1 : 0;
1978 mutex_lock(&codec
->mutex
);
1980 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
1982 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1983 widget
= wlist
->widgets
[wi
];
1985 widget
->value
= val
;
1987 update
.kcontrol
= kcontrol
;
1988 update
.widget
= widget
;
1992 widget
->dapm
->update
= &update
;
1994 dapm_mixer_update_power(widget
, kcontrol
, connect
);
1996 widget
->dapm
->update
= NULL
;
2000 mutex_unlock(&codec
->mutex
);
2003 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2006 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2007 * @kcontrol: mixer control
2008 * @ucontrol: control element information
2010 * Callback to get the value of a dapm enumerated double mixer control.
2012 * Returns 0 for success.
2014 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2015 struct snd_ctl_elem_value
*ucontrol
)
2017 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2018 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2019 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2020 unsigned int val
, bitmask
;
2022 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2024 val
= snd_soc_read(widget
->codec
, e
->reg
);
2025 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
2026 if (e
->shift_l
!= e
->shift_r
)
2027 ucontrol
->value
.enumerated
.item
[1] =
2028 (val
>> e
->shift_r
) & (bitmask
- 1);
2032 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2035 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2036 * @kcontrol: mixer control
2037 * @ucontrol: control element information
2039 * Callback to set the value of a dapm enumerated double mixer control.
2041 * Returns 0 for success.
2043 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2044 struct snd_ctl_elem_value
*ucontrol
)
2046 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2047 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2048 struct snd_soc_codec
*codec
= widget
->codec
;
2049 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2050 unsigned int val
, mux
, change
;
2051 unsigned int mask
, bitmask
;
2052 struct snd_soc_dapm_update update
;
2055 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2057 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2059 mux
= ucontrol
->value
.enumerated
.item
[0];
2060 val
= mux
<< e
->shift_l
;
2061 mask
= (bitmask
- 1) << e
->shift_l
;
2062 if (e
->shift_l
!= e
->shift_r
) {
2063 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2065 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2066 mask
|= (bitmask
- 1) << e
->shift_r
;
2069 mutex_lock(&codec
->mutex
);
2071 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2073 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2074 widget
= wlist
->widgets
[wi
];
2076 widget
->value
= val
;
2078 update
.kcontrol
= kcontrol
;
2079 update
.widget
= widget
;
2080 update
.reg
= e
->reg
;
2083 widget
->dapm
->update
= &update
;
2085 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2087 widget
->dapm
->update
= NULL
;
2091 mutex_unlock(&codec
->mutex
);
2094 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2097 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2098 * @kcontrol: mixer control
2099 * @ucontrol: control element information
2101 * Returns 0 for success.
2103 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2104 struct snd_ctl_elem_value
*ucontrol
)
2106 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2107 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2109 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2113 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2116 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2117 * @kcontrol: mixer control
2118 * @ucontrol: control element information
2120 * Returns 0 for success.
2122 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2123 struct snd_ctl_elem_value
*ucontrol
)
2125 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2126 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2127 struct snd_soc_codec
*codec
= widget
->codec
;
2128 struct soc_enum
*e
=
2129 (struct soc_enum
*)kcontrol
->private_value
;
2134 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2137 mutex_lock(&codec
->mutex
);
2139 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2141 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2142 widget
= wlist
->widgets
[wi
];
2144 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2146 dapm_mux_update_power(widget
, kcontrol
, change
,
2151 mutex_unlock(&codec
->mutex
);
2154 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2157 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2159 * @kcontrol: mixer control
2160 * @ucontrol: control element information
2162 * Callback to get the value of a dapm semi enumerated double mixer control.
2164 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2165 * used for handling bitfield coded enumeration for example.
2167 * Returns 0 for success.
2169 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2170 struct snd_ctl_elem_value
*ucontrol
)
2172 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2173 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2174 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2175 unsigned int reg_val
, val
, mux
;
2177 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2178 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2179 for (mux
= 0; mux
< e
->max
; mux
++) {
2180 if (val
== e
->values
[mux
])
2183 ucontrol
->value
.enumerated
.item
[0] = mux
;
2184 if (e
->shift_l
!= e
->shift_r
) {
2185 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2186 for (mux
= 0; mux
< e
->max
; mux
++) {
2187 if (val
== e
->values
[mux
])
2190 ucontrol
->value
.enumerated
.item
[1] = mux
;
2195 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2198 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2200 * @kcontrol: mixer control
2201 * @ucontrol: control element information
2203 * Callback to set the value of a dapm semi enumerated double mixer control.
2205 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2206 * used for handling bitfield coded enumeration for example.
2208 * Returns 0 for success.
2210 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2211 struct snd_ctl_elem_value
*ucontrol
)
2213 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2214 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2215 struct snd_soc_codec
*codec
= widget
->codec
;
2216 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2217 unsigned int val
, mux
, change
;
2219 struct snd_soc_dapm_update update
;
2222 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2224 mux
= ucontrol
->value
.enumerated
.item
[0];
2225 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2226 mask
= e
->mask
<< e
->shift_l
;
2227 if (e
->shift_l
!= e
->shift_r
) {
2228 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2230 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2231 mask
|= e
->mask
<< e
->shift_r
;
2234 mutex_lock(&codec
->mutex
);
2236 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2238 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2239 widget
= wlist
->widgets
[wi
];
2241 widget
->value
= val
;
2243 update
.kcontrol
= kcontrol
;
2244 update
.widget
= widget
;
2245 update
.reg
= e
->reg
;
2248 widget
->dapm
->update
= &update
;
2250 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2252 widget
->dapm
->update
= NULL
;
2256 mutex_unlock(&codec
->mutex
);
2259 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2262 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2264 * @kcontrol: mixer control
2265 * @uinfo: control element information
2267 * Callback to provide information about a pin switch control.
2269 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2270 struct snd_ctl_elem_info
*uinfo
)
2272 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2274 uinfo
->value
.integer
.min
= 0;
2275 uinfo
->value
.integer
.max
= 1;
2279 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2282 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2284 * @kcontrol: mixer control
2287 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2288 struct snd_ctl_elem_value
*ucontrol
)
2290 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2291 const char *pin
= (const char *)kcontrol
->private_value
;
2293 mutex_lock(&codec
->mutex
);
2295 ucontrol
->value
.integer
.value
[0] =
2296 snd_soc_dapm_get_pin_status(&codec
->dapm
, pin
);
2298 mutex_unlock(&codec
->mutex
);
2302 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2305 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2307 * @kcontrol: mixer control
2310 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2311 struct snd_ctl_elem_value
*ucontrol
)
2313 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2314 const char *pin
= (const char *)kcontrol
->private_value
;
2316 mutex_lock(&codec
->mutex
);
2318 if (ucontrol
->value
.integer
.value
[0])
2319 snd_soc_dapm_enable_pin(&codec
->dapm
, pin
);
2321 snd_soc_dapm_disable_pin(&codec
->dapm
, pin
);
2323 snd_soc_dapm_sync(&codec
->dapm
);
2325 mutex_unlock(&codec
->mutex
);
2329 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2332 * snd_soc_dapm_new_control - create new dapm control
2333 * @dapm: DAPM context
2334 * @widget: widget template
2336 * Creates a new dapm control based upon the template.
2338 * Returns 0 for success else error.
2340 int snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2341 const struct snd_soc_dapm_widget
*widget
)
2343 struct snd_soc_dapm_widget
*w
;
2346 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2349 name_len
= strlen(widget
->name
) + 1;
2350 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2351 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
2352 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
2353 if (w
->name
== NULL
) {
2357 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2358 snprintf(w
->name
, name_len
, "%s %s",
2359 dapm
->codec
->name_prefix
, widget
->name
);
2361 snprintf(w
->name
, name_len
, "%s", widget
->name
);
2365 w
->codec
= dapm
->codec
;
2366 INIT_LIST_HEAD(&w
->sources
);
2367 INIT_LIST_HEAD(&w
->sinks
);
2368 INIT_LIST_HEAD(&w
->list
);
2369 list_add(&w
->list
, &dapm
->card
->widgets
);
2371 /* machine layer set ups unconnected pins and insertions */
2375 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
2378 * snd_soc_dapm_new_controls - create new dapm controls
2379 * @dapm: DAPM context
2380 * @widget: widget array
2381 * @num: number of widgets
2383 * Creates new DAPM controls based upon the templates.
2385 * Returns 0 for success else error.
2387 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
2388 const struct snd_soc_dapm_widget
*widget
,
2393 for (i
= 0; i
< num
; i
++) {
2394 ret
= snd_soc_dapm_new_control(dapm
, widget
);
2397 "ASoC: Failed to create DAPM control %s: %d\n",
2405 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
2407 static void soc_dapm_stream_event(struct snd_soc_dapm_context
*dapm
,
2408 const char *stream
, int event
)
2410 struct snd_soc_dapm_widget
*w
;
2412 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2414 if (!w
->sname
|| w
->dapm
!= dapm
)
2416 dev_dbg(w
->dapm
->dev
, "widget %s\n %s stream %s event %d\n",
2417 w
->name
, w
->sname
, stream
, event
);
2418 if (strstr(w
->sname
, stream
)) {
2420 case SND_SOC_DAPM_STREAM_START
:
2423 case SND_SOC_DAPM_STREAM_STOP
:
2426 case SND_SOC_DAPM_STREAM_SUSPEND
:
2427 case SND_SOC_DAPM_STREAM_RESUME
:
2428 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
2429 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
2435 dapm_power_widgets(dapm
, event
);
2439 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2440 * @rtd: PCM runtime data
2441 * @stream: stream name
2442 * @event: stream event
2444 * Sends a stream event to the dapm core. The core then makes any
2445 * necessary widget power changes.
2447 * Returns 0 for success else error.
2449 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
,
2450 const char *stream
, int event
)
2452 struct snd_soc_codec
*codec
= rtd
->codec
;
2457 mutex_lock(&codec
->mutex
);
2458 soc_dapm_stream_event(&codec
->dapm
, stream
, event
);
2459 mutex_unlock(&codec
->mutex
);
2464 * snd_soc_dapm_enable_pin - enable pin.
2465 * @dapm: DAPM context
2468 * Enables input/output pin and its parents or children widgets iff there is
2469 * a valid audio route and active audio stream.
2470 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2471 * do any widget power switching.
2473 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2475 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
2477 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
2480 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2481 * @dapm: DAPM context
2484 * Enables input/output pin regardless of any other state. This is
2485 * intended for use with microphone bias supplies used in microphone
2488 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2489 * do any widget power switching.
2491 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
2494 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2497 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2501 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
2507 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
2510 * snd_soc_dapm_disable_pin - disable pin.
2511 * @dapm: DAPM context
2514 * Disables input/output pin and its parents or children widgets.
2515 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2516 * do any widget power switching.
2518 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
2521 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2523 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
2526 * snd_soc_dapm_nc_pin - permanently disable pin.
2527 * @dapm: DAPM context
2530 * Marks the specified pin as being not connected, disabling it along
2531 * any parent or child widgets. At present this is identical to
2532 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2533 * additional things such as disabling controls which only affect
2534 * paths through the pin.
2536 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2537 * do any widget power switching.
2539 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2541 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2543 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
2546 * snd_soc_dapm_get_pin_status - get audio pin status
2547 * @dapm: DAPM context
2548 * @pin: audio signal pin endpoint (or start point)
2550 * Get audio pin status - connected or disconnected.
2552 * Returns 1 for connected otherwise 0.
2554 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
2557 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2560 return w
->connected
;
2564 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
2567 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2568 * @dapm: DAPM context
2569 * @pin: audio signal pin endpoint (or start point)
2571 * Mark the given endpoint or pin as ignoring suspend. When the
2572 * system is disabled a path between two endpoints flagged as ignoring
2573 * suspend will not be disabled. The path must already be enabled via
2574 * normal means at suspend time, it will not be turned on if it was not
2577 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
2580 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
2583 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2587 w
->ignore_suspend
= 1;
2591 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
2594 * snd_soc_dapm_free - free dapm resources
2597 * Free all dapm widgets and resources.
2599 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
2601 snd_soc_dapm_sys_remove(dapm
->dev
);
2602 dapm_debugfs_cleanup(dapm
);
2603 dapm_free_widgets(dapm
);
2604 list_del(&dapm
->list
);
2606 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
2608 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
2610 struct snd_soc_dapm_widget
*w
;
2611 LIST_HEAD(down_list
);
2614 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2615 if (w
->dapm
!= dapm
)
2618 dapm_seq_insert(w
, &down_list
, false);
2624 /* If there were no widgets to power down we're already in
2628 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_PREPARE
);
2629 dapm_seq_run(dapm
, &down_list
, 0, false);
2630 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_STANDBY
);
2635 * snd_soc_dapm_shutdown - callback for system shutdown
2637 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
2639 struct snd_soc_codec
*codec
;
2641 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
2642 soc_dapm_shutdown_codec(&codec
->dapm
);
2643 snd_soc_dapm_set_bias_level(&codec
->dapm
, SND_SOC_BIAS_OFF
);
2647 /* Module information */
2648 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2649 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2650 MODULE_LICENSE("GPL");