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
;
143 case SND_SOC_BIAS_ON
:
144 dev_dbg(dapm
->dev
, "Setting full bias\n");
146 case SND_SOC_BIAS_PREPARE
:
147 dev_dbg(dapm
->dev
, "Setting bias prepare\n");
149 case SND_SOC_BIAS_STANDBY
:
150 dev_dbg(dapm
->dev
, "Setting standby bias\n");
152 case SND_SOC_BIAS_OFF
:
153 dev_dbg(dapm
->dev
, "Setting bias off\n");
156 dev_err(dapm
->dev
, "Setting invalid bias %d\n", level
);
160 trace_snd_soc_bias_level_start(card
, level
);
162 if (card
&& card
->set_bias_level
)
163 ret
= card
->set_bias_level(card
, level
);
165 if (dapm
->codec
&& dapm
->codec
->driver
->set_bias_level
)
166 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
, level
);
168 dapm
->bias_level
= level
;
171 if (card
&& card
->set_bias_level_post
)
172 ret
= card
->set_bias_level_post(card
, level
);
175 trace_snd_soc_bias_level_done(card
, level
);
180 /* set up initial codec paths */
181 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
182 struct snd_soc_dapm_path
*p
, int i
)
185 case snd_soc_dapm_switch
:
186 case snd_soc_dapm_mixer
:
187 case snd_soc_dapm_mixer_named_ctl
: {
189 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
190 w
->kcontrol_news
[i
].private_value
;
191 unsigned int reg
= mc
->reg
;
192 unsigned int shift
= mc
->shift
;
194 unsigned int mask
= (1 << fls(max
)) - 1;
195 unsigned int invert
= mc
->invert
;
197 val
= snd_soc_read(w
->codec
, reg
);
198 val
= (val
>> shift
) & mask
;
200 if ((invert
&& !val
) || (!invert
&& val
))
206 case snd_soc_dapm_mux
: {
207 struct soc_enum
*e
= (struct soc_enum
*)
208 w
->kcontrol_news
[i
].private_value
;
209 int val
, item
, bitmask
;
211 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
213 val
= snd_soc_read(w
->codec
, e
->reg
);
214 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
217 for (i
= 0; i
< e
->max
; i
++) {
218 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
223 case snd_soc_dapm_virt_mux
: {
224 struct soc_enum
*e
= (struct soc_enum
*)
225 w
->kcontrol_news
[i
].private_value
;
228 /* since a virtual mux has no backing registers to
229 * decide which path to connect, it will try to match
230 * with the first enumeration. This is to ensure
231 * that the default mux choice (the first) will be
232 * correctly powered up during initialization.
234 if (!strcmp(p
->name
, e
->texts
[0]))
238 case snd_soc_dapm_value_mux
: {
239 struct soc_enum
*e
= (struct soc_enum
*)
240 w
->kcontrol_news
[i
].private_value
;
243 val
= snd_soc_read(w
->codec
, e
->reg
);
244 val
= (val
>> e
->shift_l
) & e
->mask
;
245 for (item
= 0; item
< e
->max
; item
++) {
246 if (val
== e
->values
[item
])
251 for (i
= 0; i
< e
->max
; i
++) {
252 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
257 /* does not effect routing - always connected */
258 case snd_soc_dapm_pga
:
259 case snd_soc_dapm_out_drv
:
260 case snd_soc_dapm_output
:
261 case snd_soc_dapm_adc
:
262 case snd_soc_dapm_input
:
263 case snd_soc_dapm_dac
:
264 case snd_soc_dapm_micbias
:
265 case snd_soc_dapm_vmid
:
266 case snd_soc_dapm_supply
:
267 case snd_soc_dapm_aif_in
:
268 case snd_soc_dapm_aif_out
:
271 /* does effect routing - dynamically connected */
272 case snd_soc_dapm_hp
:
273 case snd_soc_dapm_mic
:
274 case snd_soc_dapm_spk
:
275 case snd_soc_dapm_line
:
276 case snd_soc_dapm_pre
:
277 case snd_soc_dapm_post
:
283 /* connect mux widget to its interconnecting audio paths */
284 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
285 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
286 struct snd_soc_dapm_path
*path
, const char *control_name
,
287 const struct snd_kcontrol_new
*kcontrol
)
289 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
292 for (i
= 0; i
< e
->max
; i
++) {
293 if (!(strcmp(control_name
, e
->texts
[i
]))) {
294 list_add(&path
->list
, &dapm
->card
->paths
);
295 list_add(&path
->list_sink
, &dest
->sources
);
296 list_add(&path
->list_source
, &src
->sinks
);
297 path
->name
= (char*)e
->texts
[i
];
298 dapm_set_path_status(dest
, path
, 0);
306 /* connect mixer widget to its interconnecting audio paths */
307 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
308 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
309 struct snd_soc_dapm_path
*path
, const char *control_name
)
313 /* search for mixer kcontrol */
314 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
315 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
316 list_add(&path
->list
, &dapm
->card
->paths
);
317 list_add(&path
->list_sink
, &dest
->sources
);
318 list_add(&path
->list_source
, &src
->sinks
);
319 path
->name
= dest
->kcontrol_news
[i
].name
;
320 dapm_set_path_status(dest
, path
, i
);
327 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
328 struct snd_soc_dapm_widget
*kcontrolw
,
329 const struct snd_kcontrol_new
*kcontrol_new
,
330 struct snd_kcontrol
**kcontrol
)
332 struct snd_soc_dapm_widget
*w
;
337 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
338 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
340 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
341 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
343 *kcontrol
= w
->kcontrols
[i
];
352 /* create new dapm mixer control */
353 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
355 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
357 size_t name_len
, prefix_len
;
358 struct snd_soc_dapm_path
*path
;
359 struct snd_card
*card
= dapm
->card
->snd_card
;
361 struct snd_soc_dapm_widget_list
*wlist
;
365 prefix
= dapm
->codec
->name_prefix
;
370 prefix_len
= strlen(prefix
) + 1;
375 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
378 list_for_each_entry(path
, &w
->sources
, list_sink
) {
380 /* mixer/mux paths name must match control name */
381 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
384 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
385 sizeof(struct snd_soc_dapm_widget
*),
386 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
389 "asoc: can't allocate widget list for %s\n",
393 wlist
->num_widgets
= 1;
394 wlist
->widgets
[0] = w
;
396 /* add dapm control with long name.
397 * for dapm_mixer this is the concatenation of the
398 * mixer and kcontrol name.
399 * for dapm_mixer_named_ctl this is simply the
402 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
403 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
404 name_len
+= 1 + strlen(w
->name
);
406 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
408 if (path
->long_name
== NULL
) {
415 /* The control will get a prefix from
416 * the control creation process but
417 * we're also using the same prefix
418 * for widgets so cut the prefix off
419 * the front of the widget name.
421 snprintf(path
->long_name
, name_len
, "%s %s",
422 w
->name
+ prefix_len
,
423 w
->kcontrol_news
[i
].name
);
425 case snd_soc_dapm_mixer_named_ctl
:
426 snprintf(path
->long_name
, name_len
, "%s",
427 w
->kcontrol_news
[i
].name
);
431 path
->long_name
[name_len
- 1] = '\0';
433 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
434 wlist
, path
->long_name
,
436 ret
= snd_ctl_add(card
, path
->kcontrol
);
439 "asoc: failed to add dapm kcontrol %s: %d\n",
440 path
->long_name
, ret
);
442 kfree(path
->long_name
);
443 path
->long_name
= NULL
;
446 w
->kcontrols
[i
] = path
->kcontrol
;
452 /* create new dapm mux control */
453 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
455 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
456 struct snd_soc_dapm_path
*path
= NULL
;
457 struct snd_kcontrol
*kcontrol
;
458 struct snd_card
*card
= dapm
->card
->snd_card
;
462 struct snd_soc_dapm_widget_list
*wlist
;
463 int shared
, wlistentries
;
467 if (w
->num_kcontrols
!= 1) {
469 "asoc: mux %s has incorrect number of controls\n",
474 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[0],
477 wlist
= kcontrol
->private_data
;
478 wlistentries
= wlist
->num_widgets
+ 1;
483 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
484 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
485 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
488 "asoc: can't allocate widget list for %s\n", w
->name
);
491 wlist
->num_widgets
= wlistentries
;
492 wlist
->widgets
[wlistentries
- 1] = w
;
496 prefix
= dapm
->codec
->name_prefix
;
501 name
= w
->kcontrol_news
[0].name
;
506 prefix_len
= strlen(prefix
) + 1;
512 * The control will get a prefix from the control creation
513 * process but we're also using the same prefix for widgets so
514 * cut the prefix off the front of the widget name.
516 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
517 name
+ prefix_len
, prefix
);
518 ret
= snd_ctl_add(card
, kcontrol
);
521 "asoc: failed to add kcontrol %s\n", w
->name
);
527 kcontrol
->private_data
= wlist
;
529 w
->kcontrols
[0] = kcontrol
;
531 list_for_each_entry(path
, &w
->sources
, list_sink
)
532 path
->kcontrol
= kcontrol
;
537 /* create new dapm volume control */
538 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
540 if (w
->num_kcontrols
)
541 dev_err(w
->dapm
->dev
,
542 "asoc: PGA controls not supported: '%s'\n", w
->name
);
547 /* reset 'walked' bit for each dapm path */
548 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
550 struct snd_soc_dapm_path
*p
;
552 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
556 /* We implement power down on suspend by checking the power state of
557 * the ALSA card - when we are suspending the ALSA state for the card
560 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
562 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
565 case SNDRV_CTL_POWER_D3hot
:
566 case SNDRV_CTL_POWER_D3cold
:
567 if (widget
->ignore_suspend
)
568 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
570 return widget
->ignore_suspend
;
577 * Recursively check for a completed path to an active or physically connected
578 * output widget. Returns number of complete paths.
580 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
582 struct snd_soc_dapm_path
*path
;
585 if (widget
->id
== snd_soc_dapm_supply
)
588 switch (widget
->id
) {
589 case snd_soc_dapm_adc
:
590 case snd_soc_dapm_aif_out
:
592 return snd_soc_dapm_suspend_check(widget
);
597 if (widget
->connected
) {
598 /* connected pin ? */
599 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
)
600 return snd_soc_dapm_suspend_check(widget
);
602 /* connected jack or spk ? */
603 if (widget
->id
== snd_soc_dapm_hp
|| widget
->id
== snd_soc_dapm_spk
||
604 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sources
)))
605 return snd_soc_dapm_suspend_check(widget
);
608 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
612 if (path
->sink
&& path
->connect
) {
614 con
+= is_connected_output_ep(path
->sink
);
622 * Recursively check for a completed path to an active or physically connected
623 * input widget. Returns number of complete paths.
625 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
627 struct snd_soc_dapm_path
*path
;
630 if (widget
->id
== snd_soc_dapm_supply
)
633 /* active stream ? */
634 switch (widget
->id
) {
635 case snd_soc_dapm_dac
:
636 case snd_soc_dapm_aif_in
:
638 return snd_soc_dapm_suspend_check(widget
);
643 if (widget
->connected
) {
644 /* connected pin ? */
645 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
)
646 return snd_soc_dapm_suspend_check(widget
);
648 /* connected VMID/Bias for lower pops */
649 if (widget
->id
== snd_soc_dapm_vmid
)
650 return snd_soc_dapm_suspend_check(widget
);
652 /* connected jack ? */
653 if (widget
->id
== snd_soc_dapm_mic
||
654 (widget
->id
== snd_soc_dapm_line
&& !list_empty(&widget
->sinks
)))
655 return snd_soc_dapm_suspend_check(widget
);
658 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
662 if (path
->source
&& path
->connect
) {
664 con
+= is_connected_input_ep(path
->source
);
672 * Handler for generic register modifier widget.
674 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
675 struct snd_kcontrol
*kcontrol
, int event
)
679 if (SND_SOC_DAPM_EVENT_ON(event
))
684 snd_soc_update_bits(w
->codec
, -(w
->reg
+ 1),
685 w
->mask
<< w
->shift
, val
<< w
->shift
);
689 EXPORT_SYMBOL_GPL(dapm_reg_event
);
691 /* Generic check to see if a widget should be powered.
693 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
697 in
= is_connected_input_ep(w
);
698 dapm_clear_walk(w
->dapm
);
699 out
= is_connected_output_ep(w
);
700 dapm_clear_walk(w
->dapm
);
701 return out
!= 0 && in
!= 0;
704 /* Check to see if an ADC has power */
705 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
710 in
= is_connected_input_ep(w
);
711 dapm_clear_walk(w
->dapm
);
714 return dapm_generic_check_power(w
);
718 /* Check to see if a DAC has power */
719 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
724 out
= is_connected_output_ep(w
);
725 dapm_clear_walk(w
->dapm
);
728 return dapm_generic_check_power(w
);
732 /* Check to see if a power supply is needed */
733 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
735 struct snd_soc_dapm_path
*path
;
738 /* Check if one of our outputs is connected */
739 list_for_each_entry(path
, &w
->sinks
, list_source
) {
740 if (path
->connected
&&
741 !path
->connected(path
->source
, path
->sink
))
747 if (path
->sink
->force
) {
752 if (path
->sink
->power_check
&&
753 path
->sink
->power_check(path
->sink
)) {
759 dapm_clear_walk(w
->dapm
);
764 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
765 struct snd_soc_dapm_widget
*b
,
773 sort
= dapm_down_seq
;
775 if (sort
[a
->id
] != sort
[b
->id
])
776 return sort
[a
->id
] - sort
[b
->id
];
777 if (a
->subseq
!= b
->subseq
) {
779 return a
->subseq
- b
->subseq
;
781 return b
->subseq
- a
->subseq
;
783 if (a
->reg
!= b
->reg
)
784 return a
->reg
- b
->reg
;
785 if (a
->dapm
!= b
->dapm
)
786 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
791 /* Insert a widget in order into a DAPM power sequence. */
792 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
793 struct list_head
*list
,
796 struct snd_soc_dapm_widget
*w
;
798 list_for_each_entry(w
, list
, power_list
)
799 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
800 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
804 list_add_tail(&new_widget
->power_list
, list
);
807 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
808 struct snd_soc_dapm_widget
*w
, int event
)
810 struct snd_soc_card
*card
= dapm
->card
;
815 case SND_SOC_DAPM_PRE_PMU
:
819 case SND_SOC_DAPM_POST_PMU
:
820 ev_name
= "POST_PMU";
823 case SND_SOC_DAPM_PRE_PMD
:
827 case SND_SOC_DAPM_POST_PMD
:
828 ev_name
= "POST_PMD";
836 if (w
->power
!= power
)
839 if (w
->event
&& (w
->event_flags
& event
)) {
840 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
842 trace_snd_soc_dapm_widget_event_start(w
, event
);
843 ret
= w
->event(w
, NULL
, event
);
844 trace_snd_soc_dapm_widget_event_done(w
, event
);
846 pr_err("%s: %s event failed: %d\n",
847 ev_name
, w
->name
, ret
);
851 /* Apply the coalesced changes from a DAPM sequence */
852 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
853 struct list_head
*pending
)
855 struct snd_soc_card
*card
= dapm
->card
;
856 struct snd_soc_dapm_widget
*w
;
858 unsigned int value
= 0;
859 unsigned int mask
= 0;
860 unsigned int cur_mask
;
862 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
865 list_for_each_entry(w
, pending
, power_list
) {
866 cur_mask
= 1 << w
->shift
;
867 BUG_ON(reg
!= w
->reg
);
878 pop_dbg(dapm
->dev
, card
->pop_time
,
879 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
880 w
->name
, reg
, value
, mask
);
882 /* Check for events */
883 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
884 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
888 pop_dbg(dapm
->dev
, card
->pop_time
,
889 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
890 value
, mask
, reg
, card
->pop_time
);
891 pop_wait(card
->pop_time
);
892 snd_soc_update_bits(dapm
->codec
, reg
, mask
, value
);
895 list_for_each_entry(w
, pending
, power_list
) {
896 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
897 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
901 /* Apply a DAPM power sequence.
903 * We walk over a pre-sorted list of widgets to apply power to. In
904 * order to minimise the number of writes to the device required
905 * multiple widgets will be updated in a single write where possible.
906 * Currently anything that requires more than a single write is not
909 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
910 struct list_head
*list
, int event
, bool power_up
)
912 struct snd_soc_dapm_widget
*w
, *n
;
916 int cur_reg
= SND_SOC_NOPM
;
917 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
924 sort
= dapm_down_seq
;
926 list_for_each_entry_safe(w
, n
, list
, power_list
) {
929 /* Do we need to apply any queued changes? */
930 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
931 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
932 if (!list_empty(&pending
))
933 dapm_seq_run_coalesced(cur_dapm
, &pending
);
935 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
936 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
937 if (sort
[i
] == cur_sort
)
938 cur_dapm
->seq_notifier(cur_dapm
,
943 INIT_LIST_HEAD(&pending
);
946 cur_reg
= SND_SOC_NOPM
;
951 case snd_soc_dapm_pre
:
953 list_for_each_entry_safe_continue(w
, n
, list
,
956 if (event
== SND_SOC_DAPM_STREAM_START
)
958 NULL
, SND_SOC_DAPM_PRE_PMU
);
959 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
961 NULL
, SND_SOC_DAPM_PRE_PMD
);
964 case snd_soc_dapm_post
:
966 list_for_each_entry_safe_continue(w
, n
, list
,
969 if (event
== SND_SOC_DAPM_STREAM_START
)
971 NULL
, SND_SOC_DAPM_POST_PMU
);
972 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
974 NULL
, SND_SOC_DAPM_POST_PMD
);
978 /* Queue it up for application */
979 cur_sort
= sort
[w
->id
];
980 cur_subseq
= w
->subseq
;
983 list_move(&w
->power_list
, &pending
);
988 dev_err(w
->dapm
->dev
,
989 "Failed to apply widget power: %d\n", ret
);
992 if (!list_empty(&pending
))
993 dapm_seq_run_coalesced(cur_dapm
, &pending
);
995 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
996 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
997 if (sort
[i
] == cur_sort
)
998 cur_dapm
->seq_notifier(cur_dapm
,
1003 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1005 struct snd_soc_dapm_update
*update
= dapm
->update
;
1006 struct snd_soc_dapm_widget
*w
;
1015 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1016 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1018 pr_err("%s DAPM pre-event failed: %d\n",
1022 ret
= snd_soc_update_bits(w
->codec
, update
->reg
, update
->mask
,
1025 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1028 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1029 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1031 pr_err("%s DAPM post-event failed: %d\n",
1036 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1037 * they're changing state.
1039 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1041 struct snd_soc_dapm_context
*d
= data
;
1044 if (d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_OFF
) {
1045 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1048 "Failed to turn on bias: %d\n", ret
);
1051 /* If we're changing to all on or all off then prepare */
1052 if ((d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_STANDBY
) ||
1053 (!d
->dev_power
&& d
->bias_level
== SND_SOC_BIAS_ON
)) {
1054 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1057 "Failed to prepare bias: %d\n", ret
);
1061 /* Async callback run prior to DAPM sequences - brings to their final
1064 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1066 struct snd_soc_dapm_context
*d
= data
;
1069 /* If we just powered the last thing off drop to standby bias */
1070 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&& !d
->dev_power
) {
1071 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1073 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1077 /* If we're in standby and can support bias off then do that */
1078 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&& d
->idle_bias_off
) {
1079 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1081 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1084 /* If we just powered up then move to active bias */
1085 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&& d
->dev_power
) {
1086 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1088 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1094 * Scan each dapm widget for complete audio path.
1095 * A complete path is a route that has valid endpoints i.e.:-
1097 * o DAC to output pin.
1098 * o Input Pin to ADC.
1099 * o Input pin to Output pin (bypass, sidetone)
1100 * o DAC to ADC (loopback).
1102 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1104 struct snd_soc_card
*card
= dapm
->card
;
1105 struct snd_soc_dapm_widget
*w
;
1106 struct snd_soc_dapm_context
*d
;
1108 LIST_HEAD(down_list
);
1109 LIST_HEAD(async_domain
);
1112 trace_snd_soc_dapm_start(card
);
1114 list_for_each_entry(d
, &card
->dapm_list
, list
)
1115 if (d
->n_widgets
|| d
->codec
== NULL
)
1118 /* Check which widgets we need to power and store them in
1119 * lists indicating if they should be powered up or down.
1121 list_for_each_entry(w
, &card
->widgets
, list
) {
1123 case snd_soc_dapm_pre
:
1124 dapm_seq_insert(w
, &down_list
, false);
1126 case snd_soc_dapm_post
:
1127 dapm_seq_insert(w
, &up_list
, true);
1131 if (!w
->power_check
)
1135 power
= w
->power_check(w
);
1139 w
->dapm
->dev_power
= 1;
1141 if (w
->power
== power
)
1144 trace_snd_soc_dapm_widget_power(w
, power
);
1147 dapm_seq_insert(w
, &up_list
, true);
1149 dapm_seq_insert(w
, &down_list
, false);
1156 /* If there are no DAPM widgets then try to figure out power from the
1159 if (!dapm
->n_widgets
) {
1161 case SND_SOC_DAPM_STREAM_START
:
1162 case SND_SOC_DAPM_STREAM_RESUME
:
1163 dapm
->dev_power
= 1;
1165 case SND_SOC_DAPM_STREAM_STOP
:
1166 dapm
->dev_power
= !!dapm
->codec
->active
;
1168 case SND_SOC_DAPM_STREAM_SUSPEND
:
1169 dapm
->dev_power
= 0;
1171 case SND_SOC_DAPM_STREAM_NOP
:
1172 switch (dapm
->bias_level
) {
1173 case SND_SOC_BIAS_STANDBY
:
1174 case SND_SOC_BIAS_OFF
:
1175 dapm
->dev_power
= 0;
1178 dapm
->dev_power
= 1;
1187 /* Force all contexts in the card to the same bias state */
1189 list_for_each_entry(d
, &card
->dapm_list
, list
)
1192 list_for_each_entry(d
, &card
->dapm_list
, list
)
1193 d
->dev_power
= power
;
1196 /* Run all the bias changes in parallel */
1197 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1198 async_schedule_domain(dapm_pre_sequence_async
, d
,
1200 async_synchronize_full_domain(&async_domain
);
1202 /* Power down widgets first; try to avoid amplifying pops. */
1203 dapm_seq_run(dapm
, &down_list
, event
, false);
1205 dapm_widget_update(dapm
);
1208 dapm_seq_run(dapm
, &up_list
, event
, true);
1210 /* Run all the bias changes in parallel */
1211 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1212 async_schedule_domain(dapm_post_sequence_async
, d
,
1214 async_synchronize_full_domain(&async_domain
);
1216 pop_dbg(dapm
->dev
, card
->pop_time
,
1217 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1218 pop_wait(card
->pop_time
);
1220 trace_snd_soc_dapm_done(card
);
1225 #ifdef CONFIG_DEBUG_FS
1226 static int dapm_widget_power_open_file(struct inode
*inode
, struct file
*file
)
1228 file
->private_data
= inode
->i_private
;
1232 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1233 char __user
*user_buf
,
1234 size_t count
, loff_t
*ppos
)
1236 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1240 struct snd_soc_dapm_path
*p
= NULL
;
1242 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1246 in
= is_connected_input_ep(w
);
1247 dapm_clear_walk(w
->dapm
);
1248 out
= is_connected_output_ep(w
);
1249 dapm_clear_walk(w
->dapm
);
1251 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s in %d out %d",
1252 w
->name
, w
->power
? "On" : "Off", in
, out
);
1255 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1256 " - R%d(0x%x) bit %d",
1257 w
->reg
, w
->reg
, w
->shift
);
1259 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1262 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1264 w
->active
? "active" : "inactive");
1266 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1267 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1271 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1272 " in \"%s\" \"%s\"\n",
1273 p
->name
? p
->name
: "static",
1276 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1277 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1281 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1282 " out \"%s\" \"%s\"\n",
1283 p
->name
? p
->name
: "static",
1287 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1293 static const struct file_operations dapm_widget_power_fops
= {
1294 .open
= dapm_widget_power_open_file
,
1295 .read
= dapm_widget_power_read_file
,
1296 .llseek
= default_llseek
,
1299 static int dapm_bias_open_file(struct inode
*inode
, struct file
*file
)
1301 file
->private_data
= inode
->i_private
;
1305 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1306 size_t count
, loff_t
*ppos
)
1308 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1311 switch (dapm
->bias_level
) {
1312 case SND_SOC_BIAS_ON
:
1315 case SND_SOC_BIAS_PREPARE
:
1316 level
= "Prepare\n";
1318 case SND_SOC_BIAS_STANDBY
:
1319 level
= "Standby\n";
1321 case SND_SOC_BIAS_OFF
:
1326 level
= "Unknown\n";
1330 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1334 static const struct file_operations dapm_bias_fops
= {
1335 .open
= dapm_bias_open_file
,
1336 .read
= dapm_bias_read_file
,
1337 .llseek
= default_llseek
,
1340 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1341 struct dentry
*parent
)
1345 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1347 if (!dapm
->debugfs_dapm
) {
1349 "Failed to create DAPM debugfs directory\n");
1353 d
= debugfs_create_file("bias_level", 0444,
1354 dapm
->debugfs_dapm
, dapm
,
1358 "ASoC: Failed to create bias level debugfs file\n");
1361 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1363 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1366 if (!dapm
->debugfs_dapm
|| !w
->name
)
1369 d
= debugfs_create_file(w
->name
, 0444,
1370 dapm
->debugfs_dapm
, w
,
1371 &dapm_widget_power_fops
);
1373 dev_warn(w
->dapm
->dev
,
1374 "ASoC: Failed to create %s debugfs file\n",
1378 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1380 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1384 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1385 struct dentry
*parent
)
1389 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1393 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1399 /* test and update the power status of a mux widget */
1400 static int dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1401 struct snd_kcontrol
*kcontrol
, int change
,
1402 int mux
, struct soc_enum
*e
)
1404 struct snd_soc_dapm_path
*path
;
1407 if (widget
->id
!= snd_soc_dapm_mux
&&
1408 widget
->id
!= snd_soc_dapm_virt_mux
&&
1409 widget
->id
!= snd_soc_dapm_value_mux
)
1415 /* find dapm widget path assoc with kcontrol */
1416 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1417 if (path
->kcontrol
!= kcontrol
)
1420 if (!path
->name
|| !e
->texts
[mux
])
1424 /* we now need to match the string in the enum to the path */
1425 if (!(strcmp(path
->name
, e
->texts
[mux
])))
1426 path
->connect
= 1; /* new connection */
1428 path
->connect
= 0; /* old connection must be powered down */
1432 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1437 /* test and update the power status of a mixer or switch widget */
1438 static int dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1439 struct snd_kcontrol
*kcontrol
, int connect
)
1441 struct snd_soc_dapm_path
*path
;
1444 if (widget
->id
!= snd_soc_dapm_mixer
&&
1445 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1446 widget
->id
!= snd_soc_dapm_switch
)
1449 /* find dapm widget path assoc with kcontrol */
1450 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1451 if (path
->kcontrol
!= kcontrol
)
1454 /* found, now check type */
1456 path
->connect
= connect
;
1461 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1466 /* show dapm widget status in sys fs */
1467 static ssize_t
dapm_widget_show(struct device
*dev
,
1468 struct device_attribute
*attr
, char *buf
)
1470 struct snd_soc_pcm_runtime
*rtd
=
1471 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
1472 struct snd_soc_codec
*codec
=rtd
->codec
;
1473 struct snd_soc_dapm_widget
*w
;
1475 char *state
= "not set";
1477 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1478 if (w
->dapm
!= &codec
->dapm
)
1481 /* only display widgets that burnm power */
1483 case snd_soc_dapm_hp
:
1484 case snd_soc_dapm_mic
:
1485 case snd_soc_dapm_spk
:
1486 case snd_soc_dapm_line
:
1487 case snd_soc_dapm_micbias
:
1488 case snd_soc_dapm_dac
:
1489 case snd_soc_dapm_adc
:
1490 case snd_soc_dapm_pga
:
1491 case snd_soc_dapm_out_drv
:
1492 case snd_soc_dapm_mixer
:
1493 case snd_soc_dapm_mixer_named_ctl
:
1494 case snd_soc_dapm_supply
:
1496 count
+= sprintf(buf
+ count
, "%s: %s\n",
1497 w
->name
, w
->power
? "On":"Off");
1504 switch (codec
->dapm
.bias_level
) {
1505 case SND_SOC_BIAS_ON
:
1508 case SND_SOC_BIAS_PREPARE
:
1511 case SND_SOC_BIAS_STANDBY
:
1514 case SND_SOC_BIAS_OFF
:
1518 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1523 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1525 int snd_soc_dapm_sys_add(struct device
*dev
)
1527 return device_create_file(dev
, &dev_attr_dapm_widget
);
1530 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1532 device_remove_file(dev
, &dev_attr_dapm_widget
);
1535 /* free all dapm widgets and resources */
1536 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
1538 struct snd_soc_dapm_widget
*w
, *next_w
;
1539 struct snd_soc_dapm_path
*p
, *next_p
;
1541 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
1542 if (w
->dapm
!= dapm
)
1546 * remove source and sink paths associated to this widget.
1547 * While removing the path, remove reference to it from both
1548 * source and sink widgets so that path is removed only once.
1550 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
1551 list_del(&p
->list_sink
);
1552 list_del(&p
->list_source
);
1554 kfree(p
->long_name
);
1557 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
1558 list_del(&p
->list_sink
);
1559 list_del(&p
->list_source
);
1561 kfree(p
->long_name
);
1564 kfree(w
->kcontrols
);
1570 static struct snd_soc_dapm_widget
*dapm_find_widget(
1571 struct snd_soc_dapm_context
*dapm
, const char *pin
,
1572 bool search_other_contexts
)
1574 struct snd_soc_dapm_widget
*w
;
1575 struct snd_soc_dapm_widget
*fallback
= NULL
;
1577 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1578 if (!strcmp(w
->name
, pin
)) {
1579 if (w
->dapm
== dapm
)
1586 if (search_other_contexts
)
1592 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
1593 const char *pin
, int status
)
1595 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
1598 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
1602 w
->connected
= status
;
1610 * snd_soc_dapm_sync - scan and power dapm paths
1611 * @dapm: DAPM context
1613 * Walks all dapm audio paths and powers widgets according to their
1614 * stream or path usage.
1616 * Returns 0 for success.
1618 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
1620 return dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1622 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1624 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
1625 const struct snd_soc_dapm_route
*route
)
1627 struct snd_soc_dapm_path
*path
;
1628 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1629 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
1631 const char *control
= route
->control
;
1633 char prefixed_sink
[80];
1634 char prefixed_source
[80];
1637 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
1638 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
1639 dapm
->codec
->name_prefix
, route
->sink
);
1640 sink
= prefixed_sink
;
1641 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
1642 dapm
->codec
->name_prefix
, route
->source
);
1643 source
= prefixed_source
;
1646 source
= route
->source
;
1650 * find src and dest widgets over all widgets but favor a widget from
1651 * current DAPM context
1653 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1654 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
1656 if (w
->dapm
== dapm
)
1660 if (!wsource
&& !(strcmp(w
->name
, source
))) {
1662 if (w
->dapm
== dapm
)
1666 /* use widget from another DAPM context if not found from this */
1672 if (wsource
== NULL
|| wsink
== NULL
)
1675 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
1679 path
->source
= wsource
;
1681 path
->connected
= route
->connected
;
1682 INIT_LIST_HEAD(&path
->list
);
1683 INIT_LIST_HEAD(&path
->list_source
);
1684 INIT_LIST_HEAD(&path
->list_sink
);
1686 /* check for external widgets */
1687 if (wsink
->id
== snd_soc_dapm_input
) {
1688 if (wsource
->id
== snd_soc_dapm_micbias
||
1689 wsource
->id
== snd_soc_dapm_mic
||
1690 wsource
->id
== snd_soc_dapm_line
||
1691 wsource
->id
== snd_soc_dapm_output
)
1694 if (wsource
->id
== snd_soc_dapm_output
) {
1695 if (wsink
->id
== snd_soc_dapm_spk
||
1696 wsink
->id
== snd_soc_dapm_hp
||
1697 wsink
->id
== snd_soc_dapm_line
||
1698 wsink
->id
== snd_soc_dapm_input
)
1702 /* connect static paths */
1703 if (control
== NULL
) {
1704 list_add(&path
->list
, &dapm
->card
->paths
);
1705 list_add(&path
->list_sink
, &wsink
->sources
);
1706 list_add(&path
->list_source
, &wsource
->sinks
);
1711 /* connect dynamic paths */
1712 switch (wsink
->id
) {
1713 case snd_soc_dapm_adc
:
1714 case snd_soc_dapm_dac
:
1715 case snd_soc_dapm_pga
:
1716 case snd_soc_dapm_out_drv
:
1717 case snd_soc_dapm_input
:
1718 case snd_soc_dapm_output
:
1719 case snd_soc_dapm_micbias
:
1720 case snd_soc_dapm_vmid
:
1721 case snd_soc_dapm_pre
:
1722 case snd_soc_dapm_post
:
1723 case snd_soc_dapm_supply
:
1724 case snd_soc_dapm_aif_in
:
1725 case snd_soc_dapm_aif_out
:
1726 list_add(&path
->list
, &dapm
->card
->paths
);
1727 list_add(&path
->list_sink
, &wsink
->sources
);
1728 list_add(&path
->list_source
, &wsource
->sinks
);
1731 case snd_soc_dapm_mux
:
1732 case snd_soc_dapm_virt_mux
:
1733 case snd_soc_dapm_value_mux
:
1734 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
1735 &wsink
->kcontrol_news
[0]);
1739 case snd_soc_dapm_switch
:
1740 case snd_soc_dapm_mixer
:
1741 case snd_soc_dapm_mixer_named_ctl
:
1742 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
1746 case snd_soc_dapm_hp
:
1747 case snd_soc_dapm_mic
:
1748 case snd_soc_dapm_line
:
1749 case snd_soc_dapm_spk
:
1750 list_add(&path
->list
, &dapm
->card
->paths
);
1751 list_add(&path
->list_sink
, &wsink
->sources
);
1752 list_add(&path
->list_source
, &wsource
->sinks
);
1759 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
1760 source
, control
, sink
);
1766 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1767 * @dapm: DAPM context
1768 * @route: audio routes
1769 * @num: number of routes
1771 * Connects 2 dapm widgets together via a named audio path. The sink is
1772 * the widget receiving the audio signal, whilst the source is the sender
1773 * of the audio signal.
1775 * Returns 0 for success else error. On error all resources can be freed
1776 * with a call to snd_soc_card_free().
1778 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
1779 const struct snd_soc_dapm_route
*route
, int num
)
1783 for (i
= 0; i
< num
; i
++) {
1784 ret
= snd_soc_dapm_add_route(dapm
, route
);
1786 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
1787 route
->source
, route
->sink
);
1795 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
1798 * snd_soc_dapm_new_widgets - add new dapm widgets
1799 * @dapm: DAPM context
1801 * Checks the codec for any new dapm widgets and creates them if found.
1803 * Returns 0 for success.
1805 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
1807 struct snd_soc_dapm_widget
*w
;
1810 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
1815 if (w
->num_kcontrols
) {
1816 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
1817 sizeof(struct snd_kcontrol
*),
1824 case snd_soc_dapm_switch
:
1825 case snd_soc_dapm_mixer
:
1826 case snd_soc_dapm_mixer_named_ctl
:
1827 w
->power_check
= dapm_generic_check_power
;
1830 case snd_soc_dapm_mux
:
1831 case snd_soc_dapm_virt_mux
:
1832 case snd_soc_dapm_value_mux
:
1833 w
->power_check
= dapm_generic_check_power
;
1836 case snd_soc_dapm_adc
:
1837 case snd_soc_dapm_aif_out
:
1838 w
->power_check
= dapm_adc_check_power
;
1840 case snd_soc_dapm_dac
:
1841 case snd_soc_dapm_aif_in
:
1842 w
->power_check
= dapm_dac_check_power
;
1844 case snd_soc_dapm_pga
:
1845 case snd_soc_dapm_out_drv
:
1846 w
->power_check
= dapm_generic_check_power
;
1849 case snd_soc_dapm_input
:
1850 case snd_soc_dapm_output
:
1851 case snd_soc_dapm_micbias
:
1852 case snd_soc_dapm_spk
:
1853 case snd_soc_dapm_hp
:
1854 case snd_soc_dapm_mic
:
1855 case snd_soc_dapm_line
:
1856 w
->power_check
= dapm_generic_check_power
;
1858 case snd_soc_dapm_supply
:
1859 w
->power_check
= dapm_supply_check_power
;
1860 case snd_soc_dapm_vmid
:
1861 case snd_soc_dapm_pre
:
1862 case snd_soc_dapm_post
:
1866 /* Read the initial power state from the device */
1868 val
= snd_soc_read(w
->codec
, w
->reg
);
1869 val
&= 1 << w
->shift
;
1879 dapm_debugfs_add_widget(w
);
1882 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1885 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
1888 * snd_soc_dapm_get_volsw - dapm mixer get callback
1889 * @kcontrol: mixer control
1890 * @ucontrol: control element information
1892 * Callback to get the value of a dapm mixer control.
1894 * Returns 0 for success.
1896 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
1897 struct snd_ctl_elem_value
*ucontrol
)
1899 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
1900 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
1901 struct soc_mixer_control
*mc
=
1902 (struct soc_mixer_control
*)kcontrol
->private_value
;
1903 unsigned int reg
= mc
->reg
;
1904 unsigned int shift
= mc
->shift
;
1905 unsigned int rshift
= mc
->rshift
;
1907 unsigned int invert
= mc
->invert
;
1908 unsigned int mask
= (1 << fls(max
)) - 1;
1910 ucontrol
->value
.integer
.value
[0] =
1911 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
1912 if (shift
!= rshift
)
1913 ucontrol
->value
.integer
.value
[1] =
1914 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
1916 ucontrol
->value
.integer
.value
[0] =
1917 max
- ucontrol
->value
.integer
.value
[0];
1918 if (shift
!= rshift
)
1919 ucontrol
->value
.integer
.value
[1] =
1920 max
- ucontrol
->value
.integer
.value
[1];
1925 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
1928 * snd_soc_dapm_put_volsw - dapm mixer set callback
1929 * @kcontrol: mixer control
1930 * @ucontrol: control element information
1932 * Callback to set the value of a dapm mixer control.
1934 * Returns 0 for success.
1936 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
1937 struct snd_ctl_elem_value
*ucontrol
)
1939 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
1940 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
1941 struct snd_soc_codec
*codec
= widget
->codec
;
1942 struct soc_mixer_control
*mc
=
1943 (struct soc_mixer_control
*)kcontrol
->private_value
;
1944 unsigned int reg
= mc
->reg
;
1945 unsigned int shift
= mc
->shift
;
1947 unsigned int mask
= (1 << fls(max
)) - 1;
1948 unsigned int invert
= mc
->invert
;
1950 int connect
, change
;
1951 struct snd_soc_dapm_update update
;
1954 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1958 mask
= mask
<< shift
;
1962 /* new connection */
1963 connect
= invert
? 0 : 1;
1965 /* old connection must be powered down */
1966 connect
= invert
? 1 : 0;
1968 mutex_lock(&codec
->mutex
);
1970 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
1972 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
1973 widget
= wlist
->widgets
[wi
];
1975 widget
->value
= val
;
1977 update
.kcontrol
= kcontrol
;
1978 update
.widget
= widget
;
1982 widget
->dapm
->update
= &update
;
1984 dapm_mixer_update_power(widget
, kcontrol
, connect
);
1986 widget
->dapm
->update
= NULL
;
1990 mutex_unlock(&codec
->mutex
);
1993 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
1996 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1997 * @kcontrol: mixer control
1998 * @ucontrol: control element information
2000 * Callback to get the value of a dapm enumerated double mixer control.
2002 * Returns 0 for success.
2004 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2005 struct snd_ctl_elem_value
*ucontrol
)
2007 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2008 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2009 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2010 unsigned int val
, bitmask
;
2012 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2014 val
= snd_soc_read(widget
->codec
, e
->reg
);
2015 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
2016 if (e
->shift_l
!= e
->shift_r
)
2017 ucontrol
->value
.enumerated
.item
[1] =
2018 (val
>> e
->shift_r
) & (bitmask
- 1);
2022 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2025 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2026 * @kcontrol: mixer control
2027 * @ucontrol: control element information
2029 * Callback to set the value of a dapm enumerated double mixer control.
2031 * Returns 0 for success.
2033 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2034 struct snd_ctl_elem_value
*ucontrol
)
2036 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2037 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2038 struct snd_soc_codec
*codec
= widget
->codec
;
2039 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2040 unsigned int val
, mux
, change
;
2041 unsigned int mask
, bitmask
;
2042 struct snd_soc_dapm_update update
;
2045 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2047 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2049 mux
= ucontrol
->value
.enumerated
.item
[0];
2050 val
= mux
<< e
->shift_l
;
2051 mask
= (bitmask
- 1) << e
->shift_l
;
2052 if (e
->shift_l
!= e
->shift_r
) {
2053 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2055 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2056 mask
|= (bitmask
- 1) << e
->shift_r
;
2059 mutex_lock(&codec
->mutex
);
2061 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2063 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2064 widget
= wlist
->widgets
[wi
];
2066 widget
->value
= val
;
2068 update
.kcontrol
= kcontrol
;
2069 update
.widget
= widget
;
2070 update
.reg
= e
->reg
;
2073 widget
->dapm
->update
= &update
;
2075 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2077 widget
->dapm
->update
= NULL
;
2081 mutex_unlock(&codec
->mutex
);
2084 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2087 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2088 * @kcontrol: mixer control
2089 * @ucontrol: control element information
2091 * Returns 0 for success.
2093 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2094 struct snd_ctl_elem_value
*ucontrol
)
2096 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2097 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2099 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2103 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2106 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2107 * @kcontrol: mixer control
2108 * @ucontrol: control element information
2110 * Returns 0 for success.
2112 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2113 struct snd_ctl_elem_value
*ucontrol
)
2115 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2116 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2117 struct snd_soc_codec
*codec
= widget
->codec
;
2118 struct soc_enum
*e
=
2119 (struct soc_enum
*)kcontrol
->private_value
;
2124 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2127 mutex_lock(&codec
->mutex
);
2129 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2131 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2132 widget
= wlist
->widgets
[wi
];
2134 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2136 dapm_mux_update_power(widget
, kcontrol
, change
,
2141 mutex_unlock(&codec
->mutex
);
2144 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2147 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2149 * @kcontrol: mixer control
2150 * @ucontrol: control element information
2152 * Callback to get the value of a dapm semi enumerated double mixer control.
2154 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2155 * used for handling bitfield coded enumeration for example.
2157 * Returns 0 for success.
2159 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2160 struct snd_ctl_elem_value
*ucontrol
)
2162 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2163 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2164 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2165 unsigned int reg_val
, val
, mux
;
2167 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2168 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2169 for (mux
= 0; mux
< e
->max
; mux
++) {
2170 if (val
== e
->values
[mux
])
2173 ucontrol
->value
.enumerated
.item
[0] = mux
;
2174 if (e
->shift_l
!= e
->shift_r
) {
2175 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2176 for (mux
= 0; mux
< e
->max
; mux
++) {
2177 if (val
== e
->values
[mux
])
2180 ucontrol
->value
.enumerated
.item
[1] = mux
;
2185 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2188 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2190 * @kcontrol: mixer control
2191 * @ucontrol: control element information
2193 * Callback to set the value of a dapm semi enumerated double mixer control.
2195 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2196 * used for handling bitfield coded enumeration for example.
2198 * Returns 0 for success.
2200 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2201 struct snd_ctl_elem_value
*ucontrol
)
2203 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2204 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2205 struct snd_soc_codec
*codec
= widget
->codec
;
2206 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2207 unsigned int val
, mux
, change
;
2209 struct snd_soc_dapm_update update
;
2212 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2214 mux
= ucontrol
->value
.enumerated
.item
[0];
2215 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2216 mask
= e
->mask
<< e
->shift_l
;
2217 if (e
->shift_l
!= e
->shift_r
) {
2218 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2220 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2221 mask
|= e
->mask
<< e
->shift_r
;
2224 mutex_lock(&codec
->mutex
);
2226 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2228 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2229 widget
= wlist
->widgets
[wi
];
2231 widget
->value
= val
;
2233 update
.kcontrol
= kcontrol
;
2234 update
.widget
= widget
;
2235 update
.reg
= e
->reg
;
2238 widget
->dapm
->update
= &update
;
2240 dapm_mux_update_power(widget
, kcontrol
, change
, mux
, e
);
2242 widget
->dapm
->update
= NULL
;
2246 mutex_unlock(&codec
->mutex
);
2249 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2252 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2254 * @kcontrol: mixer control
2255 * @uinfo: control element information
2257 * Callback to provide information about a pin switch control.
2259 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2260 struct snd_ctl_elem_info
*uinfo
)
2262 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2264 uinfo
->value
.integer
.min
= 0;
2265 uinfo
->value
.integer
.max
= 1;
2269 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2272 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2274 * @kcontrol: mixer control
2277 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2278 struct snd_ctl_elem_value
*ucontrol
)
2280 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2281 const char *pin
= (const char *)kcontrol
->private_value
;
2283 mutex_lock(&codec
->mutex
);
2285 ucontrol
->value
.integer
.value
[0] =
2286 snd_soc_dapm_get_pin_status(&codec
->dapm
, pin
);
2288 mutex_unlock(&codec
->mutex
);
2292 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2295 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2297 * @kcontrol: mixer control
2300 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2301 struct snd_ctl_elem_value
*ucontrol
)
2303 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2304 const char *pin
= (const char *)kcontrol
->private_value
;
2306 mutex_lock(&codec
->mutex
);
2308 if (ucontrol
->value
.integer
.value
[0])
2309 snd_soc_dapm_enable_pin(&codec
->dapm
, pin
);
2311 snd_soc_dapm_disable_pin(&codec
->dapm
, pin
);
2313 snd_soc_dapm_sync(&codec
->dapm
);
2315 mutex_unlock(&codec
->mutex
);
2319 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2322 * snd_soc_dapm_new_control - create new dapm control
2323 * @dapm: DAPM context
2324 * @widget: widget template
2326 * Creates a new dapm control based upon the template.
2328 * Returns 0 for success else error.
2330 int snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2331 const struct snd_soc_dapm_widget
*widget
)
2333 struct snd_soc_dapm_widget
*w
;
2336 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2339 name_len
= strlen(widget
->name
) + 1;
2340 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2341 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
2342 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
2343 if (w
->name
== NULL
) {
2347 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2348 snprintf(w
->name
, name_len
, "%s %s",
2349 dapm
->codec
->name_prefix
, widget
->name
);
2351 snprintf(w
->name
, name_len
, "%s", widget
->name
);
2355 w
->codec
= dapm
->codec
;
2356 INIT_LIST_HEAD(&w
->sources
);
2357 INIT_LIST_HEAD(&w
->sinks
);
2358 INIT_LIST_HEAD(&w
->list
);
2359 list_add(&w
->list
, &dapm
->card
->widgets
);
2361 /* machine layer set ups unconnected pins and insertions */
2365 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control
);
2368 * snd_soc_dapm_new_controls - create new dapm controls
2369 * @dapm: DAPM context
2370 * @widget: widget array
2371 * @num: number of widgets
2373 * Creates new DAPM controls based upon the templates.
2375 * Returns 0 for success else error.
2377 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
2378 const struct snd_soc_dapm_widget
*widget
,
2383 for (i
= 0; i
< num
; i
++) {
2384 ret
= snd_soc_dapm_new_control(dapm
, widget
);
2387 "ASoC: Failed to create DAPM control %s: %d\n",
2395 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
2397 static void soc_dapm_stream_event(struct snd_soc_dapm_context
*dapm
,
2398 const char *stream
, int event
)
2400 struct snd_soc_dapm_widget
*w
;
2402 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2404 if (!w
->sname
|| w
->dapm
!= dapm
)
2406 dev_dbg(w
->dapm
->dev
, "widget %s\n %s stream %s event %d\n",
2407 w
->name
, w
->sname
, stream
, event
);
2408 if (strstr(w
->sname
, stream
)) {
2410 case SND_SOC_DAPM_STREAM_START
:
2413 case SND_SOC_DAPM_STREAM_STOP
:
2416 case SND_SOC_DAPM_STREAM_SUSPEND
:
2417 case SND_SOC_DAPM_STREAM_RESUME
:
2418 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
2419 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
2425 dapm_power_widgets(dapm
, event
);
2429 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2430 * @rtd: PCM runtime data
2431 * @stream: stream name
2432 * @event: stream event
2434 * Sends a stream event to the dapm core. The core then makes any
2435 * necessary widget power changes.
2437 * Returns 0 for success else error.
2439 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
,
2440 const char *stream
, int event
)
2442 struct snd_soc_codec
*codec
= rtd
->codec
;
2447 mutex_lock(&codec
->mutex
);
2448 soc_dapm_stream_event(&codec
->dapm
, stream
, event
);
2449 mutex_unlock(&codec
->mutex
);
2454 * snd_soc_dapm_enable_pin - enable pin.
2455 * @dapm: DAPM context
2458 * Enables input/output pin and its parents or children widgets iff there is
2459 * a valid audio route and active audio stream.
2460 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2461 * do any widget power switching.
2463 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2465 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
2467 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
2470 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
2471 * @dapm: DAPM context
2474 * Enables input/output pin regardless of any other state. This is
2475 * intended for use with microphone bias supplies used in microphone
2478 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2479 * do any widget power switching.
2481 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
2484 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2487 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2491 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
2497 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
2500 * snd_soc_dapm_disable_pin - disable pin.
2501 * @dapm: DAPM context
2504 * Disables input/output pin and its parents or children widgets.
2505 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2506 * do any widget power switching.
2508 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
2511 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2513 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
2516 * snd_soc_dapm_nc_pin - permanently disable pin.
2517 * @dapm: DAPM context
2520 * Marks the specified pin as being not connected, disabling it along
2521 * any parent or child widgets. At present this is identical to
2522 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2523 * additional things such as disabling controls which only affect
2524 * paths through the pin.
2526 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2527 * do any widget power switching.
2529 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
2531 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
2533 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
2536 * snd_soc_dapm_get_pin_status - get audio pin status
2537 * @dapm: DAPM context
2538 * @pin: audio signal pin endpoint (or start point)
2540 * Get audio pin status - connected or disconnected.
2542 * Returns 1 for connected otherwise 0.
2544 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
2547 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
2550 return w
->connected
;
2554 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
2557 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2558 * @dapm: DAPM context
2559 * @pin: audio signal pin endpoint (or start point)
2561 * Mark the given endpoint or pin as ignoring suspend. When the
2562 * system is disabled a path between two endpoints flagged as ignoring
2563 * suspend will not be disabled. The path must already be enabled via
2564 * normal means at suspend time, it will not be turned on if it was not
2567 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
2570 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
2573 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
2577 w
->ignore_suspend
= 1;
2581 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
2584 * snd_soc_dapm_free - free dapm resources
2587 * Free all dapm widgets and resources.
2589 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
2591 snd_soc_dapm_sys_remove(dapm
->dev
);
2592 dapm_debugfs_cleanup(dapm
);
2593 dapm_free_widgets(dapm
);
2594 list_del(&dapm
->list
);
2596 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
2598 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
2600 struct snd_soc_dapm_widget
*w
;
2601 LIST_HEAD(down_list
);
2604 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
2605 if (w
->dapm
!= dapm
)
2608 dapm_seq_insert(w
, &down_list
, false);
2614 /* If there were no widgets to power down we're already in
2618 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_PREPARE
);
2619 dapm_seq_run(dapm
, &down_list
, 0, false);
2620 snd_soc_dapm_set_bias_level(dapm
, SND_SOC_BIAS_STANDBY
);
2625 * snd_soc_dapm_shutdown - callback for system shutdown
2627 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
2629 struct snd_soc_codec
*codec
;
2631 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
2632 soc_dapm_shutdown_codec(&codec
->dapm
);
2633 snd_soc_dapm_set_bias_level(&codec
->dapm
, SND_SOC_BIAS_OFF
);
2637 /* Module information */
2638 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2639 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2640 MODULE_LICENSE("GPL");