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/headphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
21 * o Delayed power down of audio subsystem to reduce pops between a quick
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/init.h>
29 #include <linux/async.h>
30 #include <linux/delay.h>
32 #include <linux/bitops.h>
33 #include <linux/platform_device.h>
34 #include <linux/jiffies.h>
35 #include <linux/debugfs.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/regulator/consumer.h>
38 #include <linux/slab.h>
39 #include <sound/core.h>
40 #include <sound/pcm.h>
41 #include <sound/pcm_params.h>
42 #include <sound/soc.h>
43 #include <sound/initval.h>
45 #include <trace/events/asoc.h>
47 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
49 /* dapm power sequences - make this per codec in the future */
50 static int dapm_up_seq
[] = {
51 [snd_soc_dapm_pre
] = 0,
52 [snd_soc_dapm_supply
] = 1,
53 [snd_soc_dapm_regulator_supply
] = 1,
54 [snd_soc_dapm_micbias
] = 2,
55 [snd_soc_dapm_dai
] = 3,
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_dai
] = 10,
91 [snd_soc_dapm_regulator_supply
] = 11,
92 [snd_soc_dapm_supply
] = 11,
93 [snd_soc_dapm_post
] = 12,
96 static void pop_wait(u32 pop_time
)
99 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time
));
102 static void pop_dbg(struct device
*dev
, u32 pop_time
, const char *fmt
, ...)
110 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
115 vsnprintf(buf
, PAGE_SIZE
, fmt
, args
);
116 dev_info(dev
, "%s", buf
);
122 static bool dapm_dirty_widget(struct snd_soc_dapm_widget
*w
)
124 return !list_empty(&w
->dirty
);
127 void dapm_mark_dirty(struct snd_soc_dapm_widget
*w
, const char *reason
)
129 if (!dapm_dirty_widget(w
)) {
130 dev_vdbg(w
->dapm
->dev
, "Marking %s dirty due to %s\n",
132 list_add_tail(&w
->dirty
, &w
->dapm
->card
->dapm_dirty
);
135 EXPORT_SYMBOL_GPL(dapm_mark_dirty
);
137 /* create a new dapm widget */
138 static inline struct snd_soc_dapm_widget
*dapm_cnew_widget(
139 const struct snd_soc_dapm_widget
*_widget
)
141 return kmemdup(_widget
, sizeof(*_widget
), GFP_KERNEL
);
144 /* get snd_card from DAPM context */
145 static inline struct snd_card
*dapm_get_snd_card(
146 struct snd_soc_dapm_context
*dapm
)
149 return dapm
->codec
->card
->snd_card
;
150 else if (dapm
->platform
)
151 return dapm
->platform
->card
->snd_card
;
159 /* get soc_card from DAPM context */
160 static inline struct snd_soc_card
*dapm_get_soc_card(
161 struct snd_soc_dapm_context
*dapm
)
164 return dapm
->codec
->card
;
165 else if (dapm
->platform
)
166 return dapm
->platform
->card
;
174 static void dapm_reset(struct snd_soc_card
*card
)
176 struct snd_soc_dapm_widget
*w
;
178 memset(&card
->dapm_stats
, 0, sizeof(card
->dapm_stats
));
180 list_for_each_entry(w
, &card
->widgets
, list
) {
181 w
->power_checked
= false;
187 static int soc_widget_read(struct snd_soc_dapm_widget
*w
, int reg
)
190 return snd_soc_read(w
->codec
, reg
);
191 else if (w
->platform
)
192 return snd_soc_platform_read(w
->platform
, reg
);
194 dev_err(w
->dapm
->dev
, "no valid widget read method\n");
198 static int soc_widget_write(struct snd_soc_dapm_widget
*w
, int reg
, int val
)
201 return snd_soc_write(w
->codec
, reg
, val
);
202 else if (w
->platform
)
203 return snd_soc_platform_write(w
->platform
, reg
, val
);
205 dev_err(w
->dapm
->dev
, "no valid widget write method\n");
209 static int soc_widget_update_bits(struct snd_soc_dapm_widget
*w
,
210 unsigned short reg
, unsigned int mask
, unsigned int value
)
213 unsigned int old
, new;
216 if (w
->codec
&& w
->codec
->using_regmap
) {
217 ret
= regmap_update_bits_check(w
->codec
->control_data
,
218 reg
, mask
, value
, &change
);
222 ret
= soc_widget_read(w
, reg
);
227 new = (old
& ~mask
) | (value
& mask
);
230 ret
= soc_widget_write(w
, reg
, new);
240 * snd_soc_dapm_set_bias_level - set the bias level for the system
241 * @dapm: DAPM context
242 * @level: level to configure
244 * Configure the bias (power) levels for the SoC audio device.
246 * Returns 0 for success else error.
248 static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context
*dapm
,
249 enum snd_soc_bias_level level
)
251 struct snd_soc_card
*card
= dapm
->card
;
254 trace_snd_soc_bias_level_start(card
, level
);
256 if (card
&& card
->set_bias_level
)
257 ret
= card
->set_bias_level(card
, dapm
, level
);
262 if (dapm
->codec
->driver
->set_bias_level
)
263 ret
= dapm
->codec
->driver
->set_bias_level(dapm
->codec
,
266 dapm
->bias_level
= level
;
271 if (card
&& card
->set_bias_level_post
)
272 ret
= card
->set_bias_level_post(card
, dapm
, level
);
274 trace_snd_soc_bias_level_done(card
, level
);
279 /* set up initial codec paths */
280 static void dapm_set_path_status(struct snd_soc_dapm_widget
*w
,
281 struct snd_soc_dapm_path
*p
, int i
)
284 case snd_soc_dapm_switch
:
285 case snd_soc_dapm_mixer
:
286 case snd_soc_dapm_mixer_named_ctl
: {
288 struct soc_mixer_control
*mc
= (struct soc_mixer_control
*)
289 w
->kcontrol_news
[i
].private_value
;
290 unsigned int reg
= mc
->reg
;
291 unsigned int shift
= mc
->shift
;
293 unsigned int mask
= (1 << fls(max
)) - 1;
294 unsigned int invert
= mc
->invert
;
296 val
= soc_widget_read(w
, reg
);
297 val
= (val
>> shift
) & mask
;
299 if ((invert
&& !val
) || (!invert
&& val
))
305 case snd_soc_dapm_mux
: {
306 struct soc_enum
*e
= (struct soc_enum
*)
307 w
->kcontrol_news
[i
].private_value
;
308 int val
, item
, bitmask
;
310 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
312 val
= soc_widget_read(w
, e
->reg
);
313 item
= (val
>> e
->shift_l
) & (bitmask
- 1);
316 for (i
= 0; i
< e
->max
; i
++) {
317 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
322 case snd_soc_dapm_virt_mux
: {
323 struct soc_enum
*e
= (struct soc_enum
*)
324 w
->kcontrol_news
[i
].private_value
;
327 /* since a virtual mux has no backing registers to
328 * decide which path to connect, it will try to match
329 * with the first enumeration. This is to ensure
330 * that the default mux choice (the first) will be
331 * correctly powered up during initialization.
333 if (!strcmp(p
->name
, e
->texts
[0]))
337 case snd_soc_dapm_value_mux
: {
338 struct soc_enum
*e
= (struct soc_enum
*)
339 w
->kcontrol_news
[i
].private_value
;
342 val
= soc_widget_read(w
, e
->reg
);
343 val
= (val
>> e
->shift_l
) & e
->mask
;
344 for (item
= 0; item
< e
->max
; item
++) {
345 if (val
== e
->values
[item
])
350 for (i
= 0; i
< e
->max
; i
++) {
351 if (!(strcmp(p
->name
, e
->texts
[i
])) && item
== i
)
356 /* does not affect routing - always connected */
357 case snd_soc_dapm_pga
:
358 case snd_soc_dapm_out_drv
:
359 case snd_soc_dapm_output
:
360 case snd_soc_dapm_adc
:
361 case snd_soc_dapm_input
:
362 case snd_soc_dapm_siggen
:
363 case snd_soc_dapm_dac
:
364 case snd_soc_dapm_micbias
:
365 case snd_soc_dapm_vmid
:
366 case snd_soc_dapm_supply
:
367 case snd_soc_dapm_regulator_supply
:
368 case snd_soc_dapm_aif_in
:
369 case snd_soc_dapm_aif_out
:
370 case snd_soc_dapm_dai
:
371 case snd_soc_dapm_hp
:
372 case snd_soc_dapm_mic
:
373 case snd_soc_dapm_spk
:
374 case snd_soc_dapm_line
:
377 /* does affect routing - dynamically connected */
378 case snd_soc_dapm_pre
:
379 case snd_soc_dapm_post
:
385 /* connect mux widget to its interconnecting audio paths */
386 static int dapm_connect_mux(struct snd_soc_dapm_context
*dapm
,
387 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
388 struct snd_soc_dapm_path
*path
, const char *control_name
,
389 const struct snd_kcontrol_new
*kcontrol
)
391 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
394 for (i
= 0; i
< e
->max
; i
++) {
395 if (!(strcmp(control_name
, e
->texts
[i
]))) {
396 list_add(&path
->list
, &dapm
->card
->paths
);
397 list_add(&path
->list_sink
, &dest
->sources
);
398 list_add(&path
->list_source
, &src
->sinks
);
399 path
->name
= (char*)e
->texts
[i
];
400 dapm_set_path_status(dest
, path
, 0);
408 /* connect mixer widget to its interconnecting audio paths */
409 static int dapm_connect_mixer(struct snd_soc_dapm_context
*dapm
,
410 struct snd_soc_dapm_widget
*src
, struct snd_soc_dapm_widget
*dest
,
411 struct snd_soc_dapm_path
*path
, const char *control_name
)
415 /* search for mixer kcontrol */
416 for (i
= 0; i
< dest
->num_kcontrols
; i
++) {
417 if (!strcmp(control_name
, dest
->kcontrol_news
[i
].name
)) {
418 list_add(&path
->list
, &dapm
->card
->paths
);
419 list_add(&path
->list_sink
, &dest
->sources
);
420 list_add(&path
->list_source
, &src
->sinks
);
421 path
->name
= dest
->kcontrol_news
[i
].name
;
422 dapm_set_path_status(dest
, path
, i
);
429 static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context
*dapm
,
430 struct snd_soc_dapm_widget
*kcontrolw
,
431 const struct snd_kcontrol_new
*kcontrol_new
,
432 struct snd_kcontrol
**kcontrol
)
434 struct snd_soc_dapm_widget
*w
;
439 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
440 if (w
== kcontrolw
|| w
->dapm
!= kcontrolw
->dapm
)
442 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
443 if (&w
->kcontrol_news
[i
] == kcontrol_new
) {
445 *kcontrol
= w
->kcontrols
[i
];
454 /* create new dapm mixer control */
455 static int dapm_new_mixer(struct snd_soc_dapm_widget
*w
)
457 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
459 size_t name_len
, prefix_len
;
460 struct snd_soc_dapm_path
*path
;
461 struct snd_card
*card
= dapm
->card
->snd_card
;
463 struct snd_soc_dapm_widget_list
*wlist
;
467 prefix
= dapm
->codec
->name_prefix
;
472 prefix_len
= strlen(prefix
) + 1;
477 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
480 list_for_each_entry(path
, &w
->sources
, list_sink
) {
482 /* mixer/mux paths name must match control name */
483 if (path
->name
!= (char *)w
->kcontrol_news
[i
].name
)
486 if (w
->kcontrols
[i
]) {
487 path
->kcontrol
= w
->kcontrols
[i
];
491 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
492 sizeof(struct snd_soc_dapm_widget
*),
493 wlist
= kzalloc(wlistsize
, GFP_KERNEL
);
496 "asoc: can't allocate widget list for %s\n",
500 wlist
->num_widgets
= 1;
501 wlist
->widgets
[0] = w
;
503 /* add dapm control with long name.
504 * for dapm_mixer this is the concatenation of the
505 * mixer and kcontrol name.
506 * for dapm_mixer_named_ctl this is simply the
509 name_len
= strlen(w
->kcontrol_news
[i
].name
) + 1;
510 if (w
->id
!= snd_soc_dapm_mixer_named_ctl
)
511 name_len
+= 1 + strlen(w
->name
);
513 path
->long_name
= kmalloc(name_len
, GFP_KERNEL
);
515 if (path
->long_name
== NULL
) {
522 /* The control will get a prefix from
523 * the control creation process but
524 * we're also using the same prefix
525 * for widgets so cut the prefix off
526 * the front of the widget name.
528 snprintf((char *)path
->long_name
, name_len
,
529 "%s %s", w
->name
+ prefix_len
,
530 w
->kcontrol_news
[i
].name
);
532 case snd_soc_dapm_mixer_named_ctl
:
533 snprintf((char *)path
->long_name
, name_len
,
534 "%s", w
->kcontrol_news
[i
].name
);
538 ((char *)path
->long_name
)[name_len
- 1] = '\0';
540 path
->kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[i
],
541 wlist
, path
->long_name
,
543 ret
= snd_ctl_add(card
, path
->kcontrol
);
546 "asoc: failed to add dapm kcontrol %s: %d\n",
547 path
->long_name
, ret
);
549 kfree(path
->long_name
);
550 path
->long_name
= NULL
;
553 w
->kcontrols
[i
] = path
->kcontrol
;
559 /* create new dapm mux control */
560 static int dapm_new_mux(struct snd_soc_dapm_widget
*w
)
562 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
563 struct snd_soc_dapm_path
*path
= NULL
;
564 struct snd_kcontrol
*kcontrol
;
565 struct snd_card
*card
= dapm
->card
->snd_card
;
569 struct snd_soc_dapm_widget_list
*wlist
;
570 int shared
, wlistentries
;
574 if (w
->num_kcontrols
!= 1) {
576 "asoc: mux %s has incorrect number of controls\n",
581 shared
= dapm_is_shared_kcontrol(dapm
, w
, &w
->kcontrol_news
[0],
584 wlist
= kcontrol
->private_data
;
585 wlistentries
= wlist
->num_widgets
+ 1;
590 wlistsize
= sizeof(struct snd_soc_dapm_widget_list
) +
591 wlistentries
* sizeof(struct snd_soc_dapm_widget
*),
592 wlist
= krealloc(wlist
, wlistsize
, GFP_KERNEL
);
595 "asoc: can't allocate widget list for %s\n", w
->name
);
598 wlist
->num_widgets
= wlistentries
;
599 wlist
->widgets
[wlistentries
- 1] = w
;
603 prefix
= dapm
->codec
->name_prefix
;
608 name
= w
->kcontrol_news
[0].name
;
613 prefix_len
= strlen(prefix
) + 1;
619 * The control will get a prefix from the control creation
620 * process but we're also using the same prefix for widgets so
621 * cut the prefix off the front of the widget name.
623 kcontrol
= snd_soc_cnew(&w
->kcontrol_news
[0], wlist
,
624 name
+ prefix_len
, prefix
);
625 ret
= snd_ctl_add(card
, kcontrol
);
627 dev_err(dapm
->dev
, "failed to add kcontrol %s: %d\n",
634 kcontrol
->private_data
= wlist
;
636 w
->kcontrols
[0] = kcontrol
;
638 list_for_each_entry(path
, &w
->sources
, list_sink
)
639 path
->kcontrol
= kcontrol
;
644 /* create new dapm volume control */
645 static int dapm_new_pga(struct snd_soc_dapm_widget
*w
)
647 if (w
->num_kcontrols
)
648 dev_err(w
->dapm
->dev
,
649 "asoc: PGA controls not supported: '%s'\n", w
->name
);
654 /* reset 'walked' bit for each dapm path */
655 static inline void dapm_clear_walk(struct snd_soc_dapm_context
*dapm
)
657 struct snd_soc_dapm_path
*p
;
659 list_for_each_entry(p
, &dapm
->card
->paths
, list
)
663 /* We implement power down on suspend by checking the power state of
664 * the ALSA card - when we are suspending the ALSA state for the card
667 static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget
*widget
)
669 int level
= snd_power_get_state(widget
->dapm
->card
->snd_card
);
672 case SNDRV_CTL_POWER_D3hot
:
673 case SNDRV_CTL_POWER_D3cold
:
674 if (widget
->ignore_suspend
)
675 dev_dbg(widget
->dapm
->dev
, "%s ignoring suspend\n",
677 return widget
->ignore_suspend
;
684 * Recursively check for a completed path to an active or physically connected
685 * output widget. Returns number of complete paths.
687 static int is_connected_output_ep(struct snd_soc_dapm_widget
*widget
)
689 struct snd_soc_dapm_path
*path
;
692 if (widget
->outputs
>= 0)
693 return widget
->outputs
;
695 DAPM_UPDATE_STAT(widget
, path_checks
);
697 switch (widget
->id
) {
698 case snd_soc_dapm_supply
:
699 case snd_soc_dapm_regulator_supply
:
705 switch (widget
->id
) {
706 case snd_soc_dapm_adc
:
707 case snd_soc_dapm_aif_out
:
708 case snd_soc_dapm_dai
:
709 if (widget
->active
) {
710 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
711 return widget
->outputs
;
717 if (widget
->connected
) {
718 /* connected pin ? */
719 if (widget
->id
== snd_soc_dapm_output
&& !widget
->ext
) {
720 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
721 return widget
->outputs
;
724 /* connected jack or spk ? */
725 if (widget
->id
== snd_soc_dapm_hp
||
726 widget
->id
== snd_soc_dapm_spk
||
727 (widget
->id
== snd_soc_dapm_line
&&
728 !list_empty(&widget
->sources
))) {
729 widget
->outputs
= snd_soc_dapm_suspend_check(widget
);
730 return widget
->outputs
;
734 list_for_each_entry(path
, &widget
->sinks
, list_source
) {
735 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
743 if (path
->sink
&& path
->connect
) {
745 con
+= is_connected_output_ep(path
->sink
);
749 widget
->outputs
= con
;
755 * Recursively check for a completed path to an active or physically connected
756 * input widget. Returns number of complete paths.
758 static int is_connected_input_ep(struct snd_soc_dapm_widget
*widget
)
760 struct snd_soc_dapm_path
*path
;
763 if (widget
->inputs
>= 0)
764 return widget
->inputs
;
766 DAPM_UPDATE_STAT(widget
, path_checks
);
768 switch (widget
->id
) {
769 case snd_soc_dapm_supply
:
770 case snd_soc_dapm_regulator_supply
:
776 /* active stream ? */
777 switch (widget
->id
) {
778 case snd_soc_dapm_dac
:
779 case snd_soc_dapm_aif_in
:
780 case snd_soc_dapm_dai
:
781 if (widget
->active
) {
782 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
783 return widget
->inputs
;
789 if (widget
->connected
) {
790 /* connected pin ? */
791 if (widget
->id
== snd_soc_dapm_input
&& !widget
->ext
) {
792 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
793 return widget
->inputs
;
796 /* connected VMID/Bias for lower pops */
797 if (widget
->id
== snd_soc_dapm_vmid
) {
798 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
799 return widget
->inputs
;
802 /* connected jack ? */
803 if (widget
->id
== snd_soc_dapm_mic
||
804 (widget
->id
== snd_soc_dapm_line
&&
805 !list_empty(&widget
->sinks
))) {
806 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
807 return widget
->inputs
;
810 /* signal generator */
811 if (widget
->id
== snd_soc_dapm_siggen
) {
812 widget
->inputs
= snd_soc_dapm_suspend_check(widget
);
813 return widget
->inputs
;
817 list_for_each_entry(path
, &widget
->sources
, list_sink
) {
818 DAPM_UPDATE_STAT(widget
, neighbour_checks
);
826 if (path
->source
&& path
->connect
) {
828 con
+= is_connected_input_ep(path
->source
);
832 widget
->inputs
= con
;
838 * Handler for generic register modifier widget.
840 int dapm_reg_event(struct snd_soc_dapm_widget
*w
,
841 struct snd_kcontrol
*kcontrol
, int event
)
845 if (SND_SOC_DAPM_EVENT_ON(event
))
850 soc_widget_update_bits(w
, -(w
->reg
+ 1),
851 w
->mask
<< w
->shift
, val
<< w
->shift
);
855 EXPORT_SYMBOL_GPL(dapm_reg_event
);
858 * Handler for regulator supply widget.
860 int dapm_regulator_event(struct snd_soc_dapm_widget
*w
,
861 struct snd_kcontrol
*kcontrol
, int event
)
863 if (SND_SOC_DAPM_EVENT_ON(event
))
864 return regulator_enable(w
->priv
);
866 return regulator_disable_deferred(w
->priv
, w
->shift
);
868 EXPORT_SYMBOL_GPL(dapm_regulator_event
);
870 static int dapm_widget_power_check(struct snd_soc_dapm_widget
*w
)
872 if (w
->power_checked
)
878 w
->new_power
= w
->power_check(w
);
880 w
->power_checked
= true;
885 /* Generic check to see if a widget should be powered.
887 static int dapm_generic_check_power(struct snd_soc_dapm_widget
*w
)
891 DAPM_UPDATE_STAT(w
, power_checks
);
893 in
= is_connected_input_ep(w
);
894 dapm_clear_walk(w
->dapm
);
895 out
= is_connected_output_ep(w
);
896 dapm_clear_walk(w
->dapm
);
897 return out
!= 0 && in
!= 0;
900 static int dapm_dai_check_power(struct snd_soc_dapm_widget
*w
)
902 DAPM_UPDATE_STAT(w
, power_checks
);
907 /* Check to see if an ADC has power */
908 static int dapm_adc_check_power(struct snd_soc_dapm_widget
*w
)
912 DAPM_UPDATE_STAT(w
, power_checks
);
915 in
= is_connected_input_ep(w
);
916 dapm_clear_walk(w
->dapm
);
919 return dapm_generic_check_power(w
);
923 /* Check to see if a DAC has power */
924 static int dapm_dac_check_power(struct snd_soc_dapm_widget
*w
)
928 DAPM_UPDATE_STAT(w
, power_checks
);
931 out
= is_connected_output_ep(w
);
932 dapm_clear_walk(w
->dapm
);
935 return dapm_generic_check_power(w
);
939 /* Check to see if a power supply is needed */
940 static int dapm_supply_check_power(struct snd_soc_dapm_widget
*w
)
942 struct snd_soc_dapm_path
*path
;
944 DAPM_UPDATE_STAT(w
, power_checks
);
946 /* Check if one of our outputs is connected */
947 list_for_each_entry(path
, &w
->sinks
, list_source
) {
948 DAPM_UPDATE_STAT(w
, neighbour_checks
);
953 if (path
->connected
&&
954 !path
->connected(path
->source
, path
->sink
))
960 if (dapm_widget_power_check(path
->sink
))
964 dapm_clear_walk(w
->dapm
);
969 static int dapm_always_on_check_power(struct snd_soc_dapm_widget
*w
)
974 static int dapm_seq_compare(struct snd_soc_dapm_widget
*a
,
975 struct snd_soc_dapm_widget
*b
,
983 sort
= dapm_down_seq
;
985 if (sort
[a
->id
] != sort
[b
->id
])
986 return sort
[a
->id
] - sort
[b
->id
];
987 if (a
->subseq
!= b
->subseq
) {
989 return a
->subseq
- b
->subseq
;
991 return b
->subseq
- a
->subseq
;
993 if (a
->reg
!= b
->reg
)
994 return a
->reg
- b
->reg
;
995 if (a
->dapm
!= b
->dapm
)
996 return (unsigned long)a
->dapm
- (unsigned long)b
->dapm
;
1001 /* Insert a widget in order into a DAPM power sequence. */
1002 static void dapm_seq_insert(struct snd_soc_dapm_widget
*new_widget
,
1003 struct list_head
*list
,
1006 struct snd_soc_dapm_widget
*w
;
1008 list_for_each_entry(w
, list
, power_list
)
1009 if (dapm_seq_compare(new_widget
, w
, power_up
) < 0) {
1010 list_add_tail(&new_widget
->power_list
, &w
->power_list
);
1014 list_add_tail(&new_widget
->power_list
, list
);
1017 static void dapm_seq_check_event(struct snd_soc_dapm_context
*dapm
,
1018 struct snd_soc_dapm_widget
*w
, int event
)
1020 struct snd_soc_card
*card
= dapm
->card
;
1021 const char *ev_name
;
1025 case SND_SOC_DAPM_PRE_PMU
:
1026 ev_name
= "PRE_PMU";
1029 case SND_SOC_DAPM_POST_PMU
:
1030 ev_name
= "POST_PMU";
1033 case SND_SOC_DAPM_PRE_PMD
:
1034 ev_name
= "PRE_PMD";
1037 case SND_SOC_DAPM_POST_PMD
:
1038 ev_name
= "POST_PMD";
1046 if (w
->power
!= power
)
1049 if (w
->event
&& (w
->event_flags
& event
)) {
1050 pop_dbg(dapm
->dev
, card
->pop_time
, "pop test : %s %s\n",
1052 trace_snd_soc_dapm_widget_event_start(w
, event
);
1053 ret
= w
->event(w
, NULL
, event
);
1054 trace_snd_soc_dapm_widget_event_done(w
, event
);
1056 pr_err("%s: %s event failed: %d\n",
1057 ev_name
, w
->name
, ret
);
1061 /* Apply the coalesced changes from a DAPM sequence */
1062 static void dapm_seq_run_coalesced(struct snd_soc_dapm_context
*dapm
,
1063 struct list_head
*pending
)
1065 struct snd_soc_card
*card
= dapm
->card
;
1066 struct snd_soc_dapm_widget
*w
;
1068 unsigned int value
= 0;
1069 unsigned int mask
= 0;
1070 unsigned int cur_mask
;
1072 reg
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1075 list_for_each_entry(w
, pending
, power_list
) {
1076 cur_mask
= 1 << w
->shift
;
1077 BUG_ON(reg
!= w
->reg
);
1088 pop_dbg(dapm
->dev
, card
->pop_time
,
1089 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1090 w
->name
, reg
, value
, mask
);
1092 /* Check for events */
1093 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMU
);
1094 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_PRE_PMD
);
1098 /* Any widget will do, they should all be updating the
1101 w
= list_first_entry(pending
, struct snd_soc_dapm_widget
,
1104 pop_dbg(dapm
->dev
, card
->pop_time
,
1105 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1106 value
, mask
, reg
, card
->pop_time
);
1107 pop_wait(card
->pop_time
);
1108 soc_widget_update_bits(w
, reg
, mask
, value
);
1111 list_for_each_entry(w
, pending
, power_list
) {
1112 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMU
);
1113 dapm_seq_check_event(dapm
, w
, SND_SOC_DAPM_POST_PMD
);
1117 /* Apply a DAPM power sequence.
1119 * We walk over a pre-sorted list of widgets to apply power to. In
1120 * order to minimise the number of writes to the device required
1121 * multiple widgets will be updated in a single write where possible.
1122 * Currently anything that requires more than a single write is not
1125 static void dapm_seq_run(struct snd_soc_dapm_context
*dapm
,
1126 struct list_head
*list
, int event
, bool power_up
)
1128 struct snd_soc_dapm_widget
*w
, *n
;
1131 int cur_subseq
= -1;
1132 int cur_reg
= SND_SOC_NOPM
;
1133 struct snd_soc_dapm_context
*cur_dapm
= NULL
;
1140 sort
= dapm_down_seq
;
1142 list_for_each_entry_safe(w
, n
, list
, power_list
) {
1145 /* Do we need to apply any queued changes? */
1146 if (sort
[w
->id
] != cur_sort
|| w
->reg
!= cur_reg
||
1147 w
->dapm
!= cur_dapm
|| w
->subseq
!= cur_subseq
) {
1148 if (!list_empty(&pending
))
1149 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1151 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1152 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1153 if (sort
[i
] == cur_sort
)
1154 cur_dapm
->seq_notifier(cur_dapm
,
1159 INIT_LIST_HEAD(&pending
);
1161 cur_subseq
= INT_MIN
;
1162 cur_reg
= SND_SOC_NOPM
;
1167 case snd_soc_dapm_pre
:
1169 list_for_each_entry_safe_continue(w
, n
, list
,
1172 if (event
== SND_SOC_DAPM_STREAM_START
)
1174 NULL
, SND_SOC_DAPM_PRE_PMU
);
1175 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1177 NULL
, SND_SOC_DAPM_PRE_PMD
);
1180 case snd_soc_dapm_post
:
1182 list_for_each_entry_safe_continue(w
, n
, list
,
1185 if (event
== SND_SOC_DAPM_STREAM_START
)
1187 NULL
, SND_SOC_DAPM_POST_PMU
);
1188 else if (event
== SND_SOC_DAPM_STREAM_STOP
)
1190 NULL
, SND_SOC_DAPM_POST_PMD
);
1194 /* Queue it up for application */
1195 cur_sort
= sort
[w
->id
];
1196 cur_subseq
= w
->subseq
;
1199 list_move(&w
->power_list
, &pending
);
1204 dev_err(w
->dapm
->dev
,
1205 "Failed to apply widget power: %d\n", ret
);
1208 if (!list_empty(&pending
))
1209 dapm_seq_run_coalesced(cur_dapm
, &pending
);
1211 if (cur_dapm
&& cur_dapm
->seq_notifier
) {
1212 for (i
= 0; i
< ARRAY_SIZE(dapm_up_seq
); i
++)
1213 if (sort
[i
] == cur_sort
)
1214 cur_dapm
->seq_notifier(cur_dapm
,
1219 static void dapm_widget_update(struct snd_soc_dapm_context
*dapm
)
1221 struct snd_soc_dapm_update
*update
= dapm
->update
;
1222 struct snd_soc_dapm_widget
*w
;
1231 (w
->event_flags
& SND_SOC_DAPM_PRE_REG
)) {
1232 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_PRE_REG
);
1234 pr_err("%s DAPM pre-event failed: %d\n",
1238 ret
= snd_soc_update_bits(w
->codec
, update
->reg
, update
->mask
,
1241 pr_err("%s DAPM update failed: %d\n", w
->name
, ret
);
1244 (w
->event_flags
& SND_SOC_DAPM_POST_REG
)) {
1245 ret
= w
->event(w
, update
->kcontrol
, SND_SOC_DAPM_POST_REG
);
1247 pr_err("%s DAPM post-event failed: %d\n",
1252 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1253 * they're changing state.
1255 static void dapm_pre_sequence_async(void *data
, async_cookie_t cookie
)
1257 struct snd_soc_dapm_context
*d
= data
;
1260 /* If we're off and we're not supposed to be go into STANDBY */
1261 if (d
->bias_level
== SND_SOC_BIAS_OFF
&&
1262 d
->target_bias_level
!= SND_SOC_BIAS_OFF
) {
1264 pm_runtime_get_sync(d
->dev
);
1266 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1269 "Failed to turn on bias: %d\n", ret
);
1272 /* Prepare for a STADDBY->ON or ON->STANDBY transition */
1273 if (d
->bias_level
!= d
->target_bias_level
) {
1274 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_PREPARE
);
1277 "Failed to prepare bias: %d\n", ret
);
1281 /* Async callback run prior to DAPM sequences - brings to their final
1284 static void dapm_post_sequence_async(void *data
, async_cookie_t cookie
)
1286 struct snd_soc_dapm_context
*d
= data
;
1289 /* If we just powered the last thing off drop to standby bias */
1290 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1291 (d
->target_bias_level
== SND_SOC_BIAS_STANDBY
||
1292 d
->target_bias_level
== SND_SOC_BIAS_OFF
)) {
1293 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_STANDBY
);
1295 dev_err(d
->dev
, "Failed to apply standby bias: %d\n",
1299 /* If we're in standby and can support bias off then do that */
1300 if (d
->bias_level
== SND_SOC_BIAS_STANDBY
&&
1301 d
->target_bias_level
== SND_SOC_BIAS_OFF
) {
1302 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_OFF
);
1304 dev_err(d
->dev
, "Failed to turn off bias: %d\n", ret
);
1307 pm_runtime_put(d
->dev
);
1310 /* If we just powered up then move to active bias */
1311 if (d
->bias_level
== SND_SOC_BIAS_PREPARE
&&
1312 d
->target_bias_level
== SND_SOC_BIAS_ON
) {
1313 ret
= snd_soc_dapm_set_bias_level(d
, SND_SOC_BIAS_ON
);
1315 dev_err(d
->dev
, "Failed to apply active bias: %d\n",
1320 static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget
*peer
,
1321 bool power
, bool connect
)
1323 /* If a connection is being made or broken then that update
1324 * will have marked the peer dirty, otherwise the widgets are
1325 * not connected and this update has no impact. */
1329 /* If the peer is already in the state we're moving to then we
1330 * won't have an impact on it. */
1331 if (power
!= peer
->power
)
1332 dapm_mark_dirty(peer
, "peer state change");
1335 static void dapm_widget_set_power(struct snd_soc_dapm_widget
*w
, bool power
,
1336 struct list_head
*up_list
,
1337 struct list_head
*down_list
)
1339 struct snd_soc_dapm_path
*path
;
1341 if (w
->power
== power
)
1344 trace_snd_soc_dapm_widget_power(w
, power
);
1346 /* If we changed our power state perhaps our neigbours changed
1349 list_for_each_entry(path
, &w
->sources
, list_sink
) {
1351 dapm_widget_set_peer_power(path
->source
, power
,
1356 case snd_soc_dapm_supply
:
1357 case snd_soc_dapm_regulator_supply
:
1358 /* Supplies can't affect their outputs, only their inputs */
1361 list_for_each_entry(path
, &w
->sinks
, list_source
) {
1363 dapm_widget_set_peer_power(path
->sink
, power
,
1371 dapm_seq_insert(w
, up_list
, true);
1373 dapm_seq_insert(w
, down_list
, false);
1378 static void dapm_power_one_widget(struct snd_soc_dapm_widget
*w
,
1379 struct list_head
*up_list
,
1380 struct list_head
*down_list
)
1385 case snd_soc_dapm_pre
:
1386 dapm_seq_insert(w
, down_list
, false);
1388 case snd_soc_dapm_post
:
1389 dapm_seq_insert(w
, up_list
, true);
1393 power
= dapm_widget_power_check(w
);
1395 dapm_widget_set_power(w
, power
, up_list
, down_list
);
1401 * Scan each dapm widget for complete audio path.
1402 * A complete path is a route that has valid endpoints i.e.:-
1404 * o DAC to output pin.
1405 * o Input Pin to ADC.
1406 * o Input pin to Output pin (bypass, sidetone)
1407 * o DAC to ADC (loopback).
1409 static int dapm_power_widgets(struct snd_soc_dapm_context
*dapm
, int event
)
1411 struct snd_soc_card
*card
= dapm
->card
;
1412 struct snd_soc_dapm_widget
*w
;
1413 struct snd_soc_dapm_context
*d
;
1415 LIST_HEAD(down_list
);
1416 LIST_HEAD(async_domain
);
1417 enum snd_soc_bias_level bias
;
1419 trace_snd_soc_dapm_start(card
);
1421 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1422 if (d
->n_widgets
|| d
->codec
== NULL
) {
1423 if (d
->idle_bias_off
)
1424 d
->target_bias_level
= SND_SOC_BIAS_OFF
;
1426 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1432 /* Check which widgets we need to power and store them in
1433 * lists indicating if they should be powered up or down. We
1434 * only check widgets that have been flagged as dirty but note
1435 * that new widgets may be added to the dirty list while we
1438 list_for_each_entry(w
, &card
->dapm_dirty
, dirty
) {
1439 dapm_power_one_widget(w
, &up_list
, &down_list
);
1442 list_for_each_entry(w
, &card
->widgets
, list
) {
1443 list_del_init(&w
->dirty
);
1448 /* Supplies and micbiases only bring the
1449 * context up to STANDBY as unless something
1450 * else is active and passing audio they
1451 * generally don't require full power. Signal
1452 * generators are virtual pins and have no
1453 * power impact themselves.
1456 case snd_soc_dapm_siggen
:
1458 case snd_soc_dapm_supply
:
1459 case snd_soc_dapm_regulator_supply
:
1460 case snd_soc_dapm_micbias
:
1461 if (d
->target_bias_level
< SND_SOC_BIAS_STANDBY
)
1462 d
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1465 d
->target_bias_level
= SND_SOC_BIAS_ON
;
1472 /* If there are no DAPM widgets then try to figure out power from the
1475 if (!dapm
->n_widgets
) {
1477 case SND_SOC_DAPM_STREAM_START
:
1478 case SND_SOC_DAPM_STREAM_RESUME
:
1479 dapm
->target_bias_level
= SND_SOC_BIAS_ON
;
1481 case SND_SOC_DAPM_STREAM_STOP
:
1482 if (dapm
->codec
&& dapm
->codec
->active
)
1483 dapm
->target_bias_level
= SND_SOC_BIAS_ON
;
1485 dapm
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1487 case SND_SOC_DAPM_STREAM_SUSPEND
:
1488 dapm
->target_bias_level
= SND_SOC_BIAS_STANDBY
;
1490 case SND_SOC_DAPM_STREAM_NOP
:
1491 dapm
->target_bias_level
= dapm
->bias_level
;
1498 /* Force all contexts in the card to the same bias state if
1499 * they're not ground referenced.
1501 bias
= SND_SOC_BIAS_OFF
;
1502 list_for_each_entry(d
, &card
->dapm_list
, list
)
1503 if (d
->target_bias_level
> bias
)
1504 bias
= d
->target_bias_level
;
1505 list_for_each_entry(d
, &card
->dapm_list
, list
)
1506 if (!d
->idle_bias_off
)
1507 d
->target_bias_level
= bias
;
1509 trace_snd_soc_dapm_walk_done(card
);
1511 /* Run all the bias changes in parallel */
1512 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1513 async_schedule_domain(dapm_pre_sequence_async
, d
,
1515 async_synchronize_full_domain(&async_domain
);
1517 /* Power down widgets first; try to avoid amplifying pops. */
1518 dapm_seq_run(dapm
, &down_list
, event
, false);
1520 dapm_widget_update(dapm
);
1523 dapm_seq_run(dapm
, &up_list
, event
, true);
1525 /* Run all the bias changes in parallel */
1526 list_for_each_entry(d
, &dapm
->card
->dapm_list
, list
)
1527 async_schedule_domain(dapm_post_sequence_async
, d
,
1529 async_synchronize_full_domain(&async_domain
);
1531 /* do we need to notify any clients that DAPM event is complete */
1532 list_for_each_entry(d
, &card
->dapm_list
, list
) {
1533 if (d
->stream_event
)
1534 d
->stream_event(d
, event
);
1537 pop_dbg(dapm
->dev
, card
->pop_time
,
1538 "DAPM sequencing finished, waiting %dms\n", card
->pop_time
);
1539 pop_wait(card
->pop_time
);
1541 trace_snd_soc_dapm_done(card
);
1546 #ifdef CONFIG_DEBUG_FS
1547 static int dapm_widget_power_open_file(struct inode
*inode
, struct file
*file
)
1549 file
->private_data
= inode
->i_private
;
1553 static ssize_t
dapm_widget_power_read_file(struct file
*file
,
1554 char __user
*user_buf
,
1555 size_t count
, loff_t
*ppos
)
1557 struct snd_soc_dapm_widget
*w
= file
->private_data
;
1561 struct snd_soc_dapm_path
*p
= NULL
;
1563 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1567 in
= is_connected_input_ep(w
);
1568 dapm_clear_walk(w
->dapm
);
1569 out
= is_connected_output_ep(w
);
1570 dapm_clear_walk(w
->dapm
);
1572 ret
= snprintf(buf
, PAGE_SIZE
, "%s: %s%s in %d out %d",
1573 w
->name
, w
->power
? "On" : "Off",
1574 w
->force
? " (forced)" : "", in
, out
);
1577 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1578 " - R%d(0x%x) bit %d",
1579 w
->reg
, w
->reg
, w
->shift
);
1581 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
1584 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, " stream %s %s\n",
1586 w
->active
? "active" : "inactive");
1588 list_for_each_entry(p
, &w
->sources
, list_sink
) {
1589 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1593 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1594 " in \"%s\" \"%s\"\n",
1595 p
->name
? p
->name
: "static",
1598 list_for_each_entry(p
, &w
->sinks
, list_source
) {
1599 if (p
->connected
&& !p
->connected(w
, p
->sink
))
1603 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1604 " out \"%s\" \"%s\"\n",
1605 p
->name
? p
->name
: "static",
1609 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1615 static const struct file_operations dapm_widget_power_fops
= {
1616 .open
= dapm_widget_power_open_file
,
1617 .read
= dapm_widget_power_read_file
,
1618 .llseek
= default_llseek
,
1621 static int dapm_bias_open_file(struct inode
*inode
, struct file
*file
)
1623 file
->private_data
= inode
->i_private
;
1627 static ssize_t
dapm_bias_read_file(struct file
*file
, char __user
*user_buf
,
1628 size_t count
, loff_t
*ppos
)
1630 struct snd_soc_dapm_context
*dapm
= file
->private_data
;
1633 switch (dapm
->bias_level
) {
1634 case SND_SOC_BIAS_ON
:
1637 case SND_SOC_BIAS_PREPARE
:
1638 level
= "Prepare\n";
1640 case SND_SOC_BIAS_STANDBY
:
1641 level
= "Standby\n";
1643 case SND_SOC_BIAS_OFF
:
1648 level
= "Unknown\n";
1652 return simple_read_from_buffer(user_buf
, count
, ppos
, level
,
1656 static const struct file_operations dapm_bias_fops
= {
1657 .open
= dapm_bias_open_file
,
1658 .read
= dapm_bias_read_file
,
1659 .llseek
= default_llseek
,
1662 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1663 struct dentry
*parent
)
1667 dapm
->debugfs_dapm
= debugfs_create_dir("dapm", parent
);
1669 if (!dapm
->debugfs_dapm
) {
1671 "Failed to create DAPM debugfs directory\n");
1675 d
= debugfs_create_file("bias_level", 0444,
1676 dapm
->debugfs_dapm
, dapm
,
1680 "ASoC: Failed to create bias level debugfs file\n");
1683 static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1685 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1688 if (!dapm
->debugfs_dapm
|| !w
->name
)
1691 d
= debugfs_create_file(w
->name
, 0444,
1692 dapm
->debugfs_dapm
, w
,
1693 &dapm_widget_power_fops
);
1695 dev_warn(w
->dapm
->dev
,
1696 "ASoC: Failed to create %s debugfs file\n",
1700 static void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1702 debugfs_remove_recursive(dapm
->debugfs_dapm
);
1706 void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context
*dapm
,
1707 struct dentry
*parent
)
1711 static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget
*w
)
1715 static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context
*dapm
)
1721 /* test and update the power status of a mux widget */
1722 int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget
*widget
,
1723 struct snd_kcontrol
*kcontrol
, int mux
, struct soc_enum
*e
)
1725 struct snd_soc_dapm_path
*path
;
1728 if (widget
->id
!= snd_soc_dapm_mux
&&
1729 widget
->id
!= snd_soc_dapm_virt_mux
&&
1730 widget
->id
!= snd_soc_dapm_value_mux
)
1733 /* find dapm widget path assoc with kcontrol */
1734 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1735 if (path
->kcontrol
!= kcontrol
)
1738 if (!path
->name
|| !e
->texts
[mux
])
1742 /* we now need to match the string in the enum to the path */
1743 if (!(strcmp(path
->name
, e
->texts
[mux
]))) {
1744 path
->connect
= 1; /* new connection */
1745 dapm_mark_dirty(path
->source
, "mux connection");
1748 dapm_mark_dirty(path
->source
,
1749 "mux disconnection");
1750 path
->connect
= 0; /* old connection must be powered down */
1755 dapm_mark_dirty(widget
, "mux change");
1756 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1761 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power
);
1763 /* test and update the power status of a mixer or switch widget */
1764 int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget
*widget
,
1765 struct snd_kcontrol
*kcontrol
, int connect
)
1767 struct snd_soc_dapm_path
*path
;
1770 if (widget
->id
!= snd_soc_dapm_mixer
&&
1771 widget
->id
!= snd_soc_dapm_mixer_named_ctl
&&
1772 widget
->id
!= snd_soc_dapm_switch
)
1775 /* find dapm widget path assoc with kcontrol */
1776 list_for_each_entry(path
, &widget
->dapm
->card
->paths
, list
) {
1777 if (path
->kcontrol
!= kcontrol
)
1780 /* found, now check type */
1782 path
->connect
= connect
;
1783 dapm_mark_dirty(path
->source
, "mixer connection");
1787 dapm_mark_dirty(widget
, "mixer update");
1788 dapm_power_widgets(widget
->dapm
, SND_SOC_DAPM_STREAM_NOP
);
1793 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power
);
1795 /* show dapm widget status in sys fs */
1796 static ssize_t
dapm_widget_show(struct device
*dev
,
1797 struct device_attribute
*attr
, char *buf
)
1799 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
1800 struct snd_soc_codec
*codec
=rtd
->codec
;
1801 struct snd_soc_dapm_widget
*w
;
1803 char *state
= "not set";
1805 list_for_each_entry(w
, &codec
->card
->widgets
, list
) {
1806 if (w
->dapm
!= &codec
->dapm
)
1809 /* only display widgets that burnm power */
1811 case snd_soc_dapm_hp
:
1812 case snd_soc_dapm_mic
:
1813 case snd_soc_dapm_spk
:
1814 case snd_soc_dapm_line
:
1815 case snd_soc_dapm_micbias
:
1816 case snd_soc_dapm_dac
:
1817 case snd_soc_dapm_adc
:
1818 case snd_soc_dapm_pga
:
1819 case snd_soc_dapm_out_drv
:
1820 case snd_soc_dapm_mixer
:
1821 case snd_soc_dapm_mixer_named_ctl
:
1822 case snd_soc_dapm_supply
:
1823 case snd_soc_dapm_regulator_supply
:
1825 count
+= sprintf(buf
+ count
, "%s: %s\n",
1826 w
->name
, w
->power
? "On":"Off");
1833 switch (codec
->dapm
.bias_level
) {
1834 case SND_SOC_BIAS_ON
:
1837 case SND_SOC_BIAS_PREPARE
:
1840 case SND_SOC_BIAS_STANDBY
:
1843 case SND_SOC_BIAS_OFF
:
1847 count
+= sprintf(buf
+ count
, "PM State: %s\n", state
);
1852 static DEVICE_ATTR(dapm_widget
, 0444, dapm_widget_show
, NULL
);
1854 int snd_soc_dapm_sys_add(struct device
*dev
)
1856 return device_create_file(dev
, &dev_attr_dapm_widget
);
1859 static void snd_soc_dapm_sys_remove(struct device
*dev
)
1861 device_remove_file(dev
, &dev_attr_dapm_widget
);
1864 /* free all dapm widgets and resources */
1865 static void dapm_free_widgets(struct snd_soc_dapm_context
*dapm
)
1867 struct snd_soc_dapm_widget
*w
, *next_w
;
1868 struct snd_soc_dapm_path
*p
, *next_p
;
1870 list_for_each_entry_safe(w
, next_w
, &dapm
->card
->widgets
, list
) {
1871 if (w
->dapm
!= dapm
)
1875 * remove source and sink paths associated to this widget.
1876 * While removing the path, remove reference to it from both
1877 * source and sink widgets so that path is removed only once.
1879 list_for_each_entry_safe(p
, next_p
, &w
->sources
, list_sink
) {
1880 list_del(&p
->list_sink
);
1881 list_del(&p
->list_source
);
1883 kfree(p
->long_name
);
1886 list_for_each_entry_safe(p
, next_p
, &w
->sinks
, list_source
) {
1887 list_del(&p
->list_sink
);
1888 list_del(&p
->list_source
);
1890 kfree(p
->long_name
);
1893 kfree(w
->kcontrols
);
1899 static struct snd_soc_dapm_widget
*dapm_find_widget(
1900 struct snd_soc_dapm_context
*dapm
, const char *pin
,
1901 bool search_other_contexts
)
1903 struct snd_soc_dapm_widget
*w
;
1904 struct snd_soc_dapm_widget
*fallback
= NULL
;
1906 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1907 if (!strcmp(w
->name
, pin
)) {
1908 if (w
->dapm
== dapm
)
1915 if (search_other_contexts
)
1921 static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context
*dapm
,
1922 const char *pin
, int status
)
1924 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
1927 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
1931 if (w
->connected
!= status
)
1932 dapm_mark_dirty(w
, "pin configuration");
1934 w
->connected
= status
;
1942 * snd_soc_dapm_sync - scan and power dapm paths
1943 * @dapm: DAPM context
1945 * Walks all dapm audio paths and powers widgets according to their
1946 * stream or path usage.
1948 * Returns 0 for success.
1950 int snd_soc_dapm_sync(struct snd_soc_dapm_context
*dapm
)
1955 * Suppress early reports (eg, jacks syncing their state) to avoid
1956 * silly DAPM runs during card startup.
1958 if (!dapm
->card
|| !dapm
->card
->instantiated
)
1961 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
1962 ret
= dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
1963 mutex_unlock(&dapm
->card
->dapm_mutex
);
1966 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync
);
1968 static int snd_soc_dapm_add_route(struct snd_soc_dapm_context
*dapm
,
1969 const struct snd_soc_dapm_route
*route
)
1971 struct snd_soc_dapm_path
*path
;
1972 struct snd_soc_dapm_widget
*wsource
= NULL
, *wsink
= NULL
, *w
;
1973 struct snd_soc_dapm_widget
*wtsource
= NULL
, *wtsink
= NULL
;
1975 const char *control
= route
->control
;
1977 char prefixed_sink
[80];
1978 char prefixed_source
[80];
1981 if (dapm
->codec
&& dapm
->codec
->name_prefix
) {
1982 snprintf(prefixed_sink
, sizeof(prefixed_sink
), "%s %s",
1983 dapm
->codec
->name_prefix
, route
->sink
);
1984 sink
= prefixed_sink
;
1985 snprintf(prefixed_source
, sizeof(prefixed_source
), "%s %s",
1986 dapm
->codec
->name_prefix
, route
->source
);
1987 source
= prefixed_source
;
1990 source
= route
->source
;
1994 * find src and dest widgets over all widgets but favor a widget from
1995 * current DAPM context
1997 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
1998 if (!wsink
&& !(strcmp(w
->name
, sink
))) {
2000 if (w
->dapm
== dapm
)
2004 if (!wsource
&& !(strcmp(w
->name
, source
))) {
2006 if (w
->dapm
== dapm
)
2010 /* use widget from another DAPM context if not found from this */
2016 if (wsource
== NULL
|| wsink
== NULL
)
2019 path
= kzalloc(sizeof(struct snd_soc_dapm_path
), GFP_KERNEL
);
2023 path
->source
= wsource
;
2025 path
->connected
= route
->connected
;
2026 INIT_LIST_HEAD(&path
->list
);
2027 INIT_LIST_HEAD(&path
->list_source
);
2028 INIT_LIST_HEAD(&path
->list_sink
);
2030 /* check for external widgets */
2031 if (wsink
->id
== snd_soc_dapm_input
) {
2032 if (wsource
->id
== snd_soc_dapm_micbias
||
2033 wsource
->id
== snd_soc_dapm_mic
||
2034 wsource
->id
== snd_soc_dapm_line
||
2035 wsource
->id
== snd_soc_dapm_output
)
2038 if (wsource
->id
== snd_soc_dapm_output
) {
2039 if (wsink
->id
== snd_soc_dapm_spk
||
2040 wsink
->id
== snd_soc_dapm_hp
||
2041 wsink
->id
== snd_soc_dapm_line
||
2042 wsink
->id
== snd_soc_dapm_input
)
2046 /* connect static paths */
2047 if (control
== NULL
) {
2048 list_add(&path
->list
, &dapm
->card
->paths
);
2049 list_add(&path
->list_sink
, &wsink
->sources
);
2050 list_add(&path
->list_source
, &wsource
->sinks
);
2055 /* connect dynamic paths */
2056 switch (wsink
->id
) {
2057 case snd_soc_dapm_adc
:
2058 case snd_soc_dapm_dac
:
2059 case snd_soc_dapm_pga
:
2060 case snd_soc_dapm_out_drv
:
2061 case snd_soc_dapm_input
:
2062 case snd_soc_dapm_output
:
2063 case snd_soc_dapm_siggen
:
2064 case snd_soc_dapm_micbias
:
2065 case snd_soc_dapm_vmid
:
2066 case snd_soc_dapm_pre
:
2067 case snd_soc_dapm_post
:
2068 case snd_soc_dapm_supply
:
2069 case snd_soc_dapm_regulator_supply
:
2070 case snd_soc_dapm_aif_in
:
2071 case snd_soc_dapm_aif_out
:
2072 case snd_soc_dapm_dai
:
2073 list_add(&path
->list
, &dapm
->card
->paths
);
2074 list_add(&path
->list_sink
, &wsink
->sources
);
2075 list_add(&path
->list_source
, &wsource
->sinks
);
2078 case snd_soc_dapm_mux
:
2079 case snd_soc_dapm_virt_mux
:
2080 case snd_soc_dapm_value_mux
:
2081 ret
= dapm_connect_mux(dapm
, wsource
, wsink
, path
, control
,
2082 &wsink
->kcontrol_news
[0]);
2086 case snd_soc_dapm_switch
:
2087 case snd_soc_dapm_mixer
:
2088 case snd_soc_dapm_mixer_named_ctl
:
2089 ret
= dapm_connect_mixer(dapm
, wsource
, wsink
, path
, control
);
2093 case snd_soc_dapm_hp
:
2094 case snd_soc_dapm_mic
:
2095 case snd_soc_dapm_line
:
2096 case snd_soc_dapm_spk
:
2097 list_add(&path
->list
, &dapm
->card
->paths
);
2098 list_add(&path
->list_sink
, &wsink
->sources
);
2099 list_add(&path
->list_source
, &wsource
->sinks
);
2106 dev_warn(dapm
->dev
, "asoc: no dapm match for %s --> %s --> %s\n",
2107 source
, control
, sink
);
2113 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
2114 * @dapm: DAPM context
2115 * @route: audio routes
2116 * @num: number of routes
2118 * Connects 2 dapm widgets together via a named audio path. The sink is
2119 * the widget receiving the audio signal, whilst the source is the sender
2120 * of the audio signal.
2122 * Returns 0 for success else error. On error all resources can be freed
2123 * with a call to snd_soc_card_free().
2125 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context
*dapm
,
2126 const struct snd_soc_dapm_route
*route
, int num
)
2130 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2131 for (i
= 0; i
< num
; i
++) {
2132 ret
= snd_soc_dapm_add_route(dapm
, route
);
2134 dev_err(dapm
->dev
, "Failed to add route %s->%s\n",
2135 route
->source
, route
->sink
);
2140 mutex_unlock(&dapm
->card
->dapm_mutex
);
2144 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes
);
2146 static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context
*dapm
,
2147 const struct snd_soc_dapm_route
*route
)
2149 struct snd_soc_dapm_widget
*source
= dapm_find_widget(dapm
,
2152 struct snd_soc_dapm_widget
*sink
= dapm_find_widget(dapm
,
2155 struct snd_soc_dapm_path
*path
;
2159 dev_err(dapm
->dev
, "Unable to find source %s for weak route\n",
2165 dev_err(dapm
->dev
, "Unable to find sink %s for weak route\n",
2170 if (route
->control
|| route
->connected
)
2171 dev_warn(dapm
->dev
, "Ignoring control for weak route %s->%s\n",
2172 route
->source
, route
->sink
);
2174 list_for_each_entry(path
, &source
->sinks
, list_source
) {
2175 if (path
->sink
== sink
) {
2182 dev_err(dapm
->dev
, "No path found for weak route %s->%s\n",
2183 route
->source
, route
->sink
);
2185 dev_warn(dapm
->dev
, "%d paths found for weak route %s->%s\n",
2186 count
, route
->source
, route
->sink
);
2192 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
2193 * @dapm: DAPM context
2194 * @route: audio routes
2195 * @num: number of routes
2197 * Mark existing routes matching those specified in the passed array
2198 * as being weak, meaning that they are ignored for the purpose of
2199 * power decisions. The main intended use case is for sidetone paths
2200 * which couple audio between other independent paths if they are both
2201 * active in order to make the combination work better at the user
2202 * level but which aren't intended to be "used".
2204 * Note that CODEC drivers should not use this as sidetone type paths
2205 * can frequently also be used as bypass paths.
2207 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context
*dapm
,
2208 const struct snd_soc_dapm_route
*route
, int num
)
2213 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2214 for (i
= 0; i
< num
; i
++) {
2215 err
= snd_soc_dapm_weak_route(dapm
, route
);
2220 mutex_unlock(&dapm
->card
->dapm_mutex
);
2224 EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes
);
2227 * snd_soc_dapm_new_widgets - add new dapm widgets
2228 * @dapm: DAPM context
2230 * Checks the codec for any new dapm widgets and creates them if found.
2232 * Returns 0 for success.
2234 int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context
*dapm
)
2236 struct snd_soc_dapm_widget
*w
;
2239 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2241 list_for_each_entry(w
, &dapm
->card
->widgets
, list
)
2246 if (w
->num_kcontrols
) {
2247 w
->kcontrols
= kzalloc(w
->num_kcontrols
*
2248 sizeof(struct snd_kcontrol
*),
2250 if (!w
->kcontrols
) {
2251 mutex_unlock(&dapm
->card
->dapm_mutex
);
2257 case snd_soc_dapm_switch
:
2258 case snd_soc_dapm_mixer
:
2259 case snd_soc_dapm_mixer_named_ctl
:
2262 case snd_soc_dapm_mux
:
2263 case snd_soc_dapm_virt_mux
:
2264 case snd_soc_dapm_value_mux
:
2267 case snd_soc_dapm_pga
:
2268 case snd_soc_dapm_out_drv
:
2275 /* Read the initial power state from the device */
2277 val
= soc_widget_read(w
, w
->reg
);
2278 val
&= 1 << w
->shift
;
2288 dapm_mark_dirty(w
, "new widget");
2289 dapm_debugfs_add_widget(w
);
2292 dapm_power_widgets(dapm
, SND_SOC_DAPM_STREAM_NOP
);
2293 mutex_unlock(&dapm
->card
->dapm_mutex
);
2296 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets
);
2299 * snd_soc_dapm_get_volsw - dapm mixer get callback
2300 * @kcontrol: mixer control
2301 * @ucontrol: control element information
2303 * Callback to get the value of a dapm mixer control.
2305 * Returns 0 for success.
2307 int snd_soc_dapm_get_volsw(struct snd_kcontrol
*kcontrol
,
2308 struct snd_ctl_elem_value
*ucontrol
)
2310 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2311 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2312 struct soc_mixer_control
*mc
=
2313 (struct soc_mixer_control
*)kcontrol
->private_value
;
2314 unsigned int reg
= mc
->reg
;
2315 unsigned int shift
= mc
->shift
;
2316 unsigned int rshift
= mc
->rshift
;
2318 unsigned int invert
= mc
->invert
;
2319 unsigned int mask
= (1 << fls(max
)) - 1;
2321 ucontrol
->value
.integer
.value
[0] =
2322 (snd_soc_read(widget
->codec
, reg
) >> shift
) & mask
;
2323 if (shift
!= rshift
)
2324 ucontrol
->value
.integer
.value
[1] =
2325 (snd_soc_read(widget
->codec
, reg
) >> rshift
) & mask
;
2327 ucontrol
->value
.integer
.value
[0] =
2328 max
- ucontrol
->value
.integer
.value
[0];
2329 if (shift
!= rshift
)
2330 ucontrol
->value
.integer
.value
[1] =
2331 max
- ucontrol
->value
.integer
.value
[1];
2336 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw
);
2339 * snd_soc_dapm_put_volsw - dapm mixer set callback
2340 * @kcontrol: mixer control
2341 * @ucontrol: control element information
2343 * Callback to set the value of a dapm mixer control.
2345 * Returns 0 for success.
2347 int snd_soc_dapm_put_volsw(struct snd_kcontrol
*kcontrol
,
2348 struct snd_ctl_elem_value
*ucontrol
)
2350 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2351 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2352 struct snd_soc_codec
*codec
= widget
->codec
;
2353 struct snd_soc_card
*card
= codec
->card
;
2354 struct soc_mixer_control
*mc
=
2355 (struct soc_mixer_control
*)kcontrol
->private_value
;
2356 unsigned int reg
= mc
->reg
;
2357 unsigned int shift
= mc
->shift
;
2359 unsigned int mask
= (1 << fls(max
)) - 1;
2360 unsigned int invert
= mc
->invert
;
2362 int connect
, change
;
2363 struct snd_soc_dapm_update update
;
2366 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2370 mask
= mask
<< shift
;
2374 /* new connection */
2375 connect
= invert
? 0 : 1;
2377 /* old connection must be powered down */
2378 connect
= invert
? 1 : 0;
2380 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
2382 change
= snd_soc_test_bits(widget
->codec
, reg
, mask
, val
);
2384 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2385 widget
= wlist
->widgets
[wi
];
2387 widget
->value
= val
;
2389 update
.kcontrol
= kcontrol
;
2390 update
.widget
= widget
;
2394 widget
->dapm
->update
= &update
;
2396 snd_soc_dapm_mixer_update_power(widget
, kcontrol
, connect
);
2398 widget
->dapm
->update
= NULL
;
2402 mutex_unlock(&card
->dapm_mutex
);
2405 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw
);
2408 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
2409 * @kcontrol: mixer control
2410 * @ucontrol: control element information
2412 * Callback to get the value of a dapm enumerated double mixer control.
2414 * Returns 0 for success.
2416 int snd_soc_dapm_get_enum_double(struct snd_kcontrol
*kcontrol
,
2417 struct snd_ctl_elem_value
*ucontrol
)
2419 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2420 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2421 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2422 unsigned int val
, bitmask
;
2424 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2426 val
= snd_soc_read(widget
->codec
, e
->reg
);
2427 ucontrol
->value
.enumerated
.item
[0] = (val
>> e
->shift_l
) & (bitmask
- 1);
2428 if (e
->shift_l
!= e
->shift_r
)
2429 ucontrol
->value
.enumerated
.item
[1] =
2430 (val
>> e
->shift_r
) & (bitmask
- 1);
2434 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double
);
2437 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2438 * @kcontrol: mixer control
2439 * @ucontrol: control element information
2441 * Callback to set the value of a dapm enumerated double mixer control.
2443 * Returns 0 for success.
2445 int snd_soc_dapm_put_enum_double(struct snd_kcontrol
*kcontrol
,
2446 struct snd_ctl_elem_value
*ucontrol
)
2448 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2449 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2450 struct snd_soc_codec
*codec
= widget
->codec
;
2451 struct snd_soc_card
*card
= codec
->card
;
2452 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2453 unsigned int val
, mux
, change
;
2454 unsigned int mask
, bitmask
;
2455 struct snd_soc_dapm_update update
;
2458 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2460 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2462 mux
= ucontrol
->value
.enumerated
.item
[0];
2463 val
= mux
<< e
->shift_l
;
2464 mask
= (bitmask
- 1) << e
->shift_l
;
2465 if (e
->shift_l
!= e
->shift_r
) {
2466 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2468 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2469 mask
|= (bitmask
- 1) << e
->shift_r
;
2472 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
2474 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2476 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2477 widget
= wlist
->widgets
[wi
];
2479 widget
->value
= val
;
2481 update
.kcontrol
= kcontrol
;
2482 update
.widget
= widget
;
2483 update
.reg
= e
->reg
;
2486 widget
->dapm
->update
= &update
;
2488 snd_soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2490 widget
->dapm
->update
= NULL
;
2494 mutex_unlock(&card
->dapm_mutex
);
2497 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double
);
2500 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
2501 * @kcontrol: mixer control
2502 * @ucontrol: control element information
2504 * Returns 0 for success.
2506 int snd_soc_dapm_get_enum_virt(struct snd_kcontrol
*kcontrol
,
2507 struct snd_ctl_elem_value
*ucontrol
)
2509 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2510 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2512 ucontrol
->value
.enumerated
.item
[0] = widget
->value
;
2516 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt
);
2519 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
2520 * @kcontrol: mixer control
2521 * @ucontrol: control element information
2523 * Returns 0 for success.
2525 int snd_soc_dapm_put_enum_virt(struct snd_kcontrol
*kcontrol
,
2526 struct snd_ctl_elem_value
*ucontrol
)
2528 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2529 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2530 struct snd_soc_codec
*codec
= widget
->codec
;
2531 struct snd_soc_card
*card
= codec
->card
;
2532 struct soc_enum
*e
=
2533 (struct soc_enum
*)kcontrol
->private_value
;
2538 if (ucontrol
->value
.enumerated
.item
[0] >= e
->max
)
2541 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
2543 change
= widget
->value
!= ucontrol
->value
.enumerated
.item
[0];
2545 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2546 widget
= wlist
->widgets
[wi
];
2548 widget
->value
= ucontrol
->value
.enumerated
.item
[0];
2550 snd_soc_dapm_mux_update_power(widget
, kcontrol
, widget
->value
, e
);
2554 mutex_unlock(&card
->dapm_mutex
);
2557 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt
);
2560 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
2562 * @kcontrol: mixer control
2563 * @ucontrol: control element information
2565 * Callback to get the value of a dapm semi enumerated double mixer control.
2567 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2568 * used for handling bitfield coded enumeration for example.
2570 * Returns 0 for success.
2572 int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2573 struct snd_ctl_elem_value
*ucontrol
)
2575 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2576 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2577 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2578 unsigned int reg_val
, val
, mux
;
2580 reg_val
= snd_soc_read(widget
->codec
, e
->reg
);
2581 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2582 for (mux
= 0; mux
< e
->max
; mux
++) {
2583 if (val
== e
->values
[mux
])
2586 ucontrol
->value
.enumerated
.item
[0] = mux
;
2587 if (e
->shift_l
!= e
->shift_r
) {
2588 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2589 for (mux
= 0; mux
< e
->max
; mux
++) {
2590 if (val
== e
->values
[mux
])
2593 ucontrol
->value
.enumerated
.item
[1] = mux
;
2598 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double
);
2601 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
2603 * @kcontrol: mixer control
2604 * @ucontrol: control element information
2606 * Callback to set the value of a dapm semi enumerated double mixer control.
2608 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2609 * used for handling bitfield coded enumeration for example.
2611 * Returns 0 for success.
2613 int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2614 struct snd_ctl_elem_value
*ucontrol
)
2616 struct snd_soc_dapm_widget_list
*wlist
= snd_kcontrol_chip(kcontrol
);
2617 struct snd_soc_dapm_widget
*widget
= wlist
->widgets
[0];
2618 struct snd_soc_codec
*codec
= widget
->codec
;
2619 struct snd_soc_card
*card
= codec
->card
;
2620 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2621 unsigned int val
, mux
, change
;
2623 struct snd_soc_dapm_update update
;
2626 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2628 mux
= ucontrol
->value
.enumerated
.item
[0];
2629 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2630 mask
= e
->mask
<< e
->shift_l
;
2631 if (e
->shift_l
!= e
->shift_r
) {
2632 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2634 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2635 mask
|= e
->mask
<< e
->shift_r
;
2638 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
2640 change
= snd_soc_test_bits(widget
->codec
, e
->reg
, mask
, val
);
2642 for (wi
= 0; wi
< wlist
->num_widgets
; wi
++) {
2643 widget
= wlist
->widgets
[wi
];
2645 widget
->value
= val
;
2647 update
.kcontrol
= kcontrol
;
2648 update
.widget
= widget
;
2649 update
.reg
= e
->reg
;
2652 widget
->dapm
->update
= &update
;
2654 snd_soc_dapm_mux_update_power(widget
, kcontrol
, mux
, e
);
2656 widget
->dapm
->update
= NULL
;
2660 mutex_unlock(&card
->dapm_mutex
);
2663 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double
);
2666 * snd_soc_dapm_info_pin_switch - Info for a pin switch
2668 * @kcontrol: mixer control
2669 * @uinfo: control element information
2671 * Callback to provide information about a pin switch control.
2673 int snd_soc_dapm_info_pin_switch(struct snd_kcontrol
*kcontrol
,
2674 struct snd_ctl_elem_info
*uinfo
)
2676 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2678 uinfo
->value
.integer
.min
= 0;
2679 uinfo
->value
.integer
.max
= 1;
2683 EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch
);
2686 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
2688 * @kcontrol: mixer control
2691 int snd_soc_dapm_get_pin_switch(struct snd_kcontrol
*kcontrol
,
2692 struct snd_ctl_elem_value
*ucontrol
)
2694 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2695 const char *pin
= (const char *)kcontrol
->private_value
;
2697 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
2699 ucontrol
->value
.integer
.value
[0] =
2700 snd_soc_dapm_get_pin_status(&card
->dapm
, pin
);
2702 mutex_unlock(&card
->dapm_mutex
);
2706 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch
);
2709 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
2711 * @kcontrol: mixer control
2714 int snd_soc_dapm_put_pin_switch(struct snd_kcontrol
*kcontrol
,
2715 struct snd_ctl_elem_value
*ucontrol
)
2717 struct snd_soc_card
*card
= snd_kcontrol_chip(kcontrol
);
2718 const char *pin
= (const char *)kcontrol
->private_value
;
2720 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
2722 if (ucontrol
->value
.integer
.value
[0])
2723 snd_soc_dapm_enable_pin(&card
->dapm
, pin
);
2725 snd_soc_dapm_disable_pin(&card
->dapm
, pin
);
2727 mutex_unlock(&card
->dapm_mutex
);
2729 snd_soc_dapm_sync(&card
->dapm
);
2732 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch
);
2734 static struct snd_soc_dapm_widget
*
2735 snd_soc_dapm_new_control(struct snd_soc_dapm_context
*dapm
,
2736 const struct snd_soc_dapm_widget
*widget
)
2738 struct snd_soc_dapm_widget
*w
;
2742 if ((w
= dapm_cnew_widget(widget
)) == NULL
)
2746 case snd_soc_dapm_regulator_supply
:
2747 w
->priv
= devm_regulator_get(dapm
->dev
, w
->name
);
2748 if (IS_ERR(w
->priv
)) {
2749 ret
= PTR_ERR(w
->priv
);
2750 dev_err(dapm
->dev
, "Failed to request %s: %d\n",
2759 name_len
= strlen(widget
->name
) + 1;
2760 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2761 name_len
+= 1 + strlen(dapm
->codec
->name_prefix
);
2762 w
->name
= kmalloc(name_len
, GFP_KERNEL
);
2763 if (w
->name
== NULL
) {
2767 if (dapm
->codec
&& dapm
->codec
->name_prefix
)
2768 snprintf((char *)w
->name
, name_len
, "%s %s",
2769 dapm
->codec
->name_prefix
, widget
->name
);
2771 snprintf((char *)w
->name
, name_len
, "%s", widget
->name
);
2774 case snd_soc_dapm_switch
:
2775 case snd_soc_dapm_mixer
:
2776 case snd_soc_dapm_mixer_named_ctl
:
2777 w
->power_check
= dapm_generic_check_power
;
2779 case snd_soc_dapm_mux
:
2780 case snd_soc_dapm_virt_mux
:
2781 case snd_soc_dapm_value_mux
:
2782 w
->power_check
= dapm_generic_check_power
;
2784 case snd_soc_dapm_adc
:
2785 case snd_soc_dapm_aif_out
:
2786 w
->power_check
= dapm_adc_check_power
;
2788 case snd_soc_dapm_dac
:
2789 case snd_soc_dapm_aif_in
:
2790 w
->power_check
= dapm_dac_check_power
;
2792 case snd_soc_dapm_pga
:
2793 case snd_soc_dapm_out_drv
:
2794 case snd_soc_dapm_input
:
2795 case snd_soc_dapm_output
:
2796 case snd_soc_dapm_micbias
:
2797 case snd_soc_dapm_spk
:
2798 case snd_soc_dapm_hp
:
2799 case snd_soc_dapm_mic
:
2800 case snd_soc_dapm_line
:
2801 w
->power_check
= dapm_generic_check_power
;
2803 case snd_soc_dapm_supply
:
2804 case snd_soc_dapm_regulator_supply
:
2805 w
->power_check
= dapm_supply_check_power
;
2807 case snd_soc_dapm_dai
:
2808 w
->power_check
= dapm_dai_check_power
;
2811 w
->power_check
= dapm_always_on_check_power
;
2817 w
->codec
= dapm
->codec
;
2818 w
->platform
= dapm
->platform
;
2819 INIT_LIST_HEAD(&w
->sources
);
2820 INIT_LIST_HEAD(&w
->sinks
);
2821 INIT_LIST_HEAD(&w
->list
);
2822 INIT_LIST_HEAD(&w
->dirty
);
2823 list_add(&w
->list
, &dapm
->card
->widgets
);
2825 /* machine layer set ups unconnected pins and insertions */
2831 * snd_soc_dapm_new_controls - create new dapm controls
2832 * @dapm: DAPM context
2833 * @widget: widget array
2834 * @num: number of widgets
2836 * Creates new DAPM controls based upon the templates.
2838 * Returns 0 for success else error.
2840 int snd_soc_dapm_new_controls(struct snd_soc_dapm_context
*dapm
,
2841 const struct snd_soc_dapm_widget
*widget
,
2844 struct snd_soc_dapm_widget
*w
;
2847 mutex_lock_nested(&dapm
->card
->dapm_mutex
, SND_SOC_DAPM_CLASS_INIT
);
2848 for (i
= 0; i
< num
; i
++) {
2849 w
= snd_soc_dapm_new_control(dapm
, widget
);
2852 "ASoC: Failed to create DAPM control %s\n",
2858 mutex_unlock(&dapm
->card
->dapm_mutex
);
2861 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls
);
2863 int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context
*dapm
,
2864 struct snd_soc_dai
*dai
)
2866 struct snd_soc_dapm_widget
template;
2867 struct snd_soc_dapm_widget
*w
;
2869 WARN_ON(dapm
->dev
!= dai
->dev
);
2871 memset(&template, 0, sizeof(template));
2872 template.reg
= SND_SOC_NOPM
;
2874 if (dai
->driver
->playback
.stream_name
) {
2875 template.id
= snd_soc_dapm_dai
;
2876 template.name
= dai
->driver
->playback
.stream_name
;
2877 template.sname
= dai
->driver
->playback
.stream_name
;
2879 dev_dbg(dai
->dev
, "adding %s widget\n",
2882 w
= snd_soc_dapm_new_control(dapm
, &template);
2884 dev_err(dapm
->dev
, "Failed to create %s widget\n",
2885 dai
->driver
->playback
.stream_name
);
2889 dai
->playback_widget
= w
;
2892 if (dai
->driver
->capture
.stream_name
) {
2893 template.id
= snd_soc_dapm_dai
;
2894 template.name
= dai
->driver
->capture
.stream_name
;
2895 template.sname
= dai
->driver
->capture
.stream_name
;
2897 dev_dbg(dai
->dev
, "adding %s widget\n",
2900 w
= snd_soc_dapm_new_control(dapm
, &template);
2902 dev_err(dapm
->dev
, "Failed to create %s widget\n",
2903 dai
->driver
->capture
.stream_name
);
2907 dai
->capture_widget
= w
;
2913 int snd_soc_dapm_link_dai_widgets(struct snd_soc_card
*card
)
2915 struct snd_soc_dapm_widget
*dai_w
, *w
;
2916 struct snd_soc_dai
*dai
;
2917 struct snd_soc_dapm_route r
;
2919 memset(&r
, 0, sizeof(r
));
2921 /* For each DAI widget... */
2922 list_for_each_entry(dai_w
, &card
->widgets
, list
) {
2923 if (dai_w
->id
!= snd_soc_dapm_dai
)
2928 /* ...find all widgets with the same stream and link them */
2929 list_for_each_entry(w
, &card
->widgets
, list
) {
2930 if (w
->dapm
!= dai_w
->dapm
)
2933 if (w
->id
== snd_soc_dapm_dai
)
2939 if (dai
->driver
->playback
.stream_name
&&
2941 dai
->driver
->playback
.stream_name
)) {
2942 r
.source
= dai
->playback_widget
->name
;
2944 dev_dbg(dai
->dev
, "%s -> %s\n",
2947 snd_soc_dapm_add_route(w
->dapm
, &r
);
2950 if (dai
->driver
->capture
.stream_name
&&
2952 dai
->driver
->capture
.stream_name
)) {
2954 r
.sink
= dai
->capture_widget
->name
;
2955 dev_dbg(dai
->dev
, "%s -> %s\n",
2958 snd_soc_dapm_add_route(w
->dapm
, &r
);
2966 static void soc_dapm_stream_event(struct snd_soc_dapm_context
*dapm
,
2967 int stream
, struct snd_soc_dai
*dai
,
2970 struct snd_soc_dapm_widget
*w
;
2972 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2973 w
= dai
->playback_widget
;
2975 w
= dai
->capture_widget
;
2980 dapm_mark_dirty(w
, "stream event");
2983 case SND_SOC_DAPM_STREAM_START
:
2986 case SND_SOC_DAPM_STREAM_STOP
:
2989 case SND_SOC_DAPM_STREAM_SUSPEND
:
2990 case SND_SOC_DAPM_STREAM_RESUME
:
2991 case SND_SOC_DAPM_STREAM_PAUSE_PUSH
:
2992 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE
:
2996 dapm_power_widgets(dapm
, event
);
3000 * snd_soc_dapm_stream_event - send a stream event to the dapm core
3001 * @rtd: PCM runtime data
3002 * @stream: stream name
3003 * @event: stream event
3005 * Sends a stream event to the dapm core. The core then makes any
3006 * necessary widget power changes.
3008 * Returns 0 for success else error.
3010 int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime
*rtd
, int stream
,
3011 struct snd_soc_dai
*dai
, int event
)
3013 struct snd_soc_card
*card
= rtd
->card
;
3015 mutex_lock_nested(&card
->dapm_mutex
, SND_SOC_DAPM_CLASS_PCM
);
3016 soc_dapm_stream_event(&card
->dapm
, stream
, dai
, event
);
3017 mutex_unlock(&card
->dapm_mutex
);
3022 * snd_soc_dapm_enable_pin - enable pin.
3023 * @dapm: DAPM context
3026 * Enables input/output pin and its parents or children widgets iff there is
3027 * a valid audio route and active audio stream.
3028 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3029 * do any widget power switching.
3031 int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3033 return snd_soc_dapm_set_pin(dapm
, pin
, 1);
3035 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin
);
3038 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
3039 * @dapm: DAPM context
3042 * Enables input/output pin regardless of any other state. This is
3043 * intended for use with microphone bias supplies used in microphone
3046 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3047 * do any widget power switching.
3049 int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context
*dapm
,
3052 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3055 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3059 dev_dbg(w
->dapm
->dev
, "dapm: force enable pin %s\n", pin
);
3062 dapm_mark_dirty(w
, "force enable");
3066 EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin
);
3069 * snd_soc_dapm_disable_pin - disable pin.
3070 * @dapm: DAPM context
3073 * Disables input/output pin and its parents or children widgets.
3074 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3075 * do any widget power switching.
3077 int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context
*dapm
,
3080 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3082 EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin
);
3085 * snd_soc_dapm_nc_pin - permanently disable pin.
3086 * @dapm: DAPM context
3089 * Marks the specified pin as being not connected, disabling it along
3090 * any parent or child widgets. At present this is identical to
3091 * snd_soc_dapm_disable_pin() but in future it will be extended to do
3092 * additional things such as disabling controls which only affect
3093 * paths through the pin.
3095 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
3096 * do any widget power switching.
3098 int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context
*dapm
, const char *pin
)
3100 return snd_soc_dapm_set_pin(dapm
, pin
, 0);
3102 EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin
);
3105 * snd_soc_dapm_get_pin_status - get audio pin status
3106 * @dapm: DAPM context
3107 * @pin: audio signal pin endpoint (or start point)
3109 * Get audio pin status - connected or disconnected.
3111 * Returns 1 for connected otherwise 0.
3113 int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context
*dapm
,
3116 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, true);
3119 return w
->connected
;
3123 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status
);
3126 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
3127 * @dapm: DAPM context
3128 * @pin: audio signal pin endpoint (or start point)
3130 * Mark the given endpoint or pin as ignoring suspend. When the
3131 * system is disabled a path between two endpoints flagged as ignoring
3132 * suspend will not be disabled. The path must already be enabled via
3133 * normal means at suspend time, it will not be turned on if it was not
3136 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context
*dapm
,
3139 struct snd_soc_dapm_widget
*w
= dapm_find_widget(dapm
, pin
, false);
3142 dev_err(dapm
->dev
, "dapm: unknown pin %s\n", pin
);
3146 w
->ignore_suspend
= 1;
3150 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend
);
3152 static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card
*card
,
3153 struct snd_soc_dapm_widget
*w
)
3155 struct snd_soc_dapm_path
*p
;
3157 list_for_each_entry(p
, &card
->paths
, list
) {
3158 if ((p
->source
== w
) || (p
->sink
== w
)) {
3160 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3161 p
->source
->name
, p
->source
->id
, p
->source
->dapm
,
3162 p
->sink
->name
, p
->sink
->id
, p
->sink
->dapm
);
3164 /* Connected to something other than the codec */
3165 if (p
->source
->dapm
!= p
->sink
->dapm
)
3168 * Loopback connection from codec external pin to
3169 * codec external pin
3171 if (p
->sink
->id
== snd_soc_dapm_input
) {
3172 switch (p
->source
->id
) {
3173 case snd_soc_dapm_output
:
3174 case snd_soc_dapm_micbias
:
3187 * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
3188 * @codec: The codec whose pins should be processed
3190 * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
3191 * which are unused. Pins are used if they are connected externally to the
3192 * codec, whether that be to some other device, or a loop-back connection to
3195 void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec
*codec
)
3197 struct snd_soc_card
*card
= codec
->card
;
3198 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
3199 struct snd_soc_dapm_widget
*w
;
3201 dev_dbg(codec
->dev
, "Auto NC: DAPMs: card:%p codec:%p\n",
3202 &card
->dapm
, &codec
->dapm
);
3204 list_for_each_entry(w
, &card
->widgets
, list
) {
3205 if (w
->dapm
!= dapm
)
3208 case snd_soc_dapm_input
:
3209 case snd_soc_dapm_output
:
3210 case snd_soc_dapm_micbias
:
3211 dev_dbg(codec
->dev
, "Auto NC: Checking widget %s\n",
3213 if (!snd_soc_dapm_widget_in_card_paths(card
, w
)) {
3215 "... Not in map; disabling\n");
3216 snd_soc_dapm_nc_pin(dapm
, w
->name
);
3226 * snd_soc_dapm_free - free dapm resources
3227 * @dapm: DAPM context
3229 * Free all dapm widgets and resources.
3231 void snd_soc_dapm_free(struct snd_soc_dapm_context
*dapm
)
3233 snd_soc_dapm_sys_remove(dapm
->dev
);
3234 dapm_debugfs_cleanup(dapm
);
3235 dapm_free_widgets(dapm
);
3236 list_del(&dapm
->list
);
3238 EXPORT_SYMBOL_GPL(snd_soc_dapm_free
);
3240 static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context
*dapm
)
3242 struct snd_soc_dapm_widget
*w
;
3243 LIST_HEAD(down_list
);
3246 list_for_each_entry(w
, &dapm
->card
->widgets
, list
) {
3247 if (w
->dapm
!= dapm
)
3250 dapm_seq_insert(w
, &down_list
, false);
3256 /* If there were no widgets to power down we're already in
3260 if (dapm
->bias_level
== SND_SOC_BIAS_ON
)
3261 snd_soc_dapm_set_bias_level(dapm
,
3262 SND_SOC_BIAS_PREPARE
);
3263 dapm_seq_run(dapm
, &down_list
, 0, false);
3264 if (dapm
->bias_level
== SND_SOC_BIAS_PREPARE
)
3265 snd_soc_dapm_set_bias_level(dapm
,
3266 SND_SOC_BIAS_STANDBY
);
3271 * snd_soc_dapm_shutdown - callback for system shutdown
3273 void snd_soc_dapm_shutdown(struct snd_soc_card
*card
)
3275 struct snd_soc_codec
*codec
;
3277 list_for_each_entry(codec
, &card
->codec_dev_list
, list
) {
3278 soc_dapm_shutdown_codec(&codec
->dapm
);
3279 if (codec
->dapm
.bias_level
== SND_SOC_BIAS_STANDBY
)
3280 snd_soc_dapm_set_bias_level(&codec
->dapm
,
3285 /* Module information */
3286 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3287 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
3288 MODULE_LICENSE("GPL");